-- ChengguangZhu - 25 Nov 2007 %TOATTENTION%

Introcudtion

Before a new MC loop, there are always unsatisfied MC aspects comparing to data, which sometimes introduces bias to measurement results. Corrections to these bias could bring believable results.

A ppt file describe a test

What the obvious difference is

Use atlfast as MC and full simulation as data as in ZhuMontCarloWithAtlfast, the differences:
  • electron for atlfast
    • not isolated, so worse purity
    • the reconstruction efficiency is uniformed along eta and pt
    • reconstruction efficiency much higer
    • without left tail in resolution (no radiations ?)
    • eta and phi not smeared
  • muon for atlfast
    • uniform reconstruction efficiency, not see cracks and ATLAS foots
    • reconstruction efficiency lower
    • 2 peaks on pt resolution plot?
    • eta and phi not smeared
  • jets for atlfast
    • slightly higher b tag efficiency and worse c/l jet rejection TODO change the weight cut
    • low light jet multiplicity
  • event reconstruction
    • much better on w, t mass reconstruction
    • high pass on quality cut due to reason above

MC with atlfast

  • From Atlfast MC, cospsi distribution in parton level and reconstruction level is drawn, efficiency function is plot to divide the 2 histgram and fit, as plot below.
  • F0 is 0.70 as input. Fit the reconstructed cospsi distribution with SM function* efficiency function should get 0.70, in fact 0.699922 and error: 0.0288418

Without afterwards correction

Without any corrections on the difference above, use atlfast data to get the efficiency function and used on fullsim data to recover the parton level distribution of cospsi. Finaly, fit the data (all data - mc background) with (SM w polarization function * efficiency function)
The same fit above on the data (full sim), I get F0: 0.723249 and error: 0.0352761

Consider the difference

  • the largest one: reconstruction efficiency along pt and eta for electron and muon
    • assume the reconstruction efficiency for data is taken from Control Sample, in fact now from full sim truth info
    • use the data reconstruction efficiency to divide the MC reconstruction efficiency, in a (pt,eta) window
    • use the above value as a weight for lepton of that (pt,eta)
    • apply this weight when plot cospsi histgram with MC for specific lepton(pt,eta)
    • the distribution with weight divide the distribution w/o weight to get the weight for cospsi correction
    • above procedure is done to the MC background which will be taken as background of data
    • cospsi distribution of data minus the MC weighted background
    • fit the above, with (SM w polarization function * efficiency function * weight for cospsi)
      wpola*(1.026363+(-0.325285)*x+(-0.093121)*x*x+(0.538057)*x*x*x)*(0.931554+(0.015724*x)+(-0.003028*x*x)) 
  • the results
    • after correction on reconstruction efficiency, we have F0: 0.7035 and error: 0.0341253
    • plus correction on electron resolution, we have F0: 0.667852 and error: 0.0326324

System error of this method

  • In this method, the uncertainty of weight function is a source of system error.
  • Change a sigma of the fitted weight function to see the measurement results
  • totally (+,0,-)sigma for 2 parameters, 3*3-1=8 different results
    0.744229  0.659012  0.690483  0.731951  0.645266  0.713547  0.753776  0.66956
  • Take the largest deviation as system error 0.05

