Adds local PID parametrization file option to KFParticle_sPHENIX#4137
Conversation
📝 WalkthroughWalkthroughAddition of local PID file configuration support to KFParticle framework. Introduces public methods Changes
✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
offline/packages/KFParticle_sPHENIX/KFParticle_Tools.cc (2)
1205-1232: Validate TF1 object lookups before populatingpidMap.
GetObject()returns without modifying the pointer if the object is missing, leaving itnullptr. These null pointers then flow intopidMapand will crashget_dEdx_fitValue()when it dereferencespidMap[PID]->Eval(momentum). Add validation checks and return early if any required TF1 object is not found.Suggested fix
if (m_use_local_PID_file) { // new method is independent of charge filefit->GetObject("pi_band",f_pion_plus); filefit->GetObject("K_band",f_kaon_plus); filefit->GetObject("p_band",f_proton_plus); filefit->GetObject("pi_band",f_pion_minus); filefit->GetObject("K_band",f_kaon_minus); filefit->GetObject("p_band",f_proton_minus); } else { filefit->GetObject("f_piband", f_pion_plus); filefit->GetObject("f_Kband", f_kaon_plus); filefit->GetObject("f_pband", f_proton_plus); filefit->GetObject("f_piminus_band", f_pion_minus); filefit->GetObject("f_Kminus_band", f_kaon_minus); filefit->GetObject("f_pbar_band", f_proton_minus); } + + const bool missing = + !f_pion_plus || !f_kaon_plus || !f_proton_plus || + !f_pion_minus || !f_kaon_minus || !f_proton_minus; + if (missing) + { + std::cerr << "Missing PID TF1(s) in file: " << dedx_fitparams << std::endl; + return; + }
1187-1203: Guard against nullTFile::Openresults before dereference.
TFile::Openreturnsnullptron failure (missing file, invalid path, permissions). The code dereferencesfilefitat line 1199 withfilefit->IsOpen()without checking for null first—ifm_local_PID_filenameis empty or invalid, this will crash.Add a null check before dereferencing:
Proposed fix
TFile *filefit = TFile::Open(dedx_fitparams.c_str()); - - if (!filefit->IsOpen()) + if (!filefit || !filefit->IsOpen()) { - std::cerr << "Error opening filefit!" << std::endl; + std::cerr << "Error opening dEdx fit file: " << dedx_fitparams << std::endl; return; }
|
Hi @petermic, thanks for adding this is. I think it does what we want but I'd suggest one change: useLocalPIDFile(bool use = false)this default here should probably be |
Types of changes
What kind of change does this PR introduce? (Bug fix, feature, ...)
Adds option to KFParticle_sPHENIX to use a local file for the dE/dx parametrization, rather than the file in the CDB. The default is still the CDB file. Enable in macro using
useLocalPIDFile(true)and set filename usingsetLocalPIDFilename.TODOs (if applicable)
Links to other PRs in macros and calibration repositories (if applicable)
Local PID Parametrization File Option for KFParticle_sPHENIX
Motivation
Adds the ability to use a local dE/dx parametrization file for particle identification (PID) instead of relying exclusively on the default CDB (Conditions Database) file. This feature allows greater flexibility for testing alternative parametrizations and local analysis workflows without modifying the database.
Key Changes
New configuration methods in
KFParticle_sPHENIX:useLocalPIDFile(bool use = false)— enables/disables local file mode (default: off)setLocalPIDFilename(std::string name)— specifies the local file pathModified
init_dEdx_fits()function inKFParticle_Tools:pi_band,K_band,p_bandfor all charge states)f_piband,f_Kband,f_pband,f_piminus_band,f_Kminus_band,f_pbar_band)std::cerroutput for file open failuresLines changed: ~35 across three files (KFParticle_sPHENIX.h, KFParticle_Tools.h/cc)
Potential Risk Areas
pi_band,K_band,p_band), which differs from the CDB format. Providing an incorrectly formatted file will fail silently after printing an error message.Possible Future Improvements
Note: AI-generated summaries can contain inaccuracies. The core logic appears sound (conditional file loading based on a boolean flag), but reviewers should verify that the expected file format and object naming scheme match actual usage patterns in local PID files.