CMS 3D CMS Logo

PedestalsAlgorithm.cc
Go to the documentation of this file.
6 #include "TProfile.h"
7 #include "TH1.h"
8 #include <iostream>
9 #include <iomanip>
10 #include <cmath>
11 
12 using namespace sistrip;
13 
14 // ----------------------------------------------------------------------------
15 //
17  : CommissioningAlgorithm(anal),
18  hPeds_(0,""),
19  hNoise_(0,""),
20  deadStripMax_(pset.getParameter<double>("DeadStripMax")),
21  noisyStripMin_(pset.getParameter<double>("NoisyStripMin"))
22 {
24  << "[PedestalsAlgorithm::" << __func__ << "]"
25  << " Set maximum noise deviation for dead strip determination to: " << deadStripMax_;
27  << "[PedestalsAlgorithm::" << __func__ << "]"
28  << " Set minimal noise deviation for noisy strip determination to: " << noisyStripMin_;
29 }
30 
31 // ----------------------------------------------------------------------------
32 //
33 void PedestalsAlgorithm::extract( const std::vector<TH1*>& histos ) {
34 
35  if ( !anal() ) {
37  << "[PedestalsAlgorithm::" << __func__ << "]"
38  << " NULL pointer to Analysis object!";
39  return;
40  }
41 
42  // Check number of histograms
43  if ( histos.size() != 2 ) {
45  }
46 
47  // Extract FED key from histo title
48  if ( !histos.empty() ) { anal()->fedKey( extractFedKey( histos.front() ) ); }
49 
50  // Extract histograms
51  std::vector<TH1*>::const_iterator ihis = histos.begin();
52  for ( ; ihis != histos.end(); ihis++ ) {
53 
54  // Check for NULL pointer
55  if ( !(*ihis) ) { continue; }
56 
57  // Check run type
58  SiStripHistoTitle title( (*ihis)->GetName() );
59  if ( title.runType() != sistrip::PEDESTALS ) {
61  continue;
62  }
63 
64  // Extract peds and noise histos (check for legacy names first!)
65  if ( title.extraInfo().find(sistrip::extrainfo::pedsAndRawNoise_) != std::string::npos ) {
66  hPeds_.first = *ihis;
67  hPeds_.second = (*ihis)->GetName();
68  PedestalsAnalysis* a = dynamic_cast<PedestalsAnalysis*>( const_cast<CommissioningAnalysis*>( anal() ) );
69  if ( a ) { a->legacy_ = true; }
70  } else if ( title.extraInfo().find(sistrip::extrainfo::pedsAndCmSubNoise_) != std::string::npos ) {
71  hNoise_.first = *ihis;
72  hNoise_.second = (*ihis)->GetName();
73  PedestalsAnalysis* a = dynamic_cast<PedestalsAnalysis*>( const_cast<CommissioningAnalysis*>( anal() ) );
74  if ( a ) { a->legacy_ = true; }
75  } else if ( title.extraInfo().find(sistrip::extrainfo::pedestals_) != std::string::npos ) {
76  hPeds_.first = *ihis;
77  hPeds_.second = (*ihis)->GetName();
78  } else if ( title.extraInfo().find(sistrip::extrainfo::noise_) != std::string::npos ) {
79  hNoise_.first = *ihis;
80  hNoise_.second = (*ihis)->GetName();
81  } else if ( title.extraInfo().find(sistrip::extrainfo::commonMode_) != std::string::npos ) {
82  //@@ something here for CM plots?
83  } else {
85  }
86 
87  }
88 
89 }
90 
91 // -----------------------------------------------------------------------------
92 //
94 
95  if ( !anal() ) {
97  << "[PedestalsAlgorithm::" << __func__ << "]"
98  << " NULL pointer to base Analysis object!";
99  return;
100  }
101 
103  PedestalsAnalysis* anal = dynamic_cast<PedestalsAnalysis*>( tmp );
104  if ( !anal ) {
106  << "[PedestalsAlgorithm::" << __func__ << "]"
107  << " NULL pointer to derived Analysis object!";
108  return;
109  }
110 
111  if ( !hPeds_.first ) {
113  return;
114  }
115 
116  if ( !hNoise_.first ) {
118  return;
119  }
120 
121  TProfile* peds_histo = dynamic_cast<TProfile*>(hPeds_.first);
122  TProfile* noise_histo = dynamic_cast<TProfile*>(hNoise_.first);
123 
124  if ( !peds_histo ) {
126  return;
127  }
128 
129  if ( !noise_histo ) {
131  return;
132  }
133 
134  if ( peds_histo->GetNbinsX() != 256 ) {
136  return;
137  }
138 
139  if ( noise_histo->GetNbinsX() != 256 ) {
141  return;
142  }
143 
144  // Iterate through APVs
145  for ( uint16_t iapv = 0; iapv < 2; iapv++ ) {
146 
147  // Used to calc mean and rms for peds and noise
148  float p_sum = 0., p_sum2 = 0., p_max = -1.*sistrip::invalid_, p_min = sistrip::invalid_;
149  float n_sum = 0., n_sum2 = 0., n_max = -1.*sistrip::invalid_, n_min = sistrip::invalid_;
150  float r_sum = 0., r_sum2 = 0., r_max = -1.*sistrip::invalid_, r_min = sistrip::invalid_;
151 
152  // Iterate through strips of APV
153  for ( uint16_t istr = 0; istr < 128; istr++ ) {
154 
155  static uint16_t strip;
156  strip = iapv*128 + istr;
157 
158  // Pedestals and raw noise
159  if ( peds_histo ) {
160  if ( peds_histo->GetBinEntries(strip+1) ) {
161 
162  anal->peds_[iapv][istr] = peds_histo->GetBinContent(strip+1);
163  p_sum += anal->peds_[iapv][istr];
164  p_sum2 += (anal->peds_[iapv][istr] * anal->peds_[iapv][istr]);
165  if ( anal->peds_[iapv][istr] > p_max ) { p_max = anal->peds_[iapv][istr]; }
166  if ( anal->peds_[iapv][istr] < p_min ) { p_min = anal->peds_[iapv][istr]; }
167 
168  anal->raw_[iapv][istr] = peds_histo->GetBinError(strip+1);
169  r_sum += anal->raw_[iapv][istr];
170  r_sum2 += (anal->raw_[iapv][istr] * anal->raw_[iapv][istr]);
171  if ( anal->raw_[iapv][istr] > r_max ) { r_max = anal->raw_[iapv][istr]; }
172  if ( anal->raw_[iapv][istr] < r_min ) { r_min = anal->raw_[iapv][istr]; }
173 
174  }
175  }
176 
177  // Noise
178  if ( noise_histo ) {
179  if ( noise_histo->GetBinEntries(strip+1) ) {
180  anal->noise_[iapv][istr] = noise_histo->GetBinContent(strip+1);
181  n_sum += anal->noise_[iapv][istr];
182  n_sum2 += (anal->noise_[iapv][istr] * anal->noise_[iapv][istr]);
183  if ( anal->noise_[iapv][istr] > n_max ) { n_max = anal->noise_[iapv][istr]; }
184  if ( anal->noise_[iapv][istr] < n_min ) { n_min = anal->noise_[iapv][istr]; }
185  }
186  }
187 
188  } // strip loop
189 
190  // Calc mean and rms for peds
191  if ( !anal->peds_[iapv].empty() ) {
192  p_sum /= static_cast<float>( anal->peds_[iapv].size() );
193  p_sum2 /= static_cast<float>( anal->peds_[iapv].size() );
194  anal->pedsMean_[iapv] = p_sum;
195  anal->pedsSpread_[iapv] = sqrt( fabs(p_sum2 - p_sum*p_sum) );
196  }
197 
198  // Calc mean and rms for noise
199  if ( !anal->noise_[iapv].empty() ) {
200  n_sum /= static_cast<float>( anal->noise_[iapv].size() );
201  n_sum2 /= static_cast<float>( anal->noise_[iapv].size() );
202  anal->noiseMean_[iapv] = n_sum;
203  anal->noiseSpread_[iapv] = sqrt( fabs(n_sum2 - n_sum*n_sum) );
204  }
205 
206  // Calc mean and rms for raw noise
207  if ( !anal->raw_[iapv].empty() ) {
208  r_sum /= static_cast<float>( anal->raw_[iapv].size() );
209  r_sum2 /= static_cast<float>( anal->raw_[iapv].size() );
210  anal->rawMean_[iapv] = r_sum;
211  anal->rawSpread_[iapv] = sqrt( fabs(r_sum2 - r_sum*r_sum) );
212  }
213 
214  // Set max and min values for peds, noise and raw noise
215  if ( p_max > -1.*sistrip::maximum_ ) { anal->pedsMax_[iapv] = p_max; }
216  if ( p_min < 1.*sistrip::maximum_ ) { anal->pedsMin_[iapv] = p_min; }
217  if ( n_max > -1.*sistrip::maximum_ ) { anal->noiseMax_[iapv] = n_max; }
218  if ( n_min < 1.*sistrip::maximum_ ) { anal->noiseMin_[iapv] = n_min; }
219  if ( r_max > -1.*sistrip::maximum_ ) { anal->rawMax_[iapv] = r_max; }
220  if ( r_min < 1.*sistrip::maximum_ ) { anal->rawMin_[iapv] = r_min; }
221 
222  // Set dead and noisy strips
223  for ( uint16_t istr = 0; istr < 128; istr++ ) {
224  if ( anal->noiseMin_[iapv] > sistrip::maximum_ ||
225  anal->noiseMax_[iapv] > sistrip::maximum_ ) { continue; }
226  if ( anal->noise_[iapv][istr] < ( anal->noiseMean_[iapv] - deadStripMax_ * anal->noiseSpread_[iapv] ) ) {
227  anal->dead_[iapv].push_back(istr);
228  }
229  else if ( anal->noise_[iapv][istr] > ( anal->noiseMean_[iapv] + noisyStripMin_ * anal->noiseSpread_[iapv] ) ) {
230  anal->noisy_[iapv].push_back(istr);
231  }
232  }
233 
234  } // apv loop
235 
236 }
#define LogDebug(id)
static const char noise_[]
static const char unexpectedTask_[]
const uint32_t & fedKey() const
static const char pedsAndRawNoise_[]
Utility class that holds histogram title.
static const char numberOfHistos_[]
static const char unexpectedExtraInfo_[]
static const char numberOfBins_[]
sistrip classes
void extract(const std::vector< TH1 * > &)
static const char mlCommissioning_[]
T sqrt(T t)
Definition: SSEVec.h:18
uint32_t extractFedKey(const TH1 *const )
Histogram-based analysis for pedestal run.
static const uint16_t maximum_
Definition: Constants.h:20
virtual void addErrorCode(const std::string &error)
static const char commonMode_[]
static const char pedestals_[]
static const char pedsAndCmSubNoise_[]
static const uint16_t invalid_
Definition: Constants.h:16
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
double a
Definition: hdecay.h:121
Abstract base for derived classes that provide analysis of commissioning histograms.
CommissioningAnalysis *const anal() const
static const char nullPtr_[]