 |
Belle II Software
release-05-02-19
|
10 #include <tracking/trackFindingCDC/mclookup/CDCMCMap.h>
12 #include <framework/datastore/StoreArray.h>
14 #include <cdc/dataobjects/CDCHit.h>
15 #include <cdc/dataobjects/CDCSimHit.h>
16 #include <mdst/dataobjects/MCParticle.h>
21 using namespace TrackFindingCDC;
24 template <
class MapType>
25 void print_map(
const MapType& m)
27 using const_iterator =
typename MapType::const_iterator;
28 for (const_iterator iter = m.begin(), iend = m.end(); iter != iend; ++iter) {
29 std::cout << iter->first <<
"-->" << iter->second << std::endl;
36 B2DEBUG(100,
"In CDCMCMap::clear()");
48 B2DEBUG(100,
"In CDCMCMap::fill()");
79 int nRelatedHits = relatedHits.
size();
80 if (nRelatedHits > 1) {
81 B2WARNING(
"CDCSimHit as more than one related CDCHit - reorganize the mapping");
84 for (
const CDCHit& hit : relatedHits) {
85 const CDCHit* ptrHit = &hit;
88 B2WARNING(
"CDCHit as more than one related CDCSimHit - reorganize the mapping");
91 itInsertHint =
m_simHitsByHit.insert(itInsertHint, {ptrHit, ptrSimHit});
96 for (
const CDCHit& hit : hits) {
97 const CDCHit* ptrHit = &hit;
100 B2WARNING(
"CDCHit has no related CDCSimHit in CDCMCMap::fill()");
110 std::map<const MCParticle*, std::vector<const CDCSimHit*>> primarySimHitsByMCParticle;
112 for (
const CDCHit& hit : hits) {
113 const CDCHit* ptrHit = &hit;
116 const int nRelatedMCParticles = relatedMCParticles.
size();
118 if (nRelatedMCParticles == 0 and not
isBackground(ptrHit)) {
119 B2WARNING(
"CDCHit has no related MCParticle but CDCHit indicates that it is no "
120 "background in CDCMCMap::fill()");
123 if (nRelatedMCParticles > 1) {
124 B2WARNING(
"CDCHit as more than one related MCParticle - reorganize the mapping");
129 for (
int iRelatedMCParticle = 0; iRelatedMCParticle < nRelatedMCParticles; ++iRelatedMCParticle) {
130 const MCParticle* ptrMCParticle = relatedMCParticles[iRelatedMCParticle];
131 double weight = relatedMCParticles.
weight(iRelatedMCParticle);
138 primarySimHitsByMCParticle[ptrMCParticle].push_back(ptrSimHit);
147 int nSortedIncorretly = 0;
156 for (std::pair<
const MCParticle*
const, std::vector<const CDCSimHit*>>&
157 primarySimHitsForMCParticle : primarySimHitsByMCParticle) {
159 const MCParticle* ptrMCParticle = primarySimHitsForMCParticle.first;
160 std::vector<const CDCSimHit*>& simHits = primarySimHitsForMCParticle.second;
161 std::sort(simHits.begin(), simHits.end(), lessArrayIndex);
162 auto itSorted = std::is_sorted_until(simHits.begin(), simHits.end(), lessFlightTime);
163 if (itSorted != simHits.end()) {
166 "CDCSimHits for MCParticle " << ptrMCParticle->
getArrayIndex()
167 <<
" only sorted correctly up to hit number "
168 << std::distance(simHits.begin(), itSorted));
171 "Between wire " << (*itSorted)->getWireID() <<
" " << (*itSorted)->getFlightTime()
173 << (*itSorted)->getArrayIndex());
176 "and wire " << (*itSorted)->getWireID() <<
" " << (*itSorted)->getFlightTime()
178 << (*itSorted)->getArrayIndex());
181 if (nSortedIncorretly) {
182 B2WARNING(
"(BII-2136) CDCSimHits for "
184 <<
" primary mc particles are not sorted correctly by their time of flight");
193 for (
const CDCSimHit& simHit : simHits) {
197 const int nRelatedMCParticles = relatedMCParticles.
size();
199 if (nRelatedMCParticles == 0 and not
isBackground(ptrSimHit)) {
200 B2WARNING(
"CDCSimHit has no related MCParticle but CDCSimHit indicates that it is no "
201 "background in CDCMCMap::fill()");
204 if (nRelatedMCParticles > 1) {
205 B2WARNING(
"CDCSimHit as more than one related MCParticle - reorganize the mapping");
210 for (
int iRelatedMCParticle = 0; iRelatedMCParticle < nRelatedMCParticles; ++iRelatedMCParticle) {
211 const MCParticle* ptrMCParticle = relatedMCParticles[iRelatedMCParticle];
212 double weight = relatedMCParticles.
weight(iRelatedMCParticle);
227 for (
const CDCHit& hit : hits) {
228 const CDCHit* ptrHit = &hit;
235 if (ptrMCParticle != ptrMCParticleFromSimHit) {
236 B2WARNING(
"MCParticle from CDCHit and MCParticle from related CDCSimHit mismatch in "
237 "CDCMCMap::validateRelations()");
248 B2WARNING(
"CDCHit is reassigned secondary but related CDCSimHit is not.");
255 return hit ? hit->getRelated<
CDCSimHit>() :
nullptr;
275 return hit ? hit->getRelated<
MCParticle>() :
nullptr;
size_t size() const
Get number of relations.
double getFlightTime() const
The method to get flight time.
std::multimap< const MCParticle *, const CDCSimHit * > m_simHitsByMCParticle
Memory for a one to n relation from MCParticles to CDCSimHit.
void fill()
Fill the Monte Carlo information retrieved from the DataStore into the local multimaps.
MayBePtr< const CDCHit > getHit(const CDCSimHit *simHit) const
Seeks the CDCHit related to the CDCSimHit - nullptr if no CDCHit is related.
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
std::multimap< const MCParticle *, const CDCHit * > m_hitsByMCParticle
Memory for a one to n relation from MCParticles to CDCHit.
std::multimap< const CDCHit *, const CDCSimHit * > m_simHitsByHit
Memory for a one to one relation from CDCHit to CDCSimHits.
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
MayBePtr< const MCParticle > getMCParticle(const CDCHit *hit) const
Seeks the MCParticle related to the CDCHit.
int getArrayIndex() const
Get 0-based index of the particle in the corresponding MCParticle list.
bool isPrimaryParticle() const
Check if particle is a primary particle which was created by the generator (and not,...
static bool indicatesReassignedSecondary(double weight)
Indicate if the given weight suggests that the corresponding hit to MCParticle relation has been redi...
std::set< const CDCSimHit * > m_reassignedSecondarySimHits
The set of reassigned secondary CDCSimHits.
void fillMCParticleBySimHitMap()
Retrieve the relations array from MCParticle to CDCSimHits and fill it in to the local map which does...
Class for type safe access to objects that are referred to in relations.
Abstract base class for different kinds of events.
void validateReassignedSecondaries() const
Checks if each CDCHit is marked as reassigned secondary is related to a reassigned secondary CDCSimHi...
void validateRelations() const
Checks if the relations CDCHit -> MCParticle and CDCHit -> CDCSimHit -> MCParticle commute.
std::set< const CDCHit * > m_reassignedSecondaryHits
The set of reassigned secondary CDCHits.
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
void fillMCParticleByHitMap()
Retrieve the relations array from MCParticle to CDCHits and fill it in to the local map which does th...
MayBePtr< const CDCSimHit > getSimHit(const CDCHit *hit) const
Seeks the CDCSimHit related to the CDCHit.
void clear()
Clear all information from the former event.
float weight(int index) const
Get weight with index.
virtual unsigned short getBackgroundTag() const
Get background tag.
bool isReassignedSecondary(const CDCSimHit *ptrSimHit) const
Indicates if the CDCSimHit has been reassigned to a primary MCParticle.
A Class to store the Monte Carlo particle information.
Accessor to arrays stored in the data store.
bool isBackground(const CDCSimHit *simHit) const
Indicates if the CDCSimHit is considered background.
void fillSimHitByHitMap()
Retrieve the relations array from CDCSimHits to CDCHits and fill it in to the local map which does th...
FROM * getRelatedFrom(const std::string &name="", const std::string &namedRelation="") const
Get the object from which this object has a relation.