Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:27:16

0001 #include "RecoTBCalo/EcalTBTDCReconstructor/interface/EcalTBTDCRecInfoAlgo.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 
0004 #include <list>
0005 #include <iostream>
0006 
0007 EcalTBTDCRecInfoAlgo::EcalTBTDCRecInfoAlgo(const std::vector<EcalTBTDCRanges>& tdcRanges)
0008     : tdcRanges_(tdcRanges), tdcRangeErrorMessageAlreadyDisplayed_(false), actualRun_(-1), actualRange_(-1) {}
0009 
0010 EcalTBTDCRecInfo EcalTBTDCRecInfoAlgo::reconstruct(const EcalTBTDCRawInfo& TDCRawInfo,
0011                                                    const EcalTBEventHeader& eventHeader,
0012                                                    bool use2004OffsetConvention) const {
0013   if (actualRun_ != eventHeader.runNumber()) {
0014     actualRun_ = eventHeader.runNumber();
0015     actualRange_ = -1;
0016     for (unsigned int i = 0; i < tdcRanges_.size(); i++)
0017       if (eventHeader.runNumber() <= tdcRanges_[i].runRanges.second &&
0018           eventHeader.runNumber() >= tdcRanges_[i].runRanges.first)
0019         actualRange_ = i;
0020 
0021     if (actualRange_ == -1) {
0022       edm::LogError("TDCRange not found") << "TDC range not found";
0023       return EcalTBTDCRecInfo(-1);
0024     }
0025   }
0026 
0027   int eventType;
0028   eventType = ((eventHeader.dbEventType() == 0) ? 0 : (eventHeader.dbEventType() - 1));
0029 
0030   int tdcd = TDCRawInfo[0].tdcValue();
0031 
0032   if (!tdcRangeErrorMessageAlreadyDisplayed_ &&
0033       (tdcd < tdcRanges_[actualRange_].tdcMin[eventType] || tdcd > tdcRanges_[actualRange_].tdcMax[eventType])) {
0034     std::cout << " ============================" << std::endl;
0035     std::cout << " Event type: " << eventType << std::endl;
0036     std::cout << " TDC values not correctly set Raw TDC = " << tdcd
0037               << " (Min/Max = " << tdcRanges_[actualRange_].tdcMin[eventType] << "/"
0038               << tdcRanges_[actualRange_].tdcMax[eventType] << std::endl;
0039     std::cout << " ============================" << std::endl;
0040     tdcRangeErrorMessageAlreadyDisplayed_ = true;
0041   }
0042 
0043   double offset =
0044       ((double)tdcd - (double)tdcRanges_[actualRange_].tdcMin[eventType]) /
0045       ((double)tdcRanges_[actualRange_].tdcMax[eventType] - (double)tdcRanges_[actualRange_].tdcMin[eventType]);
0046   if (use2004OffsetConvention)
0047     offset = (1. - offset);
0048   return EcalTBTDCRecInfo(offset);
0049 }