Index: Makefile
===================================================================
--- Makefile	(revision 4406bf83d2a69fe8b8d556318684ee1f85a8befb)
+++ Makefile	(revision 4a0d9d51f8985207061b5b889b9e4cd4faba0d82)
@@ -1362,8 +1362,6 @@
 	modules/RunPUPPI.$(SrcSuf) \
 	modules/RunPUPPI.h \
-	external/PUPPI/puppiCleanContainer.hh \
-	external/PUPPI/RecoObj.hh \
-	external/PUPPI/puppiParticle.hh \
-	external/PUPPI/puppiAlgoBin.hh \
+	external/PUPPI/RecoObj2.hh \
+	external/PUPPI/AlgoObj.hh \
 	classes/DelphesClasses.h \
 	classes/DelphesFactory.h \
@@ -1801,5 +1799,6 @@
 
 modules/RunPUPPI.h: \
-	classes/DelphesModule.h
+	classes/DelphesModule.h \
+	external/PUPPI/PuppiContainer.hh
 	@touch $@
 
@@ -1933,12 +1932,4 @@
 	external/fastjet/AreaDefinition.hh \
 	external/fastjet/ClusterSequenceAreaBase.hh
-	@touch $@
-
-external/PUPPI/puppiCleanContainer.hh: \
-	external/PUPPI/RecoObj.hh \
-	external/PUPPI/puppiParticle.hh \
-	external/PUPPI/puppiAlgoBin.hh \
-	external/fastjet/internal/base.hh \
-	external/fastjet/PseudoJet.hh
 	@touch $@
 
Index: cards/CMS_PhaseII/CMS_PhaseII_200PU.tcl
===================================================================
--- cards/CMS_PhaseII/CMS_PhaseII_200PU.tcl	(revision 4406bf83d2a69fe8b8d556318684ee1f85a8befb)
+++ cards/CMS_PhaseII/CMS_PhaseII_200PU.tcl	(revision 4a0d9d51f8985207061b5b889b9e4cd4faba0d82)
@@ -1,8 +1,10 @@
+set MaxEvents 10
+
 #
 #  Phase II - Pile-Up
 #
 #  Main authors: Michele Selvaggi (UCL)
-#                                
-#  Released on: 
+#
+#  Released on:
 #
 #  Version: v01
@@ -14,7 +16,6 @@
 
 set ExecutionPath {
- 
-  PileUpMerger 
-  
+
+  PileUpMerger
   ParticlePropagator
 
@@ -28,5 +29,5 @@
 
   TrackMerger
-  
+
   ECal
   HCal
@@ -34,5 +35,5 @@
   ElectronFilter
   TrackPileUpSubtractor
-  
+
   TowerMerger
   NeutralEFlowMerger
@@ -40,19 +41,25 @@
   EFlowMerger
 
+  LeptonFilterNoLep
+  LeptonFilterLep
+  RunPUPPIBase
   RunPUPPI
+
+  PhotonFilter
 
   PhotonIsolation
   PhotonEfficiency
-  
+
   ElectronIsolation
   ElectronEfficiency
- 
+
   MuonIsolation
   MuonLooseIdEfficiency
   MuonTightIdEfficiency
- 
+
   NeutrinoFilter
 
   MissingET
+  PuppiMissingET
   GenMissingET
   GenPileUpMissingET
@@ -62,5 +69,5 @@
 
   ScalarHT
- 
+
   JetEnergyScale
 
@@ -72,7 +79,7 @@
 
   TauTagging
-  
+
   GenParticleFilter
-  
+
   TreeWriter
 }
@@ -91,24 +98,17 @@
 
   # pre-generated minbias input file
-  set PileUpFile ../eos/cms/store/group/upgrade/delphes/PhaseII/MinBias_100k.pileup 
+  set PileUpFile ../eos/cms/store/group/upgrade/delphes/PhaseII/MinBias_100k.pileup
 
   # average expected pile up
   set MeanPileUp 200
-  
+
   # maximum spread in the beam direction in m
-  set ZVertexSpread 0.15
+  set ZVertexSpread 0.25
 
   # maximum spread in time in s
-  set TVertexSpread 1.5E-09
+  set TVertexSpread 800E-12
 
   # vertex smearing formula f(z,t) (z,t need to be respectively given in m,s)
- 
-  #set VertexDistributionFormula {exp(-(t^2/(2*(0.05/2.99792458E8*exp(-(z^2/(2*(0.05)^2))))^2)))}
-  
-  
-  set VertexDistributionFormula { (abs(t) <= 1.0e-09) * (abs(z) <= 0.15) * (1.00) +
-                                  (abs(t) >  1.0e-09) * (abs(z) <= 0.15) * (0.00) +
-   				  (abs(t) <= 1.0e-09) * (abs(z) > 0.15)  * (0.00) +
-   				  (abs(t) >  1.0e-09) * (abs(z) > 0.15)  * (0.00)}
+  set VertexDistributionFormula {exp(-(t^2/160e-12^2/2))*exp(-(z^2/0.053^2/2))}
 
 }
@@ -167,5 +167,5 @@
   set OutputArray electrons
   # tracking efficiency formula for electrons
-  set EfficiencyFormula { 
+  set EfficiencyFormula {
       (pt <= 0.2) * (0.00) + \
 	  (abs(eta) <= 1.2) * (pt > 0.2 && pt <= 1.0) * (pt * 0.96) + \
@@ -199,5 +199,5 @@
 	  (abs(eta) > 2.8 && abs(eta) <= 4.0) * (pt > 1.0) * (0.95) + \
 	  (abs(eta) > 4.0) * (0.00)
-	  
+
   }
 }
@@ -212,6 +212,6 @@
   set InputArray  ChargedHadronTrackingEfficiency/chargedHadrons
   set OutputArray chargedHadrons
