Skip to content

Commit

Permalink
Fix in CTPRunScalers::getRate
Browse files Browse the repository at this point in the history
  • Loading branch information
shahor02 committed Dec 18, 2024
1 parent d4f11dc commit 789968c
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions DataFormats/Detectors/CTP/src/Scalers.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -674,35 +674,35 @@ std::pair<double, double> CTPRunScalers::getRate(uint32_t orbit, int classindex,

// then we can use binary search to find the right entries
auto iter = std::lower_bound(mScalerRecordO2.begin(), mScalerRecordO2.end(), orbit, [&](CTPScalerRecordO2 const& a, uint32_t value) { return a.intRecord.orbit <= value; });
auto nextindex = iter - mScalerRecordO2.begin(); // this points to the first index that has orbit greater or equal to given orbit
auto nextindex = std::distance(mScalerRecordO2.begin(), iter); // this points to the first index that has orbit greater or equal to given orbit

auto calcRate = [&](auto index1, auto index2) -> double {
auto next = &mScalerRecordO2[index2];
auto prev = &mScalerRecordO2[index1];
auto timedelta = (next->intRecord.orbit - prev->intRecord.orbit) * 88.e-6; // converts orbits into time
const auto& snext = mScalerRecordO2[index2];
const auto& sprev = mScalerRecordO2[index1];
auto timedelta = (snext.intRecord.orbit - sprev.intRecord.orbit) * 88.e-6; // converts orbits into time
if (type < 7) {
auto s0 = &(prev->scalers[classindex]); // type CTPScalerO2*
auto s1 = &(next->scalers[classindex]);
const auto& s0 = sprev.scalers[classindex]; // type CTPScalerO2*
const auto& s1 = snext.scalers[classindex];
switch (type) {
case 1:
return (s1->lmBefore - s0->lmBefore) / timedelta;
return (s1.lmBefore - s0.lmBefore) / timedelta;
case 2:
return (s1->lmAfter - s0->lmAfter) / timedelta;
return (s1.lmAfter - s0.lmAfter) / timedelta;
case 3:
return (s1->l0Before - s0->l0Before) / timedelta;
return (s1.l0Before - s0.l0Before) / timedelta;
case 4:
return (s1->l0After - s0->l0After) / timedelta;
return (s1.l0After - s0.l0After) / timedelta;
case 5:
return (s1->l1Before - s0->l1Before) / timedelta;
return (s1.l1Before - s0.l1Before) / timedelta;
case 6:
return (s1->l1After - s0->l1After) / timedelta;
return (s1.l1After - s0.l1After) / timedelta;
default:
LOG(error) << "Wrong type:" << type;
return -1; // wrong type
}
} else if (type == 7) {
auto s0 = &(prev->scalersInps[classindex]); // type CTPScalerO2*
auto s1 = &(next->scalersInps[classindex]);
auto s0 = sprev.scalersInps[classindex]; // type CTPScalerO2*
auto s1 = snext.scalersInps[classindex];
return (s1 - s0) / timedelta;
} else {
LOG(error) << "Wrong type:" << type;
Expand Down Expand Up @@ -738,37 +738,37 @@ std::pair<double, double> CTPRunScalers::getRateGivenT(double timestamp, int cla
// this points to the first index that has orbit greater to given orbit;
// If this is 0, it means that the above condition was false from the beginning, basically saying that the timestamp is below any of the ScalerRecords' orbits.
// If this is mScalerRecordO2.size(), it means mScalerRecordO2.end() was returned, condition was met throughout all ScalerRecords, basically saying the timestamp is above any of the ScalarRecordss orbits.
auto nextindex = iter - mScalerRecordO2.begin();
auto nextindex = std::distance(mScalerRecordO2.begin(), iter);

auto calcRate = [&](auto index1, auto index2) -> double {
auto next = &mScalerRecordO2[index2];
auto prev = &mScalerRecordO2[index1];
auto timedelta = (next->intRecord.orbit - prev->intRecord.orbit) * 88.e-6; // converts orbits into time
const auto& snext = mScalerRecordO2[index2];
const auto& sprev = mScalerRecordO2[index1];
auto timedelta = (snext.intRecord.orbit - sprev.intRecord.orbit) * 88.e-6; // converts orbits into time
// std::cout << "timedelta:" << timedelta << std::endl;
if (type < 7) {
auto s0 = &(prev->scalers[classindex]); // type CTPScalerO2*
auto s1 = &(next->scalers[classindex]);
const auto& s0 = sprev.scalers[classindex]; // type CTPScalerO2*
const auto& s1 = snext.scalers[classindex];
switch (type) {
case 1:
return (s1->lmBefore - s0->lmBefore) / timedelta;
return (s1.lmBefore - s0.lmBefore) / timedelta;
case 2:
return (s1->lmAfter - s0->lmAfter) / timedelta;
return (s1.lmAfter - s0.lmAfter) / timedelta;
case 3:
return (s1->l0Before - s0->l0Before) / timedelta;
return (s1.l0Before - s0.l0Before) / timedelta;
case 4:
return (s1->l0After - s0->l0After) / timedelta;
return (s1.l0After - s0.l0After) / timedelta;
case 5:
return (s1->l1Before - s0->l1Before) / timedelta;
return (s1.l1Before - s0.l1Before) / timedelta;
case 6:
return (s1->l1After - s0->l1After) / timedelta;
return (s1.l1After - s0.l1After) / timedelta;
default:
LOG(error) << "Wrong type:" << type;
return -1; // wrong type
}
} else if (type == 7) {
// LOG(info) << "doing input:";
auto s0 = prev->scalersInps[classindex]; // type CTPScalerO2*
auto s1 = next->scalersInps[classindex];
auto s0 = sprev.scalersInps[classindex]; // type CTPScalerO2*
auto s1 = snext.scalersInps[classindex];
return (s1 - s0) / timedelta;
} else {
LOG(error) << "Wrong type:" << type;
Expand Down

0 comments on commit 789968c

Please sign in to comment.