Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-11 08:29:50

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 MCTruthTrackingAction.cc
0027 /// \brief Implementation of the MCTruthTrackingAction class
0028 
0029 // --------------------------------------------------------------
0030 //      GEANT 4 - MCTruthTrackingAction class
0031 // --------------------------------------------------------------
0032 //
0033 // Author: Witold POKORSKI (Witold.Pokorski@cern.ch)
0034 //
0035 // --------------------------------------------------------------
0036 //
0037 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0038 
0039 #include "MCTruthTrackingAction.hh"
0040 
0041 #include "MCTruthTrackInformation.hh"
0042 
0043 #include "G4Track.hh"
0044 #include "G4TrackVector.hh"
0045 #include "G4TrackingManager.hh"
0046 
0047 #include <iostream>
0048 
0049 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0050 
0051 MCTruthTrackingAction::MCTruthTrackingAction() : G4UserTrackingAction() {}
0052 
0053 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0054 
0055 MCTruthTrackingAction::~MCTruthTrackingAction() {}
0056 
0057 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0058 
0059 void MCTruthTrackingAction::PreUserTrackingAction(const G4Track* track)
0060 {
0061   fmom = G4LorentzVector(track->GetMomentum(), track->GetTotalEnergy());
0062 
0063   if (!track->GetUserInformation()) {
0064     G4VUserTrackInformation* mcinf = new MCTruthTrackInformation;
0065     fpTrackingManager->SetUserTrackInformation(mcinf);
0066   }
0067 }
0068 
0069 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0070 
0071 void MCTruthTrackingAction::PostUserTrackingAction(const G4Track* track)
0072 {
0073   G4LorentzVector prodpos(track->GetGlobalTime() - track->GetLocalTime(),
0074                           track->GetVertexPosition());
0075   G4LorentzVector endpos(track->GetGlobalTime(), track->GetPosition());
0076 
0077   // here (?) make all different checks to decide whether to store the particle
0078   //
0079   if (TrackToBeStored(track)) {
0080     MCTruthTrackInformation* mcinf = (MCTruthTrackInformation*)track->GetUserInformation();
0081 
0082     MCTruthManager::GetInstance()->AddParticle(
0083       fmom, prodpos, endpos, track->GetDefinition()->GetPDGEncoding(), track->GetTrackID(),
0084       track->GetParentID(), mcinf->GetDirectParent());
0085   }
0086   else {
0087     // If track is not to be stored, propagate it's parent ID (stored)
0088     // to its secondaries
0089     //
0090     G4TrackVector* childrens = fpTrackingManager->GimmeSecondaries();
0091 
0092     for (unsigned int index = 0; index < childrens->size(); ++index) {
0093       G4Track* tr = (*childrens)[index];
0094       tr->SetParentID(track->GetParentID());
0095 
0096       // set the flag saying that the direct mother is not stored
0097       //
0098       MCTruthTrackInformation* mcinf = (MCTruthTrackInformation*)tr->GetUserInformation();
0099       if (!mcinf) tr->SetUserInformation(mcinf = new MCTruthTrackInformation);
0100 
0101       mcinf->SetDirectParent(false);
0102     }
0103   }
0104 }
0105 
0106 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0107 
0108 G4bool MCTruthTrackingAction::TrackToBeStored(const G4Track* track)
0109 {
0110   MCTruthConfig* config = MCTruthManager::GetInstance()->GetConfig();
0111 
0112   // check energy
0113   if (fmom.e() > config->GetMinE()) return true;
0114 
0115   // particle type
0116   std::vector<G4int> types = config->GetParticleTypes();
0117 
0118   if (std::find(types.begin(), types.end(), track->GetDefinition()->GetPDGEncoding())
0119       != types.end())
0120     return true;
0121 
0122   // creator process
0123 
0124   // etc...
0125 
0126   return false;
0127 }
0128 
0129 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....