Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:24:28

0001 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalTimingCorrector.h"
0002 #include "DataFormats/METReco/interface/HcalCaloFlagLabels.h"
0003 
0004 // Using defined flags instead of hardcoding bits 2 and 3
0005 
0006 namespace HcalTimingCorrector_impl {
0007   template <class T, class V>
0008   void makeCorrection(T& rechit, const V& digi, int favorite_capid) {
0009     if (digi.fiberIdleOffset() == -1000)
0010       return;  //reserved for bad stuff
0011 
0012     bool bad = false;
0013     //convention, -1 means digi is early, need to add
0014     //            +1 means digi is late, need to subtract
0015     int capid_shift = (favorite_capid - digi[0].capid());
0016     capid_shift %= 4;
0017     while (capid_shift < 0)
0018       capid_shift += 4;
0019 
0020     int idle_shift = digi.fiberIdleOffset();
0021     idle_shift %= 4;
0022     while (idle_shift < 0)
0023       idle_shift += 4;
0024 
0025     if (capid_shift != idle_shift) {
0026       bad = true;
0027     } else if (capid_shift == 0) {
0028       // do nothing, all is well
0029     } else if (capid_shift == 2) {
0030       bad = true;
0031     } else {
0032       /*
0033       std::cout << "capid_shift " << capid_shift 
0034         << " fiberOffset " << digi.fiberIdleOffset() << std::endl;
0035       */
0036       rechit = T(rechit.id(), rechit.energy(), rechit.time() + (capid_shift == 1 ? -25 : +25));
0037       rechit.setFlagField(
0038           1, (capid_shift == 1 ? HcalCaloFlagLabels::TimingSubtractedBit : HcalCaloFlagLabels::TimingAddedBit));
0039     }
0040 
0041     if (bad) {
0042       /*
0043     std::cout << "BAD capid_shift " << capid_shift 
0044     << " fiberOffset " << digi.fiberIdleOffset() << std::endl;
0045       */
0046       rechit.setFlagField(1, HcalCaloFlagLabels::TimingErrorBit);
0047     }
0048   }
0049 }  // namespace HcalTimingCorrector_impl
0050 
0051 using namespace HcalTimingCorrector_impl;
0052 
0053 HcalTimingCorrector::HcalTimingCorrector() {}
0054 
0055 HcalTimingCorrector::~HcalTimingCorrector() {}
0056 
0057 void HcalTimingCorrector::Correct(HBHERecHit& rechit, const HBHEDataFrame& digi, int favorite_capid) {
0058   makeCorrection<HBHERecHit, HBHEDataFrame>(rechit, digi, favorite_capid);
0059 }
0060 
0061 void HcalTimingCorrector::Correct(HORecHit& rechit, const HODataFrame& digi, int favorite_capid) {
0062   makeCorrection<HORecHit, HODataFrame>(rechit, digi, favorite_capid);
0063 }
0064 
0065 void HcalTimingCorrector::Correct(HFRecHit& rechit, const HFDataFrame& digi, int favorite_capid) {
0066   makeCorrection<HFRecHit, HFDataFrame>(rechit, digi, favorite_capid);
0067 }