CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RecoTauPlotDiscriminator.cc
Go to the documentation of this file.
1 /*
2  * RecoTauPlotDiscriminator
3  *
4  * Plot the output of a PFTauDiscriminator using TFileService.
5  *
6  * Author: Evan K. Friis (UC Davis)
7  */
8 
9 #include <boost/foreach.hpp>
10 
16 
18 
22 
26 
29 
30 #include <TH1F.h>
31 #include <TH2F.h>
32 #include <TH3F.h>
33 
35  public:
38  void analyze(const edm::Event &evt, const edm::EventSetup &es) override;
39  private:
41  typedef std::map<std::string, TH1*> HistoMap;
42  typedef std::map<std::string, HistoMap> DiscMap;
43  typedef std::vector<edm::InputTag> VInputTag;
45  bool plotPU_;
46  double pileupPtCut_;
50 };
51 
53  :src_(pset.getParameter<edm::InputTag>("src")) {
54  uint32_t nbins = pset.getParameter<uint32_t>("nbins");
55  double min = pset.getParameter<double>("min");
56  double max = pset.getParameter<double>("max");
58  // Get the discriminators
59  discs_ = pset.getParameter<std::vector<edm::InputTag> >("discriminators");
60 
61  plotPU_ = pset.getParameter<bool>("plotPU");
62  if (plotPU_) {
63  pileupPtCut_ = pset.getParameter<double>("pileupTauPtCut");
64  pileupInfoSrc_ = pset.getParameter<edm::InputTag>("pileupInfo");
65  pileupVerticesSrc_ = pset.getParameter<edm::InputTag>("pileupVertices");
66  }
67 
68  BOOST_FOREACH(const edm::InputTag &tag, discs_) {
69  HistoMap discMap;
70  discMap["plain"] =
71  fs->make<TH1F>(tag.label().c_str(), tag.label().c_str(),
72  nbins, min, max);
73 
74  // Make correlation plots w.r.t tau pt
75  std::string vs_pt_name = tag.label()+"_pt";
76  discMap["vs_pt"] =
77  fs->make<TH2F>(vs_pt_name.c_str(), vs_pt_name.c_str(),
78  nbins, min, max, 100, 0, 200);
79 
80  // W.r.t. jet pt
81  std::string vs_jetpt_name = tag.label()+"_jetPt";
82  discMap["vs_jetPt"] =
83  fs->make<TH2F>(vs_jetpt_name.c_str(), vs_jetpt_name.c_str(),
84  nbins, min, max, 100, 0, 200);
85 
86  // W.r.t. embedded pt in alternat lorentz vector (used to hold gen tau pt)
87  std::string vs_embedpt_name = tag.label()+"_embedPt";
88  discMap["vs_embedPt"] =
89  fs->make<TH2F>(vs_embedpt_name.c_str(), vs_embedpt_name.c_str(),
90  nbins, min, max, 100, 0, 200);
91 
92  // 3D histogram with tau pt & jet pt
93  std::string vs_pt_jetPt_name = tag.label()+"_pt_jetPt";
94  discMap["vs_pt_jetPt"] =
95  fs->make<TH3F>(vs_pt_jetPt_name.c_str(), vs_pt_jetPt_name.c_str(),
96  nbins, min, max, 100, 0, 200, 100, 0, 200);
97 
98  std::string vs_pt_embedPt_name = tag.label()+"_pt_embedPt";
99  discMap["vs_pt_embedPt"] =
100  fs->make<TH3F>(vs_pt_embedPt_name.c_str(), vs_pt_embedPt_name.c_str(),
101  nbins, min, max, 100, 0, 200, 100, 0, 200);
102 
103 
104  std::string vs_eta_name = tag.label()+"_eta";
105  discMap["vs_eta"] =
106  fs->make<TH2F>(vs_eta_name.c_str(), vs_eta_name.c_str(),
107  nbins, min, max, 100, -2.5, 2.5);
108 
109  std::string vs_dm_name = tag.label()+"_dm";
110  discMap["vs_dm"] =
111  fs->make<TH2F>(vs_dm_name.c_str(), vs_dm_name.c_str(),
112  nbins, min, max, 15, -0.5, 14.5);
113 
114  if (plotPU_) {
115  std::string vs_truePU_name = tag.label()+"_truePU";
116  discMap["vs_truePU"] = fs->make<TH2F>(vs_truePU_name.c_str(),
117  vs_truePU_name.c_str(), nbins, min, max, 15, -0.5, 14.5);
118  std::string vs_recoPU_name = tag.label()+"_recoPU";
119  discMap["vs_recoPU"] = fs->make<TH2F>(vs_recoPU_name.c_str(),
120  vs_recoPU_name.c_str(), nbins, min, max, 15, -0.5, 14.5);
121  }
122 
123  histos_[tag.label()] = discMap;
124  }
125 }
126 
127 void
129  const edm::EventSetup &es) {
130  // Get the input collection to clean
132  evt.getByLabel(src_, input);
133 
134  // Cast the input candidates to Refs to real taus
135  reco::PFTauRefVector inputRefs =
136  reco::tau::castView<reco::PFTauRefVector>(input);
137 
140  if (plotPU_) {
141  evt.getByLabel(pileupInfoSrc_, puInfo);
142  evt.getByLabel(pileupVerticesSrc_, puVertices);
143  }
144 
145  // Plot the discriminator output for each of our taus
146  BOOST_FOREACH(const reco::PFTauRef& tau, inputRefs) {
147  // Plot each discriminator
148  BOOST_FOREACH(const edm::InputTag &tag, discs_) {
150  evt.getByLabel(tag, discHandle);
151  //const HistoMap &discHistos = disc.second;
152  double result = (*discHandle)[tau];
153  HistoMap& mymap = histos_[tag.label()];
154  mymap["plain"]->Fill(result);
155  mymap["vs_pt"]->Fill(result, tau->pt());
156  mymap["vs_jetPt"]->Fill(result, tau->jetRef()->pt());
157  mymap["vs_embedPt"]->Fill(result, tau->alternatLorentzVect().pt());
158  dynamic_cast<TH3F*>(mymap["vs_pt_jetPt"])->Fill(
159  result, tau->pt(), tau->jetRef()->pt());
160  dynamic_cast<TH3F*>(mymap["vs_pt_embedPt"])->Fill(
161  result, tau->pt(), tau->alternatLorentzVect().pt());
162  mymap["vs_eta"]->Fill(result, tau->eta());
163  mymap["vs_dm"]->Fill(result, tau->decayMode());
164  if (plotPU_ && tau->pt() > pileupPtCut_) {
165  if (puInfo.isValid())
166  mymap["vs_truePU"]->Fill(result, puInfo->getPU_NumInteractions());
167  mymap["vs_recoPU"]->Fill(result, puVertices->size());
168  }
169  }
170  }
171 }
172 
T getParameter(std::string const &) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
RecoTauPlotDiscriminator(const edm::ParameterSet &pset)
static std::string const input
Definition: EdmProvDump.cc:44
tuple result
Definition: mps_fire.py:95
void analyze(const edm::Event &evt, const edm::EventSetup &es) override
std::map< std::string, HistoMap > DiscMap
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
T min(T a, T b)
Definition: MathUtil.h:58
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:418
std::map< std::string, TH1 * > HistoMap
std::vector< edm::InputTag > VInputTag
std::string const & label() const
Definition: InputTag.h:36