Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "FWCore/Framework/interface/ConsumesCollector.h"
0003 
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/DAQ/SubsystemTags.h"
0008 #include "L1Trigger/L1TMuonEndCapPhase2/interface/DAQ/TPrimitives.h"
0009 #include "L1Trigger/L1TMuonEndCapPhase2/interface/Utils/CSCUtils.h"
0010 #include "L1Trigger/L1TMuonEndCapPhase2/interface/Utils/DebugUtils.h"
0011 
0012 #include "L1Trigger/L1TMuonEndCapPhase2/interface/DAQ/ME0TPCollector.h"
0013 
0014 using namespace emtf::phase2;
0015 
0016 ME0TPCollector::ME0TPCollector(const EMTFContext& context, edm::ConsumesCollector& i_consumes_collector)
0017     : context_(context),
0018       input_token_(i_consumes_collector.consumes<ME0Tag::collection_type>(context.config_.me0_input_)) {}
0019 
0020 void ME0TPCollector::collect(const edm::Event& i_event, BXTPCMap& bx_tpc_map) const {
0021   // Constants
0022   // First quarter of ME0 chamber (5 deg) and last quarter
0023   static const int me0_max_partition = 9;
0024   static const int me0_nstrips = 384;
0025   static const int me0_nphipositions = me0_nstrips * 2;
0026   static const int phiposition_q1 = me0_nphipositions / 4;
0027   static const int phiposition_q3 = (me0_nphipositions / 4) * 3;
0028 
0029   // Read ME0 digis
0030   TPCollection tpc;
0031 
0032   edm::Handle<ME0Tag::collection_type> me0_digis;
0033   i_event.getByToken(input_token_, me0_digis);
0034 
0035   auto chamber = me0_digis->begin();
0036   auto chend = me0_digis->end();
0037 
0038   for (; chamber != chend; ++chamber) {
0039     auto digi = (*chamber).second.first;
0040     auto dend = (*chamber).second.second;
0041 
0042     for (; digi != dend; ++digi) {
0043       tpc.emplace_back((*chamber).first, *digi);
0044     }
0045   }
0046 
0047   // Map to BX
0048   for (auto& tp_entry : tpc) {
0049     const auto& tp_det_id = tp_entry.tp_.detId<ME0DetId>();
0050     const ME0Data& tp_data = tp_entry.tp_.getME0Data();
0051 
0052     const int tp_region = tp_det_id.region();                    // 0: barrel, +/-1: endcap
0053     const int tp_endcap = (tp_region == -1) ? 2 : tp_region;     // 1: +endcap, 2: -endcap
0054     const int tp_endcap_pm = (tp_endcap == 2) ? -1 : tp_endcap;  // 1: +endcap, -1: -endcap
0055     const int tp_station = tp_det_id.station();
0056     const int tp_ring = 4;
0057     const int tp_layer = tp_det_id.layer();
0058     const int tp_roll = tp_det_id.roll();
0059     const int tp_me0_chamber = tp_det_id.chamber();
0060 
0061     const int tp_pad = tp_data.phiposition;
0062     const int tp_partition = tp_data.partition;
0063     const int tp_bx = tp_data.bx + this->context_.config_.me0_bx_shift_;
0064 
0065     // Reject if outside eta of 2.4
0066     if (tp_partition > me0_max_partition) {
0067       continue;
0068     }
0069 
0070     // Calculate EMTF Info
0071     // Split 20-deg chamber into 10-deg chamber
0072     // ME0 chamber is rotated by -5 deg relative to CSC chamber.
0073     // ME0 chamber 1 starts at -10 deg, CSC chamber 1 starts at -5 deg.
0074     const int tp_phiposition = tp_data.phiposition;  // in half-strip unit
0075 
0076     int tp_chamber = (tp_me0_chamber - 1) * 2 + 1;
0077 
0078     if (tp_endcap == 1) {
0079       // positive endcap
0080       // phiposition increases counter-clockwise
0081       if (tp_phiposition < phiposition_q1) {
0082         tp_chamber = csc::getNext10DegChamber(tp_chamber);
0083       } else if (tp_phiposition < phiposition_q3) {
0084         // Do nothing
0085       } else {
0086         tp_chamber = csc::getPrev10DegChamber(tp_chamber);
0087       }
0088     } else {
0089       // negative endcap
0090       // phiposition increases clockwise
0091       if (tp_phiposition < phiposition_q1) {
0092         tp_chamber = csc::getPrev10DegChamber(tp_chamber);
0093       } else if (tp_phiposition < phiposition_q3) {
0094         // Do nothing
0095       } else {
0096         tp_chamber = csc::getNext10DegChamber(tp_chamber);
0097       }
0098     }
0099 
0100     const int tp_sector = csc::getTriggerSector(tp_station, tp_ring, tp_chamber);
0101     const int tp_subsector = csc::getTriggerSubsector(tp_station, tp_chamber);
0102     const int tp_csc_id = csc::getId(tp_station, tp_ring, tp_chamber);
0103     const auto tp_csc_facing = csc::getFaceDirection(tp_station, tp_ring, tp_chamber);
0104 
0105     // Assertion checks
0106     emtf_assert(kMinEndcap <= tp_endcap && tp_endcap <= kMaxEndcap);
0107     emtf_assert(kMinTrigSector <= tp_sector && tp_sector <= kMaxTrigSector);
0108     emtf_assert((1 <= tp_subsector) and (tp_subsector <= 2));
0109     emtf_assert(tp_station == 1);
0110     emtf_assert(tp_ring == 4);
0111     emtf_assert((1 <= tp_chamber) and (tp_chamber <= 36));
0112     emtf_assert(1 <= tp_csc_id && tp_csc_id <= 3);
0113     emtf_assert(0 <= tp_pad && tp_pad <= 767);
0114     emtf_assert(0 <= tp_partition && tp_partition <= 15);
0115 
0116     // Add info
0117     tp_entry.info_.bx = tp_bx;
0118 
0119     tp_entry.info_.endcap = tp_endcap;
0120     tp_entry.info_.endcap_pm = tp_endcap_pm;
0121     tp_entry.info_.sector = tp_sector;
0122     tp_entry.info_.subsector = tp_subsector;
0123     tp_entry.info_.station = tp_station;
0124     tp_entry.info_.ring = tp_ring;
0125     tp_entry.info_.layer = tp_layer;
0126     tp_entry.info_.roll = tp_roll;
0127     tp_entry.info_.chamber = tp_chamber;
0128 
0129     tp_entry.info_.csc_id = tp_csc_id;
0130     tp_entry.info_.csc_facing = tp_csc_facing;
0131 
0132     bx_tpc_map[tp_bx].push_back(tp_entry);
0133   }
0134 }