CMS 3D CMS Logo

PFTester.cc

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

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