コード例 #1
0
int main(int argc, char** argv)
{
  //Check if all nedeed arguments to parse are there
  if(argc != 2)
  {
    std::cerr << ">>>>> WZAnalysis::usage: " << argv[0] << " configFileName" << std::endl ;
    return 1;
  }
  
  std::string fileName(argv[1]);
  boost::shared_ptr<edm::ParameterSet> parameterSet = edm::readConfig(fileName);
  
  
  // "Input"
  edm::ParameterSet Input =  parameterSet -> getParameter<edm::ParameterSet>("Input");
  std::string inputFileList = Input.getParameter<std::string>("inputFileList");
  std::string jsonFileName  = Input.getParameter<std::string>("jsonFileName");
  
  
  // "Output"
  edm::ParameterSet Output =  parameterSet -> getParameter<edm::ParameterSet>("Output");
  std::string outputRootFilePath = Output.getParameter<std::string>("outputRootFilePath");
  std::string outputRootFileName = Output.getParameter<std::string>("outputRootFileName");
  std::string outputRootFullFileName = outputRootFilePath + "/" + outputRootFileName + ".root";
  
  
  // "Options"
  edm::ParameterSet Options =  parameterSet -> getParameter<edm::ParameterSet>("Options");
  int entryMIN       = Options.getParameter<int>("entryMIN");
  int entryMAX       = Options.getParameter<int>("entryMAX");
  int entryMODULO    = Options.getParameter<int>("entryMODULO");
  int jsonFlag       = Options.getParameter<int>("jsonFlag");
  int verbosity      = Options.getParameter<int>("verbosity");
  
  
  // Get total number of events
  std::cout << ">>> WZAnalysis::Get number of events" << std::endl;
  std::map<int, int> beginEvents      = GetTotalEvents("AllPassFilterBegin/passedEvents",            inputFileList.c_str());
  std::map<int, int> goodVertexEvents = GetTotalEvents("AllPassFilterGoodVertexFilter/passedEvents", inputFileList.c_str());
  std::map<int, int> noScrapingEvents = GetTotalEvents("AllPassFilterNoScrapingFilter/passedEvents", inputFileList.c_str());
  std::map<int, int> HBHENoiseEvents  = GetTotalEvents("AllPassFilterHBHENoiseFilter/passedEvents",  inputFileList.c_str());
  std::map<int, int> electronEvents   = GetTotalEvents("AllPassFilterElectronFilter/passedEvents",   inputFileList.c_str());
  
  
  
  // Get run/LS map from JSON file
  std::cout << ">>> WZPreselection::Get run/LS map from JSON file" << std::endl;
  std::map<int, std::vector<std::pair<int, int> > > jsonMap;
  jsonMap = readJSONFile(jsonFileName);
  
  
  
  // define HLT paths
  std::vector<std::pair<std::string,std::pair<int,int> > > WHLTPathNames;
  
  std::pair<int,int> WRunRanges1(160404,161176);
  std::pair<std::string,std::pair<int,int> > WHLTPathName1("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v1",WRunRanges1);
  std::pair<int,int> WRunRanges2(161216,163261);
  std::pair<std::string,std::pair<int,int> > WHLTPathName2("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v2",WRunRanges2);
  std::pair<int,int> WRunRanges3(163269,163869);
  std::pair<std::string,std::pair<int,int> > WHLTPathName3("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v3",WRunRanges3);
  std::pair<int,int> WRunRanges4(165088,165633);
  std::pair<std::string,std::pair<int,int> > WHLTPathName4("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v3",WRunRanges4);
  std::pair<int,int> WRunRanges5(165970,166967);
  std::pair<std::string,std::pair<int,int> > WHLTPathName5("HLT_Ele25_WP80_PFMT40_v1",WRunRanges5);
  std::pair<int,int> WRunRanges6(167039,167913);
  std::pair<std::string,std::pair<int,int> > WHLTPathName6("HLT_Ele27_WP80_PFMT50_v1",WRunRanges6);
  std::pair<int,int> WRunRanges7(170249,173198);
  std::pair<std::string,std::pair<int,int> > WHLTPathName7("HLT_Ele32_WP70_PFMT50_v3",WRunRanges7);
  std::pair<int,int> WRunRanges8(173236,999999);
  std::pair<std::string,std::pair<int,int> > WHLTPathName8("HLT_Ele32_WP70_PFMT50_v4",WRunRanges8);
  
  WHLTPathNames.push_back(WHLTPathName1);
  WHLTPathNames.push_back(WHLTPathName2);
  WHLTPathNames.push_back(WHLTPathName3);
  WHLTPathNames.push_back(WHLTPathName4);
  WHLTPathNames.push_back(WHLTPathName5);
  WHLTPathNames.push_back(WHLTPathName6);
  WHLTPathNames.push_back(WHLTPathName7);
  WHLTPathNames.push_back(WHLTPathName8);
  
  
  
  std::vector<std::pair<std::string,std::pair<int,int> > > ZHLTPathNames;
  
  std::pair<int,int> ZRunRanges1(160404,161176);
  std::pair<std::string,std::pair<int,int> > ZHLTPathName1("HLT_Ele17_CaloIdL_CaloIsoVL_Ele8_CaloIdL_CaloIsoVL_v1",ZRunRanges1);
  std::pair<int,int> ZRunRanges2(161216,163261);
  std::pair<std::string,std::pair<int,int> > ZHLTPathName2("HLT_Ele17_CaloIdL_CaloIsoVL_Ele8_CaloIdL_CaloIsoVL_v2",ZRunRanges2);
  std::pair<int,int> ZRunRanges3(163269,163869);
  std::pair<std::string,std::pair<int,int> > ZHLTPathName3("HLT_Ele17_CaloIdL_CaloIsoVL_Ele8_CaloIdL_CaloIsoVL_v3",ZRunRanges3);
  std::pair<int,int> ZRunRanges4(165088,165633);
  std::pair<std::string,std::pair<int,int> > ZHLTPathName4("HLT_Ele17_CaloIdL_CaloIsoVL_Ele8_CaloIdL_CaloIsoVL_v4",ZRunRanges4);
  std::pair<int,int> ZRunRanges5(165970,166967);
  std::pair<std::string,std::pair<int,int> > ZHLTPathName5("HLT_Ele17_CaloIdL_CaloIsoVL_Ele8_CaloIdL_CaloIsoVL_v5",ZRunRanges5);
  std::pair<int,int> ZRunRanges6(167039,167913);
  std::pair<std::string,std::pair<int,int> > ZHLTPathName6("HLT_Ele17_CaloIdL_CaloIsoVL_Ele8_CaloIdL_CaloIsoVL_v6",ZRunRanges6);
  std::pair<int,int> ZRunRanges7(170249,170759);
  std::pair<std::string,std::pair<int,int> > ZHLTPathName7("HLT_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_v6",ZRunRanges7);
  std::pair<int,int> ZRunRanges8(170826,173198);
  std::pair<std::string,std::pair<int,int> > ZHLTPathName8("HLT_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_v7",ZRunRanges8);
  std::pair<int,int> ZRunRanges9(173236,999999);
  std::pair<std::string,std::pair<int,int> > ZHLTPathName9("HLT_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_v8",ZRunRanges9);
  
  ZHLTPathNames.push_back(ZHLTPathName1);
  ZHLTPathNames.push_back(ZHLTPathName2);
  ZHLTPathNames.push_back(ZHLTPathName3);
  ZHLTPathNames.push_back(ZHLTPathName4);
  ZHLTPathNames.push_back(ZHLTPathName5);
  ZHLTPathNames.push_back(ZHLTPathName6);
  ZHLTPathNames.push_back(ZHLTPathName7);
  ZHLTPathNames.push_back(ZHLTPathName8);
  ZHLTPathNames.push_back(ZHLTPathName9);
  
  
  
  // Open tree
  std::cout << ">>> WZAnalysis::Open old tree" << std::endl;
  std::string treeName = "simpleNtuple/SimpleNtuple";
  TChain* chain = new TChain(treeName.c_str());
  if(!FillChain(*chain, inputFileList.c_str())) return 1;
  treeReader reader((TTree*)(chain), false);
  
  
  
  // Open output root file
  outputRootFileName += ".root";
  
  
  
  // define histograms
  std::cout << ">>> WZAnalysis::Define histograms" << std::endl;
  
  int nStep = 10;
  TH1F* events = new TH1F("events", "events", nStep, 0., 1.*nStep);
  std::map<int, int> stepEvents;
  std::map<int, std::string> stepNames;
  
  
  
  // define the reduced ntuple 
  WZAnalysisVariablesSingleXtal vars;
  InitializeWZAnalysisTree(vars,outputRootFullFileName);
  
  
   
  //**********************
  // STEP 1 - Begin events
  int step = 1;
  SetStepNames(stepNames, "All events", step, verbosity);
  stepEvents[step] = beginEvents[1];
  
  
  
  //****************************
  // STEP 2 - Good Vertex events
  step = 2;
  SetStepNames(stepNames, "Good vertex", step, verbosity);
  stepEvents[step] = goodVertexEvents[1];
  
  
  
  //*********************
  // STEP 3 - No Scraping
  step = 3;
  SetStepNames(stepNames, "No scraping", step, verbosity);
  stepEvents[step] = noScrapingEvents[1];
  
  
  
  //*********************
  // STEP 4 - HBHE Noise
  step = 4;
  SetStepNames(stepNames, "HBHE Noise", step, verbosity);
  stepEvents[step] = HBHENoiseEvents[1];
  
  
  
  //******************
  // STEP 5 - Electron
  step = 5;
  SetStepNames(stepNames, "Electron", step, verbosity);
  stepEvents[step] = electronEvents[1];
   
  
  
  //*********************
  // LOOP OVER THE EVENTS
  std::cout << ">>>>> WZAnalysis::Read " << chain -> GetEntries() << " entries" << std::endl;  
  for(int entry = entryMIN ; entry < chain -> GetEntries() ; ++entry)
  {
    reader.GetEntry(entry);
    if((entry%entryMODULO) == 0) std::cout << ">>>>> WZAnalysis::GetEntry " << entry << std::endl;   
    if(entry == entryMAX) break;
      
    // clear variables
    ClearWZAnalysisVariables(vars);    
    
    // event variables
    vars.runId   = reader.GetInt("runId")->at(0);
    vars.lumiId  = reader.GetInt("lumiId")->at(0);
    
    
    //**************************
    // STEP 6 - run/LS selection
    step = 6;
    SetStepNames(stepNames, "run/LS", step, verbosity);
    
    bool skipEvent = false;
    
    if(AcceptEventByRunAndLumiSection(vars.runId,vars.lumiId,jsonMap) == false)
      skipEvent = true;

    if( (jsonFlag == 1) && (skipEvent == true) ) continue;
    stepEvents[step] += 1;
    
    //***********************
    // STEP 7 - HLT selection
    step += 1;
    SetStepNames(stepNames, "HLT", step, verbosity);
    
    
    skipEvent = true;
    bool isWHLT = false;
    bool isZHLT = false;
    
    if( verbosity == 1 )
    {
      std::vector<std::string> HLT_names = *(reader.GetString("HLT_Names"));
      for(unsigned int HLTIt = 0; HLTIt < HLT_names.size(); ++HLTIt)
        std::cout << "HLT bit " << HLTIt 
            << ":   "     << HLT_names.at(HLTIt)
            << std::endl;
    }
    
    // W triggers
    for(unsigned int HLTIt = 0; HLTIt < WHLTPathNames.size(); ++HLTIt)
    {
      if( AcceptHLTPath(reader, WHLTPathNames.at(HLTIt)) == true )
        skipEvent = false;
      isWHLT = true;
    }
    // Z triggers
    for(unsigned int HLTIt = 0; HLTIt < ZHLTPathNames.size(); ++HLTIt)
    {
      if( AcceptHLTPath(reader, ZHLTPathNames.at(HLTIt)) == true )
        skipEvent = false;
      isZHLT = true; 
    }
    
    if( skipEvent == true ) continue;
    stepEvents[step] += 1;    
        
    
    
    
    
    
    //**************************
    // STEP 8 - cut on electrons
    step += 1;
    SetStepNames(stepNames, "1/2 ele", step, verbosity);
    
    
    int nTightEle = 0;
    int nMediumEle = 0;
    int nLooseEle = 0;
    std::map<float,int> eleIts;
    
    // loop on electrons
    for(unsigned int eleIt = 0; eleIt < (reader.Get4V("electrons")->size()); ++eleIt)
    {
      ROOT::Math::XYZTVector ele = reader.Get4V("electrons")->at(eleIt);
      float pt = ele.pt();
      float eta = ele.eta();
      
      float tkIso  = reader.GetFloat("electrons_tkIso03")->at(eleIt);
      float emIso  = reader.GetFloat("electrons_emIso03")->at(eleIt);
      float hadIso = reader.GetFloat("electrons_hadIso03_1")->at(eleIt) + 
          reader.GetFloat("electrons_hadIso03_2")->at(eleIt);
      float combIso = tkIso + emIso + hadIso;
      
      int isEB = reader.GetInt("electrons_isEB")->at(eleIt);
      
      float sigmaIetaIeta = reader.GetFloat("electrons_sigmaIetaIeta")->at(eleIt);
      float DetaIn        = reader.GetFloat("electrons_deltaEtaIn")->at(eleIt);
      float DphiIn        = reader.GetFloat("electrons_deltaPhiIn")->at(eleIt);
      float HOverE        = reader.GetFloat("electrons_hOverE")->at(eleIt);
      
      int mishits             = reader.GetInt("electrons_mishits")->at(eleIt);
      int nAmbiguousGsfTracks = reader.GetInt("electrons_nAmbiguousGsfTracks")->at(eleIt);
      float dist = reader.GetFloat("electrons_dist")->at(eleIt);
      float dcot = reader.GetFloat("electrons_dcot")->at(eleIt);
      
      
      // tight electrons
      bool isTightElectron = false;
      if(
         (pt > 20.) &&
         (fabs(eta) < 2.5) &&
          // EleID WP80 - 2010
         ( ( (isEB == 1) && (combIso/pt    < 0.070) ) || ( (isEB == 0) && (combIso/pt    < 0.060) ) ) &&
         ( ( (isEB == 1) && (sigmaIetaIeta < 0.010) ) || ( (isEB == 0) && (sigmaIetaIeta < 0.030) ) ) &&
         ( ( (isEB == 1) && (fabs(DphiIn)  < 0.060) ) || ( (isEB == 0) && (fabs(DphiIn)  < 0.030) ) ) &&
         ( ( (isEB == 1) && (fabs(DetaIn)  < 0.004) ) || ( (isEB == 0) && (fabs(DetaIn)  < 0.007) ) ) &&
          //( ( (isEB == 1) && (HOverE        < 0.040) ) || ( (isEB == 0) && (HOverE        < 0.025) ) ) &&
         ( mishits == 0 ) &&
         ( nAmbiguousGsfTracks == 0 ) &&
         ( ( fabs(dist) > 0.02 ) || ( fabs(dcot) > 0.02 ) )
        )
      {
        isTightElectron = true;
        ++nTightEle;
        eleIts[1./pt] = eleIt;
      }
      
      
      // semi-tight electrons
      if( isTightElectron == true ) continue;
      //      bool isMediumElectron = false;
      if(
         (pt > 12.) &&
         (fabs(eta) < 2.5) &&
          // EleID WP80 - 2010
         ( ( (isEB == 1) && (combIso/pt    < 0.070) ) || ( (isEB == 0) && (combIso/pt    < 0.060) ) ) &&
         ( ( (isEB == 1) && (sigmaIetaIeta < 0.010) ) || ( (isEB == 0) && (sigmaIetaIeta < 0.030) ) ) &&
         ( ( (isEB == 1) && (fabs(DphiIn)  < 0.060) ) || ( (isEB == 0) && (fabs(DphiIn)  < 0.030) ) ) &&
         ( ( (isEB == 1) && (fabs(DetaIn)  < 0.004) ) || ( (isEB == 0) && (fabs(DetaIn)  < 0.007) ) ) &&
          //( ( (isEB == 1) && (HOverE        < 0.040) ) || ( (isEB == 0) && (HOverE        < 0.025) ) ) &&
         ( mishits == 0 ) &&
         ( nAmbiguousGsfTracks == 0 ) &&
         ( ( fabs(dist) > 0.02 ) || ( fabs(dcot) > 0.02 ) )
        )
      {
	//        isMediumElectron = true;
        ++nMediumEle;
        eleIts[1./pt] = eleIt;
      }
      
      
      // loose electrons
      if( isTightElectron == true ) continue;
      if( 
          (pt > 10.) &&
          (fabs(eta) < 2.5) &&
          // EleID WP95 - 2010
          ( ( (isEB == 1) && (combIso/pt    < 0.150) ) || ( (isEB == 0) && (combIso/pt    < 0.100) ) ) &&
          ( ( (isEB == 1) && (sigmaIetaIeta < 0.010) ) || ( (isEB == 0) && (sigmaIetaIeta < 0.030) ) ) &&
          ( ( (isEB == 1) && (fabs(DphiIn)  < 0.800) ) || ( (isEB == 0) && (fabs(DphiIn)  < 0.700) ) ) &&
          ( ( (isEB == 1) && (fabs(DetaIn)  < 0.007) ) || ( (isEB == 0) && (fabs(DetaIn)  < 0.010) ) ) &&
          ( ( (isEB == 1) && (HOverE        < 0.150) ) || ( (isEB == 0) && (HOverE        < 0.070) ) )
        )
      {
        ++nLooseEle;
      }
      
    } // loop on electrons
    
    
    
    int nLooseMu = 0;
    
    // loop on muons
    for(unsigned int muIt = 0; muIt < (reader.Get4V("muons")->size()); ++muIt)
    {
      ROOT::Math::XYZTVector mu = reader.Get4V("muons")->at(muIt);
      float pt = mu.pt();
      float eta = mu.eta();
      
      float tkIso  = reader.GetFloat("muons_tkIso03")->at(muIt);
      float emIso  = reader.GetFloat("muons_emIso03")->at(muIt);
      float hadIso = reader.GetFloat("muons_hadIso03")->at(muIt);
      float combIso = tkIso + emIso + hadIso;
      
      int global = reader.GetInt("muons_global")->at(muIt);

      if( (pt > 10.) &&
           (fabs(eta) < 2.5) &&
           (combIso/pt < 0.20) &&
           (global == 1) )
      {
        ++nLooseMu;
      }
    }
    
    
    // cuts
    if( verbosity == 1 )
      std::cout << " nTightEle = "  << nTightEle
          << " nMediumEle = " << nMediumEle
          << " nLooseEle = "  << nLooseEle
          << " nLooseMu = "   << nLooseMu
          << std::endl;
    if( nTightEle < 1 ) continue;
    if( nTightEle > 2 ) continue;
    if( nMediumEle > 1 ) continue;
    if( nLooseEle > 0 ) continue;
    if( nLooseMu > 0 ) continue;
    stepEvents[step] += 1;
    
    
    // set electron variables
    std::map<float,int>::const_iterator mapIt = eleIts.begin();

    //PhotonFix::initialise("4_2");

    if( (nTightEle == 1) && (nMediumEle == 0) )
    {
      SetElectron1Variables(vars,reader,mapIt->second);
      //PhotonFix Correction1 (vars.ele1_scE,vars.ele1_scEta,vars.ele1_scPhi,vars.ele1_e3x3/vars.ele1_scE);
      //vars.ele1_scLocalContCorr_DK = Correction1.fixedEnergy()/vars.ele1_scE;
    }
    
    mapIt = eleIts.begin();
    if( (nTightEle == 2) || (nTightEle == 1 && nMediumEle == 1) )
    {
      SetElectron1Variables(vars,reader,mapIt->second);
      //PhotonFix Correction1 (vars.ele1_scE,vars.ele1_scEta,vars.ele1_scPhi,vars.ele1_e3x3/vars.ele1_scE);
      //vars.ele1_scLocalContCorr_DK = Correction1.fixedEnergy()/vars.ele1_scE;
      
      ++mapIt;
      
      SetElectron2Variables(vars,reader,mapIt->second);
      //PhotonFix Correction2 (vars.ele2_scE,vars.ele2_scEta,vars.ele2_scPhi,vars.ele2_e3x3/vars.ele2_scE);
      //vars.ele2_scLocalContCorr_DK = Correction2.fixedEnergy()/vars.ele2_scE;
    }
    
    
    // set met variables
    SetMetVariables(vars,reader);
    
    // set di-electron variables
    if( (nTightEle == 2) || (nTightEle == 1 && nMediumEle == 1) )
    {
      SetDiElectronVariables(vars,reader);
    }
    
    
    
    
    
    
    //***********************
    // STEP 9 - W selection
    step += 1;
    SetStepNames(stepNames, "W selection", step, verbosity);
    
    
    if( (nTightEle == 1) && (nMediumEle == 0) )
    {
      if( isWHLT == false ) continue;
      if( vars.ele1_pt < 30. ) continue;
      // EleID WP70 - 2010
      if( ( vars.ele1_isEB == 1 ) && ( (vars.ele1_tkIso+vars.ele1_emIso+vars.ele1_hadIso)/vars.ele1_pt > 0.04 ) ) continue;
      if( ( vars.ele1_isEB == 1 ) && ( fabs(vars.ele1_DphiIn) > 0.030 ) ) continue;
      if( ( vars.ele1_isEB == 1 ) && ( fabs(vars.ele1_DetaIn) > 0.004 ) ) continue;
      if( ( vars.ele1_isEB == 1 ) && ( vars.ele1_HOverE > 0.025 ) ) continue;
      if( ( vars.ele1_isEB == 0 ) && ( (vars.ele1_tkIso+vars.ele1_emIso+vars.ele1_hadIso)/vars.ele1_pt > 0.03 ) ) continue;
      if( ( vars.ele1_isEB == 0 ) && ( fabs(vars.ele1_DphiIn) > 0.020 ) ) continue;
      if( ( vars.ele1_isEB == 0 ) && ( fabs(vars.ele1_DetaIn) > 0.005 ) ) continue;
      if( ( vars.ele1_isEB == 0 ) && ( vars.ele1_HOverE > 0.025 ) ) continue;
      
      if( vars.met_et       < 25.00 ) continue;
      if( vars.ele1Met_mt   < 50.00 ) continue;
      if( vars.ele1Met_Dphi <  1.57 ) continue;
      stepEvents[step] += 1;
      
      
      vars.isW = 1;
      vars.isZ = 0;
      
      
      // fill the reduced tree
      FillWZAnalysisTree(vars);
    }
    
    
    
    
    
    
    //***********************
    // STEP 10 - Z selection
    step += 1;
    SetStepNames(stepNames, "Z selection", step, verbosity);
    
    
    if( (nTightEle == 2) || (nTightEle == 1 && nMediumEle == 1) )
    {
      if( isZHLT == false ) continue;
      if( vars.met_et     >  40. ) continue;
      if( vars.ele1ele2_m <  70. ) continue;
      if( vars.ele1ele2_m > 110. ) continue;
      if( (vars.ele1_charge * vars.ele2_charge) != -1. ) continue;
      stepEvents[step] += 1;
      
      
      vars.isW = 0;
      vars.isZ = 1;
      
      
      // fill the reduced tree
      FillWZAnalysisTree(vars);
    }
    
    
    
  } // loop over the events
  
  
  
  
  
  
  // save the reduced tree
  DeleteWZAnalysisVariables(vars);
  
  
  // save the histograms
  TFile* outputRootFile = new TFile((outputRootFullFileName).c_str(), "UPDATE");
  outputRootFile -> cd();
  
  for(step = 1; step <= nStep; ++step)
  {
    events -> SetBinContent(step, stepEvents[step]);
    events -> GetXaxis() -> SetBinLabel(step, stepNames[step].c_str());
  }

  events -> Write();
  outputRootFile -> Close();
  
  
  return 0;
}
コード例 #2
0
ファイル: NtupleProducer.cpp プロジェクト: amassiro/usercode
int main(int argc, char** argv)
{ 
 //Check if all nedeed arguments to parse are there                                                                                                                               
 if(argc != 2)
 {
  std::cerr << ">>>>> analysis.cpp::usage: " << argv[0] << " configFileName" << std::endl ;
  return 1;
 }
 
 // Parse the config file                                                                                                                                                          
 parseConfigFile (argv[1]) ;
 
 std::string treeName  = gConfigParser -> readStringOption("Input::treeName");
 std::string inputFile = gConfigParser -> readStringOption("Input::inputFile");
 double inputXSection  = gConfigParser -> readDoubleOption("Input::inputXSection");
 
 int entryMAX = gConfigParser -> readIntOption("Input::entryMAX");
 int entryMIN = gConfigParser -> readIntOption("Input::entryMIN");
 int entryMOD = gConfigParser -> readIntOption("Input::entryMOD");
 
 
 std::cout << ">>>>> input::entryMIN  " << entryMIN  << std::endl;  
 std::cout << ">>>>> input::entryMAX  " << entryMAX  << std::endl;  
 std::cout << ">>>>> input::entryMOD  " << entryMOD  << std::endl;  
 
 
 int dataFlag = 0;
 if (inputXSection == -1) dataFlag = 1; //==== it's a data sample!!!
 std::cerr << ">>>>> input:: --- dataFlag  " << dataFlag << std::endl;
// define map with events
  std::map<std::pair<int,std::pair<int,int> >,int> eventsMap;  
 
 
 int nStepToDo = 1000;
 try {
  nStepToDo = gConfigParser -> readIntOption("Input::nStepToDo");
 }
 catch (char const* exceptionString){
  std::cerr << " exception = " << exceptionString << std::endl;
  nStepToDo = 1000;
 }
 std::cout << ">>>>> input::nStepToDo  " << nStepToDo  << std::endl;  
 
 
 // Open ntple
 TChain* chain = new TChain(treeName.c_str());
 chain->Add(inputFile.c_str());
 treeReader reader((TTree*)(chain));
 
 
 bool  debug = false; 
 try {
  debug = gConfigParser -> readBoolOption("Input::debug");
 }
 catch (char const* exceptionString){
  std::cerr << " exception = " << exceptionString << std::endl;
 }
 std::cout << ">>>>> input::debug  " << debug  << std::endl;  
 
 
 
 
 
 ///******************
 ///**** Triggers ****
 
 std::vector<std::string> HLTVector;
 try {
  HLTVector = gConfigParser -> readStringListOption("Options::HLTVector");
 }
 catch (char const* exceptionString){
  std::cerr << " exception = " << exceptionString << std::endl;
 }
 std::cout << ">>>>> Options::HLTVector size = " << HLTVector.size() << std::endl;  
 std::cout << ">>>>> >>>>>  "; 
 for (int iHLT = 0; iHLT < HLTVector.size(); iHLT++){
  std::cout << " " << HLTVector.at(iHLT) << ", ";
 }
 std::cout << std::endl; 
  
 ///****************************
 ///**** DATA JSON file ****
 
  std::string inFileNameJSON;
  try {
  inFileNameJSON = gConfigParser -> readStringOption("Input::inFileNameJSON");
 }
 catch (char const* exceptionString){
  std::cerr << " exception = " << exceptionString << std::endl;
 }
 std::cout << ">>>>> Input::inFileNameJSON  " << inFileNameJSON  << std::endl;  
 std::map<int, std::vector<std::pair<int, int> > > jsonMap;
 if( dataFlag == 1 ) {
   jsonMap = readJSONFile(inFileNameJSON);
}

 
 ///---- Efficiency preselections ---- 
 
 std::string histoNameEvents      = gConfigParser -> readStringOption("Input::histoNameEvents"); 
 std::cout << ">>>>> Input::inputFile                 " << inputFile  << std::endl;  
 std::cout << ">>>>> Input::inputXSection             " << inputXSection  << std::endl;  
 std::cout << ">>>>> Input::histoNameEvents      " << histoNameEvents  << std::endl;  
 
 // Open ntples
 TFile File(inputFile.c_str()) ; 
 TH1F* histoEvents = (TH1F*) File.Get(TString(histoNameEvents.c_str()));
 
 
 ///----------------------
 ///---- Preselection ----
 
 ///~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ///==== only retrocompatibility ====
 
 ///=================================
 
 double lepton_efficiency = 1;
 double jet_efficiency = 1;
 double eff_Channel_Filter = 1;
 double preselection_efficiency = 1.;

 ///~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ///~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ///~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 ///-------------------
 ///---- selection ----
 std::string outFileName    = gConfigParser -> readStringOption("Output::outFileName");
 std::cout << ">>>>> Output::outFileName  " << outFileName  << std::endl;  
 
 int nStep = 10; ///==== number of steps in the analysis
 int numEntriesBefore;
 
 // define variable container
 Variables vars;
 InitializeTree(vars, outFileName);
 InitializeTreeTrigger(vars, HLTVector, reader);
 
 vars.XSection = inputXSection;
 vars.dataFlag = dataFlag;  ///~~~~ 0 = MC       1 = DATA
 
 if (entryMAX == -1) entryMAX = reader.GetEntries();
 else if (reader.GetEntries() < entryMAX) entryMAX = reader.GetEntries();
 numEntriesBefore = entryMAX - entryMIN;
 
 if (histoEvents) preselection_efficiency = numEntriesBefore / (1. * histoEvents->GetBinContent(1));
 else preselection_efficiency = 1;
 
 vars.numEntriesBefore = numEntriesBefore;
 vars.preselection_efficiency = preselection_efficiency;
 
 FillEfficiencyTree(vars);
 
 
 ///*************************************
 ///**** definition of electron ID ****
 ///**** https://twiki.cern.ch/twiki/bin/viewauth/CMS/SimpleCutBasedEleID
 ///**** https://twiki.cern.ch/twiki/bin/viewauth/CMS/SimpleCutBasedEleID2011
 
 
 std::vector<double> BarrelSelections;
 std::vector<double> EndcapSelections;
 
 
 
 double eleCombinedIsoBarrel      = gConfigParser -> readDoubleOption("Selection::eleCombinedIsoBarrel");
 double elesigmaIetaIetaBarrel    = gConfigParser -> readDoubleOption("Selection::elesigmaIetaIetaBarrel");
 double eledPhiBarrel             = gConfigParser -> readDoubleOption("Selection::eledPhiBarrel");
 double eledEtaBarrel             = gConfigParser -> readDoubleOption("Selection::eledEtaBarrel");
 
 double eleCombinedIsoEndcap    = gConfigParser -> readDoubleOption("Selection::eleCombinedIsoEndcap");
 double elesigmaIetaIetaEndcap  = gConfigParser -> readDoubleOption("Selection::elesigmaIetaIetaEndcap");
 double eledPhiEndcap           = gConfigParser -> readDoubleOption("Selection::eledPhiEndcap");
 double eledEtaEndcap           = gConfigParser -> readDoubleOption("Selection::eledEtaEndcap");
 
 double elemishits    = gConfigParser -> readDoubleOption("Selection::elemishits");
 double eledist       = gConfigParser -> readDoubleOption("Selection::eledist");
 double eledcot       = gConfigParser -> readDoubleOption("Selection::eledcot");
 
 double eledzPV     = gConfigParser -> readDoubleOption("Selection::eledzPV");
 double eledxyPV    = gConfigParser -> readDoubleOption("Selection::eledxyPV");
 
 
 BarrelSelections.push_back(eleCombinedIsoBarrel);
 BarrelSelections.push_back(elesigmaIetaIetaBarrel);
 BarrelSelections.push_back(eledPhiBarrel);
 BarrelSelections.push_back(eledEtaBarrel);
 BarrelSelections.push_back(elemishits);
 BarrelSelections.push_back(eledist);
 BarrelSelections.push_back(eledcot);
 BarrelSelections.push_back(eledzPV);
 BarrelSelections.push_back(eledxyPV);
 
 EndcapSelections.push_back(eleCombinedIsoEndcap);
 EndcapSelections.push_back(elesigmaIetaIetaEndcap);
 EndcapSelections.push_back(eledPhiEndcap);
 EndcapSelections.push_back(eledEtaEndcap);
 EndcapSelections.push_back(elemishits);
 EndcapSelections.push_back(eledist);
 EndcapSelections.push_back(eledcot);
 EndcapSelections.push_back(eledzPV);
 EndcapSelections.push_back(eledxyPV);
 
 
 ///**** https://twiki.cern.ch/twiki/bin/viewauth/CMS/SimpleCutBasedEleID   --> 2010 Data
 ///**** 95% ****
 
  /*
   BarrelSelections.push_back(0.15); ///==== iso Tk
   BarrelSelections.push_back(2.00); ///==== iso em
   BarrelSelections.push_back(0.12); ///==== iso had
   BarrelSelections.push_back(0.15); ///==== iso combined
   BarrelSelections.push_back(0.015); ///==== hOe
   BarrelSelections.push_back(0.01); ///==== sigmaIetaIeta
   BarrelSelections.push_back(0.8); ///==== dPhi
   BarrelSelections.push_back(0.007); ///==== dEta
   
   EndCapSelections.push_back(0.08); ///==== iso Tk
   EndCapSelections.push_back(0.06); ///==== iso em
   EndCapSelections.push_back(0.05); ///==== iso had
   EndCapSelections.push_back(0.10); ///==== iso combined
   EndCapSelections.push_back(0.07); ///==== hOe
   EndCapSelections.push_back(0.03); ///==== sigmaIetaIeta
   EndCapSelections.push_back(0.7); ///==== dPhi
   EndCapSelections.push_back(0.01); ///==== dEta
   */
  
 
    ///**** 90% ****
   /*
   BarrelSelections.push_back(0.12); ///==== iso Tk
   BarrelSelections.push_back(0.09); ///==== iso em
   BarrelSelections.push_back(0.10); ///==== iso had
   BarrelSelections.push_back(0.10); ///==== iso combined
   BarrelSelections.push_back(0.12); ///==== hOe
   BarrelSelections.push_back(0.01); ///==== sigmaIetaIeta
   BarrelSelections.push_back(0.8); ///==== dPhi
   BarrelSelections.push_back(0.007); ///==== dEta
    
   EndCapSelections.push_back(0.05); ///==== iso Tk
   EndCapSelections.push_back(0.06); ///==== iso em
   EndCapSelections.push_back(0.03); ///==== iso had
   EndCapSelections.push_back(0.07); ///==== iso combined
   EndCapSelections.push_back(0.05); ///==== hOe
   EndCapSelections.push_back(0.03); ///==== sigmaIetaIeta
   EndCapSelections.push_back(0.7); ///==== dPhi
   EndCapSelections.push_back(0.007); ///==== dEta
  */
   
    ///**** 80% ****
    /*
   BarrelSelections.push_back(0.09); ///==== iso Tk
   BarrelSelections.push_back(0.07); ///==== iso em
   BarrelSelections.push_back(0.10); ///==== iso had
   BarrelSelections.push_back(0.07); ///==== iso combined
   BarrelSelections.push_back(0.040); ///==== hOe
   BarrelSelections.push_back(0.01); ///==== sigmaIetaIeta
   BarrelSelections.push_back(0.06); ///==== dPhi
   BarrelSelections.push_back(0.004); ///==== dEta
    
   EndCapSelections.push_back(0.04); ///==== iso Tk
   EndCapSelections.push_back(0.05); ///==== iso em
   EndCapSelections.push_back(0.025); ///==== iso had
   EndCapSelections.push_back(0.06); ///==== iso combined
   EndCapSelections.push_back(0.025); ///==== hOe
   EndCapSelections.push_back(0.03); ///==== sigmaIetaIeta
   EndCapSelections.push_back(0.03); ///==== dPhi
   EndCapSelections.push_back(0.007); ///==== dEta
 */
  
  
  ///**** 70% ****
  /*
  BarrelSelections.push_back(0.05); ///==== iso Tk
  BarrelSelections.push_back(0.06); ///==== iso em
  BarrelSelections.push_back(0.03); ///==== iso had
  BarrelSelections.push_back(0.04); ///==== iso combined
  BarrelSelections.push_back(0.025); ///==== hOe
  BarrelSelections.push_back(0.01); ///==== sigmaIetaIeta
  BarrelSelections.push_back(0.004); ///==== dPhi
  BarrelSelections.push_back(0.004); ///==== dEta
  
  EndCapSelections.push_back(0.025); ///==== iso Tk
  EndCapSelections.push_back(0.025); ///==== iso em
  EndCapSelections.push_back(0.02); ///==== iso had
  EndCapSelections.push_back(0.03); ///==== iso combined
  EndCapSelections.push_back(0.025); ///==== hOe
  EndCapSelections.push_back(0.03); ///==== sigmaIetaIeta
  EndCapSelections.push_back(0.02); ///==== dPhi
  EndCapSelections.push_back(0.005); ///==== dEta
  */
  
  
  
  ///**** https://twiki.cern.ch/twiki/bin/viewauth/CMS/SimpleCutBasedEleID2011   --> 2011 Data
  
  ///**** 95% ****
  /*
  BarrelSelections.push_back(10000.); ///==== iso Tk
  BarrelSelections.push_back(10000.); ///==== iso em
  BarrelSelections.push_back(10000.); ///==== iso had
  BarrelSelections.push_back(0.150); ///==== iso combined
  BarrelSelections.push_back(10000.); ///==== hOe
  BarrelSelections.push_back(0.012); ///==== sigmaIetaIeta
  BarrelSelections.push_back(0.800); ///==== dPhi
  BarrelSelections.push_back(0.007); ///==== dEta
  
  EndCapSelections.push_back(10000.); ///==== iso Tk
  EndCapSelections.push_back(10000.); ///==== iso em
  EndCapSelections.push_back(10000.); ///==== iso had
  EndCapSelections.push_back(0.100); ///==== iso combined
  EndCapSelections.push_back(10000.); ///==== hOe
  EndCapSelections.push_back(0.031); ///==== sigmaIetaIeta
  EndCapSelections.push_back(0.7); ///==== dPhi
  EndCapSelections.push_back(0.011); ///==== dEta
  */
  
  ///**** 90% ****
  /* 
   BarrelSelections.push_back(10000.); ///==== iso Tk
   BarrelSelections.push_back(10000.); ///==== iso em
   BarrelSelections.push_back(10000.); ///==== iso had
   BarrelSelections.push_back(0.085); ///==== iso combined
   BarrelSelections.push_back(10000.); ///==== hOe
   BarrelSelections.push_back(0.01); ///==== sigmaIetaIeta
   BarrelSelections.push_back(0.071); ///==== dPhi
   BarrelSelections.push_back(0.007); ///==== dEta
    
   EndCapSelections.push_back(10000.); ///==== iso Tk
   EndCapSelections.push_back(10000.); ///==== iso em
   EndCapSelections.push_back(10000.); ///==== iso had
   EndCapSelections.push_back(0.051); ///==== iso combined
   EndCapSelections.push_back(10000.); ///==== hOe
   EndCapSelections.push_back(0.031); ///==== sigmaIetaIeta
   EndCapSelections.push_back(0.047); ///==== dPhi
   EndCapSelections.push_back(0.011); ///==== dEta
   */

  ///**** 85% ****
   /*
   BarrelSelections.push_back(10000.); ///==== iso Tk
   BarrelSelections.push_back(10000.); ///==== iso em
   BarrelSelections.push_back(10000.); ///==== iso had
   BarrelSelections.push_back(0.053); ///==== iso combined
   BarrelSelections.push_back(10000.); ///==== hOe
   BarrelSelections.push_back(0.01); ///==== sigmaIetaIeta
   BarrelSelections.push_back(0.039); ///==== dPhi
   BarrelSelections.push_back(0.005); ///==== dEta
   
   EndCapSelections.push_back(10000.); ///==== iso Tk
   EndCapSelections.push_back(10000.); ///==== iso em
   EndCapSelections.push_back(10000.); ///==== iso had
   EndCapSelections.push_back(0.042); ///==== iso combined
   EndCapSelections.push_back(10000.); ///==== hOe
   EndCapSelections.push_back(0.031); ///==== sigmaIetaIeta
   EndCapSelections.push_back(0.028); ///==== dPhi
   EndCapSelections.push_back(0.007); ///==== dEta
   */


 ///**** 80% ****
   /*
   BarrelSelections.push_back(10000.); ///==== iso Tk
   BarrelSelections.push_back(10000.); ///==== iso em
   BarrelSelections.push_back(10000.); ///==== iso had
   BarrelSelections.push_back(0.040); ///==== iso combined
   BarrelSelections.push_back(10000.); ///==== hOe
   BarrelSelections.push_back(0.01); ///==== sigmaIetaIeta
   BarrelSelections.push_back(0.027); ///==== dPhi
   BarrelSelections.push_back(0.005); ///==== dEta
   
   EndCapSelections.push_back(10000.); ///==== iso Tk
   EndCapSelections.push_back(10000.); ///==== iso em
   EndCapSelections.push_back(10000.); ///==== iso had
   EndCapSelections.push_back(0.033); ///==== iso combined
   EndCapSelections.push_back(10000.); ///==== hOe
   EndCapSelections.push_back(0.031); ///==== sigmaIetaIeta
   EndCapSelections.push_back(0.021); ///==== dPhi
   EndCapSelections.push_back(0.006); ///==== dEta
   */
   
  ///***********************************
  ///**** definition of muon ID ****
  std::vector<double> Selections;
  
  double muCombinedIso   = gConfigParser -> readDoubleOption("Selection::muCombinedIso");
  double muChi2Ndof      = gConfigParser -> readDoubleOption("Selection::muChi2Ndof");
  
  
  double muValidTrackerHits = gConfigParser -> readDoubleOption("Selection::muValidTrackerHits");
  double muValidMuonHits    = gConfigParser -> readDoubleOption("Selection::muValidMuonHits");
  
  double mutracker    = gConfigParser -> readDoubleOption("Selection::mutracker");
  double mustandalone = gConfigParser -> readDoubleOption("Selection::mustandalone");
  double muglobal     = gConfigParser -> readDoubleOption("Selection::muglobal");
  
  double mudzPV     = gConfigParser -> readDoubleOption("Selection::mudzPV");
  double mudxyPV    = gConfigParser -> readDoubleOption("Selection::mudxyPV");
  
  
  Selections.push_back(muCombinedIso);
  Selections.push_back(muChi2Ndof);
  Selections.push_back(muValidTrackerHits);
  Selections.push_back(muValidMuonHits);
  Selections.push_back(mutracker);
  Selections.push_back(mustandalone);
  Selections.push_back(muglobal);
  Selections.push_back(mudzPV);
  Selections.push_back(mudxyPV);
  
    
/*  
  Selections.push_back(0.15); ///==== iso Combined
  Selections.push_back(10); ///==== Chi2/ndof
  Selections.push_back(10); ///==== n ValidTrackerHits
  Selections.push_back(0); ///==== n ValidMuonHits
  Selections.push_back(1); ///==== tracker
  Selections.push_back(1); ///==== standalone
  Selections.push_back(1); ///==== global
  //Selections.push_back(1); ///==== goodMuon
  */
  
  
  double start, end;
  std::cout << ">>>>> analysis::entryMIN " << entryMIN << " ==> entryMAX " << entryMAX << ":" << reader.GetEntries() << std::endl;   
  
  int step = 0;
  start = clock();
  for(int iEvent = entryMIN ; iEvent < entryMAX ; ++iEvent) {
   reader.GetEntry(iEvent);
   if((iEvent%entryMOD) == 0) std::cout << ">>>>> analysis::GetEntry " << iEvent << " : " << entryMAX - entryMIN << std::endl;   
   
  ///==== define variables ==== 
  std::vector<ROOT::Math::XYZTVector>* jets = reader.Get4V("jets");
//   std::vector<ROOT::Math::XYZTVector>* muons = reader.Get4V("muons");
//   std::vector<ROOT::Math::XYZTVector>* electrons = reader.Get4V("electrons");
    
  ///*********************************************************************************************
  ///*********************************************************************************************
  
  ///=============================
  ///==== fill MC information ====
  SetMCVariables(vars, reader);
  
  ///=============================
  ///==== fill Primary Vertex ====
  SetPVVariables(vars, reader);
  
  ///================================
  ///==== fill Event information ====
  SetEventVariables(vars, reader);
  
  ///***************************************************
  ///**** STEP -1 - Check no copies in DATA ****
  ///***************************************************
  if (debug) std::cout << " STEP -1 " << std::endl;
  
  if( dataFlag == 1 )
  {
   std::pair<int,int> eventLSandID(reader.GetInt("lumiId")->at(0), reader.GetInt("eventId")->at(0));
   std::pair<int,std::pair<int,int> > eventRUNandLSandID(reader.GetInt("runId")->at(0), eventLSandID);
   
   if( eventsMap[eventRUNandLSandID] == 1 ) continue;
   else eventsMap[eventRUNandLSandID] = 1;
  }

  ///*************************************************
  ///**** Check comparison with JSON file ***
  ///*************************************************


  if( dataFlag == 1 )
    {
      int runId  = reader.GetInt("runId")->at(0);
      int lumiId = reader.GetInt("lumiId")->at(0);
      if(AcceptEventByRunAndLumiSection(runId, lumiId, jsonMap) == false) continue;      
    }


  
  ///****************************
  ///**** STEP 0 - Ntuplizer ****
  ///************* no additional selections applied 

  step = 0;  
  if (step > nStepToDo) {
   FillTree(vars);
   continue;
  }
  if (debug) std::cout << ">>> STEP 0 <<<" << std::endl;
   
   ///*********************************************
  ///**** STEP 1 - Jet cleaning + min pT ****
  ///************* it's performed another time here to make sure that the cleaning worked well
  ///************* Jet - electrons (pT > 5)
  ///************* Jet - muons     (pT > 5)
  ///************ In addition only jets with pT > 15 are considered from now on!
  ///************ No selections are applied here
   
  step = 1;
  if (step > nStepToDo) {
//    FillTree(vars);
   continue;
  }  
  if (debug) std::cout << ">>> STEP 1 <<<" << std::endl;
  
  std::vector<ROOT::Math::XYZTVector> leptons_jetCleaning;   
  // build the collection of electros for jet cleaning
  
  ///==== CLEANING WITH ELECTRONS ====
  for(unsigned int iEle = 0; iEle < (reader.Get4V("electrons")->size()); ++iEle)
  {
   if( reader.Get4V("electrons")->at(iEle).pt() < 5. ) continue;
//    bool flag =  IsEleIsolatedID_VBF(reader,BarrelSelections,EndcapSelections,iEle);
   bool flag =  IsEleIsolatedIDPUCorrected_VBF(reader,BarrelSelections,EndcapSelections,iEle);
   
   if (!flag) continue;
   
   leptons_jetCleaning.push_back( reader.Get4V("electrons")->at(iEle) );
  }
  
  ///==== CLEANING WITH MUONS ====
  for (int iMu = 0; iMu < reader.Get4V("muons")->size(); iMu++){    
   if (reader.Get4V("muons")->at(iMu).pt() < 5.0) continue;
   if (fabs(reader.Get4V("muons")->at(iMu).Eta()) > 2.5) continue;
//    bool flag =  IsMuIsolatedID_VBF(reader,Selections,iMu);
   bool flag =  IsMuIsolatedIDPUCorrected_VBF(reader,Selections,iMu);
   
   if (!flag) continue;

   leptons_jetCleaning.push_back( reader.Get4V("muons")->at(iMu) );
  }
  
  
  ///==== now clean jet collection ====
  
  int nJets = reader.Get4V("jets")->size();
  std::vector<int> whitelistJet; ///~~~~ all jets, 0 if rejected, 1 if accepted
  std::vector<int> blacklistJet; ///~~~~ list of numbers of jets that are "rejected"
  std::vector<int> blacklistJet_forCJV;
  std::vector<int> blacklistJet_forBtag;
  for (int iJet = 0; iJet < nJets; iJet++){
   bool skipJet = false;
   if (reader.Get4V("jets")->at(iJet).Et() < 15.0) skipJet = true;
   for(unsigned int iLep = 0; iLep < leptons_jetCleaning.size(); ++iLep) {
    ROOT::Math::XYZTVector lep = leptons_jetCleaning.at(iLep);
    if (ROOT::Math::VectorUtil::DeltaR(reader.Get4V("jets")->at(iJet),lep) < 0.3 ) skipJet = true;
   }
   if (skipJet) {
    whitelistJet.push_back(0); ///---- reject
    blacklistJet.push_back(iJet); ///---- reject ///== black list is in a different format
    blacklistJet_forCJV.push_back(iJet); ///---- reject ///== black list is in a different format
    blacklistJet_forBtag.push_back(iJet); ///---- reject ///== black list is in a different format
   }
   else {
    whitelistJet.push_back(1); ///---- select
   }
  }
     
   ///**************************************
   ///**** STEP 2 - Super-Preselections ****
   ///************* tighter preselections to start the analysis from the same point
   ///==== construct considered objets
   ///    Objects considered and selections
   
   ///   Muon
   ///   Pt>10GeV, eta<2.5
   ///   MuonId & Iso
   ///
   ///   Electron
   ///   Pt>10GeV & |eta|<2.5
   ///   eleId & Iso
   ///
   ///    At least two leptons 
   
   ///   Jet
   ///   Antikt5, L2L3 correction jets
   ///   At least two calo jets or two pf jets with pt>15 GeV
   
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  
  step = 2;
  if (step > nStepToDo) {
//    FillTree(vars);
   continue;
  }  
  if (debug) std::cout << ">>> STEP 2 <<<" << std::endl;
  
   ///   Electron
   ///   Pt>10GeV & |eta|<2.5
   ///   IsoTr / pTele <0.5
  ///   eleId & Iso
  std::vector<int> whitelistEle;
  std::vector<int> blacklistEle;
  int nEles = reader.Get4V("electrons")->size();
  for (int iEle = 0; iEle < nEles; iEle++){    
   bool skipEle = false;
   if (reader.Get4V("electrons")->at(iEle).pt() < 10.0) skipEle = true;
   if (fabs(reader.Get4V("electrons")->at(iEle).Eta()) > 2.5) skipEle = true;
//    bool flag =  IsEleIsolatedID_VBF(reader,BarrelSelections,EndcapSelections,iEle);
   bool flag =  IsEleIsolatedIDPUCorrected_VBF(reader,BarrelSelections,EndcapSelections,iEle);
   if (!flag) skipEle = true;
   
   if (skipEle) {
    whitelistEle.push_back(0); ///---- reject
    blacklistEle.push_back(iEle); ///---- reject ///== black list is in a different format
   }
   else {
    whitelistEle.push_back(1); ///---- select
   }
  }
       
   ///   Muon
   ///   Pt>10GeV, eta<2.5
   ///   MuonId & Iso
   std::vector<int> whitelistMu;
   std::vector<int> blacklistMu;
   int nMus = reader.Get4V("muons")->size();
   for (int iMu = 0; iMu < nMus; iMu++){    
    bool skipMu = false;
    if (reader.Get4V("muons")->at(iMu).pt() < 10.0) skipMu = true;
    if (fabs(reader.Get4V("muons")->at(iMu).Eta()) > 2.5) skipMu = true;    
//     bool flag =  IsMuIsolatedID_VBF(reader,Selections,iMu);
    bool flag =  IsMuIsolatedIDPUCorrected_VBF(reader,Selections,iMu);
    
    if (!flag) skipMu = true;

    if (skipMu) {
     whitelistMu.push_back(0); ///---- reject
     blacklistMu.push_back(iMu); ///---- reject ///== black list is in a different format
    }
    else {
     whitelistMu.push_back(1); ///---- select
    }
   }
      
   ///   At least 2 leptons
   
   int numMus_Accepted = GetNumList(whitelistMu);
   int numEles_Accepted = GetNumList(whitelistEle);
   
   int numLeptons_Accepted = numMus_Accepted + numEles_Accepted;
   if (numLeptons_Accepted < 2) continue;
   
   ///   Jet
   ///   At least two calo jets or two pf jets with pt>20 GeV
   
   int numJets_Accepted = GetNumList(whitelistJet);
   if (numJets_Accepted < 2) continue; ///==== at least 2 jets "isolated"
   
  ///*************************
  ///**** STEP 3 - Jet ID ****
  ///************* Identification of two tag jets

  step = 3;
  if (step > nStepToDo) {
//    FillTree(vars);
   continue;
  }  
  if (debug) std::cout << ">>> STEP 3 <<<" << std::endl;
  
  
  std::vector<int> itSelJet;
  double maxPt_jets_selected = SelectJets(itSelJet,*jets,"maxSumPt",-1.,&blacklistJet);
  
  int q1 = itSelJet.at(0);
  int q2 = itSelJet.at(1);
  ///---- check Pt order ----
  if (jets->at(q1).Pt() < jets->at(q2).Pt()) {
   int tempq = q1;
   q1 = q2;
   q2 = tempq;
  }

if (debug) std::cerr << " q1 = " << q1 << " : q2 = " << q2 << std::endl;


  ///---- update white/black list jets ----
  for (int iJet = 0; iJet < nJets; iJet++){
   if (q1 == iJet || q2 == iJet) {
    whitelistJet.at(iJet) = 1;
    blacklistJet.push_back(iJet); ///===>  blacklistJet used for CJV => no 2 tag jets to be considered!
    blacklistJet_forCJV.push_back(iJet); ///===>  blacklistJet used for CJV => no 2 tag jets to be considered!
   }
   else {
    whitelistJet.at(iJet) = 0;
   }
  }

 SetQJetVariables(vars, reader, q1, q2, blacklistJet_forCJV, blacklistJet_forBtag, blacklistJet_forBtag);

  ///********************************
  ///**** STEP 4 - Lepton ID ****
  ///************* Identification of the two leptons
  step = 4;
  if (step > nStepToDo) {
   FillTree(vars);
   continue;
  }  
  if (debug) std::cout << ">>> STEP 4 <<<" << std::endl;
  

  std::vector<ROOT::Math::XYZTVector> leptons;
  std::vector<int> leptonFlavours;    
  std::vector<int> leptonILep;    
  
  for(unsigned int iEle = 0; iEle < nEles; iEle++){
   if (whitelistEle.at(iEle) == 1){
    leptons.push_back( reader.Get4V("electrons")->at(iEle) );  
    leptonFlavours.push_back(11);
    leptonILep.push_back(iEle);
   }
  }
  
  for(unsigned int iMu = 0; iMu < nMus; iMu++){
   if (whitelistMu.at(iMu) == 1){
    leptons.push_back( reader.Get4V("muons")->at(iMu) );      
    leptonFlavours.push_back(13);
    leptonILep.push_back(iMu);
   }
  }
  
  std::vector<int> itSelLep;
  double maxPt_lept_selected = SelectJets(itSelLep,leptons,"maxSumPt",-1.,0);
  
  int l1 = itSelLep.at(0);
  int l2 = itSelLep.at(1);
  ///---- check Pt order ----
  if (leptons.at(l1).Pt() < leptons.at(l2).Pt()) {
   int templ = l1;
   l1 = l2;
   l2 = templ;
  }
  
  if (debug) std::cerr << " l1 = " << l1 << " : l2 = " << l2 << std::endl;
  
  SetLeptonsVariables(vars, reader, leptonILep.at(l1), leptonILep.at(l2),leptonFlavours.at(l1), leptonFlavours.at(l2));
  
  if (debug) std::cerr << ">> Lepton variables set" << std::endl;
  
  
  SetMetVariables(vars, reader, "PFMet", leptonILep.at(l1), leptonILep.at(l2),leptonFlavours.at(l1), leptonFlavours.at(l2));
  if (debug) std::cerr << ">> MET variables set" << std::endl;
   
   
  //---- lepton veto
  std::vector<int> blacklistLepton;
  blacklistLepton.push_back(l1);
  blacklistLepton.push_back(l2);
  
  vars.Nleptons_pT5  = getNumberPTThreshold(leptons,  5, &blacklistLepton);
  vars.Nleptons_pT10 = getNumberPTThreshold(leptons, 10, &blacklistLepton);
  vars.Nleptons_pT15 = getNumberPTThreshold(leptons, 15, &blacklistLepton);
  vars.Nleptons_pT20 = getNumberPTThreshold(leptons, 20, &blacklistLepton);
  vars.Nleptons_pT25 = getNumberPTThreshold(leptons, 25, &blacklistLepton);
  vars.Nleptons_pT30 = getNumberPTThreshold(leptons, 30, &blacklistLepton);

  if (debug) std::cerr << ">> Lepton multiplicity set" << std::endl;
  
  
  ///*********************************
  ///**** STEP 5 - Jet Selections ****
  ///************* Loose selections of tag jets
  step = 5;
  if (step > nStepToDo) {
   FillTree(vars);
   continue;
  }  
  if (debug) std::cout << ">>> STEP 5 <<<" << std::endl;
  
  ///----  hardcoded fixed preselections ---- VBF (begin) ----
  if (vars.q1_pT < 20.) continue;
  if (vars.q2_pT < 15.) continue;
  if (vars.M_qq <   0.) continue;
  if (vars.DEta_qq < 0.) continue;
  ///----  hardcoded fixed preselections ---- VBF (end) ----

  ///==== save trigger variables ====
  SetTriggerVariables(vars, reader);
  
  ///************************************
  ///**** STEP 6 - Final Production *****
  ///************************************
  ///**** No more selections applied ****

  step = 6;
  if (step > nStepToDo) {
   FillTree(vars);
   continue;
  }  
  if (debug) std::cout << ">>> STEP 6 <<<" << std::endl;

  ///==== if not already filled ... ====
  FillTree(vars);  
  ///=================================================
  
 }
 end = clock();
 std::cout <<"Time = " <<  ((double) (end - start)) << " (a.u.)" << std::endl;  
 
 SaveTree(vars);
 
 std::cerr << " === end === " << std::endl;
}