LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
MCParticleShowerMatching_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 MCParticleShowerMatching;
52 }
53 
55 public:
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::Shower , simb::MCParticle, anab::BackTrackerMatchingData > > ();
88 }
89 
91 {
92  fShowerModuleLabel = p.get<art::InputTag>("ShowerModuleLabel");
93  fShowerHitAssnLabel = p.get<art::InputTag>("ShowerHitAssnLabel",fShowerModuleLabel);
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::Shower, simb::MCParticle, anab::BackTrackerMatchingData > > MCPartShowerassn( new art::Assns<recob::Shower, 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::Shower> > showerListHandle;
123  evt.getByLabel(fShowerModuleLabel,showerListHandle);
124 
125  art::Handle< std::vector<recob::Hit> > hitListHandle;
126  evt.getByLabel(fHitModuleLabel,hitListHandle);
127 
128  if(!showerListHandle.isValid()){
129  std::cerr << "Shower 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& showerList(*showerListHandle);
139  art::FindManyP<recob::Hit> fmtht(showerListHandle, evt, fShowerHitAssnLabel);
140  //auto const& mcpartList(*mcpartHandle);
141 
142  for(size_t i_t=0; i_t<showerList.size(); ++i_t){
143  art::Ptr<recob::Shower> shwPtr(showerListHandle,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  MCPartShowerassn->addSingle(shwPtr, maxp, btdata);
173 
174  }//end loop over showers
175 
176  evt.put(std::move(MCPartShowerassn));
177 } // Produce
178 
180 
void reconfigure(fhicl::ParameterSet const &p)
code to link reconstructed objects back to the MC truth information
Declaration of signal hit object.
MCParticleShowerMatching & operator=(MCParticleShowerMatching 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
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
T get(std::string const &key) const
Definition: ParameterSet.h:231
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
MCParticleShowerMatching(fhicl::ParameterSet const &p)
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