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