Belle II Software  release-08-01-10
AxialTrackCreatorMCTruth.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/trackFindingCDC/findlets/minimal/AxialTrackCreatorMCTruth.h>
9 
10 #include <tracking/trackFindingCDC/mclookup/CDCMCManager.h>
11 #include <tracking/trackFindingCDC/mclookup/CDCMCTrackStore.h>
12 #include <tracking/trackFindingCDC/mclookup/CDCSimHitLookUp.h>
13 #include <tracking/trackFindingCDC/mclookup/CDCMCTrackLookUp.h>
14 
15 #include <tracking/trackFindingCDC/processing/AxialTrackUtil.h>
16 #include <tracking/trackFindingCDC/fitting/CDCKarimakiFitter.h>
17 
18 #include <tracking/trackFindingCDC/eventdata/tracks/CDCTrack.h>
19 #include <tracking/trackFindingCDC/eventdata/hits/CDCRecoHit3D.h>
20 #include <tracking/trackFindingCDC/eventdata/hits/CDCRecoHit2D.h>
21 #include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
22 #include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectorySZ.h>
23 #include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectory2D.h>
24 
25 #include <tracking/trackFindingCDC/eventdata/utils/FlightTimeEstimator.h>
26 
27 #include <tracking/trackFindingCDC/topology/CDCWire.h>
28 
29 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
30 
31 #include <cdc/translators/RealisticTDCCountTranslator.h>
32 #include <cdc/dataobjects/CDCHit.h>
33 
34 #include <framework/core/ModuleParamList.templateDetails.h>
35 
36 #include <TRandom.h>
37 
38 using namespace Belle2;
39 using namespace TrackFindingCDC;
40 
41 void AxialTrackCreatorMCTruth::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
42 {
43  moduleParamList->addParameter(prefixed(prefix, "reconstructedDriftLength"),
45  "Switch to assign the reconstructed drift length to each hit, "
46  "as it can be estimated from two dimensional information only.",
48 
49  moduleParamList->addParameter(prefixed(prefix, "reconstructedPositions"),
51  "Switch to reconstruct the positions in the tracks "
52  "immitating the legendre finder.",
54 
55  moduleParamList->addParameter(prefixed(prefix, "fit"),
57  "Fit the track instead of forwarding the mc truth fit information",
58  m_param_fit);
59 
60  moduleParamList->addParameter(prefixed(prefix, "useOnlyBeforeTOP"),
62  "Cut tracks after the last layer of the CDC has been reached, "
63  "assuming the tracks left the CDC.",
65 }
66 
68 {
69  return "Constructs tracks from wire hits using the mc truth information.";
70 }
71 
72 
74 {
77 }
78 
79 
81 {
84 }
85 
86 void AxialTrackCreatorMCTruth::apply(const std::vector<CDCWireHit>& inputWireHits,
87  std::vector<CDCTrack>& outputAxialTracks)
88 {
89  const CDCMCTrackStore& mcTrackStore = CDCMCTrackStore::getInstance();
90  const CDCSimHitLookUp& simHitLookUp = CDCSimHitLookUp::getInstance();
91 
92  using CDCHitVector = CDCMCTrackStore::CDCHitVector;
93 
94  const std::map<ITrackType, CDCHitVector>& mcTracksByMCParticleIdx =
95  mcTrackStore.getMCTracksByMCParticleIdx();
96 
97  std::size_t nAxialTracks = mcTracksByMCParticleIdx.size();
98  outputAxialTracks.reserve(outputAxialTracks.size() + nAxialTracks);
99 
100  for (const std::pair<ITrackType, CDCHitVector> mcTracksAndMCParticleIdx : mcTracksByMCParticleIdx) {
101 
102  const CDCHitVector& mcTrack = mcTracksAndMCParticleIdx.second;
103 
104  outputAxialTracks.push_back(CDCTrack());
105  CDCTrack& axialTrack = outputAxialTracks.back();
106  bool reachedOuterMostLayer = false;
107  for (const CDCHit* ptrHit : mcTrack) {
108 
110  // Cut tracks after the outermost layer has been reached and
111  // the track starts to go inwards again.
112  // But let all hits in the outermost layer survive.
113  if (ptrHit->getISuperLayer() == 8 and ptrHit->getILayer() == 5) {
114  reachedOuterMostLayer = true;
115  }
116  if (reachedOuterMostLayer and ptrHit->getILayer() != 5) {
117  break;
118  }
119  }
120 
121  const CDCWireHit* wireHit = simHitLookUp.getWireHit(ptrHit, inputWireHits);
122  if (not wireHit) continue;
123 
124  CDCRecoHit2D recoHit2D = simHitLookUp.getClosestPrimaryRecoHit2D(ptrHit, inputWireHits);
125  if (not recoHit2D.isAxial()) continue;
126 
127  CDCRecoHit3D recoHit3D(recoHit2D.getRLWireHit(), {recoHit2D.getRecoPos2D(), 0}, NAN);
128  axialTrack.push_back(recoHit3D);
129  }
130 
131  // Discard short tracks
132  if (axialTrack.size() < 5) outputAxialTracks.pop_back();
133  }
134 
135  CDC::RealisticTDCCountTranslator tdcCountTranslator;
136  const FlightTimeEstimator& flightTimeEstimator = FlightTimeEstimator::instance();
137  for (CDCTrack& track : outputAxialTracks) {
138  for (CDCRecoHit3D& recoHit3D : track) {
139  Vector2D recoPos2D = recoHit3D.getRecoPos2D();
140  Vector2D flightDirection = recoHit3D.getFlightDirection2D();
141  double alpha = recoPos2D.angleWith(flightDirection);
142 
143  const CDCWire& wire = recoHit3D.getWire();
144  const bool rl = recoHit3D.getRLInfo() == ERightLeft::c_Right;
145 
146  double driftLength = std::fabs(recoHit3D.getSignedRecoDriftLength());
148  // Setup the drift length such that only information
149  // that would be present in two dimensional reconstruction is used
150  const double beta = 1;
151  flightTimeEstimator.getFlightTime2D(recoPos2D, alpha, beta);
152 
153  //TODO: for now this seems to be unused, (see following comment)
154  /*
155  double flightTimeEstimate = 0;
156  const CDCHit* hit = recoHit3D.getWireHit().getHit();
157  driftLength =
158  tdcCountTranslator.getDriftLength(hit->getTDCCount(),
159  wire.getWireID(),
160  flightTimeEstimate,
161  rl,
162  wire.getRefZ(),
163  alpha);
164  */
165 
166  // As the legendre finder does not reestimate the drift length
167  // We simply set it to the reference drift length for now.
168  // Use version above once the reestimation comes along.
169  driftLength = recoHit3D.getWireHit().getRefDriftLength();
170 
171  } else {
172  // In case the true drift length should be kept at least smear it with its variance.
173  double driftLengthVariance = tdcCountTranslator.getDriftLengthResolution(driftLength,
174  wire.getWireID(),
175  rl,
176  wire.getRefZ(),
177  alpha);
178 
179  driftLength += gRandom->Gaus(0, std::sqrt(driftLengthVariance));
180  }
181  bool snapRecoPos = true;
182  recoHit3D.setRecoDriftLength(driftLength, snapRecoPos);
183  }
184  }
185 
186  if (m_param_fit) {
187  CDCKarimakiFitter fitter;
188  for (CDCTrack& track : outputAxialTracks) {
189  CDCTrajectory2D trajectory2D = fitter.fit(track);
190  trajectory2D.setLocalOrigin(Vector2D(0.0, 0.0));
191  track.setStartTrajectory3D({trajectory2D, CDCTrajectorySZ::basicAssumption()});
192  }
193  } else {
194  const CDCMCTrackLookUp& mcTrackLookUp = CDCMCTrackLookUp::getInstance();
195  for (CDCTrack& track : outputAxialTracks) {
196  CDCTrajectory3D trajectory3D = mcTrackLookUp.getTrajectory3D(&track);
197  CDCTrajectory2D trajectory2D = trajectory3D.getTrajectory2D();
198  track.setStartTrajectory3D({trajectory2D, CDCTrajectorySZ::basicAssumption()});
199  }
200  }
201 
203  for (CDCTrack& track : outputAxialTracks) {
205  }
206  }
207 }
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
Definition: CDCHit.h:40
Translator mirroring the realistic Digitization.
double getDriftLengthResolution(double driftLength, const WireID &wireID=WireID(), bool leftRight=false, double z=0, double alpha=0, double=static_cast< double >(TMath::Pi()/2.)) override
Get position resolution^2 corresponding to the drift length from getDriftLength of this class.
The Module parameter list class.
void initialize() final
Initialize the Module before event processing.
bool m_param_reconstructedDriftLength
Parameter : Setup the drift length as it can be estimated from two dimensional information.
void beginEvent() final
Start processing the current event.
std::string getDescription() final
Short description of the findlet.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters to a module.
bool m_param_reconstructedPositions
Parameter : Switch to reconstruct the positions in the tracks immitating the legendre finder.
bool m_param_fit
Parameter : Fit the track instead of forwarding the mc truth information.
void apply(const std::vector< CDCWireHit > &inputWireHits, std::vector< CDCTrack > &outputAxialTracks) final
Main function of the track finding by the cellular automaton.
bool m_param_useOnlyBeforeTOP
Parameter : Cut tracks after the last layer of the CDC has been reached, assuming the tracks left the...
Class implementing the fitter using Karimakis method.
CDCTrajectory3D getTrajectory3D(const ACDCHitCollection *ptrHits) const
Returns the trajectory of the collection of hits.
void requireTruthInformation()
Require the mc information store arrays.
void fill()
Fill Monte Carlo look up maps from the DataStore.
static CDCMCManager & getInstance()
Getter for the singletone instance.
Definition: CDCMCManager.cc:74
Specialisation of the lookup for the truth values of reconstructed tracks.
static const CDCMCTrackLookUp & getInstance()
Getter for the singletone instance.
Class to organize and present the monte carlo hit information.
static const CDCMCTrackStore & getInstance()
Getter for the singletone instance.
std::vector< const CDCHit * > CDCHitVector
Type for an ordered sequence of pointers to the CDCHit.
const std::map< ITrackType, Belle2::TrackFindingCDC::CDCMCTrackStore::CDCHitVector > & getMCTracksByMCParticleIdx() const
Getter for the stored Monte Carlo tracks ordered by their Monte Carlo Id.
Class representing a two dimensional reconstructed hit in the central drift chamber.
Definition: CDCRecoHit2D.h:47
bool isAxial() const
Indicator if the underlying wire is axial.
Definition: CDCRecoHit2D.h:163
const CDCRLWireHit & getRLWireHit() const
Getter for the oriented wire hit assoziated with the reconstructed hit.
Definition: CDCRecoHit2D.h:281
Class representing a three dimensional reconstructed hit.
Definition: CDCRecoHit3D.h:52
Singletone class to gather local information about the hits.
static const CDCSimHitLookUp & getInstance()
Getter for the singletone instance.
const CDCWireHit * getWireHit(const CDCHit *ptrHit, const std::vector< CDCWireHit > &wireHits) const
Retrieve the wire hit the given CDCHit form the given wire hits.
CDCRecoHit2D getClosestPrimaryRecoHit2D(const CDCHit *ptrHit, const std::vector< CDCWireHit > &wireHits) const
Construct an CDCRecoHit2D from the closest primary CDCSimHit information related to the CDCHit.
Class representing a sequence of three dimensional reconstructed hits.
Definition: CDCTrack.h:41
Particle trajectory as it is seen in xy projection represented as a circle.
double setLocalOrigin(const Vector2D &localOrigin)
Setter for the origin of the local coordinate system.
Particle full three dimensional trajectory.
CDCTrajectory2D getTrajectory2D() const
Getter for the two dimensional trajectory.
static CDCTrajectorySZ basicAssumption()
Constucts a basic assumption, what the z0 start position and the sz slope are, including some broad v...
Class representing a hit wire in the central drift chamber.
Definition: CDCWireHit.h:55
Class representing a sense wire in the central drift chamber.
Definition: CDCWire.h:58
const WireID & getWireID() const
Getter for the wire id.
Definition: CDCWire.h:122
double getRefZ() const
Getter for the wire reference z coordinate Gives the wire's reference z coordinate.
Definition: CDCWire.h:236
void initialize() override
Receive and dispatch signal before the start of the event processing.
void beginEvent() override
Receive and dispatch signal for the start of a new event.
Helper struct to provide consistent flight time estimation throughout the CDC track finding.
static const FlightTimeEstimator & instance(std::unique_ptr< FlightTimeEstimator > replacement=nullptr)
Getter for the instance.
virtual double getFlightTime2D(const Vector2D &, double, double=1) const
Default estimator for the flight time.
A two dimensional vector which is equipped with functions for correct handeling of orientation relat...
Definition: Vector2D.h:35
double angleWith(const Vector2D &rhs) const
The angle between this and rhs.
Definition: Vector2D.h:209
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.
static void normalizeTrack(CDCTrack &track)
Refit and resort the track. Unmask all hits.