File indexing completed on 2024-04-06 12:33:03
0001 #include <memory>
0002 #include "Validation/RecoEgamma/plugins/PhotonValidatorMiniAOD.h"
0003
0004 #include "FWCore/Framework/interface/Frameworkfwd.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "FWCore/Common/interface/TriggerNames.h"
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009 #include "FWCore/Utilities/interface/InputTag.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011
0012 #include "FWCore/ServiceRegistry/interface/Service.h"
0013 #include "DataFormats/Common/interface/Handle.h"
0014 #include "DataFormats/Common/interface/Ptr.h"
0015
0016 #include "DataFormats/VertexReco/interface/Vertex.h"
0017 #include "DataFormats/Common/interface/TriggerResults.h"
0018
0019
0020 #include "DataFormats/PatCandidates/interface/Photon.h"
0021 #include "DataFormats/PatCandidates/interface/PackedGenParticle.h"
0022 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0023
0024 #include "CLHEP/Units/GlobalPhysicalConstants.h"
0025 #include "TTree.h"
0026 #include "TFile.h"
0027 #include "TH1F.h"
0028 #include "TH2F.h"
0029
0030
0031
0032 PhotonValidatorMiniAOD::PhotonValidatorMiniAOD(const edm::ParameterSet &iConfig)
0033 : outputFileName_(iConfig.getParameter<std::string>("outputFileName")),
0034 photonToken_(consumes<edm::View<pat::Photon> >(
0035 iConfig.getUntrackedParameter<edm::InputTag>("PhotonTag", edm::InputTag("slimmedPhotons")))),
0036 genpartToken_(consumes<reco::GenParticleCollection>(
0037 iConfig.getUntrackedParameter<edm::InputTag>("genpartTag", edm::InputTag("prunedGenParticles"))))
0038
0039 {
0040 parameters_ = iConfig;
0041 }
0042
0043 PhotonValidatorMiniAOD::~PhotonValidatorMiniAOD() {}
0044
0045 void PhotonValidatorMiniAOD::bookHistograms(DQMStore::IBooker &iBooker, edm::Run const &run, edm::EventSetup const &) {
0046 double eMin = parameters_.getParameter<double>("eMin");
0047 double eMax = parameters_.getParameter<double>("eMax");
0048 int eBin = parameters_.getParameter<int>("eBin");
0049
0050 double etMin = parameters_.getParameter<double>("etMin");
0051 double etMax = parameters_.getParameter<double>("etMax");
0052 int etBin = parameters_.getParameter<int>("etBin");
0053
0054 double resMin = parameters_.getParameter<double>("resMin");
0055 double resMax = parameters_.getParameter<double>("resMax");
0056 int resBin = parameters_.getParameter<int>("resBin");
0057
0058 double etaMin = parameters_.getParameter<double>("etaMin");
0059 double etaMax = parameters_.getParameter<double>("etaMax");
0060 int etaBin = parameters_.getParameter<int>("etaBin");
0061
0062 double phiMin = parameters_.getParameter<double>("phiMin");
0063 double phiMax = parameters_.getParameter<double>("phiMax");
0064 int phiBin = parameters_.getParameter<int>("phiBin");
0065
0066 double r9Min = parameters_.getParameter<double>("r9Min");
0067 double r9Max = parameters_.getParameter<double>("r9Max");
0068 int r9Bin = parameters_.getParameter<int>("r9Bin");
0069
0070 iBooker.setCurrentFolder("EgammaV/PhotonValidatorMiniAOD/Photons");
0071
0072 h_scEta_[0] = iBooker.book1D("scEta_miniAOD", " SC Eta ", etaBin, etaMin, etaMax);
0073 h_scPhi_[0] = iBooker.book1D("scPhi_miniAOD", " SC Phi ", phiBin, phiMin, phiMax);
0074
0075 std::string histname = " ";
0076
0077 histname = "phoE";
0078 h_phoE_[0][0] = iBooker.book1D(histname + "All_miniAOD", " Photon Energy: All ecal ", eBin, eMin, eMax);
0079 h_phoE_[0][1] = iBooker.book1D(histname + "Barrel_miniAOD", " Photon Energy: barrel ", eBin, eMin, eMax);
0080 h_phoE_[0][2] = iBooker.book1D(histname + "Endcap_miniAOD", " Photon Energy: Endcap ", eBin, eMin, eMax);
0081
0082 histname = "phoEt";
0083 h_phoEt_[0][0] =
0084 iBooker.book1D(histname + "All_miniAOD", " Photon Transverse Energy: All ecal ", etBin, etMin, etMax);
0085 h_phoEt_[0][1] =
0086 iBooker.book1D(histname + "Barrel_miniAOD", " Photon Transverse Energy: Barrel ", etBin, etMin, etMax);
0087 h_phoEt_[0][2] =
0088 iBooker.book1D(histname + "Endcap_miniAOD", " Photon Transverse Energy: Endcap ", etBin, etMin, etMax);
0089
0090 histname = "eRes";
0091 h_phoERes_[0][0] = iBooker.book1D(
0092 histname + "All_miniAOD", " Photon E/E_{true}: All ecal; E/E_{true} (GeV)", resBin, resMin, resMax);
0093 h_phoERes_[0][1] = iBooker.book1D(
0094 histname + "Barrel_miniAOD", "Photon E/E_{true}: Barrel; E/E_{true} (GeV)", resBin, resMin, resMax);
0095 h_phoERes_[0][2] = iBooker.book1D(
0096 histname + "Endcap_miniAOD", " Photon E/E_{true}: Endcap; E/E_{true} (GeV)", resBin, resMin, resMax);
0097
0098 histname = "sigmaEoE";
0099 h_phoSigmaEoE_[0][0] =
0100 iBooker.book1D(histname + "All_miniAOD", "#sigma_{E}/E: All ecal; #sigma_{E}/E", 100, 0., 0.08);
0101 h_phoSigmaEoE_[0][1] =
0102 iBooker.book1D(histname + "Barrel_miniAOD", "#sigma_{E}/E: Barrel; #sigma_{E}/E", 100, 0., 0.08);
0103 h_phoSigmaEoE_[0][2] =
0104 iBooker.book1D(histname + "Endcap_miniAOD", "#sigma_{E}/E: Endcap, #sigma_{E}/E", 100, 0., 0.08);
0105
0106 histname = "r9";
0107 h_r9_[0][0] = iBooker.book1D(histname + "All_miniAOD", " r9: All Ecal", r9Bin, r9Min, r9Max);
0108 h_r9_[0][1] = iBooker.book1D(histname + "Barrel_miniAOD", " r9: Barrel ", r9Bin, r9Min, r9Max);
0109 h_r9_[0][2] = iBooker.book1D(histname + "Endcap_miniAOD", " r9: Endcap ", r9Bin, r9Min, r9Max);
0110 histname = "full5x5_r9";
0111 h_full5x5_r9_[0][0] = iBooker.book1D(histname + "All_miniAOD", " r9: All Ecal", r9Bin, r9Min, r9Max);
0112 h_full5x5_r9_[0][1] = iBooker.book1D(histname + "Barrel_miniAOD", " r9: Barrel ", r9Bin, r9Min, r9Max);
0113 h_full5x5_r9_[0][2] = iBooker.book1D(histname + "Endcap_miniAOD", " r9: Endcap ", r9Bin, r9Min, r9Max);
0114 histname = "r1";
0115 h_r1_[0][0] = iBooker.book1D(histname + "All_miniAOD", " e1x5/e5x5: All Ecal", r9Bin, r9Min, r9Max);
0116 h_r1_[0][1] = iBooker.book1D(histname + "Barrel_miniAOD", " e1x5/e5x5: Barrel ", r9Bin, r9Min, r9Max);
0117 h_r1_[0][2] = iBooker.book1D(histname + "Endcap_miniAOD", " e1x5/e5x5: Endcap ", r9Bin, r9Min, r9Max);
0118 histname = "r2";
0119 h_r2_[0][0] = iBooker.book1D(histname + "All_miniAOD", " e2x5/e5x5: All Ecal", r9Bin, r9Min, r9Max);
0120 h_r2_[0][1] = iBooker.book1D(histname + "Barrel_miniAOD", " e2x5/e5x5: Barrel ", r9Bin, r9Min, r9Max);
0121 h_r2_[0][2] = iBooker.book1D(histname + "Endcap_miniAOD", " e2x5/e5x5: Endcap ", r9Bin, r9Min, r9Max);
0122 histname = "hOverE";
0123 h_hOverE_[0][0] = iBooker.book1D(histname + "All_miniAOD", "H/E: All Ecal", 100, 0., 0.2);
0124 h_hOverE_[0][1] = iBooker.book1D(histname + "Barrel_miniAOD", "H/E: Barrel ", 100, 0., 0.2);
0125 h_hOverE_[0][2] = iBooker.book1D(histname + "Endcap_miniAOD", "H/E: Endcap ", 100, 0., 0.2);
0126
0127 histname = "newhOverE";
0128 h_newhOverE_[0][0] = iBooker.book1D(histname + "All_miniAOD", "new H/E: All Ecal", 100, 0., 0.2);
0129 h_newhOverE_[0][1] = iBooker.book1D(histname + "Barrel_miniAOD", "new H/E: Barrel ", 100, 0., 0.2);
0130 h_newhOverE_[0][2] = iBooker.book1D(histname + "Endcap_miniAOD", "new H/E: Endcap ", 100, 0., 0.2);
0131
0132 histname = "sigmaIetaIeta";
0133 h_sigmaIetaIeta_[0][0] = iBooker.book1D(histname + "All_miniAOD", "sigmaIetaIeta: All Ecal", 100, 0., 0.1);
0134 h_sigmaIetaIeta_[0][1] = iBooker.book1D(histname + "Barrel_miniAOD", "sigmaIetaIeta: Barrel ", 100, 0., 0.05);
0135 h_sigmaIetaIeta_[0][2] = iBooker.book1D(histname + "Endcap_miniAOD", "sigmaIetaIeta: Endcap ", 100, 0., 0.1);
0136 histname = "full5x5_sigmaIetaIeta";
0137 h_full5x5_sigmaIetaIeta_[0][0] =
0138 iBooker.book1D(histname + "All_miniAOD", "Full5x5 sigmaIetaIeta: All Ecal", 100, 0., 0.1);
0139 h_full5x5_sigmaIetaIeta_[0][1] =
0140 iBooker.book1D(histname + "Barrel_miniAOD", "Full5x5 sigmaIetaIeta: Barrel ", 100, 0., 0.05);
0141 h_full5x5_sigmaIetaIeta_[0][2] =
0142 iBooker.book1D(histname + "Endcap_miniAOD", "Full5x5 sigmaIetaIeta: Endcap ", 100, 0., 0.1);
0143
0144 histname = "ecalRecHitSumEtConeDR04";
0145 h_ecalRecHitSumEtConeDR04_[0][0] =
0146 iBooker.book1D(histname + "All_miniAOD", "ecalRecHitSumEtDR04: All Ecal", etBin, etMin, 20.);
0147 h_ecalRecHitSumEtConeDR04_[0][1] =
0148 iBooker.book1D(histname + "Barrel_miniAOD", "ecalRecHitSumEtDR04: Barrel ", etBin, etMin, 20.);
0149 h_ecalRecHitSumEtConeDR04_[0][2] =
0150 iBooker.book1D(histname + "Endcap_miniAOD", "ecalRecHitSumEtDR04: Endcap ", etBin, etMin, 20.);
0151 histname = "hcalTowerSumEtConeDR04";
0152 h_hcalTowerSumEtConeDR04_[0][0] =
0153 iBooker.book1D(histname + "All_miniAOD", "hcalTowerSumEtConeDR04: All Ecal", etBin, etMin, 20.);
0154 h_hcalTowerSumEtConeDR04_[0][1] =
0155 iBooker.book1D(histname + "Barrel_miniAOD", "hcalTowerSumEtConeDR04: Barrel ", etBin, etMin, 20.);
0156 h_hcalTowerSumEtConeDR04_[0][2] =
0157 iBooker.book1D(histname + "Endcap_miniAOD", "hcalTowerSumEtConeDR04: Endcap ", etBin, etMin, 20.);
0158
0159 histname = "hcalTowerBcSumEtConeDR04";
0160 h_hcalTowerBcSumEtConeDR04_[0][0] =
0161 iBooker.book1D(histname + "All_miniAOD", "hcalTowerBcSumEtConeDR04: All Ecal", etBin, etMin, 20.);
0162 h_hcalTowerBcSumEtConeDR04_[0][1] =
0163 iBooker.book1D(histname + "Barrel_miniAOD", "hcalTowerBcSumEtConeDR04: Barrel ", etBin, etMin, 20.);
0164 h_hcalTowerBcSumEtConeDR04_[0][2] =
0165 iBooker.book1D(histname + "Endcap_miniAOD", "hcalTowerBcSumEtConeDR04: Endcap ", etBin, etMin, 20.);
0166 histname = "isoTrkSolidConeDR04";
0167 h_isoTrkSolidConeDR04_[0][0] =
0168 iBooker.book1D(histname + "All_miniAOD", "isoTrkSolidConeDR04: All Ecal", etBin, etMin, etMax * 0.1);
0169 h_isoTrkSolidConeDR04_[0][1] =
0170 iBooker.book1D(histname + "Barrel_miniAOD", "isoTrkSolidConeDR04: Barrel ", etBin, etMin, etMax * 0.1);
0171 h_isoTrkSolidConeDR04_[0][2] =
0172 iBooker.book1D(histname + "Endcap_miniAOD", "isoTrkSolidConeDR04: Endcap ", etBin, etMin, etMax * 0.1);
0173 histname = "nTrkSolidConeDR04";
0174 h_nTrkSolidConeDR04_[0][0] = iBooker.book1D(histname + "All_miniAOD", "nTrkSolidConeDR04: All Ecal", 20, 0., 20);
0175 h_nTrkSolidConeDR04_[0][1] = iBooker.book1D(histname + "Barrel_miniAOD", "nTrkSolidConeDR04: Barrel ", 20, 0., 20);
0176 h_nTrkSolidConeDR04_[0][2] = iBooker.book1D(histname + "Endcap_miniAOD", "nTrkSolidConeDR04: Endcap ", 20, 0., 20);
0177
0178
0179 histname = "chargedHadIso";
0180 h_chHadIso_[0] = iBooker.book1D(histname + "All_miniAOD", "PF chargedHadIso: All Ecal", etBin, etMin, 20.);
0181 h_chHadIso_[1] = iBooker.book1D(histname + "Barrel_miniAOD", "PF chargedHadIso: Barrel", etBin, etMin, 20.);
0182 h_chHadIso_[2] = iBooker.book1D(histname + "Endcap_miniAOD", "PF chargedHadIso: Endcap", etBin, etMin, 20.);
0183 histname = "neutralHadIso";
0184 h_nHadIso_[0] = iBooker.book1D(histname + "All_miniAOD", "PF neutralHadIso: All Ecal", etBin, etMin, 20.);
0185 h_nHadIso_[1] = iBooker.book1D(histname + "Barrel_miniAOD", "PF neutralHadIso: Barrel", etBin, etMin, 20.);
0186 h_nHadIso_[2] = iBooker.book1D(histname + "Endcap_miniAOD", "PF neutralHadIso: Endcap", etBin, etMin, 20.);
0187 histname = "photonIso";
0188 h_phoIso_[0] = iBooker.book1D(histname + "All_miniAOD", "PF photonIso: All Ecal", etBin, etMin, 20.);
0189 h_phoIso_[1] = iBooker.book1D(histname + "Barrel_miniAOD", "PF photonIso: Barrel", etBin, etMin, 20.);
0190 h_phoIso_[2] = iBooker.book1D(histname + "Endcap_miniAOD", "PF photonIso: Endcap", etBin, etMin, 20.);
0191 }
0192
0193 void PhotonValidatorMiniAOD::analyze(const edm::Event &iEvent, const edm::EventSetup &) {
0194
0195 using namespace edm;
0196
0197
0198 Handle<View<pat::Photon> > photonsHandle;
0199 iEvent.getByToken(photonToken_, photonsHandle);
0200 const auto &photons = *photonsHandle;
0201
0202 Handle<reco::GenParticleCollection> genParticles;
0203 iEvent.getByToken(genpartToken_, genParticles);
0204
0205 for (reco::GenParticleCollection::const_iterator mcIter = genParticles->begin(); mcIter != genParticles->end();
0206 mcIter++) {
0207 if (!(mcIter->pdgId() == 22))
0208 continue;
0209 if (mcIter->mother() != nullptr && !(mcIter->mother()->pdgId() == 25))
0210 continue;
0211 if (fabs(mcIter->eta()) > 2.5)
0212 continue;
0213
0214
0215
0216 float mcPhi = mcIter->phi();
0217 float mcEta = mcIter->eta();
0218
0219 float mcEnergy = mcIter->energy();
0220
0221 double dR = 9999999.;
0222 float minDr = 10000.;
0223 int iMatch = -1;
0224 bool matched = false;
0225 for (size_t ipho = 0; ipho < photons.size(); ipho++) {
0226 Ptr<pat::Photon> pho = photons.ptrAt(ipho);
0227
0228 double dphi = pho->phi() - mcPhi;
0229 if (std::fabs(dphi) > CLHEP::pi) {
0230 dphi = dphi < 0 ? (CLHEP::twopi) + dphi : dphi - CLHEP::twopi;
0231 }
0232 double deta = pho->superCluster()->position().eta() - mcEta;
0233
0234 dR = sqrt(pow((deta), 2) + pow(dphi, 2));
0235 if (dR < 0.1 && dR < minDr) {
0236 minDr = dR;
0237 iMatch = ipho;
0238 }
0239 }
0240
0241 if (iMatch > -1)
0242 matched = true;
0243 if (!matched)
0244 continue;
0245
0246 Ptr<pat::Photon> matchingPho = photons.ptrAt(iMatch);
0247
0248 bool phoIsInBarrel = false;
0249 bool phoIsInEndcap = false;
0250
0251 float phoEta = matchingPho->superCluster()->position().eta();
0252 if (fabs(phoEta) < 1.479) {
0253 phoIsInBarrel = true;
0254 } else {
0255 phoIsInEndcap = true;
0256 }
0257
0258 float photonE = matchingPho->energy();
0259 float sigmaEoE = matchingPho->getCorrectedEnergyError(matchingPho->getCandidateP4type()) / matchingPho->energy();
0260 float photonEt = matchingPho->energy() / cosh(matchingPho->eta());
0261
0262
0263 float r9 = matchingPho->r9();
0264 float full5x5_r9 = matchingPho->full5x5_r9();
0265 float r1 = matchingPho->r1x5();
0266 float r2 = matchingPho->r2x5();
0267 float sieie = matchingPho->sigmaIetaIeta();
0268 float full5x5_sieie = matchingPho->full5x5_sigmaIetaIeta();
0269 float hOverE = matchingPho->hadronicOverEm();
0270 float newhOverE = matchingPho->hadTowOverEm();
0271 float ecalIso = matchingPho->ecalRecHitSumEtConeDR04();
0272 float hcalIso = matchingPho->hcalTowerSumEtConeDR04();
0273 float newhcalIso = matchingPho->hcalTowerSumEtBcConeDR04();
0274 float trkIso = matchingPho->trkSumPtSolidConeDR04();
0275 float nIsoTrk = matchingPho->nTrkSolidConeDR04();
0276
0277 float chargedHadIso = matchingPho->chargedHadronIso();
0278 float neutralHadIso = matchingPho->neutralHadronIso();
0279 float photonIso = matchingPho->photonIso();
0280
0281
0282
0283
0284 h_scEta_[0]->Fill(matchingPho->superCluster()->eta());
0285 h_scPhi_[0]->Fill(matchingPho->superCluster()->phi());
0286
0287 h_phoE_[0][0]->Fill(photonE);
0288 h_phoEt_[0][0]->Fill(photonEt);
0289
0290 h_phoERes_[0][0]->Fill(photonE / mcEnergy);
0291 h_phoSigmaEoE_[0][0]->Fill(sigmaEoE);
0292
0293 h_r9_[0][0]->Fill(r9);
0294 h_full5x5_r9_[0][0]->Fill(full5x5_r9);
0295 h_r1_[0][0]->Fill(r1);
0296 h_r2_[0][0]->Fill(r2);
0297
0298 h_sigmaIetaIeta_[0][0]->Fill(sieie);
0299 h_full5x5_sigmaIetaIeta_[0][0]->Fill(full5x5_sieie);
0300 h_hOverE_[0][0]->Fill(hOverE);
0301 h_newhOverE_[0][0]->Fill(newhOverE);
0302
0303 h_ecalRecHitSumEtConeDR04_[0][0]->Fill(ecalIso);
0304 h_hcalTowerSumEtConeDR04_[0][0]->Fill(hcalIso);
0305 h_hcalTowerBcSumEtConeDR04_[0][0]->Fill(newhcalIso);
0306 h_isoTrkSolidConeDR04_[0][0]->Fill(trkIso);
0307 h_nTrkSolidConeDR04_[0][0]->Fill(nIsoTrk);
0308
0309
0310 h_chHadIso_[0]->Fill(chargedHadIso);
0311 h_nHadIso_[0]->Fill(neutralHadIso);
0312 h_phoIso_[0]->Fill(photonIso);
0313
0314
0315 if (phoIsInBarrel) {
0316 h_phoE_[0][1]->Fill(photonE);
0317 h_phoEt_[0][1]->Fill(photonEt);
0318 h_phoERes_[0][1]->Fill(photonE / mcEnergy);
0319 h_phoSigmaEoE_[0][1]->Fill(sigmaEoE);
0320
0321 h_r9_[0][1]->Fill(r9);
0322 h_full5x5_r9_[0][1]->Fill(full5x5_r9);
0323 h_r1_[0][1]->Fill(r1);
0324 h_r2_[0][1]->Fill(r2);
0325 h_sigmaIetaIeta_[0][1]->Fill(sieie);
0326 h_full5x5_sigmaIetaIeta_[0][1]->Fill(full5x5_sieie);
0327 h_hOverE_[0][1]->Fill(hOverE);
0328 h_newhOverE_[0][1]->Fill(newhOverE);
0329 h_ecalRecHitSumEtConeDR04_[0][1]->Fill(ecalIso);
0330 h_hcalTowerSumEtConeDR04_[0][1]->Fill(hcalIso);
0331 h_hcalTowerBcSumEtConeDR04_[0][1]->Fill(newhcalIso);
0332 h_isoTrkSolidConeDR04_[0][1]->Fill(trkIso);
0333 h_nTrkSolidConeDR04_[0][1]->Fill(nIsoTrk);
0334 h_chHadIso_[1]->Fill(chargedHadIso);
0335 h_nHadIso_[1]->Fill(neutralHadIso);
0336 h_phoIso_[1]->Fill(photonIso);
0337 }
0338 if (phoIsInEndcap) {
0339 h_phoE_[0][2]->Fill(photonE);
0340 h_phoEt_[0][2]->Fill(photonEt);
0341
0342 h_phoERes_[0][2]->Fill(photonE / mcEnergy);
0343 h_phoSigmaEoE_[0][2]->Fill(sigmaEoE);
0344 h_r9_[0][2]->Fill(r9);
0345 h_full5x5_r9_[0][2]->Fill(full5x5_r9);
0346 h_r1_[0][2]->Fill(r1);
0347 h_r2_[0][2]->Fill(r2);
0348 h_sigmaIetaIeta_[0][2]->Fill(sieie);
0349 h_full5x5_sigmaIetaIeta_[0][2]->Fill(full5x5_sieie);
0350 h_hOverE_[0][2]->Fill(hOverE);
0351 h_newhOverE_[0][2]->Fill(newhOverE);
0352 h_ecalRecHitSumEtConeDR04_[0][2]->Fill(ecalIso);
0353 h_hcalTowerSumEtConeDR04_[0][2]->Fill(hcalIso);
0354 h_hcalTowerBcSumEtConeDR04_[0][2]->Fill(newhcalIso);
0355 h_isoTrkSolidConeDR04_[0][2]->Fill(trkIso);
0356 h_nTrkSolidConeDR04_[0][2]->Fill(nIsoTrk);
0357 h_chHadIso_[2]->Fill(chargedHadIso);
0358 h_nHadIso_[2]->Fill(neutralHadIso);
0359 h_phoIso_[2]->Fill(photonIso);
0360 }
0361
0362 }
0363 }