Index: Makefile
===================================================================
--- Makefile	(revision 49234af6f43184fff8e2bfee34c7b17846289882)
+++ Makefile	(revision 37deb3b5a30eecd538f19c551b5c20c97065a5af)
@@ -301,4 +301,5 @@
 	modules/ParticlePropagator.h \
 	modules/Efficiency.h \
+	modules/IdentificationMap.h \
 	modules/EnergySmearing.h \
 	modules/MomentumSmearing.h \
@@ -696,4 +697,13 @@
 	modules/EnergyScale.$(SrcSuf) \
 	modules/EnergyScale.h \
+	classes/DelphesClasses.h \
+	classes/DelphesFactory.h \
+	classes/DelphesFormula.h \
+	external/ExRootAnalysis/ExRootResult.h \
+	external/ExRootAnalysis/ExRootFilter.h \
+	external/ExRootAnalysis/ExRootClassifier.h
+tmp/modules/IdentificationMap.$(ObjSuf): \
+	modules/IdentificationMap.$(SrcSuf) \
+	modules/IdentificationMap.h \
 	classes/DelphesClasses.h \
 	classes/DelphesFactory.h \
@@ -1164,4 +1174,5 @@
 	tmp/modules/PdgCodeFilter.$(ObjSuf) \
 	tmp/modules/EnergyScale.$(ObjSuf) \
+	tmp/modules/IdentificationMap.$(ObjSuf) \
 	tmp/modules/TrackCountingBTagging.$(ObjSuf) \
 	tmp/modules/Calorimeter.$(ObjSuf) \
@@ -1487,4 +1498,12 @@
 	@touch $@
 
+modules/IdentificationMap.h: \
+	classes/DelphesModule.h
+	@touch $@
+
+modules/ExampleModule.h: \
+	classes/DelphesModule.h
+	@touch $@
+
 modules/Isolation.h: \
 	classes/DelphesModule.h
@@ -1496,8 +1515,4 @@
 
 modules/Merger.h: \
-	classes/DelphesModule.h
-	@touch $@
-
-modules/ExampleModule.h: \
 	classes/DelphesModule.h
 	@touch $@
