CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonBadTrackFilter.cc
Go to the documentation of this file.
1 
2 
3 
4 // system include files
5 #include <memory>
6 #include <iostream>
7 
8 // user include files
11 
14 
16 
23 
24 //
25 // class declaration
26 //
27 
29 public:
30  explicit MuonBadTrackFilter(const edm::ParameterSet&);
32 
33 private:
34  virtual bool filter(edm::StreamID iID, edm::Event&, const edm::EventSetup&) const override;
35  virtual std::string trackInfo(const reco::TrackRef& trackRef) const;
36  virtual void printMuonProperties(const reco::MuonRef& muonRef) const;
37 
38  // ----------member data ---------------------------
39 
41  const bool taggingMode_;
42  const double ptMin_;
43  const double chi2Min_;
44  const double p1_;
45  const double p2_;
46  const double p3_;
47  const bool debug_;
48 
49 };
50 
51 //
52 // constants, enums and typedefs
53 //
54 
55 //
56 // static data member definitions
57 //
58 
59 //
60 // constructors and destructor
61 //
63  : tokenPFCandidates_ ( consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag> ("PFCandidates") ))
64  , taggingMode_ ( iConfig.getParameter<bool> ("taggingMode") )
65  , ptMin_ ( iConfig.getParameter<double> ("ptMin") )
66  , chi2Min_ ( iConfig.getParameter<double> ("chi2Min") )
67  , p1_ ( iConfig.getParameter<double> ("p1") )
68  , p2_ ( iConfig.getParameter<double> ("p2") )
69  , p3_ ( iConfig.getParameter<double> ("p3") )
70  , debug_ ( iConfig.getParameter<bool> ("debug") )
71 {
72  produces<bool>();
73 }
74 
76 
77 
78 //
79 // member functions
80 //
81 
82 // ------------ method called on each new Event ------------
83 bool
85 {
86  using namespace std;
87  using namespace edm;
88 
91 
92  bool foundBadTrack = false;
93 
94  for ( unsigned i=0; i<pfCandidates->size(); ++i ) {
95 
96  const reco::PFCandidate & cand = (*pfCandidates)[i];
97 
98  if ( std::abs(cand.pdgId()) != 13 ) continue;
99 
100  if (cand.pt() < ptMin_) continue;
101 
102  if (cand.muonRef().isNull()) continue;
103 
104  const reco::MuonRef muon = cand.muonRef();
105  if ( debug_ ) printMuonProperties(muon);
106 
107  if (muon->muonBestTrack().isAvailable()) {
108  if (muon->muonBestTrack()->hitPattern().numberOfValidMuonHits() == 0) {
109 
110  if (muon->globalTrack().isAvailable()) {
111  if (muon->globalTrack()->normalizedChi2() > chi2Min_) {
112  foundBadTrack = true;
113  if ( debug_ ) cout << "globalTrack numberOfValidMuonHits: " << muon->globalTrack()->hitPattern().numberOfValidMuonHits() <<
114  " numberOfValidMuonCSCHits: " << muon->globalTrack()->hitPattern().numberOfValidMuonCSCHits() <<
115  " numberOfValidMuonDTHits: " << muon->globalTrack()->hitPattern().numberOfValidMuonDTHits() <<
116  " normalizedChi2: " << muon->globalTrack()->normalizedChi2() << endl;
117  if ( debug_ ) cout << "muonBestTrack numberOfValidMuonHits: " << muon->muonBestTrack()->hitPattern().numberOfValidMuonHits() <<
118  " numberOfValidMuonCSCHits: " << muon->muonBestTrack()->hitPattern().numberOfValidMuonCSCHits() <<
119  " numberOfValidMuonDTHits: " << muon->muonBestTrack()->hitPattern().numberOfValidMuonDTHits() <<
120  " normalizedChi2: " << muon->muonBestTrack()->normalizedChi2() << endl;
121  }
122  }
123 
124  }
125  }
126 
127  // perform same check as for charged hadrons
128  if (!cand.trackRef().isNull()) {
129 
130  const reco::TrackRef trackref = cand.trackRef();
131  const double Pt = trackref->pt();
132  const double DPt = trackref->ptError();
133  const double P = trackref->p();
134  const unsigned int LostHits = trackref->numberOfLostHits();
135 
136  if ((DPt/Pt) > (p1_ * sqrt(p2_*p2_/P+p3_*p3_) / (1.+LostHits))) {
137 
138  foundBadTrack = true;
139 
140  if ( debug_ ) {
141  cout << cand << endl;
142  cout << "muon \t" << "track pT = " << Pt << " +/- " << DPt;
143  cout << endl;
144  }
145  }
146  }
147 
148  // check if at least one track has good quality
149  if (muon->innerTrack().isAvailable()) {
150  const double P = muon->innerTrack()->p();
151  const double DPt = muon->innerTrack()->ptError();
152  if (P != 0) {
153  if ( debug_ ) cout << "innerTrack DPt/P: " << DPt/P << endl;
154  if (DPt/P < 1) {
155  if ( debug_ ) cout << "innerTrack good" << endl;
156  continue;
157  }
158  }
159  }
160  if (muon->pickyTrack().isAvailable()) {
161  const double P = muon->pickyTrack()->p();
162  const double DPt = muon->pickyTrack()->ptError();
163  if (P != 0) {
164  if ( debug_ ) cout << "pickyTrack DPt/P: " << DPt/P << endl;
165  if (DPt/P < 1) {
166  if ( debug_ ) cout << "pickyTrack good" << endl;
167  continue;
168  }
169  }
170  }
171  if (muon->globalTrack().isAvailable()) {
172  const double P = muon->globalTrack()->p();
173  const double DPt = muon->globalTrack()->ptError();
174  if (P != 0) {
175  if ( debug_ ) cout << "globalTrack DPt/P: " << DPt/P << endl;
176  if (DPt/P < 1) {
177  if ( debug_ ) cout << "globalTrack good" << endl;
178  continue;
179  }
180  }
181  }
182  if (muon->tpfmsTrack().isAvailable()) {
183  const double P = muon->tpfmsTrack()->p();
184  const double DPt = muon->tpfmsTrack()->ptError();
185  if (P != 0) {
186  if ( debug_ ) cout << "tpfmsTrack DPt/P: " << DPt/P << endl;
187  if (DPt/P < 1) {
188  if ( debug_ ) cout << "tpfmsTrack good" << endl;
189  continue;
190  }
191  }
192  }
193  if (muon->dytTrack().isAvailable()) {
194  const double P = muon->dytTrack()->p();
195  const double DPt = muon->dytTrack()->ptError();
196  if (P != 0) {
197  if ( debug_ ) cout << "dytTrack DPt/P: " << DPt/P << endl;
198  if (DPt/P < 1) {
199  if ( debug_ ) cout << "dytTrack good" << endl;
200  continue;
201  }
202  }
203  }
204  if ( debug_ ) cout << "No tracks are good" << endl;
205  foundBadTrack = true;
206 
207 
208  } // end loop over PF candidates
209 
210 
211  bool pass = !foundBadTrack;
212 
213  iEvent.put( std::auto_ptr<bool>(new bool(pass)) );
214 
215  return taggingMode_ || pass;
216 }
217 
218 
220 
221  std::ostringstream out;
222 
223  if(trackRef.isNull()) {
224  out << "track ref not set";
225  }
226  else if (! trackRef.isAvailable()) {
227  out << "track ref not available";
228  }
229  else {
230  const reco::Track& track = *trackRef;
231  out << "pt = " << track.pt() << " +- " << track.ptError()/track.pt()
232  << " chi2 = " << track.normalizedChi2()
233  << "; Muon Hits: " << track.hitPattern().numberOfValidMuonHits()
234  << "/" << track.hitPattern().numberOfLostMuonHits()
235  << " (DT: " << track.hitPattern().numberOfValidMuonDTHits()
236  << "/" << track.hitPattern().numberOfLostMuonDTHits()
237  << " CSC: " << track.hitPattern().numberOfValidMuonCSCHits()
238  << "/" << track.hitPattern().numberOfLostMuonCSCHits()
239  << " RPC: " << track.hitPattern().numberOfValidMuonRPCHits()
240  << "/" << track.hitPattern().numberOfLostMuonRPCHits() << ")"
241  << "; Valid inner hits:"
242  << " TRK: " << track.hitPattern().numberOfValidTrackerHits()
243  << " PIX: " << track.hitPattern().numberOfValidPixelHits();
244  }
245  return out.str();
246 }
247 
248 
250 
251  if ( !muonRef.isNonnull() ) return;
252 
253  bool isGL = muonRef->isGlobalMuon();
254  bool isTR = muonRef->isTrackerMuon();
255  bool isST = muonRef->isStandAloneMuon();
256  bool isTPFMS = muonRef->tpfmsTrack().isNonnull() && muonRef->tpfmsTrack()->pt()>0;
257  bool isPicky = muonRef->pickyTrack().isNonnull() && muonRef->pickyTrack()->pt()>0;
258  bool isDyt = muonRef->dytTrack().isNonnull() && muonRef->dytTrack()->pt()>0;
259 
260  reco::Muon::MuonTrackType tunePType = muonRef->tunePMuonBestTrackType();
261  std::string tunePTypeStr;
262  switch( tunePType ){
263  case reco::Muon::InnerTrack: tunePTypeStr = "Inner"; break;
264  case reco::Muon::OuterTrack: tunePTypeStr = "Outer"; break;
265  case reco::Muon::CombinedTrack: tunePTypeStr = "Combined"; break;
266  case reco::Muon::TPFMS: tunePTypeStr = "TPFMS"; break;
267  case reco::Muon::Picky: tunePTypeStr = "Picky"; break;
268  case reco::Muon::DYT: tunePTypeStr = "DYT"; break;
269  default:tunePTypeStr = "unknow"; break;
270  }
271 
272  std::cout<<"pt " << muonRef->pt()
273  <<" eta " << muonRef->eta()
274  <<" GL: "<<isGL
275  <<" TR: "<<isTR
276  <<" ST: "<<isST
277  <<" TPFMS: "<<isTPFMS
278  <<" Picky: "<<isPicky
279  <<" DYT: "<<isDyt
280  <<" TuneP: "<<tunePTypeStr
281  <<" nMatches "<<muonRef->numberOfMatches()<<std::endl;
282 
283  if ( isGL ) {
284  std::cout<<"\tCombined "<<trackInfo(muonRef->combinedMuon())<<std::endl;
285  std::cout<<"\tInner "<<trackInfo(muonRef->innerTrack())<<std::endl;
286  }
287 
288  if ( isST ) {
289  std::cout<<"\tOuter "<<trackInfo(muonRef->standAloneMuon())<<std::endl;
290  }
291 
292  if ( isTR ){
293  reco::TrackRef trackerMu = muonRef->innerTrack();
294  // const reco::Track& track = *trackerMu;
295  std::cout<<"\tInner "<<trackInfo(trackerMu)<<std::endl;
296  std::cout<< "\t\tTMLastStationAngLoose "
297  << muon::isGoodMuon(*muonRef,muon::TMLastStationAngLoose) << std::endl
298  << "\t\tTMLastStationAngTight "
299  << muon::isGoodMuon(*muonRef,muon::TMLastStationAngTight) << std::endl
300  << "\t\tTMLastStationLoose "
301  << muon::isGoodMuon(*muonRef,muon::TMLastStationLoose) << std::endl
302  << "\t\tTMLastStationTight "
303  << muon::isGoodMuon(*muonRef,muon::TMLastStationTight) << std::endl
304  << "\t\tTMOneStationLoose "
305  << muon::isGoodMuon(*muonRef,muon::TMOneStationLoose) << std::endl
306  << "\t\tTMOneStationTight "
307  << muon::isGoodMuon(*muonRef,muon::TMOneStationTight) << std::endl
308  << "\t\tTMLastStationOptimizedLowPtLoose "
310  << "\t\tTMLastStationOptimizedLowPtTight "
312  << "\t\tTMLastStationOptimizedBarrelLowPtLoose "
314  << "\t\tTMLastStationOptimizedBarrelLowPtTight "
316  << std::endl;
317  }
318 
319  if( isPicky ) {
320  std::cout<<"\tPicky "<<trackInfo(muonRef->pickyTrack())<<std::endl;
321  }
322 
323  if( isDyt ) {
324  std::cout<<"\tDyt "<<trackInfo(muonRef->dytTrack())<<std::endl;
325  }
326 
327  if( isTPFMS ) {
328  std::cout<<"\tTPFMS "<<trackInfo(muonRef->tpfmsTrack())<<std::endl;
329  }
330 
331  std::cout<< "TM2DCompatibilityLoose "
332  << muon::isGoodMuon(*muonRef,muon::TM2DCompatibilityLoose) << std::endl
333  << "TM2DCompatibilityTight "
334  << muon::isGoodMuon(*muonRef,muon::TM2DCompatibilityTight) << std::endl;
335 
336  if ( muonRef->isGlobalMuon()
337  && muonRef->isTrackerMuon()
338  && muonRef->isStandAloneMuon() ) {
339  reco::TrackRef combinedMu = muonRef->combinedMuon();
340  reco::TrackRef trackerMu = muonRef->track();
341  reco::TrackRef standAloneMu = muonRef->standAloneMuon();
342 
343  double sigmaCombined = combinedMu->ptError()/(combinedMu->pt()*combinedMu->pt());
344  double sigmaTracker = trackerMu->ptError()/(trackerMu->pt()*trackerMu->pt());
345  double sigmaStandAlone = standAloneMu->ptError()/(standAloneMu->pt()*standAloneMu->pt());
346 
347  bool combined = combinedMu->ptError()/combinedMu->pt() < 0.20;
348  bool tracker = trackerMu->ptError()/trackerMu->pt() < 0.20;
349  bool standAlone = standAloneMu->ptError()/standAloneMu->pt() < 0.20;
350 
351  double delta1 = combined && tracker ?
352  fabs(1./combinedMu->pt() -1./trackerMu->pt())
353  /sqrt(sigmaCombined*sigmaCombined + sigmaTracker*sigmaTracker) : 100.;
354  double delta2 = combined && standAlone ?
355  fabs(1./combinedMu->pt() -1./standAloneMu->pt())
356  /sqrt(sigmaCombined*sigmaCombined + sigmaStandAlone*sigmaStandAlone) : 100.;
357 
358  double delta3 = standAlone && tracker ?
359  fabs(1./standAloneMu->pt() -1./trackerMu->pt())
360  /sqrt(sigmaStandAlone*sigmaStandAlone + sigmaTracker*sigmaTracker) : 100.;
361 
362  double delta =
363  standAloneMu->hitPattern().numberOfValidMuonDTHits()+
364  standAloneMu->hitPattern().numberOfValidMuonCSCHits() > 0 ?
365  std::min(delta3,std::min(delta1,delta2)) : std::max(delta3,std::max(delta1,delta2));
366 
367  std::cout << "delta = " << delta << " delta1 "<<delta1<<" delta2 "<<delta2<<" delta3 "<<delta3<<std::endl;
368 
369  double ratio =
370  combinedMu->ptError()/combinedMu->pt()
371  / (trackerMu->ptError()/trackerMu->pt());
372  //if ( ratio > 2. && delta < 3. ) std::cout << "ALARM ! " << ratio << ", " << delta << std::endl;
373  std::cout<<" ratio "<<ratio<<" combined mu pt "<<combinedMu->pt()<<std::endl;
374  //bool quality3 = ( combinedMu->pt() < 50. || ratio < 2. ) && delta < 3.;
375  }
376 
377  double sumPtR03 = muonRef->isolationR03().sumPt;
378  double emEtR03 = muonRef->isolationR03().emEt;
379  double hadEtR03 = muonRef->isolationR03().hadEt;
380  double relIsoR03 = (sumPtR03 + emEtR03 + hadEtR03)/muonRef->pt();
381  double sumPtR05 = muonRef->isolationR05().sumPt;
382  double emEtR05 = muonRef->isolationR05().emEt;
383  double hadEtR05 = muonRef->isolationR05().hadEt;
384  double relIsoR05 = (sumPtR05 + emEtR05 + hadEtR05)/muonRef->pt();
385  std::cout<<" 0.3 Rel Iso: "<<relIsoR03<<" sumPt "<<sumPtR03<<" emEt "<<emEtR03<<" hadEt "<<hadEtR03<<std::endl;
386  std::cout<<" 0.5 Rel Iso: "<<relIsoR05<<" sumPt "<<sumPtR05<<" emEt "<<emEtR05<<" hadEt "<<hadEtR05<<std::endl;
387  return;
388 }
389 
390 
391 //define this as a plug-in
dbl * delta
Definition: mlp_gen.cc:36
bool isAvailable() const
Definition: Ref.h:576
int i
Definition: DBlmapReader.cc:9
virtual int pdgId() const
PDG identifier.
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
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:548
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
#define P
virtual std::string trackInfo(const reco::TrackRef &trackRef) const
int numberOfLostMuonHits() const
Definition: HitPattern.h:886
virtual double pt() const
transverse momentum
int numberOfValidMuonCSCHits() const
Definition: HitPattern.h:861
int numberOfValidMuonRPCHits() const
Definition: HitPattern.h:866
std::vector< PFCandidatePtr > pfCandidates(const PFJet &jet, int particleId, bool sort=true)
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:433
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
MuonBadTrackFilter(const edm::ParameterSet &)
T sqrt(T t)
Definition: SSEVec.h:48
double pt() const
track transverse momentum
Definition: TrackBase.h:608
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Definition: TrackBase.h:750
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
T min(T a, T b)
Definition: MathUtil.h:58
int numberOfLostMuonRPCHits() const
Definition: HitPattern.h:941
bool isNull() const
Checks for null.
Definition: Ref.h:249
bool isGoodMuon(const reco::Muon &muon, SelectionType type, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
main GoodMuon wrapper call
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:450
tuple out
Definition: dbtoconf.py:99
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:437
int numberOfValidTrackerHits() const
Definition: HitPattern.h:806
virtual void printMuonProperties(const reco::MuonRef &muonRef) const
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:39
int numberOfLostMuonDTHits() const
Definition: HitPattern.h:931
edm::EDGetTokenT< reco::PFCandidateCollection > tokenPFCandidates_
int numberOfValidMuonDTHits() const
Definition: HitPattern.h:856
int numberOfValidPixelHits() const
Definition: HitPattern.h:816
tuple cout
Definition: gather_cfg.py:121
MuonTrackType
map for Global Muon refitters
Definition: Muon.h:38
virtual bool filter(edm::StreamID iID, edm::Event &, const edm::EventSetup &) const override
int numberOfValidMuonHits() const
Definition: HitPattern.h:811
int numberOfLostMuonCSCHits() const
Definition: HitPattern.h:936