File indexing completed on 2025-02-23 09:21:11
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 #include "EventAction.hh"
0028
0029 #include "SensitiveDetectorHit.hh"
0030
0031 #include "G4AnalysisManager.hh"
0032 #include "G4Event.hh"
0033 #include "G4EventManager.hh"
0034 #include "G4HCofThisEvent.hh"
0035 #include "G4RunManager.hh"
0036 #include "G4SDManager.hh"
0037 #include "G4SystemOfUnits.hh"
0038 #include "G4Trajectory.hh"
0039 #include "G4TrajectoryContainer.hh"
0040 #include "G4UImanager.hh"
0041 #include "G4VHitsCollection.hh"
0042 #include "G4VVisManager.hh"
0043 #include "G4ios.hh"
0044
0045 EventAction::EventAction() : fSDHT_ID(-1) {}
0046
0047
0048
0049 EventAction::~EventAction()
0050 {
0051 ;
0052 }
0053
0054
0055
0056 void EventAction::BeginOfEventAction(const G4Event*)
0057 {
0058 ;
0059 }
0060
0061
0062
0063 void EventAction::EndOfEventAction(const G4Event* evt)
0064 {
0065 G4SDManager* SDman = G4SDManager::GetSDMpointer();
0066
0067 G4ThreeVector ssd[3];
0068 ssd[0] = G4ThreeVector(0., 0., 0.);
0069 ssd[1] = G4ThreeVector(0., 0., 0.);
0070 ssd[2] = G4ThreeVector(0., 0., 0.);
0071
0072 if (fSDHT_ID == -1) {
0073 G4String sdName;
0074 if (SDman->FindSensitiveDetector(sdName = "telescope", 0)) {
0075 fSDHT_ID = SDman->GetCollectionID(sdName = "telescope/collection");
0076 }
0077 }
0078
0079 SensitiveDetectorHitsCollection* sdht = 0;
0080 G4HCofThisEvent* hce = evt->GetHCofThisEvent();
0081
0082 if (hce) {
0083 if (fSDHT_ID != -1) {
0084 G4VHitsCollection* aHCSD = hce->GetHC(fSDHT_ID);
0085 sdht = (SensitiveDetectorHitsCollection*)(aHCSD);
0086 }
0087 }
0088
0089 int bTotalHits = 0;
0090 if (sdht) {
0091 int n_hit_sd = sdht->entries();
0092 for (int i2 = 0; i2 < 3; i2++) {
0093 for (int i1 = 0; i1 < n_hit_sd; i1++) {
0094 SensitiveDetectorHit* aHit = (*sdht)[i1];
0095 if (aHit->GetLayerID() == i2) {
0096 ssd[i2] = aHit->GetWorldPos();
0097 bTotalHits++;
0098 }
0099 }
0100 }
0101 }
0102
0103 if (bTotalHits > 2) {
0104 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0105 G4double angXin = (ssd[1].x() - ssd[0].x()) / (ssd[1].z() - ssd[0].z());
0106 G4double angYin = (ssd[1].y() - ssd[0].y()) / (ssd[1].z() - ssd[0].z());
0107
0108 analysisManager->FillNtupleDColumn(0, angXin * 1.E6 * CLHEP::rad);
0109 analysisManager->FillNtupleDColumn(1, angYin * 1.E6 * CLHEP::rad);
0110
0111 double posXin = ssd[1].x() - angXin * ssd[1].z();
0112 double posYin = ssd[1].y() - angYin * ssd[1].z();
0113
0114 analysisManager->FillNtupleDColumn(2, posXin / CLHEP::mm);
0115 analysisManager->FillNtupleDColumn(3, posYin / CLHEP::mm);
0116
0117 G4double angXout = (ssd[2].x() - posXin) / (ssd[2].z());
0118 G4double angYout = (ssd[2].y() - posYin) / (ssd[2].z());
0119 analysisManager->FillNtupleDColumn(4, angXout * 1.E6 * CLHEP::rad);
0120 analysisManager->FillNtupleDColumn(5, angYout * 1.E6 * CLHEP::rad);
0121
0122 analysisManager->AddNtupleRow();
0123 }
0124 }
0125
0126