Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-21 04:25:51

0001 #include "CalibFormats/CastorObjects/interface/CastorCalibrations.h"
0002 #include "CalibFormats/CastorObjects/interface/CastorCoderDb.h"
0003 #include "CalibFormats/CastorObjects/interface/CastorDbRecord.h"
0004 #include "CalibFormats/CastorObjects/interface/CastorDbService.h"
0005 #include "CondFormats/CastorObjects/interface/CastorChannelQuality.h"
0006 #include "CondFormats/CastorObjects/interface/CastorChannelStatus.h"
0007 #include "CondFormats/CastorObjects/interface/CastorRecoParams.h"
0008 #include "CondFormats/CastorObjects/interface/CastorSaturationCorrs.h"
0009 #include "CondFormats/DataRecord/interface/CastorChannelQualityRcd.h"
0010 #include "CondFormats/DataRecord/interface/CastorRecoParamsRcd.h"
0011 #include "CondFormats/DataRecord/interface/CastorSaturationCorrsRcd.h"
0012 #include "DataFormats/Common/interface/EDCollection.h"
0013 #include "DataFormats/Common/interface/Handle.h"
0014 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
0015 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
0016 #include "DataFormats/METReco/interface/HcalCaloFlagLabels.h"
0017 #include "FWCore/Framework/interface/ESHandle.h"
0018 #include "FWCore/Framework/interface/Event.h"
0019 #include "FWCore/Framework/interface/EventSetup.h"
0020 #include "FWCore/Framework/interface/stream/EDProducer.h"
0021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0023 #include "FWCore/Utilities/interface/ESGetToken.h"
0024 #include "RecoLocalCalo/CastorReco/interface/CastorSimpleRecAlgo.h"
0025 
0026 #include <iostream>
0027 
0028 class CastorSimpleReconstructor : public edm::stream::EDProducer<> {
0029 public:
0030   explicit CastorSimpleReconstructor(const edm::ParameterSet& ps);
0031   ~CastorSimpleReconstructor() override;
0032   void produce(edm::Event& e, const edm::EventSetup& c) override;
0033 
0034 private:
0035   CastorSimpleRecAlgo reco_;
0036   DetId::Detector det_;
0037   int subdet_;
0038   //      HcalOtherSubdetector subdetOther_;
0039   edm::EDGetTokenT<CastorDigiCollection> tok_input_;
0040   edm::ESGetToken<CastorDbService, CastorDbRecord> tok_conditions_;
0041   edm::ESGetToken<CastorRecoParams, CastorRecoParamsRcd> tok_recoParams_;
0042   edm::ESGetToken<CastorSaturationCorrs, CastorSaturationCorrsRcd> tok_satCorr_;
0043 
0044   int firstSample_;
0045   int samplesToAdd_;
0046   int maxADCvalue_;
0047   bool tsFromDB_;
0048   bool setSaturationFlag_;
0049   bool doSaturationCorr_;
0050 };
0051 
0052 #include "FWCore/Framework/interface/MakerMacros.h"
0053 DEFINE_FWK_MODULE(CastorSimpleReconstructor);
0054 
0055 using namespace std;
0056 
0057 CastorSimpleReconstructor::CastorSimpleReconstructor(edm::ParameterSet const& conf)
0058     : reco_(conf.getParameter<int>("firstSample"),
0059             conf.getParameter<int>("samplesToAdd"),
0060             conf.getParameter<bool>("correctForTimeslew"),
0061             conf.getParameter<bool>("correctForPhaseContainment"),
0062             conf.getParameter<double>("correctionPhaseNS")),
0063       det_(DetId::Hcal),
0064       firstSample_(conf.getParameter<int>("firstSample")),
0065       samplesToAdd_(conf.getParameter<int>("samplesToAdd")),
0066       maxADCvalue_(conf.getParameter<int>("maxADCvalue")),
0067       tsFromDB_(conf.getParameter<bool>("tsFromDB")),
0068       setSaturationFlag_(conf.getParameter<bool>("setSaturationFlag")),
0069       doSaturationCorr_(conf.getParameter<bool>("doSaturationCorr")) {
0070   tok_input_ = consumes<CastorDigiCollection>(conf.getParameter<edm::InputTag>("digiLabel"));
0071   tok_conditions_ = esConsumes<CastorDbService, CastorDbRecord>();
0072 
0073   std::string subd = conf.getParameter<std::string>("Subdetector");
0074   if (!strcasecmp(subd.c_str(), "CASTOR")) {
0075     det_ = DetId::Calo;
0076     subdet_ = HcalCastorDetId::SubdetectorId;
0077     produces<CastorRecHitCollection>();
0078   } else {
0079     edm::LogWarning("CastorSimpleReconstructor")
0080         << "CastorSimpleReconstructor is not associated with CASTOR subdetector!" << std::endl;
0081   }
0082   if (tsFromDB_) {
0083     tok_recoParams_ = esConsumes<CastorRecoParams, CastorRecoParamsRcd>();
0084   }
0085   if (doSaturationCorr_) {
0086     tok_satCorr_ = esConsumes<CastorSaturationCorrs, CastorSaturationCorrsRcd>();
0087   }
0088 }
0089 
0090 CastorSimpleReconstructor::~CastorSimpleReconstructor() {}
0091 
0092 void CastorSimpleReconstructor::produce(edm::Event& e, const edm::EventSetup& eventSetup) {
0093   // get conditions
0094   edm::ESHandle<CastorDbService> conditions = eventSetup.getHandle(tok_conditions_);
0095   const CastorQIEShape* shape = conditions->getCastorShape();  // this one is generic
0096 
0097   CastorCalibrations calibrations;
0098 
0099   // try to get the TS windows from the db
0100   edm::ESHandle<CastorRecoParams> recoparams;
0101   if (tsFromDB_) {
0102     recoparams = eventSetup.getHandle(tok_recoParams_);
0103     if (!recoparams.isValid()) {
0104       tsFromDB_ = false;
0105       edm::LogWarning("CastorSimpleReconstructor")
0106           << "Could not handle the CastorRecoParamsRcd correctly, using parameters from cfg file from this event "
0107              "onwards... These parameters could be wrong for this run... please check"
0108           << std::endl;
0109     }
0110   }
0111 
0112   // try to get the saturation correction constants from the db
0113   edm::ESHandle<CastorSaturationCorrs> satcorr;
0114   if (doSaturationCorr_) {
0115     satcorr = eventSetup.getHandle(tok_satCorr_);
0116     if (!satcorr.isValid()) {
0117       doSaturationCorr_ = false;
0118       edm::LogWarning("CastorSimpleReconstructor") << "Could not handle the CastorSaturationCorrsRcd correctly. We'll "
0119                                                       "not try the saturation correction from this event onwards..."
0120                                                    << std::endl;
0121     }
0122   }
0123 
0124   if (det_ == DetId::Calo && subdet_ == HcalCastorDetId::SubdetectorId) {
0125     edm::Handle<CastorDigiCollection> digi;
0126     e.getByToken(tok_input_, digi);
0127 
0128     // create empty output
0129     auto rec = std::make_unique<CastorRecHitCollection>();
0130     // run the algorithm
0131     CastorDigiCollection::const_iterator i;
0132     for (i = digi->begin(); i != digi->end(); i++) {
0133       HcalCastorDetId cell = i->id();
0134       DetId detcell = (DetId)cell;
0135       const CastorCalibrations& calibrations = conditions->getCastorCalibrations(cell);
0136 
0137       if (tsFromDB_) {
0138         const CastorRecoParam* param_ts = recoparams->getValues(detcell.rawId());
0139         reco_.resetTimeSamples(param_ts->firstSample(), param_ts->samplesToAdd());
0140       }
0141       const CastorQIECoder* channelCoder = conditions->getCastorCoder(cell);
0142       CastorCoderDb coder(*channelCoder, *shape);
0143 
0144       // reconstruct the rechit
0145       rec->push_back(reco_.reconstruct(*i, coder, calibrations));
0146 
0147       // set the saturation flag if needed
0148       if (setSaturationFlag_) {
0149         reco_.checkADCSaturation(rec->back(), *i, maxADCvalue_);
0150 
0151         //++++ Saturation Correction +++++
0152         if (doSaturationCorr_ && rec->back().flagField(HcalCaloFlagLabels::ADCSaturationBit)) {
0153           // get saturation correction value
0154           const CastorSaturationCorr* saturationCorr = satcorr->getValues(detcell.rawId());
0155           double satCorrConst = 1.;
0156           satCorrConst = saturationCorr->getValue();
0157           reco_.recoverADCSaturation(rec->back(), coder, calibrations, *i, maxADCvalue_, satCorrConst);
0158         }
0159       }
0160     }
0161     // return result
0162     e.put(std::move(rec));
0163   }
0164 }