ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerTrackJets.cc
Revision: 1.2
Committed: Thu Mar 18 20:21:01 2010 UTC (15 years, 1 month ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_013
Changes since 1.1: +2 -2 lines
Log Message:
Fix beginrun,beginjob mess

File Contents

# User Rev Content
1 bendavid 1.2 // $Id: FillerTrackJets.cc,v 1.1 2010/02/24 17:38:27 bendavid Exp $
2 bendavid 1.1
3     #include "MitProd/TreeFiller/interface/FillerTrackJets.h"
4     #include "DataFormats/TrackReco/interface/Track.h"
5     #include "DataFormats/TrackReco/interface/TrackFwd.h"
6     #include "DataFormats/JetReco/interface/TrackJet.h"
7     #include "DataFormats/BTauReco/interface/JetTag.h"
8     #include "DataFormats/Common/interface/RefToPtr.h"
9     #include "SimDataFormats/JetMatching/interface/JetFlavour.h"
10     #include "SimDataFormats/JetMatching/interface/JetFlavourMatching.h"
11     #include "SimDataFormats/JetMatching/interface/MatchedPartons.h"
12     #include "SimDataFormats/JetMatching/interface/JetMatchedPartons.h"
13     #include "JetMETCorrections/Objects/interface/JetCorrector.h"
14     #include "MitAna/DataTree/interface/Names.h"
15     #include "MitAna/DataTree/interface/TrackJetCol.h"
16     #include "MitProd/ObjectService/interface/ObjectService.h"
17    
18     using namespace std;
19     using namespace edm;
20     using namespace mithep;
21    
22     //--------------------------------------------------------------------------------------------------
23     FillerTrackJets::FillerTrackJets(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     trackCountingHighEffBJetTagsName_(Conf().getUntrackedParameter<string>
54     ("TrackCountingHighEffBJetTagsName","trackCountingHighEffBJetTags")),
55     trackCountingHighPurBJetTagsName_(Conf().getUntrackedParameter<string>
56     ("TrackCountingHighPurBJetTagsName","trackCountingHighPurBJetTags")),
57     softMuonBJetTagsName_(Conf().getUntrackedParameter<string>
58     ("SoftMuonBJetTagsName","softMuonBJetTags")),
59     softMuonByIP3dBJetTagsName_(Conf().getUntrackedParameter<string>
60     ("SoftMuonByIP3dBJetTagsName","softMuonByIP3dBJetTags")),
61     softMuonByPtBJetTagsName_(Conf().getUntrackedParameter<string>
62     ("SoftMuonByPtBJetTagsName","softMuonByPtBJetTags")),
63     softElectronByIP3dBJetTagsName_(Conf().getUntrackedParameter<string>
64     ("SoftElectronByIP3dBJetTagsName","softElectronByIP3dBJetTags")),
65     softElectronByPtBJetTagsName_(Conf().getUntrackedParameter<string>
66     ("SoftElectronByPtBJetTagsName","softElectronByPtBJetTags")),
67     trackMapName_(Conf().getUntrackedParameter<string>("trackMapName","trackMapName")),
68     vertexMapName_(Conf().getUntrackedParameter<string>("vertexMapName","")),
69     jetMapName_(Conf().getUntrackedParameter<string>("jetMapName","TrackJetMap")),
70     trackMap_(0),
71     vertexMap_(0),
72     jetMap_(new mithep::TrackJetMap),
73     jets_(new mithep::TrackJetArr(16))
74     {
75     // Constructor.
76     }
77    
78     //--------------------------------------------------------------------------------------------------
79     FillerTrackJets::~FillerTrackJets()
80     {
81     // Destructor.
82    
83     delete jets_;
84     delete jetMap_;
85     }
86    
87     //--------------------------------------------------------------------------------------------------
88 bendavid 1.2 void FillerTrackJets::BookDataBlock(TreeWriter &tws)
89 bendavid 1.1 {
90     // Add jets branch to tree.
91    
92     tws.AddBranch(mitName_,&jets_);
93     OS()->add<mithep::TrackJetArr>(jets_,mitName_);
94    
95     if (!trackMapName_.empty()) {
96     trackMap_ = OS()->get<TrackMap>(trackMapName_);
97     if (trackMap_)
98     AddBranchDep(mitName_,trackMap_->GetBrName());
99     }
100     if (!vertexMapName_.empty()) {
101     vertexMap_ = OS()->get<VertexMap>(vertexMapName_);
102     if (vertexMap_)
103     AddBranchDep(mitName_,vertexMap_->GetBrName());
104     }
105     if (!jetMapName_.empty()) {
106     jetMap_->SetBrName(mitName_);
107     OS()->add<TrackJetMap>(jetMap_,jetMapName_);
108     }
109     }
110    
111     //--------------------------------------------------------------------------------------------------
112     void FillerTrackJets::FillDataBlock(const edm::Event &event,
113     const edm::EventSetup &setup)
114     {
115     // Fill jets from edm collection into our collection.
116    
117     jets_->Delete();
118     jetMap_->Reset();
119    
120     // handle for the Jet Collection
121     Handle<reco::TrackJetCollection> hJetProduct;
122     GetProduct(edmName_, hJetProduct, event);
123    
124     // handles for jet flavour matching
125     Handle<reco::JetMatchedPartonsCollection> hPartonMatchingProduct;
126     if (flavorMatchingActive_)
127     GetProduct(flavorMatchingByReferenceName_, hPartonMatchingProduct, event);
128    
129     Handle<reco::JetTagCollection> hJetProbabilityBJetTags;
130     Handle<reco::JetTagCollection> hJetBProbabilityBJetTags;
131     Handle<reco::JetTagCollection> hSimpleSecondaryVertexBJetTags;
132     Handle<reco::JetTagCollection> hCombinedSecondaryVertexBJetTags;
133     Handle<reco::JetTagCollection> hCombinedSecondaryVertexMVABJetTags;
134     Handle<reco::JetTagCollection> hTrackCountingHighEffBJetTags;
135     Handle<reco::JetTagCollection> hTrackCountingHighPurBJetTags;
136     Handle<reco::JetTagCollection> hSoftMuonBJetTags;
137     Handle<reco::JetTagCollection> hSoftMuonByIP3dBJetTags;
138     Handle<reco::JetTagCollection> hSoftMuonByPtBJetTags;
139     Handle<reco::JetTagCollection> hSoftElectronByIP3dBJetTags;
140     Handle<reco::JetTagCollection> hSoftElectronByPtBJetTags;
141    
142     if (bTaggingActive_) {
143     GetProduct(jetProbabilityBJetTagsName_, hJetProbabilityBJetTags, event);
144     GetProduct(jetBProbabilityBJetTagsName_, hJetBProbabilityBJetTags, event);
145     GetProduct(simpleSecondaryVertexBJetTagsName_, hSimpleSecondaryVertexBJetTags, event);
146     GetProduct(combinedSecondaryVertexBJetTagsName_, hCombinedSecondaryVertexBJetTags, event);
147     GetProduct(combinedSecondaryVertexMVABJetTagsName_, hCombinedSecondaryVertexMVABJetTags, event);
148     GetProduct(trackCountingHighEffBJetTagsName_, hTrackCountingHighEffBJetTags, event);
149     GetProduct(trackCountingHighPurBJetTagsName_, hTrackCountingHighPurBJetTags, event);
150     GetProduct(softMuonBJetTagsName_, hSoftMuonBJetTags, event);
151     GetProduct(softMuonByIP3dBJetTagsName_, hSoftMuonByIP3dBJetTags, event);
152     GetProduct(softMuonByPtBJetTagsName_, hSoftMuonByPtBJetTags, event);
153     GetProduct(softElectronByIP3dBJetTagsName_, hSoftElectronByIP3dBJetTags, event);
154     GetProduct(softElectronByPtBJetTagsName_, hSoftElectronByPtBJetTags, event);
155     }
156    
157     const reco::TrackJetCollection inJets = *(hJetProduct.product());
158    
159     //Handles to Jet to Vertex Association
160     Handle<std::vector<double> > JV_alpha;
161     Handle<std::vector<double> > JV_beta;
162     std::vector<double>::const_iterator it_jv_alpha;
163     std::vector<double>::const_iterator it_jv_beta;
164    
165     if (jetToVertexActive_) {
166     GetProduct(jetToVertexAlphaName_, JV_alpha, event);
167     GetProduct(jetToVertexBetaName_, JV_beta, event);
168     it_jv_alpha = JV_alpha->begin();
169     it_jv_beta = JV_beta->begin();
170     }
171    
172     //Define Jet Correction Services
173     const JetCorrector* correctorL2 = 0;
174     const JetCorrector* correctorL3 = 0;
175     if (jetCorrectionsActive_) {
176     correctorL2 = JetCorrector::getJetCorrector (L2JetCorrectorName_,setup);
177     correctorL3 = JetCorrector::getJetCorrector (L3JetCorrectorName_,setup);
178     }
179    
180     // loop through all jets
181     for (reco::TrackJetCollection::const_iterator inJet = inJets.begin();
182     inJet != inJets.end(); ++inJet) {
183    
184     reco::TrackJetRef jetRef(hJetProduct, inJet - inJets.begin());
185     reco::JetBaseRef jetBaseRef(jetRef);
186    
187     mithep::TrackJet *jet = jets_->Allocate();
188     new (jet) mithep::TrackJet(inJet->p4().x(),
189     inJet->p4().y(),
190     inJet->p4().z(),
191     inJet->p4().e());
192    
193     //add to map
194     edm::Ptr<reco::TrackJet> thePtr(hJetProduct, inJet - inJets.begin());
195     jetMap_->Add(thePtr, jet);
196    
197     //fill TrackJet specific quantities
198     //fill primary vertex reference
199     if (inJet->primaryVertex().isNonnull()) {
200     jet->SetVertex(vertexMap_->GetMit(refToPtr(inJet->primaryVertex())));
201     }
202    
203    
204     if (jetToVertexActive_) {
205     //compute alpha and beta parameter for jets
206     jet->SetAlpha((*it_jv_alpha));
207     jet->SetBeta((*it_jv_beta));
208     }
209    
210     //Jet Corrections
211     if (jetCorrectionsActive_) {
212     double L2Scale = correctorL2->correction(inJet->p4());
213     double L3Scale = correctorL3->correction(inJet->p4()*L2Scale);
214     jet->SetL2RelativeCorrectionScale(L2Scale);
215     jet->SetL3AbsoluteCorrectionScale(L3Scale);
216     jet->EnableCorrection(mithep::TrackJet::L2);
217     jet->EnableCorrection(mithep::TrackJet::L3);
218     }
219    
220     if (bTaggingActive_) {
221     jet->SetJetProbabilityBJetTagsDisc((*(hJetProbabilityBJetTags.product()))[jetBaseRef]);
222     jet->SetJetBProbabilityBJetTagsDisc((*(hJetBProbabilityBJetTags.product()))[jetBaseRef]);
223     jet->SetSimpleSecondaryVertexBJetTagsDisc(
224     (*(hSimpleSecondaryVertexBJetTags.product()))[jetBaseRef]);
225     jet->SetCombinedSecondaryVertexBJetTagsDisc(
226     (*(hCombinedSecondaryVertexBJetTags.product()))[jetBaseRef]);
227     jet->SetCombinedSecondaryVertexMVABJetTagsDisc(
228     (*(hCombinedSecondaryVertexMVABJetTags.product()))[jetBaseRef]);
229     jet->SetTrackCountingHighEffBJetTagsDisc(
230     (*(hTrackCountingHighEffBJetTags.product()))[jetBaseRef]);
231     jet->SetTrackCountingHighPurBJetTagsDisc(
232     (*(hTrackCountingHighPurBJetTags.product()))[jetBaseRef]);
233     jet->SetSoftMuonBJetTagsDisc((*(hSoftMuonBJetTags.product()))[jetBaseRef]);
234     jet->SetSoftMuonByIP3dBJetTagsDisc((*(hSoftMuonByIP3dBJetTags.product()))[jetBaseRef]);
235     jet->SetSoftMuonByPtBJetTagsDisc((*(hSoftMuonByPtBJetTags.product()))[jetBaseRef]);
236     jet->SetSoftElectronByIP3dBJetTagsDisc((*(hSoftElectronByIP3dBJetTags.product()))[jetBaseRef]);
237     jet->SetSoftElectronByPtBJetTagsDisc((*(hSoftElectronByPtBJetTags.product()))[jetBaseRef]);
238     }
239    
240     // get the Monte Carlo flavour matching information
241     if (flavorMatchingActive_) {
242     unsigned int iJet = inJet - inJets.begin();
243     const reco::JetMatchedPartonsCollection *matchedPartons = hPartonMatchingProduct.product();
244     reco::MatchedPartons matchedParton = (*matchedPartons)[matchedPartons->key(iJet)];
245     int flavorPhysDef = (matchedParton.physicsDefinitionParton().isNonnull())?
246     matchedParton.physicsDefinitionParton()->pdgId():0;
247     int flavorAlgDef = (matchedParton.algoDefinitionParton().isNonnull())?
248     matchedParton.algoDefinitionParton()->pdgId():0;
249    
250     if (flavorMatchingDefinition_ == "Algorithmic") {
251     jet->SetMatchedMCFlavor(flavorAlgDef);
252     } else if(flavorMatchingDefinition_ == "Physics") {
253     jet->SetMatchedMCFlavor(flavorPhysDef);
254     } else {
255     jet->SetMatchedMCFlavor(0);
256     }
257     }
258    
259     // add track refs
260     if (trackMap_) {
261     for (uint i=0; i<inJet->numberOfTracks(); ++i) {
262     const edm::Ptr<reco::Track> trkPtr = inJet->track(i);
263     const mithep::Track *track = trackMap_->GetMit(trkPtr);
264     jet->AddTrack(track);
265     }
266     }
267     if (jetToVertexActive_) {
268     it_jv_alpha++;
269     it_jv_beta++;
270     }
271     }
272     jets_->Trim();
273     }