Back to home page

EIC code displayed by LXR

 
 

    


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

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