LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
HitSelector.cxx
Go to the documentation of this file.
1 
11 
12 #include "TMath.h"
23 
24 namespace {
25  void WriteMsg(const char* fcn)
26  {
27  mf::LogVerbatim("HitSelector") << "HitSelector::" << fcn << " \n";
28  }
29 }
30 
31 namespace evd {
32 
33  //----------------------------------------------------------------------------
35  {
36  starthitout.resize(3);
37  endhitout.resize(3);
38  }
39 
40  //......................................................................
48  //
50  std::vector<util::PxLine> seedlines,
51  double distance)
52  {
56  std::map<int, std::vector<art::Ptr<recob::Hit>>> hits_to_save;
57 
58  double KineticEnergy = 0;
60 
61  for (size_t imod = 0; imod < recoOpt->fHitLabels.size(); ++imod) {
62  art::InputTag const which = recoOpt->fHitLabels[imod];
63  evt.getByLabel(which, HitListHandle);
64  }
65 
66  infot->SetSeedList(seedlines);
67  for (std::map<int, std::vector<art::Ptr<recob::Hit>>>::iterator it = hits_to_save.begin();
68  it != hits_to_save.end();
69  ++it) {
70  infot->SetHitList(it->first, it->second);
71  }
72  infot->SetTestFlag(1);
73  infot->SetEvtNumber(evt.id().event());
74 
75  return KineticEnergy;
76  }
77 
78  //......................................................................
87  unsigned int plane,
88  double xin,
89  double yin,
90  double x1in,
91  double y1in,
92  double distance,
93  bool good_plane)
94  {
97  auto const& wireReadoutGeom = art::ServiceHandle<geo::WireReadout const>()->Get();
98  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
99  auto const detProp =
101  util::GeometryUtilities const gser{*geo, wireReadoutGeom, clockData, detProp};
102  std::vector<art::Ptr<recob::Hit>> hits_to_save;
103 
105 
106  starthitout[plane].clear();
107  endhitout[plane].clear();
108 
109  starthitout[plane].resize(2);
110  endhitout[plane].resize(2);
111 
112  //convert input variables to cm-cm space required by GeometryUtilities
113  double x = xin * gser.WireToCm();
114  double x1 = x1in * gser.WireToCm();
115  double y = yin * gser.TimeToCm();
116  double y1 = y1in * gser.TimeToCm();
117 
118  double lslope = 0;
119 
120  if ((x - x1) != 0) lslope = (y - y1) / (x - x1);
121 
122  for (size_t imod = 0; imod < recoOpt->fHitLabels.size(); ++imod) {
123  art::InputTag const which = recoOpt->fHitLabels[imod];
124 
125  std::vector<art::Ptr<recob::Hit>> hitlist;
126  hitlist.clear();
127  evt.getByLabel(which, HitListHandle);
128 
129  for (unsigned int ii = 0; ii < HitListHandle->size(); ++ii) {
130  art::Ptr<recob::Hit> hit(HitListHandle, ii);
131  if (hit->WireID().Plane == plane) hitlist.push_back(hit);
132  }
133 
134  // Select Local Hit List
135  util::PxHitConverter PxC{gser};
136  std::vector<util::PxHit> pxhitlist;
137  PxC.GeneratePxHit(hitlist, pxhitlist);
138  std::vector<unsigned int> pxhitlist_local_index;
139  std::vector<util::PxHit> pxhitlist_local;
140  pxhitlist_local.clear();
141 
142  util::PxPoint startHit;
143  startHit.plane = pxhitlist.at(0).plane;
144  startHit.w = (x + x1) / 2;
145  startHit.t = (y + y1) / 2;
146 
147  double orttemp = std::hypot(y1 - y, x1 - x) / 2;
148 
149  gser.SelectLocalHitlistIndex(
150  pxhitlist, pxhitlist_local_index, startHit, orttemp, distance, lslope);
151 
152  for (unsigned int idx = 0; idx < pxhitlist_local_index.size(); idx++) {
153  hits_to_save.push_back(hitlist.at(pxhitlist_local_index.at(idx)));
154  pxhitlist_local.push_back(pxhitlist.at(pxhitlist_local_index.at(idx)));
155  }
156 
157  auto const hit_index = gser.FindClosestHitIndex(pxhitlist_local, x, y);
158  recob::Hit const& hit = *hits_to_save[hit_index];
159  starthitout[plane][1] = hit.PeakTime();
160  starthitout[plane][0] = hit.WireID().Wire;
161 
162  recob::Hit const& endhit =
163  hit; // this obviously not correct, the fact that x,y are used for both start and end point, A.S. -> to debug
164  endhitout[plane][1] = endhit.PeakTime();
165  endhitout[plane][0] = endhit.WireID().Wire;
166  }
167 
169  infot->SetHitList(plane, hits_to_save);
170  infot->SetTestFlag(1);
171  if (good_plane) {
172  infot->SetStartHitCoords(plane, starthitout[plane]);
173  infot->SetEndHitCoords(plane, endhitout[plane]);
174  }
175  infot->SetEvtNumber(evt.id().event());
176  }
177 
178  //......................................................................
186  void HitSelector::ChangeHit(const art::Event& evt, unsigned int plane, double xin, double yin)
187  {
190  auto const& wireReadoutGeom = art::ServiceHandle<geo::WireReadout const>()->Get();
191  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
192  auto const detProp =
194  util::GeometryUtilities const gser{*geo, wireReadoutGeom, clockData, detProp};
195 
196  //get hits from info transfer, see if our selected hit is in it
197  std::vector<art::Ptr<recob::Hit>> hits_saved;
198  std::vector<art::Ptr<recob::Hit>> hitlist;
199 
200  double x = xin * gser.WireToCm();
201  double y = yin * gser.TimeToCm();
202 
204 
205  for (size_t imod = 0; imod < recoOpt->fHitLabels.size(); ++imod) {
206  art::InputTag const which = recoOpt->fHitLabels[imod];
207  evt.getByLabel(which, HitListHandle);
208 
209  for (unsigned int ii = 0; ii < HitListHandle->size(); ++ii) {
210  art::Ptr<recob::Hit> hit(HitListHandle, ii);
211  if (hit->WireID().Plane == plane) hitlist.push_back(hit);
212  }
213 
214  util::PxHitConverter PxC{gser};
215  std::vector<util::PxHit> pxhitlist;
216  PxC.GeneratePxHit(hitlist, pxhitlist);
217 
218  unsigned int hitindex = gser.FindClosestHitIndex(pxhitlist, x, y);
219  if (hitlist[hitindex].isNull() || (hitindex > hitlist.size())) {
220  WriteMsg("no luck finding hit in evd, please try again");
221  break;
222  }
223 
225  hits_saved = infot->GetSelectedHitList(plane);
226  int found_it = 0;
227  for (unsigned int jj = 0; jj < hits_saved.size(); ++jj) {
228  if (hitlist[hitindex]->PeakTime() == hits_saved[jj]->PeakTime()) {
229  if (hitlist[hitindex]->Channel() == hits_saved[jj]->Channel()) {
230  found_it = 1;
231  hits_saved.erase(hits_saved.begin() + jj);
232  }
233  }
234  }
235 
236  //if didn't find it, add it
237  if (found_it != 1) { hits_saved.push_back(hitlist[hitindex]); }
238 
239  //update the info transfer list
240  infot->SetHitList(plane, hits_saved);
241  infot->SetTestFlag(1);
242  infot->SetEvtNumber(evt.id().event());
243  }
244  }
245 
246  //......................................................................
254  std::vector<art::Ptr<recob::Hit>> HitSelector::GetSelectedHitPtrs(unsigned int plane)
255  {
257  return infot->GetSelectedHitList(plane);
258  }
259 
260  std::vector<const recob::Hit*> HitSelector::GetSelectedHits(unsigned int plane)
261  {
262  std::vector<art::Ptr<recob::Hit>> hits_saved;
263  std::vector<const recob::Hit*> hits_to_draw; //draw selected hits in a different color
264 
266  hits_saved = infot->GetSelectedHitList(plane);
267 
268  for (unsigned int i = 0; i < hits_saved.size(); i++)
269  hits_to_draw.push_back(hits_saved[i].get());
270 
271  return hits_to_draw;
272  }
273 
274  //......................................................................
275  void HitSelector::ClearHitList(unsigned int plane)
276  {
278  infot->ClearSelectedHitList(plane);
279  }
280 
281  //----------------------------------------------------------------------------
282  std::vector<recob::Seed>& HitSelector::SeedVector()
283  {
284  return fSeedVector;
285  }
286 
287 } //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:86
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
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:430
geo::WireID const & WireID() const
Initial tdc tick for hit.
Definition: Hit.h:290
void SetStartHitCoords(unsigned int plane, std::vector< double > starthitin)
Definition: InfoTransfer.h:112
std::vector< std::vector< double > > starthitout
Definition: HitSelector.h:55
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:373
std::vector< recob::Seed > fSeedVector
Definition: HitSelector.h:53
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:226
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:49
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:56
ROOT libraries.
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()