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