Skip to content

Commit 5bebabe

Browse files
committed
Collisioncontext-tool: ability to adjust event count to existing kinematics
Needed in O2DPG, to digitize longer timeframes, reusing events multiple times.
1 parent a10c0a9 commit 5bebabe

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

Steer/src/CollisionContextTool.cxx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <TRandom.h>
2222
#include <numeric>
2323
#include <FairLogger.h>
24+
#include "Steer/MCKinematicsReader.h"
2425

2526
//
2627
// Created by Sandro Wenzel on 13.07.21.
@@ -38,6 +39,7 @@ struct Options {
3839
std::string bcpatternfile;
3940
int tfid = 0; // tfid -> used to calculate start orbit for collisions
4041
int orbitsPerTF = 256; // number of orbits per timeframe --> used to calculate start orbit for collisions
42+
bool useexistingkinematics = false;
4143
};
4244

4345
enum class InteractionLockMode {
@@ -56,7 +58,7 @@ struct InteractionSpec {
5658
bool randomizeorder = false; // whether order of events will be randomized
5759
};
5860

59-
InteractionSpec parseInteractionSpec(std::string const& specifier, std::vector<InteractionSpec> const& existingPatterns)
61+
InteractionSpec parseInteractionSpec(std::string const& specifier, std::vector<InteractionSpec> const& existingPatterns, bool adjustEventCount)
6062
{
6163
// An interaction specification is a command-separated string
6264
// of the following form:
@@ -82,7 +84,7 @@ InteractionSpec parseInteractionSpec(std::string const& specifier, std::vector<I
8284
float rate = -1.;
8385
std::pair<int, float> synconto(-1, 1);
8486

85-
// extract name
87+
// extract (kinematics prefix) name
8688
std::string name = tokens[0];
8789

8890
// extract the MC number spec if given
@@ -106,6 +108,17 @@ InteractionSpec parseInteractionSpec(std::string const& specifier, std::vector<I
106108
}
107109
}
108110

111+
if (adjustEventCount) {
112+
// if the number of collisionsavail has not been specified, we should
113+
// try to extract it from the kinematics directly
114+
o2::steer::MCKinematicsReader mcreader(name, o2::steer::MCKinematicsReader::Mode::kMCKine);
115+
if (collisionsavail > 0) {
116+
collisionsavail = std::min((size_t)collisionsavail, (size_t)mcreader.getNEvents(0));
117+
} else {
118+
collisionsavail = mcreader.getNEvents(0);
119+
}
120+
}
121+
109122
// extract interaction rate ... or locking
110123
auto& interactionToken = tokens[1];
111124
if (interactionToken[0] == '@') {
@@ -164,6 +177,7 @@ bool parseOptions(int argc, char* argv[], Options& optvalues)
164177
"show-context", "Print generated collision context to terminal.")(
165178
"bcPatternFile", bpo::value<std::string>(&optvalues.bcpatternfile)->default_value(""), "Interacting BC pattern file (e.g. from CreateBCPattern.C)")(
166179
"orbitsPerTF", bpo::value<int>(&optvalues.orbitsPerTF)->default_value(256), "Orbits per timeframes")(
180+
"use-existing-kine", "Read existing kinematics to adjust event counts")(
167181
"timeframeID", bpo::value<int>(&optvalues.tfid)->default_value(0), "Timeframe id of this context. Allows to generate contexts for different start orbits");
168182

169183
options.add_options()("help,h", "Produce help message.");
@@ -181,6 +195,9 @@ bool parseOptions(int argc, char* argv[], Options& optvalues)
181195
if (vm.count("show-context")) {
182196
optvalues.printContext = true;
183197
}
198+
if (vm.count("use-existing-kine")) {
199+
optvalues.useexistingkinematics = true;
200+
}
184201

185202
} catch (const bpo::error& e) {
186203
std::cerr << e.what() << "\n\n";
@@ -205,7 +222,7 @@ int main(int argc, char* argv[])
205222
// building the interaction spec
206223
for (auto& i : options.interactionRates) {
207224
// this is created as output from
208-
ispecs.push_back(parseInteractionSpec(i, ispecs));
225+
ispecs.push_back(parseInteractionSpec(i, ispecs, options.useexistingkinematics));
209226
}
210227

211228
std::vector<std::pair<o2::InteractionTimeRecord, std::vector<o2::steer::EventPart>>> collisions;
@@ -308,7 +325,12 @@ int main(int argc, char* argv[])
308325
}
309326

310327
if (inject) {
311-
col.second.emplace_back(id, eventcount++);
328+
if (ispecs[id].mcnumberavail >= 0) {
329+
col.second.emplace_back(id, eventcount % ispecs[id].mcnumberavail);
330+
} else {
331+
col.second.emplace_back(id, eventcount);
332+
}
333+
eventcount++;
312334
lastcol = colid;
313335
lastcoltime = coltime;
314336
}

0 commit comments

Comments
 (0)