Skip to content

Commit

Permalink
workaround for unit test "testSiStripHitEfficiency"
Browse files Browse the repository at this point in the history
Suggested by @fwyzard in
#42662 (comment)
  • Loading branch information
missirol committed Aug 25, 2023
1 parent 9002a11 commit 618a999
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
24 changes: 18 additions & 6 deletions CalibTracker/SiStripHitEfficiency/plugins/HitEff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "Geometry/CommonDetUnit/interface/GeomDet.h"
#include "Geometry/CommonDetUnit/interface/GeomDetType.h"
#include "Geometry/CommonDetUnit/interface/GluedGeomDet.h"
Expand Down Expand Up @@ -81,7 +82,8 @@ HitEff::HitEff(const edm::ParameterSet& conf)
trajTrackAsso_token_(consumes<TrajTrackAssociationCollection>(conf.getParameter<edm::InputTag>("trajectories"))),
clusters_token_(
consumes<edmNew::DetSetVector<SiStripCluster> >(conf.getParameter<edm::InputTag>("siStripClusters"))),
digis_token_(consumes(conf.getParameter<edm::InputTag>("siStripDigis"))),
digisCol_token_(consumes(conf.getParameter<edm::InputTag>("siStripDigis"))),
digisVec_token_(consumes(conf.getParameter<edm::InputTag>("siStripDigis"))),
trackerEvent_token_(consumes<MeasurementTrackerEvent>(conf.getParameter<edm::InputTag>("trackerEvent"))),
topoToken_(esConsumes()),
geomToken_(esConsumes()),
Expand Down Expand Up @@ -247,9 +249,19 @@ void HitEff::analyze(const edm::Event& e, const edm::EventSetup& es) {
const MagneticField* magField_ = &es.getData(magFieldToken_);

// get the list of module IDs with FED-detected errors
edm::Handle<DetIdVector> fedErrorIds;
//e.getByLabel("siStripDigis", fedErrorIds );
e.getByToken(digis_token_, fedErrorIds);
// - In Aug-2023, the data format was changed from DetIdCollection to DetIdVector.
// - To provide some level of backward-compatibility,
// the plugin checks for both types giving preference to the new format.
// - If only the old format is available, the collection is
// converted to the new format, then used downstream.
auto const& fedErrorIdsCol_h = e.getHandle(digisCol_token_);
auto const& fedErrorIdsVec_h = e.getHandle(digisVec_token_);
if (not fedErrorIdsCol_h.isValid() and not fedErrorIdsVec_h.isValid()) {
throw cms::Exception("InvalidProductSiStripDetIdsWithFEDErrors")
<< "no valid product for SiStrip DetIds with FED errors (see parameter \"siStripDigis\"), "
"neither for new format (DetIdVector) nor old format (DetIdCollection)";
}
auto const& fedErrorIds = fedErrorIdsVec_h.isValid() ? *fedErrorIdsVec_h : fedErrorIdsCol_h->as_vector();

edm::ESHandle<MeasurementTracker> measurementTrackerHandle = es.getHandle(measurementTkToken_);

Expand Down Expand Up @@ -976,8 +988,8 @@ void HitEff::analyze(const edm::Event& e, const edm::EventSetup& es) {
}

//check for FED-detected errors and include those in SiStripQualBad
for (unsigned int ii = 0; ii < fedErrorIds->size(); ii++) {
if (iidd == (*fedErrorIds)[ii].rawId())
for (unsigned int ii = 0; ii < fedErrorIds.size(); ii++) {
if (iidd == fedErrorIds[ii].rawId())
SiStripQualBad = 1;
}

Expand Down
4 changes: 3 additions & 1 deletion CalibTracker/SiStripHitEfficiency/plugins/HitEff.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// user includes
#include "CommonTools/UtilAlgos/interface/TFileService.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/DetId/interface/DetIdCollection.h"
#include "DataFormats/DetId/interface/DetIdVector.h"
#include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementError.h"
#include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementVector.h"
Expand Down Expand Up @@ -80,7 +81,8 @@ class HitEff : public edm::one::EDAnalyzer<edm::one::SharedResources> {
const edm::EDGetTokenT<std::vector<Trajectory> > trajectories_token_;
const edm::EDGetTokenT<TrajTrackAssociationCollection> trajTrackAsso_token_;
const edm::EDGetTokenT<edmNew::DetSetVector<SiStripCluster> > clusters_token_;
const edm::EDGetTokenT<DetIdVector> digis_token_;
const edm::EDGetTokenT<DetIdCollection> digisCol_token_;
const edm::EDGetTokenT<DetIdVector> digisVec_token_;
const edm::EDGetTokenT<MeasurementTrackerEvent> trackerEvent_token_;

// ES tokens
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "DataFormats/Common/interface/DetSetVector.h"
#include "DataFormats/Common/interface/DetSetVectorNew.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/DetId/interface/DetIdCollection.h"
#include "DataFormats/DetId/interface/DetIdVector.h"
#include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementError.h"
#include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementVector.h"
Expand All @@ -41,6 +42,7 @@
#include "FWCore/ParameterSet/interface/ParameterDescription.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "Geometry/CommonDetUnit/interface/GeomDet.h"
#include "Geometry/CommonDetUnit/interface/GeomDetType.h"
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
Expand Down Expand Up @@ -92,7 +94,8 @@ class SiStripHitEfficiencyWorker : public DQMEDAnalyzer {
const edm::EDGetTokenT<std::vector<Trajectory>> trajectories_token_;
const edm::EDGetTokenT<TrajTrackAssociationCollection> trajTrackAsso_token_;
const edm::EDGetTokenT<edmNew::DetSetVector<SiStripCluster>> clusters_token_;
const edm::EDGetTokenT<DetIdVector> digis_token_;
const edm::EDGetTokenT<DetIdCollection> digisCol_token_;
const edm::EDGetTokenT<DetIdVector> digisVec_token_;
const edm::EDGetTokenT<MeasurementTrackerEvent> trackerEvent_token_;

// event setup tokens
Expand Down Expand Up @@ -202,7 +205,8 @@ SiStripHitEfficiencyWorker::SiStripHitEfficiencyWorker(const edm::ParameterSet&
trajTrackAsso_token_(consumes<TrajTrackAssociationCollection>(conf.getParameter<edm::InputTag>("trajectories"))),
clusters_token_(
consumes<edmNew::DetSetVector<SiStripCluster>>(conf.getParameter<edm::InputTag>("siStripClusters"))),
digis_token_(consumes(conf.getParameter<edm::InputTag>("siStripDigis"))),
digisCol_token_(consumes(conf.getParameter<edm::InputTag>("siStripDigis"))),
digisVec_token_(consumes(conf.getParameter<edm::InputTag>("siStripDigis"))),
trackerEvent_token_(consumes<MeasurementTrackerEvent>(conf.getParameter<edm::InputTag>("trackerEvent"))),
tTopoToken_(esConsumes()),
tkGeomToken_(esConsumes()),
Expand Down Expand Up @@ -445,11 +449,23 @@ void SiStripHitEfficiencyWorker::analyze(const edm::Event& e, const edm::EventSe
edm::Handle<edmNew::DetSetVector<SiStripCluster>> theClusters;
e.getByToken(clusters_token_, theClusters);

edm::Handle<DetIdVector> fedErrorIds;
e.getByToken(digis_token_, fedErrorIds);
// get the list of module IDs with FED-detected errors
// - In Aug-2023, the data format was changed from DetIdCollection to DetIdVector.
// - To provide some level of backward-compatibility,
// the plugin checks for both types giving preference to the new format.
// - If only the old format is available, the collection is
// converted to the new format, then used downstream.
auto const& fedErrorIdsCol_h = e.getHandle(digisCol_token_);
auto const& fedErrorIdsVec_h = e.getHandle(digisVec_token_);
if (not fedErrorIdsCol_h.isValid() and not fedErrorIdsVec_h.isValid()) {
throw cms::Exception("InvalidProductSiStripDetIdsWithFEDErrors")
<< "no valid product for SiStrip DetIds with FED errors (see parameter \"siStripDigis\"), "
"neither for new format (DetIdVector) nor old format (DetIdCollection)";
}
auto const& fedErrorIds = fedErrorIdsVec_h.isValid() ? *fedErrorIdsVec_h : fedErrorIdsCol_h->as_vector();

// fill the calibData with the FEDErrors
for (const auto& fedErr : *fedErrorIds) {
for (const auto& fedErr : fedErrorIds) {
// fill the TkHistoMap occupancy map
calibData_.FEDErrorOccupancy->fill(fedErr.rawId(), 1.);

Expand Down Expand Up @@ -826,7 +842,7 @@ void SiStripHitEfficiencyWorker::analyze(const edm::Event& e, const edm::EventSe
tkgeom,
stripcpe,
stripQuality,
*fedErrorIds,
fedErrorIds,
commonModeDigis,
*theClusters,
e.bunchCrossing(),
Expand Down

0 comments on commit 618a999

Please sign in to comment.