Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:07

0001 /*
0002  * OmtfAngleConverter.cpp
0003  *
0004  *  Created on: Jan 14, 2019
0005  *      Author: kbunkow
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   //DT eta bins in the wheel +2
0037   const std::vector<float> bounds = {1.24, 1.14353, 1.09844, 1.05168, 1.00313, 0.952728, 0.90037, 0.8};
0038   //   0.8       -> 73
0039   //   0.85      -> 78
0040   //   0.9265    -> 85
0041   //   0.9779    -> 89.9 -> 90
0042   //   1.0274    -> 94.4 -> 94
0043   //   1.07506   -> 98.9 -> 99
0044   //   1.121     -> 103
0045   //   1.2       -> 110
0046   //   1.25      -> 115
0047   //
0048   // other (1.033) -> 1.033 -> 95
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 }  //namespace
0100 
0101 OmtfAngleConverter::~OmtfAngleConverter() {}
0102 
0103 ///////////////////////////////////////
0104 ///////////////////////////////////////
0105 int OmtfAngleConverter::getGlobalEta(const DTChamberId dTChamberId,
0106                                      const L1MuDTChambThContainer *dtThDigis,
0107                                      int bxNum) const {
0108   //const DTChamberId dTChamberId(aDigi.whNum(),aDigi.stNum(),aDigi.scNum()+1);
0109   DTTrigGeom trig_geom(_geodt->chamber(dTChamberId), false);
0110 
0111   // super layer one is the theta superlayer in a DT chamber
0112   // station 4 does not have a theta super layer
0113   // the BTI index from the theta trigger is an OR of some BTI outputs
0114   // so, we choose the BTI that's in the middle of the group
0115   // as the BTI that we get theta from
0116   // TODO:::::>>> need to make sure this ordering doesn't flip under wheel sign
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   int iEta = 0;
0132   if (bti_group == 511)
0133     iEta = 95;
0134   else if (bti_group == -1 && dTChamberId.station() == 1)
0135     iEta = 92;
0136   else if (bti_group == -1 && dTChamberId.station() == 2)
0137     iEta = 79;
0138   else if (bti_group == -1 && dTChamberId.station() == 3)
0139     iEta = 75;
0140   else if (dTChamberId.station() != 4 && bti_group >= 0) {
0141     unsigned bti_actual = bti_group * NBTI_theta / 7 + NBTI_theta / 14 + 1;
0142     DTBtiId thetaBTI = DTBtiId(dTChamberId, 2, bti_actual);
0143     GlobalPoint theta_gp = trig_geom.CMSPosition(thetaBTI);
0144     iEta = etaVal2Code(fabs(theta_gp.eta()));
0145   }
0146   int signEta = sgn(dTChamberId.wheel());
0147   iEta *= signEta;
0148 
0149   if (config->getStubEtaEncoding() == ProcConfigurationBase::StubEtaEncoding::bits)
0150     return OMTFConfiguration::eta2Bits(abs(iEta));
0151   else if (config->getStubEtaEncoding() == ProcConfigurationBase::StubEtaEncoding::valueP1Scale)
0152     return abs(iEta);
0153 
0154   return 0;
0155 }
0156 
0157 ///////////////////////////////////////
0158 ///////////////////////////////////////
0159 int OmtfAngleConverter::getGlobalEta(unsigned int rawid, const CSCCorrelatedLCTDigi &aDigi, float &r) const {
0160   ///Code taken from GeometryTranslator.
0161   ///Will be replaced by direct CSC phi local to global scale
0162   ///transformation as used in FPGA implementation
0163 
0164   // a lot of this is transcription and consolidation of the CSC
0165   // global phi calculation code
0166   // this works directly with the geometry
0167   // rather than using the old phi luts
0168   const CSCDetId id(rawid);
0169   // we should change this to weak_ptrs at some point
0170   // requires introducing std::shared_ptrs to geometry
0171   auto chamb = _geocsc->chamber(id);
0172   auto layer_geom = chamb->layer(CSCConstants::KEY_ALCT_LAYER)->geometry();
0173   auto layer = chamb->layer(CSCConstants::KEY_ALCT_LAYER);
0174 
0175   const uint16_t halfstrip = aDigi.getStrip();
0176   //const uint16_t pattern = aDigi.getPattern();
0177   const uint16_t keyWG = aDigi.getKeyWG();
0178   //const unsigned maxStrips = layer_geom->numberOfStrips();
0179 
0180   // so we can extend this later
0181   // assume TMB2007 half-strips only as baseline
0182   double offset = 0.0;
0183   //K.B. CSCPatternLUT is removed since CMSSW_11_2_1, but it looks that this offset is effectively not needed here
0184   //offset = CSCPatternLUT::get2007Position(pattern);
0185 
0186   const unsigned halfstrip_offs = unsigned(0.5 + halfstrip + offset);
0187   const unsigned strip = halfstrip_offs / 2 + 1;  // geom starts from 1
0188 
0189   // the rough location of the hit at the ALCT key layer
0190   // we will refine this using the half strip information
0191   const LocalPoint coarse_lp = layer_geom->stripWireGroupIntersection(strip, keyWG);
0192   const GlobalPoint coarse_gp = layer->surface().toGlobal(coarse_lp);
0193 
0194   // the strip width/4.0 gives the offset of the half-strip
0195   // center with respect to the strip center
0196   const double hs_offset = layer_geom->stripPhiPitch() / 4.0;
0197 
0198   // determine handedness of the chamber
0199   const bool ccw = isCSCCounterClockwise(layer);
0200   // we need to subtract the offset of even half strips and add the odd ones
0201   const double phi_offset = ((halfstrip_offs % 2 ? 1 : -1) * (ccw ? -hs_offset : hs_offset));
0202 
0203   // the global eta calculation uses the middle of the strip
0204   // so no need to increment it
0205   const GlobalPoint final_gp(
0206       GlobalPoint::Polar(coarse_gp.theta(), (coarse_gp.phi().value() + phi_offset), coarse_gp.mag()));
0207 
0208   r = final_gp.perp();
0209 
0210   if (config->getStubEtaEncoding() == ProcConfigurationBase::StubEtaEncoding::bits)
0211     return OMTFConfiguration::eta2Bits(abs(etaKeyWG2Code(id, keyWG)));
0212   else if (config->getStubEtaEncoding() == ProcConfigurationBase::StubEtaEncoding::valueP1Scale) {
0213     const LocalPoint lpWg = layer_geom->localCenterOfWireGroup(keyWG);
0214     const GlobalPoint gpWg = layer->surface().toGlobal(lpWg);
0215 
0216     return config->etaToHwEta(abs(gpWg.eta()));
0217   } else {
0218     return 0;
0219   }
0220 }
0221 ///////////////////////////////////////
0222 ///////////////////////////////////////
0223 int OmtfAngleConverter::getGlobalEtaRpc(unsigned int rawid, const unsigned int &strip, float &r) const {
0224   const RPCDetId id(rawid);
0225   auto roll = _georpc->roll(id);
0226   const LocalPoint lp = roll->centreOfStrip((int)strip);
0227   const GlobalPoint gp = roll->toGlobal(lp);
0228 
0229   if (id.region() != 0) {  //outside barrel
0230     r = gp.perp();
0231   }
0232 
0233   if (config->getStubEtaEncoding() == ProcConfigurationBase::StubEtaEncoding::bits)
0234     return OMTFConfiguration::eta2Bits(abs(etaVal2Code(gp.eta())));
0235   else if (config->getStubEtaEncoding() == ProcConfigurationBase::StubEtaEncoding::valueP1Scale)
0236     return abs(config->etaToHwEta((gp.eta())));
0237 
0238   return 0;
0239 }
0240 
0241 ///////////////////////////////////////
0242 ///////////////////////////////////////