From 2b820de91748925518f337841f240cd1c236d19d Mon Sep 17 00:00:00 2001
From: "tfarooque@ifae.es" <tfarooque@at305.pic.es>
Date: Sun, 28 Aug 2016 15:15:21 +0200
Subject: [PATCH 1/3] New options for ttccNLO weights, low-b regions, HT-slice
 correction

---
 Root/VLQ_Analysis_Data2015.cxx                |  81 +-
 .../macros_trisha/FakeTemplateValidation.cxx  | 988 ++++++++++++++++++
 macros/macros_trisha/LowBTemplateMaker.cxx    | 260 +++++
 macros/macros_trisha/VLQReclustering.cxx      | 781 ++++++++++++--
 macros/macros_trisha/mergeOutputs.sh          |   8 +-
 python/Submit_VLQAnalysis.py                  |  19 +-
 6 files changed, 2017 insertions(+), 120 deletions(-)
 create mode 100644 macros/macros_trisha/FakeTemplateValidation.cxx
 create mode 100644 macros/macros_trisha/LowBTemplateMaker.cxx

diff --git a/Root/VLQ_Analysis_Data2015.cxx b/Root/VLQ_Analysis_Data2015.cxx
index 433158b..39e89a2 100644
--- a/Root/VLQ_Analysis_Data2015.cxx
+++ b/Root/VLQ_Analysis_Data2015.cxx
@@ -268,7 +268,17 @@ VLQ_Analysis_Data2015::~VLQ_Analysis_Data2015()
       m_outMngrTree->AddStandardBranch("dRmin_mubjets", "#DeltaR_{min}(#mu, b-jets)", "D", &(m_outData->o_dRmin_mubjets));
       m_outMngrTree->AddStandardBranch("mT_bmin", "m_{T}^{min}(b-jets, MET)", "D", &(m_outData->o_mTbmin));
 
+      if(m_opt->DoLowBRegions()){
+	m_outMngrTree->AddStandardBranch("mbb_mindr_lowb_3b", "m_{inv}^{min#DeltaR} (lowb, 3b)", "D", &(m_outData->o_mbb_mindR_lowb_3b));
+	m_outMngrTree->AddStandardBranch("mbb_mindr_lowb_4b", "m_{inv}^{min#DeltaR} (lowb, 4b)", "D", &(m_outData->o_mbb_mindR_lowb_4b));
 
+	m_outMngrTree->AddStandardBranch("mT_bmin_lowb_3b", "m_{T}^{min}(b-jets, MET) (lowb, 3b)", "D", &(m_outData->o_mTbmin_lowb_3b));
+	m_outMngrTree->AddStandardBranch("mT_bmin_lowb_4b", "m_{T}^{min}(b-jets, MET) (lowb, 4b)", "D", &(m_outData->o_mTbmin_lowb_4b));
+
+	m_outMngrTree->AddStandardBranch("dRmin_bb_lowb_3b", "#DeltaR_{min}(b-jet, b-jet) (lowb, 3b)", "D", &(m_outData->o_dRmin_bjetbjet_lowb_3b));
+	m_outMngrTree->AddStandardBranch("dRmin_bb_lowb_4b", "#DeltaR_{min}(b-jet, b-jet) (lowb, 4b)", "D", &(m_outData->o_dRmin_bjetbjet_lowb_4b));
+
+      }
       m_outMngrTree->BookStandardTree("tree", "small tree");
 
     }//DumpTree
@@ -574,6 +584,10 @@ VLQ_Analysis_Data2015::~VLQ_Analysis_Data2015()
 	      m_anaTools -> BookAllHistograms("c1l2"+tagger+"6j1bLowMbb_4b"+subchannel, true);
 	      m_anaTools -> BookAllHistograms("c1l2"+tagger+"6j1bHighMbb_3b"+subchannel, true);
 	      m_anaTools -> BookAllHistograms("c1l2"+tagger+"6j1bHighMbb_4b"+subchannel, true);
+	      m_anaTools -> BookAllHistograms("c1l2"+tagger+"6j2bLowMbb_3b"+subchannel, true);
+	      m_anaTools -> BookAllHistograms("c1l2"+tagger+"6j2bLowMbb_4b"+subchannel, true);
+	      m_anaTools -> BookAllHistograms("c1l2"+tagger+"6j2bHighMbb_3b"+subchannel, true);
+	      m_anaTools -> BookAllHistograms("c1l2"+tagger+"6j2bHighMbb_4b"+subchannel, true);
 
 	      m_anaTools -> BookAllHistograms("c1l1"+tagger+"5j0b"+subchannel, true);
 	      m_anaTools -> BookAllHistograms("c1l1"+tagger+"6j0b"+subchannel, true);
@@ -587,6 +601,12 @@ VLQ_Analysis_Data2015::~VLQ_Analysis_Data2015()
 	      m_anaTools -> BookAllHistograms("c1l1"+tagger+"6j1bLowMbb_4b"+subchannel, true);
 	      m_anaTools -> BookAllHistograms("c1l1"+tagger+"6j1bHighMbb_3b"+subchannel, true);
 	      m_anaTools -> BookAllHistograms("c1l1"+tagger+"6j1bHighMbb_4b"+subchannel, true);
+	      m_anaTools -> BookAllHistograms("c1l1"+tagger+"5j2b"+subchannel, true);
+	      m_anaTools -> BookAllHistograms("c1l1"+tagger+"6j2b"+subchannel, true);
+	      m_anaTools -> BookAllHistograms("c1l1"+tagger+"6j2bLowMbb_3b"+subchannel, true);
+	      m_anaTools -> BookAllHistograms("c1l1"+tagger+"6j2bLowMbb_4b"+subchannel, true);
+	      m_anaTools -> BookAllHistograms("c1l1"+tagger+"6j2bHighMbb_3b"+subchannel, true);
+	      m_anaTools -> BookAllHistograms("c1l1"+tagger+"6j2bHighMbb_4b"+subchannel, true);
 
 	      m_anaTools -> BookAllHistograms("c1l0"+tagger+"5j0b"+subchannel, true);
 	      m_anaTools -> BookAllHistograms("c1l0"+tagger+"6j0b"+subchannel, true);
@@ -600,6 +620,10 @@ VLQ_Analysis_Data2015::~VLQ_Analysis_Data2015()
 	      m_anaTools -> BookAllHistograms("c1l0"+tagger+"6j1bLowMbb_4b"+subchannel, true);
 	      m_anaTools -> BookAllHistograms("c1l0"+tagger+"6j1bHighMbb_3b"+subchannel, true);
 	      m_anaTools -> BookAllHistograms("c1l0"+tagger+"6j1bHighMbb_4b"+subchannel, true);
+	      m_anaTools -> BookAllHistograms("c1l0"+tagger+"6j2bLowMbb_3b"+subchannel, true);
+	      m_anaTools -> BookAllHistograms("c1l0"+tagger+"6j2bLowMbb_4b"+subchannel, true);
+	      m_anaTools -> BookAllHistograms("c1l0"+tagger+"6j2bHighMbb_3b"+subchannel, true);
+	      m_anaTools -> BookAllHistograms("c1l0"+tagger+"6j2bHighMbb_4b"+subchannel, true);
 
 	    }
 
@@ -1078,12 +1102,12 @@ bool VLQ_Analysis_Data2015::Process(Long64_t entry)
   //###########################################################
   // 2015 period selection for fakes in electron channel
   //###########################################################
-  /*
+
   if( (m_opt -> SampleName() == SampleName::QCD) && (m_outData->o_channel_type == VLQ_Enums::ELECTRON) ){
     if( m_outData -> o_period == VLQ_Enums::DATA2016 ){ return false; }//FIXME set rejectionMask
     else{  m_outData -> o_eventWeight_Nom *= (13207.69/3212.96); }//Rescale by 2015+2016 luminosity
   }
-  */ //ALERTRISHA - Checking electron fake estimate with full data period
+  //ALERTRISHA - Checking electron fake estimate with full data period
 
   if(m_opt -> MsgLevel() == Debug::DEBUG) std::cout << "==> After setting the weight " << entry << std::endl;
 
@@ -1361,7 +1385,7 @@ bool VLQ_Analysis_Data2015::Process(Long64_t entry)
 		    else{
 		      m_anaTools -> FillAllHistograms("c1l2"+tagger+"6j1bHighMbb_4b"+subchannel,m_outData->o_VLQtype,true);
 		    }
