Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:24

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 optical/wls/src/WLSEventAction.cc
0028 /// \brief Implementation of the WLSEventAction class
0029 //
0030 //
0031 
0032 #include "WLSEventAction.hh"
0033 
0034 #include "WLSEventActionMessenger.hh"
0035 #include "WLSPhotonDetHit.hh"
0036 #include "WLSRun.hh"
0037 #include "WLSRunAction.hh"
0038 
0039 #include "G4AnalysisManager.hh"
0040 #include "G4Event.hh"
0041 #include "G4EventManager.hh"
0042 #include "G4RunManager.hh"
0043 #include "G4SDManager.hh"
0044 #include "G4TrajectoryContainer.hh"
0045 #include "G4VVisManager.hh"
0046 #include "Randomize.hh"
0047 
0048 // Purpose: Accumulates statistics regarding hits
0049 //          in the PhotonDet detector
0050 
0051 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0052 
0053 WLSEventAction::WLSEventAction()
0054 {
0055   fEventMessenger = new WLSEventActionMessenger(this);
0056 }
0057 
0058 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0059 
0060 WLSEventAction::~WLSEventAction()
0061 {
0062   delete fEventMessenger;
0063 }
0064 
0065 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0066 
0067 void WLSEventAction::BeginOfEventAction(const G4Event*)
0068 {
0069   fNTIR = 0;
0070   fNExiting = 0;
0071   fEscapedEnd = 0;
0072   fEscapedMid = 0;
0073   fBounce = 0;
0074   fWLSBounce = 0;
0075   fClad1Bounce = 0;
0076   fClad2Bounce = 0;
0077   fReflected = 0;
0078   fEscaped = 0;
0079   fMirror = 0;
0080 }
0081 
0082 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0083 
0084 void WLSEventAction::EndOfEventAction(const G4Event* evt)
0085 {
0086   // Get Hits from the detector if any
0087   G4SDManager* SDman = G4SDManager::GetSDMpointer();
0088   G4String colName = "PhotonDetHitCollection";
0089   fMPPCCollID = SDman->GetCollectionID(colName);
0090 
0091   G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
0092   WLSPhotonDetHitsCollection* mppcHC = nullptr;
0093 
0094   // Get the hit collections
0095   if (HCE) {
0096     if (fMPPCCollID >= 0) {
0097       mppcHC = (WLSPhotonDetHitsCollection*)(HCE->GetHC(fMPPCCollID));
0098     }
0099   }
0100 
0101   // Get hit information about photons that reached the detector in this event
0102   G4int n_hit = 0;
0103   if (mppcHC) {
0104     n_hit = mppcHC->entries();
0105   }
0106 
0107   auto analysisManager = G4AnalysisManager::Instance();
0108   analysisManager->FillH1(2, mppcHC->entries());
0109   for (size_t i = 0; i < mppcHC->entries(); ++i) {
0110     auto pdHit = (*mppcHC)[i];
0111     analysisManager->FillH1(0, pdHit->GetEnergy());
0112     analysisManager->FillH1(1, pdHit->GetArrivalTime());
0113   }
0114 
0115   if (fVerboseLevel > 1) {
0116     G4cout << "-------------------------------------" << G4endl
0117            << " In this event, number of:" << G4endl << "  TIR:           " << fNTIR << G4endl
0118            << "  Exiting:       " << fNExiting << G4endl << "  Escaped Mid:   " << fEscapedMid
0119            << G4endl << "  Escaped End:   " << fEscapedEnd << G4endl
0120            << "  Bounced:       " << fBounce << G4endl << "  WLS Bounce:    " << fWLSBounce
0121            << G4endl << "  Clad1 Bounce:  " << fClad1Bounce << G4endl
0122            << "  Clad2 Bounce:  " << fClad2Bounce << G4endl << "  Reflected:     " << fReflected
0123            << G4endl << "  Escaped:       " << fEscaped << G4endl << "  Mirror:        " << fMirror
0124            << G4endl << "  Detector hit:  " << n_hit << G4endl;
0125   }
0126 
0127   auto run = static_cast<WLSRun*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0128 
0129   run->AddTIR(fNTIR);
0130   run->AddExiting(fNExiting);
0131   run->AddEscapedEnd(fEscapedEnd);
0132   run->AddEscapedMid(fEscapedMid);
0133   run->AddBounce(fBounce);
0134   run->AddClad1Bounce(fClad1Bounce);
0135   run->AddClad2Bounce(fClad2Bounce);
0136   run->AddReflected(fReflected);
0137   run->AddEscaped(fEscaped);
0138   run->AddMirror(fMirror);
0139   run->AddDetectorHits(n_hit);
0140 }
0141 
0142 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0143 
0144 G4int WLSEventAction::GetEventNo()
0145 {
0146   return fpEventManager->GetConstCurrentEvent()->GetEventID();
0147 }
0148 
0149 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0150 
0151 void WLSEventAction::SetEventVerbose(G4int level)
0152 {
0153   fVerboseLevel = level;
0154 }