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 assignement 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.
 
MayBePtr< const CDCSimHitgetSimHit (const CDCHit *hit) const
 Seeks the CDCSimHit related to the CDCHit.
 
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.
 
MayBePtr< const MCParticlegetMCParticle (const CDCHit *hit) const
 Seeks the MCParticle related to the CDCHit.
 
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 32 of file CDCMCMap.cc.

33{
34 B2DEBUG(25, "In CDCMCMap::clear()");
35 m_simHitsByHit.clear();
36
37 m_hitsByMCParticle.clear();
39
42}
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 44 of file CDCMCMap.cc.

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

◆ 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 103 of file CDCMCMap.cc.

104{
106
107 std::map<const MCParticle*, std::vector<const CDCSimHit*>> primarySimHitsByMCParticle;
108
109 for (const CDCHit& hit : hits) {
110 const CDCHit* ptrHit = &hit;
111 RelationVector<MCParticle> relatedMCParticles = hit.getRelationsFrom<MCParticle>();
112
113 const int nRelatedMCParticles = relatedMCParticles.size();
114
115 if (nRelatedMCParticles == 0 and not isBackground(ptrHit)) {
116 B2WARNING("CDCHit has no related MCParticle but CDCHit indicates that it is no "
117 "background in CDCMCMap::fill()");
118 }
119
120 if (nRelatedMCParticles > 1) {
121 B2WARNING("CDCHit as more than one related MCParticle - reorganize the mapping");
122 }
123
124 // Pickup an iterator for hinted insertion
125 auto itInsertHint = m_hitsByMCParticle.end();
126 for (int iRelatedMCParticle = 0; iRelatedMCParticle < nRelatedMCParticles; ++iRelatedMCParticle) {
127 const MCParticle* ptrMCParticle = relatedMCParticles[iRelatedMCParticle];
128 double weight = relatedMCParticles.weight(iRelatedMCParticle);
129
130 if (indicatesReassignedSecondary(weight)) {
131 m_reassignedSecondaryHits.insert(ptrHit);
132 } else {
133 const CDCSimHit* ptrSimHit = ptrHit->getRelatedFrom<CDCSimHit>();
134 if (ptrMCParticle->isPrimaryParticle() and ptrSimHit) {
135 primarySimHitsByMCParticle[ptrMCParticle].push_back(ptrSimHit);
136 }
137 }
138
139 itInsertHint = m_hitsByMCParticle.insert(itInsertHint, {ptrMCParticle, ptrHit});
140 }
141 }
142
143 // Check time ordering of primary hits
144 int nSortedIncorretly = 0;
145 auto lessFlightTime = [](const CDCSimHit * lhs, const CDCSimHit * rhs) {
146 return lhs->getFlightTime() < rhs->getFlightTime();
147 };
148
149 auto lessArrayIndex = [](const CDCSimHit * lhs, const CDCSimHit * rhs) -> bool {
150 return lhs->getArrayIndex() < rhs->getArrayIndex();
151 };
152
153 for (std::pair<const MCParticle* const, std::vector<const CDCSimHit*>>&
154 primarySimHitsForMCParticle : primarySimHitsByMCParticle) {
155
156 const MCParticle* ptrMCParticle = primarySimHitsForMCParticle.first;
157 std::vector<const CDCSimHit*>& simHits = primarySimHitsForMCParticle.second;
158 std::sort(simHits.begin(), simHits.end(), lessArrayIndex);
159 auto itSorted = std::is_sorted_until(simHits.begin(), simHits.end(), lessFlightTime);
160 if (itSorted != simHits.end()) {
161 ++nSortedIncorretly;
162 B2DEBUG(25,
163 "CDCSimHits for MCParticle " << ptrMCParticle->getArrayIndex()
164 << " only sorted correctly up to hit number "
165 << std::distance(simHits.begin(), itSorted));
166 --itSorted;
167 B2DEBUG(25,
168 "Between wire " << (*itSorted)->getWireID() << " " << (*itSorted)->getFlightTime()
169 << "ns "
170 << (*itSorted)->getArrayIndex());
171 ++itSorted;
172 B2DEBUG(25,
173 "and wire " << (*itSorted)->getWireID() << " " << (*itSorted)->getFlightTime()
174 << "ns "
175 << (*itSorted)->getArrayIndex());
176 }
177 }
178 if (nSortedIncorretly) {
179 B2WARNING("(BII-2136) CDCSimHits for "
180 << nSortedIncorretly
181 << " primary mc particles are not sorted correctly by their time of flight");
182 }
183}
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
Definition: CDCHit.h:40
Example Detector.
Definition: CDCSimHit.h:21
double getFlightTime() const
The method to get flight time.
Definition: CDCSimHit.h:184
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
int getArrayIndex() const
Get 0-based index of the particle in the corresponding MCParticle list.
Definition: MCParticle.h:244
Class for type safe access to objects that are referred to in relations.
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.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
bool isBackground(const CDCSimHit *simHit) const
Indicates if the CDCSimHit is considered background.
Definition: CDCMCMap.cc:259
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:595

◆ 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 185 of file CDCMCMap.cc.

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

◆ 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 65 of file CDCMCMap.cc.

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

◆ 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 254 of file CDCMCMap.cc.

255{
256 return simHit ? simHit->getRelated<CDCHit>() : nullptr;
257}
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 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 269 of file CDCMCMap.cc.

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

◆ 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 274 of file CDCMCMap.cc.

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

◆ getReassignedSecondaryHits()

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

Getter for all reassigned secondary CDCHits.

Definition at line 122 of file CDCMCMap.h.

123 {
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 {
131 }

◆ getSimHit()

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

Seeks the CDCSimHit related to the CDCHit.

Definition at line 249 of file CDCMCMap.cc.

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

◆ 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 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 {
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 264 of file CDCMCMap.cc.

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

◆ isBackground() [2/2]

bool isBackground ( const CDCSimHit simHit) const

Indicates if the CDCSimHit is considered background.

Definition at line 259 of file CDCMCMap.cc.

260{
261 return simHit ? simHit->getBackgroundTag() != BackgroundMetaData::bg_none : false;
262}
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 238 of file CDCMCMap.cc.

239{
240 for (const CDCHit* ptrHit : m_reassignedSecondaryHits) {
241
242 const CDCSimHit* ptrSimHit = getSimHit(ptrHit);
243 if (not isReassignedSecondary(ptrSimHit)) {
244 B2WARNING("CDCHit is reassigned secondary but related CDCSimHit is not.");
245 }
246 }
247}
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 219 of file CDCMCMap.cc.

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

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: