00001 #include "PhysicsTools/PatExamples/plugins/PatTauAnalyzer.h"
00002
00003 #include "FWCore/Framework/interface/Frameworkfwd.h"
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005 #include "FWCore/ServiceRegistry/interface/Service.h"
00006 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00007 #include "DataFormats/PatCandidates/interface/Tau.h"
00008
00009 #include <TMath.h>
00010
00011 const reco::GenParticle* getGenTau(const pat::Tau& patTau)
00012 {
00013 std::vector<reco::GenParticleRef> associatedGenParticles = patTau.genParticleRefs();
00014 for ( std::vector<reco::GenParticleRef>::const_iterator it = associatedGenParticles.begin();
00015 it != associatedGenParticles.end(); ++it ) {
00016 if ( it->isAvailable() ) {
00017 const reco::GenParticleRef& genParticle = (*it);
00018 if ( genParticle->pdgId() == -15 || genParticle->pdgId() == +15 ) return genParticle.get();
00019 }
00020 }
00021
00022 return 0;
00023 }
00024
00025 PatTauAnalyzer::PatTauAnalyzer(const edm::ParameterSet& cfg)
00026 {
00027
00028
00029
00030 src_ = cfg.getParameter<edm::InputTag>("src");
00031
00032
00033
00034 requireGenTauMatch_ = cfg.getParameter<bool>("requireGenTauMatch");
00035
00036
00037
00038 discrByLeadTrack_ = cfg.getParameter<std::string>("discrByLeadTrack");
00039
00040
00041 discrByIso_ = cfg.getParameter<std::string>("discrByIso");
00042
00043
00044 discrByTaNC_ = cfg.getParameter<std::string>("discrByTaNC");
00045
00046 }
00047
00048 PatTauAnalyzer::~PatTauAnalyzer()
00049 {
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 }
00085
00086 void PatTauAnalyzer::beginJob()
00087 {
00088
00089
00090 edm::Service<TFileService> fs;
00091
00092
00093 hGenTauEnergy_ = fs->make<TH1F>("GenTauEnergy", "GenTauEnergy", 30, 0., 150.);
00094 hGenTauPt_ = fs->make<TH1F>("GenTauPt", "GenTauPt", 30, 0., 150.);
00095 hGenTauEta_ = fs->make<TH1F>("GenTauEta", "GenTauEta", 24, -3., +3.);
00096 hGenTauPhi_ = fs->make<TH1F>("GenTauPhi", "GenTauPhi", 18, -TMath::Pi(), +TMath::Pi());
00097
00098
00099
00100 hTauJetEnergy_ = fs->make<TH1F>("TauJetEnergy", "TauJetEnergy", 30, 0., 150.);
00101 hTauJetPt_ = fs->make<TH1F>("TauJetPt", "TauJetPt", 30, 0., 150.);
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 hNumTauJets_ = fs->make<TH1F>("NumTauJets", "NumTauJets", 10, -0.5, 9.5);
00122
00123
00124 hTauLeadTrackPt_ = fs->make<TH1F>("TauLeadTrackPt", "TauLeadTrackPt", 40, 0., 100.);
00125
00126
00127 hTauNumSigConeTracks_ = fs->make<TH1F>("TauNumSigConeTracks", "TauNumSigConeTracks", 10, -0.5, 9.5);
00128 hTauNumIsoConeTracks_ = fs->make<TH1F>("TauNumIsoConeTracks", "TauNumIsoConeTracks", 20, -0.5, 19.5);
00129
00130
00131
00132 hTauDiscrByIso_ = fs->make<TH1F>("TauDiscrByIso", "TauDiscrByIso", 103, -0.015, 1.015);
00133 hTauDiscrByTaNC_ = fs->make<TH1F>("TauDiscrByTaNC", "TauDiscrByTaNC", 103, -0.015, 1.015);
00134
00135
00136 hTauDiscrAgainstElectrons_ = fs->make<TH1F>("TauDiscrAgainstElectrons", "TauDiscrAgainstElectrons", 103, -0.015, 1.015);
00137 hTauDiscrAgainstMuons_ = fs->make<TH1F>("TauDiscrAgainstMuons", "TauDiscrAgainstMuons", 103, -0.015, 1.015);
00138
00139
00140 hTauJetEnergyIsoPassed_ = fs->make<TH1F>("TauJetEnergyIsoPassed", "TauJetEnergyIsoPassed", 30, 0., 150.);
00141 hTauJetPtIsoPassed_ = fs->make<TH1F>("TauJetPtIsoPassed", "TauJetPtIsoPassed", 30, 0., 150.);
00142 hTauJetEtaIsoPassed_ = fs->make<TH1F>("TauJetEtaIsoPassed", "TauJetEtaIsoPassed", 24, -3., +3.);
00143 hTauJetPhiIsoPassed_ = fs->make<TH1F>("TauJetPhiIsoPassed", "TauJetPhiIsoPassed", 18, -TMath::Pi(), +TMath::Pi());
00144
00145
00146 hTauJetEnergyTaNCpassed_ = fs->make<TH1F>("TauJetEnergyTaNCpassed", "TauJetEnergyTaNCpassed", 30, 0., 150.);
00147 hTauJetPtTaNCpassed_ = fs->make<TH1F>("TauJetPtTaNCpassed", "TauJetPtTaNCpassed", 30, 0., 150.);
00148 hTauJetEtaTaNCpassed_ = fs->make<TH1F>("TauJetEtaTaNCpassed", "TauJetEtaTaNCpassed", 24, -3., +3.);
00149 hTauJetPhiTaNCpassed_ = fs->make<TH1F>("TauJetPhiTaNCpassed", "TauJetPhiTaNCpassed", 18, -TMath::Pi(), +TMath::Pi());
00150 }
00151
00152 void PatTauAnalyzer::analyze(const edm::Event& evt, const edm::EventSetup& es)
00153 {
00154
00155
00156 edm::Handle<pat::TauCollection> patTaus;
00157 evt.getByLabel(src_, patTaus);
00158
00159 hNumTauJets_->Fill(patTaus->size());
00160
00161 for ( pat::TauCollection::const_iterator patTau = patTaus->begin();
00162 patTau != patTaus->end(); ++patTau ) {
00163
00164
00165 const reco::GenParticle* genTau = getGenTau(*patTau);
00166 if ( requireGenTauMatch_ && !genTau ) continue;
00167
00168
00169 if ( genTau ) {
00170 hGenTauEnergy_->Fill(genTau->energy());
00171 hGenTauPt_->Fill(genTau->pt());
00172 hGenTauEta_->Fill(genTau->eta());
00173 hGenTauPhi_->Fill(genTau->phi());
00174 }
00175
00176
00177
00178 hTauJetEnergy_->Fill(patTau->energy());
00179 hTauJetPt_->Fill(patTau->pt());
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209 hTauNumSigConeTracks_->Fill(patTau->signalTracks().size());
00210 hTauNumIsoConeTracks_->Fill(patTau->isolationTracks().size());
00211
00212
00213
00214
00215
00216 float discrByIso = ( patTau->tauID(discrByLeadTrack_.data()) > 0.5 ) ? patTau->tauID(discrByIso_.data()) : 0.;
00217 hTauDiscrByIso_->Fill(discrByIso);
00218 float discrByTaNC = ( patTau->tauID(discrByLeadTrack_.data()) > 0.5 ) ? patTau->tauID(discrByTaNC_.data()) : 0.;
00219 hTauDiscrByTaNC_->Fill(discrByTaNC);
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238 hTauDiscrAgainstMuons_->Fill(patTau->tauID("againstMuon"));
00239
00240
00241 if ( discrByIso > 0.5 ) {
00242 hTauJetEnergyIsoPassed_->Fill(patTau->energy());
00243 hTauJetPtIsoPassed_->Fill(patTau->pt());
00244 hTauJetEtaIsoPassed_->Fill(patTau->eta());
00245 hTauJetPhiIsoPassed_->Fill(patTau->phi());
00246 }
00247
00248
00249 if ( discrByTaNC > 0.5 ) {
00250 hTauJetEnergyTaNCpassed_->Fill(patTau->energy());
00251 hTauJetPtTaNCpassed_->Fill(patTau->pt());
00252 hTauJetEtaTaNCpassed_->Fill(patTau->eta());
00253 hTauJetPhiTaNCpassed_->Fill(patTau->phi());
00254 }
00255 }
00256 }
00257
00258 void PatTauAnalyzer::endJob()
00259 {
00260
00261 }
00262
00263 #include "FWCore/Framework/interface/MakerMacros.h"
00264
00265 DEFINE_FWK_MODULE(PatTauAnalyzer);
00266