From f2eda8a5889c7522bcd8f8c2faf2f21ada5f834c Mon Sep 17 00:00:00 2001 From: nemu Date: Fri, 24 Apr 2009 13:28:49 +0000 Subject: [PATCH] added fractional parameter for internal field/bessel. Corrected handling of table functions --- src/msr2msr.cpp | 278 +++++++++++++++++- src/tests/skewedGaussianTest/paramInput.dat | 2 +- src/tests/skewedGaussianTest/skewedGaussian.C | 6 +- 3 files changed, 274 insertions(+), 12 deletions(-) diff --git a/src/msr2msr.cpp b/src/msr2msr.cpp index b9e8fb05..9586dbf6 100644 --- a/src/msr2msr.cpp +++ b/src/msr2msr.cpp @@ -53,6 +53,11 @@ using namespace std; #define MSR_TAG_STATISTIC 7 #define MSR_TAG_NO_BLOCK 8 +//------------------------------------------------------------- +// msr theory tags +#define MSR_THEORY_INTERN_FLD 0 +#define MSR_THEORY_INTERN_BESSEL 1 + //-------------------------------------------------------------------------- /** *

@@ -260,8 +265,10 @@ bool msr2msr_param(char *str) *

* * \param str + * \param tag + * \param noOfAddionalParams */ -bool msr2msr_theory(char *str) +bool msr2msr_theory(char *str, int &tag, int &noOfAddionalParams) { // handle theory line TString line(str); @@ -269,7 +276,7 @@ bool msr2msr_theory(char *str) TObjString *ostr; char sstr[256]; - if (line.Contains("sktt") || line.Contains("statKTTab")) { + if ((line.Contains("sktt") || line.Contains("statKTTab")) && line.Contains("glf")) { // static Gauss KT LF table // change cmd name strcpy(sstr, "statGssKTLF "); @@ -287,9 +294,29 @@ bool msr2msr_theory(char *str) ostr = dynamic_cast(tokens->At(i)); strcat(sstr, ostr->GetString().Data()); } - strcat(sstr, " (freq sigma)"); + strcat(sstr, " (frequency damping)"); strcpy(str, sstr); - } else if (line.Contains("dktt") || line.Contains("dynmKTTab")) { + } else if ((line.Contains("sktt") || line.Contains("statKTTab")) && line.Contains("llf")) { // static Lorentz KT LF table + // change cmd name + strcpy(sstr, "statExpKTLF "); + + // tokenize the rest and extract the first two parameters + tokens = line.Tokenize(" \t"); + Int_t noTokens = tokens->GetEntries(); + if (noTokens < 3) { + cout << endl << "**ERROR** in THEORY block"; + cout << endl << " Line: '" << str << "' is not a valid statKTTab statement."; + cout << endl << " Cannot handle file." << endl; + return false; + } + for (Int_t i=1; i<3; i++) { + strcat(sstr, " "); + ostr = dynamic_cast(tokens->At(i)); + strcat(sstr, ostr->GetString().Data()); + } + strcat(sstr, " (frequency damping)"); + strcpy(str, sstr); + } else if ((line.Contains("dktt") || line.Contains("dynmKTTab")) && line.Contains("kdglf")) { // dynamic Gauss KT LF table // change cmd name strcpy(sstr, "dynGssKTLF "); @@ -307,13 +334,244 @@ bool msr2msr_theory(char *str) ostr = dynamic_cast(tokens->At(i)); strcat(sstr, ostr->GetString().Data()); } - strcat(sstr, " (freq sigma hopping_rate)"); + strcat(sstr, " (frequency damping hopping-rate)"); + strcpy(str, sstr); + } else if ((line.Contains("dktt") || line.Contains("dynmKTTab")) && line.Contains("kdllf")) { // dynamic Lorentz KT LF table + // change cmd name + strcpy(sstr, "dynExpKTLF "); + + // tokenize the rest and extract the first three parameters + tokens = line.Tokenize(" \t"); + Int_t noTokens = tokens->GetEntries(); + if (noTokens < 4) { + cout << endl << "**ERROR** in THEORY block"; + cout << endl << " Line: '" << str << "' is not a valid dynmKTTab statement."; + cout << endl << " Cannot handle file." << endl; + return false; + } + for (Int_t i=1; i<4; i++) { + strcat(sstr, " "); + ostr = dynamic_cast(tokens->At(i)); + strcat(sstr, ostr->GetString().Data()); + } + strcat(sstr, " (frequency damping hopping-rate)"); + strcpy(str, sstr); + } else if (line.Contains("internFld")) { + tag = MSR_THEORY_INTERN_FLD; + noOfAddionalParams++; + + // change cmd name + strcpy(sstr, "internFld "); + + // tokenize the rest and extract the first three parameters + tokens = line.Tokenize(" \t"); + Int_t noTokens = tokens->GetEntries(); + if (noTokens < 4) { + cout << endl << "**ERROR** in THEORY block"; + cout << endl << " Line: '" << str << "' is not a valid internFld statement."; + cout << endl << " Cannot handle file." << endl; + return false; + } + strcat(sstr, " _x_"); + for (Int_t i=1; i<4; i++) { + strcat(sstr, " "); + ostr = dynamic_cast(tokens->At(i)); + strcat(sstr, ostr->GetString().Data()); + } + strcat(sstr, " (fraction phase frequency Trate Lrate)"); + strcpy(str, sstr); + } else if (line.Contains("internBsl")) { + tag = MSR_THEORY_INTERN_BESSEL; + noOfAddionalParams++; + + // change cmd name + strcpy(sstr, "internBsl "); + + // tokenize the rest and extract the first three parameters + tokens = line.Tokenize(" \t"); + Int_t noTokens = tokens->GetEntries(); + if (noTokens < 4) { + cout << endl << "**ERROR** in THEORY block"; + cout << endl << " Line: '" << str << "' is not a valid internBsl statement."; + cout << endl << " Cannot handle file." << endl; + return false; + } + strcat(sstr, " _x_"); + for (Int_t i=1; i<4; i++) { + strcat(sstr, " "); + ostr = dynamic_cast(tokens->At(i)); + strcat(sstr, ostr->GetString().Data()); + } + strcat(sstr, " (fraction phase frequency Trate Lrate)"); strcpy(str, sstr); } return true; } + +//-------------------------------------------------------------------------- +/** + *

+ * + * \param str + */ +bool msr2msr_is_comment(char *str) +{ + bool isComment = false; + + for (unsigned int i=0; i + * + * \param str + */ +bool msr2msr_is_whitespace(char *str) +{ + bool isWhitespace = true; + + if (strlen(str) != 0) { + for (unsigned int i=0; i + * + * \param str + * \param paramNo + */ +void msr2msr_replace(char *str, int paramNo) +{ + char temp[128]; + char no[16]; + + memset(temp, 0, sizeof(temp)); + + sprintf(no, "%d", paramNo); + + int j=0; + for (unsigned int i=0; i + * + * \param fln in/out file name + * \param tag + * \param noOfAddionalParams + */ +bool msr2msr_finalize_theory(char *fln, int theoryTag, int noOfAddionalParams) +{ + ifstream fin; + fin.open(fln, iostream::in); + if (!fin.is_open()) { + cout << endl << "**ERROR**: Couldn't open input msr-file " << fln; + cout << endl << " Will quit." << endl; + return 0; + } + + // open temporary output msr-file + ofstream fout; + fout.open("__temp.msr", iostream::out); + if (!fout.is_open()) { + cout << endl << "**ERROR**: Couldn't open output msr-file __temp.msr"; + cout << endl << " Will quit." << endl; + fin.close(); + return 0; + } + + char str[256]; + int tag = -1; + bool success = true; + int param = 0; + int count = 0; + while (!fin.eof() && success) { + fin.getline(str, sizeof(str)); + + if (strstr(str, "FITPARAMETER")) { + tag = MSR_TAG_FITPARAMETER; + } else if (strstr(str, "THEORY")) { + tag = MSR_TAG_THEORY; + } + + if ((tag == MSR_TAG_FITPARAMETER) && !strstr(str, "FITPARAMETER")) { + if ((theoryTag == MSR_THEORY_INTERN_FLD) || (theoryTag == MSR_THEORY_INTERN_BESSEL)) { + if (!msr2msr_is_comment(str)) { + param++; + if (msr2msr_is_whitespace(str)) { + // add needed parameters + for (int i=0; i @@ -339,7 +597,7 @@ int main(int argc, char *argv[]) return 0; } - // open input msr-file + // open output msr-file ofstream fout; fout.open(argv[2], iostream::out); if (!fout.is_open()) { @@ -352,6 +610,8 @@ int main(int argc, char *argv[]) // read input file and write output file char str[256]; int tag = -1; + int theoryTag = -1; + int noOfAddionalParams = 0; bool success = true; while (!fin.eof() && success) { fin.getline(str, sizeof(str)); @@ -369,7 +629,7 @@ int main(int argc, char *argv[]) success = msr2msr_param(str); break; case MSR_TAG_THEORY: - success = msr2msr_theory(str); + success = msr2msr_theory(str, theoryTag, noOfAddionalParams); break; case MSR_TAG_RUN: success = msr2msr_run(str); @@ -391,7 +651,9 @@ int main(int argc, char *argv[]) system(str); } - // clean up + if (theoryTag != -1) { + msr2msr_finalize_theory(argv[2], theoryTag, noOfAddionalParams); + } cout << endl << "done ..." << endl; diff --git a/src/tests/skewedGaussianTest/paramInput.dat b/src/tests/skewedGaussianTest/paramInput.dat index 820b2eaa..a7aeec38 100644 --- a/src/tests/skewedGaussianTest/paramInput.dat +++ b/src/tests/skewedGaussianTest/paramInput.dat @@ -12,7 +12,7 @@ t0, 3300, 3300, 3300, 3300 # asym's asym, 0.24, 0.24, 0.24, 0.24 #------------------------------------------------------ -# phases in (°) +# phases in (°) phase, 10.0, 90.0, 170.0, 270.0 #------------------------------------------------------ # N0's diff --git a/src/tests/skewedGaussianTest/skewedGaussian.C b/src/tests/skewedGaussianTest/skewedGaussian.C index e856c518..8329af16 100644 --- a/src/tests/skewedGaussianTest/skewedGaussian.C +++ b/src/tests/skewedGaussianTest/skewedGaussian.C @@ -42,11 +42,11 @@ void skewedGaussian() char fln[256]; const Double_t w = 0.8; // weight of the skewed Gaussian - const Double_t B0 = 130.0; // skewed Gaussian B0 (G) - const Double_t sm = 4.5; // skewed Gaussian sigma- (G) + const Double_t B0 = 142.0; // skewed Gaussian B0 (G) + const Double_t sm = 2.5; // skewed Gaussian sigma- (G) const Double_t sp = 4.5; // skewed Gaussian sigma+ (G) - const Double_t B0ext = 30.0; // external field Gaussian B0 (G) + const Double_t B0ext = 150.0; // external field Gaussian B0 (G) const Double_t sext = 1.2; // external field Gaussian sigma (G) sprintf(fln, "skewedGauss-B%0.2lf-sm%0.2lf-sp%0.2lf-w%0.1lf-Bext%0.2lf-sext%0.2lf.dat",