Hit.cxx
Go to the documentation of this file.
1 //
2 // Hit.cxx
3 //
4 // Created by Brian Rebel on 10/6/16.
5 //
7 
9 #include "TMath.h"
10 
11 namespace gar {
12  namespace rec {
13 
14  //--------------------------------------------------------------------------
16  {
17  return;
18  }
19 
20  //--------------------------------------------------------------------------
21  Hit::Hit(unsigned int chan,
22  float sig,
23  float *pos,
24  float startT,
25  float endT,
26  float Time,
27  float RMS)
28  : fChannel (chan )
29  , fSignal (sig )
30  , fTime (Time )
31  , fStartTime(startT)
32  , fEndTime (endT )
33  , fRMS (RMS )
34  {
35 
36  fPosition[0] = pos[0];
37  fPosition[1] = pos[1];
38  fPosition[2] = pos[2];
39 
40  return;
41  }
42 
43  //--------------------------------------------------------------------------
44  // Users should be careful with this method. It will just add hits from the
45  // same channel without checking if the hits are overlapping in time or close
46  // to each other in time
48  {
49  // only add hits on the same channel
50  if(fChannel != h.Channel()){
51  MF_LOG_WARNING("Hit")
52  << "attempting to add hits from different channels, that will not work";
53  return;
54  }
55 
56  // add h to this hit. Set the new position, etc to be the weighted
57  // average of the individual hits
58  float totSig = fSignal + h.Signal();
59 
60  if(totSig == 0.){
61  MF_LOG_WARNING("Hit")
62  << "attempting to add two hits and neithr has any signal, bail.";
63  return;
64  }
65 
66  for(size_t i = 0; i < 3; ++i)
67  fPosition[i] = (fPosition[i] * fSignal + h.Position()[i] * h.Signal()) / totSig;
68 
69  // don't do a weighted average but just make a wider hit
70 
71  //fStartTime = (fStartTime * fSignal + h.StartTime() * h.Signal()) / totSig;
72  //fEndTime = (fEndTime * fSignal + h.EndTime() * h.Signal()) / totSig;
73 
74  fStartTime = TMath::Min(fStartTime,h.StartTime());
75  fEndTime = TMath::Max(fEndTime,h.EndTime());
76 
77  float avgtime = (fTime * fSignal + h.Time() * h.Signal()) / totSig;
78 
79  fRMS = TMath::Sqrt( (fSignal*(TMath::Sq(fTime-avgtime)+TMath::Sq(fRMS))
80  + h.Signal()*(TMath::Sq(h.Time()-avgtime)+TMath::Sq(h.RMS())))/totSig );
81 
82  fTime = avgtime;
83 
84  fSignal += h.Signal();
85 
86  return;
87  }
88 
89  //--------------------------------------------------------------------------
90  // Sometimes one must sort Hits
91  bool Hit::operator < (gar::rec::Hit const& h) const
92  {
93  if (Channel() < h.Channel() ) return true;
94  if (Channel() > h.Channel() ) return false;
95  if (StartTime() < h.StartTime()) return true;
96  if (StartTime() > h.StartTime()) return false;
97  if (EndTime() < h.EndTime() ) return true;
98  if (EndTime() > h.EndTime() ) return false;
99  // I dunno wot den
100  //return true; //original
101  return false;
102 
103  }
104 
105  //--------------------------------------------------------------------------
106  bool Hit::operator == (gar::rec::Hit const& h) const
107  {
108  //if(Position()!=h.Position())
109  // return false;
110  if(Channel()!=h.Channel())
111  return false;
112  //if(Signal()!=h.Signal())
113  // return false;
114  if(StartTime()!=h.StartTime())
115  return false;
116  if(EndTime()!=h.EndTime())
117  return false;
118  //if(RMS()!=h.RMS())
119  // return false;
120  //if(Time()!=h.Time())
121  // return false;
122 
123  return true;
124 
125  }
126 
127  //--------------------------------------------------------------------------
128  std::ostream& operator<< (std::ostream& o, gar::rec::Hit const& h)
129  {
130 
131  o << "Hit on channel "
132  << h.Channel()
133  << "\n\tposition = ("
134  << h.Position()[0]
135  << ", "
136  << h.Position()[1]
137  << ", "
138  << h.Position()[2]
139  << ")"
140  << "\n\tsignal = "
141  << h.Signal()
142  << "\n\tstart time: "
143  << h.StartTime()
144  << " end time: "
145  << h.EndTime();
146 
147  return o;
148  }
149 
150  } // rec
151 } // gar
float fPosition[3]
position of the hit
Definition: Hit.h:26
rec
Definition: tracks.py:88
float StartTime() const
Definition: Hit.h:67
friend std::ostream & operator<<(std::ostream &o, gar::rec::Hit const &h)
Definition: Hit.cxx:128
const float * Position() const
Definition: Hit.h:65
bool operator==(gar::rec::Hit const &h) const
Definition: Hit.cxx:106
float EndTime() const
Definition: Hit.h:68
bool operator<(gar::rec::Hit const &h) const
Definition: Hit.cxx:91
float fStartTime
start time of the hit (ticks)
Definition: Hit.h:28
void operator+=(gar::rec::Hit const &h)
Definition: Hit.cxx:47
float fRMS
Hit width calculated with RMS (in ticks)
Definition: Hit.h:30
General GArSoft Utilities.
unsigned int Channel() const
Definition: Hit.h:64
float Time() const
Definition: Hit.h:70
float fSignal
size of the signal for this hit (integral of ADC values)
Definition: Hit.h:25
unsigned int fChannel
channel recording this hit
Definition: Hit.h:24
#define MF_LOG_WARNING(category)
float const & Signal() const
Definition: Hit.h:66
float fEndTime
end time of the hit (ticks)
Definition: Hit.h:29
float fTime
time of hit charge arrival at the readout plane (ticks)
Definition: Hit.h:27
float RMS() const
Definition: Hit.h:69