-  # resolution formula for charged hadrons , 
- 
+  # resolution formula for charged hadrons ,
+
   # from http://mersi.web.cern.ch/mersi/layouts/.private/Baseline_tilted_200_Pixel_1_1_1/index.html
   source trackMomentumResolution.tcl
@@ -229,14 +229,14 @@
 
   # resolution formula for electrons
-  
+
   # taking something flat in energy for now, ECAL will take over at high energy anyway.
   # inferred from hep-ex/1306.2016 and 1502.02701
-  set ResolutionFormula {  
-  
+  set ResolutionFormula {
+
                         (abs(eta) <= 1.5)  * (1+0.64*abs(eta)^2)*(energy*0.028) +
     (abs(eta) > 1.5  && abs(eta) <= 1.75)  * (energy*0.037) +
     (abs(eta) > 1.75  && abs(eta) <= 2.15) * (energy*0.038) +
     (abs(eta) > 2.15  && abs(eta) <= 3.00) * (energy*0.044) +
-    (abs(eta) > 3.00  && abs(eta) <= 4.00) * (energy*0.10)}   
+    (abs(eta) > 3.00  && abs(eta) <= 4.00) * (energy*0.10)}
 
 }
@@ -250,9 +250,9 @@
   set OutputArray muons
   # resolution formula for muons
-  
-  # up to |eta| < 2.8 take measurement from tracking + muon chambers 
-  # for |eta| > 2.8 and pT < 5.0 take measurement from tracking alone taken from 
+
+  # up to |eta| < 2.8 take measurement from tracking + muon chambers
+  # for |eta| > 2.8 and pT < 5.0 take measurement from tracking alone taken from
   # http://mersi.web.cern.ch/mersi/layouts/.private/Baseline_tilted_200_Pixel_1_1_1/index.html
-  source muonMomentumResolution.tcl  
+  source muonMomentumResolution.tcl
 }
 
@@ -284,6 +284,6 @@
   set EFlowTowerOutputArray eflowPhotons
 
-  set IsEcal true 
- 
+  set IsEcal true
+
   set EnergyMin 0.5
   set EnergySignificanceMin 1.0
@@ -298,5 +298,5 @@
 
   # assume 0.02 x 0.02 resolution in eta,phi in the barrel |eta| < 1.5
-  
+
   set PhiBins {}
   for {set i -180} {$i <= 180} {incr i} {
@@ -311,5 +311,5 @@
 
   # assume 0.02 x 0.02 resolution in eta,phi in the endcaps 1.5 < |eta| < 3.0 (HGCAL- ECAL)
-  
+
   set PhiBins {}
   for {set i -180} {$i <= 180} {incr i} {
@@ -328,6 +328,6 @@
   }
 
-  # take present CMS granularity for HF  
- 
+  # take present CMS granularity for HF
+
   # 0.175 x (0.175 - 0.35) resolution in eta,phi in the HF 3.0 < |eta| < 5.0
   set PhiBins {}
@@ -335,5 +335,5 @@
     add PhiBins [expr {$i * $pi/18.0}]
   }
