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;
7 TT6PedestalCalculator::TT6PedestalCalculator(int evnt_ini, int evnt_iter, float sig_cut)
8  : numberOfEvents(0), alreadyUsedEvent(false) {
9  if (false)
10  cout << "Constructing TT6PedestalCalculator " << 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 TT6PedestalCalculator " << endl;
33 }
34 //
35 // -- Set Pedestal Update Status
36 //
40  }
41 }
42 //
43 // -- Initialize or Update (when needed) Pedestal Values
44 //
46  if (alreadyUsedEvent == false) {
47  alreadyUsedEvent = true;
49  if (theStatus.isCalibrating()) {
51  } else if (theStatus.isUpdating()) {
53  }
54  updateStatus();
55  }
56 }
57 //
58 // -- Initialize Pedestal Values using a set of events (eventsRequiredToCalibrate)
59 //
61  if (numberOfEvents == 1) {
62  thePedSum.clear();
63  thePedSqSum.clear();
64  theEventPerStrip.clear();
65 
66  thePedSum.reserve(128);
67  thePedSqSum.reserve(128);
68  theEventPerStrip.reserve(128);
69 
70  thePedSum.resize(in.data.size(), 0.0);
71  thePedSqSum.resize(in.data.size(), 0.0);
72  theEventPerStrip.resize(in.data.size(), 0);
73  }
76  int ii = 0;
77  for (; i != in.data.end(); i++) {
78  thePedSum[ii] += (*i).adc();
79  thePedSqSum[ii] += ((*i).adc()) * ((*i).adc());
81  ii++;
82  }
83  }
85  thePedestal.clear();
86  theRawNoise.clear();
88  int ii = 0;
89  for (; i != in.data.end(); i++) {
90  double avVal = (theEventPerStrip[ii]) ? thePedSum[ii] / theEventPerStrip[ii] : 0.0;
91  double sqAvVal = (theEventPerStrip[ii]) ? thePedSqSum[ii] / theEventPerStrip[ii] : 0.0;
92  double corr_fac = (theEventPerStrip[ii] > 1) ? (theEventPerStrip[ii] / (theEventPerStrip[ii] - 1)) : 1.0;
93  double rmsVal = (sqAvVal - avVal * avVal > 0.0) ? sqrt(corr_fac * (sqAvVal - avVal * avVal)) : 0.0;
94 
95  thePedestal.push_back(static_cast<float>(avVal));
96  theRawNoise.push_back(static_cast<float>(rmsVal));
97  ii++;
98  }
99  }
100 }
101 //
102 // -- Update Pedestal Values when needed.
103 //
106  thePedSum.clear();
107  thePedSqSum.clear();
108  theEventPerStrip.clear();
109 
110  thePedSum.reserve(128);
111  thePedSqSum.reserve(128);
112  theEventPerStrip.reserve(128);
113 
114  thePedSum.resize(in.data.size(), 0.0);
115  thePedSqSum.resize(in.data.size(), 0.0);
116  theEventPerStrip.resize(in.data.size(), 0);
117  }
118  unsigned int ii = 0;
120  for (; i < in.data.end(); i++) {
121  if (fabs((*i).adc() - thePedestal[ii]) < cutToAvoidSignal * theRawNoise[ii]) {
122  thePedSum[ii] += (*i).adc();
123  thePedSqSum[ii] += ((*i).adc()) * ((*i).adc());
124  theEventPerStrip[ii]++;
125  }
126  ii++;
127  }
129  for (unsigned int iii = 0; iii < in.data.size(); iii++) {
130  if (theEventPerStrip[iii] > 10) {
131  double avVal = (theEventPerStrip[iii]) ? thePedSum[iii] / theEventPerStrip[iii] : 0.0;
132  double sqAvVal = (theEventPerStrip[iii]) ? thePedSqSum[iii] / theEventPerStrip[iii] : 0.0;
133  double rmsVal = (sqAvVal - avVal * avVal > 0.0) ? sqrt(sqAvVal - avVal * avVal) : 0.0;
134 
135  if (avVal != 0) {
136  thePedestal[iii] = static_cast<float>(avVal);
137  theRawNoise[iii] = static_cast<float>(rmsVal);
138  }
139  }
140  }
141  thePedSum.clear();
142  thePedSqSum.clear();
143  theEventPerStrip.clear();
144  }
145 }
146 //
147 // Define New Event
148 //
bool isUpdating() const
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:23
void refinePedestal(ApvAnalysis::RawSignalType &in)
std::vector< double > thePedSum
bool isCalibrating() const
void updatePedestal(ApvAnalysis::RawSignalType &in) override
ApvAnalysis::PedestalType thePedestal
ii
Definition: cuy.py:589
std::vector< double > thePedSqSum
void setCalibrating()
collection_type::const_iterator const_iterator
Definition: DetSet.h:31