LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
LineCluster_module.cc
Go to the documentation of this file.
1 
10 // Framework libraries
15 #include "fhiclcpp/ParameterSet.h"
16 
17 // LArSoft includes
21 
22 // ... more includes in the implementation section
23 
24 namespace cluster {
37  class LineCluster : public art::EDProducer {
38 
39  public:
40  explicit LineCluster(fhicl::ParameterSet const& pset);
41 
42  private:
43  void produce(art::Event& evt) override;
44 
45  ClusterCrawlerAlg fCCAlg; // define ClusterCrawlerAlg object
46 
48 
51 
52  }; // class LineCluster
53 
54 } // namespace cluster
55 
56 //******************************************************************************
57 //*** implementation
58 //***
59 
60 // C/C++ standard libraries
61 #include <memory> // std::move()
62 
63 // Framework libraries
67 
68 //LArSoft includes
70 #include "lardata/ArtDataHelper/HitCreator.h" // recob::HitCollectionAssociator
76 
77 namespace cluster {
78 
79  //----------------------------------------------------------------------------
81  : EDProducer{pset}, fCCAlg{pset.get<fhicl::ParameterSet>("ClusterCrawlerAlg")}
82  {
83  fHitFinderLabel = pset.get<art::InputTag>("HitFinderModuleLabel");
84  fDoWireAssns = pset.get<bool>("DoWireAssns", true);
85  fDoRawDigitAssns = pset.get<bool>("DoRawDigitAssns", false);
86 
87  // let HitCollectionAssociator declare that we are going to produce
88  // hits and associations with wires and raw digits
89  // (with no particular product label)
91  producesCollector(), "", fDoWireAssns, fDoRawDigitAssns);
92 
93  produces<std::vector<recob::Cluster>>();
94  produces<std::vector<recob::Vertex>>();
95  produces<std::vector<recob::EndPoint2D>>();
96  produces<art::Assns<recob::Cluster, recob::Hit>>();
97  produces<art::Assns<recob::Cluster, recob::Vertex, unsigned short>>();
98  produces<art::Assns<recob::Cluster, recob::EndPoint2D, unsigned short>>();
99  } // LineCluster::LineCluster()
100 
101  //----------------------------------------------------------------------------
103  {
104  // fetch the wires needed by CCHitFinder
105 
106  // make this accessible to ClusterCrawler_module
107  auto hitVecHandle = evt.getValidHandle<std::vector<recob::Hit>>(fHitFinderLabel);
108 
109  // look for clusters in all planes
110  auto const clock_data =
112  auto const det_prop =
114  fCCAlg.RunCrawler(clock_data, det_prop, *hitVecHandle);
115 
116  auto FinalHits = std::make_unique<std::vector<recob::Hit>>(std::move(fCCAlg.YieldHits()));
117 
118  // shcol contains the hit collection
119  // and its associations to wires and raw digits;
120  // we get the association to raw digits through wire associations
122  std::vector<recob::Cluster> sccol;
123  std::vector<recob::Vertex> sv3col;
124  std::vector<recob::EndPoint2D> sv2col;
125 
126  std::unique_ptr<art::Assns<recob::Cluster, recob::Hit>> hc_assn(
128  std::unique_ptr<art::Assns<recob::Cluster, recob::Vertex, unsigned short>> cv_assn(
130  std::unique_ptr<art::Assns<recob::Cluster, recob::EndPoint2D, unsigned short>> cep_assn(
132 
133  std::vector<ClusterCrawlerAlg::ClusterStore> const& Clusters = fCCAlg.GetClusters();
134 
135  // Consistency check
136  /*
137  std::vector<short> const& inClus = fCCAlg.GetinClus();
138  for(unsigned int icl = 0; icl < Clusters.size(); ++icl) {
139  ClusterCrawlerAlg::ClusterStore const& clstr = Clusters[icl];
140  if(clstr.ID < 0) continue;
141  geo::PlaneID planeID = ClusterCrawlerAlg::DecodeCTP(clstr.CTP);
142  unsigned short plane = planeID.Plane;
143  for(unsigned short ii = 0; ii < clstr.tclhits.size(); ++ii) {
144  unsigned int iht = clstr.tclhits[ii];
145  recob::Hit const& theHit = FinalHits->at(iht);
146  if(theHit.WireID().Plane != plane) {
147  mf::LogError("LineCluster")<<"Cluster-hit plane mis-match "<<theHit.WireID().Plane<<" "<<plane
148  <<" in cluster "<<clstr.ID<<" WT "<<clstr.BeginWir<<":"<<(int)clstr.BeginTim<<" cluster CTP "<<clstr.CTP;
149  return;
150  }
151  if(inClus[iht] != clstr.ID) {
152  mf::LogError("LineCluster") << "InClus mis-match " << inClus[iht]
153  << " ID " << clstr.ID << " in cluster ID " << clstr.ID<<" cluster ProcCode "<<clstr.ProcCode;;
154  return;
155  }
156  } // ii
157  } // icl
158 */
159  // make EndPoints (aka 2D vertices)
160  std::vector<ClusterCrawlerAlg::VtxStore> const& EndPts = fCCAlg.GetEndPoints();
161  std::vector<unsigned int> indxToIndx(EndPts.size());
163  unsigned short vtxID = 0, end, wire, ivx;
164  for (ivx = 0; ivx < EndPts.size(); ++ivx) {
165  if (EndPts[ivx].NClusters == 0) continue;
166  indxToIndx[ivx] = vtxID;
167  ++vtxID;
168  // std::cout<<"EndPt "<<ivx<<" vtxID "<<vtxID<<"\n";
169  wire = (0.5 + EndPts[ivx].Wire);
170  geo::PlaneID plID = ClusterCrawlerAlg::DecodeCTP(EndPts[ivx].CTP);
171  geo::WireID wID = geo::WireID(plID.Cryostat, plID.TPC, plID.Plane, wire);
172  geo::View_t view = geom->View(wID);
173  sv2col.emplace_back((double)EndPts[ivx].Time, // Time
174  wID, // WireID
175  0, // strength - not relevant
176  vtxID, // ID
177  view, // View
178  0); // total charge - not relevant
179  } // iv
180  // convert 2D Vertex vector to unique_ptrs
181  std::unique_ptr<std::vector<recob::EndPoint2D>> v2col(
182  new std::vector<recob::EndPoint2D>(std::move(sv2col)));
183 
184  // make 3D vertices
185  std::vector<ClusterCrawlerAlg::Vtx3Store> const& Vertices = fCCAlg.GetVertices();
186  double xyz[3] = {0, 0, 0};
187  vtxID = 0;
188  for (ClusterCrawlerAlg::Vtx3Store const& vtx3 : Vertices) {
189  // ignore incomplete vertices
190  if (vtx3.Ptr2D[0] < 0) continue;
191  if (vtx3.Ptr2D[1] < 0) continue;
192  if (vtx3.Ptr2D[2] < 0) continue;
193  ++vtxID;
194  xyz[0] = vtx3.X;
195  xyz[1] = vtx3.Y;
196  xyz[2] = vtx3.Z;
197  sv3col.emplace_back(xyz, vtxID);
198  } // 3D vertices
199  // convert Vertex vector to unique_ptrs
200  std::unique_ptr<std::vector<recob::Vertex>> v3col(
201  new std::vector<recob::Vertex>(std::move(sv3col)));
202 
203  // make the clusters and associations
204  float sumChg, sumADC;
205  unsigned int clsID = 0, nclhits;
206  for (unsigned int icl = 0; icl < Clusters.size(); ++icl) {
207  ClusterCrawlerAlg::ClusterStore const& clstr = Clusters[icl];
208  if (clstr.ID < 0) continue;
209  ++clsID;
210  sumChg = 0;
211  sumADC = 0;
213  unsigned short plane = planeID.Plane;
214  nclhits = clstr.tclhits.size();
215  std::vector<unsigned int> clsHitIndices;
216  // correct the hit indices to refer to the valid hits that were just added
217  for (unsigned int itt = 0; itt < nclhits; ++itt) {
218  unsigned int iht = clstr.tclhits[itt];
219  recob::Hit const& hit = FinalHits->at(iht);
220  sumChg += hit.Integral();
221  sumADC += hit.SummedADC();
222  } // itt
223  // get the wire, plane from a hit
224  unsigned int iht = clstr.tclhits[0];
225 
226  geo::View_t view = FinalHits->at(iht).View();
227  sccol.emplace_back((float)clstr.BeginWir, // Start wire
228  0, // sigma start wire
229  clstr.BeginTim, // start tick
230  0, // sigma start tick
231  clstr.BeginChg, // start charge
232  clstr.BeginAng, // start angle
233  0, // start opening angle (0 for line-like clusters)
234  (float)clstr.EndWir, // end wire
235  0, // sigma end wire
236  clstr.EndTim, // end tick
237  0, // sigma end tick
238  clstr.EndChg, // end charge
239  clstr.EndAng, // end angle
240  0, // end opening angle (0 for line-like clusters)
241  sumChg, // integral
242  0, // sigma integral
243  sumADC, // summed ADC
244  0, // sigma summed ADC
245  nclhits, // n hits
246  0, // wires over hits
247  0, // width (0 for line-like clusters)
248  clsID, // ID
249  view, // view
250  planeID, // plane
251  recob::Cluster::Sentry // sentry
252  );
253  // make the cluster - hit association
254  if (!util::CreateAssn(
255  evt, *hc_assn, sccol.size() - 1, clstr.tclhits.begin(), clstr.tclhits.end())) {
257  << "Failed to associate hit " << iht << " with cluster " << icl;
258  } // exception
259  // make the cluster - EndPoint2D and Vertex associations
260  if (clstr.BeginVtx >= 0) {
261  end = 0;
262  // std::cout<<clstr.ID<<" clsID "<<clsID<<" Begin vtx "<<clstr.BeginVtx<<" vtxID "<<indxToIndx[clstr.BeginVtx]<<"\n";
263  if (!util::CreateAssnD(evt, *cep_assn, clsID - 1, indxToIndx[clstr.BeginVtx], end)) {
265  << "Failed to associate cluster " << clsID << " with EndPoint2D " << clstr.BeginVtx;
266  } // exception
267  // See if this endpoint is associated with a 3D vertex
268  unsigned short vtxIndex = 0;
269  for (ClusterCrawlerAlg::Vtx3Store const& vtx3 : Vertices) {
270  // ignore incomplete vertices
271  if (vtx3.Ptr2D[0] < 0) continue;
272  if (vtx3.Ptr2D[1] < 0) continue;
273  if (vtx3.Ptr2D[2] < 0) continue;
274  if (vtx3.Ptr2D[plane] == clstr.BeginVtx) {
275  if (!util::CreateAssnD(evt, *cv_assn, clsID - 1, vtxIndex, end)) {
277  << "Failed to associate cluster " << icl << " with vertex";
278  } // exception
279  break;
280  } // vertex match
281  ++vtxIndex;
282  } // 3D vertices
283  } // clstr.BeginVtx >= 0
284  if (clstr.EndVtx >= 0) {
285  end = 1;
286  // std::cout<<clstr.ID<<" clsID "<<clsID<<" End vtx "<<clstr.EndVtx<<" vtxID "<<indxToIndx[clstr.EndVtx]<<"\n";
287  if (!util::CreateAssnD(evt, *cep_assn, clsID - 1, indxToIndx[clstr.EndVtx], end)) {
289  << "Failed to associate cluster " << clsID << " with EndPoint2D " << clstr.BeginVtx;
290  } // exception
291  // See if this endpoint is associated with a 3D vertex
292  unsigned short vtxIndex = 0;
293  for (ClusterCrawlerAlg::Vtx3Store const& vtx3 : Vertices) {
294  // ignore incomplete vertices
295  if (vtx3.Ptr2D[0] < 0) continue;
296  if (vtx3.Ptr2D[1] < 0) continue;
297  if (vtx3.Ptr2D[2] < 0) continue;
298  if (vtx3.Ptr2D[plane] == clstr.EndVtx) {
299  if (!util::CreateAssnD(evt, *cv_assn, clsID - 1, vtxIndex, end)) {
301  << "Failed to associate cluster " << icl << " with endpoint";
302  } // exception
303  break;
304  } // vertex match
305  ++vtxIndex;
306  } // 3D vertices
307  } // clstr.BeginVtx >= 0
308  } // icl
309 
310  // convert cluster vector to unique_ptrs
311  std::unique_ptr<std::vector<recob::Cluster>> ccol(
312  new std::vector<recob::Cluster>(std::move(sccol)));
313 
314  shcol.use_hits(std::move(FinalHits));
315 
316  // clean up
318 
319  // move the hit collection and the associations into the event:
320  shcol.put_into(evt);
321  evt.put(std::move(ccol));
322  evt.put(std::move(hc_assn));
323  evt.put(std::move(v2col));
324  evt.put(std::move(v3col));
325  evt.put(std::move(cv_assn));
326  evt.put(std::move(cep_assn));
327 
328  } // LineCluster::produce()
329 
330  //----------------------------------------------------------------------------
332 
333 } // namespace cluster
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.
void produce(art::Event &evt) override
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Declaration of signal hit object.
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.
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:211
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
Definition: Hit.h:244
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
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
Helper functions to create a hit.
std::vector< recob::Hit > && YieldHits()
Returns (and loses) the collection of reconstructed hits.
std::vector< VtxStore > const & GetEndPoints() const
Returns a constant reference to the 2D end points found.
void use_hits(std::unique_ptr< std::vector< recob::Hit >> &&srchits)
Uses the specified collection as data product.
Definition: HitCreator.cxx:508
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
void put_into(art::Event &)
Moves the data into the event.
Definition: HitCreator.h:850
art::InputTag fHitFinderLabel
label of module producing input hits
A class handling a collection of hits and its associations.
Definition: HitCreator.h:787
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.
ClusterCrawlerAlg fCCAlg
Detector simulation of raw signals on wires.
ProducesCollector & producesCollector() noexcept
Produces clusters by ClusterCrawler algorithm.
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
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)
float SummedADC() const
The sum of calibrated ADC counts of the hit (0. by default)
Definition: Hit.h:240
LineCluster(fhicl::ParameterSet const &pset)
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:46
TCEvent evt
Definition: DataStructs.cxx:8
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:399