CMS 3D CMS Logo

CSCTPCollector.cc
Go to the documentation of this file.
4 
11 
13 
14 using namespace emtf::phase2;
15 
17  : context_(context),
18  input_token_(i_consumes_collector.consumes<CSCTag::collection_type>(context.config_.csc_input_)) {}
19 
20 void CSCTPCollector::collect(const edm::Event& i_event, BXTPCMap& bx_tpc_map) const {
22  i_event.getByToken(input_token_, csc_digis);
23 
24  // Collect
25  TPCollection tpc;
26 
27  auto chamber = csc_digis->begin();
28  auto chend = csc_digis->end();
29 
30  for (; chamber != chend; ++chamber) {
31  auto digi = (*chamber).second.first;
32  auto dend = (*chamber).second.second;
33 
34  for (; digi != dend; ++digi) {
35  tpc.emplace_back((*chamber).first, *digi);
36  }
37  }
38 
39  // Find wires
40  std::map<std::pair<uint32_t, uint16_t>, std::vector<uint16_t> > chamber_wires_map;
41 
42  for (auto& tp_entry : tpc) {
43  const auto& tp_det_id = tp_entry.tp_.detId<CSCDetId>();
44 
45  const CSCData& tp_data = tp_entry.tp_.getCSCData();
46  const int tp_bx = tp_data.bx + this->context_.config_.csc_bx_shift_;
47  const int tp_wire = tp_data.keywire;
48 
49  auto key = std::make_pair(tp_det_id.rawId(), tp_bx);
50  auto res = chamber_wires_map.find(key);
51 
52  if (res == chamber_wires_map.end()) {
53  // Case: Chamber not found
54  chamber_wires_map[key].push_back(tp_wire);
55  } else {
56  // Case: Chamber found
57  // Lookup wire if found move on, otherwise add it.
58  bool wire_found = false;
59 
60  auto& chamber_wires = res->second;
61 
62  for (const auto& a_wire : chamber_wires) {
63  // Short-Circuit: If wire matches stop
64  if (a_wire == tp_wire) {
65  wire_found = true;
66  break;
67  }
68  }
69 
70  // Case: Wire not found, add it.
71  if (!wire_found) {
72  chamber_wires.push_back(tp_wire);
73  }
74  }
75  }
76 
77  // Map to BX
78  for (auto& tp_entry : tpc) {
79  const auto& tp_det_id = tp_entry.tp_.detId<CSCDetId>();
80  const CSCData& tp_data = tp_entry.tp_.getCSCData();
81 
82  const int tp_endcap = tp_det_id.endcap(); // 1: +endcap, 2: -endcap
83  const int tp_endcap_pm = (tp_endcap == 2) ? -1 : tp_endcap; // 1: +endcap, -1: -endcap
84  const int tp_sector = tp_det_id.triggerSector();
85  const int tp_station = tp_det_id.station();
86  const int tp_ring = tp_det_id.ring();
87  const int tp_chamber = tp_det_id.chamber();
88  const int tp_layer = tp_det_id.layer();
89 
90  const int tp_csc_id = tp_data.cscID;
91 
92  const int tp_bx = tp_data.bx + this->context_.config_.csc_bx_shift_;
93 
94  // Get wires
95  int tp_wire1 = tp_data.keywire;
96  int tp_wire2 = -1;
97 
98  auto tp_wire_key = std::make_pair(tp_det_id.rawId(), tp_bx);
99  const auto& tp_wires = chamber_wires_map.at(tp_wire_key);
100 
101  emtf_assert((!tp_wires.empty()) && (tp_wires.size() <= 2));
102 
103  if (tp_wires.size() > 1) {
104  tp_wire1 = tp_wires.at(0);
105  tp_wire2 = tp_wires.at(1);
106  }
107 
108  // Calculate detector info
109  const int tp_subsector = csc::getTriggerSubsector(tp_station, tp_chamber);
110  const auto tp_face_dir = csc::getFaceDirection(tp_station, tp_ring, tp_chamber);
111 
112  // Assertion checks
113  const auto& [max_strip, max_wire] = csc::getMaxStripAndWire(tp_station, tp_ring);
114  const auto& [max_pattern, max_quality] = csc::getMaxPatternAndQuality(tp_station, tp_ring);
115 
116  emtf_assert(kMinEndcap <= tp_endcap && tp_endcap <= kMaxEndcap);
117  emtf_assert(kMinTrigSector <= tp_sector && tp_sector <= kMaxTrigSector);
118  emtf_assert((0 <= tp_subsector) and (tp_subsector <= 2));
119  emtf_assert(1 <= tp_station && tp_station <= 4);
120  emtf_assert(1 <= tp_ring && tp_ring <= 4);
121  emtf_assert(1 <= tp_chamber && tp_chamber <= 36);
122  emtf_assert(1 <= tp_csc_id && tp_csc_id <= 9);
123  emtf_assert(tp_data.strip < max_strip);
124  emtf_assert(tp_data.keywire < max_wire);
125  emtf_assert(tp_data.pattern < max_pattern);
126  emtf_assert(0 < tp_data.quality && tp_data.quality < max_quality);
127  emtf_assert(tp_data.valid);
128 
129  // Check for corrupted LCT data. Data corruption could occur due to software
130  // or hardware issues, if corrupted, reject the LCT.
131  if (!(tp_data.strip < max_strip)) {
132  edm::LogWarning("L1TEMTFpp") << "Found error in LCT strip: " << tp_data.strip << " (allowed range: 0-"
133  << max_strip - 1 << ").";
134 
135  edm::LogWarning("L1TEMTFpp")
136  << "From endcap " << tp_endcap << ", sector " << tp_sector << ", station " << tp_station << ", ring "
137  << tp_ring << ", cscid " << tp_csc_id
138  << ". (Note that this LCT may be reported multiple times. See source code for explanations.)";
139 
140  continue;
141  }
142 
143  if (!(tp_data.keywire < max_wire)) {
144  edm::LogWarning("L1TEMTFpp") << "Found error in LCT wire: " << tp_data.keywire << " (allowed range: 0-"
145  << max_wire - 1 << ").";
146 
147  edm::LogWarning("L1TEMTFpp")
148  << "From endcap " << tp_endcap << ", sector " << tp_sector << ", station " << tp_station << ", ring "
149  << tp_ring << ", cscid " << tp_csc_id
150  << ". (Note that this LCT may be reported multiple times. See source code for explanations.)";
151 
152  continue;
153  }
154 
155  if (!(tp_data.valid == true)) {
156  edm::LogWarning("L1TEMTFpp") << "Found error in LCT valid: " << tp_data.valid << " (allowed value: 1).";
157 
158  edm::LogWarning("L1TEMTFpp")
159  << "From endcap " << tp_endcap << ", sector " << tp_sector << ", station " << tp_station << ", ring "
160  << tp_ring << ", cscid " << tp_csc_id
161  << ". (Note that this LCT may be reported multiple times. See source code for explanations.)";
162 
163  continue;
164  }
165 
166  if (!(tp_data.pattern < max_pattern)) {
167  edm::LogWarning("L1TEMTFpp") << "Found error in LCT pattern: " << tp_data.pattern << " (allowed range: 0-"
168  << max_pattern - 1 << ").";
169 
170  edm::LogWarning("L1TEMTFpp")
171  << "From endcap " << tp_endcap << ", sector " << tp_sector << ", station " << tp_station << ", ring "
172  << tp_ring << ", cscid " << tp_csc_id
173  << ". (Note that this LCT may be reported multiple times. See source code for explanations.)";
174 
175  continue;
176  }
177 
178  if (!(0 < tp_data.quality && tp_data.quality < max_quality)) {
179  edm::LogWarning("L1TEMTFpp") << "Found error in LCT quality: " << tp_data.quality << " (allowed range: 1-"
180  << max_quality - 1 << ").";
181 
182  edm::LogWarning("L1TEMTFpp")
183  << "From endcap " << tp_endcap << ", sector " << tp_sector << ", station " << tp_station << ", ring "
184  << tp_ring << ", cscid " << tp_csc_id
185  << ". (Note that this LCT may be reported multiple times. See source code for explanations.)";
186 
187  continue;
188  }
189 
190  // Add info
191  tp_entry.info_.bx = tp_bx;
192 
193  tp_entry.info_.endcap = tp_endcap;
194  tp_entry.info_.endcap_pm = tp_endcap_pm;
195  tp_entry.info_.sector = tp_sector;
196  tp_entry.info_.subsector = tp_subsector;
197  tp_entry.info_.station = tp_station;
198  tp_entry.info_.ring = tp_ring;
199  tp_entry.info_.chamber = tp_chamber;
200  tp_entry.info_.layer = tp_layer;
201 
202  tp_entry.info_.csc_id = tp_csc_id;
203  tp_entry.info_.csc_facing = tp_face_dir;
204  tp_entry.info_.csc_first_wire = tp_wire1;
205  tp_entry.info_.csc_second_wire = tp_wire2;
206 
207  bx_tpc_map[tp_bx].push_back(tp_entry);
208  }
209 }
std::pair< int, int > getMaxPatternAndQuality(int station, int ring)
Definition: CSCUtils.cc:161
int getTriggerSubsector(int station, int chamber)
Definition: CSCUtils.cc:85
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:526
const EMTFContext & context_
CSCTPCollector(const EMTFContext &, edm::ConsumesCollector &)
Definition: Electron.h:6
constexpr int kMaxEndcap
Definition: EMTFConstants.h:7
void collect(const edm::Event &, BXTPCMap &) const final
const edm::EDGetToken input_token_
std::pair< int, int > getMaxStripAndWire(int station, int ring)
Definition: CSCUtils.cc:131
std::map< int, TPCollection > BXTPCMap
Definition: EMTFTypes.h:22
key
prepare the HTCondor submission files and eventually submit them
#define emtf_assert(expr)
Definition: DebugTools.h:18
Facing getFaceDirection(int station, int ring, int chamber)
Definition: CSCUtils.cc:100
constexpr int kMinTrigSector
Definition: EMTFConstants.h:20
constexpr int kMinEndcap
Definition: EMTFConstants.h:6
constexpr int kMaxTrigSector
Definition: EMTFConstants.h:21
Log< level::Warning, false > LogWarning
std::vector< TPEntry > TPCollection
Definition: EMTFTypes.h:21
EMTFConfiguration config_
Definition: EMTFContext.h:39