Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-03 09:04:58

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 // This example is provided by the Geant4-DNA collaboration
0027 // Any report or published results obtained using the Geant4-DNA software
0028 // shall cite the following Geant4-DNA collaboration publication:
0029 // Med. Phys. 37 (2010) 4692-4708
0030 // J. Comput. Phys. 274 (2014) 841-882
0031 // The Geant4-DNA web site is available at http://geant4-dna.org
0032 //
0033 //
0034 /// \file TimeStepAction.hh
0035 /// \brief Implementation of the TimeStepAction class
0036 
0037 #include "TimeStepAction.hh"
0038 
0039 #include "G4MolecularConfiguration.hh"
0040 #include "G4Molecule.hh"
0041 #include "G4MoleculeTable.hh"
0042 #include "G4SystemOfUnits.hh"
0043 #include "G4UnitsTable.hh"
0044 
0045 #include <G4Scheduler.hh>
0046 
0047 TimeStepAction::TimeStepAction() : G4UserTimeStepAction()
0048 {
0049   /**
0050    * Give to G4ITTimeStepper the user defined time steps
0051    * eg : from 1 picosecond to 10 picosecond, the minimum time
0052    * step that the TimeStepper can returned is 0.1 picosecond.
0053    * Those time steps are used for the chemistry of G4DNA
0054    */
0055 
0056   AddTimeStep(1 * picosecond, 0.1 * picosecond);
0057   AddTimeStep(10 * picosecond, 1 * picosecond);
0058   AddTimeStep(100 * picosecond, 3 * picosecond);
0059   AddTimeStep(1000 * picosecond, 10 * picosecond);
0060   AddTimeStep(10000 * picosecond, 100 * picosecond);
0061 }
0062 
0063 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0064 
0065 void TimeStepAction::UserPostTimeStepAction()
0066 {
0067   if (G4Scheduler::Instance()->GetGlobalTime() > 99 * ns) {
0068     G4cout << "_________________" << G4endl;
0069     G4cout << "At : " << G4BestUnit(G4Scheduler::Instance()->GetGlobalTime(), "Time") << G4endl;
0070 
0071     auto species = G4MoleculeTable::Instance()->GetConfiguration("°OH");
0072     PrintSpecieInfo(species);
0073   }
0074 }
0075 
0076 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0077 
0078 void TimeStepAction::UserReactionAction(const G4Track& reactantA, const G4Track& reactantB,
0079                                         const std::vector<G4Track*>* products)
0080 {
0081   // this function shows how to get species ID, positions of reaction.
0082   G4cout << G4endl;
0083 
0084   G4cout << "At : " << G4Scheduler::Instance()->GetGlobalTime() / ns
0085          << " (ns) reactantA = " << GetMolecule(reactantA)->GetName()
0086          << " (ID number = " << reactantA.GetTrackID() << ")"
0087          << " at position : " << reactantA.GetPosition() / nm
0088          << " reacts with reactantB = " << GetMolecule(&reactantB)->GetName()
0089          << " (ID number = " << reactantB.GetTrackID() << ")"
0090          << " at position : " << reactantA.GetPosition() / nm << G4endl;
0091 
0092   if (products) {
0093     auto nbProducts = (G4int)products->size();
0094     for (G4int i = 0; i < nbProducts; i++) {
0095       G4cout << "      creating product " << i + 1 << " =" << GetMolecule((*products)[i])->GetName()
0096              << " position : " << (*products)[i]->GetPosition() << G4endl;
0097     }
0098   }
0099   G4cout << G4endl;
0100 }
0101 
0102 void TimeStepAction::PrintSpecieInfo(G4MolecularConfiguration* molconf)
0103 {
0104   // this function shows how to get a specific species ID, positions at each time step.
0105   auto moleculeID = molconf->GetMoleculeID();
0106   const G4String& moleculeName = molconf->GetFormatedName();
0107   G4cout << "Get inf of : " << moleculeName << G4endl;
0108   auto trackList = G4ITTrackHolder::Instance()->GetMainList(moleculeID);
0109 
0110   if (trackList == nullptr) {
0111     G4cout << "No species" << G4endl;
0112     return;
0113   }
0114   G4TrackList::iterator it = trackList->begin();
0115   G4TrackList::iterator end = trackList->end();
0116   for (; it != end; ++it) {
0117     auto track = *it;
0118     G4cout << "TrackID: " << track->GetTrackID() << "  position : " << track->GetPosition() / nm
0119            << G4endl;
0120   }
0121 }