void analysisClass::Loop()
{
   std::cout << "analysisClass::Loop() begins" <<std::endl;   

   //--------------------------------------------------------------------------
   // Decide which plots to save (default is to save everything)
   //--------------------------------------------------------------------------
   
   fillSkim                         ( !true  ) ;
   fillAllPreviousCuts              ( !true  ) ;
   fillAllOtherCuts                 (  true  ) ;
   fillAllSameLevelAndLowerLevelCuts( !true  ) ;
   fillAllCuts                      ( !true  ) ;

   //--------------------------------------------------------------------------
   // Pileup reweighting initialization
   //--------------------------------------------------------------------------

   // Lumi3DReWeighting lumiWeights = Lumi3DReWeighting("/afs/cern.ch/user/e/eberry/public/LQ_PILEUP/pileup_truth_MC_Summer11_PU_S4_3DReweighting.root",
   // 						     "/afs/cern.ch/user/e/eberry/public/LQ_PILEUP/pileup_truth_finebin_2011_finebin.root",
   // 						     "pileup", "pileup");
   // lumiWeights.weight3D_init(1.0);

   //--------------------------------------------------------------------------
   // Any extra features
   //--------------------------------------------------------------------------
   
   TProfile * profile_run_vs_nvtx_HLT = new TProfile("run_vs_nvtx_HLT", "", 20000 , 160300  , 180300 );
   TProfile * profile_run_vs_nvtx_PAS = new TProfile("run_vs_nvtx_PAS", "", 20000 , 160300  , 180300 );
   
   //--------------------------------------------------------------------------
   // Get pre-cut values
   //--------------------------------------------------------------------------

   // eta boundaries

   double eleEta_bar_max = getPreCutValue1("eleEta_bar");
   double eleEta_end_min = getPreCutValue1("eleEta_end1");
   double eleEta_end_max = getPreCutValue2("eleEta_end2");

   // dataset
   
   int dataset  = getPreCutValue1("dataset") ;
   bool select2011A = ( dataset == 0 );
   bool select2011B = ( dataset == 1 );
   bool select2011  = ( dataset == 2 );

   if ( ! select2011A &&
	! select2011B &&
	! select2011 ) {
     std::cout << "Error: Must choose dataset to be 0 (2011A), 1 (2011B), or 2 (all 2011)" << std::endl;
   }

   //--------------------------------------------------------------------------
   // Create TH1D's
   //--------------------------------------------------------------------------
   
   // gap: 1.442 - 1.560

   // eleEta_bar            	1.442        -                    -               -               -1
   // eleEta_end1            	1.560        2.0                  -               -               -1
   // eleEta_end2            	2.000        2.5                  -               -               -1
   
   CreateUserTH1D( "nElectron_PAS"         ,    5   , -0.5    , 4.5      );
   CreateUserTH1D( "nMuon_PAS"             ,    5   , -0.5    , 4.5      );
   CreateUserTH1D( "nJet_PAS"              ,    10  , -0.5    , 9.5      );
   CreateUserTH1D( "Pt1stEle_PAS"	   , 	100 , 0       , 1000     ); 
   CreateUserTH1D( "Eta1stEle_PAS"	   , 	100 , -5      , 5	 ); 
   CreateUserTH1D( "Phi1stEle_PAS"	   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "Pt2ndEle_PAS"	   , 	100 , 0       , 1000     ); 
   CreateUserTH1D( "Eta2ndEle_PAS"	   , 	100 , -5      , 5	 ); 
   CreateUserTH1D( "Phi2ndEle_PAS"	   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "Charge1stEle_PAS"	   , 	2   , -1.0001 , 1.0001	 ); 
   CreateUserTH1D( "Charge2ndEle_PAS"	   , 	2   , -1.0001 , 1.0001	 ); 
   CreateUserTH1D( "MET_PAS"               ,    200 , 0       , 1000	 ); 
   CreateUserTH1D( "METSig_PAS"            ,    200 , 0       , 1000	 ); 
   CreateUserTH1D( "METPhi_PAS"		   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "METCharged_PAS"        ,    200 , 0       , 1000	 ); 
   CreateUserTH1D( "METChargedPhi_PAS"	   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "METType1_PAS"          ,    200 , 0       , 1000	 ); 
   CreateUserTH1D( "METType1Phi_PAS"	   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "Pt1stJet_PAS"          ,    100 , 0       , 1000	 ); 
   CreateUserTH1D( "Pt2ndJet_PAS"          ,    100 , 0       , 1000	 ); 
   CreateUserTH1D( "Eta1stJet_PAS"         ,    100 , -5      , 5	 ); 
   CreateUserTH1D( "Eta2ndJet_PAS"         ,    100 , -5      , 5	 ); 
   CreateUserTH1D( "Phi1stJet_PAS"	   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "Phi2ndJet_PAS"	   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "sTlep_PAS"             ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "sTjet_PAS"             ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "sT_PAS"                ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Mjj_PAS"		   ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Mee_PAS"		   ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "MTenu_PAS"                , 200 , 0       , 1000	 ); 
   CreateUserTH1D( "Me1j1_PAS"             ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Me1j2_PAS"             ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Me2j1_PAS"             ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Me2j2_PAS"             ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Me1j_selected_PAS"     ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Me2j_selected_PAS"     ,    200 , 0       , 2000     );
   CreateUserTH1D( "Mej_selected_avg_PAS"  ,    200 , 0       , 2000     ); 
   CreateUserTH1D( "Meejj_PAS"             ,    200 , 0       , 2000     );
   CreateUserTH1D( "run_PAS"               ,    20000 , 160300  , 180300 );
   CreateUserTH1D( "run_HLT"               ,    20000 , 160300  , 180300 );
		                           
   CreateUserTH1D( "Ptee_PAS"              ,    200 , 0       , 2000     );
   		                           
   CreateUserTH1D( "DCotTheta1stEle_PAS"   ,    100 , 0.0, 1.0);
   CreateUserTH1D( "Dist1stEle_PAS"        ,    100 , 0.0, 1.0);  
   CreateUserTH1D( "DCotTheta2ndEle_PAS"   ,    100 , 0.0, 1.0);
   CreateUserTH1D( "Dist2ndEle_PAS"        ,    100 , 0.0, 1.0);  
		                           
   CreateUserTH1D( "nVertex_PAS"           ,    31   , -0.5   , 30.5	 ) ; 
   CreateUserTH1D( "nVertex_good_PAS"      ,    31   , -0.5   , 30.5	 ) ; 
		                           
   CreateUserTH1D( "DR_Ele1Jet1_PAS"	   , 	getHistoNBins("DR_Ele1Jet1"), getHistoMin("DR_Ele1Jet1"), getHistoMax("DR_Ele1Jet1")     ) ; 
   CreateUserTH1D( "DR_Ele1Jet2_PAS"	   , 	getHistoNBins("DR_Ele1Jet2"), getHistoMin("DR_Ele1Jet2"), getHistoMax("DR_Ele1Jet2")     ) ; 
   CreateUserTH1D( "DR_Ele2Jet1_PAS"	   , 	getHistoNBins("DR_Ele2Jet1"), getHistoMin("DR_Ele2Jet1"), getHistoMax("DR_Ele2Jet1")     ) ; 
   CreateUserTH1D( "DR_Ele2Jet2_PAS"	   , 	getHistoNBins("DR_Ele2Jet2"), getHistoMin("DR_Ele2Jet2"), getHistoMax("DR_Ele2Jet2")     ) ; 
   CreateUserTH1D( "DR_Jet1Jet2_PAS"	   , 	getHistoNBins("DR_Jet1Jet2"), getHistoMin("DR_Jet1Jet2"), getHistoMax("DR_Jet1Jet2")     ) ; 
   CreateUserTH1D( "DR_Ele1Ele2_PAS"	   , 	getHistoNBins("DR_Jet1Jet2"), getHistoMin("DR_Jet1Jet2"), getHistoMax("DR_Jet1Jet2")     ) ; 
   CreateUserTH1D( "minDR_EleJet_PAS"	   , 	getHistoNBins("DR_Jet1Jet2"), getHistoMin("DR_Jet1Jet2"), getHistoMax("DR_Jet1Jet2")     ) ; 

   CreateUserTH2D( "Me1jVsMe2j_selected",     200, 0, 2000, 200, 0, 2000) ;
   CreateUserTH2D( "Me1jVsMe2j_rejected",     200, 0, 2000, 200, 0, 2000) ;

   CreateUserTH1D( "MTeemunu_PAS"          ,    200 , 0       , 1000	 ); 

   CreateUserTH1D( "Mee_80_100_Preselection", 200, 60, 120 );
   CreateUserTH1D( "Mee_70_110_Preselection", 200, 60, 120 );

   CreateUserTH1D( "Mee_EBEB_PAS"		   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EBEE_PAS"		   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EEEE_PAS"		   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EB_PAS" 		   ,    60 , 60       , 120	 ); 

   CreateUserTH1D( "Mee_EBEB_80_100_PAS"	   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EBEE_80_100_PAS"	   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EEEE_80_100_PAS"	   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EB_80_100_PAS" 	     	   ,    60 , 60       , 120	 ); 
   
   CreateUserTH1D( "Mee_EBEB_70_110_PAS"	   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EBEE_70_110_PAS"	   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EEEE_70_110_PAS"	   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EB_70_110_PAS" 	     	   ,    60 , 60       , 120	 ); 

   CreateUserTH1D("Mej_selected_avg_LQ250"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_avg_LQ350"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_avg_LQ400"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_avg_LQ450"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_avg_LQ500"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_avg_LQ550"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_avg_LQ600"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_avg_LQ650"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_avg_LQ750"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_avg_LQ850"         ,   40  , 0        , 2000     );

   CreateUserTH1D("Mej_selected_min_LQ250"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_min_LQ350"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_min_LQ400"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_min_LQ450"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_min_LQ500"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_min_LQ550"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_min_LQ600"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_min_LQ650"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_min_LQ750"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_min_LQ850"         ,   40  , 0        , 2000     );

   CreateUserTH1D("sT_eejj_LQ250"                  ,   20  , 0        , 2000     );
   CreateUserTH1D("sT_eejj_LQ350"                  ,   20  , 0        , 2000     );
   CreateUserTH1D("sT_eejj_LQ400"                  ,   20  , 0        , 2000     );
   CreateUserTH1D("sT_eejj_LQ450"                  ,   20  , 0        , 2000     );
   CreateUserTH1D("sT_eejj_LQ500"                  ,   20  , 0        , 2000     );
   CreateUserTH1D("sT_eejj_LQ550"                  ,   20  , 0        , 2000     );
   CreateUserTH1D("sT_eejj_LQ600"                  ,   20  , 0        , 2000     );
   CreateUserTH1D("sT_eejj_LQ650"                  ,   20  , 0        , 2000     );
   CreateUserTH1D("sT_eejj_LQ750"                  ,   20  , 0        , 2000     );
   CreateUserTH1D("sT_eejj_LQ850"                  ,   20  , 0        , 2000     );

   CreateUserTH1D("Mee_LQ250"                      ,   40  , 0        , 2000     );
   CreateUserTH1D("Mee_LQ350"                      ,   40  , 0        , 2000     );
   CreateUserTH1D("Mee_LQ400"                      ,   40  , 0        , 2000     );
   CreateUserTH1D("Mee_LQ450"                      ,   40  , 0        , 2000     );
   CreateUserTH1D("Mee_LQ500"                      ,   40  , 0        , 2000     );
   CreateUserTH1D("Mee_LQ550"                      ,   40  , 0        , 2000     );
   CreateUserTH1D("Mee_LQ600"                      ,   40  , 0        , 2000     );
   CreateUserTH1D("Mee_LQ650"                      ,   40  , 0        , 2000     );
   CreateUserTH1D("Mee_LQ750"                      ,   40  , 0        , 2000     );
   CreateUserTH1D("Mee_LQ850"                      ,   40  , 0        , 2000     );

   CreateUserTH1D( "PileupWeight"   , 100, -10, 10 );
   CreateUserTH1D( "GeneratorWeight", 100, -2.0, 2.0);
   
   //--------------------------------------------------------------------------
   // Loop over the chain
   //--------------------------------------------------------------------------

   if (fChain == 0) return;
   
   Long64_t nentries = fChain->GetEntries();
   std::cout << "analysisClass::Loop(): nentries = " << nentries << std::endl;   

   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 << "/" << nentries << std::endl;   

     //--------------------------------------------------------------------------
     // Reset the cuts
     //--------------------------------------------------------------------------

     resetCuts();

     //--------------------------------------------------------------------------
     // Check good run list
     //--------------------------------------------------------------------------
     
     int    passedJSON = passJSON ( run, ls , isData ) ;

     //--------------------------------------------------------------------------
     // Do pileup re-weighting
     //--------------------------------------------------------------------------
     
     // double pileup_weight = lumiWeights.weight3D (nPileUpInt_BXminus1, nPileUpInt_BX0, nPileUpInt_BXplus1 );
     // if ( isData ) pileup_weight = 1.0;
     // setPileupWeight ( pileup_weight ) ;

     int NPILEUP_AVE = int( nPileUpInt_BX0 );
     int NPILEUP_FINAL = min( NPILEUP_AVE , 25 );
     double pileup_weight = getPileupWeight ( NPILEUP_FINAL, isData ) ;
      
     //--------------------------------------------------------------------------
     // Get information about gen-level reweighting (should be for Sherpa only)
     //--------------------------------------------------------------------------

     double gen_weight = Weight;
     if ( isData ) gen_weight = 1.0;

     // std::cout << "Gen weight = " << int ( 1.0 / gen_weight ) << std::endl;

     //--------------------------------------------------------------------------
     // Is this the dataset we want?
     //--------------------------------------------------------------------------
     
     int PassDataset = 1;
     if ( isData ) { 
       PassDataset = 0;
       if ( select2011A ){ 
	 if ( run >= 160329 && run <= 175770 ) PassDataset = 1;
       }
       if ( select2011B ){
	 if ( run >= 175832 && run <= 180296 ) PassDataset = 1;
       }
       if ( select2011 ) {
	 PassDataset = 1;
       }
     }

     //--------------------------------------------------------------------------
     // Fill variables
     //--------------------------------------------------------------------------

     // JSON variable
     fillVariableWithValue(   "PassJSON"                      , passedJSON, gen_weight   ) ; 

     // Dataset variable
     fillVariableWithValue(   "PassDataset"                      , PassDataset, gen_weight  ) ;

     // Noise filters
     fillVariableWithValue(   "PassHBHENoiseFilter"           , PassHBHENoiseFilter    , gen_weight   ) ; 
     fillVariableWithValue(   "PassBeamHaloFilterTight"       , PassBeamHaloFilterTight, gen_weight   ) ; 

     //fillVariableWithValue(   "PassBPTX0"                     , PassBPTX0                  , gen_weight  ) ; 
     //fillVariableWithValue(   "PassPhysDecl"                  , PassPhysDecl               , gen_weight  ) ; 
     //fillVariableWithValue(   "PassBeamScraping"              , PassBeamScraping           , gen_weight  ) ; 
     //fillVariableWithValue(   "PassPrimaryVertex"             , PassPrimaryVertex          , gen_weight  ) ; 
     //fillVariableWithValue(   "PassBeamHaloFilterLoose"	      , PassBeamHaloFilterLoose	   , gen_weight  ) ; 
     //fillVariableWithValue(   "PassTrackingFailure"           , PassTrackingFailure        , gen_weight  ) ; 
     //fillVariableWithValue(   "PassCaloBoundaryDRFilter"      , PassCaloBoundaryDRFilter   , gen_weight  ) ; 
     //fillVariableWithValue(   "PassEcalMaskedCellDRFilter"    , PassEcalMaskedCellDRFilter , gen_weight  ) ; 

     // Fill HLT 
     int passHLT = 1;
     if ( isData ) { 
       passHLT = 0;
       
       if ( H_DoubleEle33_CIdL_1  == 1 || 
       	    H_DoubleEle33_CIdL_2  == 1 || 
       	    H_DoubleEle33_CIdL_3  == 1 || 
       	    H_DoubleEle33_CIdL_4  == 1 || 
       	    H_DoubleEle33_CIdL_5  == 1 || 
	    H_DoubleEle33_CIdL_6  == 1 ||
	    H_DoubleEle33_CIdL_7  == 1 ||
	    H_DoubleEle33_CIdT_1  == 1 ||
	    H_DoubleEle33_CIdT_2  == 1 ||
	    H_DoubleEle33_CIdT_3  == 1 ||
       	    H_DoublePhoton33_1    == 1 || 
       	    H_DoublePhoton33_2    == 1 || 
       	    H_DoublePhoton33_3    == 1 || 
       	    H_DoublePhoton33_4    == 1 || 
       	    H_DoublePhoton33_5    == 1 ) {
       	 passHLT = 1;
       }
     }

     // What dataset is this?

     // Electrons
     int PassNEle = 0;
     if ( nEle_Ana == 2 ) PassNEle = 1;
     
     // Muons
     int PassNMuon = 0;
     if ( nMuon_Ana == 0 ) PassNMuon = 1;
     
     fillVariableWithValue ( "Reweighting", 1, gen_weight  );
     fillVariableWithValue ( "PassHLT", passHLT, gen_weight  ) ;
     
     // Electrons
     fillVariableWithValue(   "PassNEle"                      , PassNEle    , gen_weight  ) ;
     if ( nEle_Ana >= 1 ) { 
       fillVariableWithValue( "Ele1_Pt"                       , Ele1_Pt     , gen_weight  ) ;
       fillVariableWithValue( "Ele1_Eta"                      , Ele1_Eta    , gen_weight  ) ;
       fillVariableWithValue( "abs_Ele1_Eta"                  , fabs(Ele1_Eta), gen_weight  );
     }									    
     if ( nEle_Ana >= 2 ) { 						    
       fillVariableWithValue( "Ele2_Pt"                       , Ele2_Pt     , gen_weight  ) ;
       fillVariableWithValue( "Ele2_Eta"                      , Ele2_Eta    , gen_weight  ) ;
       fillVariableWithValue( "abs_Ele2_Eta"                  , fabs(Ele2_Eta), gen_weight  );
       fillVariableWithValue( "M_e1e2"                        , M_e1e2      , gen_weight  ) ;
     }									    
									    
     // Jets								    
     fillVariableWithValue(   "nJet"                          , nJet_Ana    , gen_weight  ) ;
     if ( nJet_Ana >= 1 ) { 						    
       fillVariableWithValue( "Jet1_Pt"                       , Jet1_Pt     , gen_weight  ) ;
       fillVariableWithValue( "Jet1_Eta"                      , Jet1_Eta    , gen_weight  ) ;
     }
     if ( nJet_Ana >= 2 ) { 
       fillVariableWithValue( "Jet2_Pt"                       , Jet2_Pt     , gen_weight  ) ;
       fillVariableWithValue( "Jet2_Eta"                      , Jet2_Eta    , gen_weight  ) ;
       fillVariableWithValue( "DR_Jet1Jet2"                   , DR_Jet1Jet2 , gen_weight  ) ;
     }

     // Muons
     fillVariableWithValue(   "PassNMuon"                     , PassNMuon   , gen_weight  ) ;

     // DeltaR
     if ( nEle_Ana >= 2 && nJet_Ana >= 1) {
       fillVariableWithValue( "DR_Ele1Jet1"                   , DR_Ele1Jet1 , gen_weight  ) ;
       fillVariableWithValue( "DR_Ele2Jet1"                   , DR_Ele2Jet1 , gen_weight  ) ;
       if(nJet_Ana >= 2) {
	 fillVariableWithValue( "DR_Ele1Jet2"                 , DR_Ele1Jet2 , gen_weight  ) ;
	 fillVariableWithValue( "DR_Ele2Jet2"                 , DR_Ele2Jet2 , gen_weight  ) ;
       }
     }

     // sT
     double M_ej_avg;
     double M_ej_min;

     if ( nEle_Ana >= 2 && nJet_Ana >= 2) {
       if ( fabs(M_e1j1-M_e2j2) < fabs(M_e1j2-M_e2j1) )  {
	 M_ej_avg = (M_e1j1 + M_e2j2) / 2.0;
	 if    ( M_e1j1 < M_e2j2 ) M_ej_min = M_e1j1;
	 else                      M_ej_min = M_e2j2;
       }
       else { 
	 M_ej_avg = (M_e1j2 + M_e2j1) / 2.0;
	 if    ( M_e1j2 < M_e2j1 ) M_ej_min = M_e1j2;
	 else                      M_ej_min = M_e2j1;
       }
       
       fillVariableWithValue( "sT_eejj"                      , sT_eejj, gen_weight  ) ;

       fillVariableWithValue( "sT_eejj_LQ250"                , sT_eejj, gen_weight  ) ;
       fillVariableWithValue( "sT_eejj_LQ350"                , sT_eejj, gen_weight  ) ;
       fillVariableWithValue( "sT_eejj_LQ400"                , sT_eejj, gen_weight  ) ;
       fillVariableWithValue( "sT_eejj_LQ450"                , sT_eejj, gen_weight  ) ;
       fillVariableWithValue( "sT_eejj_LQ500"                , sT_eejj, gen_weight  ) ;
       fillVariableWithValue( "sT_eejj_LQ550"                , sT_eejj, gen_weight  ) ;
       fillVariableWithValue( "sT_eejj_LQ600"                , sT_eejj, gen_weight  ) ;
       fillVariableWithValue( "sT_eejj_LQ650"                , sT_eejj, gen_weight  ) ;
       fillVariableWithValue( "sT_eejj_LQ750"                , sT_eejj, gen_weight  ) ;
       fillVariableWithValue( "sT_eejj_LQ850"                , sT_eejj, gen_weight  ) ;
       
       fillVariableWithValue( "min_M_ej_LQ250"               , M_ej_min, gen_weight ) ;
       fillVariableWithValue( "min_M_ej_LQ350"               , M_ej_min, gen_weight ) ;
       fillVariableWithValue( "min_M_ej_LQ400"               , M_ej_min, gen_weight ) ;
       fillVariableWithValue( "min_M_ej_LQ450"               , M_ej_min, gen_weight ) ;
       fillVariableWithValue( "min_M_ej_LQ500"               , M_ej_min, gen_weight ) ;
       fillVariableWithValue( "min_M_ej_LQ550"               , M_ej_min, gen_weight ) ;
       fillVariableWithValue( "min_M_ej_LQ600"               , M_ej_min, gen_weight ) ;
       fillVariableWithValue( "min_M_ej_LQ650"               , M_ej_min, gen_weight ) ;
       fillVariableWithValue( "min_M_ej_LQ750"               , M_ej_min, gen_weight ) ;
       fillVariableWithValue( "min_M_ej_LQ850"               , M_ej_min, gen_weight ) ;


       fillVariableWithValue( "M_e1e2_LQ250"                , M_e1e2, gen_weight  ) ;
       fillVariableWithValue( "M_e1e2_LQ350"                , M_e1e2, gen_weight  ) ;
       fillVariableWithValue( "M_e1e2_LQ400"                , M_e1e2, gen_weight  ) ;
       fillVariableWithValue( "M_e1e2_LQ450"                , M_e1e2, gen_weight  ) ;
       fillVariableWithValue( "M_e1e2_LQ500"                , M_e1e2, gen_weight  ) ;
       fillVariableWithValue( "M_e1e2_LQ550"                , M_e1e2, gen_weight  ) ;
       fillVariableWithValue( "M_e1e2_LQ600"                , M_e1e2, gen_weight  ) ;
       fillVariableWithValue( "M_e1e2_LQ650"                , M_e1e2, gen_weight  ) ;
       fillVariableWithValue( "M_e1e2_LQ750"                , M_e1e2, gen_weight  ) ;
       fillVariableWithValue( "M_e1e2_LQ850"                , M_e1e2, gen_weight  ) ;
       
     }      

     //--------------------------------------------------------------------------
     // Evaluate the cuts
     //--------------------------------------------------------------------------
     
     evaluateCuts();

     //--------------------------------------------------------------------------
     // Fill preselection plots
     //--------------------------------------------------------------------------

     FillUserTH1D( "PileupWeight"   , pileup_weight );
     FillUserTH1D( "GeneratorWeight", gen_weight ) ;
     
     bool passed_minimum      = ( passedAllPreviousCuts("PassBeamHaloFilterTight") && passedCut ("PassBeamHaloFilterTight"));
     bool passed_250          = ( passedAllPreviousCuts("min_M_ej_LQ250"         ) && passedCut ("min_M_ej_LQ250"         ));
     bool passed_350          = ( passedAllPreviousCuts("min_M_ej_LQ350"         ) && passedCut ("min_M_ej_LQ350"         ));
     bool passed_400          = ( passedAllPreviousCuts("min_M_ej_LQ400"         ) && passedCut ("min_M_ej_LQ400"         ));
     bool passed_450          = ( passedAllPreviousCuts("min_M_ej_LQ450"         ) && passedCut ("min_M_ej_LQ450"         ));
     bool passed_500          = ( passedAllPreviousCuts("min_M_ej_LQ500"         ) && passedCut ("min_M_ej_LQ500"         ));
     bool passed_550          = ( passedAllPreviousCuts("min_M_ej_LQ550"         ) && passedCut ("min_M_ej_LQ550"         ));
     bool passed_600          = ( passedAllPreviousCuts("min_M_ej_LQ600"         ) && passedCut ("min_M_ej_LQ600"         ));
     bool passed_650          = ( passedAllPreviousCuts("min_M_ej_LQ650"         ) && passedCut ("min_M_ej_LQ650"         ));
     bool passed_750          = ( passedAllPreviousCuts("min_M_ej_LQ750"         ) && passedCut ("min_M_ej_LQ750"         ));
     bool passed_850          = ( passedAllPreviousCuts("min_M_ej_LQ850"         ) && passedCut ("min_M_ej_LQ850"         ));

     if ( passed_minimum && isData ){ 
       FillUserTH1D ("run_HLT", run );
       profile_run_vs_nvtx_HLT -> Fill ( run, nVertex, 1 ) ;
     }

     bool passed_preselection = ( passedAllPreviousCuts("M_e1e2") && passedCut ("M_e1e2") );

     /*
     if ( isData ) {
       std::cout.precision(0);
       std::cout << fixed <<  "Run = " << run << ", event = " << event << ", ls = " << ls << std::endl;
       std::cout.precision(3);
       std::cout << fixed <<  "  Mej      = " << M_ej_avg << std::endl;
       std::cout << fixed <<  "  Mee      = " << M_e1e2 << std::endl;
       std::cout << fixed <<  "  sT       = " << sT_enujj << std::endl;
       std::cout << fixed <<  "  Ele1 Pt  = " << Ele1_Pt << "\t, Eta = " << Ele1_Eta << "\t, Phi = " << Ele1_Phi << std::endl;
       std::cout << fixed <<  "  Ele2 Pt  = " << Ele2_Pt << "\t, Eta = " << Ele2_Eta << "\t, Phi = " << Ele2_Phi << std::endl;
       std::cout << fixed <<  "  Jet1 Pt  = " << Jet1_Pt << "\t, Eta = " << Jet1_Eta << "\t, Phi = " << Jet1_Phi << std::endl;
       std::cout << fixed <<  "  Jet2 Pt  = " << Jet2_Pt << "\t, Eta = " << Jet2_Eta << "\t, Phi = " << Jet2_Phi << std::endl;
     }
     */
     
     if ( passed_preselection ) {

       //--------------------------------------------------------------------------
       // Fill skim tree, if necessary
       //--------------------------------------------------------------------------
       
       bool isEB1 = ( fabs(Ele1_Eta) < eleEta_bar_max  ) ;
       bool isEE1 = ( fabs(Ele1_Eta) > eleEta_end_min &&
		      fabs(Ele1_Eta) < eleEta_end_max ) ;
       
       bool isEB2 = ( fabs(Ele2_Eta) < eleEta_bar_max  ) ;
       bool isEE2 = ( fabs(Ele2_Eta) > eleEta_end_min &&
		      fabs(Ele2_Eta) < eleEta_end_max ) ;

       bool isEBEB = ( isEB1 && isEB2 ) ;
       bool isEBEE = ( ( isEB1 && isEE2 ) ||
		       ( isEE1 && isEB2 ) );
       bool isEEEE = ( isEE1  && isEE2  );
       bool isEB   = ( isEBEB || isEBEE );
       
       if ( isData ) { 
	 FillUserTH1D("run_PAS", run ) ;
	 profile_run_vs_nvtx_PAS -> Fill ( run, nVertex, 1 ) ;
       }
       
       FillUserTH1D("nElectron_PAS"        , nEle_Ana         , pileup_weight * gen_weight ) ;
       FillUserTH1D("nMuon_PAS"            , nMuon_Stored     , pileup_weight * gen_weight ) ;
       FillUserTH1D("nJet_PAS"             , nJet_Ana         , pileup_weight * gen_weight ) ;
       FillUserTH1D("Pt1stEle_PAS"	   , Ele1_Pt          , pileup_weight * gen_weight ) ;
       FillUserTH1D("Eta1stEle_PAS"	   , Ele1_Eta         , pileup_weight * gen_weight ) ;
       FillUserTH1D("Phi1stEle_PAS"	   , Ele1_Phi         , pileup_weight * gen_weight ) ;
       FillUserTH1D("Pt2ndEle_PAS"	   , Ele2_Pt          , pileup_weight * gen_weight ) ;
       FillUserTH1D("Eta2ndEle_PAS"	   , Ele2_Eta         , pileup_weight * gen_weight ) ;
       FillUserTH1D("Phi2ndEle_PAS"	   , Ele2_Phi         , pileup_weight * gen_weight ) ;
       FillUserTH1D("Charge1stEle_PAS"	   , Ele1_Charge      , pileup_weight * gen_weight ) ;
       FillUserTH1D("Charge2ndEle_PAS"	   , Ele2_Charge      , pileup_weight * gen_weight ) ;
       FillUserTH1D("MET_PAS"              , MET_Pt           , pileup_weight * gen_weight ) ;
       FillUserTH1D("METSig_PAS"           , PFMETSig         , pileup_weight * gen_weight ) ;
       FillUserTH1D("METPhi_PAS"	   , MET_Phi          , pileup_weight * gen_weight ) ;
       FillUserTH1D("METCharged_PAS"       , PFMETCharged     , pileup_weight * gen_weight ) ;
       FillUserTH1D("METChargedPhi_PAS"    , PFMETChargedPhi  , pileup_weight * gen_weight ) ;   
       FillUserTH1D("METType1_PAS"         , PFMETType1Cor    , pileup_weight * gen_weight ) ;
       FillUserTH1D("METType1Phi_PAS"      , PFMETPhiType1Cor , pileup_weight * gen_weight ) ;   
       FillUserTH1D("Pt1stJet_PAS"         , Jet1_Pt          , pileup_weight * gen_weight ) ;
       FillUserTH1D("Pt2ndJet_PAS"         , Jet2_Pt          , pileup_weight * gen_weight ) ;
       FillUserTH1D("Eta1stJet_PAS"        , Jet1_Eta         , pileup_weight * gen_weight ) ;
       FillUserTH1D("Eta2ndJet_PAS"        , Jet2_Eta         , pileup_weight * gen_weight ) ;
       FillUserTH1D("Phi1stJet_PAS"	   , Jet1_Phi         , pileup_weight * gen_weight ) ;
       FillUserTH1D("Phi2ndJet_PAS"	   , Jet2_Phi         , pileup_weight * gen_weight ) ;
       FillUserTH1D("sTlep_PAS"            , Ele1_Pt + Ele2_Pt, pileup_weight * gen_weight ) ;
       FillUserTH1D("sTjet_PAS"            , Jet1_Pt + Jet2_Pt, pileup_weight * gen_weight ) ;
       FillUserTH1D("sT_PAS"               , sT_eejj          , pileup_weight * gen_weight ) ;
       FillUserTH1D("Mjj_PAS"		   , M_j1j2           , pileup_weight * gen_weight ) ;
       FillUserTH1D("Mee_PAS"		   , M_e1e2           , pileup_weight * gen_weight ) ;
       FillUserTH1D( "MTenu_PAS"           , MT_Ele1MET       , pileup_weight * gen_weight ) ;
       FillUserTH1D("Me1j1_PAS"            , M_e1j1           , pileup_weight * gen_weight ) ;
       FillUserTH1D("Me1j2_PAS"            , M_e1j2           , pileup_weight * gen_weight ) ;
       FillUserTH1D("Me2j1_PAS"            , M_e2j1           , pileup_weight * gen_weight ) ;
       FillUserTH1D("Me2j2_PAS"            , M_e2j2           , pileup_weight * gen_weight ) ;
       FillUserTH1D("Ptee_PAS"             , Pt_e1e2          , pileup_weight * gen_weight ) ;
       FillUserTH1D("DCotTheta1stEle_PAS"  , Ele1_DCotTheta   , pileup_weight * gen_weight ) ;
       FillUserTH1D("Dist1stEle_PAS"       , Ele1_Dist        , pileup_weight * gen_weight ) ;
       FillUserTH1D("DCotTheta2ndEle_PAS"  , Ele2_DCotTheta   , pileup_weight * gen_weight ) ;
       FillUserTH1D("Dist2ndEle_PAS"       , Ele2_Dist        , pileup_weight * gen_weight ) ;
       FillUserTH1D("nVertex_PAS"          , nVertex          , pileup_weight * gen_weight ) ;
       FillUserTH1D("nVertex_good_PAS"     , nVertex_good     , pileup_weight * gen_weight ) ;
       FillUserTH1D("DR_Ele1Jet1_PAS"	   , DR_Ele1Jet1      , pileup_weight * gen_weight ) ;
       FillUserTH1D("DR_Ele1Jet2_PAS"	   , DR_Ele1Jet2      , pileup_weight * gen_weight ) ;
       FillUserTH1D("DR_Ele2Jet1_PAS"	   , DR_Ele2Jet1      , pileup_weight * gen_weight ) ;
       FillUserTH1D("DR_Ele2Jet2_PAS"	   , DR_Ele2Jet2      , pileup_weight * gen_weight ) ;
       FillUserTH1D("DR_Jet1Jet2_PAS"	   , DR_Jet1Jet2      , pileup_weight * gen_weight ) ;
       
       if      ( isEBEB ) FillUserTH1D( "Mee_EBEB_PAS", M_e1e2, pileup_weight * gen_weight ); 
       else if ( isEBEE ) FillUserTH1D( "Mee_EBEE_PAS", M_e1e2, pileup_weight * gen_weight ); 
       else if ( isEEEE ) FillUserTH1D( "Mee_EEEE_PAS", M_e1e2, pileup_weight * gen_weight ); 
       if      ( isEB   ) FillUserTH1D( "Mee_EB_PAS"  , M_e1e2, pileup_weight * gen_weight ); 

       if ( M_e1e2 > 80.0 && M_e1e2 < 100.0 ){
	 FillUserTH1D("Mee_80_100_Preselection", M_e1e2, pileup_weight * gen_weight ) ;
	 if      ( isEBEB ) FillUserTH1D( "Mee_EBEB_80_100_PAS", M_e1e2, pileup_weight * gen_weight ); 
	 else if ( isEBEE ) FillUserTH1D( "Mee_EBEE_80_100_PAS", M_e1e2, pileup_weight * gen_weight ); 
	 else if ( isEEEE ) FillUserTH1D( "Mee_EEEE_80_100_PAS", M_e1e2, pileup_weight * gen_weight ); 
	 if      ( isEB   ) FillUserTH1D( "Mee_EB_80_100_PAS"  , M_e1e2, pileup_weight * gen_weight ); 
       } 

       if ( M_e1e2 > 70.0 && M_e1e2 < 110.0 ){
	 FillUserTH1D("Mee_70_110_Preselection", M_e1e2, pileup_weight * gen_weight ) ;
	 if      ( isEBEB ) FillUserTH1D( "Mee_EBEB_70_110_PAS", M_e1e2, pileup_weight * gen_weight ); 
	 else if ( isEBEE ) FillUserTH1D( "Mee_EBEE_70_110_PAS", M_e1e2, pileup_weight * gen_weight ); 
	 else if ( isEEEE ) FillUserTH1D( "Mee_EEEE_70_110_PAS", M_e1e2, pileup_weight * gen_weight ); 
	 if      ( isEB   ) FillUserTH1D( "Mee_EB_70_110_PAS"  , M_e1e2, pileup_weight * gen_weight ); 
       }
       
       double DR_Ele1Jet3 = 999.;
       double DR_Ele2Jet3 = 999.;
       double min_DR_EleJet = 999.;
       TLorentzVector eejj, e1e2mu, e1, j1, e2, j2,j3, mu, met;
       e1.SetPtEtaPhiM ( Ele1_Pt, Ele1_Eta, Ele1_Phi, 0.0 );
       e2.SetPtEtaPhiM ( Ele2_Pt, Ele2_Eta, Ele2_Phi, 0.0 );
       j1.SetPtEtaPhiM ( Jet1_Pt, Jet1_Eta, Jet1_Phi, 0.0 );
       j2.SetPtEtaPhiM ( Jet2_Pt, Jet2_Eta, Jet2_Phi, 0.0 );
       if ( nJet_Ana > 2 ) { 
	 j3.SetPtEtaPhiM ( Jet3_Pt, Jet3_Eta, Jet3_Phi, 0.0 );
	 DR_Ele1Jet3 = e1.DeltaR( j3 );
	 DR_Ele2Jet3 = e2.DeltaR( j3 );
       }
       
       if ( DR_Ele1Jet1 < min_DR_EleJet ) min_DR_EleJet = DR_Ele1Jet1;
       if ( DR_Ele1Jet2 < min_DR_EleJet ) min_DR_EleJet = DR_Ele1Jet2;
       if ( DR_Ele2Jet1 < min_DR_EleJet ) min_DR_EleJet = DR_Ele2Jet1;
       if ( DR_Ele2Jet2 < min_DR_EleJet ) min_DR_EleJet = DR_Ele2Jet2;
       if ( nJet_Ana > 2 ) {
	 if ( DR_Ele1Jet3 < min_DR_EleJet ) min_DR_EleJet = DR_Ele1Jet3;
	 if ( DR_Ele2Jet3 < min_DR_EleJet ) min_DR_EleJet = DR_Ele2Jet3;
       }
       
       FillUserTH1D( "minDR_EleJet_PAS", min_DR_EleJet, pileup_weight * gen_weight);
       
       
       mu.SetPtEtaPhiM ( Muon1_Pt, Muon1_Eta, Muon1_Phi, 0.0 );
       met.SetPtEtaPhiM ( MET_Pt, 0.0, MET_Phi, 0.0 );
       
       double DR_Ele1Ele2 = e1.DeltaR( e2 ) ;
       FillUserTH1D("DR_Ele1Ele2_PAS"	   , DR_Ele1Ele2      , pileup_weight * gen_weight ) ;
       
       eejj = e1 + e2 + j1 + j2 ; 
       double M_eejj = eejj.M();

       // e1e2mu = e1 + e2 + mu;
       // double MT_eemuMET = sqrt(2 * e1e2mu.Pt()    * MET_Pt  * (1 - cos(e1e2mu.DeltaPhi (met))));
       // FillUserTH1D("MTeemunu_PAS"         , MT_eemuMET                        , pileup_weight * gen_weight );
	      
       FillUserTH1D("Meejj_PAS", M_eejj , pileup_weight * gen_weight );

       
       if ( fabs(M_e1j1-M_e2j2) < fabs(M_e1j2-M_e2j1) )  {
	 FillUserTH1D("Mej_selected_avg_PAS", M_ej_avg, pileup_weight * gen_weight) ;	   
	 FillUserTH1D("Me1j_selected_PAS"   , M_e1j1  , pileup_weight * gen_weight) ;	   
	 FillUserTH1D("Me2j_selected_PAS"   , M_e2j2  , pileup_weight * gen_weight) ;	   
	 FillUserTH2D( "Me1jVsMe2j_selected", M_e1j1  , M_e2j2, pileup_weight * gen_weight ) ;
	 FillUserTH2D( "Me1jVsMe2j_rejected", M_e1j2  , M_e2j1, pileup_weight * gen_weight ) ;
       }

       else {
	 FillUserTH1D("Mej_selected_avg_PAS", M_ej_avg, pileup_weight * gen_weight) ;	   
	 FillUserTH1D("Me1j_selected_PAS"   , M_e1j2, pileup_weight * gen_weight) ;	   
	 FillUserTH1D("Me2j_selected_PAS"   , M_e2j1, pileup_weight * gen_weight) ;	   
	 FillUserTH2D( "Me1jVsMe2j_selected", M_e1j2, M_e2j1, pileup_weight * gen_weight ) ;
	 FillUserTH2D( "Me1jVsMe2j_rejected", M_e1j1, M_e2j2, pileup_weight * gen_weight ) ;
       }

       if ( passed_250 ) {
	 FillUserTH1D("Mej_selected_avg_LQ250", M_ej_avg, pileup_weight * gen_weight ) ;
	 FillUserTH1D("Mej_selected_min_LQ250", M_ej_min, pileup_weight * gen_weight ) ;
	 FillUserTH1D("sT_eejj_LQ250"         , sT_eejj , pileup_weight * gen_weight ) ;
	 FillUserTH1D("Mee_LQ250"             , M_e1e2  , pileup_weight * gen_weight ) ;
       }

       if ( passed_350 ) {
	 FillUserTH1D("Mej_selected_avg_LQ350", M_ej_avg, pileup_weight * gen_weight ) ;
	 FillUserTH1D("Mej_selected_min_LQ350", M_ej_min, pileup_weight * gen_weight ) ;
	 FillUserTH1D("sT_eejj_LQ350"         , sT_eejj , pileup_weight * gen_weight ) ;
	 FillUserTH1D("Mee_LQ350"             , M_e1e2  , pileup_weight * gen_weight ) ;
       }

       if ( passed_400 ) {
	 FillUserTH1D("Mej_selected_avg_LQ400", M_ej_avg, pileup_weight * gen_weight ) ;
	 FillUserTH1D("Mej_selected_min_LQ400", M_ej_min, pileup_weight * gen_weight ) ;
	 FillUserTH1D("sT_eejj_LQ400"         , sT_eejj , pileup_weight * gen_weight ) ;
	 FillUserTH1D("Mee_LQ400"             , M_e1e2  , pileup_weight * gen_weight ) ;
       }

       if ( passed_450 ) {
	 FillUserTH1D("Mej_selected_avg_LQ450", M_ej_avg, pileup_weight * gen_weight ) ;
	 FillUserTH1D("Mej_selected_min_LQ450", M_ej_min, pileup_weight * gen_weight ) ;
	 FillUserTH1D("sT_eejj_LQ450"         , sT_eejj , pileup_weight * gen_weight ) ;
	 FillUserTH1D("Mee_LQ450"             , M_e1e2  , pileup_weight * gen_weight ) ;
       }

       if ( passed_500 ) {
	 FillUserTH1D("Mej_selected_avg_LQ500", M_ej_avg, pileup_weight * gen_weight ) ;
	 FillUserTH1D("Mej_selected_min_LQ500", M_ej_min, pileup_weight * gen_weight ) ;
	 FillUserTH1D("sT_eejj_LQ500"         , sT_eejj , pileup_weight * gen_weight ) ;
	 FillUserTH1D("Mee_LQ500"             , M_e1e2  , pileup_weight * gen_weight ) ;
       }

       if ( passed_550 ) {
	 FillUserTH1D("Mej_selected_avg_LQ550", M_ej_avg, pileup_weight * gen_weight ) ;
	 FillUserTH1D("Mej_selected_min_LQ550", M_ej_min, pileup_weight * gen_weight ) ;
	 FillUserTH1D("sT_eejj_LQ550"         , sT_eejj , pileup_weight * gen_weight ) ;
	 FillUserTH1D("Mee_LQ550"             , M_e1e2  , pileup_weight * gen_weight ) ;
       }

       if ( passed_600 ) {
	 FillUserTH1D("Mej_selected_avg_LQ600", M_ej_avg, pileup_weight * gen_weight ) ;
	 FillUserTH1D("Mej_selected_min_LQ600", M_ej_min, pileup_weight * gen_weight ) ;
	 FillUserTH1D("sT_eejj_LQ600"         , sT_eejj , pileup_weight * gen_weight ) ;
	 FillUserTH1D("Mee_LQ600"             , M_e1e2  , pileup_weight * gen_weight ) ;
       }

       if ( passed_650 ) {
	 FillUserTH1D("Mej_selected_avg_LQ650", M_ej_avg, pileup_weight * gen_weight ) ;
	 FillUserTH1D("Mej_selected_min_LQ650", M_ej_min, pileup_weight * gen_weight ) ;
	 FillUserTH1D("sT_eejj_LQ650"         , sT_eejj , pileup_weight * gen_weight ) ;
	 FillUserTH1D("Mee_LQ650"             , M_e1e2  , pileup_weight * gen_weight ) ;
       }

       if ( passed_750 ) {
	 FillUserTH1D("Mej_selected_avg_LQ750", M_ej_avg, pileup_weight * gen_weight ) ;
	 FillUserTH1D("Mej_selected_min_LQ750", M_ej_min, pileup_weight * gen_weight ) ;
	 FillUserTH1D("sT_eejj_LQ750"         , sT_eejj , pileup_weight * gen_weight ) ;
	 FillUserTH1D("Mee_LQ750"             , M_e1e2  , pileup_weight * gen_weight ) ;
       }

       if ( passed_850 ) {
	 FillUserTH1D("Mej_selected_avg_LQ850", M_ej_avg, pileup_weight * gen_weight ) ;
	 FillUserTH1D("Mej_selected_min_LQ850", M_ej_min, pileup_weight * gen_weight ) ;
	 FillUserTH1D("sT_eejj_LQ850"         , sT_eejj , pileup_weight * gen_weight ) ;
	 FillUserTH1D("Mee_LQ850"             , M_e1e2  , pileup_weight * gen_weight ) ;
       }
     }
   } // End loop over events

   
   output_root_ -> cd();
   profile_run_vs_nvtx_HLT -> Write();
   profile_run_vs_nvtx_PAS -> Write();
   
   std::cout << "analysisClass::Loop() ends" <<std::endl;   
}
void analysisClass::Loop()
{
    std::cout << "analysisClass::Loop() begins" <<std::endl;

    //--------------------------------------------------------------------------
    // Final selection mass points
    //--------------------------------------------------------------------------

    const int n_lq_mass = 19;

    int LQ_MASS[n_lq_mass] = {
        300,  350,  400, 450, 500, 550,  600,  650,
        700,  750,  800, 850, 900, 950, 1000, 1050,
        1100, 1150, 1200
    };

    std::vector<bool> passed_vector;

    //--------------------------------------------------------------------------
    // Decide which plots to save (default is to save everything)
    //--------------------------------------------------------------------------

    fillSkim                         ( !true  ) ;
    fillAllPreviousCuts              ( !true  ) ;
    fillAllOtherCuts                 ( !true  ) ;
    fillAllSameLevelAndLowerLevelCuts( !true  ) ;
    fillAllCuts                      ( !true  ) ;

    //--------------------------------------------------------------------------
    // Any extra features
    //--------------------------------------------------------------------------

    TProfile * profile_run_vs_nvtx_HLT = new TProfile("run_vs_nvtx_HLT", "", 20000 , 160300  , 180300 );
    TProfile * profile_run_vs_nvtx_PAS = new TProfile("run_vs_nvtx_PAS", "", 20000 , 160300  , 180300 );

    //--------------------------------------------------------------------------
    // Get pre-cut values
    //--------------------------------------------------------------------------

    // eta boundaries

    double eleEta_bar_max = getPreCutValue1("eleEta_bar");
    double eleEta_end_min = getPreCutValue1("eleEta_end1");
    double eleEta_end_max = getPreCutValue2("eleEta_end2");

    //--------------------------------------------------------------------------
    // Create TH1D's
    //--------------------------------------------------------------------------

    CreateUserTH1D( "ProcessID"             ,    21  , -0.5    , 20.5     );
    CreateUserTH1D( "ProcessID_PAS"         ,    21  , -0.5    , 20.5     );
    CreateUserTH1D( "ProcessID_ZWindow"     ,    21  , -0.5    , 20.5     );
    CreateUserTH1D( "nElectron_PAS"         ,    5   , -0.5    , 4.5      );
    CreateUserTH1D( "nMuon_PAS"             ,    5   , -0.5    , 4.5      );
    CreateUserTH1D( "nJet_PAS"              ,    10  , -0.5    , 9.5      );
    CreateUserTH1D( "Pt1stEle_PAS"	   , 	100 , 0       , 1000     );
    CreateUserTH1D( "Eta1stEle_PAS"	   , 	100 , -5      , 5	 );
    CreateUserTH1D( "Phi1stEle_PAS"	   , 	60  , -3.1416 , +3.1416	 );
    CreateUserTH1D( "Pt2ndEle_PAS"	   , 	100 , 0       , 1000     );
    CreateUserTH1D( "Eta2ndEle_PAS"	   , 	100 , -5      , 5	 );
    CreateUserTH1D( "Phi2ndEle_PAS"	   , 	60  , -3.1416 , +3.1416	 );
    CreateUserTH1D( "Charge1stEle_PAS"	   , 	2   , -1.0001 , 1.0001	 );
    CreateUserTH1D( "Charge2ndEle_PAS"	   , 	2   , -1.0001 , 1.0001	 );
    CreateUserTH1D( "MET_PAS"               ,    200 , 0       , 1000	 );
    CreateUserTH1D( "METPhi_PAS"		   , 	60  , -3.1416 , +3.1416	 );
    CreateUserTH1D( "Pt1stJet_PAS"          ,    100 , 0       , 1000	 );
    CreateUserTH1D( "Pt2ndJet_PAS"          ,    100 , 0       , 1000	 );
    CreateUserTH1D( "Eta1stJet_PAS"         ,    100 , -5      , 5	 );
    CreateUserTH1D( "Eta2ndJet_PAS"         ,    100 , -5      , 5	 );
    CreateUserTH1D( "Phi1stJet_PAS"	   , 	60  , -3.1416 , +3.1416	 );
    CreateUserTH1D( "Phi2ndJet_PAS"	   , 	60  , -3.1416 , +3.1416	 );
    CreateUserTH1D( "sTlep_PAS"             ,    200 , 0       , 2000	 );
    CreateUserTH1D( "sTjet_PAS"             ,    200 , 0       , 2000	 );
    CreateUserTH1D( "sT_PAS"                ,    200 , 0       , 2000	 );
    CreateUserTH1D( "sT_PASandMee100"       ,    200 , 0       , 2000	 );
    CreateUserTH1D( "Mjj_PAS"		   ,    200 , 0       , 2000	 );
    CreateUserTH1D( "Mee_PAS"		   ,    200 , 0       , 2000	 );
    CreateUserTH1D( "Mee_PASandST445"       ,    200 , 0       , 2000	 );
    CreateUserTH1D( "MTenu_PAS"                , 200 , 0       , 1000	 );
    CreateUserTH1D( "Me1j1_PAS"             ,    200 , 0       , 2000	 );
    CreateUserTH1D( "Me1j2_PAS"             ,    200 , 0       , 2000	 );
    CreateUserTH1D( "Me2j1_PAS"             ,    200 , 0       , 2000	 );
    CreateUserTH1D( "Me2j2_PAS"             ,    200 , 0       , 2000	 );
    CreateUserTH1D( "Me1j_selected_PAS"     ,    200 , 0       , 2000	 );
    CreateUserTH1D( "Me2j_selected_PAS"     ,    200 , 0       , 2000     );
    CreateUserTH1D( "Mej_selected_avg_PAS"  ,    200 , 0       , 2000     );
    CreateUserTH1D( "Mej_selected_min_PAS"  ,    200 , 0       , 2000     );
    CreateUserTH1D( "Mej_selected_max_PAS"  ,    200 , 0       , 2000     );
    CreateUserTH1D( "Mej_minmax_PAS"        ,    200 , 0       , 2000     );
    CreateUserTH1D( "Meejj_PAS"             ,    200 , 0       , 2000     );
    CreateUserTH1D( "run_PAS"               ,    20000 , 160300  , 180300 );
    CreateUserTH1D( "run_HLT"               ,    20000 , 160300  , 180300 );

    CreateUserTH1D( "Ptee_PAS"              ,    200 , 0       , 2000     );

    CreateUserTH1D( "DCotTheta1stEle_PAS"   ,    100 , 0.0, 1.0);
    CreateUserTH1D( "Dist1stEle_PAS"        ,    100 , 0.0, 1.0);
    CreateUserTH1D( "DCotTheta2ndEle_PAS"   ,    100 , 0.0, 1.0);
    CreateUserTH1D( "Dist2ndEle_PAS"        ,    100 , 0.0, 1.0);

    CreateUserTH1D( "nVertex_PAS"           ,    101   , -0.5   , 100.5	 ) ;

    CreateUserTH1D( "DR_Ele1Jet1_PAS"	   , 	getHistoNBins("DR_Ele1Jet1"), getHistoMin("DR_Ele1Jet1"), getHistoMax("DR_Ele1Jet1")     ) ;
    CreateUserTH1D( "DR_Ele1Jet2_PAS"	   , 	getHistoNBins("DR_Ele1Jet2"), getHistoMin("DR_Ele1Jet2"), getHistoMax("DR_Ele1Jet2")     ) ;
    CreateUserTH1D( "DR_Ele2Jet1_PAS"	   , 	getHistoNBins("DR_Ele2Jet1"), getHistoMin("DR_Ele2Jet1"), getHistoMax("DR_Ele2Jet1")     ) ;
    CreateUserTH1D( "DR_Ele2Jet2_PAS"	   , 	getHistoNBins("DR_Ele2Jet2"), getHistoMin("DR_Ele2Jet2"), getHistoMax("DR_Ele2Jet2")     ) ;
    CreateUserTH1D( "DR_Jet1Jet2_PAS"	   , 	getHistoNBins("DR_Jet1Jet2"), getHistoMin("DR_Jet1Jet2"), getHistoMax("DR_Jet1Jet2")     ) ;
    CreateUserTH1D( "DR_Ele1Ele2_PAS"	   , 	getHistoNBins("DR_Jet1Jet2"), getHistoMin("DR_Jet1Jet2"), getHistoMax("DR_Jet1Jet2")     ) ;
    CreateUserTH1D( "minDR_EleJet_PAS"	   , 	getHistoNBins("DR_Jet1Jet2"), getHistoMin("DR_Jet1Jet2"), getHistoMax("DR_Jet1Jet2")     ) ;

    CreateUserTH2D( "Me1jVsMe2j_selected",     200, 0, 2000, 200, 0, 2000) ;
    CreateUserTH2D( "Me1jVsMe2j_rejected",     200, 0, 2000, 200, 0, 2000) ;

    CreateUserTH1D( "MTeemunu_PAS"          ,    200 , 0       , 1000	 );

    CreateUserTH1D( "Mee_80_100_Preselection", 200, 60, 120 );
    CreateUserTH1D( "Mee_70_110_Preselection", 200, 60, 120 );

    CreateUserTH1D( "Mee_70_110_Preselection_Process0", 200, 60, 120 );
    CreateUserTH1D( "Mee_70_110_Preselection_Process1", 200, 60, 120 );
    CreateUserTH1D( "Mee_70_110_Preselection_Process2", 200, 60, 120 );
    CreateUserTH1D( "Mee_70_110_Preselection_Process3", 200, 60, 120 );
    CreateUserTH1D( "Mee_70_110_Preselection_Process4", 200, 60, 120 );

    CreateUserTH1D( "Mee_EBEB_PAS"		   ,    60 , 60       , 120	 );
    CreateUserTH1D( "Mee_EBEE_PAS"		   ,    60 , 60       , 120	 );
    CreateUserTH1D( "Mee_EEEE_PAS"		   ,    60 , 60       , 120	 );
    CreateUserTH1D( "Mee_EB_PAS" 		   ,    60 , 60       , 120	 );

    CreateUserTH1D( "Mee_EBEB_80_100_PAS"	   ,    60 , 60       , 120	 );
    CreateUserTH1D( "Mee_EBEE_80_100_PAS"	   ,    60 , 60       , 120	 );
    CreateUserTH1D( "Mee_EEEE_80_100_PAS"	   ,    60 , 60       , 120	 );
    CreateUserTH1D( "Mee_EB_80_100_PAS" 	     	   ,    60 , 60       , 120	 );

    CreateUserTH1D( "Mee_EBEB_70_110_PAS"	   ,    60 , 60       , 120	 );
    CreateUserTH1D( "Mee_EBEE_70_110_PAS"	   ,    60 , 60       , 120	 );
    CreateUserTH1D( "Mee_EEEE_70_110_PAS"	   ,    60 , 60       , 120	 );
    CreateUserTH1D( "Mee_EB_70_110_PAS" 	     	   ,    60 , 60       , 120	 );

    CreateUserTH1D( "PileupWeight"   , 100, -10, 10 );
    CreateUserTH1D( "GeneratorWeight", 100, -2.0, 2.0);

    //--------------------------------------------------------------------------
    // Final selection plots
    //--------------------------------------------------------------------------

    char plot_name[100];

    for (int i_lq_mass = 0; i_lq_mass < n_lq_mass ; ++i_lq_mass ) {
        int lq_mass = LQ_MASS[i_lq_mass];
        sprintf(plot_name, "Mej_selected_avg_LQ%d"       , lq_mass );
        CreateUserTH1D ( plot_name, 50  , 0 , 2500 );
        sprintf(plot_name, "Mej_selected_min_LQ%d"       , lq_mass );
        CreateUserTH1D ( plot_name, 50  , 0 , 2500 );
        sprintf(plot_name, "Mej_selected_max_LQ%d"       , lq_mass );
        CreateUserTH1D ( plot_name, 50  , 0 , 2500 );
        sprintf(plot_name, "Mej_minmax_LQ%d"             , lq_mass );
        CreateUserTH1D ( plot_name, 50  , 0 , 2500 );
        sprintf(plot_name, "sT_eejj_LQ%d"                , lq_mass );
        CreateUserTH1D ( plot_name, 25  , 0 , 2500 );
        sprintf(plot_name, "Mee_LQ%d"                    , lq_mass );
        CreateUserTH1D ( plot_name, 40  , 0 , 2000 );
        sprintf(plot_name, "Mej_selected_min_vs_max_LQ%d", lq_mass );
        CreateUserTH2D ( plot_name, 50  , 0 , 1000, 50  , 0 , 1000 );
    }

    //--------------------------------------------------------------------------
    // Loop over the chain
    //--------------------------------------------------------------------------

    if (fChain == 0) return;

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

    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 << "/" << nentries << std::endl;

        //--------------------------------------------------------------------------
        // Reset the cuts
        //--------------------------------------------------------------------------

        resetCuts();

        //--------------------------------------------------------------------------
        // Check good run list
        //--------------------------------------------------------------------------

        int    passedJSON = passJSON ( run, ls , isData ) ;

        //--------------------------------------------------------------------------
        // Do pileup re-weighting
        //--------------------------------------------------------------------------

        double pileup_weight = getPileupWeight ( nPileUpInt_True, isData ) ;

        //--------------------------------------------------------------------------
        // Get information about gen-level reweighting (should be for Sherpa only)
        //--------------------------------------------------------------------------

        double gen_weight = Weight;
        if ( isData ) gen_weight = 1.0;
        if ( isData && Ele2_ValidFrac > 998. ) {
            gen_weight = 0.0;
            if      (  60.0 < M_e1e2 < 120. ) gen_weight = 0.61;
            else if ( 120.0 < M_e1e2 < 200. ) gen_weight = 0.42;
            else if ( 200.0 < M_e1e2        ) gen_weight = 0.42;
        }

        // std::cout << "Gen weight = " << int ( 1.0 / gen_weight ) << std::endl;

        //--------------------------------------------------------------------------
        // Fill variables
        //--------------------------------------------------------------------------

        // JSON variable
        fillVariableWithValue(   "PassJSON"                      , passedJSON, gen_weight * pileup_weight   ) ;

        // Noise filters
        fillVariableWithValue(   "PassHBHENoiseFilter"	      , PassHBHENoiseFilter                              , gen_weight * pileup_weight );
        fillVariableWithValue(   "PassBeamHaloFilterTight"       , PassBeamHaloFilterTight                          , gen_weight * pileup_weight );
        fillVariableWithValue(   "PassBadEESupercrystalFilter"   , ( isData == 1 ) ? PassBadEESupercrystalFilter : 1, gen_weight * pileup_weight );
        fillVariableWithValue(   "PassBeamScraping"	      , ( isData == 1 ) ? PassBeamScraping	      : 1, gen_weight * pileup_weight );
        fillVariableWithValue(   "PassEcalDeadCellBoundEnergy"   , PassEcalDeadCellBoundEnergy                      , gen_weight * pileup_weight );
        fillVariableWithValue(   "PassEcalDeadCellTrigPrim"      , PassEcalDeadCellTrigPrim                         , gen_weight * pileup_weight );
        fillVariableWithValue(   "PassEcalLaserCorrFilter"       , ( isData == 1 ) ? PassEcalLaserCorrFilter     : 1, gen_weight * pileup_weight );
        fillVariableWithValue(   "PassHcalLaserEventFilter"      , ( isData == 1 ) ? PassHcalLaserEventFilter    : 1, gen_weight * pileup_weight );
        fillVariableWithValue(   "PassPhysDecl"		      , ( isData == 1 ) ? PassPhysDecl		      : 1, gen_weight * pileup_weight );
        fillVariableWithValue(   "PassPrimaryVertex"	      , PassPrimaryVertex                                , gen_weight * pileup_weight );
        fillVariableWithValue(   "PassTrackingFailure"	      , ( isData == 1 ) ? PassTrackingFailure	      : 1, gen_weight * pileup_weight );

        //fillVariableWithValue(   "PassBPTX0"                     , PassBPTX0                  , gen_weight  ) ;
        //fillVariableWithValue(   "PassPhysDecl"                  , PassPhysDecl               , gen_weight  ) ;
        //fillVariableWithValue(   "PassBeamScraping"              , PassBeamScraping           , gen_weight  ) ;
        //fillVariableWithValue(   "PassPrimaryVertex"             , PassPrimaryVertex          , gen_weight  ) ;
        //fillVariableWithValue(   "PassBeamHaloFilterLoose"	      , PassBeamHaloFilterLoose	   , gen_weight  ) ;
        //fillVariableWithValue(   "PassTrackingFailure"           , PassTrackingFailure        , gen_weight  ) ;
        //fillVariableWithValue(   "PassCaloBoundaryDRFilter"      , PassCaloBoundaryDRFilter   , gen_weight  ) ;
        //fillVariableWithValue(   "PassEcalMaskedCellDRFilter"    , PassEcalMaskedCellDRFilter , gen_weight  ) ;

        // Fill HLT

        int passHLT = 1;
        if ( isData ) {
            passHLT = 0;
            if ( H_DoubleEle33_CIdL_GsfIdVL == 1 ) {
                passHLT = 1;
            }
        }


        int nEle_hltMatched = 0.0;
        if ( Ele1_hltEleSignalPt > 0.0 ) nEle_hltMatched++;
        if ( Ele2_hltEleSignalPt > 0.0 ) nEle_hltMatched++;

        int nJet_hltMatched = 0.0;
        if ( Jet1_hltNoPUJetPt > 0.0 || Jet1_hltJetPt > 0.0 ) nJet_hltMatched++;
        if ( Jet2_hltNoPUJetPt > 0.0 || Jet2_hltJetPt > 0.0 ) nJet_hltMatched++;


        /*
        int passHLT = 0;
        if ( H_Ele30_PFJet100_25      == 1 ||
         H_Ele30_PFNoPUJet100_25  == 1 ){
          passHLT = 1;
        }
        */

        // Muons and electrons
        bool is_ttbar_from_data = false;
        if ( Ele2_ValidFrac > 998. ) is_ttbar_from_data = true;

        int PassNEle = 0;
        if ( !is_ttbar_from_data && nEle_ptCut == 2 ) PassNEle = 1;
        if (  is_ttbar_from_data && nEle_ptCut == 2 ) PassNEle = 1;

        int PassNMuon = 0;
        if ( !is_ttbar_from_data && nMuon_ptCut == 0 ) PassNMuon = 1;
        if (  is_ttbar_from_data && nMuon_ptCut >  0 ) PassNMuon = 1;

        fillVariableWithValue ( "Reweighting", 1, gen_weight * pileup_weight  );
        fillVariableWithValue ( "PassHLT", passHLT, gen_weight * pileup_weight  ) ;
        fillVariableWithValue("nEle_hltMatched",nEle_hltMatched, gen_weight * pileup_weight  );
        fillVariableWithValue("nJet_hltMatched",nJet_hltMatched, gen_weight * pileup_weight  );

        // Electrons
        fillVariableWithValue(   "PassNEle"                      , PassNEle    , gen_weight * pileup_weight  ) ;
        if ( nEle_store >= 1 ) {
            fillVariableWithValue( "Ele1_Pt"                       , Ele1_Pt     , gen_weight * pileup_weight  ) ;
        }
        if ( nEle_store >= 2 ) {
            fillVariableWithValue( "Ele2_Pt"                       , Ele2_Pt     , gen_weight * pileup_weight  ) ;
            fillVariableWithValue( "M_e1e2"                        , M_e1e2      , gen_weight * pileup_weight  ) ;
            fillVariableWithValue( "M_e1e2_opt"                    , M_e1e2      , gen_weight * pileup_weight  ) ;
        }

        // Jets
        fillVariableWithValue(   "nJet"                          , nJet_ptCut  , gen_weight * pileup_weight  ) ;
        if ( nJet_store >= 1 ) {
            fillVariableWithValue( "Jet1_Pt"                       , Jet1_Pt     , gen_weight * pileup_weight  ) ;
            fillVariableWithValue( "Jet1_Eta"                      , Jet1_Eta    , gen_weight * pileup_weight  ) ;
        }
        if ( nJet_store >= 2 ) {
            fillVariableWithValue( "Jet2_Pt"                       , Jet2_Pt     , gen_weight * pileup_weight  ) ;
            fillVariableWithValue( "Jet2_Eta"                      , Jet2_Eta    , gen_weight * pileup_weight  ) ;
            fillVariableWithValue( "DR_Jet1Jet2"                   , DR_Jet1Jet2 , gen_weight * pileup_weight  ) ;
        }

        // Muons
        fillVariableWithValue(   "PassNMuon"                     , PassNMuon   , gen_weight * pileup_weight  ) ;

        // DeltaR
        if ( nEle_store >= 2 && nJet_store >= 1) {
            fillVariableWithValue( "DR_Ele1Jet1"                   , DR_Ele1Jet1 , gen_weight * pileup_weight  ) ;
            fillVariableWithValue( "DR_Ele2Jet1"                   , DR_Ele2Jet1 , gen_weight * pileup_weight  ) ;
            if(nJet_store >= 2) {
                fillVariableWithValue( "DR_Ele1Jet2"                 , DR_Ele1Jet2 , gen_weight * pileup_weight  ) ;
                fillVariableWithValue( "DR_Ele2Jet2"                 , DR_Ele2Jet2 , gen_weight * pileup_weight  ) ;
            }
        }

        // sT
        double M_ej_avg;
        double M_ej_min;
        double M_ej_max;

        if ( nEle_store >= 2 && nJet_store >= 2) {
            if ( fabs(M_e1j1-M_e2j2) < fabs(M_e1j2-M_e2j1) )  {
                M_ej_avg = (M_e1j1 + M_e2j2) / 2.0;
                if    ( M_e1j1 < M_e2j2 ) {
                    M_ej_min = M_e1j1;
                    M_ej_max = M_e2j2;
                }
                else                      {
                    M_ej_min = M_e2j2;
                    M_ej_max = M_e1j1;
                }
            }
            else {
                M_ej_avg = (M_e1j2 + M_e2j1) / 2.0;
                if    ( M_e1j2 < M_e2j1 ) {
                    M_ej_min = M_e1j2;
                    M_ej_max = M_e2j1;
                }
                else                      {
                    M_ej_min = M_e2j1;
                    M_ej_max = M_e1j2;
                }
            }

            fillVariableWithValue( "sT_eejj"                      , sT_eejj , gen_weight * pileup_weight  ) ;
            fillVariableWithValue( "sT_eejj_opt"                  , sT_eejj , gen_weight * pileup_weight  ) ;
            fillVariableWithValue( "Mej_min_opt"                  , M_ej_min, gen_weight * pileup_weight  ) ;
        }

        //--------------------------------------------------------------------------
        // Fill final selection cuts
        //--------------------------------------------------------------------------

        char cut_name[100];
        for (int i_lq_mass = 0; i_lq_mass < n_lq_mass; ++i_lq_mass ) {
            int lq_mass = LQ_MASS[i_lq_mass];
            sprintf(cut_name, "M_e1e2_LQ%d"  , lq_mass );
            fillVariableWithValue ( cut_name, M_e1e2  , gen_weight * pileup_weight  ) ;
            sprintf(cut_name, "sT_eejj_LQ%d" , lq_mass );
            fillVariableWithValue ( cut_name, sT_eejj , gen_weight * pileup_weight  ) ;
            sprintf(cut_name, "min_M_ej_LQ%d", lq_mass );
            fillVariableWithValue ( cut_name, M_ej_min, gen_weight * pileup_weight  ) ;
        }

        //--------------------------------------------------------------------------
        // Evaluate the cuts
        //--------------------------------------------------------------------------

        evaluateCuts();

        //--------------------------------------------------------------------------
        // Did we pass any final selections?
        //--------------------------------------------------------------------------

        passed_vector.clear();
        for (int i_lq_mass = 0; i_lq_mass < n_lq_mass; ++i_lq_mass ) {
            int lq_mass = LQ_MASS[i_lq_mass];
            sprintf(cut_name, "M_e1e2_LQ%d", lq_mass );
            bool decision = bool ( passedAllPreviousCuts(cut_name) && passedCut (cut_name));
            passed_vector.push_back (decision);
        }

        //--------------------------------------------------------------------------
        // Fill skim-level plots
        //--------------------------------------------------------------------------

        bool passed_minimum = ( passedAllPreviousCuts("PassTrackingFailure") && passedCut ("PassTrackingFailure"));

        if ( passed_minimum && isData ) {
            FillUserTH1D ("run_HLT", run );
            profile_run_vs_nvtx_HLT -> Fill ( run, nVertex, 1 ) ;
        }

        //--------------------------------------------------------------------------
        // Fill preselection plots
        //--------------------------------------------------------------------------

        FillUserTH1D( "PileupWeight"   , pileup_weight );
        FillUserTH1D( "GeneratorWeight", gen_weight ) ;

        bool passed_preselection = ( passedAllPreviousCuts("M_e1e2") && passedCut ("M_e1e2") );

        /*
        if ( isData ) {
          std::cout.precision(0);
          std::cout << fixed <<  "Run = " << run << ", event = " << event << ", ls = " << ls << std::endl;
          std::cout.precision(3);
          std::cout << fixed <<  "  Mej      = " << M_ej_avg << std::endl;
          std::cout << fixed <<  "  Mee      = " << M_e1e2 << std::endl;
          std::cout << fixed <<  "  sT       = " << sT_enujj << std::endl;
          std::cout << fixed <<  "  Ele1 Pt  = " << Ele1_Pt << "\t, Eta = " << Ele1_Eta << "\t, Phi = " << Ele1_Phi << std::endl;
          std::cout << fixed <<  "  Ele2 Pt  = " << Ele2_Pt << "\t, Eta = " << Ele2_Eta << "\t, Phi = " << Ele2_Phi << std::endl;
          std::cout << fixed <<  "  Jet1 Pt  = " << Jet1_Pt << "\t, Eta = " << Jet1_Eta << "\t, Phi = " << Jet1_Phi << std::endl;
          std::cout << fixed <<  "  Jet2 Pt  = " << Jet2_Pt << "\t, Eta = " << Jet2_Eta << "\t, Phi = " << Jet2_Phi << std::endl;
        }
        */

        if ( passed_preselection ) {

            FillUserTH1D( "ProcessID_PAS"      , ProcessID, pileup_weight * gen_weight ) ;

            //--------------------------------------------------------------------------
            // Fill skim tree, if necessary
            //--------------------------------------------------------------------------

            bool isEB1 = ( fabs(Ele1_Eta) < eleEta_bar_max  ) ;
            bool isEE1 = ( fabs(Ele1_Eta) > eleEta_end_min &&
                           fabs(Ele1_Eta) < eleEta_end_max ) ;

            bool isEB2 = ( fabs(Ele2_Eta) < eleEta_bar_max  ) ;
            bool isEE2 = ( fabs(Ele2_Eta) > eleEta_end_min &&
                           fabs(Ele2_Eta) < eleEta_end_max ) ;

            bool isEBEB = ( isEB1 && isEB2 ) ;
            bool isEBEE = ( ( isEB1 && isEE2 ) ||
                            ( isEE1 && isEB2 ) );
            bool isEEEE = ( isEE1  && isEE2  );
            bool isEB   = ( isEBEB || isEBEE );

            if ( isData ) {
                FillUserTH1D("run_PAS", run ) ;
                profile_run_vs_nvtx_PAS -> Fill ( run, nVertex, 1 ) ;
            }

            FillUserTH1D("nElectron_PAS"        , nEle_ptCut         , pileup_weight * gen_weight ) ;
            FillUserTH1D("nMuon_PAS"            , nMuon_ptCut        , pileup_weight * gen_weight ) ;
            FillUserTH1D("nJet_PAS"             , nJet_ptCut         , pileup_weight * gen_weight ) ;
            FillUserTH1D("Pt1stEle_PAS"	   , Ele1_Pt            , pileup_weight * gen_weight ) ;
            FillUserTH1D("Eta1stEle_PAS"	   , Ele1_Eta           , pileup_weight * gen_weight ) ;
            FillUserTH1D("Phi1stEle_PAS"	   , Ele1_Phi           , pileup_weight * gen_weight ) ;
            FillUserTH1D("Pt2ndEle_PAS"	   , Ele2_Pt            , pileup_weight * gen_weight ) ;
            FillUserTH1D("Eta2ndEle_PAS"	   , Ele2_Eta           , pileup_weight * gen_weight ) ;
            FillUserTH1D("Phi2ndEle_PAS"	   , Ele2_Phi           , pileup_weight * gen_weight ) ;
            FillUserTH1D("Charge1stEle_PAS"	   , Ele1_Charge        , pileup_weight * gen_weight ) ;
            FillUserTH1D("Charge2ndEle_PAS"	   , Ele2_Charge        , pileup_weight * gen_weight ) ;
            FillUserTH1D("MET_PAS"              , PFMET_Type01XY_Pt  , pileup_weight * gen_weight ) ;
            FillUserTH1D("METPhi_PAS"	   , PFMET_Type01XY_Phi , pileup_weight * gen_weight ) ;
            FillUserTH1D("Pt1stJet_PAS"         , Jet1_Pt            , pileup_weight * gen_weight ) ;
            FillUserTH1D("Pt2ndJet_PAS"         , Jet2_Pt            , pileup_weight * gen_weight ) ;
            FillUserTH1D("Eta1stJet_PAS"        , Jet1_Eta           , pileup_weight * gen_weight ) ;
            FillUserTH1D("Eta2ndJet_PAS"        , Jet2_Eta           , pileup_weight * gen_weight ) ;
            FillUserTH1D("Phi1stJet_PAS"	   , Jet1_Phi           , pileup_weight * gen_weight ) ;
            FillUserTH1D("Phi2ndJet_PAS"	   , Jet2_Phi           , pileup_weight * gen_weight ) ;
            FillUserTH1D("sTlep_PAS"            , Ele1_Pt + Ele2_Pt  , pileup_weight * gen_weight ) ;
            FillUserTH1D("sTjet_PAS"            , Jet1_Pt + Jet2_Pt  , pileup_weight * gen_weight ) ;
            FillUserTH1D("sT_PAS"               , sT_eejj            , pileup_weight * gen_weight ) ;
            FillUserTH1D("Mjj_PAS"		   , M_j1j2             , pileup_weight * gen_weight ) ;
            FillUserTH1D("Mee_PAS"		   , M_e1e2             , pileup_weight * gen_weight ) ;
            FillUserTH1D( "MTenu_PAS"           , MT_Ele1MET         , pileup_weight * gen_weight ) ;
            FillUserTH1D("Me1j1_PAS"            , M_e1j1             , pileup_weight * gen_weight ) ;
            FillUserTH1D("Me1j2_PAS"            , M_e1j2             , pileup_weight * gen_weight ) ;
            FillUserTH1D("Me2j1_PAS"            , M_e2j1             , pileup_weight * gen_weight ) ;
            FillUserTH1D("Me2j2_PAS"            , M_e2j2             , pileup_weight * gen_weight ) ;
            FillUserTH1D("Ptee_PAS"             , Pt_e1e2            , pileup_weight * gen_weight ) ;
            FillUserTH1D("DCotTheta1stEle_PAS"  , Ele1_DCotTheta     , pileup_weight * gen_weight ) ;
            FillUserTH1D("Dist1stEle_PAS"       , Ele1_Dist          , pileup_weight * gen_weight ) ;
            FillUserTH1D("DCotTheta2ndEle_PAS"  , Ele2_DCotTheta     , pileup_weight * gen_weight ) ;
            FillUserTH1D("Dist2ndEle_PAS"       , Ele2_Dist          , pileup_weight * gen_weight ) ;
            FillUserTH1D("nVertex_PAS"          , nVertex            , pileup_weight * gen_weight ) ;
            FillUserTH1D("DR_Ele1Jet1_PAS"	   , DR_Ele1Jet1        , pileup_weight * gen_weight ) ;
            FillUserTH1D("DR_Ele1Jet2_PAS"	   , DR_Ele1Jet2        , pileup_weight * gen_weight ) ;
            FillUserTH1D("DR_Ele2Jet1_PAS"	   , DR_Ele2Jet1        , pileup_weight * gen_weight ) ;
            FillUserTH1D("DR_Ele2Jet2_PAS"	   , DR_Ele2Jet2        , pileup_weight * gen_weight ) ;
            FillUserTH1D("DR_Jet1Jet2_PAS"	   , DR_Jet1Jet2        , pileup_weight * gen_weight ) ;

            if ( passedCut ("sT_eejj_LQ300") ) {
                FillUserTH1D( "Mee_PASandST445", M_e1e2, pileup_weight * gen_weight ) ;
            }

            if ( passedCut ("M_e1e2_LQ300") ) {
                FillUserTH1D("sT_PASandMee100", sT_eejj, pileup_weight * gen_weight ) ;
            }

            if ( passedCut ("sT_eejj_LQ300" ) &&
                    passedCut ("min_M_ej_LQ300") ) {

            }



            if      ( isEBEB ) FillUserTH1D( "Mee_EBEB_PAS", M_e1e2, pileup_weight * gen_weight );
            else if ( isEBEE ) FillUserTH1D( "Mee_EBEE_PAS", M_e1e2, pileup_weight * gen_weight );
            else if ( isEEEE ) FillUserTH1D( "Mee_EEEE_PAS", M_e1e2, pileup_weight * gen_weight );
            if      ( isEB   ) FillUserTH1D( "Mee_EB_PAS"  , M_e1e2, pileup_weight * gen_weight );

            if ( M_e1e2 > 80.0 && M_e1e2 < 100.0 ) {
                FillUserTH1D("Mee_80_100_Preselection", M_e1e2, pileup_weight * gen_weight ) ;
                if      ( isEBEB ) FillUserTH1D( "Mee_EBEB_80_100_PAS", M_e1e2, pileup_weight * gen_weight );
                else if ( isEBEE ) FillUserTH1D( "Mee_EBEE_80_100_PAS", M_e1e2, pileup_weight * gen_weight );
                else if ( isEEEE ) FillUserTH1D( "Mee_EEEE_80_100_PAS", M_e1e2, pileup_weight * gen_weight );
                if      ( isEB   ) FillUserTH1D( "Mee_EB_80_100_PAS"  , M_e1e2, pileup_weight * gen_weight );
            }

            if ( M_e1e2 > 70.0 && M_e1e2 < 110.0 ) {
                FillUserTH1D("Mee_70_110_Preselection", M_e1e2, pileup_weight * gen_weight ) ;
                if      ( isEBEB ) FillUserTH1D( "Mee_EBEB_70_110_PAS", M_e1e2, pileup_weight * gen_weight );
                else if ( isEBEE ) FillUserTH1D( "Mee_EBEE_70_110_PAS", M_e1e2, pileup_weight * gen_weight );
                else if ( isEEEE ) FillUserTH1D( "Mee_EEEE_70_110_PAS", M_e1e2, pileup_weight * gen_weight );
                if      ( isEB   ) FillUserTH1D( "Mee_EB_70_110_PAS"  , M_e1e2, pileup_weight * gen_weight );

                FillUserTH1D( "ProcessID_ZWindow", ProcessID, pileup_weight * gen_weight );
                if ( ProcessID == 0 ) FillUserTH1D ( "Mee_70_110_Preselection_Process0", M_e1e2, pileup_weight * gen_weight );
                if ( ProcessID == 1 ) FillUserTH1D ( "Mee_70_110_Preselection_Process1", M_e1e2, pileup_weight * gen_weight );
                if ( ProcessID == 2 ) FillUserTH1D ( "Mee_70_110_Preselection_Process2", M_e1e2, pileup_weight * gen_weight );
                if ( ProcessID == 3 ) FillUserTH1D ( "Mee_70_110_Preselection_Process3", M_e1e2, pileup_weight * gen_weight );
                if ( ProcessID == 4 ) FillUserTH1D ( "Mee_70_110_Preselection_Process4", M_e1e2, pileup_weight * gen_weight );
            }

            double DR_Ele1Jet3 = 999.;
            double DR_Ele2Jet3 = 999.;
            double min_DR_EleJet = 999.;
            TLorentzVector eejj, e1e2mu, e1, j1, e2, j2,j3, mu, met;
            e1.SetPtEtaPhiM ( Ele1_Pt, Ele1_Eta, Ele1_Phi, 0.0 );
            e2.SetPtEtaPhiM ( Ele2_Pt, Ele2_Eta, Ele2_Phi, 0.0 );
            j1.SetPtEtaPhiM ( Jet1_Pt, Jet1_Eta, Jet1_Phi, 0.0 );
            j2.SetPtEtaPhiM ( Jet2_Pt, Jet2_Eta, Jet2_Phi, 0.0 );
            if ( nJet_store > 2 ) {
                j3.SetPtEtaPhiM ( Jet3_Pt, Jet3_Eta, Jet3_Phi, 0.0 );
                DR_Ele1Jet3 = e1.DeltaR( j3 );
                DR_Ele2Jet3 = e2.DeltaR( j3 );
            }

            if ( DR_Ele1Jet1 < min_DR_EleJet ) min_DR_EleJet = DR_Ele1Jet1;
            if ( DR_Ele1Jet2 < min_DR_EleJet ) min_DR_EleJet = DR_Ele1Jet2;
            if ( DR_Ele2Jet1 < min_DR_EleJet ) min_DR_EleJet = DR_Ele2Jet1;
            if ( DR_Ele2Jet2 < min_DR_EleJet ) min_DR_EleJet = DR_Ele2Jet2;
            if ( nJet_store > 2 ) {
                if ( DR_Ele1Jet3 < min_DR_EleJet ) min_DR_EleJet = DR_Ele1Jet3;
                if ( DR_Ele2Jet3 < min_DR_EleJet ) min_DR_EleJet = DR_Ele2Jet3;
            }

            FillUserTH1D( "minDR_EleJet_PAS", min_DR_EleJet, pileup_weight * gen_weight);


            mu.SetPtEtaPhiM ( Muon1_Pt, Muon1_Eta, Muon1_Phi, 0.0 );
            met.SetPtEtaPhiM ( PFMET_Type01XY_Pt, 0.0, PFMET_Type01XY_Phi, 0.0 );

            double DR_Ele1Ele2 = e1.DeltaR( e2 ) ;
            FillUserTH1D("DR_Ele1Ele2_PAS"	   , DR_Ele1Ele2      , pileup_weight * gen_weight ) ;

            eejj = e1 + e2 + j1 + j2 ;
            double M_eejj = eejj.M();

            FillUserTH1D("Meejj_PAS", M_eejj , pileup_weight * gen_weight );


            if ( fabs(M_e1j1-M_e2j2) < fabs(M_e1j2-M_e2j1) )  {
                FillUserTH1D("Mej_selected_avg_PAS", M_ej_avg, pileup_weight * gen_weight) ;
                FillUserTH1D("Mej_selected_min_PAS", M_ej_min, pileup_weight * gen_weight) ;
                FillUserTH1D("Mej_selected_max_PAS", M_ej_max, pileup_weight * gen_weight) ;
                FillUserTH1D("Mej_minmax_PAS"      , M_ej_min, pileup_weight * gen_weight) ;
                FillUserTH1D("Mej_minmax_PAS"      , M_ej_max, pileup_weight * gen_weight) ;
                FillUserTH1D("Me1j_selected_PAS"   , M_e1j1  , pileup_weight * gen_weight) ;
                FillUserTH1D("Me2j_selected_PAS"   , M_e2j2  , pileup_weight * gen_weight) ;
                FillUserTH2D( "Me1jVsMe2j_selected", M_e1j1  , M_e2j2, pileup_weight * gen_weight ) ;
                FillUserTH2D( "Me1jVsMe2j_rejected", M_e1j2  , M_e2j1, pileup_weight * gen_weight ) ;
            }

            else {
                FillUserTH1D("Mej_selected_avg_PAS", M_ej_avg, pileup_weight * gen_weight) ;
                FillUserTH1D("Mej_selected_min_PAS", M_ej_min, pileup_weight * gen_weight) ;
                FillUserTH1D("Mej_selected_max_PAS", M_ej_max, pileup_weight * gen_weight) ;
                FillUserTH1D("Me1j_selected_PAS"   , M_e1j2, pileup_weight * gen_weight) ;
                FillUserTH1D("Me2j_selected_PAS"   , M_e2j1, pileup_weight * gen_weight) ;
                FillUserTH1D("Mej_minmax_PAS"      , M_ej_min, pileup_weight * gen_weight) ;
                FillUserTH1D("Mej_minmax_PAS"      , M_ej_max, pileup_weight * gen_weight) ;
                FillUserTH2D( "Me1jVsMe2j_selected", M_e1j2, M_e2j1, pileup_weight * gen_weight ) ;
                FillUserTH2D( "Me1jVsMe2j_rejected", M_e1j1, M_e2j2, pileup_weight * gen_weight ) ;
            }

            for (int i_lq_mass = 0; i_lq_mass < n_lq_mass; ++i_lq_mass ) {
                int  lq_mass = LQ_MASS      [i_lq_mass];
                bool pass    = passed_vector[i_lq_mass];
                if ( !pass ) continue;

                if ( lq_mass == 1200 && isData == 1) {
                    std::cout << std::fixed << "RUN = " << run << ", EVENT = " << event << ", LS = " << ls << std::endl;
                }

                sprintf(plot_name, "Mej_selected_avg_LQ%d"       , lq_mass );
                FillUserTH1D ( plot_name, M_ej_avg          , pileup_weight * gen_weight );
                sprintf(plot_name, "Mej_selected_min_LQ%d"       , lq_mass );
                FillUserTH1D ( plot_name, M_ej_min          , pileup_weight * gen_weight );
                sprintf(plot_name, "Mej_selected_max_LQ%d"       , lq_mass );
                FillUserTH1D ( plot_name, M_ej_max          , pileup_weight * gen_weight );
                sprintf(plot_name, "Mej_minmax_LQ%d"             , lq_mass );
                FillUserTH1D ( plot_name, M_ej_min          , pileup_weight * gen_weight );
                sprintf(plot_name, "Mej_minmax_LQ%d"             , lq_mass );
                FillUserTH1D ( plot_name, M_ej_max          , pileup_weight * gen_weight );
                sprintf(plot_name, "sT_eejj_LQ%d"                , lq_mass );
                FillUserTH1D ( plot_name, sT_eejj           , pileup_weight * gen_weight );
                sprintf(plot_name, "Mee_LQ%d"                    , lq_mass );
                FillUserTH1D ( plot_name, M_e1e2            , pileup_weight * gen_weight );
                sprintf(plot_name, "Mej_selected_min_vs_max_LQ%d", lq_mass );
                FillUserTH2D ( plot_name, M_ej_min, M_ej_max, pileup_weight * gen_weight );

            }
        }
    } // End loop over events

    output_root_ -> cd();
    profile_run_vs_nvtx_HLT -> Write();
    profile_run_vs_nvtx_PAS -> Write();

    std::cout << "analysisClass::Loop() ends" <<std::endl;
}
void analysisClass::Loop()
{
   std::cout << "analysisClass::Loop() begins" <<std::endl;   
    
   if (fChain == 0) return;
   
   //////////book histos here

  //////////book histos here

   TH1F *h_nJetFinal = new TH1F ("h_nJetFinal","",10,0,10);
   h_nJetFinal->Sumw2();      
   TH1F *h_nVtx = new TH1F ("h_nVtx","",30,0,30);
   h_nVtx->Sumw2();   
   TH1F *h_pT1stJet = new TH1F ("h_pT1stJet","",100,0,3000);
   h_pT1stJet->Sumw2();
   TH1F *h_pT2ndJet = new TH1F ("h_pT2ndJet","",100,0,3000);
   h_pT2ndJet->Sumw2();
   TH1F *h_eta1stJet = new TH1F ("h_eta1stJet","",5,-2.5,2.5);
   h_eta1stJet->Sumw2();
   TH1F *h_eta2ndJet = new TH1F ("h_eta2ndJet","",5,-2.5,2.5);
   h_eta2ndJet->Sumw2();
   TH1F *h_DijetMass = new TH1F ("h_DijetMass","",600,0,6000);
   h_DijetMass->Sumw2();
   TH1F *h_DeltaETAjj = new TH1F ("h_DeltaETAjj","",120,0,3.);
   h_DeltaETAjj->Sumw2();


   /////////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
 
     Int_t no_jets_ak4=jetPtAK4->size();
     Int_t no_jets_ak8=jetPtAK8->size();
     vector<TLorentzVector> widejets;
     TLorentzVector currentJet, wj1_tmp, wj1, wj2_tmp, wj2, v_jet_ak4,wdijet,wj1math,wj2math;
     ////cone size wide 1.1
     double wideJetDeltaR_ = 1.1;

     resetCuts();
  
     //Eirini wide jet
     // if(no_jets_ak4>=2){
     //   if( fabs(jetEtaAK4->at(0)) < getPreCutValue1("jetFidRegion") && idTAK4->at(0) == getPreCutValue1("tightJetID")){
     // 	 if( fabs(jetEtaAK4->at(1)) < getPreCutValue1("jetFidRegion") && idTAK4->at(1) == getPreCutValue1("tightJetID")){
     // 	   TLorentzVector jet1, jet2;
     // 	   jet1.SetPtEtaPhiM(jetPtAK4->at(0),jetEtaAK4->at(0),jetPhiAK4->at(0),jetMassAK4->at(0));
     // 	   jet2.SetPtEtaPhiM(jetPtAK4->at(1),jetEtaAK4->at(1),jetPhiAK4->at(1),jetMassAK4->at(1));
	   
     // 	   for(Long64_t ijet=0; ijet<no_jets_ak4; ijet++){ //jet loop for ak4
     // 	     TLorentzVector currentJet;
	     
     // 	     if( fabs(jetEtaAK4->at(ijet)) < getPreCutValue1("jetFidRegion") && idTAK4->at(ijet) == getPreCutValue1("tightJetID")){
     // 	       TLorentzVector currentJet;
     // 	       currentJet.SetPtEtaPhiM(jetPtAK4->at(ijet),jetEtaAK4->at(ijet),jetPhiAK4->at(ijet),jetMassAK4->at(ijet));          
     // 	       double DeltaR1 = currentJet.DeltaR(jet1);
     // 	       double DeltaR2 = currentJet.DeltaR(jet2);

     // 	       if(DeltaR1 < DeltaR2 && DeltaR1 < wideJetDeltaR_){
     // 		 wj1_tmp += currentJet;
     // 	       }
     // 	       else if(DeltaR2 < wideJetDeltaR_){
     // 		 wj2_tmp += currentJet;
     // 	       }
	       
	       
     // 	     } // if AK4 jet passes fid and jetid.
     // 	   } //end of ak4 jet loop

     // 	   if(wj1_tmp.Pt()==0 && wj2_tmp.Pt() ==0) 
     // 	     std::cout << " wj1_tmp.Pt() IN  " <<wj1_tmp.Pt()  << " wj2_tmp.Pt() " <<  wj2_tmp.Pt()  << std::endl;
	   
     // 	 } //fid and jet id
     //   } //fid and jet id
     // } // end of two jets.

     // -------- Start Giulia Wide jet  --------------------- 
/////////////giulia
//use only jets pt>30, fiducial region and looseId
     
     if(no_jets_ak4>=2){
       if(!(jetPtAK4->at(0)>getPreCutValue1("jetPtCut") && fabs(jetEtaAK4->at(0)) < getPreCutValue1("jetFidRegion") && idLAK4->at(0) == getPreCutValue1("looseJetID"))){
     	 std::cout << " JET 0 FAIL " <<  jetEtaAK4->at(0) << " JET 0  ID " << idLAK4->at(0) << std::endl;

       }
       if(!(jetPtAK4->at(1)>getPreCutValue1("jetPtCut") && fabs(jetEtaAK4->at(1)) < getPreCutValue1("jetFidRegion") && idLAK4->at(1) == getPreCutValue1("looseJetID"))){
     	 std::cout << " JET 1 FAIL " << jetEtaAK4->at(1) << " JET 1  ID " << idTAK4->at(1) << std::endl;

       }  
     }
     //////////////////////////

     
     //code to create wide jets : use ak4 passing loose ID
     if(no_jets_ak4>=2){

       if( fabs(jetEtaAK4->at(0)) < getPreCutValue1("jetFidRegion") && idLAK4->at(0) == getPreCutValue1("looseJetID") && jetPtAK4->at(0)>getPreCutValue1("jetPtCut")){
     	 if( fabs(jetEtaAK4->at(1)) < getPreCutValue1("jetFidRegion") && idLAK4->at(1) == getPreCutValue1("looseJetID") && jetPtAK4->at(1)>getPreCutValue1("jetPtCut")){
     	   TLorentzVector jet1, jet2;
     	   jet1.SetPtEtaPhiM(jetPtAK4->at(0),jetEtaAK4->at(0),jetPhiAK4->at(0),jetMassAK4->at(0));
     	   jet2.SetPtEtaPhiM(jetPtAK4->at(1),jetEtaAK4->at(1),jetPhiAK4->at(1),jetMassAK4->at(1));
        
     	   for(Long64_t ijet=0; ijet<no_jets_ak4; ijet++){ //jet loop for ak4
     	     TLorentzVector currentJet;
          
     	     if( fabs(jetEtaAK4->at(ijet)) < getPreCutValue1("jetFidRegion") && idLAK4->at(ijet) == 1){
     	       TLorentzVector currentJet;
     	       currentJet.SetPtEtaPhiM(jetPtAK4->at(ijet),jetEtaAK4->at(ijet),jetPhiAK4->at(ijet),jetMassAK4->at(ijet));          
     	       double DeltaR1 = currentJet.DeltaR(jet1);
     	       double DeltaR2 = currentJet.DeltaR(jet2);
            
     	       if(DeltaR1 < DeltaR2 && DeltaR1 < wideJetDeltaR_){
     		 wj1_tmp += currentJet;
     	       }
     	       else if(DeltaR2 < wideJetDeltaR_){
     		 wj2_tmp += currentJet;
     	       }
            
            
     	     } // if AK4 jet passes fid and jetid.
     	   } //end of ak4 jet loop
        
     	   if(wj1_tmp.Pt()==0 && wj2_tmp.Pt() ==0) 
     	     std::cout << " wj1_tmp.Pt() IN  " <<wj1_tmp.Pt()  << " wj2_tmp.Pt() " <<  wj2_tmp.Pt()  << std::endl;
        
     	 } //fid and jet id j2
       } //fid and jet id j1
     } // end of two jets.
     //-------------- end Giulia Wide jet --------------------------     


     //
     if(wj1_tmp.Pt()==0 && wj2_tmp.Pt() ==0)     std::cout << " wj1_tmp.Pt()  " <<wj1_tmp.Pt()  << " wj2_tmp.Pt() " << wj2_tmp.Pt()  << "  no_jets_ak4 " << no_jets_ak4 << std::endl;
     //
     double MJJWide,DeltaEtaJJWide,DeltaPhiJJWide;
     
     if( wj1_tmp.Pt()>0 && wj2_tmp.Pt() >0 ){
       // Re-order the wide jets in pt
       if( wj1_tmp.Pt() > wj2_tmp.Pt()){
	 wj1 = wj1_tmp;
	 wj2 = wj2_tmp;
       }
       else{
	 wj1 = wj2_tmp;
	 wj2 = wj1_tmp;
       }
       
       // Create dijet system
       wdijet = wj1 + wj2;
       MJJWide = wdijet.M();
       DeltaEtaJJWide = fabs(wj1.Eta()-wj2.Eta());
       DeltaPhiJJWide = fabs(wj1.DeltaPhi(wj2));
       
       // Put widejets in the container
       wj1math.SetPtEtaPhiM(wj1.Pt(), wj1.Eta(), wj1.Phi(), wj1.M());
       wj2math.SetPtEtaPhiM(wj2.Pt(), wj2.Eta(), wj2.Phi(), wj2.M());  
       widejets.push_back( wj1math );
       widejets.push_back( wj2math );
     }
     


     fillVariableWithValue("nJetFinal",widejets.size()) ;
     fillVariableWithValue("nVtx",nvtx) ;
     fillVariableWithValue("ptHat", ptHat);    
     fillVariableWithValue("neutralHadronEnergyFraction_j1", jetNhfAK4->at(0));    
     fillVariableWithValue("photonEnergyFraction_j1", jetPhfAK4->at(0));    
     fillVariableWithValue("electronEnergyFraction_j1", jetElfAK4->at(0));         
     fillVariableWithValue("muonEnergyFraction_j1", jetMufAK4->at(0));    
     fillVariableWithValue("chargedHadronMultiplicity_j1", jetChfAK4->at(0));    
     fillVariableWithValue("neutralHadronEnergyFraction_j2", jetNhfAK4->at(1));    
     fillVariableWithValue("photonEnergyFraction_j2", jetPhfAK4->at(1));    
     fillVariableWithValue("electronEnergyFraction_j2", jetElfAK4->at(1));         
     fillVariableWithValue("muonEnergyFraction_j2", jetMufAK4->at(1));    
     fillVariableWithValue("chargedHadronMultiplicity_j2", jetChfAK4->at(1));    
     fillVariableWithValue("jetIdT1",idTAK4->at(0)) ;
     fillVariableWithValue("jetIdT2",idTAK4->at(1)) ;

     if( widejets.size() >= 1 )
       
       {
	 fillVariableWithValue( "pT1stJet", widejets[0].Pt() );
	 fillVariableWithValue( "eta1stJet", widejets[0].Eta());

	 
       }
     
     if( widejets.size() >= 2 )
       {
         fillVariableWithValue( "pT2ndJet", widejets[1].Pt() );
         fillVariableWithValue( "eta2ndJet", widejets[1].Eta());

	 
         // Calculate deltaETAjj
	 //giulia 
	 fillVariableWithValue( "deltaETAjj", DeltaEtaJJWide ) ;
	 
         // Calculate Mjj
         fillVariableWithValue( "Dijet_MassW", wdijet.M() ) ;
         fillVariableWithValue( "Dijet_MassAK8", mjjAK8 ) ;  
	 fillVariableWithValue( "Dijet_MassAK4", mjjAK4 ) ;  
	 //giulia - test
	 //fillVariableWithValue( "Dijet_MassC", mjjCA8 ) ;
	 if(wdijet.M()<1){
	   std::cout << " INV MASS IS " << wdijet.M() << std::endl;
	   std::cout << " Delta Eta IS " << DeltaEtaJJWide << " n is  " << widejets.size() << std::endl;
	   std::cout << " INV MASS FROM NTUPLE AK8 " << mjjAK8 << std::endl;
	   //std::cout << " INV MASS FROM NTUPLE CA8 " << mjjCA8 << std::endl;
	 }
       }
     
     // Evaluate cuts (but do not apply them)
     evaluateCuts();
     
     // optional call to fill a skim with the full content of the input roottuple
     if( passedCut("nJetFinal") ) fillSkimTree();
     
     // optional call to fill a skim with a subset of the variables defined in the cutFile (use flag SAVE)
     if( passedCut("nJetFinal") ) fillReducedSkimTree();

     // 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;
     // ......

     if( widejets.size() >= 2) {
      h_nJetFinal->Fill(widejets.size());
      h_DijetMass->Fill(wdijet.M());
      h_pT1stJet->Fill(widejets[0].Pt());
      h_pT2ndJet->Fill(widejets[1].Pt());
      h_eta1stJet->Fill(widejets[0].Eta());
      h_eta2ndJet->Fill(widejets[0].Eta());
     }
     ////////////////////// User's code ends here ///////////////////////
     
   } // End loop over events
   
   //////////write histos 
   
   h_nVtx->Write();
   h_nJetFinal->Write();
   h_pT1stJet->Write();
   h_pT2ndJet->Write();
   h_DijetMass->Write();
   h_DeltaETAjj->Write();
   h_eta1stJet->Write();
   h_eta2ndJet->Write();

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

   std::cout << "analysisClass::Loop() ends" <<std::endl;   
}
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;   
}
void analysisClass::Loop()
{
   std::cout << "analysisClass::Loop() begins" <<std::endl;   
   
   //--------------------------------------------------------------------------
   // Final selection mass points
   //--------------------------------------------------------------------------

   const int n_lq_mass = 19;

   int LQ_MASS[n_lq_mass] = { 
     300,  350,  400, 450, 500, 550,  600,  650,
     700,  750,  800, 850, 900, 950, 1000, 1050,
     1100, 1150, 1200
   };

   std::vector<bool> passed_vector;
   
   //--------------------------------------------------------------------------
   // Decide which plots to save (default is to save everything)
   //--------------------------------------------------------------------------
   
   fillSkim                         ( !true  ) ;
   fillAllPreviousCuts              ( !true  ) ;
   fillAllOtherCuts                 ( !true  ) ;
   fillAllSameLevelAndLowerLevelCuts( !true  ) ;
   fillAllCuts                      ( !true  ) ;
   
   //--------------------------------------------------------------------------
   // Get pre-cut values
   //--------------------------------------------------------------------------

   // eta boundaries

   double eleEta_bar            = getPreCutValue1("eleEta_bar");
   double eleEta_end1_min       = getPreCutValue1("eleEta_end1");
   double eleEta_end1_max       = getPreCutValue2("eleEta_end1");
   double eleEta_end2_min       = getPreCutValue1("eleEta_end2");
   double eleEta_end2_max       = getPreCutValue2("eleEta_end2");

   // fake rates
   
   double fakeRate_low_bar_p0    = getPreCutValue1 ( "fakeRate_bar"  );
   double fakeRate_low_bar_p1    = getPreCutValue2 ( "fakeRate_bar"  );
   double fakeRate_high_bar_p0   = getPreCutValue3 ( "fakeRate_bar"  );
				 
   double fakeRate_low_end1_p0   = getPreCutValue1 ( "fakeRate_end1" );
   double fakeRate_low_end1_p1   = getPreCutValue2 ( "fakeRate_end1" );
   double fakeRate_high_end1_p0  = getPreCutValue3 ( "fakeRate_end1" );
				 
   double fakeRate_low_end2_p0   = getPreCutValue1 ( "fakeRate_end2" );
   double fakeRate_low_end2_p1   = getPreCutValue2 ( "fakeRate_end2" );
   double fakeRate_high_end2_p0  = getPreCutValue3 ( "fakeRate_end2" );
   
   double eFakeRate_low_bar_p0   = getPreCutValue1 ( "eFakeRate_bar" );
   double eFakeRate_low_bar_p1   = getPreCutValue2 ( "eFakeRate_bar" );
   double eFakeRate_high_bar_p0  = getPreCutValue3 ( "eFakeRate_bar" );

   double eFakeRate_low_end1_p0  = getPreCutValue1 ( "eFakeRate_end1");
   double eFakeRate_low_end1_p1  = getPreCutValue2 ( "eFakeRate_end1");
   double eFakeRate_high_end1_p0 = getPreCutValue3 ( "eFakeRate_end1");

   double eFakeRate_low_end2_p0  = getPreCutValue1 ( "eFakeRate_end2");
   double eFakeRate_low_end2_p1  = getPreCutValue2 ( "eFakeRate_end2");
   double eFakeRate_high_end2_p0 = getPreCutValue3 ( "eFakeRate_end2");

   //--------------------------------------------------------------------------
   // Create TH1D's
   //--------------------------------------------------------------------------

   CreateUserTH1D( "sTfrac_Jet1_PAS"       ,   100  ,  0.0    , 1.0      );
   CreateUserTH1D( "sTfrac_Ele1_PAS"       ,   100  ,  0.0    , 1.0      );
   CreateUserTH1D( "sTfrac_Ele2_PAS"       ,   100  ,  0.0    , 1.0      );
   CreateUserTH1D( "sTfrac_Jet_PAS"        ,   100  ,  0.0    , 1.0      );
   CreateUserTH1D( "sTfrac_Ele_PAS"        ,   100  ,  0.0    , 1.0      );
   CreateUserTH1D( "sTfrac_Jet1_PASandMee100"       ,   100  ,  0.0    , 1.0      );
   CreateUserTH1D( "sTfrac_Ele1_PASandMee100"       ,   100  ,  0.0    , 1.0      );
   CreateUserTH1D( "sTfrac_Ele2_PASandMee100"       ,   100  ,  0.0    , 1.0      );
   CreateUserTH1D( "sTfrac_Jet_PASandMee100"        ,   100  ,  0.0    , 1.0      );
   CreateUserTH1D( "sTfrac_Ele_PASandMee100"        ,   100  ,  0.0    , 1.0      );
   CreateUserTH1D( "sTfrac_Jet1_ROI"       ,   100  ,  0.0    , 1.0      );
   CreateUserTH1D( "sTfrac_Ele1_ROI"       ,   100  ,  0.0    , 1.0      );
   CreateUserTH1D( "sTfrac_Ele2_ROI"       ,   100  ,  0.0    , 1.0      );
   CreateUserTH1D( "sTfrac_Jet_ROI"        ,   100  ,  0.0    , 1.0      );
   CreateUserTH1D( "sTfrac_Ele_ROI"        ,   100  ,  0.0    , 1.0      );
   CreateUserTH1D( "nElectron_PAS"         ,    5   , -0.5    , 4.5      );
   CreateUserTH1D( "nMuon_PAS"             ,    5   , -0.5    , 4.5      );
   CreateUserTH1D( "nJet_PAS"              ,    10  , -0.5    , 9.5      );
   CreateUserTH1D( "nJet_PASandMee100"        ,    10  , -0.5    , 9.5      );
   CreateUserTH1D( "nJet_ROI"              ,    10  , -0.5    , 9.5      );
   CreateUserTH1D( "Pt1stEle_PAS"	   , 	100 , 0       , 1000     ); 
   CreateUserTH1D( "Pt1stEle_PASandMee100" , 	100 , 0       , 1000     ); 
   CreateUserTH1D( "Pt1stEle_ROI"	   , 	100 , 0       , 1000     ); 
   CreateUserTH1D( "Eta1stEle_PAS"	   , 	100 , -5      , 5	 ); 
   CreateUserTH1D( "Phi1stEle_PAS"	   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "Pt2ndEle_PAS"	   , 	100 , 0       , 1000     ); 
   CreateUserTH1D( "Pt2ndEle_PASandMee100" , 	100 , 0       , 1000     ); 
   CreateUserTH1D( "Pt2ndEle_ROI"	   , 	100 , 0       , 1000     ); 
   CreateUserTH1D( "Eta2ndEle_PAS"	   , 	100 , -5      , 5	 ); 
   CreateUserTH1D( "Phi2ndEle_PAS"	   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "Charge1stEle_PAS"	   , 	2   , -1.0001 , 1.0001	 ); 
   CreateUserTH1D( "Charge2ndEle_PAS"	   , 	2   , -1.0001 , 1.0001	 ); 
   CreateUserTH1D( "EleChargeSum_PAS"         ,    3   , -2.5    , 2.5  );
   CreateUserTH1D( "EleChargeSum_PASandMee100",    3   , -2.5    , 2.5  );
   CreateUserTH1D( "EleChargeSum_ROI"         ,    3   , -2.5    , 2.5  );
   CreateUserTH1D( "MET_PAS"               ,    200 , 0       , 1000	 ); 
   CreateUserTH1D( "MET_ROI"               ,    200 , 0       , 1000	 ); 
   CreateUserTH1D( "METPhi_PAS"		   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "Pt1stJet_PAS"          ,    100 , 0       , 1000	 ); 
   CreateUserTH1D( "Pt1stJet_PASandMee100" ,    100 , 0       , 1000	 ); 
   CreateUserTH1D( "Pt1stJet_ROI"          ,    100 , 0       , 1000	 ); 
   CreateUserTH1D( "Eta1stJet_PAS"         ,    100 , -5      , 5	 ); 
   CreateUserTH1D( "Phi1stJet_PAS"	   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "sTlep_PAS"             ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "sTlep_PASandMee100"    ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "sTlep_ROI"             ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "sT_PAS"                ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "sT_PASandMee100"       ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "sT_PASandMee110"       ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "sT_PASandMee120"       ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "sT_PASandMee130"       ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "sT_PASandMee140"       ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "sT_PASandMee150"       ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "sT_PASandMee160"       ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "sT_PASandMee170"       ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "sT_PASandMee180"       ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "sT_PASandMee190"       ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "sT_PASandMee200"       ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "sT_ROI"                ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Mee_PAS"		   ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Mee_ROI"		   ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Mee_PASandST445"       ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "MTenu_PAS"             ,    200 , 0       , 1000	 ); 
   CreateUserTH1D( "Me1j1_PAS"             ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Me1j1_PASandMee100"    ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Me1j1_ROI"             ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Me2j1_PAS"             ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Me1j_selected_PAS"     ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Meej_PAS"              ,    400 , 0       , 4000     );
   CreateUserTH1D( "Meej_ROI"              ,    400 , 0       , 4000     );

   CreateUserTH1D( "Eta1stJet_ROI"                   ,    100   , -5      , 5	  ); 
   CreateUserTH1D( "Eta1stEle_ROI"	             , 	100    , -5      , 5	  ); 
   CreateUserTH1D( "Eta2ndEle_ROI"	             , 	100    , -5      , 5	  ); 

   CreateUserTH1D( "Phi1stJet_ROI"	             , 	 60    , -3.1416 , +3.1416  ); 
   CreateUserTH1D( "Phi1stEle_ROI"	             , 	 60    , -3.1416 , +3.1416  ); 
   CreateUserTH1D( "Phi2ndEle_ROI"	             , 	 60    , -3.1416 , +3.1416  ); 
		            			     
   CreateUserTH1D( "Ptee_PAS"              ,    200 , 0       , 2000     );
   CreateUserTH1D( "Ptee_PASandMee100"     ,    200 , 0       , 2000     );
   CreateUserTH1D( "Ptee_ROI"              ,    200 , 0       , 2000     );
   		                           
   CreateUserTH1D( "DCotTheta1stEle_PAS"   ,    100 , 0.0, 1.0);
   CreateUserTH1D( "Dist1stEle_PAS"        ,    100 , 0.0, 1.0);  
   CreateUserTH1D( "DCotTheta2ndEle_PAS"   ,    100 , 0.0, 1.0);
   CreateUserTH1D( "Dist2ndEle_PAS"        ,    100 , 0.0, 1.0);  
		                           
   CreateUserTH1D( "nVertex_PAS"                     ,    101   , -0.5   , 100.5	 ) ; 
   CreateUserTH1D( "nVertex_PASandMee100"            ,    101   , -0.5   , 100.5	 ) ; 
   CreateUserTH1D( "nVertex_ROI"                     ,    101   , -0.5   , 100.5	 ) ; 
   
   CreateUserTH1D( "DR_Ele1Jet1_PAS"	   , 	getHistoNBins("DR_Ele1Jet1"), getHistoMin("DR_Ele1Jet1"), getHistoMax("DR_Ele1Jet1")     ) ; 
   CreateUserTH1D( "DR_Ele2Jet1_PAS"	   , 	getHistoNBins("DR_Ele2Jet1"), getHistoMin("DR_Ele2Jet1"), getHistoMax("DR_Ele2Jet1")     ) ; 
   CreateUserTH1D( "DR_Ele1Ele2_PAS"	   , 	getHistoNBins("DR_Ele1Jet1"), getHistoMin("DR_Ele1Jet1"), getHistoMax("DR_Ele1Jet1")     ) ; 

   CreateUserTH1D( "DR_ZJet1_PAS"        ,    getHistoNBins("DR_Ele1Jet1"), getHistoMin("DR_Ele1Jet1"), getHistoMax("DR_Ele1Jet1")     ) ; 
   CreateUserTH1D( "DR_ZJet1_ROI"        ,    getHistoNBins("DR_Ele1Jet1"), getHistoMin("DR_Ele1Jet1"), getHistoMax("DR_Ele1Jet1")     ) ; 

   CreateUserTH2D( "MeeVsST_PAS"                 ,     200, 0, 2000, 200, 0, 2000) ;
   CreateUserTH2D( "MeeVsST_PASandMee100"        ,     200, 0, 2000, 200, 0, 2000) ;
   CreateUserTH2D( "MeeVsST_ROI"                 ,     200, 0, 2000, 200, 0, 2000) ;


   CreateUserTH1D( "Mee_80_100_Preselection", 200, 60, 120 );
   CreateUserTH1D( "Mee_70_110_Preselection", 200, 60, 120 );
   CreateUserTH1D( "Mee_70_110_ST600_Preselection", 200, 60, 120 );
   
   CreateUserTH1D( "Mee_EBEB_PAS"		   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EBEE_PAS"		   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EEEE_PAS"		   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EB_PAS" 		   ,    60 , 60       , 120	 ); 

   CreateUserTH1D( "Mee_EBEB_80_100_PAS"	   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EBEE_80_100_PAS"	   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EEEE_80_100_PAS"	   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EB_80_100_PAS" 	     	   ,    60 , 60       , 120	 ); 
   
   CreateUserTH1D( "Mee_EBEB_70_110_PAS"	   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EBEE_70_110_PAS"	   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EEEE_70_110_PAS"	   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EB_70_110_PAS" 	     	   ,    60 , 60       , 120	 ); 

   CreateUserTH1D( "PileupWeight"   , 100, -10, 10 );
   CreateUserTH1D( "GeneratorWeight", 100, -2.0 , 2.0 );
   
   //--------------------------------------------------------------------------
   // Loop over the chain
   //--------------------------------------------------------------------------

   if (fChain == 0) return;
   
   Long64_t nentries = fChain->GetEntries();
   std::cout << "analysisClass::Loop(): nentries = " << nentries << std::endl;   

   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 << "/" << nentries << std::endl;   

     //--------------------------------------------------------------------------
     // Reset the cuts
     //--------------------------------------------------------------------------

     resetCuts();

     //--------------------------------------------------------------------------
     // Check good run list
     //--------------------------------------------------------------------------
     
     int passedJSON = passJSON ( run, ls , isData ) ;
     
     //--------------------------------------------------------------------------
     // Find the right prescale for this event
     //--------------------------------------------------------------------------
     
     int min_prescale = 0;
     int passTrigger  = 0;

     if ( LooseEle1_hltPhotonPt > 0.0 ) { 
       if ( H_Photon30_CIdVL > 0.1 && LooseEle1_hltPhotonPt >= 30.  && LooseEle1_hltPhotonPt < 50. ) { passTrigger = 1; min_prescale = H_Photon30_CIdVL; } 
       if ( H_Photon50_CIdVL > 0.1 && LooseEle1_hltPhotonPt >= 50.  && LooseEle1_hltPhotonPt < 75. ) { passTrigger = 1; min_prescale = H_Photon50_CIdVL; } 
       if ( H_Photon75_CIdVL > 0.1 && LooseEle1_hltPhotonPt >= 75.  && LooseEle1_hltPhotonPt < 90. ) { passTrigger = 1; min_prescale = H_Photon75_CIdVL; } 
       if ( H_Photon90_CIdVL > 0.1 && LooseEle1_hltPhotonPt >= 90.  && LooseEle1_hltPhotonPt < 135.) { passTrigger = 1; min_prescale = H_Photon90_CIdVL; } 
       if ( H_Photon135      > 0.1 && LooseEle1_hltPhotonPt >= 135. && LooseEle1_hltPhotonPt < 150.) { passTrigger = 1; min_prescale = H_Photon135     ; } 
       if ( H_Photon150      > 0.1 && LooseEle1_hltPhotonPt >= 150.                                ) { passTrigger = 1; min_prescale = H_Photon150     ; } 
     }
          
     //--------------------------------------------------------------------------
     // What kind of event is this?
     //   - Barrel
     //   - Endcap 1 (eta < 2.0)
     //   - Endcap 2 (eta > 2.0) 
     //--------------------------------------------------------------------------
     
     bool ele1_isBarrel  = false;
     bool ele1_isEndcap1 = false;
     bool ele1_isEndcap2 = false;
     bool ele2_isBarrel  = false;
     bool ele2_isEndcap1 = false;
     bool ele2_isEndcap2 = false;
     
     if( fabs( LooseEle1_Eta  ) < eleEta_bar )        ele1_isBarrel  = true;
     if( fabs( LooseEle1_Eta  ) > eleEta_end1_min &&
	 fabs( LooseEle1_Eta  ) < eleEta_end1_max )   ele1_isEndcap1 = true;
     if( fabs( LooseEle1_Eta  ) > eleEta_end2_min &&
	 fabs( LooseEle1_Eta  ) < eleEta_end2_max )   ele1_isEndcap2 = true;

     if( fabs( LooseEle2_Eta  ) < eleEta_bar )        ele2_isBarrel  = true;
     if( fabs( LooseEle2_Eta  ) > eleEta_end1_min &&
	 fabs( LooseEle2_Eta  ) < eleEta_end1_max )   ele2_isEndcap1 = true;
     if( fabs( LooseEle2_Eta  ) > eleEta_end2_min &&
	 fabs( LooseEle2_Eta  ) < eleEta_end2_max )   ele2_isEndcap2 = true;

     bool ele1_isEndcap = ( ele1_isEndcap1 || ele1_isEndcap2 ) ;
     bool ele2_isEndcap = ( ele2_isEndcap1 || ele2_isEndcap2 ) ;

     bool isEBEB = ( ele1_isBarrel && ele2_isBarrel ) ;
     bool isEBEE = ( ( ele1_isBarrel && ele2_isEndcap ) ||
		     ( ele2_isBarrel && ele1_isEndcap ) );
     bool isEEEE = ( ele1_isEndcap && ele2_isEndcap ) ;
     bool isEB   = ( isEBEB || isEBEE ) ;

     //--------------------------------------------------------------------------
     // Determine which fake rates to use
     //--------------------------------------------------------------------------

     double fakeRate1  = 0.0;
     double fakeRate2  = 0.0;
     double eFakeRate1 = 0.0 ;
     double eFakeRate2 = 0.0;
     
     if ( LooseEle1_Pt < 100 ){
       if ( ele1_isBarrel  ) {
	 fakeRate1  = fakeRate_low_bar_p0  + fakeRate_low_bar_p1  * LooseEle1_Pt;
	 eFakeRate1 = sqrt ((( eFakeRate_low_bar_p1  * LooseEle1_Pt       ) * 
			     ( eFakeRate_low_bar_p1  * LooseEle1_Pt       )) + 
			    (( eFakeRate_low_bar_p0  * eFakeRate_low_bar_p0 ) * 
			     ( eFakeRate_low_bar_p0  * eFakeRate_low_bar_p0 )));
       }
       if ( ele1_isEndcap1 ) {
	 fakeRate1  = fakeRate_low_end1_p0 + fakeRate_low_end1_p1 * LooseEle1_Pt;
	 eFakeRate1 = sqrt ((( eFakeRate_low_end1_p1  * LooseEle1_Pt       ) * 
			     ( eFakeRate_low_end1_p1  * LooseEle1_Pt       )) + 
			    (( eFakeRate_low_end1_p0  * eFakeRate_low_end1_p0 ) * 
			     ( eFakeRate_low_end1_p0  * eFakeRate_low_end1_p0 )));

       }
       if ( ele1_isEndcap2 ) {
	 fakeRate1 = fakeRate_low_end2_p0 + fakeRate_low_end2_p1 * LooseEle1_Pt;
	 eFakeRate1 = sqrt ((( eFakeRate_low_end2_p1  * LooseEle1_Pt       ) * 
			     ( eFakeRate_low_end2_p1  * LooseEle1_Pt       )) + 
			    (( eFakeRate_low_end2_p0  * eFakeRate_low_end2_p0 ) * 
			     ( eFakeRate_low_end2_p0  * eFakeRate_low_end2_p0 )));
       } 
     }
     else if  ( LooseEle1_Pt >= 100 ){
       if ( ele1_isBarrel  ) {
	 fakeRate1  = fakeRate_high_bar_p0  ;
	 eFakeRate1 = eFakeRate_high_bar_p0 ;
       }
       if ( ele1_isEndcap1 ) { 
	 fakeRate1 = fakeRate_high_end1_p0 ;
	 eFakeRate1 = eFakeRate_high_end1_p0 ;
       }
       if ( ele1_isEndcap2 ) {
	 fakeRate1 = fakeRate_high_end2_p0 ;
	 eFakeRate1 = eFakeRate_high_end2_p0 ;
       }
     }

     if ( LooseEle2_Pt < 100 ){
       if ( ele1_isBarrel  ) {
	 fakeRate2  = fakeRate_low_bar_p0  + fakeRate_low_bar_p1  * LooseEle2_Pt;
	 eFakeRate2 = sqrt ((( eFakeRate_low_bar_p1  * LooseEle2_Pt       ) * 
			     ( eFakeRate_low_bar_p1  * LooseEle2_Pt       )) + 
			    (( eFakeRate_low_bar_p0  * eFakeRate_low_bar_p0 ) * 
			     ( eFakeRate_low_bar_p0  * eFakeRate_low_bar_p0 )));
       }
       if ( ele1_isEndcap1 ) {
	 fakeRate2 = fakeRate_low_end1_p0 + fakeRate_low_end1_p1 * LooseEle2_Pt;
	 eFakeRate2 = sqrt ((( eFakeRate_low_end1_p1  * LooseEle2_Pt       ) * 
			     ( eFakeRate_low_end1_p1  * LooseEle2_Pt       )) + 
			    (( eFakeRate_low_end1_p0  * eFakeRate_low_end1_p0 ) * 
			     ( eFakeRate_low_end1_p0  * eFakeRate_low_end1_p0 )));
       }
       if ( ele1_isEndcap2 ) {
	 fakeRate2 = fakeRate_low_end2_p0 + fakeRate_low_end2_p1 * LooseEle2_Pt;
	 eFakeRate2 = sqrt ((( eFakeRate_low_end2_p1  * LooseEle2_Pt       ) * 
			     ( eFakeRate_low_end2_p1  * LooseEle2_Pt       )) + 
			    (( eFakeRate_low_end2_p0  * eFakeRate_low_end2_p0 ) * 
			     ( eFakeRate_low_end2_p0  * eFakeRate_low_end2_p0 )));
       }
     }

     else if  ( LooseEle2_Pt >= 100 ){
       if ( ele1_isBarrel  ) {
	 fakeRate2  = fakeRate_high_bar_p0  ;
	 eFakeRate2 = eFakeRate_high_bar_p0;
       }
       if ( ele1_isEndcap1 ) { 
	 fakeRate2 = fakeRate_high_end1_p0 ;
	 eFakeRate2 = eFakeRate_high_end1_p0;
       }
       if ( ele1_isEndcap2 ) {
	 fakeRate2 = fakeRate_high_end2_p0 ;
	 eFakeRate2 = eFakeRate_high_end2_p0;
       }
     }

     //--------------------------------------------------------------------------
     // Finally have the effective fake rate
     //--------------------------------------------------------------------------

     double fakeRateEffective  = fakeRate1 * fakeRate2;
     double eFakeRateEffective = fakeRateEffective * sqrt (  ( eFakeRate1 / fakeRate1 ) * ( eFakeRate1 / fakeRate1 ) +
							     ( eFakeRate2 / fakeRate2 ) * ( eFakeRate2 / fakeRate2 ) );
     //--------------------------------------------------------------------------
     // Fill variables
     //--------------------------------------------------------------------------

     // reweighting
     fillVariableWithValue ( "Reweighting", 1, fakeRateEffective * min_prescale ) ; 
     
     // JSON variable
     fillVariableWithValue(   "PassJSON"                      , passedJSON              , fakeRateEffective * min_prescale ) ; 

     // Noise filters
     fillVariableWithValue(   "PassHBHENoiseFilter"	      , PassHBHENoiseFilter                              , fakeRateEffective * min_prescale );
     fillVariableWithValue(   "PassBeamHaloFilterTight"       , PassBeamHaloFilterTight                          , fakeRateEffective * min_prescale );
     fillVariableWithValue(   "PassBadEESupercrystalFilter"   , ( isData == 1 ) ? PassBadEESupercrystalFilter : 1, fakeRateEffective * min_prescale );
     fillVariableWithValue(   "PassBeamScraping"	      , ( isData == 1 ) ? PassBeamScraping	      : 1, fakeRateEffective * min_prescale );
     fillVariableWithValue(   "PassEcalDeadCellBoundEnergy"   , PassEcalDeadCellBoundEnergy                      , fakeRateEffective * min_prescale );
     fillVariableWithValue(   "PassEcalDeadCellTrigPrim"      , PassEcalDeadCellTrigPrim                         , fakeRateEffective * min_prescale );
     fillVariableWithValue(   "PassEcalLaserCorrFilter"       , ( isData == 1 ) ? PassEcalLaserCorrFilter     : 1, fakeRateEffective * min_prescale );
     fillVariableWithValue(   "PassHcalLaserEventFilter"      , ( isData == 1 ) ? PassHcalLaserEventFilter    : 1, fakeRateEffective * min_prescale );
     fillVariableWithValue(   "PassPhysDecl"		      , ( isData == 1 ) ? PassPhysDecl		      : 1, fakeRateEffective * min_prescale );
     fillVariableWithValue(   "PassPrimaryVertex"	      , PassPrimaryVertex                                , fakeRateEffective * min_prescale );
     fillVariableWithValue(   "PassTrackingFailure"	      , ( isData == 1 ) ? PassTrackingFailure	      : 1, fakeRateEffective * min_prescale );
     
     // Electrons
     int PassNEle = 0;
     if ( nLooseEle_ptCut == 2 ) PassNEle = 1;
     
     double M_ej_avg;
     double M_ej_min;
     double M_ej_max;

     // Muons
     int PassNMuon = 0;
     if ( nMuon_ptCut == 0 ) PassNMuon = 1;

     fillVariableWithValue ( "PassHLT"                        , passTrigger             , fakeRateEffective * min_prescale ) ;
     fillVariableWithValue("nEle_hltMatched",-1, fakeRateEffective * min_prescale ) ;
     fillVariableWithValue("nJet_hltMatched",-1, fakeRateEffective * min_prescale ) ;
     			
							        
     // Electrons								        
     fillVariableWithValue(   "PassNEle"                      , PassNEle                , fakeRateEffective * min_prescale ) ;
     if ( nLooseEle_store >= 1 ) { 							        
       fillVariableWithValue( "Ele1_Pt"                       , LooseEle1_Pt            , fakeRateEffective * min_prescale ) ;
     }										        
     if ( nLooseEle_store >= 2 ) { 							        
       fillVariableWithValue( "Ele2_Pt"                       , LooseEle2_Pt            , fakeRateEffective * min_prescale ) ;
       fillVariableWithValue( "M_e1e2"                        , M_e1e2                  , fakeRateEffective * min_prescale ) ;
     }

     // Jets
     fillVariableWithValue(   "nJet"                          , nJetLooseEle_ptCut      , fakeRateEffective * min_prescale ) ;
     if ( nJetLooseEle_store >= 1 ) { 						                
       fillVariableWithValue( "Jet1_Pt"                       , JetLooseEle1_Pt         , fakeRateEffective * min_prescale ) ;
       fillVariableWithValue( "Jet1_Eta"                      , JetLooseEle1_Eta        , fakeRateEffective * min_prescale ) ;
     }
     
     if ( nJetLooseEle_store >= 2 ) { 
       
       if ( nLooseEle_store >= 2 && nJetLooseEle_store >= 2) {
	 if ( fabs(M_e1j1-M_e2j2) < fabs(M_e1j2-M_e2j1) )  {
	   M_ej_avg = (M_e1j1 + M_e2j2) / 2.0;
	   if    ( M_e1j1 < M_e2j2 ) { M_ej_min = M_e1j1; M_ej_max = M_e2j2; }
	   else                      { M_ej_min = M_e2j2; M_ej_max = M_e1j1; }
	 }
	 else { 
	   M_ej_avg = (M_e1j2 + M_e2j1) / 2.0;
	   if    ( M_e1j2 < M_e2j1 ) { M_ej_min = M_e1j2; M_ej_max = M_e2j1; }
	   else                      { M_ej_min = M_e2j1; M_ej_max = M_e1j2; }
	 }
       }      
     }

     double sT_eej = LooseEle1_Pt + LooseEle2_Pt + JetLooseEle1_Pt;

     // Muons
     fillVariableWithValue(   "PassNMuon"                     , PassNMuon               , fakeRateEffective * min_prescale ) ;

     // DeltaR
     if ( nLooseEle_store >= 2 && nJetLooseEle_store >= 1) {
       fillVariableWithValue( "DR_Ele1Jet1"                   , DR_Ele1Jet1             , fakeRateEffective * min_prescale ) ;
       fillVariableWithValue( "DR_Ele2Jet1"                   , DR_Ele2Jet1             , fakeRateEffective * min_prescale ) ;
     }

     // sT
     if ( nLooseEle_store >= 2 && nJetLooseEle_store >= 2) {
       fillVariableWithValue( "sT_eej"                        , sT_eej                  , fakeRateEffective  * min_prescale ) ;
     }      
     
     //--------------------------------------------------------------------------
     // Evaluate the cuts
     //--------------------------------------------------------------------------
     
     evaluateCuts();

     //--------------------------------------------------------------------------
     // Did we at least pass the noise filtes?
     //--------------------------------------------------------------------------
     
     bool passed_minimum = ( passedAllPreviousCuts("PassTrackingFailure") && passedCut ("PassTrackingFailure"));
     
     //--------------------------------------------------------------------------
     // Did we pass preselection?
     //--------------------------------------------------------------------------
     
     bool passed_preselection = ( passedAllPreviousCuts("M_e1e2") && passedCut ("M_e1e2") );
     
     //--------------------------------------------------------------------------
     // Are we in the region of interest?
     //--------------------------------------------------------------------------

     bool passed_region_of_interest = bool ( passed_preselection && M_e1e2 > 170. && sT_eej > 600.0 );
     
     //--------------------------------------------------------------------------
     // Fill plots with no selection applied
     //--------------------------------------------------------------------------

     FillUserTH1D( "PileupWeight"   , -1.0 );
     FillUserTH1D( "GeneratorWeight", -1.0 );

     //--------------------------------------------------------------------------
     // Fill preselection plots
     //--------------------------------------------------------------------------

     if ( passed_preselection ) {
       
       //--------------------------------------------------------------------------
       // Recalculate some variables
       //--------------------------------------------------------------------------

       TLorentzVector e1, j1, e2, mu, met;
       TLorentzVector e1e2mu;
       TLorentzVector eej, ee;
       
       e1.SetPtEtaPhiM ( LooseEle1_Pt, LooseEle1_Eta, LooseEle1_Phi, 0.0 );
       e2.SetPtEtaPhiM ( LooseEle2_Pt, LooseEle2_Eta, LooseEle2_Phi, 0.0 );
       j1.SetPtEtaPhiM ( JetLooseEle1_Pt, JetLooseEle1_Eta, JetLooseEle1_Phi, 0.0 );
       mu.SetPtEtaPhiM ( Muon1_Pt, Muon1_Eta, Muon1_Phi, 0.0 );
       met.SetPtEtaPhiM ( PFMET_Type01XY_Pt, 0.0, PFMET_Type01XY_Phi, 0.0 );

       eej  = e1 + e2 + j1;
       ee   = e1 + e2;
       
       double DR_Ele1Ele2 = e1.DeltaR( e2 );       
       double M_eej  = eej.M();
       double DR_ZJ1 = ee.DeltaR ( j1 );
       
       //--------------------------------------------------------------------------
       // Preselection histograms
       //--------------------------------------------------------------------------

       FillUserTH1D("DR_Ele1Ele2_PAS"	   , DR_Ele1Ele2                        , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("EleChargeSum_PAS"     , LooseEle1_Charge + LooseEle2_Charge, min_prescale * fakeRateEffective ) ;
       FillUserTH1D("sT_PAS"               , sT_eejj                            , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("nElectron_PAS"        , nLooseEle_ptCut                    , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("nMuon_PAS"            , nMuon_ptCut                        , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("nJet_PAS"             , nJetLooseEle_ptCut                 , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("Pt1stEle_PAS"	   , LooseEle1_Pt                       , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("Eta1stEle_PAS"	   , LooseEle1_Eta                      , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("Phi1stEle_PAS"	   , LooseEle1_Phi                      , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("Pt2ndEle_PAS"	   , LooseEle2_Pt                       , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("Eta2ndEle_PAS"	   , LooseEle2_Eta                      , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("Phi2ndEle_PAS"	   , LooseEle2_Phi                      , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("Charge1stEle_PAS"	   , LooseEle1_Charge                   , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("Charge2ndEle_PAS"	   , LooseEle2_Charge                   , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("MET_PAS"              , PFMET_Type01XY_Pt                  , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("METPhi_PAS"	   , PFMET_Type01XY_Phi                 , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("Pt1stJet_PAS"         , JetLooseEle1_Pt                    , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("Eta1stJet_PAS"        , JetLooseEle1_Eta                   , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("Phi1stJet_PAS"	   , JetLooseEle1_Phi                   , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("sTlep_PAS"            , LooseEle1_Pt + LooseEle2_Pt        , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("Mee_PAS"		   , M_e1e2                             , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("MTenu_PAS"            , MT_Ele1MET                         , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("Me1j1_PAS"            , M_e1j1                             , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("Me2j1_PAS"            , M_e2j1                             , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("Ptee_PAS"             , Pt_e1e2                            , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("DCotTheta1stEle_PAS"  , LooseEle1_DCotTheta                , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("Dist1stEle_PAS"       , LooseEle1_Dist                     , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("DCotTheta2ndEle_PAS"  , LooseEle2_DCotTheta                , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("Dist2ndEle_PAS"       , LooseEle2_Dist                     , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("nVertex_PAS"          , nVertex                            , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("DR_Ele1Jet1_PAS"	   , DR_Ele1Jet1                        , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("DR_Ele2Jet1_PAS"	   , DR_Ele2Jet1                        , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("Meej_PAS"             , M_eej                              , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("DR_ZJet1_PAS"         , DR_ZJ1                             , min_prescale * fakeRateEffective ) ;
       FillUserTH1D("sTfrac_Jet1_PAS"      , JetLooseEle1_Pt / sT_eejj          , min_prescale * fakeRateEffective );
       FillUserTH1D("sTfrac_Ele1_PAS"      , LooseEle1_Pt / sT_eejj             , min_prescale * fakeRateEffective );
       FillUserTH1D("sTfrac_Ele2_PAS"      , LooseEle2_Pt / sT_eejj             , min_prescale * fakeRateEffective );
       FillUserTH1D("sTfrac_Jet_PAS"       , ( JetLooseEle1_Pt  ) / sT_eejj     , min_prescale * fakeRateEffective );
       FillUserTH1D("sTfrac_Ele_PAS"       , ( LooseEle1_Pt + LooseEle2_Pt ) / sT_eejj, min_prescale * fakeRateEffective );

       FillUserTH2D("MeeVsST_PAS" , M_e1e2, sT_eej, min_prescale * fakeRateEffective ) ;	   
       
       //--------------------------------------------------------------------------
       // Preselection + event type (EBEB, EEEB, EEEE, etc)
       //--------------------------------------------------------------------------

       if      ( isEB   ) FillUserTH1D( "Mee_EB_PAS"  , M_e1e2, min_prescale * fakeRateEffective  ); 
       if      ( isEBEB ) FillUserTH1D( "Mee_EBEB_PAS", M_e1e2, min_prescale * fakeRateEffective  ); 
       else if ( isEBEE ) FillUserTH1D( "Mee_EBEE_PAS", M_e1e2, min_prescale * fakeRateEffective  ); 
       else if ( isEEEE ) FillUserTH1D( "Mee_EEEE_PAS", M_e1e2, min_prescale * fakeRateEffective  ); 
       
       //--------------------------------------------------------------------------
       // Preselection + high ST plot
       //--------------------------------------------------------------------------

       if ( sT_eej > 445. ) FillUserTH1D( "Mee_PASandST445", M_e1e2, min_prescale * fakeRateEffective ) ;

       //--------------------------------------------------------------------------
       // High M(ee) plots
       //--------------------------------------------------------------------------

       if ( M_e1e2 > 100. ) FillUserTH1D("sT_PASandMee100"   , sT_eej , min_prescale * fakeRateEffective  ); 
       if ( M_e1e2 > 110. ) FillUserTH1D("sT_PASandMee110"   , sT_eej , min_prescale * fakeRateEffective  ); 
       if ( M_e1e2 > 120. ) FillUserTH1D("sT_PASandMee120"   , sT_eej , min_prescale * fakeRateEffective  ); 
       if ( M_e1e2 > 130. ) FillUserTH1D("sT_PASandMee130"   , sT_eej , min_prescale * fakeRateEffective  ); 
       if ( M_e1e2 > 140. ) FillUserTH1D("sT_PASandMee140"   , sT_eej , min_prescale * fakeRateEffective  ); 
       if ( M_e1e2 > 150. ) FillUserTH1D("sT_PASandMee150"   , sT_eej , min_prescale * fakeRateEffective  ); 
       if ( M_e1e2 > 160. ) FillUserTH1D("sT_PASandMee160"   , sT_eej , min_prescale * fakeRateEffective  ); 
       if ( M_e1e2 > 170. ) FillUserTH1D("sT_PASandMee170"   , sT_eej , min_prescale * fakeRateEffective  ); 
       if ( M_e1e2 > 180. ) FillUserTH1D("sT_PASandMee180"   , sT_eej , min_prescale * fakeRateEffective  ); 
       if ( M_e1e2 > 190. ) FillUserTH1D("sT_PASandMee190"   , sT_eej , min_prescale * fakeRateEffective  ); 
       if ( M_e1e2 > 200. ) FillUserTH1D("sT_PASandMee200"   , sT_eej , min_prescale * fakeRateEffective  ); 
       
       
       if ( M_e1e2 > 100. ) { 

	 FillUserTH1D("Me1j1_PASandMee100"           , M_e1j1                              , min_prescale * fakeRateEffective ) ;
	 FillUserTH1D("Ptee_PASandMee100"            , Pt_e1e2                             , min_prescale * fakeRateEffective ) ;
	 FillUserTH2D("MeeVsST_PASandMee100"         , M_e1e2, sT_eej                      , min_prescale * fakeRateEffective ) ;	   
	 FillUserTH1D("nVertex_PASandMee100"         , nVertex                             , min_prescale * fakeRateEffective ) ;
	 FillUserTH1D("sT_PASandMee100"              , sT_eej                              , min_prescale * fakeRateEffective ) ;
	 FillUserTH1D("EleChargeSum_PASandMee100"    , LooseEle1_Charge + LooseEle2_Charge , min_prescale * fakeRateEffective ) ;
	 FillUserTH1D("nJet_PASandMee100"            , nJetLooseEle_ptCut                  , min_prescale * fakeRateEffective ) ;
	 FillUserTH1D("sTlep_PASandMee100"           , LooseEle1_Pt    + LooseEle2_Pt      , min_prescale * fakeRateEffective ) ;
	 FillUserTH1D("Pt1stEle_PASandMee100"        , LooseEle1_Pt                        , min_prescale * fakeRateEffective ) ;
	 FillUserTH1D("Pt2ndEle_PASandMee100"        , LooseEle2_Pt                        , min_prescale * fakeRateEffective ) ;
	 FillUserTH1D("Pt1stJet_PASandMee100"        , JetLooseEle1_Pt                     , min_prescale * fakeRateEffective ) ;

	 FillUserTH1D("sTfrac_Jet1_PASandMee100"     , JetLooseEle1_Pt / sT_eej                        , min_prescale * fakeRateEffective ) ;
	 FillUserTH1D("sTfrac_Ele1_PASandMee100"     , LooseEle1_Pt / sT_eej                           , min_prescale * fakeRateEffective ) ;
	 FillUserTH1D("sTfrac_Ele2_PASandMee100"     , LooseEle2_Pt / sT_eej                           , min_prescale * fakeRateEffective ) ;
	 FillUserTH1D("sTfrac_Jet_PASandMee100"      , ( JetLooseEle1_Pt )                   / sT_eej  , min_prescale * fakeRateEffective ) ;
	 FillUserTH1D("sTfrac_Ele_PASandMee100"      , ( LooseEle1_Pt + LooseEle2_Pt ) / sT_eej        , min_prescale * fakeRateEffective ) ;

       }

       //--------------------------------------------------------------------------
       // Preselection + M(ee) normalization region plots
       //--------------------------------------------------------------------------
       
       if ( M_e1e2 > 80.0 && M_e1e2 < 100.0 ){
	 FillUserTH1D("Mee_80_100_Preselection", M_e1e2, min_prescale * fakeRateEffective ) ;
	 if      ( isEBEB ) FillUserTH1D( "Mee_EBEB_80_100_PAS", M_e1e2, min_prescale * fakeRateEffective  ); 
	 else if ( isEBEE ) FillUserTH1D( "Mee_EBEE_80_100_PAS", M_e1e2, min_prescale * fakeRateEffective  ); 
	 else if ( isEEEE ) FillUserTH1D( "Mee_EEEE_80_100_PAS", M_e1e2, min_prescale * fakeRateEffective  ); 
	 if      ( isEB   ) FillUserTH1D( "Mee_EB_80_100_PAS"  , M_e1e2, min_prescale * fakeRateEffective  ); 
       }

       if ( M_e1e2 > 70.0 && M_e1e2 < 110.0 ){
	 FillUserTH1D("Mee_70_110_Preselection", M_e1e2, min_prescale * fakeRateEffective ) ;
	 if ( sT_eej > 600 ) 	 FillUserTH1D("Mee_70_110_ST600_Preselection", M_e1e2, min_prescale * fakeRateEffective ) ;
	 if      ( isEBEB ) FillUserTH1D( "Mee_EBEB_70_110_PAS", M_e1e2, min_prescale * fakeRateEffective  ); 
	 else if ( isEBEE ) FillUserTH1D( "Mee_EBEE_70_110_PAS", M_e1e2, min_prescale * fakeRateEffective  ); 
	 else if ( isEEEE ) FillUserTH1D( "Mee_EEEE_70_110_PAS", M_e1e2, min_prescale * fakeRateEffective  ); 
	 if      ( isEB   ) FillUserTH1D( "Mee_EB_70_110_PAS"  , M_e1e2, min_prescale * fakeRateEffective  ); 
       }

       //--------------------------------------------------------------------------
       // Region of interest plots
       //-------------------------------------------------------------------------- 
       
       if ( passed_region_of_interest ) { 
	 FillUserTH1D("Me1j1_ROI"           , M_e1j1                                         , min_prescale * fakeRateEffective );
	 FillUserTH1D("Ptee_ROI"            , Pt_e1e2                                        , min_prescale * fakeRateEffective );
	 FillUserTH1D("Eta1stJet_ROI"       , JetLooseEle1_Eta                               , min_prescale * fakeRateEffective );
	 FillUserTH1D("Eta1stEle_ROI"	    , LooseEle1_Eta                                  , min_prescale * fakeRateEffective );
	 FillUserTH1D("Eta2ndEle_ROI"	    , LooseEle2_Eta                                  , min_prescale * fakeRateEffective );
	 FillUserTH1D("Phi1stJet_ROI"       , JetLooseEle1_Phi                               , min_prescale * fakeRateEffective );
	 FillUserTH1D("Phi1stEle_ROI"	    , LooseEle1_Phi                                  , min_prescale * fakeRateEffective );
	 FillUserTH1D("Phi2ndEle_ROI"	    , LooseEle2_Phi                                  , min_prescale * fakeRateEffective );
	 FillUserTH2D("MeeVsST_ROI"         , M_e1e2                                , sT_eej , min_prescale * fakeRateEffective );	   
	 FillUserTH1D("Mee_ROI"		    , M_e1e2                                         , min_prescale * fakeRateEffective );
	 FillUserTH1D("nVertex_ROI"         , nVertex                                        , min_prescale * fakeRateEffective );
	 FillUserTH1D("EleChargeSum_ROI"    , LooseEle1_Charge + LooseEle2_Charge            , min_prescale * fakeRateEffective );
	 FillUserTH1D("nJet_ROI"            , nJetLooseEle_ptCut                             , min_prescale * fakeRateEffective );
	 FillUserTH1D("Meej_ROI"            , M_eej                                          , min_prescale * fakeRateEffective );
	 FillUserTH1D("DR_ZJet1_ROI"        , DR_ZJ1                                         , min_prescale * fakeRateEffective );
	 FillUserTH1D("MET_ROI"             , PFMET_Type01XY_Pt                              , min_prescale * fakeRateEffective );
	 FillUserTH1D("sT_ROI"              , sT_eej                                         , min_prescale * fakeRateEffective );
	 FillUserTH1D("sTlep_ROI"           , LooseEle1_Pt    + LooseEle2_Pt                 , min_prescale * fakeRateEffective );
	 FillUserTH1D("Pt1stEle_ROI"        , LooseEle1_Pt                                   , min_prescale * fakeRateEffective );
	 FillUserTH1D("Pt2ndEle_ROI"        , LooseEle2_Pt                                   , min_prescale * fakeRateEffective );
	 FillUserTH1D("Pt1stJet_ROI"        , JetLooseEle1_Pt                                , min_prescale * fakeRateEffective );
	 FillUserTH1D("sTfrac_Jet1_ROI"     , JetLooseEle1_Pt / sT_eej                       , min_prescale * fakeRateEffective );
	 FillUserTH1D("sTfrac_Ele1_ROI"     , LooseEle1_Pt / sT_eej                          , min_prescale * fakeRateEffective );
	 FillUserTH1D("sTfrac_Ele2_ROI"     , LooseEle2_Pt / sT_eej                          , min_prescale * fakeRateEffective );
	 FillUserTH1D("sTfrac_Jet_ROI"      , ( JetLooseEle1_Pt  )                  / sT_eej , min_prescale * fakeRateEffective );
	 FillUserTH1D("sTfrac_Ele_ROI"      , ( LooseEle1_Pt + LooseEle2_Pt )       / sT_eej , min_prescale * fakeRateEffective );
       }
     } // End preselection 
   } // End loop over events

   std::cout << "analysisClass::Loop() ends" <<std::endl;   
}
void analysisClass::Loop()
{
   std::cout << "analysisClass::Loop() begins" <<std::endl;   

   //--------------------------------------------------------------------------
   // Decide which plots to save (default is to save everything)
   //--------------------------------------------------------------------------
   
   fillSkim                         ( !true  ) ;
   fillAllPreviousCuts              ( !true  ) ;
   fillAllOtherCuts                 (  true  ) ;
   fillAllSameLevelAndLowerLevelCuts( !true  ) ;
   fillAllCuts                      ( !true  ) ;

   //--------------------------------------------------------------------------
   // Pileup reweighting initialization
   //--------------------------------------------------------------------------
   
   // Lumi3DReWeighting lumiWeights = Lumi3DReWeighting("/afs/cern.ch/user/e/eberry/public/LQ_PILEUP/pileup_truth_MC_Summer11_PU_S4_3DReweighting.root",
   // 						     "/afs/cern.ch/user/e/eberry/public/LQ_PILEUP/pileup_truth_finebin_2011_finebin.root",
   // 						     "pileup", "pileup");
   // lumiWeights.weight3D_init(1.0);
   
   //--------------------------------------------------------------------------
   // Any extra features
   //--------------------------------------------------------------------------
   
   TProfile * profile_run_vs_nvtx_HLT = new TProfile("run_vs_nvtx_HLT", "", 20000 , 160300  , 180300 );
   TProfile * profile_run_vs_nvtx_PAS = new TProfile("run_vs_nvtx_PAS", "", 20000 , 160300  , 180300 );
   
   //--------------------------------------------------------------------------
   // Get pre-cut values
   //--------------------------------------------------------------------------

   // eta boundaries

   double eleEta_bar_max = getPreCutValue1("eleEta_bar");
   double eleEta_end_min = getPreCutValue1("eleEta_end1");
   double eleEta_end_max = getPreCutValue2("eleEta_end2");

   // dataset
   
   int dataset  = getPreCutValue1("dataset") ;
   bool select2011A = ( dataset == 0 );
   bool select2011B = ( dataset == 1 );
   bool select2011  = ( dataset == 2 );

   if ( ! select2011A &&
	! select2011B &&
	! select2011 ) {
     std::cout << "Error: Must choose dataset to be 0 (2011A), 1 (2011B), or 2 (all 2011)" << std::endl;
   }

   //--------------------------------------------------------------------------
   // Create TH1D's
   //--------------------------------------------------------------------------
   
   // gap: 1.442 - 1.560

   // eleEta_bar            	1.442        -                    -               -               -1
   // eleEta_end1            	1.560        2.0                  -               -               -1
   // eleEta_end2            	2.000        2.5                  -               -               -1
   
   CreateUserTH1D( "nElectron_PAS"         ,    5   , -0.5    , 4.5      );
   CreateUserTH1D( "nMuon_PAS"             ,    5   , -0.5    , 4.5      );
   CreateUserTH1D( "nJet_PAS"              ,    10  , -0.5    , 9.5      );
   CreateUserTH1D( "Pt1stEle_PAS"	   , 	100 , 0       , 1000     ); 
   CreateUserTH1D( "Eta1stEle_PAS"	   , 	100 , -5      , 5	 ); 
   CreateUserTH1D( "Phi1stEle_PAS"	   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "Pt2ndEle_PAS"	   , 	100 , 0       , 1000     ); 
   CreateUserTH1D( "Eta2ndEle_PAS"	   , 	100 , -5      , 5	 ); 
   CreateUserTH1D( "Phi2ndEle_PAS"	   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "Charge1stEle_PAS"	   , 	2   , -1.0001 , 1.0001	 ); 
   CreateUserTH1D( "Charge2ndEle_PAS"	   , 	2   , -1.0001 , 1.0001	 ); 
   CreateUserTH1D( "MET_PAS"               ,    200 , 0       , 1000	 ); 
   CreateUserTH1D( "METSig_PAS"            ,    200 , 0       , 1000	 ); 
   CreateUserTH1D( "METPhi_PAS"		   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "METCharged_PAS"        ,    200 , 0       , 1000	 ); 
   CreateUserTH1D( "METChargedPhi_PAS"	   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "METType1_PAS"          ,    200 , 0       , 1000	 ); 
   CreateUserTH1D( "METType1Phi_PAS"	   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "Pt1stJet_PAS"          ,    100 , 0       , 1000	 ); 
   CreateUserTH1D( "Pt2ndJet_PAS"          ,    100 , 0       , 1000	 ); 
   CreateUserTH1D( "Eta1stJet_PAS"         ,    100 , -5      , 5	 ); 
   CreateUserTH1D( "Eta2ndJet_PAS"         ,    100 , -5      , 5	 ); 
   CreateUserTH1D( "Phi1stJet_PAS"	   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "Phi2ndJet_PAS"	   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "sTlep_PAS"             ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "sTjet_PAS"             ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "sT_PAS"                ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Mjj_PAS"		   ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Mee_PAS"		   ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "MTenu_PAS"                , 200 , 0       , 1000	 ); 
   CreateUserTH1D( "Me1j1_PAS"             ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Me1j2_PAS"             ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Me2j1_PAS"             ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Me2j2_PAS"             ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Me1j_selected_PAS"     ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Me2j_selected_PAS"     ,    200 , 0       , 2000     );
   CreateUserTH1D( "Mej_selected_avg_PAS"  ,    200 , 0       , 2000     );
   CreateUserTH1D( "Meejj_PAS"             ,    200 , 0       , 2000     );
   CreateUserTH1D( "run_PAS"               ,    20000 , 160300  , 180300 );
   CreateUserTH1D( "run_HLT"               ,    20000 , 160300  , 180300 );
		                           
   CreateUserTH1D( "PtRealEle_PAS"	   , 	100 , 0       , 1000     ); 
   CreateUserTH1D( "EtaRealEle_PAS"	   , 	100 , -5      , 5	 ); 
   CreateUserTH1D( "PhiRealEle_PAS"	   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "ChargeRealEle_PAS"	   , 	2   , -1.0001 , 1.0001	 ); 

   CreateUserTH1D( "PtRealMuon_PAS"	   , 	100 , 0       , 1000     ); 
   CreateUserTH1D( "EtaRealMuon_PAS"	   , 	100 , -5      , 5	 ); 
   CreateUserTH1D( "PhiRealMuon_PAS"	   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "ChargeRealMuon_PAS"	   , 	2   , -1.0001 , 1.0001	 ); 
   
   CreateUserTH1D( "Ptee_PAS"              ,    200 , 0       , 2000     );
   		                           
   CreateUserTH1D( "DCotTheta1stEle_PAS"   ,    100 , 0.0, 1.0);
   CreateUserTH1D( "Dist1stEle_PAS"        ,    100 , 0.0, 1.0);  
   CreateUserTH1D( "DCotTheta2ndEle_PAS"   ,    100 , 0.0, 1.0);
   CreateUserTH1D( "Dist2ndEle_PAS"        ,    100 , 0.0, 1.0);  
		                           
   CreateUserTH1D( "nVertex_PAS"           ,    31   , -0.5   , 30.5	 ) ; 
   CreateUserTH1D( "nVertex_good_PAS"      ,    31   , -0.5   , 30.5	 ) ; 
		                           
   CreateUserTH1D( "DR_Ele1Jet1_PAS"	   , 	getHistoNBins("DR_Ele1Jet1"), getHistoMin("DR_Ele1Jet1"), getHistoMax("DR_Ele1Jet1")     ) ; 
   CreateUserTH1D( "DR_Ele1Jet2_PAS"	   , 	getHistoNBins("DR_Ele1Jet2"), getHistoMin("DR_Ele1Jet2"), getHistoMax("DR_Ele1Jet2")     ) ; 
   CreateUserTH1D( "DR_Ele2Jet1_PAS"	   , 	getHistoNBins("DR_Ele2Jet1"), getHistoMin("DR_Ele2Jet1"), getHistoMax("DR_Ele2Jet1")     ) ; 
   CreateUserTH1D( "DR_Ele2Jet2_PAS"	   , 	getHistoNBins("DR_Ele2Jet2"), getHistoMin("DR_Ele2Jet2"), getHistoMax("DR_Ele2Jet2")     ) ; 
   CreateUserTH1D( "DR_Jet1Jet2_PAS"	   , 	getHistoNBins("DR_Jet1Jet2"), getHistoMin("DR_Jet1Jet2"), getHistoMax("DR_Jet1Jet2")     ) ; 
   CreateUserTH1D( "DR_Ele1Ele2_PAS"	   , 	getHistoNBins("DR_Jet1Jet2"), getHistoMin("DR_Jet1Jet2"), getHistoMax("DR_Jet1Jet2")     ) ; 
   CreateUserTH1D( "minDR_EleJet_PAS"	   , 	getHistoNBins("DR_Jet1Jet2"), getHistoMin("DR_Jet1Jet2"), getHistoMax("DR_Jet1Jet2")     ) ; 

   CreateUserTH1D( "DR_RealEleJet1_PAS"	   , 	getHistoNBins("DR_Ele1Jet1"), getHistoMin("DR_Ele1Jet1"), getHistoMax("DR_Ele1Jet1")     ) ; 
   CreateUserTH1D( "DR_RealEleJet2_PAS"	   , 	getHistoNBins("DR_Ele1Jet2"), getHistoMin("DR_Ele1Jet2"), getHistoMax("DR_Ele1Jet2")     ) ; 
   CreateUserTH1D( "DR_RealMuonJet1_PAS"   , 	getHistoNBins("DR_Ele2Jet1"), getHistoMin("DR_Ele2Jet1"), getHistoMax("DR_Ele2Jet1")     ) ; 
   CreateUserTH1D( "DR_RealMuonJet2_PAS"   , 	getHistoNBins("DR_Ele2Jet2"), getHistoMin("DR_Ele2Jet2"), getHistoMax("DR_Ele2Jet2")     ) ; 

   CreateUserTH2D( "Me1jVsMe2j_selected",     200, 0, 2000, 200, 0, 2000) ;
   CreateUserTH2D( "Me1jVsMe2j_rejected",     200, 0, 2000, 200, 0, 2000) ;

   CreateUserTH1D( "MTeemunu_PAS"          ,    200 , 0       , 1000	 ); 

   CreateUserTH1D( "Mee_80_100_Preselection", 200, 60, 120 );
   CreateUserTH1D( "Mee_70_110_Preselection", 200, 60, 120 );

   CreateUserTH1D( "Mee_EBEB_PAS"		   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EBEE_PAS"		   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EEEE_PAS"		   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EB_PAS" 		   ,    60 , 60       , 120	 ); 

   CreateUserTH1D( "Mee_EBEB_80_100_PAS"	   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EBEE_80_100_PAS"	   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EEEE_80_100_PAS"	   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EB_80_100_PAS" 	     	   ,    60 , 60       , 120	 ); 
   
   CreateUserTH1D( "Mee_EBEB_70_110_PAS"	   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EBEE_70_110_PAS"	   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EEEE_70_110_PAS"	   ,    60 , 60       , 120	 ); 
   CreateUserTH1D( "Mee_EB_70_110_PAS" 	     	   ,    60 , 60       , 120	 ); 

   CreateUserTH1D( "PileupWeight"   , 100, -10, 10 );
   CreateUserTH1D( "GeneratorWeight", 100, -2.0, 2.0);


   CreateUserTH1D("Mej_selected_avg_LQ250"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_avg_LQ350"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_avg_LQ400"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_avg_LQ450"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_avg_LQ500"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_avg_LQ550"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_avg_LQ600"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_avg_LQ650"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_avg_LQ750"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_avg_LQ850"         ,   40  , 0        , 2000     );

   CreateUserTH1D("Mej_selected_min_LQ250"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_min_LQ350"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_min_LQ400"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_min_LQ450"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_min_LQ500"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_min_LQ550"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_min_LQ600"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_min_LQ650"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_min_LQ750"         ,   40  , 0        , 2000     );
   CreateUserTH1D("Mej_selected_min_LQ850"         ,   40  , 0        , 2000     );

   CreateUserTH1D("sT_eejj_LQ250"                  ,   20  , 0        , 2000     );
   CreateUserTH1D("sT_eejj_LQ350"                  ,   20  , 0        , 2000     );
   CreateUserTH1D("sT_eejj_LQ400"                  ,   20  , 0        , 2000     );
   CreateUserTH1D("sT_eejj_LQ450"                  ,   20  , 0        , 2000     );
   CreateUserTH1D("sT_eejj_LQ500"                  ,   20  , 0        , 2000     );
   CreateUserTH1D("sT_eejj_LQ550"                  ,   20  , 0        , 2000     );
   CreateUserTH1D("sT_eejj_LQ600"                  ,   20  , 0        , 2000     );
   CreateUserTH1D("sT_eejj_LQ650"                  ,   20  , 0        , 2000     );
   CreateUserTH1D("sT_eejj_LQ750"                  ,   20  , 0        , 2000     );
   CreateUserTH1D("sT_eejj_LQ850"                  ,   20  , 0        , 2000     );

   CreateUserTH1D("Mee_LQ250"                      ,   40  , 0        , 2000     );
   CreateUserTH1D("Mee_LQ350"                      ,   40  , 0        , 2000     );
   CreateUserTH1D("Mee_LQ400"                      ,   40  , 0        , 2000     );
   CreateUserTH1D("Mee_LQ450"                      ,   40  , 0        , 2000     );
   CreateUserTH1D("Mee_LQ500"                      ,   40  , 0        , 2000     );
   CreateUserTH1D("Mee_LQ550"                      ,   40  , 0        , 2000     );
   CreateUserTH1D("Mee_LQ600"                      ,   40  , 0        , 2000     );
   CreateUserTH1D("Mee_LQ650"                      ,   40  , 0        , 2000     );
   CreateUserTH1D("Mee_LQ750"                      ,   40  , 0        , 2000     );
   CreateUserTH1D("Mee_LQ850"                      ,   40  , 0        , 2000     );

   //--------------------------------------------------------------------------
   // Loop over the chain
   //--------------------------------------------------------------------------

   if (fChain == 0) return;
   
   Long64_t nentries = fChain->GetEntries();
   std::cout << "analysisClass::Loop(): nentries = " << nentries << std::endl;   

   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 << "/" << nentries << std::endl;   

     //--------------------------------------------------------------------------
     // Reset the cuts
     //--------------------------------------------------------------------------

     resetCuts();

     //--------------------------------------------------------------------------
     // Check good run list
     //--------------------------------------------------------------------------
     
     int    passedJSON = passJSON ( run, ls , isData ) ;

     //--------------------------------------------------------------------------
     // Is this the dataset we want?
     //--------------------------------------------------------------------------
     
     int PassDataset = 1;
     if ( isData ) { 
       PassDataset = 0;
       if ( select2011A ){ 
	 if ( run >= 160329 && run <= 175770 ) PassDataset = 1;
       }
       if ( select2011B ){
	 if ( run >= 175832 && run <= 180296 ) PassDataset = 1;
       }
       if ( select2011 ) {
	 PassDataset = 1;
       }
     }

     //--------------------------------------------------------------------------
     // Do pileup re-weighting
     //--------------------------------------------------------------------------

     int NPILEUP_AVE = int( nPileUpInt_BX0 );
     int NPILEUP_FINAL = min( NPILEUP_AVE , 25 );
     double pileup_weight = getPileupWeight ( NPILEUP_FINAL, isData ) ;
     
     //--------------------------------------------------------------------------
     // Calculate electron variables with muon
     //--------------------------------------------------------------------------

     TLorentzVector e1, e2, met, j1, j2, j3;
     met.SetPtEtaPhiM ( MET_Pt, 0.0, MET_Phi, 0.0 );
     if ( nJet_Ana >= 1  ){
       j1.SetPtEtaPhiM ( Jet1_Pt , Jet1_Eta , Jet1_Phi , 0.0 );
       if ( nJet_Ana >= 2  ) {
	 j2.SetPtEtaPhiM ( Jet2_Pt , Jet2_Eta , Jet2_Phi , 0.0 );
	 if ( nJet_Ana >= 3  ) 
	   j3.SetPtEtaPhiM ( Jet3_Pt , Jet3_Eta , Jet3_Phi , 0.0 );
       }
     }

     double DR_Ele1Ele2_new ;
     double DR_Ele1Jet3_new ;
     double DR_Ele2Jet3_new ;
     double Ele1_Pt_new     ;
     double Ele2_Pt_new     ;
     double Ele1_Eta_new    ;
     double Ele2_Eta_new    ;
     double Ele1_Phi_new    ;
     double Ele2_Phi_new    ;
     double Ele1_Charge_new ;
     double Ele2_Charge_new ;

     double DR_Ele1Jet1_new;
     double DR_Ele2Jet1_new;
     double DR_Ele1Jet2_new;
     double DR_Ele2Jet2_new;
           
     double M_e1j1_new;
     double M_e2j1_new;
     double M_e1j2_new;
     double M_e2j2_new;

     double M_e1e2_new  ;
     double Pt_e1e2_new ;
     double MT_Ele1MET_new;

     double sT_eejj_new;

     bool isEB_old = false;
     bool isEE_old = false;
     bool e1_isMuon = false;
     bool e1_isEle  = false;
     bool e2_isMuon = false;
     bool e2_isEle  = false;


     if ( nMuon_Ana >= 1 && nEle_Ana >= 1  ){
       
       bool isEB_old = ( fabs(Ele1_Eta) < eleEta_bar_max  ) ;
       bool isEE_old = ( fabs(Ele1_Eta) > eleEta_end_min &&
			 fabs(Ele1_Eta) < eleEta_end_max ) ;
       
       if ( Ele1_Pt >= Muon1_Pt ) {
	 e1.SetPtEtaPhiM ( Ele1_Pt , Ele1_Eta , Ele1_Phi , 0.0 );
	 e2.SetPtEtaPhiM ( Muon1_Pt, Muon1_Eta, Muon1_Phi, 0.0 );
	 Ele2_Charge_new = Muon1_Charge;
	 Ele1_Charge_new = Ele1_Charge;
	 e1_isEle  = true;
	 e2_isMuon = true;
       }
       else { 
	 e1.SetPtEtaPhiM ( Muon1_Pt, Muon1_Eta, Muon1_Phi, 0.0 );
	 e2.SetPtEtaPhiM ( Ele1_Pt , Ele1_Eta , Ele1_Phi , 0.0 );
	 Ele2_Charge_new = Ele1_Charge;
	 Ele1_Charge_new = Muon1_Charge;
	 e1_isMuon   = true;
	 e2_isEle    = true;
       }

       Ele1_Pt_new  = e1.Pt();
       Ele1_Eta_new = e1.Eta();
       Ele1_Phi_new = e1.Phi();
       
       Ele2_Pt_new  = e2.Pt();
       Ele2_Eta_new = e2.Eta();
       Ele2_Phi_new = e2.Phi();

       TLorentzVector e1e2 = e1 + e2;
       M_e1e2_new  = e1e2.M();
       Pt_e1e2_new = e1e2.Pt();

       DR_Ele1Ele2_new = e1.DeltaR( e2 ) ;
       MT_Ele1MET_new = sqrt(2 * e1.Pt() * met.Pt() * (1 - cos(met.DeltaPhi(e1))));
       
       if ( nJet_Ana >= 1 ){

	 TLorentzVector e1j1 = e1 + j1;
	 TLorentzVector e2j1 = e2 + j1;
	 M_e1j1_new = e1j1.M();
	 M_e2j1_new = e2j1.M();

	 DR_Ele1Jet1_new = e1.DeltaR ( j1 ) ;
	 DR_Ele2Jet1_new = e2.DeltaR ( j1 ) ;
	 
	 if ( nJet_Ana >= 2 ){
	   DR_Ele1Jet2_new = e1.DeltaR ( j2 ) ;
	   DR_Ele2Jet2_new = e2.DeltaR ( j2 ) ;

	   TLorentzVector e1j2 = e1 + j2;
	   TLorentzVector e2j2 = e2 + j2;
	   M_e1j2_new = e1j2.M();
	   M_e2j2_new = e2j2.M();
	   
	   sT_eejj_new = e1.Pt() + e2.Pt() + j1.Pt() + j2.Pt();
	   
	   if ( nJet_Ana >= 3 ){
	     DR_Ele1Jet3_new = e1.DeltaR ( j3 ) ;
	     DR_Ele2Jet3_new = e2.DeltaR ( j3 ) ;
	   }
	 }
       }
     }
     
     //--------------------------------------------------------------------------
     // Fill variables
     //--------------------------------------------------------------------------

     //fillVariableWithValue(   "PassBPTX0"                     , PassBPTX0                    ) ; 
     //fillVariableWithValue(   "PassPhysDecl"                  , PassPhysDecl                 ) ; 
     //fillVariableWithValue(   "PassBeamScraping"              , PassBeamScraping             ) ; 
     //fillVariableWithValue(   "PassPrimaryVertex"             , PassPrimaryVertex            ) ; 
     //fillVariableWithValue(   "PassBeamHaloFilterLoose"	      , PassBeamHaloFilterLoose	     ) ; 
     //fillVariableWithValue(   "PassTrackingFailure"           , PassTrackingFailure          ) ; 
     //fillVariableWithValue(   "PassCaloBoundaryDRFilter"      , PassCaloBoundaryDRFilter     ) ; 
     //fillVariableWithValue(   "PassEcalMaskedCellDRFilter"    , PassEcalMaskedCellDRFilter   ) ; 

     // Fill HLT 

     int passHLT = 1;
     if ( isData ){ 
       
       passHLT = 0;
       /*
       if (  H_27_CIdVT_CIsT_TIdT_TIsT_1  == 1 ||  // 2011A   /SingleElectron/, runs: 160404 - 161176   --> 5.281(/pb)	 
	     H_27_CIdVT_CIsT_TIdT_TIsT_2  == 1 ||  // 2011A   /SingleElectron/, runs: 161216 - 163261   --> 28.321(/pb) 
	     H_27_CIdVT_CIsT_TIdT_TIsT_3  == 1 ||  // 2011A   /SingleElectron/, runs: 163269 - 163869   --> 168.613(/pb)
	     H_32_CIdVT_CIsT_TIdT_TIsT_3  == 1 ||  // 2011A   /SingleElectron/, runs: 165088 - 165633   --> 139.027(/pb)
	     H_42_CIdVT_CIsT_TIdT_TIsT_1  == 1 ||  // 2011A   /SingleElectron/, runs: 165970 - 166967   --> 524.904(/pb)
	     H_52_CIdVT_TIdT_3		  == 1 ||  // 2011A   /SingleElectron/, runs: 167039 - 167913   --> 265.747(/pb)
	     H_65_CIdVT_TIdT_3		  == 1 ||  // 2011A   /SingleElectron/, runs: 170249 - 173198   --> 748.931(/pb)
	     H_65_CIdVT_TIdT_4		  == 1 ||  // 2011A+B /SingleElectron/, runs: 173236 - 173692   --> 246.527(/pb)  +  175832 - 178380  -->  1.698(/fb)
	     H_80_CIdVT_TIdT_2            == 1 ||  // 2011B   /SingleElectron/, runs: 178420 - 179889  -->  641.378(/pb)
	     H_80_CIdVT_TIdT_3            == 1 ) { // 2011B   /SingleElectron/, runs: 179959 - 180252  -->  117.644(/pb)
	 passHLT = 1;                              // Total: 2.127351 (/fb) +  2.457022 (/fb)  = 4.584373 (/fb)
       }
       */
       
       if ( H_Mu15_Pho20_CIdL_2      == 1 || 
	    H_Mu15_Pho20_CIdL_3      == 1 || 
	    H_Mu15_Pho20_CIdL_4      == 1 || 
	    H_Mu15_Pho20_CIdL_5      == 1 || 
	    H_Mu15_Pho20_CIdL_6      == 1 || 
	    H_Mu15_Pho20_CIdL_7      == 1 || 
	    H_Mu15_Pho20_CIdL_9      == 1 || 
	    H_Mu15_Pho20_CIdL_10     == 1 || 
	    H_Mu15_Photon20_CIdL_13  == 1 || 
	    H_Mu15_Photon20_CIdL_14  == 1 || 
	    H_Mu17_Ele8_CIdT_CIsVL_4 == 1 || 
	    H_Mu17_Ele8_CIdT_CIsVL_7 == 1 || 
	    H_Mu17_Ele8_CIdT_CIsVL_8 == 1 ){
	 passHLT = 1;
       }
     }

     //--------------------------------------------------------------------------
     // Calculate weights for trigger and reconstruction efficiency
     //--------------------------------------------------------------------------

     /*
     if ( isData && passHLT == 1 && isEB_old) {
       if       ( H_27_CIdVT_CIsT_TIdT_TIsT_1  == 1 ) ele_trigger_efficiency = 0.9998;
       else if  ( H_27_CIdVT_CIsT_TIdT_TIsT_2  == 1 ) ele_trigger_efficiency = 0.9998;
       else if  ( H_27_CIdVT_CIsT_TIdT_TIsT_3  == 1 ) ele_trigger_efficiency = 0.9998;
       else if  ( H_32_CIdVT_CIsT_TIdT_TIsT_3  == 1 ) ele_trigger_efficiency = 0.9964;
       else if  ( H_42_CIdVT_CIsT_TIdT_TIsT_1  == 1 ) ele_trigger_efficiency = 0.9964;
       else if  ( H_52_CIdVT_TIdT_3	       == 1 ) ele_trigger_efficiency = 0.9898;
       else if  ( H_65_CIdVT_TIdT_3	       == 1 ) ele_trigger_efficiency = 0.9849;
       else if  ( H_65_CIdVT_TIdT_4	       == 1 ) ele_trigger_efficiency = 0.9849;
       else if  ( H_80_CIdVT_TIdT_2            == 1 ) ele_trigger_efficiency = 0.9849;
       else if  ( H_80_CIdVT_TIdT_3            == 1 ) ele_trigger_efficiency = 0.9849;
       else { 
	 std::cout << "ERROR: Which trigger fired? (EB)" << std::endl;
       }
       
     }

     else if ( isData && passHLT == 1 && isEE_old) {
       if       ( H_27_CIdVT_CIsT_TIdT_TIsT_1  == 1 ) ele_trigger_efficiency = 0.9998;
       else if  ( H_27_CIdVT_CIsT_TIdT_TIsT_2  == 1 ) ele_trigger_efficiency = 0.9998;
       else if  ( H_27_CIdVT_CIsT_TIdT_TIsT_3  == 1 ) ele_trigger_efficiency = 0.9998;
       else if  ( H_32_CIdVT_CIsT_TIdT_TIsT_3  == 1 ) ele_trigger_efficiency = 0.9996;
       else if  ( H_42_CIdVT_CIsT_TIdT_TIsT_1  == 1 ) ele_trigger_efficiency = 0.9996;
       else if  ( H_52_CIdVT_TIdT_3	       == 1 ) ele_trigger_efficiency = 0.9620;
       else if  ( H_65_CIdVT_TIdT_3	       == 1 ) ele_trigger_efficiency = 0.9710;
       else if  ( H_65_CIdVT_TIdT_4	       == 1 ) ele_trigger_efficiency = 0.9710;
       else if  ( H_80_CIdVT_TIdT_2            == 1 ) ele_trigger_efficiency = 0.9710;
       else if  ( H_80_CIdVT_TIdT_3            == 1 ) ele_trigger_efficiency = 0.9719;
       else { 
	 std::cout << "ERROR: Which trigger fired (EE)?" << std::endl;
       }
     }
     */

     double efficiency_weight = 1.0;

     //--------------------------------------------------------------------------
     
     // JSON variable
     fillVariableWithValue(   "PassJSON"                      , passedJSON, efficiency_weight   ) ; 

     // Dataset variable
     fillVariableWithValue(   "PassDataset"                   , PassDataset, efficiency_weight   ) ; 

     // Noise filters
     fillVariableWithValue(   "PassHBHENoiseFilter"           , PassHBHENoiseFilter    , efficiency_weight   ) ; 
     fillVariableWithValue(   "PassBeamHaloFilterTight"       , PassBeamHaloFilterTight, efficiency_weight   ) ; 

     
     fillVariableWithValue ( "Reweighting", 1, efficiency_weight  );
     fillVariableWithValue ( "PassHLT", passHLT, efficiency_weight  ) ;
     
     // Electrons
     int PassNEle = 0;
     if ( nEle_Ana == 1 ) PassNEle = 1;
     
     double M_ej_avg;
     double M_ej_min;

     // Muons
     int PassNMuon = 0;
     if ( nMuon_Ana == 1 ) PassNMuon = 1;

     fillVariableWithValue(   "PassNEle"                      , PassNEle          , efficiency_weight ) ;
     fillVariableWithValue(   "PassNMuon"                     , PassNMuon         , efficiency_weight ) ;
									          
     if ( nMuon_Ana >= 1 && nEle_Ana >= 1 ) {				          
       fillVariableWithValue( "Ele1_Pt"                       , Ele1_Pt_new       , efficiency_weight ) ;
       fillVariableWithValue( "Ele1_Eta"                      , Ele1_Eta_new      , efficiency_weight ) ;
       fillVariableWithValue( "abs_Ele1_Eta"                  , fabs(Ele1_Eta_new), efficiency_weight ) ;

       fillVariableWithValue( "Ele2_Pt"                       , Ele2_Pt_new       , efficiency_weight ) ;
       fillVariableWithValue( "Ele2_Eta"                      , Ele2_Eta_new      , efficiency_weight ) ;
       fillVariableWithValue( "abs_Ele2_Eta"                  , fabs(Ele2_Eta_new), efficiency_weight ) ;
       fillVariableWithValue( "M_e1e2"                        , M_e1e2_new        , efficiency_weight ) ;
     }									    
									    
     // Jets								    
     fillVariableWithValue(   "nJet"                          , nJet_Ana      , efficiency_weight ) ;
     if ( nJet_Ana >= 1 ) { 						    
       fillVariableWithValue( "Jet1_Pt"                       , Jet1_Pt       , efficiency_weight ) ;
       fillVariableWithValue( "Jet1_Eta"                      , Jet1_Eta      , efficiency_weight ) ;
     }
     if ( nJet_Ana >= 2 ) { 
       fillVariableWithValue( "Jet2_Pt"                       , Jet2_Pt       , efficiency_weight ) ;
       fillVariableWithValue( "Jet2_Eta"                      , Jet2_Eta      , efficiency_weight ) ;
       fillVariableWithValue( "DR_Jet1Jet2"                   , DR_Jet1Jet2   , efficiency_weight ) ;
     }

     // DeltaR
     if ( nEle_Ana >= 1 && nMuon_Ana >= 1 && nJet_Ana >= 1) {
       fillVariableWithValue( "DR_Ele1Jet1"                   , DR_Ele1Jet1_new   , efficiency_weight ) ;
       fillVariableWithValue( "DR_Ele2Jet1"                   , DR_Ele2Jet1_new   , efficiency_weight ) ;
       if(nJet_Ana >= 2) {					           
	 fillVariableWithValue( "DR_Ele1Jet2"                 , DR_Ele1Jet2_new   , efficiency_weight ) ;
	 fillVariableWithValue( "DR_Ele2Jet2"                 , DR_Ele2Jet2_new   , efficiency_weight ) ;
       }
     }

     // sT
     if ( nEle_Ana >= 1 && nMuon_Ana >= 1 && nJet_Ana >= 2) {
       fillVariableWithValue( "sT_eejj"                      , sT_eejj_new  , efficiency_weight ) ;

       if ( fabs(M_e1j1_new-M_e2j2_new) < fabs(M_e1j2_new-M_e2j1_new) )  {
	 M_ej_avg = (M_e1j1_new + M_e2j2_new) / 2.0;
	 if    ( M_e1j1_new < M_e2j2_new ) M_ej_min = M_e1j1_new;
	 else                              M_ej_min = M_e2j2_new;
       }
       else { 
	 M_ej_avg = (M_e1j2_new + M_e2j1_new) / 2.0;
	 if    ( M_e1j2_new < M_e2j1_new ) M_ej_min = M_e1j2_new;
	 else                              M_ej_min = M_e2j1_new;
       }
       
       fillVariableWithValue( "sT_eejj"                      , sT_eejj_new, efficiency_weight   ) ;
       
       fillVariableWithValue( "sT_eejj_LQ250"                , sT_eejj_new, efficiency_weight   ) ;
       fillVariableWithValue( "sT_eejj_LQ350"                , sT_eejj_new, efficiency_weight   ) ;
       fillVariableWithValue( "sT_eejj_LQ400"                , sT_eejj_new, efficiency_weight   ) ;
       fillVariableWithValue( "sT_eejj_LQ450"                , sT_eejj_new, efficiency_weight   ) ;
       fillVariableWithValue( "sT_eejj_LQ500"                , sT_eejj_new, efficiency_weight   ) ;
       fillVariableWithValue( "sT_eejj_LQ550"                , sT_eejj_new, efficiency_weight   ) ;
       fillVariableWithValue( "sT_eejj_LQ600"                , sT_eejj_new, efficiency_weight   ) ;
       fillVariableWithValue( "sT_eejj_LQ650"                , sT_eejj_new, efficiency_weight   ) ;
       fillVariableWithValue( "sT_eejj_LQ750"                , sT_eejj_new, efficiency_weight   ) ;
       fillVariableWithValue( "sT_eejj_LQ850"                , sT_eejj_new, efficiency_weight   ) ;


       fillVariableWithValue( "M_e1e2_LQ250"                , M_e1e2_new, efficiency_weight   ) ;
       fillVariableWithValue( "M_e1e2_LQ350"                , M_e1e2_new, efficiency_weight   ) ;
       fillVariableWithValue( "M_e1e2_LQ400"                , M_e1e2_new, efficiency_weight   ) ;
       fillVariableWithValue( "M_e1e2_LQ450"                , M_e1e2_new, efficiency_weight   ) ;
       fillVariableWithValue( "M_e1e2_LQ500"                , M_e1e2_new, efficiency_weight   ) ;
       fillVariableWithValue( "M_e1e2_LQ550"                , M_e1e2_new, efficiency_weight   ) ;
       fillVariableWithValue( "M_e1e2_LQ600"                , M_e1e2_new, efficiency_weight   ) ;
       fillVariableWithValue( "M_e1e2_LQ650"                , M_e1e2_new, efficiency_weight   ) ;
       fillVariableWithValue( "M_e1e2_LQ750"                , M_e1e2_new, efficiency_weight   ) ;
       fillVariableWithValue( "M_e1e2_LQ850"                , M_e1e2_new, efficiency_weight   ) ;
       
       fillVariableWithValue( "min_M_ej_LQ250"               , M_ej_min, efficiency_weight  ) ;
       fillVariableWithValue( "min_M_ej_LQ350"               , M_ej_min, efficiency_weight  ) ;
       fillVariableWithValue( "min_M_ej_LQ400"               , M_ej_min, efficiency_weight  ) ;
       fillVariableWithValue( "min_M_ej_LQ450"               , M_ej_min, efficiency_weight  ) ;
       fillVariableWithValue( "min_M_ej_LQ500"               , M_ej_min, efficiency_weight  ) ;
       fillVariableWithValue( "min_M_ej_LQ550"               , M_ej_min, efficiency_weight  ) ;
       fillVariableWithValue( "min_M_ej_LQ600"               , M_ej_min, efficiency_weight  ) ;
       fillVariableWithValue( "min_M_ej_LQ650"               , M_ej_min, efficiency_weight  ) ;
       fillVariableWithValue( "min_M_ej_LQ750"               , M_ej_min, efficiency_weight  ) ;
       fillVariableWithValue( "min_M_ej_LQ850"               , M_ej_min, efficiency_weight  ) ;

     }      

     //--------------------------------------------------------------------------
     // Evaluate the cuts
     //--------------------------------------------------------------------------
     
     evaluateCuts();

     //--------------------------------------------------------------------------
     // Fill preselection plots
     //--------------------------------------------------------------------------

     FillUserTH1D( "PileupWeight",   -1.0 );
     FillUserTH1D( "GeneratorWeight", -1.0 ) ;
     
     bool passed_minimum      = ( passedAllPreviousCuts("PassBeamHaloFilterTight") && passedCut ("PassBeamHaloFilterTight"));
     bool passed_250          = ( passedAllPreviousCuts("min_M_ej_LQ250"         ) && passedCut ("min_M_ej_LQ250"         ));
     bool passed_350          = ( passedAllPreviousCuts("min_M_ej_LQ350"         ) && passedCut ("min_M_ej_LQ350"         ));
     bool passed_400          = ( passedAllPreviousCuts("min_M_ej_LQ400"         ) && passedCut ("min_M_ej_LQ400"         ));
     bool passed_450          = ( passedAllPreviousCuts("min_M_ej_LQ450"         ) && passedCut ("min_M_ej_LQ450"         ));
     bool passed_500          = ( passedAllPreviousCuts("min_M_ej_LQ500"         ) && passedCut ("min_M_ej_LQ500"         ));
     bool passed_550          = ( passedAllPreviousCuts("min_M_ej_LQ550"         ) && passedCut ("min_M_ej_LQ550"         ));
     bool passed_600          = ( passedAllPreviousCuts("min_M_ej_LQ600"         ) && passedCut ("min_M_ej_LQ600"         ));
     bool passed_650          = ( passedAllPreviousCuts("min_M_ej_LQ650"         ) && passedCut ("min_M_ej_LQ650"         ));
     bool passed_750          = ( passedAllPreviousCuts("min_M_ej_LQ750"         ) && passedCut ("min_M_ej_LQ750"         ));
     bool passed_850          = ( passedAllPreviousCuts("min_M_ej_LQ850"         ) && passedCut ("min_M_ej_LQ850"         ));

     if ( passed_minimum && isData ){ 
       FillUserTH1D ("run_HLT", run );
       profile_run_vs_nvtx_HLT -> Fill ( run, nVertex, 1 ) ;
     }

     bool passed_preselection = ( passedAllPreviousCuts("M_e1e2") && passedCut ("M_e1e2") );
     
     if ( passed_preselection ) {

       //--------------------------------------------------------------------------
       // Fill skim tree, if necessary
       //--------------------------------------------------------------------------
       
       // fillSkimTree();

       bool isEB1 = ( fabs(Ele1_Eta_new) < eleEta_bar_max  ) ;
       bool isEE1 = ( fabs(Ele1_Eta_new) > eleEta_end_min &&
		      fabs(Ele1_Eta_new) < eleEta_end_max ) ;

       bool isEB2 = ( fabs(Ele2_Eta_new) < eleEta_bar_max  ) ;
       bool isEE2 = ( fabs(Ele2_Eta_new) > eleEta_end_min &&
		      fabs(Ele2_Eta_new) < eleEta_end_max ) ;

       bool isEBEB = ( isEB1 && isEB2 ) ;
       bool isEBEE = ( ( isEB1 && isEE2 ) ||
		       ( isEE1 && isEB2 ) );
       bool isEEEE = ( isEE1  && isEE2  );
       bool isEB   = ( isEBEB || isEBEE );
       
       if ( isData ) { 
	 FillUserTH1D("run_PAS", run ) ;
	 profile_run_vs_nvtx_PAS -> Fill ( run, nVertex, 1 ) ;
       }
       
       FillUserTH1D("nElectron_PAS"        , nEle_Ana                     , efficiency_weight * pileup_weight) ;
       FillUserTH1D("nMuon_PAS"            , nMuon_Ana                    , efficiency_weight * pileup_weight) ;
       FillUserTH1D("nJet_PAS"             , nJet_Ana                     , efficiency_weight * pileup_weight) ;
       FillUserTH1D("Pt1stEle_PAS"	   , Ele1_Pt_new                  , efficiency_weight * pileup_weight) ;
       FillUserTH1D("Eta1stEle_PAS"	   , Ele1_Eta_new                 , efficiency_weight * pileup_weight) ;
       FillUserTH1D("Phi1stEle_PAS"	   , Ele1_Phi_new                 , efficiency_weight * pileup_weight) ;
       FillUserTH1D("Pt2ndEle_PAS"	   , Ele2_Pt_new                  , efficiency_weight * pileup_weight) ;
       FillUserTH1D("Eta2ndEle_PAS"	   , Ele2_Eta_new                 , efficiency_weight * pileup_weight) ;
       FillUserTH1D("Phi2ndEle_PAS"	   , Ele2_Phi_new                 , efficiency_weight * pileup_weight) ;
       FillUserTH1D("Charge1stEle_PAS"	   , Ele1_Charge_new              , efficiency_weight * pileup_weight) ;
       FillUserTH1D("Charge2ndEle_PAS"	   , Ele2_Charge_new              , efficiency_weight * pileup_weight) ;
       FillUserTH1D("MET_PAS"              , MET_Pt                       , efficiency_weight * pileup_weight) ;
       FillUserTH1D("METSig_PAS"           , PFMETSig                     , efficiency_weight * pileup_weight) ;
       FillUserTH1D("METPhi_PAS"	   , MET_Phi                      , efficiency_weight * pileup_weight) ;
       FillUserTH1D("METCharged_PAS"       , PFMETCharged                 , efficiency_weight * pileup_weight) ;
       FillUserTH1D("METChargedPhi_PAS"    , PFMETChargedPhi              , efficiency_weight * pileup_weight) ;   
       FillUserTH1D("METType1_PAS"         , PFMETType1Cor                , efficiency_weight * pileup_weight) ;
       FillUserTH1D("METType1Phi_PAS"      , PFMETPhiType1Cor             , efficiency_weight * pileup_weight) ;   
       FillUserTH1D("Pt1stJet_PAS"         , Jet1_Pt                      , efficiency_weight * pileup_weight) ;
       FillUserTH1D("Pt2ndJet_PAS"         , Jet2_Pt                      , efficiency_weight * pileup_weight) ;
       FillUserTH1D("Eta1stJet_PAS"        , Jet1_Eta                     , efficiency_weight * pileup_weight) ;
       FillUserTH1D("Eta2ndJet_PAS"        , Jet2_Eta                     , efficiency_weight * pileup_weight) ;
       FillUserTH1D("Phi1stJet_PAS"	   , Jet1_Phi                     , efficiency_weight * pileup_weight) ;
       FillUserTH1D("Phi2ndJet_PAS"	   , Jet2_Phi                     , efficiency_weight * pileup_weight) ;
       FillUserTH1D("sTlep_PAS"            , Ele1_Pt_new + Ele2_Pt_new    , efficiency_weight * pileup_weight) ;
       FillUserTH1D("sTjet_PAS"            , Jet1_Pt + Jet2_Pt            , efficiency_weight * pileup_weight) ;
       FillUserTH1D("sT_PAS"               , sT_eejj_new                  , efficiency_weight * pileup_weight) ;
       FillUserTH1D("Mjj_PAS"		   , M_j1j2                       , efficiency_weight * pileup_weight) ;
       FillUserTH1D("Mee_PAS"		   , M_e1e2_new                   , efficiency_weight * pileup_weight) ;
       FillUserTH1D( "MTenu_PAS"           , MT_Ele1MET_new               , efficiency_weight * pileup_weight) ;
       FillUserTH1D("Me1j1_PAS"            , M_e1j1_new                   , efficiency_weight * pileup_weight) ;
       FillUserTH1D("Me1j2_PAS"            , M_e1j2_new                   , efficiency_weight * pileup_weight) ;
       FillUserTH1D("Me2j1_PAS"            , M_e2j1_new                   , efficiency_weight * pileup_weight) ;
       FillUserTH1D("Me2j2_PAS"            , M_e2j2_new                   , efficiency_weight * pileup_weight) ;
       FillUserTH1D("Ptee_PAS"             , Pt_e1e2_new                  , efficiency_weight * pileup_weight) ;
       FillUserTH1D("DCotTheta1stEle_PAS"  , -1.0                         , efficiency_weight * pileup_weight) ;
       FillUserTH1D("Dist1stEle_PAS"       , -1.0                         , efficiency_weight * pileup_weight) ;
       FillUserTH1D("DCotTheta2ndEle_PAS"  , -1.0                         , efficiency_weight * pileup_weight) ;
       FillUserTH1D("Dist2ndEle_PAS"       , -1.0                         , efficiency_weight * pileup_weight) ;
       FillUserTH1D("nVertex_PAS"          , nVertex                      , efficiency_weight * pileup_weight) ;
       FillUserTH1D("nVertex_good_PAS"     , nVertex_good                 , efficiency_weight * pileup_weight) ;
       FillUserTH1D("DR_Ele1Ele2_PAS"	   , DR_Ele1Ele2_new              , efficiency_weight * pileup_weight) ;
       FillUserTH1D("DR_Ele1Jet1_PAS"	   , DR_Ele1Jet1_new              , efficiency_weight * pileup_weight) ;
       FillUserTH1D("DR_Ele1Jet2_PAS"	   , DR_Ele1Jet2_new              , efficiency_weight * pileup_weight) ;
       FillUserTH1D("DR_Ele2Jet1_PAS"	   , DR_Ele2Jet1_new              , efficiency_weight * pileup_weight) ;
       FillUserTH1D("DR_Ele2Jet2_PAS"	   , DR_Ele2Jet2_new              , efficiency_weight * pileup_weight) ;
       FillUserTH1D("DR_Jet1Jet2_PAS"	   , DR_Jet1Jet2                  , efficiency_weight * pileup_weight) ;

       if ( e1_isEle ) {
	 FillUserTH1D("PtRealEle_PAS"      , Ele1_Pt_new                  , efficiency_weight * pileup_weight) ;
	 FillUserTH1D("EtaRealEle_PAS"     , Ele1_Eta_new                 , efficiency_weight * pileup_weight) ;
	 FillUserTH1D("PhiRealEle_PAS"     , Ele1_Phi_new                 , efficiency_weight * pileup_weight) ;
	 FillUserTH1D("ChargeRealEle_PAS"  , Ele1_Charge_new              , efficiency_weight * pileup_weight) ;
	 	                           			          
	 FillUserTH1D("PtRealMuon_PAS"     , Ele2_Pt_new                  , efficiency_weight * pileup_weight) ;
	 FillUserTH1D("EtaRealMuon_PAS"    , Ele2_Eta_new                 , efficiency_weight * pileup_weight) ;
	 FillUserTH1D("PhiRealMuon_PAS"    , Ele2_Phi_new                 , efficiency_weight * pileup_weight) ;
	 FillUserTH1D("ChargeRealMuon_PAS" , Ele2_Charge_new              , efficiency_weight * pileup_weight) ;
		                           			          
	 FillUserTH1D("DR_RealEleJet1_PAS" , DR_Ele1Jet1_new              , efficiency_weight * pileup_weight) ;
	 FillUserTH1D("DR_RealEleJet2_PAS" , DR_Ele1Jet2_new              , efficiency_weight * pileup_weight) ;
	 FillUserTH1D("DR_RealMuonJet1_PAS", DR_Ele2Jet1_new              , efficiency_weight * pileup_weight) ;
	 FillUserTH1D("DR_RealMuonJet2_PAS", DR_Ele2Jet2_new              , efficiency_weight * pileup_weight) ;
       }

       if ( e2_isEle ) {
	 FillUserTH1D("PtRealEle_PAS"      , Ele2_Pt_new          , efficiency_weight * pileup_weight) ;
	 FillUserTH1D("EtaRealEle_PAS"     , Ele2_Eta_new         , efficiency_weight * pileup_weight) ;
	 FillUserTH1D("PhiRealEle_PAS"     , Ele2_Phi_new         , efficiency_weight * pileup_weight) ;
	 FillUserTH1D("ChargeRealEle_PAS"  , Ele2_Charge_new      , efficiency_weight * pileup_weight) ;

	 FillUserTH1D("PtRealMuon_PAS"     , Ele1_Pt_new          , efficiency_weight * pileup_weight) ;
	 FillUserTH1D("EtaRealMuon_PAS"    , Ele1_Eta_new         , efficiency_weight * pileup_weight) ;
	 FillUserTH1D("PhiRealMuon_PAS"    , Ele1_Phi_new         , efficiency_weight * pileup_weight) ;
	 FillUserTH1D("ChargeRealMuon_PAS" , Ele1_Charge_new      , efficiency_weight * pileup_weight) ;

	 FillUserTH1D("DR_RealEleJet1_PAS" , DR_Ele2Jet1_new      , efficiency_weight * pileup_weight) ;
	 FillUserTH1D("DR_RealEleJet2_PAS" , DR_Ele2Jet2_new      , efficiency_weight * pileup_weight) ;
	 FillUserTH1D("DR_RealMuonJet1_PAS", DR_Ele1Jet1_new      , efficiency_weight * pileup_weight) ;
	 FillUserTH1D("DR_RealMuonJet2_PAS", DR_Ele1Jet2_new      , efficiency_weight * pileup_weight) ;
       }
       
       if      ( isEBEB ) FillUserTH1D( "Mee_EBEB_PAS", M_e1e2_new, efficiency_weight * pileup_weight); 
       else if ( isEBEE ) FillUserTH1D( "Mee_EBEE_PAS", M_e1e2_new, efficiency_weight * pileup_weight); 
       else if ( isEEEE ) FillUserTH1D( "Mee_EEEE_PAS", M_e1e2_new, efficiency_weight * pileup_weight); 
       if      ( isEB   ) FillUserTH1D( "Mee_EB_PAS"  , M_e1e2_new, efficiency_weight * pileup_weight); 

       if ( M_e1e2_new > 80.0 && M_e1e2_new < 100.0 ){
	 FillUserTH1D("Mee_80_100_Preselection", M_e1e2_new, efficiency_weight * pileup_weight) ;
	 if      ( isEBEB ) FillUserTH1D( "Mee_EBEB_80_100_PAS", M_e1e2_new, efficiency_weight * pileup_weight); 
	 else if ( isEBEE ) FillUserTH1D( "Mee_EBEE_80_100_PAS", M_e1e2_new, efficiency_weight * pileup_weight); 
	 else if ( isEEEE ) FillUserTH1D( "Mee_EEEE_80_100_PAS", M_e1e2_new, efficiency_weight * pileup_weight); 
	 if      ( isEB   ) FillUserTH1D( "Mee_EB_80_100_PAS"  , M_e1e2_new, efficiency_weight * pileup_weight); 
       } 

       if ( M_e1e2_new > 70.0 && M_e1e2_new < 110.0 ){
	 FillUserTH1D("Mee_70_110_Preselection", M_e1e2_new, efficiency_weight * pileup_weight) ;
	 if      ( isEBEB ) FillUserTH1D( "Mee_EBEB_70_110_PAS", M_e1e2_new, efficiency_weight * pileup_weight); 
	 else if ( isEBEE ) FillUserTH1D( "Mee_EBEE_70_110_PAS", M_e1e2_new, efficiency_weight * pileup_weight); 
	 else if ( isEEEE ) FillUserTH1D( "Mee_EEEE_70_110_PAS", M_e1e2_new, efficiency_weight * pileup_weight); 
	 if      ( isEB   ) FillUserTH1D( "Mee_EB_70_110_PAS"  , M_e1e2_new, efficiency_weight * pileup_weight); 
       }
       

       // e1e2mu = e1 + e2 + mu;
       // double MT_eemuMET = sqrt(2 * e1e2mu.Pt()    * MET_Pt  * (1 - cos(e1e2mu.DeltaPhi (met))));
       // FillUserTH1D("MTeemunu_PAS"         , MT_eemuMET                        , efficiency_weight * pileup_weight);
	      
       double min_DR_EleJet = 999.;
       
       if ( DR_Ele1Jet1_new < min_DR_EleJet ) min_DR_EleJet = DR_Ele1Jet1_new;
       if ( DR_Ele1Jet2_new < min_DR_EleJet ) min_DR_EleJet = DR_Ele1Jet2_new;
       if ( DR_Ele2Jet1_new < min_DR_EleJet ) min_DR_EleJet = DR_Ele2Jet1_new;
       if ( DR_Ele2Jet2_new < min_DR_EleJet ) min_DR_EleJet = DR_Ele2Jet2_new;
       if ( nJet_Ana >= 3 ) {
	 if ( DR_Ele1Jet3_new < min_DR_EleJet ) min_DR_EleJet = DR_Ele1Jet3_new;
	 if ( DR_Ele2Jet3_new < min_DR_EleJet ) min_DR_EleJet = DR_Ele2Jet3_new;
       }
       
       TLorentzVector eejj;
       eejj = e1 + e2 + j1 + j2;
       double M_eejj = eejj.M();

       FillUserTH1D("Meejj_PAS", M_eejj , efficiency_weight * pileup_weight);
       
       if ( fabs(M_e1j1_new-M_e2j2_new) < fabs(M_e1j2_new-M_e2j1_new) )  {

	 double M_ej_avg = (M_e1j1_new + M_e2j2_new) / 2.0;

	 FillUserTH1D("Mej_selected_avg_PAS", M_ej_avg                , efficiency_weight * pileup_weight);	   
	 FillUserTH1D("Me1j_selected_PAS"   , M_e1j1_new              , efficiency_weight * pileup_weight);	   
	 FillUserTH1D("Me2j_selected_PAS"   , M_e2j2_new              , efficiency_weight * pileup_weight);	   
	 FillUserTH2D( "Me1jVsMe2j_selected", M_e1j1_new  , M_e2j2_new, efficiency_weight * pileup_weight);
	 FillUserTH2D( "Me1jVsMe2j_rejected", M_e1j2_new  , M_e2j1_new, efficiency_weight * pileup_weight);
       }
       else {

	 double M_ej_avg = (M_e1j2_new + M_e2j1_new) / 2.0;

	 FillUserTH1D("Mej_selected_avg_PAS", M_ej_avg              , efficiency_weight * pileup_weight) ;	   
	 FillUserTH1D("Me1j_selected_PAS"   , M_e1j2_new            , efficiency_weight * pileup_weight) ;	   
	 FillUserTH1D("Me2j_selected_PAS"   , M_e2j1_new            , efficiency_weight * pileup_weight) ;
	 FillUserTH2D( "Me1jVsMe2j_selected", M_e1j2_new, M_e2j1_new, efficiency_weight * pileup_weight) ;
	 FillUserTH2D( "Me1jVsMe2j_rejected", M_e1j1_new, M_e2j2_new, efficiency_weight * pileup_weight) ;
       }
       
       if ( passed_250 ) {
	 FillUserTH1D("Mej_selected_avg_LQ250", M_ej_avg    , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("Mej_selected_min_LQ250", M_ej_min    , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("sT_eejj_LQ250"         , sT_eejj_new , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("Mee_LQ250"             , M_e1e2_new  , efficiency_weight * pileup_weight  ) ;
       }

       if ( passed_350 ) {
	 FillUserTH1D("Mej_selected_avg_LQ350", M_ej_avg    , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("Mej_selected_min_LQ350", M_ej_min    , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("sT_eejj_LQ350"         , sT_eejj_new , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("Mee_LQ350"             , M_e1e2_new  , efficiency_weight * pileup_weight  ) ;
       }

       if ( passed_400 ) {
	 FillUserTH1D("Mej_selected_avg_LQ400", M_ej_avg    , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("Mej_selected_min_LQ400", M_ej_min    , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("sT_eejj_LQ400"         , sT_eejj_new , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("Mee_LQ400"             , M_e1e2_new  , efficiency_weight * pileup_weight  ) ;
       }

       if ( passed_450 ) {
	 FillUserTH1D("Mej_selected_avg_LQ450", M_ej_avg    , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("Mej_selected_min_LQ450", M_ej_min    , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("sT_eejj_LQ450"         , sT_eejj_new , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("Mee_LQ450"             , M_e1e2_new  , efficiency_weight * pileup_weight  ) ;
       }

       if ( passed_500 ) {
	 FillUserTH1D("Mej_selected_avg_LQ500", M_ej_avg    , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("Mej_selected_min_LQ500", M_ej_min    , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("sT_eejj_LQ500"         , sT_eejj_new , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("Mee_LQ500"             , M_e1e2_new  , efficiency_weight * pileup_weight  ) ;
       }

       if ( passed_550 ) {
	 FillUserTH1D("Mej_selected_avg_LQ550", M_ej_avg    , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("Mej_selected_min_LQ550", M_ej_min    , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("sT_eejj_LQ550"         , sT_eejj_new , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("Mee_LQ550"             , M_e1e2_new  , efficiency_weight * pileup_weight  ) ;
       }

       if ( passed_600 ) {
	 FillUserTH1D("Mej_selected_avg_LQ600", M_ej_avg    , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("Mej_selected_min_LQ600", M_ej_min    , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("sT_eejj_LQ600"         , sT_eejj_new , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("Mee_LQ600"             , M_e1e2_new  , efficiency_weight * pileup_weight  ) ;
       }

       if ( passed_650 ) {
	 FillUserTH1D("Mej_selected_avg_LQ650", M_ej_avg    , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("Mej_selected_min_LQ650", M_ej_min    , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("sT_eejj_LQ650"         , sT_eejj_new , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("Mee_LQ650"             , M_e1e2_new  , efficiency_weight * pileup_weight  ) ;
       }

       if ( passed_750 ) {
	 FillUserTH1D("Mej_selected_avg_LQ750", M_ej_avg    , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("Mej_selected_min_LQ750", M_ej_min    , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("sT_eejj_LQ750"         , sT_eejj_new , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("Mee_LQ750"             , M_e1e2_new  , efficiency_weight * pileup_weight  ) ;
       }

       if ( passed_850 ) {
	 FillUserTH1D("Mej_selected_avg_LQ850", M_ej_avg    , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("Mej_selected_min_LQ850", M_ej_min    , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("sT_eejj_LQ850"         , sT_eejj_new , efficiency_weight * pileup_weight  ) ;
	 FillUserTH1D("Mee_LQ850"             , M_e1e2_new  , efficiency_weight * pileup_weight  ) ;
       }
     }
   } // End loop over events

   
   output_root_ -> cd();
   profile_run_vs_nvtx_HLT -> Write();
   profile_run_vs_nvtx_PAS -> Write();
   
   std::cout << "analysisClass::Loop() ends" <<std::endl;   
}
void analysisClass::Loop()
{
    std::cout << "analysisClass::Loop() begins" <<std::endl;

    //--------------------------------------------------------------------------
    // Decide which plots to save (default is to save everything)
    //--------------------------------------------------------------------------

    fillSkim                         (  true  ) ;
    fillAllPreviousCuts              (  true  ) ;
    fillAllOtherCuts                 ( !true  ) ;
    fillAllSameLevelAndLowerLevelCuts( !true  ) ;
    fillAllCuts                      ( !true  ) ;

    //--------------------------------------------------------------------------
    // Get pre-cut values
    //--------------------------------------------------------------------------

    // fake rates

    int qcd_fit_function_version      = getPreCutValue1 ("QCD_fit_func_version" );
    std::string qcd_file_name         = getPreCutString1("QCD_file");
    std::string qcd_barrel_plot_name  = getPreCutString1("QCD_barrel_plot" );
    std::string qcd_endcap1_plot_name = getPreCutString1("QCD_endcap1_plot");
    std::string qcd_endcap2_plot_name = getPreCutString1("QCD_endcap2_plot");

    qcdFitter * fitter = new qcdFitter(qcd_fit_function_version,
                                       qcd_file_name           ,
                                       qcd_barrel_plot_name    ,
                                       qcd_endcap1_plot_name   ,
                                       qcd_endcap2_plot_name    );
    fitter -> print();

    // override the fake rate?
    double fakeRate_override = getPreCutValue1("fakeRate_override");
    bool override_fakeRate = ( fakeRate_override > 0.0 );

    //--------------------------------------------------------------------------
    // Create TH1D's
    //--------------------------------------------------------------------------

    CreateUserTH1D( "nElectron_PAS"         ,    5   , -0.5    , 4.5      );
    CreateUserTH1D( "nMuon_PAS"             ,    5   , -0.5    , 4.5      );
    CreateUserTH1D( "nJet_PAS"              ,    10  , -0.5    , 9.5      );
    CreateUserTH1D( "Pt1stEle_PAS"	   , 	100 , 0       , 1000     );
    CreateUserTH1D( "Eta1stEle_PAS"	   , 	100 , -5      , 5	 );
    CreateUserTH1D( "Phi1stEle_PAS"	   , 	60  , -3.1416 , +3.1416	 );
    CreateUserTH1D( "Pt2ndEle_PAS"	   , 	100 , 0       , 1000     );
    CreateUserTH1D( "Eta2ndEle_PAS"	   , 	100 , -5      , 5	 );
    CreateUserTH1D( "Phi2ndEle_PAS"	   , 	60  , -3.1416 , +3.1416	 );
    CreateUserTH1D( "Charge1stEle_PAS"	   , 	2   , -1.0001 , 1.0001	 );
    CreateUserTH1D( "Charge2ndEle_PAS"	   , 	2   , -1.0001 , 1.0001	 );
    CreateUserTH1D( "MET_PAS"               ,    200 , 0       , 1000	 );
    CreateUserTH1D( "METPhi_PAS"		   , 	60  , -3.1416 , +3.1416	 );
    CreateUserTH1D( "Pt1stJet_PAS"          ,    100 , 0       , 1000	 );
    CreateUserTH1D( "Eta1stJet_PAS"         ,    100 , -5      , 5	 );
    CreateUserTH1D( "Phi1stJet_PAS"	   , 	60  , -3.1416 , +3.1416	 );
    CreateUserTH1D( "sT_PAS"                ,    200 , 0       , 2000	 );
    CreateUserTH1D( "Mee_PAS"		   ,    200 , 0       , 2000	 );
    CreateUserTH1D( "Me1j1_PAS"		   ,    200 , 0       , 2000	 );
    CreateUserTH1D( "Me2j1_PAS"		   ,    200 , 0       , 2000	 );
    CreateUserTH1D( "Meejj_PAS"             ,    200 , 0       , 2000     );
    CreateUserTH1D( "Ptee_PAS"              ,    200 , 0       , 2000     );


    CreateUserTH1D( "nVertex_PAS"           ,    31   , -0.5   , 30.5	 ) ;

    CreateUserTH1D( "DR_Ele1Jet1_PAS"	   , 	getHistoNBins("DR_Ele1Jet1"), getHistoMin("DR_Ele1Jet1"), getHistoMax("DR_Ele1Jet1")     ) ;
    CreateUserTH1D( "DR_Ele2Jet1_PAS"	   , 	getHistoNBins("DR_Ele2Jet1"), getHistoMin("DR_Ele2Jet1"), getHistoMax("DR_Ele2Jet1")     ) ;

    //--------------------------------------------------------------------------
    // Loop over the chain
    //--------------------------------------------------------------------------

    if (fChain == 0) return;

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

    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 << "/" << nentries << std::endl;

        //--------------------------------------------------------------------------
        // Reset the cuts
        //--------------------------------------------------------------------------

        resetCuts();

        //--------------------------------------------------------------------------
        // Check good run list
        //--------------------------------------------------------------------------

        int    passedJSON = passJSON ( run, ls , isData ) ;

        //--------------------------------------------------------------------------
        // Do pileup re-weighting
        //--------------------------------------------------------------------------

        double pileup_weight = getPileupWeight ( nPileUpInt_True, isData ) ;

        //--------------------------------------------------------------------------
        // Trigger
        //--------------------------------------------------------------------------

        short min_prescale = 0;
        int passTrigger = 0;

        if ( isData ) {

            if ( LooseEle1_hltPhotonPt > 0.0 ) {
                if ( H_Photon30_CIdVL > 0.1 && LooseEle1_hltPhotonPt >= 30.  && LooseEle1_hltPhotonPt < 50. ) {
                    passTrigger = 1;
                    min_prescale = H_Photon30_CIdVL;
                }
                if ( H_Photon50_CIdVL > 0.1 && LooseEle1_hltPhotonPt >= 50.  && LooseEle1_hltPhotonPt < 75. ) {
                    passTrigger = 1;
                    min_prescale = H_Photon50_CIdVL;
                }
                if ( H_Photon75_CIdVL > 0.1 && LooseEle1_hltPhotonPt >= 75.  && LooseEle1_hltPhotonPt < 90. ) {
                    passTrigger = 1;
                    min_prescale = H_Photon75_CIdVL;
                }
                if ( H_Photon90_CIdVL > 0.1 && LooseEle1_hltPhotonPt >= 90.  && LooseEle1_hltPhotonPt < 135.) {
                    passTrigger = 1;
                    min_prescale = H_Photon90_CIdVL;
                }
                if ( H_Photon135      > 0.1 && LooseEle1_hltPhotonPt >= 135. && LooseEle1_hltPhotonPt < 150.) {
                    passTrigger = 1;
                    min_prescale = H_Photon135     ;
                }
                if ( H_Photon150      > 0.1 && LooseEle1_hltPhotonPt >= 150.                                ) {
                    passTrigger = 1;
                    min_prescale = H_Photon150     ;
                }
            }

        }  // end if (isData)

        else {
            min_prescale = 1;
            passTrigger = 1 ;
        }

        //--------------------------------------------------------------------------
        // Calculate the fake rate
        //--------------------------------------------------------------------------

        double fakeRate1  = fitter -> getFakeRate    ( LooseEle1_Pt, LooseEle1_Eta );
        double fakeRate2  = fitter -> getFakeRate    ( LooseEle2_Pt, LooseEle2_Eta );
        double eFakeRate1 = fitter -> getFakeRateErr ( LooseEle1_Pt, LooseEle1_Eta );
        double eFakeRate2 = fitter -> getFakeRateErr ( LooseEle2_Pt, LooseEle2_Eta );

        double fakeRateEffective  = fakeRate1 + fakeRate2;
        double eFakeRateEffective = sqrt ( ( eFakeRate1 * eFakeRate1 ) +
                                           ( eFakeRate2 * eFakeRate2 ) );

        // fakeRateEffective += eFakeRateEffective;

        //--------------------------------------------------------------------------
        // User has the option to use a flat fake rate (e.g. 1.0 = no fake rate)
        //--------------------------------------------------------------------------

        if ( override_fakeRate ) fakeRateEffective = fakeRate_override;

        //--------------------------------------------------------------------------
        // How many loose electrons have HEEP ID?
        //--------------------------------------------------------------------------

        int nPass = 0;
        if ( LooseEle1_PassID == 1 ) nPass ++;
        if ( LooseEle2_PassID == 1 ) nPass ++;

        //--------------------------------------------------------------------------
        // Calculate a few missing variables
        //--------------------------------------------------------------------------

        TLorentzVector loose_ele1, loose_ele2 , jet1, jet2;
        loose_ele1.SetPtEtaPhiM ( LooseEle1_Pt , LooseEle1_Eta , LooseEle1_Phi , 0.0 );
        loose_ele2.SetPtEtaPhiM ( LooseEle2_Pt , LooseEle2_Eta , LooseEle2_Phi , 0.0 );
        jet1.SetPtEtaPhiM       ( JetLooseEle1_Pt, JetLooseEle1_Eta, JetLooseEle1_Phi, 0.0 );
        jet2.SetPtEtaPhiM       ( JetLooseEle2_Pt, JetLooseEle2_Eta, JetLooseEle2_Phi, 0.0 );

        TLorentzVector loose_e1e2 = loose_ele1 + loose_ele2;
        TLorentzVector j1j2 = jet1 + jet2;

        TLorentzVector e1j1 = loose_ele1 + jet1;
        TLorentzVector e2j1 = loose_ele2 + jet1;

        //--------------------------------------------------------------------------
        // Now fill cut values
        // DON'T use the pileup weight ... it's included by default
        // DO    use the prescale.  It's already 1.0 for MC.
        // DO    use the effective fake rate.  It will only mean anything when you run
        //       over data, though, so be sure to override it to 1.0
        //       if you run over Monte Carlo
        //--------------------------------------------------------------------------


        //--------------------------------------------------------------------------
        // Fill variables
        //--------------------------------------------------------------------------

        // JSON variable
        fillVariableWithValue(   "PassJSON"                      , passedJSON ) ;

        // Noise filters
        fillVariableWithValue(   "PassHBHENoiseFilter"           , PassHBHENoiseFilter ) ;
        fillVariableWithValue(   "PassBeamHaloFilterTight"       , PassBeamHaloFilterTight ) ;

        //--------------------------------------------------------------------------
        // MET filters
        //--------------------------------------------------------------------------

        fillVariableWithValue(   "PassHBHENoiseFilter"	      , PassHBHENoiseFilter                              , pileup_weight * min_prescale  * fakeRateEffective);
        fillVariableWithValue(   "PassBeamHaloFilterTight"       , PassBeamHaloFilterTight                          , pileup_weight * min_prescale  * fakeRateEffective);
        fillVariableWithValue(   "PassBadEESupercrystalFilter"   , ( isData == 1 ) ? PassBadEESupercrystalFilter : 1, pileup_weight * min_prescale  * fakeRateEffective);
        fillVariableWithValue(   "PassBeamScraping"	      , ( isData == 1 ) ? PassBeamScraping	      : 1, pileup_weight * min_prescale  * fakeRateEffective);
        fillVariableWithValue(   "PassEcalDeadCellBoundEnergy"   , PassEcalDeadCellBoundEnergy                      , pileup_weight * min_prescale  * fakeRateEffective);
        fillVariableWithValue(   "PassEcalDeadCellTrigPrim"      , PassEcalDeadCellTrigPrim                         , pileup_weight * min_prescale  * fakeRateEffective);
        fillVariableWithValue(   "PassEcalLaserCorrFilter"       , ( isData == 1 ) ? PassEcalLaserCorrFilter     : 1, pileup_weight * min_prescale  * fakeRateEffective);
        fillVariableWithValue(   "PassPhysDecl"		      , ( isData == 1 ) ? PassPhysDecl		      : 1, pileup_weight * min_prescale  * fakeRateEffective);
        fillVariableWithValue(   "PassPrimaryVertex"	      , PassPrimaryVertex                                , pileup_weight * min_prescale  * fakeRateEffective);
        fillVariableWithValue(   "PassTrackingFailure"	      , ( isData == 1 ) ? PassTrackingFailure	      : 1, pileup_weight * min_prescale  * fakeRateEffective);


        fillVariableWithValue ( "PassHLT", passTrigger, pileup_weight * min_prescale * fakeRateEffective ) ;
        fillVariableWithValue ( "PFMET"  , PFMET_Type01XY_Pt, pileup_weight * min_prescale * fakeRateEffective ) ;

        // Electrons
        fillVariableWithValue(   "nEleLoose"                     , nLooseEle_ptCut     , pileup_weight * min_prescale  * fakeRateEffective );
        fillVariableWithValue(   "nEleTight"                     , nPass            , pileup_weight * min_prescale  * fakeRateEffective );
        if ( nLooseEle_ptCut >= 1 ) {
            fillVariableWithValue( "Ele1_Pt"                       , LooseEle1_Pt   , pileup_weight * min_prescale  * fakeRateEffective ) ;
            fillVariableWithValue( "Ele1_Eta"                      , LooseEle1_Eta  , pileup_weight * min_prescale  * fakeRateEffective ) ;
        }
        if ( nLooseEle_ptCut >= 2 ) {
            fillVariableWithValue( "Ele2_Pt"                       , LooseEle2_Pt   , pileup_weight * min_prescale  * fakeRateEffective ) ;
            fillVariableWithValue( "Ele2_Eta"                      , LooseEle2_Eta  , pileup_weight * min_prescale  * fakeRateEffective ) ;
            fillVariableWithValue( "M_e1e2"                        , loose_e1e2.M()   , pileup_weight * min_prescale  * fakeRateEffective );
            fillVariableWithValue( "Pt_e1e2"                       , loose_e1e2.Pt()  , pileup_weight * min_prescale  * fakeRateEffective );
        }

        // Jets
        fillVariableWithValue(   "nJet"                          , nJetLooseEle_ptCut , pileup_weight * min_prescale  * fakeRateEffective );
        if ( nJetLooseEle_store >= 1 ) {
            fillVariableWithValue( "Jet1_Pt"                       , JetLooseEle1_Pt   , pileup_weight * min_prescale  * fakeRateEffective ) ;
            fillVariableWithValue( "Jet1_Eta"                      , JetLooseEle1_Eta , pileup_weight * min_prescale  * fakeRateEffective ) ;
        }

        // Muons
        fillVariableWithValue(   "nMuon"                         , nMuon_ptCut           , pileup_weight * min_prescale  * fakeRateEffective );

        // DeltaR
        if ( nLooseEle_ptCut >= 2 && nJetLooseEle_store >= 1) {
            double st = LooseEle1_Pt + LooseEle2_Pt + JetLooseEle1_Pt ;
            fillVariableWithValue( "DR_Ele1Jet1"                   , loose_ele1.DeltaR ( jet1 ), pileup_weight * min_prescale  * fakeRateEffective );
            fillVariableWithValue( "DR_Ele2Jet1"                   , loose_ele2.DeltaR ( jet1 ), pileup_weight * min_prescale  * fakeRateEffective );
            fillVariableWithValue( "sT_eej_200"                    , st                        , pileup_weight * min_prescale  * fakeRateEffective );
            fillVariableWithValue( "sT_eej_450"                    , st                        , pileup_weight * min_prescale  * fakeRateEffective );
            fillVariableWithValue( "sT_eej_850"                    , st                        , pileup_weight * min_prescale  * fakeRateEffective );
        }

        //--------------------------------------------------------------------------
        // Evaluate the cuts
        //--------------------------------------------------------------------------

        evaluateCuts();

        //--------------------------------------------------------------------------
        // Fill preselection plots
        // DO    use the pileup weight.  It's equal to 1.0 for data.
        // DO    use the min_prescale.  It's equal to 1.0 for Monte Carlo
        // DO    use the effective fake rate.  It will only mean anything when you run
        //       over data, though, so be sure to override it to 1.0
        //       if you run over Monte Carlo
        //--------------------------------------------------------------------------

        bool passed_preselection = ( passedAllPreviousCuts("sT_eej_200") && passedCut ("sT_eej_200") );

        if ( passed_preselection ) {

            double sT_eej = LooseEle1_Pt + LooseEle2_Pt + JetLooseEle1_Pt ;

            FillUserTH1D("nElectron_PAS"        , nLooseEle_ptCut           , pileup_weight * min_prescale * fakeRateEffective );
            FillUserTH1D("nMuon_PAS"            , nMuon_ptCut               , pileup_weight * min_prescale * fakeRateEffective );
            FillUserTH1D("nJet_PAS"             , nJetLooseEle_ptCut        , pileup_weight * min_prescale * fakeRateEffective );
            FillUserTH1D("Pt1stEle_PAS"	   , LooseEle1_Pt              , pileup_weight * min_prescale * fakeRateEffective );
            FillUserTH1D("Eta1stEle_PAS"	   , LooseEle1_Eta             , pileup_weight * min_prescale * fakeRateEffective );
            FillUserTH1D("Phi1stEle_PAS"	   , LooseEle1_Phi             , pileup_weight * min_prescale * fakeRateEffective );
            FillUserTH1D("Pt2ndEle_PAS"	   , LooseEle2_Pt              , pileup_weight * min_prescale * fakeRateEffective );
            FillUserTH1D("Eta2ndEle_PAS"	   , LooseEle2_Eta             , pileup_weight * min_prescale * fakeRateEffective );
            FillUserTH1D("Phi2ndEle_PAS"	   , LooseEle2_Phi             , pileup_weight * min_prescale * fakeRateEffective );
            FillUserTH1D("Charge1stEle_PAS"	   , LooseEle1_Charge          , pileup_weight * min_prescale * fakeRateEffective );
            FillUserTH1D("Charge2ndEle_PAS"	   , LooseEle2_Charge          , pileup_weight * min_prescale * fakeRateEffective );
            FillUserTH1D("MET_PAS"              , PFMET_Type01XY_Pt         , pileup_weight * min_prescale * fakeRateEffective );
            FillUserTH1D("METPhi_PAS"	   , PFMET_Type01XY_Phi        , pileup_weight * min_prescale * fakeRateEffective );
            FillUserTH1D("Pt1stJet_PAS"         , JetLooseEle1_Pt           , pileup_weight * min_prescale * fakeRateEffective );
            FillUserTH1D("Eta1stJet_PAS"        , JetLooseEle1_Eta          , pileup_weight * min_prescale * fakeRateEffective );
            FillUserTH1D("Phi1stJet_PAS"	   , JetLooseEle1_Phi          , pileup_weight * min_prescale * fakeRateEffective );
            FillUserTH1D("sT_PAS"               , sT_eej                    , pileup_weight * min_prescale * fakeRateEffective );
            FillUserTH1D("Mee_PAS"		   , loose_e1e2.M()            , pileup_weight * min_prescale * fakeRateEffective );
            FillUserTH1D("Ptee_PAS"             , loose_e1e2.Pt()           , pileup_weight * min_prescale * fakeRateEffective );
            FillUserTH1D("nVertex_PAS"          , nVertex                   , pileup_weight * min_prescale * fakeRateEffective );
            FillUserTH1D("DR_Ele1Jet1_PAS"	   , loose_ele1.DeltaR ( jet1 ), pileup_weight * min_prescale * fakeRateEffective );
            FillUserTH1D("DR_Ele2Jet1_PAS"	   , loose_ele2.DeltaR ( jet1 ), pileup_weight * min_prescale * fakeRateEffective );
            FillUserTH1D("Me1j1_PAS"            , e1j1.M()                  , pileup_weight * min_prescale * fakeRateEffective );
            FillUserTH1D("Me2j1_PAS"            , e2j1.M()                  , pileup_weight * min_prescale * fakeRateEffective );
        }
    } // End loop over events

    std::cout << "analysisClass::Loop() ends" <<std::endl;
}
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;   
}
void analysisClass::Loop()
{
   std::cout << "analysisClass::Loop() begins" <<std::endl;   

   //--------------------------------------------------------------------------
   // Decide which plots to save (default is to save everything)
   //--------------------------------------------------------------------------
   
   fillSkim                         (  true  ) ;
   fillAllPreviousCuts              (  true  ) ;
   fillAllOtherCuts                 ( !true  ) ;
   fillAllSameLevelAndLowerLevelCuts( !true  ) ;
   fillAllCuts                      ( !true  ) ;

   //--------------------------------------------------------------------------
   // Get pre-cut values
   //--------------------------------------------------------------------------

   // eta boundaries

   double eleEta_bar            = getPreCutValue1("eleEta_bar");
   double eleEta_end1_min       = getPreCutValue1("eleEta_end1");
   double eleEta_end1_max       = getPreCutValue2("eleEta_end1");
   double eleEta_end2_min       = getPreCutValue1("eleEta_end2");
   double eleEta_end2_max       = getPreCutValue2("eleEta_end2");

   // fake rates
   
   double fakeRate_low_bar_p0    = getPreCutValue1 ( "fakeRate_bar"  );
   double fakeRate_low_bar_p1    = getPreCutValue2 ( "fakeRate_bar"  );
   double fakeRate_high_bar_p0   = getPreCutValue3 ( "fakeRate_bar"  );
				 
   double fakeRate_low_end1_p0   = getPreCutValue1 ( "fakeRate_end1" );
   double fakeRate_low_end1_p1   = getPreCutValue2 ( "fakeRate_end1" );
   double fakeRate_high_end1_p0  = getPreCutValue3 ( "fakeRate_end1" );
				 
   double fakeRate_low_end2_p0   = getPreCutValue1 ( "fakeRate_end2" );
   double fakeRate_low_end2_p1   = getPreCutValue2 ( "fakeRate_end2" );
   double fakeRate_high_end2_p0  = getPreCutValue3 ( "fakeRate_end2" );
   
   double eFakeRate_low_bar_p0   = getPreCutValue1 ( "eFakeRate_bar" );
   double eFakeRate_low_bar_p1   = getPreCutValue2 ( "eFakeRate_bar" );
   double eFakeRate_high_bar_p0  = getPreCutValue3 ( "eFakeRate_bar" );

   double eFakeRate_low_end1_p0  = getPreCutValue1 ( "eFakeRate_end1");
   double eFakeRate_low_end1_p1  = getPreCutValue2 ( "eFakeRate_end1");
   double eFakeRate_high_end1_p0 = getPreCutValue3 ( "eFakeRate_end1");

   double eFakeRate_low_end2_p0  = getPreCutValue1 ( "eFakeRate_end2");
   double eFakeRate_low_end2_p1  = getPreCutValue2 ( "eFakeRate_end2");
   double eFakeRate_high_end2_p0 = getPreCutValue3 ( "eFakeRate_end2");

   // trigger requirements
    
   double trigger_tolerance = getPreCutValue1("trigger_tolerance"); 

   // override the fake rate?
   double fakeRate_override = getPreCutValue1("fakeRate_override");
   bool override_fakeRate = ( fakeRate_override > 0.0 );

   //--------------------------------------------------------------------------
   // Create TH1D's
   //--------------------------------------------------------------------------
   
   CreateUserTH1D( "nElectron_PAS"         ,    5   , -0.5    , 4.5      );
   CreateUserTH1D( "nMuon_PAS"             ,    5   , -0.5    , 4.5      );
   CreateUserTH1D( "nJet_PAS"              ,    10  , -0.5    , 9.5      );
   CreateUserTH1D( "Pt1stEle_PAS"	   , 	100 , 0       , 1000     ); 
   CreateUserTH1D( "Eta1stEle_PAS"	   , 	100 , -5      , 5	 ); 
   CreateUserTH1D( "Phi1stEle_PAS"	   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "Pt2ndEle_PAS"	   , 	100 , 0       , 1000     ); 
   CreateUserTH1D( "Eta2ndEle_PAS"	   , 	100 , -5      , 5	 ); 
   CreateUserTH1D( "Phi2ndEle_PAS"	   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "Charge1stEle_PAS"	   , 	2   , -1.0001 , 1.0001	 ); 
   CreateUserTH1D( "Charge2ndEle_PAS"	   , 	2   , -1.0001 , 1.0001	 ); 
   CreateUserTH1D( "MET_PAS"               ,    200 , 0       , 1000	 ); 
   CreateUserTH1D( "METPhi_PAS"		   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "METCharged_PAS"        ,    200 , 0       , 1000	 ); 
   CreateUserTH1D( "METChargedPhi_PAS"	   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "METType1_PAS"          ,    200 , 0       , 1000	 ); 
   CreateUserTH1D( "METType1Phi_PAS"	   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "Pt1stJet_PAS"          ,    100 , 0       , 1000	 ); 
   CreateUserTH1D( "Eta1stJet_PAS"         ,    100 , -5      , 5	 ); 
   CreateUserTH1D( "Phi1stJet_PAS"	   , 	60  , -3.1416 , +3.1416	 ); 
   CreateUserTH1D( "sT_PAS"                ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Mee_PAS"		   ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Me1j1_PAS"		   ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Me2j1_PAS"		   ,    200 , 0       , 2000	 ); 
   CreateUserTH1D( "Meejj_PAS"             ,    200 , 0       , 2000     );
   CreateUserTH1D( "Ptee_PAS"              ,    200 , 0       , 2000     );
   		                           
		                           
   CreateUserTH1D( "nVertex_PAS"           ,    31   , -0.5   , 30.5	 ) ; 
   CreateUserTH1D( "nVertex_good_PAS"      ,    31   , -0.5   , 30.5	 ) ; 
		                           
   CreateUserTH1D( "DR_Ele1Jet1_PAS"	   , 	getHistoNBins("DR_Ele1Jet1"), getHistoMin("DR_Ele1Jet1"), getHistoMax("DR_Ele1Jet1")     ) ; 
   CreateUserTH1D( "DR_Ele2Jet1_PAS"	   , 	getHistoNBins("DR_Ele2Jet1"), getHistoMin("DR_Ele2Jet1"), getHistoMax("DR_Ele2Jet1")     ) ; 

   //--------------------------------------------------------------------------
   // Loop over the chain
   //--------------------------------------------------------------------------

   if (fChain == 0) return;
   
   Long64_t nentries = fChain->GetEntries();
   std::cout << "analysisClass::Loop(): nentries = " << nentries << std::endl;   

   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 << "/" << nentries << std::endl;   

     //--------------------------------------------------------------------------
     // Reset the cuts
     //--------------------------------------------------------------------------

     resetCuts();

     //--------------------------------------------------------------------------
     // Check good run list
     //--------------------------------------------------------------------------
     
     int    passedJSON = passJSON ( run, ls , isData ) ;

     //--------------------------------------------------------------------------
     // Do pileup re-weighting
     //--------------------------------------------------------------------------
     
     int NPILEUP_AVE = int( nPileUpInt_BX0 );
     int NPILEUP_FINAL = min( NPILEUP_AVE , 25 );
     double pileup_weight = getPileupWeight ( NPILEUP_FINAL, isData ) ;

     //--------------------------------------------------------------------------
     // Fill variables
     //--------------------------------------------------------------------------

     // JSON variable
     fillVariableWithValue(   "PassJSON"                      , passedJSON ) ; 

     // Noise filters
     fillVariableWithValue(   "PassHBHENoiseFilter"           , PassHBHENoiseFilter ) ; 
     fillVariableWithValue(   "PassBeamHaloFilterTight"       , PassBeamHaloFilterTight ) ; 

     //--------------------------------------------------------------------------
     // Trigger
     //--------------------------------------------------------------------------

     int min_prescale;
     int passTrigger;
     std::string min_prescale_name;

     if ( isData ) {

       //--------------------------------------------------------------------------
       // 7 trigger paths (some with multiple versions)
       //--------------------------------------------------------------------------

       // Number of times a path fired per event ( should be 0 or 1 )

       int N_Photon30_CIdVL  = 0;
       int N_Photon50_CIdVL  = 0;
       int N_Photon75_CIdVL  = 0;
       int N_Photon90_CIdVL  = 0;
       int N_Photon125       = 0;
       int N_Photon135       = 0;
       int N_Photon400       = 0;

       // Trigger prescale in an event
       
       int PS_Photon30_CIdVL = 0;
       int PS_Photon50_CIdVL = 0;
       int PS_Photon75_CIdVL = 0;
       int PS_Photon90_CIdVL = 0;
       int PS_Photon125      = 0;
       int PS_Photon135      = 0;
       int PS_Photon400      = 0;

       //--------------------------------------------------------------------------
       // Find the right prescale for this event
       //--------------------------------------------------------------------------
       
       // Did the HLT_Photon30_CaloIdVL trigger fire?

       if ( H_Photon30_CIdVL_1 > 0 && H_Photon30_CIdVL_1 != 999 ) { N_Photon30_CIdVL++; PS_Photon30_CIdVL = H_Photon30_CIdVL_1; } 
       if ( H_Photon30_CIdVL_2 > 0 && H_Photon30_CIdVL_2 != 999 ) { N_Photon30_CIdVL++; PS_Photon30_CIdVL = H_Photon30_CIdVL_2; } 
       if ( H_Photon30_CIdVL_3 > 0 && H_Photon30_CIdVL_3 != 999 ) { N_Photon30_CIdVL++; PS_Photon30_CIdVL = H_Photon30_CIdVL_3; } 
       if ( H_Photon30_CIdVL_4 > 0 && H_Photon30_CIdVL_4 != 999 ) { N_Photon30_CIdVL++; PS_Photon30_CIdVL = H_Photon30_CIdVL_4; } 
       if ( H_Photon30_CIdVL_5 > 0 && H_Photon30_CIdVL_5 != 999 ) { N_Photon30_CIdVL++; PS_Photon30_CIdVL = H_Photon30_CIdVL_5; } 
       if ( H_Photon30_CIdVL_6 > 0 && H_Photon30_CIdVL_6 != 999 ) { N_Photon30_CIdVL++; PS_Photon30_CIdVL = H_Photon30_CIdVL_6; } 
       if ( H_Photon30_CIdVL_7 > 0 && H_Photon30_CIdVL_7 != 999 ) { N_Photon30_CIdVL++; PS_Photon30_CIdVL = H_Photon30_CIdVL_7; } 

       if ( isData && run > 175771 ) {
       	 if ( H_Photon30_CIdVL_8 > 0 && H_Photon30_CIdVL_8 != 999 ) { N_Photon30_CIdVL++; PS_Photon30_CIdVL = H_Photon30_CIdVL_8; }
       }

       // Did the HLT_Photon50_CaloIdVL trigger fire?
       
       if ( H_Photon50_CIdVL_1 > 0 && H_Photon50_CIdVL_1 != 999 ) { N_Photon50_CIdVL++; PS_Photon50_CIdVL = H_Photon50_CIdVL_1; } 
       if ( H_Photon50_CIdVL_2 > 0 && H_Photon50_CIdVL_2 != 999 ) { N_Photon50_CIdVL++; PS_Photon50_CIdVL = H_Photon50_CIdVL_2; } 
       if ( H_Photon50_CIdVL_3 > 0 && H_Photon50_CIdVL_3 != 999 ) { N_Photon50_CIdVL++; PS_Photon50_CIdVL = H_Photon50_CIdVL_3; } 
       if ( H_Photon50_CIdVL_4 > 0 && H_Photon50_CIdVL_4 != 999 ) { N_Photon50_CIdVL++; PS_Photon50_CIdVL = H_Photon50_CIdVL_4; } 

       // Did the HLT_Photon75_CaloIdVL trigger fire?
       
       if ( H_Photon75_CIdVL_1 > 0 && H_Photon75_CIdVL_1 != 999 ) { N_Photon75_CIdVL++; PS_Photon75_CIdVL = H_Photon75_CIdVL_1; } 
       if ( H_Photon75_CIdVL_2 > 0 && H_Photon75_CIdVL_2 != 999 ) { N_Photon75_CIdVL++; PS_Photon75_CIdVL = H_Photon75_CIdVL_2; } 
       if ( H_Photon75_CIdVL_3 > 0 && H_Photon75_CIdVL_3 != 999 ) { N_Photon75_CIdVL++; PS_Photon75_CIdVL = H_Photon75_CIdVL_3; } 
       if ( H_Photon75_CIdVL_4 > 0 && H_Photon75_CIdVL_4 != 999 ) { N_Photon75_CIdVL++; PS_Photon75_CIdVL = H_Photon75_CIdVL_4; } 
       if ( H_Photon75_CIdVL_5 > 0 && H_Photon75_CIdVL_5 != 999 ) { N_Photon75_CIdVL++; PS_Photon75_CIdVL = H_Photon75_CIdVL_5; } 
       if ( H_Photon75_CIdVL_6 > 0 && H_Photon75_CIdVL_6 != 999 ) { N_Photon75_CIdVL++; PS_Photon75_CIdVL = H_Photon75_CIdVL_6; } 
       if ( H_Photon75_CIdVL_7 > 0 && H_Photon75_CIdVL_7 != 999 ) { N_Photon75_CIdVL++; PS_Photon75_CIdVL = H_Photon75_CIdVL_7; }

       // Did the HLT_Photon90_CaloIdVL trigger fire?
       
       if ( H_Photon90_CIdVL_1 > 0 && H_Photon90_CIdVL_1 != 999 ) { N_Photon90_CIdVL++; PS_Photon90_CIdVL = H_Photon90_CIdVL_1; } 
       if ( H_Photon90_CIdVL_2 > 0 && H_Photon90_CIdVL_2 != 999 ) { N_Photon90_CIdVL++; PS_Photon90_CIdVL = H_Photon90_CIdVL_2; } 
       if ( H_Photon90_CIdVL_3 > 0 && H_Photon90_CIdVL_3 != 999 ) { N_Photon90_CIdVL++; PS_Photon90_CIdVL = H_Photon90_CIdVL_3; } 
       if ( H_Photon90_CIdVL_4 > 0 && H_Photon90_CIdVL_4 != 999 ) { N_Photon90_CIdVL++; PS_Photon90_CIdVL = H_Photon90_CIdVL_4; } 

       // Did the HLT_Photon125 trigger fire?
       
       if ( H_Photon125_1      > 0 && H_Photon125_1      != 999 ) { N_Photon125     ++; PS_Photon125      = H_Photon125_1     ; } 
       if ( H_Photon125_2      > 0 && H_Photon125_2      != 999 ) { N_Photon125     ++; PS_Photon125      = H_Photon125_2     ; } 
   
       // Did the HLT_Photon135 trigger fire?

       if ( H_Photon135_1      > 0 && H_Photon135_1      != 999 ) { N_Photon135     ++; PS_Photon135      = H_Photon135_1     ; } 
       if ( H_Photon135_2      > 0 && H_Photon135_2      != 999 ) { N_Photon135     ++; PS_Photon135      = H_Photon135_2     ; } 
       
       // Did the HLT_Photon400 trigger fire?

       if ( H_Photon400_1      > 0 && H_Photon400_1      != 999 ) { N_Photon400     ++; PS_Photon400      = H_Photon400_1     ; } 
       
       if ( isData && run > 175771 ) {
       	 if ( H_Photon400_2      > 0 && H_Photon400_2      != 999 ) { N_Photon400     ++; PS_Photon400      = H_Photon400_2     ; }
       }
       
       // Sanity check: make sure two versions of the same trigger didn't fire in the same event (impossible)
              
       if ( N_Photon30_CIdVL > 1 ) { std::cout << "ERROR: trigger overlap in N_Photon30_CIdVL" << std::endl; exit (0); }
       if ( N_Photon50_CIdVL > 1 ) { std::cout << "ERROR: trigger overlap in N_Photon50_CIdVL" << std::endl; exit (0); }
       if ( N_Photon75_CIdVL > 1 ) { std::cout << "ERROR: trigger overlap in N_Photon75_CIdVL" << std::endl; exit (0); }
       if ( N_Photon90_CIdVL > 1 ) { std::cout << "ERROR: trigger overlap in N_Photon90_CIdVL" << std::endl; exit (0); }
       if ( N_Photon125      > 1 ) { std::cout << "ERROR: trigger overlap in N_Photon125"      << std::endl; exit (0); }
       if ( N_Photon135      > 1 ) { std::cout << "ERROR: trigger overlap in N_Photon135"      << std::endl; exit (0); }
       if ( N_Photon400      > 1 ) { std::cout << "ERROR: trigger overlap in N_Photon400"      << std::endl; exit (0); }
      
       // What is the lowest-prescale trigger that this electron could have fired?
 
       min_prescale      = 999999;
       min_prescale_name = std::string("");

       if ( N_Photon30_CIdVL != 0 && QCDFakeEle1_Pt > 30. * trigger_tolerance  && PS_Photon30_CIdVL <= min_prescale ) { min_prescale = PS_Photon30_CIdVL; min_prescale_name = std::string("PS_Photon30_CIdVL"); }
       if ( N_Photon50_CIdVL != 0 && QCDFakeEle1_Pt > 50. * trigger_tolerance  && PS_Photon50_CIdVL <= min_prescale ) { min_prescale = PS_Photon50_CIdVL; min_prescale_name = std::string("PS_Photon50_CIdVL"); }
       if ( N_Photon75_CIdVL != 0 && QCDFakeEle1_Pt > 75. * trigger_tolerance  && PS_Photon75_CIdVL <= min_prescale ) { min_prescale = PS_Photon75_CIdVL; min_prescale_name = std::string("PS_Photon75_CIdVL"); }
       if ( N_Photon90_CIdVL != 0 && QCDFakeEle1_Pt > 90. * trigger_tolerance  && PS_Photon90_CIdVL <= min_prescale ) { min_prescale = PS_Photon90_CIdVL; min_prescale_name = std::string("PS_Photon90_CIdVL"); }
       if ( N_Photon125      != 0 && QCDFakeEle1_Pt > 125.* trigger_tolerance  && PS_Photon125      <= min_prescale ) { min_prescale = PS_Photon125     ; min_prescale_name = std::string("PS_Photon125"     ); }
       if ( N_Photon135      != 0 && QCDFakeEle1_Pt > 135.* trigger_tolerance  && PS_Photon135      <= min_prescale ) { min_prescale = PS_Photon135     ; min_prescale_name = std::string("PS_Photon135"     ); }
       if ( N_Photon400      != 0 && QCDFakeEle1_Pt > 400.* trigger_tolerance  && PS_Photon400      <= min_prescale ) { min_prescale = PS_Photon400     ; min_prescale_name = std::string("PS_Photon400"     ); }

       // If we find a suitable trigger, scale this event by that trigger's prescale

       passTrigger = 0;
       if ( min_prescale != 999999 ) { // if I found some suitable trigger that fired
	 passTrigger = 1;     
       } else {                        // if I was not able to find a suitable trigger that fired
	 min_prescale = 0;            
       }

     }  // end if (isData) 
					       
     else { // i.e., if this is Monte Carlo
       min_prescale = 1;
       passTrigger = 1 ;
     }


     //--------------------------------------------------------------------------
     // What kind of event is this?
     //  - EB-EB
     //  - EB-EE
     //  - EE-EE
     //--------------------------------------------------------------------------
     
     bool ele1_isBarrel  = false;
     bool ele1_isEndcap1 = false;
     bool ele1_isEndcap2 = false;
     bool ele2_isBarrel  = false;
     bool ele2_isEndcap1 = false;
     bool ele2_isEndcap2 = false;
     
     if( fabs( QCDFakeEle1_Eta  ) < eleEta_bar )        ele1_isBarrel  = true;
     if( fabs( QCDFakeEle1_Eta  ) > eleEta_end1_min &&
	 fabs( QCDFakeEle1_Eta  ) < eleEta_end1_max )   ele1_isEndcap1 = true;
     if( fabs( QCDFakeEle1_Eta  ) > eleEta_end2_min &&
	 fabs( QCDFakeEle1_Eta  ) < eleEta_end2_max )   ele1_isEndcap2 = true;

     if( fabs( QCDFakeEle2_Eta  ) < eleEta_bar )        ele2_isBarrel  = true;
     if( fabs( QCDFakeEle2_Eta  ) > eleEta_end1_min &&
	 fabs( QCDFakeEle2_Eta  ) < eleEta_end1_max )   ele2_isEndcap1 = true;
     if( fabs( QCDFakeEle2_Eta  ) > eleEta_end2_min &&
	 fabs( QCDFakeEle2_Eta  ) < eleEta_end2_max )   ele2_isEndcap2 = true;

     bool isEBEB   = ( ele1_isBarrel  && ele2_isBarrel  );
     bool isEBEE1  = ( ele1_isBarrel  && ele2_isEndcap1 );
     bool isEBEE2  = ( ele1_isBarrel  && ele2_isEndcap2 );

     bool isEE1EB  = ( ele1_isEndcap1 && ele2_isBarrel  );
     bool isEE1EE1 = ( ele1_isEndcap1 && ele2_isEndcap1 );
     bool isEE1EE2 = ( ele1_isEndcap1 && ele2_isEndcap2 );

     bool isEE2EB  = ( ele1_isEndcap2 && ele2_isBarrel  );
     bool isEE2EE1 = ( ele1_isEndcap2 && ele2_isEndcap1 );
     bool isEE2EE2 = ( ele1_isEndcap2 && ele2_isEndcap2 );

     bool isEBEE   = ( isEBEE1  || isEBEE2  || isEE1EB  || isEE2EB  );
     bool isEEEE   = ( isEE1EE1 || isEE1EE2 || isEE2EE1 || isEE2EE2 );

     //--------------------------------------------------------------------------
     // Determine which fake rates to use
     //--------------------------------------------------------------------------

     double fakeRate1  = 0.0;
     double fakeRate2  = 0.0;
     double eFakeRate1 = 0.0 ;
     double eFakeRate2 = 0.0;
     
     if ( QCDFakeEle1_Pt < 100 ){
       if ( ele1_isBarrel  ) {
	 fakeRate1  = fakeRate_low_bar_p0  + fakeRate_low_bar_p1  * QCDFakeEle1_Pt;
	 eFakeRate1 = sqrt ((( eFakeRate_low_bar_p1  * QCDFakeEle1_Pt       ) * 
			     ( eFakeRate_low_bar_p1  * QCDFakeEle1_Pt       )) + 
			    (( eFakeRate_low_bar_p0  * eFakeRate_low_bar_p0 ) * 
			     ( eFakeRate_low_bar_p0  * eFakeRate_low_bar_p0 )));
       }
       if ( ele1_isEndcap1 ) {
	 fakeRate1  = fakeRate_low_end1_p0 + fakeRate_low_end1_p1 * QCDFakeEle1_Pt;
	 eFakeRate1 = sqrt ((( eFakeRate_low_end1_p1  * QCDFakeEle1_Pt       ) * 
			     ( eFakeRate_low_end1_p1  * QCDFakeEle1_Pt       )) + 
			    (( eFakeRate_low_end1_p0  * eFakeRate_low_end1_p0 ) * 
			     ( eFakeRate_low_end1_p0  * eFakeRate_low_end1_p0 )));

       }
       if ( ele1_isEndcap2 ) {
	 fakeRate1 = fakeRate_low_end2_p0 + fakeRate_low_end2_p1 * QCDFakeEle1_Pt;
	 eFakeRate1 = sqrt ((( eFakeRate_low_end2_p1  * QCDFakeEle1_Pt       ) * 
			     ( eFakeRate_low_end2_p1  * QCDFakeEle1_Pt       )) + 
			    (( eFakeRate_low_end2_p0  * eFakeRate_low_end2_p0 ) * 
			     ( eFakeRate_low_end2_p0  * eFakeRate_low_end2_p0 )));
       } 
     }
     else if  ( QCDFakeEle1_Pt >= 100 ){
       if ( ele1_isBarrel  ) {
	 fakeRate1  = fakeRate_high_bar_p0  ;
	 eFakeRate1 = eFakeRate_high_bar_p0 ;
       }
       if ( ele1_isEndcap1 ) { 
	 fakeRate1 = fakeRate_high_end1_p0 ;
	 eFakeRate1 = eFakeRate_high_end1_p0 ;
       }
       if ( ele1_isEndcap2 ) {
	 fakeRate1 = fakeRate_high_end2_p0 ;
	 eFakeRate1 = eFakeRate_high_end2_p0 ;
       }
     }

     if ( QCDFakeEle2_Pt < 100 ){
       if ( ele1_isBarrel  ) {
	 fakeRate2  = fakeRate_low_bar_p0  + fakeRate_low_bar_p1  * QCDFakeEle2_Pt;
	 eFakeRate2 = sqrt ((( eFakeRate_low_bar_p1  * QCDFakeEle2_Pt       ) * 
			     ( eFakeRate_low_bar_p1  * QCDFakeEle2_Pt       )) + 
			    (( eFakeRate_low_bar_p0  * eFakeRate_low_bar_p0 ) * 
			     ( eFakeRate_low_bar_p0  * eFakeRate_low_bar_p0 )));
       }
       if ( ele1_isEndcap1 ) {
	 fakeRate2 = fakeRate_low_end1_p0 + fakeRate_low_end1_p1 * QCDFakeEle2_Pt;
	 eFakeRate2 = sqrt ((( eFakeRate_low_end1_p1  * QCDFakeEle2_Pt       ) * 
			     ( eFakeRate_low_end1_p1  * QCDFakeEle2_Pt       )) + 
			    (( eFakeRate_low_end1_p0  * eFakeRate_low_end1_p0 ) * 
			     ( eFakeRate_low_end1_p0  * eFakeRate_low_end1_p0 )));
       }
       if ( ele1_isEndcap2 ) {
	 fakeRate2 = fakeRate_low_end2_p0 + fakeRate_low_end2_p1 * QCDFakeEle2_Pt;
	 eFakeRate2 = sqrt ((( eFakeRate_low_end2_p1  * QCDFakeEle2_Pt       ) * 
			     ( eFakeRate_low_end2_p1  * QCDFakeEle2_Pt       )) + 
			    (( eFakeRate_low_end2_p0  * eFakeRate_low_end2_p0 ) * 
			     ( eFakeRate_low_end2_p0  * eFakeRate_low_end2_p0 )));
       }
     }

     else if  ( QCDFakeEle2_Pt >= 100 ){
       if ( ele1_isBarrel  ) {
	 fakeRate2  = fakeRate_high_bar_p0  ;
	 eFakeRate2 = eFakeRate_high_bar_p0;
       }
       if ( ele1_isEndcap1 ) { 
	 fakeRate2 = fakeRate_high_end1_p0 ;
	 eFakeRate2 = eFakeRate_high_end1_p0;
       }
       if ( ele1_isEndcap2 ) {
	 fakeRate2 = fakeRate_high_end2_p0 ;
	 eFakeRate2 = eFakeRate_high_end2_p0;
       }
     }

     //--------------------------------------------------------------------------
     // Finally have the effective fake rate
     //--------------------------------------------------------------------------

     double fakeRateEffective  = fakeRate1 + fakeRate2;
     double eFakeRateEffective = sqrt ( ( eFakeRate1 * eFakeRate1 ) +
					( eFakeRate2 * eFakeRate2 ) );

     // fakeRateEffective += eFakeRateEffective;

     //--------------------------------------------------------------------------
     // User has the option to use a flat fake rate (e.g. 1.0 = no fake rate)
     //--------------------------------------------------------------------------
     
     if ( override_fakeRate ) fakeRateEffective = fakeRate_override;

     //--------------------------------------------------------------------------
     // Bug: we don't have the number for number of loose jets stored... 
     // Have to derive it
     //--------------------------------------------------------------------------

     int nJetLooseEle_Stored = 0;
     if      ( JetLooseEle3_Pt > 10.0 ) nJetLooseEle_Stored = 3;
     else if ( JetLooseEle2_Pt > 10.0 ) nJetLooseEle_Stored = 2;
     else if ( JetLooseEle1_Pt > 10.0 ) nJetLooseEle_Stored = 1;
     else                               nJetLooseEle_Stored = 0;

     //--------------------------------------------------------------------------
     // How many loose electrons have HEEP ID?
     //--------------------------------------------------------------------------

     int nPass = 0;
     if ( QCDFakeEle1_PassID == 1 ) nPass ++;
     if ( QCDFakeEle2_PassID == 1 ) nPass ++;

     //--------------------------------------------------------------------------
     // Calculate a few missing variables
     //--------------------------------------------------------------------------

     TLorentzVector loose_ele1, loose_ele2 , jet1, jet2;
     loose_ele1.SetPtEtaPhiM ( QCDFakeEle1_Pt , QCDFakeEle1_Eta , QCDFakeEle1_Phi , 0.0 );
     loose_ele2.SetPtEtaPhiM ( QCDFakeEle2_Pt , QCDFakeEle2_Eta , QCDFakeEle2_Phi , 0.0 );
     jet1.SetPtEtaPhiM       ( JetLooseEle1_Pt, JetLooseEle1_Eta, JetLooseEle1_Phi, 0.0 );
     jet2.SetPtEtaPhiM       ( JetLooseEle2_Pt, JetLooseEle2_Eta, JetLooseEle2_Phi, 0.0 );

     TLorentzVector loose_e1e2 = loose_ele1 + loose_ele2;
     TLorentzVector j1j2 = jet1 + jet2;

     TLorentzVector e1j1 = loose_ele1 + jet1;
     TLorentzVector e2j1 = loose_ele2 + jet1;

     //--------------------------------------------------------------------------
     // Now fill cut values
     // DON'T use the pileup weight ... it's included by default
     // DO    use the prescale.  It's already 1.0 for MC.
     // DO    use the effective fake rate.  It will only mean anything when you run
     //       over data, though, so be sure to override it to 1.0 
     //       if you run over Monte Carlo
     //--------------------------------------------------------------------------
     
     fillVariableWithValue ( "PassHLT", passTrigger, min_prescale * fakeRateEffective ) ;
     
     // Electrons
     fillVariableWithValue(   "nEleLoose"                     , nEle_QCDFake     , min_prescale  * fakeRateEffective );
     fillVariableWithValue(   "nEleTight"                     , nPass            , min_prescale  * fakeRateEffective );
     if ( nEle_QCDFake >= 1 ) { 
       fillVariableWithValue( "Ele1_Pt"                       , QCDFakeEle1_Pt   , min_prescale  * fakeRateEffective ) ;
       fillVariableWithValue( "Ele1_Eta"                      , QCDFakeEle1_Eta  , min_prescale  * fakeRateEffective ) ;
     }
     if ( nEle_QCDFake >= 2 ) { 
       fillVariableWithValue( "Ele2_Pt"                       , QCDFakeEle2_Pt   , min_prescale  * fakeRateEffective ) ;
       fillVariableWithValue( "Ele2_Eta"                      , QCDFakeEle2_Eta  , min_prescale  * fakeRateEffective ) ;
       fillVariableWithValue( "M_e1e2"                        , loose_e1e2.M()   , min_prescale  * fakeRateEffective );
       fillVariableWithValue( "Pt_e1e2"                       , loose_e1e2.Pt()  , min_prescale  * fakeRateEffective );
     }

     // Jets
     fillVariableWithValue(   "nJet"                          , nJetLooseEle_Stored , min_prescale  * fakeRateEffective );
     if ( nJetLooseEle_Stored >= 1 ) {
       fillVariableWithValue( "Jet1_Pt"                       , JetLooseEle1_Pt   , min_prescale  * fakeRateEffective ) ;
       fillVariableWithValue( "Jet1_Eta"                      , JetLooseEle1_Eta , min_prescale  * fakeRateEffective ) ;
     }

     // Muons
     fillVariableWithValue(   "nMuon"                         , nMuon_Ana           , min_prescale  * fakeRateEffective ); 
										      			      
     // DeltaR
     if ( nEle_QCDFake >= 2 && nJetLooseEle_Stored >= 1) {
       double st = QCDFakeEle1_Pt + QCDFakeEle2_Pt + JetLooseEle1_Pt ;
       fillVariableWithValue( "DR_Ele1Jet1"                   , loose_ele1.DeltaR ( jet1 ), min_prescale  * fakeRateEffective );
       fillVariableWithValue( "DR_Ele2Jet1"                   , loose_ele2.DeltaR ( jet1 ), min_prescale  * fakeRateEffective );
       fillVariableWithValue( "sT_eej_200"                    , st                        , min_prescale  * fakeRateEffective );
       fillVariableWithValue( "sT_eej_450"                    , st                        , min_prescale  * fakeRateEffective );
     }      

     //--------------------------------------------------------------------------
     // Evaluate the cuts
     //--------------------------------------------------------------------------
     
     evaluateCuts();

     //--------------------------------------------------------------------------
     // Fill preselection plots
     // DO    use the pileup weight.  It's equal to 1.0 for data.  
     // DO    use the min_prescale.  It's equal to 1.0 for Monte Carlo
     // DO    use the effective fake rate.  It will only mean anything when you run
     //       over data, though, so be sure to override it to 1.0 
     //       if you run over Monte Carlo
     //--------------------------------------------------------------------------     

     bool passed_preselection = ( passedAllPreviousCuts("sT_eej_200") && passedCut ("sT_eej_200") );
     
     if ( passed_preselection ) {

       double sT_eej = QCDFakeEle1_Pt + QCDFakeEle2_Pt + JetLooseEle1_Pt ;

       FillUserTH1D("nElectron_PAS"        , nEle_QCDFake              , pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("nMuon_PAS"            , nMuon_Stored              , pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("nJet_PAS"             , nJetLooseEle_Stored       , pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("Pt1stEle_PAS"	   , QCDFakeEle1_Pt            , pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("Eta1stEle_PAS"	   , QCDFakeEle1_Eta           , pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("Phi1stEle_PAS"	   , QCDFakeEle1_Phi           , pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("Pt2ndEle_PAS"	   , QCDFakeEle2_Pt            , pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("Eta2ndEle_PAS"	   , QCDFakeEle2_Eta           , pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("Phi2ndEle_PAS"	   , QCDFakeEle2_Phi           , pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("Charge1stEle_PAS"	   , QCDFakeEle1_Charge        , pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("Charge2ndEle_PAS"	   , QCDFakeEle2_Charge        , pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("MET_PAS"              , MET_Pt                    , pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("METPhi_PAS"	   , MET_Phi                   , pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("METCharged_PAS"       , PFMETCharged              , pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("METChargedPhi_PAS"    , PFMETChargedPhi           , pileup_weight * min_prescale * fakeRateEffective );   
       FillUserTH1D("METType1_PAS"         , PFMETType1Cor             , pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("METType1Phi_PAS"      , PFMETPhiType1Cor          , pileup_weight * min_prescale * fakeRateEffective );   
       FillUserTH1D("Pt1stJet_PAS"         , JetLooseEle1_Pt           , pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("Eta1stJet_PAS"        , JetLooseEle1_Eta          , pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("Phi1stJet_PAS"	   , JetLooseEle1_Phi          , pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("sT_PAS"               , sT_eej                    , pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("Mee_PAS"		   , loose_e1e2.M()            , pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("Ptee_PAS"             , loose_e1e2.Pt()           , pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("nVertex_PAS"          , nVertex                   , pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("nVertex_good_PAS"     , nVertex_good              , pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("DR_Ele1Jet1_PAS"	   , loose_ele1.DeltaR ( jet1 ), pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("DR_Ele2Jet1_PAS"	   , loose_ele2.DeltaR ( jet1 ), pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("Me1j1_PAS"            , e1j1.M()                  , pileup_weight * min_prescale * fakeRateEffective );
       FillUserTH1D("Me2j1_PAS"            , e2j1.M()                  , pileup_weight * min_prescale * fakeRateEffective );
     }
   } // End loop over events

   std::cout << "analysisClass::Loop() ends" <<std::endl;   
}