CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
OccupancyPlotMacros.h File Reference

Go to the source code of this file.

Functions

float combinedOccupancy (TFile *ff, const char *module, const int lowerbin, const int upperbin)
 
void PlotOccupancyMap (TFile *ff, const char *module, const float min, const float max, const float mmin, const float mmax, const int color)
 

Function Documentation

float combinedOccupancy ( TFile *  ff,
const char *  module,
const int  lowerbin,
const int  upperbin 
)

Definition at line 401 of file OccupancyPlotMacros.cc.

References gather_cfg::cout, i, and mathSSE::sqrt().

401  {
402 
403  float cumoccu = -2.;
404  double cumerr = -2;
405 
406  if(ff->cd(module)) {
407 
408  TProfile* aveoccu= (TProfile*)gDirectory->Get("aveoccu");
409  // TProfile* avemult= (TProfile*)gDirectory->Get("avemult");
410  TH1F* nchannels = (TH1F*)gDirectory->Get("nchannels_real");
411 
412  float sumoccu=0.;
413  float sumnchannels=0;
414  double sumerrsq=0;
415 
416  for(int i=lowerbin; i<upperbin+1; ++i) {
417  std::cout << "processing bin " << i << " " << aveoccu->GetBinContent(i) << "+/-" << aveoccu->GetBinError(i) << std::endl;
418  sumoccu += aveoccu->GetBinContent(i);
419  sumnchannels += nchannels->GetBinContent(i);
420  sumerrsq += aveoccu->GetBinError(i)*aveoccu->GetBinError(i);
421  }
422  cumoccu = sumnchannels!=0 ? sumoccu/sumnchannels : -1;
423  cumerr = sumnchannels!=0 ? sqrt(sumerrsq)/sumnchannels : -1;
424  std::cout << "Cumulative occupancy: " << sumoccu << " " << sumnchannels << " " << cumoccu << "+/-" << cumerr;
425  }
426 
427  return cumoccu;
428 
429 }
int i
Definition: DBlmapReader.cc:9
T sqrt(T t)
Definition: SSEVec.h:48
tuple cout
Definition: gather_cfg.py:121
Definition: vlib.h:208
void PlotOccupancyMap ( TFile *  ff,
const char *  module,
const float  min,
const float  max,
const float  mmin,
const float  mmax,
const int  color 
)

Definition at line 22 of file OccupancyPlotMacros.cc.

References gather_cfg::cout, eta(), create_public_lumi_plots::exp, cmsRelvalreport::green(), i, diffTwoXMLs::label, create_public_lumi_plots::log, cmsRelvalreport::red(), and w2.

