Index: modules/RunPUPPI.cc
===================================================================
--- modules/RunPUPPI.cc	(revision 7e227ae16c60893a6c2f0961e63583a79e2759a1)
+++ modules/RunPUPPI.cc	(revision 7b45ff5e3840b1a7e6b83f7376cdb74e900f182c)
@@ -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 7e227ae16c60893a6c2f0961e63583a79e2759a1)
+++ modules/RunPUPPI.h	(revision 7b45ff5e3840b1a7e6b83f7376cdb74e900f182c)
@@ -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;
