ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/LJMet/MultivariateAnalysis/root/plot_diff.C
Revision: 1.3
Committed: Mon Feb 9 22:31:47 2009 UTC (16 years, 2 months ago) by jindal
Content type: text/plain
Branch: MAIN
Changes since 1.2: +1 -1 lines
Log Message:
adding more variables

File Contents

# User Rev Content
1 jindal 1.1 { gROOT->SetStyle("Plain");
2 jindal 1.2 gStyle->SetOptStat(00000);
3 jindal 1.1 gStyle->SetPalette(1);
4 jindal 1.2 const int nvar =14 ;
5 jindal 1.1 int color;
6 jindal 1.2 TString var[nvar]={"Mt","ht","M123inv","centrality","sphericity","htPlusLepton","getHt3","ht2p","ktMinPrime","DphiJMET","aplanarity", "dPhiLMet","W_MT","metHtPlusLepton"};
7     TString lepton_ID = "eidRobustTight";
8     TString tmp = "eidRobustTight.root";
9 jindal 1.1 TFile * f1 = new TFile(tmp);
10 jindal 1.2
11     TH1F *hnomsig[nvar];
12     TH1F *hrevsig[nvar];
13 jindal 1.1 TH1F *hdiff[nvar];
14 jindal 1.2 Double_t normnomsig, normrevsig;
15     Double_t N1[1500][20],N2[1500][20];
16 jindal 1.1 for(int j=0;j<nvar;j++){
17    
18 jindal 1.2 hnomsig[j] = (TH1F*)f1->Get("h"+var[j]+"_nominal");
19     hrevsig[j] = (TH1F*)f1->Get("h"+var[j]+"_reversed");
20     tmp = var[j]+"_diff";
21     hdiff[j] = (TH1F*) hnomsig[j]->Clone(tmp);
22     hdiff[j]->Reset();
23    
24     int nbinssig = hnomsig[j]->GetNbinsX()+1 ;
25     std::cout<< "var " << var[j] << "nbins " << nbinssig << std::endl;
26    
27    
28     for(int i = 1; i < nbinssig; i++){
29     // std::cout<< var[j] << std::endl;
30     N1[i][j] = hnomsig[j]->GetBinContent(i);
31     N2[i][j] = hrevsig[j]->GetBinContent(i);
32     }
33     normnomsig = hnomsig[j]->Integral();
34     if(normnomsig > 0)
35     normnomsig = normnomsig;
36     else
37     normnomsig = 1;
38 jindal 1.1
39    
40 jindal 1.2 normrevsig = hrevsig[j]->Integral();
41     if(normrevsig > 0)
42     normrevsig = normrevsig;
43     else
44     normrevsig = 1;
45    
46     hnomsig[j]->Scale(1./normnomsig);
47     hrevsig[j]->Scale(1./normrevsig);
48 jindal 1.1 }
49     /////////////////////// DRAWING /////////////////////////////
50    
51    
52    
53 jindal 1.2 hnomsig[0]->GetYaxis()->SetTitle("Normalized");
54     TCanvas *c1[nvar];
55     TCanvas *c2[nvar];
56     Double_t SigNom, SigRev, Diff, Err;
57     Double_t maxnom,maxrev,range;
58     Int_t maxsig_bin,maxrev_bin;
59 jindal 1.1 for(j=0;j<nvar;j++){
60     leg = new TLegend(0.4,0.6,0.65,0.88);
61     c1[j] = new TCanvas(var[j],var[j],900,600);
62     tmp = var[j]+"_diff";
63     c2[j] = new TCanvas(tmp,tmp,900,600);
64     c1[j]->cd();
65 jindal 1.2 hnomsig[j]->GetXaxis()->SetTitle(var[j]);
66     hnomsig[j]->SetTitle(var[j]);
67     hnomsig[j]->SetLineColor(1);
68     hrevsig[j]->SetLineColor(2);
69     maxsig_bin = hnomsig[j]->GetMaximumBin();
70     maxnom = hnomsig[j]->GetBinContent(maxsig_bin);
71     maxrev_bin = hrevsig[j]->GetMaximumBin();
72     maxrev = hrevsig[j]->GetBinContent(maxrev_bin);
73     if(maxnom>maxrev)
74     range = maxnom+.1*maxnom;
75     else
76     range = maxrev+.1*maxrev;
77     hnomsig[j]->SetAxisRange(0,range,"Y");
78     hnomsig[j]->Draw("HIST");
79     hrevsig[j]->Draw("HIST same");
80     tmp = lepton_ID;
81     leg->AddEntry(hnomsig[j],tmp,"L");
82     tmp = lepton_ID+" Reversed";
83     leg->AddEntry(hrevsig[j],tmp,"L");
84 jindal 1.1 leg->SetFillColor(0);
85     leg->SetLineColor(0);
86     leg->Draw();
87 jindal 1.2 tmp= var[j]+"_"+lepton_ID+".png";
88 jindal 1.1 c1[j]->Print(tmp);
89 jindal 1.2 int nbins = hnomsig[j]->GetNbinsX();
90 jindal 1.1 for(int i = 1; i < nbins+1; i++){
91 jindal 1.2 SigNom = hnomsig[j]->GetBinContent(i);
92     SigRev = hrevsig[j]->GetBinContent(i);
93     Diff = SigNom - SigRev;
94 jindal 1.1 if( N1[i][j] >0 && N2[i][j] > 0)
95 jindal 1.2 Err =(1./ sqrt(N1[i][j]))*SigNom + (1./ sqrt(N2[i][j]))*SigRev;
96 jindal 1.1 else
97     Err = 0;
98     hdiff[j]->SetBinContent(i,Diff);
99     hdiff[j]->SetBinError(i,Err);}
100    
101     c2[j]->cd();
102     hdiff[j]->SetTitle(var[j]+" difference");
103     hdiff[j]->SetXTitle(var[j]);
104     hdiff[j]->SetYTitle("difference");
105     hdiff[j]->Draw();
106 jindal 1.3 tmp= var[j]+"_"+lepton_ID+"_diff.png";
107 jindal 1.1
108     c2[j]->Print(tmp);
109    
110    
111    
112    
113    
114    
115    
116    
117     }
118     }
119    
120