LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
SmallClusterFinder_module.cc
Go to the documentation of this file.
1 //
3 // \file SmallClusterFinder.cxx
4 //
5 // \author corey.adams@yale.edu
6 //
7 // This algorithm is designed to find small clusters that could correspond to gammas
8 // or low energy electrons.
9 //
10 /* There are two parameters that matter from the fcl file:
11  fNHitsInClust is the number of hits that should be in these small clusters
12  ^-- Gamma events seem to rarely have more than 4 hits in the cluster
13  ^-- SN events are unclear. Should this even be used for SN?
14  fRadiusSizePar is the distance (in cm) between the small clusters and any other hits.
15 
16  This algorithm sorts the hits by plane, and then looks at each hit individually. If
17  there is a hit within RadiusSizePar, it gets added to a local list. All other hits
18  are ignored. Then, if the number of hits that got added to the local list is greater
19  then NHitsInClust, the original hit is ignored. If it's less, the original hit is
20  presumed to be part of a very small (or single hit) cluster. So its added to the list
21  of hits in the small cluster.
22 
23  All of the small clusters are then split apart into groups in the way you would expect.
24  Each cluster is assigned an ID number to distinguish it, and the hits that aren't
25  identified as small clusters all end up in the "leftover" cluster. The numbering scheme
26  is ID = 100*iPlane + Cluster on that plane, and the leftover hits are the first (0th)
27  cluster written out.
28 
29  All of the heavy lifting is done is the SmallClusterFinderAlg.
30  This module remains responsible for interacting with the framework, getting hits,
31  writing clusters, etc.
32 
33  Thanks to Andrzej for the basic alg.
34 
35  -Corey
36 */
37 //
39 
40 #include <iostream>
41 
42 // include the proper bit of the framework
47 
48 //All the larsoft goodies:
60 
61 namespace cluster {
62 
64  public:
65  explicit SmallClusterFinder(fhicl::ParameterSet const& pset);
66 
67  private:
68  void beginJob() override;
69  void produce(art::Event& evt) override;
73 
74  //input parameters
75  std::string fHitFinderModuleLabel;
76  bool verbose;
77  // double fRadiusSizePar; //Determines the max radius of the cluster, must be separated
78  // double fNHitsInClust; //Forces cluster to have a max number of hits
79  // Remember, this is the *small* cluster finder
80 
81  SmallClusterFinderAlg fSmallClusterFinderAlg; //object that actually finds and sorts gammas
82 
83  unsigned int fNPlanes; // number of planes
84 
86  unsigned int& p,
87  unsigned int& cs,
88  unsigned int& t,
89  unsigned int& w);
90 
91  }; // class SmallAngleFinder
92 
93 }
94 namespace cluster {
96  : EDProducer{pset}, fSmallClusterFinderAlg(pset.get<fhicl::ParameterSet>("smallClustAlg"))
97  {
98  fHitFinderModuleLabel = pset.get<std::string>("HitFinderModuleLabel");
99  verbose = pset.get<bool>("Verbose");
100 
101  produces<std::vector<recob::Cluster>>(); //This code makes clusters
102  produces<art::Assns<recob::Cluster, recob::Hit>>(); //Matches clusters with hits
103  }
104 
105  // ***************** //
107  {
108  // this will not change on a run per run basis.
109  fNPlanes = geom->Nplanes(); //get the number of planes in the TPC
110  }
111 
112  // ***************** //
113  // This method actually makes the clusters.
115  {
118  //Get the hits for this event:
120  evt.getByLabel(fHitFinderModuleLabel, HitListHandle);
121 
122  //A vector to hold hits, not yet filled:
123  std::vector<art::Ptr<recob::Hit>> hitlist;
124 
125  //How many hits in this event? Tell user:
126  if (verbose)
127  std::cout << " ++++ Hitsreceived received " << HitListHandle->size() << " +++++ "
128  << std::endl;
129  //Catch the case were there are no hits in the event:
130  if (HitListHandle->size() == 0) {
131  if (verbose) std::cout << "No hits received! Exiting." << std::endl;
132  return;
133  }
134  hitlist.resize(HitListHandle->size());
135 
136  //wrap the hits in art::Ptrs to pass to the Alg
137  for (unsigned int iHit = 0; iHit < hitlist.size(); iHit++) {
138  hitlist[iHit] = art::Ptr<recob::Hit>(HitListHandle, iHit);
139  }
140 
141  //std::cout << "Passing " << hitlist.size() << " hits to the alg." << std::endl;
142 
143  // Now run the alg to find the gammas:
144  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
145  auto const detProp =
147  util::GeometryUtilities const gser{*geom, clockData, detProp};
148  fSmallClusterFinderAlg.FindSmallClusters(gser, clockData, detProp, hitlist);
149 
150  // make an art::PtrVector of the clusters
151  auto SmallClusterFinder = std::make_unique<std::vector<recob::Cluster>>();
152  auto assn = std::make_unique<art::Assns<recob::Cluster, recob::Hit>>();
153 
154  // prepare the algorithm to compute the cluster characteristics;
155  // we use the "standard" one here; configuration would happen here,
156  // but we are using the default configuration for that algorithm
158 
159  for (unsigned int iplane = 0; iplane < fNPlanes; iplane++) {
160 
161  auto const leftoverHits = fSmallClusterFinderAlg.GetLeftoversByPlane(iplane);
162 
163  //write the leftover hits as a cluster:
164  if (leftoverHits.size() != 0) {
165  // pick some information from the first hit
166  geo::PlaneID planeID = leftoverHits.front()->WireID().planeID();
167  if (verbose)
168  std::cout << "Writing leftover hits to cluster ID: " << iplane * 100 << std::endl;
169 
170  ClusterParamAlgo.ImportHits(gser, leftoverHits);
171 
172  // create the recob::Cluster directly in the vector
173  ClusterCreator leftover(gser,
174  ClusterParamAlgo, // algo
175  0., // start_wire
176  0., // sigma_start_wire
177  0., // start_tick
178  0., // sigma_start_tick
179  0., // end_wire
180  0., // sigma_end_wire,
181  0., // end_tick
182  0., // sigma_end_tick
183  iplane * 100, // ID
184  geom->Plane(geo::PlaneID{planeID.asTPCID(), iplane}).View(),
185  planeID, // plane
186  recob::Cluster::Sentry // sentry
187  );
188 
189  SmallClusterFinder->emplace_back(leftover.move());
190 
191  util::CreateAssn(evt, *SmallClusterFinder, leftoverHits, *assn);
192  } //leftovers are written for this plane, if they exist.
193 
194  auto const smallClusters = fSmallClusterFinderAlg.GetSmallClustersByPlane(iplane);
195  for (unsigned int i = 0; i < smallClusters.size(); i++) {
196  // pick some information from the first hit
197  geo::PlaneID planeID; // invalid by default
198  if (!smallClusters.empty()) planeID = smallClusters[i].front()->WireID().planeID();
199 
200  ClusterParamAlgo.ImportHits(gser, smallClusters[i]);
201 
202  // create the recob::Cluster directly in the vector
203  ClusterCreator clust(gser,
204  ClusterParamAlgo, // algo
205  0., // start_wire
206  0., // sigma_start_wire
207  0., // start_tick
208  0., // sigma_start_tick
209  0., // end_wire
210  0., // sigma_end_wire,
211  0., // end_tick
212  0., // sigma_end_tick
213  iplane * 100 + i + 1, // ID
214  geom->Plane(geo::PlaneID{planeID.asTPCID(), iplane}).View(),
215  planeID, // plane
216  recob::Cluster::Sentry // sentry
217  );
218 
219  SmallClusterFinder->emplace_back(clust.move());
220  // associate the hits to this cluster
221  util::CreateAssn(evt, *SmallClusterFinder, smallClusters[i], *assn);
222  }
223  }
224 
225  evt.put(std::move(SmallClusterFinder));
226  evt.put(std::move(assn));
227  } //end produce
228 
230 }
Class managing the creation of a new recob::Cluster object.
void produce(art::Event &evt) override
SmallClusterFinderAlg fSmallClusterFinderAlg
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
SmallClusterFinder(fhicl::ParameterSet const &pset)
void FindSmallClusters(util::GeometryUtilities const &gser, detinfo::DetectorClocksData const &dataClocks, detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit >> allHits)
Cluster finding and building.
static const SentryArgument_t Sentry
An instance of the sentry object.
Definition: Cluster.h:174
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
PlaneGeo const & Plane(PlaneID const &planeid) const
Returns the specified wire.
View_t View() const
Which coordinate does this plane measure.
Definition: PlaneGeo.h:166
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
Helper functions to create a cluster.
Wrapper for ClusterParamsAlgBase objects to accept diverse input.
std::vector< art::Ptr< recob::Hit > > GetLeftoversByPlane(unsigned int iPlane)
Wrapper for ClusterParamsAlgBase objects to accept arbitrary input.
Declaration of cluster object.
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.
int GetPlaneAndTPC(art::Ptr< recob::Hit > a, unsigned int &p, unsigned int &cs, unsigned int &t, unsigned int &w)
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Utility object to perform functions of association.
Encapsulate the construction of a single detector plane.
std::vector< std::vector< art::Ptr< recob::Hit > > > GetSmallClustersByPlane(unsigned int iPlane)
art::ServiceHandle< geo::Geometry const > geom
unsigned int Nplanes(TPCID const &tpcid=tpc_zero) const
Returns the total number of planes in the specified TPC.
Definition: GeometryCore.h:977
Interface to class computing cluster parameters.
TCEvent evt
Definition: DataStructs.cxx:8
Float_t w
Definition: plot.C:20