CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/CalibMuon/DTCalibration/plugins/DTTTrigFillWithAverage.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2010/02/16 10:03:23 $
00005  *  $Revision: 1.3 $
00006  *  \author A. Vilela Pereira
00007  */
00008 
00009 #include "DTTTrigFillWithAverage.h"
00010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00012 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00013 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00014 #include "DataFormats/MuonDetId/interface/DTSuperLayerId.h"
00015 #include "CondFormats/DTObjects/interface/DTTtrig.h"
00016 #include "CondFormats/DataRecord/interface/DTTtrigRcd.h"
00017 
00018 using namespace std;
00019 using namespace edm;
00020 
00021 DTTTrigFillWithAverage::DTTTrigFillWithAverage(const ParameterSet& pset):foundAverage_(false) {
00022   dbLabel  = pset.getUntrackedParameter<string>("dbLabel", "");
00023 }
00024 
00025 DTTTrigFillWithAverage::~DTTTrigFillWithAverage() {}
00026 
00027 void DTTTrigFillWithAverage::setES(const EventSetup& setup) {
00028   // Get tTrig record from DB
00029   ESHandle<DTTtrig> tTrig;
00030   setup.get<DTTtrigRcd>().get(dbLabel,tTrig);
00031   tTrigMap_ = &*tTrig;
00032 
00033   // Get geometry from Event Setup
00034   setup.get<MuonGeometryRecord>().get(muonGeom_);
00035 }
00036 
00037 DTTTrigData DTTTrigFillWithAverage::correction(const DTSuperLayerId& slId) {
00038   float tTrigMean,tTrigSigma, kFactor;
00039   int status = tTrigMap_->get(slId,tTrigMean,tTrigSigma,kFactor,DTTimeUnits::ns);
00040   if(!status){
00041     return DTTTrigData(tTrigMean,tTrigSigma,kFactor);
00042   } else {
00043     if(!foundAverage_) getAverage();
00044     float corrMean = initialTTrig_.aveMean;
00045     float corrSigma = initialTTrig_.aveSigma;
00046     float corrKFactor = initialTTrig_.aveKFactor; 
00047     return DTTTrigData(corrMean,corrSigma,corrKFactor); //FIXME: kFactor is not anymore a unique one
00048   } 
00049 }
00050 
00051 void DTTTrigFillWithAverage::getAverage() {
00052   //Get the superlayers list
00053   vector<DTSuperLayer*> dtSupLylist = muonGeom_->superLayers();
00054 
00055   float aveMean = 0.;
00056   float ave2Mean = 0.;
00057   float aveSigma = 0.;
00058   float ave2Sigma = 0.;
00059   float aveKFactor = 0.;
00060   int nIter = 0;
00061   
00062   for(vector<DTSuperLayer*>::const_iterator sl = muonGeom_->superLayers().begin();
00063                                             sl != muonGeom_->superLayers().end(); ++sl) {
00064     float tTrigMean,tTrigSigma,kFactor;
00065     int status = tTrigMap_->get((*sl)->id(),tTrigMean,tTrigSigma,kFactor,DTTimeUnits::ns);
00066     if(!status){
00067       ++nIter;
00068       aveMean += tTrigMean;
00069       ave2Mean += tTrigMean*tTrigMean;
00070       aveSigma += tTrigSigma;
00071       ave2Sigma += tTrigSigma*tTrigSigma;
00072       aveKFactor += kFactor;
00073     }
00074   }
00075 
00076   // Compute average
00077   aveMean /= nIter;
00078   float rmsMean = ave2Mean/(nIter - 1) - aveMean*aveMean;
00079   rmsMean = sqrt(rmsMean);
00080   aveSigma /= nIter;
00081   float rmsSigma = ave2Sigma/(nIter - 1) - aveSigma*aveSigma;
00082   rmsSigma = sqrt(rmsSigma);
00083   aveKFactor /= nIter;  
00084 
00085   initialTTrig_.aveMean = aveMean;
00086   initialTTrig_.rmsMean = rmsMean;
00087   initialTTrig_.aveSigma = aveSigma;
00088   initialTTrig_.rmsSigma = rmsSigma;
00089   initialTTrig_.aveKFactor = aveKFactor;
00090 
00091   LogVerbatim("Calibration") << "[DTTTrigFillWithAverage] Found from " << nIter << " SL's\n"
00092                              << "                               average tTrig mean: " << aveMean << "\n"
00093                              << "                               tTrig mean RMS: " << rmsMean << "\n"
00094                              << "                               average tTrig sigma: " << aveSigma << "\n"
00095                              << "                               tTrig sigma RMS: " << rmsSigma << "\n" 
00096                              << "                               kFactor mean: " << aveKFactor;
00097   foundAverage_ = true;
00098 }