Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-06 07:49:31

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