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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 ]

Diff markup

Differences between /track/src/G4Track.cc (Version 11.3.0) and /track/src/G4Track.cc (Version 11.0.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // G4Track class implementation                    26 // G4Track class implementation
 27 //                                                 27 //
 28 // Author: Katsuya Amako, KEK - 1996               28 // Author: Katsuya Amako, KEK - 1996
 29 // Revisions: Hisaya Kurashige, 1998-2011          29 // Revisions: Hisaya Kurashige, 1998-2011
 30 // -------------------------------------------     30 // --------------------------------------------------------------------
 31                                                    31 
 32 #include "G4Track.hh"                              32 #include "G4Track.hh"
 33 #include "G4PhysicalConstants.hh"                  33 #include "G4PhysicalConstants.hh"
 34 #include "G4VAuxiliaryTrackInformation.hh"         34 #include "G4VAuxiliaryTrackInformation.hh"
 35                                                    35 
 36 #include <iostream>                                36 #include <iostream>
 37 #include <iomanip>                                 37 #include <iomanip>
 38                                                    38 
 39 // -------------------------------------------     39 // --------------------------------------------------------------------
 40 G4Allocator<G4Track>*& aTrackAllocator()           40 G4Allocator<G4Track>*& aTrackAllocator()
 41 {                                                  41 {
 42   G4ThreadLocalStatic G4Allocator<G4Track>* _i     42   G4ThreadLocalStatic G4Allocator<G4Track>* _instance = nullptr;
 43   return _instance;                                43   return _instance;
 44 }                                                  44 }
 45                                                    45 
 46 // -------------------------------------------     46 // --------------------------------------------------------------------
 47 G4Track::G4Track(G4DynamicParticle* apValueDyn     47 G4Track::G4Track(G4DynamicParticle* apValueDynamicParticle,
 48                  G4double aValueTime,              48                  G4double aValueTime,
 49                  const G4ThreeVector& aValuePo     49                  const G4ThreeVector& aValuePosition)
 50   : fPosition(aValuePosition)                      50   : fPosition(aValuePosition)
 51   , fGlobalTime(aValueTime)                        51   , fGlobalTime(aValueTime)
 52   , fVelocity(c_light)                             52   , fVelocity(c_light)
 53 {                                                  53 {
 54   fpDynamicParticle = (apValueDynamicParticle) <<  54   fpDynamicParticle = (apValueDynamicParticle)
 55                     ? apValueDynamicParticle :     55                     ? apValueDynamicParticle : new G4DynamicParticle();
 56   // check if the particle type is Optical Pho     56   // check if the particle type is Optical Photon
 57   is_OpticalPhoton =                               57   is_OpticalPhoton =
 58     (fpDynamicParticle->GetDefinition()->GetPD     58     (fpDynamicParticle->GetDefinition()->GetPDGEncoding() == -22);
 59 }                                                  59 }
 60                                                    60 
 61 // -------------------------------------------     61 // --------------------------------------------------------------------
 62 G4Track::G4Track()                                 62 G4Track::G4Track()
 63   : fVelocity(c_light)                             63   : fVelocity(c_light)
 64   , fpDynamicParticle(new G4DynamicParticle())     64   , fpDynamicParticle(new G4DynamicParticle())
 65 {}                                                 65 {}
 66                                                    66 
 67 // -------------------------------------------     67 // --------------------------------------------------------------------
 68 G4Track::G4Track(const G4Track& right,G4bool c <<  68 G4Track::G4Track(const G4Track& right)
 69   : fVelocity(c_light)                             69   : fVelocity(c_light)
 70 {                                                  70 {
 71   fCopyTouchables = copyTouchables;            << 
 72   *this = right;                                   71   *this = right;
 73   fCopyTouchables = true;                      << 
 74 }                                                  72 }
 75                                                    73 
 76 // -------------------------------------------     74 // --------------------------------------------------------------------
 77 G4Track::~G4Track()                                75 G4Track::~G4Track()
 78 {                                                  76 {
 79   delete fpDynamicParticle;                        77   delete fpDynamicParticle;
 80   delete fpUserInformation;                        78   delete fpUserInformation;
 81   ClearAuxiliaryTrackInformation();                79   ClearAuxiliaryTrackInformation();
 82 }                                                  80 }
 83                                                    81 
 84 // -------------------------------------------     82 // --------------------------------------------------------------------
 85 G4Track& G4Track::operator=(const G4Track& rig     83 G4Track& G4Track::operator=(const G4Track& right)
 86 {                                                  84 {
 87   if(this != &right)                               85   if(this != &right)
 88   {                                                86   {
 89     fPosition    = right.fPosition;                87     fPosition    = right.fPosition;
 90     fGlobalTime  = right.fGlobalTime;              88     fGlobalTime  = right.fGlobalTime;
 91     fLocalTime   = right.fLocalTime;               89     fLocalTime   = right.fLocalTime;
 92     fTrackLength = right.fTrackLength;             90     fTrackLength = right.fTrackLength;
 93     fWeight      = right.fWeight;                  91     fWeight      = right.fWeight;
 94     fStepLength  = right.fStepLength;              92     fStepLength  = right.fStepLength;
 95                                                    93 
 96     // additional fields required for geometri     94     // additional fields required for geometrical splitting
 97     if(fCopyTouchables) {                      <<  95     fpTouchable = right.fpTouchable;
 98       fpTouchable = right.fpTouchable;         <<  96     fpNextTouchable = right.fpNextTouchable;
 99       fpNextTouchable = right.fpNextTouchable; <<  97     fpOriginTouchable = right.fpOriginTouchable;
100       fpOriginTouchable = right.fpOriginToucha << 
101     }                                          << 
102                                                    98 
103     // Track ID (and Parent ID) is not copied      99     // Track ID (and Parent ID) is not copied and set to zero for new track
104     fTrackID  = 0;                                100     fTrackID  = 0;
105     fParentID = 0;                                101     fParentID = 0;
106                                                   102 
107     // CurrentStepNumber is set to be 0           103     // CurrentStepNumber is set to be 0
108     fCurrentStepNumber = 0;                       104     fCurrentStepNumber = 0;
109                                                   105 
110     // Creator model ID                           106     // Creator model ID
111     fCreatorModelID = right.fCreatorModelID;      107     fCreatorModelID = right.fCreatorModelID;
112                                                   108 
113     // Parent resonance                        << 
114     fParentResonanceDef = right.fParentResonan << 
115     fParentResonanceID  = right.fParentResonan << 
116                                                << 
117     // velocity information                       109     // velocity information
118     fVelocity = right.fVelocity;                  110     fVelocity = right.fVelocity;
119                                                   111 
120     // dynamic particle information               112     // dynamic particle information
121     delete fpDynamicParticle;                     113     delete fpDynamicParticle;
122     fpDynamicParticle = new G4DynamicParticle(    114     fpDynamicParticle = new G4DynamicParticle(*(right.fpDynamicParticle));
123                                                   115 
124     // track status and flags for tracking        116     // track status and flags for tracking
125     fTrackStatus     = right.fTrackStatus;        117     fTrackStatus     = right.fTrackStatus;
126     fBelowThreshold  = right.fBelowThreshold;     118     fBelowThreshold  = right.fBelowThreshold;
127     fGoodForTracking = right.fGoodForTracking;    119     fGoodForTracking = right.fGoodForTracking;
128                                                   120 
129     // Step information (Step Length, Step Num    121     // Step information (Step Length, Step Number, pointer to the Step,)
130     // are not copied                             122     // are not copied
131     fpStep = nullptr;                             123     fpStep = nullptr;
132                                                   124 
133     // vertex information                         125     // vertex information
134     fVtxPosition          = right.fVtxPosition    126     fVtxPosition          = right.fVtxPosition;
135     fpLVAtVertex          = right.fpLVAtVertex    127     fpLVAtVertex          = right.fpLVAtVertex;
136     fVtxKineticEnergy     = right.fVtxKineticE    128     fVtxKineticEnergy     = right.fVtxKineticEnergy;
137     fVtxMomentumDirection = right.fVtxMomentum    129     fVtxMomentumDirection = right.fVtxMomentumDirection;
138                                                   130 
139     // CreatorProcess and UserInformation are     131     // CreatorProcess and UserInformation are not copied
140     fpCreatorProcess = nullptr;                   132     fpCreatorProcess = nullptr;
141     delete fpUserInformation;                     133     delete fpUserInformation;
142     fpUserInformation = nullptr;                  134     fpUserInformation = nullptr;
143                                                   135 
144     prev_mat      = right.prev_mat;               136     prev_mat      = right.prev_mat;
145     groupvel      = right.groupvel;               137     groupvel      = right.groupvel;
146     prev_velocity = right.prev_velocity;          138     prev_velocity = right.prev_velocity;
147     prev_momentum = right.prev_momentum;          139     prev_momentum = right.prev_momentum;
148                                                   140 
149     is_OpticalPhoton = right.is_OpticalPhoton;    141     is_OpticalPhoton = right.is_OpticalPhoton;
150     useGivenVelocity = right.useGivenVelocity;    142     useGivenVelocity = right.useGivenVelocity;
151                                                   143 
152     ClearAuxiliaryTrackInformation();             144     ClearAuxiliaryTrackInformation();
153   }                                               145   }
154   return *this;                                   146   return *this;
155 }                                                 147 }
156                                                   148 
157 // -------------------------------------------    149 // --------------------------------------------------------------------
158 void G4Track::CopyTrackInfo(const G4Track& rig << 150 void G4Track::CopyTrackInfo(const G4Track& right)
159 {                                                 151 {
160   fCopyTouchables = copyTouchables;            << 
161   *this = right;                                  152   *this = right;
162   fCopyTouchables = true;                      << 
163 }                                                 153 }
164                                                   154 
165 // -------------------------------------------    155 // --------------------------------------------------------------------
166 G4double G4Track::CalculateVelocityForOpticalP    156 G4double G4Track::CalculateVelocityForOpticalPhoton() const
167 {                                                 157 {
168   G4double velocity = c_light;                    158   G4double velocity = c_light;
169                                                   159 
170   G4Material* mat        = nullptr;               160   G4Material* mat        = nullptr;
171   G4bool update_groupvel = false;                 161   G4bool update_groupvel = false;
172   if(fpStep != nullptr)                           162   if(fpStep != nullptr)
173   {                                               163   {
174     mat = this->GetMaterial();  //   Fix for r    164     mat = this->GetMaterial();  //   Fix for repeated volumes
175   }                                               165   }
176   else                                            166   else
177   {                                               167   {
178     if(fpTouchable)                            << 168     if(fpTouchable != 0)
179     {                                             169     {
180       mat = fpTouchable->GetVolume()->GetLogic    170       mat = fpTouchable->GetVolume()->GetLogicalVolume()->GetMaterial();
181     }                                             171     }
182   }                                               172   }
183   // check if previous step is in the same vol    173   // check if previous step is in the same volume
184   //  and get new GROUPVELOCITY table if neces    174   //  and get new GROUPVELOCITY table if necessary
185   if((mat != nullptr) && ((mat != prev_mat) ||    175   if((mat != nullptr) && ((mat != prev_mat) || (groupvel == nullptr)))
186   {                                               176   {
187     groupvel = nullptr;                           177     groupvel = nullptr;
188     if(mat->GetMaterialPropertiesTable() != nu    178     if(mat->GetMaterialPropertiesTable() != nullptr)
189       groupvel = mat->GetMaterialPropertiesTab    179       groupvel = mat->GetMaterialPropertiesTable()->GetProperty(kGROUPVEL);
190     update_groupvel = true;                       180     update_groupvel = true;
191   }                                               181   }
192   prev_mat = mat;                                 182   prev_mat = mat;
193                                                   183 
194   if(groupvel != nullptr)                         184   if(groupvel != nullptr)
195   {                                               185   {
196     // light velocity = c/(rindex+d(rindex)/d(    186     // light velocity = c/(rindex+d(rindex)/d(log(E_phot)))
197     // values stored in GROUPVEL material prop    187     // values stored in GROUPVEL material properties vector
198     velocity = prev_velocity;                     188     velocity = prev_velocity;
199                                                   189 
200     // check if momentum is same as in the pre    190     // check if momentum is same as in the previous step
201     //  and calculate group velocity if necess    191     //  and calculate group velocity if necessary
202     G4double current_momentum = fpDynamicParti    192     G4double current_momentum = fpDynamicParticle->GetTotalMomentum();
203     if(update_groupvel || (current_momentum !=    193     if(update_groupvel || (current_momentum != prev_momentum))
204     {                                             194     {
205       velocity      = groupvel->Value(current_    195       velocity      = groupvel->Value(current_momentum);
206       prev_velocity = velocity;                   196       prev_velocity = velocity;
207       prev_momentum = current_momentum;           197       prev_momentum = current_momentum;
208     }                                             198     }
209   }                                               199   }
210                                                   200 
211   return velocity;                                201   return velocity;
212 }                                                 202 }
213                                                   203 
214 // -------------------------------------------    204 // --------------------------------------------------------------------
215 void G4Track::SetAuxiliaryTrackInformation(G4i    205 void G4Track::SetAuxiliaryTrackInformation(G4int id,
216               G4VAuxiliaryTrackInformation* in    206               G4VAuxiliaryTrackInformation* info) const
217 {                                                 207 {
218   if(fpAuxiliaryTrackInformationMap == nullptr    208   if(fpAuxiliaryTrackInformationMap == nullptr)
219   {                                               209   {
220     fpAuxiliaryTrackInformationMap =              210     fpAuxiliaryTrackInformationMap =
221       new std::map<G4int, G4VAuxiliaryTrackInf    211       new std::map<G4int, G4VAuxiliaryTrackInformation*>;
222   }                                               212   }
223   if(G4PhysicsModelCatalog::GetModelIndex(id)     213   if(G4PhysicsModelCatalog::GetModelIndex(id) < 0)
224   {                                               214   {
225     G4ExceptionDescription ED;                    215     G4ExceptionDescription ED;
226     ED << "Process/model ID <" << id << "> is     216     ED << "Process/model ID <" << id << "> is invalid.";
227     G4Exception("G4VAuxiliaryTrackInformation:    217     G4Exception("G4VAuxiliaryTrackInformation::G4VAuxiliaryTrackInformation()",
228                 "TRACK0982", FatalException, E    218                 "TRACK0982", FatalException, ED);
229   }                                               219   }
230   (*fpAuxiliaryTrackInformationMap)[id] = info    220   (*fpAuxiliaryTrackInformationMap)[id] = info;
231 }                                                 221 }
232                                                   222 
233 // -------------------------------------------    223 // --------------------------------------------------------------------
234 G4VAuxiliaryTrackInformation*                     224 G4VAuxiliaryTrackInformation*
235 G4Track::GetAuxiliaryTrackInformation(G4int id    225 G4Track::GetAuxiliaryTrackInformation(G4int id) const
236 {                                                 226 {
237   if(fpAuxiliaryTrackInformationMap == nullptr    227   if(fpAuxiliaryTrackInformationMap == nullptr)
238     return nullptr;                               228     return nullptr;
239                                                << 
240   auto itr = fpAuxiliaryTrackInformationMap->f    229   auto itr = fpAuxiliaryTrackInformationMap->find(id);
241   if(itr == fpAuxiliaryTrackInformationMap->ce    230   if(itr == fpAuxiliaryTrackInformationMap->cend())
242     return nullptr;                               231     return nullptr;
243   return (*itr).second;                        << 232   else
                                                   >> 233     return (*itr).second;
244 }                                                 234 }
245                                                   235 
246 // -------------------------------------------    236 // --------------------------------------------------------------------
247 void G4Track::RemoveAuxiliaryTrackInformation(    237 void G4Track::RemoveAuxiliaryTrackInformation(G4int id)
248 {                                                 238 {
249   if(fpAuxiliaryTrackInformationMap != nullptr    239   if(fpAuxiliaryTrackInformationMap != nullptr  &&
250      fpAuxiliaryTrackInformationMap->find(id)     240      fpAuxiliaryTrackInformationMap->find(id) != fpAuxiliaryTrackInformationMap->cend())
251   {                                               241   {
252     fpAuxiliaryTrackInformationMap->erase(id);    242     fpAuxiliaryTrackInformationMap->erase(id);
253   }                                               243   }
254 }                                                 244 }
255                                                   245 
256 // -------------------------------------------    246 // --------------------------------------------------------------------
257 void G4Track::RemoveAuxiliaryTrackInformation(    247 void G4Track::RemoveAuxiliaryTrackInformation(G4String& name)
258 {                                                 248 {
259   if(fpAuxiliaryTrackInformationMap != nullptr    249   if(fpAuxiliaryTrackInformationMap != nullptr)
260   {                                               250   {
261     G4int id = G4PhysicsModelCatalog::GetModel    251     G4int id = G4PhysicsModelCatalog::GetModelID(name);
262     RemoveAuxiliaryTrackInformation(id);          252     RemoveAuxiliaryTrackInformation(id);
263   }                                               253   }
264 }                                                 254 }
265                                                   255 
266 // -------------------------------------------    256 // --------------------------------------------------------------------
267 void G4Track::ClearAuxiliaryTrackInformation()    257 void G4Track::ClearAuxiliaryTrackInformation()
268 {                                                 258 {
269   if(fpAuxiliaryTrackInformationMap == nullptr    259   if(fpAuxiliaryTrackInformationMap == nullptr)
270     return;                                       260     return;
271   for(const auto& itr : *fpAuxiliaryTrackInfor << 261   for(auto itr = fpAuxiliaryTrackInformationMap->cbegin();
                                                   >> 262            itr != fpAuxiliaryTrackInformationMap->cend(); ++itr)
272   {                                               263   {
273     delete itr.second;                         << 264     delete(*itr).second;
274   }                                               265   }
275   delete fpAuxiliaryTrackInformationMap;          266   delete fpAuxiliaryTrackInformationMap;
276   fpAuxiliaryTrackInformationMap = nullptr;       267   fpAuxiliaryTrackInformationMap = nullptr;
277 }                                                 268 }
278                                                   269