CMS 3D CMS Logo

GenericBenchmarkAnalyzer.cc

Go to the documentation of this file.
00001 #include "Validation/RecoParticleFlow/interface/GenericBenchmarkAnalyzer.h"
00002 // author: Mike Schmitt, University of Florida
00003 // first version 11/7/2007
00004 // extension: Leo Neuhaus & Joanna Weng 09.2008
00005 // Performs matching and basic resolution plots of 2 candidate
00006 // (or candidate based) collections
00007 
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 #include "FWCore/ServiceRegistry/interface/Service.h"
00010 
00011 #include "FWCore/Framework/interface/Event.h"
00012 #include "DataFormats/Common/interface/Handle.h"
00013 #include "FWCore/Framework/interface/ESHandle.h"
00014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00015 #include "FWCore/ParameterSet/interface/InputTag.h"
00016 
00017 
00018 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00019 #include "DataFormats/Candidate/interface/Candidate.h"
00020 
00021 #include "DQMServices/Core/interface/DQMStore.h"
00022 
00023 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
00024 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
00025 
00026 #include <vector>
00027 #include <ostream>
00028 #include <fstream>
00029 #include <iostream>
00030 #include <algorithm>
00031 #include <cmath>
00032 #include <memory>
00033 
00034 using namespace reco;
00035 using namespace edm;
00036 using namespace std;
00037 
00038 GenericBenchmarkAnalyzer::GenericBenchmarkAnalyzer(const edm::ParameterSet& iConfig)
00039 {
00040 
00041   inputTruthLabel_             = iConfig.getParameter<edm::InputTag>("InputTruthLabel");
00042   inputRecoLabel_              = iConfig.getParameter<edm::InputTag>("InputRecoLabel");
00043   outputFile_                  = iConfig.getUntrackedParameter<std::string>("OutputFile");
00044   benchmarkLabel_              = iConfig.getParameter<std::string>("BenchmarkLabel"); 
00045   plotAgainstRecoQuantities_   = iConfig.getParameter<bool>("PlotAgainstRecoQuantities");
00046   onlyTwoJets_                 = iConfig.getParameter<bool>("OnlyTwoJets");
00047   recPt_cut                    = iConfig.getParameter<double>("recPt");
00048   maxEta_cut                    = iConfig.getParameter<double>("maxEta");
00049   deltaR_cut                    = iConfig.getParameter<double>("deltaRMax");
00050 
00051   if (outputFile_.size() > 0)
00052     edm::LogInfo("OutputInfo") << " ParticleFLow Task histograms will be saved to '" << outputFile_.c_str()<< "'";
00053   else edm::LogInfo("OutputInfo") << " ParticleFlow Task histograms will NOT be saved";
00054 
00055 }
00056 
00057 GenericBenchmarkAnalyzer::~GenericBenchmarkAnalyzer() { }
00058 
00059 void GenericBenchmarkAnalyzer::beginJob(const edm::EventSetup& iSetup)
00060 {
00061 
00062   // get ahold of back-end interface
00063   dbe_ = edm::Service<DQMStore>().operator->();
00064   
00065   if (dbe_) {
00066     //dbe_->setVerbose(1);
00067     string path = "PFTask/Benchmarks/" + benchmarkLabel_ + "/";
00068     if (plotAgainstRecoQuantities_) path += "Reco"; else path += "Gen";
00069     dbe_->setCurrentFolder(path.c_str());
00070     setup(dbe_, plotAgainstRecoQuantities_);
00071 
00072   }
00073 
00074 }
00075 
00076 void GenericBenchmarkAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00077 {
00078   
00079   // Typedefs to use views
00080   typedef edm::View<reco::Candidate> candidateCollection ;
00081   typedef edm::View<reco::Candidate> candidateCollection ;
00082   
00083   const candidateCollection *truth_candidates;
00084   const candidateCollection *reco_candidates;
00085  
00086   // ==========================================================
00087   // Retrieve!
00088   // ==========================================================
00089 
00090   { 
00091     // Get Truth Candidates (GenCandidates, GenJets, etc.)
00092     Handle<candidateCollection> truth_hnd;
00093     bool isGen = iEvent.getByLabel(inputTruthLabel_, truth_hnd);
00094     if ( !isGen ) { 
00095       std::cout << "Warning : no Gen jets in input !" << std::endl;
00096       return;
00097     }
00098 
00099     truth_candidates = truth_hnd.product();
00100 
00101     // Get Reco Candidates (PFlow, CaloJet, etc.)
00102     Handle<candidateCollection> reco_hnd;
00103     bool isReco = iEvent.getByLabel(inputRecoLabel_, reco_hnd);
00104     if ( !isReco ) { 
00105       std::cout << "Warning : no Reco jets in input !" << std::endl;
00106       return; 
00107     }
00108     reco_candidates = reco_hnd.product();
00109 
00110     // no longer needed with template-ized Benchmark
00111     //const PFCandidateCollection *pf_candidates = reco_hnd.product();
00112     //static CandidateCollection reco_storage = algo_->makeCandidateCollection(pf_candidates);
00113     //reco_candidates = &reco_storage;
00114 
00115   }
00116   if (!truth_candidates || !reco_candidates) {
00117 
00118     edm::LogInfo("OutputInfo") << " failed to retrieve data required by ParticleFlow Task";
00119     edm::LogInfo("OutputInfo") << " ParticleFlow Task cannot continue...!";
00120     return;
00121 
00122   }
00123 
00124   // ==========================================================
00125   // Analyze!
00126   // ==========================================================
00127 
00128   fill(reco_candidates,truth_candidates,plotAgainstRecoQuantities_, onlyTwoJets_, recPt_cut, maxEta_cut, deltaR_cut);
00129 
00130 }
00131 
00132 void GenericBenchmarkAnalyzer::endJob() 
00133 {
00134 
00135   // Store the DAQ Histograms
00136   if (outputFile_.size() != 0)
00137     dbe_->save(outputFile_);
00138 }

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