LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
GraphCluster_module.cc
Go to the documentation of this file.
1 
11 #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 
39 //
40 // GraphCluster class
41 //
42 // andrzej.szelc@yale.edu
43 // ellen.klein@yale.edu
44 //
45 // This dummy producer is designed to create a hitlist and maybe cluster from EVD input
47 
48 // Framework includes
50 #include "fhiclcpp/ParameterSet.h"
51 
52 // LArSoft Includes
60 
61 namespace util {
62  class PxPoint;
63 }
64 
65 namespace geo {
66  class Geometry;
67 }
68 
69 namespace evd {
70 
71  class InfoTransfer;
72 
73  class GraphCluster : public art::EDProducer {
74 
75  public:
76  explicit GraphCluster(fhicl::ParameterSet const&);
77  void produce(art::Event& evt);
78 
79  private:
81 
82  void GetStartEndHits(unsigned int plane, recob::Hit* starthit, recob::Hit* endhit);
83  void GetStartEndHits(unsigned int plane);
84 
85  void GetHitList(unsigned int plane, art::PtrVector<recob::Hit>& ptrhitlist);
86 
87  std::vector<util::PxLine> GetSeedLines();
88 
89  unsigned int fNPlanes;
90 
91  int TestFlag;
92  int fRun;
93  int fSubRun;
94  int fEvent;
95 
96  std::vector<recob::Hit*> starthit;
97  std::vector<recob::Hit*> endhit;
98 
99  std::vector<util::PxLine> startendpoints;
100  }; // class GraphCluster
101 
102  //-------------------------------------------------
103  GraphCluster::GraphCluster(fhicl::ParameterSet const& pset)
104  : EDProducer{pset}, fGClAlg(pset.get<fhicl::ParameterSet>("GraphClusterAlg"))
105  {
107 
108  produces<std::vector<recob::Cluster>>();
109  produces<art::Assns<recob::Cluster, recob::Hit>>();
110  produces<std::vector<art::PtrVector<recob::Cluster>>>();
111 
112  fNPlanes = geo->Nplanes();
113  starthit.resize(fNPlanes);
114  endhit.resize(fNPlanes);
115 
116  startendpoints.resize(fNPlanes);
117  }
118 
119  //
120  //-------------------------------------------------
124  {
125 
126  std::unique_ptr<std::vector<recob::Cluster>> Graphcol(new std::vector<recob::Cluster>);
127  std::unique_ptr<art::Assns<recob::Cluster, recob::Hit>> hassn(
129  std::unique_ptr<std::vector<art::PtrVector<recob::Cluster>>> classn(
131 
133 
134  // check if evt and run numbers check out, etc...
135  if (fGClAlg.CheckValidity(evt) == -1) { return; }
136 
137  for (unsigned int ip = 0; ip < fNPlanes; ip++) {
138  startendpoints[ip] = util::PxLine(); //assign empty PxLine
139  }
140 
141  std::vector<art::PtrVector<recob::Hit>> hitlist;
142  hitlist.resize(fNPlanes);
143 
144  for (unsigned int ip = 0; ip < fNPlanes; ip++) {
145 
146  fGClAlg.GetHitListAndEndPoints(ip, hitlist[ip], startendpoints[ip]);
147 
148  if (hitlist[ip].size() == 0) continue;
149 
150  if (hitlist[ip].size() > 0 && !(TestFlag == -1)) //old event or transfer not ready
151  {
152  double swterror = 0., ewterror = 0.;
153 
154  if (startendpoints[ip].w0 == 0) swterror = 999;
155 
156  if (startendpoints[ip].t1 == 0) ewterror = 999;
157 
158  std::cout << " clustering @ " << startendpoints[ip].w0 << " +/- " << swterror << " "
159  << startendpoints[ip].t0 << " +/- " << swterror << " " << startendpoints[ip].w1
160  << " +/- " << ewterror << " " << startendpoints[ip].t1 << " +/- " << ewterror
161  << std::endl;
162 
163  // this is all we can do easily without getting the full-blown
164  // ClusterParamsAlg (that means lareventdisplay has to depend on larreco!)
165  lar::util::StatCollector<float> integral, summedADC;
166  for (art::Ptr<recob::Hit> const& hit : hitlist[ip]) {
167  integral.add(hit->Integral());
168  summedADC.add(hit->SummedADC());
169  } // for
170 
171  // get the plane ID from the first hit
172  geo::PlaneID planeID = hitlist[ip].front()->WireID().planeID();
173  Graphcol->emplace_back(startendpoints[ip].w0,
174  swterror,
175  startendpoints[ip].t0,
176  swterror,
177  0., // start_charge
178  0., // start_angle
179  0., // start_opening
180  startendpoints[ip].w1,
181  ewterror,
182  startendpoints[ip].t1,
183  ewterror,
184  0., // end_charge
185  0., // end_angle
186  0., // end_opening
187  integral.Sum(), // integral
188  integral.RMS(), // integral_stddev
189  summedADC.Sum(), // summedADC
190  summedADC.RMS(), // summedADC_stddev
191  hitlist[ip].size(), // n_hits
192  0., // multiple_hit_density
193  0., // width
194  ip,
195  geo->Plane({planeID.asTPCID(), ip}).View(),
196  planeID,
198 
199  // associate the hits to this cluster
200  util::CreateAssn(evt, *Graphcol, hitlist[ip], *hassn);
201  }
202 
203  } // end of loop on planes
204 
206  cvec.reserve(fNPlanes);
207 
208  for (unsigned int ip = 0; ip < fNPlanes; ip++) {
209  art::ProductID aid = evt.getProductID<std::vector<recob::Cluster>>();
210  art::Ptr<recob::Cluster> aptr(aid, ip, evt.productGetter(aid));
211  cvec.push_back(aptr);
212  }
213 
214  classn->push_back(cvec);
215 
216  evt.put(std::move(Graphcol));
217  evt.put(std::move(hassn));
218  evt.put(std::move(classn));
219 
220  return;
221  } // end of produce
222 
224 
225 } //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.
Definition: PIDAAlg.h:26
TTree * t1
Definition: plottest35.C:26
Reconstruction base classes.
ProductID getProductID(std::string const &instance_name="") const
Declaration of signal hit object.
std::vector< recob::Hit * > starthit
The data type to uniquely identify a Plane.
Definition: geo_types.h:463
GraphClusterAlg fGClAlg
Classes gathering simple statistics.
Weight_t RMS() const
Returns the root mean square.
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
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
PlaneGeo const & Plane(PlaneID const &planeid) const
Returns the specified wire.
Ptr(H, T) -> Ptr< detail::not_map_vector_t< typename H::element_type >>
EDProductGetter const * productGetter(ProductID const pid) const
std::vector< recob::Hit * > endhit
LArSoft includes.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
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)
parameter set interface
std::vector< util::PxLine > startendpoints
Declaration of cluster object.
Definition of data types for geometry description.
Detector simulation of raw signals on wires.
constexpr TPCID const & asTPCID() const
Conversion to TPCID (for convenience of notation).
Definition: geo_types.h:438
void GetHitListAndEndPoints(unsigned int plane, art::PtrVector< recob::Hit > &ptrhitlist, util::PxLine &startendpoints)
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.
void produce(art::Event &evt)
Utility object to perform functions of association.
Encapsulate the construction of a single detector plane.
Definition: MVAAlg.h:12
unsigned int Nplanes(TPCID const &tpcid=tpc_zero) const
Returns the total number of planes in the specified TPC.
Definition: GeometryCore.h:977
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:46
TCEvent evt
Definition: DataStructs.cxx:8
Namespace collecting geometry-related classes utilities.
Collects statistics on a single quantity (weighted)
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.