Belle II Software development
CDCMCMap Class Reference

Class to organize and present the Monte Carlo hit information. More...

#include <CDCMCMap.h>

Public Member Functions

 CDCMCMap ()=default
 Default constructor, needs to be public for initialization in CDCMCManager.
 
CDCMCMapoperator= (const CDCMCMap &)=delete
 Delete the assignment operator in order to avoid accidental copies.
 
 CDCMCMap (CDCMCMap &)=delete
 For the same reason, also delete copy constructor.
 
void clear ()
 Clear all information from the former event.
 
void fill ()
 Fill the Monte Carlo information retrieved from the DataStore into the local multimaps.
 
TrackingUtilities::MayBePtr< const CDCSimHitgetSimHit (const CDCHit *hit) const
 Seeks the CDCSimHit related to the CDCHit.
 
TrackingUtilities::MayBePtr< const CDCHitgetHit (const CDCSimHit *simHit) const
 Seeks the CDCHit related to the CDCSimHit - nullptr if no CDCHit is related.
 
bool isBackground (const CDCSimHit *simHit) const
 Indicates if the CDCSimHit is considered background.
 
bool isBackground (const CDCHit *hit) const
 Indicates if the CDCSimHit is considered background.
 
TrackingUtilities::MayBePtr< const MCParticlegetMCParticle (const CDCHit *hit) const
 Seeks the MCParticle related to the CDCHit.
 
TrackingUtilities::MayBePtr< const MCParticlegetMCParticle (const CDCSimHit *simHit) const
 Seeks the MCParticle related to the CDCSimHit.
 
auto getSimHits (const MCParticle *mcParticle) const
 Getter for the range MCParticle to CDCSimHits relations which come from the given MCParticle.
 
auto getHits (const MCParticle *mcParticle) const
 Getter for the range MCParticle to CDCHits relations which come from the given MCParticle.
 
bool isReassignedSecondary (const CDCSimHit *ptrSimHit) const
 Indicates if the CDCSimHit has been reassigned to a primary MCParticle.
 
bool isReassignedSecondary (const CDCHit *ptrHit) const
 Indicates if the CDCHit has been reassigned to a primary MCParticle.
 
const std::set< const CDCHit * > & getReassignedSecondaryHits () const
 Getter for all reassigned secondary CDCHits.
 
const std::set< const CDCSimHit * > & getReassignedSecondarySimHits () const
 Getter for all reassigned secondary CDCSimHits.
 
const std::multimap< const CDCHit *, const CDCSimHit * > & getSimHitsByHit () const
 Getter for the CDCHit -> CDCSimHit relations.
 
const std::multimap< const MCParticle *, const CDCHit * > & getHitsByMCParticle () const
 Getter for the MCParticle -> CDCHit relations.
 
const std::multimap< const MCParticle *, const CDCSimHit * > & getSimHitsByMCParticle () const
 Getter for the MCParticle -> CDCSimHit relations.
 

Private Member Functions

void fillSimHitByHitMap ()
 Retrieve the relations array from CDCSimHits to CDCHits and fill it in to the local map which does the inverse mapping.
 
void fillMCParticleByHitMap ()
 Retrieve the relations array from MCParticle to CDCHits and fill it in to the local map which does the inverse mapping.
 
void fillMCParticleBySimHitMap ()
 Retrieve the relations array from MCParticle to CDCSimHits and fill it in to the local map which does the inverse mapping.
 
void validateRelations () const
 Checks if the relations CDCHit -> MCParticle and CDCHit -> CDCSimHit -> MCParticle commute.
 
void validateReassignedSecondaries () const
 Checks if each CDCHit is marked as reassigned secondary is related to a reassigned secondary CDCSimHit.
 

Static Private Member Functions

static bool indicatesReassignedSecondary (double weight)
 Indicate if the given weight suggests that the corresponding hit to MCParticle relation has been redirected to point to a primary particle instead of the discarded secondary particle.
 

Private Attributes

std::multimap< const CDCHit *, const CDCSimHit * > m_simHitsByHit
 Memory for a one to one relation from CDCHit to CDCSimHits.
 
std::multimap< const MCParticle *, const CDCHit * > m_hitsByMCParticle
 Memory for a one to n relation from MCParticles to CDCHit.
 
