Belle II Software  release-06-01-15
CDCCKFEclSeedCreator.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #include <tracking/ckf/cdc/findlets/CDCCKFEclSeedCreator.h>
9 
10 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
11 
12 #include <tracking/dataobjects/RecoTrack.h>
13 #include <tracking/ckf/cdc/entities/CDCCKFState.h>
14 
15 #include <framework/core/ModuleParamList.h>
16 
17 #include <framework/gearbox/Const.h>
18 
19 using namespace Belle2;
20 
22 {
23 
24 }
25 
26 void CDCCKFEclSeedCreator::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
27 {
28  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "inputECLshowersStoreArrayName"),
30  "StoreArray name of the input Shower Store Array.");
31 
32  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "eclSeedRecoTrackStoreArrayName"),
34  "StoreArray name of the output Track Store Array.");
35 
36  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "minimalEnRequirementCluster"),
38  "Minimal energy requirement for the input clusters",
40 
41  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "restrictToForwardSeeds"),
43  "Don't do Ecl seeding in central region to save computing time",
45 
46  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "tanLambdaForwardNeg"),
48  "Up to which (neg) tanLambda value should the seeding be performed",
50 
51  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "tanLambdaForwardPos"),
53  "Up to which (pos) tanLambda value should the seeding be performed",
55 
56  moduleParamList->addParameter(TrackFindingCDC::prefixed(prefix, "showerDepth"),
58  "Don't do Ecl seeding in central region to save computing time",
60 }
61 
63 {
65 
67 
70 
71  m_eclSeedRecoTracks.registerRelationTo(m_inputECLshowers);
72 }
73 
74 void CDCCKFEclSeedCreator::apply(std::vector<CDCCKFPath>& seeds)
75 {
76  // loop over all showers and create seed objects
77  for (auto& shower : m_inputECLshowers) {
78  if (shower.getHypothesisId() != ECLShower::c_nPhotons) {
79  continue;
80  }
81 
82  const double Eclus = shower.getEnergy();
83  if (Eclus < m_param_minimalEnRequirement) {
84  continue;
85  }
86 
87  // Get shower position, momentum
88  const double thetaClus = shower.getTheta();
89  const double phiClus = shower.getPhi();
90  const double rClus = shower.getR();
91 
92  const double sinTheta = sin(thetaClus);
93  const double cosTheta = cos(thetaClus);
94  const double sinPhi = sin(phiClus);
95  const double cosPhi = cos(phiClus);
96 
97  TVector3 pos(rClus * sinTheta * cosPhi, rClus * sinTheta * sinPhi, rClus * cosTheta);
98  const double tanLambda = pos.Z() / pos.Perp();
99 
100  // restrict to forward seeds
102  if (tanLambda > m_param_tanLambdaForwardNeg && tanLambda < m_param_tanLambdaForwardPos) {
103  continue;
104  }
105  }
106 
107  // Correction if shower is assumed to start in a certain depth
108  pos = pos - m_param_showerDepth / pos.Mag() * pos;
109 
110  TVector3 mom = Eclus / pos.Mag() * pos;
111 
112  // Calculate helix trajectory for negative and positive charge seeds
113  // Find center of circular trajectory
114  // factor 1. for charge // speed of light in [cm per ns] // const magnetic field
115  double rad = std::abs(mom.Pt() / (Const::speedOfLight * 1e-4 * 1. * 1.5));
116 
117  // Particle would not be able to reach ECL (underestimation of shower energy)
118  if (2. * rad < pos.Perp()) {
119  rad = pos.Perp() / 2.0 + 1.0;
120  }
121 
122  // Use pq formula (center of circle has to be on perpendicular line through center of line between (0,0) and seed position)
123  double q = pos.Perp();
124  double y3 = pos.Y() / 2.0;
125  double x3 = pos.X() / 2.0;
126 
127  double basex = sqrt(rad * rad - q * q / 4.0) * (-pos.Y()) / q;
128  double basey = sqrt(rad * rad - q * q / 4.0) * pos.X() / q;
129 
130  double centerx1 = x3 + basex;
131  double centery1 = y3 + basey;
132  double centerx2 = x3 - basex;
133  double centery2 = y3 - basey;
134 
135  // vectors for tangent at seed position (perpendicular to radius at seed position)
136  double momx1 = pos.Y() - centery1;
137  double momy1 = - (pos.X() - centerx1);
138  double momx2 = pos.Y() - centery2;
139  double momy2 = - (pos.X() - centerx2);
140 
141  // two solutions (pointing toward and away from center)
142  // make sure that particle moves inwards
143  if (momx1 * pos.X() + momy1 * pos.Y() < 0) {
144  momx1 = -momx1;
145  momy1 = -momy1;
146  }
147  if (momx2 * pos.X() + momy2 * pos.Y() < 0) {
148  momx2 = -momx2;
149  momy2 = -momy2;
150  }
151 
152  // scale to unit length
153  double mom1abs = sqrt(momx1 * momx1 + momy1 * momy1);
154  double mom2abs = sqrt(momx2 * momx2 + momy2 * momy2);
155  momx1 = momx1 / mom1abs;
156  momy1 = momy1 / mom1abs;
157  momx2 = momx2 / mom2abs;
158  momy2 = momy2 / mom2abs;
159 
160  TVector3 mom1(momx1 * mom.Perp(), momy1 * mom.Perp(), mom.Z());
161  TVector3 mom2(momx2 * mom.Perp(), momy2 * mom.Perp(), mom.Z());
162 
163  // Pick the right momentum for positive/negative charge
164  // Use cross product if momentum vector is (counter)clockwise wrt position vector
165  bool clockwise1 = true;
166  bool clockwise2 = true;
167  if (pos.Y() * mom1.X() - pos.X() * mom1.Y() > 0) {
168  clockwise1 = false;
169  }
170  if (pos.Y() * mom2.X() - pos.X() * mom2.Y() > 0) {
171  clockwise2 = false;
172  }
173 
174  if (clockwise1 == clockwise2) {
175  B2WARNING("Something went wrong during helix extrapolation. Skipping track.");
176  continue;
177  }
178 
179  TVector3 mompos;
180  TVector3 momneg;
181  if (clockwise1) {
182  mompos = mom2;
183  momneg = mom1;
184  } else {
185  mompos = mom1;
186  momneg = mom2;
187  }
188 
189  // electron and positron hypothesis
190  RecoTrack* eclSeedNeg = m_eclSeedRecoTracks.appendNew(pos, momneg, -1);
191  eclSeedNeg->addRelationTo(&shower);
192  RecoTrack* eclSeedPos = m_eclSeedRecoTracks.appendNew(pos, mompos, +1);
193  eclSeedPos->addRelationTo(&shower);
194 
195  // define MeasuredStateOnPlane (use pion hypothesis)
197  genfit::MeasuredStateOnPlane msopNeg(repNeg);
199  genfit::MeasuredStateOnPlane msopPos(repPos);
200 
201  // set position, momentum, cov, sharedPlanePtr
202  TMatrixDSym cov(6);
203  double covArray[6];
204  shower.getCovarianceMatrixAsArray(covArray);
205 
206  // Calculate uncertainties on position from ECLShower
207  double dx2 = rClus * cosTheta * cosPhi * rClus * cosTheta * cosPhi * covArray[5]
208  + rClus * sinTheta * sinPhi * rClus * sinTheta * sinPhi * covArray[2];
209  double dy2 = rClus * cosTheta * sinPhi * rClus * cosTheta * sinPhi * covArray[5]
210  + rClus * sinTheta * cosPhi * rClus * sinTheta * cosPhi * covArray[2];
211  double dz2 = rClus * sinTheta * rClus * sinTheta * covArray[5];
212 
213  double dpx2 = std::abs(mom1.X() - mom2.X()) / 4.0 * std::abs(mom1.X() - mom2.X()) / 4.0;
214  double dpy2 = std::abs(mom1.Y() - mom2.Y()) / 4.0 * std::abs(mom1.Y() - mom2.Y()) / 4.0;
215  double dpz2 = 0.25 * 0.25 * mom.Z() * mom.Z();
216 
217  cov(0, 0) = dx2;
218  cov(1, 1) = dy2;
219  cov(2, 2) = dz2;
220  cov(3, 3) = dpx2;
221  cov(4, 4) = dpy2;
222  cov(5, 5) = dpz2;
223 
224  // set properties of genfit objects
225  genfit::SharedPlanePtr planeNeg(new genfit::DetPlane(pos, pos));
226  genfit::SharedPlanePtr planePos(new genfit::DetPlane(pos, pos));
227  msopNeg.setPosMomCov(pos, momneg, cov);
228  msopNeg.setPlane(planeNeg);
229  msopPos.setPosMomCov(pos, mompos, cov);
230  msopPos.setPlane(planePos);
231 
232  // create CDCCKF states
233  CDCCKFState seedStateNeg(eclSeedNeg, msopNeg);
234  seeds.push_back({seedStateNeg});
235  CDCCKFState seedStatePos(eclSeedPos, msopPos);
236  seeds.push_back({seedStatePos});
237  }
238 }
StoreArray< ECLShower > m_inputECLshowers
Input ECL Showers Store Array.
CDCCKFEclSeedCreator()
Add the subfindlets.
bool m_param_restrictToForwardSeeds
Don't do Ecl seeding in central region to save computing time.
void apply(std::vector< CDCCKFPath > &seeds) override
Load in the reco tracks and the hits.
double m_param_minimalEnRequirement
Minimal pt requirement.
void initialize() override
Create the store arrays.
std::string m_param_inputEclShowerStoreArrayName
StoreArray name of the input Ecl Shower Store Array.
std::string m_param_eclSeedRecoTrackStoreArrayName
StoreArray name of the output Track Store Array.
StoreArray< RecoTrack > m_eclSeedRecoTracks
Output Reco Tracks Store Array.
double m_param_tanLambdaForwardNeg
Up to which (neg) tanLambda value should the seeding be performed.
double m_param_tanLambdaForwardPos
Up to which (pos) tanLambda value should the seeding be performed.
double m_param_showerDepth
Correction if the shower is assumed to start in a certain depth.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) override
Expose the parameters of the sub findlets.
Define states for CKF algorithm, which can be seed track or CDC wire hit.
Definition: CDCCKFState.h:27
static const ChargedStable pion
charged pion particle
Definition: Const.h:542
static const double speedOfLight
[cm/ns]
Definition: Const.h:575
@ c_nPhotons
CR is split into n photons (N1)
Definition: ECLShower.h:37
The Module parameter list class.
static genfit::AbsTrackRep * createOrReturnRKTrackRep(RecoTrack &recoTrack, int PDGcode)
Checks if a TrackRap for the PDG id of the RecoTrack (and its charge conjugate) does already exit and...
Definition: RecoTrack.cc:401
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:76
static void registerRequiredRelations(StoreArray< RecoTrack > &recoTracks, std::string const &pxdHitsStoreArrayName="", std::string const &svdHitsStoreArrayName="", std::string const &cdcHitsStoreArrayName="", std::string const &bklmHitsStoreArrayName="", std::string const &eklmHitsStoreArrayName="", std::string const &recoHitInformationStoreArrayName="")
Convenience method which registers all relations required to fully use a RecoTrack.
Definition: RecoTrack.cc:49
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
void initialize() override
Receive and dispatch signal before the start of the event processing.
Abstract base class for a track representation.
Definition: AbsTrackRep.h:66
Detector plane.
Definition: DetPlane.h:59
#StateOnPlane with additional covariance matrix.
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
Abstract base class for different kinds of events.
std::shared_ptr< genfit::DetPlane > SharedPlanePtr
Shared Pointer to a DetPlane.