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