Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:45

0001 /** \class EcalUncalibRecHitRecWeightsAlgo
0002   *  Template used to compute amplitude, pedestal, time jitter, chi2 of a pulse
0003   *  using a weights method
0004   *
0005   *  \author R. Bruneliere - A. Zabi
0006   */
0007 
0008 #include "CondFormats/DataRecord/interface/EcalGainRatiosRcd.h"
0009 #include "CondFormats/DataRecord/interface/EcalPedestalsRcd.h"
0010 #include "CondFormats/DataRecord/interface/EcalTBWeightsRcd.h"
0011 #include "CondFormats/DataRecord/interface/EcalWeightXtalGroupsRcd.h"
0012 #include "CondFormats/EcalObjects/interface/EcalGainRatios.h"
0013 #include "CondFormats/EcalObjects/interface/EcalPedestals.h"
0014 #include "CondFormats/EcalObjects/interface/EcalTBWeights.h"
0015 #include "CondFormats/EcalObjects/interface/EcalWeightXtalGroups.h"
0016 #include "DataFormats/EcalRecHit/interface/EcalUncalibratedRecHit.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/MessageLogger/interface/MessageLogger.h"
0021 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0023 #include "FWCore/Utilities/interface/ESGetToken.h"
0024 #include "RecoLocalCalo/EcalRecAlgos/interface/EcalUncalibRecHitRecWeightsAlgo.h"
0025 #include "RecoLocalCalo/EcalRecProducers/interface/EcalUncalibRecHitWorkerRunOneDigiBase.h"
0026 #include "SimCalorimetry/EcalSimAlgos/interface/EBShape.h"
0027 #include "SimCalorimetry/EcalSimAlgos/interface/EEShape.h"
0028 
0029 class EcalUncalibRecHitWorkerWeights : public EcalUncalibRecHitWorkerRunOneDigiBase {
0030 public:
0031   EcalUncalibRecHitWorkerWeights(const edm::ParameterSet&, edm::ConsumesCollector& c);
0032   EcalUncalibRecHitWorkerWeights() = default;  // for EcalUncalibRecHitFillDescriptionWorkerFactory
0033 
0034   void set(const edm::EventSetup& es) override;
0035   bool run(const edm::Event& evt,
0036            const EcalDigiCollection::const_iterator& digi,
0037            EcalUncalibratedRecHitCollection& result) override;
0038 
0039   edm::ParameterSetDescription getAlgoDescription() override;
0040 
0041 protected:
0042   edm::ESGetToken<EcalPedestals, EcalPedestalsRcd> tokenPeds_;
0043   edm::ESGetToken<EcalGainRatios, EcalGainRatiosRcd> tokenGains_;
0044   edm::ESGetToken<EcalWeightXtalGroups, EcalWeightXtalGroupsRcd> tokenGrps_;
0045   edm::ESGetToken<EcalTBWeights, EcalTBWeightsRcd> tokenWgts_;
0046   edm::ESHandle<EcalPedestals> peds_;
0047   edm::ESHandle<EcalGainRatios> gains_;
0048   edm::ESHandle<EcalWeightXtalGroups> grps_;
0049   edm::ESHandle<EcalTBWeights> wgts_;
0050 
0051   double pedVec[3];
0052   double pedRMSVec[3];
0053   double gainRatios[3];
0054 
0055   const EcalWeightSet::EcalWeightMatrix* weights[2];
0056   const EcalWeightSet::EcalChi2WeightMatrix* chi2mat[2];
0057 
0058   EcalUncalibRecHitRecWeightsAlgo<EBDataFrame> uncalibMaker_barrel_;
0059   EcalUncalibRecHitRecWeightsAlgo<EEDataFrame> uncalibMaker_endcap_;
0060 
0061   EEShape testbeamEEShape;  // used in the chi2
0062   EBShape testbeamEBShape;  // can be replaced by simple shape arrays of floats in the future (kostas)
0063 };
0064 
0065 EcalUncalibRecHitWorkerWeights::EcalUncalibRecHitWorkerWeights(const edm::ParameterSet& ps, edm::ConsumesCollector& c)
0066     : EcalUncalibRecHitWorkerRunOneDigiBase(ps, c),
0067       tokenPeds_(c.esConsumes<EcalPedestals, EcalPedestalsRcd>()),
0068       tokenGains_(c.esConsumes<EcalGainRatios, EcalGainRatiosRcd>()),
0069       tokenGrps_(c.esConsumes<EcalWeightXtalGroups, EcalWeightXtalGroupsRcd>()),
0070       tokenWgts_(c.esConsumes<EcalTBWeights, EcalTBWeightsRcd>()),
0071       testbeamEEShape(c),
0072       testbeamEBShape(c) {}
0073 
0074 void EcalUncalibRecHitWorkerWeights::set(const edm::EventSetup& es) {
0075   gains_ = es.getHandle(tokenGains_);
0076   peds_ = es.getHandle(tokenPeds_);
0077   grps_ = es.getHandle(tokenGrps_);
0078   wgts_ = es.getHandle(tokenWgts_);
0079 
0080   testbeamEEShape.setEventSetup(es);
0081   testbeamEBShape.setEventSetup(es);
0082 }
0083 
0084 bool EcalUncalibRecHitWorkerWeights::run(const edm::Event& evt,
0085                                          const EcalDigiCollection::const_iterator& itdg,
0086                                          EcalUncalibratedRecHitCollection& result) {
0087   DetId detid(itdg->id());
0088 
0089   const EcalPedestals::Item* aped = nullptr;
0090   const EcalMGPAGainRatio* aGain = nullptr;
0091   const EcalXtalGroupId* gid = nullptr;
0092   EcalTBWeights::EcalTDCId tdcid(1);
0093 
0094   if (detid.subdetId() == EcalEndcap) {
0095     unsigned int hashedIndex = EEDetId(detid).hashedIndex();
0096     aped = &peds_->endcap(hashedIndex);
0097     aGain = &gains_->endcap(hashedIndex);
0098     gid = &grps_->endcap(hashedIndex);
0099   } else {
0100     unsigned int hashedIndex = EBDetId(detid).hashedIndex();
0101     aped = &peds_->barrel(hashedIndex);
0102     aGain = &gains_->barrel(hashedIndex);
0103     gid = &grps_->barrel(hashedIndex);
0104   }
0105 
0106   pedVec[0] = aped->mean_x12;
0107   pedVec[1] = aped->mean_x6;
0108   pedVec[2] = aped->mean_x1;
0109   pedRMSVec[0] = aped->rms_x12;
0110   pedRMSVec[1] = aped->rms_x6;
0111   pedRMSVec[2] = aped->rms_x1;
0112   gainRatios[0] = 1.;
0113   gainRatios[1] = aGain->gain12Over6();
0114   gainRatios[2] = aGain->gain6Over1() * aGain->gain12Over6();
0115 
0116   // now lookup the correct weights in the map
0117   EcalTBWeights::EcalTBWeightMap const& wgtsMap = wgts_->getMap();
0118   EcalTBWeights::EcalTBWeightMap::const_iterator wit;
0119   wit = wgtsMap.find(std::make_pair(*gid, tdcid));
0120   if (wit == wgtsMap.end()) {
0121     edm::LogError("EcalUncalibRecHitError")
0122         << "No weights found for EcalGroupId: " << gid->id() << " and  EcalTDCId: " << tdcid
0123         << "\n  skipping digi with id: " << detid.rawId();
0124 
0125     return false;
0126   }
0127   const EcalWeightSet& wset = wit->second;  // this is the EcalWeightSet
0128 
0129   const EcalWeightSet::EcalWeightMatrix& mat1 = wset.getWeightsBeforeGainSwitch();
0130   const EcalWeightSet::EcalWeightMatrix& mat2 = wset.getWeightsAfterGainSwitch();
0131   //        const EcalWeightSet::EcalChi2WeightMatrix& mat3 = wset.getChi2WeightsBeforeGainSwitch();
0132   //        const EcalWeightSet::EcalChi2WeightMatrix& mat4 = wset.getChi2WeightsAfterGainSwitch();
0133 
0134   weights[0] = &mat1;
0135   weights[1] = &mat2;
0136 
0137   //        chi2mat[0] = &mat3;
0138   //        chi2mat[1] = &mat4;
0139   /*
0140         if (detid.subdetId()==EcalEndcap) {
0141                 result.push_back(uncalibMaker_endcap_.makeRecHit(*itdg, pedVec, gainRatios, weights, chi2mat));
0142         } else {
0143                 result.push_back(uncalibMaker_barrel_.makeRecHit(*itdg, pedVec, gainRatios, weights, chi2mat));
0144         }
0145 */
0146   if (detid.subdetId() == EcalEndcap) {
0147     EcalUncalibratedRecHit rhit =
0148         (uncalibMaker_endcap_.makeRecHit(*itdg, pedVec, pedRMSVec, gainRatios, weights, testbeamEEShape));
0149     if (((EcalDataFrame)(*itdg)).hasSwitchToGain6())
0150       rhit.setFlagBit(EcalUncalibratedRecHit::kHasSwitchToGain6);
0151     if (((EcalDataFrame)(*itdg)).hasSwitchToGain1())
0152       rhit.setFlagBit(EcalUncalibratedRecHit::kHasSwitchToGain1);
0153     result.emplace_back(rhit);
0154   } else {
0155     EcalUncalibratedRecHit rhit =
0156         (uncalibMaker_endcap_.makeRecHit(*itdg, pedVec, pedRMSVec, gainRatios, weights, testbeamEBShape));
0157     if (((EcalDataFrame)(*itdg)).hasSwitchToGain6())
0158       rhit.setFlagBit(EcalUncalibratedRecHit::kHasSwitchToGain6);
0159     if (((EcalDataFrame)(*itdg)).hasSwitchToGain1())
0160       rhit.setFlagBit(EcalUncalibratedRecHit::kHasSwitchToGain1);
0161     result.emplace_back(rhit);
0162   }
0163   return true;
0164 }
0165 
0166 edm::ParameterSetDescription EcalUncalibRecHitWorkerWeights::getAlgoDescription() {
0167   edm::ParameterSetDescription psd;
0168   return psd;
0169 }
0170 
0171 #include "FWCore/Framework/interface/MakerMacros.h"
0172 #include "RecoLocalCalo/EcalRecProducers/interface/EcalUncalibRecHitWorkerFactory.h"
0173 DEFINE_EDM_PLUGIN(EcalUncalibRecHitWorkerFactory, EcalUncalibRecHitWorkerWeights, "EcalUncalibRecHitWorkerWeights");
0174 #include "RecoLocalCalo/EcalRecProducers/interface/EcalUncalibRecHitFillDescriptionWorkerFactory.h"
0175 DEFINE_EDM_PLUGIN(EcalUncalibRecHitFillDescriptionWorkerFactory,
0176                   EcalUncalibRecHitWorkerWeights,
0177                   "EcalUncalibRecHitWorkerWeights");