Belle II Software  release-05-01-25
utilities.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Nils Braun *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <hlt/softwaretrigger/core/utilities.h>
12 #include <TRandom.h>
13 
14 namespace Belle2 {
19  namespace SoftwareTrigger {
20  bool makePreScale(const unsigned int& preScaleFactor, uint32_t* counter)
21  {
22  // A prescale factor of one is always true...
23  if (preScaleFactor == 1) {
24  return true;
25  // ... and a prescale factor of 0 is always false...
26  } else if (preScaleFactor == 0) {
27  return false;
28  } else {
29  // All other cases are a bit more interesting.
30  if (not counter) {
31  // We do this by drawing a random number between 0 and preScaleFactor - 1 and comparing it to 0.
32  // The probability to get back a true result is then given by 1/preScaleFactor.
33  const unsigned int randomNumber = gRandom->Integer(preScaleFactor);
34  return randomNumber == 0;
35  } else {
36  // Similar as above, but using the remainder between the counter and preScaleFactor.
37  // If the remainder is not 0 we increment the counter, otherwise we reset the counter.
38  const auto remainder = *counter % preScaleFactor;
39  *counter = (remainder == 0) ? 1 : *counter + 1;
40  return remainder == 0;
41  }
42  }
43  }
44  }
46 }
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19