84 mf::LogInfo(
"DirectHitParticleAssns") <<
"Configured\n";
121 if(!hitListHandle.isValid()){
122 std::cerr <<
"Hit handle is not valid! Returning empty collection" << std::endl;
138 std::unordered_map<int,int> trkid_lookup;
140 auto const& hitList(*hitListHandle);
141 auto const& mcpartList(*mcpartHandle);
143 for(
size_t i_h=0; i_h<hitList.size(); ++i_h){
147 maxe = -1; tote = 0; maxtrkid = -1;
148 maxn = -1; totn = 0; maxntrkid = -1;
152 for(
size_t i_t=0; i_t<trkide_list.size(); ++i_t){
153 auto const& t(trkide_list[i_t]);
158 totn += t.numElectrons;
161 maxntrkid = t.trackID;
165 if(trkid_lookup.find(t.trackID)==trkid_lookup.end()){
167 while(i_p<mcpartList.size()){
168 if(mcpartList[i_p].TrackId() == abs(t.trackID)) { trkid_lookup[t.trackID] = (int)i_p;
break;}
171 if(i_p==mcpartList.size()) trkid_lookup[t.trackID] = -1;
179 int mcpart_i = trkid_lookup[t.first];
180 if(mcpart_i==-1)
continue;
183 bthmd.
isMaxIDE = (t.first==maxtrkid);
185 bthmd.
isMaxIDEN = ( t.first == maxntrkid );
186 bthmd.
energy = t.second.E;
188 hitPartAssns->
addSingle(mcpartPtr, hitPtr, bthmd);
code to link reconstructed objects back to the MC truth information
std::unordered_map< int, TrackIDEinfo > fTrkIDECollector
const std::vector< sim::TrackIDE > HitToTrackIDEs(recob::Hit const &hit)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
art::InputTag fHitModuleLabel
void CreateHitParticleAssociations(art::Event &, HitParticleAssociations *) override
This rebuilds the internal maps.
DirectHitParticleAssns(fhicl::ParameterSet const &pset)
Constructor.
art::InputTag fMCParticleModuleLabel
T get(std::string const &key) const
Utility object to perform functions of association.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
void addSingle(Ptr< left_t > const &left, Ptr< right_t > const &right, data_t const &data)
~DirectHitParticleAssns()
Destructor.
void reconfigure(fhicl::ParameterSet const &pset) override
ValidHandle< PROD > getValidHandle(InputTag const &tag) const