Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-23 08:27:26

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 // CaTS (Calorimetry and Tracking Simulation)
0027 //
0028 // Authors: Hans Wenzel and Soon Yung Jun
0029 //          (Fermi National Accelerator Laboratory)
0030 //
0031 // History: October 18th, 2021 : first implementation
0032 // ********************************************************************
0033 //
0034 /// \file EventAction.cc
0035 /// \brief Implementation of the CaTS::EventAction class
0036 
0037 // Geant4 headers
0038 #include "G4Event.hh"
0039 #include "G4Types.hh"
0040 #include "G4SDManager.hh"
0041 
0042 // project headers:
0043 #include "EventAction.hh"
0044 #include "ConfigurationManager.hh"
0045 #include "PhotonSD.hh"
0046 #include "PhotonHit.hh"
0047 
0048 #ifdef WITH_ROOT
0049 #include "RootIO.hh"
0050 #endif
0051 
0052 #ifdef WITH_G4OPTICKS
0053 #include "OpticksFlags.hh"
0054 #include "G4Opticks.hh"
0055 #include "G4OpticksHit.hh"
0056 #include <string>
0057 #endif
0058 
0059 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0060 void EventAction::EndOfEventAction(const G4Event* event)
0061 {
0062   G4bool verbose = ConfigurationManager::getInstance()->isEnable_verbose();
0063   if (verbose)
0064   {
0065     G4cout << "EventAction::EndOfEventAction Event:   " << event->GetEventID()
0066            << G4endl;
0067   }
0068 #ifdef WITH_G4OPTICKS
0069   if (ConfigurationManager::getInstance()->isEnable_opticks())
0070   {
0071     G4Opticks* g4ok = G4Opticks::Get();
0072     g4ok->propagateOpticalPhotons(event->GetEventID());
0073     unsigned num_hits = g4ok->getNumHit();
0074     G4cout << "EndOfEventAction: num_hits: " << num_hits << G4endl;
0075     if (num_hits > 0)
0076     {
0077       G4HCtable* hctable = G4SDManager::GetSDMpointer()->GetHCtable();
0078       for (G4int i = 0; i < hctable->entries(); ++i)
0079       {
0080         G4String sdn = hctable->GetSDname(i);
0081         std::size_t found = sdn.find("PhotonDetector");
0082         if (found != std::string::npos)
0083     {
0084           PhotonSD* aSD =
0085             (PhotonSD*) G4SDManager::GetSDMpointer()->FindSensitiveDetector(sdn);
0086           aSD->AddOpticksHits();
0087         }
0088       }
0089     }
0090     if (verbose)
0091     {
0092       G4cout << "**************************************************" << G4endl;
0093       G4cout << " EndOfEventAction: numphotons:   " << g4ok->getNumPhotons()
0094              << " Gensteps: " << g4ok->getNumGensteps()
0095              << "  Maxgensteps:  " << g4ok->getMaxGensteps() << G4endl;
0096       G4cout << " EndOfEventAction: num_hits: " << g4ok->getNumHit() << G4endl;
0097       G4cout << g4ok->dbgdesc() << G4endl;
0098     }
0099     g4ok->reset();
0100     if (verbose)
0101     {
0102       G4cout << "========================== After reset: " << G4endl;
0103       G4cout << " EndOfEventAction: numphotons:   " << g4ok->getNumPhotons()
0104              << " Gensteps: " << g4ok->getNumGensteps()
0105              << "  Maxgensteps:  " << g4ok->getMaxGensteps() << G4endl;
0106       G4cout << "EndOfEventAction: num_hits: " << g4ok->getNumHit() << G4endl;
0107       G4cout << g4ok->dbgdesc() << G4endl;
0108       G4cout << "**************************************************" << G4endl;
0109     }
0110   } // end isEnable_opticks
0111 #endif  // end WITH_G4OPTICKS
0112 
0113 #ifdef WITH_ROOT
0114   // Now we deal with the Geant4 Hit collections.
0115   if (ConfigurationManager::getInstance()->isWriteHits())
0116   {
0117     RootIO::GetInstance()->Write(event);
0118   }
0119 #endif
0120 }