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