CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
UtilsClient.cc
Go to the documentation of this file.
2 
3 #include <string>
4 #include <cmath>
5 
6 #include "TH1.h"
7 #include "TProfile.h"
8 #include "TClass.h"
9 #include "TProfile2D.h"
10 
12 
13 void
14 UtilsClient::printBadChannels( const MonitorElement* me, TH1* hi, bool positive_only)
15 {
16  if ( ! me ) {
17  std::cout << "printBadChannels() failed, NULL pointer to MonitorElement !"
18  << std::endl;
19  return;
20  }
21  if ( ! hi ) {
22  std::cout << "printBadChannels() failed, NULL pointer to ROOT histogram !"
23  << std::endl;
24  return;
25  }
26  bool title = false;
27  TProfile2D* hj = dynamic_cast<TProfile2D*>(hi);
28  int kx = -1;
29  int ky = -1;
30  for ( int ix = 1; ix <= me->getNbinsX(); ix++ ) {
31  int jx = ix * hi->GetNbinsX() / me->getNbinsX();
32  if ( jx == kx ) continue;
33  kx = jx;
34  for ( int iy = 1; iy <= me->getNbinsY(); iy++ ) {
35  int jy = iy * hi->GetNbinsY() / me->getNbinsY();
36  if ( jy == ky ) continue;
37  ky = jy;
38  if ( positive_only ) {
39  if ( hi->GetBinContent(hi->GetBin(jx, jy)) <= 0 ) continue;
40  } else {
41  float val = me->getBinContent( ix, iy );
42  // 0/3 = red/dark red
43  // 1/4 = green/dark green
44  // 2/5 = yellow/dark yellow
45  // 6 = unknown
46  if ( val == 6 ) continue;
47  if ( int(val) % 3 != 0 ) continue;
48  }
49  if ( ! title ) {
50  std::cout << " Channels failing \"" << me->getName() << "\""
51  << " (" << hi->GetName() << ") "
52  << std::endl << std::endl;
53  title = true;
54  }
55  std::cout << " ("
56  << hi->GetXaxis()->GetBinUpEdge(jx)
57  << ", "
58  << hi->GetYaxis()->GetBinUpEdge(jy);
59  if ( hj )
60  std::cout << ", "
61  << hj->GetBinEntries(hj->GetBin(jx, jy));
62  std::cout << ") = "
63  << hi->GetBinContent(hi->GetBin(jx, jy))
64  << " +- "
65  << hi->GetBinError(hi->GetBin(jx, jy))
66  << std::endl;
67  }
68  }
69  if ( title ) std::cout << std::endl;
70  return;
71 }
72 
73 bool
74 UtilsClient::getBinStatistics( TH1* histo, const int ix, const int iy, float& num, float& mean, float& rms, float minEntries )
75 {
76  num = -1.; mean = -1.; rms = -1.;
77 
78  if ( !histo ) return false;
79 
80  // TProfile2D does not inherit from TProfile; need two pointers
81 
82  TProfile *p = NULL;
83  TProfile2D *p2 = NULL;
84 
85  int bin = histo->GetBin(ix, iy);
86  char o;
87 
88  TClass *cl = histo->IsA();
89  if( cl == TClass::GetClass("TProfile") ){
90  p = static_cast<TProfile *>(histo);
91  num = p->GetBinEntries(bin);
92  o = *( p->GetErrorOption() );
93  }else if( cl == TClass::GetClass("TProfile2D") ){
94  p2 = static_cast<TProfile2D *>(histo);
95  num = p2->GetBinEntries(bin);
96  o = *( p2->GetErrorOption() );
97  }else
98  return false;
99 
100  if ( num < minEntries ) return false;
101 
102  mean = histo->GetBinContent(ix, iy);
103  if( o == 's' )
104  rms = histo->GetBinError(ix, iy);
105  else if( o == '\0' )
106  rms = histo->GetBinError(ix, iy) * std::sqrt( num );
107  // currently not compatible with other error options!!
108 
109  return true;
110 }
111 
117 // static bool getTTStatistics(TH1 *histo, const int ix, const int iy, float &num, float &mean, float &rms, float minEntries = 1.)
118 // {
119 // num = -1.; mean = -1.; rms = -1.;
120 
121 // if( !histo ) return false;
122 
123 // TProfile *p = NULL;
124 // TProfile2D *p2 = NULL;
125 
126 // std::vector<int> bins;
127 // std::vector<float> entries;
128 // char o;
129 
130 // TClass *cl = histo->IsA();
131 // if( cl == TClass::GetClass("TProfile") ){
132 
133 // int ic = histo->GetBin(ix);
134 // p = static_cast<TProfile *>(histo);
135 
136 // o = *( p->GetErrorOption() );
137 
138 // int je = ((ic-1) / 20) / 5;
139 // int jp = ((ic-1) % 20) / 5;
140 
141 // int bin;
142 // for(int i = 0; i < 5; i++){
143 // for(int j = 1; j <= 5; j++){
144 // bin = (je * 5 + i) * 20 + (jp-1) * 5 + j;
145 // bins.push_back( bin );
146 // entries.push_back( p->GetBinEntries( bin ) );
147 // }
148 // }
149 
150 // }else if( cl == TClass::GetClass("TProfile2D") ){
151 
152 // p2 = static_cast<TProfile2D *>(histo);
153 
154 // o = *( p2->GetErrorOption() );
155 
156 // int je = (ix-1) / 5;
157 // int jp = (iy-1) / 5;
158 
159 // int bin;
160 // for(int i = 1; i <= 5; i++){
161 // for(int j = 1; j <= 5; j++){
162 // bin = p2->GetBin( je*5+i, jp*5+j );
163 // bins.push_back( bin );
164 // entries.push_back( p2->GetBinEntries( bin ) );
165 // }
166 // }
167 
168 // }else
169 // return false;
170 
171 // num = 0.;
172 // float tmpm, tmpr;
173 // tmpm = tmpr = 0.;
174 
175 // int bin;
176 // float ent;
177 // float cont, err;
178 // for(unsigned u = 0; u < bins.size(); u++){
179 // bin = bins[u];
180 // ent = entries[u];
181 
182 // num += ent;
183 // tmpm += ( cont = histo->GetBinContent( bin ) ) * ent;
184 // if(o == 's')
185 // err = histo->GetBinError( bin );
186 // else if(o == '\0')
187 // err = histo->GetBinError( bin ) * std::sqrt( entries[u] );
188 // tmpr += ( err * err + cont * cont ) * ent; // sumw2 of the bin
189 // }
190 
191 // if( num < minEntries ) return false;
192 
193 // mean = tmpm / num;
194 // rms = std::sqrt( tmpr / num - mean * mean );
195 
196 // return true;
197 
198 // }
199 
200 bool
201 UtilsClient::getBinQuality( const MonitorElement* me, const int ix, const int iy )
202 {
203  if ( me ) {
204  float val = me->getBinContent(ix, iy);
205  // 0/3 = red/dark red
206  // 1/4 = green/dark green
207  // 2/5 = yellow/dark yellow
208  // 6 = unknown
209  if ( val == 0. || val == 2 || val == 6 ) return false;
210  if ( val == 1. || val == 3 || val == 4 || val == 5 ) return true;
211  }
212  return false;
213 }
214 
215 bool
216 UtilsClient::getBinStatus( const MonitorElement* me, const int ix, const int iy )
217 {
218  if ( me ) {
219  float val = me->getBinContent(ix, iy);
220  // 0/3 = red/dark red
221  // 1/4 = green/dark green
222  // 2/5 = yellow/dark yellow
223  // 6 = unknown
224  if ( val == 0. || val == 3 ) return true;
225  return false;
226  }
227  return false;
228 }
229 
230 void
231 UtilsClient::maskBinContent( const MonitorElement* me, const int ix, const int iy )
232 {
233  if ( me ) {
234  float val = me->getBinContent(ix, iy);
235  // 0/3 = red/dark red
236  // 1/4 = green/dark green
237  // 2/5 = yellow/dark yellow
238  // 6 = unknown
239  if ( val >= 0. && val <= 2. ) {
240  const_cast<MonitorElement*>(me)->setBinContent(ix, iy, val+3);
241  }
242  }
243 }
244 
245 int
247 {
248  if ( histo ) {
249  int ichannel = 1;
250  while ( ichannel <= histo->GetNbinsX() ) {
251  double counts = histo->GetBinContent(ichannel, 1);
252  if ( counts > 0 ) return( ichannel );
253  ichannel++;
254  }
255  }
256  return( 1 );
257 }
const std::string & getName(void) const
get name of ME
static bool getBinQuality(const MonitorElement *me, const int ix, const int iy)
Returns true if the bin quality is good or masked.
Definition: UtilsClient.cc:201
#define NULL
Definition: scimark2.h:8
static void maskBinContent(const MonitorElement *me, const int ix, const int iy)
Mask the bin content.
Definition: UtilsClient.cc:231
int getNbinsY(void) const
get # of bins in Y-axis
static bool getBinStatus(const MonitorElement *me, const int ix, const int iy)
Returns true if the bin status is red/dark red.
Definition: UtilsClient.cc:216
T sqrt(T t)
Definition: SSEVec.h:48
double p2[4]
Definition: TauolaWrapper.h:90
Ecal Monitor Utils for Client.
static bool getBinStatistics(TH1 *histo, const int ix, const int iy, float &num, float &mean, float &rms, float minEntries=1.)
Returns true if the bin contains good statistical data.
Definition: UtilsClient.cc:74
double getBinContent(int binx) const
get content of bin (1-D)
int getNbinsX(void) const
get # of bins in X-axis
tuple cout
Definition: gather_cfg.py:121
static void printBadChannels(const MonitorElement *me, TH1 *hi, bool positive_only=false)
Print the bad channels.
Definition: UtilsClient.cc:14
static int getFirstNonEmptyChannel(const TProfile2D *histo)
Find the first non empty bin.
Definition: UtilsClient.cc:246