File indexing completed on 2024-04-06 11:58:28
0001
0002
0003
0004
0005
0006
0007 #include "DTTTrigT0SegCorrection.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/Framework/interface/EventSetup.h"
0010 #include "FWCore/Framework/interface/ESHandle.h"
0011 #include "DataFormats/MuonDetId/interface/DTSuperLayerId.h"
0012 #include "CondFormats/DTObjects/interface/DTTtrig.h"
0013 #include "CondFormats/DataRecord/interface/DTTtrigRcd.h"
0014
0015 #include "TFile.h"
0016 #include "TH1F.h"
0017
0018 #include <string>
0019 #include <sstream>
0020
0021 using namespace std;
0022 using namespace edm;
0023
0024 namespace dtCalibration {
0025
0026 DTTTrigT0SegCorrection::DTTTrigT0SegCorrection(const ParameterSet& pset, edm::ConsumesCollector cc) {
0027 string t0SegRootFile = pset.getParameter<string>("t0SegRootFile");
0028 rootFile_ = new TFile(t0SegRootFile.c_str(), "READ");
0029 ttrigToken_ =
0030 cc.esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", pset.getUntrackedParameter<string>("dbLabel")));
0031 }
0032
0033 DTTTrigT0SegCorrection::~DTTTrigT0SegCorrection() { delete rootFile_; }
0034
0035 void DTTTrigT0SegCorrection::setES(const EventSetup& setup) {
0036
0037 ESHandle<DTTtrig> tTrig = setup.getHandle(ttrigToken_);
0038 tTrigMap_ = &*tTrig;
0039 }
0040
0041 DTTTrigData DTTTrigT0SegCorrection::correction(const DTSuperLayerId& slId) {
0042 float tTrigMean, tTrigSigma, kFactor;
0043 int status = tTrigMap_->get(slId, tTrigMean, tTrigSigma, kFactor, DTTimeUnits::ns);
0044 if (status != 0)
0045 throw cms::Exception("[DTTTrigT0SegCorrection]") << "Could not find tTrig entry in DB for" << slId << endl;
0046
0047 const TH1F* t0SegHisto = getHisto(slId);
0048 double corrMean = tTrigMean;
0049 double corrSigma = tTrigSigma;
0050
0051 double corrKFact = (kFactor * tTrigSigma + t0SegHisto->GetMean()) / tTrigSigma;
0052 return DTTTrigData(corrMean, corrSigma, corrKFact);
0053 }
0054
0055 const TH1F* DTTTrigT0SegCorrection::getHisto(const DTSuperLayerId& slId) {
0056 string histoName = getHistoName(slId);
0057 TH1F* histo = static_cast<TH1F*>(rootFile_->Get(histoName.c_str()));
0058 if (!histo)
0059 throw cms::Exception("[DTTTrigT0SegCorrection]") << "t0-seg histogram not found:" << histoName << endl;
0060 return histo;
0061 }
0062
0063 string DTTTrigT0SegCorrection::getHistoName(const DTSuperLayerId& slId) {
0064 DTChamberId chId = slId.chamberId();
0065
0066
0067 std::string wheel = std::to_string(chId.wheel());
0068 std::string station = std::to_string(chId.station());
0069 std::string sector = std::to_string(chId.sector());
0070
0071 string chHistoName = "_W" + wheel + "_St" + station + "_Sec" + sector;
0072
0073 return (slId.superLayer() != 2) ? ("hRPhiSegT0" + chHistoName) : ("hRZSegT0" + chHistoName);
0074 }
0075
0076 }