Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
256 changes: 173 additions & 83 deletions offline/packages/jetbackground/DetermineTowerBackground.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#include <eventplaneinfo/Eventplaneinfo.h>
#include <eventplaneinfo/EventplaneinfoMap.h>

#include <centrality/CentralityInfo.h>
#include <ffamodules/CDBInterface.h>
#include <cdbobjects/CDBTTree.h>

#include <jetbase/Jet.h>
#include <jetbase/JetContainer.h>

Expand Down Expand Up @@ -52,9 +56,69 @@ DetermineTowerBackground::DetermineTowerBackground(const std::string &name)

int DetermineTowerBackground::InitRun(PHCompositeNode *topNode)
{
if (_do_flow == 4)
{
if (Verbosity())
{
std::cout << "Loading the average calo v2" << std::endl;
}
if (!LoadCalibrations())
{
std::cout << "Load calibrations failed." << std::endl;
return Fun4AllReturnCodes::ABORTRUN;
}

}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

return CreateNode(topNode);
}

int DetermineTowerBackground::LoadCalibrations()
{

CDBTTree *cdbtree_calo_v2 = nullptr;

std::string calibdir;
if (m_overwrite_average_calo_v2)
{
calibdir = m_overwrite_average_calo_v2_path;
}
else
{
calibdir = CDBInterface::instance()->getUrl(m_calibName);
}

if (calibdir.empty())
{
std::cout << "Could not find and load histograms for EMCAL LUTs! defaulting to the identity table!" << std::endl;
return Fun4AllReturnCodes::ABORTRUN;
}
else
{
cdbtree_calo_v2 = new CDBTTree(calibdir);
}

if (!cdbtree_calo_v2)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the ctor of cdbttree will always return an object, checking for null will never trigger. Errors are caught in the LoadCalibrations method and the code will do a hard exit() if an error is encountered:

void CDBTTree::LoadCalibrations()

{
std::cout << "Error in finding Average Calo v2." << std::endl;

return Fun4AllReturnCodes::ABORTRUN;
}

cdbtree_calo_v2->LoadCalibrations();

_CENTRALITY_V2.assign(100,0);

for (int icent = 0; icent < 100; icent++)
{
_CENTRALITY_V2[icent] = cdbtree_calo_v2->GetFloatValue(icent, "jet_calo_v2");
}

delete cdbtree_calo_v2;

return Fun4AllReturnCodes::EVENT_OK;
}
Comment on lines +76 to +108
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Memory leak risk in LoadCalibrations.

If an exception is thrown between the allocation at line 93 and the delete at line 105 (e.g., from new CDBTTree, LoadCalibrations(), or GetFloatValue), the dynamically allocated cdbtree_calo_v2 will leak. Consider using std::unique_ptr or wrapping the allocation in a try-catch block to ensure cleanup.

Additionally, line 90 calls exit(-1) which terminates the entire process rather than allowing the caller to handle the error gracefully. Consider returning Fun4AllReturnCodes::ABORTRUN instead, consistent with other error paths in InitRun.

