ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/CmsHi/JetAnalysis/src/HiJetResponseAnalyzer.cc
Revision: 1.8
Committed: Thu Oct 21 16:24:04 2010 UTC (14 years, 6 months ago) by yilmaz
Content type: text/plain
Branch: MAIN
Changes since 1.7: +50 -39 lines
Log Message:
test new analysis

File Contents

# User Rev Content
1 yilmaz 1.1 // -*- C++ -*-
2     //
3     // Package: HiJetResponseAnalyzer
4     // Class: HiJetResponseAnalyzer
5     //
6     /**\class HiJetResponseAnalyzer HiJetResponseAnalyzer.cc CmsHi/HiJetResponseAnalyzer/src/HiJetResponseAnalyzer.cc
7    
8     Description: [one line class summary]
9    
10     Implementation:
11     [Notes on implementation]
12     */
13     //
14     // Original Author: Yetkin Yilmaz
15     // Created: Thu Sep 9 10:38:59 EDT 2010
16 yilmaz 1.8 // $Id: HiJetResponseAnalyzer.cc,v 1.7 2010/10/21 11:26:40 yilmaz Exp $
17 yilmaz 1.1 //
18     //
19    
20    
21     // system include files
22     #include <memory>
23 yilmaz 1.2 #include <iostream>
24 yilmaz 1.1
25     // user include files
26     #include "FWCore/Framework/interface/Frameworkfwd.h"
27     #include "FWCore/Framework/interface/EDAnalyzer.h"
28    
29     #include "FWCore/Framework/interface/Event.h"
30     #include "FWCore/Framework/interface/MakerMacros.h"
31    
32     #include "FWCore/ParameterSet/interface/ParameterSet.h"
33    
34     #include "FWCore/Utilities/interface/InputTag.h"
35     #include "DataFormats/HeavyIonEvent/interface/CentralityBins.h"
36     #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
37     #include "DataFormats/HeavyIonEvent/interface/Centrality.h"
38     #include "DataFormats/PatCandidates/interface/Jet.h"
39     #include "SimDataFormats/HiGenData/interface/GenHIEvent.h"
40     #include "DataFormats/JetReco/interface/CaloJetCollection.h"
41     #include "DataFormats/JetReco/interface/GenJetCollection.h"
42    
43 yilmaz 1.2 #include "CommonTools/UtilAlgos/interface/TFileService.h"
44     #include "FWCore/ServiceRegistry/interface/Service.h"
45 yilmaz 1.6 #include "DataFormats/Math/interface/deltaR.h"
46 yilmaz 1.2
47 yilmaz 1.1 #include "TTree.h"
48    
49     using namespace std;
50    
51     static const int MAXJETS = 500;
52    
53     struct etdr{
54     double et;
55     double dr;
56     };
57    
58     struct JRA{
59    
60     int nref;
61     int bin;
62     float b;
63     float hf;
64     float jtpt[MAXJETS];
65 yilmaz 1.4 float jtcorpt[MAXJETS];
66 yilmaz 1.1 float refpt[MAXJETS];
67     float jteta[MAXJETS];
68     float refeta[MAXJETS];
69     float jtphi[MAXJETS];
70     float refphi[MAXJETS];
71    
72     float weight;
73     };
74    
75 yilmaz 1.6 struct JRAV{
76 yilmaz 1.8 int index;
77 yilmaz 1.6 float jtpt;
78     float jtcorpt;
79     float refpt;
80     float refcorpt;
81     float jteta;
82     float refeta;
83     float jtphi;
84     float refphi;
85    
86     };
87    
88 yilmaz 1.1 //
89     // class declaration
90     //
91 yilmaz 1.6 bool compareCorPt(JRAV a, JRAV b) {return a.jtcorpt > b.jtcorpt;}
92     bool comparePt(JRAV a, JRAV b) {return a.jtpt > b.jtpt;}
93 yilmaz 1.1
94     class HiJetResponseAnalyzer : public edm::EDAnalyzer {
95     public:
96     explicit HiJetResponseAnalyzer(const edm::ParameterSet&);
97     ~HiJetResponseAnalyzer();
98    
99    
100     private:
101     virtual void beginJob() ;
102     virtual void analyze(const edm::Event&, const edm::EventSetup&);
103     virtual void endJob() ;
104 yilmaz 1.5 bool selectJet(int i);
105 yilmaz 1.1 // ----------member data ---------------------------
106    
107 yilmaz 1.6 bool usePat_;
108     bool doMC_;
109     bool filterJets_;
110     bool diJetsOnly_;
111     bool matchDiJets_;
112     bool matchPatGen_;
113     bool matchNew_;
114     bool sortJets_;
115     bool correctJets_;
116 yilmaz 1.5
117 yilmaz 1.6 double matchR_;
118 yilmaz 1.5 double genPtMin_;
119     double ptMin_;
120     double emfMin_;
121     double n90Min_;
122     double n90hitMin_;
123 yilmaz 1.2
124 yilmaz 1.8 edm::InputTag jetTag_;
125 yilmaz 1.6 edm::InputTag matchTag_;
126 yilmaz 1.8 std::vector<edm::InputTag> matchTags_;
127    
128     JRA jra_;
129     std::vector<JRA> jraMatch_;
130 yilmaz 1.2
131 yilmaz 1.1 TTree* t;
132    
133     edm::Handle<edm::GenHIEvent> mc;
134     edm::Handle<reco::Centrality> cent;
135    
136     edm::Handle<reco::JetView> jets;
137 yilmaz 1.5 edm::Handle<pat::JetCollection> patjets;
138 yilmaz 1.6 edm::Handle<reco::JetView> matchedJets;
139 yilmaz 1.1
140 yilmaz 1.2 edm::Service<TFileService> fs;
141 yilmaz 1.1
142     };
143    
144 yilmaz 1.5 bool HiJetResponseAnalyzer::selectJet(int i){
145     const reco::Jet& jet = (*jets)[i];
146     if(usePat_){
147     const pat::Jet& patjet = (*patjets)[i];
148     if(patjet.emEnergyFraction() <= emfMin_) return false;
149     if(patjet.jetID().n90Hits <= n90hitMin_) return false;
150     if(doMC_){
151    
152     }
153    
154     }
155    
156     return true;
157     }
158    
159    
160 yilmaz 1.1 //
161     // constants, enums and typedefs
162     //
163    
164     //
165     // static data member definitions
166     //
167    
168     //
169     // constructors and destructor
170     //
171     HiJetResponseAnalyzer::HiJetResponseAnalyzer(const edm::ParameterSet& iConfig)
172    
173     {
174     //now do what ever initialization is needed
175 yilmaz 1.6 matchR_ = iConfig.getUntrackedParameter<double>("matchR",0.25);
176 yilmaz 1.2
177 yilmaz 1.5 ptMin_ = iConfig.getUntrackedParameter<double>("ptMin",0);
178 yilmaz 1.6 genPtMin_ = iConfig.getUntrackedParameter<double>("genPtMin",20);
179     emfMin_ = iConfig.getUntrackedParameter<double>("emfMin",0.01);
180     n90Min_ = iConfig.getUntrackedParameter<double>("n90Min",1);
181     n90hitMin_ = iConfig.getUntrackedParameter<double>("n90hitMin",1);
182 yilmaz 1.5
183     filterJets_ = iConfig.getUntrackedParameter<bool>("filterJets",true);
184 yilmaz 1.6 diJetsOnly_ = iConfig.getUntrackedParameter<bool>("diJetsOnly",false);
185     matchDiJets_ = iConfig.getUntrackedParameter<bool>("matchDiJets",false);
186     matchPatGen_ = iConfig.getUntrackedParameter<bool>("matchPatGen",false);
187    
188     matchNew_ = iConfig.getUntrackedParameter<bool>("matchNew",false);
189    
190 yilmaz 1.4 usePat_ = iConfig.getUntrackedParameter<bool>("usePat",true);
191     doMC_ = iConfig.getUntrackedParameter<bool>("doMC",true);
192 yilmaz 1.6
193     sortJets_ = iConfig.getUntrackedParameter<bool>("sortJets",true);
194     correctJets_ = iConfig.getUntrackedParameter<bool>("correctJets",false);
195    
196 yilmaz 1.4 jetTag_ = iConfig.getUntrackedParameter<edm::InputTag>("src",edm::InputTag("selectedPatJets"));
197 yilmaz 1.6 matchTag_ = iConfig.getUntrackedParameter<edm::InputTag>("match",edm::InputTag("selectedPatJets"));
198 yilmaz 1.8 matchTags_ = iConfig.getUntrackedParameter<std::vector<edm::InputTag> >("matches",std::vector<edm::InputTag>(0));
199 yilmaz 1.1 }
200    
201    
202     HiJetResponseAnalyzer::~HiJetResponseAnalyzer()
203     {
204    
205     // do anything here that needs to be done at desctruction time
206     // (e.g. close files, deallocate resources etc.)
207    
208     }
209    
210    
211     //
212     // member functions
213     //
214    
215     // ------------ method called to for each event ------------
216     void
217     HiJetResponseAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
218     {
219     using namespace edm;
220    
221 yilmaz 1.2 iEvent.getByLabel(jetTag_,jets);
222 yilmaz 1.4 if(usePat_)iEvent.getByLabel(jetTag_,patjets);
223 yilmaz 1.6 std::vector<JRAV> jraV;
224 yilmaz 1.4
225 yilmaz 1.1 for(unsigned int j = 0 ; j < jets->size(); ++j){
226 yilmaz 1.6 if(filterJets_ && !selectJet(j)) continue;
227     const reco::Jet& jet = (*jets)[j];
228     JRAV jv;
229     jv.jtpt = jet.pt();
230     jv.jteta = jet.eta();
231     jv.jtphi = jet.phi();
232     jv.jtcorpt = jet.pt();
233 yilmaz 1.8 jv.index = j;
234 yilmaz 1.6 if(usePat_){
235     const pat::Jet& patjet = (*patjets)[j];
236    
237     jv.jtpt = patjet.correctedJet("raw").pt();
238     jv.jtcorpt = patjet.pt();
239    
240     if(doMC_ && matchPatGen_ && patjet.genJet() != 0){
241     if(patjet.genJet()->pt() < genPtMin_) continue;
242     jv.refpt = patjet.genJet()->pt();
243     jv.refeta = patjet.genJet()->eta();
244     jv.refphi = patjet.genJet()->phi();
245     }else{
246     jv.refpt = -99;
247     jv.refeta = -99;
248     jv.refphi = -99;
249     }
250     }
251    
252     jraV.push_back(jv);
253     }
254    
255     if(sortJets_){
256     if(usePat_ || correctJets_) std::sort(jraV.begin(),jraV.end(),compareCorPt);
257     else std::sort(jraV.begin(),jraV.end(),comparePt);
258     }
259 yilmaz 1.4
260 yilmaz 1.6 for(unsigned int i = 0; i < jraV.size(); ++i){
261     JRAV& jv = jraV[i];
262 yilmaz 1.8 const reco::Jet& jet = (*jets)[jv.index];
263    
264     if(matchNew_){
265     for(unsigned int im = 0; im < matchTags_.size(); ++im){
266     iEvent.getByLabel(matchTags_[im],matchedJets);
267     for(unsigned int m = 0 ; m < matchedJets->size(); ++m){
268     const reco::Jet& match = (*matchedJets)[m];
269     double dr = reco::deltaR(jet.eta(),jet.phi(),match.eta(),match.phi());
270     if(dr < matchR_){
271     jraMatch_[im].jtcorpt[i] = -99;
272     jraMatch_[im].jtpt[i] = match.pt();
273     jraMatch_[im].jteta[i] = match.eta();
274     jraMatch_[im].jtphi[i] = match.phi();
275     }
276     }
277     }
278     }
279    
280 yilmaz 1.7 jra_.jtpt[i] = jv.jtpt;
281     jra_.jteta[i] = jv.jteta;
282     jra_.jtphi[i] = jv.jtphi;
283     jra_.jtcorpt[i] = jv.jtcorpt;
284     jra_.refpt[i] = jv.refpt;
285     jra_.refeta[i] = jv.refeta;
286     jra_.refphi[i] = jv.refphi;
287 yilmaz 1.1 }
288 yilmaz 1.6 jra_.nref = jraV.size();
289 yilmaz 1.8
290 yilmaz 1.1 t->Fill();
291    
292     }
293    
294 yilmaz 1.8 // ------------ method called once each job just before starting event loop ------------
295    
296 yilmaz 1.1
297     void
298 yilmaz 1.8 HiJetResponseAnalyzer::beginJob(){
299     t= fs->make<TTree>("t","Jet Response Analyzer");
300     t->Branch("b",&jra_.b,"b/F");
301     t->Branch("hf",&jra_.hf,"hf/F");
302     t->Branch("nref",&jra_.nref,"nref/I");
303     t->Branch("jtpt",jra_.jtpt,"jtpt[nref]/F");
304     t->Branch("jtcorpt",jra_.jtcorpt,"jtcorpt[nref]/F");
305     t->Branch("jteta",jra_.jteta,"jteta[nref]/F");
306     t->Branch("jtphi",jra_.jtphi,"jtphi[nref]/F");
307     t->Branch("refpt",jra_.refpt,"refpt[nref]/F");
308     t->Branch("refcorpt",jra_.refpt,"refcorpt[nref]/F");
309 yilmaz 1.2 t->Branch("refeta",jra_.refeta,"refeta[nref]/F");
310     t->Branch("refphi",jra_.refphi,"refphi[nref]/F");
311     t->Branch("weight",&jra_.weight,"weight/F");
312     t->Branch("bin",&jra_.bin,"bin/I");
313 yilmaz 1.8 for(unsigned int im = 0; im < matchTags_.size(); ++im){
314     JRA jrm;
315     jraMatch_.push_back(jrm);
316     t->Branch(Form("jtpt%d",im),jraMatch_[im].jtpt,Form("jtpt%d[nref]/F",im));
317     t->Branch(Form("jtcorpt%d",im),jraMatch_[im].jtcorpt,Form("jtcorpt%d[nref]/F",im));
318     t->Branch(Form("jteta%d",im),jraMatch_[im].jteta,Form("jteta%d[nref]/F",im));
319     t->Branch(Form("jtphi%d",im),jraMatch_[im].jtphi,Form("jtphi%d[nref]/F",im));
320     }
321    
322 yilmaz 1.1 }
323    
324     // ------------ method called once each job just after ending the event loop ------------
325     void
326     HiJetResponseAnalyzer::endJob() {
327     }
328    
329     //define this as a plug-in
330     DEFINE_FWK_MODULE(HiJetResponseAnalyzer);