-  
+
   foreach eta {-5 -4.7 -4.525 -4.35 -4.175 -4 -3.825 -3.65 -3.475 -3.3 -3.125 -2.958 3.125 3.3 3.475 3.65 3.825 4 4.175 4.35 4.525 4.7 5} {
     add EtaPhiBins $eta $PhiBins
@@ -361,9 +361,9 @@
 
   # set ResolutionFormula {resolution formula as a function of eta and energy}
-  
+
   # for the ECAL barrel (|eta| < 1.5), see hep-ex/1306.2016 and 1502.02701
   # for the endcaps (1.5 < |eta| < 3.0), we take HGCAL  see LHCC-P-008, Fig. 3.39, p.117
 
-  set ResolutionFormula {  (abs(eta) <= 1.50)                    * (1+0.64*abs(eta)^2)*sqrt(energy^2*0.009^2 + energy*0.12^2 + 0.45^2) + 
+  set ResolutionFormula {  (abs(eta) <= 1.50)                    * (1+0.64*abs(eta)^2)*sqrt(energy^2*0.009^2 + energy*0.12^2 + 0.45^2) +
                            (abs(eta) > 1.50 && abs(eta) <= 1.75) * sqrt(energy^2*0.006^2 + energy*0.20^2) + \
                            (abs(eta) > 1.75 && abs(eta) <= 2.15) * sqrt(energy^2*0.007^2 + energy*0.21^2) + \
@@ -385,6 +385,6 @@
   set EFlowTowerOutputArray eflowNeutralHadrons
 
-  set IsEcal false 
- 
+  set IsEcal false
+
   set EnergyMin 1.0
   set EnergySignificanceMin 1.0
@@ -397,5 +397,5 @@
   # each list starts with the lower edge of the first tower
   # the list ends with the higher edged of the last tower
- 
+
   # assume 0.087 x 0.087 resolution in eta,phi in the barrel |eta| < 1.5
 
@@ -409,5 +409,5 @@
 
   # assume 0.02 x 0.02 resolution in eta,phi in the endcaps 1.5 < |eta| < 3.0 (HGCAL- HCAL)
-  
+
   set PhiBins {}
   for {set i -180} {$i <= 180} {incr i} {
@@ -426,6 +426,6 @@
   }
 
-  # take present CMS granularity for HF  
- 
+  # take present CMS granularity for HF
+
   # 0.175 x (0.175 - 0.35) resolution in eta,phi in the HF 3.0 < |eta| < 5.0
   set PhiBins {}
@@ -433,5 +433,5 @@
     add PhiBins [expr {$i * $pi/18.0}]
   }
-  
+
   foreach eta {-5 -4.7 -4.525 -4.35 -4.175 -4 -3.825 -3.65 -3.475 -3.3 -3.125 -2.958 3.125 3.3 3.475 3.65 3.825 4 4.175 4.35 4.525 4.7 5} {
     add EtaPhiBins $eta $PhiBins
@@ -478,4 +478,5 @@
 }
 
+
 ##########################
 # Track pile-up subtractor
@@ -547,25 +548,47 @@
 #########################################
 
-module RunPUPPI RunPUPPI {
+module PdgCodeFilter LeptonFilterNoLep {
+  set InputArray HCal/eflowTracks
+  set OutputArray eflowTracksNoLeptons
+  set Invert false
+  add PdgCode {13}
+  add PdgCode {-13}
+  add PdgCode {11}
+  add PdgCode {-11}
+}
+
+module PdgCodeFilter LeptonFilterLep {
+  set InputArray HCal/eflowTracks
+  set OutputArray eflowTracksLeptons
+  set Invert true
+  add PdgCode {11}
+  add PdgCode {-11}
+  add PdgCode {13}
+  add PdgCode {-13}
+}
+
+module RunPUPPI RunPUPPIBase {
   ## input information
-  set TrackInputArray   TrackMerger/tracks
+  set TrackInputArray   LeptonFilterNoLep/eflowTracksNoLeptons
   set NeutralInputArray NeutralEFlowMerger/eflowTowers
   set PVInputArray      PileUpMerger/vertices
   set MinPuppiWeight    0.05
   set UseExp            false
- 
-  ## define puppi algorithm parameters (more than one for the same eta region is possible)                                                                                      
-  add EtaMinBin           0.    2.5    2.5    3.0   3.0
-  add EtaMaxBin           2.5   3.0    3.0    10.0  10.0
-  add PtMinBin            0.    0.5    0.5    0.5   0.5
-  add ConeSizeBin         0.25  0.25   0.25   0.25  0.25
-  add RMSPtMinBin         0.1   0.5    0.5    0.5   0.5
-  add RMSScaleFactorBin   1.0   1.0    1.0    1.0   1.0
-  add NeutralMinEBin      0.2   1.0    1.0    1.5   1.5
-  add NeutralPtSlope      0.02  0.02   0.02   0.02  0.02
-  add ApplyCHS            true  true   true   true  true
-  add UseCharged          true  false  false  false false
-  add ApplyLowPUCorr      true  true   true   true  true
-  add MetricId            5     5      1      5     1
+  set UseNoLep          false
+
+  ## define puppi algorithm parameters (more than one for the same eta region is possible)
+  add EtaMinBin           0.0   1.5   4.0
+  add EtaMaxBin           1.5   4.0   10.0
+  add PtMinBin            0.0   0.0   0.0
+  add ConeSizeBin         0.2   0.2   0.2
+  add RMSPtMinBin         0.1   0.5   0.5
+  add RMSScaleFactorBin   1.0   1.0   1.0
+  add NeutralMinEBin      0.2   0.2   0.5
+  add NeutralPtSlope      0.006 0.013 0.067
+  add ApplyCHS            true  true  true
+  add UseCharged          true  true  false
+  add ApplyLowPUCorr      true  true  true
+  add MetricId            5     5     5
+  add CombId              0     0     0
 
   ## output name
@@ -573,7 +596,11 @@
   set OutputArrayTracks   puppiTracks
   set OutputArrayNeutrals puppiNeutrals
-} 
-
-
+}
+
+module Merger RunPUPPI {
+  add InputArray RunPUPPIBase/PuppiParticles
+  add InputArray LeptonFilterLep/eflowTracksLeptons
+  set OutputArray PuppiParticles
+}
 
 ###################
@@ -588,6 +615,13 @@
 }
 
+module Merger PuppiMissingET {
+  #add InputArray InputArray
+  add InputArray RunPUPPI/PuppiParticles
+  #add InputArray EFlowMerger/eflow
+  set MomentumOutputArray momentum
+}
+
 ###################
-# Ger PileUp Missing ET 
+# Ger PileUp Missing ET
 ###################
 
@@ -636,5 +670,5 @@
 module FastJetFinder GenJetFinder {
   set InputArray NeutrinoFilter/filteredParticles
- 
+
   set OutputArray jets
 
@@ -689,4 +723,17 @@
 
 
+#################
+# Photon filter
+#################
+
+module PdgCodeFilter PhotonFilter {
+  set InputArray ECal/eflowPhotons
+  set OutputArray photons
+  set Invert true
+  set PTMin 5.0
+  add PdgCode {22}
+}
+
+
 ####################
 # Photon isolation #
@@ -694,22 +741,27 @@
 
 module Isolation PhotonIsolation {
-  
+
   # particle for which calculate the isolation
-  set CandidateInputArray ECal/eflowPhotons
-  
+  set CandidateInputArray PhotonFilter/photons
+
   # isolation collection
-  set IsolationInputArray EFlowMerger/eflow
- 
+  set IsolationInputArray RunPUPPI/PuppiParticles
+
   # output array
   set OutputArray photons
-  
+
+  # veto isolation cand. based on proximity to input cand.
+  set DeltaRMin 0.01
+  set UseMiniCone true
+
   # isolation cone
   set DeltaRMax 0.3
-  
-  # minimum pT  
+
+  # minimum pT
   set PTMin     1.0
-  
+
   # iso ratio to cut
   set PTRatioMax 9999.
+
 }
 
@@ -721,7 +773,7 @@
 
 module Efficiency PhotonEfficiency {
-  
+
   ## input particles
-  set InputArray PhotonIsolation/photons 
+  set InputArray PhotonIsolation/photons
   ## output particles
   set OutputArray photons
@@ -741,12 +793,13 @@
 
 module Isolation ElectronIsolation {
-  
+
   set CandidateInputArray ElectronFilter/electrons
-  
+
   # isolation collection
-  set IsolationInputArray EFlowMerger/eflow
-  
+  set IsolationInputArray RunPUPPI/PuppiParticles
+  #set IsolationInputArray EFlowMerger/eflow
+
   set OutputArray electrons
-  
+
   set DeltaRMax 0.3
   set PTMin 1.0
@@ -762,8 +815,8 @@
 
 module Efficiency ElectronEfficiency {
-  
+
   set InputArray ElectronIsolation/electrons
   set OutputArray electrons
-  
+
   # set EfficiencyFormula {efficiency formula as a function of eta and pt}
   # efficiency formula for electrons
@@ -773,22 +826,22 @@
                          (abs(eta) <= 1.45 ) * (pt >  6.0 && pt <= 8.0)   * (0.70) + \
                          (abs(eta) <= 1.45 ) * (pt >  8.0 && pt <= 10.0)  * (0.85) + \
-                         (abs(eta) <= 1.45 ) * (pt > 10.0 && pt <= 30.0)  * (0.94) + \                                                      
-                         (abs(eta) <= 1.45 ) * (pt > 30.0 && pt <= 50.0)  * (0.97) + \                          
-                         (abs(eta) <= 1.45 ) * (pt > 50.0 && pt <= 70.0)  * (0.98) + \          
-                         (abs(eta) <= 1.45 ) * (pt > 70.0 )  * (1.0) + \                                                                                                 
+                         (abs(eta) <= 1.45 ) * (pt > 10.0 && pt <= 30.0)  * (0.94) + \
+                         (abs(eta) <= 1.45 ) * (pt > 30.0 && pt <= 50.0)  * (0.97) + \
+                         (abs(eta) <= 1.45 ) * (pt > 50.0 && pt <= 70.0)  * (0.98) + \
+                         (abs(eta) <= 1.45 ) * (pt > 70.0 )  * (1.0) + \
                          (abs(eta) > 1.45  && abs(eta) <= 1.55) * (pt >  4.0 && pt <= 10.0)   * (0.35) + \
-                         (abs(eta) > 1.45  && abs(eta) <= 1.55) * (pt > 10.0 && pt <= 30.0)   * (0.40) + \   
-                         (abs(eta) > 1.45  && abs(eta) <= 1.55) * (pt > 30.0 && pt <= 70.0)   * (0.45) + \                                 
-                         (abs(eta) > 1.45  && abs(eta) <= 1.55) * (pt > 70.0 )  * (0.55) + \    
+                         (abs(eta) > 1.45  && abs(eta) <= 1.55) * (pt > 10.0 && pt <= 30.0)   * (0.40) + \
+                         (abs(eta) > 1.45  && abs(eta) <= 1.55) * (pt > 30.0 && pt <= 70.0)   * (0.45) + \
+                         (abs(eta) > 1.45  && abs(eta) <= 1.55) * (pt > 70.0 )  * (0.55) + \
                          (abs(eta) >= 1.55 && abs(eta) <= 2.0 ) * (pt >  4.0 && pt <= 10.0)  * (0.75) + \
-                         (abs(eta) >= 1.55 && abs(eta) <= 2.0 ) * (pt > 10.0 && pt <= 30.0)  * (0.85) + \                                                      
-                         (abs(eta) >= 1.55 && abs(eta) <= 2.0 ) * (pt > 30.0 && pt <= 50.0)  * (0.95) + \                          
-                         (abs(eta) >= 1.55 && abs(eta) <= 2.0 ) * (pt > 50.0 && pt <= 70.0)  * (0.95) + \          
-                         (abs(eta) >= 1.55 && abs(eta) <= 2.0 ) * (pt > 70.0 )  * (1.0) + \   
+                         (abs(eta) >= 1.55 && abs(eta) <= 2.0 ) * (pt > 10.0 && pt <= 30.0)  * (0.85) + \
+                         (abs(eta) >= 1.55 && abs(eta) <= 2.0 ) * (pt > 30.0 && pt <= 50.0)  * (0.95) + \
+                         (abs(eta) >= 1.55 && abs(eta) <= 2.0 ) * (pt > 50.0 && pt <= 70.0)  * (0.95) + \
+                         (abs(eta) >= 1.55 && abs(eta) <= 2.0 ) * (pt > 70.0 )  * (1.0) + \
                          (abs(eta) >= 2.0 && abs(eta) <= 2.5 ) * (pt >  4.0 && pt <= 10.0)  * (0.65) + \
-                         (abs(eta) >= 2.0 && abs(eta) <= 2.5 ) * (pt > 10.0 && pt <= 30.0)  * (0.75) + \                                                      
-                         (abs(eta) >= 2.0 && abs(eta) <= 2.5 ) * (pt > 30.0 && pt <= 50.0)  * (0.90) + \                          
-                         (abs(eta) >= 2.0 && abs(eta) <= 2.5 ) * (pt > 50.0 && pt <= 70.0)  * (0.90) + \          
-                         (abs(eta) >= 2.0 && abs(eta) <= 2.5 ) * (pt > 70.0 )  * (0.90) + \                                                                            
+                         (abs(eta) >= 2.0 && abs(eta) <= 2.5 ) * (pt > 10.0 && pt <= 30.0)  * (0.75) + \
+                         (abs(eta) >= 2.0 && abs(eta) <= 2.5 ) * (pt > 30.0 && pt <= 50.0)  * (0.90) + \
+                         (abs(eta) >= 2.0 && abs(eta) <= 2.5 ) * (pt > 50.0 && pt <= 70.0)  * (0.90) + \
+                         (abs(eta) >= 2.0 && abs(eta) <= 2.5 ) * (pt > 70.0 )  * (0.90) + \
                          (abs(eta) > 2.5 && abs(eta) <= 4.0 ) * (pt > 4.0 && pt <= 10.0) * (0.65) + \
 					  (abs(eta) > 2.5 && abs(eta) <= 4.0 ) * (pt > 10.0 && pt <= 30.0) * (0.75) + \
@@ -797,5 +850,5 @@
 					  (abs(eta) > 2.5 && abs(eta) <= 4.0 ) * (pt > 70.0 ) * (0.90) + \
 					  (abs(eta) > 4.0) * (0.00)
- 
+
   }
 }
@@ -807,10 +860,10 @@
 module Isolation MuonIsolation {
   set CandidateInputArray MuonMomentumSmearing/muons
- 
+
   # isolation collection
-  set IsolationInputArray EFlowMerger/eflow
- 
+  set IsolationInputArray RunPUPPI/PuppiParticles
+
   set OutputArray muons
-  
+
   set DeltaRMax 0.3
   set PTMin 1.0
@@ -885,9 +938,8 @@
 
   set BitNumber 1
- 
+
   source btagMedium.tcl
 }
 
-  
 
 #############
@@ -900,9 +952,6 @@
   set BitNumber 2
 
-  source btagTight.tcl 
-}
-
-
-
+  source btagTight.tcl
+}
 
 
@@ -930,5 +979,5 @@
   add EfficiencyFormula {15} { (abs(eta) < 2.3) * 0.97*0.77*( (0.32 + 0.01*pt - 0.000054*pt*pt )*(pt<100)+0.78*(pt>100) ) + \
                                (abs(eta) > 2.3) * (0.000)
-                             } 
+                             }
 }
 
