Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/error_propagation/src/G4ErrorPropagator.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 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 /error_propagation/src/G4ErrorPropagator.cc (Version 11.3.0) and /error_propagation/src/G4ErrorPropagator.cc (Version 10.3)


  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 // $Id: G4ErrorPropagator.cc 91809 2015-08-06 13:00:09Z gcosmo $
 26 //                                                 27 //
 27 // -------------------------------------------     28 // ------------------------------------------------------------
 28 //      GEANT 4 class implementation file      <<  29 //      GEANT 4 class implementation file 
 29 // -------------------------------------------     30 // ------------------------------------------------------------
 30 //                                                 31 //
 31                                                    32 
 32 #include "G4ErrorPropagator.hh"                    33 #include "G4ErrorPropagator.hh"
 33 #include "G4ErrorPropagatorData.hh"                34 #include "G4ErrorPropagatorData.hh"
 34 #include "G4ErrorFreeTrajState.hh"                 35 #include "G4ErrorFreeTrajState.hh"
 35 #include "G4ErrorSurfaceTrajState.hh"              36 #include "G4ErrorSurfaceTrajState.hh"
 36 #include "G4ErrorGeomVolumeTarget.hh"              37 #include "G4ErrorGeomVolumeTarget.hh"
 37 #include "G4ErrorSurfaceTarget.hh"                 38 #include "G4ErrorSurfaceTarget.hh"
 38                                                    39 
 39 #include "G4SystemOfUnits.hh"                      40 #include "G4SystemOfUnits.hh"
 40 #include "G4DynamicParticle.hh"                    41 #include "G4DynamicParticle.hh"
 41 #include "G4Track.hh"                              42 #include "G4Track.hh"
 42 #include "G4SteppingManager.hh"                    43 #include "G4SteppingManager.hh"
 43 #include "G4EventManager.hh"                       44 #include "G4EventManager.hh"
 44 #include "G4TrackingManager.hh"                    45 #include "G4TrackingManager.hh"
 45 #include "G4ParticleTable.hh"                      46 #include "G4ParticleTable.hh"
 46 #include "G4StateManager.hh"                       47 #include "G4StateManager.hh"
 47                                                    48 
 48 #include "G4VPhysicalVolume.hh"                    49 #include "G4VPhysicalVolume.hh"
 49 #include "G4PhysicalVolumeStore.hh"                50 #include "G4PhysicalVolumeStore.hh"
 50 #include "G4UnitsTable.hh"                         51 #include "G4UnitsTable.hh"
 51                                                    52 
 52 #include <vector>                                  53 #include <vector>
 53                                                    54 
                                                   >>  55 
 54 //--------------------------------------------     56 //---------------------------------------------------------------------------
 55 G4ErrorPropagator::G4ErrorPropagator()             57 G4ErrorPropagator::G4ErrorPropagator()
 56   : theStepLength(0.)                          <<  58   : theStepLength(0.), theInitialTrajState(0), theStepN(0), theG4Track(0)
 57   , theInitialTrajState(0)                     << 
 58   , theStepN(0)                                << 
 59   , theG4Track(0)                              << 
 60 {                                                  59 {
 61   verbose = G4ErrorPropagatorData::verbose();  <<  60   verbose =  G4ErrorPropagatorData::verbose();
 62 #ifdef G4EVERBOSE                                  61 #ifdef G4EVERBOSE
 63   if(verbose >= 5)                             <<  62    if(verbose >= 5) { G4cout << "G4ErrorPropagator " << this << G4endl; }
 64   {                                            << 
 65     G4cout << "G4ErrorPropagator " << this <<  << 
 66   }                                            << 
 67 #endif                                             63 #endif
 68                                                    64 
 69   fpSteppingManager = G4EventManager::GetEvent     65   fpSteppingManager = G4EventManager::GetEventManager()
 70                         ->GetTrackingManager() <<  66                     ->GetTrackingManager()->GetSteppingManager();
 71                         ->GetSteppingManager() << 
 72   thePropIsInitialized = false;                    67   thePropIsInitialized = false;
 73 }                                                  68 }
 74                                                    69 
                                                   >>  70 
 75 //--------------------------------------------     71 //-----------------------------------------------------------------------
 76 G4int G4ErrorPropagator::Propagate(G4ErrorTraj <<  72 G4int G4ErrorPropagator::Propagate( G4ErrorTrajState* currentTS,
 77                                    const G4Err <<  73                               const G4ErrorTarget* target, G4ErrorMode mode )
 78                                    G4ErrorMode << 
 79 {                                                  74 {
 80   // to start ierror is set to 1 (= OK)            75   // to start ierror is set to 1 (= OK)
 81   //                                               76   //
 82   G4int ierr = 1;                                  77   G4int ierr = 1;
 83                                                    78 
 84   G4ErrorPropagatorData* g4edata =                 79   G4ErrorPropagatorData* g4edata =
 85     G4ErrorPropagatorData::GetErrorPropagatorD     80     G4ErrorPropagatorData::GetErrorPropagatorData();
 86                                                    81 
 87   //----- Do not propagate zero or too low ene     82   //----- Do not propagate zero or too low energy particles
 88   //                                               83   //
 89   if(currentTS->GetMomentum().mag() < 1.E-9 *  <<  84   if( currentTS->GetMomentum().mag() < 1.E-9*MeV )
 90   {                                                85   {
 91     std::ostringstream message;                    86     std::ostringstream message;
 92     message << "Energy too low to be propagate     87     message << "Energy too low to be propagated: "
 93             << G4BestUnit(currentTS->GetMoment <<  88             << G4BestUnit(currentTS->GetMomentum().mag(),"Energy");
 94     G4Exception("G4ErrorPropagator::Propagate(     89     G4Exception("G4ErrorPropagator::Propagate()", "GEANT4e-Notification",
 95                 JustWarning, message);             90                 JustWarning, message);
 96     return -3;                                 <<  91     return -3; 
 97   }                                                92   }
 98                                                    93 
 99   g4edata->SetMode(mode);                      <<  94   g4edata->SetMode( mode );
100                                                    95 
101 #ifdef G4EVERBOSE                                  96 #ifdef G4EVERBOSE
102   if(verbose >= 1)                             <<  97   if( verbose >= 1 )
103   {                                                98   {
104     G4cout << " =====> starting GEANT4E tracki <<  99      G4cout << " =====> starting GEANT4E tracking for "
105            << currentTS->GetParticleType()     << 100             << currentTS->GetParticleType()
106            << "  Forwards= " << g4edata->GetMo << 101             << "  Forwards= " << g4edata->GetMode() << G4endl;
107   }                                               102   }
108   if(verbose >= 1)                             << 103   if(verbose >= 1 )
109   {                                               104   {
110     G4cout << G4endl << "@@@@@@@@@@@@@@@@@@@@@ << 105      G4cout << G4endl << "@@@@@@@@@@@@@@@@@@@@@@@@@ NEW STEP " << G4endl;
111   }                                               106   }
112                                                   107 
113   if(verbose >= 3)                             << 108   if( verbose >= 3 )
114   {                                               109   {
115     G4cout << " G4ErrorPropagator::Propagate i    110     G4cout << " G4ErrorPropagator::Propagate initialTS ";
116     G4cout << *currentTS << G4endl;               111     G4cout << *currentTS << G4endl;
117     target->Dump(G4String(" to target "));        112     target->Dump(G4String(" to target "));
118   }                                               113   }
119 #endif                                            114 #endif
120                                                   115 
121   g4edata->SetTarget(target);                  << 116   g4edata->SetTarget( target );
122                                                   117 
123   //----- Create a track                          118   //----- Create a track
124   //                                              119   //
125   if(theG4Track != 0)                          << 120   if( theG4Track != 0 ) { delete theG4Track; }
126   {                                            << 121   theG4Track = InitG4Track( *currentTS );
127     delete theG4Track;                         << 
128   }                                            << 
129   theG4Track = InitG4Track(*currentTS);        << 
130                                                   122 
131   //----- Create a G4ErrorFreeTrajState           123   //----- Create a G4ErrorFreeTrajState
132   //                                              124   //
133   G4ErrorFreeTrajState* currentTS_FREE = InitF << 125   G4ErrorFreeTrajState* currentTS_FREE = InitFreeTrajState( currentTS );
134                                                   126 
135   //----- Track the particle                      127   //----- Track the particle
136   //                                              128   //
137   ierr = MakeSteps(currentTS_FREE);            << 129   ierr = MakeSteps( currentTS_FREE );
138                                                   130 
139   //------ Tracking ended, check if target has    131   //------ Tracking ended, check if target has been reached
140   //       if target not found                    132   //       if target not found
141   //                                              133   //
142   if(g4edata->GetState() != G4ErrorState_Stopp << 134   if( g4edata->GetState() != G4ErrorState_StoppedAtTarget )
143   {                                               135   {
144     if(theG4Track->GetKineticEnergy() > 0.)    << 136     if( theG4Track->GetKineticEnergy() > 0. )
145     {                                             137     {
146       ierr = -ierr - 10;                          138       ierr = -ierr - 10;
147     }                                             139     }
148     else                                          140     else
149     {                                             141     {
150       ierr = -ierr - 20;                          142       ierr = -ierr - 20;
151     }                                             143     }
152     *currentTS = *currentTS_FREE;                 144     *currentTS = *currentTS_FREE;
153     if(verbose >= 0)                           << 145     if(verbose >= 0 )
154     {                                             146     {
155       std::ostringstream message;                 147       std::ostringstream message;
156       message << "Particle does not reach targ    148       message << "Particle does not reach target: " << *currentTS;
157       G4Exception("G4ErrorPropagator::Propagat    149       G4Exception("G4ErrorPropagator::Propagate()", "GEANT4e-Notification",
158                   JustWarning, message);          150                   JustWarning, message);
159     }                                             151     }
160   }                                               152   }
161   else                                            153   else
162   {                                               154   {
163     GetFinalTrajState(currentTS, currentTS_FRE << 155     GetFinalTrajState( currentTS, currentTS_FREE, target );
164   }                                               156   }
165                                                   157 
166 #ifdef G4EVERBOSE                                 158 #ifdef G4EVERBOSE
167   if(verbose >= 1)                             << 159   if( verbose >= 1 )
168   {                                               160   {
169     G4cout << " G4ErrorPropagator: propagation    161     G4cout << " G4ErrorPropagator: propagation ended " << G4endl;
170   }                                               162   }
171   if(verbose >= 2)                             << 163   if( verbose >= 2 )
172   {                                               164   {
173     G4cout << " Current TrajState " << current    165     G4cout << " Current TrajState " << currentTS << G4endl;
174   }                                               166   }
175 #endif                                            167 #endif
176                                                << 168  
177   // Inform end of tracking to physics process    169   // Inform end of tracking to physics processes
178   //                                              170   //
179   theG4Track->GetDefinition()->GetProcessManag    171   theG4Track->GetDefinition()->GetProcessManager()->EndTracking();
180                                                   172 
181   InvokePostUserTrackingAction(theG4Track);    << 173   InvokePostUserTrackingAction( theG4Track );
182                                                   174 
183   // delete currentTS_FREE;                       175   // delete currentTS_FREE;
184                                                   176 
185   return ierr;                                    177   return ierr;
186 }                                                 178 }
187                                                   179 
                                                   >> 180 
188 //--------------------------------------------    181 //-----------------------------------------------------------------------
189 G4int G4ErrorPropagator::PropagateOneStep(G4Er << 182 G4int G4ErrorPropagator::PropagateOneStep( G4ErrorTrajState* currentTS )
190 {                                                 183 {
191   G4ErrorPropagatorData* g4edata =                184   G4ErrorPropagatorData* g4edata =
192     G4ErrorPropagatorData::GetErrorPropagatorD    185     G4ErrorPropagatorData::GetErrorPropagatorData();
193                                                   186 
194   if((g4edata->GetState() == G4ErrorState_PreI << 187   if ( (g4edata->GetState() == G4ErrorState_PreInit)
195      (G4StateManager::GetStateManager()->GetCu << 188     || (G4StateManager::GetStateManager()->GetCurrentState()
196       G4State_GeomClosed))                     << 189        != G4State_GeomClosed) )
197   {                                               190   {
198     std::ostringstream message;                   191     std::ostringstream message;
199     message << "Called before initialization i    192     message << "Called before initialization is done for this track!";
200     G4Exception("G4ErrorPropagator::PropagateO << 193     G4Exception("G4ErrorPropagator::PropagateOneStep()",
201                 FatalException, message,       << 194                 "InvalidCall", FatalException, message,
202                 "Please call G4ErrorPropagator    195                 "Please call G4ErrorPropagatorManager::InitGeant4e().");
203   }                                               196   }
204                                                   197 
205   // to start ierror is set to 0 (= OK)           198   // to start ierror is set to 0 (= OK)
206   //                                              199   //
207   G4int ierr = 0;                                 200   G4int ierr = 0;
208                                                   201 
209   //--- Do not propagate zero or too low energ    202   //--- Do not propagate zero or too low energy particles
210   //                                              203   //
211   if(currentTS->GetMomentum().mag() < 1.E-9 *  << 204   if( currentTS->GetMomentum().mag() < 1.E-9*MeV )
212   {                                               205   {
213     std::ostringstream message;                   206     std::ostringstream message;
214     message << "Energy too low to be propagate    207     message << "Energy too low to be propagated: "
215             << G4BestUnit(currentTS->GetMoment << 208             << G4BestUnit(currentTS->GetMomentum().mag(),"Energy");
216     G4Exception("G4ErrorPropagator::PropagateO << 209     G4Exception("G4ErrorPropagator::PropagateOneStep()",
217                 JustWarning, message);         << 210                 "GEANT4e-Notification", JustWarning, message);
218     return -3;                                 << 211     return -3;   
219   }                                               212   }
220                                                   213 
221 #ifdef G4EVERBOSE                                 214 #ifdef G4EVERBOSE
222   if(verbose >= 1)                             << 215   if( verbose >= 1 )
223   {                                               216   {
224     G4cout << " =====> starting GEANT4E tracki    217     G4cout << " =====> starting GEANT4E tracking for "
225            << currentTS->GetParticleType()        218            << currentTS->GetParticleType()
226            << "  Forwards= " << g4edata->GetMo    219            << "  Forwards= " << g4edata->GetMode() << G4endl;
227   }                                               220   }
228   if(verbose >= 3)                             << 221   if( verbose >= 3 )
229   {                                               222   {
230     G4cout << " G4ErrorPropagator::Propagate i    223     G4cout << " G4ErrorPropagator::Propagate initialTS ";
231     G4cout << *currentTS << G4endl;               224     G4cout << *currentTS << G4endl;
232   }                                               225   }
233 #endif                                            226 #endif
234                                                   227 
235   //----- If it is the first step, create a tr    228   //----- If it is the first step, create a track
236   //                                              229   //
237   if(theStepN == 0)                            << 230   if( theStepN == 0 )
238   {                                               231   {
239     if(theG4Track != 0)                        << 232     if( theG4Track != 0 ) { delete theG4Track; }
240     {                                          << 233     theG4Track = InitG4Track( *currentTS );
241       delete theG4Track;                       << 
242     }                                          << 
243     theG4Track = InitG4Track(*currentTS);      << 
244   }                                               234   }
245   // set to 0 by the initialization in G4Error << 235     // set to 0 by the initialization in G4ErrorPropagatorManager
246   theStepN++;                                     236   theStepN++;
247                                                   237 
248   //----- Create a G4ErrorFreeTrajState           238   //----- Create a G4ErrorFreeTrajState
249   //                                              239   //
250   G4ErrorFreeTrajState* currentTS_FREE = InitF << 240   G4ErrorFreeTrajState* currentTS_FREE = InitFreeTrajState( currentTS );
251                                                   241 
252   //----- Track the particle one step             242   //----- Track the particle one step
253   //                                              243   //
254   ierr = MakeOneStep(currentTS_FREE);          << 244   ierr = MakeOneStep( currentTS_FREE );
255                                                   245 
256   //----- Get the state on target                 246   //----- Get the state on target
257   //                                              247   //
258   GetFinalTrajState(currentTS, currentTS_FREE, << 248   GetFinalTrajState( currentTS, currentTS_FREE, g4edata->GetTarget() );
259                                                   249 
260   return ierr;                                    250   return ierr;
261 }                                                 251 }
262                                                   252 
                                                   >> 253 
263 //--------------------------------------------    254 //---------------------------------------------------------------------------
264 G4Track* G4ErrorPropagator::InitG4Track(G4Erro << 255 G4Track* G4ErrorPropagator::InitG4Track( G4ErrorTrajState& initialTS )
265 {                                                 256 {
266   if(verbose >= 5)                             << 257   if( verbose >= 5 ) { G4cout << "InitG4Track " << G4endl; }
267   {                                            << 
268     G4cout << "InitG4Track " << G4endl;        << 
269   }                                            << 
270                                                   258 
271   //----- Create Particle                         259   //----- Create Particle
272   //                                              260   //
273   const G4String partType        = initialTS.G << 261   const G4String partType = initialTS.GetParticleType();
274   G4ParticleTable* particleTable = G4ParticleT    262   G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
275   G4ParticleDefinition* particle = particleTab << 263   G4ParticleDefinition* particle = particleTable->FindParticle(partType); 
276   if(particle == 0)                            << 264   if( particle == 0)
277   {                                               265   {
278     std::ostringstream message;                   266     std::ostringstream message;
279     message << "Particle type not defined: " <    267     message << "Particle type not defined: " << partType;
280     G4Exception("G4ErrorPropagator::InitG4Trac    268     G4Exception("G4ErrorPropagator::InitG4Track()", "InvalidSetup",
281                 FatalException, message);         269                 FatalException, message);
282   }                                               270   }
                                                   >> 271  
                                                   >> 272   G4DynamicParticle* DP = 
                                                   >> 273     new G4DynamicParticle(particle,initialTS.GetMomentum());
283                                                   274 
284   G4DynamicParticle* DP =                      << 275   DP->SetPolarization(0.,0.,0.);
285     new G4DynamicParticle(particle, initialTS. << 
286                                                << 
287   DP->SetPolarization(0., 0., 0.);             << 
288                                                   276 
289   // Set Charge                                   277   // Set Charge
290   //                                              278   //
291   if(particle->GetPDGCharge() < 0)             << 279   if( particle->GetPDGCharge() < 0 )
292   {                                               280   {
293     DP->SetCharge(-eplus);                        281     DP->SetCharge(-eplus);
294   }                                               282   }
295   else                                            283   else
296   {                                               284   {
297     DP->SetCharge(eplus);                         285     DP->SetCharge(eplus);
298   }                                               286   }
299                                                   287 
300   //----- Create Track                         << 288   //----- Create Track 
301   //                                              289   //
302   theG4Track = new G4Track(DP, 0., initialTS.G << 290   theG4Track = new G4Track(DP, 0., initialTS.GetPosition() );
303   theG4Track->SetParentID(0);                     291   theG4Track->SetParentID(0);
304                                                   292 
305 #ifdef G4EVERBOSE                                 293 #ifdef G4EVERBOSE
306   if(verbose >= 3)                                294   if(verbose >= 3)
307   {                                               295   {
308     G4cout << " G4ErrorPropagator new track of    296     G4cout << " G4ErrorPropagator new track of energy: "
309            << theG4Track->GetKineticEnergy() <    297            << theG4Track->GetKineticEnergy() << G4endl;
310   }                                               298   }
311 #endif                                            299 #endif
312                                                << 300   
313   //---- Reproduce G4TrackingManager::ProcessO    301   //---- Reproduce G4TrackingManager::ProcessOneTrack initialization
314   InvokePreUserTrackingAction(theG4Track);     << 302   InvokePreUserTrackingAction( theG4Track );  
315                                                   303 
316   if(fpSteppingManager == 0)                   << 304   if( fpSteppingManager == 0 )
317   {                                               305   {
318     G4Exception("G4ErrorPropagator::InitG4Trac    306     G4Exception("G4ErrorPropagator::InitG4Track()", "InvalidSetup",
319                 FatalException, "G4SteppingMan    307                 FatalException, "G4SteppingManager not initialized yet!");
320   }                                               308   }
321   else                                            309   else
322   {                                               310   {
323     fpSteppingManager->SetInitialStep(theG4Tra    311     fpSteppingManager->SetInitialStep(theG4Track);
324   }                                               312   }
325                                                   313 
326   // Give SteppingManger the maximum number of    314   // Give SteppingManger the maximum number of processes
327   //                                              315   //
328   fpSteppingManager->GetProcessNumber();          316   fpSteppingManager->GetProcessNumber();
329                                                   317 
330   // Give track the pointer to the Step           318   // Give track the pointer to the Step
331   //                                              319   //
332   theG4Track->SetStep(fpSteppingManager->GetSt    320   theG4Track->SetStep(fpSteppingManager->GetStep());
333                                                   321 
334   // Inform beginning of tracking to physics p    322   // Inform beginning of tracking to physics processes
335   //                                              323   //
336   theG4Track->GetDefinition()->GetProcessManag    324   theG4Track->GetDefinition()->GetProcessManager()->StartTracking(theG4Track);
337                                                   325 
338   initialTS.SetG4Track(theG4Track);            << 326   initialTS.SetG4Track( theG4Track );
339                                                   327 
340   return theG4Track;                              328   return theG4Track;
341 }                                                 329 }
342                                                   330 
                                                   >> 331 
343 //--------------------------------------------    332 //-----------------------------------------------------------------------
344 G4int G4ErrorPropagator::MakeSteps(G4ErrorFree << 333 G4int G4ErrorPropagator::MakeSteps( G4ErrorFreeTrajState* currentTS_FREE )
345 {                                                 334 {
346   G4int ierr = 0;                                 335   G4int ierr = 0;
347                                                   336 
348   //----- Track the particle Step-by-Step whil    337   //----- Track the particle Step-by-Step while it is alive
349   //                                              338   //
350   theStepLength = 0.;                             339   theStepLength = 0.;
351                                                << 340   
352   while((theG4Track->GetTrackStatus() == fAliv << 341   while( (theG4Track->GetTrackStatus() == fAlive) ||
353         (theG4Track->GetTrackStatus() == fStop << 342          (theG4Track->GetTrackStatus() == fStopButAlive) )
354   {                                               343   {
355     ierr = MakeOneStep(currentTS_FREE);        << 344     ierr = MakeOneStep( currentTS_FREE );
356     if(ierr != 0)                              << 345     if( ierr != 0 ) { break; }
357     {                                          << 
358       break;                                   << 
359     }                                          << 
360                                                   346 
361     //----- Check if last step for error propa    347     //----- Check if last step for error propagation
362     //                                            348     //
363     if(CheckIfLastStep(theG4Track))            << 349     if( CheckIfLastStep( theG4Track ) )
364     {                                             350     {
365       break;                                      351       break;
366     }                                             352     }
367   }  // Loop checking, 06.08.2015, G.Cosmo        353   }  // Loop checking, 06.08.2015, G.Cosmo
368   return ierr;                                    354   return ierr;
369 }                                                 355 }
370                                                   356 
                                                   >> 357 
371 //--------------------------------------------    358 //-----------------------------------------------------------------------
372 G4int G4ErrorPropagator::MakeOneStep(G4ErrorFr << 359 G4int G4ErrorPropagator::MakeOneStep( G4ErrorFreeTrajState* currentTS_FREE )
373 {                                                 360 {
374   G4ErrorPropagatorData* g4edata =                361   G4ErrorPropagatorData* g4edata =
375     G4ErrorPropagatorData::GetErrorPropagatorD    362     G4ErrorPropagatorData::GetErrorPropagatorData();
376   G4int ierr = 0;                                 363   G4int ierr = 0;
377                                                   364 
378   //---------- Track one step                     365   //---------- Track one step
379 #ifdef G4EVERBOSE                                 366 #ifdef G4EVERBOSE
380   if(verbose >= 2)                             << 367   if(verbose >= 2 )
381   {                                               368   {
382     G4cout << G4endl << "@@@@@@@@@@@@@@@@@@@@@ << 369     G4cout << G4endl
                                                   >> 370            << "@@@@@@@@@@@@@@@@@@@@@@@@@ NEW STEP " << G4endl;
383   }                                               371   }
384 #endif                                            372 #endif
385                                                << 373   
386   theG4Track->IncrementCurrentStepNumber();       374   theG4Track->IncrementCurrentStepNumber();
387                                                   375 
388   fpSteppingManager->Stepping();                  376   fpSteppingManager->Stepping();
389                                                << 377   
390   //---------- Check if Target has been reache    378   //---------- Check if Target has been reached (and then set G4ErrorState)
391                                                   379 
392   // G4ErrorPropagationNavigator limits the st    380   // G4ErrorPropagationNavigator limits the step if target is closer than
393   // boundary (but the winner process is alway    381   // boundary (but the winner process is always "Transportation": then
394   // error propagator will stop the track         382   // error propagator will stop the track
395                                                   383 
396   if(theG4Track->GetStep()                     << 384   if( theG4Track->GetStep()->GetPostStepPoint()
397        ->GetPostStepPoint()                    << 385       ->GetProcessDefinedStep()->GetProcessName() == "Transportation" )
398        ->GetProcessDefinedStep()               << 
399        ->GetProcessName() == "Transportation") << 
400   {                                               386   {
401     if(g4edata->GetState() ==                  << 387     if( g4edata->GetState()
402        G4ErrorState(G4ErrorState_TargetCloserT << 388        == G4ErrorState(G4ErrorState_TargetCloserThanBoundary) )
403     {  // target or step length reached           389     {  // target or step length reached
404                                                << 390       
405 #ifdef G4EVERBOSE                                 391 #ifdef G4EVERBOSE
406       if(verbose >= 5)                         << 392       if(verbose >= 5 )
407       {                                           393       {
408         G4cout << " transportation determined     394         G4cout << " transportation determined by geant4e " << G4endl;
409       }                                           395       }
410 #endif                                         << 396 #endif      
411       g4edata->SetState(G4ErrorState_StoppedAt << 397       g4edata->SetState( G4ErrorState_StoppedAtTarget );
412     }                                             398     }
413     else if(g4edata->GetTarget()->GetType() == << 399     else if( g4edata->GetTarget()->GetType() == G4ErrorTarget_GeomVolume )
414     {                                             400     {
415       G4ErrorGeomVolumeTarget* target =           401       G4ErrorGeomVolumeTarget* target =
416         (G4ErrorGeomVolumeTarget*) (g4edata->G << 402         (G4ErrorGeomVolumeTarget*)(g4edata->GetTarget());
417       if(static_cast<G4ErrorGeomVolumeTarget*> << 403       if( static_cast<G4ErrorGeomVolumeTarget*>( target )
418            theG4Track->GetStep()))             << 404           ->TargetReached( theG4Track->GetStep() ) )
419       {                                           405       {
420         g4edata->SetState(G4ErrorState_Stopped << 406         g4edata->SetState( G4ErrorState_StoppedAtTarget ); 
421       }                                        << 407       } 
422     }                                             408     }
423   }                                               409   }
424   else if(theG4Track->GetStep()                << 410   else if( theG4Track->GetStep()->GetPostStepPoint()->GetProcessDefinedStep()
425             ->GetPostStepPoint()               << 411            ->GetProcessName() == "G4ErrorTrackLengthTarget" )
426             ->GetProcessDefinedStep()          << 
427             ->GetProcessName() == "G4ErrorTrac << 
428   {                                               412   {
429     g4edata->SetState(G4ErrorState_StoppedAtTa << 413     g4edata->SetState( G4ErrorState_StoppedAtTarget );
430   }                                               414   }
431                                                   415 
432   //---------- Propagate error                 << 416   //---------- Propagate error  
433                                                   417 
434 #ifdef G4EVERBOSE                                 418 #ifdef G4EVERBOSE
435   if(verbose >= 2)                             << 419   if(verbose >= 2 )
436   {                                               420   {
437     G4cout << " propagating error " << *curren    421     G4cout << " propagating error " << *currentTS_FREE << G4endl;
438   }                                               422   }
439 #endif                                            423 #endif
440   const G4Track* cTrack = const_cast<G4Track*>    424   const G4Track* cTrack = const_cast<G4Track*>(theG4Track);
441   ierr                  = currentTS_FREE->Prop << 425   ierr = currentTS_FREE->PropagateError( cTrack );
442                                                << 426   
443 #ifdef G4EVERBOSE                                 427 #ifdef G4EVERBOSE
444   if(verbose >= 3)                             << 428   if(verbose >= 3 )
445   {                                               429   {
446     G4cout << " PropagateError returns " << ie    430     G4cout << " PropagateError returns " << ierr << G4endl;
447   }                                               431   }
448 #endif                                            432 #endif
449                                                   433 
450   currentTS_FREE->Update(cTrack);              << 434   currentTS_FREE->Update( cTrack );
451                                                << 435   
452   theStepLength += theG4Track->GetStepLength()    436   theStepLength += theG4Track->GetStepLength();
453                                                << 437    
454   if(ierr != 0)                                << 438   if(ierr != 0 )
455   {                                               439   {
456     std::ostringstream message;                   440     std::ostringstream message;
457     message << "Error returned: " << ierr;        441     message << "Error returned: " << ierr;
458     G4Exception("G4ErrorPropagator::MakeOneSte << 442     G4Exception("G4ErrorPropagator::MakeOneStep()",
459                 JustWarning, message, "Geant4  << 443                 "GEANT4e-Notification", JustWarning, message,
                                                   >> 444                 "Geant4 tracking will be stopped !");
460   }                                               445   }
461                                                   446 
462   return ierr;                                 << 447   return ierr; 
463 }                                                 448 }
464                                                   449 
                                                   >> 450 
465 //--------------------------------------------    451 //-----------------------------------------------------------------------
466 G4ErrorFreeTrajState* G4ErrorPropagator::InitF << 452 G4ErrorFreeTrajState*
467   G4ErrorTrajState* currentTS)                 << 453 G4ErrorPropagator::InitFreeTrajState( G4ErrorTrajState* currentTS )
468 {                                                 454 {
469   G4ErrorFreeTrajState* currentTS_FREE = 0;       455   G4ErrorFreeTrajState* currentTS_FREE = 0;
470                                                   456 
471   //----- Transform the TrajState to Free coor    457   //----- Transform the TrajState to Free coordinates if it is OnSurface
472   //                                              458   //
473   if(currentTS->GetTSType() == G4eTS_OS)       << 459   if( currentTS->GetTSType() == G4eTS_OS )
474   {                                               460   {
475     G4ErrorSurfaceTrajState* tssd =               461     G4ErrorSurfaceTrajState* tssd =
476       static_cast<G4ErrorSurfaceTrajState*>(cu    462       static_cast<G4ErrorSurfaceTrajState*>(currentTS);
477     currentTS_FREE = new G4ErrorFreeTrajState( << 463     currentTS_FREE = new G4ErrorFreeTrajState( *tssd );
478   }                                               464   }
479   else if(currentTS->GetTSType() == G4eTS_FREE << 465   else if( currentTS->GetTSType() == G4eTS_FREE )
480   {                                               466   {
481     currentTS_FREE = static_cast<G4ErrorFreeTr    467     currentTS_FREE = static_cast<G4ErrorFreeTrajState*>(currentTS);
482   }                                               468   }
483   else                                            469   else
484   {                                               470   {
485     std::ostringstream message;                   471     std::ostringstream message;
486     message << "Wrong trajectory state: " << c    472     message << "Wrong trajectory state: " << currentTS->GetTSType();
487     G4Exception("G4ErrorPropagator::InitFreeTr    473     G4Exception("G4ErrorPropagator::InitFreeTrajState()", "InvalidState",
488                 FatalException, message);         474                 FatalException, message);
489   }                                               475   }
490   return currentTS_FREE;                          476   return currentTS_FREE;
491 }                                                 477 }
492                                                   478 
                                                   >> 479 
493 //--------------------------------------------    480 //-----------------------------------------------------------------------
494 void G4ErrorPropagator::GetFinalTrajState(G4Er << 481 void G4ErrorPropagator::GetFinalTrajState( G4ErrorTrajState* currentTS,
495                                           G4Er << 482                                            G4ErrorFreeTrajState* currentTS_FREE,
496                                           cons << 483                                            const G4ErrorTarget* target ) 
497 {                                                 484 {
498   G4ErrorPropagatorData* g4edata =                485   G4ErrorPropagatorData* g4edata =
499     G4ErrorPropagatorData::GetErrorPropagatorD    486     G4ErrorPropagatorData::GetErrorPropagatorData();
500                                                   487 
501 #ifdef G4EVERBOSE                                 488 #ifdef G4EVERBOSE
502   if(verbose >= 1)                             << 489   if(verbose >= 1 )
503   {                                               490   {
504     G4cout << " G4ErrorPropagator::Propagate:     491     G4cout << " G4ErrorPropagator::Propagate: final state "
505            << G4int(g4edata->GetState()) << "  << 492            << G4int(g4edata->GetState()) << " TSType "
506            << G4endl;                          << 493            << currentTS->GetTSType() << G4endl;
507   }                                               494   }
508 #endif                                            495 #endif
509                                                   496 
510   if((currentTS->GetTSType() == G4eTS_FREE) || << 497   if( (currentTS->GetTSType() == G4eTS_FREE) || 
511      (g4edata->GetState() != G4ErrorState_Stop << 498       (g4edata->GetState() != G4ErrorState_StoppedAtTarget) )
512   {                                               499   {
513     currentTS = currentTS_FREE;                   500     currentTS = currentTS_FREE;
514   }                                               501   }
515   else if(currentTS->GetTSType() == G4eTS_OS)  << 502   else if( currentTS->GetTSType() == G4eTS_OS )
516   {                                               503   {
517     if(target->GetType() == G4ErrorTarget_TrkL << 504     if( target->GetType() == G4ErrorTarget_TrkL )
518     {                                             505     {
519       G4Exception("G4ErrorPropagator:GetFinalT << 506       G4Exception("G4ErrorPropagator:GetFinalTrajState()",
520                   FatalException,              << 507                   "InvalidSetup", FatalException,
521                   "Using a G4ErrorSurfaceTrajS    508                   "Using a G4ErrorSurfaceTrajState with wrong target");
522     }                                             509     }
523     const G4ErrorTanPlaneTarget* targetWTP =      510     const G4ErrorTanPlaneTarget* targetWTP =
524       static_cast<const G4ErrorTanPlaneTarget*    511       static_cast<const G4ErrorTanPlaneTarget*>(target);
525     *currentTS = G4ErrorSurfaceTrajState(         512     *currentTS = G4ErrorSurfaceTrajState(
526       *(static_cast<G4ErrorFreeTrajState*>(cur << 513                  *(static_cast<G4ErrorFreeTrajState*>(currentTS_FREE)),
527       targetWTP->GetTangentPlane(currentTS_FRE << 514                  targetWTP->GetTangentPlane( currentTS_FREE->GetPosition() ) );
528 #ifdef G4EVERBOSE                                 515 #ifdef G4EVERBOSE
529     if(verbose >= 1)                           << 516     if(verbose >= 1 )
530     {                                             517     {
531       G4cout << currentTS << " returning tssd     518       G4cout << currentTS << " returning tssd " << *currentTS << G4endl;
532     }                                             519     }
533 #endif                                            520 #endif
534     delete currentTS_FREE;                        521     delete currentTS_FREE;
535   }                                               522   }
536 }                                                 523 }
537                                                   524 
                                                   >> 525 
538 //--------------------------------------------    526 //-------------------------------------------------------------------------
539 G4bool G4ErrorPropagator::CheckIfLastStep(G4Tr << 527 G4bool G4ErrorPropagator::CheckIfLastStep( G4Track* aTrack )
540 {                                                 528 {
                                                   >> 529   G4bool exception = 0;
541   G4bool lastG4eStep = false;                     530   G4bool lastG4eStep = false;
542   G4ErrorPropagatorData* g4edata =                531   G4ErrorPropagatorData* g4edata =
543     G4ErrorPropagatorData::GetErrorPropagatorD    532     G4ErrorPropagatorData::GetErrorPropagatorData();
544                                                   533 
545 #ifdef G4EVERBOSE                                 534 #ifdef G4EVERBOSE
546   if(verbose >= 4)                             << 535   if( verbose >= 4 )
547   {                                               536   {
548     G4cout << " G4ErrorPropagator::CheckIfLast    537     G4cout << " G4ErrorPropagator::CheckIfLastStep G4ErrorState= "
549            << G4int(g4edata->GetState()) << G4    538            << G4int(g4edata->GetState()) << G4endl;
550   }                                               539   }
551 #endif                                            540 #endif
552                                                << 541   
553   //----- Check if this is the last step: trac    542   //----- Check if this is the last step: track has reached the target
554   //      or the end of world                     543   //      or the end of world
555   //                                              544   //
556   if(g4edata->GetState() == G4ErrorState(G4Err << 545   if(g4edata->GetState() == G4ErrorState(G4ErrorState_StoppedAtTarget) )
557   {                                               546   {
558     lastG4eStep = true;                        << 547     lastG4eStep = true;    
559 #ifdef G4EVERBOSE                                 548 #ifdef G4EVERBOSE
560     if(verbose >= 5)                           << 549     if(verbose >= 5 )
561     {                                             550     {
562       G4cout << " G4ErrorPropagator::CheckIfLa << 551       G4cout << " G4ErrorPropagator::CheckIfLastStep " << lastG4eStep
563              << G4int(g4edata->GetState()) <<  << 552              << " " << G4int(g4edata->GetState()) << G4endl;
564     }                                             553     }
565 #endif                                            554 #endif
566   }                                               555   }
567   else if(aTrack->GetNextVolume() == 0)        << 556   else if( aTrack->GetNextVolume() == 0 )
568   {                                               557   {
569     //----- If particle is out of world, witho    558     //----- If particle is out of world, without finding the G4ErrorTarget,
570     //      give a n error/warning                559     //      give a n error/warning
571     //                                            560     //
572     lastG4eStep = true;                           561     lastG4eStep = true;
573     if(verbose >= 1)                           << 562     if( exception )
574     {                                             563     {
575       std::ostringstream message;                 564       std::ostringstream message;
576       message << "Track extrapolated until end    565       message << "Track extrapolated until end of World" << G4endl
577               << "without finding the defined  << 566               << "without finding the defined target!";
578       G4Exception("G4ErrorPropagator::CheckIfL    567       G4Exception("G4ErrorPropagator::CheckIfLastStep()",
579                   "GEANT4e-Notification", Just << 568                   "InvalidSetup", FatalException, message);
                                                   >> 569     }
                                                   >> 570     else
                                                   >> 571     {
                                                   >> 572       if( verbose >= 1 )
                                                   >> 573       {
                                                   >> 574         std::ostringstream message;
                                                   >> 575         message << "Track extrapolated until end of World" << G4endl
                                                   >> 576                 << "without finding the defined target.";
                                                   >> 577         G4Exception("G4ErrorPropagator::CheckIfLastStep()",
                                                   >> 578                     "GEANT4e-Notification", JustWarning, message);
                                                   >> 579       }
580     }                                             580     }
581   }  //----- not last step from G4e, but track    581   }  //----- not last step from G4e, but track is stopped (energy exhausted)
582   else if(aTrack->GetTrackStatus() == fStopAnd << 582   else if( aTrack->GetTrackStatus() == fStopAndKill )
583   {                                            << 583   { 
584     if(verbose >= 1)                           << 584     if( exception )
585     {                                             585     {
586       std::ostringstream message;                 586       std::ostringstream message;
587       message << "Track extrapolated until ene    587       message << "Track extrapolated until energy is exhausted" << G4endl
588               << "without finding the defined  << 588               << "without finding the defined target!";
589       G4Exception("G4ErrorPropagator::CheckIfL    589       G4Exception("G4ErrorPropagator::CheckIfLastStep()",
590                   "GEANT4e-Notification", Just << 590                   "InvalidSetup", FatalException, message);
                                                   >> 591     }
                                                   >> 592     else
                                                   >> 593     {
                                                   >> 594       if( verbose >= 1 )
                                                   >> 595       {
                                                   >> 596         std::ostringstream message;
                                                   >> 597         message << "Track extrapolated until energy is exhausted" << G4endl
                                                   >> 598                 << "without finding the defined target.";
                                                   >> 599         G4Exception("G4ErrorPropagator::CheckIfLastStep()",
                                                   >> 600                     "GEANT4e-Notification", JustWarning, message);
                                                   >> 601       }
                                                   >> 602       lastG4eStep = 1;
591     }                                             603     }
592     lastG4eStep = 1;                           << 
593   }                                               604   }
594                                                   605 
595 #ifdef G4EVERBOSE                                 606 #ifdef G4EVERBOSE
596   if(verbose >= 5)                             << 607   if( verbose >= 5 )
597   {                                               608   {
598     G4cout << " return CheckIfLastStep " << la    609     G4cout << " return CheckIfLastStep " << lastG4eStep << G4endl;
599   }                                               610   }
600 #endif                                            611 #endif
601                                                   612 
602   return lastG4eStep;                          << 613   return  lastG4eStep;
603 }                                                 614 }
604                                                   615 
                                                   >> 616 
605 //--------------------------------------------    617 //---------------------------------------------------------------------------
606 void G4ErrorPropagator::InvokePreUserTrackingA << 618 void G4ErrorPropagator::InvokePreUserTrackingAction( G4Track* fpTrack )
607 {                                                 619 {
608   const G4UserTrackingAction* fpUserTrackingAc    620   const G4UserTrackingAction* fpUserTrackingAction =
609     G4EventManager::GetEventManager()->GetUser    621     G4EventManager::GetEventManager()->GetUserTrackingAction();
610   if(fpUserTrackingAction != 0)                << 622   if( fpUserTrackingAction != 0 )
611   {                                               623   {
612     const_cast<G4UserTrackingAction*>(fpUserTr    624     const_cast<G4UserTrackingAction*>(fpUserTrackingAction)
613       ->PreUserTrackingAction((fpTrack));      << 625       ->PreUserTrackingAction((fpTrack) );
614   }                                               626   }
615 }                                                 627 }
616                                                   628 
                                                   >> 629 
617 //--------------------------------------------    630 //---------------------------------------------------------------------------
618 void G4ErrorPropagator::InvokePostUserTracking << 631 void G4ErrorPropagator::InvokePostUserTrackingAction( G4Track* fpTrack )
619 {                                                 632 {
620   const G4UserTrackingAction* fpUserTrackingAc    633   const G4UserTrackingAction* fpUserTrackingAction =
621     G4EventManager::GetEventManager()->GetUser    634     G4EventManager::GetEventManager()->GetUserTrackingAction();
622   if(fpUserTrackingAction != 0)                << 635   if( fpUserTrackingAction != 0 )
623   {                                               636   {
624     const_cast<G4UserTrackingAction*>(fpUserTr    637     const_cast<G4UserTrackingAction*>(fpUserTrackingAction)
625       ->PostUserTrackingAction((fpTrack));     << 638       ->PostUserTrackingAction((fpTrack) );
626   }                                               639   }
627 }                                                 640 }
628                                                   641