Ejemplo n.º 1
0
void baseClass::readInputList()
{

  TChain *chain = new TChain(treeName_->c_str());
  char pName[500];
  skimWasMade_ = true;
  NBeforeSkim_ = 0;
  int NBeforeSkim;

  std::cout << "baseClass::readinputList(): inputList_ =  "<< *inputList_ << std::endl;

  ifstream is(inputList_->c_str());
  if(is.good())
    {
      cout << "baseClass::readInputList: Reading list: " << *inputList_ << " ......." << endl;
      while( is.getline(pName, 500, '\n') )
        {
          if (pName[0] == '#') continue;
          STDOUT("Adding file: " << pName);
          chain->Add(pName);
	  NBeforeSkim = getGlobalInfoNstart(pName);
	  NBeforeSkim_ = NBeforeSkim_ + NBeforeSkim;
	  STDOUT("Initial number of events: NBeforeSkim, NBeforeSkim_ = "<<NBeforeSkim<<", "<<NBeforeSkim_);
        }
      tree_ = chain;
      cout << "baseClass::readInputList: Finished reading list: " << *inputList_ << endl;
    }
  else
    {
      cout << "baseClass::readInputList: ERROR opening inputList:" << *inputList_ << endl;
      exit (1);
    }
  is.close();

}
Ejemplo n.º 2
0
bool baseClass::passedAllPreviousCuts(const string& s)
{
  //STDOUT("Examining variableName = "<<s);

  map<string, cut>::iterator cc = cutName_cut_.find(s);
  if( cc == cutName_cut_.end() ) 
    {  
      STDOUT("ERROR: did not find variableName = "<<s<<" in cutName_cut_. Returning false.");
      return false;
    }

  for (vector<string>::iterator it = orderedCutNames_.begin(); 
       it != orderedCutNames_.end(); it++) 
    {
      cut * c = & (cutName_cut_.find(*it)->second);
      if( c->variableName == s ) 
	{
	  return true;
	}
      else
	{
	  if( ! (c->filled && c->passed) ) return false;
	}
    }
  STDOUT("ERROR. It should never pass from here.");
}
Ejemplo n.º 3
0
int Mmi::Choose()
{
   const char TAB[]        = "   ";

   char BUF[1024] = {0x00,};

   GetInput("Choose", BUF, sizeof(BUF));

   int len = strlen(BUF);
   if (0 == len) {
      return 0;
   }

   for (int idx = 0; idx < len; ++idx) {
      if (!isdigit(BUF[idx] & 0xFF)) {
         STDOUT(" ");
         STDOUT(RED(TAB << "Invalid Input : " << BUF));
         STDOUT(" ");
         return 0;
      }
   }

   int value = atoi(BUF);

   return ((0 == value) ? -1 : value);
}
Ejemplo n.º 4
0
double baseClass::getPreCutValue4(const string& s)
{
  double ret;
  map<string, preCut>::iterator cc = preCutName_cut_.find(s);
  if( cc == preCutName_cut_.end() ) 
    {
      STDOUT("ERROR: did not find variableName = "<<s<<" in preCutName_cut_. Returning");
    }
  preCut * c = & (cc->second);
  if(c->value4 == -9999999) STDOUT("ERROR: value4 of preliminary cut "<<s<<" was not provided.");
  return (c->value4);
}
Ejemplo n.º 5
0
baseClass::~baseClass()
{
  std::cout << "baseClass::~baseClass(): begin " << std::endl;
  if( !writeCutHistos() )
    {
      STDOUT("ERROR: writeCutHistos did not complete successfully.");
    }
  output_root_->Close();
  if( !writeCutEfficFile() )
    {
      STDOUT("ERROR: writeStatFile did not complete successfully.");
    }
  std::cout << "baseClass::~baseClass(): end " << std::endl;
}
Ejemplo n.º 6
0
int baseClass::getGlobalInfoNstart(char * pName)
{
  int NBeforeSkim = 0;
  TFile f(pName);
  //f.cd();
  TTree * tree2;
  string s;
  s = *treeName_ + "_globalInfo";
  tree2 = (TTree*)gDirectory->Get(s.c_str());
  if( !tree2 ) 
    {
      STDOUT("GlobalInfo tree named "<<s<<"not found. Will assume skim was not made for ALL files.");
      skimWasMade_ = false;
      return NBeforeSkim;
    }
  TBranch * b_Nstart;
  tree2->SetMakeClass(1);
  tree2->SetBranchAddress("Nstart", &NBeforeSkim, &b_Nstart);
  Long64_t l = 0;
  tree2->LoadTree(l);
  tree2->GetEntry(l);   
  //STDOUT(pName<<"  "<< NBeforeSkim) ;
  //	  f.Close();

  return NBeforeSkim;
}
Ejemplo n.º 7
0
AFFEND

AFFDEF(__arc_disp_write)
{
  AARG(arg, disp);
  AOARG(outport, visithash);
  typefn_t *tfn;
  AFBEGIN;
  if (!BOUND_P(AV(outport)))
    STDOUT(outport);
  if (NIL_P(AV(arg)))
    WV(arg, ARC_BUILTIN(c, S_NIL));
  if (AV(arg) == CTRUE)
    WV(arg, ARC_BUILTIN(c, S_T));
  tfn = __arc_typefn(c, AV(arg));
  if (tfn == NULL || tfn->pprint == NULL) {
    static const char *utype = "#<unknown-type %d %p>";
    char *strrep;
    int len;
    value vstr;

    len = snprintf(NULL, 0, utype, TYPE(AV(arg)), (void *)AV(arg));
    strrep = alloca(sizeof(char)*(len+1));
    snprintf(strrep, len+1, utype, TYPE(AV(arg)), (void *)AV(arg));
    vstr = arc_mkstringc(c, strrep);

    AFTCALL(arc_mkaff(c, arc_disp, CNIL), vstr, AV(outport));
    ARETURN(CNIL);
  }
  AFTCALL(arc_mkaff(c, tfn->pprint, CNIL), AV(arg), AV(disp), AV(outport),
	  AV(visithash));
  AFEND;
}
Ejemplo n.º 8
0
AFFEND

AFFDEF(arc_writeb)
{
  AARG(byte);
  AOARG(fd);
  AFBEGIN;

  if (arc_thr_argc(c, thr) == 0) {
    arc_err_cstrfmt(c, "writeb: too few arguments");
    return(CNIL);
  }

  if (!BOUND_P(AV(fd)))
    STDOUT(fd);

  IOW_TYPECHECK(AV(fd));
  CHECK_CLOSED(AV(fd));
  AFCALL(VINDEX(IO(AV(fd))->io_ops, IO_wready), AV(fd));
  if (AFCRV == CNIL) {
    arc_err_cstrfmt(c, "port is not ready for writing");
    ARETURN(CNIL);
  }
  AFTCALL(VINDEX(IO(AV(fd))->io_ops, IO_putb), AV(fd), AV(byte));
  AFEND;
}
Ejemplo n.º 9
0
bool baseClass::passedAllOtherSameAndLowerLevelCuts(const string& s)
{
  //STDOUT("Examining variableName = "<<s);
  bool ret = true;
  int cutLevel;
  map<string, cut>::iterator cc = cutName_cut_.find(s);
  if( cc == cutName_cut_.end() ) 
    {  
      STDOUT("ERROR: did not find variableName = "<<s<<" in cutName_cut_. Returning false.");
      return false;
    }
  else
    {
      cutLevel = cc->second.level_int; 
    }

  for (map<string, cut>::iterator cc = cutName_cut_.begin(); cc != cutName_cut_.end(); cc++) 
    {
      cut * c = & (cc->second);
      if( c->level_int > cutLevel || c->variableName == s ) 
	{
	  continue;
	}
      else 
	{
	  if( ! (c->filled && c->passed) ) return false;
	}
    }
  return ret;
}
Ejemplo n.º 10
0
int main( int argc, char *argv[] )
{
  setvbuf(stdout, NULL, _IONBF, 0);
  HelixClient* myClient = new HelixClient();
  STDOUT("%s", argv[1]);
  myClient->create_player("myPlayer", true);

  //myClient->open_url("myPlayer", argv[1]);
  myClient->open_url("myPlayer", "rage.mp3");
  
  bool done = true; 
  myClient->begin("myPlayer");
  while (done != myClient->is_done("myPlayer")) {
     //Do Nothing for now
    MSG msg;

    GetMessage(&msg, NULL, 0, 0);
    DispatchMessage(&msg);
  }

  delete myClient;
  myClient = 0;
  
  return 0;
}
Ejemplo n.º 11
0
AFFEND

AFFDEF(arc_stdout)
{
  AVAR(fd);
  AFBEGIN;
  STDOUT(fd);
  ARETURN(AV(fd));
  AFEND;
}
Ejemplo n.º 12
0
double baseClass::getHistoMax(const string& s)
{
  map<string, cut>::iterator cc = cutName_cut_.find(s);
  if( cc == cutName_cut_.end() )
    {
      STDOUT("ERROR: did not find variableName = "<<s<<" in cutName_cut_. Returning false.");
    }
  cut * c = & (cutName_cut_.find(s)->second);
  return (c->histoMax);
}
Ejemplo n.º 13
0
const TH1F& baseClass::getHisto_allOthrSmAndLwrLvlCuts(const string& s)
{
  map<string, cut>::iterator cc = cutName_cut_.find(s);
  if( cc == cutName_cut_.end() )
    {
      STDOUT("ERROR: did not find variableName = "<<s<<" in cutName_cut_. Returning false.");
    }

  cut * c = & (cutName_cut_.find(s)->second);
  return (c->histo3);
}
Ejemplo n.º 14
0
double baseClass::getCutMaxValue2(const string& s)
{
  double ret;
  map<string, cut>::iterator cc = cutName_cut_.find(s);
  if( cc == cutName_cut_.end() ) 
    {
      STDOUT("ERROR: did not find variableName = "<<s<<" in cutName_cut_. Returning");
    }
  cut * c = & (cc->second);
  return (c->maxValue2);
}
Ejemplo n.º 15
0
void baseClass::evaluateCuts()
{
  //  resetCuts();
  combCutName_passed_.clear();
  for (vector<string>::iterator it = orderedCutNames_.begin(); 
       it != orderedCutNames_.end(); it++) 
    {
      cut * c = & (cutName_cut_.find(*it)->second);
      if( ! ( c->filled && (c->minValue1 < c->value && c->value <= c->maxValue1 || c->minValue2 < c->value && c->value <= c->maxValue2 ) ) )
	{
          c->passed = false;
          combCutName_passed_[c->level_str.c_str()] = false;
          combCutName_passed_["all"] = false;
	}
      else
	{
	  c->passed = true;
	  map<string,bool>::iterator cp = combCutName_passed_.find( c->level_str.c_str() );
	  combCutName_passed_[c->level_str.c_str()] = (cp==combCutName_passed_.end()?true:cp->second);
	  map<string,bool>::iterator ap = combCutName_passed_.find( "all" );
	  combCutName_passed_["all"] = (ap==combCutName_passed_.end()?true:ap->second);
	}
    }

  if( !fillCutHistos() )
    {
      STDOUT("ERROR: fillCutHistos did not complete successfully.");
    }

  if( !updateCutEffic() )
    {
      STDOUT("ERROR: updateCutEffic did not complete successfully.");
    }

  return ;
}
Ejemplo n.º 16
0
void baseClass::init()
{
  STDOUT("begin");
    //std::cout << "baseClass::init(): begin " << std::endl;

  tree_ = NULL;
  readInputList();
  readCutFile();
  if(tree_ == NULL){
    std::cout << "baseClass::init(): ERROR: tree_ = NULL " << std::endl;
    return;
  }
  Init(tree_);

  char output_root_title[200];
  sprintf(output_root_title,"%s%s",&std::string(*outputFileName_)[0],".root");
  output_root_ = new TFile(&output_root_title[0],"RECREATE");

  //  for (map<string, cut>::iterator it = cutName_cut_.begin(); 
  //   it != cutName_cut_.end(); it++) STDOUT("cutName_cut->first = "<<it->first)
  //  for (vector<string>::iterator it = orderedCutNames_.begin(); 
  //       it != orderedCutNames_.end(); it++) STDOUT("orderedCutNames_ = "<<*it)
  STDOUT("end");
}
Ejemplo n.º 17
0
void baseClass::fillVariableWithValue(const string& s, const double& d)
{
  map<string, cut>::iterator cc = cutName_cut_.find(s);
  if( cc == cutName_cut_.end() )
    {
      STDOUT("variableName = "<< s << "not found in cutName_cut_.");
      return;
    } 
  else
    {
      cut * c = & (cc->second);
      c->filled = true;
      c->value = d;
    }
  return;
}
Ejemplo n.º 18
0
bool baseClass::passedCut(const string& s)
{
  bool ret = false;
  //  map<string, bool>::iterator vp = cutName_passed_.find(s);
  //  if( vp != cutName_passed_.end() ) return ret = vp->second;
  map<string, cut>::iterator cc = cutName_cut_.find(s);
  if( cc != cutName_cut_.end() ) 
    {
      cut * c = & (cutName_cut_.find(s)->second);
      return (c->filled && c->passed);
    }
  map<string, bool>::iterator cp = combCutName_passed_.find(s);
  if( cp != combCutName_passed_.end() ) 
    {
      return ret = cp->second;
    }
  STDOUT("ERROR: did not find variableName = "<<s<<" neither in cutName_cut_ nor combCutName_passed_. Returning false.");
  return (ret=false);
}
Ejemplo n.º 19
0
AFFEND

