Back to home page

EIC code displayed by LXR

 
 

    


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

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