Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21:49

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 // Phys. Med. Biol. 63(10) (2018) 105014-12pp
0032 // The Geant4-DNA web site is available at http://geant4-dna.org
0033 //
0034 //
0035 #include "PrimaryKiller.hh"
0036 
0037 #include <G4Event.hh>
0038 #include <G4EventManager.hh>
0039 #include <G4RunManager.hh>
0040 #include <G4SystemOfUnits.hh>
0041 #include <G4UIcmdWithADoubleAndUnit.hh>
0042 #include <G4UnitsTable.hh>
0043 #include <globals.hh>
0044 
0045 /** \file PrimaryKiller.cc
0046     \class PrimaryKiller
0047 
0048     Kill the primary particle:
0049     - either after a given energy loss
0050     - or after the primary particle has reached a given energy
0051  */
0052 
0053 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0054 
0055 PrimaryKiller::PrimaryKiller(G4String name, G4int depth)
0056   : G4VPrimitiveScorer(name, depth), G4UImessenger()
0057 {
0058   fELoss = 0.;  // cumulated energy for current event
0059 
0060   fELossRange_Min = DBL_MAX;  // fELoss from which the primary is killed
0061   fELossRange_Max = DBL_MAX;  // fELoss from which the event is aborted
0062   fKineticE_Min = 0;  // kinetic energy below which the primary is killed
0063 
0064   fpELossUI = new G4UIcmdWithADoubleAndUnit("/primaryKiller/eLossMin", this);
0065   fpAbortEventIfELossUpperThan = new G4UIcmdWithADoubleAndUnit("/primaryKiller/eLossMax", this);
0066   fpMinKineticE = new G4UIcmdWithADoubleAndUnit("/primaryKiller/minKineticE", this);
0067 }
0068 
0069 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0070 
0071 PrimaryKiller::~PrimaryKiller()
0072 {
0073   ;
0074 }
0075 
0076 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0077 
0078 void PrimaryKiller::SetNewValue(G4UIcommand* command, G4String newValue)
0079 {
0080   if (command == fpELossUI) {
0081     fELossRange_Min = fpELossUI->GetNewDoubleValue(newValue);
0082   }
0083   else if (command == fpAbortEventIfELossUpperThan) {
0084     fELossRange_Max = fpAbortEventIfELossUpperThan->GetNewDoubleValue(newValue);
0085   }
0086 }
0087 
0088 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0089 
0090 G4bool PrimaryKiller::ProcessHits(G4Step* aStep, G4TouchableHistory*)
0091 {
0092   const G4Track* track = aStep->GetTrack();
0093 
0094   if (track->GetTrackID() != 1) return FALSE;
0095 
0096   //-------------------
0097 
0098   double kineticE = aStep->GetPostStepPoint()->GetKineticEnergy();
0099 
0100   G4double eLoss = aStep->GetPreStepPoint()->GetKineticEnergy() - kineticE;
0101 
0102   if (eLoss == 0.) return FALSE;
0103 
0104   //-------------------
0105 
0106   fELoss += eLoss;
0107 
0108   if (fELoss > fELossRange_Max) {
0109     G4RunManager::GetRunManager()->AbortEvent();
0110     int eventID = G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetEventID();
0111     G4cout << "Aborts event " << eventID
0112            << ", energy loss "
0113               "is too large. \n"
0114            << " * Energy loss by primary is: " << G4BestUnit(fELoss, "Energy")
0115            << ". Event is aborted if the Eloss is > " << G4BestUnit(fELossRange_Max, "Energy")
0116            << G4endl;
0117   }
0118 
0119   if (fELoss >= fELossRange_Min) {  //|| kineticE <= fKineticE_Min){
0120     ((G4Track*)track)->SetTrackStatus(fStopAndKill);
0121     G4cout << "Kill track at : " << G4BestUnit(kineticE, "Energy")
0122            << ", Energy loss by primary is: " << G4BestUnit(fELoss, "Energy")
0123            << ", primary is terminated as Eloss is >: " << G4BestUnit(fELossRange_Min, "Energy")
0124            << G4endl;  //", EThreshold is: "
0125     //           << G4BestUnit(fEThreshold, "Energy")
0126     //          << G4endl;
0127   }
0128 
0129   return true;
0130 }
0131 
0132 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0133 
0134 void PrimaryKiller::Initialize(G4HCofThisEvent* /*HCE*/)
0135 {
0136   Clear();
0137 }
0138 
0139 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0140 
0141 void PrimaryKiller::EndOfEvent(G4HCofThisEvent*) {}
0142 
0143 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0144 
0145 void PrimaryKiller::Clear()
0146 {
0147   fELoss = 0.;
0148 }
0149 
0150 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0151 
0152 void PrimaryKiller::DrawAll()
0153 {
0154   ;
0155 }
0156 
0157 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0158 
0159 void PrimaryKiller::PrintAll() {}
0160 
0161 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......