Belle II Software  release-08-01-10
SegmentCreatorMCTruth.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/SegmentCreatorMCTruth.h>
9 
10 #include <tracking/trackFindingCDC/mclookup/CDCMCManager.h>
11 #include <tracking/trackFindingCDC/mclookup/CDCMCTrackStore.h>
12 #include <tracking/trackFindingCDC/mclookup/CDCSimHitLookUp.h>
13 
14 #include <tracking/trackFindingCDC/eventdata/segments/CDCSegment2D.h>
15 #include <tracking/trackFindingCDC/eventdata/segments/CDCRLWireHitSegment.h>
16 #include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
17 
18 #include <tracking/trackFindingCDC/eventdata/utils/FlightTimeEstimator.h>
19 
20 #include <tracking/trackFindingCDC/topology/CDCWire.h>
21 
22 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
23 #include <framework/core/ModuleParamList.templateDetails.h>
24 
25 #include <cdc/translators/RealisticTDCCountTranslator.h>
26 #include <cdc/dataobjects/CDCHit.h>
27 
28 #include <TRandom.h>
29 
30 using namespace Belle2;
31 using namespace TrackFindingCDC;
32 
33 void SegmentCreatorMCTruth::exposeParameters(ModuleParamList* moduleParamList, const std::string& prefix)
34 {
35  moduleParamList->addParameter(prefixed(prefix, "reconstructedDriftLength"),
37  "Switch to assign the reconstructed drift length to each hit, "
38  "as it can be estimated from two dimensional information only.",
40 
41  moduleParamList->addParameter(prefixed(prefix, "reconstructedPositions"),
43  "Switch to reconstruct the positions in the segments "
44  "immitating the facet ca picking up all correct hits.",
46 }
47 
49 {
50  return "Constructs segments from wire hits using the mc truth information.";
51 }
52 
53 
55 {
58 }
59 
60 
62 {
65 }
66 
67 void SegmentCreatorMCTruth::apply(const std::vector<CDCWireHit>& inputWireHits,
68  std::vector<CDCSegment2D>& outputSegments)
69 {
70  const CDCMCTrackStore& mcTrackStore = CDCMCTrackStore::getInstance();
71  const CDCSimHitLookUp& simHitLookUp = CDCSimHitLookUp::getInstance();
72 
73  using CDCHitVector = CDCMCTrackStore::CDCHitVector;
74 
75  const std::map<ITrackType, std::vector<CDCHitVector>>& mcSegmentsByMCParticleIdx =
76  mcTrackStore.getMCSegmentsByMCParticleIdx();
77 
78  std::size_t nSegments = 0;
79  for (const std::pair<ITrackType, std::vector<CDCHitVector>> mcSegmentsAndMCParticleIdx : mcSegmentsByMCParticleIdx) {
80  const std::vector<CDCHitVector>& mcSegments = mcSegmentsAndMCParticleIdx.second;
81  nSegments += mcSegments.size();
82  }
83 
84  outputSegments.reserve(outputSegments.size() + nSegments);
85  for (const std::pair<ITrackType, std::vector<CDCHitVector>> mcSegmentsAndMCParticleIdx : mcSegmentsByMCParticleIdx) {
86 
87  const std::vector<CDCHitVector>& mcSegments = mcSegmentsAndMCParticleIdx.second;
88  for (const CDCHitVector& mcSegment : mcSegments) {
89  outputSegments.push_back(CDCSegment2D());
90  CDCSegment2D& segment2D = outputSegments.back();
91  for (const CDCHit* ptrHit : mcSegment) {
92  const CDCWireHit* wireHit = simHitLookUp.getWireHit(ptrHit, inputWireHits);
93  if (not wireHit) continue;
94 
95  CDCRecoHit2D recoHit2D = simHitLookUp.getClosestPrimaryRecoHit2D(ptrHit, inputWireHits);
96  segment2D.push_back(recoHit2D);
97  }
98  if (segment2D.size() < 3) outputSegments.pop_back();
99  }
100  }
101 
102  CDC::RealisticTDCCountTranslator tdcCountTranslator;
103  const FlightTimeEstimator& flightTimeEstimator = FlightTimeEstimator::instance();
104  for (CDCSegment2D& segment : outputSegments) {
105  for (CDCRecoHit2D& recoHit2D : segment) {
106  Vector2D flightDirection = recoHit2D.getFlightDirection2D();
107  Vector2D recoPos2D = recoHit2D.getRecoPos2D();
108  double alpha = recoPos2D.angleWith(flightDirection);
109 
110  const CDCWire& wire = recoHit2D.getWire();
111  const CDCHit* hit = recoHit2D.getWireHit().getHit();
112  const bool rl = recoHit2D.getRLInfo() == ERightLeft::c_Right;
113 
114  double driftLength = recoHit2D.getRefDriftLength();
116  // Setup the drift length such that only information
117  // that would be present in two dimensional reconstruction is used
118  const double beta = 1;
119  double flightTimeEstimate = 0;
120  flightTimeEstimator.getFlightTime2D(recoPos2D, alpha, beta);
121 
122  driftLength =
123  tdcCountTranslator.getDriftLength(hit->getTDCCount(),
124  wire.getWireID(),
125  flightTimeEstimate,
126  rl,
127  wire.getRefZ(),
128  alpha);
129  } else {
130  // In case the true drift length should be kept at least smear it with its variance.
131  double driftLengthVariance = tdcCountTranslator.getDriftLengthResolution(driftLength,
132  wire.getWireID(),
133  rl,
134  wire.getRefZ(),
135  alpha);
136 
137  driftLength += gRandom->Gaus(0, std::sqrt(driftLengthVariance));
138  }
139  bool snapRecoPos = true;
140  recoHit2D.setRefDriftLength(driftLength, snapRecoPos);
141  }
142  }
143 
145  for (CDCSegment2D& segment : outputSegments) {
146  if (segment.size() > 1) {
147  CDCRLWireHitSegment rlWireHitSegment = segment.getRLWireHitSegment();
148  segment = CDCSegment2D::reconstructUsingFacets(rlWireHitSegment);
149  }
150  }
151  }
152 
153  for (CDCSegment2D& segment : outputSegments) {
154  segment.receiveISuperCluster();
155  }
156  std::sort(outputSegments.begin(), outputSegments.end());
157 }
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 getDriftLength(unsigned short tdcCount, const WireID &wireID=WireID(), double timeOfFlightEstimator=0, bool leftRight=false, double z=0, double alpha=0, double theta=static_cast< double >(TMath::Pi()/2.), unsigned short adcCount=0) override
Get Drift length.
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 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
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, std::vector< Belle2::TrackFindingCDC::CDCMCTrackStore::CDCHitVector > > & getMCSegmentsByMCParticleIdx() const
Getter for the stored Monte Carlo segments ordered by their Monte Carlo Id.
A segment consisting of two dimensional reconsturcted hits.
Class representing a two dimensional reconstructed hit in the central drift chamber.
Definition: CDCRecoHit2D.h:47
A reconstructed sequence of two dimensional hits in one super layer.
Definition: CDCSegment2D.h:39
static CDCSegment2D reconstructUsingFacets(const CDCRLWireHitSegment &rlWireHitSegment)
Reconstruct from wire hits with attached right left passage hypotheses by constructing facets between...
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 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.
void apply(const std::vector< CDCWireHit > &inputWireHits, std::vector< CDCSegment2D > &outputSegments) final
Main function of the segment finding by the cellular automaton.
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 segments immitating the facet ca picking up al...
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.