6 #include "GaudiKernel/ITHistSvc.h"
9 #include <RooRealVar.h>
10 #include <RooDataSet.h>
11 #include <RooArgSet.h>
13 using namespace RooFit;
14 using namespace InDet;
16 InDetBeamSpotRooFit::InDetBeamSpotRooFit(
const std::string&
type,
17 const std::string&
name,
20 m_cov(10), m_ax(0),m_ay(0),m_k(0),
21 m_mx(0),m_my(0),m_mz(0),m_rho(0),
22 m_sx(0),m_sy(0),m_sz(0),m_nUsed(0),
24 m_fitStatus(unsolved),m_vtxResCut(0)
26 declareInterface<IInDetBeamSpotTool>(
this);
37 m_cov(10), m_ax(0),m_ay(0),m_k(0),
38 m_mx(0),m_my(0),m_mz(0),m_rho(0),
39 m_sx(0),m_sy(0),m_sz(0),m_nUsed(0),
41 m_fitStatus(unsolved),
42 m_vtxResCut(rhs.m_vtxResCut),
43 m_kStart(rhs.m_kStart),
44 m_rmsCutNum(rhs.m_rmsCutNum),
45 m_kConst(rhs.m_kConst)
50 return StatusCode::SUCCESS;
55 return StatusCode::SUCCESS;
91 RooRealVar
x(
"x",
"Primary Vertex x [mm]",xMin,xMax);
92 RooRealVar
y(
"y",
"Primary Vertex y [mm]",yMin,yMax);
93 RooRealVar
z(
"z",
"Primary Vertex z [mm]",zMin,zMax);
94 RooRealVar
vxx(
"vxx",
"vxx [mm^2]",vxxMin,vxxMax);
95 RooRealVar
vyy(
"vyy",
"vyy [mm^2]",vyyMin,vyyMax);
96 RooRealVar
vxy(
"vxy",
"vyy [mm^2]",vxyMin,vxyMax);
101 +
" && abs(vxy) < 1000.";
105 RooDataSet rfData(
"rfData",
"RooFit data",RooArgSet(
x,
y,
z,
vxx,
vyy,
vxy));
121 auto reducedDSvtxCut = std::unique_ptr<RooAbsData>(rfData.reduce(
Cut(vtxCut)));
123 Double_t vxxMean = reducedDSvtxCut->mean(
vxx);
124 Double_t vyyMean = reducedDSvtxCut->mean(
vyy);
125 Double_t axStart = 0, ayStart = 0, kStart =
m_kStart;
126 Double_t wxxStart = reducedDSvtxCut->sigma(
x);
127 Double_t wyyStart = reducedDSvtxCut->sigma(
y);
128 Double_t sxStart = sqrt(std::abs(wxxStart*wxxStart - kStart*kStart*vxxMean));
129 Double_t syStart = sqrt(std::abs(wyyStart*wyyStart - kStart*kStart*vyyMean));
130 Double_t szStart = reducedDSvtxCut->sigma(
z);
131 Double_t mxStart = reducedDSvtxCut->mean(
x);
132 Double_t myStart = reducedDSvtxCut->mean(
y);
133 Double_t mzStart = reducedDSvtxCut->mean(
z);
134 Double_t rhoStart = 0;
136 RooRealVar
ax(
"ax",
"Tilt x",axStart,-1,1);
137 RooRealVar
ay(
"ay",
"Tilt y",ayStart,-1,1);
138 RooRealVar
k(
"k",
"k factor",kStart,0,3);
140 RooRealVar
mx(
"mx",
"Mean x",mxStart,xMin,xMax);
141 RooRealVar
my(
"my",
"Mean y",myStart,yMin,yMax);
142 RooRealVar
mz(
"mz",
"Mean z",mzStart,zMin,zMax);
143 RooRealVar
rho(
"rho",
"x-y correlation",rhoStart,-1,1);
144 RooRealVar
sx(
"sx",
"Width x",sxStart,0,1);
145 RooRealVar
sy(
"sy",
"Width y",syStart,0,1);
146 RooRealVar
sz(
"sz",
"Width z",szStart,1,200);
151 BeamSpotPdf fitModel(
"fitModel",
"BeamSpot PDF",
x,
y,
z,
vxx,
vyy,
vxy,
mx,
sx,
ax,
my,
sy,
ay,
mz,
sz,
k,
rho);
159 double rmsCutXLow = mxStart -
m_rmsCutNum * wxxStart;
160 double rmsCutXHigh = mxStart +
m_rmsCutNum * wxxStart;
161 double rmsCutYLow = myStart -
m_rmsCutNum * wyyStart;
162 double rmsCutYHigh = myStart +
m_rmsCutNum * wyyStart;
163 double rmsCutZLow = mzStart -
m_rmsCutNum * szStart;
164 double rmsCutZHigh = mzStart +
m_rmsCutNum * szStart;
166 std::ostringstream
ss;
167 ss <<
"x > " << rmsCutXLow <<
" && "
168 <<
"x < " << rmsCutXHigh <<
" && "
169 <<
"y > " << rmsCutYLow <<
" && "
170 <<
"y < " << rmsCutYHigh <<
" && "
171 <<
"z > " << rmsCutZLow <<
" && "
172 <<
"z < " << rmsCutZHigh;
173 std::string rmsCutString =
ss.str();
175 std::string combinedCutString =
m_vtxCutString + std::string(
" && ") + rmsCutString;
176 const char *combinedCut = (
const char*)combinedCutString.c_str();
188 auto reducedDScombinedCut = std::unique_ptr<RooAbsData>(rfData.reduce(
Cut(combinedCut)));
190 RooFitResult *
r = fitModel.fitTo( *(reducedDScombinedCut.get()) ,ConditionalObservables(RooArgSet(
vxx,
vyy,
vxy)),Save(),PrintLevel(-1),PrintEvalErrors(-1));
193 m_nUsed = reducedDScombinedCut->numEntries();
196 << reducedDScombinedCut->numEntries()<<
" vertices will be used in the ML fit.") ;
199 if (
r->edm() <= 10
e-04 &&
r->covQual() == 3){
217 m_cov =
r->covarianceMatrix();
232 const std::string offDiagArr[] = {
"TiltX",
"TiltY",
"k",
"X",
"Y",
"Z",
"RhoXY",
"Sx",
"Sy",
"Sz"};
233 const std::string diagArr[] = {
"tiltX",
"tiltY",
"k",
"posX",
"posY",
"posZ",
"rhoXY",
"sigmaX",
"sigmaY",
"sigmaZ"};
235 const std::string offDiagArrConstK[] = {
"TiltX",
"TiltY",
"X",
"Y",
"Z",
"RhoXY",
"Sx",
"Sy",
"Sz"};
236 const std::string diagArrConstK[] = {
"tiltX",
"tiltY",
"posX",
"posY",
"posZ",
"rhoXY",
"sigmaX",
"sigmaY",
"sigmaZ"};
238 std::map< std::string, double > covMap;
239 std::vector< std::string > offDiagVector;
240 std::vector< std::string > diagVector;
241 std::string covString =
"cov";
242 std::string errString =
"Err";
246 for(
int i = 0;
i < numParams;
i++){
248 offDiagVector.push_back(offDiagArrConstK[
i]);
249 diagVector.push_back(diagArrConstK[
i]);
252 offDiagVector.push_back(offDiagArr[
i]);
253 diagVector.push_back(diagArr[
i]);
257 for(
unsigned int i = 0;
i < offDiagVector.size();
i++){
258 for(
unsigned int j = 0; j <=
i; j++){
260 key = diagVector[
i] + errString;
264 key = covString + offDiagVector[
i] + offDiagVector[j];
266 key = covString + offDiagVector[j] + offDiagVector[
i];
279 const std::string offDiagRemoveArr[] = {
"k",
"RhoXY",
"Sz",
"Sy",
"Sx",
"TiltY",
"TiltX",
"Z",
"Y",
"X"};
280 const std::string offDiagRemoveArrConstK[] = {
"RhoXY",
"Sz",
"Sy",
"Sx",
"TiltY",
"TiltX",
"Z",
"Y",
"X"};
281 std::vector< std::string > offDiagRemoveVector;
282 for (
int i = 0;
i < numParams;
i++){
284 offDiagRemoveVector.push_back(offDiagRemoveArrConstK[
i]);
287 offDiagRemoveVector.push_back(offDiagRemoveArr[
i]);
290 for(
unsigned int i = 0;
i < offDiagRemoveVector.size();
i++){
291 for(
unsigned int j =
i+1; j < offDiagRemoveVector.size(); j++){
292 covMap.erase(covString+offDiagRemoveVector[
i]+offDiagRemoveVector[j]);
301 std::map<std::string,double> paramMap;
302 paramMap[
"tiltX"] =
m_ax;
303 paramMap[
"tiltY"] =
m_ay;
305 paramMap[
"posX"] =
m_mx;
306 paramMap[
"posY"] =
m_my;
307 paramMap[
"posZ"] =
m_mz;
308 paramMap[
"sigmaX"] =
m_sx;
309 paramMap[
"sigmaY"] =
m_sy;
310 paramMap[
"sigmaZ"] =
m_sz;
311 paramMap[
"rhoXY"] =
m_rho;