@@ -939,9 +988,9 @@
 
 module StatusPidFilter GenParticleFilter {
-  
+
     set InputArray  Delphes/allParticles
     set OutputArray filteredParticles
     set PTMin 5.0
-    
+
 }
 
@@ -955,5 +1004,5 @@
   add Branch GenParticleFilter/filteredParticles Particle GenParticle
   add Branch PileUpMerger/vertices Vertex Vertex
- 
+
   add Branch GenJetFinder/jets GenJet Jet
   add Branch GenMissingET/momentum GenMissingET MissingET
@@ -962,13 +1011,14 @@
 #  add Branch ECal/eflowPhotons EFlowPhoton Tower
 #  add Branch HCal/eflowNeutralHadrons EFlowNeutralHadron Tower
-  
+
   add Branch PhotonEfficiency/photons Photon Photon
   add Branch ElectronEfficiency/electrons Electron Electron
   add Branch MuonLooseIdEfficiency/muons MuonLoose Muon
   add Branch MuonTightIdEfficiency/muons MuonTight Muon
-   
+
   add Branch JetEnergyScale/jets Jet Jet
-  
+
   add Branch MissingET/momentum MissingET MissingET
+  add Branch PuppiMissingET/momentum PuppiMissingET MissingET
   add Branch GenPileUpMissingET/momentum GenPileUpMissingET MissingET
   add Branch ScalarHT/energy ScalarHT ScalarHT
