CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonWithPFIsoProducer.cc
Go to the documentation of this file.
1 #include <memory>
5 
9 
12 
13 //
14 // class declaration
15 //
17  public:
20 
21  private:
22  virtual void beginJob() override ;
23  virtual void produce(edm::Event&, const edm::EventSetup&) override;
24  virtual void endJob() override ;
25 
28 
30 
31  double trackIsoVeto_;
32  double gammaIsoVeto_;
34 };
35 
41 
43 
46 
47  // What is being produced
48  produces<std::vector<reco::Muon> >();
49 
50  // Muon collection
51  muonToken_ = consumes<edm::View<reco::Muon> >(pset.getUntrackedParameter<edm::InputTag> ("MuonTag", edm::InputTag("muons")));
52 
53  // PF candidate collection
54  pfToken_ = consumes<edm::View<reco::PFCandidate> >(pset.getUntrackedParameter<edm::InputTag> ("PFTag", edm::InputTag("particleFlow")));
55 
56  // Use only PF muons to get exact consistency with PfMET
57  usePfMuonsOnly_ = pset.getUntrackedParameter<bool> ("UsePfMuonsOnly", false);
58 
59  // Veto cone
60  trackIsoVeto_ = pset.getUntrackedParameter<double> ("TrackIsoVeto", 0.01);
61  gammaIsoVeto_ = pset.getUntrackedParameter<double> ("GammaIsoVeto", 0.07);
62  neutralHadronIsoVeto_ = pset.getUntrackedParameter<double> ("NeutralHadronIsoVeto", 0.1);
63 
64 }
65 
68 }
69 
72 }
73 
76 }
77 
80 
81  // Initialize pointer to new output muon collection
82  std::auto_ptr<reco::MuonCollection> newmuons (new reco::MuonCollection);
83 
84  // Get Muon collection
85  edm::Handle<edm::View<reco::Muon> > muonCollection;
86  if (!ev.getByToken(muonToken_, muonCollection)) {
87  edm::LogError("") << ">>> Muon collection does not exist !!!";
88  ev.put(newmuons);
89  return;
90  }
91 
92  // Get PFCandidate collection
94  if (!ev.getByToken(pfToken_, pfCollection)) {
95  edm::LogError("") << ">>> PFCandidate collection does not exist !!!";
96  ev.put(newmuons);
97  return;
98  }
99 
100  // Loop over Pf candidates to find muons and collect deposits in veto,
101  // dR<0.3 and dR<0.5 cones. Interpret "track" as charged particles (e,mu,
102  // chraged hadrons). Interpret "em" as photons and also as electromagnetic
103  // energy in HF. Interpret "had" as neutral hadrons and also as hadronic
104  // energy in HF. Apply weights if requested at input level.
105  // HO energies are not filled. Ditto for jet energies around the muon.
106  unsigned int muonCollectionSize = muonCollection->size();
107  unsigned int pfCollectionSize = pfCollection->size();
108  for (unsigned int i=0; i<muonCollectionSize; i++) {
109  edm::RefToBase<reco::Muon> mu = muonCollection->refAt(i);
110 
111  // Ask for PfMuon consistency if requested
112  bool muonFound = false;
113 
114  // Starting bycloning this muon
115  reco::Muon* newmu = mu->clone();
116  reco::TrackRef tk = mu->innerTrack();
117 
118  // Set isolations
119  reco::MuonIsolation iso03;
120  reco::MuonIsolation iso05;
121  // Loop on all candidates
122  for (unsigned int j=0; j<pfCollectionSize; j++) {
123  edm::RefToBase<reco::PFCandidate> pf = pfCollection->refAt(j);
124 
125  // Check the muon is in the PF collection when required
126  bool thisIsTheMuon = false;
127  if (tk.isNonnull() && pf->trackRef()==tk) {
128  thisIsTheMuon = true;
129  muonFound = true;
130  }
131 
132  // Get dR. Nothing to add if dR>0.5
133  double deltaR = Geom::deltaR(mu->momentum(),pf->momentum());
134  if (deltaR>0.5) continue;
135 
136  // Fill "tracker" components
137  if ( pf->particleId()==reco::PFCandidate::h
139  || pf->particleId()==reco::PFCandidate::mu ) {
140  if (deltaR<trackIsoVeto_ || thisIsTheMuon) {
141  iso05.trackerVetoPt += pf->pt();
142  iso03.trackerVetoPt += pf->pt();
143  } else {
144  iso05.sumPt += pf->pt();
145  iso05.nTracks++;
146  if (deltaR<0.3) {
147  iso03.sumPt += pf->pt();
148  iso03.nTracks++;
149  }
150  }
151  // Fill "em" components
152  } else if ( pf->particleId()==reco::PFCandidate::gamma
154  if (deltaR<gammaIsoVeto_) {
155  iso05.emVetoEt += pf->pt();
156  iso03.emVetoEt += pf->pt();
157  } else {
158  iso05.emEt += pf->pt();
159  if (deltaR<0.3) iso03.emEt += pf->pt();
160  }
161  // Fill "had" components
162  } else if ( pf->particleId()==reco::PFCandidate::h0
164  if (deltaR<neutralHadronIsoVeto_) {
165  iso05.hadVetoEt += pf->pt();
166  iso03.hadVetoEt += pf->pt();
167  } else {
168  iso05.hadEt += pf->pt();
169  if (deltaR<0.3) iso03.hadEt += pf->pt();
170  }
171  }
172  }
173 
174  // Do not take this muon (under explicit request) if it is not a PfMuon
175  if (usePfMuonsOnly_ && (!muonFound)) continue;
176 
177  // Set this isolation information in the new muon
178  newmu->setIsolation(iso03,iso05);
179 
180  // Add new muon to output collection
181  newmuons->push_back(*newmu);
182 
183  }
184 
185  // Add output collection to event
186  ev.put(newmuons);
187 }
188 
float hadEt
hcal sum-Et
Definition: MuonIsolation.h:9
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
float sumPt
sum-pt of tracks
Definition: MuonIsolation.h:7
virtual float pt() const
transverse momentum
virtual TrackRef innerTrack() const
Definition: Muon.h:48
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
MuonWithPFIsoProducer(const edm::ParameterSet &)
virtual void beginJob() override
virtual Vector momentum() const
spatial momentum vector
float hadVetoEt
hcal sum-et in the veto region in r-phi
Definition: MuonIsolation.h:15
void setIsolation(const MuonIsolation &isoR03, const MuonIsolation &isoR05)
Definition: Muon.cc:805
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:433
virtual void endJob() override
virtual void produce(edm::Event &, const edm::EventSetup &) override
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
float emEt
ecal sum-Et
Definition: MuonIsolation.h:8
int j
Definition: DBlmapReader.cc:9
const int mu
Definition: Constants.h:22
int nTracks
number of tracks in the cone (excluding veto region)
Definition: MuonIsolation.h:11
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
Muon * clone() const
create a clone
Definition: Muon.cc:44
float emVetoEt
ecal sum-et in the veto region in r-phi
Definition: MuonIsolation.h:14
edm::EDGetTokenT< edm::View< reco::PFCandidate > > pfToken_
virtual ParticleType particleId() const
Definition: PFCandidate.h:368
edm::EDGetTokenT< edm::View< reco::Muon > > muonToken_
float trackerVetoPt
(sum-)pt inside the veto region in r-phi
Definition: MuonIsolation.h:13