LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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 
17 #include "fhiclcpp/ParameterSet.h"
19 
20 #include <vector>
21 #include <algorithm> // std::max()
22 #include <functional> // std::mem_fn()
23 #include <memory> // std::move
24 #include <utility> // std::pair<>, std::unique_ptr<>
25 #include <limits> // std::numeric_limits<>
26 
27 //LArSoft includes
29 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t
39 #include "lardata/ArtDataHelper/HitCreator.h" // recob::HitCollectionAssociator
47 
48 
49 namespace cluster {
50  class ClusterCrawler;
51 }
52 
54 
55 public:
56  explicit ClusterCrawler(fhicl::ParameterSet const & pset);
57  virtual ~ClusterCrawler();
58 
59  void reconfigure(fhicl::ParameterSet const & pset) ;
60  void produce(art::Event & evt) override;
61  void beginJob() override;
62 
63 private:
64  hit::CCHitFinderAlg fCCHFAlg; // define CCHitFinderAlg object
65  ClusterCrawlerAlg fCCAlg; // define ClusterCrawlerAlg object
66  std::string fCalDataModuleLabel;
67 };
68 
69 
70 namespace cluster {
71 
73  fCCHFAlg (pset.get<fhicl::ParameterSet>("CCHitFinderAlg")),
74  fCCAlg (pset.get<fhicl::ParameterSet>("ClusterCrawlerAlg")),
75  fCalDataModuleLabel(pset.get<std::string>("CalDataModuleLabel"))
76  {
77  mf::LogWarning("ClusterCrawler") <<
78  "\nClusterCrawler module has been deprecated and will be removed."
79  "\nIt is now replaced by HitFinder and LineCluster modules."
80  ;
81 
82  this->reconfigure(pset);
83 
84  // let HitCollectionAssociator declare that we are going to produce
85  // hits and associations with wires and raw digits
86  // (with no particular product label)
88 
89  produces< std::vector<recob::Cluster> >();
90  produces< std::vector<recob::Vertex> >();
91  produces< art::Assns<recob::Cluster, recob::Hit> >();
92  produces< art::Assns<recob::Cluster, recob::Vertex, unsigned short> >();
93  }
94 
96  {
97  }
98 
100  {
101  fCCAlg.reconfigure(pset.get< fhicl::ParameterSet >("ClusterCrawlerAlg"));
102  fCCHFAlg.reconfigure(pset.get< fhicl::ParameterSet >("CCHitFinderAlg"));
103  }
104 
106  }
107 
109  {
110  // fetch the wires needed by CCHitFinder
111 
112  // make this accessible to ClusterCrawler_module
114  = evt.getValidHandle<std::vector<recob::Wire>>(fCalDataModuleLabel);
115 
116  // find hits in all planes
117  fCCHFAlg.RunCCHitFinder(*wireVecHandle);
118 
119  // extract the result of the algorithm (it's moved)
120  std::vector<recob::Hit> FirstHits = fCCHFAlg.YieldHits();
121 
122  // look for clusters in all planes
123  fCCAlg.RunCrawler(FirstHits);
124 
125  std::unique_ptr<std::vector<recob::Hit>> FinalHits
126  (new std::vector<recob::Hit>(std::move(fCCAlg.YieldHits())));
127 
129 
130  // shcol contains the hit collection
131  // and its associations to wires and raw digits;
132  // we get the association to raw digits through wire associations
133  recob::HitCollectionAssociator shcol(*this, evt, fCalDataModuleLabel, true);
134  std::vector<recob::Cluster> sccol;
135  std::vector<recob::Vertex> sv3col;
136 
137  std::unique_ptr<art::Assns<recob::Cluster, recob::Hit> >
139  std::unique_ptr<art::Assns<recob::Cluster, recob::Vertex, unsigned short>>
141 
142 
143  std::vector<ClusterCrawlerAlg::ClusterStore> const& tcl = fCCAlg.GetClusters();
144 
145  std::vector<short> const& inClus = fCCAlg.GetinClus();
146 
147  // Consistency check
148  for(unsigned int icl = 0; icl < tcl.size(); ++icl) {
149  ClusterCrawlerAlg::ClusterStore const& clstr = tcl[icl];
150  if(clstr.ID < 0) continue;
152  unsigned short plane = planeID.Plane;
153  for(unsigned short ii = 0; ii < clstr.tclhits.size(); ++ii) {
154  unsigned int iht = clstr.tclhits[ii];
155  recob::Hit const& theHit = FinalHits->at(iht);
156  if(theHit.WireID().Plane != plane) {
157  std::cout<<"CC: cluster-hit plane mis-match "<<theHit.WireID().Plane<<" "<<plane
158  <<" in cluster "<<clstr.ID<<" WT "<<clstr.BeginWir<<":"<<(int)clstr.BeginTim<<"\n";
159  return;
160  }
161  if(inClus[iht] != clstr.ID) {
162  std::cout << "CC: InClus mis-match " << inClus[iht]
163  << " ID " << clstr.ID << " in cluster " << icl << "\n";
164  return;
165  }
166  } // ii
167  } // icl
168 
169  // make 3D vertices
170  std::vector<ClusterCrawlerAlg::Vtx3Store> const& Vertices
171  = fCCAlg.GetVertices();
172 
173  double xyz[3] = {0, 0, 0};
174  unsigned int vtxID = 0, end;
175  for(ClusterCrawlerAlg::Vtx3Store const& vtx3: Vertices) {
176  // ignore incomplete vertices
177  if(vtx3.Ptr2D[0] < 0) continue;
178  if(vtx3.Ptr2D[1] < 0) continue;
179  if(vtx3.Ptr2D[2] < 0) continue;
180  ++vtxID;
181  xyz[0] = vtx3.X;
182  xyz[1] = vtx3.Y;
183  xyz[2] = vtx3.Z;
184  sv3col.emplace_back(xyz, vtxID);
185  } // 3D vertices
186  // convert Vertex vector to unique_ptrs
187  std::unique_ptr<std::vector<recob::Vertex> > v3col(new std::vector<recob::Vertex>(std::move(sv3col)));
188 
189  // make the clusters and associations
190  float sumChg, sumADC;
191  unsigned int clsID = 0, nclhits;
192  for(unsigned int icl = 0; icl < tcl.size(); ++icl) {
193  ClusterCrawlerAlg::ClusterStore const& clstr = tcl[icl];
194  if(clstr.ID < 0) continue;
195  ++clsID;
196  sumChg = 0;
197  sumADC = 0;
199  unsigned short plane = planeID.Plane;
200  nclhits = clstr.tclhits.size();
201  std::vector<unsigned int> clsHitIndices;
202  // correct the hit indices to refer to the valid hits that were just added
203  for(unsigned int itt = 0; itt < nclhits; ++itt) {
204  unsigned int iht = clstr.tclhits[itt];
205  recob::Hit const& hit = FinalHits->at(iht);
206  sumChg += hit.Integral();
207  sumADC += hit.SummedADC();
208  } // itt
209  // get the wire, plane from a hit
210  unsigned int iht = clstr.tclhits[0];
211 
212  geo::View_t view = FinalHits->at(iht).View();
213  sccol.emplace_back(
214  (float)clstr.BeginWir, // Start wire
215  0, // sigma start wire
216  clstr.BeginTim, // start tick
217  0, // sigma start tick
218  clstr.BeginChg, // start charge
219  clstr.BeginAng, // start angle
220  0, // start opening angle (0 for line-like clusters)
221  (float)clstr.EndWir, // end wire
222  0, // sigma end wire
223  clstr.EndTim, // end tick
224  0, // sigma end tick
225  clstr.EndChg, // end charge
226  clstr.EndAng, // end angle
227  0, // end opening angle (0 for line-like clusters)
228  sumChg, // integral
229  0, // sigma integral
230  sumADC, // summed ADC
231  0, // sigma summed ADC
232  nclhits, // n hits
233  0, // wires over hits
234  0, // width (0 for line-like clusters)
235  clsID, // ID
236  view, // view
237  planeID, // plane
238  recob::Cluster::Sentry // sentry
239  );
240  // make the cluster - hit association
241  if(!util::CreateAssn(
242  *this, evt, *hc_assn, sccol.size()-1, clstr.tclhits.begin(), clstr.tclhits.end())
243  )
244  {
246  <<"Failed to associate hit "<<iht<<" with cluster "<<icl;
247  } // exception
248  // make the cluster - endpoint associations
249  if(clstr.BeginVtx >= 0) {
250  end = 0;
251  // See if this endpoint is associated with a 3D vertex
252  unsigned short vtxIndex = 0;
253  for(ClusterCrawlerAlg::Vtx3Store const& vtx3: Vertices) {
254  // ignore incomplete vertices
255  if(vtx3.Ptr2D[0] < 0) continue;
256  if(vtx3.Ptr2D[1] < 0) continue;
257  if(vtx3.Ptr2D[2] < 0) continue;
258  if(vtx3.Ptr2D[plane] == clstr.BeginVtx) {
259  if(!util::CreateAssnD(*this, evt, *cv_assn, clsID - 1, vtxIndex, end))
260  {
262  <<"Failed to associate cluster "<<icl<<" with vertex";
263  } // exception
264  break;
265  } // vertex match
266  ++vtxIndex;
267  } // 3D vertices
268  } // clstr.BeginVtx >= 0
269  if(clstr.EndVtx >= 0) {
270  end = 1;
271  // See if this endpoint is associated with a 3D vertex
272  unsigned short vtxIndex = 0;
273  for(ClusterCrawlerAlg::Vtx3Store const& vtx3: Vertices) {
274  // ignore incomplete vertices
275  if(vtx3.Ptr2D[0] < 0) continue;
276  if(vtx3.Ptr2D[1] < 0) continue;
277  if(vtx3.Ptr2D[2] < 0) continue;
278  if(vtx3.Ptr2D[plane] == clstr.EndVtx) {
279  if(!util::CreateAssnD(*this, evt, *cv_assn, clsID - 1, vtxIndex, end))
280  {
282  <<"Failed to associate cluster "<<icl<<" with endpoint";
283  } // exception
284  break;
285  } // vertex match
286  ++vtxIndex;
287  } // 3D vertices
288  } // clstr.BeginVtx >= 0
289  } // icl
290 
291  // convert cluster vector to unique_ptrs
292  std::unique_ptr<std::vector<recob::Cluster> > ccol(new std::vector<recob::Cluster>(std::move(sccol)));
293 
294  shcol.use_hits(std::move(FinalHits));
295 
296  // clean up
298 
299  // move the hit collection and the associations into the event:
300  shcol.put_into(evt);
301  evt.put(std::move(ccol));
302  evt.put(std::move(hc_assn));
303  evt.put(std::move(v3col));
304  evt.put(std::move(cv_assn));
305 
306  } // produce
307 } // namespace
308 
309 
310 namespace cluster{
311 
313 
314 }
315 
void RunCCHitFinder(std::vector< recob::Wire > const &Wires)
virtual void reconfigure(fhicl::ParameterSet const &pset)
Encapsulate the construction of a single cyostat.
virtual void reconfigure(fhicl::ParameterSet const &pset)
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
geo::WireID WireID() const
Initial tdc tick for hit.
Definition: Hit.h:234
Declaration of signal hit object.
hit::CCHitFinderAlg fCCHFAlg
Procedures to create maps of object locations.
The data type to uniquely identify a Plane.
Definition: geo_types.h:250
std::vector< ClusterStore > const & GetClusters() const
Returns a constant reference to the clusters found.
STL namespace.
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:225
void use_hits(std::unique_ptr< std::vector< recob::Hit >> &&srchits)
Uses the specified collection as data product.
Definition: HitCreator.cxx:306
Cluster finding and building.
static void declare_products(ModuleType &producer, std::string instance_name="", bool doWireAssns=true, bool doRawDigitAssns=true)
Declares the hit products we are going to fill.
Definition: HitCreator.h:1117
struct of temporary 3D vertices
Hit finder algorithm designed to work with Cluster Crawler.
static const SentryArgument_t Sentry
An instance of the sentry object.
Definition: Cluster.h:182
static geo::PlaneID DecodeCTP(CTP_t CTP)
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
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:42
parameter set interface
void RunCrawler(std::vector< recob::Hit > const &srchits)
bool CreateAssnD(PRODUCER const &prod, 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.
A class handling a collection of hits and its associations.
Definition: HitCreator.h:703
T get(std::string const &key) const
Definition: ParameterSet.h:231
void produce(art::Event &evt) override
Wrapper for ClusterParamsAlgBase objects to accept arbitrary input.
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.
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:258
Declaration of cluster object.
Definition of data types for geometry description.
Detector simulation of raw signals on wires.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::string fCalDataModuleLabel
label of module producing input wires
void reconfigure(fhicl::ParameterSet const &pset)
Utility object to perform functions of association.
Encapsulate the construction of a single detector plane.
std::vector< Vtx3Store > const & GetVertices() const
Returns a constant reference to the 3D vertices found.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
void put_into(art::Event &)
Moves the data into the event.
Definition: HitCreator.h:824
float SummedADC() const
The sum of calibrated ADC counts of the hit (0. by default)
Definition: Hit.h:224
Declaration of basic channel signal object.
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
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:49
Interface to class computing cluster parameters.
std::vector< recob::Hit > && YieldHits()
Returns (and loses) the collection of reconstructed hits.
TCEvent evt
Definition: DataStructs.cxx:5
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Namespace collecting geometry-related classes utilities.
art framework interface to geometry description
Encapsulate the construction of a single detector plane.