From 199548dfdc867040529a6e9364abdaf9d743801a Mon Sep 17 00:00:00 2001 From: mmusich Date: Mon, 24 Jun 2024 15:43:33 +0200 Subject: [PATCH] DQM/TrackingMonitorSource: add missing fillDescription parameters and put early returns in case of missing input data in various plugins --- .../plugins/StandaloneTrackMonitor.cc | 19 +++++++++------ .../plugins/TrackMultiplicityFilter.cc | 7 ++++++ .../plugins/TtbarTrackProducer.cc | 23 +++++++++++-------- .../plugins/V0EventSelector.cc | 7 +++++- .../plugins/ZEEDetails.cc | 11 +++++---- 5 files changed, 44 insertions(+), 23 deletions(-) diff --git a/DQM/TrackingMonitorSource/plugins/StandaloneTrackMonitor.cc b/DQM/TrackingMonitorSource/plugins/StandaloneTrackMonitor.cc index 06fce1e2b4878..5aa881e1a0a6a 100644 --- a/DQM/TrackingMonitorSource/plugins/StandaloneTrackMonitor.cc +++ b/DQM/TrackingMonitorSource/plugins/StandaloneTrackMonitor.cc @@ -387,11 +387,11 @@ void StandaloneTrackMonitor::fillDescriptions(edm::ConfigurationDescriptions& de desc.addUntracked("haveAllHistograms", false); desc.addUntracked("puScaleFactorFile", "PileupScaleFactor.root"); desc.addUntracked("trackScaleFactorFile", "PileupScaleFactor.root"); - desc.addUntracked >("MVAProducers"); - desc.addUntracked("TrackProducerForMVA"); + desc.addUntracked >("MVAProducers", {"initialStepClassifier1", "initialStepClassifier2"}); + desc.addUntracked("TrackProducerForMVA", edm::InputTag("initialStepTracks")); - desc.addUntracked("TCProducer"); - desc.addUntracked("AlgoName"); + desc.addUntracked("TCProducer", edm::InputTag("initialStepTrackCandidates")); + desc.addUntracked("AlgoName", "GenTk"); desc.addUntracked("verbose", false); { @@ -1315,7 +1315,8 @@ void StandaloneTrackMonitor::analyze(edm::Event const& iEvent, edm::EventSetup c edm::Handle vertexColl; iEvent.getByToken(vertexToken_, vertexColl); if (!vertexColl.isValid()) { - edm::LogError("DqmTrackStudy") << "Error! Failed to get reco::Vertex Collection, " << vertexTag_; + edm::LogError("StandaloneTrackMonitor") << "Error! Failed to get reco::Vertex Collection, " << vertexTag_; + return; } if (vertexColl->empty()) { edm::LogError("StandalonaTrackMonitor") << "No good vertex in the event!!" << std::endl; @@ -1326,14 +1327,18 @@ void StandaloneTrackMonitor::analyze(edm::Event const& iEvent, edm::EventSetup c // Beam spot edm::Handle beamSpot; iEvent.getByToken(bsToken_, beamSpot); - if (!beamSpot.isValid()) + if (!beamSpot.isValid()) { edm::LogError("StandalonaTrackMonitor") << "Beamspot for input tag: " << bsTag_ << " not found!!"; + return; + } // Track collection edm::Handle tracks; iEvent.getByToken(trackToken_, tracks); - if (!tracks.isValid()) + if (!tracks.isValid()) { edm::LogError("StandalonaTrackMonitor") << "TrackCollection for input tag: " << trackTag_ << " not found!!"; + return; + } // Access PU information double wfac = 1.0; // for data diff --git a/DQM/TrackingMonitorSource/plugins/TrackMultiplicityFilter.cc b/DQM/TrackingMonitorSource/plugins/TrackMultiplicityFilter.cc index b926c7d28ccbf..06db5138f7e76 100644 --- a/DQM/TrackingMonitorSource/plugins/TrackMultiplicityFilter.cc +++ b/DQM/TrackingMonitorSource/plugins/TrackMultiplicityFilter.cc @@ -62,6 +62,13 @@ bool TrackMultiplicityFilter::filter(edm::StreamID iStream, edm::Event& iEvent, bool pass = false; edm::Handle tracks; iEvent.getByToken(tracksToken_, tracks); + + if (!tracks.isValid()) { + edm::LogError("TrackMultiplicityFilter") + << "Error >> Failed to get TrackMultiplicityFilter for label: " << tracksTag_; + return false; + } + double count = std::count_if(tracks->begin(), tracks->end(), selector_); pass = (count >= nmin_); diff --git a/DQM/TrackingMonitorSource/plugins/TtbarTrackProducer.cc b/DQM/TrackingMonitorSource/plugins/TtbarTrackProducer.cc index bd2537ae060e2..5ba1c38b15087 100644 --- a/DQM/TrackingMonitorSource/plugins/TtbarTrackProducer.cc +++ b/DQM/TrackingMonitorSource/plugins/TtbarTrackProducer.cc @@ -250,16 +250,19 @@ void TtbarTrackProducer::produce(edm::StreamID streamID, edm::Event& iEvent, edm edm::Handle bTagHandle; iEvent.getByToken(bjetsToken_, bTagHandle); - const reco::JetTagCollection& bTags = *(bTagHandle.product()); - std::vector list_bjets; - - if (!bTags.empty()) { - for (unsigned bj = 0; bj != bTags.size(); ++bj) { - TLorentzVector lv_bjets; - lv_bjets.SetPtEtaPhiE( - bTags[bj].first->pt(), bTags[bj].first->eta(), bTags[bj].first->phi(), bTags[bj].first->energy()); - if (bTags[bj].second > btagFactor_) - list_bjets.push_back(lv_bjets); + + if (bTagHandle.isValid()) { + const reco::JetTagCollection& bTags = *(bTagHandle.product()); + std::vector list_bjets; + + if (!bTags.empty()) { + for (unsigned bj = 0; bj != bTags.size(); ++bj) { + TLorentzVector lv_bjets; + lv_bjets.SetPtEtaPhiE( + bTags[bj].first->pt(), bTags[bj].first->eta(), bTags[bj].first->phi(), bTags[bj].first->energy()); + if (bTags[bj].second > btagFactor_) + list_bjets.push_back(lv_bjets); + } } } diff --git a/DQM/TrackingMonitorSource/plugins/V0EventSelector.cc b/DQM/TrackingMonitorSource/plugins/V0EventSelector.cc index 7acf591543980..77b92bf26a138 100644 --- a/DQM/TrackingMonitorSource/plugins/V0EventSelector.cc +++ b/DQM/TrackingMonitorSource/plugins/V0EventSelector.cc @@ -37,9 +37,14 @@ V0EventSelector::V0EventSelector(const edm::ParameterSet& iConfig) bool V0EventSelector::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) { edm::Handle vccHandle; iEvent.getByToken(vccToken_, vccHandle); - auto filteredVCC = std::make_unique(); + // early return if the input collection is empty + if (!vccHandle.isValid()) { + iEvent.put(std::move(filteredVCC)); + return false; + } + for (const auto& vcc : *vccHandle) { if (vcc.mass() >= massMin_ && vcc.mass() <= massMax_) { filteredVCC->push_back(vcc); diff --git a/DQM/TrackingMonitorSource/plugins/ZEEDetails.cc b/DQM/TrackingMonitorSource/plugins/ZEEDetails.cc index 8719d7d25bcd8..bad73a4841249 100644 --- a/DQM/TrackingMonitorSource/plugins/ZEEDetails.cc +++ b/DQM/TrackingMonitorSource/plugins/ZEEDetails.cc @@ -230,7 +230,7 @@ void ZEEDetails::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup if (beamSpot.isValid()) { trkd0 = -(trk->dxy(beamSpot->position())); } else { - edm::LogError("ElectronTrackProducer") << "Error >> Failed to get BeamSpot for label: " << bsTag_; + edm::LogError("ZEEDetails") << "Error >> Failed to get BeamSpot for label: " << bsTag_; } if (std::fabs(trkd0) >= maxD0_) continue; @@ -261,16 +261,17 @@ void ZEEDetails::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup finalelectrons.push_back(ele); } } else { - edm::LogError("ElectronTrackProducer") << "Error >> Failed to get ElectronCollection for label: " << electronTag_; + edm::LogError("ZEEDetails") << "Error >> Failed to get ElectronCollection for label: " << electronTag_; } edm::Handle vertexColl; iEvent.getByToken(vertexToken_, vertexColl); if (!vertexColl.isValid()) { - edm::LogError("DqmTrackStudy") << "Error! Failed to get reco::Vertex Collection, " << vertexTag_; + edm::LogError("ZEEDetails") << "Error! Failed to get reco::Vertex Collection, " << vertexTag_; + return; } if (vertexColl->empty()) { - edm::LogError("DqmTrackStudy") << "No good vertex in the event!!"; + edm::LogError("ZEEDetails") << "No good vertex in the event!!"; return; } @@ -294,7 +295,7 @@ void ZEEDetails::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup } } } else - edm::LogError("DqmTrackStudy") << "PUSummary for input tag: " << puSummaryTag_ << " not found!!"; + edm::LogError("ZEEDetails") << "PUSummary for input tag: " << puSummaryTag_ << " not found!!"; } for (unsigned int I = 0; I != finalelectrons.size(); I++) {