Skip to content

Commit

Permalink
Fix underflow/overflow in EcalVeto's closest cell calc
Browse files Browse the repository at this point in the history
  • Loading branch information
tvami committed Aug 26, 2024
1 parent 9d6b1d5 commit 2e2dbd3
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions Ecal/src/Ecal/EcalVetoProcessor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -659,23 +659,32 @@ void EcalVetoProcessor::produce(framework::Event &event) {
faceXY[1] = -9999.0;
}

int inside = 0;
int up = 0;
int step = 0;
int index;
float cell_radius = 5.0;

std::vector<float>::iterator it;
it = std::lower_bound(mapsx.begin(), mapsx.end(), faceXY[0]);

index = std::distance(mapsx.begin(), it);

if (index == mapsx.size()) {
index += -1;
// If the electron is outside the ECAL volume in X, return the default -9999.0
if (faceXY[0] < mapsx[0] - cell_radius ||
faceXY[0] > mapsx.back() + cell_radius) {
faceXY[0] != -9999.0;
}

bool inside{false};
int up{0};
int step{0};
unsigned int index{0};

// Make sure the recoil electron is inside the ECAL cells
if (!recoilP.empty() && faceXY[0] != -9999.0) {
while (true) {
std::vector<float>::iterator it;
// Find the iterator to the closest cell
it = std::lower_bound(mapsx.begin(), mapsx.end(), faceXY[0]);
// Check how far it is from the first element of the cell map
index = std::distance(mapsx.begin(), it);
// decrease the index to access the last element
if (index == mapsx.size()) {
index += -1;
}
bool underFlow = ((index + step) < 0);
bool overFlow = ((index + step) > mapsx.size() - 1);
while (underFlow || overFlow) {
std::vector<double> dis(2);

dis[0] = faceXY[0] - mapsx[index + step];
Expand All @@ -684,7 +693,7 @@ void EcalVetoProcessor::produce(framework::Event &event) {
float celldis = sqrt(pow(dis[0], 2) + pow(dis[1], 2));

if (celldis <= cell_radius) {
inside = 1;
inside = true;
break;
}

Expand Down

0 comments on commit 2e2dbd3

Please sign in to comment.