From 6c3e39dfa184d870de6b04eb426eec809731eb4c Mon Sep 17 00:00:00 2001 From: Sunanda Date: Tue, 8 Feb 2022 17:15:09 +0100 Subject: [PATCH] To make the response study work without HLT information if needed --- .../plugins/StudyCaloResponse.cc | 47 ++++++++++++------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/Calibration/IsolatedParticles/plugins/StudyCaloResponse.cc b/Calibration/IsolatedParticles/plugins/StudyCaloResponse.cc index f64b062aac50f..99310bc872d06 100644 --- a/Calibration/IsolatedParticles/plugins/StudyCaloResponse.cc +++ b/Calibration/IsolatedParticles/plugins/StudyCaloResponse.cc @@ -328,7 +328,11 @@ void StudyCaloResponse::analyze(edm::Event const& iEvent, edm::EventSetup const& bool ok(false); std::string triggerUse("None"); if (!triggerEventHandle.isValid()) { - edm::LogWarning("IsoTrack") << "Error! Can't get the product " << triggerEvent_.label(); + if (trigNames_.empty()) { + ok = true; + } else { + edm::LogWarning("IsoTrack") << "Error! Can't get the product " << triggerEvent_.label(); + } } else { triggerEvent = *(triggerEventHandle.product()); @@ -407,6 +411,17 @@ void StudyCaloResponse::analyze(edm::Event const& iEvent, edm::EventSetup const& edm::LogVerbatim("IsoTrack") << "Trigger check gives " << ok << " with " << triggerUse; //Look at the tracks + edm::Handle trkCollection; + iEvent.getByToken(tok_genTrack_, trkCollection); + + edm::Handle muonEventHandle; + iEvent.getByToken(tok_Muon_, muonEventHandle); + + if ((!trkCollection.isValid()) || (!muonEventHandle.isValid())) { + edm::LogError("IsoTrack") << "Track collection " << trkCollection.isValid() << " Muon collection " << muonEventHandle.isValid(); + ok = false; + } + if (ok) { h_goodRun->Fill(RunNo); tr_goodRun = RunNo; @@ -419,16 +434,20 @@ void StudyCaloResponse::analyze(edm::Event const& iEvent, edm::EventSetup const& edm::Handle recVtxs; iEvent.getByToken(tok_recVtx_, recVtxs); - int ntrk(0), ngoodPV(0), nPV(-1); - int nvtxs = (int)(recVtxs->size()); - for (int ind = 0; ind < nvtxs; ind++) { - if (!((*recVtxs)[ind].isFake()) && (*recVtxs)[ind].ndof() > 4) - ngoodPV++; - } - for (int i = 0; i < nPVBin_; ++i) { - if (ngoodPV >= pvBin_[i] && ngoodPV < pvBin_[i + 1]) { - nPV = i; - break; + int ntrk(0), ngoodPV(0), nPV(-1), nvtxs(0); + if (!recVtxs.isValid()) { + edm::LogWarning("IsoTrack") << "Cannot find the vertex collection"; + } else { + nvtxs = (int)(recVtxs->size()); + for (int ind = 0; ind < nvtxs; ind++) { + if (!((*recVtxs)[ind].isFake()) && (*recVtxs)[ind].ndof() > 4) + ngoodPV++; + } + for (int i = 0; i < nPVBin_; ++i) { + if (ngoodPV >= pvBin_[i] && ngoodPV < pvBin_[i + 1]) { + nPV = i; + break; + } } } @@ -453,12 +472,6 @@ void StudyCaloResponse::analyze(edm::Event const& iEvent, edm::EventSetup const& tr_eventWeight = 0; } - edm::Handle trkCollection; - iEvent.getByToken(tok_genTrack_, trkCollection); - - edm::Handle muonEventHandle; - iEvent.getByToken(tok_Muon_, muonEventHandle); - //=== genParticle information edm::Handle genParticles; iEvent.getByToken(tok_parts_, genParticles);