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

Run3-hcx333 Replace getByLabel with getHandle in SimCalorimetry/HcalTestBeam #37723

Merged
merged 3 commits into from
Apr 28, 2022
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
18 changes: 11 additions & 7 deletions SimCalorimetry/HcalTestBeam/interface/HcalTBDigiProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "SimGeneral/MixingModule/interface/DigiAccumulatorMixMod.h"
#include "SimCalorimetry/HcalSimAlgos/interface/HcalSimParameters.h"

#include <memory>
#include <string>
#include <vector>

Expand Down Expand Up @@ -61,6 +62,9 @@ class HcalTBDigiProducer : public DigiAccumulatorMixMod {
typedef CaloTDigitizer<HBHEDigitizerTraits> HBHEDigitizer;
typedef CaloTDigitizer<HODigitizerTraits> HODigitizer;

const double tunePhaseShift;
const std::string ecalTBInfoLabel;

HcalTBSimParameterMap *theParameterMap;
HcalSimParameterMap *paraMap;
CaloVShape *theHcalShape;
Expand All @@ -78,24 +82,24 @@ class HcalTBDigiProducer : public DigiAccumulatorMixMod {

HcalTimeSlewSim *theTimeSlewSim;

HBHEDigitizer *theHBHEDigitizer;
HODigitizer *theHODigitizer;
std::unique_ptr<HBHEDigitizer> theHBHEDigitizer;
std::unique_ptr<HODigitizer> theHODigitizer;

edm::ESGetToken<HcalDbService, HcalDbRecord> conditionsToken_;
edm::ESGetToken<HcalTimeSlew, HcalTimeSlewRecord> hcalTimeSlew_delay_token_;
edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geometryToken_;
const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geometryToken_;
const edm::ESGetToken<HcalDbService, HcalDbRecord> conditionsToken_;
const edm::ESGetToken<HcalTimeSlew, HcalTimeSlewRecord> hcalTimeSlew_delay_token_;
edm::ESWatcher<CaloGeometryRecord> geometryWatcher_;
const edm::EDGetTokenT<std::vector<PCaloHit>> hcalToken_;
edm::EDGetTokenT<PEcalTBInfo> theEcalTBToken_;
const CaloGeometry *theGeometry;
std::vector<DetId> hbheCells;
std::vector<DetId> hoCells;

std::vector<PCaloHit> theHBHEHits, theHOHits;

std::string ecalTBInfoLabel;
double thisPhaseShift;

bool doPhaseShift;
double tunePhaseShift;

CLHEP::HepRandomEngine *randomEngine_ = nullptr;
};
Expand Down
48 changes: 22 additions & 26 deletions SimCalorimetry/HcalTestBeam/src/HcalTBDigiProducer.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <memory>

#include "DataFormats/Common/interface/Handle.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
Expand All @@ -19,7 +21,9 @@
HcalTBDigiProducer::HcalTBDigiProducer(const edm::ParameterSet &ps,
edm::ProducesCollector producesCollector,
edm::ConsumesCollector &iC)
: theParameterMap(new HcalTBSimParameterMap(ps)),
: tunePhaseShift(ps.getUntrackedParameter<double>("tunePhaseShiftTB", 1.)),
ecalTBInfoLabel(ps.getUntrackedParameter<std::string>("EcalTBInfoLabel", "SimEcalTBG4Object")),
theParameterMap(new HcalTBSimParameterMap(ps)),
paraMap(new HcalSimParameterMap(ps)),
theHcalShape(new HcalShape()),
theHcalIntegratedShape(new CaloShapeIntegrator(theHcalShape)),
Expand All @@ -29,17 +33,16 @@ HcalTBDigiProducer::HcalTBDigiProducer(const edm::ParameterSet &ps,
theCoderFactory(nullptr),
theElectronicsSim(nullptr),
theTimeSlewSim(nullptr),
theHBHEDigitizer(nullptr),
theHODigitizer(nullptr),
geometryToken_(iC.esConsumes()),
conditionsToken_(iC.esConsumes()),
hcalTimeSlew_delay_token_(iC.esConsumes(edm::ESInputTag("", "HBHE"))),
hcalToken_(iC.consumes<std::vector<PCaloHit>>(edm::InputTag("g4SimHits", "HcalHits"))),
theHBHEHits(),
theHOHits(),
thisPhaseShift(0) {
std::string const instance("simHcalDigis");
producesCollector.produces<HBHEDigiCollection>(instance);
producesCollector.produces<HODigiCollection>(instance);
iC.consumes<std::vector<PCaloHit>>(edm::InputTag("g4SimHits", "HcalHits"));

DetId detId(DetId::Hcal, 1);
bool syncPhase = (theParameterMap->simParameters(detId)).syncPhase();
Expand All @@ -65,27 +68,22 @@ HcalTBDigiProducer::HcalTBDigiProducer(const edm::ParameterSet &ps,
theAmplifier->setTimeSlewSim(theTimeSlewSim);
}

theHBHEDigitizer = new HBHEDigitizer(theHBHEResponse, theElectronicsSim, doNoise);
theHODigitizer = new HODigitizer(theHOResponse, theElectronicsSim, doNoise);
theHBHEDigitizer = std::make_unique<HBHEDigitizer>(theHBHEResponse, theElectronicsSim, doNoise);
theHODigitizer = std::make_unique<HODigitizer>(theHOResponse, theElectronicsSim, doNoise);

tunePhaseShift = ps.getUntrackedParameter<double>("tunePhaseShiftTB", 1.);
ecalTBInfoLabel = ps.getUntrackedParameter<std::string>("EcalTBInfoLabel", "SimEcalTBG4Object");
edm::LogInfo("HcalSim") << "HcalTBDigiProducer initialized with doNoise = " << doNoise
<< ", doTimeSlew = " << doTimeSlew << " and doPhaseShift = " << doPhaseShift
<< " tunePhasShift = " << tunePhaseShift;
edm::LogVerbatim("HcalSim") << "HcalTBDigiProducer initialized with doNoise = " << doNoise
<< ", doTimeSlew = " << doTimeSlew << " and doPhaseShift = " << doPhaseShift
<< " tunePhasShift = " << tunePhaseShift;

if (doPhaseShift) {
iC.consumes<PEcalTBInfo>(edm::InputTag(ecalTBInfoLabel, ""));
}
if (doPhaseShift)
theEcalTBToken_ = iC.consumes<PEcalTBInfo>(edm::InputTag(ecalTBInfoLabel, ""));
}

HcalTBDigiProducer::~HcalTBDigiProducer() {
if (theHBHEDigitizer)
delete theHBHEDigitizer;
if (theHODigitizer)
delete theHODigitizer;
if (theParameterMap)
delete theParameterMap;
if (paraMap)
delete paraMap;
if (theHcalShape)
delete theHcalShape;
if (theHcalIntegratedShape)
Expand Down Expand Up @@ -120,8 +118,7 @@ void HcalTBDigiProducer::initializeEvent(edm::Event const &e, edm::EventSetup co
theHBHEHits.clear();
theHOHits.clear();
if (doPhaseShift) {
edm::Handle<PEcalTBInfo> theEcalTBInfo;
e.getByLabel(ecalTBInfoLabel, theEcalTBInfo);
const edm::Handle<PEcalTBInfo> &theEcalTBInfo = e.getHandle(theEcalTBToken_);
thisPhaseShift = theEcalTBInfo->phaseShift();

DetId detIdHB(DetId::Hcal, 1);
Expand Down Expand Up @@ -153,8 +150,7 @@ void HcalTBDigiProducer::accumulate(edm::Event const &e, edm::EventSetup const &
// Step A: Get Inputs, and accumulate digis

edm::InputTag hcalTag("g4SimHits", "HcalHits");
edm::Handle<std::vector<PCaloHit>> hcalHandle;
e.getByLabel(hcalTag, hcalHandle);
const edm::Handle<std::vector<PCaloHit>> &hcalHandle = e.getHandle(hcalToken_);

accumulateCaloHits(hcalHandle, 0);
}
Expand All @@ -178,9 +174,9 @@ void HcalTBDigiProducer::finalizeEvent(edm::Event &e, const edm::EventSetup &eve
LogDebug("HcalSim") << "HcalTBDigiProducer::produce Empty collection created";
// Step C: Invoke the algorithm, getting back outputs.
theHBHEDigitizer->run(*hbheResult, randomEngine_);
edm::LogInfo("HcalSim") << "HcalTBDigiProducer: HBHE digis : " << hbheResult->size();
edm::LogVerbatim("HcalSim") << "HcalTBDigiProducer: HBHE digis : " << hbheResult->size();
theHODigitizer->run(*hoResult, randomEngine_);
edm::LogInfo("HcalSim") << "HcalTBDigiProducer: HO digis : " << hoResult->size();
edm::LogVerbatim("HcalSim") << "HcalTBDigiProducer: HO digis : " << hoResult->size();

// Step D: Put outputs into event
std::string const instance("simHcalDigis");
Expand Down Expand Up @@ -226,8 +222,8 @@ void HcalTBDigiProducer::updateGeometry() {
hoCells.clear();
hoCells = theGeometry->getValidDetIds(DetId::Hcal, HcalOuter);

edm::LogInfo("HcalSim") << "HcalTBDigiProducer update Geometry with " << hbheCells.size() << " cells in HB/HE and "
<< hoCells.size() << " cells in HO";
edm::LogVerbatim("HcalSim") << "HcalTBDigiProducer update Geometry with " << hbheCells.size()
<< " cells in HB/HE and " << hoCells.size() << " cells in HO";

theHBHEDigitizer->setDetIds(hbheCells);
LogDebug("HcalSim") << "HcalTBDigiProducer: Set DetID's for HB/HE";
Expand Down