CMS 3D CMS Logo

L1TPhase2GMTBarrelStubProcessor.cc
Go to the documentation of this file.
2 #include <cmath>
3 #include <iostream>
4 #include <string>
5 #include <sstream>
6 #include <iomanip>
7 #include <ap_int.h>
8 
9 L1TPhase2GMTBarrelStubProcessor::L1TPhase2GMTBarrelStubProcessor() : minPhiQuality_(0), minBX_(-3), maxBX_(3) {}
10 
12  : minPhiQuality_(iConfig.getParameter<int>("minPhiQuality")),
13  minBX_(iConfig.getParameter<int>("minBX")),
14  maxBX_(iConfig.getParameter<int>("maxBX")),
15  eta1_(iConfig.getParameter<std::vector<int> >("eta_1")),
16  eta2_(iConfig.getParameter<std::vector<int> >("eta_2")),
17  eta3_(iConfig.getParameter<std::vector<int> >("eta_3")),
18  coarseEta1_(iConfig.getParameter<std::vector<int> >("coarseEta_1")),
19  coarseEta2_(iConfig.getParameter<std::vector<int> >("coarseEta_2")),
20  coarseEta3_(iConfig.getParameter<std::vector<int> >("coarseEta_3")),
21  coarseEta4_(iConfig.getParameter<std::vector<int> >("coarseEta_4")),
22  phiOffset_(iConfig.getParameter<std::vector<int> >("phiOffset")),
23  phiBFactor_(iConfig.getParameter<int>("phiBDivider")),
24  verbose_(iConfig.getParameter<int>("verbose")),
25  phiLSB_(iConfig.getParameter<double>("phiLSB")),
26  etaLSB_(iConfig.getParameter<double>("etaLSB")) {}
27 
29 
31  const L1MuDTChambThDigi* etaS) {
32  l1t::MuonStub stub = buildStubNoEta(phiS);
33 
34  //Now full eta
35  int qeta1 = -16384;
36  int qeta2 = -16384;
37  int eta1 = -16384;
38  int eta2 = -16384;
39 
40  bool hasEta = false;
41  for (uint i = 0; i < 7; ++i) {
42  if (etaS->position(i) == 0)
43  continue;
44  if (!hasEta) {
45  hasEta = true;
46  eta1 = calculateEta(i, etaS->whNum(), etaS->scNum(), etaS->stNum());
47 
48  if (etaS->quality(i) == 1)
49  qeta1 = 2;
50  else
51  qeta1 = 1;
52  } else {
53  eta2 = calculateEta(i, etaS->whNum(), etaS->scNum(), etaS->stNum());
54  if (etaS->quality(i) == 1)
55  qeta2 = 2;
56  else
57  qeta2 = 1;
58  }
59  }
60 
61  if (qeta2 > 0) { //both stubs->average
62  stub.setEta(eta1, eta2, 3);
64 
65  } else if (qeta1 > 0) { //Good single stub
66  stub.setEta(eta1, 0, 1);
67  stub.setOfflineQuantities(stub.offline_coord1(), stub.offline_coord2(), eta1 * etaLSB_, 0.0);
68  }
69 
70  return stub;
71 }
72 
74  int wheel = phiS.whNum();
75  int abswheel = fabs(phiS.whNum());
76  int sign = wheel > 0 ? 1 : -1;
77  int sector = phiS.scNum();
78  int station = phiS.stNum();
79 
80  ap_uint<18> normalization0 = sector * ap_uint<15>(21845);
81  ap_int<18> normalization1 = ap_int<18>(ap_int<17>(phiS.phi()) * ap_ufixed<8, 0>(0.3183));
82  ap_int<18> kmtf_phi = ap_int<18>(normalization0 + normalization1);
83  int phi = int(kmtf_phi);
84  float globalPhi = phi * M_PI / (1 << 17);
85 
86  // double globalPhi = (sector * 30) + phiS.phi() * 30. / 65535.;
87  int tag = phiS.index();
88 
89  int bx = phiS.bxNum() - 20;
90  int quality = phiS.quality();
91  uint tfLayer = phiS.stNum() - 1;
92  int eta = -16384;
93  if (station == 1) {
94  eta = coarseEta1_[abswheel];
95  } else if (station == 2) {
96  eta = coarseEta2_[abswheel];
97  } else if (station == 3) {
98  eta = coarseEta3_[abswheel];
99  } else if (station == 4) {
100  eta = coarseEta4_[abswheel];
101  }
102 
103  //override!!!
104  // eta=abswheel;
105 
106  //Now full eta
107 
108  eta = eta * sign;
109  l1t::MuonStub stub(wheel, sector, station, tfLayer, phi, phiS.phiBend(), tag, bx, quality, eta, 0, 0, 1);
110 
111  stub.setOfflineQuantities(globalPhi, float(phiS.phiBend() * 0.49e-3), eta * etaLSB_, 0.0);
112  return stub;
113 }
114 
116  const L1MuDTChambThContainer* etaContainer) {
118  for (int bx = minBX_; bx <= maxBX_; bx++) {
119  ostringstream os;
120  if (verbose_ == 2)
121  os << "PATTERN ";
122  for (int wheel = -2; wheel <= 2; wheel++) {
123  for (int sector = 0; sector < 12; sector++) {
124  for (int station = 1; station < 5; station++) {
125  bool hasEta = false;
126  const L1MuDTChambThDigi* tseta = etaContainer->chThetaSegm(wheel, station, sector, bx);
127  if (tseta != nullptr) {
128  hasEta = true;
129  }
130 
131  for (const auto& phiDigi : *phiContainer->getContainer()) {
132  if ((phiDigi.bxNum() - 20) != bx || phiDigi.whNum() != wheel || phiDigi.scNum() != sector ||
133  phiDigi.stNum() != station)
134  continue;
135  if (phiDigi.quality() < minPhiQuality_)
136  continue;
137 
138  if (verbose_ == 2) {
139  ap_uint<64> wphi = ap_uint<17>(phiDigi.phi());
140  ap_uint<64> wphib = ap_uint<13>(phiDigi.phiBend());
141  ap_uint<64> wr1 = ap_uint<21>(0);
142  ap_uint<64> wq = ap_uint<4>(phiDigi.quality());
143  ap_uint<64> wr2 = ap_uint<9>(0);
144  ap_uint<64> sN = 0;
145  sN = sN | wphi;
146  sN = sN | (wphib << 17);
147  sN = sN | (wr1 << 30);
148  sN = sN | (wq << 51);
149  sN = sN | (wr2 << 55);
150  os << std::setw(0) << std::dec << sector << " " << wheel << " " << station << " ";
151  os << std::uppercase << std::setfill('0') << std::setw(16) << std::hex << uint64_t(sN) << " ";
152  }
153 
154  if (hasEta) {
155  out.push_back(buildStub(phiDigi, tseta));
156  } else {
157  out.push_back(buildStubNoEta(phiDigi));
158  }
159  }
160  }
161  }
162  }
163  if (verbose_ == 2)
164  edm::LogInfo("BarrelStub") << os.str() << std::endl;
165  }
166 
167  if (verbose_) {
168  edm::LogInfo("BarrelStub") << "Barrel Stubs";
169  for (const auto& stub : out)
170  edm::LogInfo("BarrelStub") << "Barrel Stub bx=" << stub.bxNum() << " TF=" << stub.tfLayer()
171  << " etaRegion=" << stub.etaRegion() << " phiRegion=" << stub.phiRegion()
172  << " depthRegion=" << stub.depthRegion() << " coord1=" << stub.offline_coord1() << ","
173  << stub.coord1() << " coord2=" << stub.offline_coord2() << "," << stub.coord2()
174  << " eta1=" << stub.offline_eta1() << "," << stub.eta1()
175  << " eta2=" << stub.offline_eta2() << "," << stub.eta2()
176  << " quality=" << stub.quality() << " etaQuality=" << stub.etaQuality();
177  }
178 
179  return out;
180 }
181 
183  int eta = 0;
184  if (wheel > 0) {
185  eta = 7 * wheel + 3 - i;
186  } else if (wheel < 0) {
187  eta = 7 * wheel + i - 3;
188  } else {
189  if (sector == 0 || sector == 3 || sector == 4 || sector == 7 || sector == 8 || sector == 11)
190  eta = i - 3;
191  else
192  eta = 3 - i;
193  }
194 
195  if (station == 1)
196  eta = eta1_[eta + 17];
197  else if (station == 2)
198  eta = eta2_[eta + 17];
199  else
200  eta = eta3_[eta + 17];
201 
202  return eta;
203 }
L1MuDTChambThDigi const * chThetaSegm(int wheel, int stat, int sect, int bx) const
void setOfflineQuantities(double coord1, double coord2, double eta1, double eta2)
Definition: MuonStub.h:123
double offline_coord1() const
Definition: MuonStub.h:118
int position(const int i) const
string quality
#define M_PI
std::vector< MuonStub > MuonStubCollection
Definition: MuonStub.h:40
l1t::MuonStub buildStub(const L1Phase2MuDTPhDigi &, const L1MuDTChambThDigi *)
Log< level::Info, false > LogInfo
l1t::MuonStubCollection makeStubs(const L1Phase2MuDTPhContainer *, const L1MuDTChambThContainer *)
unsigned long long uint64_t
Definition: Time.h:13
l1t::MuonStub buildStubNoEta(const L1Phase2MuDTPhDigi &)
Segment_Container const * getContainer() const
double offline_coord2() const
Definition: MuonStub.h:119
void setEta(int eta1, int eta2, int etaQ)
Definition: MuonStub.h:129
int quality(const int i) const