Index: README_4LHCb
===================================================================
--- README_4LHCb	(revision 37deb3b5a30eecd538f19c551b5c20c97065a5af)
+++ README_4LHCb	(revision 37deb3b5a30eecd538f19c551b5c20c97065a5af)
@@ -0,0 +1,144 @@
+Delphes 4 LHCb
+==============
+
+The card "delphes_card_prelLHCb.tcl" contains a preliminary parametrization of the LHCb detector. 
+
+- ParticlePropagator
+
+particles are propagated in a constant B field.
+
+- ChargedHadronMomentumSmearing/ElectronEnergySmearing/MuonMomentumSmearing
+
+charged particles momenta are smeared according to detector resolution
+
+- TrackMerger
+
+charged particles are merged into single collection for simpler future processing
+
+- ImpactParameterSmearing
+
+charged particles transverse IP are smeared according to known LHCb tracking
+performance.
+
+
+- IdentificationMap
+
+This module is a recent addition in order to map particle misindentification rates
+and reconstruction efficiencies. 
+
+An example is given in the card but can be expanded if needed. 
+
+- ECAL/HCAL
+
+Calorimeter modules are used to parametrize the energy response and angular
+resolution of neutral objects such as photons/neutral hadrons. 
+
+- TreeWriter 
+
+user specifies here which collections are stored in the output. 
+By default tracks, neutral hadrons and photons are stored in this card.
+Tracks contain muons, electrons, and charged hadrons. 
+
+
+Quick start with Delphes
+========================
+
+1) Compile:
+
+   make
+
+2) Simulate p p -> b b~ events 
+
+  tar -xzvf pp2bb.hep.tgz
+  ./DelphesSTDHEP examples/delphes_card_prelLHCb.tcl delphes_output.root pp2bb.hep
+
+
+For more details, please visit:
+
+https://cp3.irmp.ucl.ac.be/projects/delphes
+
+
+
+Simple analysis using TTree::Draw
+=================================
+
+Now we can start ROOT and look at the data stored in the output ROOT file.
+
+Start ROOT and load Delphes shared library:
+
+   root -l
+   gSystem->Load("libDelphes");
+
+Open ROOT file and do some basic analysis using Draw or TBrowser:
+
+   TFile::Open("delphes_output.root");
+   Delphes->Draw("Track.PT");
+   TBrowser browser;
+
+Note 1: Delphes - tree name, it can be learned e.g. from TBrowser
+
+Note 2: Track - branch name; PT - variable (leaf) of this branch
+
+Complete description of all branches can be found in
+
+   doc/RootTreeDescription.html
+
+This information is also available at
+
+   https://cp3.irmp.ucl.ac.be/projects/delphes/wiki/WorkBook/RootTreeDescription
+
+
+Macro-based analysis
+====================
+
+Analysis macro consists of histogram booking, event loop (histogram filling),
+histogram display.
+
+Start ROOT and load Delphes shared library:
+
+   root -l
+   gSystem->Load("libDelphes");
+
+Basic analysis macro:
+
+{
+  // Create chain of root trees
+  TChain chain("Delphes");
+  chain.Add("delphes_output.root");
+  
+  // Create object of class ExRootTreeReader
+  ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
+  Long64_t numberOfEntries = treeReader->GetEntries();
+  
+  // Get pointers to branches used in this analysis
+  TClonesArray *branchTrack = treeReader->UseBranch("Track");
+
+  // Book histograms
+  TH1 *histTrackPT = new TH1F("track pt", "track P_{T}", 50, 0.0, 20.0);
+
+  // Loop over all events
+  for(Int_t entry = 0; entry < numberOfEntries; ++entry)
+  {
+
+    // Load selected branches with data from specified event
+    treeReader->ReadEntry(entry);
+  
+    // If event contains at least 1 track
+    if(branchTrack->GetEntries() > 0)
+    {
+      // Take first track
+      Track *track = (Track*) branchTrack->At(0);
+      
+      // Plot track transverse momentum
+      histTrackPT->Fill(track->PT);
+      
+      // Print electron transverse momentum and Particle Data Group ID
+      cout << track->PID<< "   " << track->PT << endl;
+    }
+
+  }
+
+  // Show resulting histograms
+  histTrackPT->Draw();
+}
+
Index: display/DelphesHtmlSummary.cc
===================================================================
--- display/DelphesHtmlSummary.cc	(revision 49234af6f43184fff8e2bfee34c7b17846289882)
+++ display/DelphesHtmlSummary.cc	(revision 37deb3b5a30eecd538f19c551b5c20c97065a5af)
@@ -1,2 +1,20 @@
+/*
+ *  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/>.
+ */
+
 #include "display/DelphesHtmlSummary.h"
 #include "TGHtml.h"
Index: display/DelphesHtmlSummary.h
===================================================================
--- display/DelphesHtmlSummary.h	(revision 49234af6f43184fff8e2bfee34c7b17846289882)
+++ display/DelphesHtmlSummary.h	(revision 37deb3b5a30eecd538f19c551b5c20c97065a5af)
@@ -1,2 +1,20 @@
+/*
+ *  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/>.
+ */
+
 // Delphes HTML table for the event display. 
 // Based on the ROOT example "alice_esd_html_summary.C"
Index: display/DelphesPlotSummary.cc
===================================================================
--- display/DelphesPlotSummary.cc	(revision 49234af6f43184fff8e2bfee34c7b17846289882)
+++ display/DelphesPlotSummary.cc	(revision 37deb3b5a30eecd538f19c551b5c20c97065a5af)
@@ -1,2 +1,20 @@
+/*
+ *  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/>.
+ */
+
 #include "display/DelphesPlotSummary.h"
 #include "TRootEmbeddedCanvas.h"
