CMS 3D CMS Logo

TT6NoiseCalculator.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 TT6NoiseCalculator::TT6NoiseCalculator() : numberOfEvents(0), alreadyUsedEvent(false) {
11  if (false)
12  cout << "Constructing TT6NoiseCalculator " << endl;
13  init();
14 }
15 //
16 TT6NoiseCalculator::TT6NoiseCalculator(int evnt_ini, int evnt_iter, float sig_cut)
18  if (false)
19  cout << "Constructing TT6NoiseCalculator " << endl;
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();
35 }
36 //
37 // Destructor
38 //
40  if (false)
41  cout << "Destructing TT6NoiseCalculator " << endl;
42 }
43 //
44 // Update the Status of Noise Calculation
45 //
49  }
50 }
51 //
52 // Calculate and update (when needed) Noise Values
53 //
55  if (alreadyUsedEvent == false) {
56  alreadyUsedEvent = true;
58 
59  if (numberOfEvents == 1 && theNoise.size() != in.size()) {
60  edm::LogError("TT6NoiseCalculator:updateNoise")
61  << " You did not initialize the Noise correctly prior to noise calibration.";
62  }
63 
64  // Initialize sums used for estimating noise.
65  if ((theStatus.isCalibrating() && 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  // Update sums used for estimating noise.
79  for (i = 0; i < in.size(); i++) {
80  if (fabs(in[i]) < cutToAvoidSignal_ * theNoise[i]) {
81  theNoiseSum[i] += in[i];
82  theNoiseSqSum[i] += in[i] * in[i];
84  }
85  }
86 
87  // Calculate noise.
90  theCMPSubtractedSignal.clear();
91  theNoise.clear();
92 
93  for (i = 0; i < in.size(); i++) {
94  double avVal = (theEventPerStrip[i]) ? theNoiseSum[i] / (theEventPerStrip[i]) : 0.0;
95  double sqAvVal = (theEventPerStrip[i]) ? theNoiseSqSum[i] / (theEventPerStrip[i]) : 0.0;
96  double corr_fac = (theEventPerStrip[i] > 1) ? (theEventPerStrip[i] / (theEventPerStrip[i] - 1)) : 1.0;
97  double rmsVal = (sqAvVal - avVal * avVal > 0.0) ? sqrt(corr_fac * (sqAvVal - avVal * avVal)) : 0.0;
98 
99  theCMPSubtractedSignal.push_back(static_cast<float>(avVal));
100 
101  theNoise.push_back(static_cast<float>(rmsVal));
102 
103  if (false)
104  cout << " TT6NoiseCalculator::updateNoise " << theNoiseSum[i] << " " << theNoiseSqSum[i] << " "
105  << theEventPerStrip[i] << " " << avVal << " " << sqAvVal << " " << (sqAvVal - avVal * avVal) << " "
106  << rmsVal << endl;
107  }
108  }
109  updateStatus();
110  }
111 }
112 //
113 // Define New Event
114 //
void updateNoise(ApvAnalysis::PedestalType &in) override
std::vector< float > PedestalType
Definition: ApvAnalysis.h:44
~TT6NoiseCalculator() override
TkStateMachine theStatus
std::vector< double > theNoiseSum
std::vector< unsigned short > theEventPerStrip
T sqrt(T t)
Definition: SSEVec.h:19
bool isUpdating() const
std::vector< double > theNoiseSqSum
void newEvent() override
bool isCalibrating() const
void setCalibrating()
ApvAnalysis::PedestalType theNoise
ApvAnalysis::PedestalType theCMPSubtractedSignal
void updateStatus() override