CMS 3D CMS Logo

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