Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:37:35

0001 /** \class EcalUncalibRecHitWorkerAnalFit
0002  *   produce ECAL uncalibrated rechits from dataframes with the analytical fit method
0003  *
0004  *  \author Shahram Rahatlou, University of Rome & INFN, Sept 2005
0005  *
0006  */
0007 
0008 #include "CondFormats/DataRecord/interface/EcalGainRatiosRcd.h"
0009 #include "CondFormats/DataRecord/interface/EcalPedestalsRcd.h"
0010 #include "CondFormats/EcalObjects/interface/EcalGainRatios.h"
0011 #include "CondFormats/EcalObjects/interface/EcalMGPAGainRatio.h"
0012 #include "CondFormats/EcalObjects/interface/EcalPedestals.h"
0013 #include "DataFormats/Common/interface/Handle.h"
0014 #include "DataFormats/EcalDigi/interface/EBDataFrame.h"
0015 #include "DataFormats/EcalDigi/interface/EEDataFrame.h"
0016 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0017 #include "DataFormats/EcalDigi/interface/EcalMGPASample.h"
0018 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0019 #include "DataFormats/EcalRecHit/interface/EcalUncalibratedRecHit.h"
0020 #include "FWCore/Framework/interface/ESHandle.h"
0021 #include "FWCore/Framework/interface/Event.h"
0022 #include "FWCore/Framework/interface/EventSetup.h"
0023 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0024 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0025 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0026 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0027 #include "FWCore/Utilities/interface/ESGetToken.h"
0028 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalUncalibRecHitRecAnalFitAlgo.h"
0029 #include "RecoLocalCalo/EcalRecProducers/interface/EcalUncalibRecHitWorkerRunOneDigiBase.h"
0030 
0031 #include <cmath>
0032 #include <iostream>
0033 #include <vector>
0034 
0035 class EcalUncalibRecHitWorkerAnalFit : public EcalUncalibRecHitWorkerRunOneDigiBase {
0036 public:
0037   EcalUncalibRecHitWorkerAnalFit(const edm::ParameterSet& ps, edm::ConsumesCollector& c);
0038   EcalUncalibRecHitWorkerAnalFit() {}
0039 
0040   void set(const edm::EventSetup& es) override;
0041   bool run(const edm::Event& evt,
0042            const EcalDigiCollection::const_iterator& digi,
0043            EcalUncalibratedRecHitCollection& result) override;
0044 
0045   edm::ParameterSetDescription getAlgoDescription() override;
0046 
0047 private:
0048   EcalUncalibRecHitRecAnalFitAlgo<EBDataFrame> algoEB_;
0049   EcalUncalibRecHitRecAnalFitAlgo<EEDataFrame> algoEE_;
0050 
0051   edm::ESHandle<EcalGainRatios> pRatio;
0052   edm::ESHandle<EcalPedestals> pedHandle;
0053   edm::ESGetToken<EcalGainRatios, EcalGainRatiosRcd> ratiosToken_;
0054   edm::ESGetToken<EcalPedestals, EcalPedestalsRcd> pedestalsToken_;
0055 };
0056 
0057 EcalUncalibRecHitWorkerAnalFit::EcalUncalibRecHitWorkerAnalFit(const edm::ParameterSet& ps, edm::ConsumesCollector& c)
0058     : EcalUncalibRecHitWorkerRunOneDigiBase(ps, c),
0059       ratiosToken_(c.esConsumes<EcalGainRatios, EcalGainRatiosRcd>()),
0060       pedestalsToken_(c.esConsumes<EcalPedestals, EcalPedestalsRcd>()) {}
0061 
0062 void EcalUncalibRecHitWorkerAnalFit::set(const edm::EventSetup& es) {
0063   // Gain Ratios
0064   LogDebug("EcalUncalibRecHitDebug") << "fetching gainRatios....";
0065   pRatio = es.getHandle(ratiosToken_);
0066   LogDebug("EcalUncalibRecHitDebug") << "done.";
0067 
0068   // fetch the pedestals from the cond DB via EventSetup
0069   LogDebug("EcalUncalibRecHitDebug") << "fetching pedestals....";
0070   pedHandle = es.getHandle(pedestalsToken_);
0071   LogDebug("EcalUncalibRecHitDebug") << "done.";
0072 }
0073 
0074 bool EcalUncalibRecHitWorkerAnalFit::run(const edm::Event& evt,
0075                                          const EcalDigiCollection::const_iterator& itdg,
0076                                          EcalUncalibratedRecHitCollection& result) {
0077   using namespace edm;
0078 
0079   const EcalGainRatioMap& gainMap = pRatio.product()->getMap();    // map of gain ratios
0080   const EcalPedestalsMap& pedMap = pedHandle.product()->getMap();  // map of pedestals
0081 
0082   EcalPedestalsMapIterator pedIter;  // pedestal iterator
0083   EcalPedestals::Item aped;          // pedestal object for a single xtal
0084 
0085   EcalGainRatioMap::const_iterator gainIter;  // gain iterator
0086   EcalMGPAGainRatio aGain;                    // gain object for a single xtal
0087 
0088   DetId detid(itdg->id());
0089 
0090   // find pedestals for this channel
0091   //LogDebug("EcalUncalibRecHitDebug") << "looking up pedestal for crystal: " << itdg->id(); // FIXME
0092   pedIter = pedMap.find(detid);
0093   if (pedIter != pedMap.end()) {
0094     aped = (*pedIter);
0095   } else {
0096     edm::LogError("EcalUncalibRecHitWorkerAnalFit") << "error!! could not find pedestals for channel: ";
0097     if (detid.subdetId() == EcalBarrel) {
0098       edm::LogError("EcalUncalibRecHitWorkerAnalFit") << EBDetId(detid);
0099     } else {
0100       edm::LogError("EcalUncalibRecHitWorkerAnalFit") << EEDetId(detid);
0101     }
0102     edm::LogError("EcalUncalibRecHitWorkerAnalFit") << "\n  no uncalib rechit will be made for this digi!";
0103     return false;
0104   }
0105   double pedVec[3];
0106   pedVec[0] = aped.mean_x12;
0107   pedVec[1] = aped.mean_x6;
0108   pedVec[2] = aped.mean_x1;
0109 
0110   // find gain ratios
0111   //LogDebug("EcalUncalibRecHitDebug") << "looking up gainRatios for crystal: " << itdg->id(); // FIXME
0112   gainIter = gainMap.find(detid);
0113   if (gainIter != gainMap.end()) {
0114     aGain = (*gainIter);
0115   } else {
0116     edm::LogError("EcalUncalibRecHitWorkerAnalFit") << "error!! could not find gain ratios for channel: ";
0117     if (detid.subdetId() == EcalBarrel) {
0118       edm::LogError("EcalUncalibRecHitWorkerAnalFit") << EBDetId(detid);
0119     } else {
0120       edm::LogError("EcalUncalibRecHitWorkerAnalFit") << EEDetId(detid);
0121     }
0122     edm::LogError("EcalUncalibRecHitWorkerAnalFit") << "\n  no uncalib rechit will be made for this digi!";
0123     return false;
0124   }
0125   double gainRatios[3];
0126   gainRatios[0] = 1.;
0127   gainRatios[1] = aGain.gain12Over6();
0128   gainRatios[2] = aGain.gain6Over1() * aGain.gain12Over6();
0129 
0130   if (detid.subdetId() == EcalBarrel) {
0131     EcalUncalibratedRecHit aHit = algoEB_.makeRecHit(*itdg, pedVec, gainRatios, nullptr, nullptr);
0132     result.push_back(aHit);
0133     if (aHit.amplitude() > 0.) {
0134       LogDebug("EcalUncalibRecHitInfo") << "EcalUncalibRecHitWorkerAnalFit: processed EBDataFrame with id: "
0135                                         << EBDetId(detid) << "\n"
0136                                         << "uncalib rechit amplitude: " << aHit.amplitude();
0137     }
0138   } else {
0139     EcalUncalibratedRecHit aHit = algoEE_.makeRecHit(*itdg, pedVec, gainRatios, nullptr, nullptr);
0140     result.push_back(aHit);
0141     if (aHit.amplitude() > 0.) {
0142       LogDebug("EcalUncalibRecHitInfo") << "EcalUncalibRecHitWorkerAnalFit: processed EEDataFrame with id: "
0143                                         << EEDetId(detid) << "\n"
0144                                         << "uncalib rechit amplitude: " << aHit.amplitude();
0145     }
0146   }
0147   return true;
0148 }
0149 
0150 edm::ParameterSetDescription EcalUncalibRecHitWorkerAnalFit::getAlgoDescription() {
0151   edm::ParameterSetDescription psd;
0152   //psd.addNode(edm::ParameterSet<edm::InputTag>("EBdigiCollection", edm::InputTag("ecalDigis","ebDigis")) and
0153   //           edm::ParameterSet<std::string>("EEhitCollection", "EcalUncalibRecHitsEE") and
0154   //           edm::ParameterSet<edm::InputTag>("EEdigiCollection", edm::InputTag("ecalDigis","eeDigis")) and
0155   //           edm::ParameterSet<std::string>("algo", "EcalUncalibRecHitWorkerAnalFit") and
0156   //           edm::ParameterSet<std::string>("EBhitCollection", "EcalUncalibRecHitsEB"));
0157   //
0158   return psd;
0159 }
0160 
0161 #include "FWCore/Framework/interface/MakerMacros.h"
0162 #include "RecoLocalCalo/EcalRecProducers/interface/EcalUncalibRecHitWorkerFactory.h"
0163 DEFINE_EDM_PLUGIN(EcalUncalibRecHitWorkerFactory, EcalUncalibRecHitWorkerAnalFit, "EcalUncalibRecHitWorkerAnalFit");
0164 #include "RecoLocalCalo/EcalRecProducers/interface/EcalUncalibRecHitFillDescriptionWorkerFactory.h"
0165 DEFINE_EDM_PLUGIN(EcalUncalibRecHitFillDescriptionWorkerFactory,
0166                   EcalUncalibRecHitWorkerAnalFit,
0167                   "EcalUncalibRecHitWorkerAnalFit");