CMS 3D CMS Logo

AlignmentTrackSelector.cc
Go to the documentation of this file.
2 
6 
8 
22 
23 #include <cmath>
24 
27 
28 // constructor ----------------------------------------------------------------
29 
31  : tTopoToken_(iC.esConsumes()),
32  applyBasicCuts_(cfg.getParameter<bool>("applyBasicCuts")),
33  applyNHighestPt_(cfg.getParameter<bool>("applyNHighestPt")),
34  applyMultiplicityFilter_(cfg.getParameter<bool>("applyMultiplicityFilter")),
35  seedOnlyFromAbove_(cfg.getParameter<int>("seedOnlyFrom")),
36  applyIsolation_(cfg.getParameter<bool>("applyIsolationCut")),
37  chargeCheck_(cfg.getParameter<bool>("applyChargeCheck")),
38  nHighestPt_(cfg.getParameter<int>("nHighestPt")),
39  minMultiplicity_(cfg.getParameter<int>("minMultiplicity")),
40  maxMultiplicity_(cfg.getParameter<int>("maxMultiplicity")),
41  multiplicityOnInput_(cfg.getParameter<bool>("multiplicityOnInput")),
42  ptMin_(cfg.getParameter<double>("ptMin")),
43  ptMax_(cfg.getParameter<double>("ptMax")),
44  pMin_(cfg.getParameter<double>("pMin")),
45  pMax_(cfg.getParameter<double>("pMax")),
46  etaMin_(cfg.getParameter<double>("etaMin")),
47  etaMax_(cfg.getParameter<double>("etaMax")),
48  phiMin_(cfg.getParameter<double>("phiMin")),
49  phiMax_(cfg.getParameter<double>("phiMax")),
50  nHitMin_(cfg.getParameter<double>("nHitMin")),
51  nHitMax_(cfg.getParameter<double>("nHitMax")),
52  chi2nMax_(cfg.getParameter<double>("chi2nMax")),
53  d0Min_(cfg.getParameter<double>("d0Min")),
54  d0Max_(cfg.getParameter<double>("d0Max")),
55  dzMin_(cfg.getParameter<double>("dzMin")),
56  dzMax_(cfg.getParameter<double>("dzMax")),
57  theCharge_(cfg.getParameter<int>("theCharge")),
58  minHitChargeStrip_(cfg.getParameter<double>("minHitChargeStrip")),
59  minHitIsolation_(cfg.getParameter<double>("minHitIsolation")),
60  countStereoHitAs2D_(cfg.getParameter<bool>("countStereoHitAs2D")),
61  nHitMin2D_(cfg.getParameter<unsigned int>("nHitMin2D")),
62  // Ugly to use the same getParameter n times, but this allows const cut variables...
63  minHitsinTIB_(cfg.getParameter<edm::ParameterSet>("minHitsPerSubDet").getParameter<int>("inTIB")),
64  minHitsinTOB_(cfg.getParameter<edm::ParameterSet>("minHitsPerSubDet").getParameter<int>("inTOB")),
65  minHitsinTID_(cfg.getParameter<edm::ParameterSet>("minHitsPerSubDet").getParameter<int>("inTID")),
66  minHitsinTEC_(cfg.getParameter<edm::ParameterSet>("minHitsPerSubDet").getParameter<int>("inTEC")),
67  minHitsinBPIX_(cfg.getParameter<edm::ParameterSet>("minHitsPerSubDet").getParameter<int>("inBPIX")),
68  minHitsinFPIX_(cfg.getParameter<edm::ParameterSet>("minHitsPerSubDet").getParameter<int>("inFPIX")),
69  minHitsinPIX_(cfg.getParameter<edm::ParameterSet>("minHitsPerSubDet").getParameter<int>("inPIXEL")),
70  minHitsinTIDplus_(cfg.getParameter<edm::ParameterSet>("minHitsPerSubDet").getParameter<int>("inTIDplus")),
71  minHitsinTIDminus_(cfg.getParameter<edm::ParameterSet>("minHitsPerSubDet").getParameter<int>("inTIDminus")),
72  minHitsinTECplus_(cfg.getParameter<edm::ParameterSet>("minHitsPerSubDet").getParameter<int>("inTECplus")),
73  minHitsinTECminus_(cfg.getParameter<edm::ParameterSet>("minHitsPerSubDet").getParameter<int>("inTECminus")),
74  minHitsinFPIXplus_(cfg.getParameter<edm::ParameterSet>("minHitsPerSubDet").getParameter<int>("inFPIXplus")),
75  minHitsinFPIXminus_(cfg.getParameter<edm::ParameterSet>("minHitsPerSubDet").getParameter<int>("inFPIXminus")),
76  minHitsinENDCAP_(cfg.getParameter<edm::ParameterSet>("minHitsPerSubDet").getParameter<int>("inENDCAP")),
77  minHitsinENDCAPplus_(cfg.getParameter<edm::ParameterSet>("minHitsPerSubDet").getParameter<int>("inENDCAPplus")),
78  minHitsinENDCAPminus_(cfg.getParameter<edm::ParameterSet>("minHitsPerSubDet").getParameter<int>("inENDCAPminus")),
79  maxHitDiffEndcaps_(cfg.getParameter<double>("maxHitDiffEndcaps")),
80  nLostHitMax_(cfg.getParameter<double>("nLostHitMax")),
81  RorZofFirstHitMin_(cfg.getParameter<std::vector<double> >("RorZofFirstHitMin")),
82  RorZofFirstHitMax_(cfg.getParameter<std::vector<double> >("RorZofFirstHitMax")),
83  RorZofLastHitMin_(cfg.getParameter<std::vector<double> >("RorZofLastHitMin")),
84  RorZofLastHitMax_(cfg.getParameter<std::vector<double> >("RorZofLastHitMax")),
85  clusterValueMapTag_(cfg.getParameter<edm::InputTag>("hitPrescaleMapTag")),
86  minPrescaledHits_(cfg.getParameter<int>("minPrescaledHits")),
87  applyPrescaledHitsFilter_(!clusterValueMapTag_.encode().empty() && minPrescaledHits_ > 0) {
88  if (applyIsolation_) {
89  rphirecHitsToken_ = iC.consumes<SiStripRecHit2DCollection>(cfg.getParameter<edm::InputTag>("rphirecHits"));
91  iC.consumes<SiStripMatchedRecHit2DCollection>(cfg.getParameter<edm::InputTag>("matchedrecHits"));
92  }
93 
96  }
97 
98  //convert track quality from string to enum
99  std::vector<std::string> trkQualityStrings(cfg.getParameter<std::vector<std::string> >("trackQualities"));
101  if (!trkQualityStrings.empty()) {
102  applyTrkQualityCheck_ = true;
103  for (unsigned int i = 0; i < trkQualityStrings.size(); ++i) {
104  (qualities += trkQualityStrings[i]) += ", ";
105  trkQualities_.push_back(reco::TrackBase::qualityByName(trkQualityStrings[i]));
106  }
107  } else
108  applyTrkQualityCheck_ = false;
109 
110  std::vector<std::string> trkIterStrings(cfg.getParameter<std::vector<std::string> >("iterativeTrackingSteps"));
111  if (!trkIterStrings.empty()) {
112  applyIterStepCheck_ = true;
113  std::string tracksteps;
114  for (unsigned int i = 0; i < trkIterStrings.size(); ++i) {
115  (tracksteps += trkIterStrings[i]) += ", ";
116  trkSteps_.push_back(reco::TrackBase::algoByName(trkIterStrings[i]));
117  }
118  } else
119  applyIterStepCheck_ = false;
120 
121  if (applyBasicCuts_) {
122  edm::LogInfo("AlignmentTrackSelector")
123  << "applying basic track cuts ..."
124  << "\nptmin,ptmax: " << ptMin_ << "," << ptMax_ << "\npmin,pmax: " << pMin_ << "," << pMax_
125  << "\netamin,etamax: " << etaMin_ << "," << etaMax_ << "\nphimin,phimax: " << phiMin_ << "," << phiMax_
126  << "\nnhitmin,nhitmax: " << nHitMin_ << "," << nHitMax_ << "\nnlosthitmax: " << nLostHitMax_
127  << "\nnhitmin2D: " << nHitMin2D_ << (countStereoHitAs2D_ ? "," : ", not")
128  << " counting hits on SiStrip stereo modules as 2D"
129  << "\nchi2nmax: " << chi2nMax_;
130 
131  if (applyIsolation_)
132  edm::LogInfo("AlignmentTrackSelector")
133  << "only retain tracks isolated at least by " << minHitIsolation_ << " cm from other rechits";
134 
135  if (chargeCheck_)
136  edm::LogInfo("AlignmentTrackSelector")
137  << "only retain hits with at least " << minHitChargeStrip_ << " ADC counts of total cluster charge";
138 
139  edm::LogInfo("AlignmentTrackSelector")
140  << "Minimum number of hits in TIB/TID/TOB/TEC/BPIX/FPIX/PIXEL = " << minHitsinTIB_ << "/" << minHitsinTID_
141  << "/" << minHitsinTOB_ << "/" << minHitsinTEC_ << "/" << minHitsinBPIX_ << "/" << minHitsinFPIX_ << "/"
142  << minHitsinPIX_;
143 
144  edm::LogInfo("AlignmentTrackSelector")
145  << "Minimum number of hits in TID+/TID-/TEC+/TEC-/FPIX+/FPIX- = " << minHitsinTIDplus_ << "/"
147  << "/" << minHitsinFPIXminus_;
148 
149  edm::LogInfo("AlignmentTrackSelector")
150  << "Minimum number of hits in EndCap (TID+TEC)/EndCap+/EndCap- = " << minHitsinENDCAP_ << "/"
152 
153  edm::LogInfo("AlignmentTrackSelector")
154  << "Max value of |nHitsinENDCAPplus - nHitsinENDCAPminus| = " << maxHitDiffEndcaps_;
155 
156  if (!trkQualityStrings.empty()) {
157  edm::LogInfo("AlignmentTrackSelector") << "Select tracks with these qualities: " << qualities;
158  }
159  }
160 
161  if (applyNHighestPt_)
162  edm::LogInfo("AlignmentTrackSelector") << "filter N tracks with highest Pt N=" << nHighestPt_;
163 
165  edm::LogInfo("AlignmentTrackSelector")
166  << "apply multiplicity filter N>= " << minMultiplicity_ << "and N<= " << maxMultiplicity_ << " on "
167  << (multiplicityOnInput_ ? "input" : "output");
168 
170  edm::LogInfo("AlignmentTrackSelector") << "apply cut on number of prescaled hits N>= " << minPrescaledHits_
171  << " (prescale info from " << clusterValueMapTag_ << ")";
172  }
173 
174  // Checking whether cuts on positions of first and last track hits are defined properly
175  if (RorZofFirstHitMin_.size() != 2) {
176  throw cms::Exception("BadConfig") << "@SUB=AlignmentTrackSelector::AlignmentTrackSelector"
177  << "Wrong configuration of 'RorZofFirstHitMin'."
178  << " Must have exactly 2 values instead of configured "
179  << RorZofFirstHitMin_.size() << ")";
180  } else {
181  RorZofFirstHitMin_.at(0) = std::fabs(RorZofFirstHitMin_.at(0));
182  RorZofFirstHitMin_.at(1) = std::fabs(RorZofFirstHitMin_.at(1));
183  }
184  if (RorZofFirstHitMax_.size() != 2) {
185  throw cms::Exception("BadConfig") << "@SUB=AlignmentTrackSelector::AlignmentTrackSelector"
186  << "Wrong configuration of 'RorZofFirstHitMax'."
187  << " Must have exactly 2 values instead of configured "
188  << RorZofFirstHitMax_.size() << ")";
189  } else {
190  RorZofFirstHitMax_.at(0) = std::fabs(RorZofFirstHitMax_.at(0));
191  RorZofFirstHitMax_.at(1) = std::fabs(RorZofFirstHitMax_.at(1));
192  }
193  if (RorZofLastHitMin_.size() != 2) {
194  throw cms::Exception("BadConfig") << "@SUB=AlignmentTrackSelector::AlignmentTrackSelector"
195  << "Wrong configuration of 'RorZofLastHitMin'."
196  << " Must have exactly 2 values instead of configured "
197  << RorZofLastHitMin_.size() << ")";
198  } else {
199  RorZofLastHitMin_.at(0) = std::fabs(RorZofLastHitMin_.at(0));
200  RorZofLastHitMin_.at(1) = std::fabs(RorZofLastHitMin_.at(1));
201  }
202  if (RorZofLastHitMax_.size() != 2) {
203  throw cms::Exception("BadConfig") << "@SUB=AlignmentTrackSelector::AlignmentTrackSelector"
204  << "Wrong configuration of 'RorZofLastHitMax'."
205  << " Must have exactly 2 values instead of configured "
206  << RorZofLastHitMax_.size() << ")";
207  } else {
208  RorZofLastHitMax_.at(0) = std::fabs(RorZofLastHitMax_.at(0));
209  RorZofLastHitMax_.at(1) = std::fabs(RorZofLastHitMax_.at(1));
210  }
211  // If first hit set to be at larger distance then the last hit
212  if (RorZofFirstHitMin_.at(0) > RorZofLastHitMax_.at(0) && RorZofFirstHitMin_.at(1) > RorZofLastHitMax_.at(1)) {
213  throw cms::Exception("BadConfig") << "@SUB=AlignmentTrackSelector::AlignmentTrackSelector"
214  << "Position of the first hit is set to larger distance than the last hit:."
215  << " First hit(min): [" << RorZofFirstHitMin_.at(0) << ", "
216  << RorZofFirstHitMin_.at(1) << "]; Last hit(max): [" << RorZofLastHitMax_.at(0)
217  << ", " << RorZofLastHitMax_.at(1) << "];";
218  }
219 }
220 
221 // destructor -----------------------------------------------------------------
222 
224 
225 // do selection ---------------------------------------------------------------
226 
228  const edm::Event& evt,
229  const edm::EventSetup& eSetup) const {
231  (tracks.size() < static_cast<unsigned int>(minMultiplicity_) ||
232  tracks.size() > static_cast<unsigned int>(maxMultiplicity_))) {
233  return Tracks(); // empty collection
234  }
235 
236  Tracks result = tracks;
237  // apply basic track cuts (if selected)
238  if (applyBasicCuts_)
239  result = this->basicCuts(result, evt, eSetup);
240 
241  // filter N tracks with highest Pt (if selected)
242  if (applyNHighestPt_)
243  result = this->theNHighestPtTracks(result);
244 
245  // apply minimum multiplicity requirement (if selected)
247  if (result.size() < static_cast<unsigned int>(minMultiplicity_) ||
248  result.size() > static_cast<unsigned int>(maxMultiplicity_)) {
249  result.clear();
250  }
251  }
252 
254  result = this->checkPrescaledHits(result, evt);
255  }
256 
257  return result;
258 }
259 
263 }
264 
265 // make basic cuts ------------------------------------------------------------
266 
268  const edm::Event& evt,
269  const edm::EventSetup& eSetup) const {
270  Tracks result;
271 
272  for (Tracks::const_iterator it = tracks.begin(); it != tracks.end(); ++it) {
273  const reco::Track* trackp = *it;
274  float pt = trackp->pt();
275  float p = trackp->p();
276  float eta = trackp->eta();
277  float phi = trackp->phi();
278  int nhit = trackp->numberOfValidHits();
279  int nlosthit = trackp->numberOfLostHits();
280  float chi2n = trackp->normalizedChi2();
281 
282  int q = trackp->charge();
283  bool isChargeOk = false;
284  if (theCharge_ == -1 && q < 0)
285  isChargeOk = true;
286  else if (theCharge_ == 1 && q > 0)
287  isChargeOk = true;
288  else if (theCharge_ == 0)
289  isChargeOk = true;
290 
291  float d0 = trackp->d0();
292  float dz = trackp->dz();
293 
294  // edm::LogDebug("AlignmentTrackSelector") << " pt,eta,phi,nhit: "
295  // <<pt<<","<<eta<<","<<phi<<","<<nhit;
296 
297  if (pt > ptMin_ && pt < ptMax_ && p > pMin_ && p < pMax_ && eta > etaMin_ && eta < etaMax_ && phi > phiMin_ &&
298  phi < phiMax_ && nhit >= nHitMin_ && nhit <= nHitMax_ && nlosthit <= nLostHitMax_ && chi2n < chi2nMax_ &&
299  isChargeOk && d0 >= d0Min_ && d0 <= d0Max_ && dz >= dzMin_ && dz <= dzMax_) {
300  bool trkQualityOk = false;
302  trkQualityOk = true; // nothing required
303  else
304  trkQualityOk = this->isOkTrkQuality(trackp);
305 
306  bool hitsCheckOk = this->detailedHitsCheck(trackp, evt, eSetup);
307 
308  if (trkQualityOk && hitsCheckOk)
309  result.push_back(trackp);
310  }
311  }
312 
313  return result;
314 }
315 
316 //-----------------------------------------------------------------------------
317 
319  const edm::Event& evt,
320  const edm::EventSetup& eSetup) const {
321  //Retrieve tracker topology from geometry
322  const TrackerTopology* const tTopo = &eSetup.getData(tTopoToken_);
323 
324  // checking hit requirements beyond simple number of valid hits
325 
330  (seedOnlyFromAbove_ == 1 || seedOnlyFromAbove_ == 2) || !RorZofFirstHitMin_.empty() ||
331  !RorZofFirstHitMax_.empty() || !RorZofLastHitMin_.empty() || !RorZofLastHitMax_.empty()) {
332  // any detailed hit cut is active, so have to check
333 
334  int nhitinTIB = 0, nhitinTOB = 0, nhitinTID = 0;
335  int nhitinTEC = 0, nhitinBPIX = 0, nhitinFPIX = 0, nhitinPIXEL = 0;
336  int nhitinENDCAP = 0, nhitinENDCAPplus = 0, nhitinENDCAPminus = 0;
337  int nhitinTIDplus = 0, nhitinTIDminus = 0;
338  int nhitinFPIXplus = 0, nhitinFPIXminus = 0;
339  int nhitinTECplus = 0, nhitinTECminus = 0;
340  unsigned int nHit2D = 0;
341  unsigned int thishit = 0;
342 
343  for (auto const& hit : trackp->recHits()) {
344  thishit++;
345  const DetId detId(hit->geographicalId());
346  const int subdetId = detId.subdetId();
347 
348  // *** thishit == 1 means last hit in CTF ***
349  // (FIXME: assumption might change or not be valid for all tracking algorthms)
350  // ==> for cosmics
351  // seedOnlyFrom = 1 is TIB-TOB-TEC tracks only
352  // seedOnlyFrom = 2 is TOB-TEC tracks only
353  if (seedOnlyFromAbove_ == 1 && thishit == 1 &&
354  (subdetId == int(SiStripDetId::TOB) || subdetId == int(SiStripDetId::TEC))) {
355  return false;
356  }
357  if (seedOnlyFromAbove_ == 2 && thishit == 1 && subdetId == int(SiStripDetId::TIB)) {
358  return false;
359  }
360 
361  if (!hit->isValid())
362  continue; // only real hits count as in trackp->numberOfValidHits()
363  if (detId.det() != DetId::Tracker) {
364  edm::LogError("DetectorMismatch")
365  << "@SUB=AlignmentTrackSelector::detailedHitsCheck"
366  << "DetId.det() != DetId::Tracker (=" << DetId::Tracker << "), but " << detId.det() << ".";
367  }
368  if (chargeCheck_ && !(this->isOkCharge(hit)))
369  return false;
370  if (applyIsolation_ && (!this->isIsolated(hit, evt)))
371  return false;
372  if (SiStripDetId::TIB == subdetId)
373  ++nhitinTIB;
374  else if (SiStripDetId::TOB == subdetId)
375  ++nhitinTOB;
376  else if (SiStripDetId::TID == subdetId) {
377  ++nhitinTID;
378  ++nhitinENDCAP;
379 
380  if (tTopo->tidIsZMinusSide(detId)) {
381  ++nhitinTIDminus;
382  ++nhitinENDCAPminus;
383  } else if (tTopo->tidIsZPlusSide(detId)) {
384  ++nhitinTIDplus;
385  ++nhitinENDCAPplus;
386  }
387  } else if (SiStripDetId::TEC == subdetId) {
388  ++nhitinTEC;
389  ++nhitinENDCAP;
390 
391  if (tTopo->tecIsZMinusSide(detId)) {
392  ++nhitinTECminus;
393  ++nhitinENDCAPminus;
394  } else if (tTopo->tecIsZPlusSide(detId)) {
395  ++nhitinTECplus;
396  ++nhitinENDCAPplus;
397  }
398  } else if (kBPIX == subdetId) {
399  ++nhitinBPIX;
400  ++nhitinPIXEL;
401  } else if (kFPIX == subdetId) {
402  ++nhitinFPIX;
403  ++nhitinPIXEL;
404 
405  if (tTopo->pxfSide(detId) == 1)
406  ++nhitinFPIXminus;
407  else if (tTopo->pxfSide(detId) == 2)
408  ++nhitinFPIXplus;
409  }
410  // Do not call isHit2D(..) if already enough 2D hits for performance reason:
411  if (nHit2D < nHitMin2D_ && this->isHit2D(*hit))
412  ++nHit2D;
413  } // end loop on hits
414 
415  // Checking whether the track satisfies requirement of the first and last hit positions
416  bool passedLastHitPositionR = true;
417  bool passedLastHitPositionZ = true;
418  bool passedFirstHitPositionR = true;
419  bool passedFirstHitPositionZ = true;
420 
421  if (RorZofFirstHitMin_.at(0) != 0.0 || RorZofFirstHitMin_.at(1) != 0.0 || RorZofFirstHitMax_.at(0) != 999.0 ||
422  RorZofFirstHitMax_.at(1) != 999.0) {
423  const reco::TrackBase::Point& firstPoint(trackp->innerPosition());
424 
425  if ((std::fabs(firstPoint.R()) < RorZofFirstHitMin_.at(0)))
426  passedFirstHitPositionR = false;
427  if ((std::fabs(firstPoint.R()) > RorZofFirstHitMax_.at(0)))
428  passedFirstHitPositionR = false;
429  if ((std::fabs(firstPoint.Z()) < RorZofFirstHitMin_.at(1)))
430  passedFirstHitPositionZ = false;
431  if ((std::fabs(firstPoint.Z()) > RorZofFirstHitMax_.at(1)))
432  passedFirstHitPositionZ = false;
433  }
434 
435  if (RorZofLastHitMin_.at(0) != 0.0 || RorZofLastHitMin_.at(1) != 0.0 || RorZofLastHitMax_.at(0) != 999.0 ||
436  RorZofLastHitMax_.at(1) != 999.0) {
437  const reco::TrackBase::Point& lastPoint(trackp->outerPosition());
438 
439  if ((std::fabs(lastPoint.R()) < RorZofLastHitMin_.at(0)))
440  passedLastHitPositionR = false;
441  if ((std::fabs(lastPoint.R()) > RorZofLastHitMax_.at(0)))
442  passedLastHitPositionR = false;
443  if ((std::fabs(lastPoint.Z()) < RorZofLastHitMin_.at(1)))
444  passedLastHitPositionZ = false;
445  if ((std::fabs(lastPoint.Z()) > RorZofLastHitMax_.at(1)))
446  passedLastHitPositionZ = false;
447  }
448 
449  bool passedFirstHitPosition = passedFirstHitPositionR || passedFirstHitPositionZ;
450  bool passedLastHitPosition = passedLastHitPositionR || passedLastHitPositionZ;
451 
452  return (nhitinTIB >= minHitsinTIB_ && nhitinTOB >= minHitsinTOB_ && nhitinTID >= minHitsinTID_ &&
453  nhitinTEC >= minHitsinTEC_ && nhitinENDCAP >= minHitsinENDCAP_ &&
454  nhitinENDCAPplus >= minHitsinENDCAPplus_ && nhitinENDCAPminus >= minHitsinENDCAPminus_ &&
455  std::abs(nhitinENDCAPplus - nhitinENDCAPminus) <= maxHitDiffEndcaps_ &&
456  nhitinTIDplus >= minHitsinTIDplus_ && nhitinTIDminus >= minHitsinTIDminus_ &&
457  nhitinFPIXplus >= minHitsinFPIXplus_ && nhitinFPIXminus >= minHitsinFPIXminus_ &&
458  nhitinTECplus >= minHitsinTECplus_ && nhitinTECminus >= minHitsinTECminus_ &&
459  nhitinBPIX >= minHitsinBPIX_ && nhitinFPIX >= minHitsinFPIX_ && nhitinPIXEL >= minHitsinPIX_ &&
460  nHit2D >= nHitMin2D_ && passedFirstHitPosition && passedLastHitPosition);
461  } else { // no cuts set, so we are just fine and can avoid loop on hits
462  return true;
463  }
464 }
465 
466 //-----------------------------------------------------------------------------
467 
469  // we count SiStrip stereo modules as 2D if selected via countStereoHitAs2D_
470  // (since they provide theta information)
471  if (!hit.isValid() || (hit.dimension() < 2 && !countStereoHitAs2D_ && !dynamic_cast<const SiStripRecHit1D*>(&hit))) {
472  return false; // real RecHit1D - but SiStripRecHit1D depends on countStereoHitAs2D_
473  } else {
474  const DetId detId(hit.geographicalId());
475  if (detId.det() == DetId::Tracker) {
476  if (detId.subdetId() == kBPIX || detId.subdetId() == kFPIX) {
477  return true; // pixel is always 2D
478  } else { // should be SiStrip now
479  const SiStripDetId stripId(detId);
480  if (stripId.stereo())
481  return countStereoHitAs2D_; // stereo modules
482  else if (dynamic_cast<const SiStripRecHit1D*>(&hit) || dynamic_cast<const SiStripRecHit2D*>(&hit))
483  return false; // rphi modules hit
484  //the following two are not used any more since ages...
485  else if (dynamic_cast<const SiStripMatchedRecHit2D*>(&hit))
486  return true; // matched is 2D
487  else if (dynamic_cast<const ProjectedSiStripRecHit2D*>(&hit)) {
488  const ProjectedSiStripRecHit2D* pH = static_cast<const ProjectedSiStripRecHit2D*>(&hit);
489  return (countStereoHitAs2D_ && this->isHit2D(pH->originalHit())); // depends on original...
490  } else {
491  edm::LogError("UnknownType") << "@SUB=AlignmentTrackSelector::isHit2D"
492  << "Tracker hit not in pixel, neither SiStripRecHit[12]D nor "
493  << "SiStripMatchedRecHit2D nor ProjectedSiStripRecHit2D.";
494  return false;
495  }
496  }
497  } else { // not tracker??
498  edm::LogWarning("DetectorMismatch") << "@SUB=AlignmentTrackSelector::isHit2D"
499  << "Hit not in tracker with 'official' dimension >=2.";
500  return true; // dimension() >= 2 so accept that...
501  }
502  }
503  // never reached...
504 }
505 
506 //-----------------------------------------------------------------------------
507 
509  if (!hit || !hit->isValid())
510  return true;
511 
512  // check det and subdet
513  const DetId id(hit->geographicalId());
514  if (id.det() != DetId::Tracker) {
515  edm::LogWarning("DetectorMismatch") << "@SUB=isOkCharge"
516  << "Hit not in tracker!";
517  return true;
518  }
519  if (id.subdetId() == kFPIX || id.subdetId() == kBPIX) {
520  return true; // might add some requirement...
521  }
522 
523  // We are in SiStrip now, so test normal hit:
524  const std::type_info& type = typeid(*hit);
525 
526  if (type == typeid(SiStripRecHit2D)) {
527  const SiStripRecHit2D* stripHit2D = dynamic_cast<const SiStripRecHit2D*>(hit);
528  if (stripHit2D) {
529  return this->isOkChargeStripHit(*stripHit2D);
530  }
531  } else if (type == typeid(SiStripRecHit1D)) {
532  const SiStripRecHit1D* stripHit1D = dynamic_cast<const SiStripRecHit1D*>(hit);
533  if (stripHit1D) {
534  return this->isOkChargeStripHit(*stripHit1D);
535  }
536  }
537 
538  else if (type ==
539  typeid(SiStripMatchedRecHit2D)) { // or matched (should not occur anymore due to hit splitting since 20X)
540  const SiStripMatchedRecHit2D* matchedHit = dynamic_cast<const SiStripMatchedRecHit2D*>(hit);
541  if (matchedHit) {
542  return (this->isOkChargeStripHit(matchedHit->monoHit()) && this->isOkChargeStripHit(matchedHit->stereoHit()));
543  }
544  } else if (type == typeid(ProjectedSiStripRecHit2D)) {
545  // or projected (should not occur anymore due to hit splitting since 20X):
546  const ProjectedSiStripRecHit2D* projHit = dynamic_cast<const ProjectedSiStripRecHit2D*>(hit);
547  if (projHit) {
548  return this->isOkChargeStripHit(projHit->originalHit());
549  }
550  } else {
551  edm::LogError("AlignmentTrackSelector") << "@SUB=isOkCharge"
552  << "Unknown type of a valid tracker hit in Strips "
553  << " SubDet = " << id.subdetId();
554  return false;
555  }
556 
557  // and now? SiTrackerMultiRecHit? Not here I guess!
558  // Should we throw instead?
559  edm::LogError("AlignmentTrackSelector") << "@SUB=isOkCharge"
560  << "Unknown valid tracker hit not in pixel, subdet " << id.subdetId()
561  << ", SiTrackerMultiRecHit " << dynamic_cast<const SiTrackerMultiRecHit*>(hit)
562  << ", BaseTrackerRecHit " << dynamic_cast<const BaseTrackerRecHit*>(hit);
563 
564  return true;
565 }
566 
567 //-----------------------------------------------------------------------------
568 
570  double charge = 0.;
571 
572  SiStripRecHit2D::ClusterRef cluster(siStripRecHit2D.cluster());
573  const auto& amplitudes = cluster->amplitudes();
574 
575  for (size_t ia = 0; ia < amplitudes.size(); ++ia) {
576  charge += amplitudes[ia];
577  }
578 
579  return (charge >= minHitChargeStrip_);
580 }
581 
582 //-----------------------------------------------------------------------------
583 
585  double charge = 0.;
586 
587  SiStripRecHit1D::ClusterRef cluster(siStripRecHit1D.cluster());
588  const auto& amplitudes = cluster->amplitudes();
589 
590  for (size_t ia = 0; ia < amplitudes.size(); ++ia) {
591  charge += amplitudes[ia];
592  }
593 
594  return (charge >= minHitChargeStrip_);
595 }
596 
597 //-----------------------------------------------------------------------------
598 
600  // FIXME:
601  // adapt to changes after introduction of SiStripRecHit1D...
602  //
603  // edm::ESHandle<TrackerGeometry> tracker;
606  // es.get<TrackerDigiGeometryRecord>().get(tracker);
609 
612  const SiStripRecHit2DCollection::DataContainer& stripcollSt = rphirecHits->data();
614 
615  DetId idet = hit->geographicalId();
616 
617  // FIXME: instead of looping the full hit collection, we should explore the features of
618  // SiStripRecHit2DCollection::rangeRphi = rphirecHits.get(idet) and loop
619  // only from rangeRphi.first until rangeRphi.second
620  for (istripSt = stripcollSt.begin(); istripSt != stripcollSt.end(); ++istripSt) {
621  const SiStripRecHit2D* aHit = &*(istripSt);
622  DetId mydet1 = aHit->geographicalId();
623  if (idet.rawId() != mydet1.rawId())
624  continue;
625  float theDistance = (hit->localPosition() - aHit->localPosition()).mag();
626  // std::cout << "theDistance1 = " << theDistance << "\n";
627  if (theDistance > 0.001 && theDistance < minHitIsolation_)
628  return false;
629  }
630 
631  // FIXME: see above
632  for (istripStm = stripcollStm.begin(); istripStm != stripcollStm.end(); ++istripStm) {
633  const SiStripMatchedRecHit2D* aHit = &*(istripStm);
634  DetId mydet2 = aHit->geographicalId();
635  if (idet.rawId() != mydet2.rawId())
636  continue;
637  float theDistance = (hit->localPosition() - aHit->localPosition()).mag();
638  // std::cout << "theDistance1 = " << theDistance << "\n";
639  if (theDistance > 0.001 && theDistance < minHitIsolation_)
640  return false;
641  }
642  return true;
643 }
644 
645 //-----------------------------------------------------------------------------
646 
648  Tracks sortedTracks = tracks;
649  Tracks result;
650 
651  // sort in pt
652  std::sort(sortedTracks.begin(), sortedTracks.end(), ptComparator);
653 
654  // copy theTrackMult highest pt tracks to result vector
655  int n = 0;
656  for (Tracks::const_iterator it = sortedTracks.begin(); it != sortedTracks.end(); ++it) {
657  if (n < nHighestPt_) {
658  result.push_back(*it);
659  n++;
660  }
661  }
662 
663  return result;
664 }
665 
666 //---------
667 
669  const edm::Event& evt) const {
670  Tracks result;
671 
672  //take Cluster-Flag Assomap
675  const AliClusterValueMap& flagMap = *fMap;
676 
677  //for each track loop on hits and count the number of taken hits
678  for (auto const& trackp : tracks) {
679  int ntakenhits = 0;
680  // float pt=trackp->pt();
681 
682  for (auto const& hit : trackp->recHits()) {
683  if (!hit->isValid())
684  continue;
685  DetId detid = hit->geographicalId();
686  int subDet = detid.subdetId();
688 
689  bool isPixelHit = (subDet == kFPIX || subDet == kBPIX);
690 
691  if (!isPixelHit) {
692  const std::type_info& type = typeid(*hit);
693 
694  if (type == typeid(SiStripRecHit2D)) {
695  const SiStripRecHit2D* striphit = dynamic_cast<const SiStripRecHit2D*>(hit);
696  if (striphit != nullptr) {
697  SiStripRecHit2D::ClusterRef stripclust(striphit->cluster());
698  flag = flagMap[stripclust];
699  }
700  } else if (type == typeid(SiStripRecHit1D)) {
701  const SiStripRecHit1D* striphit = dynamic_cast<const SiStripRecHit1D*>(hit);
702  if (striphit != nullptr) {
703  SiStripRecHit1D::ClusterRef stripclust(striphit->cluster());
704  flag = flagMap[stripclust];
705  }
706  } else {
707  edm::LogError("AlignmentTrackSelector")
708  << "ERROR in <AlignmentTrackSelector::checkPrescaledHits>: Dynamic cast of Strip RecHit failed!"
709  << " Skipping this hit.";
710  continue;
711  }
712 
713  } //end if hit in Strips
714  else { // test explicitely BPIX/FPIX
715  const SiPixelRecHit* pixelhit = dynamic_cast<const SiPixelRecHit*>(hit);
716  if (pixelhit != nullptr) {
717  SiPixelRecHit::ClusterRef pixclust(pixelhit->cluster());
718  flag = flagMap[pixclust];
719  } else {
720  edm::LogError("AlignmentTrackSelector")
721  << "ERROR in <AlignmentTrackSelector::checkPrescaledHits>: Dynamic cast of Pixel RecHit failed! ";
722  }
723  } //end else hit is in Pixel
724 
725  if (flag.isTaken())
726  ntakenhits++;
727 
728  } //end loop on hits
729  if (ntakenhits >= minPrescaledHits_)
730  result.push_back(trackp);
731  } //end loop on tracks
732 
733  return result;
734 } //end checkPrescaledHits
735 
736 //-----------------------------------------------------------------
737 
739  bool qualityOk = false;
740  bool iterStepOk = false;
741 
742  //check iterative step
743  if (applyIterStepCheck_) {
744  for (unsigned int i = 0; i < trkSteps_.size(); ++i) {
745  if (track->algo() == (trkSteps_[i])) {
746  iterStepOk = true;
747  }
748  }
749  } else
750  iterStepOk = true;
751 
752  //check track quality
753  if (applyTrkQualityCheck_) {
754  for (unsigned int i = 0; i < trkQualities_.size(); ++i) {
755  if (track->quality(trkQualities_[i])) {
756  qualityOk = true;
757  }
758  }
759  } else
760  qualityOk = true;
761 
762  return qualityOk && iterStepOk;
763 } //end check on track quality
edm::EDGetTokenT< SiStripMatchedRecHit2DCollection > matchedrecHitsToken_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
bool isIsolated(const TrackingRecHit *therechit, const edm::Event &evt) const
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
bool tidIsZPlusSide(const DetId &id) const
std::vector< double > RorZofFirstHitMax_
SiStripRecHit2D stereoHit() const
Tracks checkPrescaledHits(const Tracks &tracks, const edm::Event &evt) const
unsigned short numberOfValidHits() const
number of valid hits found
Definition: TrackBase.h:798
const math::XYZPoint & outerPosition() const
position of the outermost hit
Definition: Track.h:62
std::vector< data_type > DataContainer
static constexpr auto TID
Definition: SiStripDetId.h:38
Tracks select(const Tracks &tracks, const edm::Event &evt, const edm::EventSetup &eSetup) const
select tracks
double p() const
momentum vector magnitude
Definition: TrackBase.h:631
Tracks theNHighestPtTracks(const Tracks &tracks) const
filter the n highest pt tracks
Tracks basicCuts(const Tracks &tracks, const edm::Event &evt, const edm::EventSetup &eSetup) const
apply basic cuts on pt,eta,phi,nhit
std::vector< const reco::Track * > Tracks
~AlignmentTrackSelector()
destructor
std::vector< reco::TrackBase::TrackAlgorithm > trkSteps_
std::vector< reco::TrackBase::TrackQuality > trkQualities_
bool tecIsZMinusSide(const DetId &id) const
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
const unsigned int nHitMin2D_
Log< level::Error, false > LogError
ClusterRef cluster() const
bool tidIsZMinusSide(const DetId &id) const
edm::EDGetTokenT< SiStripRecHit2DCollection > rphirecHitsToken_
const int kFPIX
double pt() const
track transverse momentum
Definition: TrackBase.h:637
auto recHits() const
Access to reconstructed hits on the track.
Definition: Track.h:85
int charge() const
track electric charge
Definition: TrackBase.h:596
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
Definition: TrackBase.h:622
uint32_t stereo() const
Definition: SiStripDetId.h:168
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:649
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
bool getData(T &iHolder) const
Definition: EventSetup.h:122
math::XYZPoint Point
point in the space
Definition: TrackBase.h:80
bool detailedHitsCheck(const reco::Track *track, const edm::Event &evt, const edm::EventSetup &eSetup) const
checking hit requirements beyond simple number of valid hits
std::vector< double > RorZofLastHitMin_
unsigned short numberOfLostHits() const
number of cases where track crossed a layer without getting a hit.
Definition: TrackBase.h:801
static constexpr auto TOB
Definition: SiStripDetId.h:39
edm::EDGetTokenT< AliClusterValueMap > clusterValueMapToken_
const char * qualities[3]
std::vector< double > RorZofFirstHitMin_
Log< level::Info, false > LogInfo
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:18
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:652
Definition: DetId.h:17
const double ptMin_
if true, cut min/maxMultiplicity on input instead of on final result
static constexpr float d0
unsigned int pxfSide(const DetId &id) const
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:126
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
auto const & tracks
cannot be loose
DetId geographicalId() const
double d0() const
dxy parameter in perigee convention (d0 = -dxy)
Definition: TrackBase.h:611
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
const edm::InputTag clusterValueMapTag_
bool isOkCharge(const TrackingRecHit *therechit) const
if valid, check for minimum charge (currently only in strip), if invalid give true ...
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
Definition: TrackBase.h:593
bool tecIsZPlusSide(const DetId &id) const
def encode(args, files)
static constexpr auto TIB
Definition: SiStripDetId.h:37
bool isHit2D(const TrackingRecHit &hit) const
bool isOkTrkQuality(const reco::Track *track) const
HLT enums.
SiStripRecHit2D originalHit() const
LocalPoint localPosition() const override
static TrackAlgorithm algoByName(const std::string &name)
Definition: TrackBase.cc:137
SiStripRecHit2D monoHit() const
std::vector< double > RorZofLastHitMax_
Log< level::Warning, false > LogWarning
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:56
ClusterRef cluster() const
AlignmentTrackSelector(const edm::ParameterSet &cfg, edm::ConsumesCollector &iC)
constructor
static constexpr auto TEC
Definition: SiStripDetId.h:40
bool useThisFilter()
returns if any of the Filters is used.
Our base class.
Definition: SiPixelRecHit.h:23
bool isOkChargeStripHit(const SiStripRecHit1D &siStripRecHit1D) const
const int kBPIX