LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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 
18 #include "fhiclcpp/ParameterSet.h"
20 
32 
33 #include "ShowerRecoAlg.h"
34 #include "ShowerRecoManager.h"
35 
36 #include <string>
37 #include <iostream>
38 #include <vector>
39 #include <memory>
40 
41 class ShowerReco3D;
42 
43 class ShowerReco3D : public art::EDProducer {
44 public:
45  explicit ShowerReco3D(fhicl::ParameterSet const & p);
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.
50  ShowerReco3D(ShowerReco3D const &) = delete;
51  ShowerReco3D(ShowerReco3D &&) = delete;
52  ShowerReco3D & operator = (ShowerReco3D const &) = delete;
53  ShowerReco3D & operator = (ShowerReco3D &&) = delete;
54 
55  // Required functions.
56  void produce(art::Event & e) override;
57 
58 private:
59 
60  // Declare member data here.
62  std::string fInputProducer;
70 };
71 
72 
74 {
75  fInputProducer = p.get<std::string>("InputProducer");
76  fUsePFParticle = p.get<bool>("UsePFParticle");
77  produces< std::vector<recob::Shower> >();
78  produces< art::Assns<recob::Shower,recob::Cluster> >();
79  produces< art::Assns<recob::Shower,recob::Hit> >();
80  if(fUsePFParticle)
81  produces< art::Assns<recob::PFParticle,recob::Shower> >();
82 
83  // Instantiate algorithms
84  fCaloAlgo = new ::calo::CalorimetryAlg(p.get< fhicl::ParameterSet >("CalorimetryAlg"));
85  fShowerAlgo = new ::showerreco::ShowerRecoAlg;
86  fCPAlgoArray = new ::cmtool::CPAlgoArray;
87  fCPAlgoNHits = new ::cmtool::CPAlgoNHits;
88  fCPAlgoIgnoreTracks = new ::cmtool::CPAlgoIgnoreTracks;
89  fCFAlgoTimeOverlap = new ::cmtool::CFAlgoTimeOverlap;
90 
91  // Configure
92  fCPAlgoNHits->SetMinHits(p.get<int>("MinHits"));
93 
96 
99 
100  fShowerAlgo->Verbose(p.get<bool>("Verbosity"));
101  fShowerAlgo->SetUseArea(p.get<bool>("UseArea"));
102  fShowerAlgo->setEcorrection(p.get<bool>("ApplyMCEnergyCorrection"));
103  fShowerAlgo->CaloAlgo(fCaloAlgo);
104 
106 
107 }
108 
110 {
111  //
112  // Create output data product containers
113  //
114  std::unique_ptr<std::vector<recob::Shower> > out_shower_v(new std::vector<recob::Shower>);
115  std::unique_ptr<art::Assns<recob::Shower, recob::Cluster> > sc_assn(new art::Assns<recob::Shower, recob::Cluster>);
116  std::unique_ptr<art::Assns<recob::Shower, recob::Hit> > sh_assn(new art::Assns<recob::Shower, recob::Hit>);
117  std::unique_ptr<art::Assns<recob::PFParticle, recob::Shower> > sp_assn(new art::Assns<recob::PFParticle, recob::Shower>);
118 
119  //
120  // Preparation
121  //
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);
137  for(size_t i=0; i<cHandle->size(); ++i) {
138 
139  local_clusters.push_back(std::vector< ::util::PxHit>());
140 
141  const std::vector<art::Ptr<recob::Hit> >& hits = hit_m.at(i);
142 
143  conv.GeneratePxHit(hits, local_clusters.back());
144  }
145 
146  //
147  // Run shower reconstruction
148  //
149  // shower pfparticle index (later used to make an association)
150  std::vector<size_t> shower_pfpart_index;
151  // cluster combination in terms of cluster index (for ShowerRecoManager::Reconstruct)
152  std::vector<std::vector<unsigned int> > matched_pairs;
153  // shower vector container to receive from ShowerRecoManager::Reconstruct
154  std::vector<recob::Shower> shower_v;
155 
156  if(!fUsePFParticle) matched_pairs = fManager.Reconstruct(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  }
175  // Now to fill matched_pairs retrieve association of pfpart => cluster(s)
176  art::FindManyP<recob::Cluster> cluster_m(pfHandle, e, fInputProducer);
177 
178  for(size_t i=0; i<pfHandle->size(); ++i) {
179 
180  const art::Ptr<recob::PFParticle> pf(pfHandle,i);
181 
182  if(pf->PdgCode()!=11) continue;
183 
184  const std::vector<art::Ptr<recob::Cluster> >& clusters = cluster_m.at(i);
185 
186  std::vector<unsigned int> one_pair;
187  one_pair.reserve(clusters.size());
188 
189  for(auto const& cptr : clusters) {
190 
191  auto iter = cmap.find(cptr);
192  if(iter == cmap.end())
193  throw cet::exception(__FUNCTION__) << "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(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__) << "Logic error: # of matched pairs != # of reco-ed showers!" << std::endl;
207 
208  // Fill output shower vector data container
209  out_shower_v->reserve(shower_v.size());
210 
211  for(size_t i=0; i<shower_v.size(); ++i) {
212 
213  // Set output shower ID
214  shower_v[i].set_id(i);
215 
216  out_shower_v->push_back(shower_v[i]);
217 
218  // Create shower=>cluster association
219  std::vector<art::Ptr<recob::Cluster> > ass_clusters;
220  // Create shower=>hit association
221  std::vector<art::Ptr<recob::Hit> > ass_hits;
222  for(auto const& cindex : matched_pairs[i]) {
223 
224  ass_clusters.push_back( art::Ptr<recob::Cluster>(cHandle,cindex) );
225 
226  const std::vector<art::Ptr<recob::Hit> >& hits = hit_m.at(cindex);
227 
228  for(auto const& ptr : hits) ass_hits.push_back(ptr);
229  }
230  // Shower=>Cluster
231  util::CreateAssn(*this,
232  e,
233  *(out_shower_v.get()),
234  ass_clusters,
235  *(sc_assn.get())
236  );
237  // Shower=>Hits
238  util::CreateAssn(*this,
239  e,
240  *(out_shower_v.get()),
241  ass_hits,
242  *(sh_assn.get())
243  );
244 
245  if(fUsePFParticle) {
246 
248  e.getByLabel(fInputProducer,pfHandle);
249 
250  art::Ptr<recob::PFParticle> pf_ptr(pfHandle,shower_pfpart_index[i]);
251 
252  util::CreateAssn(*this,
253  e,
254  *(out_shower_v.get()),
255  pf_ptr,
256  *(sp_assn.get())
257  );
258  }
259  }
260 
261  // Store in an event record
262  e.put(std::move(out_shower_v));
263  e.put(std::move(sh_assn));
264  e.put(std::move(sc_assn));
265  if(fUsePFParticle)
266  e.put(std::move(sp_assn));
267 
268 }
269 
Class def header for a class ShowerRecoAlg.
void Algo(ShowerRecoAlgBase *alg)
::calo::CalorimetryAlg * fCaloAlgo
::cmtool::CPAlgoArray * fCPAlgoArray
Declaration of signal hit object.
::showerreco::ShowerRecoManager fManager
void AddAlgo(CPriorityAlgoBase *algo)
Setter to add a new algorithm.
Definition: CPAlgoArray.h:63
void SetMinHits(size_t n)
Setter for minimum # hits.
Definition: CPAlgoNHits.h:42
int PdgCode() const
Return the type of particle as a PDG ID.
Definition: PFParticle.h:83
::cmtool::CFAlgoTimeOverlap * fCFAlgoTimeOverlap
void AddMatchAlgo(CFloatAlgoBase *algo)
A simple method to add an algorithm for merging.
Definition: CMatchManager.h:48
void produce(art::Event &e) override
void CaloAlgo(::calo::CalorimetryAlg *alg)
Calorimetry algorithm setter.
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
bool isValid() const
Definition: Handle.h:190
void hits()
Definition: readHits.C:15
std::string fInputProducer
void GeneratePxHit(const std::vector< unsigned int > &hit_index, const std::vector< art::Ptr< recob::Hit >> hits, std::vector< util::PxHit > &pxhits) const
Generate: from 1 set of hits => 1 set of PxHits using indexes (association)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
void setEcorrection(bool on)
Function to decide if to use ModBox (True) or Birks (False) for calorimetry.
Definition: ShowerRecoAlg.h:48
virtual void Verbose(bool on=true)
Verbosity switch.
T get(std::string const &key) const
Definition: ParameterSet.h:231
Class def header for a class CPAlgoArray.
bool CreateAssn(PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t indx=UINT_MAX)
Creates a single one-to-one association.
ClusterAss_t Reconstruct(const std::vector< std::vector< util::PxHit > > &clusters, std::vector< ::recob::Shower > &showers)
Declaration of cluster object.
void SetUseArea(bool on)
Function to decide if to use Area or Pulse Amplitude for calculations.
Definition: ShowerRecoAlg.h:42
Class def header for a class CPAlgoNHits.
::cmtool::CMatchManager & MatchManager()
ShowerReco3D(fhicl::ParameterSet const &p)
::cmtool::CPAlgoIgnoreTracks * fCPAlgoIgnoreTracks
Utility object to perform functions of association.
::showerreco::ShowerRecoAlg * fShowerAlgo
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
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:63
Float_t e
Definition: plot.C:34
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
Class def header for a class ShowerRecoManager.