Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-17 07:52:14

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 // gpaterno, October 2025
0027 //
0028 /// \file EventAction.cc
0029 /// \brief Implementation of the EventAction class
0030 //
0031 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0032 
0033 #include "EventAction.hh"
0034 #include "RunAction.hh"
0035 #include "SensitiveDetectorHit.hh"
0036 #include "DetectorConstruction.hh"
0037 
0038 #include "G4RunManager.hh"
0039 #include "G4Event.hh"
0040 #include "G4EventManager.hh"
0041 #include "G4HCofThisEvent.hh"
0042 #include "G4VHitsCollection.hh"
0043 #include "G4TrajectoryContainer.hh"
0044 #include "G4Trajectory.hh"
0045 #include "G4VVisManager.hh"
0046 #include "G4SDManager.hh"
0047 #include "G4UImanager.hh"
0048 #include "G4ios.hh"
0049 #include "G4SystemOfUnits.hh"
0050 #include "globals.hh"
0051 #include "G4AnalysisManager.hh"
0052 
0053 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0054 
0055 EventAction::EventAction()
0056 {
0057     //An instance of the DetectorConstruction
0058     const DetectorConstruction* detectorConstruction = 
0059         static_cast<const DetectorConstruction*>
0060             (G4RunManager::GetRunManager()->GetUserDetectorConstruction());
0061 
0062     fNSpheres = detectorConstruction->GetNSpheres();
0063 
0064     //Inizialize the Edep map in the Spheres (scored through SteppingAction)
0065     for (int i = 0; i < fNSpheres; i++) {    
0066         fEdepSpheres[i] = 0.;     
0067     }
0068 }
0069 
0070 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0071 
0072 void EventAction::BeginOfEventAction(const G4Event*)
0073 {
0074     //reset Edep in the Radiator and Converter Crystals
0075     fEdepRad = 0.;
0076     fEdepConv = 0.;
0077 
0078     //reset the Edep map in the Spheres (scored through SteppingAction)
0079     if (fVerboseLevel > 0) {
0080         G4int eventID = GetEventID();
0081         G4cout << "EventAction::BeginOfEventAction(), "
0082                << "EventID: " << eventID << G4endl;
0083     }
0084 
0085     for (int i = 0; i < fNSpheres; i++) {
0086         fEdepSpheres[i] = 0.;
0087     }
0088 }
0089 
0090 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0091 
0092 void EventAction::EndOfEventAction(const G4Event* aEvent)
0093 {   
0094     //instantiating The Sensitive Detector Manager
0095     G4SDManager* SDman = G4SDManager::GetSDMpointer();
0096 
0097     //Hit Detection System
0098     if (fSensitiveDetector_ID == -1) {
0099         G4String SensitiveDetectorName;
0100         if (SDman->FindSensitiveDetector(SensitiveDetectorName="det",0)) {
0101             fSensitiveDetector_ID = 
0102                 SDman->GetCollectionID(SensitiveDetectorName="det/collection");
0103         }
0104     }
0105 
0106     SensitiveDetectorHitsCollection* sensitiveDetectorHC = 0;
0107     G4HCofThisEvent* HCE = aEvent->GetHCofThisEvent();
0108 
0109     if (HCE) {
0110         if (fSensitiveDetector_ID != -1) {
0111             G4VHitsCollection* aHC = HCE->GetHC(fSensitiveDetector_ID);
0112             sensitiveDetectorHC = (SensitiveDetectorHitsCollection*)(aHC);
0113         }
0114     }
0115     
0116     //instantiating The Analysis Manager
0117     G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0118    
0119     //get the Event Number
0120     G4int eventID = GetEventID();
0121 
0122     //filling the SD scoring ntuple
0123     if (sensitiveDetectorHC) {
0124         int vNumberOfHit = sensitiveDetectorHC->entries();
0125         for (int i=0; i<vNumberOfHit; i++) {
0126             SensitiveDetectorHit* aHit = (*sensitiveDetectorHC)[i];
0127             analysisManager->FillNtupleIColumn(0,0,aHit->GetDetID());
0128             analysisManager->FillNtupleSColumn(0,1,aHit->GetParticle());
0129             analysisManager->FillNtupleDColumn(0,2,aHit->GetPos().x()/CLHEP::mm);
0130             analysisManager->FillNtupleDColumn(0,3,aHit->GetPos().y()/CLHEP::mm);
0131             analysisManager->FillNtupleDColumn(0,4,aHit->GetMom().x()/CLHEP::MeV);
0132             analysisManager->FillNtupleDColumn(0,5,aHit->GetMom().y()/CLHEP::MeV);
0133             analysisManager->FillNtupleDColumn(0,6,aHit->GetMom().z()/CLHEP::MeV);
0134             analysisManager->FillNtupleDColumn(0,7,aHit->GetTime()/CLHEP::ns);
0135             analysisManager->FillNtupleIColumn(0,8,eventID);
0136             analysisManager->AddNtupleRow(0);
0137         }
0138     }
0139 
0140     //filling the Edep (in the Radiator Crystal) ntuple
0141     if (fEdepRad > 0) {
0142         analysisManager->FillNtupleDColumn(1,0,fEdepRad/MeV);
0143         analysisManager->FillNtupleIColumn(1,1,eventID);
0144         analysisManager->AddNtupleRow(1);
0145     }
0146 
0147     //filling the Edep (in the Converter Crystal) ntuple
0148     if (fEdepConv > 0) {
0149         analysisManager->FillNtupleDColumn(2,0,fEdepConv/MeV);
0150         analysisManager->FillNtupleIColumn(2,1,eventID);
0151         analysisManager->AddNtupleRow(2);
0152     }
0153 
0154     //Get the results accumulated through the SteppingAction class
0155     //and fill the local (one for thread) ntuple for Edep map in 
0156     //the Spheres of thew granular target.
0157     for (int i = 0; i < fNSpheres; i++) {    
0158         analysisManager->FillNtupleIColumn(3,0,i);
0159         analysisManager->FillNtupleDColumn(3,1,fEdepSpheres[i]/MeV);
0160         analysisManager->FillNtupleIColumn(3,2,eventID);
0161         analysisManager->AddNtupleRow(3);
0162     }
0163 
0164 }
0165 
0166 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0167 
0168 void EventAction::AddEdepInSpheres(G4int volID, G4double edep)
0169 {    
0170     G4double temp = fEdepSpheres.find(volID)->second;
0171     fEdepSpheres[volID] = temp + edep;
0172 
0173     if (fVerboseLevel > 1) {
0174         G4int eventID = GetEventID();
0175         G4cout << "Event: " << eventID
0176                << ", Edep[" << volID << "]: "
0177                << edep/MeV << " MeV" << G4endl;
0178     }
0179 }
0180 
0181 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0182