Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:20:59

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