LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ShowerReco3D_module.cc
Go to the documentation of this file.
1 // Class: ShowerReco3D
3 // Module Type: producer
4 // File: ShowerReco3D_module.cc
5 //
6 // Generated at Tue Jan 20 07:26:48 2015 by Kazuhiro Terao using artmod
7 // from cetpkgsupport v1_08_02.
9 
16 #include "fhiclcpp/ParameterSet.h"
17 
35 
38 
39 #include <memory>
40 #include <string>
41 
42 class ShowerReco3D : public art::EDProducer {
43 public:
44  explicit ShowerReco3D(fhicl::ParameterSet const& p);
45  // The destructor generated by the compiler is fine for classes
46  // without bare pointers or other resource use.
47 
48  // Plugins should not be copied or assigned.
49  ShowerReco3D(ShowerReco3D const&) = delete;
50  ShowerReco3D(ShowerReco3D&&) = delete;
51  ShowerReco3D& operator=(ShowerReco3D const&) = delete;
52  ShowerReco3D& operator=(ShowerReco3D&&) = delete;
53 
54 private:
55  // Required functions.
56  void produce(art::Event& e) override;
57 
58  // Declare member data here.
60  std::string fInputProducer;
68 };
69 
71 {
72  fInputProducer = p.get<std::string>("InputProducer");
73  fUsePFParticle = p.get<bool>("UsePFParticle");
74  produces<std::vector<recob::Shower>>();
75  produces<art::Assns<recob::Shower, recob::Cluster>>();
76  produces<art::Assns<recob::Shower, recob::Hit>>();
77  if (fUsePFParticle) produces<art::Assns<recob::PFParticle, recob::Shower>>();
78 
79  // Instantiate algorithms
80  fCaloAlgo = new ::calo::CalorimetryAlg(p.get<fhicl::ParameterSet>("CalorimetryAlg"));
81  fShowerAlgo = new ::showerreco::ShowerRecoAlg;
82  fCPAlgoArray = new ::cmtool::CPAlgoArray;
83  fCPAlgoNHits = new ::cmtool::CPAlgoNHits;
84  fCPAlgoIgnoreTracks = new ::cmtool::CPAlgoIgnoreTracks;
85  fCFAlgoTimeOverlap = new ::cmtool::CFAlgoTimeOverlap;
86 
87  // Configure
88  fCPAlgoNHits->SetMinHits(p.get<int>("MinHits"));
89 
92 
95 
96  fShowerAlgo->Verbose(p.get<bool>("Verbosity"));
97  fShowerAlgo->SetUseArea(p.get<bool>("UseArea"));
98  fShowerAlgo->setEcorrection(p.get<bool>("ApplyMCEnergyCorrection"));
99  fShowerAlgo->CaloAlgo(fCaloAlgo);
100 
102 }
103 
105 {
106  auto const& geom = *lar::providerFrom<geo::Geometry>();
107  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(e);
108  auto const detProp =
110  util::GeometryUtilities const gser{geom, clockData, detProp};
111 
112  // Create output data product containers
113  std::unique_ptr<std::vector<recob::Shower>> out_shower_v(new std::vector<recob::Shower>);
114  std::unique_ptr<art::Assns<recob::Shower, recob::Cluster>> sc_assn(
116  std::unique_ptr<art::Assns<recob::Shower, recob::Hit>> sh_assn(
118  std::unique_ptr<art::Assns<recob::PFParticle, recob::Shower>> sp_assn(
120 
121  // Preparation
122 
123  // Reset ShowerRecoManager
124  fManager.Reset();
125 
126  // Retrieve input clusters
128  e.getByLabel(fInputProducer, cHandle);
129 
130  if (!cHandle.isValid())
131  throw cet::exception(__FUNCTION__) << "Invalid input cluster label!" << std::endl;
132 
133  // Cluster type conversion: recob::Hit => util::PxHit
134  std::vector<std::vector<::util::PxHit>> local_clusters;
135  art::FindManyP<recob::Hit> hit_m(cHandle, e, fInputProducer);
136  ::util::PxHitConverter conv{gser};
137  for (size_t i = 0; i < cHandle->size(); ++i) {
138  local_clusters.push_back(std::vector<::util::PxHit>());
139 
140  const std::vector<art::Ptr<recob::Hit>>& hits = hit_m.at(i);
141 
142  conv.GeneratePxHit(hits, local_clusters.back());
143  }
144 
145  //
146  // Run shower reconstruction
147  //
148  // shower pfparticle index (later used to make an association)
149  std::vector<size_t> shower_pfpart_index;
150  // cluster combination in terms of cluster index (for ShowerRecoManager::Reconstruct)
151  std::vector<std::vector<unsigned int>> matched_pairs;
152  // shower vector container to receive from ShowerRecoManager::Reconstruct
153  std::vector<recob::Shower> shower_v;
154 
155  if (!fUsePFParticle) {
156  matched_pairs = fManager.Reconstruct(geom, clockData, detProp, local_clusters, shower_v);
157  }
158  else {
159 
160  // Retrieve PFParticle
162  e.getByLabel(fInputProducer, pfHandle);
163  if (!pfHandle.isValid())
164  throw cet::exception(__FUNCTION__) << "Invalid input PFParticle label!" << std::endl;
165 
166  // Make a cluster ptr => index map to fill matched_pairs
167  std::map<art::Ptr<recob::Cluster>, size_t> cmap;
168  for (size_t i = 0; i < cHandle->size(); ++i) {
169 
170  const art::Ptr<recob::Cluster> cptr(cHandle, i);
171 
172  cmap[cptr] = i;
173  }
174  // Now to fill matched_pairs retrieve association of pfpart => cluster(s)
175  art::FindManyP<recob::Cluster> cluster_m(pfHandle, e, fInputProducer);
176 
177  for (size_t i = 0; i < pfHandle->size(); ++i) {
178 
179  const art::Ptr<recob::PFParticle> pf(pfHandle, i);
180 
181  if (pf->PdgCode() != 11) continue;
182 
183  const std::vector<art::Ptr<recob::Cluster>>& clusters = cluster_m.at(i);
184 
185  std::vector<unsigned int> one_pair;
186  one_pair.reserve(clusters.size());
187 
188  for (auto const& cptr : clusters) {
189 
190  auto iter = cmap.find(cptr);
191  if (iter == cmap.end())
192  throw cet::exception(__FUNCTION__)
193  << "PFParticle=>Cluster association not valid!" << std::endl;
194 
195  one_pair.push_back((*iter).second);
196  }
197  matched_pairs.push_back(one_pair);
198  shower_pfpart_index.push_back(i);
199  }
200  // Run reconstruction
201  fManager.Reconstruct(geom, clockData, detProp, local_clusters, matched_pairs, shower_v);
202  }
203 
204  // Make sure output shower vector size is same as expected length
205  if (shower_v.size() != matched_pairs.size())
206  throw cet::exception(__FUNCTION__)
207  << "Logic error: # of matched pairs != # of reco-ed showers!" << std::endl;
208 
209  // Fill output shower vector data container
210  out_shower_v->reserve(shower_v.size());
211 
212  for (size_t i = 0; i < shower_v.size(); ++i) {
213 
214  // Set output shower ID
215  shower_v[i].set_id(i);
216 
217  out_shower_v->push_back(shower_v[i]);
218 
219  // Create shower=>cluster association
220  std::vector<art::Ptr<recob::Cluster>> ass_clusters;
221  // Create shower=>hit association
222  std::vector<art::Ptr<recob::Hit>> ass_hits;
223  for (auto const& cindex : matched_pairs[i]) {
224 
225  ass_clusters.push_back(art::Ptr<recob::Cluster>(cHandle, cindex));
226 
227  const std::vector<art::Ptr<recob::Hit>>& hits = hit_m.at(cindex);
228 
229  for (auto const& ptr : hits)
230  ass_hits.push_back(ptr);
231  }
232  // Shower=>Cluster
233  util::CreateAssn(e, *(out_shower_v.get()), ass_clusters, *(sc_assn.get()));
234  // Shower=>Hits
235  util::CreateAssn(e, *(out_shower_v.get()), ass_hits, *(sh_assn.get()));
236 
237  if (fUsePFParticle) {
238 
240  e.getByLabel(fInputProducer, pfHandle);
241 
242  art::Ptr<recob::PFParticle> pf_ptr(pfHandle, shower_pfpart_index[i]);
243 
244  util::CreateAssn(e, *(out_shower_v.get()), pf_ptr, *(sp_assn.get()));
245  }
246  }
247 
248  // Store in an event record
249  e.put(std::move(out_shower_v));
250  e.put(std::move(sh_assn));
251  e.put(std::move(sc_assn));
252  if (fUsePFParticle) e.put(std::move(sp_assn));
253 }
254 
void Algo(ShowerRecoAlgBase *alg)
::calo::CalorimetryAlg * fCaloAlgo
Utilities related to art service access.
::cmtool::CPAlgoArray * fCPAlgoArray
Declaration of signal hit object.
::showerreco::ShowerRecoManager fManager
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
void AddAlgo(CPriorityAlgoBase *algo)
Setter to add a new algorithm.
Definition: CPAlgoArray.h:62
void SetMinHits(size_t n)
Setter for minimum # hits.
Definition: CPAlgoNHits.h:41
int PdgCode() const
Return the type of particle as a PDG ID.
Definition: PFParticle.h:79
::cmtool::CFAlgoTimeOverlap * fCFAlgoTimeOverlap
void AddMatchAlgo(CFloatAlgoBase *algo)
A simple method to add an algorithm for merging.
Definition: CMatchManager.h:46
void produce(art::Event &e) override
void CaloAlgo(calo::CalorimetryAlg *alg)
Definition: ShowerRecoAlg.h:27
bool isValid() const noexcept
Definition: Handle.h:203
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
void hits()
Definition: readHits.C:15
std::string fInputProducer
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
void setEcorrection(bool on)
Function to set whether to use E correction.
Definition: ShowerRecoAlg.h:30
Class def header for a class CPAlgoArray.
Declaration of cluster object.
void SetUseArea(bool on)
Function to decide if to use Area or Pulse Amplitude for calculations.
Definition: ShowerRecoAlg.h:23
Class def header for a class CPAlgoNHits.
::cmtool::CMatchManager & MatchManager()
void Verbose(bool verbose)
Definition: ShowerRecoAlg.h:25
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
ShowerReco3D(fhicl::ParameterSet const &p)
::cmtool::CPAlgoIgnoreTracks * fCPAlgoIgnoreTracks
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Utility object to perform functions of association.
::showerreco::ShowerRecoAlg * fShowerAlgo
Class def header for a class CMatchManager.
Class def header for a class CPAlgoIgnoreTracks.
ShowerReco3D & operator=(ShowerReco3D const &)=delete
Class def header for a class CFAlgoTimeOverlap.
::cmtool::CPAlgoNHits * fCPAlgoNHits
void AddPriorityAlgo(CPriorityAlgoBase *algo)
Setter to add an algorithm for priority determination.
Definition: CMManagerBase.h:71
Float_t e
Definition: plot.C:35
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
ClusterAss_t Reconstruct(geo::GeometryCore const &geom, detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const std::vector< std::vector< util::PxHit >> &clusters, std::vector<::recob::Shower > &showers)
Class def header for a class ShowerRecoManager.