Belle II Software development
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/trackingUtilities/eventdata/segments/CDCSegment2D.h>
15#include <tracking/trackingUtilities/eventdata/segments/CDCRLWireHitSegment.h>
16#include <tracking/trackingUtilities/eventdata/hits/CDCWireHit.h>
17
18#include <tracking/trackFindingCDC/eventdata/utils/FlightTimeEstimator.h>
19
20#include <cdc/topology/CDCWire.h>
21
22#include <tracking/trackingUtilities/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
30using namespace Belle2;
31using namespace CDC;
32using namespace TrackFindingCDC;
33using namespace TrackingUtilities;
34
35void 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 "imitating 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
61
62
68
69void 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 for (CDCSegment2D& segment : outputSegments) {
106 for (CDCRecoHit2D& recoHit2D : segment) {
107 Vector2D flightDirection = recoHit2D.getFlightDirection2D();
108 Vector2D recoPos2D = recoHit2D.getRecoPos2D();
109 double alpha = recoPos2D.angleWith(flightDirection);
110
111 const CDCWire& wire = recoHit2D.getWire();
112 const CDCHit* hit = recoHit2D.getWireHit().getHit();
113 const bool rl = recoHit2D.getRLInfo() == ERightLeft::c_Right;
114
115 double driftLength = recoHit2D.getRefDriftLength();
117 // Setup the drift length such that only information
118 // that would be present in two dimensional reconstruction is used
119 const double beta = 1;
120 double flightTimeEstimate = 0;
121 FlightTimeEstimator::instance().getFlightTime2D(recoPos2D, alpha, beta);
122
123 driftLength =
124 tdcCountTranslator.getDriftLength(hit->getTDCCount(),
125 wire.getWireID(),
126 flightTimeEstimate,
127 rl,
128 wire.getRefZ(),
129 alpha);
130 } else {
131 // In case the true drift length should be kept at least smear it with its variance.
132 double driftLengthVariance = tdcCountTranslator.getDriftLengthResolution(driftLength,
133 wire.getWireID(),
134 rl,
135 wire.getRefZ(),
136 alpha);
137
138 driftLength += gRandom->Gaus(0, std::sqrt(driftLengthVariance));
139 }
140 bool snapRecoPos = true;
141 recoHit2D.setRefDriftLength(driftLength, snapRecoPos);
142 }
143 }
144
146 for (CDCSegment2D& segment : outputSegments) {
147 if (segment.size() > 1) {
148 CDCRLWireHitSegment rlWireHitSegment = segment.getRLWireHitSegment();
149 segment = CDCSegment2D::reconstructUsingFacets(rlWireHitSegment);
150 }
151 }
152 }
153
154 for (CDCSegment2D& segment : outputSegments) {
155 segment.receiveISuperCluster();
156 }
157 std::sort(outputSegments.begin(), outputSegments.end());
158}
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
Definition CDCHit.h:40
short getTDCCount() const
Getter for TDC count.
Definition CDCHit.h:219
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 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 singleton 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, std::vector< Belle2::TrackFindingCDC::CDCMCTrackStore::CDCHitVector > > & getMCSegmentsByMCParticleIdx() const
Getter for the stored Monte Carlo segments 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.
virtual double getFlightTime2D(const TrackingUtilities::Vector2D &, double, double=1) const
Default estimator for the flight time.
static const FlightTimeEstimator & instance(std::unique_ptr< FlightTimeEstimator > replacement=nullptr)
Getter for the instance.
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 imitating the facet ca picking up all...
void apply(const std::vector< TrackingUtilities::CDCWireHit > &inputWireHits, std::vector< TrackingUtilities::CDCSegment2D > &outputSegments) final
Main function of the segment finding by the cellular automaton.
A segment consisting of two dimensional reconstructed hits.
Class representing a two dimensional reconstructed hit in the central drift chamber.
A reconstructed sequence of two dimensional hits in one super layer.
static CDCSegment2D reconstructUsingFacets(const CDCRLWireHitSegment &rlWireHitSegment)
Reconstruct from wire hits with attached right left passage hypotheses by constructing facets between...
Class representing a hit wire in the central drift chamber.
Definition CDCWireHit.h:58
A two dimensional vector which is equipped with functions for correct handling of orientation relate...
Definition Vector2D.h:36
double angleWith(const Vector2D &rhs) const
The angle between this and rhs.
Definition Vector2D.h:228
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.