Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 10 additions & 2 deletions offline/packages/jetbackground/RetowerCEMC.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,15 @@ int RetowerCEMC::process_event(PHCompositeNode *topNode)
}
else
{
towerinfo->set_energy(retower_e_temp / (double) (1 - scalefactor));
if (_do_rescale)
{
towerinfo->set_energy(retower_e_temp / (double) (1 - scalefactor));
}
else
{
towerinfo->set_energy(retower_e_temp);
}

if (retower_e_temp == 0)
{
towerinfo->set_time(0);
Expand All @@ -154,8 +162,8 @@ int RetowerCEMC::process_event(PHCompositeNode *topNode)
{
towerinfo->set_time((retower_time_temp / retower_e_temp));
}
towerinfo->set_chi2(scalefactor);
}
towerinfo->set_chi2(scalefactor); // store the fraction of bad towers as the chi2
}
}
}
Expand Down
28 changes: 15 additions & 13 deletions offline/packages/jetbackground/RetowerCEMC.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class RetowerCEMC : public SubsysReco

void SetEnergyDistribution(int val) { _weighted_energy_distribution = val; }
void set_frac_cut(double frac_cut) { _frac_cut = frac_cut; }
void set_do_rescale(bool do_rescale) { _do_rescale = do_rescale; }
void set_towerinfo(bool use_towerinfo) { m_use_towerinfo = use_towerinfo; }
void set_towerNodePrefix(const std::string &prefix)
{
Expand All @@ -32,25 +33,26 @@ class RetowerCEMC : public SubsysReco
void get_weighted_fraction(PHCompositeNode *topNode);

int _weighted_energy_distribution{1};
double _frac_cut{0.5};
double _frac_cut{1};
bool _do_rescale{false};
Comment on lines +36 to +37

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
# Verify the impact of the _frac_cut default change on downstream tower usage

# Search for how the retower output is consumed and whether masking behavior matters
rg -nP --type=cc -C3 'TOWER_CALIB_CEMC_RETOWER|CEMC_RETOWER' -g '!RetowerCEMC.cc'

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 105


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# 1) Locate and inspect RetowerCEMC.h around the relevant lines
REPO_ROOT="$(pwd)"
FILE="$(fd -a --full-path 'RetowerCEMC.h' . | head -n 1 || true)"
echo "Found RetowerCEMC.h: $FILE"
if [[ -n "${FILE:-}" ]]; then
  echo "---- RetowerCEMC.h lines 1-120 ----"
  nl -ba "$FILE" | sed -n '1,120p'
fi

# 2) Find all usages of _frac_cut and masking logic
if [[ -n "${FILE:-}" ]]; then
  echo "---- _frac_cut usage ----"
  rg -n "_frac_cut" "$FILE" -C2 || true
  echo "---- _frac_cut usage across repo (limited to likely files) ----"
  rg -n "_frac_cut" -S . | head -n 200
fi

# 3) Find strings for retower outputs and downstream consumption
echo "---- Search for retower output consumers ----"
rg -n --hidden --no-ignore-vcs -S 'TOWER_CALIB_CEMC_RETOWER|CEMC_RETOWER' . | head -n 200

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 261


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# 1) Locate and inspect RetowerCEMC.h around the relevant lines
REPO_ROOT="$(pwd)"
FILE="$(fd -a --full-path 'RetowerCEMC.h' . | head -n 1 || true)"
echo "Found RetowerCEMC.h: $FILE"
if [[ -n "${FILE:-}" ]]; then
  echo "---- RetowerCEMC.h lines 1-120 ----"
  nl -ba "$FILE" | sed -n '1,120p'
fi

# 2) Find all usages of _frac_cut and masking logic
if [[ -n "${FILE:-}" ]]; then
  echo "---- _frac_cut usage ----"
  rg -n "_frac_cut" "$FILE" -C2 || true
  echo "---- _frac_cut usage across repo (limited to likely files) ----"
  rg -n "_frac_cut" -S . | head -n 200
fi

# 3) Find strings for retower outputs and downstream consumption
echo "---- Search for retower output consumers ----"
rg -n --hidden --no-ignore-vcs -S 'TOWER_CALIB_CEMC_RETOWER|CEMC_RETOWER' . | head -n 200

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 261


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="$(fd -a --full-path 'RetowerCEMC.h' . | head -n 1 || true)"
echo "Found RetowerCEMC.h: $FILE"
if [[ -n "${FILE:-}" ]]; then
  echo "---- RetowerCEMC.h lines 1-160 ----"
  nl -ba "$FILE" | sed -n '1,160p'
fi

if [[ -n "${FILE:-}" ]]; then
  echo "---- _frac_cut usage (within file) ----"
  rg -n "_frac_cut" "$FILE" -C2 || true
fi

echo "---- _frac_cut usage across repo (first 200 hits) ----"
rg -n "_frac_cut" -S . | head -n 200 || true

echo "---- Retower output identifiers usage (first 200 hits) ----"
rg -n --hidden --no-ignore-vcs -S 'TOWER_CALIB_CEMC_RETOWER|CEMC_RETOWER' . | head -n 200 || true

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 260


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="$(fd -a --full-path 'RetowerCEMC.h' . | head -n 1 || true)"
echo "Found RetowerCEMC.h: $FILE"

if [[ -n "${FILE:-}" ]]; then
  echo "---- RetowerCEMC.h excerpt (1-220) with line numbers ----"
  # Use cat -n (available) instead of nl
  cat -n "$FILE" | sed -n '1,220p'
  echo "---- _frac_cut usage (within file) ----"
  rg -n "_frac_cut" "$FILE" -C3 || true
fi

echo "---- Retower output identifier usage (first 200 hits) ----"
rg -n --hidden --no-ignore-vcs -S 'TOWER_CALIB_CEMC_RETOWER|CEMC_RETOWER' . | head -n 200 || true

echo "---- Any masking-related usage nearby ----"
rg -n --hidden --no-ignore-vcs -S 'mask|masked|bad.*frac|frac_cut|rescale|scalefactor' offline/packages/jetbackground/RetowerCEMC.h 2>/dev/null || true

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 10758


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# locate RetowerCEMC.cc
FILE="$(fd -a --full-path 'RetowerCEMC.cc' . | head -n 1 || true)"
echo "Found RetowerCEMC.cc: $FILE"

if [[ -n "${FILE:-}" ]]; then
  echo "---- RetowerCEMC.cc excerpt around _frac_cut ----"
  rg -n "_frac_cut" "$FILE" -n -C3 || true

  echo "---- Search for scalefactor/rescale/mask/bad area logic ----"
  rg -n --hidden --no-ignore-vcs -S 'scalefactor|rescale|rescal|frac_cut|bad.*area|mask|masked|badFrac|fraction' "$FILE" -C2 || true

  echo "---- Show function(s) that likely use _frac_cut (first few matches) ----"
  # Grab some broader context around the first occurrences
  FIRST=$(rg -n "_frac_cut" "$FILE" | head -n 1 | cut -d: -f1 || true)
  if [[ -n "${FIRST:-}" ]]; then
    START=$((FIRST-80))
    END=$((FIRST+120))
    if (( START<1 )); then START=1; fi
    echo "---- RetowerCEMC.cc lines $START-$END ----"
    sed -n "${START},${END}p" "$FILE" | cat -n
  fi
fi

echo "---- Inspect likely downstream usage: JetBackgroundCut.h and DetermineTowerBackground.cc ----"
for f in offline/packages/jetbackground/JetBackgroundCut.h offline/packages/jetbackground/DetermineTowerBackground.cc offline/packages/jetbase/TowerJetInput.cc; do
  if [[ -f "$f" ]]; then
    echo "### $f"
    rg -n --no-ignore-vcs -S 'TOWERINFO_CALIB_CEMC_RETOWER|TOWER_CALIB_CEMC_RETOWER|m_input_cemc_tower_node|mask|masked|bad|frac_cut|towerinfo' "$f" -C2 || true
  fi
done

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 35273


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="$(fd -a --full-path 'RetowerCEMC.cc' . | head -n 1 || true)"
echo "RetowerCEMC.cc: $FILE"

if [[ -n "${FILE:-}" ]]; then
  # show sections around get_fraction and get_weighted_fraction and retower_totalarea computation
  # We'll locate "void RetowerCEMC::get_fraction" line numbers
  EF=$(rg -n "void RetowerCEMC::get_fraction" "$FILE" | cut -d: -f1 | head -n1 || true)
  EW=$(rg -n "void RetowerCEMC::get_weighted_fraction" "$FILE" | cut -d: -f1 | head -n1 || true)
  echo "get_fraction starts at: ${EF:-N/A}, get_weighted_fraction starts at: ${EW:-N/A}"

  if [[ -n "${EF:-}" ]]; then
    START=$((EF-40)); END=$((EF+140))
    (( START<1 )) && START=1
    echo "---- RetowerCEMC.cc excerpt around get_fraction ($START-$END) ----"
    sed -n "${START},${END}p" "$FILE" | cat -n
  fi

  if [[ -n "${EW:-}" ]]; then
    START=$((EW-40)); END=$((EW+220))
    (( START<1 )) && START=1
    echo "---- RetowerCEMC.cc excerpt around get_weighted_fraction ($START-$END) ----"
    sed -n "${START},${END}p" "$FILE" | cat -n
  fi
fi

echo "---- Locate TowerInfo definitions for set_isHot/get_isGood ----"
# Find TowerInfo.h/cc and relevant methods
TIH="$(fd -a --full-path 'TowerInfo*' . | rg -m 1 -v '/src/' || true)"
echo "Some TowerInfo* match (first): $TIH"

# Use ripgrep for set_isHot and get_isGood in headers
rg -n --hidden --no-ignore-vcs -S 'set_isHot\(|get_isGood\(' . | head -n 50 || true

# Specifically locate TowerInfo class header if present
TOWERINFO_H=$(fd -a --full-path 'TowerInfo.h' . | head -n 5 || true)
echo "TowerInfo.h candidates:"
echo "$TOWERINFO_H" | head -n 5
for f in $TOWERINFO_H; do
  echo "---- excerpt from $f ----"
  rg -n "class TowerInfo|set_isHot|get_isGood" "$f" -n -C2 || true
done

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 18685


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="$(fd -a --full-path 'RetowerCEMC.cc' . | head -n 1 || true)"
echo "RetowerCEMC.cc: $FILE"

if [[ -n "${FILE:-}" ]]; then
  EF=$(rg -n "void RetowerCEMC::get_fraction" "$FILE" | cut -d: -f1 | head -n1 || true)
  EW=$(rg -n "void RetowerCEMC::get_weighted_fraction" "$FILE" | cut -d: -f1 | head -n1 || true)
  echo "get_fraction starts at: ${EF:-N/A}, get_weighted_fraction starts at: ${EW:-N/A}"

  if [[ -n "${EF:-}" ]]; then
    START=$((EF-40)); END=$((EF+160))
    (( START<1 )) && START=1
    echo "---- RetowerCEMC.cc excerpt around get_fraction ($START-$END) ----"
    sed -n "${START},${END}p" "$FILE" | cat -n
  fi

  if [[ -n "${EW:-}" ]]; then
    START=$((EW-40)); END=$((EW+260))
    (( START<1 )) && START=1
    echo "---- RetowerCEMC.cc excerpt around get_weighted_fraction ($START-$END) ----"
    sed -n "${START},${END}p" "$FILE" | cat -n
  fi
fi

echo "---- Locate TowerInfo definitions for set_isHot/get_isGood ----"
# Search for the methods across the repo (limit output)
rg -n --hidden --no-ignore-vcs -S 'set_isHot\(|get_isGood\(' . | head -n 80 || true

# Try common header name
TOWERINFO_H=$(fd -a --full-path 'TowerInfo*.h' . | head -n 20 || true)
echo "TowerInfo*.h candidates (up to 20):"
echo "$TOWERINFO_H" | head -n 20

for f in $TOWERINFO_H; do
  if [[ -f "$f" ]]; then
    if rg -q "class TowerInfo" "$f" || rg -q "set_isHot" "$f" || rg -q "get_isGood" "$f"; then
      echo "---- relevant excerpt from $f ----"
      rg -n "set_isHot|get_isGood" "$f" -C2 || true
    fi
  fi
done

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 18443


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="$(fd -a --full-path 'RetowerCEMC.cc' . | head -n 1 || true)"
echo "RetowerCEMC.cc: $FILE"

if [[ -n "${FILE:-}" ]]; then
  EF=$(rg -n "void RetowerCEMC::get_fraction" "$FILE" | cut -d: -f1 | head -n1 || true)
  EW=$(rg -n "void RetowerCEMC::get_weighted_fraction" "$FILE" | cut -d: -f1 | head -n1 || true)
  echo "get_fraction starts at: ${EF:-N/A}, get_weighted_fraction starts at: ${EW:-N/A}"

  if [[ -n "${EF:-}" ]]; then
    START=$((EF-40)); END=$((EF+160))
    (( START<1 )) && START=1
    echo "---- RetowerCEMC.cc excerpt around get_fraction ($START-$END) ----"
    sed -n "${START},${END}p" "$FILE" | cat -n
  fi

  if [[ -n "${EW:-}" ]]; then
    START=$((EW-40)); END=$((EW+260))
    (( START<1 )) && START=1
    echo "---- RetowerCEMC.cc excerpt around get_weighted_fraction ($START-$END) ----"
    sed -n "${START},${END}p" "$FILE" | cat -n
  fi
fi

echo "---- Locate TowerInfo definitions for set_isHot/get_isGood ----"
# Search for the methods across the repo (limit output)
rg -n --hidden --no-ignore-vcs -S 'set_isHot\(|get_isGood\(' . | head -n 80 || true

# Try common header name
TOWERINFO_H=$(fd -a --full-path 'TowerInfo*.h' . | head -n 20 || true)
echo "TowerInfo*.h candidates (up to 20):"
echo "$TOWERINFO_H" | head -n 20

for f in $TOWERINFO_H; do
  if [[ -f "$f" ]]; then
    if rg -q "class TowerInfo" "$f" || rg -q "set_isHot" "$f" || rg -q "get_isGood" "$f"; then
      echo "---- relevant excerpt from $f ----"
      rg -n "set_isHot|get_isGood" "$f" -C2 || true
    fi
  fi
done

Repository: sPHENIX-Collaboration/coresoftware

Length of output: 18443


Major: Raise of _frac_cut default to 1.0 effectively disables retower masking (behavioral impact)

double _frac_cut{1};
bool _do_rescale{false};

In offline/packages/jetbackground/RetowerCEMC.cc, a (retower) tower is masked only when scalefactor = retower_badarea / retower_totalarea[ieta_ihcal] satisfies scalefactor > _frac_cut; then the code sets towerinfo->set_energy(0) and towerinfo->set_isHot(true) (which makes tower->get_isGood() false in TowerInfov2/4). With _frac_cut now defaulting to 1.0, masking should only occur if scalefactor exceeds ~1 due to numerical effects, so high-bad-area towers will generally remain unmasked and therefore propagate through downstream steps like offline/packages/jetbackground/DetermineTowerBackground.cc, which excludes masked towers via !towerinfo->get_isGood() (and also references E==0 exclusion).

Confirm this intended change in default behavior and that downstream analyses expect towers with large bad-area fractions to remain included; PR description should explicitly state analysis impact and whether reprocessing is required.

bool m_use_towerinfo{false};
std::string m_towerNodePrefix{"TOWERINFO_CALIB"};

static const int neta_ihcal = 24;
static const int neta_emcal = 96;
static const int nphi_ihcal = 64;
static const int nphi_emcal = 256;
static const int neta_ihcal{24};
static const int neta_emcal{96};
static const int nphi_ihcal{64};
static const int nphi_emcal{256};

int retower_lowerbound_originaltower_ieta[neta_ihcal] = {0};
int retower_upperbound_originaltower_ieta[neta_ihcal] = {0};
double retower_lowerbound_originaltower_fraction[neta_ihcal] = {0.0};
double retower_upperbound_originaltower_fraction[neta_ihcal] = {0.0};
double retower_totalarea[neta_ihcal] = {0.0};
int retower_lowerbound_originaltower_ieta[neta_ihcal]{0};
int retower_upperbound_originaltower_ieta[neta_ihcal]{0};
double retower_lowerbound_originaltower_fraction[neta_ihcal]{0.0};
double retower_upperbound_originaltower_fraction[neta_ihcal]{0.0};
double retower_totalarea[neta_ihcal]{0.0};
int retower_first_lowerbound_originaltower_iphi{-1};

double rawtower_e[neta_emcal][nphi_emcal] = {{0.0}};
double rawtower_time[neta_emcal][nphi_emcal] = {{0.0}};
int rawtower_status[neta_emcal][nphi_emcal] = {{0}};
double rawtower_e[neta_emcal][nphi_emcal]{{0.0}};
double rawtower_time[neta_emcal][nphi_emcal]{{0.0}};
int rawtower_status[neta_emcal][nphi_emcal]{{0}};

std::string EMTowerName;
std::string IHTowerName;
Expand Down