29 #include "RooRealVar.h"
30 #include "RooDataHist.h"
31 #include "RooGaussian.h"
32 #include "RooAddPdf.h"
33 #include "RooFitResult.h"
34 #include "RooGlobalFunc.h"
43 string residualsRootFile = pset.
getParameter<
string>(
"residualsRootFile");
44 rootFile_ =
new TFile(residualsRootFile.c_str(),
"READ");
56 int tmp_wheel = 0, tmp_sector = 0, tmp_station = 0, tmp_SL = 0;
57 double tmp_ttrig = 0., tmp_t0 = 0., tmp_kfact = 0.;
58 int tmp_a = 0, tmp_b = 0, tmp_c = 0, tmp_d = 0;
59 double tmp_v_eff = 0.;
60 while(!fileSlopes.eof()){
61 fileSlopes >> tmp_wheel >> tmp_sector >> tmp_station >> tmp_SL >> tmp_a >> tmp_b >>
62 tmp_ttrig >> tmp_t0 >> tmp_kfact >> tmp_c >> tmp_d >> tmp_v_eff;
63 vDriftEff_[tmp_wheel+2][tmp_sector-1][tmp_station-1][tmp_SL-1] = -tmp_v_eff;
87 mTimeMap_ = &*mTimeHandle;
93 float tTrigMean,tTrigSigma,kFactor;
95 if(status != 0)
throw cms::Exception(
"[DTTTrigResidualCorrection]") <<
"Could not find tTrig entry in DB for"
98 float vDrift,hitResolution;
100 if(status != 0)
throw cms::Exception(
"[DTTTrigResidualCorrection]") <<
"Could not find vDrift entry in DB for"
102 TH1F residualHisto = *(
getHisto(slId));
103 LogTrace(
"Calibration") <<
"[DTTTrigResidualCorrection]: \n"
104 <<
" Mean, RMS = " << residualHisto.GetMean() <<
", " << residualHisto.GetRMS();
106 double fitMean = -1.;
107 double fitSigma = -1.;
109 LogTrace(
"Calibration") <<
"[DTTTrigResidualCorrection]: Fitting histogram " << residualHisto.GetName();
110 const bool originalFit =
false;
112 RooRealVar
x(
"x",
"residual",-1.,1.);
113 RooRealVar
mean(
"mean",
"mean",residualHisto.GetMean(),-0.3,0.3);
114 RooRealVar sigma1(
"sigma1",
"sigma1",0.,0.5);
115 RooRealVar sigma2(
"sigma2",
"sigma2",0.,0.5);
117 RooRealVar
frac(
"frac",
"frac",0.,1.);
119 RooGaussian myg1(
"myg1",
"Gaussian distribution",x,mean,sigma1);
120 RooGaussian myg2(
"myg2",
"Gaussian distribution",x,mean,sigma2);
122 RooAddPdf myg(
"myg",
"myg",RooArgList(myg1,myg2),RooArgList(frac));
124 RooDataHist hdata(
"hdata",
"Binned data",RooArgList(x),&residualHisto);
127 fitMean = mean.getVal();
128 fitSigma = sigma1.getVal();
135 LogTrace(
"Calibration") <<
"[DTTTrigResidualCorrection]: \n"
136 <<
" Fit Mean = " << fitMean <<
"\n"
137 <<
" Fit Sigma = " << fitSigma;
139 double resMean = (useFit_) ? fitMean : residualHisto.GetMean();
141 int wheel = slId.
wheel();
142 int sector = slId.
sector();
147 double vdrift_eff = vDriftEff_[wheel+2][sector-1][station-1][superLayer-1];
148 if(vdrift_eff == 0) vdrift_eff = vDrift;
150 if(vdrift_eff) resTime = resMean/vdrift_eff;
152 LogTrace(
"Calibration") <<
"[DTTTrigResidualCorrection]: Effective vDrift, correction to tTrig = "
153 << vdrift_eff <<
", " << resTime;
155 if(vDrift) resTime = resMean/vDrift;
157 LogTrace(
"Calibration") <<
"[DTTTrigResidualCorrection]: vDrift from DB, correction to tTrig = "
158 << vDrift <<
", " << resTime;
161 double corrMean = tTrigMean;
162 double corrSigma = (tTrigSigma != 0.) ? tTrigSigma : 1.;
163 double corrKFact = (tTrigSigma != 0.) ? (kFactor + resTime/tTrigSigma) : resTime;
170 LogTrace(
"Calibration") <<
"[DTTTrigResidualCorrection]: Accessing histogram " << histoName.c_str();
171 TH1F*
histo =
static_cast<TH1F*
>(rootFile_->Get(histoName.c_str()));
172 if(!histo)
throw cms::Exception(
"[DTTTrigResidualCorrection]") <<
"residual histogram not found:"
173 << histoName << endl;
180 stringstream wheel; wheel << slId.
wheel();
182 stringstream sector; sector << slId.
sector();
183 stringstream superLayer; superLayer << slId.
superlayer();
187 rootBaseDir_ +
"/Wheel" + wheel.str() +
188 "/Station" + station.str() +
189 "/Sector" + sector.str() +
190 "/hResDist_STEP" + Step.str() +
192 "_St" + station.str() +
193 "_Sec" + sector.str() +
194 "_SL" + superLayer.str();
virtual ~DTTTrigResidualCorrection()
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
DTTTrigResidualCorrection(const edm::ParameterSet &)
std::string getHistoName(const DTSuperLayerId &slID)
int superLayer() const
Return the superlayer number.
int superlayer() const
Return the superlayer number (deprecated method name)
PixelRecoRange< float > Range
virtual void setES(const edm::EventSetup &setup)
const TH1F * getHisto(const DTSuperLayerId &)
virtual DTTTrigData correction(const DTSuperLayerId &)
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="")