LineCluster_module.cc
Go to the documentation of this file.
1 /**
2  * @file LineCluster_module.cc
3  * @brief Cluster finder using cluster crawler algorithm
4  * @author Bruce Baller (bballer@fnal.gov)
5  *
6  * Generated at Fri Jun 7 09:44:09 2013 by Bruce Baller using artmod
7  * from cetpkgsupport v1_02_00.
8  */
9 
10 // Framework libraries
15 #include "fhiclcpp/ParameterSet.h"
16 
17 // LArSoft includes
21 
22 // ... more includes in the implementation section
23 
24 namespace cluster {
25  /**
26  * @brief Produces clusters by ClusterCrawler algorithm
27  *
28  * Configuration parameters
29  * -------------------------
30  *
31  * - *HitFinderModuleLabel* (InputTag, mandatory): label of the hits to be
32  * used as input (usually the label of the producing module is enough)
33  * - *ClusterCrawlerAlg* (parameter set, mandatory): full configuration for
34  * ClusterCrawlerAlg algorithm
35  *
36  */
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 
47  art::InputTag fHitFinderLabel; ///< label of module producing input hits
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  //----------------------------------------------------------------------------
102  void
104  {
105  // fetch the wires needed by CCHitFinder
106 
107  // make this accessible to ClusterCrawler_module
108  auto hitVecHandle = evt.getValidHandle<std::vector<recob::Hit>>(fHitFinderLabel);
109 
110  // look for clusters in all planes
111  auto const clock_data =
113  auto const det_prop =
115  fCCAlg.RunCrawler(clock_data, det_prop, *hitVecHandle);
116 
117  auto FinalHits = std::make_unique<std::vector<recob::Hit>>(std::move(fCCAlg.YieldHits()));
118 
119  // shcol contains the hit collection
120  // and its associations to wires and raw digits;
121  // we get the association to raw digits through wire associations
123  std::vector<recob::Cluster> sccol;
124  std::vector<recob::Vertex> sv3col;
125  std::vector<recob::EndPoint2D> sv2col;
126 
127  std::unique_ptr<art::Assns<recob::Cluster, recob::Hit>> hc_assn(
129  std::unique_ptr<art::Assns<recob::Cluster, recob::Vertex, unsigned short>> cv_assn(
131  std::unique_ptr<art::Assns<recob::Cluster, recob::EndPoint2D, unsigned short>> cep_assn(
133 
134  std::vector<ClusterCrawlerAlg::ClusterStore> const& Clusters = fCCAlg.GetClusters();
135 
136  // Consistency check
137  /*
138  std::vector<short> const& inClus = fCCAlg.GetinClus();
139  for(unsigned int icl = 0; icl < Clusters.size(); ++icl) {
140  ClusterCrawlerAlg::ClusterStore const& clstr = Clusters[icl];
141  if(clstr.ID < 0) continue;
142  geo::PlaneID planeID = ClusterCrawlerAlg::DecodeCTP(clstr.CTP);
143  unsigned short plane = planeID.Plane;
144  for(unsigned short ii = 0; ii < clstr.tclhits.size(); ++ii) {
145  unsigned int iht = clstr.tclhits[ii];
146  recob::Hit const& theHit = FinalHits->at(iht);
147  if(theHit.WireID().Plane != plane) {
148  mf::LogError("LineCluster")<<"Cluster-hit plane mis-match "<<theHit.WireID().Plane<<" "<<plane
149  <<" in cluster "<<clstr.ID<<" WT "<<clstr.BeginWir<<":"<<(int)clstr.BeginTim<<" cluster CTP "<<clstr.CTP;
150  return;
151  }
152  if(inClus[iht] != clstr.ID) {
153  mf::LogError("LineCluster") << "InClus mis-match " << inClus[iht]
154  << " ID " << clstr.ID << " in cluster ID " << clstr.ID<<" cluster ProcCode "<<clstr.ProcCode;;
155  return;
156  }
157  } // ii
158  } // icl
159 */
160  // make EndPoints (aka 2D vertices)
161  std::vector<ClusterCrawlerAlg::VtxStore> const& EndPts = fCCAlg.GetEndPoints();
162  std::vector<unsigned int> indxToIndx(EndPts.size());
164  unsigned short vtxID = 0, end, wire, ivx;
165  for (ivx = 0; ivx < EndPts.size(); ++ivx) {
166  if (EndPts[ivx].NClusters == 0) continue;
167  indxToIndx[ivx] = vtxID;
168  ++vtxID;
169  // std::cout<<"EndPt "<<ivx<<" vtxID "<<vtxID<<"\n";
170  wire = (0.5 + EndPts[ivx].Wire);
171  geo::PlaneID plID = ClusterCrawlerAlg::DecodeCTP(EndPts[ivx].CTP);
172  geo::WireID wID = geo::WireID(plID.Cryostat, plID.TPC, plID.Plane, wire);
173  geo::View_t view = geom->View(wID);
174  sv2col.emplace_back((double)EndPts[ivx].Time, // Time
175  wID, // WireID
176  0, // strength - not relevant
177  vtxID, // ID
178  view, // View
179  0); // total charge - not relevant
180  } // iv
181  // convert 2D Vertex vector to unique_ptrs
182  std::unique_ptr<std::vector<recob::EndPoint2D>> v2col(
183  new std::vector<recob::EndPoint2D>(std::move(sv2col)));
184 
185  // make 3D vertices
186  std::vector<ClusterCrawlerAlg::Vtx3Store> const& Vertices = fCCAlg.GetVertices();
187  double xyz[3] = {0, 0, 0};
188  vtxID = 0;
189  for (ClusterCrawlerAlg::Vtx3Store const& vtx3 : Vertices) {
190  // ignore incomplete vertices
191  if (vtx3.Ptr2D[0] < 0) continue;
192  if (vtx3.Ptr2D[1] < 0) continue;
193  if (vtx3.Ptr2D[2] < 0) continue;
194  ++vtxID;
195  xyz[0] = vtx3.X;
196  xyz[1] = vtx3.Y;
197  xyz[2] = vtx3.Z;
198  sv3col.emplace_back(xyz, vtxID);
199  } // 3D vertices
200  // convert Vertex vector to unique_ptrs
201  std::unique_ptr<std::vector<recob::Vertex>> v3col(
202  new std::vector<recob::Vertex>(std::move(sv3col)));
203 
204  // make the clusters and associations
205  float sumChg, sumADC;
206  unsigned int clsID = 0, nclhits;
207  for (unsigned int icl = 0; icl < Clusters.size(); ++icl) {
208  ClusterCrawlerAlg::ClusterStore const& clstr = Clusters[icl];
209  if (clstr.ID < 0) continue;
210  ++clsID;
211  sumChg = 0;
212  sumADC = 0;
214  unsigned short plane = planeID.Plane;
215  nclhits = clstr.tclhits.size();
216  std::vector<unsigned int> clsHitIndices;
217  // correct the hit indices to refer to the valid hits that were just added
218  for (unsigned int itt = 0; itt < nclhits; ++itt) {
219  unsigned int iht = clstr.tclhits[itt];
220  recob::Hit const& hit = FinalHits->at(iht);
221  sumChg += hit.Integral();
222  sumADC += hit.SummedADC();
223  } // itt
224  // get the wire, plane from a hit
225  unsigned int iht = clstr.tclhits[0];
226 
227  geo::View_t view = FinalHits->at(iht).View();
228  sccol.emplace_back((float)clstr.BeginWir, // Start wire
229  0, // sigma start wire
230  clstr.BeginTim, // start tick
231  0, // sigma start tick
232  clstr.BeginChg, // start charge
233  clstr.BeginAng, // start angle
234  0, // start opening angle (0 for line-like clusters)
235  (float)clstr.EndWir, // end wire
236  0, // sigma end wire
237  clstr.EndTim, // end tick
238  0, // sigma end tick
239  clstr.EndChg, // end charge
240  clstr.EndAng, // end angle
241  0, // end opening angle (0 for line-like clusters)
242  sumChg, // integral
243  0, // sigma integral
244  sumADC, // summed ADC
245  0, // sigma summed ADC
246  nclhits, // n hits
247  0, // wires over hits
248  0, // width (0 for line-like clusters)
249  clsID, // ID
250  view, // view
251  planeID, // plane
252  recob::Cluster::Sentry // sentry
253  );
254  // make the cluster - hit association
255  if (!util::CreateAssn(
256  *this, evt, *hc_assn, sccol.size() - 1, clstr.tclhits.begin(), clstr.tclhits.end())) {
258  << "Failed to associate hit " << iht << " with cluster " << icl;
259  } // exception
260  // make the cluster - EndPoint2D and Vertex associations
261  if (clstr.BeginVtx >= 0) {
262  end = 0;
263  // std::cout<<clstr.ID<<" clsID "<<clsID<<" Begin vtx "<<clstr.BeginVtx<<" vtxID "<<indxToIndx[clstr.BeginVtx]<<"\n";
264  if (!util::CreateAssnD(*this, evt, *cep_assn, clsID - 1, indxToIndx[clstr.BeginVtx], end)) {
266  << "Failed to associate cluster " << clsID << " with EndPoint2D " << clstr.BeginVtx;
267  } // exception
268  // See if this endpoint is associated with a 3D vertex
269  unsigned short vtxIndex = 0;
270  for (ClusterCrawlerAlg::Vtx3Store const& vtx3 : Vertices) {
271  // ignore incomplete vertices
272  if (vtx3.Ptr2D[0] < 0) continue;
273  if (vtx3.Ptr2D[1] < 0) continue;
274  if (vtx3.Ptr2D[2] < 0) continue;
275  if (vtx3.Ptr2D[plane] == clstr.BeginVtx) {
276  if (!util::CreateAssnD(*this, evt, *cv_assn, clsID - 1, vtxIndex, end)) {
278  << "Failed to associate cluster " << icl << " with vertex";
279  } // exception
280  break;
281  } // vertex match
282  ++vtxIndex;
283  } // 3D vertices
284  } // clstr.BeginVtx >= 0
285  if (clstr.EndVtx >= 0) {
286  end = 1;
287  // std::cout<<clstr.ID<<" clsID "<<clsID<<" End vtx "<<clstr.EndVtx<<" vtxID "<<indxToIndx[clstr.EndVtx]<<"\n";
288  if (!util::CreateAssnD(*this, evt, *cep_assn, clsID - 1, indxToIndx[clstr.EndVtx], end)) {
290  << "Failed to associate cluster " << clsID << " with EndPoint2D " << clstr.BeginVtx;
291  } // exception
292  // See if this endpoint is associated with a 3D vertex
293  unsigned short vtxIndex = 0;
294  for (ClusterCrawlerAlg::Vtx3Store const& vtx3 : Vertices) {
295  // ignore incomplete vertices
296  if (vtx3.Ptr2D[0] < 0) continue;
297  if (vtx3.Ptr2D[1] < 0) continue;
298  if (vtx3.Ptr2D[2] < 0) continue;
299  if (vtx3.Ptr2D[plane] == clstr.EndVtx) {
300  if (!util::CreateAssnD(*this, evt, *cv_assn, clsID - 1, vtxIndex, end)) {
302  << "Failed to associate cluster " << icl << " with endpoint";
303  } // exception
304  break;
305  } // vertex match
306  ++vtxIndex;
307  } // 3D vertices
308  } // clstr.BeginVtx >= 0
309  } // icl
310 
311  // convert cluster vector to unique_ptrs
312  std::unique_ptr<std::vector<recob::Cluster>> ccol(
313  new std::vector<recob::Cluster>(std::move(sccol)));
314 
315  shcol.use_hits(std::move(FinalHits));
316 
317  // clean up
319 
320  // move the hit collection and the associations into the event:
321  shcol.put_into(evt);
322  evt.put(std::move(ccol));
323  evt.put(std::move(hc_assn));
324  evt.put(std::move(v2col));
325  evt.put(std::move(v3col));
326  evt.put(std::move(cv_assn));
327  evt.put(std::move(cep_assn));
328 
329  } // LineCluster::produce()
330 
331  //----------------------------------------------------------------------------
333 
334 } // namespace cluster
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
void produce(art::Event &evt) override
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
The data type to uniquely identify a Plane.
Definition: geo_types.h:472
std::vector< ClusterStore > const & GetClusters() const
Returns a constant reference to the clusters found.
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:212
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
Definition: Hit.h:224
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:182
static geo::PlaneID DecodeCTP(CTP_t CTP)
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:528
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
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:908
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.
def move(depos, offset)
Definition: depos.py:107
art::InputTag fHitFinderLabel
label of module producing input hits
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
A class handling a collection of hits and its associations.
Definition: HitCreator.h:842
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
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:493
Definition of data types for geometry description.
ClusterCrawlerAlg fCCAlg
Detector simulation of raw signals on wires.
ProducesCollector & producesCollector() noexcept
Produces clusters by ClusterCrawler algorithm.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
Declaration of signal hit object.
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:223
LineCluster(fhicl::ParameterSet const &pset)
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
TCEvent evt
Definition: DataStructs.cxx:7
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:406