00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "BDSGlobalConstants.hh"
00023
00024 #include "BDSSteppingAction.hh"
00025
00026 #include <iostream>
00027 #include "G4Track.hh"
00028
00029 #include"G4TransportationManager.hh"
00030 #include"G4FieldManager.hh"
00031
00032 #include"G4Navigator.hh"
00033 #include"G4StepPoint.hh"
00034 #include "G4RotationMatrix.hh"
00035 #include "G4AffineTransform.hh"
00036
00037 #include "BDSMaterials.hh"
00038 #include "G4Material.hh"
00039 #include "G4VSensitiveDetector.hh"
00040 #include "Randomize.hh"
00041
00042 #include "G4UserLimits.hh"
00043
00044 #include "BDSNeutronTrackInfo.hh"
00045
00046 #include "G4VUserTrackInformation.hh"
00047
00048 #include "G4VProcess.hh"
00049
00050 #include "G4MagneticField.hh"
00051 #include "G4EventManager.hh"
00052 #include "G4StackManager.hh"
00053 #include "G4ChordFinder.hh"
00054 #include "G4MagIntegratorDriver.hh"
00055 #include "G4Region.hh"
00056 #include "BDSAcceleratorComponent.hh"
00057
00058 #include "BDSQuadStepper.hh"
00059 #include "BDSSextStepper.hh"
00060 #include "BDSOctStepper.hh"
00061 #include "myQuadStepper.hh"
00062
00063 extern BDSMaterials* theMaterials;
00064
00065 typedef list<BDSAcceleratorComponent*> BDSBeamline;
00066 extern BDSBeamline theBeamline;
00067
00068 extern G4double BDS_Threshold_Energy;
00069 extern G4double BDSLocalRadiusOfCurvature;
00070
00071 extern G4int event_number;
00072
00073 extern G4double initial_x,initial_xp,initial_y,initial_yp,initial_z,initial_E;
00074
00075 extern G4bool verbose;
00076 extern G4bool verboseStep;
00077 extern G4bool verboseEvent;
00078 extern G4int verboseEventNumber;
00079 extern G4bool isBatch;
00080
00081 extern G4int nptwiss;
00082
00083
00084
00085
00086 BDSSteppingAction::BDSSteppingAction()
00087 {
00088
00089 itsZposTolerance=1.e-4*m;
00090 itsPosKick=1.e-11*m;
00091 itsNmax=10000;
00092 postponedEnergy=0;
00093 }
00094
00095
00096
00097 BDSSteppingAction::~BDSSteppingAction()
00098 { }
00099
00100
00101
00102
00103 extern G4double htot;
00104
00105 void BDSSteppingAction::UserSteppingAction(const G4Step* ThisStep)
00106 {
00107
00108
00109 G4Track* ThisTrack=ThisStep->GetTrack();
00110
00111
00112
00113 G4String pName=ThisTrack->GetDefinition()->GetParticleName();
00114
00115 if(ThisTrack->GetProperTime() > 1e-4*second)
00116 {
00117 G4cout << "WARNING: ProperTime > 1.e-4 second!" << G4endl;
00118 G4cout<<" Killing the particle"<<G4endl;
00119 ThisTrack->SetTrackStatus(fStopAndKill);
00120 }
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 if(BDSGlobals->DoTwiss() && ThisTrack->GetNextVolume())
00160 {
00161
00162 G4cout <<" ***"<< ThisTrack->GetVolume()->GetName()<<G4endl;
00163
00164 G4int curr_delim = ThisTrack->GetVolume()->GetName().find("_");
00165 G4String curr_gmad_name = ThisTrack->GetVolume()->GetName().substr(0,curr_delim);
00166 G4int delim = ThisTrack->GetNextVolume()->GetName().find("_");
00167 G4String gmad_name = ThisTrack->GetNextVolume()->GetName().substr(0,delim);
00168 if (curr_gmad_name != gmad_name && gmad_name!="World")
00169
00170 {
00171 G4cout << curr_gmad_name << " " << gmad_name << G4endl;
00172 G4ThreeVector pos = ThisTrack->GetPosition();
00173 postponedEnergy+=ThisTrack->GetTotalEnergy();
00174
00175 G4StackManager* SM = G4EventManager::GetEventManager()->GetStackManager();
00176
00177 if(SM->GetNPostponedTrack()!= nptwiss-1 ) {
00178
00179 ThisTrack->SetTrackStatus(fPostponeToNextEvent);
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255 }
00256
00257
00258 if(SM->GetNPostponedTrack()== nptwiss-1)
00259 {
00260 SM->TransferStackedTracks(fPostpone, fUrgent);
00261 if(verbose) G4cout << "\nMean Energy: " << (postponedEnergy/nptwiss)/GeV << G4endl;
00262
00263 list<BDSAcceleratorComponent*>::const_iterator iBeam;
00264 G4String type="";
00265 for(iBeam=theBeamline.begin();iBeam!=theBeamline.end();iBeam++)
00266 {
00267 if( (*iBeam)->GetName() == gmad_name)
00268 {
00269 type = (*iBeam)->GetType();
00270 if(verbose) G4cout << "Next Element is: " << (*iBeam)->GetName() << G4endl;
00271 if(verbose) G4cout << "Element Type: " << type << G4endl;
00272 G4double old_P0 = BDSGlobals->GetBeamTotalEnergy();
00273 G4double old_brho =
00274 sqrt(pow(old_P0,2)- pow(electron_mass_c2,2))/(0.299792458 * (GeV/(tesla*m)));
00275 G4double new_P0 = postponedEnergy/nptwiss;
00276 G4double new_brho =
00277 sqrt(pow(new_P0,2)- pow(electron_mass_c2,2))/(0.299792458 * (GeV/(tesla*m)));
00278
00279 if(BDSGlobals->GetSynchRescale())
00280 {
00281 (*iBeam)->SynchRescale(new_brho/old_brho);
00282
00283 if(verbose) G4cout << "Rescaling by: " << new_brho/old_brho << G4endl;
00284 G4cout << "*";
00285 G4cout.flush();
00286 }
00287 break;
00288 }
00289 }
00290 postponedEnergy=0;
00291 }
00292 return;
00293 }
00294 }
00295
00296
00297
00298
00299
00300 if(verboseStep && (!BDSGlobals->GetSynchRescale()) )
00301 {
00302
00303 int ID=ThisTrack->GetTrackID();
00304
00305
00306 G4cout.precision(10);
00307 G4cout<<"This volume="<< ThisTrack->GetVolume()->GetName()<<G4endl;
00308
00309 G4LogicalVolume* LogVol=ThisTrack->GetVolume()->GetLogicalVolume();
00310 G4cout<<"This log volume="<<LogVol->GetName() <<G4endl;
00311
00312 G4cout<<"ID="<<ID<<" part="<<
00313 ThisTrack->GetDefinition()->GetParticleName()<<
00314 "Energy="<<ThisTrack->GetTotalEnergy()/GeV<<
00315 " mom Px="
00316 <<ThisTrack->GetMomentum()[0]/GeV<<
00317 " Py="<<ThisTrack->GetMomentum()[1]/GeV<<
00318 " Pz="<<ThisTrack->GetMomentum()[2]/GeV<<" vol="<<
00319 ThisTrack->GetVolume()->GetName()<<G4endl;
00320
00321 G4cout<<" Global Position="<<ThisTrack->GetPosition()<<G4endl;
00322
00323
00324 if(ThisTrack->GetMaterial()->GetName() !="LCVacuum")
00325 G4cout<<"material="<<ThisTrack->GetMaterial()->GetName()<<G4endl;
00326
00327
00328
00329 G4VProcess* proc=(G4VProcess*)(ThisStep->GetPostStepPoint()->
00330 GetProcessDefinedStep() );
00331
00332 if(proc)G4cout<<" post-step process="<<proc->GetProcessName()<<G4endl<<G4endl;
00333
00334
00335 proc=(G4VProcess*)(ThisStep->GetPreStepPoint()->
00336 GetProcessDefinedStep() );
00337
00338 if(proc)G4cout<<" pre-step process="<<proc->GetProcessName()<<G4endl<<G4endl;
00339
00340
00341
00342 }
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356 {
00357
00358
00359 if(pName=="gamma")
00360 {
00361 G4double photonCut = BDSGlobals->GetThresholdCutPhotons();
00362
00363 if(ThisTrack->GetTotalEnergy()<photonCut)
00364 {
00365
00366 ThisTrack->SetTrackStatus(fStopAndKill);
00367
00368 }
00369 }
00370
00371 if(pName=="e-"||pName=="e+")
00372 {
00373 if(ThisTrack->GetTotalEnergy()<BDSGlobals->GetThresholdCutCharged())
00374 {
00375
00376 ThisTrack->SetTrackStatus(fStopAndKill);
00377
00378 }
00379 }
00380
00381 }
00382
00383
00384
00385 }
00386
00387
00388
00389
00390