Index: cards/delphes_card_CMS.tcl
===================================================================
--- cards/delphes_card_CMS.tcl	(revision 4406bf83d2a69fe8b8d556318684ee1f85a8befb)
+++ cards/delphes_card_CMS.tcl	(revision 4a0d9d51f8985207061b5b889b9e4cd4faba0d82)
@@ -271,5 +271,5 @@
   # Eta shape from arXiv:1306.2016, Energy shape from arXiv:1502.02701
   set ECalResolutionFormula {                  (abs(eta) <= 1.5) * (1+0.64*eta^2) * sqrt(energy^2*0.008^2 + energy*0.11^2 + 0.40^2) +
-                             (abs(eta) > 1.5 && abs(eta) <= 2.5) * (2.16 + 5.6*(eta-2)^2) * sqrt(energy^2*0.008^2 + energy*0.11^2 + 0.40^2) +
+                             (abs(eta) > 1.5 && abs(eta) <= 2.5) * (2.16 + 5.6*(abs(eta)-2)^2) * sqrt(energy^2*0.008^2 + energy*0.11^2 + 0.40^2) +
                              (abs(eta) > 2.5 && abs(eta) <= 5.0) * sqrt(energy^2*0.107^2 + energy*2.08^2)}
 
Index: modules/Calorimeter.cc
===================================================================
--- modules/Calorimeter.cc	(revision 4406bf83d2a69fe8b8d556318684ee1f85a8befb)
+++ modules/Calorimeter.cc	(revision 4a0d9d51f8985207061b5b889b9e4cd4faba0d82)
@@ -625,4 +625,5 @@
     tower->Eem = ecalEnergy;
     tower->Ehad = 0.0;
+    tower->PID = 22;
 
     fEFlowPhotonOutputArray->Add(tower);
Index: modules/Isolation.cc
===================================================================
--- modules/Isolation.cc	(revision 4406bf83d2a69fe8b8d556318684ee1f85a8befb)
+++ modules/Isolation.cc	(revision 4a0d9d51f8985207061b5b889b9e4cd4faba0d82)
@@ -110,4 +110,7 @@
 
   fUseRhoCorrection = GetBool("UseRhoCorrection", true);
+
+  fDeltaRMin = GetDouble("DeltaRMin", 0.01);
+  fUseMiniCone = GetBool("UseMiniCone", false);
 
   fClassifier->fPTMin = GetDouble("PTMin", 0.5);
@@ -157,5 +160,5 @@
   Double_t sumChargedNoPU, sumChargedPU, sumNeutral, sumAllParticles;
   Double_t sumDBeta, ratioDBeta, sumRhoCorr, ratioRhoCorr, sum, ratio;
-  Int_t counter;
+  Bool_t pass = kFALSE;
   Double_t eta = 0.0;
   Double_t rho = 0.0;
@@ -197,14 +200,23 @@
     sumAllParticles = 0.0;
 
-    counter = 0;
     itIsolationArray.Reset();
