File indexing completed on 2024-05-15 04:21:50
0001
0002
0003
0004
0005
0006
0007
0008 #include "L1Trigger/L1TMuonOverlapPhase1/interface/Omtf/OmtfAngleConverter.h"
0009 #include "L1Trigger/L1TMuonOverlapPhase1/interface/Omtf/OMTFConfiguration.h"
0010
0011 #include "FWCore/Framework/interface/EventSetup.h"
0012 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0013
0014 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
0015 #include "DataFormats/CSCDigi/interface/CSCConstants.h"
0016
0017 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0018 #include "L1Trigger/DTUtilities/interface/DTTrigGeom.h"
0019 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
0020
0021 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigi.h"
0022 #include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambPhDigi.h"
0023 #include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambThContainer.h"
0024 #include "DataFormats/RPCDigi/interface/RPCDigi.h"
0025
0026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0027
0028 #include <cmath>
0029
0030 namespace {
0031 template <typename T>
0032 int sgn(T val) {
0033 return (T(0) < val) - (val < T(0));
0034 }
0035
0036
0037 const std::vector<float> bounds = {1.24, 1.14353, 1.09844, 1.05168, 1.00313, 0.952728, 0.90037, 0.8};
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050 int etaVal2Bit(float eta) { return bounds.rend() - std::lower_bound(bounds.rbegin(), bounds.rend(), fabs(eta)); }
0051
0052 int etaVal2Code(double etaVal) {
0053 int sign = sgn(etaVal);
0054 int bit = etaVal2Bit(fabs(etaVal));
0055 int code = OMTFConfiguration::etaBit2Code(bit);
0056 return sign * code;
0057 }
0058
0059 int etaKeyWG2Code(const CSCDetId &detId, uint16_t keyWG) {
0060 signed int etaCode = 121;
0061 if (detId.station() == 1 && detId.ring() == 2) {
0062 if (keyWG < 49)
0063 etaCode = 121;
0064 else if (keyWG <= 57)
0065 etaCode = OMTFConfiguration::etaBit2Code(0);
0066 else if (keyWG <= 63)
0067 etaCode = OMTFConfiguration::etaBit2Code(1);
0068 } else if (detId.station() == 1 && detId.ring() == 3) {
0069 if (keyWG <= 2)
0070 etaCode = OMTFConfiguration::etaBit2Code(2);
0071 else if (keyWG <= 8)
0072 etaCode = OMTFConfiguration::etaBit2Code(3);
0073 else if (keyWG <= 15)
0074 etaCode = OMTFConfiguration::etaBit2Code(4);
0075 else if (keyWG <= 23)
0076 etaCode = OMTFConfiguration::etaBit2Code(5);
0077 else if (keyWG <= 31)
0078 etaCode = OMTFConfiguration::etaBit2Code(6);
0079 } else if ((detId.station() == 2 || detId.station() == 3) && detId.ring() == 2) {
0080 if (keyWG < 24)
0081 etaCode = 121;
0082 else if (keyWG <= 29)
0083 etaCode = OMTFConfiguration::etaBit2Code(0);
0084 else if (keyWG <= 43)
0085 etaCode = OMTFConfiguration::etaBit2Code(1);
0086 else if (keyWG <= 49)
0087 etaCode = OMTFConfiguration::etaBit2Code(2);
0088 else if (keyWG <= 56)
0089 etaCode = OMTFConfiguration::etaBit2Code(3);
0090 else if (keyWG <= 63)
0091 etaCode = OMTFConfiguration::etaBit2Code(4);
0092 }
0093
0094 if (detId.endcap() == 2)
0095 etaCode *= -1;
0096 return etaCode;
0097 }
0098
0099 }
0100
0101 OmtfAngleConverter::~OmtfAngleConverter() {}
0102
0103
0104
0105 int OmtfAngleConverter::getGlobalEta(const DTChamberId dTChamberId,
0106 const L1MuDTChambThContainer *dtThDigis,
0107 int bxNum) const {
0108
0109 DTTrigGeom trig_geom(_geodt->chamber(dTChamberId), false);
0110
0111
0112
0113
0114
0115
0116
0117 const int NBTI_theta = ((dTChamberId.station() != 4) ? trig_geom.nCell(2) : trig_geom.nCell(3));
0118
0119 const L1MuDTChambThDigi *theta_segm =
0120 dtThDigis->chThetaSegm(dTChamberId.wheel(), dTChamberId.station(), dTChamberId.sector() - 1, bxNum);
0121
0122 int bti_group = -1;
0123 if (theta_segm) {
0124 for (unsigned int i = 0; i < 7; ++i)
0125 if (theta_segm->position(i) && bti_group < 0)
0126 bti_group = i;
0127 else if (theta_segm->position(i) && bti_group > -1)
0128 bti_group = 511;
0129 }
0130
0131
0132 int iEta = 0;
0133 if (bti_group == 511)
0134 iEta = 95;
0135 else if (bti_group == -1 && dTChamberId.station() == 1)
0136 iEta = 92;
0137 else if (bti_group == -1 && dTChamberId.station() == 2)
0138 iEta = 79;
0139 else if (bti_group == -1 && dTChamberId.station() == 3)
0140 iEta = 75;
0141 else if (dTChamberId.station() != 4 && bti_group >= 0) {
0142 unsigned bti_actual = bti_group * NBTI_theta / 7 + NBTI_theta / 14 + 1;
0143 DTBtiId thetaBTI = DTBtiId(dTChamberId, 2, bti_actual);
0144 GlobalPoint theta_gp = trig_geom.CMSPosition(thetaBTI);
0145 iEta = etaVal2Code(fabs(theta_gp.eta()));
0146 }
0147 int signEta = sgn(dTChamberId.wheel());
0148 iEta *= signEta;
0149
0150 if (config->getStubEtaEncoding() == ProcConfigurationBase::StubEtaEncoding::bits)
0151 return OMTFConfiguration::eta2Bits(abs(iEta));
0152 else if (config->getStubEtaEncoding() == ProcConfigurationBase::StubEtaEncoding::valueP1Scale)
0153 return abs(iEta);
0154
0155 return 0;
0156 }
0157
0158
0159
0160 int OmtfAngleConverter::getGlobalEta(unsigned int rawid, const CSCCorrelatedLCTDigi &aDigi, float &r) const {
0161
0162
0163
0164
0165
0166
0167
0168
0169 const CSCDetId id(rawid);
0170
0171
0172 auto chamb = _geocsc->chamber(id);
0173 auto layer_geom = chamb->layer(CSCConstants::KEY_ALCT_LAYER)->geometry();
0174 auto layer = chamb->layer(CSCConstants::KEY_ALCT_LAYER);
0175
0176 const uint16_t halfstrip = aDigi.getStrip();
0177
0178 const uint16_t keyWG = aDigi.getKeyWG();
0179
0180
0181
0182
0183 double offset = 0.0;
0184
0185
0186
0187 const unsigned halfstrip_offs = unsigned(0.5 + halfstrip + offset);
0188 const unsigned strip = halfstrip_offs / 2 + 1;
0189
0190
0191
0192 const LocalPoint coarse_lp = layer_geom->stripWireGroupIntersection(strip, keyWG);
0193 const GlobalPoint coarse_gp = layer->surface().toGlobal(coarse_lp);
0194
0195
0196
0197 const double hs_offset = layer_geom->stripPhiPitch() / 4.0;
0198
0199
0200 const bool ccw = isCSCCounterClockwise(layer);
0201
0202 const double phi_offset = ((halfstrip_offs % 2 ? 1 : -1) * (ccw ? -hs_offset : hs_offset));
0203
0204
0205
0206 const GlobalPoint final_gp(
0207 GlobalPoint::Polar(coarse_gp.theta(), (coarse_gp.phi().value() + phi_offset), coarse_gp.mag()));
0208
0209
0210 const LocalPoint lpWg = layer_geom->localCenterOfWireGroup(keyWG);
0211 const GlobalPoint gpWg = layer->surface().toGlobal(lpWg);
0212 r = round(gpWg.perp());
0213
0214 if (config->getStubEtaEncoding() == ProcConfigurationBase::StubEtaEncoding::bits)
0215 return OMTFConfiguration::eta2Bits(abs(etaKeyWG2Code(id, keyWG)));
0216 else if (config->getStubEtaEncoding() == ProcConfigurationBase::StubEtaEncoding::valueP1Scale) {
0217 return config->etaToHwEta(abs(gpWg.eta()));
0218 } else {
0219 return 0;
0220 }
0221 }
0222
0223
0224 int OmtfAngleConverter::getGlobalEtaRpc(unsigned int rawid, const unsigned int &strip, float &r) const {
0225 const RPCDetId id(rawid);
0226 auto roll = _georpc->roll(id);
0227 const LocalPoint lp = roll->centreOfStrip((int)strip);
0228 const GlobalPoint gp = roll->toGlobal(lp);
0229
0230 if (id.region() != 0) {
0231 r = gp.perp();
0232 }
0233
0234 if (config->getStubEtaEncoding() == ProcConfigurationBase::StubEtaEncoding::bits)
0235 return OMTFConfiguration::eta2Bits(abs(etaVal2Code(gp.eta())));
0236 else if (config->getStubEtaEncoding() == ProcConfigurationBase::StubEtaEncoding::valueP1Scale)
0237 return abs(config->etaToHwEta((gp.eta())));
0238
0239 return 0;
0240 }
0241
0242
0243