CMS 3D CMS Logo

DigitalTrack.cc
Go to the documentation of this file.
4 
7 
8 using namespace std;
9 
10 namespace tmtt {
11 
12  //=== Note configuration parameters.
13 
14  DigitalTrack::DigitalTrack(const Settings* settings, const string& fitterName, const L1fittedTrack* fitTrk)
15  :
16 
17  // Digitization configuration parameters
18  settings_(settings),
19 
20  // Number of phi sectors and phi nonants.
21  numPhiSectors_(settings->numPhiSectors()),
22  numPhiNonants_(settings->numPhiNonants()),
23  // Phi sector and phi nonant width (radians)
24  phiSectorWidth_(2. * M_PI / float(numPhiSectors_)),
25  phiNonantWidth_(2. * M_PI / float(numPhiNonants_)),
26  // Radius from beamline with respect to which stub r coord. is measured.
27  chosenRofPhi_(settings->chosenRofPhi()),
28 
29  // Number of q/Pt bins in Hough transform array.
30  nbinsPt_((int)settings->houghNbinsPt()),
31  invPtToDPhi_(settings->invPtToDphi()),
32 
33  // Info about fitted track
34  fitterName_(fitterName),
35  nHelixParams_(fitTrk->nHelixParam()),
36 
37  nlayers_(fitTrk->numLayers()),
38  iPhiSec_(fitTrk->iPhiSec()),
39  iEtaReg_(fitTrk->iEtaReg()),
40  mBin_(int(fitTrk->cellLocationHT().first) - floor(settings_->houghNbinsPt() / 2)),
41  cBin_(int(fitTrk->cellLocationHT().second) - floor(settings_->houghNbinsPhi() / 2)),
42  mBinhelix_(int(fitTrk->cellLocationFit().first) - floor(settings_->houghNbinsPt() / 2)),
43  cBinhelix_(int(fitTrk->cellLocationFit().second) - floor(settings_->houghNbinsPhi() / 2)),
44  hitPattern_(fitTrk->hitPattern()),
45  consistent_(fitTrk->consistentHTcell()),
46  consistentSect_(fitTrk->consistentSector()),
47  accepted_(fitTrk->accepted()),
48 
49  qOverPt_orig_(fitTrk->qOverPt()),
50  oneOver2r_orig_(fitTrk->qOverPt() * invPtToDPhi_),
51  d0_orig_(fitTrk->d0()),
52  phi0_orig_(fitTrk->phi0()),
53  tanLambda_orig_(fitTrk->tanLambda()),
54  z0_orig_(fitTrk->z0()),
55  chisquaredRphi_orig_(fitTrk->chi2rphi()),
56  chisquaredRz_orig_(fitTrk->chi2rz()),
57 
58  // Same again with beam-spot constraint.
59  qOverPt_bcon_orig_(fitTrk->qOverPt_bcon()),
60  oneOver2r_bcon_orig_(fitTrk->qOverPt_bcon() * invPtToDPhi_),
61  phi0_bcon_orig_(fitTrk->phi0_bcon()),
62  chisquaredRphi_bcon_orig_(fitTrk->chi2rphi_bcon()) {
63  // Get digitisation parameters for this particular track fitter.
64  this->loadDigiCfg(fitterName);
65 
66  // Complete storage of info about fitted track & truth particle.
67  double phiCentreSec0 = -M_PI / float(numPhiNonants_) + M_PI / float(numPhiSectors_);
68  phiSectorCentre_ = phiSectorWidth_ * float(iPhiSec_) + phiCentreSec0;
71 
72  // FIX: Remove this BODGE once BCHI increased to 11 in KFstate.h
77 
78  // Associated truth, if any.
79  const TP* tp = fitTrk->matchedTP();
80  bool tpOK = (tp != nullptr);
81  tp_tanLambda_ = tpOK ? tp->tanLambda() : 0;
82  tp_qoverpt_ = tpOK ? tp->qOverPt() : 0;
83  tp_pt_ = tpOK ? tp->pt() : 0;
84  tp_d0_ = tpOK ? tp->d0() : 0;
85  tp_eta_ = tpOK ? tp->eta() : 0;
86  tp_phi0_ = tpOK ? tp->phi0() : 0;
87  tp_z0_ = tpOK ? tp->z0() : 0;
88  tp_index_ = tpOK ? tp->index() : -1;
89  tp_useForAlgEff_ = tpOK ? tp->useForAlgEff() : false;
90  tp_useForEff_ = tpOK ? tp->useForEff() : false;
91  tp_pdgId_ = tpOK ? tp->pdgId() : 0;
92 
93  // Digitize track.
94  this->makeDigitalTrack();
95  }
96 
97  //=== Load digitisation configuration parameters for the specific track fitter being used here.
98 
99  void DigitalTrack::loadDigiCfg(const string& fitterName) {
100  if (fitterName == "SimpleLR4") {
101  // SimpleLR4 track fitter
115  } else {
116  // KF track fitter
117  // Also used for all other fitters, though unlikely to be correct them them ...
118  if (fitterName == "KF4ParamsComb" || fitterName == "KF5ParamsComb" || fitterName == "KF4ParamsCombHLS") {
120  } else {
121  skipTrackDigi_ = settings_->other_skipTrackDigi(); // Allows to skip digitisation for other fitters
122  }
135  }
136 
137  // Calculate multipliers to digitize the floating point numbers.
139  d0Mult_ = pow(2., d0Bits_) / d0Range_;
141  z0Mult_ = pow(2., z0Bits_) / z0Range_;
144  }
145 
146  //=== Digitize track
147 
149  if (skipTrackDigi_) {
150  // Optionally skip track digitisaton if done internally inside track fitting code, so
151  // retain original helix params.
152  iDigi_oneOver2r_ = 0;
153  iDigi_d0_ = 0;
154  iDigi_phi0rel_ = 0;
155  iDigi_tanLambda_ = 0;
156  iDigi_z0_ = 0;
159 
163 
166  d0_ = d0_orig_;
168  phi0_ = phi0_orig_;
170  z0_ = z0_orig_;
173 
174  // Same again with beam-spot constraint.
180 
181  } else {
182  //--- Digitize variables
183 
185  iDigi_d0_ = floor(d0_orig_ * d0Mult_);
188  iDigi_z0_ = floor(z0_orig_ * z0Mult_);
191 
192  // If fitted declared track invalid, it will have set its chi2 to very large number.
193  // So truncate it at maximum allowed by digitisation range.
194  if (!accepted_) {
197  }
198 
199  // Same again with beam-spot constraint.
203  if (!accepted_)
205 
206  //--- Determine floating point track params from digitized numbers (so with degraded resolution).
207 
210  if (nHelixParams_ == 5) {
211  d0_ = (iDigi_d0_ + 0.5) / d0Mult_;
212  } else {
213  d0_ = 0.;
214  }
215  phi0rel_ = (iDigi_phi0rel_ + 0.5) / phi0Mult_;
218  z0_ = (iDigi_z0_ + 0.5) / z0Mult_;
221 
222  // Same again with beam-spot constraint.
223  if (nHelixParams_ == 5) {
229  } else {
233  phi0_bcon_ = phi0_;
235  }
236 
237  // Check that track coords. are within assumed digitization range.
238  this->checkInRange();
239 
240  // Check that digitization followed by undigitization doesn't change results too much.
241  this->checkAccuracy();
242  }
243  }
244 
245  //=== Check that stub coords. are within assumed digitization range.
246 
248  if (accepted_) { // Don't bother apply to tracks rejected by the fitter.
250  throw cms::Exception("BadConfig")
251  << "DigitalTrack: Track oneOver2r is out of assumed digitization range."
252  << " |oneOver2r| = " << std::abs(oneOver2r_orig_) << " > " << 0.5 * oneOver2rRange_
253  << "; Fitter=" << fitterName_ << "; track accepted = " << accepted_;
254  if (consistentSect_) { // don't bother if track will fail sector consistency cut.
255  if (std::abs(phi0rel_orig_) >= 0.5 * phi0Range_)
256  throw cms::Exception("BadConfig") << "DigitalTrack: Track phi0rel is out of assumed digitization range."
257  << " |phi0rel| = " << std::abs(phi0rel_orig_) << " > " << 0.5 * phi0Range_
258  << "; Fitter=" << fitterName_ << "; track accepted = " << accepted_;
259  }
260  if (std::abs(z0_orig_) >= 0.5 * z0Range_)
261  throw cms::Exception("BadConfig") << "DigitalTrack: Track z0 is out of assumed digitization range."
262  << " |z0| = " << std::abs(z0_orig_) << " > " << 0.5 * z0Range_
263  << "; Fitter=" << fitterName_ << "; track accepted = " << accepted_;
264  if (std::abs(d0_orig_) >= 0.5 * d0Range_)
265  throw cms::Exception("BadConfig") << "DigitalTrack: Track d0 is out of assumed digitization range."
266  << " |d0| = " << std::abs(d0_orig_) << " > " << 0.5 * d0Range_
267  << "; Fitter=" << fitterName_ << "; track accepted = " << accepted_;
269  throw cms::Exception("BadConfig")
270  << "DigitalTrack: Track tanLambda is out of assumed digitization range."
271  << " |tanLambda| = " << std::abs(tanLambda_orig_) << " > " << 0.5 * tanLambdaRange_
272  << "; Fitter=" << fitterName_ << "; track accepted = " << accepted_;
273  if (accepted_) { // Tracks declared invalid by fitter can have very large original chi2.
275  throw cms::Exception("BadConfig")
276  << "DigitalTrack: Track chisquaredRphi is out of assumed digitization range."
277  << " chisquaredRphi = " << chisquaredRphi_orig_ << " > " << chisquaredRange_ << " or < 0"
278  << "; Fitter=" << fitterName_ << "; track accepted = " << accepted_;
280  throw cms::Exception("BadConfig")
281  << "DigitalTrack: Track chisquaredRz is out of assumed digitization range."
282  << " chisquaredRz = " << chisquaredRz_orig_ << " > " << chisquaredRange_ << " or < 0"
283  << "; Fitter=" << fitterName_ << "; track accepted = " << accepted_;
284  }
285  }
286  }
287 
288  //=== Check that digitisation followed by undigitisation doesn't change significantly the stub coordinates.
289 
291  if (accepted_) { // Don't bother apply to tracks rejected by the fitter.
292  float TA = qOverPt_ - qOverPt_orig_;
293  float TB = reco::deltaPhi(phi0_, phi0_orig_);
294  float TC = z0_ - z0_orig_;
295  float TD = tanLambda_ - tanLambda_orig_;
296  float TE = d0_ - d0_orig_;
298  float TG = chisquaredRz_ - chisquaredRz_orig_;
299 
300  // Compare to small numbers, representing acceptable precision loss.
301  constexpr float smallTA = 0.01, smallTB = 0.001, smallTC = 0.05, smallTD = 0.002, smallTE = 0.05, smallTF = 0.5,
302  smallTG = 0.5;
303  if (std::abs(TA) > smallTA || std::abs(TB) > smallTB || std::abs(TC) > smallTC || std::abs(TD) > smallTD ||
304  std::abs(TE) > smallTE || std::abs(TF) > smallTF || std::abs(TG) > smallTG) {
305  throw cms::Exception("LogicError")
306  << "WARNING: DigitalTrack lost precision: " << fitterName_ << " accepted=" << accepted_ << " " << TA << " "
307  << TB << " " << TC << " " << TD << " " << TE << " " << TF << " " << TG;
308  }
309  }
310  }
311 
312 } // namespace tmtt
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
unsigned int phi0Bits_
Definition: DigitalTrack.h:132
double kf_tanlambdaRange() const
Definition: Settings.h:374
unsigned int slr_oneOver2rBits() const
Definition: Settings.h:351
double kf_phi0Range() const
Definition: Settings.h:370
unsigned int kf_d0Bits() const
Definition: Settings.h:367
double slr_phi0Range() const
Definition: Settings.h:356
void checkAccuracy() const
unsigned int kf_oneOver2rBits() const
Definition: Settings.h:365
unsigned int tanLambdaBits_
Definition: DigitalTrack.h:136
float chisquaredRphi_bcon_orig_
Definition: DigitalTrack.h:182
unsigned int z0Bits_
Definition: DigitalTrack.h:134
unsigned int iPhiSec_
Definition: DigitalTrack.h:155
double kf_z0Range() const
Definition: Settings.h:372
bool other_skipTrackDigi() const
Definition: Settings.h:379
unsigned int iDigi_chisquaredRphi_bcon_
Definition: DigitalTrack.h:196
unsigned int kf_phi0Bits() const
Definition: Settings.h:369
unsigned int kf_chisquaredBits() const
Definition: Settings.h:375
U second(std::pair< T, U > const &p)
Definition: TP.h:23
unsigned int oneOver2rBits_
Definition: DigitalTrack.h:128
double slr_z0Range() const
Definition: Settings.h:358
float phi0_bcon() const
void checkInRange() const
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
unsigned int numPhiNonants_
Definition: DigitalTrack.h:118
unsigned int iDigi_chisquaredRphi_
Definition: DigitalTrack.h:191
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float phi0() const override
unsigned int numPhiSectors_
Definition: DigitalTrack.h:117
unsigned int d0Bits_
Definition: DigitalTrack.h:130
unsigned int chisquaredBits_
Definition: DigitalTrack.h:138
unsigned int slr_chisquaredBits() const
Definition: Settings.h:361
unsigned int nHelixParams_
Definition: DigitalTrack.h:151
unsigned int slr_d0Bits() const
Definition: Settings.h:353
#define M_PI
double slr_oneOver2rRange() const
Definition: Settings.h:352
std::string fitterName_
Definition: DigitalTrack.h:150
static constexpr float d0
unsigned int slr_tanlambdaBits() const
Definition: Settings.h:359
const TP * matchedTP() const override
=== This is the base class for the linearised chi-squared track fit algorithms.
Definition: Array2D.h:16
double slr_d0Range() const
Definition: Settings.h:354
double slr_chisquaredRange() const
Definition: Settings.h:362
double slr_tanlambdaRange() const
Definition: Settings.h:360
double kf_oneOver2rRange() const
Definition: Settings.h:366
const Settings * settings_
Definition: DigitalTrack.h:114
bool slr_skipTrackDigi() const
Definition: Settings.h:350
unsigned int kf_tanlambdaBits() const
Definition: Settings.h:373
double kf_d0Range() const
Definition: Settings.h:368
double kf_chisquaredRange() const
Definition: Settings.h:376
unsigned int slr_phi0Bits() const
Definition: Settings.h:355
bool kf_skipTrackDigi() const
Definition: Settings.h:364
void loadDigiCfg(const std::string &fitterName)
Definition: DigitalTrack.cc:99
unsigned int kf_z0Bits() const
Definition: Settings.h:371
unsigned int slr_z0Bits() const
Definition: Settings.h:357
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
unsigned int iDigi_chisquaredRz_
Definition: DigitalTrack.h:192