void plotHistos_Wen() {
    gROOT->LoadMacro("tdrstyle.C");
    gROOT->ProcessLine("setTDRStyle()");

    TH1::SetDefaultSumw2(1);
    //gROOT->SetBatch(1);

    TString plotdir = "plots/";

    if (gSystem->AccessPathName(plotdir))
        gSystem->mkdir(plotdir);


    ////////////////////////////////////////////////////////////////////////////
    // Task 1 (a)                                                             //
    // - please comment out other tasks                                       //
    ////////////////////////////////////////////////////////////////////////////
    /*
    // Read from ntuples
    Events * ev = new Events();
    TCut cutmc_all   = "Vtype==0";   // change this to your channel
    TCut cutdata_all = "Vtype==0";   // change this to your channel
    TString process  = "VH";         // can try other processes: VH, WJ, ZJ, TT
    ev->read(cutmc_all, cutdata_all, process);

    TString var      = "HCSV_mass";                // the variable to plot
    TCut cut         = "V_pt>120";              // the selection cut
    TString title    = ";m(jj) [GeV]";          // the title of the histogram
    TString plotname = process + "_Hmass";      // the name of the image file
    int nbinsx       = 15;                      // number of bins
    double xlow      = 30.0;                    // the low edge of x-axis
    double xup       = 255.0;                   // the upper edge of x-axis
    TString options  = "!plotLog:!plotNorm";    // use "plotLog" to plot on log-y scale,
                                                // use "!plotLog" to plot on linear scale;
                                                // use "plotNorm" to plot normalized plots,
                                                // use "!plotNorm" otherwise.

    // Use "ev->ZH" for ZH, or "ev->WjLF", "ev->WjHF", "ev->ZjLF", "ev->ZjHF", "ev->TT" for other processes
    MakePlot(ev->ZH, var, cut, title, nbinsx, xlow, xup, plotname, plotdir, options);

    // You can put in the parameters directly as in the following commented out line:
    //MakePlot(ev->ZH, "HCSV_pt", cut, "; p_{T}(jj) [GeV]", 16, 0, 240., process + "_Hpt", plotdir, options);
    */

    ////////////////////////////////////////////////////////////////////////////
    // Task 1 (b)                                                             //
    // - please comment out other tasks                                       //
    ////////////////////////////////////////////////////////////////////////////
    /*
    // Read from ntuples
    Events * ev = new Events();
    TCut cutmc_all   = "Vtype==0";   // change this to your channel
    TCut cutdata_all = "Vtype==0";   // change this to your channel
    ev->read(cutmc_all, cutdata_all, "VH:ZJ");  // read both VH and ZJ processes

    TString var      = "HCSV_mass";
    TCut cut         = "V_pt>120";
    //TCut cut         = "V_pt>120 && Jet_pt[hJCidx[0]]>30 && Jet_pt[hJCidx[1]]>30";  // for Wln, Znn, change to tighter cut
    TString title    = ";m(jj) [GeV]";
    TString plotname = "ZH_vs_ZJ_Hmass";
    int nbinsx       = 15;
    double xlow      = 30.0;
    double xup       = 255.0;
    TString options  = "!plotLog:plotNorm";

    // Using "ev->ZH" for ZH and "ev->ZjHF" for Z+HF
    MakePlot2(ev->ZH, ev->ZjHF, var, cut, title, nbinsx, xlow, xup, plotname, plotdir, options);
    
    */
    ////////////////////////////////////////////////////////////////////////////
    // Task 2                                                                 //
    // - please comment out other tasks                                       //
    ////////////////////////////////////////////////////////////////////////////
    
    // Zmm______________________________________________________________________
    //TString channel  = "Zmm";

    //Loose cuts for this channel
    //TCut cutmc_all = "Vtype==0 && V_pt>100 && met_pt<60"; // V related
    //cutmc_all += "75<V_mass && V_mass<105"; //Z mass window
    //cutmc_all += "Jet_pt[hJCidx[0]]>20 && Jet_pt[hJCidx[1]]>20 && abs(Jet_eta[hJCidx[0]])<2.4 && abs(Jet_eta[hJCidx[1]])<2.4";// H jets
    //cutmc_all += "min(Jet_btagCSV[hJCidx[0]], Jet_btagCSV[hJCidx[1]])>0.4"; //loose b-tag
    //cutmc_all += "Sum$(Jet_pt > 20 & abs(Jet_eta) < 2.4) < 3"; //no additional jets

    //TCut met_cleaning = "Flag_hbheFilterNew &&Flag_hbheIsoFilter && Flag_goodVertices &&Flag_eeBadScFilter &&Flag_CSCTightHaloFilter";
    //TCut mc_trigger = "HLT_ZmmHbbAll==1";
    //TCut data_trigger = "HLT_BIT_HLT_IsoMu18_v==1";

    //TCut cutdata_all = cutmc_all;
    //cutdata_all += data_trigger;
    //cutmc_all += mc_trigger;

    // Scale factors in order of: WjLF, WjHF, ZjLF, ZjHF, TT
    // NOTE: WjLF, WjHF are not needed for Zll
    //double scalefactors[5] = {1.00, 1.00, 1.00, 1.00, 1.00};


    // Zee______________________________________________________________________
    //TString channel  = "Zee";

    //Loose cuts for this channel
    //TCut cutmc_all = "Vtype==1 && V_pt>100 && met_pt<60"; // V related
    //cutmc_all += "75<V_mass && V_mass<105"; //Z mass window
    //cutmc_all += "Jet_pt[hJCidx[0]]>20 && Jet_pt[hJCidx[1]]>20 && abs(Jet_eta[hJCidx[0]])<2.4 && abs(Jet_eta[hJCidx[1]])<2.4";// H jets
    //cutmc_all += "min(Jet_btagCSV[hJCidx[0]], Jet_btagCSV[hJCidx[1]])>0.4"; //loose b-tag
    //cutmc_all += "Sum$(Jet_pt > 20 & abs(Jet_eta) < 2.4) < 3"; //no additional jets

    //TCut met_cleaning = "Flag_hbheFilterNew &&Flag_hbheIsoFilter && Flag_goodVertices &&Flag_eeBadScFilter &&Flag_CSCTightHaloFilter";
    //TCut mc_trigger = "HLT_ZeeHbbAll==1";
    //TCut data_trigger = "HLT_BIT_HLT_Ele27_eta2p1_WPLoose_Gsf_v==1";

    //TCut cutdata_all = cutmc_all;
    //cutdata_all += data_trigger;
    //cutmc_all += mc_trigger;

    // Scale factors in order of: WjLF, WjHF, ZjLF, ZjHF, TT
    // NOTE: WjLF, WjHF are not needed for Zll
    //double scalefactors[5] = {1.00, 1.00, 1.00, 1.00, 1.00};


    // Wmn______________________________________________________________________
    //TString channel  = "Wmn";

    //Loose cuts for this channel
    //TCut cutmc_all = "Vtype==2 && V_pt>100 && met_pt>45"; // V related
    //cutmc_all +=  "vLeptons_pt[0]>30 && abs(vLeptons_eta[0])<2.4 && naLeptons==0";//one lepton
    //cutmc_all += "Jet_pt[hJCidx[0]]>20 && Jet_pt[hJCidx[1]]>20 && abs(Jet_eta[hJCidx[0]])<2.4 && abs(Jet_eta[hJCidx[1]])<2.4";// H jets
    //cutmc_all += "min(Jet_btagCSV[hJCidx[0]], Jet_btagCSV[hJCidx[1]])>0.4"; //loose b-tag
    //cutmc_all += "Sum$(Jet_pt > 20 & abs(Jet_eta) < 2.4) < 3"; //no additional jets

    //TCut met_cleaning = "Flag_hbheFilterNew &&Flag_hbheIsoFilter && Flag_goodVertices &&Flag_eeBadScFilter &&Flag_CSCTightHaloFilter";
    //TCut mc_trigger = "";
    //TCut data_trigger = "";

    //TCut cutdata_all = cutmc_all;
    //cutdata_all += data_trigger;
    //cutmc_all += mc_trigger;
    
    // Scale factors in order of: WjLF, WjHF, ZjLF, ZjHF, TT
    // NOTE: ZjLF, ZjHF are not needed for Wln
    //double scalefactors[5] = {1.00, 1.00, 1.00, 1.00, 1.00};


    // Wen______________________________________________________________________
    TString channel  = "Wen";

    //Loose cuts for this channel
    TCut cutmc_all = "Vtype==3 && V_pt>100 && met_pt>45"; // V related
    cutmc_all +=  "vLeptons_pt[0]>30 && abs(vLeptons_eta[0])<2.4 && naLeptons==0";//one lepton
    cutmc_all += "Jet_pt[hJCidx[0]]>20 && Jet_pt[hJCidx[1]]>20 && abs(Jet_eta[hJCidx[0]])<2.4 && abs(Jet_eta[hJCidx[1]])<2.4";// H jets
    cutmc_all += "min(Jet_btagCSV[hJCidx[0]], Jet_btagCSV[hJCidx[1]])>0.4"; //loose b-tag
    cutmc_all += "Sum$(Jet_pt > 20 & abs(Jet_eta) < 2.4) < 3"; //no additional jets

    TCut met_cleaning = "Flag_hbheFilterNew &&Flag_hbheIsoFilter && Flag_goodVertices &&Flag_eeBadScFilter &&Flag_CSCTightHaloFilter";
    TCut mc_trigger = "";
    TCut data_trigger = "";

    TCut cutdata_all = cutmc_all;
    cutdata_all += data_trigger;
    cutmc_all += mc_trigger;

    // Scale factors in order of: WjLF, WjHF, ZjLF, ZjHF, TT
    // NOTE: ZjLF, ZjHF are not needed for Wln
    double scalefactors[5] = {1.00, 1.00, 1.00, 1.00, 1.00};


    // Znn______________________________________________________________________
    //TString channel  = "Znn";

    // These are loose cuts for all plots in this particular channel
    //TCut cutmc_all   = "Vtype==4 && HCSV_pt>130 && Jet_pt[hJCidx[0]]>80 && Jet_pt[hJCidx[1]]>30 && abs(Jet_eta[hJCidx[0]])<2.5 && abs(Jet_eta[hJCidx[1]])<2.5 && naLeptons==0 && Sum$(Jet_pt > 20 & abs(Jet_eta) < 2.4)<5"; 
    //&& min(Min$(abs(deltaPhi(met_phi,hJet_phi))),Min$(abs(deltaPhiMETjets(met_phi,aJet_phi,aJet_pt,aJet_eta)))+999*(Sum$(aJet_pt>25 && abs(aJet_eta)<4.5 && aJet_id==1 && aJet_puJetIdL>0)==0) )>0.5";//needs to be updated to 13 TeV
    //cutmc_all       += "min(Jet_btagCSV[hJCidx[0]], Jet_btagCSV[hJCidx[1]])>0.4 && min(abs(HCSV_phi-V_phi),(2*TMath::Pi())-abs(HCSV_phi-V_phi))>2.0";  // tighter cut
    //TCut cutdata_all = cutmc_all;
    //cutmc_all       *= "(triggerFlags[42]==1 || triggerFlags[39]==1 || triggerFlags[41]==1)"; // apply trigger bits and MET cleaning for MC (they are already applied on data)
    //cutmc_all       *= "triggercorrMET(met_pt)";

    // Scale factors in order of: WjLF, WjHF, ZjLF, ZjHF, TT
    //double scalefactors[5] = {1.00, 1.00, 1.00, 1.00, 1.00};


    // All channels_____________________________________________________________
    // Read from ntuples
    Events * ev = new Events();
    ev->read(cutmc_all, cutdata_all);

    // Set the scale factors
    ev->set_sf(scalefactors);

    // Optimize these five variables (default: recommendations for Zll)
    //double vpt    = 150.;
    //double hpt    = 0.;
    //double maxcsv = 0.679;
    //double mincsv = 0.5;
    //double dPhi   = 0.;

    // Optimize these five variables (default: recommendations for Wln)
    double vpt    = 150.;
    double hpt    = 100.;
    double maxcsv = 0.898;
    double mincsv = 0.5;
    double dPhi   = 2.95;

    // Optimize these five variables (default: recommendations for Znn)
    //double vpt    = 170.;  // for Znn, pT(V) = MET
    //double hpt    = 170.;
    //double maxcsv = 0.898;
    //double mincsv = 0.5;
    //double dPhi   = 2.95;

    // If doing cut and count analysis, cut on HCSV_mass by changing the values of minhmass and maxhmass
    //double minhmass = 0.;
    //double maxhmass = 9999.;
    double minhmass = 110.;
    double maxhmass = 140.;

    // These are tight cuts for this particular plot
    //TCut cutmc = Form("V_pt>%.2f && HCSV_pt>%.2f && max(Jet_btagCSV[hJCidx[0]],Jet_btagCSV[hJCidx[1]])>%.3f && min(Jet_btagCSV[hJCidx[0]], Jet_btagCSV[hJCidx[1]])>%.3f && HVdPhi>%.2f && %.2f<HCSV_mass && HCSV_mass<%.2f", vpt, hpt, maxcsv, mincsv, dPhi, minhmass, maxhmass);
    TCut cutmc = "";
    TCut cutdata = cutmc;

    TString var      = "HCSV_mass";
    TString title    = ";m(jj) [GeV]";
    TString plotname = channel + "_Hmass";
    int nbinsx       = 15;
    double xlow      = 30.0;
    double xup       = 255.0;

    TString options  = "printStat:plotSig:plotData:!plotLog";
    MakePlots(ev, var, cutmc, cutdata, title, nbinsx, xlow, xup, plotname, plotdir, options);


    // Or, just put in them directly as in the following commented out line:
    //MakePlots(ev, "HCSV_mass", cutmc, cutdata, "m(jj) [GeV]", 14, 30.0, 255.0, channel+"_Hmass", plotdir, "printStat:plotSig:!plotData:!plotLog");

    
    ////////////////////////////////////////////////////////////////////////////
    // Task 3                                                                 //
    // - please comment out other tasks, but keep Task 2                      //
    ////////////////////////////////////////////////////////////////////////////
    /*
    TString dcname    = Form("vhbb_%s_13TeV.txt", channel.Data());   // the datacard name
    TString wsname    = plotdir + plotname +".root";                // the workspace name
    bool    useshapes = false;
    TString options1  = "!unblind:SplusB";

    // For cut-and-count analysis, apply HCSV_mass cut before calling MakeDatacard(...)
    MakeDatacard(channel, dcname, wsname, useshapes, options1);


    // For shape analysis, remove HCSV_mass cut before calling MakeDatacard(...)
    //cutmc = Form("V_pt>%.2f && HCSV_pt>%.2f && max(Jet_btagCSV[hJCidx[0]],Jet_btagCSV[hJCidx[1]])>%.3f && min(Jet_btagCSV[hJCidx[0]], Jet_btagCSV[hJCidx[1]])>%.3f && min(abs(HCSV_phi-V_phi),(2*TMath::Pi())-abs(HCSV_phi-V_phi))>%.2f", vpt, hpt, maxcsv, mincsv, dPhi);
    //cutdata = cutmc;
    //plotname = channel + "_Hmass_shapes";
    //MakePlots(ev, var, cutmc, cutdata, title, nbinsx, xlow, xup, plotname, plotdir, options);

    //dcname    = Form("vhbb_shapes_%s_13TeV.txt", channel.Data());    // the datacard name
    //wsname    = plotdir + plotname +".root";                        // the workspace name
    //useshapes = true;
    //options1  = "unblind:SplusB";
    //MakeDatacard(channel, dcname, wsname, useshapes, options1);
    */

    delete ev;
}
void plotHistos_Znn_13TeV_BDT() {
    gROOT->LoadMacro("tdrstyle.C");
    gROOT->ProcessLine("setTDRStyle()");

    TH1::SetDefaultSumw2(1);
    //gROOT->SetBatch(1);

    TString plotdir = "plots/";

    if (gSystem->AccessPathName(plotdir))
        gSystem->mkdir(plotdir);


    ////////////////////////////////////////////////////////////////////////////
    // Task 1 (a)                                                             //
    // - please comment out other tasks                                       //
    ////////////////////////////////////////////////////////////////////////////

    // Read from ntuples
    Events * ev = new Events();
    //    TCut cutmc_all   = "Vtype==4 && Sum$(hJets_btagCSV>0.9)>0 && H_mass<250 && Jet_pt[hJidx[1]] > 30";
   // change this to your channel
    //    TCut cutdata_all = "Vtype==4 && Sum$(hJets_btagCSV>0.9)>0 && H_mass<250 && Jet_pt[hJidx[1]] > 30";   // change this to your channel

    //     TCut cutmc_all = " Vtype==4 && Sum$(hJets_btagCSV>0.7)>0 && H_mass<250 && Jet_pt[hJidx[1]] > 30 && met_pt>200 && H_pt>150 && min(hJets_btagCSV[0], hJets_btagCSV[1])>0.7 && Jet_pt[hJidx[0]]>100 && Jet_pt[hJidx[1]]>80   && deltaR_jj<1.3 && Sum$(Jet_pt>30 && abs(Jet_eta)<2.5)== 2";

    //    TCut cutmc_all = "Vtype==4 &&  Jet_btagCSV[hJCidx[0]]>0.9 && Jet_btagCSV[hJCidx[1]]>0.8  && HCSV_mass<250 &&  met_pt>200 && HCSV_pt>0 && Jet_pt[hJCidx[0]]>80 && Jet_pt[hJCidx[1]]>30   && deltaR( Jet_eta[hJCidx[0]], Jet_eta[hJCidx[1]],  Jet_phi[hJCidx[0]], Jet_phi[hJCidx[1]] )<1.3 &&  Sum$(Jet_pt>30 && abs(Jet_eta)<2.5)<=3" ;


    //     TCut cutmc_all = "Vtype==4 && MinIf$(abs(deltaPhi(met_phi,Jet_phi)) , Jet_pt>25 && abs(Jet_eta)<4.5 && Jet_puId==1)>1.5 &&  Jet_btagCSV[hJCidx[0]]>0.423 && Jet_btagCSV[hJCidx[1]]>0.423   && HCSV_mass<250 &&  met_pt>170 && HCSV_pt>130 && ( (Jet_pt[hJCidx[0]]>80 && Jet_pt[hJCidx[1]]>30)||(Jet_pt[hJCidx[1]]>80 && Jet_pt[hJCidx[0]]>30 ))  &&  Sum$(aLeptons_pt>5  && aLeptons_relIso03<1. &&  ( deltaR(Jet_eta[hJCidx[0]], aLeptons_eta, Jet_phi[hJCidx[0]], aLeptons_phi)>0.4 &&  deltaR(Jet_eta[hJCidx[1]], aLeptons_eta, Jet_phi[hJCidx[1]], aLeptons_phi)>0.4))==0 && Sum$(Jet_pt>30 && abs(Jet_eta)<4.5 && Jet_puId==1)<=99  && abs(deltaPhi(HCSV_phi, met_phi))>2.5";


    //     TCut cutmc_all = "";
    
     TCut weightmc = "(efflumi * 2. * weightTrig * sign(genWeight))";

    //    TCut cutmc_all = "Vtype==4 &&  Jet_btagCSV[hJCidx[0]]>0.814 && Jet_btagCSV[hJCidx[1]]>0.423   && HCSV_mass<250 &&  met_pt>170 && HCSV_pt>130 && ( (Jet_pt[hJCidx[0]]>80 && Jet_pt[hJCidx[1]]>30) || (Jet_pt[hJCidx[1]]>80 && Jet_pt[hJCidx[0]]>30 ))    &&  Sum$(Jet_pt>30 && abs(Jet_eta)<4.5 && Jet_puId==1)<=99";


     // TCut cutmc_all = "Vtype==4 &&  MinIf$(abs(deltaPhi(met_phi,Jet_phi)) , Jet_pt>25 && abs(Jet_eta)<4.5 && Jet_puId==1)>1.5 &&  max(Jet_btagCSV[hJCidx[0]], Jet_btagCSV[hJCidx[1]])>0.97 &&   min(Jet_btagCSV[hJCidx[0]], Jet_btagCSV[hJCidx[1]])>0.605  &&  met_pt>200 && HCSV_pt>170 && ( (Jet_pt[hJCidx[0]]>80 && Jet_pt[hJCidx[1]]>30) || (Jet_pt[hJCidx[1]]>80 && Jet_pt[hJCidx[0]]>30 ))    &&  Sum$(aLeptons_pt>10  && aLeptons_relIso03<1. &&  ( deltaR(Jet_eta[hJCidx[0]], aLeptons_eta, Jet_phi[hJCidx[0]], aLeptons_phi)>0.4 &&  deltaR( Jet_eta[hJCidx[1]], aLeptons_eta, Jet_phi[hJCidx[1]], aLeptons_phi)>0.4))>=0";




     // TCut cutmc_all = "MinIf$(abs(deltaPhi(met_phi,Jet_phi)) , Jet_pt>25 && abs(Jet_eta)<4.5 && Jet_puId==1)>1.5";
     TCut cutmc_all = "Vtype==4 && MinIf$(abs(deltaPhi(met_phi,Jet_phi)) , Jet_pt>25 && abs(Jet_eta)<4.5 && Jet_puId==1)>1.5 &&  Jet_btagCSV[hJCidx[0]]>0.423 && Jet_btagCSV[hJCidx[1]]>0.423   && HCSV_mass<250 &&  met_pt>170 && HCSV_pt>130 && ( (Jet_pt[hJCidx[0]]>80 && Jet_pt[hJCidx[1]]>30)||(Jet_pt[hJCidx[1]]>80 && Jet_pt[hJCidx[0]]>30 ))  &&  Sum$(aLeptons_pt>5  && aLeptons_relIso03<1. && ( deltaR(Jet_eta[hJCidx[0]], aLeptons_eta, Jet_phi[hJCidx[0]], aLeptons_phi)>0.4 &&  deltaR(Jet_eta[hJCidx[1]], aLeptons_eta, Jet_phi[hJCidx[1]], aLeptons_phi)>0.4))>=0 && Sum$(Jet_pt>30 && abs(Jet_eta)<4.5 && Jet_puId==1)<=99  && abs(deltaPhi(HCSV_phi, met_phi))>2.5";
     //TCut cutmc_all = "Vtype==4  &&  t[hJCidx[0]]>30 ))  &&  Sum$(aLeptons_pt>5  && aLeptons_relIso03<1. && ( deltaR(Jet_eta[hJCidx[0]], aLeptons_eta, Jet_phi[hJCidx[0]], aLeptons_phi)>0.4 &&  deltaR(Jet_eta[hJCidx[1]], aLeptons_eta, Jet_phi[hJCidx[1]], aLeptons_phi)>0.4))>=0 && Sum$(Jet_pt>30 && abs(Jet_eta)<4.5 && Jet_puId==1)<=99  && abs(deltaPhi(HCSV_phi, met_phi))>2.5";



    TCut cutdata_all = cutmc_all;

    TString channel  = "ZnnHighPt";

    ev->read(   cutmc_all   ,  cutmc_all, "" , "tree_ZnunuHighPt_test"); 




    TString var      = "HCSV_mass";                // the variable to plot
    TCut cut         = "";              // the selection cut
    TString title    = ";Hmass [GeV]";          // the title of the histogram
    TString plotname = "mass";      // the name of the image file
    int nbinsx       = 10;                      // number of bins
    double xlow      = 0;                    // the low edge of x-axis
    double xup       = 250;                   // the upper edge of x-axis
    TString options  = "printStat:plotSig:!plotData:!plotLog:!plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,
    MakePlots(ev, var, cut * weightmc , cut , title, nbinsx, xlow, xup, plotname, plotdir, options);



    var      = "HCSV_mass";                // the variable to plot
    cut         = "";              // the selection cut
    title    = ";Hmass [GeV]";          // the title of the histogram
    plotname = "massNorm";      // the name of the image file
    nbinsx       = 10;                      // number of bins
    xlow      = 0;                    // the low edge of x-axis
    xup       = 250;                   // the upper edge of x-axis
    options  = "printStat:plotSig:!plotData:plotLog:plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,
    MakePlots(ev, var, cut * weightmc , cut , title, nbinsx, xlow, xup, plotname, plotdir, options);

    options  = "printStat:plotSig:!plotData:!plotLog:plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,
    plotname = "massNormZHvsTT";      // the name of the image file                                                                                                                                 
    // Using "ev->ZH" for ZH and "ev->ZjHF" for Z+HF
    MakePlot2(ev->ZH, ev->TT, var, cut * weightmc, title, nbinsx, xlow, xup, plotname, plotdir, options);



    var      = "MaxIf$(Jet_pt, Jet_pt != Jet_pt[hJCidx[0]] && Jet_pt != Jet_pt[hJCidx[1]]  && abs(deltaPhi(Jet_phi, evalHMETPhi(0. , met_pt, met_phi, 0., HCSV_mass, HCSV_pt, HCSV_phi, 0.))) < 3.14159265358979323846 -0.3 && evalHMETPt(0. , met_pt, met_phi, 0., HCSV_mass, HCSV_pt, HCSV_phi, 0.) > 40. && Jet_puId>0 && Jet_pt>30)";                // the variable to plot
    cut         = "";              // the selection cut
    title    = ";isrpt [GeV]";          // the title of the histogram
    plotname = "isrptNorm";      // the name of the image file
    nbinsx       = 10;                      // number of bins
    xlow      = 0;                    // the low edge of x-axis
    xup       = 300;                   // the upper edge of x-axis
    options  = "printStat:plotSig:!plotData:plotLog:plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,
    MakePlots(ev, var, cut * weightmc , cut , title, nbinsx, xlow, xup, plotname, plotdir, options);



    var      = "Sum$(Jet_pt>30 &&  Jet_pt != Jet_pt[hJCidx[0]] && Jet_pt != Jet_pt[hJCidx[1]] && abs(deltaPhi(Jet_phi, evalHMETPhi(0. , met_pt, met_phi, 0., HCSV_mass, HCSV_pt, HCSV_phi, 0.))) < 3.14159265358979323846 -0.3 && evalHMETPt(0. , met_pt, met_phi, 0., HCSV_mass, HCSV_pt, HCSV_phi, 0.) > 40. && Jet_puId>0 )";                // the variable to plot
    cut         = "";              // the selection cut
    title    = ";numisr";          // the title of the histogram
    plotname = "numisr";      // the name of the image file
    nbinsx       = 10;                      // number of bins
    xlow      = 0;                    // the low edge of x-axis
    xup       = 10;                   // the upper edge of x-axis
    options  = "printStat:plotSig:!plotData:plotLog:plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,
    MakePlots(ev, var, cut * weightmc , cut , title, nbinsx, xlow, xup, plotname, plotdir, options);



    var      = "MaxIf$(abs(deltaPhi(Jet_phi,evalHMETPhi(0. , met_pt, met_phi, 0., HCSV_mass, HCSV_pt, HCSV_phi, 0.))),  Jet_pt != Jet_pt[hJCidx[0]] && Jet_pt != Jet_pt[hJCidx[1]] && evalHMETPt(0. , met_pt, met_phi, 0., HCSV_mass, HCSV_pt, HCSV_phi, 0.) > 30.  && Jet_pt>30 && Jet_puId>0)";                // the variable to plot
    cut         = "";              // the selection cut
    title    = ";d#Phi(isr,vh)";          // the title of the histogram
    plotname = "dPhijvhNorm";      // the name of the image file
    nbinsx       = 32;                      // number of bins
    xlow      = 0;                    // the low edge of x-axis
    xup       = 3.2;                   // the upper edge of x-axis
    options  = "printStat:plotSig:!plotData:plotLog:plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,
    MakePlots(ev, var, cut * weightmc , cut , title, nbinsx, xlow, xup, plotname, plotdir, options);



    var      = "MaxIf$(Jet_eta,  Jet_pt != Jet_pt[hJCidx[0]] && Jet_pt != Jet_pt[hJCidx[1]] && abs(deltaPhi(Jet_phi, evalHMETPhi(0. , met_pt, met_phi, 0., HCSV_mass, HCSV_pt, HCSV_phi, 0.))) < 3.14159265358979323846 -0.4 && evalHMETPt(0. , met_pt, met_phi, 0., HCSV_mass, HCSV_pt, HCSV_phi, 0.) > 30. && Jet_puId>0)";                // the variable to plot
    cut         = "";              // the selection cut
    title    = ";isreta";          // the title of the histogram
    plotname = "isretaNorm";      // the name of the image file
    nbinsx       = 90;                      // number of bins
    xlow      = -4.5;                    // the low edge of x-axis
    xup       = 4.5;                   // the upper edge of x-axis
    options  = "printStat:plotSig:!plotData:plotLog:plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,
    MakePlots(ev, var, cut * weightmc , cut , title, nbinsx, xlow, xup, plotname, plotdir, options);


    var      = "MaxIf$(evalHMETPt(0. , met_pt, met_phi, 0., HCSV_mass, HCSV_pt, HCSV_phi, 0.)  ,  Jet_pt != Jet_pt[hJCidx[0]] && Jet_pt != Jet_pt[hJCidx[1]] && abs(deltaPhi(Jet_phi, evalHMETPhi(0. , met_pt, met_phi, 0., HCSV_mass, HCSV_pt, HCSV_phi, 0.))) < 3.14159265358979323846 -0.4 && Jet_pt>30  && Jet_puId>0)";                // the variable to plot
    cut         = "";              // the selection cut
    title    = ";vhpt [GeV]";          // the title of the histogram
    plotname = "vptNorm";      // the name of the image file
    nbinsx       = 15;                      // number of bins
    xlow      = 0;                    // the low edge of x-axis
    xup       = 300;                   // the upper edge of x-axis
    options  = "printStat:plotSig:!plotData:plotLog:plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,
    MakePlots(ev, var, cut * weightmc , cut , title, nbinsx, xlow, xup, plotname, plotdir, options);








    var      = "HCSV_pt";                // the variable to plot
    cut         = "";              // the selection cut
    title    = ";Hpt [GeV]";          // the title of the histogram
    plotname = "hptNorm";      // the name of the image file
    nbinsx       = 15;                      // number of bins
    xlow      = 0;                    // the low edge of x-axis
    xup       = 300;                   // the upper edge of x-axis
    options  = "printStat:plotSig:!plotData:plotLog:plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,
    MakePlots(ev, var, cut * weightmc , cut , title, nbinsx, xlow, xup, plotname, plotdir, options);



    var      = "deltaR(Jet_eta[hJCidx[0]],Jet_eta[hJCidx[1]], Jet_phi[hJCidx[0]],Jet_phi[hJCidx[1]])";                // the variable to plot
    cut         = "";              // the selection cut
    title    = ";drjj [GeV]";          // the title of the histogram
    plotname = "drbbNorm";      // the name of the image file
    nbinsx       = 32;                      // number of bins
    xlow      = 0;                    // the low edge of x-axis
    xup       = 3.2;                   // the upper edge of x-axis
    options  = "printStat:plotSig:!plotData:plotLog:plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,
    MakePlots(ev, var, cut * weightmc , cut , title, nbinsx, xlow, xup, plotname, plotdir, options);



    var = "Sum$(aLeptons_pt>5  && aLeptons_relIso03<1. &&  ( deltaR(Jet_eta[hJCidx[0]], aLeptons_eta, Jet_phi[hJCidx[0]], aLeptons_phi)>0.4 &&  deltaR( Jet_eta[hJCidx[1]], aLeptons_eta, Jet_phi[hJCidx[1]],aLeptons_phi)>0.4))";
    cut         = "";              // the selection cut                                                                                                                                             
    title    = ";num extra lepton pt>5";          // the title of the histogram                                                                                                                    
    plotname = "numlept5";      // the name of the image file                                                                                                                                      
    nbinsx       = 20;                      // number of bins                                                                                                                                       
    xlow      = 0;                    // the low edge of x-axis                                                                                                                                     
    xup       = 20;                   // the upper edge of x-axis                                                                                                                                  
    options  = "printStat:plotSig:!plotData:plotLog:plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,                                                                              
    MakePlots(ev, var, cut * weightmc , cut , title, nbinsx, xlow, xup, plotname, plotdir, options);


    var = "Sum$(Jet_pt>25 && abs(Jet_eta)<2.5 && Jet_puId==1)-2";
    cut         = "";              // the selection cut                                                                                                                                             
    title    = ";num extra central jet";          // the title of the histogram                                                                                                                    
    plotname = "numcjet";      // the name of the image file                                                                                                                                      
    nbinsx       = 20;                      // number of bins                                                                                                                                       
    xlow      = 0;                    // the low edge of x-axis                                                                                                                                     
    xup       = 20;                   // the upper edge of x-axis                                                                                                                                  
    options  = "printStat:plotSig:!plotData:plotLog:plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,                                                                              
    MakePlots(ev, var, cut * weightmc , cut , title, nbinsx, xlow, xup, plotname, plotdir, options);



    var = "Jet_pt[aJCidx]";
    cut         = "";              // the selection cut                                                                                                                                             
    title    = ";pt leading add jet [GeV]";          // the title of the histogram                                                                                                                  
    plotname = "ptaddjet";      // the name of the image file                                                                                                                                      
    nbinsx       = 30;                      // number of bins                                                                                                                                       
    xlow      = 0;                    // the low edge of x-axis                                                                                                                                     
    xup       = 300;                   // the upper edge of x-axis                                                                                                                                  
    options  = "printStat:plotSig:!plotData:plotLog:plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,                                                                              
    MakePlots(ev, var, cut * weightmc , cut , title, nbinsx, xlow, xup, plotname, plotdir, options);




    var = "met_pt";
    cut         = "";              // the selection cut                                                                                                                                             
    title    = "metpt [GeV]";          // the title of the histogram                                                                                                                  
    plotname = "metpt";      // the name of the image file                                                                                                                                      
    nbinsx       = 30;                      // number of bins                                                                                                                                       
    xlow      = 0;                    // the low edge of x-axis                                                                                                                                     
    xup       = 300;                   // the upper edge of x-axis                                                                                                                                  
    options  = "printStat:plotSig:!plotData:plotLog:plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,                                                                              
    MakePlots(ev, var, cut * weightmc , cut , title, nbinsx, xlow, xup, plotname, plotdir, options);



    var = "(Jet_pt[]>25 && abs(Jet_eta)<4.5 && abs(Jet_eta)>2.5 &&  Jet_puId==1)";
    cut         = "";              // the selection cut                                                                                                                                             
    title    = ";num extra fwd jet";          // the title of the histogram                                                                                                                    
    plotname = "numfwjet";      // the name of the image file                                                                                                                                      
    nbinsx       = 20;                      // number of bins                                                                                                                                       
    xlow      = 0;                    // the low edge of x-axis                                                                                                                                     
    xup       = 20;                   // the upper edge of x-axis                                                                                                                                  
    options  = "printStat:plotSig:!plotData:plotLog:plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,                                                                              
    MakePlots(ev, var, cut * weightmc , cut , title, nbinsx, xlow, xup, plotname, plotdir, options);




    var = "min(Jet_btagCSV[hJCidx[0]], Jet_btagCSV[hJCidx[1]])";
    cut         = "";              // the selection cut
    title    = ";minCSV";          // the title of the histogram
    plotname = "minCSVNorm";      // the name of the image file
    nbinsx       = 20;                      // number of bins
    xlow      = 0;                    // the low edge of x-axis
    xup       = 1;                   // the upper edge of x-axis
    options  = "printStat:plotSig:!plotData:plotLog:plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,
    MakePlots(ev, var, cut * weightmc , cut , title, nbinsx, xlow, xup, plotname, plotdir, options);


    var      = "MinIf$(abs(deltaPhi(met_phi,Jet_phi)) , Jet_pt>25 && abs(Jet_eta)<4.5 && Jet_puId==1)";                // the variable to plot
    cut         = "";              // the selection cut
    title    = ";mindRjmet [GeV]";          // the title of the histogram
    plotname = "mindRjmetNorm";      // the name of the image file
    nbinsx       = 32;                      // number of bins
    xlow      = 0;                    // the low edge of x-axis
    xup       = 3.2;                   // the upper edge of x-axis
    options  = "printStat:plotSig:!plotData:plotLog:plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,
    MakePlots(ev, var, cut * weightmc , cut , title, nbinsx, xlow, xup, plotname, plotdir, options);





    var      = "BDTregular_125";                // the variable to plot
    cut         = "";              // the selection cut
    title    = "BDT score";          // the title of the histogram
    plotname = "bdtLog";      // the name of the image file
    nbinsx       = 15;                      // number of bins
    xlow      = -1;                    // the low edge of x-axis
    xup       = 1;                   // the upper edge of x-axis
    bool doRebin = true;
    options  = "printStat:plotSig:!plotData:plotLog:!plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,
    MakePlots(ev, var, cut * weightmc, cut , title, nbinsx, xlow, xup, plotname, plotdir, options, doRebin, 11 );




    var      = "BDTregular_125";                // the variable to plot
    cut         = "";              // the selection cut
    title    = "BDT score";          // the title of the histogram
    plotname = "bdtLogNorm";      // the name of the image file
    nbinsx       = 11;                      // number of bins
    xlow      = -1;                    // the low edge of x-axis
    xup       = 1;                   // the upper edge of x-axis
    options  = "printStat:plotSig:!plotData:plotLog:plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,
    MakePlots(ev, var, cut * weightmc, cut , title, nbinsx, xlow, xup, plotname, plotdir, options, doRebin,11);




    var      = "BDTregular_125";                // the variable to plot
    cut         = "";              // the selection cut
    title    = "BDT score";          // the title of the histogram
    plotname = "bdtLinNorm";      // the name of the image file
    nbinsx       = 11;                      // number of bins
    xlow      = -1;                    // the low edge of x-axis
    xup       = 1;                   // the upper edge of x-axis
    options  = "printStat:plotSig:!plotData:!plotLog:plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,
    MakePlots(ev, var, cut * weightmc, cut , title, nbinsx, xlow, xup, plotname, plotdir, options, doRebin,11);





    options  = "printStat:plotSig:!plotData:!plotLog:plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,
    plotname = "bdtNormZHvsTT";      // the name of the image file                                                                                                                                 
    // Using "ev->ZH" for ZH and "ev->ZjHF" for Z+HF
    MakePlot2(ev->ZH, ev->TT, var, cut * weightmc, title, nbinsx, xlow, xup, plotname, plotdir, options);



    var      = "BDTregular_125";                // the variable to plot
    cut         = "";              // the selection cut
    title    = "BDT score";          // the title of the histogram
    plotname = "bdtLin";      // the name of the image file
    nbinsx       = 15;                      // number of bins
    xlow      = -1;                    // the low edge of x-axis
    xup       = 1;                   // the upper edge of x-axis
    options  = "printStat:plotSig:!plotData:!plotLog:!plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,
    MakePlots(ev, var, cut * weightmc, cut , title, nbinsx, xlow, xup, plotname, plotdir, options, doRebin, 11);






    TString dcname    = "znnhbb_HighPt_13TeV.txt";   // the datacard name
    TString wsname    = plotdir + plotname +".root";                // the workspace name
    bool    useshapes = true;
    TString options1  = "unblind:SplusB";

    // For cut-and-count analysis, apply H.mass cut before calling MakeDatacard(...)
    MakeDatacard(channel, dcname, wsname, useshapes, options1);




    ev->read(  "MinIf$(abs(deltaPhi(met_phi,Jet_phi)) , Jet_pt>25 && abs(Jet_eta)<4.5 && Jet_puId==1)>1.5"   ,  "MinIf$(abs(deltaPhi(met_phi,Jet_phi)) , Jet_pt>25 && abs(Jet_eta)<4.5 && Jet_puId==1)>1.5", "" , "tree_ZnunuHighPt_ctrl"); 


    weightmc = "efflumi * weightTrig *  selectFlags[1] * sign(genWeight)";



    var      = "BDTregular_125";                // the variable to plot
    cut         = "";              // the selection cut
    title    = "BDT score";          // the title of the histogram
    plotname = "bdtZjLF";      // the name of the image file
    nbinsx       = 20;                      // number of bins
    xlow      = -1;                    // the low edge of x-axis
    xup       = 1;                   // the upper edge of x-axis
    options  = "printStat:plotSig:!plotData:!plotLog:!plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,

    MakePlots(ev, var, cut * weightmc, cut , title, nbinsx, xlow, xup, plotname, plotdir, options);



    weightmc = "efflumi * weightTrig * selectFlags[2] *  sign(genWeight)";



    var      = "BDTregular_125";                // the variable to plot
    cut         = "";              // the selection cut
    title    = "BDT score";          // the title of the histogram
    plotname = "bdtZjHF";      // the name of the image file
    nbinsx       = 20;                      // number of bins
    xlow      = -1;                    // the low edge of x-axis
    xup       = 1;                   // the upper edge of x-axis
    options  = "printStat:plotSig:!plotData:!plotLog:!plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,
    MakePlots(ev, var, cut * weightmc, cut , title, nbinsx, xlow, xup, plotname, plotdir, options);


    weightmc = "efflumi * weightTrig * selectFlags[3] * sign(genWeight)";


    var      = "BDTregular_125";                // the variable to plot
    cut         = "";              // the selection cut
    title    = "BDT score";          // the title of the histogram
    plotname = "bdtWjLF";      // the name of the image file
    nbinsx       = 20;                      // number of bins
    xlow      = -1;                    // the low edge of x-axis
    xup       = 1;                   // the upper edge of x-axis
    options  = "printStat:plotSig:!plotData:!plotLog:!plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,
    MakePlots(ev, var, cut * weightmc, cut , title, nbinsx, xlow, xup, plotname, plotdir, options);



    weightmc = "efflumi * weightTrig * selectFlags[4] * sign(genWeight)";


    var      = "BDTregular_125";                // the variable to plot
    cut         = "";              // the selection cut
    title    = "BDT score";          // the title of the histogram
    plotname = "bdtWjHF";      // the name of the image file
    nbinsx       = 20;                      // number of bins
    xlow      = -1;                    // the low edge of x-axis
    xup       = 1;                   // the upper edge of x-axis
    options  = "printStat:plotSig:!plotData:!plotLog:!plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,
    MakePlots(ev, var, cut * weightmc, cut , title, nbinsx, xlow, xup, plotname, plotdir, options);



    weightmc = "efflumi * weightTrig * selectFlags[5] * sign(genWeight)";


    var      = "BDTregular_125";                // the variable to plot
    cut         = "";              // the selection cut
    title    = "BDT score";          // the title of the histogram
    plotname = "bdtTT";      // the name of the image file
    nbinsx       = 20;                      // number of bins
    xlow      = -1;                    // the low edge of x-axis
    xup       = 1;                   // the upper edge of x-axis
    options  = "printStat:plotSig:!plotData:!plotLog:!plotNorm:!plotMonoH";    // use "!plotLog" to plot on log-y scale,
    MakePlots(ev, var, cut * weightmc, cut , title, nbinsx, xlow, xup, plotname, plotdir, options);





    

    /*

    ev->read(cutmc_all, cutdata_all);

    double vpt=150;
    double hpt=150;
    double mincsv=0.20;
    double jet1pt=80;
    double jet2pt=70;
    double   dPhiBB =1.3;
    int   najets =0;



    //	TCut  cut = "met_pt>150 && HCSV_pt>150 && min(hJets_btagCSV[0], hJets_btagCSV[1])>0.8 && Jet_pt[hJCidx[0]]>80 && Jet_pt[hJCidx[1]]>80  && Sum$(Jet_pt>30 && abs(Jet_eta)<4.5)<=2";
		
		int  nbinsx       = 20;                      // number of bins
		double xlow      = 80.0;                    // the low edge of x-axis
		double xup       = 160.0;                   // the upper edge of x-axis 
		TString var      = "H_mass";                // the variable to plot
		TString title    = ";Hmass [GeV]";          // the title of the histogram
		TString plotname = "All_hmass_tightcuts";      // the name of the image file
		TString options  = "printStat:plotSig:!plotData:!plotLog:!plotNorm";
		MakePlots(ev, var, cutmc_all, cutdata_all , title, nbinsx, xlow, xup, plotname, plotdir, options);




     for (vpt=150; vpt<400; vpt+=50 ) {
       //   for (hpt=150 ; hpt<400 ; hpt+=50 ) {
       //	for (mincsv=0.8 ; mincsv<=1.0 ; mincsv+=0.1) {
	    for (jet2pt=80 ; jet2pt<120 ; jet2pt+=20) {
	      for (jet1pt=90 ; jet1pt<140 ; jet1pt+=10) {


         //	      for (dPhiBB=1.3 ; dPhiBB<1.5 ; dPhiBB+=0.2) {
	      for (najets=0 ; najets<=2 ; najets+=1) {

	TCut  cut = Form("met_pt>%.2f && H_pt>%.2f && min(hJets_btagCSV[0], hJets_btagCSV[1])>%.2f && Jet_pt[hJCidx[0]]>%.2f && Jet_pt[hJCidx[1]]>%.2f  && Sum$(Jet_pt>30 && abs(Jet_eta)<2.5)<= (2 + %d) && deltaR_jj<1.3", vpt , 150., 0.8, jet1pt, jet2pt , najets);
		
		 nbinsx       = 20;                      // number of bins
		 xlow      = 80.0;                    // the low edge of x-axis
		 xup       = 160.0;                   // the upper edge of x-axis 
		 var      = "H_mass";                // the variable to plot
		 title    = ";Hmass [GeV]";          // the title of the histogram
		 plotname = "All_hmass_tightcuts";      // the name of the image file
		 options  = "printStat:plotSig:!plotData:!plotLog:!plotNorm";
		MakePlots(ev, var, cut, cut , title, nbinsx, xlow, xup, plotname, plotdir, options);

	      }
	    }
	  }
	}
     //}
     // }

     */


    // You can put in the parameters directly as in the following commented out line:
    //MakePlot(ev->ZH, "H.pt", cut, "; p_{T}(jj) [GeV]", 16, 0, 240., process + "_Hpt", plotdir, options);




    ////////////////////////////////////////////////////////////////////////////
    // Task 1 (b)                                                             //
    // - please comment out other tasks                                       //
    ////////////////////////////////////////////////////////////////////////////
/*
    // Read from ntuples
    Events * ev = new Events();
    TCut cutmc_all   = "Vtype==4";   // change this to your channel
    TCut cutdata_all = "Vtype==4";   // change this to your channel
    ev->read(cutmc_all, cutdata_all, "VH:ZJ");  // read both VH and ZJ processes

    TString var      = "H.mass";
    //TCut cut         = "V.pt>120";
    TCut cut         = "V.pt>120 && hJet_pt[0]>30 && hJet_pt[1]>30";  // for Wln, Znn, change to tighter cut
    TString title    = ";m(jj) [GeV]";
    TString plotname = "ZH_vs_ZJ_Hmass";
    int nbinsx       = 15;
    double xlow      = 30.0;
    double xup       = 255.0;
    TString options  = "!!plotLog:plotNorm";

    // Using "ev->ZH" for ZH and "ev->ZjHF" for Z+HF
    MakePlot2(ev->ZH, ev->ZjHF, var, cut, title, nbinsx, xlow, xup, plotname, plotdir, options);
*/

    ////////////////////////////////////////////////////////////////////////////
    // Task 2                                                                 //
    // - please comment out other tasks                                       //
    ////////////////////////////////////////////////////////////////////////////
/*
    // Zmm______________________________________________________________________
    //TString channel  = "Zmm";

    // These are loose cuts for all plots in this particular channel
    //TCut cutmc_all   = "Vtype==0 && V.pt>120 && hJet_pt[0]>20 && hJet_pt[1]>20 && abs(hJet_eta[0])<2.5 && abs(hJet_eta[1])<2.5 && hJet_id[0]==1 && hJet_id[1]==1 && hJet_puJetIdL[0]>0 && hJet_puJetIdL[1]>0 && vLepton_pt[0]>20 && vLepton_pt[1]>20 && abs(vLepton_eta[0])<2.4 && abs(vLepton_eta[1])<2.4 && METtype1corr.et<60 && 75<V.mass && V.mass<105 && H.dR<1.6 && hbhe==1";
    //cutmc_all       += "min(hJet_csv_nominal[0], hJet_csv_nominal[1])>0.4";  // tighter cut
    //TCut cutdata_all = cutmc_all;
    //cutmc_all       *= "weightTrig2012";  // apply trigger weight for MC

    // Scale factors in order of: WjLF, WjHF, ZjLF, ZjHF, TT
    // NOTE: WjLF, WjHF are not needed for Zll
    //double scalefactors[5] = {1.00, 1.00, 1.00, 1.00, 1.00};


    // Zee______________________________________________________________________
    //TString channel  = "Zee";

    // These are loose cuts for all plots in this particular channel
    //TCut cutmc_all   = "Vtype==1 && V.pt>120 && hJet_pt[0]>20 && hJet_pt[1]>20 && abs(hJet_eta[0])<2.5 && abs(hJet_eta[1])<2.5 && hJet_id[0]==1 && hJet_id[1]==1 && hJet_puJetIdL[0]>0 && hJet_puJetIdL[1]>0 && vLepton_pt[0]>20 && vLepton_pt[1]>20 && abs(vLepton_eta[0])<2.5 && abs(vLepton_eta[1])<2.5 && METtype1corr.et<60 && 75<V.mass && V.mass<105 && H.dR<1.6 && hbhe==1";
    //cutmc_all       += "min(hJet_csv_nominal[0], hJet_csv_nominal[1])>0.4";  // tighter cut
    //TCut cutdata_all = cutmc_all;
    //cutmc_all       *= "weightTrig2012";  // apply trigger weight for MC

    // Scale factors in order of: WjLF, WjHF, ZjLF, ZjHF, TT
    // NOTE: WjLF, WjHF are not needed for Zll
    //double scalefactors[5] = {1.00, 1.00, 1.00, 1.00, 1.00};


    // Wmn______________________________________________________________________
    //TString channel  = "Wmn";

    // These are loose cuts for all plots in this particular channel
    //TCut cutmc_all   = "Vtype==2 && H.pt>80 && hJet_pt[0]>30 && hJet_pt[1]>30 && abs(hJet_eta[0])<2.5 && abs(hJet_eta[1])<2.5 && hJet_id[0]==1 && hJet_id[1]==1 && hJet_puJetIdL[0]>0 && hJet_puJetIdL[1]>0 && vLepton_pt[0]>30 && abs(vLepton_eta[0])<2.4 && METtype1corr.et >45 && nalep==0 && Sum$(aJet_pt>20 && abs(aJet_eta)<4.5 && aJet_id==1 && aJet_puJetIdL>0)==0 && hbhe==1";
    //cutmc_all       += "min(hJet_csv_nominal[0], hJet_csv_nominal[1])>0.4 && abs(HVdPhi)>2.0";  // tighter cut
    //TCut cutdata_all = cutmc_all;
    //cutmc_all       *= "weightTrig2012";  // apply trigger weight for MC

    // Scale factors in order of: WjLF, WjHF, ZjLF, ZjHF, TT
    // NOTE: ZjLF, ZjHF are not needed for Wln
    //double scalefactors[5] = {1.00, 1.00, 1.00, 1.00, 1.00};


    // Wen______________________________________________________________________
    //TString channel  = "Wen";

    // These are loose cuts for all plots in this particular channel
    //TCut cutmc_all   = "Vtype==3 && H.pt>80 && hJet_pt[0]>30 && hJet_pt[1]>30 && abs(hJet_eta[0])<2.5 && abs(hJet_eta[1])<2.5 && hJet_id[0]==1 && hJet_id[1]==1 && hJet_puJetIdL[0]>0 && hJet_puJetIdL[1]>0 && vLepton_pt[0]>30 && abs(vLepton_eta[0])<2.5 && METtype1corr.et >45 && nalep==0 && Sum$(aJet_pt>20 && abs(aJet_eta)<4.5 && aJet_id==1 && aJet_puJetIdL>0)==0 && hbhe==1";
    //cutmc_all       += "min(hJet_csv_nominal[0], hJet_csv_nominal[1])>0.4 && abs(HVdPhi)>2.0";  // tighter cut
    //TCut cutdata_all = cutmc_all;
    //cutmc_all       *= "weightTrig2012";  // apply trigger weight for MC

    // Scale factors in order of: WjLF, WjHF, ZjLF, ZjHF, TT
    // NOTE: ZjLF, ZjHF are not needed for Wln
    //double scalefactors[5] = {1.00, 1.00, 1.00, 1.00, 1.00};


    // Znn______________________________________________________________________
    TString channel  = "Znn";

    // These are loose cuts for all plots in this particular channel
    TCut cutmc_all   = "Vtype==4 && H.pt>130 && hJet_pt[0]>80 && hJet_pt[1]>30 && abs(hJet_eta[0])<2.5 && abs(hJet_eta[1])<2.5 && hJet_id[0]==1 && hJet_id[1]==1 && hJet_puJetIdL[0]>0 && hJet_puJetIdL[1]>0 && nalep==0 && Sum$(aJet_pt>25 && abs(aJet_eta)<4.5 && aJet_id==1 && aJet_puJetIdL>0)==0 && min(Min$(abs(deltaPhi(METtype1corr.phi,hJet_phi))),Min$(abs(deltaPhiMETjets(METtype1corr.phi,aJet_phi,aJet_pt,aJet_eta)))+999*(Sum$(aJet_pt>25 && abs(aJet_eta)<4.5 && aJet_id==1 && aJet_puJetIdL>0)==0) )>0.5 && hbhe==1";
    cutmc_all       += "min(hJet_csv_nominal[0], hJet_csv_nominal[1])>0.4 && abs(HVdPhi)>2.0";  // tighter cut
    TCut cutdata_all = cutmc_all;
    cutmc_all       *= "(triggerFlags[42]==1 || triggerFlags[39]==1 || triggerFlags[41]==1) && hbhe && ecalFlag && cschaloFlag && hcallaserFlag && trackingfailureFlag && eebadscFlag && !isBadHcalEvent"; // apply trigger bits and MET cleaning for MC (they are already applied on data)
    cutmc_all       *= "triggercorrMET(METtype1corr.et)";

    // Scale factors in order of: WjLF, WjHF, ZjLF, ZjHF, TT
    double scalefactors[5] = {1.00, 1.00, 1.00, 1.00, 1.00};


    // All channels_____________________________________________________________
    // Read from ntuples
    Events * ev = new Events();
    ev->read(cutmc_all, cutdata_all);

    // Set the scale factors
    ev->set_sf(scalefactors);

    // Optimize these five variables (default: recommendations for Zll)
    //double vpt    = 150.;
    //double hpt    = 0.;
    //double maxcsv = 0.6720;
    //double mincsv = 0.5;
    //double dPhi   = 0.;

    // Optimize these five variables (default: recommendations for Wln)
    //double vpt    = 150.;
    //double hpt    = 100.;
    //double maxcsv = 0.8920;
    //double mincsv = 0.5;
    //double dPhi   = 2.95;

    // Optimize these five variables (default: recommendations for Znn)
    double vpt    = 170.;  // for Znn, pT(V) = MET
    double hpt    = 170.;
    double maxcsv = 0.8920;
    double mincsv = 0.5;
    double dPhi   = 2.95;

    // If doing cut and count analysis, cut on H.mass by changing the values of minhmass and maxhmass
    //double minhmass = 0.;
    //double maxhmass = 9999.;
    double minhmass = 110.;
    double maxhmass = 140.;

    // These are tight cuts for this particular plot
    TCut cutmc = Form("V.pt>%.2f && H.pt>%.2f && max(hJet_csv_nominal[0],hJet_csv_nominal[1])>%.3f && min(hJet_csv_nominal[0], hJet_csv_nominal[1])>%.3f && abs(HVdPhi)>%.2f && %.2f<H.mass && H.mass<%.2f", vpt, hpt, maxcsv, mincsv, dPhi, minhmass, maxhmass);
    TCut cutdata = cutmc;

    TString var      = "H.mass";
    TString title    = ";m(jj) [GeV]";
    TString plotname = channel + "_Hmass";
    int nbinsx       = 15;
    double xlow      = 30.0;
    double xup       = 255.0;
    TString options  = "printStat:plotSig:!plotData:!!plotLog";

    MakePlots(ev, var, cutmc, cutdata, title, nbinsx, xlow, xup, plotname, plotdir, options);

    // Or, just put in them directly as in the following commented out line:
    //MakePlots(ev, "H.mass", cutmc, cutdata, "m(jj) [GeV]", 15, 30.0, 255.0, channel+"_Hmass", plotdir, "printStat:plotSig:!plotData:!!plotLog");
*/

    ////////////////////////////////////////////////////////////////////////////
    // Task 3                                                                 //
    // - please comment out other tasks, but keep Task 2                      //
    ////////////////////////////////////////////////////////////////////////////
/*
    TString dcname    = Form("vhbb_%s_8TeV.txt", channel.Data());   // the datacard name
    TString wsname    = plotdir + plotname +".root";                // the workspace name
    bool    useshapes = false;
    TString options1  = "!unblind:SplusB";

    // For cut-and-count analysis, apply H.mass cut before calling MakeDatacard(...)
    MakeDatacard(channel, dcname, wsname, useshapes, options1);


    // For shape analysis, remove H.mass cut before calling MakeDatacard(...)
    //cutmc = Form("V.pt>%.2f && H.pt>%.2f && max(hJet_csv_nominal[0],hJet_csv_nominal[1])>%.3f && min(hJet_csv_nominal[0], hJet_csv_nominal[1])>%.3f && abs(HVdPhi)>%.2f", vpt, hpt, maxcsv, mincsv, dPhi);
    //cutdata = cutmc;
    //plotname = channel + "_Hmass_shapes";
    //MakePlots(ev, var, cutmc, cutdata, title, nbinsx, xlow, xup, plotname, plotdir, options);

    //dcname    = Form("vhbb_shapes_%s_8TeV.txt", channel.Data());    // the datacard name
    //wsname    = plotdir + plotname +".root";                        // the workspace name
    //useshapes = true;
    //options1  = "unblind:SplusB";
    //MakeDatacard(channel, dcname, wsname, useshapes, options1);
*/

}