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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 7.1)


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