Skip to content

Commit 6a11361

Browse files
sawenzelclaude
andcommitted
Let the TPC looper generator accept a timeframe without collisions
This fixes a problem in GenTPCLoopers::setFlatGas when the collision context of a timeframe is empty. - A timeframe holds no collision whenever the interaction rate is low enough, and the generator called exit(1) on it. - The extent of the timeframe now comes from HBFUtils in that case, which is where it is defined, instead of from the last collision. - With a single collision in the timeframe the mean interaction spacing was divided by zero; it is now taken from the interaction rate stored in the collision context. https://its.cern.ch/jira/browse/O2-7132 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 0e69731 commit 6a11361

1 file changed

Lines changed: 24 additions & 12 deletions

File tree

Generators/src/TPCLoopers.cxx

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -444,23 +444,35 @@ void GenTPCLoopers::setFlatGas(Bool_t flat, Int_t number, Int_t nloopers_orbit)
444444
mContextFile = std::filesystem::exists("collisioncontext.root") ? TFile::Open("collisioncontext.root") : nullptr;
445445
mCollisionContext = mContextFile ? (o2::steer::DigitizationContext*)mContextFile->Get("DigitizationContext") : nullptr;
446446
mInteractionTimeRecords = mCollisionContext ? mCollisionContext->getEventRecords() : std::vector<o2::InteractionTimeRecord>{};
447+
const auto& hbfUtils = o2::raw::HBFUtils::Instance();
447448
if (mInteractionTimeRecords.empty()) {
448-
LOG(error) << "Error: No interaction time records found in the collision context!";
449-
exit(1);
449+
// A timeframe can legitimately contain no collision at all when the interaction rate is
450+
// low. No event is transported in that case, so nothing below is ever used; take the
451+
// extent of the timeframe from HBFUtils rather than from the (absent) collisions.
452+
LOG(warn) << "No interaction time records in the collision context; this timeframe holds no collision";
453+
o2::InteractionRecord tfEndIR(0, hbfUtils.orbitFirstSampled + hbfUtils.nHBFPerTF);
454+
mTimeEnd = tfEndIR.bc2ns();
450455
} else {
451456
LOG(info) << "Interaction Time records has " << mInteractionTimeRecords.size() << " entries.";
452457
mCollisionContext->printCollisionSummary();
458+
for (int c = 0; c < (int)mInteractionTimeRecords.size() - 1; c++) {
459+
mIntTimeRecMean += mInteractionTimeRecords[c + 1].bc2ns() - mInteractionTimeRecords[c].bc2ns();
460+
}
461+
if (mInteractionTimeRecords.size() > 1) {
462+
mIntTimeRecMean /= (mInteractionTimeRecords.size() - 1); // Average interaction time record used as reference
463+
} else {
464+
// a single collision gives no spacing to average; use the one implied by the rate
465+
auto rate = mCollisionContext->getDigitizerInteractionRate();
466+
mIntTimeRecMean = rate > 0. ? 1.e9 / rate : (double)o2::constants::lhc::LHCOrbitNS;
467+
LOG(info) << "Only one collision in this timeframe; taking " << mIntTimeRecMean
468+
<< " ns as the mean interaction spacing from the interaction rate";
469+
}
470+
// Get the start time of the second orbit after the last interaction record
471+
const auto& lastIR = mInteractionTimeRecords.back();
472+
o2::InteractionRecord finalOrbitIR(0, lastIR.orbit + 2); // Final orbit, BC = 0
473+
mTimeEnd = finalOrbitIR.bc2ns();
474+
LOG(debug) << "Final orbit start time: " << mTimeEnd << " ns while last interaction record time is " << mInteractionTimeRecords.back().bc2ns() << " ns";
453475
}
454-
for (int c = 0; c < mInteractionTimeRecords.size() - 1; c++) {
455-
mIntTimeRecMean += mInteractionTimeRecords[c + 1].bc2ns() - mInteractionTimeRecords[c].bc2ns();
456-
}
457-
mIntTimeRecMean /= (mInteractionTimeRecords.size() - 1); // Average interaction time record used as reference
458-
const auto& hbfUtils = o2::raw::HBFUtils::Instance();
459-
// Get the start time of the second orbit after the last interaction record
460-
const auto& lastIR = mInteractionTimeRecords.back();
461-
o2::InteractionRecord finalOrbitIR(0, lastIR.orbit + 2); // Final orbit, BC = 0
462-
mTimeEnd = finalOrbitIR.bc2ns();
463-
LOG(debug) << "Final orbit start time: " << mTimeEnd << " ns while last interaction record time is " << mInteractionTimeRecords.back().bc2ns() << " ns";
464476
}
465477
} else {
466478
mFlatGasNumber = -1;

0 commit comments

Comments
 (0)