CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/RecoParticleFlow/PFClusterTools/interface/CalibratableTest.h

Go to the documentation of this file.
00001 #ifndef CALIBRATABLETEST_H_
00002 #define CALIBRATABLETEST_H_
00003 
00004 // system include files
00005 #include <memory>
00006 #include <vector>
00007 // user include files
00008 #include "FWCore/Framework/interface/Frameworkfwd.h"
00009 #include "FWCore/Framework/interface/EDAnalyzer.h"
00010 #include "FWCore/Framework/interface/Event.h"
00011 #include "FWCore/Framework/interface/MakerMacros.h"
00012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00013 #include "FWCore/ServiceRegistry/interface/Service.h"
00014 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00015 
00016 #include "DataFormats/ParticleFlowReco/interface/Calibratable.h"
00017 
00018 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
00019 #include "DataFormats/ParticleFlowReco/interface/PFSimParticleFwd.h"
00020 #include "DataFormats/ParticleFlowReco/interface/PFRecTrackFwd.h"
00021 #include "DataFormats/ParticleFlowReco/interface/PFRecHitFwd.h"
00022 #include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h"
00023 
00024 #include <TTree.h>
00025 
00026 
00057 class CalibratableTest : public edm::EDAnalyzer {
00058 public:
00059         explicit CalibratableTest(const edm::ParameterSet&);
00060         ~CalibratableTest();
00061 
00062         /*
00063          * Returns the collection in the event matching the Handle.
00064          */
00065         template<class T> void getCollection(edm::Handle<T>& c,
00066                         const edm::InputTag& tag, const edm::Event& event) const;
00067 
00068 private:
00069         /* 
00070          * The usual EDAnalyzer methods
00071          */
00072         virtual void beginJob();
00073         virtual void analyze(const edm::Event&, const edm::EventSetup&);
00074         virtual void endJob();
00075 
00076         /*
00077          * Called for each particle in the event to fill the tree and
00078          * reset calib_.
00079          */
00080         virtual void fillTreeAndReset();
00081 
00082         /*
00083          * Finds the main pions generated by FastSim
00084          */
00085         std::vector<unsigned> findPrimarySimParticles(
00086                         const std::vector<reco::PFSimParticle>& sims);
00087 
00088         /*
00089          * Finds PFCandidates within some deltaR of the supplied sim particle.
00090          */
00091         std::vector<unsigned> findCandidatesInDeltaR(const reco::PFSimParticle& pft,
00092                         const std::vector<reco::PFCandidate>& cands, const double& deltaR);
00093 
00094         /*
00095          * Fills calib_ with PFCandidate information.
00096          */
00097         void extractCandidate(const reco::PFCandidate& cand);
00098 
00099         /*
00100          * Computes delta R between two objects.
00101          */
00102         double deltaR(const double& eta1, const double& eta2, const double& phi1,
00103                         const double& phi2);
00104 
00105         //Calibratable tree
00106         TTree* tree_;
00107 
00108         //This analyzer produces a file with a tree so we need,
00109         edm::Service<TFileService> fileservice_;
00110 
00111         //Debug?
00112         int debug_;
00113 
00114         //True if this event was generally successful: 
00115         //if no sim particles are found, this will be false
00116         bool thisEventPasses_;
00117         //True if this particle should be written to the tree
00118         //If no PFCandidates are found within a delta R cone of the sim particle,
00119         //this will be false.
00120         bool thisParticlePasses_;
00121 
00122         //The Calibratable object
00123         pftools::Calibratable* calib_;
00124 
00125         //Increment nWrites_ for every record written to the tree
00126         //Incremement nFails_ for every event/particle not written to the tree (thisEventPasses_ == false)
00127         unsigned nParticleWrites_, nParticleFails_;
00128         unsigned nEventWrites_, nEventFails_;
00129         
00130         //Size of cone around sim particle to look for PFCandidates
00131         double deltaRCandToSim_;
00132 
00133         //Collection input tags
00134         edm::InputTag inputTagCandidates_;
00135         edm::InputTag inputTagSimParticles_;
00136         edm::InputTag inputTagClustersEcal_;
00137         edm::InputTag inputTagClustersHcal_;
00138 
00139         //collections
00140         edm::Handle<reco::PFCandidateCollection>* pfCandidates_;
00141         edm::Handle<reco::PFSimParticleCollection>* simParticles_;
00142         edm::Handle<reco::PFClusterCollection>* clustersEcal_;
00143         edm::Handle<reco::PFClusterCollection>* clustersHcal_;
00144 
00145 };
00146 
00147 template<class T> void CalibratableTest::getCollection(edm::Handle<T>& c,
00148                 const edm::InputTag& tag, const edm::Event& event) const {
00149 
00150         try {
00151                 event.getByLabel(tag, c);
00152                 if(!c.isValid()) {
00153                         std::cout << "Warning! Collection for label " << tag << " is not valid!" << std::endl;
00154                 }
00155         }
00156         catch (cms::Exception& err) {
00157                 std::cout << "Couldn't get collection\n";
00158                 std::ostringstream err;
00159                 //LogError("Error getting collection!") << err;
00160         }
00161 }
00162 
00163 #endif /*CALIBRATABLETEST_H_*/