CMS 3D CMS Logo

DigitalStub.cc
Go to the documentation of this file.
3 
6 
7 #include <atomic>
8 
9 using namespace std;
10 
11 namespace tmtt {
12 
13  //=== Hybrid tracking: simplified digitization for KF.
14 
15  DigitalStub::DigitalStub(const Settings* settings, double r, double phi, double z, unsigned int iPhiSec)
16  : phiSBits_(settings->phiSBits()), // No. of bits to store phiS coord.
17  phiSRange_(settings->phiSRange()), // Range of phiS coord. in radians.
18  rtBits_(settings->rtBits()), // No. of bits to store rT coord.
19  rtRange_(settings->rtRange()), // Range of rT coord. in cm.
20  zBits_(settings->zBits()), // No. of bits to store z coord.
21  zRange_(settings->zRange()), // Range of z coord in cm.
22  phiSMult_(pow(2, phiSBits_) / phiSRange_),
23  rtMult_(pow(2, rtBits_) / rtRange_),
24  zMult_(pow(2, zBits_) / zRange_),
25  numPhiSectors_(settings->numPhiSectors()),
26  numPhiNonants_(9),
27  phiSectorWidth_(2. * M_PI / double(numPhiSectors_)),
28  chosenRofPhi_(settings->chosenRofPhi()) {
29  // Centre of this sector in phi. (Nonant 0 is centred on x-axis).
30  phiCentreSec0_ = -M_PI / double(numPhiNonants_) + M_PI / double(numPhiSectors_);
31  phiSectorCentre_ = phiSectorWidth_ * double(iPhiSec) + phiCentreSec0_;
32 
33  // Used to check if new digi requests are for same sector as old
34  iPhiSec_done_ = iPhiSec;
35 
36  r_orig_ = r;
37  phi_orig_ = phi;
38  z_orig_ = z;
39 
42 
43  // Digitize
44  iDigi_Rt_ = floor(rt_orig_ * rtMult_);
45  iDigi_PhiS_ = floor(phiS_orig_ * phiSMult_);
46  iDigi_Z_ = floor(z_orig_ * zMult_);
47  }
48 
49  //=== TMTT tracking algorithm: digitisaton for entire L1 tracking chain.
50  // Initialize stub with floating point stub coords, range of HT m-bin values consistent with bend,
51  // bend and phi sector.
52 
54  double phi_orig,
55  double r_orig,
56  double z_orig,
57  unsigned int mbin_min_orig,
58  unsigned int mbin_max_orig,
59  double bend_orig,
60  unsigned int iPhiSec) {
61  // Set cfg params
62  this->setCfgParams(settings);
63 
64  // Store variable prior to digitisation
65  r_orig_ = r_orig;
68  z_orig_ = z_orig;
72 
73  // Phi of centre of phi sector and of nonant.
74  unsigned int iNonant = this->iNonant(iPhiSec);
75  phiSectorCentre_ = phiSectorWidth_ * double(iPhiSec) + phiCentreSec0_;
77 
80 
81  // Used to check if new digi requests are for same sector as old
82  iPhiSec_done_ = iPhiSec;
83 
84  // Check that stub coords. are within assumed digitization range.
85  this->checkInRange();
86 
87  // Digitize and then undigitize stub.
88  this->digitize(iPhiSec);
89  this->undigitize(iPhiSec);
90 
91  // Check that digitization followed by undigitization doesn't change results too much.
92  this->checkAccuracy();
93  }
94 
95  //=== Redo phi digitisation assigning stub to a different phi sector;
96 
97  bool DigitalStub::changePhiSec(unsigned int iPhiSec) {
98  bool doUpdate = (iPhiSec != iPhiSec_done_);
99 
100  if (doUpdate) {
101  // phi sector has changed since last time digitisation was done, so update.
102  iPhiSec_done_ = iPhiSec;
103  unsigned int iNonant = this->iNonant(iPhiSec);
104  // Update original, floating point phi w.r.t. phi sector/nonant centre.
105  phiSectorCentre_ = phiSectorWidth_ * double(iPhiSec) + phiCentreSec0_;
109  // Update digitised phi.
110  iDigi_PhiN_ = floor(phiN_orig_ * phiNMult_);
111  iDigi_PhiS_ = floor(phiS_orig_ * phiSMult_);
112  // Update digitized then undigitized phi.
113  phiN_ = (iDigi_PhiN_ + 0.5) / phiNMult_;
115  phiS_ = (iDigi_PhiS_ + 0.5) / phiSMult_;
117  }
118  return doUpdate;
119  }
120 
121  //=== Set configuration parameters.
122 
123  void DigitalStub::setCfgParams(const Settings* settings) {
124  // Digitization configuration parameters
125  phiSectorBits_ = settings->phiSectorBits(); // No. of bits to store phi sector number
126  //--- Parameters available in HT board.
127  phiSBits_ = settings->phiSBits(); // No. of bits to store phiS coord.
128  phiSRange_ = settings->phiSRange(); // Range of phiS coord. in radians.
129  rtBits_ = settings->rtBits(); // No. of bits to store rT coord.
130  rtRange_ = settings->rtRange(); // Range of rT coord. in cm.
131  zBits_ = settings->zBits(); // No. of bits to store z coord.
132  zRange_ = settings->zRange(); // Range of z coord in cm.
133  //--- Parameters available in GP board (excluding any in common with HT specified above).
134  phiNBits_ = settings->phiNBits(); // No. of bits to store phiN parameter.
135  phiNRange_ = settings->phiNRange(); // Range of phiN parameter
136  bendBits_ = settings->bendBits(); // No. of bits to store stub bend.
137 
138  // Number of phi sectors and phi nonants.
139  numPhiSectors_ = settings->numPhiSectors();
140  numPhiNonants_ = settings->numPhiNonants();
141  // Phi sector and phi nonant width (radians)
142  phiSectorWidth_ = 2. * M_PI / double(numPhiSectors_);
143  phiNonantWidth_ = 2. * M_PI / double(numPhiNonants_);
144  // Centre of phi sector 0.
145  phiCentreSec0_ = -M_PI / double(numPhiNonants_) + M_PI / double(numPhiSectors_);
146  // Radius from beamline with respect to which stub r coord. is measured.
147  chosenRofPhi_ = settings->chosenRofPhi();
148 
149  // Number of q/Pt bins in Hough transform array.
150  nbinsPt_ = (int)settings->houghNbinsPt();
151  // Min. of m-bin range in firmware,
152  min_array_mbin_ = (nbinsPt_ % 2 == 0) ? -(nbinsPt_ / 2) : -(nbinsPt_ - 1) / 2;
153 
154  // Calculate multipliers to digitize the floating point numbers.
156  rtMult_ = pow(2, rtBits_) / rtRange_;
157  zMult_ = pow(2, zBits_) / zRange_;
159 
160  // No precision lost by digitization, since original bend (after encoding) has steps of 0.25 (in units of pitch).
161  bendMult_ = 4.;
162  bendRange_ = round(pow(2, bendBits_) / bendMult_); // discrete values, so digitisation different
163  }
164 
165  //=== Digitize stub
166 
167  void DigitalStub::digitize(unsigned int iPhiSec) {
168  //--- Digitize variables used exclusively in GP input.
169  iDigi_PhiN_ = floor(phiN_orig_ * phiNMult_);
170  iDigi_Bend_ = round(bend_orig_ * bendMult_); // discrete values, so digitisation different
171 
172  //--- Digitize variables used exclusively in HT input.
173  iDigi_PhiS_ = floor(phiS_orig_ * phiSMult_);
174 
175  // Offset m-bin range allowed by bend to correspond to firmware.
178 
179  //--- Digitize variables used in both GP & HT input.
180  iDigi_Rt_ = floor(rt_orig_ * rtMult_);
181 
182  //-- Digitize variables used by SF & TF input
183  iDigi_R_ = iDigi_Rt_ + std::round(chosenRofPhi_ * rtMult_);
184 
185  //-- Digitize variables used by everything
186  iDigi_Z_ = floor(z_orig_ * zMult_);
187  }
188 
189  //=== Undigitize stub again.
190 
191  void DigitalStub::undigitize(unsigned int iPhiSec) {
192  //--- Undigitize variables used exclusively in GP.
193  phiN_ = (iDigi_PhiN_ + 0.5) / phiNMult_;
195  bend_ = iDigi_Bend_ / bendMult_; // discrete values, so digitisation different
196 
197  //--- Undigitize variables used exclusively by HT & SF/TF
198  phiS_ = (iDigi_PhiS_ + 0.5) / phiSMult_;
200 
201  //--- Undigitize variables used in both GP & HT.
202  rt_GP_HT_ = (iDigi_Rt_ + 0.5) / rtMult_;
204 
205  //--- Undigitize variables used exclusively by SF/TF.
206  r_SF_TF_ = (iDigi_R_ + 0.5) / rtMult_;
208 
209  //--- Undigitize variables used exclusively by everything.
210  z_ = (iDigi_Z_ + 0.5) / zMult_;
211  }
212 
213  //=== Check that stub coords. are within assumed digitization range.
214 
216  if (std::abs(rt_orig_) >= 0.5 * rtRange_)
217  throw cms::Exception("BadConfig") << "DigitalStub: Stub rT is out of assumed digitization range."
218  << " |rt| = " << std::abs(rt_orig_) << " > " << 0.5 * rtRange_;
219  if (std::abs(z_orig_) >= 0.5 * zRange_)
220  throw cms::Exception("BadConfig") << "DigitalStub: Stub z is out of assumed digitization range."
221  << " |z| = " << std::abs(z_orig_) << " > " << 0.5 * zRange_;
222  if (std::abs(bend_orig_) >= 0.5 * bendRange_)
223  throw cms::Exception("BadConfig") << "DigitalStub: Stub bend is out of assumed digitization range."
224  << " |bend| = " << std::abs(bend_orig_) << " > " << 0.5 * bendRange_;
225  //--- Can't check phi range, as DigitalStub called for stubs before sector assignment.
226  //if (std::abs(phiS_orig_) >= 0.5 * phiSRange_)
227  // throw cms::Exception("BadConfig") << "DigitalStub: Stub phiS is out of assumed digitization range."
228  // << " |phiS| = " << std::abs(phiS_orig_) << " > " << 0.5 * phiSRange_;
229  //if (std::abs(phiN_orig_) >= 0.5 * phiNRange_)
230  // throw cms::Exception("BadConfig") << "DigitalStub: Stub phiN is out of assumed digitization range."
231  // << " |phiN| = " << std::abs(phiN_orig_) << " > " << 0.5 * phiNRange_;
232  }
233 
234  //=== Check that digitisation followed by undigitisation doesn't change significantly the stub coordinates.
235 
237  double TA = reco::deltaPhi(phi_HT_TF_, phi_orig_);
238  double TB = r_GP_HT_ - r_orig_;
239  double TC = z_ - z_orig_;
240  double TD = bend_ - bend_orig_;
241 
242  // Compare to small numbers, representing acceptable precision loss.
243  constexpr double smallTA = 0.001, smallTB = 0.3, smallTC = 0.25, smallTD = 0.01;
244  if (std::abs(TA) > smallTA || std::abs(TB) > smallTB || std::abs(TC) > smallTC || std::abs(TD) > smallTD) {
245  throw cms::Exception("LogicError") << "WARNING: DigitalStub lost precision: " << TA << " " << TB << " " << TC
246  << " " << TD;
247  }
248  }
249 
250 } // namespace tmtt
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
double phiNonantCentre_
Definition: DigitalStub.h:125
double phiNRange() const
Definition: Settings.h:91
double bend_orig() const
Definition: DigitalStub.h:45
unsigned int nbinsPt_
Definition: DigitalStub.h:129
unsigned int phiSectorBits() const
Definition: Settings.h:82
unsigned int numPhiNonants() const
Definition: Settings.h:109
unsigned int phiSBits_
Definition: DigitalStub.h:97
unsigned int rtBits_
Definition: DigitalStub.h:99
unsigned int phiNBits() const
Definition: Settings.h:90
void digitize(unsigned int iPhiSec)
Definition: DigitalStub.cc:167
double phiSRange() const
Definition: Settings.h:84
double zRange() const
Definition: Settings.h:88
unsigned int zBits_
Definition: DigitalStub.h:101
double z_orig() const
Definition: DigitalStub.h:42
unsigned int bendBits() const
Definition: Settings.h:92
void checkInRange() const
Definition: DigitalStub.cc:215
unsigned int phiSBits() const
Definition: Settings.h:83
unsigned int mbin_min_orig() const
Definition: DigitalStub.h:43
unsigned int houghNbinsPt() const
Definition: Settings.h:137
void setCfgParams(const Settings *settings)
Definition: DigitalStub.cc:123
unsigned int mbin_min_orig_
Definition: DigitalStub.h:143
double phiSectorCentre_
Definition: DigitalStub.h:124
double phiSectorWidth_
Definition: DigitalStub.h:119
unsigned int iPhiSec_done_
Definition: DigitalStub.h:134
unsigned int zBits() const
Definition: Settings.h:87
unsigned int numPhiNonants_
Definition: DigitalStub.h:117
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double phi_orig() const
Definition: DigitalStub.h:39
unsigned int iNonant(unsigned int iPhiSec) const
Definition: DigitalStub.h:73
DigitalStub(const Settings *settings, double r, double phi, double z, unsigned int iPhiSec)
Definition: DigitalStub.cc:15
double chosenRofPhi() const
Definition: Settings.h:112
#define M_PI
unsigned int bendBits_
Definition: DigitalStub.h:105
unsigned int mbin_max_orig() const
Definition: DigitalStub.h:44
void undigitize(unsigned int iPhiSec)
Definition: DigitalStub.cc:191
=== This is the base class for the linearised chi-squared track fit algorithms.
Definition: Array2D.h:16
unsigned int mbin_max_orig_
Definition: DigitalStub.h:144
void checkAccuracy() const
Definition: DigitalStub.cc:236
unsigned int phiSectorBits_
Definition: DigitalStub.h:96
double r_orig() const
Definition: DigitalStub.h:37
unsigned int phiNBits_
Definition: DigitalStub.h:103
unsigned int iDigi_R_
Definition: DigitalStub.h:155
double z() const
Definition: DigitalStub.h:69
unsigned int numPhiSectors_
Definition: DigitalStub.h:116
unsigned int rtBits() const
Definition: Settings.h:85
double phiNonantWidth_
Definition: DigitalStub.h:120
unsigned int numPhiSectors() const
Definition: Settings.h:110
double rtRange() const
Definition: Settings.h:86
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
bool changePhiSec(unsigned int iPhiSec)
Definition: DigitalStub.cc:97