Skip to content

Commit d59d6f5

Browse files
committed
Smearing of a vector direction now preserves vector modulus.
1 parent cf2bca7 commit d59d6f5

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

boosteddmanalysis/Reconstruction/SmearedReconstructionAlg.cxx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
//------------------------------------------------------------------------------
3737
namespace {
3838

39+
/// Returns the square of the specified value.
40+
template <typename T>
41+
T sqr(T value) { return value * value; }
42+
43+
3944
/// Returns a random value distributed within a truncated Gaussian between
4045
/// `min` and `max`.
4146
double cappedGaus(CLHEP::RandGauss& gaus, double min, double max)
@@ -62,11 +67,16 @@ namespace {
6267
// details of the direction of the displacement rotation around the
6368
// original vector are not relevant.
6469
//
65-
double const dr = dtheta* v.R();
70+
// In the end, we restore the modulus of the vector.
71+
//
72+
if (dtheta == 0.0) return v; // actually, no smearing
73+
double const vR = v.R();
74+
double const dr = dtheta* vR;
6675
geo::Vector_t dv { dr * std::cos(dphi), dr * std::sin(dphi), 0.0 };
6776
auto const rotation
6877
= ROOT::Math::RotationZ(v.Phi()) * ROOT::Math::RotationY(v.Theta());
69-
return v + rotation * dv;
78+
double const rescale = std::sqrt(1.0 / (1.0 + sqr(dr/vR)));
79+
return rescale * (v + rotation * dv);
7080
}
7181

7282
} // local namespace

0 commit comments

Comments
 (0)