Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-13 08:30:05

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 SD.cc
0027 /// \brief Implementation of the RadioBio::SD class
0028 
0029 #include "SD.hh"
0030 
0031 #include "G4AccumulableManager.hh"
0032 #include "G4HCofThisEvent.hh"
0033 #include "G4SDManager.hh"
0034 #include "G4Step.hh"
0035 #include "G4ThreeVector.hh"
0036 
0037 #include "Hit.hh"
0038 #include "Manager.hh"
0039 #include "VRadiobiologicalAccumulable.hh"
0040 
0041 namespace RadioBio
0042 {
0043 
0044 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0045 
0046 SD::SD(const G4String& name, const G4String& hitsCollectionName) : G4VSensitiveDetector(name)
0047 {
0048   collectionName.insert(hitsCollectionName);
0049 }
0050 
0051 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0052 
0053 void SD::Initialize(G4HCofThisEvent* hce)
0054 {
0055   // Create hits collection
0056   fHitsCollection = new RadioBioHitsCollection(SensitiveDetectorName, collectionName[0]);
0057 
0058   // Add this collection in hce
0059   G4int hcID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
0060   hce->AddHitsCollection(hcID, fHitsCollection);
0061 }
0062 
0063 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0064 
0065 G4bool SD::ProcessHits(G4Step* aStep, G4TouchableHistory*)
0066 {
0067   // FIXME why the namespace specification? Should not be necessary...
0068   RadioBio::Hit* newHit = new RadioBio::Hit();
0069 
0070   // Get the pre-step kinetic energy
0071   G4double eKinPre = aStep->GetPreStepPoint()->GetKineticEnergy();
0072   // Get the post-step kinetic energy
0073   G4double eKinPost = aStep->GetPostStepPoint()->GetKineticEnergy();
0074   // Get the step average kinetic energy
0075   G4double eKinMean = (eKinPre + eKinPost) * 0.5;
0076 
0077   const std::vector<const G4Track*>* secondary = aStep->GetSecondaryInCurrentStep();
0078 
0079   size_t SecondarySize = (*secondary).size();
0080   G4double EnergySecondary = 0.;
0081 
0082   // Get secondary electrons energy deposited
0083   if (SecondarySize)  // Calculate only secondary particles
0084   {
0085     for (size_t numsec = 0; numsec < SecondarySize; numsec++) {
0086       // Get the PDG code of every secondaty particles in current step
0087       G4int PDGSecondary = (*secondary)[numsec]->GetDefinition()->GetPDGEncoding();
0088 
0089       if (PDGSecondary == 11)  // Calculate only secondary electrons
0090       {
0091         // Calculate the energy deposit of secondary electrons in current step
0092         EnergySecondary += (*secondary)[numsec]->GetKineticEnergy();
0093       }
0094     }
0095   }
0096 
0097   // Update the hit with the necessary quantities
0098   newHit->SetTrackID(aStep->GetTrack()->GetTrackID());
0099   newHit->SetPartType(aStep->GetTrack()->GetParticleDefinition());
0100   newHit->SetEkinMean(eKinMean);
0101   newHit->SetDeltaE(aStep->GetTotalEnergyDeposit());
0102   newHit->SetEinit(aStep->GetPreStepPoint()->GetKineticEnergy());
0103   newHit->SetTrackLength(aStep->GetStepLength());
0104   newHit->SetElectronEnergy(EnergySecondary);
0105   newHit->SetPhysicalVolume(aStep->GetPreStepPoint()->GetPhysicalVolume());
0106   newHit->SetVoxelIndexes(aStep->GetPreStepPoint()->GetTouchableHandle());
0107 
0108   // Insert the hit in the hitcollection
0109   fHitsCollection->insert(newHit);
0110 
0111   // Accumulables are accumulated only if calculation is enabled
0112   for (G4int i = 0; i < G4AccumulableManager::Instance()->GetNofAccumulables(); ++i) {
0113     // Get the accumulable from the proper manager
0114     G4VAccumulable* GenAcc = G4AccumulableManager::Instance()->GetAccumulable(i);
0115 
0116     // Get the quantity from the proper manager using the name
0117     auto q = Manager::GetInstance()->GetQuantity(GenAcc->GetName());
0118 
0119     VRadiobiologicalAccumulable* radioAcc = dynamic_cast<VRadiobiologicalAccumulable*>(GenAcc);
0120 
0121     // If the dynamic_cast did not work, this means that accumulable
0122     // was not a VRadiobiologicalAccumulable
0123     if (radioAcc == nullptr) continue;
0124 
0125     // If calculation is enabled, accumulate
0126     if (q->IsCalculationEnabled()) radioAcc->Accumulate(newHit);
0127   }
0128 
0129   return true;
0130 }
0131 
0132 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0133 
0134 void SD::EndOfEvent(G4HCofThisEvent*)
0135 {
0136   if (verboseLevel > 1) {
0137     G4int nofHits = fHitsCollection->entries();
0138     G4cout << G4endl << "-------->Hits Collection: in this event they are " << nofHits
0139            << " hits in the detector slices: " << G4endl;
0140     for (G4int i = 0; i < nofHits; i++)
0141       (*fHitsCollection)[i]->Print();
0142   }
0143 }
0144 
0145 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0146 
0147 }  // namespace RadioBio