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 //
mps_fire.i
i
Definition: mps_fire.py:355
TkStateMachine::setUpdating
void setUpdating()
Definition: TkStateMachine.h:20
funct::false
false
Definition: Factorize.h:34
edm::DetSet
Definition: DetSet.h:23
TT6PedestalCalculator::theEventPerStrip
std::vector< unsigned short > theEventPerStrip
Definition: TT6PedestalCalculator.h:40
gather_cfg.cout
cout
Definition: gather_cfg.py:144
TT6PedestalCalculator::TT6PedestalCalculator
TT6PedestalCalculator(int evnt_ini, int evnt_iter, float sig_cut)
Definition: TT6PedestalCalculator.cc:7
TT6PedestalCalculator::eventsRequiredToCalibrate
int eventsRequiredToCalibrate
Definition: TT6PedestalCalculator.h:42
TT6PedestalCalculator.h
TT6PedestalCalculator::updateStatus
void updateStatus() override
Definition: TT6PedestalCalculator.cc:37
TT6PedestalCalculator::cutToAvoidSignal
float cutToAvoidSignal
Definition: TT6PedestalCalculator.h:44
TT6PedestalCalculator::theRawNoise
ApvAnalysis::PedestalType theRawNoise
Definition: TT6PedestalCalculator.h:38
TkPedestalCalculator::theStatus
TkStateMachine theStatus
Definition: TkPedestalCalculator.h:41
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
TT6PedestalCalculator::initializePedestal
void initializePedestal(ApvAnalysis::RawSignalType &in)
Definition: TT6PedestalCalculator.cc:60
TkStateMachine::isCalibrating
bool isCalibrating() const
Definition: TkStateMachine.h:29
TT6PedestalCalculator::eventsRequiredToUpdate
int eventsRequiredToUpdate
Definition: TT6PedestalCalculator.h:43
TT6PedestalCalculator::~TT6PedestalCalculator
~TT6PedestalCalculator() override
Definition: TT6PedestalCalculator.cc:30
recoMuon::in
Definition: RecoMuonEnumerators.h:6
TT6PedestalCalculator::thePedSum
std::vector< double > thePedSum
Definition: TT6PedestalCalculator.h:39
TkStateMachine::isUpdating
bool isUpdating() const
Definition: TkStateMachine.h:28
TkStateMachine::setCalibrating
void setCalibrating()
Definition: TkStateMachine.h:21
TT6PedestalCalculator::refinePedestal
void refinePedestal(ApvAnalysis::RawSignalType &in)
Definition: TT6PedestalCalculator.cc:104
std
Definition: JetResolutionObject.h:76
TT6PedestalCalculator::init
void init()
Definition: TT6PedestalCalculator.cc:19
TT6PedestalCalculator::numberOfEvents
int numberOfEvents
Definition: TT6PedestalCalculator.h:41
TT6PedestalCalculator::newEvent
void newEvent() override
Definition: TT6PedestalCalculator.cc:149
TT6PedestalCalculator::thePedSqSum
std::vector< double > thePedSqSum
Definition: TT6PedestalCalculator.h:39
TT6PedestalCalculator::thePedestal
ApvAnalysis::PedestalType thePedestal
Definition: TT6PedestalCalculator.h:37
TT6PedestalCalculator::updatePedestal
void updatePedestal(ApvAnalysis::RawSignalType &in) override
Definition: TT6PedestalCalculator.cc:45
TT6PedestalCalculator::alreadyUsedEvent
bool alreadyUsedEvent
Definition: TT6PedestalCalculator.h:45
cuy.ii
ii
Definition: cuy.py:590
edm::DetSet::const_iterator
collection_type::const_iterator const_iterator
Definition: DetSet.h:31