File indexing completed on 2024-04-06 12:29:35
0001
0002
0003
0004
0005
0006 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
0007 #include "DataFormats/Common/interface/EDCollection.h"
0008 #include "DataFormats/Common/interface/Handle.h"
0009 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/Framework/interface/stream/EDProducer.h"
0012 #include "FWCore/Framework/interface/ESHandle.h"
0013 #include "FWCore/Framework/interface/EventSetup.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 #include "FWCore/Utilities/interface/ESGetToken.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 #include "FWCore/Utilities/interface/Exception.h"
0018 #include "SimCalorimetry/HcalZeroSuppressionProducers/interface/HcalZSAlgoRealistic.h"
0019
0020 #include <iostream>
0021 #include <memory>
0022 #include <string>
0023
0024 class HcalRealisticZS : public edm::stream::EDProducer<> {
0025 public:
0026 explicit HcalRealisticZS(const edm::ParameterSet &ps);
0027 ~HcalRealisticZS() override;
0028 void produce(edm::Event &e, const edm::EventSetup &c) override;
0029
0030 private:
0031 std::unique_ptr<HcalZSAlgoRealistic> algo_;
0032 std::string inputLabel_;
0033 edm::EDGetTokenT<HBHEDigiCollection> tok_hbhe_;
0034 edm::EDGetTokenT<HODigiCollection> tok_ho_;
0035 edm::EDGetTokenT<HFDigiCollection> tok_hf_;
0036 edm::EDGetTokenT<QIE10DigiCollection> tok_hfQIE10_;
0037 edm::EDGetTokenT<QIE11DigiCollection> tok_hbheQIE11_;
0038 edm::ESGetToken<HcalDbService, HcalDbRecord> tok_dbService_;
0039 };
0040
0041 HcalRealisticZS::HcalRealisticZS(edm::ParameterSet const &conf)
0042 : inputLabel_(conf.getParameter<std::string>("digiLabel")) {
0043 bool markAndPass = conf.getParameter<bool>("markAndPass");
0044 bool useInstanceLabels = conf.getParameter<bool>("useInstanceLabels");
0045
0046
0047 tok_hbhe_ = consumes<HBHEDigiCollection>(edm::InputTag(inputLabel_));
0048 tok_ho_ = consumes<HODigiCollection>(edm::InputTag(inputLabel_));
0049 tok_hf_ = consumes<HFDigiCollection>(edm::InputTag(inputLabel_));
0050 tok_hfQIE10_ =
0051 consumes<QIE10DigiCollection>(edm::InputTag(inputLabel_, useInstanceLabels ? "HFQIE10DigiCollection" : ""));
0052 tok_hbheQIE11_ =
0053 consumes<QIE11DigiCollection>(edm::InputTag(inputLabel_, useInstanceLabels ? "HBHEQIE11DigiCollection" : ""));
0054 tok_dbService_ = esConsumes<HcalDbService, HcalDbRecord>();
0055
0056 bool use1ts_ = conf.getParameter<bool>("use1ts");
0057
0058 std::vector<int> tmp = conf.getParameter<std::vector<int>>("HBregion");
0059
0060 if (tmp[0] < 0 || tmp[0] > 9 || tmp[1] < 0 || tmp[1] > 9 || tmp[0] > tmp[1]) {
0061 edm::LogError("HcalZeroSuppression") << "ZS(HB) region error: " << tmp[0] << ":" << tmp[1];
0062 tmp[0] = 0;
0063 tmp[1] = 9;
0064 }
0065
0066 std::pair<int, int> HBsearchTS(tmp[0], tmp[1]);
0067
0068 tmp = conf.getParameter<std::vector<int>>("HEregion");
0069 if (tmp[0] < 0 || tmp[0] > 9 || tmp[1] < 0 || tmp[1] > 9 || tmp[0] > tmp[1]) {
0070 edm::LogError("HcalZeroSuppression") << "ZS(HE) region error: " << tmp[0] << ":" << tmp[1];
0071 tmp[0] = 0;
0072 tmp[1] = 9;
0073 }
0074 std::pair<int, int> HEsearchTS(tmp[0], tmp[1]);
0075
0076 tmp = conf.getParameter<std::vector<int>>("HOregion");
0077 if (tmp[0] < 0 || tmp[0] > 9 || tmp[1] < 0 || tmp[1] > 9 || tmp[0] > tmp[1]) {
0078 edm::LogError("HcalZeroSuppression") << "ZS(HO) region error: " << tmp[0] << ":" << tmp[1];
0079 tmp[0] = 0;
0080 tmp[1] = 9;
0081 }
0082 std::pair<int, int> HOsearchTS(tmp[0], tmp[1]);
0083
0084 tmp = conf.getParameter<std::vector<int>>("HFregion");
0085 if (tmp[0] < 0 || tmp[0] > 9 || tmp[1] < 0 || tmp[1] > 9 || tmp[0] > tmp[1]) {
0086 edm::LogError("HcalZeroSuppression") << "ZS(HF) region error: " << tmp[0] << ":" << tmp[1];
0087 tmp[0] = 0;
0088 tmp[1] = 9;
0089 }
0090 std::pair<int, int> HFsearchTS(tmp[0], tmp[1]);
0091
0092
0093
0094
0095 if (conf.getParameter<int>("useConfigZSvalues")) {
0096 algo_ = std::make_unique<HcalZSAlgoRealistic>(markAndPass,
0097 use1ts_,
0098 conf.getParameter<int>("HBlevel"),
0099 conf.getParameter<int>("HElevel"),
0100 conf.getParameter<int>("HOlevel"),
0101 conf.getParameter<int>("HFlevel"),
0102 HBsearchTS,
0103 HEsearchTS,
0104 HOsearchTS,
0105 HFsearchTS);
0106
0107 } else {
0108 algo_ = std::make_unique<HcalZSAlgoRealistic>(markAndPass, use1ts_, HBsearchTS, HEsearchTS, HOsearchTS, HFsearchTS);
0109 }
0110
0111 produces<HBHEDigiCollection>();
0112 produces<HODigiCollection>();
0113 produces<HFDigiCollection>();
0114 produces<QIE10DigiCollection>("HFQIE10DigiCollection");
0115 produces<QIE11DigiCollection>("HBHEQIE11DigiCollection");
0116 }
0117
0118 HcalRealisticZS::~HcalRealisticZS() { algo_->clearDbService(); }
0119
0120 void HcalRealisticZS::produce(edm::Event &e, const edm::EventSetup &eventSetup) {
0121 edm::Handle<HBHEDigiCollection> hbhe;
0122 edm::Handle<HODigiCollection> ho;
0123 edm::Handle<HFDigiCollection> hf;
0124 edm::Handle<QIE10DigiCollection> hfQIE10;
0125 edm::Handle<QIE11DigiCollection> hbheQIE11;
0126
0127 edm::ESHandle<HcalDbService> conditions = eventSetup.getHandle(tok_dbService_);
0128 algo_->setDbService(conditions.product());
0129
0130 e.getByToken(tok_hbhe_, hbhe);
0131
0132
0133 std::unique_ptr<HBHEDigiCollection> zs_hbhe(new HBHEDigiCollection);
0134
0135 e.getByToken(tok_ho_, ho);
0136
0137
0138 std::unique_ptr<HODigiCollection> zs_ho(new HODigiCollection);
0139
0140 e.getByToken(tok_hf_, hf);
0141
0142
0143 std::unique_ptr<HFDigiCollection> zs_hf(new HFDigiCollection);
0144
0145 e.getByToken(tok_hfQIE10_, hfQIE10);
0146 e.getByToken(tok_hbheQIE11_, hbheQIE11);
0147
0148
0149 std::unique_ptr<HBHEDigiCollection> zs_hbheUpgrade(new HBHEDigiCollection);
0150 std::unique_ptr<HFDigiCollection> zs_hfUpgrade(new HFDigiCollection);
0151 std::unique_ptr<QIE10DigiCollection> zs_hfQIE10(new QIE10DigiCollection(hfQIE10->samples()));
0152 std::unique_ptr<QIE11DigiCollection> zs_hbheQIE11(new QIE11DigiCollection(hbheQIE11->samples()));
0153
0154
0155 algo_->suppress(*(hbhe.product()), *zs_hbhe);
0156 algo_->suppress(*(ho.product()), *zs_ho);
0157 algo_->suppress(*(hf.product()), *zs_hf);
0158 algo_->suppress(*(hfQIE10.product()), *zs_hfQIE10);
0159 algo_->suppress(*(hbheQIE11.product()), *zs_hbheQIE11);
0160
0161 edm::LogInfo("HcalZeroSuppression") << "Suppression (HBHE) input " << hbhe->size() << " digis, output "
0162 << zs_hbhe->size() << " digis"
0163 << " (HO) input " << ho->size() << " digis, output " << zs_ho->size() << " digis"
0164 << " (HF) input " << hf->size() << " digis, output " << zs_hf->size() << " digis"
0165 << " (HFQIE10) input " << hfQIE10->size() << " digis, output "
0166 << zs_hfQIE10->size() << " digis"
0167 << " (HBHEQIE11) input " << hbheQIE11->size() << " digis, output "
0168 << zs_hbheQIE11->size() << " digis";
0169
0170
0171 e.put(std::move(zs_hbhe));
0172 e.put(std::move(zs_ho));
0173 e.put(std::move(zs_hf));
0174 e.put(std::move(zs_hfQIE10), "HFQIE10DigiCollection");
0175 e.put(std::move(zs_hbheQIE11), "HBHEQIE11DigiCollection");
0176 }
0177
0178 #include "FWCore/Framework/interface/MakerMacros.h"
0179 #include "FWCore/PluginManager/interface/ModuleDef.h"
0180
0181 DEFINE_FWK_MODULE(HcalRealisticZS);