CMS 3D CMS Logo

GreedyMuonPFCandidateFilter.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 
20 
21 //
22 // class declaration
23 //
24 
26 public:
29 
30 private:
31  void beginJob() override ;
32  bool filter(edm::Event&, const edm::EventSetup&) override;
33  void endJob() override ;
34 
36  // ----------member data ---------------------------
37 
38  const double eOverPMax_;
39 
40  const bool debug_;
41 
42  const bool taggingMode_;
43 };
44 
45 //
46 // constants, enums and typedefs
47 //
48 
49 //
50 // static data member definitions
51 //
52 
53 //
54 // constructors and destructor
55 //
57  //now do what ever initialization is needed
58  : tokenPFCandidates_ (consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("PFCandidates") ) )
59  , eOverPMax_ (iConfig.getParameter<double>("eOverPMax") )
60  , debug_ ( iConfig.getParameter<bool>("debug") )
61  , taggingMode_ (iConfig.getParameter<bool>("taggingMode") )
62 {
63  produces<bool>();
64  produces<reco::PFCandidateCollection>("muons");
65 }
66 
67 
69 {
70 
71  // do anything here that needs to be done at desctruction time
72  // (e.g. close files, deallocate resources etc.)
73 
74 }
75 
76 
77 //
78 // member functions
79 //
80 
81 // ------------ method called on each new Event ------------
82 bool
84 {
85  using namespace std;
86  using namespace edm;
87 
89  iEvent.getByToken(tokenPFCandidates_,pfCandidates);
90 
91  bool foundMuon = false;
92 
93  auto pOutputCandidateCollection = std::make_unique<reco::PFCandidateCollection>();
94 
95  for( unsigned i=0; i<pfCandidates->size(); i++ ) {
96 
97  const reco::PFCandidate & cand = (*pfCandidates)[i];
98 
99 // if( cand.particleId() != 3 ) // not a muon
100  if( cand.particleId() != reco::PFCandidate::mu ) // not a muon
101  continue;
102 
103  if(!PFMuonAlgo::isIsolatedMuon( cand.muonRef() ) ) // muon is not isolated
104  continue;
105 
106  double totalCaloEnergy = cand.rawEcalEnergy() + cand.rawHcalEnergy();
107  double eOverP = totalCaloEnergy/cand.p();
108 
109  if( eOverP < eOverPMax_ )
110  continue;
111 
112  foundMuon = true;
113 
114  pOutputCandidateCollection->push_back( cand );
115 
116  if( debug_ ) {
117  cout<<cand<<" HCAL E="<<endl;
118  cout<<"\t"<<"ECAL energy "<<cand.rawEcalEnergy()<<endl;
119  cout<<"\t"<<"HCAL energy "<<cand.rawHcalEnergy()<<endl;
120  cout<<"\t"<<"E/p "<<eOverP<<endl;
121  }
122  }
123 
124  iEvent.put(std::move(pOutputCandidateCollection), "muons");
125 
126  bool pass = !foundMuon;
127 
128  iEvent.put(std::make_unique<bool>(pass));
129 
130  return taggingMode_ || pass;
131 
132 }
133 
134 // ------------ method called once each job just before starting event loop ------------
135 void
137 {
138 }
139 
140 // ------------ method called once each job just after ending the event loop ------------
141 void
143 }
144 
145 //define this as a plug-in
static bool isIsolatedMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:137
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
double rawEcalEnergy() const
return corrected Ecal energy
Definition: PFCandidate.h:225
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::EDGetTokenT< reco::PFCandidateCollection > tokenPFCandidates_
bool filter(edm::Event &, const edm::EventSetup &) override
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:459
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
double p() const final
magnitude of momentum vector
GreedyMuonPFCandidateFilter(const edm::ParameterSet &)
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
double rawHcalEnergy() const
return raw Hcal energy
Definition: PFCandidate.h:235