Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:41

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 /// \file TrackingAction.cc
0027 /// \brief Implementation of the TrackingAction class
0028 //
0029 //
0030 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0031 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0032 
0033 #include "TrackingAction.hh"
0034 
0035 #include "EventAction.hh"
0036 #include "HistoManager.hh"
0037 #include "Run.hh"
0038 #include "TrackingMessenger.hh"
0039 
0040 #include "G4IonTable.hh"
0041 #include "G4ParticleTypes.hh"
0042 #include "G4RunManager.hh"
0043 #include "G4SystemOfUnits.hh"
0044 #include "G4Track.hh"
0045 #include "G4UnitsTable.hh"
0046 
0047 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0048 
0049 TrackingAction::TrackingAction(EventAction* event) : fEvent(event)
0050 
0051 {
0052   fTrackMessenger = new TrackingMessenger(this);
0053 }
0054 
0055 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0056 
0057 TrackingAction::~TrackingAction()
0058 {
0059   delete fTrackMessenger;
0060 }
0061 
0062 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0063 
0064 void TrackingAction::SetTimeWindow(G4double t1, G4double dt)
0065 {
0066   fTimeWindow1 = t1;
0067   fTimeWindow2 = fTimeWindow1 + dt;
0068 }
0069 
0070 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0071 
0072 void TrackingAction::PreUserTrackingAction(const G4Track* track)
0073 {
0074   Run* run = static_cast<Run*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0075 
0076   G4ParticleDefinition* particle = track->GetDefinition();
0077   G4String name = particle->GetParticleName();
0078   fCharge = particle->GetPDGCharge();
0079   fMass = particle->GetPDGMass();
0080 
0081   G4double Ekin = track->GetKineticEnergy();
0082   G4int ID = track->GetTrackID();
0083 
0084   G4bool condition = false;
0085 
0086   // check LifeTime
0087   //
0088   G4double meanLife = particle->GetPDGLifeTime();
0089 
0090   // count particles
0091   //
0092   run->ParticleCount(name, Ekin, meanLife);
0093 
0094   // energy spectrum
0095   //
0096   G4int ih = 0;
0097   if (particle == G4Electron::Electron() || particle == G4Positron::Positron())
0098     ih = 1;
0099   else if (particle == G4NeutrinoE::NeutrinoE() || particle == G4AntiNeutrinoE::AntiNeutrinoE())
0100     ih = 2;
0101   else if (particle == G4Gamma::Gamma())
0102     ih = 3;
0103   else if (particle == G4Alpha::Alpha())
0104     ih = 4;
0105   else if (fCharge > 2.)
0106     ih = 5;
0107   if (ih) G4AnalysisManager::Instance()->FillH1(ih, Ekin);
0108 
0109   // Ion
0110   //
0111   if (fCharge > 2.) {
0112     // build decay chain
0113     if (ID == 1)
0114       fEvent->AddDecayChain(name);
0115     else
0116       fEvent->AddDecayChain(" ---> " + name);
0117     //
0118     // full chain: put at rest; if not: kill secondary
0119     G4Track* tr = (G4Track*)track;
0120     if (fFullChain) {
0121       tr->SetKineticEnergy(0.);
0122       tr->SetTrackStatus(fStopButAlive);
0123     }
0124     else if (ID > 1)
0125       tr->SetTrackStatus(fStopAndKill);
0126     //
0127     fTimeBirth = track->GetGlobalTime();
0128   }
0129 
0130   // example of saving random number seed of this fEvent, under condition
0131   //
0132   ////condition = (ih == 3);
0133   if (condition) G4RunManager::GetRunManager()->rndmSaveThisEvent();
0134 }
0135 
0136 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0137 
0138 void TrackingAction::PostUserTrackingAction(const G4Track* track)
0139 {
0140   // keep only ions
0141   //
0142   if (fCharge < 3.) return;
0143 
0144   Run* run = static_cast<Run*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0145 
0146   G4AnalysisManager* analysis = G4AnalysisManager::Instance();
0147 
0148   // get time
0149   //
0150   G4double time = track->GetGlobalTime();
0151   G4int ID = track->GetTrackID();
0152   if (ID == 1) run->PrimaryTiming(time);  // time of life of primary ion
0153   fTimeEnd = time;
0154 
0155   // energy and momentum balance (from secondaries)
0156   //
0157   const std::vector<const G4Track*>* secondaries = track->GetStep()->GetSecondaryInCurrentStep();
0158   size_t nbtrk = (*secondaries).size();
0159   if (nbtrk) {
0160     // there are secondaries --> it is a decay
0161     //
0162     // balance
0163     G4double EkinTot = 0., EkinVis = 0.;
0164     G4ThreeVector Pbalance = -track->GetMomentum();
0165     for (size_t itr = 0; itr < nbtrk; itr++) {
0166       const G4Track* trk = (*secondaries)[itr];
0167       G4ParticleDefinition* particle = trk->GetDefinition();
0168       G4double Ekin = trk->GetKineticEnergy();
0169       EkinTot += Ekin;
0170       G4bool visible =
0171         !((particle == G4NeutrinoE::NeutrinoE()) || (particle == G4AntiNeutrinoE::AntiNeutrinoE()));
0172       if (visible) EkinVis += Ekin;
0173       // exclude gamma desexcitation from momentum balance
0174       if (particle != G4Gamma::Gamma()) Pbalance += trk->GetMomentum();
0175     }
0176     G4double Pbal = Pbalance.mag();
0177     run->Balance(EkinTot, Pbal);
0178     analysis->FillH1(6, EkinTot);
0179     analysis->FillH1(7, Pbal);
0180     fEvent->AddEvisible(EkinVis);
0181   }
0182 
0183   // no secondaries --> end of chain
0184   //
0185   if (!nbtrk) {
0186     run->EventTiming(time);  // total time of life
0187     G4double weight = track->GetWeight();
0188     analysis->FillH1(8, time, weight);
0189     ////    analysis->FillH1(8,time);
0190     fTimeEnd = DBL_MAX;
0191   }
0192 
0193   // count activity in time window
0194   //
0195   run->SetTimeWindow(fTimeWindow1, fTimeWindow2);
0196 
0197   G4String name = track->GetDefinition()->GetParticleName();
0198   G4bool life1(false), life2(false), decay(false);
0199   if ((fTimeBirth <= fTimeWindow1) && (fTimeEnd > fTimeWindow1)) life1 = true;
0200   if ((fTimeBirth <= fTimeWindow2) && (fTimeEnd > fTimeWindow2)) life2 = true;
0201   if ((fTimeEnd > fTimeWindow1) && (fTimeEnd < fTimeWindow2)) decay = true;
0202   if (life1 || life2 || decay) run->CountInTimeWindow(name, life1, life2, decay);
0203 }
0204 
0205 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......