Back to home page

EIC code displayed by LXR

 
 

    


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

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:
0028 /// brief:
0029 #include "EventAction.hh"
0030 
0031 #include "AnalysisManager.hh"
0032 #include "ChromosomeHit.hh"
0033 #include "ChromosomeMapper.hh"
0034 #include "DNAGeometry.hh"
0035 #include "DNAHit.hh"
0036 #include "DetectorConstruction.hh"
0037 
0038 #include "G4RunManager.hh"
0039 
0040 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0041 
0042 EventAction::EventAction(AnalysisManager* man) : fAnalysisManager(man) {}
0043 
0044 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0045 
0046 void EventAction::Initialize()
0047 {
0048   // Get DNA Geometry
0049   const auto* det = dynamic_cast<const DetectorConstruction*>(
0050     G4RunManager::GetRunManager()->GetUserDetectorConstruction());
0051   fDNAGeometry = det->GetDNAGeometry();
0052 
0053   // Prepare Chromo Hits Map
0054   std::vector<G4String> keys = fDNAGeometry->GetChromosomeMapper()->GetChromosomeKeys();
0055   for (const auto& key : keys) {
0056     uint32_t key_i = G4::hashing::crc32::Hash(key);
0057     fChromoHitMap[key_i] = nullptr;
0058   }
0059   fInitialized = true;
0060 }
0061 
0062 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0063 
0064 void EventAction::BeginOfEventAction(const G4Event*)
0065 {
0066   if (!fInitialized) {
0067     Initialize();
0068   }
0069 
0070   fEdepCell = 0;
0071   fTraLenCell = 0;
0072   fTraLenChro = 0;
0073 
0074   // Prepare DNA Hits vector
0075   fDNAHits.reserve(10000);
0076 
0077   std::vector<G4String> keys = fDNAGeometry->GetChromosomeMapper()->GetChromosomeKeys();
0078   // ChromosomeHit* theHit;
0079   for (const auto& it : keys) {
0080     uint32_t key_i = G4::hashing::crc32::Hash(it);
0081     fChromoHitMap[key_i] = new ChromosomeHit(it);
0082   }
0083 }
0084 
0085 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0086 
0087 void EventAction::EndOfEventAction(const G4Event*)
0088 {
0089   // post-analysis
0090   fAnalysisManager->ProcessPrimary(fprimstoppos, fTraLenCell, fTraLenChro);
0091   fAnalysisManager->ProcessDNAHitsVector(fDNAHits);
0092   fAnalysisManager->ProcessChromosomeHitMap(fChromoHitMap);
0093   fAnalysisManager->ProcessCellEdep(fEdepCell);
0094 
0095   // destruction /////////////////////////////////////////////////////////////
0096   for (auto& it : fChromoHitMap) {
0097     delete it.second;
0098   }
0099 
0100   for (auto& fDNAHit : fDNAHits) {
0101     delete fDNAHit;
0102   }
0103   fDNAHits.clear();
0104 }
0105 
0106 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0107 
0108 void EventAction::AddChromosomeEdep(const G4String& key, const G4double& e, const G4bool& isDNA)
0109 {
0110   uint32_t key_i = G4::hashing::crc32::Hash(key);
0111   auto it = fChromoHitMap.find(key_i);
0112   if (it != fChromoHitMap.end()) {
0113     if (isDNA) {
0114       it->second->AddDNAEdep(e);
0115     }
0116     else {
0117       it->second->AddChromosomeEdep(e);
0118     }
0119   }
0120   else {
0121     G4ExceptionDescription errmsg;
0122     errmsg << "Energy deposit in unknown chromosome: " << key << G4endl;
0123     G4Exception("EventAction::AddChromosomeEdep", "ERR_UNKNOWN_CHROMOSOME", FatalException, errmsg);
0124   }
0125 }
0126 // 2600754154
0127 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0128 
0129 void EventAction::AddCellEdep(const G4double& edep)
0130 {
0131   fEdepCell += edep;
0132 }
0133 
0134 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0135 
0136 void EventAction::AddTrackLengthCell(const G4double& tl)
0137 {
0138   fTraLenCell += tl;
0139 }
0140 
0141 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0142 
0143 void EventAction::AddTrackLengthChro(const G4double& tl)
0144 {
0145   fTraLenChro += tl;
0146 }
0147 
0148 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......