CaloHit.cxx
Go to the documentation of this file.
1 //
2 // Hit.cxx
3 //
4 // Created by Brian Rebel on 10/6/16.
5 //
7 #include "CoreUtils/ServiceUtil.h"
8 
10 
11 namespace gar {
12  namespace rec {
13 
14  //--------------------------------------------------------------------------
16  : fEnergy(0.),
17  fCellID(0.),
18  fLayer(0.)
19  {
22 
23  fPosition[0] = 0.;
24  fPosition[1] = 0.;
25  fPosition[2] = 0.;
26 
27  fTime = std::make_pair(0., 0.);
28 
29  return;
30  }
31 
32  bool CaloHit::operator==(const CaloHit& rhs) const {
33  return (this->fIDnumero == rhs.fIDnumero);
34  }
35 
36  bool CaloHit::operator!=(const CaloHit& rhs) const {
37  return (this->fIDnumero != rhs.fIDnumero);
38  }
39 
41 
42 
43  //--------------------------------------------------------------------------
44  CaloHit::CaloHit(float energy, float time, float *pos, raw::CellID_t cellID, unsigned int layer)
45  : fEnergy (energy )
46  , fCellID (cellID )
47  , fLayer (layer )
48  {
51 
52  fPosition[0] = pos[0];
53  fPosition[1] = pos[1];
54  fPosition[2] = pos[2];
55 
56  fTime = std::make_pair(time, 0.);
57 
58  return;
59  }
60 
61  //--------------------------------------------------------------------------
62  CaloHit::CaloHit(float energy, std::pair<float, float> time, float *pos, raw::CellID_t cellID, unsigned int layer)
63  : fEnergy (energy )
64  , fTime (time )
65  , fCellID (cellID )
66  , fLayer (layer )
67  {
70 
71  fPosition[0] = pos[0];
72  fPosition[1] = pos[1];
73  fPosition[2] = pos[2];
74 
75  return;
76  }
77 
78  //--------------------------------------------------------------------------
79  bool CaloHit::operator< (const CaloHit &rhs) const
80  {
81  const TVector3 rhsPos(rhs.Position()[0], rhs.Position()[1], rhs.Position()[2]);
82  const TVector3 thisPos(this->Position()[0], this->Position()[1], this->Position()[2]);
83  const TVector3 deltaPosition(rhsPos - thisPos);
84 
85  if (std::fabs(deltaPosition.z()) > std::numeric_limits<float>::epsilon())
86  return (deltaPosition.z() > std::numeric_limits<float>::epsilon());
87 
88  if (std::fabs(deltaPosition.x()) > std::numeric_limits<float>::epsilon())
89  return (deltaPosition.x() > std::numeric_limits<float>::epsilon());
90 
91  if (std::fabs(deltaPosition.y()) > std::numeric_limits<float>::epsilon())
92  return (deltaPosition.y() > std::numeric_limits<float>::epsilon());
93 
94  return (this->Energy() > rhs.Energy());
95  }
96 
97  //--------------------------------------------------------------------------
98  std::ostream& operator<< (std::ostream& o, gar::rec::CaloHit const& h)
99  {
100 
101  o << "CaloHit "
102  << "\n\tID number = "
103  << h.getIDNumber()
104  << "\n\tposition = ("
105  << h.Position()[0]
106  << ", "
107  << h.Position()[1]
108  << ", "
109  << h.Position()[2]
110  << ")"
111  << "\n\tenergy = "
112  << h.Energy()
113  << "\n\t time: "
114  << h.Time().first << " " << h.Time().second
115  << " cellID: "
116  << h.CellID();
117 
118  return o;
119  }
120 
121  //--------------------------------------------------------------------------
122  unsigned int CaloHit::GetCellLengthScale() const
123  {
124  std::array<double, 3> point = {this->Position()[0], this->Position()[1], this->Position()[2]};
125  if(gar::providerFrom<geo::GeometryGAr>()->isTile(point, this->CellID()))
126  {
127  return std::sqrt( gar::providerFrom<geo::GeometryGAr>()->getTileSize(point) * gar::providerFrom<geo::GeometryGAr>()->getTileSize(point) );
128  }
129  else
130  {
131  return std::sqrt( gar::providerFrom<geo::GeometryGAr>()->getStripWidth(point) * gar::providerFrom<geo::GeometryGAr>()->getStripLength(point, this->CellID()) );
132  }
133  }
134 
135  } // rec
136 } // gar
float fPosition[3]
position of the calo hit in cm
Definition: CaloHit.h:37
rec
Definition: tracks.py:88
unsigned int fLayer
Layer.
Definition: CaloHit.h:40
raw::CellID_t CellID() const
Definition: CaloHit.h:72
bool operator<(const CaloHit &rhs) const
Definition: CaloHit.cxx:79
raw::CellID_t fCellID
cellID
Definition: CaloHit.h:39
std::pair< float, float > Time() const
Definition: CaloHit.h:71
bool operator!=(const CaloHit &rhs) const
Definition: CaloHit.cxx:36
unsigned int GetCellLengthScale() const
Definition: CaloHit.cxx:122
static IDNumberGen * create(IDNumber iniValue=std::numeric_limits< IDNumber >::max())
Definition: IDNumberGen.cxx:18
gar::rec::IDNumber getIDNumber() const
Definition: CaloHit.cxx:40
float fEnergy
energy of the calo hit in GeV
Definition: CaloHit.h:36
float Energy() const
Definition: CaloHit.h:69
long long int CellID_t
Definition: CaloRawDigit.h:24
General GArSoft Utilities.
const float * Position() const
Definition: CaloHit.h:70
std::pair< float, float > fTime
time of the calo hit in ns
Definition: CaloHit.h:38
bool operator==(const CaloHit &rhs) const
Definition: CaloHit.cxx:32
gar::rec::IDNumber fIDnumero
Definition: CaloHit.h:33
static gar::rec::IDNumber const FirstNumber
Definition: CaloHit.h:32
size_t IDNumber
Definition: IDNumberGen.h:71
friend std::ostream & operator<<(std::ostream &o, gar::rec::CaloHit const &h)
Definition: CaloHit.cxx:98