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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 10.7.p2)


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