CMS 3D CMS Logo

NoiseAlgorithm.cc
Go to the documentation of this file.
6 #include "TProfile.h"
7 #include "TH1.h"
8 #include <iostream>
9 #include <iomanip>
10 #include <cmath>
11 
12 using namespace sistrip;
13 
14 // ----------------------------------------------------------------------------
15 //
17  : CommissioningAlgorithm(anal), hPeds_(nullptr, ""), hNoise_(nullptr, "") {
18  ;
19 }
20 
21 // ----------------------------------------------------------------------------
22 //
23 void NoiseAlgorithm::extract(const std::vector<TH1*>& histos) {
24  if (!anal()) {
25  edm::LogWarning(mlCommissioning_) << "[NoiseAlgorithm::" << __func__ << "]"
26  << " NULL pointer to Analysis object!";
27  return;
28  }
29 
30  // Check number of histograms
31  if (histos.size() != 2) {
33  }
34 
35  // Extract FED key from histo title
36  if (!histos.empty()) {
37  anal()->fedKey(extractFedKey(histos.front()));
38  }
39 
40  // Extract histograms
41  std::vector<TH1*>::const_iterator ihis = histos.begin();
42  for (; ihis != histos.end(); ihis++) {
43  // Check for NULL pointer
44  if (!(*ihis)) {
45  continue;
46  }
47 
48  // Check run type
49  SiStripHistoTitle title((*ihis)->GetName());
50  if (title.runType() != sistrip::NOISE) {
52  continue;
53  }
54 
55  // Extract peds and noise histos (check for legacy names first!)
56  if (title.extraInfo().find(sistrip::extrainfo::pedsAndRawNoise_) != std::string::npos) {
57  hPeds_.first = *ihis;
58  hPeds_.second = (*ihis)->GetName();
59  NoiseAnalysis* a = dynamic_cast<NoiseAnalysis*>(const_cast<CommissioningAnalysis*>(anal()));
60  if (a) {
61  a->legacy_ = true;
62  }
63  } else if (title.extraInfo().find(sistrip::extrainfo::pedsAndCmSubNoise_) != std::string::npos) {
64  hNoise_.first = *ihis;
65  hNoise_.second = (*ihis)->GetName();
66  NoiseAnalysis* a = dynamic_cast<NoiseAnalysis*>(const_cast<CommissioningAnalysis*>(anal()));
67  if (a) {
68  a->legacy_ = true;
69  }
70  } else if (title.extraInfo().find(sistrip::extrainfo::pedestals_) != std::string::npos) {
71  hPeds_.first = *ihis;
72  hPeds_.second = (*ihis)->GetName();
73  } else if (title.extraInfo().find(sistrip::extrainfo::noise_) != std::string::npos) {
74  hNoise_.first = *ihis;
75  hNoise_.second = (*ihis)->GetName();
76  } else if (title.extraInfo().find(sistrip::extrainfo::commonMode_) != std::string::npos) {
77  //@@ something here for CM plots?
78  } else {
80  }
81  }
82 }
83 
84 // -----------------------------------------------------------------------------
85 //
87  if (!anal()) {
88  edm::LogWarning(mlCommissioning_) << "[NoiseAlgorithm::" << __func__ << "]"
89  << " NULL pointer to base Analysis object!";
90  return;
91  }
92 
94  NoiseAnalysis* anal = dynamic_cast<NoiseAnalysis*>(tmp);
95  if (!anal) {
96  edm::LogWarning(mlCommissioning_) << "[NoiseAlgorithm::" << __func__ << "]"
97  << " NULL pointer to derived Analysis object!";
98  return;
99  }
100 
101  if (!hPeds_.first) {
103  return;
104  }
105 
106  if (!hNoise_.first) {
108  return;
109  }
110 
111  TProfile* peds_histo = dynamic_cast<TProfile*>(hPeds_.first);
112  TProfile* noise_histo = dynamic_cast<TProfile*>(hNoise_.first);
113 
114  if (!peds_histo) {
116  return;
117  }
118 
119  if (!noise_histo) {
121  return;
122  }
123 
124  if (peds_histo->GetNbinsX() != 256) {
126  return;
127  }
128 
129  if (noise_histo->GetNbinsX() != 256) {
131  return;
132  }
133 
134  // Iterate through APVs
135  for (uint16_t iapv = 0; iapv < 2; iapv++) {
136  // Used to calc mean and rms for peds and noise
137  float p_sum = 0., p_sum2 = 0., p_max = -1. * sistrip::invalid_, p_min = sistrip::invalid_;
138  float n_sum = 0., n_sum2 = 0., n_max = -1. * sistrip::invalid_, n_min = sistrip::invalid_;
139  float r_sum = 0., r_sum2 = 0., r_max = -1. * sistrip::invalid_, r_min = sistrip::invalid_;
140 
141  // Iterate through strips of APV
142  for (uint16_t istr = 0; istr < 128; istr++) {
143  uint16_t strip = iapv * 128 + istr;
144 
145  // Pedestals and raw noise
146  if (peds_histo) {
147  if (peds_histo->GetBinEntries(strip + 1)) {
148  anal->peds_[iapv][istr] = peds_histo->GetBinContent(strip + 1);
149  p_sum += anal->peds_[iapv][istr];
150  p_sum2 += (anal->peds_[iapv][istr] * anal->peds_[iapv][istr]);
151  if (anal->peds_[iapv][istr] > p_max) {
152  p_max = anal->peds_[iapv][istr];
153  }
154  if (anal->peds_[iapv][istr] < p_min) {
155  p_min = anal->peds_[iapv][istr];
156  }
157 
158  anal->raw_[iapv][istr] = peds_histo->GetBinError(strip + 1);
159  r_sum += anal->raw_[iapv][istr];
160  r_sum2 += (anal->raw_[iapv][istr] * anal->raw_[iapv][istr]);
161  if (anal->raw_[iapv][istr] > r_max) {
162  r_max = anal->raw_[iapv][istr];
163  }
164  if (anal->raw_[iapv][istr] < r_min) {
165  r_min = anal->raw_[iapv][istr];
166  }
167  }
168  }
169 
170  // Noise
171  if (noise_histo) {
172  if (noise_histo->GetBinEntries(strip + 1)) {
173  anal->noise_[iapv][istr] = noise_histo->GetBinContent(strip + 1);
174  n_sum += anal->noise_[iapv][istr];
175  n_sum2 += (anal->noise_[iapv][istr] * anal->noise_[iapv][istr]);
176  if (anal->noise_[iapv][istr] > n_max) {
177  n_max = anal->noise_[iapv][istr];
178  }
179  if (anal->noise_[iapv][istr] < n_min) {
180  n_min = anal->noise_[iapv][istr];
181  }
182  }
183  }
184 
185  } // strip loop
186 
187  // Calc mean and rms for peds
188  if (!anal->peds_[iapv].empty()) {
189  p_sum /= static_cast<float>(anal->peds_[iapv].size());
190  p_sum2 /= static_cast<float>(anal->peds_[iapv].size());
191  anal->pedsMean_[iapv] = p_sum;
192  anal->pedsSpread_[iapv] = sqrt(fabs(p_sum2 - p_sum * p_sum));
193  }
194 
195  // Calc mean and rms for noise
196  if (!anal->noise_[iapv].empty()) {
197  n_sum /= static_cast<float>(anal->noise_[iapv].size());
198  n_sum2 /= static_cast<float>(anal->noise_[iapv].size());
199  anal->noiseMean_[iapv] = n_sum;
200  anal->noiseSpread_[iapv] = sqrt(fabs(n_sum2 - n_sum * n_sum));
201  }
202 
203  // Calc mean and rms for raw noise
204  if (!anal->raw_[iapv].empty()) {
205  r_sum /= static_cast<float>(anal->raw_[iapv].size());
206  r_sum2 /= static_cast<float>(anal->raw_[iapv].size());
207  anal->rawMean_[iapv] = r_sum;
208  anal->rawSpread_[iapv] = sqrt(fabs(r_sum2 - r_sum * r_sum));
209  }
210 
211  // Set max and min values for peds, noise and raw noise
212  if (p_max > -1. * sistrip::maximum_) {
213  anal->pedsMax_[iapv] = p_max;
214  }
215  if (p_min < 1. * sistrip::maximum_) {
216  anal->pedsMin_[iapv] = p_min;
217  }
218  if (n_max > -1. * sistrip::maximum_) {
219  anal->noiseMax_[iapv] = n_max;
220  }
221  if (n_min < 1. * sistrip::maximum_) {
222  anal->noiseMin_[iapv] = n_min;
223  }
224  if (r_max > -1. * sistrip::maximum_) {
225  anal->rawMax_[iapv] = r_max;
226  }
227  if (r_min < 1. * sistrip::maximum_) {
228  anal->rawMin_[iapv] = r_min;
229  }
230 
231  // Set dead and noisy strips
232  for (uint16_t istr = 0; istr < 128; istr++) {
233  if (anal->noiseMin_[iapv] > sistrip::maximum_ || anal->noiseMax_[iapv] > sistrip::maximum_) {
234  continue;
235  }
236  if (anal->noise_[iapv][istr] < (anal->noiseMean_[iapv] - 5. * anal->noiseSpread_[iapv])) {
237  anal->dead_[iapv].push_back(istr); //@@ valid threshold???
238  } else if (anal->noise_[iapv][istr] > (anal->noiseMean_[iapv] + 5. * anal->noiseSpread_[iapv])) {
239  anal->noisy_[iapv].push_back(istr); //@@ valid threshold???
240  }
241  }
242 
243  } // apv loop
244 }
static const char noise_[]
CommissioningAnalysis *const anal() const
static const char unexpectedTask_[]
static const char pedsAndRawNoise_[]
Utility class that holds histogram title.
static const char numberOfHistos_[]
static const char unexpectedExtraInfo_[]
static const char numberOfBins_[]
sistrip classes
uint32_t extractFedKey(const TH1 *const)
static const char mlCommissioning_[]
T sqrt(T t)
Definition: SSEVec.h:23
static const uint16_t maximum_
Definition: Constants.h:20
virtual void addErrorCode(const std::string &error)
static const char commonMode_[]
const uint32_t & fedKey() const
static const char pedestals_[]
static const char pedsAndCmSubNoise_[]
static const uint16_t invalid_
Definition: Constants.h:16
histos
Definition: combine.py:4
double a
Definition: hdecay.h:121
Histogram-based analysis for pedestal run.
Definition: NoiseAnalysis.h:15
void extract(const std::vector< TH1 *> &) override
Abstract base for derived classes that provide analysis of commissioning histograms.
Log< level::Warning, false > LogWarning
tmp
align.sh
Definition: createJobs.py:716
static const char nullPtr_[]
void analyse() override