🔒 Proposed fix for memory safety
 int DetermineTowerBackground::LoadCalibrations()
 {
   
-  CDBTTree *cdbtree_calo_v2 = nullptr;
+  std::unique_ptr<CDBTTree> cdbtree_calo_v2;
 
   std::string calibdir = CDBInterface::instance()->getUrl(m_calibName);
   if (m_overwrite_average_calo_v2)
     {
       calibdir = m_overwrite_average_calo_v2_path;
     }
 
   if (calibdir.empty())
     {
       std::cout << "Could not find filename for calo average v2, exiting" << std::endl;
-      exit(-1);
+      return Fun4AllReturnCodes::ABORTRUN;
     }
 
-  cdbtree_calo_v2 = new CDBTTree(calibdir);
+  cdbtree_calo_v2 = std::make_unique<CDBTTree>(calibdir);
   
     
   cdbtree_calo_v2->LoadCalibrations();
 
   _CENTRALITY_V2.assign(100,0);
 
   for (int icent = 0; icent < 100; icent++)
     {
       _CENTRALITY_V2[icent] = cdbtree_calo_v2->GetFloatValue(icent, "jet_calo_v2");
     }
       
-  delete cdbtree_calo_v2;
+  // unique_ptr automatically cleans up
 
   return Fun4AllReturnCodes::EVENT_OK;
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
int DetermineTowerBackground::LoadCalibrations()
{
CDBTTree *cdbtree_calo_v2 = nullptr;
std::string calibdir = CDBInterface::instance()->getUrl(m_calibName);
if (m_overwrite_average_calo_v2)
{
calibdir = m_overwrite_average_calo_v2_path;
}
if (calibdir.empty())
{
std::cout << "Could not find filename for calo average v2, exiting" << std::endl;
exit(-1);
}
cdbtree_calo_v2 = new CDBTTree(calibdir);
cdbtree_calo_v2->LoadCalibrations();
_CENTRALITY_V2.assign(100,0);
for (int icent = 0; icent < 100; icent++)
{
_CENTRALITY_V2[icent] = cdbtree_calo_v2->GetFloatValue(icent, "jet_calo_v2");
}
delete cdbtree_calo_v2;
return Fun4AllReturnCodes::EVENT_OK;
}
int DetermineTowerBackground::LoadCalibrations()
{
std::unique_ptr<CDBTTree> cdbtree_calo_v2;
std::string calibdir = CDBInterface::instance()->getUrl(m_calibName);
if (m_overwrite_average_calo_v2)
{
calibdir = m_overwrite_average_calo_v2_path;
}
if (calibdir.empty())
{
std::cout << "Could not find filename for calo average v2, exiting" << std::endl;
return Fun4AllReturnCodes::ABORTRUN;
}
cdbtree_calo_v2 = std::make_unique<CDBTTree>(calibdir);
cdbtree_calo_v2->LoadCalibrations();
_CENTRALITY_V2.assign(100,0);
for (int icent = 0; icent < 100; icent++)
{
_CENTRALITY_V2[icent] = cdbtree_calo_v2->GetFloatValue(icent, "jet_calo_v2");
}
// unique_ptr automatically cleans up
return Fun4AllReturnCodes::EVENT_OK;
}


int DetermineTowerBackground::process_event(PHCompositeNode *topNode)
{

Expand Down Expand Up @@ -481,7 +545,92 @@ int DetermineTowerBackground::process_event(PHCompositeNode *topNode)
}
}

if ( _do_flow >= 1 )

// Get psi
if (_do_flow == 2)
{ // HIJING truth flow extraction
PHG4TruthInfoContainer *truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode, "G4TruthInfo");

if (!truthinfo)
{
std::cout << "DetermineTowerBackground::process_event: FATAL , G4TruthInfo does not exist , cannot extract truth flow with do_flow = " << _do_flow << std::endl;
return -1;
}

PHG4TruthInfoContainer::Range range = truthinfo->GetPrimaryParticleRange();

float Hijing_Qx = 0;
float Hijing_Qy = 0;

for (PHG4TruthInfoContainer::ConstIterator iter = range.first; iter != range.second; ++iter)
{
PHG4Particle *g4particle = iter->second;

if (truthinfo->isEmbeded(g4particle->get_track_id()) != 0)
{
continue;
}

TLorentzVector t;
t.SetPxPyPzE(g4particle->get_px(), g4particle->get_py(), g4particle->get_pz(), g4particle->get_e());

float truth_pt = t.Pt();
if (truth_pt < 0.4)
{
continue;
}
float truth_eta = t.Eta();
if (std::fabs(truth_eta) > 1.1)
{
continue;
}
float truth_phi = t.Phi();
int truth_pid = g4particle->get_pid();

if (Verbosity() > 10)
{
std::cout << "DetermineTowerBackground::process_event: determining truth flow, using particle w/ pt / eta / phi " << truth_pt << " / " << truth_eta << " / " << truth_phi << " , embed / PID = " << truthinfo->isEmbeded(g4particle->get_track_id()) << " / " << truth_pid << std::endl;
}

Hijing_Qx += truth_pt * std::cos(2 * truth_phi);
Hijing_Qy += truth_pt * std::sin(2 * truth_phi);
}

_Psi2 = std::atan2(Hijing_Qy, Hijing_Qx) / 2.0;

