Skip to content

Cs-137 Trapping App full pipeline - #284

Open
sophieehaight wants to merge 8 commits into
cositools:develop/emfrom
sophieehaight:trapping_app_pr
Open

sophieehaight wants to merge 8 commits into
cositools:develop/emfrom
sophieehaight:trapping_app_pr

Conversation

@sophieehaight

Copy link
Copy Markdown

Standalone app which approximates experimental CCEs using Cs-137 calibration data and fits them to simulated CCE curves to obtain trapping parameters for each detector. The app requires energy, TAC, and depth calibration files as inputs in addition to the detector geometry and simulated CCE files. The final output is a csv file containing trapping parameters for all detectors for which data is read in. Additional plots and outputs characterizing goodness of fit are stored in folder trapping_param_products.

For instructions on usage enter "TrappingCorrectionCs137 -h".

@sophieehaight
sophieehaight marked this pull request as ready for review October 20, 2026 19:16
Comment thread apps/TrappingCorrectionCs137.cxx Outdated

m_PixelCorrect = false;
m_MultiRoundStripPairing = false;
m_MultiRoundStripPairing = false; // should this be changed??

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a question for us or something to remind yourself?
My understanding is that we would use MModuleStripPairingMultiRoundChiSquare going forward (or at least that's the module that people have been updating recently).

Comment thread apps/TrappingCorrectionCs137.cxx Outdated
return false;
}
m_ProductsPrefix = MString((ProductsDir / OutPath.filename()).string());
cout << "Intermediate products will be stored in " << ProductsDir.string() << endl;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you added some later cout statements into c_Info, but not here. Is this intended?

