CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/RecoJets/JetAnalyzers/src/CMSDAS11DijetTestAnalyzer.cc

Go to the documentation of this file.
00001 // CMSDAS11DijetTestAnalyzer.cc
00002 // Description: A basic dijet analyzer for the CMSDAS 2011
00003 // Author: John Paul Chou
00004 // Date: January 12, 2011
00005 
00006 #include "RecoJets/JetAnalyzers/interface/CMSDAS11DijetTestAnalyzer.h"
00007 
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 #include "FWCore/Framework/interface/MakerMacros.h"
00010 #include "FWCore/ServiceRegistry/interface/Service.h"
00011 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00012 
00013 #include "DataFormats/VertexReco/interface/Vertex.h"
00014 #include "JetMETCorrections/Objects/interface/JetCorrector.h"
00015 
00016 #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
00017 #include "SimDataFormats/GeneratorProducts/interface/GenRunInfoProduct.h"
00018 
00019 #include <TH1D.h>
00020 #include <TH2D.h>
00021 
00022 CMSDAS11DijetTestAnalyzer::CMSDAS11DijetTestAnalyzer(edm::ParameterSet const& params) :
00023   edm::EDAnalyzer(),
00024   jetSrc(params.getParameter<edm::InputTag>("jetSrc")),
00025   vertexSrc(params.getParameter<edm::InputTag>("vertexSrc")),
00026   jetCorrections(params.getParameter<std::string>("jetCorrections")),
00027   innerDeltaEta(params.getParameter<double>("innerDeltaEta")),
00028   outerDeltaEta(params.getParameter<double>("outerDeltaEta")),
00029   JESbias(params.getParameter<double>("JESbias"))
00030 {
00031   // setup file service
00032   edm::Service<TFileService> fs;
00033 
00034   const int NBINS=36;
00035   Double_t BOUNDARIES[NBINS] = { 220, 244, 270, 296, 325, 354, 386, 419, 453,
00036                                  489, 526, 565, 606, 649, 693, 740, 788, 838,
00037                                  890, 944, 1000, 1058, 1118, 1181, 1246, 1313, 1383,
00038                                  1455, 1530, 1607, 1687, 1770, 1856, 1945, 2037, 2132 };
00039   
00040   // setup histograms
00041   hVertexZ = fs->make<TH1D>("hVertexZ", "Z position of the Vertex",50,-20,20);
00042   hJetRawPt    = fs->make<TH1D>("hJetRawPt","Raw Jet Pt",50,0,1000);
00043   hJetCorrPt = fs->make<TH1D>("hJetCorrPt","Corrected Jet Pt",50,0,1000);
00044   hJet1Pt      = fs->make<TH1D>("hJet1Pt","Corrected Jet1 Pt",50,0,1000);
00045   hJet2Pt      = fs->make<TH1D>("hJet2Pt","Corrected Jet2 Pt",50,0,1000);
00046 
00047   hJetEta      = fs->make<TH1D>("hJetEta","Corrected Jet Eta",   50,-5,5);
00048   hJet1Eta      = fs->make<TH1D>("hJet1Eta","Corrected Jet1 Eta",50,-5,5);
00049   hJet2Eta      = fs->make<TH1D>("hJet2Eta","Corrected Jet2 Eta",50,-5,5);
00050 
00051   hJetPhi      = fs->make<TH1D>("hJetPhi","Corrected Jet Phi",   50,-3.1415,3.1415);
00052   hJet1Phi      = fs->make<TH1D>("hJet1Phi","Corrected Jet1 Phi",50,-3.1415,3.1415);
00053   hJet2Phi      = fs->make<TH1D>("hJet2Phi","Corrected Jet2 Phi",50,-3.1415,3.1415);
00054 
00055   hJetEMF       = fs->make<TH1D>("hJetEMF","EM Fraction of Jets",50,0,1);
00056   hJet1EMF      = fs->make<TH1D>("hJet1EMF","EM Fraction of Jet1",50,0,1);
00057   hJet2EMF      = fs->make<TH1D>("hJet2EMF","EM Fraction of Jet2",50,0,1);
00058 
00059   hCorDijetMass = fs->make<TH1D>("hCorDijetMass","Corrected Dijet Mass",NBINS-1,BOUNDARIES);
00060   hDijetDeltaPhi= fs->make<TH1D>("hDijetDeltaPhi","Dijet |#Delta #phi|",50,0,3.1415);
00061   hDijetDeltaEta= fs->make<TH1D>("hDijetDeltaEta","Dijet |#Delta #eta|",50,0,1.3);
00062   hDijetDeltaPhiNJets= fs->make<TH2D>("hDijetDeltaPhiNJets","Dijet |#Delta #phi| v. the number of jets",50,0,3.1415,7,0.5,7.5);
00063   hDijetEta1Eta2=fs->make<TH2D>("hDijetEta1Eta2","Eta 1 versus Eta 2 of dijet events",50,-5,5,50,-5,5);
00064 
00065   hInnerDijetMass = fs->make<TH1D>("hInnerDijetMass","Corrected Inner Dijet Mass",NBINS-1,BOUNDARIES);
00066   hOuterDijetMass = fs->make<TH1D>("hOuterDijetMass","Corrected Outer Dijet Mass",NBINS-1,BOUNDARIES);
00067 }
00068 
00069 void CMSDAS11DijetTestAnalyzer::endJob(void) {
00070 }
00071 
00072 void CMSDAS11DijetTestAnalyzer::analyze( const edm::Event& iEvent, const edm::EventSetup& iSetup)
00073 {
00075   double mWeight;
00076   edm::Handle<GenEventInfoProduct> hEventInfo;
00077   iEvent.getByLabel("generator", hEventInfo);
00078   if (hEventInfo.isValid()) {
00079     mWeight = hEventInfo->weight();
00080   }
00081   else 
00082     mWeight = 1.;
00083   
00085   // Get event ID information
00087   //int nrun=iEvent.id().run();
00088   //int nlumi=iEvent.luminosityBlock();
00089   //int nevent=iEvent.id().event();
00090 
00092   // Get Primary Vertex Information
00094 
00095   // magic to get the vertices from EDM
00096   edm::Handle< std::vector<reco::Vertex> > vertices_h;
00097   iEvent.getByLabel(vertexSrc, vertices_h);
00098   if (!vertices_h.isValid()) {
00099     std::cout<<"Didja hear the one about the empty vertex collection?\n";
00100     return;
00101   }
00102   
00103   // require in the event that there is at least one reconstructed vertex
00104   if(vertices_h->size()<=0) return;
00105 
00106   // pick the first (i.e. highest sum pt) verte
00107   const reco::Vertex* theVertex=&(vertices_h->front());
00108 
00109   // require that the vertex meets certain criteria
00110   if(theVertex->ndof()<5) return;
00111   if(fabs(theVertex->z())>24.0) return;
00112   if(fabs(theVertex->position().rho())>2.0) return;
00113 
00115   // Get Jet Information
00117 
00118   // magic to get the jets from EDM
00119   edm::Handle<reco::CaloJetCollection> jets_h;
00120   iEvent.getByLabel(jetSrc, jets_h);
00121   if (!jets_h.isValid()) {
00122     std::cout<<"Didja hear the one about the empty jet collection?\n";
00123     return;
00124   }
00125 
00126   // magic to get the jet energy corrections
00127   const JetCorrector* corrector = JetCorrector::getJetCorrector(jetCorrections,iSetup);
00128   corrector->vectorialCorrection();
00129   // collection of selected jets
00130   std::vector<reco::CaloJet> selectedJets;
00131 
00132   // loop over the jet collection
00133   for(reco::CaloJetCollection::const_iterator j_it = jets_h->begin(); j_it!=jets_h->end(); j_it++) {
00134     reco::CaloJet jet = *j_it;
00135 
00136     // put the selected jets into a collection
00137     selectedJets.push_back(jet);
00138   }
00139 
00140   hVertexZ->Fill(theVertex->z(), mWeight);
00141   return;
00142 }
00143 
00144 
00145 DEFINE_FWK_MODULE(CMSDAS11DijetTestAnalyzer);