ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4Track.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4Track.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 //
28 //
29 //---------------------------------------------------------------
30 //
31 // G4Track.cc
32 //
33 //---------------------------------------------------------------
34 // Add copy constructor Hisaya Feb. 07 01
35 // Fix GetVelocity Hisaya Feb. 17 01
36 // Modification for G4TouchableHandle 22 Oct. 2001 R.Chytracek//
37 // Fix GetVelocity (bug report #741) Horton-Smith Apr 14 2005
38 // Remove massless check in GetVelocity 02 Apr. 09 H.Kurashige
39 // Use G4VelocityTable 17 AUg. 2011 H.Kurashige
40 
41 #include "G4Track.hh"
42 #include "G4PhysicalConstants.hh"
43 #include "G4ParticleTable.hh"
44 #include "G4VelocityTable.hh"
46 #include "G4PhysicsModelCatalog.hh"
47 
48 #include <iostream>
49 #include <iomanip>
50 
52 {
53  G4ThreadLocalStatic G4Allocator<G4Track>* _instance = nullptr;
54  return _instance;
55 }
56 
58 {
59  G4ThreadLocalStatic G4VelocityTable* _instance = nullptr;
60  return _instance;
61 }
62 
64 G4Track::G4Track(G4DynamicParticle* apValueDynamicParticle,
65  G4double aValueTime,
66  const G4ThreeVector& aValuePosition)
68  : fCurrentStepNumber(0), fPosition(aValuePosition),
69  fGlobalTime(aValueTime), fLocalTime(0.),
70  fTrackLength(0.),
71  fParentID(0), fTrackID(0),
72  fVelocity(c_light),
73  fpDynamicParticle(apValueDynamicParticle),
74  fTrackStatus(fAlive),
75  fBelowThreshold(false), fGoodForTracking(false),
76  fStepLength(0.0), fWeight(1.0),
77  fpStep(nullptr),
78  fVtxKineticEnergy(0.0),
79  fpLVAtVertex(nullptr), fpCreatorProcess(nullptr),
80  fCreatorModelIndex(-1),
81  fpUserInformation(nullptr),
82  prev_mat(nullptr), groupvel(nullptr),
83  prev_velocity(0.0), prev_momentum(0.0),
84  is_OpticalPhoton(false),
85  useGivenVelocity(false),
86  fpAuxiliaryTrackInformationMap(nullptr)
87 {
88  static G4ThreadLocal G4bool isFirstTime = true;
89  static G4ThreadLocal G4ParticleDefinition* fOpticalPhoton = nullptr;
90  if ( isFirstTime ) {
91  isFirstTime = false;
92  // set fOpticalPhoton
93  fOpticalPhoton = G4ParticleTable::GetParticleTable()->FindParticle("opticalphoton");
94  }
95  // check if the particle type is Optical Photon
96  is_OpticalPhoton = (fpDynamicParticle->GetDefinition() == fOpticalPhoton);
97 
98  if (velTable() == nullptr ) velTable() = G4VelocityTable::GetVelocityTable();
99 
101 
102 }
103 
107  : fCurrentStepNumber(0),
108  fGlobalTime(0), fLocalTime(0.),
109  fTrackLength(0.),
110  fParentID(0), fTrackID(0),
111  fVelocity(c_light),
112  fpDynamicParticle(nullptr),
113  fTrackStatus(fAlive),
114  fBelowThreshold(false), fGoodForTracking(false),
115  fStepLength(0.0), fWeight(1.0),
116  fpStep(nullptr),
117  fVtxKineticEnergy(0.0),
118  fpLVAtVertex(nullptr), fpCreatorProcess(nullptr),
119  fCreatorModelIndex(-1),
120  fpUserInformation(nullptr),
121  prev_mat(nullptr), groupvel(nullptr),
122  prev_velocity(0.0), prev_momentum(0.0),
123  is_OpticalPhoton(false),
124  useGivenVelocity(false),
125  fpAuxiliaryTrackInformationMap(nullptr)
126 {
127 }
128 
132  : fCurrentStepNumber(0),
133  fGlobalTime(0), fLocalTime(0.),
134  fTrackLength(0.),
135  fParentID(0), fTrackID(0),
136  fVelocity(c_light),
137  fpDynamicParticle(nullptr),
138  fTrackStatus(fAlive),
139  fBelowThreshold(false), fGoodForTracking(false),
140  fStepLength(0.0), fWeight(1.0),
141  fpStep(nullptr),
142  fVtxKineticEnergy(0.0),
143  fpLVAtVertex(nullptr), fpCreatorProcess(nullptr),
144  fCreatorModelIndex(-1),
145  fpUserInformation(nullptr),
146  prev_mat(nullptr), groupvel(nullptr),
147  prev_velocity(0.0), prev_momentum(0.0),
148  is_OpticalPhoton(false),
149  useGivenVelocity(false),
150  fpAuxiliaryTrackInformationMap(nullptr)
151 {
152  *this = right;
153 }
154 
158 {
159  delete fpDynamicParticle;
160  fpDynamicParticle = nullptr;
161  delete fpUserInformation;
162  fpUserInformation = nullptr;
164 }
165 
169 {
170  if (this != &right) {
171  fPosition = right.fPosition;
172  fGlobalTime = right.fGlobalTime;
173  fLocalTime = right.fLocalTime;
174  fTrackLength = right.fTrackLength;
175  fWeight = right.fWeight;
176  fStepLength = right.fStepLength;
177 
178  // Track ID (and Parent ID) is not copied and set to zero for new track
179  fTrackID = 0;
180  fParentID =0;
181 
182  // CurrentStepNumber is set to be 0
183  fCurrentStepNumber = 0;
184 
185  // velocity information
186  fVelocity = right.fVelocity;
187 
188  // dynamic particle information
189  if ( fpDynamicParticle != nullptr ) delete fpDynamicParticle;
191 
192  // track status and flags for tracking
193  fTrackStatus = right.fTrackStatus;
196 
197  // Step information (Step Length, Step Number, pointer to the Step,)
198  // are not copied
199  fpStep = nullptr;
200 
201  // vertex information
202  fVtxPosition = right.fVtxPosition;
203  fpLVAtVertex = right.fpLVAtVertex;
206 
207  // CreatorProcess and UserInformation are not copied
208  fpCreatorProcess = nullptr;
209  if ( fpUserInformation != nullptr ) delete fpUserInformation;
210  fpUserInformation = nullptr;
211 
212  prev_mat = right.prev_mat;
213  groupvel = right.groupvel;
216 
219 
221 
222  }
223  return *this;
224 }
225 
229 {
230  *this = right;
231 }
232 
236 {
237  if (useGivenVelocity) return fVelocity;
238 
239  G4double velocity = c_light ;
240 
242 
243  // special case for photons
245 
246  // particles other than optical photon
247  if (mass<DBL_MIN) {
248  // Zero Mass
249  velocity = c_light;
250  } else {
252  if (T > GetMaxTOfVelocityTable()) {
253  velocity = c_light;
254  } else if (T<DBL_MIN) {
255  velocity =0.;
256  } else if (T<GetMinTOfVelocityTable()) {
257  velocity = c_light*std::sqrt(T*(T+2.))/(T+1.0);
258  } else {
259  velocity = velTable()->Value(T);
260  }
261 
262  }
263  return velocity ;
264 }
265 
269 {
270 
271  G4double velocity = c_light ;
272 
273 
274  G4Material* mat = nullptr;
275  G4bool update_groupvel = false;
276  if ( fpStep !=0 ){
277  mat= this->GetMaterial(); // Fix for repeated volumes
278  }else{
279  if (fpTouchable!=0){
281  }
282  }
283  // check if previous step is in the same volume
284  // and get new GROUPVELOCITY table if necessary
285  if ((mat != nullptr) && ((mat != prev_mat)||(groupvel==nullptr))) {
286  groupvel = nullptr;
287  if(mat->GetMaterialPropertiesTable() != nullptr)
288  groupvel = mat->GetMaterialPropertiesTable()->GetProperty("GROUPVEL");
289  update_groupvel = true;
290  }
291  prev_mat = mat;
292 
293  if (groupvel != nullptr ) {
294  // light velocity = c/(rindex+d(rindex)/d(log(E_phot)))
295  // values stored in GROUPVEL material properties vector
296  velocity = prev_velocity;
297 
298  // check if momentum is same as in the previous step
299  // and calculate group velocity if necessary
300  G4double current_momentum = fpDynamicParticle->GetTotalMomentum();
301  if( update_groupvel || (current_momentum != prev_momentum) ) {
302  velocity =
303  groupvel->Value(current_momentum);
304  prev_velocity = velocity;
305  prev_momentum = current_momentum;
306  }
307  }
308 
309  return velocity ;
310 }
311 
315 {
318 }
319 
324 
327 
329 
332 
334 
338 {
339  if(!fpAuxiliaryTrackInformationMap)
340  { fpAuxiliaryTrackInformationMap = new std::map<G4int,G4VAuxiliaryTrackInformation*>; }
341  if(idx<0 || idx>=G4PhysicsModelCatalog::Entries())
342  {
344  ED << "Process/model index <" << idx << "> is invalid.";
345  G4Exception("G4VAuxiliaryTrackInformation::G4VAuxiliaryTrackInformation()","TRACK0982",
346  FatalException, ED);
347  }
348  (*fpAuxiliaryTrackInformationMap)[idx] = info;
349 }
350 
354 {
355  if(!fpAuxiliaryTrackInformationMap) return nullptr;
356  std::map<G4int,G4VAuxiliaryTrackInformation*>::iterator itr
357  = fpAuxiliaryTrackInformationMap->find(idx);
358  if(itr==fpAuxiliaryTrackInformationMap->end()) return nullptr;
359  else return (*itr).second;
360 }
361 
365 {
366  if( fpAuxiliaryTrackInformationMap != nullptr
367  && idx>=0 && idx<G4PhysicsModelCatalog::Entries()){
368  fpAuxiliaryTrackInformationMap->erase(idx);
369  }
370 }
371 
375 {
376  if(fpAuxiliaryTrackInformationMap != nullptr) {
379  }
380 }
381 
385 {
386  if( fpAuxiliaryTrackInformationMap == nullptr) return;
387  for(std::map<G4int,G4VAuxiliaryTrackInformation*>::iterator itr=fpAuxiliaryTrackInformationMap->begin();
388  itr!=fpAuxiliaryTrackInformationMap->end(); itr++)
389  { delete (*itr).second; }
392 }
393 
394