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;
8 SimplePedestalCalculator::SimplePedestalCalculator(int evnt_ini) : numberOfEvents(0), alreadyUsedEvent(false) {
9  if (false)
10  cout << "Constructing SimplePedestalCalculator " << 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 SimplePedestalCalculator " << endl;
33 }
34 
35 //
36 // -- Set Pedestal Update Status
37 //
41  }
42 }
43 
44 //
45 // -- Initialize or Update (when needed) Pedestal Values
46 //
48  if (alreadyUsedEvent == false) {
49  alreadyUsedEvent = true;
51  if (theStatus.isCalibrating()) {
53  } else if (theStatus.isUpdating()) {
55  }
56  updateStatus();
57  }
58 }
59 
60 //
61 // -- Initialize Pedestal Values using a set of events (eventsRequiredToCalibrate)
62 //
64  if (numberOfEvents == 1) {
65  thePedSum.clear();
66  thePedSqSum.clear();
67  theEventPerStrip.clear();
68 
69  thePedSum.reserve(128);
70  thePedSqSum.reserve(128);
71  theEventPerStrip.reserve(128);
72 
73  thePedSum.resize(in.data.size(), 0);
74  thePedSqSum.resize(in.data.size(), 0);
75  theEventPerStrip.resize(in.data.size(), 0);
76  }
77 
78  //eventsRequiredToCalibrate is considered the minimum number of events to be used
79 
82  int ii = 0;
83  for (; i != in.data.end(); i++) {
84  thePedSum[ii] += (*i).adc();
85  thePedSqSum[ii] += ((*i).adc()) * ((*i).adc());
87  ii++;
88  }
89  }
91  thePedestal.clear();
92  theRawNoise.clear();
94  int ii = 0;
95  for (; i != in.data.end(); i++) {
96  // the pedestal is calculated as int, as required by FED.
97  int avVal = (theEventPerStrip[ii]) ? thePedSum[ii] / theEventPerStrip[ii] : 0;
98 
99  double sqAvVal = (theEventPerStrip[ii]) ? thePedSqSum[ii] / theEventPerStrip[ii] : 0.0;
100  double corr_fac = (theEventPerStrip[ii] > 1) ? (theEventPerStrip[ii] / (theEventPerStrip[ii] - 1)) : 1.0;
101  double rmsVal = (sqAvVal - avVal * avVal > 0.0) ? sqrt(corr_fac * (sqAvVal - avVal * avVal)) : 0.0;
102  thePedestal.push_back(static_cast<float>(avVal));
103  theRawNoise.push_back(static_cast<float>(rmsVal));
104  ii++;
105  }
106  }
107 }
108 
109 //
110 // -- Update Pedestal Values when needed.
111 //
112 
114  // keep adding th adc count for any events
115 
116  unsigned int ii = 0;
118  for (; i < in.data.end(); i++) {
119  thePedSum[ii] += (*i).adc();
120  thePedSqSum[ii] += ((*i).adc()) * ((*i).adc());
121  theEventPerStrip[ii]++;
122 
123  ii++;
124  }
125 
126  // calculate a new pedestal any events, so it will come for free when for the last event
127 
128  for (unsigned int iii = 0; iii < in.data.size(); iii++) {
129  if (theEventPerStrip[iii] > 10) {
130  int avVal = (theEventPerStrip[iii]) ? thePedSum[iii] / theEventPerStrip[iii] : 0;
131 
132  double sqAvVal = (theEventPerStrip[iii]) ? thePedSqSum[iii] / theEventPerStrip[iii] : 0.0;
133 
134  double rmsVal = (sqAvVal - avVal * avVal > 0.0) ? sqrt(sqAvVal - avVal * avVal) : 0.0;
135 
136  if (avVal != 0) {
137  thePedestal[iii] = static_cast<float>(avVal);
138  theRawNoise[iii] = static_cast<float>(rmsVal);
139  }
140  }
141  }
142 }
143 
144 //
145 // Define New Event
146 //
147 
SimplePedestalCalculator::init
void init()
Definition: SimplePedestalCalculator.cc:19
mps_fire.i
i
Definition: mps_fire.py:428
TkStateMachine::setUpdating
void setUpdating()
Definition: TkStateMachine.h:20
funct::false
false
Definition: Factorize.h:29
SimplePedestalCalculator::thePedestal
ApvAnalysis::PedestalType thePedestal
Definition: SimplePedestalCalculator.h:37
SimplePedestalCalculator::refinePedestal
void refinePedestal(ApvAnalysis::RawSignalType &in)
Definition: SimplePedestalCalculator.cc:113
edm::DetSet
Definition: DetSet.h:23
SimplePedestalCalculator::updatePedestal
void updatePedestal(ApvAnalysis::RawSignalType &in) override
Definition: SimplePedestalCalculator.cc:47
gather_cfg.cout
cout
Definition: gather_cfg.py:144
SimplePedestalCalculator::~SimplePedestalCalculator
~SimplePedestalCalculator() override
Definition: SimplePedestalCalculator.cc:30
SimplePedestalCalculator::updateStatus
void updateStatus() override
Definition: SimplePedestalCalculator.cc:38
SimplePedestalCalculator::SimplePedestalCalculator
SimplePedestalCalculator(int evnt_ini)
Definition: SimplePedestalCalculator.cc:8
TkPedestalCalculator::theStatus
TkStateMachine theStatus
Definition: TkPedestalCalculator.h:41
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
SimplePedestalCalculator::thePedSqSum
std::vector< int > thePedSqSum
Definition: SimplePedestalCalculator.h:39
TkStateMachine::isCalibrating
bool isCalibrating() const
Definition: TkStateMachine.h:29
SimplePedestalCalculator.h
recoMuon::in
Definition: RecoMuonEnumerators.h:6
SimplePedestalCalculator::numberOfEvents
int numberOfEvents
Definition: SimplePedestalCalculator.h:41
SimplePedestalCalculator::theEventPerStrip
std::vector< unsigned short > theEventPerStrip
Definition: SimplePedestalCalculator.h:40
TkStateMachine::isUpdating
bool isUpdating() const
Definition: TkStateMachine.h:28
TkStateMachine::setCalibrating
void setCalibrating()
Definition: TkStateMachine.h:21
SimplePedestalCalculator::thePedSum
std::vector< int > thePedSum
Definition: SimplePedestalCalculator.h:39
std
Definition: JetResolutionObject.h:76
SimplePedestalCalculator::theRawNoise
ApvAnalysis::PedestalType theRawNoise
Definition: SimplePedestalCalculator.h:38
SimplePedestalCalculator::alreadyUsedEvent
bool alreadyUsedEvent
Definition: SimplePedestalCalculator.h:45
SimplePedestalCalculator::eventsRequiredToCalibrate
int eventsRequiredToCalibrate
Definition: SimplePedestalCalculator.h:42
SimplePedestalCalculator::newEvent
void newEvent() override
Definition: SimplePedestalCalculator.cc:148
cuy.ii
ii
Definition: cuy.py:589
SimplePedestalCalculator::initializePedestal
void initializePedestal(ApvAnalysis::RawSignalType &in)
Definition: SimplePedestalCalculator.cc:63
edm::DetSet::const_iterator
collection_type::const_iterator const_iterator
Definition: DetSet.h:31