ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/LJMet/MultivariateAnalysis/test/fitter.C
Revision: 1.3
Committed: Fri May 1 06:58:27 2009 UTC (16 years ago) by kukartse
Content type: text/plain
Branch: MAIN
CVS Tags: V00-03-01, ZMorph_BASE_20100408, gak040610_morphing, V00-02-02, gak011410, gak010310, ejterm2010_25nov2009, V00-02-01, V00-02-00, gak112409, CMSSW_22X_branch_base, segala101609, V00-01-15, V00-01-14, V00-01-13, HEAD
Branch point for: ZMorph-V00-03-01, CMSSW_22X_branch
Changes since 1.2: +24 -14 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 kukartse 1.1 {
2 kukartse 1.3 TFile * data_file = new TFile("./TMVApp-data-27apr2009.root","READ");
3     TFile * ttbar_phys_template_file = new TFile("./TMVA.root","READ");
4     TFile * qcd_template_file = new TFile("./TMVApp-qcd-27apr2009.root","READ");
5 kukartse 1.1
6 kukartse 1.2 TTree * t_data = data_file->Get("classifier");
7     TTree * t_ttbar_phys = ttbar_phys_template_file->Get("TestTree");
8     TTree * t_qcd = qcd_template_file->Get("classifier");
9    
10 kukartse 1.3 TH1F * data = new TH1F("data" ,"data" ,50, -0.9, 0.9);
11     TH1F * ttbar = new TH1F("ttbar" ,"ttbar" ,50, -0.9, 0.9);
12     TH1F * wzjets = new TH1F("wzjets","wzjets",50, -0.9, 0.9);
13     TH1F * qcd = new TH1F("qcd" ,"qcd" ,50, -0.9, 0.9);
14    
15     int n_data = t_data->GetEntries();
16 kukartse 1.2
17     t_data . Draw("MVA_BDT>>data");
18     t_ttbar_phys . Draw("MVA_BDT>>ttbar","type==1");
19     t_ttbar_phys . Draw("MVA_BDT>>wzjets","type==0");
20     t_qcd . Draw("MVA_BDT>>qcd");
21    
22     //TH1F * data = (TH1F *)data_file->Get("MVA_Likelihood");
23 kukartse 1.1 //TH1F * ttbar = (TH1F *)template_file->Get("Method_Likelihood/Likelihood/MVA_Likelihood_S");
24     //TH1F * wzjets = (TH1F *)template_file->Get("Method_Likelihood/Likelihood/MVA_Likelihood_B");
25 kukartse 1.2 //TH1F * ttbar = (TH1F *)ttbar_template_file->Get("MVA_Likelihood");
26     //TH1F * wzjets = (TH1F *)wzjets_template_file->Get("MVA_Likelihood");
27     //TH1F * qcd = (TH1F *)qcd_template_file->Get("MVA_Likelihood");
28 kukartse 1.1
29     //data->Draw();
30     //ttbar->Draw();
31     //wzjets->Draw();
32     //qcd->Draw();
33    
34     TObjArray *mc = new TObjArray(3); // MC histograms are put in this array
35     mc->Add(ttbar);
36     mc->Add(wzjets);
37     mc->Add(qcd);
38     TFractionFitter* fit = new TFractionFitter(data, mc); // initialise
39     fit->Constrain(1,0.0,1.0); // constrain fraction 1 to be between 0 and 1
40     fit->Constrain(2,0.0,1.0); // constrain fraction 1 to be between 0 and 1
41 kukartse 1.3 //fit->Constrain(3,0.03,1.0); // constrain fraction 1 to be between 0 and 1
42     fit->Constrain(3,0.0,0.073); // constrain fraction 1 to be between 0 and 1
43 kukartse 1.2 fit->SetRangeX(0,50); // use only the first 15 bins in the fit
44 kukartse 1.1 Int_t status = fit->Fit(); // perform the fit
45     cout << "fit status: " << status << endl;
46     if (status == 0) { // check on fit status
47     TH1F* result = (TH1F*) fit->GetPlot();
48     data->Draw("Ep");
49     result->Draw("same");
50 kukartse 1.3 //
51     Double_t value,error;
52     fit->GetResult(0,value,error);
53     ttbar->Scale(n_data*value/ttbar->Integral());
54     ttbar->Draw("same");
55     //
56     fit->GetResult(1,value,error);
57     wzjets->Scale(n_data*value/wzjets->Integral());
58     wzjets->Draw("same");
59     //
60     fit->GetResult(2,value,error);
61     qcd->Scale(n_data*value/qcd->Integral());
62     qcd->Draw("same");
63 kukartse 1.1 }
64     }