From 888f239124bc3954193cee1fb160944ac744882a Mon Sep 17 00:00:00 2001
From: Sandro Di Mattia <sandro.di.mattia@cern.ch>
Date: Wed, 28 May 2014 12:57:50 +0200
Subject: [PATCH] fix for bug #104508 (TrigMuGirl-01-04-21)

---
 .../TrigMuGirl/TrigMuGirl/TrigMuGirl.h        |  324 +++
 .../TrigMuGirl/TrigMuGirl/TrigMuGirlAlg.h     |   81 +
 .../TrigMuGirl/TrigMuGirl/TrigMuGirlNtuple.h  |   74 +
 .../TrigMuGirl/TrigMuGirl/TrigMuGirlTool.h    |  314 +++
 .../TrigMuGirl/TrigMuGirl/TrigPostFex.h       |   66 +
 .../TrigMuGirl/TrigMuGirl/TrigPostFexNtuple.h |   63 +
 .../TrigMuGirl/cmt/requirements               |   51 +
 .../TrigMuGirl/python/TrigMuGirlConfig.py     |  433 ++++
 .../TrigMuGirl/python/TrigMuGirlConfigDb.py   |    7 +
 .../TrigMuGirl/python/TrigMuGirlFlags.py      |   23 +
 .../TrigMuGirl/python/TrigMuGirlMonitoring.py |  108 +
 .../TrigMuGirl/python/TrigPostFexConfig.py    |   31 +
 .../TrigMuGirl/src/TrigMuGirl.cxx             | 1789 +++++++++++++++++
 .../TrigMuGirl/src/TrigMuGirlAlg.cxx          |  208 ++
 .../TrigMuGirl/src/TrigMuGirlNtuple.cxx       |  178 ++
 .../TrigMuGirl/src/TrigMuGirlTool.cxx         | 1637 +++++++++++++++
 .../TrigMuGirl/src/TrigPostFex.cxx            |  335 +++
 .../TrigMuGirl/src/TrigPostFexNtuple.cxx      |  147 ++
 .../src/components/TrigMuGirl_entries.cxx     |   25 +
 .../src/components/TrigMuGirl_load.cxx        |    8 +
 20 files changed, 5902 insertions(+)
 create mode 100644 Trigger/TrigAlgorithms/TrigMuGirl/TrigMuGirl/TrigMuGirl.h
 create mode 100644 Trigger/TrigAlgorithms/TrigMuGirl/TrigMuGirl/TrigMuGirlAlg.h
 create mode 100644 Trigger/TrigAlgorithms/TrigMuGirl/TrigMuGirl/TrigMuGirlNtuple.h
 create mode 100644 Trigger/TrigAlgorithms/TrigMuGirl/TrigMuGirl/TrigMuGirlTool.h
 create mode 100644 Trigger/TrigAlgorithms/TrigMuGirl/TrigMuGirl/TrigPostFex.h
 create mode 100644 Trigger/TrigAlgorithms/TrigMuGirl/TrigMuGirl/TrigPostFexNtuple.h
 create mode 100755 Trigger/TrigAlgorithms/TrigMuGirl/cmt/requirements
 create mode 100644 Trigger/TrigAlgorithms/TrigMuGirl/python/TrigMuGirlConfig.py
 create mode 100644 Trigger/TrigAlgorithms/TrigMuGirl/python/TrigMuGirlConfigDb.py
 create mode 100644 Trigger/TrigAlgorithms/TrigMuGirl/python/TrigMuGirlFlags.py
 create mode 100644 Trigger/TrigAlgorithms/TrigMuGirl/python/TrigMuGirlMonitoring.py
 create mode 100644 Trigger/TrigAlgorithms/TrigMuGirl/python/TrigPostFexConfig.py
 create mode 100644 Trigger/TrigAlgorithms/TrigMuGirl/src/TrigMuGirl.cxx
 create mode 100644 Trigger/TrigAlgorithms/TrigMuGirl/src/TrigMuGirlAlg.cxx
 create mode 100644 Trigger/TrigAlgorithms/TrigMuGirl/src/TrigMuGirlNtuple.cxx
 create mode 100644 Trigger/TrigAlgorithms/TrigMuGirl/src/TrigMuGirlTool.cxx
 create mode 100644 Trigger/TrigAlgorithms/TrigMuGirl/src/TrigPostFex.cxx
 create mode 100644 Trigger/TrigAlgorithms/TrigMuGirl/src/TrigPostFexNtuple.cxx
 create mode 100644 Trigger/TrigAlgorithms/TrigMuGirl/src/components/TrigMuGirl_entries.cxx
 create mode 100644 Trigger/TrigAlgorithms/TrigMuGirl/src/components/TrigMuGirl_load.cxx

