src/BDSStackingAction.cc

00001 //  
00002 //   BDSIM, (C) 2001-2006 
00003 //    
00004 //   version 0.2 
00005 //   last modified : 28 Mar 2006 by agapov@pp.rhul.ac.uk
00006 //  
00007 
00008 
00009 
00010 //
00011 //    Stacking action - taken when secondaries created
00012 //
00013 
00014 
00015 #include "BDSGlobalConstants.hh"
00016 #include "BDSStackingAction.hh"
00017 #include "G4SDManager.hh"
00018 #include "G4RunManager.hh"
00019 #include "G4Run.hh"
00020 #include "G4Event.hh"
00021 #include "G4HCofThisEvent.hh"
00022 #include "G4Track.hh"
00023 #include "G4TrackStatus.hh"
00024 #include "G4ParticleDefinition.hh"
00025 #include "G4ParticleTypes.hh"
00026 #include "G4ios.hh"
00027 
00028 BDSStackingAction::BDSStackingAction()
00029 { 
00030 }
00031 
00032 BDSStackingAction::~BDSStackingAction()
00033 {
00034 }
00035 
00036 G4ClassificationOfNewTrack BDSStackingAction::ClassifyNewTrack(const G4Track * aTrack)
00037 {
00038   G4ClassificationOfNewTrack classification = fUrgent;
00039 
00040 
00041 #ifdef DEBUG 
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     G4RunManager::GetRunManager()->GetCurrentRun()->GetNumberOfEventToBeProcessed()<<G4endl;
00051   G4cout<<"Number of event : "<<
00052     G4RunManager::GetRunManager()->GetCurrentRun()->GetNumberOfEvent()<<G4endl;
00053 #endif
00054   
00055   if(BDSGlobalConstants::Instance()->DoTwiss())
00056     {
00057       if((aTrack->GetParentID() <= 0) &&
00058          (aTrack->GetTrackStatus()==fPostponeToNextEvent) )
00059         classification = fPostpone;
00060     }
00061   
00062   if(BDSGlobalConstants::Instance()->GetStopTracks()) // if tracks killed after interaction
00063     {
00064       
00065       // kill secondary electrons
00066       
00067       if( (aTrack->GetParentID() > 0) && 
00068           (aTrack->GetDefinition() == G4Electron::ElectronDefinition() ) )
00069         {
00070           
00071           
00072           classification = fKill;
00073           //classification = fUrgent;
00074 
00075           // if we are in the twiss module - aperture hit is suspicious
00076           if( BDSGlobalConstants::Instance()->DoTwiss() ) 
00077             G4cout<<"WARNING : Electron "<<aTrack->GetParentID()<<" outside of aperture, twiss results will be incorrect"<<
00078               G4endl;
00079 
00080         }
00081       
00082       // kill secondary photons
00083       
00084       if( (aTrack->GetParentID() > 0) && 
00085           (aTrack->GetDefinition() == G4Gamma::GammaDefinition() ) )
00086         {
00087           classification = fKill;
00088         }
00089       
00090       // kill secondary positrons
00091       
00092       if( (aTrack->GetParentID() > 0) && 
00093           (aTrack->GetDefinition() == G4Positron::PositronDefinition() ) )
00094         {
00095           classification = fKill;
00096 
00097           // if we are in the twiss module - aperture hit is suspicious
00098           if( BDSGlobalConstants::Instance()->DoTwiss() ) 
00099             G4cout<<"WARNING : Positron outside of aperture, twiss results will be incorrect"<<
00100               G4endl;
00101         }
00102 
00103       // kill secondary protons/antiprotons
00104       
00105       if( (aTrack->GetParentID() > 0) && 
00106           ( (aTrack->GetDefinition() == G4Proton::ProtonDefinition() ) ||
00107             (aTrack->GetDefinition() == G4AntiProton::AntiProtonDefinition()) ) )
00108         {
00109           classification = fKill;
00110           
00111           // if we are in the twiss module - aperture hit is suspicious
00112           if( BDSGlobalConstants::Instance()->DoTwiss() ) 
00113             G4cout<<"WARNING : Proton outside of aperture, twiss results will be incorrect"<<
00114               G4endl;
00115         }
00116       
00117     }
00118 
00119   if(BDSGlobalConstants::Instance()->getWaitingForDump()) // if waiting for placet synchronization
00120     {
00121        // when waiting to synchronize with placet - put on postponed stack
00122       if( aTrack->GetTrackStatus()==fPostponeToNextEvent )
00123         classification = fPostpone;
00124      }
00125   
00126   if(BDSGlobalConstants::Instance()->getDumping()) // in the process of dumping
00127     {
00128 #ifdef DEBUG
00129       G4cout<<"reclassifying track "<<aTrack->GetTrackID()<<G4endl;
00130       G4cout<<"r= "<<aTrack->GetPosition()<<G4endl;
00131 #endif
00132       
00133       G4AffineTransform tf = BDSGlobalConstants::Instance()->GetDumpTransform().Inverse();
00134       G4ThreeVector initialPos=aTrack->GetPosition();
00135       G4ThreeVector momDir=aTrack->GetMomentumDirection().unit();
00136       G4ThreeVector transformedPos = initialPos;
00137       G4ThreeVector LocalPosition=tf.TransformPoint(transformedPos);
00138       G4ThreeVector LocalDirection=tf.TransformAxis(momDir);
00139       
00140 #ifdef DEBUG
00141       G4cout << "Stacking: Pos = " << transformedPos << G4endl;
00142       G4cout << "LocalPos: Pos = " << LocalPosition << G4endl;
00143       G4cout << "Stacking: mom = " << momDir << G4endl;
00144       G4cout << "LocalDir: mom = " << LocalDirection << G4endl;
00145 #endif
00146       
00147       G4double x=LocalPosition.x()/micrometer;
00148       G4double y=LocalPosition.y()/micrometer;
00149       G4double z=LocalPosition.z()/micrometer;
00150       G4double xPrime=LocalDirection.x()/(1e-6*radian);
00151       G4double yPrime=LocalDirection.y()/(1e-6*radian);
00152       G4double t=aTrack->GetGlobalTime();
00153       
00154       BDSGlobalConstants::Instance()->fileDump.precision(15);
00155       // TODO : dump the file
00156       //        BDSGlobalConstants::Instance()->fileDump << aTrack->GetTotalEnergy()/GeV << "\t"
00157       //<< x << "\t" << y << "\t" << z << "\t"
00158       //<< xPrime << "\t" << yPrime << "\t" << t <<"\n"; // SPM
00159 #ifdef DEBUG
00160       printf("Out: %.15f %.15f %.15f %.15f %.15f %.15f %f\n",
00161              aTrack->GetTotalEnergy()/GeV,x,y,z,xPrime,yPrime,t);
00162 #endif
00163       tmpParticle outputParticle, transformedParticle;
00164       if(aTrack->GetDefinition()->GetPDGEncoding()==-11)
00165         outputParticle.E=-(aTrack->GetTotalEnergy());
00166       else outputParticle.E=aTrack->GetTotalEnergy();
00167       outputParticle.xp=momDir.x();
00168       outputParticle.yp=momDir.y();
00169       outputParticle.x=initialPos.x();
00170       outputParticle.y=initialPos.y();
00171       outputParticle.z=initialPos.z();
00172       outputParticle.t=t;
00173       outputParticle.trackID=aTrack->GetTrackID();
00174       outputParticle.parentID=aTrack->GetParentID();
00175       
00176       transformedParticle.x=x;
00177       transformedParticle.y=y;
00178       transformedParticle.z=z;
00179       transformedParticle.xp=xPrime;
00180       transformedParticle.yp=yPrime;
00181       transformedParticle.t=t;
00182       transformedParticle.E=aTrack->GetTotalEnergy()/GeV;
00183       transformedParticle.parentID=aTrack->GetParentID();
00184       
00185       BDSGlobalConstants::Instance()->outputQueue.push_back(outputParticle);
00186       BDSGlobalConstants::Instance()->transformedQueue.push_back(transformedParticle);
00187       classification = fPostpone;
00188     }
00189   
00190   if(BDSGlobalConstants::Instance()->getReading()){
00191     classification = fWaiting_1;
00192   }
00193 
00194   //For improvement in efficiency 
00195   //  if(aTrack->GetNextVolume() != aTrack->GetVolume()) classification = fWaiting; //Track all particles in same volume first
00196   //  if(aTrack->GetTrackID()!=1) classification = fWaiting_1;  //Not a secondary
00197   //  if(aTrack->GetTotalEnergy()<0.1*BDSGlobalConstants::Instance()->GetBeamTotalEnergy()) classification = fWaiting_2;  //Below certain thresholds
00198   //  if(aTrack->GetTotalEnergy()<0.01*BDSGlobalConstants::Instance()->GetBeamTotalEnergy()) classification = fWaiting_3; 
00199   //  if(aTrack->GetTotalEnergy()<0.001*BDSGlobalConstants::Instance()->GetBeamTotalEnergy()) classification = fWaiting_4; 
00200   
00201   return classification;
00202 }
00203 
00204 
00205 void BDSStackingAction::NewStage()
00206 {
00207   // urgent stack empty, looking into the waiting stack
00208  
00209 #ifdef DEBUG
00210   G4cout<<"StackingAction: New stage"<<G4endl;
00211 #endif
00212 
00213   return;
00214  
00215 }
00216     
00217 void BDSStackingAction::PrepareNewEvent()
00218 { 
00219 }
00220 
00221 

Generated on 27 Aug 2013 for BDSIM by  doxygen 1.4.7