ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/LJMet/MultivariateAnalysis/root/toyMC.C
(Generate patch)

Comparing UserCode/LJMet/MultivariateAnalysis/root/toyMC.C (file contents):
Revision 1.6 by kukartse, Tue May 19 19:07:10 2009 UTC vs.
Revision 1.7 by kukartse, Tue May 19 19:12:58 2009 UTC

# Line 29 | Line 29 | public:
29    void set_overflow_bins(TH1F * h);
30    void debug_hist(TH1F * h);
31    int fit_data(void);
32 +
33 +  // returns pair<mean,width>
34 +  std::pair<double,double> do_toys(double n_sig, double n_bkg1, double n_bkg2, int n_exp=100);
35    
36    TH1F * data;
37    TH1F * ttbar;
# Line 152 | Line 155 | void toyMC::load_templates(){
155  
156  
157   void toyMC::load_ejets_templates(){
158 +  TFile * data_file = new TFile("./TMVApp-data-electron-18may2009.root","READ");
159    //TFile * data_file = new TFile("./TMVApp-data-electron_noqcd.root","READ");
160    //TFile * data_file = new TFile("./TMVApp-data-electron_wzfastsim-08may2009.root","READ");
161 <  TFile * data_file = new TFile("./TMVApp-data-electron-08may2009.root","READ");
162 <  TFile * ttbar_phys_template_file = new TFile("./TMVA.root","READ");
163 <  TFile * qcd_template_file = new TFile("./TMVApp-qcd-electron-08may2009.root","READ");
161 >  //TFile * data_file = new TFile("./TMVApp-data-electron_wzfastsim-08may2009.root","READ");
162 >  TFile * ttbar_phys_template_file = new TFile("./TMVA_wjets.root","READ");
163 >  TFile * qcd_template_file = new TFile("TMVApp-qcd-electron-18may2009.root","READ");
164    
165     //TChain * t_data       = new TChain("classifier");
166     //t_data->Add("./TMVApp-data-electron_noqcd.root");
# Line 221 | Line 225 | int toyMC::do_fit(TH1F * _data){
225    fit = new TFractionFitter(_data, mc); // initialise
226  
227    fit->Constrain(1,0.0,1.0);               // constrain fraction 1 to be between 0 and 1
228 <  fit->Constrain(2,0.0,1.0);               // constrain fraction 1 to be between 0 and 1
229 <   //fit->Constrain(3,0.0,1.0);               // constrain fraction 1 to be between 0 and 1
228 >  fit->Constrain(2,0.0,1.0);
229 >  //fit->Constrain(3,0.0,1.0);
230  
231 <   //fit->Constrain(3,0.37259,0.37261);
232 <  
233 <   fit->Constrain(3,0.036759,0.036761); // mu+jets true
234 <   fit->Constrain(3,0.017379,0.017381); // mu+jets ABCD
235 <   //fit->Constrain(3,0.4422735,0.4422736);               // constrain fraction 1 to be between 0 and 1
231 >  //fit->Constrain(2,0.1651865,0.1651866);
232 >  //fit->Constrain(3,0.024999,0.025001);
233 >  fit->Constrain(3,0.176895306858,0.176895306860);
234 >  //fit->Constrain(3,0.37259,0.37261);
235 >  //fit->Constrain(3,0.036759,0.036761); // mu+jets true
236 >  //fit->Constrain(3,0.017379,0.017381); // mu+jets ABCD
237 >  //fit->Constrain(3,0.4422735,0.4422736);
238    //
239    //double qcd_frac = (double)n_gen_bkg2/(double)(n_gen_sig+n_gen_bkg1+n_gen_bkg2);
240    //fit->Constrain(3,qcd_frac-0.000001,qcd_frac+0.000001);               // constrain fraction 1 to be between 0 and 1
# Line 340 | Line 346 | int toyMC::fit_data(){
346    c->SaveAs("fit.eps");
347    return _res;
348   }
349 +
350 +
351 +
352 + std::pair<double,double> toyMC::do_toys(double n_sig, double n_bkg1, double n_bkg2, int n_exp=100){
353 +  double n_total = n_sig+n_bkg1+n_bkg2;
354 +
355 +  //load_templates();
356 +  //load_ejets_templates();
357 +  TH1F * toy_mean   = new TH1F("mean"  ,"ttbar signal yield"  ,50, n_sig-5.0*sqrt(n_sig), n_sig+5.0*sqrt(n_sig));
358 +  TH1F * toy_error   = new TH1F("error"  ,"ttbar signal yield error"  ,50, 0, 3.0*sqrt(n_sig));
359 +  TH1F * toy_pull   = new TH1F("pull"  ,"pull"  ,50, -3, 3);
360 +  toy_mean->SetFillColor(44);
361 +  toy_error->SetFillColor(44);
362 +  toy_pull->SetFillColor(44);
363 +  for (int i=0;i<n_exp;i++){
364 +    generate_toy(n_sig,n_bkg1,n_bkg2);
365 +    int _ttbar = n_gen_sig;
366 +    int status = do_fit(toy_data);
367 +    if (status==0){
368 +      Double_t value,error;
369 +      fit->GetResult(0,value,error);
370 +      toy_mean->Fill(value*n_total);
371 +      toy_error->Fill(error*n_total);
372 +      //toy_pull->Fill((value-n_sig/n_total)/error);
373 +      toy_pull->Fill((value-(Double_t)_ttbar/n_total)/error);
374 +    }
375 +  }
376 +  TCanvas * c = new TCanvas("canvas","canvas",800,600);
377 +  c->Divide(2,2);
378 +  TVirtualPad * pad = c->cd(1);
379 +  toy_mean->Fit("gaus");
380 +  pad->SaveAs("mean.eps");
381 +  pad = c->cd(2);
382 +  toy_error->Draw();
383 +  pad->SaveAs("error.eps");
384 +  pad = c->cd(3);
385 +  toy_pull->Fit("gaus");
386 +  pad->SaveAs("pull.eps");
387 +
388 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines