/home/cern/BDSIM_new/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 
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   //G4ClassificationOfNewTrack classification = fWaiting;
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()) // if tracks killed after interaction
00077     {
00078       
00079       // kill secondary electrons
00080       
00081       if( (aTrack->GetParentID() != 0) && 
00082           (aTrack->GetDefinition() == G4Electron::ElectronDefinition() ) )
00083         {
00084           
00085           
00086           classification = fKill;
00087           //classification = fUrgent;
00088 
00089           // if we are in the twiss module - aperture hit is suspicious
00090           if( BDSGlobals->DoTwiss() ) 
00091             G4cout<<"WARNING : particle outside of aperture, twiss results will be incorrect"<<
00092               G4endl;;
00093 
00094         }
00095       
00096       // kill secondary photons
00097       
00098       if( (aTrack->GetParentID() != 0) && 
00099           (aTrack->GetDefinition() == G4Gamma::GammaDefinition() ) )
00100         {
00101           classification = fKill;
00102         }
00103       
00104       // kill secondary positrons
00105       
00106       if( (aTrack->GetParentID() != 0) && 
00107           (aTrack->GetDefinition() == G4Positron::PositronDefinition() ) )
00108         {
00109           classification = fKill;
00110 
00111           // if we are in the twiss module - aperture hit is suspicious
00112           if( BDSGlobals->DoTwiss() ) 
00113             G4cout<<"WARNING : particle outside of aperture, twiss results will be incorrect"<<
00114               G4endl;
00115         }
00116 
00117       // kill secondary protons/antiprotons
00118       
00119       if( (aTrack->GetParentID() != 0) && 
00120           ( (aTrack->GetDefinition() == G4Proton::ProtonDefinition() ) ||
00121             (aTrack->GetDefinition() == G4AntiProton::AntiProtonDefinition()) ) )
00122         {
00123           classification = fKill;
00124           
00125           // if we are in the twiss module - aperture hit is suspicious
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()) // if waiting for placet synchronization
00134      {
00135        // when waiting to synchronize with placet - put on postponed stack
00136        if( aTrack->GetTrackStatus()==fPostponeToNextEvent )
00137        classification = fPostpone;
00138        //BDSGlobals->setWaitingForDump(false); // next event ok
00139      }
00140   
00141     if(BDSGlobals->getDumping()) // in the process of dumping
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 //      const G4RotationMatrix Rot=tf.NetRotation();
00151 //      const G4ThreeVector Trans=-tf.NetTranslation();
00152 
00153         G4ThreeVector pos=aTrack->GetPosition();
00154         G4ThreeVector momDir=aTrack->GetMomentumDirection();
00155 
00156         //pos.setZ(aTrack->GetGlobalTime()*c_light);
00157 
00158 //        G4ThreeVector LocalPosition=pos+Trans;
00159 //        G4ThreeVector LocalDirection=Rot*momDir;
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         // TODO : dump the file
00178         BDSGlobals->fileDump << aTrack->GetTotalEnergy()/GeV << "\t"
00179         << x << "\t" << y << "\t" << z << "\t"
00180         << xPrime << "\t" << yPrime << "\n"; // SPM
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   // urgent stack empty, looking into the waiting stack
00195  
00196   if(DEBUG) G4cout<<"StackingAction: New stage"<<G4endl;
00197 
00198   //stackManager->ReClassify();
00199   
00200   return;
00201  
00202 }
00203     
00204 void BDSStackingAction::PrepareNewEvent()
00205 { 
00206 }
00207 
00208 

Generated on Wed Mar 5 17:25:23 2008 for BDSIM by  doxygen 1.5.3