Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-08 08:28:19

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 /// \file SteppingAction.cc
0027 /// \brief Implementation of the SteppingAction class
0028 
0029 #include "SteppingAction.hh"
0030 
0031 #include "DetectorConstruction.hh"
0032 #include "EventAction.hh"
0033 #include "HistoManager.hh"
0034 #include "Run.hh"
0035 
0036 #include "G4PhysicalConstants.hh"
0037 #include "G4Positron.hh"
0038 #include "G4RunManager.hh"
0039 
0040 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0041 
0042 SteppingAction::SteppingAction(DetectorConstruction* det, EventAction* evt)
0043   : fDetector(det), fEventAct(evt)
0044 {}
0045 
0046 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0047 
0048 void SteppingAction::UserSteppingAction(const G4Step* aStep)
0049 {
0050   // track informations
0051   const G4StepPoint* prePoint = aStep->GetPreStepPoint();
0052 
0053   // if World, return
0054   //
0055   G4VPhysicalVolume* volume = prePoint->GetTouchableHandle()->GetVolume();
0056   // if sum of absorbers do not fill exactly a layer: check material, not volume.
0057   const G4Material* mat = volume->GetLogicalVolume()->GetMaterial();
0058   if (mat == fDetector->GetWorldMaterial()) return;
0059 
0060   const G4StepPoint* endPoint = aStep->GetPostStepPoint();
0061   const G4ParticleDefinition* particle = aStep->GetTrack()->GetDefinition();
0062 
0063   // here we are in an absorber. Locate it
0064   //
0065   G4int absorNum = prePoint->GetTouchableHandle()->GetCopyNumber(0);
0066   G4int layerNum = prePoint->GetTouchableHandle()->GetCopyNumber(1);
0067 
0068   // get Run
0069   Run* run = static_cast<Run*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0070 
0071   // collect energy deposit taking into account track weight
0072   G4double edep = aStep->GetTotalEnergyDeposit() * aStep->GetTrack()->GetWeight();
0073 
0074   // collect step length of charged particles
0075   G4double stepl = 0.;
0076   if (particle->GetPDGCharge() != 0.) {
0077     stepl = aStep->GetStepLength();
0078     run->AddChargedStep();
0079   }
0080   else {
0081     run->AddNeutralStep();
0082   }
0083 
0084   //  G4cout << "Nabs= " << absorNum << "   edep(keV)= " << edep << G4endl;
0085 
0086   // sum up per event
0087   fEventAct->SumEnergy(absorNum, edep, stepl);
0088 
0089   // longitudinal profile of edep per absorber
0090   if (edep > 0.) {
0091     G4AnalysisManager::Instance()->FillH1(kMaxAbsor + absorNum, G4double(layerNum + 1), edep);
0092   }
0093   // energy flow
0094   //
0095   //  unique identificator of layer+absorber
0096   G4int Idnow = (fDetector->GetNbOfAbsor()) * layerNum + absorNum;
0097   G4int plane;
0098   //
0099   // leaving the absorber ?
0100   if (endPoint->GetStepStatus() == fGeomBoundary) {
0101     G4ThreeVector position = endPoint->GetPosition();
0102     G4ThreeVector direction = endPoint->GetMomentumDirection();
0103     G4double sizeYZ = 0.5 * fDetector->GetCalorSizeYZ();
0104     G4double Eflow = endPoint->GetKineticEnergy();
0105     if (particle == G4Positron::Positron()) Eflow += 2 * electron_mass_c2;
0106     if ((std::abs(position.y()) >= sizeYZ) || (std::abs(position.z()) >= sizeYZ))
0107       run->SumLateralEleak(Idnow, Eflow);
0108     else if (direction.x() >= 0.)
0109       run->SumEnergyFlow(plane = Idnow + 1, Eflow);
0110     else
0111       run->SumEnergyFlow(plane = Idnow, -Eflow);
0112   }
0113 
0114   ////  example of Birk attenuation
0115   /// G4double destep   = aStep->GetTotalEnergyDeposit();
0116   /// G4double response = BirksAttenuation(aStep);
0117   /// G4cout << " Destep: " << destep/keV << " keV"
0118   ///       << " response after Birks: " << response/keV << " keV" << G4endl;
0119 }
0120 
0121 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0122 
0123 G4double SteppingAction::BirksAttenuation(const G4Step* aStep)
0124 {
0125   // Example of Birk attenuation law in organic scintillators.
0126   // adapted from Geant3 PHYS337. See MIN 80 (1970) 239-244
0127   //
0128   const G4Material* material = aStep->GetTrack()->GetMaterial();
0129   G4double birk1 = material->GetIonisation()->GetBirksConstant();
0130   G4double destep = aStep->GetTotalEnergyDeposit();
0131   G4double stepl = aStep->GetStepLength();
0132   G4double charge = aStep->GetTrack()->GetDefinition()->GetPDGCharge();
0133   //
0134   G4double response = destep;
0135   if (birk1 * destep * stepl * charge != 0.) {
0136     response = destep / (1. + birk1 * destep / stepl);
0137   }
0138   return response;
0139 }
0140 
0141 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......