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
00043
00044
00045
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
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
00108
00109 return true;
00110 }
00111
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
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
00206
00207
00208
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
00221
00222
00223
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
00236
00237
00238
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 }