@@ -168,85 +168,41 @@ int FastMultEst::selectROFs(const std::array<gsl::span<const o2::itsmft::ROFReco
168168 ROFMaskTableN& sel)
169169{
170170 const auto & multEstConf = FastMultEstConfig::Instance (); // parameters for mult estimation and cuts
171- const int selectionLayer = overlapView.getClock ();
172- int multLayer = std::clamp (multEstConf.cutMultClusLayer , 0 , NLayers - 1 );
173- if (doStaggering && rofs[multLayer].empty ()) {
174- LOGP (info, " FastMultEst multiplicity layer {} has no ROFs, falling back to selection layer {}" , multLayer, selectionLayer);
175- multLayer = selectionLayer;
176- }
177-
178- const auto multCounts = buildMultiplicityCounts<NLayers>(rofs, clus, doStaggering, multLayer);
171+ const int selectionLayer = multEstConf.isMultCutRequested () ? std::clamp (multEstConf.cutMultClusLayer , 0 , NLayers - 1 ) : overlapView.getClock ();
172+ const auto multCounts = buildMultiplicityCounts<NLayers>(rofs, clus, doStaggering, selectionLayer);
179173 const int selectionRofCount = doStaggering ? static_cast <int >(rofs[selectionLayer].size ()) : static_cast <int >(rofs[0 ].size ());
180174
181175 sel.resetMask ();
182176 lastRandomSeed = gRandom ->GetSeed ();
183177 const o2::InteractionRecord tfStartIR{0 , firstTForbit};
184-
185- if (!trig.empty ()) {
178+ // mask ROFs which are not good from the multiplicity selection (if any) POV
179+ struct ROFStatus {
180+ int entry = 0 , priority = 0 ;
181+ };
182+ std::vector<ROFStatus> selROFs;
183+ selROFs.reserve (selectionRofCount);
184+ bool selmult = multEstConf.isMultCutRequested ();
185+ for (int selectionRof = 0 ; selectionRof < selectionRofCount; ++selectionRof) {
186+ selROFs.emplace_back (selectionRof, (selmult && !multEstConf.isPassingMultCut (process (multCounts[selectionRof]))) ? -1 : 0 );
187+ }
188+ if (!trig.empty () && multEstConf.preferTriggered ) {
186189 const auto & selectionLayerTiming = overlapView.getLayer (selectionLayer);
187- const auto & multLayerTiming = overlapView.getLayer (multLayer);
188-
189190 for (const auto & trigger : trig) {
190191 const int selectionRof = findROFForIR (trigger.ir , tfStartIR, selectionLayerTiming);
191- if (selectionRof < 0 ) {
192- continue ;
193- }
194- if (multEstConf.cutRandomFraction > 0 .f && gRandom ->Rndm () < multEstConf.cutRandomFraction ) {
195- continue ;
196- }
197- if (multEstConf.isMultCutRequested ()) {
198- const int triggerMultRof = doStaggering ? findROFForIR (trigger.ir , tfStartIR, multLayerTiming) : selectionRof;
199- if (triggerMultRof < 0 || triggerMultRof >= static_cast <int >(multCounts.size ())) {
200- continue ;
201- }
202- if (!multEstConf.isPassingMultCut (process (multCounts[triggerMultRof]))) {
203- continue ;
204- }
205- }
206- enableCompatibleROFs<NLayers>(selectionLayer, selectionRof, overlapView, sel);
207- }
208- } else {
209- LOGP (info, " FastMultEst received no physics/TRD triggers, falling back to ROF-driven filtering on layer {}" , selectionLayer);
210- for (int selectionRof = 0 ; selectionRof < selectionRofCount; ++selectionRof) {
211- if (multEstConf.isMultCutRequested ()) {
212- bool passes = false ;
213- if (!doStaggering || selectionLayer == multLayer) {
214- if (selectionRof < static_cast <int >(multCounts.size ())) {
215- passes = multEstConf.isPassingMultCut (process (multCounts[selectionRof]));
216- }
217- } else {
218- const auto & overlap = overlapView.getOverlap (selectionLayer, multLayer, selectionRof);
219- for (int rof = overlap.getFirstEntry (); rof < overlap.getEntriesBound (); ++rof) {
220- if (rof < static_cast <int >(multCounts.size ())) {
221- if (multEstConf.isPassingMultCut (process (multCounts[rof]))) {
222- passes = true ;
223- break ;
224- }
225- }
226- }
227- }
228- if (!passes) {
229- continue ;
230- }
231- }
232- if (multEstConf.cutRandomFraction > 0 .f && gRandom ->Rndm () < multEstConf.cutRandomFraction ) {
192+ if (selectionRof < 0 || selROFs[selectionRof].priority < 0 ) {
233193 continue ;
234194 }
235- enableCompatibleROFs<NLayers>(selectionLayer, selectionRof, overlapView, sel);
195+ selROFs[ selectionRof]. priority ++; // increment trigger counter
236196 }
197+ sort (selROFs.begin (), selROFs.end (), [](const ROFStatus& a, const ROFStatus& b) { return a.priority > b.priority ; }); // order in number of triggers, masked will go to the end
237198 }
238-
239- const auto selView = sel.getView ();
240199 int nsel = 0 ;
241- for (int irof = 0 ; irof < selectionRofCount; ++irof) {
242- nsel += selView.isROFEnabled (selectionLayer, irof);
243- }
244-
245- if (!trig.empty () && multEstConf.preferTriggered ) {
246- LOGP (debug, " FastMultEst preferTriggered is ignored in trigger-driven mask mode" );
200+ for (auto & rof : selROFs) {
201+ if (rof.priority >= 0 && (multEstConf.cutRandomFraction <= 0 .f || (gRandom ->Rndm () > multEstConf.cutRandomFraction ))) {
202+ enableCompatibleROFs<NLayers>(selectionLayer, rof.entry , overlapView, sel);
203+ nsel++;
204+ }
247205 }
248-
249206 LOGP (debug, " NSel = {} of {} rofs on layer {} Seeds: before {} after {}" , nsel, selectionRofCount, selectionLayer, lastRandomSeed, gRandom ->GetSeed ());
250-
251207 return nsel;
252208}
0 commit comments