File indexing completed on 2024-04-06 12:25:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021
0022
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/stream/EDProducer.h"
0025
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 #include "FWCore/Framework/interface/EventSetup.h"
0029
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031
0032 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
0033 #include "CalibFormats/CastorObjects/interface/CastorCoderDb.h"
0034 #include "CalibFormats/CastorObjects/interface/CastorCalibrations.h"
0035 #include "CalibFormats/CastorObjects/interface/CastorDbService.h"
0036 #include "CalibFormats/CastorObjects/interface/CastorDbRecord.h"
0037 #include "CondFormats/CastorObjects/interface/CastorChannelQuality.h"
0038 #include "CondFormats/CastorObjects/interface/CastorChannelStatus.h"
0039 #include "CondFormats/DataRecord/interface/CastorChannelQualityRcd.h"
0040
0041
0042
0043
0044
0045 class RecHitCorrector : public edm::stream::EDProducer<> {
0046 public:
0047 explicit RecHitCorrector(const edm::ParameterSet&);
0048 ~RecHitCorrector() override;
0049
0050 private:
0051 void produce(edm::Event&, const edm::EventSetup&) override;
0052
0053
0054 const edm::ESGetToken<CastorDbService, CastorDbRecord> tokCond_;
0055 const edm::ESGetToken<CastorChannelQuality, CastorChannelQualityRcd> tokChan_;
0056 const double factor_;
0057 const bool doInterCalib_;
0058 edm::EDGetTokenT<CastorRecHitCollection> tok_input_;
0059 };
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072 RecHitCorrector::RecHitCorrector(const edm::ParameterSet& iConfig)
0073 : tokCond_(esConsumes<CastorDbService, CastorDbRecord>()),
0074 tokChan_(esConsumes<CastorChannelQuality, CastorChannelQualityRcd>()),
0075 factor_(iConfig.getParameter<double>("revertFactor")),
0076 doInterCalib_(iConfig.getParameter<bool>("doInterCalib")) {
0077 tok_input_ = consumes<CastorRecHitCollection>(iConfig.getParameter<edm::InputTag>("rechitLabel"));
0078
0079 produces<CastorRecHitCollection>();
0080
0081 }
0082
0083 RecHitCorrector::~RecHitCorrector() {
0084
0085
0086 }
0087
0088
0089
0090
0091
0092
0093 void RecHitCorrector::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0094 using namespace edm;
0095
0096
0097 edm::Handle<CastorRecHitCollection> rechits;
0098 iEvent.getByToken(tok_input_, rechits);
0099
0100
0101 const CastorDbService* conditions = &iSetup.getData(tokCond_);
0102 const CastorChannelQuality* myqual = &iSetup.getData(tokChan_);
0103
0104 if (!rechits.isValid())
0105 edm::LogWarning("CastorRecHitCorrector") << "No valid CastorRecHitCollection found, please check the InputLabel...";
0106
0107 CastorCalibrations calibrations;
0108
0109 auto rec = std::make_unique<CastorRecHitCollection>();
0110
0111 for (unsigned int i = 0; i < rechits->size(); i++) {
0112 CastorRecHit rechit = (*rechits)[i];
0113 double time = rechit.time();
0114 double correctedenergy = factor_ * rechit.energy();
0115
0116 if (doInterCalib_) {
0117
0118 const CastorCalibrations& calibrations = conditions->getCastorCalibrations(rechit.id());
0119 int capid = 0;
0120 correctedenergy *= calibrations.gain(capid);
0121 }
0122
0123
0124 bool ok = true;
0125 DetId detcell = (DetId)rechit.id();
0126 std::vector<DetId> channels = myqual->getAllChannels();
0127 for (auto channel : channels) {
0128 if (channel.rawId() == detcell.rawId()) {
0129 const CastorChannelStatus* mydigistatus = myqual->getValues(channel);
0130 if (mydigistatus->getValue() == 2989) {
0131 ok = false;
0132 break;
0133 }
0134 }
0135 }
0136
0137 if (ok) {
0138 rec->emplace_back(rechit.id(), correctedenergy, time);
0139 }
0140 }
0141
0142 iEvent.put(std::move(rec));
0143
0144 delete myqual;
0145 }
0146
0147
0148 DEFINE_FWK_MODULE(RecHitCorrector);