CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RecoTauDifferenceAnalyzer.cc
Go to the documentation of this file.
4 
9 
11  public:
12  explicit RecoTauDifferenceAnalyzer(const edm::ParameterSet& pset);
14  virtual bool filter(edm::Event& evt, const edm::EventSetup& es) override;
15  virtual void endJob() override;
16  private:
21  double maxDeltaR_;
23  size_t tausExamined_;
24  size_t differences_;
25  size_t passed1_;
26  size_t passed2_;
27  size_t allPassed1_;
28  size_t allPassed2_;
29  bool filter_;
30 };
31 
33  const edm::ParameterSet& pset) {
34  src1_ = pset.getParameter<edm::InputTag>("src1");
35  src2_ = pset.getParameter<edm::InputTag>("src2");
36  disc1_ = pset.getParameter<edm::InputTag>("disc1");
37  disc2_ = pset.getParameter<edm::InputTag>("disc2");
38  eventsExamined_ = 0;
39  tausExamined_ = 0;
40  differences_ = 0;
41  passed1_ = 0;
42  passed2_ = 0;
43  allPassed2_ = 0;
44  allPassed1_ = 0;
45  filter_ = pset.exists("filter") ? pset.getParameter<bool>("filter") : false;
46 }
47 
48 namespace {
49  reco::PFJetRef getJetRef(const reco::PFTau& tau) {
50  if (tau.jetRef().isNonnull())
51  return tau.jetRef();
52  else if (tau.pfTauTagInfoRef()->pfjetRef().isNonnull())
53  return tau.pfTauTagInfoRef()->pfjetRef();
54  else throw cms::Exception("cant find jet ref");
55  }
56 }
57 
59  edm::Event& evt, const edm::EventSetup& es) {
61  // Get taus
63  evt.getByLabel(src1_, taus1);
65  evt.getByLabel(src2_, taus2);
66 
67  // Get discriminators
69  evt.getByLabel(disc1_, disc1);
71  evt.getByLabel(disc2_, disc2);
72 
73  bool differenceFound = false;
74  // Loop over first collection
75  for (size_t iTau1 = 0; iTau1 < taus1->size(); ++iTau1) {
76  tausExamined_++;
77  reco::PFTauRef tau1(taus1, iTau1);
78  // Find the best match in the other collection
80  double bestDeltaR = -1;
81  for (size_t iTau2 = 0; iTau2 < taus2->size(); ++iTau2) {
82  reco::PFTauRef tau2(taus2, iTau2);
83  reco::PFJetRef jet1 = getJetRef(*tau1);
84  reco::PFJetRef jet2 = getJetRef(*tau2);
85  double deltaRVal = deltaR(jet2->p4(), jet1->p4());
86  if (bestMatch.isNull() || deltaRVal < bestDeltaR) {
87  bestMatch = tau2;
88  bestDeltaR = deltaRVal;
89  }
90  }
91  // See what's up with the discriminators
92  bool result1 = ((*disc1)[tau1] > 0.5);
93  bool result2 = ((*disc2)[bestMatch] > 0.5);
94  allPassed1_ += result1;
95  allPassed2_ += result2;
96  if (result1 ^ result2) {
97  differenceFound = true;
98  passed1_ += result1;
99  passed2_ += result2;
100  differences_++;
101  std::cout << "********* RecoTau difference detected! *************"
102  << std::endl;
103  std::cout << " Tau1 InputTag: " << src1_ << " result: " << result1
104  << std::endl;
105  std::cout << " Tau2 InputTag: " << src2_ << " result: " << result2
106  << std::endl;
107  std::cout << "--------- Tau 1 -------------"
108  << std::endl;
109  std::cout << *tau1 << std::endl;
110  tau1->dump(std::cout);
111  std::cout << "--------- Tau 2 -------------"
112  << std::endl;
113  std::cout << *bestMatch << std::endl;
114  bestMatch->dump(std::cout);
115  }
116  }
117  return (filter_ ? differenceFound : true);
118 }
119 
121  std::cout << " RECO TAU DIFFERENCE SUMMARY: " << std::endl;
122  std::cout << " Examined " << tausExamined_ << " taus in "
123  << eventsExamined_ << " events." << std::endl;
124  std::cout << " There were " << differences_ << " differences." << std::endl;
125  std::cout << src1_ << "," << disc1_ << " had "
126  << allPassed1_ << " total passes and "
127  << passed1_ << " exclusive passes." << std::endl;
128  std::cout << src2_ << "," << disc2_ << " had "
129  << allPassed2_ << " total passes and "
130  << passed2_ << " exclusive passes." << std::endl;
131 }
132 
133 
def bestMatch
Definition: deltar.py:139
T getParameter(std::string const &) const
RecoTauDifferenceAnalyzer(const edm::ParameterSet &pset)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
const PFJetRef & jetRef() const
Definition: PFTau.cc:54
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:405
bool isNull() const
Checks for null.
Definition: Ref.h:247
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
const PFTauTagInfoRef & pfTauTagInfoRef() const
Definition: PFTau.cc:57
virtual bool filter(edm::Event &evt, const edm::EventSetup &es) override
tuple cout
Definition: gather_cfg.py:121