All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TCShower_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: TCShower
3 // Plugin Type: producer (art v2_11_02)
4 // File: TCShower_module.cc
5 //
6 // Generated at Fri Jun 8 14:55:04 2018 by Rory Fitzpatrick using cetskelgen
7 // from cetlib version v3_03_01.
8 //
9 // Contact: roryfitz@umich.edu
10 //
11 // module produces showers by selecting tracks surround by many
12 // showerLike trajectories as defined by trajcluster with negative
13 // cluster IDs
14 ////////////////////////////////////////////////////////////////////////
15 
16 #include "art/Framework/Core/EDProducer.h"
17 #include "art/Framework/Core/ModuleMacros.h"
18 #include "art/Framework/Principal/Event.h"
19 #include "art/Framework/Principal/Handle.h"
20 #include "art/Framework/Services/Registry/ServiceHandle.h"
21 #include "canvas/Persistency/Common/FindManyP.h"
22 #include "fhiclcpp/ParameterSet.h"
23 
35 
37 
38 #include <memory>
39 
40 namespace shower {
41  class TCShower;
42 }
43 
44 class shower::TCShower : public art::EDProducer {
45 public:
46  explicit TCShower(fhicl::ParameterSet const& p);
47 
48  TCShower(TCShower const&) = delete;
49  TCShower(TCShower&&) = delete;
50  TCShower& operator=(TCShower const&) = delete;
51  TCShower& operator=(TCShower&&) = delete;
52 
53 private:
54  void produce(art::Event& e) override;
55 
56  int getShowersWithSlices(art::Event const& evt,
57  detinfo::DetectorClocksData const& clockData,
59  art::Ptr<recob::Slice> const& thisslice);
60  int getShowersWithoutSlices(art::Event const& evt,
61  detinfo::DetectorClocksData const& clockData,
62  detinfo::DetectorPropertiesData const& detProp);
63 
65 
66  std::string fClusterModuleLabel;
67  std::string fTrackModuleLabel;
68  std::string fHitModuleLabel;
69  std::string fSliceModuleLabel;
70  std::string fVertexModuleLabel;
72 };
73 
74 // -----------------------------------------------------
75 
76 shower::TCShower::TCShower(fhicl::ParameterSet const& pset)
77  : EDProducer{pset}
78  , fTCAlg(pset.get<fhicl::ParameterSet>("TCAlg"))
79  , fClusterModuleLabel(pset.get<std::string>("ClusterModuleLabel", "trajcluster"))
80  , fTrackModuleLabel(pset.get<std::string>("TrackModuleLabel", "trajclusterKalmanTrack"))
81  , fHitModuleLabel(pset.get<std::string>("HitModuleLabel", "trajcluster"))
82  , fSliceModuleLabel(pset.get<std::string>("SliceModuleLabel", "dbcluster3d"))
83  , fVertexModuleLabel(pset.get<std::string>("VertexModuleLabel", "trajcluster"))
84  , fCalorimetryModuleLabel(pset.get<std::string>("CalorimetryModuleLabel"))
85 {
86  produces<std::vector<recob::Shower>>();
87  produces<art::Assns<recob::Shower, recob::Hit>>();
88  produces<art::Assns<recob::Slice, recob::Shower>>();
89 }
90 
91 // -----------------------------------------------------
92 
93 void
95 {
96  auto showers = std::make_unique<std::vector<recob::Shower>>();
97  auto hitShowerAssociations = std::make_unique<art::Assns<recob::Shower, recob::Hit>>();
98  auto sliceShowerAssociations = std::make_unique<art::Assns<recob::Slice, recob::Shower>>();
99 
100  // slices
101  art::Handle<std::vector<recob::Slice>> sliceListHandle;
102  std::vector<art::Ptr<recob::Slice>> slicelist;
103  if (evt.getByLabel(fSliceModuleLabel, sliceListHandle))
104  art::fill_ptr_vector(slicelist, sliceListHandle);
105 
106  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
107  auto const detProp =
108  art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt, clockData);
109 
110  int foundShower = -1;
111 
112  if (empty(slicelist)) { // no slices
113  foundShower = getShowersWithoutSlices(evt, clockData, detProp);
114 
115  if (foundShower) {
116  showers->emplace_back(fTCAlg.shwDir,
117  fTCAlg.dcosVtxErr,
118  fTCAlg.shwvtx,
119  fTCAlg.xyzErr,
120  fTCAlg.totalEnergy,
121  fTCAlg.totalEnergyErr,
122  fTCAlg.dEdx,
123  fTCAlg.dEdxErr,
124  fTCAlg.bestplane,
125  0);
126  showers->back().set_id(showers->size() - 1);
127 
128  util::CreateAssn(evt, *showers, fTCAlg.showerHits, *hitShowerAssociations);
129  }
130  }
131  else { // use slices
132  for (size_t i = 0; i < slicelist.size(); ++i) {
133  std::cout << "---------- slice " << i << " ----------" << std::endl;
134 
135  foundShower = getShowersWithSlices(evt, clockData, detProp, slicelist[i]);
136 
137  if (foundShower) {
138  std::cout << "FOUND SHOWER " << foundShower << std::endl;
139  std::cout << "shower hits " << fTCAlg.showerHits.size() << std::endl;
140 
141  showers->emplace_back(fTCAlg.shwDir,
142  fTCAlg.dcosVtxErr,
143  fTCAlg.shwvtx,
144  fTCAlg.xyzErr,
145  fTCAlg.totalEnergy,
146  fTCAlg.totalEnergyErr,
147  fTCAlg.dEdx,
148  fTCAlg.dEdxErr,
149  fTCAlg.bestplane,
150  0);
151  showers->back().set_id(showers->size() - 1);
152 
153  util::CreateAssn(evt, *showers, fTCAlg.showerHits, *hitShowerAssociations);
154  util::CreateAssn(evt, *showers, slicelist[i], *sliceShowerAssociations);
155  }
156  } // loop through slices
157  } // with slices
158 
159  evt.put(std::move(showers));
160  evt.put(std::move(hitShowerAssociations));
161  evt.put(std::move(sliceShowerAssociations));
162 } // produce
163 
164 // -----------------------------------------------------
165 int
167  detinfo::DetectorClocksData const& clockData,
169  art::Ptr<recob::Slice> const& thisslice)
170 {
171  art::Handle<std::vector<recob::Hit>> hitListHandle;
172  evt.getByLabel(fHitModuleLabel, hitListHandle);
173 
174  art::Handle<std::vector<recob::Cluster>> clusterListHandle;
175  evt.getByLabel(fClusterModuleLabel, clusterListHandle);
176 
177  art::Handle<std::vector<recob::Track>> trackListHandle;
178  evt.getByLabel(fTrackModuleLabel, trackListHandle);
179 
180  art::Handle<std::vector<recob::Slice>> sliceListHandle;
181  evt.getByLabel(fSliceModuleLabel, sliceListHandle);
182 
183  art::Handle<std::vector<recob::Vertex>> vtxListHandle;
184  evt.getByLabel(fVertexModuleLabel, vtxListHandle);
185 
186  art::Handle<std::vector<recob::PFParticle>> pfpListHandle;
187  evt.getByLabel(fHitModuleLabel, pfpListHandle);
188 
189  art::FindManyP<recob::Hit> hitslice_fm(sliceListHandle, evt, fHitModuleLabel);
190  art::FindManyP<recob::PFParticle> pfpslice_fm(sliceListHandle, evt, fHitModuleLabel);
191  art::FindManyP<recob::Cluster> clsslice_fm(sliceListHandle, evt, fHitModuleLabel);
192  art::FindManyP<recob::Cluster> clspfp_fm(pfpListHandle, evt, fHitModuleLabel);
193  art::FindManyP<recob::Vertex> vtxpfp_fm(pfpListHandle, evt, fVertexModuleLabel);
194  // art::FindManyP<recob::EndPoint2D> vx2cls_fm(clusterListHandle, evt, fClusterModuleLabel);
195 
196  std::vector<art::Ptr<recob::Hit>> hitlist;
197  std::vector<art::Ptr<recob::Cluster>> clusterlist;
198  std::vector<art::Ptr<recob::Vertex>> vertexlist;
199  std::vector<art::Ptr<recob::EndPoint2D>> vx2list;
200 
201  // get all hits with hit-slice association
202  hitlist = hitslice_fm.at(thisslice.key());
203 
204  // get all clusters with cluster-slice association
205  clusterlist = clsslice_fm.at(thisslice.key());
206 
207  std::vector<art::Ptr<recob::PFParticle>> pfplist = pfpslice_fm.at(thisslice.key());
208 
209  for (size_t i = 0; i < pfplist.size(); ++i) {
210  std::vector<art::Ptr<recob::Vertex>> thisvtxlist = vtxpfp_fm.at(pfplist[i].key());
211  // get all verticies with slice-pfparticle, pfparticle-vertex
212  for (size_t j = 0; j < thisvtxlist.size(); ++j) {
213  vertexlist.push_back(thisvtxlist[j]);
214  } // loop through tracks
215  } // loop through pfparticles
216 
217  // get associations
218  art::FindManyP<recob::Hit> cls_fm(clusterListHandle, evt, fClusterModuleLabel);
219  art::FindManyP<recob::PFParticle> hit_fm(hitListHandle, evt, fHitModuleLabel);
220  art::FindManyP<recob::Cluster> hitcls_fm(hitListHandle, evt, fClusterModuleLabel);
221  art::FindManyP<recob::Track> trkpfp_fm(pfpListHandle, evt, fTrackModuleLabel);
222 
223  art::FindManyP<anab::Calorimetry> fmcal(trackListHandle, evt, fCalorimetryModuleLabel);
224 
225  return fTCAlg.makeShowers(clockData,
226  detProp,
227  pfplist,
228  vertexlist,
229  clusterlist,
230  hitlist,
231  cls_fm,
232  clspfp_fm,
233  vtxpfp_fm,
234  hit_fm,
235  hitcls_fm,
236  trkpfp_fm,
237  fmcal);
238 }
239 
240 // -----------------------------------------------------
241 int
243  detinfo::DetectorClocksData const& clockData,
245 {
246  // pfparticles
247  art::Handle<std::vector<recob::PFParticle>> pfpListHandle;
248  std::vector<art::Ptr<recob::PFParticle>> pfplist;
249  if (evt.getByLabel(fHitModuleLabel, pfpListHandle)) art::fill_ptr_vector(pfplist, pfpListHandle);
250 
251  art::Handle<std::vector<recob::Hit>> hitListHandle;
252  std::vector<art::Ptr<recob::Hit>> hitlist;
253  if (evt.getByLabel(fHitModuleLabel, hitListHandle)) art::fill_ptr_vector(hitlist, hitListHandle);
254 
255  art::Handle<std::vector<recob::Cluster>> clusterListHandle;
256  std::vector<art::Ptr<recob::Cluster>> clusterlist;
257  if (evt.getByLabel(fClusterModuleLabel, clusterListHandle))
258  art::fill_ptr_vector(clusterlist, clusterListHandle);
259 
260  art::Handle<std::vector<recob::Vertex>> vtxListHandle;
261  std::vector<art::Ptr<recob::Vertex>> vertexlist;
262  if (evt.getByLabel(fVertexModuleLabel, vtxListHandle))
263  art::fill_ptr_vector(vertexlist, vtxListHandle);
264 
265  art::Handle<std::vector<recob::Track>> trackListHandle;
266  evt.getByLabel(fTrackModuleLabel, trackListHandle);
267 
268  // get associations
269  art::FindManyP<recob::Cluster> clspfp_fm(pfpListHandle, evt, fHitModuleLabel);
270  art::FindManyP<recob::Vertex> vtxpfp_fm(pfpListHandle, evt, fVertexModuleLabel);
271  art::FindManyP<recob::Hit> cls_fm(clusterListHandle, evt, fClusterModuleLabel);
272  art::FindManyP<recob::PFParticle> hit_fm(hitListHandle, evt, fHitModuleLabel);
273  art::FindManyP<recob::Cluster> hitcls_fm(hitListHandle, evt, fClusterModuleLabel);
274  art::FindManyP<recob::Track> trkpfp_fm(pfpListHandle, evt, fTrackModuleLabel);
275 
276  art::FindManyP<anab::Calorimetry> fmcal(trackListHandle, evt, fCalorimetryModuleLabel);
277 
278  return fTCAlg.makeShowers(clockData,
279  detProp,
280  pfplist,
281  vertexlist,
282  clusterlist,
283  hitlist,
284  cls_fm,
285  clspfp_fm,
286  vtxpfp_fm,
287  hit_fm,
288  hitcls_fm,
289  trkpfp_fm,
290  fmcal);
291 }
292 
293 DEFINE_ART_MODULE(shower::TCShower)
shower::TCShowerAlg fTCAlg
int getShowersWithSlices(art::Event const &evt, detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, art::Ptr< recob::Slice > const &thisslice)
int getShowersWithoutSlices(art::Event const &evt, detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp)
Declaration of signal hit object.
std::string fVertexModuleLabel
pdgs p
Definition: selectors.fcl:22
TCShower(fhicl::ParameterSet const &p)
std::string fSliceModuleLabel
process_name shower
Definition: cheaterreco.fcl:51
TCShower & operator=(TCShower const &)=delete
std::string fTrackModuleLabel
void produce(art::Event &e) override
std::string fHitModuleLabel
std::string fClusterModuleLabel
Declaration of cluster object.
Provides recob::Track data product.
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.
Contains all timing reference information for the detector.
std::string fCalorimetryModuleLabel
do i e
TCEvent evt
Definition: DataStructs.cxx:8
bool empty(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:555
BEGIN_PROLOG could also be cout
auto const detProp