CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/Validation/RecoParticleFlow/plugins/PFTester.cc

Go to the documentation of this file.
00001 #include "Validation/RecoParticleFlow/plugins/PFTester.h"
00002 // author: Mike Schmitt, University of Florida
00003 // first version 11/7/2007
00004 
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 #include "FWCore/ServiceRegistry/interface/Service.h"
00008 
00009 #include "FWCore/Framework/interface/Event.h"
00010 #include "DataFormats/Common/interface/Handle.h"
00011 #include "FWCore/Framework/interface/ESHandle.h"
00012 
00013 //#include "DataFormats/HepMCCandidate/interface/GenParticleCollection.h"
00014 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
00015 #include "DataFormats/METReco/interface/GenMET.h"
00016 #include "DataFormats/METReco/interface/GenMETCollection.h"
00017 #include "DataFormats/METReco/interface/CaloMET.h"
00018 #include "DataFormats/METReco/interface/CaloMETCollection.h"
00019 //#include "DataFormats/TrackReco/interface/Track.h"
00020 #include "DataFormats/ParticleFlowReco/interface/PFBlock.h"
00021 #include "DataFormats/ParticleFlowReco/interface/PFBlockElement.h"
00022 #include "DataFormats/ParticleFlowReco/interface/PFRecTrack.h"
00023 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
00024 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
00025 #include "DataFormats/Common/interface/RefToBase.h"
00026 
00027 #include <vector>
00028 #include <ostream>
00029 #include <fstream>
00030 #include <iostream>
00031 #include <algorithm>
00032 #include <cmath>
00033 #include <memory>
00034 
00035 using namespace edm;
00036 using namespace std;
00037 using namespace reco;
00038 
00039 
00040 PFTester::PFTester(const edm::ParameterSet& iConfig)
00041 {
00042 
00043   inputPFlowLabel_             = iConfig.getParameter<std::string>("InputPFlowLabel");
00044   outputFile_                  = iConfig.getUntrackedParameter<std::string>("OutputFile");
00045 
00046   if (outputFile_.size() > 0)
00047     edm::LogInfo("OutputInfo") << " ParticleFLow Task histograms will be saved to '" << outputFile_.c_str() << "'";
00048   else edm::LogInfo("OutputInfo") << " ParticleFlow Task histograms will NOT be saved";
00049 
00050 }
00051 
00052 PFTester::~PFTester() { }
00053 
00054 void 
00055 PFTester::beginJob()
00056 {
00057 
00058   // get ahold of back-end interface
00059   dbe_ = edm::Service<DQMStore>().operator->();
00060   
00061   if (dbe_) {
00062 
00063     dbe_->setCurrentFolder("PFTask/PFCandidates");
00064 
00065     me["CandidateEt"] = dbe_->book1D("CandidateEt","CandidateEt",1000,0,1000);
00066     me["CandidateEta"] = dbe_->book1D("CandidateEta","CandidateEta",200,-5,5);
00067     me["CandidatePhi"] = dbe_->book1D("CandidatePhi","CandidatePhi",200,-M_PI,M_PI);
00068     me["CandidateCharge"] = dbe_->book1D("CandidateCharge","CandidateCharge",5,-2,2);
00069     me["PFCandidateType"] = dbe_->book1D("PFCandidateType","PFCandidateType",10,0,10);
00070 
00071     dbe_->setCurrentFolder("PFTask/PFBlocks");
00072 
00073     me["NumElements"] = dbe_->book1D("NumElements","NumElements",25,0,25);
00074     me["NumTrackElements"] = dbe_->book1D("NumTrackElements","NumTrackElements",5,0,5);
00075     me["NumPS1Elements"] = dbe_->book1D("NumPS1Elements","NumPS1Elements",5,0,5);
00076     me["NumPS2Elements"] = dbe_->book1D("NumPS2Elements","NumPS2Elements",5,0,5);
00077     me["NumECALElements"] = dbe_->book1D("NumECALElements","NumECALElements",5,0,5);
00078     me["NumHCALElements"] = dbe_->book1D("NumHCALElements","NumHCALElements",5,0,5);
00079     me["NumMuonElements"] = dbe_->book1D("NumMuonElements","NumMuonElements",5,0,5);
00080 
00081     dbe_->setCurrentFolder("PFTask/PFTracks");
00082 
00083     me["TrackCharge"] = dbe_->book1D("TrackCharge","TrackCharge",5,-2,2);
00084     me["TrackNumPoints"] = dbe_->book1D("TrackNumPoints","TrackNumPoints",100,0,100);
00085     me["TrackNumMeasurements"] = dbe_->book1D("TrackNumMeasurements","TrackNumMeasurements",100,0,100);
00086     me["TrackImpactParameter"] = dbe_->book1D("TrackImpactParameter","TrackImpactParameter",1000,0,1);
00087 
00088     dbe_->setCurrentFolder("PFTask/PFClusters");
00089 
00090   }
00091 
00092 }
00093 
00094 void 
00095 PFTester::analyze(const edm::Event& iEvent, 
00096                   const edm::EventSetup& iSetup)
00097 {
00098   
00099   // Data to Retrieve from the Event
00100   const PFCandidateCollection *pflow_candidates;
00101 
00102   // ==========================================================
00103   // Retrieve!
00104   // ==========================================================
00105 
00106   { 
00107 
00108     // Get Particle Flow Candidates
00109     Handle<PFCandidateCollection> pflow_hnd;
00110     iEvent.getByLabel(inputPFlowLabel_, pflow_hnd);
00111     pflow_candidates = pflow_hnd.product();
00112 
00113   }
00114 
00115   if (!pflow_candidates) {
00116 
00117     edm::LogInfo("OutputInfo") << " failed to retrieve data required by ParticleFlow Task";
00118     edm::LogInfo("OutputInfo") << " ParticleFlow Task cannot continue...!";
00119     return;
00120 
00121   }
00122 
00123   // ==========================================================
00124   // Analyze!
00125   // ==========================================================
00126 
00127   // Loop Over Particle Flow Candidates
00128   PFCandidateCollection::const_iterator pf;
00129   for (pf = pflow_candidates->begin(); pf != pflow_candidates->end(); pf++) {
00130 
00131     const PFCandidate *particle = &(*pf);
00132 
00133     // Fill Histograms for Candidate Methods
00134     me["CandidateEt"]->Fill(particle->et());
00135     me["CandidateEta"]->Fill(particle->eta());
00136     me["CandidatePhi"]->Fill(particle->phi());
00137     me["CandidateCharge"]->Fill(particle->charge());
00138     me["CandidatePdgId"]->Fill(particle->pdgId());
00139 
00140     // Fill Histograms for PFCandidate Specific Methods
00141     me["PFCandidateType"]->Fill(particle->particleId());
00142     // particle->elementsInBlocks(); 
00143     
00144    // Get the PFBlock and Elements
00145    // JW: Returns vector of blocks now ,TO BE FIXED ----
00146     /*PFBlock block = *(particle->block());
00147     OwnVector<PFBlockElement> elements = block.elements();
00148     int numElements = elements.size();
00149     int numTrackElements = 0;
00150     int numPS1Elements = 0;
00151     int numPS2Elements = 0;
00152     int numECALElements = 0;
00153     int numHCALElements = 0;
00154     int numMuonElements = 0;
00155 
00156     // Loop over Elements in Block
00157     OwnVector<PFBlockElement>::const_iterator element;
00158     for (element = elements.begin(); element != elements.end(); element++) {
00159 
00160       int element_type = element->type();
00161       // Element is a Tracker Track
00162       if (element_type == PFBlockElement::TRACK) {
00163 
00164         // Get General Information about the Track
00165         PFRecTrack track = *(element->trackRefPF());
00166         me["TrackCharge"]->Fill(track.charge());
00167         me["TrackNumPoints"]->Fill(track.nTrajectoryPoints());
00168         me["TrackNumMeasurements"]->Fill(track.nTrajectoryMeasurements());
00169 
00170         // Loop Over Points in the Track
00171         vector<PFTrajectoryPoint> points = track.trajectoryPoints();
00172         vector<PFTrajectoryPoint>::iterator point;
00173         for (point = points.begin(); point != points.end(); point++) {
00174           int point_layer = point->layer();
00175           double x = point->positionXYZ().x();
00176           double y = point->positionXYZ().y();
00177           double z = point->positionXYZ().z();
00178           //switch (point_layer) {
00179           //case PFTrajectoryPoint::ClosestApproach:
00180           // Fill the Track's D0
00181           if (point_layer == PFTrajectoryPoint::ClosestApproach) {
00182             me["TrackImpactParameter"]->Fill(sqrt(x*x + y*y + z*z));
00183           }
00184         }
00185         numTrackElements++;
00186       }
00187 
00188       // Element is an ECAL Cluster
00189       else if (element_type == PFBlockElement::ECAL) {
00190         numECALElements++;
00191       }
00192       // Element is a HCAL Cluster
00193       else if (element_type == PFBlockElement::HCAL) {
00194         numHCALElements++;
00195       }
00196       // Element is a Muon Track
00197       else if (element_type == PFBlockElement::MUON) {
00198         numMuonElements++;
00199       } 
00200       // Fill the Respective Elements Sizes
00201       me["NumElements"]->Fill(numElements);
00202       me["NumTrackElements"]->Fill(numTrackElements);
00203       me["NumPS1Elements"]->Fill(numPS1Elements);
00204       me["NumPS2Elements"]->Fill(numPS2Elements);
00205       me["NumECALElements"]->Fill(numECALElements);
00206       me["NumHCALElements"]->Fill(numHCALElements);
00207       me["NumMuonElements"]->Fill(numMuonElements);
00208     } ----------------------------------------------  */
00209 
00210   }
00211 
00212 }
00213 
00214 void PFTester::endJob() 
00215 {
00216 
00217   // Store the DAQ Histograms
00218   if (outputFile_.size() > 0 && dbe_)
00219     dbe_->save(outputFile_);
00220 
00221 }