Index: modules/PileUpJetID.cc
===================================================================
--- modules/PileUpJetID.cc	(revision 3db52828f2d0c59e2c96ba61afc99dc49156477d)
+++ modules/PileUpJetID.cc	(revision 28627706f1b8299e53bd6fe7bed07fea66cc20cf)
@@ -1,26 +1,8 @@
-/*
- *  Delphes: a framework for fast simulation of a generic collider experiment
- *  Copyright (C) 2012-2014  Universite catholique de Louvain (UCL), Belgium
- *
- *  This program is free software: you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
 
 /** \class PileUpJetID
  *
- *  CMS PileUp Jet ID Variables, based on http://cds.cern.ch/record/1581583
+ *  CMS PileUp Jet ID Variables
  *
- *  \author S. Zenz, December 2013
+ *  \author S. Zenz
  *
  */
@@ -41,5 +23,5 @@
 #include "TRandom3.h"
 #include "TObjArray.h"
-#include "TDatabasePDG.h"
+//#include "TDatabasePDG.h"
 #include "TLorentzVector.h"
 
@@ -54,5 +36,5 @@
 
 PileUpJetID::PileUpJetID() :
-  fItJetInputArray(0),fTrackInputArray(0),fNeutralInputArray(0),fItVertexInputArray(0)
+  fItJetInputArray(0),fTrackInputArray(0),fNeutralInputArray(0)
 {
 
@@ -70,8 +52,36 @@
 void PileUpJetID::Init()
 {
+
   fJetPTMin = GetDouble("JetPTMin", 20.0);
   fParameterR = GetDouble("ParameterR", 0.5);
   fUseConstituents = GetInt("UseConstituents", 0);
 
+
+  /*
+  Double_t fMeanSqDeltaRMaxBarrel; // |eta| < 1.5
+  Double_t fBetaMinBarrel; // |eta| < 2.5
+  Double_t fMeanSqDeltaRMaxEndcap; // 1.5 < |eta| < 4.0
+  Double_t fBetaMinEndcap; // 1.5 < |eta| < 4.0
+  Double_t fMeanSqDeltaRMaxForward; // |eta| > 4.0
+  */
+
+  fMeanSqDeltaRMaxBarrel = GetDouble("MeanSqDeltaRMaxBarrel",0.1);
+  fBetaMinBarrel = GetDouble("BetaMinBarrel",0.1);
+  fMeanSqDeltaRMaxEndcap = GetDouble("MeanSqDeltaRMaxEndcap",0.1);
+  fBetaMinEndcap = GetDouble("BetaMinEndcap",0.1);
+  fMeanSqDeltaRMaxForward = GetDouble("MeanSqDeltaRMaxForward",0.1);
+  fJetPTMinForNeutrals = GetDouble("JetPTMinForNeutrals", 20.0);
+  fNeutralPTMin = GetDouble("NeutralPTMin", 2.0);
+
+
+
+  cout << "  set MeanSqDeltaRMaxBarrel " << fMeanSqDeltaRMaxBarrel << endl;
+  cout << "  set BetaMinBarrel " << fBetaMinBarrel << endl;
+  cout << "  set MeanSqDeltaRMaxEndcap " << fMeanSqDeltaRMaxEndcap << endl;
+  cout << "  set BetaMinEndcap " << fBetaMinEndcap << endl;
+  cout << "  set MeanSqDeltaRMaxForward " << fMeanSqDeltaRMaxForward << endl;
+
+
+
   fAverageEachTower = false; // for timing
 
@@ -81,18 +91,25 @@
   fItJetInputArray = fJetInputArray->MakeIterator();
 
-  fTrackInputArray = ImportArray(GetString("TrackInputArray", "Calorimeter/eflowTracks"));
+
+  //  cout << "BeforE SCZ additions in init" << endl;
+  //  cout << GetString("TrackInputArray", "ParticlePropagator/tracks") << endl;
+  //  cout << GetString("EFlowTrackInputArray", "ParticlePropagator/tracks") << endl;
+
+  fTrackInputArray = ImportArray(GetString("TrackInputArray", "ParticlePropagator/tracks"));
   fItTrackInputArray = fTrackInputArray->MakeIterator();
 
-  fNeutralInputArray = ImportArray(GetString("NeutralInputArray", "Calorimeter/eflowTowers"));
+  fNeutralInputArray = ImportArray(GetString("NeutralInputArray", "ParticlePropagator/tracks"));
   fItNeutralInputArray = fNeutralInputArray->MakeIterator();
 
-  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"));
+
+  fNeutralsInPassingJets = ExportArray(GetString("NeutralsInPassingJets","eflowtowers"));
+
+
+  //  cout << " end of INIT " << endl;
+
 }
 
@@ -101,8 +118,10 @@
 void PileUpJetID::Finish()
 {
+  //  cout << "In finish" << endl;
+
   if(fItJetInputArray) delete fItJetInputArray;
   if(fItTrackInputArray) delete fItTrackInputArray;
   if(fItNeutralInputArray) delete fItNeutralInputArray;
-  if(fItVertexInputArray) delete fItVertexInputArray;
+
 }
 
@@ -111,24 +130,13 @@
 void PileUpJetID::Process()
 {
+  //  cout << "start of process" << endl;
+
   Candidate *candidate, *constituent;
   TLorentzVector momentum, area;
-  Int_t i, nc, nn;
-  Double_t sumpt, sumptch, sumptchpv, sumptchpu, sumdrsqptsq, sumptsq;
-  Double_t dr, pt, pt_ann[5];
-  Double_t zvtx = 0.0;
-
-  Candidate *track;
-
-  // find z position of primary vertex
-
-  fItVertexInputArray->Reset();
-  while((candidate = static_cast<Candidate*>(fItVertexInputArray->Next())))
-  {
-    if(!candidate->IsPU)
-    {
-      zvtx = candidate->Position.Z();
-      break;
-    }
-  }
+
+  //  cout << "BeforE SCZ additions in process" << endl;
+
+  // SCZ
+  Candidate *trk;
 
   // loop over all input candidates
@@ -139,152 +147,197 @@
     area = candidate->Area;
 
-    sumpt = 0.0;
-    sumptch = 0.0;
-    sumptchpv = 0.0;
-    sumptchpu = 0.0;
-    sumdrsqptsq = 0.0;
-    sumptsq = 0.0;
-    nc = 0;
-    nn = 0;
-
-    for(i = 0; i < 5; ++i)
-    {
-      pt_ann[i] = 0.0;
-    }
-
-    if(fUseConstituents)
-    {
+    float sumT0 = 0.;
+    float sumT1 = 0.;
+    float sumT10 = 0.;
+    float sumT20 = 0.;
+    float sumT30 = 0.;
+    float sumT40 = 0.;
+    float sumWeightsForT = 0.;
+    candidate->Ntimes = 0;
+
+    float sumpt = 0.;
+    float sumptch = 0.;
+    float sumptchpv = 0.;
+    float sumptchpu = 0.;
+    float sumdrsqptsq = 0.;
+    float sumptsq = 0.;
+    int nc = 0;
+    int nn = 0;
+    float pt_ann[5];
+
+    for (int i = 0 ; i < 5 ; i++) {
+      pt_ann[i] = 0.;
+    }
+
+    if (fUseConstituents) {
       TIter itConstituents(candidate->GetCandidates());
-      while((constituent = static_cast<Candidate*>(itConstituents.Next())))
-      {
-        pt = constituent->Momentum.Pt();
-        dr = candidate->Momentum.DeltaR(constituent->Momentum);
-        sumpt += pt;
-        sumdrsqptsq += dr*dr*pt*pt;
-        sumptsq += pt*pt;
-        if(constituent->Charge == 0)
-        {
-          // neutrals
-          ++nn;
-        }
-        else
-        {
-          // charged
-          if(constituent->IsPU && TMath::Abs(constituent->Position.Z()-zvtx) > fZVertexResolution)
-          {
-            sumptchpu += pt;
-          }
-          else
-          {
-            sumptchpv += pt;
-          }
-          sumptch += pt;
-          ++nc;
-        }
-        for(i = 0; i < 5; ++i)
-        {
-          if(dr > 0.1*i && dr < 0.1*(i + 1))
-          {
-            pt_ann[i] += pt;
-          }
-        }
-      }
-    }
-    else
-    {
+      while((constituent = static_cast<Candidate*>(itConstituents.Next()))) {
+        float pt = constituent->Momentum.Pt();
+        float dr = candidate->Momentum.DeltaR(constituent->Momentum);
+	//	cout << " There exists a constituent with dr=" << dr << endl;
+	sumpt += pt;
+	sumdrsqptsq += dr*dr*pt*pt;
+	sumptsq += pt*pt;
+	if (constituent->Charge == 0) {
+	  nn++;
+	} else {
+	  if (constituent->IsRecoPU) {
+	    sumptchpu += pt;
+	  } else {
+	    sumptchpv += pt;
+	  }
+	  sumptch += pt;
+	  nc++;
+	}
+	for (int i = 0 ; i < 5 ; i++) {
+	  if (dr > 0.1*i && dr < 0.1*(i+1)) {
+	    pt_ann[i] += pt;
+	  }
+	}
+	float tow_sumT = 0;
+	float tow_sumW = 0;
+	for (int i = 0 ; i < constituent->Ecal_E_t.size() ; i++) {
+	  float w = TMath::Sqrt(constituent->Ecal_E_t[i].first);
+	  if (fAverageEachTower) {
+            tow_sumT += w*constituent->Ecal_E_t[i].second;
+            tow_sumW += w;
+	  } else {
+	    sumT0 += w*constituent->Ecal_E_t[i].second;
+	    sumT1 += w*gRandom->Gaus(constituent->Ecal_E_t[i].second,0.001);
+	    sumT10 += w*gRandom->Gaus(constituent->Ecal_E_t[i].second,0.010);
+	    sumT20 += w*gRandom->Gaus(constituent->Ecal_E_t[i].second,0.020);
+	    sumT30 += w*gRandom->Gaus(constituent->Ecal_E_t[i].second,0.030);
+	    sumT40 += w*gRandom->Gaus(constituent->Ecal_E_t[i].second,0.040);
+	    sumWeightsForT += w;
+	    candidate->Ntimes++;
+	  }
+	}
+	if (fAverageEachTower && tow_sumW > 0.) {
+	  sumT0 += tow_sumT;
+	  sumT1 += tow_sumW*gRandom->Gaus(tow_sumT/tow_sumW,0.001);
+          sumT10 += tow_sumW*gRandom->Gaus(tow_sumT/tow_sumW,0.0010);
+          sumT20 += tow_sumW*gRandom->Gaus(tow_sumT/tow_sumW,0.0020);
+          sumT30 += tow_sumW*gRandom->Gaus(tow_sumT/tow_sumW,0.0030);
+          sumT40 += tow_sumW*gRandom->Gaus(tow_sumT/tow_sumW,0.0040);
+	  sumWeightsForT += tow_sumW;
+	  candidate->Ntimes++;
+	}
+      }
+    } else {
       // Not using constituents, using dr
       fItTrackInputArray->Reset();
-      while((track = static_cast<Candidate*>(fItTrackInputArray->Next())))
-      {
-        if(track->Momentum.DeltaR(candidate->Momentum) < fParameterR)
-        {
-          pt = track->Momentum.Pt();
-          sumpt += pt;
-          sumptch += pt;
-          if(track->IsPU && TMath::Abs(track->Position.Z()-zvtx) > fZVertexResolution)
-          {
-            sumptchpu += pt;
-          }
-          else
-          {
-            sumptchpv += pt;
-          }
-          dr = candidate->Momentum.DeltaR(track->Momentum);
-          sumdrsqptsq += dr*dr*pt*pt;
-          sumptsq += pt*pt;
-          nc++;
-          for(i = 0; i < 5; ++i)
-          {
-            if(dr > 0.1*i && dr < 0.1*(i + 1))
-            {
-              pt_ann[i] += pt;
-            }
-          }
-        }
-      }
-
+      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->IsRecoPU) {
+	    sumptchpu += pt;
+	  } else {
+	    sumptchpv += pt;
+	  }
+	  float dr = candidate->Momentum.DeltaR(trk->Momentum);
+	  sumdrsqptsq += dr*dr*pt*pt;
+	  sumptsq += pt*pt;
+	  nc++;
+	  for (int i = 0 ; i < 5 ; i++) {
+	    if (dr > 0.1*i && dr < 0.1*(i+1)) {
+	      pt_ann[i] += pt;
+	    }
+	  }
+	}
+      }
       fItNeutralInputArray->Reset();
-      while ((constituent = static_cast<Candidate*>(fItNeutralInputArray->Next())))
-      {
-        if(constituent->Momentum.DeltaR(candidate->Momentum) < fParameterR)
-        {
-          pt = constituent->Momentum.Pt();
-          sumpt += pt;
-          dr = candidate->Momentum.DeltaR(constituent->Momentum);
-          sumdrsqptsq += dr*dr*pt*pt;
-          sumptsq += pt*pt;
-          nn++;
-          for(i = 0; i < 5; ++i)
-          {
-            if(dr > 0.1*i && dr < 0.1*(i + 1))
-            {
-              pt_ann[i] += pt;
-            }
-          }
-        }
-      }
-    }
-
-    if(sumptch > 0.0)
-    {
-      candidate->Beta = sumptchpu/sumptch;
-      candidate->BetaStar = sumptchpv/sumptch;
-    }
-    else
-    {
-      candidate->Beta = -999.0;
-      candidate->BetaStar = -999.0;
-    }
-    if(sumptsq > 0.0)
-    {
+      while ((constituent = static_cast<Candidate*>(fItNeutralInputArray->Next()))) {
+	if (constituent->Momentum.DeltaR(candidate->Momentum) < fParameterR) {
+	  float pt = constituent->Momentum.Pt();
+	  sumpt += pt;
+	  float dr = candidate->Momentum.DeltaR(constituent->Momentum);
+	  sumdrsqptsq += dr*dr*pt*pt;
+	  sumptsq += pt*pt;
+	  nn++;
+	  for (int i = 0 ; i < 5 ; i++) {
+	    if (dr > 0.1*i && dr < 0.1*(i+1)) {
+            pt_ann[i] += pt;
+	    }
+	  }
+	}
+      }
+    }
+
+    if (sumptch > 0.) {
+      candidate->Beta = sumptchpv/sumptch;
+      candidate->BetaStar = sumptchpu/sumptch;
+    } else {
+      candidate->Beta = -999.;
+      candidate->BetaStar = -999.;
+    }
+    if (sumptsq > 0.) {
       candidate->MeanSqDeltaR = sumdrsqptsq/sumptsq;
-    }
-    else
-    {
-      candidate->MeanSqDeltaR = -999.0;
+    } else {
+      candidate->MeanSqDeltaR = -999.;
     }
     candidate->NCharged = nc;
     candidate->NNeutrals = nn;
