ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerCaloJets.cc
Revision: 1.27
Committed: Fri May 28 14:30:02 2010 UTC (14 years, 11 months ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_014pre3
Changes since 1.26: +4 -4 lines
Log Message:
Quick fix for missing btag variable

File Contents

# User Rev Content
1 bendavid 1.27 // $Id: FillerCaloJets.cc,v 1.26 2010/03/26 14:18:47 sixie 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     Handle<reco::JetTagCollection> hCombinedSecondaryVertexBJetTags;
132     Handle<reco::JetTagCollection> hCombinedSecondaryVertexMVABJetTags;
133     Handle<reco::JetTagCollection> hTrackCountingHighEffBJetTags;
134     Handle<reco::JetTagCollection> hTrackCountingHighPurBJetTags;
135     Handle<reco::JetTagCollection> hSoftMuonBJetTags;
136 bendavid 1.21 Handle<reco::JetTagCollection> hSoftMuonByIP3dBJetTags;
137     Handle<reco::JetTagCollection> hSoftMuonByPtBJetTags;
138     Handle<reco::JetTagCollection> hSoftElectronByIP3dBJetTags;
139     Handle<reco::JetTagCollection> hSoftElectronByPtBJetTags;
140 sixie 1.8
141     if (bTaggingActive_) {
142 sixie 1.11 GetProduct(jetProbabilityBJetTagsName_, hJetProbabilityBJetTags, event);
143     GetProduct(jetBProbabilityBJetTagsName_, hJetBProbabilityBJetTags, event);
144 bendavid 1.27 //GetProduct(simpleSecondaryVertexBJetTagsName_, hSimpleSecondaryVertexBJetTags, event);
145 sixie 1.11 GetProduct(combinedSecondaryVertexBJetTagsName_, hCombinedSecondaryVertexBJetTags, event);
146 loizides 1.22 GetProduct(combinedSecondaryVertexMVABJetTagsName_, hCombinedSecondaryVertexMVABJetTags, event);
147 sixie 1.11 GetProduct(trackCountingHighEffBJetTagsName_, hTrackCountingHighEffBJetTags, event);
148     GetProduct(trackCountingHighPurBJetTagsName_, hTrackCountingHighPurBJetTags, event);
149     GetProduct(softMuonBJetTagsName_, hSoftMuonBJetTags, event);
150 bendavid 1.21 GetProduct(softMuonByIP3dBJetTagsName_, hSoftMuonByIP3dBJetTags, event);
151     GetProduct(softMuonByPtBJetTagsName_, hSoftMuonByPtBJetTags, event);
152     GetProduct(softElectronByIP3dBJetTagsName_, hSoftElectronByIP3dBJetTags, event);
153     GetProduct(softElectronByPtBJetTagsName_, hSoftElectronByPtBJetTags, event);
154 sixie 1.11 }
155    
156     const reco::CaloJetCollection inJets = *(hJetProduct.product());
157    
158 loizides 1.16 // handle to Jet to Vertex association
159 sixie 1.11 Handle<std::vector<double> > JV_alpha;
160     Handle<std::vector<double> > JV_beta;
161     std::vector<double>::const_iterator it_jv_alpha;
162     std::vector<double>::const_iterator it_jv_beta;
163    
164     if (jetToVertexActive_) {
165     GetProduct(jetToVertexAlphaName_, JV_alpha, event);
166     GetProduct(jetToVertexBetaName_, JV_beta, event);
167     it_jv_alpha = JV_alpha->begin();
168     it_jv_beta = JV_beta->begin();
169 sixie 1.8 }
170    
171 loizides 1.16 // define jet correction services
172 loizides 1.12 const JetCorrector* correctorL2 = 0;
173     const JetCorrector* correctorL3 = 0;
174 sixie 1.11 if (jetCorrectionsActive_) {
175     correctorL2 = JetCorrector::getJetCorrector (L2JetCorrectorName_,setup);
176     correctorL3 = JetCorrector::getJetCorrector (L3JetCorrectorName_,setup);
177     }
178 loizides 1.1
179     // loop through all jets
180     for (reco::CaloJetCollection::const_iterator inJet = inJets.begin();
181     inJet != inJets.end(); ++inJet) {
182 sixie 1.8
183     reco::CaloJetRef jetRef(hJetProduct, inJet - inJets.begin());
184     reco::JetBaseRef jetBaseRef(jetRef);
185    
186 bendavid 1.15 mithep::CaloJet *jet = jets_->Allocate();
187     new (jet) mithep::CaloJet(inJet->p4().x(),
188 loizides 1.3 inJet->p4().y(),
189     inJet->p4().z(),
190     inJet->p4().e());
191    
192 loizides 1.18 // add to map
193 bendavid 1.17 edm::Ptr<reco::CaloJet> thePtr(hJetProduct, inJet - inJets.begin());
194     jetMap_->Add(thePtr, jet);
195    
196 sixie 1.26 //fill jet moments
197     jet->SetSigmaEta(TMath::Sqrt(inJet->etaetaMoment()));
198     jet->SetSigmaPhi(TMath::Sqrt(inJet->phiphiMoment()));
199    
200 loizides 1.16 // fill calojet-specific quantities
201 loizides 1.3 jet->SetMaxEInEmTowers (inJet->maxEInEmTowers());
202     jet->SetMaxEInHadTowers(inJet->maxEInHadTowers());
203     jet->SetEnergyFractionH(inJet->energyFractionHadronic());
204 bendavid 1.15 jet->SetEnergyFractionEm(inJet->emEnergyFraction());
205 loizides 1.3 jet->SetHadEnergyInHB (inJet->hadEnergyInHB());
206     jet->SetHadEnergyInHO (inJet->hadEnergyInHO());
207     jet->SetHadEnergyInHE (inJet->hadEnergyInHE());
208     jet->SetHadEnergyInHF (inJet->hadEnergyInHF());
209     jet->SetEmEnergyInEB (inJet->emEnergyInEB());
210     jet->SetEmEnergyInEE (inJet->emEnergyInEE());
211     jet->SetEmEnergyInHF (inJet->emEnergyInHF());
212     jet->SetTowersArea (inJet->towersArea());
213 sixie 1.11
214     if (jetToVertexActive_) {
215 loizides 1.16 // compute alpha and beta parameter for jets
216 sixie 1.11 jet->SetAlpha((*it_jv_alpha));
217     jet->SetBeta((*it_jv_beta));
218     }
219    
220 loizides 1.16 // jet corrections
221 sixie 1.11 if (jetCorrectionsActive_) {
222     double L2Scale = correctorL2->correction(inJet->p4());
223     double L3Scale = correctorL3->correction(inJet->p4()*L2Scale);
224     jet->SetL2RelativeCorrectionScale(L2Scale);
225 bendavid 1.14 jet->SetL3AbsoluteCorrectionScale(L3Scale);
226 bendavid 1.15 jet->EnableCorrection(mithep::CaloJet::L2);
227     jet->EnableCorrection(mithep::CaloJet::L3);
228 sixie 1.11 }
229 bendavid 1.24
230     //fill jet id variables
231     if (jetIDActive_) {
232     reco::JetID jetId = (*hJetIDMap)[jetBaseRef];
233    
234     jet->SetFHPD(jetId.fHPD);
235     jet->SetFRBX(jetId.fRBX);
236     jet->SetN90Hits(jetId.n90Hits);
237     jet->SetFSubDetector1(jetId.fSubDetector1);
238     jet->SetFSubDetector2(jetId.fSubDetector1);
239     jet->SetFSubDetector3(jetId.fSubDetector1);
240     jet->SetFSubDetector4(jetId.fSubDetector1);
241     jet->SetRestrictedEMF(jetId.restrictedEMF);
242     jet->SetNHCalTowers(jetId.nHCALTowers);
243     jet->SetNECalTowers(jetId.nECALTowers);
244     jet->SetApproximatefHPD(jetId.approximatefHPD);
245     jet->SetApproximatefRBX(jetId.approximatefRBX);
246     jet->SetHitsInN90(jetId.hitsInN90);
247     jet->SetNHits2RPC(jetId.numberOfHits2RPC);
248     jet->SetNHits3RPC(jetId.numberOfHits3RPC);
249     jet->SetNHitsRPC(jetId.numberOfHitsRPC);
250 sixie 1.26
251 bendavid 1.24 }
252 sixie 1.11
253 sixie 1.8 if (bTaggingActive_) {
254     jet->SetJetProbabilityBJetTagsDisc((*(hJetProbabilityBJetTags.product()))[jetBaseRef]);
255 bendavid 1.14 jet->SetJetBProbabilityBJetTagsDisc((*(hJetBProbabilityBJetTags.product()))[jetBaseRef]);
256 bendavid 1.27 //jet->SetSimpleSecondaryVertexBJetTagsDisc(
257     //(*(hSimpleSecondaryVertexBJetTags.product()))[jetBaseRef]);
258 loizides 1.16 jet->SetCombinedSecondaryVertexBJetTagsDisc(
259     (*(hCombinedSecondaryVertexBJetTags.product()))[jetBaseRef]);
260     jet->SetCombinedSecondaryVertexMVABJetTagsDisc(
261     (*(hCombinedSecondaryVertexMVABJetTags.product()))[jetBaseRef]);
262     jet->SetTrackCountingHighEffBJetTagsDisc(
263     (*(hTrackCountingHighEffBJetTags.product()))[jetBaseRef]);
264     jet->SetTrackCountingHighPurBJetTagsDisc(
265     (*(hTrackCountingHighPurBJetTags.product()))[jetBaseRef]);
266 sixie 1.8 jet->SetSoftMuonBJetTagsDisc((*(hSoftMuonBJetTags.product()))[jetBaseRef]);
267 bendavid 1.21 jet->SetSoftMuonByIP3dBJetTagsDisc((*(hSoftMuonByIP3dBJetTags.product()))[jetBaseRef]);
268     jet->SetSoftMuonByPtBJetTagsDisc((*(hSoftMuonByPtBJetTags.product()))[jetBaseRef]);
269 loizides 1.22 jet->SetSoftElectronByIP3dBJetTagsDisc((*(hSoftElectronByIP3dBJetTags.product()))[jetBaseRef]);
270 bendavid 1.21 jet->SetSoftElectronByPtBJetTagsDisc((*(hSoftElectronByPtBJetTags.product()))[jetBaseRef]);
271 sixie 1.8 }
272    
273 loizides 1.16 // get the Monte Carlo flavour matching information
274 sixie 1.6 if (flavorMatchingActive_) {
275     unsigned int iJet = inJet - inJets.begin();
276     const reco::JetMatchedPartonsCollection *matchedPartons = hPartonMatchingProduct.product();
277     reco::MatchedPartons matchedParton = (*matchedPartons)[matchedPartons->key(iJet)];
278     int flavorPhysDef = (matchedParton.physicsDefinitionParton().isNonnull())?
279     matchedParton.physicsDefinitionParton()->pdgId():0;
280     int flavorAlgDef = (matchedParton.algoDefinitionParton().isNonnull())?
281     matchedParton.algoDefinitionParton()->pdgId():0;
282    
283     if (flavorMatchingDefinition_ == "Algorithmic") {
284     jet->SetMatchedMCFlavor(flavorAlgDef);
285     } else if(flavorMatchingDefinition_ == "Physics") {
286     jet->SetMatchedMCFlavor(flavorPhysDef);
287     } else {
288     jet->SetMatchedMCFlavor(0);
289     }
290 sixie 1.5 }
291 bendavid 1.7
292 loizides 1.16 // add CaloTower references
293 bendavid 1.7 if (caloTowerMap_) {
294     std::vector<CaloTowerDetId> ctidVector = inJet->getTowerIndices();
295 loizides 1.12 for(std::vector<CaloTowerDetId>::const_iterator ctid = ctidVector.begin();
296     ctid != ctidVector.end(); ++ctid) {
297 bendavid 1.7 mithep::CaloTower *caloTower = caloTowerMap_->GetMit(*ctid);
298     jet->AddTower(caloTower);
299     }
300     }
301 sixie 1.11 if (jetToVertexActive_) {
302     it_jv_alpha++;
303     it_jv_beta++;
304     }
305     }
306 loizides 1.1 jets_->Trim();
307     }