CMS 3D CMS Logo

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