CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
FastFedCablingAlgorithm Class Reference

Histogram-based analysis for connection loop. More...

#include <FastFedCablingAlgorithm.h>

Inheritance diagram for FastFedCablingAlgorithm:
CommissioningAlgorithm

Public Member Functions

 FastFedCablingAlgorithm (const edm::ParameterSet &pset, FastFedCablingAnalysis *const )
 
const Histohisto () const
 
virtual ~FastFedCablingAlgorithm ()
 
- Public Member Functions inherited from CommissioningAlgorithm
void analysis (const std::vector< TH1 * > &)
 
 CommissioningAlgorithm (CommissioningAnalysis *const )
 
 CommissioningAlgorithm ()
 
virtual ~CommissioningAlgorithm ()
 

Private Member Functions

void analyse ()
 
void extract (const std::vector< TH1 * > &)
 
 FastFedCablingAlgorithm ()
 

Private Attributes

Histo histo_
 

Additional Inherited Members

- Public Types inherited from CommissioningAlgorithm
typedef std::pair< TH1
*, std::string > 
Histo
 
- Protected Member Functions inherited from CommissioningAlgorithm
CommissioningAnalysis *const anal () const
 
uint32_t extractFedKey (const TH1 *const )
 

Detailed Description

Histogram-based analysis for connection loop.

Author
R.Bainbridge

Definition at line 16 of file FastFedCablingAlgorithm.h.

Constructor & Destructor Documentation

FastFedCablingAlgorithm::FastFedCablingAlgorithm ( const edm::ParameterSet pset,
FastFedCablingAnalysis * const  anal 
)

Definition at line 17 of file FastFedCablingAlgorithm.cc.

virtual FastFedCablingAlgorithm::~FastFedCablingAlgorithm ( )
inlinevirtual

Definition at line 22 of file FastFedCablingAlgorithm.h.

22 {;}
FastFedCablingAlgorithm::FastFedCablingAlgorithm ( )
inlineprivate

Private constructor.

Definition at line 30 of file FastFedCablingAlgorithm.h.

30 {;}

Member Function Documentation

void FastFedCablingAlgorithm::analyse ( )
privatevirtual

Performs histogram anaysis.

Implements CommissioningAlgorithm.

Definition at line 65 of file FastFedCablingAlgorithm.cc.

References CommissioningAnalysis::addErrorCode(), CommissioningAlgorithm::anal(), relmon_rootfiles_spy::contents, FastFedCablingAnalysis::dcuHardId_, python.tagInventory::entries, benchmark_cfg::errors, FastFedCablingAnalysis::highMean_, FastFedCablingAnalysis::highMedian_, FastFedCablingAnalysis::highRms_, histo(), histo_, sistrip::invalid32_, sistrip::invalid_, FastFedCablingAnalysis::lldCh_, FastFedCablingAnalysis::lowMean_, FastFedCablingAnalysis::lowMedian_, FastFedCablingAnalysis::lowRms_, FastFedCablingAnalysis::max_, FastFedCablingAnalysis::midRange_, FastFedCablingAnalysis::min_, sistrip::mlCommissioning_, pileupCalc::nbins, FastFedCablingAnalysis::nBitsForDcuId_, FastFedCablingAnalysis::nBitsForLldCh_, sistrip::noEntries_, sistrip::nullPtr_, sistrip::numberOfBins_, FastFedCablingAnalysis::range_, sistrip::smallDataRange_, python.multivaluedict::sort(), mathSSE::sqrt(), FastFedCablingAnalysis::threshold_, tmp, and sistrip::valid_.

65  {
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 uint32_t invalid32_
Definition: Constants.h:16
const Histo & histo() const
static const uint16_t nBitsForDcuId_
static const uint16_t valid_
Definition: Constants.h:18
static const char numberOfBins_[]
Histogram-based analysis for connection loop.
static const char mlCommissioning_[]
T sqrt(T t)
Definition: SSEVec.h:48
virtual void addErrorCode(const std::string &error)
static const char noEntries_[]
static const uint16_t invalid_
Definition: Constants.h:17
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_
void FastFedCablingAlgorithm::extract ( const std::vector< TH1 * > &  histos)
privatevirtual

Extracts and organises histograms.

Implements CommissioningAlgorithm.

Definition at line 24 of file FastFedCablingAlgorithm.cc.

References CommissioningAnalysis::addErrorCode(), CommissioningAlgorithm::anal(), CommissioningAlgorithm::extractFedKey(), sistrip::FAST_CABLING, CommissioningAnalysis::fedKey(), histo_, sistrip::mlCommissioning_, sistrip::numberOfHistos_, indexGen::title, and sistrip::unexpectedTask_.

24  {
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 }
static const char unexpectedTask_[]
const uint32_t & fedKey() const
Utility class that holds histogram title.
static const char numberOfHistos_[]
static const char mlCommissioning_[]
uint32_t extractFedKey(const TH1 *const )
virtual void addErrorCode(const std::string &error)
CommissioningAnalysis *const anal() const
const FastFedCablingAlgorithm::Histo & FastFedCablingAlgorithm::histo ( ) const
inline

Container of histogram pointer and title.

Definition at line 47 of file FastFedCablingAlgorithm.h.

References histo_.

Referenced by analyse().

Member Data Documentation

Histo FastFedCablingAlgorithm::histo_
private

Histo

Definition at line 41 of file FastFedCablingAlgorithm.h.

Referenced by analyse(), extract(), and histo().