Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ECAL esConsumes migration of CalibCalorimetry packages #35077

Merged
merged 22 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
#include "Geometry/Records/interface/IdealGeometryRecord.h"
#include "Geometry/CaloGeometry/interface/CaloGeometry.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "DataFormats/EcalDetId/interface/EBDetId.h"
#include "DataFormats/EcalDetId/interface/EEDetId.h"
#include <iostream>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
#include "Geometry/Records/interface/IdealGeometryRecord.h"
#include "Geometry/CaloGeometry/interface/CaloGeometry.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "DataFormats/HcalDetId/interface/HcalDetId.h"
#include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
#include "Geometry/CaloTopology/interface/HcalTopology.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "CondFormats/EcalObjects/interface/EcalIntercalibConstants.h"
#include "CondFormats/DataRecord/interface/EcalIntercalibConstantsRcd.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "CondFormats/EcalObjects/interface/EcalIntercalibConstantsMC.h"
#include "CondFormats/DataRecord/interface/EcalIntercalibConstantsMCRcd.h"
Expand Down
27 changes: 18 additions & 9 deletions CalibCalorimetry/CaloMiscalibTools/interface/EcalRecHitRecalib.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,21 @@

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
#include "CondFormats/EcalObjects/interface/EcalIntercalibConstants.h"
#include "CondFormats/DataRecord/interface/EcalIntercalibConstantsRcd.h"
//
// class decleration
//

