Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21: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 /// \file SAXSSteppingAction.cc
0027 /// \brief Definition of the SAXSSteppingAction class
0028 //
0029 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0030 
0031 #ifdef G4MULTITHREADED
0032 #  include "G4MTRunManager.hh"
0033 #else
0034 #  include "G4RunManager.hh"
0035 #endif
0036 
0037 #include "SAXSDetectorConstruction.hh"
0038 #include "SAXSEventAction.hh"
0039 #include "SAXSSteppingAction.hh"
0040 
0041 #include "G4AnalysisManager.hh"
0042 #include "G4Event.hh"
0043 #include "G4EventManager.hh"
0044 #include "G4HCofThisEvent.hh"
0045 #include "G4OpticalPhoton.hh"
0046 #include "G4SDManager.hh"
0047 #include "G4Step.hh"
0048 #include "G4SystemOfUnits.hh"
0049 #include "G4Track.hh"
0050 #include "G4Trajectory.hh"
0051 #include "G4TrajectoryContainer.hh"
0052 #include "G4UImanager.hh"
0053 #include "G4VHitsCollection.hh"
0054 #include "G4VVisManager.hh"
0055 #include "G4ios.hh"
0056 
0057 #include <cmath>
0058 
0059 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0060 
0061 SAXSSteppingAction::SAXSSteppingAction(SAXSEventAction* eventAction)
0062   : G4UserSteppingAction(), fEventAction(eventAction), fPhantom(0), fEventNumber(-1), fNSe(0)
0063 {}
0064 
0065 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0066 
0067 SAXSSteppingAction::~SAXSSteppingAction() {}
0068 
0069 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0070 
0071 void SAXSSteppingAction::UserSteppingAction(const G4Step* step)
0072 {
0073   // DetectorConstruction instance
0074   const SAXSDetectorConstruction* detectorConstruction =
0075     static_cast<const SAXSDetectorConstruction*>(
0076       G4RunManager::GetRunManager()->GetUserDetectorConstruction());
0077 
0078   // get Phantom volume
0079   fPhantom = detectorConstruction->GetPhantom();
0080 
0081   // get pre and post step points
0082   G4StepPoint* preStepPoint = step->GetPreStepPoint();
0083   G4StepPoint* postStepPoint = step->GetPostStepPoint();
0084 
0085   // get the volume of the current step
0086   G4LogicalVolume* volume = preStepPoint->GetTouchableHandle()->GetVolume()->GetLogicalVolume();
0087 
0088   // get track and particle name
0089   G4Track* track = step->GetTrack();
0090   G4int ID = track->GetTrackID();
0091   G4String partName = track->GetDefinition()->GetParticleName();
0092 
0093   // update the primary particle (event) weight
0094   G4double PrimaryWeight = 1.;
0095   if (partName == "gamma" && ID == 1) {
0096     PrimaryWeight = track->GetWeight();
0097     fEventAction->UpdateEventWeight(PrimaryWeight);
0098   }
0099 
0100   // if the particle is not a primary photon stepping in the phantom, exit!
0101   if (volume != fPhantom || partName != "gamma" || ID != 1) return;
0102 
0103   // if it is a new event, reset variable values to 0
0104   G4int eventNumber = G4RunManager::GetRunManager()->GetCurrentEvent()->GetEventID();
0105   if (eventNumber != fEventNumber) {
0106     fEventNumber = eventNumber;
0107     fNSe = 0;
0108   }
0109 
0110   // identify the process that occurred
0111   G4String Process;
0112   if (postStepPoint->GetProcessDefinedStep() != NULL) {
0113     Process = postStepPoint->GetProcessDefinedStep()->GetProcessName();
0114   }
0115   else {
0116     Process = "UserLimit";
0117   }
0118   // G4cout << "Process: " << Process << G4endl;
0119   G4int ProcIndex = -1;
0120   if (Process == "Transportation" || Process == "CoupledTransportation" || Process == "UserLimit") {
0121     ProcIndex = 0;
0122   }
0123   if (Process == "Rayl" || Process == "biasWrapper(Rayl)") {
0124     ProcIndex = 1;
0125     fNSe++;
0126     fEventAction->AddNRi();
0127   }
0128   if (Process == "compt" || Process == "biasWrapper(compt)") {
0129     ProcIndex = 2;
0130     fNSe++;
0131     fEventAction->AddNCi();
0132   }
0133   if (Process == "phot" || Process == "biasWrapper(phot)") ProcIndex = 3;
0134   if (Process == "conv" || Process == "biasWrapper(conv)") ProcIndex = 4;
0135   if (Process == "photonNuclear" || Process == "biasWrapper(photonNuclear)") {
0136     ProcIndex = 5;
0137   }
0138   if (Process == "PowderDiffraction" || Process == "biasWrapper(PowderDiffraction)") {
0139     ProcIndex = 6;
0140     fNSe++;
0141     fEventAction->AddNDi();
0142   }
0143   // G4cout << "ProcIndex: " << ProcIndex << G4endl;
0144 
0145   // calculate the scattering angle
0146   G4ThreeVector mom1 = preStepPoint->GetMomentumDirection();
0147   G4ThreeVector mom2 = postStepPoint->GetMomentumDirection();
0148   G4double theta = mom1.angle(mom2);
0149 
0150   // fill the Scattering ntuple
0151   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0152   if (theta > 1e-6) {  // record only if the angle is not 0
0153     analysisManager->FillNtupleIColumn(1, 0, ProcIndex);
0154     analysisManager->FillNtupleDColumn(1, 1, preStepPoint->GetKineticEnergy() / CLHEP::keV);
0155     analysisManager->FillNtupleDColumn(1, 2, theta / CLHEP::deg);
0156     analysisManager->FillNtupleDColumn(1, 3, track->GetWeight());
0157     analysisManager->AddNtupleRow(1);
0158   }
0159 }
0160 
0161 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......