1 |
// -*- C++ -*-
|
2 |
//
|
3 |
// Package: HadronicVariableComputer
|
4 |
// Class: HadronicVariableComputer
|
5 |
//
|
6 |
/**\class HadronicVariableComputer HadronicVariableComputer.cc Gio/HadronicVariableComputer/src/HadronicVariableComputer.cc
|
7 |
|
8 |
Description: <one line class summary>
|
9 |
|
10 |
Implementation:
|
11 |
<Notes on implementation>
|
12 |
*/
|
13 |
//
|
14 |
// Original Author: Jun 20 11:36 (85-18-136-104.fastres.net)
|
15 |
// Created: Fri Jun 20 11:41:35 CEST 2008
|
16 |
// $Id: HadronicVariableComputer.cc,v 1.1 2009/09/05 17:14:35 gpetrucc Exp $
|
17 |
//
|
18 |
//
|
19 |
|
20 |
|
21 |
// system include files
|
22 |
#include <memory>
|
23 |
|
24 |
// user include files
|
25 |
#include "FWCore/Framework/interface/Frameworkfwd.h"
|
26 |
#include "FWCore/Framework/interface/EDProducer.h"
|
27 |
|
28 |
#include "FWCore/Framework/interface/Event.h"
|
29 |
#include "FWCore/Framework/interface/MakerMacros.h"
|
30 |
|
31 |
#include "FWCore/ParameterSet/interface/ParameterSet.h"
|
32 |
#include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h"
|
33 |
#include "DataFormats/HepMCCandidate/interface/GenParticle.h"
|
34 |
#include "DataFormats/Common/interface/View.h"
|
35 |
#include "DataFormats/Common/interface/ValueMap.h"
|
36 |
#include "DataFormats/Math/interface/deltaR.h"
|
37 |
#include "DataFormats/MuonReco/interface/MuonFwd.h"
|
38 |
#include "DataFormats/MuonReco/interface/Muon.h"
|
39 |
//#include "DataFormats/JetReco/interface/Jet.h"
|
40 |
#include "DataFormats/PatCandidates/interface/Jet.h"
|
41 |
#include "CommonTools/Utils/interface/StringCutObjectSelector.h"
|
42 |
//
|
43 |
// class decleration
|
44 |
//
|
45 |
|
46 |
class HadronicVariableComputer : public edm::EDProducer {
|
47 |
public:
|
48 |
explicit HadronicVariableComputer(const edm::ParameterSet&);
|
49 |
~HadronicVariableComputer();
|
50 |
|
51 |
|
52 |
private:
|
53 |
virtual void beginJob(const edm::EventSetup&) ;
|
54 |
virtual void produce(edm::Event&, const edm::EventSetup&);
|
55 |
virtual void endJob() ;
|
56 |
|
57 |
// ----------member data ---------------------------
|
58 |
edm::InputTag muons_;
|
59 |
edm::InputTag jets_;
|
60 |
StringCutObjectSelector<pat::Jet> cut_;
|
61 |
double deltaR_;
|
62 |
|
63 |
const pat::Jet *findNear(const reco::Candidate &muon, const edm::View<pat::Jet> &jets, bool nearest) const ;
|
64 |
std::pair<float,int> findInPhi(const edm::View<pat::Jet> &jets, double phi, double phiRange) const ;
|
65 |
|
66 |
/// Write a ValueMap<int> in the event
|
67 |
template<typename T>
|
68 |
void writeValueMap(edm::Event &iEvent,
|
69 |
const edm::Handle<edm::View<reco::Candidate> > & handle,
|
70 |
const std::vector<T> & values,
|
71 |
const std::string & label) const ;
|
72 |
|
73 |
|
74 |
};
|
75 |
|
76 |
//
|
77 |
// constructors and destructor
|
78 |
//
|
79 |
HadronicVariableComputer::HadronicVariableComputer(const edm::ParameterSet& iConfig) :
|
80 |
muons_(iConfig.getParameter<edm::InputTag>("muons")),
|
81 |
jets_(iConfig.getParameter<edm::InputTag>("jets")),
|
82 |
cut_(iConfig.getParameter<std::string>("cut")),
|
83 |
deltaR_(iConfig.getParameter<double>("deltaR"))
|
84 |
{
|
85 |
produces<edm::ValueMap<float> >("ptrelNearest");
|
86 |
produces<edm::ValueMap<float> >("ptrelHardest");
|
87 |
produces<edm::ValueMap<float> >("ptjetNearest");
|
88 |
produces<edm::ValueMap<float> >("ptjetHardest");
|
89 |
produces<edm::ValueMap<float> >("drNearest");
|
90 |
produces<edm::ValueMap<float> >("drHardest");
|
91 |
produces<edm::ValueMap<float> >("hardestSame");
|
92 |
produces<edm::ValueMap<float> >("hardestOppo");
|
93 |
produces<edm::ValueMap<int> >("countSame");
|
94 |
produces<edm::ValueMap<int> >("countOppo");
|
95 |
|
96 |
produces<edm::ValueMap<float> >("btagTCPNearest");
|
97 |
produces<edm::ValueMap<float> >("btagTCENearest");
|
98 |
produces<edm::ValueMap<float> >("btagJPNearest");
|
99 |
produces<edm::ValueMap<float> >("btagJPBNearest");
|
100 |
produces<edm::ValueMap<float> >("btagSSVNearest");
|
101 |
produces<edm::ValueMap<int> >("mcFlavNearest");
|
102 |
}
|
103 |
|
104 |
|
105 |
HadronicVariableComputer::~HadronicVariableComputer()
|
106 |
{
|
107 |
}
|
108 |
|
109 |
//
|
110 |
// member functions
|
111 |
//
|
112 |
const pat::Jet *
|
113 |
HadronicVariableComputer::findNear(const reco::Candidate &muon, const edm::View<pat::Jet> &jets, bool nearest) const {
|
114 |
const pat::Jet *match = 0;
|
115 |
double val = (nearest ? deltaR_ : nearest);
|
116 |
for (edm::View<pat::Jet>::const_iterator jet = jets.begin(), end = jets.end(); jet != end; ++jet) {
|
117 |
if (!cut_(*jet)) continue;
|
118 |
double dr = ::deltaR(muon, *jet);
|
119 |
if (dr > deltaR_) continue;
|
120 |
if (nearest) {
|
121 |
if (dr < val) { match = &*jet; val = dr; }
|
122 |
} else {
|
123 |
if (jet->pt() > val) { match = &*jet; val = jet->pt(); }
|
124 |
}
|
125 |
}
|
126 |
return match;
|
127 |
}
|
128 |
|
129 |
std::pair<float,int>
|
130 |
HadronicVariableComputer::findInPhi(const edm::View<pat::Jet> &jets, double phi, double phiRange) const {
|
131 |
std::pair<float,int> ret(0,0);
|
132 |
for (edm::View<pat::Jet>::const_iterator jet = jets.begin(), end = jets.end(); jet != end; ++jet) {
|
133 |
if (!cut_(*jet)) continue;
|
134 |
if (std::abs(deltaPhi(phi, jet->phi())) > phiRange) continue;
|
135 |
if (jet->pt() > ret.first) ret.first = jet->pt();
|
136 |
ret.second++;
|
137 |
}
|
138 |
return ret;
|
139 |
}
|
140 |
|
141 |
// ------------ method called to for each event ------------
|
142 |
void
|
143 |
HadronicVariableComputer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
|
144 |
{
|
145 |
using namespace edm;
|
146 |
using namespace std;
|
147 |
Handle<View<reco::Candidate> > muons;
|
148 |
iEvent.getByLabel(muons_, muons);
|
149 |
Handle<View<pat::Jet> > jets;
|
150 |
iEvent.getByLabel(jets_, jets);
|
151 |
|
152 |
const char *rankings[2] = { "Hardest", "Nearest" };
|
153 |
for (int nearest = 0; nearest <= 1; ++nearest) {
|
154 |
vector<float> ptjet(muons->size(), 0);
|
155 |
vector<float> ptrel(muons->size(), 0);
|
156 |
vector<float> dr(muons->size(), 0);
|
157 |
vector<float> btagTCP(muons->size(), -999);
|
158 |
vector<float> btagTCE(muons->size(), -999);
|
159 |
vector<float> btagJP(muons->size(), -999);
|
160 |
vector<float> btagJPB(muons->size(), -999);
|
161 |
vector<float> btagSSV(muons->size(), -999);
|
162 |
vector<int> mcFlav(muons->size(), -1);
|
163 |
for (size_t i = 0; i < muons->size(); ++i) {
|
164 |
const reco::Candidate &mu = (*muons)[i];
|
165 |
const pat::Jet *jet = findNear(mu, *jets, nearest);
|
166 |
if (jet != 0) {
|
167 |
dr[i] = ::deltaR(mu,*jet);
|
168 |
ptjet[i] = jet->pt();
|
169 |
ptrel[i] = mu.momentum().Cross(jet->momentum().Unit()).R();
|
170 |
btagTCP[i] = jet->bDiscriminator("trackCountingHighPurBJetTags");
|
171 |
btagTCE[i] = jet->bDiscriminator("trackCountingHighEffBJetTags");
|
172 |
btagJP[i] = jet->bDiscriminator("jetProbabilityBJetTags");
|
173 |
btagJPB[i] = jet->bDiscriminator("jetBProbabilityBJetTags");
|
174 |
btagSSV[i] = jet->bDiscriminator("simpleSecondaryVertexBJetTags");
|
175 |
mcFlav[i] = jet->partonFlavour();
|
176 |
}
|
177 |
}
|
178 |
writeValueMap<float>(iEvent, muons, dr, std::string("dr")+rankings[nearest]);
|
179 |
writeValueMap<float>(iEvent, muons, ptjet, std::string("ptjet")+rankings[nearest]);
|
180 |
writeValueMap<float>(iEvent, muons, ptrel, std::string("ptrel")+rankings[nearest]);
|
181 |
if (nearest) {
|
182 |
writeValueMap<float>(iEvent, muons, btagTCP, std::string("btagTCP")+rankings[nearest]);
|
183 |
writeValueMap<float>(iEvent, muons, btagTCE, std::string("btagTCE")+rankings[nearest]);
|
184 |
writeValueMap<float>(iEvent, muons, btagJP, std::string("btagJP")+rankings[nearest]);
|
185 |
writeValueMap<float>(iEvent, muons, btagJPB, std::string("btagJPB")+rankings[nearest]);
|
186 |
writeValueMap<float>(iEvent, muons, btagSSV, std::string("btagSSV")+rankings[nearest]);
|
187 |
writeValueMap<int>(iEvent, muons, mcFlav, std::string("mcFlav")+rankings[nearest]);
|
188 |
}
|
189 |
|
190 |
}
|
191 |
|
192 |
const char *sides[2] = { "Same", "Oppo" };
|
193 |
for (int side = 0; side <= 1; ++side) {
|
194 |
vector<float> pt(muons->size(), 0);
|
195 |
vector<int> count(muons->size(), 0);
|
196 |
for (size_t i = 0; i < muons->size(); ++i) {
|
197 |
const reco::Candidate &mu = (*muons)[i];
|
198 |
pair<float,int> result = findInPhi(*jets, mu.phi()+side*M_PI, 0.5*M_PI);
|
199 |
pt[i] = result.first;
|
200 |
count[i] = result.second;
|
201 |
}
|
202 |
|
203 |
writeValueMap<float>(iEvent, muons, pt, std::string("hardest")+sides[side]);
|
204 |
writeValueMap<int>(iEvent, muons, count, std::string("count")+sides[side]);
|
205 |
}
|
206 |
}
|
207 |
|
208 |
|
209 |
// ------------ method called once each job just before starting event loop ------------
|
210 |
void
|
211 |
HadronicVariableComputer::beginJob(const edm::EventSetup&)
|
212 |
{
|
213 |
}
|
214 |
|
215 |
// ------------ method called once each job just after ending the event loop ------------
|
216 |
void
|
217 |
HadronicVariableComputer::endJob() {
|
218 |
}
|
219 |
|
220 |
template<typename T>
|
221 |
void
|
222 |
HadronicVariableComputer::writeValueMap(edm::Event &iEvent,
|
223 |
const edm::Handle<edm::View<reco::Candidate> > & handle,
|
224 |
const std::vector<T> & values,
|
225 |
const std::string & label) const
|
226 |
{
|
227 |
using namespace edm;
|
228 |
using namespace std;
|
229 |
auto_ptr<ValueMap<T> > valMap(new ValueMap<T>());
|
230 |
typename edm::ValueMap<T>::Filler filler(*valMap);
|
231 |
filler.insert(handle, values.begin(), values.end());
|
232 |
filler.fill();
|
233 |
iEvent.put(valMap, label);
|
234 |
}
|
235 |
|
236 |
|
237 |
//define this as a plug-in
|
238 |
DEFINE_FWK_MODULE(HadronicVariableComputer);
|
239 |
|