Back to home page

EIC code displayed by LXR

 
 

    


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

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 "ActionInitialization.hh"
0040 
0041 #include "ChemistrySteppingAction.hh"
0042 #include "ChemistryTrackingManager.hh"
0043 #include "EventAction.hh"
0044 #include "PrimaryGeneratorAction.hh"
0045 #include "RunAction.hh"
0046 #include "StackingAction.hh"
0047 
0048 #include "G4DNAChemistryManager.hh"
0049 #include "G4H2O.hh"
0050 #include "G4MoleculeCounter.hh"
0051 #include "G4MoleculeCounterManager.hh"
0052 #include "G4MoleculeReactionCounter.hh"
0053 #include "G4Scheduler.hh"
0054 #include "G4UserTimeStepAction.hh"
0055 
0056 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0057 void ActionInitialization::BuildForMaster() const
0058 {
0059   SetUserAction(new RunAction);
0060   BuildMoleculeCounters();
0061 }
0062 
0063 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0064 void ActionInitialization::Build() const
0065 {
0066   SetUserAction(new PrimaryGeneratorAction());
0067 
0068   SetUserAction(new RunAction);
0069   SetUserAction(new EventAction);
0070   SetUserAction(new StackingAction);
0071 
0072   if (G4DNAChemistryManager::IsActivated()) {
0073     G4Scheduler::Instance()->SetUserAction(new G4UserTimeStepAction);
0074 
0075     auto chemTrackingManager = new ChemistryTrackingManager();
0076     chemTrackingManager->SetUserAction(new ChemistrySteppingAction);
0077     G4Scheduler::Instance()->SetInteractivity(chemTrackingManager);
0078     BuildMoleculeCounters();
0079   }
0080 }
0081 
0082 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0083 void ActionInitialization::BuildMoleculeCounters() const
0084 {
0085   G4MoleculeCounterManager::Instance()->SetResetCountersBeforeEvent(true);
0086   // The sensitive detectors will retrieve and process the counts after events
0087   // Note that this setting is different from the other examples!
0088 
0089   G4MoleculeCounterManager::Instance()->SetResetCountersBeforeRun(false);
0090   // SetResetCountersBeforeRun is irrelevant when resetting before event
0091   // So we just set it to false here.
0092 
0093   // Register molecule counters
0094 
0095   // Basic (built-in) Counters
0096   {
0097     // Basic molecule counter using a fixed time precision.
0098     // this will create many records {molecule -> {time -> conut}}
0099     auto counter = std::make_unique<G4MoleculeCounter>("BasicCounter");
0100     counter->IgnoreMolecule(G4H2O::Definition());
0101     counter->SetTimeComparer(G4MoleculeCounterTimeComparer::CreateWithFixedPrecision(10 * ps));
0102     G4MoleculeCounterManager::Instance()->RegisterCounter(std::move(counter));
0103   }
0104   {
0105     // Basic molecule counter using variable time precision without time restrition.
0106     // The precision is changed with respect to chemistry time.
0107     auto counter = std::make_unique<G4MoleculeCounter>("BasicCounter_VariablePrecision");
0108     counter->IgnoreMolecule(G4H2O::Definition());
0109     counter->SetTimeComparer(G4MoleculeCounterTimeComparer::CreateWithVariablePrecision({
0110       {10 * ps, 5 * ps},
0111       {100 * ps, 50 * ps},
0112       {1000 * ps, 500 * ps},
0113       {10 * ns, 5 * ns},
0114       {1 * microsecond, 50 * ns},
0115     }));
0116     G4MoleculeCounterManager::Instance()->RegisterCounter(std::move(counter));
0117   }
0118 
0119   // Molecule Reaction Counter with fixed time precision.
0120   // Set to be active from 0ps to 1us.
0121   {
0122     auto counter = std::make_unique<G4MoleculeReactionCounter>("Reactions");
0123     counter->SetTimeComparer(G4MoleculeCounterTimeComparer::CreateWithFixedPrecision(10 * ps));
0124     G4MoleculeCounterManager::Instance()->RegisterCounter(std::move(counter));
0125   }
0126 }
0127 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......