Skip to content

Commit

Permalink
modernize Alignment/OfflineValidation: remove legacy EDModules types,…
Browse files Browse the repository at this point in the history
… move to getting data from EventSetup (with token) and remove other static analyzer warnings
  • Loading branch information
mmusich committed Nov 3, 2020
1 parent 6b7cf86 commit 27d076d
Show file tree
Hide file tree
Showing 17 changed files with 180 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@
#include "DataFormats/TrackReco/interface/TrackFwd.h"

#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/MakerMacros.h"
Expand All @@ -58,7 +57,7 @@
// class decleration
//

class CosmicSplitterValidation : public edm::EDAnalyzer {
class CosmicSplitterValidation : public edm::one::EDAnalyzer<edm::one::SharedResources> {
public:
explicit CosmicSplitterValidation(const edm::ParameterSet&);
~CosmicSplitterValidation() override;
Expand Down Expand Up @@ -414,6 +413,7 @@ CosmicSplitterValidation::CosmicSplitterValidation(const edm::ParameterSet& iCon
phiErr_orm_(0),
ptErr_orm_(0),
qoverptErr_orm_(0) {
usesResource(TFileService::kSharedResource);
edm::ConsumesCollector&& iC = consumesCollector();
splitTracksToken_ = iC.consumes<std::vector<reco::Track>>(splitTracks_);
originalTracksToken_ = iC.consumes<std::vector<reco::Track>>(originalTracks_);
Expand Down
29 changes: 12 additions & 17 deletions Alignment/OfflineValidation/plugins/DMRChecker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -494,11 +494,10 @@ class DMRChecker : public edm::one::EDAnalyzer<edm::one::SharedResources> {
event.getByToken(theTrackCollectionToken, trackCollection);

// magnetic field setup
edm::ESHandle<MagneticField> magneticField_ = setup.getHandle(magFieldToken_);
float B_ = magneticField_.product()->inTesla(GlobalPoint(0, 0, 0)).mag();
const MagneticField *magneticField_ = &setup.getData(magFieldToken_);
float B_ = magneticField_->inTesla(GlobalPoint(0, 0, 0)).mag();

edm::ESHandle<RunInfo> runInfo = setup.getHandle(runInfoToken_);
const RunInfo *summary = runInfo.product();
const RunInfo *summary = &setup.getData(runInfoToken_);
time_t start_time = summary->m_start_time_ll;
ctime(&start_time);
time_t end_time = summary->m_stop_time_ll;
Expand All @@ -511,15 +510,14 @@ class DMRChecker : public edm::one::EDAnalyzer<edm::one::SharedResources> {
<< " end_time " << end_time << "( " << summary->m_stop_time_str <<" )" << std::endl;
*/

double seconds = difftime(end_time, start_time) / 1.0e+6;
double seconds = difftime(end_time, start_time) / 1.0e+6; // convert from micros-seconds
//edm::LogVerbatim("DMRChecker")<<" diff: "<< seconds << "s" << std::endl;
timeMap_[event.run()] = seconds;

// topology setup
edm::ESHandle<TrackerTopology> tTopoHandle = setup.getHandle(topoToken_);
const TrackerTopology *const tTopo = tTopoHandle.product();
const TrackerTopology *const tTopo = &setup.getData(topoToken_);

edm::ESHandle<SiStripLatency> apvlat = setup.getHandle(latencyToken_);
const SiStripLatency *apvlat = &setup.getData(latencyToken_);
if (apvlat->singleReadOutMode() == 1) {
mode = 1; // peak mode
} else if (apvlat->singleReadOutMode() == 0) {
Expand All @@ -530,8 +528,7 @@ class DMRChecker : public edm::one::EDAnalyzer<edm::one::SharedResources> {
conditionsMap_[event.run()].second = B_;

// geometry setup
edm::ESHandle<TrackerGeometry> geometry = setup.getHandle(geomToken_);
const TrackerGeometry *theGeometry = &(*geometry);
const TrackerGeometry *theGeometry = &setup.getData(geomToken_);

if (firstEvent_) {
if (theGeometry->isThere(GeomDetEnumerators::P2PXB) || theGeometry->isThere(GeomDetEnumerators::P2PXEC)) {
Expand Down Expand Up @@ -620,7 +617,7 @@ class DMRChecker : public edm::one::EDAnalyzer<edm::one::SharedResources> {
// fill DMRs and DrNRs
if (subid == StripSubdetector::TIB) {
uOrientation = deltaPhi(gUDirection.barePhi(), gPModule.barePhi()) >= 0. ? +1.F : -1.F;
vOrientation = gVDirection.z() - gPModule.z() >= 0 ? +1.F : -1.F;
//vOrientation = gVDirection.z() - gPModule.z() >= 0 ? +1.F : -1.F; // not used for Strips

// if the detid has never occcurred yet, set the local orientations
if (resDetailsTIB_.find(detid_db) == resDetailsTIB_.end()) {
Expand All @@ -637,7 +634,7 @@ class DMRChecker : public edm::one::EDAnalyzer<edm::one::SharedResources> {

} else if (subid == StripSubdetector::TOB) {
uOrientation = deltaPhi(gUDirection.barePhi(), gPModule.barePhi()) >= 0. ? +1.F : -1.F;
vOrientation = gVDirection.z() - gPModule.z() >= 0 ? +1.F : -1.F;
//vOrientation = gVDirection.z() - gPModule.z() >= 0 ? +1.F : -1.F; // not used for Strips

hTOBResXPrime->Fill(uOrientation * resX * 10000);
hTOBResXPull->Fill(pullX);
Expand All @@ -654,7 +651,7 @@ class DMRChecker : public edm::one::EDAnalyzer<edm::one::SharedResources> {

} else if (subid == StripSubdetector::TID) {
uOrientation = deltaPhi(gUDirection.barePhi(), gPModule.barePhi()) >= 0. ? +1.F : -1.F;
vOrientation = gVDirection.perp() - gPModule.perp() >= 0. ? +1.F : -1.F;
//vOrientation = gVDirection.perp() - gPModule.perp() >= 0. ? +1.F : -1.F; // not used for Strips

hTIDResXPrime->Fill(uOrientation * resX * 10000);
hTIDResXPull->Fill(pullX);
Expand All @@ -664,7 +661,7 @@ class DMRChecker : public edm::one::EDAnalyzer<edm::one::SharedResources> {

} else if (subid == StripSubdetector::TEC) {
uOrientation = deltaPhi(gUDirection.barePhi(), gPModule.barePhi()) >= 0. ? +1.F : -1.F;
vOrientation = gVDirection.perp() - gPModule.perp() >= 0. ? +1.F : -1.F;
//vOrientation = gVDirection.perp() - gPModule.perp() >= 0. ? +1.F : -1.F; // not used for Strips

hTECResXPrime->Fill(uOrientation * resX * 10000);
hTECResXPull->Fill(pullX);
Expand Down Expand Up @@ -1874,11 +1871,9 @@ class DMRChecker : public edm::one::EDAnalyzer<edm::one::SharedResources> {
}

unsigned int side = -1;
unsigned int plane = i;

if (detType.find("FPix") != std::string::npos) {
side = (i - 1) / 3 + 1;
plane = (i - 1) % 3 + 1;
unsigned int plane = (i - 1) % 3 + 1;

std::string theSide = "";
if (side == 1) {
Expand Down
6 changes: 3 additions & 3 deletions Alignment/OfflineValidation/plugins/EopTreeWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@

// framework include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

Expand Down Expand Up @@ -65,7 +64,7 @@
// class decleration
//

class EopTreeWriter : public edm::EDAnalyzer {
class EopTreeWriter : public edm::one::EDAnalyzer<edm::one::SharedResources> {
public:
explicit EopTreeWriter(const edm::ParameterSet&);
~EopTreeWriter() override;
Expand Down Expand Up @@ -101,6 +100,7 @@ class EopTreeWriter : public edm::EDAnalyzer {
//
EopTreeWriter::EopTreeWriter(const edm::ParameterSet& iConfig)
: src_(iConfig.getParameter<edm::InputTag>("src")), geometryToken_(esConsumes()) {
usesResource(TFileService::kSharedResource);
//now do what ever initialization is needed

// TrackAssociator parameters
Expand Down
23 changes: 10 additions & 13 deletions Alignment/OfflineValidation/plugins/MuonAlignmentAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/Event.h"

#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
#include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
#include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
#include "Geometry/CommonDetUnit/interface/GeomDet.h"
#include "DataFormats/DetId/interface/DetId.h"
#include "DataFormats/MuonDetId/interface/DTChamberId.h"
Expand Down Expand Up @@ -47,7 +44,9 @@

/// Constructor
MuonAlignmentAnalyzer::MuonAlignmentAnalyzer(const edm::ParameterSet &pset)
: hGBNmuons(nullptr),
: magFieldToken_(esConsumes()),
trackingGeometryToken_(esConsumes()),
hGBNmuons(nullptr),
hSANmuons(nullptr),
hSimNmuons(nullptr),
hGBNmuons_Barrel(nullptr),
Expand Down Expand Up @@ -194,6 +193,8 @@ MuonAlignmentAnalyzer::MuonAlignmentAnalyzer(const edm::ParameterSet &pset)
hprofGlobalPhiCSC(nullptr),
hprofGlobalThetaCSC(nullptr),
hprofGlobalRCSC(nullptr) {
usesResource(TFileService::kSharedResource);

theSTAMuonTag = pset.getParameter<edm::InputTag>("StandAloneTrackCollectionTag");
theGLBMuonTag = pset.getParameter<edm::InputTag>("GlobalMuonTrackCollectionTag");

Expand Down Expand Up @@ -1992,11 +1993,8 @@ void MuonAlignmentAnalyzer::analyze(const edm::Event &event, const edm::EventSet
// ############ Residual plots ###################

if (doResplots) {
edm::ESHandle<MagneticField> theMGField;
eventSetup.get<IdealMagneticFieldRecord>().get(theMGField);

edm::ESHandle<GlobalTrackingGeometry> theTrackingGeometry;
eventSetup.get<GlobalTrackingGeometryRecord>().get(theTrackingGeometry);
const MagneticField *theMGField = &eventSetup.getData(magFieldToken_);
edm::ESHandle<GlobalTrackingGeometry> theTrackingGeometry = eventSetup.getHandle(trackingGeometryToken_);

// Get the RecTrack collection from the event
edm::Handle<reco::TrackCollection> staTracks;
Expand Down Expand Up @@ -2029,13 +2027,13 @@ void MuonAlignmentAnalyzer::analyze(const edm::Event &event, const edm::EventSet
std::cout << "<MuonAlignmentAnalyzer>" << geomDet->toGlobal((*segmentCSC).localPosition()) << std::endl;
}
*/
thePropagator = new SteppingHelixPropagator(&*theMGField, alongMomentum);
thePropagator = new SteppingHelixPropagator(theMGField, alongMomentum);

reco::TrackCollection::const_iterator staTrack;
for (staTrack = staTracks->begin(); staTrack != staTracks->end(); ++staTrack) {
int countPoints = 0;

reco::TransientTrack track(*staTrack, &*theMGField, theTrackingGeometry);
reco::TransientTrack track(*staTrack, theMGField, theTrackingGeometry);

if (staTrack->numberOfValidHits() > (min1DTrackRecHitSize - 1)) {
RecHitVector my4DTrack = this->doMatching(
Expand Down Expand Up @@ -2246,8 +2244,7 @@ void MuonAlignmentAnalyzer::analyze(const edm::Event &event, const edm::EventSet
} else {
residualGlobalRPhi = 0, residualGlobalPhi = 0, residualGlobalR = 0, residualGlobalTheta = 0,
residualGlobalZ = 0;
residualLocalX = 0, residualLocalPhi = 0, residualLocalY = 0, residualLocalTheta = 0,
residualLocalY = 0;
residualLocalX = 0, residualLocalPhi = 0, residualLocalY = 0, residualLocalTheta = 0;
}
// Fill individual chamber histograms
if (newDetector) {
Expand Down
21 changes: 13 additions & 8 deletions Alignment/OfflineValidation/plugins/MuonAlignmentAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@
*/

// Base Class Headers
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "CommonTools/UtilAlgos/interface/TFileService.h"
#include "DataFormats/CSCRecHit/interface/CSCSegmentCollection.h"
#include "DataFormats/DTRecHit/interface/DTRecSegment4DCollection.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "TrackingTools/GeomPropagators/interface/Propagator.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/DTRecHit/interface/DTRecSegment4DCollection.h"
#include "DataFormats/CSCRecHit/interface/CSCSegmentCollection.h"
#include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
#include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
#include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
#include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
#include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
#include "TrackingTools/GeomPropagators/interface/Propagator.h"
#include <vector>

namespace edm {
Expand All @@ -37,7 +40,7 @@ class TH2F;
typedef std::vector<std::vector<int> > intDVector;
typedef std::vector<TrackingRecHit *> RecHitVector;

class MuonAlignmentAnalyzer : public edm::EDAnalyzer {
class MuonAlignmentAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
public:
/// Constructor
MuonAlignmentAnalyzer(const edm::ParameterSet &pset);
Expand All @@ -54,6 +57,8 @@ class MuonAlignmentAnalyzer : public edm::EDAnalyzer {

protected:
private:
const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magFieldToken_;
const edm::ESGetToken<GlobalTrackingGeometry, GlobalTrackingGeometryRecord> trackingGeometryToken_;
RecHitVector doMatching(const reco::Track &,
edm::Handle<DTRecSegment4DCollection> &,
edm::Handle<CSCSegmentCollection> &,
Expand Down
26 changes: 14 additions & 12 deletions Alignment/OfflineValidation/plugins/OverlapValidation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Utilities/interface/ESGetToken.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
Expand Down Expand Up @@ -101,6 +102,11 @@ class OverlapValidation : public edm::one::EDAnalyzer<> {
int layerFromId(const DetId&, const TrackerTopology* const tTopo) const;

// ----------member data ---------------------------

const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomToken_;
const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magFieldToken_;
const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoToken_;

edm::ParameterSet config_;
edm::InputTag trajectoryTag_;
SiStripDetInfoFileReader* reader;
Expand Down Expand Up @@ -180,7 +186,10 @@ using std::vector;
// constructors and destructor
//
OverlapValidation::OverlapValidation(const edm::ParameterSet& iConfig)
: config_(iConfig),
: geomToken_(esConsumes()),
magFieldToken_(esConsumes()),
topoToken_(esConsumes()),
config_(iConfig),
rootTree_(nullptr),
FileInPath_("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"),
addExtraBranches_(false),
Expand Down Expand Up @@ -277,20 +286,15 @@ void OverlapValidation::analyze(const edm::Event& iEvent, const edm::EventSetup&
//
// mag field & search tracker
//
edm::ESHandle<MagneticField> magFieldHandle;
iSetup.get<IdealMagneticFieldRecord>().get(magFieldHandle);
magField_ = magFieldHandle.product();
const MagneticField* magField_ = &iSetup.getData(magFieldToken_);
//
// propagator
//
AnalyticalPropagator propagator(magField_, anyDirection);
//
// geometry

//
edm::ESHandle<TrackerGeometry> geometryHandle;
iSetup.get<TrackerDigiGeometryRecord>().get(geometryHandle);
trackerGeometry_ = geometryHandle.product();
trackerGeometry_ = &iSetup.getData(geomToken_);
//
// make associator for SimHits
//
Expand All @@ -314,9 +318,7 @@ void OverlapValidation::analyze(const edm::Event& iEvent, const edm::EventSetup&

//
// loop over trajectories from refit
edm::ESHandle<TrackerTopology> tTopoHandle;
iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
const TrackerTopology* const tTopo = tTopoHandle.product();
const TrackerTopology* const tTopo = &iSetup.getData(topoToken_);
for (const auto& trajectory : *trajectoryCollection)
analyze(trajectory, propagator, *associator, tTopo);

Expand Down
21 changes: 9 additions & 12 deletions Alignment/OfflineValidation/plugins/ResidualRefitting.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@
#include "TrackingTools/Records/interface/TrackingComponentsRecord.h"

ResidualRefitting::ResidualRefitting(const edm::ParameterSet& cfg)
: outputFileName_(cfg.getUntrackedParameter<std::string>("histoutputFile")),
PropagatorSource_(cfg.getParameter<std::string>("propagator")),
: magFieldToken_(esConsumes()),
topoToken_(esConsumes()),
trackingGeometryToken_(esConsumes()),
propagatorToken_(esConsumes(edm::ESInputTag(cfg.getParameter<std::string>("propagator")))),
outputFileName_(cfg.getUntrackedParameter<std::string>("histoutputFile")),
muons_(cfg.getParameter<edm::InputTag>("muons")),
muonsRemake_(cfg.getParameter<edm::InputTag>("muonsRemake")), //This Feels Misalignment
muonsNoStation1_(cfg.getParameter<edm::InputTag>("muonsNoStation1")),
Expand Down Expand Up @@ -138,13 +141,9 @@ void ResidualRefitting::analyze(const edm::Event& event, const edm::EventSetup&
event.getByLabel(muonsNoTOBLayer6_, muonsNoTOBLayer6Coll);
*/
//magnetic field information
edm::ESHandle<MagneticField> field;
edm::ESHandle<GlobalTrackingGeometry> globalTrackingGeometry;
eventSetup.get<IdealMagneticFieldRecord>().get(field);
eventSetup.get<GlobalTrackingGeometryRecord>().get(globalTrackingGeometry);
eventSetup.get<TrackingComponentsRecord>().get(PropagatorSource_, thePropagator);
theField = &*field;

theField = &eventSetup.getData(magFieldToken_);
edm::ESHandle<GlobalTrackingGeometry> globalTrackingGeometry = eventSetup.getHandle(trackingGeometryToken_);
thePropagator = eventSetup.getHandle(propagatorToken_);
theService->update(eventSetup);

//Zero storage
Expand Down Expand Up @@ -269,9 +268,7 @@ void ResidualRefitting::CollectTrackHits(edm::Handle<reco::TrackCollection> trac
ResidualRefitting::storage_trackExtrap& trackExtrap,
const edm::EventSetup& eventSetup) {
//Retrieve tracker topology from geometry
edm::ESHandle<TrackerTopology> tTopoHandle;
eventSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
const TrackerTopology* const tTopo = tTopoHandle.product();
const TrackerTopology* const tTopo = &eventSetup.getData(topoToken_);

int iMuonHit = 0;
int iTrackHit = 0;
Expand Down
Loading

0 comments on commit 27d076d

Please sign in to comment.