LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
MCParticleTrackMatching_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 MCParticleTrackMatching;
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  fTrackModuleLabel = p.get<art::InputTag>("TrackModuleLabel");
68  fTrackHitAssnLabel = p.get<art::InputTag>("TrackHitAssnLabel", fTrackModuleLabel);
69  fHitModuleLabel = p.get<art::InputTag>("HitModuleLabel");
70  fHitParticleAssnLabel = p.get<art::InputTag>("HitParticleAssnLabel");
71 
72  produces<art::Assns<recob::Track, 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::Track, simb::MCParticle, anab::BackTrackerMatchingData>>
82 
83  double maxe = -1;
84  double tote = 0;
85  // int trkid = -1;
86  //int maxtrkid = -1;
87  //double maxn = -1;
88  //double totn = 0;
89  //int maxntrkid = -1;
90 
92  std::unordered_map<int, double> trkide;
93 
95  evt.getByLabel(fTrackModuleLabel, trackListHandle);
96 
98  evt.getByLabel(fHitModuleLabel, hitListHandle);
99 
100  if (!trackListHandle.isValid()) {
101  std::cerr << "Track handle is not valid!" << std::endl;
102  return;
103  }
104 
105  if (!hitListHandle.isValid()) {
106  std::cerr << "Hit handle is not valid!" << std::endl;
107  return;
108  }
109 
110  auto const& trackList(*trackListHandle);
111  art::FindManyP<recob::Hit> fmtht(trackListHandle, evt, fTrackHitAssnLabel);
112  //auto const& mcpartList(*mcpartHandle);
113 
114  for (size_t i_t = 0; i_t < trackList.size(); ++i_t) {
115  art::Ptr<recob::Track> trkPtr(trackListHandle, i_t);
116  trkide.clear();
117  tote = 0;
118  maxe = -1;
120 
121  std::vector<art::Ptr<recob::Hit>> allHits = fmtht.at(i_t);
122 
123  std::vector<anab::BackTrackerHitMatchingData const*> bthmd_vec;
124  std::vector<art::Ptr<simb::MCParticle>> matchedParticlePtrs;
125 
127  hitListHandle, evt, fHitParticleAssnLabel);
128 
129  for (size_t i_h = 0; i_h < allHits.size(); ++i_h) {
130  bthmd_vec.clear();
131  matchedParticlePtrs.clear();
132  particles_per_hit.get(allHits[i_h].key(), matchedParticlePtrs, bthmd_vec);
133 
134  for (size_t i_p = 0; i_p < matchedParticlePtrs.size(); ++i_p) {
135  trkide[matchedParticlePtrs[i_p]->TrackId()] += bthmd_vec[i_p]->energy;
136  tote += bthmd_vec[i_p]->energy;
137  if (trkide[matchedParticlePtrs[i_p]->TrackId()] > maxe) {
138  maxe = trkide[matchedParticlePtrs[i_p]->TrackId()];
139  maxp = matchedParticlePtrs[i_p];
140  }
141  } //end loop over particles per hit
142 
143  } //end loop over hits
144 
145  btdata.cleanliness = maxe / tote;
146  if (maxe > 0) MCPartTrackassn->addSingle(trkPtr, maxp, btdata);
147 
148  } //end loop over tracks
149 
150  evt.put(std::move(MCPartTrackassn));
151 } // Produce
152 
code to link reconstructed objects back to the MC truth information
Declaration of signal hit object.
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
MCParticleTrackMatching & operator=(MCParticleTrackMatching const &)=delete
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
MCParticleTrackMatching(fhicl::ParameterSet const &p)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
Provides recob::Track data product.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
size_type get(size_type i, reference item, data_reference data) const
Definition: FindManyP.h:453
TCEvent evt
Definition: DataStructs.cxx:8
void produce(art::Event &e) override
Float_t e
Definition: plot.C:35