Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-17 07:52:14

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 // gpaterno, October 2025
0027 //
0028 /// \file SteppingAction.cc
0029 /// \brief Implementation of the SteppingAction class
0030 //
0031 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0032 
0033 #include "SteppingAction.hh"
0034 #include "EventAction.hh"
0035 #include "DetectorConstruction.hh"
0036 
0037 #include "G4AnalysisManager.hh"
0038 #include "G4Step.hh"
0039 #include "G4Event.hh"
0040 #include "G4RunManager.hh"
0041 #include "G4LogicalVolume.hh"
0042 #include "G4SystemOfUnits.hh"
0043 
0044 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0045 
0046 SteppingAction::SteppingAction(EventAction* eventAction): 
0047 fEventAction(eventAction)
0048 {}
0049 
0050 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0051 
0052 void SteppingAction::UserSteppingAction(const G4Step* step)
0053 {
0054     //get an instance of the DetectorConstruction and retrieve some settings 
0055     const DetectorConstruction* detectorConstruction
0056         = static_cast<const DetectorConstruction*>
0057             (G4RunManager::GetRunManager()->GetUserDetectorConstruction());
0058     
0059     //get the Sensitive Volumes
0060     fCrystalVolume = detectorConstruction->GetCrystalVolume(); //Radiator
0061     fConverterVolume = detectorConstruction->GetConverterVolume(); //Converter/Target
0062     if (fScoringVolume.size() == 0)
0063         fScoringVolume = detectorConstruction->GetScoringVolume(); //Spheres of Converter
0064     G4int NScoringVolumes = fScoringVolume.size();
0065           
0066     //get if I want to score the features of particles
0067     //exiting the radiator and /or the target (27/09/2024)
0068     G4bool scoreCrystalExit = detectorConstruction->GetScoringCrystalExit();
0069   
0070   
0071     //get pre and post step points
0072     G4StepPoint* preStepPoint = step->GetPreStepPoint();
0073     G4StepPoint* postStepPoint = step->GetPostStepPoint();
0074         
0075     //get the current and next particle postion
0076     G4ThreeVector preStepPos = preStepPoint->GetPosition();
0077     G4ThreeVector postStepPos = postStepPoint->GetPosition();
0078     G4ThreeVector pos = preStepPos + G4UniformRand()*(postStepPos - preStepPos);
0079           
0080     //get the volume of the current step
0081     G4LogicalVolume* volume = 
0082         preStepPoint->GetTouchableHandle()->GetVolume()->GetLogicalVolume();
0083     G4String volumeName = volume->GetName();
0084       
0085     //get track and particle name
0086     G4Track* track = step->GetTrack();
0087     G4String partName = track->GetDefinition()->GetParticleName();
0088     G4int trackID = track->GetTrackID();
0089 
0090     //get the energy deposited during in this step
0091     G4double edep = step->GetTotalEnergyDeposit();
0092     
0093     //get eventID
0094     G4int eventID = 
0095         G4RunManager::GetRunManager()->GetCurrentEvent()->GetEventID();
0096                
0097     
0098     //instantiating The Analysis Manager
0099     G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0100        
0101     
0102     //declaration of variables useful for the scoring 
0103     //of the features of the particles exiting the crystals
0104     //G4ThreeVector postStepPos;
0105     G4ThreeVector postStepMom;
0106     G4double postStepTime;
0107     G4LogicalVolume* volumeNext;
0108     
0109     
0110     //score the Edep in the Crystal (the Radiator)
0111     if (volume == fCrystalVolume) {     
0112         fEventAction->AddEdepRad(edep);
0113         
0114         //score the features of the particle exiting the volume
0115         postStepMom = postStepPoint->GetMomentum(); 
0116         postStepTime = postStepPoint->GetGlobalTime();
0117         volumeNext = 
0118             postStepPoint->GetTouchableHandle()->GetVolume()->GetLogicalVolume();
0119         //G4cout << "volume: " << volumeName << ", next volume: " << volumeNextName << G4endl;
0120         if (scoreCrystalExit && volumeNext && volume != volumeNext) {
0121             analysisManager->FillNtupleSColumn(4,0,partName);
0122             analysisManager->FillNtupleDColumn(4,1,postStepPos.x()/CLHEP::mm);
0123             analysisManager->FillNtupleDColumn(4,2,postStepPos.y()/CLHEP::mm);
0124             analysisManager->FillNtupleDColumn(4,3,postStepPos.z()/CLHEP::mm);
0125             analysisManager->FillNtupleDColumn(4,4,postStepMom.x()/CLHEP::MeV);
0126             analysisManager->FillNtupleDColumn(4,5,postStepMom.y()/CLHEP::MeV);
0127             analysisManager->FillNtupleDColumn(4,6,postStepMom.z()/CLHEP::MeV);
0128             analysisManager->FillNtupleDColumn(4,7,postStepTime/CLHEP::ns);
0129             analysisManager->FillNtupleIColumn(4,8,eventID);
0130             analysisManager->FillNtupleIColumn(4,9,trackID);
0131             analysisManager->AddNtupleRow(4);          
0132         }
0133         
0134     }
0135     
0136     
0137     //score the Edep in the Converter (the Target)
0138     if (volume == fConverterVolume) {     
0139         fEventAction->AddEdepConv(edep);
0140         
0141         //score the features of the particle exiting the volume
0142         //postStepPos = postStepPoint->GetPosition();
0143         postStepMom = postStepPoint->GetMomentum(); 
0144         postStepTime = postStepPoint->GetGlobalTime();
0145         volumeNext = 
0146             postStepPoint->GetTouchableHandle()->GetVolume()->GetLogicalVolume();
0147         if (scoreCrystalExit && volumeNext && volume != volumeNext) {
0148             analysisManager->FillNtupleSColumn(4,0,partName);
0149             analysisManager->FillNtupleDColumn(4,1,postStepPos.x()/CLHEP::mm);
0150             analysisManager->FillNtupleDColumn(4,2,postStepPos.y()/CLHEP::mm);
0151             analysisManager->FillNtupleDColumn(4,3,postStepPos.z()/CLHEP::mm);
0152             analysisManager->FillNtupleDColumn(4,4,postStepMom.x()/CLHEP::MeV);
0153             analysisManager->FillNtupleDColumn(4,5,postStepMom.y()/CLHEP::MeV);
0154             analysisManager->FillNtupleDColumn(4,6,postStepMom.z()/CLHEP::MeV);
0155             analysisManager->FillNtupleDColumn(4,7,postStepTime/CLHEP::ns);
0156             analysisManager->FillNtupleIColumn(4,8,eventID);
0157             analysisManager->FillNtupleIColumn(4,9,trackID);
0158             analysisManager->AddNtupleRow(4);          
0159         } 
0160         
0161     }
0162           
0163       
0164     //score the Edep in the spheres of the granular target 
0165     //(NScoringVolumes !=0 only if the target is granular)
0166     for (int i = 0; i < NScoringVolumes; i++) {
0167         if (volume == fScoringVolume[i]) {    
0168             if (edep > 0) {
0169                 fEventAction->AddEdepInSpheres(i, edep);            
0170             }          
0171         }
0172     }
0173     
0174 }
0175 
0176 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0177