Belle II Software development
utilities.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <hlt/softwaretrigger/core/utilities.h>
10#include <TRandom.h>
11
12namespace Belle2 {
17 namespace SoftwareTrigger {
18 bool makePreScale(const unsigned int& preScaleFactor, uint32_t* counter)
19 {
20 // A prescale factor of one is always true...
21 if (preScaleFactor == 1) {
22 return true;
23 // ... and a prescale factor of 0 is always false...
24 } else if (preScaleFactor == 0) {
25 return false;
26 } else {
27 // All other cases are a bit more interesting.
28 if (not counter) {
29 // We do this by drawing a random number between 0 and preScaleFactor - 1 and comparing it to 0.
30 // The probability to get back a true result is then given by 1/preScaleFactor.
31 const unsigned int randomNumber = gRandom->Integer(preScaleFactor);
32 return randomNumber == 0;
33 } else {
34 // Similar as above, but using the remainder between the counter and preScaleFactor.
35 // If the remainder is not 0 we increment the counter, otherwise we reset the counter.
36 const auto remainder = *counter % preScaleFactor;
37 *counter = (remainder == 0) ? 1 : *counter + 1;
38 return remainder == 0;
39 }
40 }
41 }
42 }
44}
Abstract base class for different kinds of events.