Repository navigation
Conversation
|
@ckierans the pull request on the shield readout was updated to include bug correction on the MReadOutElementVoxel3D class. MSubModuleShieldEnergyCorrection.cxx also updated to write more info in the verbose and verify the update. This pull request solves issues 275 and 279. Code analysis obtained with chatGPT and Claude in parallel. Main bugs:
Additional corrections aim to simplify the code and none of them change results for valid, fully specified data.
|
|
@ckierans I added the following commit to the PR: [BUG+ADD] reading D0/D1 plus bug correction on event merging. I updated the MSubModuleDEEIntake.cxx file to:
I tested the DEE using the smex v36 mass model, all ok. NOTE: the energy correction file only contains the X0 panel, but nuclearizer applies a constant default energy correction when it does not find a value from file, so it is not blocking the DEE. |
ckierans
left a comment
There was a problem hiding this comment.
Nice work, Valentina!
The unit tests are failing still after your change to Issue #275 - note at the bottom of the issue it says "Done when: all problems described in this issue are fixed, all ExpectedToFail() instances related to this issue are removed from the unit tests, and the unit tests pass on both macOS and Linux." So you have to update UTNReadOutElementVoxel3D accordingly:
// before
Passed = ExpectedToFail(EvaluateTrue("operator<", "different crystal ID", "...", (A < D2) != (D2 < A))) && Passed;
// after
Passed = EvaluateTrue("operator<", "different crystal ID", "...", (A < D2) != (D2 < A)) && Passed;
In a Claude review of your PR, one suggestion was to change m_DetectorID to m_DetectorName to resolve the shadowing of m_DetectorID with it's base member, as pointed out in issue #275. Meaning that the crystals with their string identifier have a DetectorName instead of a DetectorID in the derived MReadOutElementVoxel3D class. You can make this a smaller change and keep the public facing Set/GetDetectorID(), but internally change the protected members to m_DetectorName to avoid confusion:
//! Set detector ID as string
void SetDetectorID(const MString& DetectorID)
{
- m_DetectorID = DetectorID;
+ m_DetectorName = DetectorID;
}
//! Get detector ID as string
MString GetDetectorID() const
{
- return m_DetectorID;
+ return m_DetectorName;
}
I also would vote for changing the name "Shield" to "ACS" in almost all of these files. That's the official name of the subsystem, and is especially true considering it's not used only as a Shield! That's an annoying cosmetic change, I know.
| //! Set detector ID as string | ||
| void SetDetectorID(const MString& DetectorID) | ||
| { | ||
| m_DetectorID = DetectorID; | ||
| } | ||
| //! Get detector ID as string | ||
| MString GetDetectorID() const | ||
| { | ||
| return m_DetectorID; | ||
| } |
There was a problem hiding this comment.
| //! Set detector ID as string | |
| void SetDetectorID(const MString& DetectorID) { m_DetectorID = DetectorID; } | |
| //! Get detector ID as string | |
| MString GetDetectorID() const { return m_DetectorID; } |
There was a problem hiding this comment.
Move to single line for easier readability following the convention in other Nuclearizer classes.
| //! Set crystal ID as int | ||
| void SetCrystalID(unsigned int CrystalID) | ||
| { | ||
| m_CrystalID = CrystalID; | ||
| } | ||
| //! Get crystal ID as int | ||
| unsigned int GetCrystalID() const | ||
| { | ||
| return m_CrystalID; | ||
| } |
There was a problem hiding this comment.
| } | |
| //! Set crystal ID as int | |
| void SetCrystalID(unsigned int CrystalID) { m_CrystalID = CrystalID; } | |
| //! Get crystal ID as int | |
| unsigned int GetCrystalID() const { return m_CrystalID; } |
| //! Set Voxel X ID as int | ||
| void SetVoxelXID(unsigned int VoxelXID) | ||
| { | ||
| m_VoxelXID = VoxelXID; | ||
| } | ||
| //! Get Voxel X ID as int | ||
| unsigned int GetVoxelXID() const | ||
| { | ||
| return m_VoxelXID; | ||
| } |
There was a problem hiding this comment.
| //! Set Voxel X ID as int | |
| void SetVoxelXID(unsigned int VoxelXID) { m_VoxelXID = VoxelXID; } | |
| //! Get Voxel X ID as int | |
| unsigned int GetVoxelXID() const { return m_VoxelXID; } |
| //! Set Voxel Y ID as int | ||
| void SetVoxelYID(unsigned int VoxelYID) | ||
| { | ||
| m_VoxelYID = VoxelYID; | ||
| } | ||
| //! Set Voxel Y ID as int | ||
| //! Get Voxel Y ID as int | ||
| unsigned int GetVoxelYID() const | ||
| { | ||
| return m_VoxelYID; | ||
| } |
There was a problem hiding this comment.
| //! Set Voxel Y ID as int | |
| void SetVoxelYID(unsigned int VoxelYID) { m_VoxelYID = VoxelYID; } | |
| //! Get Voxel Y ID as int | |
| unsigned int GetVoxelYID() const { return m_VoxelYID; } |
| //! Set Voxel Z ID as int | ||
| void SetVoxelZID(unsigned int VoxelZID) | ||
| { | ||
| m_VoxelZID = VoxelZID; | ||
| } | ||
| //! Get Voxel Z ID as int | ||
| unsigned int GetVoxelZID() const | ||
| { | ||
| return m_VoxelZID; | ||
| } |
There was a problem hiding this comment.
| //! Set Voxel Z ID as int | |
| void SetVoxelZID(unsigned int VoxelZID) { m_VoxelZID = VoxelZID; } | |
| //! Get Voxel Z ID as int | |
| unsigned int GetVoxelZID() const { return m_VoxelZID; } |
| bool MReadOutElementVoxel3D::IsWritableDetectorID(const MString& DetectorID) | ||
| { | ||
| const char* C = DetectorID.Data(); | ||
| if (C[0] == '#' || (C[0] == '/' && C[1] == '/')) return false; // would start a comment in MTokenizer | ||
| if (DetectorID == c_EmptyDetectorIDToken) return false; // would be read back as empty | ||
| for (; *C != '\0'; ++C) { | ||
| if (isspace(static_cast<unsigned char>(*C)) != 0) return false; | ||
| } | ||
| return true; | ||
| } |
There was a problem hiding this comment.
Can you make this a bit more readable and follow the coding style in other Nuclearizer module. Claude did this translation for me as an example, but this should be equivalent.
| bool MReadOutElementVoxel3D::IsWritableDetectorID(const MString& DetectorID) | |
| { | |
| const char* C = DetectorID.Data(); | |
| if (C[0] == '#' || (C[0] == '/' && C[1] == '/')) return false; // would start a comment in MTokenizer | |
| if (DetectorID == c_EmptyDetectorIDToken) return false; // would be read back as empty | |
| for (; *C != '\0'; ++C) { | |
| if (isspace(static_cast<unsigned char>(*C)) != 0) return false; | |
| } | |
| return true; | |
| } | |
| bool MReadOutElementVoxel3D::IsWritableDetectorID(const MString& DetectorID) | |
| { | |
| // MTokenizer treats everything after "#" or "//" as a comment | |
| if (DetectorID.BeginsWith("#") == true || DetectorID.BeginsWith("//") == true) { | |
| return false; | |
| } | |
| // "-" is reserved as the placeholder for an empty detector ID | |
| if (DetectorID == c_EmptyDetectorIDToken) { | |
| return false; | |
| } | |
| // Whitespace would split the ID into several tokens | |
| for (unsigned int i = 0; i < DetectorID.Length(); ++i) { | |
| const unsigned char Character = DetectorID.Data()[i]; | |
| if (isspace(Character) != 0) { | |
| return false; | |
| } | |
| } | |
| return true; | |
| } |
| bool MReadOutElementVoxel3D::ParseUnsignedInt(const MString& Token, unsigned int& Value) | ||
| { | ||
| const char* C = Token.Data(); | ||
| if (*C == '\0') return false; | ||
|
|
||
| unsigned long long V = 0; | ||
| for (; *C != '\0'; ++C) { | ||
| if (*C < '0' || *C > '9') return false; | ||
| V = 10*V + static_cast<unsigned long long>(*C - '0'); | ||
| if (V > numeric_limits<unsigned int>::max()) return false; | ||
| } | ||
|
|
||
| Value = static_cast<unsigned int>(V); | ||
| return true; | ||
| } | ||
|
|
There was a problem hiding this comment.
Same comment about readability as above.
| CH.m_ADC = 2000 + 4*CH.m_Energy; | ||
| if (CH.m_ADC > 16383) CH.m_ADC = 16383; | ||
| for (MDEECrystalHit& CrystalHit: Hits) { | ||
| CrystalHit.m_ADC = GetADC(CrystalHit.m_Energy, CrystalHit.m_DetectorID, CrystalHit.m_CrystalID); |
There was a problem hiding this comment.
m_ADC is an unsigned int, but here GetADC returns a double. I think you should make a new variable double ADC = GetADC(.... and then do the max/min checks and then save CrystalHit.m_ADC as an unsigned int casted/rounded version of ADC.
| //////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
|
|
||
| bool MSubModuleShieldReadout::ParseShieldReadoutFile() |
There was a problem hiding this comment.
Eventually, once we have the ACS energy calibration in the forward pipeline, we might move this chunk of code into the (currently non-existant) MModuleACSEnergyCalibration module to match what we do in the GeD pipeline, but that is okay here now.
|
|
||
| MSubModuleShieldEnergyCorrection::MSubModuleShieldEnergyCorrection() | ||
| : MSubModule(), | ||
| m_Random(0) |
There was a problem hiding this comment.
I'm pretty sure the 4th issue identified in #279 is still present. Remove m_Random(0) here and use TRandom.h ROOT library in this file and use gRandom directly.
// before
double CorrectedEnergy = m_Random.Gaus(ShieldCorrectedCentroid, ShieldSigma);
// after
// Use ROOT's global generator gRandom, which MAssembly seeds, so that DEE runs are reproducible
double CorrectedEnergy = gRandom->Gaus(ShieldCorrectedCentroid, ShieldSigma);
This is an update for PR #199, that was closed because of conflicts with the master branch.
This PR modifies the following files:
GUI configuration to read the calibration file:
I added the ability in MReadOutElementVoxel3D to also map the detector/crystal ID with the detector and crystal ID listed in the calibration file:
new DEE submodule (Shield Readout) to convert from energy to ADC the shield hits:
A new file (energy to ADC calibration parameters) is added in resource/dee/ShieldEnergyCalibration_NRL.csv
Changes from PR #199:
On this comment on include/MReadOutElementVoxel3D.h:
using bool without virtual in
bool operator<(const MReadOutElementVoxel3D& R) const;is correct, because it only needs to order between two MReadOutElementVoxel3D objects, while
virtual bool operator==(const MReadOutElement& R) const;should be able to compare any readout element from the derived class.