File indexing completed on 2024-10-19 04:58:39
0001 #include "ZdcHitReconstructor_Run3.h"
0002 #include "DataFormats/Common/interface/EDCollection.h"
0003 #include "DataFormats/Common/interface/Handle.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0007 #include "CalibFormats/HcalObjects/interface/HcalCoderDb.h"
0008 #include "CalibFormats/HcalObjects/interface/HcalCalibrations.h"
0009 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
0010 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
0011 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalSeverityLevelComputer.h"
0012 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalSeverityLevelComputerRcd.h"
0013 #include "Geometry/CaloTopology/interface/HcalTopology.h"
0014
0015 #include <iostream>
0016
0017 #include <Eigen/Dense>
0018
0019 #include <vector>
0020 namespace zdchelper {
0021 void setZDCSaturation(ZDCRecHit& rh, QIE10DataFrame& digi, int maxValue) {
0022 for (int i = 0; i < digi.samples(); i++) {
0023 if (digi[i].adc() >= maxValue) {
0024 rh.setFlagField(1, HcalCaloFlagLabels::ADCSaturationBit);
0025 break;
0026 }
0027 }
0028 }
0029
0030 }
0031
0032 ZdcHitReconstructor_Run3::ZdcHitReconstructor_Run3(edm::ParameterSet const& conf)
0033
0034 : reco_(conf.getParameter<int>("recoMethod")),
0035 saturationFlagSetter_(nullptr),
0036 det_(DetId::Hcal),
0037 correctionMethodEM_(conf.getParameter<int>("correctionMethodEM")),
0038 correctionMethodHAD_(conf.getParameter<int>("correctionMethodHAD")),
0039 correctionMethodRPD_(conf.getParameter<int>("correctionMethodRPD")),
0040 ootpuRatioEM_(conf.getParameter<double>("ootpuRatioEM")),
0041 ootpuRatioHAD_(conf.getParameter<double>("ootpuRatioHAD")),
0042 ootpuRatioRPD_(conf.getParameter<double>("ootpuRatioRPD")),
0043 ootpuFracEM_(conf.getParameter<double>("ootpuFracEM")),
0044 ootpuFracHAD_(conf.getParameter<double>("ootpuFracHAD")),
0045 ootpuFracRPD_(conf.getParameter<double>("ootpuFracRPD")),
0046 chargeRatiosEM_(conf.getParameter<std::vector<double>>("chargeRatiosEM")),
0047 chargeRatiosHAD_(conf.getParameter<std::vector<double>>("chargeRatiosHAD")),
0048 chargeRatiosRPD_(conf.getParameter<std::vector<double>>("chargeRatiosRPD")),
0049 bxTs_(conf.getParameter<std::vector<unsigned int>>("bxTs")),
0050 nTs_(conf.getParameter<int>("nTs")),
0051 forceSOI_(conf.getParameter<bool>("forceSOI")),
0052 signalSOI_(conf.getParameter<std::vector<unsigned int>>("signalSOI")),
0053 noiseSOI_(conf.getParameter<std::vector<unsigned int>>("noiseSOI")),
0054 setSaturationFlags_(conf.getParameter<bool>("setSaturationFlags")),
0055 dropZSmarkedPassed_(conf.getParameter<bool>("dropZSmarkedPassed")),
0056 skipRPD_(conf.getParameter<bool>("skipRPD")) {
0057 tok_input_QIE10 = consumes<QIE10DigiCollection>(conf.getParameter<edm::InputTag>("digiLabelQIE10ZDC"));
0058
0059 std::string subd = conf.getParameter<std::string>("Subdetector");
0060
0061 if (setSaturationFlags_) {
0062 const edm::ParameterSet& pssat = conf.getParameter<edm::ParameterSet>("saturationParameters");
0063 maxADCvalue_ = pssat.getParameter<int>("maxADCvalue");
0064 }
0065 if (!strcasecmp(subd.c_str(), "ZDC")) {
0066 det_ = DetId::Calo;
0067 subdet_ = HcalZDCDetId::SubdetectorId;
0068 produces<ZDCRecHitCollection>();
0069 } else if (!strcasecmp(subd.c_str(), "CALIB")) {
0070 subdet_ = HcalOther;
0071 subdetOther_ = HcalCalibration;
0072 produces<HcalCalibRecHitCollection>();
0073 } else {
0074 std::cout << "ZdcHitReconstructor_Run3 is not associated with a specific subdetector!" << std::endl;
0075 }
0076 reco_.initCorrectionMethod(correctionMethodEM_, 1);
0077 reco_.initCorrectionMethod(correctionMethodHAD_, 2);
0078 reco_.initCorrectionMethod(correctionMethodRPD_, 4);
0079 reco_.initTemplateFit(bxTs_, chargeRatiosEM_, nTs_, 1);
0080 reco_.initTemplateFit(bxTs_, chargeRatiosHAD_, nTs_, 2);
0081 reco_.initTemplateFit(bxTs_, chargeRatiosRPD_, nTs_, 4);
0082 reco_.initRatioSubtraction(ootpuRatioEM_, ootpuFracEM_, 1);
0083 reco_.initRatioSubtraction(ootpuRatioHAD_, ootpuFracHAD_, 2);
0084 reco_.initRatioSubtraction(ootpuRatioRPD_, ootpuFracRPD_, 4);
0085
0086 htopoToken_ = esConsumes<HcalTopology, HcalRecNumberingRecord, edm::Transition::BeginRun>();
0087 paramsToken_ = esConsumes<HcalLongRecoParams, HcalLongRecoParamsRcd, edm::Transition::BeginRun>();
0088 conditionsToken_ = esConsumes<HcalDbService, HcalDbRecord>();
0089 qualToken_ = esConsumes<HcalChannelQuality, HcalChannelQualityRcd>(edm::ESInputTag("", "withTopo"));
0090 sevToken_ = esConsumes<HcalSeverityLevelComputer, HcalSeverityLevelComputerRcd>();
0091 }
0092
0093 ZdcHitReconstructor_Run3::~ZdcHitReconstructor_Run3() { delete saturationFlagSetter_; }
0094
0095 void ZdcHitReconstructor_Run3::beginRun(edm::Run const& r, edm::EventSetup const& es) {
0096 const HcalTopology& htopo = es.getData(htopoToken_);
0097 const HcalLongRecoParams& p = es.getData(paramsToken_);
0098 longRecoParams_ = std::make_unique<HcalLongRecoParams>(p);
0099 longRecoParams_->setTopo(&htopo);
0100 }
0101
0102 void ZdcHitReconstructor_Run3::endRun(edm::Run const& r, edm::EventSetup const& es) {}
0103
0104 void ZdcHitReconstructor_Run3::produce(edm::Event& e, const edm::EventSetup& eventSetup) {
0105
0106 const HcalDbService* conditions = &eventSetup.getData(conditionsToken_);
0107 const HcalChannelQuality* myqual = &eventSetup.getData(qualToken_);
0108 const HcalSeverityLevelComputer* mySeverity = &eventSetup.getData(sevToken_);
0109
0110
0111 std::vector<unsigned int> mySignalTS;
0112 std::vector<unsigned int> myNoiseTS;
0113
0114 if (det_ == DetId::Calo && subdet_ == HcalZDCDetId::SubdetectorId) {
0115 edm::Handle<QIE10DigiCollection> digi;
0116 e.getByToken(tok_input_QIE10, digi);
0117
0118
0119 auto rec = std::make_unique<ZDCRecHitCollection>();
0120 rec->reserve(digi->size());
0121
0122
0123 for (auto it = digi->begin(); it != digi->end(); it++) {
0124 QIE10DataFrame QIE10_i = static_cast<QIE10DataFrame>(*it);
0125 HcalZDCDetId cell = QIE10_i.id();
0126 bool isRPD = cell.section() == 4;
0127 if (isRPD && skipRPD_)
0128 continue;
0129 if (cell.section() == 1 && cell.channel() > 5)
0130 continue;
0131
0132 DetId detcell = (DetId)cell;
0133
0134
0135 const HcalChannelStatus* mydigistatus = myqual->getValues(detcell.rawId());
0136 if (mySeverity->dropChannel(mydigistatus->getValue()))
0137 continue;
0138 if (dropZSmarkedPassed_)
0139 if (QIE10_i.zsMarkAndPass())
0140 continue;
0141
0142 const HcalCalibrations& calibrations = conditions->getHcalCalibrations(cell);
0143 const HcalQIECoder* channelCoder = conditions->getHcalCoder(cell);
0144 const HcalQIEShape* shape = conditions->getHcalShape(channelCoder);
0145 HcalCoderDb coder(*channelCoder, *shape);
0146
0147
0148 const HcalPedestal* effPeds = conditions->getEffectivePedestal(cell);
0149
0150 if (forceSOI_)
0151 rec->push_back(reco_.reconstruct(QIE10_i, noiseSOI_, signalSOI_, coder, calibrations, *effPeds));
0152
0153 else {
0154 const HcalLongRecoParam* myParams = longRecoParams_->getValues(detcell);
0155 mySignalTS.clear();
0156 myNoiseTS.clear();
0157 mySignalTS = myParams->signalTS();
0158 myNoiseTS = myParams->noiseTS();
0159
0160 rec->push_back(reco_.reconstruct(QIE10_i, myNoiseTS, mySignalTS, coder, calibrations, *effPeds));
0161 }
0162
0163
0164 (rec->back()).setFlags(0);
0165 if (setSaturationFlags_)
0166 zdchelper::setZDCSaturation(rec->back(), QIE10_i, maxADCvalue_);
0167 }
0168
0169 e.put(std::move(rec));
0170 }
0171
0172 }
0173
0174 void ZdcHitReconstructor_Run3::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0175
0176 edm::ParameterSetDescription desc;
0177 desc.add<edm::InputTag>("digiLabelQIE10ZDC", edm::InputTag("hcalDigis", "ZDC"));
0178 desc.add<std::string>("Subdetector", "ZDC");
0179 desc.add<bool>("dropZSmarkedPassed", true);
0180 desc.add<bool>("skipRPD", true);
0181 desc.add<int>("recoMethod", 1);
0182 desc.add<int>("correctionMethodEM", 1);
0183 desc.add<int>("correctionMethodHAD", 1);
0184 desc.add<int>("correctionMethodRPD", 0);
0185 desc.add<double>("ootpuRatioEM", 3.0);
0186 desc.add<double>("ootpuRatioHAD", 3.0);
0187 desc.add<double>("ootpuRatioRPD", -1.0);
0188 desc.add<double>("ootpuFracEM", 1.0);
0189 desc.add<double>("ootpuFracHAD", 1.0);
0190 desc.add<double>("ootpuFracRPD", 0.0);
0191 desc.add<std::vector<double>>("chargeRatiosEM",
0192 {
0193 1.0,
0194 0.23157,
0195 0.10477,
0196 0.06312,
0197 });
0198 desc.add<std::vector<double>>("chargeRatiosHAD",
0199 {
0200 1.0,
0201 0.23157,
0202 0.10477,
0203 0.06312,
0204 });
0205 desc.add<std::vector<double>>("chargeRatiosRPD",
0206 {
0207 1.0,
0208 0.23157,
0209 0.10477,
0210 0.06312,
0211 });
0212 desc.add<std::vector<unsigned int>>("bxTs",
0213 {
0214 0,
0215 2,
0216 4,
0217 });
0218 desc.add<int>("nTs", 6);
0219 desc.add<bool>("forceSOI", false);
0220 desc.add<std::vector<unsigned int>>("signalSOI",
0221 {
0222 2,
0223 });
0224 desc.add<std::vector<unsigned int>>("noiseSOI",
0225 {
0226 1,
0227 });
0228 desc.add<bool>("setSaturationFlags", true);
0229 {
0230 edm::ParameterSetDescription psd0;
0231 psd0.add<int>("maxADCvalue", 255);
0232 desc.add<edm::ParameterSetDescription>("saturationParameters", psd0);
0233 }
0234 descriptions.add("zdcrecoRun3", desc);
0235
0236
0237 }
0238
0239
0240 DEFINE_FWK_MODULE(ZdcHitReconstructor_Run3);