@@ -281,7 +281,7 @@ void processSameEvent(T1 const& SliceParticle1,
281281 PairHistManager.fillMixingQaSe ();
282282}
283283
284- // process mixed event
284+ // mixed event in data
285285template <modes::Mode mode,
286286 typename T1,
287287 typename T2,
@@ -304,54 +304,79 @@ void processMixedEvent(T1 const& Collisions,
304304 T9& CprManager,
305305 T10& PcManager)
306306{
307- bool firstBin = true ;
308- int windowSize = 0 ;
309- PairHistManager.resetTrackedParticlesPerEvent ();
310- auto pairGenerator = o2::soa::selfCombinations (policy, depth, -1 , Collisions, Collisions);
311- for (auto pairIterator = pairGenerator.begin (); pairIterator != pairGenerator.end (); pairIterator++) {
312- auto const & [collision1, collision2] = *pairIterator;
313- if (pairIterator.isNewWindow ()) { // is true for the first bin, so we skip
314- if (!firstBin) {
315- // we fill histograms after we finish processing one mixing bin
316- // the very first bin is considered a new window, so we skp it
317- PairHistManager.fillMixingQaMePerMixingBin (windowSize);
307+ int64_t lastCollisionIndex = -1 ;
308+ int windowSizeRaw = 0 ;
309+ int windowSizeEffective = 0 ;
310+
311+ for (auto const & [collision1, collision2] : o2::soa::selfCombinations (policy, depth, -1 , Collisions, Collisions)) {
312+
313+ // --- new window ---
314+ if (collision1.globalIndex () != lastCollisionIndex) {
315+ if (lastCollisionIndex != -1 ) {
316+ PairHistManager.fillMixingQaMePerMixingBin (windowSizeRaw, windowSizeEffective);
318317 }
319- windowSize = pairIterator.currentWindowNeighbours ();
320- firstBin = false ;
318+ windowSizeRaw = 0 ;
319+ windowSizeEffective = 0 ;
320+ lastCollisionIndex = collision1.globalIndex ();
321321 }
322+
323+ ++windowSizeRaw;
324+
322325 if (collision1.magField () != collision2.magField ()) {
323- LOG (warn) << " Tried to mixng to events with different magntic field. This should not happen.. ." ;
326+ LOG (warn) << " Tried mixing events with different magnetic field." ;
324327 continue ;
325328 }
329+
326330 CprManager.setMagField (collision1.magField ());
331+
327332 auto sliceParticle1 = Partition1->sliceByCached (o2::aod::femtobase::stored::fColId , collision1.globalIndex (), cache);
333+
328334 auto sliceParticle2 = Partition2->sliceByCached (o2::aod::femtobase::stored::fColId , collision2.globalIndex (), cache);
329335
330336 PairHistManager.resetTrackedParticlesPerEvent ();
337+
338+ if (sliceParticle1.size () == 0 || sliceParticle2.size () == 0 ) {
339+ PairHistManager.fillMixingQaMePerEvent ();
340+ continue ;
341+ }
342+
343+ bool hasValidPair = false ;
331344 PairHistManager.fillMixingQaMe (collision1, collision2);
332345 for (auto const & [p1, p2] : o2::soa::combinations (o2::soa::CombinationsFullIndexPolicy (sliceParticle1, sliceParticle2))) {
333- // pair cleaning
346+
334347 if (!PcManager.isCleanPair (p1, p2, TrackTable)) {
335348 continue ;
336349 }
337- // Close pair rejection
350+
338351 CprManager.setPair (p1, p2, TrackTable);
339352 if (CprManager.isClosePair ()) {
340353 continue ;
341354 }
355+
342356 PairHistManager.setPair (p1, p2, TrackTable, collision1, collision2);
343357 CprManager.fill (PairHistManager.getKstar ());
358+
344359 if (PairHistManager.checkPairCuts ()) {
345- PairHistManager. template fill <mode>() ;
360+ hasValidPair = true ;
346361 PairHistManager.trackParticlesPerEvent (p1, p2);
362+ PairHistManager.template fill <mode>();
347363 }
348364 }
365+
366+ if (hasValidPair) {
367+ ++windowSizeEffective;
368+ }
369+
349370 PairHistManager.fillMixingQaMePerEvent ();
350371 }
351- PairHistManager.fillMixingQaMePerMixingBin (windowSize); // fill last window
372+
373+ // --- final window ---
374+ if (windowSizeRaw > 0 ) {
375+ PairHistManager.fillMixingQaMePerMixingBin (windowSizeRaw, windowSizeEffective);
376+ }
352377}
353378
354- // process mixed event with mc information
379+ // process mixed event in mc
355380template <modes::Mode mode,
356381 typename T1,
357382 typename T2,
@@ -386,64 +411,80 @@ void processMixedEvent(T1 const& Collisions,
386411 T15& CprManager,
387412 T16& PcManager)
388413{
389- bool firstBin = true ;
390- int windowSize = 0 ;
391- PairHistManager.resetTrackedParticlesPerEvent ();
392- auto pairGenerator = o2::soa::selfCombinations (policy, depth, -1 , Collisions, Collisions);
393- for (auto pairIterator = pairGenerator.begin (); pairIterator != pairGenerator.end (); ++pairIterator) {
394- auto const & [collision1, collision2] = *pairIterator;
395- // handle mixing windows (same as data)
396- if (pairIterator.isNewWindow ()) {
397- if (!firstBin) {
398- PairHistManager.fillMixingQaMePerMixingBin (windowSize);
414+ int64_t lastCollisionIndex = -1 ;
415+ int windowSizeRaw = 0 ;
416+ int windowSizeEffective = 0 ;
417+
418+ for (auto const & [collision1, collision2] : o2::soa::selfCombinations (policy, depth, -1 , Collisions, Collisions)) {
419+ if (collision1.globalIndex () != lastCollisionIndex) {
420+ if (lastCollisionIndex != -1 ) {
421+ PairHistManager.fillMixingQaMePerMixingBin (windowSizeRaw, windowSizeEffective);
399422 }
400- windowSize = pairIterator.currentWindowNeighbours ();
401- firstBin = false ;
423+ windowSizeRaw = 0 ;
424+ windowSizeEffective = 0 ;
425+ lastCollisionIndex = collision1.globalIndex ();
402426 }
427+
428+ ++windowSizeRaw;
429+
403430 if (collision1.magField () != collision2.magField ()) {
404- LOG (warn) << " Tried to mixng to events with different magntic field. This should not happen.. ." ;
431+ LOG (warn) << " Tried mixing events with different magnetic field." ;
405432 continue ;
406433 }
434+
407435 CprManager.setMagField (collision1.magField ());
408436
409- auto sliceParticle1 = Partition1->sliceByCached (
410- o2::aod::femtobase::stored::fColId ,
411- collision1.globalIndex (),
412- cache);
413- auto sliceParticle2 = Partition2->sliceByCached (
414- o2::aod::femtobase::stored::fColId ,
415- collision2.globalIndex (),
416- cache);
437+ auto sliceParticle1 = Partition1->sliceByCached (o2::aod::femtobase::stored::fColId , collision1.globalIndex (), cache);
438+
439+ auto sliceParticle2 = Partition2->sliceByCached (o2::aod::femtobase::stored::fColId , collision2.globalIndex (), cache);
417440
418441 PairHistManager.resetTrackedParticlesPerEvent ();
442+
443+ if (sliceParticle1.size () == 0 || sliceParticle2.size () == 0 ) {
444+ PairHistManager.fillMixingQaMePerEvent ();
445+ continue ;
446+ }
447+
448+ bool hasValidPair = false ;
419449 PairHistManager.fillMixingQaMe (collision1, collision2);
420- for ( auto const & [p1, p2] :
421- o2::soa::combinations (o2::soa::CombinationsFullIndexPolicy (sliceParticle1, sliceParticle2))) {
422- // particle cleaning (MC-specific)
450+
451+ for ( auto const & [p1, p2] : o2::soa::combinations (o2::soa::CombinationsFullIndexPolicy (sliceParticle1, sliceParticle2))) {
452+
423453 if (!ParticleCleaner1.isClean (p1, mcParticles, mcMothers, mcPartonicMothers) ||
424454 !ParticleCleaner2.isClean (p2, mcParticles, mcMothers, mcPartonicMothers)) {
425455 continue ;
426456 }
427- // pair cleaning
457+
428458 if (!PcManager.isCleanPair (p1, p2, TrackTable)) {
429459 continue ;
430460 }
431- // close pair rejection
461+
432462 CprManager.setPair (p1, p2, TrackTable);
433463 if (CprManager.isClosePair ()) {
434464 continue ;
435465 }
466+
436467 PairHistManager.setPairMc (p1, p2, TrackTable, mcParticles, collision1, collision2, mcCollisions);
468+
437469 CprManager.fill (PairHistManager.getKstar ());
470+
438471 if (PairHistManager.checkPairCuts ()) {
439- PairHistManager. template fill <mode>() ;
472+ hasValidPair = true ;
440473 PairHistManager.trackParticlesPerEvent (p1, p2);
474+ PairHistManager.template fill <mode>();
441475 }
442476 }
477+
478+ if (hasValidPair) {
479+ ++windowSizeEffective;
480+ }
481+
443482 PairHistManager.fillMixingQaMePerEvent ();
444483 }
445- // final window
446- PairHistManager.fillMixingQaMePerMixingBin (windowSize);
484+
485+ if (windowSizeRaw > 0 ) {
486+ PairHistManager.fillMixingQaMePerMixingBin (windowSizeRaw, windowSizeEffective);
487+ }
447488}
448489
449490} // namespace pairprocesshelpers
0 commit comments