Skip to content

Commit adc8cad

Browse files
committed
Digicontext: Several improvements
Work needed for restructuring O2DPG MC workflows towards the use of a globally pre-generated collision context. * fixes for picking up vertices from collision contexts * possibility to generate vertices in CollContextTool from CCDB entry * smaller cleanup relates to https://its.cern.ch/jira/browse/O2-3622
1 parent d0c4891 commit adc8cad

File tree

5 files changed

+62
-28
lines changed

5 files changed

+62
-28
lines changed

Common/SimConfig/include/SimConfig/SimConfig.h

+5
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ struct SimConfigData {
8383
bool mNoGeant = false; // if Geant transport should be turned off (when one is only interested in the generated events)
8484
bool mIsUpgrade = false; // true if the simulation is for Run 5
8585
std::string mFromCollisionContext = ""; // string denoting a collision context file; If given, this file will be used to determine number of events
86+
//
8687
bool mForwardKine = false; // true if tracks and event headers are to be published on a FairMQ channel (for reading by other consumers)
8788
bool mWriteToDisc = true; // whether we write simulation products (kine, hits) to disc
8889
VertexMode mVertexMode = VertexMode::kDiamondParam; // by default we should use die InteractionDiamond parameter
@@ -177,6 +178,10 @@ class SimConfig
177178
bool writeToDisc() const { return mConfigData.mWriteToDisc; }
178179
VertexMode getVertexMode() const { return mConfigData.mVertexMode; }
179180

181+
// returns the pair of collision context filename as well as event prefix encoded
182+
// in the mFromCollisionContext string. Returns empty string if information is not available or set.
183+
std::pair<std::string, std::string> getCollContextFilenameAndEventPrefix() const;
184+
180185
private:
181186
SimConfigData mConfigData; //!
182187

Common/SimConfig/src/SimConfig.cxx

+18-12
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void SimConfig::initOptions(boost::program_options::options_description& options
7676
"noGeant", bpo::bool_switch(), "prohibits any Geant transport/physics (by using tight cuts)")(
7777
"forwardKine", bpo::bool_switch(), "forward kinematics on a FairMQ channel")(
7878
"noDiscOutput", bpo::bool_switch(), "switch off writing sim results to disc (useful in combination with forwardKine)");
79-
options.add_options()("fromCollContext", bpo::value<std::string>()->default_value(""), "Use a pregenerated collision context to infer number of events to simulate, how to embedd them, the vertex position etc. Takes precedence of other options such as \"--nEvents\".");
79+
options.add_options()("fromCollContext", bpo::value<std::string>()->default_value(""), "Use a pregenerated collision context to infer number of events to simulate, how to embedd them, the vertex position etc. Takes precedence of other options such as \"--nEvents\". The format is COLLISIONCONTEXTFILE.root[:SIGNALNAME] where SIGNALNAME is the event part in the context which is relevant.");
8080
}
8181

8282
void SimConfig::determineActiveModules(std::vector<std::string> const& inputargs, std::vector<std::string> const& skippedModules, std::vector<std::string>& activeModules, bool isUpgrade)
@@ -270,6 +270,21 @@ void SimConfig::determineReadoutDetectors(std::vector<std::string> const& active
270270
}
271271
}
272272

