CMS 3D CMS Logo

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