-
     while((isolation = static_cast<Candidate*>(itIsolationArray.Next())))
     {
       const TLorentzVector &isolationMomentum = isolation->Momentum;
 
-      if(candidateMomentum.DeltaR(isolationMomentum) <= fDeltaRMax &&
-         candidate->GetUniqueID() != isolation->GetUniqueID())
-      {
+      if(fUseMiniCone)
+      {
+         pass = candidateMomentum.DeltaR(isolationMomentum) <= fDeltaRMax &&
+         candidateMomentum.DeltaR(isolationMomentum) > fDeltaRMin;
+      }
+      else
+      {
+         pass = candidateMomentum.DeltaR(isolationMomentum) <= fDeltaRMax &&
+         candidate->GetUniqueID() != isolation->GetUniqueID();
+      }
+
+      if(pass)
+      {
+
         sumAllParticles += isolationMomentum.Pt();
         if(isolation->Charge != 0)
@@ -223,9 +235,9 @@
           sumNeutral += isolationMomentum.Pt();
         }
-        ++counter;
-      }
+      }
+
     }
 
-    // find rho
+   // find rho
     rho = 0.0;
     if(fRhoInputArray)
@@ -240,4 +252,6 @@
       }
     }
+
+
 
     // correct sum for pile-up contamination
Index: modules/Isolation.h
===================================================================
--- modules/Isolation.h	(revision 4406bf83d2a69fe8b8d556318684ee1f85a8befb)
+++ modules/Isolation.h	(revision 4a0d9d51f8985207061b5b889b9e4cd4faba0d82)
@@ -57,7 +57,11 @@
   Double_t fPTSumMax;
 
+  Double_t fDeltaRMin;
+
   Bool_t fUsePTSum;
 
   Bool_t fUseRhoCorrection;
+
+  Bool_t fUseMiniCone;
 
   IsolationClassifier *fClassifier; //!
Index: modules/RunPUPPI.cc
===================================================================
--- modules/RunPUPPI.cc	(revision 4406bf83d2a69fe8b8d556318684ee1f85a8befb)
+++ modules/RunPUPPI.cc	(revision 4a0d9d51f8985207061b5b889b9e4cd4faba0d82)
@@ -1,8 +1,8 @@
 #include "modules/RunPUPPI.h"
 
-#include "PUPPI/puppiCleanContainer.hh"
-#include "PUPPI/RecoObj.hh"
-#include "PUPPI/puppiParticle.hh"
-#include "PUPPI/puppiAlgoBin.hh"
+#include "PUPPI/RecoObj2.hh"
+#include "PUPPI/AlgoObj.hh"
+//#include "PUPPI/puppiParticle.hh"
+//#include "PUPPI/puppiAlgoBin.hh"
 
 #include "classes/DelphesClasses.h"
