Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-16 23:02:06

0001 // -*- C++ -*-
0002 //
0003 // Package:    RecHitCorrector
0004 // Class:      RecHitCorrector
0005 //
0006 /**\class RecHitCorrector RecHitCorrector.cc RecoLocalCalo/Castor/src/RecHitCorrector.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Hans Van Haevermaet
0015 //         Created:  Wed Feb 23 11:29:43 CET 2011
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
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 // class declaration
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   // ----------member data ---------------------------
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 // constants, enums and typedefs
0063 //
0064 
0065 //
0066 // static data member definitions
0067 //
0068 
0069 //
0070 // constructors and destructor
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   //register your products
0079   produces<CastorRecHitCollection>();
0080   //now do what ever other initialization is needed
0081 }
0082 
0083 RecHitCorrector::~RecHitCorrector() {
0084   // do anything here that needs to be done at desctruction time
0085   // (e.g. close files, deallocate resources etc.)
0086 }
0087 
0088 //
0089 // member functions
0090 //
0091 
0092 // ------------ method called to produce the data  ------------
0093 void RecHitCorrector::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0094   using namespace edm;
0095 
0096   // get original rechits
0097   edm::Handle<CastorRecHitCollection> rechits;
0098   iEvent.getByToken(tok_input_, rechits);
0099 
0100   // get conditions
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       // do proper gain calibration reading the latest entries in the condDB
0118       const CastorCalibrations& calibrations = conditions->getCastorCalibrations(rechit.id());
0119       int capid = 0;  // take some capid, gains are the same for all capid's
0120       correctedenergy *= calibrations.gain(capid);
0121     }
0122 
0123     // now check the channelquality of this rechit
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;  // 2989 = BAD
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 //define this as a plug-in
0148 DEFINE_FWK_MODULE(RecHitCorrector);