ShowerReco3D_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // 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.
8 ////////////////////////////////////////////////////////////////////////
9 
14 #include "canvas/Persistency/Common/FindManyP.h"
15 #include "fhiclcpp/ParameterSet.h"
16 
33 
34 #include "ShowerRecoAlg.h"
35 #include "ShowerRecoManager.h"
36 
37 #include <memory>
38 #include <string>
39 
40 class ShowerReco3D : public art::EDProducer {
41 public:
42  explicit ShowerReco3D(fhicl::ParameterSet const& p);
43  // The destructor generated by the compiler is fine for classes
44  // without bare pointers or other resource use.
45 
46  // Plugins should not be copied or assigned.
47  ShowerReco3D(ShowerReco3D const&) = delete;
48  ShowerReco3D(ShowerReco3D&&) = delete;
49  ShowerReco3D& operator=(ShowerReco3D const&) = delete;
50  ShowerReco3D& operator=(ShowerReco3D&&) = delete;
51 
52 private:
53  // Required functions.
54  void produce(art::Event& e) override;
55 
56  // Declare member data here.
66 };
67 
69 {
70  fInputProducer = p.get<std::string>("InputProducer");
71  fUsePFParticle = p.get<bool>("UsePFParticle");
72  produces<std::vector<recob::Shower>>();
73  produces<art::Assns<recob::Shower, recob::Cluster>>();
74  produces<art::Assns<recob::Shower, recob::Hit>>();
75  if (fUsePFParticle) produces<art::Assns<recob::PFParticle, recob::Shower>>();
76 
77  // Instantiate algorithms
78  fCaloAlgo = new ::calo::CalorimetryAlg(p.get<fhicl::ParameterSet>("CalorimetryAlg"));
79  fShowerAlgo = new ::showerreco::ShowerRecoAlg;
80  fCPAlgoArray = new ::cmtool::CPAlgoArray;
81  fCPAlgoNHits = new ::cmtool::CPAlgoNHits;
82  fCPAlgoIgnoreTracks = new ::cmtool::CPAlgoIgnoreTracks;
83  fCFAlgoTimeOverlap = new ::cmtool::CFAlgoTimeOverlap;
84 
85  // Configure
86  fCPAlgoNHits->SetMinHits(p.get<int>("MinHits"));
87 
90 
93 
94  fShowerAlgo->Verbose(p.get<bool>("Verbosity"));
95  fShowerAlgo->SetUseArea(p.get<bool>("UseArea"));
96  fShowerAlgo->setEcorrection(p.get<bool>("ApplyMCEnergyCorrection"));
97  fShowerAlgo->CaloAlgo(fCaloAlgo);
98 
100 }
101 
102 void
104 {
105  auto const& geom = *lar::providerFrom<geo::Geometry>();
106  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(e);
107  auto const detProp =
109  util::GeometryUtilities const gser{geom, clockData, detProp};
110 
111  // Create output data product containers
112  std::unique_ptr<std::vector<recob::Shower>> out_shower_v(new std::vector<recob::Shower>);
113  std::unique_ptr<art::Assns<recob::Shower, recob::Cluster>> sc_assn(
115  std::unique_ptr<art::Assns<recob::Shower, recob::Hit>> sh_assn(
117  std::unique_ptr<art::Assns<recob::PFParticle, recob::Shower>> sp_assn(
119 
120  // Preparation
121 
122  // Reset ShowerRecoManager
123  fManager.Reset();
124 
125  // Retrieve input clusters
127  e.getByLabel(fInputProducer, cHandle);
128 
129  if (!cHandle.isValid())
130  throw cet::exception(__FUNCTION__) << "Invalid input cluster label!" << std::endl;
131 
132  // Cluster type conversion: recob::Hit => util::PxHit
133  std::vector<std::vector<::util::PxHit>> local_clusters;
134  art::FindManyP<recob::Hit> hit_m(cHandle, e, fInputProducer);
135  ::util::PxHitConverter conv{gser};
136  for (size_t i = 0; i < cHandle->size(); ++i) {
137  local_clusters.push_back(std::vector<::util::PxHit>());
138 
139  const std::vector<art::Ptr<recob::Hit>>& hits = hit_m.at(i);
140 
141  conv.GeneratePxHit(hits, local_clusters.back());
142  }
143 
144  //
145  // Run shower reconstruction
146  //
147  // shower pfparticle index (later used to make an association)
148  std::vector<size_t> shower_pfpart_index;
149  // cluster combination in terms of cluster index (for ShowerRecoManager::Reconstruct)
150  std::vector<std::vector<unsigned int>> matched_pairs;
151  // shower vector container to receive from ShowerRecoManager::Reconstruct
152  std::vector<recob::Shower> shower_v;
153 
154  if (!fUsePFParticle) {
155  matched_pairs = fManager.Reconstruct(geom, clockData, detProp, local_clusters, shower_v);
156  }
157  else {
158 
159  // Retrieve PFParticle
161  e.getByLabel(fInputProducer, pfHandle);
162  if (!pfHandle.isValid())
163  throw cet::exception(__FUNCTION__) << "Invalid input PFParticle label!" << std::endl;
164 
165  // Make a cluster ptr => index map to fill matched_pairs
166  std::map<art::Ptr<recob::Cluster>, size_t> cmap;
167  for (size_t i = 0; i < cHandle->size(); ++i) {
168 
169  const art::Ptr<recob::Cluster> cptr(cHandle, i);
170 
171  cmap[cptr] = i;
172  }
173  // Now to fill matched_pairs retrieve association of pfpart => cluster(s)
174  art::FindManyP<recob::Cluster> cluster_m(pfHandle, e, fInputProducer);
175 
176  for (size_t i = 0; i < pfHandle->size(); ++i) {
177 
178  const art::Ptr<recob::PFParticle> pf(pfHandle, i);
179 
180  if (pf->PdgCode() != 11) continue;
181 
182  const std::vector<art::Ptr<recob::Cluster>>& clusters = cluster_m.at(i);
183 
184  std::vector<unsigned int> one_pair;
185  one_pair.reserve(clusters.size());
186 
187  for (auto const& cptr : clusters) {
188 
189  auto iter = cmap.find(cptr);
190  if (iter == cmap.end())
191  throw cet::exception(__FUNCTION__)
192  << "PFParticle=>Cluster association not valid!" << std::endl;
193 
194  one_pair.push_back((*iter).second);
195  }
196  matched_pairs.push_back(one_pair);
197  shower_pfpart_index.push_back(i);
198  }
199  // Run reconstruction
200  fManager.Reconstruct(geom, clockData, detProp, local_clusters, matched_pairs, shower_v);
201  }
202 
203  // Make sure output shower vector size is same as expected length
204  if (shower_v.size() != matched_pairs.size())
205  throw cet::exception(__FUNCTION__)
206  << "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)
229  ass_hits.push_back(ptr);
230  }
231  // Shower=>Cluster
232  util::CreateAssn(*this, e, *(out_shower_v.get()), ass_clusters, *(sc_assn.get()));
233  // Shower=>Hits
234  util::CreateAssn(*this, e, *(out_shower_v.get()), ass_hits, *(sh_assn.get()));
235 
236  if (fUsePFParticle) {
237 
239  e.getByLabel(fInputProducer, pfHandle);
240 
241  art::Ptr<recob::PFParticle> pf_ptr(pfHandle, shower_pfpart_index[i]);
242 
243  util::CreateAssn(*this, e, *(out_shower_v.get()), pf_ptr, *(sp_assn.get()));
244  }
245  }
246 
247  // Store in an event record
248  e.put(std::move(out_shower_v));
249  e.put(std::move(sh_assn));
250  e.put(std::move(sc_assn));
251  if (fUsePFParticle) e.put(std::move(sp_assn));
252 }
253 
void Algo(ShowerRecoAlgBase *alg)
::calo::CalorimetryAlg * fCaloAlgo
::cmtool::CPAlgoArray * fCPAlgoArray
std::string string
Definition: nybbler.cc:12
::showerreco::ShowerRecoManager fManager
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
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:47
void produce(art::Event &e) override
void CaloAlgo(calo::CalorimetryAlg *alg)
Definition: ShowerRecoAlg.h:36
art framework interface to geometry description
bool isValid() const noexcept
Definition: Handle.h:191
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
const double e
std::string fInputProducer
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
void setEcorrection(bool on)
Function to set whether to use E correction.
Definition: ShowerRecoAlg.h:43
def move(depos, offset)
Definition: depos.py:107
p
Definition: test.py:223
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
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.
void SetUseArea(bool on)
Function to decide if to use Area or Pulse Amplitude for calculations.
Definition: ShowerRecoAlg.h:24
Class def header for a class CPAlgoNHits.
::cmtool::CMatchManager & MatchManager()
void Verbose(bool verbose)
Definition: ShowerRecoAlg.h:30
ShowerReco3D(fhicl::ParameterSet const &p)
::cmtool::CPAlgoIgnoreTracks * fCPAlgoIgnoreTracks
Declaration of signal hit object.
::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:80
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
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.