Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-13 08:28:37

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 Run.cc
0027 /// \brief Implementation of the B3b::Run class
0028 
0029 #include "Run.hh"
0030 
0031 #include "G4Event.hh"
0032 #include "G4HCofThisEvent.hh"
0033 #include "G4RunManager.hh"
0034 #include "G4SDManager.hh"
0035 #include "G4SystemOfUnits.hh"
0036 #include "G4THitsMap.hh"
0037 
0038 namespace B3b
0039 {
0040 
0041 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0042 
0043 void Run::RecordEvent(const G4Event* event)
0044 {
0045   if (fCollID_cryst < 0) {
0046     fCollID_cryst = G4SDManager::GetSDMpointer()->GetCollectionID("crystal/edep");
0047     // G4cout << " fCollID_cryst: " << fCollID_cryst << G4endl;
0048   }
0049 
0050   if (fCollID_patient < 0) {
0051     fCollID_patient = G4SDManager::GetSDMpointer()->GetCollectionID("patient/dose");
0052     // G4cout << " fCollID_patient: " << fCollID_patient << G4endl;
0053   }
0054 
0055   G4int evtNb = event->GetEventID();
0056 
0057   if (evtNb % fPrintModulo == 0) {
0058     G4cout << G4endl << "---> end of event: " << evtNb << G4endl;
0059   }
0060 
0061   // Hits collections
0062   //
0063   G4HCofThisEvent* HCE = event->GetHCofThisEvent();
0064   if (!HCE) return;
0065 
0066   // Energy in crystals : identify 'good events'
0067   //
0068   const G4double eThreshold = 500 * keV;
0069   G4int nbOfFired = 0;
0070 
0071   auto evtMap = static_cast<G4THitsMap<G4double>*>(HCE->GetHC(fCollID_cryst));
0072 
0073   for (auto& mapElement : (*evtMap->GetMap())) {
0074     auto edep = *(mapElement.second);
0075     if (edep > eThreshold) nbOfFired++;
0076     // auto copyNb  = mapElement.first;
0077     // G4cout << "\n  cryst" << copyNb << ": " << edep/keV << " keV ";
0078   }
0079   if (nbOfFired == 2) fGoodEvents++;
0080 
0081   // Dose deposit in patient
0082   //
0083   G4double dose = 0.;
0084 
0085   evtMap = static_cast<G4THitsMap<G4double>*>(HCE->GetHC(fCollID_patient));
0086 
0087   for (auto& mapElement : (*evtMap->GetMap())) {
0088     dose += *(mapElement.second);
0089     // auto copyNb  = mapElement.first;
0090     // G4cout << "\n  patient" << copyNb << ": " << G4BestUnit(dose,"Dose");
0091   }
0092   fSumDose += dose;
0093   fStatDose += dose;
0094 
0095   G4Run::RecordEvent(event);
0096 }
0097 
0098 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0099 
0100 void Run::Merge(const G4Run* run)
0101 {
0102   const Run* localRun = static_cast<const Run*>(run);
0103   fGoodEvents += localRun->fGoodEvents;
0104   fSumDose += localRun->fSumDose;
0105   fStatDose += localRun->fStatDose;
0106   G4Run::Merge(run);
0107 }
0108 
0109 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0110 
0111 }  // namespace B3b