CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/CalibMuon/DTCalibration/plugins/DTTTrigCorrection.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/17 17:54:23 $
00006  *  $Revision: 1.10 $
00007  *  \author S. Maselli - INFN Torino
00008  *          A. Vilela Pereira
00009  */
00010 
00011 #include "DTTTrigCorrection.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/Records/interface/MuonGeometryRecord.h"
00019 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00020 #include "Geometry/DTGeometry/interface/DTSuperLayer.h"
00021 
00022 #include "CondFormats/DTObjects/interface/DTTtrig.h"
00023 #include "CondFormats/DataRecord/interface/DTTtrigRcd.h"
00024 
00025 #include "CalibMuon/DTCalibration/interface/DTCalibDBUtils.h"
00026 
00027 #include "CalibMuon/DTCalibration/interface/DTTTrigCorrectionFactory.h"
00028 #include "CalibMuon/DTCalibration/interface/DTTTrigBaseCorrection.h"
00029 
00030 #include <iostream>
00031 #include <fstream>
00032 
00033 using namespace edm;
00034 using namespace std;
00035 
00036 DTTTrigCorrection::DTTTrigCorrection(const ParameterSet& pset): 
00037   dbLabel_( pset.getUntrackedParameter<string>("dbLabel", "") ) {
00038 
00039   LogVerbatim("Calibration") << "[DTTTrigCorrection] Constructor called" << endl;
00040 
00041   // Get the concrete algo from the factory
00042   string theAlgoName = pset.getParameter<string>("correctionAlgo");
00043   correctionAlgo_ = DTTTrigCorrectionFactory::get()->create(theAlgoName,pset.getParameter<ParameterSet>("correctionAlgoConfig"));
00044 }
00045 
00046 DTTTrigCorrection::~DTTTrigCorrection(){
00047   LogVerbatim("Calibration") << "[DTTTrigCorrection] Destructor called" << endl;
00048   delete correctionAlgo_;
00049 }
00050 
00051 void DTTTrigCorrection::beginRun( const edm::Run& run, const edm::EventSetup& setup ) {
00052   // Get tTrig record from DB
00053   ESHandle<DTTtrig> tTrig;
00054   setup.get<DTTtrigRcd>().get(dbLabel_,tTrig);
00055   tTrigMap_ = &*tTrig;
00056   LogVerbatim("Calibration") << "[DTTTrigCorrection]: TTrig version: " << tTrig->version() << endl;
00057 
00058   // Get geometry from Event Setup
00059   setup.get<MuonGeometryRecord>().get(muonGeom_);
00060 
00061   // Pass EventSetup to correction Algo
00062   correctionAlgo_->setES(setup);
00063 }
00064 
00065 void DTTTrigCorrection::endJob() {
00066   // Create the object to be written to DB
00067   DTTtrig* tTrigNewMap = new DTTtrig();  
00068 
00069   for(vector<DTSuperLayer*>::const_iterator sl = muonGeom_->superLayers().begin();
00070                                             sl != muonGeom_->superLayers().end(); ++sl) {
00071     // Get old value from DB
00072     float tTrigMean,tTrigSigma,kFactor;
00073     int status = tTrigMap_->get((*sl)->id(),tTrigMean,tTrigSigma,kFactor,DTTimeUnits::ns);
00074 
00075     //Compute new ttrig
00076     try{
00077       DTTTrigData tTrigCorr = correctionAlgo_->correction((*sl)->id());
00078       float tTrigMeanNew = tTrigCorr.mean;
00079       float tTrigSigmaNew = tTrigCorr.sigma; 
00080       float kFactorNew = tTrigCorr.kFactor;
00081       tTrigNewMap->set((*sl)->id(),tTrigMeanNew,tTrigSigmaNew,kFactorNew,DTTimeUnits::ns);
00082 
00083       LogVerbatim("Calibration") << "New tTrig for: " << (*sl)->id()
00084                                  << " mean from " << tTrigMean << " to " << tTrigMeanNew
00085                                  << " sigma from " << tTrigSigma << " to " << tTrigSigmaNew
00086                                  << " kFactor from " << kFactor << " to " << kFactorNew << endl;
00087     } catch(cms::Exception& e){
00088       LogError("Calibration") << e.explainSelf();
00089       // Set db to the old value, if it was there in the first place
00090       if(!status){
00091          tTrigNewMap->set((*sl)->id(),tTrigMean,tTrigSigma,kFactor,DTTimeUnits::ns);
00092          LogVerbatim("Calibration") << "Keep old tTrig for: " << (*sl)->id()
00093                                     << " mean " << tTrigMean
00094                                     << " sigma " << tTrigSigma
00095                                     << " kFactor " << kFactor << endl;
00096       } 
00097       continue;
00098     }
00099   }//End of loop on superlayers 
00100 
00101   //Write object to DB
00102   LogVerbatim("Calibration") << "[DTTTrigCorrection]: Writing ttrig object to DB!" << endl;
00103   string record = "DTTtrigRcd";
00104   DTCalibDBUtils::writeToDB<DTTtrig>(record, tTrigNewMap);
00105 } 
00106 
00107 
00108