std::multimap< const MCParticle *, const CDCSimHit * > m_simHitsByMCParticle
 Memory for a one to n relation from MCParticles to CDCSimHit.
 
std::set< const CDCHit * > m_reassignedSecondaryHits
 The set of reassigned secondary CDCHits.
 
std::set< const CDCSimHit * > m_reassignedSecondarySimHits
 The set of reassigned secondary CDCSimHits.
 

Detailed Description

Class to organize and present the Monte Carlo hit information.

Definition at line 28 of file CDCMCMap.h.

Member Function Documentation

◆ clear()

void clear ( )

Clear all information from the former event.

Definition at line 33 of file CDCMCMap.cc.

34{
35 B2DEBUG(25, "In CDCMCMap::clear()");
36 m_simHitsByHit.clear();
37
38 m_hitsByMCParticle.clear();
40
43}
std::set< const CDCHit * > m_reassignedSecondaryHits
The set of reassigned secondary CDCHits.
Definition CDCMCMap.h:162
std::set< const CDCSimHit * > m_reassignedSecondarySimHits
The set of reassigned secondary CDCSimHits.
Definition CDCMCMap.h:165
std::multimap< const CDCHit *, const CDCSimHit * > m_simHitsByHit
Memory for a one to one relation from CDCHit to CDCSimHits.
Definition CDCMCMap.h:153
std::multimap< const MCParticle *, const CDCHit * > m_hitsByMCParticle
Memory for a one to n relation from MCParticles to CDCHit.
Definition CDCMCMap.h:156
std::multimap< const MCParticle *, const CDCSimHit * > m_simHitsByMCParticle
Memory for a one to n relation from MCParticles to CDCSimHit.
Definition CDCMCMap.h:159

◆ fill()

void fill ( )

Fill the Monte Carlo information retrieved from the DataStore into the local multimaps.

Definition at line 45 of file CDCMCMap.cc.

46{
47 B2DEBUG(25, "In CDCMCMap::fill()");
48 clear();
49
53
56
57 B2DEBUG(25, "m_simHitsByHit.size(): " << m_simHitsByHit.size());
58
59 B2DEBUG(25, "m_hitsByMCParticle.size(): " << m_hitsByMCParticle.size());
60 B2DEBUG(25, "m_simHitsByMCParticle.size(): " << m_simHitsByMCParticle.size());
61
62 B2DEBUG(25, "m_reassignedSecondaryHits.size(): " << m_reassignedSecondaryHits.size());
63 B2DEBUG(25, "m_reassignedSecondarySimHits.size(): " << m_reassignedSecondarySimHits.size());
64}
void fillSimHitByHitMap()
Retrieve the relations array from CDCSimHits to CDCHits and fill it in to the local map which does th...
Definition CDCMCMap.cc:66
void validateRelations() const
Checks if the relations CDCHit -> MCParticle and CDCHit -> CDCSimHit -> MCParticle commute.
Definition CDCMCMap.cc:220
void fillMCParticleByHitMap()
Retrieve the relations array from MCParticle to CDCHits and fill it in to the local map which does th...
Definition CDCMCMap.cc:104
void fillMCParticleBySimHitMap()
Retrieve the relations array from MCParticle to CDCSimHits and fill it in to the local map which does...
Definition CDCMCMap.cc:186
void clear()
Clear all information from the former event.
Definition CDCMCMap.cc:33
void validateReassignedSecondaries() const
Checks if each CDCHit is marked as reassigned secondary is related to a reassigned secondary CDCSimHi...
Definition CDCMCMap.cc:239

◆ fillMCParticleByHitMap()

void fillMCParticleByHitMap ( )
private

Retrieve the relations array from MCParticle to CDCHits and fill it in to the local map which does the inverse mapping.

Definition at line 104 of file CDCMCMap.cc.

