CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PtAssignment.cc
Go to the documentation of this file.
2 
5 
7  PtAssignmentEngineDxy* pt_assign_engine_dxy,
8  int verbose,
9  int endcap,
10  int sector,
11  int bx,
12  bool readPtLUTFile,
13  bool fixMode15HighPt,
14  bool bug9BitDPhi,
15  bool bugMode7CLCT,
16  bool bugNegPt,
17  bool bugGMTPhi,
18  bool promoteMode7,
19  int modeQualVer,
20  std::string pbFileName) {
21  emtf_assert(pt_assign_engine != nullptr);
22  emtf_assert(pt_assign_engine_dxy != nullptr);
23 
24  pt_assign_engine_ = pt_assign_engine;
25 
26  pt_assign_engine_dxy_ = pt_assign_engine_dxy;
27 
28  verbose_ = verbose;
29  endcap_ = endcap;
30  sector_ = sector;
31  bx_ = bx;
32 
33  pt_assign_engine_->configure(verbose_, readPtLUTFile, fixMode15HighPt, bug9BitDPhi, bugMode7CLCT, bugNegPt);
34 
36 
37  bugGMTPhi_ = bugGMTPhi;
38  promoteMode7_ = promoteMode7;
39  modeQualVer_ = modeQualVer;
40 }
41 
43  using address_t = PtAssignmentEngine::address_t;
44 
45  EMTFTrackCollection::iterator best_tracks_it = best_tracks.begin();
46  EMTFTrackCollection::iterator best_tracks_end = best_tracks.end();
47 
48  for (; best_tracks_it != best_tracks_end; ++best_tracks_it) {
49  EMTFTrack& track = *best_tracks_it; // pass by reference
50 
51  // Assign GMT eta and phi
52  int gmt_phi = aux().getGMTPhi(track.Phi_fp());
53 
54  if (!bugGMTPhi_) {
55  gmt_phi = aux().getGMTPhiV2(track.Phi_fp());
56  }
57 
58  int gmt_eta = aux().getGMTEta(track.Theta_fp(), track.Endcap()); // Convert to integer eta using FW LUT
59 
60  // Notes from Alex (2016-09-28):
61  //
62  // When using two's complement, you get two eta bins with zero coordinate.
63  // This peculiarity is created because positive and negative endcaps are
64  // processed by separate processors, so each of them gets its own zero bin.
65  // With simple inversion, the eta scale becomes uniform, one bin for one
66  // eta value.
67  bool use_ones_complem_gmt_eta = true;
68  if (use_ones_complem_gmt_eta) {
69  gmt_eta = (gmt_eta < 0) ? ~(-gmt_eta) : gmt_eta;
70  }
71 
72  // Assign prompt & displaced pT
73  address_t address = 0;
74  float xmlpt = 0.;
75  float pt = 0.;
76  int gmt_pt = 0;
77 
78  float pt_dxy = 0.;
79  float dxy = 0.;
80  int gmt_pt_dxy = 0;
81  int gmt_dxy = 0;
82 
83  if (track.Mode() != 1) {
84  address = pt_assign_engine_->calculate_address(track);
85  xmlpt = pt_assign_engine_->calculate_pt(address);
86 
87  // Check address packing / unpacking using PtAssignmentEngine2017::calculate_pt_xml(const EMTFTrack& track)
89  not(fabs(xmlpt - pt_assign_engine_->calculate_pt(track)) < 0.001)) {
90  edm::LogError("L1T") << "EMTF pT assignment mismatch: xmlpt = " << xmlpt
91  << ", pt_assign_engine_->calculate_pt(track)) = "
93  }
94 
95  pt = (xmlpt < 0.) ? 1. : xmlpt; // Matt used fabs(-1) when mode is invalid
97  pt, track.Mode()); // Multiply by some factor to achieve 90% efficiency at threshold
98 
99  gmt_pt = aux().getGMTPt(pt); // Encode integer pT in GMT format
100  } // End if (track.Mode() != 1)
101  else {
102  gmt_pt = 10 - (abs(gmt_eta) / 32);
103  }
104 
105  pt = (gmt_pt <= 0) ? 0 : (gmt_pt - 1) * 0.5; // Decode integer pT (result is in 0.5 GeV step)
106 
107  // Calculate displaced pT and d0 using NN
108  emtf::Feature feature;
109  emtf::Prediction prediction;
110 
111  feature.fill(0);
112  prediction.fill(0);
113 
114  pt_assign_engine_dxy_->calculate_pt_dxy(track, feature, prediction);
115 
116  pt_dxy = std::abs(1.0 / prediction.at(0));
117  dxy = prediction.at(1);
118 
119  gmt_pt_dxy = aux().getGMTPtDxy(pt_dxy);
120  gmt_dxy = aux().getGMTDxy(dxy);
121 
122  pt_dxy = aux().getPtFromGMTPtDxy(gmt_pt_dxy);
123 
124  int gmt_quality = 0;
125  if (track.Mode() != 1) {
126  gmt_quality = aux().getGMTQuality(track.Mode(), track.Theta_fp(), promoteMode7_, modeQualVer_);
127  } else { // Special quality for single-hit tracks from ME1/1
128  gmt_quality = track.Hits().front().Pattern() / 4;
129  }
130 
131  std::pair<int, int> gmt_charge = std::make_pair(0, 0);
132  if (track.Mode() != 1) {
133  std::vector<int> phidiffs;
134  for (int i = 0; i < emtf::NUM_STATION_PAIRS; ++i) {
135  int phidiff = (track.PtLUT().sign_ph[i] == 1) ? track.PtLUT().delta_ph[i] : -track.PtLUT().delta_ph[i];
136  phidiffs.push_back(phidiff);
137  }
138  gmt_charge = aux().getGMTCharge(track.Mode(), phidiffs);
139  } else { // Special charge assignment for single-hit tracks from ME1/1
140  int CLCT = track.Hits().front().Pattern();
141  if (CLCT != 10) {
142  if (endcap_ == 1)
143  gmt_charge = std::make_pair((CLCT % 2) == 0 ? 0 : 1, 1);
144  else
145  gmt_charge = std::make_pair((CLCT % 2) == 0 ? 1 : 0, 1);
146  }
147  }
148 
149  // _________________________________________________________________________
150  // Output
151 
152  EMTFPtLUT tmp_LUT = track.PtLUT();
153  tmp_LUT.address = address;
154 
155  track.set_PtLUT(tmp_LUT);
156  track.set_pt_XML(xmlpt);
157  track.set_pt(pt);
158  track.set_pt_dxy(pt_dxy);
159  track.set_dxy(dxy);
160  track.set_charge((gmt_charge.second == 1) ? ((gmt_charge.first == 1) ? -1 : +1) : 0);
161 
162  track.set_gmt_pt(gmt_pt);
163  track.set_gmt_pt_dxy(gmt_pt_dxy);
164  track.set_gmt_dxy(gmt_dxy);
165  track.set_gmt_phi(gmt_phi);
166  track.set_gmt_eta(gmt_eta);
167  track.set_gmt_quality(gmt_quality);
168  track.set_gmt_charge(gmt_charge.first);
169  track.set_gmt_charge_valid(gmt_charge.second);
170  }
171 
172  // Remove worst track if it addresses the same bank as one of two best tracks
173  bool disable_worst_track_in_same_bank = true;
174  if (disable_worst_track_in_same_bank) {
175  // FW macro for detecting same bank address
176  // bank and chip must match, and valid flags must be set
177  // a and b are indexes 0,1,2
178  // `define sb(a,b) (ptlut_addr[a][29:26] == ptlut_addr[b][29:26] && ptlut_addr[a][5:2] == ptlut_addr[b][5:2] && ptlut_addr_val[a] && ptlut_addr_val[b])
179  auto is_in_same_bank = [](const EMTFTrack& lhs, const EMTFTrack& rhs) {
180  unsigned lhs_addr = lhs.PtLUT().address;
181  unsigned rhs_addr = rhs.PtLUT().address;
182  unsigned lhs_addr_1 = (lhs_addr >> 26) & 0xF;
183  unsigned rhs_addr_1 = (rhs_addr >> 26) & 0xF;
184  unsigned lhs_addr_2 = (lhs_addr >> 2) & 0xF;
185  unsigned rhs_addr_2 = (rhs_addr >> 2) & 0xF;
186  return (lhs_addr_1 == rhs_addr_1) && (lhs_addr_2 == rhs_addr_2);
187  };
188 
189  emtf_assert(best_tracks.size() <= 3);
190  if (best_tracks.size() == 3) {
191  bool same_bank = is_in_same_bank(best_tracks.at(0), best_tracks.at(2)) ||
192  is_in_same_bank(best_tracks.at(1), best_tracks.at(2));
193  if (same_bank) {
194  // Set worst track pT to zero
195  best_tracks.at(2).set_pt(0);
196  best_tracks.at(2).set_gmt_pt(0);
197  }
198  }
199  }
200 
201  if (verbose_ > 0) { // debug
202  for (const auto& track : best_tracks) {
203  std::cout << "track: " << track.Winner() << " pt address: " << track.PtLUT().address
204  << " GMT pt: " << track.GMT_pt() << " pt: " << track.Pt() << " mode: " << track.Mode()
205  << " GMT charge: " << track.GMT_charge() << " quality: " << track.GMT_quality()
206  << " eta: " << track.GMT_eta() << " phi: " << track.GMT_phi() << std::endl;
207  }
208  }
209 }
210 
int Theta_fp() const
Definition: EMTFTrack.h:187
virtual address_t calculate_address(const EMTFTrack &track) const
l1t::EMTFTrackCollection EMTFTrackCollection
Definition: Common.h:27
constexpr int NUM_STATION_PAIRS
Definition: Common.h:59
void set_gmt_eta(int bits)
Definition: EMTFTrack.h:159
virtual float calculate_pt(const address_t &address) const
uint16_t sign_ph[6]
Definition: EMTFTrack.h:32
int Endcap() const
Definition: EMTFTrack.h:165
const PtAssignmentEngineAux & aux() const
int getGMTPhiV2(int phi) const
int Phi_fp() const
Definition: EMTFTrack.h:190
void configure(int verbose, bool readPtLUTFile, bool fixMode15HighPt, bool bug9BitDPhi, bool bugMode7CLCT, bool bugNegPt)
void set_charge(int bits)
Definition: EMTFTrack.h:138
int getGMTEta(int theta, int endcap) const
int getGMTPtDxy(float pt) const
double phidiff(double phi)
Normalized difference in azimuthal angles to a range between .
Definition: fourvec.cc:220
Log< level::Error, false > LogError
uint16_t delta_ph[6]
Definition: EMTFTrack.h:30
void set_PtLUT(EMTFPtLUT bits)
Definition: EMTFTrack.h:128
const PtAssignmentEngineAux & aux() const
void configure(int verbose, const std::string pbFileNameDxy)
std::array< float, NUM_PREDICTIONS > Prediction
Definition: Common.h:72
void set_gmt_phi(int bits)
Definition: EMTFTrack.h:158
void set_pt(float val)
Definition: EMTFTrack.h:142
void set_gmt_pt_dxy(int bits)
Definition: EMTFTrack.h:156
static constexpr int verbose
virtual float scale_pt(const float pt, const int mode=15) const =0
void set_gmt_quality(int bits)
Definition: EMTFTrack.h:160
PtAssignmentEngineDxy * pt_assign_engine_dxy_
Definition: PtAssignment.h:35
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
PtAssignmentEngine * pt_assign_engine_
Definition: PtAssignment.h:33
bool promoteMode7_
Definition: PtAssignment.h:39
std::pair< int, int > getGMTCharge(int mode, const std::vector< int > &phidiffs) const
void set_gmt_dxy(int bits)
Definition: EMTFTrack.h:157
int getGMTDxy(float dxy) const
void set_gmt_charge(int bits)
Definition: EMTFTrack.h:161
EMTFHitCollection Hits() const
Definition: EMTFTrack.h:125
int get_pt_lut_version() const
#define emtf_assert(expr)
Definition: DebugTools.h:18
void process(EMTFTrackCollection &best_tracks)
Definition: PtAssignment.cc:42
uint64_t address
Definition: EMTFTrack.h:25
void set_pt_XML(float val)
Definition: EMTFTrack.h:143
float getPtFromGMTPtDxy(int gmt_pt_dxy) const
void configure(PtAssignmentEngine *pt_assign_engine, PtAssignmentEngineDxy *pt_assign_engine_dxy, int verbose, int endcap, int sector, int bx, bool readPtLUTFile, bool fixMode15HighPt, bool bug9BitDPhi, bool bugMode7CLCT, bool bugNegPt, bool bugGMTPhi, bool promoteMode7, int modeQualVer, std::string pbFileName)
Definition: PtAssignment.cc:6
int getGMTPhi(int phi) const
int Mode() const
Definition: EMTFTrack.h:168
std::array< float, NUM_FEATURES > Feature
Definition: Common.h:71
void set_gmt_charge_valid(int bits)
Definition: EMTFTrack.h:162
tuple cout
Definition: gather_cfg.py:144
int getGMTPt(float pt) const
EMTFPtLUT PtLUT() const
Definition: EMTFTrack.h:129
void set_gmt_pt(int bits)
Definition: EMTFTrack.h:155
virtual void calculate_pt_dxy(const EMTFTrack &track, emtf::Feature &feature, emtf::Prediction &prediction) const
void set_dxy(float val)
Definition: EMTFTrack.h:145
int getGMTQuality(int mode, int theta, bool promoteMode7, int version) const
void set_pt_dxy(float val)
Definition: EMTFTrack.h:144