Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-30 07:32:57

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 ExGflashEventAction.cc
0027 /// \brief Implementation of the ExGflashEventAction class
0028 
0029 // Created by Joanna Weng 26.11.2004
0030 
0031 #include "ExGflashEventAction.hh"
0032 
0033 #include "ExGflashHit.hh"
0034 
0035 #include "G4Event.hh"
0036 #include "G4EventManager.hh"
0037 #include "G4SDManager.hh"
0038 #include "G4SystemOfUnits.hh"
0039 #include "G4TrajectoryContainer.hh"
0040 #include "G4UImanager.hh"
0041 // std
0042 #include <algorithm>
0043 #include <iostream>
0044 // Gflash
0045 using namespace std;
0046 
0047 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0048 
0049 ExGflashEventAction::ExGflashEventAction() = default;
0050 
0051 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0052 
0053 ExGflashEventAction::~ExGflashEventAction()
0054 {
0055   if (fNevent > 0) {
0056     G4cout << "Internal Real Elapsed Time /event is: " << fDtime / fNevent << G4endl;
0057   }
0058 }
0059 
0060 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0061 
0062 void ExGflashEventAction::BeginOfEventAction(const G4Event* evt)
0063 {
0064   fTimerIntern.Start();
0065   G4cout << " ------ Start ExGflashEventAction ----- " << G4endl;
0066   fNevent = evt->GetEventID();
0067   G4cout << " Start generating event Nr " << fNevent << G4endl << G4endl;
0068 }
0069 
0070 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0071 
0072 void ExGflashEventAction::EndOfEventAction(const G4Event* evt)
0073 {
0074   fTimerIntern.Stop();
0075   G4cout << G4endl;
0076   G4cout << "******************************************";
0077   G4cout << G4endl;
0078   G4cout << "Internal Real Elapsed Time is: " << fTimerIntern.GetRealElapsed();
0079   G4cout << G4endl;
0080   G4cout << "Internal System Elapsed Time: " << fTimerIntern.GetSystemElapsed();
0081   G4cout << G4endl;
0082   G4cout << "Internal GetUserElapsed Time: " << fTimerIntern.GetUserElapsed();
0083   G4cout << G4endl;
0084   G4cout << "******************************************" << G4endl;
0085   fDtime += fTimerIntern.GetRealElapsed();
0086   G4cout << " ------ ExGflashEventAction::End of event nr. " << fNevent << "  -----" << G4endl;
0087 
0088   G4SDManager* SDman = G4SDManager::GetSDMpointer();
0089   G4String colNam;
0090   fCalorimeterCollectionId = SDman->GetCollectionID(colNam = "ExGflashCollection");
0091   if (fCalorimeterCollectionId < 0) return;
0092   G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
0093   ExGflashHitsCollection* THC = nullptr;
0094   G4double totE = 0;
0095   // Read out of the crysta ECAL
0096   THC = (ExGflashHitsCollection*)(HCE->GetHC(fCalorimeterCollectionId));
0097   if (THC) {
0098     /// Hits in sensitive Detector
0099     int n_hit = THC->entries();
0100     G4cout << "  " << n_hit << " hits are stored in ExGflashHitsCollection " << G4endl;
0101     G4PrimaryVertex* pvertex = evt->GetPrimaryVertex();
0102     /// Computing (x,y,z) of vertex of initial particles
0103     G4ThreeVector vtx = pvertex->GetPosition();
0104     G4PrimaryParticle* pparticle = pvertex->GetPrimary();
0105     // direction of the Shower
0106     G4ThreeVector mom = pparticle->GetMomentum() / pparticle->GetMomentum().mag();
0107 
0108     //@@@ ExGflashEventAction: Magicnumber
0109     G4double energyincrystal[100];
0110     G4int hitsincrystal[100];
0111     for (int i = 0; i < 100; i++)
0112       energyincrystal[i] = 0.;
0113     for (int i = 0; i < 100; i++)
0114       hitsincrystal[i] = 0.;
0115 
0116     //@@@ ExGflashEventAction: Magicnumber
0117     /// For all Hits in sensitive detector
0118     for (int i = 0; i < n_hit; i++) {
0119       G4double estep = (*THC)[i]->GetEdep() / GeV;
0120       if (estep > 0.0) {
0121         totE += (*THC)[i]->GetEdep() / GeV;
0122         G4int num = (*THC)[i]->GetCrystalNum();
0123 
0124         energyincrystal[num] += (*THC)[i]->GetEdep() / GeV;
0125         hitsincrystal[num]++;
0126         // G4cout << num << G4endl;
0127         //   G4cout << " Crystal Nummer " <<  (*THC)[i]->GetCrystalNum()  << G4endl;
0128         //   G4cout <<  (*THC)[i]->GetCrystalNum() /10 <<
0129         //  "  "<<(*THC)[i]->GetCrystalNum()%10 << G4endl;
0130 
0131         G4ThreeVector hitpos = (*THC)[i]->GetPos();
0132         G4ThreeVector l(hitpos.x(), hitpos.y(), hitpos.z());
0133         // distance from shower start
0134         l = l - vtx;
0135         // projection on shower axis = longitudinal profile
0136         G4ThreeVector longitudinal = l;
0137         // shower profiles (Radial)
0138         G4ThreeVector radial = vtx.cross(l);
0139       }
0140     }
0141     G4double max = 0;
0142     G4int index = 0;
0143     // Find crystal with maximum energy
0144     for (int i = 0; i < 100; i++) {
0145       // G4cout << i <<"  " << energyincrystal[i] << G4endl;
0146       if (max < energyincrystal[i]) {
0147         max = energyincrystal[i];
0148         index = i;
0149       }
0150     }
0151     // G4cout << index <<" NMAX  " << index << G4endl;
0152 
0153     // 3x3 matrix of crystals around the crystal with the maximum energy deposit
0154     G4double e3x3 = energyincrystal[index] + energyincrystal[index + 1] + energyincrystal[index - 1]
0155                     + energyincrystal[index - 10] + energyincrystal[index - 9]
0156                     + energyincrystal[index - 11] + energyincrystal[index + 10]
0157                     + energyincrystal[index + 11] + energyincrystal[index + 9];
0158 
0159     // 5x5 matrix of crystals around the crystal with the maximum energy deposit
0160     G4double e5x5 =
0161       energyincrystal[index] + energyincrystal[index + 1] + energyincrystal[index - 1]
0162       + energyincrystal[index + 2] + energyincrystal[index - 2] + energyincrystal[index - 10]
0163       + energyincrystal[index - 9] + energyincrystal[index - 11] + energyincrystal[index - 8]
0164       + energyincrystal[index - 12] + energyincrystal[index + 10] + energyincrystal[index + 11]
0165       + energyincrystal[index + 9] + energyincrystal[index + 12] + energyincrystal[index + 8];
0166 
0167     // 3x3 matrix of crystals around the crystal with the maximum energy deposit
0168     G4int num3x3 = hitsincrystal[index] + hitsincrystal[index + 1] + hitsincrystal[index - 1]
0169                    + hitsincrystal[index - 10] + hitsincrystal[index - 9]
0170                    + hitsincrystal[index - 11] + hitsincrystal[index + 10]
0171                    + hitsincrystal[index + 11] + hitsincrystal[index + 9];
0172 
0173     // 5x5 matrix of crystals around the crystal with the maximum energy deposit
0174     G4int num5x5 = hitsincrystal[index] + hitsincrystal[index + 1] + hitsincrystal[index - 1]
0175                    + hitsincrystal[index + 2] + hitsincrystal[index - 2] + hitsincrystal[index - 10]
0176                    + hitsincrystal[index - 9] + hitsincrystal[index - 11] + hitsincrystal[index - 8]
0177                    + hitsincrystal[index - 12] + hitsincrystal[index + 10]
0178                    + hitsincrystal[index + 11] + hitsincrystal[index + 9]
0179                    + hitsincrystal[index + 12] + hitsincrystal[index + 8];
0180 
0181     G4cout << "   e1  " << energyincrystal[index] << "   e3x3  " << e3x3 << "   GeV  e5x5  " << e5x5
0182            << G4endl;
0183 
0184     G4cout << "   num1  " << hitsincrystal[index] << "   num3x3  " << num3x3 << "    num5x5  "
0185            << num5x5 << G4endl;
0186   }
0187 
0188   G4cout << " Total energy deposited in the calorimeter: " << totE << " (GeV)" << G4endl;
0189   G4TrajectoryContainer* trajectoryContainer = evt->GetTrajectoryContainer();
0190   G4int n_trajectories = 0;
0191   if (trajectoryContainer) {
0192     n_trajectories = trajectoryContainer->entries();
0193   }
0194   G4cout << "    " << n_trajectories << " trajectories stored in this event." << G4endl;
0195 }
0196 
0197 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......