diff --git a/Trigger/TrigAlgorithms/TrigMuGirl/TrigMuGirl/TrigMuGirl.h b/Trigger/TrigAlgorithms/TrigMuGirl/TrigMuGirl/TrigMuGirl.h
new file mode 100644
index 00000000000..51cec8b61be
--- /dev/null
+++ b/Trigger/TrigAlgorithms/TrigMuGirl/TrigMuGirl/TrigMuGirl.h
@@ -0,0 +1,324 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+/***************************************************************************
+    Authors: E. Reinherz-Aronis, A. Kreisel 
+             based on MuGirl by Shlomit Tarem
+***************************************************************************/
+#ifndef TRIGMUGIRL_H
+#define TRIGMUGIRL_H
+
+#include "GaudiKernel/Algorithm.h"
+#include "GaudiKernel/ToolHandle.h"
+
+//* Trigger includes *//
+#include <string>
+#include "TrigInterfaces/FexAlgo.h"
+
+#include "CaloIdentifier/CaloCell_ID.h"
+#include "TrkSegment/SegmentCollection.h"
+
+//added for EFContainer 2008-03-10
+#include "TrigMuonEvent/MuonFeature.h"
+#include "TrigMuonEvent/CombinedMuonFeature.h"
+// for the optional output object
+#include "TrigMuonEvent/TrigMuonEFCbTrack.h"
+#include "TrigMuonEvent/TrigMuonEFInfo.h"
+#include "TrigMuonEvent/TrigMuonEFInfoContainer.h"
+#include "TrigMuonEvent/TrigMuonEFInfoTrackContainer.h"
+
+#include "GaudiKernel/NTuple.h"
+
+#include "TrigTimeAlgs/TrigTimerSvc.h"
+#include "TrkTrack/TrackCollection.h"
+#include "Particle/TrackParticleContainer.h"
+#include "xAODTracking/TrackParticleContainer.h"
+#include "xAODCaloEvent/CaloClusterContainer.h"
+
+
+namespace HLT {
+  class TriggerElement;
+}
+
+class StoreGateSvc;
+class IExtrapolateToCaloTool;
+class ICaloMuonLikelihoodTool;
+class CaloClusterContainer;
+
+namespace Rec
+{
+class TrackParticle;
+class TrackParticleContainer;
+}
+
+
+namespace MuonGM
+{
+class MuonDetectorManager;
+}
+
+namespace Muon
+{
+class IMdtDriftCircleOnTrackCreator;
+class IMuonClusterOnTrackCreator;
+class IMuonSegmentMaker;
+class IMuGirlParticleCreatorTool;
+class MuonSegment;
+
+}
+
+namespace NTuple
+{
+class Tuple;
+}
+
+namespace MuGirlNS
+{
+class ICandidateTool;
+class IPerformanceTruthTool;
+class IGlobalFitTool;
+class CandidateSummary;
+class IStauTool;
+class IANNSelectionTool;
+class IMuGirlParticleCreatorTool;
+class SegmentManager;
+}
+
+namespace Trk
+{
+class IIntersector;
+class Surface;
+// 2008-12-13 downgrade
+//class ITrackParticleCreatorTool;
+class ParticleCreatorTool;
+}
+
+namespace MagField {
+class IMagFieldSvc;
+}
+
+
+class INTupleSvc;
+
+class TrigMuGirlNtuple;
+
+//for 
+
+class TrigMuGirl : public HLT::FexAlgo {
+  
+  public:
+  
+  TrigMuGirl(const std::string&, ISvcLocator*);
+  ~TrigMuGirl();
+  
+  HLT::ErrorCode hltInitialize();
+  //  HLT::ErrorCode hltExecute(const HLT::TriggerElement* inputTE, HLT::TriggerElement* outputTE);
+  HLT::ErrorCode hltExecute(const HLT::TriggerElement* , HLT::TriggerElement*);
+  HLT::ErrorCode hltFinalize(); 
+  
+  private:
+  /*
+  template <class T>
+    StatusCode retrieve(ToolHandle<T>& pHandle, bool bError = true)
+    {
+      StatusCode sc = pHandle.retrieve();
+      if (sc.isFailure())
+        {
+	  if (bError)
+	    msg() << MSG::ERROR << "Cannot retrieve " << pHandle << endreq;
+	  else
+	    msg() << MSG::WARNING << "Cannot retrieve " << pHandle << endreq;
+        }
+        msg() << MSG::INFO << "Retrieved " << pHandle << endreq;
+        return sc;
+    }
+  */
+    // took out 2008-02-27 
+    // because MuGirl bring something else with the same name
+  //  StoreGateSvc* m_pEventStore;      //< The event store
+  //  ActiveStoreSvc* m_pActiveStore;     //< The active store
+  
+
+    struct CaloParticle
+    {
+        const xAOD::TrackParticle*   pTrackParticle;
+        const Trk::TrackParameters*  pTrackParameters;
+        double eta;
+        double phi;
+        bool isolated;
+        float dR;
+
+        CaloParticle() :
+	  pTrackParticle(NULL), pTrackParameters(NULL), eta(0.0), phi(0.0), isolated(true), dR(-1)
+        {}
+
+        CaloParticle(const xAOD::TrackParticle* pTParticle, const Trk::TrackParameters* pTParameters, double eta, double phi) :
+	  pTrackParticle(pTParticle), pTrackParameters(pTParameters), eta(eta), phi(phi), isolated(true), dR(99)
+        {}
+    }
+    ;
+    typedef std::vector<CaloParticle*> CaloParticleList;
+
+    bool generateMuGirl(MuGirlNS::CandidateSummary* summary);
+    //    void fillMuonSegmentColl();
+    void fillMuonSegmentColl(std::vector<const Muon::MuonSegment*> muonSegmentList);
+    void testMuGirls();
+    void createCaloParticles();
+    void IsolatedIdTracks(double dR);
+    void calculateLHR(CaloParticle* pParticle);
+    Rec::TrackParticle* TEcreateParticle(const Trk::Track* track,const Trk::VxCandidate* vxCandidate,Trk::TrackParticleOrigin prtOrigin);
+
+    template <class T>
+    StatusCode retrieve(ToolHandle<T>& pHandle, bool bError = true)
+    {
+        StatusCode sc = pHandle.retrieve();
+        if (sc.isFailure())
+        {
+            if (bError)
+	      msg() << MSG::ERROR << "Cannot retrieve " << pHandle << endreq;
+            else
+	      msg() << MSG::WARNING << "Cannot retrieve " << pHandle << endreq;
+        }
+        else
+	  msg() << MSG::INFO << "Retrieved " << pHandle << endreq;
+        return sc;
+    }
+    template <class T>
+    StatusCode retrieve(ServiceHandle<T>& pHandle, bool bError = true)
+    {
+        StatusCode sc = pHandle.retrieve();
+        if (sc.isFailure())
+        {
+            if (bError)
+                msg() << MSG::ERROR << "Cannot retrieve service " << pHandle << endreq;
+            else
+                msg() << MSG::WARNING << "Cannot retrieve service " << pHandle << endreq;
+        }
+        else
+            msg() << MSG::INFO << "Retrieved service " << pHandle << endreq;
+        return sc;
+    }
+
+//    MsgStream                               m_log;
+    FloatProperty                           m_ptLowerLimit;     //< The pT cut on tracks  
+    StringProperty                          m_ntupleName;       //< The name of the output NTuple  
+    StringProperty                          m_ntupleTitle;      //< The label of the output NTuple  
+    FloatProperty                           m_roadDeltaPhi;     //< The phi width of crude roads  
+    BooleanProperty                         m_doNTuple;         //< Create the special NTuple  
+    BooleanProperty                         m_doLHR;
+    BooleanProperty                         m_doCSC;
+    FloatProperty                           m_barrelNNCut;      //< Cut on NN function for barrel  
+    FloatProperty                           m_endcapNNCut;      //< Cut on NN function for endcap  
+    StringProperty                          m_sSegmentCollection; //< The name of the segment SG collection  
+
+    StringProperty                          m_sRefittedTrkCollection; /**< The name of the RefittedTrk SG collection */
+    StringProperty                          m_RefittedTrkLocation; /**< The name of the RefittedTrk SG collection */
+
+    StringProperty                          m_inDetParticlesLocation;
+    StringProperty                          m_CaloCollection;
+    BooleanProperty                         m_doStau;
+    FloatProperty                           m_stauPtCut;
+    FloatProperty                           m_mfPtCut;
+
+    //const MuonGM::MuonDetectorManager*      m_pMuonMgr;         //< The Muon manager  
+    Trk::SegmentCollection*                 m_pSegmentCollection;
+    //adeed 2008-07-21
+    TrackCollection*                        m_pRefittedTrkCollection;
+    Rec::TrackParticleContainer*            m_pRefittedTrkContainer;
+    std::vector<CaloCell_ID::CaloSample>    m_caloLayers;
+    std::string                             m_applyLHR;
+    double                                  m_idR;
+    double                                  m_lhr;
+    double                                  m_eOverP;
+
+    BooleanProperty                         m_doTruth;
+    BooleanProperty                         m_doGlobalFit;
+    BooleanProperty                         m_doSAFit;
+    BooleanProperty                         m_doMuonFeature;
+    BooleanProperty                         m_doANNSelection;
+    BooleanProperty                         m_doParticleCreator;
+    // const Trk::RunOutlierRemoval      m_runOutlier;
+    //const Trk::ParticleHypothesis         m_matEffects;
+
+    ElementLinkVector<xAOD::TrackParticleContainer>  m_inDetTrackParticleLinks;
+    CaloParticleList                        m_caloParticles;
+    const xAOD::CaloClusterContainer*       m_pClusCollection;
+    NTuple::Tuple*                          m_pCandNTuple;
+
+    // Tool Handles
+    // didn't compaile trying "old ver"
+    ServiceHandle<StoreGateSvc>                         m_pEventStore;      //< The event store  
+    ToolHandle<MuGirlNS::ICandidateTool>                m_pCandidate;       //< The Muon candidate  
+    ToolHandle<IExtrapolateToCaloTool>                  m_pToCalo;
+    ToolHandle<ICaloMuonLikelihoodTool>                 m_pMuLHR;
+    ToolHandle<MuGirlNS::IPerformanceTruthTool>         m_pTruthTool;
+    // 2008-12-13 downgrade
+    //    ToolHandle< Trk::ITrackParticleCreatorTool >              m_particleCreatorTool;
+    //    ToolHandle< Trk::ParticleCreatorTool >              m_particleCreatorTool;
+
+    ToolHandle<MuGirlNS::IGlobalFitTool>                m_pStauGlobalFitTool;
+    ToolHandle<MuGirlNS::IGlobalFitTool>                m_pGlobalFitTool;
+    ToolHandle<MuGirlNS::IGlobalFitTool>                m_pMuonFeatureGlobalFitTool;
+    ToolHandle<MuGirlNS::IANNSelectionTool>             m_pANNSelectionTool;
+    ToolHandle<MuGirlNS::IMuGirlParticleCreatorTool>    m_pParticleCreatorTool;
+    //<S>
+    ToolHandle<MuGirlNS::IStauTool>                     m_pStauTool;        //< The Stau tool  
+
+    ServiceHandle<MagField::IMagFieldSvc>               m_magFieldSvc;
+
+    MuGirlNS::SegmentManager*                           m_pSegmentManager;
+
+
+    TrigMuonEFInfoContainer* eMuonEFInfoCont;
+    Rec::TrackParticleContainer* eTrkParCont;
+
+    TrigTimer* m_timerExecTotal;
+
+    std::vector<float> muon_pT;
+    std::vector<float> muon_phi;
+    std::vector<float> muon_cotTh;
+    std::vector<int> muon_nMDThits;
+    std::vector<int> muon_nMDThitsInseg;
+    std::vector<int> muon_nRPChitsInseg;
+    std::vector<int> muon_nTGChitsInseg;
+    std::vector<int> muon_nTGCRPChitsInseg;
+    std::vector<int> muon_nCSCPhihits;
+    std::vector<int> muon_nCSCEtahits;
+    std::vector<int> muon_nRPCPhihits;
+    std::vector<int> muon_nRPCEtahits;
+    std::vector<int> muon_nTGCPhihits;
+    std::vector<int> muon_nTGCEtahits;
+    std::vector<int> muon_nTGCRPCPhihits;
+    std::vector<int> muon_nTGCRPCEtahits;
+    std::vector<int> muon_nMDTsegs;
+    std::vector<int> muon_nRPCsegs;
+    std::vector<int> muon_nCSCsegs;
+    std::vector<int> muon_nTGCsegs;
+    std::vector<int> muon_nTGCRPCsegs;
+    std::vector<float> muon_beta;
+    std::vector<float> muon_nnBarrel;
+    std::vector<float> muon_nnEndcap;
+    std::vector<float> muon_RPCHitsMeasTime;
+    std::vector<float> muon_RPCHitsPropTime;
+    std::vector<float> muon_RPCHitsTof;
+    std::vector<float> muon_RPCHitsDis;
+
+    // for perform
+    TrigMuGirlNtuple*                   m_pTrigMuGirlNtuple;
+    HLT::ErrorCode doMuTruthPerformance();
+    NTuple::Tuple*                      m_ntuplePerformance;
+    StringProperty                      m_ntupleNamePerformance;       /**< The name of the output NTuple */
+    StringProperty                      m_ntupleTitlePerformance;      /**< The label of the output NTuple */
+    BooleanProperty                     m_doTruthPerformance;
+    BooleanProperty                     m_doNTuplePerformance;
+
+    int eRunNumber;
+    int eEventNumber;
+
+    float NN[6];
+    float dRmu;
+    unsigned short int m_roi;
+};
+
+#endif
diff --git a/Trigger/TrigAlgorithms/TrigMuGirl/TrigMuGirl/TrigMuGirlAlg.h b/Trigger/TrigAlgorithms/TrigMuGirl/TrigMuGirl/TrigMuGirlAlg.h
new file mode 100644
index 00000000000..8b0c811e4f4
--- /dev/null
+++ b/Trigger/TrigAlgorithms/TrigMuGirl/TrigMuGirl/TrigMuGirlAlg.h
@@ -0,0 +1,81 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+/***************************************************************************
+    Authors: E. Reinherz-Aronis, A. Kreisel 
+             based on MuGirl by Shlomit Tarem
+***************************************************************************/
+#ifndef TRIGMUGIRLALG_H
+#define TRIGMUGIRLALG_H
+
+#include "GaudiKernel/Algorithm.h"
+#include "GaudiKernel/ToolHandle.h"
+
+//* Trigger includes *//
+#include <string>
+#include "TrigInterfaces/FexAlgo.h"
+
+// for the optional output object
+#include "TrigMuonEvent/TrigMuonEFCbTrack.h"
+#include "TrigMuonEvent/TrigMuonEFInfo.h"
+#include "TrigMuonEvent/TrigMuonEFInfoContainer.h"
+#include "TrigMuonEvent/TrigMuonEFInfoTrackContainer.h"
+
+#include "TrigMuonToolInterfaces/TrigMuonEFMonVars.h"
+
+// Tracking includes
+#include "TrkToolInterfaces/ITrackParticleCreatorTool.h"
+
+namespace HLT {
+  class TriggerElement;
+}
+
+class ITrigMuGirlTool;
+
+class TrigMuGirlAlg : public HLT::FexAlgo {
+  
+  public:
+  
+  TrigMuGirlAlg(const std::string&, ISvcLocator*);
+  ~TrigMuGirlAlg();
+  
+  HLT::ErrorCode hltInitialize();
+  HLT::ErrorCode hltExecute(const HLT::TriggerElement* , HLT::TriggerElement*);
+  HLT::ErrorCode hltFinalize(); 
+  
+  private:
+
+    template <class T>
+    StatusCode retrieve(ToolHandle<T>& pHandle, bool bError = true)
+    {
+        StatusCode sc = pHandle.retrieve();
+        if (sc.isFailure())
+        {
+            if (bError)
+	      msg() << MSG::ERROR << "Cannot retrieve " << pHandle << endreq;
+            else
+	      msg() << MSG::WARNING << "Cannot retrieve " << pHandle << endreq;
+        }
+        else
+	  msg() << MSG::INFO << "Retrieved " << pHandle << endreq;
+        return sc;
+    }
+
+    // Tool Handles
+    ToolHandle<ITrigMuGirlTool>                      m_trigMuGirlTool;       /**< The MuGirl Trigger Tool */
+    ToolHandle< Trk::ITrackParticleCreatorTool >     m_particleCreatorTool;  /**< The ID Particle Creator Tool */
+
+
+    std::string                  m_idTrackParticlesName;
+
+    BooleanProperty              m_doMuonFeature;
+
+    TrigMuonEFInfoContainer*     m_eMuonEFInfoCont;
+    Rec::TrackParticleContainer* m_eTrkParCont;
+
+    TrigMuGirlMonVars            m_TrigMuGirlMonVars;
+    std::vector<TrigTimer*>      m_TrigMuGirlTimers;
+};
+
+#endif
diff --git a/Trigger/TrigAlgorithms/TrigMuGirl/TrigMuGirl/TrigMuGirlNtuple.h b/Trigger/TrigAlgorithms/TrigMuGirl/TrigMuGirl/TrigMuGirlNtuple.h
new file mode 100644
index 00000000000..622bcbb10d1
--- /dev/null
+++ b/Trigger/TrigAlgorithms/TrigMuGirl/TrigMuGirl/TrigMuGirlNtuple.h
@@ -0,0 +1,74 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef TRIGMUGIRLNTUPLE_H
+#define TRIGMUGIRLNTUPLE_H
+
+#include "GaudiKernel/NTuple.h"
+#include "GaudiKernel/StatusCode.h"
+#include "StoreGate/StoreGateSvc.h"
+#include "DataModel/DataLink.h"
+
+class INTupleSvc;
+class TrigMuGirl;
+
+class TrigMuGirlNtuple
+{
+public:
+
+  TrigMuGirlNtuple(HLT::FexAlgo* pTrigMuGirl, INTupleSvc* pNTupleSvc);
+
+  StatusCode book( const std::string& ntupleName, const std::string& ntupleTitle);
+  StatusCode writeRecord();
+  StatusCode fillTruth(int nMu, double phi, double cot, double eta, double pt, int pdg, int parentPdg);
+  StatusCode fillReco(int nMu, double phi, double cot,  double eta, double pt, int charge, float NN0, float NN1, float NN2, float NN3, float NN4, float NN5, float LHR, float iso , float dR);
+
+  StatusCode fillEvent(int event, int run);
+    
+private:
+
+    // Truth muon parameters
+    NTuple::Item<long>    m_NumTruthMuon;
+    NTuple::Array<float>  m_TruthMuonPt;
+    NTuple::Array<float>  m_TruthMuonPhi;
+    NTuple::Array<float>  m_TruthMuonCot;
+    NTuple::Array<float>  m_TruthMuonEta;
+    NTuple::Array<long>   m_TruthMuonPdg;
+    NTuple::Array<long>   m_TruthMuonParentPdg;
+  
+    // Reco muon parameters
+    NTuple::Item<long>    m_NumRecoMuon;
+    NTuple::Array<float>  m_RecoMuonPt;
+    NTuple::Array<float>  m_RecoMuonPhi;
+    NTuple::Array<float>  m_RecoMuonCot;
+    NTuple::Array<float>  m_RecoMuonEta;
+    NTuple::Array<long>   m_RecoMuonCharge;
+    NTuple::Array<float>  m_RecoMuonNN0;
+    NTuple::Array<float>  m_RecoMuonNN1;
+    NTuple::Array<float>  m_RecoMuonNN2;
+    NTuple::Array<float>  m_RecoMuonNN3;
+    NTuple::Array<float>  m_RecoMuonNN4;
+    NTuple::Array<float>  m_RecoMuonNN5;
+    NTuple::Array<float>  m_RecoMuonLHR;
+    NTuple::Array<float>  m_RecoMuonIso;
+    NTuple::Array<float>  m_RecoMuondR;
+
+    // event info
+    NTuple::Item<long>   m_Event;
+    NTuple::Item<long>   m_Run;
+
+    int m_max_pair;
+    int m_max_dig;
+    int m_max_idtrack;
+    int m_maxTruthMuons;
+    //    TrigMuGirlFex* m_pTrigMuGirlFex; /**< The TrigMuGirlFex algorithm */
+    HLT::FexAlgo* m_pTrigMuGirl; /**< The TrigMuGirlFex algorithm */
+    NTuple::Tuple*  m_pNtuple;         /**< The NTuple object */
+    INTupleSvc*     m_pNTupleSvc;      /**< The Athena NTuple service */
+    std::string     m_ntupleName;      /**< The NTuple name */
+
+};
+
+#endif // TRIGMUGIRLNTUPLE_H 
+
diff --git a/Trigger/TrigAlgorithms/TrigMuGirl/TrigMuGirl/TrigMuGirlTool.h b/Trigger/TrigAlgorithms/TrigMuGirl/TrigMuGirl/TrigMuGirlTool.h
new file mode 100644
index 00000000000..852d8393053
--- /dev/null
+++ b/Trigger/TrigAlgorithms/TrigMuGirl/TrigMuGirl/TrigMuGirlTool.h
@@ -0,0 +1,314 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef TRIGMUGIRL_TRIGMUGIRLTOOL_H
+#define TRIGMUGIRL_TRIGMUGIRLTOOL_H
+
+#include "AthenaBaseComps/AthAlgTool.h"
+
+//* Trigger includes *//
+#include <string>
+#include "TrigInterfaces/FexAlgo.h"
+
+#include "CaloIdentifier/CaloCell_ID.h"
+#include "TrkSegment/SegmentCollection.h"
+
+#include "TrigMuonEvent/MuonFeature.h"
+#include "TrigMuonEvent/CombinedMuonFeature.h"
+
+// for the optional output object
+#include "TrigMuonEvent/TrigMuonEFCbTrack.h"
+#include "TrigMuonEvent/TrigMuonEFInfo.h"
+#include "TrigMuonEvent/TrigMuonEFInfoContainer.h"
+#include "TrigMuonEvent/TrigMuonEFInfoTrackContainer.h"
+
+#include "GaudiKernel/NTuple.h"
+
+#include "TrigTimeAlgs/TrigTimerSvc.h"
+#include "TrkTrack/TrackCollection.h"
+#include "Particle/TrackParticleContainer.h"
+#include "MuGirlInterfaces/CandidateSummary.h"
+
+#include "TrigMuonToolInterfaces/ITrigMuGirlTool.h"
+#include "TrigMuonToolInterfaces/TrigMuonEFMonVars.h"
+
+#include "xAODTracking/TrackParticleContainer.h"
+
+namespace HLT {
+  class TriggerElement;
+}
+
+class StoreGateSvc;
+class IExtrapolateToCaloTool;
+class ICaloMuonLikelihoodTool;
+class CaloClusterContainer;
+class EventInfo;
+
+//namespace xAOD {
+//    TrackParticle;
+//}
+
+//namespace Rec
+//{
+//class TrackParticle;
+//class TrackParticleContainer;
+//}
+
+namespace MuonGM
+{
+class MuonDetectorManager;
+}
+
+namespace Muon
+{
+class IMdtDriftCircleOnTrackCreator;
+class IMuonClusterOnTrackCreator;
+class IMuonSegmentMaker;
+class IMuGirlParticleCreatorTool;
+class MuonSegment;
+}
+
+namespace NTuple
+{
+class Tuple;
+}
+
+namespace MuGirlNS
+{
+class ICandidateTool;
+class IPerformanceTruthTool;
+class IGlobalFitTool;
+class CandidateSummary;
+class IStauTool;
+class IANNSelectionTool;
+class IMuGirlParticleCreatorTool;
+class SegmentManager;
+}
+
+namespace Trk
+{
+class IIntersector;
+class Surface;
+class ParticleCreatorTool;
+}
+
+namespace MagField {
+class IMagFieldSvc;
+}
+
+
+class INTupleSvc;
+class TrigMuGirlNtuple;
+
+class TrigMuGirlTool : public AthAlgTool, public ITrigMuGirlTool
+{
+  
+ public:
+  
+  TrigMuGirlTool(const std::string& type,
+		 const std::string& name,
+		 const IInterface* parent);
+  
+  virtual ~TrigMuGirlTool();
+  
+  StatusCode initialize();
+  StatusCode finalize();
+  
+  void declareMonitoringVariables(HLT::FexAlgo* fexAlgo, TrigMuGirlMonVars& monVars);
+  void addTimers(HLT::FexAlgo* fexAlgo, std::vector<TrigTimer*>& timers);
+  
+  HLT::ErrorCode initNtuple(HLT::FexAlgo* fexAlgo);
+
+  HLT::ErrorCode initRoiProcessing(std::vector<TrigTimer*>& timers, TrigMuonEFInfoContainer* eMuonEFInfoCont);
+
+  HLT::ErrorCode processMuonFeatures(const std::vector<const MuonFeature*>& vectorOfMuonFeature,
+				     const ElementLink<CombinedMuonFeatureContainer>& CombinedMuonFeatureEL);
+
+  HLT::ErrorCode processTrackCollections(const ElementLinkVector<xAOD::TrackParticleContainer>& idTrackParticleLinks,
+					 const std::vector<const xAOD::CaloClusterContainer*>& vectorOfClusterContainers);
+ 
+  HLT::ErrorCode finalizeRoiProcessing(std::vector<TrigTimer*>& timers,
+				       TrigMuonEFInfoContainer* eMuonEFInfoCont,
+				       Rec::TrackParticleContainer*& eTrkParCont,
+				       TrigMuGirlMonVars& monVars);
+  
+
+ private:
+    struct CaloParticle
+    {
+        const xAOD::TrackParticle* pTrackParticle;
+        double eta;
+        double phi;
+        bool isolated;
+        float dR;
+
+        CaloParticle() :
+	  pTrackParticle(NULL), eta(0.0), phi(0.0), isolated(true), dR(-1)
+        {}
+
+        CaloParticle(const xAOD::TrackParticle* pTrackParticle, double eta, double phi) :
+	  pTrackParticle(pTrackParticle), eta(eta), phi(phi), isolated(true), dR(99)
+        {}
+    }
+    ;
+    typedef std::vector<CaloParticle*> CaloParticleList;
+
+    bool generateMuGirl(MuGirlNS::CandidateSummary* summary);
+    //    void fillMuonSegmentColl();
+    void fillMuonSegmentColl(std::vector<const Muon::MuonSegment*> muonSegmentList);
+    void testMuGirls();
+    void createCaloParticles();
+    void IsolatedIdTracks(double dR);
+    void calculateLHR(CaloParticle* pParticle);
+    Rec::TrackParticle* TEcreateParticle(const Trk::Track* track,const Trk::VxCandidate* vxCandidate,Trk::TrackParticleOrigin prtOrigin);
+
+  
+  template <class T>
+    StatusCode retrieve(ToolHandle<T>& pHandle, bool bError = true)
+    {
+      StatusCode sc = pHandle.retrieve();
+      if (sc.isFailure())
+        {
+	  if (bError)
+	    msg() << MSG::ERROR << "Cannot retrieve " << pHandle << endreq;
+	  else
+	    msg() << MSG::WARNING << "Cannot retrieve " << pHandle << endreq;
+        }
+      else
+	msg() << MSG::INFO << "Retrieved " << pHandle << endreq;
+      return sc;
+    }
+
+  template <class T>
+    StatusCode retrieve(ServiceHandle<T>& pHandle, bool bError = true)
+    {
+        StatusCode sc = pHandle.retrieve();
+        if (sc.isFailure())
+        {
+            if (bError)
+                msg() << MSG::ERROR << "Cannot retrieve service " << pHandle << endreq;
+            else
+                msg() << MSG::WARNING << "Cannot retrieve service " << pHandle << endreq;
+        }
+        else
+            msg() << MSG::INFO << "Retrieved service " << pHandle << endreq;
+        return sc;
+    }
+
+
+    FloatProperty                           m_ptLowerLimit;     //< The pT cut on tracks  
+    StringProperty                          m_ntupleName;       //< The name of the output NTuple  
+    StringProperty                          m_ntupleTitle;      //< The label of the output NTuple  
+    FloatProperty                           m_roadDeltaPhi;     //< The phi width of crude roads  
+    BooleanProperty                         m_doNTuple;         //< Create the special NTuple  
+    BooleanProperty                         m_doLHR;
+    BooleanProperty                         m_doCSC;
+    FloatProperty                           m_barrelNNCut;      //< Cut on NN function for barrel  
+    FloatProperty                           m_endcapNNCut;      //< Cut on NN function for endcap  
+    StringProperty                          m_sSegmentCollection; //< The name of the segment SG collection  
+
+    StringProperty                          m_sRefittedTrkCollection; /**< The name of the RefittedTrk SG collection */
+    StringProperty                          m_RefittedTrkLocation; /**< The name of the RefittedTrk SG collection */
+
+    StringProperty                          m_inDetParticlesLocation;
+    StringProperty                          m_CaloCollection;
+    BooleanProperty                         m_doStau;
+    FloatProperty                           m_stauPtCut;
+    FloatProperty                           m_mfPtCut;
+
+    Trk::SegmentCollection*                 m_pSegmentCollection;
+    TrackCollection*                        m_pRefittedTrkCollection;
+    Rec::TrackParticleContainer*            m_pRefittedTrkContainer;
+    std::vector<CaloCell_ID::CaloSample>    m_caloLayers;
+    std::string                             m_applyLHR;
+    double                                  m_idR;
+    double                                  m_lhr;
+    double                                  m_eOverP;
+
+    BooleanProperty                         m_doTruth;
+    BooleanProperty                         m_doGlobalFit;
+    BooleanProperty                         m_doSAFit;
+    BooleanProperty                         m_doMuonFeature;
+    BooleanProperty                         m_doANNSelection;
+    BooleanProperty                         m_doParticleCreator;
+
+    ElementLinkVector<xAOD::TrackParticleContainer>  m_inDetTrackParticleLinks;
+    CaloParticleList                        m_caloParticles;
+    const xAOD::CaloClusterContainer*       m_pClusCollection;
+    NTuple::Tuple*                          m_pCandNTuple;
+
+    const EventInfo*                        m_pEventInfo;
+    
+    // Tool Handles
+    ServiceHandle<StoreGateSvc>                         m_pEventStore;      //< The event store  
+    ToolHandle<MuGirlNS::ICandidateTool>                m_pCandidate;       //< The Muon candidate  
+    ToolHandle<IExtrapolateToCaloTool>                  m_pToCalo;
+    ToolHandle<ICaloMuonLikelihoodTool>                 m_pMuLHR;
+    ToolHandle<MuGirlNS::IPerformanceTruthTool>         m_pTruthTool;
+    ToolHandle<MuGirlNS::IGlobalFitTool>                m_pStauGlobalFitTool;
+    ToolHandle<MuGirlNS::IGlobalFitTool>                m_pGlobalFitTool;
+    ToolHandle<MuGirlNS::IGlobalFitTool>                m_pMuonFeatureGlobalFitTool;
+    ToolHandle<MuGirlNS::IANNSelectionTool>             m_pANNSelectionTool;
+    ToolHandle<MuGirlNS::IMuGirlParticleCreatorTool>    m_pParticleCreatorTool;
+    //<S>
+    ToolHandle<MuGirlNS::IStauTool>                     m_pStauTool;        //< The Stau tool  
+    ServiceHandle<MagField::IMagFieldSvc>               m_magFieldSvc;
+    MuGirlNS::SegmentManager*                           m_pSegmentManager;
+
+    TrigTimer* m_timerExecTotal;
+
+    MuGirlNS::CandidateSummaryList      m_summaryList;
+ 
+    std::vector<float> muon_pT;
+    std::vector<float> muon_phi;
+    std::vector<float> muon_cotTh;
+    std::vector<int> muon_nMDThits;
+    std::vector<int> muon_nMDThitsInseg;
+    std::vector<int> muon_nRPChitsInseg;
+    std::vector<int> muon_nTGChitsInseg;
+    std::vector<int> muon_nTGCRPChitsInseg;
+    std::vector<int> muon_nCSCPhihits;
+    std::vector<int> muon_nCSCEtahits;
+    std::vector<int> muon_nRPCPhihits;
+    std::vector<int> muon_nRPCEtahits;
+    std::vector<int> muon_nTGCPhihits;
+    std::vector<int> muon_nTGCEtahits;
+    std::vector<int> muon_nTGCRPCPhihits;
+    std::vector<int> muon_nTGCRPCEtahits;
+    std::vector<int> muon_nMDTsegs;
+    std::vector<int> muon_nRPCsegs;
+    std::vector<int> muon_nCSCsegs;
+    std::vector<int> muon_nTGCsegs;
+    std::vector<int> muon_nTGCRPCsegs;
+    std::vector<float> muon_beta;
+    std::vector<float> muon_nnBarrel;
+    std::vector<float> muon_nnEndcap;
+    std::vector<float> muon_RPCHitsMeasTime;
+    std::vector<float> muon_RPCHitsPropTime;
+    std::vector<float> muon_RPCHitsTof;
+    std::vector<float> muon_RPCHitsDis;
+
+    // for perform
+    TrigMuGirlNtuple*                   m_pTrigMuGirlNtuple;
+    HLT::ErrorCode doMuTruthPerformance();
+    NTuple::Tuple*                      m_ntuplePerformance;
+    StringProperty                      m_ntupleNamePerformance;       /**< The name of the output NTuple */
+    StringProperty                      m_ntupleTitlePerformance;      /**< The label of the output NTuple */
+    BooleanProperty                     m_doTruthPerformance;
+    BooleanProperty                     m_doNTuplePerformance;
+
+    int eRunNumber;
+    int eEventNumber;
+
+    float NN[6];
+    float dRmu;
+    unsigned short int m_roi;
+
+    float m_TrackIso;
+
+};
+
+
+#endif // TRIGMUGIRL_TRIGMUGIRLTOOL_H
+
diff --git a/Trigger/TrigAlgorithms/TrigMuGirl/TrigMuGirl/TrigPostFex.h b/Trigger/TrigAlgorithms/TrigMuGirl/TrigMuGirl/TrigPostFex.h
new file mode 100644
index 00000000000..92a8dc8fefb
--- /dev/null
+++ b/Trigger/TrigAlgorithms/TrigMuGirl/TrigMuGirl/TrigPostFex.h
@@ -0,0 +1,66 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+/***************************************************************************
+    Authors: E. Reinherz-Aronis, A. Kreisel 
+             This Fex is able to run after both TrigMuGirl and TrigMooHLT
+             for now the code assum it's coming in the same sequqance 
+             as TrigMuGirl or TrigMooHLT 
+***************************************************************************/
+#ifndef TRIGPOSTFEX_H
+#define TRIGPOSTFEX_H
+
+#include "TrigInterfaces/FexAlgo.h"
+
+#include "EventInfo/EventInfo.h"
+#include "EventInfo/EventID.h"
+
+//class TriggerElement;
+class TrigPostFexNtuple;
+
+class TrigPostFex: public HLT::FexAlgo{
+
+public:
+    TrigPostFex(const std::string& name, ISvcLocator* pSvcLocator);
+    ~TrigPostFex();
+
+    HLT::ErrorCode hltInitialize();
+    HLT::ErrorCode hltFinalize();
+    HLT::ErrorCode hltExecute(const HLT::TriggerElement* inputTE, HLT::TriggerElement* outputTE);
+    HLT::ErrorCode doMuTruth();
+	
+private:
+    
+    DoubleProperty m_MassMin;
+    DoubleProperty m_MassMax;
+
+    StoreGateSvc* m_pStoreGate;
+
+    const EventInfo* pEventInfo;
+    int eRunNumber;
+    int eEventNumber;
+
+    float muon_pT;
+
+    std::vector<float> m_pt;
+    std::vector<float> m_cotTh;
+    std::vector<float> m_phi;
+    std::vector<float> m_m;
+    std::vector<float> m_charge;
+
+    int NumberOfMuons;
+
+    StringProperty                      m_ntupleName;       /**< The name of the output NTuple */
+    StringProperty                      m_ntupleTitle;      /**< The label of the output NTuple */
+    StringProperty			m_fileName;
+    BooleanProperty                     m_doTruth;
+    BooleanProperty                     m_doNTuple;
+    TrigPostFexNtuple*                     m_pTrigPostFexNtuple;
+    NTuple::Tuple*                      m_ntuple;
+    int nMuons;
+    int whichOutput;
+
+};
+
+#endif 
diff --git a/Trigger/TrigAlgorithms/TrigMuGirl/TrigMuGirl/TrigPostFexNtuple.h b/Trigger/TrigAlgorithms/TrigMuGirl/TrigMuGirl/TrigPostFexNtuple.h
new file mode 100644
index 00000000000..db0ffdcdf00
--- /dev/null
+++ b/Trigger/TrigAlgorithms/TrigMuGirl/TrigMuGirl/TrigPostFexNtuple.h
@@ -0,0 +1,63 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef TRIGPOSTFEXNTUPLE_H
+#define TRIGPOSTFEXNTUPLE_H
+
+#include "GaudiKernel/NTuple.h"
+#include "GaudiKernel/StatusCode.h"
+#include "StoreGate/StoreGateSvc.h"
+#include "DataModel/DataLink.h"
+
+class INTupleSvc;
+class TrigPostFex;
+
+class TrigPostFexNtuple
+{
+public:
+
+    TrigPostFexNtuple(TrigPostFex* pTrigPostFex, INTupleSvc* pNTupleSvc);
+
+    StatusCode book( const std::string& ntupleName, const std::string& ntupleTitle);
+    StatusCode writeRecord();
+  StatusCode fillTruth(int nMu, double phi, double cot, double eta, double pt, int pdg, int parentPdg);
+  StatusCode fillReco(int nMu, double phi, double cot,  double eta, double pt, int charge);
+  StatusCode fillEvent(int event, int run);
+    
+private:
+
+    // Truth muon parameters
+    NTuple::Item<long>    m_NumTruthMuon;
+    NTuple::Array<float>  m_TruthMuonPt;
+    NTuple::Array<float>  m_TruthMuonPhi;
+    NTuple::Array<float>  m_TruthMuonCot;
+    NTuple::Array<float>  m_TruthMuonEta;
+    NTuple::Array<long>   m_TruthMuonPdg;
+    NTuple::Array<long>   m_TruthMuonParentPdg;
+  
+    // Reco muon parameters
+    NTuple::Item<long>    m_NumRecoMuon;
+    NTuple::Array<float>  m_RecoMuonPt;
+    NTuple::Array<float>  m_RecoMuonPhi;
+    NTuple::Array<float>  m_RecoMuonCot;
+    NTuple::Array<float>  m_RecoMuonEta;
+    NTuple::Array<long>   m_RecoMuonCharge;
+
+    // event info
+    NTuple::Item<long>   m_Event;
+    NTuple::Item<long>   m_Run;
+
+    int m_max_pair;
+    int m_max_dig;
+    int m_max_idtrack;
+    int m_maxTruthMuons;
+    TrigPostFex* m_pTrigPostFex; /**< The TrigPostFex algorithm */
+    NTuple::Tuple*  m_pNtuple;         /**< The NTuple object */
+    INTupleSvc*     m_pNTupleSvc;      /**< The Athena NTuple service */
+    std::string     m_ntupleName;      /**< The NTuple name */
+
+};
+
+#endif // TRIGPOSTFEXNTUPLE_H 
+
diff --git a/Trigger/TrigAlgorithms/TrigMuGirl/cmt/requirements b/Trigger/TrigAlgorithms/TrigMuGirl/cmt/requirements
new file mode 100755
index 00000000000..cc498af94ec
--- /dev/null
+++ b/Trigger/TrigAlgorithms/TrigMuGirl/cmt/requirements
@@ -0,0 +1,51 @@
+package TrigMuGirl
+
+public
+use  AtlasPolicy                AtlasPolicy-*
+use  AthenaBaseComps            AthenaBaseComps-*               Control
+use  CaloIdentifier             CaloIdentifier-*                Calorimeter
+use  DataModel                  DataModel-*                     Control
+use  EventInfo                  EventInfo-*                     Event
+use  xAODTracking               xAODTracking-*                  Event/xAOD
+use  xAODCaloEvent              xAODCaloEvent-*                 Event/xAOD
+use  GaudiInterface             GaudiInterface-*                External
+use  MuGirlInterfaces           MuGirlInterfaces-*              Reconstruction/MuonIdentification
+use  Particle                   Particle-*                      Reconstruction
+use  StoreGate                  StoreGate-*                     Control
+use  TrigInterfaces             TrigInterfaces-*                Trigger/TrigSteer
+use  TrigMuonEvent              TrigMuonEvent-*                 Trigger/TrigEvent
+use  TrigTimeAlgs               TrigTimeAlgs-*                  Trigger/TrigTools
+use  TrkSegment                 TrkSegment-*                    Tracking/TrkEvent
+use  TrkTrack                   TrkTrack-*                      Tracking/TrkEvent
+use  TrigMuonToolInterfaces     TrigMuonToolInterfaces-*        Trigger/TrigTools
+use  TrkToolInterfaces          TrkToolInterfaces-*             Tracking/TrkTools
+
+private
+use  AtlasCLHEP                 AtlasCLHEP-*                    External
+use  CaloEvent                  CaloEvent-*                     Calorimeter
+use  GeneratorObjects           GeneratorObjects-*              Generators
+use  ICaloTrkMuIdTools          ICaloTrkMuIdTools-*             Reconstruction/MuonIdentification
+use  RecoToolInterfaces         RecoToolInterfaces-*            Reconstruction/RecoTools
+use  MuonReadoutGeometry        MuonReadoutGeometry-*           MuonSpectrometer/MuonDetDescr
+use  MuonRecToolInterfaces      MuonRecToolInterfaces-*         MuonSpectrometer/MuonReconstruction/MuonRecTools
+use  RegionSelector             RegionSelector-*                DetectorDescription
+use  TrigNavigation             TrigNavigation-*                Trigger/TrigEvent
+use  TrigSteeringEvent          TrigSteeringEvent-*             Trigger/TrigEvent
+use  TrigCaloEvent              TrigCaloEvent-*                 Trigger/TrigEvent
+use  TrkExInterfaces            TrkExInterfaces-*               Tracking/TrkExtrapolation
+use  TrkExUtils                 TrkExUtils-*                    Tracking/TrkExtrapolation
+use  MagFieldInterfaces         MagFieldInterfaces-*            MagneticField
+
+
+
+
+public
+library TrigMuGirl *.cxx -s=components *.cxx
+
+apply_pattern component_library
+#apply_pattern dual_use_library files=*.cxx
+#apply_pattern declare_runtime files="*.xml"
+#apply_pattern declare_joboptions files="*.py"
+apply_pattern declare_python_modules files="*.py"
+
+
diff --git a/Trigger/TrigAlgorithms/TrigMuGirl/python/TrigMuGirlConfig.py b/Trigger/TrigAlgorithms/TrigMuGirl/python/TrigMuGirlConfig.py
new file mode 100644
index 00000000000..1ea9e45bbb7
--- /dev/null
+++ b/Trigger/TrigAlgorithms/TrigMuGirl/python/TrigMuGirlConfig.py
@@ -0,0 +1,433 @@
+# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+
+from TrigMuGirl.TrigMuGirlConf import TrigMuGirl,TrigMuGirlTool
+from TrigMuGirl.TrigMuGirlFlags import trigMuGirlFlags 
+from AthenaCommon.GlobalFlags import globalflags
+from AthenaCommon.AppMgr import ServiceMgr
+from AthenaCommon import CfgMgr
+from AthenaCommon.SystemOfUnits import GeV
+
+#added MuGirl 2008-03-4
+#from TrigMuGirl.TrigMuGirlFlags import TrigmuGirlFlags
+from RecExConfig.RecFlags import rec
+from AthenaCommon.Configurable import *
+
+from AthenaCommon.AppMgr import ToolSvc
+from AthenaCommon.CfgGetter import getPublicTool
+
+#from AthenaCommon.AppMgr import ServiceMgr
+
+#from MuidCaloEnergyTools.MuidCaloEnergyToolsConf import Rec__MuidCaloEnergyParam
+#MuidCaloEnergyParam = Rec__MuidCaloEnergyParam(name = 'MuidCaloEnergyParam')
+#ToolSvc += MuidCaloEnergyParam
+
+#from MuidCaloEnergyTools.MuidCaloEnergyToolsConf import Rec__MuidCaloEnergyTool
+#MuidCaloEnergyToolParam = Rec__MuidCaloEnergyTool(name = 'MuidCaloEnergyToolParam',
+#                                                      CaloParamTool         = MuidCaloEnergyParam,
+#                                                      EnergyLossMeasurement = False)
+#ToolSvc += MuidCaloEnergyToolParam
+        # the default instance depends on the calorimeter and indet DetFlags
+
+#from MuidCaloEnergyTools.MuidCaloEnergyToolsConf import Rec__MuidCaloEnergyMeas
+#MuidCaloEnergyMeas = Rec__MuidCaloEnergyMeas(name = 'MuidCaloEnergyMeas',
+#                                                 CaloParamTool = MuidCaloEnergyParam)
+#ToolSvc += MuidCaloEnergyMeas
+#ToolSvc += Rec__MuidCaloEnergyTool(name = 'MuidCaloEnergyTool',
+#                                       CaloMeasTool  = MuidCaloEnergyMeas,
+#                                       CaloParamTool = MuidCaloEnergyParam)
+#
+#from MuidCaloEnergyTools.MuidCaloEnergyToolsConf import Rec__MuidCaloEnergyParam
+#MuidCaloEnergyParam = Rec__MuidCaloEnergyParam(name = 'MuidCaloEnergyParam')
+#ToolSvc += MuidCaloEnergyParam
+
+#from MuidCaloEnergyTools.MuidCaloEnergyToolsConf import Rec__MuidCaloEnergyTool
+#MuidCaloEnergyToolParam = Rec__MuidCaloEnergyTool(name = 'MuidCaloEnergyToolParam',
+#                                                      CaloParamTool         = MuidCaloEnergyParam,
+#                                                      EnergyLossMeasurement = False)
+#ToolSvc += MuidCaloEnergyToolParam
+## the default instance depends on the calorimeter and indet DetFlags
+#from MuidCaloEnergyTools.MuidCaloEnergyToolsConf import Rec__MuidCaloEnergyMeas
+#MuidCaloEnergyMeas = Rec__MuidCaloEnergyMeas(name = 'MuidCaloEnergyMeas',
+#                                                 CaloParamTool = MuidCaloEnergyParam)
+#ToolSvc += MuidCaloEnergyMeas
+#MuidCaloEnergyTool = Rec__MuidCaloEnergyTool(name = 'MuidCaloEnergyTool',
+#                                   CaloMeasTool  = MuidCaloEnergyMeas,
+#                                   CaloParamTool = MuidCaloEnergyParam)
+#ToolSvc += MuidCaloEnergyTool
+
+# set up the extrapolator and fitter as used by Muid
+from AthenaCommon.AppMgr import ServiceMgr
+
+from TrkDetDescrSvc.TrkDetDescrSvcConf import Trk__TrackingVolumesSvc
+ServiceMgr += Trk__TrackingVolumesSvc(BuildVolumesFromTagInfo = False)
+
+from MuonRecExample import MuonRecTools
+MuonExtrapolator              = MuonRecTools.getPublicTool('MuonExtrapolator')
+MuonStraightLineExtrapolator  = MuonRecTools.getPublicTool('MuonStraightLineExtrapolator')
+#from MuonTrackFinderTools.MuonTrackFinderToolsConf import Muon__MuonChamberHoleRecoveryTool
+#MuonHoleRecovery = Muon__MuonChamberHoleRecoveryTool("MuonHoleRecovery")
+#ToolSvc +=MuonHoleRecovery
+#MuonHoleRecovery              = MuonRecTools.getPublicTool('MuonChamberHoleRecoveryTool') 
+
+#from AthenaCommon.Include import include
+#include ('TrkDetDescrSvc/AtlasTrackingGeometrySvc.py')
+from TrkDetDescrSvc.AtlasTrackingGeometrySvc import AtlasTrackingGeometrySvc
+
+from TrkExRungeKuttaIntersector.TrkExRungeKuttaIntersectorConf import \
+     Trk__IntersectorWrapper as Propagator
+TrigMuGirl_MuidPropagator = Propagator(name = 'TrigMuGirl_MuidPropagator')
+ToolSvc += TrigMuGirl_MuidPropagator
+
+from TrkExTools.TrkExToolsConf import Trk__MaterialEffectsUpdator
+TrigMuGirl_MuidMaterialUpdator = Trk__MaterialEffectsUpdator(name = "TrigMuGirl_MuidMaterialEffectsUpdator")
+ToolSvc += TrigMuGirl_MuidMaterialUpdator
+
+from TrkExTools.TrkExToolsConf import Trk__Navigator
+TrigMuGirl_MuidNavigator = Trk__Navigator(name                = 'TrigMuGirl_MuidNavigator',
+                                    TrackingGeometrySvc = ServiceMgr.AtlasTrackingGeometrySvc
+                                    )
+ToolSvc += TrigMuGirl_MuidNavigator
+
+from TrkExTools.TrkExToolsConf import Trk__Extrapolator
+TrigMuGirl_MuidExtrapolator = Trk__Extrapolator( 
+    name = 'TrigMuGirl_MuidExtrapolator', 
+    Propagators = [ TrigMuGirl_MuidPropagator ],
+    MaterialEffectsUpdators = [ TrigMuGirl_MuidMaterialUpdator ],
+    Navigator=TrigMuGirl_MuidNavigator)
+ToolSvc += TrigMuGirl_MuidExtrapolator
+
+# material allocation 
+from TrkiPatFitter.TrkiPatFitterConf import Trk__MaterialAllocator 
+TrigMuGirl_MuidMaterialAllocator = Trk__MaterialAllocator( 
+    name                      = 'TrigMuGirl_MuidMaterialAllocator', 
+    AggregateMaterial         = True, 
+    Extrapolator              = TrigMuGirl_MuidExtrapolator, 
+    SpectrometerExtrapolator  = MuonExtrapolator, 
+    TrackingGeometrySvc       = ServiceMgr.AtlasTrackingGeometrySvc) 
+ToolSvc += TrigMuGirl_MuidMaterialAllocator 
+ 	
+
+
+
+from TrkiPatFitter.TrkiPatFitterConf import Trk__iPatFitter
+TrigMuGirl_iPatFitter = Trk__iPatFitter(
+    name                      = 'TrigMuGirl_iPatFitter',
+    AggregateMaterial         = True,
+    FullCombinedFit           = True,
+    MaterialAllocator         = TrigMuGirl_MuidMaterialAllocator)
+    #Extrapolator              = TrigMuGirl_MuidExtrapolator,
+    #MuonMaterialExtrapolator  = MuonExtrapolator,
+    #TrackingGeometrySvc       = ServiceMgr.AtlasTrackingGeometrySvc)
+TrigMuGirl_iPatSLFitter = Trk__iPatFitter(
+    name                      = 'TrigMuGirl_iPatSLFitter',
+    FullCombinedFit           = True,
+    LineFit                   = True,
+    MaterialAllocator         = TrigMuGirl_MuidMaterialAllocator)
+    #Extrapolator              = MuonStraightLineExtrapolator,
+    #MuonMaterialExtrapolator  = MuonStraightLineExtrapolator,
+    #TrackingGeometrySvc       = ServiceMgr.AtlasTrackingGeometrySvc)
+
+
+ToolSvc += TrigMuGirl_iPatFitter
+ToolSvc += TrigMuGirl_iPatSLFitter
+
+TrigMuGirl_MuidTrackCleaner = CfgMgr.Muon__MuonTrackCleaner(name = 'TrigMuGirl_MuidTrackCleaner',
+                                               PullCut     = 3.0,
+                                               PullCutPhi  = 4.0,
+                                               Fitter      = TrigMuGirl_iPatFitter,
+                                               SLFitter    = TrigMuGirl_iPatSLFitter)
+ToolSvc += TrigMuGirl_MuidTrackCleaner
+
+
+
+
+from TrkTrackSummaryTool.TrkTrackSummaryToolConf import Trk__TrackSummaryTool
+MuonTrackSummaryHelperTool    = MuonRecTools.getPublicTool("MuonTrackSummaryHelper")
+#if not hasattr( ToolSvc,' InDetTrackSummaryHelperTool' ):
+
+
+from TrkTrackSummaryTool.TrkTrackSummaryToolConf import Trk__TrackSummaryTool
+from AthenaCommon.DetFlags import DetFlags 
+if not DetFlags.detdescr.ID_on():
+    TrigMuGirl_MuidTrackSummaryTool = Trk__TrackSummaryTool(
+        name = "MuidTrackSummaryTool",
+        MuonSummaryHelperTool  = MuonTrackSummaryHelperTool,
+        doSharedHits           = False)
+else: 
+    from InDetTrigRecExample.InDetTrigConfigRecLoadTools import InDetTrigTrackSummaryHelperTool,  InDetTrigHoleSearchTool
+    TrigMuGirl_MuidTrackSummaryTool = Trk__TrackSummaryTool(
+        name = "MuidTrackSummaryTool",
+        InDetSummaryHelperTool = InDetTrigTrackSummaryHelperTool,
+        InDetHoleSearchTool = InDetTrigHoleSearchTool,
+        MuonSummaryHelperTool  = MuonTrackSummaryHelperTool,
+        doSharedHits           = False)
+ToolSvc += TrigMuGirl_MuidTrackSummaryTool
+
+
+from TrkParticleCreator.TrkParticleCreatorConf import Trk__TrackParticleCreatorTool
+TrigMuGirl_MuidParticleCreatorTool = Trk__TrackParticleCreatorTool(
+     name = "TrigMuGirl_MuidParticleCreatorTool",
+     #Extrapolator     = muidExtrapolator,
+     TrackSummaryTool = TrigMuGirl_MuidTrackSummaryTool)
+ToolSvc += TrigMuGirl_MuidParticleCreatorTool
+
+
+#from MuonIdentificationHelper.MuonIdentificationHelperConf  import Rec__MuonIdentificationHelper
+#TrigMuGirl_MuonIdentificationHelperTool = Rec__MuonIdentificationHelper (
+#     name = "TrigMuGirl_MuonIdentificationHelperTool",
+#     ParticleCreatorTool = TrigMuGirl_MuidParticleCreatorTool )
+#ToolSvc += TrigMuGirl_MuonIdentificationHelperTool
+
+
+class TrigMuGirlConfig (TrigMuGirl):
+    __slots__ = ()
+#
+#    def __init__(self, name = "TrigMuGirl"):
+#        super( TrigMuGirl, self ).__init__( name )
+#    def __new__( cls, *args, **kwargs ):
+#        newargs = ['%s_%s' % (cls.getType(),args[0]) ] + list(args)
+#        return super( TrigMuGirlConfig, cls ).__new__( cls, *newargs, **kwargs )
+#    __slots__ = []
+     
+#    def __new__( cls, *args, **kwargs ):
+#        newargs = ['%s_%s' % (cls.getType(),args[0]) ] + list(args)
+#        return super( TrigMuGirlConfig, cls ).__new__( cls, *newargs, **kwargs )
+    def __new__( cls, *args, **kwargs ):
+        newargs = ['%s_%s' % (cls.getType(),args[0]) ] + list(args)
+        return super( TrigMuGirlConfig, cls ).__new__( cls, *newargs, **kwargs )
+ 
+    def __init__( self, name, *args, **kwargs ):
+        super( TrigMuGirlConfig, self ).__init__( name )
+
+        self.doCSC=trigMuGirlFlags.doCSC()
+
+        from AthenaCommon.AppMgr import ToolSvc
+        from AthenaCommon.AppMgr import ServiceMgr
+
+        TrigMuGirlMuonHoleRecovery = CfgMgr.Muon__MuonChamberHoleRecoveryTool("TrigMuGirlMuonHoleRecovery") 
+        if not trigMuGirlFlags.doCSC(): 
+            TrigMuGirlMuonHoleRecovery.CscRotCreator = None 
+        ToolSvc +=TrigMuGirlMuonHoleRecovery 
+
+
+        from MuidCaloEnergyTools.MuidCaloEnergyToolsConf import Rec__MuidCaloEnergyParam
+        TrigMuGirlCaloEnergyParam = Rec__MuidCaloEnergyParam(name = 'TrigMuGirlCaloEnergyParam')
+        ToolSvc += TrigMuGirlCaloEnergyParam
+
+        from MuidCaloEnergyTools.MuidCaloEnergyToolsConf import Rec__MuidCaloEnergyMeas
+        TrigMuGirlCaloEnergyMeas = Rec__MuidCaloEnergyMeas(name = 'TrigMuGirlCaloEnergyMeas',  CaloParamTool = TrigMuGirlCaloEnergyParam, UseCaloNoiseTool = False,CaloNoiseTool='')
+        ToolSvc += TrigMuGirlCaloEnergyMeas
+
+        from MuidCaloEnergyTools.MuidCaloEnergyToolsConf import Rec__MuidCaloEnergyTool
+        TrigMuGirlCaloEnergyTool = Rec__MuidCaloEnergyTool(name = 'TrigMuGirlCaloEnergyTool', CaloParamTool=TrigMuGirlCaloEnergyParam,CaloMeasTool=TrigMuGirlCaloEnergyMeas, EnergyLossMeasurement = False,MopParametrization    = True)
+        ToolSvc += TrigMuGirlCaloEnergyTool
+
+        from MuidCaloScatteringTools.MuidCaloScatteringToolsConf import Rec__MuidCaloTrackStateOnSurface
+        TrigMuGirlCaloTSOS = Rec__MuidCaloTrackStateOnSurface(name = 'TrigMuGirlCaloTSOS', CaloEnergyDeposit=TrigMuGirlCaloEnergyTool, CaloEnergyParam = TrigMuGirlCaloEnergyTool )
+        ToolSvc += TrigMuGirlCaloTSOS
+
+        from MuidTrackBuilder.MuidTrackBuilderConf import Rec__CombinedMuonTrackBuilder
+        TrigMuGirlTrackBuilder= Rec__CombinedMuonTrackBuilder(name = 'TrigMuGirlTrackBuilder', CaloEnergyParam=TrigMuGirlCaloEnergyTool,CaloTSOS=TrigMuGirlCaloTSOS,ReallocateMaterial=False,Cleaner=TrigMuGirl_MuidTrackCleaner,Fitter=TrigMuGirl_iPatFitter,SLFitter=TrigMuGirl_iPatSLFitter,MuonHoleRecovery=TrigMuGirlMuonHoleRecovery)
+        ToolSvc += TrigMuGirlTrackBuilder
+
+        from CscClusterization.CscClusterizationConf import CscThresholdClusterBuilderTool
+        TrigMuGirlCscClusterBuilder = CscThresholdClusterBuilderTool("TrigMuGirlCscClusterBuilder")
+        TrigMuGirlCscClusterBuilder.threshold = 20000
+        TrigMuGirlCscClusterBuilder.strip_fitter = getPublicTool("CalibCscStripFitter")
+        TrigMuGirlCscClusterBuilder.default_fitter = getPublicTool("SimpleCscClusterFitter")
+        TrigMuGirlCscClusterBuilder.precision_fitter = getPublicTool("QratCscClusterFitter")
+        TrigMuGirlCscClusterBuilder.split_fitter = getPublicTool("CscSplitClusterFitter")
+        ToolSvc += TrigMuGirlCscClusterBuilder
+        #print MuGirlCscClusterBuilder
+
+        from MuGirlCandidate.MuGirlCandidateConfig import MuGirlNS__CandidateToolConfig
+        TrigMuGirlCandidateTool = MuGirlNS__CandidateToolConfig("TrigMuGirlCandidateTool")
+        ToolSvc += TrigMuGirlCandidateTool
+        TrigMuGirlCandidateTool.MuidCaloEnergy= TrigMuGirlCaloEnergyTool
+        TrigMuGirlCandidateTool.CscClusterProviderTool = TrigMuGirlCscClusterBuilder
+        #TrigMuGirlCandidateTool.OutputLevel =2
+        TrigMuGirlCandidateTool.doCSC = self.doCSC 
+        TrigMuGirlCandidateTool.writeChamberT0s = False 
+        self.MuGirlCandidate = TrigMuGirlCandidateTool
+
+        from MuGirlSelection.MuGirlSelectionConf import MuGirlNS__ANNSelectionTool
+        TrigMuGirlSelectionTool = MuGirlNS__ANNSelectionTool("TrigMuGirlSelectionTool")
+        ToolSvc += TrigMuGirlSelectionTool
+        TrigMuGirlSelectionTool.CandidateTool = TrigMuGirlCandidateTool
+        self.ANNSelectionTool = TrigMuGirlSelectionTool
+
+        from MuGirlParticleCreatorTool.MuGirlParticleCreatorToolConf import MuGirlNS__MuGirlParticleCreatorTool
+        TrigMuGirlParticleCreatorTool  = MuGirlNS__MuGirlParticleCreatorTool("TrigMuGirlParticleCreatorTool")
+        ToolSvc += TrigMuGirlParticleCreatorTool
+        TrigMuGirlParticleCreatorTool.MuidCaloEnergyTool= TrigMuGirlCaloEnergyTool
+        TrigMuGirlParticleCreatorTool.doFill= False
+        self.MuGirlParticleCreatorTool = TrigMuGirlParticleCreatorTool
+
+        from MuGirlGlobalFit.MuGirlGlobalFitConf import MuGirlNS__GlobalFitTool
+        TrigMuGirlGlobalFitTool = MuGirlNS__GlobalFitTool("TrigMuGirlGlobalFitTool")
+        ToolSvc += TrigMuGirlGlobalFitTool
+        TrigMuGirlGlobalFitTool.trackFitter= TrigMuGirlTrackBuilder
+        #TrigMuGirlGlobalFitTool.OutputLevel=2
+
+        from MuGirlGlobalFit.MuGirlGlobalFitConf import MuGirlNS__GlobalFitTool
+        TrigMuGirlStauGlobalFitTool = MuGirlNS__GlobalFitTool("TrigMuGirlStauGlobalFitTool")
+        ToolSvc += TrigMuGirlStauGlobalFitTool
+        TrigMuGirlStauGlobalFitTool.trackFitter= TrigMuGirlTrackBuilder
+        #TrigMuGirlStauGlobalFitTool.OutputLevel=2
+
+        from MuGirlGlobalFit.MuGirlGlobalFitConf import MuGirlNS__GlobalFitTool
+        TrigMuGirlSAGlobalFitTool = MuGirlNS__GlobalFitTool("TrigMuGirlSAGlobalFitTool")
+        ToolSvc += TrigMuGirlSAGlobalFitTool
+        TrigMuGirlSAGlobalFitTool.trackFitter= TrigMuGirlTrackBuilder
+        #TrigMuGirlSAGlobalFitTool.OutputLevel=2
+
+        self.MuGirlGlobalFIT = TrigMuGirlGlobalFitTool
+        self.MuGirlGlobalStauFIT = TrigMuGirlStauGlobalFitTool
+        self.MuGirlGlobalMuonFeatureFIT = TrigMuGirlSAGlobalFitTool
+
+
+        from TrigMuGirl.TrigMuGirlMonitoring import TrigMuGirlValidationMonitoring
+        validation = TrigMuGirlValidationMonitoring()
+        from TrigMuGirl.TrigMuGirlMonitoring import TrigMuGirlOnlineMonitoring
+        online = TrigMuGirlOnlineMonitoring()
+
+        from TrigTimeMonitor.TrigTimeHistToolConfig import TrigTimeHistToolConfig
+        time = TrigTimeHistToolConfig("Time")
+        time.TimerHistLimits = [0, 1000]
+        time.NumberOfHistBins = 1000
+        self.AthenaMonTools = [ validation, online, time ]
+
+        #from TrackToCalo.ExtrapolTrackToCaloToolBase import ExtrapolTrackToCaloToolFactory
+        #MuGirlExtrapolTrackToCaloTool = ExtrapolTrackToCaloToolFactory(depth="showerdefault")
+        #ToolSvc += MuGirlExtrapolTrackToCaloTool
+        #self.ExtrapolTrackToCaloTool = MuGirlExtrapolTrackToCaloTool
+
+        
+        from MuGirlStau.MuGirlStauConfig import MuGirlNS__StauToolConfig
+        TrigMuGirlStauTool = MuGirlNS__StauToolConfig("TrigMuGirlStauTool")
+        TrigMuGirlStauTool.StauGlobalFitTool = TrigMuGirlStauGlobalFitTool
+        TrigMuGirlStauTool.particleCreatorTool = TrigMuGirl_MuidParticleCreatorTool
+        ToolSvc += TrigMuGirlStauTool
+        self.MuGirlStauTool = TrigMuGirlStauTool
+
+        if ( args[0] == 'Slow' ):
+             self.doMuonFeature = True
+             self.doSAFit = True
+             self.doStau = True
+#        from MuGirlParticleCreatorTool.MuGirlParticleCreatorToolConf import MuGirlNS__MuGirlParticleCreatorTool
+#        MuGirlParticleCreatorTool = MuGirlNS__MuGirlParticleCreatorTool(name = 'MuGirlParticleCreatorTool')
+##        MuGirlParticleCreatorTool.doNTuple = self.doNTuple
+##        MuGirlParticleCreatorTool.doTruth = self.doTruth
+##        MuGirlParticleCreatorTool.PerformanceTruthTool = MuGirlPerformanceTruthTool
+#        ToolSvc += MuGirlParticleCreatorTool
+#        self.MuGirlParticleCreatorTool = MuGirlParticleCreatorTool
+
+#        self.doGlobalFit=True
+#TrigMuGirl = TrigMuGirlConfig()
+
+class TrigMuGirlToolConfig (TrigMuGirlTool): 
+    __slots__ = ()
+
+    def __init__( self, name="TrigMuGirlTool" ):
+        super( TrigMuGirlToolConfig, self ).__init__( name )
+
+        self.doCSC=trigMuGirlFlags.doCSC()
+
+        from AthenaCommon.AppMgr import ToolSvc
+        from AthenaCommon.AppMgr import ServiceMgr
+
+        TrigMuGirlMuonHoleRecovery = CfgMgr.Muon__MuonChamberHoleRecoveryTool("TrigMuGirlMuonHoleRecovery")
+        if not trigMuGirlFlags.doCSC(): 
+            TrigMuGirlMuonHoleRecovery.CscRotCreator = None
+        ToolSvc +=TrigMuGirlMuonHoleRecovery
+
+
+        from MuidCaloEnergyTools.MuidCaloEnergyToolsConf import Rec__MuidCaloEnergyParam
+        TrigMuGirlCaloEnergyParam = Rec__MuidCaloEnergyParam(name = 'TrigMuGirlCaloEnergyParam')
+        ToolSvc += TrigMuGirlCaloEnergyParam
+
+        from MuidCaloEnergyTools.MuidCaloEnergyToolsConf import Rec__MuidCaloEnergyMeas
+        TrigMuGirlCaloEnergyMeas = Rec__MuidCaloEnergyMeas(name = 'TrigMuGirlCaloEnergyMeas',  CaloParamTool = TrigMuGirlCaloEnergyParam, UseCaloNoiseTool = False,CaloNoiseTool='')
+        ToolSvc += TrigMuGirlCaloEnergyMeas
+
+        from MuidCaloEnergyTools.MuidCaloEnergyToolsConf import Rec__MuidCaloEnergyTool
+        TrigMuGirlCaloEnergyTool = Rec__MuidCaloEnergyTool(name = 'TrigMuGirlCaloEnergyTool', CaloParamTool=TrigMuGirlCaloEnergyParam,CaloMeasTool=TrigMuGirlCaloEnergyMeas, EnergyLossMeasurement = False,MopParametrization    = True)
+        ToolSvc += TrigMuGirlCaloEnergyTool
+
+        from MuidCaloScatteringTools.MuidCaloScatteringToolsConf import Rec__MuidCaloTrackStateOnSurface
+        TrigMuGirlCaloTSOS = Rec__MuidCaloTrackStateOnSurface(name = 'TrigMuGirlCaloTSOS', CaloEnergyDeposit=TrigMuGirlCaloEnergyTool, CaloEnergyParam = TrigMuGirlCaloEnergyTool )
+        ToolSvc += TrigMuGirlCaloTSOS
+
+        from MuidTrackBuilder.MuidTrackBuilderConf import Rec__CombinedMuonTrackBuilder
+        TrigMuGirlTrackBuilder= Rec__CombinedMuonTrackBuilder(name = 'TrigMuGirlTrackBuilder', CaloEnergyParam=TrigMuGirlCaloEnergyTool,CaloTSOS=TrigMuGirlCaloTSOS,ReallocateMaterial=False,Cleaner=TrigMuGirl_MuidTrackCleaner,Fitter=TrigMuGirl_iPatFitter,SLFitter=TrigMuGirl_iPatSLFitter,MuonHoleRecovery=TrigMuGirlMuonHoleRecovery)
+        ToolSvc += TrigMuGirlTrackBuilder
+
+        from CscClusterization.CscClusterizationConf import CscThresholdClusterBuilderTool
+        TrigMuGirlCscClusterBuilder = CscThresholdClusterBuilderTool("TrigMuGirlCscClusterBuilder")
+        TrigMuGirlCscClusterBuilder.threshold = 20000
+        TrigMuGirlCscClusterBuilder.strip_fitter = getPublicTool("CalibCscStripFitter")
+        TrigMuGirlCscClusterBuilder.default_fitter = getPublicTool("SimpleCscClusterFitter")
+        TrigMuGirlCscClusterBuilder.precision_fitter = getPublicTool("QratCscClusterFitter")
+        TrigMuGirlCscClusterBuilder.split_fitter = getPublicTool("CscSplitClusterFitter")
+        ToolSvc += TrigMuGirlCscClusterBuilder
+        #print MuGirlCscClusterBuilder
+
+        from MuGirlCandidate.MuGirlCandidateConfig import MuGirlNS__CandidateToolConfig
+        TrigMuGirlCandidateTool = MuGirlNS__CandidateToolConfig("TrigMuGirlCandidateTool")
+        ToolSvc += TrigMuGirlCandidateTool
+        TrigMuGirlCandidateTool.MuidCaloEnergy= TrigMuGirlCaloEnergyTool
+        TrigMuGirlCandidateTool.CscClusterProviderTool = TrigMuGirlCscClusterBuilder
+        #TrigMuGirlCandidateTool.OutputLevel =2
+        TrigMuGirlCandidateTool.doCSC = self.doCSC
+        TrigMuGirlCandidateTool.writeChamberT0s = False
+        self.MuGirlCandidate = TrigMuGirlCandidateTool
+
+        from MuGirlSelection.MuGirlSelectionConf import MuGirlNS__ANNSelectionTool
+        TrigMuGirlSelectionTool = MuGirlNS__ANNSelectionTool("TrigMuGirlSelectionTool")
+        ToolSvc += TrigMuGirlSelectionTool
+        TrigMuGirlSelectionTool.CandidateTool = TrigMuGirlCandidateTool
+        self.ANNSelectionTool = TrigMuGirlSelectionTool
+
+        from MuGirlParticleCreatorTool.MuGirlParticleCreatorToolConf import MuGirlNS__MuGirlParticleCreatorTool
+        TrigMuGirlParticleCreatorTool  = MuGirlNS__MuGirlParticleCreatorTool("TrigMuGirlParticleCreatorTool")
+        ToolSvc += TrigMuGirlParticleCreatorTool
+        TrigMuGirlParticleCreatorTool.MuidCaloEnergyTool= TrigMuGirlCaloEnergyTool
+        TrigMuGirlParticleCreatorTool.doFill= False
+        #TrigMuGirlParticleCreatorTool.MuonIdentificationHelper= TrigMuGirl_MuonIdentificationHelperTool
+        self.MuGirlParticleCreatorTool = TrigMuGirlParticleCreatorTool
+
+        from MuGirlGlobalFit.MuGirlGlobalFitConf import MuGirlNS__GlobalFitTool
+        TrigMuGirlGlobalFitTool = MuGirlNS__GlobalFitTool("TrigMuGirlGlobalFitTool")
+        ToolSvc += TrigMuGirlGlobalFitTool
+        TrigMuGirlGlobalFitTool.trackFitter= TrigMuGirlTrackBuilder
+        #TrigMuGirlGlobalFitTool.OutputLevel=2
+
+        from MuGirlGlobalFit.MuGirlGlobalFitConf import MuGirlNS__GlobalFitTool
+        TrigMuGirlStauGlobalFitTool = MuGirlNS__GlobalFitTool("TrigMuGirlStauGlobalFitTool")
+        ToolSvc += TrigMuGirlStauGlobalFitTool
+        TrigMuGirlStauGlobalFitTool.trackFitter= TrigMuGirlTrackBuilder
+        #TrigMuGirlStauGlobalFitTool.OutputLevel=2
+
+        from MuGirlGlobalFit.MuGirlGlobalFitConf import MuGirlNS__GlobalFitTool
+        TrigMuGirlSAGlobalFitTool = MuGirlNS__GlobalFitTool("TrigMuGirlSAGlobalFitTool")
+        ToolSvc += TrigMuGirlSAGlobalFitTool
+        TrigMuGirlSAGlobalFitTool.trackFitter= TrigMuGirlTrackBuilder
+        #TrigMuGirlSAGlobalFitTool.OutputLevel=2
+
+        self.MuGirlGlobalFIT = TrigMuGirlGlobalFitTool
+        self.MuGirlGlobalStauFIT = TrigMuGirlStauGlobalFitTool
+        self.MuGirlGlobalMuonFeatureFIT = TrigMuGirlSAGlobalFitTool
+
+        #from TrackToCalo.ExtrapolTrackToCaloToolBase import ExtrapolTrackToCaloToolFactory
+        #MuGirlExtrapolTrackToCaloTool = ExtrapolTrackToCaloToolFactory(depth="showerdefault")
+        #ToolSvc += MuGirlExtrapolTrackToCaloTool
+        #self.ExtrapolTrackToCaloTool = MuGirlExtrapolTrackToCaloTool
+
+
+        from MuGirlStau.MuGirlStauConfig import MuGirlNS__StauToolConfig
+        TrigMuGirlStauTool = MuGirlNS__StauToolConfig("TrigMuGirlStauTool")
+        TrigMuGirlStauTool.StauGlobalFitTool = TrigMuGirlStauGlobalFitTool
+        TrigMuGirlStauTool.particleCreatorTool = TrigMuGirl_MuidParticleCreatorTool
+        ToolSvc += TrigMuGirlStauTool
+        self.MuGirlStauTool = TrigMuGirlStauTool
+
diff --git a/Trigger/TrigAlgorithms/TrigMuGirl/python/TrigMuGirlConfigDb.py b/Trigger/TrigAlgorithms/TrigMuGirl/python/TrigMuGirlConfigDb.py
new file mode 100644
index 00000000000..d1dd35123e1
--- /dev/null
+++ b/Trigger/TrigAlgorithms/TrigMuGirl/python/TrigMuGirlConfigDb.py
@@ -0,0 +1,7 @@
+# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+
+from AthenaCommon.CfgGetter import addAlgorithm,addTool,addService
+
+addTool("TrigMuGirl.TrigMuGirlConfig.TrigMuGirlToolConfig", "TrigMuGirlTool")
+
+addAlgorithm("TrigMuGirl.TrigMuGirlConfig.TrigMuGirlConfig", "TrigMuGirl")
diff --git a/Trigger/TrigAlgorithms/TrigMuGirl/python/TrigMuGirlFlags.py b/Trigger/TrigAlgorithms/TrigMuGirl/python/TrigMuGirlFlags.py
new file mode 100644
index 00000000000..f22deec33f3
--- /dev/null
+++ b/Trigger/TrigAlgorithms/TrigMuGirl/python/TrigMuGirlFlags.py
@@ -0,0 +1,23 @@
+# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+
+from AthenaCommon.JobProperties import JobProperty, JobPropertyContainer
+from AthenaCommon.JobProperties import jobproperties
+
+class doCSC(JobProperty):
+    """ 
+    """
+    statusOn = True
+    allowedTypes = ['bool']
+    StoredValue = False
+
+
+class TrigMuGirlFlags(JobPropertyContainer):
+    """ TrigMuGirl Job Properties
+    """
+    pass
+
+jobproperties.add_Container(TrigMuGirlFlags)
+jobproperties.TrigMuGirlFlags.add_JobProperty(doCSC)
+
+trigMuGirlFlags = jobproperties.TrigMuGirlFlags
+trigMuGirlFlags.print_JobProperties('tree&value')
diff --git a/Trigger/TrigAlgorithms/TrigMuGirl/python/TrigMuGirlMonitoring.py b/Trigger/TrigAlgorithms/TrigMuGirl/python/TrigMuGirlMonitoring.py
new file mode 100644
index 00000000000..d1812a9ab45
--- /dev/null
+++ b/Trigger/TrigAlgorithms/TrigMuGirl/python/TrigMuGirlMonitoring.py
@@ -0,0 +1,108 @@
+# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+
+from TrigMonitorBase.TrigGenericMonitoringToolConfig import defineHistogram, TrigGenericMonitoringToolConfig 
+
+class TrigMuGirlValidationMonitoring(TrigGenericMonitoringToolConfig):
+    def __init__ (self, name="TrigMuGirlValidationMonitoring"):
+        super(TrigMuGirlValidationMonitoring, self).__init__(name)
+        self.defineTarget("Validation")
+        self.Histograms = [ defineHistogram('MuonsPt', type='TH1F', title="TrigMuGirl muons pT", xbins=1000, xmin=0, xmax=200000) ]
+        self.Histograms += [ defineHistogram('MuonsCotTh', type='TH1F', title="TrigMuGirl Muons CotTh", xbins=100, xmin=-10, xmax=10) ]
+        self.Histograms += [ defineHistogram('MuonsPhi', type='TH1F', title="TrigMuGirl Muons phi", xbins=100, xmin=-4, xmax=4) ]
+        self.Histograms += [ defineHistogram('MuonsMdtHits', type='TH1F', title="TrigMuGirl Muons MDT Hits", xbins=100, xmin=0, xmax=50) ]
+        self.Histograms += [ defineHistogram('MuonsRpcPhiHits', type='TH1F', title="TrigMuGirl Muons RPC Phi Hits", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('MuonsRpcEtaHits', type='TH1F', title="TrigMuGirl Muons RPC Eta Hits", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('MuonsTgcPhiHits', type='TH1F', title="TrigMuGirl Muons TGC Phi Hits", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('MuonsTgcEtaHits', type='TH1F', title="TrigMuGirl Muons TGC Eta Hits", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('MuonsCscPhiHits', type='TH1F', title="TrigMuGirl Muons CSC Phi Hits", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('MuonsCscEtaHits', type='TH1F', title="TrigMuGirl Muons CSC Eta Hits", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('MuonsTgcRpcPhiHits', type='TH1F', title="TrigMuGirl Muons TGC RPC Phi Hits", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('MuonsTgcRpcEtaHits', type='TH1F', title="TrigMuGirl Muons TGC RPC Eta Hits", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('MuonsMdtHitsInSeg', type='TH1F', title="TrigMuGirl Muons MDT Hits in Segments", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('MuonsRpcHitsInSeg', type='TH1F', title="TrigMuGirl Muons RPC Hits in Segments", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('MuonsTgcHitsInSeg', type='TH1F', title="TrigMuGirl Muons TGC Hits in Segments", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('MuonsTgcRpcHitsInSeg', type='TH1F', title="TrigMuGirl Muons TGC RPC Hits in Segments", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('MuonsMdtSegs', type='TH1F', title="TrigMuGirl Muons MDT Segments", xbins=10, xmin=0, xmax=10) ]
+        self.Histograms += [ defineHistogram('MuonsRpcSegs', type='TH1F', title="TrigMuGirl Muons RPC Segments", xbins=10, xmin=0, xmax=10) ]
+        self.Histograms += [ defineHistogram('MuonsCscSegs', type='TH1F', title="TrigMuGirl Muons CSC Segments", xbins=10, xmin=0, xmax=10) ]
+        self.Histograms += [ defineHistogram('MuonsTgcSegs', type='TH1F', title="TrigMuGirl Muons TGC Segments", xbins=10, xmin=0, xmax=10) ]
+        self.Histograms += [ defineHistogram('MuonsTgcRpcSegs', type='TH1F', title="TrigMuGirl Muons TGC RPC Segments", xbins=10, xmin=0, xmax=10) ]
+        self.Histograms += [ defineHistogram('MuonsBeta', type='TH1F', title="TrigMuGirl Muons beta", xbins=120, xmin=0, xmax=1.2) ]
+        self.Histograms += [ defineHistogram('MuonsNNBarrel', type='TH1F', title="TrigMuGirl Muons barrel NN", xbins=120, xmin=0, xmax=1.2) ]
+        self.Histograms += [ defineHistogram('MuonsNNEndcap', type='TH1F', title="TrigMuGirl Muons endcap NN", xbins=120, xmin=0, xmax=1.2) ]
+        self.Histograms += [ defineHistogram('MuonsRPCHitsMeasTime', type='TH1F', title="TrigMuGirl Muons RPC Hits Meas time", xbins=200, xmin=0, xmax=100) ]
+        self.Histograms += [ defineHistogram('MuonsRPCHitsPropTime', type='TH1F', title="TrigMuGirl Muons RPC Hits Prop time", xbins=200, xmin=0, xmax=100) ]
+        self.Histograms += [ defineHistogram('MuonsRPCHitsTof', type='TH1F', title="TrigMuGirl Muons RPC Hits TOF", xbins=200, xmin=0, xmax=100) ]
+        self.Histograms += [ defineHistogram('MuonsRPCHitsDist', type='TH1F', title="TrigMuGirl Muons RPC Hits Distance", xbins=100, xmin=0, xmax=50) ]
+
+
+class TrigMuGirlOnlineMonitoring(TrigGenericMonitoringToolConfig):
+    def __init__ (self, name="TrigMuGirlOnlineMonitoring"):
+        super(TrigMuGirlOnlineMonitoring, self).__init__(name)
+        self.defineTarget("Online")
+        self.Histograms = [ defineHistogram('MuonsPt', type='TH1F', title="TrigMuGirl muons pT", xbins=1000, xmin=0, xmax=200000) ]
+        self.Histograms += [ defineHistogram('MuonsCotTh', type='TH1F', title="TrigMuGirl Muons CotTh", xbins=100, xmin=-10, xmax=10) ]
+        self.Histograms += [ defineHistogram('MuonsPhi', type='TH1F', title="TrigMuGirl Muons phi", xbins=100, xmin=-4, xmax=4) ]
+        self.Histograms += [ defineHistogram('MuonsMdtHits', type='TH1F', title="TrigMuGirl Muons MDT Hits", xbins=100, xmin=0, xmax=50) ]
+        self.Histograms += [ defineHistogram('MuonsRpcPhiHits', type='TH1F', title="TrigMuGirl Muons RPC Phi Hits", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('MuonsRpcEtaHits', type='TH1F', title="TrigMuGirl Muons RPC Eta Hits", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('MuonsTgcPhiHits', type='TH1F', title="TrigMuGirl Muons TGC Phi Hits", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('MuonsTgcEtaHits', type='TH1F', title="TrigMuGirl Muons TGC Eta Hits", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('MuonsCscPhiHits', type='TH1F', title="TrigMuGirl Muons CSC Phi Hits", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('MuonsCscEtaHits', type='TH1F', title="TrigMuGirl Muons CSC Eta Hits", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('MuonsTgcRpcPhiHits', type='TH1F', title="TrigMuGirl Muons TGC RPC Phi Hits", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('MuonsTgcRpcEtaHits', type='TH1F', title="TrigMuGirl Muons TGC RPC Eta Hits", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('MuonsMdtHitsInSeg', type='TH1F', title="TrigMuGirl Muons MDT Hits in Segments", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('MuonsRpcHitsInSeg', type='TH1F', title="TrigMuGirl Muons RPC Hits in Segments", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('MuonsTgcHitsInSeg', type='TH1F', title="TrigMuGirl Muons TGC Hits in Segments", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('MuonsTgcRpcHitsInSeg', type='TH1F', title="TrigMuGirl Muons TGC RPC Hits in Segments", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('MuonsMdtSegs', type='TH1F', title="TrigMuGirl Muons MDT Segments", xbins=10, xmin=0, xmax=10) ]
+        self.Histograms += [ defineHistogram('MuonsRpcSegs', type='TH1F', title="TrigMuGirl Muons RPC Segments", xbins=10, xmin=0, xmax=10) ]
+        self.Histograms += [ defineHistogram('MuonsCscSegs', type='TH1F', title="TrigMuGirl Muons CSC Segments", xbins=10, xmin=0, xmax=10) ]
+        self.Histograms += [ defineHistogram('MuonsTgcSegs', type='TH1F', title="TrigMuGirl Muons TGC Segments", xbins=10, xmin=0, xmax=10) ]
+        self.Histograms += [ defineHistogram('MuonsTgcRpcSegs', type='TH1F', title="TrigMuGirl Muons TGC RPC Segments", xbins=10, xmin=0, xmax=10) ]
+        self.Histograms += [ defineHistogram('MuonsBeta', type='TH1F', title="TrigMuGirl Muons beta", xbins=120, xmin=0, xmax=1.2) ]
+        self.Histograms += [ defineHistogram('MuonsNNBarrel', type='TH1F', title="TrigMuGirl Muons barrel NN", xbins=120, xmin=0, xmax=1.2) ]
+        self.Histograms += [ defineHistogram('MuonsNNEndcap', type='TH1F', title="TrigMuGirl Muons endcap NN", xbins=120, xmin=0, xmax=1.2) ]
+        self.Histograms += [ defineHistogram('MuonsRPCHitsMeasTime', type='TH1F', title="TrigMuGirl Muons RPC Hits Meas time", xbins=200, xmin=0, xmax=100) ]
+        self.Histograms += [ defineHistogram('MuonsRPCHitsPropTime', type='TH1F', title="TrigMuGirl Muons RPC Hits Prop time", xbins=200, xmin=0, xmax=100) ]
+        self.Histograms += [ defineHistogram('MuonsRPCHitsTof', type='TH1F', title="TrigMuGirl Muons RPC Hits TOF", xbins=200, xmin=0, xmax=100) ]
+        self.Histograms += [ defineHistogram('MuonsRPCHitsDist', type='TH1F', title="TrigMuGirl Muons RPC Hits Distance", xbins=100, xmin=0, xmax=50) ]
+
+class TrigMuGirlToolMonitoring(TrigGenericMonitoringToolConfig):
+    def __init__ (self, name="TrigMuGirlToolMonitoring"):
+        super(TrigMuGirlToolMonitoring, self).__init__(name)
+        self.defineTarget( ["Online", "Validation"] )
+
+        # TrigMuGirl
+        self.Histograms += [ defineHistogram('EF_mgtrks_pt', type='TH1F', title="TrigMuGirl muons pT", xbins=1000, xmin=0, xmax=200000) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_cotTh', type='TH1F', title="TrigMuGirl Muons CotTh", xbins=100, xmin=-10, xmax=10) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_phi', type='TH1F', title="TrigMuGirl Muons phi", xbins=100, xmin=-4, xmax=4) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_mdtHits', type='TH1F', title="TrigMuGirl Muons MDT Hits", xbins=100, xmin=0, xmax=50) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_rpcPhiHits', type='TH1F', title="TrigMuGirl Muons RPC Phi Hits", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_rpcEtaHits', type='TH1F', title="TrigMuGirl Muons RPC Eta Hits", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_tgcPhiHits', type='TH1F', title="TrigMuGirl Muons TGC Phi Hits", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_tgcEtaHits', type='TH1F', title="TrigMuGirl Muons TGC Eta Hits", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_cscPhiHits', type='TH1F', title="TrigMuGirl Muons CSC Phi Hits", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_cscEtaHits', type='TH1F', title="TrigMuGirl Muons CSC Eta Hits", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_tgcRpcPhiHits', type='TH1F', title="TrigMuGirl Muons TGC RPC Phi Hits", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_tgcRpcEtaHits', type='TH1F', title="TrigMuGirl Muons TGC RPC Eta Hits", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_mdtHitsInSeg', type='TH1F', title="TrigMuGirl Muons MDT Hits in Segments", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_rpcHitsInSeg', type='TH1F', title="TrigMuGirl Muons RPC Hits in Segments", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_tgcHitsInSeg', type='TH1F', title="TrigMuGirl Muons TGC Hits in Segments", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_tgcRpcHitsInSeg', type='TH1F', title="TrigMuGirl Muons TGC RPC Hits in Segments", xbins=30, xmin=0, xmax=30) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_mdtSegs', type='TH1F', title="TrigMuGirl Muons MDT Segments", xbins=10, xmin=0, xmax=10) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_rpcSegs', type='TH1F', title="TrigMuGirl Muons RPC Segments", xbins=10, xmin=0, xmax=10) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_cscSegs', type='TH1F', title="TrigMuGirl Muons CSC Segments", xbins=10, xmin=0, xmax=10) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_tgcSegs', type='TH1F', title="TrigMuGirl Muons TGC Segments", xbins=10, xmin=0, xmax=10) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_tgcRpcSegs', type='TH1F', title="TrigMuGirl Muons TGC RPC Segments", xbins=10, xmin=0, xmax=10) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_beta', type='TH1F', title="TrigMuGirl Muons beta", xbins=120, xmin=0, xmax=1.2) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_nnBarrel', type='TH1F', title="TrigMuGirl Muons barrel NN", xbins=120, xmin=0, xmax=1.2) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_nnEndcap', type='TH1F', title="TrigMuGirl Muons endcap NN", xbins=120, xmin=0, xmax=1.2) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_rpcHitsMeasTime', type='TH1F', title="TrigMuGirl Muons RPC Hits Meas time", xbins=200, xmin=0, xmax=100) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_rpcHitsPropTime', type='TH1F', title="TrigMuGirl Muons RPC Hits Prop time", xbins=200, xmin=0, xmax=100) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_rpcHitsTof', type='TH1F', title="TrigMuGirl Muons RPC Hits TOF", xbins=200, xmin=0, xmax=100) ]
+        self.Histograms += [ defineHistogram('EF_mgtrks_rpcHitsDist', type='TH1F', title="TrigMuGirl Muons RPC Hits Distance", xbins=100, xmin=0, xmax=50) ]
+
+
+
diff --git a/Trigger/TrigAlgorithms/TrigMuGirl/python/TrigPostFexConfig.py b/Trigger/TrigAlgorithms/TrigMuGirl/python/TrigPostFexConfig.py
new file mode 100644
index 00000000000..1032c77d5d6
--- /dev/null
+++ b/Trigger/TrigAlgorithms/TrigMuGirl/python/TrigPostFexConfig.py
@@ -0,0 +1,31 @@
+# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+
+from TrigMuGirl.TrigMuGirlConf import TrigPostFex
+from AthenaCommon.GlobalFlags import globalflags
+from AthenaCommon.AppMgr import ServiceMgr
+
+#from AthenaCommon.SystemOfUnits import GeV
+
+class TrigPostFexConfig (TrigPostFex):
+    __slots__ = []
+
+# the ver to use with no input
+#    def __init__(self, name = "TrigPostFexConfig"):
+#        super( TrigPostFex, self ).__init__( name )
+
+    def __new__( cls, *args, **kwargs ):
+        newargs = ['%s_%s' % (cls.getType(),args[0]) ] + list(args)
+        return super( TrigPostFexConfig, cls ).__new__( cls, *newargs, **kwargs )
+     
+    def __init__( self, name, *args, **kwargs ):
+        super( TrigPostFexConfig, self ).__init__( name )
+
+#        from TrigMuGirl.TrigPostFexMonitoring import TrigPostFexValidationMonitoring
+#        validation = TrigPostFexValidationMonitoring()
+#        from TrigMuGirl.TrigPostFexMonitoring import TrigPostFexOnlineMonitoring
+#        online = TrigPostFexOnlineMonitoring()
+        from TrigTimeMonitor.TrigTimeHistToolConfig import TrigTimeHistToolConfig
+        time = TrigTimeHistToolConfig("Time")
+#        self.AthenaMonTools = [ validation, online, time ]
+        self.AthenaMonTools = [ time ]
+
diff --git a/Trigger/TrigAlgorithms/TrigMuGirl/src/TrigMuGirl.cxx b/Trigger/TrigAlgorithms/TrigMuGirl/src/TrigMuGirl.cxx
new file mode 100644
index 00000000000..ea8644200f3
--- /dev/null
+++ b/Trigger/TrigAlgorithms/TrigMuGirl/src/TrigMuGirl.cxx
@@ -0,0 +1,1789 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+/***************************************************************************
+    Authors: E. Reinherz-Aronis, A. Kreisel 
+             based on MuGirl by Shlomit Tarem
+***************************************************************************/
+#include "TrigInterfaces/AlgoConfig.h"
+#include "TrigNavigation/TriggerElement.h"
+#include "TrigNavigation/Navigation.h"
+#include "TrigSteeringEvent/TrigRoiDescriptor.h"
+
+#include <iostream>
+#include<iomanip>
+
+#include "CLHEP/Units/SystemOfUnits.h"
+#include "CLHEP/Vector/LorentzVector.h"
+#include "GaudiKernel/NTuple.h"
+
+#include "TrigMuGirl/TrigMuGirl.h"
+#include "MuGirlInterfaces/ICandidateTool.h"
+#include "MuGirlInterfaces/CandidateSummary.h"
+#include "MuGirlInterfaces/IPerformanceTruthTool.h"
+#include "MuGirlInterfaces/IGlobalFitTool.h"
+#include "MuGirlInterfaces/IANNSelectionTool.h"
+#include "MuGirlInterfaces/IMuGirlParticleCreatorTool.h"
+#include "MuGirlInterfaces/IStauTool.h"
+#include "MuGirlInterfaces/SegmentManager.h"
+#include "MuGirlInterfaces/RpcSegmentInfo.h"
+
+//#include "MuGirlEvent/MuGirlObject.h"
+//#include "MuGirlEvent/MuGirlObjectCollection.h"
+#include "StoreGate/StoreGateSvc.h"
+#include "MuonReadoutGeometry/MuonDetectorManager.h"
+#include "RegionSelector/IRegSelSvc.h"
+
+#include "MuonRecToolInterfaces/IMuonClusterOnTrackCreator.h"
+#include "MuonRecToolInterfaces/IMdtDriftCircleOnTrackCreator.h"
+
+#include "TrkTrack/TrackCollection.h"
+#include "MuonRecToolInterfaces/IMuonSegmentMaker.h"
+#include "TrkExInterfaces/IIntersector.h"
+#include "TrkExUtils/TrackSurfaceIntersection.h"
+
+#include "EventInfo/EventInfo.h"
+#include "EventInfo/EventID.h"
+
+#include "RecoToolInterfaces/IExtrapolateToCaloTool.h"
+#include "ICaloTrkMuIdTools/ICaloMuonLikelihoodTool.h"
+#include "CaloEvent/CaloClusterContainer.h"
+
+#include "Particle/TrackParticleContainer.h"
+
+
+//<S>
+#include "MuGirlInterfaces/MdtSegmentMakerInfo.h"
+
+#include "TrigMuonEvent/MuonFeature.h"
+#include "TrigMuonEvent/CombinedMuonFeature.h"
+#include "TrigMuonEvent/CombinedMuonFeatureContainer.h"
+#include "TrigMuonEvent/TrigMuonEFInfoContainer.h"
+#include "TrigMuonEvent/TrigMuonEFInfo.h"
+
+//for TEcreateParticle
+//#include "TrkEventPrimitives/FitQuality.h"
+//#include "TrkSurfaces/PerigeeSurface.h"
+//#include "TrkTrack/TrackStateOnSurface.h"
+
+// for performance 
+#include "TrigMuGirl/TrigMuGirlNtuple.h"
+#include "GeneratorObjects/McEventCollection.h"
+#include "MagFieldInterfaces/IMagFieldSvc.h"
+
+using HepGeom::Point3D;
+using CLHEP::Hep3Vector;
+using CLHEP::GeV;
+
+TrigMuGirl::TrigMuGirl(const std::string& name, ISvcLocator* pSvcLocator) :
+  HLT::FexAlgo(name, pSvcLocator),
+        m_ptLowerLimit(2.5*GeV),
+        m_ntupleName("/NTUPLES/MUGIRL/MUGIRL"),
+        m_ntupleTitle("Muon Candidates"),
+        m_roadDeltaPhi(0.2),
+        m_doNTuple(false),
+        m_doLHR(false),
+        m_doCSC(false),
+        m_barrelNNCut(0.4),
+        m_endcapNNCut(0.4),
+        m_sSegmentCollection("MuGirlSegments"),
+        m_sRefittedTrkCollection("MuGirlRefittedTracks"),
+        m_RefittedTrkLocation("MuGirlRefittedTrackParticles"),
+        m_inDetParticlesLocation("TrackParticleCandidate"),
+        m_CaloCollection("CaloTopoCluster"),
+        m_doStau(false),
+        m_stauPtCut(20000.0),
+        m_mfPtCut(20000.0),
+        //m_pMuonMgr(NULL),
+        m_pSegmentCollection(NULL),
+        m_pRefittedTrkContainer(NULL),
+        m_applyLHR("On"),
+        m_idR(0.3),
+        m_lhr(0.8),
+        m_eOverP(0.3),
+        m_doTruth(false),
+        m_doGlobalFit(true),
+        m_doSAFit(false),
+        m_doMuonFeature(false),
+        m_doANNSelection(true),
+        m_doParticleCreator(false),
+        m_pClusCollection(NULL),
+        m_pCandNTuple(NULL),
+        // Tool names
+        m_pEventStore("StoreGateSvc", name),
+        m_pCandidate("MuGirlNS::CandidateTool"),
+  //        m_pToCalo("None"),
+        m_pToCalo("ExtrapolateToCaloTool/ExtrapolateToCaloTool"),
+        m_pMuLHR("CaloMuonLikelihoodTool"),
+        m_pTruthTool("MuGirlNS::PerformanceTruthTool",0),                 // make this a public tool
+  //        m_particleCreatorTool("Trk::TrackParticleCreatorTool"),
+        //m_runOutlier(false),
+        //m_matEffects(Trk::muon),
+        m_pGlobalFitTool("MuGirlNS::GlobalFitTool",0),                    // make this a public tool
+        m_pMuonFeatureGlobalFitTool("MuGirlNS::GlobalFitTool",0),         // make this a public tool
+        m_pANNSelectionTool("MuGirlNS::ANNSelectionTool",0),              // make this a public tool
+        m_pParticleCreatorTool("MuGirlNS::MuGirlParticleCreatorTool",0),  // make this a public tool
+        //m_intersector("Trk::RungeKuttaIntersector")
+        //<S>
+        m_pStauTool("MuGirlNS::StauTool",0),                              // make this a public tool
+        m_magFieldSvc("MagField::AtlasFieldSvc/AtlasFieldSvc",name),
+        m_pSegmentManager(NULL),
+  // for perform
+        m_pTrigMuGirlNtuple(NULL),
+        m_ntupleNamePerformance("/NTUPLES/TRIGMUGIRL/TRIGMUGIRL"),
+        m_ntupleTitlePerformance("TrigMuGirlPer"),
+        m_doNTuplePerformance(false),
+        m_roi(0)
+ 
+{
+
+    // configure property values
+    declareProperty("PtLowerLimit",                 m_ptLowerLimit);
+    declareProperty("NtupleName",                   m_ntupleName);
+    declareProperty("NtupleTitle",                  m_ntupleTitle);
+    declareProperty("RoadDeltaPhi",                 m_roadDeltaPhi);
+    declareProperty("doNTuple",                     m_doNTuple);
+    declareProperty("doLHR",                        m_doLHR);
+    declareProperty("doCSC",                        m_doCSC);
+    declareProperty("BarrelNNCut",                  m_barrelNNCut);
+    declareProperty("EndcapNNCut",                  m_endcapNNCut);
+    declareProperty("SegmentCollection",            m_sSegmentCollection);
+    declareProperty("RefittedTrkCollection",        m_sRefittedTrkCollection);
+    declareProperty("RefittedTrkLocation",          m_RefittedTrkLocation);
+    declareProperty("InDetTrackParticlesLocation",  m_inDetParticlesLocation);
+    declareProperty("doStau",                       m_doStau);
+    declareProperty("StauPtCut",                    m_stauPtCut);
+    declareProperty("MFPtCut",                    m_mfPtCut);
+    declareProperty("IdConeR",                      m_idR);
+    declareProperty("LHRValue",                     m_lhr);
+    declareProperty("eCaloOverPCut",                m_eOverP);
+    declareProperty("InCaloCollection",             m_CaloCollection);
+    declareProperty("doTruth",                      m_doTruth);
+    declareProperty("doGlobalFit",                  m_doGlobalFit);
+    declareProperty("doSAFit",                      m_doSAFit);
+    declareProperty("doMuonFeature",                m_doMuonFeature);
+    declareProperty("doANNSelection",               m_doANNSelection);
+    declareProperty("doParticleCreator",            m_doParticleCreator);
+    // Tools
+    // in the old ver there was no
+    declareProperty("StoreGateSvc",                 m_pEventStore);
+    declareProperty("MuGirlCandidate",              m_pCandidate);
+    declareProperty("MuGirlGlobalFIT",              m_pGlobalFitTool);
+    declareProperty("MuGirlGlobalStauFIT",          m_pStauGlobalFitTool);
+    declareProperty("MuGirlGlobalMuonFeatureFIT",   m_pMuonFeatureGlobalFitTool);
+    declareProperty("ExtrapolTrackToCaloTool",      m_pToCalo);
+    declareProperty("CaloMuonLikelihoodTool",       m_pMuLHR);
+    //    declareProperty("TrackParticleCreatorTool", m_particleCreatorTool);
+    //<S>
+    declareProperty("MuGirlStauTool",               m_pStauTool);
+    declareProperty("PerformanceTruthTool",         m_pTruthTool);
+    declareProperty("ANNSelectionTool",             m_pANNSelectionTool);
+    declareProperty("MuGirlParticleCreatorTool",             m_pParticleCreatorTool);
+    // varibles for monitor
+    //    declareMonitoredStdContainer ("MuonsPt", pt);
+    //    declareMonitoredStdContainer ("MuonsCosTh", cotTh);
+    //    declareMonitoredStdContainer ("MuonsPhi", phi);
+
+    declareMonitoredStdContainer ("MuonsPt", muon_pT);
+    declareMonitoredStdContainer ("MuonsCotTh", muon_cotTh);
+    declareMonitoredStdContainer ("MuonsPhi", muon_phi);
+    declareMonitoredStdContainer ("MuonsMdtHits", muon_nMDThits);
+    declareMonitoredStdContainer ("MuonsRpcPhiHits", muon_nRPCPhihits);
+    declareMonitoredStdContainer ("MuonsRpcEtaHits", muon_nRPCEtahits);
+    declareMonitoredStdContainer ("MuonsCscPhiHits", muon_nCSCPhihits);
+    declareMonitoredStdContainer ("MuonsCscEtaHits", muon_nCSCEtahits);
+    declareMonitoredStdContainer ("MuonsTgcPhiHits", muon_nTGCPhihits);
+    declareMonitoredStdContainer ("MuonsTgcEtaHits", muon_nTGCEtahits);
+    declareMonitoredStdContainer ("MuonsTgcRpcPhiHits", muon_nTGCRPCPhihits);
+    declareMonitoredStdContainer ("MuonsTgcRpcEtaHits", muon_nTGCRPCEtahits);
+    declareMonitoredStdContainer ("MuonsMdtHitsInSeg", muon_nMDThitsInseg);
+    declareMonitoredStdContainer ("MuonsRpcHitsInSeg", muon_nRPChitsInseg);
+    declareMonitoredStdContainer ("MuonsTgcHitsInSeg", muon_nTGChitsInseg);
+    declareMonitoredStdContainer ("MuonsTgcRpcHitsInSeg", muon_nTGCRPChitsInseg);
+    declareMonitoredStdContainer ("MuonsMdtSegs", muon_nMDTsegs);
+    declareMonitoredStdContainer ("MuonsRpcSegs", muon_nRPCsegs);
+    declareMonitoredStdContainer ("MuonsCscSegs", muon_nCSCsegs);
+    declareMonitoredStdContainer ("MuonsTgcSegs", muon_nTGCsegs);
+    declareMonitoredStdContainer ("MuonsTgcRpcSegs", muon_nTGCRPCsegs);
+    declareMonitoredStdContainer ("MuonsBeta", muon_beta);
+    declareMonitoredStdContainer ("MuonsNNBarrel", muon_nnBarrel);
+    declareMonitoredStdContainer ("MuonsNNEndcap", muon_nnEndcap);
+    declareMonitoredStdContainer ("MuonsRPCHitsMeasTime", muon_RPCHitsMeasTime);
+    declareMonitoredStdContainer ("MuonsRPCHitsPropTime", muon_RPCHitsPropTime);
+    declareMonitoredStdContainer ("MuonsRPCHitsTof", muon_RPCHitsTof);
+    declareMonitoredStdContainer ("MuonsRPCHitsDist", muon_RPCHitsDis);
+    // for perform
+    declareProperty("doNTuplePerformance",  m_doNTuplePerformance  = false);
+    declareProperty("doTruthPerformance",   m_doTruthPerformance   = false);
+    
+}
+
+//** ----------------------------------------------------------------------------------------------------------------- **//
+
+
+TrigMuGirl::~TrigMuGirl() {delete m_pSegmentManager;}
+
+
+//** ----------------------------------------------------------------------------------------------------------------- **//
+
+
+HLT::ErrorCode TrigMuGirl::hltInitialize() {
+  
+  if (msgLvl() <= MSG::DEBUG) 
+    msg() << MSG::DEBUG << "Initializing TrigMuGirl " << endreq;    
+
+  //  StatusCode status;
+  //  StatusCode sc = StatusCode::SUCCESS;
+
+  //int timers
+  m_timerExecTotal = addTimer("eExecTotal");
+  
+    m_pSegmentManager = new MuGirlNS::SegmentManager;
+    if (m_magFieldSvc.retrieve().isFailure())
+    {
+        msg(MSG::ERROR) <<"Could not retrieve magFieldSvc"<<endreq;
+        return StatusCode::RECOVERABLE;
+    }
+
+/*
+    ServiceHandle<StoreGateSvc> pDetStore("DetectorStore", name());
+    if (retrieve(pDetStore).isFailure())
+        return StatusCode::RECOVERABLE;
+    if (pDetStore->retrieve(m_pMuonMgr).isFailure() || m_pMuonMgr == NULL)
+    {
+      msg() << MSG::ERROR << "Cannot retrieve MuonDetectorManager" << endreq;
+        return StatusCode::RECOVERABLE;
+    }
+
+*/
+  if (retrieve(m_pEventStore).isFailure())
+    //      return StatusCode::RECOVERABLE;
+    msg() << MSG::DEBUG << "Failed to get the StoreGate" << endreq;    
+
+  // Initialize tools
+  if (retrieve(m_pToCalo, false).isFailure())
+    {
+      msg() << MSG::DEBUG << "Failed to get pToCalo" << endreq;    
+      m_pToCalo = NULL;
+    }
+  
+  if (m_doTruth)
+    {
+      if (retrieve(m_pTruthTool).isFailure())
+	//            return StatusCode::RECOVERABLE;
+	msg() << MSG::DEBUG << "Failed to get the TruthTool" << endreq;    
+    }
+
+  if (m_doLHR)
+    {
+      if (retrieve(m_pMuLHR, false).isFailure())
+	{
+	  msg() << MSG::DEBUG << "Failed to get the pMuLHR" << endreq;    
+	  m_pMuLHR = NULL;
+	}
+    }
+  
+  if (m_doStau)
+    {
+      if (retrieve(m_pStauTool).isFailure())
+	{
+	  msg() << MSG::DEBUG << "Failed to get the StauTool" << endreq;    
+	  //            return StatusCode::RECOVERABLE;
+	}
+        m_pStauTool->setSegmentManager(m_pSegmentManager);
+    }
+  
+  if (m_doGlobalFit )
+    {
+      if (retrieve(m_pGlobalFitTool, false).isFailure())
+	{
+	  msg() << MSG::DEBUG << "Failed to get the GlobalFitTool" << endreq;
+	  m_pGlobalFitTool = NULL;
+	}
+    }
+  if (m_doMuonFeature && m_doSAFit )
+    {
+      if (retrieve(m_pMuonFeatureGlobalFitTool, false).isFailure())
+	{
+	  msg() << MSG::DEBUG << "Failed to get the GlobalFitTool for SA fit" << endreq;
+	  m_pMuonFeatureGlobalFitTool = NULL;
+	}
+    }
+
+  if (m_doANNSelection)
+    {
+      if (retrieve(m_pANNSelectionTool, false).isFailure())
+	{
+	  msg() << MSG::DEBUG << "no m_pANNSelection" << endreq;    
+	  m_pANNSelectionTool = NULL;
+	}
+    }
+  
+    // this is done anyway to have the function removeRedundantCandidates avilable
+    //    if (m_doParticleCreator)
+    {
+      if (retrieve(m_pParticleCreatorTool).isFailure())
+	{
+	  msg()<<MSG::DEBUG<<"no m_pParticleCreatorTool"<<endreq;    
+	  m_pParticleCreatorTool = NULL;
+	}
+    }
+
+    m_caloLayers.push_back( CaloCell_ID::PreSamplerB );
+    m_caloLayers.push_back( CaloCell_ID::EMB1 );
+    m_caloLayers.push_back( CaloCell_ID::EMB2 );
+    m_caloLayers.push_back( CaloCell_ID::EMB3 );
+    m_caloLayers.push_back( CaloCell_ID::TileBar0 );
+    m_caloLayers.push_back( CaloCell_ID::TileBar1 );
+    m_caloLayers.push_back( CaloCell_ID::TileBar2 );
+    m_caloLayers.push_back( CaloCell_ID::PreSamplerE );
+    m_caloLayers.push_back( CaloCell_ID::EME1 );
+    m_caloLayers.push_back( CaloCell_ID::EME2 );
+    m_caloLayers.push_back( CaloCell_ID::EME3 );
+    m_caloLayers.push_back( CaloCell_ID::HEC0 );
+    m_caloLayers.push_back( CaloCell_ID::HEC1 );
+    m_caloLayers.push_back( CaloCell_ID::HEC2 );
+    m_caloLayers.push_back( CaloCell_ID::FCAL0 );
+    m_caloLayers.push_back( CaloCell_ID::FCAL1 );
+    m_caloLayers.push_back( CaloCell_ID::FCAL2 );
+    m_caloLayers.push_back( CaloCell_ID::TileExt0 );
+    m_caloLayers.push_back( CaloCell_ID::TileExt1 );
+    m_caloLayers.push_back( CaloCell_ID::TileExt2 );
+
+
+    if (retrieve(m_pCandidate).isFailure())
+      {
+	msg()<<MSG::ERROR<<"Could not get pCandidate"<<endreq;
+	return StatusCode::RECOVERABLE;
+      }
+    m_pCandidate->setSegmentManager(m_pSegmentManager);
+
+    // Initialize NTuple
+    if (m_doNTuple)
+    {
+      msg()<<MSG::DEBUG<<"in doNTuple"<<endreq;
+
+      m_pCandNTuple = ntupleSvc()->book(m_ntupleName, CLID_ColumnWiseTuple, m_ntupleTitle);
+      if (m_pCandNTuple == NULL)
+      {
+	  msg() << MSG::ERROR << "Could not create NTuple " << m_ntupleName << endreq;
+	  return StatusCode::RECOVERABLE;
+      }
+      if (m_pCandidate->bookNTuple(m_pCandNTuple).isFailure())
+      {
+	  msg() << MSG::ERROR << "Could not book Candidate NTuple " << m_ntupleName << endreq;
+	  return StatusCode::RECOVERABLE;
+      }
+
+      if(m_doStau)
+      {
+	  if(m_pStauTool->bookNTuple(m_pCandNTuple).isFailure())
+            {
+	      msg() << MSG::ERROR << "Could not book Stau NTuple " << m_ntupleName << endreq;
+	      return StatusCode::RECOVERABLE;
+            }
+      }
+      if(m_doMuonFeature && m_doSAFit)
+      {
+           if (m_pMuonFeatureGlobalFitTool->bookNTuple(m_pCandNTuple,"StandAlone").isFailure())
+	       msg() << MSG::ERROR << "Could not book GlobalFit NTuple for StandAlone fit" << m_ntupleName << endreq;
+           else 
+	       msg() << MSG::DEBUG << "Book GlobalFit NTuple for StandAlone fit" << m_ntupleName << endreq;
+      }
+      if (m_doTruth&& m_pTruthTool->bookNTuple(m_pCandNTuple).isFailure())
+      {
+	  msg() << MSG::ERROR << "Could not book Truth NTuple " << m_ntupleName << endreq;
+	  return StatusCode::RECOVERABLE;
+      }
+      if (m_doGlobalFit&& m_pGlobalFitTool->bookNTuple(m_pCandNTuple,"").isFailure())
+      {
+            msg() << MSG::ERROR << "Could not book GlobalFit NTuple " << m_ntupleName << endreq;
+            return StatusCode::RECOVERABLE;
+      }
+    }
+
+    // this shouldn't work but we can work without it too
+    //    if (retrieve(m_particleCreatorTool).isFailure())
+    //      {
+    //	msg()<<MSG::ERROR<<"Could not get m_particleCreatorTool"<<endreq;
+    //	//return StatusCode::RECOVERABLE;
+    //      }
+
+    if (m_doNTuplePerformance)
+      {
+        m_pTrigMuGirlNtuple = new TrigMuGirlNtuple(this, ntupleSvc());
+        StatusCode SCstatus = m_pTrigMuGirlNtuple->book(m_ntupleNamePerformance, m_ntupleTitlePerformance);
+        if (SCstatus.isFailure() || m_pTrigMuGirlNtuple == NULL)
+	  {
+            msg()<< MSG::ERROR << "Could not book NTuple " << m_ntupleName << endreq;
+            return HLT::BAD_JOB_SETUP;
+	  }
+      }
+
+
+    if (msgLvl() <= MSG::DEBUG) 
+      msg() << MSG::DEBUG << "Initializing TrigMuGirl done successfully" << endreq;    
+    return HLT::OK;
+}
+
+
+//** ----------------------------------------------------------------------------------------------------------------- **//
+
+
+HLT::ErrorCode TrigMuGirl::hltFinalize() {
+
+  if (msgLvl() <= MSG::INFO) 
+    msg() << MSG::INFO << "Finalizing TrigMuGirl" << endreq;
+
+    return HLT::OK;
+}
+
+//** ----------------------------------------------------------------------------------------------------------------- **//
+
+
+HLT::ErrorCode TrigMuGirl::hltExecute(const HLT::TriggerElement* inputTE, HLT::TriggerElement* outputTE) {
+
+  if (doTiming()) 
+    {
+      m_timerExecTotal->start();
+      //      m_timerTotal1->start();
+      //      m_timerAllFun->start();
+      //      m_timerAllFun->pause();
+    }
+    ++m_roi;
+  //  if (msg().level() <= MSG::DEBUG) msg() << MSG::DEBUG << "Executing TrigMuGirl <--*--> hello erez" << endreq;
+    if (m_doNTuplePerformance)
+      {
+	eRunNumber=0;
+	eEventNumber=0;
+	NN[0]=0;
+	NN[1]=0;
+	NN[2]=0;
+	NN[3]=0;
+	NN[4]=0;
+	NN[5]=0;
+      }
+
+  //  StatusCode status;
+  StatusCode sc = StatusCode::SUCCESS;
+
+  const EventInfo* pEventInfo = NULL;
+  sc = m_pEventStore->retrieve(pEventInfo);
+  if (sc.isFailure() || pEventInfo == NULL)
+	msg() << MSG::WARNING << "Cannot retrieve EventInfo" << endreq;
+  else if (m_doNTuplePerformance)
+  {
+	eRunNumber   = pEventInfo->event_ID()->run_number();
+	eEventNumber = pEventInfo->event_ID()->event_number();
+  }
+
+  if ( msgLvl() <= MSG::DEBUG ) 
+    msg()<<MSG::DEBUG<<"Executing "<<name()<<" for types "
+	 <<inputTE->getId()<<" -> "<<outputTE->getId()<<endreq;
+  
+  //m_pRefittedTrkCollection = new TrackCollection();
+  //m_pRefittedTrkContainer = new Rec::TrackParticleContainer();
+  //m_pSegmentCollection = new Trk::SegmentCollection();
+
+  HLT::ErrorCode status;
+  MuGirlNS::CandidateSummaryList summaryList;
+
+  /** initialize old EDM still used by the HLT Muon Trigger Elemen */
+  ElementLinkVector<Rec::TrackParticleContainer> elv_idtrks;
+
+/* sofia */
+
+  if (m_doMuonFeature)
+  {
+     std::vector<const MuonFeature*> vectorOfMuonFeature;
+     status = getFeatures(inputTE, vectorOfMuonFeature, "");
+     if (status != HLT::OK)
+        goto IDtrack;
+
+ 
+     int iMuF=0;  
+     if (vectorOfMuonFeature.size() != 0)
+     {
+       m_pStauTool->initTool(m_doSAFit);
+
+       if (msg().level() <= MSG::DEBUG)
+           msg()<<MSG::DEBUG<<"Start MuonFeature processing for "<<vectorOfMuonFeature.size()<<endreq;
+     
+          //const MuonFeature* pMuonFeature = vectorOfMuonFeature.front();
+       for(unsigned int i=0; i<vectorOfMuonFeature.size(); i++)
+     
+       {
+          const MuonFeature* pMuonFeature = vectorOfMuonFeature[i];
+          if (!pMuonFeature)
+          {
+             msg() << MSG::ERROR
+                   << "Retrieval of MuonFeature from vector failed!"
+                   << endreq;
+             continue;
+          }
+          if (fabs(pMuonFeature->pt())<m_mfPtCut)  //MuonFeature momentum is in GeV
+             continue;
+
+          bool has_combined = false;
+
+          ElementLink<CombinedMuonFeatureContainer> CombinedMuonFeatureEL;
+          if ( HLT::OK == getFeatureLink<CombinedMuonFeatureContainer, 
+                   CombinedMuonFeature>(inputTE, CombinedMuonFeatureEL) )            
+          { 
+             if ( CombinedMuonFeatureEL.isValid() )     
+             { 
+
+                const CombinedMuonFeature* pMuon = *CombinedMuonFeatureEL; 
+                if(pMuon)
+                {
+                  ElementLink<MuonFeatureContainer> mfastEL = pMuon->muFastTrackLink();
+                  ElementLink<TrigInDetTrackCollection> trackEL = pMuon->IDTrackLink();           
+                  if (!mfastEL) continue;
+
+                  const MuonFeature* pMF = *mfastEL;
+                   
+                  if (!pMF) continue; 
+                  if (pMF == pMuonFeature && trackEL.isValid())                                                          
+                  { 
+                    if (msg().level() <= MSG::DEBUG)
+                        msg()<<MSG::DEBUG<<"HAS IDTrack! moving to IDTrack processing"<<endreq;
+                    has_combined = true;
+                    continue;
+                  }
+                }
+             }
+          } 
+ 
+          if (m_pCandidate->fillMF(iMuF, pMuonFeature, true,has_combined).isFailure()) 
+          {
+             msg()<< MSG::DEBUG << "MuonFeature Cannot fill CANDIDATE" << endreq;
+             continue;
+          }
+          fillMuonSegmentColl(m_pCandidate->vectorMuonSegments());
+
+          MuGirlNS::CandidateSummary* summary_mf = new MuGirlNS::CandidateSummary();
+          if ( msgLvl() <= MSG::DEBUG ) 
+          {
+             msg()<< MSG::DEBUG << "MuonFeature "<<pMuonFeature->pt()<<" eta "<<pMuonFeature->eta()<<" phi "<<pMuonFeature->phi()  << endreq;
+             msg()<< MSG::DEBUG << "MuonFeature fill SUMMARY" << endreq;
+          }
+
+          if (m_pCandidate->fillSummary(summary_mf).isFailure())
+          {
+              msg()<< MSG::DEBUG << "MuonFeature Cannot fill SUMMARY" << endreq;
+              continue;
+          }
+
+          if (m_doNTuple)
+          {
+             if (pEventInfo != NULL)
+             {
+                if ((m_pCandidate->fillNTupleEventInfo(pEventInfo->event_ID()->run_number(),
+                    pEventInfo->event_ID()->event_number())).isFailure())
+                    msg() << MSG::WARNING << "MuonFeature::execute Cannot fill NTuple" << endreq;
+             }
+	      if (msg().level() <= MSG::DEBUG)
+	          msg() << MSG::DEBUG << "Calling m_pCandidate->fillNTuple for MF" << endreq;
+             if (m_pCandidate->fillNTuple().isFailure())
+                 msg() << MSG::WARNING << "MuonFeature::execute Cannot fill NTuple" << endreq;
+             if (m_doTruth&&pMuonFeature!=0)
+             {
+                 msg() << MSG::DEBUG << "Calling m_pTruthTool->fillNTuple for MuonFeature processing" << endreq;
+                 if (m_pTruthTool->fillNTuple(summary_mf).isFailure())
+                     msg() << MSG::WARNING << "TrigMuGirl::execute Cannot fill Truth in NTuple for Muonfeature processing" << endreq;
+             }
+          }
+          
+          if ( msgLvl() <= MSG::DEBUG ) 
+              msg()<< MSG::DEBUG << "MuonFeature do Stau hits" << summary_mf->numMdtHits
+                   <<" "<<summary_mf->numTgcEtaHits<<" "<<summary_mf->numTgcPhiHits
+                   <<" "<<summary_mf->numRpcEtaHits<<" "<< summary_mf->numRpcPhiHits
+                   << endreq;
+          if (summary_mf->numMdtHits >4 && 
+             (summary_mf->numTgcEtaHits>2 || summary_mf->numTgcPhiHits>2 || summary_mf->numRpcEtaHits>2 || summary_mf->numRpcPhiHits>2))
+          {
+             if ( msgLvl() <= MSG::DEBUG ) 
+                msg()<< MSG::DEBUG << "MuonFeature do Stau" << endreq;
+             summary_mf->saveStau = 1;
+             m_pCandidate->setPassdoStau(true);
+
+             const MuGirlNS::MdtSegmentMakerInfoList mdtSegmentMakerInfoList = m_pCandidate->getMdtSegmentMakerInfo();
+             const MuGirlNS::RIO_OnTrackLists& rpcHitsInSegments = m_pCandidate->getRpcHitsInSegments();
+             const MuGirlNS::RIO_OnTrackLists& tgcHitsInSegments = m_pCandidate->getTgcHitsInSegments();
+
+             float mf_cot  = 1/tan(2*atan(exp (-pMuonFeature->eta())));
+             float mf_px   = 1000*fabs(pMuonFeature->pt())*cos(pMuonFeature->phi());
+             float mf_py   = 1000*fabs(pMuonFeature->pt())*sin(pMuonFeature->phi());
+             float mf_pz   = 1000*fabs(pMuonFeature->pt())*mf_cot;
+             //double mf_p    = sqrt(mf_px*mf_px+ mf_py*mf_py + mf_pz*mf_pz);
+             Amg::Vector3D v(mf_px,mf_py,mf_pz);
+             if ( m_pStauTool->processStau(NULL,m_pCandidate->vectorMuonSegments(),mdtSegmentMakerInfoList,rpcHitsInSegments,tgcHitsInSegments,NULL,NULL,v).isFailure())
+                  msg() << MSG::WARNING << "MuonFeature::cannot execute processStau" << endreq;
+             for(std::vector<const Muon::MuonSegment*>::const_iterator itSegs = (*m_pStauTool->newMdtSegments()).begin(); itSegs != (*m_pStauTool->newMdtSegments()).end(); itSegs++)
+             {
+                 m_pSegmentManager->addSegment(*itSegs, MuGirlNS::SegmentManager::MDT_STAU);
+             }
+             fillMuonSegmentColl(*m_pStauTool->newMdtSegments());
+             if (m_pStauTool->beta() <0.2 || m_pStauTool->beta()>1.2)
+             {
+                 delete m_pStauTool->refittedTrack();
+                 continue;
+             }  
+             summary_mf->beta = m_pStauTool->beta();
+
+             if (m_doNTuple)
+             {
+                if (m_pStauTool->fillNTuple().isFailure())
+                    msg() << MSG::WARNING << "MuonFeature::execute Cannot fill Stau NTuple" << endreq;
+             }
+
+             MuGirlNS::CandidateSummary* stauSummary = new MuGirlNS::CandidateSummary();
+
+             if (m_pStauTool->fillStauSummary(summary_mf,stauSummary).isFailure())
+                 msg() << MSG::DEBUG << "MuonFeature::execute Cannot fill stausummary" << endreq;
+             stauSummary->qOverP = summary_mf->qOverP;
+             stauSummary->startFromMF = 1;
+             bool ANNstau = generateMuGirl(stauSummary);
+
+             msg() << MSG::DEBUG << "MuonFeature::execute ANNstau"<< ANNstau << endreq;
+             //if (ANNstau)
+            // {
+             stauSummary->saveStau = 1;
+             summaryList.push_back(stauSummary);
+             //}
+	     if ( m_doSAFit && stauSummary->muonSegmentList.size()>0)
+	     //if ( m_doSAFit && m_pCandidate->vectorMuonSegments().size()>0)
+             {
+               msg() << MSG::DEBUG << "MuonFeature:: stau segments "<<stauSummary->muonSegmentList.size()
+                                   << " Muon segments "<<m_pCandidate->vectorMuonSegments().size()<< endreq;
+               const Trk::Track* RefittedTrack = 0;
+               RefittedTrack = m_pMuonFeatureGlobalFitTool->globalFit(stauSummary->muonSegmentList,summary_mf->qOverP,m_doNTuple);
+               //RefittedTrack = m_pMuonFeatureGlobalFitTool->globalFit(m_pCandidate->vectorMuonSegments(),summary_mf->qOverP,m_doNTuple);
+
+                 if (RefittedTrack != NULL)
+                 {
+                    ATH_MSG_DEBUG("found SA track");
+                    /** add only the refitted track to the MuGirl summary */
+                    xAOD::TrackParticle* tp = NULL;
+                    m_pCandidate-> fillRefittedTrack(tp,RefittedTrack,stauSummary);
+                //  m_pRefittedTrkCollection->push_back(const_cast<Trk::Track*> (RefittedTrack));
+                 }
+                 else
+                 { 
+                    delete RefittedTrack;
+                    m_pCandidate-> fillRefittedTrack(NULL,NULL,stauSummary);
+                 }
+             }
+          }   // enter stau selection
+
+          iMuF++;
+       } // loop on vector of MuonFeatures
+    }   // if vectorOfMuonFeature.size()>0
+    if (m_doNTuple)
+    {
+       if (m_pCandNTuple->writeRecord().isFailure())
+           msg() << MSG::WARNING << "MuonFeature::execute Cannot write NTuple" << endreq;
+    }
+
+    if (msg().level() <= MSG::DEBUG)
+       msg() << MSG::DEBUG << "MF processing is done"<<endreq;
+      
+   }   //if doMuonFeature
+
+   IDtrack:
+   m_pStauTool->initTool(m_doGlobalFit);
+   const VxContainer* vxCandidatesContainer = 0;
+   int iTrack = 0;
+   // for performance ntuple
+   float TrackIso=-1;
+
+
+   std::vector<const xAOD::CaloClusterContainer*> vectorOfClusterContainers;
+    
+    //if(getFeatures(inputTE, vectorOfClusterContainers,"HLT_TrigCaloClusterMaker")!=HLT::OK) 
+    if(getFeatures(inputTE, vectorOfClusterContainers,"HLT")!=HLT::OK) 
+      {
+        if(msgLvl() <= MSG::WARNING) msg() << MSG::WARNING << "Failed to get ClusterContainers" << endreq;
+        //      return "";
+      }
+    if(msgLvl() <= MSG::DEBUG)
+      msg() << MSG::DEBUG << "Got vector with " << vectorOfClusterContainers.size()  << " ClusterContainers" << endreq;
+    
+    // if no containers were found, just leave the vector empty and leave
+    if ( vectorOfClusterContainers.size() < 1) {
+      if(msgLvl() <= MSG::DEBUG) 
+        msg() << MSG::DEBUG << "No Cluster container available !" << endreq;
+      //      return "";
+    }
+    else
+      {
+        // get last container to be put in vector (should also be the only one)
+        m_pClusCollection = vectorOfClusterContainers.back();
+        if (!m_pClusCollection)
+          {
+            if(msgLvl() <= MSG::WARNING) 
+              msg() << MSG::WARNING << "No Clusters found in the RoI" << endreq;
+            //  return "";
+          }
+      }
+
+    if (!m_magFieldSvc->solenoidOn()) 
+    { 
+        if (msg().level()<=MSG::DEBUG) msg()<<MSG::DEBUG << "MuGirl::Solenoid is off. Execute done" << endreq; 
+        goto notrack;
+     } 
+      else
+        if (msg().level()<=MSG::DEBUG) msg()<<MSG::DEBUG << "MuGirl::Solenoid is ON" << endreq; 
+
+   // get element links to the ID tracks
+   m_inDetTrackParticleLinks.clear();
+   if( HLT::OK != getFeaturesLinks<Rec::TrackParticleContainer,Rec::TrackParticleContainer>(inputTE, elv_idtrks, "") ) {
+    msg() << MSG::WARNING << "Failed to get ElementLinkVector<Rec::TrackParticleContainer>, aborting this ROI" << endreq;
+    goto notrack;
+  }
+
+    // out for timing
+    //    if (msg().level() <= MSG::DEBUG)
+    //        msg() << MSG::DEBUG << "Size of TrackParticleCandidate = " << m_inDetTrackParticleLinks->size() << endreq;
+   if (m_pEventStore->contains<VxContainer>("VxPrimaryCandidate"))
+   {
+      sc = m_pEventStore->retrieve(vxCandidatesContainer, "VxPrimaryCandidate");
+       if (sc.isFailure())
+       {
+          if (msg().level() <= MSG::DEBUG) 
+              msg()<<MSG::DEBUG << "Cannot retrieve " << "VxPrimaryCandidate" << endreq;
+       }
+    }
+    else
+         if (msg().level() <= MSG::DEBUG)
+               msg()<<MSG::DEBUG << "Cannot retrieve " << "VxPrimaryCandidate" << endreq;
+
+    if (m_doNTuplePerformance)
+    {
+	eRunNumber   = pEventInfo->event_ID()->run_number();
+	eEventNumber = pEventInfo->event_ID()->event_number();
+    }
+    // in case we want to look for Calo information
+    /*
+    std::vector<const CaloClusterContainer*> vectorOfClusterContainers;
+    
+    if(getFeatures(inputTE, vectorOfClusterContainers, "")!=HLT::OK) 
+      {
+	if(msgLvl() <= MSG::WARNING) msg() << MSG::WARNING << "Failed to get ClusterContainers" << endreq;
+	//	return "";
+      }
+    if(msgLvl() <= MSG::DEBUG)
+      msg() << MSG::DEBUG << "Got vector with " << vectorOfClusterContainers.size()  << " ClusterContainers" << endreq;
+    
+    // if no containers were found, just leave the vector empty and leave
+    if ( vectorOfClusterContainers.size() < 1) {
+      if(msgLvl() <= MSG::DEBUG) 
+	msg() << MSG::DEBUG << "No Cluster container available !" << endreq;
+      //      return "";
+    }
+    else
+      {
+	// get last container to be put in vector (should also be the only one)
+	m_pClusCollection = vectorOfClusterContainers.back();
+	if (!m_pClusCollection)
+	  {
+	    if(msgLvl() <= MSG::WARNING) 
+	      msg() << MSG::WARNING << "No Clusters found in the RoI" << endreq;
+	    //	return "";
+	  }
+      }
+    */
+    /*  
+    const DataHandle<CaloClusterContainer> resultContainer, lastContainer;
+    sc =m_pEventStore->retrieve(resultContainer, lastContainer);
+    if (sc.isFailure()) {
+      msg() << MSG::DEBUG << " didn't find any CaloClusterContainer " << endreq;
+    } else {
+      msg() << MSG::DEBUG << " found  CaloClusterContainers " << endreq;
+      int ncl=0;
+      for (; resultContainer != lastContainer; ++resultContainer) {
+	ncl++;	
+	std::string name(resultContainer.key());
+	msg() << MSG::DEBUG << "Container "<< resultContainer.key()<< " ncl= "<<ncl<<endreq;
+	//	if( name.find("TrigCaloClusterMaker") != std::string::npos ){
+	if( name.find("HLT_TrigCaloClusterMaker") != std::string::npos ){
+	  msg() << MSG::DEBUG <<  " in if ncl= "<<ncl<<endreq;
+ 	  m_pClusCollection = resultContainer;
+ 	  msg() << MSG::DEBUG << "clus size = "<<m_pClusCollection->size()<<endreq;
+
+
+         }
+      }
+    }
+*/
+
+
+    createCaloParticles();
+      // out for timing
+      //    if (msg().level() <= MSG::DEBUG)
+      //      msg() << MSG::DEBUG << "Size of CaloParticles " << m_caloParticles.size() << endreq;
+    
+    IsolatedIdTracks(m_idR);
+
+
+    for (unsigned int i = 0; i < m_caloParticles.size(); i++)
+    {
+        CaloParticle* pParticle = m_caloParticles[i];
+        const xAOD::TrackParticle* pTrackParticle = pParticle->pTrackParticle;
+        const Trk::TrackParameters* extrMuonLayer = pParticle->pTrackParameters;
+
+        bool doStau = m_doStau && pTrackParticle->perigeeParameters().pT() >= m_stauPtCut;
+        msg() << MSG::DEBUG << "TrigMuGirl::execute doStau "<<doStau << endreq;
+        if (!m_pCandidate->fill(iTrack, pTrackParticle, extrMuonLayer, doStau).isSuccess())
+        {
+            msg() << MSG::DEBUG << "TrigMuGirl::execute failed candidate->fill " << endreq;
+   
+            fillMuonSegmentColl(m_pCandidate->vectorMuonSegments());
+            continue;
+        }
+	//	if (m_pClusCollection != NULL)
+	//	  {
+	    //	    msg()<<MSG::DEBUG<<"pParticle->isolated ="<<pParticle->isolated<<endreq;
+	    //	    if (m_doLHR && m_pMuLHR && m_pClusCollection->size() > 0)
+	//	    if (m_doLHR && m_pMuLHR && pParticle->isolated && m_pClusCollection->size() > 0)
+	//	      calculateLHR(pParticle);
+	//	  }
+
+	//for performance ntuple
+	if (pParticle->isolated)
+	  {
+	    m_pCandidate->setIsolation(1);
+	    m_pCandidate->setLHR(-2);
+	  }
+	TrackIso=pParticle->isolated;
+
+        MuGirlNS::CandidateSummary* summary = new MuGirlNS::CandidateSummary();
+
+        bool ANNaccept = false;
+        if (m_pCandidate->fillSummary(summary).isFailure())
+	{
+            msg() << MSG::DEBUG << "TrigMuGirl::execute Cannot fill summary" << endreq;
+	}
+        else
+	{
+	   if (m_doANNSelection)
+	   {
+               ANNaccept = generateMuGirl(summary);
+	   }
+	}
+
+	if ((m_doANNSelection && ANNaccept) || !(m_doANNSelection)) 
+        {
+	   summary->saveAnn = 1;
+
+	   if (m_doGlobalFit&&pTrackParticle->track()!=NULL&&
+	      (m_pCandidate->vectorMuonSegments()).size()>0)
+            {
+               const Trk::Track* RefittedTrack = 0;
+               RefittedTrack = m_pGlobalFitTool->globalFit(pTrackParticle->track(),m_pCandidate->vectorMuonSegments(),m_doNTuple);
+               if (RefittedTrack != NULL)
+               {
+                   //m_pRefittedTrkCollection->push_back(const_cast<Trk::Track*> (RefittedTrack));
+                   //const xAOD::Vertex* pVxCandidate = 0 ;
+		   //pVxCandidate = *(pTrackParticle->vertex());
+                   xAOD::TrackParticle* tp = 0;
+
+                   m_pCandidate-> fillRefittedTrack(tp,RefittedTrack,summary);
+	       }
+	       else
+               {
+		  delete RefittedTrack;
+	          m_pCandidate-> fillRefittedTrack(NULL,NULL,summary);
+               } 
+
+	       if (msg().level() <= MSG::DEBUG)
+	           msg() << MSG::DEBUG << "Global Fit was ran " << endreq;
+           }  //if doGlobalFit
+
+       }//if ANN     
+       else
+	  m_pCandidate-> fillRefittedTrack(NULL,NULL,summary);
+
+       if (m_doNTuple)
+       {
+          if (pEventInfo != NULL)
+          {
+	      sc = m_pCandidate->fillNTupleEventInfo(pEventInfo->event_ID()->run_number(),
+	    				             pEventInfo->event_ID()->event_number());
+
+	      if (sc.isFailure())
+	          msg() << MSG::WARNING << "TrigMuGirl::execute Cannot fill NTuple" << endreq;
+	  }
+	  if (msg().level() <= MSG::DEBUG)
+	      msg() << MSG::DEBUG << "Calling m_pCandidate->fillNTuple" << endreq;
+	    
+	  if (m_pCandidate->fillNTuple().isFailure())
+	      msg() << MSG::WARNING << "TrigMuGirl::execute Cannot fill NTuple" << endreq;
+	  if (m_doNTuple&&m_doTruth&&pTrackParticle!=NULL)
+	  {
+	      if (msg().level() <= MSG::DEBUG)
+	          msg() << MSG::DEBUG << "Calling m_pTruthTool->fillNTuple" << endreq;
+	      if (m_pTruthTool->fillNTuple(summary).isFailure())
+	          msg() << MSG::WARNING << "TrigMuGirl::execute Cannot fill Truth in NTuple" << endreq;
+	  }
+       } //if doNTuple
+       fillMuonSegmentColl(summary->muonSegmentList);
+        //<S>
+	// needs to be updated - there is a branch
+       bool passedStau = false;
+       if(doStau && summary->numMdtHits >4 &&(summary->numTgcEtaHits>2 || summary->numTgcPhiHits>2 || summary->numRpcEtaHits>2 || summary->numRpcPhiHits>2))
+       {   
+	  m_pCandidate->setPassdoStau(true);
+  //retrieve segment maker info list
+	  const MuGirlNS::MdtSegmentMakerInfoList mdtSegmentMakerInfoList = m_pCandidate->getMdtSegmentMakerInfo();
+	  //retrieve the rpc hits
+	  const MuGirlNS::RIO_OnTrackLists& rpcHitsInSegments = m_pCandidate->getRpcHitsInSegments();
+          const MuGirlNS::RIO_OnTrackLists& tgcHitsInSegments = m_pCandidate->getTgcHitsInSegments();
+
+	  //process stau
+
+          const Trk::Track* pMuonRefittedTrack = NULL;
+          if (summary->pRefittedTrack != NULL)
+              pMuonRefittedTrack = summary->pRefittedTrack->track(); 
+          sc = m_pStauTool->processStau(pTrackParticle, m_pCandidate->vectorMuonSegments(), mdtSegmentMakerInfoList,rpcHitsInSegments,tgcHitsInSegments,pMuonRefittedTrack);
+	  summary->beta = m_pStauTool->beta();
+
+          for(std::vector<const Muon::MuonSegment*>::const_iterator itSegs = (*m_pStauTool->newMdtSegments()).begin(); itSegs != (*m_pStauTool->newMdtSegments()).end(); itSegs++)
+          {
+             m_pSegmentManager->addSegment(*itSegs, MuGirlNS::SegmentManager::MDT_STAU);
+          }
+	
+          fillMuonSegmentColl(*m_pStauTool->newMdtSegments());
+	  if (!sc.isFailure())
+          {
+             
+              if (m_pStauTool->beta() <0.2 || m_pStauTool->beta() >1.2)
+                 delete m_pStauTool->refittedTrack();
+              else
+              {
+	          MuGirlNS::CandidateSummary* stauSummary = new MuGirlNS::CandidateSummary();
+	          if (m_pStauTool->fillStauSummary(summary,stauSummary).isFailure())
+	          msg() << MSG::DEBUG << "TrigMuGirl::execute Cannot fill stausummary" << endreq;
+
+                  bool ANNstau = generateMuGirl(stauSummary);
+                  if (stauSummary->nnBarrel >0.2 || stauSummary->nnEndCap >0.2) ANNstau = true;
+                  msg()<<MSG::DEBUG << "MuGirl::execute: stau passANN "<<ANNstau << endreq;
+
+                  const Trk::Track* stauRefittedTrack = m_pStauTool->refittedTrack();
+                  if (stauRefittedTrack != NULL)
+                  {
+                      //const Trk::VxCandidate* pVxCandidate = 0 ;
+                      //pVxCandidate=pTrackParticle->reconstructedVertex();
+                      xAOD::TrackParticle* stauTp = NULL;
+
+                      stauSummary->pRefittedTrack = stauTp;  
+                      stauSummary->pTrkRefitted   = stauRefittedTrack; 
+                  }
+                  else
+                  {
+                      stauSummary->pRefittedTrack = NULL;    
+                      stauSummary->pTrkRefitted   = NULL;
+                      delete stauRefittedTrack;
+                  }
+	          if (m_doNTuple)
+                  {
+	              sc = m_pStauTool->fillNTuple();
+	              if(sc.isFailure())
+                          msg() << MSG::DEBUG << "TrigMuGirl::execute stauTool->fillNtuple failed " << endreq; 
+                  }
+
+                  if (ANNstau)
+                  {
+	              stauSummary->saveStau = 1;
+              
+	              passedStau =true;
+	              summaryList.push_back(stauSummary);
+                  }     
+              }
+          }
+       } //if doStau
+
+       msg() << MSG::DEBUG << "TrigMuGirl::execute passedStau "<<passedStau << endreq;
+    
+        if (summary->saveAnn == 1)
+	{
+	    summary->saveStau = 0;
+            summaryList.push_back(summary);
+	}
+        else
+	{
+/*
+            if (passedStau)
+            {
+                std::vector<const Muon::MuonSegment*> muonSegmentList_noMDT;
+                for (MuGirlNS::MuonSegmentList::iterator itMuonSeg = (summary->muonSegmentList).begin();
+                    itMuonSeg != (summary->muonSegmentList).end();
+                    itMuonSeg++)
+                {
+                  if (m_pSegmentManager->isNotMDT(*itMuonSeg))
+                      muonSegmentList_noMDT.push_back(*itMuonSeg);
+                }
+                //fillMuonSegmentColl(muonSegmentList_noMDT);
+            }
+            //else
+	    //   fillMuonSegmentColl(summary->muonSegmentList);
+ */
+	    delete summary; 
+        }
+
+        if (m_doNTuple)
+	{
+            if (m_pCandNTuple->writeRecord().isFailure())
+	      msg() << MSG::WARNING << "TrigMuGirl::execute Cannot write NTuple" << endreq;
+	}
+	// out for timing
+	//	if (msg().level() <= MSG::DEBUG)
+	//	  msg() << MSG::DEBUG << "Done processing track " << iTrack << endreq;
+        iTrack++;
+
+    }  //loop on CaloParticle
+
+
+    // for perform
+    if (m_doNTuplePerformance)
+    {
+        StatusCode statusfill = m_pTrigMuGirlNtuple->fillEvent(eEventNumber,eRunNumber);
+	if (statusfill.isFailure())
+	{
+	    msg() << MSG::ERROR << " Cannot fill NTuple event # " << endreq;
+	    return HLT::BAD_JOB_SETUP;
+	}
+    }
+
+    
+    //    if (msg().level() <= MSG::DEBUG) msg()<<MSG::DEBUG << "Number of summaries=" << summaryList.size() << endreq; 
+
+    
+    if (m_doTruthPerformance)
+    {
+	if (doMuTruthPerformance() != HLT::OK)
+	  msg() << MSG::ERROR  << "The doMuTruth status is not Ok" << endreq;
+    }
+
+    notrack:
+
+    //another output object option
+    eMuonEFInfoCont = new TrigMuonEFInfoContainer();
+    //added a container of ID tracks for future use
+    eTrkParCont = new Rec::TrackParticleContainer;
+ 
+   TrigMuonEFInfo* eMuoninfo = new TrigMuonEFInfo(m_roi);
+   eMuonEFInfoCont->push_back(eMuoninfo);
+
+   //TrigMuonEFInfoTrackContainer* infoTrkCont=eMuoninfo->TrackContainer();
+   
+    int tot_seg = 0; 
+    int tot_mdt = 0; 
+    int tot_csc = 0; 
+    int tot_rpc = 0; 
+    int tot_tgc = 0; 
+   
+    //clear buffers
+    muon_pT.clear();
+    muon_phi.clear();
+    muon_cotTh.clear();
+    muon_nMDThits.clear();
+    muon_nRPCPhihits.clear();
+    muon_nRPCEtahits.clear();
+    muon_nCSCPhihits.clear();
+    muon_nCSCEtahits.clear();
+    muon_nTGCPhihits.clear();
+    muon_nTGCEtahits.clear();
+    muon_nTGCRPCPhihits.clear();
+    muon_nTGCRPCEtahits.clear();
+    muon_nMDThitsInseg.clear();
+    muon_nRPChitsInseg.clear();
+    muon_nTGChitsInseg.clear();
+    muon_nTGCRPChitsInseg.clear();
+    muon_nMDTsegs.clear();
+    muon_nRPCsegs.clear();
+    muon_nTGCsegs.clear();
+    muon_nTGCRPCsegs.clear();
+    muon_nCSCsegs.clear();
+    muon_beta.clear();
+    muon_nnBarrel.clear();
+    muon_nnEndcap.clear();
+    muon_RPCHitsMeasTime.clear();
+    muon_RPCHitsPropTime.clear();
+    muon_RPCHitsTof.clear();
+    muon_RPCHitsDis.clear();
+
+    std::vector<bool> IncludeList;
+    MuGirlNS::CandidateSummaryList* SummaryList=&summaryList;
+
+    m_pParticleCreatorTool->removeRedundantCandidates(SummaryList, IncludeList);
+
+   int iCand = -1;
+   int nMuons=0;
+   for (MuGirlNS::CandidateSummaryList::iterator itSummary = SummaryList->begin(); itSummary !=SummaryList->end(); itSummary++)
+     {
+       iCand++;
+       if (!IncludeList[iCand])
+	  continue;
+       const MuGirlNS::CandidateSummary* pSummary = *itSummary;
+       if (!pSummary->startFromMF && pSummary->pTrackParticle ==NULL)
+       {
+          msg()<<MSG::DEBUG<<"This is not a RHadron candidate and ID track is NULL! candidate skipped"<< endreq;
+          continue;
+       }
+       if (pSummary->saveAnn == 1 || pSummary->saveStau == 1)
+       {
+          muon_nMDThits.push_back(pSummary->numMdtHits);
+          muon_nRPCPhihits.push_back(pSummary->numRpcPhiHits);
+          muon_nRPCEtahits.push_back(pSummary->numRpcEtaHits);
+          muon_nCSCPhihits.push_back(pSummary->numCscPhiHits);
+          muon_nCSCEtahits.push_back(pSummary->numCscEtaHits);
+          muon_nTGCPhihits.push_back(pSummary->numTgcPhiHits);
+          muon_nTGCEtahits.push_back(pSummary->numTgcEtaHits);
+          muon_nTGCRPCEtahits.push_back(pSummary->numTgcRpcEtaHits);
+          muon_nTGCRPCPhihits.push_back(pSummary->numTgcRpcPhiHits);
+ 
+          muon_nMDThitsInseg.push_back(pSummary->numMdtHitsInSeg);
+          muon_nRPChitsInseg.push_back(pSummary->numRpcHitsInSeg);
+          muon_nTGChitsInseg.push_back(pSummary->numTgcHitsInSeg);
+          muon_nTGCRPChitsInseg.push_back(pSummary->numTgcRpcHitsInSeg);
+
+          muon_nMDTsegs.push_back(pSummary->numMdtSegs);
+          muon_nRPCsegs.push_back(pSummary->numRpcSegs);
+          muon_nCSCsegs.push_back(pSummary->numCscSegs);
+          muon_nTGCsegs.push_back(pSummary->numTgcSegs);
+          muon_nTGCRPCsegs.push_back(pSummary->numTgcRpcSegs);
+
+          muon_beta.push_back(pSummary->beta);
+          muon_nnBarrel.push_back(pSummary->nnBarrel);
+          muon_nnEndcap.push_back(pSummary->nnEndCap);
+          MuGirlNS::StauRpcHitsLists* rpcHitsLists = pSummary->rpcHitsLists;
+          if(NULL!=rpcHitsLists)
+          {
+               for(MuGirlNS::StauRpcHitsLists::iterator it = rpcHitsLists->begin(); it != rpcHitsLists->end(); it++)
+               {
+	               MuGirlNS::StauRpcHitsList* pRpcHits = *it;
+	               for(MuGirlNS::StauRpcHitsList::iterator it1 = pRpcHits->begin(); it1 != pRpcHits->end(); it1++)
+	               {
+                           MuGirlNS::StauRpcHit* hit = (*it1);
+	                   muon_RPCHitsMeasTime.push_back( hit->measuredTime);
+	                   muon_RPCHitsPropTime.push_back( hit->propagationTime);
+	                   muon_RPCHitsTof.push_back( hit->muonToF);
+	                   muon_RPCHitsDis.push_back( hit->distance);
+	               }
+	
+	       }
+	
+	  }
+	  //const Rec::TrackParticle* etp;
+          const Trk::Track* etp;
+
+	  if (pSummary->pTrkRefitted==NULL)
+          {   
+              if (pSummary->startFromMF) continue;
+              etp = pSummary->pTrackParticle->track();
+          }
+	  else etp = pSummary->pTrkRefitted;
+
+          const Trk::TrackSummary* trackSummary = etp->trackSummary();
+          int numhits_pix = trackSummary->get(Trk::numberOfPixelHits);
+          int numhits_sct = trackSummary->get(Trk::numberOfSCTHits);
+          int numhits_trt = trackSummary->get(Trk::numberOfSCTHits);
+
+
+	  const Trk::Perigee* emp = etp->perigeeParameters();
+	  double ePhi = emp->parameters()[Trk::phi];
+	  double eTheta = 1/tan(emp->parameters()[Trk::theta]);
+	  double theta = emp->parameters()[Trk::theta];
+	  double ePt = 1/(emp->pT());
+	  double eCharge = etp->perigeeParameters()->charge();
+	  double eMass = 105.7;
+	  if (pSummary->beta >0.0 && pSummary->beta < 1.0)
+          {
+              double BetaCand = pSummary->beta;
+              double mom = (emp->pT())/sin(theta);
+              eMass = mom * sqrt(1.-BetaCand*BetaCand)/BetaCand; 
+          }
+
+	  muon_pT.push_back(1/ePt);
+	  muon_cotTh.push_back(eTheta);
+	  muon_phi.push_back(ePhi);
+	    
+      //      msg() << MSG::DEBUG <<"ePt="<<ePt<< endreq;
+      //      msg() << MSG::DEBUG <<"eTheta="<<eTheta<< endreq;
+      //      msg() << MSG::DEBUG <<"ePhi="<<ePhi<< endreq;
+      //      msg() << MSG::DEBUG <<"eCharge="<<eCharge<< endreq;
+	   //	   msg() << MSG::DEBUG << " testiso pSummary->lhr = " <<pSummary->lhr<< endreq;
+	   //	   msg() << MSG::DEBUG << " testiso TrackIso = " <<TrackIso<< endreq;
+
+          TrigMuonEFInfoTrack * infoTrack = new TrigMuonEFInfoTrack();
+          if (pSummary->pRefittedTrack!=NULL)
+	     infoTrack->setMuonType(2);
+          else
+	     infoTrack->setMuonType(3);
+  
+
+          eMuoninfo->addTrack(infoTrack);
+	   // another output object option
+	  TrigMuonEFCbTrack* combinedTrk = infoTrack->CombinedTrack();
+	  combinedTrk->setPerigee(ePt,eTheta,ePhi,eMass);
+	  combinedTrk->setCharge(eCharge);
+          combinedTrk->setNIdSctHits(numhits_sct); 
+          combinedTrk->setNIdPixelHits(numhits_pix); 
+          combinedTrk->setNTrtHits(numhits_trt);
+           
+          combinedTrk->setNMdtHits(pSummary->numMdtHits);
+          combinedTrk->setNRpcHitsPhi(pSummary->numRpcPhiHits);
+          combinedTrk->setNRpcHitsEta(pSummary->numRpcEtaHits);
+          combinedTrk->setNTgcHitsPhi(pSummary->numTgcPhiHits);
+          combinedTrk->setNTgcHitsEta(pSummary->numTgcEtaHits);
+          combinedTrk->setNCscHitsPhi(pSummary->numCscPhiHits);
+          combinedTrk->setNCscHitsEta(pSummary->numCscEtaHits);
+          if (!pSummary->startFromMF)
+          {
+	     bool foundellink=false;
+	     // find track particle corresponding to the ID track used in the combined muon
+	     for(ElementLinkVector<xAOD::TrackParticleContainer>::const_iterator elit=m_inDetTrackParticleLinks.begin(); 
+		 elit!=m_inDetTrackParticleLinks.end(); ++elit) {
+	       if ( !elit->isValid() ) {
+		 ATH_MSG_WARNING("Invalid EF ID TrackParticle ElementLink");
+		 continue;
+	       }
+	       if(pSummary->pTrackParticle==(**elit)) {
+		 if ( msgLvl(MSG::DEBUG) ) msg() << MSG::DEBUG << "Assigning TrackParticle" << endreq;
+		 // removed until we get new EDM that supports xAOD  ==> combinedTrk->setIDTrackElementLink( *elit );
+		 if ( msgLvl(MSG::DEBUG) ) msg()  << MSG::DEBUG << " MuonEF  - ID TrackParticle parameters are:  pt " << combinedTrk->getIDTrackParticle()->pt()
+				     << " MeV - eta " << combinedTrk->getIDTrackParticle()->eta()
+				     << " phi " <<  combinedTrk->getIDTrackParticle()->phi()<< endreq;
+		 foundellink=true;
+		 break;
+	       }
+	       
+	     }//ID ElementLink loop
+	     
+	     if(!foundellink) {
+	       msg() << MSG::WARNING << "Did not find matching EF ID track - cannot store in EDM" << endreq;
+	     }
+          }
+          tot_mdt = tot_mdt + pSummary->numMdtHits; 
+          tot_rpc = tot_rpc + pSummary->numRpcEtaHits + pSummary->numRpcPhiHits; 
+          tot_tgc = tot_tgc + pSummary->numTgcEtaHits + pSummary->numTgcPhiHits; 
+          tot_csc = tot_csc + pSummary->numCscEtaHits + pSummary->numCscPhiHits; 
+          tot_seg = tot_seg + pSummary->numMdtSegs + pSummary->numRpcSegs + pSummary->numTgcSegs
+                            + pSummary->numCscSegs + pSummary->numTgcRpcSegs;
+	  
+	  // xAOD::TrackParticle* etp2 = NULL; //new Rec::TrackParticle(*etp);
+	  // removed until we the migration to the new EDM is performed.  ==> eTrkParCont->push_back(etp2);	   
+	   //for perform
+         if(m_doNTuplePerformance)
+         {
+	      ++nMuons;
+	       // tan(x/2)=sqrt(1+cot**2)-cot
+	      double eta=-log(sqrt(1+(eTheta)*(eTheta))-(eTheta)); 
+	      StatusCode statusfill = m_pTrigMuGirlNtuple->fillReco(nMuons,ePhi,eTheta,eta,(1/ePt), (int)eCharge, NN[0], NN[1], NN[2], NN[3], NN[4], NN[5], pSummary->lhr, TrackIso, pSummary->innDelta );
+	      if (statusfill.isFailure())
+	      {
+	          msg() << MSG::ERROR << " Cannot fill NTuple Reco " << endreq;
+	          return HLT::BAD_JOB_SETUP;
+	      }
+	    
+	 } 
+
+      }
+   }
+
+   eMuoninfo->setNMdtHits(tot_mdt); 
+   eMuoninfo->setNRpcHits(tot_rpc); 
+   eMuoninfo->setNTgcHits(tot_tgc); 
+   eMuoninfo->setNCscHits(tot_csc); 
+   eMuoninfo->setNSegments(tot_seg); 
+  
+   status = attachFeature(outputTE, eMuonEFInfoCont,"eMuonEFInfo");
+   if(status != HLT::OK) 
+   {
+       msg() << MSG::WARNING << "Failed to attach TrigMuonEFInfoContainer." << endreq;
+       //     return status;
+   } 
+   else 
+   {
+       msg() << MSG::DEBUG << "Successfully attached to TEout a TrigMuonEFInfoContainer with size " << eMuonEFInfoCont->size() << endreq;
+   }
+
+
+   //for perform
+   if (m_doNTuplePerformance)
+   {
+       if (msg().level() <= MSG::DEBUG)
+           msg() << MSG::DEBUG << " Write Ntuple " << endreq;
+       StatusCode statusNT = m_pTrigMuGirlNtuple->writeRecord();
+       if (statusNT.isFailure() || m_pTrigMuGirlNtuple == NULL)
+       {
+	   msg() << MSG::ERROR << "TrigMuGirlFex::execute Cannot write NTuple" << endreq;
+	   //delete di_muon;
+	   return HLT::BAD_JOB_SETUP;
+       }
+   }
+
+
+   //attached ID track container
+   //   msg()<<MSG::DEBUG<<"number of eTrkParCont="<<eTrkParCont->size()<<endreq;
+   status = attachFeature(outputTE, eTrkParCont, "eGirlID");
+   if (status!= HLT::OK) 
+     {
+       msg() << MSG::WARNING << "Problems with attachFeature TrackParticles  Container"<< endreq;
+     }
+   else 
+     {
+       msg()<<MSG::DEBUG<<"attached GirlIDTrk container with size="<<eTrkParCont->size()<<endreq;
+     }
+
+
+   if (m_doParticleCreator && !summaryList.empty()) 
+   {
+       if (msg().level() <= MSG::DEBUG) 
+  	   msg()<< MSG::DEBUG << "Calling m_pParticleCreatorTool->fillContainer" << endreq; 
+       if (m_pParticleCreatorTool->fillContainer(&summaryList).isFailure()) 
+       {
+           for (MuGirlNS::CandidateSummaryList::iterator itSummary = summaryList.begin(); itSummary !=summaryList.end(); itSummary++)
+	   {
+	       delete *itSummary;
+	   }
+	   summaryList.clear();
+	   for (unsigned i = 0; i < m_caloParticles.size(); i++)
+	   {
+	       delete m_caloParticles[i];
+	   }
+	   m_caloParticles.clear();
+	   return StatusCode::RECOVERABLE;
+       }
+    }
+
+   msg() << MSG::DEBUG << "TrigMuGirl::clearing caloParticles" << endreq;
+
+   for (unsigned i = 0; i < m_caloParticles.size(); i++)
+   {
+      delete m_caloParticles[i];
+   }
+   m_caloParticles.clear();
+
+   //    msg() << MSG::DEBUG <<"muon_pT="<<muon_pT<< endreq;
+   //    msg() << MSG::DEBUG <<"muon_phi="<<muon_phi<< endreq;
+   //    msg() << MSG::DEBUG <<"muon_cotTh="<<muon_cotTh<< endreq;
+
+   // delete all m_sSegmentCollection
+   //   for (Trk::SegmentCollection::iterator segitr=m_pSegmentCollection->begin();segitr< m_pSegmentCollection->end(); segitr++)
+   //     {
+   //       delete *segitr;
+   //     }
+
+        
+
+   msg() << MSG::DEBUG << "TrigMuGirl::clearing summaries" << endreq;
+   for (MuGirlNS::CandidateSummaryList::iterator itSummary = summaryList.begin(); itSummary !=summaryList.end(); itSummary++)
+   {
+      if ((*itSummary)->startFromMF) delete *itSummary;  
+      else 
+      {
+         if ((*itSummary)->pRefittedTrack != NULL)
+            delete ((*itSummary)->pRefittedTrack)->track(); 
+         delete (*itSummary)->pRefittedTrack; 
+         if ((*itSummary)->pTrkRefitted != NULL)
+            delete (*itSummary)->pTrkRefitted;
+         delete *itSummary;
+      }
+   }
+ 
+   msg() << MSG::DEBUG << "TrigMuGirl::clearing segments" << endreq;
+   m_pSegmentManager->clear();
+   summaryList.clear();
+ 
+
+   if (msg().level() <= MSG::DEBUG)
+        msg() << MSG::DEBUG << "TrigMuGirl::execute done" << endreq;
+
+   if (doTiming()) 
+   {
+	m_timerExecTotal->stop();
+   }
+
+   return HLT::OK;
+}
+
+
+void TrigMuGirl::createCaloParticles()
+{
+    Amg::Vector3D pt_calo_local(0,0,0);
+
+    // out for timing
+    //    if (msg().level() <= MSG::DEBUG)
+    //        msg() << MSG::DEBUG << "createCaloParticles: Pre-selection from " << m_inDetTrackParticleLinks->size() << " particles." << endreq;
+
+    for (ElementLinkVector<xAOD::TrackParticleContainer>::const_iterator ipIt = m_inDetTrackParticleLinks.begin();
+            ipIt != m_inDetTrackParticleLinks.end();
+            ++ipIt)
+    {
+        if ( !ipIt->isValid() ) {
+            ATH_MSG_WARNING("Invalid EF ID TrackParticle ElementLink");
+            continue;
+        }
+
+        const xAOD::TrackParticle* tp_id = **ipIt;
+        const Trk::Perigee& pPerigee = tp_id->perigeeParameters();
+/*
+        if (pPerigee == NULL)
+        {
+            if (msg().level() <= MSG::DEBUG)
+                msg() << MSG::DEBUG << "Missing perigee" << endreq;
+            continue;
+        }
+*/
+        double px = pPerigee.momentum()[Trk::px];
+        double py = pPerigee.momentum()[Trk::py];
+        double pt = sqrt(px * px + py * py);
+
+        if (pt < m_ptLowerLimit)
+        {
+	  // out for riming
+	  //            if (msg().level() <= MSG::DEBUG)
+	  //                msg() << "pT=" << pPerigee->pT() << " is lower than limit = " << m_ptLowerLimit << ". Skipping track." << endreq;
+            continue;
+        }
+/*
+        if (tp_id->trackSummary() == NULL)
+        {
+            if (msg().level() <= MSG::DEBUG)
+                msg() << MSG::DEBUG << "Missing trackSummary" << endreq;
+            continue;
+        }
+*/
+        uint8_t pixel_hits = 0;
+        uint8_t sct_hits = 0;
+        tp_id->summaryValue(pixel_hits,xAOD::numberOfPixelHits);
+        tp_id->summaryValue(pixel_hits,xAOD::numberOfSCTHits);
+
+        int numhits_id = pixel_hits + sct_hits; 
+                         //tp_id->trackSummary()->get(Trk::numberOfPixelHits) + tp_id->trackSummary()->get(Trk::numberOfSCTHits);
+
+        if (numhits_id < 5)
+        {
+            if (msg().level() <= MSG::DEBUG)
+                msg() << MSG::DEBUG << "Cut on #hits=" << numhits_id << endreq;
+            continue;
+        }
+
+        bool seenByCalo = false;
+        if (m_pToCalo)
+        {
+            double offset = 0.;
+            const Trk::TrackParameters* calo_local = 0;
+            for (unsigned i = 0; i < m_caloLayers.size(); ++i)
+            {
+                if ( (calo_local = m_pToCalo->extrapolate(*(tp_id->track()), m_caloLayers[i],offset))!=0 ) {
+                    seenByCalo=true;
+                    pt_calo_local = calo_local->position();
+                }
+                //seenByCalo = m_pToCalo->TrackSeenByCalo(tp_id->originalTrack(), m_caloLayers[i], offset, &pt_calo_ctb, &pt_calo_local);
+                if (seenByCalo)
+                    break;
+            }
+        }
+        else
+            seenByCalo = true;
+        if (!seenByCalo)
+        {
+            if (msg().level() <= MSG::DEBUG)
+                msg() << MSG::DEBUG << "Not seen by calo" << endreq;
+            continue;
+        }
+
+	// out for timing
+	//        if (msg().level() <= MSG::DEBUG)
+	//            msg() << MSG::DEBUG << "This TrackParticle is seen by Calo!" << endreq;
+
+        CaloParticle* pParticle = new CaloParticle(tp_id, &pPerigee, pt_calo_local.eta(), pt_calo_local.phi());
+        m_caloParticles.push_back(pParticle);
+    }
+}
+
+void TrigMuGirl::IsolatedIdTracks(double dR)
+{
+    for (unsigned int i = 0; i < m_caloParticles.size(); i++)
+    {
+        CaloParticle* pParticle1 = m_caloParticles[i];
+        if (!pParticle1->isolated)
+            continue;
+        const xAOD::TrackParticle* tp1 = pParticle1->pTrackParticle;
+        const Trk::Perigee mp1 = tp1->perigeeParameters();
+        double phi1 = mp1.parameters()[Trk::phi];
+        double eta1 = asinh(1. / tan(mp1.parameters()[Trk::theta]));
+        for (unsigned int j = i + 1; j < m_caloParticles.size(); j++)
+        {
+            CaloParticle* pParticle2 = m_caloParticles[j];
+            if (!pParticle2->isolated)
+                continue;
+            const xAOD::TrackParticle* tp2 = pParticle2->pTrackParticle;
+            const Trk::Perigee mp2 = tp2->perigeeParameters();
+            double phi2 = mp2.parameters()[Trk::phi];
+            double eta2 = asinh(1. / tan(mp2.parameters()[Trk::theta]));
+            double deta = fabs(eta2 - eta1);
+            double dphi = fabs(phi2 - phi1);
+            if (dphi > M_PI)
+                dphi = 2 * M_PI - dphi;
+	    float dRmu=sqrt(deta * deta + dphi * dphi);
+            if (sqrt(deta * deta + dphi * dphi) < dR)
+            {
+                pParticle1->isolated = false;
+		if (pParticle1->dR > dRmu) pParticle1->dR = dRmu;
+                pParticle2->isolated = false;
+		if (pParticle2->dR > dRmu) pParticle2->dR = dRmu;
+            }
+        }
+    }
+}
+
+void TrigMuGirl::calculateLHR(CaloParticle* pParticle)
+{
+    const xAOD::TrackParticle* pTrackParticle = pParticle->pTrackParticle;
+    const Trk::Perigee pPerigee = pTrackParticle->perigeeParameters();
+    double charge_id = pTrackParticle->charge();
+    double qOverP_id = pPerigee.parameters()[Trk::qOverP];
+    double p_id      = fabs(1.0/qOverP_id);
+    double phi_id    = pPerigee.parameters()[Trk::phi];
+    double eta_id    = asinh(1./tan(pPerigee.parameters()[Trk::theta]));
+    double pt_id     = pPerigee.pT();
+
+    if (msg().level() <= MSG::DEBUG)
+        msg() << MSG::DEBUG << "Parameters of isolated tracks seen by calo: " <<
+        " pt =  " << pt_id  <<
+        " eta = " << eta_id <<
+        " phi = " << phi_id <<
+        " charge = " << charge_id << endreq;
+
+    double theLHR = m_pMuLHR->getLHR(m_pClusCollection, eta_id, p_id, pParticle->eta, pParticle->phi);
+    if (msg().level() <= MSG::DEBUG)
+        msg() << MSG::DEBUG << "theLHR = " << theLHR << endreq;
+
+    m_pCandidate->setIsolation(1);
+    m_pCandidate->setLHR(theLHR);
+}
+
+
+bool TrigMuGirl::generateMuGirl(MuGirlNS::CandidateSummary* summary)
+{
+    double eta = 999.;
+    //double pt = 0.;
+    if (summary->startFromMF)
+    {
+        if( summary->pMuonFeature != NULL)
+        {
+            eta = (summary->pMuonFeature)->eta();
+         //   pt = (summary->pMuonFeature)->pt();
+        }
+    }
+    else
+    {
+       Trk::Perigee seed_perigee = summary->pTrackParticle->perigeeParameters();
+       eta = asinh(1./tan(seed_perigee.parameters()[Trk::theta]));
+       //pt = (summary->pTrackParticle)->measuredPerigee()->pT();
+    }
+
+    if (fabs(eta)>2.0 && (summary->numMdtHits <= 2 && summary->numCscSegs == 0 && summary->numTgcEtaHits <= 2 && summary->numTgcPhiHits <= 2 ))
+        return false;
+    if (fabs(eta)<2.0 && summary->numMdtHits<=2)
+        return false;
+
+    if ((summary->innAngle == 999.) && (summary->midAngle == 999.))
+        return false;
+    double value[8];
+    double ANN[2];
+
+    msg()<<MSG::DEBUG<<"generateMuGirl LHR"<<summary->lhr<<"setting it to 0.8"<<endreq;
+    summary->lhr = 0.8;
+
+    m_pANNSelectionTool->evaluateANN(summary,value,ANN);
+    m_pCandidate->setAnn(ANN[0], ANN[1]);
+    summary->nnBarrel = ANN[0];
+    summary->nnEndCap = ANN[1];
+
+    msg() << MSG::DEBUG << " ANN [0] "<<value[0]<< " ANN [1] "<<value[1]<< " ANN [2] "<<value[2]<< " ANN [3] "<<value[3]<< " ANN [4] "<<value[4]<< " ANN [5] "<<value[5] << endreq;
+    //    msg() << MSG::DEBUG << "arikerez "<<value[0]<< " "<<value[1]<< " "<<value[2]<< " "<<value[3]<< " "<<value[4]<< " "<<value[5] << endreq;
+    if (m_doNTuplePerformance)
+      {
+	NN[0]=value[0];
+	NN[1]=value[1];
+	NN[2]=value[2];
+	NN[3]=value[3];
+	NN[4]=value[4];
+	NN[5]=value[5];
+      }
+
+    /*        
+    if (value[0]>0.08 || //0.004 ||    // BARREL GOOD  PT<10GeV
+	value[1]>0.11 || //0.004  ||    // BARREL BAD
+	value[2]>0.15 || //0.004 ||    // REGION OVERLAP
+            value[3]>0.004 ||     // MAGNET OVERLAP
+            value[4]>0.004 ||    // ENDCAP
+            value[5]>0.004 )      // FORWARD
+      {
+        msg()<<MSG::DEBUG<<"eTrigEFMuon pass=true"<<endreq;
+	summary->PassNNsel = true;
+	m_pCandidate->setPassANN(true);
+	return true;
+      }
+      else 
+	  {
+	  msg()<<MSG::DEBUG<<"eTrigEFMuon pass=false"<<endreq;
+	    summary->PassNNsel = false;
+	    m_pCandidate->setPassANN(false);
+	    return false;
+	  }
+    
+    */
+    
+    if (value[0]<0.2 && //0.004 ||    // BARREL GOOD  PT<10GeV
+        value[1]<0.2 && //0.004  ||    // BARREL BAD
+        value[2]<0.2 && //0.004 ||    // REGION OVERLAP
+        value[3]<0.2 &&     // MAGNET OVERLAP
+        value[4]<0.2 &&    // ENDCAP
+        value[5]<0.2 )      // FORWARD
+    {
+        summary->PassNNsel = false;
+	m_pCandidate->setPassANN(false);
+	return false;
+    }
+    else
+    {
+      summary->PassNNsel = true;
+      m_pCandidate->setPassANN(true);
+      return true;
+    }
+    
+}
+
+void TrigMuGirl::fillMuonSegmentColl(std::vector<const Muon::MuonSegment*> muonSegmentList)
+{
+    for (MuGirlNS::MuonSegmentList::const_iterator MuonSegItr=muonSegmentList.begin();  MuonSegItr!=muonSegmentList.end(); MuonSegItr++)
+    {
+        const Muon::MuonSegment* seg = *MuonSegItr;
+        //m_pSegmentCollection->push_back(const_cast <Muon::MuonSegment*>(seg));
+	m_pSegmentManager->setInStore(seg, false);
+    }
+}
+
+
+Rec::TrackParticle* TrigMuGirl::TEcreateParticle(const Trk::Track* track,const Trk::VxCandidate* vxCandidate,Trk::TrackParticleOrigin prtOrigin)
+ {
+     if (track == 0) return 0;
+     //     MsgStream log(msgSvc(), name());
+     const Trk::Perigee* aMeasPer(0);
+     
+     aMeasPer = dynamic_cast<const Trk::Perigee*>( track->perigeeParameters() );
+     aMeasPer = aMeasPer->clone(); 
+    if (aMeasPer==0) return 0;        
+ 
+     //Creating TrackParticle with a dummy TrackSummary
+     const Trk::TrackSummary* summary=new Trk::TrackSummary;
+     //     summary=new Trk::TrackSummary;
+                
+     // find the first and the last hit in track
+     // we do that the same way as in the track slimming tool!
+     // that way it is also ok on not slimmed tracks!
+     std::vector<const Trk::TrackParameters*> parameters;
+     
+     //     if (m_keepParameters)
+     {
+       const DataVector<const Trk::TrackStateOnSurface>* trackStates = track->trackStateOnSurfaces();
+       
+       const Trk::TrackParameters* first(0) ; 
+       
+       // search first valid TSOS first
+       for ( DataVector<const Trk::TrackStateOnSurface>::const_iterator itTSoS = trackStates->begin(); itTSoS != trackStates->end(); ++itTSoS)
+       {
+         if ( (*itTSoS)->type(Trk::TrackStateOnSurface::Measurement) && (*itTSoS)->trackParameters()!=0 && (*itTSoS)->measurementOnTrack()!=0 )
+         {
+             first = (*itTSoS)->trackParameters();
+             parameters.push_back((*itTSoS)->trackParameters()->clone());
+             break;
+         }
+       }
+         
+       // search last valid TSOS first
+       for ( DataVector<const Trk::TrackStateOnSurface>::const_reverse_iterator rItTSoS = trackStates->rbegin(); rItTSoS != trackStates->rend(); ++rItTSoS)
+       {
+         if ( (*rItTSoS)->type(Trk::TrackStateOnSurface::Measurement) && (*rItTSoS)->trackParameters()!=0 && (*rItTSoS)->measurementOnTrack()!=0 )
+         {
+             if (!(first == (*rItTSoS)->trackParameters())) parameters.push_back((*rItTSoS)->trackParameters()->clone());
+             break;
+         }
+       }
+       
+       // security check:
+       if (parameters.size() > 2) msg() << MSG::WARNING << "More than two additional track parameters to be stored in TrackParticle!" << endreq;
+     }   
+     const Trk::FitQuality* fitQuality = new Trk::FitQuality( (*track->fitQuality()) );
+     return new Rec::TrackParticle(track, prtOrigin, vxCandidate, summary, parameters, aMeasPer,  fitQuality);
+ }
+
+
+// for perfo ntuple
+HLT::ErrorCode TrigMuGirl::doMuTruthPerformance()
+{
+    int nTruthMu = 0;
+    const McEventCollection* pMcEventCollection = NULL;
+    StatusCode status = m_pEventStore->retrieve(pMcEventCollection, "TruthEvent");
+    if (status.isFailure() || pMcEventCollection == NULL)
+    {
+      msg() << MSG::WARNING << " Cannot retrieve McEventCollection " << endreq;
+      return HLT::SG_ERROR;
+    }
+
+    McEventCollection::const_iterator itMc = pMcEventCollection->begin(), itMc_e = pMcEventCollection->end();
+    for (; itMc != itMc_e; ++itMc)
+      {
+        const HepMC::GenEvent* pGenEvent = *itMc;
+
+	HepMC::GenEvent::particle_const_iterator itPart = pGenEvent->particles_begin(), itPart_e = pGenEvent->particles_end();
+        for (; itPart != itPart_e; ++itPart)
+	  {
+            const HepMC::GenParticle* pPart = *itPart;
+
+            if (pPart->pdg_id() == -13 || pPart->pdg_id() == 13)
+	      {
+                int parent_pdg = 0;
+                if (pPart->production_vertex() != NULL)
+		  {
+		    HepMC::GenVertex::particle_iterator itVxPart = pPart->production_vertex()->particles_begin(HepMC::parents), itVxPart_e = pPart->production_vertex()->particles_end(HepMC::parents);
+                    for (; itVxPart != itVxPart_e; ++itVxPart)
+		      {
+                        parent_pdg = (*itVxPart)->pdg_id();
+		      }
+		  }
+
+                ++nTruthMu;
+                if (m_doNTuplePerformance)
+		  {
+		    double cot=1/tan(2*atan(exp(-pPart->momentum().eta())));
+
+                    status = m_pTrigMuGirlNtuple->fillTruth(nTruthMu,
+                                                        pPart->momentum().phi(),
+                                                        cot,
+                                                        pPart->momentum().eta(),
+                                                        pPart->momentum().perp(),
+                                                        pPart->pdg_id(),
+							    parent_pdg);
+                    if (status.isFailure())
+                    {
+		      msg() << MSG::ERROR << " Cannot fill NTuple TRUTH " << endreq;
+		      //delete di_muon; 
+		      return HLT::BAD_JOB_SETUP;
+                    }
+		  }
+	      }
+	  }
+      }
+    return HLT::OK;
+}
+
+
+//** ----------------------------------------------------------------------------------------------------------------- **//
diff --git a/Trigger/TrigAlgorithms/TrigMuGirl/src/TrigMuGirlAlg.cxx b/Trigger/TrigAlgorithms/TrigMuGirl/src/TrigMuGirlAlg.cxx
new file mode 100644
index 00000000000..421a786422c
--- /dev/null
+++ b/Trigger/TrigAlgorithms/TrigMuGirl/src/TrigMuGirlAlg.cxx
@@ -0,0 +1,208 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+/***************************************************************************
+    Authors: E. Reinherz-Aronis, A. Kreisel 
+             based on MuGirl by Shlomit Tarem
+***************************************************************************/
+#include "TrigInterfaces/AlgoConfig.h"
+#include "TrigNavigation/TriggerElement.h"
+#include "TrigNavigation/Navigation.h"
+#include "TrigSteeringEvent/TrigRoiDescriptor.h"
+
+#ifdef HAVE_NEW_IOSTREAMS
+#include <iostream>
+#include<iomanip>
+#else
+#include <iostream.h>
+#include<iomanip>
+#endif
+
+#include "CLHEP/Units/SystemOfUnits.h"
+#include "CLHEP/Vector/LorentzVector.h"
+#include "GaudiKernel/NTuple.h"
+
+#include "TrigMuGirl/TrigMuGirlAlg.h"
+
+#include "TrigMuonToolInterfaces/ITrigMuGirlTool.h"
+#include "xAODCaloEvent/CaloClusterContainer.h"
+
+#include "xAODTracking/TrackParticleContainer.h"
+#include "xAODTracking/TrackParticleAuxContainer.h"
+
+
+
+TrigMuGirlAlg::TrigMuGirlAlg(const std::string& name, ISvcLocator* pSvcLocator) :
+  HLT::FexAlgo(name, pSvcLocator),
+  m_trigMuGirlTool("TrigMuGirlTool/TrigMuGirlTool"),  
+  m_particleCreatorTool("TrackToTrackParticleConvTool"),
+  m_idTrackParticlesName("InDetTrigParticleCreation_Muon_EFID"),
+  m_doMuonFeature(false),
+  m_eMuonEFInfoCont(0),
+  m_eTrkParCont(0)
+{
+  
+  // configure property values
+  declareProperty("TrigMuGirlTool",          m_trigMuGirlTool);  
+  declareProperty("doMuonFeature",           m_doMuonFeature);
+  declareProperty("IdTrackParticles",        m_idTrackParticlesName);
+  declareProperty("ParticleCreatorTool",     m_particleCreatorTool);
+  
+}
+
+//** ----------------------------------------------------------------------------------------------------------------- **//
+
+TrigMuGirlAlg::~TrigMuGirlAlg() 
+{
+  
+}
+
+
+//** ----------------------------------------------------------------------------------------------------------------- **//
+
+
+HLT::ErrorCode TrigMuGirlAlg::hltInitialize() {
+  
+  if (msgLvl() <= MSG::DEBUG) 
+    msg() << MSG::DEBUG << "Initializing TrigMuGirl " << endreq;    
+
+  
+  if (m_particleCreatorTool.retrieve().isFailure()) {
+    msg() << MSG::ERROR << "Cannot retrieve the ParticleCreator Tool" << endreq;
+    return StatusCode::FAILURE;
+  }
+
+  if (retrieve(m_trigMuGirlTool).isFailure()) {
+    msg()<<MSG::ERROR<<"no m_trigMuGirlTool"<<endreq;    
+    return StatusCode::RECOVERABLE;
+  }
+  
+  m_trigMuGirlTool->declareMonitoringVariables(this,m_TrigMuGirlMonVars);
+  if (doTiming()) m_trigMuGirlTool->addTimers(this,m_TrigMuGirlTimers);
+  m_trigMuGirlTool->initNtuple(this);
+
+  if (msgLvl() <= MSG::DEBUG) 
+    msg() << MSG::DEBUG << "Initializing TrigMuGirl done successfully" << endreq;    
+  return HLT::OK;
+}
+
+
+//** ----------------------------------------------------------------------------------------------------------------- **//
+
+
+HLT::ErrorCode TrigMuGirlAlg::hltFinalize() {
+
+  if (msgLvl() <= MSG::INFO) 
+    msg() << MSG::INFO << "Finalizing TrigMuGirl" << endreq;
+
+  return HLT::OK;
+}
+
+//** ----------------------------------------------------------------------------------------------------------------- **//
+
+
+HLT::ErrorCode TrigMuGirlAlg::hltExecute(const HLT::TriggerElement* inputTE, HLT::TriggerElement* outputTE) {
+
+        
+  if ( msgLvl() <= MSG::DEBUG ) 
+    msg()<<MSG::DEBUG<<"Executing "<<name()<<" for types "
+	 <<inputTE->getId()<<" -> "<<outputTE->getId()<<endreq;
+  
+  m_trigMuGirlTool->initRoiProcessing(m_TrigMuGirlTimers,m_eMuonEFInfoCont);
+
+  HLT::ErrorCode status;
+
+  if (m_doMuonFeature)
+    {
+      std::vector<const MuonFeature*> vectorOfMuonFeature;
+      status = getFeatures(inputTE, vectorOfMuonFeature, "");
+      if (status != HLT::OK)
+        goto IDtrack;
+
+      ElementLink<CombinedMuonFeatureContainer> CombinedMuonFeatureEL;
+      getFeatureLink<CombinedMuonFeatureContainer, CombinedMuonFeature>(inputTE, CombinedMuonFeatureEL);
+     
+      status = m_trigMuGirlTool->processMuonFeatures(vectorOfMuonFeature, CombinedMuonFeatureEL);
+      if (status != HLT::OK) {
+	return status;
+      }
+    }   //if doMuonFeature
+
+ IDtrack:
+
+  // get element links to the ID tracks
+  ElementLinkVector<Rec::TrackParticleContainer> elv_idtrks;
+  if( HLT::OK != getFeaturesLinks<Rec::TrackParticleContainer,Rec::TrackParticleContainer>(inputTE, elv_idtrks, m_idTrackParticlesName) ) {
+    msg() << MSG::WARNING << "Failed to get ElementLinkVector<xAOD::TrackParticleContainer>, aborting this ROI" << endreq;
+    return HLT::MISSING_FEATURE;
+  }
+
+  std::vector<const xAOD::CaloClusterContainer*> vectorOfClusterContainers;
+  if(getFeatures(inputTE, vectorOfClusterContainers,"HLT")!=HLT::OK) 
+    {
+      if(msgLvl() <= MSG::WARNING) msg() << MSG::WARNING << "Failed to get ClusterContainers" << endreq;
+    }
+
+
+  /** Trasform the input TrackParticle into xAOD::Trackparticles */
+  ElementLinkVector<xAOD::TrackParticleContainer> idSeeds;
+/*
+  xAOD::TrackParticleContainer*    idTrackParticles = new xAOD::TrackParticleContainer();
+  xAOD::TrackParticleAuxContainer* idTrackParticlesAuxCont = new xAOD::TrackParticleAuxContainer();
+  idTrackParticles->setStore( idTrackParticlesAuxCont );
+  int itrack=0;
+  for (ElementLinkVector<Rec::TrackParticleContainer>::const_iterator ipIt = elv_idtrks.begin();ipIt != elv_idtrks.end();) {
+      for 
+      /// Use ElementLink so the xAOD::TrackParticle has a link back to the Trk::Track
+      const ElementLink<TrackCollection> trackLink(*ipIt, itrack);
+      ATH_MSG_VERBOSE("Create xAOD track particle for tract with pt " << (*trackLink)->perigeeParameters()->pT());
+
+      xAOD::TrackParticle* trackparticle = m_particleCreatorTool->createParticle( trackLink, idTrackParticles, 0, xAOD::muon);
+      ATH_MSG_VERBOSE("Created xAOD TrackParticle pointer " << trackparticle << ", container size = " << idTrackParticles->size());
+      ATH_MSG_VERBOSE("pt, eta, phi, m = " << trackparticle->pt() << ", " << trackparticle->eta() << ", " << trackparticle->phi() << ", " << trackparticle->m() << " valid trk link = " << trackparticle->track().isValid());  
+      idSeeds.push_back(idTrackParticles->at(itrack));
+      itrack++;
+  }
+*/
+  /** Process the Inner detector seeds */
+  status = m_trigMuGirlTool->processTrackCollections(idSeeds,vectorOfClusterContainers);
+  if (status!=HLT::OK) return status;
+   
+  m_eMuonEFInfoCont = new TrigMuonEFInfoContainer();
+  m_trigMuGirlTool->finalizeRoiProcessing(m_TrigMuGirlTimers,m_eMuonEFInfoCont,m_eTrkParCont,m_TrigMuGirlMonVars);
+   
+  status = attachFeature(outputTE, m_eMuonEFInfoCont,"eMuonEFInfo");
+  if(status != HLT::OK) 
+    {
+      msg() << MSG::WARNING << "Failed to attach TrigMuonEFInfoContainer." << endreq;
+      delete m_eMuonEFInfoCont;
+      m_eMuonEFInfoCont = 0;
+      //     return status;
+    } 
+  else 
+    {
+      msg() << MSG::DEBUG << "Successfully attached to TEout a TrigMuonEFInfoContainer with size " << m_eMuonEFInfoCont->size() << endreq;
+    }
+
+
+  //attached ID track container
+  //   msg()<<MSG::DEBUG<<"number of eTrkParCont="<<m_eTrkParCont->size()<<endreq;
+  status = attachFeature(outputTE, m_eTrkParCont, "eGirlID");
+  if (status!= HLT::OK) 
+    {
+      msg() << MSG::WARNING << "Problems with attachFeature TrackParticles  Container"<< endreq;
+    }
+  else 
+    {
+      msg()<<MSG::DEBUG<<"attached GirlIDTrk container with size="<<m_eTrkParCont->size()<<endreq;
+    }
+
+  ///delete idTrackParticles;
+  ///delete idTrackParticlesAuxCont;
+
+  if (msg().level() <= MSG::DEBUG)
+    msg() << MSG::DEBUG << "TrigMuGirlAlg::execute done" << endreq;
+
+  return HLT::OK;
+}
diff --git a/Trigger/TrigAlgorithms/TrigMuGirl/src/TrigMuGirlNtuple.cxx b/Trigger/TrigAlgorithms/TrigMuGirl/src/TrigMuGirlNtuple.cxx
new file mode 100644
index 00000000000..fafb5ccf794
--- /dev/null
+++ b/Trigger/TrigAlgorithms/TrigMuGirl/src/TrigMuGirlNtuple.cxx
@@ -0,0 +1,178 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+/*----------------------------------------
+        Authors: Arik Kreisel & Erez Ra
+------------------------------------------*/
+#include "GaudiKernel/ISvcLocator.h"
+#include "GaudiKernel/IDataProviderSvc.h" 
+#include "TrigMuGirl/TrigMuGirl.h"
+#include "TrigMuGirl/TrigMuGirlNtuple.h"
+#include <math.h>
+
+TrigMuGirlNtuple::TrigMuGirlNtuple(HLT::FexAlgo* pTrigMuGirl, INTupleSvc* pNTupleSvc):
+m_max_pair    (100),
+m_max_dig     (200),
+m_max_idtrack (200),
+m_maxTruthMuons(200),
+m_pTrigMuGirl(pTrigMuGirl),
+m_pNtuple     (NULL),
+m_pNTupleSvc  (pNTupleSvc)
+{}
+
+StatusCode TrigMuGirlNtuple::book(const std::string& ntupleName, const std::string& ntupleTitle)
+{
+    MsgStream log(m_pTrigMuGirl->messageService(), m_pTrigMuGirl->name());
+    log << MSG::INFO << " CandidateNtuple initialization" << endreq;
+
+    m_ntupleName = ntupleName;
+    m_pNtuple = m_pNTupleSvc->book(m_ntupleName, CLID_ColumnWiseTuple, ntupleTitle);
+    if (m_pNtuple == NULL)
+    {
+        log << MSG::ERROR << " Cannot book Ntuple " << endreq;
+        return StatusCode::FAILURE;
+    }
+    if ( m_pNtuple->addItem("TRIGMUGIRL/NumTruthMuon",     m_NumTruthMuon, 0, m_maxTruthMuons).isFailure() ||
+         m_pNtuple->addItem("TRIGMUGIRL/TruthMuPt" ,       m_NumTruthMuon, m_TruthMuonPt).isFailure()||
+         m_pNtuple->addItem("TRIGMUGIRL/TruthMuPhi" ,      m_NumTruthMuon, m_TruthMuonPhi).isFailure()||
+         m_pNtuple->addItem("TRIGMUGIRL/TruthMuCot" ,      m_NumTruthMuon, m_TruthMuonCot).isFailure()||
+         m_pNtuple->addItem("TRIGMUGIRL/TruthMuEta" ,      m_NumTruthMuon, m_TruthMuonEta).isFailure()||
+         m_pNtuple->addItem("TRIGMUGIRL/TruthMuPdg" ,      m_NumTruthMuon, m_TruthMuonPdg).isFailure()||
+         m_pNtuple->addItem("TRIGMUGIRL/TruthMuParentPdg" ,m_NumTruthMuon, m_TruthMuonParentPdg).isFailure())
+    {
+        log << MSG::ERROR << "Cannot addItem(Truth Muons)" << endreq;
+        return StatusCode::FAILURE;
+    }
+
+    if (  m_pNtuple->addItem("TRIGMUGIRL/NumRecoMuon",     m_NumRecoMuon, 0, m_maxTruthMuons).isFailure() ||
+         m_pNtuple->addItem("TRIGMUGIRL/RecoMuPt" ,       m_NumRecoMuon, m_RecoMuonPt).isFailure()||
+         m_pNtuple->addItem("TRIGMUGIRL/RecoMuPhi" ,      m_NumRecoMuon, m_RecoMuonPhi).isFailure()||
+         m_pNtuple->addItem("TRIGMUGIRL/RecoMuCot" ,      m_NumRecoMuon, m_RecoMuonCot).isFailure()||
+         m_pNtuple->addItem("TRIGMUGIRL/RecoMuEta" ,      m_NumRecoMuon, m_RecoMuonEta).isFailure()||
+	  m_pNtuple->addItem("TRIGMUGIRL/RecoMuCharge" ,      m_NumRecoMuon, m_RecoMuonCharge).isFailure()||
+	  m_pNtuple->addItem("TRIGMUGIRL/RecoMuNN0" ,      m_NumRecoMuon, m_RecoMuonNN0).isFailure()||
+	  m_pNtuple->addItem("TRIGMUGIRL/RecoMuNN1" ,      m_NumRecoMuon, m_RecoMuonNN1).isFailure()||
+	  m_pNtuple->addItem("TRIGMUGIRL/RecoMuNN2" ,      m_NumRecoMuon, m_RecoMuonNN2).isFailure()||
+	  m_pNtuple->addItem("TRIGMUGIRL/RecoMuNN3" ,      m_NumRecoMuon, m_RecoMuonNN3).isFailure()||
+	  m_pNtuple->addItem("TRIGMUGIRL/RecoMuNN4" ,      m_NumRecoMuon, m_RecoMuonNN4).isFailure()||
+	  m_pNtuple->addItem("TRIGMUGIRL/RecoMuNN5" ,      m_NumRecoMuon, m_RecoMuonNN5).isFailure()||
+	  m_pNtuple->addItem("TRIGMUGIRL/RecoLHR" ,      m_NumRecoMuon, m_RecoMuonLHR).isFailure()||
+	  m_pNtuple->addItem("TRIGMUGIRL/RecoIso" ,      m_NumRecoMuon, m_RecoMuonIso).isFailure()||
+	  m_pNtuple->addItem("TRIGMUGIRL/RecodR" ,      m_NumRecoMuon, m_RecoMuondR).isFailure())
+    {
+        log << MSG::ERROR << "Cannot addItem(Reco Muons)" << endreq;
+        return StatusCode::FAILURE;
+    }
+
+    if (  m_pNtuple->addItem("TRIGMUGIRL/Event",  m_Event).isFailure() ||
+	  m_pNtuple->addItem("TRIGMUGIRL/Run",  m_Run).isFailure()) 
+    {
+        log << MSG::ERROR << "Cannot addItem(event number)" << endreq;
+        return StatusCode::FAILURE;
+    }
+
+
+
+    return StatusCode::SUCCESS;
+}
+
+
+StatusCode TrigMuGirlNtuple::writeRecord()
+{
+    return m_pNTupleSvc->writeRecord(m_ntupleName);
+}
+StatusCode TrigMuGirlNtuple::fillEvent(int event, int run)
+{
+  MsgStream log(m_pTrigMuGirl->messageService(), m_pTrigMuGirl->name());
+  if (log.level() <= MSG::DEBUG)
+    log << MSG::INFO << "TrigMuGirlNtuple::fillEvent(" << event << ")" << endreq;
+	
+  m_Event=event;
+  m_Run=run;
+
+  if (log.level() <= MSG::DEBUG)
+    log << MSG::INFO << "TrigMuGirlNtuple::fillTruth done" << endreq;
+  
+return StatusCode::SUCCESS;
+
+}
+
+StatusCode TrigMuGirlNtuple::fillTruth(int nMu, double phi, double cot, double eta, double pt, int pdg, int parentPdg)
+{
+        MsgStream log(m_pTrigMuGirl->messageService(), m_pTrigMuGirl->name());
+        if (log.level() <= MSG::DEBUG)
+            log << MSG::INFO << "TrigMuGirlNtuple::fillTruth(" << nMu << ")" << endreq;
+
+        if (nMu > m_maxTruthMuons)
+            return StatusCode::FAILURE;
+
+        m_NumTruthMuon = nMu;
+        m_TruthMuonPt       [nMu-1] = pt;
+        m_TruthMuonCot      [nMu-1] = cot;
+        m_TruthMuonEta      [nMu-1] = eta;
+        m_TruthMuonPhi      [nMu-1] = phi;
+        m_TruthMuonPdg      [nMu-1] = pdg;
+        m_TruthMuonParentPdg[nMu-1] = parentPdg;
+
+	//        log << MSG::DEBUG << " m_NumTruthMuon = " << m_NumTruthMuon <<
+	//                             " m_TruthMuonPt = " << m_TruthMuonPt[nMu-1] <<
+	//                             " m_TruthMuonEta = " << m_TruthMuonEta[nMu-1] <<
+	//                             " m_TruthMuonPhi = " << m_TruthMuonPhi[nMu-1] <<
+	//                             " m_TruthMuonPdg = " << m_TruthMuonPdg[nMu-1] <<
+	//                             " m_TruthMuonParentPdg = " << m_TruthMuonParentPdg[nMu-1] << endreq;
+
+        if (log.level() <= MSG::DEBUG)
+            log << MSG::INFO << "TrigMuGirlNtuple::fillTruth done" << endreq;
+        return StatusCode::SUCCESS;
+}
+
+StatusCode TrigMuGirlNtuple::fillReco(int nMu, double phi, double cot, double eta, double pt, int charge, float NN0, float NN1, float NN2, float NN3, float NN4, float NN5, float LHR, float Iso ,float dR)
+{
+        MsgStream log(m_pTrigMuGirl->messageService(), m_pTrigMuGirl->name());
+        if (log.level() <= MSG::DEBUG)
+            log << MSG::INFO << "TrigMuGirlNtuple::fillReco(" << nMu << ")" << endreq;
+
+	//        log << MSG::DEBUG << " nMu= " << nMu <<
+	//                             " pt = " << pt <<
+	//                             " eta = " << eta <<
+	//                             " phi = " << phi <<
+	//                             " charge = " << charge << 
+	//                             " NN0 = " << NN0 <<
+	//                             " NN1 = " << NN1 <<
+	//                             " NN2 = " << NN2 <<
+	//                             " NN3 = " << NN3 <<
+	//                             " NN4 = " << NN4 <<
+	//                             " NN5 = " << NN5 <<
+	//                             " m_maxTruthMuons = " << m_maxTruthMuons <<endreq;
+
+        if (nMu > m_maxTruthMuons)
+            return StatusCode::FAILURE;
+
+        m_NumRecoMuon = nMu;
+        m_RecoMuonPt       [nMu-1] = pt;
+        m_RecoMuonEta      [nMu-1] = eta;
+        m_RecoMuonCot      [nMu-1] = cot;
+        m_RecoMuonPhi      [nMu-1] = phi;
+        m_RecoMuonCharge   [nMu-1] = charge;
+	m_RecoMuonNN0      [nMu-1] = NN0;
+	m_RecoMuonNN1      [nMu-1] = NN1;
+	m_RecoMuonNN2      [nMu-1] = NN2;
+	m_RecoMuonNN3      [nMu-1] = NN3;
+	m_RecoMuonNN4      [nMu-1] = NN4;
+	m_RecoMuonNN5      [nMu-1] = NN5;
+	m_RecoMuonLHR      [nMu-1] = LHR;
+	m_RecoMuonIso      [nMu-1] = Iso;
+	m_RecoMuondR       [nMu-1] = dR;
+
+	//        log << MSG::DEBUG << " m_NumRecoMuon = " << m_NumRecoMuon <<
+	//                             " m_RecoMuonPt = " << m_RecoMuonPt[nMu-1] <<
+	//                             " m_RecoMuonEta = " << m_RecoMuonEta[nMu-1] <<
+	//                             " m_RecoMuonPhi = " << m_RecoMuonPhi[nMu-1] <<
+	//                             " m_RecoMuonCharge = " << m_RecoMuonCharge[nMu-1] << endreq;
+
+        if (log.level() <= MSG::DEBUG)
+            log << MSG::INFO << "TrigMuGirlNtuple::fillReco done" << endreq;
+        return StatusCode::SUCCESS;
+
+}
diff --git a/Trigger/TrigAlgorithms/TrigMuGirl/src/TrigMuGirlTool.cxx b/Trigger/TrigAlgorithms/TrigMuGirl/src/TrigMuGirlTool.cxx
new file mode 100644
index 00000000000..1a5a1b2cd58
--- /dev/null
+++ b/Trigger/TrigAlgorithms/TrigMuGirl/src/TrigMuGirlTool.cxx
@@ -0,0 +1,1637 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+/***************************************************************************
+    Authors: E. Reinherz-Aronis, A. Kreisel 
+             based on MuGirl by Shlomit Tarem
+***************************************************************************/
+#include "TrigMuGirl/TrigMuGirlTool.h"
+
+#include "TrigInterfaces/AlgoConfig.h"
+#include "TrigNavigation/TriggerElement.h"
+#include "TrigNavigation/Navigation.h"
+#include "TrigSteeringEvent/TrigRoiDescriptor.h"
+
+#include <iostream>
+#include<iomanip>
+
+#include "CLHEP/Units/SystemOfUnits.h"
+#include "CLHEP/Vector/LorentzVector.h"
+#include "GaudiKernel/NTuple.h"
+
+#include "TrigMuGirl/TrigMuGirl.h"
+#include "MuGirlInterfaces/ICandidateTool.h"
+#include "MuGirlInterfaces/CandidateSummary.h"
+#include "MuGirlInterfaces/IPerformanceTruthTool.h"
+#include "MuGirlInterfaces/IGlobalFitTool.h"
+#include "MuGirlInterfaces/IANNSelectionTool.h"
+#include "MuGirlInterfaces/IMuGirlParticleCreatorTool.h"
+#include "MuGirlInterfaces/IStauTool.h"
+#include "MuGirlInterfaces/SegmentManager.h"
+#include "MuGirlInterfaces/RpcSegmentInfo.h"
+
+#include "StoreGate/StoreGateSvc.h"
+#include "MuonReadoutGeometry/MuonDetectorManager.h"
+#include "RegionSelector/IRegSelSvc.h"
+
+#include "MuonRecToolInterfaces/IMuonClusterOnTrackCreator.h"
+#include "MuonRecToolInterfaces/IMdtDriftCircleOnTrackCreator.h"
+
+#include "TrkTrack/TrackCollection.h"
+#include "MuonRecToolInterfaces/IMuonSegmentMaker.h"
+#include "TrkExInterfaces/IIntersector.h"
+#include "TrkExUtils/TrackSurfaceIntersection.h"
+
+#include "EventInfo/EventInfo.h"
+#include "EventInfo/EventID.h"
+
+#include "RecoToolInterfaces/IExtrapolateToCaloTool.h"
+#include "ICaloTrkMuIdTools/ICaloMuonLikelihoodTool.h"
+#include "CaloEvent/CaloClusterContainer.h"
+
+#include "Particle/TrackParticleContainer.h"
+#include "xAODTracking/TrackParticle.h"
+
+#include "MuGirlInterfaces/MdtSegmentMakerInfo.h"
+
+#include "TrigMuonEvent/MuonFeature.h"
+#include "TrigMuonEvent/CombinedMuonFeature.h"
+#include "TrigMuonEvent/CombinedMuonFeatureContainer.h"
+#include "TrigMuonEvent/TrigMuonEFInfoContainer.h"
+#include "TrigMuonEvent/TrigMuonEFInfo.h"
+
+// for performance 
+#include "TrigMuGirl/TrigMuGirlNtuple.h"
+#include "GeneratorObjects/McEventCollection.h"
+#include "MagFieldInterfaces/IMagFieldSvc.h"
+
+using HepGeom::Point3D;
+using CLHEP::Hep3Vector;
+using CLHEP::GeV;
+
+//________________________________________________________________________
+TrigMuGirlTool::TrigMuGirlTool(const std::string& type,
+			       const std::string& name,
+			       const IInterface* parent)
+  : AthAlgTool(type,name,parent),
+    m_ptLowerLimit(2.5*GeV),
+    m_ntupleName("/NTUPLES/MUGIRL/MUGIRL"),
+    m_ntupleTitle("Muon Candidates"),
+    m_roadDeltaPhi(0.2),
+    m_doNTuple(false),
+    m_doLHR(false),
+    m_doCSC(false),
+    m_barrelNNCut(0.4),
+    m_endcapNNCut(0.4),
+    m_sSegmentCollection("MuGirlSegments"),
+    m_sRefittedTrkCollection("MuGirlRefittedTracks"),
+    m_RefittedTrkLocation("MuGirlRefittedTrackParticles"),
+    m_inDetParticlesLocation("TrackParticleCandidate"),
+    m_CaloCollection("CaloTopoCluster"),
+    m_doStau(false),
+    m_stauPtCut(20000.0),
+    m_mfPtCut(20000.0),
+    m_pSegmentCollection(NULL),
+    m_pRefittedTrkContainer(NULL),
+    m_applyLHR("On"),
+    m_idR(0.3),
+    m_lhr(0.8),
+    m_eOverP(0.3),
+    m_doTruth(false),
+    m_doGlobalFit(true),
+    m_doSAFit(false),
+    m_doMuonFeature(false),
+    m_doANNSelection(true),
+    m_doParticleCreator(false),
+    m_pClusCollection(NULL),
+    m_pCandNTuple(NULL),
+    // Tool names
+    m_pEventInfo(NULL),
+    m_pEventStore("StoreGateSvc", name),
+    m_pCandidate("MuGirlNS::CandidateTool"),
+    m_pToCalo("ExtrapolateToCaloTool/ExtrapolateToCaloTool"),
+    m_pMuLHR("CaloMuonLikelihoodTool"),
+    m_pTruthTool("MuGirlNS::PerformanceTruthTool",0),                 // make this a public tool
+    m_pGlobalFitTool("MuGirlNS::GlobalFitTool",0),                    // make this a public tool
+    m_pMuonFeatureGlobalFitTool("MuGirlNS::GlobalFitTool",0),         // make this a public tool
+    m_pANNSelectionTool("MuGirlNS::ANNSelectionTool",0),              // make this a public tool
+    m_pParticleCreatorTool("MuGirlNS::MuGirlParticleCreatorTool",0),  // make this a public tool
+    m_pStauTool("MuGirlNS::StauTool",0),                              // make this a public tool
+    m_magFieldSvc("MagField::AtlasFieldSvc/AtlasFieldSvc",name),
+    m_pSegmentManager(NULL),
+    // for perform
+    m_pTrigMuGirlNtuple(NULL),
+    m_ntupleNamePerformance("/NTUPLES/TRIGMUGIRL/TRIGMUGIRL"),
+    m_ntupleTitlePerformance("TrigMuGirlPer"),
+    m_doNTuplePerformance(false),
+    m_roi(0) 
+{
+
+  declareInterface<ITrigMuGirlTool>(this);
+
+  declareProperty("PtLowerLimit",                 m_ptLowerLimit);
+  declareProperty("NtupleName",                   m_ntupleName);
+  declareProperty("NtupleTitle",                  m_ntupleTitle);
+  declareProperty("RoadDeltaPhi",                 m_roadDeltaPhi);
+  declareProperty("doNTuple",                     m_doNTuple);
+  declareProperty("doLHR",                        m_doLHR);
+  declareProperty("doCSC",                        m_doCSC);
+  declareProperty("BarrelNNCut",                  m_barrelNNCut);
+  declareProperty("EndcapNNCut",                  m_endcapNNCut);
+  declareProperty("SegmentCollection",            m_sSegmentCollection);
+  declareProperty("RefittedTrkCollection",        m_sRefittedTrkCollection);
+  declareProperty("RefittedTrkLocation",          m_RefittedTrkLocation);
+  declareProperty("InDetTrackParticlesLocation",  m_inDetParticlesLocation);
+  declareProperty("doStau",                       m_doStau);
+  declareProperty("StauPtCut",                    m_stauPtCut);
+  declareProperty("MFPtCut",                    m_mfPtCut);
+  declareProperty("IdConeR",                      m_idR);
+  declareProperty("LHRValue",                     m_lhr);
+  declareProperty("eCaloOverPCut",                m_eOverP);
+  declareProperty("InCaloCollection",             m_CaloCollection);
+  declareProperty("doTruth",                      m_doTruth);
+  declareProperty("doGlobalFit",                  m_doGlobalFit);
+  declareProperty("doSAFit",                      m_doSAFit);
+  declareProperty("doANNSelection",               m_doANNSelection);
+  declareProperty("doParticleCreator",            m_doParticleCreator);
+  // Tools
+  // in the old ver there was no
+  declareProperty("StoreGateSvc",                 m_pEventStore);
+  declareProperty("MuGirlCandidate",              m_pCandidate);
+  declareProperty("MuGirlGlobalFIT",              m_pGlobalFitTool);
+  declareProperty("MuGirlGlobalStauFIT",          m_pStauGlobalFitTool);
+  declareProperty("MuGirlGlobalMuonFeatureFIT",   m_pMuonFeatureGlobalFitTool);
+  declareProperty("ExtrapolTrackToCaloTool",      m_pToCalo);
+  declareProperty("CaloMuonLikelihoodTool",       m_pMuLHR);
+  //    declareProperty("TrackParticleCreatorTool", m_particleCreatorTool);
+  //<S>
+  declareProperty("MuGirlStauTool",               m_pStauTool);
+  declareProperty("PerformanceTruthTool",         m_pTruthTool);
+  declareProperty("ANNSelectionTool",             m_pANNSelectionTool);
+  declareProperty("MuGirlParticleCreatorTool",             m_pParticleCreatorTool);
+  // varibles for monitor
+  //    declareMonitoredStdContainer ("MuonsPt", pt);
+  //    declareMonitoredStdContainer ("MuonsCosTh", cotTh);
+  //    declareMonitoredStdContainer ("MuonsPhi", phi);
+
+
+  // for perform
+  declareProperty("doNTuplePerformance",  m_doNTuplePerformance  = false);
+  declareProperty("doTruthPerformance",   m_doTruthPerformance   = false);
+
+  declareProperty("doMuonFeature",                m_doMuonFeature);
+
+} 
+
+//________________________________________________________________________
+TrigMuGirlTool::~TrigMuGirlTool()
+{
+
+}
+
+//________________________________________________________________________
+StatusCode TrigMuGirlTool::initialize()
+{
+  
+  if (msgLvl(MSG::DEBUG) )
+    msg() << MSG::DEBUG << "Initializing TrigMuGirlTool " << endreq;    
+  
+  
+  m_pSegmentManager = new MuGirlNS::SegmentManager;
+  if (m_magFieldSvc.retrieve().isFailure())
+    {
+        msg(MSG::ERROR) <<"Could not retrieve magFieldSvc"<<endreq;
+        return StatusCode::RECOVERABLE;
+    }
+
+  
+  if (retrieve(m_pEventStore).isFailure())
+    msg() << MSG::DEBUG << "Failed to get the StoreGate" << endreq;    
+  
+  // Initialize tools
+  if (retrieve(m_pToCalo, false).isFailure())
+    {
+      msg() << MSG::DEBUG << "Failed to get pToCalo" << endreq;    
+      m_pToCalo = NULL;
+    }
+  
+  if (m_doTruth)
+    {
+      if (retrieve(m_pTruthTool).isFailure())
+	msg() << MSG::DEBUG << "Failed to get the TruthTool" << endreq;    
+    }
+
+  if (m_doLHR)
+    {
+      if (retrieve(m_pMuLHR, false).isFailure())
+	{
+	  msg() << MSG::DEBUG << "Failed to get the pMuLHR" << endreq;    
+	  m_pMuLHR = NULL;
+	}
+    }
+  
+  if (m_doStau)
+    {
+      if (retrieve(m_pStauTool).isFailure())
+	{
+	  msg() << MSG::DEBUG << "Failed to get the StauTool" << endreq;    
+	}
+      m_pStauTool->setSegmentManager(m_pSegmentManager);
+    }
+  
+  if (m_doGlobalFit )
+    {
+      if (retrieve(m_pGlobalFitTool, false).isFailure())
+	{
+	  msg() << MSG::DEBUG << "Failed to get the GlobalFitTool" << endreq;
+	  m_pGlobalFitTool = NULL;
+	}
+    }
+  if (m_doMuonFeature && m_doSAFit )
+    {
+      if (retrieve(m_pMuonFeatureGlobalFitTool, false).isFailure())
+	{
+	  msg() << MSG::DEBUG << "Failed to get the GlobalFitTool for SA fit" << endreq;
+	  m_pMuonFeatureGlobalFitTool = NULL;
+	}
+    }
+
+  if (m_doANNSelection)
+    {
+      if (retrieve(m_pANNSelectionTool, false).isFailure())
+	{
+	  msg() << MSG::DEBUG << "no m_pANNSelection" << endreq;    
+	  m_pANNSelectionTool = NULL;
+	}
+    }
+  
+  // this is done anyway to have the function removeRedundantCandidates avilable
+  {
+    if (retrieve(m_pParticleCreatorTool).isFailure())
+      {
+	msg()<<MSG::DEBUG<<"no m_pParticleCreatorTool"<<endreq;    
+	m_pParticleCreatorTool = NULL;
+      }
+  }
+
+  m_caloLayers.push_back( CaloCell_ID::PreSamplerB );
+  m_caloLayers.push_back( CaloCell_ID::EMB1 );
+  m_caloLayers.push_back( CaloCell_ID::EMB2 );
+  m_caloLayers.push_back( CaloCell_ID::EMB3 );
+  m_caloLayers.push_back( CaloCell_ID::TileBar0 );
+  m_caloLayers.push_back( CaloCell_ID::TileBar1 );
+  m_caloLayers.push_back( CaloCell_ID::TileBar2 );
+  m_caloLayers.push_back( CaloCell_ID::PreSamplerE );
+  m_caloLayers.push_back( CaloCell_ID::EME1 );
+  m_caloLayers.push_back( CaloCell_ID::EME2 );
+  m_caloLayers.push_back( CaloCell_ID::EME3 );
+  m_caloLayers.push_back( CaloCell_ID::HEC0 );
+  m_caloLayers.push_back( CaloCell_ID::HEC1 );
+  m_caloLayers.push_back( CaloCell_ID::HEC2 );
+  m_caloLayers.push_back( CaloCell_ID::FCAL0 );
+  m_caloLayers.push_back( CaloCell_ID::FCAL1 );
+  m_caloLayers.push_back( CaloCell_ID::FCAL2 );
+  m_caloLayers.push_back( CaloCell_ID::TileExt0 );
+  m_caloLayers.push_back( CaloCell_ID::TileExt1 );
+  m_caloLayers.push_back( CaloCell_ID::TileExt2 );
+
+
+  if (retrieve(m_pCandidate).isFailure())
+    {
+      msg()<<MSG::ERROR<<"Could not get pCandidate"<<endreq;
+      return StatusCode::RECOVERABLE;
+    }
+  m_pCandidate->setSegmentManager(m_pSegmentManager);
+
+ 
+  return StatusCode::SUCCESS;
+}
+
+//________________________________________________________________________
+HLT::ErrorCode TrigMuGirlTool::initNtuple(HLT::FexAlgo* fexAlgo)
+{
+  if (m_doNTuple) 
+    {
+      // Initialize NTuple
+      msg()<<MSG::DEBUG<<"in doNTuple"<<endreq;
+      
+      m_pCandNTuple = fexAlgo->ntupleSvc()->book(m_ntupleName, CLID_ColumnWiseTuple, m_ntupleTitle);
+      if (m_pCandNTuple == NULL)
+	{
+	  msg() << MSG::ERROR << "Could not create NTuple " << m_ntupleName << endreq;
+	  return StatusCode::RECOVERABLE;
+	}
+      if (m_pCandidate->bookNTuple(m_pCandNTuple).isFailure())
+	{
+	  msg() << MSG::ERROR << "Could not book Candidate NTuple " << m_ntupleName << endreq;
+	  return StatusCode::RECOVERABLE;
+	}
+      
+      if(m_doStau)
+	{
+	  if(m_pStauTool->bookNTuple(m_pCandNTuple).isFailure())
+	    {
+	      msg() << MSG::ERROR << "Could not book Stau NTuple " << m_ntupleName << endreq;
+	      return StatusCode::RECOVERABLE;
+	    }
+	}
+      if(m_doMuonFeature && m_doSAFit)
+	{
+	  if (m_pMuonFeatureGlobalFitTool->bookNTuple(m_pCandNTuple,"StandAlone").isFailure())
+	    msg() << MSG::ERROR << "Could not book GlobalFit NTuple for StandAlone fit" << m_ntupleName << endreq;
+	  else 
+	    msg() << MSG::DEBUG << "Book GlobalFit NTuple for StandAlone fit" << m_ntupleName << endreq;
+	}
+      if (m_doTruth&& m_pTruthTool->bookNTuple(m_pCandNTuple).isFailure())
+	{
+	  msg() << MSG::ERROR << "Could not book Truth NTuple " << m_ntupleName << endreq;
+	  return StatusCode::RECOVERABLE;
+	}
+      if (m_doGlobalFit&& m_pGlobalFitTool->bookNTuple(m_pCandNTuple,"").isFailure())
+	{
+	  msg() << MSG::ERROR << "Could not book GlobalFit NTuple " << m_ntupleName << endreq;
+	  return StatusCode::RECOVERABLE;
+	}
+    }
+  
+  if (m_doNTuplePerformance)
+    {
+      if (!m_pTrigMuGirlNtuple)
+	{
+	  msg()<< MSG::ERROR << "Could not book NTuple " << m_ntupleName << endreq;
+	  return HLT::BAD_JOB_SETUP;
+	}
+
+      INTupleSvc* ntupleSvc=fexAlgo->ntupleSvc();
+      m_pTrigMuGirlNtuple = new TrigMuGirlNtuple(fexAlgo, ntupleSvc);
+      StatusCode SCstatus = m_pTrigMuGirlNtuple->book(m_ntupleNamePerformance, m_ntupleTitlePerformance);
+      if (SCstatus.isFailure())
+	{
+	  msg()<< MSG::ERROR << "Could not book NTuple " << m_ntupleName << endreq;
+	  return HLT::BAD_JOB_SETUP;
+	}
+    }
+  
+  return HLT::OK;
+}
+
+//________________________________________________________________________
+StatusCode TrigMuGirlTool::finalize()
+{
+  return StatusCode::SUCCESS;
+}
+
+//________________________________________________________________________
+HLT::ErrorCode TrigMuGirlTool::initRoiProcessing(std::vector<TrigTimer*>& timers, 
+						 TrigMuonEFInfoContainer* eMuonEFInfoCont)
+{
+  TrigTimer* timerExecTotal = 0;
+  if (timers.size() >= 1) timerExecTotal=timers[0];
+
+  if (timerExecTotal) timerExecTotal->start();
+
+  ++m_roi;
+  
+  if (eMuonEFInfoCont->size() == 0) {
+    TrigMuonEFInfo* eMuoninfo = new TrigMuonEFInfo(m_roi);
+    eMuonEFInfoCont->push_back( eMuoninfo );
+  }
+
+  if (m_doNTuplePerformance) {    
+    eRunNumber=0;
+    eEventNumber=0;
+    NN[0]=0;
+    NN[1]=0;
+    NN[2]=0;
+    NN[3]=0;
+    NN[4]=0;
+    NN[5]=0;
+  }
+  
+  
+  //  StatusCode status;
+  StatusCode sc = StatusCode::SUCCESS;
+  
+  m_pEventInfo = NULL;
+  sc = m_pEventStore->retrieve(m_pEventInfo);
+  if (sc.isFailure() || m_pEventInfo == NULL)
+    msg() << MSG::WARNING << "Cannot retrieve EventInfo" << endreq;
+  else if (m_doNTuplePerformance) {
+    eRunNumber   = m_pEventInfo->event_ID()->run_number();
+    eEventNumber = m_pEventInfo->event_ID()->event_number();
+  }
+
+  m_summaryList.clear();
+
+  return HLT::OK;
+}
+
+//________________________________________________________________________
+HLT::ErrorCode TrigMuGirlTool::processMuonFeatures(const std::vector<const MuonFeature*>& vectorOfMuonFeature,
+						   const ElementLink<CombinedMuonFeatureContainer>& CombinedMuonFeatureEL)
+{
+
+  int iMuF=0;  
+  if (vectorOfMuonFeature.size() != 0)
+    {
+      m_pStauTool->initTool(m_doSAFit);
+      
+      if (msg().level() <= MSG::DEBUG)
+	msg()<<MSG::DEBUG<<"Start MuonFeature processing for "<<vectorOfMuonFeature.size()<<endreq;
+      
+      //const MuonFeature* pMuonFeature = vectorOfMuonFeature.front();
+      for(unsigned int i=0; i<vectorOfMuonFeature.size(); i++)
+	
+	{
+          const MuonFeature* pMuonFeature = vectorOfMuonFeature[i];
+          if (!pMuonFeature)
+	    {
+	      msg() << MSG::ERROR
+		    << "Retrieval of MuonFeature from vector failed!"
+		    << endreq;
+	      continue;
+	    }
+          if (fabs(pMuonFeature->pt())<m_mfPtCut)  //MuonFeature momentum is in GeV
+	    continue;
+	  
+          bool has_combined = false;
+
+ 
+	  if ( CombinedMuonFeatureEL.isValid() )     
+	    { 
+	      
+	      const CombinedMuonFeature* pMuon = *CombinedMuonFeatureEL; 
+	      if(pMuon)
+		{
+		  ElementLink<MuonFeatureContainer> mfastEL = pMuon->muFastTrackLink();
+		  ElementLink<TrigInDetTrackCollection> trackEL = pMuon->IDTrackLink();           
+		  if (!mfastEL) continue;
+		  
+		  const MuonFeature* pMF = *mfastEL;
+                  
+		  if (!pMF) continue; 
+		  if (pMF == pMuonFeature && trackEL.isValid())                                                          
+		    { 
+		      if (msg().level() <= MSG::DEBUG)
+			msg()<<MSG::DEBUG<<"HAS IDTrack! moving to IDTrack processing"<<endreq;
+		      has_combined = true;
+		      continue;
+		    }
+		}
+	    }
+	  
+	  
+          if (m_pCandidate->fillMF(iMuF, pMuonFeature, true,has_combined).isFailure()) 
+	    {
+	      msg()<< MSG::DEBUG << "MuonFeature Cannot fill CANDIDATE" << endreq;
+	      continue;
+	    }
+          fillMuonSegmentColl(m_pCandidate->vectorMuonSegments());
+
+          MuGirlNS::CandidateSummary* summary_mf = new MuGirlNS::CandidateSummary();
+          if ( msgLvl(MSG::DEBUG) ) 
+	    {
+	      msg()<< MSG::DEBUG << "MuonFeature "<<pMuonFeature->pt()<<" eta "<<pMuonFeature->eta()<<" phi "<<pMuonFeature->phi()  << endreq;
+	      msg()<< MSG::DEBUG << "MuonFeature fill SUMMARY" << endreq;
+	    }
+
+          if (m_pCandidate->fillSummary(summary_mf).isFailure())
+	    {
+              msg()<< MSG::DEBUG << "MuonFeature Cannot fill SUMMARY" << endreq;
+              continue;
+	    }
+
+          if (m_doNTuple)
+	    {
+	      if (m_pEventInfo != NULL)
+		{
+		  if ((m_pCandidate->fillNTupleEventInfo(m_pEventInfo->event_ID()->run_number(),
+							 m_pEventInfo->event_ID()->event_number())).isFailure())
+                    msg() << MSG::WARNING << "MuonFeature::execute Cannot fill NTuple" << endreq;
+		}
+	      if (msg().level() <= MSG::DEBUG)
+		msg() << MSG::DEBUG << "Calling m_pCandidate->fillNTuple for MF" << endreq;
+	      if (m_pCandidate->fillNTuple().isFailure())
+		msg() << MSG::WARNING << "MuonFeature::execute Cannot fill NTuple" << endreq;
+	      if (m_doTruth&&pMuonFeature!=0)
+		{
+		  msg() << MSG::DEBUG << "Calling m_pTruthTool->fillNTuple for MuonFeature processing" << endreq;
+		  if (m_pTruthTool->fillNTuple(summary_mf).isFailure())
+		    msg() << MSG::WARNING << "TrigMuGirlTool::execute Cannot fill Truth in NTuple for Muonfeature processing" << endreq;
+		}
+	    }
+          
+          if ( msgLvl(MSG::DEBUG) ) 
+	    msg()<< MSG::DEBUG << "MuonFeature do Stau hits" << summary_mf->numMdtHits
+		 <<" "<<summary_mf->numTgcEtaHits<<" "<<summary_mf->numTgcPhiHits
+		 <<" "<<summary_mf->numRpcEtaHits<<" "<< summary_mf->numRpcPhiHits
+		 << endreq;
+          if (summary_mf->numMdtHits >4 && 
+	      (summary_mf->numTgcEtaHits>2 || summary_mf->numTgcPhiHits>2 || summary_mf->numRpcEtaHits>2 || summary_mf->numRpcPhiHits>2))
+	    {
+	      if ( msgLvl(MSG::DEBUG) ) 
+                msg()<< MSG::DEBUG << "MuonFeature do Stau" << endreq;
+	      summary_mf->saveStau = 1;
+	      m_pCandidate->setPassdoStau(true);
+
+	      const MuGirlNS::MdtSegmentMakerInfoList mdtSegmentMakerInfoList = m_pCandidate->getMdtSegmentMakerInfo();
+	      const MuGirlNS::RIO_OnTrackLists& rpcHitsInSegments = m_pCandidate->getRpcHitsInSegments();
+	      const MuGirlNS::RIO_OnTrackLists& tgcHitsInSegments = m_pCandidate->getTgcHitsInSegments();
+
+	      float mf_cot  = 1/tan(2*atan(exp (-pMuonFeature->eta())));
+	      float mf_px   = 1000*fabs(pMuonFeature->pt())*cos(pMuonFeature->phi());
+	      float mf_py   = 1000*fabs(pMuonFeature->pt())*sin(pMuonFeature->phi());
+	      float mf_pz   = 1000*fabs(pMuonFeature->pt())*mf_cot;
+	      //double mf_p    = sqrt(mf_px*mf_px+ mf_py*mf_py + mf_pz*mf_pz);
+	      Amg::Vector3D v(mf_px,mf_py,mf_pz);  
+	      if ( m_pStauTool->processStau(NULL,m_pCandidate->vectorMuonSegments(),mdtSegmentMakerInfoList,rpcHitsInSegments,tgcHitsInSegments,NULL,NULL,v).isFailure())
+		msg() << MSG::WARNING << "MuonFeature::cannot execute processStau" << endreq;
+	      for(std::vector<const Muon::MuonSegment*>::const_iterator itSegs = (*m_pStauTool->newMdtSegments()).begin(); itSegs != (*m_pStauTool->newMdtSegments()).end(); itSegs++)
+		{
+		  m_pSegmentManager->addSegment(*itSegs, MuGirlNS::SegmentManager::MDT_STAU);
+		}
+	      fillMuonSegmentColl(*m_pStauTool->newMdtSegments());
+	      if (m_pStauTool->beta() <0.2 || m_pStauTool->beta()>1.2)
+		{
+		  delete m_pStauTool->refittedTrack();
+		  continue;
+		}  
+	      summary_mf->beta = m_pStauTool->beta();
+
+	      if (m_doNTuple)
+		{
+		  if (m_pStauTool->fillNTuple().isFailure())
+                    msg() << MSG::WARNING << "MuonFeature::execute Cannot fill Stau NTuple" << endreq;
+		}
+
+	      MuGirlNS::CandidateSummary* stauSummary = new MuGirlNS::CandidateSummary();
+
+	      if (m_pStauTool->fillStauSummary(summary_mf,stauSummary).isFailure())
+		msg() << MSG::DEBUG << "MuonFeature::execute Cannot fill stausummary" << endreq;
+	      stauSummary->qOverP = summary_mf->qOverP;
+	      stauSummary->startFromMF = 1;
+	      bool ANNstau = generateMuGirl(stauSummary);
+
+	      msg() << MSG::DEBUG << "MuonFeature::execute ANNstau"<< ANNstau << endreq;
+	      //if (ANNstau)
+	      // {
+	      stauSummary->saveStau = 1;
+	      m_summaryList.push_back(stauSummary);
+	      //}
+	      if ( m_doSAFit && stauSummary->muonSegmentList.size()>0)
+		//if ( m_doSAFit && m_pCandidate->vectorMuonSegments().size()>0)
+		{
+		  msg() << MSG::DEBUG << "MuonFeature:: stau segments "<<stauSummary->muonSegmentList.size()
+			<< " Muon segments "<<m_pCandidate->vectorMuonSegments().size()<< endreq;
+		  const Trk::Track* RefittedTrack = 0;
+		  RefittedTrack = m_pMuonFeatureGlobalFitTool->globalFit(stauSummary->muonSegmentList,summary_mf->qOverP,m_doNTuple);
+		  //RefittedTrack = m_pMuonFeatureGlobalFitTool->globalFit(m_pCandidate->vectorMuonSegments(),summary_mf->qOverP,m_doNTuple);
+
+		  if (RefittedTrack != NULL)
+		    {
+                      xAOD::TrackParticle* tp = NULL;
+                      ATH_MSG_DEBUG("found SA track");
+                      /** add the refitted track to the refitted track container and create the element link */
+		      m_pCandidate-> fillRefittedTrack(tp,RefittedTrack,stauSummary);
+                    }
+                    else
+                    {	
+                      delete RefittedTrack;
+                      m_pCandidate-> fillRefittedTrack(NULL,NULL,stauSummary);
+                    }
+		      //    m_pRefittedTrkCollection->push_back(const_cast<Trk::Track*> (RefittedTrack));
+		 }
+	    }   // enter stau selection
+
+          iMuF++;
+	} // loop on vector of MuonFeatures
+    }   // if vectorOfMuonFeature.size()>0
+  if (m_doNTuple)
+    {
+      if (m_pCandNTuple->writeRecord().isFailure())
+	msg() << MSG::WARNING << "MuonFeature::execute Cannot write NTuple" << endreq;
+    }
+  
+  if (msg().level() <= MSG::DEBUG)
+    msg() << MSG::DEBUG << "MF processing is done"<<endreq;
+  
+  return HLT::OK;
+}
+
+//________________________________________________________________________
+HLT::ErrorCode TrigMuGirlTool::processTrackCollections(	const ElementLinkVector<xAOD::TrackParticleContainer>& idTrackParticleLinks,
+                                                        const std::vector<const xAOD::CaloClusterContainer*>& vectorOfClusterContainers)
+{
+  
+  m_pStauTool->initTool(m_doGlobalFit);
+  
+  const VxContainer* vxCandidatesContainer = 0;
+  int iTrack = 0;
+  // for performance ntuple
+  m_TrackIso=-1;
+
+  if(msgLvl(MSG::DEBUG))
+    msg() << MSG::DEBUG << "Got vector with " << vectorOfClusterContainers.size()  << " ClusterContainers" << endreq;
+  
+  // if no containers were found, just leave the vector empty and leave
+  if ( vectorOfClusterContainers.size() < 1) {
+    if(msgLvl(MSG::DEBUG)) 
+      msg() << MSG::DEBUG << "No Cluster container available !" << endreq;
+  }
+  else
+    {
+      // get last container to be put in vector (should also be the only one)
+      m_pClusCollection = vectorOfClusterContainers.back();
+      if (!m_pClusCollection)
+	{
+	  if(msgLvl(MSG::WARNING)) 
+	    msg() << MSG::WARNING << "No Clusters found in the RoI" << endreq;
+	}
+    }
+  
+  if (!m_magFieldSvc->solenoidOn()) 
+    { 
+      if (msg().level()<=MSG::DEBUG) msg()<<MSG::DEBUG << "MuGirl::Solenoid is off. Execute done" << endreq; 
+      return HLT::OK;
+    } 
+  else
+    if (msg().level()<=MSG::DEBUG) msg()<<MSG::DEBUG << "MuGirl::Solenoid is ON" << endreq; 
+  
+  m_inDetTrackParticleLinks = idTrackParticleLinks;
+  
+  // out for timing
+  //    if (msg().level() <= MSG::DEBUG)
+  //        msg() << MSG::DEBUG << "Size of TrackParticleCandidate = " << m_inDetTrackParticleLinks.size() << endreq;
+  if (m_pEventStore->contains<VxContainer>("VxPrimaryCandidate"))
+    {
+      if (m_pEventStore->retrieve(vxCandidatesContainer, "VxPrimaryCandidate").isFailure())
+	{
+          if (msg().level() <= MSG::DEBUG) 
+	    msg()<<MSG::DEBUG << "Cannot retrieve " << "VxPrimaryCandidate" << endreq;
+	}
+    }
+  else
+    if (msg().level() <= MSG::DEBUG)
+      msg()<<MSG::DEBUG << "Cannot retrieve " << "VxPrimaryCandidate" << endreq;
+
+  if (m_doNTuplePerformance)
+    {
+      eRunNumber   = m_pEventInfo->event_ID()->run_number();
+      eEventNumber = m_pEventInfo->event_ID()->event_number();
+    }
+
+  createCaloParticles();
+   
+  IsolatedIdTracks(m_idR);
+
+
+  for (unsigned int i = 0; i < m_caloParticles.size(); i++)
+    {
+      CaloParticle* pParticle = m_caloParticles[i];
+      const xAOD::TrackParticle* pTrackParticle = pParticle->pTrackParticle;
+      const Trk::Perigee perigee = pTrackParticle->perigeeParameters();
+
+      bool doStau = m_doStau && perigee.pT() >= m_stauPtCut;
+      msg() << MSG::DEBUG << "TrigMuGirlTool::execute doStau "<<doStau << endreq;
+      if (!m_pCandidate->fill(iTrack, pTrackParticle, &perigee, doStau).isSuccess())
+        {
+	  msg() << MSG::DEBUG << "TrigMuGirlTool::execute failed candidate->fill " << endreq;
+   
+	  fillMuonSegmentColl(m_pCandidate->vectorMuonSegments());
+	  continue;
+	}
+
+      //for performance ntuple
+      if (pParticle->isolated)
+	{
+	  m_pCandidate->setIsolation(1);
+	  m_pCandidate->setLHR(-2);
+	}
+      m_TrackIso=pParticle->isolated;
+
+      MuGirlNS::CandidateSummary* summary = new MuGirlNS::CandidateSummary();
+
+      bool ANNaccept = false;
+      if (m_pCandidate->fillSummary(summary).isFailure())
+	{
+	  msg() << MSG::DEBUG << "TrigMuGirlTool::execute Cannot fill summary" << endreq;
+	}
+      else
+	{
+	  if (m_doANNSelection)
+	    {
+	      ANNaccept = generateMuGirl(summary);
+	    }
+	}
+
+      if ((m_doANNSelection && ANNaccept) || !(m_doANNSelection)) 
+        {
+	  summary->saveAnn = 1;
+
+	  if (m_doGlobalFit&&( pTrackParticle->track()!=NULL )&&
+	      (m_pCandidate->vectorMuonSegments()).size()>0)
+            {
+	      const Trk::Track* RefittedTrack = 0;
+	      RefittedTrack = m_pGlobalFitTool->globalFit( pTrackParticle->track(),m_pCandidate->vectorMuonSegments(),m_doNTuple);
+	      if (RefittedTrack != NULL)
+		{
+		  //m_pRefittedTrkCollection->push_back(const_cast<Trk::Track*> (RefittedTrack));
+		  //const Trk::VxCandidate* pVxCandidate = 0 ;
+		  //pVxCandidate=pTrackParticle->reconstructedVertex();
+		  xAOD::TrackParticle* tp = 0;
+/*
+		  if (pVxCandidate != NULL && vxCandidatesContainer != 0)
+		    tp =TEcreateParticle(RefittedTrack, pVxCandidate, pVxCandidate->vertexType());
+		  else
+		    // this didn't worked so we rewrite this routine for TE
+		    //                   tp =m_particleCreatorTool->createParticle(RefittedTrack, pVxCandidate, Trk::NoVtx);
+		    tp =TEcreateParticle(RefittedTrack, pVxCandidate, Trk::NoVtx);
+*/
+		  m_pCandidate-> fillRefittedTrack(tp,RefittedTrack,summary);
+		}
+	      else
+		{
+		  delete RefittedTrack;
+	          m_pCandidate-> fillRefittedTrack(NULL,NULL,summary);
+		} 
+
+	      if (msg().level() <= MSG::DEBUG)
+		msg() << MSG::DEBUG << "Global Fit was ran " << endreq;
+	    }  //if doGlobalFit
+
+	}//if ANN     
+      else
+	m_pCandidate-> fillRefittedTrack(NULL,NULL,summary);
+
+      if (m_doNTuple)
+	{
+          if (m_pEventInfo != NULL)
+	    {
+	      if (m_pCandidate->fillNTupleEventInfo(m_pEventInfo->event_ID()->run_number(),
+						    m_pEventInfo->event_ID()->event_number()).isFailure())
+		msg() << MSG::WARNING << "TrigMuGirlTool::execute Cannot fill NTuple" << endreq;
+	    }
+	  if (msg().level() <= MSG::DEBUG)
+	    msg() << MSG::DEBUG << "Calling m_pCandidate->fillNTuple" << endreq;
+	    
+	  if (m_pCandidate->fillNTuple().isFailure())
+	    msg() << MSG::WARNING << "TrigMuGirlTool::execute Cannot fill NTuple" << endreq;
+	  if (m_doNTuple&&m_doTruth&&pTrackParticle!=NULL)
+	    {
+	      if (msg().level() <= MSG::DEBUG)
+		msg() << MSG::DEBUG << "Calling m_pTruthTool->fillNTuple" << endreq;
+	      if (m_pTruthTool->fillNTuple(summary).isFailure())
+		msg() << MSG::WARNING << "TrigMuGirlTool::execute Cannot fill Truth in NTuple" << endreq;
+	    }
+	} //if doNTuple
+      fillMuonSegmentColl(summary->muonSegmentList);
+      //<S>
+      // needs to be updated - there is a branch
+      bool passedStau = false;
+      if(doStau && summary->numMdtHits >4 &&(summary->numTgcEtaHits>2 || summary->numTgcPhiHits>2 || summary->numRpcEtaHits>2 || summary->numRpcPhiHits>2))
+	{   
+	  m_pCandidate->setPassdoStau(true);
+	  //retrieve segment maker info list
+	  const MuGirlNS::MdtSegmentMakerInfoList mdtSegmentMakerInfoList = m_pCandidate->getMdtSegmentMakerInfo();
+	  //retrieve the rpc hits
+	  const MuGirlNS::RIO_OnTrackLists& rpcHitsInSegments = m_pCandidate->getRpcHitsInSegments();
+          const MuGirlNS::RIO_OnTrackLists& tgcHitsInSegments = m_pCandidate->getTgcHitsInSegments();
+
+	  //process stau
+
+          const Trk::Track* pMuonRefittedTrack = NULL;
+          if (summary->pRefittedTrack != NULL)
+	    pMuonRefittedTrack = summary->pRefittedTrack->track(); 
+          StatusCode sc = m_pStauTool->processStau(pTrackParticle, m_pCandidate->vectorMuonSegments(), mdtSegmentMakerInfoList,rpcHitsInSegments,tgcHitsInSegments,pMuonRefittedTrack);
+	  summary->beta = m_pStauTool->beta();
+
+          for(std::vector<const Muon::MuonSegment*>::const_iterator itSegs = (*m_pStauTool->newMdtSegments()).begin(); itSegs != (*m_pStauTool->newMdtSegments()).end(); itSegs++)
+	    {
+	      m_pSegmentManager->addSegment(*itSegs, MuGirlNS::SegmentManager::MDT_STAU);
+	    }
+	
+          fillMuonSegmentColl(*m_pStauTool->newMdtSegments());
+	  if (!sc.isFailure())
+	    {
+             
+              if (m_pStauTool->beta() <0.2 || m_pStauTool->beta() >1.2)
+		delete m_pStauTool->refittedTrack();
+              else
+		{
+	          MuGirlNS::CandidateSummary* stauSummary = new MuGirlNS::CandidateSummary();
+	          if (m_pStauTool->fillStauSummary(summary,stauSummary).isFailure())
+		    msg() << MSG::DEBUG << "TrigMuGirlTool::execute Cannot fill stausummary" << endreq;
+
+                  bool ANNstau = generateMuGirl(stauSummary);
+                  if (stauSummary->nnBarrel >0.2 || stauSummary->nnEndCap >0.2) ANNstau = true;
+                  msg()<<MSG::DEBUG << "MuGirl::execute: stau passANN "<<ANNstau << endreq;
+
+                  const Trk::Track* stauRefittedTrack = m_pStauTool->refittedTrack();
+                  if (stauRefittedTrack != NULL)
+		    {
+                      //const Trk::VxCandidate* pVxCandidate = 0 ;
+                      //pVxCandidate=pTrackParticle->reconstructedVertex();
+                      xAOD::TrackParticle* stauTp = 0;
+                      //if (pVxCandidate != NULL && vxCandidatesContainer != 0)
+			//stauTp =TEcreateParticle(stauRefittedTrack, pVxCandidate, pVxCandidate->vertexType());
+                      //else
+			//stauTp =TEcreateParticle(stauRefittedTrack, pVxCandidate, Trk::NoVtx);
+                      //if (stauTp != NULL)
+			//{
+                          //if (msg().level() <= MSG::DEBUG)
+			    //msg() << MSG::DEBUG << "Trk::Track converted to Rec::TrackParticle p() "<<stauTp->p() << endreq;
+                      stauSummary->pRefittedTrack = stauTp;  
+                      stauSummary->pTrkRefitted   = stauRefittedTrack;
+			//}
+                      //else
+			//delete stauTp;
+		    }
+                  else
+                    {
+		      delete stauRefittedTrack;
+                      stauSummary->pRefittedTrack = NULL;    
+                      stauSummary->pTrkRefitted   = NULL;
+                    }
+	          if (m_doNTuple)
+		    {
+	              sc = m_pStauTool->fillNTuple();
+	              if(sc.isFailure())
+			msg() << MSG::DEBUG << "TrigMuGirlTool::execute stauTool->fillNtuple failed " << endreq; 
+		    }
+
+                  if (ANNstau)
+		    {
+	              stauSummary->saveStau = 1;
+              
+	              passedStau =true;
+	              m_summaryList.push_back(stauSummary);
+		    }     
+		}
+	    }
+	} //if doStau
+
+      msg() << MSG::DEBUG << "TrigMuGirlTool::execute passedStau "<<passedStau << endreq;
+    
+      if (summary->saveAnn == 1)
+	{
+	  summary->saveStau = 0;
+	  m_summaryList.push_back(summary);
+	}
+      else
+	{
+
+	  delete summary; 
+        }
+
+      if (m_doNTuple)
+	{
+	  if (m_pCandNTuple->writeRecord().isFailure())
+	    msg() << MSG::WARNING << "TrigMuGirlTool::execute Cannot write NTuple" << endreq;
+	}
+      // out for timing
+      //	if (msg().level() <= MSG::DEBUG)
+      //	  msg() << MSG::DEBUG << "Done processing track " << iTrack << endreq;
+      iTrack++;
+
+    }  //loop on CaloParticle
+
+
+  // for perform
+  if (m_doNTuplePerformance && m_pTrigMuGirlNtuple)
+    {
+      StatusCode statusfill = m_pTrigMuGirlNtuple->fillEvent(eEventNumber,eRunNumber);
+      if (statusfill.isFailure())
+	{
+	  msg() << MSG::ERROR << " Cannot fill NTuple event # " << endreq;
+	  return HLT::BAD_JOB_SETUP;
+	}
+    }
+
+    
+  //    if (msg().level() <= MSG::DEBUG) msg()<<MSG::DEBUG << "Number of summaries=" << summaryList.size() << endreq; 
+
+    
+  if (m_doTruthPerformance)
+    {
+      if (doMuTruthPerformance() != HLT::OK)
+	msg() << MSG::ERROR  << "The doMuTruth status is not Ok" << endreq;
+    }
+
+  return HLT::OK;
+}
+
+//________________________________________________________________________
+HLT::ErrorCode TrigMuGirlTool::finalizeRoiProcessing(std::vector<TrigTimer*>& timers,
+						     TrigMuonEFInfoContainer* eMuonEFInfoCont,
+						     Rec::TrackParticleContainer*& eTrkParCont,
+						     TrigMuGirlMonVars& monVars)
+{
+  TrigTimer* timerExecTotal = 0;
+  if (timers.size() >= 1) timerExecTotal=timers[0];
+
+  //added a container of ID tracks for future use
+  eTrkParCont = new Rec::TrackParticleContainer;
+
+  /*
+  TrigMuonEFInfo* eMuoninfo = 0;
+  if ( eMuonEFInfoCont->size() == 0 ) {
+  eMuoninfo = new TrigMuonEFInfo(m_roi);
+  eMuonEFInfoCont->push_back( eMuoninfo );
+  ATH_MSG_DEBUG("creating new TrigMuonEFInfo with m_roi_num=" << eMuoninfo->RoINum());
+  } else {
+  eMuoninfo = eMuonEFInfoCont->front();
+  ATH_MSG_DEBUG("adding to existing TrigMuonEFInfo with m_roi_num=" << eMuoninfo->RoINum());    
+  }
+  */
+
+  TrigMuonEFInfoContainer::const_iterator MuonItr = eMuonEFInfoCont->begin();
+  TrigMuonEFInfo* eMuoninfo = (*MuonItr);
+
+  int tot_seg = 0; 
+  int tot_mdt = 0; 
+  int tot_csc = 0; 
+  int tot_rpc = 0; 
+  int tot_tgc = 0; 
+
+  std::vector<bool> IncludeList;
+  MuGirlNS::CandidateSummaryList* SummaryList=&m_summaryList;
+
+  m_pParticleCreatorTool->removeRedundantCandidates(SummaryList, IncludeList);
+
+  int iCand = -1;
+  int nMuons=0;
+  for (MuGirlNS::CandidateSummaryList::iterator itSummary = SummaryList->begin(); itSummary !=SummaryList->end(); itSummary++)
+    {
+      iCand++;
+      if (!IncludeList[iCand])
+	continue;
+      const MuGirlNS::CandidateSummary* pSummary = *itSummary;
+      if (!pSummary->startFromMF && pSummary->pTrackParticle ==NULL)
+	{
+          msg()<<MSG::DEBUG<<"This is not a RHadron candidate and ID track is NULL! candidate skipped"<< endreq;
+          continue;
+	}
+      if (pSummary->saveAnn == 1 || pSummary->saveStau == 1)
+	{
+          monVars.nMdt.push_back(pSummary->numMdtHits);
+          monVars.nRpcPhi.push_back(pSummary->numRpcPhiHits);
+          monVars.nRpcEta.push_back(pSummary->numRpcEtaHits);
+          monVars.nCscPhi.push_back(pSummary->numCscPhiHits);
+          monVars.nCscEta.push_back(pSummary->numCscEtaHits);
+          monVars.nTgcPhi.push_back(pSummary->numTgcPhiHits);
+          monVars.nTgcEta.push_back(pSummary->numTgcEtaHits);
+          monVars.nTgcRpcEta.push_back(pSummary->numTgcRpcEtaHits);
+          monVars.nTgcRpcPhi.push_back(pSummary->numTgcRpcPhiHits);
+ 
+          monVars.nMdtInseg.push_back(pSummary->numMdtHitsInSeg);
+          monVars.nRpcInseg.push_back(pSummary->numRpcHitsInSeg);
+          monVars.nTgcInseg.push_back(pSummary->numTgcHitsInSeg);
+          monVars.nTgcRpcInseg.push_back(pSummary->numTgcRpcHitsInSeg);
+
+          monVars.nMdtSegs.push_back(pSummary->numMdtSegs);
+          monVars.nRpcSegs.push_back(pSummary->numRpcSegs);
+          monVars.nCscSegs.push_back(pSummary->numCscSegs);
+          monVars.nTgcSegs.push_back(pSummary->numTgcSegs);
+          monVars.nTgcRpcSegs.push_back(pSummary->numTgcRpcSegs);
+
+          monVars.beta.push_back(pSummary->beta);
+          monVars.nnBarrel.push_back(pSummary->nnBarrel);
+          monVars.nnEndcap.push_back(pSummary->nnEndCap);
+          MuGirlNS::StauRpcHitsLists* rpcHitsLists = pSummary->rpcHitsLists;
+          if(NULL!=rpcHitsLists)
+	    {
+	      for(MuGirlNS::StauRpcHitsLists::iterator it = rpcHitsLists->begin(); it != rpcHitsLists->end(); it++)
+		{
+		  MuGirlNS::StauRpcHitsList* pRpcHits = *it;
+		  for(MuGirlNS::StauRpcHitsList::iterator it1 = pRpcHits->begin(); it1 != pRpcHits->end(); it1++)
+		    {
+		      MuGirlNS::StauRpcHit* hit = (*it1);
+		      monVars.rpcHitsMeasTime.push_back( hit->measuredTime);
+		      monVars.rpcHitsPropTime.push_back( hit->propagationTime);
+		      monVars.rpcHitsTof.push_back( hit->muonToF);
+		      monVars.rpcHitsDis.push_back( hit->distance);
+		    }
+	
+		}
+	
+	    }
+	  //const xAOD::TrackParticle* etp;
+          const Trk::Track* etp = NULL;
+
+	  if (pSummary->pTrkRefitted==NULL)
+	    {   
+              if (pSummary->startFromMF) continue;
+              etp = pSummary->pTrackParticle->track();
+	    }
+	  else etp = pSummary->pTrkRefitted;
+
+          const Trk::TrackSummary* trackSummary = etp->trackSummary();
+          int numhits_pix = trackSummary->get(Trk::numberOfPixelHits);
+          int numhits_sct = trackSummary->get(Trk::numberOfSCTHits);
+          int numhits_trt = trackSummary->get(Trk::numberOfSCTHits);
+
+
+	  const Trk::Perigee* emp = etp->perigeeParameters();
+	  double ePhi = emp->parameters()[Trk::phi];
+	  double eTheta = 1/tan(emp->parameters()[Trk::theta]);
+	  double theta = emp->parameters()[Trk::theta];
+	  double ePt = 1/(emp->pT());
+	  double eCharge = emp->charge();
+	  double eMass = 105.7;
+	  if (pSummary->beta >0.0 && pSummary->beta < 1.0)
+	    {
+              double BetaCand = pSummary->beta;
+              double mom = (emp->pT())/sin(theta);
+              eMass = mom * sqrt(1.-BetaCand*BetaCand)/BetaCand; 
+	    }
+
+	  monVars.pt.push_back(1/ePt);
+	  monVars.cotTh.push_back(eTheta);
+	  monVars.phi.push_back(ePhi);
+	    
+	  //      msg() << MSG::DEBUG <<"ePt="<<ePt<< endreq;
+	  //      msg() << MSG::DEBUG <<"eTheta="<<eTheta<< endreq;
+	  //      msg() << MSG::DEBUG <<"ePhi="<<ePhi<< endreq;
+	  //      msg() << MSG::DEBUG <<"eCharge="<<eCharge<< endreq;
+	  //	   msg() << MSG::DEBUG << " testiso pSummary->lhr = " <<pSummary->lhr<< endreq;
+	  //	   msg() << MSG::DEBUG << " testiso TrackIso = " <<m_TrackIso<< endreq;
+
+          TrigMuonEFInfoTrack * infoTrack = new TrigMuonEFInfoTrack();
+          if (pSummary->pRefittedTrack!=NULL)
+	    infoTrack->setMuonType(2);
+          else
+	    infoTrack->setMuonType(3);
+  
+
+          eMuoninfo->addTrack(infoTrack);
+	  // another output object option
+	  TrigMuonEFCbTrack* combinedTrk = infoTrack->CombinedTrack();
+	  combinedTrk->setPerigee(ePt,eTheta,ePhi,eMass);
+	  combinedTrk->setCharge(eCharge);
+          combinedTrk->setNIdSctHits(numhits_sct); 
+          combinedTrk->setNIdPixelHits(numhits_pix); 
+          combinedTrk->setNTrtHits(numhits_trt);
+           
+          combinedTrk->setNMdtHits(pSummary->numMdtHits);
+          combinedTrk->setNRpcHitsPhi(pSummary->numRpcPhiHits);
+          combinedTrk->setNRpcHitsEta(pSummary->numRpcEtaHits);
+          combinedTrk->setNTgcHitsPhi(pSummary->numTgcPhiHits);
+          combinedTrk->setNTgcHitsEta(pSummary->numTgcEtaHits);
+          combinedTrk->setNCscHitsPhi(pSummary->numCscPhiHits);
+          combinedTrk->setNCscHitsEta(pSummary->numCscEtaHits);
+          if (!pSummary->startFromMF)
+	    {
+	      bool foundellink=false;
+	      // find track particle corresponding to the ID track used in the combined muon
+	      for(ElementLinkVector<xAOD::TrackParticleContainer>::const_iterator elit= m_inDetTrackParticleLinks.begin(); elit!=m_inDetTrackParticleLinks.end(); ++elit) {
+		if ( !elit->isValid() ) {
+		  ATH_MSG_WARNING("Invalid EF ID TrackParticle ElementLink");
+		  continue;
+		}
+		if(pSummary->pTrackParticle==(**elit)) {
+		  if (msgLvl(MSG::DEBUG)) msg() << MSG::DEBUG << "Assigning TrackParticle" << endreq;
+		  // removed until we get new EDM that supports xAOD  ==>  combinedTrk->setIDTrackElementLink( *elit );
+		  if (msgLvl(MSG::DEBUG)) msg()  << MSG::DEBUG << " MuonEF  - ID TrackParticle parameters are:  pt " << combinedTrk->getIDTrackParticle()->pt()
+				      << " MeV - eta " << combinedTrk->getIDTrackParticle()->eta()
+				      << " phi " <<  combinedTrk->getIDTrackParticle()->phi()<< endreq;
+		  foundellink=true;
+		  break;
+		}
+		
+	      }//ID ElementLink loop
+	      
+	      if(!foundellink) {
+		msg() << MSG::WARNING << "Did not find matching EF ID track - cannot store in EDM" << endreq;
+	      }
+
+	    }
+          tot_mdt = tot_mdt + pSummary->numMdtHits; 
+          tot_rpc = tot_rpc + pSummary->numRpcEtaHits + pSummary->numRpcPhiHits; 
+          tot_tgc = tot_tgc + pSummary->numTgcEtaHits + pSummary->numTgcPhiHits; 
+          tot_csc = tot_csc + pSummary->numCscEtaHits + pSummary->numCscPhiHits; 
+          tot_seg = tot_seg + pSummary->numMdtSegs + pSummary->numRpcSegs + pSummary->numTgcSegs
+	    + pSummary->numCscSegs + pSummary->numTgcRpcSegs;
+	  
+          // xAOD::TrackParticle* etp2 = NULL; //new Rec::TrackParticle(*etp);
+          // removed until we the migration to the new EDM is performed.  ==> eTrkParCont->push_back(etp2);
+	  //for perform
+	  if(m_doNTuplePerformance && m_pTrigMuGirlNtuple)
+	    {
+	      ++nMuons;
+	      // tan(x/2)=sqrt(1+cot**2)-cot
+	      double eta=-log(sqrt(1+(eTheta)*(eTheta))-(eTheta)); 
+	      StatusCode statusfill = m_pTrigMuGirlNtuple->fillReco(nMuons,ePhi,eTheta,eta,(1/ePt), (int)eCharge, NN[0], NN[1], NN[2], NN[3], NN[4], NN[5], pSummary->lhr, m_TrackIso, pSummary->innDelta );
+	      if (statusfill.isFailure())
+		{
+	          msg() << MSG::ERROR << " Cannot fill NTuple Reco " << endreq;
+	          return HLT::BAD_JOB_SETUP;
+		}
+	    }
+	} 
+      
+    }
+  
+  eMuoninfo->setNMdtHits(tot_mdt); 
+  eMuoninfo->setNRpcHits(tot_rpc); 
+  eMuoninfo->setNTgcHits(tot_tgc); 
+  eMuoninfo->setNCscHits(tot_csc); 
+  eMuoninfo->setNSegments(tot_seg); 
+  
+  //for perform
+  if (m_doNTuplePerformance)
+    {
+      if (msg().level() <= MSG::DEBUG)
+	msg() << MSG::DEBUG << " Write Ntuple " << endreq;
+
+      if (!m_pTrigMuGirlNtuple)
+	{
+	  msg() << MSG::ERROR << "TrigMuGirlFex::execute Cannot write NTuple" << endreq;
+	  return HLT::BAD_JOB_SETUP;
+	}
+
+      StatusCode statusNT = m_pTrigMuGirlNtuple->writeRecord();
+      if (statusNT.isFailure())
+	{
+	  msg() << MSG::ERROR << "TrigMuGirlFex::execute Cannot write NTuple" << endreq;
+	  //delete di_muon;
+	  return HLT::BAD_JOB_SETUP;
+	}
+    }
+  
+  if (m_doParticleCreator && !m_summaryList.empty()) 
+    {
+      if (msg().level() <= MSG::DEBUG) 
+	msg()<< MSG::DEBUG << "Calling m_pParticleCreatorTool->fillContainer" << endreq; 
+      if (m_pParticleCreatorTool->fillContainer(&m_summaryList).isFailure()) 
+	{
+	  for (MuGirlNS::CandidateSummaryList::iterator itSummary = m_summaryList.begin(); itSummary !=m_summaryList.end(); itSummary++)
+	    {
+	      delete *itSummary;
+	    }
+	  m_summaryList.clear();
+	  for (unsigned i = 0; i < m_caloParticles.size(); i++)
+	    {
+	      delete m_caloParticles[i];
+	    }
+	  m_caloParticles.clear();
+	  return StatusCode::RECOVERABLE;
+	}
+    }
+  
+  msg() << MSG::DEBUG << "TrigMuGirlTool::clearing caloParticles" << endreq;
+  
+  for (unsigned i = 0; i < m_caloParticles.size(); i++)
+    {
+      delete m_caloParticles[i];
+    }
+  m_caloParticles.clear();
+
+  msg() << MSG::DEBUG << "TrigMuGirlTool::clearing summaries" << endreq;
+  for (MuGirlNS::CandidateSummaryList::iterator itSummary = m_summaryList.begin(); itSummary !=m_summaryList.end(); itSummary++)
+    {
+      if ((*itSummary)->startFromMF) delete *itSummary;  
+      else 
+	{
+	  if ((*itSummary)->pRefittedTrack != NULL)
+            delete ((*itSummary)->pRefittedTrack)->track(); 
+	  delete (*itSummary)->pRefittedTrack; 
+          if ((*itSummary)->pTrkRefitted != NULL)
+            delete (*itSummary)->pTrkRefitted;
+	  delete *itSummary;
+	}
+    }
+  
+  msg() << MSG::DEBUG << "TrigMuGirlTool::clearing segments" << endreq;
+  m_pSegmentManager->clear();
+  m_summaryList.clear();
+  
+  
+  if (msg().level() <= MSG::DEBUG)
+    msg() << MSG::DEBUG << "TrigMuGirlTool::finalizeRoiProcessing done" << endreq;
+  
+  if (timerExecTotal) timerExecTotal->stop();    
+  
+  return HLT::OK;
+}
+
+//________________________________________________________________________
+void TrigMuGirlTool::addTimers(HLT::FexAlgo* fexAlgo, std::vector<TrigTimer*>& timers)
+{
+  timers.push_back( fexAlgo->addTimer("eExecTotal") );
+  
+}
+
+
+//________________________________________________________________________
+void TrigMuGirlTool::declareMonitoringVariables(HLT::FexAlgo* fexAlgo, TrigMuGirlMonVars& monVars)
+{
+  ATH_MSG_DEBUG("declaring monitoring variables");
+
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_pt",            monVars.pt, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_cotTh",         monVars.cotTh, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_phi",           monVars.phi, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_mdtHits",       monVars.nMdt, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_rpcPhiHits",    monVars.nRpcPhi, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_rpcEtaHits",    monVars.nRpcEta, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_cscPhiHits",    monVars.nCscPhi, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_cscEtaHits",    monVars.nCscEta, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_tgcPhiHits",    monVars.nTgcPhi, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_tgcEtaHits",    monVars.nTgcEta, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_tgcRpcPhiHits", monVars.nTgcRpcPhi, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_tgcRpcEtaHits", monVars.nTgcRpcEta, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_mdtHitsInSeg",  monVars.nMdtInseg, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_rpcHitsInSeg",  monVars.nRpcInseg, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_tgcHitsInSeg",  monVars.nTgcInseg, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_tgcRpcHitsInSeg", monVars.nTgcRpcInseg, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_mdtSegs",       monVars.nMdtSegs, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_rpcSegs",       monVars.nRpcSegs, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_cscSegs",       monVars.nCscSegs, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_tgcSegs",       monVars.nTgcSegs, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_tgcRpcSegs",    monVars.nTgcRpcSegs, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_beta",          monVars.beta, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_nnBarrel",      monVars.nnBarrel, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_nnEndcap",      monVars.nnEndcap, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_rpcHitsMeasTime", monVars.rpcHitsMeasTime, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_rpcHitsPropTime", monVars.rpcHitsPropTime, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_rpcHitsTof",  monVars.rpcHitsTof, IMonitoredAlgo::AutoClear);
+  fexAlgo->declareMonitoredStdContainer ("EF_mgtrks_rpcHitsDist", monVars.rpcHitsDis, IMonitoredAlgo::AutoClear);
+
+
+  return;
+}
+void TrigMuGirlTool::createCaloParticles()
+{
+  Amg::Vector3D pt_calo_local(0,0,0);
+
+  // out for timing
+  //    if (msg().level() <= MSG::DEBUG)
+  //        msg() << MSG::DEBUG << "createCaloParticles: Pre-selection from " << m_inDetTrackParticleLinks.size() << " particles." << endreq;
+
+  for (ElementLinkVector<xAOD::TrackParticleContainer>::const_iterator ipIt = m_inDetTrackParticleLinks.begin();
+       ipIt != m_inDetTrackParticleLinks.end();
+       ++ipIt)
+    {
+      if ( !ipIt->isValid() )
+        {
+          ATH_MSG_WARNING("Invalid EF ID TrackParticle ElementLink");
+          continue;
+        }
+
+      const xAOD::TrackParticle* tp_id = **ipIt;
+      const Trk::Perigee pPerigee = tp_id->perigeeParameters();
+/*
+      if (pPerigee == NULL)
+        {
+	  if (msg().level() <= MSG::DEBUG)
+	    msg() << MSG::DEBUG << "Missing perigee" << endreq;
+	  continue;
+        }
+*/
+      double px = pPerigee.momentum()[Trk::px];
+      double py = pPerigee.momentum()[Trk::py];
+      double pt = sqrt(px * px + py * py);
+
+      if (pt < m_ptLowerLimit)
+        {
+	  // out for riming
+	  //            if (msg().level() <= MSG::DEBUG)
+	  //                msg() << "pT=" << pPerigee->pT() << " is lower than limit = " << m_ptLowerLimit << ". Skipping track." << endreq;
+	  continue;
+        }
+/*
+      if (tp_id->trackSummary() == NULL)
+        {
+	  if (msg().level() <= MSG::DEBUG)
+	    msg() << MSG::DEBUG << "Missing trackSummary" << endreq;
+	  continue;
+        }
+*/
+      uint8_t pixel_hits = 0;
+      uint8_t sct_hits = 0;
+      tp_id->summaryValue(pixel_hits,xAOD::numberOfPixelHits);
+      tp_id->summaryValue(pixel_hits,xAOD::numberOfSCTHits);
+
+      int numhits_id = pixel_hits + sct_hits;
+
+
+      if (numhits_id < 5)
+        {
+	  if (msg().level() <= MSG::DEBUG)
+	    msg() << MSG::DEBUG << "Cut on #hits=" << numhits_id << endreq;
+	  continue;
+        }
+
+      bool seenByCalo = false;
+      if (m_pToCalo)
+        {
+            double offset = 0.;
+            const Trk::TrackParameters* calo_local = 0;
+            for (unsigned i = 0; i < m_caloLayers.size(); ++i)
+            {
+                if ( (calo_local = m_pToCalo->extrapolate(*(tp_id->track()), m_caloLayers[i],offset))!=0 ) {
+                    seenByCalo=true;
+                    pt_calo_local = calo_local->position();
+                }
+                //seenByCalo = m_pToCalo->TrackSeenByCalo(tp_id->originalTrack(), m_caloLayers[i], offset, &pt_calo_ctb, &pt_calo_local);
+                if (seenByCalo)
+                    break;
+            }
+        }
+      else
+	seenByCalo = true;
+      if (!seenByCalo)
+        {
+	  if (msg().level() <= MSG::DEBUG)
+	    msg() << MSG::DEBUG << "Not seen by calo" << endreq;
+	  continue;
+        }
+
+      // out for timing
+      //        if (msg().level() <= MSG::DEBUG)
+      //            msg() << MSG::DEBUG << "This TrackParticle is seen by Calo!" << endreq;
+
+      CaloParticle* pParticle = new CaloParticle(tp_id, pt_calo_local.eta(), pt_calo_local.phi());
+      m_caloParticles.push_back(pParticle);
+    }
+}
+
+void TrigMuGirlTool::IsolatedIdTracks(double dR)
+{
+  for (unsigned int i = 0; i < m_caloParticles.size(); i++)
+    {
+      CaloParticle* pParticle1 = m_caloParticles[i];
+      if (!pParticle1->isolated)
+	continue;
+      const xAOD::TrackParticle* tp1 = pParticle1->pTrackParticle;
+      const Trk::Perigee mp1 = tp1->perigeeParameters();
+      double phi1 = mp1.parameters()[Trk::phi];
+      double eta1 = asinh(1. / tan(mp1.parameters()[Trk::theta]));
+      for (unsigned int j = i + 1; j < m_caloParticles.size(); j++)
+        {
+	  CaloParticle* pParticle2 = m_caloParticles[j];
+	  if (!pParticle2->isolated)
+	    continue;
+	  const xAOD::TrackParticle* tp2 = pParticle2->pTrackParticle;
+	  const Trk::Perigee mp2 = tp2->perigeeParameters();
+	  double phi2 = mp2.parameters()[Trk::phi];
+	  double eta2 = asinh(1. / tan(mp2.parameters()[Trk::theta]));
+	  double deta = fabs(eta2 - eta1);
+	  double dphi = fabs(phi2 - phi1);
+	  if (dphi > M_PI)
+	    dphi = 2 * M_PI - dphi;
+	  float dRmu=sqrt(deta * deta + dphi * dphi);
+	  if (sqrt(deta * deta + dphi * dphi) < dR)
+            {
+	      pParticle1->isolated = false;
+	      if (pParticle1->dR > dRmu) pParticle1->dR = dRmu;
+	      pParticle2->isolated = false;
+	      if (pParticle2->dR > dRmu) pParticle2->dR = dRmu;
+            }
+        }
+    }
+}
+
+void TrigMuGirlTool::calculateLHR(CaloParticle* pParticle)
+{
+  const xAOD::TrackParticle* pTrackParticle = pParticle->pTrackParticle;
+  const Trk::Perigee pPerigee = pTrackParticle->perigeeParameters();
+  double charge_id = pPerigee.charge();
+  double qOverP_id = pPerigee.parameters()[Trk::qOverP];
+  double p_id      = fabs(1.0/qOverP_id);
+  double phi_id    = pPerigee.parameters()[Trk::phi];
+  double eta_id    = asinh(1./tan(pPerigee.parameters()[Trk::theta]));
+  double pt_id     = pPerigee.pT();
+
+  if (msg().level() <= MSG::DEBUG)
+    msg() << MSG::DEBUG << "Parameters of isolated tracks seen by calo: " <<
+      " pt =  " << pt_id  <<
+      " eta = " << eta_id <<
+      " phi = " << phi_id <<
+      " charge = " << charge_id << endreq;
+
+  double theLHR = m_pMuLHR->getLHR(m_pClusCollection, eta_id, p_id, pParticle->eta, pParticle->phi);
+  if (msg().level() <= MSG::DEBUG)
+    msg() << MSG::DEBUG << "theLHR = " << theLHR << endreq;
+
+  m_pCandidate->setIsolation(1);
+  m_pCandidate->setLHR(theLHR);
+}
+
+
+bool TrigMuGirlTool::generateMuGirl(MuGirlNS::CandidateSummary* summary)
+{
+  double eta = 999.;
+  //double pt = 0.;
+  if (summary->startFromMF)
+    {
+      if( summary->pMuonFeature != NULL)
+        {
+	  eta = (summary->pMuonFeature)->eta();
+	  //   pt = (summary->pMuonFeature)->pt();
+        }
+    }
+  else
+    {
+      Trk::Perigee seed_perigee = summary->pTrackParticle->perigeeParameters();
+      eta = asinh(1./tan(seed_perigee.parameters()[Trk::theta]));
+      //eta = (summary->pTrackParticle)->measuredPerigee()->eta();
+      //pt = (summary->pTrackParticle)->measuredPerigee()->pT();
+    }
+
+  if (fabs(eta)>2.0 && (summary->numMdtHits <= 2 && summary->numCscSegs == 0 && summary->numTgcEtaHits <= 2 && summary->numTgcPhiHits <= 2 ))
+    return false;
+  if (fabs(eta)<2.0 && summary->numMdtHits<=2)
+    return false;
+
+  if ((summary->innAngle == 999.) && (summary->midAngle == 999.))
+    return false;
+  double value[8];
+  double ANN[2];
+
+  msg()<<MSG::DEBUG<<"generateMuGirl LHR"<<summary->lhr<<"setting it to 0.8"<<endreq;
+  summary->lhr = 0.8;
+
+  m_pANNSelectionTool->evaluateANN(summary,value,ANN);
+  m_pCandidate->setAnn(ANN[0], ANN[1]);
+  summary->nnBarrel = ANN[0];
+  summary->nnEndCap = ANN[1];
+
+  msg() << MSG::DEBUG << " ANN [0] "<<value[0]<< " ANN [1] "<<value[1]<< " ANN [2] "<<value[2]<< " ANN [3] "<<value[3]<< " ANN [4] "<<value[4]<< " ANN [5] "<<value[5] << endreq;
+  //    msg() << MSG::DEBUG << "arikerez "<<value[0]<< " "<<value[1]<< " "<<value[2]<< " "<<value[3]<< " "<<value[4]<< " "<<value[5] << endreq;
+  if (m_doNTuplePerformance)
+    {
+      NN[0]=value[0];
+      NN[1]=value[1];
+      NN[2]=value[2];
+      NN[3]=value[3];
+      NN[4]=value[4];
+      NN[5]=value[5];
+    }
+
+  /*        
+	    if (value[0]>0.08 || //0.004 ||    // BARREL GOOD  PT<10GeV
+	    value[1]>0.11 || //0.004  ||    // BARREL BAD
+	    value[2]>0.15 || //0.004 ||    // REGION OVERLAP
+            value[3]>0.004 ||     // MAGNET OVERLAP
+            value[4]>0.004 ||    // ENDCAP
+            value[5]>0.004 )      // FORWARD
+	    {
+	    msg()<<MSG::DEBUG<<"eTrigEFMuon pass=true"<<endreq;
+	    summary->PassNNsel = true;
+	    m_pCandidate->setPassANN(true);
+	    return true;
+	    }
+	    else 
+	    {
+	    msg()<<MSG::DEBUG<<"eTrigEFMuon pass=false"<<endreq;
+	    summary->PassNNsel = false;
+	    m_pCandidate->setPassANN(false);
+	    return false;
+	    }
+    
+  */
+    
+  if (value[0]<0.2 && //0.004 ||    // BARREL GOOD  PT<10GeV
+      value[1]<0.2 && //0.004  ||    // BARREL BAD
+      value[2]<0.2 && //0.004 ||    // REGION OVERLAP
+      value[3]<0.2 &&     // MAGNET OVERLAP
+      value[4]<0.2 &&    // ENDCAP
+      value[5]<0.2 )      // FORWARD
+    {
+      summary->PassNNsel = false;
+      m_pCandidate->setPassANN(false);
+      return false;
+    }
+  else
+    {
+      summary->PassNNsel = true;
+      m_pCandidate->setPassANN(true);
+      return true;
+    }
+    
+}
+
+void TrigMuGirlTool::fillMuonSegmentColl(std::vector<const Muon::MuonSegment*> muonSegmentList)
+{
+  for (MuGirlNS::MuonSegmentList::const_iterator MuonSegItr=muonSegmentList.begin();  MuonSegItr!=muonSegmentList.end(); MuonSegItr++)
+    {
+      const Muon::MuonSegment* seg = *MuonSegItr;
+      //m_pSegmentCollection->push_back(const_cast <Muon::MuonSegment*>(seg));
+      m_pSegmentManager->setInStore(seg, false);
+    }
+}
+
+
+Rec::TrackParticle* TrigMuGirlTool::TEcreateParticle(const Trk::Track* track,const Trk::VxCandidate* vxCandidate,Trk::TrackParticleOrigin prtOrigin)
+{
+  if (track == 0) return 0;
+  //     MsgStream log(msgSvc(), name());
+  const Trk::Perigee* aMeasPer(0);
+     
+  aMeasPer = dynamic_cast<const Trk::Perigee*>( track->perigeeParameters() );
+  aMeasPer = aMeasPer->clone(); 
+  if (aMeasPer==0) return 0;        
+ 
+  //Creating TrackParticle with a dummy TrackSummary
+  const Trk::TrackSummary* summary=new Trk::TrackSummary;
+  //     summary=new Trk::TrackSummary;
+                
+  // find the first and the last hit in track
+  // we do that the same way as in the track slimming tool!
+  // that way it is also ok on not slimmed tracks!
+  std::vector<const Trk::TrackParameters*> parameters;
+     
+  //     if (m_keepParameters)
+  {
+    const DataVector<const Trk::TrackStateOnSurface>* trackStates = track->trackStateOnSurfaces();
+       
+    const Trk::TrackParameters* first(0) ; 
+       
+    // search first valid TSOS first
+    for ( DataVector<const Trk::TrackStateOnSurface>::const_iterator itTSoS = trackStates->begin(); itTSoS != trackStates->end(); ++itTSoS)
+      {
+	if ( (*itTSoS)->type(Trk::TrackStateOnSurface::Measurement) && (*itTSoS)->trackParameters()!=0 && (*itTSoS)->measurementOnTrack()!=0 )
+	  {
+	    first = (*itTSoS)->trackParameters();
+	    parameters.push_back((*itTSoS)->trackParameters()->clone());
+	    break;
+	  }
+      }
+         
+    // search last valid TSOS first
+    for ( DataVector<const Trk::TrackStateOnSurface>::const_reverse_iterator rItTSoS = trackStates->rbegin(); rItTSoS != trackStates->rend(); ++rItTSoS)
+      {
+	if ( (*rItTSoS)->type(Trk::TrackStateOnSurface::Measurement) && (*rItTSoS)->trackParameters()!=0 && (*rItTSoS)->measurementOnTrack()!=0 )
+	  {
+	    if (!(first == (*rItTSoS)->trackParameters())) parameters.push_back((*rItTSoS)->trackParameters()->clone());
+	    break;
+	  }
+      }
+       
+    // security check:
+    if (parameters.size() > 2) msg() << MSG::WARNING << "More than two additional track parameters to be stored in TrackParticle!" << endreq;
+  }   
+  const Trk::FitQuality* fitQuality = new Trk::FitQuality( (*track->fitQuality()) );
+  return new Rec::TrackParticle(track, prtOrigin, vxCandidate, summary, parameters, aMeasPer,  fitQuality);
+}
+
+
+// for perfo ntuple
+HLT::ErrorCode TrigMuGirlTool::doMuTruthPerformance()
+{
+  int nTruthMu = 0;
+  const McEventCollection* pMcEventCollection = NULL;
+  StatusCode status = m_pEventStore->retrieve(pMcEventCollection, "TruthEvent");
+  if (status.isFailure() || pMcEventCollection == NULL)
+    {
+      msg() << MSG::WARNING << " Cannot retrieve McEventCollection " << endreq;
+      return HLT::SG_ERROR;
+    }
+
+  McEventCollection::const_iterator itMc = pMcEventCollection->begin(), itMc_e = pMcEventCollection->end();
+  for (; itMc != itMc_e; ++itMc)
+    {
+      const HepMC::GenEvent* pGenEvent = *itMc;
+
+      HepMC::GenEvent::particle_const_iterator itPart = pGenEvent->particles_begin(), itPart_e = pGenEvent->particles_end();
+      for (; itPart != itPart_e; ++itPart)
+	{
+	  const HepMC::GenParticle* pPart = *itPart;
+
+	  if (pPart->pdg_id() == -13 || pPart->pdg_id() == 13)
+	    {
+	      int parent_pdg = 0;
+	      if (pPart->production_vertex() != NULL)
+		{
+		  HepMC::GenVertex::particle_iterator itVxPart = pPart->production_vertex()->particles_begin(HepMC::parents), itVxPart_e = pPart->production_vertex()->particles_end(HepMC::parents);
+		  for (; itVxPart != itVxPart_e; ++itVxPart)
+		    {
+		      parent_pdg = (*itVxPart)->pdg_id();
+		    }
+		}
+
+	      ++nTruthMu;
+	      if (m_doNTuplePerformance && m_pTrigMuGirlNtuple)
+		{
+		  double cot=1/tan(2*atan(exp(-pPart->momentum().eta())));
+
+		  status = m_pTrigMuGirlNtuple->fillTruth(nTruthMu,
+							  pPart->momentum().phi(),
+							  cot,
+							  pPart->momentum().eta(),
+							  pPart->momentum().perp(),
+							  pPart->pdg_id(),
+							  parent_pdg);
+		  if (status.isFailure())
+                    {
+		      msg() << MSG::ERROR << " Cannot fill NTuple TRUTH " << endreq;
+		      //delete di_muon; 
+		      return HLT::BAD_JOB_SETUP;
+                    }
+		}
+	    }
+	}
+    }
+  return HLT::OK;
+}
diff --git a/Trigger/TrigAlgorithms/TrigMuGirl/src/TrigPostFex.cxx b/Trigger/TrigAlgorithms/TrigMuGirl/src/TrigPostFex.cxx
new file mode 100644
index 00000000000..b73b122f8d3
--- /dev/null
+++ b/Trigger/TrigAlgorithms/TrigMuGirl/src/TrigPostFex.cxx
@@ -0,0 +1,335 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+/***************************************************************************
+    Authors: E. Reinherz-Aronis, A. Kreisel 
+             This Fex is able to run after both TrigMuGirl and TrigMooHLT
+             for now the code assum it's coming in the same sequqance 
+             as TrigMuGirl or TrigMooHLT 
+***************************************************************************/
+#include "TrigMuGirl/TrigPostFex.h" 
+
+#include "TrigMuonEvent/TrigMuonEFContainer.h"
+
+//for the event info
+#include "StoreGate/StoreGateSvc.h"
+ 
+#include "GaudiKernel/NTuple.h"
+#include "TrigMuGirl/TrigPostFexNtuple.h"
+#include "GeneratorObjects/McEventCollection.h"
+// for second potput object 
+#include "TrigMuonEvent/TrigMuonEFInfoContainer.h"
+#include "TrigMuonEvent/TrigMuonEFInfo.h"
+#include "TrigMuonEvent/TrigMuonEFCbTrack.h"
+
+
+
+TrigPostFex::TrigPostFex(const std::string& name, ISvcLocator* pSvcLocator) :
+  HLT::FexAlgo(name, pSvcLocator),
+    m_pStoreGate        (NULL),
+    m_pTrigPostFexNtuple (NULL)
+{
+
+    declareProperty("MuMuMassMin", m_MassMin = 2800.);
+    declareProperty("MuMuMassMax", m_MassMax = 4000.);
+    declareMonitoredVariable("pT", muon_pT);
+    declareProperty("NtupleName",           m_ntupleName    = "/NTUPLES/POSTFEX/POSTFEX");
+    declareProperty("NtupleTitle",          m_ntupleTitle   = "PostFex");
+    declareProperty("doNTuple",             m_doNTuple      = false);
+    declareProperty("doTruth",              m_doTruth       = false);
+}
+
+TrigPostFex::~TrigPostFex()
+{}
+
+HLT::ErrorCode TrigPostFex::hltInitialize()
+{
+    msg() << MSG::INFO << "Initializing TrigPostFex hello Erez" << endreq;
+    //   StatusCode SCstatus;
+
+    // Initialize NTuple
+    if (m_doNTuple)
+    {
+        m_pTrigPostFexNtuple = new TrigPostFexNtuple(this, ntupleSvc());
+        StatusCode SCstatus = m_pTrigPostFexNtuple->book(m_ntupleName, m_ntupleTitle);
+        if (SCstatus.isFailure() || m_pTrigPostFexNtuple == NULL)
+        {
+            msg()<< MSG::ERROR << "Could not book NTuple " << m_ntupleName << endreq;
+            return HLT::BAD_JOB_SETUP;
+        }
+    }
+
+    return HLT::OK;
+}
+
+HLT::ErrorCode TrigPostFex::hltFinalize()
+{
+    msg() << MSG::INFO << "Finalizing TrigPostFex" << endreq;
+
+    return HLT::OK;
+}
+
+HLT::ErrorCode TrigPostFex::hltExecute(const HLT::TriggerElement* /*inputTE*/, HLT::TriggerElement* outputTE)
+{
+  msg()<<MSG::DEBUG<<"Executing TrigPostFex <--*-->"<<endreq;
+    
+  //  const EventInfo* pEventInfo;
+  eRunNumber=0;
+  eEventNumber=0;
+
+  m_pt.clear();
+  m_cotTh.clear();
+  m_phi.clear(); 
+  m_m.clear();
+  m_charge.clear();
+
+  m_pStoreGate = store();
+
+  if ( m_pStoreGate->retrieve(pEventInfo).isFailure() ) {
+    msg()  << MSG::DEBUG << "Failed to get EventInfo " << endreq;
+  } else {
+    eRunNumber   = pEventInfo->event_ID()->run_number();
+    eEventNumber = pEventInfo->event_ID()->event_number();
+    msg()<<MSG::DEBUG<<"Run "<< eRunNumber<<" Event "<< eEventNumber<<endreq;
+  }
+    
+  HLT::ErrorCode status;
+  // StatusCode   statusfill;
+  whichOutput=0;
+
+  const TrigMuonEFInfoContainer* trackInfoCont = 0;
+  std::vector<const TrigMuonEFInfoContainer*>  vectorOfTrigMuonEFInfo;
+  status=getFeatures(outputTE, vectorOfTrigMuonEFInfo, "eMuonEFInfo");
+  if (status != HLT::OK || vectorOfTrigMuonEFInfo.size()==0) 
+    {
+      msg() << MSG::DEBUG << "Could not retieve vector of TrigMuonEFInfoConatiner "<< endreq;
+      return HLT::MISSING_FEATURE;
+    }
+  else
+    {
+      whichOutput=1;
+
+      if (status != HLT::OK || vectorOfTrigMuonEFInfo.size()==0) 
+	{
+	  msg() << MSG::DEBUG << "Could not retieve vector of TrigMuonEFInfoConatiner "<< endreq;
+	  return HLT::MISSING_FEATURE;
+	}
+  
+      for (unsigned int i=0; i<vectorOfTrigMuonEFInfo.size(); i++)
+	{
+	  msg() << MSG::DEBUG << "Element "<<i<<" of vector of TrigMuonEFInfo containers  "<<endreq;
+	  // Get first (and only) RoI:
+	  trackInfoCont = vectorOfTrigMuonEFInfo[i];
+	  if(!trackInfoCont)
+	    {
+	      msg() << MSG::ERROR
+		    << "Retrieval of TrigMuonEFInfo container from vector failed" << endreq;
+	      return  HLT::NAV_ERROR;
+	    }  
+	  else msg() << MSG::DEBUG << "container OK with size "<<trackInfoCont->size()<< endreq;
+	}
+    }
+
+  // Get vector of pointers to all TrigMuonEF objects linked to the outputTE
+  // if the code isn't in the same sequance as TriMuGirl or TrigMooHLT 
+  // outputTE --> inputTE
+  const TrigMuonEFContainer* trackCont=0;
+  std::vector<const TrigMuonEFContainer*> vectorOfTrigMuonEF;  
+  
+  status=getFeatures(outputTE, vectorOfTrigMuonEF);
+
+  if (status != HLT::OK || vectorOfTrigMuonEF.size()==0) 
+    {
+      msg() << MSG::DEBUG << "Could not retieve vector of TrigMuonEFConatiner "<< endreq;
+      return HLT::MISSING_FEATURE;
+    }
+  
+  for (unsigned int i=0; i<vectorOfTrigMuonEF.size(); i++)
+    {
+      msg() << MSG::DEBUG << "Element "<<i<<" of vector of TrigMuonEF containers  "<<endreq;
+      // Get first (and only) RoI:
+      trackCont = vectorOfTrigMuonEF[i];
+      if(!trackCont)
+	{
+	  msg() << MSG::ERROR
+		<< "Retrieval of TrigMuonEF  container from vector failed" << endreq;
+	  return  HLT::NAV_ERROR;
+	}  
+      else msg() << MSG::DEBUG << "container OK with size "<<trackCont->size()<< endreq;
+    }
+
+
+  if (m_doNTuple)
+    {
+      StatusCode statusfill = m_pTrigPostFexNtuple->fillEvent(eEventNumber,eRunNumber);
+      if (statusfill.isFailure())
+	{
+	  msg() << MSG::ERROR << " Cannot fill NTuple event # " << endreq;
+	  return HLT::BAD_JOB_SETUP;
+	}
+    }
+
+  if (m_doTruth)
+    {
+      if (doMuTruth() != HLT::OK)
+	msg() << MSG::ERROR  << "The doMuTruth status is not Ok" << endreq;
+    }
+ 
+  nMuons=0;
+
+
+  if (whichOutput)
+    {  
+  for (TrigMuonEFInfoContainer::const_iterator tr = trackInfoCont->begin();tr != trackInfoCont->end(); tr++)
+    {
+      TrigMuonEFInfo* eInfo = (*tr);
+      TrigMuonEFCbTrack* trC = eInfo->CombinedTrack();
+	m_pt.push_back( trC->pt());
+	m_cotTh.push_back( trC->cotTh());
+	m_phi.push_back( trC->phi());
+	m_m.push_back( trC->m());
+	m_charge.push_back( trC->charge());
+	if(m_doNTuple)
+	  {
+	    ++nMuons;
+	    // tan(x/2)=sqrt(1+cot**2)-cot
+	    double eta=-log(sqrt(1+(trC->cotTh())*(trC->cotTh()))-(trC->cotTh())); 
+	    StatusCode statusfill = m_pTrigPostFexNtuple->fillReco(nMuons,trC->phi(),trC->cotTh(),eta,trC->pt(), (int)trC->charge());
+	    
+	    if (statusfill.isFailure())
+	      {
+		msg() << MSG::ERROR << " Cannot fill NTuple Reco " << endreq;
+		return HLT::BAD_JOB_SETUP;
+	      }
+	    
+	  } 
+    }
+    }
+  else
+    {
+  for (TrigMuonEFContainer::const_iterator tr = trackCont->begin();tr != trackCont->end(); tr++)
+    {
+      if ((*tr)->MuonCode()<100 && (*tr)->MuonCode() != 5) continue;
+      {
+	m_pt.push_back( (*tr)->pt());
+	m_cotTh.push_back( (*tr)->cotTh());
+	m_phi.push_back( (*tr)->phi());
+	m_m.push_back( (*tr)->m());
+	m_charge.push_back( (*tr)->charge());
+
+	//        IdTracks.push_back((*tr)->indetTrack());
+
+	if(m_doNTuple)
+	  {
+	    ++nMuons;
+	    // tan(x/2)=sqrt(1+cot**2)-cot
+	    double eta=-log(sqrt(1+((*tr)->cotTh())*((*tr)->cotTh()))-((*tr)->cotTh())); 
+	    StatusCode statusfill = m_pTrigPostFexNtuple->fillReco(nMuons,(*tr)->phi(),(*tr)->cotTh(),eta,(*tr)->pt(), (int)(*tr)->charge());
+	    
+	    if (statusfill.isFailure())
+	      {
+		msg() << MSG::ERROR << " Cannot fill NTuple Reco " << endreq;
+		return HLT::BAD_JOB_SETUP;
+	      }
+	    
+	  } 
+      }
+    }
+    }
+
+  muon_pT=-99;
+  NumberOfMuons=-99;
+  NumberOfMuons=m_pt.size();
+  
+  //  StatusCode statusNT; 
+  if (m_doNTuple)
+    {
+      msg() << MSG::DEBUG << " Write Ntuple " << endreq;
+      StatusCode statusNT = m_pTrigPostFexNtuple->writeRecord();
+      if (statusNT.isFailure() || m_pTrigPostFexNtuple == NULL)
+	{
+	  msg() << MSG::ERROR << "TrigPostFex::execute Cannot write NTuple" << endreq;
+	  //delete di_muon;
+	  return HLT::BAD_JOB_SETUP;
+	}
+    }
+
+
+  //  status= attachFeature(outputTE, pOut, "EFMuPairs");
+  
+  m_pt.clear();
+  m_cotTh.clear();
+  m_phi.clear();
+  m_m.clear();
+  m_charge.clear();
+  
+  return HLT::OK;
+}
+HLT::ErrorCode TrigPostFex::doMuTruth()
+{
+    int nTruthMu = 0;
+    const McEventCollection* pMcEventCollection = NULL;
+    StatusCode status = m_pStoreGate->retrieve(pMcEventCollection, "TruthEvent");
+    if (status.isFailure() || pMcEventCollection == NULL)
+    {
+        msg() << MSG::WARNING << " Cannot retrieve McEventCollection " << endreq;
+		return HLT::SG_ERROR;
+    }
+
+	McEventCollection::const_iterator
+		itMc = pMcEventCollection->begin(),
+		itMc_e = pMcEventCollection->end();
+    for (; itMc != itMc_e; ++itMc)
+    {
+        const HepMC::GenEvent* pGenEvent = *itMc;
+
+		HepMC::GenEvent::particle_const_iterator
+			itPart = pGenEvent->particles_begin(),
+			itPart_e = pGenEvent->particles_end();
+        for (; itPart != itPart_e; ++itPart)
+        {
+            const HepMC::GenParticle* pPart = *itPart;
+
+            if (pPart->pdg_id() == -13 || pPart->pdg_id() == 13)
+            {
+                int parent_pdg = 0;
+                if (pPart->production_vertex() != NULL)
+                {
+					HepMC::GenVertex::particle_iterator
+						itVxPart = pPart->production_vertex()->particles_begin(HepMC::parents),
+						itVxPart_e = pPart->production_vertex()->particles_end(HepMC::parents);
+                    for (; itVxPart != itVxPart_e; ++itVxPart)
+                    {
+                        parent_pdg = (*itVxPart)->pdg_id();
+                    }
+                }
+
+                ++nTruthMu;
+                if (m_doNTuple)
+                {
+		  double cot=1/tan(2*atan(exp(-pPart->momentum().eta())));
+
+                    status = m_pTrigPostFexNtuple->fillTruth(nTruthMu,
+                                                        pPart->momentum().phi(),
+                                                        cot,
+                                                        pPart->momentum().eta(),
+                                                        pPart->momentum().perp(),
+                                                        pPart->pdg_id(),
+							    parent_pdg);
+                    if (status.isFailure())
+                    {
+                        msg() << MSG::ERROR << " Cannot fill NTuple TRUTH " << endreq;
+                        //delete di_muon; 
+                        return HLT::BAD_JOB_SETUP;
+                    }
+                }
+            }
+        }
+    }
+    //}
+
+	return HLT::OK;
+}
+
+
diff --git a/Trigger/TrigAlgorithms/TrigMuGirl/src/TrigPostFexNtuple.cxx b/Trigger/TrigAlgorithms/TrigMuGirl/src/TrigPostFexNtuple.cxx
new file mode 100644
index 00000000000..2903359827c
--- /dev/null
+++ b/Trigger/TrigAlgorithms/TrigMuGirl/src/TrigPostFexNtuple.cxx
@@ -0,0 +1,147 @@
+/*
+  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+*/
+
+/*----------------------------------------
+        Authors: Arik Kreisel & Erez Ra
+------------------------------------------*/
+#include "GaudiKernel/ISvcLocator.h"
+#include "GaudiKernel/IDataProviderSvc.h" 
+#include "TrigMuGirl/TrigPostFex.h"
+#include "TrigMuGirl/TrigPostFexNtuple.h"
+#include <math.h>
+
+TrigPostFexNtuple::TrigPostFexNtuple(TrigPostFex* pTrigPostFex, INTupleSvc* pNTupleSvc):
+m_max_pair    (100),
+m_max_dig     (200),
+m_max_idtrack (200),
+m_maxTruthMuons(200),
+m_pTrigPostFex(pTrigPostFex),
+m_pNtuple     (NULL),
+m_pNTupleSvc  (pNTupleSvc)
+{}
+
+StatusCode TrigPostFexNtuple::book(const std::string& ntupleName, const std::string& ntupleTitle)
+{
+    MsgStream log(m_pTrigPostFex->messageService(), m_pTrigPostFex->name());
+    log << MSG::INFO << " CandidateNtuple initialization" << endreq;
+
+    m_ntupleName = ntupleName;
+    m_pNtuple = m_pNTupleSvc->book(m_ntupleName, CLID_ColumnWiseTuple, ntupleTitle);
+    if (m_pNtuple == NULL)
+    {
+        log << MSG::ERROR << " Cannot book Ntuple " << endreq;
+        return StatusCode::FAILURE;
+    }
+    if ( m_pNtuple->addItem("POSTFEX/NumTruthMuon",     m_NumTruthMuon, 0, m_maxTruthMuons).isFailure() ||
+         m_pNtuple->addItem("POSTFEX/TruthMuPt" ,       m_NumTruthMuon, m_TruthMuonPt).isFailure()||
+         m_pNtuple->addItem("POSTFEX/TruthMuPhi" ,      m_NumTruthMuon, m_TruthMuonPhi).isFailure()||
+         m_pNtuple->addItem("POSTFEX/TruthMuCot" ,      m_NumTruthMuon, m_TruthMuonCot).isFailure()||
+         m_pNtuple->addItem("POSTFEX/TruthMuEta" ,      m_NumTruthMuon, m_TruthMuonEta).isFailure()||
+         m_pNtuple->addItem("POSTFEX/TruthMuPdg" ,      m_NumTruthMuon, m_TruthMuonPdg).isFailure()||
+         m_pNtuple->addItem("POSTFEX/TruthMuParentPdg" ,m_NumTruthMuon, m_TruthMuonParentPdg).isFailure())
+    {
+        log << MSG::ERROR << "Cannot addItem(Truth Muons)" << endreq;
+        return StatusCode::FAILURE;
+    }
+
+    if (  m_pNtuple->addItem("POSTFEX/NumRecoMuon",     m_NumRecoMuon, 0, m_maxTruthMuons).isFailure() ||
+         m_pNtuple->addItem("POSTFEX/RecoMuPt" ,       m_NumRecoMuon, m_RecoMuonPt).isFailure()||
+         m_pNtuple->addItem("POSTFEX/RecoMuPhi" ,      m_NumRecoMuon, m_RecoMuonPhi).isFailure()||
+         m_pNtuple->addItem("POSTFEX/RecoMuCot" ,      m_NumRecoMuon, m_RecoMuonCot).isFailure()||
+         m_pNtuple->addItem("POSTFEX/RecoMuEta" ,      m_NumRecoMuon, m_RecoMuonEta).isFailure()||
+	  m_pNtuple->addItem("POSTFEX/RecoMuCharge" ,      m_NumRecoMuon, m_RecoMuonCharge).isFailure())
+    {
+        log << MSG::ERROR << "Cannot addItem(Reco Muons)" << endreq;
+        return StatusCode::FAILURE;
+    }
+
+    if (  m_pNtuple->addItem("POSTFEX/Event",  m_Event).isFailure() ||
+	  m_pNtuple->addItem("POSTFEX/Run",  m_Run).isFailure()) 
+    {
+        log << MSG::ERROR << "Cannot addItem(event number)" << endreq;
+        return StatusCode::FAILURE;
+    }
+
+
+
+    return StatusCode::SUCCESS;
+}
+
+
+StatusCode TrigPostFexNtuple::writeRecord()
+{
+    return m_pNTupleSvc->writeRecord(m_ntupleName);
+}
+StatusCode TrigPostFexNtuple::fillEvent(int event, int run)
+{
+  MsgStream log(m_pTrigPostFex->messageService(), m_pTrigPostFex->name());
+  if (log.level() <= MSG::DEBUG)
+    log << MSG::INFO << "TrigPostFexNtuple::fillEvent(" << event << ")" << endreq;
+	
+  m_Event=event;
+  m_Run=run;
+
+  if (log.level() <= MSG::DEBUG)
+    log << MSG::INFO << "TrigPostFexNtuple::fillTruth done" << endreq;
+  
+return StatusCode::SUCCESS;
+
+}
+
+StatusCode TrigPostFexNtuple::fillTruth(int nMu, double phi, double cot, double eta, double pt, int pdg, int parentPdg)
+{
+        MsgStream log(m_pTrigPostFex->messageService(), m_pTrigPostFex->name());
+        if (log.level() <= MSG::DEBUG)
+            log << MSG::INFO << "TrigPostFexNtuple::fillTruth(" << nMu << ")" << endreq;
+
+        if (nMu > m_maxTruthMuons)
+            return StatusCode::FAILURE;
+
+        m_NumTruthMuon = nMu;
+        m_TruthMuonPt       [nMu-1] = pt;
+        m_TruthMuonCot      [nMu-1] = cot;
+        m_TruthMuonEta      [nMu-1] = eta;
+        m_TruthMuonPhi      [nMu-1] = phi;
+        m_TruthMuonPdg      [nMu-1] = pdg;
+        m_TruthMuonParentPdg[nMu-1] = parentPdg;
+
+	//        log << MSG::DEBUG << " m_NumTruthMuon = " << m_NumTruthMuon <<
+	//                             " m_TruthMuonPt = " << m_TruthMuonPt[nMu-1] <<
+	//                             " m_TruthMuonEta = " << m_TruthMuonEta[nMu-1] <<
+	//                             " m_TruthMuonPhi = " << m_TruthMuonPhi[nMu-1] <<
+	//                             " m_TruthMuonPdg = " << m_TruthMuonPdg[nMu-1] <<
+	//                             " m_TruthMuonParentPdg = " << m_TruthMuonParentPdg[nMu-1] << endreq;
+
+        if (log.level() <= MSG::DEBUG)
+            log << MSG::INFO << "TrigPostFexNtuple::fillTruth done" << endreq;
+        return StatusCode::SUCCESS;
+}
+
+StatusCode TrigPostFexNtuple::fillReco(int nMu, double phi, double cot, double eta, double pt, int charge)
+{
+        MsgStream log(m_pTrigPostFex->messageService(), m_pTrigPostFex->name());
+        if (log.level() <= MSG::DEBUG)
+            log << MSG::INFO << "TrigPostFexNtuple::fillReco(" << nMu << ")" << endreq;
+
+        if (nMu > m_maxTruthMuons)
+            return StatusCode::FAILURE;
+
+        m_NumRecoMuon = nMu;
+        m_RecoMuonPt       [nMu-1] = pt;
+        m_RecoMuonEta      [nMu-1] = eta;
+        m_RecoMuonCot      [nMu-1] = cot;
+        m_RecoMuonPhi      [nMu-1] = phi;
+        m_RecoMuonCharge   [nMu-1] = charge;
+
+	//        log << MSG::DEBUG << " m_NumRecoMuon = " << m_NumRecoMuon <<
+	//                             " m_RecoMuonPt = " << m_RecoMuonPt[nMu-1] <<
+	//                             " m_RecoMuonEta = " << m_RecoMuonEta[nMu-1] <<
+	//                             " m_RecoMuonPhi = " << m_RecoMuonPhi[nMu-1] <<
+	//                             " m_RecoMuonCharge = " << m_RecoMuonCharge[nMu-1] << endreq;
+
+        if (log.level() <= MSG::DEBUG)
+            log << MSG::INFO << "TrigPostFexNtuple::fillReco done" << endreq;
+        return StatusCode::SUCCESS;
+
+}
diff --git a/Trigger/TrigAlgorithms/TrigMuGirl/src/components/TrigMuGirl_entries.cxx b/Trigger/TrigAlgorithms/TrigMuGirl/src/components/TrigMuGirl_entries.cxx
new file mode 100644
index 00000000000..72bb4fb35db
--- /dev/null
+++ b/Trigger/TrigAlgorithms/TrigMuGirl/src/components/TrigMuGirl_entries.cxx
@@ -0,0 +1,25 @@
+/***************************************************************************
+    Authors: E. Reinherz-Aronis, A. Kreisel 
+             based on MuGirl by Shlomit Tarem
+***************************************************************************/
+#include "GaudiKernel/DeclareFactoryEntries.h"
+#include "TrigMuGirl/TrigMuGirl.h"
+#include "TrigMuGirl/TrigPostFex.h"
+#include "TrigMuGirl/TrigMuGirlAlg.h"
+#include "TrigMuGirl/TrigMuGirlTool.h"
+
+
+DECLARE_ALGORITHM_FACTORY( TrigMuGirl )
+DECLARE_ALGORITHM_FACTORY( TrigMuGirlAlg )
+DECLARE_ALGORITHM_FACTORY( TrigPostFex )
+DECLARE_TOOL_FACTORY( TrigMuGirlTool )
+
+DECLARE_FACTORY_ENTRIES( TrigMuGirl ) { 
+
+    DECLARE_ALGORITHM( TrigMuGirl )
+    DECLARE_ALGORITHM( TrigMuGirlAlg )
+    DECLARE_ALGORITHM( TrigPostFex )
+    DECLARE_TOOL( TrigMuGirlTool )
+
+}
+
diff --git a/Trigger/TrigAlgorithms/TrigMuGirl/src/components/TrigMuGirl_load.cxx b/Trigger/TrigAlgorithms/TrigMuGirl/src/components/TrigMuGirl_load.cxx
new file mode 100644
index 00000000000..57631996d03
--- /dev/null
+++ b/Trigger/TrigAlgorithms/TrigMuGirl/src/components/TrigMuGirl_load.cxx
@@ -0,0 +1,8 @@
+/***************************************************************************
+    Authors: E. Reinherz-Aronis, A. Kreisel 
+             based on MuGirl by Shlomit Tarem
+***************************************************************************/
+#include "GaudiKernel/LoadFactoryEntries.h"
+
+LOAD_FACTORY_ENTRIES( TrigMuGirl )
+
-- 
GitLab