-		  }
+		  }//6 jets
 		}//2 toptags 
 		else if (  m_outData -> o_toptaggedjets_n.at(tagger) == 1 ) {
 		  if(m_outData -> o_jets_n==5){
@@ -1516,20 +1540,65 @@ bool VLQ_Analysis_Data2015::Process(Long64_t entry)
 		    m_anaTools -> FillAllHistograms("c1l2"+tagger+"5j2b"+subchannel,m_outData->o_VLQtype,true);
 		  } else if (m_outData -> o_jets_n>=6){
 		    m_anaTools -> FillAllHistograms("c1l2"+tagger+"6j2b"+subchannel,m_outData->o_VLQtype,true);
-		  }
+		    if(m_opt->DoLowBRegions()){
+		      //3b and 4b
+		      if(m_outData -> o_mbb_mindR_lowb_3b < 100){
+			m_anaTools -> FillAllHistograms("c1l2"+tagger+"6j2bLowMbb_3b"+subchannel,m_outData->o_VLQtype,true);
+		      }
+		      else{
+			m_anaTools -> FillAllHistograms("c1l2"+tagger+"6j2bHighMbb_3b"+subchannel,m_outData->o_VLQtype,true);
+		      }
+		      if(m_outData -> o_mbb_mindR_lowb_4b < 100){
+			m_anaTools -> FillAllHistograms("c1l2"+tagger+"6j2bLowMbb_4b"+subchannel,m_outData->o_VLQtype,true);
+		      }
+		      else{
+			m_anaTools -> FillAllHistograms("c1l2"+tagger+"6j2bHighMbb_4b"+subchannel,m_outData->o_VLQtype,true);
+		      }
+		    }//do low-b
+		  }//6 jets
 		} else if (  m_outData -> o_toptaggedjets_n.at(tagger) == 1 ) {
 		  if(m_outData -> o_jets_n==5){
 		    m_anaTools -> FillAllHistograms("c1l1"+tagger+"5j2b"+subchannel,m_outData->o_VLQtype,true);
 		  } else if(m_outData -> o_jets_n>=6){
 		    m_anaTools -> FillAllHistograms("c1l1"+tagger+"6j2b"+subchannel,m_outData->o_VLQtype,true);
+		    if(m_opt->DoLowBRegions()){
+		      //3b and 4b
+		      if(m_outData -> o_mbb_mindR_lowb_3b < 100){
+			m_anaTools -> FillAllHistograms("c1l1"+tagger+"6j2bLowMbb_3b"+subchannel,m_outData->o_VLQtype,true);
+		      }
+		      else{
+			m_anaTools -> FillAllHistograms("c1l1"+tagger+"6j2bHighMbb_3b"+subchannel,m_outData->o_VLQtype,true);
+		      }
+		      if(m_outData -> o_mbb_mindR_lowb_4b < 100){
+			m_anaTools -> FillAllHistograms("c1l1"+tagger+"6j2bLowMbb_4b"+subchannel,m_outData->o_VLQtype,true);
+		      }
+		      else{
+			m_anaTools -> FillAllHistograms("c1l1"+tagger+"6j2bHighMbb_4b"+subchannel,m_outData->o_VLQtype,true);
+		      }
+		    }//do low-b
 		  }
 		} else if (  m_outData -> o_toptaggedjets_n.at(tagger) == 0 ){
 		  if(m_outData -> o_jets_n==5){
 		    m_anaTools -> FillAllHistograms("c1l0"+tagger+"5j2b"+subchannel,m_outData->o_VLQtype,true);
 		  } else if(m_outData -> o_jets_n>=6){
 		    m_anaTools -> FillAllHistograms("c1l0"+tagger+"6j2b"+subchannel,m_outData->o_VLQtype,true);
-		  }
-		}
+		    if(m_opt->DoLowBRegions()){
+		      //3b and 4b
+		      if(m_outData -> o_mbb_mindR_lowb_3b < 100){
+			m_anaTools -> FillAllHistograms("c1l0"+tagger+"6j2bLowMbb_3b"+subchannel,m_outData->o_VLQtype,true);
+		      }
+		      else{
+			m_anaTools -> FillAllHistograms("c1l0"+tagger+"6j2bHighMbb_3b"+subchannel,m_outData->o_VLQtype,true);
+		      }
+		      if(m_outData -> o_mbb_mindR_lowb_4b < 100){
+			m_anaTools -> FillAllHistograms("c1l0"+tagger+"6j2bLowMbb_4b"+subchannel,m_outData->o_VLQtype,true);
+		      }
+		      else{
+			m_anaTools -> FillAllHistograms("c1l0"+tagger+"6j2bHighMbb_4b"+subchannel,m_outData->o_VLQtype,true);
+		      }
+		    }//do low-b
+		  }//6 jets
+		}// 0 top-tag
 	      } else if( channel.first == "0l" ){
 		//
 		// 0l channel
diff --git a/macros/macros_trisha/FakeTemplateValidation.cxx b/macros/macros_trisha/FakeTemplateValidation.cxx
new file mode 100644
index 0000000..3ec8d0e
--- /dev/null
+++ b/macros/macros_trisha/FakeTemplateValidation.cxx
@@ -0,0 +1,988 @@
+#include <TChain.h>
+#include <TFile.h>
+#include <TLorentzVector.h>
+#include <TH1.h>
+#include "IFAETopFramework/HistManager.h"
+#include <vector>
+#include <string>
+#include <iostream>
+ 
+int main(int argc, char** argv){
+
+  bool isdata = ( atoi(argv[3]) > 0 );
+  bool isttlight = ( atoi(argv[4]) == 1 );
+  bool isttbb = ( atoi(argv[4]) == 2 );
+  bool isvjets22 = ( atoi(argv[4]) == 3 );
+  bool isqcd = ( atoi(argv[4]) == 4 );
+  bool dolowb = ( atoi(argv[6]) > 0 );
+  std::string qcdconfig = Form("config%i", atoi(argv[5]));
+
+  std::cout<<" isdata =  "<<isdata <<std::endl;
+  std::cout<<" isttlight =  "<<isttlight <<std::endl;
+  std::cout<<" isttbb =  "<<isttbb <<std::endl;
+  std::cout<<" isvjets22 =  "<<isvjets22 <<std::endl;
+  std::cout<<" isqcd =  "<<isqcd <<std::endl;
+  std::cout<<" qcdconfig =  "<<qcdconfig <<std::endl;
+  std::cout<<" dolowb =  "<<dolowb <<std::endl;
+
+
+  if(argc<6){ std::cout<<"Provide name of file from which to read chain; name of file to write to; isdata; istt"<<std::endl; }
+
+
+  //_______________________ SET UP THE CHAIN ________________________
+
+  TChain          *fChain = new TChain("tree");   //!pointer to the analyzed TTree or TChain
+  fChain->Add(argv[1]);
+
+  // Declaration of leaf types
+  Double_t        nomWeight;
+
+  Float_t         nomWeight_weight_btag;
+  Float_t         nomWeight_weight_leptonSF;
+  Float_t         nomWeight_weight_jvt;
+  Float_t         nomWeight_weight_mc;
+  Double_t        nomWeight_weight_norm;
+  Float_t         nomWeight_weight_pileup;
+  //Double_t        nomWeight_weight_ttbar_fractions_rw;
+  Float_t        nomWeight_weight_ttbar_nnlo;
+  Double_t        nomWeight_weight_ttbb;
+  Float_t         nomWeight_weight_sherpa_22_vjets;
+
+  Float_t        nomWeight_fakesMM_weight_ejets_2015;
+  //Float_t        nomWeight_fakesMM_weight_ejets_2016;
+  Float_t        nomWeight_fakesMM_weight_mujets_2015;
+  Float_t        nomWeight_fakesMM_weight_mujets_2016;
+
+  Int_t           channel;
+  Int_t           run_number;
+  Int_t           data_period;
+
+  Int_t           npv;
+  Double_t        pileup_mu;
+
+  Int_t           bjets_n;
+  Double_t        dPhi_jetmet;
+  Double_t        dPhi_lepbjet;
+  Double_t        dPhi_lepjet;
+  Double_t        dPhi_lepmet;
+  Double_t        dRmin_bb;
+  Double_t        dRmin_ebjets;
+  Double_t        dRmin_ejets;
+  Double_t        dRmin_jetjet;
+  Double_t        dRmin_mubjets;
+  Double_t        dRmin_mujets;
+  Double_t        el1_eta;
+  Double_t        el1_phi;
+  Double_t        el1_pt;
+  Int_t           el_n;
+
+  Int_t           el_loose_n;
+  Int_t           mu_loose_n;
+  Int_t           lep_loose_n;
+
+  std::vector<double>*        fjets_eta;
+  std::vector<double>*        fjets_m;
+  std::vector<double>*        fjets_phi;
+  std::vector<double>*        fjets_pt;
+  Int_t           fjets_n;
+
+  std::vector<double>*        jets_btagw;
+  std::vector<double>*        jets_eta;
+  std::vector<double>*        jets_jvt;
+  std::vector<double>*        jets_m;
+  std::vector<double>*        jets_phi;
+  std::vector<double>*        jets_pt;
+  std::vector<double>*        jets_drmin_rc = new std::vector<double>; //input : 0
+
+  Int_t           jets_n;
+  Int_t           lep_n;
+  Double_t        mT_bmin;
+  Double_t        mbb_mindr;
+
+  Double_t        mT_bmin_lowb_3b;
+  Double_t        mbb_mindr_lowb_3b;
+  Double_t        dRmin_bb_lowb_3b;
+
+  Double_t        mT_bmin_lowb_4b;
+  Double_t        mbb_mindr_lowb_4b;
+  Double_t        dRmin_bb_lowb_4b;
+
+
+  Double_t        meff;
+  Double_t        met;
+  Double_t        met_phi;
+  Double_t        mtw;
+  //Double_t        ptw;
+  Double_t        mu1_eta;
+  Double_t        mu1_phi;
+  Double_t        mu1_pt;
+  Int_t           mu_n;
+  Double_t        hthad;
+  std::vector<double>*        rcjets_eta;
+  std::vector<double>*        rcjets_m;
+  std::vector<double>*        rcjets_nconsts;
+  std::vector<double>*        rcjets_phi;
+  std::vector<double>*        rcjets_pt;
+  Int_t           rcjets_n;
+  Int_t           ttjets_n;
+
+  // List of branches
+  //TBranch        *b_nomWeight; //!
+
+  TBranch        *b_channel;   //!
+  TBranch        *b_data_period;   //!
+  TBranch        *b_run_number;   //!
+  TBranch        *b_npv;   //!
+  TBranch        *b_pileup_mu;   //!
+  
+  TBranch        *b_nomWeight_weight_btag;   //!
+  TBranch        *b_nomWeight_weight_leptonSF;   //!
+  TBranch        *b_nomWeight_weight_jvt;   //!
+  TBranch        *b_nomWeight_weight_mc;   //!
+  TBranch        *b_nomWeight_weight_norm;   //!
+  TBranch        *b_nomWeight_weight_pileup;   //!
+  TBranch        *b_nomWeight_weight_ttbb;   //!
+  TBranch        *b_nomWeight_weight_ttbar_nnlo;   //!
+  TBranch        *b_nomWeight_weight_sherpa_22_vjets; //!
+
+  TBranch        *b_nomWeight_fakesMM_weight_ejets_2015;
+  //TBranch        *b_nomWeight_fakesMM_weight_ejets_2016;
+  TBranch        *b_nomWeight_fakesMM_weight_mujets_2015;
+  TBranch        *b_nomWeight_fakesMM_weight_mujets_2016;
+  
+  TBranch        *b_bjets_n;   //!
+  TBranch        *b_dPhi_jetmet;   //!
+  TBranch        *b_dPhi_lepbjet;   //!
+  TBranch        *b_dPhi_lepjet;   //!
+  TBranch        *b_dPhi_lepmet;   //!
+  TBranch        *b_dRmin_bb;   //!
+  TBranch        *b_dRmin_ebjets;   //!
+  TBranch        *b_dRmin_ejets;   //!
+  TBranch        *b_dRmin_jetjet;   //!
+  TBranch        *b_dRmin_mubjets;   //!
+  TBranch        *b_dRmin_mujets;   //!
+  TBranch        *b_el1_eta;   //!
+  TBranch        *b_el1_phi;   //!
+  TBranch        *b_el1_pt;   //!
+  TBranch        *b_el_n;   //!
+  TBranch        *b_fjets_eta;   //!
+  TBranch        *b_fjets_m;   //!
+  TBranch        *b_fjets_phi;   //!
+  TBranch        *b_fjets_pt;   //!
+  TBranch        *b_fjets_n;   //!
+  TBranch        *b_jets_btagw;   //!
+  TBranch        *b_jets_eta;   //!
+  TBranch        *b_jets_jvt;   //!
+  TBranch        *b_jets_m;   //!
+  TBranch        *b_jets_phi;   //!
+  TBranch        *b_jets_pt;   //!
+  TBranch        *b_jets_n;   //!
+  TBranch        *b_lep_n;   //!
+  TBranch        *b_mT_bmin;   //!
+  TBranch        *b_mbb_mindr;   //!
+
+  TBranch        *b_mT_bmin_lowb_3b; //!
+  TBranch        *b_mbb_mindr_lowb_3b; //!
+  TBranch        *b_dRmin_bb_lowb_3b; //!
+
+  TBranch        *b_mT_bmin_lowb_4b; //!
+  TBranch        *b_mbb_mindr_lowb_4b; //!
+  TBranch        *b_dRmin_bb_lowb_4b; //!
+
+  TBranch        *b_meff;   //!
+  TBranch        *b_met;   //!
+  TBranch        *b_met_phi;   //!
+  TBranch        *b_mtw;   //!
+  TBranch        *b_mu1_eta;   //!
+  TBranch        *b_mu1_phi;   //!
+  TBranch        *b_mu1_pt;   //!
+  TBranch        *b_mu_n;   //!
+
+  TBranch        *b_el_loose_n; //!
+  TBranch        *b_mu_loose_n; //!
+  TBranch        *b_lep_loose_n; //!
+ 
+  TBranch        *b_hthad;   //!
+  TBranch        *b_rcjets_eta;   //!
+  TBranch        *b_rcjets_m;   //!
+  TBranch        *b_rcjets_nconsts;   //!
+  TBranch        *b_rcjets_phi;   //!
+  TBranch        *b_rcjets_pt;   //!
+  TBranch        *b_rcjets_n;   //!
+  TBranch        *b_ttjets_n;   //!
+
+  fjets_eta = 0;
+  fjets_m = 0;
+  fjets_phi = 0;
+  fjets_pt = 0;
+  jets_btagw = 0;
+  jets_eta = 0;
+  jets_jvt = 0;
+  jets_m = 0;
+  jets_phi = 0;
+  jets_pt = 0;
+  rcjets_eta = 0;
+  rcjets_m = 0;
+  rcjets_nconsts = 0;
+  rcjets_phi = 0;
+  rcjets_pt = 0;
+
+  //fChain->SetBranchAddress("nomWeight", &nomWeight, &b_nomWeight);
+  if(!isdata){
+    if(isqcd){
+      fChain->SetBranchAddress(Form("nomWeight_fakesMM_weight_ejets_2015_Loose_test2015%s", qcdconfig.c_str()), &nomWeight_fakesMM_weight_ejets_2015
+			       , &b_nomWeight_fakesMM_weight_ejets_2015);
+      //fChain->SetBranchAddress(Form("nomWeight_fakesMM_weight_ejets_2016_%s", qcdconfig.c_str()), &nomWeight_fakesMM_weight_ejets_2016
+      //		       , &b_nomWeight_fakesMM_weight_ejets_2016);
+      fChain->SetBranchAddress(Form("nomWeight_fakesMM_weight_mujets_2015_Loose_test2015%s", qcdconfig.c_str()), &nomWeight_fakesMM_weight_mujets_2015
+			       , &b_nomWeight_fakesMM_weight_mujets_2015);
+      fChain->SetBranchAddress(Form("nomWeight_fakesMM_weight_mujets_2016_Loose_test2016%s", qcdconfig.c_str()), &nomWeight_fakesMM_weight_mujets_2016
+			       , &b_nomWeight_fakesMM_weight_mujets_2016);
+    }
+    else{
+      fChain->SetBranchAddress("nomWeight_weight_btag", &nomWeight_weight_btag, &b_nomWeight_weight_btag);
+      fChain->SetBranchAddress("nomWeight_weight_leptonSF", &nomWeight_weight_leptonSF, &b_nomWeight_weight_leptonSF);
+      fChain->SetBranchAddress("nomWeight_weight_jvt", &nomWeight_weight_jvt, &b_nomWeight_weight_jvt);
+      fChain->SetBranchAddress("nomWeight_weight_mc", &nomWeight_weight_mc, &b_nomWeight_weight_mc);
+      fChain->SetBranchAddress("nomWeight_weight_norm", &nomWeight_weight_norm, &b_nomWeight_weight_norm);
+      fChain->SetBranchAddress("nomWeight_weight_pileup", &nomWeight_weight_pileup, &b_nomWeight_weight_pileup);
+      if(isttbb){
+	fChain->SetBranchAddress("nomWeight_weight_ttbb", &nomWeight_weight_ttbb, &b_nomWeight_weight_ttbb);
+      }
+      if(isttlight){
+	fChain->SetBranchAddress("nomWeight_weight_ttbar_nnlo", &nomWeight_weight_ttbar_nnlo, &b_nomWeight_weight_ttbar_nnlo);
+      }
+      else if(isvjets22){
+	fChain->SetBranchAddress("nomWeight_weight_sherpa_22_vjets", &nomWeight_weight_sherpa_22_vjets, &b_nomWeight_weight_sherpa_22_vjets);
+      }//vjets_22
+    }//!qcd
+  }//!data
+
+  fChain->SetBranchAddress("channel", &channel, &b_channel);
+  fChain->SetBranchAddress("run_number", &run_number, &b_run_number);
+  fChain->SetBranchAddress("data_period", &data_period, &b_data_period);
+  fChain->SetBranchAddress("npv", &npv, &b_npv);
+  fChain->SetBranchAddress("pileup_mu", &pileup_mu, &b_pileup_mu);
+
+  fChain->SetBranchAddress("bjets_n", &bjets_n, &b_bjets_n);
+  fChain->SetBranchAddress("dPhi_jetmet", &dPhi_jetmet, &b_dPhi_jetmet);
+  fChain->SetBranchAddress("dPhi_lepbjet", &dPhi_lepbjet, &b_dPhi_lepbjet);
+  fChain->SetBranchAddress("dPhi_lepjet", &dPhi_lepjet, &b_dPhi_lepjet);
+  fChain->SetBranchAddress("dPhi_lepmet", &dPhi_lepmet, &b_dPhi_lepmet);
+  fChain->SetBranchAddress("dRmin_bb", &dRmin_bb, &b_dRmin_bb);
+  fChain->SetBranchAddress("dRmin_ebjets", &dRmin_ebjets, &b_dRmin_ebjets);
+  fChain->SetBranchAddress("dRmin_ejets", &dRmin_ejets, &b_dRmin_ejets);
+  fChain->SetBranchAddress("dRmin_jetjet", &dRmin_jetjet, &b_dRmin_jetjet);
+  fChain->SetBranchAddress("dRmin_mubjets", &dRmin_mubjets, &b_dRmin_mubjets);
+  fChain->SetBranchAddress("dRmin_mujets", &dRmin_mujets, &b_dRmin_mujets);
+  fChain->SetBranchAddress("el1_eta", &el1_eta, &b_el1_eta);
+  fChain->SetBranchAddress("el1_phi", &el1_phi, &b_el1_phi);
+  fChain->SetBranchAddress("el1_pt", &el1_pt, &b_el1_pt);
+  fChain->SetBranchAddress("el_n", &el_n, &b_el_n);
+
+  fChain->SetBranchAddress("el_loose_n", &el_loose_n, &b_el_loose_n);
+  fChain->SetBranchAddress("mu_loose_n", &mu_loose_n, &b_mu_loose_n);
+  fChain->SetBranchAddress("lep_loose_n", &lep_loose_n, &b_lep_loose_n);
+
+  fChain->SetBranchAddress("fjets_eta", &fjets_eta, &b_fjets_eta);
+  fChain->SetBranchAddress("fjets_m", &fjets_m, &b_fjets_m);
+  fChain->SetBranchAddress("fjets_phi", &fjets_phi, &b_fjets_phi);
+  fChain->SetBranchAddress("fjets_pt", &fjets_pt, &b_fjets_pt);
+  fChain->SetBranchAddress("fjets_n", &fjets_n, &b_fjets_n);
+  fChain->SetBranchAddress("jets_btagw", &jets_btagw, &b_jets_btagw);
+  fChain->SetBranchAddress("jets_eta", &jets_eta, &b_jets_eta);
+  fChain->SetBranchAddress("jets_jvt", &jets_jvt, &b_jets_jvt);
+  fChain->SetBranchAddress("jets_m", &jets_m, &b_jets_m);
+  fChain->SetBranchAddress("jets_phi", &jets_phi, &b_jets_phi);
+  fChain->SetBranchAddress("jets_pt", &jets_pt, &b_jets_pt);
+  fChain->SetBranchAddress("jets_n", &jets_n, &b_jets_n);
+  fChain->SetBranchAddress("lep_n", &lep_n, &b_lep_n);
+  fChain->SetBranchAddress("mT_bmin", &mT_bmin, &b_mT_bmin);
+  fChain->SetBranchAddress("mbb_mindr", &mbb_mindr, &b_mbb_mindr);
+  if(dolowb){
+    fChain->SetBranchAddress("mT_bmin_lowb_3b", &mT_bmin_lowb_3b, &b_mT_bmin_lowb_3b);
+    fChain->SetBranchAddress("mbb_mindr_lowb_3b", &mbb_mindr_lowb_3b, &b_mbb_mindr_lowb_3b);
+    fChain->SetBranchAddress("dRmin_bb_lowb_3b", &dRmin_bb_lowb_3b, &b_dRmin_bb_lowb_3b);
+
+    fChain->SetBranchAddress("mT_bmin_lowb_4b", &mT_bmin_lowb_4b, &b_mT_bmin_lowb_4b);
+    fChain->SetBranchAddress("mbb_mindr_lowb_4b", &mbb_mindr_lowb_4b, &b_mbb_mindr_lowb_4b);
+    fChain->SetBranchAddress("dRmin_bb_lowb_4b", &dRmin_bb_lowb_4b, &b_dRmin_bb_lowb_4b);
+  }
+  fChain->SetBranchAddress("meff", &meff, &b_meff);
+  fChain->SetBranchAddress("met", &met, &b_met);
+  fChain->SetBranchAddress("met_phi", &met_phi, &b_met_phi);
+  fChain->SetBranchAddress("mtw", &mtw, &b_mtw);
+  fChain->SetBranchAddress("mu1_eta", &mu1_eta, &b_mu1_eta);
+  fChain->SetBranchAddress("mu1_phi", &mu1_phi, &b_mu1_phi);
+  fChain->SetBranchAddress("mu1_pt", &mu1_pt, &b_mu1_pt);
+  fChain->SetBranchAddress("mu_n", &mu_n, &b_mu_n);
+  fChain->SetBranchAddress("hthad", &hthad, &b_hthad);
+  fChain->SetBranchAddress("rcjets_eta", &rcjets_eta, &b_rcjets_eta);
+  fChain->SetBranchAddress("rcjets_m", &rcjets_m, &b_rcjets_m);
+  fChain->SetBranchAddress("rcjets_nconsts", &rcjets_nconsts, &b_rcjets_nconsts);
+  fChain->SetBranchAddress("rcjets_phi", &rcjets_phi, &b_rcjets_phi);
+  fChain->SetBranchAddress("rcjets_pt", &rcjets_pt, &b_rcjets_pt);
+  fChain->SetBranchAddress("rcjets_n", &rcjets_n, &b_rcjets_n);
+  fChain->SetBranchAddress("ttjets_n", &ttjets_n, &b_ttjets_n);
+
+  //_________________________________________________________________________________________________
+
+  std::vector<std::string> regions; regions.clear();
+
+  //regions.push_back("0lep"); 
+
+  //regions.push_back("0lep_period2015"); 
+  //regions.push_back("0lep_period2016"); 
+  /*
+  regions.push_back("0lep_lowmu"); 
+  regions.push_back("0lep_highmu"); 
+  */
+  //regions.push_back("1lep"); 
+  //regions.push_back("1elmu"); 
+  /*
+  regions.push_back("1elmu"); 
+  regions.push_back("1el"); 
+  regions.push_back("1mu"); 
+  regions.push_back("1elmu_period2015"); 
+  regions.push_back("1elmu_period2016"); 
+  regions.push_back("1el_period2015"); 
+  regions.push_back("1el_period2016"); 
+  regions.push_back("1mu_period2015"); 
+  regions.push_back("1mu_period2016"); 
+  */
+
+  regions.push_back("metmtwinc_1el_0bex");
+  regions.push_back("metmtwinc_1mu_0bex");
+
+  regions.push_back("metmtwinc_1el_1bex");
+  regions.push_back("metmtwinc_1mu_1bex");
+
+  regions.push_back("metmtwinc_1el_2bin");
+  regions.push_back("metmtwinc_1mu_2bin");
+
+  regions.push_back("1el_0bex");
+  regions.push_back("1mu_0bex");
+
+  regions.push_back("1el_1bex");
+  regions.push_back("1mu_1bex");
+
+  regions.push_back("1el_2bin");
+  regions.push_back("1mu_2bin");
+
+  /*
+  regions.push_back("1elmu_lowmu"); 
+  regions.push_back("1elmu_highmu"); 
+  regions.push_back("1el_lowmu"); 
+  regions.push_back("1el_highmu"); 
+  regions.push_back("1mu_lowmu"); 
+  regions.push_back("1mu_highmu"); 
+  */
+  //regions.push_back("0lep_RC1M_nsj1"); 
+  //regions.push_back("0lep_RC1M_mwin"); 
+  //regions.push_back("0lep_RC1M_moutwin"); 
+
+  /*
+  regions.push_back("0lep_RC1M_nsj2"); 
+  regions.push_back("0lep_RC1M_nsjge3"); 
+
+
+  regions.push_back("0lep_RC1M_nsj2_mwin"); 
+  regions.push_back("0lep_RC1M_nsj2_moutwin"); 
+  */
+  HistManager* m_hstMngr = new HistManager(true, true);
+  
+
+  std::vector<std::string> variables;
+
+  variables.push_back("npv");
+  variables.push_back("pileup_mu");
+
+  variables.push_back("fjets_n");
+  variables.push_back("rcjets_n");
+  variables.push_back("jets_n");
+  variables.push_back("bjets_n");
+
+  //variables.push_back("el_loose_n");
+  //variables.push_back("mu_loose_n");
+  //variables.push_back("lep_loose_n");
+
+  variables.push_back("dPhi_jetmet");
+
+  variables.push_back("dPhi_lepbjet");
+  variables.push_back("dPhi_lepjet");
+  variables.push_back("dPhi_lepmet");
+
+  variables.push_back("dRmin_ebjets");
+  variables.push_back("dRmin_ejets");
+  variables.push_back("dRmin_mubjets");
+  variables.push_back("dRmin_mujets");
+
+  variables.push_back("dRmin_bb");
+  variables.push_back("dRmin_jetjet");
+
+  variables.push_back("mT_bmin");
+  variables.push_back("mbb_mindr");
+  variables.push_back("ptbb_mindr");
+  variables.push_back("etabb_mindr");
+  variables.push_back("phibb_mindr");
+
+  if(dolowb){
+    variables.push_back("dRmin_bb_lowb_3b");
+    variables.push_back("mT_bmin_lowb_3b");
+    variables.push_back("mbb_mindr_lowb_3b");
+
+    variables.push_back("dRmin_bb_lowb_4b");
+    variables.push_back("mT_bmin_lowb_4b");
+    variables.push_back("mbb_mindr_lowb_4b");
+  }
+
+  variables.push_back("bjet1_mindr_pt");
+  variables.push_back("bjet1_mindr_mass");
+  variables.push_back("bjet1_mindr_eta");
+  variables.push_back("bjet1_mindr_phi");
+  variables.push_back("bjet1_mindr_dR_rc");
+
+  variables.push_back("bjet2_mindr_pt");
+  variables.push_back("bjet2_mindr_mass");
+  variables.push_back("bjet2_mindr_eta");
+  variables.push_back("bjet2_mindr_phi");
+  variables.push_back("bjet2_mindr_dR_rc");
+
+  variables.push_back("jet1_mindr_pt");
+  variables.push_back("jet1_mindr_mass");
+  variables.push_back("jet1_mindr_eta");
+  variables.push_back("jet1_mindr_phi");
+  variables.push_back("jet1_mindr_dR_rc");
+
+  variables.push_back("jet2_mindr_pt");
+  variables.push_back("jet2_mindr_mass");
+  variables.push_back("jet2_mindr_eta");
+  variables.push_back("jet2_mindr_phi");
+  variables.push_back("jet2_mindr_dR_rc");
+
+
+  variables.push_back("hthad");
+  variables.push_back("meff");
+  variables.push_back("met");
+  variables.push_back("met_phi");
+  variables.push_back("mtw");
+
+  variables.push_back("fjet1_pt");
+  variables.push_back("fjet1_mass");
+  variables.push_back("fjet1_eta");
+  variables.push_back("fjet1_phi");
+
+  variables.push_back("fjets_pt");
+  variables.push_back("fjets_mass");
+  variables.push_back("fjets_eta");
+  variables.push_back("fjets_phi");
+
+  variables.push_back("rcjet1_pt");
+  variables.push_back("rcjet1_eta");
+  variables.push_back("rcjet1_phi");
+  variables.push_back("rcjet1_mass");
+  variables.push_back("rcjet1_nconsts");
+
+  variables.push_back("rcjet2_pt");
+  variables.push_back("rcjet2_eta");
+  variables.push_back("rcjet2_phi");
+  variables.push_back("rcjet2_mass");
+  variables.push_back("rcjet2_nconsts");
+
+  variables.push_back("rcjets_pt");
+  variables.push_back("rcjets_eta");
+  variables.push_back("rcjets_phi");
+  variables.push_back("rcjets_mass");
+  variables.push_back("rcjets_nconsts");
+
+  variables.push_back("jets_pt");
+  variables.push_back("jets_mass");
+  variables.push_back("jets_eta");
+  variables.push_back("jets_phi");
+  variables.push_back("jets_btagw");
+  variables.push_back("jets_jvt");
+  variables.push_back("jets_dRmin_j");
+  
+  variables.push_back("bjets_pt");
+  variables.push_back("bjets_mass");
+  variables.push_back("bjets_eta");
+  variables.push_back("bjets_phi");
+  variables.push_back("bjets_btagw");
+  variables.push_back("bjets_jvt");
+  variables.push_back("bjets_dRmin_j");
+
+  variables.push_back("ljets_pt");
+  variables.push_back("ljets_mass");
+  variables.push_back("ljets_eta");
+  variables.push_back("ljets_phi");
+  variables.push_back("ljets_btagw");
+  variables.push_back("ljets_jvt");
+  variables.push_back("ljets_dRmin_j");
+
+  //
+  variables.push_back("jet1_pt");
+  variables.push_back("jet1_mass");
+  variables.push_back("jet1_eta");
+  variables.push_back("jet1_phi");
+  variables.push_back("jet1_btagw");
+  variables.push_back("jet1_jvt");
+  variables.push_back("jet1_dRmin_j");
+  
+  variables.push_back("bjet1_pt");
+  variables.push_back("bjet1_mass");
+  variables.push_back("bjet1_eta");
+  variables.push_back("bjet1_phi");
+  variables.push_back("bjet1_btagw");
+  variables.push_back("bjet1_jvt");
+  variables.push_back("bjet1_dRmin_j");
+
+  variables.push_back("ljet1_pt");
+  variables.push_back("ljet1_mass");
+  variables.push_back("ljet1_eta");
+  variables.push_back("ljet1_phi");
+  variables.push_back("ljet1_btagw");
+  variables.push_back("ljet1_jvt");
+  variables.push_back("ljet1_dRmin_j");
+
+  variables.push_back("el1_pt");
+  variables.push_back("el1_eta");
+  variables.push_back("el1_phi");
+
+  variables.push_back("mu1_pt");
+  variables.push_back("mu1_eta");
+  variables.push_back("mu1_phi");
+
+
+  for(const std::string region : regions){
+
+    for(const std::string variable : variables){
+      double binsize = 0.; double binmin = 0.; double binmax = 0.;
+      if( (variable == "fjets_n") || (variable == "rcjets_n") ){ binsize = 1.; binmin = 0.; binmax = 5.; }
+      else if( variable == "jets_n" ){ binsize = 1.; binmin = 0.; binmax = 15.; }
+      else if( variable == "bjets_n" ){ binsize = 1.; binmin = 0.; binmax = 8.; }
+      else if( variable == "ljets_n" ){ binsize = 1.; binmin = 0.; binmax = 15.; }
+      else if( (variable == "el_loose_n") || (variable == "mu_loose_n") || (variable == "lep_loose_n") ){ binsize = 1.; binmin = 0.; binmax = 4.; }
+      else if( (variable.find("_njets") != std::string::npos) || (variable.find("_nconsts") != std::string::npos) ){
+	binsize = 1.; binmin = 0.; binmax = 8.;
+      }
+      else if(variable.find("_nbjets") != std::string::npos){ binsize = 1.; binmin = 0.; binmax = 4.; }
+      else if(variable.find("_nljets") != std::string::npos){ binsize = 1.; binmin = 0.; binmax = 4.; }
+      
+      else if( (variable.find("dPhi") != std::string::npos) || (variable.find("phibb") != std::string::npos) 
+	       || (variable.find("_phi") != std::string::npos) ){ binsize = 0.2; binmin = -4.; binmax = 4.; }
+      else if( (variable.find("_eta") != std::string::npos) || (variable.find("etabb") != std::string::npos) ){ binsize = 0.2; binmin = -3.; binmax = 3.; }
+      else if( variable.find("dR") != std::string::npos ){ binsize = 0.25; binmin = 0.; binmax = 5.; }
+      else if( (variable == "meff") || (variable == "hthad") ){ binsize = 50.; binmin = 0.; binmax = 2000.; }
+      else if(variable == "met"){ binsize = 20.; binmin = 0.; binmax = 500.; }
+      else if(variable == "mtw"){ binsize = 20.; binmin = 0.; binmax = 400.; }
+      else if( (variable.find("mT_bmin") != std::string::npos) || (variable.find("mbb_mindr") != std::string::npos) ){ binsize = 25.; binmin = 0.; binmax = 400.; }
+      else if( (variable.find("_mass") != std::string::npos) 
+	       || (variable.find("_mjsum") != std::string::npos) 
+	       || (variable.find("_m_sumj") != std::string::npos) ){
+	if( (variable.find("rcjet") != std::string::npos) || (variable.find("fjet") != std::string::npos) ){
+	  binsize = 20.; binmin = 0.; binmax = 400.;
+	}
+	else{ binsize = 10.; binmin = 0.; binmax = 150.; }
+      }
+      else if( (variable.find("ptbb") != std::string::npos) || (variable.find("_pt") != std::string::npos) ){
+	if(variable.find("_ptfrac") != std::string::npos){ binsize = 0.05; binmin = 0.; binmax = 1.; }
+	else if( (variable.find("rcjet") != std::string::npos) || (variable.find("fjet") != std::string::npos) ){
+	  binsize = 20.; binmin = 0.; binmax = 1000.;
+	}
+	else if( (variable == "el1_pt") || (variable == "mu1_pt") ){ binsize = 5.; binmin = 0.; binmax = 500.; }
+	else{ binsize = 20.; binmin = 0.; binmax = 500.; }
+      }
+      else if( (variable.find("btagw") != std::string::npos) || (variable.find("jvt") != std::string::npos) ){ binsize = 0.1; binmin = -1.1; binmax = 1.1; }
+      else if( variable == "npv" ){ binsize = 1.; binmin = 0.; binmax = 50.;}
+      else if( variable == "pileup_mu" ){ binsize = 1.; binmin = 0.; binmax = 50.;}
+      //---------------------------------
+      //std::cout<<" Booking histogram "<<region+"_"+variable<<std::endl;
+      m_hstMngr->BookTH1D(region+"_"+variable,  "", binsize, binmin, binmax);	
+	
+    }//variables
+
+  }//regions
+
+    //
+    //m_hstMngr->BookTH1D(region+"_"+"jets_rc1_trim05_pt", "", 10., 0., 500.);
+    //____________________________________________________
+
+  //__________________________ EVENT LOOP _____________________________________
+
+  for(long int entry = 0; entry < fChain->GetEntries(); ++entry){
+
+    jets_drmin_rc->clear();
+
+    if(entry % 10000 == 0) std::cout<<"Processing entry "<<entry<<std::endl;
+    fChain->GetEntry(entry);
+
+    nomWeight = 1;
+    if(!isdata){
+      if(!isqcd){
+	nomWeight = nomWeight_weight_btag * nomWeight_weight_mc * nomWeight_weight_norm * nomWeight_weight_pileup;// * nomWeight_weight_jvt;
+	if( el_n + mu_n > 0 ){
+	  nomWeight *= nomWeight_weight_leptonSF;
+	}
+	if(isttlight){
+	  nomWeight *= nomWeight_weight_ttbar_nnlo;
+	} 
+	else if(isttbb){
+	  nomWeight *= nomWeight_weight_ttbb;
+	} 
+	else if(isvjets22){
+	  nomWeight *= nomWeight_weight_sherpa_22_vjets;
+	}
+      }
+      else{
+	if(channel==1 && data_period==1){
+	  nomWeight = nomWeight_fakesMM_weight_ejets_2015;
+	}
+	else if(channel==1 && data_period==2){ continue;
+	  //nomWeight = nomWeight_fakesMM_weight_ejets_2016;
+	}
+	else if(channel==2 && data_period==1){
+	  nomWeight = nomWeight_fakesMM_weight_mujets_2015;
+	}
+	else if(channel==2 && data_period==2){
+	  nomWeight = nomWeight_fakesMM_weight_mujets_2016;
+	}
+      }
+    }
+
+    if(!dolowb && (bjets_n < 2)) continue;
+    if(jets_n < 5) continue;
+
+
+    for(const std::string region:regions){
+      if( (region.find("noRC") != std::string::npos) && (rcjets_n > 0) ) continue;
+      else if( (region.find("RC1M") != std::string::npos) && (rcjets_n != 1) ) continue;
+      //-------------------------------------------------------------
+      if(region.find("_low150") != std::string::npos){
+	if(rcjets_n>0 && rcjets_m->at(0) > 150) continue;
+      }
+      if(region.find("_high150") != std::string::npos){
+	if(rcjets_n>0 && rcjets_m->at(0) < 150) continue;
+      }
+
+      if(region.find("_mwin") != std::string::npos){
+	if(rcjets_n>0 && (rcjets_m->at(0) < 90 || rcjets_m->at(0) > 140) ) continue;
+      }
+
+      if(region.find("_moutwin") != std::string::npos){
+	if(rcjets_n>0 && (rcjets_m->at(0) >= 90 && rcjets_m->at(0) <= 140) ) continue;
+      }
+
+      if(region.find("_nsj1") != std::string::npos){
+	if(rcjets_n>0 && rcjets_nconsts->at(0) != 1) continue;
+      }
+      if(region.find("_nsj2") != std::string::npos){
+	if(rcjets_n>0 && rcjets_nconsts->at(0) != 2) continue;
+      }
+      if(region.find("_nsjge3") != std::string::npos){
+	if(rcjets_n>0 && rcjets_nconsts->at(0) < 3) continue;
+      }
+
+
+      //---------------------------------------------------------------
+
+      if(region.find("0lep") != std::string::npos){
+	if ( (el_n+mu_n > 0) || (met < 200) || (fabs(dPhi_jetmet) < 0.4) || (jets_n < 6) || (channel != 3) ){continue;}
+      }
+      else if(region.find("1elmu") != std::string::npos){ 
+	if  (el_n+mu_n <= 0  || (channel != 1 && channel != 2) ){continue;}
+      }
+      else if(region.find("1el") != std::string::npos){
+	if  (el_n != 1 || mu_n > 0 || channel != 1){continue;}
+      }
+      else if(region.find("1mu") != std::string::npos){
+	if (el_n > 0 || mu_n != 1 || channel != 2){continue;}
+      }
+
+      //--------------------------------------------------------------------------------------------
+
+      if( (region.find("0bex") != std::string::npos) && (bjets_n != 0) ){continue;} 
+      else if( (region.find("1bex") != std::string::npos) && (bjets_n != 1) ){continue;} 
+      else if( (region.find("2bex") != std::string::npos) && (bjets_n != 2) ){continue;} 
+      else if( (region.find("3bex") != std::string::npos) && (bjets_n != 3) ){continue;} 
+
+      else if( (region.find("0bin") != std::string::npos) && (bjets_n < 0) ){continue;} 
+      else if( (region.find("1bin") != std::string::npos) && (bjets_n < 1) ){continue;} 
+      else if( (region.find("2bin") != std::string::npos) && (bjets_n < 2) ){continue;} 
+      else if( (region.find("3bin") != std::string::npos) && (bjets_n < 3) ){continue;} 
+      else if( (region.find("4bin") != std::string::npos) && (bjets_n < 4) ){continue;} 
+ 
+      //------------------------------------------------------------------------------------------
+      if(region.find("metmtwinc") != std::string::npos){ 
+	if( (met<20.) || (met+mtw < 60.) ){continue;}
+      }
+
+     //--------------------------------------------------------------------------------------------
+      if( region.find("period2015") != std::string::npos ){ 
+	if(data_period != 1){ continue; }
+      }
+      else if( region.find("period2016") != std::string::npos ){ 
+	if(data_period != 2){ continue; }
+      }
+      //---------------------------------------------------------
+
+      if( region.find("lowmu") != std::string::npos ){ 
+	if(pileup_mu >= 22.){ continue; }
+      }
+      if( region.find("highmu") != std::string::npos ){ 
+	if(pileup_mu < 22.){ continue; }
+      }
+      /*
+      m_hstMngr->FillTH1D(region+"_"+"el_loose_n", el_loose_n, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"mu_loose_n", mu_loose_n, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"el_loose_n", el_loose_n+mu_loose_n, nomWeight);
+      */
+      for( int ifj = 0; ifj < fjets_n; ifj++){
+	if(ifj == 0){
+	  m_hstMngr->FillTH1D(region+"_"+"fjet1_mass", fjets_m->at(ifj), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"fjet1_pt", fjets_pt->at(ifj), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"fjet1_eta", fjets_eta->at(ifj), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"fjet1_phi", fjets_phi->at(ifj), nomWeight);
+	}
+	m_hstMngr->FillTH1D(region+"_"+"fjets_mass", fjets_m->at(ifj), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"fjets_pt", fjets_pt->at(ifj), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"fjets_eta", fjets_eta->at(ifj), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"fjets_phi", fjets_phi->at(ifj), nomWeight);
+      }
+
+      for( int irc = 0; irc < rcjets_n; irc++){
+	if(irc == 0){
+	  m_hstMngr->FillTH1D(region+"_"+"rcjet1_mass", rcjets_m->at(irc), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"rcjet1_pt", rcjets_pt->at(irc), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"rcjet1_eta", rcjets_eta->at(irc), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"rcjet1_phi", rcjets_phi->at(irc), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"rcjet1_nconsts", rcjets_nconsts->at(irc), nomWeight);
+	}
+	else if(irc == 1){
+	  m_hstMngr->FillTH1D(region+"_"+"rcjet2_mass", rcjets_m->at(irc), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"rcjet2_pt", rcjets_pt->at(irc), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"rcjet2_eta", rcjets_eta->at(irc), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"rcjet2_phi", rcjets_phi->at(irc), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"rcjet2_nconsts", rcjets_nconsts->at(irc), nomWeight);
+	}
+
+	m_hstMngr->FillTH1D(region+"_"+"rcjets_mass", rcjets_m->at(irc), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"rcjets_pt", rcjets_pt->at(irc), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"rcjets_eta", rcjets_eta->at(irc), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"rcjets_phi", rcjets_phi->at(irc), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"rcjets_nconsts", rcjets_nconsts->at(irc), nomWeight);
+	
+      }//reclustered jet loop
+      
+      int nbj = 0; int nlj = 0; 
+
+      int i1_mindr_bb = -1; int i2_mindr_bb = -1; double mindr_bb = 10.;
+      int i1_mindr_jj = -1; int i2_mindr_jj = -1; double mindr_jj = 10.;
+
+      for( int ij = 0; ij < jets_n; ij++){
+
+	TLorentzVector tlv_j;
+	tlv_j.SetPtEtaPhiM(jets_pt->at(ij), jets_eta->at(ij), jets_phi->at(ij), jets_m->at(ij));
+	double dRmin_jj = 10.; double dRmin_rc = 10.;
+
+	for(int irc = 0; irc < rcjets_n; irc++){
+	  TLorentzVector tlv_rc;
+	  tlv_rc.SetPtEtaPhiM(rcjets_pt->at(irc), rcjets_eta->at(irc), rcjets_phi->at(irc), rcjets_m->at(irc));
+	  double dr_jrc = tlv_rc.DeltaR(tlv_j);
+	  if(dr_jrc < dRmin_rc) dRmin_rc = dr_jrc;
+	}
+	jets_drmin_rc->push_back(dRmin_rc);
+
+	for( int jj = 0; jj < jets_n; jj++){
+	  if(ij == jj) continue;
+	  TLorentzVector tlv_jalt;
+	  tlv_jalt.SetPtEtaPhiM(jets_pt->at(jj), jets_eta->at(jj), jets_phi->at(jj), jets_m->at(jj));
+	  double dr_jj = tlv_jalt.DeltaR(tlv_j);
+	  if(dr_jj < dRmin_jj) dRmin_jj = dr_jj;
+	  if(dr_jj < mindr_jj){
+	    mindr_jj = dr_jj;
+	    i1_mindr_jj = ij; i2_mindr_jj = jj;
+	  }
+
+	  if( (jets_btagw->at(ij) > 0.645925) && (jets_btagw->at(jj) > 0.645925) ){
+	    if(dr_jj < mindr_bb){
+	      mindr_bb = dr_jj;
+	      i1_mindr_bb = ij; i2_mindr_bb = jj;
+	    }
+	  }
+	}//second jet loop
+
+	m_hstMngr->FillTH1D(region+"_"+"jets_pt", jets_pt->at(ij), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"jets_mass", jets_m->at(ij), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"jets_eta", jets_eta->at(ij), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"jets_phi", jets_phi->at(ij), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"jets_btagw", jets_btagw->at(ij), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"jets_jvt", jets_jvt->at(ij), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"jets_dRmin_j", dRmin_jj, nomWeight);
+
+	if(ij == 0){
+	  m_hstMngr->FillTH1D(region+"_"+"jet1_pt", jets_pt->at(ij), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"jet1_mass", jets_m->at(ij), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"jet1_eta", jets_eta->at(ij), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"jet1_phi", jets_phi->at(ij), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"jet1_btagw", jets_btagw->at(ij), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"jet1_jvt", jets_jvt->at(ij), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"jet1_dRmin_j", dRmin_jj, nomWeight);
+	}
+
+	if(jets_btagw->at(ij) > 0.645925){
+	  m_hstMngr->FillTH1D(region+"_"+"bjets_pt", jets_pt->at(ij), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"bjets_mass", jets_m->at(ij), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"bjets_eta", jets_eta->at(ij), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"bjets_phi", jets_phi->at(ij), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"bjets_btagw", jets_btagw->at(ij), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"bjets_jvt", jets_jvt->at(ij), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"bjets_dRmin_j", dRmin_jj, nomWeight);
+
+	  if(nbj==0){
+	    m_hstMngr->FillTH1D(region+"_"+"bjet1_pt", jets_pt->at(ij), nomWeight);
+	    m_hstMngr->FillTH1D(region+"_"+"bjet1_mass", jets_m->at(ij), nomWeight);
+	    m_hstMngr->FillTH1D(region+"_"+"bjet1_eta", jets_eta->at(ij), nomWeight);
+	    m_hstMngr->FillTH1D(region+"_"+"bjet1_phi", jets_phi->at(ij), nomWeight);
+	    m_hstMngr->FillTH1D(region+"_"+"bjet1_btagw", jets_btagw->at(ij), nomWeight);
+	    m_hstMngr->FillTH1D(region+"_"+"bjet1_jvt", jets_jvt->at(ij), nomWeight);
+	    m_hstMngr->FillTH1D(region+"_"+"bjet1_dRmin_j", dRmin_jj, nomWeight);
+	  }
+	  nbj++;
+	}//bjet
+	else{
+	  m_hstMngr->FillTH1D(region+"_"+"ljets_pt", jets_pt->at(ij), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"ljets_mass", jets_m->at(ij), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"ljets_eta", jets_eta->at(ij), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"ljets_phi", jets_phi->at(ij), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"ljets_btagw", jets_btagw->at(ij), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"ljets_jvt", jets_jvt->at(ij), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"ljets_dRmin_j", dRmin_jj, nomWeight);
+
+	  if(nbj==0){
+	    m_hstMngr->FillTH1D(region+"_"+"ljet1_pt", jets_pt->at(ij), nomWeight);
+	    m_hstMngr->FillTH1D(region+"_"+"ljet1_mass", jets_m->at(ij), nomWeight);
+	    m_hstMngr->FillTH1D(region+"_"+"ljet1_eta", jets_eta->at(ij), nomWeight);
+	    m_hstMngr->FillTH1D(region+"_"+"ljet1_phi", jets_phi->at(ij), nomWeight);
+	    m_hstMngr->FillTH1D(region+"_"+"ljet1_btagw", jets_btagw->at(ij), nomWeight);
+	    m_hstMngr->FillTH1D(region+"_"+"ljet1_jvt", jets_jvt->at(ij), nomWeight);
+	    m_hstMngr->FillTH1D(region+"_"+"ljet1_dRmin_j", dRmin_jj, nomWeight);
+	  }
+	  nlj++;
+	}//ljet
+
+      }//jet loop
+      m_hstMngr->FillTH1D(region+"_"+"dPhi_jetmet", dPhi_jetmet, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"dRmin_jetjet", dRmin_jetjet, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"dRmin_bb", dRmin_bb, nomWeight);
+
+      if( (i1_mindr_bb >= 0) && (i2_mindr_bb >= 0) ){
+	TLorentzVector tlv_b1;
+	tlv_b1.SetPtEtaPhiM(jets_pt->at(i1_mindr_bb), jets_eta->at(i1_mindr_bb), jets_phi->at(i1_mindr_bb), jets_m->at(i1_mindr_bb));
+	TLorentzVector tlv_b2;
+	tlv_b2.SetPtEtaPhiM(jets_pt->at(i2_mindr_bb), jets_eta->at(i2_mindr_bb), jets_phi->at(i2_mindr_bb), jets_m->at(i2_mindr_bb));
+	TLorentzVector tlv_bb_sys = tlv_b1 + tlv_b2;
+
+	m_hstMngr->FillTH1D(region+"_"+"ptbb_mindr", tlv_bb_sys.Pt(), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"etabb_mindr", tlv_bb_sys.Eta(), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"phibb_mindr", tlv_bb_sys.Phi(), nomWeight);
+      }
+
+      if(i1_mindr_bb >= 0){
+	m_hstMngr->FillTH1D(region+"_"+"bjet1_mindr_pt", jets_pt->at(i1_mindr_bb), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"bjet1_mindr_mass", jets_m->at(i1_mindr_bb), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"bjet1_mindr_eta", jets_eta->at(i1_mindr_bb), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"bjet1_mindr_phi", jets_phi->at(i1_mindr_bb), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"bjet1_mindr_dR_rc", jets_drmin_rc->at(i1_mindr_bb), nomWeight);
+      }
+      if(i2_mindr_bb >= 0){
+	m_hstMngr->FillTH1D(region+"_"+"bjet2_mindr_pt", jets_pt->at(i2_mindr_bb), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"bjet2_mindr_mass", jets_m->at(i2_mindr_bb), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"bjet2_mindr_eta", jets_eta->at(i2_mindr_bb), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"bjet2_mindr_phi", jets_phi->at(i2_mindr_bb), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"bjet2_mindr_dR_rc", jets_drmin_rc->at(i2_mindr_bb), nomWeight);
+      }
+      if(i1_mindr_jj >= 0){
+	m_hstMngr->FillTH1D(region+"_"+"jet1_mindr_pt", jets_pt->at(i1_mindr_jj), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"jet1_mindr_mass", jets_m->at(i1_mindr_jj), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"jet1_mindr_eta", jets_eta->at(i1_mindr_jj), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"jet1_mindr_phi", jets_phi->at(i1_mindr_jj), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"jet1_mindr_dR_rc", jets_drmin_rc->at(i1_mindr_jj), nomWeight);
+      }
+      if(i2_mindr_jj >= 0){
+	m_hstMngr->FillTH1D(region+"_"+"jet2_mindr_pt", jets_pt->at(i2_mindr_jj), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"jet2_mindr_mass", jets_m->at(i2_mindr_jj), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"jet2_mindr_eta", jets_eta->at(i2_mindr_jj), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"jet2_mindr_phi", jets_phi->at(i2_mindr_jj), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"jet2_mindr_dR_rc", jets_drmin_rc->at(i2_mindr_jj), nomWeight);
+      }
+
+      if(el_n + mu_n > 0){
+	m_hstMngr->FillTH1D(region+"_"+"dPhi_lepbjet", dPhi_lepbjet, nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"dPhi_lepjet", dPhi_lepjet, nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"dPhi_lepmet", dPhi_lepmet, nomWeight);
+      }
+      if(el_n > 0){
+	m_hstMngr->FillTH1D(region+"_"+"dRmin_ebjets", dRmin_ebjets, nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"dRmin_ejets", dRmin_ejets, nomWeight);
+      }
+
+      if(mu_n > 0){
+	m_hstMngr->FillTH1D(region+"_"+"dRmin_mubjets", dRmin_mubjets, nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"dRmin_mujets", dRmin_mujets, nomWeight);
+
+      }
+
+      m_hstMngr->FillTH1D(region+"_"+"mT_bmin", mT_bmin, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"mbb_mindr", mbb_mindr, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"meff", meff, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"hthad", hthad, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"met", met, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"met_phi", met_phi, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"mtw", mtw, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"el1_pt", el1_pt, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"el1_eta", el1_eta, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"el1_phi", el1_phi, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"mu1_pt", mu1_pt, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"mu1_eta", mu1_eta, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"mu1_phi", mu1_phi, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"npv", npv, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"pileup_mu", pileup_mu, nomWeight);
+
+      m_hstMngr->FillTH1D(region+"_"+"fjets_n", fjets_n, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"rcjets_n", rcjets_n, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"jets_n", jets_n, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"bjets_n", bjets_n, nomWeight);
+
+      if(dolowb){
+	m_hstMngr->FillTH1D(region+"_"+"dRmin_bb_lowb_3b", dRmin_bb_lowb_3b, nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"mT_bmin_lowb_3b", mT_bmin_lowb_3b, nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"mbb_mindr_lowb_3b", mbb_mindr_lowb_3b, nomWeight);
+
+	m_hstMngr->FillTH1D(region+"_"+"dRmin_bb_lowb_4b", dRmin_bb_lowb_4b, nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"mT_bmin_lowb_4b", mT_bmin_lowb_4b, nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"mbb_mindr_lowb_4b", mbb_mindr_lowb_4b, nomWeight);
+      }
+    }// Regions
+    
+  }//Event loop
+
+  TFile* outfile = TFile::Open(argv[2], "RECREATE");
+  outfile->cd(); 
+  for( const std::string hist : m_hstMngr->GetTH1KeyList() ){
+    m_hstMngr->FinaliseTH1Bins(hist); 
+    m_hstMngr->GetTH1D(hist)->Write();
+  }
+
+  outfile->Close();
+  delete outfile;
+  
+  m_hstMngr->ClearAllTH1();
+  m_hstMngr->ClearAllTH2();
+  delete m_hstMngr;
+  delete fChain; 
+  
+  return 0;
+  
+}
+  
+  
diff --git a/macros/macros_trisha/LowBTemplateMaker.cxx b/macros/macros_trisha/LowBTemplateMaker.cxx
new file mode 100644
index 0000000..8fe390f
--- /dev/null
+++ b/macros/macros_trisha/LowBTemplateMaker.cxx
@@ -0,0 +1,260 @@
+#include <TH1D.h>
+#include <TFile.h>
+#include <TLorentzVector.h>
+#include <TH1.h>
+#include <vector>
+#include <string>
+#include <iostream>
+
+
+TFile* m_infile;
+TFile* m_outfile;
+
+bool m_useOnlyMuons;
+double m_sc_etomu = 1.;
+std::vector<std::string> m_variables{"meff", "hthad", "met_zoom", "mtw_zoom", "ptw_zoom", 
+    "RCTTMass_jets_n", "jets_n", "jets_pt", "jets_eta", "lep0_pt_zoom", "lep0_eta", 
+    "mtbmin_lowb_3b_zoom", "mtbmin_lowb_4b_zoom"};
+
+std::vector<std::string> m_jets{"", "5j", "6j"};
+std::vector<std::string> m_toptags{"2RCTTMass","1RCTTMass","0RCTTMass"};
+std::vector<std::string> m_target_btags{"1b"};//, "2b", "3b", "4b"};
+std::vector<std::string> m_target_btags_6j_noPresel{};//"3bHighMbb", "3bLowMbb", "4bHighMbb", "4bLowMbb"};
+
+std::vector<std::string> m_source_btags{"0b", "1b", "2b", "3b", "4b"};
+
+std::vector<std::string> m_source_btags_3bHighMbb{};//"0bHighMbb_3b","1bHighMbb_3b","2bHighMbb_3b", "3bHighMbb"};
+std::vector<std::string> m_source_btags_4bHighMbb{};//"0bHighMbb_4b","1bHighMbb_4b","2bHighMbb_4b", "4bHighMbb"};
+std::vector<std::string> m_source_btags_3bLowMbb{};//"0bLowMbb_3b","1bLowMbb_3b","2bLowMbb_3b", "3bLowMbb"};
+std::vector<std::string> m_source_btags_4bLowMbb{};//"0bLowMbb_4b","1bLowMbb_4b","2bLowMbb_4b", "4bLowMbb"};
+std::vector<std::string> m_lepchannels{"", "_e", "_mu"};
+
+TH1D* MakeLowBSourceTemplate(const std::string& variable, const std::string& ch_jet, const std::string& ch_lep,
+			     const std::string& ch_topjet="", const std::string& ch_mbb="" );
+void MakeLowBTemplate(const std::string& variable, TH1D* temp_lowb, const std::string& ch_jet, const std::string& ch_bjet, const std::string& ch_lep,
+		      const std::string& ch_topjet="" );
+
+ 
+int main(int argc, char** argv){
+
+  if(argc<2){ std::cout<<"Provide name of file from which to read inputs; name of file to write to"<<std::endl; }
+
+  m_infile = TFile::Open(argv[1], "READ");
+  m_outfile = TFile::Open(argv[2], "RECREATE");
+
+  m_useOnlyMuons = atoi(argv[3]) > 0;
+
+  //Find scaling factor;
+  m_sc_etomu = 1.;
+  double e_sc = 1.; double mu_sc = 1.;
+
+  TH1D* presel_el = ((TH1D*)(m_infile->Get("c1l2b_e_meff")));
+  if(presel_el){ e_sc = presel_el->Integral(); }
+  else{ std::cerr << " Cannot find preselection electron histogram " << std::endl; exit(1); }
+  presel_el->SetDirectory(0);
+
+  TH1D* presel_mu = ((TH1D*)(m_infile->Get("c1l2b_mu_meff")));
+  if(presel_mu){ mu_sc = presel_mu->Integral(); }
+  else{ std::cerr << " Cannot find preselection muon histogram " << std::endl; exit(1); }
+  presel_mu->SetDirectory(0);
+
+  m_sc_etomu = e_sc/mu_sc;
+
+  delete presel_el; delete presel_mu;
+
+  //------------------ 0b -----------------
+  //Find scaling factor;
+  double m_sc_etomu_0b = 1.;
+  double e_sc_0b = 1.; double mu_sc_0b = 1.;
+
+  TH1D* presel_0b_el = ((TH1D*)(m_infile->Get("c1l0b_e_meff")));
+  if(presel_0b_el){ e_sc_0b = presel_0b_el->Integral(); }
+  else{ std::cerr << " Cannot find preselection electron histogram " << std::endl; exit(1); }
+  presel_0b_el->SetDirectory(0);
+
+  TH1D* presel_0b_mu = ((TH1D*)(m_infile->Get("c1l0b_mu_meff")));
+  if(presel_0b_mu){ mu_sc_0b = presel_0b_mu->Integral(); }
+  else{ std::cerr << " Cannot find preselection muon histogram " << std::endl; exit(1); }
+  presel_0b_mu->SetDirectory(0);
+
+  m_sc_etomu_0b = e_sc_0b/mu_sc_0b;
+
+
+  //------------------- 1b  ---------------
+
+  //Find scaling factor;
+  double m_sc_etomu_1b = 1.;
+  double e_sc_1b = 1.; double mu_sc_1b = 1.;
+
+  TH1D* presel_1b_el = ((TH1D*)(m_infile->Get("c1l1b_e_meff")));
+  if(presel_1b_el){ e_sc_1b = presel_1b_el->Integral(); }
+  else{ std::cerr << " Cannot find preselection electron histogram " << std::endl; exit(1); }
+  presel_1b_el->SetDirectory(0);
+
+  TH1D* presel_1b_mu = ((TH1D*)(m_infile->Get("c1l1b_mu_meff")));
+  if(presel_1b_mu){ mu_sc_1b = presel_1b_mu->Integral(); }
+  else{ std::cerr << " Cannot find preselection muon histogram " << std::endl; exit(1); }
+  presel_1b_mu->SetDirectory(0);
+
+  m_sc_etomu_1b = e_sc_1b/mu_sc_1b;
+
+  std::cout<< "m_sc_etomu = "<<m_sc_etomu<<std::endl;
+  std::cout<< "m_sc_etomu_0b = "<<m_sc_etomu_0b<<std::endl;
+  std::cout<< "m_sc_etomu_1b = "<<m_sc_etomu_1b<<std::endl;
+  m_sc_etomu = m_sc_etomu_1b; //ALERTRISHA
+
+  std::string chjet_ie = ""; std::string chbjet_ie="";
+
+  for(const std::string var : m_variables){
+
+    //----------------------------------------
+
+    for( const std::string chjet : m_jets ){
+      if(chjet.empty()){ chjet_ie = ""; }
+      else{ chjet_ie = (chjet == "5j") ? chjet+"e" : chjet+"i"; }
+
+      for(const std::string chlep : m_lepchannels){
+
+	//========= Presel ==========================
+	TH1D* temp_lowb = NULL;
+	temp_lowb = MakeLowBSourceTemplate(var, chjet_ie, chlep);
+
+	for(const std::string chbjet : m_target_btags){
+	  if(chjet.empty() ){ 
+	    if( (chbjet == "3b") || (chbjet == "4b") ){ continue; } 
+	    chbjet_ie = chbjet;
+	  }
+	  else{ chbjet_ie = (chbjet == "4b") ? chbjet+"i" : chbjet+"e"; }
+
+	  MakeLowBTemplate(var, temp_lowb, chjet_ie, chbjet_ie, chlep);
+	  chbjet_ie.clear();
+	}
+	m_outfile->cd();
+	temp_lowb->Write(); 
+	delete temp_lowb;
+
+	if(chjet.empty() ){ continue; } //Only preselection if no jet multiplicity specified
+
+	std::cout<<"  ============= Preselection Done for chjet = "<<chjet<<" chlep = "<<chlep<<std::endl;
+	//============ Analysis regions ================================
+	for(const std::string chtopjet : m_toptags){
+
+	  //No Mbb splitting first
+	  temp_lowb = MakeLowBSourceTemplate(var, chjet, chlep, chtopjet);
+	  for(const std::string chbjet : m_target_btags){
+	    MakeLowBTemplate(var, temp_lowb, chjet, chbjet, chlep, chtopjet);
+	  }
+	  m_outfile->cd();
+	  temp_lowb->Write(); 
+	  delete temp_lowb;
+
+	  if(chjet == "6j"){
+	    //Mbb splitting
+	    for(const std::string chmbb : m_target_btags_6j_noPresel){
+	      temp_lowb = MakeLowBSourceTemplate(var, chjet, chlep, chtopjet, chmbb); 
+	      MakeLowBTemplate(var, temp_lowb, chjet, chmbb, chlep, chtopjet);
+	      m_outfile->cd();
+	      temp_lowb->Write(); 
+	      delete temp_lowb;
+	    }//Mbb channels
+	  }//6 jet channels
+
+	}//top-tag channels
+
+      }//lepton channels
+
+      chjet_ie.clear();
+    }//jet channels
+  }//variable loop
+  m_outfile->Close();
+  m_infile->Close();
+  return 0; 
+}
+
+//Return the summed low-b source template
+TH1D* MakeLowBSourceTemplate(const std::string& variable, const std::string& ch_jet, const std::string& ch_lep,
+			     const std::string& ch_topjet, const std::string& ch_mbb){
+
+
+  //std::cout<<"Inside MakeLowBSourceTemplate ::  ch_jet = "<<ch_jet<<" ch_lep = "<<ch_lep<<" ch_topjet = "<<ch_topjet<<" ch_mbb = "<<ch_mbb<<" variable = "<<variable<<std::endl;   
+  //----------------------------------------------------------------------------------------------
+  TH1D* temp_lowb=NULL;
+
+  std::vector<std::string>* source_btags = &m_source_btags;
+
+  
+  if     (ch_mbb == "3bHighMbb"){ source_btags = &m_source_btags_3bHighMbb; }
+  else if(ch_mbb == "4bHighMbb"){ source_btags = &m_source_btags_4bHighMbb; }
+  else if(ch_mbb == "3bLowMbb") { source_btags = &m_source_btags_3bLowMbb; }
+  else if(ch_mbb == "4bLowMbb") { source_btags = &m_source_btags_4bLowMbb; }
+
+  //Make a "source" low-b template by looping over the source b-tag regions and adding them together
+  std::string chbjet_ie = "";
+  for(const std::string chb_lowb : *source_btags){
+
+    if(ch_jet.empty()){ 
+      if( (chb_lowb == "3b") || (chb_lowb == "4b") ){ continue; }
+      chbjet_ie = chb_lowb;
+    }
+    else{
+      if(ch_topjet == ""){
+	chbjet_ie = (chb_lowb == "4b") ? chb_lowb +"i" : chb_lowb+"e";
+      }
+      else{ chbjet_ie = chb_lowb; }
+    }
+    std::string var_lowb = (m_useOnlyMuons) ? "c1l"+ch_topjet+ch_jet+chbjet_ie+"_mu"+"_"+variable : "c1l"+ch_topjet+ch_jet+chbjet_ie+ch_lep+"_"+variable;
+    if(temp_lowb==NULL){
+      temp_lowb = (TH1D*)(m_infile->Get(var_lowb.c_str()));
+      temp_lowb->SetDirectory(0);
+    }
+    else{ temp_lowb -> Add ( (TH1D*)(m_infile->Get(var_lowb.c_str())) ); }
+    var_lowb.clear();
+  }
+  std::string var_lowb_NEW = "source_c1l"+ch_topjet+ch_jet+ch_mbb+ch_lep+"_"+variable;
+
+  temp_lowb->SetName(var_lowb_NEW.c_str());
+  var_lowb_NEW.clear();
+  //--------------------------------------------------------------------------------------------
+  source_btags = NULL;
+  return temp_lowb;
+
+}
+
+void MakeLowBTemplate(const std::string& variable, TH1D* temp_lowb, const std::string& ch_jet, const std::string& ch_bjet, const std::string& ch_lep,
+		      const std::string& ch_topjet){
+
+  std::string target_temp_name = "c1l"+ch_topjet+ch_jet+ch_bjet+ch_lep+"_"+variable;
+  std::string target_dist = (m_useOnlyMuons) ? "c1l"+ch_topjet+ch_jet+ch_bjet+"_mu_"+variable : target_temp_name;
+  std::string target_dist_NEW = "orig_c1l"+ch_topjet+ch_jet+ch_bjet+ch_lep+"_"+variable;
+
+  TH1D* targethist = (TH1D*)(m_infile->Get(target_dist.c_str()));
+  targethist->SetDirectory(0); //because this also needs to be written to the new file
+  targethist->SetName(target_dist_NEW.c_str());
+  double target_intgl = targethist->Integral();
+
+  TH1D* target_temp = (TH1D*)(temp_lowb->Clone(target_dist.c_str()));
+  target_temp->SetDirectory(0);
+  double source_intgl = temp_lowb->Integral();
+ 
+  if( source_intgl > 0){
+    target_temp->Scale(target_intgl/source_intgl);
+  }
+
+  //If using muon channel only, do appropriate scaling
+  if(m_useOnlyMuons){
+    if(ch_lep=="_e"){ target_temp->Scale(m_sc_etomu); }
+    if(ch_lep=="")  { target_temp->Scale(1+m_sc_etomu); }
+  }
+
+  target_temp->SetName(target_temp_name.c_str());
+
+  m_outfile->cd();
+  targethist->Write();
+  target_temp->Write();
+
+  return;
+
+}
+
+  
+  
diff --git a/macros/macros_trisha/VLQReclustering.cxx b/macros/macros_trisha/VLQReclustering.cxx
index 4803ad4..bfb962c 100644
--- a/macros/macros_trisha/VLQReclustering.cxx
+++ b/macros/macros_trisha/VLQReclustering.cxx
@@ -10,9 +10,14 @@
 int main(int argc, char** argv){
 
   bool isdata = ( atoi(argv[3]) > 0 );
-  bool istt = ( atoi(argv[4]) > 0 );
+  bool isttlight = ( atoi(argv[4]) == 1 );
+  bool isttbb = ( atoi(argv[4]) == 2 );
+  bool isvjets22 = ( atoi(argv[4]) == 3 );
+  bool isqcd = ( atoi(argv[4]) == 4 );
+  bool dolowb = ( atoi(argv[6]) > 0 );
+  std::string qcdconfig = Form("Loose_test2015config%i", atoi(argv[5]));
 
-  if(argc<5){ std::cout<<"Provide name of file from which to read chain; name of file to write to; isdata; istt"<<std::endl; }
+  if(argc<6){ std::cout<<"Provide name of file from which to read chain; name of file to write to; isdata; istt"<<std::endl; }
 
 
   //_______________________ SET UP THE CHAIN ________________________
@@ -23,21 +28,28 @@ int main(int argc, char** argv){
   // Declaration of leaf types
   Double_t        nomWeight;
 
-  Float_t         nomWeight_weight_bTagSF_77;
-  Float_t         nomWeight_weight_indiv_SF_EL_ID;
-  Float_t         nomWeight_weight_indiv_SF_EL_Isol;
-  Float_t         nomWeight_weight_indiv_SF_EL_Reco;
-  Float_t         nomWeight_weight_indiv_SF_MU_ID;
-  Float_t         nomWeight_weight_indiv_SF_MU_Isol;
-  Float_t         nomWeight_weight_indiv_SF_MU_TTVA;
-  Float_t         nomWeight_weight_indiv_SF_MU_Trigger;
+  Float_t         nomWeight_weight_btag;
+  Float_t         nomWeight_weight_leptonSF;
   Float_t         nomWeight_weight_jvt;
   Float_t         nomWeight_weight_mc;
   Double_t        nomWeight_weight_norm;
   Float_t         nomWeight_weight_pileup;
   //Double_t        nomWeight_weight_ttbar_fractions_rw;
+  Float_t        nomWeight_weight_ttbar_nnlo;
   Double_t        nomWeight_weight_ttbb;
-  Double_t        nomWeight_weight_ttbar_NNLO;
+  Float_t         nomWeight_weight_sherpa_22_vjets;
+
+  Float_t        nomWeight_fakesMM_weight_ejets_2015;
+  //Float_t        nomWeight_fakesMM_weight_ejets_2016;
+  Float_t        nomWeight_fakesMM_weight_mujets_2015;
+  Float_t        nomWeight_fakesMM_weight_mujets_2016;
+
+  Int_t           channel;
+  Int_t           run_number;
+  Int_t           data_period;
+
+  Int_t           npv;
+  Double_t        pileup_mu;
 
   Int_t           bjets_n;
   Double_t        dPhi_jetmet;
@@ -71,14 +83,27 @@ int main(int argc, char** argv){
   std::vector<double>*        jets_m;
   std::vector<double>*        jets_phi;
   std::vector<double>*        jets_pt;
+  std::vector<double>*        jets_drmin_rc = new std::vector<double>; //input : 0
+
   Int_t           jets_n;
   Int_t           lep_n;
   Double_t        mT_bmin;
   Double_t        mbb_mindr;
+
+  Double_t        mT_bmin_lowb_3b;
+  Double_t        mbb_mindr_lowb_3b;
+  Double_t        dRmin_bb_lowb_3b;
+
+  Double_t        mT_bmin_lowb_4b;
+  Double_t        mbb_mindr_lowb_4b;
+  Double_t        dRmin_bb_lowb_4b;
+
+
   Double_t        meff;
   Double_t        met;
   Double_t        met_phi;
   Double_t        mtw;
+  Double_t        ptw;
   Double_t        mu1_eta;
   Double_t        mu1_phi;
   Double_t        mu1_pt;
@@ -94,22 +119,27 @@ int main(int argc, char** argv){
 
   // List of branches
   //TBranch        *b_nomWeight; //!
+
+  TBranch        *b_channel;   //!
+  TBranch        *b_data_period;   //!
+  TBranch        *b_run_number;   //!
+  TBranch        *b_npv;   //!
+  TBranch        *b_pileup_mu;   //!
   
-  TBranch        *b_nomWeight_weight_bTagSF_77;   //!
-  TBranch        *b_nomWeight_weight_indiv_SF_EL_ID;   //!
-  TBranch        *b_nomWeight_weight_indiv_SF_EL_Isol;   //!
-  TBranch        *b_nomWeight_weight_indiv_SF_EL_Reco;   //!
-  TBranch        *b_nomWeight_weight_indiv_SF_MU_ID;   //!
-  TBranch        *b_nomWeight_weight_indiv_SF_MU_Isol;   //!
-  TBranch        *b_nomWeight_weight_indiv_SF_MU_TTVA;   //!
-  TBranch        *b_nomWeight_weight_indiv_SF_MU_Trigger;   //!
+  TBranch        *b_nomWeight_weight_btag;   //!
+  TBranch        *b_nomWeight_weight_leptonSF;   //!
   TBranch        *b_nomWeight_weight_jvt;   //!
   TBranch        *b_nomWeight_weight_mc;   //!
   TBranch        *b_nomWeight_weight_norm;   //!
   TBranch        *b_nomWeight_weight_pileup;   //!
-  //TBranch        *b_nomWeight_weight_ttbar_fractions_rw;   //!
   TBranch        *b_nomWeight_weight_ttbb;   //!
-  TBranch        *b_nomWeight_weight_ttbar_NNLO;   //!
+  TBranch        *b_nomWeight_weight_ttbar_nnlo;   //!
+  TBranch        *b_nomWeight_weight_sherpa_22_vjets; //!
+
+  TBranch        *b_nomWeight_fakesMM_weight_ejets_2015;
+  //TBranch        *b_nomWeight_fakesMM_weight_ejets_2016;
+  TBranch        *b_nomWeight_fakesMM_weight_mujets_2015;
+  TBranch        *b_nomWeight_fakesMM_weight_mujets_2016;
   
   TBranch        *b_bjets_n;   //!
   TBranch        *b_dPhi_jetmet;   //!
@@ -141,6 +171,15 @@ int main(int argc, char** argv){
   TBranch        *b_lep_n;   //!
   TBranch        *b_mT_bmin;   //!
   TBranch        *b_mbb_mindr;   //!
+
+  TBranch        *b_mT_bmin_lowb_3b; //!
+  TBranch        *b_mbb_mindr_lowb_3b; //!
+  TBranch        *b_dRmin_bb_lowb_3b; //!
+
+  TBranch        *b_mT_bmin_lowb_4b; //!
+  TBranch        *b_mbb_mindr_lowb_4b; //!
+  TBranch        *b_dRmin_bb_lowb_4b; //!
+
   TBranch        *b_meff;   //!
   TBranch        *b_met;   //!
   TBranch        *b_met_phi;   //!
@@ -181,23 +220,40 @@ int main(int argc, char** argv){
 
   //fChain->SetBranchAddress("nomWeight", &nomWeight, &b_nomWeight);
   if(!isdata){
-    fChain->SetBranchAddress("nomWeight_weight_bTagSF_77", &nomWeight_weight_bTagSF_77, &b_nomWeight_weight_bTagSF_77);
-    fChain->SetBranchAddress("nomWeight_weight_indiv_SF_EL_ID", &nomWeight_weight_indiv_SF_EL_ID, &b_nomWeight_weight_indiv_SF_EL_ID);
-    fChain->SetBranchAddress("nomWeight_weight_indiv_SF_EL_Isol", &nomWeight_weight_indiv_SF_EL_Isol, &b_nomWeight_weight_indiv_SF_EL_Isol);
-    fChain->SetBranchAddress("nomWeight_weight_indiv_SF_EL_Reco", &nomWeight_weight_indiv_SF_EL_Reco, &b_nomWeight_weight_indiv_SF_EL_Reco);
-    fChain->SetBranchAddress("nomWeight_weight_indiv_SF_MU_ID", &nomWeight_weight_indiv_SF_MU_ID, &b_nomWeight_weight_indiv_SF_MU_ID);
-    fChain->SetBranchAddress("nomWeight_weight_indiv_SF_MU_Isol", &nomWeight_weight_indiv_SF_MU_Isol, &b_nomWeight_weight_indiv_SF_MU_Isol);
-    fChain->SetBranchAddress("nomWeight_weight_indiv_SF_MU_TTVA", &nomWeight_weight_indiv_SF_MU_TTVA, &b_nomWeight_weight_indiv_SF_MU_TTVA);
-    fChain->SetBranchAddress("nomWeight_weight_indiv_SF_MU_Trigger", &nomWeight_weight_indiv_SF_MU_Trigger, &b_nomWeight_weight_indiv_SF_MU_Trigger);
-    fChain->SetBranchAddress("nomWeight_weight_jvt", &nomWeight_weight_jvt, &b_nomWeight_weight_jvt);
-    fChain->SetBranchAddress("nomWeight_weight_mc", &nomWeight_weight_mc, &b_nomWeight_weight_mc);
-    fChain->SetBranchAddress("nomWeight_weight_norm", &nomWeight_weight_norm, &b_nomWeight_weight_norm);
-    fChain->SetBranchAddress("nomWeight_weight_pileup", &nomWeight_weight_pileup, &b_nomWeight_weight_pileup);
-    if(istt){
-      fChain->SetBranchAddress("nomWeight_weight_ttbb", &nomWeight_weight_ttbb, &b_nomWeight_weight_ttbb);
-      fChain->SetBranchAddress("nomWeight_weight_ttbar_NNLO", &nomWeight_weight_ttbar_NNLO, &b_nomWeight_weight_ttbar_NNLO);
+    if(isqcd){
+      fChain->SetBranchAddress(Form("nomWeight_fakesMM_weight_ejets_2015_%s", qcdconfig.c_str()), &nomWeight_fakesMM_weight_ejets_2015
+			       , &b_nomWeight_fakesMM_weight_ejets_2015);
+      //fChain->SetBranchAddress(Form("nomWeight_fakesMM_weight_ejets_2016_%s", qcdconfig.c_str()), &nomWeight_fakesMM_weight_ejets_2016
+      //		       , &b_nomWeight_fakesMM_weight_ejets_2016);
+      fChain->SetBranchAddress(Form("nomWeight_fakesMM_weight_mujets_2015_%s", qcdconfig.c_str()), &nomWeight_fakesMM_weight_mujets_2015
+			       , &b_nomWeight_fakesMM_weight_mujets_2015);
+      fChain->SetBranchAddress(Form("nomWeight_fakesMM_weight_mujets_2016_%s", qcdconfig.c_str()), &nomWeight_fakesMM_weight_mujets_2016
+			       , &b_nomWeight_fakesMM_weight_mujets_2016);
     }
-  }
+    else{
+      fChain->SetBranchAddress("nomWeight_weight_btag", &nomWeight_weight_btag, &b_nomWeight_weight_btag);
+      fChain->SetBranchAddress("nomWeight_weight_leptonSF", &nomWeight_weight_leptonSF, &b_nomWeight_weight_leptonSF);
+      fChain->SetBranchAddress("nomWeight_weight_jvt", &nomWeight_weight_jvt, &b_nomWeight_weight_jvt);
+      fChain->SetBranchAddress("nomWeight_weight_mc", &nomWeight_weight_mc, &b_nomWeight_weight_mc);
+      fChain->SetBranchAddress("nomWeight_weight_norm", &nomWeight_weight_norm, &b_nomWeight_weight_norm);
+      fChain->SetBranchAddress("nomWeight_weight_pileup", &nomWeight_weight_pileup, &b_nomWeight_weight_pileup);
+      if(isttbb){
+	fChain->SetBranchAddress("nomWeight_weight_ttbb", &nomWeight_weight_ttbb, &b_nomWeight_weight_ttbb);
+      }
+      if(isttlight){
+	fChain->SetBranchAddress("nomWeight_weight_ttbar_nnlo", &nomWeight_weight_ttbar_nnlo, &b_nomWeight_weight_ttbar_nnlo);
+      }
+      else if(isvjets22){
+	fChain->SetBranchAddress("nomWeight_weight_sherpa_22_vjets", &nomWeight_weight_sherpa_22_vjets, &b_nomWeight_weight_sherpa_22_vjets);
+      }//vjets_22
+    }//!qcd
+  }//!data
+
+  fChain->SetBranchAddress("channel", &channel, &b_channel);
+  fChain->SetBranchAddress("run_number", &run_number, &b_run_number);
+  fChain->SetBranchAddress("data_period", &data_period, &b_data_period);
+  fChain->SetBranchAddress("npv", &npv, &b_npv);
+  fChain->SetBranchAddress("pileup_mu", &pileup_mu, &b_pileup_mu);
 
   fChain->SetBranchAddress("bjets_n", &bjets_n, &b_bjets_n);
   fChain->SetBranchAddress("dPhi_jetmet", &dPhi_jetmet, &b_dPhi_jetmet);
@@ -234,6 +290,15 @@ int main(int argc, char** argv){
   fChain->SetBranchAddress("lep_n", &lep_n, &b_lep_n);
   fChain->SetBranchAddress("mT_bmin", &mT_bmin, &b_mT_bmin);
   fChain->SetBranchAddress("mbb_mindr", &mbb_mindr, &b_mbb_mindr);
+  if(dolowb){
+    fChain->SetBranchAddress("mT_bmin_lowb_3b", &mT_bmin_lowb_3b, &b_mT_bmin_lowb_3b);
+    fChain->SetBranchAddress("mbb_mindr_lowb_3b", &mbb_mindr_lowb_3b, &b_mbb_mindr_lowb_3b);
+    fChain->SetBranchAddress("dRmin_bb_lowb_3b", &dRmin_bb_lowb_3b, &b_dRmin_bb_lowb_3b);
+
+    fChain->SetBranchAddress("mT_bmin_lowb_4b", &mT_bmin_lowb_4b, &b_mT_bmin_lowb_4b);
+    fChain->SetBranchAddress("mbb_mindr_lowb_4b", &mbb_mindr_lowb_4b, &b_mbb_mindr_lowb_4b);
+    fChain->SetBranchAddress("dRmin_bb_lowb_4b", &dRmin_bb_lowb_4b, &b_dRmin_bb_lowb_4b);
+  }
   fChain->SetBranchAddress("meff", &meff, &b_meff);
   fChain->SetBranchAddress("met", &met, &b_met);
   fChain->SetBranchAddress("met_phi", &met_phi, &b_met_phi);
@@ -255,46 +320,188 @@ int main(int argc, char** argv){
 
   std::vector<std::string> regions; regions.clear();
 
-  regions.push_back("0lep"); 
-  regions.push_back("0lep_RC1M_nsj1"); 
+  //regions.push_back("0lep"); 
+
+  //regions.push_back("0lep_period2015"); 
+  //regions.push_back("0lep_period2016"); 
+  /*
+  regions.push_back("0lep_lowmu"); 
+  regions.push_back("0lep_highmu"); 
+  */
+  //regions.push_back("1lep"); 
+  //regions.push_back("1elmu"); 
+  /*
+  regions.push_back("1elmu"); 
+  regions.push_back("1el"); 
+  regions.push_back("1mu"); 
+  regions.push_back("1elmu_period2015"); 
+  regions.push_back("1elmu_period2016"); 
+  regions.push_back("1el_period2015"); 
+  regions.push_back("1el_period2016"); 
+  regions.push_back("1mu_period2015"); 
+  regions.push_back("1mu_period2016"); 
+  */
+
+  regions.push_back("metmtwinc_1el_0bex");
+  regions.push_back("metmtwinc_1mu_0bex");
+
+  regions.push_back("metmtwinc_1el_1bex");
+  regions.push_back("metmtwinc_1mu_1bex");
+
+  regions.push_back("metmtwinc_1el_2bin");
+  regions.push_back("metmtwinc_1mu_2bin");
+
+  regions.push_back("1el_0bex");
+  regions.push_back("1mu_0bex");
+
+  regions.push_back("1el_1bex");
+  regions.push_back("1mu_1bex");
+
+  regions.push_back("1el_2bin");
+  regions.push_back("1mu_2bin");
+
+  /*
+  regions.push_back("1elmu_lowmu"); 
+  regions.push_back("1elmu_highmu"); 
+  regions.push_back("1el_lowmu"); 
+  regions.push_back("1el_highmu"); 
+  regions.push_back("1mu_lowmu"); 
+  regions.push_back("1mu_highmu"); 
+  */
+  //regions.push_back("0lep_RC1M_nsj1"); 
+  //regions.push_back("0lep_RC1M_mwin"); 
+  //regions.push_back("0lep_RC1M_moutwin"); 
+
+  /*
   regions.push_back("0lep_RC1M_nsj2"); 
   regions.push_back("0lep_RC1M_nsjge3"); 
 
-  regions.push_back("0lep_RC1M_mwin"); 
-  regions.push_back("0lep_RC1M_moutwin"); 
 
   regions.push_back("0lep_RC1M_nsj2_mwin"); 
   regions.push_back("0lep_RC1M_nsj2_moutwin"); 
-
+  */
   HistManager* m_hstMngr = new HistManager(true, true);
+  
   //-------------------------------
+  std::vector<std::string> correlations;
+  /*
+  correlations.push_back("bjets_eta_vs_phi");
+  correlations.push_back("ljets_eta_vs_phi");
+  correlations.push_back("jets_eta_vs_phi");
+  correlations.push_back("rcjets_eta_vs_phi");
+
+  correlations.push_back("bjet1_eta_vs_phi");
+  correlations.push_back("ljet1_eta_vs_phi");
+  correlations.push_back("jet1_eta_vs_phi");
+  correlations.push_back("rcjet1_eta_vs_phi");
+
+  correlations.push_back("bjets_rc1_eta_vs_phi");
+  correlations.push_back("ljets_rc1_eta_vs_phi");
+  correlations.push_back("jets_rc1_eta_vs_phi");
+
+  //--------- Energy-weighted -------------------------
+
+  correlations.push_back("nrg_tot_bjets_eta_vs_phi");
+  correlations.push_back("nrg_tot_ljets_eta_vs_phi");
+  correlations.push_back("nrg_tot_jets_eta_vs_phi");
+  correlations.push_back("nrg_tot_rcjets_eta_vs_phi");
+
+  correlations.push_back("nrg_tot_bjet1_eta_vs_phi");
+  correlations.push_back("nrg_tot_ljet1_eta_vs_phi");
+  correlations.push_back("nrg_tot_jet1_eta_vs_phi");
+  correlations.push_back("nrg_tot_rcjet1_eta_vs_phi");
+
+  correlations.push_back("nrg_tot_bjets_rc1_eta_vs_phi");
+  correlations.push_back("nrg_tot_ljets_rc1_eta_vs_phi");
+  correlations.push_back("nrg_tot_jets_rc1_eta_vs_phi");
+
+  //--------- Average Energy-weighted -------------------------
+
+  correlations.push_back("nrg_avg_bjets_eta_vs_phi");
+  correlations.push_back("nrg_avg_ljets_eta_vs_phi");
+  correlations.push_back("nrg_avg_jets_eta_vs_phi");
+  correlations.push_back("nrg_avg_rcjets_eta_vs_phi");
+
+  correlations.push_back("nrg_avg_bjet1_eta_vs_phi");
+  correlations.push_back("nrg_avg_ljet1_eta_vs_phi");
+  correlations.push_back("nrg_avg_jet1_eta_vs_phi");
+  correlations.push_back("nrg_avg_rcjet1_eta_vs_phi");
+
+  correlations.push_back("nrg_avg_bjets_rc1_eta_vs_phi");
+  correlations.push_back("nrg_avg_ljets_rc1_eta_vs_phi");
+  correlations.push_back("nrg_avg_jets_rc1_eta_vs_phi");
+*/
+
+
   std::vector<std::string> variables;
+
+  variables.push_back("npv");
+  variables.push_back("pileup_mu");
+
   variables.push_back("fjets_n");
   variables.push_back("rcjets_n");
   variables.push_back("jets_n");
   variables.push_back("bjets_n");
 
-  variables.push_back("el_loose_n");
-  variables.push_back("mu_loose_n");
-  variables.push_back("lep_loose_n");
+  //variables.push_back("el_loose_n");
+  //variables.push_back("mu_loose_n");
+  //variables.push_back("lep_loose_n");
 
   variables.push_back("dPhi_jetmet");
-  /*
-  variables.push_back("dPhi_lepbjet");
-  variables.push_back("dPhi_lepjet");
-  variables.push_back("dPhi_lepmet");
-  */
-  /*
-  variables.push_back("dRmin_ebjets");
-  variables.push_back("dRmin_ejets");
-  variables.push_back("dRmin_mubjets");
-  variables.push_back("dRmin_mujets");
-  */
+
+  //variables.push_back("dPhi_lepbjet");
+  //variables.push_back("dPhi_lepjet");
+  //variables.push_back("dPhi_lepmet");
+
+  //variables.push_back("dRmin_ebjets");
+  //variables.push_back("dRmin_ejets");
+  //variables.push_back("dRmin_mubjets");
+  //variables.push_back("dRmin_mujets");
+
   variables.push_back("dRmin_bb");
   variables.push_back("dRmin_jetjet");
 
   variables.push_back("mT_bmin");
   variables.push_back("mbb_mindr");
+  variables.push_back("ptbb_mindr");
+  variables.push_back("etabb_mindr");
+  variables.push_back("phibb_mindr");
+
+  if(dolowb){
+    variables.push_back("dRmin_bb_lowb_3b");
+    variables.push_back("mT_bmin_lowb_3b");
+    variables.push_back("mbb_mindr_lowb_3b");
+
+    variables.push_back("dRmin_bb_lowb_4b");
+    variables.push_back("mT_bmin_lowb_4b");
+    variables.push_back("mbb_mindr_lowb_4b");
+  }
+
+  variables.push_back("bjet1_mindr_pt");
+  variables.push_back("bjet1_mindr_mass");
+  variables.push_back("bjet1_mindr_eta");
+  variables.push_back("bjet1_mindr_phi");
+  variables.push_back("bjet1_mindr_dR_rc");
+
+  variables.push_back("bjet2_mindr_pt");
+  variables.push_back("bjet2_mindr_mass");
+  variables.push_back("bjet2_mindr_eta");
+  variables.push_back("bjet2_mindr_phi");
+  variables.push_back("bjet2_mindr_dR_rc");
+
+  variables.push_back("jet1_mindr_pt");
+  variables.push_back("jet1_mindr_mass");
+  variables.push_back("jet1_mindr_eta");
+  variables.push_back("jet1_mindr_phi");
+  variables.push_back("jet1_mindr_dR_rc");
+
+  variables.push_back("jet2_mindr_pt");
+  variables.push_back("jet2_mindr_mass");
+  variables.push_back("jet2_mindr_eta");
+  variables.push_back("jet2_mindr_phi");
+  variables.push_back("jet2_mindr_dR_rc");
+
+
   variables.push_back("hthad");
   variables.push_back("meff");
   variables.push_back("met");
@@ -332,6 +539,10 @@ int main(int argc, char** argv){
   variables.push_back("rcjet1_nbjets_trim05");
   variables.push_back("rcjet1_nbjets_trim10");
   variables.push_back("rcjet1_nbjets_trim20");
+  variables.push_back("rcjet1_nljets");
+  variables.push_back("rcjet1_nljets_trim05");
+  variables.push_back("rcjet1_nljets_trim10");
+  variables.push_back("rcjet1_nljets_trim20");
   variables.push_back("rcjet1_sj1_ptfrac");
   variables.push_back("rcjet1_sj2_ptfrac");
   variables.push_back("rcjet1_sjge3_ptfrac");
@@ -363,6 +574,10 @@ int main(int argc, char** argv){
   variables.push_back("rcjet2_nbjets_trim05");
   variables.push_back("rcjet2_nbjets_trim10");
   variables.push_back("rcjet2_nbjets_trim20");
+  variables.push_back("rcjet2_nljets");
+  variables.push_back("rcjet2_nljets_trim05");
+  variables.push_back("rcjet2_nljets_trim10");
+  variables.push_back("rcjet2_nljets_trim20");
   variables.push_back("rcjet2_sj1_ptfrac");
   variables.push_back("rcjet2_sj2_ptfrac");
   variables.push_back("rcjet2_sjge3_ptfrac");
@@ -394,6 +609,10 @@ int main(int argc, char** argv){
   variables.push_back("rcjets_nbjets_trim05");
   variables.push_back("rcjets_nbjets_trim10");
   variables.push_back("rcjets_nbjets_trim20");
+  variables.push_back("rcjets_nljets");
+  variables.push_back("rcjets_nljets_trim05");
+  variables.push_back("rcjets_nljets_trim10");
+  variables.push_back("rcjets_nljets_trim20");
   variables.push_back("rcjets_sj1_ptfrac");
   variables.push_back("rcjets_sj2_ptfrac");
   variables.push_back("rcjets_sjge3_ptfrac");
@@ -420,6 +639,14 @@ int main(int argc, char** argv){
   variables.push_back("bjets_jvt");
   variables.push_back("bjets_dRmin_j");
 
+  variables.push_back("ljets_pt");
+  variables.push_back("ljets_mass");
+  variables.push_back("ljets_eta");
+  variables.push_back("ljets_phi");
+  variables.push_back("ljets_btagw");
+  variables.push_back("ljets_jvt");
+  variables.push_back("ljets_dRmin_j");
+
   //
   variables.push_back("jet1_pt");
   variables.push_back("jet1_mass");
@@ -437,6 +664,14 @@ int main(int argc, char** argv){
   variables.push_back("bjet1_jvt");
   variables.push_back("bjet1_dRmin_j");
 
+  variables.push_back("ljet1_pt");
+  variables.push_back("ljet1_mass");
+  variables.push_back("ljet1_eta");
+  variables.push_back("ljet1_phi");
+  variables.push_back("ljet1_btagw");
+  variables.push_back("ljet1_jvt");
+  variables.push_back("ljet1_dRmin_j");
+
   //
   variables.push_back("jets_rc1_pt");
   variables.push_back("jets_rc1_mass");
@@ -456,6 +691,15 @@ int main(int argc, char** argv){
   variables.push_back("bjets_rc1_dR");
   variables.push_back("bjets_rc1_dRmin_j");
 
+  variables.push_back("ljets_rc1_pt");
+  variables.push_back("ljets_rc1_mass");
+  variables.push_back("ljets_rc1_eta");
+  variables.push_back("ljets_rc1_phi");
+  variables.push_back("ljets_rc1_btagw");
+  variables.push_back("ljets_rc1_jvt");
+  variables.push_back("ljets_rc1_dR");
+  variables.push_back("ljets_rc1_dRmin_j");
+
 
   //
   variables.push_back("jets_rc1_trim05_pt");
@@ -476,6 +720,15 @@ int main(int argc, char** argv){
   variables.push_back("bjets_rc1_trim05_dR");
   variables.push_back("bjets_rc1_trim05_dRmin_j");
 
+  variables.push_back("ljets_rc1_trim05_pt");
+  variables.push_back("ljets_rc1_trim05_mass");
+  variables.push_back("ljets_rc1_trim05_eta");
+  variables.push_back("ljets_rc1_trim05_phi");
+  variables.push_back("ljets_rc1_trim05_btagw");
+  variables.push_back("ljets_rc1_trim05_jvt");
+  variables.push_back("ljets_rc1_trim05_dR");
+  variables.push_back("ljets_rc1_trim05_dRmin_j");
+
   //
   variables.push_back("jets_rc1_trim10_pt");
   variables.push_back("jets_rc1_trim10_mass");
@@ -495,6 +748,15 @@ int main(int argc, char** argv){
   variables.push_back("bjets_rc1_trim10_dR");
   variables.push_back("bjets_rc1_trim10_dRmin_j");
 
+  variables.push_back("ljets_rc1_trim10_pt");
+  variables.push_back("ljets_rc1_trim10_mass");
+  variables.push_back("ljets_rc1_trim10_eta");
+  variables.push_back("ljets_rc1_trim10_phi");
+  variables.push_back("ljets_rc1_trim10_btagw");
+  variables.push_back("ljets_rc1_trim10_jvt");
+  variables.push_back("ljets_rc1_trim10_dR");
+  variables.push_back("ljets_rc1_trim10_dRmin_j");
+
   //
   variables.push_back("jets_rc1_trim20_pt");
   variables.push_back("jets_rc1_trim20_mass");
@@ -514,34 +776,62 @@ int main(int argc, char** argv){
   variables.push_back("bjets_rc1_trim20_dR");
   variables.push_back("bjets_rc1_trim20_dRmin_j");
 
+  variables.push_back("ljets_rc1_trim20_pt");
+  variables.push_back("ljets_rc1_trim20_mass");
+  variables.push_back("ljets_rc1_trim20_eta");
+  variables.push_back("ljets_rc1_trim20_phi");
+  variables.push_back("ljets_rc1_trim20_btagw");
+  variables.push_back("ljets_rc1_trim20_jvt");
+  variables.push_back("ljets_rc1_trim20_dR");
+  variables.push_back("ljets_rc1_trim20_dRmin_j");
+
+  //variables.push_back("el1_pt");
+  //variables.push_back("mu1_pt");
+
   for(const std::string region : regions){
 
+    for(const std::string correlation : correlations){
+      double binxsize = 0.; double binxmin = 0.; double binxmax = 0.;
+      double binysize = 0.; double binymin = 0.; double binymax = 0.;
+
+      if(correlation.find("eta_vs_phi") != std::string::npos){
+	binxsize = 0.1; binxmin = -3.; binxmax = 3.; //eta
+	binysize = 0.1; binymin = -4.; binymax = 4.; //phi
+      }
+      m_hstMngr->BookTH2D(region+"_"+correlation,  "", binxsize, binxmin, binxmax, binysize, binymin, binymax);	
+
+    }//eta-phi correlation
+
     for(const std::string variable : variables){
       double binsize = 0.; double binmin = 0.; double binmax = 0.;
       if( (variable == "fjets_n") || (variable == "rcjets_n") ){ binsize = 1.; binmin = 0.; binmax = 5.; }
       else if( variable == "jets_n" ){ binsize = 1.; binmin = 0.; binmax = 15.; }
       else if( variable == "bjets_n" ){ binsize = 1.; binmin = 0.; binmax = 8.; }
+      else if( variable == "ljets_n" ){ binsize = 1.; binmin = 0.; binmax = 15.; }
       else if( (variable == "el_loose_n") || (variable == "mu_loose_n") || (variable == "lep_loose_n") ){ binsize = 1.; binmin = 0.; binmax = 4.; }
       else if( (variable.find("_njets") != std::string::npos) || (variable.find("_nconsts") != std::string::npos) ){
 	binsize = 1.; binmin = 0.; binmax = 8.;
       }
       else if(variable.find("_nbjets") != std::string::npos){ binsize = 1.; binmin = 0.; binmax = 4.; }
+      else if(variable.find("_nljets") != std::string::npos){ binsize = 1.; binmin = 0.; binmax = 4.; }
       
-      else if( (variable.find("dPhi") != std::string::npos) || (variable.find("_phi") != std::string::npos) ){ binsize = 0.2; binmin = -4.; binmax = 4.; }
-      else if( (variable.find("_eta") != std::string::npos) ){ binsize = 0.2; binmin = -3.; binmax = 3.; }
+      else if( (variable.find("dPhi") != std::string::npos) || (variable.find("phibb") != std::string::npos) 
+	       || (variable.find("_phi") != std::string::npos) ){ binsize = 0.2; binmin = -4.; binmax = 4.; }
+      else if( (variable.find("_eta") != std::string::npos) || (variable.find("etabb") != std::string::npos) ){ binsize = 0.2; binmin = -3.; binmax = 3.; }
       else if( variable.find("dR") != std::string::npos ){ binsize = 0.25; binmin = 0.; binmax = 5.; }
       else if( (variable == "meff") || (variable == "hthad") ){ binsize = 50.; binmin = 0.; binmax = 2000.; }
-      else if( (variable == "met") || (variable == "mtw") ){ binsize = 20.; binmin = 0.; binmax = 400.; }
-      else if( (variable == "mT_bmin") || (variable == "mbb_mindr") ){ binsize = 25.; binmin = 0.; binmax = 400.; }
+      else if(variable == "met"){ binsize = 20.; binmin = 0.; binmax = 500.; }
+      else if(variable == "mtw"){ binsize = 20.; binmin = 0.; binmax = 400.; }
+      else if( (variable.find("mT_bmin") != std::string::npos) || (variable.find("mbb_mindr") != std::string::npos) ){ binsize = 25.; binmin = 0.; binmax = 400.; }
       else if( (variable.find("_mass") != std::string::npos) 
 	       || (variable.find("_mjsum") != std::string::npos) 
 	       || (variable.find("_m_sumj") != std::string::npos) ){
 	if( (variable.find("rcjet") != std::string::npos) || (variable.find("fjet") != std::string::npos) ){
 	  binsize = 20.; binmin = 0.; binmax = 400.;
 	}
-	else{ binsize = 20.; binmin = 0.; binmax = 200.; }
+	else{ binsize = 10.; binmin = 0.; binmax = 150.; }
       }
-      else if(variable.find("_pt") != std::string::npos){
+      else if( (variable.find("ptbb") != std::string::npos) || (variable.find("_pt") != std::string::npos) ){
 	if(variable.find("_ptfrac") != std::string::npos){ binsize = 0.05; binmin = 0.; binmax = 1.; }
 	else if( (variable.find("rcjet") != std::string::npos) || (variable.find("fjet") != std::string::npos) ){
 	  binsize = 20.; binmin = 0.; binmax = 1000.;
@@ -549,12 +839,15 @@ int main(int argc, char** argv){
 	else{ binsize = 20.; binmin = 0.; binmax = 500.; }
       }
       else if( (variable.find("btagw") != std::string::npos) || (variable.find("jvt") != std::string::npos) ){ binsize = 0.1; binmin = -1.1; binmax = 1.1; }
+      else if( variable == "npv" ){ binsize = 1.; binmin = 0.; binmax = 50.;}
+      else if( variable == "pileup_mu" ){ binsize = 1.; binmin = 0.; binmax = 50.;}
       //---------------------------------
       //std::cout<<" Booking histogram "<<region+"_"+variable<<std::endl;
       m_hstMngr->BookTH1D(region+"_"+variable,  "", binsize, binmin, binmax);	
 	
-    }
-  }
+    }//variables
+
+  }//regions
 
     //
     //m_hstMngr->BookTH1D(region+"_"+"jets_rc1_trim05_pt", "", 10., 0., 500.);
@@ -563,31 +856,50 @@ int main(int argc, char** argv){
   //__________________________ EVENT LOOP _____________________________________
 
   for(long int entry = 0; entry < fChain->GetEntries(); ++entry){
-    if(entry % 10000 == 0) std::cout<<"Processing entry "<<entry<<std::endl;
 
+    jets_drmin_rc->clear();
+
+    if(entry % 10000 == 0) std::cout<<"Processing entry "<<entry<<std::endl;
     fChain->GetEntry(entry);
 
     nomWeight = 1;
     if(!isdata){
-      nomWeight = nomWeight_weight_bTagSF_77 * nomWeight_weight_mc * nomWeight_weight_norm * nomWeight_weight_pileup;// * nomWeight_weight_jvt
-      if( el_n + mu_n > 0 ){
-	nomWeight *= nomWeight_weight_indiv_SF_MU_Trigger;
-	if(el_n > 0){
-	  nomWeight *= nomWeight_weight_indiv_SF_EL_ID * nomWeight_weight_indiv_SF_EL_Isol * nomWeight_weight_indiv_SF_EL_Reco;
+      if(!isqcd){
+	nomWeight = nomWeight_weight_btag * nomWeight_weight_mc * nomWeight_weight_norm * nomWeight_weight_pileup * nomWeight_weight_jvt;
+	if( el_n + mu_n > 0 ){
+	  nomWeight *= nomWeight_weight_leptonSF;
 	}
-	if(mu_n > 0){ 
-	  nomWeight *= nomWeight_weight_indiv_SF_MU_ID * nomWeight_weight_indiv_SF_MU_Isol * nomWeight_weight_indiv_SF_MU_TTVA;
+	if(isttlight){
+	  nomWeight *= nomWeight_weight_ttbar_nnlo;
+	} 
+	else if(isttbb){
+	  nomWeight *= nomWeight_weight_ttbb;
+	} 
+	else if(isvjets22){
+	  nomWeight *= nomWeight_weight_sherpa_22_vjets;
+	}
+      }
+      else{
+	if(channel==1 && data_period==1){
+	  nomWeight = nomWeight_fakesMM_weight_ejets_2015;
+	}
+	else if(channel==1 && data_period==2){ continue;
+	  //nomWeight = nomWeight_fakesMM_weight_ejets_2016;
+	}
+	else if(channel==2 && data_period==1){
+	  nomWeight = nomWeight_fakesMM_weight_mujets_2015;
+	}
+	else if(channel==2 && data_period==2){
+	  nomWeight = nomWeight_fakesMM_weight_mujets_2016;
 	}
       }
-      if(istt){
-	nomWeight *= nomWeight_weight_ttbb*nomWeight_weight_ttbar_NNLO;
-      } 
     }
 
+    if(!dolowb && (bjets_n < 2)) continue;
+    if(jets_n < 5) continue;
+
 
     for(const std::string region:regions){
-      if(bjets_n < 2) continue;
-      if(jets_n < 5) continue;
       if( (region.find("noRC") != std::string::npos) && (rcjets_n > 0) ) continue;
       else if( (region.find("RC1M") != std::string::npos) && (rcjets_n != 1) ) continue;
       //-------------------------------------------------------------
@@ -619,23 +931,57 @@ int main(int argc, char** argv){
 
       //---------------------------------------------------------------
 
-      if( (region.find("0lep") != std::string::npos) && ( (el_n+mu_n > 0) || (met < 200) || (fabs(dPhi_jetmet) < 0.4) ) ){continue;}
-      //if( (region.find("0lep") != std::string::npos) && ( (el_n+mu_n > 0) || (met < 200) || (fabs(dPhi_jetmet) >= 0.4) ) ){continue;}
-      else if( (region.find("1elmu") != std::string::npos) && (el_n+mu_n <= 0) ){continue;}
-      else if( (region.find("1el") != std::string::npos) && (el_n != 1 || mu_n > 0) ){continue;}
-      else if( (region.find("1mu") != std::string::npos) && (el_n > 0 || mu_n != 1) ){continue;}
-      
+      if(region.find("0lep") != std::string::npos){
+	if ( (el_n+mu_n > 0) || (met < 200) || (fabs(dPhi_jetmet) < 0.4) || (jets_n < 6) || (channel != 3) ){continue;}
+      }
+      else if(region.find("1elmu") != std::string::npos){ 
+	if  (el_n+mu_n <= 0  || (channel != 1 && channel != 2) ){continue;}
+      }
+      else if(region.find("1el") != std::string::npos){
+	if  (el_n != 1 || mu_n > 0 || channel != 1){continue;}
+      }
+      else if(region.find("1mu") != std::string::npos){
+	if (el_n > 0 || mu_n != 1 || channel != 2){continue;}
+      }
+
       //--------------------------------------------------------------------------------------------
 
-      if( (region.find("2bex") != std::string::npos) && (bjets_n != 2) ){continue;} 
+      if( (region.find("0bex") != std::string::npos) && (bjets_n != 0) ){continue;} 
+      else if( (region.find("1bex") != std::string::npos) && (bjets_n != 1) ){continue;} 
+      else if( (region.find("2bex") != std::string::npos) && (bjets_n != 2) ){continue;} 
+      else if( (region.find("3bex") != std::string::npos) && (bjets_n != 3) ){continue;} 
+
+      else if( (region.find("0bin") != std::string::npos) && (bjets_n < 0) ){continue;} 
+      else if( (region.find("1bin") != std::string::npos) && (bjets_n < 1) ){continue;} 
+      else if( (region.find("2bin") != std::string::npos) && (bjets_n < 2) ){continue;} 
+      else if( (region.find("3bin") != std::string::npos) && (bjets_n < 3) ){continue;} 
+      else if( (region.find("4bin") != std::string::npos) && (bjets_n < 4) ){continue;} 
  
+      //------------------------------------------------------------------------------------------
+      if(region.find("metmtwinc") != std::string::npos){ 
+	if( (met<20.) || (met+mtw < 60.) ){continue;}
+      }
+
      //--------------------------------------------------------------------------------------------
+      if( region.find("period2015") != std::string::npos ){ 
+	if(data_period != 1){ continue; }
+      }
+      else if( region.find("period2016") != std::string::npos ){ 
+	if(data_period != 2){ continue; }
+      }
+      //---------------------------------------------------------
+
+      if( region.find("lowmu") != std::string::npos ){ 
+	if(pileup_mu >= 22.){ continue; }
+      }
+      if( region.find("highmu") != std::string::npos ){ 
+	if(pileup_mu < 22.){ continue; }
+      }
       /*
       m_hstMngr->FillTH1D(region+"_"+"el_loose_n", el_loose_n, nomWeight);
       m_hstMngr->FillTH1D(region+"_"+"mu_loose_n", mu_loose_n, nomWeight);
       m_hstMngr->FillTH1D(region+"_"+"el_loose_n", el_loose_n+mu_loose_n, nomWeight);
       */
-
       for( int ifj = 0; ifj < fjets_n; ifj++){
 	if(ifj == 0){
 	  m_hstMngr->FillTH1D(region+"_"+"fjet1_mass", fjets_m->at(ifj), nomWeight);
@@ -652,10 +998,10 @@ int main(int argc, char** argv){
       for( int irc = 0; irc < rcjets_n; irc++){
 	//if( (rcjets_pt->at(irc) < 100) || (rcjets_pt->at(irc) > 300) ) continue;
 	TLorentzVector tlv_rc;
-	int nbj_rc = 0; int nj_rc = 0;
-	int nj_rc_trim05 = 0; int nbj_rc_trim05 = 0;
-	int nj_rc_trim10 = 0; int nbj_rc_trim10 = 0;
-	int nj_rc_trim20 = 0; int nbj_rc_trim20 = 0;
+	int nbj_rc = 0; int nj_rc = 0; int nlj_rc = 0;
+	int nj_rc_trim05 = 0; int nbj_rc_trim05 = 0; int nlj_rc_trim05 = 0;
+	int nj_rc_trim10 = 0; int nbj_rc_trim10 = 0; int nlj_rc_trim10 = 0;
+	int nj_rc_trim20 = 0; int nbj_rc_trim20 = 0; int nlj_rc_trim20 = 0;
 
 	double mjsum = 0.; double m_sumj = 0.;
 	double mjsum_trim05 = 0.; double m_sumj_trim05 = 0.;
@@ -663,7 +1009,7 @@ int main(int argc, char** argv){
 	double mjsum_trim20 = 0.; double m_sumj_trim20 = 0.;
 
 	tlv_rc.SetPtEtaPhiM(rcjets_pt->at(irc), rcjets_eta->at(irc), rcjets_phi->at(irc), rcjets_m->at(irc));
-
+	
 	TLorentzVector tlv_rc_sumj;
 
 	std::vector<int> inds_rc_sj;
@@ -699,6 +1045,11 @@ int main(int argc, char** argv){
 	    drjjmin.push_back(dRmin_jj);
 
 	    if(irc == 0){
+	      /*
+	      m_hstMngr->FillTH2D(region+"_nrg_tot_jets_rc1_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), tlv_j.E()*nomWeight);
+	      m_hstMngr->FillTH2D(region+"_nrg_avg_jets_rc1_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), tlv_j.E()*nomWeight);
+	      m_hstMngr->FillTH2D(region+"_jets_rc1_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), nomWeight);
+	      */
 	      m_hstMngr->FillTH1D(region+"_"+"jets_rc1_pt", jets_pt->at(ij), nomWeight);
 	      m_hstMngr->FillTH1D(region+"_"+"jets_rc1_mass", jets_m->at(ij), nomWeight);
 	      m_hstMngr->FillTH1D(region+"_"+"jets_rc1_eta", jets_eta->at(ij), nomWeight);
@@ -708,8 +1059,13 @@ int main(int argc, char** argv){
 	      m_hstMngr->FillTH1D(region+"_"+"jets_rc1_dR", dr_rj, nomWeight);
 	      m_hstMngr->FillTH1D(region+"_"+"jets_rc1_dRmin_j", dRmin_jj, nomWeight);
 
-	      if(jets_btagw->at(ij) > -0.4434){
+	      if(jets_btagw->at(ij) > 0.645925){
 		nbj_rc++;
+		/*
+		m_hstMngr->FillTH2D(region+"_nrg_tot_bjets_rc1_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), tlv_j.E()*nomWeight);
+		m_hstMngr->FillTH2D(region+"_nrg_avg_bjets_rc1_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), tlv_j.E()*nomWeight);
+		m_hstMngr->FillTH2D(region+"_bjets_rc1_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), nomWeight);
+		*/
 		m_hstMngr->FillTH1D(region+"_"+"bjets_rc1_pt", jets_pt->at(ij), nomWeight);
 		m_hstMngr->FillTH1D(region+"_"+"bjets_rc1_mass", jets_m->at(ij), nomWeight);
 		m_hstMngr->FillTH1D(region+"_"+"bjets_rc1_eta", jets_eta->at(ij), nomWeight);
@@ -720,6 +1076,23 @@ int main(int argc, char** argv){
 		m_hstMngr->FillTH1D(region+"_"+"bjets_rc1_dRmin_j", dRmin_jj, nomWeight);
 
 	      }//b-tagged	  
+	      else{
+		nlj_rc++;
+		/*
+		m_hstMngr->FillTH2D(region+"_nrg_tot_ljets_rc1_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), tlv_j.E()*nomWeight);
+		m_hstMngr->FillTH2D(region+"_nrg_avg_ljets_rc1_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), tlv_j.E()*nomWeight);
+		m_hstMngr->FillTH2D(region+"_ljets_rc1_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), nomWeight);
+		*/
+		m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_pt", jets_pt->at(ij), nomWeight);
+		m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_mass", jets_m->at(ij), nomWeight);
+		m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_eta", jets_eta->at(ij), nomWeight);
+		m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_phi", jets_phi->at(ij), nomWeight);
+		m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_btagw", jets_btagw->at(ij), nomWeight);
+		m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_jvt", jets_jvt->at(ij), nomWeight);
+		m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_dR", dr_rj, nomWeight);
+		m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_dRmin_j", dRmin_jj, nomWeight);
+	      }
+
 	    }//first rc jet
 	  }//inside rc
 
@@ -777,7 +1150,7 @@ int main(int argc, char** argv){
 	    m_hstMngr->FillTH1D(region+"_"+"jets_rc1_trim05_dR", dr_rj, nomWeight);
 	    m_hstMngr->FillTH1D(region+"_"+"jets_rc1_trim05_dRmin_j", dRmin_jj, nomWeight);
 
-	    if(jets_btagw->at(ij) > -0.4434){
+	    if(jets_btagw->at(ij) > 0.645925){
 	      nbj_rc_trim05++;
 	      m_hstMngr->FillTH1D(region+"_"+"bjets_rc1_trim05_pt", jets_pt->at(ij), nomWeight);
 	      m_hstMngr->FillTH1D(region+"_"+"bjets_rc1_trim05_mass", jets_m->at(ij), nomWeight);
@@ -788,7 +1161,17 @@ int main(int argc, char** argv){
 	      m_hstMngr->FillTH1D(region+"_"+"bjets_rc1_trim05_dR", dr_rj, nomWeight);
 	      m_hstMngr->FillTH1D(region+"_"+"bjets_rc1_trim05_dRmin_j", dRmin_jj, nomWeight);
 	    }//btag
-
+	    else{
+	      nlj_rc_trim05++;
+	      m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_trim05_pt", jets_pt->at(ij), nomWeight);
+	      m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_trim05_mass", jets_m->at(ij), nomWeight);
+	      m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_trim05_eta", jets_eta->at(ij), nomWeight);
+	      m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_trim05_phi", jets_phi->at(ij), nomWeight);
+	      m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_trim05_btagw", jets_btagw->at(ij), nomWeight);
+	      m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_trim05_jvt", jets_jvt->at(ij), nomWeight);
+	      m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_trim05_dR", dr_rj, nomWeight);
+	      m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_trim05_dRmin_j", dRmin_jj, nomWeight);
+	    }
 	    if(tlv_j.Pt() >= tlv_rc_sumj.Pt()*0.10){
 	      tlv_rc_sumj_trim10 += tlv_j;
 	      nj_rc_trim10++;
@@ -803,7 +1186,7 @@ int main(int argc, char** argv){
 	      m_hstMngr->FillTH1D(region+"_"+"jets_rc1_trim10_dR", dr_rj, nomWeight);
 	      m_hstMngr->FillTH1D(region+"_"+"jets_rc1_trim10_dRmin_j", dRmin_jj, nomWeight);
 
-	      if(jets_btagw->at(ij) > -0.4434){
+	      if(jets_btagw->at(ij) > 0.645925){
 		nbj_rc_trim10++;
 		m_hstMngr->FillTH1D(region+"_"+"bjets_rc1_trim10_pt", jets_pt->at(ij), nomWeight);
 		m_hstMngr->FillTH1D(region+"_"+"bjets_rc1_trim10_mass", jets_m->at(ij), nomWeight);
@@ -814,7 +1197,17 @@ int main(int argc, char** argv){
 		m_hstMngr->FillTH1D(region+"_"+"bjets_rc1_trim10_dR", dr_rj, nomWeight);
 		m_hstMngr->FillTH1D(region+"_"+"bjets_rc1_trim10_dRmin_j", dRmin_jj, nomWeight);
 	      }//btag
-
+	      else{
+		nlj_rc_trim10++;
+		m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_trim10_pt", jets_pt->at(ij), nomWeight);
+		m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_trim10_mass", jets_m->at(ij), nomWeight);
+		m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_trim10_eta", jets_eta->at(ij), nomWeight);
+		m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_trim10_phi", jets_phi->at(ij), nomWeight);
+		m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_trim10_btagw", jets_btagw->at(ij), nomWeight);
+		m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_trim10_jvt", jets_jvt->at(ij), nomWeight);
+		m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_trim10_dR", dr_rj, nomWeight);
+		m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_trim10_dRmin_j", dRmin_jj, nomWeight);
+	      }
 	      if(tlv_j.Pt() >= tlv_rc_sumj.Pt()*0.20){
 		tlv_rc_sumj_trim20 += tlv_j;
 		nj_rc_trim20++;
@@ -829,7 +1222,7 @@ int main(int argc, char** argv){
 		m_hstMngr->FillTH1D(region+"_"+"jets_rc1_trim20_dR", dr_rj, nomWeight);
 		m_hstMngr->FillTH1D(region+"_"+"jets_rc1_dRmin_j", dRmin_jj, nomWeight);
 	      
-		if(jets_btagw->at(ij) > -0.4434){
+		if(jets_btagw->at(ij) > 0.645925){
 		  nbj_rc_trim20++;
 		  m_hstMngr->FillTH1D(region+"_"+"bjets_rc1_trim20_pt", jets_pt->at(ij), nomWeight);
 		  m_hstMngr->FillTH1D(region+"_"+"bjets_rc1_trim20_mass", jets_m->at(ij), nomWeight);
@@ -840,7 +1233,17 @@ int main(int argc, char** argv){
 		  m_hstMngr->FillTH1D(region+"_"+"bjets_rc1_trim20_dR", dr_rj, nomWeight);
 		  m_hstMngr->FillTH1D(region+"_"+"bjets_rc1_trim20_dRmin_j", dRmin_jj, nomWeight);
 		}//btag
-
+		else{
+		  nlj_rc_trim20++;
+		  m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_trim20_pt", jets_pt->at(ij), nomWeight);
+		  m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_trim20_mass", jets_m->at(ij), nomWeight);
+		  m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_trim20_eta", jets_eta->at(ij), nomWeight);
+		  m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_trim20_phi", jets_phi->at(ij), nomWeight);
+		  m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_trim20_btagw", jets_btagw->at(ij), nomWeight);
+		  m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_trim20_jvt", jets_jvt->at(ij), nomWeight);
+		  m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_trim20_dR", dr_rj, nomWeight);
+		  m_hstMngr->FillTH1D(region+"_"+"ljets_rc1_trim20_dRmin_j", dRmin_jj, nomWeight);
+		}
 	      }//20%
 
 	    }//10%
@@ -855,6 +1258,11 @@ int main(int argc, char** argv){
 	m_sumj_trim20 = tlv_rc_sumj_trim20.M();
 	
 	if(irc == 0){
+	  /*
+	  m_hstMngr->FillTH2D(region+"_nrg_tot_rcjet1_eta_vs_phi", rcjets_eta->at(irc), rcjets_phi->at(irc), tlv_rc.E()*nomWeight);
+	  m_hstMngr->FillTH2D(region+"_nrg_avg_rcjet1_eta_vs_phi", rcjets_eta->at(irc), rcjets_phi->at(irc), tlv_rc.E()*nomWeight);
+	  m_hstMngr->FillTH2D(region+"_rcjet1_eta_vs_phi", rcjets_eta->at(irc), rcjets_phi->at(irc), nomWeight);
+	  */
 	  m_hstMngr->FillTH1D(region+"_"+"rcjet1_mass", rcjets_m->at(irc), nomWeight);
 	  m_hstMngr->FillTH1D(region+"_"+"rcjet1_pt", rcjets_pt->at(irc), nomWeight);
 	  m_hstMngr->FillTH1D(region+"_"+"rcjet1_eta", rcjets_eta->at(irc), nomWeight);
@@ -862,12 +1270,16 @@ int main(int argc, char** argv){
 	  m_hstMngr->FillTH1D(region+"_"+"rcjet1_nconsts", rcjets_nconsts->at(irc), nomWeight);
 	  m_hstMngr->FillTH1D(region+"_"+"rcjet1_nbjets", nbj_rc, nomWeight);
 	  m_hstMngr->FillTH1D(region+"_"+"rcjet1_njets", nj_rc, nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"rcjet1_nljets", nlj_rc, nomWeight);
  	  m_hstMngr->FillTH1D(region+"_"+"rcjet1_nbjets_trim05", nbj_rc_trim05, nomWeight);
  	  m_hstMngr->FillTH1D(region+"_"+"rcjet1_nbjets_trim10", nbj_rc_trim10, nomWeight);
  	  m_hstMngr->FillTH1D(region+"_"+"rcjet1_nbjets_trim20", nbj_rc_trim20, nomWeight);
 	  m_hstMngr->FillTH1D(region+"_"+"rcjet1_njets_trim05", nj_rc_trim05, nomWeight);
 	  m_hstMngr->FillTH1D(region+"_"+"rcjet1_njets_trim10", nj_rc_trim10, nomWeight);
 	  m_hstMngr->FillTH1D(region+"_"+"rcjet1_njets_trim20", nj_rc_trim20, nomWeight);
+ 	  m_hstMngr->FillTH1D(region+"_"+"rcjet1_nljets_trim05", nlj_rc_trim05, nomWeight);
+ 	  m_hstMngr->FillTH1D(region+"_"+"rcjet1_nljets_trim10", nlj_rc_trim10, nomWeight);
+ 	  m_hstMngr->FillTH1D(region+"_"+"rcjet1_nljets_trim20", nlj_rc_trim20, nomWeight);
 	  
 	  m_hstMngr->FillTH1D(region+"_"+"rcjet1_mjsum", mjsum, nomWeight);
 	  m_hstMngr->FillTH1D(region+"_"+"rcjet1_mjsum_trim05", mjsum_trim05, nomWeight);
@@ -880,7 +1292,11 @@ int main(int argc, char** argv){
 	  m_hstMngr->FillTH1D(region+"_"+"rcjet1_m_sumj_trim20", m_sumj_trim20, nomWeight);
 	  
 	}
-	
+	/*
+	m_hstMngr->FillTH2D(region+"_nrg_tot_rcjets_eta_vs_phi", rcjets_eta->at(irc), rcjets_phi->at(irc), tlv_rc.E()*nomWeight);
+	m_hstMngr->FillTH2D(region+"_nrg_avg_rcjets_eta_vs_phi", rcjets_eta->at(irc), rcjets_phi->at(irc), tlv_rc.E()*nomWeight);
+	m_hstMngr->FillTH2D(region+"_rcjets_eta_vs_phi", rcjets_eta->at(irc), rcjets_phi->at(irc), nomWeight);
+	*/
 	m_hstMngr->FillTH1D(region+"_"+"rcjets_mass", rcjets_m->at(irc), nomWeight);
 	m_hstMngr->FillTH1D(region+"_"+"rcjets_pt", rcjets_pt->at(irc), nomWeight);
 	m_hstMngr->FillTH1D(region+"_"+"rcjets_eta", rcjets_eta->at(irc), nomWeight);
@@ -888,12 +1304,16 @@ int main(int argc, char** argv){
 	m_hstMngr->FillTH1D(region+"_"+"rcjets_nconsts", rcjets_nconsts->at(irc), nomWeight);
 	m_hstMngr->FillTH1D(region+"_"+"rcjets_nbjets", nbj_rc, nomWeight);
 	m_hstMngr->FillTH1D(region+"_"+"rcjets_njets", nj_rc, nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"rcjets_nljets", nlj_rc, nomWeight);
 	m_hstMngr->FillTH1D(region+"_"+"rcjets_nbjets_trim05", nbj_rc_trim05, nomWeight);
 	m_hstMngr->FillTH1D(region+"_"+"rcjets_nbjets_trim10", nbj_rc_trim10, nomWeight);
 	m_hstMngr->FillTH1D(region+"_"+"rcjets_nbjets_trim20", nbj_rc_trim20, nomWeight);
 	m_hstMngr->FillTH1D(region+"_"+"rcjets_njets_trim05", nj_rc_trim05, nomWeight);
 	m_hstMngr->FillTH1D(region+"_"+"rcjets_njets_trim10", nj_rc_trim10, nomWeight);
 	m_hstMngr->FillTH1D(region+"_"+"rcjets_njets_trim20", nj_rc_trim20, nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"rcjets_nljets_trim05", nlj_rc_trim05, nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"rcjets_nljets_trim10", nlj_rc_trim10, nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"rcjets_nljets_trim20", nlj_rc_trim20, nomWeight);
 	
 	m_hstMngr->FillTH1D(region+"_"+"rcjets_mjsum", mjsum, nomWeight);
 	m_hstMngr->FillTH1D(region+"_"+"rcjets_mjsum_trim05", mjsum_trim05, nomWeight);
@@ -907,20 +1327,48 @@ int main(int argc, char** argv){
 	
       }//reclustered jet loop
       
-      int nbj = 0; 
+      int nbj = 0; int nlj = 0; 
+
+      int i1_mindr_bb = -1; int i2_mindr_bb = -1; double mindr_bb = 10.;
+      int i1_mindr_jj = -1; int i2_mindr_jj = -1; double mindr_jj = 10.;
+
       for( int ij = 0; ij < jets_n; ij++){
 
 	TLorentzVector tlv_j;
 	tlv_j.SetPtEtaPhiM(jets_pt->at(ij), jets_eta->at(ij), jets_phi->at(ij), jets_m->at(ij));
-	double dRmin_jj = 10.;
+	double dRmin_jj = 10.; double dRmin_rc = 10.;
+
+	for(int irc = 0; irc < rcjets_n; irc++){
+	  TLorentzVector tlv_rc;
+	  tlv_rc.SetPtEtaPhiM(rcjets_pt->at(irc), rcjets_eta->at(irc), rcjets_phi->at(irc), rcjets_m->at(irc));
+	  double dr_jrc = tlv_rc.DeltaR(tlv_j);
+	  if(dr_jrc < dRmin_rc) dRmin_rc = dr_jrc;
+	}
+	jets_drmin_rc->push_back(dRmin_rc);
+
 	for( int jj = 0; jj < jets_n; jj++){
 	  if(ij == jj) continue;
 	  TLorentzVector tlv_jalt;
 	  tlv_jalt.SetPtEtaPhiM(jets_pt->at(jj), jets_eta->at(jj), jets_phi->at(jj), jets_m->at(jj));
 	  double dr_jj = tlv_jalt.DeltaR(tlv_j);
 	  if(dr_jj < dRmin_jj) dRmin_jj = dr_jj;
-	}
+	  if(dr_jj < mindr_jj){
+	    mindr_jj = dr_jj;
+	    i1_mindr_jj = ij; i2_mindr_jj = jj;
+	  }
 
+	  if( (jets_btagw->at(ij) > 0.645925) && (jets_btagw->at(jj) > 0.645925) ){
+	    if(dr_jj < mindr_bb){
+	      mindr_bb = dr_jj;
+	      i1_mindr_bb = ij; i2_mindr_bb = jj;
+	    }
+	  }
+	}//second jet loop
+	/*
+	m_hstMngr->FillTH2D(region+"_nrg_tot_jets_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), tlv_j.E()*nomWeight);
+	m_hstMngr->FillTH2D(region+"_nrg_avg_jets_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), tlv_j.E()*nomWeight);
+	m_hstMngr->FillTH2D(region+"_jets_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), nomWeight);
+	*/
 	m_hstMngr->FillTH1D(region+"_"+"jets_pt", jets_pt->at(ij), nomWeight);
 	m_hstMngr->FillTH1D(region+"_"+"jets_mass", jets_m->at(ij), nomWeight);
 	m_hstMngr->FillTH1D(region+"_"+"jets_eta", jets_eta->at(ij), nomWeight);
@@ -930,6 +1378,11 @@ int main(int argc, char** argv){
 	m_hstMngr->FillTH1D(region+"_"+"jets_dRmin_j", dRmin_jj, nomWeight);
 
 	if(ij == 0){
+	  /*
+	  m_hstMngr->FillTH2D(region+"_nrg_tot_jet1_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), tlv_j.E()*nomWeight);
+	  m_hstMngr->FillTH2D(region+"_nrg_avg_jet1_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), tlv_j.E()*nomWeight);
+	  m_hstMngr->FillTH2D(region+"_jet1_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), nomWeight);
+	  */
 	  m_hstMngr->FillTH1D(region+"_"+"jet1_pt", jets_pt->at(ij), nomWeight);
 	  m_hstMngr->FillTH1D(region+"_"+"jet1_mass", jets_m->at(ij), nomWeight);
 	  m_hstMngr->FillTH1D(region+"_"+"jet1_eta", jets_eta->at(ij), nomWeight);
@@ -939,7 +1392,12 @@ int main(int argc, char** argv){
 	  m_hstMngr->FillTH1D(region+"_"+"jet1_dRmin_j", dRmin_jj, nomWeight);
 	}
 
-	if(jets_btagw->at(ij) > -0.4434){
+	if(jets_btagw->at(ij) > 0.645925){
+	  /*
+	  m_hstMngr->FillTH2D(region+"_nrg_tot_bjets_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), tlv_j.E()*nomWeight);
+	  m_hstMngr->FillTH2D(region+"_nrg_avg_bjets_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), tlv_j.E()*nomWeight);
+	  m_hstMngr->FillTH2D(region+"_bjets_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), nomWeight);
+	  */
 	  m_hstMngr->FillTH1D(region+"_"+"bjets_pt", jets_pt->at(ij), nomWeight);
 	  m_hstMngr->FillTH1D(region+"_"+"bjets_mass", jets_m->at(ij), nomWeight);
 	  m_hstMngr->FillTH1D(region+"_"+"bjets_eta", jets_eta->at(ij), nomWeight);
@@ -949,6 +1407,11 @@ int main(int argc, char** argv){
 	  m_hstMngr->FillTH1D(region+"_"+"bjets_dRmin_j", dRmin_jj, nomWeight);
 
 	  if(nbj==0){
+	    /*
+	    m_hstMngr->FillTH2D(region+"_nrg_tot_bjet1_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), tlv_j.E()*nomWeight);
+	    m_hstMngr->FillTH2D(region+"_nrg_avg_bjet1_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), tlv_j.E()*nomWeight);
+	    m_hstMngr->FillTH2D(region+"_bjet1_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), nomWeight);
+	    */
 	    m_hstMngr->FillTH1D(region+"_"+"bjet1_pt", jets_pt->at(ij), nomWeight);
 	    m_hstMngr->FillTH1D(region+"_"+"bjet1_mass", jets_m->at(ij), nomWeight);
 	    m_hstMngr->FillTH1D(region+"_"+"bjet1_eta", jets_eta->at(ij), nomWeight);
@@ -959,11 +1422,83 @@ int main(int argc, char** argv){
 	  }
 	  nbj++;
 	}//bjet
+	else{
+	  /*
+	  m_hstMngr->FillTH2D(region+"_nrg_tot_ljets_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), tlv_j.E()*nomWeight);
+	  m_hstMngr->FillTH2D(region+"_nrg_avg_ljets_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), tlv_j.E()*nomWeight);
+	  m_hstMngr->FillTH2D(region+"_ljets_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), nomWeight);
+	  */
+	  m_hstMngr->FillTH1D(region+"_"+"ljets_pt", jets_pt->at(ij), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"ljets_mass", jets_m->at(ij), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"ljets_eta", jets_eta->at(ij), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"ljets_phi", jets_phi->at(ij), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"ljets_btagw", jets_btagw->at(ij), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"ljets_jvt", jets_jvt->at(ij), nomWeight);
+	  m_hstMngr->FillTH1D(region+"_"+"ljets_dRmin_j", dRmin_jj, nomWeight);
+
+	  if(nbj==0){
+	    /*
+	    m_hstMngr->FillTH2D(region+"_nrg_tot_ljet1_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), tlv_j.E()*nomWeight);
+	    m_hstMngr->FillTH2D(region+"_nrg_avg_ljet1_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), tlv_j.E()*nomWeight);
+	    m_hstMngr->FillTH2D(region+"_ljet1_eta_vs_phi", jets_eta->at(ij), jets_phi->at(ij), nomWeight);
+	    */
+	    m_hstMngr->FillTH1D(region+"_"+"ljet1_pt", jets_pt->at(ij), nomWeight);
+	    m_hstMngr->FillTH1D(region+"_"+"ljet1_mass", jets_m->at(ij), nomWeight);
+	    m_hstMngr->FillTH1D(region+"_"+"ljet1_eta", jets_eta->at(ij), nomWeight);
+	    m_hstMngr->FillTH1D(region+"_"+"ljet1_phi", jets_phi->at(ij), nomWeight);
+	    m_hstMngr->FillTH1D(region+"_"+"ljet1_btagw", jets_btagw->at(ij), nomWeight);
+	    m_hstMngr->FillTH1D(region+"_"+"ljet1_jvt", jets_jvt->at(ij), nomWeight);
+	    m_hstMngr->FillTH1D(region+"_"+"ljet1_dRmin_j", dRmin_jj, nomWeight);
+	  }
+	  nlj++;
+	}//ljet
+
       }//jet loop
       m_hstMngr->FillTH1D(region+"_"+"dPhi_jetmet", dPhi_jetmet, nomWeight);
       m_hstMngr->FillTH1D(region+"_"+"dRmin_jetjet", dRmin_jetjet, nomWeight);
       m_hstMngr->FillTH1D(region+"_"+"dRmin_bb", dRmin_bb, nomWeight);
 
+      if( (i1_mindr_bb >= 0) && (i2_mindr_bb >= 0) ){
+	TLorentzVector tlv_b1;
+	tlv_b1.SetPtEtaPhiM(jets_pt->at(i1_mindr_bb), jets_eta->at(i1_mindr_bb), jets_phi->at(i1_mindr_bb), jets_m->at(i1_mindr_bb));
+	TLorentzVector tlv_b2;
+	tlv_b2.SetPtEtaPhiM(jets_pt->at(i2_mindr_bb), jets_eta->at(i2_mindr_bb), jets_phi->at(i2_mindr_bb), jets_m->at(i2_mindr_bb));
+	TLorentzVector tlv_bb_sys = tlv_b1 + tlv_b2;
+
+	m_hstMngr->FillTH1D(region+"_"+"ptbb_mindr", tlv_bb_sys.Pt(), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"etabb_mindr", tlv_bb_sys.Eta(), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"phibb_mindr", tlv_bb_sys.Phi(), nomWeight);
+      }
+
+      if(i1_mindr_bb >= 0){
+	m_hstMngr->FillTH1D(region+"_"+"bjet1_mindr_pt", jets_pt->at(i1_mindr_bb), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"bjet1_mindr_mass", jets_m->at(i1_mindr_bb), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"bjet1_mindr_eta", jets_eta->at(i1_mindr_bb), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"bjet1_mindr_phi", jets_phi->at(i1_mindr_bb), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"bjet1_mindr_dR_rc", jets_drmin_rc->at(i1_mindr_bb), nomWeight);
+      }
+      if(i2_mindr_bb >= 0){
+	m_hstMngr->FillTH1D(region+"_"+"bjet2_mindr_pt", jets_pt->at(i2_mindr_bb), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"bjet2_mindr_mass", jets_m->at(i2_mindr_bb), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"bjet2_mindr_eta", jets_eta->at(i2_mindr_bb), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"bjet2_mindr_phi", jets_phi->at(i2_mindr_bb), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"bjet2_mindr_dR_rc", jets_drmin_rc->at(i2_mindr_bb), nomWeight);
+      }
+      if(i1_mindr_jj >= 0){
+	m_hstMngr->FillTH1D(region+"_"+"jet1_mindr_pt", jets_pt->at(i1_mindr_jj), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"jet1_mindr_mass", jets_m->at(i1_mindr_jj), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"jet1_mindr_eta", jets_eta->at(i1_mindr_jj), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"jet1_mindr_phi", jets_phi->at(i1_mindr_jj), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"jet1_mindr_dR_rc", jets_drmin_rc->at(i1_mindr_jj), nomWeight);
+      }
+      if(i2_mindr_jj >= 0){
+	m_hstMngr->FillTH1D(region+"_"+"jet2_mindr_pt", jets_pt->at(i2_mindr_jj), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"jet2_mindr_mass", jets_m->at(i2_mindr_jj), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"jet2_mindr_eta", jets_eta->at(i2_mindr_jj), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"jet2_mindr_phi", jets_phi->at(i2_mindr_jj), nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"jet2_mindr_dR_rc", jets_drmin_rc->at(i2_mindr_jj), nomWeight);
+      }
+
       /*
       if(el_n + mu_n > 0){
 	m_hstMngr->FillTH1D(region+"_"+"dPhi_lepbjet", dPhi_lepbjet, nomWeight);
@@ -987,27 +1522,63 @@ int main(int argc, char** argv){
       m_hstMngr->FillTH1D(region+"_"+"hthad", o_hthad, nomWeight);
       m_hstMngr->FillTH1D(region+"_"+"met", met, nomWeight);
       m_hstMngr->FillTH1D(region+"_"+"met_phi", met_phi, nomWeight);
-      //m_hstMngr->FillTH1D(region+"_"+"mtw", mtw, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"mtw", mtw, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"el1_pt", el1_pt, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"mu1_pt", mu1_pt, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"npv", npv, nomWeight);
+      m_hstMngr->FillTH1D(region+"_"+"pileup_mu", pileup_mu, nomWeight);
 
       m_hstMngr->FillTH1D(region+"_"+"fjets_n", fjets_n, nomWeight);
       m_hstMngr->FillTH1D(region+"_"+"rcjets_n", rcjets_n, nomWeight);
       m_hstMngr->FillTH1D(region+"_"+"jets_n", jets_n, nomWeight);
       m_hstMngr->FillTH1D(region+"_"+"bjets_n", bjets_n, nomWeight);
-     
+
+      if(dolowb){
+	m_hstMngr->FillTH1D(region+"_"+"dRmin_bb_lowb_3b", dRmin_bb_lowb_3b, nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"mT_bmin_lowb_3b", mT_bmin_lowb_3b, nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"mbb_mindr_lowb_3b", mbb_mindr_lowb_3b, nomWeight);
+
+	m_hstMngr->FillTH1D(region+"_"+"dRmin_bb_lowb_4b", dRmin_bb_lowb_4b, nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"mT_bmin_lowb_4b", mT_bmin_lowb_4b, nomWeight);
+	m_hstMngr->FillTH1D(region+"_"+"mbb_mindr_lowb_4b", mbb_mindr_lowb_4b, nomWeight);
+      }
     }// Regions
     
   }//Event loop
-  
+  /*
+  for(const std::string region:regions){
+    m_hstMngr->GetTH2D(region+"_nrg_avg_bjet1_eta_vs_phi")->Divide( m_hstMngr->GetTH2D(region+"bjet1_eta_vs_phi")   );
+    m_hstMngr->GetTH2D(region+"_nrg_avg_ljet1_eta_vs_phi")->Divide( m_hstMngr->GetTH2D(region+"ljet1_eta_vs_phi")   );
+    m_hstMngr->GetTH2D(region+"_nrg_avg_jet1_eta_vs_phi")->Divide( m_hstMngr->GetTH2D(region+"jet1_eta_vs_phi")   );
+    m_hstMngr->GetTH2D(region+"_nrg_avg_rcjet1_eta_vs_phi")->Divide( m_hstMngr->GetTH2D(region+"rcjet1_eta_vs_phi")   );
+
+    m_hstMngr->GetTH2D(region+"_nrg_avg_bjets_eta_vs_phi")->Divide( m_hstMngr->GetTH2D(region+"bjets_eta_vs_phi")   );
+    m_hstMngr->GetTH2D(region+"_nrg_avg_ljets_eta_vs_phi")->Divide( m_hstMngr->GetTH2D(region+"ljets_eta_vs_phi")   );
+    m_hstMngr->GetTH2D(region+"_nrg_avg_jets_eta_vs_phi")->Divide( m_hstMngr->GetTH2D(region+"jets_eta_vs_phi")   );
+    m_hstMngr->GetTH2D(region+"_nrg_avg_rcjets_eta_vs_phi")->Divide( m_hstMngr->GetTH2D(region+"rcjets_eta_vs_phi")   );
+
+    m_hstMngr->GetTH2D(region+"_nrg_avg_bjets_rc1_eta_vs_phi")->Divide( m_hstMngr->GetTH2D(region+"bjets_rc1_eta_vs_phi")   );
+    m_hstMngr->GetTH2D(region+"_nrg_avg_ljets_rc1_eta_vs_phi")->Divide( m_hstMngr->GetTH2D(region+"ljets_rc1_eta_vs_phi")   );
+    m_hstMngr->GetTH2D(region+"_nrg_avg_jets_rc1_eta_vs_phi")->Divide( m_hstMngr->GetTH2D(region+"jets_rc1_eta_vs_phi")   );
+
+  }
+  */
   TFile* outfile = TFile::Open(argv[2], "RECREATE");
   outfile->cd(); 
   for( const std::string hist : m_hstMngr->GetTH1KeyList() ){
     m_hstMngr->FinaliseTH1Bins(hist); 
     m_hstMngr->GetTH1D(hist)->Write();
   }
+  /*
+  for( const std::string hist : m_hstMngr->GetTH2KeyList() ){
+    m_hstMngr->GetTH2D(hist)->Write();
+  }
+  */
   outfile->Close();
   delete outfile;
   
   m_hstMngr->ClearAllTH1();
+  m_hstMngr->ClearAllTH2();
   delete m_hstMngr;
   delete fChain; 
   
diff --git a/macros/macros_trisha/mergeOutputs.sh b/macros/macros_trisha/mergeOutputs.sh
index b4b68c1..c2d87b5 100755
--- a/macros/macros_trisha/mergeOutputs.sh
+++ b/macros/macros_trisha/mergeOutputs.sh
@@ -12,12 +12,8 @@ hadd MergedFiles/outVLQAnalysis_ttbarlight_nominal.root HistFiles/outVLQAnalysis
 hadd MergedFiles/outVLQAnalysis_ttbarcc_nominal.root HistFiles/outVLQAnalysis_ttbarcc_*.root
 hadd MergedFiles/outVLQAnalysis_ttbarbb_nominal.root HistFiles/outVLQAnalysis_ttbarbb_*.root
 hadd MergedFiles/outVLQAnalysis_singletop_nominal.root HistFiles/outVLQAnalysis_Singletop_*.root
-hadd MergedFiles/outVLQAnalysis_Wjets22_nominal.root HistFiles/outVLQAnalysis_W+jets22_*.root
-hadd MergedFiles/outVLQAnalysis_Zjets22_nominal.root HistFiles/outVLQAnalysis_Z+jets22_*.root
+hadd MergedFiles/outVLQAnalysis_Wjets22_nominal.root HistFiles/outVLQAnalysis_W+jets22*_*.root
+hadd MergedFiles/outVLQAnalysis_Zjets22_nominal.root HistFiles/outVLQAnalysis_Z+jets22*_*.root
 hadd MergedFiles/outVLQAnalysis_others_nominal.root HistFiles/outVLQAnalysis_topEW_*.root HistFiles/outVLQAnalysis_ttH_*.root HistFiles/outVLQAnalysis_Dibosons_*.root HistFiles/outVLQAnalysis_4tops_*.root
 
-#hadd MergedFiles/outVLQAnalysis_Zjets22_nunu_nominal.root HistFiles/outVLQAnalysis_*363412*.root  HistFiles/outVLQAnalysis_*363413*.root  HistFiles/outVLQAnalysis_*363414*.root  HistFiles/outVLQAnalysis_*363415*.root  HistFiles/outVLQAnalysis_*363416*.root  HistFiles/outVLQAnalysis_*363417*.root  HistFiles/outVLQAnalysis_*363418*.root  HistFiles/outVLQAnalysis_*363419*.root  HistFiles/outVLQAnalysis_*363420*.root  HistFiles/outVLQAnalysis_*363421*.root  HistFiles/outVLQAnalysis_*363422*.root  HistFiles/outVLQAnalysis_*363423*.root  HistFiles/outVLQAnalysis_*363424*.root  HistFiles/outVLQAnalysis_*363425*.root  HistFiles/outVLQAnalysis_*363426*.root  HistFiles/outVLQAnalysis_*363427*.root  HistFiles/outVLQAnalysis_*363428*.root  HistFiles/outVLQAnalysis_*363429*.root  HistFiles/outVLQAnalysis_*363430*.root  HistFiles/outVLQAnalysis_*363431*.root  HistFiles/outVLQAnalysis_*363432*.root  HistFiles/outVLQAnalysis_*363433*.root  HistFiles/outVLQAnalysis_*363434*.root  HistFiles/outVLQAnalysis_*363435*.root 
-
-#hadd MergedFiles/outVLQAnalysis_others_nominal.root HistFiles/outVLQAnalysis_Dibosons_*.root HistFiles/outVLQAnalysis_4tops_*.root
-
 cd ${CURDIR}
diff --git a/python/Submit_VLQAnalysis.py b/python/Submit_VLQAnalysis.py
index ec73ac2..8696456 100644
--- a/python/Submit_VLQAnalysis.py
+++ b/python/Submit_VLQAnalysis.py
@@ -15,20 +15,23 @@ from Samples import *
 ## OPTIONS
 nFilesSplit = 200 #number of files to merge in a single run of the code (chaining them)
 nMerge = 10 #number of merged running of the code in a single job
+
 channels = ["./.",]
 useMiniIsolation = False
 usePileUpWeight = True
 #Samples
 param_useSlices = True
 #Top corrections
+param_scaleHtSlices = True
 param_applyTtbbCorrection = True
 param_recomputeTTBB = True
-param_reweightTTcomponents = False
+param_computeTTCC = True
+param_reweightTTcomponents = True
 param_applyTopPtWeight = True
 param_applyVjetsSherpa22RW = True
 #Job parameters
 btagOP = "77"
-param_recomputeBtagSF=False
+param_recomputeBtagSF=True
 doBlind = False 
 dumpHistos = True
 dumpTree = False
@@ -77,7 +80,7 @@ here = os.getcwd()
 ##________________________________________________________
 ## Defining the paths and the tarball
 inputDir="/nfs/at3/scratch2/lvalery/VLQFiles/AT-00-00-12/" #place where to find the input files
-#inputDir="/nfs/at3/scratch2/farooque/VLQFiles/tag_00_00_15_noTRIGMATCH/"
+#inputDir="/nfs/at3/scratch2/farooque/VLQFiles/tag_00_00_16_METTRIG/"
 #inputDir="/nfs/at3/scratch2/farooque/VLQFiles/tag_00_00_14/2016/"
 outputDir = "/nfs/at3/scratch2/"+os.getenv("USER")+"/VLQAnalysisRun2/VLQAnalysisOutputs_" #output repository
 if useMiniIsolation:
@@ -212,6 +215,11 @@ for channel in channels:
             else:
                 jO.addOption("RECOMPUTETTBBRW","false")
 
+            if param_computeTTCC and SType.find("ttbar")>-1:
+                jO.addOption("COMPUTETTCCNLO","true")
+            else:
+                jO.addOption("COMPUTETTCCNLO","false")
+
             #ttbar fractions reweighting
             if param_reweightTTcomponents and SType.find("ttbar")>-1 and SName.find("410000")==-1:
                 jO.addOption("RWTTFRACTIONS","true")
@@ -278,6 +286,11 @@ for channel in channels:
                     jO.addOption("APPLYTTBARNNLOCORRECTION","true")
                 else:
                     jO.addOption("APPLYTTBARNNLOCORRECTION","false")
+                
+                if param_scaleHtSlices:
+                    jO.addOption("SCALETTBARHTSLICES","true")
+                else:
+                    jO.addOption("SCALETTBARHTSLICES","false")
 
             if SType.find("W+jets22")>-1 or SType.find("Z+jets22")>-1 :
 
-- 
GitLab


From 04aad4d51403edfa72332073afbf7cfa843a1284 Mon Sep 17 00:00:00 2001
From: "tfarooque@ifae.es" <tfarooque@at306.pic.es>
Date: Tue, 30 Aug 2016 22:00:18 +0200
Subject: [PATCH 2/3] Big fix for V+jets Sherpa reweighting with new samples;
 new options for RC jets pT and nsubjets cuts

---
 Root/VLQ_AnalysisTools.cxx               |  5 +++--
 Root/VLQ_Analysis_Data2015.cxx           |  4 +++-
 Root/VLQ_Options.cxx                     |  7 +++++++
 VLQAnalysis/VLQ_Options.h                |  2 ++
 macros/macros_trisha/mergeOutputTrees.sh |  6 +++---
 python/Submit_VLQAnalysis.py             | 17 +++++++++++++----
 6 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/Root/VLQ_AnalysisTools.cxx b/Root/VLQ_AnalysisTools.cxx
index 1c1ef17..9a56e09 100644
--- a/Root/VLQ_AnalysisTools.cxx
+++ b/Root/VLQ_AnalysisTools.cxx
@@ -234,8 +234,9 @@ bool VLQ_AnalysisTools::GetObjectVectors(){
                 std::cout << "    eta " <<  TMath::Abs(m_ntupData -> d_rcjets_eta -> at(iRCJet));
                 std::cout << "    nconsts " << m_ntupData -> d_rcjets_nconsts -> at(iRCJet);
             }
-
-            if(m_ntupData -> d_rcjets_pt -> at(iRCJet)/1000. >= 300 && TMath::Abs(m_ntupData -> d_rcjets_eta -> at(iRCJet)) < 2.0 && m_ntupData -> d_rcjets_nconsts -> at(iRCJet) >= m_opt->RCNsubjetsCut() ){
+            if(m_ntupData -> d_rcjets_pt -> at(iRCJet)/1000. >= m_opt->RCJetsPtCut() 
+	       && TMath::Abs(m_ntupData -> d_rcjets_eta -> at(iRCJet)) < 2.0 
+	       && m_ntupData -> d_rcjets_nconsts -> at(iRCJet) >= m_opt->RCNsubjetsCut() ){
                 AnalysisObject *obj = new AnalysisObject();
                 obj -> SetPtEtaPhiM( m_ntupData -> d_rcjets_pt -> at(iRCJet)/1000., m_ntupData -> d_rcjets_eta -> at(iRCJet),
                                     m_ntupData -> d_rcjets_phi -> at(iRCJet), m_ntupData -> d_rcjets_m -> at(iRCJet)/1000. );
diff --git a/Root/VLQ_Analysis_Data2015.cxx b/Root/VLQ_Analysis_Data2015.cxx
index 39e89a2..9316d2b 100644
--- a/Root/VLQ_Analysis_Data2015.cxx
+++ b/Root/VLQ_Analysis_Data2015.cxx
@@ -144,7 +144,8 @@ VLQ_Analysis_Data2015::~VLQ_Analysis_Data2015()
     bool isTtbar =  (m_opt -> SampleName() == SampleName::TTBAR) || (m_opt -> SampleName() == SampleName::TTBARBB) 
       || (m_opt -> SampleName() == SampleName::TTBARCC) || (m_opt -> SampleName() == SampleName::TTBARLIGHT);
 
-    bool isVjets22 = (m_opt -> StrSampleName()=="W+JETS22") ||(m_opt -> StrSampleName()=="Z+JETS22"); 
+    bool isVjets22 = ( (m_opt -> StrSampleName().find("W+JETS22") != std::string::npos) 
+		       || (m_opt -> StrSampleName().find("Z+JETS22") != std::string::npos) ); 
     m_weightMngr    ->  SetConfigBlock( "SCALETTBARHTSLICES", isTtbar && m_opt -> ScaleTtbarHtSlices() );
     m_weightMngr    ->  SetConfigBlock( "USETTBBCORRECTION", isTtbar && m_opt -> ApplyTtbbCorrection() );
     m_weightMngr    ->  SetConfigBlock( "USETTBARFRACTIONSREWEIGHTING", isTtbar && m_opt -> ReweightTtbarFractions() );
@@ -1107,6 +1108,7 @@ bool VLQ_Analysis_Data2015::Process(Long64_t entry)
     if( m_outData -> o_period == VLQ_Enums::DATA2016 ){ return false; }//FIXME set rejectionMask
     else{  m_outData -> o_eventWeight_Nom *= (13207.69/3212.96); }//Rescale by 2015+2016 luminosity
   }
+
   //ALERTRISHA - Checking electron fake estimate with full data period
 
   if(m_opt -> MsgLevel() == Debug::DEBUG) std::cout << "==> After setting the weight " << entry << std::endl;
diff --git a/Root/VLQ_Options.cxx b/Root/VLQ_Options.cxx
index bef58d1..68ccc68 100644
--- a/Root/VLQ_Options.cxx
+++ b/Root/VLQ_Options.cxx
@@ -47,6 +47,7 @@ m_applyVjetsSherpa22RW(false),
 m_computeTtccNLO(false),
 m_maxb(4),
 m_RCNsubjetsCut(2),
+m_RCJetsPtCut(300.),
 m_jetsPtCut(25.),
 m_jetsEtaCut(2.5),
 m_lepPtCut(25.),
@@ -92,6 +93,8 @@ OptionsBase(q)
     m_computeTtccNLO    = q.m_computeTtccNLO;
     m_RecTtBbRw         = q.m_RecTtBbRw;
     m_RwTtFractions     = q.m_RwTtFractions;
+    m_RCNsubjetsCut     = q.m_RCNsubjetsCut;
+    m_RCJetsPtCut       = q.m_RCJetsPtCut;
     m_jetsPtCut         = q.m_jetsPtCut;
     m_jetsEtaCut        = q.m_jetsEtaCut;
     m_lepPtCut          = q.m_lepPtCut;
@@ -185,6 +188,9 @@ bool VLQ_Options::IdentifyOption ( const std::string &argument, const std::strin
         //
         // Float arguments
         //
+        else if( temp_arg.find("--RCJETPTCUT") != std::string::npos ){
+            m_RCJetsPtCut = atof(temp_val.c_str());
+        }
         else if( temp_arg.find("--JETPTCUT") != std::string::npos ){
             m_jetsPtCut = atof(temp_val.c_str());
         }
@@ -253,6 +259,7 @@ void VLQ_Options::PrintOptions(){
     std::cout << " m_qcdMode                 = " << m_QCDMode           << std::endl;
     std::cout << " m_maxb                    = " << m_maxb              << std::endl;
     std::cout << " m_RCNsubjetsCut           = " << m_RCNsubjetsCut     << std::endl;
+    std::cout << " m_RCJetsPtCut             = " << m_RCJetsPtCut       << std::endl;
     std::cout << " m_applyMetMtwCuts         = " << m_applyMetMtwCuts   << std::endl;
     std::cout << " m_invertMetMtwCuts        = " << m_invertMetMtwCuts   << std::endl;
     std::cout << " m_applyDeltaPhiCut        = " << m_applyDeltaPhiCut  << std::endl;
diff --git a/VLQAnalysis/VLQ_Options.h b/VLQAnalysis/VLQ_Options.h
index 63a0eee..759cf58 100644
--- a/VLQAnalysis/VLQ_Options.h
+++ b/VLQAnalysis/VLQ_Options.h
@@ -66,6 +66,7 @@ public:
     inline std::string TRFCDIPath() const { return m_TRFCDIPath; }
     inline std::string QCDMode() const { return m_QCDMode; }
     // doubles
+    inline double RCJetsPtCut() const { return m_RCJetsPtCut; }
     inline double JetsPtCut() const { return m_jetsPtCut; }
     inline double JetsEtaCut() const { return m_jetsEtaCut; }
     inline double LepPtCut() const { return m_lepPtCut; }
@@ -112,6 +113,7 @@ private:
     bool m_computeTtccNLO;
     int m_maxb;
     int m_RCNsubjetsCut;
+    double m_RCJetsPtCut;
     double m_jetsPtCut;
     double m_jetsEtaCut;
     double m_lepPtCut;
diff --git a/macros/macros_trisha/mergeOutputTrees.sh b/macros/macros_trisha/mergeOutputTrees.sh
index 6bbfc20..97a7475 100755
--- a/macros/macros_trisha/mergeOutputTrees.sh
+++ b/macros/macros_trisha/mergeOutputTrees.sh
@@ -6,13 +6,13 @@ CURDIR=$PWD
 cd ${INDIR}
 mkdir MergedTreeFiles
 
-#hadd MergedTreeFiles/outVLQAnalysis_Data_nominalTREE.root TreeFiles/outVLQAnalysis_Data_*TREE.root
+hadd MergedTreeFiles/outVLQAnalysis_Data_nominalTREE.root TreeFiles/outVLQAnalysis_Data_*TREE.root
 hadd MergedTreeFiles/outVLQAnalysis_ttbarlight_nominalTREE.root TreeFiles/outVLQAnalysis_ttbarlight_41*TREE.root TreeFiles/outVLQAnalysis_ttbarlight_40*TREE.root 
 hadd MergedTreeFiles/outVLQAnalysis_ttbarcc_nominalTREE.root TreeFiles/outVLQAnalysis_ttbarcc_41*TREE.root TreeFiles/outVLQAnalysis_ttbarcc_40*TREE.root
 hadd MergedTreeFiles/outVLQAnalysis_ttbarbb_nominalTREE.root TreeFiles/outVLQAnalysis_ttbarbb_41*TREE.root TreeFiles/outVLQAnalysis_ttbarbb_40*TREE.root
 hadd MergedTreeFiles/outVLQAnalysis_singletop_nominalTREE.root TreeFiles/outVLQAnalysis_Singletop_*TREE.root
-hadd MergedTreeFiles/outVLQAnalysis_Wjets22_nominalTREE.root TreeFiles/outVLQAnalysis_W+jets22_*TREE.root
-hadd MergedTreeFiles/outVLQAnalysis_Zjets22_nominalTREE.root TreeFiles/outVLQAnalysis_Z+jets22_*TREE.root
+hadd MergedTreeFiles/outVLQAnalysis_Wjets22_nominalTREE.root TreeFiles/outVLQAnalysis_W+jets22*_*TREE.root
+hadd MergedTreeFiles/outVLQAnalysis_Zjets22_nominalTREE.root TreeFiles/outVLQAnalysis_Z+jets22*_*TREE.root
 hadd MergedTreeFiles/outVLQAnalysis_others_nominal_TREE.root TreeFiles/outVLQAnalysis_topEW_*TREE.root TreeFiles/outVLQAnalysis_ttH_*TREE.root TreeFiles/outVLQAnalysis_Dibosons_*TREE.root TreeFiles/outVLQAnalysis_4tops_*TREE.root
 
 
diff --git a/python/Submit_VLQAnalysis.py b/python/Submit_VLQAnalysis.py
index 8696456..ce4a37d 100644
--- a/python/Submit_VLQAnalysis.py
+++ b/python/Submit_VLQAnalysis.py
@@ -33,22 +33,25 @@ param_applyVjetsSherpa22RW = True
 btagOP = "77"
 param_recomputeBtagSF=True
 doBlind = False 
-dumpHistos = True
-dumpTree = False
+dumpHistos = True 
+dumpTree = False 
 splitVLQDecays = True
 doTruthAnalysis = False
-param_applyMetMtwCuts = True
+param_applyMetMtwCuts = True 
 param_invertMetMtwCuts = False
 param_useLeptonSF = True
 param_drawOtherVariables = False #Set it to true with great care !!! (default should be false)
 param_do1lepAna = True
 param_do0lepAna = True
-param_doLowBRegions = False
+param_doLowBRegions = False 
 param_useLeptonTrigger = True
 param_useMETTrigger = True
 param_applyDPhiCut = True
 param_invertDPhiCut = False
 param_jetPtCut = "25"
+param_RCJetPtCut = "300"
+param_RCNSJCut = "2"
+
 #TRF
 param_doTRF = False
 param_doTRF_forSmallBackgrounds = False
@@ -390,6 +393,12 @@ for channel in channels:
             # Jet pT cut
             jO.addOption("jetPtCut",param_jetPtCut)
 
+            # RC Jet pT cut
+            jO.addOption("RCJetPtCut",param_RCJetPtCut)
+
+            #RC Jet subjet multiplicity
+            jO.addOption("RCNSUBJETSCUT", param_RCNSJCut)
+
             # Use deltaPhi cut
             if param_applyDPhiCut:
                 jO.addOption("applydeltaphicut","true")
-- 
GitLab


From 16503d392c9e89ffade4acae5a74707fee3a5fb9 Mon Sep 17 00:00:00 2001
From: "tfarooque@ifae.es" <tfarooque@at302.pic.es>
Date: Sat, 3 Sep 2016 00:35:41 +0200
Subject: [PATCH 3/3] Fixed recomputeBTagSF default value in
 Submit_VLQAnalysis.py

---
 python/Submit_VLQAnalysis.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/python/Submit_VLQAnalysis.py b/python/Submit_VLQAnalysis.py
index ce4a37d..0d9281f 100644
--- a/python/Submit_VLQAnalysis.py
+++ b/python/Submit_VLQAnalysis.py
@@ -31,7 +31,7 @@ param_applyTopPtWeight = True
 param_applyVjetsSherpa22RW = True
 #Job parameters
 btagOP = "77"
-param_recomputeBtagSF=True
+param_recomputeBtagSF=False
 doBlind = False 
 dumpHistos = True 
 dumpTree = False 
-- 
GitLab