CMS 3D CMS Logo

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