class EcalRecHitRecalib : public edm::EDProducer {
class EcalRecHitRecalib : public edm::stream::EDProducer<> {
public:
explicit EcalRecHitRecalib(const edm::ParameterSet &);
~EcalRecHitRecalib() override;
Expand All @@ -44,13 +47,19 @@ class EcalRecHitRecalib : public edm::EDProducer {
private:
// ----------member data ---------------------------

std::string ecalHitsProducer_;
std::string barrelHits_;
std::string endcapHits_;
std::string RecalibBarrelHits_;
std::string RecalibEndcapHits_;
double refactor_;
double refactor_mean_;
const std::string ecalHitsProducer_;
const std::string barrelHits_;
const std::string endcapHits_;
const std::string recalibBarrelHits_;
const std::string recalibEndcapHits_;
const double refactor_;
const double refactor_mean_;

const edm::EDGetTokenT<EBRecHitCollection> ebRecHitToken_;
const edm::EDGetTokenT<EERecHitCollection> eeRecHitToken_;
const edm::ESGetToken<EcalIntercalibConstants, EcalIntercalibConstantsRcd> intercalibConstsToken_;
const edm::EDPutTokenT<EBRecHitCollection> barrelHitsToken_;
const edm::EDPutTokenT<EERecHitCollection> endcapHitsToken_;
};

#endif
24 changes: 13 additions & 11 deletions CalibCalorimetry/CaloMiscalibTools/interface/HcalRecHitRecalib.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
Expand All @@ -32,8 +32,9 @@
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "CalibCalorimetry/CaloMiscalibTools/interface/CaloMiscalibMapHcal.h"
#include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
#include "Geometry/Records/interface/HcalRecNumberingRecord.h"

class HcalRecHitRecalib : public edm::EDProducer {
class HcalRecHitRecalib : public edm::stream::EDProducer<> {
public:
explicit HcalRecHitRecalib(const edm::ParameterSet &);
~HcalRecHitRecalib() override;
Expand All @@ -42,18 +43,19 @@ class HcalRecHitRecalib : public edm::EDProducer {
void produce(edm::Event &, const edm::EventSetup &) override;

private:
edm::EDGetTokenT<HBHERecHitCollection> tok_hbhe_;
edm::EDGetTokenT<HORecHitCollection> tok_ho_;
edm::EDGetTokenT<HFRecHitCollection> tok_hf_;
std::string RecalibHBHEHits_;
std::string RecalibHFHits_;
std::string RecalibHOHits_;
const edm::EDGetTokenT<HBHERecHitCollection> tok_hbhe_;
const edm::EDGetTokenT<HORecHitCollection> tok_ho_;
const edm::EDGetTokenT<HFRecHitCollection> tok_hf_;
const edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> topologyToken_;
const std::string recalibHBHEHits_;
const std::string recalibHFHits_;
const std::string recalibHOHits_;

std::string hcalfile_;
std::string hcalfileinpath_;
const std::string hcalfileinpath_;

CaloMiscalibMapHcal mapHcal_;
double refactor_;
double refactor_mean_;
const double refactor_;
const double refactor_mean_;
};
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@

// user 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/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "CondFormats/EcalObjects/interface/EcalIntercalibConstants.h"
#include "CondFormats/DataRecord/interface/EcalIntercalibConstantsRcd.h"
//
// class decleration
//

class WriteEcalMiscalibConstants : public edm::EDAnalyzer {
class WriteEcalMiscalibConstants : public edm::one::EDAnalyzer<> {
public:
explicit WriteEcalMiscalibConstants(const edm::ParameterSet&);
~WriteEcalMiscalibConstants() override;
Expand All @@ -33,4 +36,6 @@ class WriteEcalMiscalibConstants : public edm::EDAnalyzer {

// ----------member data ---------------------------
std::string newTagRequest_;

const edm::ESGetToken<EcalIntercalibConstants, EcalIntercalibConstantsRcd> intercalibConstsToken_;
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@

// user 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/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "CondFormats/EcalObjects/interface/EcalIntercalibConstantsMC.h"
#include "CondFormats/DataRecord/interface/EcalIntercalibConstantsMCRcd.h"
//
// class decleration
//

class WriteEcalMiscalibConstantsMC : public edm::EDAnalyzer {
class WriteEcalMiscalibConstantsMC : public edm::one::EDAnalyzer<> {
public:
explicit WriteEcalMiscalibConstantsMC(const edm::ParameterSet&);
~WriteEcalMiscalibConstantsMC() override;
Expand All @@ -33,4 +36,6 @@ class WriteEcalMiscalibConstantsMC : public edm::EDAnalyzer {

// ----------member data ---------------------------
std::string newTagRequest_;

const edm::ESGetToken<EcalIntercalibConstantsMC, EcalIntercalibConstantsMCRcd> intercalibConstsToken_;
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// user include files
#include "CalibCalorimetry/CaloMiscalibTools/interface/CaloMiscalibTools.h"
#include "FWCore/ParameterSet/interface/FileInPath.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "CalibCalorimetry/CaloMiscalibTools/interface/MiscalibReaderFromXMLEcalBarrel.h"
#include "CalibCalorimetry/CaloMiscalibTools/interface/MiscalibReaderFromXMLEcalEndcap.h"
Expand All @@ -45,8 +46,8 @@ CaloMiscalibTools::CaloMiscalibTools(const edm::ParameterSet& iConfig) {
barrelfile_ = barrelfiletmp.fullPath();
endcapfile_ = endcapfiletmp.fullPath();

std::cout << "Barrel file is:" << barrelfile_ << std::endl;
std::cout << "endcap file is:" << endcapfile_ << std::endl;
edm::LogVerbatim("CaloMiscalibTools") << "Barrel file is:" << barrelfile_;
edm::LogVerbatim("CaloMiscalibTools") << "endcap file is:" << endcapfile_;

// added by Zhen (changed since 1_2_0)
setWhatProduced(this, &CaloMiscalibTools::produce);
Expand Down Expand Up @@ -75,9 +76,7 @@ CaloMiscalibTools::ReturnType CaloMiscalibTools::produce(const EcalIntercalibCon
endcapreader_.parseXMLMiscalibFile(endcapfile_);
map.print();
// Added by Zhen, need a new object so to not be deleted at exit
// std::cout<<"about to copy"<<std::endl;
CaloMiscalibTools::ReturnType mydata = std::make_unique<EcalIntercalibConstants>(map.get());
// std::cout<<"mydata "<<mydata<<std::endl;
return mydata;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// user include files
#include "CalibCalorimetry/CaloMiscalibTools/interface/CaloMiscalibToolsMC.h"
#include "FWCore/ParameterSet/interface/FileInPath.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "CalibCalorimetry/CaloMiscalibTools/interface/MiscalibReaderFromXMLEcalBarrel.h"
#include "CalibCalorimetry/CaloMiscalibTools/interface/MiscalibReaderFromXMLEcalEndcap.h"
Expand All @@ -45,8 +46,8 @@ CaloMiscalibToolsMC::CaloMiscalibToolsMC(const edm::ParameterSet& iConfig) {
barrelfile_ = barrelfiletmp.fullPath();
endcapfile_ = endcapfiletmp.fullPath();

std::cout << "Barrel file is:" << barrelfile_ << std::endl;
std::cout << "endcap file is:" << endcapfile_ << std::endl;
edm::LogVerbatim("CaloMiscalibToolsMC") << "Barrel file is:" << barrelfile_;
edm::LogVerbatim("CaloMiscalibToolsMC") << "endcap file is:" << endcapfile_;

// added by Zhen (changed since 1_2_0)
setWhatProduced(this, &CaloMiscalibToolsMC::produce);
Expand Down Expand Up @@ -75,9 +76,7 @@ CaloMiscalibToolsMC::ReturnType CaloMiscalibToolsMC::produce(const EcalIntercali
endcapreader_.parseXMLMiscalibFile(endcapfile_);
map.print();
// Added by Zhen, need a new object so to not be deleted at exit
// std::cout<<"about to copy"<<std::endl;
CaloMiscalibToolsMC::ReturnType mydata = std::make_unique<EcalIntercalibConstantsMC>(map.get());
// std::cout<<"mydata "<<mydata<<std::endl;
return mydata;
}

Expand Down
54 changes: 22 additions & 32 deletions CalibCalorimetry/CaloMiscalibTools/plugins/EcalRecHitRecalib.cc
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@

#include "CondFormats/EcalObjects/interface/EcalIntercalibConstants.h"
#include "CondFormats/DataRecord/interface/EcalIntercalibConstantsRcd.h"

#include "DataFormats/Common/interface/Handle.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/EventSetup.h"

#include "DataFormats/EcalDetId/interface/EBDetId.h"
#include "DataFormats/EcalDetId/interface/EEDetId.h"
#include "CalibCalorimetry/CaloMiscalibTools/interface/EcalRecHitRecalib.h"
#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

EcalRecHitRecalib::EcalRecHitRecalib(const edm::ParameterSet& iConfig) {
ecalHitsProducer_ = iConfig.getParameter<std::string>("ecalRecHitsProducer");
barrelHits_ = iConfig.getParameter<std::string>("barrelHitCollection");
endcapHits_ = iConfig.getParameter<std::string>("endcapHitCollection");
RecalibBarrelHits_ = iConfig.getParameter<std::string>("RecalibBarrelHitCollection");
RecalibEndcapHits_ = iConfig.getParameter<std::string>("RecalibEndcapHitCollection");
refactor_ = iConfig.getUntrackedParameter<double>("Refactor", (double)1);
refactor_mean_ = iConfig.getUntrackedParameter<double>("Refactor_mean", (double)1);

//register your products
produces<EBRecHitCollection>(RecalibBarrelHits_);
produces<EERecHitCollection>(RecalibEndcapHits_);
}
EcalRecHitRecalib::EcalRecHitRecalib(const edm::ParameterSet& iConfig)
: ecalHitsProducer_(iConfig.getParameter<std::string>("ecalRecHitsProducer")),
barrelHits_(iConfig.getParameter<std::string>("barrelHitCollection")),
endcapHits_(iConfig.getParameter<std::string>("endcapHitCollection")),
recalibBarrelHits_(iConfig.getParameter<std::string>("RecalibBarrelHitCollection")),
recalibEndcapHits_(iConfig.getParameter<std::string>("RecalibEndcapHitCollection")),
refactor_(iConfig.getUntrackedParameter<double>("Refactor", (double)1)),
refactor_mean_(iConfig.getUntrackedParameter<double>("Refactor_mean", (double)1)),
ebRecHitToken_(consumes<EBRecHitCollection>(edm::InputTag(ecalHitsProducer_, barrelHits_))),
eeRecHitToken_(consumes<EERecHitCollection>(edm::InputTag(ecalHitsProducer_, endcapHits_))),
intercalibConstsToken_(esConsumes()),
barrelHitsToken_(produces<EBRecHitCollection>(recalibBarrelHits_)),
endcapHitsToken_(produces<EERecHitCollection>(recalibEndcapHits_)) {}

EcalRecHitRecalib::~EcalRecHitRecalib() {}

Expand All @@ -39,14 +33,14 @@ void EcalRecHitRecalib::produce(edm::Event& iEvent, const edm::EventSetup& iSetu
const EBRecHitCollection* EBRecHits = nullptr;
const EERecHitCollection* EERecHits = nullptr;

iEvent.getByLabel(ecalHitsProducer_, barrelHits_, barrelRecHitsHandle);
iEvent.getByToken(ebRecHitToken_, barrelRecHitsHandle);
if (!barrelRecHitsHandle.isValid()) {
LogDebug("") << "EcalREcHitMiscalib: Error! can't get product!" << std::endl;
} else {
EBRecHits = barrelRecHitsHandle.product(); // get a ptr to the product
}

iEvent.getByLabel(ecalHitsProducer_, endcapHits_, endcapRecHitsHandle);
iEvent.getByToken(eeRecHitToken_, endcapRecHitsHandle);
if (!endcapRecHitsHandle.isValid()) {
LogDebug("") << "EcalREcHitMiscalib: Error! can't get product!" << std::endl;
} else {
Expand All @@ -58,21 +52,18 @@ void EcalRecHitRecalib::produce(edm::Event& iEvent, const edm::EventSetup& iSetu
auto RecalibEERecHitCollection = std::make_unique<EERecHitCollection>();

// Intercalib constants
edm::ESHandle<EcalIntercalibConstants> pIcal;
iSetup.get<EcalIntercalibConstantsRcd>().get(pIcal);
const EcalIntercalibConstants* ical = pIcal.product();
const EcalIntercalibConstants& ical = iSetup.getData(intercalibConstsToken_);

if (EBRecHits) {
//loop on all EcalRecHits (barrel)
EBRecHitCollection::const_iterator itb;
for (itb = EBRecHits->begin(); itb != EBRecHits->end(); ++itb) {
// find intercalib constant for this xtal
EcalIntercalibConstantMap::const_iterator icalit = ical->getMap().find(itb->id().rawId());
EcalIntercalibConstantMap::const_iterator icalit = ical.getMap().find(itb->id().rawId());
EcalIntercalibConstant icalconst = -1;

if (icalit != ical->getMap().end()) {
if (icalit != ical.getMap().end()) {
icalconst = (*icalit);
// edm::LogDebug("EcalRecHitRecalib") << "Found intercalib for xtal " << EBDetId(itb->id()) << " " << icalconst ;

} else {
edm::LogError("EcalRecHitRecalib") << "No intercalib const found for xtal " << EBDetId(itb->id())
Expand All @@ -93,12 +84,11 @@ void EcalRecHitRecalib::produce(edm::Event& iEvent, const edm::EventSetup& iSetu
EERecHitCollection::const_iterator ite;
for (ite = EERecHits->begin(); ite != EERecHits->end(); ++ite) {
// find intercalib constant for this xtal
EcalIntercalibConstantMap::const_iterator icalit = ical->getMap().find(ite->id().rawId());
EcalIntercalibConstantMap::const_iterator icalit = ical.getMap().find(ite->id().rawId());
EcalIntercalibConstant icalconst = -1;

if (icalit != ical->getMap().end()) {
if (icalit != ical.getMap().end()) {
icalconst = (*icalit);
// edm:: LogDebug("EcalRecHitRecalib") << "Found intercalib for xtal " << EEDetId(ite->id()) << " " << icalconst ;
} else {
edm::LogError("EcalRecHitRecalib") << "No intercalib const found for xtal " << EEDetId(ite->id())
<< "! something wrong with EcalIntercalibConstants in your DB? ";
Expand All @@ -115,6 +105,6 @@ void EcalRecHitRecalib::produce(edm::Event& iEvent, const edm::EventSetup& iSetu
}

//Put Recalibrated rechit in the event
iEvent.put(std::move(RecalibEBRecHitCollection), RecalibBarrelHits_);
iEvent.put(std::move(RecalibEERecHitCollection), RecalibEndcapHits_);
iEvent.put(barrelHitsToken_, std::move(RecalibEBRecHitCollection));
iEvent.put(endcapHitsToken_, std::move(RecalibEERecHitCollection));
}
Loading