Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-02 03:46:04

0001 #include "RecoLocalCalo/EcalRecProducers/plugins/EcalUncalibRecHitWorkerWeights.h"
0002 
0003 #include "FWCore/Framework/interface/EventSetup.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 
0007 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0009 
0010 #include "DataFormats/EcalRecHit/interface/EcalUncalibratedRecHit.h"
0011 
0012 EcalUncalibRecHitWorkerWeights::EcalUncalibRecHitWorkerWeights(const edm::ParameterSet& ps, edm::ConsumesCollector& c)
0013     : EcalUncalibRecHitWorkerRunOneDigiBase(ps, c),
0014       tokenPeds_(c.esConsumes<EcalPedestals, EcalPedestalsRcd>()),
0015       tokenGains_(c.esConsumes<EcalGainRatios, EcalGainRatiosRcd>()),
0016       tokenGrps_(c.esConsumes<EcalWeightXtalGroups, EcalWeightXtalGroupsRcd>()),
0017       tokenWgts_(c.esConsumes<EcalTBWeights, EcalTBWeightsRcd>()),
0018       testbeamEEShape(c),
0019       testbeamEBShape(c) {}
0020 
0021 void EcalUncalibRecHitWorkerWeights::set(const edm::EventSetup& es) {
0022   gains_ = es.getHandle(tokenGains_);
0023   peds_ = es.getHandle(tokenPeds_);
0024   grps_ = es.getHandle(tokenGrps_);
0025   wgts_ = es.getHandle(tokenWgts_);
0026 
0027   testbeamEEShape.setEventSetup(es);
0028   testbeamEBShape.setEventSetup(es);
0029 }
0030 
0031 bool EcalUncalibRecHitWorkerWeights::run(const edm::Event& evt,
0032                                          const EcalDigiCollection::const_iterator& itdg,
0033                                          EcalUncalibratedRecHitCollection& result) {
0034   DetId detid(itdg->id());
0035 
0036   const EcalPedestals::Item* aped = nullptr;
0037   const EcalMGPAGainRatio* aGain = nullptr;
0038   const EcalXtalGroupId* gid = nullptr;
0039   EcalTBWeights::EcalTDCId tdcid(1);
0040 
0041   if (detid.subdetId() == EcalEndcap) {
0042     unsigned int hashedIndex = EEDetId(detid).hashedIndex();
0043     aped = &peds_->endcap(hashedIndex);
0044     aGain = &gains_->endcap(hashedIndex);
0045     gid = &grps_->endcap(hashedIndex);
0046   } else {
0047     unsigned int hashedIndex = EBDetId(detid).hashedIndex();
0048     aped = &peds_->barrel(hashedIndex);
0049     aGain = &gains_->barrel(hashedIndex);
0050     gid = &grps_->barrel(hashedIndex);
0051   }
0052 
0053   pedVec[0] = aped->mean_x12;
0054   pedVec[1] = aped->mean_x6;
0055   pedVec[2] = aped->mean_x1;
0056   pedRMSVec[0] = aped->rms_x12;
0057   pedRMSVec[1] = aped->rms_x6;
0058   pedRMSVec[2] = aped->rms_x1;
0059   gainRatios[0] = 1.;
0060   gainRatios[1] = aGain->gain12Over6();
0061   gainRatios[2] = aGain->gain6Over1() * aGain->gain12Over6();
0062 
0063   // now lookup the correct weights in the map
0064   EcalTBWeights::EcalTBWeightMap const& wgtsMap = wgts_->getMap();
0065   EcalTBWeights::EcalTBWeightMap::const_iterator wit;
0066   wit = wgtsMap.find(std::make_pair(*gid, tdcid));
0067   if (wit == wgtsMap.end()) {
0068     edm::LogError("EcalUncalibRecHitError")
0069         << "No weights found for EcalGroupId: " << gid->id() << " and  EcalTDCId: " << tdcid
0070         << "\n  skipping digi with id: " << detid.rawId();
0071 
0072     return false;
0073   }
0074   const EcalWeightSet& wset = wit->second;  // this is the EcalWeightSet
0075 
0076   const EcalWeightSet::EcalWeightMatrix& mat1 = wset.getWeightsBeforeGainSwitch();
0077   const EcalWeightSet::EcalWeightMatrix& mat2 = wset.getWeightsAfterGainSwitch();
0078   //        const EcalWeightSet::EcalChi2WeightMatrix& mat3 = wset.getChi2WeightsBeforeGainSwitch();
0079   //        const EcalWeightSet::EcalChi2WeightMatrix& mat4 = wset.getChi2WeightsAfterGainSwitch();
0080 
0081   weights[0] = &mat1;
0082   weights[1] = &mat2;
0083 
0084   //        chi2mat[0] = &mat3;
0085   //        chi2mat[1] = &mat4;
0086   /*
0087         if (detid.subdetId()==EcalEndcap) {
0088                 result.push_back(uncalibMaker_endcap_.makeRecHit(*itdg, pedVec, gainRatios, weights, chi2mat));
0089         } else {
0090                 result.push_back(uncalibMaker_barrel_.makeRecHit(*itdg, pedVec, gainRatios, weights, chi2mat));
0091         }
0092 */
0093   if (detid.subdetId() == EcalEndcap) {
0094     EcalUncalibratedRecHit rhit =
0095         (uncalibMaker_endcap_.makeRecHit(*itdg, pedVec, pedRMSVec, gainRatios, weights, testbeamEEShape));
0096     if (((EcalDataFrame)(*itdg)).hasSwitchToGain6())
0097       rhit.setFlagBit(EcalUncalibratedRecHit::kHasSwitchToGain6);
0098     if (((EcalDataFrame)(*itdg)).hasSwitchToGain1())
0099       rhit.setFlagBit(EcalUncalibratedRecHit::kHasSwitchToGain1);
0100     result.emplace_back(rhit);
0101   } else {
0102     EcalUncalibratedRecHit rhit =
0103         (uncalibMaker_endcap_.makeRecHit(*itdg, pedVec, pedRMSVec, gainRatios, weights, testbeamEBShape));
0104     if (((EcalDataFrame)(*itdg)).hasSwitchToGain6())
0105       rhit.setFlagBit(EcalUncalibratedRecHit::kHasSwitchToGain6);
0106     if (((EcalDataFrame)(*itdg)).hasSwitchToGain1())
0107       rhit.setFlagBit(EcalUncalibratedRecHit::kHasSwitchToGain1);
0108     result.emplace_back(rhit);
0109   }
0110   return true;
0111 }
0112 
0113 edm::ParameterSetDescription EcalUncalibRecHitWorkerWeights::getAlgoDescription() {
0114   edm::ParameterSetDescription psd;
0115   return psd;
0116 }
0117 
0118 #include "FWCore/Framework/interface/MakerMacros.h"
0119 #include "RecoLocalCalo/EcalRecProducers/interface/EcalUncalibRecHitWorkerFactory.h"
0120 DEFINE_EDM_PLUGIN(EcalUncalibRecHitWorkerFactory, EcalUncalibRecHitWorkerWeights, "EcalUncalibRecHitWorkerWeights");
0121 #include "RecoLocalCalo/EcalRecProducers/interface/EcalUncalibRecHitFillDescriptionWorkerFactory.h"
0122 DEFINE_EDM_PLUGIN(EcalUncalibRecHitFillDescriptionWorkerFactory,
0123                   EcalUncalibRecHitWorkerWeights,
0124                   "EcalUncalibRecHitWorkerWeights");