CMS 3D CMS Logo

SimpleNoiseCalculator.cc
Go to the documentation of this file.
3 #include <cmath>
4 #include <numeric>
5 #include <algorithm>
6 using namespace std;
7 //
8 // Constructors
9 //
10 SimpleNoiseCalculator::SimpleNoiseCalculator() : numberOfEvents(0), alreadyUsedEvent(false) {
11  if (false)
12  cout << "Constructing SimpleNoiseCalculator " << endl;
13  init();
14 }
15 //
16 SimpleNoiseCalculator::SimpleNoiseCalculator(int evnt_ini, bool use_DB) : numberOfEvents(0), alreadyUsedEvent(false) {
17  if (false)
18  cout << "Constructing SimpleNoiseCalculator " << endl;
19  useDB_ = use_DB;
20  eventsRequiredToCalibrate_ = evnt_ini;
21  // eventsRequiredToUpdate_ = evnt_iter;
22  // cutToAvoidSignal_ = sig_cut;
23  init();
24 }
25 //
26 // Initialization.
27 //
29  theCMPSubtractedSignal.clear();
30  theNoise.clear();
31  theNoiseSum.clear();
32  theNoiseSqSum.clear();
33  theEventPerStrip.clear();
34  // theStatus.setCalibrating();
35 }
36 //
37 // Destructor
38 //
40  if (false)
41  cout << "Destructing SimpleNoiseCalculator " << endl;
42 }
43 //
44 // Update the Status of Noise Calculation
45 //
48  (useDB_ == true && numberOfEvents == 1)) {
50  }
51 }
52 //
53 // Calculate and update (when needed) Noise Values
54 //
56  if (alreadyUsedEvent == false) {
57  alreadyUsedEvent = true;
59 
60  if (numberOfEvents == 1 && theNoise.size() != in.size()) {
61  edm::LogError("SimpleNoiseCalculator:updateNoise")
62  << " You did not initialize the Noise correctly prior to noise calibration.";
63  }
64 
65  // Initialize sums used for estimating noise.
66  if (numberOfEvents == 1) {
67  theNoiseSum.clear();
68  theNoiseSqSum.clear();
69  theEventPerStrip.clear();
70 
71  theNoiseSum.resize(in.size(), 0.0);
72  theNoiseSqSum.resize(in.size(), 0.0);
73  theEventPerStrip.resize(in.size(), 0);
74  }
75 
76  unsigned int i;
77 
78  // At every event Update sums used for estimating noise.
79  for (i = 0; i < in.size(); i++) {
80  theNoiseSum[i] += in[i];
81  theNoiseSqSum[i] += in[i] * in[i];
83  }
84 
85  // Calculate noise.
87  theCMPSubtractedSignal.clear();
88  theNoise.clear();
89 
90  for (i = 0; i < in.size(); i++) {
91  double avVal = (theEventPerStrip[i]) ? theNoiseSum[i] / (theEventPerStrip[i]) : 0.0;
92  double sqAvVal = (theEventPerStrip[i]) ? theNoiseSqSum[i] / (theEventPerStrip[i]) : 0.0;
93  double corr_fac = (theEventPerStrip[i] > 1) ? (theEventPerStrip[i] / (theEventPerStrip[i] - 1)) : 1.0;
94  double rmsVal = (sqAvVal - avVal * avVal > 0.0) ? sqrt(corr_fac * (sqAvVal - avVal * avVal)) : 0.0;
95 
96  theCMPSubtractedSignal.push_back(static_cast<float>(avVal));
97 
98  theNoise.push_back(static_cast<float>(rmsVal));
99 
100  if (false)
101  cout << " SimpleNoiseCalculator::updateNoise " << theNoiseSum[i] << " " << theNoiseSqSum[i] << " "
102  << theEventPerStrip[i] << " " << avVal << " " << sqAvVal << " " << (sqAvVal - avVal * avVal) << " "
103  << rmsVal << endl;
104  }
105  }
106  updateStatus();
107  }
108 }
109 //
110 // Define New Event
111 //
std::vector< float > PedestalType
Definition: ApvAnalysis.h:44
bool isUpdating() const
void updateNoise(ApvAnalysis::PedestalType &in) override
ApvAnalysis::PedestalType theNoise
std::vector< double > theNoiseSum
std::vector< double > theNoiseSqSum
Log< level::Error, false > LogError
ApvAnalysis::PedestalType theCMPSubtractedSignal
TkStateMachine theStatus
T sqrt(T t)
Definition: SSEVec.h:19
bool isCalibrating() const
std::vector< unsigned short > theEventPerStrip