CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/DQM/EcalCommon/src/UtilsClient.cc

Go to the documentation of this file.
00001 #include "DQM/EcalCommon/interface/UtilsClient.h"
00002 
00003 #include <string>
00004 #include <cmath>
00005 
00006 #include "TH1.h"
00007 #include "TProfile.h"
00008 #include "TClass.h"
00009 #include "TProfile2D.h"
00010 
00011 #include "DQMServices/Core/interface/MonitorElement.h"
00012 
00013 void
00014 UtilsClient::printBadChannels( const MonitorElement* me, TH1* hi, bool positive_only)
00015 {
00016   if ( ! me ) {
00017     std::cout << "printBadChannels() failed, NULL pointer to MonitorElement !"
00018               << std::endl;
00019     return;
00020   }
00021   if ( ! hi ) {
00022     std::cout << "printBadChannels() failed, NULL pointer to ROOT histogram !"
00023               << std::endl;
00024     return;
00025   }
00026   bool title = false;
00027   TProfile2D* hj = dynamic_cast<TProfile2D*>(hi);
00028   int kx = -1;
00029   int ky = -1;
00030   for ( int ix = 1; ix <= me->getNbinsX(); ix++ ) {
00031     int jx = ix * hi->GetNbinsX() / me->getNbinsX();
00032     if ( jx == kx ) continue;
00033     kx = jx;
00034     for ( int iy = 1; iy <= me->getNbinsY(); iy++ ) {
00035       int jy = iy * hi->GetNbinsY() / me->getNbinsY();
00036       if ( jy == ky ) continue;
00037       ky = jy;
00038       if ( positive_only ) {
00039         if ( hi->GetBinContent(hi->GetBin(jx, jy)) <= 0 ) continue;
00040       } else {
00041         float val = me->getBinContent( ix, iy );
00042         //  0/3 = red/dark red
00043         //  1/4 = green/dark green
00044         //  2/5 = yellow/dark yellow
00045         //  6   = unknown
00046         if ( val == 6 ) continue;
00047         if ( int(val) % 3 != 0 ) continue;
00048       }
00049       if ( ! title ) {
00050         std::cout << " Channels failing \"" << me->getName() << "\""
00051                   << " (" << hi->GetName() << ") "
00052                   << std::endl << std::endl;
00053         title = true;
00054       }
00055       std::cout << " ("
00056                 << hi->GetXaxis()->GetBinUpEdge(jx)
00057                 << ", "
00058                 << hi->GetYaxis()->GetBinUpEdge(jy);
00059       if ( hj )
00060         std::cout << ", "
00061                   << hj->GetBinEntries(hj->GetBin(jx, jy));
00062       std::cout << ") = "
00063                 << hi->GetBinContent(hi->GetBin(jx, jy))
00064                 << " +- "
00065                 << hi->GetBinError(hi->GetBin(jx, jy))
00066                 << std::endl;
00067     }
00068   }
00069   if ( title ) std::cout << std::endl;
00070   return;
00071 }
00072 
00073 bool
00074 UtilsClient::getBinStatistics( TH1* histo, const int ix, const int iy, float& num, float& mean, float& rms, float minEntries )
00075 {
00076   num  = -1.; mean = -1.; rms  = -1.;
00077 
00078   if ( !histo ) return false;
00079  
00080   // TProfile2D does not inherit from TProfile; need two pointers
00081  
00082   TProfile *p = NULL;
00083   TProfile2D *p2 = NULL;
00084  
00085   int bin = histo->GetBin(ix, iy);
00086   char o;
00087  
00088   TClass *cl = histo->IsA();
00089   if( cl == TClass::GetClass("TProfile") ){
00090     p = static_cast<TProfile *>(histo);
00091     num = p->GetBinEntries(bin);
00092     o = *( p->GetErrorOption() );
00093   }else if( cl == TClass::GetClass("TProfile2D") ){
00094     p2 = static_cast<TProfile2D *>(histo);
00095     num = p2->GetBinEntries(bin);
00096     o = *( p2->GetErrorOption() );
00097   }else
00098     return false;
00099  
00100   if ( num < minEntries ) return false;
00101  
00102   mean = histo->GetBinContent(ix, iy);
00103   if( o == 's' )
00104     rms  = histo->GetBinError(ix, iy);
00105   else if( o == '\0' )
00106     rms = histo->GetBinError(ix, iy) * std::sqrt( num );
00107   // currently not compatible with other error options!!
00108  
00109   return true;
00110 }
00111  
00117 // static bool getTTStatistics(TH1 *histo, const int ix, const int iy, float &num, float &mean, float &rms, float minEntries = 1.)
00118 // {
00119 //   num = -1.; mean = -1.; rms = -1.;
00120  
00121 //   if( !histo ) return false;
00122  
00123 //   TProfile *p = NULL;
00124 //   TProfile2D *p2 = NULL;
00125  
00126 //   std::vector<int> bins;
00127 //   std::vector<float> entries;
00128 //   char o;
00129  
00130 //   TClass *cl = histo->IsA();
00131 //   if( cl == TClass::GetClass("TProfile") ){
00132  
00133 //     int ic = histo->GetBin(ix);
00134 //     p = static_cast<TProfile *>(histo);
00135  
00136 //     o = *( p->GetErrorOption() );
00137  
00138 //     int je = ((ic-1) / 20) / 5;
00139 //     int jp = ((ic-1) % 20) / 5;
00140  
00141 //     int bin;
00142 //     for(int i = 0; i < 5; i++){
00143 //       for(int j = 1; j <= 5; j++){
00144 //      bin = (je * 5 + i) * 20 + (jp-1) * 5 + j;
00145 //      bins.push_back( bin );
00146 //      entries.push_back( p->GetBinEntries( bin ) );
00147 //       }
00148 //     }
00149  
00150 //   }else if( cl == TClass::GetClass("TProfile2D") ){
00151  
00152 //     p2 = static_cast<TProfile2D *>(histo);
00153  
00154 //     o = *( p2->GetErrorOption() );
00155  
00156 //     int je = (ix-1) / 5;
00157 //     int jp = (iy-1) / 5;
00158  
00159 //     int bin;
00160 //     for(int i = 1; i <= 5; i++){
00161 //       for(int j = 1; j <= 5; j++){
00162 //      bin = p2->GetBin( je*5+i, jp*5+j );
00163 //      bins.push_back( bin );
00164 //      entries.push_back( p2->GetBinEntries( bin ) );
00165 //       }
00166 //     }
00167  
00168 //   }else
00169 //     return false;
00170  
00171 //   num = 0.;
00172 //   float tmpm, tmpr;
00173 //   tmpm = tmpr = 0.;
00174  
00175 //   int bin;
00176 //   float ent;
00177 //   float cont, err;
00178 //   for(unsigned u = 0; u < bins.size(); u++){
00179 //     bin = bins[u];
00180 //     ent = entries[u];
00181  
00182 //     num += ent;
00183 //     tmpm += ( cont = histo->GetBinContent( bin ) ) * ent;
00184 //     if(o == 's')
00185 //       err = histo->GetBinError( bin );
00186 //     else if(o == '\0')
00187 //       err = histo->GetBinError( bin ) * std::sqrt( entries[u] );
00188 //     tmpr += ( err * err + cont * cont ) * ent; // sumw2 of the bin
00189 //   }
00190  
00191 //   if( num < minEntries ) return false;
00192  
00193 //   mean = tmpm / num;
00194 //   rms = std::sqrt( tmpr / num - mean * mean );
00195  
00196 //   return true;
00197 
00198 // }
00199 
00200 bool
00201 UtilsClient::getBinQuality( const MonitorElement* me, const int ix, const int iy )
00202 {
00203   if ( me ) {
00204     float val = me->getBinContent(ix, iy);
00205     //  0/3 = red/dark red
00206     //  1/4 = green/dark green
00207     //  2/5 = yellow/dark yellow
00208     //  6   = unknown
00209     if ( val == 0. || val == 2 || val == 6 ) return false;
00210     if ( val == 1. || val == 3 || val == 4 || val == 5 ) return true;
00211   }
00212   return false;
00213 }
00214 
00215 bool
00216 UtilsClient::getBinStatus( const MonitorElement* me, const int ix, const int iy )
00217 {
00218   if ( me ) {
00219     float val = me->getBinContent(ix, iy);
00220     //  0/3 = red/dark red
00221     //  1/4 = green/dark green
00222     //  2/5 = yellow/dark yellow
00223     //  6   = unknown
00224     if ( val == 0. || val == 3 ) return true;
00225     return false;
00226   }
00227   return false;
00228 }
00229 
00230 void
00231 UtilsClient::maskBinContent( const MonitorElement* me, const int ix, const int iy )
00232 {
00233   if ( me ) {
00234     float val = me->getBinContent(ix, iy);
00235     //  0/3 = red/dark red
00236     //  1/4 = green/dark green
00237     //  2/5 = yellow/dark yellow
00238     //  6   = unknown
00239     if ( val >= 0. && val <= 2. ) {
00240       const_cast<MonitorElement*>(me)->setBinContent(ix, iy, val+3);
00241     }
00242   }
00243 }
00244 
00245 int
00246 UtilsClient::getFirstNonEmptyChannel( const TProfile2D* histo )
00247 {
00248   if ( histo ) {
00249     int ichannel = 1;
00250     while ( ichannel <= histo->GetNbinsX() ) {
00251       double counts = histo->GetBinContent(ichannel, 1);
00252       if ( counts > 0 ) return( ichannel );
00253       ichannel++;
00254     }
00255   }
00256   return( 1 );
00257 }