Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-19 10:28:03

0001 /*
0002  *  See header file for a description of this class.
0003  */
0004 
0005 #include "DTT0AbsoluteReferenceCorrection.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008 #include "FWCore/Framework/interface/ESHandle.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 
0011 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0012 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0013 #include "Geometry/DTGeometry/interface/DTSuperLayer.h"
0014 
0015 #include "DataFormats/MuonDetId/interface/DTWireId.h"
0016 #include "CondFormats/DTObjects/interface/DTT0.h"
0017 #include "CondFormats/DataRecord/interface/DTT0Rcd.h"
0018 
0019 #include <string>
0020 #include <sstream>
0021 
0022 using namespace std;
0023 using namespace edm;
0024 
0025 namespace dtCalibration {
0026 
0027   DTT0AbsoluteReferenceCorrection::DTT0AbsoluteReferenceCorrection(const ParameterSet& pset, edm::ConsumesCollector cc)
0028       : calibChamber_(pset.getParameter<string>("calibChamber")),
0029         reference_(pset.getParameter<double>("reference")),
0030         t0Token_(cc.esConsumes<edm::Transition::BeginRun>()) {
0031     //DTChamberId chosenChamberId;
0032     if (!calibChamber_.empty() && calibChamber_ != "None" && calibChamber_ != "All") {
0033       stringstream linestr;
0034       int selWheel, selStation, selSector;
0035       linestr << calibChamber_;
0036       linestr >> selWheel >> selStation >> selSector;
0037       chosenChamberId_ = DTChamberId(selWheel, selStation, selSector);
0038       LogVerbatim("Calibration") << "[DTT0AbsoluteReferenceCorrection] Chosen chamber: " << chosenChamberId_ << endl;
0039     }
0040     //FIXME: Check if chosen chamber is valid.
0041   }
0042 
0043   DTT0AbsoluteReferenceCorrection::~DTT0AbsoluteReferenceCorrection() {}
0044 
0045   void DTT0AbsoluteReferenceCorrection::setES(const EventSetup& setup) {
0046     // Get t0 record from DB
0047     ESHandle<DTT0> t0H;
0048     t0H = setup.getHandle(t0Token_);
0049     t0Map_ = &*t0H;
0050     LogVerbatim("Calibration") << "[DTT0AbsoluteReferenceCorrection] T0 version: " << t0H->version();
0051   }
0052 
0053   DTT0Data DTT0AbsoluteReferenceCorrection::correction(const DTWireId& wireId) {
0054     // Compute for selected chamber (or All) correction using as reference chamber mean
0055 
0056     DTChamberId chamberId = wireId.layerId().superlayerId().chamberId();
0057 
0058     if (calibChamber_.empty() || calibChamber_ == "None")
0059       return defaultT0(wireId);
0060     if (calibChamber_ != "All" && chamberId != chosenChamberId_)
0061       return defaultT0(wireId);
0062 
0063     // Access DB
0064     float t0Mean, t0RMS;
0065     int status = t0Map_->get(wireId, t0Mean, t0RMS, DTTimeUnits::counts);
0066     if (status != 0)
0067       throw cms::Exception("[DTT0AbsoluteReferenceCorrection]")
0068           << "Could not find t0 entry in DB for" << wireId << endl;
0069 
0070     float t0MeanNew = t0Mean - reference_;
0071     float t0RMSNew = t0RMS;
0072     return DTT0Data(t0MeanNew, t0RMSNew);
0073   }
0074 
0075   DTT0Data DTT0AbsoluteReferenceCorrection::defaultT0(const DTWireId& wireId) {
0076     // Access default DB
0077     float t0Mean, t0RMS;
0078     int status = t0Map_->get(wireId, t0Mean, t0RMS, DTTimeUnits::counts);
0079     if (!status) {
0080       return DTT0Data(t0Mean, t0RMS);
0081     } else {
0082       //...
0083       throw cms::Exception("[DTT0AbsoluteReferenceCorrection]")
0084           << "Could not find t0 entry in DB for" << wireId << endl;
0085     }
0086   }
0087 
0088 }  // namespace dtCalibration