10#include <klm/modules/MCMatcherKLMClusters/MCMatcherKLMClustersModule.h>
13#include <klm/dataobjects/bklm/BKLMHit1d.h>
14#include <klm/dataobjects/KLMDigit.h>
15#include <klm/dataobjects/KLMHit2d.h>
16#include <klm/dataobjects/KLMSimHit.h>
19#include <mdst/dataobjects/MCParticle.h>
37 "Add also relations for KLMHit2d.",
false);
61bool compareByValue(
const std::pair<MCParticle*, double>& a,
const std::pair<MCParticle*, double>& b)
63 return a.second > b.second;
74 int i1, i2, i3, i4, i5, i6, n1, n2, n3, n4, n5, n6;
75 std::map<MCParticle*, double> mcParticles, mcParticlesHit;
76 std::vector<std::pair<MCParticle*, double>> helperVector;
77 std::map<MCParticle*, double>::iterator it;
79 for (i1 = 0; i1 < n1; i1++) {
83 n2 = bklmHit2ds.
size();
84 for (i2 = 0; i2 < n2; i2++) {
86 mcParticlesHit.clear();
88 bklmHit2ds[i2]->getRelationsTo<
BKLMHit1d>();
89 n3 = bklmHit1ds.
size();
90 for (i3 = 0; i3 < n3; i3++) {
92 bklmHit1ds[i3]->getRelationsTo<
KLMDigit>();
93 n4 = bklmDigits.
size();
94 for (i4 = 0; i4 < n4; i4++) {
96 bklmDigits[i4]->getRelationsTo<
KLMSimHit>();
97 n5 = bklmSimHits.
size();
98 for (i5 = 0; i5 < n5; i5++) {
100 bklmSimHits[i5]->getRelationsFrom<
MCParticle>();
101 n6 = bklmMCParticles.
size();
102 for (i6 = 0; i6 < n6; i6++) {
103 it = mcParticles.find(bklmMCParticles[i6]);
104 if (it == mcParticles.end()) {
105 mcParticles.insert(std::pair<MCParticle*, double>(
107 bklmSimHits[i5]->getEnergyDeposit()));
109 it->second = it->second + bklmSimHits[i5]->getEnergyDeposit();
112 it = mcParticlesHit.find(bklmMCParticles[i6]);
113 if (it == mcParticlesHit.end()) {
114 mcParticlesHit.insert(std::pair<MCParticle*, double>(
116 bklmSimHits[i5]->getEnergyDeposit()));
118 it->second = it->second + bklmSimHits[i5]->getEnergyDeposit();
126 helperVector.clear();
127 helperVector.insert(helperVector.end(), mcParticlesHit.begin(), mcParticlesHit.end());
128 std::sort(helperVector.begin(), helperVector.end(), compareByValue);
129 double weightSum = std::accumulate(helperVector.begin(), helperVector.end(), 0.0, [](
double sum,
const auto & pair) { return sum + pair.second; });
130 for (
const auto& helperPair : helperVector)
131 bklmHit2ds[i2]->addRelationTo(helperPair.first, helperPair.second / weightSum);
136 n2 = eklmHit2ds.
size();
137 for (i2 = 0; i2 < n2; i2++) {
139 mcParticlesHit.clear();
141 eklmHit2ds[i2]->getRelationsTo<
KLMDigit>();
142 n3 = eklmDigits.
size();
143 for (i3 = 0; i3 < n3; i3++) {
145 eklmDigits[i3]->getRelationsTo<
KLMSimHit>();
146 n4 = eklmSimHits.
size();
147 for (i4 = 0; i4 < n4; i4++) {
149 eklmSimHits[i4]->getRelationsFrom<
MCParticle>();
150 n5 = eklmMCParticles.
size();
151 for (i5 = 0; i5 < n5; i5++) {
152 it = mcParticles.find(eklmMCParticles[i5]);
153 if (it == mcParticles.end()) {
154 mcParticles.insert(std::pair<MCParticle*, double>(
156 eklmSimHits[i4]->getEnergyDeposit()));
158 it->second = it->second + eklmSimHits[i4]->getEnergyDeposit();
161 it = mcParticlesHit.find(eklmMCParticles[i5]);
162 if (it == mcParticlesHit.end()) {
163 mcParticlesHit.insert(std::pair<MCParticle*, double>(
165 eklmSimHits[i4]->getEnergyDeposit()));
167 it->second = it->second + eklmSimHits[i4]->getEnergyDeposit();
174 helperVector.clear();
175 helperVector.insert(helperVector.end(), mcParticlesHit.begin(), mcParticlesHit.end());
176 std::sort(helperVector.begin(), helperVector.end(), compareByValue);
177 double weightSum = std::accumulate(helperVector.begin(), helperVector.end(), 0.0, [](
double sum,
const auto & pair) { return sum + pair.second; });
178 for (
const auto& helperPair : helperVector)
179 eklmHit2ds[i2]->addRelationTo(helperPair.first, helperPair.second / weightSum);
182 helperVector.clear();
183 helperVector.insert(helperVector.end(), mcParticles.begin(), mcParticles.end());
184 std::sort(helperVector.begin(), helperVector.end(), compareByValue);
185 double weightSum = std::accumulate(helperVector.begin(), helperVector.end(), 0.0, [](
double sum,
const auto & pair) { return sum + pair.second; });
186 for (
const auto& helperPair : helperVector)
187 m_KLMClusters[i1]->addRelationTo(helperPair.first, helperPair.second / weightSum);
Store one reconstructed BKLM 1D hit as a ROOT object.
KLM digit (class representing a digitized hit in RPCs or scintillators).
bool m_Hit2dRelations
Add relations for KLMHit2d and KLMHit2d.
void initialize() override
Initializer.
void event() override
This method is called for each event.
~MCMatcherKLMClustersModule()
Destructor.
StoreArray< KLMCluster > m_KLMClusters
KLM clusters.
MCMatcherKLMClustersModule()
Constructor.
StoreArray< MCParticle > m_MCParticles
MCParticles StoreArray.
A Class to store the Monte Carlo particle information.
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
Accessor to arrays stored in the data store.
bool isValid() const
Check whether the array was registered.
bool registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.