CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DaqScopeModeAlgorithm.cc
Go to the documentation of this file.
6 #include "TH1.h"
7 #include <iostream>
8 #include <iomanip>
9 #include <cmath>
10 
11 using namespace sistrip;
12 
13 // ----------------------------------------------------------------------------
14 //
16  : CommissioningAlgorithm(anal),
17  histo_(0,"")
18 {;}
19 
20 // ----------------------------------------------------------------------------
21 //
22 void DaqScopeModeAlgorithm::extract( const std::vector<TH1*>& histos ) {
23 
24  if ( !anal() ) {
26  << "[DaqScopeModeAlgorithm::" << __func__ << "]"
27  << " NULL pointer to base Analysis object!";
28  return;
29  }
30 
31  // Check
32  if ( histos.size() != 1 ) {
34  }
35 
36  // Extract FED key from histo title
37  if ( !histos.empty() ) { anal()->fedKey( extractFedKey( histos.front() ) ); }
38 
39  // Extract histograms
40  std::vector<TH1*>::const_iterator ihis = histos.begin();
41  for ( ; ihis != histos.end(); ihis++ ) {
42 
43  // Check for NULL pointer
44  if ( !(*ihis) ) { continue; }
45 
46  // Check name
47  SiStripHistoTitle title( (*ihis)->GetName() );
48  if ( title.runType() != sistrip::DAQ_SCOPE_MODE ) {
50  continue;
51  }
52 
53  // Extract timing histo
54  histo_.first = *ihis;
55  histo_.second = (*ihis)->GetName();
56 
57  }
58 
59 }
60 
61 // ----------------------------------------------------------------------------
62 //
64 
65  if ( !anal() ) {
67  << "[DaqScopeModeAlgorithm::" << __func__ << "]"
68  << " NULL pointer to base Analysis object!";
69  return;
70  }
71 
74  if ( !anal ) {
76  << "[DaqScopeModeAlgorithm::" << __func__ << "]"
77  << " NULL pointer to derived Analysis object!";
78  return;
79  }
80 
81  if ( !histo_.first ) {
83  return;
84  }
85 
86  // Some initialization
87  std::vector<float> median;
88  float max_value = -1. * sistrip::invalid_;
89  float max_contents = -1. * sistrip::invalid_;
90  float sum = 0.;
91  float sum2 = 0.;
92 
93  // Entries, min, mode
94  uint16_t nbins = static_cast<uint16_t>( histo_.first->GetNbinsX() );
95  for ( uint16_t ibin = 0; ibin < nbins; ibin++ ) {
96  float value = histo_.first->GetBinLowEdge(ibin+1) + histo_.first->GetBinWidth(ibin+1) / 2.;
97  float contents = histo_.first->GetBinContent(ibin+1);
98  //float errors = histo_.first->GetBinError(ibin+1);
99  if ( contents ) {
100  if ( contents > max_contents ) { anal->mode_ = contents; max_contents = contents; }
101  if ( value > max_value ) { max_value = value; }
102  if ( value < anal->min_ ) { anal->min_ = value; }
103  sum += value * contents;
104  sum2 += value * contents* value * contents;
105  median.insert( median.end(), static_cast<uint32_t>(contents), value );
106  }
107  anal->entries_ += contents;
108  }
109 
110  // Max
111  if ( max_value > -1. * sistrip::maximum_ ) { anal->max_ = max_value; }
112 
113  // Median
114  sort( median.begin(), median.end() );
115  if ( !median.empty() ) { anal->median_ = median[ median.size()%2 ? median.size()/2 : median.size()/2 ]; }
116 
117  // Mean, rms
118  if ( anal->entries_ ) {
119  sum /= static_cast<float>(anal->entries_);
120  sum2 /= static_cast<float>(anal->entries_);
121  anal->mean_ = sum;
122  if ( sum2 > sum*sum ) { anal->rms_ = sqrt( sum2 - sum*sum ); }
123  }
124 
125 }
static const char unexpectedTask_[]
const uint32_t & fedKey() const
const float & median() const
Utility class that holds histogram title.
static const char numberOfHistos_[]
static const char mlCommissioning_[]
double const max_value[nValueQuantityType]
Definition: ValueQuantity.h:67
T sqrt(T t)
Definition: SSEVec.h:18
uint32_t extractFedKey(const TH1 *const )
static const uint16_t maximum_
Definition: Constants.h:20
virtual void addErrorCode(const std::string &error)
static const uint16_t invalid_
Definition: Constants.h:16
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
Abstract base for derived classes that provide analysis of commissioning histograms.
void extract(const std::vector< TH1 * > &)
CommissioningAnalysis *const anal() const
static const char nullPtr_[]
Analysis for scope mode data.