added DKS asymmetry fit support

This commit is contained in:
2016-04-15 16:47:40 +02:00
parent 27eb664686
commit aedacbcd34
7 changed files with 249 additions and 82 deletions

View File

@ -85,37 +85,64 @@ Double_t PFitterFcnDKS::operator()(const std::vector<Double_t>& par) const
Int_t ierr = fDKS.writeParams(&par[0], par.size());
// loop over all data sets
PSingleHistoParams shp;
PDKSParams dksp;
Double_t norm = 1.0;
// single histos
for (UInt_t i=0; i<fRunListCollection->GetNoOfSingleHisto(); i++) {
// get current values of N0, Nbkg, tau, the functions, the maps, the time resolution, the fit start time, etc.
ierr = fRunListCollection->GetSingleHistoParams(i, par, shp);
ierr = fRunListCollection->GetSingleHistoParams(i, par, dksp);
// set N0, Nbkg
ierr += fDKS.callSetConsts(shp.fN0, shp.fTau, shp.fNbkg);
ierr += fDKS.callSetConsts(dksp.fN0, dksp.fTau, dksp.fNbkg);
// set fun values
ierr += fDKS.writeFunctions(&shp.fFun[0], shp.fFun.size());
ierr += fDKS.writeFunctions(&dksp.fFun[0], dksp.fFun.size());
// set map values
ierr += fDKS.writeMaps(&shp.fMap[0], shp.fMap.size());
ierr += fDKS.writeMaps(&dksp.fMap[0], dksp.fMap.size());
// calc chisq/log-mlh
chisq = 0.0;
ierr += fDKS.callLaunchChiSquare(fMemData[i], fMemData[i], shp.fNoOfFitBins,
par.size(), shp.fFun.size(), shp.fMap.size(),
shp.fStartTime , shp.fPackedTimeResolution, chisq);
ierr += fDKS.callLaunchChiSquare(FITTYPE_SINGLE_HISTO, fMemDataSingleHisto[i], fMemDataSingleHisto[i], dksp.fNoOfFitBins,
par.size(), dksp.fFun.size(), dksp.fMap.size(),
dksp.fStartTime , dksp.fPackedTimeResolution, chisq);
value += chisq;
if (ierr != 0) {
cerr << "PFitterFcnDKS::operator(): **ERROR** Kernel launch failed!" << endl;
cerr << "PFitterFcnDKS::operator(): **ERROR** Kernel launch for single histo failed!" << endl;
exit (EXIT_FAILURE);
}
}
Double_t norm = 1.0;
if (shp.fScaleN0AndBkg)
norm = shp.fPackedTimeResolution*1.0e3;
// asymmetries
for (UInt_t i=0; i<fRunListCollection->GetNoOfAsymmetry(); i++) {
// get current values of alpha and beta, the functions, the maps, the time resolution, the fit start time, etc.
ierr = fRunListCollection->GetAsymmetryParams(i, par, dksp);
// set alpha and beta
ierr += fDKS.callSetConsts(dksp.fAlpha, dksp.fBeta);
// set fun values
ierr += fDKS.writeFunctions(&dksp.fFun[0], dksp.fFun.size());
// set map values
ierr += fDKS.writeMaps(&dksp.fMap[0], dksp.fMap.size());
// calc chisq
chisq = 0.0;
ierr += fDKS.callLaunchChiSquare(FITTYPE_ASYMMETRY, fMemDataAsymmetry[i], fMemDataAsymmetryErr[i], dksp.fNoOfFitBins,
par.size(), dksp.fFun.size(), dksp.fMap.size(),
dksp.fStartTime , dksp.fPackedTimeResolution, chisq);
value += chisq;
if (ierr != 0) {
cerr << "PFitterFcnDKS::operator(): **ERROR** Kernel launch for asymmetry failed!" << endl;
exit (EXIT_FAILURE);
}
}
if (dksp.fScaleN0AndBkg)
norm = dksp.fPackedTimeResolution*1.0e3;
return norm*value;
}
@ -220,6 +247,7 @@ void PFitterFcnDKS::InitDKS(const UInt_t dksTag)
}
// now ready to init the chisq buffer on the GPU
cout << "debug> minSize=" << minSize << ", parSize=" << parSize << ", funSize=" << funSize << ", mapSize=" << mapSize << endl;
ierr = fDKS.initChiSquare(minSize, parSize, funSize, mapSize);
if (ierr != 0) {
cerr << ">> PFitterFcnDKS::InitDKS: **ERROR** failed to allocate the necessary chisq buffer on the GPU." << endl;
@ -228,28 +256,58 @@ void PFitterFcnDKS::InitDKS(const UInt_t dksTag)
}
// allocate memory for the data on the GPU/CPU and transfer the data sets
fMemData.resize(fRunListCollection->GetNoOfSingleHisto());
PRunData *runData=0;
// single histos
fMemDataSingleHisto.resize(fRunListCollection->GetNoOfSingleHisto());
for (UInt_t i=0; i<fRunListCollection->GetNoOfSingleHisto(); i++) {
runData = fRunListCollection->GetSingleHisto(i);
if (runData == 0) {
cerr << ">> PFitterFcnDKS::InitDKS: **ERROR** failed to get data set (i=" << i << ") from fRunListCollection." << endl;
cerr << ">> PFitterFcnDKS::InitDKS: **ERROR** failed to get single histo data set (i=" << i << ") from fRunListCollection." << endl;
fValid = false;
return;
}
fMemData[i] = fDKS.allocateMemory<Double_t>(minSize, ierr);
fMemDataSingleHisto[i] = fDKS.allocateMemory<Double_t>(minSize, ierr);
if (ierr != 0) {
cerr << ">> PFitterFcnDKS::InitDKS: **ERROR** failed to allocated data set memory (i=" << i << ") on the GPU" << endl;
cerr << ">> PFitterFcnDKS::InitDKS: **ERROR** failed to allocated single histo data set memory (i=" << i << ") on the GPU" << endl;
fValid = false;
return;
}
Int_t startTimeBin = fRunListCollection->GetStartTimeBin(i);
Int_t startTimeBin = fRunListCollection->GetStartTimeBin(MSR_FITTYPE_SINGLE_HISTO, i);
if (startTimeBin < 0) {
cerr << ">> PFitterFcnDKS::InitDKS: **ERROR** startTimeBin undefind." << endl;
cerr << ">> PFitterFcnDKS::InitDKS: **ERROR** startTimeBin undefind (single histo fit)." << endl;
fValid = false;
return;
}
fDKS.writeData<double>(fMemData[i], &runData->GetValue()->at(startTimeBin), minSize);
fDKS.writeData<double>(fMemDataSingleHisto[i], &runData->GetValue()->at(startTimeBin), minSize);
}
// asymmetry
fMemDataAsymmetry.resize(fRunListCollection->GetNoOfAsymmetry());
fMemDataAsymmetryErr.resize(fRunListCollection->GetNoOfAsymmetry());
for (UInt_t i=0; i<fRunListCollection->GetNoOfAsymmetry(); i++) {
runData = fRunListCollection->GetAsymmetry(i);
if (runData == 0) {
cerr << ">> PFitterFcnDKS::InitDKS: **ERROR** failed to get asymmetry data set (i=" << i << ") from fRunListCollection." << endl;
fValid = false;
return;
}
fMemDataAsymmetry[i] = fDKS.allocateMemory<Double_t>(minSize, ierr);
fMemDataAsymmetryErr[i] = fDKS.allocateMemory<Double_t>(minSize, ierr);
if (ierr != 0) {
cerr << ">> PFitterFcnDKS::InitDKS: **ERROR** failed to allocated asymmetry data set memory (i=" << i << ") on the GPU" << endl;
fValid = false;
return;
}
Int_t startTimeBin = fRunListCollection->GetStartTimeBin(MSR_FITTYPE_ASYM, i);
if (startTimeBin < 0) {
cerr << ">> PFitterFcnDKS::InitDKS: **ERROR** startTimeBin undefind (asymmetry fit)." << endl;
fValid = false;
return;
}
fDKS.writeData<double>(fMemDataAsymmetry[i], &runData->GetValue()->at(startTimeBin), minSize);
fDKS.writeData<double>(fMemDataAsymmetryErr[i], &runData->GetError()->at(startTimeBin), minSize);
}
// set the function string and compile the program
@ -281,9 +339,17 @@ void PFitterFcnDKS::InitDKS(const UInt_t dksTag)
void PFitterFcnDKS::FreeDKS()
{
PRunData *runData=0;
for (UInt_t i=0; i<fMemData.size(); i++) {
// single histo
for (UInt_t i=0; i<fMemDataSingleHisto.size(); i++) {
runData = fRunListCollection->GetSingleHisto(i);
fDKS.freeMemory<Double_t>(fMemData[i], runData->GetValue()->size());
fDKS.freeMemory<Double_t>(fMemDataSingleHisto[i], runData->GetValue()->size());
}
fMemDataSingleHisto.clear();
// asymmetry
for (UInt_t i=0; i<fMemDataAsymmetry.size(); i++) {
runData = fRunListCollection->GetAsymmetry(i);
fDKS.freeMemory<Double_t>(fMemDataAsymmetry[i], runData->GetValue()->size());
fDKS.freeMemory<Double_t>(fMemDataAsymmetryErr[i], runData->GetValue()->size());
}
fMemData.clear();
}