Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:50:01

0001 #pragma once
0002 /**
0003 U4SensitiveDetector.h
0004 ======================
0005 
0006 Placeholder SensitiveDetector for standalone running 
0007 
0008 ::
0009 
0010    g4-;g4-cls G4VSensitiveDetector
0011 
0012 **/
0013 
0014 #include <vector>
0015 #include <string>
0016 #include <sstream>
0017 #include <iomanip>
0018 
0019 #include "U4_API_EXPORT.hh"
0020 #include "G4VSensitiveDetector.hh"
0021 
0022 struct U4_API U4SensitiveDetector : public G4VSensitiveDetector
0023 {
0024     static std::vector<U4SensitiveDetector*>* INSTANCES ;  
0025     static U4SensitiveDetector* Get(const char* name); 
0026     static std::string Desc(); 
0027 
0028     U4SensitiveDetector(const char* name); 
0029 
0030     G4bool ProcessHits(G4Step* step, G4TouchableHistory* hist);     
0031 };
0032 
0033 
0034 
0035 inline U4SensitiveDetector* U4SensitiveDetector::Get(const char* name)
0036 {
0037     U4SensitiveDetector* instance = nullptr ; 
0038     int count = 0 ; 
0039     int num_instance = INSTANCES ? INSTANCES->size() : 0 ; 
0040 
0041     for(int i=0 ; i < num_instance ; i++)
0042     {
0043         U4SensitiveDetector* sd = (*INSTANCES)[i]; 
0044         G4String sdn = sd->GetName() ; // CAUTION: RETURNS BY VALUE 
0045         if( strcmp(sdn.c_str(), name) == 0 ) 
0046         {
0047             instance = sd ;   
0048             count += 1 ; 
0049         } 
0050     }
0051     if( count > 1 ) std::cerr 
0052         << "U4SensitiveDetector::Get"
0053         << " counted more than one " << count 
0054         << " with name " << ( name ? name : "-" )
0055         << std::endl 
0056         ;
0057 
0058     return instance ; 
0059 }
0060 inline std::string U4SensitiveDetector::Desc()
0061 {
0062     int num_instance = INSTANCES ? INSTANCES->size() : 0 ; 
0063     std::stringstream ss ; 
0064     ss << "U4SensitiveDetector::Desc"
0065        << " INSTANCES " << ( INSTANCES ? "YES" : "NO " )
0066        << " num_instance " << num_instance
0067        << std::endl 
0068        ;
0069 
0070     for(int i=0 ; i < num_instance ; i++)
0071     {
0072         U4SensitiveDetector* sd = (*INSTANCES)[i]; 
0073         G4String sdn = sd->GetName() ; // CAUTION: RETURNS BY VALUE 
0074         ss << std::setw(3) << i << " : " << sdn << std::endl ;   
0075     }
0076     std::string str = ss.str() ; 
0077     return str ; 
0078 }
0079 
0080 
0081 inline U4SensitiveDetector::U4SensitiveDetector(const char* name)
0082     :
0083     G4VSensitiveDetector(name)
0084 {
0085     if(INSTANCES == nullptr) INSTANCES = new std::vector<U4SensitiveDetector*>() ; 
0086     INSTANCES->push_back(this) ; 
0087 }
0088 
0089 inline G4bool U4SensitiveDetector::ProcessHits(G4Step* , G4TouchableHistory* )
0090 {
0091     //std::cout << "U4SensitiveDetector::ProcessHits" << std::endl ; 
0092     return true ; 
0093 }
0094