22  {
23 
24  gROOT->SetStyle("Plain");
25 
26  if(color == 1) {
27  // A not-so-great color version
28  const Int_t NRGBs = 5;
29  const Int_t NCont = 255;
30  Double_t stops[NRGBs] = { 0.00, 0.25, 0.50, 0.75, 1.00 };
31  Double_t red[NRGBs] = { 0.00, 0.00, 0.40, 1.00, 1.00 };
32  Double_t green[NRGBs] = { 0.00, 0.40, 0.70, 0.60, 1.00 };
33  Double_t blue[NRGBs] = { 0.30, 0.60, 0.00, 0.00, 0.20 };
34  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
35  gStyle->SetNumberContours(NCont);
36  }
37  else if(color==2) {
38  // Gray scale
39  const Int_t NRGBs = 3;
40  const Int_t NCont = 255;
41  Double_t stops[NRGBs] = { 0.00, 0.50, 1.00 };
42  Double_t red[NRGBs] = { 0.90, 0.50, 0.00};
43  Double_t green[NRGBs] = { 0.90, 0.50, 0.00};
44  Double_t blue[NRGBs] = { 0.90, 0.50, 0.00};
45  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
46  gStyle->SetNumberContours(NCont);
47  }
48  else if(color==3) {
49  // used by Kevin in the TRK-11-001 paper
50  const Int_t NRGBs = 7;
51  const Int_t NCont = 255;
52  Double_t stops[NRGBs] = { 0.00, 0.15, 0.30, 0.45, 0.65, 0.85, 1.00 };
53  Double_t red[NRGBs] = { 0.60, 0.30, 0.00, 0.00, 0.60, 0.40, 0.00 };
54  Double_t green[NRGBs] = { 1.00, 0.90, 0.80, 0.75, 0.20, 0.00, 0.00 };
55  Double_t blue[NRGBs] = { 1.00, 1.00, 1.00, 0.30, 0.00, 0.00, 0.00 };
56  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
57  gStyle->SetNumberContours(NCont);
58  }
59 
60  int ncol = gStyle->GetNumberOfColors();
61  std::cout << "Number of colors " << ncol << std::endl;
62 
63  if(ff->cd(module)) {
64 
65  TProfile* aveoccu= (TProfile*)gDirectory->Get("aveoccu");
66  TProfile* avemult= (TProfile*)gDirectory->Get("avemult");
67  TH1F* nchannels = (TH1F*)gDirectory->Get("nchannels_real");
68 
69  TProfile* averadius = (TProfile*)gDirectory->Get("averadius");
70  TProfile* avez = (TProfile*)gDirectory->Get("avez");
71 
72  std::cout << "pointers " << aveoccu << " " << avemult << " " << nchannels << " " << averadius << " " << avez << std::endl;
73 
74  if(aveoccu && avemult && nchannels && averadius && avez) {
75 
76  nchannels->Sumw2();
77  for(int i=1;i<nchannels->GetNbinsX()+1;++i) {
78  nchannels->SetBinError(i,0.);
79  }
80 
81  TH1D* haveoccu = aveoccu->ProjectionX("haveoccu");
82  haveoccu->SetDirectory(0);
83  haveoccu->Divide(nchannels);
84  TH1D* havemult = avemult->ProjectionX("havemult");
85  havemult->SetDirectory(0);
86  havemult->Divide(nchannels);
87 
88  TH1D* havewidth = (TH1D*)haveoccu->Clone("havewidth");
89  havewidth->SetDirectory(0);
90  havewidth->SetTitle("Average Cluster Size");
91  havewidth->Divide(havemult);
92 
93 
94  new TCanvas("occupancy","occupancy",1200,500);
95  gPad->SetLogy(1);
96  haveoccu->SetStats(0);
97  haveoccu->DrawCopy();
98  TLine* l1 = new TLine(1000,0,1000,haveoccu->GetMaximum()); l1->DrawClone();
99  TLine* l2 = new TLine(2000,0,2000,haveoccu->GetMaximum()); l2->DrawClone();
100  TLine* l3 = new TLine(3000,0,3000,haveoccu->GetMaximum()); l3->DrawClone();
101  TLine* l4 = new TLine(4000,0,4000,haveoccu->GetMaximum()); l4->DrawClone();
102  TLine* l5 = new TLine(5000,0,5000,haveoccu->GetMaximum()); l5->DrawClone();
103  TText* tpix = new TText(500,haveoccu->GetMaximum(),"BPIX+FPIX"); tpix->SetTextAlign(22); tpix->DrawClone();
104  TText* ttib = new TText(1500,haveoccu->GetMaximum(),"TIB"); ttib->SetTextAlign(22); ttib->DrawClone();
105  TText* ttid = new TText(2500,haveoccu->GetMaximum(),"TID"); ttid->SetTextAlign(22); ttid->DrawClone();
106  TText* ttob = new TText(3500,haveoccu->GetMaximum(),"TOB"); ttob->SetTextAlign(22); ttob->DrawClone();
107  TText* ttecm = new TText(4500,haveoccu->GetMaximum(),"TEC-"); ttecm->SetTextAlign(22); ttecm->DrawClone();
108  TText* ttecp = new TText(5500,haveoccu->GetMaximum(),"TEC+"); ttecp->SetTextAlign(22); ttecp->DrawClone();
109 
110  new TCanvas("multiplicity","multiplicity",1200,500);
111  gPad->SetLogy(1);
112  havemult->SetStats(0);
113  havemult->DrawCopy();
114  tpix->SetY(havemult->GetMaximum()); tpix->DrawClone();
115  ttib->SetY(havemult->GetMaximum()); ttib->DrawClone();
116  ttid->SetY(havemult->GetMaximum()); ttid->DrawClone();
117  ttob->SetY(havemult->GetMaximum()); ttob->DrawClone();
118  ttecm->SetY(havemult->GetMaximum()); ttecm->DrawClone();
119  ttecp->SetY(havemult->GetMaximum()); ttecp->DrawClone();
120  l1->SetY2(havemult->GetMaximum()); l1->DrawClone();
121  l2->SetY2(havemult->GetMaximum()); l2->DrawClone();
122  l3->SetY2(havemult->GetMaximum()); l3->DrawClone();
123  l4->SetY2(havemult->GetMaximum()); l4->DrawClone();
124  l5->SetY2(havemult->GetMaximum()); l5->DrawClone();
125 
126  new TCanvas("width","width",1200,500);
127  havewidth->SetStats(0);
128  havewidth->DrawCopy();
129  tpix->SetY(havewidth->GetMaximum()); tpix->DrawClone();
130  ttib->SetY(havewidth->GetMaximum()); ttib->DrawClone();
131  ttid->SetY(havewidth->GetMaximum()); ttid->DrawClone();
132  ttob->SetY(havewidth->GetMaximum()); ttob->DrawClone();
133  ttecm->SetY(havewidth->GetMaximum()); ttecm->DrawClone();
134  ttecp->SetY(havewidth->GetMaximum()); ttecp->DrawClone();
135  l1->SetY2(havewidth->GetMaximum()); l1->DrawClone();
136  l2->SetY2(havewidth->GetMaximum()); l2->DrawClone();
137  l3->SetY2(havewidth->GetMaximum()); l3->DrawClone();
138  l4->SetY2(havewidth->GetMaximum()); l4->DrawClone();
139  l5->SetY2(havewidth->GetMaximum()); l5->DrawClone();
140 
141  TCanvas * o2 = new TCanvas("occupancy2","occupancy2",1200,800);
142  o2->Divide(3,2);
143  o2->cd(1);
144  haveoccu->SetAxisRange(100,270);
145  haveoccu->DrawCopy();
146  tpix->SetY(haveoccu->GetMaximum()); tpix->SetX(185); tpix->DrawClone();
147  o2->cd(2);
148  haveoccu->SetAxisRange(1050,1450);
149  haveoccu->DrawCopy();
150  ttib->SetY(haveoccu->GetMaximum()); ttib->SetX(1250); ttib->DrawClone();
151  o2->cd(3);
152  haveoccu->SetAxisRange(2070,2400);
153  haveoccu->DrawCopy();
154  ttid->SetY(haveoccu->GetMaximum()); ttid->SetX(2235); ttid->DrawClone();
155  o2->cd(4);
156  haveoccu->SetAxisRange(3000,3700);
157  haveoccu->DrawCopy();
158  ttob->SetY(haveoccu->GetMaximum()); ttob->SetX(3350); ttob->DrawClone();
159  o2->cd(5);
160  haveoccu->SetAxisRange(4000,4850);
161  haveoccu->DrawCopy();
162  ttecm->SetY(haveoccu->GetMaximum()); ttecm->SetX(4425); ttecm->DrawClone();
163  o2->cd(6);
164  haveoccu->SetAxisRange(5000,5850);
165  haveoccu->DrawCopy();
166  ttecp->SetY(haveoccu->GetMaximum()); ttecp->SetX(5425); ttecp->DrawClone();
167 
168  TCanvas * m2 = new TCanvas("multiplicity2","multiplicity2",1200,800);
169  m2->Divide(3,2);
170  m2->cd(1);
171  havemult->SetAxisRange(100,270);
172  havemult->DrawCopy();
173  tpix->SetY(havemult->GetMaximum()); tpix->SetX(185); tpix->DrawClone();
174  m2->cd(2);
175  havemult->SetAxisRange(1050,1450);
176  havemult->DrawCopy();
177  ttib->SetY(havemult->GetMaximum()); ttib->SetX(1250); ttib->DrawClone();
178  m2->cd(3);
179  havemult->SetAxisRange(2070,2400);
180  havemult->DrawCopy();
181  ttid->SetY(havemult->GetMaximum()); ttid->SetX(2235); ttid->DrawClone();
182  m2->cd(4);
183  havemult->SetAxisRange(3000,3700);
184  havemult->DrawCopy();
185  ttob->SetY(havemult->GetMaximum()); ttob->SetX(3350); ttob->DrawClone();
186  m2->cd(5);
187  havemult->SetAxisRange(4000,4850);
188  havemult->DrawCopy();
189  ttecm->SetY(havemult->GetMaximum()); ttecm->SetX(4425); ttecm->DrawClone();
190  m2->cd(6);
191  havemult->SetAxisRange(5000,5850);
192  havemult->DrawCopy();
193  ttecp->SetY(havemult->GetMaximum()); ttecp->SetX(5425); ttecp->DrawClone();
194 
195  TCanvas * w2 = new TCanvas("width2","width2",1200,800);
196  w2->Divide(3,2);
197  w2->cd(1);
198  havewidth->SetAxisRange(100,270);
199  havewidth->DrawCopy();
200  tpix->SetY(havewidth->GetMaximum()); tpix->SetX(185); tpix->DrawClone();
201  w2->cd(2);
202  havewidth->SetAxisRange(1050,1450);
203  havewidth->DrawCopy();
204  ttib->SetY(havewidth->GetMaximum()); ttib->SetX(1250); ttib->DrawClone();
205  w2->cd(3);
206  havewidth->SetAxisRange(2070,2400);
207  havewidth->DrawCopy();
208  ttid->SetY(havewidth->GetMaximum()); ttid->SetX(2235); ttid->DrawClone();
209  w2->cd(4);
210  havewidth->SetAxisRange(3000,3700);
211  havewidth->DrawCopy();
212  ttob->SetY(havewidth->GetMaximum()); ttob->SetX(3350); ttob->DrawClone();
213  w2->cd(5);
214  havewidth->SetAxisRange(4000,4850);
215  havewidth->DrawCopy();
216  ttecm->SetY(havewidth->GetMaximum()); ttecm->SetX(4425); ttecm->DrawClone();
217  w2->cd(6);
218  havewidth->SetAxisRange(5000,5850);
219  havewidth->DrawCopy();
220  ttecp->SetY(havewidth->GetMaximum()); ttecp->SetX(5425); ttecp->DrawClone();
221 
222  // Loop on bins and creation of boxes
223 
224  TList modulesoccu;
225  TList modulesmult;
226 
227  for(int i=1;i<haveoccu->GetNbinsX();++i) {
228 
229  if(averadius->GetBinEntries(i)*avez->GetBinEntries(i)) {
230 
231  double dz = 2.;
232  double dr = 1.;
233  // determine module size
234 
235  if(i > 100 && i < 200) { dz=3.33;dr=0.4;} // BPIX
236 
237  if(i > 200 && i < 1000 && ( i%10 == 1 || i%10 == 7)) { dz=0.8;dr=0.4;} // FPIX
238  if(i > 200 && i < 1000 && !( i%10 == 1 || i%10 == 7)) { dz=0.8;dr=0.8;}
239 
240  if(i > 1000 && i < 2000) { dz=5.948;dr=0.4;} // TIB
241 
242  if(i > 3000 && i < 4000) { dz=9.440;dr=0.4;} // TOB
243 
244  if(i > 2000 && i < 3000 && (i%1000)/100 == 1) { dz=0.8;dr=5.647;} // TID
245  if(i > 2000 && i < 3000 && (i%1000)/100 == 2) { dz=0.8;dr=4.512;}
246  if(i > 2000 && i < 3000 && (i%1000)/100 == 3) { dz=0.8;dr=5.637;}
247 
248  if(i > 4000 && i < 6000 && (i%1000)/100 == 1) { dz=0.8;dr=4.362;} // TEC
249  if(i > 4000 && i < 6000 && (i%1000)/100 == 2) { dz=0.8;dr=4.512;}
250  if(i > 4000 && i < 6000 && (i%1000)/100 == 3) { dz=0.8;dr=5.637;}
251  if(i > 4000 && i < 6000 && (i%1000)/100 == 4) { dz=0.8;dr=5.862;}
252  if(i > 4000 && i < 6000 && (i%1000)/100 == 5) { dz=0.8;dr=7.501;}
253  if(i > 4000 && i < 6000 && (i%1000)/100 == 6) { dz=0.8;dr=9.336;}
254  if(i > 4000 && i < 6000 && (i%1000)/100 == 7) { dz=0.8;dr=10.373;}
255 
256  {
257  TBox* modoccu = new TBox(avez->GetBinContent(i)-dz,averadius->GetBinContent(i)-dr,avez->GetBinContent(i)+dz,averadius->GetBinContent(i)+dr);
258  modoccu->SetFillStyle(1001);
259  int icol=int(ncol*(log(haveoccu->GetBinContent(i))-log(min))/(log(max)-log(min)));
260  if(icol < 0) icol=0;
261  if(icol > (ncol-1)) icol=(ncol-1);
262  std::cout << i << " " << icol << " " << haveoccu->GetBinContent(i) << std::endl;
263  modoccu->SetFillColor(gStyle->GetColorPalette(icol));
264  modulesoccu.Add(modoccu);
265  }
266  {
267  TBox* modmult = new TBox(avez->GetBinContent(i)-dz,averadius->GetBinContent(i)-dr,avez->GetBinContent(i)+dz,averadius->GetBinContent(i)+dr);
268  modmult->SetFillStyle(1001);
269  int icol=int(ncol*(log(havemult->GetBinContent(i))-log(mmin))/(log(mmax)-log(mmin)));
270  if(icol < 0) icol=0;
271  if(icol > (ncol-1)) icol=(ncol-1);
272  std::cout << i << " " << icol << " " << havemult->GetBinContent(i) << std::endl;
273  modmult->SetFillColor(gStyle->GetColorPalette(icol));
274  modulesmult.Add(modmult);
275  }
276 
277  }
278 
279  }
280  // eta boundaries lines
281  TList etalines;
282  TList etalabels;
283  TList paperlabels;
284  for(int i=0;i<8;++i) {
285  double eta = 3.0-i*0.2;
286  TLine* lin = new TLine(295,2*295/(exp(eta)-exp(-eta)),305,2*305/(exp(eta)-exp(-eta)));
287  etalines.Add(lin);
288  char lab[100];
289  sprintf(lab,"%3.1f",eta);
290  TText* label = new TText(285,2*285/(exp(eta)-exp(-eta)),lab);
291  label->SetTextSize(.03);
292  label->SetTextAlign(22);
293  etalabels.Add(label);
294  }
295  for(int i=0;i<8;++i) {
296  double eta = -3.0+i*0.2;
297  TLine* lin = new TLine(-295,-2*295/(exp(eta)-exp(-eta)),-305,-2*305/(exp(eta)-exp(-eta)));
298  etalines.Add(lin);
299  char lab[100];
300  sprintf(lab,"%3.1f",eta);
301  TText* label = new TText(-285,-2*285/(exp(eta)-exp(-eta)),lab);
302  label->SetTextSize(.03);
303  label->SetTextAlign(22);
304  etalabels.Add(label);
305  }
306  for(int i=0;i<15;++i) {
307  double eta = -1.4+i*0.2;
308  TLine* lin = new TLine(130.*(exp(eta)-exp(-eta))/2.,130,138.*(exp(eta)-exp(-eta))/2.,138);
309  etalines.Add(lin);
310  char lab[100];
311  sprintf(lab,"%3.1f",eta);
312  TText* label = new TText(125.*(exp(eta)-exp(-eta))/2.,125,lab);
313  label->SetTextSize(.03);
314  label->SetTextAlign(22);
315  etalabels.Add(label);
316  }
317  TLatex* etalab = new TLatex(0,115,"#eta");
318  etalab->SetTextSize(.03);
319  etalab->SetTextAlign(22);
320  etalabels.Add(etalab);
321 
322  // CMS label
323  TLatex *cmslab = new TLatex(0.15,0.965,"CMS");
324  cmslab->SetNDC();
325  cmslab->SetTextSize(0.04);
326  cmslab->SetTextAlign(31);
327  paperlabels.Add(cmslab);
328  TLatex *enelab = new TLatex(0.92,0.965,"#sqrt{s} = 7 TeV");
329  enelab->SetNDC();
330  enelab->SetTextSize(0.04);
331  enelab->SetTextAlign(31);
332  paperlabels.Add(enelab);
333  /*
334  TLatex *lumilab = new TLatex(0.6,0.965,Form("L = %.1f fb^{-1}",19.7));
335  lumilab->SetNDC();
336  lumilab->SetTextSize(0.04);
337  lumilab->SetTextAlign(31);
338  paperlabels.Add(lumilab);
339  */
340 
341  TGaxis *raxis = new TGaxis(-310,0,-310,140,0,140,10,"S");
342  TGaxis *zaxis = new TGaxis(-310,0,310,0,-310,310,10,"S");
343  raxis->SetTickSize(.01); zaxis->SetTickSize(.01);
344  raxis->SetTitle("r (cm)"); zaxis->SetTitle("z (cm)");
345 
346  TList palette;
347  TList mpalette;
348 
349  for(int i = 0;i< ncol ; ++i) {
350  TBox* box= new TBox(315,0+140./ncol*i,330,0+140./ncol*(i+1));
351  box->SetFillStyle(1001);
352  box->SetFillColor(gStyle->GetColorPalette(i));
353  palette.Add(box);
354  mpalette.Add(box);
355 
356  }
357 
358  TGaxis *paxis = new TGaxis(330,0,330,140,min,max,510,"SLG+");
359  paxis->SetTickSize(.02);
360  paxis->SetLabelOffset(paxis->GetLabelOffset()*0.5);
361  paxis->SetTitle("channel occupancy");
362  palette.Add(paxis);
363 
364  TGaxis *mpaxis = new TGaxis(330,0,330,140,mmin,mmax,510,"SLG+");
365  mpaxis->SetTickSize(.02);
366  mpaxis->SetLabelOffset(paxis->GetLabelOffset()*0.5);
367  mpalette.Add(mpaxis);
368 
369  TCanvas* cc1 = new TCanvas("occumap","occumap",1000,500);
370  cc1->Range(-370.,-20.,390.,150.);
371  TFrame* fr1 = new TFrame(-310,0,310,140);
372  fr1->UseCurrentStyle();
373  fr1->Draw();
374  raxis->Draw(); zaxis->Draw();
375  std::cout << modulesoccu.GetSize() << std::endl;
376  etalines.Draw();
377  etalabels.Draw();
378  paperlabels.Draw();
379  palette.Draw();
380  modulesoccu.Draw();
381 
382  TCanvas* cc2 = new TCanvas("multmap","multmap",1000,500);
383  cc2->Range(-370.,-20.,390.,150.);
384  TFrame* fr2 = new TFrame(-310,0,310,140);
385  fr2->UseCurrentStyle();
386  fr2->Draw();
387  raxis->Draw(); zaxis->Draw();
388  std::cout << modulesmult.GetSize() << std::endl;
389  etalines.Draw();
390  etalabels.Draw();
391  mpalette.Draw();
392  modulesmult.Draw();
393 
394  }
395 
396 
397  }
398 
399 }
int i
Definition: DBlmapReader.cc:9
common ppss p3p6s2 common epss epspn46 common const1 w2
Definition: inclppp.h:1
T eta() const
const T & max(const T &a, const T &b)
tuple cout
Definition: gather_cfg.py:121
Definition: vlib.h:208