LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
LineCluster_module.cc
Go to the documentation of this file.
1 
11 // C/C++ standard libraries
12 #include <string>
13 #include <utility> // std::unique_ptr<>
14 
15 // Framework libraries
16 #include "fhiclcpp/ParameterSet.h"
21 
22 //LArSoft includes
25 
26 // ... more includes in the implementation section
27 
28 namespace cluster {
41  class LineCluster: public art::EDProducer {
42 
43  public:
44  explicit LineCluster(fhicl::ParameterSet const & pset);
45  virtual ~LineCluster() = default;
46 
47  void reconfigure(fhicl::ParameterSet const & pset) ;
48  void produce(art::Event & evt) override;
49 
50  private:
51  std::unique_ptr<ClusterCrawlerAlg> fCCAlg; // define ClusterCrawlerAlg object
52 
54 
57 
58  }; // class LineCluster
59 
60 } // namespace cluster
61 
62 //******************************************************************************
63 //*** implementation
64 //***
65 
66 // C/C++ standard libraries
67 #include <vector>
68 #include <memory> // std::move()
69 
70 // Framework libraries
74 
75 //LArSoft includes
82 #include "lardata/ArtDataHelper/HitCreator.h" // recob::HitCollectionAssociator
85 
86 
87 namespace cluster {
88 
89  //----------------------------------------------------------------------------
91  reconfigure(pset);
92 
93  // let HitCollectionAssociator declare that we are going to produce
94  // hits and associations with wires and raw digits
95  // (with no particular product label)
97 
98  produces< std::vector<recob::Cluster> >();
99  produces< std::vector<recob::Vertex> >();
100  produces< std::vector<recob::EndPoint2D> >();
101  produces< art::Assns<recob::Cluster, recob::Hit> >();
102  produces< art::Assns<recob::Cluster, recob::Vertex, unsigned short> >();
103  produces< art::Assns<recob::Cluster, recob::EndPoint2D, unsigned short> >();
104  } // LineCluster::LineCluster()
105 
106 
107  //----------------------------------------------------------------------------
109  {
110  fHitFinderLabel = pset.get<art::InputTag>("HitFinderModuleLabel");
111  fDoWireAssns = pset.get<bool>("DoWireAssns",true);
112  fDoRawDigitAssns = pset.get<bool>("DoRawDigitAssns",false);
113 
114  // this trick avoids double configuration on construction
115  if (fCCAlg)
116  fCCAlg->reconfigure(pset.get< fhicl::ParameterSet >("ClusterCrawlerAlg"));
117  else {
118  fCCAlg.reset(new ClusterCrawlerAlg
119  (pset.get< fhicl::ParameterSet >("ClusterCrawlerAlg")));
120  }
121  } // LineCluster::reconfigure()
122 
123  //----------------------------------------------------------------------------
125  {
126  // fetch the wires needed by CCHitFinder
127 
128  // make this accessible to ClusterCrawler_module
130  = evt.getValidHandle<std::vector<recob::Hit>>(fHitFinderLabel);
131 
132  // look for clusters in all planes
133  fCCAlg->RunCrawler(*hitVecHandle);
134 
135  std::unique_ptr<std::vector<recob::Hit>> FinalHits
136  (new std::vector<recob::Hit>(std::move(fCCAlg->YieldHits())));
137 
138  // shcol contains the hit collection
139  // and its associations to wires and raw digits;
140  // we get the association to raw digits through wire associations
142  std::vector<recob::Cluster> sccol;
143  std::vector<recob::Vertex> sv3col;
144  std::vector<recob::EndPoint2D> sv2col;
145 
146  std::unique_ptr<art::Assns<recob::Cluster, recob::Hit> >
148  std::unique_ptr<art::Assns<recob::Cluster, recob::Vertex, unsigned short>>
150  std::unique_ptr<art::Assns<recob::Cluster, recob::EndPoint2D, unsigned short>>
152 
153  std::vector<ClusterCrawlerAlg::ClusterStore> const& Clusters = fCCAlg->GetClusters();
154 
155 
156 // Consistency check
157 /*
158  std::vector<short> const& inClus = fCCAlg->GetinClus();
159  for(unsigned int icl = 0; icl < Clusters.size(); ++icl) {
160  ClusterCrawlerAlg::ClusterStore const& clstr = Clusters[icl];
161  if(clstr.ID < 0) continue;
162  geo::PlaneID planeID = ClusterCrawlerAlg::DecodeCTP(clstr.CTP);
163  unsigned short plane = planeID.Plane;
164  for(unsigned short ii = 0; ii < clstr.tclhits.size(); ++ii) {
165  unsigned int iht = clstr.tclhits[ii];
166  recob::Hit const& theHit = FinalHits->at(iht);
167  if(theHit.WireID().Plane != plane) {
168  mf::LogError("LineCluster")<<"Cluster-hit plane mis-match "<<theHit.WireID().Plane<<" "<<plane
169  <<" in cluster "<<clstr.ID<<" WT "<<clstr.BeginWir<<":"<<(int)clstr.BeginTim<<" cluster CTP "<<clstr.CTP;
170  return;
171  }
172  if(inClus[iht] != clstr.ID) {
173  mf::LogError("LineCluster") << "InClus mis-match " << inClus[iht]
174  << " ID " << clstr.ID << " in cluster ID " << clstr.ID<<" cluster ProcCode "<<clstr.ProcCode;;
175  return;
176  }
177  } // ii
178  } // icl
179 */
180  // make EndPoints (aka 2D vertices)
181  std::vector<ClusterCrawlerAlg::VtxStore> const& EndPts = fCCAlg->GetEndPoints();
182  std::vector<unsigned int> indxToIndx(EndPts.size());
184  unsigned short vtxID = 0, end, wire, ivx;
185  for(ivx = 0; ivx < EndPts.size(); ++ivx) {
186  if(EndPts[ivx].NClusters == 0) continue;
187  indxToIndx[ivx] = vtxID;
188  ++vtxID;
189 // std::cout<<"EndPt "<<ivx<<" vtxID "<<vtxID<<"\n";
190  wire = (0.5 + EndPts[ivx].Wire);
191  geo::PlaneID plID = ClusterCrawlerAlg::DecodeCTP(EndPts[ivx].CTP);
192  geo::WireID wID = geo::WireID(plID.Cryostat, plID.TPC, plID.Plane, wire);
193  geo::View_t view = geom->View(wID);
194  sv2col.emplace_back((double)EndPts[ivx].Time, // Time
195  wID, // WireID
196  0, // strength - not relevant
197  vtxID, // ID
198  view, // View
199  0); // total charge - not relevant
200  } // iv
201  // convert 2D Vertex vector to unique_ptrs
202  std::unique_ptr<std::vector<recob::EndPoint2D> > v2col(new std::vector<recob::EndPoint2D>(std::move(sv2col)));
203 
204  // make 3D vertices
205  std::vector<ClusterCrawlerAlg::Vtx3Store> const& Vertices = fCCAlg->GetVertices();
206  double xyz[3] = {0, 0, 0};
207  vtxID = 0;
208  for(ClusterCrawlerAlg::Vtx3Store const& vtx3: Vertices) {
209  // ignore incomplete vertices
210  if(vtx3.Ptr2D[0] < 0) continue;
211  if(vtx3.Ptr2D[1] < 0) continue;
212  if(vtx3.Ptr2D[2] < 0) continue;
213  ++vtxID;
214  xyz[0] = vtx3.X;
215  xyz[1] = vtx3.Y;
216  xyz[2] = vtx3.Z;
217  sv3col.emplace_back(xyz, vtxID);
218  } // 3D vertices
219  // convert Vertex vector to unique_ptrs
220  std::unique_ptr<std::vector<recob::Vertex> > v3col(new std::vector<recob::Vertex>(std::move(sv3col)));
221 
222  // make the clusters and associations
223  float sumChg, sumADC;
224  unsigned int clsID = 0, nclhits;
225  for(unsigned int icl = 0; icl < Clusters.size(); ++icl) {
226  ClusterCrawlerAlg::ClusterStore const& clstr = Clusters[icl];
227  if(clstr.ID < 0) continue;
228  ++clsID;
229  sumChg = 0;
230  sumADC = 0;
232  unsigned short plane = planeID.Plane;
233  nclhits = clstr.tclhits.size();
234  std::vector<unsigned int> clsHitIndices;
235  // correct the hit indices to refer to the valid hits that were just added
236  for(unsigned int itt = 0; itt < nclhits; ++itt) {
237  unsigned int iht = clstr.tclhits[itt];
238  recob::Hit const& hit = FinalHits->at(iht);
239  sumChg += hit.Integral();
240  sumADC += hit.SummedADC();
241  } // itt
242  // get the wire, plane from a hit
243  unsigned int iht = clstr.tclhits[0];
244 
245  geo::View_t view = FinalHits->at(iht).View();
246  sccol.emplace_back(
247  (float)clstr.BeginWir, // Start wire
248  0, // sigma start wire
249  clstr.BeginTim, // start tick
250  0, // sigma start tick
251  clstr.BeginChg, // start charge
252  clstr.BeginAng, // start angle
253  0, // start opening angle (0 for line-like clusters)
254  (float)clstr.EndWir, // end wire
255  0, // sigma end wire
256  clstr.EndTim, // end tick
257  0, // sigma end tick
258  clstr.EndChg, // end charge
259  clstr.EndAng, // end angle
260  0, // end opening angle (0 for line-like clusters)
261  sumChg, // integral
262  0, // sigma integral
263  sumADC, // summed ADC
264  0, // sigma summed ADC
265  nclhits, // n hits
266  0, // wires over hits
267  0, // width (0 for line-like clusters)
268  clsID, // ID
269  view, // view
270  planeID, // plane
271  recob::Cluster::Sentry // sentry
272  );
273  // make the cluster - hit association
274  if(!util::CreateAssn(
275  *this, evt, *hc_assn, sccol.size()-1, clstr.tclhits.begin(), clstr.tclhits.end())
276  )
277  {
279  <<"Failed to associate hit "<<iht<<" with cluster "<<icl;
280  } // exception
281  // make the cluster - EndPoint2D and Vertex associations
282  if(clstr.BeginVtx >= 0) {
283  end = 0;
284 // std::cout<<clstr.ID<<" clsID "<<clsID<<" Begin vtx "<<clstr.BeginVtx<<" vtxID "<<indxToIndx[clstr.BeginVtx]<<"\n";
285  if(!util::CreateAssnD(*this, evt, *cep_assn, clsID - 1, indxToIndx[clstr.BeginVtx], end))
286  {
287  throw art::Exception(art::errors::ProductRegistrationFailure)<<"Failed to associate cluster "<<clsID<<" with EndPoint2D "<<clstr.BeginVtx;
288  } // exception
289  // See if this endpoint is associated with a 3D vertex
290  unsigned short vtxIndex = 0;
291  for(ClusterCrawlerAlg::Vtx3Store const& vtx3: Vertices) {
292  // ignore incomplete vertices
293  if(vtx3.Ptr2D[0] < 0) continue;
294  if(vtx3.Ptr2D[1] < 0) continue;
295  if(vtx3.Ptr2D[2] < 0) continue;
296  if(vtx3.Ptr2D[plane] == clstr.BeginVtx) {
297  if(!util::CreateAssnD(*this, evt, *cv_assn, clsID - 1, vtxIndex, end))
298  {
300  <<"Failed to associate cluster "<<icl<<" with vertex";
301  } // exception
302  break;
303  } // vertex match
304  ++vtxIndex;
305  } // 3D vertices
306  } // clstr.BeginVtx >= 0
307  if(clstr.EndVtx >= 0) {
308  end = 1;
309 // std::cout<<clstr.ID<<" clsID "<<clsID<<" End vtx "<<clstr.EndVtx<<" vtxID "<<indxToIndx[clstr.EndVtx]<<"\n";
310  if(!util::CreateAssnD(*this, evt, *cep_assn, clsID - 1, indxToIndx[clstr.EndVtx], end))
311  {
312  throw art::Exception(art::errors::ProductRegistrationFailure)<<"Failed to associate cluster "<<clsID<<" with EndPoint2D "<<clstr.BeginVtx;
313  } // exception
314  // See if this endpoint is associated with a 3D vertex
315  unsigned short vtxIndex = 0;
316  for(ClusterCrawlerAlg::Vtx3Store const& vtx3: Vertices) {
317  // ignore incomplete vertices
318  if(vtx3.Ptr2D[0] < 0) continue;
319  if(vtx3.Ptr2D[1] < 0) continue;
320  if(vtx3.Ptr2D[2] < 0) continue;
321  if(vtx3.Ptr2D[plane] == clstr.EndVtx) {
322  if(!util::CreateAssnD(*this, evt, *cv_assn, clsID - 1, vtxIndex, end))
323  {
325  <<"Failed to associate cluster "<<icl<<" with endpoint";
326  } // exception
327  break;
328  } // vertex match
329  ++vtxIndex;
330  } // 3D vertices
331  } // clstr.BeginVtx >= 0
332  } // icl
333 
334  // convert cluster vector to unique_ptrs
335  std::unique_ptr<std::vector<recob::Cluster> > ccol(new std::vector<recob::Cluster>(std::move(sccol)));
336 
337  shcol.use_hits(std::move(FinalHits));
338 
339  // clean up
340  fCCAlg->ClearResults();
341 
342  // move the hit collection and the associations into the event:
343  shcol.put_into(evt);
344  evt.put(std::move(ccol));
345  evt.put(std::move(hc_assn));
346  evt.put(std::move(v2col));
347  evt.put(std::move(v3col));
348  evt.put(std::move(cv_assn));
349  evt.put(std::move(cep_assn));
350 
351  } // LineCluster::produce()
352 
353 
354 
355  //----------------------------------------------------------------------------
357 
358 } // namespace cluster
359 
void reconfigure(fhicl::ParameterSet const &pset)
void produce(art::Event &evt) override
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Declaration of signal hit object.
The data type to uniquely identify a Plane.
Definition: geo_types.h:250
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:130
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
Definition: Hit.h:225
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
virtual ~LineCluster()=default
static const SentryArgument_t Sentry
An instance of the sentry object.
Definition: Cluster.h:182
static geo::PlaneID DecodeCTP(CTP_t CTP)
std::unique_ptr< ClusterCrawlerAlg > fCCAlg
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
Helper functions to create a hit.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
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.
T get(std::string const &key) const
Definition: ParameterSet.h:231
art::InputTag fHitFinderLabel
label of module producing input hits
A class handling a collection of hits and its associations.
Definition: HitCreator.h:865
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.
Produces clusters by ClusterCrawler algorithm.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
Utility object to perform functions of association.
float SummedADC() const
The sum of calibrated ADC counts of the hit (0. by default)
Definition: Hit.h:224
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
LineCluster(fhicl::ParameterSet const &pset)
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:49
Interface to class computing cluster parameters.
TCEvent evt
Definition: DataStructs.cxx:5
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:203