Go to the documentation of this file.00001
00002
00003
00004
00005
00006
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 namespace dtCalibration {
00022
00023 DTTTrigFillWithAverage::DTTTrigFillWithAverage(const ParameterSet& pset):foundAverage_(false) {
00024 dbLabel = pset.getUntrackedParameter<string>("dbLabel", "");
00025 }
00026
00027 DTTTrigFillWithAverage::~DTTTrigFillWithAverage() {}
00028
00029 void DTTTrigFillWithAverage::setES(const EventSetup& setup) {
00030
00031 ESHandle<DTTtrig> tTrig;
00032 setup.get<DTTtrigRcd>().get(dbLabel,tTrig);
00033 tTrigMap_ = &*tTrig;
00034
00035
00036 setup.get<MuonGeometryRecord>().get(muonGeom_);
00037 }
00038
00039 DTTTrigData DTTTrigFillWithAverage::correction(const DTSuperLayerId& slId) {
00040 float tTrigMean,tTrigSigma, kFactor;
00041 int status = tTrigMap_->get(slId,tTrigMean,tTrigSigma,kFactor,DTTimeUnits::ns);
00042 if(!status){
00043 return DTTTrigData(tTrigMean,tTrigSigma,kFactor);
00044 } else {
00045 if(!foundAverage_) getAverage();
00046 float corrMean = initialTTrig_.aveMean;
00047 float corrSigma = initialTTrig_.aveSigma;
00048 float corrKFactor = initialTTrig_.aveKFactor;
00049 return DTTTrigData(corrMean,corrSigma,corrKFactor);
00050 }
00051 }
00052
00053 void DTTTrigFillWithAverage::getAverage() {
00054
00055 vector<DTSuperLayer*> dtSupLylist = muonGeom_->superLayers();
00056
00057 float aveMean = 0.;
00058 float ave2Mean = 0.;
00059 float aveSigma = 0.;
00060 float ave2Sigma = 0.;
00061 float aveKFactor = 0.;
00062 int nIter = 0;
00063
00064 for(vector<DTSuperLayer*>::const_iterator sl = muonGeom_->superLayers().begin();
00065 sl != muonGeom_->superLayers().end(); ++sl) {
00066 float tTrigMean,tTrigSigma,kFactor;
00067 int status = tTrigMap_->get((*sl)->id(),tTrigMean,tTrigSigma,kFactor,DTTimeUnits::ns);
00068 if(!status){
00069 ++nIter;
00070 aveMean += tTrigMean;
00071 ave2Mean += tTrigMean*tTrigMean;
00072 aveSigma += tTrigSigma;
00073 ave2Sigma += tTrigSigma*tTrigSigma;
00074 aveKFactor += kFactor;
00075 }
00076 }
00077
00078
00079 aveMean /= nIter;
00080 float rmsMean = ave2Mean/(nIter - 1) - aveMean*aveMean;
00081 rmsMean = sqrt(rmsMean);
00082 aveSigma /= nIter;
00083 float rmsSigma = ave2Sigma/(nIter - 1) - aveSigma*aveSigma;
00084 rmsSigma = sqrt(rmsSigma);
00085 aveKFactor /= nIter;
00086
00087 initialTTrig_.aveMean = aveMean;
00088 initialTTrig_.rmsMean = rmsMean;
00089 initialTTrig_.aveSigma = aveSigma;
00090 initialTTrig_.rmsSigma = rmsSigma;
00091 initialTTrig_.aveKFactor = aveKFactor;
00092
00093 LogVerbatim("Calibration") << "[DTTTrigFillWithAverage] Found from " << nIter << " SL's\n"
00094 << " average tTrig mean: " << aveMean << "\n"
00095 << " tTrig mean RMS: " << rmsMean << "\n"
00096 << " average tTrig sigma: " << aveSigma << "\n"
00097 << " tTrig sigma RMS: " << rmsSigma << "\n"
00098 << " kFactor mean: " << aveKFactor;
00099 foundAverage_ = true;
00100 }
00101
00102 }