CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
OccupancyPlotMacros.cc File Reference
#include "TText.h"
#include "TLine.h"
#include "TGaxis.h"
#include "TFile.h"
#include "TDirectory.h"
#include "TH1F.h"
#include "TProfile.h"
#include "TH1D.h"
#include "TList.h"
#include "TBox.h"
#include "TFrame.h"
#include "TStyle.h"
#include "TCanvas.h"
#include "TColor.h"
#include <cstring>
#include <iostream>
#include <math.h>
#include "TROOT.h"
#include "OccupancyPlotMacros.h"

Go to the source code of this file.

Functions

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

Function Documentation

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 21 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.

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