test
CMS 3D CMS Logo

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