Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-21 08:11:27

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 //
0027 /// \file ExGflashEventAction.cc
0028 /// \brief Implementation of the ExGflashEventAction class
0029 //
0030 
0031 #include "ExGflashEventAction.hh"
0032 
0033 #include "ExGflashDetectorConstruction.hh"
0034 #include "ExGflashHistoManager.hh"
0035 #include "ExGflashHit.hh"
0036 
0037 #include "G4Event.hh"
0038 #include "G4EventManager.hh"
0039 #include "G4SDManager.hh"
0040 #include "G4SystemOfUnits.hh"
0041 #include "G4UImanager.hh"
0042 // std
0043 #include <algorithm>
0044 #include <iostream>
0045 #include <vector>
0046 
0047 using MyVector = std::vector<G4double>;
0048 
0049 // Gflash
0050 using namespace std;
0051 
0052 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0053 
0054 ExGflashEventAction::ExGflashEventAction(ExGflashDetectorConstruction* det) : fDet(det) {}
0055 
0056 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0057 
0058 ExGflashEventAction::~ExGflashEventAction() = default;
0059 
0060 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0061 
0062 void ExGflashEventAction::BeginOfEventAction(const G4Event* /* evt */) {}
0063 
0064 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0065 
0066 void ExGflashEventAction::EndOfEventAction(const G4Event* evt)
0067 {
0068   G4SDManager* SDman = G4SDManager::GetSDMpointer();
0069   G4String colNam;
0070   fCalorimeterCollectionId = SDman->GetCollectionID(colNam = "ExGflashCollection");
0071 
0072   if (fCalorimeterCollectionId < 0) {
0073     return;
0074   }
0075 
0076   G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
0077   ExGflashHitsCollection* THC = nullptr;
0078   G4double totE = 0;
0079 
0080   // Read out of the crysta ECAL
0081   THC = (ExGflashHitsCollection*)(HCE->GetHC(fCalorimeterCollectionId));
0082 
0083   if (THC != nullptr) {
0084     /// Hits in sensitive Detector
0085     int n_hit = THC->entries();
0086 
0087     G4PrimaryVertex* pvertex = evt->GetPrimaryVertex();
0088     // Computing (x,y,z) of vertex of initial particles
0089     G4ThreeVector vtx = pvertex->GetPosition();
0090     G4PrimaryParticle* pparticle = pvertex->GetPrimary();
0091     // direction of the Shower
0092     G4ThreeVector mom = pparticle->GetMomentumDirection();
0093 
0094     G4double Ekin = pparticle->GetKineticEnergy();
0095     G4double mass = pparticle->GetParticleDefinition()->GetPDGMass();
0096     G4double Etot = Ekin / MeV + mass / MeV;
0097 
0098     G4int nLbin = fDet->GetnLtot();
0099     G4int nRbin = fDet->GetnRtot();
0100     G4double dLradl = fDet->GetdLradl();
0101     G4double dRradl = fDet->GetdRradl();
0102 
0103     G4double SDRadl = fDet->GetSDRadLen();  // SD matrial rad len
0104     G4double SDRm = fDet->GetSDRm();  // SD Radius Moliere
0105 
0106     // init to to 0.0
0107     MyVector dEdL(nLbin, 0.0);
0108     MyVector dEdR(nRbin, 0.0);
0109 
0110     G4AnalysisManager* fAnalysisManager = G4AnalysisManager::Instance();
0111 
0112     fAnalysisManager->FillH1(1, n_hit + 0.5);
0113     /// For all Hits in sensitive detector
0114     for (int i = 0; i < n_hit; i++) {
0115       G4double estep = (*THC)[i]->GetEdep();
0116       fAnalysisManager->FillH1(2, estep / MeV);
0117       estep /= MeV;
0118 
0119       if (estep > 0.0) {
0120         totE += estep;
0121 
0122         G4ThreeVector hitpos = (*THC)[i]->GetPos();
0123         // in shower coordinate system
0124         // from shower start
0125         G4ThreeVector l = hitpos - vtx;
0126         // longitudinal profile
0127         G4ThreeVector longitudinal = l.dot(mom) * mom;
0128         // shower profiles (Radial)
0129         G4ThreeVector radial = l - longitudinal;
0130 
0131         auto SlideNb = G4int((longitudinal.mag() / SDRadl) / dLradl);
0132         auto RingNb = G4int((radial.mag() / SDRm) / dRradl);
0133 
0134         if ((SlideNb >= 0 && SlideNb < nLbin) && (RingNb >= 0 && RingNb < nRbin)) {
0135           dEdL[SlideNb] += estep;
0136           dEdR[RingNb] += estep;
0137         }
0138       }
0139     }
0140 
0141     G4double Lnorm = 100. / dLradl / Etot;
0142     G4double Lsum = 0.0;
0143     for (int i = 0; i < nLbin; i++) {  // Slide
0144       fAnalysisManager->FillP1(0, (i + 0.5) * dLradl, dEdL[i] * Lnorm);
0145       Lsum += dEdL[i];
0146       fAnalysisManager->FillP1(2, (i + 0.5) * dLradl, Lsum * Lnorm);
0147     }
0148     G4double Rnorm = 100. / dRradl / Etot;
0149     G4double Rsum = 0.0;
0150     for (int i = 0; i < nRbin; i++) {  // Ring
0151       fAnalysisManager->FillP1(1, (i + 0.5) * dRradl, dEdR[i] * Rnorm);
0152       Rsum += dEdR[i];
0153       fAnalysisManager->FillP1(3, (i + 0.5) * dRradl, Rsum * Rnorm);
0154     }
0155 
0156     fAnalysisManager->FillH1(0, totE / Etot * 100.);
0157   }
0158 }
0159 
0160 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......