CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/CalibMuon/DTCalibration/plugins/DTVDriftSegment.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.3 $
00007  *  \author A. Vilela Pereira
00008  */
00009 
00010 #include "DTVDriftSegment.h"
00011 
00012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00013 #include "FWCore/Framework/interface/ESHandle.h"
00014 #include "FWCore/Framework/interface/EventSetup.h"
00015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00016 
00017 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00018 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00019 #include "CondFormats/DTObjects/interface/DTMtime.h"
00020 #include "CondFormats/DataRecord/interface/DTMtimeRcd.h"
00021 
00022 #include "CalibMuon/DTCalibration/interface/DTResidualFitter.h"
00023 #include "CalibMuon/DTCalibration/interface/DTCalibDBUtils.h"
00024 
00025 #include <string>
00026 #include <vector>
00027 
00028 #include "TH1F.h"
00029 #include "TFile.h"
00030 
00031 using namespace std;
00032 using namespace edm;
00033 
00034 DTVDriftSegment::DTVDriftSegment(const ParameterSet& pset):
00035   nSigmas_( pset.getUntrackedParameter<unsigned int>("nSigmasFitRange", 1) ) {
00036 
00037   string rootFileName = pset.getParameter<string>("rootFileName");
00038   rootFile_ = new TFile(rootFileName.c_str(), "READ");
00039 
00040   bool debug = pset.getUntrackedParameter<bool>("debug",false);
00041   fitter_ = new DTResidualFitter(debug);
00042   //bool debug = pset.getUntrackedParameter<bool>("debug", false);
00043   //if(debug) fitter_->setVerbosity(1);
00044 }
00045 
00046 DTVDriftSegment::~DTVDriftSegment() {
00047   rootFile_->Close();
00048   delete fitter_;
00049 }
00050 
00051 void DTVDriftSegment::setES(const edm::EventSetup& setup) {
00052   // Get the map of vdrift from the setup
00053   ESHandle<DTMtime> mTime;
00054   setup.get<DTMtimeRcd>().get(mTime);
00055   mTimeMap_ = &*mTime;
00056 }
00057 
00058 DTVDriftData DTVDriftSegment::compute(DTSuperLayerId const& slId) {
00059 
00060   // Get original value from DB; vdrift is cm/ns , resolution is cm
00061   float vDrift = 0., resolution = 0.;
00062   int status = mTimeMap_->get(slId,vDrift,resolution,DTVelocityUnits::cm_per_ns);
00063 
00064   if(status != 0) throw cms::Exception("DTCalibration") << "Could not find vDrift entry in DB for"
00065                                                         << slId << endl;
00066 
00067   // For RZ superlayers use original value
00068   if(slId.superLayer() == 2){
00069      LogTrace("Calibration") << "[DTVDriftSegment]: RZ superlayer\n"
00070                              << "                   Will use original vDrift and resolution.";
00071      return DTVDriftData(vDrift,resolution);
00072   } else{
00073      TH1F* vDriftCorrHisto = getHisto(slId);
00074      // If empty histogram 
00075      if(vDriftCorrHisto->GetEntries() == 0){
00076         LogError("Calibration") << "[DTVDriftSegment]: Histogram " << vDriftCorrHisto->GetName() << " is empty.\n"
00077                                 << "                   Will use original vDrift and resolution.";
00078         return DTVDriftData(vDrift,resolution);                              
00079      }
00080    
00081      LogTrace("Calibration") << "[DTVDriftSegment]: Fitting histogram " << vDriftCorrHisto->GetName(); 
00082      DTResidualFitResult fitResult = fitter_->fitResiduals(*vDriftCorrHisto,nSigmas_);
00083      LogTrace("Calibration") << "[DTVDriftSegment]: \n"
00084                              << "   Fit Mean  = " << fitResult.fitMean << " +/- "
00085                                                   << fitResult.fitMeanError << "\n"
00086                              << "   Fit Sigma = " << fitResult.fitSigma << " +/- "
00087                                                   << fitResult.fitSigmaError;
00088 
00089      float vDriftCorr = fitResult.fitMean;
00090      float vDriftNew = vDrift*(1. - vDriftCorr); 
00091      float resolutionNew = resolution;
00092      return DTVDriftData(vDriftNew,resolutionNew);
00093   }
00094 }
00095 
00096 TH1F* DTVDriftSegment::getHisto(const DTSuperLayerId& slId) {
00097   string histoName = getHistoName(slId);
00098   TH1F* histo = static_cast<TH1F*>(rootFile_->Get(histoName.c_str()));
00099   if(!histo) throw cms::Exception("DTCalibration") << "v-drift correction histogram not found:"
00100                                                    << histoName << endl; 
00101   return histo;
00102 }
00103 
00104 string DTVDriftSegment::getHistoName(const DTSuperLayerId& slId) {
00105   DTChamberId chId = slId.chamberId();
00106 
00107   // Compose the chamber name
00108   stringstream wheel; wheel << chId.wheel();
00109   stringstream station; station << chId.station();
00110   stringstream sector; sector << chId.sector();
00111 
00112   string chHistoName =
00113     "_W" + wheel.str() +
00114     "_St" + station.str() +
00115     "_Sec" + sector.str();
00116 
00117   return (slId.superLayer() != 2)?("hRPhiVDriftCorr" + chHistoName):("hRZVDriftCorr" + chHistoName);
00118 }
00119