Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "DTVDriftWriter.h"
00012
00013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00014 #include "FWCore/Framework/interface/ESHandle.h"
00015 #include "FWCore/Framework/interface/EventSetup.h"
00016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00017
00018 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00019 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00020 #include "Geometry/DTGeometry/interface/DTSuperLayer.h"
00021
00022 #include "CondFormats/DTObjects/interface/DTMtime.h"
00023 #include "CondFormats/DataRecord/interface/DTMtimeRcd.h"
00024
00025 #include "CalibMuon/DTCalibration/interface/DTCalibDBUtils.h"
00026 #include "CalibMuon/DTCalibration/interface/DTVDriftPluginFactory.h"
00027 #include "CalibMuon/DTCalibration/interface/DTVDriftBaseAlgo.h"
00028
00029 #include <string>
00030 #include <vector>
00031
00032 using namespace std;
00033 using namespace edm;
00034
00035 DTVDriftWriter::DTVDriftWriter(const ParameterSet& pset):
00036 granularity_( pset.getUntrackedParameter<string>("calibGranularity","bySL") ) {
00037
00038 LogVerbatim("Calibration") << "[DTVDriftWriter]Constructor called!";
00039
00040 if(granularity_ != "bySL")
00041 throw cms::Exception("Configuration") << "[DTVDriftWriter] Check parameter calibGranularity: " << granularity_ << " option not available.";
00042
00043
00044 string algoName = pset.getParameter<string>("vDriftAlgo");
00045 ParameterSet algoPSet = pset.getParameter<ParameterSet>("vDriftAlgoConfig");
00046 vDriftAlgo_ = DTVDriftPluginFactory::get()->create(algoName,algoPSet);
00047 }
00048
00049 DTVDriftWriter::~DTVDriftWriter(){
00050 LogVerbatim("Calibration") << "[DTVDriftWriter]Destructor called!";
00051 delete vDriftAlgo_;
00052 }
00053
00054 void DTVDriftWriter::beginRun(const edm::Run& run, const edm::EventSetup& setup) {
00055
00056 ESHandle<DTMtime> mTime;
00057 setup.get<DTMtimeRcd>().get(mTime);
00058 mTimeMap_ = &*mTime;
00059
00060
00061 setup.get<MuonGeometryRecord>().get(dtGeom_);
00062
00063 vDriftAlgo_->setES(setup);
00064 }
00065
00066 void DTVDriftWriter::endJob() {
00067
00068 DTMtime* mTimeNewMap = new DTMtime();
00069
00070 if(granularity_ == "bySL") {
00071
00072 const vector<DTSuperLayer*>& superLayers = dtGeom_->superLayers();
00073 vector<DTSuperLayer*>::const_iterator sl = superLayers.begin();
00074 vector<DTSuperLayer*>::const_iterator sl_end = superLayers.end();
00075 for(; sl != sl_end; ++sl){
00076 DTSuperLayerId slId = (*sl)->id();
00077
00078 float vDrift = 0., resolution = 0.;
00079
00080 int status = mTimeMap_->get(slId,vDrift,resolution,DTVelocityUnits::cm_per_ns);
00081
00082
00083 try{
00084 DTVDriftData vDriftData = vDriftAlgo_->compute(slId);
00085 float vDriftNew = vDriftData.vdrift;
00086 float resolutionNew = vDriftData.resolution;
00087
00088 mTimeNewMap->set(slId,
00089 vDriftNew,
00090 resolutionNew,
00091 DTVelocityUnits::cm_per_ns);
00092 LogVerbatim("Calibration") << "vDrift for: " << slId
00093 << " Mean " << vDriftNew
00094 << " Resolution " << resolutionNew;
00095 } catch(cms::Exception& e){
00096 LogError("Calibration") << e.explainSelf();
00097
00098 if(!status){
00099 mTimeNewMap->set(slId,
00100 vDrift,
00101 resolution,
00102 DTVelocityUnits::cm_per_ns);
00103 LogVerbatim("Calibration") << "Keep original vDrift for: " << slId
00104 << " Mean " << vDrift
00105 << " Resolution " << resolution;
00106 }
00107 }
00108 }
00109 }
00110
00111
00112 LogVerbatim("Calibration") << "[DTVDriftWriter]Writing vdrift object to DB!";
00113 string record = "DTMtimeRcd";
00114 DTCalibDBUtils::writeToDB<DTMtime>(record, mTimeNewMap);
00115 }