CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SimplePedestalCalculator.cc
Go to the documentation of this file.
2 
3 #include <cmath>
4 #include <numeric>
5 #include <algorithm>
6 
7 using namespace std;
8 SimplePedestalCalculator::SimplePedestalCalculator(int evnt_ini) : numberOfEvents(0), alreadyUsedEvent(false) {
9  if (false)
10  cout << "Constructing SimplePedestalCalculator " << endl;
11  eventsRequiredToCalibrate = evnt_ini;
12  // eventsRequiredToUpdate = evnt_iter;
13  // cutToAvoidSignal = sig_cut;
14  init();
15 }
16 //
17 // Initialization.
18 //
20  theRawNoise.clear();
21  thePedestal.clear();
22  thePedSum.clear();
23  thePedSqSum.clear();
24  theEventPerStrip.clear();
26 }
27 //
28 // -- Destructor
29 //
31  if (false)
32  cout << "Destructing SimplePedestalCalculator " << endl;
33 }
34 
35 //
36 // -- Set Pedestal Update Status
37 //
41  }
42 }
43 
44 //
45 // -- Initialize or Update (when needed) Pedestal Values
46 //
48  if (alreadyUsedEvent == false) {
49  alreadyUsedEvent = true;
51  if (theStatus.isCalibrating()) {
53  } else if (theStatus.isUpdating()) {
54  refinePedestal(in);
55  }
56  updateStatus();
57  }
58 }
59 
60 //
61 // -- Initialize Pedestal Values using a set of events (eventsRequiredToCalibrate)
62 //
64  if (numberOfEvents == 1) {
65  thePedSum.clear();
66  thePedSqSum.clear();
67  theEventPerStrip.clear();
68 
69  thePedSum.reserve(128);
70  thePedSqSum.reserve(128);
71  theEventPerStrip.reserve(128);
72 
73  thePedSum.resize(in.data.size(), 0);
74  thePedSqSum.resize(in.data.size(), 0);
75  theEventPerStrip.resize(in.data.size(), 0);
76  }
77 
78  //eventsRequiredToCalibrate is considered the minimum number of events to be used
79 
82  int ii = 0;
83  for (; i != in.data.end(); i++) {
84  thePedSum[ii] += (*i).adc();
85  thePedSqSum[ii] += ((*i).adc()) * ((*i).adc());
87  ii++;
88  }
89  }
91  thePedestal.clear();
92  theRawNoise.clear();
94  int ii = 0;
95  for (; i != in.data.end(); i++) {
96  // the pedestal is calculated as int, as required by FED.
97  int avVal = (theEventPerStrip[ii]) ? thePedSum[ii] / theEventPerStrip[ii] : 0;
98 
99  double sqAvVal = (theEventPerStrip[ii]) ? thePedSqSum[ii] / theEventPerStrip[ii] : 0.0;
100  double corr_fac = (theEventPerStrip[ii] > 1) ? (theEventPerStrip[ii] / (theEventPerStrip[ii] - 1)) : 1.0;
101  double rmsVal = (sqAvVal - avVal * avVal > 0.0) ? sqrt(corr_fac * (sqAvVal - avVal * avVal)) : 0.0;
102  thePedestal.push_back(static_cast<float>(avVal));
103  theRawNoise.push_back(static_cast<float>(rmsVal));
104  ii++;
105  }
106  }
107 }
108 
109 //
110 // -- Update Pedestal Values when needed.
111 //
112 
114  // keep adding th adc count for any events
115 
116  unsigned int ii = 0;
118  for (; i < in.data.end(); i++) {
119  thePedSum[ii] += (*i).adc();
120  thePedSqSum[ii] += ((*i).adc()) * ((*i).adc());
121  theEventPerStrip[ii]++;
122 
123  ii++;
124  }
125 
126  // calculate a new pedestal any events, so it will come for free when for the last event
127 
128  for (unsigned int iii = 0; iii < in.data.size(); iii++) {
129  if (theEventPerStrip[iii] > 10) {
130  int avVal = (theEventPerStrip[iii]) ? thePedSum[iii] / theEventPerStrip[iii] : 0;
131 
132  double sqAvVal = (theEventPerStrip[iii]) ? thePedSqSum[iii] / theEventPerStrip[iii] : 0.0;
133 
134  double rmsVal = (sqAvVal - avVal * avVal > 0.0) ? sqrt(sqAvVal - avVal * avVal) : 0.0;
135 
136  if (avVal != 0) {
137  thePedestal[iii] = static_cast<float>(avVal);
138  theRawNoise[iii] = static_cast<float>(rmsVal);
139  }
140  }
141  }
142 }
143 
144 //
145 // Define New Event
146 //
147 
std::vector< unsigned short > theEventPerStrip
void updatePedestal(ApvAnalysis::RawSignalType &in) override
int ii
Definition: cuy.py:589
T sqrt(T t)
Definition: SSEVec.h:19
ApvAnalysis::PedestalType theRawNoise
bool isUpdating() const
bool isCalibrating() const
collection_type data
Definition: DetSet.h:80
void setCalibrating()
tuple cout
Definition: gather_cfg.py:144
void refinePedestal(ApvAnalysis::RawSignalType &in)
collection_type::const_iterator const_iterator
Definition: DetSet.h:31
void initializePedestal(ApvAnalysis::RawSignalType &in)
ApvAnalysis::PedestalType thePedestal