Skip to content

Commit

Permalink
Merge pull request #31802 from makortel/esConsumesTrackDetectorAssoci…
Browse files Browse the repository at this point in the history
…ator

Migrate TrackDetectorAssociator to EventSetup consumes
  • Loading branch information
cmsbuild authored Oct 22, 2020
2 parents 8c3c47e + d67bd80 commit 17ce976
Show file tree
Hide file tree
Showing 17 changed files with 172 additions and 170 deletions.
13 changes: 8 additions & 5 deletions Alignment/OfflineValidation/plugins/EopTreeWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class EopTreeWriter : public edm::EDAnalyzer {

// ----------member data ---------------------------
edm::InputTag src_;
edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geometryToken_;

edm::Service<TFileService> fs_;
TTree* tree_;
Expand All @@ -98,7 +99,8 @@ class EopTreeWriter : public edm::EDAnalyzer {
//
// constructors and destructor
//
EopTreeWriter::EopTreeWriter(const edm::ParameterSet& iConfig) : src_(iConfig.getParameter<edm::InputTag>("src")) {
EopTreeWriter::EopTreeWriter(const edm::ParameterSet& iConfig)
: src_(iConfig.getParameter<edm::InputTag>("src")), geometryToken_(esConsumes()) {
//now do what ever initialization is needed

// TrackAssociator parameters
Expand All @@ -125,9 +127,7 @@ void EopTreeWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSe
using namespace edm;

// get geometry
edm::ESHandle<CaloGeometry> geometry;
iSetup.get<CaloGeometryRecord>().get(geometry);
const CaloGeometry* geo = geometry.product();
const CaloGeometry* geo = &iSetup.getData(geometryToken_);
// const CaloSubdetectorGeometry* towerGeometry =
// geo->getSubdetectorGeometry(DetId::Calo, CaloTowerDetId::SubdetId);

Expand Down Expand Up @@ -190,7 +190,10 @@ void EopTreeWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSe

trackAssociator_.useDefaultPropagator();
TrackDetMatchInfo info = trackAssociator_.associate(
iEvent, iSetup, trackAssociator_.getFreeTrajectoryState(iSetup, *track), parameters_);
iEvent,
iSetup,
trackAssociator_.getFreeTrajectoryState(&iSetup.getData(parameters_.bFieldToken), *track),
parameters_);

trackemc1 = info.nXnEnergy(TrackDetMatchInfo::EcalRecHits, 0);
trackemc3 = info.nXnEnergy(TrackDetMatchInfo::EcalRecHits, 1);
Expand Down
22 changes: 13 additions & 9 deletions Calibration/HcalCalibAlgos/plugins/ValidIsoTrkCalib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ See the twiki page for details:
// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/ESHandle.h"

//#include "FWCore/Framework/interface/Event.h"
//#include "FWCore/Framework/interface/MakerMacros.h"
Expand Down Expand Up @@ -90,6 +89,9 @@ class ValidIsoTrkCalib : public edm::one::EDAnalyzer<edm::one::SharedResources>
edm::EDGetTokenT<reco::IsolatedPixelTrackCandidateCollection> tok_track_;
edm::EDGetTokenT<reco::TrackCollection> tok_track1_;

edm::ESGetToken<HcalRespCorrs, HcalRespCorrsRcd> tok_recalibCorrs_;
edm::ESGetToken<CaloGeometry, CaloGeometryRecord> tok_geom_;

//std::string m_inputTrackLabel;
//std::string m_hcalLabel;

Expand Down Expand Up @@ -202,6 +204,9 @@ ValidIsoTrkCalib::ValidIsoTrkCalib(const edm::ParameterSet& iConfig) {
consumes<reco::IsolatedPixelTrackCandidateCollection>(iConfig.getParameter<edm::InputTag>("HcalIsolTrackInput"));
tok_track1_ = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("trackInput"));

tok_recalibCorrs_ = esConsumes(edm::ESInputTag("", "recalibrate"));
tok_geom_ = esConsumes();

associationConeSize_ = iConfig.getParameter<double>("associationConeSize");
allowMissingInputs_ = iConfig.getUntrackedParameter<bool>("allowMissingInputs", true);
// outputFileName_=iConfig.getParameter<std::string>("outputFileName");
Expand Down Expand Up @@ -229,9 +234,7 @@ ValidIsoTrkCalib::ValidIsoTrkCalib(const edm::ParameterSet& iConfig) {
// ------------ method called to for each event ------------
void ValidIsoTrkCalib::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
try {
edm::ESHandle<HcalRespCorrs> recalibCorrs;
iSetup.get<HcalRespCorrsRcd>().get("recalibrate", recalibCorrs);
respRecalib = recalibCorrs.product();
respRecalib = &iSetup.getData(tok_recalibCorrs_);

edm::LogInfo("CalibConstants") << " Loaded: OK ";

Expand Down Expand Up @@ -259,9 +262,7 @@ void ValidIsoTrkCalib::analyze(const edm::Event& iEvent, const edm::EventSetup&
iEvent.getByToken(tok_hbhe_, hbhe);
const HBHERecHitCollection Hithbhe = *(hbhe.product());

edm::ESHandle<CaloGeometry> pG;
iSetup.get<CaloGeometryRecord>().get(pG);
geo = pG.product();
geo = &iSetup.getData(tok_geom_);

const HcalGeometry* gHcal = static_cast<const HcalGeometry*>(geo->getSubdetectorGeometry(DetId::Hcal, HcalBarrel));
//Note: even though it says HcalBarrel, we actually get the whole Hcal detector geometry!
Expand Down Expand Up @@ -328,8 +329,11 @@ void ValidIsoTrkCalib::analyze(const edm::Event& iEvent, const edm::EventSetup&
//cout<<"Point 0.3. Matched :: pt: "<<trit->pt()<<" wholeEnergy: "<<trackE<<" emEnergy: "<<emEnergy<<" eta: "<<etahcal<<" phi: "<<phihcal<<endl;
//cout<<"Point 0.4. EM energy in cone: "<<emEnergy<<" EtaHcal: "<<etahcal<<" PhiHcal: "<<phihcal<<endl;

TrackDetMatchInfo info =
trackAssociator_.associate(iEvent, iSetup, trackAssociator_.getFreeTrajectoryState(iSetup, *trit), parameters_);
TrackDetMatchInfo info = trackAssociator_.associate(
iEvent,
iSetup,
trackAssociator_.getFreeTrajectoryState(&iSetup.getData(parameters_.bFieldToken), *trit),
parameters_);

//float etaecal=info.trkGlobPosAtEcal.eta();
//float phiecal=info.trkGlobPosAtEcal.phi();
Expand Down
57 changes: 22 additions & 35 deletions Calibration/IsolatedParticles/plugins/IsolatedTracksCone.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Common/interface/TriggerNames.h"
Expand Down Expand Up @@ -163,6 +162,12 @@ class IsolatedTracksCone : public edm::one::EDAnalyzer<edm::one::SharedResources
const edm::EDGetTokenT<edm::PCaloHitContainer> tok_caloHH_;
const edm::EDGetTokenT<edm::TriggerResults> tok_trigger_;

const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> tok_geom_;
const edm::ESGetToken<CaloTopology, CaloTopologyRecord> tok_caloTopology_;
const edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> tok_topo_;
const edm::ESGetToken<EcalChannelStatus, EcalChannelStatusRcd> tok_ecalChStatus_;
const edm::ESGetToken<EcalSeverityLevelAlgo, EcalSeverityLevelAlgoRcd> tok_sevlv_;

const double minTrackP_, maxTrackEta_, maxNearTrackP_;
const int debugEcalSimInfo_;
const bool applyEcalIsolation_;
Expand Down Expand Up @@ -348,6 +353,11 @@ IsolatedTracksCone::IsolatedTracksCone(const edm::ParameterSet& iConfig)
tok_caloEE_(consumes<edm::PCaloHitContainer>(edm::InputTag("g4SimHits", "EcalHitsEE"))),
tok_caloHH_(consumes<edm::PCaloHitContainer>(edm::InputTag("g4SimHits", "HcalHits"))),
tok_trigger_(consumes<edm::TriggerResults>(edm::InputTag("TriggerResults", "", "HLT"))),
tok_geom_(esConsumes()),
tok_caloTopology_(esConsumes()),
tok_topo_(esConsumes()),
tok_ecalChStatus_(esConsumes()),
tok_sevlv_(esConsumes()),
minTrackP_(iConfig.getUntrackedParameter<double>("minTrackP", 10.0)),
maxTrackEta_(iConfig.getUntrackedParameter<double>("maxTrackEta", 5.0)),
maxNearTrackP_(iConfig.getUntrackedParameter<double>("maxNearTrackP", 1.0)),
Expand Down Expand Up @@ -485,31 +495,22 @@ void IsolatedTracksCone::analyze(const edm::Event& iEvent, const edm::EventSetup
// Get the collection handles
///////////////////////////////////////////////

edm::ESHandle<CaloGeometry> pG;
iSetup.get<CaloGeometryRecord>().get(pG);
const CaloGeometry* geo = pG.product();
const CaloGeometry* geo = &iSetup.getData(tok_geom_);
const CaloSubdetectorGeometry* gEB = (geo->getSubdetectorGeometry(DetId::Ecal, EcalBarrel));
const CaloSubdetectorGeometry* gEE = (geo->getSubdetectorGeometry(DetId::Ecal, EcalEndcap));
const CaloSubdetectorGeometry* gHB = (geo->getSubdetectorGeometry(DetId::Hcal, HcalBarrel));
const CaloSubdetectorGeometry* gHE = (geo->getSubdetectorGeometry(DetId::Hcal, HcalEndcap));

edm::ESHandle<CaloTopology> theCaloTopology;
iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
const CaloTopology* caloTopology = theCaloTopology.product();

edm::ESHandle<HcalTopology> htopo;
iSetup.get<HcalRecNumberingRecord>().get(htopo);
const HcalTopology* theHBHETopology = htopo.product();
const CaloTopology* caloTopology = &iSetup.getData(tok_caloTopology_);
const HcalTopology* theHBHETopology = &iSetup.getData(tok_topo_);

edm::Handle<EcalRecHitCollection> barrelRecHitsHandle;
edm::Handle<EcalRecHitCollection> endcapRecHitsHandle;
iEvent.getByToken(tok_EB_, barrelRecHitsHandle);
iEvent.getByToken(tok_EE_, endcapRecHitsHandle);

// Retrieve the good/bad ECAL channels from the DB
edm::ESHandle<EcalChannelStatus> ecalChStatus;
iSetup.get<EcalChannelStatusRcd>().get(ecalChStatus);
const EcalChannelStatus* theEcalChStatus = ecalChStatus.product();
const EcalChannelStatus* theEcalChStatus = &iSetup.getData(tok_ecalChStatus_);

edm::Handle<HBHERecHitCollection> hbhe;
iEvent.getByToken(tok_hbhe_, hbhe);
Expand Down Expand Up @@ -628,6 +629,7 @@ void IsolatedTracksCone::analyze(const edm::Event& iEvent, const edm::EventSetup
nMissEcal = 0;
nMissHcal = 0;

const EcalSeverityLevelAlgo* sevlv = &iSetup.getData(tok_sevlv_);
for (trkItr = trkCollection->begin(); trkItr != trkCollection->end(); ++trkItr) {
nRawTRK++;

Expand Down Expand Up @@ -668,7 +670,8 @@ void IsolatedTracksCone::analyze(const edm::Event& iEvent, const edm::EventSetup
// Find track trajectory
////////////////////////////////////////////

const FreeTrajectoryState fts1 = trackAssociator_->getFreeTrajectoryState(iSetup, *pTrack);
const FreeTrajectoryState fts1 =
trackAssociator_->getFreeTrajectoryState(&iSetup.getData(parameters_.bFieldToken), *pTrack);

TrackDetMatchInfo info1 = trackAssociator_->associate(iEvent, iSetup, fts1, parameters_);

Expand Down Expand Up @@ -757,33 +760,17 @@ void IsolatedTracksCone::analyze(const edm::Event& iEvent, const edm::EventSetup
// NxN cluster
double e3x3 = -999.0;
double trkEcalEne = -999.0;
edm::ESHandle<EcalSeverityLevelAlgo> sevlv;
iSetup.get<EcalSeverityLevelAlgoRcd>().get(sevlv);

if (std::abs(point1.eta()) < 1.479) {
const DetId isoCell = gEB->getClosestCell(point1);
e3x3 = spr::eECALmatrix(isoCell,
barrelRecHitsHandle,
endcapRecHitsHandle,
*theEcalChStatus,
geo,
caloTopology,
sevlv.product(),
1,
1)
e3x3 = spr::eECALmatrix(
isoCell, barrelRecHitsHandle, endcapRecHitsHandle, *theEcalChStatus, geo, caloTopology, sevlv, 1, 1)
.first;
trkEcalEne = spr::eCaloSimInfo(iEvent, geo, pcaloeb, pcaloee, SimTk, SimVtx, pTrack, *associate);
} else {
const DetId isoCell = gEE->getClosestCell(point1);
e3x3 = spr::eECALmatrix(isoCell,
barrelRecHitsHandle,
endcapRecHitsHandle,
*theEcalChStatus,
geo,
caloTopology,
sevlv.product(),
1,
1)
e3x3 = spr::eECALmatrix(
isoCell, barrelRecHitsHandle, endcapRecHitsHandle, *theEcalChStatus, geo, caloTopology, sevlv, 1, 1)
.first;
trkEcalEne = spr::eCaloSimInfo(iEvent, geo, pcaloeb, pcaloee, SimTk, SimVtx, pTrack, *associate);
}
Expand Down
3 changes: 2 additions & 1 deletion Calibration/IsolatedParticles/src/ChargeIsolation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ namespace spr {
// candidate
if (trkItr2 != trkItr) {
// Get propagator
const FreeTrajectoryState fts2 = associator.getFreeTrajectoryState(iSetup, *pTrack2);
const FreeTrajectoryState fts2 =
associator.getFreeTrajectoryState(&iSetup.getData(parameters_.bFieldToken), *pTrack2);
TrackDetMatchInfo info2 = associator.associate(iEvent, iSetup, fts2, parameters_);

// Make sure it reaches Hcal
Expand Down
9 changes: 6 additions & 3 deletions Calibration/IsolatedParticles/src/ChargeIsolationExtra.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ namespace spr {

bool trkQuality = pTrack2->quality(trackQuality_);
if ((trkItr2 != trkItr) && trkQuality) {
const FreeTrajectoryState fts2 = associator.getFreeTrajectoryState(iSetup, *pTrack2);
const FreeTrajectoryState fts2 =
associator.getFreeTrajectoryState(&iSetup.getData(parameters_.bFieldToken), *pTrack2);
TrackDetMatchInfo info2 = associator.associate(iEvent, iSetup, fts2, parameters_);
const GlobalPoint point2(info2.trkGlobPosAtEcal.x(), info2.trkGlobPosAtEcal.y(), info2.trkGlobPosAtEcal.z());

Expand Down Expand Up @@ -131,7 +132,8 @@ namespace spr {

bool trkQuality = pTrack2->quality(trackQuality_);
if ((trkItr2 != trkItr) && trkQuality) {
const FreeTrajectoryState fts2 = associator.getFreeTrajectoryState(iSetup, *pTrack2);
const FreeTrajectoryState fts2 =
associator.getFreeTrajectoryState(&iSetup.getData(parameters_.bFieldToken), *pTrack2);
TrackDetMatchInfo info2 = associator.associate(iEvent, iSetup, fts2, parameters_);
const GlobalPoint point2(info2.trkGlobPosAtEcal.x(), info2.trkGlobPosAtEcal.y(), info2.trkGlobPosAtEcal.z());

Expand Down Expand Up @@ -204,7 +206,8 @@ namespace spr {

bool trkQuality = pTrack2->quality(trackQuality_);
if ((trkItr2 != trkItr) && trkQuality) {
const FreeTrajectoryState fts2 = associator.getFreeTrajectoryState(iSetup, *pTrack2);
const FreeTrajectoryState fts2 =
associator.getFreeTrajectoryState(&iSetup.getData(parameters_.bFieldToken), *pTrack2);
TrackDetMatchInfo info2 = associator.associate(iEvent, iSetup, fts2, parameters_);
const GlobalPoint point2(info2.trkGlobPosAtHcal.x(), info2.trkGlobPosAtHcal.y(), info2.trkGlobPosAtHcal.z());

Expand Down
9 changes: 6 additions & 3 deletions JetMETCorrections/IsolatedParticles/test/TestIsoSimTracks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "DataFormats/Common/interface/Handle.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "DataFormats/Common/interface/OrphanHandle.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"
Expand Down Expand Up @@ -191,8 +190,12 @@ void TestIsoSimTracks::analyze(const edm::Event& iEvent, const edm::EventSetup&
// << " GeV" << std::endl;

// std::cout << "Details:\n" <<std::endl;
TrackDetMatchInfo info = trackAssociator_.associate(
iEvent, iSetup, trackAssociator_.getFreeTrajectoryState(iSetup, *tracksCI, vertex), trackAssociatorParameters_);
TrackDetMatchInfo info =
trackAssociator_.associate(iEvent,
iSetup,
trackAssociator_.getFreeTrajectoryState(
&iSetup.getData(trackAssociatorParameters_.bFieldToken), *tracksCI, vertex),
trackAssociatorParameters_);
// std::cout << "ECAL, if track reach ECAL: " << info.isGoodEcal << std::endl;
// std::cout << "ECAL, number of crossed cells: " << info.crossedEcalRecHits.size() << std::endl;
// std::cout << "ECAL, energy of crossed cells: " << info.ecalEnergy() << " GeV" << std::endl;
Expand Down
6 changes: 4 additions & 2 deletions JetMETCorrections/IsolatedParticles/test/TestIsoTracks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "DataFormats/Common/interface/Handle.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "DataFormats/Common/interface/OrphanHandle.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"
Expand Down Expand Up @@ -215,7 +214,10 @@ void TestIsoTracks::analyze(const edm::Event& iEvent, const edm::EventSetup& iSe

// std::cout << "Details:\n" <<std::endl;
TrackDetMatchInfo info = trackAssociator_.associate(
iEvent, iSetup, trackAssociator_.getFreeTrajectoryState(iSetup, *tracksCI), trackAssociatorParameters_);
iEvent,
iSetup,
trackAssociator_.getFreeTrajectoryState(&iSetup.getData(trackAssociatorParameters_.bFieldToken), *tracksCI),
trackAssociatorParameters_);
// std::cout << "ECAL, if track reach ECAL: " << info.isGoodEcal << std::endl;
// std::cout << "ECAL, number of crossed cells: " << info.crossedEcalRecHits.size() << std::endl;
// std::cout << "ECAL, energy of crossed cells: " << info.ecalEnergy() << " GeV" << std::endl;
Expand Down
Loading

0 comments on commit 17ce976

Please sign in to comment.