added a theory translator for DKS

This commit is contained in:
2016-03-08 16:23:18 +01:00
parent d9a35a25bb
commit d9782c55c8
4 changed files with 130 additions and 0 deletions

View File

@ -6032,6 +6032,125 @@ Double_t PMsrHandler::GetAlphaEstimateN0()
return fStartupOptions->alphaEstimateN0;
}
//--------------------------------------------------------------------------
// GetDKSTheoryString (public)
//--------------------------------------------------------------------------
/**
* <p>returns the theory string in a c++ compatible string. This is needed
* for DKS/GPU.
*
* \return the theory in a c++ like string.
*/
std::string PMsrHandler::GetDKSTheoryString()
{
std::string result("");
PStringVector args;
TString tp = TString::Format("%.15lf", TMath::TwoPi());
TString ph = TString::Format("%.15lf", TMath::Pi() / 180.0);
for (UInt_t i=1; i<fTheory.size(); i++) { // start with 1, since fTheory[0].fLine == "THEORY"
if (i > 1) {
if (!fTheory[i-1].fLine.BeginsWith("+")) {
result += " * ";
}
}
HandleTheoryArguments(fTheory[i].fLine, args);
if (fTheory[i].fLine.BeginsWith("asymmetry ", TString::kIgnoreCase) ||
fTheory[i].fLine.BeginsWith("a ", TString::kIgnoreCase)) {
result += args[0].Data();
} else if (fTheory[i].fLine.BeginsWith("simplExpo ", TString::kIgnoreCase) ||
fTheory[i].fLine.BeginsWith("se ")) { // se -> se(t,lambda)
result += "se(t, ";
result += args[0].Data();
result += ")";
} else if (fTheory[i].fLine.BeginsWith("simpleGss ", TString::kIgnoreCase) ||
fTheory[i].fLine.BeginsWith("sg ")) { // sg -> sg(t,sigma)
result += "sg(t, ";
result += args[0].Data();
result += ")";
} else if (fTheory[i].fLine.BeginsWith("TFieldCos ", TString::kIgnoreCase) ||
fTheory[i].fLine.BeginsWith("tf ")) { // tf -> tf(t, phi (°), nu (MHz))
result += "tf(t, ";
result += args[0].Data();
result += ", ";
result += args[1].Data();
result += ")";
} else if (fTheory[i].fLine.BeginsWith("+")) {
result.erase(result.end()-3, result.end()); // remove the '*' at the end
result += " + ";
} else {
result = string("??"); // not yet available in DKS
break;
}
}
return result;
}
//--------------------------------------------------------------------------
// HandleTheoryArguments (private)
//--------------------------------------------------------------------------
/**
* <p>tokenizes the theory function arguments and transforms them for DKS
*
* \param theo
* \param args vector of the transformed arguments
*/
void PMsrHandler::HandleTheoryArguments(const TString theo, PStringVector &args)
{
TObjArray *tok=theo.Tokenize(" \t");
TObjString *ostr=0;
TString str, argStr;
Int_t ival;
args.clear(); // make sure vector is empty
if (tok == 0) {
cerr << ">> PMsrHandler::HandleTheoryArguments(): **ERROR** couldn't tokensize '" << theo << "'" << endl;
return;
}
for (Int_t i=0; i<tok->GetEntries(); i++) {
ostr = dynamic_cast<TObjString*>(tok->At(i));
str = ostr->GetString();
if (str.BeginsWith("#") || str.BeginsWith("(")) { // comment or description
continue;
} else if (str.IsDigit()) { // parameter
ival = str.Atoi();
ival -= 1;
str = TString::Format("%d",ival);
argStr = "p["+ str +"]";
args.push_back(argStr);
} else if (str.BeginsWith("map", TString::kIgnoreCase)) { // map
str.Remove(0,3);
if (!str.IsDigit()) {
return;
}
ival = str.Atoi();
ival -= 1;
str = TString::Format("%d",ival);
argStr = "p[m[" + str + "]]";
args.push_back(argStr);
} else if (str.BeginsWith("fun", TString::kIgnoreCase)) { // function
str.Remove(0,3);
if (!str.IsDigit()) {
return;
}
ival = str.Atoi();
ival -= 1;
str = TString::Format("%d",ival);
argStr = "f[" + str + "]";
args.push_back(argStr);
}
}
// clean up
delete tok;
}
//--------------------------------------------------------------------------
// NeededPrecision (private)
//--------------------------------------------------------------------------