Index: cards/CMS_PhaseII/CMS_PhaseII_200PU_v03.tcl
===================================================================
--- cards/CMS_PhaseII/CMS_PhaseII_200PU_v03.tcl	(revision 5b51d33750bc7415d4ede53ce13067db637a5a11)
+++ cards/CMS_PhaseII/CMS_PhaseII_200PU_v03.tcl	(revision ec37bc3202fb17e911b9602b03a7044a2e62d42f)
@@ -1,2 +1,6 @@
+set RandomSeed 123
+set MaxEvents 10
+
+########################################
 #
 #  Main authors: Michele Selvaggi (CERN)
@@ -15,4 +19,9 @@
   PileUpMerger
   ParticlePropagator
+  TrackMergerProp
+
+  DenseProp
+  DenseMergeTracks
+  DenseTrackFilter
 
   ChargedHadronTrackingEfficiency
@@ -24,11 +33,10 @@
   MuonMomentumSmearing
 
-  DenseProp
-  DenseMergeTracks
-  TrackMergerProp
   TrackMerger
 
   ECal
   HCal
+
+  MuonFilter
 
   PhotonEnergySmearing
@@ -182,4 +190,90 @@
 
 
+##############
+# Track merger
+##############
+
+module Merger TrackMergerProp {
+# add InputArray InputArray
+  add InputArray ParticlePropagator/chargedHadrons
+  add InputArray ParticlePropagator/electrons
+  add InputArray ParticlePropagator/muons
+  set OutputArray tracks
+}
+
+
+#################################
+# Dense Track propagation
+#################################
+
+module ParticlePropagator DenseProp {
+
+  set InputArray TrackMergerProp/tracks
+
+  set OutputArray stableParticles
+  set NeutralOutputArray neutralParticles
+  set ChargedHadronOutputArray chargedHadrons
+  set ElectronOutputArray electrons
+  set MuonOutputArray muons
+
+  # radius of the first pixel layer
+  set Radius 0.3
+  set RadiusMax 1.29
+  # half-length of the magnetic field coverage, in m
+  set HalfLength 0.7
+  set HalfLengthMax 3.0
+
+  # magnetic field
+  set Bz 3.8
+}
+
+
+####################
+# Dense Track merger
+###################
+
+module Merger DenseMergeTracks {
+# add InputArray InputArray
+  add InputArray DenseProp/chargedHadrons
+  add InputArray DenseProp/electrons
+  add InputArray DenseProp/muons
+  set OutputArray tracks
+}
+
+######################
+#   Dense Track Filter
+######################
+
+module DenseTrackFilter DenseTrackFilter {
+  set TrackInputArray DenseMergeTracks/tracks
+  set TrackOutputArray tracks
+
+  set ChargedHadronOutputArray chargedHadrons
+  set ElectronOutputArray electrons
+  set MuonOutputArray muons
+
+  set EtaPhiRes 0.003
+  set EtaMax 4.0
+
+  set pi [expr {acos(-1)}]
+
+  set nbins_phi [expr {$pi/$EtaPhiRes} ]
+  set nbins_phi [expr {int($nbins_phi)} ]
+
+  set PhiBins {}
+  for {set i -$nbins_phi} {$i <= $nbins_phi} {incr i} {
+    add PhiBins [expr {$i * $pi/$nbins_phi}]
+  }
+
+  set nbins_eta [expr {$EtaMax/$EtaPhiRes} ]
+  set nbins_eta [expr {int($nbins_eta)} ]
+
+  for {set i -$nbins_eta} {$i <= $nbins_eta} {incr i} {
+    set eta [expr {$i * $EtaPhiRes}]
+    add EtaPhiBins $eta $PhiBins
+  }
+
+}
+
 
 
@@ -190,5 +284,5 @@
 module Efficiency ChargedHadronTrackingEfficiency {
   ## particles after propagation
-  set InputArray  ParticlePropagator/chargedHadrons
+  set InputArray  DenseTrackFilter/chargedHadrons
   set OutputArray chargedHadrons
   # tracking efficiency formula for charged hadrons
@@ -211,5 +305,5 @@
 
 module Efficiency ElectronTrackingEfficiency {
-  set InputArray  ParticlePropagator/electrons
+  set InputArray  DenseTrackFilter/electrons
   set OutputArray electrons
   # tracking efficiency formula for electrons
@@ -234,5 +328,5 @@
 
 module Efficiency MuonTrackingEfficiency {
-  set InputArray ParticlePropagator/muons
+  set InputArray DenseTrackFilter/muons
   set OutputArray muons
   # tracking efficiency formula for muons
@@ -351,4 +445,17 @@
 }
 
+
+##############
+# Track merger
+##############
+
+module Merger TrackMerger {
+# add InputArray InputArray
+  add InputArray ChargedHadronMomentumSmearing/chargedHadrons
+  add InputArray ElectronEnergySmearing/electrons
+  add InputArray MuonMomentumSmearing/muons
+  set OutputArray tracks
+}
+
 #################################
 # Energy resolution for electrons
@@ -390,85 +497,5 @@
 }
 
-##############
-# Track merger
-##############
-
-module Merger TrackMergerProp {
-# add InputArray InputArray
-  add InputArray ChargedHadronMomentumSmearing/chargedHadrons
-  add InputArray ElectronEnergySmearing/electrons
-  add InputArray MuonMomentumSmearing/muons
-  set OutputArray tracks
-}
-
-
-#################################
-# Dense Track propagation
-#################################
-
-module ParticlePropagator DenseProp {
-  set InputArray PileUpMerger/stableParticles
-
-  set OutputArray stableParticles
-  set NeutralOutputArray neutralParticles
-  set ChargedHadronOutputArray chargedHadrons
-  set ElectronOutputArray electrons
-  set MuonOutputArray muons
-
-  # radius of the first pixel layer
-  set Radius 0.3
-  set RadiusMax 1.29
-  # half-length of the magnetic field coverage, in m
-  set HalfLength 0.7
-  set HalfLengthMax 3.0
-
-  # magnetic field
-  set Bz 3.8
-}
-
-####################
-# Dense Track merger
-###################
-
-module Merger DenseMergeTracks {
-# add InputArray InputArray
-  add InputArray DenseProp/chargedHadrons
-  add InputArray DenseProp/electrons
-  add InputArray DenseProp/muons
-  set OutputArray tracks
-}
-
-######################
-#   Dense Track Filter
-######################
-
-module DenseTrackFilter TrackMerger {
-  set TrackInputArray TrackMergerProp/tracks
-  set DenseChargedInputArray DenseMergeTracks/tracks
-
-  set TrackOutputArray tracks
-
-  set EtaPhiRes 0.003
-  set EtaMax 4.0
-
-  set pi [expr {acos(-1)}]
-
-  set nbins_phi [expr {$pi/$EtaPhiRes} ]
-  set nbins_phi [expr {int($nbins_phi)} ]
-
-  set PhiBins {}
-  for {set i -$nbins_phi} {$i <= $nbins_phi} {incr i} {
-    add PhiBins [expr {$i * $pi/$nbins_phi}]
-  }
-
-  set nbins_eta [expr {$EtaMax/$EtaPhiRes} ]
-  set nbins_eta [expr {int($nbins_eta)} ]
-
-  for {set i -$nbins_eta} {$i <= $nbins_eta} {incr i} {
-    set eta [expr {$i * $EtaPhiRes}]
-    add EtaPhiBins $eta $PhiBins
-  }
-
-}
+
 
 
@@ -694,4 +721,16 @@
 }
 
