Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions Generators/include/Generators/PrimaryGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class PrimaryGenerator : public FairPrimaryGenerator
/** Public embedding methods **/
Bool_t embedInto(TString fname);

/// sets the embedding index
void setEmbedIndex(int idx) { mEmbedIndex = idx; }

void setExternalVertexForNextEvent(double x, double y, double z);

// sets the vertex mode; if mode is kCCDB, a valid MeanVertexObject pointer must be given at the same time
Expand Down
25 changes: 13 additions & 12 deletions Generators/src/PrimaryGenerator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Bool_t PrimaryGenerator::GenerateEvent(FairGenericStack* pStack)
/** generate event **/

/** normal generation if no embedding **/
if (!mEmbedTree) {
if (!mEmbedTree || mEmbedIndex < 0) {
fixInteractionVertex(); // <-- always fixes vertex outside of FairROOT
auto ret = FairPrimaryGenerator::GenerateEvent(pStack);
if (ret) {
Expand All @@ -91,17 +91,18 @@ Bool_t PrimaryGenerator::GenerateEvent(FairGenericStack* pStack)
}

/** this is for embedding **/

/** setup interaction vertex **/
mEmbedTree->GetEntry(mEmbedIndex);
setInteractionVertex(mEmbedEvent);

/** notify event generators **/
auto genList = GetListOfGenerators();
for (int igen = 0; igen < genList->GetEntries(); ++igen) {
auto o2gen = dynamic_cast<Generator*>(genList->At(igen));
if (o2gen) {
o2gen->notifyEmbedding(mEmbedEvent);
if (mEmbedIndex >= 0) {
/** setup interaction vertex **/
mEmbedTree->GetEntry(mEmbedIndex);
setInteractionVertex(mEmbedEvent);

/** notify event generators **/
auto genList = GetListOfGenerators();
for (int igen = 0; igen < genList->GetEntries(); ++igen) {
auto o2gen = dynamic_cast<Generator*>(genList->At(igen));
if (o2gen) {
o2gen->notifyEmbedding(mEmbedEvent);
}
}
}

Expand Down
26 changes: 26 additions & 0 deletions run/O2PrimaryServerDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <chrono>
#include <CCDB/BasicCCDBManager.h>
#include <TRandom3.h>
#include <regex>

namespace o2
{
Expand Down Expand Up @@ -135,6 +136,17 @@ class O2PrimaryServerDevice final : public fair::mq::Device

auto embedinto_filename = conf.getEmbedIntoFileName();
if (!embedinto_filename.empty()) {
// determine the sim prefix from the embedding filename
// the filename should be an MCHeader file ... so it should match SOME_PATH/prefix_MCHeader.root
std::regex re(R"((.*/)?([^/]+)_MCHeader\.root$)");
std::smatch match;

if (std::regex_search(embedinto_filename, match, re)) {
std::cout << "Extracted embedding prefix : " << match[2] << '\n';
mEmbeddIntoPrefix = match[2];
} else {
LOG(fatal) << "Embedding asked but no suitable embedding prefix extractable from " << embedinto_filename;
}
mPrimGen->embedInto(embedinto_filename);
}

Expand Down Expand Up @@ -197,6 +209,19 @@ class O2PrimaryServerDevice final : public fair::mq::Device
auto& vertex = vertices.at(collisionindex);
LOG(info) << "Setting vertex " << vertex << " for event " << mEventCounter << " for prefix " << mSimConfig.getOutPrefix() << " from CollContext";
mPrimGen->setExternalVertexForNextEvent(vertex.X(), vertex.Y(), vertex.Z());

// set correct embedding index for PrimaryGenerator ... based on collision context for embedding
auto& collisionParts = mCollissionContext->getEventParts()[collisionindex];
int background_index = -1; // -1 means no embedding taking place for this signal

// find the part that corresponds to the event embeded into
for (auto& part : collisionParts) {
if (mCollissionContext->getSimPrefixes()[part.sourceID] == mEmbeddIntoPrefix) {
background_index = part.entryID;
LOG(info) << "Setting embedding index to " << background_index;
}
}
mPrimGen->setEmbedIndex(background_index);
}
}
mPrimGen->GenerateEvent(mStack);
Expand Down Expand Up @@ -696,6 +721,7 @@ class O2PrimaryServerDevice final : public fair::mq::Device
// some information specific to use case when we have a collision context
o2::steer::DigitizationContext* mCollissionContext = nullptr; //!
std::unordered_map<int, int> mEventID_to_CollID; //!
std::string mEmbeddIntoPrefix; //! sim prefix of background events

TRandom3 mSeedGenerator; //! specific random generator for seed generation for work chunks
};
Expand Down