CMS 3D CMS Logo

PFJetTester.cc

Go to the documentation of this file.
00001 // Producer for validation histograms for PFJet objects
00002 // J. Weng, based on F. Ratnikov, Sept. 7, 2006
00003 
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005 #include "FWCore/Framework/interface/Event.h"
00006 #include "DataFormats/Common/interface/Handle.h"
00007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00008 #include "FWCore/ServiceRegistry/interface/Service.h"
00009 
00010 #include "DQMServices/Core/interface/DQMStore.h"
00011 #include "DQMServices/Core/interface/MonitorElement.h"
00012 #include "DataFormats/Math/interface/deltaR.h"
00013 #include "DataFormats/JetReco/interface/PFJet.h"
00014 #include "DataFormats/JetReco/interface/GenJet.h"
00015 #include "DataFormats/JetReco/interface/GenJetCollection.h"
00016 
00017 #include "RecoJets/JetAlgorithms/interface/JetMatchingTools.h"
00018 
00019 #include "Validation/RecoJets/src/PFJetTester.h"
00020 
00021 using namespace edm;
00022 using namespace reco;
00023 using namespace std;
00024 namespace {
00025   bool is_B (const reco::Jet& fJet) {return fabs (fJet.eta()) < 1.4;}
00026   bool is_E (const reco::Jet& fJet) {return fabs (fJet.eta()) >= 1.4 && fabs (fJet.eta()) < 3.;}
00027   bool is_F (const reco::Jet& fJet) {return fabs (fJet.eta()) >= 3.;}
00028 }
00029 
00030 PFJetTester::PFJetTester(const edm::ParameterSet& iConfig)
00031   : mInputCollection (iConfig.getParameter<edm::InputTag>( "src" )), 
00032     mInputGenCollection (iConfig.getParameter<edm::InputTag>( "srcGen" )),
00033     mOutputFile (iConfig.getUntrackedParameter<string>("outputFile", "")),
00034     mMatchGenPtThreshold (iConfig.getParameter<double>("genPtThreshold")),
00035     mGenEnergyFractionThreshold (iConfig.getParameter<double>("genEnergyFractionThreshold")),
00036     mReverseEnergyFractionThreshold (iConfig.getParameter<double>("reverseEnergyFractionThreshold")),
00037     mRThreshold (iConfig.getParameter<double>("RThreshold"))
00038 {
00039 
00040   //**** @@@
00041   mEta = mPhi = mE = mP = mPt = mMass = mConstituents
00042     = mEtaFirst = mPhiFirst = mEFirst = mPtFirst 
00043     =mChargedHadronEnergy
00044     = mNeutralHadronEnergy = mChargedEmEnergy = mChargedMuEnergy
00045     = mNeutralEmEnergy =  mChargedMultiplicity = mNeutralMultiplicity
00046     = mMuonMultiplicity =   mAllGenJetsPt = mMatchedGenJetsPt = mAllGenJetsEta = mMatchedGenJetsEta 
00047     = mGenJetMatchEnergyFraction = mReverseMatchEnergyFraction = mRMatch
00048     = mDeltaEta = mDeltaPhi = mEScale = mDeltaE= 0;
00049   //cout<<" PFJetTester -----------------------------------------------------> 1"<<endl;//////////////////////
00050   //cout<<"setting all variables zero -----------------------------------------------------> 2"<<endl;//////////////////////
00051   DQMStore* dbe = &*edm::Service<DQMStore>();
00052   if (dbe) {
00053     //cout<<" Creating the histograms -----------------------------------------------------> 3"<<endl;//////////////////////
00054     dbe->setCurrentFolder("RecoJetsV/PFJetTask_" + mInputCollection.label());
00055     mEta = dbe->book1D("Eta", "Eta", 100, -5, 5); 
00056     mPhi = dbe->book1D("Phi", "Phi", 70, -3.5, 3.5); 
00057     mE = dbe->book1D("E", "E", 100, 0, 500); 
00058     mP = dbe->book1D("P", "P", 100, 0, 500); 
00059     mPt = dbe->book1D("Pt", "Pt", 100, 0, 50); 
00060     mMass = dbe->book1D("Mass", "Mass", 100, 0, 25); 
00061     mConstituents = dbe->book1D("Constituents", "# of Constituents", 100, 0, 100); 
00062     //
00063     mEtaFirst = dbe->book1D("EtaFirst", "EtaFirst", 100, -5, 5); 
00064     mPhiFirst = dbe->book1D("PhiFirst", "PhiFirst", 70, -3.5, 3.5); 
00065     mEFirst = dbe->book1D("EFirst", "EFirst", 100, 0, 1000); 
00066     mPtFirst = dbe->book1D("PtFirst", "PtFirst", 100, 0, 500); 
00067     //
00068     mChargedHadronEnergy = dbe->book1D("mChargedHadronEnergy", "mChargedHadronEnergy", 100, 0, 100); 
00069     mNeutralHadronEnergy = dbe->book1D("mNeutralHadronEnergy", "mNeutralHadronEnergy", 100, 0, 100);  
00070     mChargedEmEnergy= dbe->book1D("mChargedEmEnergy ", "mChargedEmEnergy ", 100, 0, 100); 
00071     mChargedMuEnergy = dbe->book1D("mChargedMuEnergy", "mChargedMuEnergy", 100, 0, 100); 
00072     mNeutralEmEnergy= dbe->book1D("mNeutralEmEnergy", "mNeutralEmEnergy", 100, 0, 100);   
00073     mChargedMultiplicity= dbe->book1D("mChargedMultiplicity ", "mChargedMultiplicity ", 100, 0, 100);     
00074     mNeutralMultiplicity = dbe->book1D(" mNeutralMultiplicity", "mNeutralMultiplicity", 100, 0, 100);
00075     mMuonMultiplicity= dbe->book1D("mMuonMultiplicity", "mMuonMultiplicity", 100, 0, 100);
00076     double log10PtMin = 0.5;
00077     double log10PtMax = 4.;
00078     int log10PtBins = 14;
00079     double etaMin = -5.;
00080     double etaMax = 5.;
00081     int etaBins = 50;
00082     mAllGenJetsPt = dbe->book1D("GenJetLOGpT", "GenJet LOG(pT_gen)", 
00083                                 log10PtBins, log10PtMin, log10PtMax);
00084     mMatchedGenJetsPt = dbe->book1D("MatchedGenJetLOGpT", "MatchedGenJet LOG(pT_gen)", 
00085                                     log10PtBins, log10PtMin, log10PtMax);
00086     mAllGenJetsEta = dbe->book2D("GenJetEta", "GenJet Eta vs LOG(pT_gen)", 
00087                                  log10PtBins, log10PtMin, log10PtMax, etaBins, etaMin, etaMax);
00088     mMatchedGenJetsEta = dbe->book2D("MatchedGenJetEta", "MatchedGenJet Eta vs LOG(pT_gen)", 
00089                                      log10PtBins, log10PtMin, log10PtMax, etaBins, etaMin, etaMax);
00090     mGenJetMatchEnergyFraction  = dbe->book3D("GenJetMatchEnergyFraction", "GenJetMatchEnergyFraction vs LOG(pT_gen) vs eta", 
00091                                               log10PtBins, log10PtMin, log10PtMax, etaBins, etaMin, etaMax, 101, 0, 1.01);
00092     mReverseMatchEnergyFraction  = dbe->book3D("ReverseMatchEnergyFraction", "ReverseMatchEnergyFraction vs LOG(pT_gen) vs eta", 
00093                                                log10PtBins, log10PtMin, log10PtMax, etaBins, etaMin, etaMax, 101, 0, 1.01);
00094     mRMatch  = dbe->book3D("RMatch", "delta(R)(Gen-Calo) vs LOG(pT_gen) vs eta", 
00095                            log10PtBins, log10PtMin, log10PtMax, etaBins, etaMin, etaMax, 60, 0, 3);
00096     mDeltaEta = dbe->book3D("DeltaEta", "DeltaEta vs LOG(pT_gen) vs eta", 
00097                             log10PtBins, log10PtMin, log10PtMax, etaBins, etaMin, etaMax, 100, -1, 1);
00098     mDeltaPhi = dbe->book3D("DeltaPhi", "DeltaPhi vs LOG(pT_gen) vs eta", 
00099                             log10PtBins, log10PtMin, log10PtMax, etaBins, etaMin, etaMax, 100, -1, 1);
00100     mEScale = dbe->book3D("EScale", "EnergyScale vs LOG(pT_gen) vs eta", 
00101                           log10PtBins, log10PtMin, log10PtMax, etaBins, etaMin, etaMax, 100, 0, 2);
00102     mDeltaE = dbe->book3D("DeltaE", "DeltaE vs LOG(pT_gen) vs eta", 
00103                           log10PtBins, log10PtMin, log10PtMax, etaBins, etaMin, etaMax, 2000, -200, 200);
00104 
00105     //__________________________________________________
00106 
00107     mNeutralFraction = dbe->book1D("NeutralFraction","Neutral Fraction",100,0,1);
00108     mEEffNeutralFraction = dbe->book1D("EEffNeutralFraction","E Efficiency vs Neutral Fraction",100,0,1);    //_________________(*)
00109     mEEffChargedFraction = dbe->book1D("EEffChargedFraction","E Efficiency vs Charged Fraction",100,0,1); 
00110     mEResNeutralFraction = dbe->book1D("EResNeutralFraction","E Resolution vs Neutral Fraction",100,0,1);
00111     mEResChargedFraction = dbe->book1D("EResChargedFraction","E Resolution vs Charged Fraction",100,0,1); 
00112     nEEff = dbe->book1D("nEEff","EEff",100,0,1);
00113     mNeutralFraction2 = dbe->book1D("NeutralFraction2","Neutral Fraction 2",100,0,1);
00114     
00115   }
00116   if (mOutputFile.empty ()) {
00117     LogInfo("OutputInfo") << " PFJet histograms will NOT be saved";
00118   } 
00119   else {
00120     LogInfo("OutputInfo") << " PFJethistograms will be saved to file:" << mOutputFile;
00121   }
00122 }
00123    
00124 PFJetTester::~PFJetTester()
00125 {
00126 }
00127 
00128 void PFJetTester::beginJob(const edm::EventSetup& c){
00129 }
00130 
00131 void PFJetTester::endJob() {
00132 
00133   if (!mOutputFile.empty() && &*edm::Service<DQMStore>()) edm::Service<DQMStore>()->save (mOutputFile);
00134   //cout<<" endjob ----------------------------------------------------->"<<endl;//////////////////////
00135 }
00136 
00137 
00138 void PFJetTester::analyze(const edm::Event& mEvent, const edm::EventSetup& mSetup)
00139 {
00140   //cout<<" start analyze -----------------------------------------------------> 4"<<endl;//////////////////////
00141   Handle<PFJetCollection> pfJets;
00142   //cout<<"  -----------------------------------------------------> 4a"<<endl;//////////////////////
00143   mEvent.getByLabel(mInputCollection, pfJets);
00144   //  cout <<"!!!!!!!!!!! " <<mInputCollection << " " <<collection->size() <<endl;
00145   PFJetCollection::const_iterator jet = pfJets->begin ();
00146 
00147   //cout<<"filling the histogramms ------------------------------------------------------------------> 5"<<endl;
00148   for (; jet != pfJets->end (); jet++) {
00149     if (mEta) mEta->Fill (jet->eta());
00150     //cout<<jet->eta()<<" ------------------------------------------------------------------> 6"<<endl;
00151     if (mPhi) mPhi->Fill (jet->phi());
00152     if (mE) mE->Fill (jet->energy());
00153     if (mP) mP->Fill (jet->p());
00154     if (mPt) mPt->Fill (jet->pt());
00155     if (mMass) mMass->Fill (jet->mass());
00156     if (mConstituents) mConstituents->Fill (jet->nConstituents());
00157     if (jet == pfJets->begin ()) { // first jet
00158       if (mEtaFirst) mEtaFirst->Fill (jet->eta());
00159       if (mPhiFirst) mPhiFirst->Fill (jet->phi());
00160       if (mEFirst) mEFirst->Fill (jet->energy());
00161       if (mPtFirst) mPtFirst->Fill (jet->pt());
00162     }
00163     if (mChargedHadronEnergy)  mChargedHadronEnergy->Fill (jet->chargedHadronEnergy());
00164     if (mNeutralHadronEnergy)  mNeutralHadronEnergy->Fill (jet->neutralHadronEnergy());
00165     if (mChargedEmEnergy) mChargedEmEnergy->Fill(jet->chargedEmEnergy());
00166     if (mChargedMuEnergy) mChargedMuEnergy->Fill (jet->chargedMuEnergy ());
00167     if (mNeutralEmEnergy) mNeutralEmEnergy->Fill(jet->neutralEmEnergy()); 
00168     if (mChargedMultiplicity ) mChargedMultiplicity->Fill(jet->chargedMultiplicity());
00169     if (mNeutralMultiplicity ) mNeutralMultiplicity->Fill(jet->neutralMultiplicity());
00170     if (mMuonMultiplicity )mMuonMultiplicity->Fill (jet-> muonMultiplicity());
00171     //_______________________________________________________
00172     if (mNeutralFraction) mNeutralFraction->Fill (jet->neutralMultiplicity()/jet->nConstituents());
00173   } 
00174 
00175   // now match PFJets to GenJets
00176   JetMatchingTools jetMatching (mEvent);
00177   if (!(mInputGenCollection.label().empty())) {
00178     Handle<GenJetCollection> genJets;
00179     mEvent.getByLabel(mInputGenCollection, genJets);
00180 
00181 
00182     for (unsigned iGenJet = 0; iGenJet < genJets->size(); ++iGenJet) {
00183       const GenJet& genJet = (*genJets) [iGenJet];
00184       double genJetPt = genJet.pt();
00185       if (fabs(genJet.eta()) > 5.) continue; // out of detector 
00186       if (genJetPt < mMatchGenPtThreshold) continue; // no low momentum 
00187       double logPtGen = log10 (genJetPt);
00188       mAllGenJetsPt->Fill (logPtGen);
00189       mAllGenJetsEta->Fill (logPtGen, genJet.eta());
00190       if (pfJets->size() <= 0) continue; // no PFJets - nothing to match
00191       if (mRThreshold > 0) {
00192         unsigned iPFJetBest = 0;
00193         double deltaRBest = 999.;
00194         for (unsigned iPFJet = 0; iPFJet < pfJets->size(); ++iPFJet) {
00195           double dR = deltaR (genJet.eta(), genJet.phi(), (*pfJets) [iPFJet].eta(), (*pfJets) [iPFJet].phi());
00196           if (deltaRBest < mRThreshold && dR < mRThreshold && genJet.pt() > 5.) {
00197             std::cout << "Yet another matched jet for GenJet pt=" << genJet.pt()
00198                       << " previous PFJet pt/dr: " << (*pfJets) [iPFJetBest].pt() << '/' << deltaRBest
00199                       << " new PFJet pt/dr: " << (*pfJets) [iPFJet].pt() << '/' << dR
00200                       << std::endl;
00201           }
00202           if (dR < deltaRBest) {
00203             iPFJetBest = iPFJet;
00204             deltaRBest = dR;
00205           }
00206         }
00207         mRMatch->Fill (logPtGen, genJet.eta(), deltaRBest);
00208         if (deltaRBest < mRThreshold) { // Matched
00209           fillMatchHists (genJet, (*pfJets) [iPFJetBest]);
00210         }
00211       }
00212       else {}
00213         /*      {
00214         unsigned iPFJetBest = 0;
00215         double energyFractionBest = 0.;
00216         for (unsigned iPFJet = 0; iPFJet < pfJets->size(); ++iPFJet) {
00217           double energyFraction = jetMatching.overlapEnergyFraction (genJetConstituents [iGenJet], 
00218                                                                      pfJetConstituents [iPFJet]);
00219           if (energyFraction > energyFractionBest) {
00220             iPFJetBest = iPFJet;
00221             energyFractionBest = energyFraction;
00222           }
00223         }
00224         mGenJetMatchEnergyFraction->Fill (logPtGen, genJet.eta(), energyFractionBest);
00225         if (energyFractionBest > mGenEnergyFractionThreshold) { // good enough
00226           double reverseEnergyFraction = jetMatching.overlapEnergyFraction (pfJetConstituents [iPFJetBest], 
00227                                                                             genJetConstituents [iGenJet]);
00228           mReverseMatchEnergyFraction->Fill (logPtGen, genJet.eta(), reverseEnergyFraction);
00229           if (reverseEnergyFraction > mReverseEnergyFractionThreshold) { // Matched
00230             fillMatchHists (genJet, (*pfJets) [iPFJetBest]);
00231           }
00232         }
00233         }*/
00234     }
00235   }
00236 }
00237 
00238 
00239 
00240 
00241 void PFJetTester::fillMatchHists (const reco::GenJet& fGenJet, const reco::PFJet& fPFJet) {
00242   double logPtGen = log10 (fGenJet.pt());
00243   std::cout << "Filling matchingn" << std::cout;
00244   mMatchedGenJetsPt->Fill (logPtGen);
00245   mMatchedGenJetsEta->Fill (logPtGen, fGenJet.eta());
00246   mDeltaEta->Fill (logPtGen, fGenJet.eta(), fPFJet.eta()-fGenJet.eta());
00247   mDeltaPhi->Fill (logPtGen, fGenJet.eta(), fPFJet.phi()-fGenJet.phi());
00248   mEScale->Fill (logPtGen, fGenJet.eta(), fPFJet.energy()/fGenJet.energy());
00249   mDeltaE->Fill (logPtGen, fGenJet.eta(), fPFJet.energy()-fGenJet.energy());
00250 
00251   //_______________________________________________________________________________________________________________
00252 
00253   //mEEffNeutralFraction->Fill (fPFJet.energy()/fGenJet.energy());
00254   mEEffNeutralFraction->Fill (fPFJet.neutralMultiplicity()/fPFJet.nConstituents(), fPFJet.energy()/fGenJet.energy());
00255   nEEff->Fill(fPFJet.energy()/fGenJet.energy());
00256   mNeutralFraction2->Fill (fPFJet.neutralMultiplicity()/fPFJet.nConstituents());
00257   mEEffChargedFraction->Fill (fPFJet.chargedMultiplicity()/fPFJet.nConstituents(), fPFJet.energy()/fGenJet.energy());
00258   mEResNeutralFraction->Fill (fPFJet.neutralMultiplicity()/fPFJet.nConstituents(), (fPFJet.energy()-fGenJet.energy())/fGenJet.energy());
00259   mEResChargedFraction->Fill (fPFJet.chargedMultiplicity()/fPFJet.nConstituents(), (fPFJet.energy()-fGenJet.energy())/fGenJet.energy());
00260 }

Generated on Tue Jun 9 17:49:33 2009 for CMSSW by  doxygen 1.5.4