forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patho2sim_mctracks_to_aod.cxx
160 lines (139 loc) · 5.6 KB
/
o2sim_mctracks_to_aod.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
// #include "O2RivetExporter.h"
#include "../Detectors/AOD/include/AODProducerWorkflow/AODMcProducerHelpers.h"
#include <Framework/AnalysisTask.h>
#include <SimulationDataFormat/InteractionSampler.h>
#include <Framework/runDataProcessing.h>
template <typename T>
using Configurable = o2::framework::Configurable<T>;
struct MctracksToAod {
/** @{
@name Types used */
using Collisions = o2::aod::McCollisions;
// using Particles = o2::aod::McParticles; //
using Particles = o2::aod::StoredMcParticles_001;
using XSections = o2::aod::HepMCXSections;
using PdfInfos = o2::aod::HepMCPdfInfos;
using HeavyIons = o2::aod::HepMCHeavyIons;
using InteractionSampler = o2::steer::InteractionSampler;
/** @} */
/** @{
@name Produced data */
/** Collision header */
o2::framework::Produces<Collisions> mCollisions;
/** Particles in collision */
o2::framework::Produces<Particles> mParticles;
/** Cross-section information */
o2::framework::Produces<XSections> mXSections;
/** Parton-distribution-function information */
o2::framework::Produces<PdfInfos> mPdfInfos;
/** Heavy-ion colllision information */
o2::framework::Produces<HeavyIons> mHeavyIons;
/** @} */
/** @{
@name Configurable parameters */
Configurable<float> IR{"interaction-rate", 100.f,
"Interaction rate to simulate"};
Configurable<bool> filt{"filter-mctracks", false,
"Filter tracks"};
Configurable<uint64_t> tfOffset{"tf-offset", 0, "Start TF counter from an offset"};
/** @} */
/** Number of timeframes */
uint64_t mTimeFrame = 0;
/** Interaction simulation */
InteractionSampler mSampler;
/** Initialize */
void init(o2::framework::InitContext& /*ic*/)
{
mSampler.setInteractionRate(IR);
mSampler.setFirstIR({0, 0});
mSampler.init();
mTimeFrame = tfOffset;
}
/** Run the conversion */
void run(o2::framework::ProcessingContext& pc)
{
LOG(debug) << "=== Running extended MC AOD exporter ===";
using namespace o2::aodmchelpers;
using McHeader = o2::dataformats::MCEventHeader;
using McTrack = o2::MCTrack;
using McTracks = std::vector<McTrack>;
auto nParts = pc.inputs().getNofParts(0);
auto nPartsVerify = pc.inputs().getNofParts(1);
using o2::framework::Lifetime;
using o2::framework::Output;
if (nParts != nPartsVerify) {
LOG(warn) << "Mismatch between number of MC headers and "
<< "number of track vectors: " << nParts
<< " != " << nPartsVerify
<< ", shipping the empty timeframe";
pc.outputs().snapshot(Output{"TFF", "TFFilename", 0}, "");
pc.outputs().snapshot(Output{"TFN", "TFNumber", 0}, ++mTimeFrame);
return;
}
// TODO: include BC simulation
auto bcCounter = 0UL;
size_t offset = 0;
for (auto i = 0U; i < nParts; ++i) {
LOG(debug) << "--- Loop over " << nParts << " parts ---";
auto record = mSampler.generateCollisionTime();
auto header = pc.inputs().get<McHeader*>("mcheader", i);
auto tracks = pc.inputs().get<McTracks>("mctracks", i);
LOG(debug) << "Updating collision table";
auto genID = updateMCCollisions(mCollisions.cursor,
bcCounter,
record.timeInBCNS * 1.e-3,
*header,
0,
i);
LOG(debug) << "Updating HepMC tables";
updateHepMCXSection(mXSections.cursor, bcCounter, genID, *header);
updateHepMCPdfInfo(mPdfInfos.cursor, bcCounter, genID, *header);
updateHepMCHeavyIon(mHeavyIons.cursor, bcCounter, genID, *header);
LOG(debug) << "Updating particles table";
TrackToIndex preselect;
offset = updateParticles(mParticles.cursor,
bcCounter,
tracks,
preselect,
offset,
(bool)filt,
false);
LOG(debug) << "Increment BC counter";
bcCounter++;
}
pc.outputs().snapshot(Output{"TFF", "TFFilename", 0}, "");
pc.outputs().snapshot(Output{"TFN", "TFNumber", 0}, ++mTimeFrame);
}
};
using WorkflowSpec = o2::framework::WorkflowSpec;
using TaskName = o2::framework::TaskName;
using DataProcessorSpec = o2::framework::DataProcessorSpec;
using ConfigContext = o2::framework::ConfigContext;
using InputSpec = o2::framework::InputSpec;
using OutputSpec = o2::framework::OutputSpec;
using Lifetime = o2::framework::Lifetime;
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
{
using o2::framework::adaptAnalysisTask;
auto spec = adaptAnalysisTask<MctracksToAod>(cfgc);
spec.inputs.emplace_back("mctracks", "MC", "MCTRACKS", 0.,
Lifetime::Timeframe);
spec.inputs.emplace_back("mcheader", "MC", "MCHEADER", 0.,
Lifetime::Timeframe);
spec.outputs.emplace_back("TFF", "TFFilename");
spec.outputs.emplace_back("TFN", "TFNumber");
return {spec};
}
//
// EOF
//