diff --git a/dd4hepplugins/OpticsSteppingAction.cc b/dd4hepplugins/OpticsSteppingAction.cc index 5b0dec5b7..cac0f6c9e 100644 --- a/dd4hepplugins/OpticsSteppingAction.cc +++ b/dd4hepplugins/OpticsSteppingAction.cc @@ -128,8 +128,7 @@ void OpticsSteppingAction::operator()(const G4Step *step, G4SteppingManager *mgr { G4AutoLock lock(&genstep_mutex); - U4::CollectGenstep_DsG4Scintillation_r4695(track, step, numPhotons, - /*scnt=*/1, scintTime); + U4::CollectGenstep_Scintillation(track, step, numPhotons, /*scnt=*/1, scintTime); } if (verbose_ > 0) diff --git a/examples/MC_Truth/GPUMCTruth.h b/examples/MC_Truth/GPUMCTruth.h index ea50c6631..bb1ea4ea0 100644 --- a/examples/MC_Truth/GPUMCTruth.h +++ b/examples/MC_Truth/GPUMCTruth.h @@ -605,8 +605,7 @@ struct SteppingAction : G4UserSteppingAction G4double SCINTILLATIONTIMECONSTANT1 = MPT->GetConstProperty(kSCINTILLATIONTIMECONSTANT1); G4AutoLock lock(&genstep_mutex); - U4::CollectGenstep_DsG4Scintillation_r4695(aTrack, aStep, fNumPhotons, 1, - SCINTILLATIONTIMECONSTANT1); + U4::CollectGenstep_Scintillation(aTrack, aStep, fNumPhotons, 1, SCINTILLATIONTIMECONSTANT1); } } } diff --git a/examples/async_gpu_launch/async_gpu_launch.h b/examples/async_gpu_launch/async_gpu_launch.h index 13ec06b14..ad6126fd8 100644 --- a/examples/async_gpu_launch/async_gpu_launch.h +++ b/examples/async_gpu_launch/async_gpu_launch.h @@ -449,7 +449,7 @@ static quad6 MakeGenstep_Scintillation(const G4Track* aTrack, const G4Step* aSte gs.zero(); sscint* sc = (sscint*)(&gs); - sc->gentype = OpticksGenstep_DsG4Scintillation_r4695; + sc->gentype = OpticksGenstep_SCINTILLATION; sc->trackid = aTrack->GetTrackID(); sc->matline = aMaterial->GetIndex() + SEvt::G4_INDEX_OFFSET; sc->numphoton = numPhotons; @@ -953,7 +953,7 @@ struct SteppingAction : G4UserSteppingAction nRemaining -= nPhotComp; if (nPhotComp > 0) - U4::CollectGenstep_DsG4Scintillation_r4695(aTrack, aStep, nPhotComp, c + 1, tc[c]); + U4::CollectGenstep_Scintillation(aTrack, aStep, nPhotComp, c + 1, tc[c]); } } } diff --git a/examples/async_gpu_std/async_gpu_std.h b/examples/async_gpu_std/async_gpu_std.h index f67f6a45f..c2d74260a 100644 --- a/examples/async_gpu_std/async_gpu_std.h +++ b/examples/async_gpu_std/async_gpu_std.h @@ -522,7 +522,7 @@ static quad6 MakeGenstep_Scintillation(const G4Track* aTrack, gs.zero(); sscint* sc = (sscint*)(&gs); - sc->gentype = OpticksGenstep_DsG4Scintillation_r4695; + sc->gentype = OpticksGenstep_SCINTILLATION; sc->trackid = aTrack->GetTrackID(); sc->matline = mat->GetIndex() + SEvt::G4_INDEX_OFFSET; sc->numphoton = numPhotons; @@ -1006,8 +1006,7 @@ struct SteppingAction : G4UserSteppingAction : static_cast(numPhotons * yield[c] / yieldSum); remaining -= n; if (n > 0) - U4::CollectGenstep_DsG4Scintillation_r4695(track, aStep, n, c + 1, - tc[c]); + U4::CollectGenstep_Scintillation(track, aStep, n, c + 1, tc[c]); } } } diff --git a/qudarap/qsim.h b/qudarap/qsim.h index a52c8c606..1e110505b 100644 --- a/qudarap/qsim.h +++ b/qudarap/qsim.h @@ -2424,7 +2424,6 @@ inline QSIM_METHOD void qsim::generate_photon(sphoton& p, RNG& rng, const quad6& case OpticksGenstep_CERENKOV: cerenkov->generate( p, rng, gs, photon_id, genstep_id ) ; break ; - case OpticksGenstep_DsG4Scintillation_r4695: case OpticksGenstep_SCINTILLATION: if (scint != nullptr) scint->generate(p, rng, gs, photon_id, genstep_id); diff --git a/src/GPUCerenkov.h b/src/GPUCerenkov.h index 40c417939..bf492d962 100644 --- a/src/GPUCerenkov.h +++ b/src/GPUCerenkov.h @@ -501,8 +501,7 @@ struct SteppingAction : G4UserSteppingAction G4double SCINTILLATIONTIMECONSTANT1 = MPT->GetConstProperty(kSCINTILLATIONTIMECONSTANT1); G4AutoLock lock(&genstep_mutex); - U4::CollectGenstep_DsG4Scintillation_r4695(aTrack, aStep, fNumPhotons, 1, - SCINTILLATIONTIMECONSTANT1); + U4::CollectGenstep_Scintillation(aTrack, aStep, fNumPhotons, 1, SCINTILLATIONTIMECONSTANT1); } } } diff --git a/src/GPURaytrace.h b/src/GPURaytrace.h index 14606bfe3..e0c950028 100644 --- a/src/GPURaytrace.h +++ b/src/GPURaytrace.h @@ -601,7 +601,7 @@ struct SteppingAction : G4UserSteppingAction nRemaining -= nPhotComp; if (nPhotComp > 0) - U4::CollectGenstep_DsG4Scintillation_r4695(aTrack, aStep, nPhotComp, c + 1, tc[c]); + U4::CollectGenstep_Scintillation(aTrack, aStep, nPhotComp, c + 1, tc[c]); } } } diff --git a/sysrap/OpticksGenstep.h b/sysrap/OpticksGenstep.h index 4c299de53..9f61e8b4b 100644 --- a/sysrap/OpticksGenstep.h +++ b/sysrap/OpticksGenstep.h @@ -19,11 +19,7 @@ See also: npy/G4StepNPY.cpp (TODO: consolidate these?) enum { OpticksGenstep_INVALID = 0, - OpticksGenstep_G4Cerenkov_1042 = 1, - OpticksGenstep_G4Scintillation_1042 = 2, - OpticksGenstep_DsG4Cerenkov_r3971 = 3, - OpticksGenstep_DsG4Scintillation_r3971 = 4, - OpticksGenstep_DsG4Scintillation_r4695 = 5, + // Values 1-5 are intentionally unused after retiring their legacy encodings. OpticksGenstep_TORCH = 6, OpticksGenstep_FABRICATED = 7, OpticksGenstep_EMITSOURCE = 8, @@ -52,11 +48,6 @@ enum struct OpticksGenstep_ { static constexpr const char* INVALID_ = "INVALID" ; - static constexpr const char* G4Cerenkov_1042_ = "G4Cerenkov_1042" ; - static constexpr const char* G4Scintillation_1042_ = "G4Scintillation_1042" ; - static constexpr const char* DsG4Cerenkov_r3971_ = "DsG4Cerenkov_r3971" ; - static constexpr const char* DsG4Scintillation_r3971_ = "DsG4Scintillation_r3971" ; - static constexpr const char* DsG4Scintillation_r4695_ = "DsG4Scintillation_r4695" ; static constexpr const char* TORCH_ = "TORCH" ; static constexpr const char* FABRICATED_ = "FABRICATED" ; static constexpr const char* EMITSOURCE_ = "EMITSOURCE" ; @@ -97,12 +88,7 @@ struct OpticksGenstep_ inline unsigned OpticksGenstep_::Type(const char* name) { unsigned type = OpticksGenstep_INVALID ; - if(strcmp(name,G4Cerenkov_1042_ )==0) type = OpticksGenstep_G4Cerenkov_1042 ; - if(strcmp(name,G4Scintillation_1042_ )==0) type = OpticksGenstep_G4Scintillation_1042 ; - if(strcmp(name,DsG4Cerenkov_r3971_ )==0) type = OpticksGenstep_DsG4Cerenkov_r3971 ; if(strcmp(name,G4Cerenkov_modified_ )==0) type = OpticksGenstep_G4Cerenkov_modified ; - if(strcmp(name,DsG4Scintillation_r3971_ )==0) type = OpticksGenstep_DsG4Scintillation_r3971 ; - if(strcmp(name,DsG4Scintillation_r4695_ )==0) type = OpticksGenstep_DsG4Scintillation_r4695 ; if(strcmp(name,TORCH_)==0) type = OpticksGenstep_TORCH ; if(strcmp(name,FABRICATED_)==0) type = OpticksGenstep_FABRICATED ; if(strcmp(name,EMITSOURCE_)==0) type = OpticksGenstep_EMITSOURCE ; @@ -131,12 +117,7 @@ inline const char* OpticksGenstep_::Name(unsigned type) switch(type) { case OpticksGenstep_INVALID: n = INVALID_ ; break ; - case OpticksGenstep_G4Cerenkov_1042: n = G4Cerenkov_1042_ ; break ; - case OpticksGenstep_G4Scintillation_1042: n = G4Scintillation_1042_ ; break ; - case OpticksGenstep_DsG4Cerenkov_r3971: n = DsG4Cerenkov_r3971_ ; break ; case OpticksGenstep_G4Cerenkov_modified: n = G4Cerenkov_modified_ ; break ; - case OpticksGenstep_DsG4Scintillation_r3971: n = DsG4Scintillation_r3971_ ; break ; - case OpticksGenstep_DsG4Scintillation_r4695: n = DsG4Scintillation_r4695_ ; break ; case OpticksGenstep_TORCH: n = TORCH_ ; break ; case OpticksGenstep_FABRICATED: n = FABRICATED_ ; break ; case OpticksGenstep_EMITSOURCE: n = EMITSOURCE_ ; break ; @@ -167,19 +148,11 @@ inline bool OpticksGenstep_::IsValid(int gentype) // static inline bool OpticksGenstep_::IsCerenkov(int gentype) // static { - return gentype == OpticksGenstep_G4Cerenkov_1042 || - gentype == OpticksGenstep_DsG4Cerenkov_r3971 || - gentype == OpticksGenstep_CERENKOV || - gentype == OpticksGenstep_G4Cerenkov_modified - ; + return gentype == OpticksGenstep_CERENKOV || gentype == OpticksGenstep_G4Cerenkov_modified; } inline bool OpticksGenstep_::IsScintillation(int gentype) // static { - return gentype == OpticksGenstep_G4Scintillation_1042 || - gentype == OpticksGenstep_DsG4Scintillation_r3971 || - gentype == OpticksGenstep_DsG4Scintillation_r4695 || - gentype == OpticksGenstep_SCINTILLATION - ; + return gentype == OpticksGenstep_SCINTILLATION; } inline bool OpticksGenstep_::IsTorchLike(int gentype) // static { @@ -263,5 +236,3 @@ inline unsigned OpticksGenstep_::GentypeToPhotonFlag(char gentype) // static #endif - - diff --git a/sysrap/sscint.h b/sysrap/sscint.h index f8a837531..44978c8c1 100644 --- a/sysrap/sscint.h +++ b/sysrap/sscint.h @@ -5,12 +5,10 @@ sscint.h : scintillation genstep helpers ======================================== * FOLLOWING PATTERN OF storch.h and scerenkov.h - -For now just implemnet for JUNO specific variant : collectGenstep_DsG4Scintillation_r4695 +* shared by collected and fabricated scintillation gensteps **/ - #if defined(__CUDACC__) || defined(__CUDABE__) #define SSCINT_METHOD __device__ #else diff --git a/sysrap/tests/CMakeLists.txt b/sysrap/tests/CMakeLists.txt index 506599e45..6c4ae88c5 100644 --- a/sysrap/tests/CMakeLists.txt +++ b/sysrap/tests/CMakeLists.txt @@ -90,6 +90,7 @@ set(TEST_SOURCES scanvasTest.cc OpticksPhotonTest.cc + GenstepTest.cc SUTest.cc SEventConfigTest.cc SFrameConfigTest.cc diff --git a/sysrap/tests/GenstepTest.cc b/sysrap/tests/GenstepTest.cc new file mode 100644 index 000000000..1e24e709a --- /dev/null +++ b/sysrap/tests/GenstepTest.cc @@ -0,0 +1,39 @@ +#include +#include + +#include "OpticksGenstep.h" + +void test_retired_codes() +{ + for (unsigned type = 1; type <= 5; ++type) + { + assert(std::strcmp(OpticksGenstep_::Name(type), OpticksGenstep_::INVALID_) == 0); + assert(!OpticksGenstep_::IsValid(type)); + assert(!OpticksGenstep_::IsCerenkov(type)); + assert(!OpticksGenstep_::IsScintillation(type)); + assert(!OpticksGenstep_::IsExpected(type)); + assert(OpticksGenstep_::GenstepToPhotonFlag(type) == NAN_ABORT); + } +} + +void test_current_optical_codes() +{ + static_assert(OpticksGenstep_TORCH == 6, "genstep protocol values must remain stable"); + static_assert(OpticksGenstep_CERENKOV == 15, "genstep protocol values must remain stable"); + static_assert(OpticksGenstep_SCINTILLATION == 16, "genstep protocol values must remain stable"); + + assert(OpticksGenstep_::Type("CERENKOV") == OpticksGenstep_CERENKOV); + assert(OpticksGenstep_::Type("SCINTILLATION") == OpticksGenstep_SCINTILLATION); + assert(OpticksGenstep_::IsCerenkov(OpticksGenstep_CERENKOV)); + assert(OpticksGenstep_::IsCerenkov(OpticksGenstep_G4Cerenkov_modified)); + assert(OpticksGenstep_::IsScintillation(OpticksGenstep_SCINTILLATION)); + assert(OpticksGenstep_::GenstepToPhotonFlag(OpticksGenstep_CERENKOV) == CERENKOV); + assert(OpticksGenstep_::GenstepToPhotonFlag(OpticksGenstep_SCINTILLATION) == SCINTILLATION); +} + +int main() +{ + test_retired_codes(); + test_current_optical_codes(); + return 0; +} diff --git a/sysrap/tests/sgs_test.cc b/sysrap/tests/sgs_test.cc index 6eba6c16f..54a137a2b 100644 --- a/sysrap/tests/sgs_test.cc +++ b/sysrap/tests/sgs_test.cc @@ -6,32 +6,31 @@ void test_assign() { - sgs gs ; + sgs gs; - gs = {} ; - std::cout << gs.desc() << std::endl ; + gs = {}; + std::cout << gs.desc() << std::endl; - gs = { 101, 10000, 5000, OpticksGenstep_TORCH } ; - std::cout << gs.desc() << std::endl ; + gs = {101, 10000, 5000, OpticksGenstep_TORCH}; + std::cout << gs.desc() << std::endl; - gs = { 202, 20000, 4000, OpticksGenstep_CERENKOV } ; - std::cout << gs.desc() << std::endl ; + gs = {202, 20000, 4000, OpticksGenstep_CERENKOV}; + std::cout << gs.desc() << std::endl; - gs = { 303, 30000, 3000, OpticksGenstep_SCINTILLATION } ; - std::cout << gs.desc() << std::endl ; + gs = {303, 30000, 3000, OpticksGenstep_SCINTILLATION}; + std::cout << gs.desc() << std::endl; - gs = { 303, 30000, 3000, OpticksGenstep_G4Cerenkov_1042 } ; + gs = {303, 30000, 3000, OpticksGenstep_G4Cerenkov_modified}; std::cout << gs.desc() << std::endl ; } void test_array() { - sgs gs[] = { - { 101, 10000, 5000, OpticksGenstep_TORCH }, - { 202, 20000, 4000, OpticksGenstep_CERENKOV }, - { 303, 30000, 3000, OpticksGenstep_SCINTILLATION }, - { 303, 30000, 3000, OpticksGenstep_G4Cerenkov_1042 } - }; + sgs gs[] = { + {101, 10000, 5000, OpticksGenstep_TORCH}, + {202, 20000, 4000, OpticksGenstep_CERENKOV}, + {303, 30000, 3000, OpticksGenstep_SCINTILLATION}, + {303, 30000, 3000, OpticksGenstep_G4Cerenkov_modified}}; std::cout << " sizeof(sgs) " << sizeof(sgs) diff --git a/u4/Local_DsG4Scintillation.cc b/u4/Local_DsG4Scintillation.cc index 8423ef566..42ef3226a 100644 --- a/u4/Local_DsG4Scintillation.cc +++ b/u4/Local_DsG4Scintillation.cc @@ -584,7 +584,7 @@ Local_DsG4Scintillation::PostStepDoIt(const G4Track& aTrack, const G4Step& aStep if(is_opticks_genstep && (m_opticksMode & 1)) { NumPhoton = std::min( NumPhoton, 3 ); // for debugging purposes it helps to have less photons - U4::CollectGenstep_DsG4Scintillation_r4695( &aTrack, &aStep, NumPhoton, scnt, ScintillationTime); + U4::CollectGenstep_Scintillation(&aTrack, &aStep, NumPhoton, scnt, ScintillationTime); } if( m_opticksMode == 0 || (m_opticksMode & 2) ) diff --git a/u4/U4.cc b/u4/U4.cc index a75dd247e..a43871c27 100644 --- a/u4/U4.cc +++ b/u4/U4.cc @@ -49,8 +49,7 @@ HMM: perhapa this state belongs better within SEvt together with the full genste **/ - -static sgs gs = {} ; // updated by eg U4::CollectGenstep_DsG4Scintillation_r4695 prior to each photon generation loop +static sgs gs = {}; // updated by eg U4::CollectGenstep_Scintillation prior to each photon generation loop static spho ancestor = {} ; // updated by U4::GenPhotonAncestor prior to the photon generation loop(s) static spho pho = {} ; // updated by U4::GenPhotonBegin at start of photon generation loop static spho secondary = {} ; // updated by U4::GenPhotonEnd at end of photon generation loop @@ -65,13 +64,12 @@ Using hidden static non-member functions allows keeping Opticks types like quad6 **/ -static quad6 MakeGenstep_DsG4Scintillation_r4695( - const G4Track* aTrack, - const G4Step* aStep, - G4int numPhotons, - G4int scnt, - G4double ScintillationTime - ) +static quad6 MakeGenstep_Scintillation( + const G4Track* aTrack, + const G4Step* aStep, + G4int numPhotons, + G4int scnt, + G4double ScintillationTime) { G4StepPoint* pPreStepPoint = aStep->GetPreStepPoint(); G4StepPoint* pPostStepPoint = aStep->GetPostStepPoint(); @@ -89,7 +87,7 @@ static quad6 MakeGenstep_DsG4Scintillation_r4695( sscint* gs = (sscint*)(&_gs) ; // warning: dereferencing type-punned pointer will break strict-aliasing rules - gs->gentype = OpticksGenstep_DsG4Scintillation_r4695 ; + gs->gentype = OpticksGenstep_SCINTILLATION; gs->trackid = aTrack->GetTrackID() ; gs->matline = aMaterial->GetIndex() + SEvt::G4_INDEX_OFFSET ; // offset signals that a mapping must be done in SEvt::setGenstep gs->numphoton = numPhotons ; @@ -125,15 +123,13 @@ static quad6 MakeGenstep_DsG4Scintillation_r4695( return _gs ; } - -const char* U4::CollectGenstep_DsG4Scintillation_r4695_DISABLE = "U4__CollectGenstep_DsG4Scintillation_r4695_DISABLE" ; -const char* U4::CollectGenstep_DsG4Scintillation_r4695_ZEROPHO = "U4__CollectGenstep_DsG4Scintillation_r4695_ZEROPHO" ; - +const char* U4::CollectGenstep_Scintillation_DISABLE = "U4__CollectGenstep_Scintillation_DISABLE"; +const char* U4::CollectGenstep_Scintillation_ZEROPHO = "U4__CollectGenstep_Scintillation_ZEROPHO"; /** -U4::CollectGenstep_DsG4Scintillation_r4695 -------------------------------------------- +U4::CollectGenstep_Scintillation +-------------------------------- 1. makes quad6 gs_ collecting parameters needed to generate photons on GPU 2. adds gs_ to SEvt using SEvt::AddGenstep which collects into a vectors of quad6 for each SEvt @@ -142,33 +138,30 @@ U4::CollectGenstep_DsG4Scintillation_r4695 **/ -void U4::CollectGenstep_DsG4Scintillation_r4695( - const G4Track* aTrack, - const G4Step* aStep, - G4int numPhotons, - G4int scnt, - G4double ScintillationTime - ) +void U4::CollectGenstep_Scintillation( + const G4Track* aTrack, + const G4Step* aStep, + G4int numPhotons, + G4int scnt, + G4double ScintillationTime) { - if(getenv(CollectGenstep_DsG4Scintillation_r4695_DISABLE)) + if (getenv(CollectGenstep_Scintillation_DISABLE)) { - LOG(error) << CollectGenstep_DsG4Scintillation_r4695_DISABLE ; + LOG(error) << CollectGenstep_Scintillation_DISABLE; return ; } - if(getenv(CollectGenstep_DsG4Scintillation_r4695_ZEROPHO)) + if (getenv(CollectGenstep_Scintillation_ZEROPHO)) { - LOG(error) << CollectGenstep_DsG4Scintillation_r4695_ZEROPHO ; + LOG(error) << CollectGenstep_Scintillation_ZEROPHO; numPhotons = 0 ; } - - - quad6 gs_ = MakeGenstep_DsG4Scintillation_r4695( aTrack, aStep, numPhotons, scnt, ScintillationTime); + quad6 gs_ = MakeGenstep_Scintillation(aTrack, aStep, numPhotons, scnt, ScintillationTime); gs = SEvt::AddGenstep(gs_); // returns sgs struct which is a simple 4 int label // gs is private static genstep label - //if(dump) std::cout << "U4::CollectGenstep_DsG4Scintillation_r4695 " << gs.desc() << std::endl ; + // if(dump) std::cout << "U4::CollectGenstep_Scintillation " << gs.desc() << std::endl ; LOG(LEVEL) << gs.desc(); } diff --git a/u4/U4.hh b/u4/U4.hh index 811c76382..e38eb7f16 100644 --- a/u4/U4.hh +++ b/u4/U4.hh @@ -100,15 +100,14 @@ struct U4_API U4 static const plog::Severity LEVEL ; // genstep collection - static const char* CollectGenstep_DsG4Scintillation_r4695_DISABLE ; - static const char* CollectGenstep_DsG4Scintillation_r4695_ZEROPHO ; - static void CollectGenstep_DsG4Scintillation_r4695( - const G4Track* aTrack, - const G4Step* aStep, - G4int numPhotons, - G4int scnt, - G4double ScintillationTime - ); + static const char* CollectGenstep_Scintillation_DISABLE; + static const char* CollectGenstep_Scintillation_ZEROPHO; + static void CollectGenstep_Scintillation( + const G4Track* aTrack, + const G4Step* aStep, + G4int numPhotons, + G4int scnt, + G4double ScintillationTime); static const char* CollectGenstep_G4Cerenkov_modified_DISABLE ; static const char* CollectGenstep_G4Cerenkov_modified_ZEROPHO ; @@ -138,5 +137,3 @@ struct U4_API U4 }; - -