@@ -30,5 +30,4 @@
 
 void RunPUPPI::Init(){
-
   // input collection
   fTrackInputArray     = ImportArray(GetString("TrackInputArray", "Calorimeter/towers"));
@@ -38,74 +37,101 @@
   fPVInputArray        = ImportArray(GetString("PVInputArray", "PV"));
   fPVItInputArray      = fPVInputArray->MakeIterator();
-
-
-  // puppi parameters                                     
+  // puppi parameters                                 
+  fApplyNoLep     = GetBool("UseNoLep", true);    
   fMinPuppiWeight = GetDouble("MinPuppiWeight", 0.01);
   fUseExp         = GetBool("UseExp", false);
-
-  // read eta min ranges                                                                                                                                                           
+  // read eta min ranges
   ExRootConfParam param = GetParam("EtaMinBin");
   fEtaMinBin.clear();
   for(int iMap = 0; iMap < param.GetSize(); ++iMap) fEtaMinBin.push_back(param[iMap].GetDouble());
-
-  // read eta max ranges                                                                                                                                                           
+  // read eta max ranges
   param = GetParam("EtaMaxBin");
   fEtaMaxBin.clear();
   for(int iMap = 0; iMap < param.GetSize(); ++iMap) fEtaMaxBin.push_back(param[iMap].GetDouble());
-
-  // read pt min value                                                                                                                                                           
+  // read pt min value
   param = GetParam("PtMinBin");
   fPtMinBin.clear();
   for(int iMap = 0; iMap < param.GetSize(); ++iMap) fPtMinBin.push_back(param[iMap].GetDouble());
-
   // read cone size                                                                                                                                                           
   param = GetParam("ConeSizeBin");
   fConeSizeBin.clear();
   for(int iMap = 0; iMap < param.GetSize(); ++iMap) fConeSizeBin.push_back(param[iMap].GetDouble());
-
   // read RMS min pt                                                                                                                                             
   param = GetParam("RMSPtMinBin");
   fRMSPtMinBin.clear();
   for(int iMap = 0; iMap < param.GetSize(); ++iMap) fRMSPtMinBin.push_back(param[iMap].GetDouble());
-
-  // read RMS scale factor                                                                                                                                                           
+  // read RMS scale factor
   param = GetParam("RMSScaleFactorBin");
   fRMSScaleFactorBin.clear();
   for(int iMap = 0; iMap < param.GetSize(); ++iMap) fRMSScaleFactorBin.push_back(param[iMap].GetDouble());
-
-  // read neutral pt min cut                                                                                                                                                           
+  // read neutral pt min cut
   param = GetParam("NeutralMinEBin");
   fNeutralMinEBin.clear();
   for(int iMap = 0; iMap < param.GetSize(); ++iMap) fNeutralMinEBin.push_back(param[iMap].GetDouble());
-
-  // read neutral pt min slope                                                                                                                                                           
+  // read neutral pt min slope
   param = GetParam("NeutralPtSlope");
   fNeutralPtSlope.clear();
   for(int iMap = 0; iMap < param.GetSize(); ++iMap) fNeutralPtSlope.push_back(param[iMap].GetDouble());
-
   // read apply chs                                                                                                                                                           
-  param = GetParam("ApplyCHS");
-  fApplyCHS.clear();
-  for(int iMap = 0; iMap < param.GetSize(); ++iMap) fApplyCHS.push_back(param[iMap].GetBool());
-
-  // read use charged                                                                                                                                                           
+  //param = GetParam("ApplyCHS");
+  //fApplyCHS.clear();
+  //for(int iMap = 0; iMap < param.GetSize(); ++iMap) fApplyCHS.push_back(param[iMap].GetBool());
+  // read use charged
   param = GetParam("UseCharged");
   fUseCharged.clear();
   for(int iMap = 0; iMap < param.GetSize(); ++iMap) fUseCharged.push_back(param[iMap].GetBool());
-
-  // read apply chs correction                                                                                                                                                           
+  // read apply chs correction
   param = GetParam("ApplyLowPUCorr");
   fApplyLowPUCorr.clear();
   for(int iMap = 0; iMap < param.GetSize(); ++iMap) fApplyLowPUCorr.push_back(param[iMap].GetBool());
-  
   // read metric id                                                                                                                                                          
   param = GetParam("MetricId");
   fMetricId.clear();
   for(int iMap = 0; iMap < param.GetSize(); ++iMap) fMetricId.push_back(param[iMap].GetInt());
-
+  // scheme for combining
+  param = GetParam("CombId");
+  fCombId.clear();
+  for(int iMap = 0; iMap < param.GetSize(); ++iMap) fCombId.push_back(param[iMap].GetInt());
   // create output array
   fOutputArray        = ExportArray(GetString("OutputArray", "puppiParticles"));
   fOutputTrackArray   = ExportArray(GetString("OutputArrayTracks", "puppiTracks"));
   fOutputNeutralArray = ExportArray(GetString("OutputArrayNeutrals", "puppiNeutrals"));
+  // Create algorithm list for puppi
+  std::vector<AlgoObj> puppiAlgo;
+  if(puppiAlgo.empty()){
+    if(!(fEtaMinBin.size() == fEtaMaxBin.size() and fEtaMinBin.size() == fPtMinBin.size() and fEtaMinBin.size() == fConeSizeBin.size() and fEtaMinBin.size() == fRMSPtMinBin.size()
+	 and fEtaMinBin.size() == fRMSScaleFactorBin.size() and fEtaMinBin.size() == fNeutralMinEBin.size() and  fEtaMinBin.size() == fNeutralPtSlope.size() 
+	 and fEtaMinBin.size() == fUseCharged.size()
+	 and fEtaMinBin.size() == fApplyLowPUCorr.size() and fEtaMinBin.size() == fMetricId.size())) {
+      std::cerr<<" Error in PUPPI configuration, algo info should have the same size --> exit from the code"<<std::endl;
+      std::exit(EXIT_FAILURE);
+    }
+  }
+  for( size_t iAlgo =  0 ; iAlgo < fEtaMinBin.size() ; iAlgo++){
+    AlgoObj algoTmp ;
+    algoTmp.etaMin            = fEtaMinBin.at(iAlgo);
+    algoTmp.etaMax            = fEtaMaxBin.at(iAlgo);
+    algoTmp.ptMin             = fPtMinBin.at(iAlgo);
+    algoTmp.minNeutralPt      = fNeutralMinEBin.at(iAlgo);
+    algoTmp.minNeutralPtSlope = fNeutralPtSlope.at(iAlgo);
+    //Eta Extrapolation stuff is missing
+    //Loop through file requiring algos for same bins to be adjacent
+    while(iAlgo < fEtaMinBin.size() and algoTmp.etaMin == fEtaMinBin.at(iAlgo) and algoTmp.etaMax == fEtaMaxBin.at(iAlgo)) { 
+      AlgoSubObj algoSubTmp;
+      algoSubTmp.metricId          = fMetricId.at(iAlgo);
+      algoSubTmp.useCharged        = fUseCharged.at(iAlgo);
+      algoSubTmp.applyLowPUCorr    = fApplyLowPUCorr.at(iAlgo);
+      algoSubTmp.combId            = fCombId.at(iAlgo);
+      algoSubTmp.coneSize          = fConeSizeBin.at(iAlgo);
+      algoSubTmp.rmsPtMin          = fRMSPtMinBin.at(iAlgo);
+      algoSubTmp.rmsScaleFactor    = fRMSScaleFactorBin.at(iAlgo);
+      algoTmp.subAlgos.push_back(algoSubTmp);
+      iAlgo++;
+    }
+    iAlgo--;
+    //if(std::find(puppiAlgo.begin(),puppiAlgo.end(),algoTmp) != puppiAlgo.end()) continue;    
+    puppiAlgo.push_back(algoTmp);     
+  }
+  fPuppi  = new PuppiContainer(true,fUseExp,fMinPuppiWeight,puppiAlgo);
 }
 
@@ -124,10 +150,10 @@
   TLorentzVector momentum;
 
-  DelphesFactory *factory = GetFactory();
+  //DelphesFactory *factory = GetFactory();
 
   // loop over input objects
-  fItTrackInputArray->Reset();
-  fItNeutralInputArray->Reset();
-  fPVItInputArray->Reset();
+  fItTrackInputArray   ->Reset();
+  fItNeutralInputArray ->Reset();
+  fPVItInputArray      ->Reset();
 
   std::vector<Candidate *> InputParticles;
@@ -142,10 +168,8 @@
   std::vector<RecoObj> puppiInputVector;
   puppiInputVector.clear();
