CMS 3D CMS Logo

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  void beginJob() override ;
34  bool filter(edm::Event&, const edm::EventSetup&) override;
35  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 
83  iEvent.getByToken(tokenPFCandidates_,pfCandidates);
84 
85  bool foundMuon = false;
86 
87  auto pOutputCandidateCollection = std::make_unique<reco::PFCandidateCollection>();
88 
89  for ( unsigned i=0; i<pfCandidates->size(); i++ ) {
90 
91  const reco::PFCandidate & cand = (*pfCandidates)[i];
92 
93  if ( cand.particleId() != reco::PFCandidate::mu ) continue;
94  if ( cand.pt() < ptMin_ ) continue;
95 
96  const reco::MuonRef muon = cand.muonRef();
97  if ( muon->isTrackerMuon()
98  && muon->isGlobalMuon()
99  && fabs(muon->innerTrack()->pt()/muon->globalTrack()->pt() - 1) <= maxPTDiff_
100  )
101  continue;
102 
103  foundMuon = true;
104 
105  pOutputCandidateCollection->push_back( cand );
106 
107  if ( debug_ ) {
108  cout << cand << endl;
109  cout << "\t" << "tracker pT = ";
110  if (muon->isTrackerMuon()) cout << muon->innerTrack()->pt();
111  else cout << "(n/a)";
112  cout << endl;
113  cout << "\t" << "global fit pT = ";
114  if (muon->isGlobalMuon()) cout << muon->globalTrack()->pt();
115  else cout << "(n/a)";
116  cout << endl;
117  }
118  } // end loop over PF candidates
119 
120  iEvent.put(std::move(pOutputCandidateCollection), "muons");
121 
122  bool pass = !foundMuon;
123 
124  iEvent.put(std::make_unique<bool>(pass));
125 
126  return taggingMode_ || pass;
127 }
128 
129 // ------------ method called once each job just before starting event loop ------------
130 void
132 {
133 }
134 
135 // ------------ method called once each job just after ending the event loop ------------
136 void
138 }
139 
140 //define this as a plug-in
edm::EDGetTokenT< reco::PFCandidateCollection > tokenPFCandidates_
bool filter(edm::Event &, const edm::EventSetup &) override
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
InconsistentMuonPFCandidateFilter(const edm::ParameterSet &)
double pt() const final
transverse momentum
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:459
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
fixed size matrix
HLT enums.
virtual ParticleType particleId() const
Definition: PFCandidate.h:374
def move(src, dest)
Definition: eostools.py:511