Skip to content

Commit fcbe55d

Browse files
Merge pull request #7497 from chiarazampolli/AODproducer
Use mc flag to be able to run with data
1 parent 69fd283 commit fcbe55d

2 files changed

Lines changed: 76 additions & 69 deletions

File tree

Detectors/AOD/include/AODProducerWorkflow/AODProducerWorkflowSpec.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,15 @@ typedef boost::unordered_map<Triplet_t, int, TripletHash, TripletEqualTo> Triple
191191
class AODProducerWorkflowDPL : public Task
192192
{
193193
public:
194-
AODProducerWorkflowDPL(GID::mask_t src, std::shared_ptr<DataRequest> dataRequest) : mInputSources(src), mDataRequest(dataRequest) {}
194+
AODProducerWorkflowDPL(GID::mask_t src, std::shared_ptr<DataRequest> dataRequest, bool useMC = true) : mInputSources(src), mDataRequest(dataRequest), mUseMC(useMC) {}
195195
~AODProducerWorkflowDPL() override = default;
196196
void init(InitContext& ic) final;
197197
void run(ProcessingContext& pc) final;
198198
void endOfStream(framework::EndOfStreamContext& ec) final;
199199

200200
private:
201+
bool mUseMC = true;
202+
201203
const float cSpeed = 0.029979246f; // speed of light in TOF units
202204

203205
GID::mask_t mInputSources;

Detectors/AOD/src/AODProducerWorkflowSpec.cxx

Lines changed: 73 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -977,17 +977,15 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
977977
auto v0sCursor = v0sBuilder.cursor<o2::aod::StoredV0s>();
978978
auto zdcCursor = zdcBuilder.cursor<o2::aod::Zdcs>();
979979

980-
o2::steer::MCKinematicsReader mcReader("collisioncontext.root");
981-
const auto mcContext = mcReader.getDigitizationContext();
982-
const auto& mcRecords = mcContext->getEventRecords();
983-
const auto& mcParts = mcContext->getEventParts();
984-
985-
LOG(DEBUG) << "FOUND " << mcRecords.size() << " records";
986-
LOG(DEBUG) << "FOUND " << mcParts.size() << " parts";
980+
std::unique_ptr<o2::steer::MCKinematicsReader> mcReader;
981+
if (mUseMC) {
982+
mcReader = std::make_unique<o2::steer::MCKinematicsReader>("collisioncontext.root");
983+
LOG(DEBUG) << "FOUND " << mcReader->getDigitizationContext()->getEventRecords().size()
984+
<< " records" << mcReader->getDigitizationContext()->getEventParts().size() << " parts";
985+
}
987986

988987
std::map<uint64_t, int> bcsMap;
989-
collectBCs(fddRecPoints, ft0RecPoints, fv0RecPoints, primVertices, mcRecords, bcsMap);
990-
988+
collectBCs(fddRecPoints, ft0RecPoints, fv0RecPoints, primVertices, mUseMC ? mcReader->getDigitizationContext()->getEventRecords() : std::vector<o2::InteractionTimeRecord>{}, bcsMap);
991989
const auto* dh = o2::header::get<o2::header::DataHeader*>(pc.inputs().getFirstValid(true).header);
992990
o2::InteractionRecord startIR = {0, dh->firstTForbit};
993991

@@ -1070,40 +1068,44 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
10701068
// correct ordering when iterating over container elements
10711069
std::map<std::pair<int, int>, int> mcColToEvSrc;
10721070

1073-
// TODO: figure out collision weight
1074-
float mcColWeight = 1.;
1075-
// filling mcCollision table
1076-
int nMCCollisions = mcContext->getNCollisions();
1077-
for (int iCol = 0; iCol < nMCCollisions; iCol++) {
1078-
auto time = mcRecords[iCol].getTimeNS();
1079-
auto globalBC = mcRecords[iCol].toLong();
1080-
auto item = bcsMap.find(globalBC);
1081-
int bcID = -1;
1082-
if (item != bcsMap.end()) {
1083-
bcID = item->second;
1084-
} else {
1085-
LOG(FATAL) << "Error: could not find a corresponding BC ID for MC collision; BC = " << globalBC << ", mc collision = " << iCol;
1086-
}
1087-
auto& colParts = mcParts[iCol];
1088-
for (auto colPart : colParts) {
1089-
auto eventID = colPart.entryID;
1090-
auto sourceID = colPart.sourceID;
1091-
if (sourceID == 0) { // embedding: using background event info
1092-
// FIXME:
1093-
// use generators' names for generatorIDs (?)
1094-
short generatorID = sourceID;
1095-
auto& header = mcReader.getMCEventHeader(sourceID, eventID);
1096-
mcCollisionsCursor(0,
1097-
bcID,
1098-
generatorID,
1099-
truncateFloatFraction(header.GetX(), mCollisionPosition),
1100-
truncateFloatFraction(header.GetY(), mCollisionPosition),
1101-
truncateFloatFraction(header.GetZ(), mCollisionPosition),
1102-
truncateFloatFraction(time, mCollisionPosition),
1103-
truncateFloatFraction(mcColWeight, mCollisionPosition),
1104-
header.GetB());
1071+
if (mUseMC) {
1072+
// TODO: figure out collision weight
1073+
float mcColWeight = 1.;
1074+
// filling mcCollision table
1075+
int nMCCollisions = mcReader->getDigitizationContext()->getNCollisions();
1076+
const auto& mcRecords = mcReader->getDigitizationContext()->getEventRecords();
1077+
const auto& mcParts = mcReader->getDigitizationContext()->getEventParts();
1078+
for (int iCol = 0; iCol < nMCCollisions; iCol++) {
1079+
auto time = mcRecords[iCol].getTimeNS();
1080+
auto globalBC = mcRecords[iCol].toLong();
1081+
auto item = bcsMap.find(globalBC);
1082+
int bcID = -1;
1083+
if (item != bcsMap.end()) {
1084+
bcID = item->second;
1085+
} else {
1086+
LOG(FATAL) << "Error: could not find a corresponding BC ID for MC collision; BC = " << globalBC << ", mc collision = " << iCol;
1087+
}
1088+
auto& colParts = mcParts[iCol];
1089+
for (auto colPart : colParts) {
1090+
auto eventID = colPart.entryID;
1091+
auto sourceID = colPart.sourceID;
1092+
if (sourceID == 0) { // embedding: using background event info
1093+
// FIXME:
1094+
// use generators' names for generatorIDs (?)
1095+
short generatorID = sourceID;
1096+
auto& header = mcReader->getMCEventHeader(sourceID, eventID);
1097+
mcCollisionsCursor(0,
1098+
bcID,
1099+
generatorID,
1100+
truncateFloatFraction(header.GetX(), mCollisionPosition),
1101+
truncateFloatFraction(header.GetY(), mCollisionPosition),
1102+
truncateFloatFraction(header.GetZ(), mCollisionPosition),
1103+
truncateFloatFraction(time, mCollisionPosition),
1104+
truncateFloatFraction(mcColWeight, mCollisionPosition),
1105+
header.GetB());
1106+
}
1107+
mcColToEvSrc.emplace(std::pair<int, int>(eventID, sourceID), iCol); // point background and injected signal events to one collision
11051108
}
1106-
mcColToEvSrc.emplace(std::pair<int, int>(eventID, sourceID), iCol); // point background and injected signal events to one collision
11071109
}
11081110
}
11091111

@@ -1182,12 +1184,14 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
11821184
ft0RecPoint.getTrigger().triggersignals);
11831185
}
11841186

1185-
// filling MC collision labels
1186-
for (auto& label : primVerLabels) {
1187-
auto it = mcColToEvSrc.find(std::pair<int, int>(label.getEventID(), label.getSourceID()));
1188-
int32_t mcCollisionID = it != mcColToEvSrc.end() ? it->second : -1;
1189-
uint16_t mcMask = 0; // todo: set mask using normalized weights?
1190-
mcColLabelsCursor(0, mcCollisionID, mcMask);
1187+
if (mUseMC) {
1188+
// filling MC collision labels
1189+
for (auto& label : primVerLabels) {
1190+
auto it = mcColToEvSrc.find(std::pair<int, int>(label.getEventID(), label.getSourceID()));
1191+
int32_t mcCollisionID = it != mcColToEvSrc.end() ? it->second : -1;
1192+
uint16_t mcMask = 0; // todo: set mask using normalized weights?
1193+
mcColLabelsCursor(0, mcCollisionID, mcMask);
1194+
}
11911195
}
11921196

11931197
// hash map for track indices of secondary vertices
@@ -1291,26 +1295,27 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
12911295

12921296
bcsMap.clear();
12931297

1294-
// filling mc particles table
1295-
fillMCParticlesTable(mcReader,
1296-
mcParticlesCursor,
1297-
primVer2TRefs,
1298-
primVerGIs,
1299-
recoData,
1300-
mcColToEvSrc);
1301-
1302-
mcColToEvSrc.clear();
1303-
1304-
// ------------------------------------------------------
1305-
// filling track labels
1306-
1307-
// need to go through labels in the same order as for tracks
1308-
fillMCTrackLabelsTable(mcTrackLabelCursor, mcMFTTrackLabelCursor, mcFwdTrackLabelCursor, primVer2TRefs.back(), primVerGIs, recoData);
1309-
for (int iref = 0; iref < primVer2TRefs.size() - 1; iref++) {
1310-
auto& trackRef = primVer2TRefs[iref];
1311-
fillMCTrackLabelsTable(mcTrackLabelCursor, mcMFTTrackLabelCursor, mcFwdTrackLabelCursor, trackRef, primVerGIs, recoData);
1298+
if (mUseMC) {
1299+
// filling mc particles table
1300+
fillMCParticlesTable(*mcReader,
1301+
mcParticlesCursor,
1302+
primVer2TRefs,
1303+
primVerGIs,
1304+
recoData,
1305+
mcColToEvSrc);
1306+
1307+
mcColToEvSrc.clear();
1308+
1309+
// ------------------------------------------------------
1310+
// filling track labels
1311+
1312+
// need to go through labels in the same order as for tracks
1313+
fillMCTrackLabelsTable(mcTrackLabelCursor, mcMFTTrackLabelCursor, mcFwdTrackLabelCursor, primVer2TRefs.back(), primVerGIs, recoData);
1314+
for (int iref = 0; iref < primVer2TRefs.size() - 1; iref++) {
1315+
auto& trackRef = primVer2TRefs[iref];
1316+
fillMCTrackLabelsTable(mcTrackLabelCursor, mcMFTTrackLabelCursor, mcFwdTrackLabelCursor, trackRef, primVerGIs, recoData);
1317+
}
13121318
}
1313-
13141319
mToStore.clear();
13151320

13161321
pc.outputs().snapshot(Output{"TFN", "TFNumber", 0, Lifetime::Timeframe}, tfNumber);
@@ -1363,7 +1368,7 @@ DataProcessorSpec getAODProducerWorkflowSpec(GID::mask_t src, bool useMC)
13631368
"aod-producer-workflow",
13641369
dataRequest->inputs,
13651370
outputs,
1366-
AlgorithmSpec{adaptFromTask<AODProducerWorkflowDPL>(src, dataRequest)},
1371+
AlgorithmSpec{adaptFromTask<AODProducerWorkflowDPL>(src, dataRequest, useMC)},
13671372
Options{
13681373
ConfigParamSpec{"aod-timeframe-id", VariantType::Int64, -1L, {"Set timeframe number"}},
13691374
ConfigParamSpec{"enable-truncation", VariantType::Int, 1, {"Truncation parameter: 1 -- on, != 1 -- off"}},

0 commit comments

Comments
 (0)