Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 
0003 #include "L1Trigger/L1TMuonEndCapPhase2/interface/EMTFConfiguration.h"
0004 #include "L1Trigger/L1TMuonEndCapPhase2/interface/EMTFConstants.h"
0005 #include "L1Trigger/L1TMuonEndCapPhase2/interface/EMTFContext.h"
0006 #include "L1Trigger/L1TMuonEndCapPhase2/interface/Data/HostLut.h"
0007 #include "L1Trigger/L1TMuonEndCapPhase2/interface/Data/SiteLut.h"
0008 #include "L1Trigger/L1TMuonEndCapPhase2/interface/Data/ZoneLut.h"
0009 #include "L1Trigger/L1TMuonEndCapPhase2/interface/DAQ/SubsystemTags.h"
0010 #include "L1Trigger/L1TMuonEndCapPhase2/interface/Utils/DebugUtils.h"
0011 #include "L1Trigger/L1TMuonEndCapPhase2/interface/Utils/CSCUtils.h"
0012 #include "L1Trigger/L1TMuonEndCapPhase2/interface/Utils/TPUtils.h"
0013 
0014 #include "L1Trigger/L1TMuonEndCapPhase2/interface/DAQ/CSCTPConverter.h"
0015 
0016 using namespace emtf::phase2;
0017 
0018 CSCTPConverter::CSCTPConverter(const EMTFContext& context, const int& endcap, const int& sector)
0019     : context_(context), endcap_(endcap), sector_(sector) {}
0020 
0021 void CSCTPConverter::convert(const TriggerPrimitive& tp, const TPInfo& tp_info, EMTFHit& hit) const {
0022   // Unpack Id
0023   const auto& tp_hit_id = tp_info.hit_id;
0024   const auto& tp_segment_id = tp_info.segment_id;
0025 
0026   // Unpack trigger primitive
0027   const auto& tp_det_id = tp.detId<CSCDetId>();
0028   const auto& tp_data = tp.getCSCData();
0029 
0030   // Unpack detector info
0031   const auto tp_subsystem = L1TMuon::kCSC;
0032 
0033   const int tp_raw_id = tp_det_id.rawId();
0034 
0035   const int tp_endcap_pm = tp_info.endcap_pm;
0036   const int tp_subsector = tp_info.subsector;
0037   const int tp_chamber = tp_info.chamber;
0038   const int tp_station = tp_info.station;
0039   const int tp_ring = tp_info.ring;
0040   const int tp_layer = tp_info.layer;
0041 
0042   const int tp_csc_id = tp_info.csc_id;
0043   const auto tp_csc_facing = tp_info.csc_facing;
0044 
0045   // Unpack data
0046   const int tp_strip = tp_data.strip;
0047   const int tp_strip_quart_bit = tp_data.strip_quart_bit;
0048   const int tp_strip_eighth_bit = tp_data.strip_eighth_bit;
0049   const int tp_strip_quart = tp_data.strip_quart;
0050   const int tp_strip_eighth = tp_data.strip_eighth;
0051 
0052   const int tp_wire1 = tp_info.csc_first_wire;
0053   const int tp_wire2 = tp_info.csc_second_wire;
0054 
0055   int tp_bend;
0056   const int tp_slope = tp_data.slope;
0057 
0058   const int tp_bx = tp_info.bx;
0059   const int tp_subbx = 0;   // no fine resolution timing
0060   const float tp_time = 0;  // no fine resolution timing. Note: Check with Efe, Jia Fu gets this from digi directly.
0061 
0062   const auto tp_selection = tp_info.selection;
0063 
0064   const int tp_pattern = tp_data.pattern;
0065   const int tp_quality = 6;
0066 
0067   // Apply CSC Run 2 pattern -> bend conversion
0068   // Override tp_bend
0069   constexpr int tp_bend_lut_size = 11;
0070   constexpr int tp_bend_lut[tp_bend_lut_size] = {-5, 5, -4, 4, -3, 3, -2, 2, -1, 1, 0};
0071   emtf_assert(tp_pattern < tp_bend_lut_size);
0072   tp_bend = tp_bend_lut[tp_pattern];
0073   tp_bend *= tp_endcap_pm;  // sign flip depending on endcap
0074 
0075   // ID scheme used in FW
0076   const int tp_ilink = tp_info.ilink;
0077 
0078   // Get Global Coordinates
0079   const GlobalPoint& gp_w1 = this->context_.geometry_translator_.getGlobalPoint(tp);
0080   const float glob_phi_w1 = tp::radToDeg(gp_w1.phi().value());
0081   const float glob_theta_w1 = tp::radToDeg(gp_w1.theta().value());
0082   const double glob_rho_w1 = gp_w1.perp();
0083   const double glob_z_w1 = gp_w1.z();
0084 
0085   // Calculate EMTF Values
0086   const int emtf_phi_w1 = tp::calcPhiInt(sector_, glob_phi_w1);
0087   const int emtf_bend_w1 = std::clamp(tp_bend * 4, -16, 15);  // 5-bit, signed
0088   const int emtf_theta_w1 = tp::calcThetaInt(tp_endcap_pm, glob_theta_w1);
0089   const int emtf_qual_w1 = std::clamp(tp_quality, 0, 15);  // 4-bit, unsigned
0090   const int emtf_site_w1 = context_.site_lut_.lookup({tp_subsystem, tp_station, tp_ring});
0091   const int emtf_host_w1 = context_.host_lut_.lookup({tp_subsystem, tp_station, tp_ring});
0092   const int emtf_zones_w1 = context_.zone_lut_.getZones(emtf_host_w1, emtf_theta_w1);
0093 
0094   // Calculated Ambiguous Info
0095   int emtf_theta_w2 = 0;
0096   int emtf_qual_w2 = tp_pattern;
0097 
0098   if (tp_wire2 > -1) {
0099     auto tp_w2 = tp;
0100 
0101     tp_w2.accessCSCData().keywire = tp_wire2;
0102 
0103     const GlobalPoint& gp_w2 = this->context_.geometry_translator_.getGlobalPoint(tp_w2);
0104     const double glob_theta_w2 = tp::radToDeg(gp_w2.theta().value());
0105 
0106     emtf_theta_w2 = tp::calcThetaInt(tp_endcap_pm, glob_theta_w2);
0107   }
0108 
0109   emtf_assert((0 <= emtf_phi_w1) and (emtf_phi_w1 < 5040));
0110   emtf_assert((1 <= emtf_theta_w1) and (emtf_theta_w1 < 128));
0111   emtf_assert((0 <= emtf_theta_w2) and (emtf_theta_w2 < 128));
0112 
0113   // Get flags
0114   const bool tp_flag_neighbor = (tp_selection == TPSelection::kNeighbor);
0115   const bool tp_flag_substitute = tp_info.flag_substitute;
0116   const bool tp_flag_valid = tp_data.valid;
0117 
0118   // Set properties
0119   hit.setId(tp_hit_id);
0120 
0121   hit.setRawDetId(tp_raw_id);
0122   hit.setSubsystem(L1TMuon::kCSC);
0123   hit.setEndcap(tp_endcap_pm);
0124   hit.setSector(sector_);
0125   hit.setSubsector(tp_subsector);
0126   hit.setStation(tp_station);
0127   hit.setRing(tp_ring);
0128   hit.setLayer(tp_layer);
0129   hit.setChamber(tp_chamber);
0130 
0131   hit.setCscId(tp_csc_id);
0132   hit.setCscFR(tp_csc_facing == csc::Facing::kRear);
0133 
0134   hit.setStrip(tp_strip);
0135   hit.setStripLo(tp_strip);
0136   hit.setStripHi(tp_strip);
0137   hit.setStripQuart(tp_strip_quart);
0138   hit.setStripEighth(tp_strip_eighth);
0139   hit.setStripQuartBit(tp_strip_quart_bit);
0140   hit.setStripEighthBit(tp_strip_eighth_bit);
0141 
0142   hit.setWire1(tp_wire1);
0143   hit.setWire2(tp_wire2);
0144 
0145   hit.setBend(tp_bend);
0146   hit.setSlope(tp_slope);
0147 
0148   hit.setBx(tp_bx);
0149   hit.setSubbx(tp_subbx);
0150 
0151   hit.setQuality(tp_quality);
0152   hit.setPattern(tp_pattern);
0153 
0154   hit.setGlobPhi(glob_phi_w1);
0155   hit.setGlobTheta(glob_theta_w1);
0156   hit.setGlobPerp(glob_rho_w1);
0157   hit.setGlobZ(glob_z_w1);
0158   hit.setGlobTime(tp_time);
0159 
0160   hit.setEmtfChamber(tp_ilink);
0161   hit.setEmtfSegment(tp_segment_id);
0162   hit.setEmtfPhi(emtf_phi_w1);
0163   hit.setEmtfBend(emtf_bend_w1);
0164   hit.setEmtfTheta1(emtf_theta_w1);
0165   hit.setEmtfTheta2(emtf_theta_w2);
0166   hit.setEmtfQual1(emtf_qual_w1);
0167   hit.setEmtfQual2(emtf_qual_w2);
0168   hit.setEmtfSite(emtf_site_w1);
0169   hit.setEmtfHost(emtf_host_w1);
0170   hit.setEmtfZones(emtf_zones_w1);
0171 
0172   hit.setFlagNeighbor(tp_flag_neighbor);
0173   hit.setFlagSubstitute(tp_flag_substitute);
0174   hit.setFlagValid(tp_flag_valid);
0175 }