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.0)


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