LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
MCParticleShowerMatching_module.cc
Go to the documentation of this file.
1 
19 // Framework includes
27 #include "fhiclcpp/ParameterSet.h"
28 
29 #include <iostream>
30 #include <iterator>
31 #include <memory>
32 
33 // LArSoft
38 
39 namespace t0 {
40  class MCParticleShowerMatching;
41 }
42 
44 public:
46  // The destructor generated by the compiler is fine for classes
47  // without bare pointers or other resource use.
48 
49  // Plugins should not be copied or assigned.
54 
55  // Required functions.
56  void produce(art::Event& e) override;
57 
58 private:
63 };
64 
66 {
67  fShowerModuleLabel = p.get<art::InputTag>("ShowerModuleLabel");
68  fShowerHitAssnLabel = p.get<art::InputTag>("ShowerHitAssnLabel", fShowerModuleLabel);
69  fHitModuleLabel = p.get<art::InputTag>("HitModuleLabel");
70  fHitParticleAssnLabel = p.get<art::InputTag>("HitParticleAssnLabel");
71 
72  produces<art::Assns<recob::Shower, simb::MCParticle, anab::BackTrackerMatchingData>>();
73 }
74 
76 {
77  if (evt.isRealData()) return;
78 
79  //auto mcpartHandle = evt.getValidHandle< std::vector<simb::MCParticle> >("largeant");
80  std::unique_ptr<art::Assns<recob::Shower, simb::MCParticle, anab::BackTrackerMatchingData>>
81  MCPartShowerassn(
83 
84  double maxe = -1;
85  double tote = 0;
86  // int trkid = -1;
87  //int maxtrkid = -1;
88  //double maxn = -1;
89  //double totn = 0;
90  //int maxntrkid = -1;
91 
93  std::unordered_map<int, double> trkide;
94 
96  evt.getByLabel(fShowerModuleLabel, showerListHandle);
97 
99  evt.getByLabel(fHitModuleLabel, hitListHandle);
100 
101  if (!showerListHandle.isValid()) {
102  std::cerr << "Shower handle is not valid!" << std::endl;
103  return;
104  }
105 
106  if (!hitListHandle.isValid()) {
107  std::cerr << "Hit handle is not valid!" << std::endl;
108  return;
109  }
110 
111  auto const& showerList(*showerListHandle);
112  art::FindManyP<recob::Hit> fmtht(showerListHandle, evt, fShowerHitAssnLabel);
113  //auto const& mcpartList(*mcpartHandle);
114 
115  for (size_t i_t = 0; i_t < showerList.size(); ++i_t) {
116  art::Ptr<recob::Shower> shwPtr(showerListHandle, i_t);
117  trkide.clear();
118  tote = 0;
119  maxe = -1;
121 
122  std::vector<art::Ptr<recob::Hit>> allHits = fmtht.at(i_t);
123 
124  std::vector<anab::BackTrackerHitMatchingData const*> bthmd_vec;
125  std::vector<art::Ptr<simb::MCParticle>> matchedParticlePtrs;
126 
128  hitListHandle, evt, fHitParticleAssnLabel);
129 
130  for (size_t i_h = 0; i_h < allHits.size(); ++i_h) {
131  bthmd_vec.clear();
132  matchedParticlePtrs.clear();
133  particles_per_hit.get(allHits[i_h].key(), matchedParticlePtrs, bthmd_vec);
134 
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];
141  }
142  } //end loop over particles per hit
143 
144  } //end loop over hits
145 
146  btdata.cleanliness = maxe / tote;
147  if (maxe > 0) MCPartShowerassn->addSingle(shwPtr, maxp, btdata);
148 
149  } //end loop over showers
150 
151  evt.put(std::move(MCPartShowerassn));
152 } // Produce
153 
code to link reconstructed objects back to the MC truth information
Declaration of signal hit object.
MCParticleShowerMatching & operator=(MCParticleShowerMatching const &)=delete
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
bool isRealData() const
Definition: Event.cc:53
Particle class.
bool isValid() const noexcept
Definition: Handle.h:203
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
MCParticleShowerMatching(fhicl::ParameterSet const &p)
size_type get(size_type i, reference item, data_reference data) const
Definition: FindManyP.h:453
TCEvent evt
Definition: DataStructs.cxx:8
Float_t e
Definition: plot.C:35