CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/CalibMuon/DTCalibration/plugins/DTVDriftWriter.cc

Go to the documentation of this file.
00001 
00002 /*
00003  *  See header file for a description of this class.
00004  *
00005  *  $Date: 2010/11/19 14:02:08 $
00006  *  $Revision: 1.11 $
00007  *  Author of original version: M. Giunta
00008  *  \author A. Vilela Pereira
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   // Get the concrete algo from the factory
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   // Get the map of ttrig from the Setup
00056   ESHandle<DTMtime> mTime;
00057   setup.get<DTMtimeRcd>().get(mTime);
00058   mTimeMap_ = &*mTime;
00059 
00060   // Get geometry from Event Setup
00061   setup.get<MuonGeometryRecord>().get(dtGeom_);
00062   // Pass EventSetup to concrete implementation
00063   vDriftAlgo_->setES(setup); 
00064 }
00065 
00066 void DTVDriftWriter::endJob() {
00067   // Create the object to be written to DB
00068   DTMtime* mTimeNewMap = new DTMtime();
00069 
00070   if(granularity_ == "bySL") {    
00071      // Get all the sls from the geometry
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         // Get original value from DB
00078         float vDrift = 0., resolution = 0.;
00079         // vdrift is cm/ns , resolution is cm
00080         int status = mTimeMap_->get(slId,vDrift,resolution,DTVelocityUnits::cm_per_ns);
00081 
00082         // Compute vDrift
00083         try{
00084            DTVDriftData vDriftData = vDriftAlgo_->compute(slId);
00085            float vDriftNew = vDriftData.vdrift;
00086            float resolutionNew = vDriftData.resolution; 
00087            // vdrift is cm/ns , resolution is cm
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            // Go back to original value in case of error
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      } // End of loop on superlayers
00109   }
00110 
00111   // Write the vDrift object to DB
00112   LogVerbatim("Calibration") << "[DTVDriftWriter]Writing vdrift object to DB!";
00113   string record = "DTMtimeRcd";
00114   DTCalibDBUtils::writeToDB<DTMtime>(record, mTimeNewMap);
00115 }