Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:26:16

0001 #ifndef RecoMuon_TrackingTools_MuonServiceProxy_H
0002 #define RecoMuon_TrackingTools_MuonServiceProxy_H
0003 
0004 /** \class MuonServiceProxy
0005  *  Class to handle the services needed by the muon reconstruction
0006  *  This class avoid the EventSetup percolation.
0007  *  The update method is called each event in order to update the
0008  *  pointers.
0009  *
0010  *  \author N. Amapane - CERN <nicola.amapane@cern.ch>
0011  *  \author R. Bellan - INFN Torino <riccardo.bellan@cern.ch>
0012  *
0013  *  Modified by C. Calabria
0014  *  Modified by D. Nash
0015  */
0016 
0017 #include "FWCore/Framework/interface/ESHandle.h"
0018 #include "FWCore/Framework/interface/FrameworkfwdMostUsed.h"
0019 #include "FWCore/Utilities/interface/ESGetToken.h"
0020 
0021 // EventSetup data types
0022 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
0023 #include "MagneticField/Engine/interface/MagneticField.h"
0024 #include "RecoMuon/DetLayers/interface/MuonDetLayerGeometry.h"
0025 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
0026 
0027 // EventSetup record types
0028 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
0029 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0030 #include "RecoMuon/Records/interface/MuonRecoGeometryRecord.h"
0031 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
0032 
0033 #include "RecoMuon/Navigation/interface/MuonNavigationSchool.h"
0034 
0035 #include <map>
0036 #include <string>
0037 
0038 class MuonServiceProxy {
0039 public:
0040   enum class UseEventSetupIn { Run, Event, RunAndEvent };
0041 
0042   /// Constructor
0043   MuonServiceProxy(const edm::ParameterSet&,
0044                    edm::ConsumesCollector&&,
0045                    UseEventSetupIn useEventSetupIn = UseEventSetupIn::Event);
0046 
0047   /// Destructor
0048   virtual ~MuonServiceProxy();
0049 
0050   // Operations
0051 
0052   /// update the services each event
0053   void update(const edm::EventSetup& setup, bool duringEvent = true);
0054 
0055   /// get the magnetic field
0056   edm::ESHandle<MagneticField> magneticField() const { return theMGField; }
0057 
0058   /// get the tracking geometry
0059   edm::ESHandle<GlobalTrackingGeometry> trackingGeometry() const { return theTrackingGeometry; }
0060 
0061   /// get the detLayer geometry
0062   edm::ESHandle<MuonDetLayerGeometry> detLayerGeometry() const { return theDetLayerGeometry; }
0063 
0064   /// get the propagator
0065   edm::ESHandle<Propagator> propagator(std::string propagatorName) const;
0066 
0067   /// get the whole EventSetup
0068   /// (Note: this is a dangerous function. I would delete it if modules were
0069   /// not using it. If this function is called for an event where the function
0070   /// 'update' was not called, then the pointer stored in 'theEventSetup' will point to
0071   /// an object that no longer exists even if all the ESHandles are still valid!
0072   /// Be careful. As long as 'update' is called every event and this is only
0073   /// used while processing that single corresponding event, it will work OK...
0074   /// This function also makes it difficult to examine code in a module and
0075   /// understand which parts of a module use the EventSetup to get data.)
0076   const edm::EventSetup& eventSetup() const { return *theEventSetup; }
0077 
0078   /// check if the MuonReco Geometry has been changed
0079   bool isTrackingComponentsRecordChanged() const { return theChangeInTrackingComponentsRecord; }
0080 
0081   const MuonNavigationSchool* muonNavigationSchool() const { return theSchool; }
0082 
0083 private:
0084   class PropagatorInfo {
0085   public:
0086     edm::ESHandle<Propagator> esHandle_;
0087     edm::ESGetToken<Propagator, TrackingComponentsRecord> eventToken_;
0088     edm::ESGetToken<Propagator, TrackingComponentsRecord> runToken_;
0089   };
0090 
0091   using PropagatorMap = std::map<std::string, PropagatorInfo>;
0092 
0093   edm::ESHandle<GlobalTrackingGeometry> theTrackingGeometry;
0094   edm::ESHandle<MagneticField> theMGField;
0095   edm::ESHandle<MuonDetLayerGeometry> theDetLayerGeometry;
0096 
0097   edm::ESGetToken<GlobalTrackingGeometry, GlobalTrackingGeometryRecord> globalTrackingGeometryEventToken_;
0098   edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magneticFieldEventToken_;
0099   edm::ESGetToken<MuonDetLayerGeometry, MuonRecoGeometryRecord> muonDetLayerGeometryEventToken_;
0100 
0101   edm::ESGetToken<GlobalTrackingGeometry, GlobalTrackingGeometryRecord> globalTrackingGeometryRunToken_;
0102   edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magneticFieldRunToken_;
0103   edm::ESGetToken<MuonDetLayerGeometry, MuonRecoGeometryRecord> muonDetLayerGeometryRunToken_;
0104 
0105   const edm::EventSetup* theEventSetup;
0106   bool theMuonNavigationFlag;
0107   bool theRPCLayer;
0108   bool theCSCLayer;
0109   bool theGEMLayer;
0110   bool theME0Layer;
0111   const MuonNavigationSchool* theSchool;
0112 
0113   PropagatorMap thePropagators;
0114 
0115   unsigned long long theCacheId_GTG;
0116   unsigned long long theCacheId_MG;
0117   unsigned long long theCacheId_DG;
0118   unsigned long long theCacheId_P;
0119 
0120   bool theChangeInTrackingComponentsRecord;
0121 };
0122 #endif