1 |
// $Id: FillerTrackJets.cc,v 1.2 2010/03/18 20:21:01 bendavid Exp $
|
2 |
|
3 |
#include "MitProd/TreeFiller/interface/FillerTrackJets.h"
|
4 |
#include "DataFormats/TrackReco/interface/Track.h"
|
5 |
#include "DataFormats/TrackReco/interface/TrackFwd.h"
|
6 |
#include "DataFormats/JetReco/interface/TrackJet.h"
|
7 |
#include "DataFormats/BTauReco/interface/JetTag.h"
|
8 |
#include "DataFormats/Common/interface/RefToPtr.h"
|
9 |
#include "SimDataFormats/JetMatching/interface/JetFlavour.h"
|
10 |
#include "SimDataFormats/JetMatching/interface/JetFlavourMatching.h"
|
11 |
#include "SimDataFormats/JetMatching/interface/MatchedPartons.h"
|
12 |
#include "SimDataFormats/JetMatching/interface/JetMatchedPartons.h"
|
13 |
#include "JetMETCorrections/Objects/interface/JetCorrector.h"
|
14 |
#include "MitAna/DataTree/interface/Names.h"
|
15 |
#include "MitAna/DataTree/interface/TrackJetCol.h"
|
16 |
#include "MitProd/ObjectService/interface/ObjectService.h"
|
17 |
|
18 |
using namespace std;
|
19 |
using namespace edm;
|
20 |
using namespace mithep;
|
21 |
|
22 |
//--------------------------------------------------------------------------------------------------
|
23 |
FillerTrackJets::FillerTrackJets(const ParameterSet &cfg, const char *name, bool active) :
|
24 |
BaseFiller(cfg,name,active),
|
25 |
flavorMatchingActive_(Conf().getUntrackedParameter<bool>("flavorMatchingActive",true)),
|
26 |
bTaggingActive_(Conf().getUntrackedParameter<bool>("bTaggingActive",true)),
|
27 |
jetToVertexActive_(Conf().getUntrackedParameter<bool>("jetToVertexActive",true)),
|
28 |
jetCorrectionsActive_(Conf().getUntrackedParameter<bool>("jetCorrectionsActive",true)),
|
29 |
edmName_(Conf().getUntrackedParameter<string>("edmName","recoPFJets:iterativeCone5PFJets")),
|
30 |
mitName_(Conf().getUntrackedParameter<string>("mitName","ItrCone5PFJets")),
|
31 |
jetToVertexAlphaName_(Conf().getUntrackedParameter<string>
|
32 |
("jetToVertexAlphaName","jetToVertexAlpha")),
|
33 |
jetToVertexBetaName_(Conf().getUntrackedParameter<string>
|
34 |
("jetToVertexBetaName","jetToVertexBetaName")),
|
35 |
L2JetCorrectorName_(Conf().getUntrackedParameter<string>
|
36 |
("L2JetCorrectorName","L2JetCorrectorName")),
|
37 |
L3JetCorrectorName_(Conf().getUntrackedParameter<string>
|
38 |
("L3JetCorrectorName","L3JetCorrectorName")),
|
39 |
flavorMatchingByReferenceName_(Conf().getUntrackedParameter<string>
|
40 |
("flavorMatchingByReferenceName","srcByReference")),
|
41 |
flavorMatchingDefinition_(Conf().getUntrackedParameter<string>
|
42 |
("flavorMatchingDefinition","Algorithmic")),
|
43 |
jetProbabilityBJetTagsName_(Conf().getUntrackedParameter<string>
|
44 |
("JetProbabilityBJetTagsName","jetProbabilityBJetTags")),
|
45 |
jetBProbabilityBJetTagsName_(Conf().getUntrackedParameter<string>
|
46 |
("JetBProbabilityBJetTagsName","jetBProbabilityBJetTags")),
|
47 |
simpleSecondaryVertexBJetTagsName_(Conf().getUntrackedParameter<string>
|
48 |
("SimpleSecondaryVertexBJetTagsName","simpleSecondaryVertexBJetTags")),
|
49 |
combinedSecondaryVertexBJetTagsName_(Conf().getUntrackedParameter<string>
|
50 |
("CombinedSecondaryVertexBJetTagsName","combinedSecondaryVertexBJetTags")),
|
51 |
combinedSecondaryVertexMVABJetTagsName_(Conf().getUntrackedParameter<string>
|
52 |
("CombinedSecondaryVertexMVABJetTagsName","combinedSecondaryVertexMVABJetTags")),
|
53 |
trackCountingHighEffBJetTagsName_(Conf().getUntrackedParameter<string>
|
54 |
("TrackCountingHighEffBJetTagsName","trackCountingHighEffBJetTags")),
|
55 |
trackCountingHighPurBJetTagsName_(Conf().getUntrackedParameter<string>
|
56 |
("TrackCountingHighPurBJetTagsName","trackCountingHighPurBJetTags")),
|
57 |
softMuonBJetTagsName_(Conf().getUntrackedParameter<string>
|
58 |
("SoftMuonBJetTagsName","softMuonBJetTags")),
|
59 |
softMuonByIP3dBJetTagsName_(Conf().getUntrackedParameter<string>
|
60 |
("SoftMuonByIP3dBJetTagsName","softMuonByIP3dBJetTags")),
|
61 |
softMuonByPtBJetTagsName_(Conf().getUntrackedParameter<string>
|
62 |
("SoftMuonByPtBJetTagsName","softMuonByPtBJetTags")),
|
63 |
softElectronByIP3dBJetTagsName_(Conf().getUntrackedParameter<string>
|
64 |
("SoftElectronByIP3dBJetTagsName","softElectronByIP3dBJetTags")),
|
65 |
softElectronByPtBJetTagsName_(Conf().getUntrackedParameter<string>
|
66 |
("SoftElectronByPtBJetTagsName","softElectronByPtBJetTags")),
|
67 |
trackMapName_(Conf().getUntrackedParameter<string>("trackMapName","trackMapName")),
|
68 |
vertexMapName_(Conf().getUntrackedParameter<string>("vertexMapName","")),
|
69 |
jetMapName_(Conf().getUntrackedParameter<string>("jetMapName","TrackJetMap")),
|
70 |
trackMap_(0),
|
71 |
vertexMap_(0),
|
72 |
jetMap_(new mithep::TrackJetMap),
|
73 |
jets_(new mithep::TrackJetArr(16))
|
74 |
{
|
75 |
// Constructor.
|
76 |
}
|
77 |
|
78 |
//--------------------------------------------------------------------------------------------------
|
79 |
FillerTrackJets::~FillerTrackJets()
|
80 |
{
|
81 |
// Destructor.
|
82 |
|
83 |
delete jets_;
|
84 |
delete jetMap_;
|
85 |
}
|
86 |
|
87 |
//--------------------------------------------------------------------------------------------------
|
88 |
void FillerTrackJets::BookDataBlock(TreeWriter &tws)
|
89 |
{
|
90 |
// Add jets branch to tree.
|
91 |
|
92 |
tws.AddBranch(mitName_,&jets_);
|
93 |
OS()->add<mithep::TrackJetArr>(jets_,mitName_);
|
94 |
|
95 |
if (!trackMapName_.empty()) {
|
96 |
trackMap_ = OS()->get<TrackMap>(trackMapName_);
|
97 |
if (trackMap_)
|
98 |
AddBranchDep(mitName_,trackMap_->GetBrName());
|
99 |
}
|
100 |
if (!vertexMapName_.empty()) {
|
101 |
vertexMap_ = OS()->get<VertexMap>(vertexMapName_);
|
102 |
if (vertexMap_)
|
103 |
AddBranchDep(mitName_,vertexMap_->GetBrName());
|
104 |
}
|
105 |
if (!jetMapName_.empty()) {
|
106 |
jetMap_->SetBrName(mitName_);
|
107 |
OS()->add<TrackJetMap>(jetMap_,jetMapName_);
|
108 |
}
|
109 |
}
|
110 |
|
111 |
//--------------------------------------------------------------------------------------------------
|
112 |
void FillerTrackJets::FillDataBlock(const edm::Event &event,
|
113 |
const edm::EventSetup &setup)
|
114 |
{
|
115 |
// Fill jets from edm collection into our collection.
|
116 |
|
117 |
jets_->Delete();
|
118 |
jetMap_->Reset();
|
119 |
|
120 |
// handle for the Jet Collection
|
121 |
Handle<reco::TrackJetCollection> hJetProduct;
|
122 |
GetProduct(edmName_, hJetProduct, event);
|
123 |
|
124 |
// handles for jet flavour matching
|
125 |
Handle<reco::JetMatchedPartonsCollection> hPartonMatchingProduct;
|
126 |
if (flavorMatchingActive_)
|
127 |
GetProduct(flavorMatchingByReferenceName_, hPartonMatchingProduct, event);
|
128 |
|
129 |
Handle<reco::JetTagCollection> hJetProbabilityBJetTags;
|
130 |
Handle<reco::JetTagCollection> hJetBProbabilityBJetTags;
|
131 |
Handle<reco::JetTagCollection> hSimpleSecondaryVertexBJetTags;
|
132 |
Handle<reco::JetTagCollection> hCombinedSecondaryVertexBJetTags;
|
133 |
Handle<reco::JetTagCollection> hCombinedSecondaryVertexMVABJetTags;
|
134 |
Handle<reco::JetTagCollection> hTrackCountingHighEffBJetTags;
|
135 |
Handle<reco::JetTagCollection> hTrackCountingHighPurBJetTags;
|
136 |
Handle<reco::JetTagCollection> hSoftMuonBJetTags;
|
137 |
Handle<reco::JetTagCollection> hSoftMuonByIP3dBJetTags;
|
138 |
Handle<reco::JetTagCollection> hSoftMuonByPtBJetTags;
|
139 |
Handle<reco::JetTagCollection> hSoftElectronByIP3dBJetTags;
|
140 |
Handle<reco::JetTagCollection> hSoftElectronByPtBJetTags;
|
141 |
|
142 |
if (bTaggingActive_) {
|
143 |
GetProduct(jetProbabilityBJetTagsName_, hJetProbabilityBJetTags, event);
|
144 |
GetProduct(jetBProbabilityBJetTagsName_, hJetBProbabilityBJetTags, event);
|
145 |
GetProduct(simpleSecondaryVertexBJetTagsName_, hSimpleSecondaryVertexBJetTags, event);
|
146 |
GetProduct(combinedSecondaryVertexBJetTagsName_, hCombinedSecondaryVertexBJetTags, event);
|
147 |
GetProduct(combinedSecondaryVertexMVABJetTagsName_, hCombinedSecondaryVertexMVABJetTags, event);
|
148 |
GetProduct(trackCountingHighEffBJetTagsName_, hTrackCountingHighEffBJetTags, event);
|
149 |
GetProduct(trackCountingHighPurBJetTagsName_, hTrackCountingHighPurBJetTags, event);
|
150 |
GetProduct(softMuonBJetTagsName_, hSoftMuonBJetTags, event);
|
151 |
GetProduct(softMuonByIP3dBJetTagsName_, hSoftMuonByIP3dBJetTags, event);
|
152 |
GetProduct(softMuonByPtBJetTagsName_, hSoftMuonByPtBJetTags, event);
|
153 |
GetProduct(softElectronByIP3dBJetTagsName_, hSoftElectronByIP3dBJetTags, event);
|
154 |
GetProduct(softElectronByPtBJetTagsName_, hSoftElectronByPtBJetTags, event);
|
155 |
}
|
156 |
|
157 |
const reco::TrackJetCollection inJets = *(hJetProduct.product());
|
158 |
|
159 |
//Handles to Jet to Vertex Association
|
160 |
Handle<std::vector<double> > JV_alpha;
|
161 |
Handle<std::vector<double> > JV_beta;
|
162 |
std::vector<double>::const_iterator it_jv_alpha;
|
163 |
std::vector<double>::const_iterator it_jv_beta;
|
164 |
|
165 |
if (jetToVertexActive_) {
|
166 |
GetProduct(jetToVertexAlphaName_, JV_alpha, event);
|
167 |
GetProduct(jetToVertexBetaName_, JV_beta, event);
|
168 |
it_jv_alpha = JV_alpha->begin();
|
169 |
it_jv_beta = JV_beta->begin();
|
170 |
}
|
171 |
|
172 |
//Define Jet Correction Services
|
173 |
const JetCorrector* correctorL2 = 0;
|
174 |
const JetCorrector* correctorL3 = 0;
|
175 |
if (jetCorrectionsActive_) {
|
176 |
correctorL2 = JetCorrector::getJetCorrector (L2JetCorrectorName_,setup);
|
177 |
correctorL3 = JetCorrector::getJetCorrector (L3JetCorrectorName_,setup);
|
178 |
}
|
179 |
|
180 |
// loop through all jets
|
181 |
for (reco::TrackJetCollection::const_iterator inJet = inJets.begin();
|
182 |
inJet != inJets.end(); ++inJet) {
|
183 |
|
184 |
reco::TrackJetRef jetRef(hJetProduct, inJet - inJets.begin());
|
185 |
reco::JetBaseRef jetBaseRef(jetRef);
|
186 |
|
187 |
mithep::TrackJet *jet = jets_->Allocate();
|
188 |
new (jet) mithep::TrackJet(inJet->p4().x(),
|
189 |
inJet->p4().y(),
|
190 |
inJet->p4().z(),
|
191 |
inJet->p4().e());
|
192 |
|
193 |
//add to map
|
194 |
edm::Ptr<reco::TrackJet> thePtr(hJetProduct, inJet - inJets.begin());
|
195 |
jetMap_->Add(thePtr, jet);
|
196 |
|
197 |
//fill jet moments
|
198 |
jet->SetSigmaEta(TMath::Sqrt(inJet->etaetaMoment()));
|
199 |
jet->SetSigmaPhi(TMath::Sqrt(inJet->phiphiMoment()));
|
200 |
|
201 |
//fill TrackJet specific quantities
|
202 |
//fill primary vertex reference
|
203 |
if (inJet->primaryVertex().isNonnull()) {
|
204 |
jet->SetVertex(vertexMap_->GetMit(refToPtr(inJet->primaryVertex())));
|
205 |
}
|
206 |
|
207 |
|
208 |
if (jetToVertexActive_) {
|
209 |
//compute alpha and beta parameter for jets
|
210 |
jet->SetAlpha((*it_jv_alpha));
|
211 |
jet->SetBeta((*it_jv_beta));
|
212 |
}
|
213 |
|
214 |
//Jet Corrections
|
215 |
if (jetCorrectionsActive_) {
|
216 |
double L2Scale = correctorL2->correction(inJet->p4());
|
217 |
double L3Scale = correctorL3->correction(inJet->p4()*L2Scale);
|
218 |
jet->SetL2RelativeCorrectionScale(L2Scale);
|
219 |
jet->SetL3AbsoluteCorrectionScale(L3Scale);
|
220 |
jet->EnableCorrection(mithep::TrackJet::L2);
|
221 |
jet->EnableCorrection(mithep::TrackJet::L3);
|
222 |
}
|
223 |
|
224 |
if (bTaggingActive_) {
|
225 |
jet->SetJetProbabilityBJetTagsDisc((*(hJetProbabilityBJetTags.product()))[jetBaseRef]);
|
226 |
jet->SetJetBProbabilityBJetTagsDisc((*(hJetBProbabilityBJetTags.product()))[jetBaseRef]);
|
227 |
jet->SetSimpleSecondaryVertexBJetTagsDisc(
|
228 |
(*(hSimpleSecondaryVertexBJetTags.product()))[jetBaseRef]);
|
229 |
jet->SetCombinedSecondaryVertexBJetTagsDisc(
|
230 |
(*(hCombinedSecondaryVertexBJetTags.product()))[jetBaseRef]);
|
231 |
jet->SetCombinedSecondaryVertexMVABJetTagsDisc(
|
232 |
(*(hCombinedSecondaryVertexMVABJetTags.product()))[jetBaseRef]);
|
233 |
jet->SetTrackCountingHighEffBJetTagsDisc(
|
234 |
(*(hTrackCountingHighEffBJetTags.product()))[jetBaseRef]);
|
235 |
jet->SetTrackCountingHighPurBJetTagsDisc(
|
236 |
(*(hTrackCountingHighPurBJetTags.product()))[jetBaseRef]);
|
237 |
jet->SetSoftMuonBJetTagsDisc((*(hSoftMuonBJetTags.product()))[jetBaseRef]);
|
238 |
jet->SetSoftMuonByIP3dBJetTagsDisc((*(hSoftMuonByIP3dBJetTags.product()))[jetBaseRef]);
|
239 |
jet->SetSoftMuonByPtBJetTagsDisc((*(hSoftMuonByPtBJetTags.product()))[jetBaseRef]);
|
240 |
jet->SetSoftElectronByIP3dBJetTagsDisc((*(hSoftElectronByIP3dBJetTags.product()))[jetBaseRef]);
|
241 |
jet->SetSoftElectronByPtBJetTagsDisc((*(hSoftElectronByPtBJetTags.product()))[jetBaseRef]);
|
242 |
}
|
243 |
|
244 |
// get the Monte Carlo flavour matching information
|
245 |
if (flavorMatchingActive_) {
|
246 |
unsigned int iJet = inJet - inJets.begin();
|
247 |
const reco::JetMatchedPartonsCollection *matchedPartons = hPartonMatchingProduct.product();
|
248 |
reco::MatchedPartons matchedParton = (*matchedPartons)[matchedPartons->key(iJet)];
|
249 |
int flavorPhysDef = (matchedParton.physicsDefinitionParton().isNonnull())?
|
250 |
matchedParton.physicsDefinitionParton()->pdgId():0;
|
251 |
int flavorAlgDef = (matchedParton.algoDefinitionParton().isNonnull())?
|
252 |
matchedParton.algoDefinitionParton()->pdgId():0;
|
253 |
|
254 |
if (flavorMatchingDefinition_ == "Algorithmic") {
|
255 |
jet->SetMatchedMCFlavor(flavorAlgDef);
|
256 |
} else if(flavorMatchingDefinition_ == "Physics") {
|
257 |
jet->SetMatchedMCFlavor(flavorPhysDef);
|
258 |
} else {
|
259 |
jet->SetMatchedMCFlavor(0);
|
260 |
}
|
261 |
}
|
262 |
|
263 |
// add track refs
|
264 |
if (trackMap_) {
|
265 |
for (uint i=0; i<inJet->numberOfTracks(); ++i) {
|
266 |
const edm::Ptr<reco::Track> trkPtr = inJet->track(i);
|
267 |
const mithep::Track *track = trackMap_->GetMit(trkPtr);
|
268 |
jet->AddTrack(track);
|
269 |
}
|
270 |
}
|
271 |
if (jetToVertexActive_) {
|
272 |
it_jv_alpha++;
|
273 |
it_jv_beta++;
|
274 |
}
|
275 |
}
|
276 |
jets_->Trim();
|
277 |
}
|