Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 
0003 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
0004 #include "L1Trigger/L1TMuonEndCapPhase2/interface/EMTFConfiguration.h"
0005 #include "L1Trigger/L1TMuonEndCapPhase2/interface/EMTFConstants.h"
0006 #include "L1Trigger/L1TMuonEndCapPhase2/interface/EMTFContext.h"
0007 #include "L1Trigger/L1TMuonEndCapPhase2/interface/Data/HostLut.h"
0008 #include "L1Trigger/L1TMuonEndCapPhase2/interface/Data/SiteLut.h"
0009 #include "L1Trigger/L1TMuonEndCapPhase2/interface/Data/ZoneLut.h"
0010 #include "L1Trigger/L1TMuonEndCapPhase2/interface/DAQ/SubsystemTags.h"
0011 #include "L1Trigger/L1TMuonEndCapPhase2/interface/Utils/DebugUtils.h"
0012 #include "L1Trigger/L1TMuonEndCapPhase2/interface/Utils/CSCUtils.h"
0013 #include "L1Trigger/L1TMuonEndCapPhase2/interface/Utils/RPCUtils.h"
0014 #include "L1Trigger/L1TMuonEndCapPhase2/interface/Utils/TPUtils.h"
0015 
0016 #include "L1Trigger/L1TMuonEndCapPhase2/interface/DAQ/RPCTPConverter.h"
0017 
0018 using namespace emtf::phase2;
0019 
0020 RPCTPConverter::RPCTPConverter(const EMTFContext& context, const int& endcap, const int& sector)
0021     : context_(context), endcap_(endcap), sector_(sector) {}
0022 
0023 void RPCTPConverter::convert(const TriggerPrimitive& tp, const TPInfo& tp_info, EMTFHit& hit) const {
0024   // Unpack Id
0025   const auto& tp_hit_id = tp_info.hit_id;
0026   const auto& tp_segment_id = tp_info.segment_id;
0027 
0028   // Unpack trigger primitive
0029   const auto& tp_det_id = tp.detId<RPCDetId>();
0030   const auto& tp_data = tp.getRPCData();
0031 
0032   // Unpack detector info
0033   const auto tp_subsystem = L1TMuon::kRPC;
0034 
0035   const int tp_raw_id = tp_det_id.rawId();
0036 
0037   const int tp_endcap_pm = tp_info.endcap_pm;
0038   const int tp_subsector = tp_info.subsector;
0039   const int tp_station = tp_info.station;
0040   const int tp_ring = tp_info.ring;
0041   const int tp_roll = tp_info.roll;
0042   const int tp_layer = tp_info.layer;
0043   const int tp_chamber = tp_info.chamber;
0044 
0045   const auto tp_csc_facing = tp_info.csc_facing;
0046   const int tp_csc_id = tp_info.csc_id;
0047   const auto tp_rpc_type = tp_info.rpc_type;
0048 
0049   // Unpack data
0050   const int tp_strip = (tp_data.strip_low + tp_data.strip_hi) / 2;  // in full-strip unit
0051   const int tp_strip_lo = tp_data.strip_low;
0052   const int tp_strip_hi = tp_data.strip_hi;
0053   const int tp_clus_width = (tp_strip_hi - tp_strip_lo + 1);
0054 
0055   int tp_bend = 0;  // not applicable
0056 
0057   const int tp_bx = tp_info.bx;
0058   const float tp_time = tp_data.time;
0059   float tp_subbx_f32 = tp_time - (std::round(tp_time / 25.) * 25.);  // reduce range to [-12.5,12.5] ns
0060   int tp_subbx = static_cast<int>(std::round(tp_subbx_f32 * 16. / 25.));
0061   tp_subbx = std::clamp(tp_subbx, -8, 7);  // 4-bit, signed
0062   int tp_bx_check = static_cast<int>(std::round(tp_time / 25.));
0063 
0064   // Not sure why sometimes digi.time() returns 0?
0065   emtf_assert(((not(std::abs(tp_time) < 1e-6)) and (tp_bx == tp_bx_check)) or (std::abs(tp_time) < 1e-6));
0066 
0067   const auto tp_selection = tp_info.selection;
0068 
0069   // Use cluster width as quality.
0070   int tp_quality;
0071 
0072   if (tp_rpc_type == rpc::Type::kiRPC) {
0073     tp_quality = tp_clus_width;
0074   } else {
0075     tp_quality = tp_clus_width * 3 / 2;  // RPC strip pitch is 1.5 times the iRPC strip pitch.
0076   }
0077 
0078   // ID scheme used in FW
0079   const int tp_ilink = tp_info.ilink;
0080 
0081   // Get Global Coordinates
0082   float glob_phi;
0083   float glob_theta;
0084   double glob_rho;
0085   double glob_z;
0086 
0087   if (tp_rpc_type == rpc::Type::kiRPC) {
0088     // Handle iRPC Coordinates
0089     const RPCRoll* roll =
0090         dynamic_cast<const RPCRoll*>(this->context_.geometry_translator_.getRPCGeometry().roll(tp_det_id));
0091     const GlobalPoint& irpc_gp = roll->surface().toGlobal(LocalPoint(tp_data.x, tp_data.y, 0));
0092 
0093     glob_phi = tp::radToDeg(irpc_gp.phi().value());
0094     glob_theta = tp::radToDeg(irpc_gp.theta().value());
0095     glob_rho = irpc_gp.perp();
0096     glob_z = irpc_gp.z();
0097   } else {
0098     // Handle RPC Coordinates
0099     const GlobalPoint& gp = this->context_.geometry_translator_.getGlobalPoint(tp);
0100     glob_phi = tp::radToDeg(gp.phi().value());
0101     glob_theta = tp::radToDeg(gp.theta().value());
0102     glob_rho = gp.perp();
0103     glob_z = gp.z();
0104   }
0105 
0106   // Calculate EMTF Values
0107   const int emtf_phi = tp::calcPhiInt(sector_, glob_phi);
0108   const int emtf_bend = 0;
0109   const int emtf_theta = tp::calcThetaInt(tp_endcap_pm, glob_theta);
0110   const int emtf_qual = 0;
0111   const int emtf_site = context_.site_lut_.lookup({tp_subsystem, tp_station, tp_ring});
0112   const int emtf_host = context_.host_lut_.lookup({tp_subsystem, tp_station, tp_ring});
0113   const int emtf_zones = context_.zone_lut_.getZones(emtf_host, emtf_theta);
0114 
0115   emtf_assert((0 <= emtf_phi) and (emtf_phi < 5040));
0116   emtf_assert((1 <= emtf_theta) and (emtf_theta < 128));
0117 
0118   // Get flags
0119   const bool tp_flag_neighbor = (tp_selection == TPSelection::kNeighbor);
0120   const bool tp_flag_substitute = tp_info.flag_substitute;
0121   const bool tp_flag_valid = tp_data.valid;
0122 
0123   // Set all the variables
0124   hit.setId(tp_hit_id);
0125 
0126   hit.setRawDetId(tp_raw_id);
0127   hit.setSubsystem(tp_subsystem);
0128   hit.setEndcap(tp_endcap_pm);
0129   hit.setSector(sector_);
0130   hit.setSubsector(tp_subsector);
0131   hit.setStation(tp_station);
0132   hit.setRing(tp_ring);
0133   hit.setLayer(tp_layer);
0134   hit.setChamber(tp_chamber);
0135 
0136   hit.setCscId(tp_csc_id);
0137   hit.setCscFR(tp_csc_facing == csc::Facing::kRear);
0138 
0139   hit.setStrip(tp_strip);
0140   hit.setStripLo(tp_strip_lo);
0141   hit.setStripHi(tp_strip_hi);
0142 
0143   hit.setWire1(tp_roll);
0144   hit.setWire2(0);
0145 
0146   hit.setBend(tp_bend);
0147 
0148   hit.setBx(tp_bx);
0149   hit.setSubbx(tp_subbx);
0150 
0151   hit.setQuality(tp_quality);
0152   hit.setPattern(0);
0153 
0154   hit.setGlobPhi(glob_phi);
0155   hit.setGlobTheta(glob_theta);
0156   hit.setGlobPerp(glob_rho);
0157   hit.setGlobZ(glob_z);
0158   hit.setGlobTime(tp_time);
0159 
0160   hit.setEmtfChamber(tp_ilink);
0161   hit.setEmtfSegment(tp_segment_id);
0162   hit.setEmtfPhi(emtf_phi);
0163   hit.setEmtfBend(emtf_bend);
0164   hit.setEmtfTheta1(emtf_theta);
0165   hit.setEmtfTheta2(0);
0166   hit.setEmtfQual1(emtf_qual);
0167   hit.setEmtfQual2(0);
0168   hit.setEmtfSite(emtf_site);
0169   hit.setEmtfHost(emtf_host);
0170   hit.setEmtfZones(emtf_zones);
0171 
0172   hit.setFlagNeighbor(tp_flag_neighbor);
0173   hit.setFlagSubstitute(tp_flag_substitute);
0174   hit.setFlagValid(tp_flag_valid);
0175 }