LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ClusterCrawler_module.cc
Go to the documentation of this file.
1 // Class: ClusterCrawler
3 // Module Type: producer
4 // File: ClusterCrawler_module.cc
5 //
6 // Generated at Fri Jun 7 09:44:09 2013 by Bruce Baller using artmod
7 // from cetpkgsupport v1_02_00.
9 
16 #include "fhiclcpp/ParameterSet.h"
17 
18 #include <memory>
19 
20 //LArSoft includes
23 #include "lardata/ArtDataHelper/HitCreator.h" // recob::HitCollectionAssociator
34 
35 namespace cluster {
36  class ClusterCrawler;
37 }
38 
40 
41 public:
42  explicit ClusterCrawler(fhicl::ParameterSet const& pset);
43 
44 private:
45  void produce(art::Event& evt) override;
46 
47  hit::CCHitFinderAlg fCCHFAlg; // define CCHitFinderAlg object
48  ClusterCrawlerAlg fCCAlg; // define ClusterCrawlerAlg object
49  std::string fCalDataModuleLabel;
50 };
51 
52 namespace cluster {
53 
55  : EDProducer{pset}
56  , fCCHFAlg(pset.get<fhicl::ParameterSet>("CCHitFinderAlg"))
57  , fCCAlg(pset.get<fhicl::ParameterSet>("ClusterCrawlerAlg"))
58  , fCalDataModuleLabel(pset.get<std::string>("CalDataModuleLabel"))
59  {
60  mf::LogWarning("ClusterCrawler")
61  << "\nClusterCrawler module has been deprecated and will be removed."
62  "\nIt is now replaced by HitFinder and LineCluster modules.";
63 
64  // let HitCollectionAssociator declare that we are going to produce
65  // hits and associations with wires and raw digits
66  // (with no particular product label)
68 
69  produces<std::vector<recob::Cluster>>();
70  produces<std::vector<recob::Vertex>>();
71  produces<art::Assns<recob::Cluster, recob::Hit>>();
72  produces<art::Assns<recob::Cluster, recob::Vertex, unsigned short>>();
73  }
74 
76  {
77  // fetch the wires needed by CCHitFinder
78 
79  // make this accessible to ClusterCrawler_module
81  evt.getValidHandle<std::vector<recob::Wire>>(fCalDataModuleLabel);
82 
83  // find hits in all planes
84  fCCHFAlg.RunCCHitFinder(*wireVecHandle);
85 
86  // extract the result of the algorithm (it's moved)
87  std::vector<recob::Hit> FirstHits = fCCHFAlg.YieldHits();
88 
89  auto const clock_data =
91  auto const det_prop =
93 
94  // look for clusters in all planes
95  fCCAlg.RunCrawler(clock_data, det_prop, FirstHits);
96 
97  auto FinalHits = std::make_unique<std::vector<recob::Hit>>(fCCAlg.YieldHits());
98 
100 
101  // shcol contains the hit collection
102  // and its associations to wires and raw digits;
103  // we get the association to raw digits through wire associations
105  std::vector<recob::Cluster> sccol;
106  std::vector<recob::Vertex> sv3col;
107 
108  auto hc_assn = std::make_unique<art::Assns<recob::Cluster, recob::Hit>>();
109  auto cv_assn = std::make_unique<art::Assns<recob::Cluster, recob::Vertex, unsigned short>>();
110 
111  std::vector<ClusterCrawlerAlg::ClusterStore> const& tcl = fCCAlg.GetClusters();
112 
113  std::vector<short> const& inClus = fCCAlg.GetinClus();
114 
115  // Consistency check
116  for (unsigned int icl = 0; icl < tcl.size(); ++icl) {
117  ClusterCrawlerAlg::ClusterStore const& clstr = tcl[icl];
118  if (clstr.ID < 0) continue;
120  unsigned short plane = planeID.Plane;
121  for (unsigned short ii = 0; ii < clstr.tclhits.size(); ++ii) {
122  unsigned int iht = clstr.tclhits[ii];
123  recob::Hit const& theHit = FinalHits->at(iht);
124  if (theHit.WireID().Plane != plane) {
125  std::cout << "CC: cluster-hit plane mis-match " << theHit.WireID().Plane << " " << plane
126  << " in cluster " << clstr.ID << " WT " << clstr.BeginWir << ":"
127  << (int)clstr.BeginTim << "\n";
128  return;
129  }
130  if (inClus[iht] != clstr.ID) {
131  std::cout << "CC: InClus mis-match " << inClus[iht] << " ID " << clstr.ID
132  << " in cluster " << icl << "\n";
133  return;
134  }
135  } // ii
136  } // icl
137 
138  // make 3D vertices
139  std::vector<ClusterCrawlerAlg::Vtx3Store> const& Vertices = fCCAlg.GetVertices();
140 
141  double xyz[3] = {0, 0, 0};
142  unsigned int vtxID = 0, end;
143  for (ClusterCrawlerAlg::Vtx3Store const& vtx3 : Vertices) {
144  // ignore incomplete vertices
145  if (vtx3.Ptr2D[0] < 0) continue;
146  if (vtx3.Ptr2D[1] < 0) continue;
147  if (vtx3.Ptr2D[2] < 0) continue;
148  ++vtxID;
149  xyz[0] = vtx3.X;
150  xyz[1] = vtx3.Y;
151  xyz[2] = vtx3.Z;
152  sv3col.emplace_back(xyz, vtxID);
153  } // 3D vertices
154  // convert Vertex vector to unique_ptrs
155  std::unique_ptr<std::vector<recob::Vertex>> v3col(
156  new std::vector<recob::Vertex>(std::move(sv3col)));
157 
158  // make the clusters and associations
159  float sumChg, sumADC;
160  unsigned int clsID = 0, nclhits;
161  for (unsigned int icl = 0; icl < tcl.size(); ++icl) {
162  ClusterCrawlerAlg::ClusterStore const& clstr = tcl[icl];
163  if (clstr.ID < 0) continue;
164  ++clsID;
165  sumChg = 0;
166  sumADC = 0;
168  unsigned short plane = planeID.Plane;
169  nclhits = clstr.tclhits.size();
170  std::vector<unsigned int> clsHitIndices;
171  // correct the hit indices to refer to the valid hits that were just added
172  for (unsigned int itt = 0; itt < nclhits; ++itt) {
173  unsigned int iht = clstr.tclhits[itt];
174  recob::Hit const& hit = FinalHits->at(iht);
175  sumChg += hit.Integral();
176  sumADC += hit.SummedADC();
177  } // itt
178  // get the wire, plane from a hit
179  unsigned int iht = clstr.tclhits[0];
180 
181  geo::View_t view = FinalHits->at(iht).View();
182  sccol.emplace_back((float)clstr.BeginWir, // Start wire
183  0, // sigma start wire
184  clstr.BeginTim, // start tick
185  0, // sigma start tick
186  clstr.BeginChg, // start charge
187  clstr.BeginAng, // start angle
188  0, // start opening angle (0 for line-like clusters)
189  (float)clstr.EndWir, // end wire
190  0, // sigma end wire
191  clstr.EndTim, // end tick
192  0, // sigma end tick
193  clstr.EndChg, // end charge
194  clstr.EndAng, // end angle
195  0, // end opening angle (0 for line-like clusters)
196  sumChg, // integral
197  0, // sigma integral
198  sumADC, // summed ADC
199  0, // sigma summed ADC
200  nclhits, // n hits
201  0, // wires over hits
202  0, // width (0 for line-like clusters)
203  clsID, // ID
204  view, // view
205  planeID, // plane
206  recob::Cluster::Sentry // sentry
207  );
208  // make the cluster - hit association
209  if (!util::CreateAssn(
210  evt, *hc_assn, sccol.size() - 1, clstr.tclhits.begin(), clstr.tclhits.end())) {
212  << "Failed to associate hit " << iht << " with cluster " << icl;
213  } // exception
214  // make the cluster - endpoint associations
215  if (clstr.BeginVtx >= 0) {
216  end = 0;
217  // See if this endpoint is associated with a 3D vertex
218  unsigned short vtxIndex = 0;
219  for (ClusterCrawlerAlg::Vtx3Store const& vtx3 : Vertices) {
220  // ignore incomplete vertices
221  if (vtx3.Ptr2D[0] < 0) continue;
222  if (vtx3.Ptr2D[1] < 0) continue;
223  if (vtx3.Ptr2D[2] < 0) continue;
224  if (vtx3.Ptr2D[plane] == clstr.BeginVtx) {
225  if (!util::CreateAssnD(evt, *cv_assn, clsID - 1, vtxIndex, end)) {
227  << "Failed to associate cluster " << icl << " with vertex";
228  } // exception
229  break;
230  } // vertex match
231  ++vtxIndex;
232  } // 3D vertices
233  } // clstr.BeginVtx >= 0
234  if (clstr.EndVtx >= 0) {
235  end = 1;
236  // See if this endpoint is associated with a 3D vertex
237  unsigned short vtxIndex = 0;
238  for (ClusterCrawlerAlg::Vtx3Store const& vtx3 : Vertices) {
239  // ignore incomplete vertices
240  if (vtx3.Ptr2D[0] < 0) continue;
241  if (vtx3.Ptr2D[1] < 0) continue;
242  if (vtx3.Ptr2D[2] < 0) continue;
243  if (vtx3.Ptr2D[plane] == clstr.EndVtx) {
244  if (!util::CreateAssnD(evt, *cv_assn, clsID - 1, vtxIndex, end)) {
246  << "Failed to associate cluster " << icl << " with endpoint";
247  } // exception
248  break;
249  } // vertex match
250  ++vtxIndex;
251  } // 3D vertices
252  } // clstr.BeginVtx >= 0
253  } // icl
254 
255  // convert cluster vector to unique_ptrs
256  std::unique_ptr<std::vector<recob::Cluster>> ccol(
257  new std::vector<recob::Cluster>(std::move(sccol)));
258 
259  shcol.use_hits(std::move(FinalHits));
260 
261  // clean up
263 
264  // move the hit collection and the associations into the event:
265  shcol.put_into(evt);
266  evt.put(std::move(ccol));
267  evt.put(std::move(hc_assn));
268  evt.put(std::move(v3col));
269  evt.put(std::move(cv_assn));
270 
271  } // produce
272 } // namespace
273 
274 namespace cluster {
275 
277 
278 }
void RunCCHitFinder(std::vector< recob::Wire > const &Wires)
bool CreateAssnD(art::Event &evt, art::Assns< T, U, D > &assn, size_t first_index, size_t second_index, typename art::Assns< T, U, D >::data_t &&data)
Creates a single one-to-one association with associated data.
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Declaration of signal hit object.
hit::CCHitFinderAlg fCCHFAlg
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
The data type to uniquely identify a Plane.
Definition: geo_types.h:463
std::vector< ClusterStore > const & GetClusters() const
Returns a constant reference to the clusters found.
Definition of basic raw digits.
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
Definition: Hit.h:244
geo::WireID const & WireID() const
Initial tdc tick for hit.
Definition: Hit.h:280
void use_hits(std::unique_ptr< std::vector< recob::Hit >> &&srchits)
Uses the specified collection as data product.
Definition: HitCreator.cxx:376
Cluster finding and building.
struct of temporary 3D vertices
static void declare_products(art::ProducesCollector &collector, std::string instance_name="", bool doWireAssns=true, bool doRawDigitAssns=true)
Declares the hit products we are going to fill.
Definition: HitCreator.cxx:248
Hit finder algorithm designed to work with Cluster Crawler.
static const SentryArgument_t Sentry
An instance of the sentry object.
Definition: Cluster.h:174
static geo::PlaneID DecodeCTP(CTP_t CTP)
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
ClusterCrawler(fhicl::ParameterSet const &pset)
Helper functions to create a hit.
std::vector< recob::Hit > && YieldHits()
Returns (and loses) the collection of reconstructed hits.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
A class handling a collection of hits and its associations.
Definition: HitCreator.h:650
void produce(art::Event &evt) override
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:481
Declaration of cluster object.
Definition of data types for geometry description.
Detector simulation of raw signals on wires.
ProducesCollector & producesCollector() noexcept
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.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::string fCalDataModuleLabel
label of module producing input wires
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Utility object to perform functions of association.
std::vector< Vtx3Store > const & GetVertices() const
Returns a constant reference to the 3D vertices found.
void RunCrawler(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, std::vector< recob::Hit > const &srchits)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
void put_into(art::Event &)
Moves the data into the event.
Definition: HitCreator.h:748
float SummedADC() const
The sum of calibrated ADC counts of the hit (0. by default)
Definition: Hit.h:240
Declaration of basic channel signal object.
std::vector< short > const & GetinClus() const
Returns (and loses) the collection of reconstructed hits.
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:46
std::vector< recob::Hit > && YieldHits()
Returns (and loses) the collection of reconstructed hits.
TCEvent evt
Definition: DataStructs.cxx:8
Namespace collecting geometry-related classes utilities.
art framework interface to geometry description