ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/LJMet/MultivariateAnalysis/root/make_rarfit_templates.C
Revision: 1.1
Committed: Wed Jan 21 18:36:09 2009 UTC (16 years, 3 months 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, V00-01-12, V00-01-11, V00-01-10, gak031009, gak030509, gak022309, gak021209, gak040209, gak012809, V00-01-09, V00-01-08, V00-01-07, V00-01-06, V00-01-05, V00-01-04, HEAD
Branch point for: ZMorph-V00-03-01, CMSSW_22X_branch
Log Message:
after JTerm status update

File Contents

# User Rev Content
1 kukartse 1.1 {
2     TFile * in_file = new TFile("TMVA-phys-13jan2009.root", "READ");
3     TFile * in_file2 = new TFile("TMVA-qcd-09jan2009.root", "READ");
4     TH1F * _sig = (TH1F *)in_file.Get("Method_Likelihood/Likelihood/MVA_Likelihood_S");
5     TH1F * _bg = (TH1F *)in_file.Get("Method_Likelihood/Likelihood/MVA_Likelihood_B");
6     TH1F * _qcd = (TH1F *)in_file2.Get("Method_Likelihood/Likelihood/MVA_Likelihood_B");
7    
8     // output file
9     TFile * out_file = new TFile("rarfit_templates-13jan2009.root", "RECREATE");
10     // create new TTree
11     TTree * sig_template = new TTree("signal_template","signal_template");
12     TTree * bg_template = new TTree("background_template","background_template");
13     TTree * qcd_template = new TTree("qcd_template","qcd_template");
14    
15     Double_t _ll = -1.0;
16     TBranch * b_ll = sig_template->Branch("MVA_Likelihood", &_ll, "MVA_Likelihood/D");
17     // loop over bins in the signal histogram
18     int n_bins = _sig->GetNbinsX();
19     double integral = _sig->Integral();
20     double n_entries = _sig->GetEntries();
21     double scale_factor = n_entries/integral; // histogram is scaled, so need to scale it back
22     for (int bin=1; bin != n_bins+1; bin++){
23     _ll = _sig->GetBinCenter(bin);
24     //loop over bin content
25     int bin_entries = (int)(_sig->GetBinContent(bin) * scale_factor + 0.5);
26     for (int _entry=0; _entry!=bin_entries; _entry++){
27     if (_ll < 0.0) cout << _ll << endl;
28     sig_template->Fill();
29     }
30     }
31    
32     _ll = -1.0;
33     b_ll = bg_template->Branch("MVA_Likelihood", &_ll, "MVA_Likelihood/D");
34     // loop over bins in the background histogram
35     n_bins = _bg->GetNbinsX();
36     integral = _bg->Integral();
37     n_entries = _bg->GetEntries();
38     scale_factor = n_entries/integral; // histogram is scaled, so need to scale it back
39     for (int bin=1; bin != n_bins+1; bin++){
40     _ll = _bg->GetBinCenter(bin);
41     //loop over bin content
42     int bin_entries = (int)(_bg->GetBinContent(bin) * scale_factor + 0.5);
43     for (int _entry=0; _entry!=bin_entries; _entry++){
44     if (_ll < 0.0) cout << _ll << endl;
45     bg_template->Fill();
46     }
47     }
48    
49     _ll = -1.0;
50     b_ll = qcd_template->Branch("MVA_Likelihood", &_ll, "MVA_Likelihood/D");
51     // loop over bins in the background histogram
52     n_bins = _qcd->GetNbinsX();
53     integral = _qcd->Integral();
54     n_entries = _qcd->GetEntries();
55     scale_factor = n_entries/integral; // histogram is scaled, so need to scale it back
56     for (int bin=1; bin != n_bins+1; bin++){
57     _ll = _qcd->GetBinCenter(bin);
58     //loop over bin content
59     int bin_entries = (int)(_qcd->GetBinContent(bin) * scale_factor + 0.5);
60     for (int _entry=0; _entry!=bin_entries; _entry++){
61     if (_ll < 0.0) cout << _ll << endl;
62     qcd_template->Fill();
63     }
64     }
65    
66     out_file->cd();
67    
68     out_file->Write();
69     delete out_file;
70     delete in_file;
71     }
72