CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/Validation/RecoTau/plugins/PFTauTest.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/Frameworkfwd.h"
00002 #include "FWCore/Framework/interface/EDAnalyzer.h"
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/Framework/interface/MakerMacros.h"
00005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00006 
00007 #include "DataFormats/TauReco/interface/PFTau.h"
00008 #include "DataFormats/TauReco/interface/PFTauTagInfo.h"
00009 //#include "DataFormats/MuonReco/interface/MuonFwd.h"
00010 #include "DataFormats/MuonReco/interface/MuonSelectors.h"
00011 
00012 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00013 #include "DataFormats/Candidate/interface/Candidate.h"
00014 
00015 //#include "Math/GenVector/VectorUtil.h"
00016 #include "Math/GenVector/PxPyPzE4D.h"
00017 
00018 #include <memory>
00019 #include <string>
00020 #include <iostream>
00021 
00022 #include <TROOT.h>
00023 #include <TSystem.h>
00024 #include <TFile.h>
00025 #include <TCanvas.h>
00026 #include <TH1.h>
00027 #include <TH2.h>
00028 #include <TDirectory.h>
00029 
00030 #include "FWCore/ServiceRegistry/interface/Service.h" // Framework services
00031 //#include "PhysicsTools/UtilAlgos/interface/TFileService.h" // Framework service for histograms
00032 //#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00033 #include <Math/GenVector/VectorUtil.h>
00034 
00035 // get rid of this damn TLorentzVector!
00036 //#include "DataFormats/Candidate/interface/Particle.h"
00037 #include "DataFormats/Math/interface/deltaR.h"
00038 //#include "TLorentzVector.h"
00039 
00040 // Include DQM core
00041 #include "DQMServices/Core/interface/DQMStore.h"
00042 #include "DQMServices/Core/interface/MonitorElement.h"
00043 
00044 using namespace edm;
00045 using namespace reco; 
00046 using namespace std;
00047 
00048 typedef Particle::LorentzVector LorentzVector;
00049 
00050 class PFTauHLTTest : public EDAnalyzer {
00051 public:
00052   explicit PFTauHLTTest(const ParameterSet&);
00053   ~PFTauHLTTest() {}
00054   virtual void analyze(const Event& iEvent,const EventSetup& iSetup);
00055   virtual void beginJob();
00056   virtual void endJob();
00057 private:
00058 
00059   DeltaR<LorentzVector> deltaRComputer_;
00060 
00061   string PFTauProducer_, MatchedPFTauProducer_,PFJetProducer_;
00062 
00063   
00064   int nEvent;
00065   int nTauMatchPFTau;
00066   int nElecMatchPFTau;
00067   int nTauElecPreID;
00068   int nElecElecPreID;
00069   int nTauNonElecPreID;
00070   int nElecNonElecPreID;
00071 
00072   // files
00073   std::string outPutFile_;
00074   TFile *_file;
00075   TDirectory *_dir;
00076 
00077   // Efficiency plots
00078   MonitorElement* h_PFTau_Eta_;
00079   MonitorElement* h_NumberOfJets_;
00080   MonitorElement* h_MatchedPFTau_Eta_;
00081   MonitorElement* h_PFTau_Phi_;
00082   MonitorElement* h_PFTau_Pt_;
00083   MonitorElement* h_Tau_Pt_;
00084   MonitorElement* h_MatchedPFTau_Pt_;
00085   MonitorElement* h_PFTau_SignalChargedHadron_;
00086   MonitorElement* h_PFTau_SignalNeutralHadron_;
00087   MonitorElement* h_PFTau_LeadingTrackPt_;
00088   MonitorElement* h_PFTau_SignalTracks_;
00089   MonitorElement* h_PFTau_SignalGammas_;
00090   MonitorElement* h_PFTauEt_MCTauEt_;
00091   DQMStore* dbeTau;
00092 };
00093 
00094 PFTauHLTTest::PFTauHLTTest(const ParameterSet& iConfig){
00095   PFTauProducer_                         = iConfig.getParameter<string>("PFTauProducer");
00096   PFJetProducer_                         = iConfig.getParameter<string>("PFJetProducer");
00097   MatchedPFTauProducer_                         = iConfig.getParameter<string>("MatchedPFTauProducer");
00098 
00099   nEvent=0;
00100 
00101   nTauMatchPFTau=0;
00102   nElecMatchPFTau=0;
00103   nTauElecPreID=0;
00104   nElecElecPreID=0;
00105   nTauNonElecPreID=0;
00106   nElecNonElecPreID=0;
00107 
00108   outPutFile_ = "PFTauTest.root";
00109 }
00110 void PFTauHLTTest::beginJob(){
00111   dbeTau = &*edm::Service<DQMStore>();
00112   dbeTau->setCurrentFolder("RecoPFTau"); 
00113 
00114   // Book histograms
00115   h_PFTau_Eta_ = dbeTau->book1D("PFTau_Eta","PFTau_Eta",50,0.,5.0);
00116   h_MatchedPFTau_Eta_ = dbeTau->book1D("MatchedPFTau_Eta","MatchedPFTau_Eta",50,0.,5.0);
00117   h_PFTau_Phi_ = dbeTau->book1D("PFTau_Phi","PFTau_Phi",50,-3.15,3.15);
00118   h_PFTau_Pt_ = dbeTau->book1D("PFTau_Pt","PFTau_Pt",50,0.,50.);
00119   h_Tau_Pt_ = dbeTau->book1D("Tau_Pt","Tau_Pt",50,0.,50.);
00120   h_MatchedPFTau_Pt_ = dbeTau->book1D("MatchedPFTau_Pt","MatchedPFTau_Pt",50,0.,50.);
00121   h_PFTau_SignalChargedHadron_ = dbeTau->book1D("PFTau_NumberChargedHadrons","PFTau_NumberChargedHadrons",10,0.,10.);
00122   h_PFTau_SignalNeutralHadron_ = dbeTau->book1D("PFTau_NumberNeutralHadrons","PFTau_NumberNeutralHadrons",10,0.,10.);
00123   h_PFTau_LeadingTrackPt_ = dbeTau->book1D("PFTau_LeadingTrackPt","PFTau_LeadingTrackPt",10,0.,10.);
00124   h_PFTau_SignalTracks_ = dbeTau->book1D("PFTau_NumberTracks","PFTau_NumberTracks",10,0.,10.);
00125   h_PFTau_SignalGammas_= dbeTau->book1D("PFTau_NumberPhotons","PFTau_NumberPhotons",10,0.,10.); 
00126 
00127   h_PFTauEt_MCTauEt_  = dbeTau->book2D("PFTauEt_MCTauEt","PFTau_Et Vs MCTau_Et", 50,0.,50.,50,0.,50.);
00128 
00129   h_NumberOfJets_ = dbeTau->book1D("NumberOfJets","NumberOfJets",20,0.,20.);
00130 
00131 }
00132 
00133 
00134 void PFTauHLTTest::analyze(const Event& iEvent, const EventSetup& iSetup){
00135   //cout<<"********"<<endl;
00136   //cout<<"Event number "<<nEvent++<<endl;
00137 
00138 
00139 
00141 
00142    
00143   
00144   Handle<PFTauCollection> thePFTauHandle;
00145   iEvent.getByLabel(PFTauProducer_,thePFTauHandle);
00146   
00147   Handle<PFTauCollection> thePFJetHandle;
00148   iEvent.getByLabel(PFJetProducer_,thePFJetHandle);
00149   double numberOfJets = thePFJetHandle->size()*1.;
00150   h_NumberOfJets_->Fill(numberOfJets);
00151   
00152   Handle<View<Candidate> > theMatchedPFTauHandle;
00153   iEvent.getByLabel(MatchedPFTauProducer_,theMatchedPFTauHandle);
00154 
00155   //int n = 0;
00156   // Tau Loop
00157   for (unsigned int iPFTau=0;iPFTau<thePFTauHandle->size();iPFTau++) { 
00158     const PFTauRef thePFTau(thePFTauHandle, iPFTau);
00159     if(thePFTau->pt() > 0.){
00160       h_PFTau_Eta_->Fill(fabs((*thePFTau).eta()));
00161       h_PFTau_Pt_->Fill((*thePFTau).pt());
00162       h_PFTau_Phi_->Fill((*thePFTau).phi());
00163     }
00164     bool matched = false;
00165     //loop over the matched jets
00166     for (View<Candidate>::size_type iMPFTau=0;iMPFTau<theMatchedPFTauHandle->size();iMPFTau++) { 
00167       const Candidate *theMPFTau = &(*theMatchedPFTauHandle)[iMPFTau];
00168       double deltaR = ROOT::Math::VectorUtil::DeltaR(thePFTau->p4().Vect(), (theMPFTau->p4()).Vect());
00169       if(deltaR < 0.5) {
00170         matched = true;
00171         h_PFTauEt_MCTauEt_->Fill(theMPFTau->pt(),thePFTau->pt());
00172         break;
00173       }
00174 
00175     }
00176 
00177     if(matched) {
00178       h_MatchedPFTau_Pt_->Fill((*thePFTau).pt());
00179       h_MatchedPFTau_Eta_->Fill(fabs((*thePFTau).eta()));
00180       cout <<"Particle type "<<(*thePFTau).leadPFChargedHadrCand()->particleId()<<endl;
00181       if((*thePFTau).hasMuonReference()){
00182         MuonRef muonref = (*thePFTau).leadPFChargedHadrCand()->muonRef();
00183         cout <<"Muon segments " <<muonref->numberOfMatches()<<endl;
00184       }
00185     }
00186     if(!matched){
00187             h_PFTau_SignalChargedHadron_->Fill((*thePFTau).signalPFChargedHadrCands().size()*1.);
00188             h_PFTau_SignalNeutralHadron_->Fill((*thePFTau).signalPFNeutrHadrCands().size()*1.);
00189            if((*thePFTau).leadPFChargedHadrCand().isNonnull())
00190                 h_PFTau_LeadingTrackPt_->Fill((*thePFTau).leadPFChargedHadrCand()->pt());
00191 
00192               h_PFTau_SignalTracks_->Fill((*thePFTau).signalTracks().size()*1.);
00193               h_PFTau_SignalGammas_->Fill((*thePFTau).signalPFGammaCands().size()*1.);
00194     }
00195 
00196   }
00197 
00198    for (View<Candidate>::size_type iMPFTau=0;iMPFTau<theMatchedPFTauHandle->size();iMPFTau++) { 
00199       const Candidate *theMPFTau = &(*theMatchedPFTauHandle)[iMPFTau];
00200       h_Tau_Pt_->Fill(theMPFTau->pt());
00201     }
00202   
00203 }
00204 
00205 void PFTauHLTTest::endJob(){
00206  if (!outPutFile_.empty() && &*edm::Service<DQMStore>()) dbeTau->save (outPutFile_);
00207 }
00208 
00209 
00210 DEFINE_FWK_MODULE(PFTauHLTTest);