LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
TCShower_module.cc
Go to the documentation of this file.
1 // 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
15 
22 #include "fhiclcpp/ParameterSet.h"
23 
35 
37 
38 #include <memory>
39 
40 namespace shower {
41  class TCShower;
42 }
43 
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 
57  detinfo::DetectorClocksData const& clockData,
58  detinfo::DetectorPropertiesData const& detProp,
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 
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 
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  auto const& shwDir = fTCAlg.shwDir;
116  auto const& shwvtx = fTCAlg.shwvtx;
117  showers->emplace_back(TVector3{shwDir.X(), shwDir.Y(), shwDir.Z()},
119  TVector3{shwvtx.X(), shwvtx.Y(), shwvtx.Z()},
120  fTCAlg.xyzErr,
123  fTCAlg.dEdx,
124  fTCAlg.dEdxErr,
126  0);
127  showers->back().set_id(showers->size() - 1);
128 
129  util::CreateAssn(evt, *showers, fTCAlg.showerHits, *hitShowerAssociations);
130  }
131  }
132  else { // use slices
133  for (size_t i = 0; i < slicelist.size(); ++i) {
134  std::cout << "---------- slice " << i << " ----------" << std::endl;
135 
136  foundShower = getShowersWithSlices(evt, clockData, detProp, slicelist[i]);
137 
138  if (foundShower) {
139  std::cout << "FOUND SHOWER " << foundShower << std::endl;
140  std::cout << "shower hits " << fTCAlg.showerHits.size() << std::endl;
141 
142  auto const& shwDir = fTCAlg.shwDir;
143  auto const& shwvtx = fTCAlg.shwvtx;
144  showers->emplace_back(TVector3{shwDir.X(), shwDir.Y(), shwDir.Z()},
146  TVector3{shwvtx.X(), shwvtx.Y(), shwvtx.Z()},
147  fTCAlg.xyzErr,
150  fTCAlg.dEdx,
151  fTCAlg.dEdxErr,
153  0);
154  showers->back().set_id(showers->size() - 1);
155 
156  util::CreateAssn(evt, *showers, fTCAlg.showerHits, *hitShowerAssociations);
157  util::CreateAssn(evt, *showers, slicelist[i], *sliceShowerAssociations);
158  }
159  } // loop through slices
160  } // with slices
161 
162  evt.put(std::move(showers));
163  evt.put(std::move(hitShowerAssociations));
164  evt.put(std::move(sliceShowerAssociations));
165 } // produce
166 
167 // -----------------------------------------------------
169  detinfo::DetectorClocksData const& clockData,
170  detinfo::DetectorPropertiesData const& detProp,
171  art::Ptr<recob::Slice> const& thisslice)
172 {
173  auto hitListHandle = evt.getHandle<std::vector<recob::Hit>>(fHitModuleLabel);
174  auto clusterListHandle = evt.getHandle<std::vector<recob::Cluster>>(fClusterModuleLabel);
175  auto trackListHandle = evt.getHandle<std::vector<recob::Track>>(fTrackModuleLabel);
176  auto sliceListHandle = evt.getHandle<std::vector<recob::Slice>>(fSliceModuleLabel);
177  auto vtxListHandle = evt.getHandle<std::vector<recob::Vertex>>(fVertexModuleLabel);
178  auto pfpListHandle = evt.getHandle<std::vector<recob::PFParticle>>(fHitModuleLabel);
179 
180  art::FindManyP<recob::Hit> hitslice_fm(sliceListHandle, evt, fHitModuleLabel);
181  art::FindManyP<recob::PFParticle> pfpslice_fm(sliceListHandle, evt, fHitModuleLabel);
182  art::FindManyP<recob::Cluster> clsslice_fm(sliceListHandle, evt, fHitModuleLabel);
183  art::FindManyP<recob::Cluster> clspfp_fm(pfpListHandle, evt, fHitModuleLabel);
184  art::FindManyP<recob::Vertex> vtxpfp_fm(pfpListHandle, evt, fVertexModuleLabel);
185 
186  // get all hits with hit-slice association
187  auto const& hitlist = hitslice_fm.at(thisslice.key());
188 
189  // get all clusters with cluster-slice association
190  auto const& clusterlist = clsslice_fm.at(thisslice.key());
191 
192  auto const& pfplist = pfpslice_fm.at(thisslice.key());
193 
194  // get associations
195  art::FindManyP<recob::Hit> cls_fm(clusterListHandle, evt, fClusterModuleLabel);
196  art::FindManyP<recob::Cluster> hitcls_fm(hitListHandle, evt, fClusterModuleLabel);
197  art::FindManyP<recob::Track> trkpfp_fm(pfpListHandle, evt, fTrackModuleLabel);
198 
199  return fTCAlg.makeShowers(clockData,
200  detProp,
201  pfplist,
202  clusterlist,
203  hitlist,
204  cls_fm,
205  clspfp_fm,
206  vtxpfp_fm,
207  hitcls_fm,
208  trkpfp_fm);
209 }
210 
211 // -----------------------------------------------------
213  detinfo::DetectorClocksData const& clockData,
214  detinfo::DetectorPropertiesData const& detProp)
215 {
216  auto pfpListHandle = evt.getHandle<std::vector<recob::PFParticle>>(fHitModuleLabel);
217  std::vector<art::Ptr<recob::PFParticle>> pfplist;
218  if (pfpListHandle) { art::fill_ptr_vector(pfplist, pfpListHandle); }
219 
220  auto clusterListHandle = evt.getHandle<std::vector<recob::Cluster>>(fClusterModuleLabel);
221  std::vector<art::Ptr<recob::Cluster>> clusterlist;
222  if (clusterListHandle) { art::fill_ptr_vector(clusterlist, clusterListHandle); }
223 
224  auto hitListHandle = evt.getHandle<std::vector<recob::Hit>>(fHitModuleLabel);
225  std::vector<art::Ptr<recob::Hit>> hitlist;
226  if (hitListHandle) { art::fill_ptr_vector(hitlist, hitListHandle); }
227 
228  // get associations
229  art::FindManyP<recob::Hit> cls_fm(clusterListHandle, evt, fClusterModuleLabel);
230  art::FindManyP<recob::Cluster> clspfp_fm(pfpListHandle, evt, fHitModuleLabel);
231  art::FindManyP<recob::Vertex> vtxpfp_fm(pfpListHandle, evt, fVertexModuleLabel);
232  art::FindManyP<recob::Cluster> hitcls_fm(hitListHandle, evt, fClusterModuleLabel);
233  art::FindManyP<recob::Track> trkpfp_fm(pfpListHandle, evt, fTrackModuleLabel);
234 
235  return fTCAlg.makeShowers(clockData,
236  detProp,
237  pfplist,
238  clusterlist,
239  hitlist,
240  cls_fm,
241  clspfp_fm,
242  vtxpfp_fm,
243  hitcls_fm,
244  trkpfp_fm);
245 }
246 
shower::TCShowerAlg fTCAlg
std::vector< double > totalEnergyErr
Definition: TCShowerAlg.h:46
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)
std::vector< double > dEdx
Definition: TCShowerAlg.h:47
Declaration of signal hit object.
std::string fVertexModuleLabel
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
TCShower(fhicl::ParameterSet const &p)
std::string fSliceModuleLabel
geo::Point_t shwvtx
Definition: TCShowerAlg.h:43
int makeShowers(detinfo::DetectorClocksData const &dataClock, detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::PFParticle >> const &pfplist, 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::Cluster > const &hitcls_fm, art::FindManyP< recob::Track > const &trkpfp_fm)
Definition: TCShowerAlg.cxx:49
TCShower & operator=(TCShower const &)=delete
std::string fTrackModuleLabel
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
geo::Vector_t shwDir
Definition: TCShowerAlg.h:41
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
void produce(art::Event &e) override
std::string fHitModuleLabel
key_type key() const noexcept
Definition: Ptr.h:166
Provides recob::Track data product.
std::string fClusterModuleLabel
Declaration of cluster object.
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.
Handle< PROD > getHandle(SelectorBase const &) const
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Utility object to perform functions of association.
Contains all timing reference information for the detector.
std::string fCalorimetryModuleLabel
std::vector< double > totalEnergy
Definition: TCShowerAlg.h:45
TCEvent evt
Definition: DataStructs.cxx:8
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:306
Float_t e
Definition: plot.C:35
std::vector< art::Ptr< recob::Hit > > showerHits
Definition: TCShowerAlg.h:50
std::vector< double > dEdxErr
Definition: TCShowerAlg.h:48
Definition: fwd.h:26
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:109