Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-10 08:05:40

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 eventgenerator/HepMC/HepMCEx01/src/ExN04EventAction.cc
0027 /// \brief Implementation of the ExN04EventAction class
0028 //
0029 //
0030 
0031 #include "ExN04EventAction.hh"
0032 
0033 #include "ExN04CalorimeterHit.hh"
0034 #include "ExN04MuonHit.hh"
0035 #include "ExN04TrackerHit.hh"
0036 
0037 #include "G4Event.hh"
0038 #include "G4EventManager.hh"
0039 #include "G4HCofThisEvent.hh"
0040 #include "G4SDManager.hh"
0041 #include "G4SystemOfUnits.hh"
0042 #include "G4UImanager.hh"
0043 #include "G4VHitsCollection.hh"
0044 #include "G4ios.hh"
0045 
0046 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0047 ExN04EventAction::ExN04EventAction()
0048   : G4UserEventAction(), ftrackerCollID(-1), fcalorimeterCollID(-1), fmuonCollID(-1)
0049 {}
0050 
0051 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0052 ExN04EventAction::~ExN04EventAction() {}
0053 
0054 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0055 void ExN04EventAction::BeginOfEventAction(const G4Event*)
0056 {
0057   G4SDManager* SDman = G4SDManager::GetSDMpointer();
0058   if (ftrackerCollID < 0 || fcalorimeterCollID < 0 || fmuonCollID < 0) {
0059     G4String colNam;
0060     ftrackerCollID = SDman->GetCollectionID(colNam = "trackerCollection");
0061     fcalorimeterCollID = SDman->GetCollectionID(colNam = "calCollection");
0062     fmuonCollID = SDman->GetCollectionID(colNam = "muonCollection");
0063   }
0064 }
0065 
0066 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0067 void ExN04EventAction::EndOfEventAction(const G4Event* evt)
0068 {
0069   G4cout << ">>> Event " << evt->GetEventID() << G4endl;
0070 
0071   if (ftrackerCollID < 0 || fcalorimeterCollID < 0 || fmuonCollID < 0) return;
0072 
0073   G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
0074   ExN04TrackerHitsCollection* THC = NULL;
0075   ExN04CalorimeterHitsCollection* CHC = NULL;
0076   ExN04MuonHitsCollection* MHC = NULL;
0077 
0078   if (HCE) {
0079     THC = (ExN04TrackerHitsCollection*)(HCE->GetHC(ftrackerCollID));
0080     CHC = (ExN04CalorimeterHitsCollection*)(HCE->GetHC(fcalorimeterCollID));
0081     MHC = (ExN04MuonHitsCollection*)(HCE->GetHC(fmuonCollID));
0082   }
0083 
0084   if (THC) {
0085     G4int n_hit = THC->entries();
0086     G4cout << "     " << n_hit << " hits are stored in ExN04TrackerHitsCollection." << G4endl;
0087   }
0088 
0089   if (CHC) {
0090     G4int n_hit = CHC->entries();
0091     G4cout << "     " << n_hit << " hits are stored in ExN04CalorimeterHitsCollection." << G4endl;
0092     G4double totE = 0;
0093     for (int i = 0; i < n_hit; i++) {
0094       totE += (*CHC)[i]->GetEdep();
0095     }
0096     G4cout << "     Total energy deposition in calorimeter : " << totE / GeV << " (GeV)" << G4endl;
0097   }
0098 
0099   if (MHC) {
0100     G4int n_hit = MHC->entries();
0101     G4cout << "     " << n_hit << " hits are stored in ExN04MuonHitsCollection." << G4endl;
0102   }
0103 }