ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerCaloJets.cc
Revision: 1.29
Committed: Wed Mar 9 17:32:53 2011 UTC (14 years, 1 month ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_032, Mit_031, Mit_025c_branch2, Mit_025c_branch1, Mit_030, Mit_029c, Mit_029b, Mit_030_pre1, Mit_029a, Mit_029, Mit_029_pre1, Mit_028a, Mit_025c_branch0, Mit_028, Mit_027a, Mit_027, Mit_026, Mit_025e, Mit_025d, Mit_025c, Mit_025b, Mit_025a, Mit_025, Mit_025pre2, Mit_024b, Mit_025pre1, Mit_024a, Mit_024, Mit_023, Mit_022a, Mit_022, Mit_020d, TMit_020d, Mit_020c, Mit_021, Mit_021pre2, Mit_021pre1, Mit_020b, Mit_020a, Mit_020, Mit_020pre1, HEAD
Branch point for: Mit_025c_branch
Changes since 1.28: +16 -18 lines
Log Message:
cleanup btagging variables

File Contents

# User Rev Content
1 bendavid 1.29 // $Id: FillerCaloJets.cc,v 1.28 2010/05/30 14:00:50 bendavid Exp $
2 loizides 1.1
3     #include "MitProd/TreeFiller/interface/FillerCaloJets.h"
4 loizides 1.19 #include "DataFormats/JetReco/interface/Jet.h"
5     #include "DataFormats/BTauReco/interface/JetTag.h"
6 bendavid 1.24 #include "DataFormats/JetReco/interface/JetID.h"
7 sixie 1.5 #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 sixie 1.11 #include "JetMETCorrections/Objects/interface/JetCorrector.h"
12 loizides 1.19 #include "MitAna/DataTree/interface/CaloJetCol.h"
13     #include "MitAna/DataTree/interface/Names.h"
14     #include "MitProd/ObjectService/interface/ObjectService.h"
15 sixie 1.8
16 loizides 1.1 using namespace std;
17     using namespace edm;
18     using namespace mithep;
19    
20     //--------------------------------------------------------------------------------------------------
21     FillerCaloJets::FillerCaloJets(const ParameterSet &cfg, const char *name, bool active) :
22 loizides 1.4 BaseFiller(cfg,name,active),
23 sixie 1.5 flavorMatchingActive_(Conf().getUntrackedParameter<bool>("flavorMatchingActive",true)),
24 sixie 1.8 bTaggingActive_(Conf().getUntrackedParameter<bool>("bTaggingActive",true)),
25 sixie 1.11 jetToVertexActive_(Conf().getUntrackedParameter<bool>("jetToVertexActive",true)),
26     jetCorrectionsActive_(Conf().getUntrackedParameter<bool>("jetCorrectionsActive",true)),
27 bendavid 1.24 jetIDActive_(Conf().getUntrackedParameter<bool>("jetIDActive",false)),
28 loizides 1.2 edmName_(Conf().getUntrackedParameter<string>("edmName","recoCaloJets:iterativeCone5CaloJets")),
29 sixie 1.11 mitName_(Conf().getUntrackedParameter<string>("mitName",Names::gkCaloJetBrn)),
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 bendavid 1.24 jetIDName_(Conf().getUntrackedParameter<string>
39     ("jetIDName","jetIDName")),
40 sixie 1.5 flavorMatchingByReferenceName_(Conf().getUntrackedParameter<string>
41 sixie 1.8 ("flavorMatchingByReferenceName","srcByReference")),
42 sixie 1.5 flavorMatchingDefinition_(Conf().getUntrackedParameter<string>
43 sixie 1.8 ("flavorMatchingDefinition","Algorithmic")),
44     jetProbabilityBJetTagsName_(Conf().getUntrackedParameter<string>
45 sixie 1.11 ("JetProbabilityBJetTagsName","jetProbabilityBJetTags")),
46 sixie 1.8 jetBProbabilityBJetTagsName_(Conf().getUntrackedParameter<string>
47 sixie 1.11 ("JetBProbabilityBJetTagsName","jetBProbabilityBJetTags")),
48 sixie 1.8 simpleSecondaryVertexBJetTagsName_(Conf().getUntrackedParameter<string>
49 sixie 1.11 ("SimpleSecondaryVertexBJetTagsName","simpleSecondaryVertexBJetTags")),
50 bendavid 1.29 simpleSecondaryVertexHighEffBJetTagsName_(Conf().getUntrackedParameter<string>
51     ("SimpleSecondaryVertexHighEffBJetTagsName","simpleSecondaryVertexHighEffBJetTags")),
52     simpleSecondaryVertexHighPurBJetTagsName_(Conf().getUntrackedParameter<string>
53     ("SimpleSecondaryVertexHighPurBJetTagsName","simpleSecondaryVertexHighPurBJetTags")),
54 sixie 1.8 combinedSecondaryVertexBJetTagsName_(Conf().getUntrackedParameter<string>
55 sixie 1.11 ("CombinedSecondaryVertexBJetTagsName","combinedSecondaryVertexBJetTags")),
56 sixie 1.8 combinedSecondaryVertexMVABJetTagsName_(Conf().getUntrackedParameter<string>
57 sixie 1.11 ("CombinedSecondaryVertexMVABJetTagsName","combinedSecondaryVertexMVABJetTags")),
58 bendavid 1.29 ghostTrackBJetTagsName_(Conf().getUntrackedParameter<string>
59     ("GhostTrackBJetTagsName","ghostTrackBJetTags")),
60 sixie 1.8 trackCountingHighEffBJetTagsName_(Conf().getUntrackedParameter<string>
61 sixie 1.11 ("TrackCountingHighEffBJetTagsName","trackCountingHighEffBJetTags")),
62 sixie 1.8 trackCountingHighPurBJetTagsName_(Conf().getUntrackedParameter<string>
63 sixie 1.11 ("TrackCountingHighPurBJetTagsName","trackCountingHighPurBJetTags")),
64 sixie 1.8 softMuonBJetTagsName_(Conf().getUntrackedParameter<string>
65 sixie 1.11 ("SoftMuonBJetTagsName","softMuonBJetTags")),
66 bendavid 1.21 softMuonByIP3dBJetTagsName_(Conf().getUntrackedParameter<string>
67     ("SoftMuonByIP3dBJetTagsName","softMuonByIP3dBJetTags")),
68     softMuonByPtBJetTagsName_(Conf().getUntrackedParameter<string>
69     ("SoftMuonByPtBJetTagsName","softMuonByPtBJetTags")),
70     softElectronByIP3dBJetTagsName_(Conf().getUntrackedParameter<string>
71     ("SoftElectronByIP3dBJetTagsName","softElectronByIP3dBJetTags")),
72     softElectronByPtBJetTagsName_(Conf().getUntrackedParameter<string>
73     ("SoftElectronByPtBJetTagsName","softElectronByPtBJetTags")),
74 loizides 1.9 caloTowerMapName_(Conf().getUntrackedParameter<string>("caloTowerMapName","CaloTowerMap")),
75 bendavid 1.17 jetMapName_(Conf().getUntrackedParameter<string>("jetMapName","CaloJetMap")),
76 bendavid 1.7 caloTowerMap_(0),
77 bendavid 1.17 jetMap_(new mithep::CaloJetMap),
78 bendavid 1.15 jets_(new mithep::CaloJetArr(16))
79 loizides 1.1 {
80     // Constructor.
81     }
82    
83     //--------------------------------------------------------------------------------------------------
84     FillerCaloJets::~FillerCaloJets()
85     {
86     // Destructor.
87    
88     delete jets_;
89 bendavid 1.17 delete jetMap_;
90 loizides 1.1 }
91    
92     //--------------------------------------------------------------------------------------------------
93 bendavid 1.25 void FillerCaloJets::BookDataBlock(TreeWriter &tws)
94 loizides 1.1 {
95     // Add jets branch to tree.
96    
97 loizides 1.16 tws.AddBranch(mitName_,&jets_);
98     OS()->add<mithep::CaloJetArr>(jets_,mitName_);
99 bendavid 1.7
100 loizides 1.16 if (!caloTowerMapName_.empty()) {
101     caloTowerMap_ = OS()->get<CaloTowerMap>(caloTowerMapName_);
102     if (caloTowerMap_)
103     AddBranchDep(mitName_, caloTowerMap_->GetBrName());
104     }
105 bendavid 1.17 if (!jetMapName_.empty()) {
106     jetMap_->SetBrName(mitName_);
107     OS()->add<CaloJetMap>(jetMap_,jetMapName_);
108     }
109 loizides 1.1 }
110    
111     //--------------------------------------------------------------------------------------------------
112     void FillerCaloJets::FillDataBlock(const edm::Event &event,
113     const edm::EventSetup &setup)
114     {
115     // Fill jets from edm collection into our collection.
116    
117 bendavid 1.13 jets_->Delete();
118 bendavid 1.17 jetMap_->Reset();
119 loizides 1.1
120 loizides 1.16 // handle for the jet collection
121 sixie 1.8 Handle<reco::CaloJetCollection> hJetProduct;
122     GetProduct(edmName_, hJetProduct, event);
123    
124 loizides 1.16 // handles for jet flavour matching
125 sixie 1.6 Handle<reco::JetMatchedPartonsCollection> hPartonMatchingProduct;
126     if (flavorMatchingActive_)
127     GetProduct(flavorMatchingByReferenceName_, hPartonMatchingProduct, event);
128 sixie 1.5
129 bendavid 1.24 // handle for jet id variables
130     Handle<reco::JetIDValueMap> hJetIDMap;
131     if (jetIDActive_)
132     GetProduct( jetIDName_, hJetIDMap, event);
133    
134 sixie 1.8 Handle<reco::JetTagCollection> hJetProbabilityBJetTags;
135     Handle<reco::JetTagCollection> hJetBProbabilityBJetTags;
136     Handle<reco::JetTagCollection> hSimpleSecondaryVertexBJetTags;
137 bendavid 1.28 Handle<reco::JetTagCollection> hSimpleSecondaryVertexHighEffBJetTags;
138     Handle<reco::JetTagCollection> hSimpleSecondaryVertexHighPurBJetTags;
139 sixie 1.8 Handle<reco::JetTagCollection> hCombinedSecondaryVertexBJetTags;
140     Handle<reco::JetTagCollection> hCombinedSecondaryVertexMVABJetTags;
141     Handle<reco::JetTagCollection> hTrackCountingHighEffBJetTags;
142     Handle<reco::JetTagCollection> hTrackCountingHighPurBJetTags;
143     Handle<reco::JetTagCollection> hSoftMuonBJetTags;
144 bendavid 1.21 Handle<reco::JetTagCollection> hSoftMuonByIP3dBJetTags;
145     Handle<reco::JetTagCollection> hSoftMuonByPtBJetTags;
146     Handle<reco::JetTagCollection> hSoftElectronByIP3dBJetTags;
147     Handle<reco::JetTagCollection> hSoftElectronByPtBJetTags;
148 bendavid 1.28 Handle<reco::JetTagCollection> hGhostTrackBJetTags;
149 sixie 1.8
150     if (bTaggingActive_) {
151 sixie 1.11 GetProduct(jetProbabilityBJetTagsName_, hJetProbabilityBJetTags, event);
152 bendavid 1.28 GetProduct(jetBProbabilityBJetTagsName_, hJetBProbabilityBJetTags, event);
153 bendavid 1.29 event.getByLabel(simpleSecondaryVertexBJetTagsName_,hSimpleSecondaryVertexBJetTags);
154     event.getByLabel(simpleSecondaryVertexHighEffBJetTagsName_,hSimpleSecondaryVertexHighEffBJetTags);
155     event.getByLabel(simpleSecondaryVertexHighPurBJetTagsName_,hSimpleSecondaryVertexHighPurBJetTags);
156 sixie 1.11 GetProduct(combinedSecondaryVertexBJetTagsName_, hCombinedSecondaryVertexBJetTags, event);
157 loizides 1.22 GetProduct(combinedSecondaryVertexMVABJetTagsName_, hCombinedSecondaryVertexMVABJetTags, event);
158 sixie 1.11 GetProduct(trackCountingHighEffBJetTagsName_, hTrackCountingHighEffBJetTags, event);
159     GetProduct(trackCountingHighPurBJetTagsName_, hTrackCountingHighPurBJetTags, event);
160     GetProduct(softMuonBJetTagsName_, hSoftMuonBJetTags, event);
161 bendavid 1.21 GetProduct(softMuonByIP3dBJetTagsName_, hSoftMuonByIP3dBJetTags, event);
162     GetProduct(softMuonByPtBJetTagsName_, hSoftMuonByPtBJetTags, event);
163     GetProduct(softElectronByIP3dBJetTagsName_, hSoftElectronByIP3dBJetTags, event);
164     GetProduct(softElectronByPtBJetTagsName_, hSoftElectronByPtBJetTags, event);
165 bendavid 1.29 event.getByLabel(ghostTrackBJetTagsName_,hGhostTrackBJetTags);
166 sixie 1.11 }
167    
168     const reco::CaloJetCollection inJets = *(hJetProduct.product());
169    
170 loizides 1.16 // handle to Jet to Vertex association
171 sixie 1.11 Handle<std::vector<double> > JV_alpha;
172     Handle<std::vector<double> > JV_beta;
173     std::vector<double>::const_iterator it_jv_alpha;
174     std::vector<double>::const_iterator it_jv_beta;
175    
176     if (jetToVertexActive_) {
177     GetProduct(jetToVertexAlphaName_, JV_alpha, event);
178     GetProduct(jetToVertexBetaName_, JV_beta, event);
179     it_jv_alpha = JV_alpha->begin();
180     it_jv_beta = JV_beta->begin();
181 sixie 1.8 }
182    
183 loizides 1.16 // define jet correction services
184 loizides 1.12 const JetCorrector* correctorL2 = 0;
185     const JetCorrector* correctorL3 = 0;
186 sixie 1.11 if (jetCorrectionsActive_) {
187     correctorL2 = JetCorrector::getJetCorrector (L2JetCorrectorName_,setup);
188     correctorL3 = JetCorrector::getJetCorrector (L3JetCorrectorName_,setup);
189     }
190 loizides 1.1
191     // loop through all jets
192     for (reco::CaloJetCollection::const_iterator inJet = inJets.begin();
193     inJet != inJets.end(); ++inJet) {
194 sixie 1.8
195     reco::CaloJetRef jetRef(hJetProduct, inJet - inJets.begin());
196     reco::JetBaseRef jetBaseRef(jetRef);
197    
198 bendavid 1.15 mithep::CaloJet *jet = jets_->Allocate();
199     new (jet) mithep::CaloJet(inJet->p4().x(),
200 loizides 1.3 inJet->p4().y(),
201     inJet->p4().z(),
202     inJet->p4().e());
203    
204 loizides 1.18 // add to map
205 bendavid 1.17 edm::Ptr<reco::CaloJet> thePtr(hJetProduct, inJet - inJets.begin());
206     jetMap_->Add(thePtr, jet);
207    
208 sixie 1.26 //fill jet moments
209     jet->SetSigmaEta(TMath::Sqrt(inJet->etaetaMoment()));
210     jet->SetSigmaPhi(TMath::Sqrt(inJet->phiphiMoment()));
211    
212 loizides 1.16 // fill calojet-specific quantities
213 loizides 1.3 jet->SetMaxEInEmTowers (inJet->maxEInEmTowers());
214     jet->SetMaxEInHadTowers(inJet->maxEInHadTowers());
215     jet->SetEnergyFractionH(inJet->energyFractionHadronic());
216 bendavid 1.15 jet->SetEnergyFractionEm(inJet->emEnergyFraction());
217 loizides 1.3 jet->SetHadEnergyInHB (inJet->hadEnergyInHB());
218     jet->SetHadEnergyInHO (inJet->hadEnergyInHO());
219     jet->SetHadEnergyInHE (inJet->hadEnergyInHE());
220     jet->SetHadEnergyInHF (inJet->hadEnergyInHF());
221     jet->SetEmEnergyInEB (inJet->emEnergyInEB());
222     jet->SetEmEnergyInEE (inJet->emEnergyInEE());
223     jet->SetEmEnergyInHF (inJet->emEnergyInHF());
224     jet->SetTowersArea (inJet->towersArea());
225 sixie 1.11
226     if (jetToVertexActive_) {
227 loizides 1.16 // compute alpha and beta parameter for jets
228 sixie 1.11 jet->SetAlpha((*it_jv_alpha));
229     jet->SetBeta((*it_jv_beta));
230     }
231    
232 loizides 1.16 // jet corrections
233 sixie 1.11 if (jetCorrectionsActive_) {
234     double L2Scale = correctorL2->correction(inJet->p4());
235     double L3Scale = correctorL3->correction(inJet->p4()*L2Scale);
236     jet->SetL2RelativeCorrectionScale(L2Scale);
237 bendavid 1.14 jet->SetL3AbsoluteCorrectionScale(L3Scale);
238 bendavid 1.15 jet->EnableCorrection(mithep::CaloJet::L2);
239     jet->EnableCorrection(mithep::CaloJet::L3);
240 sixie 1.11 }
241 bendavid 1.24
242     //fill jet id variables
243     if (jetIDActive_) {
244     reco::JetID jetId = (*hJetIDMap)[jetBaseRef];
245    
246     jet->SetFHPD(jetId.fHPD);
247     jet->SetFRBX(jetId.fRBX);
248     jet->SetN90Hits(jetId.n90Hits);
249     jet->SetFSubDetector1(jetId.fSubDetector1);
250     jet->SetFSubDetector2(jetId.fSubDetector1);
251     jet->SetFSubDetector3(jetId.fSubDetector1);
252     jet->SetFSubDetector4(jetId.fSubDetector1);
253     jet->SetRestrictedEMF(jetId.restrictedEMF);
254     jet->SetNHCalTowers(jetId.nHCALTowers);
255     jet->SetNECalTowers(jetId.nECALTowers);
256     jet->SetApproximatefHPD(jetId.approximatefHPD);
257     jet->SetApproximatefRBX(jetId.approximatefRBX);
258     jet->SetHitsInN90(jetId.hitsInN90);
259     jet->SetNHits2RPC(jetId.numberOfHits2RPC);
260     jet->SetNHits3RPC(jetId.numberOfHits3RPC);
261     jet->SetNHitsRPC(jetId.numberOfHitsRPC);
262 sixie 1.26
263 bendavid 1.24 }
264 sixie 1.11
265 sixie 1.8 if (bTaggingActive_) {
266     jet->SetJetProbabilityBJetTagsDisc((*(hJetProbabilityBJetTags.product()))[jetBaseRef]);
267 bendavid 1.14 jet->SetJetBProbabilityBJetTagsDisc((*(hJetBProbabilityBJetTags.product()))[jetBaseRef]);
268 bendavid 1.29 // jet->SetSimpleSecondaryVertexBJetTagsDisc((*(hSimpleSecondaryVertexBJetTags.product()))[jetBaseRef]);
269     jet->SetSimpleSecondaryVertexHighEffBJetTagsDisc((*(hSimpleSecondaryVertexHighEffBJetTags.product()))[jetBaseRef]);
270     jet->SetSimpleSecondaryVertexHighPurBJetTagsDisc((*(hSimpleSecondaryVertexHighPurBJetTags.product()))[jetBaseRef]);
271 loizides 1.16 jet->SetCombinedSecondaryVertexBJetTagsDisc(
272     (*(hCombinedSecondaryVertexBJetTags.product()))[jetBaseRef]);
273     jet->SetCombinedSecondaryVertexMVABJetTagsDisc(
274     (*(hCombinedSecondaryVertexMVABJetTags.product()))[jetBaseRef]);
275     jet->SetTrackCountingHighEffBJetTagsDisc(
276     (*(hTrackCountingHighEffBJetTags.product()))[jetBaseRef]);
277     jet->SetTrackCountingHighPurBJetTagsDisc(
278     (*(hTrackCountingHighPurBJetTags.product()))[jetBaseRef]);
279 sixie 1.8 jet->SetSoftMuonBJetTagsDisc((*(hSoftMuonBJetTags.product()))[jetBaseRef]);
280 bendavid 1.21 jet->SetSoftMuonByIP3dBJetTagsDisc((*(hSoftMuonByIP3dBJetTags.product()))[jetBaseRef]);
281     jet->SetSoftMuonByPtBJetTagsDisc((*(hSoftMuonByPtBJetTags.product()))[jetBaseRef]);
282 loizides 1.22 jet->SetSoftElectronByIP3dBJetTagsDisc((*(hSoftElectronByIP3dBJetTags.product()))[jetBaseRef]);
283 bendavid 1.21 jet->SetSoftElectronByPtBJetTagsDisc((*(hSoftElectronByPtBJetTags.product()))[jetBaseRef]);
284 bendavid 1.29 // jet->SetGhostTrackBJetTagsDisc((*(hGhostTrackBJetTags.product()))[jetBaseRef]);
285 sixie 1.8 }
286 bendavid 1.29
287 loizides 1.16 // get the Monte Carlo flavour matching information
288 sixie 1.6 if (flavorMatchingActive_) {
289     unsigned int iJet = inJet - inJets.begin();
290     const reco::JetMatchedPartonsCollection *matchedPartons = hPartonMatchingProduct.product();
291     reco::MatchedPartons matchedParton = (*matchedPartons)[matchedPartons->key(iJet)];
292     int flavorPhysDef = (matchedParton.physicsDefinitionParton().isNonnull())?
293     matchedParton.physicsDefinitionParton()->pdgId():0;
294     int flavorAlgDef = (matchedParton.algoDefinitionParton().isNonnull())?
295     matchedParton.algoDefinitionParton()->pdgId():0;
296    
297     if (flavorMatchingDefinition_ == "Algorithmic") {
298     jet->SetMatchedMCFlavor(flavorAlgDef);
299     } else if(flavorMatchingDefinition_ == "Physics") {
300     jet->SetMatchedMCFlavor(flavorPhysDef);
301     } else {
302     jet->SetMatchedMCFlavor(0);
303     }
304 sixie 1.5 }
305 bendavid 1.7
306 loizides 1.16 // add CaloTower references
307 bendavid 1.7 if (caloTowerMap_) {
308     std::vector<CaloTowerDetId> ctidVector = inJet->getTowerIndices();
309 loizides 1.12 for(std::vector<CaloTowerDetId>::const_iterator ctid = ctidVector.begin();
310     ctid != ctidVector.end(); ++ctid) {
311 bendavid 1.7 mithep::CaloTower *caloTower = caloTowerMap_->GetMit(*ctid);
312     jet->AddTower(caloTower);
313     }
314     }
315 sixie 1.11 if (jetToVertexActive_) {
316     it_jv_alpha++;
317     it_jv_beta++;
318     }
319     }
320 loizides 1.1 jets_->Trim();
321     }