CMS 3D CMS Logo

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