Project
Loading...
Searching...
No Matches
AODMcProducerWorkflowSpec.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13
17#include "Framework/DataTypes.h"
19#include "O2Version.h"
20#include "TString.h"
21
22using namespace o2::framework;
23
24namespace o2::aodmcproducer
25{
26
27//------------------------------------------------------------------
29{
30 mTimer.Stop();
31 mLPMProdTag = ic.options().get<std::string>("lpmp-prod-tag");
32 mAnchorPass = ic.options().get<std::string>("anchor-pass");
33 mAnchorProd = ic.options().get<std::string>("anchor-prod");
34 mRecoPass = ic.options().get<std::string>("reco-pass");
35 mTFNumber = ic.options().get<int64_t>("aod-timeframe-id");
36 mFilterMC = ic.options().get<int>("filter-mctracks");
37 int truncate = ic.options().get<int>("enable-truncation");
38 if (mTFNumber == -1L) {
39 LOG(info) << "TFNumber will be obtained from CCDB";
40 }
41
42 // set no truncation if selected by user
43 if (truncate == 0) {
44 LOG(info) << "Truncation is not used!";
45 mCollisionPosition = 0xFFFFFFFF;
46 mMcParticleW = 0xFFFFFFFF;
47 mMcParticlePos = 0xFFFFFFFF;
48 mMcParticleMom = 0xFFFFFFFF;
49 }
50
51 mEnableEmbed = ic.options().get<bool>("enable-embedding");
52
53 if (!mEnableEmbed) {
54 // parse list of sim prefixes into vector
55 mSimPrefix = ic.options().get<std::string>("mckine-fname");
56 }
57 std::string hepmcUpdate = ic.options().get<std::string>("hepmc-update");
58 HepMCUpdate when = (hepmcUpdate == "never" //
59 ? HepMCUpdate::never //
60 : hepmcUpdate == "always" //
61 ? HepMCUpdate::always //
62 : hepmcUpdate == "all" //
63 ? HepMCUpdate::allKeys //
64 : HepMCUpdate::anyKey);
65 mXSectionUpdate = when;
66 mPdfInfoUpdate = when;
67 mHeavyIonUpdate = when;
68
69 mTimer.Reset();
70}
71
72//------------------------------------------------------------------
73void AODMcProducerWorkflowDPL::updateHeader(CollisionCursor& collisionCursor,
74 XSectionCursor& xSectionCursor,
75 PdfInfoCursor& pdfInfoCursor,
76 HeavyIonCursor& heavyIonCursor,
77 const MCEventHeader& header,
78 int collisionID, // Index
79 int bcID,
80 float time,
81 short generatorID,
82 int sourceID)
83{
88
89 auto genID = updateMCCollisions(collisionCursor,
90 bcID,
91 time,
92 header,
93 generatorID,
94 sourceID,
95 mCollisionPosition);
96 mXSectionUpdate = (updateHepMCXSection(xSectionCursor, //
97 collisionID, //
98 genID, //
99 header, //
100 mXSectionUpdate) //
101 ? HepMCUpdate::always //
102 : HepMCUpdate::never);
103 mPdfInfoUpdate = (updateHepMCPdfInfo(pdfInfoCursor, //
104 collisionID, //
105 genID, //
106 header, //
107 mPdfInfoUpdate) //
108 ? HepMCUpdate::always //
109 : HepMCUpdate::never);
110 mHeavyIonUpdate = (updateHepMCHeavyIon(heavyIonCursor, //
111 collisionID, //
112 genID, //
113 header, //
114 mHeavyIonUpdate) //
115 ? HepMCUpdate::always //
116 : HepMCUpdate::never);
117}
118
119//------------------------------------------------------------------
121{
122 mTimer.Start(false);
123
124 uint64_t tfNumber = mTFNumber;
125
126 using namespace o2::aodmchelpers;
127 using namespace o2::aodhelpers;
128
129 auto collisionsCursor = createTableCursor<McCollisions>(pc);
130 auto particlesCursor = createTableCursor<McParticles>(pc);
131 auto originCursor = createTableCursor<Origins>(pc);
132 auto xSectionCursor = createTableCursor<XSections>(pc);
133 auto pdfInfoCursor = createTableCursor<PdfInfos>(pc);
134 auto heavyIonCursor = createTableCursor<HeavyIons>(pc);
135
136 // --- Create our reader -------------------------------------------
137 std::unique_ptr<MCKinematicsReader> reader;
138 if (not mEnableEmbed) {
139 reader =
140 std::make_unique<MCKinematicsReader>(mSimPrefix,
142 } else {
143 reader = std::make_unique<MCKinematicsReader>("collisioncontext.root");
144 }
145
146 // --- Container of event indexes ---------------------------------
147 using EventInfo = std::vector<std::tuple<int, int, int>>;
148 EventInfo eventInfo;
149
150 // --- Fill collision and HepMC aux tables ------------------------
151 // dummy time information
152 float time = 0;
153
154 if (not mEnableEmbed) {
155 // simply store all MC events into table
156 int icol = 0;
157 int nSources = reader->getNSources();
158 for (int isrc = 0; isrc < nSources; isrc++) {
159 short generatorID = isrc;
160 int nEvents = reader->getNEvents(isrc);
161 for (int ievt = 0; ievt < nEvents; ievt++) {
162 auto& header = reader->getMCEventHeader(isrc, ievt);
163 updateHeader(collisionsCursor.cursor,
164 xSectionCursor.cursor,
165 pdfInfoCursor.cursor,
166 heavyIonCursor.cursor,
167 header,
168 ievt,
169 ievt, // BC is the same as collision index
170 time,
171 generatorID,
172 isrc);
173
174 eventInfo.emplace_back(std::make_tuple(icol, isrc, ievt));
175 icol++;
176 }
177 }
178 } else {
179 // treat embedded events using collisioncontext: injected events
180 // will be stored together with background events into the same
181 // collisions
182 int nCollisions = reader->getDigitizationContext()->getNCollisions();
183 const auto& records = reader->getDigitizationContext()->getEventRecords();
184 const auto& parts = reader->getDigitizationContext()->getEventParts();
185 for (int icol = 0; icol < nCollisions; icol++) {
186 auto& colParts = parts[icol];
187 auto nParts = colParts.size();
188 for (auto colPart : colParts) {
189 auto eventID = colPart.entryID;
190 auto sourceID = colPart.sourceID;
191 // enable embedding: if several colParts exist, then they are
192 // saved as one collision
193 if (nParts == 1 || sourceID == 0) {
194 // Make collision header from first source only
195 short generatorID = sourceID;
196 auto& header = reader->getMCEventHeader(sourceID, eventID);
197
198 updateHeader(collisionsCursor.cursor,
199 xSectionCursor.cursor,
200 pdfInfoCursor.cursor,
201 heavyIonCursor.cursor,
202 header,
203 icol,
204 icol, // BC is the same as collision index
205 time,
206 generatorID,
207 sourceID);
208 }
209 // point background and injected signal events to one collision
210 eventInfo.emplace_back(std::make_tuple(icol, sourceID, eventID));
211 }
212 }
213 }
214
215 // Sort the event information
216 std::sort(eventInfo.begin(), eventInfo.end(),
217 [](typename EventInfo::const_reference left,
218 typename EventInfo::const_reference right) { //
219 return (std::get<0>(left) < std::get<0>(right));
220 });
221
222 // Loop over available events and update the tracks table
223 size_t offset = 0;
224 for (auto& colInfo : eventInfo) {
225 int event = std::get<2>(colInfo);
226 int source = std::get<1>(colInfo);
227 int collisionID = std::get<0>(colInfo);
228 auto tracks = reader->getTracks(source, event);
229
230 TrackToIndex preselect;
231 offset = updateParticles(particlesCursor.cursor,
232 collisionID,
233 tracks,
234 preselect,
235 offset,
236 mFilterMC,
237 source == 0,
238 mMcParticleW,
239 mMcParticleMom,
240 mMcParticlePos);
241
242 reader->releaseTracksForSourceAndEvent(source, event);
243 }
244
245 // --- Update the origin and the time-frame ------------------------
246 originCursor(tfNumber);
247
248 // --- Sending metadata to writer if not done already --------------
249 if (not mIsMDSent) {
250 TString o2Version = o2::fullVersion();
251 std::vector<TString> metaDataKeys = {"DataType",
252 "Run",
253 "O2Version",
254 "ROOTVersion",
255 "RecoPassName",
256 "AnchorProduction",
257 "AnchorPassName",
258 "LPMProductionTag"};
259 std::vector<TString> metaDataVals = {"MC",
260 "3",
261 TString{o2::fullVersion()},
262 ROOT_RELEASE,
263 mRecoPass,
264 mAnchorProd,
265 mAnchorPass,
266 mLPMProdTag};
267 pc.outputs().snapshot(Output{"AMD", "AODMetadataKeys", 0}, metaDataKeys);
268 pc.outputs().snapshot(Output{"AMD", "AODMetadataVals", 0}, metaDataVals);
269 mIsMDSent = true;
270 }
271
272 pc.outputs().snapshot(Output{"TFN", "TFNumber", 0}, tfNumber);
273 pc.outputs().snapshot(Output{"TFF", "TFFilename", 0}, "");
274
276 pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
277
278 mTimer.Stop();
279}
280
282{
283 LOGF(info, "aod producer dpl total timing: Cpu: %.3e Real: %.3e s in %d slots",
284 mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1);
285}
286
288{
289 using McCollisions = AODMcProducerWorkflowDPL::McCollisions;
290 using McParticles = AODMcProducerWorkflowDPL::McParticles;
291 using Origins = AODMcProducerWorkflowDPL::Origins;
292 using XSections = AODMcProducerWorkflowDPL::XSections;
293 using PdfInfos = AODMcProducerWorkflowDPL::PdfInfos;
294 using HeavyIons = AODMcProducerWorkflowDPL::HeavyIons;
295
296 std::vector<OutputSpec> outputs{
303 OutputSpec{"TFN", "TFNumber"},
304 OutputSpec{"TFF", "TFFilename"},
305 OutputSpec{"AMD", "AODMetadataKeys"},
306 OutputSpec{"AMD", "AODMetadataVals"}};
307
308 return DataProcessorSpec{
309 "aod-mc-producer-workflow",
310 Inputs{},
311 outputs,
312 AlgorithmSpec{adaptFromTask<AODMcProducerWorkflowDPL>()},
313 Options{
314 ConfigParamSpec{"aod-timeframe-id", VariantType::Int64, 1L, {"Set timeframe number"}},
315 ConfigParamSpec{"enable-truncation", VariantType::Int, 1, {"Truncation parameter: 1 -- on, != 1 -- off"}},
316 ConfigParamSpec{"lpmp-prod-tag", VariantType::String, "", {"LPMProductionTag"}},
317 ConfigParamSpec{"anchor-pass", VariantType::String, "", {"AnchorPassName"}},
318 ConfigParamSpec{"anchor-prod", VariantType::String, "", {"AnchorProduction"}},
319 ConfigParamSpec{"reco-pass", VariantType::String, "", {"RecoPassName"}},
320 ConfigParamSpec{"filter-mctracks", VariantType::Int, 1, {"Store only physical primary MC tracks and their mothers/daughters. 0 -- off, != 0 -- on"}},
321 ConfigParamSpec{"enable-embedding", VariantType::Int, 0, {"Use collisioncontext.root to process embedded events"}},
322 ConfigParamSpec{"mckine-fname", VariantType::String, "o2sim", {"MC kinematics file name prefix: e.g. 'o2sim', 'bkg', 'sgn_1'. Used only if 'enable-embedding' is 0"}},
323 ConfigParamSpec{"hepmc-update", VariantType::String, "always", {"When to update HepMC Aux tables: always - force update, never - never update, all - if all keys are present, any - when any key is present (not valid yet)"}}}};
324}
325
326} // namespace o2::aodmcproducer
327//
328// EOF
329//
int16_t time
Definition RawEventData.h:4
Utility functions for MC particles.
void endOfStream(EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
void snapshot(const Output &spec, T const &object)
ConfigParamRegistry const & options()
Definition InitContext.h:33
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
ServiceRegistryRef services()
The services registry associated with this processing context.
struct _cl_event * event
Definition glcorearb.h:2982
GLdouble GLdouble right
Definition glcorearb.h:4077
GLsizei GLsizei GLchar * source
Definition glcorearb.h:798
GLintptr offset
Definition glcorearb.h:660
bool updateHepMCHeavyIon(const HeavyIonCursor &cursor, int collisionID, short generatorID, o2::dataformats::MCEventHeader const &header, HepMCUpdate when=HepMCUpdate::anyKey)
std::unordered_map< int, int > TrackToIndex
short updateMCCollisions(const CollisionCursor &cursor, int bcId, float time, o2::dataformats::MCEventHeader const &header, short generatorId=0, int sourceId=0, unsigned int mask=0xFFFFFFF0)
bool updateHepMCPdfInfo(const PdfInfoCursor &cursor, int collisionID, short generatorID, o2::dataformats::MCEventHeader const &header, HepMCUpdate when=HepMCUpdate::anyKey)
bool updateHepMCXSection(const XSectionCursor &cursor, int collisionID, short generatorID, o2::dataformats::MCEventHeader const &header, HepMCUpdate when=HepMCUpdate::anyKey)
framework::DataProcessorSpec getAODMcProducerWorkflowSpec()
create a processor spec
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
std::string fullVersion()
get full version information (official O2 release and git commit)
uint32_t truncate(int32_t j, uint32_t val)
static OutputSpec const spec()
const int nEvents
Definition test_Fifo.cxx:27
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"