105{
106 StoreArray<CDCHit> hits;
107
108 std::map<const MCParticle*, std::vector<const CDCSimHit*>> primarySimHitsByMCParticle;
109
110 for (const CDCHit& hit : hits) {
111 const CDCHit* ptrHit = &hit;
112 RelationVector<MCParticle> relatedMCParticles = hit.getRelationsFrom<MCParticle>();
113
114 const int nRelatedMCParticles = relatedMCParticles.size();
115
116 if (nRelatedMCParticles == 0 and not isBackground(ptrHit)) {
117 B2WARNING("CDCHit has no related MCParticle but CDCHit indicates that it is no "
118 "background in CDCMCMap::fill()");
119 }
120
121 if (nRelatedMCParticles > 1) {
122 B2WARNING("CDCHit as more than one related MCParticle - reorganize the mapping");
123 }
124
125 // Pickup an iterator for hinted insertion
126 auto itInsertHint = m_hitsByMCParticle.end();
127 for (int iRelatedMCParticle = 0; iRelatedMCParticle < nRelatedMCParticles; ++iRelatedMCParticle) {
128 const MCParticle* ptrMCParticle = relatedMCParticles[iRelatedMCParticle];
129 double weight = relatedMCParticles.weight(iRelatedMCParticle);
130
131 if (indicatesReassignedSecondary(weight)) {
132 m_reassignedSecondaryHits.insert(ptrHit);
133 } else {
134 const CDCSimHit* ptrSimHit = ptrHit->getRelatedFrom<CDCSimHit>();
135 if (ptrMCParticle->isPrimaryParticle() and ptrSimHit) {
136 primarySimHitsByMCParticle[ptrMCParticle].push_back(ptrSimHit);
137 }
138 }
139
140 itInsertHint = m_hitsByMCParticle.insert(itInsertHint, {ptrMCParticle, ptrHit});
141 }
142 }
143
144 // Check time ordering of primary hits
145 int nSortedIncorretly = 0;
146 auto lessFlightTime = [](const CDCSimHit * lhs, const CDCSimHit * rhs) {
147 return lhs->getFlightTime() < rhs->getFlightTime();
148 };
149
150 auto lessArrayIndex = [](const CDCSimHit * lhs, const CDCSimHit * rhs) -> bool {
151 return lhs->getArrayIndex() < rhs->getArrayIndex();
152 };
153
154 for (std::pair<const MCParticle* const, std::vector<const CDCSimHit*>>&
155 primarySimHitsForMCParticle : primarySimHitsByMCParticle) {
156
157 const MCParticle* ptrMCParticle = primarySimHitsForMCParticle.first;
158 std::vector<const CDCSimHit*>& simHits = primarySimHitsForMCParticle.second;
159 std::sort(simHits.begin(), simHits.end(), lessArrayIndex);
160 auto itSorted = std::is_sorted_until(simHits.begin(), simHits.end(), lessFlightTime);
161 if (itSorted != simHits.end()) {
162 ++nSortedIncorretly;
163 B2DEBUG(25,
164 "CDCSimHits for MCParticle " << ptrMCParticle->getArrayIndex()
165 << " only sorted correctly up to hit number "
166 << std::distance(simHits.begin(), itSorted));
167 --itSorted;
168 B2DEBUG(25,
169 "Between wire " << (*itSorted)->getWireID() << " " << (*itSorted)->getFlightTime()
170 << "ns "
171 << (*itSorted)->getArrayIndex());
172 ++itSorted;
173 B2DEBUG(25,
174 "and wire " << (*itSorted)->getWireID() << " " << (*itSorted)->getFlightTime()
175 << "ns "
176 << (*itSorted)->getArrayIndex());
177 }
178 }
179 if (nSortedIncorretly) {
180 B2WARNING("(BII-2136) CDCSimHits for "
181 << nSortedIncorretly
182 << " primary mc particles are not sorted correctly by their time of flight");
183 }
184}
double getFlightTime() const
The method to get flight time.
Definition CDCSimHit.h:183
int getArrayIndex() const
Get 0-based index of the particle in the corresponding MCParticle list.
Definition MCParticle.h:233
size_t size() const
Get number of relations.
float weight(int index) const
Get weight with index.
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
FROM * getRelatedFrom(const std::string &name="", const std::string &namedRelation="") const
Get the object from which this object has a relation.
bool isBackground(const CDCSimHit *simHit) const
Indicates if the CDCSimHit is considered background.
Definition CDCMCMap.cc:260
static bool indicatesReassignedSecondary(double weight)
Indicate if the given weight suggests that the corresponding hit to MCParticle relation has been redi...
Definition CDCMCMap.h:52
bool isPrimaryParticle() const
Check if particle is a primary particle which was created by the generator (and not,...
Definition MCParticle.h:585

◆ fillMCParticleBySimHitMap()

void fillMCParticleBySimHitMap ( )
private

Retrieve the relations array from MCParticle to CDCSimHits and fill it in to the local map which does the inverse mapping.

Definition at line 186 of file CDCMCMap.cc.

187{
188 StoreArray<CDCSimHit> simHits;
189
190 for (const CDCSimHit& simHit : simHits) {
191 const CDCSimHit* ptrSimHit = &simHit;
192 RelationVector<MCParticle> relatedMCParticles = simHit.getRelationsFrom<MCParticle>();
193
194 const int nRelatedMCParticles = relatedMCParticles.size();
195
196 if (nRelatedMCParticles == 0 and not isBackground(ptrSimHit)) {
197 B2WARNING("CDCSimHit has no related MCParticle but CDCSimHit indicates that it is no "
198 "background in CDCMCMap::fill()");
199 }
200
201 if (nRelatedMCParticles > 1) {
202 B2WARNING("CDCSimHit as more than one related MCParticle - reorganize the mapping");
203 }
204
205 // Pickup an iterator for hinted insertion
206 auto itInsertHint = m_simHitsByMCParticle.end();
207 for (int iRelatedMCParticle = 0; iRelatedMCParticle < nRelatedMCParticles; ++iRelatedMCParticle) {
208 const MCParticle* ptrMCParticle = relatedMCParticles[iRelatedMCParticle];
209 double weight = relatedMCParticles.weight(iRelatedMCParticle);
210
211 if (indicatesReassignedSecondary(weight)) {
212 m_reassignedSecondarySimHits.insert(ptrSimHit);
213 }
214
215 itInsertHint = m_simHitsByMCParticle.insert(itInsertHint, {ptrMCParticle, ptrSimHit});
216 }
217 }
218}

◆ fillSimHitByHitMap()

void fillSimHitByHitMap ( )
private

Retrieve the relations array from CDCSimHits to CDCHits and fill it in to the local map which does the inverse mapping.

Definition at line 66 of file CDCMCMap.cc.

67{
68 StoreArray<CDCSimHit> simHits;
69 StoreArray<CDCHit> hits;
70
71 // Pickup an iterator for hinted insertion
72 auto itInsertHint = m_simHitsByHit.end();
73
74 for (const CDCSimHit& simHit : simHits) {
75 const CDCSimHit* ptrSimHit = &simHit;
76 RelationVector<CDCHit> relatedHits = simHit.getRelationsTo<CDCHit>();
77
78 int nRelatedHits = relatedHits.size();
79 if (nRelatedHits > 1) {
80 B2WARNING("CDCSimHit as more than one related CDCHit - reorganize the mapping");
81 }
82
83 for (const CDCHit& hit : relatedHits) {
84 const CDCHit* ptrHit = &hit;
85
86 if (m_simHitsByHit.count(ptrHit) != 0) {
87 B2WARNING("CDCHit as more than one related CDCSimHit - reorganize the mapping");
88 }
89
90 itInsertHint = m_simHitsByHit.insert(itInsertHint, {ptrHit, ptrSimHit});
91 }
92 }
93
94 // Check if every hit has a corresponding simulated hit
95 for (const CDCHit& hit : hits) {
96 const CDCHit* ptrHit = &hit;
97
98 if (m_simHitsByHit.count(ptrHit) == 0) {
99 B2WARNING("CDCHit has no related CDCSimHit in CDCMCMap::fill()");
100 }
101 }
102}

◆ getHit()

MayBePtr< const CDCHit > getHit ( const CDCSimHit * simHit) const

Seeks the CDCHit related to the CDCSimHit - nullptr if no CDCHit is related.

Definition at line 255 of file CDCMCMap.cc.

256{
257 return simHit ? simHit->getRelated<CDCHit>() : nullptr;
258}
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.

◆ getHits()

auto getHits ( const MCParticle * mcParticle) const
inline

Getter for the range MCParticle to CDCHits relations which come from the given MCParticle.

Definition at line 104 of file CDCMCMap.h.

105 {
106 return TrackingUtilities::asRange(m_hitsByMCParticle.equal_range(mcParticle));
107 }

◆ getHitsByMCParticle()

const std::multimap< const MCParticle *, const CDCHit * > & getHitsByMCParticle ( ) const
inline

Getter for the MCParticle -> CDCHit relations.

Definition at line 140 of file CDCMCMap.h.

141 {
142 return m_hitsByMCParticle;
143 }

◆ getMCParticle() [1/2]

MayBePtr< const MCParticle > getMCParticle ( const CDCHit * hit) const

Seeks the MCParticle related to the CDCHit.

Nullptr if no MCParticle is related, this is also the case for background hits.

Definition at line 270 of file CDCMCMap.cc.

271{
272 return hit ? hit->getRelated<MCParticle>() : nullptr;
273}

◆ getMCParticle() [2/2]

MayBePtr< const MCParticle > getMCParticle ( const CDCSimHit * simHit) const

Seeks the MCParticle related to the CDCSimHit.

Nullptr if no MCParticle is related, this is also the case for background hits.

Definition at line 275 of file CDCMCMap.cc.

276{
277 return simHit ? simHit->getRelated<MCParticle>() : nullptr;
278}

◆ getReassignedSecondaryHits()

const std::set< const CDCHit * > & getReassignedSecondaryHits ( ) const
inline

Getter for all reassigned secondary CDCHits.

Definition at line 122 of file CDCMCMap.h.

123 {
124 return m_reassignedSecondaryHits;
125 }

◆ getReassignedSecondarySimHits()

const std::set< const CDCSimHit * > & getReassignedSecondarySimHits ( ) const
inline

Getter for all reassigned secondary CDCSimHits.

Definition at line 128 of file CDCMCMap.h.

129 {
130 return m_reassignedSecondarySimHits;
131 }

◆ getSimHit()

MayBePtr< const CDCSimHit > getSimHit ( const CDCHit * hit) const

Seeks the CDCSimHit related to the CDCHit.

Definition at line 250 of file CDCMCMap.cc.

251{
252 return hit ? hit->getRelated<CDCSimHit>() : nullptr;
253}

◆ getSimHits()

auto getSimHits ( const MCParticle * mcParticle) const
inline

Getter for the range MCParticle to CDCSimHits relations which come from the given MCParticle.

Definition at line 98 of file CDCMCMap.h.

99 {
100 return TrackingUtilities::asRange(m_simHitsByMCParticle.equal_range(mcParticle));
101 }

◆ getSimHitsByHit()

const std::multimap< const CDCHit *, const CDCSimHit * > & getSimHitsByHit ( ) const
inline

Getter for the CDCHit -> CDCSimHit relations.

Definition at line 134 of file CDCMCMap.h.

135 {
136 return m_simHitsByHit;
137 }

◆ getSimHitsByMCParticle()

const std::multimap< const MCParticle *, const CDCSimHit * > & getSimHitsByMCParticle ( ) const
inline

Getter for the MCParticle -> CDCSimHit relations.

Definition at line 146 of file CDCMCMap.h.

147 {
148 return m_simHitsByMCParticle;
149 }

◆ indicatesReassignedSecondary()

static bool indicatesReassignedSecondary ( double weight)
inlinestaticprivate

Indicate if the given weight suggests that the corresponding hit to MCParticle relation has been redirected to point to a primary particle instead of the discarded secondary particle.

Definition at line 52 of file CDCMCMap.h.

53 {
54 return weight <= 0;
55 }

◆ isBackground() [1/2]

bool isBackground ( const CDCHit * hit) const

Indicates if the CDCSimHit is considered background.

Definition at line 265 of file CDCMCMap.cc.

266{
267 return isBackground(getSimHit(hit));
268}
TrackingUtilities::MayBePtr< const CDCSimHit > getSimHit(const CDCHit *hit) const
Seeks the CDCSimHit related to the CDCHit.
Definition CDCMCMap.cc:250

◆ isBackground() [2/2]

bool isBackground ( const CDCSimHit * simHit) const

Indicates if the CDCSimHit is considered background.

Definition at line 260 of file CDCMCMap.cc.

261{
262 return simHit ? simHit->getBackgroundTag() != BackgroundMetaData::bg_none : false;
263}
virtual unsigned short getBackgroundTag() const
Get background tag.
Definition SimHitBase.h:46

◆ isReassignedSecondary() [1/2]

bool isReassignedSecondary ( const CDCHit * ptrHit) const
inline

Indicates if the CDCHit has been reassigned to a primary MCParticle.

Definition at line 116 of file CDCMCMap.h.

117 {
118 return m_reassignedSecondaryHits.count(ptrHit) > 0;
119 }

◆ isReassignedSecondary() [2/2]

bool isReassignedSecondary ( const CDCSimHit * ptrSimHit) const
inline

Indicates if the CDCSimHit has been reassigned to a primary MCParticle.

Definition at line 110 of file CDCMCMap.h.

111 {
112 return m_reassignedSecondarySimHits.count(ptrSimHit) > 0;
113 }

◆ validateReassignedSecondaries()

void validateReassignedSecondaries ( ) const
private

Checks if each CDCHit is marked as reassigned secondary is related to a reassigned secondary CDCSimHit.

Definition at line 239 of file CDCMCMap.cc.

240{
241 for (const CDCHit* ptrHit : m_reassignedSecondaryHits) {
242
243 const CDCSimHit* ptrSimHit = getSimHit(ptrHit);
244 if (not isReassignedSecondary(ptrSimHit)) {
245 B2WARNING("CDCHit is reassigned secondary but related CDCSimHit is not.");
246 }
247 }
248}
bool isReassignedSecondary(const CDCSimHit *ptrSimHit) const
Indicates if the CDCSimHit has been reassigned to a primary MCParticle.
Definition CDCMCMap.h:110

◆ validateRelations()

void validateRelations ( ) const
private

Checks if the relations CDCHit -> MCParticle and CDCHit -> CDCSimHit -> MCParticle commute.

Definition at line 220 of file CDCMCMap.cc.

221{
222 StoreArray<CDCHit> hits;
223
224 for (const CDCHit& hit : hits) {
225 const CDCHit* ptrHit = &hit;
226
227 const CDCSimHit* ptrSimHit = getSimHit(ptrHit);
228 const MCParticle* ptrMCParticle = getMCParticle(ptrHit);
229
230 const MCParticle* ptrMCParticleFromSimHit = getMCParticle(ptrSimHit);
231
232 if (ptrMCParticle != ptrMCParticleFromSimHit) {
233 B2WARNING("MCParticle from CDCHit and MCParticle from related CDCSimHit mismatch in "
234 "CDCMCMap::validateRelations()");
235 }
236 }
237}
TrackingUtilities::MayBePtr< const MCParticle > getMCParticle(const CDCHit *hit) const
Seeks the MCParticle related to the CDCHit.
Definition CDCMCMap.cc:270

Member Data Documentation

◆ m_hitsByMCParticle

std::multimap<const MCParticle*, const CDCHit*> m_hitsByMCParticle
private

Memory for a one to n relation from MCParticles to CDCHit.

Definition at line 156 of file CDCMCMap.h.

◆ m_reassignedSecondaryHits

std::set<const CDCHit*> m_reassignedSecondaryHits
private

The set of reassigned secondary CDCHits.

Definition at line 162 of file CDCMCMap.h.

◆ m_reassignedSecondarySimHits

std::set<const CDCSimHit*> m_reassignedSecondarySimHits
private

The set of reassigned secondary CDCSimHits.

Definition at line 165 of file CDCMCMap.h.

◆ m_simHitsByHit

std::multimap<const CDCHit*, const CDCSimHit*> m_simHitsByHit
private

Memory for a one to one relation from CDCHit to CDCSimHits.

Definition at line 153 of file CDCMCMap.h.

◆ m_simHitsByMCParticle

std::multimap<const MCParticle*, const CDCSimHit*> m_simHitsByMCParticle
private

Memory for a one to n relation from MCParticles to CDCSimHit.

Definition at line 159 of file CDCMCMap.h.


The documentation for this class was generated from the following files: