CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/DPGAnalysis/SiStripTools/bin/OccupancyPlotMacros.cc

Go to the documentation of this file.
00001 #include "TText.h"
00002 #include "TGaxis.h"
00003 #include "TFile.h"
00004 #include "TDirectory.h"
00005 #include "TH1F.h"
00006 #include "TProfile.h"
00007 #include "TH1D.h"
00008 #include "TList.h"
00009 #include "TBox.h"
00010 #include "TFrame.h"
00011 #include "TStyle.h"
00012 #include "TCanvas.h"
00013 #include "TColor.h"
00014 #include <cstring>
00015 #include <iostream>
00016 #include <math.h>
00017 #include "TROOT.h"
00018 #include "OccupancyPlotMacros.h"
00019 
00020 void PlotOccupancyMap(TFile* ff, const char* module, const float min, const float max, const float mmin, const float mmax, const int color) {
00021 
00022   gROOT->SetStyle("Plain");
00023 
00024   if(color == 1) {
00025     // A not-so-great color version
00026     const Int_t NRGBs = 5;
00027     const Int_t NCont = 255;
00028     Double_t stops[NRGBs] = { 0.00, 0.25, 0.50, 0.75, 1.00 };
00029     Double_t red[NRGBs]   = { 0.00, 0.00, 0.40, 1.00, 1.00 };
00030     Double_t green[NRGBs] = { 0.00, 0.40, 0.70, 0.60, 1.00 };
00031     Double_t blue[NRGBs]  = { 0.30, 0.60, 0.00, 0.00, 0.20 };
00032     TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
00033     gStyle->SetNumberContours(NCont);
00034   }
00035   else if(color==2) {
00036     // Gray scale
00037     const Int_t NRGBs = 3;
00038     const Int_t NCont = 255;
00039     Double_t stops[NRGBs] = { 0.00, 0.50, 1.00 };
00040     Double_t red[NRGBs]   = { 0.90, 0.50, 0.00};
00041     Double_t green[NRGBs] = { 0.90, 0.50, 0.00};
00042     Double_t blue[NRGBs]  = { 0.90, 0.50, 0.00};
00043     TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
00044     gStyle->SetNumberContours(NCont);
00045   }
00046   else if(color==3) {
00047     // used by Kevin in the TRK-11-001 paper
00048     const Int_t NRGBs = 7;
00049     const Int_t NCont = 255;
00050     Double_t stops[NRGBs] = { 0.00, 0.15, 0.30, 0.45, 0.65, 0.85, 1.00 };
00051     Double_t red[NRGBs]   = { 0.60, 0.30, 0.00, 0.00, 0.60, 0.40, 0.00 };
00052     Double_t green[NRGBs] = { 1.00, 0.90, 0.80, 0.75, 0.20, 0.00, 0.00 };
00053     Double_t blue[NRGBs]  = { 1.00, 1.00, 1.00, 0.30, 0.00, 0.00, 0.00 };
00054     TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
00055     gStyle->SetNumberContours(NCont);
00056   }
00057 
00058   int ncol = gStyle->GetNumberOfColors();
00059   std::cout << "Number of colors "  << ncol << std::endl;
00060   
00061   if(ff->cd(module)) {
00062 
00063     TProfile* aveoccu= (TProfile*)gDirectory->Get("aveoccu");
00064     TProfile* avemult= (TProfile*)gDirectory->Get("avemult");
00065     TH1F* nchannels = (TH1F*)gDirectory->Get("nchannels_real");
00066 
00067     TProfile* averadius = (TProfile*)gDirectory->Get("averadius"); 
00068     TProfile* avez = (TProfile*)gDirectory->Get("avez"); 
00069 
00070     std::cout << "pointers " << aveoccu << " " << avemult << " " << nchannels << " " << averadius << " " << avez << std::endl;
00071 
00072     if(aveoccu && avemult && nchannels && averadius && avez) {
00073 
00074       nchannels->Sumw2();
00075       for(int i=1;i<nchannels->GetNbinsX()+1;++i) {
00076         nchannels->SetBinError(i,0.);
00077       }
00078 
00079       TH1D* haveoccu = aveoccu->ProjectionX("haveoccu");
00080       haveoccu->SetDirectory(0);
00081       haveoccu->Divide(nchannels);
00082       TH1D* havemult = avemult->ProjectionX("havemult");
00083       havemult->SetDirectory(0);
00084       havemult->Divide(nchannels);
00085 
00086       TH1D* havewidth = (TH1D*)haveoccu->Clone("havewidth");
00087       havewidth->SetDirectory(0);
00088       havewidth->Divide(havemult);
00089 
00090 
00091       new TCanvas("occupancy","occupancy",1200,500);
00092       haveoccu->Draw();
00093       new TCanvas("multiplicity","multiplicity",1200,500);
00094       havemult->Draw();
00095       new TCanvas("width","width",1200,500);
00096       havewidth->Draw();
00097 
00098       // Loop on bins and creation of boxes
00099 
00100       TList modulesoccu;
00101       TList modulesmult;
00102 
00103       for(int i=1;i<haveoccu->GetNbinsX();++i) {
00104 
00105         if(averadius->GetBinEntries(i)*avez->GetBinEntries(i)) {
00106 
00107           double dz = 2.;
00108           double dr = 1.;
00109           // determine module size
00110           
00111           if(i > 100 && i < 200) { dz=3.33;dr=0.4;}
00112 
00113           if(i > 200 && i < 1000 && ( i%10 == 1 || i%10 == 7)) { dz=0.8;dr=0.4;}
00114           if(i > 200 && i < 1000 && !( i%10 == 1 || i%10 == 7)) { dz=0.8;dr=0.8;}
00115 
00116           if(i > 1000 && i < 2000) { dz=5.948;dr=0.4;}
00117 
00118           if(i > 3000 && i < 4000) { dz=9.440;dr=0.4;}
00119 
00120           if(i > 2000 && i < 3000  && (i%1000)/100 == 1) { dz=0.8;dr=5.647;} 
00121           if(i > 2000 && i < 3000  && (i%1000)/100 == 2) { dz=0.8;dr=4.512;} 
00122           if(i > 2000 && i < 3000  && (i%1000)/100 == 3) { dz=0.8;dr=5.637;} 
00123 
00124           if(i > 4000 && i < 6000  && (i%1000)/100 == 1) { dz=0.8;dr=4.362;} 
00125           if(i > 4000 && i < 6000  && (i%1000)/100 == 2) { dz=0.8;dr=4.512;} 
00126           if(i > 4000 && i < 6000  && (i%1000)/100 == 3) { dz=0.8;dr=5.637;} 
00127           if(i > 4000 && i < 6000  && (i%1000)/100 == 4) { dz=0.8;dr=5.862;} 
00128           if(i > 4000 && i < 6000  && (i%1000)/100 == 5) { dz=0.8;dr=7.501;} 
00129           if(i > 4000 && i < 6000  && (i%1000)/100 == 6) { dz=0.8;dr=9.336;} 
00130           if(i > 4000 && i < 6000  && (i%1000)/100 == 7) { dz=0.8;dr=10.373;} 
00131         
00132           {  
00133             TBox* modoccu = new TBox(avez->GetBinContent(i)-dz,averadius->GetBinContent(i)-dr,avez->GetBinContent(i)+dz,averadius->GetBinContent(i)+dr);
00134             modoccu->SetFillStyle(1001);
00135             int icol=int(ncol*(log(haveoccu->GetBinContent(i))-log(min))/(log(max)-log(min)));
00136             if(icol < 0) icol=0;
00137             if(icol > (ncol-1)) icol=(ncol-1);
00138             std::cout << i << " " << icol << " " << haveoccu->GetBinContent(i) << std::endl; 
00139             modoccu->SetFillColor(gStyle->GetColorPalette(icol));
00140             modulesoccu.Add(modoccu);
00141           }
00142           {
00143             TBox* modmult = new TBox(avez->GetBinContent(i)-dz,averadius->GetBinContent(i)-dr,avez->GetBinContent(i)+dz,averadius->GetBinContent(i)+dr);
00144             modmult->SetFillStyle(1001);
00145             int icol=int(ncol*(log(havemult->GetBinContent(i))-log(mmin))/(log(mmax)-log(mmin)));
00146             if(icol < 0) icol=0;
00147             if(icol > (ncol-1)) icol=(ncol-1);
00148             std::cout << i << " " << icol << " " << havemult->GetBinContent(i) << std::endl; 
00149             modmult->SetFillColor(gStyle->GetColorPalette(icol));
00150             modulesmult.Add(modmult);
00151           }
00152 
00153         }
00154 
00155       }
00156       // eta boundaries lines
00157       TList etalines;
00158       TList etalabels;
00159       for(int i=0;i<8;++i) {
00160         double eta = 3.0-i*0.2;
00161         TLine* lin = new TLine(295,2*295/(exp(eta)-exp(-eta)),305,2*305/(exp(eta)-exp(-eta)));
00162         etalines.Add(lin);
00163         char lab[100];
00164         sprintf(lab,"%3.1f",eta);
00165         TText* label = new TText(285,2*285/(exp(eta)-exp(-eta)),lab);
00166         label->SetTextSize(.03);
00167         label->SetTextAlign(22);
00168         etalabels.Add(label);
00169       }
00170       for(int i=0;i<8;++i) {
00171         double eta = -3.0+i*0.2;
00172         TLine* lin = new TLine(-295,-2*295/(exp(eta)-exp(-eta)),-305,-2*305/(exp(eta)-exp(-eta)));
00173         etalines.Add(lin);
00174         char lab[100];
00175         sprintf(lab,"%3.1f",eta);
00176         TText* label = new TText(-285,-2*285/(exp(eta)-exp(-eta)),lab);
00177         label->SetTextSize(.03);
00178         label->SetTextAlign(22);
00179         etalabels.Add(label);
00180       }
00181       for(int i=0;i<15;++i) {
00182         double eta = -1.4+i*0.2;
00183         TLine* lin = new TLine(130.*(exp(eta)-exp(-eta))/2.,130,138.*(exp(eta)-exp(-eta))/2.,138);
00184         etalines.Add(lin);
00185         char lab[100];
00186         sprintf(lab,"%3.1f",eta);
00187         TText* label = new TText(125.*(exp(eta)-exp(-eta))/2.,125,lab);
00188         label->SetTextSize(.03);
00189         label->SetTextAlign(22);
00190         etalabels.Add(label);
00191       }
00192 
00193 
00194       TGaxis *raxis = new TGaxis(-310,0,-310,140,0,140,10,"S");
00195       TGaxis *zaxis = new TGaxis(-310,0,310,0,-310,310,10,"S");
00196       raxis->SetTickSize(.01);      zaxis->SetTickSize(.01);
00197       raxis->SetTitle("R (cm)"); zaxis->SetTitle("Z (cm)");
00198 
00199       TList palette;
00200       TList mpalette;
00201 
00202       for(int i = 0;i< ncol ; ++i) {
00203         TBox* box= new TBox(315,0+140./ncol*i,330,0+140./ncol*(i+1));
00204         box->SetFillStyle(1001);
00205         box->SetFillColor(gStyle->GetColorPalette(i));
00206         palette.Add(box);
00207         mpalette.Add(box);
00208 
00209       }
00210 
00211       TGaxis *paxis = new TGaxis(330,0,330,140,min,max,510,"SLG+");
00212       paxis->SetTickSize(.02);
00213       paxis->SetLabelOffset(paxis->GetLabelOffset()*0.5);
00214       palette.Add(paxis);
00215 
00216       TGaxis *mpaxis = new TGaxis(330,0,330,140,mmin,mmax,510,"SLG+");
00217       mpaxis->SetTickSize(.02);
00218       mpaxis->SetLabelOffset(paxis->GetLabelOffset()*0.5);
00219       mpalette.Add(mpaxis);
00220 
00221       TCanvas* cc1 = new TCanvas("occumap","occumap",1000,500);
00222       cc1->Range(-370.,-20.,390.,150.);
00223       TFrame* fr1 = new TFrame(-310,0,310,140);
00224       fr1->UseCurrentStyle();
00225       fr1->Draw();
00226       raxis->Draw(); zaxis->Draw();
00227       std::cout << modulesoccu.GetSize() << std::endl;
00228       etalines.Draw();
00229       etalabels.Draw();
00230       palette.Draw();
00231       modulesoccu.Draw();
00232 
00233       TCanvas* cc2 = new TCanvas("multmap","multmap",1000,500); 
00234       cc2->Range(-370.,-20.,390.,150.);
00235       TFrame* fr2 = new TFrame(-310,0,310,140);
00236       fr2->UseCurrentStyle();
00237       fr2->Draw();
00238       raxis->Draw(); zaxis->Draw();
00239       std::cout << modulesmult.GetSize() << std::endl;
00240       etalines.Draw();
00241       etalabels.Draw();
00242       mpalette.Draw();
00243       modulesmult.Draw();
00244 
00245     }
00246 
00247 
00248   }
00249 
00250 }