CMS 3D CMS Logo

CalibrationTrackSelector.cc
Go to the documentation of this file.
2 
5 
7 
15 
19 
22 
23 // constructor ----------------------------------------------------------------
24 
26  applyBasicCuts_( cfg.getParameter<bool>( "applyBasicCuts" ) ),
27  applyNHighestPt_( cfg.getParameter<bool>( "applyNHighestPt" ) ),
28  applyMultiplicityFilter_( cfg.getParameter<bool>( "applyMultiplicityFilter" ) ),
29  seedOnlyFromAbove_( cfg.getParameter<int>( "seedOnlyFrom" ) ),
30  applyIsolation_( cfg.getParameter<bool>( "applyIsolationCut" ) ),
31  chargeCheck_( cfg.getParameter<bool>( "applyChargeCheck" ) ),
32  nHighestPt_( cfg.getParameter<int>( "nHighestPt" ) ),
33  minMultiplicity_ ( cfg.getParameter<int>( "minMultiplicity" ) ),
34  maxMultiplicity_ ( cfg.getParameter<int>( "maxMultiplicity" ) ),
35  multiplicityOnInput_ ( cfg.getParameter<bool>( "multiplicityOnInput" ) ),
36  ptMin_( cfg.getParameter<double>( "ptMin" ) ),
37  ptMax_( cfg.getParameter<double>( "ptMax" ) ),
38  etaMin_( cfg.getParameter<double>( "etaMin" ) ),
39  etaMax_( cfg.getParameter<double>( "etaMax" ) ),
40  phiMin_( cfg.getParameter<double>( "phiMin" ) ),
41  phiMax_( cfg.getParameter<double>( "phiMax" ) ),
42  nHitMin_( cfg.getParameter<double>( "nHitMin" ) ),
43  nHitMax_( cfg.getParameter<double>( "nHitMax" ) ),
44  chi2nMax_( cfg.getParameter<double>( "chi2nMax" ) ),
45  minHitChargeStrip_( cfg.getParameter<double>( "minHitChargeStrip" ) ),
46  minHitIsolation_( cfg.getParameter<double>( "minHitIsolation" ) ),
47  rphirecHitsTag_( cfg.getParameter<edm::InputTag>("rphirecHits") ),
48  matchedrecHitsTag_( cfg.getParameter<edm::InputTag>("matchedrecHits") ),
49  nHitMin2D_( cfg.getParameter<unsigned int>( "nHitMin2D" ) ),
50  // Ugly to use the same getParameter 6 times, but this allows const cut variables...
51  minHitsinTIB_(cfg.getParameter<edm::ParameterSet>( "minHitsPerSubDet" ).getParameter<int>( "inTIB" ) ),
52  minHitsinTOB_ (cfg.getParameter<edm::ParameterSet>( "minHitsPerSubDet" ).getParameter<int>( "inTOB" ) ),
53  minHitsinTID_ (cfg.getParameter<edm::ParameterSet>( "minHitsPerSubDet" ).getParameter<int>( "inTID" ) ),
54  minHitsinTEC_ (cfg.getParameter<edm::ParameterSet>( "minHitsPerSubDet" ).getParameter<int>( "inTEC" ) ),
55  minHitsinBPIX_ (cfg.getParameter<edm::ParameterSet>( "minHitsPerSubDet" ).getParameter<int>( "inBPIX" ) ),
56  minHitsinFPIX_ (cfg.getParameter<edm::ParameterSet>( "minHitsPerSubDet" ).getParameter<int>( "inFPIX" ) )
57 {
58 
59  if (applyBasicCuts_)
60  edm::LogInfo("CalibrationTrackSelector")
61  << "applying basic track cuts ..."
62  << "\nptmin,ptmax: " << ptMin_ << "," << ptMax_
63  << "\netamin,etamax: " << etaMin_ << "," << etaMax_
64  << "\nphimin,phimax: " << phiMin_ << "," << phiMax_
65  << "\nnhitmin,nhitmax: " << nHitMin_ << "," << nHitMax_
66  << "\nnhitmin2D: " << nHitMin2D_
67  << "\nchi2nmax: " << chi2nMax_;
68 
69  if (applyNHighestPt_)
70  edm::LogInfo("CalibrationTrackSelector")
71  << "filter N tracks with highest Pt N=" << nHighestPt_;
72 
74  edm::LogInfo("CalibrationTrackSelector")
75  << "apply multiplicity filter N>= " << minMultiplicity_ << "and N<= " << maxMultiplicity_
76  << " on " << (multiplicityOnInput_ ? "input" : "output");
77 
78  if (applyIsolation_)
79  edm::LogInfo("CalibrationTrackSelector")
80  << "only retain tracks isolated at least by " << minHitIsolation_ <<
81  " cm from other rechits";
82 
83  if (chargeCheck_)
84  edm::LogInfo("CalibrationTrackSelector")
85  << "only retain hits with at least " << minHitChargeStrip_ <<
86  " ADC counts of total cluster charge";
87 
88  edm::LogInfo("CalibrationTrackSelector")
89  << "Minimum number of hits in TIB/TID/TOB/TEC/BPIX/FPIX = "
90  << minHitsinTIB_ << "/" << minHitsinTID_ << "/" << minHitsinTOB_
91  << "/" << minHitsinTEC_ << "/" << minHitsinBPIX_ << "/" << minHitsinFPIX_;
92 
93 }
94 
95 // destructor -----------------------------------------------------------------
96 
98 {}
99 
100 
101 // do selection ---------------------------------------------------------------
102 
105 {
106 
108  (tracks.size() < static_cast<unsigned int>(minMultiplicity_)
109  || tracks.size() > static_cast<unsigned int>(maxMultiplicity_))) {
110  return Tracks(); // empty collection
111  }
112 
113  Tracks result = tracks;
114  // apply basic track cuts (if selected)
115  if (applyBasicCuts_) result= this->basicCuts(result, evt);
116 
117  // filter N tracks with highest Pt (if selected)
118  if (applyNHighestPt_) result = this->theNHighestPtTracks(result);
119 
120  // apply minimum multiplicity requirement (if selected)
122  if (result.size() < static_cast<unsigned int>(minMultiplicity_)
123  || result.size() > static_cast<unsigned int>(maxMultiplicity_) ) {
124 
125  result.clear();
126  }
127  }
128 
129  // edm::LogDebug("CalibrationTrackSelector") << "tracks all,kept: " << tracks.size() << "," << result.size();
130 
131  return result;
132 }
133 
134 // make basic cuts ------------------------------------------------------------
135 
138 {
139  Tracks result;
140 
141  for (Tracks::const_iterator it=tracks.begin(); it != tracks.end(); ++it) {
142  const reco::Track* trackp=*it;
143  float pt=trackp->pt();
144  float eta=trackp->eta();
145  float phi=trackp->phi();
146  int nhit = trackp->numberOfValidHits();
147  float chi2n = trackp->normalizedChi2();
148 
149  // edm::LogDebug("CalibrationTrackSelector") << " pt,eta,phi,nhit: "
150  // <<pt<<","<<eta<<","<<phi<<","<<nhit;
151 
152  if (pt>ptMin_ && pt<ptMax_
153  && eta>etaMin_ && eta<etaMax_
154  && phi>phiMin_ && phi<phiMax_
155  && nhit>=nHitMin_ && nhit<=nHitMax_
156  && chi2n<chi2nMax_) {
157  if (this->detailedHitsCheck(trackp, evt)) result.push_back(trackp);
158  }
159  }
160 
161  return result;
162 }
163 
164 //-----------------------------------------------------------------------------
165 
167 {
168  // checking hit requirements beyond simple number of valid hits
169 
172  || applyIsolation_) { // any detailed hit cut is active, so have to check
173 
174  int nhitinTIB = 0, nhitinTOB = 0, nhitinTID = 0;
175  int nhitinTEC = 0, nhitinBPIX = 0, nhitinFPIX = 0;
176  unsigned int nHit2D = 0;
177  unsigned int thishit = 0;
178 
179  for (trackingRecHit_iterator iHit = trackp->recHitsBegin(); iHit != trackp->recHitsEnd(); ++iHit) {
180 
181  thishit++;
182  int type = (*iHit)->geographicalId().subdetId();
183 
184  // *** thishit == 1 means last hit in CTF ***
185  // (FIXME: assumption might change or not be valid for all tracking algorthms)
186  // ==> for cosmics
187  // seedOnlyFrom = 1 is TIB-TOB-TEC tracks only
188  // seedOnlyFrom = 2 is TOB-TEC tracks only
189  if (seedOnlyFromAbove_ == 1 && thishit == 1 && (type == int(StripSubdetector::TOB) || type == int(StripSubdetector::TEC))) return false;
190 
191  if (seedOnlyFromAbove_ == 2 && thishit == 1 && type == int(StripSubdetector::TIB)) return false;
192 
193  if (!(*iHit)->isValid()) continue; // only real hits count as in trackp->numberOfValidHits()
194  const DetId detId((*iHit)->geographicalId());
195  if (detId.det() != DetId::Tracker) {
196  edm::LogError("DetectorMismatch") << "@SUB=CalibrationTrackSelector::detailedHitsCheck"
197  << "DetId.det() != DetId::Tracker (=" << DetId::Tracker
198  << "), but " << detId.det() << ".";
199  }
200  const TrackingRecHit* therechit = (*iHit);
201  if (chargeCheck_ && !(this->isOkCharge(therechit))) return false;
202  if (applyIsolation_ && (!this->isIsolated(therechit, evt))) return false;
203  if (StripSubdetector::TIB == detId.subdetId()) ++nhitinTIB;
204  else if (StripSubdetector::TOB == detId.subdetId()) ++nhitinTOB;
205  else if (StripSubdetector::TID == detId.subdetId()) ++nhitinTID;
206  else if (StripSubdetector::TEC == detId.subdetId()) ++nhitinTEC;
207  else if ( kBPIX == detId.subdetId()) ++nhitinBPIX;
208  else if ( kFPIX == detId.subdetId()) ++nhitinFPIX;
209  // Do not call isHit2D(..) if already enough 2D hits for performance reason:
210  if (nHit2D < nHitMin2D_ && this->isHit2D(**iHit)) ++nHit2D;
211  } // end loop on hits
212  return (nhitinTIB >= minHitsinTIB_ && nhitinTOB >= minHitsinTOB_
213  && nhitinTID >= minHitsinTID_ && nhitinTEC >= minHitsinTEC_
214  && nhitinBPIX >= minHitsinBPIX_ && nhitinFPIX >= minHitsinFPIX_
215  && nHit2D >= nHitMin2D_);
216  } else { // no cuts set, so we are just fine and can avoid loop on hits
217  return true;
218  }
219 }
220 
221 //-----------------------------------------------------------------------------
222 
224 {
225  if (hit.dimension() < 2) {
226  return false; // some (muon...) stuff really has RecHit1D
227  } else {
228  const DetId detId(hit.geographicalId());
229  if (detId.det() == DetId::Tracker) {
230  if (detId.subdetId() == kBPIX || detId.subdetId() == kFPIX) {
231  return true; // pixel is always 2D
232  } else { // should be SiStrip now
233  if (dynamic_cast<const SiStripRecHit2D*>(&hit)) return false; // normal hit
234  else if (dynamic_cast<const SiStripMatchedRecHit2D*>(&hit)) return true; // matched is 2D
235  else if (dynamic_cast<const ProjectedSiStripRecHit2D*>(&hit)) return false; // crazy hit...
236  else {
237  edm::LogError("UnkownType") << "@SUB=CalibrationTrackSelector::isHit2D"
238  << "Tracker hit not in pixel and neither SiStripRecHit2D nor "
239  << "SiStripMatchedRecHit2D nor ProjectedSiStripRecHit2D.";
240  return false;
241  }
242  }
243  } else { // not tracker??
244  edm::LogWarning("DetectorMismatch") << "@SUB=CalibrationTrackSelector::isHit2D"
245  << "Hit not in tracker with 'official' dimension >=2.";
246  return true; // dimension() >= 2 so accept that...
247  }
248  }
249  // never reached...
250 }
251 
252 //-----------------------------------------------------------------------------
253 
255 {
256  float charge1 = 0;
257  float charge2 = 0;
258  const SiStripMatchedRecHit2D* matchedhit = dynamic_cast<const SiStripMatchedRecHit2D*>(therechit);
259  const SiStripRecHit2D* hit = dynamic_cast<const SiStripRecHit2D*>(therechit);
260  const ProjectedSiStripRecHit2D* unmatchedhit = dynamic_cast<const ProjectedSiStripRecHit2D*>(therechit);
261 
262  if (matchedhit) {
263  const SiStripCluster & monocluster = matchedhit->monoCluster();
264  const std::vector<uint16_t> amplitudesmono( monocluster.amplitudes().begin(),
265  monocluster.amplitudes().end());
266  for(size_t ia=0; ia<amplitudesmono.size();++ia)
267  { charge1+=amplitudesmono[ia];}
268 
269  const SiStripCluster & stereocluster = matchedhit->stereoCluster();
270  const std::vector<uint16_t> amplitudesstereo( stereocluster.amplitudes().begin(),
271  stereocluster.amplitudes().end());
272  for(size_t ia=0; ia<amplitudesstereo.size();++ia)
273  {charge2+=amplitudesstereo[ia];}
274  // std::cout << "charge1 = " << charge1 << "\n";
275  // std::cout << "charge2 = " << charge2 << "\n";
276  if (charge1 < minHitChargeStrip_ || charge2 < minHitChargeStrip_) return false;
277  }
278  else if (hit) {
279 
280  const SiStripCluster* cluster = &*(hit->cluster());
281  const std::vector<uint16_t> amplitudes( cluster->amplitudes().begin(),
282  cluster->amplitudes().end());
283  for(size_t ia=0; ia<amplitudes.size();++ia)
284  {charge1+=amplitudes[ia];}
285  // std::cout << "charge1 = " << charge1 << "\n";
286  if (charge1 < minHitChargeStrip_) return false;
287  }
288  else if (unmatchedhit) {
289 
290  const SiStripRecHit2D &orighit = unmatchedhit->originalHit();
291  const SiStripCluster* origcluster = &*(orighit.cluster());
292  const std::vector<uint16_t> amplitudes( origcluster->amplitudes().begin(),
293  origcluster->amplitudes().end());
294  for(size_t ia=0; ia<amplitudes.size();++ia)
295  {charge1+=amplitudes[ia];}
296  // std::cout << "charge1 = " << charge1 << "\n";
297  if (charge1 < minHitChargeStrip_) return false;
298  }
299  return true;
300 }
301 
302 //-----------------------------------------------------------------------------
303 
304 bool CalibrationTrackSelector::isIsolated(const TrackingRecHit* therechit, const edm::Event& evt) const
305 {
306 
307  // edm::ESHandle<TrackerGeometry> tracker;
310  // es.get<TrackerDigiGeometryRecord>().get(tracker);
311  evt.getByLabel( rphirecHitsTag_, rphirecHits );
312  evt.getByLabel( matchedrecHitsTag_, matchedrecHits );
313 
316  const SiStripRecHit2DCollection& stripcollSt = *rphirecHits;
317  const SiStripMatchedRecHit2DCollection& stripcollStm = *matchedrecHits;
318 
319  DetId idet = therechit->geographicalId();
320 
321  // FIXME: instead of looping the full hit collection, we should explore the features of
322  // SiStripRecHit2DCollection::rangeRphi = rphirecHits.get(idet) and loop
323  // only from rangeRphi.first until rangeRphi.second
324  for( istripSt=stripcollSt.data().begin(); istripSt!=stripcollSt.data().end(); ++istripSt ) {
325  const SiStripRecHit2D *aHit = &*(istripSt);
326  DetId mydet1 = aHit->geographicalId();
327  if (idet.rawId() != mydet1.rawId()) continue;
328  float theDistance = ( therechit->localPosition() - aHit->localPosition() ).mag();
329  // std::cout << "theDistance1 = " << theDistance << "\n";
330  if (theDistance > 0.001 && theDistance < minHitIsolation_) return false;
331  }
332 
333  // FIXME: see above
334  for( istripStm=stripcollStm.data().begin(); istripStm!=stripcollStm.data().end(); ++istripStm ) {
335  const SiStripMatchedRecHit2D *aHit = &*(istripStm);
336  DetId mydet2 = aHit->geographicalId();
337  if (idet.rawId() != mydet2.rawId()) continue;
338  float theDistance = (therechit->localPosition() - aHit->localPosition()).mag();
339  // std::cout << "theDistance1 = " << theDistance << "\n";
340  if (theDistance > 0.001 && theDistance < minHitIsolation_) return false;
341  }
342  return true;
343 }
344 //-----------------------------------------------------------------------------
345 
348 {
349  Tracks sortedTracks=tracks;
350  Tracks result;
351 
352  // sort in pt
353  std::sort(sortedTracks.begin(),sortedTracks.end(),ptComparator);
354 
355  // copy theTrackMult highest pt tracks to result vector
356  int n=0;
357  for (Tracks::const_iterator it=sortedTracks.begin();
358  it!=sortedTracks.end(); ++it) {
359  if (n<nHighestPt_) { result.push_back(*it); n++; }
360  }
361 
362  return result;
363 }
364 
type
Definition: HCALResponse.h:21
const edm::InputTag matchedrecHitsTag_
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
std::vector< const reco::Track * > Tracks
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:556
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
SiStripCluster const & monoCluster() const
Tracks select(const Tracks &tracks, const edm::Event &evt) const
select tracks
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:640
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:646
bool isIsolated(const TrackingRecHit *therechit, const edm::Event &evt) const
bool detailedHitsCheck(const reco::Track *track, const edm::Event &evt) const
checking hit requirements beyond simple number of valid hits
virtual int dimension() const =0
double pt() const
track transverse momentum
Definition: TrackBase.h:616
data_type const * data(size_t cell) const
const edm::InputTag rphirecHitsTag_
ClusterRef cluster() const
unsigned short numberOfValidHits() const
number of valid hits found
Definition: TrackBase.h:815
virtual LocalPoint localPosition() const final
bool isOkCharge(const TrackingRecHit *therechit) const
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:104
virtual LocalPoint localPosition() const =0
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:416
const double ptMin_
if true, cut min/maxMultiplicity on input instead of on final result
SiStripRecHit2D originalHit() const
Definition: DetId.h:18
const int kBPIX
const int kFPIX
SiStripCluster const & stereoCluster() const
HLT enums.
Tracks theNHighestPtTracks(const Tracks &tracks) const
filter the n highest pt tracks
bool isHit2D(const TrackingRecHit &hit) const
CalibrationTrackSelector(const edm::ParameterSet &cfg)
constructor
Tracks basicCuts(const Tracks &tracks, const edm::Event &evt) const
apply basic cuts on pt,eta,phi,nhit
DetId geographicalId() const
const std::vector< uint8_t > & amplitudes() const
TrackingRecHitCollection::base::const_iterator trackingRecHit_iterator
iterator over a vector of reference to TrackingRecHit in the same collection
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:109