Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /*
0002  *  See header file for a description of this class.
0003  *
0004  *  $Date: 2012/03/21 13:48:46 $
0005  *  $Revision: 1.2 $
0006  *  \author A. Vilela Pereira
0007  */
0008 
0009 #include "DTT0FillChamberFromDB.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/Framework/interface/EventSetup.h"
0012 #include "FWCore/Framework/interface/ESHandle.h"
0013 #include "FWCore/MessageLogger/interface/MessageLogger.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   DTT0FillChamberFromDB::DTT0FillChamberFromDB(const ParameterSet& pset, edm::ConsumesCollector cc)
0028       : chamberRef_(pset.getParameter<string>("chamberId")),
0029         t0Token_(cc.esConsumes<edm::Transition::BeginRun>()),
0030         t0RefToken_(
0031             cc.esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", pset.getParameter<string>("dbLabelRef")))) {
0032     //DTChamberId chosenChamberId;
0033     if (!chamberRef_.empty() && chamberRef_ != "None") {
0034       stringstream linestr;
0035       int selWheel, selStation, selSector;
0036       linestr << chamberRef_;
0037       linestr >> selWheel >> selStation >> selSector;
0038       chosenChamberId_ = DTChamberId(selWheel, selStation, selSector);
0039       LogVerbatim("Calibration") << "[DTT0FillChamberFromDB] Chosen chamber: " << chosenChamberId_ << endl;
0040     }
0041     //FIXME: Check if chosen chamber is valid.
0042   }
0043 
0044   DTT0FillChamberFromDB::~DTT0FillChamberFromDB() {}
0045 
0046   void DTT0FillChamberFromDB::setES(const EventSetup& setup) {
0047     // Get t0 record from DB
0048     ESHandle<DTT0> t0H = setup.getHandle(t0Token_);
0049     t0Map_ = &*t0H;
0050     LogVerbatim("Calibration") << "[DTT0FillChamberFromDB] T0 version: " << t0H->version();
0051 
0052     // Get reference t0 DB
0053     ESHandle<DTT0> t0RefH = setup.getHandle(t0RefToken_);
0054     t0MapRef_ = &*t0RefH;
0055     LogVerbatim("Calibration") << "[DTT0FillChamberFromDB] Reference T0 version: " << t0RefH->version();
0056   }
0057 
0058   DTT0Data DTT0FillChamberFromDB::correction(const DTWireId& wireId) {
0059     // If wire belongs to chosen chamber, use t0 value from reference DB
0060     // Otherwise use value from default DB
0061 
0062     DTChamberId chamberId = wireId.layerId().superlayerId().chamberId();
0063 
0064     if (!chamberRef_.empty() && chamberRef_ != "None" && chamberId == chosenChamberId_) {
0065       // Access reference DB
0066       float t0MeanRef, t0RMSRef;
0067       int statusRef = t0MapRef_->get(wireId, t0MeanRef, t0RMSRef, DTTimeUnits::counts);
0068       if (!statusRef) {
0069         return DTT0Data(t0MeanRef, t0RMSRef);
0070       } else {
0071         //...
0072         throw cms::Exception("[DTT0FillChamberFromDB]")
0073             << "Could not find t0 entry in reference DB for" << wireId << endl;
0074       }
0075     } else {
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("[DTT0FillChamberFromDB]") << "Could not find t0 entry in DB for" << wireId << endl;
0084       }
0085     }
0086   }
0087 
0088 }  // namespace dtCalibration