CMS 3D CMS Logo

VpspScanAlgorithm.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  histos_( 2, Histo(0,"") )
20 {;}
21 
22 // ----------------------------------------------------------------------------
23 //
24 void VpspScanAlgorithm::extract( const std::vector<TH1*>& histos ) {
25 
26  if ( !anal() ) {
28  << "[VpspScanAlgorithm::" << __func__ << "]"
29  << " NULL pointer to Analysis object!";
30  return;
31  }
32 
33  // Check number of histograms
34  if ( histos.size() != 2 ) {
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 pointer
46  if ( !(*ihis) ) { continue; }
47 
48  // Check name
49  SiStripHistoTitle title( (*ihis)->GetName() );
50  if ( title.runType() != sistrip::VPSP_SCAN ) {
52  continue;
53  }
54 
55  // Extract APV number
56  uint16_t apv = sistrip::invalid_;
57  if ( title.extraInfo().find(sistrip::apv_) != std::string::npos ) {
58  std::stringstream ss;
59  ss << title.extraInfo().substr( title.extraInfo().find(sistrip::apv_) + (sizeof(sistrip::apv_) - 1), 1 );
60  ss >> std::dec >> apv;
61  }
62 
63  if ( apv <= 1 ) {
64  histos_[apv].first = *ihis;
65  histos_[apv].second = (*ihis)->GetName();
66  } else {
68  }
69 
70  }
71 
72 }
73 
74 // -----------------------------------------------------------------------------
75 //
77 
78  if ( !anal() ) {
80  << "[VpspScanAlgorithm::" << __func__ << "]"
81  << " NULL pointer to base Analysis object!";
82  return;
83  }
84 
86  VpspScanAnalysis* anal = dynamic_cast<VpspScanAnalysis*>( tmp );
87  if ( !anal ) {
89  << "[VpspScanAlgorithm::" << __func__ << "]"
90  << " NULL pointer to derived Analysis object!";
91  return;
92  }
93 
94  // from deprecated()
95 
96  std::vector<const TProfile*> histos;
97  std::vector<uint16_t> monitorables;
98  for ( uint16_t iapv = 0; iapv < 2; iapv++ ) {
99 
100  monitorables.clear();
101  monitorables.resize( 7, sistrip::invalid_ );
102 
103  histos.clear();
104  histos.push_back( const_cast<const TProfile*>( dynamic_cast<TProfile*>(histos_[iapv].first) ) );
105 
106  if ( !histos[0] ) {
108  continue;
109  }
110 
111  // Find "top" plateau
112  int first = sistrip::invalid_;
113  float top = -1. * sistrip::invalid_;;
114  for ( int k = 5; k < 55; k++ ) {
115  if ( !histos[0]->GetBinEntries(k) ) { continue; }
116  if ( histos[0]->GetBinContent(k) >= top ) {
117  first = k;
118  top = histos[0]->GetBinContent(k);
119  }
120  }
121  if ( top < -1. * sistrip::valid_ ) { top = sistrip::invalid_; } //@@ just want +ve invalid number here
122  if ( top > 1. * sistrip::valid_ ) {
124  continue;
125  }
126  monitorables[5] = static_cast<uint16_t>(top);
127  monitorables[3] = first;
128 
129  // Find "bottom" plateau
130  int last = sistrip::invalid_;
131  float bottom = 1. * sistrip::invalid_;
132  for ( int k = 55; k > 5; k-- ) {
133  if ( !histos[0]->GetBinEntries(k) ) { continue; }
134  if ( histos[0]->GetBinContent(k) <= bottom ) {
135  last = k;
136  bottom = histos[0]->GetBinContent(k);
137  }
138  }
139  if ( bottom > 1. * sistrip::valid_ ) {
141  continue;
142  }
143  monitorables[6] = static_cast<uint16_t>(bottom);
144  monitorables[4] = last;
145 
146  // Set optimum baseline level
147  float opt = bottom + ( top - bottom ) * 1./3.;
148  monitorables[1] = static_cast<uint16_t>(opt);
149 
150  // Find optimum VPSP setting
151  uint16_t vpsp = sistrip::invalid_;
152  if ( opt < 1. * sistrip::valid_ ) {
153  uint16_t ivpsp = 5;
154  for ( ; ivpsp < 55; ivpsp++ ) {
155  if ( histos[0]->GetBinContent(ivpsp) < opt ) { break; }
156  }
157  if ( ivpsp != 54 ) {
158  vpsp = ivpsp;
159  monitorables[0] = vpsp;
160  }
161  else {
163  continue;
164  }
165 
166  } else {
168  continue;
169  }
170 
171  // Set analysis results for both APVs
172  anal->vpsp_[iapv] = monitorables[0];
173  anal->adcLevel_[iapv] = monitorables[1];
174  anal->fraction_[iapv] = monitorables[2];
175  anal->topEdge_[iapv] = monitorables[3];
176  anal->bottomEdge_[iapv] = monitorables[4];
177  anal->topLevel_[iapv] = monitorables[5];
178  anal->bottomLevel_[iapv] = monitorables[6];
179 
180  }
181 
182 }
static const char unexpectedTask_[]
const uint32_t & fedKey() const
Utility class that holds histogram title.
std::vector< Histo > histos_
std::pair< TH1 *, std::string > Histo
static const char numberOfHistos_[]
static const char unexpectedExtraInfo_[]
static const char noBaselineLevel_[]
static const uint16_t valid_
Definition: Constants.h:17
sistrip classes
void extract(const std::vector< TH1 * > &)
static const char noBottomPlateau_[]
static const char mlCommissioning_[]
uint32_t extractFedKey(const TH1 *const )
virtual void addErrorCode(const std::string &error)
static const char noTopPlateau_[]
static const char apv_[]
int k[5][pyjets_maxn]
Histogram-based analysis for VPSP scan.
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.
static const char noVpspSetting_[]
CommissioningAnalysis *const anal() const
static const char nullPtr_[]