ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerPFJets.cc
Revision: 1.2
Committed: Sun Mar 15 11:20:41 2009 UTC (16 years, 1 month ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_008pre2
Changes since 1.1: +25 -15 lines
Log Message:
Introduced BranchTable plus general cleanup.

File Contents

# User Rev Content
1 loizides 1.2 // $Id: FillerPFJets.cc,v 1.1 2009/03/11 20:08:23 bendavid Exp $
2 bendavid 1.1
3     #include "MitProd/TreeFiller/interface/FillerPFJets.h"
4     #include "FWCore/MessageLogger/interface/MessageLogger.h"
5     #include "DataFormats/Common/interface/Handle.h"
6     #include "MitAna/DataTree/interface/Names.h"
7     #include "SimDataFormats/JetMatching/interface/JetFlavour.h"
8     #include "SimDataFormats/JetMatching/interface/JetFlavourMatching.h"
9     #include "SimDataFormats/JetMatching/interface/MatchedPartons.h"
10     #include "SimDataFormats/JetMatching/interface/JetMatchedPartons.h"
11     #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
12     #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
13    
14     #include "DataFormats/JetReco/interface/PFJet.h"
15     #include "DataFormats/BTauReco/interface/JetTag.h"
16     #include "JetMETCorrections/Objects/interface/JetCorrector.h"
17    
18     using namespace std;
19     using namespace edm;
20     using namespace mithep;
21    
22     //--------------------------------------------------------------------------------------------------
23     FillerPFJets::FillerPFJets(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     impactParameterMVABJetTagsName_(Conf().getUntrackedParameter<string>
54     ("ImpactParameterMVABJetTagsName","impactParameterMVABJetTags")),
55     trackCountingHighEffBJetTagsName_(Conf().getUntrackedParameter<string>
56     ("TrackCountingHighEffBJetTagsName","trackCountingHighEffBJetTags")),
57     trackCountingHighPurBJetTagsName_(Conf().getUntrackedParameter<string>
58     ("TrackCountingHighPurBJetTagsName","trackCountingHighPurBJetTags")),
59     softMuonBJetTagsName_(Conf().getUntrackedParameter<string>
60     ("SoftMuonBJetTagsName","softMuonBJetTags")),
61     softMuonNoIPBJetTagsName_(Conf().getUntrackedParameter<string>
62     ("SoftMuonNoIPBJetTagsName","softMuonNoIPBJetTags")),
63     softElectronBJetTagsName_(Conf().getUntrackedParameter<string>
64     ("SoftElectronBJetTagsName","softElectronBJetTags")),
65     pfCandMapName_(Conf().getUntrackedParameter<string>("pfCandMapName","pfCandMapName")),
66     pfCandMap_(0),
67     jets_(new mithep::PFJetArr(16))
68     {
69     // Constructor.
70     }
71    
72     //--------------------------------------------------------------------------------------------------
73     FillerPFJets::~FillerPFJets()
74     {
75     // Destructor.
76    
77     delete jets_;
78     }
79    
80     //--------------------------------------------------------------------------------------------------
81     void FillerPFJets::BookDataBlock(TreeWriter &tws)
82     {
83     // Add jets branch to tree.
84    
85 loizides 1.2 tws.AddBranch(mitName_,&jets_);
86     OS()->add<mithep::PFJetArr>(jets_,mitName_);
87 bendavid 1.1
88 loizides 1.2 if (!pfCandMapName_.empty()) {
89     pfCandMap_ = OS()->get<PFCandidateMap>(pfCandMapName_);
90     if (pfCandMap_)
91     AddBranchDep(mitName_,pfCandMap_->GetBrName());
92     }
93 bendavid 1.1 }
94    
95     //--------------------------------------------------------------------------------------------------
96     void FillerPFJets::FillDataBlock(const edm::Event &event,
97 loizides 1.2 const edm::EventSetup &setup)
98 bendavid 1.1 {
99     // Fill jets from edm collection into our collection.
100    
101     jets_->Delete();
102    
103 loizides 1.2 // handle for the Jet Collection
104 bendavid 1.1 Handle<reco::PFJetCollection> hJetProduct;
105     GetProduct(edmName_, hJetProduct, event);
106    
107 loizides 1.2 // handles for jet flavour matching
108 bendavid 1.1 Handle<reco::JetMatchedPartonsCollection> hPartonMatchingProduct;
109     if (flavorMatchingActive_)
110     GetProduct(flavorMatchingByReferenceName_, hPartonMatchingProduct, event);
111    
112     Handle<reco::JetTagCollection> hJetProbabilityBJetTags;
113     Handle<reco::JetTagCollection> hJetBProbabilityBJetTags;
114     Handle<reco::JetTagCollection> hSimpleSecondaryVertexBJetTags;
115     Handle<reco::JetTagCollection> hCombinedSecondaryVertexBJetTags;
116     Handle<reco::JetTagCollection> hCombinedSecondaryVertexMVABJetTags;
117     Handle<reco::JetTagCollection> hImpactParameterMVABJetTags;
118     Handle<reco::JetTagCollection> hTrackCountingHighEffBJetTags;
119     Handle<reco::JetTagCollection> hTrackCountingHighPurBJetTags;
120     Handle<reco::JetTagCollection> hSoftMuonBJetTags;
121     Handle<reco::JetTagCollection> hSoftMuonNoIPBJetTags;
122     Handle<reco::JetTagCollection> hSoftElectronBJetTags;
123    
124     if (bTaggingActive_) {
125     GetProduct(jetProbabilityBJetTagsName_, hJetProbabilityBJetTags, event);
126     GetProduct(jetBProbabilityBJetTagsName_, hJetBProbabilityBJetTags, event);
127     GetProduct(simpleSecondaryVertexBJetTagsName_, hSimpleSecondaryVertexBJetTags, event);
128     GetProduct(combinedSecondaryVertexBJetTagsName_, hCombinedSecondaryVertexBJetTags, event);
129     GetProduct(combinedSecondaryVertexMVABJetTagsName_, hCombinedSecondaryVertexMVABJetTags, event);
130     GetProduct(impactParameterMVABJetTagsName_, hImpactParameterMVABJetTags, event);
131     GetProduct(trackCountingHighEffBJetTagsName_, hTrackCountingHighEffBJetTags, event);
132     GetProduct(trackCountingHighPurBJetTagsName_, hTrackCountingHighPurBJetTags, event);
133     GetProduct(softMuonBJetTagsName_, hSoftMuonBJetTags, event);
134     GetProduct(softMuonNoIPBJetTagsName_, hSoftMuonNoIPBJetTags, event);
135     GetProduct(softElectronBJetTagsName_, hSoftElectronBJetTags, event);
136     }
137    
138     const reco::PFJetCollection inJets = *(hJetProduct.product());
139    
140     //Handles to Jet to Vertex Association
141     Handle<std::vector<double> > JV_alpha;
142     Handle<std::vector<double> > JV_beta;
143     std::vector<double>::const_iterator it_jv_alpha;
144     std::vector<double>::const_iterator it_jv_beta;
145    
146     if (jetToVertexActive_) {
147     GetProduct(jetToVertexAlphaName_, JV_alpha, event);
148     GetProduct(jetToVertexBetaName_, JV_beta, event);
149     it_jv_alpha = JV_alpha->begin();
150     it_jv_beta = JV_beta->begin();
151     }
152    
153     //Define Jet Correction Services
154     const JetCorrector* correctorL2 = 0;
155     const JetCorrector* correctorL3 = 0;
156     if (jetCorrectionsActive_) {
157     correctorL2 = JetCorrector::getJetCorrector (L2JetCorrectorName_,setup);
158     correctorL3 = JetCorrector::getJetCorrector (L3JetCorrectorName_,setup);
159     }
160    
161     // loop through all jets
162     for (reco::PFJetCollection::const_iterator inJet = inJets.begin();
163     inJet != inJets.end(); ++inJet) {
164    
165     reco::PFJetRef jetRef(hJetProduct, inJet - inJets.begin());
166     reco::JetBaseRef jetBaseRef(jetRef);
167    
168     mithep::PFJet *jet = jets_->Allocate();
169     new (jet) mithep::PFJet(inJet->p4().x(),
170     inJet->p4().y(),
171     inJet->p4().z(),
172     inJet->p4().e());
173    
174     //fill pfjet-specific quantities
175     jet->SetChargedHadronEnergy(inJet->chargedHadronEnergy());
176     jet->SetNeutralHadronEnergy(inJet->neutralHadronEnergy());
177     jet->SetChargedEmEnergy(inJet->chargedEmEnergy());
178     jet->SetChargedMuEnergy(inJet->chargedMuEnergy());
179     jet->SetNeutralEmEnergy(inJet->neutralEmEnergy());
180     jet->SetChargedMultiplicity(inJet->chargedMultiplicity());
181     jet->SetNeutralMultiplicity(inJet->neutralMultiplicity());
182     jet->SetMuonMultiplicity(inJet->muonMultiplicity());
183    
184     if (jetToVertexActive_) {
185     //compute alpha and beta parameter for jets
186     jet->SetAlpha((*it_jv_alpha));
187     jet->SetBeta((*it_jv_beta));
188     }
189    
190     //Jet Corrections
191     if (jetCorrectionsActive_) {
192     double L2Scale = correctorL2->correction(inJet->p4());
193     double L3Scale = correctorL3->correction(inJet->p4()*L2Scale);
194     jet->SetL2RelativeCorrectionScale(L2Scale);
195     jet->SetL3AbsoluteCorrectionScale(L3Scale);
196     jet->EnableCorrection(mithep::PFJet::L2);
197     jet->EnableCorrection(mithep::PFJet::L3);
198     }
199    
200     if (bTaggingActive_) {
201     jet->SetJetProbabilityBJetTagsDisc((*(hJetProbabilityBJetTags.product()))[jetBaseRef]);
202     jet->SetJetBProbabilityBJetTagsDisc((*(hJetBProbabilityBJetTags.product()))[jetBaseRef]);
203 loizides 1.2 jet->SetSimpleSecondaryVertexBJetTagsDisc(
204     (*(hSimpleSecondaryVertexBJetTags.product()))[jetBaseRef]);
205     jet->SetCombinedSecondaryVertexBJetTagsDisc(
206     (*(hCombinedSecondaryVertexBJetTags.product()))[jetBaseRef]);
207     jet->SetCombinedSecondaryVertexMVABJetTagsDisc(
208     (*(hCombinedSecondaryVertexMVABJetTags.product()))[jetBaseRef]);
209     jet->SetImpactParameterMVABJetTagsDisc(
210     (*(hImpactParameterMVABJetTags.product()))[jetBaseRef]);
211     jet->SetTrackCountingHighEffBJetTagsDisc(
212     (*(hTrackCountingHighEffBJetTags.product()))[jetBaseRef]);
213     jet->SetTrackCountingHighPurBJetTagsDisc(
214     (*(hTrackCountingHighPurBJetTags.product()))[jetBaseRef]);
215 bendavid 1.1 jet->SetSoftMuonBJetTagsDisc((*(hSoftMuonBJetTags.product()))[jetBaseRef]);
216     jet->SetSoftMuonNoIPBJetTagsDisc((*(hSoftMuonNoIPBJetTags.product()))[jetBaseRef]);
217     jet->SetSoftElectronBJetTagsDisc((*(hSoftElectronBJetTags.product()))[jetBaseRef]);
218     }
219    
220 loizides 1.2 // get the Monte Carlo Flavour Matching information
221 bendavid 1.1 if (flavorMatchingActive_) {
222     unsigned int iJet = inJet - inJets.begin();
223     const reco::JetMatchedPartonsCollection *matchedPartons = hPartonMatchingProduct.product();
224     reco::MatchedPartons matchedParton = (*matchedPartons)[matchedPartons->key(iJet)];
225     int flavorPhysDef = (matchedParton.physicsDefinitionParton().isNonnull())?
226     matchedParton.physicsDefinitionParton()->pdgId():0;
227     int flavorAlgDef = (matchedParton.algoDefinitionParton().isNonnull())?
228     matchedParton.algoDefinitionParton()->pdgId():0;
229    
230     if (flavorMatchingDefinition_ == "Algorithmic") {
231     jet->SetMatchedMCFlavor(flavorAlgDef);
232     } else if(flavorMatchingDefinition_ == "Physics") {
233     jet->SetMatchedMCFlavor(flavorPhysDef);
234     } else {
235     jet->SetMatchedMCFlavor(0);
236     }
237     }
238    
239 loizides 1.2 // add PFCandidate Refs
240 bendavid 1.1 if (pfCandMap_) {
241     for (uint i=0; i<inJet->numberOfDaughters(); ++i) {
242     const reco::CandidatePtr candPtr = inJet->daughterPtr(i);
243     const reco::PFCandidatePtr pfPtr(candPtr);
244     const mithep::PFCandidate *constituent = pfCandMap_->GetMit(pfPtr);
245     jet->AddPFCand(constituent);
246     }
247     }
248     if (jetToVertexActive_) {
249     it_jv_alpha++;
250     it_jv_beta++;
251     }
252     }
253     jets_->Trim();
254     }