File indexing completed on 2024-09-07 04:34:56
0001
0002
0003
0004
0005 #include "DTT0Correction.h"
0006
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/Framework/interface/ESHandle.h"
0009 #include "FWCore/Framework/interface/EventSetup.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011
0012 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0013 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0014 #include "Geometry/DTGeometry/interface/DTSuperLayer.h"
0015
0016 #include "CondFormats/DTObjects/interface/DTT0.h"
0017 #include "CondFormats/DataRecord/interface/DTT0Rcd.h"
0018
0019 #include "CalibMuon/DTCalibration/interface/DTCalibDBUtils.h"
0020
0021 #include "CalibMuon/DTCalibration/interface/DTT0CorrectionFactory.h"
0022 #include "CalibMuon/DTCalibration/interface/DTT0BaseCorrection.h"
0023 #include "FWCore/Framework/interface/ConsumesCollector.h"
0024
0025 #include <iostream>
0026 #include <fstream>
0027
0028 using namespace edm;
0029 using namespace std;
0030
0031 DTT0Correction::DTT0Correction(const ParameterSet& pset)
0032 : correctionAlgo_{DTT0CorrectionFactory::get()->create(pset.getParameter<string>("correctionAlgo"),
0033 pset.getParameter<ParameterSet>("correctionAlgoConfig"),
0034 consumesCollector())},
0035 dtGeomToken_(esConsumes<edm::Transition::BeginRun>()),
0036 t0Token_(esConsumes<edm::Transition::BeginRun>()) {
0037 LogVerbatim("Calibration") << "[DTT0Correction] Constructor called" << endl;
0038 }
0039
0040 DTT0Correction::~DTT0Correction() { LogVerbatim("Calibration") << "[DTT0Correction] Destructor called" << endl; }
0041
0042 void DTT0Correction::beginRun(const edm::Run& run, const edm::EventSetup& setup) {
0043
0044 ESHandle<DTT0> t0H;
0045 t0H = setup.getHandle(t0Token_);
0046 t0Map_ = &setup.getData(t0Token_);
0047 LogVerbatim("Calibration") << "[DTT0Correction]: T0 version: " << t0H->version() << endl;
0048
0049
0050 muonGeom_ = setup.getHandle(dtGeomToken_);
0051
0052
0053 correctionAlgo_->setES(setup);
0054 }
0055
0056 void DTT0Correction::endJob() {
0057
0058 DTT0 t0NewMap;
0059
0060
0061 for (vector<const DTSuperLayer*>::const_iterator sl = muonGeom_->superLayers().begin();
0062 sl != muonGeom_->superLayers().end();
0063 ++sl) {
0064 for (vector<const DTLayer*>::const_iterator layer = (*sl)->layers().begin(); layer != (*sl)->layers().end();
0065 ++layer) {
0066
0067 const DTTopology& dtTopo = (*layer)->specificTopology();
0068 const int firstWire = dtTopo.firstChannel();
0069 const int lastWire = dtTopo.lastChannel();
0070
0071
0072
0073 for (int wire = firstWire; wire <= lastWire; ++wire) {
0074 DTWireId wireId((*layer)->id(), wire);
0075
0076
0077 float t0Mean, t0RMS;
0078 int status = t0Map_->get(wireId, t0Mean, t0RMS, DTTimeUnits::counts);
0079
0080
0081 try {
0082 dtCalibration::DTT0Data t0Corr = correctionAlgo_->correction(wireId);
0083 float t0MeanNew = t0Corr.mean;
0084 float t0RMSNew = t0Corr.rms;
0085 t0NewMap.set(wireId, t0MeanNew, t0RMSNew, DTTimeUnits::counts);
0086
0087 LogVerbatim("Calibration") << "New t0 for: " << wireId << " mean from " << t0Mean << " to " << t0MeanNew
0088 << " rms from " << t0RMS << " to " << t0RMSNew << endl;
0089 } catch (cms::Exception& e) {
0090 LogError("Calibration") << e.explainSelf();
0091
0092 if (!status) {
0093 t0NewMap.set(wireId, t0Mean, t0RMS, DTTimeUnits::counts);
0094 LogVerbatim("Calibration") << "Keep old t0 for: " << wireId << " mean " << t0Mean << " rms " << t0RMS
0095 << endl;
0096 }
0097 continue;
0098 }
0099 }
0100 }
0101 }
0102
0103
0104 LogVerbatim("Calibration") << "[DTT0Correction]: Writing t0 object to DB!" << endl;
0105 string record = "DTT0Rcd";
0106 DTCalibDBUtils::writeToDB<DTT0>(record, t0NewMap);
0107 }