File indexing completed on 2024-04-06 12:06:31
0001 #ifndef MuNtuple_MuNtupleUtils_h
0002 #define MuNtuple_MuNtupleUtils_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/Utilities/interface/InputTag.h"
0019 #include "FWCore/Framework/interface/ESHandle.h"
0020 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0021 #include "FWCore/Framework/interface/ConsumesCollector.h"
0022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0023
0024 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0025 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0026
0027 #include <array>
0028 #include <string>
0029
0030 class L1MuDTChambPhDigi;
0031 class L1Phase2MuDTPhDigi;
0032
0033 namespace nano_mu {
0034
0035 template <class T>
0036 class EDTokenHandle {
0037 public:
0038
0039 EDTokenHandle(const edm::ParameterSet& config, edm::ConsumesCollector&& collector, std::string name)
0040 : m_name{name}, m_inputTag{config.getParameter<edm::InputTag>(name)} {
0041 if (m_inputTag.label() != "none") {
0042 m_token = collector.template consumes<T>(m_inputTag);
0043 }
0044 }
0045
0046
0047
0048
0049 auto conditionalGet(const edm::Event& ev) const {
0050 edm::Handle<T> collection;
0051
0052 if (!m_token.isUninitialized() && !ev.getByToken(m_token, collection))
0053 edm::LogError("") << "[EDTokenHandle]::conditionalGet: " << m_inputTag.label()
0054 << " collection does not exist !!!";
0055
0056 return collection;
0057 }
0058
0059 private:
0060 std::string m_name;
0061 edm::InputTag m_inputTag;
0062 edm::EDGetTokenT<T> m_token;
0063 };
0064
0065 template <class T, class R, edm::Transition TR = edm::Transition::Event>
0066 class ESTokenHandle {
0067 public:
0068
0069 ESTokenHandle(edm::ConsumesCollector&& collector, const std::string& label = "")
0070 : m_token{collector.template esConsumes<TR>(edm::ESInputTag{"", label})} {}
0071
0072
0073 void getFromES(const edm::EventSetup& environment) { m_handle = environment.getHandle(m_token); }
0074
0075
0076 bool isValid() { return m_handle.isValid(); }
0077
0078
0079 T const* operator->() { return m_handle.product(); }
0080
0081 private:
0082 edm::ESGetToken<T, R> m_token;
0083 edm::ESHandle<T> m_handle;
0084 };
0085
0086 class DTTrigGeomUtils {
0087 public:
0088 struct chambCoord {
0089 double pos{};
0090 double dir{};
0091 };
0092
0093
0094 DTTrigGeomUtils(edm::ConsumesCollector&& collector, bool dirInDeg = true);
0095
0096
0097 chambCoord trigToReco(const L1MuDTChambPhDigi* trig);
0098
0099
0100 chambCoord trigToReco(const L1Phase2MuDTPhDigi* trig);
0101
0102
0103 bool hasPosRF(int wh, int sec) { return wh > 0 || (wh == 0 && sec % 4 > 1); };
0104
0105
0106 void getFromES(const edm::Run& run, const edm::EventSetup& environment) {
0107 m_dtGeom.getFromES(environment);
0108 for (int i_st = 0; i_st != 4; ++i_st) {
0109 const DTChamberId chId(-2, i_st + 1, 4);
0110 const DTChamber* chamb = m_dtGeom->chamber(chId);
0111 const DTSuperLayer* sl1 = chamb->superLayer(DTSuperLayerId(chId, 1));
0112 const DTSuperLayer* sl3 = chamb->superLayer(DTSuperLayerId(chId, 3));
0113 m_zsl1[i_st] = chamb->surface().toLocal(sl1->position()).z();
0114 m_zsl3[i_st] = chamb->surface().toLocal(sl3->position()).z();
0115 m_zcn[i_st] = 0.5 * (m_zsl1[i_st] + m_zsl3[i_st]);
0116 }
0117 };
0118
0119 private:
0120 ESTokenHandle<DTGeometry, MuonGeometryRecord, edm::Transition::BeginRun> m_dtGeom;
0121
0122 std::array<double, 4> m_zcn;
0123 std::array<double, 4> m_zsl1;
0124 std::array<double, 4> m_zsl3;
0125
0126 static constexpr double PH1_PHI_R = 4096.;
0127 static constexpr double PH1_PHIB_R = 512.;
0128
0129 static constexpr double PH2_PHI_R = 65536. / 0.8;
0130 static constexpr double PH2_PHIB_R = 2048. / 1.4;
0131 };
0132
0133 }
0134
0135 #endif