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