AFFDEF(arc_writec)
{
  AARG(chr);
  AOARG(fd);
  AVAR(buf, i, writeb, nbytes);
  char cbuf[UTFmax];
  Rune ch;
  int j;
  AFBEGIN;

  if (arc_thr_argc(c, thr) == 0) {
    arc_err_cstrfmt(c, "writec: too few arguments");
    return(CNIL);
  }

  if (!BOUND_P(AV(fd)))
    STDOUT(fd);

  IOW_TYPECHECK(AV(fd));
  CHECK_CLOSED(AV(fd));
  if (IO(AV(fd))->flags & IO_FLAG_GETB_IS_GETC) {
    AFCALL(VINDEX(IO(AV(fd))->io_ops, IO_putb), AV(fd),
	   INT2FIX(arc_char2rune(c, AV(chr))));
    ARETURN(arc_mkchar(c, FIX2INT(AFCRV)));
  }
  /* XXX - should put this in builtins */
  WV(writeb, arc_mkaff(c, arc_writeb, CNIL));
  ch = arc_char2rune(c, AV(chr));
  WV(nbytes, INT2FIX(runetochar(cbuf, &ch)));
  /* Convert C char array into Arcueid vector of fixnums */
  WV(buf, arc_mkvector(c, FIX2INT(AV(nbytes))));
  for (j=0; j<FIX2INT(AV(nbytes)); j++)
    SVINDEX(AV(buf), j, INT2FIX(cbuf[j]));
  for (WV(i, INT2FIX(0)); FIX2INT(AV(i)) < FIX2INT(AV(nbytes)); WV(i, INT2FIX(FIX2INT(AV(i)) + 1))) {
    AFCALL(AV(writeb),VINDEX(AV(buf), FIX2INT(AV(i))), AV(fd));
  }
  ARETURN(AV(chr));
  AFEND;
}
void analysisClass::Loop()
{
  //STDOUT("analysisClass::Loop() begins");

  if (fChain == 0) return;

  /*//------------------------------------------------------------------
   *
   *
   *      
   *      Get all Pre-cut values!
   *
   *
   *
   *///-----------------------------------------------------------------
  
   //--------------------------------------------------------------------------
   // Decide which plots to save (default is to save everything)
   //--------------------------------------------------------------------------
   
   fillSkim                         ( !true  ) ;
   fillAllPreviousCuts              ( !true  ) ;
   fillAllOtherCuts                 ( !true  ) ;
   fillAllSameLevelAndLowerLevelCuts( !true  ) ;
   fillAllCuts                      ( !true  ) ;

  //-----------------------------------------------------------------
  // Electron cut values
  //-----------------------------------------------------------------
  
  double ele_PtCut_STORE = getPreCutValue2("ele_PtCut");
  double ele_PtCut_ANA   = getPreCutValue1("ele_PtCut");
  
  double eleEta_bar      = getPreCutValue1("eleEta_bar");
  double eleEta_end_min  = getPreCutValue1("eleEta_end");
  double eleEta_end_max  = getPreCutValue2("eleEta_end");
  
  if ( ele_PtCut_STORE > ele_PtCut_ANA ) {
    STDOUT("ERROR in Electron cut values: all storage cuts must be looser or equal to analysis cuts.");
    exit(0) ;
  }

  // For WP80

  double eleMissingHitsWP             = getPreCutValue1("eleMissingHitsWP"        );
  double eleDistWP                    = getPreCutValue1("eleDistWP"               );
  double eleDCotThetaWP               = getPreCutValue1("eleDCotThetaWP"          );
  double eleCombRelIsoWP_bar          = getPreCutValue1("eleCombRelIsoWP"         );
  double eleCombRelIsoWP_end          = getPreCutValue2("eleCombRelIsoWP"         );
  double eleSigmaIetaIetaWP_bar       = getPreCutValue1("eleSigmaIetaIetaWP"      );
  double eleSigmaIetaIetaWP_end       = getPreCutValue2("eleSigmaIetaIetaWP"      );
  double eleDeltaPhiTrkSCWP_bar       = getPreCutValue1("eleDeltaPhiTrkSCWP"      );
  double eleDeltaPhiTrkSCWP_end       = getPreCutValue2("eleDeltaPhiTrkSCWP"      );
  double eleDeltaEtaTrkSCWP_bar       = getPreCutValue1("eleDeltaEtaTrkSCWP"      );
  double eleDeltaEtaTrkSCWP_end       = getPreCutValue2("eleDeltaEtaTrkSCWP"      );
  double eleUseEcalDrivenWP           = getPreCutValue1("eleUseEcalDrivenWP"      );
  double eleUseHasMatchConvWP         = getPreCutValue1("eleUseHasMatchConvWP"    );

  // For HEEP 3.1

  double eleDeltaEtaTrkSCHeep_bar     = getPreCutValue1("eleDeltaEtaTrkSCHeep"    );
  double eleDeltaEtaTrkSCHeep_end     = getPreCutValue2("eleDeltaEtaTrkSCHeep"    );
  double eleDeltaPhiTrkSCHeep_bar     = getPreCutValue1("eleDeltaPhiTrkSCHeep"    );
  double eleDeltaPhiTrkSCHeep_end     = getPreCutValue2("eleDeltaPhiTrkSCHeep"    );
  double eleHoEHeep_bar               = getPreCutValue1("eleHoEHeep"              );
  double eleHoEHeep_end               = getPreCutValue2("eleHoEHeep"              );
  double eleE2x5OverE5x5Heep_bar      = getPreCutValue1("eleE2x5OverE5x5Heep"     );
  double eleE1x5OverE5x5Heep_bar      = getPreCutValue1("eleE1x5OverE5x5Heep"     );
  double eleSigmaIetaIetaHeep_end     = getPreCutValue2("eleSigmaIetaIetaHeep"    );
  double eleEcalHcalIsoHeep_1_bar     = getPreCutValue1("eleEcalHcalIsoHeep"      );
  double eleEcalHcalIsoHeep_2_bar     = getPreCutValue2("eleEcalHcalIsoHeep"      );
  double eleEcalHcalIsoHeep_1_end     = getPreCutValue3("eleEcalHcalIsoHeep"      );
  double eleEcalHcalIsoHeep_2_end     = getPreCutValue4("eleEcalHcalIsoHeep"      );
  double eleEcalHcalIsoHeep_PTthr_end = getPreCutValue2("eleEcalHcalIsoHeep_PTthr");
  double eleHcalIsoD2Heep_end         = getPreCutValue2("eleHcalIsoD2Heep"        );
  double eleTrkIsoHeep_bar            = getPreCutValue1("eleTrkIsoHeep"           );
  double eleTrkIsoHeep_end            = getPreCutValue2("eleTrkIsoHeep"           );
  double eleMissingHitsHeep           = getPreCutValue1("eleMissingHitsHeep"      );
  double eleUseEcalDrivenHeep         = getPreCutValue1("eleUseEcalDrivenHeep"    );

  // For HEEP 3.2

  double eleDeltaEtaTrkSCHeep32_bar     = getPreCutValue1("eleDeltaEtaTrkSCHeep32"    );
  double eleDeltaEtaTrkSCHeep32_end     = getPreCutValue2("eleDeltaEtaTrkSCHeep32"    );
  double eleDeltaPhiTrkSCHeep32_bar     = getPreCutValue1("eleDeltaPhiTrkSCHeep32"    );
  double eleDeltaPhiTrkSCHeep32_end     = getPreCutValue2("eleDeltaPhiTrkSCHeep32"    );
  double eleHoEHeep32_bar               = getPreCutValue1("eleHoEHeep32"              );
  double eleHoEHeep32_end               = getPreCutValue2("eleHoEHeep32"              );
  double eleE2x5OverE5x5Heep32_bar      = getPreCutValue1("eleE2x5OverE5x5Heep32"     );
  double eleE1x5OverE5x5Heep32_bar      = getPreCutValue1("eleE1x5OverE5x5Heep32"     );
  double eleSigmaIetaIetaHeep32_end     = getPreCutValue2("eleSigmaIetaIetaHeep32"    );
  double eleEcalHcalIsoHeep32_1_bar     = getPreCutValue1("eleEcalHcalIsoHeep32"      );
  double eleEcalHcalIsoHeep32_2_bar     = getPreCutValue2("eleEcalHcalIsoHeep32"      );
  double eleEcalHcalIsoHeep32_1_end     = getPreCutValue3("eleEcalHcalIsoHeep32"      );
  double eleEcalHcalIsoHeep32_2_end     = getPreCutValue4("eleEcalHcalIsoHeep32"      );
  double eleEcalHcalIsoHeep32_PTthr_end = getPreCutValue2("eleEcalHcalIsoHeep32_PTthr");
  //double eleHcalIsoD2Heep32_end         = getPreCutValue2("eleHcalIsoD2Heep32"        );
  double eleTrkIsoHeep32_bar            = getPreCutValue1("eleTrkIsoHeep32"           );
  double eleTrkIsoHeep32_end            = getPreCutValue2("eleTrkIsoHeep32"           );
  double eleMissingHitsHeep32           = getPreCutValue1("eleMissingHitsHeep32"      );
  double eleUseEcalDrivenHeep32         = getPreCutValue1("eleUseEcalDrivenHeep32"    );

  CreateUserTH1D("dphi_met_ele", 100, 0, 3.14159 );

  //-----------------------------------------------------------------
  // Which algorithms to use?
  //-----------------------------------------------------------------

  int    eleAlgorithm = (int) getPreCutValue1("eleAlgorithm");

  //-----------------------------------------------------------------
  // Counters
  //-----------------------------------------------------------------

  int n_photon30__160404_163869 = 0;
  int n_photon30_HEEP__160404_163869 = 0;
  int n_photon30_HEEP_ele27__160404_163869 = 0;
  double eff_eleIDIso__160404_163869 = 0.;

  //## Maps 
  // first  = key   = RunNumber 
  // second = value = NumberOfEvents 
  map<int, int> MapTrg; 
  map<int, int> MapDen; 
  map<int, int> MapNum;
  map<int, int> MapNumErrSquare;
    
  /*//------------------------------------------------------------------
   *
   *
   *      
   *      Start analysis loop!
   *
   *
   *
   *///-----------------------------------------------------------------


  Long64_t nentries = fChain->GetEntries();
  //Long64_t nentries = 200000;
  STDOUT("analysisClass::Loop(): nentries = " << nentries);

  Long64_t nbytes = 0, nb = 0;
  for (Long64_t jentry=0; jentry<nentries;jentry++) { // Begin of loop over events
    Long64_t ientry = LoadTree(jentry);
    if (ientry < 0) break;
    nb = fChain->GetEntry(jentry);   nbytes += nb;
    if(jentry < 10 || jentry%1000 == 0) STDOUT("analysisClass::Loop(): jentry = " << jentry << "/" << nentries );
    
    //-----------------------------------------------------------------
    // Do pileup re-weighting, if necessary
    //  --> To be done after the skim, so commented out for now
    //-----------------------------------------------------------------
    
    // double event_weight = getPileupWeight ( PileUpInteractions, isData ) ;
    
    //-----------------------------------------------------------------
    // Get trigger information, if necessary
    //-----------------------------------------------------------------

    if ( isData ) { 
      getTriggers ( HLTKey, HLTInsideDatasetTriggerNames, HLTInsideDatasetTriggerDecisions,  HLTInsideDatasetTriggerPrescales ) ;
    }
    
    //-----------------------------------------------------------------
    // Selection: Electrons
    //-----------------------------------------------------------------    

    vector<int> v_idx_ele_PtCut_IDISO_STORE;
    vector<int> v_idx_ele_PtCut_IDISO_ANA;
    vector<int> v_idx_ele_IDISO;

    //Loop over electrons
    for(int iele=0; iele<ElectronPt->size(); iele++){
      
      int passEleSel = 0;
      int isBarrel = 0;
      int isEndcap = 0;
      
      if( fabs( ElectronSCEta->at(iele) ) < eleEta_bar )       isBarrel = 1;
      if( fabs( ElectronSCEta->at(iele) ) > eleEta_end_min &&
	  fabs( ElectronSCEta->at(iele) ) < eleEta_end_max )   isEndcap = 1;

      //-----------------------------------------------------------------    
      // HEEP ID application 3.1
      //-----------------------------------------------------------------    

      if ( eleAlgorithm == 1 ) { 
	
	if(isBarrel) {		

	  if(   fabs(ElectronDeltaEtaTrkSC->at(iele)) < eleDeltaEtaTrkSCHeep_bar 
		&& fabs(ElectronDeltaPhiTrkSC->at(iele)) < eleDeltaPhiTrkSCHeep_bar 
		&& ElectronHoE->at(iele) < eleHoEHeep_bar 
		&& (ElectronE2x5OverE5x5->at(iele) >eleE2x5OverE5x5Heep_bar || ElectronE1x5OverE5x5->at(iele) > eleE1x5OverE5x5Heep_bar ) 
		&& ( ElectronEcalIsoDR03->at(iele)+ElectronHcalIsoD1DR03->at(iele) ) < eleEcalHcalIsoHeep_1_bar + eleEcalHcalIsoHeep_2_bar*ElectronPt->at(iele)
		&& ElectronTrkIsoDR03->at(iele) <eleTrkIsoHeep_bar 
		&& ElectronMissingHits->at(iele) == 0 
		&& ElectronHasEcalDrivenSeed->at(iele)
	     )
	    passEleSel = 1;		

	}//end barrel
	
	if(isEndcap) {		
	  
	  int passEcalHcalIsoCut=0;
	  if(ElectronPt->at(iele) < eleEcalHcalIsoHeep_PTthr_end && 
	     (ElectronEcalIsoDR03->at(iele)+ElectronHcalIsoD1DR03->at(iele)) < eleEcalHcalIsoHeep_1_end) 
	    passEcalHcalIsoCut=1;
	  if(ElectronPt->at(iele) > eleEcalHcalIsoHeep_PTthr_end && 
	     (ElectronEcalIsoDR03->at(iele)+ElectronHcalIsoD1DR03->at(iele)) < eleEcalHcalIsoHeep_1_end+eleEcalHcalIsoHeep_2_end*(ElectronPt->at(iele)-eleEcalHcalIsoHeep_PTthr_end) ) 
	    passEcalHcalIsoCut=1;
	  
	  if(fabs(ElectronDeltaEtaTrkSC->at(iele)) < eleDeltaEtaTrkSCHeep_end 
	     && fabs(ElectronDeltaPhiTrkSC->at(iele)) < eleDeltaPhiTrkSCHeep_end 
	     && ElectronHoE->at(iele) < eleHoEHeep_end 
	     && ElectronSigmaIEtaIEta->at(iele) < eleSigmaIetaIetaHeep_end 
	     && passEcalHcalIsoCut == 1
	     && ElectronHcalIsoD2DR03->at(iele) < eleHcalIsoD2Heep_end 
	     && ElectronTrkIsoDR03->at(iele) < eleTrkIsoHeep_end 
	     && ElectronMissingHits->at(iele) == 0 
	     && ElectronHasEcalDrivenSeed->at(iele)
	     )
	    passEleSel = 1;
	  
	}//end endcap
      }

      //-----------------------------------------------------------------    
      // WP80 ID application
      //-----------------------------------------------------------------    

      else if ( eleAlgorithm == 2 ) { 
	// ecal driven	    
	if( eleUseEcalDrivenWP && !ElectronHasEcalDrivenSeed->at(iele) ) continue;
	
	// isolation
	double ElectronCombRelIsoWP_bar  =  ( ElectronTrkIsoDR03->at(iele) 
					    + max( 0., ElectronEcalIsoDR03->at(iele) - 1. ) 
					    + ElectronHcalIsoDR03FullCone->at(iele) 
					    - rhoIso*TMath::Pi()*0.3*0.3 
					    ) / ElectronPt->at(iele) ;
	
	double ElectronCombRelIsoWP_end  =  ( ElectronTrkIsoDR03->at(iele) 
					      + ElectronEcalIsoDR03->at(iele) 
					      + ElectronHcalIsoDR03FullCone->at(iele) 
					      - rhoIso*TMath::Pi()*0.3*0.3 
					      ) / ElectronPt->at(iele) ;
	
	// conversions
	int isPhotConv = 0;
	if(eleUseHasMatchConvWP) {
	  if( ElectronHasMatchedConvPhot->at(iele) ) 
	    isPhotConv = 1;
	}
	else {
	  if( ElectronDist->at(iele) < eleDistWP && ElectronDCotTheta->at(iele) < eleDCotThetaWP )	
	    isPhotConv = 1;
	}

	if(isBarrel) {
	  
	  if( ElectronMissingHits->at(iele) <= eleMissingHitsWP              && 
	      isPhotConv == 0					             && 
	      ElectronCombRelIsoWP_bar < eleCombRelIsoWP_bar		     && 
	      ElectronSigmaIEtaIEta->at(iele) < eleSigmaIetaIetaWP_bar       && 
	      fabs(ElectronDeltaPhiTrkSC->at(iele)) < eleDeltaPhiTrkSCWP_bar && 
	      fabs(ElectronDeltaEtaTrkSC->at(iele)) < eleDeltaEtaTrkSCWP_bar  )
	    passEleSel = 1;		
	  
	}//end barrel
	
	if(isEndcap) {		
	    
	  if( ElectronMissingHits->at(iele) == eleMissingHitsWP              && 
	      isPhotConv == 0						     && 
	      ElectronCombRelIsoWP_end < eleCombRelIsoWP_end		     && 
	      ElectronSigmaIEtaIEta->at(iele) < eleSigmaIetaIetaWP_end 	     && 
	      fabs(ElectronDeltaPhiTrkSC->at(iele)) < eleDeltaPhiTrkSCWP_end && 
	      fabs(ElectronDeltaEtaTrkSC->at(iele)) < eleDeltaEtaTrkSCWP_end  )
	    passEleSel = 1;		
	  
	}//end endcap	
      }

      //-----------------------------------------------------------------    
      // HEEP ID application 3.2
      //-----------------------------------------------------------------    

      else if ( eleAlgorithm == 3 ) { 
	
	if(isBarrel) {
		
	  if(   fabs(ElectronDeltaEtaTrkSC->at(iele)) < eleDeltaEtaTrkSCHeep32_bar 
		&& fabs(ElectronDeltaPhiTrkSC->at(iele)) < eleDeltaPhiTrkSCHeep32_bar 
		&& ElectronHoE->at(iele) < eleHoEHeep32_bar 
		&& (ElectronE2x5OverE5x5->at(iele) >eleE2x5OverE5x5Heep32_bar || ElectronE1x5OverE5x5->at(iele) > eleE1x5OverE5x5Heep32_bar ) 
		&& ( ElectronEcalIsoDR03->at(iele)+ElectronHcalIsoD1DR03->at(iele) ) < eleEcalHcalIsoHeep32_1_bar + eleEcalHcalIsoHeep32_2_bar*ElectronPt->at(iele)
		&& ElectronTrkIsoDR03->at(iele) <eleTrkIsoHeep32_bar 
		&& ElectronMissingHits->at(iele) == 0 
		&& ElectronHasEcalDrivenSeed->at(iele)
	     )
	    passEleSel = 1;		

	}//end barrel
	
	if(isEndcap) {		
	  
	  int passEcalHcalIsoCut=0;
	  if(ElectronPt->at(iele) < eleEcalHcalIsoHeep32_PTthr_end && 
	     (ElectronEcalIsoDR03->at(iele)+ElectronHcalIsoD1DR03->at(iele)) < eleEcalHcalIsoHeep32_1_end) 
	    passEcalHcalIsoCut=1;
	  if(ElectronPt->at(iele) > eleEcalHcalIsoHeep32_PTthr_end && 
	     (ElectronEcalIsoDR03->at(iele)+ElectronHcalIsoD1DR03->at(iele)) < eleEcalHcalIsoHeep32_1_end+eleEcalHcalIsoHeep32_2_end*(ElectronPt->at(iele)-eleEcalHcalIsoHeep32_PTthr_end) ) 
	    passEcalHcalIsoCut=1;
	  
	  if(fabs(ElectronDeltaEtaTrkSC->at(iele)) < eleDeltaEtaTrkSCHeep32_end 
	     && fabs(ElectronDeltaPhiTrkSC->at(iele)) < eleDeltaPhiTrkSCHeep32_end 
	     && ElectronHoE->at(iele) < eleHoEHeep32_end 
	     && ElectronSigmaIEtaIEta->at(iele) < eleSigmaIetaIetaHeep32_end 
	     && passEcalHcalIsoCut == 1
	     //&& ElectronHcalIsoD2DR03->at(iele) < eleHcalIsoD2Heep32_end 
	     && ElectronTrkIsoDR03->at(iele) < eleTrkIsoHeep32_end 
	     && ElectronMissingHits->at(iele) == 0 
	     && ElectronHasEcalDrivenSeed->at(iele)
	     )
	    passEleSel = 1;
	  
	}//end endcap
      }
      
      if ( passEleSel ) { 
	v_idx_ele_IDISO.push_back ( iele ) ;
	if ( ElectronPt -> at (iele) >= ele_PtCut_STORE ) v_idx_ele_PtCut_IDISO_STORE.push_back ( iele ) ;
	if ( ElectronPt -> at (iele) >= ele_PtCut_ANA   ) v_idx_ele_PtCut_IDISO_ANA  .push_back ( iele ) ;
      }

    }
    
    //-----------------------------------------------------------------
    // Fill your single-object variables with values
    //-----------------------------------------------------------------

    // Set the evaluation of the cuts to false and clear the variable values and filled status
    resetCuts();
    
    fillVariableWithValue( "PassJSON", passJSON(run, ls, isData) );    
    // Set the value of the variableNames listed in the cutFile to their current value

    //event info
    fillVariableWithValue( "isData"   , isData     ) ;
    fillVariableWithValue( "bunch"    , bunch      ) ;
    fillVariableWithValue( "event"    , event      ) ;
    fillVariableWithValue( "ls"       , ls         ) ;
    fillVariableWithValue( "orbit"    , orbit      ) ;
    fillVariableWithValue( "run"      , run        ) ;

    // Trigger (L1 and HLT)
    if(isData==true)
      {
	fillVariableWithValue( "PassBPTX0", isBPTX0 ) ;
	fillVariableWithValue( "PassPhysDecl", isPhysDeclared ) ;
      }
    else
      {
	fillVariableWithValue( "PassBPTX0", true ) ;
	fillVariableWithValue( "PassPhysDecl", true ) ;
      }
    //triggerFired ("HLT_Photon30_CaloIdVL_v1")

    //Event filters at RECO level
    fillVariableWithValue( "PassBeamScraping", !isBeamScraping ) ;
    fillVariableWithValue( "PassPrimaryVertex", isPrimaryVertex ) ;
    fillVariableWithValue( "PassHBHENoiseFilter", passHBHENoiseFilter ) ;
    fillVariableWithValue( "PassBeamHaloFilterLoose", passBeamHaloFilterLoose ) ;
    fillVariableWithValue( "PassBeamHaloFilterTight", passBeamHaloFilterTight ) ;
    fillVariableWithValue( "PassTrackingFailure", !isTrackingFailure ) ;
    fillVariableWithValue( "PassCaloBoundaryDRFilter", passCaloBoundaryDRFilter ) ;
    fillVariableWithValue( "PassEcalMaskedCellDRFilter", passEcalMaskedCellDRFilter ) ;
    
    // Evaluate cuts (but do not apply them)
    evaluateCuts();

    double met = PFMET -> at(0);
    double met_phi = PFMETPhi -> at(0);

    //Basic Event Selection
    if( passedCut("PassJSON") 
	&& passedCut("PassBPTX0") 
	&& passedCut("PassBeamScraping") 
	&& passedCut("PassPrimaryVertex")
	&& passedCut("PassHBHENoiseFilter")
	&& passedCut("PassBeamHaloFilterTight") 
	)
      {      

	//### Fill Maps (full run range)
	
	if( triggerFired ("HLT_Photon30_CaloIdVL_v1") 
	    || triggerFired ("HLT_Photon30_CaloIdVL_v2") 
	    || triggerFired ("HLT_Photon30_CaloIdVL_v3") 
	    || triggerFired ("HLT_Photon30_CaloIdVL_v4") 
	    || triggerFired ("HLT_Photon30_CaloIdVL_v5") 
	    || triggerFired ("HLT_Photon30_CaloIdVL_v6") 
	    || triggerFired ("HLT_Photon30_CaloIdVL_v7") 
	    || triggerFired ("HLT_Photon30_CaloIdVL_v8") 
	    )
	  {
	
	    map<int,int>::iterator MapTrgIt = MapTrg.find(run);
	    map<int,int>::iterator MapTrgItEnd = MapTrg.end();
	    if( MapTrgIt == MapTrgItEnd )
	      {
		MapTrg.insert(pair<int,int>(run,1));
		//MapDen[run]=1;
	      }
	    else
	      MapTrgIt->second++;

	    TLorentzVector my_v_met, my_ele;
	    double my_delta_phi;
	    my_v_met.SetPtEtaPhiM ( met, 0.0, met_phi, 0.0);
	    
	    if( v_idx_ele_PtCut_IDISO_ANA.size()==1){
	      my_ele.SetPtEtaPhiM ( ElectronPt  -> at (v_idx_ele_PtCut_IDISO_ANA[0]),
				    ElectronEta -> at (v_idx_ele_PtCut_IDISO_ANA[0]),
				    ElectronPhi -> at (v_idx_ele_PtCut_IDISO_ANA[0]),
				    0.0 );
	      my_delta_phi = fabs(my_v_met.DeltaPhi ( my_ele ) );
	    }

	    
	    if( v_idx_ele_PtCut_IDISO_ANA.size()==1 && met > 30.0 && my_delta_phi > 2.5 )
	      {
		//denominator
		map<int,int>::iterator MapDenIt = MapDen.find(run);
		map<int,int>::iterator MapDenItEnd = MapDen.end();

		FillUserTH1D("dphi_met_ele", my_delta_phi );
		

		if( MapDenIt == MapDenItEnd )
		  {
		    MapDen.insert(pair<int,int>(run,1));
		    //MapDen[run]=1;
		  }
		else
		  MapDenIt->second++;

		CreateAndFillUserTH1D("ElePt_AfterPhoton30", 100, 0, 1000, ElectronPt -> at (v_idx_ele_PtCut_IDISO_ANA[0]) );
		CreateAndFillUserTH1D("MET_AfterPhoton30", 100, 0, 1000, PFMET->at(0) );

		//numerator
		map<int,int>::iterator MapNumIt = MapNum.find(run);
		map<int,int>::iterator MapNumErrSquareIt = MapNumErrSquare.find(run);
		map<int,int>::iterator MapNumItEnd = MapNum.end();

		//-- 160404-161176
		if( triggerFired ("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v1") )
		  {
		    if( MapNumIt == MapNumItEnd )
		      {
			MapNum.insert(pair<int,int>( run , triggerPrescale("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v1") ));
			//MapNum[run]=1;
			MapNumErrSquare.insert(pair<int,int>( run , pow(triggerPrescale("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v1"),2) ));
		      }
		    else
		      {
			MapNumIt->second += triggerPrescale("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v1");
			MapNumErrSquareIt->second += pow(triggerPrescale("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v1"),2);
		      }
		  }

		//-- 161216-163261
		if( triggerFired ("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v2") )
		  {
		    if( MapNumIt == MapNumItEnd )
		      {
			MapNum.insert(pair<int,int>( run , triggerPrescale("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v2") ));
			//MapNum[run]=1;
			MapNumErrSquare.insert(pair<int,int>( run , pow(triggerPrescale("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v2"),2) ));
		      }
		    else
		      {
			MapNumIt->second += triggerPrescale("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v2");
			MapNumErrSquareIt->second += pow(triggerPrescale("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v2"),2);
		      }
		  }

		//-- 163269-163869
		if( triggerFired ("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v3") )
		  {
		    if( MapNumIt == MapNumItEnd )
		      {
			MapNum.insert(pair<int,int>( run , triggerPrescale("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v3") ));
			//MapNum[run]=1;
			MapNumErrSquare.insert(pair<int,int>( run , pow(triggerPrescale("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v3"),2) ));
		      }
		    else
		      {
			MapNumIt->second += triggerPrescale("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v3");
			MapNumErrSquareIt->second += pow(triggerPrescale("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v3"),2);
		      }
		  }

		//-- 165088-165633
		if( triggerFired ("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v3") )
		  {
		    if( MapNumIt == MapNumItEnd )
		      {
			MapNum.insert(pair<int,int>( run , triggerPrescale("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v3") ));
			//MapNum[run]=1;
			MapNumErrSquare.insert(pair<int,int>( run , pow(triggerPrescale("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v3"),2) ));
		      }
		    else
		      {
			MapNumIt->second += triggerPrescale("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v3");
			MapNumErrSquareIt->second += pow(triggerPrescale("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v3"),2);
		      }
		  }

		//-- 165970-166967
		if( triggerFired ("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v4") )
		  {
		    if( MapNumIt == MapNumItEnd )
		      {
			MapNum.insert(pair<int,int>( run , triggerPrescale("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v4") ));
			//MapNum[run]=1;
			MapNumErrSquare.insert(pair<int,int>( run , pow(triggerPrescale("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v4"),2) ));
		      }
		    else
		      {
			MapNumIt->second += triggerPrescale("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v4");
			MapNumErrSquareIt->second += pow(triggerPrescale("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v4"),2);
		      }
		  }

		//-- 167039-167913
		if( triggerFired ("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v5") )
		  {
		    if( MapNumIt == MapNumItEnd )
		      {
			MapNum.insert(pair<int,int>( run , triggerPrescale("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v5") ));
			//MapNum[run]=1;
			MapNumErrSquare.insert(pair<int,int>( run , pow(triggerPrescale("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v5"),2) ));
		      }
		    else
		      {
			MapNumIt->second += triggerPrescale("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v5");
			MapNumErrSquareIt->second += pow(triggerPrescale("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v5"),2);
		      }
		  }

		//-- 170249-173198
		if( triggerFired ("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v6") )
		  {
		    if( MapNumIt == MapNumItEnd )
		      {
			MapNum.insert(pair<int,int>( run , triggerPrescale("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v6") ));
			//MapNum[run]=1;
			MapNumErrSquare.insert(pair<int,int>( run , pow(triggerPrescale("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v6"),2) ));
		      }
		    else
		      {
			MapNumIt->second += triggerPrescale("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v6");
			MapNumErrSquareIt->second += pow(triggerPrescale("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v6"),2);
		      }
		  }

		//-- 173236-178380
		if( triggerFired ("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v7") )
		  {
		    if( MapNumIt == MapNumItEnd )
		      {
			MapNum.insert(pair<int,int>( run , triggerPrescale("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v7") ));
			//MapNum[run]=1;
			MapNumErrSquare.insert(pair<int,int>( run , pow(triggerPrescale("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v7"),2) ));
		      }
		    else
		      {
			MapNumIt->second += triggerPrescale("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v7");
			MapNumErrSquareIt->second += pow(triggerPrescale("HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v7"),2);
		      }
		  }

		//-- 178420-179889
		if( triggerFired ("HLT_Ele27_WP80_v2") )
		  {
		    if( MapNumIt == MapNumItEnd )
		      {
			MapNum.insert(pair<int,int>( run , triggerPrescale("HLT_Ele27_WP80_v2") ));
			//MapNum[run]=1;
			MapNumErrSquare.insert(pair<int,int>( run , pow(triggerPrescale("HLT_Ele27_WP80_v2"),2) ));
		      }
		    else
		      {
			MapNumIt->second += triggerPrescale("HLT_Ele27_WP80_v2");
			MapNumErrSquareIt->second += pow(triggerPrescale("HLT_Ele27_WP80_v2"),2);
		      }
		  }

		//-- 179959-180252
		if( triggerFired ("HLT_Ele27_WP80_v3") )
		  {
		    if( MapNumIt == MapNumItEnd )
		      {
			MapNum.insert(pair<int,int>( run , triggerPrescale("HLT_Ele27_WP80_v3") ));
			//MapNum[run]=1;
			MapNumErrSquare.insert(pair<int,int>( run , pow(triggerPrescale("HLT_Ele27_WP80_v3"),2) ));
		      }
		    else
		      {
			MapNumIt->second += triggerPrescale("HLT_Ele27_WP80_v3");
			MapNumErrSquareIt->second += pow(triggerPrescale("HLT_Ele27_WP80_v3"),2);
		      }
		  }

		// HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v1    160404-161176
		// HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v2    161216-163261
		// (HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v1)  161216-163261
		// HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v3    163269-163869
		// (HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v2)  163269-163869
		// HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v3    165088-165633
		// HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v4    165970-166967
		// HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v5    167039-167913
		// HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v6    170249-173198
		// HLT_Ele32_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v7    173236-178380
		// HLT_Ele27_WP80_v2				 178420-179889
		// HLT_Ele27_WP80_v3				 179959-180252

	      }//end 1 HEEP requirement

	  }//end photon trigger fired
	//###

	//### run range: 160404-163869 (TEST)
	if( triggerFired ("HLT_Photon30_CaloIdVL_v1") 
	    || triggerFired ("HLT_Photon30_CaloIdVL_v2") 
	    || triggerFired ("HLT_Photon30_CaloIdVL_v3") 
	    )
	  {
	    n_photon30__160404_163869++;
	    
	    if( v_idx_ele_PtCut_IDISO_ANA.size()==1 )
	      {
		//denominator
		n_photon30_HEEP__160404_163869++; 	
		CreateAndFillUserTH1D("ElePt_AfterPhoton30__160404_163869", 100, 0, 1000, ElectronPt -> at (v_idx_ele_PtCut_IDISO_ANA[0]) );
		
		//numerator
		if( triggerFired ("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v1") )
		  n_photon30_HEEP_ele27__160404_163869 += triggerPrescale ("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v1" ); 
		
		if( triggerFired ("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v2") )
		  n_photon30_HEEP_ele27__160404_163869 += triggerPrescale ("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v2" ); 
		
		if( triggerFired ("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v3") )
		  n_photon30_HEEP_ele27__160404_163869 += triggerPrescale ("HLT_Ele27_CaloIdVT_CaloIsoT_TrkIdT_TrkIsoT_v3" ); 
	      }//end 1 HEEP requirement
	  }//end photon trigger fired
	//###

      }//end Basic Event Selection


  } // End of loop over events

  //##################################################

  //## Printout (test)
  cout << "---- Test : run range = 160404-163869 ----" << endl;

  eff_eleIDIso__160404_163869 = double(n_photon30_HEEP_ele27__160404_163869) / double(n_photon30_HEEP__160404_163869);

  cout << "n_photon30__160404_163869: " << n_photon30__160404_163869 << endl;
  cout << "n_photon30_HEEP__160404_163869: " << n_photon30_HEEP__160404_163869 << endl;
  cout << "n_photon30_HEEP_ele27__160404_163869: " << n_photon30_HEEP_ele27__160404_163869 << endl;
  cout << "eff_eleIDIso__160404_163869: " << eff_eleIDIso__160404_163869 << endl;
  cout << endl;

  //## Printout (final results)
  cout << "---- Final Results (full run range) ----" << endl;

  map<int,int>::iterator MapTrgIt = MapTrg.begin();
  map<int,int>::iterator MapTrgItEnd = MapTrg.end();
  int sumTrg = 0 ;
  //   FILE * pFileTrg;
  //   pFileTrg = fopen ("MapTrg.txt","w");
  for(;MapTrgIt!=MapTrgItEnd;++MapTrgIt)
    {
      //cout << "run , N : " << MapTrgIt->first << " " << MapTrgIt->second << endl;
      sumTrg += MapTrgIt->second;
      cout << "MAPTRG: " << MapTrgIt->first << " " << MapTrgIt->second << " " << sqrt(MapTrgIt->second) << endl;
      //fprintf (pFileTrg, "%d %d %f\n",MapTrgIt->first,MapTrgIt->second,sqrt(MapTrgIt->second));
    }
  //fclose (pFileTrg);

  map<int,int>::iterator MapDenIt = MapDen.begin();
  map<int,int>::iterator MapDenItEnd = MapDen.end();
  int sumDen = 0 ;
  //   FILE * pFileDen;
  //   pFileDen = fopen ("MapDen.txt","w");
  for(;MapDenIt!=MapDenItEnd;++MapDenIt)
    {
      //cout << "run , N : " << MapDenIt->first << " " << MapDenIt->second << endl;
      sumDen += MapDenIt->second;
      cout << "MAPDEN: " << MapDenIt->first << " " << MapDenIt->second << " " << sqrt(MapDenIt->second) << endl;
      //fprintf (pFileDen, "%d %d %f\n",MapDenIt->first,MapDenIt->second,sqrt(MapDenIt->second));
    }
  //fclose (pFileDen);

  map<int,int>::iterator MapNumIt = MapNum.begin();
  map<int,int>::iterator MapNumErrSquareIt = MapNumErrSquare.begin();
  map<int,int>::iterator MapNumItEnd = MapNum.end();
  int sumNum = 0 ;
  float sumNumErrSquare = 0. ;
  //   FILE * pFileNum;
  //   pFileNum = fopen ("MapNum.txt","w");
  for(;MapNumIt!=MapNumItEnd;++MapNumIt)
    {            
      //cout << "run , N : " << MapNumIt->first << " " << MapNumIt->second << endl;
      sumNum += MapNumIt->second;
      sumNumErrSquare += MapNumErrSquareIt->second;
      cout << "MAPNUM: " << MapNumIt->first << " " << MapNumIt->second << " " << sqrt(MapNumErrSquareIt->second) << endl;
      //fprintf (pFileNum, "%d %d %f\n",MapNumIt->first,MapNumIt->second,sqrt(MapNumErrSquareIt->second));
      ++MapNumErrSquareIt;
    }
  //fclose (pFileNum);

  double eff = double(sumNum) / double(sumDen);

  cout << "sumTrg : " << sumTrg << endl;
  cout << "sumDen : " << sumDen << endl;
  cout << "sumNum +/- err: " << sumNum << " +/- " << sqrt(sumNumErrSquare) << endl;
  cout << "eff : "    << eff    << endl; 

  /*//------------------------------------------------------------------
   *
   *
   *      
   *      End analysis loop!
   *
   *
   *
   *///-----------------------------------------------------------------

  STDOUT("analysisClass::Loop() ends");
}
void analysisClass::Loop()
{
   std::cout << "analysisClass::Loop() begins" <<std::endl;   
    
   if (fChain == 0) return;
   
   //////////book histos here
   TH2F *h_RelDeltaP_vs_trkP_top = new TH2F ("h_RelDeltaP_vs_trkP_top","h_RelDeltaP_vs_trkP_top",500,0,500,500,-10,10);
   TH2F *h_RelDeltaP_vs_trkP_bottom = new TH2F ("h_RelDeltaP_vs_trkP_bottom","h_RelDeltaP_vs_trkP_bottom",500,0,500,500,-10,10);

   TH2F *h_muonDTP_vs_trkP_top = new TH2F ("h_muonDTP_vs_trkP_top","h_muonDTP_vs_trkP_top",500,0,500,500,0,500);
   TH2F *h_muonDTP_vs_trkP_bottom = new TH2F ("h_muonDTP_vs_trkP_bottom","h_muonDTP_vs_trkP_bottom",500,0,500,500,0,500);

#ifdef USE_EXAMPLE
   STDOUT("WARNING: using example code. In order NOT to use it, comment line that defines USE_EXAMPLE flag in Makefile.");   
   // number of electrons
   TH1F *h_nEleFinal = new TH1F ("h_nEleFinal","",11,-0.5,10.5);
   h_nEleFinal->Sumw2();
   //pT 1st ele
   TH1F *h_pT1stEle = new TH1F ("h_pT1stEle","",100,0,1000);
   h_pT1stEle->Sumw2();
   //pT 2nd ele
   TH1F *h_pT2ndEle = new TH1F ("h_pT2ndEle","",100,0,1000);
   h_pT2ndEle->Sumw2();

#endif //end of USE_EXAMPLE

   /////////initialize variables

   Long64_t nentries = fChain->GetEntriesFast();
   std::cout << "analysisClass::Loop(): nentries = " << nentries << std::endl;   

   ////// The following ~7 lines have been taken from rootNtupleClass->Loop() /////
   ////// If the root version is updated and rootNtupleClass regenerated,     /////
   ////// these lines may need to be updated.                                 /////    
   Long64_t nbytes = 0, nb = 0;
   for (Long64_t jentry=0; jentry<nentries;jentry++) {
     Long64_t ientry = LoadTree(jentry);
     if (ientry < 0) break;
     nb = fChain->GetEntry(jentry);   nbytes += nb;
     if(jentry < 10 || jentry%1000 == 0) std::cout << "analysisClass::Loop(): jentry = " << jentry << std::endl;   
     // if (Cut(ientry) < 0) continue;

     ////////////////////// User's code starts here ///////////////////////

     ///Stuff to be done every event

#ifdef USE_EXAMPLE
     // Electrons
     vector<int> v_idx_ele_final;
     for(int iele=0;iele<eleCount;iele++)
       {
	 // ECAL barrel fiducial region
	 bool pass_ECAL_FR=false;
	 if( fabs(eleEta[iele]) < getPreCutValue1("eleFidRegion") )	v_idx_ele_final.push_back(iele);
       }     

     // Set the evaluation of the cuts to false and clear the variable values and filled status
     resetCuts();
     
     // Set the value of the variableNames listed in the cutFile to their current value
     fillVariableWithValue("nEleFinal", v_idx_ele_final.size()) ;
     if( v_idx_ele_final.size() >= 1 ) 
       {
	 fillVariableWithValue( "pT1stEle", elePt[v_idx_ele_final[0]] );
       }
     if( v_idx_ele_final.size() >= 2 ) 
       {
	 fillVariableWithValue( "pT2ndEle", elePt[v_idx_ele_final[1]] );
	 // Calculate Mee
	 TLorentzVector v_ee, ele1, ele2;
	 ele1.SetPtEtaPhiM(elePt[v_idx_ele_final[0]],eleEta[v_idx_ele_final[0]],elePhi[v_idx_ele_final[0]],0);
	 ele2.SetPtEtaPhiM(elePt[v_idx_ele_final[1]],eleEta[v_idx_ele_final[1]],elePhi[v_idx_ele_final[1]],0);
	 v_ee = ele1 + ele2;
	 fillVariableWithValue( "invMass_ee", v_ee.M() ) ;
       }

     // Evaluate cuts (but do not apply them)
     evaluateCuts();
     
     // Fill histograms and do analysis based on cut evaluation
     h_nEleFinal->Fill(v_idx_ele_final.size());
     //if( v_idx_ele_final.size()>=1 ) h_pT1stEle->Fill(elePt[v_idx_ele_final[0]]);
     //if( v_idx_ele_final.size()>=2 && (elePt[v_idx_ele_final[0]])>85 ) h_pT2ndEle->Fill(elePt[v_idx_ele_final[1]]);
     if( passedCut("pT1stEle") ) h_pT1stEle->Fill(elePt[v_idx_ele_final[0]]);
     if( passedCut("pT2ndEle") ) h_pT2ndEle->Fill(elePt[v_idx_ele_final[1]]);
     
     // reject events that did not pass level 0 cuts
     if( !passedCut("0") ) continue;
     // ......
     
     // reject events that did not pass level 1 cuts
     if( !passedCut("1") ) continue;
     // ......

     // reject events that did not pass the full cut list
     if( !passedCut("all") ) continue;
     // ......

#endif  // end of USE_EXAMPLE

     //########### My code here #############
     // Set the evaluation of the cuts to false and clear the variable values and filled status
     resetCuts();

     double LenghtHB = getPreCutValue2("radiusHB") - getPreCutValue1("radiusHB");

     int n_DTtracksT=0;
     int n_DTtracksB=0;
     int n_DTtracksValidProp=0;
     for(int muon=0; muon<muonDTCount; muon++)
       {
	 if(muonDTYin[muon]>0 && muonDTYout[muon]>0)
	   n_DTtracksT++;

	 if(muonDTYin[muon]<0 && muonDTYout[muon]<0)
	   n_DTtracksB++;

	 if(muonDTisValidProp[muon]==1)
	   n_DTtracksValidProp++;
       }

     fillVariableWithValue( "N_DTtracks", muonDTCount );
     fillVariableWithValue( "N_DTtracksProp", n_DTtracksValidProp );
     fillVariableWithValue( "N_DTtracksT", n_DTtracksT );
     fillVariableWithValue( "N_DTtracksB", n_DTtracksB );
     fillVariableWithValue( "N_TRKtracks", trackCount );

     if( muonDTCount >=2  )
       {

	 int indexTOP=-1;
	 int indexBOTTOM=-1;
	 
	 if(muonDTYin[0]>0 && muonDTYout[0]>0)
	   {
	     indexTOP = 0;
	   }
	 else
	   if(muonDTYin[0]<0 && muonDTYout[0]<0)
	     {
	       indexBOTTOM = 0;
	     }

	 if(muonDTYin[1]>0 && muonDTYout[1]>0)
	   {
	     indexTOP = 1;
	   }
	 else
	   if(muonDTYin[1]<0 && muonDTYout[1]<0)
	     {
	       indexBOTTOM = 1;
	     }
	
	 if(indexTOP >= 0 && indexBOTTOM >= 0)
	   {
	     //top
	     fillVariableWithValue( "muonTDXY_DT_TRK", muonDTnrstTrkDXY[indexTOP] );
	     fillVariableWithValue( "muonTDZ_DT_TRK", muonDTnrstTrkDZ[indexTOP] );
	     fillVariableWithValue( "muonTDTNHits", muonDTNumRecHits[indexTOP] );
	     fillVariableWithValue( "muonTDTNValidHits", muonDTNumValidRecHits[indexTOP] );
	     fillVariableWithValue( "muonTDTEtaAtHB", max(muonDTEtaAtInHB[indexTOP],muonDTEtaAtOutHB[indexTOP]) );
	     fillVariableWithValue( "muonTDTPhiAtHB", max(muonDTPhiAtInHB[indexTOP],muonDTPhiAtOutHB[indexTOP]) );
	     fillVariableWithValue( "muonTDTLenghtHB", muonDTLengthInHB[indexTOP] );
	     fillVariableWithValue( "muonTDTdRHitMuInHB", muonDTdeltaRatInHB[indexTOP] );
	     fillVariableWithValue( "muonTDTdRHitMuOutHB", muonDTdeltaRatOutHB[indexTOP] );
	     fillVariableWithValue( "muonTDTEnergy", muonDTTotEnergy[indexTOP] );
	     double normEnergyTOP = (muonDTTotEnergy[indexTOP] / muonDTLengthInHB[indexTOP]) * LenghtHB; 
	     fillVariableWithValue( "muonTDTEnergyNorm", normEnergyTOP );
	     fillVariableWithValue( "muonTDTNCells", muonDTNumCells[indexTOP] );
	     fillVariableWithValue( "muonTDTCellSameEta", muonDTHaveCellsSameEta[indexTOP] );
	     fillVariableWithValue( "muonTDTCellSamePhi", muonDTHaveCellsSamePhi[indexTOP] );
	     if(muonDTHaveCellsSameEta[indexTOP] || muonDTHaveCellsSamePhi[indexTOP])
	       fillVariableWithValue( "muonTDTCellSmEtaOrPhi", 1 );
	     fillVariableWithValue( "muonTDTP", muonDTP[indexTOP] );
	     fillVariableWithValue( "muonTDTPt", muonDTPt[indexTOP] );

	     if(muonDTnrstTrkIdx[indexTOP]>=0)
	       {
		 fillVariableWithValue( "muonTDTtrkChi2", trackChi2[muonDTnrstTrkIdx[indexTOP]] );
		 fillVariableWithValue( "muonTDTtrkNdof", trackNdof[muonDTnrstTrkIdx[indexTOP]] );
		 fillVariableWithValue( "muonTDTtrkNrmChi2", trackChi2[muonDTnrstTrkIdx[indexTOP]]/trackNdof[muonDTnrstTrkIdx[indexTOP]] );
		 fillVariableWithValue( "muonTDTtrkP", trackP[muonDTnrstTrkIdx[indexTOP]] );
		 fillVariableWithValue( "muonTDTtrkPt", trackPt[muonDTnrstTrkIdx[indexTOP]] );
		 double relDeltaP = ( muonDTP[indexTOP] - trackP[muonDTnrstTrkIdx[indexTOP]] ) / trackP[muonDTnrstTrkIdx[indexTOP]];
		 double relDeltaPt = ( muonDTPt[indexTOP] - trackPt[muonDTnrstTrkIdx[indexTOP]] ) / trackPt[muonDTnrstTrkIdx[indexTOP]];
		 fillVariableWithValue( "muonTDTtrkRelDeltaP", relDeltaP );
		 fillVariableWithValue( "muonTDTtrkRelDeltaPt", relDeltaPt );
	       }

	     //bottom
	     fillVariableWithValue( "muonBDXY_DT_TRK", muonDTnrstTrkDXY[indexBOTTOM] );
	     fillVariableWithValue( "muonBDZ_DT_TRK", muonDTnrstTrkDZ[indexBOTTOM] );
	     fillVariableWithValue( "muonBDTNHits", muonDTNumRecHits[indexBOTTOM] );
	     fillVariableWithValue( "muonBDTNValidHits", muonDTNumValidRecHits[indexBOTTOM] );
	     fillVariableWithValue( "muonBDTEtaAtHB", max(muonDTEtaAtInHB[indexBOTTOM],muonDTEtaAtOutHB[indexBOTTOM]) );
	     fillVariableWithValue( "muonBDTPhiAtHB", max(muonDTPhiAtInHB[indexBOTTOM],muonDTPhiAtOutHB[indexBOTTOM]) );
	     fillVariableWithValue( "muonBDTLenghtHB", muonDTLengthInHB[indexBOTTOM] );	     
	     fillVariableWithValue( "muonBDTdRHitMuInHB", muonDTdeltaRatInHB[indexBOTTOM] );
	     fillVariableWithValue( "muonBDTdRHitMuOutHB", muonDTdeltaRatOutHB[indexBOTTOM] );
	     fillVariableWithValue( "muonBDTEnergy", muonDTTotEnergy[indexBOTTOM] );
	     double normEnergyBOTTOM = (muonDTTotEnergy[indexBOTTOM] / muonDTLengthInHB[indexBOTTOM]) * LenghtHB; 
	     fillVariableWithValue( "muonBDTEnergyNorm", normEnergyBOTTOM );
	     fillVariableWithValue( "muonBDTNCells", muonDTNumCells[indexBOTTOM] );
	     fillVariableWithValue( "muonBDTCellSameEta", muonDTHaveCellsSameEta[indexBOTTOM] );
	     fillVariableWithValue( "muonBDTCellSamePhi", muonDTHaveCellsSamePhi[indexBOTTOM] );
	     if(muonDTHaveCellsSameEta[indexBOTTOM] || muonDTHaveCellsSamePhi[indexBOTTOM])
	       fillVariableWithValue( "muonBDTCellSmEtaOrPhi", 1 );
	     fillVariableWithValue( "muonBDTP", muonDTP[indexBOTTOM] );
	     fillVariableWithValue( "muonBDTPt", muonDTPt[indexBOTTOM] );

	     if(muonDTnrstTrkIdx[indexBOTTOM]>=0)
	       {
		 fillVariableWithValue( "muonBDTtrkChi2", trackChi2[muonDTnrstTrkIdx[indexBOTTOM]] );
		 fillVariableWithValue( "muonBDTtrkNdof", trackNdof[muonDTnrstTrkIdx[indexBOTTOM]] );
		 fillVariableWithValue( "muonBDTtrkNrmChi2", trackChi2[muonDTnrstTrkIdx[indexBOTTOM]]/trackNdof[muonDTnrstTrkIdx[indexBOTTOM]] );
		 fillVariableWithValue( "muonBDTtrkP", trackP[muonDTnrstTrkIdx[indexBOTTOM]] );
		 fillVariableWithValue( "muonBDTtrkPt", trackPt[muonDTnrstTrkIdx[indexBOTTOM]] );
		 double relDeltaP = ( muonDTP[indexBOTTOM] - trackP[muonDTnrstTrkIdx[indexBOTTOM]] ) / trackP[muonDTnrstTrkIdx[indexBOTTOM]];
		 double relDeltaPt = ( muonDTPt[indexBOTTOM] - trackPt[muonDTnrstTrkIdx[indexBOTTOM]] ) / trackPt[muonDTnrstTrkIdx[indexBOTTOM]];
		 fillVariableWithValue( "muonBDTtrkRelDeltaP", relDeltaP );
		 fillVariableWithValue( "muonBDTtrkRelDeltaPt", relDeltaPt );
	       }
	   }
       
       }

     // Evaluate cuts (but do not apply them)
     evaluateCuts();

     if( passedCut("0") && passedCut("1") &&  passedCut("2") && passedCut("3") && passedCut("4") ) 
       { 
	 if( muonDTCount >=2  )
	   {
	   
	     int indexTOP=-1;
	     int indexBOTTOM=-1;
	   
	     if(muonDTYin[0]>0 && muonDTYout[0]>0)
	       indexTOP = 0;
	     else
	       if(muonDTYin[0]<0 && muonDTYout[0]<0)
		 indexBOTTOM = 0;
	     if(muonDTYin[1]>0 && muonDTYout[1]>0)
	       indexTOP = 1;
	     else
	       if(muonDTYin[1]<0 && muonDTYout[1]<0)
		 indexBOTTOM = 1;

	     if(indexTOP >= 0 && indexBOTTOM >= 0)
	       {
		 if(muonDTnrstTrkIdx[indexTOP]>=0)
		   {
		     double relDeltaP = ( muonDTP[indexTOP] - trackP[muonDTnrstTrkIdx[indexTOP]] ) / trackP[muonDTnrstTrkIdx[indexTOP]];
		     h_RelDeltaP_vs_trkP_top->Fill(trackP[muonDTnrstTrkIdx[indexTOP]] , relDeltaP);
		     h_muonDTP_vs_trkP_top->Fill(trackP[muonDTnrstTrkIdx[indexTOP]] , muonDTP[indexTOP]);
		   }
	     
		 if(muonDTnrstTrkIdx[indexBOTTOM]>=0)
		   {
		     double relDeltaP = ( muonDTP[indexBOTTOM] - trackP[muonDTnrstTrkIdx[indexBOTTOM]] ) / trackP[muonDTnrstTrkIdx[indexBOTTOM]];
		     h_RelDeltaP_vs_trkP_bottom->Fill(trackP[muonDTnrstTrkIdx[indexBOTTOM]] , relDeltaP);
		     h_muonDTP_vs_trkP_bottom->Fill(trackP[muonDTnrstTrkIdx[indexBOTTOM]] , muonDTP[indexBOTTOM]);
		   }
	       }
	   }
       }
     
     ////////////////////// User's code ends here ///////////////////////

   } // End loop over events

   //////////write histos 


#ifdef USE_EXAMPLE
   STDOUT("WARNING: using example code. In order NOT to use it, comment line that defines USE_EXAMPLE flag in Makefile.");   

   h_nEleFinal->Write();
   h_pT1stEle->Write();
   h_pT2ndEle->Write();

   //pT of both electrons, to be built using the histograms produced automatically by baseClass
   TH1F * h_pTElectrons = new TH1F ("h_pTElectrons","", getHistoNBins("pT1stEle"), getHistoMin("pT1stEle"), getHistoMax("pT1stEle"));
   h_pTElectrons->Add( & getHisto_noCuts_or_skim("pT1stEle") ); // all histos can be retrieved, see other getHisto_xxxx methods in baseClass.h
   h_pTElectrons->Add( & getHisto_noCuts_or_skim("pT2ndEle") );
   //one could also do:  *h_pTElectrons = getHisto_noCuts_or_skim("pT1stEle") + getHisto_noCuts_or_skim("pT2ndEle");
   h_pTElectrons->Write();
   //one could also do:   const TH1F& h = getHisto_noCuts_or_skim// and use h
#endif // end of USE_EXAMPLE

   h_RelDeltaP_vs_trkP_top->Write();
   h_RelDeltaP_vs_trkP_bottom->Write();
   h_muonDTP_vs_trkP_top->Write();
   h_muonDTP_vs_trkP_bottom->Write();
		 
   std::cout << "analysisClass::Loop() ends" <<std::endl;   
}
Ejemplo n.º 22
0
void baseClass::readCutFile()
{
  string s;
  STDOUT("Reading cutFile_ = "<< *cutFile_)

  ifstream is(cutFile_->c_str());
  if(is.good())
    {
      //      STDOUT("Reading file: " << *cutFile_ );
      int id=0;
      while( getline(is,s) )
        {
          STDOUT("read line: " << s);
          if (s[0] == '#') continue;
	  vector<string> v = split(s);
	  map<string, cut>::iterator cc = cutName_cut_.find(v[0]);
	  if( cc != cutName_cut_.end() )
	    {
	      STDOUT("ERROR: variableName = "<< v[0] << " exists already in cutName_cut_. Returning.");
	      return;
	    } 

	  int level_int = atoi( v[5].c_str() );
	  if(level_int == -1)
	    {
	      map<string, preCut>::iterator cc = preCutName_cut_.find(v[0]);
	      if( cc != preCutName_cut_.end() )
		{
		  STDOUT("ERROR: variableName = "<< v[0] << " exists already in preCutName_cut_. Returning.");
		  return;
		} 
	      preCutInfo_ << "### Preliminary cut values: " << s <<endl;
	      preCut thisPreCut;
	      thisPreCut.variableName =     v[0];
	      thisPreCut.value1  = decodeCutValue( v[1] );
	      thisPreCut.value2  = decodeCutValue( v[2] );
	      thisPreCut.value3  = decodeCutValue( v[3] );
	      thisPreCut.value4  = decodeCutValue( v[4] );
	      preCutName_cut_[thisPreCut.variableName]=thisPreCut;
	      continue;
	    }
	  cut thisCut;
	  thisCut.variableName =     v[0];
	  string m1=v[1];
	  string M1=v[2];
	  string m2=v[3];
	  string M2=v[4];
	  if( m1=="-" || M1=="-" ) 
	    {
	      STDOUT("ERROR: minValue1 and maxValue2 have to be provided. Returning."); 
	      return; // FIXME implement exception
	    } 
	  if( (m2=="-" && M2!="-") || (m2!="-" && M2=="-") ) 
	    {
	      STDOUT("ERROR: if any of minValue2 and maxValue2 is -, then both have to be -. Returning");
	      return; // FIXME implement exception
	    }
	  if( m2=="-") m2="+inf";
	  if( M2=="-") M2="-inf";
	  thisCut.minValue1  = decodeCutValue( m1 );
	  thisCut.maxValue1  = decodeCutValue( M1 );
	  thisCut.minValue2  = decodeCutValue( m2 );
	  thisCut.maxValue2  = decodeCutValue( M2 );
	  thisCut.level_int  = level_int;
	  thisCut.level_str  =       v[5];
	  thisCut.histoNBins = atoi( v[6].c_str() );
	  thisCut.histoMin   = atof( v[7].c_str() );
	  thisCut.histoMax   = atof( v[8].c_str() );
	  // Not filled from file
	  thisCut.id=++id;
	  string s1;
	  if(skimWasMade_)
	    {
	      s1 = "cutHisto_skim___________________" + thisCut.variableName;
	    }
	  else
	    {
	      s1 = "cutHisto_noCuts_________________" + thisCut.variableName;
	    }
	  string s2 = "cutHisto_allPreviousCuts________" + thisCut.variableName;
	  string s3 = "cutHisto_allOthrSmAndLwrLvlCuts_" + thisCut.variableName;
	  string s4 = "cutHisto_allOtherCuts___________" + thisCut.variableName;
	  string s5 = "cutHisto_allCuts________________" + thisCut.variableName;
	  thisCut.histo1 = TH1F (s1.c_str(),"", thisCut.histoNBins, thisCut.histoMin, thisCut.histoMax);
	  thisCut.histo2 = TH1F (s2.c_str(),"", thisCut.histoNBins, thisCut.histoMin, thisCut.histoMax);
	  thisCut.histo3 = TH1F (s3.c_str(),"", thisCut.histoNBins, thisCut.histoMin, thisCut.histoMax);
	  thisCut.histo4 = TH1F (s4.c_str(),"", thisCut.histoNBins, thisCut.histoMin, thisCut.histoMax);
	  thisCut.histo5 = TH1F (s5.c_str(),"", thisCut.histoNBins, thisCut.histoMin, thisCut.histoMax);
	  thisCut.histo1.Sumw2();
	  thisCut.histo2.Sumw2();
	  thisCut.histo3.Sumw2();
	  thisCut.histo4.Sumw2();
	  thisCut.histo5.Sumw2();
	  // Filled event by event
	  thisCut.filled = false;
	  thisCut.value = 0;
	  thisCut.passed = false;
	  thisCut.nEvtInput=0;
	  thisCut.nEvtPassed=0;

	  orderedCutNames_.push_back(thisCut.variableName);
	  cutName_cut_[thisCut.variableName]=thisCut;

	}
      STDOUT( "baseClass::readCutFile: Finished reading cutFile: " << *cutFile_ );
    }
  else
    {
      STDOUT("ERROR opening cutFile:" << *cutFile_ );
      exit (1);
    }
  is.close();

}
void analysisClass::Loop()
{
  //STDOUT("analysisClass::Loop() begins");

  if (fChain == 0) return;

  /*//------------------------------------------------------------------
   *
   *
   *      
   *      Get all Pre-cut values!
   *
   *
   *
   *///-----------------------------------------------------------------
  
   //--------------------------------------------------------------------------
   // Decide which plots to save (default is to save everything)
   //--------------------------------------------------------------------------
   
   fillSkim                         ( !true  ) ;
   fillAllPreviousCuts              ( !true  ) ;
   fillAllOtherCuts                 ( !true  ) ;
   fillAllSameLevelAndLowerLevelCuts( !true  ) ;
   fillAllCuts                      ( !true  ) ;


  //-----------------------------------------------------------------
  // Electron cut values
  //-----------------------------------------------------------------
  
  double ele_PtCut_STORE = getPreCutValue2("ele_PtCut");
  double ele_PtCut_ANA   = getPreCutValue1("ele_PtCut");
  
  double eleEta_bar      = getPreCutValue1("eleEta_bar");
  double eleEta_end_min  = getPreCutValue1("eleEta_end");
  double eleEta_end_max  = getPreCutValue2("eleEta_end");
  
  if ( ele_PtCut_STORE > ele_PtCut_ANA ) {
    STDOUT("ERROR in Electron cut values: all storage cuts must be looser or equal to analysis cuts.");
    exit(0) ;
  }

  // For WP80

  double eleMissingHitsWP             = getPreCutValue1("eleMissingHitsWP"        );
  double eleDistWP                    = getPreCutValue1("eleDistWP"               );
  double eleDCotThetaWP               = getPreCutValue1("eleDCotThetaWP"          );
  double eleCombRelIsoWP_bar          = getPreCutValue1("eleCombRelIsoWP"         );
  double eleCombRelIsoWP_end          = getPreCutValue2("eleCombRelIsoWP"         );
  double eleSigmaIetaIetaWP_bar       = getPreCutValue1("eleSigmaIetaIetaWP"      );
  double eleSigmaIetaIetaWP_end       = getPreCutValue2("eleSigmaIetaIetaWP"      );
  double eleDeltaPhiTrkSCWP_bar       = getPreCutValue1("eleDeltaPhiTrkSCWP"      );
  double eleDeltaPhiTrkSCWP_end       = getPreCutValue2("eleDeltaPhiTrkSCWP"      );
  double eleDeltaEtaTrkSCWP_bar       = getPreCutValue1("eleDeltaEtaTrkSCWP"      );
  double eleDeltaEtaTrkSCWP_end       = getPreCutValue2("eleDeltaEtaTrkSCWP"      );
  double eleUseEcalDrivenWP           = getPreCutValue1("eleUseEcalDrivenWP"      );
  double eleUseHasMatchConvWP         = getPreCutValue1("eleUseHasMatchConvWP"    );

  // For HEEP 3.1

  double eleDeltaEtaTrkSCHeep_bar     = getPreCutValue1("eleDeltaEtaTrkSCHeep"    );
  double eleDeltaEtaTrkSCHeep_end     = getPreCutValue2("eleDeltaEtaTrkSCHeep"    );
  double eleDeltaPhiTrkSCHeep_bar     = getPreCutValue1("eleDeltaPhiTrkSCHeep"    );
  double eleDeltaPhiTrkSCHeep_end     = getPreCutValue2("eleDeltaPhiTrkSCHeep"    );
  double eleHoEHeep_bar               = getPreCutValue1("eleHoEHeep"              );
  double eleHoEHeep_end               = getPreCutValue2("eleHoEHeep"              );
  double eleE2x5OverE5x5Heep_bar      = getPreCutValue1("eleE2x5OverE5x5Heep"     );
  double eleE1x5OverE5x5Heep_bar      = getPreCutValue1("eleE1x5OverE5x5Heep"     );
  double eleSigmaIetaIetaHeep_end     = getPreCutValue2("eleSigmaIetaIetaHeep"    );
  double eleEcalHcalIsoHeep_1_bar     = getPreCutValue1("eleEcalHcalIsoHeep"      );
  double eleEcalHcalIsoHeep_2_bar     = getPreCutValue2("eleEcalHcalIsoHeep"      );
  double eleEcalHcalIsoHeep_1_end     = getPreCutValue3("eleEcalHcalIsoHeep"      );
  double eleEcalHcalIsoHeep_2_end     = getPreCutValue4("eleEcalHcalIsoHeep"      );
  double eleEcalHcalIsoHeep_PTthr_end = getPreCutValue2("eleEcalHcalIsoHeep_PTthr");
  double eleHcalIsoD2Heep_end         = getPreCutValue2("eleHcalIsoD2Heep"        );
  double eleTrkIsoHeep_bar            = getPreCutValue1("eleTrkIsoHeep"           );
  double eleTrkIsoHeep_end            = getPreCutValue2("eleTrkIsoHeep"           );
  double eleMissingHitsHeep           = getPreCutValue1("eleMissingHitsHeep"      );
  double eleUseEcalDrivenHeep         = getPreCutValue1("eleUseEcalDrivenHeep"    );

  // For HEEP 3.2

  double eleDeltaEtaTrkSCHeep32_bar     = getPreCutValue1("eleDeltaEtaTrkSCHeep32"    );
  double eleDeltaEtaTrkSCHeep32_end     = getPreCutValue2("eleDeltaEtaTrkSCHeep32"    );
  double eleDeltaPhiTrkSCHeep32_bar     = getPreCutValue1("eleDeltaPhiTrkSCHeep32"    );
  double eleDeltaPhiTrkSCHeep32_end     = getPreCutValue2("eleDeltaPhiTrkSCHeep32"    );
  double eleHoEHeep32_bar               = getPreCutValue1("eleHoEHeep32"              );
  double eleHoEHeep32_end               = getPreCutValue2("eleHoEHeep32"              );
  double eleE2x5OverE5x5Heep32_bar      = getPreCutValue1("eleE2x5OverE5x5Heep32"     );
  double eleE1x5OverE5x5Heep32_bar      = getPreCutValue1("eleE1x5OverE5x5Heep32"     );
  double eleSigmaIetaIetaHeep32_end     = getPreCutValue2("eleSigmaIetaIetaHeep32"    );
  double eleEcalHcalIsoHeep32_1_bar     = getPreCutValue1("eleEcalHcalIsoHeep32"      );
  double eleEcalHcalIsoHeep32_2_bar     = getPreCutValue2("eleEcalHcalIsoHeep32"      );
  double eleEcalHcalIsoHeep32_1_end     = getPreCutValue3("eleEcalHcalIsoHeep32"      );
  double eleEcalHcalIsoHeep32_2_end     = getPreCutValue4("eleEcalHcalIsoHeep32"      );
  double eleEcalHcalIsoHeep32_PTthr_end = getPreCutValue2("eleEcalHcalIsoHeep32_PTthr");
  //double eleHcalIsoD2Heep32_end         = getPreCutValue2("eleHcalIsoD2Heep32"        );
  double eleTrkIsoHeep32_bar            = getPreCutValue1("eleTrkIsoHeep32"           );
  double eleTrkIsoHeep32_end            = getPreCutValue2("eleTrkIsoHeep32"           );
  double eleMissingHitsHeep32           = getPreCutValue1("eleMissingHitsHeep32"      );
  double eleUseEcalDrivenHeep32         = getPreCutValue1("eleUseEcalDrivenHeep32"    );

  //-----------------------------------------------------------------
  // Vertex cut values
  //-----------------------------------------------------------------

  double vertexMinimumNDOF = getPreCutValue1("vertexMinimumNDOF");
  double vertexMaxAbsZ     = getPreCutValue1("vertexMaxAbsZ");
  double vertexMaxd0       = getPreCutValue1("vertexMaxd0");

  //-----------------------------------------------------------------
  // Which algorithms to use?
  //-----------------------------------------------------------------

  int    eleAlgorithm = (int) getPreCutValue1("eleAlgorithm");

  //-----------------------------------------------------------------
  // Counters
  //-----------------------------------------------------------------
  int    N_probe_PassEleOffline = 0;
  int    N_probe_PassEleOfflineAndWP80 = 0;
  int    N_probe_PassEleOfflineAndTag = 0;  

  int    N_probe_PassEleOffline_bar = 0;
  int    N_probe_PassEleOfflineAndWP80_bar = 0;
  int    N_probe_PassEleOfflineAndTag_bar = 0;  

  int    N_probe_PassEleOffline_end = 0;
  int    N_probe_PassEleOfflineAndWP80_end = 0;
  int    N_probe_PassEleOfflineAndTag_end = 0;  

  //Histograms
  CreateUserTH1D("eta_recoEleMatchProbe_PassEleOffline", 50, -5, 5);
  CreateUserTH1D("pt_recoEleMatchProbe_PassEleOffline", 40, 0, 200);			
  CreateUserTH1D("NPV_recoEleMatchProbe_PassEleOffline", 50, 0, 50);			
  CreateUserTH1D("NPV_recoEleMatchProbe_PassEleOffline_bar", 50, 0, 50);			
  CreateUserTH1D("NPV_recoEleMatchProbe_PassEleOffline_end", 50, 0, 50);			

  CreateUserTH1D("eta_recoEleMatchProbe_PassEleOfflineAndWP80", 50, -5, 5);
  CreateUserTH1D("pt_recoEleMatchProbe_PassEleOfflineAndWP80", 40, 0, 200);			
  CreateUserTH1D("NPV_recoEleMatchProbe_PassEleOfflineAndWP80", 50, 0, 50);			
  CreateUserTH1D("NPV_recoEleMatchProbe_PassEleOfflineAndWP80_bar", 50, 0, 50);			
  CreateUserTH1D("NPV_recoEleMatchProbe_PassEleOfflineAndWP80_end", 50, 0, 50);			

  CreateUserTH1D("eta_recoEleMatchProbe_PassEleOfflineAndTag", 50, -5, 5);
  CreateUserTH1D("pt_recoEleMatchProbe_PassEleOfflineAndTag", 40, 0, 200);			
  CreateUserTH1D("NPV_recoEleMatchProbe_PassEleOfflineAndTag", 50, 0, 50);			
  CreateUserTH1D("NPV_recoEleMatchProbe_PassEleOfflineAndTag_bar", 50, 0, 50);			
  CreateUserTH1D("NPV_recoEleMatchProbe_PassEleOfflineAndTag_end", 50, 0, 50);			

  /*//------------------------------------------------------------------
   *
   *
   *      
   *      Start analysis loop!
   *
   *
   *
   *///-----------------------------------------------------------------


  Long64_t nentries = fChain->GetEntries();
  //Long64_t nentries = 100000;
  STDOUT("analysisClass::Loop(): nentries = " << nentries);

  Long64_t nbytes = 0, nb = 0;
  for (Long64_t jentry=0; jentry<nentries;jentry++) { // Begin of loop over events
    Long64_t ientry = LoadTree(jentry);
    if (ientry < 0) break;
    nb = fChain->GetEntry(jentry);   nbytes += nb;
    if(jentry < 10 || jentry%1000 == 0) STDOUT("analysisClass::Loop(): jentry = " << jentry << "/" << nentries );
    
    //-----------------------------------------------------------------
    // Do pileup re-weighting, if necessary
    //  --> To be done after the skim, so commented out for now
    //-----------------------------------------------------------------
    
    // double event_weight = getPileupWeight ( PileUpInteractions, isData ) ;
    
    //-----------------------------------------------------------------
    // Get trigger information, if necessary
    //-----------------------------------------------------------------

    if ( isData ) { 
      getTriggers ( HLTKey, HLTInsideDatasetTriggerNames, HLTInsideDatasetTriggerDecisions,  HLTInsideDatasetTriggerPrescales ) ;
    }
    
    //-----------------------------------------------------------------
    // Selection: Electrons
    //-----------------------------------------------------------------    

    vector<int> v_idx_ele_PtCut_IDISO_STORE;
    vector<int> v_idx_ele_PtCut_IDISO_ANA;
    vector<int> v_idx_ele_IDISO;

    //Loop over electrons
    for(int iele=0; iele<ElectronPt->size(); iele++){
      
      int passEleSel = 0;
      int isBarrel = 0;
      int isEndcap = 0;
      
      if( fabs( ElectronSCEta->at(iele) ) < eleEta_bar )       isBarrel = 1;
      if( fabs( ElectronSCEta->at(iele) ) > eleEta_end_min &&
	  fabs( ElectronSCEta->at(iele) ) < eleEta_end_max )   isEndcap = 1;

      //-----------------------------------------------------------------    
      // HEEP ID application 3.1
      //-----------------------------------------------------------------    

      if ( eleAlgorithm == 1 ) { 
	
	if(isBarrel) {		

	  if(   fabs(ElectronDeltaEtaTrkSC->at(iele)) < eleDeltaEtaTrkSCHeep_bar 
		&& fabs(ElectronDeltaPhiTrkSC->at(iele)) < eleDeltaPhiTrkSCHeep_bar 
		&& ElectronHoE->at(iele) < eleHoEHeep_bar 
		&& (ElectronE2x5OverE5x5->at(iele) >eleE2x5OverE5x5Heep_bar || ElectronE1x5OverE5x5->at(iele) > eleE1x5OverE5x5Heep_bar ) 
		&& ( ElectronEcalIsoDR03->at(iele)+ElectronHcalIsoD1DR03->at(iele) ) < eleEcalHcalIsoHeep_1_bar + eleEcalHcalIsoHeep_2_bar*ElectronPt->at(iele)
		&& ElectronTrkIsoDR03->at(iele) <eleTrkIsoHeep_bar 
		&& ElectronMissingHits->at(iele) == 0 
		&& ElectronHasEcalDrivenSeed->at(iele)
	     )
	    passEleSel = 1;		

	}//end barrel
	
	if(isEndcap) {		
	  
	  int passEcalHcalIsoCut=0;
	  if(ElectronPt->at(iele) < eleEcalHcalIsoHeep_PTthr_end && 
	     (ElectronEcalIsoDR03->at(iele)+ElectronHcalIsoD1DR03->at(iele)) < eleEcalHcalIsoHeep_1_end) 
	    passEcalHcalIsoCut=1;
	  if(ElectronPt->at(iele) > eleEcalHcalIsoHeep_PTthr_end && 
	     (ElectronEcalIsoDR03->at(iele)+ElectronHcalIsoD1DR03->at(iele)) < eleEcalHcalIsoHeep_1_end+eleEcalHcalIsoHeep_2_end*(ElectronPt->at(iele)-eleEcalHcalIsoHeep_PTthr_end) ) 
	    passEcalHcalIsoCut=1;
	  
	  if(fabs(ElectronDeltaEtaTrkSC->at(iele)) < eleDeltaEtaTrkSCHeep_end 
	     && fabs(ElectronDeltaPhiTrkSC->at(iele)) < eleDeltaPhiTrkSCHeep_end 
	     && ElectronHoE->at(iele) < eleHoEHeep_end 
	     && ElectronSigmaIEtaIEta->at(iele) < eleSigmaIetaIetaHeep_end 
	     && passEcalHcalIsoCut == 1
	     && ElectronHcalIsoD2DR03->at(iele) < eleHcalIsoD2Heep_end 
	     && ElectronTrkIsoDR03->at(iele) < eleTrkIsoHeep_end 
	     && ElectronMissingHits->at(iele) == 0 
	     && ElectronHasEcalDrivenSeed->at(iele)
	     )
	    passEleSel = 1;
	  
	}//end endcap
      }

      //-----------------------------------------------------------------    
      // WP80 ID application
      //-----------------------------------------------------------------    

      else if ( eleAlgorithm == 2 ) { 
	// ecal driven	    
	if( eleUseEcalDrivenWP && !ElectronHasEcalDrivenSeed->at(iele) ) continue;
	
	// isolation
	double ElectronCombRelIsoWP_bar  =  ( ElectronTrkIsoDR03->at(iele) 
					    + max( 0., ElectronEcalIsoDR03->at(iele) - 1. ) 
					    + ElectronHcalIsoDR03FullCone->at(iele) 
					    - rhoIso*TMath::Pi()*0.3*0.3 
					    ) / ElectronPt->at(iele) ;
	
	double ElectronCombRelIsoWP_end  =  ( ElectronTrkIsoDR03->at(iele) 
					      + ElectronEcalIsoDR03->at(iele) 
					      + ElectronHcalIsoDR03FullCone->at(iele) 
					      - rhoIso*TMath::Pi()*0.3*0.3 
					      ) / ElectronPt->at(iele) ;
	
	// conversions
	int isPhotConv = 0;
	if(eleUseHasMatchConvWP) {
	  if( ElectronHasMatchedConvPhot->at(iele) ) 
	    isPhotConv = 1;
	}
	else {
	  if( ElectronDist->at(iele) < eleDistWP && ElectronDCotTheta->at(iele) < eleDCotThetaWP )	
	    isPhotConv = 1;
	}

	if(isBarrel) {
	  
	  if( ElectronMissingHits->at(iele) <= eleMissingHitsWP              && 
	      isPhotConv == 0					             && 
	      ElectronCombRelIsoWP_bar < eleCombRelIsoWP_bar		     && 
	      ElectronSigmaIEtaIEta->at(iele) < eleSigmaIetaIetaWP_bar       && 
	      fabs(ElectronDeltaPhiTrkSC->at(iele)) < eleDeltaPhiTrkSCWP_bar && 
	      fabs(ElectronDeltaEtaTrkSC->at(iele)) < eleDeltaEtaTrkSCWP_bar  )
	    passEleSel = 1;		
	  
	}//end barrel
	
	if(isEndcap) {		
	    
	  if( ElectronMissingHits->at(iele) == eleMissingHitsWP              && 
	      isPhotConv == 0						     && 
	      ElectronCombRelIsoWP_end < eleCombRelIsoWP_end		     && 
	      ElectronSigmaIEtaIEta->at(iele) < eleSigmaIetaIetaWP_end 	     && 
	      fabs(ElectronDeltaPhiTrkSC->at(iele)) < eleDeltaPhiTrkSCWP_end && 
	      fabs(ElectronDeltaEtaTrkSC->at(iele)) < eleDeltaEtaTrkSCWP_end  )
	    passEleSel = 1;		
	  
	}//end endcap	
      }

      //-----------------------------------------------------------------    
      // HEEP ID application 3.2
      //-----------------------------------------------------------------    

      else if ( eleAlgorithm == 3 ) { 
	
	if(isBarrel) {
		
	  if(   fabs(ElectronDeltaEtaTrkSC->at(iele)) < eleDeltaEtaTrkSCHeep32_bar 
		&& fabs(ElectronDeltaPhiTrkSC->at(iele)) < eleDeltaPhiTrkSCHeep32_bar 
		&& ElectronHoE->at(iele) < eleHoEHeep32_bar 
		&& (ElectronE2x5OverE5x5->at(iele) >eleE2x5OverE5x5Heep32_bar || ElectronE1x5OverE5x5->at(iele) > eleE1x5OverE5x5Heep32_bar ) 
		&& ( ElectronEcalIsoDR03->at(iele)+ElectronHcalIsoD1DR03->at(iele) ) < eleEcalHcalIsoHeep32_1_bar + eleEcalHcalIsoHeep32_2_bar*ElectronPt->at(iele)
		&& ElectronTrkIsoDR03->at(iele) <eleTrkIsoHeep32_bar 
		&& ElectronMissingHits->at(iele) == 0 
		&& ElectronHasEcalDrivenSeed->at(iele)
	     )
	    passEleSel = 1;		

	}//end barrel
	
	if(isEndcap) {		
	  
	  int passEcalHcalIsoCut=0;
	  if(ElectronPt->at(iele) < eleEcalHcalIsoHeep32_PTthr_end && 
	     (ElectronEcalIsoDR03->at(iele)+ElectronHcalIsoD1DR03->at(iele)) < eleEcalHcalIsoHeep32_1_end) 
	    passEcalHcalIsoCut=1;
	  if(ElectronPt->at(iele) > eleEcalHcalIsoHeep32_PTthr_end && 
	     (ElectronEcalIsoDR03->at(iele)+ElectronHcalIsoD1DR03->at(iele)) < eleEcalHcalIsoHeep32_1_end+eleEcalHcalIsoHeep32_2_end*(ElectronPt->at(iele)-eleEcalHcalIsoHeep32_PTthr_end) ) 
	    passEcalHcalIsoCut=1;
	  
	  if(fabs(ElectronDeltaEtaTrkSC->at(iele)) < eleDeltaEtaTrkSCHeep32_end 
	     && fabs(ElectronDeltaPhiTrkSC->at(iele)) < eleDeltaPhiTrkSCHeep32_end 
	     && ElectronHoE->at(iele) < eleHoEHeep32_end 
	     && ElectronSigmaIEtaIEta->at(iele) < eleSigmaIetaIetaHeep32_end 
	     && passEcalHcalIsoCut == 1
	     //&& ElectronHcalIsoD2DR03->at(iele) < eleHcalIsoD2Heep32_end 
	     && ElectronTrkIsoDR03->at(iele) < eleTrkIsoHeep32_end 
	     && ElectronMissingHits->at(iele) == 0 
	     && ElectronHasEcalDrivenSeed->at(iele)
	     )
	    passEleSel = 1;
	  
	}//end endcap
      }
      
      if ( passEleSel ) { 
	v_idx_ele_IDISO.push_back ( iele ) ;
	if ( ElectronPt -> at (iele) >= ele_PtCut_STORE ) v_idx_ele_PtCut_IDISO_STORE.push_back ( iele ) ;
	if ( ElectronPt -> at (iele) >= ele_PtCut_ANA   ) v_idx_ele_PtCut_IDISO_ANA  .push_back ( iele ) ;
      }

    }
    

    //-----------------------------------------------------------------
    // Selection: vertices
    //-----------------------------------------------------------------

    vector<int> v_idx_vertex_good;
    // loop over vertices
    for(int ivertex = 0; ivertex<VertexChi2->size(); ivertex++){
      if ( !(VertexIsFake->at(ivertex))
    	   && VertexNDF->at(ivertex) > vertexMinimumNDOF
    	   && fabs( VertexZ->at(ivertex) ) <= vertexMaxAbsZ
    	   && fabs( VertexRho->at(ivertex) ) <= vertexMaxd0 )
    	{
    	  v_idx_vertex_good.push_back(ivertex);
    	  //STDOUT("v_idx_vertex_good.size = "<< v_idx_vertex_good.size() );
    	}
    }

    //-----------------------------------------------------------------
    // Fill your single-object variables with values
    //-----------------------------------------------------------------

    // Set the evaluation of the cuts to false and clear the variable values and filled status
    resetCuts();
    
    fillVariableWithValue( "PassJSON", passJSON(run, ls, isData) );    
    // Set the value of the variableNames listed in the cutFile to their current value

    //event info
    fillVariableWithValue( "isData"   , isData     ) ;
    fillVariableWithValue( "bunch"    , bunch      ) ;
    fillVariableWithValue( "event"    , event      ) ;
    fillVariableWithValue( "ls"       , ls         ) ;
    fillVariableWithValue( "orbit"    , orbit      ) ;
    fillVariableWithValue( "run"      , run        ) ;

    // nVertex and pile-up
    fillVariableWithValue( "nVertex", VertexChi2->size() ) ;
    fillVariableWithValue( "nVertex_good", v_idx_vertex_good.size() ) ;

    // Trigger (L1 and HLT)
    if(isData==true)
      {
	fillVariableWithValue( "PassBPTX0", isBPTX0 ) ;
	fillVariableWithValue( "PassPhysDecl", isPhysDeclared ) ;

	bool PassHLT = false;
	if( triggerFired ("HLT_Ele32_CaloIdT_CaloIsoT_TrkIdT_TrkIsoT_SC17_v1") 
	    || triggerFired ("HLT_Ele32_CaloIdT_CaloIsoT_TrkIdT_TrkIsoT_SC17_v2") 
	    || triggerFired ("HLT_Ele32_CaloIdT_CaloIsoT_TrkIdT_TrkIsoT_SC17_v3") 
	    || triggerFired ("HLT_Ele32_CaloIdT_CaloIsoT_TrkIdT_TrkIsoT_SC17_v4") 
	    || triggerFired ("HLT_Ele32_CaloIdT_CaloIsoT_TrkIdT_TrkIsoT_SC17_v5") 
	    || triggerFired ("HLT_Ele32_CaloIdT_CaloIsoT_TrkIdT_TrkIsoT_SC17_v6") 
	    || triggerFired ("HLT_Ele32_CaloIdT_CaloIsoT_TrkIdT_TrkIsoT_SC17_v7") 
	    || triggerFired ("HLT_Ele32_CaloIdT_CaloIsoT_TrkIdT_TrkIsoT_SC17_v8") 
	    )
	  {
	    PassHLT = true;
	  }
	fillVariableWithValue( "PassHLT", PassHLT ) ;
      }
    else
      {
	fillVariableWithValue( "PassBPTX0", true ) ;
	fillVariableWithValue( "PassPhysDecl", true ) ;
	fillVariableWithValue( "PassHLT", true ) ;
      }


    //Event filters at RECO level
    fillVariableWithValue( "PassBeamScraping", !isBeamScraping ) ;
    fillVariableWithValue( "PassPrimaryVertex", isPrimaryVertex ) ;
    fillVariableWithValue( "PassHBHENoiseFilter", passHBHENoiseFilter ) ;
    fillVariableWithValue( "PassBeamHaloFilterLoose", passBeamHaloFilterLoose ) ;
    fillVariableWithValue( "PassBeamHaloFilterTight", passBeamHaloFilterTight ) ;
    fillVariableWithValue( "PassTrackingFailure", !isTrackingFailure ) ;
    fillVariableWithValue( "PassCaloBoundaryDRFilter", passCaloBoundaryDRFilter ) ;
    fillVariableWithValue( "PassEcalMaskedCellDRFilter", passEcalMaskedCellDRFilter ) ;
    
    // Evaluate cuts (but do not apply them)
    evaluateCuts();


    //Basic Event Selection
    if( passedCut("PassJSON") 
	&& passedCut("run")
	&& passedCut("PassBPTX0") 
	&& passedCut("PassBeamScraping") 
	&& passedCut("PassPrimaryVertex")
	&& passedCut("PassHBHENoiseFilter")
	&& passedCut("PassBeamHaloFilterTight") 
	&& passedCut("PassHLT")
	)
      {      
	//Loop over probes
	for(int iprobe=0; iprobe<HLTEle32CaloIdTCaloIsoTTrkIdTTrkIsoTSC17HEDoubleFilterPt->size(); iprobe++)
	  {

	    TLorentzVector probe;
	    probe.SetPtEtaPhiE(HLTEle32CaloIdTCaloIsoTTrkIdTTrkIsoTSC17HEDoubleFilterPt->at(iprobe),
			       HLTEle32CaloIdTCaloIsoTTrkIdTTrkIsoTSC17HEDoubleFilterEta->at(iprobe),
			       HLTEle32CaloIdTCaloIsoTTrkIdTTrkIsoTSC17HEDoubleFilterPhi->at(iprobe),
			       HLTEle32CaloIdTCaloIsoTTrkIdTTrkIsoTSC17HEDoubleFilterEnergy->at(iprobe)
			       );

	    int isProbeBarrel = 0;
	    int isProbeEndcap = 0;
	    
	    if( fabs( probe.Eta() ) < eleEta_bar )       isProbeBarrel = 1;
	    if( fabs( probe.Eta() ) > eleEta_end_min &&
		fabs( probe.Eta() ) < eleEta_end_max )   isProbeEndcap = 1;


	    CreateAndFillUserTH1D("Pt_Probe", 200, 0, 200, probe.Pt() );

	    //Loop over tags
 	    for(int itag=0; itag<HLTEle32CaloIdTCaloIsoTTrkIdTTrkIsoTEle17TrackIsolFilterPt->size(); itag++)
	      {

		TLorentzVector tag;
		tag.SetPtEtaPhiE(HLTEle32CaloIdTCaloIsoTTrkIdTTrkIsoTEle17TrackIsolFilterPt->at(itag),
				 HLTEle32CaloIdTCaloIsoTTrkIdTTrkIsoTEle17TrackIsolFilterEta->at(itag),
				 HLTEle32CaloIdTCaloIsoTTrkIdTTrkIsoTEle17TrackIsolFilterPhi->at(itag),
				 HLTEle32CaloIdTCaloIsoTTrkIdTTrkIsoTEle17TrackIsolFilterEnergy->at(itag)
				 );	    

		CreateAndFillUserTH1D("DR_ProbeVsTag", 100, 0, 10, probe.DeltaR(tag) );

		//-----------------
		//if the tag matches in DR with the probe --> move to the next tag candidate
		if( probe.DeltaR(tag) < 0.5) 
		  continue;
		//-----------------


		//Now we should have a good (tag-probe) pair

		bool IsProbeMatchedWithOfflineEle = false;
		bool IsProbeMatchedWithTriggerWP80 = false;
		bool IsProbeMatchedWithTriggerTag = false;
		bool IsTagMatchedWithOfflineEle = false;

		//Loop over offline electrons
		TLorentzVector RecoEleMatchedWithProbe;
		TLorentzVector RecoEleMatchedWithTag;
		for(int iele=0; iele<v_idx_ele_PtCut_IDISO_ANA.size(); iele++)
		  {
		    TLorentzVector ele;
		    ele.SetPtEtaPhiE( ElectronPt->at(v_idx_ele_PtCut_IDISO_ANA[iele]),
				      ElectronEta->at(v_idx_ele_PtCut_IDISO_ANA[iele]),
				      ElectronPhi->at(v_idx_ele_PtCut_IDISO_ANA[iele]),
				      ElectronEnergy->at(v_idx_ele_PtCut_IDISO_ANA[iele])
				      );	    
		    
		    CreateAndFillUserTH1D("DR_ProbeVsEle", 100, 0, 10, probe.DeltaR(ele) );
		    CreateAndFillUserTH1D("DR_TagVsEle", 100, 0, 10, tag.DeltaR(ele) );

		    if( probe.DeltaR(ele) < 0.2 )
		      {
			IsProbeMatchedWithOfflineEle = true;
			RecoEleMatchedWithProbe = ele;
		      }

		    if( tag.DeltaR(ele) < 0.2 ) 
		      {
			IsTagMatchedWithOfflineEle = true;		    
			RecoEleMatchedWithTag = ele;
		      }

		  }

		//Loop over trigger WP80 electrons
		for(int iwp80=0; iwp80<HLTEle27WP80TrackIsoFilterPt->size(); iwp80++)
		  {
		    TLorentzVector wp80;
		    wp80.SetPtEtaPhiE(HLTEle27WP80TrackIsoFilterPt->at(iwp80),
				      HLTEle27WP80TrackIsoFilterEta->at(iwp80),
				      HLTEle27WP80TrackIsoFilterPhi->at(iwp80),
				      HLTEle27WP80TrackIsoFilterEnergy->at(iwp80)
				      );	    
		    
		    CreateAndFillUserTH1D("DR_ProbeVsWP80", 100, 0, 10, probe.DeltaR(wp80) );

		    if( probe.DeltaR(wp80) < 0.2 ) 
		      IsProbeMatchedWithTriggerWP80 = true;
		  }

		//Loop over trigger tag
		for(int itag2=0; itag2<HLTEle32CaloIdTCaloIsoTTrkIdTTrkIsoTEle17TrackIsolFilterPt->size(); itag2++)
		  {
		    TLorentzVector tag2;
		    tag2.SetPtEtaPhiE(HLTEle32CaloIdTCaloIsoTTrkIdTTrkIsoTEle17TrackIsolFilterPt->at(itag2),
				      HLTEle32CaloIdTCaloIsoTTrkIdTTrkIsoTEle17TrackIsolFilterEta->at(itag2),
				      HLTEle32CaloIdTCaloIsoTTrkIdTTrkIsoTEle17TrackIsolFilterPhi->at(itag2),
				      HLTEle32CaloIdTCaloIsoTTrkIdTTrkIsoTEle17TrackIsolFilterEnergy->at(itag2)
				      );	    

		    CreateAndFillUserTH1D("DR_ProbeVsTag2", 100, 0, 10, probe.DeltaR(tag2) );

		    if( probe.DeltaR(tag2) < 0.2 ) 
		      IsProbeMatchedWithTriggerTag = true;
		  }				

		TLorentzVector tag_probe_system;
		tag_probe_system = tag + probe;
		double mass = tag_probe_system.M();

		CreateAndFillUserTH1D("Mass_TagProbeSystem_NoCutOnProbe", 200, 0, 200, mass );

		if( IsProbeMatchedWithOfflineEle && IsTagMatchedWithOfflineEle )
		  {
		    CreateAndFillUserTH1D("Mass_TagProbeSystem_ProbeMatchedOfflineEle", 200, 0, 200, mass );

		    if( mass > 75 && mass < 95)
		      {
			CreateAndFillUserTH1D("Mass_TagProbeSystem_ForEfficiencyCalculation", 200, 0, 200, mass );

			FillUserTH1D("eta_recoEleMatchProbe_PassEleOffline", RecoEleMatchedWithProbe.Eta() );
			FillUserTH1D("pt_recoEleMatchProbe_PassEleOffline", RecoEleMatchedWithProbe.Pt() );			
			FillUserTH1D("NPV_recoEleMatchProbe_PassEleOffline", getVariableValue("nVertex") );			

			N_probe_PassEleOffline++;
			if( isProbeBarrel )
			  {
			    N_probe_PassEleOffline_bar++;
			    FillUserTH1D("NPV_recoEleMatchProbe_PassEleOffline_bar", getVariableValue("nVertex") );			
			  }
			if( isProbeEndcap )
			  {
			    N_probe_PassEleOffline_end++;
			    FillUserTH1D("NPV_recoEleMatchProbe_PassEleOffline_end", getVariableValue("nVertex") );			
			  }			

			if(IsProbeMatchedWithTriggerWP80)
			  {
			    FillUserTH1D("eta_recoEleMatchProbe_PassEleOfflineAndWP80", RecoEleMatchedWithProbe.Eta() );
			    FillUserTH1D("pt_recoEleMatchProbe_PassEleOfflineAndWP80", RecoEleMatchedWithProbe.Pt() );			
			    FillUserTH1D("NPV_recoEleMatchProbe_PassEleOfflineAndWP80", getVariableValue("nVertex") );			

			    N_probe_PassEleOfflineAndWP80++;
			    if( isProbeBarrel )
			      {
				N_probe_PassEleOfflineAndWP80_bar++;
				FillUserTH1D("NPV_recoEleMatchProbe_PassEleOfflineAndWP80_bar", getVariableValue("nVertex") );			
			      }
			    if( isProbeEndcap )
			      {
				N_probe_PassEleOfflineAndWP80_end++;
				FillUserTH1D("NPV_recoEleMatchProbe_PassEleOfflineAndWP80_end", getVariableValue("nVertex") );			
			      }
			  }
			
			if(IsProbeMatchedWithTriggerTag)
			  {
			    FillUserTH1D("eta_recoEleMatchProbe_PassEleOfflineAndTag", RecoEleMatchedWithProbe.Eta() );
			    FillUserTH1D("pt_recoEleMatchProbe_PassEleOfflineAndTag", RecoEleMatchedWithProbe.Pt() );			
			    FillUserTH1D("NPV_recoEleMatchProbe_PassEleOfflineAndTag", getVariableValue("nVertex") );			

			    N_probe_PassEleOfflineAndTag++;
			    if( isProbeBarrel )
			      {
				N_probe_PassEleOfflineAndTag_bar++;
				FillUserTH1D("NPV_recoEleMatchProbe_PassEleOfflineAndTag_bar", getVariableValue("nVertex") );			
			      }
			    if( isProbeEndcap )
			      {
				N_probe_PassEleOfflineAndTag_end++;
				FillUserTH1D("NPV_recoEleMatchProbe_PassEleOfflineAndTag_end", getVariableValue("nVertex") );			
			      }
			  }
			
		      }//mass cut

		  }//IsProbeMatchedWithOfflineEle
		
	      }//end loop over tag


	  }//end loop over probe
	  


	//	fillVariableWithValue( "PassEcalMaskedCellDRFilter", passEcalMaskedCellDRFilter ) ;

	//triggerFired ("HLT_Photon30_CaloIdVL_v1") 


	//v_idx_ele_PtCut_IDISO_ANA.size()

	//CreateAndFillUserTH1D("ElePt_AfterPhoton30", 100, 0, 1000, ElectronPt -> at (v_idx_ele_PtCut_IDISO_ANA[0]) );

      }//end Basic Event Selection


  } // End of loop over events

  //##################################################

  /*//------------------------------------------------------------------
   *
   *
   *      
   *      End analysis loop!
   *
   *
   *
   *///-----------------------------------------------------------------

  //Printout
  double eff_WP80 = double(N_probe_PassEleOfflineAndWP80)/double(N_probe_PassEleOffline);
  double eff_Tag = double(N_probe_PassEleOfflineAndTag)/double(N_probe_PassEleOffline);

  cout << "*** ALL ***" << endl;
  cout << "N_probe_PassEleOffline: " << N_probe_PassEleOffline << endl;
  cout << "N_probe_PassEleOfflineAndWP80: " << N_probe_PassEleOfflineAndWP80 << endl;
  cout << "N_probe_PassEleOfflineAndTag: " << N_probe_PassEleOfflineAndTag << endl;
  cout << endl;
  cout << "eff_WP80: " << eff_WP80 << " +/- " << sqrt(eff_WP80 * (1- eff_WP80) / N_probe_PassEleOffline ) << endl;  
  cout << "eff_Tag: " << eff_Tag << " +/- " << sqrt(eff_Tag * (1- eff_Tag) / N_probe_PassEleOffline ) << endl;  
  cout << endl;

  double eff_WP80_bar = double(N_probe_PassEleOfflineAndWP80_bar)/double(N_probe_PassEleOffline_bar);
  double eff_Tag_bar = double(N_probe_PassEleOfflineAndTag_bar)/double(N_probe_PassEleOffline_bar);

  cout << "*** BARREL ***" << endl;
  cout << "N_probe_PassEleOffline_bar: " << N_probe_PassEleOffline_bar << endl;
  cout << "N_probe_PassEleOfflineAndWP80_bar: " << N_probe_PassEleOfflineAndWP80_bar << endl;
  cout << "N_probe_PassEleOfflineAndTag_bar: " << N_probe_PassEleOfflineAndTag_bar << endl;
  cout << endl;
  cout << "eff_WP80_bar: " << eff_WP80_bar << " +/- " << sqrt(eff_WP80_bar * (1- eff_WP80_bar) / N_probe_PassEleOffline_bar ) << endl;  
  cout << "eff_Tag_bar: " << eff_Tag_bar << " +/- " << sqrt(eff_Tag_bar * (1- eff_Tag_bar) / N_probe_PassEleOffline_bar ) << endl;  
  cout << endl;

  double eff_WP80_end = double(N_probe_PassEleOfflineAndWP80_end)/double(N_probe_PassEleOffline_end);
  double eff_Tag_end = double(N_probe_PassEleOfflineAndTag_end)/double(N_probe_PassEleOffline_end);

  cout << "*** ENDCAP ***" << endl;
  cout << "N_probe_PassEleOffline_end: " << N_probe_PassEleOffline_end << endl;
  cout << "N_probe_PassEleOfflineAndWP80_end: " << N_probe_PassEleOfflineAndWP80_end << endl;
  cout << "N_probe_PassEleOfflineAndTag_end: " << N_probe_PassEleOfflineAndTag_end << endl;
  cout << endl;
  cout << "eff_WP80_end: " << eff_WP80_end << " +/- " << sqrt(eff_WP80_end * (1- eff_WP80_end) / N_probe_PassEleOffline_end ) << endl;  
  cout << "eff_Tag_end: " << eff_Tag_end << " +/- " << sqrt(eff_Tag_end * (1- eff_Tag_end) / N_probe_PassEleOffline_end ) << endl;  
  cout << endl;


  STDOUT("analysisClass::Loop() ends");
}
void analysisClass::Loop()
{
  //STDOUT("analysisClass::Loop() begins");
  
  if (fChain == 0) return;

   TH1F *h_TrigDiff = new TH1F("TrigDiff","TrigDiff",3.0,-1.5,1.5);
   TH2F *h2_DebugTrig = new TH2F("DebugTrig","DebugTrig;HLTResults;HLTBits",2,0,2,2,0,2);
   
   TH1F *h_dPhi_JetSC = new TH1F("dPhi_JetSC","dPhi_JetSC",650,0,6.5); h_dPhi_JetSC->Sumw2();
   TH1F *h_dR_JetSC = new TH1F("dR_JetSC","dR_JetSC",600,0,3.0); h_dR_JetSC->Sumw2();
   TH1F *h_NisoSC = new TH1F ("NisoSC","NisoSC",6,-0.5,5.5);  h_NisoSC->Sumw2();

   TH1F *h_goodEleSCPt = new TH1F ("goodEleSCPt","goodEleSCPt",100,0,100); h_goodEleSCPt->Sumw2();
   TH1F *h_goodEleSCEta = new TH1F ("goodEleSCEta","goodEleSCEta",100,-3.,3.); h_goodEleSCEta->Sumw2();
   TH1F *h_goodEleSCPt_Barrel = new TH1F ("goodEleSCPt_Barrel","goodEleSCPt_Barrel",100,0,100); h_goodEleSCPt_Barrel->Sumw2();
   TH1F *h_goodEleSCPt_Endcap = new TH1F ("goodEleSCPt_Endcap","goodEleSCPt_Endcap",100,0,100); h_goodEleSCPt_Endcap->Sumw2();

   TH1F *h_goodSCPt = new TH1F ("goodSCPt","goodSCPt",100,0,100); h_goodSCPt->Sumw2();
   TH1F *h_goodSCEta = new TH1F ("goodSCEta","goodSCEta",100,-3.,3.); h_goodSCEta->Sumw2();
   TH1F *h_goodSCPt_Barrel = new TH1F ("goodSCPt_Barrel","goodSCPt_Barrel",100,0,100); h_goodSCPt_Barrel->Sumw2();
   TH1F *h_goodSCPt_Endcap = new TH1F ("goodSCPt_Endcap","goodSCPt_Endcap",100,0,100); h_goodSCPt_Endcap->Sumw2();

   TH1F *h_eta_failHLT = new TH1F("eta_failHLT","eta_failHLT",500,-3.0,3.0);
   TH1F *h_phi_failHLT = new TH1F("phi_failHLT","phi_failHLT",100,-3.5,3.5);

   /////////initialize variables
   double FailRate = 0;
   double NFailHLT = 0;
   double HasSC = 0;

  
  ////////////////////// User's code to book histos - END ///////////////////////
    
  Long64_t nentries = fChain->GetEntriesFast();
  STDOUT("analysisClass::Loop(): nentries = " << nentries);   
  
  ////// The following ~7 lines have been taken from rootNtupleClass->Loop() /////
  ////// If the root version is updated and rootNtupleClass regenerated,     /////
  ////// these lines may need to be updated.                                 /////    
  Long64_t nbytes = 0, nb = 0;
  for (Long64_t jentry=0; jentry<nentries;jentry++) { // Begin of loop over events
  //for (Long64_t jentry=0; jentry<10000;jentry++) { // Begin of loop over events
    Long64_t ientry = LoadTree(jentry);
    if (ientry < 0) break;
    nb = fChain->GetEntry(jentry);   nbytes += nb;
    if(jentry < 10 || jentry%10000 == 0) STDOUT("analysisClass::Loop(): jentry = " << jentry);   
    // if (Cut(ientry) < 0) continue;
    
    ////////////////////// User's code to be done for every event - BEGIN ///////////////////////

    //## HLT

    bool PassTrig=HLTResults->at(1); // results of HLTPhoton15 
    //bool PassTrig=HLTBits->at(71); // results of HLTPhoton15 
    int TrigDiff = HLTBits->at(71) - HLTResults->at(1);
    h_TrigDiff->Fill(TrigDiff);
    h2_DebugTrig->Fill(HLTResults->at(1),HLTBits->at(71));

    // Electrons
    vector<int> v_idx_ele_all;
    vector<int> v_idx_ele_PtCut;
    vector<int> v_idx_ele_HEEP;
    int eleIDType = (int) getPreCutValue1("eleIDType");
     
    //Loop over electrons
    for(int iele=0; iele<ElectronPt->size(); iele++)
      {
	//no cut on reco electrons
	v_idx_ele_all.push_back(iele); 

	//pT pre-cut on ele
	if( ElectronPt->at(iele) < getPreCutValue1("ele_PtCut") ) continue; 
	v_idx_ele_PtCut.push_back(iele);

	//ID + ISO + NO overlap with good muons 
	int eleID = ElectronPassID->at(iele);
	if ( (eleID & 1<<eleIDType) > 0  && ElectronOverlaps->at(iele)==0 )
	  {
	    v_idx_ele_HEEP.push_back(iele);
	  }

// 	bool HEEP = false;
// 	if (fabs(ElectronEta->at(iele))<1.442){
// 	if (fabs(ElectronDeltaEtaTrkSC->at(iele))<0.005){
// 	  if (fabs(ElectronDeltaPhiTrkSC->at(iele))<0.09){
// 	    if (ElectronHoE->at(iele)<0.05){
// 		if ((ElectronE2x5OverE5x5->at(iele)>0.94)||(ElectronE1x5OverE5x5->at(iele)>0.83)){
// 		  if ((ElectronEcalIsoHeep->at(iele) + ElectronHcalIsoD1Heep->at(iele))<(2+0.03*ElectronPt->at(iele))){
// 		    if (ElectronTrkIsoHeep->at(iele)<7.5){
// 		      HEEP = true;
// 		    }
// 		  }
// 		}
// 	      }
// 	    }
// 	  }
// 	}

// 	double eleEt = ElectronPt->at(iele);
// 	if ((fabs(ElectronEta->at(iele))>1.56) && (fabs(ElectronEta->at(iele))<2.5)){
// 	if (fabs(ElectronDeltaEtaTrkSC->at(iele))<0.007){
// 	  if (fabs(ElectronDeltaPhiTrkSC->at(iele))<0.09){
// 	    if (ElectronHoE->at(iele)<0.05){
// 	      if (ElectronSigmaIEtaIEta->at(iele)<0.03){
// 		if (((ElectronEcalIsoHeep->at(iele) + ElectronHcalIsoD1Heep->at(iele))<2.5) || 
// 		    ((eleEt>50)&&(ElectronEcalIsoHeep->at(iele) + ElectronHcalIsoD1Heep->at(iele))< ((0.03*(eleEt-50))+2.5))){
// 		    if (ElectronTrkIsoHeep->at(iele)<15){
// 		      if (ElectronHcalIsoD2Heep->at(iele)<0.5){
// 		      HEEP = true;
// 		      }
// 		    }
// 		}
// 	      }
// 	    }
// 	  }
// 	}
// 	}

// 	if ( HEEP  && ElectronOverlaps->at(iele)==0 )
// 	  {
// 	    v_idx_ele_HEEP.push_back(iele);
// 	  }

      } // End loop over electrons

    
    //////// Fill SC histos

     vector<int> v_idx_sc_iso;

    for(int isc=0;isc<SuperClusterPt->size();isc++){
      if ( SuperClusterPt->at(isc) < getPreCutValue1("ele_PtCut") ) continue;
      if (SuperClusterHoE->at(isc)<0.05) {
	v_idx_sc_iso.push_back(isc);
      }
    }

    // Jets
    vector<int> v_idx_jet_all;
    vector<int> v_idx_jet_PtCut;
 
    // Loop over jets
    for(int ijet=0; ijet<CaloJetPt->size(); ijet++)
      {

	//no cut on reco jets
	v_idx_jet_all.push_back(ijet);

	//pT pre-cut on reco jets
	if ( CaloJetPt->at(ijet) < getPreCutValue1("jet_PtCut") ) continue;

	if( ( CaloJetOverlaps->at(ijet) & 1 << eleIDType) == 0 )/* NO overlap with electrons */  
	  v_idx_jet_PtCut.push_back(ijet);

      } // End loop over jets


    // Set the evaluation of the cuts to false and clear the variable values and filled status
    resetCuts();
    

    // Set the value of the variableNames listed in the cutFile to their current value
    
    // HLT
    fillVariableWithValue( "HLT", PassTrig ) ;

    //## SC
    fillVariableWithValue( "nIsoSC", v_idx_sc_iso.size() );
    //fillVariableWithValue( "nIsoSC",v_idx_sc_iso_barrel.size() );

    // nJet
    fillVariableWithValue( "nJet_all", v_idx_jet_all.size() ) ;
    fillVariableWithValue( "nJet_PtCut", v_idx_jet_PtCut.size() ) ;
    fillVariableWithValue( "nJet_PtCut_noOvrlpSC", v_idx_jet_PtCut.size() ) ;

    // 1st SC
    if( v_idx_sc_iso.size() >= 1 ) 
      {
	fillVariableWithValue( "Pt1stSC_ISO", SuperClusterPt->at(v_idx_sc_iso[0]) );
	fillVariableWithValue( "Eta1stSC_ISO", SuperClusterEta->at(v_idx_sc_iso[0]) );
	fillVariableWithValue( "mEta1stSC_ISO", fabs(SuperClusterEta->at(v_idx_sc_iso[0])) );
      }

    // 2nd SC
    if( v_idx_sc_iso.size() >= 2 ) 
      {
	fillVariableWithValue( "Pt2ndSC_ISO", SuperClusterPt->at(v_idx_sc_iso[1]) );
	fillVariableWithValue( "Eta2ndSC_ISO", SuperClusterEta->at(v_idx_sc_iso[1]) );
	fillVariableWithValue( "mEta2ndSC_ISO", fabs(SuperClusterEta->at(v_idx_sc_iso[1])) );
	fillVariableWithValue( "maxMEtaSC_ISO", max( getVariableValue("mEta1stSC_ISO"), getVariableValue("mEta2ndSC_ISO") ) );
      }

    // 1st jet
    if( v_idx_jet_PtCut.size() >= 1 ) 
      {
	fillVariableWithValue( "Pt1stJet_noOvrlpSC", CaloJetPt->at(v_idx_jet_PtCut[0]) );
	fillVariableWithValue( "Eta1stJet_noOvrlpSC", CaloJetEta->at(v_idx_jet_PtCut[0]) );
	fillVariableWithValue( "mEta1stJet_noOvrlpSC", fabs(CaloJetEta->at(v_idx_jet_PtCut[0])) );
      }


    //cout << "2nd Jet" << endl;
    //## 2nd jet
    if( v_idx_jet_PtCut.size() >= 2 ) 
      {
	fillVariableWithValue( "Pt2ndJet_noOvrlpSC", CaloJetPt->at(v_idx_jet_PtCut[1]) );
	fillVariableWithValue( "Eta2ndJet_noOvrlpSC", CaloJetEta->at(v_idx_jet_PtCut[1]) );
	fillVariableWithValue( "mEta2ndJet_noOvrlpSC", fabs(CaloJetEta->at(v_idx_jet_PtCut[1])) );
	fillVariableWithValue( "maxMEtaJets_noOvrlpSC", max( getVariableValue("mEta1stJet_noOvrlpSC"), getVariableValue("mEta2ndJet_noOvrlpSC") ) );
      }


    // Evaluate cuts (but do not apply them)
    evaluateCuts();

     if (passedCut("nIsoSC")){
       HasSC++;
     }

     // Fill histograms and do analysis based on cut evaluation
     if (v_idx_sc_iso.size()>0 && !passedCut("HLT")){
       NFailHLT++;
       h_eta_failHLT->Fill(SuperClusterEta->at(v_idx_sc_iso[0]));
       h_phi_failHLT->Fill(SuperClusterPhi->at(v_idx_sc_iso[0]));
     }


     if ( v_idx_ele_PtCut.size()>1) continue; // require at most one loose ele to reject Zs
     if (PFMET->at(0) > 10) continue; // get rid of Ws
	 for(int isc=0;isc<v_idx_sc_iso.size();isc++)
	   {
	     //Require dR>2.6 between SC and JET
	     TVector3 sc_vec;
	     sc_vec.SetPtEtaPhi(SuperClusterPt->at(v_idx_sc_iso[isc]),
			   SuperClusterEta->at(v_idx_sc_iso[isc]),
			   SuperClusterPhi->at(v_idx_sc_iso[isc]));
	     double dPhi_SC_Jet=0;
	     for (int ijet=0;ijet<v_idx_jet_PtCut.size();ijet++){
	       TVector3 jet_vec;
	       jet_vec.SetPtEtaPhi(CaloJetPt->at(v_idx_jet_PtCut[ijet]),
			    CaloJetEta->at(v_idx_jet_PtCut[ijet]),
			    CaloJetPhi->at(v_idx_jet_PtCut[ijet]));
	       double deltaPhi=fabs(jet_vec.DeltaPhi(sc_vec));
	       if (deltaPhi>dPhi_SC_Jet)dPhi_SC_Jet=deltaPhi;
	     }
	     if (dPhi_SC_Jet<2.6) continue;
	     h_dPhi_JetSC->Fill(dPhi_SC_Jet);	

	     h_goodSCPt->Fill(SuperClusterPt->at(v_idx_sc_iso[isc]));
	     h_goodSCEta->Fill(SuperClusterEta->at(v_idx_sc_iso[isc]));

	     bool Barrel = false;
	     bool Endcap = false;
	     if (fabs(SuperClusterEta->at(v_idx_sc_iso[isc]))<1.45) Barrel = true;
	     if (fabs(SuperClusterEta->at(v_idx_sc_iso[isc]))>1.56 && fabs(SuperClusterEta->at(v_idx_sc_iso[isc]))<2.5) Endcap = true;

	     if (Barrel) h_goodSCPt_Barrel->Fill(SuperClusterPt->at(v_idx_sc_iso[isc]));
	     if (Endcap) h_goodSCPt_Endcap->Fill(SuperClusterPt->at(v_idx_sc_iso[isc]));

	     ///  see if there is a HEEP ele to match this
	     double deltaR_ele_sc = 99;
	     int idx_HEEP = -1;
	     for(int iele=0;iele<v_idx_ele_HEEP.size();iele++){
	       TVector3 ele_vec;
	       ele_vec.SetPtEtaPhi(ElectronPt->at(v_idx_ele_HEEP[iele]),
			   ElectronEta->at(v_idx_ele_HEEP[iele]),
			   ElectronPhi->at(v_idx_ele_HEEP[iele]));
	       double tmp_deltaR = ele_vec.DeltaR(sc_vec);
	       if (tmp_deltaR<deltaR_ele_sc){
		 deltaR_ele_sc = tmp_deltaR;
		 idx_HEEP = iele;
	       }
	     }
	     if (deltaR_ele_sc<0.3){
		h_goodEleSCPt->Fill(ElectronSCPt->at(v_idx_ele_HEEP[idx_HEEP]));
		h_goodEleSCEta->Fill(ElectronSCEta->at(v_idx_ele_HEEP[idx_HEEP]));
		
		bool Barrel = false;
		bool Endcap = false;
		if (fabs(ElectronSCEta->at(v_idx_ele_HEEP[idx_HEEP]))<1.45) Barrel = true;
		if (fabs(ElectronSCEta->at(v_idx_ele_HEEP[idx_HEEP]))>1.56 && fabs(ElectronSCEta->at(v_idx_ele_HEEP[idx_HEEP]))<2.5) Endcap = true;
		
		if (Barrel) h_goodEleSCPt_Barrel->Fill(ElectronSCPt->at(v_idx_ele_HEEP[idx_HEEP]));
		if (Endcap) h_goodEleSCPt_Endcap->Fill(ElectronSCPt->at(v_idx_ele_HEEP[idx_HEEP]));
		}
	   } // for sc


    ////////////////////// User's code to be done for every event - END ///////////////////////
    
  } // End of loop over events
  

  ////////////////////// User's code to write histos - BEGIN ///////////////////////

   h_TrigDiff->Write();
   h2_DebugTrig->Write();

   h_dPhi_JetSC->Write();
   h_dR_JetSC->Write();
   h_NisoSC->Write();
   h_goodEleSCPt->Write();
   h_goodEleSCEta->Write();
   h_goodEleSCPt_Barrel->Write();
   h_goodEleSCPt_Endcap->Write();
   h_goodSCPt->Write();
   h_goodSCEta->Write();
   h_goodSCPt_Barrel->Write();
   h_goodSCPt_Endcap->Write();

   h_eta_failHLT->Write();
   h_phi_failHLT->Write();

   FailRate = 100 * NFailHLT/HasSC;
   //cout << "NFail: " << NFailHLT << "\t" << "FailRate: " << FailRate << " %" << endl;
  
  //STDOUT("analysisClass::Loop() ends");   
}
void analysisClass::Loop()
{
  //STDOUT("analysisClass::Loop() begins");
  
  if (fChain == 0) return;
   
  ////////////////////// User's code to book histos - BEGIN ///////////////////////

  TH1F *h_Mej_PAS = new TH1F ("h_Mej_PAS","h_Mej_PAS",200,0,2000);  h_Mej_PAS->Sumw2();

  ////////////////////// User's code to book histos - END ///////////////////////

  ////////////////////// User's code to get preCut values - BEGIN ///////////////

  double eleEta_bar = getPreCutValue1("eleEta_bar");
  double eleEta_end_min = getPreCutValue1("eleEta_end");
  double eleEta_end_max = getPreCutValue2("eleEta_end");

  double EleEnergyScale_EB=getPreCutValue1("EleEnergyScale_EB");
  double EleEnergyScale_EE=getPreCutValue1("EleEnergyScale_EE");
  double JetEnergyScale=getPreCutValue1("JetEnergyScale");

  // Not used when using ElectronHeepID and heepBitMask // int eleIDType = (int) getPreCutValue1("eleIDType");
  int heepBitMask_EB  =  getPreCutValue1("heepBitMask_EBGapEE") ;
  int heepBitMask_GAP =  getPreCutValue2("heepBitMask_EBGapEE") ;

  int heepBitMask_EE  =  getPreCutValue3("heepBitMask_EBGapEE") ;

  int looseBitMask_EB       =  getPreCutValue1("looseBitMask_EBGapEE") ;
  int looseBitMask_GAP      =  getPreCutValue2("looseBitMask_EBGapEE") ;
  int looseBitMask_EE       =  getPreCutValue3("looseBitMask_EBGapEE") ;
  int looseBitMask_enabled  =  getPreCutValue4("looseBitMask_EBGapEE") ;

  double muon_PtCut = getPreCutValue1("muon_PtCut");
  double muFidRegion = getPreCutValue1("muFidRegion"); // currently unused !!!
  double muNHits_minThresh = getPreCutValue1("muNHits_minThresh");
  double muTrkD0Maximum = getPreCutValue1("muTrkD0Maximum");

  double BarrelCross = getPreCutValue1("fakeRate_Barrel");
  double BarrelSlope = getPreCutValue2("fakeRate_Barrel");
  double EndcapCross = getPreCutValue1("fakeRate_Endcap");
  double EndcapSlope = getPreCutValue2("fakeRate_Endcap");

  ////////////////////// User's code to get preCut values - END /////////////////
    
  Long64_t nentries = fChain->GetEntriesFast();
  STDOUT("analysisClass::Loop(): nentries = " << nentries);   
  
  ////// The following ~7 lines have been taken from rootNtupleClass->Loop() /////
  ////// If the root version is updated and rootNtupleClass regenerated,     /////
  ////// these lines may need to be updated.                                 /////    
  Long64_t nbytes = 0, nb = 0;
  for (Long64_t jentry=0; jentry<nentries;jentry++) { // Begin of loop over events
    //for (Long64_t jentry=0; jentry<10000;jentry++) { // Begin of loop over events
    Long64_t ientry = LoadTree(jentry);
    if (ientry < 0) break;
    nb = fChain->GetEntry(jentry);   nbytes += nb;
    if(jentry < 10 || jentry%1000 == 0) STDOUT("analysisClass::Loop(): jentry = " << jentry);   
    // if (Cut(ientry) < 0) continue;
    
    ////////////////////// User's code to be done for every event - BEGIN ///////////////////////

    //if (PtHat>=30) continue;

    // EES and JES
    if( EleEnergyScale_EB != 1 || EleEnergyScale_EE != 1 )
      {
	for(int iele=0; iele<SuperClusterPt->size(); iele++)
	  {
	    if( fabs(SuperClusterEta->at(iele)) < eleEta_bar )
	      SuperClusterPt->at(iele) *= EleEnergyScale_EB;
	    if( fabs(SuperClusterEta->at(iele)) > eleEta_end_min && fabs(SuperClusterEta->at(iele)) < eleEta_end_max )
	      SuperClusterPt->at(iele) *= EleEnergyScale_EE;
	  }
      }
    if( JetEnergyScale != 1 )
      {
	for(int ijet=0; ijet<CaloJetPt->size(); ijet++)
	  {
	    CaloJetPt->at(ijet) *= JetEnergyScale;
	  }
      }

    //## HLT
    int PassTrig = 0;
    int HLTFromRun[4] = {getPreCutValue1("HLTFromRun"),
			 getPreCutValue2("HLTFromRun"),
			 getPreCutValue3("HLTFromRun"),
			 getPreCutValue4("HLTFromRun")};
    int HLTTrigger[4] = {getPreCutValue1("HLTTrigger"),
			 getPreCutValue2("HLTTrigger"),
			 getPreCutValue3("HLTTrigger"),
			 getPreCutValue4("HLTTrigger")};
    int HLTTrgUsed;
    for (int i=0; i<4; i++) {
      if ( !isData && i != 0) continue; // For MC use HLTPhoton15 as the cleaned trigger is not in MC yet as of July 20, 2010
      if ( HLTFromRun[i] <= run ) {
 	//if(jentry == 0 ) STDOUT("run, i, HLTTrigger[i], HLTFromRun[i] = "<<run<<"\t"<<i<<"\t"<<"\t"<<HLTTrigger[i]<<"\t"<<HLTFromRun[i]);
	if (HLTTrigger[i] > 0 && HLTTrigger[i] < HLTResults->size() ) {
	  PassTrig=HLTResults->at(HLTTrigger[i]);
	  HLTTrgUsed=HLTTrigger[i];
	} else {
	  STDOUT("ERROR: HLTTrigger out of range of HLTResults: HLTTrigger = "<<HLTTrigger[i] <<"and HLTResults size = "<< HLTResults->size());
	}
      }
    }
    if(jentry == 0 ) STDOUT("Run = "<<run <<", HLTTrgUsed is number = "<<HLTTrgUsed<<" of the list HLTPathsOfInterest");
    
    // Superclusters
    vector<int> v_idx_sc_all;
    vector<int> v_idx_sc_PtCut;
    vector<int> v_idx_sc_Iso;
    
    //Create vector with indices of supercluster ordered by pT
    vector<pair<size_t, myiter> > order(SuperClusterPt->size());
    size_t n = 0;
    for (myiter it = SuperClusterPt->begin(); it != SuperClusterPt->end(); ++it, ++n)
      order[n] = make_pair(n, it);
    sort(order.begin(), order.end(), ordering());
    
    for(int isc=0; isc<order.size(); isc++)
      {
	// 	cout << "index , pT: " 
	// 	     << order[isc].first 
	// 	     << " , " 
	// 	     << *order[isc].second 
	// 	     << endl;
	v_idx_sc_all.push_back(order[isc].first); //### All superclusters ordered by pT
      }
    
    for(int isc=0;isc<v_idx_sc_all.size();isc++){

      //pT cut + ECAL acceptance cut + remove spikes (all together)
      if ( 1 - SuperClusterS4S1->at(v_idx_sc_all[isc]) > 0.95 ) continue;  

      bool Barrel = false;
      bool Endcap = false;
      if (fabs(SuperClusterEta->at(v_idx_sc_all[isc]))<eleEta_bar) Barrel = true;
      if ((fabs(SuperClusterEta->at(v_idx_sc_all[isc]))<eleEta_end_max)
	  &&(fabs(SuperClusterEta->at(v_idx_sc_all[isc]))>eleEta_end_min)) Endcap = true;
      if ( !Barrel && !Endcap) continue;

      bool PassPt = false;
      if ( SuperClusterPt->at(v_idx_sc_all[isc]) > getPreCutValue1("ele_PtCut") ) PassPt=true;
      if ( !PassPt ) continue;

      v_idx_sc_PtCut.push_back(v_idx_sc_all[isc]); //### Pt cut (+ no gaps + no spikes)

      //ID+Isolation together
      bool PassHoE = false;
      if ( SuperClusterHoE->at(v_idx_sc_all[isc])<0.05) PassHoE=true;
      if ( !PassHoE ) continue;

      bool PassEcalIso = false;
      if (Barrel && SuperClusterHEEPEcalIso->at(v_idx_sc_all[isc]) <(6+(0.01*SuperClusterPt->at(v_idx_sc_all[isc])))) 
	PassEcalIso=true;
      if (Endcap && SuperClusterPt->at(v_idx_sc_all[isc])<50 
	  && SuperClusterHEEPEcalIso->at(v_idx_sc_all[isc])<(6+(0.01*SuperClusterPt->at(v_idx_sc_all[isc])))) 
	PassEcalIso=true;
      if (Endcap && SuperClusterPt->at(v_idx_sc_all[isc])>=50 
	  && SuperClusterHEEPEcalIso->at(v_idx_sc_all[isc])<(6+(0.01*(SuperClusterPt->at(v_idx_sc_all[isc])-50)))) 
	PassEcalIso=true;
      if ( !PassEcalIso ) continue;

      v_idx_sc_Iso.push_back(v_idx_sc_all[isc]); //### Pt cut + ID+ISO

    }

    // Electrons
    vector<int> v_idx_ele_all;
    vector<int> v_idx_ele_PtCut;
    vector<int> v_idx_ele_PtCut_IDISO_noOverlap;
    int heepBitMask;

    //Loop over electrons
    for(int iele=0; iele<ElectronPt->size(); iele++)
      {

	// Reject ECAL spikes
	if ( 1 - ElectronSCS4S1->at(iele) > 0.95 ) continue; 

	//no cut on reco electrons
	v_idx_ele_all.push_back(iele); 

	//pT pre-cut on ele
	if( ElectronPt->at(iele) < getPreCutValue1("ele_PtCut") ) continue; 
	v_idx_ele_PtCut.push_back(iele);

	// get heepBitMask for EB, GAP, EE 
	if( fabs(ElectronEta->at(iele)) < eleEta_bar ) 
	  {
	    heepBitMask = heepBitMask_EB;
	  }
	else if ( fabs(ElectronEta->at(iele)) > eleEta_end_min && fabs(ElectronEta->at(iele)) < eleEta_end_max ) 
	  {
	    heepBitMask = heepBitMask_EE;
	  }
	else {
	  heepBitMask = heepBitMask_GAP;
	}

	//ID + ISO + NO overlap with good muons 
	// int eleID = ElectronPassID->at(iele);
	// if ( (eleID & 1<<eleIDType) > 0  && ElectronOverlaps->at(iele)==0 )
	if ( (ElectronHeepID->at(iele) & ~heepBitMask)==0x0  && ElectronOverlaps->at(iele)==0 )
	  {
	    //STDOUT("ElectronHeepID = " << hex << ElectronHeepID->at(iele) << " ; ElectronPassID = " << ElectronPassID->at(iele) )
	    v_idx_ele_PtCut_IDISO_noOverlap.push_back(iele);
	  }

      } // End loop over electrons

    // tight-loose electrons, if enabled from cut file
    if ( looseBitMask_enabled == 1 && v_idx_ele_PtCut_IDISO_noOverlap.size() == 1 )
      {
	//STDOUT("v_idx_ele_PtCut_IDISO_noOverlap[0] = "<<v_idx_ele_PtCut_IDISO_noOverlap[0] << " - Pt = "<<ElectronPt->at(v_idx_ele_PtCut_IDISO_noOverlap[0]));
	bool loosePtLargerThanTightPt = true;
	for(int iele=0; iele<v_idx_ele_PtCut.size(); iele++)
	  {
	    
	    if (v_idx_ele_PtCut[iele] == v_idx_ele_PtCut_IDISO_noOverlap[0])
	      {
		loosePtLargerThanTightPt = false;
		continue;
	      }
	    // get looseBitMask for EB, GAP, EE 

	    int looseBitMask;
	    if( fabs(ElectronEta->at(v_idx_ele_PtCut[iele])) < eleEta_bar ) 
	      {
		looseBitMask = looseBitMask_EB;
	      }
	    else if ( fabs(ElectronEta->at(v_idx_ele_PtCut[iele])) > eleEta_end_min && fabs(ElectronEta->at(v_idx_ele_PtCut[iele])) < eleEta_end_max ) 
	      {
		looseBitMask = looseBitMask_EE;
	      }
	    else {
	      looseBitMask = looseBitMask_GAP;
	    }
	    if ( (ElectronHeepID->at(v_idx_ele_PtCut[iele]) & ~looseBitMask)==0x0  && ElectronOverlaps->at(v_idx_ele_PtCut[iele])==0 )
	      {
		if ( loosePtLargerThanTightPt )
		  {
		    v_idx_ele_PtCut_IDISO_noOverlap.insert(v_idx_ele_PtCut_IDISO_noOverlap.begin(),1,v_idx_ele_PtCut[iele]);
		  }
		else 
		  {
		    v_idx_ele_PtCut_IDISO_noOverlap.push_back(v_idx_ele_PtCut[iele]);
		  }
		break; // happy with one loose electron - Note: if you want more than 1 loose, pt sorting will not be OK with the code as is. 
	      }
	  }	
	// 	for ( int i=0; i<v_idx_ele_PtCut_IDISO_noOverlap.size(); i++)
	// 	  {
	// 	    STDOUT("i="<<i<<", v_idx_ele_PtCut_IDISO_noOverlap[i] = "<<v_idx_ele_PtCut_IDISO_noOverlap[i] << ", Pt = "<<ElectronPt->at(v_idx_ele_PtCut_IDISO_noOverlap[i]));
	// 	  }
      } // tight-loose electrons, if enabled from cut file

    // Jets
    vector<int> v_idx_jet_all;
    vector<int> v_idx_jet_PtCut;
    vector<int> v_idx_jet_PtCut_noOverlap;
    vector<int> v_idx_jet_PtCut_noOverlap_ID;
    vector<int> v_idx_jet_PtCut_noOverlap_ID_EtaCut;

    // Loop over jets
    for(int ijet=0; ijet<CaloJetPt->size(); ijet++)
      {
	//no cut on reco jets
	v_idx_jet_all.push_back(ijet);

	//pT pre-cut on reco jets
	if ( CaloJetPt->at(ijet) < getPreCutValue1("jet_PtCut") ) continue;
	v_idx_jet_PtCut.push_back(ijet);
      }

    vector <int> jetFlags(v_idx_jet_PtCut.size(), 0);
    int Njetflagged = 0;
    for (int isc=0; isc<v_idx_sc_Iso.size(); isc++)
      {
	TLorentzVector sc;
        sc.SetPtEtaPhiM(SuperClusterPt->at(v_idx_sc_Iso[isc]),
			SuperClusterEta->at(v_idx_sc_Iso[isc]),
			SuperClusterPhi->at(v_idx_sc_Iso[isc]),0);
	TLorentzVector jet;
	double minDR=9999.;
	int ijet_minDR = -1;    
        for(int ijet=0; ijet<v_idx_jet_PtCut.size(); ijet++)
          {
	    if ( jetFlags[ijet] == 1 ) 
	      continue;
            jet.SetPtEtaPhiM(CaloJetPt->at(v_idx_jet_PtCut[ijet]),
			     CaloJetEta->at(v_idx_jet_PtCut[ijet]),
			     CaloJetPhi->at(v_idx_jet_PtCut[ijet]),0);
	    double DR = jet.DeltaR(sc);
	    if (DR<minDR) 
	      {
		minDR = DR;
		ijet_minDR = ijet;
	      }
	  }
	if ( minDR < getPreCutValue1("jet_ele_DeltaRcut") && ijet_minDR > -1)
	  {
	    jetFlags[ijet_minDR] = 1;
	    Njetflagged++;
	  }
      }

    //     // printouts for jet cleaning
    //     STDOUT("CLEANING ----------- v_idx_ele_PtCut_IDISO_noOverlap.size = "<< v_idx_ele_PtCut_IDISO_noOverlap.size() <<", Njetflagged = "<< Njetflagged<<", diff="<< v_idx_ele_PtCut_IDISO_noOverlap.size()-Njetflagged );
    //     if( (v_idx_ele_PtCut_IDISO_noOverlap.size()-Njetflagged) == 1 ) 
    //       {
    // 	TLorentzVector thisele;
    // 	for(int iele=0; iele<v_idx_ele_PtCut_IDISO_noOverlap.size(); iele++)
    // 	  {
    // 	    thisele.SetPtEtaPhiM(ElectronPt->at(v_idx_ele_PtCut_IDISO_noOverlap[iele]),
    // 				 ElectronEta->at(v_idx_ele_PtCut_IDISO_noOverlap[iele]),
    // 				 ElectronPhi->at(v_idx_ele_PtCut_IDISO_noOverlap[iele]),0);
    // 	    STDOUT("CLEANING: e"<<iele+1<<" Pt, eta, phi = "  << ", "<<thisele.Pt()<<", "<< thisele.Eta() <<", "<< thisele.Phi());
    // 	  }
    // 	TLorentzVector thisjet;
    // 	for(int ijet=0; ijet<v_idx_jet_PtCut.size(); ijet++)
    // 	  {
    // 	    thisjet.SetPtEtaPhiM(CaloJetPt->at(v_idx_jet_PtCut[ijet]),
    // 				 CaloJetEta->at(v_idx_jet_PtCut[ijet]),
    // 				 CaloJetPhi->at(v_idx_jet_PtCut[ijet]),0);
    // 	    STDOUT("CLEANING: j"<<ijet+1<<" Pt, eta, phi = " << ", "<<thisjet.Pt()<<", "<< thisjet.Eta() <<", "<< thisjet.Phi()<<" jetFlags="<<jetFlags[ijet] );
    // 	  }
    //       } // printouts for jet cleaning
    
    
    float JetEtaCutValue = getPreCutValue1("jet_EtaCut");
    for(int ijet=0; ijet<v_idx_jet_PtCut.size(); ijet++) //pT pre-cut + no overlaps with electrons + jetID
      {	
	bool passjetID = JetIdloose(CaloJetresEMF->at(v_idx_jet_PtCut[ijet]),CaloJetfHPD->at(v_idx_jet_PtCut[ijet]),CaloJetn90Hits->at(v_idx_jet_PtCut[ijet]), CaloJetEta->at(v_idx_jet_PtCut[ijet]));
	// ---- use the flag stored in rootTuples
	//if( (CaloJetOverlaps->at(v_idx_jet_PtCut[ijet]) & 1 << eleIDType) == 0  /* NO overlap with electrons */  
	// ----

	if( jetFlags[ijet] == 0  )                         /* NO overlap with electrons */  
	  //  && passjetID == true )                            /* pass JetID */
	  // && (caloJetOverlaps[ijet] & 1 << 5)==0 )         /* NO overlap with muons */      
	  v_idx_jet_PtCut_noOverlap.push_back(v_idx_jet_PtCut[ijet]);

	if( jetFlags[ijet] == 0                           /* NO overlap with electrons */  
	    && passjetID == true )                            /* pass JetID */
	  // && (caloJetOverlaps[ijet] & 1 << 5)==0 )         /* NO overlap with muons */      
	  v_idx_jet_PtCut_noOverlap_ID.push_back(v_idx_jet_PtCut[ijet]);

	if( jetFlags[ijet] == 0                           /* NO overlap with electrons */  
	    && passjetID == true                             /* pass JetID */
	    && fabs( CaloJetEta->at(v_idx_jet_PtCut[ijet]) ) < JetEtaCutValue )
	  // && (caloJetOverlaps[ijet] & 1 << 5)==0 )         /* NO overlap with muons */      
	  v_idx_jet_PtCut_noOverlap_ID_EtaCut.push_back(v_idx_jet_PtCut[ijet]);

	
	//NOTE: We should verify that caloJetOverlaps match with the code above
      } // End loop over jets
    

    // Muons
    vector<int> v_idx_muon_all;
    vector<int> v_idx_muon_PtCut;
    vector<int> v_idx_muon_PtCut_IDISO;
    
    // Loop over muons  
    for(int imuon=0; imuon<MuonPt->size(); imuon++){

      // no cut on reco muons
      v_idx_muon_all.push_back(imuon);

      if ( (*MuonPt)[imuon] < muon_PtCut) continue;

      // pT pre-cut on muons
      v_idx_muon_PtCut.push_back(imuon);
      
      if ( ((*MuonTrkHits)[imuon]  >= muNHits_minThresh  )
	   &&( fabs((*MuonTrkD0)[imuon]) < muTrkD0Maximum ) 
	   &&((*MuonPassIso)[imuon]==1 ) 
	   &&((*MuonPassID)[imuon]==1) ) 
	{
	  v_idx_muon_PtCut_IDISO.push_back(imuon);
	}

    }// end loop over muons


    /////  Define the fake rate for QCD and calculate prob. for each sc to be an ele

    double p1 = 0, p2 = 0, p3 = 0;
    if (v_idx_sc_Iso.size()>=1){
      if (fabs(SuperClusterEta->at(v_idx_sc_Iso[0]))<eleEta_bar) p1 = BarrelCross + BarrelSlope*SuperClusterPt->at(v_idx_sc_Iso[0]);
      if (fabs(SuperClusterEta->at(v_idx_sc_Iso[0]))>eleEta_end_min) p1 = EndcapCross + EndcapSlope*SuperClusterPt->at(v_idx_sc_Iso[0]) ;
    }
    if (v_idx_sc_Iso.size()>=2){
      if (fabs(SuperClusterEta->at(v_idx_sc_Iso[1]))<eleEta_bar) p2 = BarrelCross + BarrelSlope*SuperClusterPt->at(v_idx_sc_Iso[1]);
      if (fabs(SuperClusterEta->at(v_idx_sc_Iso[1]))>eleEta_end_min) p2 = EndcapCross + EndcapSlope*SuperClusterPt->at(v_idx_sc_Iso[1]);
    }
    if (v_idx_sc_Iso.size()>=3){
      if (fabs(SuperClusterEta->at(v_idx_sc_Iso[2]))<eleEta_bar) p3 = BarrelCross + BarrelSlope*SuperClusterPt->at(v_idx_sc_Iso[2]);
      if (fabs(SuperClusterEta->at(v_idx_sc_Iso[2]))>eleEta_end_min) p3 = EndcapCross + EndcapSlope*SuperClusterPt->at(v_idx_sc_Iso[2]);
    }

    // Set the evaluation of the cuts to false and clear the variable values and filled status
    resetCuts();
    
    //-----

    // Set the value of the variableNames listed in the cutFile to their current value


    //     //-------------- EXAMPLE OF RESET-EVALUATE LOOP -
    //     //TEST : loop reset-evaluate cuts    
    //     fillVariableWithValue("Test",0,0.5);    
    //     evaluateCuts();
    //     resetCuts();    
    //     fillVariableWithValue("Test",0,0.25);    
    //     evaluateCuts();
    //     resetCuts();
    //     fillVariableWithValue("Test",1,1);
    //     evaluateCuts();
    //     resetCuts();
    //     fillVariableWithValue("Test",1,0.2);
    //     //---------------


    // original code from Ellie available at 
    // http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/Leptoquarks/rootNtupleMacrosV2/src/analysisClass_eejjSample_QCD.C?revision=1.8&view=markup
    //here we report only the code to fill correctly the "nEle_PtCut_IDISO_noOvrlp" variable
    
    //## fill bin Nele=0
    
    //     if (v_idx_sc_Iso.size()==0) fillVariableWithValue( "nEle_PtCut_IDISO_noOvrlp", v_idx_sc_Iso.size()) ;
    //     else if (v_idx_sc_Iso.size()==1) {
    //       fillVariableWithValue( "nEle_PtCut_IDISO_noOvrlp",0, 1-p1 ) ;
    //     }
    //     else if (v_idx_sc_Iso.size()==2) {
    //       fillVariableWithValue( "nEle_PtCut_IDISO_noOvrlp",0, (1-p1)*(1-p2) ) ;
    //     }
    //     else if (v_idx_sc_Iso.size()>2) {
    //       fillVariableWithValue( "nEle_PtCut_IDISO_noOvrlp",0, (1-p1)*(1-p2)*(1-p3) ) ;
    //     }

    //     evaluateCuts();
    //     resetCuts();

    //## fill bin Nele=1

    //     if (v_idx_sc_Iso.size()==1) fillVariableWithValue( "nEle_PtCut_IDISO_noOvrlp",1, p1 ) ;
    //     else if (v_idx_sc_Iso.size()==2) {
    //       fillVariableWithValue( "nEle_PtCut_IDISO_noOvrlp",1, p1 + p2 - 2*p1*p2 ) ;
    //     }
    //     else if (v_idx_sc_Iso.size()>2) {
    //       fillVariableWithValue( "nEle_PtCut_IDISO_noOvrlp",1, p1 + p2 + p3 - 2*p1*p2 - 2*p2*p3 - 2*p1*p3   ) ;
    //     }

    //     evaluateCuts();
    //     resetCuts();

    //## fill bin Nele=2

    //     if (v_idx_sc_Iso.size()==2) fillVariableWithValue( "nEle_PtCut_IDISO_noOvrlp",2, p1*p2) ;
    //     else if (v_idx_sc_Iso.size()>2) {
    //       fillVariableWithValue( "nEle_PtCut_IDISO_noOvrlp",2, p1*p3 + p1*p2 + p3*p2 ) ;
    //     }

    //     evaluateCuts();
    //     resetCuts();

    //## fill bin Nele=3

    //     if (v_idx_sc_Iso.size()>2) fillVariableWithValue( "nEle_PtCut_IDISO_noOvrlp",3, p1*p2*p3) ;


    //-----

    ///  Just fill all histograms assuming exactly 2 superclusters.
    //     if (v_idx_sc_all.size()>=2) fillVariableWithValue( "nEle_all",v_idx_sc_all.size() , p1*p2 ) ;
    //     if (v_idx_sc_PtCut.size()>=2) fillVariableWithValue( "nEle_PtCut",v_idx_sc_PtCut.size(), p1*p2) ;
    if (v_idx_sc_Iso.size()>=2) fillVariableWithValue("nEle_PtCut_IDISO_noOvrlp",v_idx_sc_Iso.size(), p1*p2) ;


    /// Now fill all variables that are filled just once
    // Trigger (L1 and HLT)
    if(isData==true)
      {
	fillVariableWithValue( "PassBPTX0", isBPTX0 ) ;
	fillVariableWithValue( "PassPhysDecl", isPhysDeclared ) ;       
      }
    else
      {
	fillVariableWithValue( "PassBPTX0", true ) ;
	fillVariableWithValue( "PassPhysDecl", true ) ;       
      }

    fillVariableWithValue( "PassHLT", PassTrig ) ;

    //Event filters at RECO level
    fillVariableWithValue( "PassBeamScraping", !isBeamScraping ) ;
    fillVariableWithValue( "PassPrimaryVertex", isPrimaryVertex ) ;
    //fillVariableWithValue( "PassHBHENoiseFilter", passLooseNoiseFilter ) ;

    // nJet
    fillVariableWithValue( "nJet_all", v_idx_jet_all.size(), p1*p2 ) ;
    fillVariableWithValue( "nJet_PtCut", v_idx_jet_PtCut.size(), p1*p2 ) ;
    fillVariableWithValue( "nJet_PtCut_noOvrlp", v_idx_jet_PtCut_noOverlap.size(), p1*p2 ) ;
    fillVariableWithValue( "nJet_PtCut_noOvrlp_ID", v_idx_jet_PtCut_noOverlap_ID.size(), p1*p2 ) ;
    //TwoEleOnly
    fillVariableWithValue( "nJet_TwoEleOnly_All", v_idx_jet_PtCut_noOverlap_ID.size() , p1*p2) ;
    fillVariableWithValue( "nJet_TwoEleOnly_EtaCut", v_idx_jet_PtCut_noOverlap_ID_EtaCut.size(), p1*p2 ) ;
    //PAS June 2010
    fillVariableWithValue( "nJet_PAS_All", v_idx_jet_PtCut_noOverlap_ID.size(), p1*p2 ) ;
    fillVariableWithValue( "nJet_PAS_EtaCut", v_idx_jet_PtCut_noOverlap_ID_EtaCut.size(), p1*p2 ) ;

    // MET
    //PAS June 2010
    fillVariableWithValue( "pfMET_PAS", PFMET->at(0), p1*p2 ) ;
    fillVariableWithValue( "tcMET_PAS", TCMET->at(0), p1*p2 ) ;
    fillVariableWithValue( "caloMET_PAS", CaloMET->at(0), p1*p2 ) ;

    //ele Pt
    if( v_idx_sc_Iso.size() >= 2 ) 
      {
	fillVariableWithValue( "Pt1stEle_IDISO_NoOvrlp", SuperClusterPt->at(v_idx_sc_Iso[0]), p1*p2 );
	fillVariableWithValue( "Eta1stEle_IDISO_NoOvrlp", SuperClusterEta->at(v_idx_sc_Iso[0]), p1*p2 );
	fillVariableWithValue( "mEta1stEle_IDISO_NoOvrlp", fabs(SuperClusterEta->at(v_idx_sc_Iso[0])), p1*p2 );
	//PAS June 2010
	fillVariableWithValue( "Pt1stEle_PAS", SuperClusterPt->at(v_idx_sc_Iso[0]), p1*p2 );
	fillVariableWithValue( "Eta1stEle_PAS", SuperClusterEta->at(v_idx_sc_Iso[0]), p1*p2 );

	fillVariableWithValue( "Pt2ndEle_IDISO_NoOvrlp", SuperClusterPt->at(v_idx_sc_Iso[1]), p1*p2 );
	fillVariableWithValue( "Eta2ndEle_IDISO_NoOvrlp", SuperClusterEta->at(v_idx_sc_Iso[1]), p1*p2 );
	fillVariableWithValue( "mEta2ndEle_IDISO_NoOvrlp", fabs(SuperClusterEta->at(v_idx_sc_Iso[1])), p1*p2 );
	fillVariableWithValue( "maxMEtaEles_IDISO_NoOvrl", max( getVariableValue("mEta1stEle_IDISO_NoOvrlp"), getVariableValue("mEta2ndEle_IDISO_NoOvrlp") ) , p1*p2);
	//PAS June 2010
	fillVariableWithValue( "Pt2ndEle_PAS", SuperClusterPt->at(v_idx_sc_Iso[1]), p1*p2 );
	fillVariableWithValue( "Eta2ndEle_PAS", SuperClusterEta->at(v_idx_sc_Iso[1]), p1*p2 );
      }

    // 1st jet
    if( v_idx_jet_PtCut_noOverlap_ID.size() >= 1 ) 
      {
	fillVariableWithValue( "Pt1stJet_noOvrlp_ID", CaloJetPt->at(v_idx_jet_PtCut_noOverlap_ID[0]), p1*p2 );
	fillVariableWithValue( "Eta1stJet_noOvrlp_ID", CaloJetEta->at(v_idx_jet_PtCut_noOverlap_ID[0]) , p1*p2);
	fillVariableWithValue( "mEta1stJet_noOvrlp_ID", fabs(CaloJetEta->at(v_idx_jet_PtCut_noOverlap_ID[0])), p1*p2 );
	//PAS June 2010
	fillVariableWithValue( "Pt1stJet_PAS", CaloJetPt->at(v_idx_jet_PtCut_noOverlap_ID[0]), p1*p2 );
	fillVariableWithValue( "Eta1stJet_PAS", CaloJetEta->at(v_idx_jet_PtCut_noOverlap_ID[0]), p1*p2 );
      }


    //cout << "2nd Jet" << endl;
    //## 2nd jet
    if( v_idx_jet_PtCut_noOverlap_ID.size() >= 2 ) 
      {
	fillVariableWithValue( "Pt2ndJet_noOvrlp_ID", CaloJetPt->at(v_idx_jet_PtCut_noOverlap_ID[1]), p1*p2 );
	fillVariableWithValue( "Eta2ndJet_noOvrlp_ID", CaloJetEta->at(v_idx_jet_PtCut_noOverlap_ID[1]), p1*p2 );
	fillVariableWithValue( "mEta2ndJet_noOvrlp_ID", fabs(CaloJetEta->at(v_idx_jet_PtCut_noOverlap_ID[1])), p1*p2 );
	fillVariableWithValue( "maxMEtaJets_noOvrlp_ID", max( getVariableValue("mEta1stJet_noOvrlp_ID"), getVariableValue("mEta2ndJet_noOvrlp_ID") ), p1*p2 );
	//PAS June 2010
	fillVariableWithValue( "Pt2ndJet_PAS", CaloJetPt->at(v_idx_jet_PtCut_noOverlap_ID[1]), p1*p2 );
	fillVariableWithValue( "Eta2ndJet_PAS", CaloJetEta->at(v_idx_jet_PtCut_noOverlap_ID[1]), p1*p2 );
      }

    //## define "2ele" and "2jets" booleans
    bool TwoEle=false;
    bool TwoJets=false;
    if( v_idx_sc_Iso.size() >= 2 ) TwoEle = true;
    if( v_idx_jet_PtCut_noOverlap_ID.size() >= 2 ) TwoJets = true;

    // ST
    double calc_sT=-999.; 
    if ( (TwoEle) && (TwoJets) ) 
      {
	calc_sT = 
	  SuperClusterPt->at(v_idx_sc_Iso[0]) +
	  SuperClusterPt->at(v_idx_sc_Iso[1]) +
	  CaloJetPt->at(v_idx_jet_PtCut_noOverlap_ID[0]) +
	  CaloJetPt->at(v_idx_jet_PtCut_noOverlap_ID[1]);
	fillVariableWithValue("sT", calc_sT, p1*p2);
	fillVariableWithValue("sT_MLQ100", calc_sT, p1*p2);
	fillVariableWithValue("sT_MLQ200", calc_sT, p1*p2);
	fillVariableWithValue("sT_MLQ250", calc_sT, p1*p2);
	fillVariableWithValue("sT_MLQ300", calc_sT, p1*p2);
	fillVariableWithValue("sT_MLQ400", calc_sT, p1*p2);       
	//PAS June 2010
	fillVariableWithValue("sT_PAS", calc_sT, p1*p2);
      }

    // ST jets
    if (TwoJets)
      {
	double calc_sTjet=-999.;
	calc_sTjet =
	  CaloJetPt->at(v_idx_jet_PtCut_noOverlap_ID[0]) + 
	  CaloJetPt->at(v_idx_jet_PtCut_noOverlap_ID[1]) ;
	fillVariableWithValue("sTjet_PAS", calc_sTjet, p1*p2);
      }

    // Mjj
    if (TwoJets)
      {
	TLorentzVector jet1, jet2, jj;
	jet1.SetPtEtaPhiM(CaloJetPt->at(v_idx_jet_PtCut_noOverlap_ID[0]),
			  CaloJetEta->at(v_idx_jet_PtCut_noOverlap_ID[0]),
			  CaloJetPhi->at(v_idx_jet_PtCut_noOverlap_ID[0]),0);
	jet2.SetPtEtaPhiM(CaloJetPt->at(v_idx_jet_PtCut_noOverlap_ID[1]),
			  CaloJetEta->at(v_idx_jet_PtCut_noOverlap_ID[1]),
			  CaloJetPhi->at(v_idx_jet_PtCut_noOverlap_ID[1]),0);
	jj = jet1+jet2;
	//PAS June 2010
	fillVariableWithValue("Mjj_PAS", jj.M(), p1*p2);
      }


    // Mee
    if (TwoEle)
      {
	TLorentzVector ele1, ele2, ee;
	ele1.SetPtEtaPhiM(SuperClusterPt->at(v_idx_sc_Iso[0]),
			  SuperClusterEta->at(v_idx_sc_Iso[0]),
			  SuperClusterPhi->at(v_idx_sc_Iso[0]),0);
	ele2.SetPtEtaPhiM(SuperClusterPt->at(v_idx_sc_Iso[1]),
			  SuperClusterEta->at(v_idx_sc_Iso[1]),
			  SuperClusterPhi->at(v_idx_sc_Iso[1]),0);
	ee = ele1+ele2;
	fillVariableWithValue("Mee", ee.M(), p1*p2);
	//TwoEleOnly
	fillVariableWithValue("Mee_TwoEleOnly", ee.M(), p1*p2);
	fillVariableWithValue("Mee_presel", ee.M(), p1*p2);
	//
	//PAS June 2010
	fillVariableWithValue("Mee_PAS", ee.M(), p1*p2);

	double calc_sTele=-999.;
        calc_sTele =
	  SuperClusterPt->at(v_idx_sc_Iso[0]) +
	  SuperClusterPt->at(v_idx_sc_Iso[1]) ;
	fillVariableWithValue("sTele_PAS", calc_sTele, p1*p2);

	// 	if(isData==true) 
	// 	  {
	// 	    STDOUT("Two electrons: Run, LS, Event = "<<run<<", "<<ls<<", "<<event);
	// 	    STDOUT("Two electrons: M_ee, Pt_ee, Eta_ee, Phi_ee = "<<ee.M() <<", "<< ee.Pt() <<", "<< ee.Eta() <<", "<< ee.Phi());
	// 	    STDOUT("Two electrons: 1st ele Pt, eta, phi = "<< ele1.Pt() <<", "<< ele1.Eta() <<", "<< ele1.Phi() );
	// 	    STDOUT("Two electrons: 2nd ele Pt, eta, phi = "<< ele2.Pt() <<", "<< ele2.Eta() <<", "<< ele2.Phi() );
	// 	  }
      }

    // Mej 
    double Me1j1, Me1j2, Me2j1, Me2j2 = -999;
    double deltaM_e1j1_e2j2 = 9999;
    double deltaM_e1j2_e2j1 = 9999;
    double Mej_1stPair = 0;
    double Mej_2ndPair = 0;
    double deltaR_e1j1 ;
    double deltaR_e2j2 ;
    double deltaR_e1j2 ;
    double deltaR_e2j1 ;
    if ( (TwoEle) && (TwoJets) ) // TwoEle and TwoJets
      {
	TLorentzVector jet1, jet2, ele1, ele2;
	ele1.SetPtEtaPhiM(SuperClusterPt->at(v_idx_sc_Iso[0]),
			  SuperClusterEta->at(v_idx_sc_Iso[0]),
			  SuperClusterPhi->at(v_idx_sc_Iso[0]),0);
	ele2.SetPtEtaPhiM(SuperClusterPt->at(v_idx_sc_Iso[1]),
			  SuperClusterEta->at(v_idx_sc_Iso[1]),
			  SuperClusterPhi->at(v_idx_sc_Iso[1]),0);
	jet1.SetPtEtaPhiM(CaloJetPt->at(v_idx_jet_PtCut_noOverlap_ID[0]),
			  CaloJetEta->at(v_idx_jet_PtCut_noOverlap_ID[0]),
			  CaloJetPhi->at(v_idx_jet_PtCut_noOverlap_ID[0]),0);
	jet2.SetPtEtaPhiM(CaloJetPt->at(v_idx_jet_PtCut_noOverlap_ID[1]),
			  CaloJetEta->at(v_idx_jet_PtCut_noOverlap_ID[1]),
			  CaloJetPhi->at(v_idx_jet_PtCut_noOverlap_ID[1]),0);
	TLorentzVector e1j1, e1j2, e2j1, e2j2;
	e1j1 = ele1 + jet1;
	e2j2 = ele2 + jet2;
	e2j1 = ele2 + jet1;
	e1j2 = ele1 + jet2;
	Me1j1 = e1j1.M();
	Me2j2 = e2j2.M();
	Me1j2 = e1j2.M();
	Me2j1 = e2j1.M();

	deltaM_e1j1_e2j2 = Me1j1 - Me2j2;
	deltaM_e1j2_e2j1 = Me1j2 - Me2j1;


	double deltaR_e1j1 = ele1.DeltaR(jet1);
	double deltaR_e2j2 = ele2.DeltaR(jet2);
	double deltaR_e1j2 = ele1.DeltaR(jet2);
	double deltaR_e2j1 = ele2.DeltaR(jet1);

	// 	// Fill min DR between any of the 2 selected eles and any of the 2 selected jets
	// 	double minDR_2ele_2jet = min ( min(deltaR_e1j1,deltaR_e2j2) , min(deltaR_e1j2,deltaR_e2j1) );
	// 	fillVariableWithValue("minDR_2ele_2jet", minDR_2ele_2jet);

	if(fabs(deltaM_e1j1_e2j2) > fabs(deltaM_e1j2_e2j1))
	  {
	    Mej_1stPair = Me1j2;
	    Mej_2ndPair = Me2j1;
	    fillVariableWithValue("minDRej_selecPairs", min(deltaR_e1j2,deltaR_e2j1), p1*p2 );
	    fillVariableWithValue("minDRej_unselPairs", min(deltaR_e1j1,deltaR_e2j2), p1*p2 );
	  }
	else
	  {
	    Mej_1stPair = Me1j1;
	    Mej_2ndPair = Me2j2;
	    fillVariableWithValue("minDRej_selecPairs", min(deltaR_e1j1,deltaR_e2j2), p1*p2 );
	    fillVariableWithValue("minDRej_unselPairs", min(deltaR_e1j2,deltaR_e2j1), p1*p2 );
	  } 
	fillVariableWithValue("Mej_1stPair", Mej_1stPair, p1*p2);       
	fillVariableWithValue("Mej_2ndPair", Mej_2ndPair, p1*p2);
	//PAS June 2010
	h_Mej_PAS->Fill(Mej_1stPair);
	h_Mej_PAS->Fill(Mej_2ndPair);
	fillVariableWithValue("Mej_1stPair_PAS", Mej_1stPair, p1*p2);       
	fillVariableWithValue("Mej_2ndPair_PAS", Mej_2ndPair, p1*p2);

	// min and max DeltaR between electrons and any jet
	double minDeltaR_ej = 999999;
	double maxDeltaR_ej = -1;
	double thisMinDR, thisMaxDR, DR_thisjet_e1, DR_thisjet_e2;
	TLorentzVector thisjet;
	for(int ijet=0; ijet<v_idx_jet_PtCut_noOverlap_ID.size(); ijet++)
	  {
	    thisjet.SetPtEtaPhiM(CaloJetPt->at(v_idx_jet_PtCut_noOverlap_ID[ijet]),
				 CaloJetEta->at(v_idx_jet_PtCut_noOverlap_ID[ijet]),
				 CaloJetPhi->at(v_idx_jet_PtCut_noOverlap_ID[ijet]),0);
	    DR_thisjet_e1 = thisjet.DeltaR(ele1);
	    DR_thisjet_e2 = thisjet.DeltaR(ele2);
	    thisMinDR = min(DR_thisjet_e1, DR_thisjet_e2);
	    thisMaxDR = max(DR_thisjet_e1, DR_thisjet_e2);
	    if(thisMinDR < minDeltaR_ej)
	      minDeltaR_ej = thisMinDR;
	    if(thisMaxDR > maxDeltaR_ej)
	      maxDeltaR_ej = thisMaxDR;
	  } 
	fillVariableWithValue("minDeltaR_ej", minDeltaR_ej, p1*p2);
	fillVariableWithValue("maxDeltaR_ej", maxDeltaR_ej, p1*p2);

	// 	// printouts for small Mej
	// 	if(isData==true && ( Mej_1stPair<20 || Mej_2ndPair<20 ) ) // printouts for low Mej 
	// 	  {
	// 	    STDOUT("Mej<20GeV: Run, LS, Event = "<<run<<",\t"<<ls<<",\t"<<event);
	// 	    STDOUT("Mej<20GeV: Mej_1stPair = "<<Mej_1stPair <<", Mej_2ndPair = "<< Mej_2ndPair );
	// 	    STDOUT("Mej<20GeV: e1j1.M = "<<e1j1.M() <<", e2j2.M = "<<e2j2.M() <<", e1j2.M = "<<e1j2.M()  <<", e2j1.M = "<<e2j1.M()  );
	// 	    STDOUT("Mej<20GeV: deltaM_e1j1_e2j2 = "<<deltaM_e1j1_e2j2 <<", deltaM_e1j2_e2j1 = "<<deltaM_e1j2_e2j1  );
	// 	    STDOUT("Mej<20GeV: deltaR_e1j1 = "<<deltaR_e1j1 <<", deltaR_e2j2 = "<<deltaR_e2j2 <<", deltaR_e1j2 = "<<deltaR_e1j2  <<", deltaR_e2j1 = "<<deltaR_e2j1  );
	// // 	    STDOUT("Mej<20GeV: 1st ele Pt, eta, phi = "<< ele1.Pt() <<",\t"<< ele1.Eta() <<",\t"<< ele1.Phi() );
	// // 	    STDOUT("Mej<20GeV: 2nd ele Pt, eta, phi = "<< ele2.Pt() <<",\t"<< ele2.Eta() <<",\t"<< ele2.Phi() );
	// // 	    STDOUT("Mej<20GeV: 1st jet Pt, eta, phi = "<< jet1.Pt() <<",\t"<< jet1.Eta() <<",\t"<< jet1.Phi() );
	// // 	    STDOUT("Mej<20GeV: 2nd jet Pt, eta, phi = "<< jet2.Pt() <<",\t"<< jet2.Eta() <<",\t"<< jet2.Phi() );
	// 	    TLorentzVector thisele;
	// 	    for(int iele=0; iele<v_idx_sc_Iso.size(); iele++)
	// 	      {
	// 		thisele.SetPtEtaPhiM(SuperClusterPt->at(v_idx_sc_Iso[iele]),
	// 				     SuperClusterEta->at(v_idx_sc_Iso[iele]),
	// 				     SuperClusterPhi->at(v_idx_sc_Iso[iele]),0);
	// 		STDOUT("Mej<20GeV: e"<<iele+1<<" Pt, eta, phi = " 
	// 		       << ", "<<thisele.Pt()<<", "<< thisele.Eta() <<", "<< thisele.Phi()<<"; DR_j1, DR_j2 = "<< thisele.DeltaR(jet1)<<", "<<thisele.DeltaR(jet2));
	// 	      }
	// 	    TLorentzVector thisjet;
	// 	    TLorentzVector thisjet_e1, thisjet_e2;
	// 	    for(int ijet=0; ijet<v_idx_jet_PtCut_noOverlap_ID.size(); ijet++)
	// 	      {
	// 		thisjet.SetPtEtaPhiM(CaloJetPt->at(v_idx_jet_PtCut_noOverlap_ID[ijet]),
	// 				     CaloJetEta->at(v_idx_jet_PtCut_noOverlap_ID[ijet]),
	// 				     CaloJetPhi->at(v_idx_jet_PtCut_noOverlap_ID[ijet]),0);
	// 		thisjet_e1 = thisjet + ele1;
	// 		thisjet_e2 = thisjet + ele2;
	// 		STDOUT("Mej<20GeV: j"<<ijet+1<<" Pt, eta, phi = " << ", "<<thisjet.Pt()<<", "<< thisjet.Eta() <<", "<< thisjet.Phi()<<"; DR_e1, DR_e2 = "<< thisjet.DeltaR(ele1)<<", "<<thisjet.DeltaR(ele2) << "; M_e1, M_e2 = " <<thisjet_e1.M() <<", "<<thisjet_e2.M() );
	// 	      }
	// 	  } // printouts for low Mej 

      } // TwoEle and TwoJets



    // Evaluate cuts (but do not apply them)
    evaluateCuts();

    // Fill histograms and do analysis based on cut evaluation
    //h_nEleFinal->Fill( ElectronPt->size() );
     

    //     //Large MET events passing pre-selection
    //     float METcut = 60;
    //     if( variableIsFilled("pfMET_PAS") && passedAllPreviousCuts("pfMET_PAS") && isData==true) 
    //       {

    // 	if( getVariableValue("pfMET_PAS") > METcut )
    // 	  {

    // 	    STDOUT("pfMET>60GeV: ----------- START ------------");

    // 	    STDOUT("pfMET>60GeV: Run, LS, Event = "<<run<<",\t"<<ls<<",\t"<<event);	    
    // 	    if( variableIsFilled("Pt1stEle_PAS") && variableIsFilled("Eta1stEle_PAS") )	      
    // 	      STDOUT("pfMET>60GeV: Pt1stEle_PAS,Eta1stEle_PAS = "******"Pt1stEle_PAS")<<",\t"<<getVariableValue("Eta1stEle_PAS"));
    // 	    if( variableIsFilled("Pt2ndEle_PAS") && variableIsFilled("Eta2ndEle_PAS") )	      
    // 	      STDOUT("pfMET>60GeV: Pt2ndEle_PAS,Eta2ndEle_PAS = "******"Pt2ndEle_PAS")<<",\t"<<getVariableValue("Eta2ndEle_PAS"));
    // 	    if( variableIsFilled("Pt1stJet_PAS") && variableIsFilled("Eta1stJet_PAS") )	      
    // 	      STDOUT("pfMET>60GeV: Pt1stJet_PAS,Eta1stJet_PAS = "******"Pt1stJet_PAS")<<",\t"<<getVariableValue("Eta1stJet_PAS"));
    // 	    if( variableIsFilled("Pt2ndJet_PAS") && variableIsFilled("Eta2ndJet_PAS") )	      
    // 	      STDOUT("pfMET>60GeV: Pt2ndJet_PAS,Eta2ndJet_PAS = "******"Pt2ndJet_PAS")<<",\t"<<getVariableValue("Eta2ndJet_PAS"));
    // 	    if( variableIsFilled("Mee_PAS") && variableIsFilled("Mjj_PAS") )	      
    // 	      STDOUT("pfMET>60GeV: Mee_PAS,Mjj_PAS = "******"Mee_PAS")<<",\t"<<getVariableValue("Mjj_PAS"));
    // 	    if( variableIsFilled("Mej_1stPair_PAS") && variableIsFilled("Mej_2ndPair_PAS") )	      
    // 	      STDOUT("pfMET>60GeV: Mej_1stPair_PAS,Mej_2ndPair_PAS = "******"Mej_1stPair_PAS")
    // 		     <<",\t"<<getVariableValue("Mej_2ndPair_PAS"));
    // 	    if( variableIsFilled("pfMET_PAS") && variableIsFilled("caloMET_PAS") )	      
    // 	      STDOUT("pfMET>60GeV: pfMET_PAS,caloMET_PAS = "******"pfMET_PAS")<<",\t"<<getVariableValue("caloMET_PAS"));

    // 	    STDOUT("pfMET>60GeV: ------------ END -------------");

    // 	  }
    //       }


    //INFO
    //      // retrieve value of previously filled variables (after making sure that they were filled)
    //      double totpTEle;
    //      if ( variableIsFilled("pT1stEle") && variableIsFilled("pT2ndEle") ) 
    //        totpTEle = getVariableValue("pT1stEle")+getVariableValue("pT2ndEle");
    //      // reject events that did not pass level 0 cuts
    //      if( !passedCut("0") ) continue;
    //      // ......

        
    ////////////////////// User's code to be done for every event - END ///////////////////////
    
  } // End of loop over events
  

  ////////////////////// User's code to write histos - BEGIN ///////////////////////

  h_Mej_PAS->Write();

  ////////////////////// User's code to write histos - END ///////////////////////
  
  
  //STDOUT("analysisClass::Loop() ends");   
}
void analysisClass::Loop()
{
  //STDOUT("analysisClass::Loop() begins");
  
  if (fChain == 0) return;
   
  ////////////////////// User's code to book histos - BEGIN ///////////////////////

  TH1F *h_Mlj_PAS = new TH1F ("h_Mlj_PAS","h_Mlj_PAS",200,0,2000);  h_Mlj_PAS->Sumw2();

  ////////////////////// User's code to book histos - END ///////////////////////

  ////////////////////// User's code to get preCut values - BEGIN ///////////////

  double eleEta_bar = getPreCutValue1("eleEta_bar");
  double eleEta_end_min = getPreCutValue1("eleEta_end");
  double eleEta_end_max = getPreCutValue2("eleEta_end");

  double EleEnergyScale_EB=getPreCutValue1("EleEnergyScale_EB");
  double EleEnergyScale_EE=getPreCutValue1("EleEnergyScale_EE");
  double JetEnergyScale=getPreCutValue1("JetEnergyScale");

  // Not used when using ElectronHeepID and heepBitMask // int eleIDType = (int) getPreCutValue1("eleIDType");
  int heepBitMask_EB  =  getPreCutValue1("heepBitMask_EBGapEE") ;
  int heepBitMask_GAP =  getPreCutValue2("heepBitMask_EBGapEE") ;

  int heepBitMask_EE  =  getPreCutValue3("heepBitMask_EBGapEE") ;

  int looseBitMask_EB       =  getPreCutValue1("looseBitMask_EBGapEE") ;
  int looseBitMask_GAP      =  getPreCutValue2("looseBitMask_EBGapEE") ;
  int looseBitMask_EE       =  getPreCutValue3("looseBitMask_EBGapEE") ;
  int looseBitMask_enabled  =  getPreCutValue4("looseBitMask_EBGapEE") ;

  double muon_PtCut = getPreCutValue1("muon_PtCut");
  double muFidRegion = getPreCutValue1("muFidRegion"); // currently unused !!!
  double muNHits_minThresh = getPreCutValue1("muNHits_minThresh");
  double muTrkD0Maximum = getPreCutValue1("muTrkD0Maximum");

  int jetAlgorithm = getPreCutValue1("jetAlgorithm");
  int metAlgorithm = getPreCutValue1("metAlgorithm");

  ////////////////////// User's code to get preCut values - END /////////////////
    
  Long64_t nentries = fChain->GetEntriesFast();
  STDOUT("analysisClass::Loop(): nentries = " << nentries);   
  
  ////// The following ~7 lines have been taken from rootNtupleClass->Loop() /////
  ////// If the root version is updated and rootNtupleClass regenerated,     /////
  ////// these lines may need to be updated.                                 /////    
  Long64_t nbytes = 0, nb = 0;
  for (Long64_t jentry=0; jentry<nentries;jentry++) { // Begin of loop over events
    Long64_t ientry = LoadTree(jentry);
    if (ientry < 0) break;
    nb = fChain->GetEntry(jentry);   nbytes += nb;
    if(jentry < 10 || jentry%1000 == 0) STDOUT("analysisClass::Loop(): jentry = " << jentry);   
    // if (Cut(ientry) < 0) continue;
    
    ////////////////////// User's code to be done for every event - BEGIN ///////////////////////

    //## Define new jet collection
    std::auto_ptr<std::vector<double> >  JetPt  ( new std::vector<double>()  );
    std::auto_ptr<std::vector<double> >  JetPtRaw  ( new std::vector<double>()  );
    std::auto_ptr<std::vector<double> >  JetEnergy  ( new std::vector<double>()  );
    std::auto_ptr<std::vector<double> >  JetEta  ( new std::vector<double>()  );
    std::auto_ptr<std::vector<double> >  JetPhi  ( new std::vector<double>()  );
    std::auto_ptr<std::vector<int> >     JetPassID  ( new std::vector<int>()  );
    std::auto_ptr<std::vector<double> >  JetTCHE  ( new std::vector<double>()  );

    if(jetAlgorithm==1) //PF jets
      {
	for (int ijet=0 ; ijet< PFJetPt->size() ; ijet++)
	  {
	    JetPt->push_back( PFJetPt->at(ijet) );
	    JetPtRaw->push_back( PFJetPtRaw->at(ijet) );
	    JetEnergy->push_back( PFJetEnergy->at(ijet) );
	    JetEta->push_back( PFJetEta->at(ijet) );
	    JetPhi->push_back( PFJetPhi->at(ijet) );
            JetPassID->push_back( PFJetPassLooseID->at(ijet) );
	    //     JetPassID->push_back(
	    //  PFJetIdloose(PFJetChargedHadronEnergyFraction->at(ijet),
	    //       PFJetChargedEmEnergyFraction->at(ijet),
	    //       PFJetNeutralHadronEnergyFraction->at(ijet),
	    //       PFJetNeutralEmEnergyFraction->at(ijet),
	    //       PFJetEta->at(ijet) )
	    //  );
            JetTCHE->push_back( PFJetTrackCountingHighEffBTag->at(ijet) );
	  }//end loop over pf jets
      }//end if "pf jets"

    if(jetAlgorithm==2) //Calo jets
      {
	for (int ijet=0 ; ijet < CaloJetPt->size() ; ijet++)
	  {
	    JetPt->push_back( CaloJetPt->at(ijet) );
	    JetPtRaw->push_back( CaloJetPtRaw->at(ijet) );
	    JetEnergy->push_back( CaloJetEnergy->at(ijet) );
	    JetEta->push_back( CaloJetEta->at(ijet) );
	    JetPhi->push_back( CaloJetPhi->at(ijet) );
            JetPassID->push_back( CaloJetPassLooseID->at(ijet) );
	    //     JetPassID->push_back(
	    //  JetIdloose(CaloJetresEMF->at(ijet),
	    //     CaloJetfHPD->at(ijet),
	    //     CaloJetn90Hits->at(ijet),
	    //     CaloJetEta->at(ijet) )
	    //  );
            JetTCHE->push_back( CaloJetTrackCountingHighEffBTag->at(ijet) );
	  }//end loop over calo jets
      }//end if "calo jets"

    //## Define new met collection
    double thisMET;
    double thisMETPhi;
    double thisSumET;
    double thisGenSumET;

    if(isData==0)
      thisGenSumET = GenSumETTrue->at(0);
    else
      thisGenSumET = -1;

    if(metAlgorithm==1) // --> PFMET
      {
	thisMET = PFMET->at(0);
	thisMETPhi = PFMETPhi->at(0);
	thisSumET = PFSumET->at(0);
      }
    if(metAlgorithm==2) // --> CaloMET
      {
	thisMET = CaloMET->at(0);
	thisMETPhi = CaloMETPhi->at(0);
	thisSumET = CaloSumET->at(0);
      }
    if(metAlgorithm==3) // --> PFMET (with type-1 corrections)
      {
	thisMET = PFMETType1Cor->at(0);
	thisMETPhi = PFMETPhiType1Cor->at(0);
	thisSumET = PFSumETType1Cor->at(0);
      }


    // EES and JES
    if( EleEnergyScale_EB != 1 || EleEnergyScale_EE != 1 )
      {
	for(int iele=0; iele<ElectronPt->size(); iele++)
	  {
	    if( fabs(ElectronEta->at(iele)) < eleEta_bar )
	      ElectronPt->at(iele) *= EleEnergyScale_EB;
	    if( fabs(ElectronEta->at(iele)) > eleEta_end_min && fabs(ElectronEta->at(iele)) < eleEta_end_max )
	      ElectronPt->at(iele) *= EleEnergyScale_EE;
	  }
      }
    if( JetEnergyScale != 1 )
      {
	for(int ijet=0; ijet<JetPt->size(); ijet++)
	  {
	    JetPt->at(ijet) *= JetEnergyScale;
	    JetEnergy->at(ijet) *= JetEnergyScale;
	  }
      }

    //## HLT
    int PassTrig = 0;
    int HLTFromRun[4] = {getPreCutValue1("HLTFromRun"),
			 getPreCutValue2("HLTFromRun"),
			 getPreCutValue3("HLTFromRun"),
			 getPreCutValue4("HLTFromRun")};
    int HLTTrigger[4] = {getPreCutValue1("HLTTrigger"),
			 getPreCutValue2("HLTTrigger"),
			 getPreCutValue3("HLTTrigger"),
			 getPreCutValue4("HLTTrigger")};
    int HLTTrgUsed;
    for (int i=0; i<4; i++) {
      if ( !isData && i != 0) continue; // For MC use HLTPhoton15 as the cleaned trigger is not in MC yet as of July 20, 2010
      if ( HLTFromRun[i] <= run ) {
 	//if(jentry == 0 ) STDOUT("run, i, HLTTrigger[i], HLTFromRun[i] = "<<run<<"\t"<<i<<"\t"<<"\t"<<HLTTrigger[i]<<"\t"<<HLTFromRun[i]);
	if (HLTTrigger[i] > 0 && HLTTrigger[i] < HLTResults->size() ) {
	  PassTrig=HLTResults->at(HLTTrigger[i]);
	  HLTTrgUsed=HLTTrigger[i];
	} else {
	  STDOUT("ERROR: HLTTrigger out of range of HLTResults: HLTTrigger = "<<HLTTrigger[i] <<"and HLTResults size = "<< HLTResults->size());
	}
      }
    }
    if(jentry == 0 ) STDOUT("Run = "<<run <<", HLTTrgUsed is number = "<<HLTTrgUsed<<" of the list HLTPathsOfInterest");

    // Electrons
    vector<int> v_idx_ele_all;
    vector<int> v_idx_ele_PtCut;
    vector<int> v_idx_ele_PtCut_IDISO_noOverlap;
    int heepBitMask;

    //Loop over electrons
    for(int iele=0; iele<ElectronPt->size(); iele++)
      {

	// Reject ECAL spikes
	if ( 1 - ElectronSCS4S1->at(iele) > 0.95 ) continue; 

	//no cut on reco electrons
	v_idx_ele_all.push_back(iele); 

	//pT pre-cut on ele
	if( ElectronPt->at(iele) < getPreCutValue1("ele_PtCut") ) continue; 
	v_idx_ele_PtCut.push_back(iele);

	// get heepBitMask for EB, GAP, EE 
	if( fabs(ElectronEta->at(iele)) < eleEta_bar ) 
	  {
	    heepBitMask = heepBitMask_EB;
	  }
	else if ( fabs(ElectronEta->at(iele)) > eleEta_end_min && fabs(ElectronEta->at(iele)) < eleEta_end_max ) 
	  {
	    heepBitMask = heepBitMask_EE;
	  }
	else {
	    heepBitMask = heepBitMask_GAP;
	}

	//ID + ISO + NO overlap with good muons 
	// int eleID = ElectronPassID->at(iele);
	// if ( (eleID & 1<<eleIDType) > 0  && ElectronOverlaps->at(iele)==0 )
	if ( (ElectronHeepID->at(iele) & ~heepBitMask)==0x0  && ElectronOverlaps->at(iele)==0 )
	  {
	    //STDOUT("ElectronHeepID = " << hex << ElectronHeepID->at(iele) << " ; ElectronPassID = " << ElectronPassID->at(iele) )
	    v_idx_ele_PtCut_IDISO_noOverlap.push_back(iele);
	  }

      } // End loop over electrons

    // tight-loose electrons, if enabled from cut file
    if ( looseBitMask_enabled == 1 && v_idx_ele_PtCut_IDISO_noOverlap.size() == 1 )
      {
	//STDOUT("v_idx_ele_PtCut_IDISO_noOverlap[0] = "<<v_idx_ele_PtCut_IDISO_noOverlap[0] << " - Pt = "<<ElectronPt->at(v_idx_ele_PtCut_IDISO_noOverlap[0]));
	bool loosePtLargerThanTightPt = true;
	for(int iele=0; iele<v_idx_ele_PtCut.size(); iele++)
	  {
	    
	    if (v_idx_ele_PtCut[iele] == v_idx_ele_PtCut_IDISO_noOverlap[0])
	      {
		loosePtLargerThanTightPt = false;
		continue;
	      }
	    // get looseBitMask for EB, GAP, EE 

	    int looseBitMask;
	    if( fabs(ElectronEta->at(v_idx_ele_PtCut[iele])) < eleEta_bar ) 
	      {
		looseBitMask = looseBitMask_EB;
	      }
	    else if ( fabs(ElectronEta->at(v_idx_ele_PtCut[iele])) > eleEta_end_min && fabs(ElectronEta->at(v_idx_ele_PtCut[iele])) < eleEta_end_max ) 
	      {
		looseBitMask = looseBitMask_EE;
	      }
	    else {
	      looseBitMask = looseBitMask_GAP;
	    }
	    if ( (ElectronHeepID->at(v_idx_ele_PtCut[iele]) & ~looseBitMask)==0x0  && ElectronOverlaps->at(v_idx_ele_PtCut[iele])==0 )
	      {
		if ( loosePtLargerThanTightPt )
		  {
		    v_idx_ele_PtCut_IDISO_noOverlap.insert(v_idx_ele_PtCut_IDISO_noOverlap.begin(),1,v_idx_ele_PtCut[iele]);
		  }
		else 
		  {
		    v_idx_ele_PtCut_IDISO_noOverlap.push_back(v_idx_ele_PtCut[iele]);
		  }
		break; // happy with one loose electron - Note: if you want more than 1 loose, pt sorting will not be OK with the code as is. 
	      }
	  }	
// 	for ( int i=0; i<v_idx_ele_PtCut_IDISO_noOverlap.size(); i++)
// 	  {
// 	    STDOUT("i="<<i<<", v_idx_ele_PtCut_IDISO_noOverlap[i] = "<<v_idx_ele_PtCut_IDISO_noOverlap[i] << ", Pt = "<<ElectronPt->at(v_idx_ele_PtCut_IDISO_noOverlap[i]));
// 	  }
      } // tight-loose electrons, if enabled from cut file


    // Muons
    vector<int> v_idx_muon_all;
    vector<int> v_idx_muon_PtCut;
    vector<int> v_idx_muon_PtCut_IDISO;
    
    // Loop over muons  
    for(int imuon=0; imuon<MuonPt->size(); imuon++){

      // no cut on reco muons
      v_idx_muon_all.push_back(imuon);

      if ( (*MuonPt)[imuon] < muon_PtCut) continue;

      // pT pre-cut on muons
      v_idx_muon_PtCut.push_back(imuon);
      
      if ( ((*MuonTrkHits)[imuon]  >= muNHits_minThresh  )&&( fabs((*MuonTrkD0)[imuon]) < muTrkD0Maximum ) &&((*MuonPassIso)[imuon]==1 ) &&((*MuonPassID)[imuon]==1) ) 
	{
	  v_idx_muon_PtCut_IDISO.push_back(imuon);
	}
    }// end loop over muons


    // Jets
    vector<int> v_idx_jet_all;
    vector<int> v_idx_jet_PtCut;
    vector<int> v_idx_jet_PtCut_noOverlap;
    vector<int> v_idx_jet_PtCut_noOverlap_ID;
    vector<int> v_idx_jet_PtCut_noOverlap_ID_EtaCut;

    // Loop over jets
    for(int ijet=0; ijet<JetPt->size(); ijet++)
      {
	//no cut on reco jets
	v_idx_jet_all.push_back(ijet);

	//pT pre-cut on reco jets
	if ( JetPt->at(ijet) < getPreCutValue1("jet_PtCut") ) continue;
	v_idx_jet_PtCut.push_back(ijet);
      }

// 	//Checking overlap between electrons and jets
// 	int JetOverlapsWithEle = 0; //don't change the default (0) 
// 	float minDeltaR=9999.;
// 	TVector3 jet_vec;
// 	jet_vec.SetPtEtaPhi(JetPt->at(ijet),JetEta->at(ijet),JetPhi->at(ijet));
// 	for (int i=0; i < v_idx_ele_PtCut_IDISO_noOverlap.size(); i++){
// 	  TVector3 ele_vec;	  
// 	  ele_vec.SetPtEtaPhi(ElectronPt->at(v_idx_ele_PtCut_IDISO_noOverlap[i])
// 			      ,ElectronEta->at(v_idx_ele_PtCut_IDISO_noOverlap[i])
// 			      ,ElectronPhi->at(v_idx_ele_PtCut_IDISO_noOverlap[i]));
// 	  double distance = jet_vec.DeltaR(ele_vec);
// 	  if (distance<minDeltaR) minDeltaR=distance;
// 	}
// 	if ( minDeltaR < getPreCutValue1("jet_ele_DeltaRcut") )
// 	  JetOverlapsWithEle = 1; //this jet overlaps with a good electron --> remove it from the analysis

// 	//pT pre-cut + no overlaps with electrons
// 	// ---- use the flag stored in rootTuples
// 	//if( ( JetOverlaps->at(ijet) & 1 << eleIDType) == 0)/* NO overlap with electrons */  
// 	// && (caloJetOverlaps[ijet] & 1 << 5)==0 )/* NO overlap with muons */   
// 	// ----
// 	if( JetOverlapsWithEle == 0 )  /* NO overlap with electrons */  
// 	  v_idx_jet_PtCut_noOverlap.push_back(ijet);

    vector <int> jetFlags(v_idx_jet_PtCut.size(), 0);
    int Njetflagged = 0;
    for (int iele=0; iele<v_idx_ele_PtCut_IDISO_noOverlap.size(); iele++)
      {
	TLorentzVector ele;
        ele.SetPtEtaPhiM(ElectronPt->at(v_idx_ele_PtCut_IDISO_noOverlap[iele]),
			 ElectronEta->at(v_idx_ele_PtCut_IDISO_noOverlap[iele]),
			 ElectronPhi->at(v_idx_ele_PtCut_IDISO_noOverlap[iele]),0);
	TLorentzVector jet;
	double minDR=9999.;
	int ijet_minDR = -1;    
        for(int ijet=0; ijet<v_idx_jet_PtCut.size(); ijet++)
          {
	    if ( jetFlags[ijet] == 1 ) 
	      continue;
            jet.SetPtEtaPhiM(JetPt->at(v_idx_jet_PtCut[ijet]),
			     JetEta->at(v_idx_jet_PtCut[ijet]),
			     JetPhi->at(v_idx_jet_PtCut[ijet]),0);
	    double DR = jet.DeltaR(ele);
	    if (DR<minDR) 
	      {
		minDR = DR;
		ijet_minDR = ijet;
	      }
	  }
	if ( minDR < getPreCutValue1("jet_ele_DeltaRcut") && ijet_minDR > -1)
	  {
	    jetFlags[ijet_minDR] = 1;
	    Njetflagged++;
	  }
      }

//     // printouts for jet cleaning
//     STDOUT("CLEANING ----------- v_idx_ele_PtCut_IDISO_noOverlap.size = "<< v_idx_ele_PtCut_IDISO_noOverlap.size() <<", Njetflagged = "<< Njetflagged<<", diff="<< v_idx_ele_PtCut_IDISO_noOverlap.size()-Njetflagged );
//     if( (v_idx_ele_PtCut_IDISO_noOverlap.size()-Njetflagged) == 1 ) 
//       {
// 	TLorentzVector thisele;
// 	for(int iele=0; iele<v_idx_ele_PtCut_IDISO_noOverlap.size(); iele++)
// 	  {
// 	    thisele.SetPtEtaPhiM(ElectronPt->at(v_idx_ele_PtCut_IDISO_noOverlap[iele]),
// 				 ElectronEta->at(v_idx_ele_PtCut_IDISO_noOverlap[iele]),
// 				 ElectronPhi->at(v_idx_ele_PtCut_IDISO_noOverlap[iele]),0);
// 	    STDOUT("CLEANING: e"<<iele+1<<" Pt, eta, phi = "  << ", "<<thisele.Pt()<<", "<< thisele.Eta() <<", "<< thisele.Phi());
// 	  }
// 	TLorentzVector thisjet;
// 	for(int ijet=0; ijet<v_idx_jet_PtCut.size(); ijet++)
// 	  {
// 	    thisjet.SetPtEtaPhiM(JetPt->at(v_idx_jet_PtCut[ijet]),
// 				 JetEta->at(v_idx_jet_PtCut[ijet]),
// 				 JetPhi->at(v_idx_jet_PtCut[ijet]),0);
// 	    STDOUT("CLEANING: j"<<ijet+1<<" Pt, eta, phi = " << ", "<<thisjet.Pt()<<", "<< thisjet.Eta() <<", "<< thisjet.Phi()<<" jetFlags="<<jetFlags[ijet] );
// 	  }
//       } // printouts for jet cleaning
    
    // Flagging jets if they overlap with muons
    vector <int> jetFlags_muon(v_idx_jet_PtCut.size(), 0);
    int Njetflagged_muon = 0;
    for (int imuon=0; imuon<v_idx_muon_PtCut_IDISO.size(); imuon++)
      {
	TLorentzVector muon;
        muon.SetPtEtaPhiM(MuonPt->at(v_idx_muon_PtCut_IDISO[imuon]),
			  MuonEta->at(v_idx_muon_PtCut_IDISO[imuon]),
			  MuonPhi->at(v_idx_muon_PtCut_IDISO[imuon]),0);
	TLorentzVector jet;
	double minDR=9999.;
	int ijet_minDR = -1;    
        for(int ijet=0; ijet<v_idx_jet_PtCut.size(); ijet++)
          {
	    if ( jetFlags_muon[ijet] == 1 ) 
	      continue;
            jet.SetPtEtaPhiM(JetPt->at(v_idx_jet_PtCut[ijet]),
			     JetEta->at(v_idx_jet_PtCut[ijet]),
			     JetPhi->at(v_idx_jet_PtCut[ijet]),0);
	    double DR = jet.DeltaR(muon);
	    if (DR<minDR) 
	      {
		minDR = DR;
		ijet_minDR = ijet;
	      }
	  }
	if ( minDR < getPreCutValue1("jet_muon_DeltaRcut") && ijet_minDR > -1)
	  {
	    jetFlags_muon[ijet_minDR] = 1;
	    Njetflagged_muon++;
	  }
      }

    
    float JetEtaCutValue = getPreCutValue1("jet_EtaCut");
    for(int ijet=0; ijet<v_idx_jet_PtCut.size(); ijet++) //pT pre-cut + no overlaps with electrons + jetID
      {	
	bool passjetID = JetPassID->at(v_idx_jet_PtCut[ijet]);
	//bool passjetID = JetIdloose(CaloJetresEMF->at(v_idx_jet_PtCut[ijet]),CaloJetfHPD->at(v_idx_jet_PtCut[ijet]),CaloJetn90Hits->at(v_idx_jet_PtCut[ijet]), CaloJetEta->at(v_idx_jet_PtCut[ijet]));
	// ---- use the flag stored in rootTuples
	//if( (JetOverlaps->at(v_idx_jet_PtCut[ijet]) & 1 << eleIDType) == 0  /* NO overlap with electrons */  
	// ----

	if( jetFlags[ijet] == 0                            /* NO overlap with electrons */  
	    && jetFlags_muon[ijet] == 0 )                  /* NO overlap with muons */
	  //  && passjetID == true )                            /* pass JetID */
	  // && (caloJetOverlaps[ijet] & 1 << 5)==0 )         /* NO overlap with muons */      
	  v_idx_jet_PtCut_noOverlap.push_back(v_idx_jet_PtCut[ijet]);

	if( jetFlags[ijet] == 0                            /* NO overlap with electrons */  
	    && jetFlags_muon[ijet] == 0                    /* NO overlap with muons */
	    && passjetID == true )                            /* pass JetID */
	  // && (caloJetOverlaps[ijet] & 1 << 5)==0 )         /* NO overlap with muons */      
	  v_idx_jet_PtCut_noOverlap_ID.push_back(v_idx_jet_PtCut[ijet]);

	if( jetFlags[ijet] == 0                           /* NO overlap with electrons */  
	    && jetFlags_muon[ijet] == 0                   /* NO overlap with muons */
	    && passjetID == true                             /* pass JetID */
	    && fabs( JetEta->at(v_idx_jet_PtCut[ijet]) ) < JetEtaCutValue )
	  // && (caloJetOverlaps[ijet] & 1 << 5)==0 )         /* NO overlap with muons */      
	  v_idx_jet_PtCut_noOverlap_ID_EtaCut.push_back(v_idx_jet_PtCut[ijet]);

	
	//NOTE: We should verify that caloJetOverlaps match with the code above
      } // End loop over jets
    


    // Set the evaluation of the cuts to false and clear the variable values and filled status
    resetCuts();
    

    // Set the value of the variableNames listed in the cutFile to their current value
    
    // Trigger (L1 and HLT)
    if(isData==true)
      {
	fillVariableWithValue( "PassBPTX0", isBPTX0 ) ;
	fillVariableWithValue( "PassPhysDecl", isPhysDeclared ) ;       
      }
    else
      {
	fillVariableWithValue( "PassBPTX0", true ) ;
	fillVariableWithValue( "PassPhysDecl", true ) ;       
      }

    fillVariableWithValue( "PassHLT", PassTrig ) ;

    //Event filters at RECO level
    fillVariableWithValue( "PassBeamScraping", !isBeamScraping ) ;
    fillVariableWithValue( "PassPrimaryVertex", isPrimaryVertex ) ;
    //    fillVariableWithValue( "PassHBHENoiseFilter", passLooseNoiseFilter ) ;

    // nMu
    fillVariableWithValue( "nMu_all", MuonPt->size() ) ;
    fillVariableWithValue( "nMu_PtCut", v_idx_muon_PtCut.size() ) ;
    fillVariableWithValue( "nMu_PtCut_IDISO", v_idx_muon_PtCut_IDISO.size() ) ;

    // nEle
    fillVariableWithValue( "nEle_all", v_idx_ele_all.size() ) ;
    fillVariableWithValue( "nEle_PtCut", v_idx_ele_PtCut.size() ) ;
    fillVariableWithValue( "nEle_PtCut_IDISO_noOvrlp", v_idx_ele_PtCut_IDISO_noOverlap.size() ) ;

    // nLeptons
    fillVariableWithValue( "nLept_PtCut_IDISO", v_idx_ele_PtCut_IDISO_noOverlap.size()+v_idx_muon_PtCut_IDISO.size() ) ;
     
    // nJet
    fillVariableWithValue( "nJet_all", v_idx_jet_all.size() ) ;
    fillVariableWithValue( "nJet_PtCut", v_idx_jet_PtCut.size() ) ;
    fillVariableWithValue( "nJet_PtCut_noOvrlp", v_idx_jet_PtCut_noOverlap.size() ) ;
    fillVariableWithValue( "nJet_PtCut_noOvrlp_ID", v_idx_jet_PtCut_noOverlap_ID.size() ) ;
    //OneEleOneMu
    fillVariableWithValue( "nJet_OneEleOneMu_All", v_idx_jet_PtCut_noOverlap_ID.size() ) ;
    fillVariableWithValue( "nJet_OneEleOneMu_EtaCut", v_idx_jet_PtCut_noOverlap_ID_EtaCut.size() ) ;
    //PAS June 2010
    fillVariableWithValue( "nJet_PAS_All", v_idx_jet_PtCut_noOverlap_ID.size() ) ;
    fillVariableWithValue( "nJet_PAS_EtaCut", v_idx_jet_PtCut_noOverlap_ID_EtaCut.size() ) ;

    // MET
    //PAS June 2010
    fillVariableWithValue( "MET_PAS", thisMET ) ;
    fillVariableWithValue( "METPhi_PAS", thisMETPhi);
    fillVariableWithValue( "pfMET_PAS", PFMET->at(0) ) ;
    fillVariableWithValue( "tcMET_PAS", TCMET->at(0) ) ;
    fillVariableWithValue( "caloMET_PAS", CaloMET->at(0) ) ;
    TVector2 v_MET;
    v_MET.SetMagPhi( thisMET , thisMETPhi);

    // 1st ele
    if( v_idx_ele_PtCut_IDISO_noOverlap.size() >= 1 ) 
      {
	fillVariableWithValue( "Pt1stEle_IDISO_NoOvrlp", ElectronPt->at(v_idx_ele_PtCut_IDISO_noOverlap[0]) );
	fillVariableWithValue( "Eta1stEle_IDISO_NoOvrlp", ElectronEta->at(v_idx_ele_PtCut_IDISO_noOverlap[0]) );
	fillVariableWithValue( "mEta1stEle_IDISO_NoOvrlp", fabs(ElectronEta->at(v_idx_ele_PtCut_IDISO_noOverlap[0])) );
	//PAS June 2010
	fillVariableWithValue( "Pt1stEle_PAS", ElectronPt->at(v_idx_ele_PtCut_IDISO_noOverlap[0]) );
	fillVariableWithValue( "Eta1stEle_PAS", ElectronEta->at(v_idx_ele_PtCut_IDISO_noOverlap[0]) );
        fillVariableWithValue( "Phi1stEle_PAS", ElectronPhi->at(v_idx_ele_PtCut_IDISO_noOverlap[0]) );
	// transverse mass ele+MET
	TVector2 v_ele;
	v_ele.SetMagPhi( ElectronPt->at(v_idx_ele_PtCut_IDISO_noOverlap[0]) , ElectronPhi->at(v_idx_ele_PtCut_IDISO_noOverlap[0]) );
	double deltaphi = v_MET.DeltaPhi(v_ele);
	double MT_eleMET = sqrt(2 * v_ele.Mod() * thisMET * (1 - cos(deltaphi)) );
	fillVariableWithValue("MT_eleMET", MT_eleMET);
      }

    // 1st muon
    if( v_idx_muon_PtCut_IDISO.size() >= 1 ) 
      {
	fillVariableWithValue( "Pt1stMu_IDISO", MuonPt->at(v_idx_muon_PtCut_IDISO[0]) );
	fillVariableWithValue( "Eta1stMu_IDISO", MuonEta->at(v_idx_muon_PtCut_IDISO[0]) );
	fillVariableWithValue( "mEta1stMu_IDISO", fabs(MuonEta->at(v_idx_muon_PtCut_IDISO[0])) );
	//PAS June 2010
	fillVariableWithValue( "Pt1stMu_PAS", MuonPt->at(v_idx_muon_PtCut_IDISO[0]) );
	fillVariableWithValue( "Eta1stMu_PAS", MuonEta->at(v_idx_muon_PtCut_IDISO[0]) );
        fillVariableWithValue( "Phi1stMu_PAS", MuonPhi->at(v_idx_muon_PtCut_IDISO[0]) );
	// transverse mass ele+MET
	TVector2 v_muon;
	v_muon.SetMagPhi( MuonPt->at(v_idx_muon_PtCut_IDISO[0]) , MuonPhi->at(v_idx_muon_PtCut_IDISO[0]) );
	double deltaphi = v_MET.DeltaPhi(v_muon);
	double MT_muonMET = sqrt(2 * v_muon.Mod() * thisMET * (1 - cos(deltaphi)) );
	fillVariableWithValue("MT_muonMET", MT_muonMET);
      }

    // 1st jet
    if( v_idx_jet_PtCut_noOverlap_ID.size() >= 1 ) 
      {
	fillVariableWithValue( "Pt1stJet_noOvrlp_ID", JetPt->at(v_idx_jet_PtCut_noOverlap_ID[0]) );
	fillVariableWithValue( "Eta1stJet_noOvrlp_ID", JetEta->at(v_idx_jet_PtCut_noOverlap_ID[0]) );
	fillVariableWithValue( "mEta1stJet_noOvrlp_ID", fabs(JetEta->at(v_idx_jet_PtCut_noOverlap_ID[0])) );
	//PAS June 2010
	fillVariableWithValue( "Pt1stJet_PAS", JetPt->at(v_idx_jet_PtCut_noOverlap_ID[0]) );
	fillVariableWithValue( "Eta1stJet_PAS", JetEta->at(v_idx_jet_PtCut_noOverlap_ID[0]) );
        fillVariableWithValue( "Phi1stJet_PAS", JetPhi->at(v_idx_jet_PtCut_noOverlap_ID[0]) );
      }


    //cout << "2nd Jet" << endl;
    //## 2nd jet
    if( v_idx_jet_PtCut_noOverlap_ID.size() >= 2 ) 
      {
	fillVariableWithValue( "Pt2ndJet_noOvrlp_ID", JetPt->at(v_idx_jet_PtCut_noOverlap_ID[1]) );
	fillVariableWithValue( "Eta2ndJet_noOvrlp_ID", JetEta->at(v_idx_jet_PtCut_noOverlap_ID[1]) );
	fillVariableWithValue( "mEta2ndJet_noOvrlp_ID", fabs(JetEta->at(v_idx_jet_PtCut_noOverlap_ID[1])) );
	fillVariableWithValue( "maxMEtaJets_noOvrlp_ID", max( getVariableValue("mEta1stJet_noOvrlp_ID"), getVariableValue("mEta2ndJet_noOvrlp_ID") ) );
	//PAS June 2010
	fillVariableWithValue( "Pt2ndJet_PAS", JetPt->at(v_idx_jet_PtCut_noOverlap_ID[1]) );
	fillVariableWithValue( "Eta2ndJet_PAS", JetEta->at(v_idx_jet_PtCut_noOverlap_ID[1]) );
        fillVariableWithValue( "Phi2ndJet_PAS", JetPhi->at(v_idx_jet_PtCut_noOverlap_ID[1]) );
      }

    //## define "1ele+1muon" and "2jets" booleans
    bool OneEleOneMu=false;
    bool TwoJets=false;
    if( v_idx_ele_PtCut_IDISO_noOverlap.size() >= 1 && v_idx_muon_PtCut_IDISO.size() >= 1 ) OneEleOneMu = true;
    if( v_idx_jet_PtCut_noOverlap_ID.size() >= 2 ) TwoJets = true;

    // ST
    double calc_sT=-999.; 
    if ( (OneEleOneMu) && (TwoJets) ) 
      {
	calc_sT = 
	  ElectronPt->at(v_idx_ele_PtCut_IDISO_noOverlap[0]) +
	  MuonPt->at(v_idx_muon_PtCut_IDISO[0]) +
	  JetPt->at(v_idx_jet_PtCut_noOverlap_ID[0]) +
	  JetPt->at(v_idx_jet_PtCut_noOverlap_ID[1]);
	fillVariableWithValue("sT", calc_sT);
	fillVariableWithValue("sT_MLQ250", calc_sT);
	fillVariableWithValue("sT_MLQ280", calc_sT);
	fillVariableWithValue("sT_MLQ300", calc_sT);
	fillVariableWithValue("sT_MLQ320", calc_sT);
	fillVariableWithValue("sT_MLQ340", calc_sT);
	fillVariableWithValue("sT_MLQ400", calc_sT);       
	//PAS June 2010
	fillVariableWithValue("sT_PAS", calc_sT);
      }

    // ST jets
    if (TwoJets)
      {
	double calc_sTjet=-999.;
	calc_sTjet =
	  JetPt->at(v_idx_jet_PtCut_noOverlap_ID[0]) + 
	  JetPt->at(v_idx_jet_PtCut_noOverlap_ID[1]) ;
	fillVariableWithValue("sTjet_PAS", calc_sTjet);
      }

    // Mjj
    if (TwoJets)
      {
	TLorentzVector jet1, jet2, jj;
	jet1.SetPtEtaPhiM(JetPt->at(v_idx_jet_PtCut_noOverlap_ID[0]),
			  JetEta->at(v_idx_jet_PtCut_noOverlap_ID[0]),
			  JetPhi->at(v_idx_jet_PtCut_noOverlap_ID[0]),0);
	jet2.SetPtEtaPhiM(JetPt->at(v_idx_jet_PtCut_noOverlap_ID[1]),
			  JetEta->at(v_idx_jet_PtCut_noOverlap_ID[1]),
			  JetPhi->at(v_idx_jet_PtCut_noOverlap_ID[1]),0);
	jj = jet1+jet2;
	//PAS June 2010
	fillVariableWithValue("Mjj_PAS", jj.M());
      }


    // Memu
    if (OneEleOneMu)
      {
	fillVariableWithValue( "maxMEtaEleMu_IDISO", max( getVariableValue("mEta1stEle_IDISO_NoOvrlp"), getVariableValue("mEta1stMu_IDISO") ) );
	TLorentzVector ele1, mu1, emu;
	ele1.SetPtEtaPhiM(ElectronPt->at(v_idx_ele_PtCut_IDISO_noOverlap[0]),
			  ElectronEta->at(v_idx_ele_PtCut_IDISO_noOverlap[0]),
			  ElectronPhi->at(v_idx_ele_PtCut_IDISO_noOverlap[0]),0);
	mu1.SetPtEtaPhiM(MuonPt->at(v_idx_muon_PtCut_IDISO[0]),
			 MuonEta->at(v_idx_muon_PtCut_IDISO[0]),
			 MuonPhi->at(v_idx_muon_PtCut_IDISO[0]),0);
	emu = ele1+mu1;
	fillVariableWithValue("Memu", emu.M());
	//OneEleOneMu
	fillVariableWithValue("Memu_OneEleOneMu", emu.M());
	fillVariableWithValue("Memu_presel", emu.M());
	//
	//PAS June 2010
	fillVariableWithValue("Memu_PAS", emu.M());

	double calc_sTemu=-999.;
        calc_sTemu =
	   ElectronPt->at(v_idx_ele_PtCut_IDISO_noOverlap[0]) +
	   MuonPt->at(v_idx_muon_PtCut_IDISO[0]) ;
	fillVariableWithValue("sTemu_PAS", calc_sTemu);

	if(isData==true) 
	  {
	    STDOUT("OneEleOneMu: Run, LS, Event = "<<run<<", "<<ls<<", "<<event);
	    STDOUT("OneEleOneMu: M_emu, Pt_emu, Eta_emu, Phi_emu = "<<emu.M() <<", "<< emu.Pt() <<", "<< emu.Eta() <<", "<< emu.Phi());
	    STDOUT("OneEleOneMu: 1st ele  Pt, eta, phi = "<< ele1.Pt() <<", "<< ele1.Eta() <<", "<< ele1.Phi() );
	    STDOUT("OneEleOneMu: 1st muon Pt, eta, phi = "<< mu1.Pt() <<", "<< mu1.Eta() <<", "<< mu1.Phi() );
	  }
      }

    // Mlj 
    double Me1j1, Me1j2, Mm1j1, Mm1j2 = -999;
    double deltaM_e1j1_m1j2 = 9999;
    double deltaM_e1j2_m1j1 = 9999;
    double Mlj_1stPair = 0;
    double Mlj_2ndPair = 0;
    double deltaR_e1j1 ;
    double deltaR_m1j2 ;
    double deltaR_e1j2 ;
    double deltaR_m1j1 ;
    if ( (OneEleOneMu) && (TwoJets) ) // OneEleOneMu and TwoJets
      {
	TLorentzVector jet1, jet2, ele1, mu1;
	ele1.SetPtEtaPhiM(ElectronPt->at(v_idx_ele_PtCut_IDISO_noOverlap[0]),
			  ElectronEta->at(v_idx_ele_PtCut_IDISO_noOverlap[0]),
			  ElectronPhi->at(v_idx_ele_PtCut_IDISO_noOverlap[0]),0);
	mu1.SetPtEtaPhiM(MuonPt->at(v_idx_muon_PtCut_IDISO[0]),
			 MuonEta->at(v_idx_muon_PtCut_IDISO[0]),
			 MuonPhi->at(v_idx_muon_PtCut_IDISO[0]),0);
	jet1.SetPtEtaPhiM(JetPt->at(v_idx_jet_PtCut_noOverlap_ID[0]),
			  JetEta->at(v_idx_jet_PtCut_noOverlap_ID[0]),
			  JetPhi->at(v_idx_jet_PtCut_noOverlap_ID[0]),0);
	jet2.SetPtEtaPhiM(JetPt->at(v_idx_jet_PtCut_noOverlap_ID[1]),
			  JetEta->at(v_idx_jet_PtCut_noOverlap_ID[1]),
			  JetPhi->at(v_idx_jet_PtCut_noOverlap_ID[1]),0);
	TLorentzVector e1j1, e1j2, m1j1, m1j2;
	e1j1 = ele1 + jet1;
	m1j2 =  mu1 + jet2;
	m1j1 =  mu1 + jet1;
	e1j2 = ele1 + jet2;
	Me1j1 = e1j1.M();
	Mm1j2 = m1j2.M();
	Me1j2 = e1j2.M();
	Mm1j1 = m1j1.M();

	deltaM_e1j1_m1j2 = Me1j1 - Mm1j2;
	deltaM_e1j2_m1j1 = Me1j2 - Mm1j1;


	double deltaR_e1j1 = ele1.DeltaR(jet1);
	double deltaR_m1j2 =  mu1.DeltaR(jet2);
	double deltaR_e1j2 = ele1.DeltaR(jet2);
	double deltaR_m1j1 =  mu1.DeltaR(jet1);

// 	// Fill min DR between any of the 2 selected eles and any of the 2 selected jets
// 	double minDR_2ele_2jet = min ( min(deltaR_e1j1,deltaR_m1j2) , min(deltaR_e1j2,deltaR_m1j1) );
// 	fillVariableWithValue("minDR_2ele_2jet", minDR_2ele_2jet);

	if(fabs(deltaM_e1j1_m1j2) > fabs(deltaM_e1j2_m1j1))
	  {
	    Mlj_1stPair = Me1j2;
	    Mlj_2ndPair = Mm1j1;
	    fillVariableWithValue("minDRlj_selecPairs", min(deltaR_e1j2,deltaR_m1j1) );
	    fillVariableWithValue("minDRlj_unselPairs", min(deltaR_e1j1,deltaR_m1j2) );
	  }
	else
	  {
	    Mlj_1stPair = Me1j1;
	    Mlj_2ndPair = Mm1j2;
	    fillVariableWithValue("minDRlj_selecPairs", min(deltaR_e1j1,deltaR_m1j2) );
	    fillVariableWithValue("minDRlj_unselPairs", min(deltaR_e1j2,deltaR_m1j1) );
	  } 
	fillVariableWithValue("Mlj_1stPair", Mlj_1stPair);       
	fillVariableWithValue("Mlj_2ndPair", Mlj_2ndPair);
	//PAS June 2010
	h_Mlj_PAS->Fill(Mlj_1stPair);
	h_Mlj_PAS->Fill(Mlj_2ndPair);
	fillVariableWithValue("Mlj_1stPair_PAS", Mlj_1stPair);       
	fillVariableWithValue("Mlj_2ndPair_PAS", Mlj_2ndPair);

	// min and max DeltaR between electrons and any jet
	double minDeltaR_lj = 999999;
	double maxDeltaR_lj = -1;
	double thisMinDR, thisMaxDR, DR_thisjet_e1, DR_thisjet_m1;
	TLorentzVector thisjet;
	for(int ijet=0; ijet<v_idx_jet_PtCut_noOverlap_ID.size(); ijet++)
	  {
	    thisjet.SetPtEtaPhiM(JetPt->at(v_idx_jet_PtCut_noOverlap_ID[ijet]),
				 JetEta->at(v_idx_jet_PtCut_noOverlap_ID[ijet]),
				 JetPhi->at(v_idx_jet_PtCut_noOverlap_ID[ijet]),0);
	    DR_thisjet_e1 = thisjet.DeltaR(ele1);
	    DR_thisjet_m1 = thisjet.DeltaR(mu1);
	    thisMinDR = min(DR_thisjet_e1, DR_thisjet_m1);
	    thisMaxDR = max(DR_thisjet_e1, DR_thisjet_m1);
	    if(thisMinDR < minDeltaR_lj)
	      minDeltaR_lj = thisMinDR;
	    if(thisMaxDR > maxDeltaR_lj)
	      maxDeltaR_lj = thisMaxDR;
	  } 
	fillVariableWithValue("minDeltaR_lj", minDeltaR_lj);
	fillVariableWithValue("maxDeltaR_lj", maxDeltaR_lj);

	// printouts for small Mlj
	if(isData==true && ( Mlj_1stPair<20 || Mlj_2ndPair<20 ) ) // printouts for low Mlj 
	  {
	    STDOUT("Mlj<20GeV: Run, LS, Event = "<<run<<",\t"<<ls<<",\t"<<event);
	    STDOUT("Mlj<20GeV: Mlj_1stPair = "<<Mlj_1stPair <<", Mlj_2ndPair = "<< Mlj_2ndPair );
	    STDOUT("Mlj<20GeV: e1j1.M = "<<e1j1.M() <<", m1j2.M = "<<m1j2.M() <<", e1j2.M = "<<e1j2.M()  <<", m1j1.M = "<<m1j1.M()  );
	    STDOUT("Mlj<20GeV: deltaM_e1j1_m1j2 = "<<deltaM_e1j1_m1j2 <<", deltaM_e1j2_m1j1 = "<<deltaM_e1j2_m1j1  );
	    STDOUT("Mlj<20GeV: deltaR_e1j1 = "<<deltaR_e1j1 <<", deltaR_m1j2 = "<<deltaR_m1j2 <<", deltaR_e1j2 = "<<deltaR_e1j2  <<", deltaR_m1j1 = "<<deltaR_m1j1  );
	    TLorentzVector thisele;
	    // Add printout for muons?
	    for(int iele=0; iele<v_idx_ele_PtCut_IDISO_noOverlap.size(); iele++)
	      {
		thisele.SetPtEtaPhiM(ElectronPt->at(v_idx_ele_PtCut_IDISO_noOverlap[iele]),
				     ElectronEta->at(v_idx_ele_PtCut_IDISO_noOverlap[iele]),
				     ElectronPhi->at(v_idx_ele_PtCut_IDISO_noOverlap[iele]),0);
		STDOUT("Mlj<20GeV: e"<<iele+1<<" Pt, eta, phi = " 
		       << ", "<<thisele.Pt()<<", "<< thisele.Eta() <<", "<< thisele.Phi()<<"; DR_j1, DR_j2 = "<< thisele.DeltaR(jet1)<<", "<<thisele.DeltaR(jet2));
	      }
	    TLorentzVector thisjet;
	    TLorentzVector thisjet_e1, thisjet_m1;
	    for(int ijet=0; ijet<v_idx_jet_PtCut_noOverlap_ID.size(); ijet++)
	      {
		thisjet.SetPtEtaPhiM(JetPt->at(v_idx_jet_PtCut_noOverlap_ID[ijet]),
				     JetEta->at(v_idx_jet_PtCut_noOverlap_ID[ijet]),
				     JetPhi->at(v_idx_jet_PtCut_noOverlap_ID[ijet]),0);
		thisjet_e1 = thisjet + ele1;
		thisjet_m1 = thisjet +  mu1;
		STDOUT("Mlj<20GeV: j"<<ijet+1<<" Pt, eta, phi = " << ", "<<thisjet.Pt()<<", "<< thisjet.Eta() <<", "<< thisjet.Phi()<<"; DR_e1, DR_m1 = "<< thisjet.DeltaR(ele1)<<", "<<thisjet.DeltaR(mu1) << "; M_e1, M_m1 = " <<thisjet_e1.M() <<", "<<thisjet_m1.M() );
	      }
	  } // printouts for low Mlj 

      } // OneEleOneMu and TwoJets



    // Evaluate cuts (but do not apply them)
    evaluateCuts();

    // Fill histograms and do analysis based on cut evaluation
    //h_nEleFinal->Fill( ElectronPt->size() );
     

    // printouts for OneEleOneMuTwoJets
    if( isData==true && passedAllPreviousCuts("Memu") ) 
      {
	STDOUT("OneEleOneMuTwoJets: Run, LS, Event = "<<run<<",\t"<<ls<<",\t"<<event);
	STDOUT("OneEleOneMuTwoJets: sT, Memu, Mjj_PAS = "******"sT") <<", "<< getVariableValue("Memu")<<", "<< getVariableValue("Mjj_PAS") );
	STDOUT("OneEleOneMuTwoJets: Mlj_1stPair, Mlj_2ndPair = "<< getVariableValue("Mlj_1stPair")<<", "<< getVariableValue("Mlj_2ndPair") );
	STDOUT("OneEleOneMuTwoJets: 1stEle Pt, eta, phi = "<<getVariableValue("Pt1stEle_PAS") <<", "<< getVariableValue("Eta1stEle_PAS") <<", "<< getVariableValue("Phi1stEle_PAS") );
	STDOUT("OneEleOneMuTwoJets: 1stMu  Pt, eta, phi = "<<getVariableValue("Pt1stMu_PAS") <<", "<< getVariableValue("Eta1stMu_PAS") <<", "<< getVariableValue("Phi1stMu_PAS") );
	STDOUT("OneEleOneMuTwoJets: 1stJet Pt, eta, phi = "<<getVariableValue("Pt1stJet_PAS") <<", "<< getVariableValue("Eta1stJet_PAS") <<", "<< getVariableValue("Phi1stJet_PAS") );
	STDOUT("OneEleOneMuTwoJets: 2ndJet Pt, eta, phi = "<<getVariableValue("Pt2ndJet_PAS") <<", "<< getVariableValue("Eta2ndJet_PAS") <<", "<< getVariableValue("Phi2ndJet_PAS") );
	STDOUT("OneEleOneMuTwoJets: minDRlj_selecPairs, minDRlj_unselPairs = "<<getVariableValue("minDRlj_selecPairs") <<", "<< getVariableValue("minDRlj_unselPairs") );
// 	if ( passedCut("Mee") )
// 	  {
// 	    STDOUT("PassedMeeAndAllPrevious: Run, LS, Event = "<<run<<",\t"<<ls<<",\t"<<event<<", sT = "<< getVariableValue("sT"));
// 	  }
      } // printouts for OneEleOneMuTwoJets:

    
    //INFO
    //      // retrieve value of previously filled variables (after making sure that they were filled)
    //      double totpTEle;
    //      if ( variableIsFilled("pT1stEle") && variableIsFilled("pT2ndEle") ) 
    //        totpTEle = getVariableValue("pT1stEle")+getVariableValue("pT2ndEle");
    //      // reject events that did not pass level 0 cuts
    //      if( !passedCut("0") ) continue;
    //      // ......

        
    ////////////////////// User's code to be done for every event - END ///////////////////////
    
  } // End of loop over events
  

  ////////////////////// User's code to write histos - BEGIN ///////////////////////

  h_Mlj_PAS->Write();

  ////////////////////// User's code to write histos - END ///////////////////////
  
  
  //STDOUT("analysisClass::Loop() ends");   
}
void analysisClass::Loop()
{
   std::cout << "analysisClass::Loop() begins" <<std::endl;   
    
   if (fChain == 0) return;
   
   //////////book histos here

#ifdef USE_EXAMPLE
   STDOUT("WARNING: using example code. In order NOT to use it, comment line that defines USE_EXAMPLE flag in Makefile.");   
   // number of electrons
   TH1F *h_nEleFinal = new TH1F ("h_nEleFinal","",11,-0.5,10.5);
   h_nEleFinal->Sumw2();
   //pT 1st ele
   TH1F *h_pT1stEle = new TH1F ("h_pT1stEle","",100,0,1000);
   h_pT1stEle->Sumw2();
   //pT 2nd ele
   TH1F *h_pT2ndEle = new TH1F ("h_pT2ndEle","",100,0,1000);
   h_pT2ndEle->Sumw2();

#endif //end of USE_EXAMPLE

   /////////initialize variables

   Long64_t nentries = fChain->GetEntriesFast();
   std::cout << "analysisClass::Loop(): nentries = " << nentries << std::endl;   

   ////// The following ~7 lines have been taken from rootNtupleClass->Loop() /////
   ////// If the root version is updated and rootNtupleClass regenerated,     /////
   ////// these lines may need to be updated.                                 /////    
   Long64_t nbytes = 0, nb = 0;
   for (Long64_t jentry=0; jentry<nentries;jentry++) {
     Long64_t ientry = LoadTree(jentry);
     if (ientry < 0) break;
     nb = fChain->GetEntry(jentry);   nbytes += nb;
     if(jentry < 10 || jentry%1000 == 0) std::cout << "analysisClass::Loop(): jentry = " << jentry << std::endl;   
     // if (Cut(ientry) < 0) continue;

     ////////////////////// User's code starts here ///////////////////////

     ///Stuff to be done every event

#ifdef USE_EXAMPLE
     // Electrons
     vector<int> v_idx_ele_final;
     for(int iele=0;iele<eleCount;iele++)
       {
	 // ECAL barrel fiducial region
	 bool pass_ECAL_FR=false;
	 if( fabs(eleEta[iele]) < getPreCutValue1("eleFidRegion") )	v_idx_ele_final.push_back(iele);
       }     

     // Set the evaluation of the cuts to false and clear the variable values and filled status
     resetCuts();
     
     // Set the value of the variableNames listed in the cutFile to their current value
     fillVariableWithValue("nEleFinal", v_idx_ele_final.size()) ;
     if( v_idx_ele_final.size() >= 1 ) 
       {
	 fillVariableWithValue( "pT1stEle", elePt[v_idx_ele_final[0]] );
       }
     if( v_idx_ele_final.size() >= 2 ) 
       {
	 fillVariableWithValue( "pT2ndEle", elePt[v_idx_ele_final[1]] );
	 // Calculate Mee
	 TLorentzVector v_ee, ele1, ele2;
	 ele1.SetPtEtaPhiM(elePt[v_idx_ele_final[0]],eleEta[v_idx_ele_final[0]],elePhi[v_idx_ele_final[0]],0);
	 ele2.SetPtEtaPhiM(elePt[v_idx_ele_final[1]],eleEta[v_idx_ele_final[1]],elePhi[v_idx_ele_final[1]],0);
	 v_ee = ele1 + ele2;
	 fillVariableWithValue( "invMass_ee", v_ee.M() ) ;
       }

     // Evaluate cuts (but do not apply them)
     evaluateCuts();
     
     // Fill histograms and do analysis based on cut evaluation
     h_nEleFinal->Fill(v_idx_ele_final.size());
     //if( v_idx_ele_final.size()>=1 ) h_pT1stEle->Fill(elePt[v_idx_ele_final[0]]);
     //if( v_idx_ele_final.size()>=2 && (elePt[v_idx_ele_final[0]])>85 ) h_pT2ndEle->Fill(elePt[v_idx_ele_final[1]]);
     if( passedCut("pT1stEle") ) h_pT1stEle->Fill(elePt[v_idx_ele_final[0]]);
     if( passedCut("pT2ndEle") ) h_pT2ndEle->Fill(elePt[v_idx_ele_final[1]]);
     
     // retrieve value of previously filled variables (after making sure that they were filled)
     double totpTEle;
     if ( variableIsFilled("pT1stEle") && variableIsFilled("pT2ndEle") ) 
       totpTEle = getVariableValue("pT1stEle")+getVariableValue("pT2ndEle");

     // reject events that did not pass level 0 cuts
     if( !passedCut("0") ) continue;
     // ......
     
     // reject events that did not pass level 1 cuts
     if( !passedCut("1") ) continue;
     // ......

     // reject events that did not pass the full cut list
     if( !passedCut("all") ) continue;
     // ......

#endif  // end of USE_EXAMPLE


     ////////////////////// User's code ends here ///////////////////////

   } // End loop over events

   //////////write histos 

#ifdef USE_EXAMPLE
   STDOUT("WARNING: using example code. In order NOT to use it, comment line that defines USE_EXAMPLE flag in Makefile.");   

   h_nEleFinal->Write();
   h_pT1stEle->Write();
   h_pT2ndEle->Write();

   //pT of both electrons, to be built using the histograms produced automatically by baseClass
   TH1F * h_pTElectrons = new TH1F ("h_pTElectrons","", getHistoNBins("pT1stEle"), getHistoMin("pT1stEle"), getHistoMax("pT1stEle"));
   h_pTElectrons->Add( & getHisto_noCuts_or_skim("pT1stEle") ); // all histos can be retrieved, see other getHisto_xxxx methods in baseClass.h
   h_pTElectrons->Add( & getHisto_noCuts_or_skim("pT2ndEle") );
   //one could also do:  *h_pTElectrons = getHisto_noCuts_or_skim("pT1stEle") + getHisto_noCuts_or_skim("pT2ndEle");
   h_pTElectrons->Write();
   //one could also do:   const TH1F& h = getHisto_noCuts_or_skim// and use h
#endif // end of USE_EXAMPLE
   std::cout << "analysisClass::Loop() ends" <<std::endl;   
}