@@ -482,7 +482,7 @@ void AODProducerWorkflowDPL::addToFwdTracksTable(FwdTracksCursorType& fwdTracksC
482482 tanl = track.getTanl ();
483483 invqpt = track.getInvQPt ();
484484 chi2 = track.getTrackChi2 ();
485- // nClusters = track.getNumberOfPoints();
485+ // nClusters = track.getNumberOfPoints();
486486 chi2matchmchmid = track.getMIDMatchingChi2 ();
487487 chi2matchmchmft = track.getMatchingChi2 ();
488488 matchmfttrackid = track.getMFTTrackID ();
@@ -557,7 +557,7 @@ void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader&
557557 gsl::span<const o2::dataformats::VtxTrackRef>& primVer2TRefs,
558558 gsl::span<const GIndex>& GIndices,
559559 o2::globaltracking::RecoContainer& data,
560- std::vector <std::pair<int , int >> const & mcColToEvSrc)
560+ std::map <std::pair<int , int >, int > const & mcColToEvSrc)
561561{
562562 // mark reconstructed MC particles to store them into the table
563563 for (auto & trackRef : primVer2TRefs) {
@@ -598,9 +598,10 @@ void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader&
598598 }
599599 }
600600 int tableIndex = 1 ;
601- for (int mccolid = 0 ; mccolid < mcColToEvSrc.size (); ++mccolid) {
602- auto event = mcColToEvSrc[mccolid].first ;
603- auto source = mcColToEvSrc[mccolid].second ;
601+ for (auto & colInfo : mcColToEvSrc) { // loop over "<eventID, sourceID> <-> combined MC col. ID" key pairs
602+ int event = colInfo.first .first ;
603+ int source = colInfo.first .second ;
604+ int mcColId = colInfo.second ;
604605 std::vector<MCTrack> const & mcParticles = mcReader.getTracks (source, event);
605606 // mark tracks to be stored per event
606607 // loop over stack of MC particles from end to beginning: daughters are stored after mothers
@@ -652,6 +653,9 @@ void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader&
652653 }
653654 int statusCode = 0 ;
654655 uint8_t flags = 0 ;
656+ if (source == 0 ) {
657+ flags |= 1 << 1 ; // mark as particle from background event
658+ }
655659 float weight = 0 .f ;
656660 int mcMother0 = mcParticles[particle].getMotherTrackId ();
657661 auto item = mToStore .find (Triplet_t (source, event, mcMother0));
@@ -677,13 +681,12 @@ void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader&
677681 if (item != mToStore .end ()) {
678682 daughterL = item->second ;
679683 }
680- float pX = (float )mcParticles[particle].Px ();
681- float pY = (float )mcParticles[particle].Py ();
682- float pZ = (float )mcParticles[particle].Pz ();
683- float energy = (float )mcParticles[particle].GetEnergy ();
684-
684+ auto pX = (float )mcParticles[particle].Px ();
685+ auto pY = (float )mcParticles[particle].Py ();
686+ auto pZ = (float )mcParticles[particle].Pz ();
687+ auto energy = (float )mcParticles[particle].GetEnergy ();
685688 mcParticlesCursor (0 ,
686- mccolid ,
689+ mcColId ,
687690 mcParticles[particle].GetPdgCode (),
688691 statusCode,
689692 flags,
@@ -1051,43 +1054,46 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
10511054 dummyTime,
10521055 dummyTime);
10531056
1054- // TODO: figure out collision weight
10551057 // keep track event/source id for each mc-collision
1056- std::vector<std::pair<int , int >> mcColToEvSrc;
1058+ // using map and not unordered_map to ensure
1059+ // correct ordering when iterating over container elements
1060+ std::map<std::pair<int , int >, int > mcColToEvSrc;
10571061
1062+ // TODO: figure out collision weight
10581063 float mcColWeight = 1 .;
10591064 // filling mcCollision table
1060- int index = 0 ;
1061- for (auto & rec : mcRecords ) {
1062- auto time = rec .getTimeNS ();
1063- uint64_t globalBC = rec .toLong ();
1065+ int nMCCollisions = mcContext-> getNCollisions () ;
1066+ for (int iCol = 0 ; iCol < nMCCollisions; iCol++ ) {
1067+ auto time = mcRecords[iCol] .getTimeNS ();
1068+ auto globalBC = mcRecords[iCol] .toLong ();
10641069 auto item = bcsMap.find (globalBC);
10651070 int bcID = -1 ;
10661071 if (item != bcsMap.end ()) {
10671072 bcID = item->second ;
10681073 } else {
1069- LOG (FATAL) << " Error: could not find a corresponding BC ID for MC collision; BC = " << globalBC << " , index = " << index ;
1074+ LOG (FATAL) << " Error: could not find a corresponding BC ID for MC collision; BC = " << globalBC << " , mc collision = " << iCol ;
10701075 }
1071- auto & colParts = mcParts[index ];
1076+ auto & colParts = mcParts[iCol ];
10721077 for (auto colPart : colParts) {
10731078 auto eventID = colPart.entryID ;
10741079 auto sourceID = colPart.sourceID ;
1075- // FIXME:
1076- // use generators' names for generatorIDs (?)
1077- short generatorID = sourceID;
1078- auto & header = mcReader.getMCEventHeader (sourceID, eventID);
1079- mcCollisionsCursor (0 ,
1080- bcID,
1081- generatorID,
1082- truncateFloatFraction (header.GetX (), mCollisionPosition ),
1083- truncateFloatFraction (header.GetY (), mCollisionPosition ),
1084- truncateFloatFraction (header.GetZ (), mCollisionPosition ),
1085- truncateFloatFraction (time, mCollisionPosition ),
1086- truncateFloatFraction (mcColWeight, mCollisionPosition ),
1087- header.GetB ());
1088- mcColToEvSrc.emplace_back (std::pair<int , int >(eventID, sourceID));
1080+ if (sourceID == 0 ) { // embedding: using background event info
1081+ // FIXME:
1082+ // use generators' names for generatorIDs (?)
1083+ short generatorID = sourceID;
1084+ auto & header = mcReader.getMCEventHeader (sourceID, eventID);
1085+ mcCollisionsCursor (0 ,
1086+ bcID,
1087+ generatorID,
1088+ truncateFloatFraction (header.GetX (), mCollisionPosition ),
1089+ truncateFloatFraction (header.GetY (), mCollisionPosition ),
1090+ truncateFloatFraction (header.GetZ (), mCollisionPosition ),
1091+ truncateFloatFraction (time, mCollisionPosition ),
1092+ truncateFloatFraction (mcColWeight, mCollisionPosition ),
1093+ header.GetB ());
1094+ }
1095+ mcColToEvSrc.emplace (std::pair<int , int >(eventID, sourceID), iCol); // point background and injected signal events to one collision
10891096 }
1090- index++;
10911097 }
10921098
10931099 // vector of FDD amplitudes
@@ -1167,9 +1173,8 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
11671173
11681174 // filling MC collision labels
11691175 for (auto & label : primVerLabels) {
1170- auto it = std::find_if (mcColToEvSrc.begin (), mcColToEvSrc.end (),
1171- [&label](const std::pair<int , int >& item) { return (item.first == label.getEventID () && item.second == label.getSourceID ()); });
1172- int32_t mcCollisionID = (it != mcColToEvSrc.end ()) ? it - mcColToEvSrc.begin () : -1 ;
1176+ auto it = mcColToEvSrc.find (std::pair<int , int >(label.getEventID (), label.getSourceID ()));
1177+ int32_t mcCollisionID = it != mcColToEvSrc.end () ? it->second : -1 ;
11731178 uint16_t mcMask = 0 ; // todo: set mask using normalized weights?
11741179 mcColLabelsCursor (0 , mcCollisionID, mcMask);
11751180 }
@@ -1201,7 +1206,6 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
12011206 } else {
12021207 LOG (FATAL) << " Error: could not find a corresponding BC ID for a collision; BC = " << globalBC << " , collisionID = " << collisionID;
12031208 }
1204-
12051209 collisionsCursor (0 ,
12061210 bcID,
12071211 truncateFloatFraction (vertex.getX (), mCollisionPosition ),
@@ -1284,6 +1288,8 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
12841288 recoData,
12851289 mcColToEvSrc);
12861290
1291+ mcColToEvSrc.clear ();
1292+
12871293 // ------------------------------------------------------
12881294 // filling track labels
12891295
0 commit comments