ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerPFJets.cc
Revision: 1.9
Committed: Fri Sep 25 08:42:51 2009 UTC (15 years, 7 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_013pre1, Mit_012i, Mit_012h, Mit_012g, Mit_012f, Mit_012e, Mit_012d, Mit_012c, Mit_012b, Mit_012a, Mit_012, Mit_011a
Changes since 1.8: +2 -2 lines
Log Message:
Extended interface of BookDataBlock to contain event setup.

File Contents

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