CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQM/SiStripCommissioningAnalysis/src/NoiseAlgorithm.cc

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