27 #include "RooRealVar.h"
28 #include "RooDataHist.h"
29 #include "RooGaussian.h"
30 #include "RooAddPdf.h"
31 #include "RooFitResult.h"
32 #include "RooGlobalFunc.h"
41 namespace dtCalibration {
43 DTTTrigResidualCorrection::DTTTrigResidualCorrection(
const ParameterSet& pset) {
44 string residualsRootFile = pset.
getParameter<
string>(
"residualsRootFile");
45 rootFile_ =
new TFile(residualsRootFile.c_str(),
"READ");
57 int tmp_wheel = 0, tmp_sector = 0, tmp_station = 0, tmp_SL = 0;
58 double tmp_ttrig = 0., tmp_t0 = 0., tmp_kfact = 0.;
59 int tmp_a = 0, tmp_b = 0, tmp_c = 0, tmp_d = 0;
60 double tmp_v_eff = 0.;
61 while(!fileSlopes.eof()){
62 fileSlopes >> tmp_wheel >> tmp_sector >> tmp_station >> tmp_SL >> tmp_a >> tmp_b >>
63 tmp_ttrig >> tmp_t0 >> tmp_kfact >> tmp_c >> tmp_d >> tmp_v_eff;
64 vDriftEff_[tmp_wheel+2][tmp_sector-1][tmp_station-1][tmp_SL-1] = -tmp_v_eff;
73 DTTTrigResidualCorrection::~DTTTrigResidualCorrection() {
88 mTimeMap_ = &*mTimeHandle;
94 float tTrigMean,tTrigSigma,kFactor;
96 if(status != 0)
throw cms::Exception(
"[DTTTrigResidualCorrection]") <<
"Could not find tTrig entry in DB for"
99 float vDrift,hitResolution;
101 if(status != 0)
throw cms::Exception(
"[DTTTrigResidualCorrection]") <<
"Could not find vDrift entry in DB for"
103 TH1F residualHisto = *(
getHisto(slId));
104 LogTrace(
"Calibration") <<
"[DTTTrigResidualCorrection]: \n"
105 <<
" Mean, RMS = " << residualHisto.GetMean() <<
", " << residualHisto.GetRMS();
107 double fitMean = -1.;
108 double fitSigma = -1.;
110 LogTrace(
"Calibration") <<
"[DTTTrigResidualCorrection]: Fitting histogram " << residualHisto.GetName();
111 const bool originalFit =
false;
113 RooRealVar
x(
"x",
"residual",-1.,1.);
114 RooRealVar
mean(
"mean",
"mean",residualHisto.GetMean(),-0.3,0.3);
115 RooRealVar sigma1(
"sigma1",
"sigma1",0.,0.5);
116 RooRealVar sigma2(
"sigma2",
"sigma2",0.,0.5);
118 RooRealVar
frac(
"frac",
"frac",0.,1.);
120 RooGaussian myg1(
"myg1",
"Gaussian distribution",x,mean,sigma1);
121 RooGaussian myg2(
"myg2",
"Gaussian distribution",x,mean,sigma2);
123 RooAddPdf myg(
"myg",
"myg",RooArgList(myg1,myg2),RooArgList(frac));
125 RooDataHist hdata(
"hdata",
"Binned data",RooArgList(x),&residualHisto);
128 fitMean = mean.getVal();
129 fitSigma = sigma1.getVal();
136 LogTrace(
"Calibration") <<
"[DTTTrigResidualCorrection]: \n"
137 <<
" Fit Mean = " << fitMean <<
"\n"
138 <<
" Fit Sigma = " << fitSigma;
140 double resMean = (useFit_) ? fitMean : residualHisto.GetMean();
142 int wheel = slId.
wheel();
143 int sector = slId.
sector();
148 double vdrift_eff = vDriftEff_[wheel+2][sector-1][station-1][superLayer-1];
149 if(vdrift_eff == 0) vdrift_eff = vDrift;
151 if(vdrift_eff) resTime = resMean/vdrift_eff;
153 LogTrace(
"Calibration") <<
"[DTTTrigResidualCorrection]: Effective vDrift, correction to tTrig = "
154 << vdrift_eff <<
", " << resTime;
156 if(vDrift) resTime = resMean/vDrift;
158 LogTrace(
"Calibration") <<
"[DTTTrigResidualCorrection]: vDrift from DB, correction to tTrig = "
159 << vDrift <<
", " << resTime;
162 double corrMean = tTrigMean;
163 double corrSigma = (tTrigSigma != 0.) ? tTrigSigma : 1.;
164 double corrKFact = (tTrigSigma != 0.) ? (kFactor + resTime/tTrigSigma) : resTime;
171 LogTrace(
"Calibration") <<
"[DTTTrigResidualCorrection]: Accessing histogram " << histoName.c_str();
172 TH1F*
histo =
static_cast<TH1F*
>(rootFile_->Get(histoName.c_str()));
173 if(!histo)
throw cms::Exception(
"[DTTTrigResidualCorrection]") <<
"residual histogram not found:"
174 << histoName << endl;
181 stringstream wheel; wheel << slId.
wheel();
183 stringstream sector; sector << slId.
sector();
184 stringstream superLayer; superLayer << slId.
superlayer();
188 rootBaseDir_ +
"/Wheel" + wheel.str() +
189 "/Station" + station.str() +
190 "/Sector" + sector.str() +
191 "/hResDist_STEP" + Step.str() +
193 "_St" + station.str() +
194 "_Sec" + sector.str() +
195 "_SL" + superLayer.str();
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
T x() const
Cartesian x coordinate.
int superLayer() const
Return the superlayer number.
int superlayer() const
Return the superlayer number (deprecated method name)
PixelRecoRange< float > Range
std::string fullPath() const
int station() const
Return the station number.
int wheel() const
Return the wheel number.
TH1F * getHisto(std::string name, std::string process, DQMStore *dbe_, bool verb=false, bool clone=false)
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")