Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-13 08:27:56

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 // The `molcounters` example(s) are provided as part of Geant4-DNA
0027 // and any report or published result obtained using it shall cite
0028 // the respective Geant4-DNA collaboration publications.
0029 //
0030 // Reports or results obtained using the spatially-aware `MoleculeCounter`
0031 // provided in this example, shall further cite:
0032 //
0033 // Velten & Tomé, Radiation Physics and Chemistry, 2023 (10.1016/j.radphyschem.2023.111194)
0034 //
0035 //
0036 // Author: Christian Velten (2025)
0037 //
0038 
0039 #include <memory>
0040 
0041 #include "MoleculeCounter.hh"
0042 
0043 #include "G4Event.hh"
0044 #include "G4EventManager.hh"
0045 #include "G4MolecularConfiguration.hh"
0046 #include "G4Molecule.hh"
0047 #include "G4MoleculeLocator.hh"
0048 #include "G4Navigator.hh"
0049 #include "G4Scheduler.hh"
0050 #include "G4UIcommand.hh"
0051 #include "G4UnitsTable.hh"
0052 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0053 using G4VMoleculeCounterIndex = G4VMoleculeCounter::G4VMoleculeCounterIndex;
0054 
0055 G4ThreadLocal std::unique_ptr<G4Navigator> MoleculeCounter::fNavigator = nullptr;
0056 
0057 MoleculeCounter::MoleculeCounter(G4String name)
0058   : G4VUserMoleculeCounter(name, G4VMoleculeCounter::MoleculeCounterType::Other),
0059     fIgnoreMoleculePosition(false),
0060     fIgnoreCopyNumbers(true)
0061 {}
0062 
0063 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0064 void MoleculeCounter::InitializeUser() {}
0065 
0066 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0067 std::unique_ptr<G4VMoleculeCounterIndex> MoleculeCounter::BuildIndex(const G4Track* aTrack) const
0068 {
0069   if (fVerbose > 1) {
0070     G4cout << "MoleculeCounter::BuildIndex(" << aTrack->GetTrackID() << " : "
0071            << GetMolecule(aTrack)->GetName() << ")" << G4endl;
0072   }
0073   if (fIgnoreMoleculePosition) {
0074     return std::make_unique<MoleculeCounterIndex>(
0075       GetMolecule(aTrack)->GetMolecularConfiguration(), nullptr);
0076   }
0077   else {
0078     const G4VTouchable* touchable = aTrack->GetNextTouchable();
0079     G4TouchableHistory* touchableHistory = nullptr;
0080 
0081     if (touchable == nullptr) touchable = aTrack->GetTouchable();
0082     if (touchable == nullptr) {
0083       auto touchableHandle = G4MoleculeLocator::Instance()->LocateMoleculeTrack(aTrack);
0084       touchable = touchableHandle();
0085     }
0086     if (touchable == nullptr) {  // still not found -- should never fire
0087       G4ExceptionDescription errMsg;
0088       errMsg << "Molecule scorer requires a valid volume pointer."
0089              << " G4Track->GetVolume: " << aTrack->GetVolume()
0090              << " G4Navigator->LocateGlobalPointAndUpdateTouchable: nullptr" << G4endl;
0091       G4Exception("MoleculeCounter::BuildIndex", "VOL_NOT_FOUND", FatalException, errMsg);
0092     }
0093 
0094     auto index = std::make_unique<MoleculeCounterIndex>(
0095         GetMolecule(aTrack)->GetMolecularConfiguration(), touchable);
0096 
0097     delete touchableHistory;
0098     return index;
0099   }
0100 }
0101 
0102 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0103 std::unique_ptr<G4VMoleculeCounterIndex>
0104 MoleculeCounter::BuildIndex(const G4Track* aTrack, const G4StepPoint* aStepPoint) const
0105 {
0106   return std::make_unique<MoleculeCounterIndex>(
0107       GetMolecule(aTrack)->GetMolecularConfiguration(), aStepPoint->GetTouchable());
0108 }
0109 
0110 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0111 std::unique_ptr<G4VMoleculeCounterIndex>
0112 MoleculeCounter::BuildSimpleIndex(const G4MolecularConfiguration* configuration) const
0113 {
0114   return std::make_unique<MoleculeCounterIndex>(
0115     configuration, nullptr);
0116 }
0117 
0118 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0119 G4bool MoleculeCounter::GetIgnoreMoleculePosition() const
0120 {
0121   return fIgnoreMoleculePosition;
0122 }
0123 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0124 void MoleculeCounter::SetIgnoreMoleculePosition(G4bool flag)
0125 {
0126   fIgnoreMoleculePosition = flag;
0127 }
0128 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0129 void MoleculeCounter::SetNegativeCountsAreFatal(G4bool flag)
0130 {
0131   G4VMoleculeCounter::SetNegativeCountsAreFatal(flag);
0132   // this is protected in G4VMoleculeCounter and thus, must be exposed by the derived class
0133 }
0134 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......