CMS 3D CMS Logo

DaqScopeModeAlgorithm.cc
Go to the documentation of this file.
6 #include "TH1.h"
7 #include "TProfile.h"
8 #include <iostream>
9 #include <iomanip>
10 #include <cmath>
11 
12 using namespace sistrip;
13 
14 // ----------------------------------------------------------------------------
15 //
17  : CommissioningAlgorithm(anal),
18  histo_(nullptr,""),
19  hPeds_(nullptr,""),
20  hNoise_(nullptr,""),
21  deadStripMax_(pset.getParameter<double>("DeadStripMax")),
22  noisyStripMin_(pset.getParameter<double>("NoisyStripMin"))
23 {;}
24 
25 // ----------------------------------------------------------------------------
26 //
27 void DaqScopeModeAlgorithm::extract( const std::vector<TH1*>& histos ) {
28 
29  if ( !anal() ) {
31  << "[DaqScopeModeAlgorithm::" << __func__ << "]"
32  << " NULL pointer to base Analysis object!";
33  return;
34  }
35 
36  // Check
37  if ( histos.size() != 3 ) {
39  }
40 
41  // Extract FED key from histo title
42  if ( !histos.empty() ) { anal()->fedKey( extractFedKey( histos.front() ) ); }
43 
44  // Extract histograms
45  std::vector<TH1*>::const_iterator ihis = histos.begin();
46  for ( ; ihis != histos.end(); ihis++ ) {
47 
48  // Check for NULL pointer
49  if ( !(*ihis) ) { continue; }
50 
51  // Check name
52  SiStripHistoTitle title( (*ihis)->GetName() );
53  if ( title.runType() != sistrip::DAQ_SCOPE_MODE ) {
55  continue;
56  }
57 
58  // Extract timing histo
59  // Extract peds and noise histos (check for legacy names first!)
60  if ( title.extraInfo().find(sistrip::extrainfo::pedsAndRawNoise_) != std::string::npos ) {
61  hPeds_.first = *ihis;
62  hPeds_.second = (*ihis)->GetName();
63  }
64  else if ( title.extraInfo().find(sistrip::extrainfo::pedsAndCmSubNoise_) != std::string::npos ) {
65  hNoise_.first = *ihis;
66  hNoise_.second = (*ihis)->GetName();
67  } else if ( title.extraInfo().find(sistrip::extrainfo::pedestals_) != std::string::npos ) {
68  hPeds_.first = *ihis;
69  hPeds_.second = (*ihis)->GetName();
70  } else if ( title.extraInfo().find(sistrip::extrainfo::noise_) != std::string::npos ) {
71  hNoise_.first = *ihis;
72  hNoise_.second = (*ihis)->GetName();
73  } else if ( title.extraInfo().find(sistrip::extrainfo::commonMode_) != std::string::npos ) {
74  //@@ something here for CM plots?
75  }
76  else if ( title.extraInfo().find(sistrip::extrainfo::scopeModeFrame_) != std::string::npos ) {
77  histo_.first = *ihis;
78  histo_.second = (*ihis)->GetName();
79  }
80  }
81 }
82 
83 // ----------------------------------------------------------------------------
84 //
86 
87  if ( !anal() ) {
89  << "[DaqScopeModeAlgorithm::" << __func__ << "]"
90  << " NULL pointer to base Analysis object!";
91  return;
92  }
93 
96  if ( !anal ) {
98  << "[DaqScopeModeAlgorithm::" << __func__ << "]"
99  << " NULL pointer to derived Analysis object!";
100  return;
101  }
102 
103  // Analysis level wants all the informations --> it will work only on Spy-events
104  if ( !hPeds_.first ) {
106  return;
107  }
108 
109  if ( !hNoise_.first ) {
111  return;
112  }
113 
114  if ( !histo_.first ) {
116  return;
117  }
118 
120  TProfile* peds_histo = dynamic_cast<TProfile*>(hPeds_.first);
121  TProfile* noise_histo = dynamic_cast<TProfile*>(hNoise_.first);
123  TProfile* scope_histo = dynamic_cast<TProfile*>(histo_.first);
124 
125  if ( !peds_histo ) {
127  return;
128  }
129 
130  if ( !noise_histo ) {
132  return;
133  }
134 
135  if ( !scope_histo ) {
137  return;
138  }
139 
140  if ( peds_histo->GetNbinsX() != 256 ) {
142  return;
143  }
144 
145  if ( noise_histo->GetNbinsX() != 256 ) {
147  return;
148  }
149 
150  if ( scope_histo->GetNbinsX() != 298 ) {
152  return;
153  }
154 
155  // Calculate pedestals and noise
156  // Iterate through APVs
157  for ( uint16_t iapv = 0; iapv < 2; iapv++ ) {
158 
159  // Used to calc mean and rms for peds and noise
160  float p_sum = 0., p_sum2 = 0., p_max = -1.*sistrip::invalid_, p_min = sistrip::invalid_;
161  float n_sum = 0., n_sum2 = 0., n_max = -1.*sistrip::invalid_, n_min = sistrip::invalid_;
162  float r_sum = 0., r_sum2 = 0., r_max = -1.*sistrip::invalid_, r_min = sistrip::invalid_;
163 
164  // Iterate through strips of APV
165  for ( uint16_t istr = 0; istr < 128; istr++ ) {
166  uint16_t strip = iapv*128 + istr;
167 
168  // Pedestals and raw noise
169  if ( peds_histo ) {
170  if ( peds_histo->GetBinEntries(strip+1) ) {
171  anal->peds_[iapv][istr] = peds_histo->GetBinContent(strip+1);
172  p_sum += anal->peds_[iapv][istr];
173  p_sum2 += (anal->peds_[iapv][istr] * anal->peds_[iapv][istr]);
174  if ( anal->peds_[iapv][istr] > p_max ) { p_max = anal->peds_[iapv][istr]; }
175  if ( anal->peds_[iapv][istr] < p_min ) { p_min = anal->peds_[iapv][istr]; }
176 
177  anal->raw_[iapv][istr] = peds_histo->GetBinError(strip+1);
178  r_sum += anal->raw_[iapv][istr];
179  r_sum2 += (anal->raw_[iapv][istr] * anal->raw_[iapv][istr]);
180  if ( anal->raw_[iapv][istr] > r_max ) { r_max = anal->raw_[iapv][istr]; }
181  if ( anal->raw_[iapv][istr] < r_min ) { r_min = anal->raw_[iapv][istr]; }
182  }
183  }
184 
185  // Noise
186  if ( noise_histo ) {
187  if ( noise_histo->GetBinEntries(strip+1) ) {
188  anal->noise_[iapv][istr] = noise_histo->GetBinContent(strip+1);
189  n_sum += anal->noise_[iapv][istr];
190  n_sum2 += (anal->noise_[iapv][istr] * anal->noise_[iapv][istr]);
191  if ( anal->noise_[iapv][istr] > n_max ) { n_max = anal->noise_[iapv][istr]; }
192  if ( anal->noise_[iapv][istr] < n_min ) { n_min = anal->noise_[iapv][istr]; }
193  }
194  }
195  } // strip loop
196 
197  // Calc mean and rms for peds
198  if (!anal->peds_[iapv].empty()) {
199  p_sum /= static_cast<float>( anal->peds_[iapv].size() );
200  p_sum2 /= static_cast<float>( anal->peds_[iapv].size() );
201  anal->pedsMean_[iapv] = p_sum;
202  anal->pedsSpread_[iapv] = sqrt( fabs(p_sum2 - p_sum*p_sum) );
203  }
204 
205  // Calc mean and rms for noise
206  if ( !anal->noise_[iapv].empty() ) {
207  n_sum /= static_cast<float>( anal->noise_[iapv].size() );
208  n_sum2 /= static_cast<float>( anal->noise_[iapv].size() );
209  anal->noiseMean_[iapv] = n_sum;
210  anal->noiseSpread_[iapv] = sqrt( fabs(n_sum2 - n_sum*n_sum) );
211  }
212 
213  // Calc mean and rms for raw noise
214  if ( !anal->raw_[iapv].empty() ) {
215  r_sum /= static_cast<float>( anal->raw_[iapv].size() );
216  r_sum2 /= static_cast<float>( anal->raw_[iapv].size() );
217  anal->rawMean_[iapv] = r_sum;
218  anal->rawSpread_[iapv] = sqrt( fabs(r_sum2 - r_sum*r_sum) );
219  }
220 
221  // Set max and min values for peds, noise and raw noise
222  if ( p_max > -1.*sistrip::maximum_ ) { anal->pedsMax_[iapv] = p_max; }
223  if ( p_min < 1.*sistrip::maximum_ ) { anal->pedsMin_[iapv] = p_min; }
224  if ( n_max > -1.*sistrip::maximum_ ) { anal->noiseMax_[iapv] = n_max; }
225  if ( n_min < 1.*sistrip::maximum_ ) { anal->noiseMin_[iapv] = n_min; }
226  if ( r_max > -1.*sistrip::maximum_ ) { anal->rawMax_[iapv] = r_max; }
227  if ( r_min < 1.*sistrip::maximum_ ) { anal->rawMin_[iapv] = r_min; }
228 
229  // Set dead and noisy strips
230  for ( uint16_t istr = 0; istr < 128; istr++ ) {
231  if ( anal->noiseMin_[iapv] > sistrip::maximum_ ||
232  anal->noiseMax_[iapv] > sistrip::maximum_ ) { continue; }
233  if ( anal->noise_[iapv][istr] < ( anal->noiseMean_[iapv] - deadStripMax_ * anal->noiseSpread_[iapv] ) ) {
234  anal->dead_[iapv].push_back(istr);
235  }
236  else if ( anal->noise_[iapv][istr] > ( anal->noiseMean_[iapv] + noisyStripMin_ * anal->noiseSpread_[iapv] ) ) {
237  anal->noisy_[iapv].push_back(istr);
238  }
239  }
240  } // apv loop
241 
243  anal->peak_ = (scope_histo->GetBinContent(287)+scope_histo->GetBinContent(288))/2.; // trailing tickmark for each APV
244  anal->base_ = (scope_histo->GetBinContent(1)+scope_histo->GetBinContent(2)+scope_histo->GetBinContent(3)+scope_histo->GetBinContent(4)+scope_histo->GetBinContent(5))/5.;
245  anal->height_ = anal->peak_-anal->base_;
248  return;
249  }
250 }
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_[]
#define nullptr
static const char numberOfBins_[]
sistrip classes
static const float tickMarkHeightThreshold_
static const char mlCommissioning_[]
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 char commonMode_[]
static const char pedestals_[]
static const char smallTickMarkHeight_[]
static const char pedsAndCmSubNoise_[]
void extract(const std::vector< TH1 * > &) override
static const uint16_t invalid_
Definition: Constants.h:16
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
static const char scopeModeFrame_[]
Abstract base for derived classes that provide analysis of commissioning histograms.
void addErrorCode(const std::string &error) override
CommissioningAnalysis *const anal() const
static const char nullPtr_[]
Analysis for scope mode data.