Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21:11

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 #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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0048 
0049 EventAction::~EventAction()
0050 {
0051   ;
0052 }
0053 
0054 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0055 
0056 void EventAction::BeginOfEventAction(const G4Event*)
0057 {
0058   ;
0059 }
0060 
0061 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....