2424
2525#include < Rtypes.h>
2626
27+ #include < algorithm>
2728#include < array>
2829#include < iostream>
2930#include < map>
@@ -39,8 +40,8 @@ class MixingHandler : public TNamed
3940 float eta;
4041 float phi;
4142 uint32_t filteringFlags;
42- // flip a bit to zero (needed when a track was already used in mixing for that bit for the required pool depth)
43- void FlipBit ( int64_t mask) { filteringFlags ^= mask; }
43+ // Clear a bit once the track was used in mixing for that bit for the required pool depth.
44+ void ClearBit ( uint32_t mask) { filteringFlags &= ~ mask; }
4445 void Print () const
4546 {
4647 std::cout << " pt: " << pt << " , eta: " << eta << " , phi: " << phi << " , filteringFlags: " << filteringFlags << std::endl;
@@ -68,32 +69,40 @@ class MixingHandler : public TNamed
6869 tracks2.push_back (track);
6970 filteringMask |= track.filteringFlags ;
7071 }
71- // flip bits in the filtering mask
72- void FlipFilteringMask ( int64_t mask) { filteringMask ^= mask; }
72+ // Clear bits in the filtering mask.
73+ void ClearFilteringMask ( uint32_t mask) { filteringMask &= ~ mask; }
7374 // 1) increment the counters for a given track cut bit mask and if the counters reached the pool depth,
74- // 2) flip the corresponding bit in the tracks filtering flags to exclude them from further mixing
75+ // 2) clear the corresponding bit in the tracks filtering flags to exclude them from further mixing
7576 // 3) for each track, if there are no more active bits in the filtering mask, then remove the track from the event
7677 void IncrementCounters (uint32_t mask, short poolDepth)
7778 {
7879 for (int i = 0 ; i < 32 ; i++) {
79- if (mask & (1ULL << i)) {
80+ uint32_t bitMask = (static_cast <uint32_t >(1 ) << i);
81+ if (mask & bitMask) {
8082 counters[i]++;
8183 if (counters[i] >= poolDepth) {
8284 for (auto & track : tracks1) {
83- track.FlipBit (1ULL << i);
84- if (track.filteringFlags == 0 ) {
85- track = tracks1.back ();
86- tracks1.pop_back ();
85+ track.ClearBit (bitMask);
86+ }
87+ for (auto track = tracks1.begin (); track != tracks1.end ();) {
88+ if (track->filteringFlags == 0 ) {
89+ track = tracks1.erase (track);
90+ } else {
91+ ++track;
8792 }
8893 }
94+
8995 for (auto & track : tracks2) {
90- track.FlipBit (1ULL << i);
91- if (track.filteringFlags == 0 ) {
92- track = tracks2.back ();
93- tracks2.pop_back ();
96+ track.ClearBit (bitMask);
97+ }
98+ for (auto track = tracks2.begin (); track != tracks2.end ();) {
99+ if (track->filteringFlags == 0 ) {
100+ track = tracks2.erase (track);
101+ } else {
102+ ++track;
94103 }
95104 }
96- FlipFilteringMask ( 1ULL << i );
105+ ClearFilteringMask (bitMask );
97106 }
98107 }
99108 }
@@ -131,9 +140,13 @@ class MixingHandler : public TNamed
131140 // check which events in the pool are empty (i.e. no active tracks for mixing) and remove them from the pool
132141 void CleanPool ()
133142 {
134- events.erase (std::remove_if (events.begin (), events.end (),
135- [](const MixingEvent& event) { return event.tracks1 .empty () && event.tracks2 .empty (); }),
136- events.end ());
143+ for (auto event = events.begin (); event != events.end ();) {
144+ if (event->tracks1 .empty () && event->tracks2 .empty ()) {
145+ event = events.erase (event);
146+ } else {
147+ ++event;
148+ }
149+ }
137150 }
138151 // The function that performs the mixing is called outside this class, but the pool provides the events and tracks to be mixed and takes care of updating the events after mixing
139152 // (e.g. incrementing the counters and removing the tracks that reached the pool depth for a given cut)
0 commit comments