Skip to content

Commit

Permalink
Merge pull request #22538 from kpedro88/HcalDigiFixES
Browse files Browse the repository at this point in the history
Improve event setup usage in HCAL digitization
  • Loading branch information
cmsbuild committed Mar 10, 2018
2 parents 849f098 + 0f66303 commit 58a31df
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 63 deletions.
9 changes: 3 additions & 6 deletions SimCalorimetry/HcalSimAlgos/interface/HcalShapes.h
Expand Up @@ -9,12 +9,11 @@
#include "SimCalorimetry/CaloSimAlgos/interface/CaloShapes.h"
#include "SimCalorimetry/HcalSimAlgos/interface/HcalShape.h"
#include "SimCalorimetry/HcalSimAlgos/interface/ZDCShape.h"
#include "CalibFormats/HcalObjects/interface/HcalDbService.h"
#include <vector>
#include <map>
class CaloVShape;
class DetId;
class HcalMCParams;
class HcalTopology;

class HcalShapes : public CaloShapes
{
Expand All @@ -23,8 +22,7 @@ class HcalShapes : public CaloShapes
HcalShapes();
~HcalShapes() override;

void beginRun(edm::EventSetup const & es);
void endRun();
void setDbService(const HcalDbService * service) {theDbService = service;}

const CaloVShape * shape(const DetId & detId, bool precise=false) const override;

Expand All @@ -33,8 +31,7 @@ class HcalShapes : public CaloShapes
// hardcoded, if we can't figure it out from the DB
const CaloVShape * defaultShape(const DetId & detId, bool precise=false) const;
const ShapeMap& getShapeMap(bool precise) const;
HcalMCParams * theMCParams;
const HcalTopology * theTopology;
const HcalDbService * theDbService;
ShapeMap theShapes;
ShapeMap theShapesPrecise;
ZDCShape theZDCShape;
Expand Down
33 changes: 3 additions & 30 deletions SimCalorimetry/HcalSimAlgos/src/HcalShapes.cc
Expand Up @@ -10,8 +10,7 @@
#include "Geometry/CaloTopology/interface/HcalTopology.h"

HcalShapes::HcalShapes()
: theMCParams(nullptr),
theTopology(nullptr)
: theDbService(nullptr)
{
/*
00 - not used (reserved)
Expand Down Expand Up @@ -50,41 +49,15 @@ HcalShapes::~HcalShapes()
delete shapeItr.second;
}
theShapes.clear();
if (theMCParams!=nullptr) delete theMCParams;
if (theTopology!=nullptr) delete theTopology;
}


void HcalShapes::beginRun(edm::EventSetup const & es)
{
edm::ESHandle<HcalMCParams> p;
es.get<HcalMCParamsRcd>().get(p);
theMCParams = new HcalMCParams(*p.product());

// here we are making a _copy_ so we need to add a copy of the topology...

edm::ESHandle<HcalTopology> htopo;
es.get<HcalRecNumberingRecord>().get(htopo);
theTopology=new HcalTopology(*htopo);
theMCParams->setTopo(theTopology);
}


void HcalShapes::endRun()
{
if (theMCParams) delete theMCParams;
theMCParams = nullptr;
if (theTopology) delete theTopology;
theTopology = nullptr;
}


const CaloVShape * HcalShapes::shape(const DetId & detId, bool precise) const
{
if(!theMCParams) {
if(!theDbService) {
return defaultShape(detId);
}
int shapeType = theMCParams->getValues(detId)->signalShape();
int shapeType = theDbService->getHcalMCParam(detId)->signalShape();
const auto& myShapes = getShapeMap(precise);
auto shapeMapItr = myShapes.find(shapeType);
if(shapeMapItr == myShapes.end()) {
Expand Down
8 changes: 6 additions & 2 deletions SimCalorimetry/HcalSimProducers/interface/HcalDigitizer.h
Expand Up @@ -15,6 +15,9 @@
#include "DataFormats/HcalCalibObjects/interface/HFRecalibration.h"
#include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
#include "CalibCalorimetry/HcalAlgos/interface/HcalTimeSlew.h"
#include "FWCore/Framework/interface/ESWatcher.h"
#include "Geometry/Records/interface/CaloGeometryRecord.h"
#include "Geometry/Records/interface/HcalRecNumberingRecord.h"

#include <vector>

Expand Down Expand Up @@ -50,8 +53,6 @@ class HcalDigitizer
void accumulate(edm::Event const& e, edm::EventSetup const& c, CLHEP::HepRandomEngine*);
void accumulate(PileUpEventPrincipal const& e, edm::EventSetup const& c, CLHEP::HepRandomEngine*);
void finalizeEvent(edm::Event& e, edm::EventSetup const& c, CLHEP::HepRandomEngine*);
void beginRun(const edm::EventSetup & es);
void endRun();

void setHBHENoiseSignalGenerator(HcalBaseSignalGenerator * noiseGenerator);
void setHFNoiseSignalGenerator(HcalBaseSignalGenerator * noiseGenerator);
Expand All @@ -61,13 +62,16 @@ class HcalDigitizer
void setQIE11NoiseSignalGenerator(HcalBaseSignalGenerator * noiseGenerator);

private:
void setup(const edm::EventSetup & es);
void accumulateCaloHits(edm::Handle<std::vector<PCaloHit> > const& hcalHits, edm::Handle<std::vector<PCaloHit> > const& zdcHits, int bunchCrossing, CLHEP::HepRandomEngine*, const HcalTopology *h);

/// some hits in each subdetector, just for testing purposes
void fillFakeHits();
/// make sure the digitizer has the correct list of all cells that
/// exist in the geometry
void checkGeometry(const edm::EventSetup& eventSetup);
edm::ESWatcher<CaloGeometryRecord> theGeometryWatcher_;
edm::ESWatcher<HcalRecNumberingRecord> theRecNumberWatcher_;
const CaloGeometry * theGeometry;
const HcalDDDRecConstants * theRecNumber;
void updateGeometry(const edm::EventSetup& eventSetup);
Expand Down
8 changes: 2 additions & 6 deletions SimCalorimetry/HcalSimProducers/src/HcalDigiProducer.cc
Expand Up @@ -50,14 +50,10 @@ HcalDigiProducer::accumulate(PileUpEventPrincipal const& event, edm::EventSetup
}

void
HcalDigiProducer::beginRun(edm::Run const&, edm::EventSetup const& es) {
theDigitizer_.beginRun(es);
}
HcalDigiProducer::beginRun(edm::Run const&, edm::EventSetup const& es) {}

void
HcalDigiProducer::endRun(edm::Run const&, edm::EventSetup const&) {
theDigitizer_.endRun();
}
HcalDigiProducer::endRun(edm::Run const&, edm::EventSetup const&) {}

void
HcalDigiProducer::setHBHENoiseSignalGenerator(HcalBaseSignalGenerator * noiseGenerator) {
Expand Down
36 changes: 17 additions & 19 deletions SimCalorimetry/HcalSimProducers/src/HcalDigitizer.cc
Expand Up @@ -21,7 +21,6 @@
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "SimCalorimetry/CaloSimAlgos/interface/CaloTDigitizer.h"
#include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
#include "Geometry/Records/interface/CaloGeometryRecord.h"
#include "CalibFormats/HcalObjects/interface/HcalDbService.h"
#include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
#include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"
Expand Down Expand Up @@ -296,10 +295,14 @@ void HcalDigitizer::setZDCNoiseSignalGenerator(HcalBaseSignalGenerator * noiseGe
}

void HcalDigitizer::initializeEvent(edm::Event const& e, edm::EventSetup const& eventSetup) {
setup(eventSetup);

// get the appropriate gains, noises, & widths for this event
edm::ESHandle<HcalDbService> conditions;
eventSetup.get<HcalDbRecord>().get(conditions);

theShapes->setDbService(conditions.product());

theHBHEAmplifier->setDbService(conditions.product());
theHFAmplifier->setDbService(conditions.product());
theHOAmplifier->setDbService(conditions.product());
Expand Down Expand Up @@ -528,9 +531,8 @@ void HcalDigitizer::finalizeEvent(edm::Event& e, const edm::EventSetup& eventSet
}


void HcalDigitizer::beginRun(const edm::EventSetup & es) {
void HcalDigitizer::setup(const edm::EventSetup & es) {
checkGeometry(es);
theShapes->beginRun(es);

if (agingFlagHB) {
edm::ESHandle<HBHEDarkening> hdark;
Expand All @@ -554,28 +556,14 @@ void HcalDigitizer::beginRun(const edm::EventSetup & es) {
}


void HcalDigitizer::endRun() {
theShapes->endRun();
}


void HcalDigitizer::checkGeometry(const edm::EventSetup & eventSetup) {
// TODO find a way to avoid doing this every event
edm::ESHandle<CaloGeometry> geometry;
eventSetup.get<CaloGeometryRecord>().get(geometry);
theGeometry = &*geometry;
edm::ESHandle<HcalDDDRecConstants> pHRNDC;
eventSetup.get<HcalRecNumberingRecord>().get(pHRNDC);
theRecNumber= &*pHRNDC;

// See if it's been updated
if (&*geometry != theGeometry) {
theGeometry = &*geometry;
theRecNumber= &*pHRNDC;
updateGeometry(eventSetup);
}
}


void HcalDigitizer::updateGeometry(const edm::EventSetup & eventSetup) {
if(theHBHEResponse) theHBHEResponse->setGeometry(theGeometry);
if(theHBHESiPMResponse) theHBHESiPMResponse->setGeometry(theGeometry);
if(theHOResponse) theHOResponse->setGeometry(theGeometry);
Expand All @@ -585,6 +573,16 @@ void HcalDigitizer::updateGeometry(const edm::EventSetup & eventSetup) {
theZDCResponse->setGeometry(theGeometry);
if(theRelabeller) theRelabeller->setGeometry(theRecNumber);

// See if it's been updated
bool check1 = theGeometryWatcher_.check(eventSetup);
bool check2 = theRecNumberWatcher_.check(eventSetup);
if (check1 or check2) {
updateGeometry(eventSetup);
}
}


void HcalDigitizer::updateGeometry(const edm::EventSetup & eventSetup) {
const std::vector<DetId>& hbCells = theGeometry->getValidDetIds(DetId::Hcal, HcalBarrel);
const std::vector<DetId>& heCells = theGeometry->getValidDetIds(DetId::Hcal, HcalEndcap);
const std::vector<DetId>& hoCells = theGeometry->getValidDetIds(DetId::Hcal, HcalOuter);
Expand Down

0 comments on commit 58a31df

Please sign in to comment.