CMS 3D CMS Logo

SimplePedestalCalculator.cc
Go to the documentation of this file.
2 
3 #include <cmath>
4 #include <numeric>
5 #include <algorithm>
6 
7 using namespace std;
9  numberOfEvents(0),
10  alreadyUsedEvent(false)
11 {
12  if (false) cout << "Constructing SimplePedestalCalculator " << endl;
13  eventsRequiredToCalibrate = evnt_ini;
14  // eventsRequiredToUpdate = evnt_iter;
15  // cutToAvoidSignal = sig_cut;
16  init();
17 }
18 //
19 // Initialization.
20 //
22  theRawNoise.clear();
23  thePedestal.clear();
24  thePedSum.clear();
25  thePedSqSum.clear();
26  theEventPerStrip.clear();
28 
29 }
30 //
31 // -- Destructor
32 //
34  if (false) cout << "Destructing SimplePedestalCalculator " << endl;
35 }
36 
37 
38 //
39 // -- Set Pedestal Update Status
40 //
42  if (theStatus.isCalibrating() &&
45  }
46 }
47 
48 
49 //
50 // -- Initialize or Update (when needed) Pedestal Values
51 //
53 
54  if (alreadyUsedEvent == false) {
55  alreadyUsedEvent = true;
57  if (theStatus.isCalibrating()) {
59  } else if (theStatus.isUpdating()) {
60  refinePedestal(in);
61  }
62  updateStatus();
63  }
64 
65 
66 }
67 
68 //
69 // -- Initialize Pedestal Values using a set of events (eventsRequiredToCalibrate)
70 //
72  if (numberOfEvents == 1) {
73 
74  thePedSum.clear();
75  thePedSqSum.clear();
76  theEventPerStrip.clear();
77 
78  thePedSum.reserve(128);
79  thePedSqSum.reserve(128);
80  theEventPerStrip.reserve(128);
81 
82  thePedSum.resize(in.data.size(), 0);
83  thePedSqSum.resize(in.data.size(), 0);
84  theEventPerStrip.resize(in.data.size(),0);
85  }
86 
87  //eventsRequiredToCalibrate is considered the minimum number of events to be used
88 
91  int ii=0;
92  for (;i!=in.data.end() ; i++) {
93  thePedSum[ii] += (*i).adc();
94  thePedSqSum[ii] += ((*i).adc())*((*i).adc());
96  ii++;
97  }
98  }
100  thePedestal.clear();
101  theRawNoise.clear();
103  int ii=0;
104  for (;i!=in.data.end() ; i++) {
105 
106 
107  // the pedestal is calculated as int, as required by FED.
108  int avVal = (theEventPerStrip[ii])
109  ? thePedSum[ii]/theEventPerStrip[ii]:0;
110 
111  double sqAvVal = (theEventPerStrip[ii])
112  ? thePedSqSum[ii]/theEventPerStrip[ii]:0.0;
113  double corr_fac = (theEventPerStrip[ii] > 1)
114  ? (theEventPerStrip[ii]/(theEventPerStrip[ii]-1)) : 1.0;
115  double rmsVal = (sqAvVal - avVal*avVal > 0.0)
116  ? sqrt(corr_fac * (sqAvVal - avVal*avVal)) : 0.0;
117  thePedestal.push_back(static_cast<float>(avVal));
118  theRawNoise.push_back(static_cast<float>(rmsVal));
119  ii++;
120  }
121 
122  }
123 }
124 
125 //
126 // -- Update Pedestal Values when needed.
127 //
128 
130 
131 
132  // keep adding th adc count for any events
133 
134  unsigned int ii=0;
136  for (; i < in.data.end(); i++) {
137 
138  thePedSum[ii] += (*i).adc();
139  thePedSqSum[ii] += ((*i).adc())*((*i).adc());
140  theEventPerStrip[ii]++;
141 
142  ii++;
143  }
144 
145 
146  // calculate a new pedestal any events, so it will come for free when for the last event
147 
148  for (unsigned int iii = 0; iii < in.data.size(); iii++) {
149  if (theEventPerStrip[iii] > 10 ) {
150  int avVal = (theEventPerStrip[iii])
151  ? thePedSum[iii]/theEventPerStrip[iii]:0;
152 
153  double sqAvVal = (theEventPerStrip[iii])
154  ? thePedSqSum[iii]/theEventPerStrip[iii]:0.0;
155 
156  double rmsVal = (sqAvVal - avVal*avVal > 0.0)
157  ? sqrt(sqAvVal - avVal*avVal) : 0.0;
158 
159 
160  if (avVal != 0 ) {
161  thePedestal[iii] = static_cast<float>(avVal);
162  theRawNoise[iii] = static_cast<float>(rmsVal);
163  }
164  }
165  }
166 
167 }
168 
169 
170 
171 
172 
173 //
174 // Define New Event
175 //
176 
178  alreadyUsedEvent = false;
179 }
std::vector< unsigned short > theEventPerStrip
void updatePedestal(ApvAnalysis::RawSignalType &in) override
T sqrt(T t)
Definition: SSEVec.h:18
ApvAnalysis::PedestalType theRawNoise
bool isUpdating() const
ii
Definition: cuy.py:588
bool isCalibrating() const
collection_type data
Definition: DetSet.h:78
void setCalibrating()
void refinePedestal(ApvAnalysis::RawSignalType &in)
collection_type::const_iterator const_iterator
Definition: DetSet.h:33
void initializePedestal(ApvAnalysis::RawSignalType &in)
ApvAnalysis::PedestalType thePedestal