GraphCluster_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file GraphCluster_module.cc
3 /// \brief
4 ///
5 ///
6 /// \author andrzej.szelc@yale.edu
7 /// \author ellen.klein@yale.edu
8 ////////////////////////////////////////////////////////////////////////
9 
10 #include <vector>
12 
13 #ifdef __ROOTCLING__
14 namespace art {
15  class EDProducer;
16  class Event;
17  class PtrVector;
18  class Ptr;
19  class ServiceHandle;
20 }
21 
22 namespace fhicl {
23  class ParameterSet;
24 }
25 
26 namespace recob {
27  class Hit;
28 }
29 #else
36 #endif
37 
38 
39 ////////////////////////////////////////////////////////////////////////
40 //
41 // GraphCluster class
42 //
43 // andrzej.szelc@yale.edu
44 // ellen.klein@yale.edu
45 //
46 // This dummy producer is designed to create a hitlist and maybe cluster from EVD input
47 ////////////////////////////////////////////////////////////////////////
48 
49 // Framework includes
51 #include "fhiclcpp/ParameterSet.h"
52 
53 // LArSoft Includes
61 
62 namespace util {
63  class PxPoint;
64 }
65 
66 namespace geo {
67  class Geometry;
68 }
69 
70 /* unused function
71 namespace{
72  void WriteMsg(const char* fcn)
73  {
74  mf::LogWarning("GraphCluster") << "GraphCluster::" << fcn << " \n";
75  }
76 }
77 */
78 
79 namespace evd {
80 
81  class InfoTransfer;
82 
83  class GraphCluster : public art::EDProducer {
84 
85  public:
86 
87  explicit GraphCluster(fhicl::ParameterSet const&);
88  void produce(art::Event& evt);
89 
90  private:
91 
92 
94 
95  // art::ServiceHandle<evd::InfoTransfer const> intr;
96  // art::ServiceHandle<geo::Geometry const> geo;
97 
98  void GetStartEndHits(unsigned int plane, recob::Hit * starthit,recob::Hit * endhit);
99  void GetStartEndHits(unsigned int plane);
100 
101  //void GetHitList(unsigned int plane,std::vector< art::Ptr <recob::Hit> > ptrhitlist);
102  void GetHitList(unsigned int plane, art::PtrVector <recob::Hit> &ptrhitlist);
103 
104 
105  std::vector < util::PxLine > GetSeedLines();
106 
107  // int GetMetaInfo(art::Event& evt);
108 
109  unsigned int fNPlanes;
110 
111  int TestFlag;
112  int fRun;
113  int fSubRun;
114  int fEvent;
115 
116 
117 
118 
119  std::vector< recob::Hit * > starthit;
120  std::vector< recob::Hit * > endhit;
121 
122 // std::vector < std::vector< recob::Hit * > > hitlist;
123 
124  std::vector < util::PxLine > startendpoints;
125 
126 // std::vector <unsigned int> swire;
127 // std::vector <unsigned int> ewire;
128 // std::vector <double> stime;
129 // std::vector <double> etime;
130 
131 
132 
133  }; // class GraphCluster
134 
135 
136 
137  //-------------------------------------------------
138  GraphCluster::GraphCluster(fhicl::ParameterSet const& pset) :
139  EDProducer{pset},
140  fGClAlg(pset.get< fhicl::ParameterSet >("GraphClusterAlg"))
141  {
143 
144 
145  produces< std::vector<recob::Cluster> >();
146  produces< art::Assns<recob::Cluster, recob::Hit> >();
147  produces< std::vector < art::PtrVector <recob::Cluster> > >();
148 
149 
150  fNPlanes = geo->Nplanes();
151  starthit.resize(fNPlanes);
152  endhit.resize(fNPlanes);
153 
154 
155  startendpoints.resize(fNPlanes);
156 // swire.resize(fNPlanes);
157 // ewire.resize(fNPlanes);
158 // stime.resize(fNPlanes);
159 // etime.resize(fNPlanes);
160  }
161 
162 
163  //
164  //-------------------------------------------------
165  /// \todo This method appears to produce a recob::Cluster really as it is
166  /// \todo a collection of 2D clusters from single planes
168  {
169 
170  std::unique_ptr<std::vector<recob::Cluster> > Graphcol(new std::vector<recob::Cluster>);
171  std::unique_ptr< art::Assns<recob::Cluster, recob::Hit> > hassn(new art::Assns<recob::Cluster, recob::Hit>);
172  // std::unique_ptr< art::Assns<recob::Cluster, recob::Cluster> > classn(new art::Assns<recob::Cluster, recob::Cluster>);
173  std::unique_ptr< std::vector < art::PtrVector < recob::Cluster > > > classn(new std::vector < art::PtrVector < recob::Cluster > >);
174 
175 
176 
177 
179 
180  // check if evt and run numbers check out, etc...
181  if(fGClAlg.CheckValidity( evt ) == -1)
182  {
183  return;
184  }
185 
186 
187  for(unsigned int ip=0;ip<fNPlanes;ip++) {
188  startendpoints[ip]=util::PxLine(); //assign empty PxLine
189 
190  }
191 
192  std::vector < art::PtrVector < recob::Hit > > hitlist;
193  hitlist.resize(fNPlanes);
194 
195  for(unsigned int ip=0;ip<fNPlanes;ip++) {
196 
197  fGClAlg.GetHitListAndEndPoints(ip,hitlist[ip],startendpoints[ip]);
198  // Read in the Hit List object(s).
199  //fGClAlg.GetHitList(ip,hitlist[ip]);
200 
201  if(hitlist[ip].size()==0)
202  continue;
203  //Read in the starthit:
204  // GetStartEndHits(ip, starthit[ip],endhit[ip]);
205 
206 
207 
208 
209  //fGClAlg.GetStartEndHits(&startendpoints[ip]);
210 
211  if(hitlist[ip].size()>0 && !(TestFlag==-1 ) ) //old event or transfer not ready
212  {
213  double swterror=0.,ewterror=0.;
214 
215  if(startendpoints[ip].w0==0 )
216  swterror=999;
217 
218  if(startendpoints[ip].t1==0 )
219  ewterror=999;
220 
221  std::cout << " clustering @ " <<startendpoints[ip].w0 << " +/- "<< swterror
222  <<" " << startendpoints[ip].t0<< " +/- "<< swterror
223  <<" " << startendpoints[ip].w1<< " +/- "<< ewterror
224  <<" " << startendpoints[ip].t1<< " +/- "<< ewterror << std::endl;
225 
226  // this is all we can do easily without getting the full-blown
227  // ClusterParamsAlg (that means lareventdisplay has to depend on larreco!)
229  for (art::Ptr<recob::Hit> const& hit: hitlist[ip]) {
230  integral.add(hit->Integral());
231  summedADC.add(hit->SummedADC());
232  } // for
233 
234  // get the plane ID from the first hit
235  geo::PlaneID planeID = hitlist[ip].front()->WireID().planeID();
236  Graphcol->emplace_back(
237  startendpoints[ip].w0,
238  swterror,
239  startendpoints[ip].t0,
240  swterror,
241  0., // start_charge
242  0., // start_angle
243  0., // start_opening
244  startendpoints[ip].w1,
245  ewterror,
246  startendpoints[ip].t1,
247  ewterror,
248  0., // end_charge
249  0., // end_angle
250  0., // end_opening
251  integral.Sum(), // integral
252  integral.RMS(), // integral_stddev
253  summedADC.Sum(), // summedADC
254  summedADC.RMS(), // summedADC_stddev
255  hitlist[ip].size(), // n_hits
256  0., // multiple_hit_density
257  0., // width
258  ip,
259  geo->Plane(ip,planeID.TPC,planeID.Cryostat).View(),
260  planeID,
262  );
263 
264  // associate the hits to this cluster
265  util::CreateAssn(*this, evt, *Graphcol, hitlist[ip], *hassn);
266  }
267 
268  }// end of loop on planes
269 
271  cvec.reserve(fNPlanes);
272 
273  for(unsigned int ip=0;ip<fNPlanes;ip++) {
274  art::ProductID aid = evt.getProductID< std::vector < recob::Cluster > >();
275  art::Ptr< recob::Cluster > aptr(aid, ip, evt.productGetter(aid));
276  cvec.push_back(aptr);
277  }
278 
279  classn->push_back(cvec);
280 
281  // for(unsigned int ip=0;ip<fNPlanes;ip++) {
282  // for(unsigned int jp=ip+1;jp<fNPlanes;jp++) {
283  // util::CreateSameAssn(*this, evt, *Graphcol, *Graphcol, *classn,ip,ip+1,jp );
284  // // std::cout << "associating cluster" << ip <<" with cluster " << jp << std::endl;
285  // }
286  // }
287  //
288 
289  evt.put(std::move(Graphcol));
290  evt.put(std::move(hassn));
291  evt.put(std::move(classn));
292 
293  return;
294  } // end of produce
295 
296 
297 
299 
300 } //end of evd namespace
code to link reconstructed objects back to the MC truth information
void reserve(size_type n)
Definition: PtrVector.h:337
Namespace for general, non-LArSoft-specific utilities.
PlaneGeo const & Plane(unsigned int const p, unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified wire.
Reconstruction base classes.
ProductID getProductID(std::string const &instance_name="") const
Definition: DataViewImpl.h:338
The data type to uniquely identify a Plane.
Definition: geo_types.h:472
GraphClusterAlg fGClAlg
struct vector vector
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:212
Classes gathering simple statistics.
Weight_t RMS() const
Returns the root mean square.
std::vector< recob::Hit * > starthit
art framework interface to geometry description
static const SentryArgument_t Sentry
An instance of the sentry object.
Definition: Cluster.h:182
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
View_t View() const
Which coordinate does this plane measure.
Definition: PlaneGeo.h:184
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.
Definition: InfoTransfer.h:33
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:435
Weight_t Sum() const
Returns the weighted sum of the values.
int CheckValidity(art::Event &evt)
def move(depos, offset)
Definition: depos.py:107
EDProductGetter const * productGetter(ProductID const pid) const
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.
std::vector< util::PxLine > startendpoints
Definition of data types for geometry description.
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)
Declaration of signal hit object.
Encapsulate the construction of a single detector plane.
Definition: types.h:32
std::vector< recob::Hit * > endhit
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
LArSoft geometry interface.
Definition: ChannelGeo.h:16
Collects statistics on a single quantity (weighted)
QTextStream & endl(QTextStream &s)
void add(Data_t value, Weight_t weight=Weight_t(1.0))
Adds one entry with specified value and weight.