CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoTauTag/TauTagTools/plugins/RecoTauDifferenceAnalyzer.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/EDFilter.h"
00002 #include "FWCore/Framework/interface/Event.h"
00003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00004 
00005 #include "DataFormats/Math/interface/deltaR.h"
00006 #include "DataFormats/TauReco/interface/PFTau.h"
00007 #include "DataFormats/TauReco/interface/PFTauFwd.h"
00008 #include "DataFormats/TauReco/interface/PFTauDiscriminator.h"
00009 
00010 class RecoTauDifferenceAnalyzer : public edm::EDFilter {
00011   public:
00012     explicit RecoTauDifferenceAnalyzer(const edm::ParameterSet& pset);
00013     virtual ~RecoTauDifferenceAnalyzer() {}
00014     virtual bool filter(edm::Event& evt, const edm::EventSetup& es);
00015     virtual void endJob();
00016   private:
00017     edm::InputTag src1_;
00018     edm::InputTag src2_;
00019     edm::InputTag disc1_;
00020     edm::InputTag disc2_;
00021     double maxDeltaR_;
00022     size_t eventsExamined_;
00023     size_t tausExamined_;
00024     size_t differences_;
00025     size_t passed1_;
00026     size_t passed2_;
00027     size_t allPassed1_;
00028     size_t allPassed2_;
00029     bool filter_;
00030 };
00031 
00032 RecoTauDifferenceAnalyzer::RecoTauDifferenceAnalyzer(
00033     const edm::ParameterSet& pset) {
00034   src1_ = pset.getParameter<edm::InputTag>("src1");
00035   src2_ = pset.getParameter<edm::InputTag>("src2");
00036   disc1_ = pset.getParameter<edm::InputTag>("disc1");
00037   disc2_ = pset.getParameter<edm::InputTag>("disc2");
00038   eventsExamined_ = 0;
00039   tausExamined_ = 0;
00040   differences_ = 0;
00041   passed1_ = 0;
00042   passed2_ = 0;
00043   allPassed2_ = 0;
00044   allPassed1_ = 0;
00045   filter_ = pset.exists("filter") ? pset.getParameter<bool>("filter") : false;
00046 }
00047 
00048 namespace {
00049   reco::PFJetRef getJetRef(const reco::PFTau& tau) {
00050     if (tau.jetRef().isNonnull())
00051       return tau.jetRef();
00052     else if (tau.pfTauTagInfoRef()->pfjetRef().isNonnull())
00053       return tau.pfTauTagInfoRef()->pfjetRef();
00054     else throw cms::Exception("cant find jet ref");
00055   }
00056 }
00057 
00058 bool RecoTauDifferenceAnalyzer::filter(
00059     edm::Event& evt, const edm::EventSetup& es) {
00060   eventsExamined_++;
00061   // Get taus
00062   edm::Handle<reco::PFTauCollection> taus1;
00063   evt.getByLabel(src1_, taus1);
00064   edm::Handle<reco::PFTauCollection> taus2;
00065   evt.getByLabel(src2_, taus2);
00066 
00067   // Get discriminators
00068   edm::Handle<reco::PFTauDiscriminator> disc1;
00069   evt.getByLabel(disc1_, disc1);
00070   edm::Handle<reco::PFTauDiscriminator> disc2;
00071   evt.getByLabel(disc2_, disc2);
00072 
00073   bool differenceFound = false;
00074   // Loop over first collection
00075   for (size_t iTau1 = 0; iTau1 < taus1->size(); ++iTau1) {
00076     tausExamined_++;
00077     reco::PFTauRef tau1(taus1, iTau1);
00078     // Find the best match in the other collection
00079     reco::PFTauRef bestMatch;
00080     double bestDeltaR = -1;
00081     for (size_t iTau2 = 0; iTau2 < taus2->size(); ++iTau2) {
00082       reco::PFTauRef tau2(taus2, iTau2);
00083       reco::PFJetRef jet1 = getJetRef(*tau1);
00084       reco::PFJetRef jet2 = getJetRef(*tau2);
00085       double deltaRVal = deltaR(jet2->p4(), jet1->p4());
00086       if (bestMatch.isNull() || deltaRVal < bestDeltaR) {
00087         bestMatch = tau2;
00088         bestDeltaR = deltaRVal;
00089       }
00090     }
00091     // See what's up with the discriminators
00092     bool result1 = ((*disc1)[tau1] > 0.5);
00093     bool result2 = ((*disc2)[bestMatch] > 0.5);
00094     allPassed1_ += result1;
00095     allPassed2_ += result2;
00096     if (result1 ^ result2) {
00097       differenceFound = true;
00098       passed1_ += result1;
00099       passed2_ += result2;
00100       differences_++;
00101       std::cout << "********* RecoTau difference detected! *************"
00102           << std::endl;
00103       std::cout << " Tau1 InputTag: " << src1_ << " result: " << result1
00104           << std::endl;
00105       std::cout << " Tau2 InputTag: " << src2_ << " result: " << result2
00106           << std::endl;
00107       std::cout << "---------       Tau 1                  -------------"
00108           << std::endl;
00109       std::cout << *tau1 << std::endl;
00110       tau1->dump(std::cout);
00111       std::cout << "---------       Tau 2                  -------------"
00112           << std::endl;
00113       std::cout << *bestMatch << std::endl;
00114       bestMatch->dump(std::cout);
00115     }
00116   }
00117   return (filter_ ? differenceFound : true);
00118 }
00119 
00120 void RecoTauDifferenceAnalyzer::endJob() {
00121   std::cout <<  " RECO TAU DIFFERENCE SUMMARY: " << std::endl;
00122   std::cout <<  " Examined " << tausExamined_ << " taus in "
00123     << eventsExamined_ << " events." << std::endl;
00124   std::cout << " There were " << differences_ << " differences." << std::endl;
00125   std::cout << src1_ << "," << disc1_ << " had "
00126     << allPassed1_ << " total passes and "
00127     << passed1_ << " exclusive passes." << std::endl;
00128   std::cout << src2_ << "," << disc2_ << " had "
00129     << allPassed2_ << " total passes and "
00130     << passed2_ << " exclusive passes." << std::endl;
00131 }
00132 
00133 
00134 #include "FWCore/Framework/interface/MakerMacros.h"
00135 DEFINE_FWK_MODULE(RecoTauDifferenceAnalyzer);