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