20 #include "art/Framework/Core/EDProducer.h"
21 #include "art/Framework/Core/ModuleMacros.h"
22 #include "art/Framework/Principal/Event.h"
23 #include "art/Framework/Principal/Handle.h"
24 #include "canvas/Persistency/Common/FindManyP.h"
25 #include "canvas/Persistency/Common/Ptr.h"
26 #include "canvas/Utilities/InputTag.h"
27 #include "fhiclcpp/ParameterSet.h"
37 #include "nusimdata/SimulationBase/MCParticle.h"
40 class MCParticleTrackMatching;
56 void produce(art::Event &
e)
override;
71 fTrackModuleLabel =
p.get<art::InputTag>(
"TrackModuleLabel");
72 fTrackHitAssnLabel =
p.get<art::InputTag>(
"TrackHitAssnLabel",fTrackModuleLabel);
73 fHitModuleLabel =
p.get<art::InputTag>(
"HitModuleLabel");
74 fHitParticleAssnLabel =
p.get<art::InputTag>(
"HitParticleAssnLabel");
76 produces< art::Assns<recob::Track , simb::MCParticle, anab::BackTrackerMatchingData > > ();
81 if (evt.isRealData())
return;
84 std::unique_ptr< art::Assns<recob::Track, simb::MCParticle, anab::BackTrackerMatchingData > > MCPartTrackassn(
new art::Assns<recob::Track, simb::MCParticle, anab::BackTrackerMatchingData >);
96 std::unordered_map<int,double> trkide;
98 art::Handle< std::vector<recob::Track> > trackListHandle;
99 evt.getByLabel(fTrackModuleLabel,trackListHandle);
101 art::Handle< std::vector<recob::Hit> > hitListHandle;
102 evt.getByLabel(fHitModuleLabel,hitListHandle);
104 if(!trackListHandle.isValid()){
105 std::cerr <<
"Track handle is not valid!" << std::endl;
109 if(!hitListHandle.isValid()){
110 std::cerr <<
"Hit handle is not valid!" << std::endl;
114 auto const& trackList(*trackListHandle);
115 art::FindManyP<recob::Hit> fmtht(trackListHandle, evt, fTrackHitAssnLabel);
118 for(
size_t i_t=0; i_t<trackList.size(); ++i_t){
119 art::Ptr<recob::Track> trkPtr(trackListHandle,i_t);
121 tote = 0; maxe=-1; art::Ptr<simb::MCParticle> maxp;
123 std::vector< art::Ptr<recob::Hit> > allHits = fmtht.at(i_t);
125 std::vector<anab::BackTrackerHitMatchingData const*> bthmd_vec;
126 std::vector< art::Ptr<simb::MCParticle> > matchedParticlePtrs;
128 art::FindManyP<simb::MCParticle,anab::BackTrackerHitMatchingData>
129 particles_per_hit(hitListHandle, evt, fHitParticleAssnLabel);
131 for(
size_t i_h=0; i_h<allHits.size(); ++i_h){
132 bthmd_vec.clear(); matchedParticlePtrs.clear();
133 particles_per_hit.get(allHits[i_h].key(),matchedParticlePtrs,bthmd_vec);
135 for(
size_t i_p=0; i_p<matchedParticlePtrs.size(); ++i_p){
136 trkide[ matchedParticlePtrs[i_p]->TrackId() ] += bthmd_vec[i_p]->energy;
137 tote += bthmd_vec[i_p]->energy;
138 if( trkide[ matchedParticlePtrs[i_p]->TrackId() ] > maxe ){
139 maxe = trkide[ matchedParticlePtrs[i_p]->TrackId() ];
140 maxp = matchedParticlePtrs[i_p];
148 MCPartTrackassn->addSingle(trkPtr, maxp, btdata);
152 evt.put(std::move(MCPartTrackassn));
BEGIN_PROLOG could also be cerr
art::InputTag fTrackHitAssnLabel
Declaration of signal hit object.
MCParticleTrackMatching & operator=(MCParticleTrackMatching const &)=delete
MCParticleTrackMatching(fhicl::ParameterSet const &p)
art::InputTag fHitModuleLabel
Provides recob::Track data product.
void produce(art::Event &e) override
art::InputTag fTrackModuleLabel
art::InputTag fHitParticleAssnLabel