Index: display/DelphesPlotSummary.h
===================================================================
--- display/DelphesPlotSummary.h	(revision 49234af6f43184fff8e2bfee34c7b17846289882)
+++ display/DelphesPlotSummary.h	(revision 37deb3b5a30eecd538f19c551b5c20c97065a5af)
@@ -1,2 +1,20 @@
+/*
+ *  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 DelphesPlotSummary_h
 #define DelphesPlotSummary_h
Index: examples/delphes_card_prelLHCb.tcl
===================================================================
--- examples/delphes_card_prelLHCb.tcl	(revision 37deb3b5a30eecd538f19c551b5c20c97065a5af)
+++ examples/delphes_card_prelLHCb.tcl	(revision 37deb3b5a30eecd538f19c551b5c20c97065a5af)
@@ -0,0 +1,375 @@
+#set MaxEvents 1000
+#set RandomSeed 123
+
+
+#######################################
+# Order of execution of various modules
+#######################################
+
+set ExecutionPath {
+  
+  ParticlePropagator
+  
+  ChargedHadronMomentumSmearing
+  ElectronEnergySmearing
+  MuonMomentumSmearing
+
+  TrackMerger
+  ImpactParameterSmearing
+ 
+  IdentificationMap
+  
+  Ecal
+  Hcal
+
+  TreeWriter
+}
+
+
+
+#################################
+# Propagate particles in cylinder
+#################################
+
+module ParticlePropagator ParticlePropagator {
+  set InputArray Delphes/stableParticles
+
+  set OutputArray stableParticles
+  set ChargedHadronOutputArray chargedHadrons
+  set ElectronOutputArray electrons
+  set MuonOutputArray muons
+
+  # radius of the magnetic field coverage, in m
+ 
+  set Radius 3.31
+ 
+  
+  # half-length of the magnetic field coverage, in m
+  set HalfLength 12.0
+
+  # magnetic field
+  set Bz 1.1
+
+  # Need to veto anything with theta > 0.269 rad  -> eta = 2
+  #                            theta < 0.0135 rad -> eta = 5
+  
+  # tracker and calos are at approx 0.269 rad, R = 12*tan(0.269) 
+
+}
+
+  
+########################################
+# Momentum resolution for charged tracks
+########################################
+
+module MomentumSmearing ChargedHadronMomentumSmearing {
+  set InputArray ParticlePropagator/chargedHadrons
+  set OutputArray chargedHadrons
+
+  # set ResolutionFormula {resolution formula as a function of eta and pt}
+
+  # resolution formula for charged hadrons
+  set ResolutionFormula {(eta > 2.0  && eta <= 5.0)      * (pt > 0.5) * (0.005)}
+}
+
+#################################
+# Energy resolution for electrons
+#################################
+
+module EnergySmearing ElectronEnergySmearing {
+  set InputArray ParticlePropagator/electrons
+  set OutputArray electrons
+
+  # set ResolutionFormula {resolution formula as a function of eta and energy}
+
+  # resolution formula for electrons
+  set ResolutionFormula { (eta > 2.0  && eta <= 5.0) * (energy > 0.1   && energy <= 8.0) * (energy*0.05) + \ 
+                          (eta > 2.0  && eta <= 5.0) * (energy > 8.0)                    *  sqrt(energy^2*0.015^2 + energy*0.10^2)}
+  }
+
+###############################
+# Momentum resolution for muons
+###############################
+
+module MomentumSmearing MuonMomentumSmearing {
+  set InputArray ParticlePropagator/muons
+  set OutputArray muons
+
+  # resolution formula for muons
+  set ResolutionFormula {(eta > 2.0  && eta <= 5.0)      * (pt > 0.5)* (0.005)}
+}
+
+
+##############
+# Track merger
+##############
+
+module Merger TrackMerger {
+# add InputArray InputArray
+  add InputArray ChargedHadronMomentumSmearing/chargedHadrons
+  add InputArray ElectronEnergySmearing/electrons
+  add InputArray MuonMomentumSmearing/muons
+  set OutputArray tracks
+}
+
+
+
+################################
+# Track impact parameter smearing
+################################
+
+module ImpactParameterSmearing ImpactParameterSmearing {
+  set InputArray TrackMerger/tracks
+  set OutputArray tracks
+
+
+# absolute impact parameter smearing formula (in mm) as a function of pt and eta
+set ResolutionFormula {0.0116 + 0.0234/pt}
+
+}
+
+###### ref. JINST 9 C01065 #############
+
+
+####################################
+# Charged hadron PID
+####################################
+
+module IdentificationMap IdentificationMap {
+  set InputArray ImpactParameterSmearing/tracks
+  set OutputArray tracks
+  
+  # {PID in} {PID out} {formula}
+  # make sure "PID in" and "PID out" have the same charge (e.g {-13} {211} or {-321} {211})
+  # {211} {-13} is equivalent to {-211} {13} (and needs to be written once only...)
+  
+  
+  
+  
+  
+  
+  # --- pions --- 
+  
+  add EfficiencyFormula {211} {211} {      (eta <= 2.0)                                  * (0.00) + \
+                                           (eta > 2.0  && eta <= 5.0) *       (pt < 0.8) * (0.00) + \
+					   (eta > 2.0  && eta <= 5.0) *       (pt >= 0.8)* (0.95) + \
+					   (eta > 5.0)                                   * (0.00)}
+  
+  add EfficiencyFormula {211} {-13} {      (eta <= 2.0)                                 * (0.00) + \
+                                           (eta > 2.0  && eta <= 5.0) *      (pt < 0.8) * (0.00) + \
+					   (eta > 2.0  && eta <= 5.0) *      (pt >= 0.8)* (0.005 + 0.0663*exp(-0.13*pt*cosh(eta))) + \
+					   (eta > 5.0)                                  * (0.00)}
+
+  
+ # --- kaons ---
+ 
+  
+  add EfficiencyFormula {321} {321} {      (eta <= 2.0)                                  * (0.00) + \
+                                           (eta > 2.0  && eta <= 5.0) *       (pt < 0.8) * (0.00) + \
+					   (eta > 2.0  && eta <= 5.0) *       (pt >= 0.8)* (0.95) + \
+					   (eta > 5.0)                                   * (0.00)}
+					   
+  add EfficiencyFormula {321} {-13} {      (eta <= 2.0)                                 * (0.00) + \
+                                           (eta > 2.0  && eta <= 5.0) *      (pt < 0.8) * (0.00) + \
+					   (eta > 2.0  && eta <= 5.0) *      (pt >= 0.8)* (0.005 + 0.086*exp(-0.11*pt*cosh(eta))) + \
+					   (eta > 5.0)                                  * (0.00)}
+
+
+ # --- protons ---
+ 
+  
+  add EfficiencyFormula {2212} {2212} {    (eta <= 2.0)                                  * (0.00) + \
+                                           (eta > 2.0  && eta <= 5.0) *       (pt < 0.8) * (0.00) + \
+					   (eta > 2.0  && eta <= 5.0) *       (pt >= 0.8)* (0.95) + \
+					   (eta > 5.0)                                   * (0.00)}
+					   
+  add EfficiencyFormula {2212} {-13} {     (eta <= 2.0)                                 * (0.00) + \
+                                           (eta > 2.0  && eta <= 5.0) *      (pt < 0.8) * (0.00) + \
+					   (eta > 2.0  && eta <= 5.0) *      (pt >= 0.8)* (0.002) + \
+					   (eta > 5.0)                                  * (0.00)}
+
+
+
+ # --- muons ---
+
+
+
+  add EfficiencyFormula {-13} {-13} {      (eta <= 2.0)                                * (0.00) + \
+                                           (eta > 2.0  && eta <= 5.0) *      (pt < 0.8)* (0.00) + \
+                                           (eta > 2.0  && eta <= 5.0) *     (pt >= 0.8)* (0.97) + \
+                                           (eta > 5.0)                                 * (0.00)}
+
+ 
+ # efficiency for other charged particles (should be always {0} {0} {formula})
+ 
+  add EfficiencyFormula {0} {0}     {      (eta <= 2.0)                                * (0.00) + \
+                                           (eta > 2.0  && eta <= 5.0) *     (pt < 0.8) * (0.00) + \
+					   (eta > 2.0  && eta <= 5.0) *     (pt > 0.8) * (0.95) + \
+                                           (eta > 5.0)                                 * (0.00)}
+
+}
+
+###### ref. JINST 8 P10020 #############
+
+
+#############
+#   ECAL
+#############
+
+module SimpleCalorimeter Ecal {
+  set ParticleInputArray ParticlePropagator/stableParticles
+  set TrackInputArray IdentificationMap/tracks
+
+  set TowerOutputArray ecalTowers
+  set EFlowTowerOutputArray eflowPhotons
+  
+  set pi [expr {acos(-1)}]
+
+  # lists of the edges of each tower in eta and phi
+  # each list starts with the lower edge of the first tower
+  # the list ends with the higher edged of the last tower
+
+   # 1 degree towers
+  set PhiBins {}
+  for {set i -180} {$i <= 180} {incr i} {
+    add PhiBins [expr {$i * $pi/180.0}]
+  }
+
+  # 0.02 unit in eta  from eta = 3.2 to eta = 5.0
+  for {set i 1} {$i <= 90} {incr i} {
+    set eta [expr {3.2 + $i * 0.02}]
+    add EtaPhiBins $eta $PhiBins
+  }
+  
+    # 1.25 degree towers
+  set PhiBins {}
+  for {set i -135} {$i <= 135} {incr i} {
+    add PhiBins [expr {$i * $pi/135.0}]
+  }
+
+  # 0.025 unit in eta  from eta = 2.6 to eta = 3.2
+  for {set i 1} {$i <= 24} {incr i} {
+    set eta [expr {2.6 + $i * 0.025}]
+    add EtaPhiBins $eta $PhiBins
+  }
+
+     # 1.25 degree towers
+  set PhiBins {}
+  for {set i -100} {$i <= 100} {incr i} {
+    add PhiBins [expr {$i * $pi/100.0}]
+  }
+
+  # 0.04 unit in eta  from eta = 2.0 to eta = 2.6
+  for {set i 0} {$i <= 24} {incr i} {
+    set eta [expr {2.0 + $i * 0.04}]
+    add EtaPhiBins $eta $PhiBins
+  }
+
+  add EnergyFraction {0} {0.0}
+  # energy fractions for e, gamma and pi0
+  add EnergyFraction {11} {1.0}
+  add EnergyFraction {22} {1.0}
+  add EnergyFraction {111} {1.0}
+  # energy fractions for muon, neutrinos and neutralinos
+  add EnergyFraction {12} {0.0}
+  add EnergyFraction {13} {0.0}
+  add EnergyFraction {14} {0.0}
+  add EnergyFraction {16} {0.0}
+  add EnergyFraction {1000022} {0.0}
+  add EnergyFraction {1000023} {0.0}
+  add EnergyFraction {1000025} {0.0}
+  add EnergyFraction {1000035} {0.0}
+  add EnergyFraction {1000045} {0.0}
+  # energy fractions for K0short and Lambda
+  add EnergyFraction {310} {0.3}
+  add EnergyFraction {3122} {0.3}
+
+   set ResolutionFormula {(eta <= 5.0 && eta > 2.0) * sqrt(energy^2*0.015^2 + energy*0.10^2)}
+}
+
+#############
+#   HCAL
+#############
+
+module SimpleCalorimeter Hcal {
+  set ParticleInputArray ParticlePropagator/stableParticles
+  set TrackInputArray IdentificationMap/tracks
+
+  set TowerOutputArray hcalTowers
+  set EFlowTowerOutputArray eflowNeutralHadrons
+  
+  set pi [expr {acos(-1)}]
+
+  # lists of the edges of each tower in eta and phi
+  # each list starts with the lower edge of the first tower
+  # the list ends with the higher edged of the last tower
+
+    # 1 degree towers
+  set PhiBins {}
+  for {set i -16} {$i <= 16} {incr i} {
+    add PhiBins [expr {$i * $pi/16.0}]
+  }
+
+  # 0.20 unit in eta  from eta = 2.6 to eta = 5.0
+  for {set i 1} {$i <= 12} {incr i} {
+    set eta [expr {2.6 + $i * 0.2}]
+    add EtaPhiBins $eta $PhiBins
+  }
+
+    # 1 degree towers
+  set PhiBins {}
+  for {set i -32} {$i <= 32} {incr i} {
+    add PhiBins [expr {$i * $pi/32.0}]
+  }
+
+  # 0.1 unit in eta  from eta = 2 to eta = 2.6
+  for {set i 0} {$i <= 6} {incr i} {
+    set eta [expr {2.0 + $i * 0.1}]
+    add EtaPhiBins $eta $PhiBins
+  }
+
+
+   
+  # default energy fractions {abs(PDG code)} {Fecal Fhcal}
+  add EnergyFraction {0} {1.0}
+  # energy fractions for e, gamma and pi0
+  add EnergyFraction {11} {0.0}
+  add EnergyFraction {22} {0.0}
+  add EnergyFraction {111} {0.0}
+  # energy fractions for muon, neutrinos and neutralinos
+  add EnergyFraction {12} {0.0}
+  add EnergyFraction {13} {0.0}
+  add EnergyFraction {14} {0.0}
+  add EnergyFraction {16} {0.0}
+  add EnergyFraction {1000022} {0.0}
+  add EnergyFraction {1000023} {0.0}
+  add EnergyFraction {1000025} {0.0}
+  add EnergyFraction {1000035} {0.0}
+  add EnergyFraction {1000045} {0.0}
+  # energy fractions for K0short and Lambda
+  add EnergyFraction {310} {0.7}
+  add EnergyFraction {3122} {0.7}
+
+  set ResolutionFormula { (eta <= 5.0 && eta > 2.0) * sqrt(energy^2*0.05^2 + energy*0.80^2)}
+  }
+
+
+##################
+# ROOT tree writer
+##################
+
+# tracks, towers and eflow objects are not stored by default in the output.
+# if needed (for jet constituent or other studies), uncomment the relevant 
+# "add Branch ..." lines. 
+
+module TreeWriter TreeWriter {
+# add Branch InputArray BranchName BranchClass
+ 
+  add Branch Delphes/allParticles Particle GenParticle
+
+  add Branch IdentificationMap/tracks Track Track
+  add Branch Hcal/eflowNeutralHadrons NeutralHadron Tower
+  add Branch Ecal/eflowPhotons Photon Photon
+ 
+}
+
Index: modules/IdentificationMap.cc
===================================================================
--- modules/IdentificationMap.cc	(revision 37deb3b5a30eecd538f19c551b5c20c97065a5af)
+++ modules/IdentificationMap.cc	(revision 37deb3b5a30eecd538f19c551b5c20c97065a5af)
@@ -0,0 +1,222 @@
+/*
+ *  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 IdentificationMap
+ *
+ *  Converts particles with some PDG code into another particle, according to parametrized probability as fction of pt eta
+ given by user. 
+ *
+ *  $Date: 2014-08-07 14:57:44 +0100 (Thu, 07 Aug 2014) $
+ *  $Revision: 905 $
+ *
+ *
+ *  \author M. Selvaggi - UCL, Louvain-la-Neuve
+ *
+ */
+
+#include "modules/IdentificationMap.h"
+
+#include "classes/DelphesClasses.h"
+#include "classes/DelphesFactory.h"
+#include "classes/DelphesFormula.h"
+
+#include "ExRootAnalysis/ExRootResult.h"
+#include "ExRootAnalysis/ExRootFilter.h"
+#include "ExRootAnalysis/ExRootClassifier.h"
+
+#include "TMath.h"
+#include "TString.h"
+#include "TFormula.h"
+#include "TRandom3.h"
+#include "TObjArray.h"
+#include "TDatabasePDG.h"
+#include "TLorentzVector.h"
+
+#include <algorithm> 
+#include <stdexcept>
+#include <iostream>
+#include <sstream>
+
+using namespace std;
+
+//------------------------------------------------------------------------------
+
+IdentificationMap::IdentificationMap() :
+  fItInputArray(0)
+{
+}
+
+//------------------------------------------------------------------------------
+
+IdentificationMap::~IdentificationMap()
+{
+}
+
+//------------------------------------------------------------------------------
+
+void IdentificationMap::Init()
+{
+  // read efficiency formula
+
+  
+  TMisIDMap::iterator itEfficiencyMap;
+  ExRootConfParam param;
+  DelphesFormula *formula;
+  Int_t i, size, pdg;
+  
+  // read efficiency formulas
+  param = GetParam("EfficiencyFormula");
+  size = param.GetSize();
+  
+  fEfficiencyMap.clear();
+  for(i = 0; i < size/3; ++i)
+  {
+    formula = new DelphesFormula;
+    formula->Compile(param[i*3 + 2].GetString());
+    pdg = param[i*3].GetInt();
+    fEfficiencyMap.insert(make_pair(pdg,make_pair(param[i*3 + 1].GetInt(),formula)));
+  
+   // cout<<param[i*3].GetInt()<<","<<param[i*3+1].GetInt()<<","<<param[i*3 + 2].GetString()<<endl;
+  
+  }
+
+  // set default efficiency formula
+  itEfficiencyMap = fEfficiencyMap.find(0);
+  if(itEfficiencyMap == fEfficiencyMap.end())
+  {
+    formula = new DelphesFormula;
+    formula->Compile("1.0");
+
+    fEfficiencyMap.insert(make_pair(0,make_pair(0,formula)));
+  }
+ 
+  // import input array
+
+  fInputArray = ImportArray(GetString("InputArray", "ParticlePropagator/stableParticles"));
+  fItInputArray = fInputArray->MakeIterator();
+
+  // create output array
+
+  fOutputArray = ExportArray(GetString("OutputArray", "stableParticles"));
+}
+
+//------------------------------------------------------------------------------
+
+void IdentificationMap::Finish()
+{
+  if(fItInputArray) delete fItInputArray;
+  
+  TMisIDMap::iterator itEfficiencyMap;
+  DelphesFormula *formula;
+  for(itEfficiencyMap = fEfficiencyMap.begin(); itEfficiencyMap != fEfficiencyMap.end(); ++itEfficiencyMap)
+  {
+    formula = (itEfficiencyMap->second).second;
+    if(formula) delete formula;
+  }
+
+}
+
+//------------------------------------------------------------------------------
+
+void IdentificationMap::Process()
+{ 
+  Candidate *candidate;
+  Double_t pt, eta, phi;
+  TMisIDMap::iterator itEfficiencyMap;
+  pair <TMisIDMap::iterator, TMisIDMap::iterator> range;
+  DelphesFormula *formula;
+  Int_t pdgIn, pdgOut, charge;
+
+  Double_t P, Pi;
+   
+ // cout<<"------------ New Event ------------"<<endl;
+   
+  fItInputArray->Reset();
+  while((candidate = static_cast<Candidate*>(fItInputArray->Next())))
+  {
+    const TLorentzVector &candidatePosition = candidate->Position;
+    const TLorentzVector &candidateMomentum = candidate->Momentum;
+    eta = candidatePosition.Eta();
+    phi = candidatePosition.Phi();
+    pt = candidateMomentum.Pt();
+    pdgIn = candidate->PID;
+    charge = candidate->Charge;
+    
+   // cout<<"------------ New Candidate ------------"<<endl;
+   // cout<<candidate->PID<<"   "<<pt<<","<<eta<<","<<phi<<endl;
+     
+    P = 1.0;
+    
+    //first check that PID of this particle is specified in cfg, if not set look for PID=0
+      
+    itEfficiencyMap = fEfficiencyMap.find(pdgIn);
+     
+    range = fEfficiencyMap.equal_range(pdgIn); 
+    if(range.first == range.second) range = fEfficiencyMap.equal_range(-pdgIn);
+    if(range.first == range.second) range = fEfficiencyMap.equal_range(0);
+   
+    //loop over submap for this pid
+    for (TMisIDMap::iterator it=range.first; it!=range.second; ++it)
+    { 
+       
+      formula = (it->second).second;
+      pdgOut = (it->second).first;
+
+      Pi = formula->Eval(pt, eta);
+    
+     // cout<<"PdgIn: "<<pdgIn<<", PdgOut: "<<pdgOut<<", Pi = "<<Pi<<endl;
+    
+      // check that sum of probabilities does not exceed 1.
+      
+      P = (P - Pi)/P;
+	
+      if( P < 0.0 ) 
+      {
+       // cout<<"Sum of probabilities exceeds 1 for particle ID "<<pdgIn<<", check formulas in IdentificationMap module"<<endl;
+	continue;
+      }
+      else
+      {
+      
+        //randomly assign a PID to particle according to map
+      
+        Double_t rndm = gRandom->Uniform();
+       // cout<<"Random number vs P //  "<<rndm<<"  "<<P<<endl;
+     
+        if(rndm > P)
+        //if(gRandom->Uniform() > P)
+        {
+         // cout<<"particle "<<candidate->PID<<" --> ";
+	
+	  //change PID of particle
+          if(pdgOut != 0) candidate->PID = charge*pdgOut;
+         // cout<<"Final PID: "<<candidate->PID<<endl;
+	
+	  fOutputArray->Add(candidate);
+          break;
+      }
+     }	
+	
+    }
+      
+   }
+
+}
+
+//------------------------------------------------------------------------------
Index: modules/IdentificationMap.h
===================================================================
--- modules/IdentificationMap.h	(revision 37deb3b5a30eecd538f19c551b5c20c97065a5af)
+++ modules/IdentificationMap.h	(revision 37deb3b5a30eecd538f19c551b5c20c97065a5af)
@@ -0,0 +1,68 @@
+/*
+ *  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 IdentificationMap_h
+#define IdentificationMap_h
+
+
+/** \class IdentificationMap
+ *
+ *  Converts particles with some PDG code into another particle, according to parametrized probability as fction of pt eta
+ given by user. 
+ *
+ *  $Date: 2014-08-07 14:57:44 +0100 (Thu, 07 Aug 2014) $
+ *  $Revision: 905 $
+ *
+ *
+ *  \author M. Selvaggi - UCL, Louvain-la-Neuve
+ *
+ */
+
+#include "classes/DelphesModule.h"
+
+class TIterator;
+class TObjArray;
+class DelphesFormula;
+
+class IdentificationMap: public DelphesModule
+{
+public:
+
+  IdentificationMap();
+  ~IdentificationMap();
+
+  void Init();
+  void Process();
+  void Finish();
+
+private:
+  
+  typedef std::multimap< Int_t, std::pair<Int_t , DelphesFormula * > > TMisIDMap; //!
+  
+  TMisIDMap fEfficiencyMap;
+  
+  TIterator *fItInputArray; //!
+
+  const TObjArray *fInputArray; //!
+
+  TObjArray *fOutputArray; //!
+
+  ClassDef(IdentificationMap, 1)
+};
+
+#endif
Index: modules/ModulesLinkDef.h
===================================================================
--- modules/ModulesLinkDef.h	(revision 49234af6f43184fff8e2bfee34c7b17846289882)
+++ modules/ModulesLinkDef.h	(revision 37deb3b5a30eecd538f19c551b5c20c97065a5af)
@@ -22,6 +22,6 @@
  *  Lists classes to be included in cint dicitonary
  *
- *  $Date$
- *  $Revision$
+ *  $Date: 2014-04-16 17:17:35 +0200 (Wed, 16 Apr 2014) $
+ *  $Revision: 1369 $
  *
  *
@@ -36,4 +36,5 @@
 #include "modules/ParticlePropagator.h"
 #include "modules/Efficiency.h"
+#include "modules/IdentificationMap.h"
 #include "modules/EnergySmearing.h"
 #include "modules/MomentumSmearing.h"
@@ -75,4 +76,5 @@
 #pragma link C++ class ParticlePropagator+;
 #pragma link C++ class Efficiency+;
+#pragma link C++ class IdentificationMap+;
 #pragma link C++ class EnergySmearing+;
 #pragma link C++ class MomentumSmearing+;
