CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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_);
190  iDigi_chisquaredRz_ = floor(chisquaredRz_orig_ * chisquaredMult_);
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.
200  iDigi_oneOver2r_bcon_ = floor(oneOver2r_bcon_orig_ * oneOver2rMult_);
201  iDigi_phi0rel_bcon_ = floor(phi0rel_bcon_orig_ * phi0Mult_);
202  iDigi_chisquaredRphi_bcon_ = floor(chisquaredRphi_bcon_orig_ * chisquaredMult_);
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
unsigned int kf_tanlambdaBits() const
Definition: Settings.h:373
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
unsigned int phi0Bits_
Definition: DigitalTrack.h:132
unsigned int slr_tanlambdaBits() const
Definition: Settings.h:359
double slr_phi0Range() const
Definition: Settings.h:356
float qOverPt() const
Definition: TP.h:50
double kf_z0Range() const
Definition: Settings.h:372
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::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
unsigned int tanLambdaBits_
Definition: DigitalTrack.h:136
double kf_oneOver2rRange() const
Definition: Settings.h:366
float chisquaredRphi_bcon_orig_
Definition: DigitalTrack.h:182
unsigned int index() const
Definition: TP.h:39
double kf_phi0Range() const
Definition: Settings.h:370
unsigned int z0Bits_
Definition: DigitalTrack.h:134
unsigned int iPhiSec_
Definition: DigitalTrack.h:155
float tanLambda() const
Definition: TP.h:56
unsigned int iDigi_chisquaredRphi_bcon_
Definition: DigitalTrack.h:196
double kf_chisquaredRange() const
Definition: Settings.h:376
double slr_tanlambdaRange() const
Definition: Settings.h:360
float eta() const
Definition: TP.h:54
unsigned int slr_z0Bits() const
Definition: Settings.h:357
float phi0_bcon() const
unsigned int kf_phi0Bits() const
Definition: Settings.h:369
U second(std::pair< T, U > const &p)
Definition: TP.h:23
unsigned int oneOver2rBits_
Definition: DigitalTrack.h:128
unsigned int slr_oneOver2rBits() const
Definition: Settings.h:351
double slr_chisquaredRange() const
Definition: Settings.h:362
unsigned int numPhiNonants_
Definition: DigitalTrack.h:118
unsigned int kf_chisquaredBits() const
Definition: Settings.h:375
unsigned int iDigi_chisquaredRphi_
Definition: DigitalTrack.h:191
float phi0() const
Definition: TP.h:57
unsigned int kf_z0Bits() const
Definition: Settings.h:371
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float phi0() const override
unsigned int numPhiSectors_
Definition: DigitalTrack.h:117
double slr_oneOver2rRange() const
Definition: Settings.h:352
int pdgId() const
Definition: TP.h:41
double kf_tanlambdaRange() const
Definition: Settings.h:374
unsigned int d0Bits_
Definition: DigitalTrack.h:130
unsigned int chisquaredBits_
Definition: DigitalTrack.h:138
bool useForAlgEff() const
Definition: TP.h:89
unsigned int nHelixParams_
Definition: DigitalTrack.h:151
#define M_PI
float pt() const
Definition: TP.h:48
std::string fitterName_
Definition: DigitalTrack.h:150
void checkAccuracy() const
unsigned int slr_d0Bits() const
Definition: Settings.h:353
static constexpr float d0
const TP * matchedTP() const override
double kf_d0Range() const
Definition: Settings.h:368
void checkInRange() const
unsigned int kf_oneOver2rBits() const
Definition: Settings.h:365
const Settings * settings_
Definition: DigitalTrack.h:114
unsigned int kf_d0Bits() const
Definition: Settings.h:367
float d0() const
Definition: TP.h:63
bool other_skipTrackDigi() const
Definition: Settings.h:379
unsigned int slr_chisquaredBits() const
Definition: Settings.h:361
double slr_z0Range() const
Definition: Settings.h:358
void loadDigiCfg(const std::string &fitterName)
Definition: DigitalTrack.cc:99
bool kf_skipTrackDigi() const
Definition: Settings.h:364
unsigned int slr_phi0Bits() const
Definition: Settings.h:355
double slr_d0Range() const
Definition: Settings.h:354
float z0() const
Definition: TP.h:64
bool slr_skipTrackDigi() const
Definition: Settings.h:350
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
unsigned int iDigi_chisquaredRz_
Definition: DigitalTrack.h:192
bool useForEff() const
Definition: TP.h:87