Belle II Software development
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/trackingUtilities/eventdata/tracks/CDCTrack.h>
19#include <tracking/trackingUtilities/eventdata/hits/CDCRecoHit3D.h>
20#include <tracking/trackingUtilities/eventdata/hits/CDCRecoHit2D.h>
21#include <tracking/trackingUtilities/eventdata/hits/CDCWireHit.h>
22#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectorySZ.h>
23#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectory2D.h>
24
25#include <tracking/trackFindingCDC/eventdata/utils/FlightTimeEstimator.h>
26
27#include <cdc/topology/CDCWire.h>
28
29#include <tracking/trackingUtilities/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 <Math/Vector2D.h>
37#include <Math/VectorUtil.h>
38#include <TRandom.h>
39
40using namespace Belle2;
41using namespace CDC;
42using namespace TrackFindingCDC;
43using namespace TrackingUtilities;
44
45void AxialTrackCreatorMCTruth::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
46{
47 moduleParamList->addParameter(prefixed(prefix, "reconstructedDriftLength"),
49 "Switch to assign the reconstructed drift length to each hit, "
50 "as it can be estimated from two dimensional information only.",
52
53 moduleParamList->addParameter(prefixed(prefix, "reconstructedPositions"),
55 "Switch to reconstruct the positions in the tracks "
56 "imitating the Legendre finder.",
58
59 moduleParamList->addParameter(prefixed(prefix, "fit"),
61 "Fit the track instead of forwarding the mc truth fit information",
63
64 moduleParamList->addParameter(prefixed(prefix, "useOnlyBeforeTOP"),
66 "Cut tracks after the last layer of the CDC has been reached, "
67 "assuming the tracks left the CDC.",
69}
70
72{
73 return "Constructs tracks from wire hits using the MC truth information.";
74}
75
76
82
83
89
90void AxialTrackCreatorMCTruth::apply(const std::vector<CDCWireHit>& inputWireHits,
91 std::vector<CDCTrack>& outputAxialTracks)
92{
93 const CDCMCTrackStore& mcTrackStore = CDCMCTrackStore::getInstance();
94 const CDCSimHitLookUp& simHitLookUp = CDCSimHitLookUp::getInstance();
95
96 using CDCHitVector = CDCMCTrackStore::CDCHitVector;
97
98 const std::map<ITrackType, CDCHitVector>& mcTracksByMCParticleIdx =
99 mcTrackStore.getMCTracksByMCParticleIdx();
100
101 std::size_t nAxialTracks = mcTracksByMCParticleIdx.size();
102 outputAxialTracks.reserve(outputAxialTracks.size() + nAxialTracks);
103
104 for (const std::pair<ITrackType, CDCHitVector> mcTracksAndMCParticleIdx : mcTracksByMCParticleIdx) {
105
106 const CDCHitVector& mcTrack = mcTracksAndMCParticleIdx.second;
107
108 outputAxialTracks.push_back(CDCTrack());
109 CDCTrack& axialTrack = outputAxialTracks.back();
110 bool reachedOuterMostLayer = false;
111 for (const CDCHit* ptrHit : mcTrack) {
112
114 // Cut tracks after the outermost layer has been reached and
115 // the track starts to go inwards again.
116 // But let all hits in the outermost layer survive.
117 if (ptrHit->getISuperLayer() == 8 and ptrHit->getILayer() == 5) {
118 reachedOuterMostLayer = true;
119 }
120 if (reachedOuterMostLayer and ptrHit->getILayer() != 5) {
121 break;
122 }
123 }
124
125 const CDCWireHit* wireHit = simHitLookUp.getWireHit(ptrHit, inputWireHits);
126 if (not wireHit) continue;
127
128 CDCRecoHit2D recoHit2D = simHitLookUp.getClosestPrimaryRecoHit2D(ptrHit, inputWireHits);
129 if (not recoHit2D.isAxial()) continue;
130
131 const auto& tmp = recoHit2D.getRecoPos2D();
132 CDCRecoHit3D recoHit3D(recoHit2D.getRLWireHit(), {tmp.X(), tmp.Y(), 0}, NAN);
133 axialTrack.push_back(recoHit3D);
134 }
135
136 // Discard short tracks
137 if (axialTrack.size() < 5) outputAxialTracks.pop_back();
138 }
139
140 CDC::RealisticTDCCountTranslator tdcCountTranslator;
141 for (CDCTrack& track : outputAxialTracks) {
142 for (CDCRecoHit3D& recoHit3D : track) {
143 ROOT::Math::XYVector recoPos2D = recoHit3D.getRecoPos2D();
144 ROOT::Math::XYVector flightDirection = recoHit3D.getFlightDirection2D();
145 double alpha = ROOT::Math::VectorUtil::DeltaPhi(recoPos2D, flightDirection);
146
147 const CDCWire& wire = recoHit3D.getWire();
148 const bool rl = recoHit3D.getRLInfo() == ERightLeft::c_Right;
149
150 double driftLength = std::fabs(recoHit3D.getSignedRecoDriftLength());
152 // Setup the drift length such that only information
153 // that would be present in two dimensional reconstruction is used
154 const double beta = 1;
155 FlightTimeEstimator::instance().getFlightTime2D(recoPos2D, alpha, beta);
156
157 //TODO: for now this seems to be unused, (see following comment)
158 /*
159 double flightTimeEstimate = 0;
160 const CDCHit* hit = recoHit3D.getWireHit().getHit();
161 driftLength =
162 tdcCountTranslator.getDriftLength(hit->getTDCCount(),
163 wire.getWireID(),
164 flightTimeEstimate,
165 rl,
166 wire.getRefZ(),
167 alpha);
168 */
169
170 // As the legendre finder does not reestimate the drift length
171 // We simply set it to the reference drift length for now.
172 // Use version above once the reestimation comes along.
173 driftLength = recoHit3D.getWireHit().getRefDriftLength();
174
175 } else {
176 // In case the true drift length should be kept at least smear it with its variance.
177 double driftLengthVariance = tdcCountTranslator.getDriftLengthResolution(driftLength,
178 wire.getWireID(),
179 rl,
180 wire.getRefZ(),
181 alpha);
182
183 driftLength += gRandom->Gaus(0, std::sqrt(driftLengthVariance));
184 }
185 bool snapRecoPos = true;
186 recoHit3D.setRecoDriftLength(driftLength, snapRecoPos);
187 }
188 }
189
190 if (m_param_fit) {
191 CDCKarimakiFitter fitter;
192 for (CDCTrack& track : outputAxialTracks) {
193 CDCTrajectory2D trajectory2D = fitter.fit(track);
194 trajectory2D.setLocalOrigin(ROOT::Math::XYVector(0.0, 0.0));
195 track.setStartTrajectory3D({trajectory2D, CDCTrajectorySZ::basicAssumption()});
196 }
197 } else {
198 const CDCMCTrackLookUp& mcTrackLookUp = CDCMCTrackLookUp::getInstance();
199 for (CDCTrack& track : outputAxialTracks) {
200 CDCTrajectory3D trajectory3D = mcTrackLookUp.getTrajectory3D(&track);
201 CDCTrajectory2D trajectory2D = trajectory3D.getTrajectory2D();
202 track.setStartTrajectory3D({trajectory2D, CDCTrajectorySZ::basicAssumption()});
203 }
204 }
205
207 for (CDCTrack& track : outputAxialTracks) {
209 }
210 }
211}
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
Definition CDCHit.h:40
Class representing a sense wire in the central drift chamber.
Definition CDCWire.h:50
const WireID & getWireID() const
Getter for the wire id.
Definition CDCWire.h:114
double getRefZ() const
Getter for the wire reference z coordinate Gives the wire's reference z coordinate.
Definition CDCWire.h:228
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.
void apply(const std::vector< TrackingUtilities::CDCWireHit > &inputWireHits, std::vector< TrackingUtilities::CDCTrack > &outputAxialTracks) final
Main function of the track finding by the cellular automaton.
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 imitating the Legendre finder.
bool m_param_fit
Parameter : Fit the track instead of forwarding the MC truth information.
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.
TrackingUtilities::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 singleton instance.
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.
Singletone class to gather local information about the hits.
static const CDCSimHitLookUp & getInstance()
Getter for the singletone instance.
TrackingUtilities::CDCRecoHit2D getClosestPrimaryRecoHit2D(const CDCHit *ptrHit, const std::vector< TrackingUtilities::CDCWireHit > &wireHits) const
Construct an TrackingUtilities::CDCRecoHit2D from the closest primary CDCSimHit information related t...
const TrackingUtilities::CDCWireHit * getWireHit(const CDCHit *ptrHit, const std::vector< TrackingUtilities::CDCWireHit > &wireHits) const
Retrieve the wire hit the given CDCHit form the given wire hits.
static const FlightTimeEstimator & instance(std::unique_ptr< FlightTimeEstimator > replacement=nullptr)
Getter for the instance.
virtual double getFlightTime2D(const ROOT::Math::XYVector &, double, double=1) const
Default estimator for the flight time.
Class representing a two dimensional reconstructed hit in the central drift chamber.
const CDCRLWireHit & getRLWireHit() const
Getter for the oriented wire hit associated with the reconstructed hit.
bool isAxial() const
Indicator if the underlying wire is axial.
ROOT::Math::XYVector getRecoPos2D() const
Getter for the position in the reference plane.
Class representing a three dimensional reconstructed hit.
Class representing a sequence of three dimensional reconstructed hits.
Definition CDCTrack.h:37
Particle trajectory as it is seen in xy projection represented as a circle.
double setLocalOrigin(const ROOT::Math::XYVector &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()
Constructs a basic assumption, what the z0 start position and the sz slope are, including some broad ...
Class representing a hit wire in the central drift chamber.
Definition CDCWireHit.h:56
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.
static void normalizeTrack(TrackingUtilities::CDCTrack &track)
Refit and resort the track. Unmask all hits.