Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-15 04:21:50

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   //TODO why bti_group == 511 (meaning there is more then one bit fired) is converted into 95, but not into middle of the chamber?
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   ///Code taken from GeometryTranslator.
0162   ///Will be replaced by direct CSC phi local to global scale
0163   ///transformation as used in FPGA implementation
0164 
0165   // a lot of this is transcription and consolidation of the CSC
0166   // global phi calculation code
0167   // this works directly with the geometry
0168   // rather than using the old phi luts
0169   const CSCDetId id(rawid);
0170   // we should change this to weak_ptrs at some point
0171   // requires introducing std::shared_ptrs to geometry
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   //const uint16_t pattern = aDigi.getPattern();
0178   const uint16_t keyWG = aDigi.getKeyWG();
0179   //const unsigned maxStrips = layer_geom->numberOfStrips();
0180 
0181   // so we can extend this later
0182   // assume TMB2007 half-strips only as baseline
0183   double offset = 0.0;
0184   //K.B. CSCPatternLUT is removed since CMSSW_11_2_1, but it looks that this offset is effectively not needed here
0185   //offset = CSCPatternLUT::get2007Position(pattern);
0186 
0187   const unsigned halfstrip_offs = unsigned(0.5 + halfstrip + offset);
0188   const unsigned strip = halfstrip_offs / 2 + 1;  // geom starts from 1
0189 
0190   // the rough location of the hit at the ALCT key layer
0191   // we will refine this using the half strip information
0192   const LocalPoint coarse_lp = layer_geom->stripWireGroupIntersection(strip, keyWG);
0193   const GlobalPoint coarse_gp = layer->surface().toGlobal(coarse_lp);
0194 
0195   // the strip width/4.0 gives the offset of the half-strip
0196   // center with respect to the strip center
0197   const double hs_offset = layer_geom->stripPhiPitch() / 4.0;
0198 
0199   // determine handedness of the chamber
0200   const bool ccw = isCSCCounterClockwise(layer);
0201   // we need to subtract the offset of even half strips and add the odd ones
0202   const double phi_offset = ((halfstrip_offs % 2 ? 1 : -1) * (ccw ? -hs_offset : hs_offset));
0203 
0204   // the global eta calculation uses the middle of the strip
0205   // so no need to increment it
0206   const GlobalPoint final_gp(
0207       GlobalPoint::Polar(coarse_gp.theta(), (coarse_gp.phi().value() + phi_offset), coarse_gp.mag()));
0208 
0209   //TODO for phase 2, add firmware like, fixed point conversion from keyWG to eta and r
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) {  //outside barrel
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 ///////////////////////////////////////