CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 //
11  numberOfEvents(0) ,
12  alreadyUsedEvent(false)
13 {
14  if (0) cout << "Constructing TT6NoiseCalculator " << endl;
15  init();
16 }
17 //
19  int evnt_iter, float sig_cut) :
20  numberOfEvents(0) ,
21  alreadyUsedEvent(false)
22 {
23  if (0) cout << "Constructing TT6NoiseCalculator " << endl;
24  eventsRequiredToCalibrate_ = evnt_ini;
25  eventsRequiredToUpdate_ = evnt_iter;
26  cutToAvoidSignal_ = sig_cut;
27  init();
28 }
29 //
30 // Initialization.
31 //
33  theCMPSubtractedSignal.clear();
34  theNoise.clear();
35  theNoiseSum.clear();
36  theNoiseSqSum.clear();
37  theEventPerStrip.clear();
39 }
40 //
41 // Destructor
42 //
44  if (0) cout << "Destructing TT6NoiseCalculator " << endl;
45 }
46 //
47 // Update the Status of Noise Calculation
48 //
50  if (theStatus.isCalibrating() &&
53  }
54 }
55 //
56 // Calculate and update (when needed) Noise Values
57 //
59  if (alreadyUsedEvent == false) {
60  alreadyUsedEvent = true;
62 
63  if (numberOfEvents == 1 && theNoise.size() != in.size()) {
64  edm::LogError("TT6NoiseCalculator:updateNoise") << " You did not initialize the Noise correctly prior to noise calibration.";
65  }
66 
67  // Initialize sums used for estimating noise.
68  if ((theStatus.isCalibrating() && numberOfEvents == 1) ||
70  {
71  theNoiseSum.clear();
72  theNoiseSqSum.clear();
73  theEventPerStrip.clear();
74 
75  theNoiseSum.resize(in.size(),0.0);
76  theNoiseSqSum.resize(in.size(),0.0);
77  theEventPerStrip.resize(in.size(),0);
78  }
79 
80  unsigned int i;
81 
82  // Update sums used for estimating noise.
83  for (i = 0; i < in.size(); i++) {
84  if (fabs(in[i]) < cutToAvoidSignal_*theNoise[i]) {
85  theNoiseSum[i] += in[i];
86  theNoiseSqSum[i] += in[i]*in[i];
88  }
89  }
90 
91  // Calculate noise.
94  {
95  theCMPSubtractedSignal.clear();
96  theNoise.clear();
97 
98  for (i = 0; i < in.size(); i++) {
99  double avVal = (theEventPerStrip[i]) ? theNoiseSum[i]/(theEventPerStrip[i]):0.0;
100  double sqAvVal = (theEventPerStrip[i]) ? theNoiseSqSum[i]/(theEventPerStrip[i]):0.0;
101  double corr_fac = (theEventPerStrip[i] > 1) ? (theEventPerStrip[i]/(theEventPerStrip[i]-1)) : 1.0;
102  double rmsVal = (sqAvVal - avVal*avVal > 0.0) ? sqrt(corr_fac * (sqAvVal - avVal*avVal)) : 0.0;
103 
104  theCMPSubtractedSignal.push_back(static_cast<float>(avVal));
105 
106  theNoise.push_back(static_cast<float>(rmsVal));
107 
108  if (0) cout << " TT6NoiseCalculator::updateNoise "
109  << theNoiseSum[i] << " "
110  << theNoiseSqSum[i] << " "
111  << theEventPerStrip[i] << " "
112  << avVal << " "
113  << sqAvVal << " "
114  << (sqAvVal - avVal*avVal) << " "
115  << rmsVal << endl;
116  }
117  }
118  updateStatus();
119  }
120 }
121 //
122 // Define New Event
123 //
125  alreadyUsedEvent = false;
126 }
127 
128 
int i
Definition: DBlmapReader.cc:9
std::vector< float > PedestalType
Definition: ApvAnalysis.h:48
TkStateMachine theStatus
std::vector< double > theNoiseSum
std::vector< unsigned short > theEventPerStrip
T sqrt(T t)
Definition: SSEVec.h:48
bool isUpdating() const
void updateNoise(ApvAnalysis::PedestalType &in)
std::vector< double > theNoiseSqSum
bool isCalibrating() const
void setCalibrating()
tuple cout
Definition: gather_cfg.py:121
ApvAnalysis::PedestalType theNoise
ApvAnalysis::PedestalType theCMPSubtractedSignal