@@ -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