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  headerLow_(nullptr,""),
20  headerHigh_(nullptr,""),
21  hPeds_(nullptr,""),
22  hNoise_(nullptr,""),
23  deadStripMax_(pset.getParameter<double>("DeadStripMax")),
24  noisyStripMin_(pset.getParameter<double>("NoisyStripMin"))
25 {;}
26 
27 // ----------------------------------------------------------------------------
28 //
29 void DaqScopeModeAlgorithm::extract( const std::vector<TH1*>& histos ) {
30 
31  if ( !anal() ) {
33  << "[DaqScopeModeAlgorithm::" << __func__ << "]"
34  << " NULL pointer to base Analysis object!";
35  return;
36  }
37 
38 
39  // Extract FED key from histo title
40  if ( !histos.empty() ) { anal()->fedKey( extractFedKey( histos.front() ) ); }
41 
42  // Extract histograms
43  std::vector<TH1*>::const_iterator ihis = histos.begin();
44  for ( ; ihis != histos.end(); ihis++ ) {
45 
46  // Check for NULL pointer
47  if ( !(*ihis) ) { continue; }
48 
49  // Check name
50  SiStripHistoTitle title( (*ihis)->GetName() );
51  if ( title.runType() != sistrip::DAQ_SCOPE_MODE ) {
53  continue;
54  }
55 
56  // Extract timing histo
57  // Extract peds and noise histos (check for legacy names first!)
58  if ( title.extraInfo().find(sistrip::extrainfo::pedsAndRawNoise_) != std::string::npos ) {
59  hPeds_.first = *ihis;
60  hPeds_.second = (*ihis)->GetName();
61  }
62  else if ( title.extraInfo().find(sistrip::extrainfo::pedsAndCmSubNoise_) != std::string::npos ) {
63  hNoise_.first = *ihis;
64  hNoise_.second = (*ihis)->GetName();
65  } else if ( title.extraInfo().find(sistrip::extrainfo::pedestals_) != std::string::npos ) {
66  hPeds_.first = *ihis;
67  hPeds_.second = (*ihis)->GetName();
68  } else if ( title.extraInfo().find(sistrip::extrainfo::noise_) != std::string::npos ) {
69  hNoise_.first = *ihis;
70  hNoise_.second = (*ihis)->GetName();
71  } else if ( title.extraInfo().find(sistrip::extrainfo::commonMode_) != std::string::npos ) {
72  //@@ something here for CM plots?
73  }
74  else if ( title.extraInfo().find(sistrip::extrainfo::scopeModeFrame_) != std::string::npos ) {
75  histo_.first = *ihis;
76  histo_.second = (*ihis)->GetName();
77  }
78  else if ( title.extraInfo().find(sistrip::extrainfo::scopeModeHeaderLow_) != std::string::npos ) {
79  headerLow_.first = *ihis;
80  headerLow_.second = (*ihis)->GetName();
81  }
82  else if ( title.extraInfo().find(sistrip::extrainfo::scopeModeHeaderHigh_) != std::string::npos ) {
83  headerHigh_.first = *ihis;
84  headerHigh_.second = (*ihis)->GetName();
85  }
86  }
87 }
88 
89 // ----------------------------------------------------------------------------
90 //
92 
93  if ( !anal() ) {
95  << "[DaqScopeModeAlgorithm::" << __func__ << "]"
96  << " NULL pointer to base Analysis object!";
97  return;
98  }
99 
101  DaqScopeModeAnalysis* anal = dynamic_cast<DaqScopeModeAnalysis*>( tmp );
102  if ( !anal ) {
104  << "[DaqScopeModeAlgorithm::" << __func__ << "]"
105  << " NULL pointer to derived Analysis object!";
106  return;
107  }
108 
109  // Analysis level wants all the informations --> it will work only on Spy-events
110  if ( !hPeds_.first ) {
112  return;
113  }
114 
115  if ( !hNoise_.first ) {
117  return;
118  }
119 
120  if ( !histo_.first ) {
122  return;
123  }
124  if ( !headerLow_.first ) {
126  return;
127  }
128  if ( !headerHigh_.first ) {
130  return;
131  }
132 
134  TProfile* peds_histo = dynamic_cast<TProfile*>(hPeds_.first);
135  TProfile* noise_histo = dynamic_cast<TProfile*>(hNoise_.first);
137  TProfile* scope_histo = dynamic_cast<TProfile*>(histo_.first);
138  TH1F* headerLow_histo = dynamic_cast<TH1F*>(headerLow_.first);
139  TH1F* headerHigh_histo = dynamic_cast<TH1F*>(headerHigh_.first);
140 
141  if ( !peds_histo ) {
143  return;
144  }
145 
146  if ( !noise_histo ) {
148  return;
149  }
150 
151  if ( !scope_histo ) {
153  return;
154  }
155 
156  if ( !headerLow_histo ) {
158  return;
159  }
160 
161  if ( !headerHigh_histo ) {
163  return;
164  }
165 
166  if ( peds_histo->GetNbinsX() != 256 ) {
168  return;
169  }
170 
171  if ( noise_histo->GetNbinsX() != 256 ) {
173  return;
174  }
175 
176  if ( scope_histo->GetNbinsX() != 298 ) {
178  return;
179  }
180 
181  // Calculate pedestals and noise
182  // Iterate through APVs
183  for ( uint16_t iapv = 0; iapv < 2; iapv++ ) {
184 
185  // Used to calc mean and rms for peds and noise
186  float p_sum = 0., p_sum2 = 0., p_max = -1.*sistrip::invalid_, p_min = sistrip::invalid_;
187  float n_sum = 0., n_sum2 = 0., n_max = -1.*sistrip::invalid_, n_min = sistrip::invalid_;
188  float r_sum = 0., r_sum2 = 0., r_max = -1.*sistrip::invalid_, r_min = sistrip::invalid_;
189 
190  // Iterate through strips of APV
191  for ( uint16_t istr = 0; istr < 128; istr++ ) {
192  uint16_t strip = iapv*128 + istr;
193 
194  // Pedestals and raw noise
195  if ( peds_histo ) {
196  if ( peds_histo->GetBinEntries(strip+1) ) {
197  anal->peds_[iapv][istr] = peds_histo->GetBinContent(strip+1);
198  p_sum += anal->peds_[iapv][istr];
199  p_sum2 += (anal->peds_[iapv][istr] * anal->peds_[iapv][istr]);
200  if ( anal->peds_[iapv][istr] > p_max ) { p_max = anal->peds_[iapv][istr]; }
201  if ( anal->peds_[iapv][istr] < p_min ) { p_min = anal->peds_[iapv][istr]; }
202 
203  anal->raw_[iapv][istr] = peds_histo->GetBinError(strip+1);
204  r_sum += anal->raw_[iapv][istr];
205  r_sum2 += (anal->raw_[iapv][istr] * anal->raw_[iapv][istr]);
206  if ( anal->raw_[iapv][istr] > r_max ) { r_max = anal->raw_[iapv][istr]; }
207  if ( anal->raw_[iapv][istr] < r_min ) { r_min = anal->raw_[iapv][istr]; }
208  }
209  }
210 
211  // Noise
212  if ( noise_histo ) {
213  if ( noise_histo->GetBinEntries(strip+1) ) {
214  anal->noise_[iapv][istr] = noise_histo->GetBinContent(strip+1);
215  n_sum += anal->noise_[iapv][istr];
216  n_sum2 += (anal->noise_[iapv][istr] * anal->noise_[iapv][istr]);
217  if ( anal->noise_[iapv][istr] > n_max ) { n_max = anal->noise_[iapv][istr]; }
218  if ( anal->noise_[iapv][istr] < n_min ) { n_min = anal->noise_[iapv][istr]; }
219  }
220  }
221  } // strip loop
222 
223  // Calc mean and rms for peds
224  if (!anal->peds_[iapv].empty()) {
225  p_sum /= static_cast<float>( anal->peds_[iapv].size() );
226  p_sum2 /= static_cast<float>( anal->peds_[iapv].size() );
227  anal->pedsMean_[iapv] = p_sum;
228  anal->pedsSpread_[iapv] = sqrt( fabs(p_sum2 - p_sum*p_sum) );
229  }
230 
231  // Calc mean and rms for noise
232  if ( !anal->noise_[iapv].empty() ) {
233  n_sum /= static_cast<float>( anal->noise_[iapv].size() );
234  n_sum2 /= static_cast<float>( anal->noise_[iapv].size() );
235  anal->noiseMean_[iapv] = n_sum;
236  anal->noiseSpread_[iapv] = sqrt( fabs(n_sum2 - n_sum*n_sum) );
237  }
238 
239  // Calc mean and rms for raw noise
240  if ( !anal->raw_[iapv].empty() ) {
241  r_sum /= static_cast<float>( anal->raw_[iapv].size() );
242  r_sum2 /= static_cast<float>( anal->raw_[iapv].size() );
243  anal->rawMean_[iapv] = r_sum;
244  anal->rawSpread_[iapv] = sqrt( fabs(r_sum2 - r_sum*r_sum) );
245  }
246 
247  // Set max and min values for peds, noise and raw noise
248  if ( p_max > -1.*sistrip::maximum_ ) { anal->pedsMax_[iapv] = p_max; }
249  if ( p_min < 1.*sistrip::maximum_ ) { anal->pedsMin_[iapv] = p_min; }
250  if ( n_max > -1.*sistrip::maximum_ ) { anal->noiseMax_[iapv] = n_max; }
251  if ( n_min < 1.*sistrip::maximum_ ) { anal->noiseMin_[iapv] = n_min; }
252  if ( r_max > -1.*sistrip::maximum_ ) { anal->rawMax_[iapv] = r_max; }
253  if ( r_min < 1.*sistrip::maximum_ ) { anal->rawMin_[iapv] = r_min; }
254 
255  // Set dead and noisy strips
256  for ( uint16_t istr = 0; istr < 128; istr++ ) {
257  if ( anal->noiseMin_[iapv] > sistrip::maximum_ ||
258  anal->noiseMax_[iapv] > sistrip::maximum_ ) { continue; }
259  if ( anal->noise_[iapv][istr] < ( anal->noiseMean_[iapv] - deadStripMax_ * anal->noiseSpread_[iapv] ) ) {
260  anal->dead_[iapv].push_back(istr);
261  }
262  else if ( anal->noise_[iapv][istr] > ( anal->noiseMean_[iapv] + noisyStripMin_ * anal->noiseSpread_[iapv] ) ) {
263  anal->noisy_[iapv].push_back(istr);
264  }
265  }
266  } // apv loop
267 
269  //anal->peak_ = (scope_histo->GetBinContent(287)+scope_histo->GetBinContent(288))/2.;
270  //anal->base_ = (scope_histo->GetBinContent(1)+scope_histo->GetBinContent(2)+scope_histo->GetBinContent(3)+scope_histo->GetBinContent(4)+scope_histo->GetBinContent(5))/5.;
271  anal->peak_ = headerHigh_histo->GetMean();
272  anal->base_ = headerLow_histo->GetMean();
273  anal->height_ = anal->peak_-anal->base_;
276  return;
277  }
278 }
static const char noise_[]
static const char unexpectedTask_[]
const uint32_t & fedKey() const
static const char pedsAndRawNoise_[]
Utility class that holds histogram title.
#define nullptr
static const char numberOfBins_[]
sistrip classes
static const float tickMarkHeightThreshold_
static const char mlCommissioning_[]
static const char scopeModeHeaderLow_[]
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_[]
static const char scopeModeHeaderHigh_[]
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.