CMS 3D CMS Logo

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 
14 
16 
20 
24 
27 
28 #include <TH1F.h>
29 #include <TH2F.h>
30 #include <TH3F.h>
31 
33  public:
36  void analyze(const edm::Event &evt, const edm::EventSetup &es) override;
37  private:
39  typedef std::map<std::string, TH1*> HistoMap;
40  typedef std::map<std::string, HistoMap> DiscMap;
41  typedef std::vector<edm::InputTag> VInputTag;
42  VInputTag discs_;
43  bool plotPU_;
44  double pileupPtCut_;
47  DiscMap histos_;
48 };
49 
51  :src_(pset.getParameter<edm::InputTag>("src")) {
52  uint32_t nbins = pset.getParameter<uint32_t>("nbins");
53  double min = pset.getParameter<double>("min");
54  double max = pset.getParameter<double>("max");
56  // Get the discriminators
57  discs_ = pset.getParameter<std::vector<edm::InputTag> >("discriminators");
58 
59  plotPU_ = pset.getParameter<bool>("plotPU");
60  if (plotPU_) {
61  pileupPtCut_ = pset.getParameter<double>("pileupTauPtCut");
62  pileupInfoSrc_ = pset.getParameter<edm::InputTag>("pileupInfo");
63  pileupVerticesSrc_ = pset.getParameter<edm::InputTag>("pileupVertices");
64  }
65 
66  for(auto const& tag : discs_) {
67  HistoMap discMap;
68  discMap["plain"] =
69  fs->make<TH1F>(tag.label().c_str(), tag.label().c_str(),
70  nbins, min, max);
71 
72  // Make correlation plots w.r.t tau pt
73  std::string vs_pt_name = tag.label()+"_pt";
74  discMap["vs_pt"] =
75  fs->make<TH2F>(vs_pt_name.c_str(), vs_pt_name.c_str(),
76  nbins, min, max, 100, 0, 200);
77 
78  // W.r.t. jet pt
79  std::string vs_jetpt_name = tag.label()+"_jetPt";
80  discMap["vs_jetPt"] =
81  fs->make<TH2F>(vs_jetpt_name.c_str(), vs_jetpt_name.c_str(),
82  nbins, min, max, 100, 0, 200);
83 
84  // W.r.t. embedded pt in alternat lorentz vector (used to hold gen tau pt)
85  std::string vs_embedpt_name = tag.label()+"_embedPt";
86  discMap["vs_embedPt"] =
87  fs->make<TH2F>(vs_embedpt_name.c_str(), vs_embedpt_name.c_str(),
88  nbins, min, max, 100, 0, 200);
89 
90  // 3D histogram with tau pt & jet pt
91  std::string vs_pt_jetPt_name = tag.label()+"_pt_jetPt";
92  discMap["vs_pt_jetPt"] =
93  fs->make<TH3F>(vs_pt_jetPt_name.c_str(), vs_pt_jetPt_name.c_str(),
94  nbins, min, max, 100, 0, 200, 100, 0, 200);
95 
96  std::string vs_pt_embedPt_name = tag.label()+"_pt_embedPt";
97  discMap["vs_pt_embedPt"] =
98  fs->make<TH3F>(vs_pt_embedPt_name.c_str(), vs_pt_embedPt_name.c_str(),
99  nbins, min, max, 100, 0, 200, 100, 0, 200);
100 
101 
102  std::string vs_eta_name = tag.label()+"_eta";
103  discMap["vs_eta"] =
104  fs->make<TH2F>(vs_eta_name.c_str(), vs_eta_name.c_str(),
105  nbins, min, max, 100, -2.5, 2.5);
106 
107  std::string vs_dm_name = tag.label()+"_dm";
108  discMap["vs_dm"] =
109  fs->make<TH2F>(vs_dm_name.c_str(), vs_dm_name.c_str(),
110  nbins, min, max, 15, -0.5, 14.5);
111 
112  if (plotPU_) {
113  std::string vs_truePU_name = tag.label()+"_truePU";
114  discMap["vs_truePU"] = fs->make<TH2F>(vs_truePU_name.c_str(),
115  vs_truePU_name.c_str(), nbins, min, max, 15, -0.5, 14.5);
116  std::string vs_recoPU_name = tag.label()+"_recoPU";
117  discMap["vs_recoPU"] = fs->make<TH2F>(vs_recoPU_name.c_str(),
118  vs_recoPU_name.c_str(), nbins, min, max, 15, -0.5, 14.5);
119  }
120 
121  histos_[tag.label()] = discMap;
122  }
123 }
124 
125 void
127  const edm::EventSetup &es) {
128  // Get the input collection to clean
130  evt.getByLabel(src_, input);
131 
132  // Cast the input candidates to Refs to real taus
133  reco::PFTauRefVector inputRefs =
134  reco::tau::castView<reco::PFTauRefVector>(input);
135 
138  if (plotPU_) {
139  evt.getByLabel(pileupInfoSrc_, puInfo);
140  evt.getByLabel(pileupVerticesSrc_, puVertices);
141  }
142 
143  // Plot the discriminator output for each of our taus
144  for(auto const& tau : inputRefs) {
145  // Plot each discriminator
146  for(auto const& tag : discs_) {
148  evt.getByLabel(tag, discHandle);
149  //const HistoMap &discHistos = disc.second;
150  double result = (*discHandle)[tau];
151  HistoMap& mymap = histos_[tag.label()];
152  mymap["plain"]->Fill(result);
153  mymap["vs_pt"]->Fill(result, tau->pt());
154  mymap["vs_jetPt"]->Fill(result, tau->jetRef()->pt());
155  mymap["vs_embedPt"]->Fill(result, tau->alternatLorentzVect().pt());
156  dynamic_cast<TH3F*>(mymap["vs_pt_jetPt"])->Fill(
157  result, tau->pt(), tau->jetRef()->pt());
158  dynamic_cast<TH3F*>(mymap["vs_pt_embedPt"])->Fill(
159  result, tau->pt(), tau->alternatLorentzVect().pt());
160  mymap["vs_eta"]->Fill(result, tau->eta());
161  mymap["vs_dm"]->Fill(result, tau->decayMode());
162  if (plotPU_ && tau->pt() > pileupPtCut_) {
163  if (puInfo.isValid())
164  mymap["vs_truePU"]->Fill(result, puInfo->getPU_NumInteractions());
165  mymap["vs_recoPU"]->Fill(result, puVertices->size());
166  }
167  }
168  }
169 }
170 
T getParameter(std::string const &) const
RecoTauPlotDiscriminator(const edm::ParameterSet &pset)
static std::string const input
Definition: EdmProvDump.cc:48
void analyze(const edm::Event &evt, const edm::EventSetup &es) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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:480
std::map< std::string, TH1 * > HistoMap
std::vector< edm::InputTag > VInputTag
HLT enums.