LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
GraphCluster_module.cc
Go to the documentation of this file.
1 #ifndef GRAPHCLUSTER_H
10 #define GRAPHCLUSTER_H
11 
12 #include <vector>
13 #include <string>
15 
16 #ifdef __ROOTCLING__
17 namespace art {
18  class EDProducer;
19  class Event;
20  class PtrVector;
21  class Ptr;
22  class ServiceHandle;
23  class View;
24 }
25 
26 namespace fhicl {
27  class ParameterSet;
28 }
29 
30 namespace recob {
31  class Hit;
32 }
33 
34 
35 #else
45 
46 #endif
47 
48 
50 //
51 // GraphCluster class
52 //
53 // andrzej.szelc@yale.edu
54 // ellen.klein@yale.edu
55 //
56 // This dummy producer is designed to create a hitlist and maybe cluster from EVD input
58 
59 extern "C" {
60 #include <sys/types.h>
61 #include <sys/stat.h>
62 }
63 #include <sstream>
64 #include <math.h>
65 #include <algorithm>
66 
67 // Framework includes
69 #include "fhiclcpp/ParameterSet.h"
73 
77 
78 // LArSoft Includes
79 
86 
87 // ROOT
88 #include "TMath.h"
89 #include "TF1.h"
90 #include "TH1D.h"
91 
92 
93 
94 namespace util {
95  class PxLine;
96  class PxPoint;
97 }
98 
99 namespace geo {
100  class Geometry;
101 }
102 
103 /* unused function
104 namespace{
105  void WriteMsg(const char* fcn)
106  {
107  mf::LogWarning("GraphCluster") << "GraphCluster::" << fcn << " \n";
108  }
109 }
110 */
111 
112 namespace evd {
113 
114  class InfoTransfer;
115 
116  class GraphCluster : public art::EDProducer {
117 
118  public:
119 
120  explicit GraphCluster(fhicl::ParameterSet const&);
121  virtual ~GraphCluster();
122 
123  void reconfigure(fhicl::ParameterSet const& p);
124  void produce(art::Event& evt);
125 
126  private:
127 
128 
130 
131  protected:
132 
133  // art::ServiceHandle<evd::InfoTransfer> intr;
134  // art::ServiceHandle<geo::Geometry> geo;
135 
136  void GetStartEndHits(unsigned int plane, recob::Hit * starthit,recob::Hit * endhit);
137  void GetStartEndHits(unsigned int plane);
138 
139  //void GetHitList(unsigned int plane,std::vector< art::Ptr <recob::Hit> > ptrhitlist);
140  void GetHitList(unsigned int plane, art::PtrVector <recob::Hit> &ptrhitlist);
141 
142 
143  std::vector < util::PxLine > GetSeedLines();
144 
145  // int GetMetaInfo(art::Event& evt);
146 
147  unsigned int fNPlanes;
148 
149  int TestFlag;
150  int fRun;
151  int fSubRun;
152  int fEvent;
153 
154 
155 
156 
157  std::vector< recob::Hit * > starthit;
158  std::vector< recob::Hit * > endhit;
159 
160 // std::vector < std::vector< recob::Hit * > > hitlist;
161 
162  std::vector < util::PxLine > startendpoints;
163 
164 // std::vector <unsigned int> swire;
165 // std::vector <unsigned int> ewire;
166 // std::vector <double> stime;
167 // std::vector <double> etime;
168 
169 
170 
171  }; // class GraphCluster
172 
173 
174 
175  //-------------------------------------------------
176  GraphCluster::GraphCluster(fhicl::ParameterSet const& pset) :
177  fGClAlg(pset.get< fhicl::ParameterSet >("GraphClusterAlg"))
178  {
179  this->reconfigure(pset);
181 
182 
183  produces< std::vector<recob::Cluster> >();
184  produces< art::Assns<recob::Cluster, recob::Hit> >();
185  produces< std::vector < art::PtrVector <recob::Cluster> > >();
186 
187 
188  fNPlanes = geo->Nplanes();
189  starthit.resize(fNPlanes);
190  endhit.resize(fNPlanes);
191 
192 
193  startendpoints.resize(fNPlanes);
194 // swire.resize(fNPlanes);
195 // ewire.resize(fNPlanes);
196 // stime.resize(fNPlanes);
197 // etime.resize(fNPlanes);
198  }
199 
200 
201  //-------------------------------------------------
203  {
204  }
205 
206  //-------------------------------------------------
208  {
209 
210 
211  return;
212  }
213 
214  //
215  //-------------------------------------------------
219  {
220 
221  std::unique_ptr<std::vector<recob::Cluster> > Graphcol(new std::vector<recob::Cluster>);
222  std::unique_ptr< art::Assns<recob::Cluster, recob::Hit> > hassn(new art::Assns<recob::Cluster, recob::Hit>);
223  // std::unique_ptr< art::Assns<recob::Cluster, recob::Cluster> > classn(new art::Assns<recob::Cluster, recob::Cluster>);
224  std::unique_ptr< std::vector < art::PtrVector < recob::Cluster > > > classn(new std::vector < art::PtrVector < recob::Cluster > >);
225 
226 
227 
228 
230 
231  // check if evt and run numbers check out, etc...
232  if(fGClAlg.CheckValidity( evt ) == -1)
233  {
234  return;
235  }
236 
237 
238  for(unsigned int ip=0;ip<fNPlanes;ip++) {
239  startendpoints[ip]=util::PxLine(); //assign empty PxLine
240 
241  }
242 
243  std::vector < art::PtrVector < recob::Hit > > hitlist;
244  hitlist.resize(fNPlanes);
245 
246  for(unsigned int ip=0;ip<fNPlanes;ip++) {
247 
248  fGClAlg.GetHitListAndEndPoints(ip,hitlist[ip],startendpoints[ip]);
249  // Read in the Hit List object(s).
250  //fGClAlg.GetHitList(ip,hitlist[ip]);
251 
252  if(hitlist[ip].size()==0)
253  continue;
254  //Read in the starthit:
255  // GetStartEndHits(ip, starthit[ip],endhit[ip]);
256 
257 
258 
259 
260  //fGClAlg.GetStartEndHits(&startendpoints[ip]);
261 
262  if(hitlist[ip].size()>0 && !(TestFlag==-1 ) ) //old event or transfer not ready
263  {
264  double swterror=0.,ewterror=0.;
265 
266  if(startendpoints[ip].w0==0 )
267  swterror=999;
268 
269  if(startendpoints[ip].t1==0 )
270  ewterror=999;
271 
272  std::cout << " clustering @ " <<startendpoints[ip].w0 << " +/- "<< swterror
273  <<" " << startendpoints[ip].t0<< " +/- "<< swterror
274  <<" " << startendpoints[ip].w1<< " +/- "<< ewterror
275  <<" " << startendpoints[ip].t1<< " +/- "<< ewterror << std::endl;
276 
277  // this is all we can do easily without getting the full-blown
278  // ClusterParamsAlg (that means lareventdisplay has to depend on larreco!)
279  lar::util::StatCollector<float> integral, summedADC;
280  for (art::Ptr<recob::Hit> const& hit: hitlist[ip]) {
281  integral.add(hit->Integral());
282  summedADC.add(hit->SummedADC());
283  } // for
284 
285  // get the plane ID from the first hit
286  geo::PlaneID planeID = hitlist[ip].front()->WireID().planeID();
287  Graphcol->emplace_back(
288  startendpoints[ip].w0,
289  swterror,
290  startendpoints[ip].t0,
291  swterror,
292  0., // start_charge
293  0., // start_angle
294  0., // start_opening
295  startendpoints[ip].w1,
296  ewterror,
297  startendpoints[ip].t1,
298  ewterror,
299  0., // end_charge
300  0., // end_angle
301  0., // end_opening
302  integral.Sum(), // integral
303  integral.RMS(), // integral_stddev
304  summedADC.Sum(), // summedADC
305  summedADC.RMS(), // summedADC_stddev
306  hitlist[ip].size(), // n_hits
307  0., // multiple_hit_density
308  0., // width
309  ip,
310  geo->Plane(ip,planeID.TPC,planeID.Cryostat).View(),
311  planeID,
313  );
314 
315  // associate the hits to this cluster
316  util::CreateAssn(*this, evt, *Graphcol, hitlist[ip], *hassn);
317  }
318 
319  }// end of loop on planes
320 
322  cvec.reserve(fNPlanes);
323 
324  for(unsigned int ip=0;ip<fNPlanes;ip++) {
325  art::ProductID aid = this->getProductID< std::vector < recob::Cluster > >();
326  art::Ptr< recob::Cluster > aptr(aid, ip, evt.productGetter(aid));
327  cvec.push_back(aptr);
328  }
329 
330  classn->push_back(cvec);
331 
332  // for(unsigned int ip=0;ip<fNPlanes;ip++) {
333  // for(unsigned int jp=ip+1;jp<fNPlanes;jp++) {
334  // util::CreateSameAssn(*this, evt, *Graphcol, *Graphcol, *classn,ip,ip+1,jp );
335  // // std::cout << "associating cluster" << ip <<" with cluster " << jp << std::endl;
336  // }
337  // }
338  //
339 
340  evt.put(std::move(Graphcol));
341  evt.put(std::move(hassn));
342  evt.put(std::move(classn));
343 
344  return;
345  } // end of produce
346 
347 
348 
350 
351 } //end of evd namespace
352 
353 
354 #endif // GRAPHCLUSTER_H
code to link reconstructed objects back to the MC truth information
void reserve(size_type n)
Definition: PtrVector.h:343
Namespace for general, non-LArSoft-specific utilities.
Definition: PIDAAlg.h:17
PlaneGeo const & Plane(unsigned int const p, unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified wire.
TTree * t1
Definition: plottest35.C:26
Reconstruction base classes.
Declaration of signal hit object.
The data type to uniquely identify a Plane.
Definition: geo_types.h:250
GraphClusterAlg fGClAlg
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:130
EDProductGetter const * productGetter(ProductID const) const
Definition: Event.cc:64
Classes gathering simple statistics.
Weight_t RMS() const
Returns the root mean square.
std::vector< recob::Hit * > starthit
static const SentryArgument_t Sentry
An instance of the sentry object.
Definition: Cluster.h:182
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
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.
LArSoft includes.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:441
Weight_t Sum() const
Returns the weighted sum of the values.
int CheckValidity(art::Event &evt)
parameter set interface
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.
std::vector< util::PxLine > startendpoints
Declaration of cluster object.
Detector simulation of raw signals on wires.
void GetHitListAndEndPoints(unsigned int plane, art::PtrVector< recob::Hit > &ptrhitlist, util::PxLine &startendpoints)
void produce(art::Event &evt)
Utility object to perform functions of association.
Encapsulate the construction of a single detector plane.
HLT enums.
std::vector< recob::Hit * > endhit
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:49
TCEvent evt
Definition: DataStructs.cxx:5
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:203
Namespace collecting geometry-related classes utilities.
Collects statistics on a single quantity (weighted)
void reconfigure(fhicl::ParameterSet const &p)
art framework interface to geometry description
void add(Data_t value, Weight_t weight=Weight_t(1.0))
Adds one entry with specified value and weight.