File indexing completed on 2024-04-06 12:29:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include "FWCore/Framework/interface/Frameworkfwd.h"
0018
0019 #include "FWCore/Framework/interface/Event.h"
0020 #include "FWCore/Framework/interface/MakerMacros.h"
0021 #include "FWCore/Framework/interface/stream/EDProducer.h"
0022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0024 #include "FWCore/Utilities/interface/EDGetToken.h"
0025 #include "FWCore/Utilities/interface/InputTag.h"
0026
0027 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0028 #include "DataFormats/Provenance/interface/ParameterSetID.h"
0029 #include "DataFormats/Provenance/interface/ProductID.h"
0030 #include "DataFormats/Provenance/interface/Provenance.h"
0031
0032 #include "CondFormats/DataRecord/interface/EcalTPGCrystalStatusRcd.h"
0033 #include "CondFormats/DataRecord/interface/EcalTPGFineGrainEBGroupRcd.h"
0034 #include "CondFormats/DataRecord/interface/EcalTPGFineGrainEBIdMapRcd.h"
0035 #include "CondFormats/DataRecord/interface/EcalTPGFineGrainStripEERcd.h"
0036 #include "CondFormats/DataRecord/interface/EcalTPGFineGrainTowerEERcd.h"
0037 #include "CondFormats/DataRecord/interface/EcalTPGLinearizationConstRcd.h"
0038 #include "CondFormats/DataRecord/interface/EcalTPGLutGroupRcd.h"
0039 #include "CondFormats/DataRecord/interface/EcalTPGLutIdMapRcd.h"
0040 #include "CondFormats/DataRecord/interface/EcalTPGPedestalsRcd.h"
0041 #include "CondFormats/DataRecord/interface/EcalTPGSlidingWindowRcd.h"
0042 #include "CondFormats/DataRecord/interface/EcalTPGSpikeRcd.h"
0043 #include "CondFormats/DataRecord/interface/EcalTPGStripStatusRcd.h"
0044 #include "CondFormats/DataRecord/interface/EcalTPGTowerStatusRcd.h"
0045 #include "CondFormats/DataRecord/interface/EcalTPGWeightGroupRcd.h"
0046 #include "CondFormats/DataRecord/interface/EcalTPGWeightIdMapRcd.h"
0047 #include "CondFormats/DataRecord/interface/EcalTPGOddWeightGroupRcd.h"
0048 #include "CondFormats/DataRecord/interface/EcalTPGOddWeightIdMapRcd.h"
0049 #include "CondFormats/DataRecord/interface/EcalTPGTPModeRcd.h"
0050 #include "CondFormats/DataRecord/interface/EcalTPGPedestalsRcd.h"
0051 #include "CondFormats/EcalObjects/interface/EcalTPGCrystalStatus.h"
0052 #include "CondFormats/EcalObjects/interface/EcalTPGFineGrainEBGroup.h"
0053 #include "CondFormats/EcalObjects/interface/EcalTPGFineGrainEBIdMap.h"
0054 #include "CondFormats/EcalObjects/interface/EcalTPGFineGrainStripEE.h"
0055 #include "CondFormats/EcalObjects/interface/EcalTPGFineGrainTowerEE.h"
0056 #include "CondFormats/EcalObjects/interface/EcalTPGLinearizationConst.h"
0057 #include "CondFormats/EcalObjects/interface/EcalTPGLutGroup.h"
0058 #include "CondFormats/EcalObjects/interface/EcalTPGLutIdMap.h"
0059 #include "CondFormats/EcalObjects/interface/EcalTPGPedestals.h"
0060 #include "CondFormats/EcalObjects/interface/EcalTPGSlidingWindow.h"
0061 #include "CondFormats/EcalObjects/interface/EcalTPGSpike.h"
0062 #include "CondFormats/EcalObjects/interface/EcalTPGStripStatus.h"
0063 #include "CondFormats/EcalObjects/interface/EcalTPGTowerStatus.h"
0064 #include "CondFormats/EcalObjects/interface/EcalTPGWeightGroup.h"
0065 #include "CondFormats/EcalObjects/interface/EcalTPGWeightIdMap.h"
0066 #include "CondFormats/EcalObjects/interface/EcalTPGOddWeightGroup.h"
0067 #include "CondFormats/EcalObjects/interface/EcalTPGOddWeightIdMap.h"
0068 #include "CondFormats/EcalObjects/interface/EcalTPGTPMode.h"
0069
0070 #include "Geometry/EcalMapping/interface/EcalMappingRcd.h"
0071 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0072
0073 #include <memory>
0074
0075 #include "SimCalorimetry/EcalTrigPrimAlgos/interface/EcalTrigPrimFunctionalAlgo.h"
0076
0077 class EcalTrigPrimProducer : public edm::stream::EDProducer<> {
0078 public:
0079 explicit EcalTrigPrimProducer(const edm::ParameterSet &conf);
0080
0081 ~EcalTrigPrimProducer() override;
0082
0083 void beginRun(const edm::Run &run, const edm::EventSetup &es) override;
0084 void endRun(const edm::Run &, const edm::EventSetup &) override;
0085 void produce(edm::Event &e, const edm::EventSetup &c) override;
0086
0087 static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
0088
0089 private:
0090 std::unique_ptr<EcalTrigPrimFunctionalAlgo> algo_;
0091 bool barrelOnly_;
0092 bool tcpFormat_;
0093 bool debug_;
0094 bool famos_;
0095 bool tpInfoPrintout_;
0096 edm::EDGetTokenT<EBDigiCollection> tokenEB_;
0097 edm::EDGetTokenT<EEDigiCollection> tokenEE_;
0098
0099 const edm::ESGetToken<EcalElectronicsMapping, EcalMappingRcd> tokenEcalMapping_;
0100
0101 edm::ESGetToken<CaloSubdetectorGeometry, EcalEndcapGeometryRecord> tokenEndcapGeom_;
0102 edm::ESGetToken<EcalTrigTowerConstituentsMap, IdealGeometryRecord> tokenETTMap_;
0103
0104
0105
0106 edm::ESGetToken<EcalTPGLinearizationConst, EcalTPGLinearizationConstRcd> tokenEcalTPGLinearization_;
0107 edm::ESGetToken<EcalTPGPedestals, EcalTPGPedestalsRcd> tokenEcalTPGPedestals_;
0108 edm::ESGetToken<EcalTPGCrystalStatus, EcalTPGCrystalStatusRcd> tokenEcalTPGCrystalStatus_;
0109
0110
0111 edm::ESGetToken<EcalTPGSlidingWindow, EcalTPGSlidingWindowRcd> tokenEcalTPGSlidingWindow_;
0112 edm::ESGetToken<EcalTPGWeightIdMap, EcalTPGWeightIdMapRcd> tokenEcalTPGWeightIdMap_;
0113 edm::ESGetToken<EcalTPGWeightGroup, EcalTPGWeightGroupRcd> tokenEcalTPGWeightGroup_;
0114 edm::ESGetToken<EcalTPGOddWeightIdMap, EcalTPGOddWeightIdMapRcd> tokenEcalTPGOddWeightIdMap_;
0115 edm::ESGetToken<EcalTPGOddWeightGroup, EcalTPGOddWeightGroupRcd> tokenEcalTPGOddWeightGroup_;
0116 edm::ESGetToken<EcalTPGFineGrainStripEE, EcalTPGFineGrainStripEERcd> tokenEcalTPGFineGrainStripEE_;
0117 edm::ESGetToken<EcalTPGStripStatus, EcalTPGStripStatusRcd> tokenEcalTPGStripStatus_;
0118
0119
0120
0121 edm::ESGetToken<EcalTPGFineGrainEBGroup, EcalTPGFineGrainEBGroupRcd> tokenEcalTPGFineGrainEBGroup_;
0122 edm::ESGetToken<EcalTPGLutGroup, EcalTPGLutGroupRcd> tokenEcalTPGLutGroup_;
0123 edm::ESGetToken<EcalTPGLutIdMap, EcalTPGLutIdMapRcd> tokenEcalTPGLutIdMap_;
0124 edm::ESGetToken<EcalTPGFineGrainEBIdMap, EcalTPGFineGrainEBIdMapRcd> tokenEcalTPGFineGrainEBIdMap_;
0125 edm::ESGetToken<EcalTPGFineGrainTowerEE, EcalTPGFineGrainTowerEERcd> tokenEcalTPGFineGrainTowerEE_;
0126 edm::ESGetToken<EcalTPGTowerStatus, EcalTPGTowerStatusRcd> tokenEcalTPGTowerStatus_;
0127 edm::ESGetToken<EcalTPGSpike, EcalTPGSpikeRcd> tokenEcalTPGSpike_;
0128
0129 edm::ESGetToken<EcalTPGTPMode, EcalTPGTPModeRcd> tokenEcalTPGTPMode_;
0130
0131 int binOfMaximum_;
0132 bool fillBinOfMaximumFromHistory_;
0133
0134
0135 unsigned long long getRecords(edm::EventSetup const &setup);
0136 unsigned long long cacheID_;
0137 };
0138
0139 EcalTrigPrimProducer::EcalTrigPrimProducer(const edm::ParameterSet &iConfig)
0140 : barrelOnly_(iConfig.getParameter<bool>("BarrelOnly")),
0141 tcpFormat_(iConfig.getParameter<bool>("TcpOutput")),
0142 debug_(iConfig.getParameter<bool>("Debug")),
0143 famos_(iConfig.getParameter<bool>("Famos")),
0144 tpInfoPrintout_(iConfig.getParameter<bool>("TPinfoPrintout")),
0145 tokenEB_(consumes<EBDigiCollection>(
0146 edm::InputTag(iConfig.getParameter<std::string>("Label"), iConfig.getParameter<std::string>("InstanceEB")))),
0147 tokenEE_(consumes<EEDigiCollection>(
0148 edm::InputTag(iConfig.getParameter<std::string>("Label"), iConfig.getParameter<std::string>("InstanceEE")))),
0149 tokenEcalMapping_(esConsumes<edm::Transition::BeginRun>()),
0150 tokenEcalTPGLinearization_(esConsumes()),
0151 tokenEcalTPGPedestals_(esConsumes()),
0152 tokenEcalTPGCrystalStatus_(esConsumes()),
0153 tokenEcalTPGSlidingWindow_(esConsumes()),
0154 tokenEcalTPGWeightIdMap_(esConsumes()),
0155 tokenEcalTPGWeightGroup_(esConsumes()),
0156 tokenEcalTPGOddWeightIdMap_(esConsumes()),
0157 tokenEcalTPGOddWeightGroup_(esConsumes()),
0158 tokenEcalTPGFineGrainStripEE_(esConsumes()),
0159 tokenEcalTPGStripStatus_(esConsumes()),
0160 tokenEcalTPGFineGrainEBGroup_(esConsumes()),
0161 tokenEcalTPGLutGroup_(esConsumes()),
0162 tokenEcalTPGLutIdMap_(esConsumes()),
0163 tokenEcalTPGFineGrainEBIdMap_(esConsumes()),
0164 tokenEcalTPGFineGrainTowerEE_(esConsumes()),
0165 tokenEcalTPGTowerStatus_(esConsumes()),
0166 tokenEcalTPGSpike_(esConsumes()),
0167 tokenEcalTPGTPMode_(esConsumes()),
0168 binOfMaximum_(iConfig.getParameter<int>("binOfMaximum")),
0169 fillBinOfMaximumFromHistory_(-1 == binOfMaximum_),
0170 cacheID_(0) {
0171
0172 produces<EcalTrigPrimDigiCollection>();
0173 if (tcpFormat_)
0174 produces<EcalTrigPrimDigiCollection>("formatTCP");
0175 if (not barrelOnly_) {
0176 tokenEndcapGeom_ = esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", "EcalEndcap"));
0177 tokenETTMap_ = esConsumes<edm::Transition::BeginRun>();
0178 }
0179 }
0180
0181 static int findBinOfMaximum(bool iFillFromHistory, int iPSetValue, edm::ProcessHistory const &iHistory) {
0182
0183
0184
0185 int binOfMaximum = 0;
0186 if (not iFillFromHistory) {
0187 binOfMaximum = iPSetValue;
0188 edm::LogInfo("EcalTPG") << "EcalTrigPrimProducer is using binOfMaximum found in cfg file : " << binOfMaximum;
0189 }
0190
0191
0192 const std::string kModuleName{"ecalUnsuppressedDigis"};
0193 for (auto it = iHistory.rbegin(), itEnd = iHistory.rend(); it != itEnd; ++it) {
0194 auto const &topLevelPSet = getParameterSet(it->parameterSetID());
0195 if (topLevelPSet.exists(kModuleName)) {
0196 int psetBinOfMax = topLevelPSet.getParameter<edm::ParameterSet>(kModuleName).getParameter<int>("binOfMaximum");
0197
0198 if (not iFillFromHistory) {
0199 if (psetBinOfMax != binOfMaximum)
0200 edm::LogWarning("EcalTPG") << "binofMaximum given in configuration (=" << binOfMaximum
0201 << ") is different from the one found in ProductRegistration(=" << psetBinOfMax
0202 << ")!!!";
0203 } else {
0204 binOfMaximum = psetBinOfMax;
0205 edm::LogInfo("EcalTPG") << "EcalTrigPrimProducer is using binOfMaximum "
0206 "found in ProductRegistry : "
0207 << binOfMaximum;
0208 }
0209 break;
0210 }
0211 }
0212 if (binOfMaximum == 0) {
0213 binOfMaximum = 6;
0214 edm::LogWarning("EcalTPG") << "Could not find product registry of EBDigiCollection (label "
0215 "ecalUnsuppressedDigis), had to set the following parameters by "
0216 "Hand: binOfMaximum="
0217 << binOfMaximum;
0218 }
0219 return binOfMaximum;
0220 }
0221
0222 void EcalTrigPrimProducer::beginRun(edm::Run const &run, edm::EventSetup const &setup) {
0223
0224 binOfMaximum_ = findBinOfMaximum(fillBinOfMaximumFromHistory_, binOfMaximum_, run.processHistory());
0225
0226 auto const &ecalmapping = setup.getData(tokenEcalMapping_);
0227 if (barrelOnly_) {
0228 algo_ = std::make_unique<EcalTrigPrimFunctionalAlgo>(
0229 &ecalmapping, binOfMaximum_, tcpFormat_, debug_, famos_, tpInfoPrintout_);
0230 } else {
0231 auto const &endcapGeometry = setup.getData(tokenEndcapGeom_);
0232 auto const &eTTmap = setup.getData(tokenETTMap_);
0233 algo_ = std::make_unique<EcalTrigPrimFunctionalAlgo>(
0234 &eTTmap, &endcapGeometry, &ecalmapping, binOfMaximum_, tcpFormat_, debug_, famos_, tpInfoPrintout_);
0235 }
0236 }
0237
0238 void EcalTrigPrimProducer::endRun(edm::Run const &run, edm::EventSetup const &setup) {
0239 algo_.reset();
0240 cacheID_ = 0;
0241 }
0242
0243 unsigned long long EcalTrigPrimProducer::getRecords(edm::EventSetup const &setup) {
0244
0245
0246
0247
0248 const EcalTPGLinearizationConst *ecaltpLin = &setup.getData(tokenEcalTPGLinearization_);
0249 const EcalTPGPedestals *ecaltpPed = &setup.getData(tokenEcalTPGPedestals_);
0250 const EcalTPGCrystalStatus *ecaltpgBadX = &setup.getData(tokenEcalTPGCrystalStatus_);
0251
0252
0253 const EcalTPGSlidingWindow *ecaltpgSlidW = &setup.getData(tokenEcalTPGSlidingWindow_);
0254 const EcalTPGWeightIdMap *ecaltpgWeightMap = &setup.getData(tokenEcalTPGWeightIdMap_);
0255 const EcalTPGWeightGroup *ecaltpgWeightGroup = &setup.getData(tokenEcalTPGWeightGroup_);
0256 const EcalTPGOddWeightIdMap *ecaltpgOddWeightMap = &setup.getData(tokenEcalTPGOddWeightIdMap_);
0257 const EcalTPGOddWeightGroup *ecaltpgOddWeightGroup = &setup.getData(tokenEcalTPGOddWeightGroup_);
0258 const EcalTPGFineGrainStripEE *ecaltpgFgStripEE = &setup.getData(tokenEcalTPGFineGrainStripEE_);
0259 const EcalTPGStripStatus *ecaltpgStripStatus = &setup.getData(tokenEcalTPGStripStatus_);
0260 const EcalTPGTPMode *ecaltpgTPMode = &setup.getData(tokenEcalTPGTPMode_);
0261
0262 algo_->setPointers(ecaltpLin,
0263 ecaltpPed,
0264 ecaltpgSlidW,
0265 ecaltpgWeightMap,
0266 ecaltpgWeightGroup,
0267 ecaltpgOddWeightMap,
0268 ecaltpgOddWeightGroup,
0269 ecaltpgFgStripEE,
0270 ecaltpgBadX,
0271 ecaltpgStripStatus,
0272 ecaltpgTPMode);
0273
0274
0275
0276 const EcalTPGFineGrainEBGroup *ecaltpgFgEBGroup = &setup.getData(tokenEcalTPGFineGrainEBGroup_);
0277 const EcalTPGLutGroup *ecaltpgLutGroup = &setup.getData(tokenEcalTPGLutGroup_);
0278 const EcalTPGLutIdMap *ecaltpgLut = &setup.getData(tokenEcalTPGLutIdMap_);
0279 const EcalTPGFineGrainEBIdMap *ecaltpgFineGrainEB = &setup.getData(tokenEcalTPGFineGrainEBIdMap_);
0280 const EcalTPGFineGrainTowerEE *ecaltpgFineGrainTowerEE = &setup.getData(tokenEcalTPGFineGrainTowerEE_);
0281 const EcalTPGTowerStatus *ecaltpgBadTT = &setup.getData(tokenEcalTPGTowerStatus_);
0282 const EcalTPGSpike *ecaltpgSpike = &setup.getData(tokenEcalTPGSpike_);
0283
0284 algo_->setPointers2(ecaltpgFgEBGroup,
0285 ecaltpgLutGroup,
0286 ecaltpgLut,
0287 ecaltpgFineGrainEB,
0288 ecaltpgFineGrainTowerEE,
0289 ecaltpgBadTT,
0290 ecaltpgSpike,
0291 ecaltpgTPMode);
0292
0293
0294
0295 return setup.get<EcalTPGLinearizationConstRcd>().cacheIdentifier();
0296 }
0297
0298 EcalTrigPrimProducer::~EcalTrigPrimProducer() {}
0299
0300
0301 void EcalTrigPrimProducer::produce(edm::Event &e, const edm::EventSetup &iSetup) {
0302
0303 if (iSetup.get<EcalTPGLinearizationConstRcd>().cacheIdentifier() != cacheID_)
0304 cacheID_ = this->getRecords(iSetup);
0305
0306
0307
0308 edm::Handle<EBDigiCollection> ebDigis;
0309 edm::Handle<EEDigiCollection> eeDigis;
0310 bool barrel = true;
0311 bool endcap = true;
0312 if (barrelOnly_)
0313 endcap = false;
0314
0315 if (!e.getByToken(tokenEB_, ebDigis)) {
0316 barrel = false;
0317 edm::EDConsumerBase::Labels labels;
0318 labelsForToken(tokenEB_, labels);
0319 edm::LogWarning("EcalTPG") << " Couldnt find Barrel dataframes with producer " << labels.module << " and label "
0320 << labels.productInstance << "!!!";
0321 }
0322 if (!barrelOnly_) {
0323 if (!e.getByToken(tokenEE_, eeDigis)) {
0324 endcap = false;
0325 edm::EDConsumerBase::Labels labels;
0326 labelsForToken(tokenEE_, labels);
0327 edm::LogWarning("EcalTPG") << " Couldnt find Endcap dataframes with producer " << labels.module << " and label "
0328 << labels.productInstance << "!!!";
0329 }
0330 }
0331 if (!barrel && !endcap) {
0332 edm::EDConsumerBase::Labels labels;
0333 labelsForToken(tokenEB_, labels);
0334 throw cms::Exception(" ProductNotFound") << "No EBDataFrames(EEDataFrames) with producer " << labels.module
0335 << " and label " << labels.productInstance << " found in input!!\n";
0336 }
0337
0338 if (!barrelOnly_)
0339 LogDebug("EcalTPG") << " =================> Treating event " << e.id() << ", Number of EBDataFrames "
0340 << ebDigis.product()->size() << ", Number of EEDataFrames " << eeDigis.product()->size();
0341 else
0342 LogDebug("EcalTPG") << " =================> Treating event " << e.id() << ", Number of EBDataFrames "
0343 << ebDigis.product()->size();
0344
0345 auto pOut = std::make_unique<EcalTrigPrimDigiCollection>();
0346 auto pOutTcp = std::make_unique<EcalTrigPrimDigiCollection>();
0347
0348
0349
0350 const EBDigiCollection *ebdc = nullptr;
0351 const EEDigiCollection *eedc = nullptr;
0352 if (barrel) {
0353 ebdc = ebDigis.product();
0354 algo_->run(ebdc, *pOut, *pOutTcp);
0355 }
0356
0357 if (endcap) {
0358 eedc = eeDigis.product();
0359 algo_->run(eedc, *pOut, *pOutTcp);
0360 }
0361
0362 edm::LogInfo("produce") << "For Barrel + Endcap, " << pOut->size() << " TP Digis were produced";
0363
0364
0365
0366 for (unsigned int i = 0; i < pOut->size(); ++i) {
0367 bool print = false;
0368 for (int isam = 0; isam < (*pOut)[i].size(); ++isam) {
0369 if ((*pOut)[i][isam].raw())
0370 print = true;
0371 }
0372 if (print)
0373 LogDebug("EcalTPG") << " For tower " << (((*pOut)[i])).id() << ", TP is " << (*pOut)[i];
0374 }
0375 if (barrelOnly_)
0376 LogDebug("EcalTPG") << "\n =================> For Barrel , " << pOut->size()
0377 << " TP Digis were produced (including zero ones)";
0378 else
0379 LogDebug("EcalTPG") << "\n =================> For Barrel + Endcap, " << pOut->size()
0380 << " TP Digis were produced (including zero ones)";
0381
0382
0383
0384 e.put(std::move(pOut));
0385 if (tcpFormat_)
0386 e.put(std::move(pOutTcp), "formatTCP");
0387 }
0388
0389 void EcalTrigPrimProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0390 edm::ParameterSetDescription desc;
0391 desc.add<bool>("BarrelOnly", false);
0392 desc.add<bool>("TcpOutput", false);
0393 desc.add<bool>("Debug", false);
0394 desc.add<bool>("Famos", false);
0395 desc.add<std::string>("Label", "simEcalUnsuppressedDigis");
0396 desc.add<std::string>("InstanceEB", "");
0397 desc.add<std::string>("InstanceEE", "");
0398 const std::string kComment(
0399 "A value of -1 will make the module lookup the value of 'binOfMaximum' "
0400 "from the module 'ecalUnsuppressedDigis' from the process history. "
0401 "Allowed values are -1 and from 1-10.");
0402
0403
0404 desc.add<int>("binOfMaximum", -1)->setComment(kComment);
0405 desc.add<bool>("TPinfoPrintout", false);
0406 descriptions.addDefault(desc);
0407 }
0408
0409 DEFINE_FWK_MODULE(EcalTrigPrimProducer);