ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerCaloJets.cc
Revision: 1.28
Committed: Sun May 30 14:00:50 2010 UTC (14 years, 11 months ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_018, Mit_017, Mit_017pre3, Mit_017pre2, Mit_017pre1, Mit_016, Mit_015b, Mit_015a, Mit_015, Mit_014e, Mit_014d, Mit_014c, Mit_014b, Mit_014a, Mit_014
Changes since 1.27: +21 -5 lines
Log Message:
Add new btag variables in a backwards compatible way

File Contents

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