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 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 // G4Track class implementation
 27 //
 28 // Author: Katsuya Amako, KEK - 1996
 29 // Revisions: Hisaya Kurashige, 1998-2011
 30 // --------------------------------------------------------------------
 31 
 32 #include "G4Track.hh"
 33 #include "G4PhysicalConstants.hh"
 34 #include "G4VAuxiliaryTrackInformation.hh"
 35 
 36 #include <iostream>
 37 #include <iomanip>
 38 
 39 // --------------------------------------------------------------------
 40 G4Allocator<G4Track>*& aTrackAllocator()
 41 {
 42   G4ThreadLocalStatic G4Allocator<G4Track>* _instance = nullptr;
 43   return _instance;
 44 }
 45 
 46 // --------------------------------------------------------------------
 47 G4Track::G4Track(G4DynamicParticle* apValueDynamicParticle,
 48                  G4double aValueTime,
 49                  const G4ThreeVector& aValuePosition)
 50   : fPosition(aValuePosition)
 51   , fGlobalTime(aValueTime)
 52   , fVelocity(c_light)
 53 {
 54   fpDynamicParticle = (apValueDynamicParticle) != nullptr
 55                     ? apValueDynamicParticle : new G4DynamicParticle();
 56   // check if the particle type is Optical Photon
 57   is_OpticalPhoton =
 58     (fpDynamicParticle->GetDefinition()->GetPDGEncoding() == -22);
 59 }
 60 
 61 // --------------------------------------------------------------------
 62 G4Track::G4Track()
 63   : fVelocity(c_light)
 64   , fpDynamicParticle(new G4DynamicParticle())
 65 {}
 66 
 67 // --------------------------------------------------------------------
 68 G4Track::G4Track(const G4Track& right,G4bool copyTouchables)
 69   : fVelocity(c_light)
 70 {
 71   fCopyTouchables = copyTouchables;
 72   *this = right;
 73   fCopyTouchables = true;
 74 }
 75 
 76 // --------------------------------------------------------------------
 77 G4Track::~G4Track()
 78 {
 79   delete fpDynamicParticle;
 80   delete fpUserInformation;
 81   ClearAuxiliaryTrackInformation();
 82 }
 83 
 84 // --------------------------------------------------------------------
 85 G4Track& G4Track::operator=(const G4Track& right)
 86 {
 87   if(this != &right)
 88   {
 89     fPosition    = right.fPosition;
 90     fGlobalTime  = right.fGlobalTime;
 91     fLocalTime   = right.fLocalTime;
 92     fTrackLength = right.fTrackLength;
 93     fWeight      = right.fWeight;
 94     fStepLength  = right.fStepLength;
 95 
 96     // additional fields required for geometrical splitting
 97     if(fCopyTouchables) {
 98       fpTouchable = right.fpTouchable;
 99       fpNextTouchable = right.fpNextTouchable;
100       fpOriginTouchable = right.fpOriginTouchable;
101     }
102 
103     // Track ID (and Parent ID) is not copied and set to zero for new track
104     fTrackID  = 0;
105     fParentID = 0;
106 
107     // CurrentStepNumber is set to be 0
108     fCurrentStepNumber = 0;
109 
110     // Creator model ID
111     fCreatorModelID = right.fCreatorModelID;
112 
113     // Parent resonance
114     fParentResonanceDef = right.fParentResonanceDef;
115     fParentResonanceID  = right.fParentResonanceID;
116    
117     // velocity information
118     fVelocity = right.fVelocity;
119 
120     // dynamic particle information
121     delete fpDynamicParticle;
122     fpDynamicParticle = new G4DynamicParticle(*(right.fpDynamicParticle));
123 
124     // track status and flags for tracking
125     fTrackStatus     = right.fTrackStatus;
126     fBelowThreshold  = right.fBelowThreshold;
127     fGoodForTracking = right.fGoodForTracking;
128 
129     // Step information (Step Length, Step Number, pointer to the Step,)
130     // are not copied
131     fpStep = nullptr;
132 
133     // vertex information
134     fVtxPosition          = right.fVtxPosition;
135     fpLVAtVertex          = right.fpLVAtVertex;
136     fVtxKineticEnergy     = right.fVtxKineticEnergy;
137     fVtxMomentumDirection = right.fVtxMomentumDirection;
138 
139     // CreatorProcess and UserInformation are not copied
140     fpCreatorProcess = nullptr;
141     delete fpUserInformation;
142     fpUserInformation = nullptr;
143 
144     prev_mat      = right.prev_mat;
145     groupvel      = right.groupvel;
146     prev_velocity = right.prev_velocity;
147     prev_momentum = right.prev_momentum;
148 
149     is_OpticalPhoton = right.is_OpticalPhoton;
150     useGivenVelocity = right.useGivenVelocity;
151 
152     ClearAuxiliaryTrackInformation();
153   }
154   return *this;
155 }
156 
157 // --------------------------------------------------------------------
158 void G4Track::CopyTrackInfo(const G4Track& right, G4bool copyTouchables)
159 {
160   fCopyTouchables = copyTouchables;
161   *this = right;
162   fCopyTouchables = true;
163 }
164 
165 // --------------------------------------------------------------------
166 G4double G4Track::CalculateVelocityForOpticalPhoton() const
167 {
168   G4double velocity = c_light;
169 
170   G4Material* mat        = nullptr;
171   G4bool update_groupvel = false;
172   if(fpStep != nullptr)
173   {
174     mat = this->GetMaterial();  //   Fix for repeated volumes
175   }
176   else
177   {
178     if(fpTouchable)
179     {
180       mat = fpTouchable->GetVolume()->GetLogicalVolume()->GetMaterial();
181     }
182   }
183   // check if previous step is in the same volume
184   //  and get new GROUPVELOCITY table if necessary
185   if((mat != nullptr) && ((mat != prev_mat) || (groupvel == nullptr)))
186   {
187     groupvel = nullptr;
188     if(mat->GetMaterialPropertiesTable() != nullptr)
189       groupvel = mat->GetMaterialPropertiesTable()->GetProperty(kGROUPVEL);
190     update_groupvel = true;
191   }
192   prev_mat = mat;
193 
194   if(groupvel != nullptr)
195   {
196     // light velocity = c/(rindex+d(rindex)/d(log(E_phot)))
197     // values stored in GROUPVEL material properties vector
198     velocity = prev_velocity;
199 
200     // check if momentum is same as in the previous step
201     //  and calculate group velocity if necessary
202     G4double current_momentum = fpDynamicParticle->GetTotalMomentum();
203     if(update_groupvel || (current_momentum != prev_momentum))
204     {
205       velocity      = groupvel->Value(current_momentum);
206       prev_velocity = velocity;
207       prev_momentum = current_momentum;
208     }
209   }
210 
211   return velocity;
212 }
213 
214 // --------------------------------------------------------------------
215 void G4Track::SetAuxiliaryTrackInformation(G4int id,
216               G4VAuxiliaryTrackInformation* info) const
217 {
218   if(fpAuxiliaryTrackInformationMap == nullptr)
219   {
220     fpAuxiliaryTrackInformationMap =
221       new std::map<G4int, G4VAuxiliaryTrackInformation*>;
222   }
223   if(G4PhysicsModelCatalog::GetModelIndex(id) < 0)
224   {
225     G4ExceptionDescription ED;
226     ED << "Process/model ID <" << id << "> is invalid.";
227     G4Exception("G4VAuxiliaryTrackInformation::G4VAuxiliaryTrackInformation()",
228                 "TRACK0982", FatalException, ED);
229   }
230   (*fpAuxiliaryTrackInformationMap)[id] = info;
231 }
232 
233 // --------------------------------------------------------------------
234 G4VAuxiliaryTrackInformation*
235 G4Track::GetAuxiliaryTrackInformation(G4int id) const
236 {
237   if(fpAuxiliaryTrackInformationMap == nullptr)
238     return nullptr;
239   
240   auto itr = fpAuxiliaryTrackInformationMap->find(id);
241   if(itr == fpAuxiliaryTrackInformationMap->cend())
242     return nullptr;
243   return (*itr).second;
244 }
245 
246 // --------------------------------------------------------------------
247 void G4Track::RemoveAuxiliaryTrackInformation(G4int id)
248 {
249   if(fpAuxiliaryTrackInformationMap != nullptr  &&
250      fpAuxiliaryTrackInformationMap->find(id) != fpAuxiliaryTrackInformationMap->cend())
251   {
252     fpAuxiliaryTrackInformationMap->erase(id);
253   }
254 }
255 
256 // --------------------------------------------------------------------
257 void G4Track::RemoveAuxiliaryTrackInformation(G4String& name)
258 {
259   if(fpAuxiliaryTrackInformationMap != nullptr)
260   {
261     G4int id = G4PhysicsModelCatalog::GetModelID(name);
262     RemoveAuxiliaryTrackInformation(id);
263   }
264 }
265 
266 // --------------------------------------------------------------------
267 void G4Track::ClearAuxiliaryTrackInformation()
268 {
269   if(fpAuxiliaryTrackInformationMap == nullptr)
270     return;
271   for(const auto& itr : *fpAuxiliaryTrackInformationMap)
272   {
273     delete itr.second;
274   }
275   delete fpAuxiliaryTrackInformationMap;
276   fpAuxiliaryTrackInformationMap = nullptr;
277 }
278