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
tmtt::DigitalStub::r_orig_
double r_orig_
Definition: DigitalStub.h:137
tmtt::DigitalStub::mbin_max_orig_
unsigned int mbin_max_orig_
Definition: DigitalStub.h:144
tmtt::DigitalStub::phiSMult_
double phiSMult_
Definition: DigitalStub.h:109
tmtt::DigitalStub::phi_HT_TF_
double phi_HT_TF_
Definition: DigitalStub.h:163
tmtt::DigitalStub::r_orig
double r_orig() const
Definition: DigitalStub.h:37
tmtt::DigitalStub::iDigi_Bend_
int iDigi_Bend_
Definition: DigitalStub.h:150
tmtt::DigitalStub::phiN_
double phiN_
Definition: DigitalStub.h:159
tmtt::DigitalStub::bendMult_
double bendMult_
Definition: DigitalStub.h:113
tmtt::Settings::numPhiNonants
unsigned int numPhiNonants() const
Definition: Settings.h:109
reco::deltaPhi
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
tmtt::DigitalStub::phiNRange_
double phiNRange_
Definition: DigitalStub.h:104
tmtt::DigitalStub::numPhiSectors_
unsigned int numPhiSectors_
Definition: DigitalStub.h:116
tmtt::DigitalStub::phiNMult_
double phiNMult_
Definition: DigitalStub.h:112
tmtt::DigitalStub::bend_
double bend_
Definition: DigitalStub.h:161
tmtt::Settings::phiNBits
unsigned int phiNBits() const
Definition: Settings.h:90
tmtt::DigitalStub::phi_GP_
double phi_GP_
Definition: DigitalStub.h:160
tmtt::DigitalStub::phiSBits_
unsigned int phiSBits_
Definition: DigitalStub.h:97
tmtt::DigitalStub::zBits_
unsigned int zBits_
Definition: DigitalStub.h:101
tmtt::DigitalStub::iDigi_Z_
int iDigi_Z_
Definition: DigitalStub.h:156
tmtt::DigitalStub::checkInRange
void checkInRange() const
Definition: DigitalStub.cc:215
tmtt::DigitalStub::phiCentreSec0_
double phiCentreSec0_
Definition: DigitalStub.h:122
tmtt::Settings::chosenRofPhi
double chosenRofPhi() const
Definition: Settings.h:112
tmtt::DigitalStub::rt_GP_HT_
double rt_GP_HT_
Definition: DigitalStub.h:164
tmtt::DigitalStub::iDigi_PhiN_
int iDigi_PhiN_
Definition: DigitalStub.h:149
tmtt::DigitalStub::mbin_min_orig
unsigned int mbin_min_orig() const
Definition: DigitalStub.h:43
tmtt::DigitalStub::r_SF_TF_
double r_SF_TF_
Definition: DigitalStub.h:166
tmtt::DigitalStub::DigitalStub
DigitalStub(const Settings *settings, double r, double phi, double z, unsigned int iPhiSec)
Definition: DigitalStub.cc:15
tmtt::DigitalStub::phiSectorCentre_
double phiSectorCentre_
Definition: DigitalStub.h:124
tmtt::DigitalStub::rt_orig_
double rt_orig_
Definition: DigitalStub.h:138
tmtt::Settings::phiSRange
double phiSRange() const
Definition: Settings.h:84
tmtt::DigitalStub::iPhiSec_done_
unsigned int iPhiSec_done_
Definition: DigitalStub.h:134
tmtt::DigitalStub::numPhiNonants_
unsigned int numPhiNonants_
Definition: DigitalStub.h:117
tmtt::DigitalStub::iDigi_Rt_
int iDigi_Rt_
Definition: DigitalStub.h:154
tmtt::DigitalStub::iDigi_PhiS_
int iDigi_PhiS_
Definition: DigitalStub.h:151
beampixel_dqm_sourceclient-live_cfg.zRange
zRange
Definition: beampixel_dqm_sourceclient-live_cfg.py:148
tmtt::Settings::bendBits
unsigned int bendBits() const
Definition: Settings.h:92
tmtt::DigitalStub::rtBits_
unsigned int rtBits_
Definition: DigitalStub.h:99
tmtt::DigitalStub::z_orig
double z_orig() const
Definition: DigitalStub.h:42
tmtt::DigitalStub::iNonant
unsigned int iNonant(unsigned int iPhiSec) const
Definition: DigitalStub.h:73
tmtt::DigitalStub::r_GP_HT_
double r_GP_HT_
Definition: DigitalStub.h:165
tmtt::Settings::zBits
unsigned int zBits() const
Definition: Settings.h:87
tmtt::DigitalStub::digitize
void digitize(unsigned int iPhiSec)
Definition: DigitalStub.cc:167
tmtt::DigitalStub::mbin_min_orig_
unsigned int mbin_min_orig_
Definition: DigitalStub.h:143
tmtt::DigitalStub::setCfgParams
void setCfgParams(const Settings *settings)
Definition: DigitalStub.cc:123
tmtt::DigitalStub::iDigi_R_
unsigned int iDigi_R_
Definition: DigitalStub.h:155
tmtt::DigitalStub::z
double z() const
Definition: DigitalStub.h:69
tmtt::DigitalStub::bendRange_
double bendRange_
Definition: DigitalStub.h:106
tmtt::DigitalStub::phiSectorWidth_
double phiSectorWidth_
Definition: DigitalStub.h:119
tmtt::DigitalStub::phiSRange_
double phiSRange_
Definition: DigitalStub.h:98
tmtt::Settings
Definition: Settings.h:17
tmtt::DigitalStub::phiS_
double phiS_
Definition: DigitalStub.h:162
createfilelist.int
int
Definition: createfilelist.py:10
tmtt::DigitalStub::mbin_max_
int mbin_max_
Definition: DigitalStub.h:153
DigitalStub.h
tmtt::DigitalStub::zMult_
double zMult_
Definition: DigitalStub.h:111
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:50
tmtt::DigitalStub::phi_orig
double phi_orig() const
Definition: DigitalStub.h:39
tmtt::DigitalStub::phiN_orig_
double phiN_orig_
Definition: DigitalStub.h:141
tmtt::DigitalStub::checkAccuracy
void checkAccuracy() const
Definition: DigitalStub.cc:236
tmtt::Settings::phiSBits
unsigned int phiSBits() const
Definition: Settings.h:83
tmtt::Settings::numPhiSectors
unsigned int numPhiSectors() const
Definition: Settings.h:110
tmtt::Settings::zRange
double zRange() const
Definition: Settings.h:88
tmtt::DigitalStub::phi_orig_
double phi_orig_
Definition: DigitalStub.h:139
tmtt::Settings::rtRange
double rtRange() const
Definition: Settings.h:86
tmtt::DigitalStub::bendBits_
unsigned int bendBits_
Definition: DigitalStub.h:105
alignCSCRings.r
r
Definition: alignCSCRings.py:93
tmtt::DigitalStub::bend_orig_
double bend_orig_
Definition: DigitalStub.h:145
tmtt::DigitalStub::z_orig_
double z_orig_
Definition: DigitalStub.h:142
tmtt::DigitalStub::mbin_min_
int mbin_min_
Definition: DigitalStub.h:152
tmtt::Settings::phiSectorBits
unsigned int phiSectorBits() const
Definition: Settings.h:82
tmtt::Settings::houghNbinsPt
unsigned int houghNbinsPt() const
Definition: Settings.h:137
std
Definition: JetResolutionObject.h:76
tmtt::DigitalStub::bend_orig
double bend_orig() const
Definition: DigitalStub.h:45
tmtt::DigitalStub::mbin_max_orig
unsigned int mbin_max_orig() const
Definition: DigitalStub.h:44
tmtt::DigitalStub::undigitize
void undigitize(unsigned int iPhiSec)
Definition: DigitalStub.cc:191
tmtt::DigitalStub::rtRange_
double rtRange_
Definition: DigitalStub.h:100
tmtt::DigitalStub::nbinsPt_
unsigned int nbinsPt_
Definition: DigitalStub.h:129
tmtt::DigitalStub::phiS_orig_
double phiS_orig_
Definition: DigitalStub.h:140
Settings.h
Exception
Definition: hltDiff.cc:246
tmtt::DigitalStub::rtMult_
double rtMult_
Definition: DigitalStub.h:110
Exception.h
tmtt::DigitalStub::phiSectorBits_
unsigned int phiSectorBits_
Definition: DigitalStub.h:96
tmtt::Settings::rtBits
unsigned int rtBits() const
Definition: Settings.h:85
tmtt::DigitalStub::zRange_
double zRange_
Definition: DigitalStub.h:102
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
tmtt::DigitalStub::changePhiSec
bool changePhiSec(unsigned int iPhiSec)
Definition: DigitalStub.cc:97
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
tmtt::DigitalStub::phiNBits_
unsigned int phiNBits_
Definition: DigitalStub.h:103
tmtt::DigitalStub::z_
double z_
Definition: DigitalStub.h:168
tmtt::DigitalStub::chosenRofPhi_
double chosenRofPhi_
Definition: DigitalStub.h:127
tmtt::DigitalStub::phiNonantCentre_
double phiNonantCentre_
Definition: DigitalStub.h:125
tmtt
=== This is the base class for the linearised chi-squared track fit algorithms.
Definition: ChiSquaredFit4.h:6
tmtt::DigitalStub::rt_SF_TF_
double rt_SF_TF_
Definition: DigitalStub.h:167
deltaPhi.h
tmtt::DigitalStub::phiNonantWidth_
double phiNonantWidth_
Definition: DigitalStub.h:120
tmtt::DigitalStub::min_array_mbin_
int min_array_mbin_
Definition: DigitalStub.h:131
tmtt::Settings::phiNRange
double phiNRange() const
Definition: Settings.h:91