ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerPFJets.cc
Revision: 1.4
Committed: Sun Mar 22 10:00:46 2009 UTC (16 years, 1 month ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_009a, Mit_009, Mit_008
Changes since 1.3: +3 -4 lines
Log Message:
Cleanup

File Contents

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