LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
MCParticleTrackMatching_module.cc
Go to the documentation of this file.
1 
19 // Framework includes
31 
33 #include "fhiclcpp/ParameterSet.h"
35 
36 #include <memory>
37 #include <iostream>
38 #include <map>
39 #include <iterator>
40 
41 // LArSoft
44 
49 
50 namespace t0 {
51  class MCParticleTrackMatching;
52 }
53 
55 public:
56  explicit MCParticleTrackMatching(fhicl::ParameterSet const & p);
57  // The destructor generated by the compiler is fine for classes
58  // without bare pointers or other resource use.
59 
60  // Plugins should not be copied or assigned.
65 
66  // Required functions.
67  void produce(art::Event & e) override;
68 
69  // Selected optional functions.
70  void beginJob() override;
71  void reconfigure(fhicl::ParameterSet const & p) ;
72 
73 
74 private:
75 
80 
81 };
82 
83 
85 {
86  reconfigure(p);
87  produces< art::Assns<recob::Track , simb::MCParticle, anab::BackTrackerMatchingData > > ();
88 }
89 
91 {
92  fTrackModuleLabel = p.get<art::InputTag>("TrackModuleLabel");
93  fTrackHitAssnLabel = p.get<art::InputTag>("TrackHitAssnLabel",fTrackModuleLabel);
94  fHitModuleLabel = p.get<art::InputTag>("HitModuleLabel");
95  fHitParticleAssnLabel = p.get<art::InputTag>("HitParticleAssnLabel");
96 
97 }
98 
100 {
101 }
102 
104 {
105  if (evt.isRealData()) return;
106 
107  //auto mcpartHandle = evt.getValidHandle< std::vector<simb::MCParticle> >("largeant");
108  std::unique_ptr< art::Assns<recob::Track, simb::MCParticle, anab::BackTrackerMatchingData > > MCPartTrackassn( new art::Assns<recob::Track, simb::MCParticle, anab::BackTrackerMatchingData >);
109 
110 
111  double maxe = -1;
112  double tote = 0;
113  // int trkid = -1;
114  //int maxtrkid = -1;
115  //double maxn = -1;
116  //double totn = 0;
117  //int maxntrkid = -1;
118 
120  std::unordered_map<int,double> trkide;
121 
122  art::Handle< std::vector<recob::Track> > trackListHandle;
123  evt.getByLabel(fTrackModuleLabel,trackListHandle);
124 
125  art::Handle< std::vector<recob::Hit> > hitListHandle;
126  evt.getByLabel(fHitModuleLabel,hitListHandle);
127 
128  if(!trackListHandle.isValid()){
129  std::cerr << "Track handle is not valid!" << std::endl;
130  return;
131  }
132 
133  if(!hitListHandle.isValid()){
134  std::cerr << "Hit handle is not valid!" << std::endl;
135  return;
136  }
137 
138  auto const& trackList(*trackListHandle);
139  art::FindManyP<recob::Hit> fmtht(trackListHandle, evt, fTrackHitAssnLabel);
140  //auto const& mcpartList(*mcpartHandle);
141 
142  for(size_t i_t=0; i_t<trackList.size(); ++i_t){
143  art::Ptr<recob::Track> trkPtr(trackListHandle,i_t);
144  trkide.clear();
145  tote = 0; maxe=-1; art::Ptr<simb::MCParticle> maxp;
146 
147  std::vector< art::Ptr<recob::Hit> > allHits = fmtht.at(i_t);
148 
149  std::vector<anab::BackTrackerHitMatchingData const*> bthmd_vec;
150  std::vector< art::Ptr<simb::MCParticle> > matchedParticlePtrs;
151 
153  particles_per_hit(hitListHandle, evt, fHitParticleAssnLabel);
154 
155  for(size_t i_h=0; i_h<allHits.size(); ++i_h){
156  bthmd_vec.clear(); matchedParticlePtrs.clear();
157  particles_per_hit.get(allHits[i_h].key(),matchedParticlePtrs,bthmd_vec);
158 
159  for(size_t i_p=0; i_p<matchedParticlePtrs.size(); ++i_p){
160  trkide[ matchedParticlePtrs[i_p]->TrackId() ] += bthmd_vec[i_p]->energy;
161  tote += bthmd_vec[i_p]->energy;
162  if( trkide[ matchedParticlePtrs[i_p]->TrackId() ] > maxe ){
163  maxe = trkide[ matchedParticlePtrs[i_p]->TrackId() ];
164  maxp = matchedParticlePtrs[i_p];
165  }
166  }//end loop over particles per hit
167 
168  }//end loop over hits
169 
170  btdata.cleanliness = maxe/tote;
171  if(maxe>0)
172  MCPartTrackassn->addSingle(trkPtr, maxp, btdata);
173 
174  }//end loop over tracks
175 
176  evt.put(std::move(MCPartTrackassn));
177 } // Produce
178 
180 
code to link reconstructed objects back to the MC truth information
Declaration of signal hit object.
MCParticleTrackMatching & operator=(MCParticleTrackMatching const &)=delete
bool isRealData() const
Definition: Event.h:83
Particle class.
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
bool isValid() const
Definition: Handle.h:190
MCParticleTrackMatching(fhicl::ParameterSet const &p)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
Provides recob::Track data product.
T get(std::string const &key) const
Definition: ParameterSet.h:231
void reconfigure(fhicl::ParameterSet const &p)
Utility object to perform functions of association.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
size_type get(size_type i, reference item, data_reference data) const
Definition: FindManyP.h:469
TCEvent evt
Definition: DataStructs.cxx:5
Float_t e
Definition: plot.C:34