#include "hrtfunctional.h"
#include "hsavitzkygolay.h"
#include "hruntimedb.h"
#include "TFile.h"
#include "TMath.h"
#undef FREEZE_RHO_ZETA
#undef LOCAL_GRID_FILE
#undef RTFUNC_DEBUG
HRtFunctional::HRtFunctional(void) {
fSavGol = 0;
fPoint = 0;
fDeg2Rad = TMath::Pi()/180.;
}
HRtFunctional::~HRtFunctional(void) {
}
Bool_t HRtFunctional::init(void) {
#ifdef LOCAL_GRID_FILE
TFile f("reftgrid.root");
fCurrentGrid = (HRtGrid *)gFile->Get("reftgrid_el");
#else
fData = (HRtData *)HRuntimeDb::instance()->getContainer("RtData");
if (!fData) return kFALSE;
fCurrentGrid = fData->getGrid(1);
#endif
fPolinomPar = (HRtSavGolPar *)HRuntimeDb::instance()->
getContainer("RtSavGolPar");
if (!fPolinomPar) return kFALSE;
return kTRUE;
}
Bool_t HRtFunctional::reinit(void) {
if (fPolinomPar->hasChanged()) {
delete fSavGol;
fSavGol = new HRtSavGolManager(fPolinomPar->getNLeft(),
fPolinomPar->getNRight(),
1,
fPolinomPar->getM());
}
return kTRUE;
}
Bool_t HRtFunctional::setPoint(HRtVector &p,Int_t pol) {
HRtVector pp(kRtParameterDim);
#ifndef LOCAL_GRID_FILE
fCurrentGrid = fData->getGrid(pol);
#endif
pp(0) = p.at(0);
pp(1) = p.at(1);
pp(2) = p.at(2);
pp(3) = p.at(3) - 90;
pp(4) = p.at(4);
if (pp(3)>0) {
fSectorSide = kRight;
} else {
fSectorSide = kLeft;
pp(3) = -pp(3);
pp(2) = -pp(2);
}
fPointValue = &(fCurrentGrid->bin(pp));
fPoint = fCurrentGrid->getCurrentBin();
fCurrentGrid->fillCurrentBinCoord(pp);
p(0) = pp(0);
p(1) = pp(1);
p(4) = pp(4);
if (fSectorSide == kRight) {
p(3) = pp(3) + 90;
p(2) = pp(2);
} else {
p(3) = -pp(3) + 90;
p(2) = -pp(2);
}
#ifdef RTFUNC_DEBUG
std::cout << "Internal coord ";
for (Int_t i=0;i<5;i++) std::cout << fPoint[i] << ", ";
std::cout << std::endl;
#endif
return (fCurrentGrid->getStatus() == HRtGrid::kOk);
}
Float_t HRtFunctional::partialDerivative(Int_t pi,Int_t pj) {
Float_t sum = 0;
Int_t temp = fPoint[pj];
Int_t idx;
Int_t nl,nr;
Float_t parity = 1;
Float_t iParity = 1;
Float_t result = 0.;
const HRtVector *sgCoef;
if (fSectorSide == kLeft) {
if ( (pi & 1)==0) parity = -1;
}
#ifdef FREEZE_RHO_ZETA
if (pj==1 || pj==2) return 0;
#endif
for (nl=1; nl<=fPolinomPar->getNLeft(); nl++) {
idx = temp - nl;
if (idx<0) {
if (pj==3) idx=-idx-1;
else break;
}
fPoint[pj] = idx;
HRtMeasurement &m = fCurrentGrid->bin(fPoint);
if (fCurrentGrid->getStatus() != HRtGrid::kOk ||
fabs(m[pi]) > 5000.) {
break;
}
}
nl-=1;
for (nr=1; nr<=fPolinomPar->getNRight(); nr++) {
fPoint[pj] = temp + nr;
HRtMeasurement &m = fCurrentGrid->bin(fPoint);
if (fCurrentGrid->getStatus() != HRtGrid::kOk ||
fabs(m[pi]) > 5000.) {
break;
}
}
nr-=1;
idx = temp-nl;
if (pj==3) {
if (fSectorSide == kRight) sgCoef=fSavGol->getCoefficients(nl,nr);
else sgCoef=fSavGol->getCoefficients(nr,nl);
if (sgCoef) {
for (Int_t n=0;n<nl+nr+1;n++,idx++) {
if (idx<0) {
fPoint[pj]=-idx-1;
if ( (pi & 1) == 0) iParity = -parity;
} else {
fPoint[pj]=idx;
iParity = parity;
}
HRtMeasurement &m=fCurrentGrid->bin(fPoint);
if (fCurrentGrid->getStatus() != HRtGrid::kOk) {
result = 0;
break;
}
if (fSectorSide == kRight)
sum += sgCoef->at(n) * m[pi] * iParity;
else
sum += sgCoef->at(nl+nr-n) * m[pi] * iParity;
}
}
} else {
sgCoef = fSavGol->getCoefficients(nl,nr);
if (sgCoef) {
for (Int_t n=0;n<nl+nr+1;n++,idx++) {
fPoint[pj]=idx;
HRtMeasurement &m=fCurrentGrid->bin(fPoint);
if (fCurrentGrid->getStatus() != HRtGrid::kOk) {
result = 0.;
break;
}
sum += sgCoef->at(n) * m[pi] * parity;
}
}
}
result = sum / fCurrentGrid->getBinSize(pj);
fPoint[pj] = temp;
return result;
}
void HRtFunctional::calcDerivatives(HRtMatrix &result) {
for (Int_t i=0;i<result.getRows();i++)
for (Int_t j=0;j<result.getCols();j++)
result(i,j) = partialDerivative(i,j);
}
void HRtFunctional::calcValue(HRtVector &result) {
if (fSectorSide == kRight) {
for (Int_t i=0;i<4;i++) {
result(i<<1) = fPointValue->operator[](i<<1);
result((i<<1) | 1) = fPointValue->operator[]((i<<1) | 1);
}
} else {
for (Int_t i=0;i<4;i++) {
result(i<<1) = -fPointValue->operator[](i<<1);
result((i<<1) | 1) = fPointValue->operator[]((i<<1) | 1);
}
}
}
ClassImp(HRtFunctional)
Last change: Sat May 22 13:11:38 2010
Last generated: 2010-05-22 13:11
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.