-    if(sumpt > 0.0)
-    {
+    if (sumpt > 0.) {
       candidate->PTD = TMath::Sqrt(sumptsq) / sumpt;
-      for(i = 0; i < 5; ++i)
-      {
+      for (int i = 0 ; i < 5 ; i++) {
         candidate->FracPt[i] = pt_ann[i]/sumpt;
       }
-    }
-    else
-    {
-      candidate->PTD = -999.0;
-      for(i = 0; i < 5; ++i)
-      {
-        candidate->FracPt[i] = -999.0;
+    } else {
+      candidate->PTD = -999.;
+      for (int i = 0 ; i < 5 ; i++) {
+        candidate->FracPt[i] = -999.;
       }
     }
 
     fOutputArray->Add(candidate);
+
+    // New stuff
+    /*
+    fMeanSqDeltaRMaxBarrel = GetDouble("MeanSqDeltaRMaxBarrel",0.1);
+    fBetaMinBarrel = GetDouble("BetaMinBarrel",0.1);
+    fMeanSqDeltaRMaxEndcap = GetDouble("MeanSqDeltaRMaxEndcap",0.1);
+    fBetaMinEndcap = GetDouble("BetaMinEndcap",0.1);
+    fMeanSqDeltaRMaxForward = GetDouble("MeanSqDeltaRMaxForward",0.1);
+    */
+
+    bool passId = false;
+    if (candidate->Momentum.Pt() > fJetPTMinForNeutrals && candidate->MeanSqDeltaR > -0.1) {
+      if (fabs(candidate->Momentum.Eta())<1.5) {
+	passId = ((candidate->Beta > fBetaMinBarrel) && (candidate->MeanSqDeltaR < fMeanSqDeltaRMaxBarrel));
+      } else if (fabs(candidate->Momentum.Eta())<4.0) {
+	passId = ((candidate->Beta > fBetaMinEndcap) && (candidate->MeanSqDeltaR < fMeanSqDeltaRMaxEndcap));
+      } else {
+	passId = (candidate->MeanSqDeltaR < fMeanSqDeltaRMaxForward);
+      }
+    }
+
+    //    cout << " Pt Eta MeanSqDeltaR Beta PassId " << candidate->Momentum.Pt() 
+    //	 << " " << candidate->Momentum.Eta() << " " << candidate->MeanSqDeltaR << " " << candidate->Beta << " " << passId << endl;
+
+    if (passId) {
+      if (fUseConstituents) {
+	TIter itConstituents(candidate->GetCandidates());
+	while((constituent = static_cast<Candidate*>(itConstituents.Next()))) {
+	  if (constituent->Charge == 0 && constituent->Momentum.Pt() > fNeutralPTMin) {
+	    fNeutralsInPassingJets->Add(constituent);
+	    //	    cout << "    Constitutent added Pt Eta Charge " << constituent->Momentum.Pt() << " " << constituent->Momentum.Eta() << " " << constituent->Charge << endl;
+	  }
+	}
+      } else { // use DeltaR
+	fItNeutralInputArray->Reset();
+	while ((constituent = static_cast<Candidate*>(fItNeutralInputArray->Next()))) {
+	  if (constituent->Momentum.DeltaR(candidate->Momentum) < fParameterR && constituent->Momentum.Pt() > fNeutralPTMin) {
+	    fNeutralsInPassingJets->Add(constituent);
+	    //            cout << "    Constitutent added Pt Eta Charge " << constituent->Momentum.Pt() << " " << constituent->Momentum.Eta() << " " << constituent->Charge << endl;
+	  }
+	}
+      }
+    }
+
+
   }
 }
 
 //------------------------------------------------------------------------------
-
Index: modules/PileUpJetID.h
===================================================================
--- modules/PileUpJetID.h	(revision 3db52828f2d0c59e2c96ba61afc99dc49156477d)
+++ modules/PileUpJetID.h	(revision 28627706f1b8299e53bd6fe7bed07fea66cc20cf)
@@ -1,20 +1,2 @@
-/*
- *  Delphes: a framework for fast simulation of a generic collider experiment
- *  Copyright (C) 2012-2014  Universite catholique de Louvain (UCL), Belgium
- *
- *  This program is free software: you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
 #ifndef PileUpJetID_h
 #define PileUpJetID_h
@@ -22,7 +4,7 @@
 /** \class PileUpJetID
  *
- *  CMS PileUp Jet ID Variables, based on http://cds.cern.ch/record/1581583
+ *  CMS PileUp Jet ID Variables
  *
- *  \author S. Zenz, December 2013
+ *  \author S. Zenz
  *
  */
@@ -34,4 +16,5 @@
 
 class TObjArray;
+class DelphesFormula;
 
 class PileUpJetID: public DelphesModule
@@ -51,8 +34,59 @@
   Double_t fParameterR;
 
+  Double_t fMeanSqDeltaRMaxBarrel; // |eta| < 1.5
+  Double_t fBetaMinBarrel; // |eta| < 2.5
+  Double_t fMeanSqDeltaRMaxEndcap; // 1.5 < |eta| < 4.0
+  Double_t fBetaMinEndcap; // 1.5 < |eta| < 4.0
+  Double_t fMeanSqDeltaRMaxForward; // |eta| > 4.0
+
+  Double_t fNeutralPTMin;
+  Double_t fJetPTMinForNeutrals;
+
+  /*
+JAY
+---
+
+|Eta|<1.5
+
+meanSqDeltaR betaStar SigEff BgdEff
+0.13 0.92 96% 8%
+0.13 0.95 97% 16%
+0.13 0.97 98% 27%
+
+|Eta|>1.5
+
+meanSqDeltaR betaStar SigEff BgdEff
+0.14 0.91 95% 15%
+0.14 0.94 97% 19%
+0.14 0.97 98% 29%
+
+BRYAN
+-----
+
+Barrel (MeanSqDR, Beta, sig eff, bg eff): 
+0.10, 0.08, 90%, 8%
+0.11, 0.12, 90%, 6%
+0.13, 0.16, 89%, 5%
+
+Endcap (MeanSqDR, Beta, sig eff, bg eff):
+0.07, 0.06, 89%, 4%
+0.08, 0.08, 92%, 6%
+0.09, 0.08, 95%, 10%
+0.10, 0.08, 97%, 13%
+
+SETH GUESSES FOR |eta| > 4.0
+----------------------------
+
+MeanSqDeltaR 
+0.07 
+0.10 
+0.14 
+0.2
+  */
+
   // If set to true, may have weird results for PFCHS
   // If set to false, uses everything within dR < fParameterR even if in other jets &c.
   // Results should be very similar for PF
-  Int_t fUseConstituents;
+  Int_t fUseConstituents; 
 
   Bool_t fAverageEachTower;
@@ -62,20 +96,16 @@
   const TObjArray *fJetInputArray; //!
 
-  const TObjArray *fTrackInputArray; //!
-  const TObjArray *fNeutralInputArray; //!
+  const TObjArray *fTrackInputArray; // SCZ
+  const TObjArray *fNeutralInputArray; 
 
-  TIterator *fItTrackInputArray; //!
-  TIterator *fItNeutralInputArray; //!
+  TIterator *fItTrackInputArray; // SCZ
+  TIterator *fItNeutralInputArray; // SCZ
 
   TObjArray *fOutputArray; //!
+  TObjArray *fNeutralsInPassingJets; // SCZ
 
-  TIterator *fItVertexInputArray; //!
-  const TObjArray *fVertexInputArray; //!
 
-  Double_t fZVertexResolution;
-
-  ClassDef(PileUpJetID, 1)
+  ClassDef(PileUpJetID, 2)
 };
 
 #endif
-
