CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
List of all members | Public Member Functions | Private Attributes
PtAssignment Class Reference

#include <PtAssignment.h>

Public Member Functions

const PtAssignmentEngineAuxaux () 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)
 
void process (EMTFTrackCollection &best_tracks)
 

Private Attributes

bool bugGMTPhi_
 
int bx_
 
int endcap_
 
int modeQualVer_
 
bool promoteMode7_
 
PtAssignmentEnginept_assign_engine_
 
PtAssignmentEngineDxypt_assign_engine_dxy_
 
int sector_
 
int verbose_
 

Detailed Description

Definition at line 10 of file PtAssignment.h.

Member Function Documentation

◆ aux()

const PtAssignmentEngineAux & PtAssignment::aux ( ) const

Definition at line 211 of file PtAssignment.cc.

References PtAssignmentEngine::aux(), and pt_assign_engine_.

Referenced by process().

211 { return pt_assign_engine_->aux(); }
PtAssignmentEngine * pt_assign_engine_
Definition: PtAssignment.h:33
const PtAssignmentEngineAux & aux() const

◆ configure()

void PtAssignment::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 at line 6 of file PtAssignment.cc.

References bugGMTPhi_, nano_mu_digi_cff::bx, bx_, PtAssignmentEngineDxy::configure(), PtAssignmentEngine::configure(), emtf_assert, makeMuonMisalignmentScenario::endcap, endcap_, modeQualVer_, promoteMode7_, pt_assign_engine_, pt_assign_engine_dxy_, nano_mu_digi_cff::sector, sector_, verbose, and verbose_.

Referenced by SectorProcessor::process_single_bx().

20  {
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 }
bool verbose
void configure(int verbose, bool readPtLUTFile, bool fixMode15HighPt, bool bug9BitDPhi, bool bugMode7CLCT, bool bugNegPt)
void configure(int verbose, const std::string pbFileNameDxy)
PtAssignmentEngineDxy * pt_assign_engine_dxy_
Definition: PtAssignment.h:35
PtAssignmentEngine * pt_assign_engine_
Definition: PtAssignment.h:33
bool promoteMode7_
Definition: PtAssignment.h:39
#define emtf_assert(expr)
Definition: DebugTools.h:18

◆ process()

void PtAssignment::process ( EMTFTrackCollection best_tracks)

Definition at line 42 of file PtAssignment.cc.

References funct::abs(), l1t::EMTFPtLUT::address, aux(), bugGMTPhi_, PtAssignmentEngine::calculate_address(), PtAssignmentEngine::calculate_pt(), PtAssignmentEngineDxy::calculate_pt_dxy(), gather_cfg::cout, PVValHelper::dxy, emtf_assert, endcap_, PtAssignmentEngine::get_pt_lut_version(), PtAssignmentEngineAux::getGMTCharge(), PtAssignmentEngineAux::getGMTDxy(), PtAssignmentEngineAux::getGMTEta(), PtAssignmentEngineAux::getGMTPhi(), PtAssignmentEngineAux::getGMTPhiV2(), PtAssignmentEngineAux::getGMTPt(), PtAssignmentEngineAux::getGMTPtDxy(), PtAssignmentEngineAux::getGMTQuality(), PtAssignmentEngineAux::getPtFromGMTPtDxy(), mps_fire::i, modeQualVer_, emtf::NUM_STATION_PAIRS, hitfit::phidiff(), promoteMode7_, DiDispStaMuonMonitor_cfi::pt, pt_assign_engine_, pt_assign_engine_dxy_, l1t::EMTFTrack::PtLUT(), PtAssignmentEngine::scale_pt(), HLT_2024v11_cff::track, and verbose_.

Referenced by SectorProcessor::process_single_bx().

42  {
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) {
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(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 }
constexpr int NUM_STATION_PAIRS
Definition: Common.h:59
int getGMTPtDxy(float pt) const
int getGMTQuality(int mode, int theta, bool promoteMode7, int version) const
virtual void calculate_pt_dxy(const EMTFTrack &track, emtf::Feature &feature, emtf::Prediction &prediction) const
double phidiff(double phi)
Normalized difference in azimuthal angles to a range between .
Definition: fourvec.cc:220
virtual float calculate_pt(const address_t &address) const
Log< level::Error, false > LogError
std::array< float, NUM_PREDICTIONS > Prediction
Definition: Common.h:72
virtual float scale_pt(const float pt, const int mode=15) const =0
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
int get_pt_lut_version() const
bool promoteMode7_
Definition: PtAssignment.h:39
int getGMTPt(float pt) const
virtual address_t calculate_address(const EMTFTrack &track) const
const PtAssignmentEngineAux & aux() const
std::pair< int, int > getGMTCharge(int mode, const std::vector< int > &phidiffs) const
int getGMTEta(int theta, int endcap) const
#define emtf_assert(expr)
Definition: DebugTools.h:18
uint64_t address
Definition: EMTFTrack.h:25
int getGMTPhi(int phi) const
EMTFPtLUT PtLUT() const
Definition: EMTFTrack.h:129
int getGMTPhiV2(int phi) const
std::array< float, NUM_FEATURES > Feature
Definition: Common.h:71
int getGMTDxy(float dxy) const
float getPtFromGMTPtDxy(int gmt_pt_dxy) const

Member Data Documentation

◆ bugGMTPhi_

bool PtAssignment::bugGMTPhi_
private

Definition at line 39 of file PtAssignment.h.

Referenced by configure(), and process().

◆ bx_

int PtAssignment::bx_
private

Definition at line 37 of file PtAssignment.h.

Referenced by configure().

◆ endcap_

int PtAssignment::endcap_
private

Definition at line 37 of file PtAssignment.h.

Referenced by configure(), and process().

◆ modeQualVer_

int PtAssignment::modeQualVer_
private

Definition at line 40 of file PtAssignment.h.

Referenced by configure(), and process().

◆ promoteMode7_

bool PtAssignment::promoteMode7_
private

Definition at line 39 of file PtAssignment.h.

Referenced by configure(), and process().

◆ pt_assign_engine_

PtAssignmentEngine* PtAssignment::pt_assign_engine_
private

Definition at line 33 of file PtAssignment.h.

Referenced by aux(), configure(), and process().

◆ pt_assign_engine_dxy_

PtAssignmentEngineDxy* PtAssignment::pt_assign_engine_dxy_
private

Definition at line 35 of file PtAssignment.h.

Referenced by configure(), and process().

◆ sector_

int PtAssignment::sector_
private

Definition at line 37 of file PtAssignment.h.

Referenced by configure().

◆ verbose_

int PtAssignment::verbose_
private

Definition at line 37 of file PtAssignment.h.

Referenced by configure(), and process().