LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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:
58 
59 
60 namespace cluster {
61 
63 
64  public:
65 
67  explicit SmallClusterFinder(fhicl::ParameterSet const& pset);
68  virtual ~SmallClusterFinder();
69  void beginJob();
70  void beginRun(art::Run& run);
71  void reconfigure(fhicl::ParameterSet const& pset);
72  void produce(art::Event& evt);
74  private:
75 
77 
78  //input parameters
79  std::string fHitFinderModuleLabel;
80  bool verbose;
81  // double fRadiusSizePar; //Determines the max radius of the cluster, must be separated
82  // double fNHitsInClust; //Forces cluster to have a max number of hits
83  // Remember, this is the *small* cluster finder
84 
85  SmallClusterFinderAlg fSmallClusterFinderAlg; //object that actually finds and sorts gammas
86 
87  unsigned int fNPlanes; // number of planes
88 
90  unsigned int &p,
91  unsigned int &cs,
92  unsigned int &t,
93  unsigned int &w);
94 
95  }; // class SmallAngleFinder
96 
97 }
98 namespace cluster{
100  {
101  this->reconfigure(pset);
102  produces< std::vector<recob::Cluster> >(); //This code makes clusters
103  produces< art::Assns<recob::Cluster, recob::Hit> >(); //Matches clusters with hits
104  }
105 
107  {
108  fHitFinderModuleLabel =pset.get< std::string > ("HitFinderModuleLabel");
109  verbose =pset.get< bool > ("Verbose");
110 
111  //Let the clusterAlg have access to the pset too:
112  fSmallClusterFinderAlg.reconfigure(pset.get<fhicl::ParameterSet> ("smallClustAlg") );
113  }
114 
115  // ***************** //
117  {
118  //Nothing to do in the destructor
119  }
120 
121  //____________________________________________________________________________
123  {
124  //nothing to do at beginRun()
125  return;
126  }
127 
128  //-----------------------------------------------
129 
130  // ***************** //
132  {
133  // this will not change on a run per run basis.
134  fNPlanes = geom->Nplanes(); //get the number of planes in the TPC
137  return;
138  }
139 
140 
141 
142  // ***************** //
143  // This method actually makes the clusters.
145  {
148  //Get the hits for this event:
149  art::Handle< std::vector<recob::Hit> > HitListHandle;
150  evt.getByLabel(fHitFinderModuleLabel,HitListHandle);
151 
152  //A vector to hold hits, not yet filled:
153  std::vector< art::Ptr<recob::Hit> > hitlist;
154 
155  //How many hits in this event? Tell user:
156  if (verbose) std::cout << " ++++ Hitsreceived received " << HitListHandle->size() << " +++++ " << std::endl;
157  //Catch the case were there are no hits in the event:
158  if(HitListHandle->size() ==0 )
159  {
160  if (verbose) std::cout << "No hits received! Exiting." << std::endl;
161  return;
162  }
163  hitlist.resize(HitListHandle->size());
164 
165  //wrap the hits in art::Ptrs to pass to the Alg
166  for (unsigned int iHit = 0; iHit < hitlist.size(); iHit++){
167  hitlist[iHit] = art::Ptr< recob::Hit>(HitListHandle, iHit);
168  }
169 
170  //std::cout << "Passing " << hitlist.size() << " hits to the alg." << std::endl;
171 
172 
173  //Now run the alg to find the gammas:
175 
176 
177 
178  // make an art::PtrVector of the clusters
179  std::unique_ptr< std::vector<recob::Cluster> > SmallClusterFinder(new std::vector<recob::Cluster>);
180  std::unique_ptr< art::Assns<recob::Cluster, recob::Hit> > assn(new art::Assns<recob::Cluster, recob::Hit>);
181 
182  // prepare the algorithm to compute the cluster characteristics;
183  // we use the "standard" one here; configuration would happen here,
184  // but we are using the default configuration for that algorithm
186 
187 
188  for(unsigned int iplane=0;iplane<fNPlanes;iplane++){
189 
190  //Get the leftover hits for this plane:
191  std::vector<art::Ptr<recob::Hit> > leftoverHits = fSmallClusterFinderAlg.GetLeftoversByPlane(iplane);
192 
193  //write the leftover hits as a cluster:
194  if (leftoverHits.size() != 0){
195  // pick some information from the first hit
196  geo::PlaneID planeID = leftoverHits.front()->WireID().planeID();
197  if (verbose) std::cout << "Writing leftover hits to cluster ID: " << iplane*100 << std::endl;
198 
199  ClusterParamAlgo.ImportHits(leftoverHits);
200 
201  // create the recob::Cluster directly in the vector
202  ClusterCreator leftover(
203  ClusterParamAlgo, // algo
204  0., // start_wire
205  0., // sigma_start_wire
206  0., // start_tick
207  0., // sigma_start_tick
208  0., // end_wire
209  0., // sigma_end_wire,
210  0., // end_tick
211  0., // sigma_end_tick
212  iplane*100, // ID
213  geom->Plane(iplane,planeID.TPC,planeID.Cryostat).View(),
214  // view
215  planeID, // plane
216  recob::Cluster::Sentry // sentry
217  );
218 
219  SmallClusterFinder->emplace_back(leftover.move());
220 
221  util::CreateAssn(*this, evt, *SmallClusterFinder, leftoverHits, *assn);
222  } //leftovers are written for this plane, if they exist.
223 
224  //Now get the small clusters;
225  std::vector< std::vector<art::Ptr<recob::Hit> > > smallClusters;
226  smallClusters = fSmallClusterFinderAlg.GetSmallClustersByPlane(iplane);
227 
228  for (unsigned int i = 0; i < smallClusters.size(); i++){
229  // pick some information from the first hit
230  geo::PlaneID planeID; // invalid by default
231  if (!smallClusters.empty()) planeID = smallClusters[i].front()->WireID().planeID();
232 
233  ClusterParamAlgo.ImportHits(smallClusters[i]);
234 
235  // create the recob::Cluster directly in the vector
236  ClusterCreator clust(
237  ClusterParamAlgo, // algo
238  0., // start_wire
239  0., // sigma_start_wire
240  0., // start_tick
241  0., // sigma_start_tick
242  0., // end_wire
243  0., // sigma_end_wire,
244  0., // end_tick
245  0., // sigma_end_tick
246  iplane*100 + i + 1, // ID
247  geom->Plane(iplane,planeID.TPC,planeID.Cryostat).View(),
248  // view
249  planeID, // plane
250  recob::Cluster::Sentry // sentry
251  );
252 
253  SmallClusterFinder->emplace_back(clust.move());
254  // associate the hits to this cluster
255  util::CreateAssn(*this, evt, *SmallClusterFinder, smallClusters[i], *assn);
256  }
257 
258  //Just in case there is nothing for this event, make an empty cluster
259  //so that the clusters are defined. Tag with ID -1.
260  /* if (smallClusters.size() == 0 && leftoverHits.size() == 0){
261  std::vector< art::Ptr < recob::Hit> > emptyVector;
262  recob::Cluster clust( 0, 0, //start wire, error in start wire
263  0, 0, //start time, error in start time
264  0., 0., //end wire, error in end wire
265  0., 0., //end time, error in end wire
266  0., 0., //dTdW, error in dTdW ??
267  0., 0., //dQdW, error in dQdW ??
268  0., //Total Q
269  geom->Plane(iplane,0,0).View(), //View (geo::View_t)
270  -iplane, //id for cluster, given as plane here
271  PlaneID()); // invalid plane
272 
273 
274  SmallClusterFinder->push_back(clust);
275  // associate the hits to this cluster
276  util::CreateAssn(*this, evt, *SmallClusterFinder, emptyVector, *assn);
277  }
278  */
279 
280  }
281 
282  //Finish up:
283  evt.put(std::move(SmallClusterFinder));
284  evt.put(std::move(assn));
285 
286  return;
287  } //end produce
288 
289 } // end namespace cluster
290 
291 namespace cluster {
292 
294 
295 }
296 
297 
Class managing the creation of a new recob::Cluster object.
PlaneGeo const & Plane(unsigned int const p, unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified wire.
SmallClusterFinderAlg fSmallClusterFinderAlg
Declaration of signal hit object.
The data type to uniquely identify a Plane.
Definition: geo_types.h:250
SmallClusterFinder(fhicl::ParameterSet const &pset)
void FindSmallClusters(std::vector< art::Ptr< recob::Hit > > allHits)
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:130
Cluster finding and building.
static const SentryArgument_t Sentry
An instance of the sentry object.
Definition: Cluster.h:182
Definition: Run.h:30
void reconfigure(fhicl::ParameterSet const &pset)
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
View_t View() const
Which coordinate does this plane measure.
Definition: PlaneGeo.h:171
unsigned int Nplanes(unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wire planes in the specified TPC.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
Helper functions to create a cluster.
Wrapper for ClusterParamsAlgBase objects to accept diverse input.
std::vector< art::Ptr< recob::Hit > > GetLeftoversByPlane(unsigned int iPlane)
T get(std::string const &key) const
Definition: ParameterSet.h:231
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.
Declaration of cluster object.
int GetPlaneAndTPC(art::Ptr< recob::Hit > a, unsigned int &p, unsigned int &cs, unsigned int &t, unsigned int &w)
Utility object to perform functions of association.
Encapsulate the construction of a single detector plane.
void reconfigure(fhicl::ParameterSet const &pset)
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
std::vector< std::vector< art::Ptr< recob::Hit > > > GetSmallClustersByPlane(unsigned int iPlane)
art::ServiceHandle< geo::Geometry > geom
void ImportHits(Iter begin, Iter end)
Calls SetHits() with the hits in the sequence.
Interface to class computing cluster parameters.
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:203
Float_t w
Definition: plot.C:23