File indexing completed on 2023-03-17 11:18:56
0001 #include "ZdcSimpleReconstructor.h"
0002 #include "DataFormats/Common/interface/EDCollection.h"
0003 #include "DataFormats/Common/interface/Handle.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "CalibFormats/HcalObjects/interface/HcalCoderDb.h"
0006 #include "CalibFormats/HcalObjects/interface/HcalCalibrations.h"
0007 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
0008 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
0009 #include "Geometry/CaloTopology/interface/HcalTopology.h"
0010
0011 #include <iostream>
0012
0013 ZdcSimpleReconstructor::ZdcSimpleReconstructor(edm::ParameterSet const& conf)
0014 : reco_(conf.getParameter<bool>("correctForTimeslew"),
0015 conf.getParameter<bool>("correctForPhaseContainment"),
0016 conf.getParameter<double>("correctionPhaseNS"),
0017 conf.getParameter<int>("recoMethod"),
0018 conf.getParameter<int>("lowGainOffset"),
0019 conf.getParameter<double>("lowGainFrac")),
0020 det_(DetId::Hcal),
0021 dropZSmarkedPassed_(conf.getParameter<bool>("dropZSmarkedPassed")) {
0022 tok_input_castor = consumes<ZDCDigiCollection>(conf.getParameter<edm::InputTag>("digiLabelcastor"));
0023 tok_input_hcal = consumes<ZDCDigiCollection>(conf.getParameter<edm::InputTag>("digiLabelhcal"));
0024
0025 std::string subd = conf.getParameter<std::string>("Subdetector");
0026 if (!strcasecmp(subd.c_str(), "ZDC")) {
0027 det_ = DetId::Calo;
0028 subdet_ = HcalZDCDetId::SubdetectorId;
0029 produces<ZDCRecHitCollection>();
0030 } else if (!strcasecmp(subd.c_str(), "CALIB")) {
0031 subdet_ = HcalOther;
0032 subdetOther_ = HcalCalibration;
0033 produces<HcalCalibRecHitCollection>();
0034 } else {
0035 std::cout << "ZdcSimpleReconstructor is not associated with a specific subdetector!" << std::endl;
0036 }
0037
0038 hcalTimeSlew_delay_ = nullptr;
0039
0040
0041 htopoToken_ = esConsumes<HcalTopology, HcalRecNumberingRecord, edm::Transition::BeginRun>();
0042 paramsToken_ = esConsumes<HcalLongRecoParams, HcalLongRecoParamsRcd, edm::Transition::BeginRun>();
0043 conditionsToken_ = esConsumes<HcalDbService, HcalDbRecord>();
0044 timeSlewToken_ = esConsumes<HcalTimeSlew, HcalTimeSlewRecord>(edm::ESInputTag("", "HBHE"));
0045 }
0046
0047 ZdcSimpleReconstructor::~ZdcSimpleReconstructor() {}
0048
0049 void ZdcSimpleReconstructor::beginRun(edm::Run const& r, edm::EventSetup const& es) {
0050 const HcalTopology& htopo = es.getData(htopoToken_);
0051 const HcalLongRecoParams& p = es.getData(paramsToken_);
0052 longRecoParams_ = std::make_unique<HcalLongRecoParams>(p);
0053 longRecoParams_->setTopo(&htopo);
0054
0055 hcalTimeSlew_delay_ = &es.getData(timeSlewToken_);
0056 }
0057
0058 void ZdcSimpleReconstructor::endRun(edm::Run const& r, edm::EventSetup const& es) {}
0059
0060 void ZdcSimpleReconstructor::produce(edm::Event& e, const edm::EventSetup& eventSetup) {
0061
0062 const HcalDbService* conditions = &eventSetup.getData(conditionsToken_);
0063
0064
0065 std::vector<unsigned int> mySignalTS;
0066 std::vector<unsigned int> myNoiseTS;
0067
0068 if (det_ == DetId::Calo && subdet_ == HcalZDCDetId::SubdetectorId) {
0069 edm::Handle<ZDCDigiCollection> digi;
0070 e.getByToken(tok_input_hcal, digi);
0071
0072 if (digi->empty()) {
0073 e.getByToken(tok_input_castor, digi);
0074 if (digi->empty())
0075 edm::LogInfo("ZdcHitReconstructor") << "No ZDC info found in either castorDigis or hcalDigis." << std::endl;
0076 }
0077
0078
0079 auto rec = std::make_unique<ZDCRecHitCollection>();
0080 rec->reserve(digi->size());
0081
0082 unsigned int toaddMem = 0;
0083
0084 ZDCDigiCollection::const_iterator i;
0085 for (i = digi->begin(); i != digi->end(); i++) {
0086 HcalZDCDetId cell = i->id();
0087 DetId detcell = (DetId)cell;
0088
0089 if (dropZSmarkedPassed_)
0090 if (i->zsMarkAndPass())
0091 continue;
0092
0093
0094 const HcalLongRecoParam* myParams = longRecoParams_->getValues(detcell);
0095 mySignalTS.clear();
0096 myNoiseTS.clear();
0097 mySignalTS = myParams->signalTS();
0098 myNoiseTS = myParams->noiseTS();
0099
0100
0101 unsigned int toadd = mySignalTS.size();
0102 if (toaddMem != toadd) {
0103 reco_.initPulseCorr(toadd, hcalTimeSlew_delay_);
0104 toaddMem = toadd;
0105 }
0106 const HcalCalibrations& calibrations = conditions->getHcalCalibrations(cell);
0107 const HcalQIECoder* channelCoder = conditions->getHcalCoder(cell);
0108 const HcalQIEShape* shape = conditions->getHcalShape(channelCoder);
0109 HcalCoderDb coder(*channelCoder, *shape);
0110 rec->push_back(reco_.reconstruct(*i, myNoiseTS, mySignalTS, coder, calibrations));
0111 }
0112
0113 e.put(std::move(rec));
0114 }
0115 }