3 #include "art/Framework/Principal/Event.h"
4 #include "art/Framework/Principal/Handle.h"
5 #include "art/Framework/Services/Registry/ServiceHandle.h"
6 #include "art/Utilities/ToolMacros.h"
7 #include "canvas/Persistency/Common/Ptr.h"
8 #include "messagefacility/MessageLogger/MessageLogger.h"
9 #include "fhiclcpp/ParameterSet.h"
16 #include "nusimdata/SimulationBase/MCParticle.h"
46 void reconfigure(fhicl::ParameterSet
const& pset)
override;
76 mf::LogInfo(
"DirectHitParticleAssns") <<
"Configured\n";
109 art::ServiceHandle<cheat::BackTrackerService const> btService;
110 art::ServiceHandle<cheat::ParticleInventoryService const> piService;
112 auto const clockData =
113 art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
117 art::Handle<std::vector<recob::Hit>> hitListHandle;
118 evt.getByLabel(inputTag, hitListHandle);
120 if (!hitListHandle.isValid()) {
121 mf::LogInfo(
"DirectHitParticleAssns")
122 <<
"InputTag not associating to valid hit collection, tag: " << inputTag <<
"\n";
127 std::unordered_map<int, int>
130 auto const& hitList(*hitListHandle);
131 auto const& mcpartList(*mcpartHandle);
133 for (
size_t i_h = 0; i_h < hitList.size(); ++i_h) {
134 art::Ptr<recob::Hit> hitPtr(hitListHandle, i_h);
136 auto trkide_list = btService->HitToTrackIDEs(clockData, hitPtr);
148 for (
size_t i_t = 0; i_t < trkide_list.size(); ++i_t) {
149 auto const& t(trkide_list[i_t]);
154 maxtrkid = t.trackID;
157 totn += t.numElectrons;
160 maxntrkid = t.trackID;
164 if (trkid_lookup.find(t.trackID) == trkid_lookup.end()) {
166 while (i_p < mcpartList.size()) {
167 if (mcpartList[i_p].TrackId() ==
abs(t.trackID)) {
168 trkid_lookup[t.trackID] = (int)i_p;
173 if (i_p == mcpartList.size()) trkid_lookup[t.trackID] = -1;
180 int mcpart_i = trkid_lookup[t.first];
181 if (mcpart_i == -1)
continue;
182 art::Ptr<simb::MCParticle> mcpartPtr(mcpartHandle, mcpart_i);
184 bthmd.
isMaxIDE = (t.first == maxtrkid);
186 bthmd.
isMaxIDEN = (t.first == maxntrkid);
187 bthmd.
energy = t.second.E;
189 hitPartAssns->addSingle(mcpartPtr, hitPtr, bthmd);
art::Assns< simb::MCParticle, recob::Hit, anab::BackTrackerHitMatchingData > HitParticleAssociations
std::unordered_map< int, TrackIDEinfo > fTrkIDECollector
Declaration of signal hit object.
void CreateHitParticleAssociations(art::Event &, HitParticleAssociations *) override
This rebuilds the internal maps.
DirectHitParticleAssns(fhicl::ParameterSet const &pset)
Constructor.
art::InputTag fMCParticleModuleLabel
std::vector< art::InputTag > fHitModuleLabelVec
void reconfigure(fhicl::ParameterSet const &pset) override