Go to the documentation of this file.00001 #ifndef UtilsClient_H
00002 #define UtilsClient_H
00003
00012 #include <string>
00013
00014 #include "DQMServices/Core/interface/MonitorElement.h"
00015
00016 #include "TH1.h"
00017 #include "TProfile2D.h"
00018
00023 class UtilsClient {
00024
00025 public:
00026
00033 template<class T> static T getHisto( const MonitorElement* me, bool clone = false, T ret = 0) {
00034 if( me ) {
00035
00036 TObject* ob = const_cast<MonitorElement*>(me)->getRootObject();
00037 if( ob ) {
00038 if( clone ) {
00039 if( ret ) {
00040 delete ret;
00041 }
00042 std::string s = "ME " + me->getName();
00043 ret = dynamic_cast<T>(ob->Clone(s.c_str()));
00044 if( ret ) {
00045 ret->SetDirectory(0);
00046 }
00047 } else {
00048 ret = dynamic_cast<T>(ob);
00049 }
00050 } else {
00051 ret = 0;
00052 }
00053 } else {
00054 if( !clone ) {
00055 ret = 0;
00056 }
00057 }
00058 return ret;
00059 }
00060
00067 template<class T> static void printBadChannels( const MonitorElement* me, const T* hi, bool positive_only = false ) {
00068 if ( ! me ) {
00069 std::cout << "printBadChannels() failed, NULL pointer to MonitorElement !"
00070 << std::endl;
00071 return;
00072 }
00073 if ( ! hi ) {
00074 std::cout << "printBadChannels() failed, NULL pointer to ROOT histogram !"
00075 << std::endl;
00076 return;
00077 }
00078 bool title = false;
00079 TProfile2D* hj = dynamic_cast<TProfile2D*>(const_cast<T*>(hi));
00080 int kx = -1;
00081 int ky = -1;
00082 for ( int ix = 1; ix <= me->getNbinsX(); ix++ ) {
00083 int jx = ix * hi->GetNbinsX() / me->getNbinsX();
00084 if ( jx == kx ) continue;
00085 kx = jx;
00086 for ( int iy = 1; iy <= me->getNbinsY(); iy++ ) {
00087 int jy = iy * hi->GetNbinsY() / me->getNbinsY();
00088 if ( jy == ky ) continue;
00089 ky = jy;
00090 if ( positive_only ) {
00091 if ( hi->GetBinContent(hi->GetBin(jx, jy)) <= 0 ) continue;
00092 } else {
00093 float val = me->getBinContent( ix, iy );
00094
00095
00096
00097
00098 if ( val == 6 ) continue;
00099 if ( int(val) % 3 != 0 ) continue;
00100 }
00101 if ( ! title ) {
00102 std::cout << " Channels failing \"" << me->getName() << "\""
00103 << " (" << hi->GetName() << ") "
00104 << std::endl << std::endl;
00105 title = true;
00106 }
00107 std::cout << " ("
00108 << hi->GetXaxis()->GetBinUpEdge(jx)
00109 << ", "
00110 << hi->GetYaxis()->GetBinUpEdge(jy);
00111 if ( hj )
00112 std::cout << ", "
00113 << hj->GetBinEntries(hj->GetBin(jx, jy));
00114 std::cout << ") = "
00115 << hi->GetBinContent(hi->GetBin(jx, jy))
00116 << " +- "
00117 << hi->GetBinError(hi->GetBin(jx, jy))
00118 << std::endl;
00119 }
00120 }
00121 if ( title ) std::cout << std::endl;
00122 return;
00123 }
00124
00133 template<class T> static bool getBinStatistics( const T* histo, const int ix, const int iy, float& num, float& mean, float& rms ) {
00134 num = -1.; mean = -1.; rms = -1.;
00135 float n_min_bin = 1.;
00136
00137 if ( histo ) {
00138 num = histo->GetBinEntries(histo->GetBin(ix, iy));
00139 if ( num >= n_min_bin ) {
00140 mean = histo->GetBinContent(ix, iy);
00141 rms = histo->GetBinError(ix, iy);
00142 return true;
00143 }
00144 }
00145 return false;
00146 }
00147
00153 static bool getBinQuality( const MonitorElement* me, const int ix, const int iy ) {
00154 if ( me ) {
00155 float val = me->getBinContent(ix, iy);
00156
00157
00158
00159
00160 if ( val == 0. || val == 2 || val == 6 ) return false;
00161 if ( val == 1. || val == 3 || val == 4 || val == 5 ) return true;
00162 }
00163 return false;
00164 }
00165
00171 static bool getBinStatus( const MonitorElement* me, const int ix, const int iy ) {
00172 if ( me ) {
00173 float val = me->getBinContent(ix, iy);
00174
00175
00176
00177
00178 if ( val == 0. || val == 3 ) return true;
00179 return false;
00180 }
00181 return false;
00182 }
00183
00189 static void maskBinContent( const MonitorElement* me, const int ix, const int iy ) {
00190 if ( me ) {
00191 float val = me->getBinContent(ix, iy);
00192
00193
00194
00195
00196 if ( val >= 0. && val <= 2. ) {
00197 const_cast<MonitorElement*>(me)->setBinContent(ix, iy, val+3);
00198 }
00199 }
00200 }
00201
00206 static int getFirstNonEmptyChannel( const TProfile2D* histo ) {
00207 if ( histo ) {
00208 int ichannel = 1;
00209 while ( ichannel <= histo->GetNbinsX() ) {
00210 double counts = histo->GetBinContent(ichannel, 1);
00211 if ( counts > 0 ) return( ichannel );
00212 ichannel++;
00213 }
00214 }
00215 return( 1 );
00216 }
00217
00218 private:
00219
00220 UtilsClient() {};
00221 ~UtilsClient() {};
00222
00223 };
00224
00225 #endif