5 #include "RooAbsReal.h"
8 using namespace RooFit;
17 rangeYmin(1), rangeYmax(-1),
18 rangeZmin(1), rangeZmax(-1),
22 theYVar(
"theYVar",
"theYVar", this),
23 theZVar(
"theZVar",
"theZVar", this)
31 rangeYmin(1), rangeYmax(-1),
32 rangeZmin(1), rangeZmax(-1),
36 theYVar(
"theYVar",
"theYVar", this),
37 theZVar(
"theZVar",
"theZVar", this)
46 const std::vector<T>& inXList,
47 const std::vector<T>& inYList,
48 const std::vector<T>& inZList,
49 const std::vector<std::vector<std::vector<T>>>& inFcnList,
60 MELANCSplineCore(name, title, inXVar, inXList, inUseFloor, inFloorEval, inFloorInt),
61 rangeYmin(1), rangeYmax(-1),
62 rangeZmin(1), rangeZmax(-1),
63 bcBeginX(bcBeginX_), bcEndX(bcEndX_),
64 bcBeginY(bcBeginY_), bcEndY(bcEndY_),
65 bcBeginZ(bcBeginZ_), bcEndZ(bcEndZ_),
66 theYVar(
"theYVar",
"theYVar", this, inYVar),
67 theZVar(
"theZVar",
"theZVar", this, inZVar),
80 for (
int i=0; i<npoints; i++){
for (
int j=0; j<npoints; j++){ xAtrans[i][j]=xA.at(i).at(j); } }
84 coutE(InputArguments) <<
"MELANCSpline_3D_fast::interpolateFcn: Matrix xA could not be inverted. Something is wrong with the x coordinates of points!" << endl;
91 for (
int i=0; i<npoints; i++){
for (
int j=0; j<npoints; j++){ yAtrans[i][j]=yA.at(i).at(j); } }
95 coutE(InputArguments) <<
"MELANCSpline_3D_fast::interpolateFcn: Matrix yA could not be inverted. Something is wrong with the y coordinates of points!" << endl;
102 for (
int i=0; i<npoints; i++){
for (
int j=0; j<npoints; j++){ zAtrans[i][j]=zA.at(i).at(j); } }
106 coutE(InputArguments) <<
"MELANCSpline_3D_fast::interpolateFcn: Matrix zA could not be inverted. Something is wrong with the z coordinates of points!" << endl;
118 std::vector<std::vector<
119 std::vector<std::vector<MELANCSplineCore::T>>
122 for (
unsigned int k=0; k<
npointsZ(); k++){
125 std::vector<std::vector<
126 std::vector<std::vector<MELANCSplineCore::T>>
127 >> coefficients_perZ;
129 vector<vector<vector<MELANCSplineCore::T>>> coefsAlongY;
130 for (
unsigned int j=0; j<
npointsY(); j++){
135 nxbins=xcoefsAtYjZk.size();
136 nxpoldim=xcoefsAtYjZk.at(0).size();
138 for (
int ix=0; ix<nxbins; ix++){
139 vector<vector<MELANCSplineCore::T>> dum_xycoefarray;
140 for (
int icx=0; icx<nxpoldim; icx++){
141 vector<MELANCSplineCore::T> dum_ycoefarray;
142 dum_xycoefarray.push_back(dum_ycoefarray);
144 coefsAlongY.push_back(dum_xycoefarray);
147 if (nxbins!=(
int)xcoefsAtYjZk.size() || nxpoldim!=(
int)xcoefsAtYjZk.at(0).size()){
148 coutE(InputArguments) <<
"MELANCSpline_3D_fast::interpolateFcn: nxbins!=(int)xcoefsAtYjZk.size() || nxpoldim!=(int)xcoefsAtYjZk.at(0).size()!" << endl;
151 for (
int ix=0; ix<nxbins; ix++){
152 for (
int icx=0; icx<nxpoldim; icx++) coefsAlongY.at(ix).at(icx).push_back(xcoefsAtYjZk.at(ix).at(icx));
158 for (
int ix=0; ix<nxbins; ix++){
160 vector<vector<vector<MELANCSplineCore::T>>> xCoefs;
161 for (
int icx=0; icx<nxpoldim; icx++){
163 xCoefs.push_back(yCoefs);
165 coefficients_perZ.push_back(xCoefs);
169 nybins = coefficients_perZ.at(0).at(0).size();
170 nypoldim = coefficients_perZ.at(0).at(0).at(0).size();
171 for (
int ix=0; ix<nxbins; ix++){
172 vector<vector<vector<vector<MELANCSplineCore::T>>>> xCoefs;
173 for (
int icx=0; icx<nxpoldim; icx++){
174 vector<vector<vector<MELANCSplineCore::T>>> xCoefsAlongY;
175 for (
int iy=0; iy<nybins; iy++){
176 vector<vector<MELANCSplineCore::T>> yCoefs;
177 for (
int icy=0; icy<nypoldim; icy++){
178 vector<MELANCSplineCore::T> yCoefAtZj;
179 yCoefs.push_back(yCoefAtZj);
181 xCoefsAlongY.push_back(yCoefs);
183 xCoefs.push_back(xCoefsAlongY);
185 coefsAlongZ.push_back(xCoefs);
188 for (
int ix=0; ix<nxbins; ix++){
189 for (
int icx=0; icx<nxpoldim; icx++){
190 for (
int iy=0; iy<nybins; iy++){
191 for (
int icy=0; icy<nypoldim; icy++){
192 coefsAlongZ.at(ix).at(icx).at(iy).at(icy).push_back(coefficients_perZ.at(ix).at(icx).at(iy).at(icy));
200 for (
int ix=0; ix<nxbins; ix++){
201 vector<vector<vector<vector<vector<MELANCSplineCore::T>>>>> xCoefs;
202 for (
int icx=0; icx<nxpoldim; icx++){
203 vector<vector<vector<vector<MELANCSplineCore::T>>>> xCoefsAlongY;
204 for (
int iy=0; iy<nybins; iy++){
205 vector<vector<vector<MELANCSplineCore::T>>> yCoefs;
206 for (
int icy=0; icy<nypoldim; icy++){
208 yCoefs.push_back(yCoefsAlongZ);
210 xCoefsAlongY.push_back(yCoefs);
212 xCoefs.push_back(xCoefsAlongY);
234 rangeYmin(other.rangeYmin), rangeYmax(other.rangeYmax),
235 rangeZmin(other.rangeZmin), rangeZmax(other.rangeZmax),
236 bcBeginX(other.bcBeginX), bcEndX(other.bcEndX),
237 bcBeginY(other.bcBeginY), bcEndY(other.bcEndY),
238 bcBeginZ(other.bcBeginZ), bcEndZ(other.bcEndZ),
239 theYVar(
"theYVar", this, other.theYVar),
240 theZVar(
"theZVar", this, other.theZVar),
243 FcnList(other.FcnList),
244 kappaX(other.kappaX),
245 kappaY(other.kappaY),
246 kappaZ(other.kappaZ),
247 coefficients(other.coefficients)
256 vector<Int_t> varprime; varprime.push_back(2); varprime.push_back(3); varprime.push_back(5);
257 const Int_t
ndims=(
const Int_t)varprime.size();
258 vector<Int_t> varbin;
259 vector<Int_t> varbinmin;
260 vector<Int_t> varbinmax;
261 vector<MELANCSplineCore::T> tvar;
262 vector<MELANCSplineCore::T> tvarmin;
263 vector<MELANCSplineCore::T> tvarmax;
264 vector<const vector<MELANCSplineCore::T>*> varkappa; varkappa.push_back(&
kappaX); varkappa.push_back(&
kappaY); varkappa.push_back(&
kappaZ);
265 vector<const RooRealProxy*> varcoord; varcoord.push_back(&
theXVar); varcoord.push_back(&
theYVar); varcoord.push_back(&
theZVar);
266 for (Int_t idim=0; idim<
ndims; idim++){
273 if (code==0 || code%varprime.at(idim)!=0){
276 tval =
getTVar(*(varkappa.at(idim)), *(varcoord.at(idim)), binval, idim);
281 const std::vector<MELANCSplineCore::T>& kappadim = *(varkappa.at(idim));
283 tmin =
getTVar(kappadim, coordmin, binmin, idim);
285 tmax =
getTVar(kappadim, coordmax, binmax, idim);
287 varbin.push_back(binval);
288 varbinmin.push_back(binmin);
289 varbinmax.push_back(binmax);
290 tvar.push_back(tval);
291 tvarmin.push_back(tmin);
292 tvarmax.push_back(tmax);
297 (varbin[0]>=0 && ix!=varbin[0])
299 (varbinmin[0]>=0 && varbinmax[0]>=varbinmin[0] && !(varbinmin[0]<=ix && ix<=varbinmax[0]))
302 if (code>0 && code%varprime[0]==0){
303 if (ix==varbinmin[0]) txlow=tvarmin[0];
304 if (ix==varbinmax[0]) txhigh=tvarmax[0];
308 vector<MELANCSplineCore::T> xCoefs;
309 for (
int icx=0; icx<(int)
coefficients.at(ix).size(); icx++){
311 for (
int iy=0; iy<(int)
coefficients.at(ix).at(icx).size(); iy++){
313 (varbin[1]>=0 && iy!=varbin[1])
315 (varbinmin[1]>=0 && varbinmax[1]>=varbinmin[1] && !(varbinmin[1]<=iy && iy<=varbinmax[1]))
318 if (code>0 && code%varprime[1]==0){
319 if (iy==varbinmin[1]) tylow=tvarmin[1];
320 if (iy==varbinmax[1]) tyhigh=tvarmax[1];
324 vector<MELANCSplineCore::T> yCoefs;
325 for (
int icy=0; icy<(int)
coefficients.at(ix).at(icx).at(iy).size(); icy++){
327 for (
int iz=0; iz<(int)
coefficients.at(ix).at(icx).at(iy).at(icy).size(); iz++){
329 (varbin[2]>=0 && iz!=varbin[2])
331 (varbinmin[2]>=0 && varbinmax[2]>=varbinmin[2] && !(varbinmin[2]<=iz && iz<=varbinmax[2]))
335 if (code>0 && code%varprime[2]==0){
336 if (iz==varbinmin[2]) tzlow=tvarmin[2];
337 if (iz==varbinmax[2]) tzhigh=tvarmax[2];
341 theYCoef +=
evalSplineSegment(
coefficients.at(ix).at(icx).at(iy).at(icy).at(iz), varkappa[2]->at(iz), tzhigh, tzlow, (code>0 && code%varprime[2]==0));
343 yCoefs.push_back(theYCoef);
345 theXCoef +=
evalSplineSegment(yCoefs, varkappa[1]->at(iy), tyhigh, tylow, (code>0 && code%varprime[1]==0));
347 xCoefs.push_back(theXCoef);
350 res +=
evalSplineSegment(xCoefs, varkappa[0]->at(ix), txhigh, txlow, (code>0 && code%varprime[0]==0));
361 vector<MELANCSplineCore::T>
const* coord;
362 if (whichDirection==0){
366 else if (whichDirection==1){
375 for (Int_t j=0; j<npoints-1; j++){
381 kappas.push_back(
kappa);
383 kappas.push_back(
kappa);
389 vector<MELANCSplineCore::T>
const* coord;
390 if (whichDirection==0){
394 else if (whichDirection==1){
403 if (npoints<=1) bin=0;
405 valjpo = coord->at(0);
406 for (Int_t j=0; j<npoints-1; j++){
408 valjpo = coord->at(j+1);
409 if (val<valjpo && val>=valj){ bin=j;
break; }
411 if (bin==-1 && val>=valjpo) bin=npoints-2;
412 else if (bin==-1) bin=0;
419 vector<MELANCSplineCore::T>
const* coord;
420 if (whichDirection==0) coord=&
XList;
421 else if (whichDirection==1) coord=&
YList;
423 return (val-coord->at(bin))*K;
427 const std::vector<MELANCSplineCore::T>& kappaX,
const TMatrix_t& xAinv,
428 const Int_t& ybin,
const Int_t& zbin,
432 vector<MELANCSplineCore::T> fcnList;
433 for (
unsigned int bin=0; bin<
npointsX(); bin++){ fcnList.push_back(
FcnList.at(zbin).at(ybin).at(bin)); }
448 if (_forceNumInt)
return 0;
452 RooArgSet Xdeps, Ydeps, Zdeps;
453 RooRealVar* rrv_x =
dynamic_cast<RooRealVar*
>(
theXVar.absArg());
454 RooRealVar* rrv_y =
dynamic_cast<RooRealVar*
>(
theYVar.absArg());
455 RooRealVar* rrv_z =
dynamic_cast<RooRealVar*
>(
theZVar.absArg());
456 if (rrv_x==0)
theXVar.absArg()->leafNodeServerList(&Xdeps, 0,
true);
457 if (rrv_y==0)
theYVar.absArg()->leafNodeServerList(&Ydeps, 0,
true);
458 if (rrv_z==0)
theZVar.absArg()->leafNodeServerList(&Zdeps, 0,
true);
462 (Ydeps.find(*rrv_x)==0 || rrv_y!=0)
464 (Zdeps.find(*rrv_x)==0 || rrv_z!=0)
466 if (matchArgs(allVars, analVars,
theXVar)) code*=2;
471 (Xdeps.find(*rrv_y)==0 || rrv_x!=0)
473 (Zdeps.find(*rrv_y)==0 || rrv_z!=0)
475 if (matchArgs(allVars, analVars,
theYVar)) code*=3;
480 (Xdeps.find(*rrv_z)==0 || rrv_x!=0)
482 (Ydeps.find(*rrv_z)==0 || rrv_y!=0)
484 if (matchArgs(allVars, analVars,
theZVar)) code*=5;
494 if (
verbosity>=
MELANCSplineCore::kError) coutE(Integration) <<
"MELANCSpline_3D_fast ERROR::MELANCSpline_3D_fast(" << GetName() <<
") integration returned " <<
value <<
" for code = " << code << endl;
503 if (whichDirection==0){
507 else if (whichDirection==1){
515 return (*(range[0])>*(range[1]) || (val>=*(range[0]) && val<=*(range[1])));
519 if (whichDirection==0){
523 else if (whichDirection==1){
537 if (whichDirection==0){
541 else if (whichDirection==1){
549 if (val<*(range[0])) val = *(range[0]);
550 if (val>*(range[1])) val = *(range[1]);