00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "BDSExecOptions.hh"
00023 #include "BDSGlobalConstants.hh"
00024
00025 #include "BDSSteppingAction.hh"
00026 #include "BDSBeamline.hh"
00027 #include <iostream>
00028 #include "G4Track.hh"
00029
00030 #include"G4TransportationManager.hh"
00031
00032 #include"G4StepPoint.hh"
00033 #include "G4RotationMatrix.hh"
00034 #include "G4AffineTransform.hh"
00035
00036 #include "BDSMaterials.hh"
00037 #include "G4Material.hh"
00038 #include "G4VSensitiveDetector.hh"
00039 #include "Randomize.hh"
00040
00041 #include "G4UserLimits.hh"
00042
00043
00044
00045 #include "G4VUserTrackInformation.hh"
00046
00047 #include "G4VProcess.hh"
00048
00049 #include "G4MagneticField.hh"
00050 #include "G4EventManager.hh"
00051 #include "G4StackManager.hh"
00052 #include "G4ChordFinder.hh"
00053 #include "G4MagIntegratorDriver.hh"
00054 #include "G4Region.hh"
00055 #include "BDSAcceleratorComponent.hh"
00056
00057 #include "BDSQuadStepper.hh"
00058 #include "BDSSextStepper.hh"
00059 #include "BDSOctStepper.hh"
00060 #include "myQuadStepper.hh"
00061
00062 #include "G4Timer.hh"
00063
00064 extern BDSMaterials* theMaterials;
00065
00066 extern G4double BDS_Threshold_Energy;
00067 extern G4double BDSLocalRadiusOfCurvature;
00068
00069 extern G4int event_number;
00070
00071 extern G4double initial_x,initial_xp,initial_y,initial_yp,initial_z,initial_E;
00072
00073
00074
00075
00076 BDSSteppingAction::BDSSteppingAction()
00077 {
00078 verbose = BDSExecOptions::Instance()->GetVerbose();
00079 verboseStep = BDSExecOptions::Instance()->GetVerboseStep();
00080 verboseEvent = BDSExecOptions::Instance()->GetVerboseEvent();
00081 verboseEventNumber= BDSExecOptions::Instance()->GetVerboseEventNumber();
00082 nptwiss = BDSExecOptions::Instance()->GetNPTwiss();
00083
00084
00085
00086
00087
00088 postponedEnergy=0;
00089 SetTrackLength(0);
00090 SetTrackLengthInWorldRegion(0);
00091 }
00092
00093
00094
00095 BDSSteppingAction::~BDSSteppingAction()
00096 { }
00097
00098
00099
00100 G4double BDSSteppingAction::GetTrackLengthInWorldRegion(){
00101 return trackLengthInWorldRegion;
00102 }
00103
00104 G4double BDSSteppingAction::GetTrackLength(){
00105 return trackLength;
00106 }
00107
00108 void BDSSteppingAction::SetTrackLengthInWorldRegion(G4double dvalue){
00109 trackLengthInWorldRegion = dvalue;
00110 }
00111
00112 void BDSSteppingAction::SetTrackLength(G4double dvalue){
00113 trackLength = dvalue;
00114 }
00115
00116
00117
00118 extern G4double htot;
00119
00120 void BDSSteppingAction::UserSteppingAction(const G4Step* ThisStep)
00121 {
00122
00123
00124 if(BDSGlobalConstants::Instance()->DoTwiss()){
00125 if(ThisStep->GetTrack()->GetNextVolume() && ThisStep->GetTrack()->GetParentID() <= 0)
00126 {
00127
00128 #ifdef DEBUG
00129 G4cout <<" ***"<< ThisStep->GetTrack()->GetVolume()->GetName()<<G4endl;
00130 G4cout <<" +++"<< ThisStep->GetPreStepPoint()->GetPhysicalVolume()->GetName() << G4endl;
00131 G4cout <<" ---"<< ThisStep->GetPostStepPoint()->GetPhysicalVolume()->GetName() << G4endl;
00132 G4cout << "StepLength = " << ThisStep->GetStepLength() << G4endl;
00133 G4cout << "Track energy = " << ThisStep->GetTrack()->GetTotalEnergy() << G4endl;
00134 #endif
00135
00136 G4int curr_delim = ThisStep->GetTrack()->GetVolume()->GetName().find("_");
00137 G4String curr_gmad_name = ThisStep->GetTrack()->GetVolume()->GetName().substr(0,curr_delim);
00138 G4int delim = ThisStep->GetTrack()->GetNextVolume()->GetName().find("_");
00139 G4String gmad_name = ThisStep->GetTrack()->GetNextVolume()->GetName().substr(0,delim);
00140 if (curr_gmad_name != gmad_name && gmad_name!="World")
00141 {
00142 #ifdef DEBUG
00143 G4cout << curr_gmad_name << " " << gmad_name << G4endl;
00144 #endif
00145 G4ThreeVector pos = ThisStep->GetTrack()->GetPosition();
00146 postponedEnergy+=ThisStep->GetTrack()->GetTotalEnergy();
00147
00148 G4StackManager* SM = G4EventManager::GetEventManager()->GetStackManager();
00149 #ifdef DEBUG
00150 G4cout << "Postponing track " << SM->GetNPostponedTrack() << G4endl;
00151 #endif
00152 if(SM->GetNPostponedTrack()!= nptwiss-1 ) {
00153
00154 ThisStep->GetTrack()->SetTrackStatus(fPostponeToNextEvent);
00155 }
00156
00157
00158 if(SM->GetNPostponedTrack()== nptwiss-1)
00159 {
00160 SM->TransferStackedTracks(fPostpone, fUrgent);
00161 if(verbose) G4cout << "\nMean Energy: " << (postponedEnergy/nptwiss)/GeV << G4endl;
00162
00163 std::list<BDSAcceleratorComponent*>::const_iterator iBeam;
00164 G4String type="";
00165 for(BDSBeamline::Instance()->first();!BDSBeamline::Instance()->isDone();BDSBeamline::Instance()->next())
00166 {
00167 if( BDSBeamline::Instance()->currentItem()->GetName() == gmad_name)
00168 {
00169 type = BDSBeamline::Instance()->currentItem()->GetType();
00170 if(verbose) G4cout << "Next Element is: " << BDSBeamline::Instance()->currentItem()->GetName() << G4endl;
00171 if(verbose) G4cout << "Element Type: " << type << G4endl;
00172 G4double old_P0 = BDSGlobalConstants::Instance()->GetBeamTotalEnergy();
00173 G4double old_brho =
00174 sqrt(pow(old_P0,2)- pow(electron_mass_c2,2))/(0.299792458 * (GeV/(tesla*m)));
00175 G4double new_P0 = postponedEnergy/nptwiss;
00176 G4double new_brho =
00177 sqrt(pow(new_P0,2)- pow(electron_mass_c2,2))/(0.299792458 * (GeV/(tesla*m)));
00178
00179 if(BDSGlobalConstants::Instance()->GetSynchRescale())
00180 {
00181 BDSBeamline::Instance()->currentItem()->SynchRescale(new_brho/old_brho);
00182 if(verbose) G4cout << "Rescaling " << BDSBeamline::Instance()->currentItem()->GetName() << "by: " << new_brho/old_brho << G4endl;
00183 G4cout << "*";
00184 G4cout.flush();
00185 }
00186 break;
00187 }
00188 }
00189 postponedEnergy=0;
00190 }
00191 return;
00192 }
00193 }
00194 }
00195
00196
00197
00198
00199 if((verboseStep || verboseEventNumber == event_number) && (!BDSGlobalConstants::Instance()->GetSynchRescale()) )
00200 {
00201 int ID=ThisStep->GetTrack()->GetTrackID();
00202 int G4precision = G4cout.precision();
00203 G4cout.precision(10);
00204 G4cout<<"This volume="<< ThisStep->GetTrack()->GetVolume()->GetName()<<G4endl;
00205
00206 G4LogicalVolume* LogVol=ThisStep->GetTrack()->GetVolume()->GetLogicalVolume();
00207 G4cout<<"This log volume="<<LogVol->GetName() <<G4endl;
00208
00209 G4cout<<"ID="<<ID<<" part="<<
00210 ThisStep->GetTrack()->GetDefinition()->GetParticleName()<<
00211 "Energy="<<ThisStep->GetTrack()->GetTotalEnergy()/GeV<<
00212 " mom Px="
00213 <<ThisStep->GetTrack()->GetMomentum()[0]/GeV<<
00214 " Py="<<ThisStep->GetTrack()->GetMomentum()[1]/GeV<<
00215 " Pz="<<ThisStep->GetTrack()->GetMomentum()[2]/GeV<<" vol="<<
00216 ThisStep->GetTrack()->GetVolume()->GetName()<<G4endl;
00217
00218 G4cout<<" Global Position="<<ThisStep->GetTrack()->GetPosition()<<G4endl;
00219 G4AffineTransform tf(ThisStep->GetPreStepPoint()->GetTouchableHandle()->GetHistory()->GetTopTransform());
00220 G4cout<<" Local Position="<< tf.TransformPoint(ThisStep->GetTrack()->GetPosition()) <<G4endl;
00221
00222 if(ThisStep->GetTrack()->GetMaterial()->GetName() !="LCVacuum")
00223 G4cout<<"material="<<ThisStep->GetTrack()->GetMaterial()->GetName()<<G4endl;
00224
00225 G4VProcess* proc=(G4VProcess*)(ThisStep->GetPostStepPoint()->
00226 GetProcessDefinedStep() );
00227
00228 if(proc)G4cout<<" post-step process="<<proc->GetProcessName()<<G4endl<<G4endl;
00229
00230
00231 proc=(G4VProcess*)(ThisStep->GetPreStepPoint()->
00232 GetProcessDefinedStep() );
00233
00234 if(proc)G4cout<<" pre-step process="<<proc->GetProcessName()<<G4endl<<G4endl;
00235
00236
00237 G4cout.precision(G4precision);
00238 }
00239
00240
00241
00242
00243
00244
00245 G4String pName=ThisStep->GetTrack()->GetDefinition()->GetParticleName();
00246
00247 #ifndef NOSTEPPERCUT
00248
00249
00250 if(pName=="gamma"){
00251 if(ThisStep->GetTrack()->GetKineticEnergy()<BDSGlobalConstants::Instance()->GetThresholdCutPhotons())
00252 {
00253 ThisStep->GetTrack()->SetTrackStatus(fStopAndKill);
00254 }
00255 } else if(pName=="e-"||pName=="e+"){
00256 if(ThisStep->GetTrack()->GetKineticEnergy()<BDSGlobalConstants::Instance()->GetThresholdCutCharged())
00257 {
00258 ThisStep->GetTrack()->SetTrackStatus(fStopAndKill);
00259 }
00260 }
00261 #endif
00262
00263
00264 G4bool killNeutrinos = true;
00265 if( killNeutrinos ){
00266 if( pName=="nu_e" || pName=="nu_mu" || pName=="nu_tau" || pName=="anti_nu_e" || pName=="anti_nu_mu" || pName=="anti_nu_tau" ){
00267 ThisStep->GetTrack()->SetTrackStatus(fStopAndKill);
00268 }
00269 }
00270 }
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280