Index: /trunk/examples/delphes_card_CMS_PileUp.tcl
===================================================================
--- /trunk/examples/delphes_card_CMS_PileUp.tcl	(revision 1348)
+++ /trunk/examples/delphes_card_CMS_PileUp.tcl	(revision 1349)
@@ -25,4 +25,5 @@
   Rho
   FastJetFinder
+  PileUpJetID
   JetPileUpSubtractor
 
@@ -61,5 +62,5 @@
 
   # pre-generated minbias input file
-  set PileUpFile MinBias.pileup
+  set PileUpFile ../../Delphes/MinBias.pileup
 
   # average expected pile up
@@ -325,5 +326,6 @@
   add InputArray ElectronEnergySmearing/electrons electrons
   add InputArray MuonMomentumSmearing/muons muons
-
+  
+  set VertexInputArray PileUpMerger/vertices
   # assume perfect pile-up subtraction for tracks with |z| > fZVertexResolution
   # Z vertex resolution in m
@@ -404,9 +406,31 @@
 
 ###########################
+# Jet Pile-Up ID
+###########################
+
+module PileUpJetID PileUpJetID {
+  set JetInputArray FastJetFinder/jets
+  set TrackInputArray Calorimeter/eflowTracks
+  set NeutralInputArray Calorimeter/eflowTowers
+
+  set VertexInputArray PileUpMerger/vertices
+  # assume perfect pile-up subtraction for tracks with |z| > fZVertexResolution
+  # Z vertex resolution in m
+  set ZVertexResolution 0.0001
+  
+  set OutputArray jets
+
+  set UseConstituents 0
+  set ParameterR 0.5
+
+  set JetPTMin 20.0
+}
+
+###########################
 # Jet Pile-Up Subtraction
 ###########################
 
 module JetPileUpSubtractor JetPileUpSubtractor {
-  set JetInputArray FastJetFinder/jets
+  set JetInputArray PileUpJetID/jets
   set RhoInputArray Rho/rho
 
Index: /trunk/modules/PileUpJetID.cc
===================================================================
--- /trunk/modules/PileUpJetID.cc	(revision 1348)
+++ /trunk/modules/PileUpJetID.cc	(revision 1349)
@@ -36,5 +36,5 @@
 
 PileUpJetID::PileUpJetID() :
-  fItJetInputArray(0),fTrackInputArray(0),fNeutralInputArray(0)
+  fItJetInputArray(0),fTrackInputArray(0),fNeutralInputArray(0),fItVertexInputArray(0) 
 {
 
@@ -68,6 +68,10 @@
   fNeutralInputArray = ImportArray(GetString("NeutralInputArray", "Calorimeter/eflowTowers"));
   fItNeutralInputArray = fNeutralInputArray->MakeIterator();
-
-  // create output array(s)
+  
+  fVertexInputArray = ImportArray(GetString("VertexInputArray", "PileUpMerger/vertices"));
+  fItVertexInputArray = fVertexInputArray->MakeIterator();
+  
+  fZVertexResolution  = GetDouble("ZVertexResolution", 0.005)*1.0E3;
+// create output array(s)
 
   fOutputArray = ExportArray(GetString("OutputArray", "jets"));
@@ -83,4 +87,5 @@
   if(fItTrackInputArray) delete fItTrackInputArray;
   if(fItNeutralInputArray) delete fItNeutralInputArray;
+  if(fItVertexInputArray) delete fItVertexInputArray;
 
 }
@@ -92,6 +97,19 @@
   Candidate *candidate, *constituent;
   TLorentzVector momentum, area;
+  Double_t zvtx=0;
 
   Candidate *trk;
+
+ // find z position of primary vertex
+   
+  fItVertexInputArray->Reset();
+  while((candidate = static_cast<Candidate*>(fItVertexInputArray->Next())))
+  {
+    if(!candidate->IsPU)
+    {
+    zvtx = candidate->Position.Z();
+    break;
+    }
+  }
 
   // loop over all input candidates
@@ -129,5 +147,5 @@
 	} else {
 	  // charged
-	  if (constituent->IsPU) {
+	  if (constituent->IsPU && TMath::Abs(constituent->Position.Z()-zvtx) > fZVertexResolution) {
 	    sumptchpu += pt;
 	  } else {
@@ -146,10 +164,10 @@
       // Not using constituents, using dr
       fItTrackInputArray->Reset();
-      while ((trk = static_cast<Candidate*>(fItTrackInputArray->Next()))) {
+       while ((trk = static_cast<Candidate*>(fItTrackInputArray->Next()))) {
 	if (trk->Momentum.DeltaR(candidate->Momentum) < fParameterR) {
 	  float pt = trk->Momentum.Pt();
 	  sumpt += pt;
 	  sumptch += pt;
-	  if (trk->IsPU) {
+	  if (trk->IsPU && TMath::Abs(trk->Position.Z()-zvtx) > fZVertexResolution) {
 	    sumptchpu += pt;
 	  } else {
Index: /trunk/modules/PileUpJetID.h
===================================================================
--- /trunk/modules/PileUpJetID.h	(revision 1348)
+++ /trunk/modules/PileUpJetID.h	(revision 1349)
@@ -53,5 +53,9 @@
 
   TObjArray *fOutputArray; //!
+  
+  TIterator *fItVertexInputArray; //!
+  const TObjArray *fVertexInputArray; //!
 
+  Double_t fZVertexResolution;
 
   ClassDef(PileUpJetID, 1)
Index: /trunk/modules/TrackPileUpSubtractor.cc
===================================================================
--- /trunk/modules/TrackPileUpSubtractor.cc	(revision 1348)
+++ /trunk/modules/TrackPileUpSubtractor.cc	(revision 1349)
@@ -110,11 +110,10 @@
   while((candidate = static_cast<Candidate*>(fItVertexInputArray->Next())))
   {
-    if(candidate->IsPU == 0)
+    if(!candidate->IsPU)
     {
     zvtx = candidate->Position.Z();
-    break;
+    // break;
     }
   }
-
 
   // loop over all input arrays
@@ -130,7 +129,8 @@
       particle = static_cast<Candidate*>(candidate->GetCandidates()->At(0));
       z = particle->Position.Z();
-
+      
       // apply pile-up subtraction
       // assume perfect pile-up subtraction for tracks outside fZVertexResolution
+      
       if(candidate->IsPU && TMath::Abs(z-zvtx) > fZVertexResolution) continue;
 
