LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
DirOfGamma.cxx
Go to the documentation of this file.
1 #include "DirOfGamma.h"
2 
5 
11 #include "larcore/CoreUtils/ServiceUtil.h" // lar::providerFrom<>()
12 
14 
15 #include "TMath.h"
16 
17 //class Hit2D
18 
20 fHit(src)
21 {
22  geo::GeometryCore const* geom = lar::providerFrom<geo::Geometry>();
23  detinfo::DetectorProperties const* detprop
24  = lar::providerFrom<detinfo::DetectorPropertiesService>();
25 
26  unsigned int plane = src->WireID().Plane;
27  unsigned int tpc = src->WireID().TPC;
28  unsigned int cryo = src->WireID().Cryostat;
29 
30  double wireCentre[3];
31  geom->WireIDToWireGeo(src->WireID()).GetCenter(wireCentre);
32  double x = detprop->ConvertTicksToX(src->PeakTime(), plane, tpc, cryo);
33  double globalWire;
34 
35  if (tpc % 2 == 0)
36  {
37  globalWire = geom->WireCoordinate(wireCentre[1], wireCentre[2], plane, 0, cryo);
38  fPoint.Set(globalWire, x);
39  }
40  else
41  {
42  globalWire = geom->WireCoordinate(wireCentre[1], wireCentre[2], plane, 1, cryo);
43  fPoint.Set(globalWire, x);
44  }
45  fCharge = src->SummedADC();
46 }
47 
48 ems::Bin2D::Bin2D(const TVector2 & center) :
49 fCenter2D(center),
50 fTotCharge(0.0),
51 fSize(0)
52 {
53 }
54 
56 {
57  fHits2D.push_back(hit);
58  fTotCharge += hit->GetCharge();
59  fSize = fHits2D.size();
60  SortLess();
61 }
62 
64 {
65  return std::sort(fHits2D.begin(), fHits2D.end(), bDistCentMore2D(fCenter2D));
66 }
67 
69 {
70  return std::sort(fHits2D.begin(), fHits2D.end(), bDistCentLess2D(fCenter2D));
71 }
72 
73 std::vector< art::Ptr< recob::Hit > > ems::Bin2D::GetIniHits(const double radius, const unsigned int nhits) const
74 {
75 
76  std::vector< art::Ptr< recob::Hit > > vec;
77  for (unsigned int i = 0; i < fHits2D.size(); i++)
78  {
79  if (pma::Dist2(fHits2D[i]->GetPointCm(), fCenter2D) < radius*radius)
80  {
81  vec.push_back(fHits2D[i]->GetHitPtr());
82  if (vec.size() == nhits) break;
83  }
84  }
85 
86  return vec;
87 }
88 
89 ems::EndPoint::EndPoint(const Hit2D & center, const std::vector< Hit2D* > & hits, unsigned int nbins) :
90 fCenter2D(center),
91 fPoints2D(hits),
92 fNbins(nbins)
93 {
94 
95  for (unsigned int i = 0; i < fNbins; i++)
96  {
97  fBins.push_back(Bin2D(center.GetPointCm()));
98  }
99 
100  FillBins();
103 
104  fPlane = center.GetHitPtr()->WireID().Plane;
105  fTpc = center.GetHitPtr()->WireID().TPC;
106  fCryo = center.GetHitPtr()->WireID().Cryostat;
107 }
108 
110 {
111  TVector2 vstart(0, 1);
112 
113  unsigned int saveid = 0; bool exist = false;
114  for (unsigned int i = 0; i < fPoints2D.size(); i++)
115  {
116  if (fPoints2D[i]->GetHitPtr().key() != fCenter2D.GetHitPtr().key())
117  {
118  TVector2 pos(fPoints2D[i]->GetPointCm());
119  TVector2 centre(fCenter2D.GetPointCm());
120  TVector2 vecp = pos - centre;
121  float sinsign = (vstart.X() * vecp.Y()) - (vstart.Y() * vecp.X());
122  float cosine = (vstart * vecp) / vecp.Mod();
123  float theta = 180.0F * (std::acos(cosine)) / TMath::Pi();
124 
125  unsigned int id = 0; double bin = double(360.0) / double(fNbins);
126 
127  if (sinsign >= 0) id = int (theta / bin);
128  else if (sinsign < 0) id = int (theta / bin) + (fNbins / 2);
129  if (id > (fNbins - 1)) id = (fNbins - 1);
130 
131  fBins[id].Add(fPoints2D[i]);
132  fBins[(id + 1) % fNbins].Add(fPoints2D[i]);
133  }
134  else {saveid = i; exist = true;}
135  }
136 
137  if (exist)
138  for (unsigned int id = 0; id < fNbins; id++) fBins[id].Add(fPoints2D[saveid]);
139 }
140 
142 {
143  fMaxCharge = 0.0;
144  unsigned int saveid = 0;
145  for (unsigned int i = 0; i < fNbins; i++)
146  if (fBins[i].Size() && (fMaxCharge < fBins[i].GetTotCharge()))
147  {
148  fMaxCharge = fBins[i].GetTotCharge();
149  saveid = i;
150  }
151 
152  fMaxChargeIdBin = saveid;
153 }
154 
156 {
157  fMeanCharge = 0.0;
158  if (fNbins == 0) return;
159 
160  unsigned int iprev, inext;
161 
162  if (fMaxChargeIdBin > 0) iprev = fMaxChargeIdBin - 1;
163  else iprev = fNbins - 1;
164 
165  inext = (fMaxChargeIdBin + 1) % fNbins;
166 
167  double sumcharge = 0.0;
168  for (unsigned int i = 0; i < fNbins; i++)
169  if ((i!=fMaxChargeIdBin) && (i!=iprev) && (i!=inext)) sumcharge += fBins[i].GetTotCharge();
170 
171  fMeanCharge = sumcharge / double (fNbins);
172 }
173 
175 {
176  if ((fMaxCharge + fMeanCharge) == 0) return 0.0;
177  else return ((fMaxCharge - fMeanCharge) / (fMaxCharge + fMeanCharge));
178 }
179 
180 ems::DirOfGamma::DirOfGamma(const std::vector< art::Ptr< recob::Hit > > & src, unsigned int nbins, unsigned int idcl) :
181 fNbins(nbins),
182 fIdCl(idcl),
183 fCandidateID(0),
184 fIsCandidateIDset(false)
185 {
186  fHits = src;
187 
188  for (unsigned int i = 0; i < src.size(); i++)
189  {
190  Hit2D* hit = new Hit2D(src[i]);
191  fPoints2D.push_back(hit);
192  }
193 
195 
196  for (unsigned int i = 0; i < fNbins; i++)
197  fBins.push_back(Bin2D(fBaryCenter));
198 
199  FillBins();
200  ComputeMaxDist();
201  if (FindCandidates())
202  {
204  FindInitialPart();
205  }
206 }
207 
209 {
210  double nomx = 0.0; double nomy = 0.0;
211  double denom = 0.0;
212  for (unsigned int i = 0; i < fPoints2D.size(); i++)
213  {
214  nomx += fPoints2D[i]->GetPointCm().X() * fPoints2D[i]->GetCharge();
215  nomy += fPoints2D[i]->GetPointCm().Y() * fPoints2D[i]->GetCharge();
216  denom += fPoints2D[i]->GetCharge();
217  }
218 
219  double bx = nomx / denom; double by = nomy / denom;
220  fBaryCenter.Set(bx, by);
221 }
222 
224 {
225  TVector2 vstart(0, 1);
226 
227  for (unsigned int i = 0; i < fPoints2D.size(); i++)
228  {
229  TVector2 pos(fPoints2D[i]->GetPointCm().X(), fPoints2D[i]->GetPointCm().Y());
230  TVector2 vecp = pos - fBaryCenter;
231  float sinsign = (vstart.X() * vecp.Y()) - (vstart.Y() * vecp.X());
232  float cosine = (vstart * vecp) / (vstart.Mod() * vecp.Mod());
233  float theta = 180.0F * (std::acos(cosine)) / TMath::Pi();
234 
235  unsigned int id = 0; double bin = double(360.0) / double(fNbins);
236 
237  if (sinsign >= 0) id = int (theta / bin);
238  else if (sinsign < 0) id = int (theta / bin) + (fNbins/2);
239  if (id > (fNbins - 1)) id = (fNbins - 1);
240 
241  fBins[id].Add(fPoints2D[i]);
242  }
243 
244  for (unsigned int id = 0; id < fBins.size(); id++) fBins[id].Sort();
245 
246 }
247 
249 {
250  double maxdist2 = 0.0;
251 
252  for (unsigned int id = 0; id < fBins.size(); id++)
253  {
254 
255  if (!fBins[id].Size()) continue;
256 
257  Hit2D* candidate = fBins[id].GetHits2D().front();
258  if (candidate)
259  {
260  double dist2 = pma::Dist2(candidate->GetPointCm(), fBaryCenter);
261  if (dist2 > maxdist2)
262  {
263  maxdist2 = dist2;
264  }
265  }
266  }
267 
268  fNormDist = std::sqrt(maxdist2);
269 }
270 
272 {
273  float rad = 0.5F * fNormDist; unsigned int nbins = fNbins * 4;
274  for (unsigned int id = 0; id < fNbins; id++)
275  {
276 
277  if (!fBins[id].Size()) continue;
278 
279  std::vector< Hit2D* > points;
280  Hit2D* candidate2D = fBins[id].GetHits2D().front();
281 
282  for (unsigned int i = 0; i < fPoints2D.size(); i++)
283  {
284  double distnorm = std::sqrt(pma::Dist2(candidate2D->GetPointCm(), fBaryCenter)) / fNormDist;
285  double dist2 = pma::Dist2(candidate2D->GetPointCm(), fPoints2D[i]->GetPointCm());
286 
287  if ((distnorm > 0.5) && (dist2 < rad*rad)) points.push_back(fPoints2D[i]);
288  }
289 
290 
291  if (fBins[id].Size() > 1)
292  {
293  EndPoint ep(*candidate2D, points, nbins);
294  fCandidates.push_back(ep);
295  }
296  }
297  if (fCandidates.size()) return true;
298  else return false;
299 }
300 
302 {
303  fNormCharge = 0.0;
304  for (unsigned int i = 0; i < fCandidates.size(); i++)
305  {
306  if (fCandidates[i].GetMaxCharge() > fNormCharge)
307  {
308  fNormCharge = fCandidates[i].GetMaxCharge();
309  }
310  }
311 }
312 
314 {
315  double max_asymmetry = 0.0;
316  unsigned int saveid = 0; bool found = false;
317 
318  double maxdist2 = 0.0; double maxcharge = 0.0;
319  unsigned int idmaxdist = 0; unsigned int idmaxcharge = 0;
320 
321  for (unsigned int i = 0; i < fCandidates.size(); i++)
322  {
323  double dist2 = pma::Dist2(fCandidates[i].GetPosition(), fBaryCenter);
324  double charge = fCandidates[i].GetMaxCharge();
325  if (dist2 > maxdist2) { maxdist2 = dist2; idmaxdist = i;}
326  if (charge > maxcharge) { maxcharge = charge; idmaxcharge = i;}
327  }
328 
329  maxdist2 = 0.0; unsigned int idmaxdistb = 0;
330  for (size_t i = 0; i < fCandidates.size(); i++)
331  {
332  if ((i == idmaxdist) || (i == idmaxcharge)) continue;
333 
334  double dist2 = pma::Dist2(fCandidates[i].GetPosition(), fCandidates[idmaxdist].GetPosition());
335  if (dist2 > maxdist2) { maxdist2 = dist2; idmaxdistb = i;}
336  }
337 
338  if (fCandidates.size() > 2)
339  {
340  for (unsigned int i = 0; i < fCandidates.size(); i++)
341  {
342  double asymmetry = fCandidates[i].GetAsymmetry();
343 
344  if ((i == idmaxdist) || (i == idmaxcharge) || (i == idmaxdistb))
345  {
346  if (asymmetry > max_asymmetry)
347  {
348  max_asymmetry = asymmetry;
349  saveid = i; found = true;
350  }
351  }
352  }
353  }
354  else
355  {
356  for (unsigned int i = 0; i < fCandidates.size(); i++)
357  {
358  double asymmetry = fCandidates[i].GetAsymmetry();
359 
360  if ((i == idmaxdist) || (i == idmaxdistb))
361  {
362  if (asymmetry > max_asymmetry)
363  {
364  max_asymmetry = asymmetry;
365  saveid = i; found = true;
366  }
367  }
368  }
369  }
370 
371  if (!found) mf::LogError("DirOfGamma") << fCandidates.size() << "DirOfGamma - Find Initial Part problem.";
372 
373  fStartHit = fCandidates[saveid].GetHit();
374  fStartPoint = fCandidates[saveid].GetPosition();
375  fIniHits = fCandidates[saveid].MaxChargeBin().GetIniHits();
376  fCandidateID = saveid;
377 
378 }
379 
380 
381 
382 
383 
384 
385 
Float_t x
Definition: compare.C:6
key_type key() const
Definition: Ptr.h:356
geo::Length_t WireCoordinate(double YPos, double ZPos, geo::PlaneID const &planeid) const
Returns the index of the nearest wire to the specified position.
void SortLess()
Definition: DirOfGamma.cxx:68
TVector2 fPoint
Definition: DirOfGamma.h:41
std::vector< Hit2D * > fPoints2D
Definition: DirOfGamma.h:155
Utilities related to art service access.
DirOfGamma(const std::vector< art::Ptr< recob::Hit > > &src, unsigned int nbins, unsigned int idcl)
Definition: DirOfGamma.cxx:180
art::Ptr< recob::Hit > const & GetHitPtr(void) const
Definition: DirOfGamma.h:36
double Dist2(const TVector2 &v1, const TVector2 &v2)
Definition: Utilities.cxx:19
void FillBins(void)
Definition: DirOfGamma.cxx:223
void Add(Hit2D *hit)
Definition: DirOfGamma.cxx:55
geo::WireID WireID() const
Initial tdc tick for hit.
Definition: Hit.h:234
Float_t Y
Definition: plot.C:39
void ComputeMaxCharge(void)
Definition: DirOfGamma.cxx:301
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:130
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
void FindInitialPart(void)
Definition: DirOfGamma.cxx:313
void ComputeMaxCharge()
Definition: DirOfGamma.cxx:141
std::vector< Bin2D > fBins
Definition: DirOfGamma.h:156
TVector2 fBaryCenter
Definition: DirOfGamma.h:174
size_t fNbins
Definition: DirOfGamma.h:100
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
std::vector< art::Ptr< recob::Hit > > fIniHits
Definition: DirOfGamma.h:161
Hit2D fCenter2D
Definition: DirOfGamma.h:98
void ComputeBaryCenter(void)
Definition: DirOfGamma.cxx:208
unsigned int fSize
Definition: DirOfGamma.h:71
void hits()
Definition: readHits.C:15
std::vector< Hit2D * > fPoints2D
Definition: DirOfGamma.h:99
const TVector2 & fCenter2D
Definition: DirOfGamma.h:68
double fTotCharge
Definition: DirOfGamma.h:70
std::vector< Bin2D > fBins
Definition: DirOfGamma.h:105
EndPoint(const Hit2D &center, const std::vector< Hit2D * > &hits, unsigned int nbins)
Definition: DirOfGamma.cxx:89
Implementation of the Projection Matching Algorithm.
Double_t radius
size_t fPlane
Definition: DirOfGamma.h:113
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:258
Description of geometry of one entire detector.
float bin[41]
Definition: plottest35.C:14
std::vector< art::Ptr< recob::Hit > > GetIniHits(const double radius=10.0, const unsigned int nhits=10) const
Definition: DirOfGamma.cxx:73
Detector simulation of raw signals on wires.
Encapsulate the geometry of a wire.
size_t fMaxChargeIdBin
Definition: DirOfGamma.h:107
TVector2 const & GetPointCm(void) const
Definition: DirOfGamma.h:33
bool FindCandidates(void)
Definition: DirOfGamma.cxx:271
double fCharge
Definition: DirOfGamma.h:39
double GetCharge(void) const
Definition: DirOfGamma.h:34
Implementation of the Projection Matching Algorithm.
float PeakTime() const
Time of the signal peak, in tick units.
Definition: Hit.h:219
size_t fCandidateID
Definition: DirOfGamma.h:153
void ComputeMaxDist(void)
Definition: DirOfGamma.cxx:248
Encapsulate the construction of a single detector plane.
TVector2 fStartPoint
Definition: DirOfGamma.h:160
void Sort()
Definition: DirOfGamma.cxx:63
std::vector< Hit2D * > fHits2D
Definition: DirOfGamma.h:69
float SummedADC() const
The sum of calibrated ADC counts of the hit (0. by default)
Definition: Hit.h:224
double fMeanCharge
Definition: DirOfGamma.h:103
void ComputeMeanCharge()
Definition: DirOfGamma.cxx:155
double fMaxCharge
Definition: DirOfGamma.h:102
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:203
double GetAsymmetry(void) const
Definition: DirOfGamma.cxx:174
Float_t X
Definition: plot.C:39
std::vector< art::Ptr< recob::Hit > > fHits
Definition: DirOfGamma.h:162
art framework interface to geometry description
art::Ptr< recob::Hit > fStartHit
Definition: DirOfGamma.h:159
Encapsulate the construction of a single detector plane.
std::vector< EndPoint > fCandidates
Definition: DirOfGamma.h:157
size_t fCryo
Definition: DirOfGamma.h:115
WireGeo const & WireIDToWireGeo(geo::WireID const &wireid) const
Returns the specified wire.
Bin2D(const TVector2 &center)
Definition: DirOfGamma.cxx:48
Hit2D(art::Ptr< recob::Hit > src)
Definition: DirOfGamma.cxx:19