Skip to content

Commit

Permalink
fixed gtouchable processing, major improvements in gtouchable debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
maureeungaro committed May 5, 2023
1 parent dd6fad3 commit c36bb3a
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 35 deletions.
21 changes: 14 additions & 7 deletions gdynamicDigitization/gdynamicdigitization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// glibrary
#include "gtranslationTableConventions.h"
#include "gdataConventions.h"
#include "gtouchableConventions.h"

// c++
using std::cerr;
Expand Down Expand Up @@ -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<GTouchable*> 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) };
}

}


Expand Down
69 changes: 45 additions & 24 deletions gtouchable/gtouchable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

// glibrary
#include "gutilities.h"
#include "gutsConventions.h"
using namespace std;

//#include <math.h> /* 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<double> dimensions, bool verb) :
verbosity(verb),
trackId(0),
eMultiplier(1),
stepTimeAtElectronicsIndex(0),
detectorDimenions(dimensions) {
stepTimeAtElectronicsIndex(GTOUCHABLEUNSETTIMEINDEX),
detectorDimensions(dimensions) {

// gtype from digitization
if ( digitization == FLUXNAME ) {
Expand Down Expand Up @@ -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<GIdentifier> gid, float weight) :
Expand Down Expand Up @@ -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; i<that.gidentity.size(); i++) {
string comparisonResult = ( this->gidentity[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) {
Expand All @@ -81,17 +107,15 @@ bool GTouchable::operator == (const GTouchable& that) const
return false;
}

if (verbosity) {
cout << " Touchable comparison: " << endl;
for (size_t i=0; i<that.gidentity.size(); i++) {
cout << this->gidentity[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; i<that.gidentity.size(); i++) {
if ( this->gidentity[i].getValue() != that.gidentity[i].getValue() ) {
if (verbosity) {
cout << " Touchable gidentity are different: " << this->gidentity[i] << " " << that.gidentity[i] << endl;
}
return false;
}
}
Expand All @@ -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;
}

Expand Down
15 changes: 11 additions & 4 deletions gtouchable/gtouchable.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class GTouchable
// to register a new gtouchable in the sensitive detector gtouchable map
GTouchable(string digitization, string gidentityString, vector<double> 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
Expand All @@ -74,20 +79,20 @@ 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;

// to print it out
friend ostream &operator<<(ostream &stream, GTouchable gtouchable);

// could be used in GDynamicDigitization when the dimensions are needed
vector<double> detectorDimenions;
vector<double> detectorDimensions;

public:
// Overloaded "==" operator for the class 'GTouchable'
Expand All @@ -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<GIdentifier> getIdentity() const {return gidentity;}
inline const vector<double> getDetectorDimensions() const {return detectorDimenions;}
inline const vector<double> getDetectorDimensions() const {return detectorDimensions;}

};

Expand Down
1 change: 1 addition & 0 deletions gtouchable/gtouchableConventions.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
#define FLUXNAME "flux"
#define COUNTERNAME "particleCounter"
#define DOSIMETERNAME "dosimeter"
#define GTOUCHABLEUNSETTIMEINDEX -1

#endif
3 changes: 3 additions & 0 deletions release_notes/1.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c36bb3a

Please sign in to comment.