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 
20 #include "canvas/Persistency/Common/FindManyP.h"
21 #include "fhiclcpp/ParameterSet.h"
22 
34 
36 
37 #include <memory>
38 
39 namespace shower {
40  class TCShower;
41 }
42 
44 public:
45  explicit TCShower(fhicl::ParameterSet const& p);
46 
47  TCShower(TCShower const&) = delete;
48  TCShower(TCShower&&) = delete;
49  TCShower& operator=(TCShower const&) = delete;
50  TCShower& operator=(TCShower&&) = delete;
51 
52 private:
53  void produce(art::Event& e) override;
54 
56  detinfo::DetectorClocksData const& clockData,
57  detinfo::DetectorPropertiesData const& detProp,
58  art::Ptr<recob::Slice> const& thisslice);
59  int getShowersWithoutSlices(art::Event const& evt,
60  detinfo::DetectorClocksData const& clockData,
61  detinfo::DetectorPropertiesData const& detProp);
62 
64 
71 };
72 
73 // -----------------------------------------------------
74 
76  : EDProducer{pset}
77  , fTCAlg(pset.get<fhicl::ParameterSet>("TCAlg"))
78  , fClusterModuleLabel(pset.get<std::string>("ClusterModuleLabel", "trajcluster"))
79  , fTrackModuleLabel(pset.get<std::string>("TrackModuleLabel", "trajclusterKalmanTrack"))
80  , fHitModuleLabel(pset.get<std::string>("HitModuleLabel", "trajcluster"))
81  , fSliceModuleLabel(pset.get<std::string>("SliceModuleLabel", "dbcluster3d"))
82  , fVertexModuleLabel(pset.get<std::string>("VertexModuleLabel", "trajcluster"))
83  , fCalorimetryModuleLabel(pset.get<std::string>("CalorimetryModuleLabel"))
84 {
85  produces<std::vector<recob::Shower>>();
86  produces<art::Assns<recob::Shower, recob::Hit>>();
87  produces<art::Assns<recob::Slice, recob::Shower>>();
88 }
89 
90 // -----------------------------------------------------
91 
92 void
94 {
95  auto showers = std::make_unique<std::vector<recob::Shower>>();
96  auto hitShowerAssociations = std::make_unique<art::Assns<recob::Shower, recob::Hit>>();
97  auto sliceShowerAssociations = std::make_unique<art::Assns<recob::Slice, recob::Shower>>();
98 
99  // slices
100  art::Handle<std::vector<recob::Slice>> sliceListHandle;
101  std::vector<art::Ptr<recob::Slice>> slicelist;
102  if (evt.getByLabel(fSliceModuleLabel, sliceListHandle))
103  art::fill_ptr_vector(slicelist, sliceListHandle);
104 
105  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
106  auto const detProp =
108 
109  int foundShower = -1;
110 
111  if (empty(slicelist)) { // no slices
112  foundShower = getShowersWithoutSlices(evt, clockData, detProp);
113 
114  if (foundShower) {
115  showers->emplace_back(fTCAlg.shwDir,
117  fTCAlg.shwvtx,
118  fTCAlg.xyzErr,
121  fTCAlg.dEdx,
122  fTCAlg.dEdxErr,
124  0);
125  showers->back().set_id(showers->size() - 1);
126 
127  util::CreateAssn(evt, *showers, fTCAlg.showerHits, *hitShowerAssociations);
128  }
129  }
130  else { // use slices
131  for (size_t i = 0; i < slicelist.size(); ++i) {
132  std::cout << "---------- slice " << i << " ----------" << std::endl;
133 
134  foundShower = getShowersWithSlices(evt, clockData, detProp, slicelist[i]);
135 
136  if (foundShower) {
137  std::cout << "FOUND SHOWER " << foundShower << std::endl;
138  std::cout << "shower hits " << fTCAlg.showerHits.size() << std::endl;
139 
140  showers->emplace_back(fTCAlg.shwDir,
142  fTCAlg.shwvtx,
143  fTCAlg.xyzErr,
146  fTCAlg.dEdx,
147  fTCAlg.dEdxErr,
149  0);
150  showers->back().set_id(showers->size() - 1);
151 
152  util::CreateAssn(evt, *showers, fTCAlg.showerHits, *hitShowerAssociations);
153  util::CreateAssn(evt, *showers, slicelist[i], *sliceShowerAssociations);
154  }
155  } // loop through slices
156  } // with slices
157 
158  evt.put(std::move(showers));
159  evt.put(std::move(hitShowerAssociations));
160  evt.put(std::move(sliceShowerAssociations));
161 } // produce
162 
163 // -----------------------------------------------------
164 int
166  detinfo::DetectorClocksData const& clockData,
167  detinfo::DetectorPropertiesData const& detProp,
168  art::Ptr<recob::Slice> const& thisslice)
169 {
171  evt.getByLabel(fHitModuleLabel, hitListHandle);
172 
173  art::Handle<std::vector<recob::Cluster>> clusterListHandle;
174  evt.getByLabel(fClusterModuleLabel, clusterListHandle);
175 
176  art::Handle<std::vector<recob::Track>> trackListHandle;
177  evt.getByLabel(fTrackModuleLabel, trackListHandle);
178 
179  art::Handle<std::vector<recob::Slice>> sliceListHandle;
180  evt.getByLabel(fSliceModuleLabel, sliceListHandle);
181 
183  evt.getByLabel(fVertexModuleLabel, vtxListHandle);
184 
186  evt.getByLabel(fHitModuleLabel, pfpListHandle);
187 
188  art::FindManyP<recob::Hit> hitslice_fm(sliceListHandle, evt, fHitModuleLabel);
189  art::FindManyP<recob::PFParticle> pfpslice_fm(sliceListHandle, evt, fHitModuleLabel);
190  art::FindManyP<recob::Cluster> clsslice_fm(sliceListHandle, evt, fHitModuleLabel);
191  art::FindManyP<recob::Cluster> clspfp_fm(pfpListHandle, evt, fHitModuleLabel);
192  art::FindManyP<recob::Vertex> vtxpfp_fm(pfpListHandle, evt, fVertexModuleLabel);
193  // art::FindManyP<recob::EndPoint2D> vx2cls_fm(clusterListHandle, evt, fClusterModuleLabel);
194 
195  std::vector<art::Ptr<recob::Hit>> hitlist;
196  std::vector<art::Ptr<recob::Cluster>> clusterlist;
197  std::vector<art::Ptr<recob::Vertex>> vertexlist;
198  std::vector<art::Ptr<recob::EndPoint2D>> vx2list;
199 
200  // get all hits with hit-slice association
201  hitlist = hitslice_fm.at(thisslice.key());
202 
203  // get all clusters with cluster-slice association
204  clusterlist = clsslice_fm.at(thisslice.key());
205 
206  std::vector<art::Ptr<recob::PFParticle>> pfplist = pfpslice_fm.at(thisslice.key());
207 
208  for (size_t i = 0; i < pfplist.size(); ++i) {
209  std::vector<art::Ptr<recob::Vertex>> thisvtxlist = vtxpfp_fm.at(pfplist[i].key());
210  // get all verticies with slice-pfparticle, pfparticle-vertex
211  for (size_t j = 0; j < thisvtxlist.size(); ++j) {
212  vertexlist.push_back(thisvtxlist[j]);
213  } // loop through tracks
214  } // loop through pfparticles
215 
216  // get associations
217  art::FindManyP<recob::Hit> cls_fm(clusterListHandle, evt, fClusterModuleLabel);
218  art::FindManyP<recob::PFParticle> hit_fm(hitListHandle, evt, fHitModuleLabel);
219  art::FindManyP<recob::Cluster> hitcls_fm(hitListHandle, evt, fClusterModuleLabel);
220  art::FindManyP<recob::Track> trkpfp_fm(pfpListHandle, evt, fTrackModuleLabel);
221 
222  art::FindManyP<anab::Calorimetry> fmcal(trackListHandle, evt, fCalorimetryModuleLabel);
223 
224  return fTCAlg.makeShowers(clockData,
225  detProp,
226  pfplist,
227  vertexlist,
228  clusterlist,
229  hitlist,
230  cls_fm,
231  clspfp_fm,
232  vtxpfp_fm,
233  hit_fm,
234  hitcls_fm,
235  trkpfp_fm,
236  fmcal);
237 }
238 
239 // -----------------------------------------------------
240 int
242  detinfo::DetectorClocksData const& clockData,
243  detinfo::DetectorPropertiesData const& detProp)
244 {
245  // pfparticles
247  std::vector<art::Ptr<recob::PFParticle>> pfplist;
248  if (evt.getByLabel(fHitModuleLabel, pfpListHandle)) art::fill_ptr_vector(pfplist, pfpListHandle);
249 
251  std::vector<art::Ptr<recob::Hit>> hitlist;
252  if (evt.getByLabel(fHitModuleLabel, hitListHandle)) art::fill_ptr_vector(hitlist, hitListHandle);
253 
254  art::Handle<std::vector<recob::Cluster>> clusterListHandle;
255  std::vector<art::Ptr<recob::Cluster>> clusterlist;
256  if (evt.getByLabel(fClusterModuleLabel, clusterListHandle))
257  art::fill_ptr_vector(clusterlist, clusterListHandle);
258 
260  std::vector<art::Ptr<recob::Vertex>> vertexlist;
261  if (evt.getByLabel(fVertexModuleLabel, vtxListHandle))
262  art::fill_ptr_vector(vertexlist, vtxListHandle);
263 
264  art::Handle<std::vector<recob::Track>> trackListHandle;
265  evt.getByLabel(fTrackModuleLabel, trackListHandle);
266 
267  // get associations
268  art::FindManyP<recob::Cluster> clspfp_fm(pfpListHandle, evt, fHitModuleLabel);
269  art::FindManyP<recob::Vertex> vtxpfp_fm(pfpListHandle, evt, fVertexModuleLabel);
270  art::FindManyP<recob::Hit> cls_fm(clusterListHandle, evt, fClusterModuleLabel);
271  art::FindManyP<recob::PFParticle> hit_fm(hitListHandle, evt, fHitModuleLabel);
272  art::FindManyP<recob::Cluster> hitcls_fm(hitListHandle, evt, fClusterModuleLabel);
273  art::FindManyP<recob::Track> trkpfp_fm(pfpListHandle, evt, fTrackModuleLabel);
274 
275  art::FindManyP<anab::Calorimetry> fmcal(trackListHandle, evt, fCalorimetryModuleLabel);
276 
277  return fTCAlg.makeShowers(clockData,
278  detProp,
279  pfplist,
280  vertexlist,
281  clusterlist,
282  hitlist,
283  cls_fm,
284  clspfp_fm,
285  vtxpfp_fm,
286  hit_fm,
287  hitcls_fm,
288  trkpfp_fm,
289  fmcal);
290 }
291 
shower::TCShowerAlg fTCAlg
std::vector< double > totalEnergyErr
Definition: TCShowerAlg.h:43
int getShowersWithSlices(art::Event const &evt, detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, art::Ptr< recob::Slice > const &thisslice)
std::string string
Definition: nybbler.cc:12
int getShowersWithoutSlices(art::Event const &evt, detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp)
std::vector< double > dEdx
Definition: TCShowerAlg.h:44
std::string fVertexModuleLabel
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
TCShower(fhicl::ParameterSet const &p)
std::string fSliceModuleLabel
TCShower & operator=(TCShower const &)=delete
std::string fTrackModuleLabel
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
int makeShowers(detinfo::DetectorClocksData const &dataClock, detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::PFParticle >> const &pfplist, std::vector< art::Ptr< recob::Vertex >> const &vertexlist, std::vector< art::Ptr< recob::Cluster >> const &clusterlist, std::vector< art::Ptr< recob::Hit >> const &hitlist, art::FindManyP< recob::Hit > const &cls_fm, art::FindManyP< recob::Cluster > const &clspfp_fm, art::FindManyP< recob::Vertex > const &vtxpfp_fm, art::FindManyP< recob::PFParticle > const &hit_fm, art::FindManyP< recob::Cluster > const &hitcls_fm, art::FindManyP< recob::Track > const &trkpfp_fm, art::FindManyP< anab::Calorimetry > const &fmcal)
Definition: TCShowerAlg.cxx:51
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
void produce(art::Event &e) override
def key(type, name=None)
Definition: graph.py:13
std::string fHitModuleLabel
def move(depos, offset)
Definition: depos.py:107
key_type key() const noexcept
Definition: Ptr.h:216
p
Definition: test.py:223
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
std::string fClusterModuleLabel
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.
Declaration of signal hit object.
Contains all timing reference information for the detector.
std::string fCalorimetryModuleLabel
Provides recob::Track data product.
std::vector< double > totalEnergy
Definition: TCShowerAlg.h:42
TCEvent evt
Definition: DataStructs.cxx:7
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
std::vector< art::Ptr< recob::Hit > > showerHits
Definition: TCShowerAlg.h:47
std::vector< double > dEdxErr
Definition: TCShowerAlg.h:45
Definition: fwd.h:31
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:97
QTextStream & endl(QTextStream &s)