CMS 3D CMS Logo

FastFedCablingAlgorithm.cc
Go to the documentation of this file.
6 #include "TProfile.h"
7 #include "TH1.h"
8 #include <iostream>
9 #include <sstream>
10 #include <iomanip>
11 #include <cmath>
12 
13 using namespace sistrip;
14 
15 // ----------------------------------------------------------------------------
16 //
18  : CommissioningAlgorithm(anal), histo_(nullptr, "") {
19  ;
20 }
21 
22 // ----------------------------------------------------------------------------
23 //
24 void FastFedCablingAlgorithm::extract(const std::vector<TH1*>& histos) {
25  if (!anal()) {
26  edm::LogWarning(mlCommissioning_) << "[FastFedCablingAlgorithm::" << __func__ << "]"
27  << " NULL pointer to Analysis object!";
28  return;
29  }
30 
31  // Check number of histograms
32  if (histos.size() != 1) {
34  }
35 
36  // Extract FED key from histo title
37  if (!histos.empty()) {
38  anal()->fedKey(extractFedKey(histos.front()));
39  }
40 
41  // Extract histograms
42  std::vector<TH1*>::const_iterator ihis = histos.begin();
43  for (; ihis != histos.end(); ihis++) {
44  // Check for NULL pointer
45  if (!(*ihis)) {
46  continue;
47  }
48 
49  // Check name
50  SiStripHistoTitle title((*ihis)->GetName());
51  if (title.runType() != sistrip::FAST_CABLING) {
53  continue;
54  }
55 
56  // Extract cabling histo
57  histo_.first = *ihis;
58  histo_.second = (*ihis)->GetName();
59  }
60 }
61 
62 // -----------------------------------------------------------------------------
63 //
65  if (!anal()) {
66  edm::LogWarning(mlCommissioning_) << "[FastFedCablingAlgorithm::" << __func__ << "]"
67  << " NULL pointer to base Analysis object!";
68  return;
69  }
70 
71  CommissioningAnalysis* tmp = const_cast<CommissioningAnalysis*>(anal());
72  FastFedCablingAnalysis* anal = dynamic_cast<FastFedCablingAnalysis*>(tmp);
73  if (!anal) {
74  edm::LogWarning(mlCommissioning_) << "[FastFedCablingAlgorithm::" << __func__ << "]"
75  << " NULL pointer to derived Analysis object!";
76  return;
77  }
78 
79  if (!histo_.first) {
81  return;
82  }
83 
84  TProfile* histo = dynamic_cast<TProfile*>(histo_.first);
85  if (!histo) {
87  return;
88  }
89 
90  // Initialization
91  uint16_t zero_entries = 0;
92  uint16_t nbins = static_cast<uint16_t>(histo->GetNbinsX());
93  std::vector<float> contents;
94  std::vector<float> errors;
95  std::vector<float> entries;
96  contents.reserve(nbins);
97  errors.reserve(nbins);
98  entries.reserve(nbins);
99 
100  // Copy histo contents to containers and find min/max
101  anal->max_ = -1. * sistrip::invalid_;
102  for (uint16_t ibin = 0; ibin < nbins; ibin++) {
103  contents.push_back(histo->GetBinContent(ibin + 1));
104  errors.push_back(histo->GetBinError(ibin + 1));
105  entries.push_back(histo->GetBinEntries(ibin + 1));
106  if (entries[ibin]) {
107  if (contents[ibin] > anal->max_) {
108  anal->max_ = contents[ibin];
109  }
110  if (contents[ibin] < anal->min_) {
111  anal->min_ = contents[ibin];
112  }
113  } else {
114  zero_entries++;
115  }
116  }
117  if (anal->max_ < -1. * sistrip::valid_) {
118  anal->max_ = sistrip::invalid_;
119  }
120 
121  // Check number of bins
124  return;
125  }
126 
127  // Check for bins with zero entries
128  if (zero_entries) {
130  return;
131  }
132 
133  // Check min and max found
134  if (anal->max_ > sistrip::valid_ || anal->min_ > sistrip::valid_) {
135  return;
136  }
137 
138  // Calculate range and mid-range levels
139  anal->range_ = anal->max_ - anal->min_;
140  anal->midRange_ = anal->min_ + anal->range_ / 2.;
141 
142  // Check if range is above threshold
145  return;
146  }
147 
148  // Identify samples to be either "low" or "high"
149  std::vector<float> high;
150  std::vector<float> low;
151  for (uint16_t ibin = 0; ibin < nbins; ibin++) {
152  if (entries[ibin]) {
153  if (contents[ibin] < anal->midRange_) {
154  low.push_back(contents[ibin]);
155  } else {
156  high.push_back(contents[ibin]);
157  }
158  }
159  }
160 
161  // Find median of high and low levels
162  sort(high.begin(), high.end());
163  sort(low.begin(), low.end());
164  if (!high.empty()) {
165  anal->highMedian_ = high[high.size() % 2 ? high.size() / 2 : high.size() / 2];
166  }
167  if (!low.empty()) {
168  anal->lowMedian_ = low[low.size() % 2 ? low.size() / 2 : low.size() / 2];
169  }
170 
171  // Check if light levels above thresholds
172  //if ( anal->highMedian_ < FastFedCablingAnalysis::dirtyThreshold_ ) { anal->addErrorCode(sistrip::invalidLightLevel_); }
173  //if ( anal->lowMedian_ < FastFedCablingAnalysis::trimDacThreshold_ ) { anal->addErrorCode(sistrip::invalidTrimDacLevel_); }
174 
175  // Find mean and rms in "low" samples
176  anal->lowMean_ = 0.;
177  anal->lowRms_ = 0.;
178  for (uint16_t ibin = 0; ibin < low.size(); ibin++) {
179  anal->lowMean_ += low[ibin];
180  anal->lowRms_ += low[ibin] * low[ibin];
181  }
182  if (!low.empty()) {
183  anal->lowMean_ = anal->lowMean_ / low.size();
184  anal->lowRms_ = anal->lowRms_ / low.size();
185  } else {
186  anal->lowMean_ = 1. * sistrip::invalid_;
187  anal->lowRms_ = 1. * sistrip::invalid_;
188  }
189  if (anal->lowMean_ < sistrip::valid_) {
190  anal->lowRms_ = sqrt(fabs(anal->lowRms_ - anal->lowMean_ * anal->lowMean_));
191  } else {
192  anal->lowMean_ = 1. * sistrip::invalid_;
193  anal->lowRms_ = 1. * sistrip::invalid_;
194  }
195 
196  // Find mean and rms in "high" samples
197  anal->highMean_ = 0.;
198  anal->highRms_ = 0.;
199  for (uint16_t ibin = 0; ibin < high.size(); ibin++) {
200  anal->highMean_ += high[ibin];
201  anal->highRms_ += high[ibin] * high[ibin];
202  }
203  if (!high.empty()) {
204  anal->highMean_ = anal->highMean_ / high.size();
205  anal->highRms_ = anal->highRms_ / high.size();
206  } else {
207  anal->highMean_ = 1. * sistrip::invalid_;
208  anal->highRms_ = 1. * sistrip::invalid_;
209  }
210  if (anal->highMean_ < sistrip::valid_) {
211  anal->highRms_ = sqrt(fabs(anal->highRms_ - anal->highMean_ * anal->highMean_));
212  } else {
213  anal->highMean_ = 1. * sistrip::invalid_;
214  anal->highRms_ = 1. * sistrip::invalid_;
215  }
216 
217  // Check if light levels above thresholds
218  //if ( anal->highMean_ < FastFedCablingAnalysis::dirtyThreshold_ ) { anal->addErrorCode(sistrip::invalidLightLevel_); }
219  //if ( anal->lowMean_ < FastFedCablingAnalysis::trimDacThreshold_ ) { anal->addErrorCode(sistrip::invalidTrimDacLevel_); }
220 
221  // Recalculate range
222  if (anal->highMean_ < 1. * sistrip::valid_ && anal->lowMean_ < 1. * sistrip::valid_) {
223  anal->range_ = anal->highMean_ - anal->lowMean_;
224  anal->midRange_ = anal->lowMean_ + anal->range_ / 2.;
225  } else {
226  anal->range_ = 1. * sistrip::invalid_;
227  anal->midRange_ = 1. * sistrip::invalid_;
228  }
229 
230  // Check if updated range is valid and above threshold
231  if (anal->range_ > 1. * sistrip::valid_ || anal->range_ < FastFedCablingAnalysis::threshold_) {
233  return;
234  }
235 
236  // Extract DCU id
237  anal->dcuHardId_ = 0;
238  for (uint16_t ibin = 0; ibin < FastFedCablingAnalysis::nBitsForDcuId_; ibin++) {
239  if (entries[ibin]) {
240  if (contents[ibin] > anal->midRange_) {
241  anal->dcuHardId_ += 0xFFFFFFFF & (1 << ibin);
242  }
243  }
244  }
245  if (!anal->dcuHardId_) {
246  anal->dcuHardId_ = sistrip::invalid32_;
247  }
248 
249  // Extract DCU id
250  anal->lldCh_ = 0;
251  for (uint16_t ibin = 0; ibin < FastFedCablingAnalysis::nBitsForLldCh_; ibin++) {
252  if (entries[FastFedCablingAnalysis::nBitsForDcuId_ + ibin]) {
253  if (contents[FastFedCablingAnalysis::nBitsForDcuId_ + ibin] > anal->midRange_) {
254  anal->lldCh_ += (0x3 & (1 << ibin));
255  }
256  }
257  }
258  anal->lldCh_++; // starts from 1
259  if (!anal->lldCh_) {
260  anal->lldCh_ = sistrip::invalid_;
261  }
262 }
runGCPTkAlMap.title
string title
Definition: runGCPTkAlMap.py:94
MessageLogger.h
sistrip::FAST_CABLING
Definition: ConstantsForRunType.h:89
sistrip::invalid32_
static const uint32_t invalid32_
Definition: Constants.h:15
CommissioningAlgorithm::extractFedKey
uint32_t extractFedKey(const TH1 *const)
Definition: CommissioningAlgorithm.cc:29
sistrip::unexpectedTask_
static const char unexpectedTask_[]
Definition: ConstantsForCommissioningAnalysis.h:21
FastFedCablingAlgorithm.h
CommissioningAnalysis::fedKey
const uint32_t & fedKey() const
Definition: CommissioningAnalysis.h:134
CommissioningAnalysis::addErrorCode
virtual void addErrorCode(const std::string &error)
Definition: CommissioningAnalysis.h:148
sistrip::numberOfHistos_
static const char numberOfHistos_[]
Definition: ConstantsForCommissioningAnalysis.h:16
FastFedCablingAnalysis
Histogram-based analysis for connection loop.
Definition: FastFedCablingAnalysis.h:16
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
sistrip::valid_
static const uint16_t valid_
Definition: Constants.h:17
relmon_rootfiles_spy.contents
contents
Definition: relmon_rootfiles_spy.py:129
sistrip::mlCommissioning_
static const char mlCommissioning_[]
Definition: ConstantsForLogger.h:15
FastFedCablingAnalysis::threshold_
static const float threshold_
Definition: FastFedCablingAnalysis.h:83
errors
Definition: errors.py:1
CommissioningAlgorithm::anal
CommissioningAnalysis *const anal() const
Definition: CommissioningAlgorithm.h:50
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
FastFedCablingAlgorithm::extract
void extract(const std::vector< TH1 * > &) override
Definition: FastFedCablingAlgorithm.cc:24
LaserClient_cfi.nbins
nbins
Definition: LaserClient_cfi.py:51
sistrip::numberOfBins_
static const char numberOfBins_[]
Definition: ConstantsForCommissioningAnalysis.h:18
edm::ParameterSet
Definition: ParameterSet.h:47
FastFedCablingAnalysis::nBitsForDcuId_
static const uint16_t nBitsForDcuId_
Definition: FastFedCablingAnalysis.h:92
sistrip::noEntries_
static const char noEntries_[]
Definition: ConstantsForCommissioningAnalysis.h:20
FastFedCablingAnalysis::nBitsForLldCh_
static const uint16_t nBitsForLldCh_
Definition: FastFedCablingAnalysis.h:95
sistrip::invalid_
static const uint16_t invalid_
Definition: Constants.h:16
FastFedCablingAlgorithm::analyse
void analyse() override
Definition: FastFedCablingAlgorithm.cc:64
FastFedCablingAlgorithm::FastFedCablingAlgorithm
FastFedCablingAlgorithm()
Definition: FastFedCablingAlgorithm.h:27
combine.histos
histos
Definition: combine.py:4
CommissioningAnalysis
Abstract base for derived classes that provide analysis of commissioning histograms.
Definition: CommissioningAnalysis.h:18
LaserClient_cfi.high
high
Definition: LaserClient_cfi.py:50
FastFedCablingAlgorithm::histo_
Histo histo_
Definition: FastFedCablingAlgorithm.h:37
SiStripEnumsAndStrings.h
SiStripHistoTitle.h
FastFedCablingAlgorithm::histo
const Histo & histo() const
Definition: FastFedCablingAlgorithm.h:42
CommissioningAlgorithm
Definition: CommissioningAlgorithm.h:17
sistrip::smallDataRange_
static const char smallDataRange_[]
Definition: ConstantsForCommissioningAnalysis.h:38
SiStripHistoTitle
Utility class that holds histogram title.
Definition: SiStripHistoTitle.h:20
sistrip
sistrip classes
Definition: SiStripQualityHelpers.h:14
FastFedCablingAnalysis.h
conversion_template_cfg.anal
anal
Definition: conversion_template_cfg.py:16
sistrip::nullPtr_
static const char nullPtr_[]
Definition: ConstantsForCommissioningAnalysis.h:17
LaserClient_cfi.low
low
Definition: LaserClient_cfi.py:52
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
debug_messages_cfi.errors
errors
Definition: debug_messages_cfi.py:54