CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/Validation/RecoParticleFlow/plugins/GenericBenchmarkAnalyzer.cc

Go to the documentation of this file.
00001 #include "Validation/RecoParticleFlow/plugins/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/Utilities/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   startFromGen_                = iConfig.getParameter<bool>("StartFromGen");
00046   plotAgainstRecoQuantities_   = iConfig.getParameter<bool>("PlotAgainstRecoQuantities");
00047   onlyTwoJets_                 = iConfig.getParameter<bool>("OnlyTwoJets");
00048   recPt_cut                    = iConfig.getParameter<double>("recPt");
00049   minEta_cut                   = iConfig.getParameter<double>("minEta");
00050   maxEta_cut                   = iConfig.getParameter<double>("maxEta");
00051   deltaR_cut                   = iConfig.getParameter<double>("deltaRMax");
00052 
00053   minDeltaEt_                   = iConfig.getParameter<double>("minDeltaEt");
00054   maxDeltaEt_                   = iConfig.getParameter<double>("maxDeltaEt");
00055   minDeltaPhi_                  = iConfig.getParameter<double>("minDeltaPhi");
00056   maxDeltaPhi_                  = iConfig.getParameter<double>("maxDeltaPhi");
00057   doMetPlots_                   = iConfig.getParameter<bool>("doMetPlots");
00058 
00059   if (outputFile_.size() > 0)
00060     edm::LogInfo("OutputInfo") << " ParticleFLow Task histograms will be saved to '" << outputFile_.c_str()<< "'";
00061   else edm::LogInfo("OutputInfo") << " ParticleFlow Task histograms will NOT be saved";
00062 
00063 }
00064 
00065 GenericBenchmarkAnalyzer::~GenericBenchmarkAnalyzer() { }
00066 
00067 void 
00068 GenericBenchmarkAnalyzer::beginJob()
00069 {
00070 
00071   // get ahold of back-end interface
00072   dbe_ = edm::Service<DQMStore>().operator->();
00073   
00074   if (dbe_) {
00075     //dbe_->setVerbose(1);
00076     string path = "PFTask/Benchmarks/" + benchmarkLabel_ + "/";
00077     if (plotAgainstRecoQuantities_) path += "Reco"; else path += "Gen";
00078     dbe_->setCurrentFolder(path.c_str());
00079     setup(dbe_, plotAgainstRecoQuantities_, minDeltaEt_, maxDeltaEt_, minDeltaPhi_, maxDeltaPhi_, doMetPlots_);
00080 
00081   }
00082 
00083 }
00084 
00085 void 
00086 GenericBenchmarkAnalyzer::analyze(const edm::Event& iEvent, 
00087                                   const edm::EventSetup& iSetup)
00088 {
00089   
00090   // Typedefs to use views
00091   typedef edm::View<reco::Candidate> candidateCollection ;
00092   typedef edm::View<reco::Candidate> candidateCollection ;
00093   
00094   const candidateCollection *truth_candidates;
00095   const candidateCollection *reco_candidates;
00096  
00097   // ==========================================================
00098   // Retrieve!
00099   // ==========================================================
00100 
00101   { 
00102     // Get Truth Candidates (GenCandidates, GenJets, etc.)
00103     Handle<candidateCollection> truth_hnd;
00104     bool isGen = iEvent.getByLabel(inputTruthLabel_, truth_hnd);
00105     if ( !isGen ) { 
00106       std::cout << "Warning : no Gen jets in input !" << std::endl;
00107       return;
00108     }
00109 
00110     truth_candidates = truth_hnd.product();
00111 
00112     // Get Reco Candidates (PFlow, CaloJet, etc.)
00113     Handle<candidateCollection> reco_hnd;
00114     bool isReco = iEvent.getByLabel(inputRecoLabel_, reco_hnd);
00115     if ( !isReco ) { 
00116       std::cout << "Warning : no Reco jets in input !" << std::endl;
00117       return; 
00118     }
00119     reco_candidates = reco_hnd.product();
00120 
00121     // no longer needed with template-ized Benchmark
00122     //const PFCandidateCollection *pf_candidates = reco_hnd.product();
00123     //static CandidateCollection reco_storage = algo_->makeCandidateCollection(pf_candidates);
00124     //reco_candidates = &reco_storage;
00125 
00126   }
00127   if (!truth_candidates || !reco_candidates) {
00128 
00129     edm::LogInfo("OutputInfo") << " failed to retrieve data required by ParticleFlow Task";
00130     edm::LogInfo("OutputInfo") << " ParticleFlow Task cannot continue...!";
00131     return;
00132 
00133   }
00134 
00135   // ==========================================================
00136   // Analyze!
00137   // ==========================================================
00138 
00139   fill(reco_candidates,truth_candidates,
00140       startFromGen_, plotAgainstRecoQuantities_, 
00141       onlyTwoJets_, recPt_cut,  minEta_cut, maxEta_cut, deltaR_cut);
00142 }
00143 
00144 void GenericBenchmarkAnalyzer::endJob() 
00145 {
00146 
00147   // Store the DAQ Histograms
00148   if (outputFile_.size() != 0)
00149     dbe_->save(outputFile_);
00150 }