5 #include "nusimdata/SimulationBase/MCParticle.h"
7 #include "art/Framework/Principal/Event.h"
8 #include "art/Framework/Principal/Handle.h"
9 #include "art/Utilities/ToolMacros.h"
10 #include "canvas/Persistency/Common/Ptr.h"
11 #include "canvas/Utilities/InputTag.h"
12 #include "messagefacility/MessageLogger/MessageLogger.h"
13 #include "fhiclcpp/ParameterSet.h"
45 void reconfigure(fhicl::ParameterSet
const & pset)
override;
72 mf::LogInfo(
"IndirectHitParticleAssns") <<
"Configured\n";
108 if (!partHitAssnsHandle.isValid() || !mcParticleHandle.isValid())
110 throw cet::exception(
"IndirectHitParticleAssns") <<
"===>> NO MCParticle <--> Hit associations found for run/subrun/event: " << evt.run() <<
"/" << evt.subRun() <<
"/" << evt.id().event();
117 art::Handle< std::vector<recob::Hit> > hitListHandle;
118 evt.getByLabel(inputTag,hitListHandle);
120 if(!hitListHandle.isValid()){
121 mf::LogInfo(
"IndirectHitParticleAssns") <<
"===>> NO Hit collection found to process for run/subrun/event: " << evt.run() <<
"/" << evt.subRun() <<
"/" << evt.id().event() <<
"\n";
126 using ParticleDataPair = std::pair<size_t, const anab::BackTrackerHitMatchingData*>;
127 using MCParticleDataSet = std::set<ParticleDataPair>;
128 using TickToPartDataMap = std::unordered_map<raw::TDCtick_t, MCParticleDataSet>;
129 using ChannelToTickPartDataMap = std::unordered_map<raw::ChannelID_t, TickToPartDataMap>;
131 ChannelToTickPartDataMap chanToTickPartDataMap;
134 for(HitParticleAssociations::const_iterator partHitItr = partHitAssnsHandle->begin(); partHitItr != partHitAssnsHandle->end(); ++partHitItr)
136 const art::Ptr<simb::MCParticle>& mcParticle = partHitItr->first;
137 const art::Ptr<recob::Hit>& recoHit = partHitItr->second;
140 TickToPartDataMap& tickToPartDataMap = chanToTickPartDataMap[recoHit->Channel()];
144 tickToPartDataMap[
tick].insert(ParticleDataPair(mcParticle.key(),data));
149 for(
size_t hitIdx = 0; hitIdx < hitListHandle->size(); hitIdx++)
151 art::Ptr<recob::Hit>
hit(hitListHandle,hitIdx);
153 TickToPartDataMap& tickToPartDataMap = chanToTickPartDataMap[hit->Channel()];
155 if (tickToPartDataMap.empty())
157 mf::LogInfo(
"IndirectHitParticleAssns") <<
"No channel information found for hit " << hit <<
"\n";
162 MCParticleDataSet particleDataSet;
167 TickToPartDataMap::iterator hitInfoItr = tickToPartDataMap.find(
tick);
169 if (hitInfoItr != tickToPartDataMap.end())
171 for(
const auto& partData : hitInfoItr->second) particleDataSet.insert(partData);
176 for(
const auto& partData : particleDataSet)
177 hitPartAssns->addSingle(art::Ptr<simb::MCParticle>(mcParticleHandle, partData.first), hit, *partData.second);
art::Assns< simb::MCParticle, recob::Hit, anab::BackTrackerHitMatchingData > HitParticleAssociations
void CreateHitParticleAssociations(art::Event &, HitParticleAssociations *) override
This rebuilds the internal maps.
Declaration of signal hit object.
art::InputTag fMCParticleModuleLabel
art::InputTag fHitPartAssnsModuleLabel
int TDCtick_t
Type representing a TDC tick.
void reconfigure(fhicl::ParameterSet const &pset) override
std::vector< art::InputTag > fHitModuleLabelVec
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
IndirectHitParticleAssns(fhicl::ParameterSet const &pset)
Constructor.