LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
HitSelector.cxx
Go to the documentation of this file.
1 
11 
12 #include "TMath.h"
22 
23 namespace {
24  void WriteMsg(const char* fcn)
25  {
26  mf::LogVerbatim("HitSelector") << "HitSelector::" << fcn << " \n";
27  }
28 }
29 
30 namespace evd {
31 
32  //----------------------------------------------------------------------------
34  {
35  starthitout.resize(3);
36  endhitout.resize(3);
37  }
38 
39  //......................................................................
47  //
49  std::vector<util::PxLine> seedlines,
50  double distance)
51  {
55  std::map<int, std::vector<art::Ptr<recob::Hit>>> hits_to_save;
56 
57  double KineticEnergy = 0;
59 
60  for (size_t imod = 0; imod < recoOpt->fHitLabels.size(); ++imod) {
61  art::InputTag const which = recoOpt->fHitLabels[imod];
62  evt.getByLabel(which, HitListHandle);
63  }
64 
65  infot->SetSeedList(seedlines);
66  for (std::map<int, std::vector<art::Ptr<recob::Hit>>>::iterator it = hits_to_save.begin();
67  it != hits_to_save.end();
68  ++it) {
69  infot->SetHitList(it->first, it->second);
70  }
71  infot->SetTestFlag(1);
72  infot->SetEvtNumber(evt.id().event());
73 
74  return KineticEnergy;
75  }
76 
77  //......................................................................
86  unsigned int plane,
87  double xin,
88  double yin,
89  double x1in,
90  double y1in,
91  double distance,
92  bool good_plane)
93  {
96  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
97  auto const detProp =
99  util::GeometryUtilities const gser{*geo, clockData, detProp};
100  std::vector<art::Ptr<recob::Hit>> hits_to_save;
101 
103 
104  starthitout[plane].clear();
105  endhitout[plane].clear();
106 
107  starthitout[plane].resize(2);
108  endhitout[plane].resize(2);
109 
110  //convert input variables to cm-cm space required by GeometryUtilities
111  double x = xin * gser.WireToCm();
112  double x1 = x1in * gser.WireToCm();
113  double y = yin * gser.TimeToCm();
114  double y1 = y1in * gser.TimeToCm();
115 
116  double lslope = 0;
117 
118  if ((x - x1) != 0) lslope = (y - y1) / (x - x1);
119 
120  for (size_t imod = 0; imod < recoOpt->fHitLabels.size(); ++imod) {
121  art::InputTag const which = recoOpt->fHitLabels[imod];
122 
123  std::vector<art::Ptr<recob::Hit>> hitlist;
124  hitlist.clear();
125  evt.getByLabel(which, HitListHandle);
126 
127  for (unsigned int ii = 0; ii < HitListHandle->size(); ++ii) {
128  art::Ptr<recob::Hit> hit(HitListHandle, ii);
129  if (hit->WireID().Plane == plane) hitlist.push_back(hit);
130  }
131 
132  // Select Local Hit List
133  util::PxHitConverter PxC{gser};
134  std::vector<util::PxHit> pxhitlist;
135  PxC.GeneratePxHit(hitlist, pxhitlist);
136  std::vector<unsigned int> pxhitlist_local_index;
137  std::vector<util::PxHit> pxhitlist_local;
138  pxhitlist_local.clear();
139 
140  util::PxPoint startHit;
141  startHit.plane = pxhitlist.at(0).plane;
142  startHit.w = (x + x1) / 2;
143  startHit.t = (y + y1) / 2;
144 
145  double orttemp = std::hypot(y1 - y, x1 - x) / 2;
146 
147  gser.SelectLocalHitlistIndex(
148  pxhitlist, pxhitlist_local_index, startHit, orttemp, distance, lslope);
149 
150  for (unsigned int idx = 0; idx < pxhitlist_local_index.size(); idx++) {
151  hits_to_save.push_back(hitlist.at(pxhitlist_local_index.at(idx)));
152  pxhitlist_local.push_back(pxhitlist.at(pxhitlist_local_index.at(idx)));
153  }
154 
155  auto const hit_index = gser.FindClosestHitIndex(pxhitlist_local, x, y);
156  recob::Hit const& hit = *hits_to_save[hit_index];
157  starthitout[plane][1] = hit.PeakTime();
158  starthitout[plane][0] = hit.WireID().Wire;
159 
160  recob::Hit const& endhit =
161  hit; // this obviously not correct, the fact that x,y are used for both start and end point, A.S. -> to debug
162  endhitout[plane][1] = endhit.PeakTime();
163  endhitout[plane][0] = endhit.WireID().Wire;
164  }
165 
167  infot->SetHitList(plane, hits_to_save);
168  infot->SetTestFlag(1);
169  if (good_plane) {
170  infot->SetStartHitCoords(plane, starthitout[plane]);
171  infot->SetEndHitCoords(plane, endhitout[plane]);
172  }
173  infot->SetEvtNumber(evt.id().event());
174  }
175 
176  //......................................................................
184  void HitSelector::ChangeHit(const art::Event& evt, unsigned int plane, double xin, double yin)
185  {
188  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
189  auto const detProp =
191  util::GeometryUtilities const gser{*geo, clockData, detProp};
192 
193  //get hits from info transfer, see if our selected hit is in it
194  std::vector<art::Ptr<recob::Hit>> hits_saved;
195  std::vector<art::Ptr<recob::Hit>> hitlist;
196 
197  double x = xin * gser.WireToCm();
198  double y = yin * gser.TimeToCm();
199 
201 
202  for (size_t imod = 0; imod < recoOpt->fHitLabels.size(); ++imod) {
203  art::InputTag const which = recoOpt->fHitLabels[imod];
204  evt.getByLabel(which, HitListHandle);
205 
206  for (unsigned int ii = 0; ii < HitListHandle->size(); ++ii) {
207  art::Ptr<recob::Hit> hit(HitListHandle, ii);
208  if (hit->WireID().Plane == plane) hitlist.push_back(hit);
209  }
210 
211  util::PxHitConverter PxC{gser};
212  std::vector<util::PxHit> pxhitlist;
213  PxC.GeneratePxHit(hitlist, pxhitlist);
214 
215  unsigned int hitindex = gser.FindClosestHitIndex(pxhitlist, x, y);
216  if (hitlist[hitindex].isNull() || (hitindex > hitlist.size())) {
217  WriteMsg("no luck finding hit in evd, please try again");
218  break;
219  }
220 
222  hits_saved = infot->GetSelectedHitList(plane);
223  int found_it = 0;
224  for (unsigned int jj = 0; jj < hits_saved.size(); ++jj) {
225  if (hitlist[hitindex]->PeakTime() == hits_saved[jj]->PeakTime()) {
226  if (hitlist[hitindex]->Channel() == hits_saved[jj]->Channel()) {
227  found_it = 1;
228  hits_saved.erase(hits_saved.begin() + jj);
229  }
230  }
231  }
232 
233  //if didn't find it, add it
234  if (found_it != 1) { hits_saved.push_back(hitlist[hitindex]); }
235 
236  //update the info transfer list
237  infot->SetHitList(plane, hits_saved);
238  infot->SetTestFlag(1);
239  infot->SetEvtNumber(evt.id().event());
240  }
241  }
242 
243  //......................................................................
251  std::vector<art::Ptr<recob::Hit>> HitSelector::GetSelectedHitPtrs(unsigned int plane)
252  {
254  return infot->GetSelectedHitList(plane);
255  }
256 
257  std::vector<const recob::Hit*> HitSelector::GetSelectedHits(unsigned int plane)
258  {
259  std::vector<art::Ptr<recob::Hit>> hits_saved;
260  std::vector<const recob::Hit*> hits_to_draw; //draw selected hits in a different color
261 
263  hits_saved = infot->GetSelectedHitList(plane);
264 
265  for (unsigned int i = 0; i < hits_saved.size(); i++)
266  hits_to_draw.push_back(hits_saved[i].get());
267 
268  return hits_to_draw;
269  }
270 
271  //......................................................................
272  void HitSelector::ClearHitList(unsigned int plane)
273  {
275  infot->ClearSelectedHitList(plane);
276  }
277 
278  //----------------------------------------------------------------------------
279  std::vector<recob::Seed>& HitSelector::SeedVector()
280  {
281  return fSeedVector;
282  }
283 
284 } //end namespace
Float_t x
Definition: compare.C:6
void SetTestFlag(int value)
Definition: InfoTransfer.h:55
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
std::vector< art::Ptr< recob::Hit > > GetSelectedHitPtrs(unsigned int plane)
void SaveHits(const art::Event &evt, unsigned int plane, double x, double y, double x1, double y1, double distance, bool good_plane=true)
Definition: HitSelector.cxx:85
Float_t y1[n_points_granero]
Definition: compare.C:5
void ClearSelectedHitList(int plane)
Definition: InfoTransfer.h:80
Float_t x1[n_points_granero]
Definition: compare.C:5
Float_t y
Definition: compare.C:6
void SetHitList(unsigned int p, std::vector< art::Ptr< recob::Hit >> hits_to_save)
Definition: InfoTransfer.h:64
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:563
geo::WireID const & WireID() const
Initial tdc tick for hit.
Definition: Hit.h:280
void SetStartHitCoords(unsigned int plane, std::vector< double > starthitin)
Definition: InfoTransfer.h:112
std::vector< std::vector< double > > starthitout
Definition: HitSelector.h:54
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
void GeneratePxHit(const std::vector< unsigned int > &hit_index, const std::vector< art::Ptr< recob::Hit >> hits, std::vector< PxHit > &pxhits) const
Generate: from 1 set of hits => 1 set of PxHits using indexes (association)
void ClearHitList(unsigned int plane)
LArSoft includes.
Class to perform operations needed to select hits and pass them to a cluster.
double t
Definition: PxUtils.h:10
std::vector< art::Ptr< recob::Hit > > const & GetSelectedHitList(unsigned int plane) const
Definition: InfoTransfer.h:75
std::vector< const recob::Hit * > GetSelectedHits(unsigned int plane)
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:481
std::vector< recob::Seed > fSeedVector
Definition: HitSelector.h:52
Detector simulation of raw signals on wires.
double w
Definition: PxUtils.h:9
void ChangeHit(const art::Event &evt, unsigned int plane, double x, double y)
void SetEvtNumber(int value)
Definition: InfoTransfer.h:61
float PeakTime() const
Time of the signal peak, in tick units.
Definition: Hit.h:220
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
void SetSeedList(std::vector< util::PxLine > seedlines)
EventNumber_t event() const
Definition: EventID.h:116
void SetEndHitCoords(unsigned int plane, std::vector< double > endhitin)
Definition: InfoTransfer.h:119
double SaveSeedLines(const art::Event &evt, std::vector< util::PxLine > seedline, double distance)
Definition: HitSelector.cxx:48
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:46
std::vector< art::InputTag > fHitLabels
module labels that produced hits
TCEvent evt
Definition: DataStructs.cxx:8
std::vector< std::vector< double > > endhitout
Definition: HitSelector.h:55
Namespace collecting geometry-related classes utilities.
EventID id() const
Definition: Event.cc:23
art framework interface to geometry description
unsigned int plane
Definition: PxUtils.h:11
std::vector< recob::Seed > & SeedVector()