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  unsigned int tag) {
27  int endcap = detid.endcap();
28  int station = detid.station();
29  int chamber = detid.chamber();
30  int ring = detid.ring();
31 
33 
34  const GlobalPoint& gp = translator->getGlobalPoint(primitive);
35 
36  int phi = int(gp.phi().value() / coord1LSB_);
37  int eta1 = int(gp.eta() / eta1LSB_);
38 
39  int wheel = 0;
40  int sign = endcap == 1 ? -1 : 1;
41 
42  if (ring == 3)
43  wheel = sign * 3;
44  else if (ring == 2)
45  wheel = sign * 4;
46  else if (ring == 1)
47  wheel = sign * 5;
48 
49  int sector = fabs(chamber);
50 
51  int bx = digi.getBX() - 8;
52  int quality = 1;
53 
54  uint tfLayer = 0;
55  if ((ring == 3 || ring == 2) && station == 1) //ME1/3
56  tfLayer = 4;
57  else if (ring == 1 && station == 1) //ME1/3
58  tfLayer = 0;
59  else if (station == 2) //ME2/2
60  tfLayer = 2;
61  else if (station == 3) //ME3/2
62  tfLayer = 1;
63  else if (station == 4) //ME4/2
64  tfLayer = 3;
65 
66  l1t::MuonStub stub(wheel, sector, station, tfLayer, phi, 0, tag, bx, quality, eta1, 0, 1, 0);
67 
68  stub.setOfflineQuantities(gp.phi().value(), 0.0, gp.eta(), 0.0);
69  return stub;
70 }
71 
73  const RPCDigi& digi,
74  const L1TMuon::GeometryTranslator* translator) {
76  const GlobalPoint& gp = translator->getGlobalPoint(primitive);
77 
78  int phi2 = int(gp.phi().value() / coord2LSB_);
79  int eta2 = int(gp.eta() / eta2LSB_);
80 
81  int wheel = -(6 - detid.ring()) * detid.region();
82  int sector = (detid.sector() - 1) * 6 + detid.subsector();
83  int station = detid.station();
84  bool tag = detid.trIndex();
85  int bx = digi.bx();
86  int quality = 2;
87 
88  int ring = detid.ring();
89 
90  uint tfLayer = 0;
91 
92  if ((ring == 3 || ring == 2) && station == 1) //ME1/3
93  tfLayer = 4;
94  // else if (ring==1 && station==1) //ME1/3
95  // tfLayer=0;
96  else if (station == 2) //ME2/2
97  tfLayer = 2;
98  else if (station == 3) //ME3/2
99  tfLayer = 1;
100  else if (station == 4) //ME4/2
101  tfLayer = 3;
102 
103  l1t::MuonStub stub(wheel, sector, station, tfLayer, 0, phi2, tag, bx, quality, 0, eta2, 2, 0);
104  stub.setOfflineQuantities(gp.phi().value(), gp.phi().value(), gp.eta(), gp.eta());
105  return stub;
106 }
107 
109  const l1t::MuonStubCollection& rpcStubs) {
111  l1t::MuonStubCollection usedRPC;
112  l1t::MuonStubCollection cleanedRPC;
113 
114  l1t::MuonStubCollection cleanedCSC;
115 
116  //clean ME11 ambiguities
117  l1t::MuonStubCollection allCSC = cscStubs;
118 
119  while (!allCSC.empty()) {
120  l1t::MuonStub stub = allCSC[0];
121  l1t::MuonStubCollection freeCSC;
122  for (uint i = 1; i < allCSC.size(); ++i) {
123  if ((stub.etaRegion() == allCSC[i].etaRegion()) && (stub.depthRegion() == allCSC[i].depthRegion()) &&
124  (fabs(deltaPhi(stub.offline_coord1(), allCSC[i].offline_coord1())) < 0.001)) {
125  if (fabs(stub.offline_eta1() - allCSC[i].offline_eta1()) > 0.001) {
126  stub.setEta(stub.eta1(), allCSC[i].eta1(), 3);
127  stub.setOfflineQuantities(stub.offline_coord1(), 0.0, stub.offline_eta1(), allCSC[i].offline_eta1());
128  }
129  } else {
130  freeCSC.push_back(allCSC[i]);
131  }
132  }
133  cleanedCSC.push_back(stub);
134  allCSC = freeCSC;
135  }
136 
137  for (const auto& csc : cleanedCSC) {
138  int nRPC = 0;
139  float phiF = 0.0;
140  float etaF = 0.0;
141  int phi = 0;
142  int eta = 0;
143  for (const auto& rpc : rpcStubs) {
144  if (csc.depthRegion() != rpc.depthRegion())
145  continue;
146  if (fabs(deltaPhi(csc.offline_coord1(), rpc.offline_coord2())) < phiMatch_ &&
147  fabs(csc.offline_eta1() - rpc.offline_eta2()) < etaMatch_ && csc.bxNum() == rpc.bxNum()) {
148  phiF += rpc.offline_coord2();
149  etaF += rpc.offline_eta2();
150  phi += rpc.coord2();
151  eta += rpc.eta2();
152  nRPC++;
153  usedRPC.push_back(rpc);
154  }
155  }
156 
157  int finalRPCPhi = 0;
158  int finalRPCEta = 0;
159  double offline_finalRPCPhi = 0;
160  double offline_finalRPCEta = 0;
161  if (nRPC != 0) {
162  finalRPCPhi = phi / nRPC;
163  finalRPCEta = eta / nRPC;
164  offline_finalRPCPhi = phiF / nRPC;
165  offline_finalRPCEta = etaF / nRPC;
166  l1t::MuonStub stub(csc.etaRegion(),
167  csc.phiRegion(),
168  csc.depthRegion(),
169  csc.tfLayer(),
170  csc.coord1(),
171  finalRPCPhi,
172  0,
173  csc.bxNum(),
174  3,
175  csc.eta1(),
176  finalRPCEta,
177  3,
178  0);
179  stub.setOfflineQuantities(csc.offline_coord1(), offline_finalRPCPhi, csc.offline_eta1(), offline_finalRPCEta);
180  out.push_back(stub);
181  } else {
182  out.push_back(csc);
183  }
184  }
185 
186  //clean the RPC from the used ones
187 
188  for (const auto& rpc : rpcStubs) {
189  bool keep = true;
190  for (const auto& rpc2 : usedRPC) {
191  if (rpc == rpc2) {
192  keep = false;
193  break;
194  }
195  }
196  if (keep)
197  cleanedRPC.push_back(rpc);
198  }
199 
200  while (!cleanedRPC.empty()) {
201  l1t::MuonStubCollection freeRPC;
202 
203  int nRPC = 1;
204  float phiF = cleanedRPC[0].offline_coord2();
205  float etaF = cleanedRPC[0].offline_eta2();
206  int phi = cleanedRPC[0].coord2();
207  int eta = cleanedRPC[0].eta2();
208 
209  for (unsigned i = 1; i < cleanedRPC.size(); ++i) {
210  if (fabs(deltaPhi(cleanedRPC[0].offline_coord2(), cleanedRPC[i].offline_coord2())) < phiMatch_ &&
211  cleanedRPC[0].depthRegion() == cleanedRPC[i].depthRegion() &&
212  fabs(cleanedRPC[0].offline_eta2() - cleanedRPC[i].offline_eta2()) < etaMatch_ &&
213  cleanedRPC[0].bxNum() == cleanedRPC[i].bxNum()) {
214  phiF += cleanedRPC[i].offline_coord2();
215  etaF += cleanedRPC[i].offline_eta2();
216  phi += cleanedRPC[i].coord2();
217  eta += cleanedRPC[i].eta2();
218  nRPC++;
219  } else {
220  freeRPC.push_back(cleanedRPC[i]);
221  }
222  }
223  l1t::MuonStub stub(cleanedRPC[0].etaRegion(),
224  cleanedRPC[0].phiRegion(),
225  cleanedRPC[0].depthRegion(),
226  cleanedRPC[0].tfLayer(),
227  0,
228  phi / nRPC,
229  0,
230  cleanedRPC[0].bxNum(),
231  2,
232  0,
233  eta / nRPC,
234  2,
235  0);
236  stub.setOfflineQuantities(phiF / nRPC, phiF / nRPC, etaF / nRPC, etaF / nRPC);
237  out.push_back(stub);
238  cleanedRPC = freeRPC;
239  };
240  return out;
241 }
242 
247  const edm::EventSetup& iSetup) {
248  l1t::MuonStubCollection cscStubs;
249  auto chamber = csc.begin();
250  auto chend = csc.end();
251  for (; chamber != chend; ++chamber) {
252  auto digi = (*chamber).second.first;
253  auto dend = (*chamber).second.second;
254  unsigned int tag = 0;
255  for (; digi != dend; ++digi) {
256  l1t::MuonStub stub = buildCSCOnlyStub((*chamber).first, *digi, t, tag);
257  tag = tag + 1;
258  if (stub.bxNum() >= minBX_ && stub.bxNum() <= maxBX_)
259  cscStubs.push_back(stub);
260  }
261  }
262 
263  l1t::MuonStubCollection rpcStubs;
264 
265  auto rpcchamber = cleaned.begin();
266  auto rpcchend = cleaned.end();
267  for (; rpcchamber != rpcchend; ++rpcchamber) {
268  if ((*rpcchamber).first.region() == 0)
269  continue;
270  auto digi = (*rpcchamber).second.first;
271  auto dend = (*rpcchamber).second.second;
272  for (; digi != dend; ++digi) {
273  l1t::MuonStub stub = buildRPCOnlyStub((*rpcchamber).first, *digi, t);
274  if (stub.bxNum() >= minBX_ && stub.bxNum() <= maxBX_)
275  rpcStubs.push_back(stub);
276  }
277  }
278 
279  l1t::MuonStubCollection combinedStubs = combineStubs(cscStubs, rpcStubs);
280 
281  if (verbose_) {
282  edm::LogInfo("EndcapStub") << "CSC Stubs";
283  for (const auto& stub : cscStubs)
284  edm::LogInfo("EndcapStub") << "CSC Stub bx=" << stub.bxNum() << " TF=" << stub.tfLayer()
285  << " etaRegion=" << stub.etaRegion() << " phiRegion=" << stub.phiRegion()
286  << " depthRegion=" << stub.depthRegion() << " coord1=" << stub.offline_coord1() << ","
287  << stub.coord1() << " coord2=" << stub.offline_coord2() << "," << stub.coord2()
288  << " eta1=" << stub.offline_eta1() << "," << stub.eta1()
289  << " eta2=" << stub.offline_eta2() << "," << stub.eta2()
290  << " quality=" << stub.quality() << " etaQuality=" << stub.etaQuality();
291 
292  edm::LogInfo("EndcapStub") << "RPC Stubs";
293  for (const auto& stub : rpcStubs)
294  edm::LogInfo("EndcapStub") << "RPC Stub bx=" << stub.bxNum() << " TF=" << stub.tfLayer()
295  << " etaRegion=" << stub.etaRegion() << " phiRegion=" << stub.phiRegion()
296  << " depthRegion=" << stub.depthRegion() << " coord1=" << stub.offline_coord1() << ","
297  << stub.coord1() << " coord2=" << stub.offline_coord2() << "," << stub.coord2()
298  << " eta1=" << stub.offline_eta1() << "," << stub.eta1()
299  << " eta2=" << stub.offline_eta2() << "," << stub.eta2()
300  << " quality=" << stub.quality() << " etaQuality=" << stub.etaQuality();
301 
302  for (const auto& stub : combinedStubs)
303  edm::LogInfo("EndcapStub") << "Combined Stub bx=" << stub.bxNum() << " TF=" << stub.tfLayer()
304  << " etaRegion=" << stub.etaRegion() << " phiRegion=" << stub.phiRegion()
305  << " depthRegion=" << stub.depthRegion() << " coord1=" << stub.offline_coord1() << ","
306  << stub.coord1() << " coord2=" << stub.offline_coord2() << "," << stub.coord2()
307  << " eta1=" << stub.offline_eta1() << "," << stub.eta1()
308  << " eta2=" << stub.offline_eta2() << "," << stub.eta2()
309  << " quality=" << stub.quality() << " etaQuality=" << stub.etaQuality();
310  }
311 
312  return combinedStubs;
313 }
double offline_eta1() const
Definition: MuonStub.h:120
int bx() const
Definition: RPCDigi.h:28
l1t::MuonStub buildCSCOnlyStub(const CSCDetId &, const CSCCorrelatedLCTDigi &, const L1TMuon::GeometryTranslator *, unsigned int)
void setOfflineQuantities(double coord1, double coord2, double eta1, double eta2)
Definition: MuonStub.h:123
double offline_coord1() const
Definition: MuonStub.h:118
GlobalPoint getGlobalPoint(const TriggerPrimitive &) const
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
string quality
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:108
DigiRangeIterator begin() const
Definition: L1Track.h:19
std::vector< MuonStub > MuonStubCollection
Definition: MuonStub.h:40
Log< level::Info, false > LogInfo
void setEta(int eta1, int eta2, int etaQ)
Definition: MuonStub.h:129
int bxNum() const
return bunch crossing
Definition: MuonStub.h:105
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...