00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "BDSGlobalConstants.hh"
00017 #include "BDSStackingAction.hh"
00018 #include "G4SDManager.hh"
00019 #include "G4RunManager.hh"
00020 #include "G4Run.hh"
00021 #include "G4Event.hh"
00022 #include "G4HCofThisEvent.hh"
00023 #include "G4Track.hh"
00024 #include "G4TrackStatus.hh"
00025 #include "G4ParticleDefinition.hh"
00026 #include "G4ParticleTypes.hh"
00027 #include "G4ios.hh"
00028
00029
00030
00031 const int DEBUG = 0;
00032
00033
00034 BDSStackingAction::BDSStackingAction()
00035 {
00036 }
00037
00038 BDSStackingAction::~BDSStackingAction()
00039 {
00040 }
00041
00042 G4ClassificationOfNewTrack
00043 BDSStackingAction::ClassifyNewTrack(const G4Track * aTrack)
00044 {
00045
00046 G4ClassificationOfNewTrack classification = fUrgent;
00047
00048 G4String pName=aTrack->GetDefinition()->GetParticleName();
00049
00050
00051 if(DEBUG) {
00052 G4cout<<"StackingAction: ClassifyNewtrack "<<aTrack->GetTrackID()<<
00053 " "<<aTrack->GetDefinition()->GetParticleName()<<G4endl;
00054
00055 G4StackManager* SM = G4EventManager::GetEventManager()->GetStackManager();
00056
00057 G4cout<<"N total tracks : "<<SM->GetNTotalTrack() << G4endl;
00058 G4cout<<"N waiting tracks : "<<SM->GetNWaitingTrack() << G4endl;
00059 G4cout<<"N urgent tracks : "<<SM->GetNUrgentTrack() << G4endl;
00060 G4cout<<"N postponed tracks : "<<SM->GetNPostponedTrack() << G4endl;
00061 G4cout<<"Events to process : "<<
00062 G4RunManager::GetRunManager()->GetCurrentRun()->GetNumberOfEventToBeProcessed()<<G4endl;
00063 G4cout<<"Number of event : "<<
00064 G4RunManager::GetRunManager()->GetCurrentRun()->GetNumberOfEvent()<<G4endl;
00065
00066
00067 }
00068
00069 if(BDSGlobals->DoTwiss())
00070 {
00071 if((aTrack->GetParentID() <= 0) &&
00072 (aTrack->GetTrackStatus()==fPostponeToNextEvent) )
00073 classification = fPostpone;
00074 }
00075
00076 if(BDSGlobals->GetStopTracks())
00077 {
00078
00079
00080
00081 if( (aTrack->GetParentID() != 0) &&
00082 (aTrack->GetDefinition() == G4Electron::ElectronDefinition() ) )
00083 {
00084
00085
00086 classification = fKill;
00087
00088
00089
00090 if( BDSGlobals->DoTwiss() )
00091 G4cout<<"WARNING : particle outside of aperture, twiss results will be incorrect"<<
00092 G4endl;;
00093
00094 }
00095
00096
00097
00098 if( (aTrack->GetParentID() != 0) &&
00099 (aTrack->GetDefinition() == G4Gamma::GammaDefinition() ) )
00100 {
00101 classification = fKill;
00102 }
00103
00104
00105
00106 if( (aTrack->GetParentID() != 0) &&
00107 (aTrack->GetDefinition() == G4Positron::PositronDefinition() ) )
00108 {
00109 classification = fKill;
00110
00111
00112 if( BDSGlobals->DoTwiss() )
00113 G4cout<<"WARNING : particle outside of aperture, twiss results will be incorrect"<<
00114 G4endl;
00115 }
00116
00117
00118
00119 if( (aTrack->GetParentID() != 0) &&
00120 ( (aTrack->GetDefinition() == G4Proton::ProtonDefinition() ) ||
00121 (aTrack->GetDefinition() == G4AntiProton::AntiProtonDefinition()) ) )
00122 {
00123 classification = fKill;
00124
00125
00126 if( BDSGlobals->DoTwiss() )
00127 G4cout<<"WARNING : particle outside of aperture, twiss results will be incorrect"<<
00128 G4endl;
00129 }
00130
00131 }
00132
00133 if(BDSGlobals->getWaitingForDump())
00134 {
00135
00136 if( aTrack->GetTrackStatus()==fPostponeToNextEvent )
00137 classification = fPostpone;
00138
00139 }
00140
00141 if(BDSGlobals->getDumping())
00142 {
00143 if(DEBUG){
00144 G4cout<<"reclassifying track "<<aTrack->GetTrackID()<<G4endl;
00145
00146 G4cout<<"r= "<<aTrack->GetPosition()<<G4endl;
00147 }
00148
00149 G4AffineTransform tf = BDSGlobals->GetDumpTransform().Inverse();
00150
00151
00152
00153 G4ThreeVector pos=aTrack->GetPosition();
00154 G4ThreeVector momDir=aTrack->GetMomentumDirection();
00155
00156
00157
00158
00159
00160 G4ThreeVector LocalPosition=tf.TransformPoint(pos);
00161 G4ThreeVector LocalDirection=tf.TransformAxis(momDir);
00162
00163 if(DEBUG){
00164 G4cout << "Stacking: Pos = " << pos << G4endl;
00165 G4cout << "LocalPos: Pos = " << LocalPosition << G4endl;
00166 G4cout << "Stacking: mom = " << momDir << G4endl;
00167 G4cout << "LocalDir: mom = " << LocalDirection << G4endl;
00168 }
00169
00170 G4double x=LocalPosition.x()/micrometer;
00171 G4double y=LocalPosition.y()/micrometer;
00172 G4double z=LocalPosition.z()/micrometer;
00173 G4double xPrime=LocalDirection.x()/(1e-6*radian);
00174 G4double yPrime=LocalDirection.y()/(1e-6*radian);
00175
00176 BDSGlobals->fileDump.precision(14);
00177
00178 BDSGlobals->fileDump << aTrack->GetTotalEnergy()/GeV << "\t"
00179 << x << "\t" << y << "\t" << z << "\t"
00180 << xPrime << "\t" << yPrime << "\n";
00181 classification = fPostpone;
00182 }
00183
00184 if(BDSGlobals->getReading()){
00185 classification = fWaiting_1;
00186 }
00187
00188 return classification;
00189 }
00190
00191
00192 void BDSStackingAction::NewStage()
00193 {
00194
00195
00196 if(DEBUG) G4cout<<"StackingAction: New stage"<<G4endl;
00197
00198
00199
00200 return;
00201
00202 }
00203
00204 void BDSStackingAction::PrepareNewEvent()
00205 {
00206 }
00207
00208