CMS 3D CMS Logo

PatTauAnalyzer.cc
Go to the documentation of this file.
2 
7 
8 #include <TMath.h>
9 
10 const reco::GenParticle* getGenTau(const pat::Tau& patTau) {
11  std::vector<reco::GenParticleRef> associatedGenParticles = patTau.genParticleRefs();
12  for (std::vector<reco::GenParticleRef>::const_iterator it = associatedGenParticles.begin();
13  it != associatedGenParticles.end();
14  ++it) {
15  if (it->isAvailable()) {
16  const reco::GenParticleRef& genParticle = (*it);
17  if (genParticle->pdgId() == -15 || genParticle->pdgId() == +15)
18  return genParticle.get();
19  }
20  }
21 
22  return nullptr;
23 }
24 
26  //std::cout << "<PatTauAnalyzer::PatTauAnalyzer>:" << std::endl;
27 
28  //--- read name of pat::Tau collection
29  src_ = cfg.getParameter<edm::InputTag>("src");
30  //std::cout << " src = " << src_ << std::endl;
31  srcToken_ = consumes<pat::TauCollection>(src_);
32 
33  //--- fill histograms for all tau-jet candidates or for "real" taus only ?
34  requireGenTauMatch_ = cfg.getParameter<bool>("requireGenTauMatch");
35  //std::cout << " requireGenTauMatch = " << requireGenTauMatch_ << std::endl;
36 
37  //--- read names of tau id. discriminators
38  discrByLeadTrack_ = cfg.getParameter<std::string>("discrByLeadTrack");
39  //std::cout << " discrByLeadTrack = " << discrByLeadTrack_ << std::endl;
40 
41  discrByIso_ = cfg.getParameter<std::string>("discrByIso");
42  //std::cout << " discrByIso = " << discrByIso_ << std::endl;
43 
44  discrByTaNC_ = cfg.getParameter<std::string>("discrByTaNC");
45  //std::cout << " discrByTaNC = " << discrByTaNC_ << std::endl;
46 }
47 
49  //std::cout << "<PatTauAnalyzer::~PatTauAnalyzer>:" << std::endl;
50 
51  //--- clean-up memory;
52  // delete all histograms
53  /*
54  deletion of histograms taken care of by TFileService;
55  do not delete them here (if the histograms are deleted here,
56  they will not appear in the ROOT file written by TFileService)
57 
58  delete hGenTauEnergy_;
59  delete hGenTauPt_;
60  delete hGenTauEta_;
61  delete hGenTauPhi_;
62  delete hTauJetEnergy_;
63  delete hTauJetPt_;
64  delete hTauJetEta_;
65  delete hTauJetPhi_;
66  delete hNumTauJets_;
67  delete hTauLeadTrackPt_;
68  delete hTauNumSigConeTracks_;
69  delete hTauNumIsoConeTracks_;
70  delete hTauDiscrByIso_;
71  delete hTauDiscrByTaNC_;
72  delete hTauDiscrAgainstElectrons_;
73  delete hTauDiscrAgainstMuons_;
74  delete hTauJetEnergyIsoPassed_;
75  delete hTauJetPtIsoPassed_;
76  delete hTauJetEtaIsoPassed_;
77  delete hTauJetPhiIsoPassed_;
78  delete hTauJetEnergyTaNCpassed_;
79  delete hTauJetPtTaNCpassed_;
80  delete hTauJetEtaTaNCpassed_;
81  delete hTauJetPhiTaNCpassed_;
82  */
83 }
84 
86  //--- retrieve handle to auxiliary service
87  // used for storing histograms into ROOT file
89 
90  //--- book generator level histograms
91  hGenTauEnergy_ = fs->make<TH1F>("GenTauEnergy", "GenTauEnergy", 30, 0., 150.);
92  hGenTauPt_ = fs->make<TH1F>("GenTauPt", "GenTauPt", 30, 0., 150.);
93  hGenTauEta_ = fs->make<TH1F>("GenTauEta", "GenTauEta", 24, -3., +3.);
94  hGenTauPhi_ = fs->make<TH1F>("GenTauPhi", "GenTauPhi", 18, -TMath::Pi(), +TMath::Pi());
95 
96  //--- book reconstruction level histograms
97  // for tau-jet Energy, Pt, Eta, Phi
98  hTauJetEnergy_ = fs->make<TH1F>("TauJetEnergy", "TauJetEnergy", 30, 0., 150.);
99  hTauJetPt_ = fs->make<TH1F>("TauJetPt", "TauJetPt", 30, 0., 150.);
100  //
101  // TO-DO: add histograms for eta and phi of the tau-jet candidate
102  //
103  // NOTE:
104  // 1.) please use
105  // "TauJetEta" and "TauJetPhi"
106  // for the names of the histograms and choose the exact same binning
107  // as is used for the histograms
108  // "TauJetEtaIsoPassed" and "TauJetPhiIsoPassed"
109  // below
110  //
111  // 2.) please check the histograms
112  // hTauJetEta_ and hTauJetPt_
113  // have already been defined in PatTauAnalyzer.h
114  //
115  //hTauJetEta_ =...
116  //hTauJetPt_ =...
117 
118  //... for number of tau-jet candidates
119  hNumTauJets_ = fs->make<TH1F>("NumTauJets", "NumTauJets", 10, -0.5, 9.5);
120 
121  //... for Pt of highest Pt track within signal cone tau-jet...
122  hTauLeadTrackPt_ = fs->make<TH1F>("TauLeadTrackPt", "TauLeadTrackPt", 40, 0., 100.);
123 
124  //... for total number of tracks within signal/isolation cones
125  hTauNumSigConeTracks_ = fs->make<TH1F>("TauNumSigConeTracks", "TauNumSigConeTracks", 10, -0.5, 9.5);
126  hTauNumIsoConeTracks_ = fs->make<TH1F>("TauNumIsoConeTracks", "TauNumIsoConeTracks", 20, -0.5, 19.5);
127 
128  //... for values of tau id. discriminators based on track isolation cut/
129  // neural network-based tau id.
130  hTauDiscrByIso_ = fs->make<TH1F>("TauDiscrByIso", "TauDiscrByIso", 103, -0.015, 1.015);
131  hTauDiscrByTaNC_ = fs->make<TH1F>("TauDiscrByTaNC", "TauDiscrByTaNC", 103, -0.015, 1.015);
132 
133  //... for values of tau id. discriminators against (unidentified) electrons and muons
135  fs->make<TH1F>("TauDiscrAgainstElectrons", "TauDiscrAgainstElectrons", 103, -0.015, 1.015);
136  hTauDiscrAgainstMuons_ = fs->make<TH1F>("TauDiscrAgainstMuons", "TauDiscrAgainstMuons", 103, -0.015, 1.015);
137 
138  //... for Energy, Pt, Eta, Phi of tau-jets passing the discriminatorByIsolation selection
139  hTauJetEnergyIsoPassed_ = fs->make<TH1F>("TauJetEnergyIsoPassed", "TauJetEnergyIsoPassed", 30, 0., 150.);
140  hTauJetPtIsoPassed_ = fs->make<TH1F>("TauJetPtIsoPassed", "TauJetPtIsoPassed", 30, 0., 150.);
141  hTauJetEtaIsoPassed_ = fs->make<TH1F>("TauJetEtaIsoPassed", "TauJetEtaIsoPassed", 24, -3., +3.);
142  hTauJetPhiIsoPassed_ = fs->make<TH1F>("TauJetPhiIsoPassed", "TauJetPhiIsoPassed", 18, -TMath::Pi(), +TMath::Pi());
143 
144  //... for Energy, Pt, Eta, Phi of tau-jets passing the discriminatorByTaNC ("Tau Neural Classifier") selection
145  hTauJetEnergyTaNCpassed_ = fs->make<TH1F>("TauJetEnergyTaNCpassed", "TauJetEnergyTaNCpassed", 30, 0., 150.);
146  hTauJetPtTaNCpassed_ = fs->make<TH1F>("TauJetPtTaNCpassed", "TauJetPtTaNCpassed", 30, 0., 150.);
147  hTauJetEtaTaNCpassed_ = fs->make<TH1F>("TauJetEtaTaNCpassed", "TauJetEtaTaNCpassed", 24, -3., +3.);
148  hTauJetPhiTaNCpassed_ = fs->make<TH1F>("TauJetPhiTaNCpassed", "TauJetPhiTaNCpassed", 18, -TMath::Pi(), +TMath::Pi());
149 }
150 
152  //std::cout << "<PatTauAnalyzer::analyze>:" << std::endl;
153 
156 
157  hNumTauJets_->Fill(patTaus->size());
158 
159  for (pat::TauCollection::const_iterator patTau = patTaus->begin(); patTau != patTaus->end(); ++patTau) {
160  //--- skip fake taus in case configuration parameters set to do so...
161  const reco::GenParticle* genTau = getGenTau(*patTau);
162  if (requireGenTauMatch_ && !genTau)
163  continue;
164 
165  //--- fill generator level histograms
166  if (genTau) {
167  hGenTauEnergy_->Fill(genTau->energy());
168  hGenTauPt_->Fill(genTau->pt());
169  hGenTauEta_->Fill(genTau->eta());
170  hGenTauPhi_->Fill(genTau->phi());
171  }
172 
173  //--- fill reconstruction level histograms
174  // for Pt of highest Pt track within signal cone tau-jet...
175  hTauJetEnergy_->Fill(patTau->energy());
176  hTauJetPt_->Fill(patTau->pt());
177  //
178  // TO-DO:
179  // 1.) fill histograms
180  // hTauJetEta_ and hTauJetPhi_
181  // with the pseudo-rapidity and azimuthal angle
182  // of the tau-jet candidate respectively
183  // hTauJetEta_->...
184  // hTauJetPhi_->...
185  //
186  // 2.) fill histogram
187  // hTauLeadTrackPt_
188  // with the transverse momentum of the highest Pt ("leading") track within the tau-jet
189  //
190  // NOTE:
191  // 1.) please have a look at
192  // http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/CMSSW/DataFormats/Candidate/interface/Particle.h?revision=1.28&view=markup
193  // to find the methods for accessing eta and phi of the tau-jet
194  //
195  // 2.) please have a look at
196  // http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/CMSSW/DataFormats/PatCandidates/interface/Tau.h?revision=1.25&view=markup
197  // to find the method for accessing the leading track
198  //
199  // 3.) the method pat::Tau::leadTrack returns a reference (reco::TrackRef) to a reco::Track object
200  // this reference can be null (in case no high Pt track has been reconstructed within the tau-jet),
201  // so a check if the leadTrack exists is needed before dereferencing the reco::TrackRef via operator->
202  //
203  // if ( patTau->leadTrack().isAvailable() ) hTauLeadTrackPt_->Fill(patTau->leadTrack()->pt());
204 
205  //... for total number of tracks within signal/isolation cones
206  hTauNumSigConeTracks_->Fill(patTau->signalTracks().size());
207  hTauNumIsoConeTracks_->Fill(patTau->isolationTracks().size());
208 
209  //... for values of tau id. discriminators based on track isolation cut/
210  // neural network-based tau id.
211  // (combine with requirement of at least one "leading" track of Pt > 5. GeV
212  // within the signal cone of the tau-jet)
213  float discrByIso = (patTau->tauID(discrByLeadTrack_.data()) > 0.5) ? patTau->tauID(discrByIso_.data()) : 0.;
214  hTauDiscrByIso_->Fill(discrByIso);
215  float discrByTaNC = (patTau->tauID(discrByLeadTrack_.data()) > 0.5) ? patTau->tauID(discrByTaNC_.data()) : 0.;
216  hTauDiscrByTaNC_->Fill(discrByTaNC);
217 
218  //... for values of tau id. discriminators against (unidentified) electrons and muons
219  //
220  // TO-DO: fill histogram
221  // hTauDiscrAgainstElectrons_
222  // with the value of the discriminatorAgainstElectronsLoose
223  //
224  // NOTE:
225  // 1.) please have a look at
226  // http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/CMSSW/DataFormats/PatCandidates/interface/Tau.h?revision=1.25&view=markup
227  // to find the method for accessing the tau id. information
228  //
229  // 2.) please have a look at
230  // http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/CMSSW/PhysicsTools/PatAlgos/python/tools/tauTools.py?revision=1.43&view=markup
231  // and convince yourself that the string "againstElectronLoose" needs to be passed as argument
232  // of the pat::Tau::tauID method
233  //
234  // hTauDiscrAgainstElectrons_->Fill...
235  hTauDiscrAgainstMuons_->Fill(patTau->tauID("againstMuonLoose"));
236 
237  //... for Energy, Pt, Eta, Phi of tau-jets passing the discriminatorByIsolation selection
238  if (discrByIso > 0.5) {
239  hTauJetEnergyIsoPassed_->Fill(patTau->energy());
240  hTauJetPtIsoPassed_->Fill(patTau->pt());
241  hTauJetEtaIsoPassed_->Fill(patTau->eta());
242  hTauJetPhiIsoPassed_->Fill(patTau->phi());
243  }
244 
245  //... for Energy, Pt, Eta, Phi of tau-jets passing the discriminatorByTaNC ("Tau Neural Classifier") selection
246  if (discrByTaNC > 0.5) {
247  hTauJetEnergyTaNCpassed_->Fill(patTau->energy());
248  hTauJetPtTaNCpassed_->Fill(patTau->pt());
249  hTauJetEtaTaNCpassed_->Fill(patTau->eta());
250  hTauJetPhiTaNCpassed_->Fill(patTau->phi());
251  }
252  }
253 }
254 
256  //--- nothing to be done yet...
257 }
258 
260 
PatTauAnalyzer::hTauLeadTrackPt_
TH1 * hTauLeadTrackPt_
Definition: PatTauAnalyzer.h:51
hemisphereProducer_cfi.patTaus
patTaus
Definition: hemisphereProducer_cfi.py:8
PatTauAnalyzer::hGenTauEnergy_
TH1 * hGenTauEnergy_
Definition: PatTauAnalyzer.h:38
PatTauAnalyzer::hTauJetEnergy_
TH1 * hTauJetEnergy_
Definition: PatTauAnalyzer.h:44
PatTauAnalyzer::hTauNumSigConeTracks_
TH1 * hTauNumSigConeTracks_
Definition: PatTauAnalyzer.h:53
MessageLogger.h
reco::GenParticle
Definition: GenParticle.h:21
pat::Tau
Analysis-level tau class.
Definition: Tau.h:53
edm::Ref::get
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
PatTauAnalyzer::hGenTauEta_
TH1 * hGenTauEta_
Definition: PatTauAnalyzer.h:40
reco::LeafCandidate::pt
double pt() const final
transverse momentum
Definition: LeafCandidate.h:146
edm::Handle
Definition: AssociativeIterator.h:50
edm::Ref< GenParticleCollection >
PatTauAnalyzer::hTauDiscrByIso_
TH1 * hTauDiscrByIso_
Definition: PatTauAnalyzer.h:56
PatTauAnalyzer::hNumTauJets_
TH1 * hNumTauJets_
Definition: PatTauAnalyzer.h:49
MakerMacros.h
PatTauAnalyzer::~PatTauAnalyzer
~PatTauAnalyzer() override
Definition: PatTauAnalyzer.cc:48
PatTauAnalyzer::hGenTauPhi_
TH1 * hGenTauPhi_
Definition: PatTauAnalyzer.h:41
PatTauAnalyzer::hTauJetPhiIsoPassed_
TH1 * hTauJetPhiIsoPassed_
Definition: PatTauAnalyzer.h:64
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
PatTauAnalyzer::hTauDiscrByTaNC_
TH1 * hTauDiscrByTaNC_
Definition: PatTauAnalyzer.h:57
PatTauAnalyzer::src_
edm::InputTag src_
Definition: PatTauAnalyzer.h:28
Service.h
PatTauAnalyzer::discrByTaNC_
std::string discrByTaNC_
Definition: PatTauAnalyzer.h:35
pat::PATObject::genParticleRefs
std::vector< reco::GenParticleRef > genParticleRefs() const
Definition: PATObject.h:784
PatTauAnalyzer::endJob
void endJob() override
Definition: PatTauAnalyzer.cc:255
PatTauAnalyzer::hTauJetEnergyIsoPassed_
TH1 * hTauJetEnergyIsoPassed_
Definition: PatTauAnalyzer.h:61
getGenTau
const reco::GenParticle * getGenTau(const pat::Tau &patTau)
Definition: PatTauAnalyzer.cc:10
PatTauAnalyzer::hTauJetEtaTaNCpassed_
TH1 * hTauJetEtaTaNCpassed_
Definition: PatTauAnalyzer.h:68
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
PatTauAnalyzer::hTauJetPhiTaNCpassed_
TH1 * hTauJetPhiTaNCpassed_
Definition: PatTauAnalyzer.h:69
PatTauAnalyzer::hTauNumIsoConeTracks_
TH1 * hTauNumIsoConeTracks_
Definition: PatTauAnalyzer.h:54
PatTauAnalyzer::srcToken_
edm::EDGetTokenT< pat::TauCollection > srcToken_
Definition: PatTauAnalyzer.h:29
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PatTauAnalyzer::requireGenTauMatch_
bool requireGenTauMatch_
Definition: PatTauAnalyzer.h:31
TFileService.h
PatTauAnalyzer::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: PatTauAnalyzer.cc:151
edm::ParameterSet
Definition: ParameterSet.h:36
PatTauAnalyzer::discrByIso_
std::string discrByIso_
Definition: PatTauAnalyzer.h:34
reco::LeafCandidate::eta
double eta() const final
momentum pseudorapidity
Definition: LeafCandidate.h:152
PatTauAnalyzer
Definition: PatTauAnalyzer.h:16
edm::Service< TFileService >
PatTauAnalyzer::hTauJetEnergyTaNCpassed_
TH1 * hTauJetEnergyTaNCpassed_
Definition: PatTauAnalyzer.h:66
PatTauAnalyzer.h
edm::EventSetup
Definition: EventSetup.h:57
PatTauAnalyzer::hGenTauPt_
TH1 * hGenTauPt_
Definition: PatTauAnalyzer.h:39
looper.cfg
cfg
Definition: looper.py:297
PatTauAnalyzer::hTauDiscrAgainstElectrons_
TH1 * hTauDiscrAgainstElectrons_
Definition: PatTauAnalyzer.h:58
reco::LeafCandidate::phi
double phi() const final
momentum azimuthal angle
Definition: LeafCandidate.h:148
Frameworkfwd.h
PatTauAnalyzer::hTauJetPtIsoPassed_
TH1 * hTauJetPtIsoPassed_
Definition: PatTauAnalyzer.h:62
PatTauAnalyzer::hTauJetPt_
TH1 * hTauJetPt_
Definition: PatTauAnalyzer.h:45
PatTauAnalyzer::hTauDiscrAgainstMuons_
TH1 * hTauDiscrAgainstMuons_
Definition: PatTauAnalyzer.h:59
PatTauAnalyzer::beginJob
void beginJob() override
Definition: PatTauAnalyzer.cc:85
reco::LeafCandidate::energy
double energy() const final
energy
Definition: LeafCandidate.h:125
Pi
const double Pi
Definition: CosmicMuonParameters.h:18
PatTauAnalyzer::PatTauAnalyzer
PatTauAnalyzer(const edm::ParameterSet &)
Definition: PatTauAnalyzer.cc:25
PatTauAnalyzer::hTauJetEtaIsoPassed_
TH1 * hTauJetEtaIsoPassed_
Definition: PatTauAnalyzer.h:63
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
TFileService::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileService.h:64
PatTauAnalyzer::hTauJetPtTaNCpassed_
TH1 * hTauJetPtTaNCpassed_
Definition: PatTauAnalyzer.h:67
PatTauAnalyzer::discrByLeadTrack_
std::string discrByLeadTrack_
Definition: PatTauAnalyzer.h:33