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++) {
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
134  if (pf->particleId() == reco::PFCandidate::h || pf->particleId() == reco::PFCandidate::e ||
135  pf->particleId() == reco::PFCandidate::mu) {
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
148  } else if (pf->particleId() == reco::PFCandidate::gamma || pf->particleId() == reco::PFCandidate::egamma_HF) {
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) {
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 
MuonAlignmentFromReference_cff.newmuons
newmuons
Definition: MuonAlignmentFromReference_cff.py:26
Handle.h
MuonWithPFIsoProducer::gammaIsoVeto_
double gammaIsoVeto_
Definition: MuonWithPFIsoProducer.cc:32
mps_fire.i
i
Definition: mps_fire.py:355
Muon.h
MuonWithPFIsoProducer::MuonWithPFIsoProducer
MuonWithPFIsoProducer(const edm::ParameterSet &)
Definition: MuonWithPFIsoProducer.cc:45
MessageLogger.h
EDProducer.h
reco::PFCandidate::e
Definition: PFCandidate.h:46
PFCandidate.h
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
reco::MuonIsolation::emEt
float emEt
ecal sum-Et
Definition: MuonIsolation.h:7
VectorUtil.h
edm::EDGetTokenT
Definition: EDGetToken.h:33
reco::PFCandidate::h
Definition: PFCandidate.h:45
reco::PFCandidate::h_HF
Definition: PFCandidate.h:50
edm::Handle
Definition: AssociativeIterator.h:50
reco::Muon::setIsolation
void setIsolation(const MuonIsolation &isoR03, const MuonIsolation &isoR05)
reco::MuonIsolation
Definition: MuonIsolation.h:5
reco::Muon
Definition: Muon.h:27
edm::Ref< TrackCollection >
MakerMacros.h
reco::MuonIsolation::sumPt
float sumPt
sum-pt of tracks
Definition: MuonIsolation.h:6
Track.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
reco::PFCandidate::mu
Definition: PFCandidate.h:47
MuonWithPFIsoProducer::beginJob
void beginJob() override
Definition: MuonWithPFIsoProducer.cc:70
MuonFwd.h
reco::MuonCollection
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
ResolutionFunction.h
MuonWithPFIsoProducer::muonToken_
edm::EDGetTokenT< edm::View< reco::Muon > > muonToken_
Definition: MuonWithPFIsoProducer.cc:26
MuonWithPFIsoProducer::pfToken_
edm::EDGetTokenT< edm::View< reco::PFCandidate > > pfToken_
Definition: MuonWithPFIsoProducer.cc:27
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
Event.h
reco::MuonIsolation::hadVetoEt
float hadVetoEt
hcal sum-et in the veto region in r-phi
Definition: MuonIsolation.h:14
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
MuonWithPFIsoProducer::trackIsoVeto_
double trackIsoVeto_
Definition: MuonWithPFIsoProducer.cc:31
reco::PFCandidate::egamma_HF
Definition: PFCandidate.h:51
reco::PFCandidate::gamma
Definition: PFCandidate.h:48
reco::MuonIsolation::nTracks
int nTracks
number of tracks in the cone (excluding veto region)
Definition: MuonIsolation.h:10
edm::EventSetup
Definition: EventSetup.h:57
MuonWithPFIsoProducer::endJob
void endJob() override
Definition: MuonWithPFIsoProducer.cc:73
pdwgLeptonRecoSkim_cfi.muonCollection
muonCollection
Definition: pdwgLeptonRecoSkim_cfi.py:7
reco::MuonIsolation::emVetoEt
float emVetoEt
ecal sum-et in the veto region in r-phi
Definition: MuonIsolation.h:13
MuonWithPFIsoProducer::neutralHadronIsoVeto_
double neutralHadronIsoVeto_
Definition: MuonWithPFIsoProducer.cc:33
eostools.move
def move(src, dest)
Definition: eostools.py:511
reco::MuonIsolation::hadEt
float hadEt
hcal sum-Et
Definition: MuonIsolation.h:8
Frameworkfwd.h
packedPFCandidateRefMixer_cfi.pf
pf
Definition: packedPFCandidateRefMixer_cfi.py:4
reco::PFCandidate::h0
Definition: PFCandidate.h:49
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
reco::MuonIsolation::trackerVetoPt
float trackerVetoPt
(sum-)pt inside the veto region in r-phi
Definition: MuonIsolation.h:12
edm::EDProducer
Definition: EDProducer.h:36
edm::RefToBase
Definition: AssociativeIterator.h:54
MuonWithPFIsoProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: MuonWithPFIsoProducer.cc:76
View.h
MuonWithPFIsoProducer::~MuonWithPFIsoProducer
~MuonWithPFIsoProducer() override
Definition: MuonWithPFIsoProducer.cc:67
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
MuonWithPFIsoProducer
Definition: MuonWithPFIsoProducer.cc:16
MomentumScaleCorrector.h
edm::InputTag
Definition: InputTag.h:15
MuonWithPFIsoProducer::usePfMuonsOnly_
bool usePfMuonsOnly_
Definition: MuonWithPFIsoProducer.cc:29
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27