Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-04-21 02:53:15

0001 #include "L1Trigger/CSCTrackFinder/interface/CSCSectorReceiverMiniLUT.h"
0002 #include "L1Trigger/CSCTriggerPrimitives/interface/CSCPatternBank.h"
0003 #include "DataFormats/L1CSCTrackFinder/interface/CSCBitWidths.h"
0004 #include "DataFormats/L1CSCTrackFinder/interface/CSCTFConstants.h"
0005 #include "DataFormats/CSCDigi/interface/CSCConstants.h"
0006 
0007 #include "Geometry/CSCGeometry/interface/CSCLayerGeometry.h"
0008 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
0009 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0010 
0011 #include "DataFormats/MuonDetId/interface/CSCTriggerNumbering.h"
0012 
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014 
0015 #include <fstream>
0016 #include <cmath>
0017 
0018 lclphidat CSCSectorReceiverMiniLUT::calcLocalPhiMini(unsigned theadd, const bool gangedME1a) {
0019   // This method is ripped from CSCSectorReceverLUT.cc with minor changes
0020 
0021   lclphidat data;
0022 
0023   constexpr int maxPhiL = 1 << CSCBitWidths::kLocalPhiDataBitWidth;
0024   unsigned short int pattern = ((theadd >> 8) & 0xf);
0025   unsigned short int strip = (theadd & 0xff);
0026 
0027   if (strip < 2 * (CSCConstants::MAX_NUM_STRIPS_RUN1 * 7 / 5) &&
0028       pattern <
0029           CSCConstants::
0030               NUM_CLCT_PATTERNS) {  // MDG, DA and RW, for ME1 we have 7CFEBs and not just 5, so the num_strips can go up to 16 * 7 but only for ME1
0031     data.phi_local = gangedME1a ? static_cast<unsigned>((lcl_phi_param0[pattern] + strip) * lcl_phi_param1)
0032                                 : static_cast<unsigned>((lcl_phi_param0[pattern] + strip) * 0.625 * lcl_phi_param1);
0033     //DA and MDG, rescale range of local phi so ME1/1b fits in 0-511
0034   } else
0035     edm::LogWarning("CSCSectorReceiverMiniLUT") << "+++ Value of strip, " << strip << ", exceeds max allowed, "
0036                                                 << 2 * CSCConstants::MAX_NUM_STRIPS_RUN1 - 1 << " +++\n";
0037 
0038   if (data.phi_local >= maxPhiL)
0039     edm::LogWarning("CSCSectorReceiverMiniLUT")
0040         << "+++ Value of phi_local, " << data.phi_local << ", exceeds max allowed, "
0041         << CSCConstants::NUM_CLCT_PATTERNS - 1 << " +++\n";
0042 
0043   //  data.phi_bend_local = 0;
0044   // Just pass through all bits of pattern as bend angle (so 2 MSB unfilled)
0045   data.phi_bend_local = pattern & 0x3F;
0046 
0047   return data;
0048 }
0049 
0050 global_eta_data CSCSectorReceiverMiniLUT::calcGlobalEtaMEMini(unsigned short endcap,
0051                                                               unsigned short sector,
0052                                                               unsigned short station,
0053                                                               unsigned short subsector,
0054                                                               unsigned theadd,
0055                                                               const bool gangedME1a) {
0056   if (endcap < 1 || endcap > 2)
0057     edm::LogWarning("CSCSectorReceiverMiniLUT")
0058         << "+++ Value of endcap, " << endcap << ", is out of bounds, [1, 2] +++\n";
0059   if (sector < 1 || sector > 6)
0060     edm::LogWarning("CSCSectorReceiverMiniLUT")
0061         << "+++ Value of sector, " << sector << ", is out of bounds, [1, 6] +++\n";
0062   if (station < 1 || station > 4)
0063     edm::LogWarning("CSCSectorReceiverMiniLUT")
0064         << "+++ Value of station, " << station << ", is out of bounds, [1, 4] +++\n";
0065 
0066   gbletadat data(0);
0067 
0068   unsigned short int tcscid = ((theadd >> 15) & 0xf);
0069   unsigned short int lclPhi = ((theadd >> 6) & 0x3);
0070   unsigned short int WG = ((theadd >> 8) & 0x7f);
0071   unsigned short int bend = ((theadd)&0x3f);
0072 
0073   int eta_temp = 999, eta_min = 999, eta_max = 999;
0074 
0075   if ((tcscid > 0) && (tcscid <= 12) && (WG < CSCConstants::MAX_NUM_WIREGROUPS)) {
0076     unsigned short int cscid = (tcscid > 9) ? tcscid - 9 : tcscid;
0077     if (station == 1) {
0078       unsigned short int lclPhip = 0;
0079       if (lclPhi == 1 || lclPhi == 3)
0080         lclPhip = 2;
0081       // use only eta correction for first and last third of ME1/1 chamber since local phi scaling changed
0082       if (gangedME1a) {
0083         eta_temp =
0084             (gbl_eta_params[endcap - 1][sector - 1][station - 1][subsector - 1][lclPhi][cscid - 1][0] +
0085              gbl_eta_params[endcap - 1][sector - 1][station - 1][subsector - 1][lclPhi][cscid - 1][1] *
0086                  log(gbl_eta_params[endcap - 1][sector - 1][station - 1][subsector - 1][lclPhi][cscid - 1][2] + WG));
0087         eta_min = gbl_eta_bounds[endcap - 1][sector - 1][station - 1][subsector - 1][lclPhi][cscid - 1][0];
0088         eta_max = gbl_eta_bounds[endcap - 1][sector - 1][station - 1][subsector - 1][lclPhi][cscid - 1][1];
0089       } else {  // DA and MDG, if unganged replace "lclPhi" index with "lclPhip"
0090         eta_temp =
0091             (gbl_eta_params[endcap - 1][sector - 1][station - 1][subsector - 1][lclPhip][cscid - 1][0] +
0092              gbl_eta_params[endcap - 1][sector - 1][station - 1][subsector - 1][lclPhip][cscid - 1][1] *
0093                  log(gbl_eta_params[endcap - 1][sector - 1][station - 1][subsector - 1][lclPhip][cscid - 1][2] + WG));
0094         eta_min = gbl_eta_bounds[endcap - 1][sector - 1][station - 1][subsector - 1][lclPhip][cscid - 1][0];
0095         eta_max = gbl_eta_bounds[endcap - 1][sector - 1][station - 1][subsector - 1][lclPhip][cscid - 1][1];
0096       }
0097 
0098       // add offset to ME+11a, subtract for ME-11a (wire tilt and strip direction)1
0099       // only is ganged
0100       if (gangedME1a && (tcscid < 4) && (lclPhi == 3)) {
0101         if (endcap == 1)
0102           eta_temp += 3;
0103         else
0104           eta_temp -= 3;
0105       }
0106     } else {
0107       eta_temp = (gbl_eta_params[endcap - 1][sector - 1][station - 1][0][lclPhi][cscid - 1][0] +
0108                   gbl_eta_params[endcap - 1][sector - 1][station - 1][0][lclPhi][cscid - 1][1] *
0109                       log(gbl_eta_params[endcap - 1][sector - 1][station - 1][0][lclPhi][cscid - 1][2] + WG));
0110       eta_min = gbl_eta_bounds[endcap - 1][sector - 1][station - 1][0][lclPhi][cscid - 1][0];
0111       eta_max = gbl_eta_bounds[endcap - 1][sector - 1][station - 1][0][lclPhi][cscid - 1][1];
0112     }
0113   } else {
0114     edm::LogWarning("CSCSectorReceiverMiniLUT")
0115         << "+++ Value of cscid, " << tcscid << ", is out of bounds, [1, 9] -- or --"
0116         << " Value of wire group, " << WG << ", exceeds max allowed, " << CSCConstants::MAX_NUM_WIREGROUPS << " +++\n";
0117   }
0118 
0119   // protect from negative numbers.  If the value of eta_temp is <0, set global eta to the minimum value
0120   if ((eta_temp >= eta_min) && (eta_temp <= eta_max))
0121     data.global_eta = eta_temp;
0122   else if (eta_temp < eta_min)
0123     data.global_eta = eta_min;
0124   else
0125     data.global_eta = eta_max;
0126 
0127   //  data.global_bend = 0;
0128   // Just pass through lowest 5 bits of local bend (drop 1 MSB)
0129   data.global_bend = bend & 0x1F;
0130 
0131   return data;
0132 }
0133 
0134 global_phi_data CSCSectorReceiverMiniLUT::calcGlobalPhiMEMini(unsigned short endcap,
0135                                                               unsigned short sector,
0136                                                               unsigned short station,
0137                                                               unsigned short subsector,
0138                                                               unsigned theadd,
0139                                                               const bool gangedME1a) {
0140   if (endcap < 1 || endcap > 2)
0141     edm::LogWarning("CSCSectorReceiverMiniLUT")
0142         << "+++ Value of endcap, " << endcap << ", is out of bounds, [1, 2] +++\n";
0143   if (sector < 1 || sector > 6)
0144     edm::LogWarning("CSCSectorReceiverMiniLUT")
0145         << "+++ Value of sector, " << sector << ", is out of bounds, [1, 6] +++\n";
0146   if (station < 1 || station > 4)
0147     edm::LogWarning("CSCSectorReceiverMiniLUT")
0148         << "+++ Value of station, " << station << ", is out of bounds, [1, 4] +++\n";
0149 
0150   gblphidat data(0);
0151 
0152   unsigned short int maxPhiL = 1 << CSCBitWidths::kLocalPhiDataBitWidth;
0153   unsigned short int maxPhiG = 1 << CSCBitWidths::kGlobalPhiDataBitWidth;
0154   unsigned short int cscid = ((theadd >> 15) & 0xf);
0155   unsigned short int lclPhi = (theadd & 0x3ff);
0156   if (!gangedME1a)
0157     lclPhi = lclPhi / 0.625;  // DA and MDG recover old scaling of local phi
0158 
0159   // 12/11/09
0160   // GP et DA: how to identify the strip number and isolate and shift the localPhi value
0161   const double binPhiL = static_cast<double>(maxPhiL) / (2 * CSCConstants::MAX_NUM_STRIPS_RUN1);
0162 
0163   int strip = static_cast<int>(lclPhi / binPhiL);
0164   if (station == 1 && (cscid <= 3) &&
0165       (strip >= 127 && strip < 224)) {  // 160 --> 224, change range for ME1/1a acceptance, DA and MDG
0166     // in this case need to redefine lclPhi in order to
0167     // place local phi in the middle of the 5th CFEB
0168     // and not on the first third of the CFEB as default
0169 
0170     gangedME1a
0171         ? lclPhi = (strip - 127 + 31) * (4 * binPhiL / 3)
0172         : lclPhi =
0173               (strip - 127) *
0174               (4 * binPhiL /
0175                3);  //DA and MDG remove offset to center of ME1/1a (no ganging), and reset ME1/1a strip number to start from 0, and scale 48 strips to match ME1/1b 64 strips
0176   }
0177   // end GP et DA
0178 
0179   if (station == 1 && ((cscid <= 3) || (cscid >= 7))) {
0180     //if ( (strip >= 127 && strip < 160) || (cscid >= 10) ) // VK: the || (cscid >= 10) for unganged ME1a
0181     //  maxPhiL = maxPhiL*(48./80); // GP et DA: currently a hack that is in place to handle the different number of strips in ME1/1a and ME1/3
0182     //else
0183     maxPhiL =
0184         maxPhiL *
0185         (64. / 80);  // currently a hack that is in place to handle the different number of strips in ME1/1 and ME1/3
0186   }
0187 
0188   // VK: The the unganged ME1a hack
0189   if (station == 1 && (cscid >= 10)) {
0190     lclPhi = strip * (4 * binPhiL / 3);
0191     cscid = cscid - 9;  // back to normal 1-9 range
0192   }
0193   // end VK
0194 
0195   if ((cscid > 0) && (cscid <= 9)) {
0196     if ((station == 1) && (lclPhi < maxPhiL))
0197       data.global_phi = (gbl_phi_me_params[endcap - 1][sector - 1][station - 1][subsector - 1][cscid - 1][0] +
0198                          gbl_phi_me_params[endcap - 1][sector - 1][station - 1][subsector - 1][cscid - 1][1] * lclPhi);
0199     else if ((station == 1) && (lclPhi >= maxPhiL))
0200       data.global_phi =
0201           (gbl_phi_me_params[endcap - 1][sector - 1][station - 1][subsector - 1][cscid - 1][0] +
0202            gbl_phi_me_params[endcap - 1][sector - 1][station - 1][subsector - 1][cscid - 1][1] * (maxPhiL - 1));
0203     else
0204       data.global_phi = (gbl_phi_me_params[endcap - 1][sector - 1][station - 1][0][cscid - 1][0] +
0205                          gbl_phi_me_params[endcap - 1][sector - 1][station - 1][0][cscid - 1][1] * lclPhi);
0206   } else
0207     edm::LogWarning("CSCSectorReceiverMiniLUT")
0208         << "+++ Value of cscid, " << cscid << ", is out of bounds, [1, 9] +++\n";
0209 
0210   if (data.global_phi >= maxPhiG)
0211     edm::LogWarning("CSCSectorReceiverMiniLUT")
0212         << "+++ Value of global_phi, " << data.global_phi << ", exceeds max allowed, " << maxPhiG - 1 << " +++\n";
0213 
0214   return data;
0215 }
0216 
0217 global_phi_data CSCSectorReceiverMiniLUT::calcGlobalPhiMBMini(
0218     unsigned short endcap, unsigned short sector, unsigned short subsector, unsigned theadd, const bool gangedME1a) {
0219   if (endcap < 1 || endcap > 2)
0220     edm::LogWarning("CSCSectorReceiverMiniLUT")
0221         << "+++ Value of endcap, " << endcap << ", is out of bounds, [1, 2] +++\n";
0222   if (sector < 1 || sector > 6)
0223     edm::LogWarning("CSCSectorReceiverMiniLUT")
0224         << "+++ Value of sector, " << sector << ", is out of bounds, [1, 6] +++\n";
0225 
0226   gblphidat data(0);
0227 
0228   unsigned short int maxPhiL = 1 << CSCBitWidths::kLocalPhiDataBitWidth;
0229   unsigned short int maxPhiG = 1 << CSCBitWidths::kGlobalPhiDataBitWidth;
0230   unsigned short int cscid = ((theadd >> 15) & 0xf);
0231   unsigned short int lclPhi = (theadd & 0x3ff);
0232   if (!gangedME1a)
0233     lclPhi = lclPhi / 0.625;  // DA and MDG, recover old scaling of local phi
0234 
0235   if ((cscid <= 3) || (cscid >= 7))
0236     maxPhiL =
0237         maxPhiL *
0238         (64. / 80);  // currently a hack that is in place to handle the different number of strips in ME1/1 and ME1/3
0239 
0240   if ((cscid > 0) && (cscid <= 9)) {
0241     if (lclPhi < maxPhiL)
0242       data.global_phi = (gbl_phi_mb_params[endcap - 1][sector - 1][subsector - 1][cscid - 1][0] +
0243                          gbl_phi_mb_params[endcap - 1][sector - 1][subsector - 1][cscid - 1][1] * lclPhi);
0244     else
0245       data.global_phi = (gbl_phi_mb_params[endcap - 1][sector - 1][subsector - 1][cscid - 1][0] +
0246                          gbl_phi_mb_params[endcap - 1][sector - 1][subsector - 1][cscid - 1][1] * (maxPhiL - 1));
0247   } else
0248     edm::LogWarning("CSCSectorReceiverMiniLUT")
0249         << "+++ Value of cscid, " << cscid << ", is out of bounds, [1, 9] +++\n";
0250 
0251   if (data.global_phi >= maxPhiG)
0252     edm::LogWarning("CSCSectorReceiverMiniLUT")
0253         << "+++ Value of global_phi, " << data.global_phi << ", exceeds max allowed, " << maxPhiG - 1 << " +++\n";
0254 
0255   if (data.global_phi >= maxPhiG)
0256     edm::LogWarning("CSCSectorReceiverMiniLUT")
0257         << "+++ Value of global_phi, " << data.global_phi << ", exceeds max allowed, " << maxPhiG - 1 << " +++\n";
0258 
0259   return data;
0260 }