Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-31 07:50:54

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 RE01StackingAction.cc
0027 /// \brief Implementation of the RE01StackingAction class
0028 
0029 #include "RE01StackingAction.hh"
0030 
0031 #include "RE01CalorimeterHit.hh"
0032 #include "RE01TrackInformation.hh"
0033 
0034 #include "G4Event.hh"
0035 #include "G4HCofThisEvent.hh"
0036 #include "G4ParticleDefinition.hh"
0037 #include "G4ParticleTypes.hh"
0038 #include "G4RunManager.hh"
0039 #include "G4SDManager.hh"
0040 #include "G4SystemOfUnits.hh"
0041 #include "G4Track.hh"
0042 #include "G4TrackStatus.hh"
0043 #include "G4ios.hh"
0044 
0045 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0046 RE01StackingAction::RE01StackingAction()
0047   : G4UserStackingAction(), fStage(0), fCalorimeterHitsColID(-1)
0048 {
0049   ;
0050 }
0051 
0052 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0053 RE01StackingAction::~RE01StackingAction()
0054 {
0055   ;
0056 }
0057 
0058 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0059 G4ClassificationOfNewTrack RE01StackingAction ::ClassifyNewTrack(const G4Track* aTrack)
0060 {
0061   G4ClassificationOfNewTrack classification = fUrgent;
0062 
0063   if (fStage == 0) {
0064     RE01TrackInformation* trackInfo;
0065     if (aTrack->GetTrackStatus() == fSuspend)  // Track reached to calorimeter
0066     {
0067       trackInfo = (RE01TrackInformation*)(aTrack->GetUserInformation());
0068       trackInfo->SetTrackingStatus(0);
0069       trackInfo->SetSourceTrackInformation(aTrack);
0070       //      G4cout << "Track " << aTrack->GetTrackID()
0071       //             << " (parentID " << aTrack->GetParentID()
0072       //             << ") has reached to calorimeter and has been suspended at "
0073       //             << aTrack->GetPosition() << G4endl;
0074       classification = fWaiting;
0075     }
0076     else if (aTrack->GetParentID() == 0)  // Primary particle
0077     {
0078       trackInfo = new RE01TrackInformation(aTrack);
0079       trackInfo->SetTrackingStatus(1);
0080       G4Track* theTrack = (G4Track*)aTrack;
0081       theTrack->SetUserInformation(trackInfo);
0082     }
0083   }
0084   return classification;
0085 }
0086 
0087 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0088 G4VHitsCollection* RE01StackingAction::GetCalCollection()
0089 {
0090   G4SDManager* SDMan = G4SDManager::GetSDMpointer();
0091   G4RunManager* runMan = G4RunManager::GetRunManager();
0092   if (fCalorimeterHitsColID < 0) {
0093     fCalorimeterHitsColID = SDMan->GetCollectionID("calCollection");
0094   }
0095   if (fCalorimeterHitsColID >= 0) {
0096     const G4Event* currentEvent = runMan->GetCurrentEvent();
0097     G4HCofThisEvent* HCE = currentEvent->GetHCofThisEvent();
0098     return HCE->GetHC(fCalorimeterHitsColID);
0099   }
0100   return 0;
0101 }
0102 
0103 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0104 void RE01StackingAction::NewStage()
0105 {
0106   // G4cout << "+++++++++++ Stage " << fStage << G4endl;
0107   if (fStage == 0) {
0108     // display trajetory information in the tracking region
0109     G4cout << G4endl;
0110     G4cout << "Tracks in tracking region have been processed. -- Stage 0 over." << G4endl;
0111     G4cout << G4endl;
0112   }
0113   else {
0114     // display calorimeter information caused by a "source" track
0115     // in the tracker region
0116     //    G4cout << G4endl;
0117     //    G4cout << "Processing one shower originated by a source track "
0118     //           << "in tracker region is over." << G4endl;
0119     //    G4cout << G4endl;
0120     RE01CalorimeterHitsCollection* CHC = (RE01CalorimeterHitsCollection*)GetCalCollection();
0121     if (CHC) {
0122       int n_hit = CHC->entries();
0123       G4double totE = 0;
0124       G4int n_hitByATrack = 0;
0125       for (int i = 0; i < n_hit; i++) {
0126         G4double edepByATrack = (*CHC)[i]->GetEdepByATrack();
0127         if (edepByATrack > 0.) {
0128           totE += edepByATrack;
0129           if (n_hitByATrack == 0) {
0130             (*CHC)[i]->GetTrackInformation()->Print();
0131           }
0132           n_hitByATrack++;
0133           G4cout << "Cell[" << (*CHC)[i]->GetZ() << "," << (*CHC)[i]->GetPhi() << "]    "
0134                  << edepByATrack / GeV << " [GeV]" << G4endl;
0135           (*CHC)[i]->ClearEdepByATrack();
0136         }
0137       }
0138       if (n_hitByATrack > 0) {
0139         G4cout << "###  Total energy deposition in calorimeter by a source track in "
0140                << n_hitByATrack << " cells : " << totE / GeV << " (GeV)" << G4endl;
0141         G4cout << G4endl;
0142       }
0143     }
0144   }
0145 
0146   if (stackManager->GetNUrgentTrack()) {
0147     // Transfer all tracks in Urgent stack to Waiting stack, since all tracks
0148     // in Waiting stack have already been transfered to Urgent stack before
0149     // invokation of this method.
0150     stackManager->TransferStackedTracks(fUrgent, fWaiting);
0151 
0152     // Then, transfer only one track to Urgent stack.
0153     stackManager->TransferOneStackedTrack(fWaiting, fUrgent);
0154 
0155     fStage++;
0156   }
0157 }
0158 
0159 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0160 void RE01StackingAction::PrepareNewEvent()
0161 {
0162   fStage = 0;
0163 }