Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-13 08:26:58

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 //
0027 /// \file SteppingAction.cc
0028 /// \brief Implementation of the SteppingAction class
0029 
0030 #include "SteppingAction.hh"
0031 #include "DetectorConstruction.hh"
0032 
0033 #include "G4Step.hh"
0034 #include "G4Event.hh"
0035 #include "G4RunManager.hh"
0036 #include "G4LogicalVolume.hh"
0037 
0038 #include "G4AnalysisManager.hh"
0039 
0040 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0041 
0042 SteppingAction::SteppingAction()
0043 {}
0044 
0045 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0046 
0047 void SteppingAction::UserSteppingAction(const G4Step* step)
0048 {
0049 
0050     G4String volumeName = step->GetPreStepPoint()->GetTouchableHandle()
0051                             ->GetVolume()->GetName();
0052 
0053     //if a particle enters the detector volume
0054     if (step->GetPreStepPoint()-> GetStepStatus()==G4StepStatus::fGeomBoundary&&
0055         (volumeName=="Crystal"||volumeName=="Detector"))
0056     {
0057 
0058         //coordinates
0059         G4double x0 = step->GetPreStepPoint()->GetPosition().getX()/CLHEP::mm;
0060         G4double y0 = step->GetPreStepPoint()->GetPosition().getY()/CLHEP::mm;
0061 
0062         //angles
0063         G4ThreeVector momentumDirection =
0064             step->GetPreStepPoint()->GetMomentumDirection();
0065         G4double angle_x =
0066             std::atan(momentumDirection.getX()/momentumDirection.getZ());
0067         G4double angle_y =
0068             std::atan(momentumDirection.getY()/momentumDirection.getZ());
0069         if (momentumDirection.getZ() < 0)
0070         {
0071             if (momentumDirection.getX() > 0)
0072             {
0073                 angle_x += CLHEP::pi;
0074             }
0075             else
0076             {
0077                 angle_x -= CLHEP::pi;
0078             }
0079             if (momentumDirection.getY() > 0)
0080             {
0081                 angle_y += CLHEP::pi;
0082             }
0083             else
0084             {
0085                 angle_y -= CLHEP::pi;
0086             }
0087         }
0088 
0089         //kinetic energy
0090         G4double ekin = step->GetPreStepPoint()->GetKineticEnergy()/CLHEP::MeV;
0091 
0092         //particle name, ID and parentID
0093         G4String particleName =
0094             step->GetTrack()->GetDefinition()->GetParticleName();
0095         G4int particleID = step->GetTrack()->GetTrackID();
0096         G4int parentID = step->GetTrack()->GetParentID();
0097 
0098         //event ID
0099         G4int eventID =
0100             G4RunManager::GetRunManager()->GetCurrentEvent()->GetEventID();
0101 
0102         //ntuple index
0103         G4int iTuple = 0;
0104         if(volumeName=="Crystal")
0105         {
0106             iTuple = 0;
0107         }
0108         else if(volumeName=="Detector")
0109         {
0110             if(particleName=="gamma")
0111             {
0112                iTuple = 2;
0113             }
0114             else
0115             {
0116                iTuple = 1;
0117             }
0118         }
0119 
0120         //saving result to root
0121         G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0122         analysisManager->FillNtupleIColumn(iTuple,0,eventID);
0123         analysisManager->FillNtupleSColumn(iTuple,1,volumeName);
0124         analysisManager->FillNtupleDColumn(iTuple,2,x0);
0125         analysisManager->FillNtupleDColumn(iTuple,3,y0);
0126         analysisManager->FillNtupleDColumn(iTuple,4,angle_x);
0127         analysisManager->FillNtupleDColumn(iTuple,5,angle_y);
0128         analysisManager->FillNtupleDColumn(iTuple,6,ekin);
0129         analysisManager->FillNtupleSColumn(iTuple,7,particleName);
0130         analysisManager->FillNtupleIColumn(iTuple,8,particleID);
0131         analysisManager->FillNtupleIColumn(iTuple,9,parentID);
0132         analysisManager->AddNtupleRow(iTuple);
0133     }
0134 }
0135 
0136 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0137 
0138 //}