if (Verbosity() > 0)
{
std::cout << "DetermineTowerBackground::process_event: flow extracted from Hijing truth particles, setting Psi2 = " << _Psi2 << " ( " << _Psi2 / M_PI << " * pi ) " << std::endl;
}
}
else if (_do_flow == 3 || _do_flow == 4)
{ // sEPD event plane extraction
// get event plane map
EventplaneinfoMap *epmap = findNode::getClass<EventplaneinfoMap>(topNode, "EventplaneinfoMap");
if (!epmap)
{
std::cout << "DetermineTowerBackground::process_event: FATAL, EventplaneinfoMap does not exist, cannot extract sEPD flow with do_flow = " << _do_flow << std::endl;
exit(-1);
}
Comment on lines +594 to +602
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Replace exit() with proper error return.

Line 601 calls exit(-1) when EventplaneinfoMap is missing. This terminates the entire process and prevents the framework from handling the error gracefully. Return Fun4AllReturnCodes::ABORTRUN instead, consistent with how other missing nodes are handled elsewhere in the file (e.g., line 460).

♻️ Proposed fix
   else if (_do_flow == 3 || _do_flow == 4)
     { // sEPD event plane extraction
       // get event plane map
       EventplaneinfoMap *epmap = findNode::getClass<EventplaneinfoMap>(topNode, "EventplaneinfoMap");
       if (!epmap)
         {
           std::cout << "DetermineTowerBackground::process_event: FATAL, EventplaneinfoMap does not exist, cannot extract sEPD flow with do_flow = " << _do_flow << std::endl;
-          exit(-1);
+          return Fun4AllReturnCodes::ABORTRUN;
         }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
else if (_do_flow == 3 || _do_flow == 4)
{ // sEPD event plane extraction
// get event plane map
EventplaneinfoMap *epmap = findNode::getClass<EventplaneinfoMap>(topNode, "EventplaneinfoMap");
if (!epmap)
{
std::cout << "DetermineTowerBackground::process_event: FATAL, EventplaneinfoMap does not exist, cannot extract sEPD flow with do_flow = " << _do_flow << std::endl;
exit(-1);
}
else if (_do_flow == 3 || _do_flow == 4)
{ // sEPD event plane extraction
// get event plane map
EventplaneinfoMap *epmap = findNode::getClass<EventplaneinfoMap>(topNode, "EventplaneinfoMap");
if (!epmap)
{
std::cout << "DetermineTowerBackground::process_event: FATAL, EventplaneinfoMap does not exist, cannot extract sEPD flow with do_flow = " << _do_flow << std::endl;
return Fun4AllReturnCodes::ABORTRUN;
}

if (!(epmap->empty()))
{
auto *EPDNS = epmap->get(EventplaneinfoMap::sEPDNS);
_Psi2 = EPDNS->get_shifted_psi(2);
}
else
{
_is_flow_failure = true;
_Psi2 = 0;
}

if (Verbosity() > 0)
{
std::cout << "DetermineTowerBackground::process_event: flow extracted from sEPD, setting Psi2 = " << _Psi2 << " ( " << _Psi2 / M_PI << " * pi ) " << std::endl;
}

}
Comment on lines +594 to +619
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Major: exit(-1) in process_event bypasses error handling.

Line 606 calls exit(-1) when EventplaneinfoMap is missing. This immediately terminates the process, bypassing Fun4All's error handling infrastructure. Return Fun4AllReturnCodes::ABORTRUN instead to allow graceful shutdown and proper cleanup.

🔧 Fix error handling
       if (!epmap)
         {
           std::cout << "DetermineTowerBackground::process_event: FATAL, EventplaneinfoMap does not exist, cannot extract sEPD flow with do_flow = " << _do_flow << std::endl;
-          exit(-1);
+          return Fun4AllReturnCodes::ABORTRUN;
         }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
else if (_do_flow == 3 || _do_flow == 4)
{ // sEPD event plane extraction
// get event plane map
EventplaneinfoMap *epmap = findNode::getClass<EventplaneinfoMap>(topNode, "EventplaneinfoMap");
if (!epmap)
{
std::cout << "DetermineTowerBackground::process_event: FATAL, EventplaneinfoMap does not exist, cannot extract sEPD flow with do_flow = " << _do_flow << std::endl;
exit(-1);
}
if (!(epmap->empty()))
{
auto *EPDNS = epmap->get(EventplaneinfoMap::sEPDNS);
_Psi2 = EPDNS->get_shifted_psi(2);
}
else
{
_is_flow_failure = true;
_Psi2 = 0;
}
if (Verbosity() > 0)
{
std::cout << "DetermineTowerBackground::process_event: flow extracted from sEPD, setting Psi2 = " << _Psi2 << " ( " << _Psi2 / M_PI << " * pi ) " << std::endl;
}
}
else if (_do_flow == 3 || _do_flow == 4)
{ // sEPD event plane extraction
// get event plane map
EventplaneinfoMap *epmap = findNode::getClass<EventplaneinfoMap>(topNode, "EventplaneinfoMap");
if (!epmap)
{
std::cout << "DetermineTowerBackground::process_event: FATAL, EventplaneinfoMap does not exist, cannot extract sEPD flow with do_flow = " << _do_flow << std::endl;
return Fun4AllReturnCodes::ABORTRUN;
}
if (!(epmap->empty()))
{
auto *EPDNS = epmap->get(EventplaneinfoMap::sEPDNS);
_Psi2 = EPDNS->get_shifted_psi(2);
}
else
{
_is_flow_failure = true;
_Psi2 = 0;
}
if (Verbosity() > 0)
{
std::cout << "DetermineTowerBackground::process_event: flow extracted from sEPD, setting Psi2 = " << _Psi2 << " ( " << _Psi2 / M_PI << " * pi ) " << std::endl;
}
}


if ( _do_flow >= 1 && _do_flow < 4)
{

if (Verbosity() > 0)
Expand Down Expand Up @@ -754,88 +903,6 @@ int DetermineTowerBackground::process_event(PHCompositeNode *topNode)
{ // Calo event plane
_Psi2 = std::atan2(Q_y, Q_x) / 2.0;
}
else if (_do_flow == 2)
{ // HIJING truth flow extraction
PHG4TruthInfoContainer *truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode, "G4TruthInfo");

if (!truthinfo)
{
std::cout << "DetermineTowerBackground::process_event: FATAL , G4TruthInfo does not exist , cannot extract truth flow with do_flow = " << _do_flow << std::endl;
return -1;
}

PHG4TruthInfoContainer::Range range = truthinfo->GetPrimaryParticleRange();

float Hijing_Qx = 0;
float Hijing_Qy = 0;

for (PHG4TruthInfoContainer::ConstIterator iter = range.first; iter != range.second; ++iter)
{
PHG4Particle *g4particle = iter->second;

if (truthinfo->isEmbeded(g4particle->get_track_id()) != 0)
{
continue;
}

TLorentzVector t;
t.SetPxPyPzE(g4particle->get_px(), g4particle->get_py(), g4particle->get_pz(), g4particle->get_e());

float truth_pt = t.Pt();
if (truth_pt < 0.4)
{
continue;
}
float truth_eta = t.Eta();
if (std::fabs(truth_eta) > 1.1)
{
continue;
}
float truth_phi = t.Phi();
int truth_pid = g4particle->get_pid();

if (Verbosity() > 10)
{
std::cout << "DetermineTowerBackground::process_event: determining truth flow, using particle w/ pt / eta / phi " << truth_pt << " / " << truth_eta << " / " << truth_phi << " , embed / PID = " << truthinfo->isEmbeded(g4particle->get_track_id()) << " / " << truth_pid << std::endl;
}

Hijing_Qx += truth_pt * std::cos(2 * truth_phi);
Hijing_Qy += truth_pt * std::sin(2 * truth_phi);
}

_Psi2 = std::atan2(Hijing_Qy, Hijing_Qx) / 2.0;

if (Verbosity() > 0)
{
std::cout << "DetermineTowerBackground::process_event: flow extracted from Hijing truth particles, setting Psi2 = " << _Psi2 << " ( " << _Psi2 / M_PI << " * pi ) " << std::endl;
}
}
else if (_do_flow == 3)
{ // sEPD event plane extraction
// get event plane map
EventplaneinfoMap *epmap = findNode::getClass<EventplaneinfoMap>(topNode, "EventplaneinfoMap");
if (!epmap)
{
std::cout << "DetermineTowerBackground::process_event: FATAL, EventplaneinfoMap does not exist, cannot extract sEPD flow with do_flow = " << _do_flow << std::endl;
exit(-1);
}
if (!(epmap->empty()))
{
auto *EPDNS = epmap->get(EventplaneinfoMap::sEPDNS);
_Psi2 = EPDNS->get_shifted_psi(2);
}
else
{
_is_flow_failure = true;
_Psi2 = 0;
}

if (Verbosity() > 0)
{
std::cout << "DetermineTowerBackground::process_event: flow extracted from sEPD, setting Psi2 = " << _Psi2 << " ( " << _Psi2 / M_PI << " * pi ) " << std::endl;
}

}

if (std::isnan(_Psi2) || std::isinf(_Psi2))
{
Expand Down Expand Up @@ -890,7 +957,30 @@ int DetermineTowerBackground::process_event(PHCompositeNode *topNode)
std::cout << "DetermineTowerBackground::process_event: flow extraction successful, Psi2 = " << _Psi2 << " ( " << _Psi2 / M_PI << " * pi ) , v2 = " << _v2 << std::endl;
}
} // if do flow
else if (_do_flow == 4)
{

CentralityInfo *centinfo = findNode::getClass<CentralityInfo>(topNode, "CentralityInfo");

if (!centinfo)
{
std::cout << "DetermineTowerBackground::process_event: FATAL, CentralityInfo does not exist, cannot extract centrality with do_flow = " << _do_flow << std::endl;
exit(-1);
}

int centrality_bin = centinfo->get_centrality_bin(CentralityInfo::PROP::mbd_NS);

if (centrality_bin > 0 && centrality_bin < 95)
{
_v2 = _CENTRALITY_V2[centrality_bin];
}
else
{
_v2 = 0;
_is_flow_failure = true;
_Psi2 = 0;
}
}
Comment on lines +948 to +971
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# First, let's locate and examine the file
find . -name "DetermineTowerBackground.cc" -type f

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 138


🏁 Script executed:

#!/bin/bash
# Let's read the relevant section to understand context
cat -n offline/packages/jetbackground/DetermineTowerBackground.cc | sed -n '930,980p'

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 1837


🏁 Script executed:

#!/bin/bash
# Search for exit() usage patterns in this file to understand conventions
rg -n "exit\(" offline/packages/jetbackground/DetermineTowerBackground.cc

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 282


🏁 Script executed:

#!/bin/bash
# Search for Fun4AllReturnCodes usage pattern in the file
rg -n "Fun4AllReturnCodes" offline/packages/jetbackground/DetermineTowerBackground.cc

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 385


🏁 Script executed:

#!/bin/bash
# Find LoadCalibrations to understand _CENTRALITY_V2 initialization
rg -n "LoadCalibrations\|_CENTRALITY_V2" offline/packages/jetbackground/DetermineTowerBackground.cc

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 60


🏁 Script executed:

#!/bin/bash
# Search for centrality bin range documentation or comments
rg -n -B5 -A5 "centrality.*bin|CENTRALITY.*V2" offline/packages/jetbackground/DetermineTowerBackground.cc | head -80

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 964


🏁 Script executed:

#!/bin/bash
# Search for get_centrality_bin implementation and any documentation
rg -n "get_centrality_bin|centrality.*bin.*valid|bin.*0.*invalid" --type=cc --type=h | head -40

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 104


🏁 Script executed:

#!/bin/bash
# Search for other uses of centrality_bin range checks in the codebase
rg -n "centrality_bin.*<|centrality_bin.*>" --type=cc --type=h -C2 | head -60

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 104


🏁 Script executed:

#!/bin/bash
# Check CentralityInfo class definition for get_centrality_bin
find . -name "*.h" -type f | xargs grep -l "CentralityInfo" | head -5

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 327


🏁 Script executed:

#!/bin/bash
# Look for any documentation or comments about bin ranges
rg -n "centrality.*bin.*range|bin.*95|bin.*0.*invalid" --type=cc --type=h

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 104


🏁 Script executed:

#!/bin/bash
# Search for centrality_bin usage without type restriction
rg -n "centrality_bin.*<|centrality_bin.*>" -C2 | head -80

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 1322


🏁 Script executed:

#!/bin/bash
# Look at CentralityInfo.h to understand get_centrality_bin
cat -n ./offline/packages/centrality/CentralityInfo.h | head -100

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 2414


🏁 Script executed:

#!/bin/bash
# Look at CentralityInfov1.h for implementation details
cat -n ./offline/packages/centrality/CentralityInfov1.h | head -150

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 1361


🏁 Script executed:

#!/bin/bash
# Search for bin 0 or bin 95+ context in the codebase
rg -n "bin.*==.*0|bin.*95|bin.*99" -C2 | grep -A2 -B2 "centrality" | head -60

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 2096


🏁 Script executed:

#!/bin/bash
# Look for CentralityInfov2 to see full implementation
cat -n ./offline/packages/centrality/CentralityInfov2.h 2>/dev/null | head -80

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 1089


🏁 Script executed:

#!/bin/bash
# Search for any documentation about bin 0 or the 95 boundary
rg -n "bin.*0|centrality.*100|centrality.*valid" | grep -i "cent\|bin" | head -40

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 4895


🏁 Script executed:

#!/bin/bash
# Check other modules using centrality_bin to understand expected range
rg -n "get_centrality_bin\|centrality_bin.*=" -A3 -B1 | head -100

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 60


🏁 Script executed:

#!/bin/bash
# Look for calibration or setup documentation about the 95 boundary
rg -n "95\|CENTRALITY_V2" -C3 | head -80

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 60


🏁 Script executed:

#!/bin/bash
# Look for any comments in the code about centrality bin ranges or calibration
cat -n ./offline/packages/jetbackground/DetermineTowerBackground.cc | sed -n '40,120p'

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 2422


🏁 Script executed:

#!/bin/bash
# Search for where _CENTRALITY_V2 is used or referenced
rg -n "_CENTRALITY_V2" -B3 -A3

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 2228


🏁 Script executed:

#!/bin/bash
# Look for any comments in initialization about bin ranges
cat -n ./offline/packages/jetbackground/DetermineTowerBackground.cc | sed -n '80,110p'

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 1020


Replace exit(-1) with proper error return code.

Line 956 calls exit(-1) when CentralityInfo is missing. Replace with return Fun4AllReturnCodes::ABORTRUN to align with the error handling pattern used elsewhere in the file (e.g., line 68).

Additionally, the centrality bin validation at line 961 restricts usage to bins 1–94, but LoadCalibrations populates all 100 bins (0–99). Verify whether bins 0 and 95–99 are intentionally excluded (e.g., reserved or uncalibrated) or if this range restriction should be widened.

Proposed fix for exit() call
   else if (_do_flow == 4)
     {
 
       CentralityInfo *centinfo = findNode::getClass<CentralityInfo>(topNode, "CentralityInfo");
       
       if (!centinfo)
 	{
 	  std::cout << "DetermineTowerBackground::process_event: FATAL, CentralityInfo does not exist, cannot extract centrality with do_flow = " << _do_flow << std::endl;
-	  exit(-1);
+	  return Fun4AllReturnCodes::ABORTRUN;
 	}


// now calculate energy densities...
_nTowers = 0; // store how many towers were used to determine bkg
Expand Down
14 changes: 13 additions & 1 deletion offline/packages/jetbackground/DetermineTowerBackground.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <jetbase/Jet.h>
#include <string>
#include <vector>
#include <array>

// forward declarations
class PHCompositeNode;
Expand All @@ -37,7 +38,11 @@ class DetermineTowerBackground : public SubsysReco
void SetBackgroundOutputName(const std::string &name) { _backgroundName = name; }
void SetSeedType(int seed_type) { _seed_type = seed_type; }
void SetFlow(int do_flow) { _do_flow = do_flow; };

void SetOverwriteCaloV2(std::string &url)
{
m_overwrite_average_calo_v2 = true;
m_overwrite_average_calo_v2_path = url;
}
void SetSeedJetD(float D) { _seed_jet_D = D; };
void SetSeedJetPt(float pt) { _seed_jet_pt = pt; };
void SetSeedMaxConst(float max_const) { _seed_max_const = max_const; };
Expand All @@ -55,6 +60,13 @@ class DetermineTowerBackground : public SubsysReco
int CreateNode(PHCompositeNode *topNode);
void FillNode(PHCompositeNode *topNode);

int LoadCalibrations();

std::vector<float> _CENTRALITY_V2;
std::string m_calibName = "JET_AVERAGE_CALO_V2_SEPD_PSI2";
bool m_overwrite_average_calo_v2{false};
std::string m_overwrite_average_calo_v2_path;

int _do_flow{0};
float _v2{0};
float _Psi2{0};
Expand Down
3 changes: 3 additions & 0 deletions offline/packages/jetbackground/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ libjetbackground_la_LDFLAGS = \
libjetbackground_la_LIBADD = \
libjetbackground_io.la \
-lcalo_io \
-lcentrality_io \
-lcdbobjects \
-lConstituentSubtractor \
-leventplaneinfo_io \
-lglobalvertex \
Expand All @@ -33,6 +35,7 @@ libjetbackground_la_LIBADD = \
-lphg4hit \
-lphparameter \
-lqautils \
-lffamodules \
-lSubsysReco

pkginclude_HEADERS = \
Expand Down