Skip to content

Commit

Permalink
Avoid empty events to be generated
Browse files Browse the repository at this point in the history
  • Loading branch information
sawenzel committed Nov 10, 2023
1 parent 1729c33 commit 03c0567
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions run/O2PrimaryServerDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,33 @@ class O2PrimaryServerDevice final : public fair::mq::Device
TStopwatch timer;
timer.Start();
try {
mStack->Reset();
// see if we the vertex comes from the collision context
if (mCollissionContext) {
const auto& vertices = mCollissionContext->getInteractionVertices();
if (vertices.size() > 0) {
auto collisionindex = mEventID_to_CollID.at(mEventCounter);
auto& vertex = vertices.at(collisionindex);
LOG(info) << "Setting vertex " << vertex << " for event " << mEventCounter << " for prefix " << mSimConfig.getOutPrefix();
mPrimGen->setExternalVertexForNextEvent(vertex.X(), vertex.Y(), vertex.Z());
bool valid = false;
int retry_counter = 0;
const int MAX_RETRY = 100;
do {
mStack->Reset();
// see if we the vertex comes from the collision context
if (mCollissionContext) {
const auto& vertices = mCollissionContext->getInteractionVertices();
if (vertices.size() > 0) {
auto collisionindex = mEventID_to_CollID.at(mEventCounter);
auto& vertex = vertices.at(collisionindex);
LOG(info) << "Setting vertex " << vertex << " for event " << mEventCounter << " for prefix " << mSimConfig.getOutPrefix();
mPrimGen->setExternalVertexForNextEvent(vertex.X(), vertex.Y(), vertex.Z());
}
}
}
mPrimGen->GenerateEvent(mStack);
mPrimGen->GenerateEvent(mStack);
if (mStack->getPrimaries().size() > 0) {
valid = true;
} else {
retry_counter++;
if (retry_counter > MAX_RETRY) {
LOG(warn) << "Not able to generate a non-empty event in " << MAX_RETRY << " trials";
// empty event is sent out
valid = true;
}
}
} while (!valid);
} catch (std::exception const& e) {
LOG(error) << " Exception occurred during event gen " << e.what();
}
Expand Down

0 comments on commit 03c0567

Please sign in to comment.