Skip to content

Commit

Permalink
DQM/TrackingMonitorSource: add missing fillDescription parameters and…
Browse files Browse the repository at this point in the history
… put early returns in case of missing input data in various plugins
  • Loading branch information
mmusich committed Oct 1, 2024
1 parent 41e92bb commit 199548d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 23 deletions.
19 changes: 12 additions & 7 deletions DQM/TrackingMonitorSource/plugins/StandaloneTrackMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,11 @@ void StandaloneTrackMonitor::fillDescriptions(edm::ConfigurationDescriptions& de
desc.addUntracked<bool>("haveAllHistograms", false);
desc.addUntracked<std::string>("puScaleFactorFile", "PileupScaleFactor.root");
desc.addUntracked<std::string>("trackScaleFactorFile", "PileupScaleFactor.root");
desc.addUntracked<std::vector<std::string> >("MVAProducers");
desc.addUntracked<edm::InputTag>("TrackProducerForMVA");
desc.addUntracked<std::vector<std::string> >("MVAProducers", {"initialStepClassifier1", "initialStepClassifier2"});
desc.addUntracked<edm::InputTag>("TrackProducerForMVA", edm::InputTag("initialStepTracks"));

desc.addUntracked<edm::InputTag>("TCProducer");
desc.addUntracked<std::string>("AlgoName");
desc.addUntracked<edm::InputTag>("TCProducer", edm::InputTag("initialStepTrackCandidates"));
desc.addUntracked<std::string>("AlgoName", "GenTk");
desc.addUntracked<bool>("verbose", false);

{
Expand Down Expand Up @@ -1315,7 +1315,8 @@ void StandaloneTrackMonitor::analyze(edm::Event const& iEvent, edm::EventSetup c
edm::Handle<reco::VertexCollection> 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;
Expand All @@ -1326,14 +1327,18 @@ void StandaloneTrackMonitor::analyze(edm::Event const& iEvent, edm::EventSetup c
// Beam spot
edm::Handle<reco::BeamSpot> 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<reco::TrackCollection> 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
Expand Down
7 changes: 7 additions & 0 deletions DQM/TrackingMonitorSource/plugins/TrackMultiplicityFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ bool TrackMultiplicityFilter::filter(edm::StreamID iStream, edm::Event& iEvent,
bool pass = false;
edm::Handle<reco::TrackCollection> 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_);

Expand Down
23 changes: 13 additions & 10 deletions DQM/TrackingMonitorSource/plugins/TtbarTrackProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,19 @@ void TtbarTrackProducer::produce(edm::StreamID streamID, edm::Event& iEvent, edm

edm::Handle<reco::JetTagCollection> bTagHandle;
iEvent.getByToken(bjetsToken_, bTagHandle);
const reco::JetTagCollection& bTags = *(bTagHandle.product());
std::vector<TLorentzVector> 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<TLorentzVector> 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);
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion DQM/TrackingMonitorSource/plugins/V0EventSelector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ V0EventSelector::V0EventSelector(const edm::ParameterSet& iConfig)
bool V0EventSelector::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
edm::Handle<reco::VertexCompositeCandidateCollection> vccHandle;
iEvent.getByToken(vccToken_, vccHandle);

auto filteredVCC = std::make_unique<reco::VertexCompositeCandidateCollection>();

// 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);
Expand Down
11 changes: 6 additions & 5 deletions DQM/TrackingMonitorSource/plugins/ZEEDetails.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<reco::VertexCollection> 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;
}

Expand All @@ -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++) {
Expand Down

0 comments on commit 199548d

Please sign in to comment.