Ejemplo n.º 1
0
//Setup camera events and stream.
void HandleCameraPlugged(unsigned long UniqueId)
{
    if(!GCamera.UID && !GCamera.Abort)
    {
        GCamera.UID = UniqueId;    
      
        if(CameraSetup())
        {
            printf("Camera %lu opened\n",UniqueId);   
            
            // setup event channel
            if(EventSetup())
			{
				// start streaming from the camera
				if (!CameraStart())
					GCamera.Abort = true;
			}
			else
				GCamera.Abort = true;
        }
        else
		{
            //failure. signal main thread to abort
			GCamera.Abort = true;
		}
    }  
}
Ejemplo n.º 2
0
//------------------------------------------------------------------------------
// Loop
//------------------------------------------------------------------------------
void AnalysisMonoH::Loop(TString analysis, TString filename, float luminosity)
{
  if (fChain == 0) return;

  Setup(analysis, filename, luminosity);


  // Define histograms
  //----------------------------------------------------------------------------
  for (int j=0; j<ncut; j++) {

    for (int k=0; k<=njetbin; k++) {

      TString sbin = (k < njetbin) ? Form("/%djet", k) : "";

      TString directory = scut[j] + sbin;

      root_output->cd();

      if (k < njetbin) gDirectory->mkdir(directory);

      root_output->cd(directory);

      for (int i=ee; i<=ll; i++) {

	TString suffix = "_" + schannel[i];

	DefineHistograms(i, j, k, suffix);

	h_fullpmet         [i][j][k] = new TH1D("h_fullpmet"        + suffix, "", 1000, 0.,  1000);
	h_trkpmet          [i][j][k] = new TH1D("h_trkpmet"         + suffix, "", 1000, 0.,  1000);
        h_deltarl1met      [i][j][k] = new TH1D("h_deltarl1met"     + suffix, "",  100, 0.,     5);
        h_deltarl2met      [i][j][k] = new TH1D("h_deltarl2met"     + suffix, "",  100, 0.,     5);
        h_deltarllmet      [i][j][k] = new TH1D("h_deltarllmet"     + suffix, "",  100, 0.,     5);
	h_deltarjet1met    [i][j][k] = new TH1D("h_deltarjet1met"   + suffix, "",  100, 0.,     5);
	h_deltarjet2met    [i][j][k] = new TH1D("h_deltarjet2met"   + suffix, "",  100, 0.,     5);
	h_deltarjj         [i][j][k] = new TH1D("h_deltarjj"        + suffix, "",  100, 0.,     5);
	h_deltarjjmet      [i][j][k] = new TH1D("h_deltarjjmet"     + suffix, "",  100, 0.,     5);
	h_deltarlep1jet1   [i][j][k] = new TH1D("h_deltarlep1jet1"  + suffix, "",  100, 0.,     5);
	h_deltarlep1jet2   [i][j][k] = new TH1D("h_deltarlep1jet2"  + suffix, "",  100, 0.,     5);
	h_deltarlep2jet1   [i][j][k] = new TH1D("h_deltarlep2jet1"  + suffix, "",  100, 0.,     5);
	h_deltarlep2jet2   [i][j][k] = new TH1D("h_deltarlep2jet2"  + suffix, "",  100, 0.,     5);
       	h_mllstar          [i][j][k] = new TH1D("h_mllstar"         + suffix, "", 3000, 0.,  3000);
       	//h_mnunu            [i][j][k] = new TH1D("h_mnunu"           + suffix, "",   10, 0.,    10);
	h_mr             [i][j][k] = new TH1D("h_mr"              + suffix, "", 2000, 0.,  2000);

	//h_met_m2l         [i][j][k] = new TH2D("h_met_m2l"        + suffix, "", 200,  0,  2000,  100,   0, 200);
	//h_met_deltaphill  [i][j][k] = new TH2D("h_met_deltaphill" + suffix, "", 200,  0,  2000,  100,   0,   5);     
      }
    }
  }

  root_output->cd();
  

  // Loop over events
  //----------------------------------------------------------------------------
  for (Long64_t jentry=0; jentry<_nentries;jentry++) {

    Long64_t ientry = LoadTree(jentry);

    if (ientry < 0) break;

    fChain->GetEntry(jentry);

    PrintProgress(jentry, _nentries);

    EventSetup();


    // Analysis
    //--------------------------------------------------------------------------
    //if (Lepton1.flavour * Lepton2.flavour > 0) continue;
    //if (Lepton1.v.Pt() < 20.) continue;
    //if (Lepton2.v.Pt() < 20.) continue;

    // Let's trust our ntuples
    //--------------------------------------------------------------------------
    if (std_vector_lepton_flavour->at(0)*std_vector_lepton_flavour->at(1) > 0) continue;
    if (std_vector_lepton_pt->at(0) < 20.) continue; 
    if (std_vector_lepton_pt->at(1) < 20.) continue; 
    if (std_vector_lepton_pt->at(2) > 10.) continue; 

    _nelectron = 0;

    if (abs(Lepton1.flavour) == ELECTRON_FLAVOUR) _nelectron++;
    if (abs(Lepton2.flavour) == ELECTRON_FLAVOUR) _nelectron++;

    if      (_nelectron == 2) _channel = ee;
    else if (_nelectron == 1) _channel = em;
    else if (_nelectron == 0) _channel = mm;
    
    _m2l  = mll;
    _pt2l = ptll;


    // Fill histograms
    //--------------------------------------------------------------------------
    bool pass = true;

    // WW cuts   
    FillLevelHistograms(MonoH_00_Has2Leptons, pass);

    pass &= (mll > 12.);
    FillLevelHistograms(MonoH_01_Mll, pass);
    
    pass &= (MET.Et() > 20.);
    FillLevelHistograms(MonoH_02_PfMet, pass);

    bool pass_zveto = (_nelectron == 1 || fabs(mll - Z_MASS) > 15.);
    FillLevelHistograms(MonoH_03_ZVeto, pass && pass_zveto);

    pass &= (mpmet > 45. || (_nelectron == 1 && mpmet > 45.));
    FillLevelHistograms(MonoH_04_MpMet, pass && pass_zveto);

    pass &= (_passdphiveto);
    FillLevelHistograms(MonoH_05_DPhiVeto, pass && pass_zveto);

    pass &= (_nelectron == 1 && ptll > 30. || _nelectron != 1 && ptll > 45.);
    FillLevelHistograms(MonoH_06_Ptll, pass && pass_zveto);

    bool passTopCR = pass && _nbjet20cmvav2l == 1;

    pass &= (_nbjet20cmvav2l == 0);
    FillLevelHistograms(MonoH_07_BVeto, pass && pass_zveto);

    if (_saveminitree && pass && pass_zveto) minitree->Fill();

    //ZH->4l Control Region
    if (AnalysisLeptons[2].v.Pt() > 0 || AnalysisLeptons[3].v.Pt() > 0 ){
      //cout<<"I passed! :)"<<endl;
      
      bool passZHCR = ( (fabs(_mll13 - Z_MASS) < 15. || fabs(_mll23 - Z_MASS) < 15. || fabs(_mll14 - Z_MASS) < 15. || fabs(_mll24 - Z_MASS) < 15. || fabs(_mll34 - Z_MASS) < 15.) && AnalysisLeptons[2].v.Pt() > 20. && AnalysisLeptons[3].v.Pt() > 20.);
      
      FillLevelHistograms(MonoH_08_ZHCR, passZHCR);
      // cout<<"Lepton 3 pT = "<<std_vector_lepton_pt->at(2)<<endl;
      // cout<<"Lepton 4 pT = "<<std_vector_lepton_pt->at(3)<<endl;
      // cout<<"-------------------------------------------"<<endl;
    }

    FillLevelHistograms(MonoH_09_TopCR, passTopCR && pass_zveto);

    //    pass &= (!_foundsoftmuon);
    //    FillLevelHistograms(MonoH_08_SoftMu, pass && pass_zveto);

    // monoH cuts                                                         
    // bool pass_monoh = (pass && pass_zveto);
    // bool pass_drll = (Lepton1.v.DeltaR(Lepton2.v) < 1.5);

    // FillLevelHistograms(MonoH_103_CR, pass_monoh && !pass_drll);

    // pass_monoh &= (_mc < 100.);
    // FillLevelHistograms(MonoH_100_Mc, pass_monoh);
   
    // pass_monoh &= pass_drll;                                                                       
    // FillLevelHistograms(MonoH_101_DRll, pass_monoh); 
  
    // pass_monoh &= (mpmet > 60.);
    // FillLevelHistograms(MonoH_102_MpMet, pass_monoh);

    // pass_monoh &= (mpmet > 100.);
    // FillLevelHistograms(MonoH_09_mpmet100, pass_monoh);

    // pass_monoh &= (mth > 200.);
    // FillLevelHistograms(MonoH_10_mth200, pass_monoh);

    // pass_monoh &= (Lepton1.v.DeltaPhi(MET) > 2.6);
    // FillLevelHistograms(MonoH_11_dphil1met, pass_monoh);

    // pass_monoh &= (Lepton2.v.DeltaPhi(MET) > 2.6);
    // FillLevelHistograms(MonoH_12_dphil2met, pass_monoh);

    // pass_monoh &= (drll < 0.8);
    // FillLevelHistograms(MonoH_13_deltarll, pass_monoh);

    // pass_monoh &= (mtw1 > 160.);
    // FillLevelHistograms(MonoH_14_mtw1, pass_monoh);

    // pass_monoh &= (mtw2 > 100.);
    // FillLevelHistograms(MonoH_15_mtw2, pass_monoh);

    // pass_monoh &= (metTtrk > 100.);
    // FillLevelHistograms(MonoH_16_trkmet, pass_monoh);

  }

  EndJob();
}
Ejemplo n.º 3
0
//------------------------------------------------------------------------------
// Loop
//------------------------------------------------------------------------------
void AnalysisControl::Loop(TString analysis, TString filename, float luminosity)
{
  if (fChain == 0) return;

  Setup(analysis, filename, luminosity);


  // Define histograms
  //----------------------------------------------------------------------------
  root_output->cd();

  for (int j=0; j<ncut; j++) {

    for (int k=0; k<=njetbin; k++) {

      TString sbin = (k < njetbin) ? Form("/%djet", k) : "";

      TString directory = scut[j] + sbin;

      root_output->cd();

      if (k < njetbin) gDirectory->mkdir(directory);

      root_output->cd(directory);

      for (int i=ee; i<=ll; i++) {

	TString suffix = "_" + schannel[i];

	DefineHistograms(i, j, k, suffix);
      }
    }
  }

  root_output->cd();


  // Loop over events
  //----------------------------------------------------------------------------
  for (Long64_t jentry=0; jentry<_nentries;jentry++) {

    Long64_t ientry = LoadTree(jentry);

    if (ientry < 0) break;

    fChain->GetEntry(jentry);

    PrintProgress(jentry, _nentries);

    EventSetup();


    // Analysis
    //--------------------------------------------------------------------------
    _nelectron = 0;

    if (abs(Lepton1.flavour) == ELECTRON_FLAVOUR) _nelectron++;
    if (abs(Lepton2.flavour) == ELECTRON_FLAVOUR) _nelectron++;

    if      (_nelectron == 2) _channel = ee;
    else if (_nelectron == 1) _channel = em;
    else if (_nelectron == 0) _channel = mm;
    
    _m2l  = mll;   // Needs l2Sel
    _pt2l = ptll;  // Needs l2Sel

    bool pass_2l = (Lepton1.flavour * Lepton2.flavour < 0);

    pass_2l &= (Lepton1.v.Pt() > 25.);
    pass_2l &= (Lepton2.v.Pt() > 20.);
    pass_2l &= (std_vector_lepton_pt->at(2) < 10.);
    pass_2l &= (_m2l > 20.);


    bool pass;


    // No cuts
    //--------------------------------------------------------------------------
    pass = true;

    FillLevelHistograms(Control_00_NoCuts, pass);


    // Has 2 tight leptons
    //--------------------------------------------------------------------------
    pass = pass_2l;

    FillLevelHistograms(Control_01_TwoLeptons, pass);

    if (_saveminitree && pass) minitree->Fill();


    // R out/in
    //--------------------------------------------------------------------------
    pass = pass_2l;

    pass &= (_nbjet30csvv2m > 0);

    FillLevelHistograms(Control_02_Routin, pass);


    // WW
    // https://github.com/latinos/PlotsConfigurations/blob/master/Configurations/ControlRegions/WW/Full2016/cuts.py
    //--------------------------------------------------------------------------
    pass =
      mll > 80                         &&
      std_vector_lepton_pt->at(0) > 25 &&
      std_vector_lepton_pt->at(1) > 13 &&
      std_vector_lepton_pt->at(2) < 10 &&
      metPfType1 > 20                  &&
      ptll > 30                        &&
      mth >= 60	                       &&
      (std_vector_jet_pt->at(0) < 20 || std_vector_jet_cmvav2->at(0) < -0.5884) &&
      (std_vector_jet_pt->at(1) < 20 || std_vector_jet_cmvav2->at(1) < -0.5884) &&
      (std_vector_jet_pt->at(2) < 20 || std_vector_jet_cmvav2->at(2) < -0.5884) &&
      (std_vector_jet_pt->at(3) < 20 || std_vector_jet_cmvav2->at(3) < -0.5884) &&
      (std_vector_jet_pt->at(4) < 20 || std_vector_jet_cmvav2->at(4) < -0.5884) &&
      (std_vector_jet_pt->at(5) < 20 || std_vector_jet_cmvav2->at(5) < -0.5884) &&
      (std_vector_jet_pt->at(6) < 20 || std_vector_jet_cmvav2->at(6) < -0.5884) &&
      (std_vector_jet_pt->at(7) < 20 || std_vector_jet_cmvav2->at(7) < -0.5884) &&
      (std_vector_jet_pt->at(8) < 20 || std_vector_jet_cmvav2->at(8) < -0.5884) &&
      (std_vector_jet_pt->at(9) < 20 || std_vector_jet_cmvav2->at(9) < -0.5884);

    FillLevelHistograms(Control_03_WW, pass);

    if (pass) EventDump();


    // Top
    //--------------------------------------------------------------------------
    pass = pass_2l;

    pass &= (_njet > 1);
    pass &= (_nbjet30csvv2m > 0);
    pass &= (_channel == em || fabs(_m2l - Z_MASS) > 15.);
    pass &= (MET.Et() > 45.);

    FillLevelHistograms(Control_04_Top, pass);
  }


  EndJob();
}
Ejemplo n.º 4
0
//------------------------------------------------------------------------------
// Loop
//------------------------------------------------------------------------------
void AnalysisPR::Loop(TString analysis, TString filename, float luminosity)
{
  if (fChain == 0) return;

  Setup(analysis, filename, luminosity);

  root_output->cd();
  

  // Define prompt rate histograms
  //----------------------------------------------------------------------------
  h_Muon_loose_pt_eta_PR = new TH2D("h_Muon_loose_pt_eta_PR", "", nptbin, ptbins, netabin, etabins);
  h_Muon_tight_pt_eta_PR = new TH2D("h_Muon_tight_pt_eta_PR", "", nptbin, ptbins, netabin, etabins);
  h_Ele_loose_pt_eta_PR  = new TH2D("h_Ele_loose_pt_eta_PR",  "", nptbin, ptbins, netabin, etabins);
  h_Ele_tight_pt_eta_PR  = new TH2D("h_Ele_tight_pt_eta_PR",  "", nptbin, ptbins, netabin, etabins);
    
  h_Muon_loose_pt_PR = new TH1D("h_Muon_loose_pt_PR", "", nptbin, ptbins);
  h_Muon_tight_pt_PR = new TH1D("h_Muon_tight_pt_PR", "", nptbin, ptbins);
  h_Ele_loose_pt_PR  = new TH1D("h_Ele_loose_pt_PR",  "", nptbin, ptbins);
  h_Ele_tight_pt_PR  = new TH1D("h_Ele_tight_pt_PR",  "", nptbin, ptbins);
    
  h_Muon_loose_eta_PR = new TH1D("h_Muon_loose_eta_PR", "", netabin, etabins);
  h_Muon_tight_eta_PR = new TH1D("h_Muon_tight_eta_PR", "", netabin, etabins);
  h_Ele_loose_eta_PR  = new TH1D("h_Ele_loose_eta_PR",  "", netabin, etabins);
  h_Ele_tight_eta_PR  = new TH1D("h_Ele_tight_eta_PR",  "", netabin, etabins);


  // Loop over events
  //----------------------------------------------------------------------------
  for (Long64_t jentry=0; jentry<_nentries;jentry++) {

    Long64_t ientry = LoadTree(jentry);

    if (ientry < 0) break;

    fChain->GetEntry(jentry);

    PrintProgress(jentry, _nentries);

    EventSetup();

    _channel = (abs(Lepton1.flavour) == ELECTRON_FLAVOUR) ? e : m;

    _leptonPtMin  = (_channel == e) ?  13 :  10;
    _leptonEtaMax = (_channel == e) ? 2.5 : 2.4;

    if (Lepton1.v.Pt()        < _leptonPtMin)  continue;
    if (fabs(Lepton1.v.Eta()) > _leptonEtaMax) continue;


    // Make Z candidate
    //--------------------------------------------------------------------------
    _Zlepton1type = Loose;
    _Zlepton2type = Loose;

    _m2l = -999;
    
    if (AnalysisLeptons.size() >= 2) { 
      
      for (int iLep1=0; iLep1<AnalysisLeptons.size(); iLep1++) {
	
	if (AnalysisLeptons[iLep1].v.Pt() < 10.) continue;
	
	for (int iLep2=iLep1+1; iLep2<AnalysisLeptons.size(); iLep2++) {
	  
	  if (AnalysisLeptons[iLep2].v.Pt() < 10.) continue;
	  
	  if ((AnalysisLeptons[iLep1].flavour + AnalysisLeptons[iLep2].flavour) != 0.) continue;
	  
	  float inv_mass = (AnalysisLeptons[iLep1].v + AnalysisLeptons[iLep2].v).M();
	  
	  if (_m2l < 0 || fabs(inv_mass - Z_MASS) < fabs(_m2l - Z_MASS)) {
	    
	    _m2l = inv_mass;

	    // Is the first Z lepton tight?
	    if (AnalysisLeptons[iLep1].type > 0.5 && AnalysisLeptons[iLep1].flavour == ELECTRON_FLAVOUR)
	      {
		_Zlepton1type  = Tight;
		_Zdecayflavour = ELECTRON_FLAVOUR;
	      }
	    else if (AnalysisLeptons[iLep1].type > 0.5 && AnalysisLeptons[iLep1].flavour == MUON_FLAVOUR)
	      {
		_Zlepton1type  = Tight;
		_Zdecayflavour = MUON_FLAVOUR;
	      }

	    
	    // Is the second Z lepton tight?
	    if (AnalysisLeptons[iLep2].type > 0.5 && AnalysisLeptons[iLep2].flavour == ELECTRON_FLAVOUR)
	      {
		_Zlepton2type = Tight;
	      }
	    else if (AnalysisLeptons[iLep2].type > 0.5 && AnalysisLeptons[iLep2].flavour == MUON_FLAVOUR)
	      {
		_Zlepton2type = Tight;
	      }
	  }
	}
      }
    }
    

    // Get the event weight
    //--------------------------------------------------------------------------
    bool passTrigger;

    if (_ismc) {

      passTrigger = true;

      _event_weight = (baseW / 1e3) * puW;

      if (GEN_weight_SM) _event_weight *= GEN_weight_SM / abs(GEN_weight_SM);


      // Muons
      //------------------------------------------------------------------------
      if (_channel == m)
	{
	  (Lepton1.v.Pt() <= 20.) ? _event_weight *= 7.339 : _event_weight *= 217.553;  // For 36/fb
	}

      
      // Electrons
      //------------------------------------------------------------------------
      if (_channel == e)
	{
	  (Lepton1.v.Pt() <= 25.) ? _event_weight *= 14.888 : _event_weight *= 63.046;
	}

    } else {

      _event_weight = 1.0;

      passTrigger = false;


      // Muons
      //------------------------------------------------------------------------
      if (_sample.Contains("DoubleMuon") && _channel == m) {

	if (Lepton1.v.Pt() <= 20. && std_vector_trigger->at(22)) {  // HLT_Mu8_TrkIsoVVL_v*

	  passTrigger = true;

	} else if (Lepton1.v.Pt() > 20. && std_vector_trigger->at(23)) {  // HLT_Mu17_TrkIsoVVL_v*

	  passTrigger = true;
	}
      }


      // Electrons
      //------------------------------------------------------------------------
      if (_sample.Contains("DoubleEG") && _channel == e) {
	
	if (Lepton1.v.Pt() <= 25. && std_vector_trigger->at(31)) {  // HLT_Ele12_CaloIdL_TrackIdL_IsoVL_PFJet30_v*

	  passTrigger = true;
	  
	} else if (Lepton1.v.Pt() > 25. && std_vector_trigger->at(33)) {  // HLT_Ele23_CaloIdL_TrackIdL_IsoVL_PFJet30_v*

	  passTrigger = true;
	}
      }
    }


    // Prompt rate from MC
    //--------------------------------------------------------------------------
    bool pass = true;

    pass &= (76. < _m2l && 106. > _m2l);
    pass &= (_mtw < 20.);
    
    if (pass && _sample.Contains("DYJetsToLL") && _Zlepton1type == Tight) {

      float Zlep2pt  = std_vector_lepton_pt->at(1);
      float Zlep2eta = fabs(std_vector_lepton_eta->at(1));
      
      if (fabs(_Zdecayflavour) == ELECTRON_FLAVOUR) {
      
	h_Ele_loose_pt_eta_PR->Fill(Zlep2pt, Zlep2eta, _event_weight);
	h_Ele_loose_pt_PR    ->Fill(Zlep2pt,  _event_weight);
	h_Ele_loose_eta_PR   ->Fill(Zlep2eta, _event_weight);
	
	if (_Zlepton2type == Tight) {
      
	  h_Ele_tight_pt_eta_PR->Fill(Zlep2pt, Zlep2eta, _event_weight);
	  h_Ele_tight_pt_PR    ->Fill(Zlep2pt,  _event_weight);
	  h_Ele_tight_eta_PR   ->Fill(Zlep2eta, _event_weight);
	}

      }	else if (fabs(_Zdecayflavour) == MUON_FLAVOUR) {

	h_Muon_loose_pt_eta_PR->Fill(Zlep2pt, Zlep2eta, _event_weight);
	h_Muon_loose_pt_PR    ->Fill(Zlep2pt,  _event_weight);
	h_Muon_loose_eta_PR   ->Fill(Zlep2eta, _event_weight);

	if (_Zlepton2type == Tight) {
	  
	  h_Muon_tight_pt_eta_PR->Fill(Zlep2pt, Zlep2eta, _event_weight);
	  h_Muon_tight_pt_PR    ->Fill(Zlep2pt,  _event_weight);
	  h_Muon_tight_eta_PR   ->Fill(Zlep2eta, _event_weight);
	}
      }
    }
  }

  EndJob();
}
Ejemplo n.º 5
0
//------------------------------------------------------------------------------
// Loop
//------------------------------------------------------------------------------
void AnalysisFR::Loop(TString analysis, TString filename, float luminosity)
{
  if (fChain == 0) return;

  Setup(analysis, filename, luminosity);

  // Define fake rate histograms
  //----------------------------------------------------------------------------
  for (int i=0; i<ncut; i++) {
    
    TString directory = scut[i];
    
    root_output->cd();
    
    gDirectory->mkdir(directory);
    
    root_output->cd(directory);
    
    for (int j=0; j<njetet; j++) {
      
      TString muonsuffix = Form("_%.0fGeV", muonjetet[j]);
      TString elesuffix  = Form("_%.0fGeV", elejetet[j]);
      
      h_Muon_loose_pt_eta_bin[i][j] = new TH2D("h_Muon_loose_pt_eta_bin" + muonsuffix, "", nptbin, ptbins, netabin, etabins);
      h_Muon_tight_pt_eta_bin[i][j] = new TH2D("h_Muon_tight_pt_eta_bin" + muonsuffix, "", nptbin, ptbins, netabin, etabins);
      h_Ele_loose_pt_eta_bin [i][j] = new TH2D("h_Ele_loose_pt_eta_bin"  + elesuffix,  "", nptbin, ptbins, netabin, etabins);
      h_Ele_tight_pt_eta_bin [i][j] = new TH2D("h_Ele_tight_pt_eta_bin"  + elesuffix,  "", nptbin, ptbins, netabin, etabins);
      
      h_Muon_loose_pt_bin[i][j] = new TH1D("h_Muon_loose_pt_bin" + muonsuffix, "", nptbin, ptbins);
      h_Muon_tight_pt_bin[i][j] = new TH1D("h_Muon_tight_pt_bin" + muonsuffix, "", nptbin, ptbins);
      h_Ele_loose_pt_bin [i][j] = new TH1D("h_Ele_loose_pt_bin"  + elesuffix,  "", nptbin, ptbins);
      h_Ele_tight_pt_bin [i][j] = new TH1D("h_Ele_tight_pt_bin"  + elesuffix,  "", nptbin, ptbins);
      
      h_Muon_loose_eta_bin[i][j] = new TH1D("h_Muon_loose_eta_bin" + muonsuffix, "", netabin, etabins);
      h_Muon_tight_eta_bin[i][j] = new TH1D("h_Muon_tight_eta_bin" + muonsuffix, "", netabin, etabins);
      h_Ele_loose_eta_bin [i][j] = new TH1D("h_Ele_loose_eta_bin"  + elesuffix,  "", netabin, etabins);
      h_Ele_tight_eta_bin [i][j] = new TH1D("h_Ele_tight_eta_bin"  + elesuffix,  "", netabin, etabins);
	
      h_Muon_loose_pt[i][j] = new TH1D("h_Muon_loose_pt" + muonsuffix, "", 1000, 0, 200);
      h_Muon_tight_pt[i][j] = new TH1D("h_Muon_tight_pt" + muonsuffix, "", 1000, 0, 200);
      h_Ele_loose_pt [i][j] = new TH1D("h_Ele_loose_pt"  + elesuffix,  "", 1000, 0, 200);
      h_Ele_tight_pt [i][j] = new TH1D("h_Ele_tight_pt"  + elesuffix,  "", 1000, 0, 200);
      
      h_Muon_loose_mtw[i][j] = new TH1D("h_Muon_loose_mtw" + muonsuffix, "", 1000, 0, 200);
      h_Muon_tight_mtw[i][j] = new TH1D("h_Muon_tight_mtw" + muonsuffix, "", 1000, 0, 200);
      h_Ele_loose_mtw [i][j] = new TH1D("h_Ele_loose_mtw"  + elesuffix,  "", 1000, 0, 200);
      h_Ele_tight_mtw [i][j] = new TH1D("h_Ele_tight_mtw"  + elesuffix,  "", 1000, 0, 200);
	
      h_Muon_loose_m2l[i][j] = new TH1D("h_Muon_loose_m2l" + muonsuffix, "", 1000, 0, 200);
      h_Muon_tight_m2l[i][j] = new TH1D("h_Muon_tight_m2l" + muonsuffix, "", 1000, 0, 200);
      h_Ele_loose_m2l [i][j] = new TH1D("h_Ele_loose_m2l"  + elesuffix,  "", 1000, 0, 200);
      h_Ele_tight_m2l [i][j] = new TH1D("h_Ele_tight_m2l"  + elesuffix,  "", 1000, 0, 200);
      
      
      // Define effective luminosity estimation histograms
      //------------------------------------------------------------------------
      h_Muon_loose_pt_m2l[i][j] = new TH2D("h_Muon_loose_pt_m2l" + muonsuffix, "", 200, 0, 200, nptbin, ptbins);
      h_Muon_tight_pt_m2l[i][j] = new TH2D("h_Muon_tight_pt_m2l" + muonsuffix, "", 200, 0, 200, nptbin, ptbins);
      h_Ele_loose_pt_m2l [i][j] = new TH2D("h_Ele_loose_pt_m2l"  + elesuffix,  "", 200, 0, 200, nptbin, ptbins);
      h_Ele_tight_pt_m2l [i][j] = new TH2D("h_Ele_tight_pt_m2l"  + elesuffix,  "", 200, 0, 200, nptbin, ptbins);
    }
  }
  
  root_output->cd();
  
  // Loop over events
  //----------------------------------------------------------------------------
  for (Long64_t jentry=0; jentry<_nentries;jentry++) {
    
    Long64_t ientry = LoadTree(jentry);
    
    if (ientry < 0) break;
    
    fChain->GetEntry(jentry);
    
    PrintProgress(jentry, _nentries);
    
    EventSetup();
    
    _channel = (abs(Lepton1.flavour) == ELECTRON_FLAVOUR) ? e : m;
    
    _leptonPtMin  = (_channel == e) ?  13 :  10;
    _leptonEtaMax = (_channel == e) ? 2.5 : 2.4;

    if (Lepton1.v.Pt()        < _leptonPtMin)  continue;
    if (fabs(Lepton1.v.Eta()) > _leptonEtaMax) continue;


    // Get the event weight
    //--------------------------------------------------------------------------
    bool passTrigger;

    if (_ismc) {

      passTrigger = true;

      Float_t corrected_baseW = baseW; 

      if (_sample.Contains("DYJetsToLL_M-10to50")) corrected_baseW = 0.829752445221; 
      if (_sample.Contains("DYJetsToLL_M-50"))     corrected_baseW = 0.318902641535;

      _base_weight = (corrected_baseW / 1e3) * puW6p3 * GEN_weight_SM / abs(GEN_weight_SM);

      _event_weight = _base_weight;


      // Muons
      //------------------------------------------------------------------------
      if (_channel == m)
	{
	  (Lepton1.v.Pt() <= 20.) ? _event_weight *= 5.86 : _event_weight *= 163.84;
	}

      
      // Electrons
      //------------------------------------------------------------------------
      if (_channel == e)
	{
	  (Lepton1.v.Pt() <= 25.) ? _event_weight *= 8.51 : _event_weight *= 42.34;
	}

    } else {

      _event_weight = 1.0;

      passTrigger = false;


      // Muons
      //------------------------------------------------------------------------
      if (_sample.Contains("DoubleMuon") && _channel == m) {

	if (Lepton1.v.Pt() <= 20. && std_vector_trigger->at(22)) {  // HLT_Mu8_TrkIsoVVL_v*

	  passTrigger = true;

	} else if (Lepton1.v.Pt() > 20. && std_vector_trigger->at(23)) {  // HLT_Mu17_TrkIsoVVL_v*

	  passTrigger = true;
	}
      }


      // Electrons
      //------------------------------------------------------------------------
      if (_sample.Contains("DoubleEG") && _channel == e) {
	
	if (Lepton1.v.Pt() <= 25. && std_vector_trigger->at(31)) {  // HLT_Ele12_CaloIdL_TrackIdL_IsoVL_PFJet30_v*

	  passTrigger = true;
	  
	} else if (Lepton1.v.Pt() > 25. && std_vector_trigger->at(33)) {  // HLT_Ele23_CaloIdL_TrackIdL_IsoVL_PFJet30_v*

	  passTrigger = true;
	}
      }
    }


    // Get the jets and the W transverse mass
    //--------------------------------------------------------------------------
    GetAwayJets();
    GetMt(Lepton1, _mtw);


    // Preselection
    //--------------------------------------------------------------------------
    if (!passTrigger) continue;

    if (AnalysisJets.size() < 1) continue;


    // Get histograms for different jet pt thresholds
    //--------------------------------------------------------------------------
    for (int i=0; i<njetet; i++) {

      _inputJetEt = (_channel == e) ? elejetet[i] : muonjetet[i];

      if (AnalysisJets[0].v.Pt() < _inputJetEt) continue; 


      // QCD region
      //------------------------------------------------------------------------
      bool pass;
      pass = (_nlepton == 1);

      FillLevelHistograms(FR_00_QCD, i, pass);

    }
  }
  

  EndJob();
}