+#################
+# Muon filter
+#################
+
+module PdgCodeFilter MuonFilter {
+  set InputArray HCal/eflowTracks
+  set OutputArray muons
+  set Invert true
+  add PdgCode {13}
+  add PdgCode {-13}
+}
+
 
 ##########################
@@ -703,5 +742,5 @@
   add InputArray HCal/eflowTracks eflowTracks
   add InputArray ElectronFilter/electrons electrons
-  add InputArray MuonMomentumSmearing/muons muons
+  add InputArray MuonFilter/muons muons
 
   set VertexInputArray PileUpMerger/vertices
@@ -1161,5 +1200,5 @@
 
 module Cloner MuonCloner {
-  set InputArray MuonMomentumSmearing/muons
+  set InputArray MuonFilter/muons
   set OutputArray muons
 }
@@ -2168,5 +2207,5 @@
 
 module Isolation MuonIsolation {
-  set CandidateInputArray MuonMomentumSmearing/muons
+  set CandidateInputArray MuonFilter/muons
 
   # isolation collection
@@ -4083,4 +4122,6 @@
   add Branch GenMissingET/momentum GenMissingET MissingET
 
+  add Branch TrackMerger/tracks TrackMerger Track
+  add Branch HCal/eflowTracks EFlowTrack Track
 #  add Branch HCal/eflowTracks EFlowTrack Track
 #  add Branch ECal/eflowPhotons EFlowPhoton Tower
Index: modules/DenseTrackFilter.cc
===================================================================
--- modules/DenseTrackFilter.cc	(revision 5b51d33750bc7415d4ede53ce13067db637a5a11)
+++ modules/DenseTrackFilter.cc	(revision ec37bc3202fb17e911b9602b03a7044a2e62d42f)
@@ -54,5 +54,5 @@
 
 DenseTrackFilter::DenseTrackFilter() :
-  fItTrackInputArray(0),   fItDenseChargedInputArray(0)
+  fItTrackInputArray(0)
 {
 }
@@ -116,8 +116,8 @@
   fItTrackInputArray = fTrackInputArray->MakeIterator();
 
-  fDenseChargedInputArray = ImportArray(GetString("DenseChargedInputArray", "DenseMergeTracks/tracks"));
-  fItDenseChargedInputArray = fDenseChargedInputArray->MakeIterator();
-
   fTrackOutputArray = ExportArray(GetString("TrackOutputArray", "tracks"));
+  fChargedHadronOutputArray = ExportArray(GetString("ChargedHadronOutputArray", "chargedHadrons"));
+  fElectronOutputArray = ExportArray(GetString("ElectronOutputArray", "electrons"));
+  fMuonOutputArray = ExportArray(GetString("MuonOutputArray", "muons"));
 }
 
