CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/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: 2012/03/02 19:47:33 $
00006  *  $Revision: 1.4 $
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 namespace dtCalibration {
00035 
00036 DTVDriftSegment::DTVDriftSegment(const ParameterSet& pset):
00037   nSigmas_( pset.getUntrackedParameter<unsigned int>("nSigmasFitRange", 1) ) {
00038 
00039   string rootFileName = pset.getParameter<string>("rootFileName");
00040   rootFile_ = new TFile(rootFileName.c_str(), "READ");
00041 
00042   bool debug = pset.getUntrackedParameter<bool>("debug",false);
00043   fitter_ = new DTResidualFitter(debug);
00044   //bool debug = pset.getUntrackedParameter<bool>("debug", false);
00045   //if(debug) fitter_->setVerbosity(1);
00046 }
00047 
00048 DTVDriftSegment::~DTVDriftSegment() {
00049   rootFile_->Close();
00050   delete fitter_;
00051 }
00052 
00053 void DTVDriftSegment::setES(const edm::EventSetup& setup) {
00054   // Get the map of vdrift from the setup
00055   ESHandle<DTMtime> mTime;
00056   setup.get<DTMtimeRcd>().get(mTime);
00057   mTimeMap_ = &*mTime;
00058 }
00059 
00060 DTVDriftData DTVDriftSegment::compute(DTSuperLayerId const& slId) {
00061 
00062   // Get original value from DB; vdrift is cm/ns , resolution is cm
00063   float vDrift = 0., resolution = 0.;
00064   int status = mTimeMap_->get(slId,vDrift,resolution,DTVelocityUnits::cm_per_ns);
00065 
00066   if(status != 0) throw cms::Exception("DTCalibration") << "Could not find vDrift entry in DB for"
00067                                                         << slId << endl;
00068 
00069   // For RZ superlayers use original value
00070   if(slId.superLayer() == 2){
00071      LogTrace("Calibration") << "[DTVDriftSegment]: RZ superlayer\n"
00072                              << "                   Will use original vDrift and resolution.";
00073      return DTVDriftData(vDrift,resolution);
00074   } else{
00075      TH1F* vDriftCorrHisto = getHisto(slId);
00076      // If empty histogram 
00077      if(vDriftCorrHisto->GetEntries() == 0){
00078         LogError("Calibration") << "[DTVDriftSegment]: Histogram " << vDriftCorrHisto->GetName() << " is empty.\n"
00079                                 << "                   Will use original vDrift and resolution.";
00080         return DTVDriftData(vDrift,resolution);                              
00081      }
00082    
00083      LogTrace("Calibration") << "[DTVDriftSegment]: Fitting histogram " << vDriftCorrHisto->GetName(); 
00084      DTResidualFitResult fitResult = fitter_->fitResiduals(*vDriftCorrHisto,nSigmas_);
00085      LogTrace("Calibration") << "[DTVDriftSegment]: \n"
00086                              << "   Fit Mean  = " << fitResult.fitMean << " +/- "
00087                                                   << fitResult.fitMeanError << "\n"
00088                              << "   Fit Sigma = " << fitResult.fitSigma << " +/- "
00089                                                   << fitResult.fitSigmaError;
00090 
00091      float vDriftCorr = fitResult.fitMean;
00092      float vDriftNew = vDrift*(1. - vDriftCorr); 
00093      float resolutionNew = resolution;
00094      return DTVDriftData(vDriftNew,resolutionNew);
00095   }
00096 }
00097 
00098 TH1F* DTVDriftSegment::getHisto(const DTSuperLayerId& slId) {
00099   string histoName = getHistoName(slId);
00100   TH1F* histo = static_cast<TH1F*>(rootFile_->Get(histoName.c_str()));
00101   if(!histo) throw cms::Exception("DTCalibration") << "v-drift correction histogram not found:"
00102                                                    << histoName << endl; 
00103   return histo;
00104 }
00105 
00106 string DTVDriftSegment::getHistoName(const DTSuperLayerId& slId) {
00107   DTChamberId chId = slId.chamberId();
00108 
00109   // Compose the chamber name
00110   stringstream wheel; wheel << chId.wheel();
00111   stringstream station; station << chId.station();
00112   stringstream sector; sector << chId.sector();
00113 
00114   string chHistoName =
00115     "_W" + wheel.str() +
00116     "_St" + station.str() +
00117     "_Sec" + sector.str();
00118 
00119   return (slId.superLayer() != 2)?("hRPhiVDriftCorr" + chHistoName):("hRZVDriftCorr" + chHistoName);
00120 }
00121 
00122 } // namespace