LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
NuSliceHitsProducer_module.cc
Go to the documentation of this file.
1 // Class: NuSliceHitsProducer
3 // Plugin Type: producer (art v3_06_03)
4 // File: NuSliceHitsProducer_module.cc
5 //
6 // Generated at Tue May 25 10:39:19 2021 by Giuseppe Cerati using cetskelgen
7 // from cetlib version v3_11_01.
9 
18 #include "fhiclcpp/ParameterSet.h"
20 
21 #include <memory>
22 
31 
33 
36 
38 public:
39  explicit NuSliceHitsProducer(fhicl::ParameterSet const& p);
40  // The compiler-generated destructor is fine for non-base
41  // classes without bare pointers or other resource use.
42 
43  // Plugins should not be copied or assigned.
48 
49  // Required functions.
50  void produce(art::Event& e) override;
51 
52 private:
53  // Declare member data here.
54  std::string fPfpLabel;
55  std::string fSliceLabel;
56  std::string fHitLabel;
57  std::string fHitTruthLabel;
58 };
59 
61  : EDProducer{p}
62  , fPfpLabel(p.get<std::string>("PfpLabel", "pandora"))
63  , fSliceLabel(p.get<std::string>("SliceLabel", "pandora"))
64  , fHitLabel(p.get<std::string>("HitLabel", "gaushit"))
65  , fHitTruthLabel(p.get<std::string>("HitTruthLabel", ""))
66 // More initializers here.
67 {
68  // Call appropriate produces<>() functions here.
69  produces<std::vector<recob::Hit>>();
70  if (!fHitTruthLabel.empty()) produces<HitParticleAssociations>();
71 
72  // Call appropriate consumes<>() for any products to be retrieved by this module.
73 }
74 
76 {
77  // Implementation of required member function here.
78 
79  auto outputHits = std::make_unique<std::vector<recob::Hit>>();
80  auto outputHitPartAssns = std::make_unique<HitParticleAssociations>();
81  art::PtrMaker<recob::Hit> hitPtrMaker(e);
82 
84  e.getValidHandle<std::vector<recob::PFParticle>>(fPfpLabel);
85  auto assocPfpSlice = std::unique_ptr<art::FindManyP<recob::Slice>>(
86  new art::FindManyP<recob::Slice>(inputPfp, e, fPfpLabel));
87 
89  e.getValidHandle<std::vector<recob::Slice>>(fSliceLabel);
90  auto assocSliceHit = std::unique_ptr<art::FindManyP<recob::Hit>>(
91  new art::FindManyP<recob::Hit>(inputSlice, e, fSliceLabel));
92 
94  e.getByLabel(fHitLabel, hitListHandle);
95  std::unique_ptr<art::FindManyP<simb::MCParticle, anab::BackTrackerHitMatchingData>> hittruth;
96  if (!fHitTruthLabel.empty()) {
97  hittruth = std::make_unique<art::FindManyP<simb::MCParticle, anab::BackTrackerHitMatchingData>>(
98  hitListHandle, e, fHitTruthLabel);
99  }
100 
101  for (size_t ipfp = 0; ipfp < inputPfp->size(); ipfp++) {
102 
103  art::Ptr<recob::PFParticle> pfp(inputPfp, ipfp);
104  if (pfp->IsPrimary() == false) continue;
105  auto PDG = fabs(pfp->PdgCode());
106  if (PDG != 12 && PDG != 14) continue;
107 
108  auto assocSlice = assocPfpSlice->at(pfp.key());
109  auto sliceHits = assocSliceHit->at(assocSlice[0].key());
110 
111  for (size_t ihit = 0; ihit < sliceHits.size(); ++ihit) {
112  auto hit = sliceHits.at(ihit);
113  outputHits->emplace_back(*hit);
114 
115  if (!hittruth) continue;
116  std::vector<art::Ptr<simb::MCParticle>> particle_vec = hittruth->at(hit.key());
117  std::vector<anab::BackTrackerHitMatchingData const*> match_vec = hittruth->data(hit.key());
118  const art::Ptr<recob::Hit> ahp = hitPtrMaker(outputHits->size() - 1);
119  for (size_t i_p = 0; i_p < particle_vec.size(); ++i_p) {
120  outputHitPartAssns->addSingle(particle_vec[i_p], ahp, *match_vec[i_p]);
121  }
122  }
123  }
124 
125  e.put(std::move(outputHits));
126  if (!fHitTruthLabel.empty()) e.put(std::move(outputHitPartAssns));
127 }
128 
NuSliceHitsProducer & operator=(NuSliceHitsProducer const &)=delete
Declaration of signal hit object.
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
int PdgCode() const
Return the type of particle as a PDG ID.
Definition: PFParticle.h:79
Particle class.
NuSliceHitsProducer(fhicl::ParameterSet const &p)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
key_type key() const noexcept
Definition: Ptr.h:166
bool IsPrimary() const
Returns whether the particle is the root of the flow.
Definition: PFParticle.h:82
Detector simulation of raw signals on wires.
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
void produce(art::Event &e) override
Float_t e
Definition: plot.C:35