Skip to content

Commit

Permalink
Migrate (most of) MixingModule and PreMixingModule to EventSetup cons…
Browse files Browse the repository at this point in the history
…umes()

Also do some related refactoring in the digitizer code.
  • Loading branch information
makortel committed Oct 7, 2020
1 parent 69faafb commit cccc646
Show file tree
Hide file tree
Showing 69 changed files with 810 additions and 853 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ class SiPixelGainCalibrationOfflineSimService
: public SiPixelGainCalibrationServicePayloadGetter<SiPixelGainCalibrationOffline,
SiPixelGainCalibrationOfflineSimRcd> {
public:
// For clients not yet migrated to esConsumes
explicit SiPixelGainCalibrationOfflineSimService(const edm::ParameterSet& conf)
: SiPixelGainCalibrationServicePayloadGetter<SiPixelGainCalibrationOffline, SiPixelGainCalibrationOfflineSimRcd>(
conf){};
~SiPixelGainCalibrationOfflineSimService() override{};
: SiPixelGainCalibrationServicePayloadGetter(conf){};
// For clients migrated to esConsumes
explicit SiPixelGainCalibrationOfflineSimService(const edm::ParameterSet& conf, edm::ConsumesCollector iC)
: SiPixelGainCalibrationServicePayloadGetter(conf, iC){};

// pixel granularity
float getPedestal(const uint32_t& detID, const int& col, const int& row) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@

// Framework
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/ESGetToken.h"
#include "FWCore/Utilities/interface/Exception.h"

// Abstract base class provides common interface to different payload getters
Expand Down Expand Up @@ -57,7 +58,10 @@ class SiPixelGainCalibrationServiceBase {
template <class thePayloadObject, class theDBRecordType>
class SiPixelGainCalibrationServicePayloadGetter : public SiPixelGainCalibrationServiceBase {
public:
// For clients not yet migrated to esConsumes
explicit SiPixelGainCalibrationServicePayloadGetter(const edm::ParameterSet& conf);
// For clients migrated to esConsumes
explicit SiPixelGainCalibrationServicePayloadGetter(const edm::ParameterSet& conf, edm::ConsumesCollector iC);
~SiPixelGainCalibrationServicePayloadGetter() override{};

//Abstract methods
Expand Down Expand Up @@ -94,7 +98,9 @@ class SiPixelGainCalibrationServicePayloadGetter : public SiPixelGainCalibration

edm::ParameterSet conf_;
bool ESetupInit_;
edm::ESHandle<thePayloadObject> ped;
// TODO: make const when esConsumes migration has finished
edm::ESGetToken<thePayloadObject, theDBRecordType> pedToken_;
const thePayloadObject* ped = nullptr;
int numberOfRowsAveragedOver_;
double gainLow_;
double gainHigh_;
Expand Down Expand Up @@ -142,10 +148,24 @@ SiPixelGainCalibrationServicePayloadGetter<thePayloadObject, theDBRecordType>::S
oldThisColumnIsNoisyPed_ = false;
}

template <class thePayloadObject, class theDBRecordType>
SiPixelGainCalibrationServicePayloadGetter<thePayloadObject, theDBRecordType>::SiPixelGainCalibrationServicePayloadGetter(
const edm::ParameterSet& conf, edm::ConsumesCollector iC)
: SiPixelGainCalibrationServicePayloadGetter(conf) {
pedToken_ = iC.esConsumes();
}

template <class thePayloadObject, class theDBRecordType>
void SiPixelGainCalibrationServicePayloadGetter<thePayloadObject, theDBRecordType>::setESObjects(
const edm::EventSetup& es) {
es.get<theDBRecordType>().get(ped);
if (pedToken_.isInitialized()) {
ped = &es.getData(pedToken_);
} else {
// assume the caller has not been migrated esConsumes, to be removed later
edm::ESHandle<thePayloadObject> hped;
es.get<theDBRecordType>().get(hped);
ped = hped.product();
}
// ped->initialize(); moved to cond infrastructure
numberOfRowsAveragedOver_ = ped->getNumberOfRowsToAverageOver();
ESetupInit_ = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class SiStripFedZeroSuppression {
void suppress(const std::vector<SiStripDigi>& in,
std::vector<SiStripDigi>& selectedSignal,
uint32_t detId,
edm::ESHandle<SiStripNoises>&,
edm::ESHandle<SiStripThreshold>&);
const SiStripNoises&,
const SiStripThreshold&);
void suppress(const std::vector<SiStripDigi>& in, std::vector<SiStripDigi>& selectedSignal, uint32_t detId);
void suppress(const edm::DetSet<SiStripRawDigi>& in, edm::DetSet<SiStripDigi>& out);
void suppress(const std::vector<int16_t>& in, uint16_t firstAPV, edm::DetSet<SiStripDigi>& out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ void SiStripFedZeroSuppression::init(const edm::EventSetup& es) {
void SiStripFedZeroSuppression::suppress(const std::vector<SiStripDigi>& in,
std::vector<SiStripDigi>& selectedSignal,
uint32_t detID) {
suppress(in, selectedSignal, detID, noiseHandle, thresholdHandle);
suppress(in, selectedSignal, detID, *noiseHandle, *thresholdHandle);
}

void SiStripFedZeroSuppression::suppress(const std::vector<SiStripDigi>& in,
std::vector<SiStripDigi>& selectedSignal,
uint32_t detID,
edm::ESHandle<SiStripNoises>& noiseHandle,
edm::ESHandle<SiStripThreshold>& thresholdHandle) {
const SiStripNoises& noise,
const SiStripThreshold& threshold) {
int i;
int inSize = in.size();
SiStripNoises::Range detNoiseRange = noiseHandle->getRange(detID);
SiStripThreshold::Range detThRange = thresholdHandle->getRange(detID);
SiStripNoises::Range detNoiseRange = noise.getRange(detID);
SiStripThreshold::Range detThRange = threshold.getRange(detID);

// reserving more than needed, but quicker than one at a time
selectedSignal.clear();
Expand All @@ -48,10 +48,9 @@ void SiStripFedZeroSuppression::suppress(const std::vector<SiStripDigi>& in,

adc = in[i].adc();

SiStripThreshold::Data thresholds = thresholdHandle->getData(strip, detThRange);
theFEDlowThresh = static_cast<int16_t>(thresholds.getLth() * noiseHandle->getNoiseFast(strip, detNoiseRange) + 0.5);
theFEDhighThresh =
static_cast<int16_t>(thresholds.getHth() * noiseHandle->getNoiseFast(strip, detNoiseRange) + 0.5);
SiStripThreshold::Data thresholds = threshold.getData(strip, detThRange);
theFEDlowThresh = static_cast<int16_t>(thresholds.getLth() * noise.getNoiseFast(strip, detNoiseRange) + 0.5);
theFEDhighThresh = static_cast<int16_t>(thresholds.getHth() * noise.getNoiseFast(strip, detNoiseRange) + 0.5);

adcPrev = -9999;
adcNext = -9999;
Expand Down Expand Up @@ -80,19 +79,18 @@ void SiStripFedZeroSuppression::suppress(const std::vector<SiStripDigi>& in,
theNextFEDhighThresh = 9999;
} else if (i + 1 < inSize && in[i + 1].strip() == strip + 1) {
adcNext = in[i + 1].adc();
SiStripThreshold::Data thresholds_1 = thresholdHandle->getData(strip + 1, detThRange);
SiStripThreshold::Data thresholds_1 = threshold.getData(strip + 1, detThRange);
theNextFEDlowThresh =
static_cast<int16_t>(thresholds_1.getLth() * noiseHandle->getNoiseFast(strip + 1, detNoiseRange) + 0.5);
static_cast<int16_t>(thresholds_1.getLth() * noise.getNoiseFast(strip + 1, detNoiseRange) + 0.5);
theNextFEDhighThresh =
static_cast<int16_t>(thresholds_1.getHth() * noiseHandle->getNoiseFast(strip + 1, detNoiseRange) + 0.5);
static_cast<int16_t>(thresholds_1.getHth() * noise.getNoiseFast(strip + 1, detNoiseRange) + 0.5);
if (((strip) % 128) == 126) {
adcNext2 = 0;
theNext2FEDlowThresh = 9999;
} else if (i + 2 < inSize && in[i + 2].strip() == strip + 2) {
adcNext2 = in[i + 2].adc();
theNext2FEDlowThresh = static_cast<int16_t>(thresholdHandle->getData(strip + 2, detThRange).getLth() *
noiseHandle->getNoiseFast(strip + 2, detNoiseRange) +
0.5);
theNext2FEDlowThresh = static_cast<int16_t>(
threshold.getData(strip + 2, detThRange).getLth() * noise.getNoiseFast(strip + 2, detNoiseRange) + 0.5);
}
}

Expand All @@ -102,19 +100,18 @@ void SiStripFedZeroSuppression::suppress(const std::vector<SiStripDigi>& in,
thePrevFEDhighThresh = 9999;
} else if (i - 1 >= 0 && in[i - 1].strip() == strip - 1) {
adcPrev = in[i - 1].adc();
SiStripThreshold::Data thresholds_1 = thresholdHandle->getData(strip - 1, detThRange);
SiStripThreshold::Data thresholds_1 = threshold.getData(strip - 1, detThRange);
thePrevFEDlowThresh =
static_cast<int16_t>(thresholds_1.getLth() * noiseHandle->getNoiseFast(strip - 1, detNoiseRange) + 0.5);
static_cast<int16_t>(thresholds_1.getLth() * noise.getNoiseFast(strip - 1, detNoiseRange) + 0.5);
thePrevFEDhighThresh =
static_cast<int16_t>(thresholds_1.getHth() * noiseHandle->getNoiseFast(strip - 1, detNoiseRange) + 0.5);
static_cast<int16_t>(thresholds_1.getHth() * noise.getNoiseFast(strip - 1, detNoiseRange) + 0.5);
if (((strip) % 128) == 1) {
adcPrev2 = 0;
thePrev2FEDlowThresh = 9999;
} else if (i - 2 >= 0 && in[i - 2].strip() == strip - 2) {
adcPrev2 = in[i - 2].adc();
thePrev2FEDlowThresh = static_cast<int16_t>(thresholdHandle->getData(strip - 2, detThRange).getLth() *
noiseHandle->getNoiseFast(strip - 2, detNoiseRange) +
0.5);
thePrev2FEDlowThresh = static_cast<int16_t>(
threshold.getData(strip - 2, detThRange).getLth() * noise.getNoiseFast(strip - 2, detNoiseRange) + 0.5);
}
}

Expand Down
31 changes: 15 additions & 16 deletions SimCalorimetry/CastorSim/plugins/CastorDigiProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
#include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Utilities/interface/RandomNumberGenerator.h"
#include "FWCore/Utilities/interface/StreamID.h"
#include "Geometry/CaloGeometry/interface/CaloGeometry.h"
#include "Geometry/Records/interface/CaloGeometryRecord.h"
#include "SimCalorimetry/CaloSimAlgos/interface/CaloShapeIntegrator.h"
#include "SimCalorimetry/CaloSimAlgos/interface/CaloTDigitizer.h"
#include "SimCalorimetry/CastorSim/plugins/CastorDigiProducer.h"
Expand All @@ -22,7 +20,9 @@
CastorDigiProducer::CastorDigiProducer(const edm::ParameterSet &ps,
edm::ProducesCollector producesCollector,
edm::ConsumesCollector &iC)
: theParameterMap(new CastorSimParameterMap(ps)),
: theConditionsToken(iC.esConsumes()),
theGeometryToken(iC.esConsumes()),
theParameterMap(new CastorSimParameterMap(ps)),
theCastorShape(new CastorShape()),
theCastorIntegratedShape(new CaloShapeIntegrator(theCastorShape)),
theCastorResponse(new CaloHitResponse(theParameterMap, theCastorIntegratedShape)),
Expand Down Expand Up @@ -75,11 +75,10 @@ CastorDigiProducer::~CastorDigiProducer() {

void CastorDigiProducer::initializeEvent(edm::Event const &event, edm::EventSetup const &eventSetup) {
// get the appropriate gains, noises, & widths for this event
edm::ESHandle<CastorDbService> conditions;
eventSetup.get<CastorDbRecord>().get(conditions);
theAmplifier->setDbService(conditions.product());
theCoderFactory->setDbService(conditions.product());
theParameterMap->setDbService(conditions.product());
const CastorDbService *conditions = &eventSetup.getData(theConditionsToken);
theAmplifier->setDbService(conditions);
theCoderFactory->setDbService(conditions);
theParameterMap->setDbService(conditions);

// Cache random number engine
edm::Service<edm::RandomNumberGenerator> rng;
Expand Down Expand Up @@ -156,14 +155,14 @@ void CastorDigiProducer::fillFakeHits() {
}

void CastorDigiProducer::checkGeometry(const edm::EventSetup &eventSetup) {
// TODO find a way to avoid doing this every event
edm::ESHandle<CaloGeometry> geometry;
eventSetup.get<CaloGeometryRecord>().get(geometry);
theCastorResponse->setGeometry(&*geometry);
if (theGeometryWatcher.check(eventSetup)) {
const CaloGeometry *geometry = &eventSetup.getData(theGeometryToken);
theCastorResponse->setGeometry(geometry);

const std::vector<DetId> &castorCells = geometry->getValidDetIds(DetId::Calo, HcalCastorDetId::SubdetectorId);
const std::vector<DetId> &castorCells = geometry->getValidDetIds(DetId::Calo, HcalCastorDetId::SubdetectorId);

// std::cout<<"CastorDigiProducer::CheckGeometry number of cells:
// "<<castorCells.size()<<std::endl;
theCastorDigitizer->setDetIds(castorCells);
// std::cout<<"CastorDigiProducer::CheckGeometry number of cells:
// "<<castorCells.size()<<std::endl;
theCastorDigitizer->setDetIds(castorCells);
}
}
12 changes: 7 additions & 5 deletions SimCalorimetry/CastorSim/plugins/CastorDigiProducer.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#ifndef CastorDigiProducer_h
#define CastorDigiProducer_h

#include "CalibFormats/CastorObjects/interface/CastorDbRecord.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ESWatcher.h"
#include "FWCore/Framework/interface/FrameworkfwdMostUsed.h"
#include "FWCore/Framework/interface/ProducesCollector.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "Geometry/Records/interface/CaloGeometryRecord.h"
#include "SimCalorimetry/CaloSimAlgos/interface/CaloHitResponse.h"
#include "SimCalorimetry/CaloSimAlgos/interface/CaloTDigitizer.h"
#include "SimCalorimetry/CastorSim/src/CastorAmplifier.h"
Expand All @@ -20,11 +24,6 @@

#include <vector>

namespace edm {
class StreamID;
class ConsumesCollector;
} // namespace edm

namespace CLHEP {
class HepRandomEngine;
}
Expand Down Expand Up @@ -54,6 +53,9 @@ class CastorDigiProducer : public DigiAccumulatorMixMod {
void checkGeometry(const edm::EventSetup &eventSetup);

edm::InputTag theHitsProducerTag;
const edm::ESGetToken<CastorDbService, CastorDbRecord> theConditionsToken;
const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> theGeometryToken;
edm::ESWatcher<CaloGeometryRecord> theGeometryWatcher;

/** Reconstruction algorithm*/
typedef CaloTDigitizer<CastorDigitizerTraits> CastorDigitizer;
Expand Down
32 changes: 32 additions & 0 deletions SimCalorimetry/EcalSimProducers/interface/EcalDigiProducer.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
#ifndef SimCalorimetry_EcalSimProducers_EcalDigiProducer_h
#define SimCalorimetry_EcalSimProducers_EcalDigiProducer_h

#include "CalibCalorimetry/EcalLaserCorrection/interface/EcalLaserDbRecord.h"
#include "CalibCalorimetry/EcalLaserCorrection/interface/EcalLaserDbService.h"
#include "CondFormats/DataRecord/interface/EcalADCToGeVConstantRcd.h"
#include "CondFormats/DataRecord/interface/EcalGainRatiosRcd.h"
#include "CondFormats/DataRecord/interface/EcalIntercalibConstantsMCRcd.h"
#include "CondFormats/DataRecord/interface/ESGainRcd.h"
#include "CondFormats/DataRecord/interface/ESIntercalibConstantsRcd.h"
#include "CondFormats/DataRecord/interface/ESMIPToGeVConstantRcd.h"
#include "CondFormats/DataRecord/interface/ESPedestalsRcd.h"
#include "CondFormats/DataRecord/interface/EcalPedestalsRcd.h"
#include "CondFormats/EcalObjects/interface/EcalADCToGeVConstant.h"
#include "CondFormats/EcalObjects/interface/EcalGainRatios.h"
#include "CondFormats/EcalObjects/interface/EcalIntercalibConstantsMC.h"
#include "CondFormats/EcalObjects/interface/EcalPedestals.h"
#include "CondFormats/ESObjects/interface/ESGain.h"
#include "CondFormats/ESObjects/interface/ESIntercalibConstants.h"
#include "CondFormats/ESObjects/interface/ESMIPToGeVConstant.h"
#include "CondFormats/ESObjects/interface/ESPedestals.h"
#include "DataFormats/Math/interface/Error.h"
#include "FWCore/Framework/interface/ESWatcher.h"
#include "FWCore/Framework/interface/ProducesCollector.h"
#include "Geometry/Records/interface/CaloGeometryRecord.h"
#include "SimCalorimetry/EcalSimAlgos/interface/APDShape.h"
#include "SimCalorimetry/EcalSimAlgos/interface/EBShape.h"
#include "SimCalorimetry/EcalSimAlgos/interface/EEShape.h"
Expand Down Expand Up @@ -98,6 +118,18 @@ class EcalDigiProducer : public DigiAccumulatorMixMod {
const std::string m_ESdigiCollection;
const std::string m_hitsProducerTag;

const edm::ESGetToken<EcalPedestals, EcalPedestalsRcd> m_pedestalsToken;
const edm::ESGetToken<EcalIntercalibConstantsMC, EcalIntercalibConstantsMCRcd> m_icalToken;
const edm::ESGetToken<EcalLaserDbService, EcalLaserDbRecord> m_laserToken;
const edm::ESGetToken<EcalADCToGeVConstant, EcalADCToGeVConstantRcd> m_agcToken;
const edm::ESGetToken<EcalGainRatios, EcalGainRatiosRcd> m_grToken;
const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> m_geometryToken;
edm::ESGetToken<ESGain, ESGainRcd> m_esGainToken;
edm::ESGetToken<ESMIPToGeVConstant, ESMIPToGeVConstantRcd> m_esMIPToGeVToken;
edm::ESGetToken<ESPedestals, ESPedestalsRcd> m_esPedestalsToken;
edm::ESGetToken<ESIntercalibConstants, ESIntercalibConstantsRcd> m_esMIPsToken;
edm::ESWatcher<CaloGeometryRecord> m_geometryWatcher;

bool m_useLCcorrection;

const bool m_apdSeparateDigi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@

#include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/Framework/interface/ESWatcher.h"
#include "FWCore/Framework/interface/FrameworkfwdMostUsed.h"
#include "FWCore/Framework/interface/ProducesCollector.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "Geometry/Records/interface/CaloGeometryRecord.h"
#include "SimCalorimetry/EcalSimAlgos/interface/EcalDigitizerTraits.h"
#include "SimDataFormats/CaloHit/interface/PCaloHit.h"
#include "SimGeneral/MixingModule/interface/DigiAccumulatorMixMod.h"
Expand All @@ -21,11 +24,8 @@ class PileUpEventPrincipal;
class EcalTimeMapDigitizer;

namespace edm {
class Event;
class EventSetup;
template <typename T>
class Handle;
class ParameterSet;
} // namespace edm

class EcalTimeDigiProducer : public DigiAccumulatorMixMod {
Expand All @@ -52,6 +52,8 @@ class EcalTimeDigiProducer : public DigiAccumulatorMixMod {
const edm::InputTag m_hitsProducerTagEE;
const edm::EDGetTokenT<std::vector<PCaloHit>> m_hitsProducerTokenEB;
const edm::EDGetTokenT<std::vector<PCaloHit>> m_hitsProducerTokenEE;
const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> m_geometryToken;
edm::ESWatcher<CaloGeometryRecord> m_geometryWatcher;

private:
int m_timeLayerEB;
Expand Down
Loading

0 comments on commit cccc646

Please sign in to comment.