Plots of above procedure

  • plots for different stages:
    recoeffi_corr.jpg
  • corrections on discrepency on e pt resolution:
    corre_e_resolution.jpg

  • correction function in less bins, still small chi2:
    correction_function_atlfastMC.jpg

  • Assigned to Due date Description State Closed Notify  
    ChengguangZhu 2007-12-07 corrections made on to one of jet multiplicity, e purity, too good w mass     edit

    Logfile

    • only e events
    root [0] .L method2_cospsi.cxx
    root [1] CheckObjects(0)
    in Initialized() .....
    in EfficiencyFunctionFromMC() .....
    Truth psi distribution, F0: 0.703292 and error: 0.00472439
    
    in PerfectMCTest() .....
    with   perfect MC, F0: 0.687856 and error: 0.0413459
    in UnPerfectMC() .....
    with unperfect MC, F0: 0.843797 and error: 0.0673169
    
    
    all corrections: (((nselelec+nselmuon==1 && nselmuon==1)*m_reco_effi_diff_num(ptmuon_true,etamuon_true))+((nselelec+nselmuon==1 && nselelec==1)*e_reco_effi_diff_num(ptele_true,etaele_true)))
    Final fit function:
    wpola*(1.008860+(-0.307160)*x+(-0.096998)*x*x+(0.351918)*x*x*x)*(0.721941+(-0.003548*x)+(-0.003160*x*x))
      NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
       1  p0           6.53828e-01   5.01147e-02  -5.90016e-05  -5.99261e-03
       2  p1           3.11416e-01   2.94997e-02  -1.89552e-06  -7.87461e-03
       3  p2           1.92705e+02   5.09837e+00  -1.27713e-02   2.88872e-05
    with corrected MC, F0: 0.653828 and error: 0.0501147
    change the weighting histgram with gaus(1signa) and get, F0: 0.660071 and error: 0.0497266
    0.01 taken as the system error
    
    
    
    in ChooseCorrections() .....
    all corrections: ((nselelec+nselmuon==1 && nselelec==1)*ElectronResolutionEffectDist(ptele_true))+(nselelec+nselmuon==1 && nselmuon==1)
    wpola*(1.008860+(-0.307160)*x+(-0.096998)*x*x+(0.351918)*x*x*x)*(0.997261+(0.003020*x)+(0.005733*x*x))
      NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
       1  p0           6.88002e-01   5.41594e-02  -5.84322e-04  -1.26714e-02
       2  p1           2.92998e-01   3.22358e-02   5.52728e-04  -2.96864e-02
       3  p2           1.15317e+02   3.30821e+00  -8.96634e-04   8.37112e-06
    change the weighting histgram with gaus(1signa) and get, F0: 0.685411 and error: 0.0546315
    0.003 taken as the system error
    
    in CorrectionsTransformToCospsi() .....
    (((nselelec+nselmuon==1 && nselmuon==1)*m_reco_effi_diff_num(ptmuon,etamuon))+((nselelec+nselmuon==1 && nselelec==1)*e_reco_effi_diff_num(ptele,etaele)))*(((nselelec+nselmuon==1 && nselelec==1)*ElectronResolutionEffectDist(ptele_true))+(nselelec+nselmuon==1 && nselmuon==1)).
    Final fit function:
    wpola*(1.008860+(-0.307160)*x+(-0.096998)*x*x+(0.351918)*x*x*x)*(0.719705+(-0.000770*x)+(-0.007114*x*x))
      NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
       1  p0           6.48738e-01   4.97759e-02   6.79392e-05   1.05794e-02
       2  p1           3.15770e-01   2.95140e-02   4.15821e-05   2.16752e-04
       3  p2           1.94070e+02   5.08428e+00   1.26492e-02   1.28164e-04
    
    

    • data of (eventnumber odd) to compare with atlfast and act as final measurement data, atlfast/2. only electron events
    in PerfectMCTest() .....
    with   perfect MC, F0: 0.687883 and error: 0.0593561
    
    in UnPerfectMC() .....
    with unperfect MC, F0: 0.963872 and error: 0.0958852
    
    in ReconstructionEffiencyDiffernece() .....
    
    
    in ElectronPtResolutionDifference() .....
    
    in ChooseCorrections() .....
    all corrections: (((nselelec+nselmuon==1 && nselmuon==1))+((nselelec+nselmuon==1
     && nselelec==1)*e_reco_effi_diff_num(ptele_true,etaele_true)))
    
    in CorrectionsTransformToCospsi() .....
    fit the correction to cospsi
    
    in PickupSignalFromData() .....
    Final fit function:
    wpola*(1.008939+(-0.307048)*x+(-0.096921)*x*x+(0.351830)*x*x*x)*(0.714308+(0.006
    453*x)+(0.002096*x*x))
     FCN=29.8953 FROM MIGRAD    STATUS=CONVERGED     472 CALLS         473 TOTAL
                         EDM=3.26558e-14    STRATEGY= 1  ERROR MATRIX UNCERTAINTY   
    3.0 per cent
      EXT PARAMETER                                   STEP         FIRST   
      NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
       1  p0           7.14375e-01   7.05779e-02  -5.80326e-05   5.87628e-06
       2  p1           2.64112e-01   4.17502e-02   5.10726e-05   8.05374e-06
       3  p2           9.77161e+01   3.60029e+00  -1.01535e-03   8.93163e-08
    with corrected MC, F0: 0.714375 and error: 0.0705779
    Info in <TCanvas::Print>: ps file 20071212_93508.ps has been created
    
    
    • check the the correction function is used only to background but not to the final fit
    root [0] .L method2_cospsi.cxx
    root [1] CheckObjects(2)      
    
    in Initialized() .....
    
    in EfficiencyFunctionFromMC() .....
    Truth psi distribution, F0: 0.703292 and error: 0.00472439
    
    in SigBkgdFromMC() .....
    
    in PerfectMCTest() .....
    with   perfect MC, F0: 0.687883 and error: 0.0593561
    
    in UnPerfectMC() .....
    with unperfect MC, F0: 0.963872 and error: 0.0958852
    
    in ReconstructionEffiencyDiffernece() .....
    
    
    in ElectronPtResolutionDifference() .....
    
    in ChooseCorrections() .....
    all corrections: (((nselelec+nselmuon==1 && nselmuon==1))+((nselelec+nselmuon==1 && nselelec==1)*e_reco_effi_diff_num(ptele_true,etaele_true)))
    
    in CorrectionsTransformToCospsi() .....
    fit the correction to cospsi
    
    in PickupSignalFromData() .....
     FCN=29.9719 FROM MIGRAD    STATUS=CONVERGED      71 CALLS          72 TOTAL
                         EDM=3.60706e-09    STRATEGY= 1  ERROR MATRIX UNCERTAINTY   2.2 per cent
      EXT PARAMETER                                   STEP         FIRST   
      NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
       1  p0           7.14492e-01   7.07598e-02  -1.36342e-04   2.99680e-03
       2  p1           2.61641e-01   4.17056e-02  -1.93982e-05   4.09386e-03
       3  p2           6.97836e+01   2.57280e+00   1.29330e-03   2.55219e-05
    with corrected MC, F0: 0.714492 and error: 0.0707598
    Info in <TCanvas::Print>: ps file 20071212_95056.ps has been created
    
    
    • this time change the measurement data to data (eventnumber odd)
    root [0] .L method2_cospsi.cxx
    root [1] CheckObjects(1)      
    
    in Initialized() .....
    
    in EfficiencyFunctionFromMC() .....
    Truth psi distribution, F0: 0.703292 and error: 0.00472439
    
    in SigBkgdFromMC() .....
    
    in PerfectMCTest() .....
    with   perfect MC, F0: 0.687883 and error: 0.0593561
    
    in ReconstructionEffiencyDiffernece() .....
    
    
    in ElectronPtResolutionDifference() .....
    
    in ChooseCorrections() .....
    all corrections: (((nselelec+nselmuon==1 && nselmuon==1))+((nselelec+nselmuon==1 && nselelec==1)*e_reco_effi_diff_num(ptele_true,etaele_true)))
    
    in CorrectionsTransformToCospsi() .....
    fit the correction to cospsi
    
    in UnPerfectMC() .....
    with unperfect MC, F0: 0.76894 and error: 0.10056
    
    in PickupSignalFromData() .....
    Final fit function:
    wpola*(1.008939+(-0.307048)*x+(-0.096921)*x*x+(0.351830)*x*x*x)*(0.714308+(0.006453*x)+(0.002096*x*x))
     FCN=18.4754 FROM MIGRAD    STATUS=CONVERGED     441 CALLS         442 TOTAL
                         EDM=1.60643e-13    STRATEGY= 1  ERROR MATRIX UNCERTAINTY   2.1 per cent
      EXT PARAMETER                                   STEP         FIRST   
      NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
       1  p0           5.92153e-01   7.02022e-02  -9.77396e-06   2.65546e-06
       2  p1           3.69016e-01   4.21341e-02  -6.84815e-07   1.00334e-05
       3  p2           9.57221e+01   3.58124e+00   1.74876e-04   1.89282e-07
    with corrected MC, F0: 0.592153 and error: 0.0702022
    Info in <TCanvas::Print>: ps file 20071212_101437.ps has been created
    
    
    the code to produce up 2 logs :
    gROOT->Reset();

    //MC char *adbk1_m="/atlas/czhu/analysisResults/singlet_jcali_atlfast/ANA.ntuple.root"; char *adbk2_m="/atlas/czhu/analysisResults/wjets_jcali_atlfast/ANA.ntuple.root"; char *ad3_m="/atlas/czhu/analysisResults/forplots_3_jcali_Moore_MCALO_atlfast_btagemulation_jetprecalibration/ANA.ntuple.root";

    //Data char *adbk1_d="/atlas/czhu/analysisResults/singlet_forplots_3_jcali_Moore_MCALO_btag60_HLT_AODlevelbugfix/ANA.ntuple.root"; char *adbk2_d="/atlas/czhu/analysisResults/wjets_forplots_3_jcali_Moore_MCALO_btag60_HLT_AODlevelbugfix/ANA.ntuple.root"; char *ad3_d="/atlas/czhu/analysisResults/forplots_3_jcali_Moore_MCALO_btag60_HLT_AODlevelbugfix/ANA.ntuple.root";

    // real data char *frldt="/data/czhu/analysisResults/Streamtest/ANA.ntuple.root"; char *frldth="/data/czhu/analysisResults/Streamtest/ANA.hist.root";

    //-------------------------------------------------------------------------------------- //Cuts

    //------ FirstData TCut semiemu = "nl_true==1 && abs(istau_true)==0"; TCut semitau = "nl_true==1 && abs(istau_true)!=0"; TCut semilep = "nl_true==1"; TCut semie = "nl_true==1 && abs(istau_true)==0 && abs(kl_true)==11"; TCut semimu = "nl_true==1 && abs(istau_true)==0 && abs(kl_true)==13"; TCut dilep = "nl_true==2"; TCut hadronivc = "nl_true==0";

    TCut weight_3 = "weight";

    using namespace std;

    double g_test=0; int g_trig_bins =50; double g_trig_lpt = 0; double g_trig_hpt =100; double g_etrig_hist[300]; double g_mtrig_hist[300];

    int bins = 25 ; double lox = -1 ; double hix = 1 ; double fit_lo = -0.9 ; double fit_hi = 0.8 ;

    TTree* ntuple_tt_bk1_m; TTree* ntuple_tt_bk2_m; TTree* ntuple_tt_3_m; TTree* ntuple_tt_bk1_d; TTree* ntuple_tt_bk2_d; TTree* ntuple_tt_3_d;

    TTree* ntuple_tt_rldt; TF1* wpola; TF1* F_trig; TF1* F_pola_effi; TF1* F_pola_effi_perfect; TF1* F_pola_effi_corr;

    char m_e_pt_reso_diff_cut[1000]; char mc_efficiency[1000]; char ept_trig_effi[1000]; char mpt_trig_effi[1000]; char allcorrections[1000]; char lcospsi_trig_effi[1000]; char lcospsi_trig_effibk[1000]; char ps_filename[100]; char func_pola_effi_corr[1000]; char func_pola_effi_perfect[1000];

    // variable bins for 2D histgram //for electron const int eptbins = 9; const int eetabins = 19; const Float_t exbin[eptbins+1]={0,20.,25,30,35,40,50,70,120.,300}; const Float_t eybin[eetabins+1]={-10,-2.14,-1.78,-1.4,-1.2,-1,-0.8,-0.7,-0.5,-0.1,0.1,0.5,0.7,0.8,1,1.2,1.4,1.78,2.14,10}; //for muon const int mptbins = 9; const int metabins = 7; const Float_t mxbin[mptbins+1]={0,20.,25,30,35,40,50,70,120.,300}; const Float_t mybin[metabins+1]={-10,-1.35,-1.15,-0.1,0.1,1.15,1.35,10};

    TMatrixD g_m_reco_effi_diff_hist(mptbins,metabins); TMatrixD g_e_reco_effi_diff_hist(eptbins,eetabins); char e_reco_effi_diff_cut[300]; char m_reco_effi_diff_cut[300];

    // TH1F* e_reso_effect ; //TH1F* MC_bk1_w_pola_reco=new TH1F( "MC_bk1_w_pola_reco","MC_bk1_w_pola_reco",bins, lox, hix);; //TH1F* MC_bk2_w_pola_reco=new TH1F( "MC_bk2_w_pola_reco","MC_bk2_w_pola_reco",bins, lox, hix);; //TH1F* MC_bk3_w_pola_reco=new TH1F( "MC_bk3_w_pola_reco","MC_bk3_w_pola_reco",bins, lox, hix);; //TH1F* MC_bk4_w_pola_reco=new TH1F( "MC_bk4_w_pola_reco","MC_bk4_w_pola_reco",bins, lox, hix);;

    double lpar0; double lpar1; double lpar2; double lerr0; double lerr1; double lerr2;

    double epar0; double epar1; double epar2; double eerr0; double eerr1; double eerr2;

    double mpar0; double mpar1; double mpar2; double merr0; double merr1; double merr2;

    double bkpar0; double bkpar1; double bkpar2; double bkerr0; double bkerr1; double bkerr2;

    TH2F* tmpupref; //trigger TCut EFe1_trg="EFItem[4]==4"; TCut EFm1_trg="EFItem[13]==13"; TCut EF_trg=EFe1_trg||EFm1_trg; TCut goodemu_events="nselelec+nselmuon==1"; TCut sele_events="nselelec==1"; TCut selmu_events="nselmuon==1"; //reconstruction cuts //TCut goodlnb = "goodlnb>0"; TCut goodlnb = "fabs(eta_blep-eta_blep_true)<0.1 && fabs(phi_blep-phi_blep_true)<0.1 "; TCut qualitycut="(abs(pwhad[4]-80410)<20000. && pt_n/pt_miss>0.99 && abs(ptlep[4]-175000.)<35000. && abs(pthad[4]-175000.)<35000.)";

    //data cuts TCut MC_ori ="1";//"(eventnumber%30)==0 "; TCut data_ori ="1";//"(eventnumber%30)==0 "; //TCut MC_ori = "eventnumber>270000"; TCut data_ori = "eventnumber>270000"; TCut nom ="(runnumber==5200)/730 + (runnumber==8240)/103 +(runnumber==8241)/89 +(runnumber==8242)/112 +(runnumber==8243)/224 +(runnumber==8244)/92 +(runnumber==8245)/143 +(runnumber==8246)/82 +(runnumber==8247)/224 +(runnumber==8248)/197 +(runnumber==8249)/149 +(runnumber==8250)/109 +(runnumber==5500)/990 +(runnumber==5502)/185";

    TCut MC = MC_ori*nom*"730/2"; TCut data = data_ori*nom*"730"*"(eventnumber%2)==0"; TCut rldt = data_ori;

    int padnum=0;

    void Plots(){

    CheckObjects( 0);

    CheckObjects( 2); CheckObjects( 3); CheckObjects( 4); CheckObjects( 5); CheckObjects( 6); CheckObjects( 7); CheckObjects( 8); CheckObjects( 9);

    }

    void CheckObjects(int plotSelection=0){

    /// create a canvas gStyle->SetCanvasColor(0); c1 = new TCanvas( "c1", "result check", 200, 0, 800, 630); c1->Draw(); c1->Divide(4,4); gStyle->SetOptFit(0111); gStyle->SetOptStat(001000010);

    Initialized();

    switch (plotSelection) {

    case -1: ReconstructionEffiencyDiffernece(); break;

    case 0:

    EfficiencyFunctionFromMC();

    SigBkgdFromMC();

    PerfectMCTest();

    UnPerfectMC();

    ReconstructionEffiencyDiffernece();

    ElectronPtResolutionDifference();

    ChooseCorrections(1); CorrectionsTransformToCospsi(); PickupSignalFromData1(); FitSignalWithAlternateFunction(0,0,0);

    // FitSignalWithAlternateFunction( 0, 0, 1); // FitSignalWithAlternateFunction( 0, 0,-1); // FitSignalWithAlternateFunction( 0, 1, 0); // FitSignalWithAlternateFunction( 0, 1, 1); // FitSignalWithAlternateFunction( 0, 1,-1); // FitSignalWithAlternateFunction( 0,-1, 0); // FitSignalWithAlternateFunction( 0,-1, 1); // FitSignalWithAlternateFunction( 0,-1,-1);

    break; case 1:

    EfficiencyFunctionFromMC();

    SigBkgdFromMC();

    PerfectMCTest(); UnPerfectMC();

    break;

    case 2: FitSignalWithAlternateFunction( 0, 0, 1); break; case 3: FitSignalWithAlternateFunction( 0, 0,-1); break; case 4: FitSignalWithAlternateFunction( 0, 1, 0); break; case 5: FitSignalWithAlternateFunction( 0, 1, 1); break; case 6: FitSignalWithAlternateFunction( 0, 1,-1); break; case 7: FitSignalWithAlternateFunction( 0,-1, 0); break; case 8: FitSignalWithAlternateFunction( 0,-1, 1); break; case 9: FitSignalWithAlternateFunction( 0,-1,-1); break;

    case 10:

    CospsiResolutionEffectsToFinalFit();

    break;

    }

    Finalize();

    c1->Print(ps_filename); }

    void CutTest(int plotSelection=0){

    /// create a canvas gStyle->SetCanvasColor(0); c1 = new TCanvas( "main", "result check", 200, 0, 800, 630); c1->Draw(); c1->Divide(2,1);

    Initialized();

    switch (plotSelection) {

    case 0: CD(); DrawoneDenNtuple( ntuple_tt_3, "(pt_miss-pt_n_true)/pt_n_true", "etmiss resolution", weight_3*qualitycut*goodlnb*"pt_miss!=0 && pt_n_true!=0", 200, -1, 1, 1, 1., 0, 1,"" );

    CD(); DrawoneDenNtuple( ntuple_tt_3, "(pt_miss-ptmiss_true)/ptmiss_true", "etmiss resolution", weight_3*qualitycut*goodlnb*"pt_miss!=0 && ptmiss_true!=0", 200, -1, 1, 1, 1., 0, 1,"" );

    CD(); DrawoneDenNtuple( ntuple_tt_3, "(pt_n_true-ptmiss_true)/ptmiss_true", "etmiss resolution", weight_3*qualitycut*goodlnb*"pt_n_true!=0 && ptmiss_true!=0", 200, -1, 1, 1, 1., 0, 1,"" ); CD(); DrawoneDenNtuple( ntuple_tt_3, "phi_n_true-phimiss_true", "et phi resolution", weight_3*qualitycut*goodlnb*"pt_n_true!=0 && ptmiss_true!=0", 200, -1, 1, 1, 1., 0, 1,"" ); break;

    case 2: CD(); //plot_Efficiency2D(ntuple_tt_3_d, weight_3*data*semie*"selelec_true==1 && e_true_found_rec>0 ", weight_3*semie*"selelec_true==1", "e_reco_effi_pteta", "ptele_true", 20, 20,200,0.001, "etaele_true",21,-2.5,2.5,1);

    CD();

    break;

    }

    Finalize();

    //c1->Print(ps_filename); }

    void Initialized(){ cout<<endl<<"in Initialized() ....." <<endl;

    // open MC files TFile* full_bk1_m = new TFile(adbk1_m); TTree* ntuple_e_bk1_m = (TTree*) full_bk1_m->Get("Electron/t100" ); TTree* ntuple_mu_bk1_m = (TTree*) full_bk1_m->Get("Muon/t300" ); TTree* ntuple_jet_bk1_m = (TTree*) full_bk1_m->Get("JetTag/t700" ); ntuple_tt_bk1_m = (TTree*) full_bk1_m->Get("ttbar/t400" ); ntuple_tt_bk1_m->AddFriend(ntuple_e_bk1_m); ntuple_tt_bk1_m->AddFriend(ntuple_mu_bk1_m); ntuple_tt_bk1_m->AddFriend(ntuple_jet_bk1_m);

    TFile* full_bk2_m = new TFile(adbk2_m); TTree* ntuple_e_bk2_m = (TTree*) full_bk2_m->Get("Electron/t100" ); TTree* ntuple_mu_bk2_m = (TTree*) full_bk2_m->Get("Muon/t300" ); TTree* ntuple_jet_bk2_m = (TTree*) full_bk2_m->Get("JetTag/t700" ); ntuple_tt_bk2_m = (TTree*) full_bk2_m->Get("ttbar/t400" ); ntuple_tt_bk2_m->AddFriend(ntuple_e_bk2_m); ntuple_tt_bk2_m->AddFriend(ntuple_mu_bk2_m); ntuple_tt_bk2_m->AddFriend(ntuple_jet_bk2_m);

    TFile* full_3_m = new TFile(ad3_m); TTree* ntuple_e_3_m = (TTree*) full_3_m->Get("Electron/t100" ); TTree* ntuple_mu_3_m = (TTree*) full_3_m->Get("Muon/t300" ); TTree* ntuple_jet_3_m = (TTree*) full_3_m->Get("JetTag/t700" ); ntuple_tt_3_m = (TTree*) full_3_m->Get("ttbar/t400" ); ntuple_tt_3_m->AddFriend(ntuple_jet_3_m); ntuple_tt_3_m->AddFriend(ntuple_e_3_m); ntuple_tt_3_m->AddFriend(ntuple_mu_3_m);

    // open data files TFile* full_bk1_d = new TFile(adbk1_d); TTree* ntuple_e_bk1_d = (TTree*) full_bk1_d->Get("Electron/t100" ); TTree* ntuple_mu_bk1_d = (TTree*) full_bk1_d->Get("Muon/t300" ); TTree* ntuple_jet_bk1_d = (TTree*) full_bk1_d->Get("JetTag/t700" ); ntuple_tt_bk1_d = (TTree*) full_bk1_d->Get("ttbar/t400" ); ntuple_tt_bk1_d->AddFriend(ntuple_e_bk1_d); ntuple_tt_bk1_d->AddFriend(ntuple_mu_bk1_d); ntuple_tt_bk1_d->AddFriend(ntuple_jet_bk1_d);

    TFile* full_bk2_d = new TFile(adbk2_d); TTree* ntuple_e_bk2_d = (TTree*) full_bk2_d->Get("Electron/t100" ); TTree* ntuple_mu_bk2_d = (TTree*) full_bk2_d->Get("Muon/t300" ); TTree* ntuple_jet_bk2_d = (TTree*) full_bk2_d->Get("JetTag/t700" ); ntuple_tt_bk2_d = (TTree*) full_bk2_d->Get("ttbar/t400" ); ntuple_tt_bk2_d->AddFriend(ntuple_e_bk2_d); ntuple_tt_bk2_d->AddFriend(ntuple_mu_bk2_d); ntuple_tt_bk2_d->AddFriend(ntuple_jet_bk2_d);

    TFile* full_3_d = new TFile(ad3_d); TTree* ntuple_e_3_d = (TTree*) full_3_d->Get("Electron/t100" ); TTree* ntuple_mu_3_d = (TTree*) full_3_d->Get("Muon/t300" ); TTree* ntuple_jet_3_d = (TTree*) full_3_d->Get("JetTag/t700" ); ntuple_tt_3_d = (TTree*) full_3_d->Get("ttbar/t400" ); ntuple_tt_3_d->AddFriend(ntuple_jet_3_d); ntuple_tt_3_d->AddFriend(ntuple_e_3_d); ntuple_tt_3_d->AddFriend(ntuple_mu_3_d);

    //cout<<"open the real data..."<<<<endl; TFile* realdata = new TFile(frldt); TTree* ntuple_e_rldt = (TTree*) realdata->Get("Electron/t100" ); TTree* ntuple_mu_rldt = (TTree*) realdata->Get("Muon/t300" ); TTree* ntuple_jet_rldt = (TTree*) realdata->Get("JetTag/t700" ); ntuple_tt_rldt = (TTree*) realdata->Get("ttbar/t400" ); ntuple_tt_rldt->AddFriend(ntuple_jet_rldt); ntuple_tt_rldt->AddFriend(ntuple_e_rldt); ntuple_tt_rldt->AddFriend(ntuple_mu_rldt);

    //Fitting functions Wpola function wpola = new TF1("wpola","1.5*[2]*([0]*((1-x*x)/2.)+[1]*((1-x)*(1-x)/4.)+(1-[0]-[1])*((1+x)*(1+x)/4.))",-1.,1.); wpola ->SetParName(0,"F0"); wpola ->SetParName(1,"FL"); wpola ->SetParName(2,"Const"); wpola ->SetParameter(0,0.703); wpola ->SetParameter(1,0.297); wpola ->SetRange(-0.9,0.8);

    TDatime dt; sprintf( ps_filename, "%i_%i.ps", dt.GetDate(),dt.GetTime() );

    InitializeCharVector(m_e_pt_reso_diff_cut); InitializeCharVector(mc_efficiency); InitializeCharVector(ept_trig_effi); InitializeCharVector(mpt_trig_effi); InitializeCharVector(allcorrections); InitializeCharVector(lcospsi_trig_effi); InitializeCharVector(lcospsi_trig_effibk); InitializeCharVector(func_pola_effi_corr); InitializeCharVector(func_pola_effi_perfect);

    // initilize pad to be c1 padnum=0; }

    void EfficiencyFunctionFromMC(){ ///////////////////////////////////////////// // use MC dara: get the efficiency function for w polarization distribution. cout<<endl<<"in EfficiencyFunctionFromMC() ....." <<endl;

    // 1. get and draw the normalized reco and truth distribution of cospsi GetHistFromNtuple(ntuple_tt_3_m, "cospsi_ang", "MC_w_pola_reco", weight_3*MC *semiemu*qualitycut*goodlnb, bins, lox, hix, 1); GetHistFromNtuple(ntuple_tt_3_m, "cospsi_ang_true", "MC_w_pola_true", weight_3*MC_ori*semiemu*"cospsi_ang_true!=0", bins, lox, hix, 1); MC_w_pola_true->Sumw2(); MC_w_pola_reco->Sumw2(); CD(); TH1F* MC_w_pola_reco_nom =MC_w_pola_reco->DrawNormalized("E"); CD(); TH1F* MC_w_pola_true_nom =MC_w_pola_true->DrawNormalized("E");

    //2. fit the truth cospsi to get the truth F0 (from truth objects other than input parameter) MC_w_pola_true_nom->Fit("wpola","Q","", fit_lo, fit_hi); TF1* truthfit=MC_w_pola_true_nom->GetFunction("wpola"); cout<<"Truth psi distribution, F0: "<<truthfit->GetParameter(0)<<" and error: "<<truthfit->GetParError(0)<<endl;

    //3. divide reco by truth of cospsi distribution to get efficiency distribution v.s. cospsi TH1F* MC_efficiency= MC_w_pola_reco_nom->Clone(); MC_efficiency->Divide( MC_w_pola_true_nom );

    //4. fit the efficiency distribution to get the efficiency function CD(); MC_efficiency->Fit("pol3","RQ","E",fit_lo,fit_hi); TF1* EffiFit = MC_efficiency ->GetFunction("pol3"); sprintf(mc_efficiency,"%f+(%f)*x+(%f)*x*x+(%f)*x*x*x", EffiFit->GetParameter(0), EffiFit->GetParameter(1), EffiFit->GetParameter(2), EffiFit->GetParameter(3));

    MC_efficiency->DrawCopy("E");

    //delete MC_w_pola_true_nom; //delete MC_w_pola_reco_nom; delete MC_w_pola_true; delete MC_efficiency; }

    void SigBkgdFromMC(){ //////////////////////////////////// // use MC dara: simulate the background: tau-background, wjet-background, singtop-background and combinetorial background. cout<<endl<<"in SigBkgdFromMC() ....." <<endl;

    //1. simulate all kinds of background GetHistFromNtuple(ntuple_tt_bk1_m, "cospsi_ang", "MC_bk1_w_pola_reco", weight_3*MC*qualitycut, bins, lox, hix, 1); GetHistFromNtuple(ntuple_tt_bk2_m, "cospsi_ang", "MC_bk2_w_pola_reco", weight_3*MC*qualitycut, bins, lox, hix, 1); GetHistFromNtuple(ntuple_tt_3_m, "cospsi_ang", "MC_bk3_w_pola_reco", weight_3*MC*qualitycut*(semiemu), bins, lox, hix, 1); GetHistFromNtuple(ntuple_tt_3_m, "cospsi_ang", "MC_bk4_w_pola_reco", weight_3*MC*qualitycut*semiemu*(goodlnb),bins, lox, hix, 1);

    //2. check the structures of the signal and background with MC TH1F* MC_sig_bkgd = MC_w_pola_reco->Clone(); MC_sig_bkgd->Add(MC_bk1_w_pola_reco,1); MC_sig_bkgd->Add(MC_bk2_w_pola_reco,1); MC_sig_bkgd->Add(MC_bk3_w_pola_reco,1); MC_sig_bkgd->Add(MC_bk4_w_pola_reco,1);

    CD(); MC_sig_bkgd->DrawCopy("HIST");MC_sig_bkgd->SetFillStyle(3015); MC_sig_bkgd->Add(MC_w_pola_reco, -1); MC_sig_bkgd->SetFillColor(2);MC_sig_bkgd->SetLineColor(2); MC_sig_bkgd->DrawCopy("SAME HIST"); MC_sig_bkgd->Add(MC_bk4_w_pola_reco,-1); MC_sig_bkgd->SetFillColor(4);MC_sig_bkgd->SetLineColor(4); MC_sig_bkgd->DrawCopy("SAME HIST"); MC_sig_bkgd->Add(MC_bk3_w_pola_reco,-1); MC_sig_bkgd->SetFillColor(6);MC_sig_bkgd->SetLineColor(6); MC_sig_bkgd->DrawCopy("SAME HIST"); MC_sig_bkgd->Add(MC_bk1_w_pola_reco,-1); MC_sig_bkgd->SetFillColor(8);MC_sig_bkgd->SetLineColor(8); MC_sig_bkgd->DrawCopy("SAME HIST");

    delete MC_sig_bkgd; }

    void PerfectMCTest(){ ///////////////////////////////////// //test perfect MC: means MC can describe data perfectly except statistical error, in principle, data and MC are 2 samples. cout<<endl<<"in PerfectMCTest() ....." <<endl;

    //1. compose the perfect data from different components GetHistFromNtuple(ntuple_tt_3_m, "cospsi_ang", "w_pola_reco_perfect", weight_3*MC*qualitycut, bins, lox, hix, 1); GetHistFromNtuple(ntuple_tt_bk1_m, "cospsi_ang", "bk1_w_pola_reco_perfect", weight_3*MC*qualitycut, bins, lox, hix, 1); GetHistFromNtuple(ntuple_tt_bk2_m, "cospsi_ang", "bk2_w_pola_reco_perfect", weight_3*MC*qualitycut, bins, lox, hix, 1);

    TH1F* RL_data_perfect= new TH1F( "RL_data_perfect","RL_data_perfect",bins, lox, hix); RL_data_perfect->Add(w_pola_reco_perfect, 1); RL_data_perfect->Add(bk1_w_pola_reco_perfect, 1); RL_data_perfect->Add(bk2_w_pola_reco_perfect, 1);

    //2. compare the real data the MC on one plot CD();RL_data_perfect->SetLineColor(30); RL_data_perfect->DrawCopy("SAME E");

    //3. form RL_data minus all background simulated with MC RL_data_perfect->Add(MC_bk1_w_pola_reco,-1); RL_data_perfect->Add(MC_bk2_w_pola_reco,-1); RL_data_perfect->Add(MC_bk3_w_pola_reco,-1); RL_data_perfect->Add(MC_bk4_w_pola_reco,-1);

    //4. fit the pure signal with "wpola*efficnecyfun" CD(); sprintf(func_pola_effi_perfect,"wpola*(%s)", mc_efficiency); F_pola_effi_perfect=new TF1("F_pola_effi_perfect",func_pola_effi_perfect); RL_data_perfect->Fit("F_pola_effi_perfect","Q","E",fit_lo, fit_hi); TF1* perfectdatafit=RL_data_perfect->GetFunction("F_pola_effi_perfect"); cout<<"with perfect MC, F0: "<<perfectdatafit->GetParameter(0)<<" and error: "<<perfectdatafit->GetParError(0)<<endl; RL_data_perfect->DrawCopy("E");

    delete w_pola_reco_perfect; delete bk1_w_pola_reco_perfect; delete bk2_w_pola_reco_perfect; delete RL_data_perfect;

    }

    void RealDataDirectMeasurement(){ ///////////////////////////////////// //test perfect MC: means MC can describe data perfectly except statistical error, in principle, data and MC are 2 samples. cout<<endl<<"in RealDataDirectMeasurement() ....." <<endl;

    //1. compose the perfect data from different components GetHistFromNtuple(ntuple_tt_rldt, "cospsi_ang", "w_pola_reco_perfect", rldt*"(abs(pwhad[4]-80410)<20000. && pt_n/pt_miss>0.99 && abs(ptlep[4]-175000.)<35000. && abs(pthad[4]-175000.)<35000.)", bins, lox, hix, 1);

    TH1F* RL_data_perfect= new TH1F( "RL_data_perfect","RL_data_perfect",bins, lox, hix); RL_data_perfect->Add(w_pola_reco_perfect, 1);

    //2. compare the real data the MC on one plot CD();RL_data_perfect->SetLineColor(30); RL_data_perfect->DrawCopy("SAME E"); CD();RL_data_perfect->DrawCopy("E");

    //3. form RL_data minus all background simulated with MC RL_data_perfect->Add(MC_bk1_w_pola_reco,-1); RL_data_perfect->Add(MC_bk2_w_pola_reco,-1); RL_data_perfect->Add(MC_bk3_w_pola_reco,-1); RL_data_perfect->Add(MC_bk4_w_pola_reco,-1);

    //4. fit the pure signal with "wpola*efficnecyfun" CD(); sprintf(func_pola_effi_perfect,"wpola*(%s)", mc_efficiency); F_pola_effi_perfect=new TF1("F_pola_effi_perfect",func_pola_effi_perfect); RL_data_perfect->Fit("F_pola_effi_perfect","Q","E",fit_lo, fit_hi); TF1* perfectdatafit=RL_data_perfect->GetFunction("F_pola_effi_perfect"); cout<<"with perfect MC, F0: "<<perfectdatafit->GetParameter(0)<<" and error: "<<perfectdatafit->GetParError(0)<<endl; RL_data_perfect->DrawCopy("E");

    delete w_pola_reco_perfect; //delete bk1_w_pola_reco_perfect; //delete bk2_w_pola_reco_perfect; delete RL_data_perfect;

    }

    void UnPerfectMC(){ ////////////////////////////////// // unpefect MC : MC can't describe data perfectly: // in this procedure, MC still with 100% trigger efficiency, so can't describe data which has unperfect real trigger efficiency. //data-mc_bkgd: fit with function (wpola*efficiency*trigger_correction) cout<<endl<<"in UnPerfectMC() ....." <<endl;

    //1. compose data from different sources which has unperfect trigger efficiency(real trigger efficnecy) TCut trig_corr="";//EF_trg; GetHistFromNtuple(ntuple_tt_3_d, "cospsi_ang", "w_pola_reco", weight_3*data*qualitycut*trig_corr, bins, lox, hix, 1); GetHistFromNtuple(ntuple_tt_bk1_d, "cospsi_ang", "bk1_w_pola_reco", weight_3*data*qualitycut*trig_corr, bins, lox, hix, 1); GetHistFromNtuple(ntuple_tt_bk2_d, "cospsi_ang", "bk2_w_pola_reco", weight_3*data*qualitycut*trig_corr, bins, lox, hix, 1); TH1F* RL_data = w_pola_reco->Clone(); RL_data->Add(bk1_w_pola_reco,1); RL_data->Add(bk2_w_pola_reco,1);

    //real data - MC background which has perfect trigger efficiency RL_data->Add(MC_bk1_w_pola_reco,-1); RL_data->Add(MC_bk2_w_pola_reco,-1); RL_data->Add(MC_bk3_w_pola_reco,-1); RL_data->Add(MC_bk4_w_pola_reco,-1);

    CD(); RL_data->Fit("F_pola_effi_perfect","Q","E",fit_lo, fit_hi); TF1* datafit=RL_data->GetFunction("F_pola_effi_perfect"); cout<<"with unperfect MC, F0: "<<datafit->GetParameter(0)<<" and error: "<<datafit->GetParError(0)<<endl;

    RL_data->DrawCopy("E"); delete RL_data; delete w_pola_reco; delete bk1_w_pola_reco; delete bk2_w_pola_reco; delete MC_bk1_w_pola_reco; delete MC_bk2_w_pola_reco; delete MC_bk3_w_pola_reco; delete MC_bk4_w_pola_reco; delete MC_w_pola_reco; }

    void ReconstructionEffiencyDiffernece(){ cout<<endl<<"in ReconstructionEffiencyDiffernece() ....." <<endl;

    // for electron CD(); plot_Efficiency2D(ntuple_tt_3_d, "m_reco_effi_pteta_d", weight_3*data*semimu*"selmuon_true==1 && mu_true_found_rec>0 ", weight_3*semimu*"selmuon_true==1", "ptmuon_true", mptbins, mxbin, 0.001, "etamuon_true",metabins, mybin,1); plot_Efficiency2D(ntuple_tt_3_m, "m_reco_effi_pteta_m", weight_3*MC *semimu*"selmuon_true==1 && mu_true_found_rec>0 ", weight_3*semimu*"selmuon_true==1", "ptmuon_true", mptbins, mxbin, 0.001, "etamuon_true",metabins, mybin,1);

    TH1F* m_reco_effi_pteta_diff=m_reco_effi_pteta_d->Clone(); m_reco_effi_pteta_diff->Divide(m_reco_effi_pteta_m); m_reco_effi_pteta_diff->DrawCopy("lego");

    // for muon CD();

    plot_Efficiency2D(ntuple_tt_3_d, "e_reco_effi_pteta_d", weight_3*data*semie*"selelec_true==1 && e_true_found_rec>0 ", weight_3*semie*"selelec_true==1", "ptele_true", eptbins, exbin, 0.001, "etaele_true",eetabins, eybin,1); plot_Efficiency2D(ntuple_tt_3_m, "e_reco_effi_pteta_m", weight_3*MC *semie*"selelec_true==1 && e_true_found_rec>0 ", weight_3*semie*"selelec_true==1", "ptele_true", eptbins, exbin, 0.001, "etaele_true",eetabins, eybin,1);

    TH1F* e_reco_effi_pteta_diff=e_reco_effi_pteta_d->Clone(); e_reco_effi_pteta_diff->Divide(e_reco_effi_pteta_m); e_reco_effi_pteta_diff->DrawCopy("lego");

    for(int i=1;i<eptbins+1;i++){ for(int j=1;j<eetabins+1;j++){ g_e_reco_effi_diff_hist(i-1,j-1) = e_reco_effi_pteta_diff->GetBinContent(i,j)+gRandom->Gaus(0,e_reco_effi_pteta_diff->GetBinError(i,j)); } }

    sprintf(e_reco_effi_diff_cut,"(nselelec+nselmuon==1 && nselelec==1)*e_reco_effi_diff_num(ptele_true,etaele_true)");

    for(int i=1;i<mptbins+1;i++){ for(int j=1;j<metabins+1;j++){ g_m_reco_effi_diff_hist(i-1,j-1) = m_reco_effi_pteta_diff->GetBinContent(i,j)+gRandom->Gaus(0,m_reco_effi_pteta_diff->GetBinError(i,j)); } } cout<<endl; sprintf(m_reco_effi_diff_cut,"(nselelec+nselmuon==1 && nselmuon==1)");//*m_reco_effi_diff_num(ptmuon_true,etamuon_true)");

    delete m_reco_effi_pteta_d; delete m_reco_effi_pteta_m; delete e_reco_effi_pteta_d; delete e_reco_effi_pteta_m;

    delete e_reco_effi_pteta_diff; delete m_reco_effi_pteta_diff; } double e_reco_effi_diff_num(double pt, double eta){

    pt=pt/1000; if(pt>=exbin[eptbins]) pt=exbin[eptbins]-0.1; int i = 0; while( pt>=exbin[i]) { i++;} int j = 0; while( eta>=eybin[j]) { j++;} return g_e_reco_effi_diff_hist(i-1,j-1); }

    double m_reco_effi_diff_num(double pt, double eta){ pt=pt/1000; if(pt>=mxbin[eptbins]) pt=mxbin[mptbins]-0.1; int i = 0; while( pt>=mxbin[i]) { i++;} int j = 0; while( eta>=mybin[j]) { j++;} return g_m_reco_effi_diff_hist(i-1,j-1); }

    void ElectronPtResolutionDifference(){ cout<<endl<<"in ElectronPtResolutionDifference() ....." <<endl;

    CD(); GetHistFromNtuple( ntuple_tt_3_m, "ptele/ptele_true-1","e_pt_reso_m_hist", weight_3*semiemu*"nselelec==1 && selelec_true==1 && ptele_true<50000", 60,-0.12, 0.1,1); GetHistFromNtuple( ntuple_tt_3_d, "ptele/ptele_true-1","e_pt_reso_d_hist", weight_3*semiemu*"nselelec==1 && selelec_true==1 && ptele_true<50000", 60,-0.12, 0.1,1); ScaleHist(e_pt_reso_m_hist); e_pt_reso_m_hist->SetLineColor(kRed); e_pt_reso_m_hist->Draw(); ScaleHist(e_pt_reso_d_hist); e_pt_reso_d_hist->SetLineColor(kBlue); e_pt_reso_d_hist->Draw("SAME");

    CD(); GetHistFromNtuple( ntuple_tt_3_m, "ptele_true", "e_pt_true_m_hist", weight_3*semiemu*"ptele_true>0"*"ElectronResolulationDistMC(ptele_true)>20000", 50, 15, 25, 0.001); e_pt_true_m_hist->SetLineColor(kRed); e_pt_true_m_hist->DrawCopy(); GetHistFromNtuple( ntuple_tt_3_m, "ptele_true", "e_pt_true_d_hist", weight_3*semiemu*"ptele_true>0"*"ElectronResolulationDistData(ptele_true)>20000", 50, 15, 25, 0.001); e_pt_true_d_hist->SetLineColor(kBlue); e_pt_true_d_hist->DrawCopy("SAME");

    CD(); e_reso_effect=(TH1F*)e_pt_true_d_hist->Clone(); e_reso_effect->Sumw2(); e_reso_effect->Divide(e_pt_true_m_hist); e_reso_effect->DrawCopy(); sprintf(m_e_pt_reso_diff_cut,"((nselelec+nselmuon==1 && nselelec==1)*ElectronResolutionEffectDist(ptele_true))+(nselelec+nselmuon==1 && nselmuon==1)");

    }

    double ElectronResolulationDistMC(double pt){ return pt*(1+e_pt_reso_m_hist->GetRandom()); } double ElectronResolulationDistData(double pt){ return pt*(1+e_pt_reso_d_hist->GetRandom()); }

    double ElectronResolutionEffectDist(double pt){ if(pt>24000) return 1; int i=(int)(pt/1000-15)/0.2+1; return e_reso_effect->GetBinContent(i); }

    void ChooseCorrections(int correctionindex){ cout<<endl<<"in ChooseCorrections() ....." <<endl; InitializeCharVector(allcorrections); switch (correctionindex){ case 1: sprintf(allcorrections,"((%s)+(%s))",m_reco_effi_diff_cut,e_reco_effi_diff_cut ); break;

    case 2: sprintf(allcorrections,"%s",m_e_pt_reso_diff_cut ); break; case 3: sprintf(allcorrections,"((%s)+(%s))*(%s)",m_reco_effi_diff_cut,e_reco_effi_diff_cut,m_e_pt_reso_diff_cut ); break; } cout<<"all corrections: "<<allcorrections<<endl; return; }

    void TEST(){

    CD(); GetHistFromNtuple( ntuple_tt_3_m, "ptele/ptele_true-1","e_pt_reso_m_hist", weight_3*semiemu*allcorrections*"nselelec==1 && selelec_true==1 && ptele_true<50000", 60,-0.12, 0.1,1); GetHistFromNtuple( ntuple_tt_3_d, "ptele/ptele_true-1","e_pt_reso_d_hist", weight_3*semiemu*allcorrections*"nselelec==1 && selelec_true==1 && ptele_true<50000", 60,-0.12, 0.1,1); ScaleHist(e_pt_reso_m_hist); e_pt_reso_m_hist->SetLineColor(kRed); e_pt_reso_m_hist->DrawCopy(); ScaleHist(e_pt_reso_d_hist); e_pt_reso_d_hist->SetLineColor(kBlue); e_pt_reso_d_hist->DrawCopy("SAME");

    delete e_pt_reso_m_hist; delete e_pt_reso_d_hist; }

    void CorrectionsTransformToCospsi(){ cout<<endl<<"in CorrectionsTransformToCospsi() ....." <<endl; CD(); plot_Efficiency( ntuple_tt_3_m,"cospsi_l_effi","cospsi_ang", weight_3*MC*qualitycut*semiemu*(goodlnb)*allcorrections, weight_3*MC*qualitycut*semiemu*(goodlnb), 10, -1, 1, 1,2,0.5,1.5,29,"");

    cout<<"fit the correction to cospsi"<<endl; cospsi_l_effi->Fit("pol2","Q","E",fit_lo,fit_hi); TF1* Fit_cospsi_trig = cospsi_l_effi ->GetFunction("pol2"); lpar0 = Fit_cospsi_trig->GetParameter(0); lpar1 = Fit_cospsi_trig->GetParameter(1); lpar2 = Fit_cospsi_trig->GetParameter(2); lerr0 = Fit_cospsi_trig->GetParError(0); lerr1 = Fit_cospsi_trig->GetParError(1); lerr2 = Fit_cospsi_trig->GetParError(2); sprintf(lcospsi_trig_effi,"%f+(%f*x)+(%f*x*x)", lpar0,lpar1,lpar2);

    cospsi_l_effi->DrawCopy("E"); delete Fit_cospsi_trig; delete cospsi_l_effi; }

    void PickupSignalFromData1(int s0=0, int s1=0, int s2=0){ ////////////////////////////////// //the unperfect trigger efficiency from data is versus pt is converted to versus cospsi and used to correct efficiency function. // and fit (data-mc_bkgd) with function(wpola*efficiency*trigger_correction) cout<<endl<<"in PickupSignalFromData() ....." <<endl;

    //1. compose the data TH1F* RL_data_corr= new TH1F( "RL_data_corr","RL_data_corr",bins, lox, hix); GetHistFromNtuple(ntuple_tt_3_d, "cospsi_ang", "w_pola_reco_corr", weight_3*data*qualitycut, bins, lox, hix, 1); GetHistFromNtuple(ntuple_tt_bk1_d, "cospsi_ang", "bk1_w_pola_reco_corr", weight_3*data*qualitycut, bins, lox, hix, 1); GetHistFromNtuple(ntuple_tt_bk2_d, "cospsi_ang", "bk2_w_pola_reco_corr", weight_3*data*qualitycut, bins, lox, hix, 1); RL_data_corr->Add(w_pola_reco_corr,1); delete w_pola_reco_corr; RL_data_corr->Add(bk1_w_pola_reco_corr,1); delete bk1_w_pola_reco_corr; RL_data_corr->Add(bk2_w_pola_reco_corr,1); delete bk2_w_pola_reco_corr;

    //3. simulate all kinds of mc background with unperfect trigger efficnecy from data involved ; GetHistFromNtuple(ntuple_tt_bk1_m, "cospsi_ang", "MC_bk1_w_pola_reco_corr", weight_3*MC*allcorrections*qualitycut, bins, lox, hix, 1); GetHistFromNtuple(ntuple_tt_bk2_m, "cospsi_ang", "MC_bk2_w_pola_reco_corr", weight_3*MC*allcorrections*qualitycut, bins, lox, hix, 1); GetHistFromNtuple(ntuple_tt_3_m, "cospsi_ang", "MC_bk3_w_pola_reco_corr", weight_3*MC*allcorrections*qualitycut*(semiemu), bins, lox, hix, 1); GetHistFromNtuple(ntuple_tt_3_m, "cospsi_ang", "MC_bk4_w_pola_reco_corr", weight_3*MC*allcorrections*qualitycut*semiemu*(goodlnb),bins, lox, hix, 1); // RL_data_corr - minus MC bk RL_data_corr->Add(MC_bk1_w_pola_reco_corr,-1); delete MC_bk1_w_pola_reco_corr; RL_data_corr->Add(MC_bk2_w_pola_reco_corr,-1); delete MC_bk2_w_pola_reco_corr; RL_data_corr->Add(MC_bk3_w_pola_reco_corr,-1); delete MC_bk3_w_pola_reco_corr; RL_data_corr->Add(MC_bk4_w_pola_reco_corr,-1); delete MC_bk4_w_pola_reco_corr;

    }

    void PickupSignalFromData2(int s0=0, int s1=0, int s2=0){ ////////////////////////////////// //the unperfect trigger efficiency from data is versus pt is converted to versus cospsi and used to correct efficiency function. // and fit (data-mc_bkgd) with function(wpola*efficiency*trigger_correction) cout<<endl<<"in PickupSignalFromData() ....." <<endl;

    //1. compose the data data = data_ori*nom*"730"*"(eventnumber%2)!=0"; TH1F* RL_data_corr= new TH1F( "RL_data_corr","RL_data_corr",bins, lox, hix); GetHistFromNtuple(ntuple_tt_3_d, "cospsi_ang", "w_pola_reco_corr", weight_3*data*qualitycut, bins, lox, hix, 1); GetHistFromNtuple(ntuple_tt_bk1_d, "cospsi_ang", "bk1_w_pola_reco_corr", weight_3*data*qualitycut, bins, lox, hix, 1); GetHistFromNtuple(ntuple_tt_bk2_d, "cospsi_ang", "bk2_w_pola_reco_corr", weight_3*data*qualitycut, bins, lox, hix, 1); RL_data_corr->Add(w_pola_reco_corr,1); delete w_pola_reco_corr; RL_data_corr->Add(bk1_w_pola_reco_corr,1); delete bk1_w_pola_reco_corr; RL_data_corr->Add(bk2_w_pola_reco_corr,1); delete bk2_w_pola_reco_corr;

    //3. simulate all kinds of mc background with unperfect trigger efficnecy from data involved ; GetHistFromNtuple(ntuple_tt_bk1_m, "cospsi_ang", "MC_bk1_w_pola_reco_corr", weight_3*MC*allcorrections*qualitycut, bins, lox, hix, 1); GetHistFromNtuple(ntuple_tt_bk2_m, "cospsi_ang", "MC_bk2_w_pola_reco_corr", weight_3*MC*allcorrections*qualitycut, bins, lox, hix, 1); GetHistFromNtuple(ntuple_tt_3_m, "cospsi_ang", "MC_bk3_w_pola_reco_corr", weight_3*MC*allcorrections*qualitycut*(semiemu), bins, lox, hix, 1); GetHistFromNtuple(ntuple_tt_3_m, "cospsi_ang", "MC_bk4_w_pola_reco_corr", weight_3*MC*allcorrections*qualitycut*semiemu*(goodlnb),bins, lox, hix, 1); // RL_data_corr - minus MC bk RL_data_corr->Add(MC_bk1_w_pola_reco_corr,-1); delete MC_bk1_w_pola_reco_corr; RL_data_corr->Add(MC_bk2_w_pola_reco_corr,-1); delete MC_bk2_w_pola_reco_corr; RL_data_corr->Add(MC_bk3_w_pola_reco_corr,-1); delete MC_bk3_w_pola_reco_corr; RL_data_corr->Add(MC_bk4_w_pola_reco_corr,-1); delete MC_bk4_w_pola_reco_corr;

    }

    void FitSignalWithAlternateFunction(int s0=0, int s1=0, int s2=0){ //4. fit with (wpola*efficiency*trigger_correction) sprintf(lcospsi_trig_effi,"%f+(%f*x)+(%f*x*x)", lpar0+s0*lerr0,lpar1+s1*lerr1,lpar2+s2*lerr2); sprintf(func_pola_effi_corr,"wpola*(%s)*(%s)", mc_efficiency, lcospsi_trig_effi ); cout<<"Final fit function:"<<endl<<func_pola_effi_corr<<endl; if( F_pola_effi_corr ) delete F_pola_effi_corr; F_pola_effi_corr=new TF1("F_pola_effi_corr",func_pola_effi_corr); CD(); RL_data_corr->Fit("F_pola_effi_corr","","E",fit_lo, fit_hi); TF1* corrdatafit=RL_data_corr->GetFunction("F_pola_effi_corr"); cout<<"with corrected MC, F0: "<<corrdatafit->GetParameter(0)<<" and error: "<<corrdatafit->GetParError(0)<<endl; RL_data_corr->DrawCopy("E"); delete corrdatafit; delete RL_data_corr;

    }

    void Finalize(){

    }

    void CD(){ padnum++; c1->cd(padnum); }

    void CospsiResolutionEffectsToFinalFit(){ ///////////////////////////////////////////// // cout<<endl<<"in CospsiResolutionEffectsToFinalFit() ....." <<endl; CD(); DrawoneDenNtuple( ntuple_tt_3, "acos(cospsi_ang_true)", "cospsi_true", weight_3*MC_ori*semiemu*"cospsi_ang_true!=0", 200, 0, 3.2, 1, 1., 0, 1,"" ); DrawoneDenNtuple( ntuple_tt_3, "acos(cospsi_ang)", "cospsi", weight_3*MC_ori*semiemu*"cospsi_ang!=0", 200, 0, 3.2, 1, 1., 2, 1,"SAME" ); CD(); DrawoneDenNtuple( ntuple_tt_3, "acos(cospsi_ang)-acos(cospsi_ang_true)", "cospsi_true", weight_3*MC_ori*semiemu*goodlnb*"cospsi_ang!=0&&cospsi_ang_true!=0", 200, -1.5, 1.5, 1, 1., 0, 1,"" );

    // CD(); // const int CONST1=10; // double psi[CONST1],rmspsi[CONST1],epsi[CONST1],ermspsi[CONST1]; // for(int i=0;i<CONST1;i++){ // double psi1=3.142/CONST1*i; // cout<<psi1<<endl; // double psi2=3.142/CONST1*(i+1); // cout<<psi2<<endl; // char psicut[500]; // sprintf(psicut,"acos(cospsi_ang_true)>%f && acos(cospsi_ang_true)<%f", psi1,psi2); // std::vector histdata=DrawoneDenNtuple( ntuple_tt_3, "acos(cospsi_ang)-acos(cospsi_ang_true)", "cospsi_true", weight_3*MC_ori*semiemu*goodlnb*"cospsi_ang!=0&&cospsi_ang_true!=0"*psicut, 200, -1.5, 1.5, 1, 1., 0, 1,"" ); // psi [i]=3.142/CONST1*(i+0.5); // rmspsi[i]=3.142/CONST1; // epsi [i]=histdata[0]; // ermspsi[i]=histdata[1]; // //histdata->Delete(); // cout<<psi [i]<<" : "<<rmspsi[i] <<" : "<<epsi [i]<<" : "<<ermspsi[i]<<endl; // } // CD(); // TGraphErrors* resopsi_vs_psi =new TGraphErrors(CONST1,psi,epsi,rmspsi,ermspsi); // resopsi_vs_psi->SetTitle("cospsi resolution vs. cospsi"); // resopsi_vs_psi->Draw("ALP"); // CD(); // resopsi_vs_psi->Fit("pol2"); // // CD(); // ntuple_tt_3->Draw("acos(cospsi_ang)-acos(cospsi_ang_true):acos(cospsi_ang_true)>>resovscospsi(25,0,3.2,30,-1.5,1.5)", weight_3*MC_ori*semiemu*goodlnb*"cospsi_ang!=0&&cospsi_ang_true!=0" ); // CD(); // resovscospsi->ProfileX()->Draw(); // CD(); // resovscospsi->ProfileY()->Draw();

    // 1. CD(); GetHistFromNtuple(ntuple_tt_3, "AddRandomNumberToNtupleVariable(cospsi_ang_true)", "w_pola_true", weight_3*MC_ori*semiemu*"cospsi_ang_true!=0", bins, lox, hix, 1);

    //2. w_pola_true->Fit("wpola","Q","", fit_lo, fit_hi); TF1* truthfit=w_pola_true->GetFunction("wpola"); cout<<"Truth psi distribution, F0: "<<truthfit->GetParameter(0)<<" and error: "<<truthfit->GetParError(0)<<endl;

    w_pola_true->DrawCopy(); delete w_pola_true; }

    double AddRandomNumberToNtupleVariable(double x){

    return cos(acos(x)+gRandom->Gaus(0,0.3146-0.01933*x-0.02423*x*x));

    }

    // void WeightCorrectedMC(){ // ////////////////////////////////// // //MC efficiency function is versus cospsi, but the unperfect trigger efficiency is versus pt. // //so correction due to trigger efficiency can't be multiplied directly to MC efficiency function. // // the method is to give a weight to the (data-mc_bkgd) with the inverse of real trigger efficiency // // and fit with function(wpola*efficiency) // // //1. define cut allcorrections which is function of pt of lepton // trig_corr=EF_trg*allcorrections; // // //2. the allcorrections will correct data's cospsi distribution according to its lepton's pt // GetHistFromNtuple(ntuple_tt_3, "cospsi_ang", "w_pola_reco_corr", weight_3*data*qualitycut*trig_corr, bins, lox, hix, 1); // GetHistFromNtuple(ntuple_tt_bk1, "cospsi_ang", "bk1_w_pola_reco_corr", weight_3*data*qualitycut*trig_corr, bins, lox, hix, 1); // GetHistFromNtuple(ntuple_tt_bk2, "cospsi_ang", "bk2_w_pola_reco_corr", weight_3*data*qualitycut*trig_corr, bins, lox, hix, 1); // // TH1F* RL_data_corr= new TH1F( "RL_data_corr","RL_data_corr",bins, lox, hix); // RL_data_corr->Add(w_pola_reco_corr,1); // RL_data_corr->Add(bk1_w_pola_reco_corr,1); // RL_data_corr->Add(bk2_w_pola_reco_corr,1); // // //RL_data_corr - minus MC bk // RL_data_corr->Add(MC_bk1_w_pola_reco,-1); // RL_data_corr->Add(MC_bk2_w_pola_reco,-1); // RL_data_corr->Add(MC_bk3_w_pola_reco,-1); // RL_data_corr->Add(MC_bk4_w_pola_reco,-1); // // // fit with (wpola*efficiency) // CD(); // RL_data_corr->Fit("F_pola_effi","Q","E",fit_lo, fit_hi); // TF1* corrdatafit=RL_data_corr->GetFunction("F_pola_effi"); // cout<<"with corrected MC, F0: "<<corrdatafit->GetParameter(0)<<" and error: "<<corrdatafit->GetParError(0)<<endl; // // }

    void GetHistFromNtuple( TTree* tree, char* varntuple, char* histname, TCut cut, int bins, float lowx, float highx, float scale=1){ char var[1000]; sprintf( var , "(%s)*%f>>%s(%i,%f,%f)", varntuple,scale,histname,bins,lowx,highx); tree->Draw(var, cut,"goff"); }

    void GetHistFromNtuple2D( TTree* tree, TCut cut, char* histname, char* varntuplex, int binx, float lowx, float highx,float scalex=1, char* varntupley, int biny, float lowy, float highy, float scaley=1){ char var[1000]; sprintf( var , "(%s*%f):(%s*%f)>>%s(%i,%f,%f,%i,%f,%f)", varntupley,scaley,varntuplex,scalex,histname,binx,lowx,highx, biny,lowy,highy); tree->Draw(var, cut,"lego"); }

    void GetHistFromNtuple2D( TTree* tree, TCut cut, char* histname, char* varntuplex,float scalex=1, char* varntupley, float scaley=1){ char var[1000]; sprintf( var , "(%s*%f):(%s*%f)>>%s", varntupley,scaley,varntuplex,scalex,histname); tree->Draw(var, cut,"goff"); }

    void plot_Efficiency(TTree* tref, char* hist, char* varntuple,TCut cutup,TCut cutdw,int bins,float lowx,float highx,float scale=1,int color=1, float min=0., float max=1., int marker=8, char* opt="",char* title=""){ GetHistFromNtuple(tref,varntuple,"tmpupref",cutup,bins,lowx,highx,scale); GetHistFromNtuple(tref,varntuple,"tmpdwref",cutdw,bins,lowx,highx,scale);

    tmpdwref->Sumw2(); tmpupref->Divide(tmpdwref); tmpupref->SetMarkerStyle(marker); tmpupref->SetLineColor(color); tmpupref->SetMarkerColor(color); if(opt=="HIST" || opt=="HIST SAME"){ tmpupref->SetLineWidth(color); if(color>3 ) { tmpupref->SetLineStyle(color-2); tmpupref->SetLineWidth(2); } } tmpupref->SetMarkerSize(0.3); tmpupref->SetMinimum(min); tmpupref->SetMaximum(max); tmpupref->GetXaxis()->SetTitle(title); tmpupref->GetYaxis()->SetTitle("Efficiency"); tmpupref->DrawCopy(opt); tmpupref->Clone(hist); tmpupref->Delete(); tmpdwref->Delete(); }

    void plot_Efficiency2D(TTree* tree, TCut cutup, TCut cutdw, char* hist, char* varntuplex, int binx, float lowx, float highx,float scalex=1, char* varntupley, int biny, float lowy, float highy, float scaley=1){ GetHistFromNtuple2D(tree, cutup, "tmpupref",varntuplex, binx,lowx,highx,scalex, varntupley,biny,lowy,highy,scaley); GetHistFromNtuple2D(tree, cutdw, "tmpdwref",varntuplex, binx,lowx,highx,scalex, varntupley,biny,lowy,highy,scaley);

    tmpdwref->Sumw2(); tmpupref->Divide(tmpdwref); tmpupref->DrawCopy("lego"); tmpupref->Clone(hist); tmpupref->Delete(); tmpdwref->Delete(); }

    void plot_Efficiency2D(TTree* tree,char* hist, TCut cutup, TCut cutdw, char* varntuplex, int binx, const Float_t* xbin ,float scalex=1, char* varntupley, int biny, const Float_t* ybin, float scaley=1){

    tmpupref=new TH2F("tmpupref", "tmpupref", binx,xbin, biny,ybin); GetHistFromNtuple2D(tree, cutup, "tmpupref",varntuplex,scalex, varntupley,scaley); TH2F* tmpdwref=new TH2F("tmpdwref", "tmpdwref", binx,xbin, biny,ybin); GetHistFromNtuple2D(tree, cutdw, "tmpdwref",varntuplex, scalex, varntupley,scaley);

    tmpdwref->Sumw2(); tmpupref->Divide(tmpdwref); //tmpupref->DrawCopy("goff"); tmpupref->Clone(hist); tmpupref->Delete(); tmpdwref->Delete(); }

    double etrig_num(double pt){

    pt=pt/1000; if(pt>=g_trig_hpt) pt=g_trig_hpt-0.1; int bin=pt/(g_trig_hpt-g_trig_lpt)*g_trig_bins+1;

    if(g_etrig_hist[bin]==0) return 10000; else return g_etrig_hist[bin]; }

    double mtrig_num(double pt){

    pt=pt/1000; if(pt>=g_trig_hpt) pt=g_trig_hpt-0.1; int bin=pt/(g_trig_hpt-g_trig_lpt)*g_trig_bins+1;

    if(g_mtrig_hist[bin]==0) return 10000; else return g_mtrig_hist[bin]; }

    void InitializeCharVector(char* cv){ sprintf(cv,"1" );

    }

    std::vector DrawoneDenNtuple( TTree* newtree, char* varntuple, char* title, TCut cut, int bins, float lowx, float highx, float xscale=1, float yscale=1., int color=0, int linewidth=1, char* drawoption="" ){ GetHistFromNtuple(newtree,varntuple,"histnew",cut, bins,lowx,highx, xscale); ScaleHist(histnew,yscale); SetYmaxYmin(histnew);

    histnew->GetXaxis()->SetTitle(title); if(linewidth!=1 )histnew->SetLineWidth(linewidth); if(color!=0 )histnew->SetLineColor(color); if(drawoption!="" ){ char opt[20]; sprintf( opt , "H%s", drawoption); histnew->DrawCopy(opt); } else histnew->DrawCopy("HIST"); // std::vector RMS; RMS.push_back(histnew->GetRMS()); RMS.push_back(histnew->GetRMSError());

    histnew->Delete(); return RMS; }

    void ScaleHist(TH1F* hist, float scale=1.){ float histinte = hist->Integral(); hist->Sumw2(); if( histinte>0 ) hist->Scale(scale/histinte ); else cout<<"the histgram integral to 0"<<endl; }

    void SetYmaxYmin(TH1F* hist){ hist->SetMinimum(0.0005); int maxbin = hist->GetMaximumBin(); float highy=hist->GetBinContent(maxbin)*1.2; hist->SetMaximum(highy); }

    Assigned to Due date Description State Closed Notify  
    ChengguangZhu 2007-12-11 e mu is in different selection, is a good 2 smaples to study the bias introduced by lepton selection...     edit
Topic attachments
I Attachment History Action Size Date Who Comment
JPEGjpg corre_e_resolution.jpg r1 manage 132.7 K 2007-12-06 - 13:34 ChengguangZhu corrections on discrepency on e pt resolution
JPEGjpg correction_function_atlfastMC.jpg r1 manage 19.0 K 2007-12-09 - 16:05 ChengguangZhu correction function in less bins, still small chi2
Unknown file formatcxx method2.cxx r1 manage 43.3 K 2007-11-29 - 19:43 ChengguangZhu my program to do this work
JPEGjpg recoeffi_corr.jpg r1 manage 146.9 K 2007-11-29 - 19:15 ChengguangZhu plots for different stages
PowerPointppt top_zhucg_trigger_syserror.ppt r1 manage 678.0 K 2007-11-27 - 20:04 ChengguangZhu Document
Edit | Attach | Watch | Print version | History: r15 < r14 < r13 < r12 < r11 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r15 - 2007-12-12 - ChengguangZhu
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    Main All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback