Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:13:53

0001 #include<iostream>
0002 #include<TStyle.h>
0003 #include<TFile.h>
0004 #include<TDirectory.h>
0005 #include<TTree.h>
0006 #include<TCanvas.h>
0007 #include<TPaveText.h>
0008 #include<TH1F.h>
0009 #include<TLegend.h>
0010 #include <fstream>
0011 
0012 void Style(){
0013     
0014     TStyle *tdrStyle = new TStyle("tdrStyle","Style for P-TDR");
0015     
0016     // For the canvas:
0017     tdrStyle->SetCanvasBorderMode(0);
0018     tdrStyle->SetCanvasColor(kWhite);
0019     tdrStyle->SetCanvasDefH(600); //Height of canvas
0020     tdrStyle->SetCanvasDefW(1100); //Width of canvas
0021     tdrStyle->SetCanvasDefX(0);   //POsition on screen
0022     tdrStyle->SetCanvasDefY(0);
0023     
0024     // For the Pad:
0025     tdrStyle->SetPadBorderMode(0);
0026     tdrStyle->SetPadColor(kWhite);
0027     tdrStyle->SetPadGridX(false);
0028     tdrStyle->SetPadGridY(false);
0029     tdrStyle->SetGridColor(0);
0030     tdrStyle->SetGridStyle(3);
0031     tdrStyle->SetGridWidth(1);
0032     
0033     // For the frame:
0034     tdrStyle->SetFrameBorderMode(0);
0035     tdrStyle->SetFrameBorderSize(1);
0036     tdrStyle->SetFrameFillColor(0);
0037     tdrStyle->SetFrameFillStyle(0);
0038     tdrStyle->SetFrameLineColor(1);
0039     tdrStyle->SetFrameLineStyle(1);
0040     tdrStyle->SetFrameLineWidth(1);
0041     
0042     tdrStyle->SetHistLineWidth(1.5);
0043     //For the fit/function:
0044     tdrStyle->SetOptFit(1);
0045     tdrStyle->SetStatColor(kWhite);
0046     tdrStyle->SetStatFont(42);
0047     tdrStyle->SetStatFontSize(0.025);
0048     tdrStyle->SetOptStat(000000);
0049     tdrStyle->SetStatColor(kWhite);
0050     
0051     // Margins:
0052     tdrStyle->SetPadTopMargin(0.05);
0053     tdrStyle->SetPadBottomMargin(0.13);
0054     tdrStyle->SetPadLeftMargin(0.10);
0055     tdrStyle->SetPadRightMargin(0.02);
0056     
0057     // For the Global title:
0058     
0059     tdrStyle->SetOptTitle(0);
0060     tdrStyle->SetTitleFont(42);
0061     tdrStyle->SetTitleColor(1);
0062     tdrStyle->SetTitleTextColor(1);
0063     tdrStyle->SetTitleFillColor(10);
0064     tdrStyle->SetTitleFontSize(0.05);
0065     
0066     // For the axis titles:
0067     
0068     tdrStyle->SetTitleColor(1, "XYZ");
0069     tdrStyle->SetTitleFont(42, "XYZ");
0070     tdrStyle->SetTitleSize(0.04, "XYZ");
0071     tdrStyle->SetTitleXOffset(1.1);
0072     tdrStyle->SetTitleYOffset(1.1);
0073     
0074     // For the axis labels:
0075     
0076     tdrStyle->SetLabelColor(1, "XYZ");
0077     tdrStyle->SetLabelFont(42, "XYZ");
0078     tdrStyle->SetLabelOffset(0.007, "XYZ");
0079     tdrStyle->SetLabelSize(0.04, "XYZ");
0080     
0081     // For the axis:
0082     
0083     tdrStyle->SetAxisColor(1, "XYZ");
0084     tdrStyle->SetStripDecimals(kTRUE);
0085     tdrStyle->SetTickLength(0.03, "XYZ");
0086     tdrStyle->SetNdivisions(510, "XYZ");
0087     tdrStyle->SetPadTickX(1);  // To get tick marks on the opposite side of the frame
0088     tdrStyle->SetPadTickY(1);
0089     
0090     // Change for log plots:
0091     tdrStyle->SetOptLogx(0);
0092     tdrStyle->SetOptLogy(0);
0093     tdrStyle->SetOptLogz(0);
0094     
0095     // Postscript options:
0096     tdrStyle->SetPaperSize(20.,20.);
0097     
0098     tdrStyle->cd();
0099     
0100     gStyle->SetFillColor(-1);
0101 }
0102 
0103 
0104 void plotDJR(const TString& f1, const TString& f2 ) //,const TString & outfile)
0105 {
0106     Style();
0107 
0108     // TString location =  "/uscms_data/d2/yarba_j/PS-Matching-Veto/";
0109     TString location = "./";
0110     
0111     TString infile1 = location + f1;
0112     TString infile2 = location + f2;
0113     
0114     std::cout << "infile1=" << infile1 << std::endl;
0115     std::cout << "infile2=" << infile2 << std::endl;
0116     
0117     ifstream file1(infile1);
0118     ifstream file2(infile2);
0119     
0120     std::cout << "file1 is good: " << file1.good() << std::endl; 
0121     std::cout << "file2 is good: " << file2.good() << std::endl; 
0122 
0123     int nbin=60;
0124     float xmax=3.2;
0125     TPaveText *text[4];
0126 
0127     TH1F* DJR1[4][5];
0128     TH1F* Sum1[4];
0129     TH1F* DJR2[4][5];
0130     TH1F* Sum2[4];
0131 
0132     float Qpar1, Qpar2, Qpar3, Qpar4;
0133     int Npart;
0134 
0135     for(int k=0;k<4;k++)
0136     {
0137         text[k]=new TPaveText(0.4,0.90,0.7,0.95,"NDC");
0138         text[k]->AddText(Form("DJR(%d#rightarrow%d)",k+1,k));
0139         text[k]->SetTextSize(0.05);
0140         if(k>=2)text[k]->SetTextSize(0.04);
0141         text[k]->SetBorderSize(0);
0142         for(int m=0;m<5;m++)
0143         {
0144             DJR1[k][m]=new TH1F(Form("Py6: djr%d%d",k,m),";Q;Normalized scale;",nbin,0.01,xmax);
0145             DJR1[k][m]->SetLineColor(m+1);
0146             DJR1[k][m]->SetLineStyle(2);    
0147             DJR2[k][m]=new TH1F(Form("Py8: djr%d%d",k,m),";Q;Normalized scale;",nbin,0.01,xmax);
0148             DJR2[k][m]->SetMarkerColor(m+1);
0149             DJR2[k][m]->SetMarkerStyle(23); 
0150         }   
0151         Sum1[k]=new TH1F(Form("Py6: sum%d",k),";Log_{10}(Merging scale);Normalized scale;",nbin,0.01,xmax); 
0152         Sum1[k]->SetLineColor(38);
0153         Sum1[k]->SetLineWidth(2);
0154         Sum1[k]->GetYaxis()->SetTitleSize(0.05-k*0.005);
0155         Sum1[k]->GetYaxis()->SetLabelSize(0.05-k*0.005);
0156         Sum1[k]->GetYaxis()->SetTitleOffset(1+k*0.1);
0157         Sum1[k]->GetYaxis()->SetLabelOffset(0.01);
0158         Sum2[k]=new TH1F(Form("Py8: sum%d",k),";Log_{10}(Merging scale);Normalized scale;",nbin,0.01,xmax); 
0159         //Sum2[k]->SetMarkerColor(38);
0160         //Sum2[k]->SetMarkerStyle(23);
0161         Sum2[k]->SetLineWidth(3);
0162         // Sum2[k]->SetLineStyle(2);
0163         Sum2[k]->SetLineColor(kMagenta);
0164         Sum2[k]->GetYaxis()->SetTitleSize(0.05-k*0.005);
0165         Sum2[k]->GetYaxis()->SetLabelSize(0.05-k*0.005);
0166         Sum2[k]->GetYaxis()->SetTitleOffset(1+k*0.1);
0167         Sum2[k]->GetYaxis()->SetLabelOffset(0.01);
0168     }
0169 
0170     int npmax=0;
0171 
0172 // take in Pythia6 info
0173 
0174     float djr_val[4];
0175     float np;
0176     
0177     while(1)
0178     {
0179         for (int k=0;k<4;k++) 
0180         {
0181            djr_val[k]=-100000;
0182         }
0183         Qpar1=-10;
0184         Qpar2=-10;
0185         Qpar3=-10;
0186         Qpar4=-10;
0187 
0188         file1 >> np >> djr_val[0]>>djr_val[1]>>djr_val[2]>>djr_val[3];
0189 
0190         Npart=np;
0191 
0192         for(int k=0;k<4;k++)
0193         {
0194             if(djr_val[k]>0)
0195             {
0196                 DJR1[k][(int)np]->Fill(log10(djr_val[k]));
0197                 if(k==0)Qpar1=log10(djr_val[k]);
0198                 else if(k==1)Qpar2=log10(djr_val[k]);
0199                 else if(k==2)Qpar3=log10(djr_val[k]);
0200                 else if(k==3)Qpar4=log10(djr_val[k]);
0201             }
0202         }
0203         if(np>npmax)npmax=np;
0204 
0205         if(!file1.good()) break;
0206 
0207     }
0208 
0209     for(int k=0;k<4;k++)
0210     {
0211         for(int n=0;n<=npmax;n++)
0212         {
0213            Sum1[k]->Add(DJR1[k][n]);
0214         }
0215     }
0216 
0217 // now take Pythia8 info
0218 
0219     npmax = 0;
0220     
0221     while(1)
0222     {
0223         for (int k=0;k<4;k++) 
0224         {
0225            djr_val[k]=-100000;
0226         }
0227         Qpar1=-10;
0228         Qpar2=-10;
0229         Qpar3=-10;
0230         Qpar4=-10;
0231 
0232         file2 >> np >> djr_val[0]>>djr_val[1]>>djr_val[2]>>djr_val[3];
0233 
0234         Npart=np;
0235 
0236         for(int k=0;k<4;k++)
0237         {
0238             if(djr_val[k]>0)
0239             {
0240                 DJR2[k][(int)np]->Fill(log10(djr_val[k]));
0241                 if(k==0)Qpar1=log10(djr_val[k]);
0242                 else if(k==1)Qpar2=log10(djr_val[k]);
0243                 else if(k==2)Qpar3=log10(djr_val[k]);
0244                 else if(k==3)Qpar4=log10(djr_val[k]);
0245             }
0246         }
0247         if(np>npmax)npmax=np;
0248 
0249         if(!file2.good()) break;
0250 
0251     }
0252 
0253 
0254     for(int k=0;k<4;k++)
0255     {
0256        for(int n=0;n<=npmax;n++)
0257        {
0258           Sum2[k]->Add(DJR2[k][n]);
0259        }
0260     }
0261     
0262     TCanvas *c1= new TCanvas("c1", "c1", 1100, 900);
0263     c1->SetLeftMargin(0.0);
0264     c1->SetTopMargin(0.00);
0265     c1->SetRightMargin(0.00);
0266     c1->SetBottomMargin(0.0);
0267     
0268     TLegend* legend1=new TLegend(0.20,0.90-(npmax+1)*0.05,0.45,0.90);
0269     TLegend* legend2=new TLegend(0.65,0.90-(npmax+1)*0.05,0.90,0.90);
0270     legend1->SetTextSize(0.040);
0271     legend1->SetBorderSize(0);
0272     legend1->SetTextFont(62);
0273     legend1->SetLineColor(0);
0274     legend1->SetLineStyle(1);
0275     legend1->SetLineWidth(1);
0276     legend1->SetFillColor(0);
0277     legend1->SetFillStyle(1001);
0278     legend2->SetTextSize(0.040);
0279     legend2->SetBorderSize(0);
0280     legend2->SetTextFont(62);
0281     legend2->SetLineColor(0);
0282     legend2->SetLineStyle(1);
0283     legend2->SetLineWidth(1);
0284     legend2->SetFillColor(0);
0285     legend2->SetFillStyle(1001);
0286     
0287     for(int n=0;n<=npmax;n++)
0288     {
0289        legend1->AddEntry(DJR1[0][n],Form("%d partons, Py6",n));
0290        legend2->AddEntry(DJR2[0][n],Form("%d partons, Py8",n));
0291     }
0292     legend1->AddEntry(Sum1[0], "Sum, Py6");
0293     legend2->AddEntry(Sum2[0], "Sum, Py8");
0294     
0295     TPad *pad[4];
0296     pad[0]  =new TPad("pad0","pad",0,0.54,0.54,1.0);
0297     pad[1]  =new TPad("pad1","pad",0.54,0.54,1.0,1.0);
0298     pad[2]  =new TPad("pad2","pad",0,0,0.54,0.54);
0299     pad[3]  =new TPad("pad3","pad",0.54,0.0,1.0,0.54);
0300 
0301     for(int k=0;k<4;k++)
0302     {
0303         if(k==0 || k==2)
0304         {
0305            pad[k]->SetLeftMargin(0.15);
0306            pad[k]->SetRightMargin(0.0);
0307         }
0308         if(k==1 || k==3)
0309         {
0310            pad[k]->SetRightMargin(0.01);
0311            pad[k]->SetLeftMargin(0.0);
0312         }
0313         if(k==0 || k==1)
0314         {
0315            pad[k]->SetTopMargin(0.01);
0316            pad[k]->SetBottomMargin(0.0);
0317         }
0318         if(k==2 || k==3)
0319         {
0320            pad[k]->SetTopMargin(0.0);
0321            pad[k]->SetBottomMargin(0.15);
0322         }
0323         pad[k]->Draw();
0324     }
0325 
0326     float Ymax1, Ymax2;
0327     float scalingFactor1=1.0/Sum1[0]->Integral();
0328     float scalingFactor2=1.0/Sum2[0]->Integral();
0329 
0330     for(int k=0;k<4;k++){
0331         
0332         pad[k]->cd();
0333         for(int m=0;m<=xmax;m++)
0334         {
0335                    DJR1[k][m]->Scale(scalingFactor1);
0336                    DJR2[k][m]->Scale(scalingFactor2);
0337                 }
0338 
0339         Sum1[k]->Scale(scalingFactor1);
0340         Sum2[k]->Scale(scalingFactor2);
0341         Sum1[k]->Draw("hist");
0342         Sum2[k]->Draw("same");
0343 
0344         if (k==0) Ymax1=Sum1[k]->GetBinContent(Sum1[k]->GetMaximumBin())*2.5;
0345         Sum1[k]->SetMaximum(20.*Ymax1);
0346         Sum1[k]->SetMinimum(0.0007*Ymax1);
0347 
0348         for(int m=0;m<=xmax;m++)
0349         {
0350            DJR1[k][m]->Draw("histsame");
0351            DJR2[k][m]->SetMarkerSize(0.7);
0352            DJR2[k][m]->Draw("psame");
0353         }
0354         text[k]->Draw();
0355         if(k==0) 
0356         {
0357            legend1->Draw();
0358            legend2->Draw();
0359         }
0360         gPad->SetLogy(1);   
0361         
0362     }
0363     
0364     c1->Print("DJR.gif"); 
0365 
0366 }
0367