Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-04-21 02:53:36

0001 #include "TROOT.h"
0002 #include "TStyle.h"
0003 #include "TFile.h"
0004 #include "TF1.h"
0005 #include "TH1.h"
0006 #include "TH2.h"
0007 #include "TCanvas.h"
0008 #include "TGraphErrors.h"
0009 #include "TPaveStats.h"
0010 #include "TLegend.h"
0011 #include "TChain.h"
0012 #include "TVirtualFitter.h"
0013 #include "TBox.h"
0014 #include "TPaveText.h"
0015 #include "TColor.h"
0016 #include "TProfile.h"
0017 #include "TProfile2D.h"
0018 
0019 //#include <iostream>
0020 #include <iomanip>
0021 #include <string>
0022 #include <sstream>
0023 #include <ctime>
0024 #include <map>
0025 #include <algorithm>
0026 #include <math.h>
0027 #include <vector>
0028 
0029 void setTDRStyle() {
0030 
0031   TStyle *tdrStyle = new TStyle("tdrStyle","Style for P-TDR");
0032 
0033 // For the canvas:
0034   tdrStyle->SetCanvasBorderMode(0);
0035   tdrStyle->SetCanvasColor(kWhite);
0036   tdrStyle->SetCanvasDefH(600); //Height of canvas
0037   tdrStyle->SetCanvasDefW(600); //Width of canvas
0038   tdrStyle->SetCanvasDefX(0);   //POsition on screen
0039   tdrStyle->SetCanvasDefY(0);
0040 
0041 // For the Pad:
0042   tdrStyle->SetPadBorderMode(0);
0043   tdrStyle->SetPadColor(kWhite);
0044   tdrStyle->SetPadGridX(false);
0045   tdrStyle->SetPadGridY(false);
0046   tdrStyle->SetGridColor(0);
0047   tdrStyle->SetGridStyle(3);
0048   tdrStyle->SetGridWidth(1);
0049 
0050 // For the frame:
0051   tdrStyle->SetFrameBorderMode(0);
0052   tdrStyle->SetFrameBorderSize(1);
0053   tdrStyle->SetFrameFillColor(0);
0054   tdrStyle->SetFrameFillStyle(0);
0055   tdrStyle->SetFrameLineColor(1);
0056   tdrStyle->SetFrameLineStyle(1);
0057   tdrStyle->SetFrameLineWidth(1);
0058 
0059 // For the histo:
0060   tdrStyle->SetHistLineColor(1);
0061   tdrStyle->SetHistLineStyle(0);
0062   tdrStyle->SetHistLineWidth(1);
0063   tdrStyle->SetEndErrorSize(2);
0064   tdrStyle->SetErrorX(0.);
0065   tdrStyle->SetMarkerStyle(20);
0066 
0067 //For the fit/function:
0068   tdrStyle->SetOptFit(1);
0069   tdrStyle->SetFitFormat("5.4g");
0070   tdrStyle->SetFuncColor(2);
0071   tdrStyle->SetFuncStyle(1);
0072   tdrStyle->SetFuncWidth(1);
0073 
0074 //For the date:
0075   tdrStyle->SetOptDate(0);
0076 
0077 // For the statistics box:
0078   tdrStyle->SetOptFile(0);
0079   tdrStyle->SetOptStat(0); // To display the mean and RMS:   SetOptStat("mr");
0080   tdrStyle->SetStatColor(kWhite);
0081   tdrStyle->SetStatFont(42);
0082   tdrStyle->SetStatFontSize(0.025);
0083   tdrStyle->SetStatTextColor(1);
0084   tdrStyle->SetStatFormat("6.4g");
0085   tdrStyle->SetStatBorderSize(1);
0086   tdrStyle->SetStatH(0.1);
0087   tdrStyle->SetStatW(0.15);
0088 
0089 // Margins:
0090   tdrStyle->SetPadTopMargin(0.07);
0091   tdrStyle->SetPadBottomMargin(0.13);
0092   tdrStyle->SetPadLeftMargin(0.13);
0093   tdrStyle->SetPadRightMargin(0.19);
0094 
0095 // For the Global title:
0096   tdrStyle->SetOptTitle(0);
0097   tdrStyle->SetTitleFont(42);
0098   tdrStyle->SetTitleColor(1);
0099   tdrStyle->SetTitleTextColor(1);
0100   tdrStyle->SetTitleFillColor(10);
0101   tdrStyle->SetTitleFontSize(0.05);
0102 
0103 // For the axis titles:
0104   tdrStyle->SetTitleColor(1, "XYZ");
0105   tdrStyle->SetTitleFont(42, "XYZ");
0106   tdrStyle->SetTitleSize(0.06, "XYZ");
0107   tdrStyle->SetTitleXOffset(0.9);
0108   tdrStyle->SetTitleYOffset(1.);
0109 
0110 // For the axis labels:
0111   tdrStyle->SetLabelColor(1, "XYZ");
0112   tdrStyle->SetLabelFont(42, "XYZ");
0113   tdrStyle->SetLabelOffset(0.007, "XYZ");
0114   tdrStyle->SetLabelSize(0.045, "XYZ");
0115 
0116 // For the axis:
0117   tdrStyle->SetAxisColor(1, "XYZ");
0118   tdrStyle->SetStripDecimals(kTRUE);
0119   tdrStyle->SetTickLength(0.03, "XYZ");
0120   tdrStyle->SetNdivisions(510, "XYZ");
0121   tdrStyle->SetPadTickX(1);  // To get tick marks on the opposite side of the frame
0122   tdrStyle->SetPadTickY(1);
0123 
0124 // Change for log plots:
0125   tdrStyle->SetOptLogx(0);
0126   tdrStyle->SetOptLogy(0);
0127   tdrStyle->SetOptLogz(0);
0128 
0129 // Postscript options:
0130   tdrStyle->SetPaperSize(20.,20.);
0131 
0132   tdrStyle->cd();
0133 }
0134 
0135 
0136 void palette(){
0137 
0138     const Int_t NRGBs = 5;
0139     const Int_t NCont = 255;
0140 
0141     Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
0142     Double_t red[NRGBs]   = { 0.00, 0.00, 0.87, 1.00, 0.51 };
0143     Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
0144     Double_t blue[NRGBs]  = { 0.51, 1.00, 0.12, 0.00, 0.00 };
0145     TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
0146     gStyle->SetNumberContours(NCont);
0147 }
0148 
0149 
0150 // data dirs
0151 TString theDirName = "Figures";
0152 //
0153 
0154 //
0155 float xmin = -4.;
0156 float xmax = 4.; 
0157 
0158 float ymin = -3.1416;
0159 float ymax = 3.1416;
0160 
0161 float zmin_x0 = 0.; 
0162 float zmax_x0;
0163 
0164 float zmin_lambdaI = 0.; 
0165 float zmax_lambdaI;
0166 //
0167 
0168 //
0169 int rebin_x0_x = 1;
0170 int rebin_x0_y = 1;
0171 float norm_x0 = rebin_x0_x*rebin_x0_y;
0172 
0173 int rebin_lambdaI_x = 1;
0174 int rebin_lambdaI_y = 1;
0175 float norm_lambdaI = rebin_lambdaI_x*rebin_lambdaI_y;
0176 //
0177 
0178 using namespace std;
0179 
0180 // Main
0181 void MaterialBudget_Maps() {
0182 
0183     //TDR style
0184     setTDRStyle(); 
0185     //palette colori
0186     palette();
0187 
0188     TString subDetectorFileName = "matbdg_Tracker.root";
0189 
0190     // open file
0191     TFile *subDetectorFile = new TFile(subDetectorFileName);
0192     cout << "*** Open file... " << endl;
0193     cout << subDetectorFileName << endl;
0194     cout << "***" << endl;
0195 
0196     //case t/X0
0197     TProfile2D *prof_x0_Tracker_XY = (TProfile2D*)subDetectorFile->Get("30");
0198     TH2D* hist_x0_Tracker_XY = (TH2D*)prof_x0_Tracker_XY->ProjectionXY();
0199 
0200     // canvas
0201     TCanvas can_x0("can_x0","can_x0",800,800);
0202 //  can_x0.Range(0,0,25,25);
0203     
0204     // Draw
0205     hist_x0_Tracker_XY->GetXaxis()->SetRangeUser(xmin,xmax);
0206     hist_x0_Tracker_XY->GetYaxis()->SetRangeUser(ymin,ymax);
0207     hist_x0_Tracker_XY->Rebin2D(rebin_x0_x,rebin_x0_y);
0208     hist_x0_Tracker_XY->Scale(1/norm_x0);
0209 
0210     zmax_x0 = hist_x0_Tracker_XY->GetMaximum();
0211     hist_x0_Tracker_XY->SetMinimum(zmin_x0);
0212     hist_x0_Tracker_XY->SetMaximum(zmax_x0);
0213 
0214     hist_x0_Tracker_XY->GetXaxis()->SetTitle("#eta");
0215     hist_x0_Tracker_XY->GetYaxis()->SetTitle("#varphi [rad]");
0216     hist_x0_Tracker_XY->GetZaxis()->SetTitle("t/X_{0}");
0217     hist_x0_Tracker_XY->GetZaxis()->SetTitleOffset(1.1);
0218 
0219     hist_x0_Tracker_XY->Draw("zcol");
0220 
0221     // text
0222     TPaveText* text_x0 = new TPaveText(0.13,0.937,0.35,0.997,"NDC");
0223     text_x0->SetFillColor(0);
0224     text_x0->SetBorderSize(0);
0225     text_x0->AddText("CMS Simulation");
0226     text_x0->SetTextAlign(13);
0227     text_x0->Draw();
0228 
0229     // Store
0230     can_x0.Update();
0231     //  can_x0.SaveAs( Form( "%s/EtaPhiMap_x0.eps",  theDirName.Data() ) );
0232     //  can_x0.SaveAs( Form( "%s/EtaPhiMap_x0.gif",  theDirName.Data() ) );
0233     can_x0.SaveAs( Form( "%s/EtaPhiMap_x0.pdf",  theDirName.Data() ) );
0234     can_x0.SaveAs( Form( "%s/EtaPhiMap_x0.png",  theDirName.Data() ) );
0235     can_x0.SaveAs( Form( "%s/EtaPhiMap_x0.root",  theDirName.Data() ) );
0236     //  can_x0.SaveAs( Form( "%s/EtaPhiMap_x0.C",  theDirName.Data() ) );
0237     //
0238 
0239 //----------------
0240 
0241     //case t/lambdaI
0242     TProfile2D *prof_lambdaI_Tracker_XY = (TProfile2D*)subDetectorFile->Get("1030");
0243     TH2D* hist_lambdaI_Tracker_XY = (TH2D*)prof_lambdaI_Tracker_XY->ProjectionXY();
0244 
0245     // canvas
0246     TCanvas can_lambdaI("can_lambdaI","can_lambdaI",800,800);
0247 //  can_lambdaI.Range(0,0,25,25);
0248     
0249     // Draw
0250     hist_lambdaI_Tracker_XY->GetXaxis()->SetRangeUser(xmin,xmax);
0251     hist_lambdaI_Tracker_XY->GetYaxis()->SetRangeUser(ymin,ymax);
0252     hist_lambdaI_Tracker_XY->Rebin2D(rebin_lambdaI_x,rebin_lambdaI_y);
0253     hist_lambdaI_Tracker_XY->Scale(1/norm_lambdaI);
0254 
0255     zmax_lambdaI = hist_lambdaI_Tracker_XY->GetMaximum();
0256     hist_lambdaI_Tracker_XY->SetMinimum(zmin_lambdaI);
0257     hist_lambdaI_Tracker_XY->SetMaximum(zmax_lambdaI);
0258 
0259     hist_lambdaI_Tracker_XY->GetXaxis()->SetTitle("#eta");
0260     hist_lambdaI_Tracker_XY->GetYaxis()->SetTitle("#varphi [rad]");
0261     hist_lambdaI_Tracker_XY->GetZaxis()->SetTitle("t/#lambda_{I}");
0262 
0263     hist_lambdaI_Tracker_XY->Draw("zcol");
0264 
0265     // text
0266     TPaveText* text_lambdaI = new TPaveText(0.13,0.937,0.35,0.997,"NDC");
0267     text_lambdaI->SetFillColor(0);
0268     text_lambdaI->SetBorderSize(0);
0269     text_lambdaI->AddText("CMS Simulation");
0270     text_lambdaI->SetTextAlign(13);
0271     text_lambdaI->Draw();
0272 
0273     // Store
0274     can_lambdaI.Update();
0275     //  can_lambdaI.SaveAs( Form( "%s/EtaPhiMap_lambdaI.eps",  theDirName.Data() ) );
0276     //  can_lambdaI.SaveAs( Form( "%s/EtaPhiMap_lambdaI.gif",  theDirName.Data() ) );
0277     can_lambdaI.SaveAs( Form( "%s/EtaPhiMap_lambdaI.pdf",  theDirName.Data() ) );
0278     can_lambdaI.SaveAs( Form( "%s/EtaPhiMap_lambdaI.png",  theDirName.Data() ) );
0279     can_lambdaI.SaveAs( Form( "%s/EtaPhiMap_lambdaI.root",  theDirName.Data() ) );
0280     //  can_lambdaI.SaveAs( Form( "%s/EtaPhiMap_lambdaI.C",  theDirName.Data() ) );
0281     //
0282 }