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 e7e90dfd4bd3101eab20f85883eef511d88978c7)
+++ 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+;
