Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-01 23:54:13

0001 #ifndef MuonAnalysis_MuonAssociators_interface_PropagateToMuonSetup_h
0002 #define MuonAnalysis_MuonAssociators_interface_PropagateToMuonSetup_h
0003 
0004 /**
0005   \class PropagateToMuonSetup PropagateToMuonSetup.h "MuonAnalysis/MuonAssociators/interface/PropagateToMuonSetup.h" 
0006 
0007   \brief Propagate an object (usually a track) to the second (default) or first muon station.
0008 */
0009 
0010 #include "FWCore/Framework/interface/ESHandle.h"
0011 #include "FWCore/Framework/interface/EventSetup.h"
0012 #include "FWCore/Framework/interface/ConsumesCollector.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0015 #include "FWCore/Utilities/interface/Transition.h"
0016 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0017 #include "MuonAnalysis/MuonAssociators/interface/PropagateToMuon.h"
0018 #include "MuonAnalysis/MuonAssociators/interface/trackStateEnums.h"
0019 #include "RecoMuon/Records/interface/MuonRecoGeometryRecord.h"
0020 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
0021 
0022 template <edm::Transition Tr>
0023 class PropagateToMuonSetupT {
0024 public:
0025   explicit PropagateToMuonSetupT(const edm::ParameterSet &iConfig, edm::ConsumesCollector);
0026   ~PropagateToMuonSetupT() = default;
0027 
0028   /// Call this method at the beginning of each run, to initialize geometry,
0029   /// magnetic field and propagators
0030   PropagateToMuon init(const edm::EventSetup &iSetup) const;
0031   static void fillPSetDescription(edm::ParameterSetDescription &desc) {
0032     desc.add<bool>("useSimpleGeometry", true);
0033     desc.add<bool>("useStation2", true);
0034     desc.add<bool>("fallbackToME1", false);
0035     desc.add<bool>("cosmicPropagationHypothesis", false);
0036     desc.add<bool>("useMB2InOverlap", false);
0037     desc.add<std::string>("useTrack", "tracker");
0038     desc.add<std::string>("useState", "atVertex");
0039     desc.add<edm::ESInputTag>("propagatorAlong", edm::ESInputTag("", "hltESPSteppingHelixPropagatorAlong"));
0040     desc.add<edm::ESInputTag>("propagatorAny", edm::ESInputTag("", "SteppingHelixPropagatorAny"));
0041     desc.add<edm::ESInputTag>("propagatorOpposite", edm::ESInputTag("", "hltESPSteppingHelixPropagatorOpposite"));
0042   }
0043 
0044 private:
0045   /// Use simplified geometry (cylinders and disks, not individual chambers)
0046   const bool useSimpleGeometry_;
0047 
0048   /// Propagate to MB2 (default) instead of MB1
0049   const bool useMB2_;
0050 
0051   /// Fallback to ME1 if propagation to ME2 fails
0052   const bool fallbackToME1_;
0053 
0054   /// Labels for input collections
0055   WhichTrack whichTrack_;
0056   WhichState whichState_;
0057 
0058   /// for cosmics, some things change: the along-opposite is not in-out, nor the innermost/outermost states are in-out really
0059   const bool cosmicPropagation_;
0060 
0061   const bool useMB2InOverlap_;
0062 
0063   const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magfieldToken_;
0064   const edm::ESGetToken<Propagator, TrackingComponentsRecord> propagatorToken_, propagatorAnyToken_,
0065       propagatorOppositeToken_;
0066   const edm::ESGetToken<MuonDetLayerGeometry, MuonRecoGeometryRecord> muonGeometryToken_;
0067 };
0068 
0069 template <edm::Transition Tr>
0070 PropagateToMuonSetupT<Tr>::PropagateToMuonSetupT(const edm::ParameterSet &iConfig, edm::ConsumesCollector iC)
0071     : useSimpleGeometry_(iConfig.getParameter<bool>("useSimpleGeometry")),
0072       useMB2_(iConfig.getParameter<bool>("useStation2")),
0073       fallbackToME1_(iConfig.getParameter<bool>("fallbackToME1")),
0074       whichTrack_(None),
0075       whichState_(AtVertex),
0076       cosmicPropagation_(iConfig.getParameter<bool>("cosmicPropagationHypothesis")),
0077       useMB2InOverlap_(iConfig.getParameter<bool>("useMB2InOverlap")),
0078       magfieldToken_(iC.esConsumes<Tr>()),
0079       propagatorToken_(iC.esConsumes<Tr>(iConfig.getParameter<edm::ESInputTag>("propagatorAlong"))),
0080       propagatorAnyToken_(iC.esConsumes<Tr>(iConfig.getParameter<edm::ESInputTag>("propagatorAny"))),
0081       propagatorOppositeToken_(iC.esConsumes<Tr>(iConfig.getParameter<edm::ESInputTag>("propagatorOpposite"))),
0082       muonGeometryToken_(iC.esConsumes<Tr>()) {
0083   std::string whichTrack = iConfig.getParameter<std::string>("useTrack");
0084   if (whichTrack == "none") {
0085     whichTrack_ = None;
0086   } else if (whichTrack == "tracker") {
0087     whichTrack_ = TrackerTk;
0088   } else if (whichTrack == "muon") {
0089     whichTrack_ = MuonTk;
0090   } else if (whichTrack == "global") {
0091     whichTrack_ = GlobalTk;
0092   } else
0093     throw cms::Exception("Configuration") << "Parameter 'useTrack' must be 'none', 'tracker', 'muon', 'global'\n";
0094   if (whichTrack_ != None) {
0095     std::string whichState = iConfig.getParameter<std::string>("useState");
0096     if (whichState == "atVertex") {
0097       whichState_ = AtVertex;
0098     } else if (whichState == "innermost") {
0099       whichState_ = Innermost;
0100     } else if (whichState == "outermost") {
0101       whichState_ = Outermost;
0102     } else
0103       throw cms::Exception("Configuration") << "Parameter 'useState' must be 'atVertex', 'innermost', "
0104                                                "'outermost'\n";
0105   }
0106   if (cosmicPropagation_ && (whichTrack_ == None || whichState_ == AtVertex)) {
0107     throw cms::Exception("Configuration") << "When using 'cosmicPropagationHypothesis' useTrack must not be "
0108                                              "'none', and the state must not be 'atVertex'\n";
0109   }
0110 }
0111 
0112 template <edm::Transition Tr>
0113 PropagateToMuon PropagateToMuonSetupT<Tr>::init(const edm::EventSetup &iSetup) const {
0114   auto const magfield = iSetup.getHandle(magfieldToken_);
0115   auto const propagator = iSetup.getHandle(propagatorToken_);
0116   auto const propagatorOpposite = iSetup.getHandle(propagatorOppositeToken_);
0117   auto const propagatorAny = iSetup.getHandle(propagatorAnyToken_);
0118   auto const muonGeometry = iSetup.getHandle(muonGeometryToken_);
0119 
0120   return PropagateToMuon(magfield,
0121                          propagator,
0122                          propagatorAny,
0123                          propagatorOpposite,
0124                          muonGeometry,
0125                          useSimpleGeometry_,
0126                          useMB2_,
0127                          fallbackToME1_,
0128                          whichTrack_,
0129                          whichState_,
0130                          cosmicPropagation_,
0131                          useMB2InOverlap_);
0132 }
0133 
0134 using PropagateToMuonSetup = PropagateToMuonSetupT<edm::Transition::Event>;
0135 
0136 #endif