Skip to content
Merged
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
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];
Comment on lines +704 to +705
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@lietava the real bug was here (the address of the counter was taken instead of its value) the rest is cosmetics.

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
Loading