LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
SpacePts_module.cc
Go to the documentation of this file.
1 //
3 // \file SpacePts_module.cc
4 //
5 // \author echurch@fnal.gov, msoderbe@fnal.gov
6 //
7 // A very ArgoNeuTy module, for now.
9 
10 #include <string>
11 #include <vector>
12 
13 #include <algorithm>
14 #include <cmath>
15 #include <iomanip>
16 
17 // Framework includes
26 #include "fhiclcpp/ParameterSet.h"
28 
29 // LArSoft includes
40 
41 // ROOT includes
42 #include "TF1.h"
43 #include "TGraph.h"
44 #include "TMath.h"
45 #include "TVector2.h"
46 #include "TVector3.h"
47 
48 namespace trkf {
49 
50  class SpacePts : public art::EDProducer {
51  public:
52  explicit SpacePts(fhicl::ParameterSet const& pset);
53 
54  private:
55  void produce(art::Event& evt);
56 
57  int ftmatch; // tolerance for time matching (in time samples)
58  double fPreSamplings; // in ticks
60  std::string fClusterModuleLabel; // label for input cluster collection
61  std::string fEndPoint2DModuleLabel; //label for input EndPoint2D collection
62  }; // class SpacePts
63 
64  struct SortByWire {
66  {
67  return h1->Channel() < h2->Channel();
68  }
69  };
70 
71  //-------------------------------------------------
73  {
74  fPreSamplings = pset.get<double>("TicksOffset");
75  ftmatch = pset.get<int>("TMatch");
76  fClusterModuleLabel = pset.get<std::string>("ClusterModuleLabel");
77  fEndPoint2DModuleLabel = pset.get<std::string>("EndPoint2DModuleLabel");
78  fvertexclusterWindow = pset.get<double>("vertexclusterWindow");
79 
80  produces<std::vector<recob::Track>>();
81  produces<std::vector<recob::SpacePoint>>();
82  produces<art::Assns<recob::Track, recob::SpacePoint>>();
83  produces<art::Assns<recob::Track, recob::Cluster>>();
84  produces<art::Assns<recob::Track, recob::Hit>>();
85  produces<art::Assns<recob::SpacePoint, recob::Hit>>();
86  }
87 
88  //------------------------------------------------------------------------------------//
90  {
92  auto const detProp =
94 
96  // Make a std::unique_ptr<> for the thing you want to put into the event
97  // because that handles the memory management for you
99  auto tcol = std::make_unique<std::vector<recob::Track>>();
100  auto spcol = std::make_unique<std::vector<recob::SpacePoint>>();
101  auto tspassn = std::make_unique<art::Assns<recob::Track, recob::SpacePoint>>();
102  auto tcassn = std::make_unique<art::Assns<recob::Track, recob::Cluster>>();
103  auto thassn = std::make_unique<art::Assns<recob::Track, recob::Hit>>();
104  auto shassn = std::make_unique<art::Assns<recob::SpacePoint, recob::Hit>>();
105 
106  // define TPC parameters
107  TString tpcName = geom->GetLArTPCVolumeName();
108 
109  //TPC dimensions
110  double YC = (geom->DetHalfHeight()) * 2.; // TPC height in cm
111  constexpr geo::TPCID tpcid{0, 0};
112  double Angle = geom->Plane(geo::PlaneID{tpcid, 1}).Wire(0).ThetaZ(false) -
113  TMath::Pi() / 2.; // wire angle with respect to the vertical direction
114  // Parameters temporary defined here, but possibly to be retrieved somewhere in the code
115  double timetick = 0.198; //time sample in us
116  double presamplings = fPreSamplings; // 60.;
117  const double wireShift =
118  50.; // half the number of wires from the Induction(Collection) plane intersecting with a wire from the Collection(Induction) plane.
119  double plane_pitch = geom->PlanePitch(tpcid, 0, 1); //wire plane pitch in cm
120  double wire_pitch = geom->WirePitch(); //wire pitch in cm
121  double Efield_drift = 0.5; // Electric Field in the drift region in kV/cm
122  double Efield_SI = 0.7; // Electric Field between Shield and Induction planes in kV/cm
123  double Efield_IC = 0.9; // Electric Field between Induction and Collection planes in kV/cm
124  double Temperature = 90.; // LAr Temperature in K
125 
126  double driftvelocity =
127  detProp.DriftVelocity(Efield_drift, Temperature); //drift velocity in the drift region (cm/us)
128  double driftvelocity_SI = detProp.DriftVelocity(
129  Efield_SI, Temperature); //drift velocity between shield and induction (cm/us)
130  double driftvelocity_IC = detProp.DriftVelocity(
131  Efield_IC, Temperature); //drift velocity between induction and collection (cm/us)
132  double timepitch = driftvelocity * timetick; //time sample (cm)
133  double tSI = plane_pitch / driftvelocity_SI /
134  timetick; //drift time between Shield and Collection planes (time samples)
135  double tIC = plane_pitch / driftvelocity_IC /
136  timetick; //drift time between Induction and Collection planes (time samples)
137 
138  // get input Cluster object(s).
139  art::Handle<std::vector<recob::Cluster>> clusterListHandle;
140  evt.getByLabel(fClusterModuleLabel, clusterListHandle);
141 
142  // get input EndPoint2D object(s).
143  art::Handle<std::vector<recob::EndPoint2D>> endpointListHandle;
144  evt.getByLabel(fEndPoint2DModuleLabel, endpointListHandle);
145 
147  if (evt.getByLabel(fEndPoint2DModuleLabel, endpointListHandle))
148  for (unsigned int i = 0; i < endpointListHandle->size(); ++i) {
149  art::Ptr<recob::EndPoint2D> endpointHolder(endpointListHandle, i);
150  endpointlist.push_back(endpointHolder);
151  }
152 
153  // Declare some vectors..
154  // Induction
155  std::vector<double> Iwirefirsts; // in cm
156  std::vector<double> Iwirelasts; // in cm
157  std::vector<double> Itimefirsts; // in cm
158  std::vector<double> Itimelasts; // in cm
159  std::vector<double> Itimefirsts_line; // in cm
160  std::vector<double> Itimelasts_line; // in cm
161  std::vector<std::vector<art::Ptr<recob::Hit>>> IclusHitlists;
162  std::vector<unsigned int> Icluster_count;
163 
164  // Collection
165  std::vector<double> Cwirefirsts; // in cm
166  std::vector<double> Cwirelasts; // in cm
167  std::vector<double> Ctimefirsts; // in cm
168  std::vector<double> Ctimelasts; // in cm
169  std::vector<double> Ctimefirsts_line; // in cm
170  std::vector<double> Ctimelasts_line; // in cm
171  std::vector<std::vector<art::Ptr<recob::Hit>>> CclusHitlists;
172  std::vector<unsigned int> Ccluster_count;
173 
174  art::FindManyP<recob::Hit> fm(clusterListHandle, evt, fClusterModuleLabel);
175 
176  for (unsigned int ii = 0; ii < clusterListHandle->size(); ++ii) {
177  art::Ptr<recob::Cluster> cl(clusterListHandle, ii);
178 
179  // Figure out which View the cluster belongs to
180  //only consider merged-lines that are associated with the vertex.
181  //this helps get rid of through-going muon background -spitz
182  int vtx2d_w = -99999;
183  double vtx2d_t = -99999;
184  bool found2dvtx = false;
185 
186  for (unsigned int j = 0; j < endpointlist.size(); j++) {
187  if (endpointlist[j]->View() == cl->View()) {
188  vtx2d_w = endpointlist[j]->WireID().Wire; //for update to EndPoint2D ... WK 4/22/13
189  vtx2d_t = endpointlist[j]->DriftTime();
190  found2dvtx = true;
191  break;
192  }
193  }
194  if (found2dvtx) {
195  double w = cl->StartWire();
196  double t = cl->StartTick();
197  double dtdw = std::tan(cl->StartAngle());
198  double t_vtx = t + dtdw * (vtx2d_w - w);
199  double dis = std::abs(vtx2d_t - t_vtx);
200  if (dis > fvertexclusterWindow) continue;
201  }
202  //else continue; //what to do if a 2D vertex is not found? perhaps vertex finder was not even run.
203 
204  // Some variables for the hit
205  float time; //hit time at maximum
206 
207  std::vector<art::Ptr<recob::Hit>> hitlist = fm.at(ii);
208  std::sort(hitlist.begin(), hitlist.end(), trkf::SortByWire());
209 
210  TGraph* the2Dtrack = new TGraph(hitlist.size());
211 
212  std::vector<double> wires;
213  std::vector<double> times;
214 
215  int np = 0;
216  //loop over cluster hits
217  for (std::vector<art::Ptr<recob::Hit>>::const_iterator theHit = hitlist.begin();
218  theHit != hitlist.end();
219  theHit++) {
220  //recover the Hit
221  // recob::Hit* theHit = (recob::Hit*)(*hitIter);
222  time = (*theHit)->PeakTime();
223 
224  time -= presamplings;
225 
226  if (geom->SignalType((*theHit)->Channel()) == geo::kCollection) time -= tIC; // Collection
227  //transform hit wire and time into cm
228  double wire_cm = 0.;
229  if (geom->SignalType((*theHit)->Channel()) == geo::kInduction)
230  wire_cm = (double)(((*theHit)->WireID().Wire + 3.95) * wire_pitch);
231  else
232  wire_cm = (double)(((*theHit)->WireID().Wire + 1.84) * wire_pitch);
233 
234  //double time_cm = (double)(time * timepitch);
235  double time_cm;
236  if (time > tSI)
237  time_cm = (double)((time - tSI) * timepitch + tSI * driftvelocity_SI * timetick);
238  else
239  time_cm = time * driftvelocity_SI * timetick;
240 
241  wires.push_back(wire_cm);
242  times.push_back(time_cm);
243 
244  the2Dtrack->SetPoint(np, wire_cm, time_cm);
245  np++;
246  } //end of loop over cluster hits
247 
248  // fit the 2Dtrack and get some info to store
249  try {
250  the2Dtrack->Fit("pol1", "Q");
251  }
252  catch (...) {
253  std::cout << "The 2D track fit failed" << std::endl;
254  continue;
255  }
256 
257  TF1* pol1 = (TF1*)the2Dtrack->GetFunction("pol1");
258  double par[2];
259  pol1->GetParameters(par);
260  double intercept = par[0];
261  double slope = par[1];
262 
263  double w0 = wires.front(); // first hit wire (cm)
264  double w1 = wires.back(); // last hit wire (cm)
265  double t0 = times.front(); // first hit time (cm)
266  double t1 = times.back(); // last hit time (cm)
267  double t0_line = intercept + (w0)*slope; // time coordinate at wire w0 on the fit line (cm)
268  double t1_line = intercept + (w1)*slope; // time coordinate at wire w1 on the fit line (cm)
269 
270  // actually store the 2Dtrack info
271  switch (geom->SignalType((*hitlist.begin())->Channel())) {
272  case geo::kInduction:
273  Iwirefirsts.push_back(w0);
274  Iwirelasts.push_back(w1);
275  Itimefirsts.push_back(t0);
276  Itimelasts.push_back(t1);
277  Itimefirsts_line.push_back(t0_line);
278  Itimelasts_line.push_back(t1_line);
279  IclusHitlists.push_back(hitlist);
280  Icluster_count.push_back(ii);
281  break;
282  case geo::kCollection:
283  Cwirefirsts.push_back(w0);
284  Cwirelasts.push_back(w1);
285  Ctimefirsts.push_back(t0);
286  Ctimelasts.push_back(t1);
287  Ctimefirsts_line.push_back(t0_line);
288  Ctimelasts_line.push_back(t1_line);
289  CclusHitlists.push_back(hitlist);
290  Ccluster_count.push_back(ii);
291  break;
292  case geo::kMysteryType: break;
293  }
294  delete pol1;
295  } // end of loop over all input clusters
296 
300 
301  for (unsigned int collectionIter = 0; collectionIter < CclusHitlists.size();
302  collectionIter++) { //loop over Collection view 2D tracks
303  // Recover previously stored info
304  double Cw0 = Cwirefirsts[collectionIter];
305  double Cw1 = Cwirelasts[collectionIter];
306  //double Ct0 = Ctimefirsts[collectionIter];
307  //double Ct1 = Ctimelasts[collectionIter];
308  double Ct0_line = Ctimefirsts_line[collectionIter];
309  double Ct1_line = Ctimelasts_line[collectionIter];
310  std::vector<art::Ptr<recob::Hit>> hitsCtrk = CclusHitlists[collectionIter];
311 
312  double collLength =
313  TMath::Sqrt(TMath::Power(Ct1_line - Ct0_line, 2) + TMath::Power(Cw1 - Cw0, 2));
314 
315  for (unsigned int inductionIter = 0; inductionIter < IclusHitlists.size();
316  inductionIter++) { //loop over Induction view 2D tracks
317  // Recover previously stored info
318  double Iw0 = Iwirefirsts[inductionIter];
319  double Iw1 = Iwirelasts[inductionIter];
320  //double It0 = Itimefirsts[inductionIter];
321  //double It1 = Itimelasts[inductionIter];
322  double It0_line = Itimefirsts_line[inductionIter];
323  double It1_line = Itimelasts_line[inductionIter];
324  std::vector<art::Ptr<recob::Hit>> hitsItrk = IclusHitlists[inductionIter];
325 
326  double indLength =
327  TMath::Sqrt(TMath::Power(It1_line - It0_line, 2) + TMath::Power(Iw1 - Iw0, 2));
328 
329  bool forward_match = ((std::abs(Ct0_line - It0_line) < ftmatch * timepitch) &&
330  (std::abs(Ct1_line - It1_line) < ftmatch * timepitch));
331  bool backward_match = ((std::abs(Ct0_line - It1_line) < ftmatch * timepitch) &&
332  (std::abs(Ct1_line - It0_line) < ftmatch * timepitch));
333 
334  if (forward_match || backward_match) {
335 
336  // Reconstruct the 3D track
337  TVector3 XYZ0, XYZ1; // track endpoints
338  if (forward_match) {
339  XYZ0.SetXYZ(Ct0_line,
340  (Cw0 - Iw0) / (2. * TMath::Sin(Angle)),
341  (Cw0 + Iw0) / (2. * TMath::Cos(Angle)) - YC / 2. * TMath::Tan(Angle));
342  XYZ1.SetXYZ(Ct1_line,
343  (Cw1 - Iw1) / (2. * TMath::Sin(Angle)),
344  (Cw1 + Iw1) / (2. * TMath::Cos(Angle)) - YC / 2. * TMath::Tan(Angle));
345  }
346  else {
347  XYZ0.SetXYZ(Ct0_line,
348  (Cw0 - Iw1) / (2. * TMath::Sin(Angle)),
349  (Cw0 + Iw1) / (2. * TMath::Cos(Angle)) - YC / 2. * TMath::Tan(Angle));
350  XYZ1.SetXYZ(Ct1_line,
351  (Cw1 - Iw0) / (2. * TMath::Sin(Angle)),
352  (Cw1 + Iw0) / (2. * TMath::Cos(Angle)) - YC / 2. * TMath::Tan(Angle));
353  }
354 
355  //compute track direction in Local co-ordinate system
356  //WARNING: There is an ambiguity introduced here for the case of backwards-going tracks.
357  //If available, vertex info. could sort this out.
358  TVector3 startpointVec, endpointVec;
359  TVector2 collVtx, indVtx;
360  if (XYZ0.Z() <= XYZ1.Z()) {
361  startpointVec.SetXYZ(XYZ0.X(), XYZ0.Y(), XYZ0.Z());
362  endpointVec.SetXYZ(XYZ1.X(), XYZ1.Y(), XYZ1.Z());
363  if (forward_match) {
364  collVtx.Set(Ct0_line, Cw0);
365  indVtx.Set(It0_line, Iw0);
366  }
367  else {
368  collVtx.Set(Ct0_line, Cw0);
369  indVtx.Set(It1_line, Iw1);
370  }
371  }
372  else {
373  startpointVec.SetXYZ(XYZ1.X(), XYZ1.Y(), XYZ1.Z());
374  endpointVec.SetXYZ(XYZ0.X(), XYZ0.Y(), XYZ0.Z());
375  if (forward_match) {
376  collVtx.Set(Ct1_line, Cw1);
377  indVtx.Set(It1_line, Iw1);
378  }
379  else {
380  collVtx.Set(Ct1_line, Cw1);
381  indVtx.Set(It0_line, Iw0);
382  }
383  }
384 
385  //compute track (normalized) cosine directions in the TPC co-ordinate system
386  TVector3 DirCos = endpointVec - startpointVec;
387 
388  //SetMag casues a crash if the magnitude of the vector is zero
389  try {
390  DirCos.SetMag(1.0); //normalize vector
391  }
392  catch (...) {
393  std::cout << "The Spacepoint is infinitely small" << std::endl;
394  continue;
395  }
396 
397  art::Ptr<recob::Cluster> cl1(clusterListHandle, Icluster_count[inductionIter]);
398  art::Ptr<recob::Cluster> cl2(clusterListHandle, Ccluster_count[collectionIter]);
399  art::PtrVector<recob::Cluster> clustersPerTrack;
400  clustersPerTrack.push_back(cl1);
401  clustersPerTrack.push_back(cl2);
402 
404  // Match hits
406 
407  //create collection of spacepoints that will be used when creating the Track object
408  std::vector<recob::SpacePoint> spacepoints;
409 
410  std::vector<art::Ptr<recob::Hit>> minhits =
411  hitsCtrk.size() <= hitsItrk.size() ? hitsCtrk : hitsItrk;
412  std::vector<art::Ptr<recob::Hit>> maxhits =
413  hitsItrk.size() < hitsCtrk.size() ? hitsCtrk : hitsItrk;
414 
415  std::vector<bool> maxhitsMatch(maxhits.size());
416  for (unsigned int it = 0; it < maxhits.size(); it++)
417  maxhitsMatch[it] = false;
418 
419  std::vector<recob::Hit*> hits3Dmatched;
420  // For the matching start from the view where the track projection presents less hits
421  unsigned int imaximum = 0;
422  size_t spStart = spcol->size();
423  for (unsigned int imin = 0; imin < minhits.size(); imin++) { //loop over hits
424  //get wire - time coordinate of the hit
425  //unsigned int channel,wire,plane1,plane2,tpc,cstat;
426  geo::WireID hit1WireID = minhits[imin]->WireID();
427  auto const hitSigType = minhits[imin]->SignalType();
428  double w1 = 0;
429 
430  //the 3.95 and 1.84 below are the ArgoNeuT TPC offsets for the induction and collection plane, respectively and are in units of wire pitch.
431  if (hitSigType == geo::kInduction)
432  w1 = (double)((hit1WireID.Wire + 3.95) * wire_pitch);
433  else
434  w1 = (double)((hit1WireID.Wire + 1.84) * wire_pitch);
435 
436  double temptime1 = minhits[imin]->PeakTime() - presamplings;
437  if (hitSigType == geo::kCollection) temptime1 -= tIC;
438  double
439  t1; // = plane1==1?(double)((minhits[imin]->PeakTime()-presamplings-tIC)*timepitch):(double)((minhits[imin]->PeakTime()-presamplings)*timepitch); //in cm
440  if (temptime1 > tSI)
441  t1 = (double)((temptime1 - tSI) * timepitch + tSI * driftvelocity_SI * timetick);
442  else
443  t1 = temptime1 * driftvelocity_SI * timetick;
444 
445  //get the track origin co-ordinates in the two views
446  TVector2 minVtx2D;
447  (hitSigType == geo::kCollection) ? minVtx2D.Set(collVtx.X(), collVtx.Y()) :
448  minVtx2D.Set(indVtx.X(), indVtx.Y());
449  TVector2 maxVtx2D;
450  (hitSigType == geo::kCollection) ? maxVtx2D.Set(indVtx.X(), indVtx.Y()) :
451  maxVtx2D.Set(collVtx.X(), collVtx.Y());
452 
453  double ratio =
454  (collLength > indLength) ? collLength / indLength : indLength / collLength;
455 
456  //compute the distance of the hit (imin) from the relative track origin
457  double minDistance = ratio * TMath::Sqrt(TMath::Power(t1 - minVtx2D.X(), 2) +
458  TMath::Power(w1 - minVtx2D.Y(), 2));
459 
460  //core matching algorithm
461  double difference = 9999999.;
462 
463  for (unsigned int imax = 0; imax < maxhits.size();
464  imax++) { //loop over hits of the other view
465  if (!maxhitsMatch[imax]) {
466  //get wire - time coordinate of the hit
467  geo::WireID hit2WireID = maxhits[imax]->WireID();
468  auto const hit2SigType = maxhits[imax]->SignalType();
469  double w2 = 0.;
470  if (hit2SigType == geo::kInduction)
471  w2 = (double)((hit2WireID.Wire + 3.95) * wire_pitch);
472  else
473  w2 = (double)((hit2WireID.Wire + 1.84) * wire_pitch);
474 
475  double temptime2 = maxhits[imax]->PeakTime() - presamplings;
476  if (hit2SigType == geo::kCollection) temptime2 -= tIC;
477  double t2;
478  if (temptime2 > tSI)
479  t2 = (double)((temptime2 - tSI) * timepitch + tSI * driftvelocity_SI * timetick);
480  else
481  t2 = temptime2 * driftvelocity_SI * timetick;
482 
483  bool timematch = (std::abs(t1 - t2) < ftmatch * timepitch);
484  bool wirematch = (std::abs(w1 - w2) < wireShift * wire_pitch);
485 
486  double maxDistance = TMath::Sqrt(TMath::Power(t2 - maxVtx2D.X(), 2) +
487  TMath::Power(w2 - maxVtx2D.Y(), 2));
488  if (wirematch && timematch && std::abs(maxDistance - minDistance) < difference) {
489  difference = std::abs(maxDistance - minDistance);
490  imaximum = imax;
491  }
492  }
493  }
494  maxhitsMatch[imaximum] = true;
495 
497  if (difference != 9999999.) {
498  sp_hits.push_back(minhits[imin]);
499  sp_hits.push_back(maxhits[imaximum]);
500  }
501 
502  // Get the time-wire co-ordinates of the matched hit
503  geo::WireID hit2WireID = maxhits[imaximum]->WireID();
504  auto const hit2SigType = maxhits[imaximum]->SignalType();
505 
506  //double w1_match = (double)((wire+1)*wire_pitch);
507  double w1_match = 0.;
508  if (hit2SigType == geo::kInduction)
509  w1_match = (double)((hit2WireID.Wire + 3.95) * wire_pitch);
510  else
511  w1_match = (double)((hit2WireID.Wire + 1.84) * wire_pitch);
512 
513  double temptime3 = maxhits[imaximum]->PeakTime() - presamplings;
514  if (hit2SigType == geo::kCollection) temptime3 -= tIC;
515  double t1_match;
516  if (temptime3 > tSI)
517  t1_match =
518  (double)((temptime3 - tSI) * timepitch + tSI * driftvelocity_SI * timetick);
519  else
520  t1_match = temptime3 * driftvelocity_SI * timetick;
521 
522  // create the 3D hit, compute its co-ordinates and add it to the 3D hits list
523  double Ct = hitSigType == geo::kCollection ? t1 : t1_match;
524  double Cw = hit2SigType == geo::kCollection ? w1 : w1_match;
525  double Iw = hit2SigType == geo::kCollection ? w1_match : w1;
526 
527  const TVector3 hit3d(Ct,
528  (Cw - Iw) / (2. * TMath::Sin(Angle)),
529  (Cw + Iw) / (2. * TMath::Cos(Angle)) -
530  YC / 2. * TMath::Tan(Angle));
531 
532  Double_t hitcoord[3];
533  hitcoord[0] = hit3d.X();
534  hitcoord[1] = hit3d.Y();
535  hitcoord[2] = hit3d.Z();
536 
537  /*
538  double yy,zz;
539  if(geom->ChannelsIntersect(geom->PlaneWireToChannel(0,(int)((Iw/wire_pitch)-3.95)), geom->PlaneWireToChannel(1,(int)((Cw/wire_pitch)-1.84)),yy,zz))
540  {
541  //channelsintersect provides a slightly more accurate set of y and z coordinates. use channelsintersect in case the wires in question do cross.
542  hitcoord[1] = yy;
543  hitcoord[2] = zz;
544  mf::LogInfo("SpacePts: ") << "SpacePoint adding xyz ..." << hitcoord[0] <<","<< hitcoord[1] <<","<< hitcoord[2];
545  // std::cout<<"wire 1: "<<(Iw/wire_pitch)-3.95<<" "<<(Cw/wire_pitch)-1.84<<std::endl;
546  // std::cout<<"Intersect: "<<yy<<" "<<zz<<std::endl;
547  }
548  else
549  continue;
550  */
551 
552  double err[6] = {util::kBogusD};
553  recob::SpacePoint mysp(hitcoord,
554  err,
556  spStart + spacepoints.size()); //3d point at end of track
557  // Don't add a spacepoint right on top of the last one.
558  const double eps(0.1); // 1mm
559  if (spacepoints.size() >= 1) {
560  TVector3 magNew(mysp.XYZ()[0], mysp.XYZ()[1], mysp.XYZ()[2]);
561  TVector3 magLast(spacepoints.back().XYZ()[0],
562  spacepoints.back().XYZ()[1],
563  spacepoints.back().XYZ()[2]);
564  if (!(magNew.Mag() >= magLast.Mag() + eps || magNew.Mag() <= magLast.Mag() - eps))
565  continue;
566  }
567  spacepoints.push_back(mysp);
568  spcol->push_back(mysp);
569  util::CreateAssn(evt, *spcol, sp_hits, *shassn);
570 
571  } //loop over min-hits
572 
573  size_t spEnd = spcol->size();
574 
575  // Add the 3D track to the vector of the reconstructed tracks
576  if (spacepoints.size() > 0) {
577 
578  // make a vector of the trajectory points along the track
579  std::vector<TVector3> xyz(spacepoints.size());
580  for (size_t s = 0; s < spacepoints.size(); ++s) {
581  xyz[s] = TVector3(spacepoints[s].XYZ());
582  }
583 
585  std::vector<TVector3> dircos(spacepoints.size(), DirCos);
586 
587  tcol->push_back(
590  recob::Track::Flags_t(xyz.size()),
591  false),
592  0,
593  -1.,
594  0,
597  tcol->size()));
598 
599  // make associations between the track and space points
600  util::CreateAssn(evt, *tcol, *spcol, *tspassn, spStart, spEnd);
601 
602  // now the track and clusters
603  util::CreateAssn(evt, *tcol, clustersPerTrack, *tcassn);
604 
605  // and the hits and track
606  art::FindManyP<recob::Hit> fmh(clustersPerTrack, evt, fClusterModuleLabel);
607  for (size_t cpt = 0; cpt < clustersPerTrack.size(); ++cpt)
608  util::CreateAssn(evt, *tcol, fmh.at(cpt), *thassn);
609  }
610  } //close match 2D tracks
611 
612  } //close loop over Induction view 2D tracks
613 
614  } //close loop over Collection xxview 2D tracks
615 
616  mf::LogVerbatim("Summary") << std::setfill('-') << std::setw(175) << "-" << std::setfill(' ');
617  mf::LogVerbatim("Summary") << "SpacePts Summary:";
618  for (unsigned int i = 0; i < tcol->size(); ++i)
619  mf::LogVerbatim("Summary") << tcol->at(i);
620 
621  evt.put(std::move(tcol));
622  evt.put(std::move(spcol));
623  evt.put(std::move(tspassn));
624  evt.put(std::move(tcassn));
625  evt.put(std::move(thassn));
626  evt.put(std::move(shassn));
627 
628  } // end SpacePts::produce()
629 
631 
632 } // end namespace
code to link reconstructed objects back to the MC truth information
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
std::string GetLArTPCVolumeName(TPCID const &tpcid=tpc_zero) const
Return the name of specified LAr TPC volume.
TTree * t1
Definition: plottest35.C:26
Who knows?
Definition: geo_types.h:153
double fvertexclusterWindow
std::vector< Vector_t > convertCollToVector(std::vector< Vector > const &coll)
Definition: TrackingTypes.h:78
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
SpacePts(fhicl::ParameterSet const &pset)
TrackTrajectory::Flags_t Flags_t
Definition: Track.h:67
constexpr auto abs(T v)
Returns the absolute value of the argument.
float StartWire() const
Returns the wire coordinate of the start of the cluster.
Definition: Cluster.h:276
ROOT::Math::SMatrix< Double32_t, 5, 5, ROOT::Math::MatRepSym< Double32_t, 5 >> SMatrixSym55
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:563
float StartAngle() const
Returns the starting angle of the cluster.
Definition: Cluster.h:461
std::string fClusterModuleLabel
double ThetaZ() const
Angle of the wires from positive z axis; .
Definition: PlaneGeo.cxx:646
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
void produce(art::Event &evt)
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.
bool SortByWire(art::Ptr< recob::Hit > const &h1, art::Ptr< recob::Hit > const &h2)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:435
Signal from induction planes.
Definition: geo_types.h:151
A trajectory in space reconstructed from hits.
Provides recob::Track data product.
std::vector< Point_t > convertCollToPoint(std::vector< Point > const &coll)
Definition: TrackingTypes.h:68
The data type to uniquely identify a TPC.
Definition: geo_types.h:381
Declaration of cluster object.
size_type size() const
Definition: PtrVector.h:302
TTree * t2
Definition: plottest35.C:36
TH1F * h2
Definition: plot.C:44
Encapsulate the geometry of a wire.
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.
bool operator()(art::Ptr< recob::Hit > const &h1, art::Ptr< recob::Hit > const &h2) const
geo::View_t View() const
Returns the view for this cluster.
Definition: Cluster.h:714
SigType_t SignalType(PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
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.
Length_t PlanePitch(TPCID const &tpcid, PlaneID::PlaneID_t p1=0, PlaneID::PlaneID_t p2=1) const
Returns the distance between two planes.
TH1F * h1
Definition: plot.C:41
constexpr double kBogusD
obviously bogus double value
Length_t DetHalfHeight(TPCID const &tpcid=tpc_zero) const
Returns the half height of the active volume of the specified TPC.
TCEvent evt
Definition: DataStructs.cxx:8
std::string fEndPoint2DModuleLabel
Float_t w
Definition: plot.C:20
float StartTick() const
Returns the tick coordinate of the start of the cluster.
Definition: Cluster.h:287
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
Definition: Hit.h:268
Length_t WirePitch(PlaneID const &planeid=plane_zero) const
Returns the distance between two consecutive wires.
art framework interface to geometry description
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:49
Signal from collection planes.
Definition: geo_types.h:152