CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  virtual void beginJob() ;
32  virtual bool filter(edm::Event&, const edm::EventSetup&);
33  virtual void endJob() ;
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  : inputTagPFCandidates_ (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 
90 
91  bool foundMuon = false;
92 
93  auto_ptr< reco::PFCandidateCollection >
94  pOutputCandidateCollection( new reco::PFCandidateCollection );
95 
96  for( unsigned i=0; i<pfCandidates->size(); i++ ) {
97 
98  const reco::PFCandidate & cand = (*pfCandidates)[i];
99 
100 // if( cand.particleId() != 3 ) // not a muon
101  if( cand.particleId() != reco::PFCandidate::mu ) // not a muon
102  continue;
103 
104  if(!PFMuonAlgo::isIsolatedMuon( cand.muonRef() ) ) // muon is not isolated
105  continue;
106 
107  double totalCaloEnergy = cand.rawEcalEnergy() + cand.rawHcalEnergy();
108  double eOverP = totalCaloEnergy/cand.p();
109 
110  if( eOverP < eOverPMax_ )
111  continue;
112 
113  foundMuon = true;
114 
115  pOutputCandidateCollection->push_back( cand );
116 
117  if( debug_ ) {
118  cout<<cand<<" HCAL E="<<endl;
119  cout<<"\t"<<"ECAL energy "<<cand.rawEcalEnergy()<<endl;
120  cout<<"\t"<<"HCAL energy "<<cand.rawHcalEnergy()<<endl;
121  cout<<"\t"<<"E/p "<<eOverP<<endl;
122  }
123  }
124 
125  iEvent.put( pOutputCandidateCollection, "muons" );
126 
127  bool pass = !foundMuon;
128 
129  iEvent.put( std::auto_ptr<bool>(new bool(pass)) );
130 
131  return taggingMode_ || pass;
132 
133 }
134 
135 // ------------ method called once each job just before starting event loop ------------
136 void
138 {
139 }
140 
141 // ------------ method called once each job just after ending the event loop ------------
142 void
144 }
145 
146 //define this as a plug-in
static bool isIsolatedMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:76
int i
Definition: DBlmapReader.cc:9
virtual double p() const
magnitude of momentum vector
double rawEcalEnergy() const
return corrected Ecal energy
Definition: PFCandidate.h:192
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< PFCandidatePtr > pfCandidates(const PFJet &jet, int particleId, bool sort=true)
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:355
virtual bool filter(edm::Event &, const edm::EventSetup &)
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
GreedyMuonPFCandidateFilter(const edm::ParameterSet &)
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:33
tuple cout
Definition: gather_cfg.py:121
virtual ParticleType particleId() const
Definition: PFCandidate.h:324
double rawHcalEnergy() const
return raw Hcal energy
Definition: PFCandidate.h:202