CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/DQM/SiStripCommissioningAnalysis/src/PedestalsAlgorithm.cc

Go to the documentation of this file.
00001 #include "DQM/SiStripCommissioningAnalysis/interface/PedestalsAlgorithm.h"
00002 #include "CondFormats/SiStripObjects/interface/PedestalsAnalysis.h" 
00003 #include "DataFormats/SiStripCommon/interface/SiStripHistoTitle.h"
00004 #include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include "TProfile.h"
00007 #include "TH1.h"
00008 #include <iostream>
00009 #include <iomanip>
00010 #include <cmath>
00011 
00012 using namespace sistrip;
00013 
00014 // ----------------------------------------------------------------------------
00015 // 
00016 PedestalsAlgorithm::PedestalsAlgorithm( const edm::ParameterSet & pset, PedestalsAnalysis* const anal ) 
00017   : CommissioningAlgorithm(anal),
00018     hPeds_(0,""),
00019     hNoise_(0,""),
00020     deadStripMax_(pset.getParameter<double>("DeadStripMax")),
00021     noisyStripMin_(pset.getParameter<double>("NoisyStripMin"))
00022 {
00023   LogDebug(mlCommissioning_)
00024     << "[PedestalsAlgorithm::" << __func__ << "]"
00025     << " Set maximum noise deviation for dead strip determination to: " << deadStripMax_;
00026   LogDebug(mlCommissioning_)
00027     << "[PedestalsAlgorithm::" << __func__ << "]"
00028     << " Set minimal noise deviation for noisy strip determination to: " << noisyStripMin_;
00029 }
00030 
00031 // ----------------------------------------------------------------------------
00032 // 
00033 void PedestalsAlgorithm::extract( const std::vector<TH1*>& histos ) { 
00034 
00035   if ( !anal() ) {
00036     edm::LogWarning(mlCommissioning_)
00037       << "[PedestalsAlgorithm::" << __func__ << "]"
00038       << " NULL pointer to Analysis object!";
00039     return; 
00040   }
00041 
00042   // Check number of histograms
00043   if ( histos.size() != 2 ) {
00044     anal()->addErrorCode(sistrip::numberOfHistos_);
00045   }
00046   
00047   // Extract FED key from histo title
00048   if ( !histos.empty() ) { anal()->fedKey( extractFedKey( histos.front() ) ); }
00049   
00050   // Extract histograms
00051   std::vector<TH1*>::const_iterator ihis = histos.begin();
00052   for ( ; ihis != histos.end(); ihis++ ) {
00053     
00054     // Check for NULL pointer
00055     if ( !(*ihis) ) { continue; }
00056     
00057     // Check run type
00058     SiStripHistoTitle title( (*ihis)->GetName() );
00059     if ( title.runType() != sistrip::PEDESTALS ) {
00060       anal()->addErrorCode(sistrip::unexpectedTask_);
00061       continue;
00062     }
00063     
00064     // Extract peds and noise histos (check for legacy names first!)
00065     if ( title.extraInfo().find(sistrip::extrainfo::pedsAndRawNoise_) != std::string::npos ) {
00066       hPeds_.first = *ihis;
00067       hPeds_.second = (*ihis)->GetName();
00068       PedestalsAnalysis* a = dynamic_cast<PedestalsAnalysis*>( const_cast<CommissioningAnalysis*>( anal() ) );
00069       if ( a ) { a->legacy_ = true; }
00070     } else if ( title.extraInfo().find(sistrip::extrainfo::pedsAndCmSubNoise_) != std::string::npos ) {
00071       hNoise_.first = *ihis;
00072       hNoise_.second = (*ihis)->GetName();
00073       PedestalsAnalysis* a = dynamic_cast<PedestalsAnalysis*>( const_cast<CommissioningAnalysis*>( anal() ) );
00074       if ( a ) { a->legacy_ = true; }
00075     } else if ( title.extraInfo().find(sistrip::extrainfo::pedestals_) != std::string::npos ) {
00076       hPeds_.first = *ihis;
00077       hPeds_.second = (*ihis)->GetName();
00078     } else if ( title.extraInfo().find(sistrip::extrainfo::noise_) != std::string::npos ) {
00079       hNoise_.first = *ihis;
00080       hNoise_.second = (*ihis)->GetName();
00081     } else if ( title.extraInfo().find(sistrip::extrainfo::commonMode_) != std::string::npos ) {
00082       //@@ something here for CM plots?
00083     } else { 
00084       anal()->addErrorCode(sistrip::unexpectedExtraInfo_);
00085     }
00086     
00087   }
00088 
00089 }
00090 
00091 // -----------------------------------------------------------------------------
00092 // 
00093 void PedestalsAlgorithm::analyse() {
00094 
00095   if ( !anal() ) {
00096     edm::LogWarning(mlCommissioning_)
00097       << "[PedestalsAlgorithm::" << __func__ << "]"
00098       << " NULL pointer to base Analysis object!";
00099     return; 
00100   }
00101 
00102   CommissioningAnalysis* tmp = const_cast<CommissioningAnalysis*>( anal() );
00103   PedestalsAnalysis* anal = dynamic_cast<PedestalsAnalysis*>( tmp );
00104   if ( !anal ) {
00105     edm::LogWarning(mlCommissioning_)
00106       << "[PedestalsAlgorithm::" << __func__ << "]"
00107       << " NULL pointer to derived Analysis object!";
00108     return; 
00109   }
00110 
00111   if ( !hPeds_.first ) {
00112     anal->addErrorCode(sistrip::nullPtr_);
00113     return;
00114   }
00115 
00116   if ( !hNoise_.first ) {
00117     anal->addErrorCode(sistrip::nullPtr_);
00118     return;
00119   }
00120   
00121   TProfile* peds_histo = dynamic_cast<TProfile*>(hPeds_.first);
00122   TProfile* noise_histo = dynamic_cast<TProfile*>(hNoise_.first);
00123   
00124   if ( !peds_histo ) {
00125     anal->addErrorCode(sistrip::nullPtr_);
00126     return;
00127   }
00128 
00129   if ( !noise_histo ) {
00130     anal->addErrorCode(sistrip::nullPtr_);
00131     return;
00132   }
00133 
00134   if ( peds_histo->GetNbinsX() != 256 ) {
00135     anal->addErrorCode(sistrip::numberOfBins_);
00136     return;
00137   }
00138 
00139   if ( noise_histo->GetNbinsX() != 256 ) {
00140     anal->addErrorCode(sistrip::numberOfBins_);
00141     return;
00142   }
00143   
00144   // Iterate through APVs 
00145   for ( uint16_t iapv = 0; iapv < 2; iapv++ ) {
00146 
00147     // Used to calc mean and rms for peds and noise
00148     float p_sum = 0., p_sum2 = 0., p_max = -1.*sistrip::invalid_, p_min = sistrip::invalid_;
00149     float n_sum = 0., n_sum2 = 0., n_max = -1.*sistrip::invalid_, n_min = sistrip::invalid_;
00150     float r_sum = 0., r_sum2 = 0., r_max = -1.*sistrip::invalid_, r_min = sistrip::invalid_;
00151 
00152     // Iterate through strips of APV
00153     for ( uint16_t istr = 0; istr < 128; istr++ ) {
00154 
00155       static uint16_t strip;
00156       strip = iapv*128 + istr;
00157 
00158       // Pedestals and raw noise
00159       if ( peds_histo ) {
00160         if ( peds_histo->GetBinEntries(strip+1) ) {
00161 
00162           anal->peds_[iapv][istr] = peds_histo->GetBinContent(strip+1);
00163           p_sum += anal->peds_[iapv][istr];
00164           p_sum2 += (anal->peds_[iapv][istr] * anal->peds_[iapv][istr]);
00165           if ( anal->peds_[iapv][istr] > p_max ) { p_max = anal->peds_[iapv][istr]; }
00166           if ( anal->peds_[iapv][istr] < p_min ) { p_min = anal->peds_[iapv][istr]; }
00167 
00168           anal->raw_[iapv][istr] = peds_histo->GetBinError(strip+1);
00169           r_sum += anal->raw_[iapv][istr];
00170           r_sum2 += (anal->raw_[iapv][istr] * anal->raw_[iapv][istr]);
00171           if ( anal->raw_[iapv][istr] > r_max ) { r_max = anal->raw_[iapv][istr]; }
00172           if ( anal->raw_[iapv][istr] < r_min ) { r_min = anal->raw_[iapv][istr]; }
00173 
00174         }
00175       } 
00176       
00177       // Noise
00178       if ( noise_histo ) {
00179         if ( noise_histo->GetBinEntries(strip+1) ) {
00180           anal->noise_[iapv][istr] = noise_histo->GetBinContent(strip+1);
00181           n_sum += anal->noise_[iapv][istr];
00182           n_sum2 += (anal->noise_[iapv][istr] * anal->noise_[iapv][istr]);
00183           if ( anal->noise_[iapv][istr] > n_max ) { n_max = anal->noise_[iapv][istr]; }
00184           if ( anal->noise_[iapv][istr] < n_min ) { n_min = anal->noise_[iapv][istr]; }
00185         }
00186       }
00187       
00188     } // strip loop
00189     
00190     // Calc mean and rms for peds
00191     if ( !anal->peds_[iapv].empty() ) { 
00192       p_sum /= static_cast<float>( anal->peds_[iapv].size() );
00193       p_sum2 /= static_cast<float>( anal->peds_[iapv].size() );
00194       anal->pedsMean_[iapv] = p_sum;
00195       anal->pedsSpread_[iapv] = sqrt( fabs(p_sum2 - p_sum*p_sum) );
00196     }
00197     
00198     // Calc mean and rms for noise
00199     if ( !anal->noise_[iapv].empty() ) { 
00200       n_sum /= static_cast<float>( anal->noise_[iapv].size() );
00201       n_sum2 /= static_cast<float>( anal->noise_[iapv].size() );
00202       anal->noiseMean_[iapv] = n_sum;
00203       anal->noiseSpread_[iapv] = sqrt( fabs(n_sum2 - n_sum*n_sum) );
00204     }
00205 
00206     // Calc mean and rms for raw noise
00207     if ( !anal->raw_[iapv].empty() ) { 
00208       r_sum /= static_cast<float>( anal->raw_[iapv].size() );
00209       r_sum2 /= static_cast<float>( anal->raw_[iapv].size() );
00210       anal->rawMean_[iapv] = r_sum;
00211       anal->rawSpread_[iapv] = sqrt( fabs(r_sum2 - r_sum*r_sum) );
00212     }
00213     
00214     // Set max and min values for peds, noise and raw noise
00215     if ( p_max > -1.*sistrip::maximum_ ) { anal->pedsMax_[iapv] = p_max; }
00216     if ( p_min < 1.*sistrip::maximum_ )  { anal->pedsMin_[iapv] = p_min; }
00217     if ( n_max > -1.*sistrip::maximum_ ) { anal->noiseMax_[iapv] = n_max; }
00218     if ( n_min < 1.*sistrip::maximum_ )  { anal->noiseMin_[iapv] = n_min; }
00219     if ( r_max > -1.*sistrip::maximum_ ) { anal->rawMax_[iapv] = r_max; }
00220     if ( r_min < 1.*sistrip::maximum_ )  { anal->rawMin_[iapv] = r_min; }
00221     
00222     // Set dead and noisy strips
00223     for ( uint16_t istr = 0; istr < 128; istr++ ) {
00224       if ( anal->noiseMin_[iapv] > sistrip::maximum_ ||
00225            anal->noiseMax_[iapv] > sistrip::maximum_ ) { continue; }
00226       if ( anal->noise_[iapv][istr] < ( anal->noiseMean_[iapv] - deadStripMax_ * anal->noiseSpread_[iapv] ) ) {
00227         anal->dead_[iapv].push_back(istr);
00228       } 
00229       else if ( anal->noise_[iapv][istr] > ( anal->noiseMean_[iapv] + noisyStripMin_ * anal->noiseSpread_[iapv] ) ) {
00230         anal->noisy_[iapv].push_back(istr);
00231       }
00232     }
00233     
00234   } // apv loop
00235 
00236 }