CMS 3D CMS Logo

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