273+
std::pair<std::string, std::string> SimConfig::getCollContextFilenameAndEventPrefix() const
274+
{
275+
// we decompose the argument to fetch
276+
// (a) collision contextfilename
277+
// (b) sim prefix to use from the context
278+
auto pos = mConfigData.mFromCollisionContext.find(':');
279+
std::string collcontextfile{mConfigData.mFromCollisionContext};
280+
std::string simprefix{mConfigData.mOutputPrefix};
281+
if (pos != std::string::npos) {
282+
collcontextfile = mConfigData.mFromCollisionContext.substr(0, pos);
283+
simprefix = mConfigData.mFromCollisionContext.substr(pos + 1);
284+
}
285+
return std::make_pair(collcontextfile, simprefix);
286+
}
287+
273288
bool SimConfig::resetFromParsedMap(boost::program_options::variables_map const& vm)
274289
{
275290
using o2::detectors::DetID;
@@ -333,17 +348,8 @@ bool SimConfig::resetFromParsedMap(boost::program_options::variables_map const&
333348
mConfigData.mFilterNoHitEvents = true;
334349
}
335350
mConfigData.mFromCollisionContext = vm["fromCollContext"].as<std::string>();
336-
// we decompose the argument to fetch
337-
// (a) collision contextfilename
338-
// (b) sim prefix to use from the context
339-
auto pos = mConfigData.mFromCollisionContext.find(':');
340-
std::string collcontextfile{mConfigData.mFromCollisionContext};
341-
std::string simprefix{mConfigData.mOutputPrefix};
342-
if (pos != std::string::npos) {
343-
collcontextfile = mConfigData.mFromCollisionContext.substr(0, pos);
344-
simprefix = mConfigData.mFromCollisionContext.substr(pos + 1);
345-
}
346-
adjustFromCollContext(collcontextfile, simprefix);
351+
auto collcontext_simprefix = getCollContextFilenameAndEventPrefix();
352+
adjustFromCollContext(collcontext_simprefix.first, collcontext_simprefix.second);
347353

348354
// analyse vertex options
349355
if (!parseVertexModeString(vm["vertexMode"].as<std::string>(), mConfigData.mVertexMode)) {

DataFormats/simulation/src/DigitizationContext.cxx

+2
Original file line numberDiff line numberDiff line change
@@ -578,5 +578,7 @@ DigitizationContext DigitizationContext::extractSingleTimeframe(int timeframeid,
578578
} catch (std::exception) {
579579
LOG(warn) << "No such timeframe id in collision context. Returing empty object";
580580
}
581+
// fix number of collisions
582+
r.setNCollisions(r.mEventRecords.size());
581583
return r;
582584
}

Steer/src/CollisionContextTool.cxx

+34-14
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "CommonUtils/ConfigurableParam.h"
2828
#include <CCDB/BasicCCDBManager.h>
2929
#include "DataFormatsParameters/GRPLHCIFData.h"
30+
#include "SimConfig/SimConfig.h"
3031

3132
//
3233
// Created by Sandro Wenzel on 13.07.21.
@@ -52,11 +53,12 @@ struct Options {
5253
bool useexistingkinematics = false;
5354
bool noEmptyTF = false; // prevent empty timeframes; the first interaction will be shifted backwards to fall within the range given by Options.orbits
5455
int maxCollsPerTF = -1; // the maximal number of hadronic collisions per TF (can be used to constrain number of collisions per timeframe to some maximal value)
55-
bool genVertices = false; // whether to assign vertices to collisions
5656
std::string configKeyValues = ""; // string to init config key values
5757
long timestamp = -1; // timestamp for CCDB queries
5858
std::string individualTFextraction = ""; // triggers extraction of individuel timeframe components when non-null
5959
// format is path prefix
60+
std::string vertexModeString{"kNoVertex"}; // Vertex Mode; vertices will be assigned to collisions of mode != kNoVertex
61+
o2::conf::VertexMode vertexMode = o2::conf::VertexMode::kNoVertex;
6062
};
6163

6264
enum class InteractionLockMode {
@@ -203,7 +205,9 @@ bool parseOptions(int argc, char* argv[], Options& optvalues)
203205
"first-orbit", bpo::value<double>(&optvalues.firstFractionalOrbit)->default_value(0), "First (fractional) orbit in the run (HBFUtils.firstOrbit + BC from decimal)")(
204206
"maxCollsPerTF", bpo::value<int>(&optvalues.maxCollsPerTF)->default_value(-1), "Maximal number of MC collisions to put into one timeframe. By default no constraint.")(
205207
"noEmptyTF", bpo::bool_switch(&optvalues.noEmptyTF), "Enforce to have at least one collision")(
206-
"configKeyValues", bpo::value<std::string>(&optvalues.configKeyValues)->default_value(""), "Semicolon separated key=value strings (e.g.: 'TPC.gasDensity=1;...')")("with-vertices", "Assign vertices to collisions.")("timestamp", bpo::value<long>(&optvalues.timestamp)->default_value(-1L), "Timestamp for CCDB queries / anchoring")(
208+
"configKeyValues", bpo::value<std::string>(&optvalues.configKeyValues)->default_value(""), "Semicolon separated key=value strings (e.g.: 'TPC.gasDensity=1;...')")(
209+
"with-vertices", bpo::value<std::string>(&optvalues.vertexModeString)->default_value("kNoVertex"), "Assign vertices to collisions. Argument is the vertex mode. Defaults to no vertexing applied")(
210+
"timestamp", bpo::value<long>(&optvalues.timestamp)->default_value(-1L), "Timestamp for CCDB queries / anchoring")(
207211
"extract-per-timeframe", bpo::value<std::string>(&optvalues.individualTFextraction)->default_value(""),
208212
"Extract individual timeframe contexts. Format required: time_frame_prefix[:comma_separated_list_of_signals_to_offset]");
209213

@@ -225,9 +229,8 @@ bool parseOptions(int argc, char* argv[], Options& optvalues)
225229
if (vm.count("use-existing-kine")) {
226230
optvalues.useexistingkinematics = true;
227231
}
228-
if (vm.count("with-vertices")) {
229-
optvalues.genVertices = true;
230-
}
232+
233+
o2::conf::SimConfig::parseVertexModeString(optvalues.vertexModeString, optvalues.vertexMode);
231234

232235
// fix the first orbit and bunch crossing
233236
// auto orbitbcpair = parseOrbitAndBC(optvalues.firstIRString);
@@ -277,10 +280,9 @@ int main(int argc, char* argv[])
277280
LOG(info) << "Fetch bcPattern information from CCDB";
278281
// fetch the GRP Object
279282
auto& ccdb = o2::ccdb::BasicCCDBManager::instance();
280-
ccdb.setTimestamp(options.timestamp);
281283
ccdb.setCaching(false);
282284
ccdb.setLocalObjectValidityChecking(true);
283-
auto grpLHC = ccdb.get<o2::parameters::GRPLHCIFData>("GLO/Config/GRPLHCIF");
285+
auto grpLHC = ccdb.getForTimeStamp<o2::parameters::GRPLHCIFData>("GLO/Config/GRPLHCIF", options.timestamp);
284286
LOG(info) << "Fetched injection scheme " << grpLHC->getInjectionScheme() << " from CCDB";
285287
sampler.setBunchFilling(grpLHC->getBunchFilling());
286288
} else {
@@ -449,14 +451,32 @@ int main(int argc, char* argv[])
449451

450452
auto numTimeFrames = digicontext.finalizeTimeframeStructure(orbitstart, options.orbitsPerTF);
451453

452-
if (options.genVertices) {
453-
// TODO: offer option taking meanVertex directly from CCDB ! "GLO/Calib/MeanVertex"
454-
// sample interaction vertices
454+
if (options.vertexMode != o2::conf::VertexMode::kNoVertex) {
455+
switch (options.vertexMode) {
456+
case o2::conf::VertexMode::kCCDB: {
457+
// fetch mean vertex from CCDB
458+
auto meanv = o2::ccdb::BasicCCDBManager::instance().getForTimeStamp<o2::dataformats::MeanVertexObject>("GLO/Calib/MeanVertex", options.timestamp);
459+
if (meanv) {
460+
LOG(info) << "Applying vertexing using CCDB mean vertex " << *meanv;
461+
digicontext.sampleInteractionVertices(*meanv);
462+
} else {
463+
LOG(fatal) << "No vertex available";
464+
}
465+
break;
466+
}
455467

456-
// init this vertex from CCDB or InteractionDiamond parameter
457-
const auto& dparam = o2::eventgen::InteractionDiamondParam::Instance();
458-
o2::dataformats::MeanVertexObject meanv(dparam.position[0], dparam.position[1], dparam.position[2], dparam.width[0], dparam.width[1], dparam.width[2], dparam.slopeX, dparam.slopeY);
459-
digicontext.sampleInteractionVertices(meanv);
468+
case o2::conf::VertexMode::kDiamondParam: {
469+
// init this vertex from CCDB or InteractionDiamond parameter
470+
const auto& dparam = o2::eventgen::InteractionDiamondParam::Instance();
471+
o2::dataformats::MeanVertexObject meanv(dparam.position[0], dparam.position[1], dparam.position[2], dparam.width[0], dparam.width[1], dparam.width[2], dparam.slopeX, dparam.slopeY);
472+
LOG(info) << "Applying vertexing using DiamondParam mean vertex " << meanv;
473+
digicontext.sampleInteractionVertices(meanv);
474+
break;
475+
}
476+
default: {
477+
LOG(error) << "Unknown vertex mode ... Not generating vertices";
478+
}
479+
}
460480
}
461481

462482
// we fill QED contributions to the context

run/O2PrimaryServerDevice.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ class O2PrimaryServerDevice final : public fair::mq::Device
138138
mPrimGen->SetEvent(&mEventHeader);
139139

140140
// A good moment to couple to collision context
141-
auto collContextFileName = mSimConfig.getConfigData().mFromCollisionContext;
141+
auto collContextFileName_PrefixPair = mSimConfig.getCollContextFilenameAndEventPrefix();
142+
auto collContextFileName = collContextFileName_PrefixPair.first;
142143
if (collContextFileName.size() > 0) {
143144
LOG(info) << "Simulation has collission context";
144145
mCollissionContext = o2::steer::DigitizationContext::loadFromFile(collContextFileName);
@@ -147,7 +148,7 @@ class O2PrimaryServerDevice final : public fair::mq::Device
147148
LOG(info) << "We found " << vertices.size() << " vertices included ";
148149

149150
// initialize the eventID to collID mapping
150-
const auto source = mCollissionContext->findSimPrefix(mSimConfig.getOutPrefix());
151+
const auto source = mCollissionContext->findSimPrefix(collContextFileName_PrefixPair.second);
151152
if (source == -1) {
152153
LOG(fatal) << "Wrong simulation prefix";
153154
}

0 commit comments

Comments
 (0)