CMS 3D CMS Logo

L1TPhase2GMTEndcapStubProcessor.cc
Go to the documentation of this file.
3 #include <cmath>
4 #include <iostream>
5 #include <string>
6 #include <sstream>
7 
9 
11  : minBX_(iConfig.getParameter<int>("minBX")),
12  maxBX_(iConfig.getParameter<int>("maxBX")),
13  coord1LSB_(iConfig.getParameter<double>("coord1LSB")),
14  coord2LSB_(iConfig.getParameter<double>("coord2LSB")),
15  eta1LSB_(iConfig.getParameter<double>("eta1LSB")),
16  eta2LSB_(iConfig.getParameter<double>("eta2LSB")),
17  etaMatch_(iConfig.getParameter<double>("etaMatch")),
18  phiMatch_(iConfig.getParameter<double>("phiMatch")),
19  verbose_(iConfig.getParameter<unsigned int>("verbose")) {}
20 
22 
24  const CSCCorrelatedLCTDigi& digi,
25  const L1TMuon::GeometryTranslator* translator) {
26  int endcap = detid.endcap();
27  int station = detid.station();
28  int chamber = detid.chamber();
29  int ring = detid.ring();
30 
32 
33  const GlobalPoint& gp = translator->getGlobalPoint(primitive);
34 
35  int phi = int(gp.phi().value() / coord1LSB_);
36  int eta1 = int(gp.eta() / eta1LSB_);
37 
38  int wheel = 0;
39  int sign = endcap == 1 ? -1 : 1;
40 
41  if (ring == 3)
42  wheel = sign * 3;
43  else if (ring == 2)
44  wheel = sign * 4;
45  else if (ring == 1)
46  wheel = sign * 5;
47 
48  int sector = fabs(chamber);
49 
50  int bx = digi.getBX() - 8;
51  int quality = 1;
52 
53  uint tfLayer = 0;
54  if ((ring == 3 || ring == 2) && station == 1) //ME1/3
55  tfLayer = 4;
56  else if (ring == 1 && station == 1) //ME1/3
57  tfLayer = 0;
58  else if (station == 2) //ME2/2
59  tfLayer = 2;
60  else if (station == 3) //ME3/2
61  tfLayer = 1;
62  else if (station == 4) //ME4/2
63  tfLayer = 3;
64 
65  l1t::MuonStub stub(wheel, sector, station, tfLayer, phi, 0, 0, bx, quality, eta1, 0, 1, 0);
66 
67  stub.setOfflineQuantities(gp.phi().value(), 0.0, gp.eta(), 0.0);
68  return stub;
69 }
70 
72  const RPCDigi& digi,
73  const L1TMuon::GeometryTranslator* translator) {
75  const GlobalPoint& gp = translator->getGlobalPoint(primitive);
76 
77  int phi2 = int(gp.phi().value() / coord2LSB_);
78  int eta2 = int(gp.eta() / eta2LSB_);
79 
80  int wheel = -(6 - detid.ring()) * detid.region();
81  int sector = (detid.sector() - 1) * 6 + detid.subsector();
82  int station = detid.station();
83  bool tag = detid.trIndex();
84  int bx = digi.bx();
85  int quality = 2;
86 
87  int ring = detid.ring();
88 
89  uint tfLayer = 0;
90 
91  if ((ring == 3 || ring == 2) && station == 1) //ME1/3
92  tfLayer = 4;
93  // else if (ring==1 && station==1) //ME1/3
94  // tfLayer=0;
95  else if (station == 2) //ME2/2
96  tfLayer = 2;
97  else if (station == 3) //ME3/2
98  tfLayer = 1;
99  else if (station == 4) //ME4/2
100  tfLayer = 3;
101 
102  l1t::MuonStub stub(wheel, sector, station, tfLayer, 0, phi2, tag, bx, quality, 0, eta2, 2, 0);
103  stub.setOfflineQuantities(gp.phi().value(), gp.phi().value(), gp.eta(), gp.eta());
104  return stub;
105 }
106 
108  const l1t::MuonStubCollection& rpcStubs) {
110  l1t::MuonStubCollection usedRPC;
111  l1t::MuonStubCollection cleanedRPC;
112 
113  l1t::MuonStubCollection cleanedCSC;
114 
115  //clean ME11 ambiguities
116  l1t::MuonStubCollection allCSC = cscStubs;
117 
118  while (!allCSC.empty()) {
119  l1t::MuonStub stub = allCSC[0];
120  l1t::MuonStubCollection freeCSC;
121  for (uint i = 1; i < allCSC.size(); ++i) {
122  if ((stub.etaRegion() == allCSC[i].etaRegion()) && (stub.depthRegion() == allCSC[i].depthRegion()) &&
123  (fabs(deltaPhi(stub.offline_coord1(), allCSC[i].offline_coord1())) < 0.001)) {
124  if (fabs(stub.offline_eta1() - allCSC[i].offline_eta1()) > 0.001) {
125  stub.setEta(stub.eta1(), allCSC[i].eta1(), 3);
126  stub.setOfflineQuantities(stub.offline_coord1(), 0.0, stub.offline_eta1(), allCSC[i].offline_eta1());
127  }
128  } else {
129  freeCSC.push_back(allCSC[i]);
130  }
131  }
132  cleanedCSC.push_back(stub);
133  allCSC = freeCSC;
134  }
135 
136  for (const auto& csc : cleanedCSC) {
137  int nRPC = 0;
138  float phiF = 0.0;
139  float etaF = 0.0;
140  int phi = 0;
141  int eta = 0;
142  for (const auto& rpc : rpcStubs) {
143  if (csc.depthRegion() != rpc.depthRegion())
144  continue;
145  if (fabs(deltaPhi(csc.offline_coord1(), rpc.offline_coord2())) < phiMatch_ &&
146  fabs(csc.offline_eta1() - rpc.offline_eta2()) < etaMatch_ && csc.bxNum() == rpc.bxNum()) {
147  phiF += rpc.offline_coord2();
148  etaF += rpc.offline_eta2();
149  phi += rpc.coord2();
150  eta += rpc.eta2();
151  nRPC++;
152  usedRPC.push_back(rpc);
153  }
154  }
155 
156  int finalRPCPhi = 0;
157  int finalRPCEta = 0;
158  double offline_finalRPCPhi = 0;
159  double offline_finalRPCEta = 0;
160  if (nRPC != 0) {
161  finalRPCPhi = phi / nRPC;
162  finalRPCEta = eta / nRPC;
163  offline_finalRPCPhi = phiF / nRPC;
164  offline_finalRPCEta = etaF / nRPC;
165  l1t::MuonStub stub(csc.etaRegion(),
166  csc.phiRegion(),
167  csc.depthRegion(),
168  csc.tfLayer(),
169  csc.coord1(),
170  finalRPCPhi,
171  0,
172  csc.bxNum(),
173  3,
174  csc.eta1(),
175  finalRPCEta,
176  3,
177  0);
178  stub.setOfflineQuantities(csc.offline_coord1(), offline_finalRPCPhi, csc.offline_eta1(), offline_finalRPCEta);
179  out.push_back(stub);
180  } else {
181  out.push_back(csc);
182  }
183  }
184 
185  //clean the RPC from the used ones
186 
187  for (const auto& rpc : rpcStubs) {
188  bool keep = true;
189  for (const auto& rpc2 : usedRPC) {
190  if (rpc == rpc2) {
191  keep = false;
192  break;
193  }
194  }
195  if (keep)
196  cleanedRPC.push_back(rpc);
197  }
198 
199  while (!cleanedRPC.empty()) {
200  l1t::MuonStubCollection freeRPC;
201 
202  int nRPC = 1;
203  float phiF = cleanedRPC[0].offline_coord2();
204  float etaF = cleanedRPC[0].offline_eta2();
205  int phi = cleanedRPC[0].coord2();
206  int eta = cleanedRPC[0].eta2();
207 
208  for (unsigned i = 1; i < cleanedRPC.size(); ++i) {
209  if (fabs(deltaPhi(cleanedRPC[0].offline_coord2(), cleanedRPC[i].offline_coord2())) < phiMatch_ &&
210  cleanedRPC[0].depthRegion() == cleanedRPC[i].depthRegion() &&
211  fabs(cleanedRPC[0].offline_eta2() - cleanedRPC[i].offline_eta2()) < etaMatch_ &&
212  cleanedRPC[0].bxNum() == cleanedRPC[i].bxNum()) {
213  phiF += cleanedRPC[i].offline_coord2();
214  etaF += cleanedRPC[i].offline_eta2();
215  phi += cleanedRPC[i].coord2();
216  eta += cleanedRPC[i].eta2();
217  nRPC++;
218  } else {
219  freeRPC.push_back(cleanedRPC[i]);
220  }
221  }
222  l1t::MuonStub stub(cleanedRPC[0].etaRegion(),
223  cleanedRPC[0].phiRegion(),
224  cleanedRPC[0].depthRegion(),
225  cleanedRPC[0].tfLayer(),
226  0,
227  phi / nRPC,
228  0,
229  cleanedRPC[0].bxNum(),
230  2,
231  0,
232  eta / nRPC,
233  2,
234  0);
235  stub.setOfflineQuantities(phiF / nRPC, phiF / nRPC, etaF / nRPC, etaF / nRPC);
236  out.push_back(stub);
237  cleanedRPC = freeRPC;
238  };
239  return out;
240 }
241 
246  const edm::EventSetup& iSetup) {
247  l1t::MuonStubCollection cscStubs;
248  auto chamber = csc.begin();
249  auto chend = csc.end();
250  for (; chamber != chend; ++chamber) {
251  auto digi = (*chamber).second.first;
252  auto dend = (*chamber).second.second;
253  for (; digi != dend; ++digi) {
254  l1t::MuonStub stub = buildCSCOnlyStub((*chamber).first, *digi, t);
255  if (stub.bxNum() >= minBX_ && stub.bxNum() <= maxBX_)
256  cscStubs.push_back(stub);
257  }
258  }
259 
260  l1t::MuonStubCollection rpcStubs;
261 
262  auto rpcchamber = cleaned.begin();
263  auto rpcchend = cleaned.end();
264  for (; rpcchamber != rpcchend; ++rpcchamber) {
265  if ((*rpcchamber).first.region() == 0)
266  continue;
267  auto digi = (*rpcchamber).second.first;
268  auto dend = (*rpcchamber).second.second;
269  for (; digi != dend; ++digi) {
270  l1t::MuonStub stub = buildRPCOnlyStub((*rpcchamber).first, *digi, t);
271  if (stub.bxNum() >= minBX_ && stub.bxNum() <= maxBX_)
272  rpcStubs.push_back(stub);
273  }
274  }
275 
276  l1t::MuonStubCollection combinedStubs = combineStubs(cscStubs, rpcStubs);
277 
278  if (verbose_) {
279  printf("CSC Stubs\n");
280  for (const auto& stub : cscStubs)
281  printf(
282  "CSC Stub bx=%d TF=%d etaRegion=%d phiRegion=%d depthRegion=%d coord1=%f,%d coord2=%f,%d eta1=%f,%d "
283  "eta2=%f,%d quality=%d etaQuality=%d\n",
284  stub.bxNum(),
285  stub.tfLayer(),
286  stub.etaRegion(),
287  stub.phiRegion(),
288  stub.depthRegion(),
289  stub.offline_coord1(),
290  stub.coord1(),
291  stub.offline_coord2(),
292  stub.coord2(),
293  stub.offline_eta1(),
294  stub.eta1(),
295  stub.offline_eta2(),
296  stub.eta2(),
297  stub.quality(),
298  stub.etaQuality());
299  printf("RPC Stubs\n");
300  for (const auto& stub : rpcStubs)
301  printf(
302  "RPC Stub bx=%d TF=%d etaRegion=%d phiRegion=%d depthRegion=%d coord1=%f,%d coord2=%f,%d eta1=%f,%d "
303  "eta2=%f,%d quality=%d etaQuality=%d\n",
304  stub.bxNum(),
305  stub.tfLayer(),
306  stub.etaRegion(),
307  stub.phiRegion(),
308  stub.depthRegion(),
309  stub.offline_coord1(),
310  stub.coord1(),
311  stub.offline_coord2(),
312  stub.coord2(),
313  stub.offline_eta1(),
314  stub.eta1(),
315  stub.offline_eta2(),
316  stub.eta2(),
317  stub.quality(),
318  stub.etaQuality());
319  for (const auto& stub : combinedStubs)
320  printf(
321  "Combined Stub bx=%d TF=%d etaRegion=%d phiRegion=%d depthRegion=%d coord1=%f,%d coord2=%f,%d eta1=%f,%d "
322  "eta2=%f,%d quality=%d etaQuality=%d\n",
323  stub.bxNum(),
324  stub.tfLayer(),
325  stub.etaRegion(),
326  stub.phiRegion(),
327  stub.depthRegion(),
328  stub.offline_coord1(),
329  stub.coord1(),
330  stub.offline_coord2(),
331  stub.coord2(),
332  stub.offline_eta1(),
333  stub.eta1(),
334  stub.offline_eta2(),
335  stub.eta2(),
336  stub.quality(),
337  stub.etaQuality());
338  }
339 
340  return combinedStubs;
341 }
int sector() const
Sector id: the group of chambers at same phi (and increasing r)
Definition: RPCDetId.h:81
l1t::MuonStub buildCSCOnlyStub(const CSCDetId &, const CSCCorrelatedLCTDigi &, const L1TMuon::GeometryTranslator *)
double offline_eta1() const
Definition: MuonStub.h:98
int bx() const
Definition: RPCDigi.h:28
void setOfflineQuantities(double coord1, double coord2, double eta1, double eta2)
Definition: MuonStub.h:101
double offline_coord1() const
Definition: MuonStub.h:96
GlobalPoint getGlobalPoint(const TriggerPrimitive &) const
int trIndex() const
Definition: RPCDetId.h:96
int ring() const
Definition: RPCDetId.h:59
int etaRegion() const
return wheel
Definition: MuonStub.h:67
int depthRegion() const
return station
Definition: MuonStub.h:71
Primitive< F, X >::type primitive(const F &f)
Definition: Primitive.h:41
l1t::MuonStubCollection makeStubs(const MuonDigiCollection< CSCDetId, CSCCorrelatedLCTDigi > &csc, const MuonDigiCollection< RPCDetId, RPCDigi > &rpc, const L1TMuon::GeometryTranslator *t, const edm::EventSetup &iSetup)
uint16_t getBX() const
return BX
l1t::MuonStubCollection combineStubs(const l1t::MuonStubCollection &, const l1t::MuonStubCollection &)
int eta1() const
return eta
Definition: MuonStub.h:86
int chamber() const
Definition: CSCDetId.h:62
int subsector() const
SubSector id : some sectors are divided along the phi direction in subsectors (from 1 to 4 in Barrel...
Definition: RPCDetId.h:88
DigiRangeIterator begin() const
Definition: L1Track.h:19
std::vector< MuonStub > MuonStubCollection
Definition: MuonStub.h:40
int station() const
Definition: CSCDetId.h:79
int endcap() const
Definition: CSCDetId.h:85
int station() const
Definition: RPCDetId.h:78
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:53
void setEta(int eta1, int eta2, int etaQ)
Definition: MuonStub.h:107
int bxNum() const
return bunch crossing
Definition: MuonStub.h:83
int ring() const
Definition: CSCDetId.h:68
string quality
DigiRangeIterator end() const
l1t::MuonStub buildRPCOnlyStub(const RPCDetId &, const RPCDigi &, const L1TMuon::GeometryTranslator *)
A container for a generic type of digis indexed by some index, implemented with a map<IndexType...