From c36bb3a6963353ecce71a6cbeeb6fda6b80392f7 Mon Sep 17 00:00:00 2001 From: Maurizio Ungaro Date: Fri, 5 May 2023 14:04:47 -0400 Subject: [PATCH] fixed gtouchable processing, major improvements in gtouchable debugging --- gdynamicDigitization/gdynamicdigitization.cc | 21 ++++-- gtouchable/gtouchable.cc | 69 +++++++++++++------- gtouchable/gtouchable.h | 15 +++-- gtouchable/gtouchableConventions.h | 1 + release_notes/1.4.md | 3 + 5 files changed, 74 insertions(+), 35 deletions(-) diff --git a/gdynamicDigitization/gdynamicdigitization.cc b/gdynamicDigitization/gdynamicdigitization.cc index a2bef7b5..00175b17 100644 --- a/gdynamicDigitization/gdynamicdigitization.cc +++ b/gdynamicDigitization/gdynamicdigitization.cc @@ -4,6 +4,7 @@ // glibrary #include "gtranslationTableConventions.h" #include "gdataConventions.h" +#include "gtouchableConventions.h" // c++ using std::cerr; @@ -133,15 +134,21 @@ float GDynamicDigitization:: processStepTime(GTouchable *gTouchID, G4Step* thisS } -// if not overloaded, returns a vector with a single touchable, with cell time index based on processStepTime +// if not overloaded, returns: +// a vector with a single touchable, with cell time index based on processStepTime if the time index is the same as the gTouchID's (or if it wasn't set) +// a vectory with two touchables, one with the original gtouchID time index, and one with the new one vector GDynamicDigitization::processTouchable(GTouchable *gTouchID, G4Step* thisStep) { - + float stepTimeAtElectronics = processStepTime(gTouchID, thisStep); - - gTouchID->assignStepTimeAtElectronicsIndex(readoutSpecs->timeCellIndex(stepTimeAtElectronics)); - - return { gTouchID }; - + float stepTimeAtElectronicsIndex = readoutSpecs->timeCellIndex(stepTimeAtElectronics); + + if ( stepTimeAtElectronicsIndex == gTouchID->getStepTimeAtElectronicsIndex() || gTouchID->getStepTimeAtElectronicsIndex() == GTOUCHABLEUNSETTIMEINDEX) { + gTouchID->assignStepTimeAtElectronicsIndex(stepTimeAtElectronicsIndex); + return { gTouchID }; + } else { + return { gTouchID, new GTouchable(gTouchID, stepTimeAtElectronicsIndex) }; + } + } diff --git a/gtouchable/gtouchable.cc b/gtouchable/gtouchable.cc index e6cd3658..fda6832e 100644 --- a/gtouchable/gtouchable.cc +++ b/gtouchable/gtouchable.cc @@ -4,19 +4,19 @@ // glibrary #include "gutilities.h" +#include "gutsConventions.h" using namespace std; -//#include /* fabs */ -// contructor from digitization and gidentity strings +// constructor from digitization and gidentity strings // called in GDetectorConstruction::ConstructSDandField // to register a new gtouchable in the sensitive detector gtouchable map GTouchable::GTouchable(string digitization, string gidentityString, vector dimensions, bool verb) : verbosity(verb), trackId(0), eMultiplier(1), -stepTimeAtElectronicsIndex(0), -detectorDimenions(dimensions) { +stepTimeAtElectronicsIndex(GTOUCHABLEUNSETTIMEINDEX), +detectorDimensions(dimensions) { // gtype from digitization if ( digitization == FLUXNAME ) { @@ -44,6 +44,21 @@ detectorDimenions(dimensions) { } + +// copy constructor called in the non-overloaded processTouchable: +// used in case the stepTimeIndex of the hit is different from the gtouchable one +GTouchable::GTouchable(const GTouchable* baseGT, int newTimeIndex) { + gType = baseGT->gType; + gidentity = baseGT->gidentity; + verbosity = baseGT->verbosity; + trackId = baseGT->trackId; + eMultiplier = baseGT->eMultiplier; + detectorDimensions = baseGT->detectorDimensions; + stepTimeAtElectronicsIndex = newTimeIndex; +} + + + // copy constructor called in processTouchable // weight and time can be set by processTouchable //GTouchable::GTouchable(const GTouchable& baseGT, vector gid, float weight) : @@ -71,8 +86,19 @@ detectorDimenions(dimensions) { // Overloaded "==" operator for the class 'GTouchable' bool GTouchable::operator == (const GTouchable& that) const { - - // first, compare size of identity + if (verbosity) { + cout << " Touchable comparison: " << endl; + for (size_t i=0; igidentity[i].getValue() == that.gidentity[i].getValue() ) ? " ✅" : " ❌"; + cout << " " << this->gidentity[i] << " " << that.gidentity[i] << comparisonResult << endl; + } + if (this->gType == readout) { + string cellIndexCompariton = (this->stepTimeAtElectronicsIndex == that.stepTimeAtElectronicsIndex) ? " ✅" : " ❌"; + cout << " time index: " << this->stepTimeAtElectronicsIndex << " " << that.stepTimeAtElectronicsIndex << cellIndexCompariton << endl; + } + } + + // first, compare size of identity // this should never happen because the same sensitivity should be assigned the same identifier structure if (this->gidentity.size() != that.gidentity.size()) { if (verbosity) { @@ -81,17 +107,15 @@ bool GTouchable::operator == (const GTouchable& that) const return false; } - if (verbosity) { - cout << " Touchable comparison: " << endl; - for (size_t i=0; igidentity[i] << " " << that.gidentity[i] << endl; - } - } - // now compare that the identity is actuallty the same + + // now compare that the identity is actually the same // return false if something is different for (size_t i=0; igidentity[i].getValue() != that.gidentity[i].getValue() ) { + if (verbosity) { + cout << " Touchable gidentity are different: " << this->gidentity[i] << " " << that.gidentity[i] << endl; + } return false; } } @@ -115,35 +139,32 @@ bool GTouchable::operator == (const GTouchable& that) const // ostream GTouchable ostream &operator<<(ostream &stream, GTouchable gtouchable) { - stream << " ・ "; + stream << " GTouchable: "; for ( auto& gid: gtouchable.gidentity ) { - - stream << gid ; + stream << KRED << gid ; if ( gid.getName() != gtouchable.gidentity.back().getName() ) { stream << ", "; } else { - stream << std::endl; + stream << RST ; } } switch (gtouchable.gType) { case readout: // compare the time cell - stream << " ・ type: readout " << std::endl; + stream << KGRN << " (readout), " << RST << " multiplier: " << gtouchable.eMultiplier << ", time cell index: " << gtouchable.stepTimeAtElectronicsIndex ; break; case flux: - stream << " ・ type: flux " << std::endl; + stream << KGRN << " (flux), " << RST << " g4 track id: " << gtouchable.trackId; break; case dosimeter: - stream << " ・ type: dosimeter " << std::endl; + stream << KGRN << " (dosimeter), " << RST << " g4 track id: " << gtouchable.trackId ; break; case particleCounter: - stream << " ・ type: particleCounter " << std::endl; + stream << KGRN << " (particleCounter), " << RST << " g4 track id: " << gtouchable.trackId ; break; } - stream << " ・ energy multiplier: " << gtouchable.eMultiplier << std::endl; - stream << " ・ time cell index: " << gtouchable.stepTimeAtElectronicsIndex << std::endl; - stream << " ・ g4 track id: " << gtouchable.trackId << std::endl; + return stream; } diff --git a/gtouchable/gtouchable.h b/gtouchable/gtouchable.h index f891139c..9fe66fe7 100644 --- a/gtouchable/gtouchable.h +++ b/gtouchable/gtouchable.h @@ -53,6 +53,11 @@ class GTouchable // to register a new gtouchable in the sensitive detector gtouchable map GTouchable(string digitization, string gidentityString, vector dimensions, bool verb = false); + // copy constructor called in the non-overloaded processTouchable: + // used in case the stepTimeIndex of the hit is different from the gtouchable one + GTouchable(const GTouchable* baseGT, int newTimeIndex); + + // copy constructor called in processTouchable // used for energy sharing (keeps time as is) // need to provide the gidentity @@ -74,12 +79,12 @@ class GTouchable int trackId; // set by processGTouchable in the digitization plugin. Defaulted to 1. Used to share energy / create new hits. - // Energy Multiplier. By default it is 1, but energy could be shared (or created) among volumes + // Energy Multiplier. By default, it is 1, but energy could be shared (or created) among volumes float eMultiplier; // stepTimeAtElectronicsIndex is used to determine if a hit is within // an existing detector readout electronic time window - // stepTimeAtElectronicsIndex is set using using assignStepTimeAtElectronicsIndex + // stepTimeAtElectronicsIndex is set using assignStepTimeAtElectronicsIndex // in gDynamicDigitization using the greadoutSpecs int stepTimeAtElectronicsIndex; @@ -87,7 +92,7 @@ class GTouchable friend ostream &operator<<(ostream &stream, GTouchable gtouchable); // could be used in GDynamicDigitization when the dimensions are needed - vector detectorDimenions; + vector detectorDimensions; public: // Overloaded "==" operator for the class 'GTouchable' @@ -101,10 +106,12 @@ class GTouchable inline void assignStepTimeAtElectronicsIndex(int timeIndex) { stepTimeAtElectronicsIndex = timeIndex; } + inline const int getStepTimeAtElectronicsIndex() const { return stepTimeAtElectronicsIndex; } + // api public: inline const vector getIdentity() const {return gidentity;} - inline const vector getDetectorDimensions() const {return detectorDimenions;} + inline const vector getDetectorDimensions() const {return detectorDimensions;} }; diff --git a/gtouchable/gtouchableConventions.h b/gtouchable/gtouchableConventions.h index 3268e23d..aeed8946 100644 --- a/gtouchable/gtouchableConventions.h +++ b/gtouchable/gtouchableConventions.h @@ -8,5 +8,6 @@ #define FLUXNAME "flux" #define COUNTERNAME "particleCounter" #define DOSIMETERNAME "dosimeter" +#define GTOUCHABLEUNSETTIMEINDEX -1 #endif diff --git a/release_notes/1.4.md b/release_notes/1.4.md index f2cb732f..29860dd2 100644 --- a/release_notes/1.4.md +++ b/release_notes/1.4.md @@ -16,3 +16,6 @@ - verbosity option for glibrary classes conforms to same description - testing all sci-g examples - added GEMCDB_ENV to list of location for sqlite database +- fixed gtouchable processing: when step time is on another time index, the non-overloaded processTouchable returns + a vector of gtouchable containing the step gtouchable and a new one with the new time index +- major improvements in gtouchable debugging