Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mc2coda_random.cc
Go to the documentation of this file.
1 #include <stdint.h>
2 #include <cmath>
3 using namespace std;
4 
5 #include <TRandom2.h>
6 
7 static TRandom2 randgen;
8 bool NO_PEDESTAL = true; // flag to completely disable pedestal generation
9 bool NO_RANDOM_PEDESTAL = false; // turn off random components of pedestals
10 float MEAN_PEDESTAL = 100.0; // mean pedestal in single sample fADC counts
11 float SIGMA_COMMON_PEDESTAL = 4.0; // common mode noise in single sample fADC counts
12 float SIGMA_INDIVIDUAL_PEDESTAL = 3.0; // stochastic noise in single sample fADC counts
13 
14 
15 extern "C" {
16  void GetPedestals(uint32_t *peds, uint32_t Npeds);
17 }
18 
19 void GetPedestals(uint32_t *peds, uint32_t Npeds)
20 {
21  /// Generate a set of pedestal values based on the global variables.
22  /// Ths will fill in the first Npeds-1 values in "peds" with a pedestal
23  /// near zero and Npeds-th value will be near the mean pedestal setting.
24  /// The idea is that the last value delivered will contain the mean
25  /// pedestal for all channels in the module plus common mode noise.
26  /// The first set of values will contain individual pedestal fluctuations
27  /// for each channel. The f250 and f125 will use the one common pedestal
28  /// to adjust the pulse integral and pulse peak values. For the measured
29  /// pedestals output in Pulse Pedestal words, the stochastic part is added
30  /// in as well to represent the inaccuracy of that measurement. Note that
31  /// this means the actual pedestal value used is not actually written
32  /// to the output file anywhere.
33  ///
34  /// If the global boolean NO_PEDESTAL is set to true, then all values
35  /// will be set to zero.
36  ///
37  /// If the global NO_RANDOM_PEDESTAL is set to true, then the first
38  /// Npeds-1 values will be set to zero and the last value to the mean
39  /// pedestal (=MEAN_PEDESTAL) with no random variation.
40  ///
41  /// The values MEAN_PEDESTAL, SIGMA_COMMON_PEDESTAL, and
42  /// SIGMA_INDIVIDUAL_PEDESTAL are used to calculate the values. Random
43  /// sampling is done from Gaussian's with the specified sigmas.
44 
45  if(NO_PEDESTAL){
46  for(uint32_t i=0; i<Npeds; i++) peds[i] = 0;
47  }else if(NO_RANDOM_PEDESTAL){
48  for(uint32_t i=0; i<Npeds-1; i++) peds[i] = 0;
49  peds[Npeds - 1] = (uint32_t)MEAN_PEDESTAL;
50  }else{
51  for(uint32_t i=0; i<Npeds-1; i++) peds[i] = round(randgen.Gaus(0.0, SIGMA_INDIVIDUAL_PEDESTAL));
52  peds[Npeds - 1] = round(randgen.Gaus(MEAN_PEDESTAL, SIGMA_COMMON_PEDESTAL));
53  }
54 
55 }
56 
float SIGMA_COMMON_PEDESTAL
bool NO_RANDOM_PEDESTAL
float MEAN_PEDESTAL
float SIGMA_INDIVIDUAL_PEDESTAL
bool NO_PEDESTAL
void GetPedestals(uint32_t *peds, uint32_t Npeds)
static TRandom2 randgen