Comment thread apps/TrappingCorrectionCs137.cxx Outdated
Comment on lines +826 to +829
if (SimCCEs.empty()) {
std::cerr << "[FATAL] Simulated CCE file is empty or file not found at: " << g_SimulatedCCEPath << std::endl;
return false;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like you're loading using namespace std; at the beginning of the file, so you could just remove std:: here and elsewhere:

Suggested change
if (SimCCEs.empty()) {
std::cerr << "[FATAL] Simulated CCE file is empty or file not found at: " << g_SimulatedCCEPath << std::endl;
return false;
}
if (SimCCEs.empty() == true) {
cerr << "[FATAL] Simulated CCE file is empty or file not found at: " << g_SimulatedCCEPath << endl;
return false;
}

Comment thread apps/TrappingCorrectionCs137.cxx Outdated
Comment on lines +843 to +846
if (!CombinedFile.is_open()) {
std::cerr << "[Error] Cannot create output file: " << CombinedCSV << std::endl;
return false;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not going to flag everything, but maybe you can have a look for style guide changes:

Suggested change
if (!CombinedFile.is_open()) {
std::cerr << "[Error] Cannot create output file: " << CombinedCSV << std::endl;
return false;
}
if (CombinedFile.is_open() == false) {
cerr << "[Error] Cannot create output file: " << CombinedCSV << endl;
return false;
}

Comment thread apps/TrappingCorrectionCs137.cxx Outdated
Comment on lines +1192 to +1194
if (!Result.IsValid()) {
std::cerr << "[Warning] Fit result not valid (status " << Result.Status() << ") for Detector " << DetID << std::endl;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have warnings, you could do

Suggested change
if (!Result.IsValid()) {
std::cerr << "[Warning] Fit result not valid (status " << Result.Status() << ") for Detector " << DetID << std::endl;
}
if (Result.IsValid() == false) {
if (m_Verbosity >= c_Warning) cout << "WARNING: Fit result not valid (status " << Result.Status() << ") for Detector " << DetID << endl;
}

Comment thread apps/TrappingCorrectionCs137.cxx Outdated
Comment on lines +1204 to +1213
std::cout << "\n================ JOINT FIT RESULTS ================" << std::endl;
std::cout << " Detector ID : " << DetID << std::endl;
std::cout << " A_hv : " << TrappingParams[0] << std::endl;
std::cout << " A_lv : " << TrappingParams[1] << std::endl;
std::cout << " B (e-trap) : " << TrappingParams[2] << std::endl;
std::cout << " C (h-trap) : " << TrappingParams[3] << std::endl;
std::cout << " Chi2 (Calc) : " << CalculatedChi2 << std::endl;
std::cout << " NDF : " << NDF << std::endl;
std::cout << " Chi2 / NDF : " << (NDF > 0 ? CalculatedChi2 / NDF : -1) << std::endl;
std::cout << "====================================================\n" << std::endl;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this always be printed to the console?

Comment thread apps/TrappingCorrectionCs137.cxx Outdated
Legend->Draw();
}

MString PlotFile = m_ProductsPrefix + MString("_Det_") + DetID + MString("_CCE_fit.png");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you always want to create PNG values for the CCE fits or should this be an optional feature that the user can turn off when running the app?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The module actually produces quite a lot of files characterizing the individual photopeak fits and fitted CCE. I had them read into a separate directory trapping_param_products to tuck them away. I can add an option s.t all output files apart from the trapping parameter file itself are suppressed unless you choose to save them.

I'll also wrap all of the terminal outputs in verbosity checks so that the outputs here are as clean as possible by default!

fixed compilation error, comment cleanup, updated verbosity settings
Comment thread apps/TrappingCorrectionCs137.cxx Outdated
double m_MaxEnergy;

//! Verbosity of this app's own output, independent of the MEGAlib g_Verbosity used by the nuclearizer modules
// Verbosity of this app's own output, independent of the globabl verbosity used by the nuclearizer modules

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo:

Suggested change
// Verbosity of this app's own output, independent of the globabl verbosity used by the nuclearizer modules
// Verbosity of this app's own output, independent of the global verbosity used by the nuclearizer modules

m_MaxEnergy = 700;
m_NDepthBins = 20;
m_Verbosity = c_Error;
m_SaveProducts = false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Products" as in plots, or also the intermediate CCE files?
If it's both, we might want to have several independent options to save the CCE peak fit results, but not the plots, etc.

Comment thread apps/TrappingCorrectionCs137.cxx Outdated
cout<<Usage.str()<<endl;
if (((argc > i+1) && (argv[i+1][0] != '-' || isalpha(argv[i+1][1]) == 0)) == false) {
if (m_Verbosity >= c_Error) {
cout<<"[Error] Option "<<argv[i][1]<<" needs a second argument!"<<endl;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We tend to use ERROR: Option ... syntax instead of [Error] Option ... but I don't have too strong of a feeling about this.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep happy to update these

Comment thread apps/TrappingCorrectionCs137.cxx Outdated
Comment on lines +418 to +427
// Relate the local verbosity setting to the global verbosity levels
if (m_Verbosity >= c_Info) {
gErrorIgnoreLevel = kInfo;
} else if (m_Verbosity >= c_Warning) {
gErrorIgnoreLevel = kWarning;
} else if (m_Verbosity >= c_Error) {
gErrorIgnoreLevel = kError;
} else {
gErrorIgnoreLevel = kFatal;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this needed for?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wrapping the errors that ROOT outputs for the canvases and plots in this module with my verbosity settings for info, warning, and error so the ROOT errors only get printed at that verbosity setting. I updated the comment to clarify this.

Comment thread apps/TrappingCorrectionCs137.cxx Outdated
return false;
}

// Check that you ond't trim too mnay depth bins

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Check that you ond't trim too mnay depth bins
// Check that you don't trim too many depth bins

return false;
}

// Set global verbosity to 0 s.t to supressed output from the nuclearizer modules

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Set global verbosity to 0 s.t to supressed output from the nuclearizer modules
// Set global verbosity to 0 to suppress output from the nuclearizer modules

Comment thread apps/TrappingCorrectionCs137.cxx Outdated
Comment on lines +1265 to +1268
if (m_SaveProducts == true) {
PlotCCEFit(ExpData, Sim, TrappingParams, DetID);
SaveTrappingParamFile(OutputCSVPath, TrappingParamPath, TrappingParams, Sim, DetID);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to my comment above:
I would prefer having separate m_SaveProducts and m_SavePlots for the text files and plots of the fits, respectively.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I've update this in my next push. I've also added an option to save the hit and depth bin data in ROOT file after they've been calibrated by the nuclearizer modules. This separates the calibration step from the general analysis and ultimately makes it much quicker to fit experimental CCE at various binnings. Let me know what you think!

////////////////////////////////////////////////////////////////////////////////////////////////////

void TrappingCorrectionCs137::PlotCCEFit(const std::vector<ExperimentalPoint>& ExpData,
void TrappingCorrectionCs137::PlotCCEFit(const vector<ExperimentalPoint>& ExpData,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you attach an example screenshot of what such a PNG file would look like? :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2026-10-20 at 4 32 26 PM Here's one to show the formatting! could be a better fit though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants