CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 //
11  numberOfEvents(0) ,
12  alreadyUsedEvent(false)
13 {
14  if (0) cout << "Constructing SimpleNoiseCalculator " << endl;
15  init();
16 }
17 //
19  numberOfEvents(0) ,
20  alreadyUsedEvent(false)
21 {
22  if (0) cout << "Constructing SimpleNoiseCalculator " << endl;
23  useDB_ = use_DB;
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();
38  // theStatus.setCalibrating();
39 }
40 //
41 // Destructor
42 //
44  if (0) cout << "Destructing SimpleNoiseCalculator " << endl;
45 }
46 //
47 // Update the Status of Noise Calculation
48 //
52  }
53 }
54 //
55 // Calculate and update (when needed) Noise Values
56 //
58  if (alreadyUsedEvent == false) {
59  alreadyUsedEvent = true;
61 
62  if (numberOfEvents == 1 && theNoise.size() != in.size()) {
63  edm::LogError("SimpleNoiseCalculator:updateNoise") << " You did not initialize the Noise correctly prior to noise calibration.";
64  }
65 
66  // Initialize sums used for estimating noise.
67  if (numberOfEvents == 1)
68  {
69  theNoiseSum.clear();
70  theNoiseSqSum.clear();
71  theEventPerStrip.clear();
72 
73  theNoiseSum.resize(in.size(),0.0);
74  theNoiseSqSum.resize(in.size(),0.0);
75  theEventPerStrip.resize(in.size(),0);
76  }
77 
78  unsigned int i;
79 
80  // At every event Update sums used for estimating noise.
81  for (i = 0; i < in.size(); i++) {
82 
83  theNoiseSum[i] += in[i];
84  theNoiseSqSum[i] += in[i]*in[i];
86  }
87 
88  // Calculate noise.
90  {
91  theCMPSubtractedSignal.clear();
92  theNoise.clear();
93 
94  for (i = 0; i < in.size(); i++) {
95  double avVal = (theEventPerStrip[i])
96  ? theNoiseSum[i]/(theEventPerStrip[i]):0.0;
97  double sqAvVal = (theEventPerStrip[i])
98  ? theNoiseSqSum[i]/(theEventPerStrip[i]):0.0;
99  double corr_fac = (theEventPerStrip[i] > 1)
100  ? (theEventPerStrip[i]/(theEventPerStrip[i]-1)) : 1.0;
101  double rmsVal = (sqAvVal - avVal*avVal > 0.0)
102  ? 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 << " SimpleNoiseCalculator::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
ApvAnalysis::PedestalType theNoise
std::vector< double > theNoiseSum
std::vector< double > theNoiseSqSum
ApvAnalysis::PedestalType theCMPSubtractedSignal
void updateNoise(ApvAnalysis::PedestalType &in)
TkStateMachine theStatus
T sqrt(T t)
Definition: SSEVec.h:46
bool isUpdating() const
std::vector< unsigned short > theEventPerStrip
bool isCalibrating() const
tuple cout
Definition: gather_cfg.py:121