ATLAS Offline Software
CalibrationHit.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // CalibrationHit.h
6 // Definition of a calibration hit in the LArG4 simulation.
7 // 08-Jan-2004 Bill Seligman
8 
9 // Note: A calibration hit has to record a few different types of
10 // energies. As far as the code below is concerned, the
11 // LArG4::CalibrationHit does not know what these energies are. That
12 // is, there are four energy fields, and maybe the first one is E-M
13 // energy, the second is hadronic energy, etc., but that's irrelevant
14 // to this code. It's other routines that have to interpret the
15 // meaning of these fields.
16 
17 #ifndef LArG4_CalibrationHit_H
18 #define LArG4_CalibrationHit_H
19 
21 
22 #include "G4VHit.hh"
23 #include "G4THitsCollection.hh"
24 #include "G4Allocator.hh"
25 
26 namespace LArG4 {
27 
28  class CalibrationHit : public G4VHit
29  {
30  public:
31 
32  // Constructors and destructors. Note that since hits get created
33  // and destroyed all the time, I've inlined everything that I can.
34 
37  m_energy0(0.) ,
38  m_energy1(0.) ,
39  m_energy2(0.) ,
40  m_energy3(0.)
41  {}
42 
44  G4double energy0 = 0.,
45  G4double energy1 = 0.,
46  G4double energy2 = 0.,
47  G4double energy3 = 0.) :
49  m_energy0(energy0) ,
50  m_energy1(energy1) ,
51  m_energy2(energy2) ,
52  m_energy3(energy3)
53  {}
54 
55  virtual ~CalibrationHit() {;}
56 
57  inline void* operator new(size_t);
58  inline void operator delete(void *aHit);
59 
60  // These two methods are never called in LArG4; there's no point
61  // in making them inline.
62 
63  virtual void Draw();
64  virtual void Print();
65 
66  private:
67 
69 
70  // Implementation note: we don't define the energies as a vector
71  // or a map, because there are so many hits that we want to avoid
72  // the memory overhead. We could get away with an array, but in
73  // this case we'd save so little code that it's not worth it.
74 
75  G4double m_energy0;
76  G4double m_energy1;
77  G4double m_energy2;
78  G4double m_energy3;
79 
80  public:
81 
82  // Accessor methods. Note the lack of "Set" methods. Once you've
83  // defined the position of a hit, you can't change it.
84 
85  inline LArG4Identifier identifier() const { return m_identifier; }
86 
87  inline G4double energy(unsigned int i) const
88  {
89  if ( i == 0 ) return m_energy0;
90  else if ( i == 1 ) return m_energy1;
91  else if ( i == 2 ) return m_energy2;
92  else if ( i == 3 ) return m_energy3;
93  else return 0.;
94  }
95 
96  // The following line lets you execute "aHit(2)" to get the 3rd
97  // energy value.
98  inline G4double operator() (unsigned int i) { return energy(i); }
99 
100  // The following methods make life much easier for the class
101  // LArG4::CalibrationSensitiveDetector. They define comparisons
102  // between CalibrationHit pointers that reference the underlying
103  // objects. For example given that p and q are CalibrationHit*,
104  // then p<q if the identifier of (*p) is less than the identifier
105  // of (*q).
106 
107  bool Less(CalibrationHit* const& h) const { return m_identifier < h->m_identifier; }
108  bool Equals(CalibrationHit* const& h) const { return m_identifier == h->m_identifier; };
109  void Add(CalibrationHit* const& h)
110  {
111  m_energy0 += h->m_energy0;
112  m_energy1 += h->m_energy1;
113  m_energy2 += h->m_energy2;
114  m_energy3 += h->m_energy3;
115  }
116 
117  };
118 
119 
120  // The following is copied from the Geant4 example; I'm not entirely
121  // sure why we need to define "new" and "delete".
122 
123  typedef G4THitsCollection<CalibrationHit> CalibrationHitsCollection;
124 
125  extern thread_local G4Allocator<CalibrationHit> CalibrationHitAllocator;
126 
127  inline void* CalibrationHit::operator new(size_t)
128  {
129  void *aHit;
130  aHit = (void *) CalibrationHitAllocator.MallocSingle();
131  return aHit;
132  }
133 
134  inline void CalibrationHit::operator delete(void *aHit)
135  {
136  CalibrationHitAllocator.FreeSingle((CalibrationHit*) aHit);
137  }
138 
139 } // namespace LArG4
140 
141 #endif // LArG4_CalibrationHit_H
LArG4::CalibrationHit::m_energy0
G4double m_energy0
Definition: CalibrationHit.h:75
LArG4Identifier
Definition: LArG4Identifier.h:121
LArG4::CalibrationHit::identifier
LArG4Identifier identifier() const
Definition: CalibrationHit.h:85
LArG4::CalibrationHit::Add
void Add(CalibrationHit *const &h)
Definition: CalibrationHit.h:109
LArG4::CalibrationHit::Equals
bool Equals(CalibrationHit *const &h) const
Definition: CalibrationHit.h:108
LArG4::CalibrationHit::Print
virtual void Print()
LArG4
Definition: LArWheelCalculatorEnums.h:8
LArG4::CalibrationHit::CalibrationHit
CalibrationHit(const LArG4Identifier &ident, G4double energy0=0., G4double energy1=0., G4double energy2=0., G4double energy3=0.)
Definition: CalibrationHit.h:43
LArG4::CalibrationHit::Draw
virtual void Draw()
LArG4::CalibrationHit::energy
G4double energy(unsigned int i) const
Definition: CalibrationHit.h:87
LArG4::CalibrationHit::m_energy1
G4double m_energy1
Definition: CalibrationHit.h:76
LArG4::CalibrationHit::~CalibrationHit
virtual ~CalibrationHit()
Definition: CalibrationHit.h:55
LArG4::CalibrationHitsCollection
G4THitsCollection< CalibrationHit > CalibrationHitsCollection
Definition: CalibrationHit.h:123
lumiFormat.i
int i
Definition: lumiFormat.py:92
LArG4::CalibrationHit::m_energy2
G4double m_energy2
Definition: CalibrationHit.h:77
LArG4::CalibrationHit
Definition: CalibrationHit.h:29
LArG4Identifier.h
LArG4::CalibrationHit::Less
bool Less(CalibrationHit *const &h) const
Definition: CalibrationHit.h:107
LArG4::CalibrationHitAllocator
thread_local G4Allocator< CalibrationHit > CalibrationHitAllocator
TRT::Hit::ident
@ ident
Definition: HitInfo.h:77
h
LArG4::CalibrationHit::m_energy3
G4double m_energy3
Definition: CalibrationHit.h:78
LArG4::CalibrationHit::CalibrationHit
CalibrationHit()
Definition: CalibrationHit.h:35
LArG4::CalibrationHit::m_identifier
LArG4Identifier m_identifier
Definition: CalibrationHit.h:68
LArG4::CalibrationHit::operator()
G4double operator()(unsigned int i)
Definition: CalibrationHit.h:98