CMS 3D CMS Logo

DaqScopeModeAlgorithm.cc
Go to the documentation of this file.
6 #include "TH1.h"
7 #include "TProfile.h"
8 #include <iostream>
9 #include <iomanip>
10 #include <cmath>
11 
12 using namespace sistrip;
13 
14 // ----------------------------------------------------------------------------
15 //
18  histo_(nullptr, ""),
19  headerLow_(nullptr, ""),
20  headerHigh_(nullptr, ""),
21  hPeds_(nullptr, ""),
22  hNoise_(nullptr, ""),
23  deadStripMax_(pset.getParameter<double>("DeadStripMax")),
24  noisyStripMin_(pset.getParameter<double>("NoisyStripMin")) {
25  ;
26 }
27 
28 // ----------------------------------------------------------------------------
29 //
30 void DaqScopeModeAlgorithm::extract(const std::vector<TH1*>& histos) {
31  if (!anal()) {
32  edm::LogWarning(mlCommissioning_) << "[DaqScopeModeAlgorithm::" << __func__ << "]"
33  << " NULL pointer to base Analysis object!";
34  return;
35  }
36 
37  // Extract FED key from histo title
38  if (!histos.empty()) {
39  anal()->fedKey(extractFedKey(histos.front()));
40  }
41 
42  // Extract histograms
43  std::vector<TH1*>::const_iterator ihis = histos.begin();
44  for (; ihis != histos.end(); ihis++) {
45  // Check for NULL pointer
46  if (!(*ihis)) {
47  continue;
48  }
49 
50  // Check name
51  SiStripHistoTitle title((*ihis)->GetName());
52  if (title.runType() != sistrip::DAQ_SCOPE_MODE) {
54  continue;
55  }
56 
57  // Extract timing histo
58  // Extract peds and noise histos (check for legacy names first!)
59  if (title.extraInfo().find(sistrip::extrainfo::pedsAndRawNoise_) != std::string::npos) {
60  hPeds_.first = *ihis;
61  hPeds_.second = (*ihis)->GetName();
62  } else if (title.extraInfo().find(sistrip::extrainfo::pedsAndCmSubNoise_) != std::string::npos) {
63  hNoise_.first = *ihis;
64  hNoise_.second = (*ihis)->GetName();
65  } else if (title.extraInfo().find(sistrip::extrainfo::pedestals_) != std::string::npos) {
66  hPeds_.first = *ihis;
67  hPeds_.second = (*ihis)->GetName();
68  } else if (title.extraInfo().find(sistrip::extrainfo::noise_) != std::string::npos) {
69  hNoise_.first = *ihis;
70  hNoise_.second = (*ihis)->GetName();
71  } else if (title.extraInfo().find(sistrip::extrainfo::commonMode_) != std::string::npos) {
72  //@@ something here for CM plots?
73  } else if (title.extraInfo().find(sistrip::extrainfo::scopeModeFrame_) != std::string::npos) {
74  histo_.first = *ihis;
75  histo_.second = (*ihis)->GetName();
76  } else if (title.extraInfo().find(sistrip::extrainfo::scopeModeHeaderLow_) != std::string::npos) {
77  headerLow_.first = *ihis;
78  headerLow_.second = (*ihis)->GetName();
79  } else if (title.extraInfo().find(sistrip::extrainfo::scopeModeHeaderHigh_) != std::string::npos) {
80  headerHigh_.first = *ihis;
81  headerHigh_.second = (*ihis)->GetName();
82  }
83  }
84 }
85 
86 // ----------------------------------------------------------------------------
87 //
89  if (!anal()) {
90  edm::LogWarning(mlCommissioning_) << "[DaqScopeModeAlgorithm::" << __func__ << "]"
91  << " NULL pointer to base Analysis object!";
92  return;
93  }
94 
95  CommissioningAnalysis* tmp = const_cast<CommissioningAnalysis*>(anal());
96  DaqScopeModeAnalysis* anal = dynamic_cast<DaqScopeModeAnalysis*>(tmp);
97  if (!anal) {
98  edm::LogWarning(mlCommissioning_) << "[DaqScopeModeAlgorithm::" << __func__ << "]"
99  << " NULL pointer to derived Analysis object!";
100  return;
101  }
102 
103  // Analysis level wants all the informations --> it will work only on Spy-events
104  if (!hPeds_.first) {
106  return;
107  }
108 
109  if (!hNoise_.first) {
111  return;
112  }
113 
114  if (!histo_.first) {
116  return;
117  }
118  if (!headerLow_.first) {
120  return;
121  }
122  if (!headerHigh_.first) {
124  return;
125  }
126 
128  TProfile* peds_histo = dynamic_cast<TProfile*>(hPeds_.first);
129  TProfile* noise_histo = dynamic_cast<TProfile*>(hNoise_.first);
131  TProfile* scope_histo = dynamic_cast<TProfile*>(histo_.first);
132  TH1F* headerLow_histo = dynamic_cast<TH1F*>(headerLow_.first);
133  TH1F* headerHigh_histo = dynamic_cast<TH1F*>(headerHigh_.first);
134 
135  if (!peds_histo) {
137  return;
138  }
139 
140  if (!noise_histo) {
142  return;
143  }
144 
145  if (!scope_histo) {
147  return;
148  }
149 
150  if (!headerLow_histo) {
152  return;
153  }
154 
155  if (!headerHigh_histo) {
157  return;
158  }
159 
160  if (peds_histo->GetNbinsX() != 256) {
162  return;
163  }
164 
165  if (noise_histo->GetNbinsX() != 256) {
167  return;
168  }
169 
170  if (scope_histo->GetNbinsX() != 298) {
172  return;
173  }
174 
175  // Calculate pedestals and noise
176  // Iterate through APVs
177  for (uint16_t iapv = 0; iapv < 2; iapv++) {
178  // Used to calc mean and rms for peds and noise
179  float p_sum = 0., p_sum2 = 0., p_max = -1. * sistrip::invalid_, p_min = sistrip::invalid_;
180  float n_sum = 0., n_sum2 = 0., n_max = -1. * sistrip::invalid_, n_min = sistrip::invalid_;
181  float r_sum = 0., r_sum2 = 0., r_max = -1. * sistrip::invalid_, r_min = sistrip::invalid_;
182 
183  // Iterate through strips of APV
184  for (uint16_t istr = 0; istr < 128; istr++) {
185  uint16_t strip = iapv * 128 + istr;
186 
187  // Pedestals and raw noise
188  if (peds_histo) {
189  if (peds_histo->GetBinEntries(strip + 1)) {
190  anal->peds_[iapv][istr] = peds_histo->GetBinContent(strip + 1);
191  p_sum += anal->peds_[iapv][istr];
192  p_sum2 += (anal->peds_[iapv][istr] * anal->peds_[iapv][istr]);
193  if (anal->peds_[iapv][istr] > p_max) {
194  p_max = anal->peds_[iapv][istr];
195  }
196  if (anal->peds_[iapv][istr] < p_min) {
197  p_min = anal->peds_[iapv][istr];
198  }
199 
200  anal->raw_[iapv][istr] = peds_histo->GetBinError(strip + 1);
201  r_sum += anal->raw_[iapv][istr];
202  r_sum2 += (anal->raw_[iapv][istr] * anal->raw_[iapv][istr]);
203  if (anal->raw_[iapv][istr] > r_max) {
204  r_max = anal->raw_[iapv][istr];
205  }
206  if (anal->raw_[iapv][istr] < r_min) {
207  r_min = anal->raw_[iapv][istr];
208  }
209  }
210  }
211 
212  // Noise
213  if (noise_histo) {
214  if (noise_histo->GetBinEntries(strip + 1)) {
215  anal->noise_[iapv][istr] = noise_histo->GetBinContent(strip + 1);
216  n_sum += anal->noise_[iapv][istr];
217  n_sum2 += (anal->noise_[iapv][istr] * anal->noise_[iapv][istr]);
218  if (anal->noise_[iapv][istr] > n_max) {
219  n_max = anal->noise_[iapv][istr];
220  }
221  if (anal->noise_[iapv][istr] < n_min) {
222  n_min = anal->noise_[iapv][istr];
223  }
224  }
225  }
226  } // strip loop
227 
228  // Calc mean and rms for peds
229  if (!anal->peds_[iapv].empty()) {
230  p_sum /= static_cast<float>(anal->peds_[iapv].size());
231  p_sum2 /= static_cast<float>(anal->peds_[iapv].size());
232  anal->pedsMean_[iapv] = p_sum;
233  anal->pedsSpread_[iapv] = sqrt(fabs(p_sum2 - p_sum * p_sum));
234  }
235 
236  // Calc mean and rms for noise
237  if (!anal->noise_[iapv].empty()) {
238  n_sum /= static_cast<float>(anal->noise_[iapv].size());
239  n_sum2 /= static_cast<float>(anal->noise_[iapv].size());
240  anal->noiseMean_[iapv] = n_sum;
241  anal->noiseSpread_[iapv] = sqrt(fabs(n_sum2 - n_sum * n_sum));
242  }
243 
244  // Calc mean and rms for raw noise
245  if (!anal->raw_[iapv].empty()) {
246  r_sum /= static_cast<float>(anal->raw_[iapv].size());
247  r_sum2 /= static_cast<float>(anal->raw_[iapv].size());
248  anal->rawMean_[iapv] = r_sum;
249  anal->rawSpread_[iapv] = sqrt(fabs(r_sum2 - r_sum * r_sum));
250  }
251 
252  // Set max and min values for peds, noise and raw noise
253  if (p_max > -1. * sistrip::maximum_) {
254  anal->pedsMax_[iapv] = p_max;
255  }
256  if (p_min < 1. * sistrip::maximum_) {
257  anal->pedsMin_[iapv] = p_min;
258  }
259  if (n_max > -1. * sistrip::maximum_) {
260  anal->noiseMax_[iapv] = n_max;
261  }
262  if (n_min < 1. * sistrip::maximum_) {
263  anal->noiseMin_[iapv] = n_min;
264  }
265  if (r_max > -1. * sistrip::maximum_) {
266  anal->rawMax_[iapv] = r_max;
267  }
268  if (r_min < 1. * sistrip::maximum_) {
269  anal->rawMin_[iapv] = r_min;
270  }
271 
272  // Set dead and noisy strips
273  for (uint16_t istr = 0; istr < 128; istr++) {
274  if (anal->noiseMin_[iapv] > sistrip::maximum_ || anal->noiseMax_[iapv] > sistrip::maximum_) {
275  continue;
276  }
277  if (anal->noise_[iapv][istr] < (anal->noiseMean_[iapv] - deadStripMax_ * anal->noiseSpread_[iapv])) {
278  anal->dead_[iapv].push_back(istr);
279  } else if (anal->noise_[iapv][istr] > (anal->noiseMean_[iapv] + noisyStripMin_ * anal->noiseSpread_[iapv])) {
280  anal->noisy_[iapv].push_back(istr);
281  }
282  }
283  } // apv loop
284 
286  //anal->peak_ = (scope_histo->GetBinContent(287)+scope_histo->GetBinContent(288))/2.;
287  //anal->base_ = (scope_histo->GetBinContent(1)+scope_histo->GetBinContent(2)+scope_histo->GetBinContent(3)+scope_histo->GetBinContent(4)+scope_histo->GetBinContent(5))/5.;
288  anal->peak_ = headerHigh_histo->GetMean();
289  anal->base_ = headerLow_histo->GetMean();
290  anal->height_ = anal->peak_ - anal->base_;
293  return;
294  }
295 }
sistrip::extrainfo::commonMode_
static const char commonMode_[]
Definition: ConstantsForDqm.h:48
sistrip::DAQ_SCOPE_MODE
Definition: ConstantsForRunType.h:83
runGCPTkAlMap.title
string title
Definition: runGCPTkAlMap.py:94
sistrip::extrainfo::noise_
static const char noise_[]
Definition: ConstantsForDqm.h:47
MessageLogger.h
sistrip::extrainfo::scopeModeHeaderHigh_
static const char scopeModeHeaderHigh_[]
Definition: ConstantsForDqm.h:65
CommissioningAlgorithm::extractFedKey
uint32_t extractFedKey(const TH1 *const)
Definition: CommissioningAlgorithm.cc:29
sistrip::unexpectedTask_
static const char unexpectedTask_[]
Definition: ConstantsForCommissioningAnalysis.h:21
DaqScopeModeAlgorithm::noisyStripMin_
float noisyStripMin_
Definition: DaqScopeModeAlgorithm.h:49
DaqScopeModeAlgorithm::histo_
Histo histo_
Definition: DaqScopeModeAlgorithm.h:37
digitizers_cfi.strip
strip
Definition: digitizers_cfi.py:19
CommissioningAnalysis::fedKey
const uint32_t & fedKey() const
Definition: CommissioningAnalysis.h:134
DaqScopeModeAlgorithm::headerLow_
Histo headerLow_
Definition: DaqScopeModeAlgorithm.h:39
DaqScopeModeAlgorithm::deadStripMax_
float deadStripMax_
Definition: DaqScopeModeAlgorithm.h:48
DaqScopeModeAlgorithm.h
DaqScopeModeAlgorithm::headerHigh_
Histo headerHigh_
Definition: DaqScopeModeAlgorithm.h:41
CommissioningAnalysis::addErrorCode
virtual void addErrorCode(const std::string &error)
Definition: CommissioningAnalysis.h:148
sistrip::extrainfo::pedsAndCmSubNoise_
static const char pedsAndCmSubNoise_[]
Definition: ConstantsForDqm.h:55
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
sistrip::mlCommissioning_
static const char mlCommissioning_[]
Definition: ConstantsForLogger.h:15
CommissioningAlgorithm::anal
CommissioningAnalysis *const anal() const
Definition: CommissioningAlgorithm.h:50
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
sistrip::numberOfBins_
static const char numberOfBins_[]
Definition: ConstantsForCommissioningAnalysis.h:18
DaqScopeModeAnalysis
Analysis for scope mode data.
Definition: DaqScopeModeAnalysis.h:16
sistrip::extrainfo::pedestals_
static const char pedestals_[]
Definition: ConstantsForDqm.h:45
edm::ParameterSet
Definition: ParameterSet.h:47
sistrip::extrainfo::scopeModeFrame_
static const char scopeModeFrame_[]
Definition: ConstantsForDqm.h:63
sistrip::maximum_
static const uint16_t maximum_
Definition: Constants.h:20
DaqScopeModeAlgorithm::extract
void extract(const std::vector< TH1 * > &) override
Definition: DaqScopeModeAlgorithm.cc:30
DaqScopeModeAlgorithm::analyse
void analyse() override
Definition: DaqScopeModeAlgorithm.cc:88
DaqScopeModeAlgorithm::DaqScopeModeAlgorithm
DaqScopeModeAlgorithm()
Definition: DaqScopeModeAlgorithm.h:29
sistrip::invalid_
static const uint16_t invalid_
Definition: Constants.h:16
DaqScopeModeAnalysis::tickMarkHeightThreshold_
static const float tickMarkHeightThreshold_
Definition: DaqScopeModeAnalysis.h:78
sistrip::extrainfo::pedsAndRawNoise_
static const char pedsAndRawNoise_[]
Definition: ConstantsForDqm.h:53
sistrip::smallTickMarkHeight_
static const char smallTickMarkHeight_[]
Definition: ConstantsForCommissioningAnalysis.h:39
combine.histos
histos
Definition: combine.py:4
CommissioningAnalysis
Abstract base for derived classes that provide analysis of commissioning histograms.
Definition: CommissioningAnalysis.h:18
DaqScopeModeAlgorithm::hNoise_
Histo hNoise_
Definition: DaqScopeModeAlgorithm.h:45
SiStripEnumsAndStrings.h
SiStripHistoTitle.h
CommissioningAlgorithm
Definition: CommissioningAlgorithm.h:17
SiStripHistoTitle
Utility class that holds histogram title.
Definition: SiStripHistoTitle.h:20
DaqScopeModeAnalysis.h
DaqScopeModeAlgorithm::hPeds_
Histo hPeds_
Definition: DaqScopeModeAlgorithm.h:43
sistrip::extrainfo::scopeModeHeaderLow_
static const char scopeModeHeaderLow_[]
Definition: ConstantsForDqm.h:64
sistrip
sistrip classes
Definition: SiStripQualityHelpers.h:14
conversion_template_cfg.anal
anal
Definition: conversion_template_cfg.py:16
sistrip::nullPtr_
static const char nullPtr_[]
Definition: ConstantsForCommissioningAnalysis.h:17
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27