CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
InconsistentMuonPFCandidateFilter.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 
22 
23 //
24 // class declaration
25 //
26 
28 public:
31 
32 private:
33  virtual void beginJob() override ;
34  virtual bool filter(edm::Event&, const edm::EventSetup&) override;
35  virtual void endJob() override ;
36 
37  // ----------member data ---------------------------
38 
40  const double ptMin_;
41  const double maxPTDiff_;
42 
43  const bool taggingMode_, debug_;
44 };
45 
46 //
47 // constants, enums and typedefs
48 //
49 
50 //
51 // static data member definitions
52 //
53 
54 //
55 // constructors and destructor
56 //
58  : tokenPFCandidates_ ( consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag> ("PFCandidates") ))
59  , ptMin_ ( iConfig.getParameter<double> ("ptMin") )
60  , maxPTDiff_ ( iConfig.getParameter<double> ("maxPTDiff") )
61  , taggingMode_ ( iConfig.getParameter<bool> ("taggingMode") )
62  , debug_ ( iConfig.getParameter<bool> ("debug") )
63 {
64  produces<bool>();
65  produces<reco::PFCandidateCollection>("muons");
66 }
67 
69 
70 
71 //
72 // member functions
73 //
74 
75 // ------------ method called on each new Event ------------
76 bool
78 {
79  using namespace std;
80  using namespace edm;
81 
84 
85  bool foundMuon = false;
86 
87  auto_ptr< reco::PFCandidateCollection >
88  pOutputCandidateCollection( new reco::PFCandidateCollection );
89 
90  for ( unsigned i=0; i<pfCandidates->size(); i++ ) {
91 
92  const reco::PFCandidate & cand = (*pfCandidates)[i];
93 
94  if ( cand.particleId() != reco::PFCandidate::mu ) continue;
95  if ( cand.pt() < ptMin_ ) continue;
96 
97  const reco::MuonRef muon = cand.muonRef();
98  if ( muon->isTrackerMuon()
99  && muon->isGlobalMuon()
100  && fabs(muon->innerTrack()->pt()/muon->globalTrack()->pt() - 1) <= maxPTDiff_
101  )
102  continue;
103 
104  foundMuon = true;
105 
106  pOutputCandidateCollection->push_back( cand );
107 
108  if ( debug_ ) {
109  cout << cand << endl;
110  cout << "\t" << "tracker pT = ";
111  if (muon->isTrackerMuon()) cout << muon->innerTrack()->pt();
112  else cout << "(n/a)";
113  cout << endl;
114  cout << "\t" << "global fit pT = ";
115  if (muon->isGlobalMuon()) cout << muon->globalTrack()->pt();
116  else cout << "(n/a)";
117  cout << endl;
118  }
119  } // end loop over PF candidates
120 
121  iEvent.put( pOutputCandidateCollection, "muons" );
122 
123  bool pass = !foundMuon;
124 
125  iEvent.put( std::auto_ptr<bool>(new bool(pass)) );
126 
127  return taggingMode_ || pass;
128 }
129 
130 // ------------ method called once each job just before starting event loop ------------
131 void
133 {
134 }
135 
136 // ------------ method called once each job just after ending the event loop ------------
137 void
139 }
140 
141 //define this as a plug-in
edm::EDGetTokenT< reco::PFCandidateCollection > tokenPFCandidates_
virtual bool filter(edm::Event &, const edm::EventSetup &) override
int i
Definition: DBlmapReader.cc:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
InconsistentMuonPFCandidateFilter(const edm::ParameterSet &)
virtual double pt() const
transverse momentum
std::vector< PFCandidatePtr > pfCandidates(const PFJet &jet, int particleId, bool sort=true)
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:450
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:39
tuple cout
Definition: gather_cfg.py:121
virtual ParticleType particleId() const
Definition: PFCandidate.h:373