CMS 3D CMS Logo

TT6PedestalCalculator.cc
Go to the documentation of this file.
2 
3 #include <cmath>
4 #include <numeric>
5 #include <algorithm>
6 using namespace std;
8  int evnt_iter, float sig_cut) :
9  numberOfEvents(0),
10  alreadyUsedEvent(false)
11 {
12  if (0) cout << "Constructing TT6PedestalCalculator " << 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 // -- Destructor
31 //
33  if (0) cout << "Destructing TT6PedestalCalculator " << endl;
34 }
35 //
36 // -- Set Pedestal Update Status
37 //
39 
40  if (theStatus.isCalibrating() &&
43  }
44 }
45 //
46 // -- Initialize or Update (when needed) Pedestal Values
47 //
49  if (alreadyUsedEvent == false) {
50  alreadyUsedEvent = true;
52  if (theStatus.isCalibrating()) {
54  } else if (theStatus.isUpdating()) {
55  refinePedestal(in);
56  }
57  updateStatus();
58  }
59 }
60 //
61 // -- Initialize Pedestal Values using a set of events (eventsRequiredToCalibrate)
62 //
64  if (numberOfEvents == 1) {
65 
66  thePedSum.clear();
67  thePedSqSum.clear();
68  theEventPerStrip.clear();
69 
70  thePedSum.reserve(128);
71  thePedSqSum.reserve(128);
72  theEventPerStrip.reserve(128);
73 
74  thePedSum.resize(in.data.size(), 0.0);
75  thePedSqSum.resize(in.data.size(), 0.0);
76  theEventPerStrip.resize(in.data.size(), 0);
77  }
80  int ii=0;
81  for (;i!=in.data.end() ; i++) {
82  thePedSum[ii] += (*i).adc();
83  thePedSqSum[ii] += ((*i).adc())*((*i).adc());
85  ii++;
86  }
87  }
89  thePedestal.clear();
90  theRawNoise.clear();
92  int ii=0;
93  for (;i!=in.data.end() ; i++) {
94  double avVal = (theEventPerStrip[ii]) ? thePedSum[ii]/theEventPerStrip[ii]:0.0;
95  double sqAvVal = (theEventPerStrip[ii]) ? thePedSqSum[ii]/theEventPerStrip[ii]:0.0;
96  double corr_fac = (theEventPerStrip[ii] > 1) ? (theEventPerStrip[ii]/(theEventPerStrip[ii]-1)) : 1.0;
97  double rmsVal = (sqAvVal - avVal*avVal > 0.0) ? sqrt(corr_fac * (sqAvVal - avVal*avVal)) : 0.0;
98 
99  thePedestal.push_back(static_cast<float>(avVal));
100  theRawNoise.push_back(static_cast<float>(rmsVal));
101  ii++;
102  }
103  }
104 }
105 //
106 // -- Update Pedestal Values when needed.
107 //
110 
111  thePedSum.clear();
112  thePedSqSum.clear();
113  theEventPerStrip.clear();
114 
115  thePedSum.reserve(128);
116  thePedSqSum.reserve(128);
117  theEventPerStrip.reserve(128);
118 
119  thePedSum.resize(in.data.size(), 0.0);
120  thePedSqSum.resize(in.data.size(), 0.0);
121  theEventPerStrip.resize(in.data.size(), 0);
122  }
123  unsigned int ii=0;
125  for (; i < in.data.end(); i++) {
126  if (fabs((*i).adc()-thePedestal[ii]) < cutToAvoidSignal*theRawNoise[ii]) {
127  thePedSum[ii] += (*i).adc();
128  thePedSqSum[ii] += ((*i).adc())*((*i).adc());
129  theEventPerStrip[ii]++;
130  }
131  ii++;
132  }
133  if (((numberOfEvents-eventsRequiredToCalibrate) % eventsRequiredToUpdate) == 0) {
134 
135  for (unsigned int iii = 0; iii < in.data.size(); iii++) {
136  if (theEventPerStrip[iii] > 10 ) {
137  double avVal = (theEventPerStrip[iii]) ? thePedSum[iii]/theEventPerStrip[iii]:0.0;
138  double sqAvVal = (theEventPerStrip[iii]) ? thePedSqSum[iii]/theEventPerStrip[iii]:0.0;
139  double rmsVal = (sqAvVal - avVal*avVal > 0.0) ? sqrt(sqAvVal - avVal*avVal) : 0.0;
140 
141 
142  if (avVal != 0 ) {
143  thePedestal[iii] = static_cast<float>(avVal);
144  theRawNoise[iii] = static_cast<float>(rmsVal);
145  }
146  }
147  }
148  thePedSum.clear();
149  thePedSqSum.clear();
150  theEventPerStrip.clear();
151  }
152  }
153  //
154  // Define New Event
155 //
157  alreadyUsedEvent = false;
158 }
std::vector< unsigned short > theEventPerStrip
ApvAnalysis::PedestalType theRawNoise
TT6PedestalCalculator(int evnt_ini, int evnt_iter, float sig_cut)
void initializePedestal(ApvAnalysis::RawSignalType &in)
T sqrt(T t)
Definition: SSEVec.h:18
void refinePedestal(ApvAnalysis::RawSignalType &in)
std::vector< double > thePedSum
ApvAnalysis::PedestalType thePedestal
bool isUpdating() const
ii
Definition: cuy.py:588
bool isCalibrating() const
collection_type data
Definition: DetSet.h:78
std::vector< double > thePedSqSum
void setCalibrating()
void updatePedestal(ApvAnalysis::RawSignalType &in)
collection_type::const_iterator const_iterator
Definition: DetSet.h:33