@@ -128,5 +128,4 @@
   vector< vector< Double_t >* >::iterator itPhiBin;
   if(fItTrackInputArray) delete fItTrackInputArray;
-  if(fItDenseChargedInputArray) delete fItDenseChargedInputArray;
   for(itPhiBin = fPhiBins.begin(); itPhiBin != fPhiBins.end(); ++itPhiBin)
   {
@@ -155,7 +154,7 @@
 
   // loop over all tracks
-  fItDenseChargedInputArray->Reset();
+  fItTrackInputArray->Reset();
   number = -1;
-  while((track = static_cast<Candidate*>(fItDenseChargedInputArray->Next())))
+  while((track = static_cast<Candidate*>(fItTrackInputArray->Next())))
   {
     const TLorentzVector &trackPosition = track->Position;
@@ -217,5 +216,5 @@
     {
       ++fTowerTrackHits;
-      track = static_cast<Candidate*>(fDenseChargedInputArray->At(number));
+      track = static_cast<Candidate*>(fTrackInputArray->At(number));
       momentum = track->Momentum;
 
@@ -244,19 +243,42 @@
   Int_t numberOfCandidates;
 
-  numberOfCandidates = fBestTrack->GetCandidates()->GetEntriesFast();
-
+  
+  cout<<fBestTrack<<endl;
+  
   // saving track with highest pT that hit the tower
-  if(fTowerTrackHits > 0 && numberOfCandidates > 1)
-  {
-    track = static_cast<Candidate*>(fBestTrack->GetCandidates()->At(numberOfCandidates - 2));
-    candidate = static_cast<Candidate*>(track->Clone());
-    pt = candidate->Momentum.Pt();
-    eta = candidate->Momentum.Eta();
-    phi = candidate->Momentum.Phi();
-    eta = gRandom->Gaus(eta, fEtaPhiRes);
-    phi = gRandom->Gaus(phi, fEtaPhiRes);
-    candidate->Momentum.SetPtEtaPhiE(pt, eta, phi, pt*TMath::CosH(eta));
-    candidate->AddCandidate(track);
-    fTrackOutputArray->Add(candidate);
-  }
-}
+  if(fTowerTrackHits > 0) 
+  {
+    
+    numberOfCandidates = fBestTrack->GetCandidates()->GetEntriesFast();
+    if (numberOfCandidates < 2)
+       cout<<fBestTrack<<endl;
+
+    if (numberOfCandidates > 1)
+    {  
+
+      track = static_cast<Candidate*>(fBestTrack->GetCandidates()->At(numberOfCandidates - 1));
+      candidate = static_cast<Candidate*>(track->Clone());
+      pt = candidate->Momentum.Pt();
+      eta = candidate->Momentum.Eta();
+      phi = candidate->Momentum.Phi();
+      eta = gRandom->Gaus(eta, fEtaPhiRes);
+      phi = gRandom->Gaus(phi, fEtaPhiRes);
+      candidate->Momentum.SetPtEtaPhiE(pt, eta, phi, pt*TMath::CosH(eta));
+      candidate->AddCandidate(track);
+      fTrackOutputArray->Add(candidate);
+      switch(TMath::Abs(candidate->PID))
+      {
+        case 11:
+          fElectronOutputArray->Add(candidate);
+          break;
+        case 13:
+          fMuonOutputArray->Add(candidate);
+          break;
+        default:
+          fChargedHadronOutputArray->Add(candidate);
+      }
+ 
+    }
+  }
+
+}
Index: modules/DenseTrackFilter.h
===================================================================
--- modules/DenseTrackFilter.h	(revision 5b51d33750bc7415d4ede53ce13067db637a5a11)
+++ modules/DenseTrackFilter.h	(revision ec37bc3202fb17e911b9602b03a7044a2e62d42f)
@@ -69,11 +69,10 @@
 
   const TObjArray *fTrackInputArray; //!
-
   TObjArray *fTrackOutputArray; //!
 
+  TObjArray *fChargedHadronOutputArray; //!
+  TObjArray *fElectronOutputArray; //!
+  TObjArray *fMuonOutputArray; //!
 
-  const TObjArray *fDenseChargedInputArray;
-  TIterator *fItDenseChargedInputArray;
-  
   void FillTrack();
   ClassDef(DenseTrackFilter, 1)
