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 {
91  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()){
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  }
110  else 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  }
121  else applyIterStepCheck_=false;
122 
123  if (applyBasicCuts_){
124  edm::LogInfo("AlignmentTrackSelector")
125  << "applying basic track cuts ..."
126  << "\nptmin,ptmax: " << ptMin_ << "," << ptMax_
127  << "\npmin,pmax: " << pMin_ << "," << pMax_
128  << "\netamin,etamax: " << etaMin_ << "," << etaMax_
129  << "\nphimin,phimax: " << phiMin_ << "," << phiMax_
130  << "\nnhitmin,nhitmax: " << nHitMin_ << "," << nHitMax_
131  << "\nnlosthitmax: " << nLostHitMax_
132  << "\nnhitmin2D: " << nHitMin2D_
133  << (countStereoHitAs2D_ ? "," : ", not") << " counting hits on SiStrip stereo modules as 2D"
134  << "\nchi2nmax: " << chi2nMax_;
135 
136  if (applyIsolation_)
137  edm::LogInfo("AlignmentTrackSelector")
138  << "only retain tracks isolated at least by " << minHitIsolation_ <<
139  " cm from other rechits";
140 
141  if (chargeCheck_)
142  edm::LogInfo("AlignmentTrackSelector")
143  << "only retain hits with at least " << minHitChargeStrip_ <<
144  " ADC counts of total cluster charge";
145 
146  edm::LogInfo("AlignmentTrackSelector")
147  << "Minimum number of hits in TIB/TID/TOB/TEC/BPIX/FPIX/PIXEL = "
148  << minHitsinTIB_ << "/" << minHitsinTID_ << "/" << minHitsinTOB_
149  << "/" << minHitsinTEC_ << "/" << minHitsinBPIX_ << "/" << minHitsinFPIX_ << "/" << minHitsinPIX_;
150 
151  edm::LogInfo("AlignmentTrackSelector")
152  << "Minimum number of hits in TID+/TID-/TEC+/TEC-/FPIX+/FPIX- = "
154  << "/" << minHitsinTECplus_ << "/" << minHitsinTECminus_
155  << "/" << minHitsinFPIXplus_ << "/" << minHitsinFPIXminus_;
156 
157  edm::LogInfo("AlignmentTrackSelector")
158  << "Minimum number of hits in EndCap (TID+TEC)/EndCap+/EndCap- = "
160 
161  edm::LogInfo("AlignmentTrackSelector")
162  << "Max value of |nHitsinENDCAPplus - nHitsinENDCAPminus| = "
164 
165  if (!trkQualityStrings.empty()) {
166  edm::LogInfo("AlignmentTrackSelector")
167  << "Select tracks with these qualities: " << qualities;
168  }
169  }
170 
171  if (applyNHighestPt_)
172  edm::LogInfo("AlignmentTrackSelector")
173  << "filter N tracks with highest Pt N=" << nHighestPt_;
174 
176  edm::LogInfo("AlignmentTrackSelector")
177  << "apply multiplicity filter N>= " << minMultiplicity_ << "and N<= " << maxMultiplicity_
178  << " on " << (multiplicityOnInput_ ? "input" : "output");
179 
181  edm::LogInfo("AlignmentTrackSelector")
182  << "apply cut on number of prescaled hits N>= " << minPrescaledHits_
183  << " (prescale info from " << clusterValueMapTag_ << ")";
184 
185  }
186 
187  // Checking whether cuts on positions of first and last track hits are defined properly
188  if(RorZofFirstHitMin_.size() != 2){
189  throw cms::Exception("BadConfig") << "@SUB=AlignmentTrackSelector::AlignmentTrackSelector"
190  << "Wrong configuration of 'RorZofFirstHitMin'."
191  << " Must have exactly 2 values instead of configured " << RorZofFirstHitMin_.size() << ")";
192  } else {
193  RorZofFirstHitMin_.at(0)=std::fabs(RorZofFirstHitMin_.at(0));
194  RorZofFirstHitMin_.at(1)=std::fabs(RorZofFirstHitMin_.at(1));
195  }
196  if(RorZofFirstHitMax_.size() != 2){
197  throw cms::Exception("BadConfig") << "@SUB=AlignmentTrackSelector::AlignmentTrackSelector"
198  << "Wrong configuration of 'RorZofFirstHitMax'."
199  << " Must have exactly 2 values instead of configured " << RorZofFirstHitMax_.size() << ")";
200  } else {
201  RorZofFirstHitMax_.at(0) = std::fabs(RorZofFirstHitMax_.at(0));
202  RorZofFirstHitMax_.at(1) = std::fabs(RorZofFirstHitMax_.at(1));
203  }
204  if(RorZofLastHitMin_.size() != 2){
205  throw cms::Exception("BadConfig") << "@SUB=AlignmentTrackSelector::AlignmentTrackSelector"
206  << "Wrong configuration of 'RorZofLastHitMin'."
207  << " Must have exactly 2 values instead of configured " << RorZofLastHitMin_.size() << ")";
208  } else {
209  RorZofLastHitMin_.at(0) = std::fabs(RorZofLastHitMin_.at(0));
210  RorZofLastHitMin_.at(1) = std::fabs(RorZofLastHitMin_.at(1));
211  }
212  if(RorZofLastHitMax_.size() != 2){
213  throw cms::Exception("BadConfig") << "@SUB=AlignmentTrackSelector::AlignmentTrackSelector"
214  << "Wrong configuration of 'RorZofLastHitMax'."
215  << " Must have exactly 2 values instead of configured " << RorZofLastHitMax_.size() << ")";
216  } else {
217  RorZofLastHitMax_.at(0) = std::fabs(RorZofLastHitMax_.at(0));
218  RorZofLastHitMax_.at(1) = std::fabs(RorZofLastHitMax_.at(1));
219  }
220  // If first hit set to be at larger distance then the last hit
222  throw cms::Exception("BadConfig") << "@SUB=AlignmentTrackSelector::AlignmentTrackSelector"
223  << "Position of the first hit is set to larger distance than the last hit:."
224  << " First hit(min): [" << RorZofFirstHitMin_.at(0) << ", " << RorZofFirstHitMin_.at(1) << "]; Last hit(max): ["
225  << RorZofLastHitMax_.at(0) << ", " << RorZofLastHitMax_.at(1) << "];";
226  }
227 
228 }
229 
230 // destructor -----------------------------------------------------------------
231 
233 {}
234 
235 
236 // do selection ---------------------------------------------------------------
237 
239 AlignmentTrackSelector::select(const Tracks& tracks, const edm::Event& evt, const edm::EventSetup& eSetup) const
240 {
241 
243  (tracks.size() < static_cast<unsigned int>(minMultiplicity_)
244  || tracks.size() > static_cast<unsigned int>(maxMultiplicity_))) {
245  return Tracks(); // empty collection
246  }
247 
248  Tracks result = tracks;
249  // apply basic track cuts (if selected)
250  if (applyBasicCuts_) result= this->basicCuts(result, evt, eSetup);
251 
252  // filter N tracks with highest Pt (if selected)
253  if (applyNHighestPt_) result = this->theNHighestPtTracks(result);
254 
255  // apply minimum multiplicity requirement (if selected)
257  if (result.size() < static_cast<unsigned int>(minMultiplicity_)
258  || result.size() > static_cast<unsigned int>(maxMultiplicity_) ) {
259 
260  result.clear();
261  }
262  }
263 
265  result = this->checkPrescaledHits(result, evt);
266  }
267 
268  return result;
269 }
270 
273 {
275 
276 }
277 
278 
279 // make basic cuts ------------------------------------------------------------
280 
283 {
284  Tracks result;
285 
286  for (Tracks::const_iterator it=tracks.begin(); it != tracks.end(); ++it) {
287  const reco::Track* trackp=*it;
288  float pt=trackp->pt();
289  float p=trackp->p();
290  float eta=trackp->eta();
291  float phi=trackp->phi();
292  int nhit = trackp->numberOfValidHits();
293  int nlosthit = trackp->numberOfLostHits();
294  float chi2n = trackp->normalizedChi2();
295 
296  int q = trackp->charge();
297  bool isChargeOk = false;
298  if(theCharge_==-1 && q<0) isChargeOk = true;
299  else if (theCharge_==1 && q>0) isChargeOk = true;
300  else if (theCharge_==0) isChargeOk = true;
301 
302  float d0 = trackp->d0();
303  float dz = trackp->dz();
304 
305  // edm::LogDebug("AlignmentTrackSelector") << " pt,eta,phi,nhit: "
306  // <<pt<<","<<eta<<","<<phi<<","<<nhit;
307 
308  if (pt>ptMin_ && pt<ptMax_
309  && p>pMin_ && p<pMax_
310  && eta>etaMin_ && eta<etaMax_
311  && phi>phiMin_ && phi<phiMax_
312  && nhit>=nHitMin_ && nhit<=nHitMax_
313  && nlosthit<=nLostHitMax_
314  && chi2n<chi2nMax_
315  && isChargeOk
316  && d0>=d0Min_ && d0<=d0Max_
317  && dz>=dzMin_ && dz<=dzMax_) {
318  bool trkQualityOk=false ;
319  if (!applyTrkQualityCheck_ &&!applyIterStepCheck_)trkQualityOk=true ; // nothing required
320  else trkQualityOk = this->isOkTrkQuality(trackp);
321 
322  bool hitsCheckOk=this->detailedHitsCheck(trackp, evt, eSetup);
323 
324  if (trkQualityOk && hitsCheckOk ) result.push_back(trackp);
325  }
326  }
327 
328  return result;
329 }
330 
331 //-----------------------------------------------------------------------------
332 
333 bool AlignmentTrackSelector::detailedHitsCheck(const reco::Track *trackp, const edm::Event& evt, const edm::EventSetup& eSetup) const
334 {
335 
336  //Retrieve tracker topology from geometry
337  edm::ESHandle<TrackerTopology> tTopoHandle;
338  eSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
339  const TrackerTopology* const tTopo = tTopoHandle.product();
340 
341  // checking hit requirements beyond simple number of valid hits
342 
350  || !RorZofFirstHitMin_.empty() || !RorZofFirstHitMax_.empty() || !RorZofLastHitMin_.empty() || !RorZofLastHitMax_.empty() ) {
351  // any detailed hit cut is active, so have to check
352 
353  int nhitinTIB = 0, nhitinTOB = 0, nhitinTID = 0;
354  int nhitinTEC = 0, nhitinBPIX = 0, nhitinFPIX = 0, nhitinPIXEL=0;
355  int nhitinENDCAP = 0, nhitinENDCAPplus = 0, nhitinENDCAPminus = 0;
356  int nhitinTIDplus = 0, nhitinTIDminus = 0;
357  int nhitinFPIXplus = 0, nhitinFPIXminus = 0;
358  int nhitinTECplus = 0, nhitinTECminus = 0;
359  unsigned int nHit2D = 0;
360  unsigned int thishit = 0;
361 
362  for (trackingRecHit_iterator iHit = trackp->recHitsBegin(); iHit != trackp->recHitsEnd(); ++iHit) {
363  thishit++;
364  const DetId detId((*iHit)->geographicalId());
365  const int subdetId = detId.subdetId();
366 
367  // *** thishit == 1 means last hit in CTF ***
368  // (FIXME: assumption might change or not be valid for all tracking algorthms)
369  // ==> for cosmics
370  // seedOnlyFrom = 1 is TIB-TOB-TEC tracks only
371  // seedOnlyFrom = 2 is TOB-TEC tracks only
372  if (seedOnlyFromAbove_ == 1 && thishit == 1
373  && (subdetId == int(SiStripDetId::TOB) || subdetId == int(SiStripDetId::TEC))){
374  return false;
375  }
376  if (seedOnlyFromAbove_ == 2 && thishit == 1 && subdetId == int(SiStripDetId::TIB)) {
377  return false;
378  }
379 
380  if (!(*iHit)->isValid()) continue; // only real hits count as in trackp->numberOfValidHits()
381  if (detId.det() != DetId::Tracker) {
382  edm::LogError("DetectorMismatch") << "@SUB=AlignmentTrackSelector::detailedHitsCheck"
383  << "DetId.det() != DetId::Tracker (=" << DetId::Tracker
384  << "), but " << detId.det() << ".";
385  }
386  const TrackingRecHit* therechit = (*iHit);
387  if (chargeCheck_ && !(this->isOkCharge(therechit))) return false;
388  if (applyIsolation_ && (!this->isIsolated(therechit, evt))) return false;
389  if (SiStripDetId::TIB == subdetId) ++nhitinTIB;
390  else if (SiStripDetId::TOB == subdetId) ++nhitinTOB;
391  else if (SiStripDetId::TID == subdetId) {
392  ++nhitinTID;
393  ++nhitinENDCAP;
394 
395  if (tTopo->tidIsZMinusSide(detId)) {
396  ++nhitinTIDminus;
397  ++nhitinENDCAPminus;
398  }
399  else if (tTopo->tidIsZPlusSide(detId)) {
400  ++nhitinTIDplus;
401  ++nhitinENDCAPplus;
402  }
403  }
404  else if (SiStripDetId::TEC == subdetId) {
405  ++nhitinTEC;
406  ++nhitinENDCAP;
407 
408  if (tTopo->tecIsZMinusSide(detId)) {
409  ++nhitinTECminus;
410  ++nhitinENDCAPminus;
411  }
412  else if (tTopo->tecIsZPlusSide(detId)) {
413  ++nhitinTECplus;
414  ++nhitinENDCAPplus;
415  }
416  }
417  else if ( kBPIX == subdetId) {++nhitinBPIX;++nhitinPIXEL;}
418  else if ( kFPIX == subdetId) {
419  ++nhitinFPIX;
420  ++nhitinPIXEL;
421 
422  if (tTopo->pxfSide(detId)==1) ++nhitinFPIXminus;
423  else if (tTopo->pxfSide(detId)==2) ++nhitinFPIXplus;
424  }
425  // Do not call isHit2D(..) if already enough 2D hits for performance reason:
426  if (nHit2D < nHitMin2D_ && this->isHit2D(**iHit)) ++nHit2D;
427  } // end loop on hits
428 
429 
430  // Checking whether the track satisfies requirement of the first and last hit positions
431  bool passedLastHitPositionR = true;
432  bool passedLastHitPositionZ = true;
433  bool passedFirstHitPositionR = true;
434  bool passedFirstHitPositionZ = true;
435 
436  if( RorZofFirstHitMin_.at(0) != 0.0 || RorZofFirstHitMin_.at(1) != 0.0
437  || RorZofFirstHitMax_.at(0) != 999.0 || RorZofFirstHitMax_.at(1) != 999.0 ) {
438 
439  const reco::TrackBase::Point& firstPoint(trackp->innerPosition());
440 
441  if( (std::fabs(firstPoint.R()) < RorZofFirstHitMin_.at(0) )) passedFirstHitPositionR = false;
442  if( (std::fabs(firstPoint.R()) > RorZofFirstHitMax_.at(0) )) passedFirstHitPositionR = false;
443  if( (std::fabs(firstPoint.Z()) < RorZofFirstHitMin_.at(1) )) passedFirstHitPositionZ = false;
444  if( (std::fabs(firstPoint.Z()) > RorZofFirstHitMax_.at(1) )) passedFirstHitPositionZ = false;
445  }
446 
447  if( RorZofLastHitMin_.at(0) != 0.0 || RorZofLastHitMin_.at(1) != 0.0
448  || RorZofLastHitMax_.at(0) != 999.0 || RorZofLastHitMax_.at(1) != 999.0 ) {
449 
450  const reco::TrackBase::Point& lastPoint(trackp->outerPosition());
451 
452  if( (std::fabs(lastPoint.R()) < RorZofLastHitMin_.at(0) )) passedLastHitPositionR = false;
453  if( (std::fabs(lastPoint.R()) > RorZofLastHitMax_.at(0) )) passedLastHitPositionR = false;
454  if( (std::fabs(lastPoint.Z()) < RorZofLastHitMin_.at(1) )) passedLastHitPositionZ = false;
455  if( (std::fabs(lastPoint.Z()) > RorZofLastHitMax_.at(1) )) passedLastHitPositionZ = false;
456  }
457 
458  bool passedFirstHitPosition = passedFirstHitPositionR || passedFirstHitPositionZ;
459  bool passedLastHitPosition = passedLastHitPositionR || passedLastHitPositionZ;
460 
461 
462 
463  return (nhitinTIB >= minHitsinTIB_ && nhitinTOB >= minHitsinTOB_
464  && nhitinTID >= minHitsinTID_ && nhitinTEC >= minHitsinTEC_
465  && nhitinENDCAP >= minHitsinENDCAP_ && nhitinENDCAPplus >= minHitsinENDCAPplus_ && nhitinENDCAPminus >= minHitsinENDCAPminus_
466  && std::abs(nhitinENDCAPplus-nhitinENDCAPminus) <= maxHitDiffEndcaps_
467  && nhitinTIDplus >= minHitsinTIDplus_ && nhitinTIDminus >= minHitsinTIDminus_
468  && nhitinFPIXplus >= minHitsinFPIXplus_ && nhitinFPIXminus >= minHitsinFPIXminus_
469  && nhitinTECplus >= minHitsinTECplus_ && nhitinTECminus >= minHitsinTECminus_
470  && nhitinBPIX >= minHitsinBPIX_
471  && nhitinFPIX >= minHitsinFPIX_ && nhitinPIXEL>=minHitsinPIX_
472  && nHit2D >= nHitMin2D_ && passedFirstHitPosition && passedLastHitPosition);
473  } else { // no cuts set, so we are just fine and can avoid loop on hits
474  return true;
475  }
476 
477 }
478 
479 //-----------------------------------------------------------------------------
480 
482 {
483  // we count SiStrip stereo modules as 2D if selected via countStereoHitAs2D_
484  // (since they provide theta information)
485  if (!hit.isValid() ||
486  (hit.dimension() < 2 && !countStereoHitAs2D_ && !dynamic_cast<const SiStripRecHit1D*>(&hit))){
487  return false; // real RecHit1D - but SiStripRecHit1D depends on countStereoHitAs2D_
488  } else {
489  const DetId detId(hit.geographicalId());
490  if (detId.det() == DetId::Tracker) {
491  if (detId.subdetId() == kBPIX || detId.subdetId() == kFPIX) {
492  return true; // pixel is always 2D
493  } else { // should be SiStrip now
494  const SiStripDetId stripId(detId);
495  if (stripId.stereo()) return countStereoHitAs2D_; // stereo modules
496  else if (dynamic_cast<const SiStripRecHit1D*>(&hit)
497  || dynamic_cast<const SiStripRecHit2D*>(&hit)) return false; // rphi modules hit
498  //the following two are not used any more since ages...
499  else if (dynamic_cast<const SiStripMatchedRecHit2D*>(&hit)) return true; // matched is 2D
500  else if (dynamic_cast<const ProjectedSiStripRecHit2D*>(&hit)) {
501  const ProjectedSiStripRecHit2D* pH = static_cast<const ProjectedSiStripRecHit2D*>(&hit);
502  return (countStereoHitAs2D_ && this->isHit2D(pH->originalHit())); // depends on original...
503  } else {
504  edm::LogError("UnkownType") << "@SUB=AlignmentTrackSelector::isHit2D"
505  << "Tracker hit not in pixel, neither SiStripRecHit[12]D nor "
506  << "SiStripMatchedRecHit2D nor ProjectedSiStripRecHit2D.";
507  return false;
508  }
509  }
510  } else { // not tracker??
511  edm::LogWarning("DetectorMismatch") << "@SUB=AlignmentTrackSelector::isHit2D"
512  << "Hit not in tracker with 'official' dimension >=2.";
513  return true; // dimension() >= 2 so accept that...
514  }
515  }
516  // never reached...
517 }
518 
519 //-----------------------------------------------------------------------------
520 
522 {
523  if (!hit || !hit->isValid()) return true;
524 
525  // check det and subdet
526  const DetId id(hit->geographicalId());
527  if (id.det() != DetId::Tracker) {
528  edm::LogWarning("DetectorMismatch") << "@SUB=isOkCharge" << "Hit not in tracker!";
529  return true;
530  }
531  if (id.subdetId() == kFPIX || id.subdetId() == kBPIX) {
532  return true; // might add some requirement...
533  }
534 
535  // We are in SiStrip now, so test normal hit:
536  const std::type_info &type = typeid(*hit);
537 
538 
539  if (type == typeid(SiStripRecHit2D)) {
540  const SiStripRecHit2D *stripHit2D = dynamic_cast<const SiStripRecHit2D*>(hit);
541  if (stripHit2D) {
542  return this->isOkChargeStripHit(*stripHit2D);
543  }
544  }
545  else if(type == typeid(SiStripRecHit1D)){
546  const SiStripRecHit1D *stripHit1D = dynamic_cast<const SiStripRecHit1D*>(hit);
547  if (stripHit1D) {
548  return this->isOkChargeStripHit(*stripHit1D);
549  }
550  }
551 
552  else if(type == typeid(SiStripMatchedRecHit2D)){ // or matched (should not occur anymore due to hit splitting since 20X)
553  const SiStripMatchedRecHit2D *matchedHit = dynamic_cast<const SiStripMatchedRecHit2D*>(hit);
554  if (matchedHit) {
555  return (this->isOkChargeStripHit(matchedHit->monoHit())
556  && this->isOkChargeStripHit(matchedHit->stereoHit()));
557  }
558  }
559  else if(type == typeid(ProjectedSiStripRecHit2D)){
560  // or projected (should not occur anymore due to hit splitting since 20X):
561  const ProjectedSiStripRecHit2D *projHit = dynamic_cast<const ProjectedSiStripRecHit2D*>(hit);
562  if (projHit) {
563  return this->isOkChargeStripHit(projHit->originalHit());
564  }
565  }
566  else{
567  edm::LogError("AlignmentTrackSelector")<< "@SUB=isOkCharge" <<"Unknown type of a valid tracker hit in Strips "
568  << " SubDet = "<<id.subdetId();
569  return false;
570  }
571 
572 
573 
574  // and now? SiTrackerMultiRecHit? Not here I guess!
575  // Should we throw instead?
576  edm::LogError("AlignmentTrackSelector")
577  << "@SUB=isOkCharge" << "Unknown valid tracker hit not in pixel, subdet " << id.subdetId()
578  << ", SiTrackerMultiRecHit " << dynamic_cast<const SiTrackerMultiRecHit*>(hit)
579  << ", BaseTrackerRecHit " << dynamic_cast<const BaseTrackerRecHit*>(hit);
580 
581  return true;
582 }
583 
584 
585 //-----------------------------------------------------------------------------
586 
588 {
589  double charge = 0.;
590 
591  SiStripRecHit2D::ClusterRef cluster(siStripRecHit2D.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 {
605  double charge = 0.;
606 
607  SiStripRecHit1D::ClusterRef cluster(siStripRecHit1D.cluster());
608  const auto &amplitudes = cluster->amplitudes();
609 
610  for (size_t ia = 0; ia < amplitudes.size(); ++ia) {
611  charge += amplitudes[ia];
612  }
613 
614  return (charge >= minHitChargeStrip_);
615 }
616 
617 //-----------------------------------------------------------------------------
618 
619 bool AlignmentTrackSelector::isIsolated(const TrackingRecHit* therechit, const edm::Event& evt) const
620 {
621  // FIXME:
622  // adapt to changes after introduction of SiStripRecHit1D...
623  //
624  // edm::ESHandle<TrackerGeometry> tracker;
627  // es.get<TrackerDigiGeometryRecord>().get(tracker);
628  evt.getByToken( rphirecHitsToken_, rphirecHits );
629  evt.getByToken( matchedrecHitsToken_, matchedrecHits );
630 
633  const SiStripRecHit2DCollection::DataContainer& stripcollSt = rphirecHits->data();
634  const SiStripMatchedRecHit2DCollection::DataContainer& stripcollStm = matchedrecHits->data();
635 
636  DetId idet = therechit->geographicalId();
637 
638  // FIXME: instead of looping the full hit collection, we should explore the features of
639  // SiStripRecHit2DCollection::rangeRphi = rphirecHits.get(idet) and loop
640  // only from rangeRphi.first until rangeRphi.second
641  for( istripSt=stripcollSt.begin(); istripSt!=stripcollSt.end(); ++istripSt ) {
642  const SiStripRecHit2D *aHit = &*(istripSt);
643  DetId mydet1 = aHit->geographicalId();
644  if (idet.rawId() != mydet1.rawId()) continue;
645  float theDistance = ( therechit->localPosition() - aHit->localPosition() ).mag();
646  // std::cout << "theDistance1 = " << theDistance << "\n";
647  if (theDistance > 0.001 && theDistance < minHitIsolation_) return false;
648  }
649 
650  // FIXME: see above
651  for( istripStm=stripcollStm.begin(); istripStm!=stripcollStm.end(); ++istripStm ) {
652  const SiStripMatchedRecHit2D *aHit = &*(istripStm);
653  DetId mydet2 = aHit->geographicalId();
654  if (idet.rawId() != mydet2.rawId()) continue;
655  float theDistance = (therechit->localPosition() - aHit->localPosition()).mag();
656  // std::cout << "theDistance1 = " << theDistance << "\n";
657  if (theDistance > 0.001 && theDistance < minHitIsolation_) return false;
658  }
659  return true;
660 }
661 
662 //-----------------------------------------------------------------------------
663 
666 {
667  Tracks sortedTracks=tracks;
668  Tracks result;
669 
670  // sort in pt
671  std::sort(sortedTracks.begin(),sortedTracks.end(),ptComparator);
672 
673  // copy theTrackMult highest pt tracks to result vector
674  int n=0;
675  for (Tracks::const_iterator it=sortedTracks.begin();
676  it!=sortedTracks.end(); ++it) {
677  if (n<nHighestPt_) { result.push_back(*it); n++; }
678  }
679 
680  return result;
681 }
682 
683 //---------
684 
687 {
688  Tracks result;
689 
690  //take Cluster-Flag Assomap
692  evt.getByToken( clusterValueMapToken_, fMap);
693  const AliClusterValueMap &flagMap=*fMap;
694 
695  //for each track loop on hits and count the number of taken hits
696  for (Tracks::const_iterator ittrk=tracks.begin(); ittrk != tracks.end(); ++ittrk) {
697  const reco::Track* trackp=*ittrk;
698  int ntakenhits=0;
699  // float pt=trackp->pt();
700 
701  for (trackingRecHit_iterator ith = trackp->recHitsBegin(), edh = trackp->recHitsEnd(); ith != edh; ++ith) {
702  const TrackingRecHit *hit = (*ith); // ith is an iterator on edm::Ref to rechit
703  if(! hit->isValid())continue;
704  DetId detid = hit->geographicalId();
705  int subDet = detid.subdetId();
707 
708  bool isPixelHit=(subDet == kFPIX || subDet == kBPIX);
709 
710  if (!isPixelHit){
711  const std::type_info &type = typeid(*hit);
712 
713  if (type == typeid(SiStripRecHit2D)) {
714  const SiStripRecHit2D* striphit=dynamic_cast<const SiStripRecHit2D*>(hit);
715  if(striphit!=nullptr){
716  SiStripRecHit2D::ClusterRef stripclust(striphit->cluster());
717  flag = flagMap[stripclust];
718  }
719  }
720  else if(type == typeid(SiStripRecHit1D)){
721  const SiStripRecHit1D* striphit = dynamic_cast<const SiStripRecHit1D*>(hit);
722  if(striphit!=nullptr){
723  SiStripRecHit1D::ClusterRef stripclust(striphit->cluster());
724  flag = flagMap[stripclust];
725  }
726  }
727  else{
728  edm::LogError("AlignmentTrackSelector")<<"ERROR in <AlignmentTrackSelector::checkPrescaledHits>: Dynamic cast of Strip RecHit failed!"
729  <<" Skipping this hit.";
730  continue;
731  }
732 
733 
734 
735  }//end if hit in Strips
736  else{ // test explicitely BPIX/FPIX
737  const SiPixelRecHit* pixelhit= dynamic_cast<const SiPixelRecHit*>(hit);
738  if(pixelhit!=nullptr){
739  SiPixelRecHit::ClusterRef pixclust(pixelhit->cluster());
740  flag = flagMap[pixclust];
741  }
742  else{
743  edm::LogError("AlignmentTrackSelector")<<"ERROR in <AlignmentTrackSelector::checkPrescaledHits>: Dynamic cast of Pixel RecHit failed! ";
744  }
745  }//end else hit is in Pixel
746 
747  if(flag.isTaken())ntakenhits++;
748 
749  }//end loop on hits
750  if(ntakenhits >= minPrescaledHits_)result.push_back(trackp);
751  }//end loop on tracks
752 
753  return result;
754 }//end checkPrescaledHits
755 
756 //-----------------------------------------------------------------
757 
759 {
760  bool qualityOk=false;
761  bool iterStepOk=false;
762 
763  //check iterative step
765  for (unsigned int i = 0; i < trkSteps_.size(); ++i) {
766  if (track->algo()==(trkSteps_[i])) {
767  iterStepOk=true;
768  }
769  }
770  }
771  else iterStepOk=true;
772 
773  //check track quality
775  for (unsigned int i = 0; i < trkQualities_.size(); ++i) {
776  if (track->quality(trkQualities_[i])) {
777  qualityOk=true;
778  }
779  }
780  }
781  else qualityOk=true;
782 
783  return qualityOk&&iterStepOk;
784 }//end check on track quality
edm::EDGetTokenT< SiStripMatchedRecHit2DCollection > matchedrecHitsToken_
ClusterRef cluster() const
double p() const
momentum vector magnitude
Definition: TrackBase.h:615
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:597
uint32_t stereo() const
Definition: SiStripDetId.h:160
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:561
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
std::vector< const reco::Track * > Tracks
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:645
unsigned short numberOfLostHits() const
number of cases where track crossed a layer without getting a hit.
Definition: TrackBase.h:826
std::vector< reco::TrackBase::TrackQuality > trkQualities_
const unsigned int nHitMin2D_
const math::XYZPoint & outerPosition() const
position of the outermost hit
Definition: Track.h:65
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:55
TrackAlgorithm algo() const
Definition: TrackBase.h:497
uint32_t rawId() const
get the raw id
Definition: DetId.h:44
const int kFPIX
bool isHit2D(const TrackingRecHit &hit) const
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:651
virtual int dimension() const =0
double pt() const
track transverse momentum
Definition: TrackBase.h:621
data_type const * data(size_t cell) const
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:820
math::XYZPoint Point
point in the space
Definition: TrackBase.h:83
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:104
virtual LocalPoint localPosition() const =0
std::vector< double > RorZofLastHitMin_
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:38
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:609
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:125
SiStripRecHit2D stereoHit() const
bool tidIsZPlusSide(const DetId &id) const
const edm::InputTag clusterValueMapTag_
ClusterRef cluster() const
Definition: SiPixelRecHit.h:49
const T & get() const
Definition: EventSetup.h:59
bool isValid() const
def encode(args, files)
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:510
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 ...
static TrackAlgorithm algoByName(const std::string &name)
Definition: TrackBase.cc:137
unsigned int pxfSide(const DetId &id) const
LocalPoint localPosition() const final
int charge() const
track electric charge
Definition: TrackBase.h:567
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
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:109