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 & infile,const TString & outfile){
0105     Style();
0106     ifstream file(infile);
0107     int nbin=60;
0108     float xmax=3.2;
0109     TPaveText *text[4];
0110     TH1F *DJR[4][5],*sum[4];
0111     TFile *f = new TFile(outfile,"RECREATE");
0112         TTree *events = new TTree("QPar","Qpar");
0113     float Qpar1, Qpar2, Qpar3, Qpar4;
0114     int Npart;
0115         events->Branch("Qpar1",&Qpar1,"Qpar1/F");
0116     events->Branch("Qpar2",&Qpar2,"Qpar2/F");
0117     events->Branch("Qpar3",&Qpar3,"Qpar3/F");
0118     events->Branch("Qpar4",&Qpar4,"Qpar4/F");
0119     events->Branch("Npart",&Npart,"Npart/I");
0120     for(int k=0;k<4;k++){
0121         text[k]=new TPaveText(0.4,0.90,0.7,0.95,"NDC");
0122         text[k]->AddText(Form("DJR(%d#rightarrow%d)",k+1,k));
0123         text[k]->SetTextSize(0.05);
0124         if(k>=2)text[k]->SetTextSize(0.04);
0125         text[k]->SetBorderSize(0);
0126         for(int m=0;m<5;m++){
0127             DJR[k][m]=new TH1F(Form("djr%d%d",k,m),";Q;Normalized scale;",nbin,0.01,xmax);
0128             DJR[k][m]->SetLineColor(m+1);
0129             DJR[k][m]->SetLineStyle(2); 
0130         }   
0131         sum[k]=new TH1F(Form("sum%d",k),";Log_{10}(Merging scale);Normalized scale;",nbin,0.01,xmax);   
0132         sum[k]->SetLineColor(38);
0133         sum[k]->GetYaxis()->SetTitleSize(0.05-k*0.005);
0134         sum[k]->GetYaxis()->SetLabelSize(0.05-k*0.005);
0135         sum[k]->GetYaxis()->SetTitleOffset(1+k*0.1);
0136         sum[k]->GetYaxis()->SetLabelOffset(0.01);
0137     }
0138     int npmax=0;
0139     while(1)
0140     {
0141         float djr_val[4];
0142         for(int k=0;k<4;k++){djr_val[k]=-100000;}
0143         Qpar1=-10;
0144         Qpar2=-10;
0145         Qpar3=-10;
0146         Qpar4=-10;
0147         float np;
0148         file >> np >> djr_val[0]>>djr_val[1]>>djr_val[2]>>djr_val[3];
0149         Npart=np;
0150         for(int k=0;k<4;k++){
0151             if(djr_val[k]>0){
0152                 DJR[k][(int)np]->Fill(log10(djr_val[k]));
0153                 if(k==0)Qpar1=log10(djr_val[k]);
0154                 else if(k==1)Qpar2=log10(djr_val[k]);
0155                 else if(k==2)Qpar3=log10(djr_val[k]);
0156                 else if(k==3)Qpar4=log10(djr_val[k]);
0157             }
0158         }
0159         events->Fill();
0160         if(np>npmax)npmax=np;
0161         if(!file.good()) break;
0162     }
0163     for(int k=0;k<4;k++){
0164         for(int n=0;n<=npmax;n++){
0165             sum[k]->Add(DJR[k][n]);
0166         }
0167     }
0168     events->Write();
0169     
0170     TCanvas *c1= new TCanvas("c1", "c1", 800, 600);
0171     c1->SetLeftMargin(0.0);
0172     c1->SetTopMargin(0.00);
0173     c1->SetRightMargin(0.00);
0174     c1->SetBottomMargin(0.0);
0175     
0176     TLegend *legend=new TLegend(0.75,0.95-npmax*0.06,0.95,0.95);
0177     legend->SetTextSize(0.050);
0178     legend->SetBorderSize(0);
0179     legend->SetTextFont(62);
0180     legend->SetLineColor(0);
0181     legend->SetLineStyle(1);
0182     legend->SetLineWidth(1);
0183     legend->SetFillColor(0);
0184     legend->SetFillStyle(1001);
0185     
0186     for(int n=0;n<=npmax;n++){
0187         legend->AddEntry(DJR[0][n],Form("%d partons",n));
0188     }
0189     
0190     TPad *pad[4];
0191     pad[0]  =new TPad("pad0","pad",0,0.54,0.54,1.0);
0192     pad[1]  =new TPad("pad1","pad",0.54,0.54,1.0,1.0);
0193     pad[2]  =new TPad("pad2","pad",0,0,0.54,0.54);
0194     pad[3]  =new TPad("pad3","pad",0.54,0.0,1.0,0.54);
0195     for(int k=0;k<4;k++){
0196         if(k==0 || k==2){
0197                 pad[k]->SetLeftMargin(0.15);
0198                 pad[k]->SetRightMargin(0.0);
0199         }
0200         if(k==1 || k==3){
0201             pad[k]->SetRightMargin(0.01);
0202             pad[k]->SetLeftMargin(0.0);
0203         }
0204         if(k==0 || k==1){
0205             pad[k]->SetTopMargin(0.01);
0206             pad[k]->SetBottomMargin(0.0);
0207         }
0208         if(k==2 || k==3){
0209             pad[k]->SetTopMargin(0.0);
0210             pad[k]->SetBottomMargin(0.15);
0211 
0212         }
0213         pad[k]->Draw();
0214     }
0215     float Ymax;
0216     float scalingFactor=1.0/sum[0]->Integral();
0217     for(int k=0;k<4;k++){
0218         
0219         pad[k]->cd();
0220          for(int m=0;m<=xmax;m++){
0221                         DJR[k][m]->Scale(scalingFactor);
0222                 }
0223 
0224         sum[k]->Scale(scalingFactor);
0225         sum[k]->SetLineWidth(2);
0226         sum[k]->Draw("hist");
0227         if(k==0)Ymax=sum[k]->GetBinContent(sum[k]->GetMaximumBin())*2.5;
0228         sum[k]->SetMaximum(Ymax);
0229         sum[k]->SetMinimum(0.0007*Ymax);
0230         for(int m=0;m<=xmax;m++){
0231             DJR[k][m]->Draw("histsame");
0232         }
0233         text[k]->Draw();
0234         if(k==0)legend->Draw();
0235         gPad->SetLogy(1);   
0236         
0237     }
0238     
0239     c1->Print("DJR.pdf"); 
0240 
0241 }
0242