Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-16 08:29:32

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 SAXSEventAction.cc
0027 /// \brief Implementation of the SAXSEventAction class
0028 
0029 #ifdef G4MULTITHREADED
0030 #  include "G4MTRunManager.hh"
0031 #else
0032 #  include "G4RunManager.hh"
0033 #endif
0034 
0035 #include "SAXSEventAction.hh"
0036 #include "SAXSSensitiveDetectorHit.hh"
0037 
0038 #include "G4AnalysisManager.hh"
0039 #include "G4Event.hh"
0040 #include "G4EventManager.hh"
0041 #include "G4HCofThisEvent.hh"
0042 #include "G4SDManager.hh"
0043 #include "G4SystemOfUnits.hh"
0044 #include "G4Trajectory.hh"
0045 #include "G4TrajectoryContainer.hh"
0046 #include "G4UImanager.hh"
0047 #include "G4VHitsCollection.hh"
0048 #include "G4VVisManager.hh"
0049 #include "G4ios.hh"
0050 
0051 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0052 
0053 SAXSEventAction::SAXSEventAction()
0054   : G4UserEventAction(),
0055     fSensitiveDetector_ID(-1),
0056     fVerboseLevel(0),
0057     fNRi(0),
0058     fNCi(0),
0059     fNDi(0),
0060     fEventWeight(0.)
0061 {}
0062 
0063 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0064 
0065 SAXSEventAction::~SAXSEventAction() {}
0066 
0067 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0068 
0069 void SAXSEventAction::BeginOfEventAction(const G4Event*)
0070 {
0071   fNRi = 0;
0072   fNCi = 0;
0073   fNDi = 0;
0074   fEventWeight = 1.;
0075 }
0076 
0077 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0078 
0079 void SAXSEventAction::EndOfEventAction(const G4Event* aEvent)
0080 {
0081   // instantiating The Sensitive Detector Manager
0082   G4SDManager* SDman = G4SDManager::GetSDMpointer();
0083 
0084   // Hit Detection System
0085   if (fSensitiveDetector_ID == -1) {
0086     G4String SensitiveDetectorName;
0087     if (SDman->FindSensitiveDetector(SensitiveDetectorName = "det", 0)) {
0088       fSensitiveDetector_ID = SDman->GetCollectionID(SensitiveDetectorName = "det/collection");
0089     }
0090   }
0091 
0092   SensitiveDetectorHitsCollection* fSensitiveDetectorHC = 0;
0093   G4HCofThisEvent* HCE = aEvent->GetHCofThisEvent();
0094 
0095   if (HCE) {
0096     if (fSensitiveDetector_ID != -1) {
0097       G4VHitsCollection* aHC = HCE->GetHC(fSensitiveDetector_ID);
0098       fSensitiveDetectorHC = (SensitiveDetectorHitsCollection*)(aHC);
0099     }
0100   }
0101 
0102   // instantiating The Analysis Manager
0103   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0104 
0105   // get the Event Number
0106   G4int eventNumber = G4RunManager::GetRunManager()->GetCurrentEvent()->GetEventID();
0107 
0108   // filling the SD scoring ntuple
0109   if (fSensitiveDetectorHC) {
0110     size_t vNumberOfHit = fSensitiveDetectorHC->entries();
0111     for (size_t i = 0; i < vNumberOfHit; i++) {
0112       SAXSSensitiveDetectorHit* aHit = (*fSensitiveDetectorHC)[i];
0113       analysisManager->FillNtupleDColumn(0, 0, aHit->GetEnergy() / CLHEP::keV);
0114       analysisManager->FillNtupleDColumn(0, 1, aHit->GetPos().x() / CLHEP::mm);
0115       analysisManager->FillNtupleDColumn(0, 2, aHit->GetPos().y() / CLHEP::mm);
0116       analysisManager->FillNtupleDColumn(0, 3, aHit->GetPos().z() / CLHEP::mm);
0117       analysisManager->FillNtupleDColumn(0, 4, aHit->GetMom().x());
0118       analysisManager->FillNtupleDColumn(0, 5, aHit->GetMom().y());
0119       analysisManager->FillNtupleDColumn(0, 6, aHit->GetMom().z());
0120       analysisManager->FillNtupleDColumn(0, 7, aHit->GetTime() / CLHEP::ns);
0121       analysisManager->FillNtupleIColumn(0, 8, aHit->GetType());
0122       analysisManager->FillNtupleIColumn(0, 9, aHit->GetTrackID());
0123       analysisManager->FillNtupleIColumn(0, 10, fNRi);
0124       analysisManager->FillNtupleIColumn(0, 11, fNCi);
0125       analysisManager->FillNtupleIColumn(0, 12, fNDi);
0126       analysisManager->FillNtupleIColumn(0, 13, eventNumber);
0127       analysisManager->FillNtupleDColumn(0, 14, aHit->GetWeight());
0128       analysisManager->AddNtupleRow(0);
0129     }
0130   }
0131 }
0132 
0133 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....