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