00001
00002 #include <memory>
00003 #include <string>
00004 #include <iostream>
00005 #include <fstream>
00006
00007
00008 #include "FWCore/Framework/interface/Frameworkfwd.h"
00009 #include "FWCore/Framework/interface/EDAnalyzer.h"
00010
00011 #include "FWCore/Framework/interface/Event.h"
00012 #include "DataFormats/Common/interface/Handle.h"
00013 #include "FWCore/Framework/interface/MakerMacros.h"
00014 #include "FWCore/Framework/interface/EventSetup.h"
00015 #include "FWCore/Framework/interface/ESHandle.h"
00016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00017
00018
00019 #include "CLHEP/Vector/LorentzVector.h"
00020 #include "CLHEP/Units/PhysicalConstants.h"
00021 #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
00022 #include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
00023
00024
00025 #include "DataFormats/Math/interface/LorentzVector.h"
00026 #include "DataFormats/Math/interface/Vector3D.h"
00027 #include "Math/GenVector/VectorUtil.h"
00028 #include "Math/GenVector/PxPyPzE4D.h"
00029 #include "DataFormats/Math/interface/deltaR.h"
00030
00031
00032 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00033 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00034 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00035 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00036
00037 #include "DataFormats/JetReco/interface/CaloJet.h"
00038 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00039 #include "DataFormats/JetReco/interface/GenJet.h"
00040 #include "DataFormats/JetReco/interface/GenJetCollection.h"
00041 #include "JetMETCorrections/Objects/interface/JetCorrector.h"
00042
00043
00044 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00045 #include "DataFormats/MuonReco/interface/Muon.h"
00046 #include "DataFormats/TrackReco/interface/Track.h"
00047
00048
00049 #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
00050 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
00051 #include "DataFormats/EgammaReco/interface/ClusterShapeFwd.h"
00052 #include "DataFormats/EgammaReco/interface/BasicClusterShapeAssociation.h"
00053 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00054
00055 #include "DataFormats/Candidate/interface/LeafCandidate.h"
00056 #include "DataFormats/Candidate/interface/Candidate.h"
00057 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00058
00059 #include "TFile.h"
00060 #include "TTree.h"
00061 #include "TH1.h"
00062 #include "TH2.h"
00063
00064 #include "DataFormats/Math/interface/LorentzVector.h"
00065 #include "DataFormats/Math/interface/Vector3D.h"
00066 #include "Math/GenVector/VectorUtil.h"
00067 #include "Math/GenVector/PxPyPzE4D.h"
00068
00069 #include <vector>
00070
00071 using namespace std;
00072 using namespace reco;
00073
00074
00075
00076
00077
00078 class JPTAnalyzer : public edm::EDAnalyzer {
00079 public:
00080 explicit JPTAnalyzer(const edm::ParameterSet&);
00081 ~JPTAnalyzer();
00082
00083
00084 private:
00085 virtual void beginJob(const edm::EventSetup&) ;
00086 virtual void analyze(const edm::Event&, const edm::EventSetup&);
00087 virtual void endJob() ;
00088
00089
00090
00091 string fOutputFileName ;
00092
00093
00094 string calojetsSrc;
00095
00096 string zspjetsSrc;
00097
00098 string genjetsSrc;
00099
00100
00101
00102
00103
00104
00105 string JetCorrectionJPT;
00106
00107 double EtaGen1, PhiGen1, EtaRaw1, PhiRaw1, EtGen1, EtRaw1, EtMCJ1, EtZSP1, EtJPT1, DRMAXgjet1;
00108 double EtaGen2, PhiGen2, EtaRaw2, PhiRaw2, EtGen2, EtRaw2, EtMCJ2, EtZSP2, EtJPT2, DRMAXgjet2;
00109
00110 TFile* hOutputFile ;
00111 TTree* t1;
00112 };
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 void
00124 JPTAnalyzer::beginJob(const edm::EventSetup&)
00125 {
00126 using namespace edm;
00127
00128
00129 hOutputFile = new TFile( fOutputFileName.c_str(), "RECREATE" ) ;
00130
00131 t1 = new TTree("t1","analysis tree");
00132
00133 t1->Branch("EtaGen1",&EtaGen1,"EtaGen1/D");
00134 t1->Branch("PhiGen1",&PhiGen1,"PhiGen1/D");
00135 t1->Branch("EtaRaw1",&EtaRaw1,"EtaRaw1/D");
00136 t1->Branch("PhiRaw1",&PhiRaw1,"PhiRaw1/D");
00137 t1->Branch("EtGen1",&EtGen1,"EtGen1/D");
00138 t1->Branch("EtRaw1",&EtRaw1,"EtRaw1/D");
00139 t1->Branch("EtMCJ1",&EtMCJ1,"EtMCJ1/D");
00140 t1->Branch("EtZSP1",&EtZSP1,"EtZSP1/D");
00141 t1->Branch("EtJPT1",&EtJPT1,"EtJPT1/D");
00142 t1->Branch("DRMAXgjet1",&DRMAXgjet1,"DRMAXgjet1/D");
00143
00144 t1->Branch("EtaGen2",&EtaGen2,"EtaGen2/D");
00145 t1->Branch("PhiGen2",&PhiGen2,"PhiGen2/D");
00146 t1->Branch("EtaRaw2",&EtaRaw2,"EtaRaw2/D");
00147 t1->Branch("PhiRaw2",&PhiRaw2,"PhiRaw2/D");
00148 t1->Branch("EtGen2",&EtGen2,"EtGen2/D");
00149 t1->Branch("EtRaw2",&EtRaw2,"EtRaw2/D");
00150 t1->Branch("EtMCJ2",&EtMCJ2,"EtMCJ2/D");
00151 t1->Branch("EtZSP2",&EtZSP2,"EtZSP2/D");
00152 t1->Branch("EtJPT2",&EtJPT2,"EtJPT2/D");
00153 t1->Branch("DRMAXgjet2",&DRMAXgjet2,"DRMAXgjet2/D");
00154
00155 return ;
00156 }
00157
00158
00159 void
00160 JPTAnalyzer::endJob() {
00161
00162 hOutputFile->Write() ;
00163 hOutputFile->Close() ;
00164
00165 return ;
00166 }
00167
00168
00169
00170
00171 JPTAnalyzer::JPTAnalyzer(const edm::ParameterSet& iConfig)
00172
00173 {
00174
00175 using namespace edm;
00176
00177
00178 fOutputFileName = iConfig.getUntrackedParameter<string>("HistOutFile");
00179
00180
00181
00182 calojetsSrc = iConfig.getParameter< std::string > ("calojets");
00183
00184 zspjetsSrc = iConfig.getParameter< std::string > ("zspjets");
00185 genjetsSrc = iConfig.getParameter< std::string > ("genjets");
00186
00187
00188
00189
00190
00191
00192 JetCorrectionJPT = iConfig.getParameter< std::string > ("JetCorrectionJPT");
00193 }
00194
00195
00196 JPTAnalyzer::~JPTAnalyzer()
00197 {
00198
00199
00200
00201
00202 }
00203
00204
00205
00206
00207
00208
00209
00210 void
00211 JPTAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00212 {
00213 using namespace edm;
00214
00215
00216
00217 vector<HepLorentzVector> gjets;
00218 gjets.clear();
00219
00220
00221 EtaGen1 = 0.;
00222 PhiGen1 = 0.;
00223 EtaRaw1 = 0.;
00224 PhiRaw1 = 0.;
00225 EtGen1 = 0.;
00226 EtRaw1 = 0.;
00227 EtMCJ1 = 0.;
00228 EtZSP1 = 0.;
00229 EtJPT1 = 0.;
00230 DRMAXgjet1 = 1000.;
00231
00232 EtaGen2 = 0.;
00233 PhiGen2 = 0.;
00234 EtaRaw2 = 0.;
00235 PhiRaw2 = 0.;
00236 EtGen2 = 0.;
00237 EtRaw2 = 0.;
00238 EtMCJ2 = 0.;
00239 EtZSP2 = 0.;
00240 EtJPT2 = 0.;
00241 DRMAXgjet2 = 1000.;
00242
00243
00244
00245
00246
00247
00248 edm::Handle<HepMCProduct> EvtHandle ;
00249 iEvent.getByLabel( "source", EvtHandle ) ;
00250
00251
00252
00253 HepLorentzVector l1(0.,0.,1.,1.);
00254 HepLorentzVector l2(0.,0.,1.,1.);
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292 Handle<GenJetCollection> genjets;
00293 iEvent.getByLabel(genjetsSrc, genjets);
00294 int jg = 0;
00295 for(GenJetCollection::const_iterator gjet = genjets->begin();
00296 gjet != genjets->end(); ++gjet ) {
00297 if(gjet->pt() >= 20.) {
00298 HepLorentzVector jet(gjet->px(), gjet->py(), gjet->pz(), gjet->energy());
00299 double drjl1 = l1.deltaR(jet);
00300 double drjl2 = l2.deltaR(jet);
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317 if(drjl1 > 1.0 && drjl2 > 1.0)
00318 {
00319 jg++;
00320 if(jg <= 2) {
00321 gjets.push_back(jet);
00322 }
00323 }
00324 }
00325 }
00326
00327
00328
00329 if(gjets.size() > 0) {
00330
00331 edm::Handle<CaloJetCollection> calojets;
00332 iEvent.getByLabel(calojetsSrc, calojets);
00333
00334 edm::Handle<CaloJetCollection> zspjets;
00335 iEvent.getByLabel(zspjetsSrc, zspjets);
00336
00337
00338
00339
00340 if(calojets->size() > 0) {
00341
00342
00343
00344
00345
00346
00347
00348 const JetCorrector* correctorJPT = JetCorrector::getJetCorrector (JetCorrectionJPT, iSetup);
00349
00350
00351 int jc = 0;
00352
00353 for( CaloJetCollection::const_iterator cjet = calojets->begin();
00354 cjet != calojets->end(); ++cjet ){
00355
00356 HepLorentzVector cjetc(cjet->px(), cjet->py(), cjet->pz(), cjet->energy());
00357
00358
00359
00360
00361
00362 CaloJetCollection::const_iterator zspjet;
00363 for( zspjet = zspjets->begin();
00364 zspjet != zspjets->end(); ++zspjet ){
00365 HepLorentzVector zspjetc(zspjet->px(), zspjet->py(), zspjet->pz(), zspjet->energy());
00366 double dr = zspjetc.deltaR(cjetc);
00367
00368
00369
00370
00371
00372
00373 if(dr < 0.001) break;
00374 }
00375
00376
00377
00378
00379
00380
00381 double scaleJPT = correctorJPT->correction ((*zspjet),iEvent,iSetup);
00382 Jet::LorentzVector jetscaleJPT(zspjet->px()*scaleJPT, zspjet->py()*scaleJPT,
00383 zspjet->pz()*scaleJPT, zspjet->energy()*scaleJPT);
00384
00385
00386
00387
00388
00389 CaloJet cjetJPT(jetscaleJPT, cjet->getSpecific(), cjet->getJetConstituents());
00390
00391 double DRgjet1 = gjets[0].deltaR(cjetc);
00392
00393 if(DRgjet1 < DRMAXgjet1) {
00394 DRMAXgjet1 = DRgjet1;
00395
00396 EtaGen1 = gjets[0].eta();
00397 PhiGen1 = gjets[0].phi();
00398 EtGen1 = gjets[0].perp();
00399
00400 EtaRaw1 = cjet->eta();
00401 PhiRaw1 = cjet->phi();
00402 EtRaw1 = cjet->pt();
00403
00404 EtZSP1 = zspjet->pt();
00405 EtJPT1 = cjetJPT.pt();
00406 }
00407 if(gjets.size() == 2) {
00408 double DRgjet2 = gjets[1].deltaR(cjetc);
00409 if(DRgjet2 < DRMAXgjet2) {
00410 DRMAXgjet2 = DRgjet2;
00411
00412 EtaGen2 = gjets[1].eta();
00413 PhiGen2 = gjets[1].phi();
00414 EtGen2 = gjets[1].perp();
00415
00416 EtaRaw2 = cjet->eta();
00417 PhiRaw2 = cjet->phi();
00418 EtRaw2 = cjet->pt();
00419 EtZSP2 = zspjet->pt();
00420 EtJPT2 = cjetJPT.pt();
00421 }
00422 }
00423 jc++;
00424 }
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435 }
00436 }
00437
00438 t1->Fill();
00439 }
00440
00441
00442
00443 DEFINE_FWK_MODULE(JPTAnalyzer);