EDepSimHitSegment.hh
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////
2 // $Id: EDepSim::HitSegment.hh,v 1.5 2011/06/29 04:35:53 mcgrew Exp $
3 
4 #ifndef EDepSim_HitSegment_h
5 #define EDepSim_HitSegment_h
6 
7 #include <vector>
8 
9 #include <G4VHit.hh>
10 #include <G4THitsCollection.hh>
11 #include <G4Allocator.hh>
12 #include <G4ThreeVector.hh>
13 #include <G4LorentzVector.hh>
14 
15 #include <G4SystemOfUnits.hh>
16 #include <G4PhysicalConstants.hh>
17 
18 class G4Step;
19 class G4Track;
20 
21 #include "EDepSimVolumeId.hh"
22 
23 /// This is a base class used to save G4Hit objects into a root output file.
24 /// It contains the global position of the starting point and stopping point
25 /// of the track segment that created the hit, plus the any fields provided by
26 /// CP::TG4VHit. The electronics response is simulated in a separate program
27 /// (library) which will construct the digitized hits. This class is used
28 /// with the EDepSim::SegmentSD sensitive detector class, and can be requested
29 /// using the "segment" name from EDepSim::SensitiveDetectorFactor::MakeSD().
30 namespace EDepSim {class HitSegment;}
31 class EDepSim::HitSegment : public G4VHit {
32 public:
33  /// Create a new hit segment with a maximum allowed sagitta and length.
34  /// The default values are set so that normally, a scintillator element
35  /// will only have a single hit for a through going track (& delta-rays).
36  HitSegment(double maxSagitta = 1*CLHEP::mm,
37  double maxLength = 5*CLHEP::mm);
38 
39  HitSegment(const EDepSim::HitSegment& rhs);
40  virtual ~HitSegment();
41 
42  typedef G4THitsCollection<EDepSim::HitSegment> HitSegmentCollection;
43 
44  inline void* operator new(size_t);
45  inline void operator delete(void*);
46 
47  /// Add the effects of a part of a step to this hit.
48  virtual void AddStep(G4Step* theStep);
49 
50  /// Hits for the same primary particle, in the same physical volume belong
51  /// in the same hit.
52  virtual bool SameHit(G4Step* theStep);
53 
54  /// Disambiguate the draw and print methods to distinguish between the
55  /// G4VHit and TObject definitions.
56  virtual void Draw();
57  virtual void Print();
58  virtual void Draw(const char*) {}
59  virtual void Print(const char*) const {}
60 
61  /// Provide public access to the contributors for internal G4 classes.
62  std::vector<int>& GetContributors() {return fContributors;}
63 
64  /// Find the distance from the starting point to stoping point of the
65  /// track.
66  virtual double GetLength() const;
67 
68  /// Return a list of track identifiers that contributed to this hit.
69  /// These track ids can be used as indicies to find trajectories in the
70  /// TG4TrajectoryContainer object associated with an MC event.
71  int GetContributor(int i) const {
72  return fContributors[i];
73  }
74 
75  /// Return a list of track identifiers that contributed to this hit.
76  /// These track ids can be used as indicies to find trajectories in the
77  /// TG4TrajectoryContainer object associated with an MC event.
78  int GetContributorCount() const {
79  return fContributors.size();
80  }
81 
82  /// Get the TrackId of the "primary" particle that is associated with this
83  /// hit. This is slightly complicated since the "interesting" primary
84  /// particle is saved. For instance, if the primary particle is a pizero,
85  /// The TrackId of the gamma-rays from the decay is saved. Likewise, the
86  /// electron from a muon decay is used as the primary particle. You can
87  /// find the "really truly" primary particle by finding the trajectory
88  /// associated with this PrimaryId, and then working backwards to the
89  /// associated G4PrimaryParticle (You can tell that a trajectory comes
90  /// from a primary particle by checking if it's ParentID is zero. If it
91  /// is zero, the trajectory came from a primary).
92  int GetPrimaryTrajectoryId(void) const {return fPrimaryId;}
93 
94  /// Get the total energy deposited in this hit.
95  double GetEnergyDeposit(void) const {return fEnergyDeposit;}
96 
97  /// Get the secondary energy deposited in this hit (see the field
98  /// documentation).
99  double GetSecondaryDeposit(void) const {return fSecondaryDeposit;}
100 
101  /// Get the total charged track length in this hit. This includes all of
102  /// the contributions from secondary particles that got lumped into this
103  /// hit (e.g. the contributions from delta-rays).
104  double GetTrackLength(void) const {return fTrackLength;}
105 
106  /// The position of the starting point.
107  const G4LorentzVector& GetStart() const {return fStart;}
108 
109  /// The position of the stopping point.
110  const G4LorentzVector& GetStop() const {return fStop;}
111 
112 #ifdef BOGUS
113  /// The X position of the hit starting point. Note that a hit by
114  /// definition is in a single volume. If the hit is spread over two
115  /// volumes, it's a result of round-off error (and is almost a bug). The
116  /// GeoNodeId should be defined by the average position of the hit.
117  double GetStartX(void) const {return fStartX;}
118 
119  /// The Y position of the hit starting point. Note that a hit by
120  /// definition is in a single volume. If the hit is spread over two
121  /// volumes, it's a result of round-off error (and is almost a bug). The
122  /// GeoNodeId should be defined by the average position of the hit.
123  double GetStartY(void) const {return fStartY;}
124 
125  /// The Z position of the hit starting point. Note that a hit by
126  /// definition is in a single volume. If the hit is spread over two
127  /// volumes, it's a result of round-off error (and is almost a bug). The
128  /// GeoNodeId should be defined by the average position of the hit.
129  double GetStartZ(void) const {return fStartZ;}
130 
131  /// The time of the hit starting point. Note that a hit by
132  /// definition is in a single volume. If the hit is spread over two
133  /// volumes, it's a result of round-off error (and is almost a bug). The
134  /// GeoNodeId should be defined by the average position of the hit.
135  double GetStartT(void) const {return fStartT;}
136 
137  /// The X position of the hit stoping point. Note that a hit by
138  /// definition is in a single volume. If the hit is spread over two
139  /// volumes, it's a result of round-off error (and is almost a bug). The
140  /// GeoNodeId should be defined by the average position of the hit.
141  double GetStopX(void) const {return fStopX;}
142 
143  /// The Y position of the hit stoping point. Note that a hit by
144  /// definition is in a single volume. If the hit is spread over two
145  /// volumes, it's a result of round-off error (and is almost a bug). The
146  /// GeoNodeId should be defined by the average position of the hit.
147  double GetStopY(void) const {return fStopY;}
148 
149  /// The Z position of the hit stoping point. Note that a hit by
150  /// definition is in a single volume. If the hit is spread over two
151  /// volumes, it's a result of round-off error (and is almost a bug). The
152  /// GeoNodeId should be defined by the average position of the hit.
153  double GetStopZ(void) const {return fStopZ;}
154 
155  /// The time of the hit stopping point. Note that a hit by
156  /// definition is in a single volume. If the hit is spread over two
157  /// volumes, it's a result of round-off error (and is almost a bug). The
158  /// GeoNodeId should be defined by the average position of the hit.
159  double GetStopT(void) const {return fStopT;}
160 #endif
161 
162  /// Print the hit information.
163  void ls(std::string = "") const;
164 
165 protected:
166  /// Find the primary track ID for the current track. This is the primary
167  /// that is the ultimate parent of the current track.
168  int FindPrimaryId(G4Track* theTrack);
169 
170  /// Find the maximum separation (the sagitta) between the current hit
171  /// segment path points, and the straight line connecting the start and
172  /// proposed new stop point.
173  double FindSagitta(G4Step* theStep);
174 
175  /// Find the maximum distance from the hit segment to the new step that is
176  /// proposed to be added to the hit segment. This is used to
177  /// combine secondaries with a parent track.
178  double FindSeparation(G4Step* theStep);
179 
180 private:
181 
182  /// The sagitta tolerance for the segment.
183  double fMaxSagitta;
184 
185  /// The maximum length between the start and stop points of the segment.
186  double fMaxLength;
187 
188  /// The TrackID for each trajectory that contributed to this hit. This
189  /// could contain the TrackID of the primary particle, but not
190  /// necessarily.
191  std::vector<int> fContributors;
192 
193  /// The track id of the primary particle.
195 
196  /// The total energy deposit in this hit.
198 
199  /// The "secondary" energy deposit in this hit. This is used to help
200  /// simulate the recombination of electrons, and is part of the total
201  /// energy deposit.
202  ///
203  /// DETSIM is expected to use this field to save the amount of energy
204  /// deposited as opticalphotons. The remaining energy will be deposited
205  /// as ionization. In this model (in argon), the mean number of quanta
206  /// created will be <N_q> = (fEnergyDeposit)/(19.5*eV), N_q should be
207  /// fluctuated around <N_q>, N_ph = N_q*fSecondaryDeposit/fEnergyDeposit,
208  /// and N_e = N_q - N_ph. Thd fSecondaryDeposit value already includes
209  /// the binomial fluctuation, so don't fluctuate N_ph or N_e.
211 
212  /// The total charged track length in this hit. This includes the
213  /// contribution from all of the secondary particles (e.g. delta-rays)
214  /// that are included in this hit.
215  double fTrackLength;
216 
217  /// The starting position of the segment.
218  G4LorentzVector fStart;
219 
220  /// The stopping position of the segment.
221  G4LorentzVector fStop;
222 
223 private:
224  /// The G4 physical volume that contains the hit.
226 
227  /// The end points of the steps that make up this hit. This is used to
228  /// make sure that the current hit stays inside of it's allowed
229  /// tolerances.
230  std::vector<G4ThreeVector> fPath;
231 
232 };
233 
234 extern G4Allocator<EDepSim::HitSegment> edepHitSegmentAllocator;
235 
236 inline void* EDepSim::HitSegment::operator new(size_t) {
237  void *aHit;
238  aHit = (void *) edepHitSegmentAllocator.MallocSingle();
239  return aHit;
240 }
241 
242 inline void EDepSim::HitSegment::operator delete(void *aHit) {
243  edepHitSegmentAllocator.FreeSingle((EDepSim::HitSegment*) aHit);
244 }
245 
246 #endif
double fEnergyDeposit
The total energy deposit in this hit.
HitSegment(double maxSagitta=1 *CLHEP::mm, double maxLength=5 *CLHEP::mm)
virtual double GetLength() const
double GetTrackLength(void) const
virtual void Print(const char *) const
void ls(std::string="") const
Print the hit information.
std::string string
Definition: nybbler.cc:12
int fPrimaryId
The track id of the primary particle.
std::vector< int > fContributors
G4Allocator< EDepSim::HitSegment > edepHitSegmentAllocator
virtual bool SameHit(G4Step *theStep)
const G4LorentzVector & GetStart() const
The position of the starting point.
int GetContributor(int i) const
G4LorentzVector fStart
The starting position of the segment.
Construct a module from components.
Definition: TG4HitSegment.h:10
double fMaxSagitta
The sagitta tolerance for the segment.
std::vector< G4ThreeVector > fPath
double fMaxLength
The maximum length between the start and stop points of the segment.
double FindSeparation(G4Step *theStep)
int FindPrimaryId(G4Track *theTrack)
double GetSecondaryDeposit(void) const
int GetContributorCount() const
int GetPrimaryTrajectoryId(void) const
G4LorentzVector fStop
The stopping position of the segment.
const G4LorentzVector & GetStop() const
The position of the stopping point.
virtual void Draw(const char *)
static constexpr double mm
Definition: Units.h:65
EDepSim::VolumeId fHitVolume
The G4 physical volume that contains the hit.
G4THitsCollection< EDepSim::HitSegment > HitSegmentCollection
std::vector< int > & GetContributors()
Provide public access to the contributors for internal G4 classes.
double FindSagitta(G4Step *theStep)
double GetEnergyDeposit(void) const
Get the total energy deposited in this hit.
virtual void AddStep(G4Step *theStep)
Add the effects of a part of a step to this hit.