-
+  int lNBad  = 0; 
   // Loop on charge track candidate
   while((candidate = static_cast<Candidate*>(fItTrackInputArray->Next()))){   
-
       momentum = candidate->Momentum;
-      
       RecoObj curRecoObj;
       curRecoObj.pt  = momentum.Pt();
@@ -154,7 +178,10 @@
       curRecoObj.m   = momentum.M();  
       particle = static_cast<Candidate*>(candidate->GetCandidates()->Last());
+      //if(fApplyNoLep && TMath::Abs(candidate->PID) == 11) continue; //Dumb cut to minimize the nolepton on electron
+      //if(fApplyNoLep && TMath::Abs(candidate->PID) == 13) continue;
       if (candidate->IsRecoPU and candidate->Charge !=0) { // if it comes fromPU vertexes after the resolution smearing and the dZ matching within resolution
+	lNBad++;
 	curRecoObj.id    = 2;
-	curRecoObj.vtxId = candidate->IsPU;
+	curRecoObj.vtxId = 0.7*(fPVInputArray->GetEntries()); //Hack apply reco vtx efficiency of 70% for calibration
 	if(TMath::Abs(candidate->PID) == 11)      curRecoObj.pfType = 2;
 	else if(TMath::Abs(candidate->PID) == 13) curRecoObj.pfType = 3;
@@ -183,7 +210,5 @@
   // Loop on neutral calo cells 
   while((candidate = static_cast<Candidate*>(fItNeutralInputArray->Next()))){
-
       momentum = candidate->Momentum;
-
       RecoObj curRecoObj;
       curRecoObj.pt  = momentum.Pt();
@@ -191,6 +216,6 @@
       curRecoObj.phi = momentum.Phi();
       curRecoObj.m   = momentum.M();
+      curRecoObj.charge = 0;
       particle = static_cast<Candidate*>(candidate->GetCandidates()->Last());
-
 
       if(candidate->Charge == 0){
@@ -210,38 +235,8 @@
       InputParticles.push_back(candidate);
   }
-
-  // Create algorithm list for puppi
-  std::vector<puppiAlgoBin> puppiAlgo;
-  if(puppiAlgo.empty()){
-   if(!(fEtaMinBin.size() == fEtaMaxBin.size() and fEtaMinBin.size() == fPtMinBin.size() and fEtaMinBin.size() == fConeSizeBin.size() and fEtaMinBin.size() == fRMSPtMinBin.size()
-       and fEtaMinBin.size() == fRMSScaleFactorBin.size() and fEtaMinBin.size() == fNeutralMinEBin.size() and  fEtaMinBin.size() == fNeutralPtSlope.size() 
-       and fEtaMinBin.size() == fApplyCHS.size()  and fEtaMinBin.size() == fUseCharged.size()
-       and fEtaMinBin.size() == fApplyLowPUCorr.size() and fEtaMinBin.size() == fMetricId.size())) {
-    std::cerr<<" Error in PUPPI configuration, algo info should have the same size --> exit from the code"<<std::endl;
-    std::exit(EXIT_FAILURE);
-   } 
-
-   for( size_t iAlgo =  0 ; iAlgo < fEtaMinBin.size() ; iAlgo++){
-    puppiAlgoBin algoTmp ;
-    algoTmp.fEtaMin_ = fEtaMinBin.at(iAlgo);
-    algoTmp.fEtaMax_ = fEtaMaxBin.at(iAlgo);
-    algoTmp.fPtMin_  = fPtMinBin.at(iAlgo);
-    algoTmp.fConeSize_        = fConeSizeBin.at(iAlgo);
-    algoTmp.fRMSPtMin_        = fRMSPtMinBin.at(iAlgo);
-    algoTmp.fRMSScaleFactor_  = fRMSScaleFactorBin.at(iAlgo);
-    algoTmp.fNeutralMinE_     = fNeutralMinEBin.at(iAlgo);
-    algoTmp.fNeutralPtSlope_  = fNeutralPtSlope.at(iAlgo);
-    algoTmp.fApplyCHS_        = fApplyCHS.at(iAlgo);
-    algoTmp.fUseCharged_      = fUseCharged.at(iAlgo);
-    algoTmp.fApplyLowPUCorr_  = fApplyLowPUCorr.at(iAlgo);
-    algoTmp.fMetricId_        = fMetricId.at(iAlgo);
-    if(std::find(puppiAlgo.begin(),puppiAlgo.end(),algoTmp) != puppiAlgo.end()) continue;    
-    puppiAlgo.push_back(algoTmp);     
-   }
-  }  
-
   // Create PUPPI container
-  puppiCleanContainer curEvent(puppiInputVector,puppiAlgo,fMinPuppiWeight,fUseExp);
-  std::vector<fastjet::PseudoJet> puppiParticles = curEvent.puppiEvent();
+  fPuppi->initialize(puppiInputVector);
+  fPuppi->puppiWeights();
+  std::vector<fastjet::PseudoJet> puppiParticles = fPuppi->puppiParticles();
 
   // Loop on final particles
Index: modules/RunPUPPI.h
===================================================================
--- modules/RunPUPPI.h	(revision 4406bf83d2a69fe8b8d556318684ee1f85a8befb)
+++ modules/RunPUPPI.h	(revision 4a0d9d51f8985207061b5b889b9e4cd4faba0d82)
@@ -3,4 +3,5 @@
 
 #include "classes/DelphesModule.h"
+#include "PUPPI/PuppiContainer.hh"
 #include <vector>
 
@@ -29,7 +30,8 @@
   const TObjArray *fNeutralInputArray; //!
   const TObjArray *fPVInputArray; //!                                                                                                                                                     
- 
+  PuppiContainer* fPuppi;
   // puppi parameters
-  float fMinPuppiWeight;
+  bool fApplyNoLep;
+  double fMinPuppiWeight;
   bool fUseExp;
   
@@ -46,4 +48,5 @@
   std::vector<bool>  fApplyLowPUCorr;
   std::vector<int>   fMetricId;
+  std::vector<int>   fCombId;
 
   TObjArray *fOutputArray;
Index: modules/SimpleCalorimeter.cc
===================================================================
--- modules/SimpleCalorimeter.cc	(revision 4406bf83d2a69fe8b8d556318684ee1f85a8befb)
+++ modules/SimpleCalorimeter.cc	(revision 4a0d9d51f8985207061b5b889b9e4cd4faba0d82)
@@ -504,6 +504,9 @@
     tower->Eem = (!fIsEcal) ? 0 : energy;
     tower->Ehad = (fIsEcal) ? 0 : energy;
-
+    
     tower->Momentum.SetPtEtaPhiE(pt, eta, phi, energy);
+    
+    tower->PID = (fIsEcal) ? 22 : 0;
+    
     fEFlowTowerOutputArray->Add(tower);
   }
