implemented ADDRUN feature which adds runs on the fly. Still very experimental and not thoroughly tested.

This commit is contained in:
nemu 2009-03-12 15:59:19 +00:00
parent 6eacc87cee
commit 3eaa9e433f
12 changed files with 505 additions and 321 deletions

View File

@ -402,7 +402,6 @@ int PMsrHandler::WriteMsrLogFile()
}
// write functions block
cout << endl << ">> GetNoOfFuncs() = " << GetNoOfFuncs() << endl;
if (GetNoOfFuncs() != 0) {
f << endl << "FUNCTIONS";
CheckAndWriteComment(f, ++lineNo);
@ -419,17 +418,33 @@ cout << endl << ">> GetNoOfFuncs() = " << GetNoOfFuncs() << endl;
// write run block
for (unsigned int i=0; i<fRuns.size(); i++) {
// run header
f << endl << "RUN " << fRuns[i].fRunName.Data() << " ";
str = fRuns[i].fBeamline;
f << endl << "RUN " << fRuns[i].fRunName[0].Data() << " ";
str = fRuns[i].fBeamline[0];
str.ToUpper();
f << str.Data() << " ";
str = fRuns[i].fInstitute;
str = fRuns[i].fInstitute[0];
str.ToUpper();
f << str.Data() << " ";
str = fRuns[i].fFileFormat;
str = fRuns[i].fFileFormat[0];
str.ToUpper();
f << str.Data() << " (name beamline institute data-file-format)";
CheckAndWriteComment(f, ++lineNo);
// check for ADDRUN entries
if (fRuns[i].fRunName.size() > 1) {
for (unsigned int j=1; j<fRuns[i].fRunName.size(); j++) {
f << endl << "ADDRUN " << fRuns[i].fRunName[j].Data() << " ";
str = fRuns[i].fBeamline[j];
str.ToUpper();
f << str.Data() << " ";
str = fRuns[i].fInstitute[j];
str.ToUpper();
f << str.Data() << " ";
str = fRuns[i].fFileFormat[j];
str.ToUpper();
f << str.Data() << " (name beamline institute data-file-format)";
CheckAndWriteComment(f, ++lineNo);
}
}
// fittype
f.width(16);
switch (fRuns[i].fFitType) {
@ -609,12 +624,10 @@ cout << endl << ">> GetNoOfFuncs() = " << GetNoOfFuncs() << endl;
CheckAndWriteComment(f, ++lineNo);
}
// t0
if (fRuns[i].fT0[0] != -1) {
if (fRuns[i].fT0.size() > 0) {
f.width(16);
f << endl << left << "t0";
for (unsigned int j=0; j<2; j++) {
if (fRuns[i].fT0[j] == -1)
break;
for (unsigned int j=0; j<fRuns[i].fT0.size(); j++) {
f.width(8);
f << left << fRuns[i].fT0[j];
}
@ -1248,16 +1261,37 @@ bool PMsrHandler::HandleRunEntry(PMsrLines &lines)
} else {
// run name
ostr = dynamic_cast<TObjString*>(tokens->At(1));
param.fRunName = ostr->GetString();
param.fRunName.push_back(ostr->GetString());
// beamline
ostr = dynamic_cast<TObjString*>(tokens->At(2));
param.fBeamline = ostr->GetString();
param.fBeamline.push_back(ostr->GetString());
// institute
ostr = dynamic_cast<TObjString*>(tokens->At(3));
param.fInstitute = ostr->GetString();
param.fInstitute.push_back(ostr->GetString());
// data file format
ostr = dynamic_cast<TObjString*>(tokens->At(4));
param.fFileFormat = ostr->GetString();
param.fFileFormat.push_back(ostr->GetString());
}
}
// ADDRUN line ---------------------------------------------
if (iter->fLine.BeginsWith("addrun", TString::kIgnoreCase)) {
// get run name, beamline, institute, and file-format
if (tokens->GetEntries() < 5) {
error = true;
} else {
// run name
ostr = dynamic_cast<TObjString*>(tokens->At(1));
param.fRunName.push_back(ostr->GetString());
// beamline
ostr = dynamic_cast<TObjString*>(tokens->At(2));
param.fBeamline.push_back(ostr->GetString());
// institute
ostr = dynamic_cast<TObjString*>(tokens->At(3));
param.fInstitute.push_back(ostr->GetString());
// data file format
ostr = dynamic_cast<TObjString*>(tokens->At(4));
param.fFileFormat.push_back(ostr->GetString());
}
}
@ -1478,14 +1512,14 @@ bool PMsrHandler::HandleRunEntry(PMsrLines &lines)
// t0 -----------------------------------------------------
if (iter->fLine.BeginsWith("t0", TString::kIgnoreCase)) {
if ((tokens->GetEntries() != 2) && (tokens->GetEntries() != 3)) {
if (tokens->GetEntries() < 2) {
error = true;
} else {
for (int i=1; i<tokens->GetEntries(); i++) {
ostr = dynamic_cast<TObjString*>(tokens->At(i));
str = ostr->GetString();
if (str.IsDigit())
param.fT0[i-1] = str.Atoi();
param.fT0.push_back(str.Atoi());
else
error = true;
}
@ -1664,7 +1698,7 @@ bool PMsrHandler::HandleRunEntry(PMsrLines &lines)
found = false;
}
if (!found) {
cout << endl << ">> PMsrHandler::HandleRunEntry: **ERROR** for run " << fRuns[i].fRunName << ", forward " << fRuns[i].fForwardHistoNo;
cout << endl << ">> PMsrHandler::HandleRunEntry: **ERROR** for run " << fRuns[i].fRunName[0].Data() << ", forward " << fRuns[i].fForwardHistoNo;
cout << endl << " no background information found!";
cout << endl << " Either of the tags 'backgr.fit', 'backgr.fix', 'background'";
cout << endl << " with data is needed.";
@ -1687,10 +1721,10 @@ bool PMsrHandler::HandleRunEntry(PMsrLines &lines)
*/
void PMsrHandler::InitRunParameterStructure(PMsrRunStructure &param)
{
param.fRunName = "";
param.fBeamline = "";
param.fInstitute = "";
param.fFileFormat = "";
param.fRunName.clear();
param.fBeamline.clear();
param.fInstitute.clear();
param.fFileFormat.clear();
param.fFitType = -1;
param.fAlphaParamNo = -1;
param.fBetaParamNo = -1;
@ -1710,8 +1744,7 @@ void PMsrHandler::InitRunParameterStructure(PMsrRunStructure &param)
param.fBkgRange[i] = -1;
for (int i=0; i<4; i++)
param.fDataRange[i] = -1;
for (int i=0; i<2; i++)
param.fT0[i] = -1;
param.fT0.clear();
for (int i=0; i<4; i++)
param.fFitRange[i] = -1;
param.fPacking = 1;

View File

@ -512,7 +512,7 @@ void PMusrCanvas::UpdateInfoPad()
for (unsigned int i=0; i<fData.size(); i++) {
// run label = run_name/histo/T=0K/B=0G/E=0keV/...
runNo = (unsigned int)plotInfo.fRuns[i].Re()-1;
tstr = runs[runNo].fRunName + TString(","); // run_name
tstr = runs[runNo].fRunName[0] + TString(","); // run_name
// histo info (depending on the fittype
if (runs[runNo].fFitType == MSR_FITTYPE_SINGLE_HISTO) {
tstr += TString("h:");
@ -527,7 +527,7 @@ void PMusrCanvas::UpdateInfoPad()
}
// temperature if present
tstr += TString("T=");
dval = fRunList->GetTemp(runs[runNo].fRunName);
dval = fRunList->GetTemp(runs[runNo].fRunName[0]);
if (dval == -9.9e99) {
tstr += TString("??,");
} else {
@ -536,7 +536,7 @@ void PMusrCanvas::UpdateInfoPad()
}
// field if present
tstr += TString("B=");
dval = fRunList->GetField(runs[runNo].fRunName);
dval = fRunList->GetField(runs[runNo].fRunName[0]);
if (dval == -9.9e99) {
tstr += TString("??,");
} else {
@ -545,7 +545,7 @@ void PMusrCanvas::UpdateInfoPad()
}
// energy if present
tstr += TString("E=");
dval = fRunList->GetEnergy(runs[runNo].fRunName);
dval = fRunList->GetEnergy(runs[runNo].fRunName[0]);
//cout << endl << ">> dval = " << dval << " (Engery)";
if (dval == -9.9e99) {
tstr += TString("??,");
@ -554,7 +554,7 @@ void PMusrCanvas::UpdateInfoPad()
tstr += TString(sval) + TString("(keV),");
}
// setup if present
tstr += fRunList->GetSetup(runs[runNo].fRunName);
tstr += fRunList->GetSetup(runs[runNo].fRunName[0]);
// add entry
fInfoPad->AddEntry(fData[i].data, tstr.Data(), "p");
}
@ -1303,7 +1303,7 @@ void PMusrCanvas::HandleDataSet(unsigned int plotNo, unsigned int runNo, PRunDat
// dataHisto -------------------------------------------------------------
// create histo specific infos
name = fMsrHandler->GetMsrRunList()->at(runNo).fRunName + "_DataRunNo";
name = fMsrHandler->GetMsrRunList()->at(runNo).fRunName[0] + "_DataRunNo";
name += (int)runNo;
start = data->fDataTimeStart - data->fDataTimeStep/2.0;
end = data->fDataTimeStart + data->fValue.size()*data->fDataTimeStep + data->fDataTimeStep/2.0;
@ -1339,7 +1339,7 @@ void PMusrCanvas::HandleDataSet(unsigned int plotNo, unsigned int runNo, PRunDat
// theoHisto -------------------------------------------------------------
// create histo specific infos
name = fMsrHandler->GetMsrRunList()->at(runNo).fRunName + "_TheoRunNo";
name = fMsrHandler->GetMsrRunList()->at(runNo).fRunName[0] + "_TheoRunNo";
name += (int)runNo;
start = data->fTheoryTimeStart - data->fTheoryTimeStep/2.0;
end = data->fTheoryTimeStart + data->fTheory.size()*data->fTheoryTimeStep + data->fTheoryTimeStep/2.0;
@ -2166,8 +2166,8 @@ void PMusrCanvas::PlotData()
PMsrRunList runs = *fMsrHandler->GetMsrRunList();
PMsrPlotStructure plotInfo = fMsrHandler->GetMsrPlotList()->at(fPlotNumber);
unsigned int runNo = (unsigned int)plotInfo.fRuns[0].Re()-1;
TString xAxisTitle = fRunList->GetXAxisTitle(runs[runNo].fRunName, runNo);
TString yAxisTitle = fRunList->GetYAxisTitle(runs[runNo].fRunName, runNo);
TString xAxisTitle = fRunList->GetXAxisTitle(runs[runNo].fRunName[0], runNo);
TString yAxisTitle = fRunList->GetYAxisTitle(runs[runNo].fRunName[0], runNo);
if (fNonMusrData.size() > 0) {
// check if fMultiGraphData needs to be created, and if yes add all data and theory
@ -2250,7 +2250,7 @@ void PMusrCanvas::PlotDifference()
PMsrRunList runs = *fMsrHandler->GetMsrRunList();
PMsrPlotStructure plotInfo = fMsrHandler->GetMsrPlotList()->at(fPlotNumber);
unsigned int runNo = (unsigned int)plotInfo.fRuns[0].Re()-1;
TString xAxisTitle = fRunList->GetXAxisTitle(runs[runNo].fRunName, runNo);
TString xAxisTitle = fRunList->GetXAxisTitle(runs[runNo].fRunName[0], runNo);
// if fMultiGraphDiff is not present create it and add the diff data
if (!fMultiGraphDiff) {

View File

@ -280,9 +280,9 @@ bool PRunAsymmetry::PrepareData()
// get forward/backward histo from PRunDataHandler object ------------------------
// get the correct run
PRawRunData *runData = fRawData->GetRunData(fRunInfo->fRunName);
PRawRunData *runData = fRawData->GetRunData(fRunInfo->fRunName[0]);
if (!runData) { // run not found
cout << endl << "PRunAsymmetry::PrepareData(): Couldn't get run " << fRunInfo->fRunName.Data() << "!";
cout << endl << "PRunAsymmetry::PrepareData(): Couldn't get run " << fRunInfo->fRunName[0].Data() << "!";
return false;
}
@ -332,7 +332,7 @@ bool PRunAsymmetry::PrepareData()
// check if post pile up data shall be used
unsigned int histoNo[2]; // forward/backward
if (fRunInfo->fFileFormat.Contains("ppc")) {
if (fRunInfo->fFileFormat[0].Contains("ppc")) {
histoNo[0] = runData->fDataBin.size()/2 + fRunInfo->fForwardHistoNo-1;
histoNo[1] = runData->fDataBin.size()/2 + fRunInfo->fBackwardHistoNo-1;
} else {
@ -349,12 +349,92 @@ bool PRunAsymmetry::PrepareData()
cout << endl;
return false;
}
// get raw forward/backward histo data
for (unsigned int i=0; i<runData->fDataBin[histoNo[0]].size(); i++) {
fForward.push_back(runData->fDataBin[histoNo[0]][i]);
fBackward.push_back(runData->fDataBin[histoNo[1]][i]);
}
// check if addrun's are present, and if yes add data
// check if there are runs to be added to the current one
if (fRunInfo->fRunName.size() > 1) { // runs to be added present
PRawRunData *addRunData;
for (unsigned int i=1; i<fRunInfo->fRunName.size(); i++) {
// get run to be added to the main one
addRunData = fRawData->GetRunData(fRunInfo->fRunName[i]);
if (addRunData == 0) { // couldn't get run
cout << endl << "PRunAsymmetry::PrepareData(): **ERROR** Couldn't get addrun " << fRunInfo->fRunName[i].Data() << "!";
return false;
}
// get T0's of the to be added run
int t0Add[2] = {0, 0};
// check if the t0's are given in the msr-file
if (fRunInfo->fT0[0] == -1) { // t0's are NOT in the msr-file
// check if the t0's are in the data file
if (addRunData->fT0s.size() != 0) { // t0's in the run data
// keep the proper t0's. For asymmetry runs, forward/backward are holding the histo no
// fForwardHistoNo starts with 1 not with 0 etc. ;-)
t0Add[0] = addRunData->fT0s[fRunInfo->fForwardHistoNo-1]; // forward t0
t0Add[1] = addRunData->fT0s[fRunInfo->fBackwardHistoNo-1]; // backward t0
} else { // t0's are neither in the run data nor in the msr-file -> not acceptable!
cout << endl << "PRunAsymmetry::PrepareData(): NO t0's found, neither in the addrun (" << fRunInfo->fRunName[i].Data() << ") data nor in the msr-file!";
return false;
}
} else { // t0's in the msr-file
// check if t0's are given in the data file
if (addRunData->fT0s.size() != 0) {
// compare t0's of the msr-file with the one in the data file
if (fabs(t0Add[0]-addRunData->fT0s[fRunInfo->fForwardHistoNo-1])>5.0) { // given in bins!!
cout << endl << "PRunAsymmetry::PrepareData(): **WARNING**: forward histo";
cout << endl << " t0 from the msr-file is " << fRunInfo->fT0[0];
cout << endl << " t0 from the data file is " << addRunData->fT0s[fRunInfo->fForwardHistoNo-1];
cout << endl << " This is quite a deviation! Is this done intentionally??";
cout << endl << " addrun: " << fRunInfo->fRunName[i].Data();
cout << endl;
}
if (fabs(t0Add[1]-addRunData->fT0s[fRunInfo->fBackwardHistoNo-1])>5.0) { // given in bins!!
cout << endl << "PRunAsymmetry::PrepareData(): **WARNING**: backward histo";
cout << endl << " t0 from the msr-file is " << fRunInfo->fT0[1];
cout << endl << " t0 from the data file is " << addRunData->fT0s[fRunInfo->fBackwardHistoNo-1];
cout << endl << " This is quite a deviation! Is this done intentionally??";
cout << endl << " addrun: " << fRunInfo->fRunName[i].Data();
cout << endl;
}
}
if (2*i+1 < fRunInfo->fT0.size()) {
t0Add[0] = fRunInfo->fT0[2*i];
t0Add[1] = fRunInfo->fT0[2*i+1];
} else {
cout << endl << "PRunAsymmetry::PrepareData(): **WARNING** NO t0's found, neither in the addrun data (";
cout << fRunInfo->fRunName[i].Data();
cout << "), nor in the msr-file! Will try to use the T0 of the run data (";
cout << fRunInfo->fRunName[i].Data();
cout << ") without any warranty!";
t0Add[0] = fRunInfo->fT0[0];
t0Add[1] = fRunInfo->fT0[1];
}
}
// add forward run
for (unsigned int j=0; j<runData->fDataBin[histoNo[0]].size(); j++) {
// make sure that the index stays in the proper range
if ((j-t0Add[0]+fT0s[0] >= 0) && (j-t0Add[0]+fT0s[0] < addRunData->fDataBin[histoNo[0]].size())) {
fForward[j] += addRunData->fDataBin[histoNo[0]][j-t0Add[0]+fT0s[0]];
}
}
// add backward run
for (unsigned int j=0; j<runData->fDataBin[histoNo[1]].size(); j++) {
// make sure that the index stays in the proper range
if ((j-t0Add[1]+fT0s[1] >= 0) && (j-t0Add[1]+fT0s[1] < addRunData->fDataBin[histoNo[1]].size())) {
fBackward[j] += addRunData->fDataBin[histoNo[1]][j-t0Add[1]+fT0s[1]];
}
}
}
}
// subtract background from histogramms ------------------------------------------
if (!fRunInfo->fBkgFixPresent[0]) { // no fixed background given
if (fRunInfo->fBkgRange[0] != 0) {
@ -435,11 +515,11 @@ bool PRunAsymmetry::SubtractEstimatedBkg()
double beamPeriod = 0.0;
// check if data are from PSI, RAL, or TRIUMF
if (fRunInfo->fInstitute.Contains("psi"))
if (fRunInfo->fInstitute[0].Contains("psi"))
beamPeriod = ACCEL_PERIOD_PSI;
else if (fRunInfo->fInstitute.Contains("ral"))
else if (fRunInfo->fInstitute[0].Contains("ral"))
beamPeriod = ACCEL_PERIOD_RAL;
else if (fRunInfo->fInstitute.Contains("triumf"))
else if (fRunInfo->fInstitute[0].Contains("triumf"))
beamPeriod = ACCEL_PERIOD_TRIUMF;
else
beamPeriod = 0.0;
@ -642,15 +722,6 @@ bool PRunAsymmetry::PrepareFitData(PRawRunData* runData, unsigned int histoNo[2]
fData.fError.push_back(error);
}
/*
FILE *fp = fopen("asym.dat", "w");
for (unsigned int i=0; i<fData.fValue.size(); i++) {
fprintf(fp, "%lf, %lf, %lf\n", fData.fDataTimeStart+(double)i*fData.fDataTimeStep, fData.fValue[i], fData.fError[i]);
}
fclose(fp);
return false;
*/
// count the number of bins to be fitted
double time;
fNoOfFitBins=0;

View File

@ -149,35 +149,36 @@ bool PRunDataHandler::ReadFile()
return false;
}
PMsrRunList::iterator run_it;
for (run_it = runList->begin(); run_it != runList->end(); ++run_it) {
//cout << endl << "run : " << run_it->fRunName.Data();
fRunName = run_it->fRunName;
// check is file is already read
if (FileAlreadyRead(*run_it))
continue;
// check if file actually exists
if (!FileExistsCheck(*run_it))
return false;
// everything looks fine, hence try to read the data file
if (!run_it->fFileFormat.CompareTo("root-npp")) // not post pile up corrected histos
success = ReadRootFile(true);
else if (!run_it->fFileFormat.CompareTo("root-ppc")) // post pile up corrected histos
success = ReadRootFile(false);
else if (!run_it->fFileFormat.CompareTo("nexus"))
success = ReadNexusFile();
else if (!run_it->fFileFormat.CompareTo("psi-bin"))
success = ReadPsiBinFile();
else if (!run_it->fFileFormat.CompareTo("mud"))
success = ReadMudFile();
else if (!run_it->fFileFormat.CompareTo("wkm"))
success = ReadWkmFile();
else if (!run_it->fFileFormat.CompareTo("ascii"))
success = ReadAsciiFile();
else if (!run_it->fFileFormat.CompareTo("db"))
success = ReadDBFile();
else
success = false;
for (unsigned int i=0; i<runList->size(); i++) {
for (unsigned int j=0; j<runList->at(i).fRunName.size(); j++) {
// cout << endl << "run : " << runList->at(i).fRunName[j].Data();
fRunName = runList->at(i).fRunName[j];
// check is file is already read
if (FileAlreadyRead(runList->at(i).fRunName[j]))
continue;
// check if file actually exists
if (!FileExistsCheck(runList->at(i), j))
return false;
// everything looks fine, hence try to read the data file
if (!runList->at(i).fFileFormat[j].CompareTo("root-npp")) // not post pile up corrected histos
success = ReadRootFile(true);
else if (!runList->at(i).fFileFormat[j].CompareTo("root-ppc")) // post pile up corrected histos
success = ReadRootFile(false);
else if (!runList->at(i).fFileFormat[j].CompareTo("nexus"))
success = ReadNexusFile();
else if (!runList->at(i).fFileFormat[j].CompareTo("psi-bin"))
success = ReadPsiBinFile();
else if (!runList->at(i).fFileFormat[j].CompareTo("mud"))
success = ReadMudFile();
else if (!runList->at(i).fFileFormat[j].CompareTo("wkm"))
success = ReadWkmFile();
else if (!runList->at(i).fFileFormat[j].CompareTo("ascii"))
success = ReadAsciiFile();
else if (!runList->at(i).fFileFormat[j].CompareTo("db"))
success = ReadDBFile();
else
success = false;
}
}
return success;
@ -190,10 +191,10 @@ bool PRunDataHandler::ReadFile()
* <p>
*
*/
bool PRunDataHandler::FileAlreadyRead(PMsrRunStructure &runInfo)
bool PRunDataHandler::FileAlreadyRead(TString runName)
{
for (unsigned int i=0; i<fData.size(); i++) {
if (!fData[i].fRunName.CompareTo(runInfo.fRunName)) { // run alread read
if (!fData[i].fRunName.CompareTo(runName)) { // run alread read
return true;
}
}
@ -208,7 +209,7 @@ bool PRunDataHandler::FileAlreadyRead(PMsrRunStructure &runInfo)
* <p>
*
*/
bool PRunDataHandler::FileExistsCheck(PMsrRunStructure &runInfo)
bool PRunDataHandler::FileExistsCheck(PMsrRunStructure &runInfo, const unsigned int idx)
{
bool success = true;
@ -218,37 +219,37 @@ bool PRunDataHandler::FileExistsCheck(PMsrRunStructure &runInfo)
TString str;
TString ext;
runInfo.fBeamline.ToLower();
runInfo.fInstitute.ToLower();
runInfo.fFileFormat.ToLower();
runInfo.fBeamline[idx].ToLower();
runInfo.fInstitute[idx].ToLower();
runInfo.fFileFormat[idx].ToLower();
// file extensions for the various formats
if (!runInfo.fFileFormat.CompareTo("root-npp")) // not post pile up corrected histos
if (!runInfo.fFileFormat[idx].CompareTo("root-npp")) // not post pile up corrected histos
ext = TString("root");
else if (!runInfo.fFileFormat.CompareTo("root-ppc")) // post pile up corrected histos
else if (!runInfo.fFileFormat[idx].CompareTo("root-ppc")) // post pile up corrected histos
ext = TString("root");
else if (!runInfo.fFileFormat.CompareTo("nexus"))
else if (!runInfo.fFileFormat[idx].CompareTo("nexus"))
ext = TString("nexus");
else if (!runInfo.fFileFormat.CompareTo("psi-bin"))
else if (!runInfo.fFileFormat[idx].CompareTo("psi-bin"))
ext = TString("bin");
else if (!runInfo.fFileFormat.CompareTo("mud"))
else if (!runInfo.fFileFormat[idx].CompareTo("mud"))
ext = TString("mud");
else if (!runInfo.fFileFormat.CompareTo("wkm")) {
if (!runInfo.fBeamline.CompareTo("mue4"))
else if (!runInfo.fFileFormat[idx].CompareTo("wkm")) {
if (!runInfo.fBeamline[idx].CompareTo("mue4"))
ext = TString("nemu");
else
ext = runInfo.fBeamline;
ext = runInfo.fBeamline[idx];
}
else if (!runInfo.fFileFormat.CompareTo("ascii"))
else if (!runInfo.fFileFormat[idx].CompareTo("ascii"))
ext = TString("dat");
else if (!runInfo.fFileFormat.CompareTo("db"))
else if (!runInfo.fFileFormat[idx].CompareTo("db"))
ext = TString("db");
else
success = false;
// unkown file format found
if (!success) {
str = runInfo.fFileFormat;
str = runInfo.fFileFormat[idx];
str.ToUpper();
cout << endl << "File Format '" << str.Data() << "' unsupported.";
cout << endl << " support file formats are:";
@ -265,7 +266,7 @@ bool PRunDataHandler::FileExistsCheck(PMsrRunStructure &runInfo)
}
// check if the file is in the local directory
str = runInfo.fRunName + TString(".") + ext;
str = runInfo.fRunName[idx] + TString(".") + ext;
if (gSystem->AccessPathName(str.Data())!=true) { // found in the local dir
pathName = str;
}
@ -273,7 +274,7 @@ bool PRunDataHandler::FileExistsCheck(PMsrRunStructure &runInfo)
// check if the file is found in the directory given in the startup file
if (pathName.CompareTo("???") == 0) { // not found in local directory search
for (unsigned int i=0; i<fDataPath.size(); i++) {
str = fDataPath[i] + TString("/") + runInfo.fRunName + TString(".") + ext;
str = fDataPath[i] + TString("/") + runInfo.fRunName[idx] + TString(".") + ext;
if (gSystem->AccessPathName(str.Data())!=true) { // found
pathName = str;
break;
@ -290,7 +291,7 @@ bool PRunDataHandler::FileExistsCheck(PMsrRunStructure &runInfo)
TObjString *ostr;
for (int i=0; i<tokens->GetEntries(); i++) {
ostr = dynamic_cast<TObjString*>(tokens->At(i));
str = ostr->GetString() + TString("/") + runInfo.fRunName + TString(".") + ext;
str = ostr->GetString() + TString("/") + runInfo.fRunName[idx] + TString(".") + ext;
if (gSystem->AccessPathName(str.Data())!=true) { // found
pathName = str;
break;
@ -304,18 +305,18 @@ bool PRunDataHandler::FileExistsCheck(PMsrRunStructure &runInfo)
// WKMFULLDATAPATH has the structure: path_1:path_2:...:path_n
TObjArray *tokens = str.Tokenize(":");
TObjString *ostr;
runInfo.fInstitute.ToUpper();
runInfo.fBeamline.ToUpper();
runInfo.fInstitute[idx].ToUpper();
runInfo.fBeamline[idx].ToUpper();
TDatime datetime;
TString dt;
dt += datetime.GetYear();
for (int i=0; i<tokens->GetEntries(); i++) {
ostr = dynamic_cast<TObjString*>(tokens->At(i));
str = ostr->GetString() + TString("/DATA/") +
runInfo.fInstitute + TString("/") +
runInfo.fBeamline + TString("/") +
runInfo.fInstitute[idx] + TString("/") +
runInfo.fBeamline[idx] + TString("/") +
dt + TString("/") +
runInfo.fRunName + TString(".") + ext;
runInfo.fRunName[idx] + TString(".") + ext;
cout << endl << ">> generated path: " << str.Data() << endl;
if (gSystem->AccessPathName(str.Data())!=true) { // found
pathName = str;
@ -326,7 +327,7 @@ cout << endl << ">> generated path: " << str.Data() << endl;
// no proper path name found
if (pathName.CompareTo("???") == 0) {
cout << endl << "**ERROR** Couldn't find '" << runInfo.fRunName << "' in any standard path.";
cout << endl << "**ERROR** Couldn't find '" << runInfo.fRunName[idx] << "' in any standard path.";
cout << endl << " standard search pathes are:";
cout << endl << " 1. the local directory";
cout << endl << " 2. the data directory given in the startup XML file";
@ -355,6 +356,7 @@ bool PRunDataHandler::ReadRootFile(bool notPostPileup)
PRawRunData runData;
//cout << endl << ">> in ReadRootFile() ...";
//cout << endl << ">> fRunPathName = " << fRunPathName.Data();
TFile f(fRunPathName.Data());
if (f.IsZombie()) {
return false;
@ -402,8 +404,9 @@ bool PRunDataHandler::ReadRootFile(bool notPostPileup)
// check if t0's are there
if (t0[0] != -1) { // ugly, but at the moment there is no other way
// copy t0's so they are not lost
for (int i=0; i<noOfHistos; i++)
runData.fT0s.push_back(t0[i]);
for (int i=0; i<noOfHistos; i++) {
runData.fT0s.push_back((int)t0[i]);
}
}
// read data ---------------------------------------------------------
@ -843,7 +846,7 @@ cout << endl;
return false;
}
for (unsigned int i=0; i<ivec.size(); i++)
runData.fT0s.push_back((double)ivec[i]);
runData.fT0s.push_back(ivec[i]);
// fill raw data
PDoubleVector histoData;

View File

@ -63,7 +63,7 @@ PRunNonMusr::PRunNonMusr() : PRunBase()
PRunNonMusr::PRunNonMusr(PMsrHandler *msrInfo, PRunDataHandler *rawData, unsigned int runNo, EPMusrHandleTag tag) : PRunBase(msrInfo, rawData, runNo, tag)
{
// get the proper run
fRawRunData = fRawData->GetRunData(fRunInfo->fRunName);
fRawRunData = fRawData->GetRunData(fRunInfo->fRunName[0]);
if (!fRawRunData) { // couldn't get run
cout << endl << "PRunNonMusr::PRunNonMusr(): **ERROR** Couldn't get raw run data!";
fValid = false;
@ -237,7 +237,7 @@ bool PRunNonMusr::PrepareViewData()
{
bool success = true;
cout << endl << ">> fRunInfo->fRunName = " << fRunInfo->fRunName.Data();
cout << endl << ">> fRunInfo->fRunName = " << fRunInfo->fRunName[0].Data();
// get x-, y-index
unsigned int xIndex = GetXIndex();

View File

@ -307,12 +307,133 @@ bool PRunSingleHisto::PrepareData()
// cout << endl << "in PRunSingleHisto::PrepareData(): will feed fData";
bool success = true;
// get the proper run
PRawRunData* runData = fRawData->GetRunData(fRunInfo->fRunName[0]);
if (!runData) { // couldn't get run
cout << endl << "PRunSingleHisto::PrepareData(): **ERROR** Couldn't get run " << fRunInfo->fRunName[0].Data() << "!";
return false;
}
// check if post pile up data shall be used
unsigned int histoNo;
if (fRunInfo->fFileFormat[0].Contains("ppc")) {
histoNo = runData->fDataBin.size()/2 + fRunInfo->fForwardHistoNo-1;
} else {
histoNo = fRunInfo->fForwardHistoNo-1;
}
if ((runData->fDataBin.size() < histoNo) || (histoNo < 0)) {
cout << endl << "PRunSingleHisto::PrepareData(): **PANIC ERROR**:";
cout << endl << " histoNo found = " << histoNo << ", but there are only " << runData->fDataBin.size() << " runs!?!?";
cout << endl << " Will quite :-(";
cout << endl;
return false;
}
// check if the t0's are given in the msr-file
if (fRunInfo->fT0[0] == -1) { // t0's are NOT in the msr-file
// check if the t0's are in the data file
if (runData->fT0s.size() != 0) { // t0's in the run data
// keep the proper t0's. For single histo runs, forward is holding the histo no
// fForwardHistoNo starts with 1 not with 0 ;-)
fT0s.push_back(runData->fT0s[fRunInfo->fForwardHistoNo-1]);
} else { // t0's are neither in the run data nor in the msr-file -> not acceptable!
cout << endl << "PRunSingleHisto::PrepareData(): **ERROR** NO t0's found, neither in the run data nor in the msr-file!";
cout << endl << " run: " << fRunInfo->fRunName[0].Data();
return false;
}
} else { // t0's in the msr-file
// check if t0's are given in the data file
if (runData->fT0s.size() != 0) {
// compare t0's of the msr-file with the one in the data file
if (fabs(fRunInfo->fT0[0]-runData->fT0s[fRunInfo->fForwardHistoNo-1])>5.0) { // given in bins!!
cout << endl << "PRunSingleHisto::PrepareData(): **WARNING**:";
cout << endl << " t0 from the msr-file is " << fRunInfo->fT0[0];
cout << endl << " t0 from the data file is " << runData->fT0s[fRunInfo->fForwardHistoNo-1];
cout << endl << " This is quite a deviation! Is this done intentionally??";
cout << endl;
}
}
fT0s.push_back(fRunInfo->fT0[0]);
}
// check if t0 is within proper bounds
int t0 = fT0s[0];
if ((t0 < 0) || (t0 > (int)runData->fDataBin[histoNo].size())) {
cout << endl << "PRunSingleHisto::PrepareData(): **ERROR** t0 data bin doesn't make any sense!";
return false;
}
// check if there are runs to be added to the current one
if (fRunInfo->fRunName.size() > 1) { // runs to be added present
PRawRunData *addRunData;
for (unsigned int i=1; i<fRunInfo->fRunName.size(); i++) {
// get run to be added to the main one
addRunData = fRawData->GetRunData(fRunInfo->fRunName[i]);
if (addRunData == 0) { // couldn't get run
cout << endl << "PRunSingleHisto::PrepareData(): **ERROR** Couldn't get addrun " << fRunInfo->fRunName[i].Data() << "!";
return false;
}
// get T0's of the to be added run
int t0Add;
// check if the t0's are given in the msr-file
if (fRunInfo->fT0[i] == -1) { // t0's are NOT in the msr-file
// check if the t0's are in the data file
if (addRunData->fT0s.size() != 0) { // t0's in the run data
// keep the proper t0's. For single histo runs, forward is holding the histo no
// fForwardHistoNo starts with 1 not with 0 ;-)
t0Add = addRunData->fT0s[fRunInfo->fForwardHistoNo-1];
} else { // t0's are neither in the run data nor in the msr-file -> not acceptable!
cout << endl << "PRunSingleHisto::PrepareData(): **ERROR** NO t0's found, neither in the addrun data nor in the msr-file!";
cout << endl << " addrun: " << fRunInfo->fRunName[i].Data();
return false;
}
} else { // t0's in the msr-file
// check if t0's are given in the data file
if (addRunData->fT0s.size() != 0) {
// compare t0's of the msr-file with the one in the data file
if (fabs(fRunInfo->fT0[i]-addRunData->fT0s[fRunInfo->fForwardHistoNo-1])>5.0) { // given in bins!!
cout << endl << "PRunSingleHisto::PrepareData(): **WARNING**:";
cout << endl << " t0 from the msr-file is " << fRunInfo->fT0[i];
cout << endl << " t0 from the data file is " << addRunData->fT0s[fRunInfo->fForwardHistoNo-1];
cout << endl << " This is quite a deviation! Is this done intentionally??";
cout << endl << " addrun: " << fRunInfo->fRunName[i].Data();
cout << endl;
}
}
if (i < fRunInfo->fT0.size()) {
t0Add = fRunInfo->fT0[i];
} else {
cout << endl << "PRunSingleHisto::PrepareData(): **WARNING** NO t0's found, neither in the addrun data (";
cout << fRunInfo->fRunName[i].Data();
cout << "), nor in the msr-file! Will try to use the T0 of the run data (";
cout << fRunInfo->fRunName[i].Data();
cout << ") without any warranty!";
t0Add = fRunInfo->fT0[0];
}
}
// add run
for (unsigned int j=0; j<runData->fDataBin[histoNo].size(); j++) {
// make sure that the index stays in the proper range
if ((j-t0Add+t0 >= 0) && (j-t0Add+t0 < addRunData->fDataBin[histoNo].size())) {
runData->fDataBin[histoNo][j] += addRunData->fDataBin[histoNo][j-t0Add+t0];
}
}
}
}
// keep the time resolution in (us)
fTimeResolution = runData->fTimeResolution/1.0e3;
if (fHandleTag == kFit)
success = PrepareFitData();
success = PrepareFitData(runData, histoNo);
else if ((fHandleTag == kView) && !fRunInfo->fLifetimeCorrection)
success = PrepareRawViewData();
success = PrepareRawViewData(runData, histoNo);
else if ((fHandleTag == kView) && fRunInfo->fLifetimeCorrection)
success = PrepareViewData();
success = PrepareViewData(runData, histoNo);
else
success = false;
@ -326,23 +447,31 @@ bool PRunSingleHisto::PrepareData()
* <p>
*
*/
bool PRunSingleHisto::PrepareFitData()
bool PRunSingleHisto::PrepareFitData(PRawRunData* runData, const unsigned int histoNo)
{
/*
// get the proper run
PRawRunData* runData = fRawData->GetRunData(fRunInfo->fRunName);
if (!runData) { // couldn't get run
cout << endl << "PRunSingleHisto::PrepareFitData(): **ERROR** Couldn't get run " << fRunInfo->fRunName.Data() << "!";
PRawRunData* runData = fRawData->GetRunData(fRunInfo->fRunName[0]);
if (runData == 0) { // couldn't get run
cout << endl << "PRunSingleHisto::PrepareFitData(): **ERROR** Couldn't get run " << fRunInfo->fRunName[0].Data() << "!";
return false;
}
// keep the time resolution in (us)
fTimeResolution = runData->fTimeResolution/1.0e3;
// keep start/stop time for fit
fFitStartTime = fRunInfo->fFitRange[0];
fFitStopTime = fRunInfo->fFitRange[1];
//cout << endl << "start/stop (fit): " << fFitStartTime << ", " << fFitStopTime;
// get the proper histo number and check if post pile up data shall be used (LEM)
unsigned int histoNo;
if (fRunInfo->fFileFormat[0].Contains("ppc")) {
histoNo = runData->fDataBin.size()/2 + fRunInfo->fForwardHistoNo-1;
} else {
histoNo = fRunInfo->fForwardHistoNo-1;
}
if ((runData->fDataBin.size() < histoNo) || (histoNo < 0)) {
cout << endl << "PRunSingleHisto::PrepareFitData(): **PANIC ERROR**:";
cout << endl << " histoNo found = " << histoNo << ", but there are only " << runData->fDataBin.size() << " runs!?!?";
cout << endl << " Will quit :-(";
cout << endl;
return false;
}
// check if the t0's are given in the msr-file
if (fRunInfo->fT0[0] == -1) { // t0's are NOT in the msr-file
@ -352,7 +481,8 @@ bool PRunSingleHisto::PrepareFitData()
// fForwardHistoNo starts with 1 not with 0 ;-)
fT0s.push_back(runData->fT0s[fRunInfo->fForwardHistoNo-1]);
} else { // t0's are neither in the run data nor in the msr-file -> not acceptable!
cout << endl << "PRunSingleHisto::PrepareData(): **ERROR** NO t0's found, neither in the run data nor in the msr-file!";
cout << endl << "PRunSingleHisto::PrepareFitData(): **ERROR** NO t0's found, neither in the run data nor in the msr-file!";
cout << endl << " run: " << fRunInfo->fRunName[0].Data();
return false;
}
} else { // t0's in the msr-file
@ -370,28 +500,88 @@ bool PRunSingleHisto::PrepareFitData()
fT0s.push_back(fRunInfo->fT0[0]);
}
// check if post pile up data shall be used
unsigned int histoNo;
if (fRunInfo->fFileFormat.Contains("ppc")) {
histoNo = runData->fDataBin.size()/2 + fRunInfo->fForwardHistoNo-1;
} else {
histoNo = fRunInfo->fForwardHistoNo-1;
}
if ((runData->fDataBin.size() < histoNo) || (histoNo < 0)) {
cout << endl << "PRunSingleHisto::PrepareFitData(): **PANIC ERROR**:";
cout << endl << " histoNo found = " << histoNo << ", but there are only " << runData->fDataBin.size() << " runs!?!?";
cout << endl << " Will quite :-(";
cout << endl;
// check if t0 is within proper bounds
int t0 = fT0s[0];
if ((t0 < 0) || (t0 > (int)runData->fDataBin[histoNo].size())) {
cout << endl << "PRunSingleHisto::PrepareFitData(): **ERROR** t0 data bin doesn't make any sense!";
return false;
}
// check if there are runs to be added to the current one
if (fRunInfo->fRunName.size() > 1) { // runs to be added present
PRawRunData *addRunData;
for (unsigned int i=1; i<fRunInfo->fRunName.size(); i++) {
// get run to be added to the main one
addRunData = fRawData->GetRunData(fRunInfo->fRunName[i]);
if (addRunData == 0) { // couldn't get run
cout << endl << "PRunSingleHisto::PrepareFitData(): **ERROR** Couldn't get addrun " << fRunInfo->fRunName[i].Data() << "!";
return false;
}
// get T0's of the to be added run
int t0Add;
// check if the t0's are given in the msr-file
if (fRunInfo->fT0[i] == -1) { // t0's are NOT in the msr-file
// check if the t0's are in the data file
if (addRunData->fT0s.size() != 0) { // t0's in the run data
// keep the proper t0's. For single histo runs, forward is holding the histo no
// fForwardHistoNo starts with 1 not with 0 ;-)
t0Add = addRunData->fT0s[fRunInfo->fForwardHistoNo-1];
} else { // t0's are neither in the run data nor in the msr-file -> not acceptable!
cout << endl << "PRunSingleHisto::PrepareFitData(): **ERROR** NO t0's found, neither in the addrun data nor in the msr-file!";
cout << endl << " addrun: " << fRunInfo->fRunName[i].Data();
return false;
}
} else { // t0's in the msr-file
// check if t0's are given in the data file
if (addRunData->fT0s.size() != 0) {
// compare t0's of the msr-file with the one in the data file
if (fabs(fRunInfo->fT0[i]-addRunData->fT0s[fRunInfo->fForwardHistoNo-1])>5.0) { // given in bins!!
cout << endl << "PRunSingleHisto::PrepareFitData(): **WARNING**:";
cout << endl << " t0 from the msr-file is " << fRunInfo->fT0[i];
cout << endl << " t0 from the data file is " << addRunData->fT0s[fRunInfo->fForwardHistoNo-1];
cout << endl << " This is quite a deviation! Is this done intentionally??";
cout << endl;
}
}
if (i < fRunInfo->fT0.size()) {
t0Add = fRunInfo->fT0[i];
} else {
cout << endl << "PRunSingleHisto::PrepareFitData(): **WARNING** NO t0's found, neither in the addrun data (";
cout << fRunInfo->fRunName[i].Data();
cout << "), nor in the msr-file! Will try to use the T0 of the run data (";
cout << fRunInfo->fRunName[i].Data();
cout << ") without any warranty!";
t0Add = fRunInfo->fT0[0];
}
}
// add run
for (unsigned int j=0; j<runData->fDataBin[histoNo].size(); j++) {
// make sure that the index stays in the proper range
if ((j-t0Add+t0 >= 0) && (j-t0Add+t0 < addRunData->fDataBin[histoNo].size())) {
runData->fDataBin[histoNo][j] += addRunData->fDataBin[histoNo][j-t0Add+t0];
}
}
}
}
// keep the time resolution in (us)
fTimeResolution = runData->fTimeResolution/1.0e3;
*/
// keep start/stop time for fit
fFitStartTime = fRunInfo->fFitRange[0];
fFitStopTime = fRunInfo->fFitRange[1];
//cout << endl << "start/stop (fit): " << fFitStartTime << ", " << fFitStopTime;
// transform raw histo data. This is done the following way (for details see the manual):
// for the single histo fit, just the rebinned raw data are copied
// first get start data, end data, and t0
unsigned int start;
unsigned int end;
double t0 = fT0s[0];
start = fRunInfo->fDataRange[0];
end = fRunInfo->fDataRange[1];
// check if start, end, and t0 make any sense
@ -411,11 +601,6 @@ bool PRunSingleHisto::PrepareFitData()
cout << endl << "PRunSingleHisto::PrepareFitData(): **ERROR** end data bin doesn't make any sense!";
return false;
}
// 4th check if t0 is within proper bounds
if ((t0 < 0) || (t0 > runData->fDataBin[histoNo].size())) {
cout << endl << "PRunSingleHisto::PrepareFitData(): **ERROR** t0 data bin doesn't make any sense!";
return false;
}
// check how the background shall be handled
if (fRunInfo->fBkgFitParamNo == -1) { // bkg shall **NOT** be fitted
@ -433,11 +618,12 @@ bool PRunSingleHisto::PrepareFitData()
}
// everything looks fine, hence fill data set
int t0 = fT0s[0];
double value = 0.0;
double normalizer = 1.0;
// data start at data_start-t0
// time shifted so that packing is included correctly, i.e. t0 == t0 after packing
fData.fDataTimeStart = fTimeResolution*(((double)start-t0)+(double)fRunInfo->fPacking/2.0);
fData.fDataTimeStart = fTimeResolution*((double)(start-t0)+(double)(fRunInfo->fPacking-1)/2.0);
fData.fDataTimeStep = fTimeResolution*fRunInfo->fPacking;
for (unsigned i=start; i<end; i++) {
if (fRunInfo->fPacking == 1) {
@ -485,69 +671,16 @@ bool PRunSingleHisto::PrepareFitData()
* <p> Muon raw data
*
*/
bool PRunSingleHisto::PrepareRawViewData()
bool PRunSingleHisto::PrepareRawViewData(PRawRunData* runData, const unsigned int histoNo)
{
// get the proper run
PRawRunData* runData = fRawData->GetRunData(fRunInfo->fRunName);
if (!runData) { // couldn't get run
cout << endl << "PRunSingleHisto::PrepareRawViewData(): **ERROR** Couldn't get run " << fRunInfo->fRunName.Data() << "!";
return false;
}
// keep the time resolution in (us)
fTimeResolution = runData->fTimeResolution/1.0e3;
// check if the t0's are given in the msr-file
if (fRunInfo->fT0[0] == -1) { // t0's are NOT in the msr-file
// check if the t0's are in the data file
if (runData->fT0s.size() != 0) { // t0's in the run data
// keep the proper t0's. For single histo runs, forward is holding the histo no
// fForwardHistoNo starts with 1 not with 0 ;-)
fT0s.push_back(runData->fT0s[fRunInfo->fForwardHistoNo-1]);
} else { // t0's are neither in the run data nor in the msr-file -> not acceptable!
cout << endl << "PRunSingleHisto::PrepareRawViewData(): **ERROR** NO t0's found, neither in the run data nor in the msr-file!";
return false;
}
} else { // t0's in the msr-file
// check if t0's are given in the data file
if (runData->fT0s.size() != 0) {
// compare t0's of the msr-file with the one in the data file
if (fabs(fRunInfo->fT0[0]-runData->fT0s[fRunInfo->fForwardHistoNo-1])>5.0) { // given in bins!!
cout << endl << "PRunSingleHisto::PrepareRawViewData(): **WARNING**:";
cout << endl << " t0 from the msr-file is " << fRunInfo->fT0[0];
cout << endl << " t0 from the data file is " << runData->fT0s[fRunInfo->fForwardHistoNo-1];
cout << endl << " This is quite a deviation! Is this done intentionally??";
cout << endl;
}
}
fT0s.push_back(fRunInfo->fT0[0]);
}
// check if post pile up data shall be used
unsigned int histoNo;
if (fRunInfo->fFileFormat.Contains("ppc")) {
histoNo = runData->fDataBin.size()/2 + fRunInfo->fForwardHistoNo-1;
} else {
histoNo = fRunInfo->fForwardHistoNo-1;
}
if ((runData->fDataBin.size() < histoNo) || (histoNo < 0)) {
cout << endl << "PRunSingleHisto::PrepareRawViewData(): **PANIC ERROR**:";
cout << endl << " histoNo found = " << histoNo << ", but there are only " << runData->fDataBin.size() << " runs!?!?";
cout << endl << " Will quite :-(";
cout << endl;
return false;
}
// transform raw histo data. This is done the following way (for details see the manual):
// for the single histo fit, just the rebinned raw data are copied
// first get start data, end data, and t0
unsigned int start;
unsigned int end;
double t0 = fT0s[0];
// raw data, since PMusrCanvas is doing ranging etc.
// start = the first bin which is a multiple of packing backward from t0
start = (int)t0 - ((int)t0/fRunInfo->fPacking)*fRunInfo->fPacking;
// start = the first bin which is a multiple of packing backward from first good data bin
start = fRunInfo->fDataRange[0] - (fRunInfo->fDataRange[0]/fRunInfo->fPacking)*fRunInfo->fPacking;
// end = last bin starting from start which is a multipl of packing and still within the data
end = start + ((runData->fDataBin[histoNo].size()-start-1)/fRunInfo->fPacking)*fRunInfo->fPacking;
// check if start, end, and t0 make any sense
@ -567,24 +700,21 @@ bool PRunSingleHisto::PrepareRawViewData()
cout << endl << "PRunSingleHisto::PrepareRawViewData(): **ERROR** end data bin doesn't make any sense!";
return false;
}
// 4th check if t0 is within proper bounds
if ((t0 < 0) || (t0 > runData->fDataBin[histoNo].size())) {
cout << endl << "PRunSingleHisto::PrepareRawViewData(): **ERROR** t0 data bin doesn't make any sense!";
return false;
}
// everything looks fine, hence fill data set
int t0 = fT0s[0];
double value = 0.0;
// data start at data_start-t0
// time shifted so that packing is included correctly, i.e. t0 == t0 after packing
fData.fDataTimeStart = fTimeResolution*((double)start-t0+(double)fRunInfo->fPacking/2.0);
fData.fDataTimeStart = fTimeResolution*((double)start-(double)t0+(double)(fRunInfo->fPacking-1)/2.0);
fData.fDataTimeStep = fTimeResolution*fRunInfo->fPacking;
/*
cout << endl << ">> time resolution = " << fTimeResolution;
cout << endl << ">> start = " << start << ", t0 = " << t0 << ", packing = " << fRunInfo->fPacking;
cout << endl << ">> data start time = " << fData.fDataTimeStart;
*/
double normalizer = 1.0;
fData.fDataTimeStep = fTimeResolution*fRunInfo->fPacking;
for (unsigned i=start; i<end; i++) {
if (((i-start) % fRunInfo->fPacking == 0) && (i != start)) { // fill data
// in order that after rebinning the fit does not need to be redone (important for plots)
@ -659,13 +789,11 @@ cout << endl << ">> data start time = " << fData.fDataTimeStart;
// calculate theory
unsigned int size = runData->fDataBin[histoNo].size();
double startTime = -fT0s[0]*fTimeResolution;
double theoryValue;
fData.fTheoryTimeStart = startTime;
//cout << endl << ">> theory start time = " << fData.fTheoryTimeStart;
fData.fTheoryTimeStart = fData.fDataTimeStart;
fData.fTheoryTimeStep = fTimeResolution;
for (unsigned int i=0; i<size; i++) {
time = startTime + (double)i*fTimeResolution;
time = fData.fTheoryTimeStart + i*fTimeResolution;
theoryValue = fTheory->Func(time, par, fFuncValues);
if (theoryValue > 10.0) { // dirty hack needs to be fixed!!
theoryValue = 0.0;
@ -693,71 +821,20 @@ cout << endl << ">> data start time = " << fData.fDataTimeStart;
* \f[ N(t_i) = \frac{1}{p}\, \sum_{j=i}^{i+p} n_j \f]
* with \f$ n_j \f$ the raw histogram data bins.
*/
bool PRunSingleHisto::PrepareViewData()
bool PRunSingleHisto::PrepareViewData(PRawRunData* runData, const unsigned int histoNo)
{
// get the proper run
PRawRunData* runData = fRawData->GetRunData(fRunInfo->fRunName);
if (!runData) { // couldn't get run
cout << endl << "PRunSingleHisto::PrepareViewData(): **ERROR** Couldn't get run " << fRunInfo->fRunName.Data() << "!";
return false;
}
// keep the time resolution in (us)
fTimeResolution = runData->fTimeResolution/1.0e3;
// check if the t0's are given in the msr-file
if (fRunInfo->fT0[0] == -1) { // t0's are NOT in the msr-file
// check if the t0's are in the data file
if (runData->fT0s.size() != 0) { // t0's in the run data
// keep the proper t0's. For single histo runs, forward is holding the histo no
// fForwardHistoNo starts with 1 not with 0 ;-)
fT0s.push_back(runData->fT0s[fRunInfo->fForwardHistoNo-1]);
} else { // t0's are neither in the run data nor in the msr-file -> not acceptable!
cout << endl << "PRunSingleHisto::PrepareViewData(): **ERROR** NO t0's found, neither in the run data nor in the msr-file!";
return false;
}
} else { // t0's in the msr-file
// check if t0's are given in the data file
if (runData->fT0s.size() != 0) {
// compare t0's of the msr-file with the one in the data file
if (fabs(fRunInfo->fT0[0]-runData->fT0s[fRunInfo->fForwardHistoNo-1])>5.0) { // given in bins!!
cout << endl << "PRunSingleHisto::PrepareViewData(): **WARNING**:";
cout << endl << " t0 from the msr-file is " << fRunInfo->fT0[0];
cout << endl << " t0 from the data file is " << runData->fT0s[fRunInfo->fForwardHistoNo-1];
cout << endl << " This is quite a deviation! Is this done intentionally??";
cout << endl;
}
}
fT0s.push_back(fRunInfo->fT0[0]);
}
// check if post pile up data shall be used
unsigned int histoNo;
if (fRunInfo->fFileFormat.Contains("ppc")) {
histoNo = runData->fDataBin.size()/2 + fRunInfo->fForwardHistoNo-1;
} else {
histoNo = fRunInfo->fForwardHistoNo-1;
}
if ((runData->fDataBin.size() < histoNo) || (histoNo < 0)) {
cout << endl << "PRunSingleHisto::PrepareViewData(): **PANIC ERROR**:";
cout << endl << " histoNo found = " << histoNo << ", but there are only " << runData->fDataBin.size() << " runs!?!?";
cout << endl << " Will quite :-(";
cout << endl;
return false;
}
// transform raw histo data. This is done the following way (for details see the manual):
// for the single histo fit, just the rebinned raw data are copied
// first get start data, end data, and t0
unsigned int start;
unsigned int end;
double t0 = fT0s[0];
// raw data, since PMusrCanvas is doing ranging etc.
// start = the first bin which is a multiple of packing backward from t0
start = (int)t0 - ((int)t0/fRunInfo->fPacking)*fRunInfo->fPacking;
int t0 = fT0s[0];
// start = the first bin which is a multiple of packing backward from first good data bin
start = fRunInfo->fDataRange[0] - (fRunInfo->fDataRange[0]/fRunInfo->fPacking)*fRunInfo->fPacking;
// end = last bin starting from start which is a multipl of packing and still within the data
end = start + ((runData->fDataBin[histoNo].size()-start-1)/fRunInfo->fPacking)*fRunInfo->fPacking;
// check if start, end, and t0 make any sense
// 1st check if start and end are in proper order
if (end < start) { // need to swap them
@ -775,11 +852,6 @@ bool PRunSingleHisto::PrepareViewData()
cout << endl << "PRunSingleHisto::PrepareViewData(): **ERROR** end data bin doesn't make any sense!";
return false;
}
// 4th check if t0 is within proper bounds
if ((t0 < 0) || (t0 > runData->fDataBin[histoNo].size())) {
cout << endl << "PRunSingleHisto::PrepareViewData(): **ERROR** t0 data bin doesn't make any sense!";
return false;
}
// everything looks fine, hence fill data set
@ -831,7 +903,7 @@ bool PRunSingleHisto::PrepareViewData()
// data start at data_start-t0
// time shifted so that packing is included correctly, i.e. t0 == t0 after packing
fData.fDataTimeStart = fTimeResolution*((double)start-t0+(double)fRunInfo->fPacking/2.0);
fData.fDataTimeStart = fTimeResolution*((double)start-(double)t0+(double)(fRunInfo->fPacking-1)/2.0);
fData.fDataTimeStep = fTimeResolution*fRunInfo->fPacking;
/*
cout << endl << ">> start time = " << fData.fDataTimeStart << ", step = " << fData.fDataTimeStep;
@ -873,13 +945,12 @@ cout << endl << "--------------------------------";
// calculate theory
unsigned int size = runData->fDataBin[histoNo].size();
double startTime = -fT0s[0]*fTimeResolution;
double theoryValue;
fData.fTheoryTimeStart = startTime;
fData.fTheoryTimeStart = fData.fDataTimeStart;
fData.fTheoryTimeStep = fTimeResolution;
//cout << endl << ">> size=" << size << ", startTime=" << startTime << ", fTimeResolution=" << fTimeResolution;
for (unsigned int i=0; i<size; i++) {
time = startTime + (double)i*fTimeResolution;
time = fData.fTheoryTimeStart + (double)i*fTimeResolution;
theoryValue = fTheory->Func(time, par, fFuncValues);
if (theoryValue > 10.0) { // dirty hack needs to be fixed!!
theoryValue = 0.0;
@ -904,11 +975,11 @@ bool PRunSingleHisto::EstimateBkg(unsigned int histoNo)
double beamPeriod = 0.0;
// check if data are from PSI, RAL, or TRIUMF
if (fRunInfo->fInstitute.Contains("psi"))
if (fRunInfo->fInstitute[0].Contains("psi"))
beamPeriod = ACCEL_PERIOD_PSI;
else if (fRunInfo->fInstitute.Contains("ral"))
else if (fRunInfo->fInstitute[0].Contains("ral"))
beamPeriod = ACCEL_PERIOD_RAL;
else if (fRunInfo->fInstitute.Contains("triumf"))
else if (fRunInfo->fInstitute[0].Contains("triumf"))
beamPeriod = ACCEL_PERIOD_TRIUMF;
else
beamPeriod = 0.0;
@ -934,7 +1005,7 @@ bool PRunSingleHisto::EstimateBkg(unsigned int histoNo)
}
// get the proper run
PRawRunData* runData = fRawData->GetRunData(fRunInfo->fRunName);
PRawRunData* runData = fRawData->GetRunData(fRunInfo->fRunName[0]);
// check if start is within histogram bounds
if ((start < 0) || (start >= runData->fDataBin[histoNo].size())) {
@ -963,7 +1034,7 @@ bool PRunSingleHisto::EstimateBkg(unsigned int histoNo)
fBackground = bkg / (fTimeResolution * 1e3); // keep background (per 1 nsec) for chisq, max.log.likelihood, fTimeResolution us->ns
cout << endl << ">> fRunInfo->fRunName=" << fRunInfo->fRunName.Data() << ", histNo=" << histoNo << ", fBackground=" << fBackground;
cout << endl << ">> fRunInfo->fRunName=" << fRunInfo->fRunName[0].Data() << ", histNo=" << histoNo << ", fBackground=" << fBackground;
return true;
}

View File

@ -186,7 +186,7 @@ typedef struct {
double fTemp; ///< temperature during the run
double fEnergy; ///< implantation energy of the muon
double fTimeResolution; ///< time resolution of the run
PDoubleVector fT0s; ///< vector of t0's of a run
PIntVector fT0s; ///< vector of t0's of a run
vector<PDoubleVector> fDataBin; ///< vector of all histos of a run
PNonMusrRawRunData fDataNonMusr; ///< keeps all ascii- or db-file info in case of nonMusr fit
} PRawRunData;
@ -242,36 +242,36 @@ typedef vector<PMsrParamStructure> PMsrParamList;
*
*/
typedef struct {
TString fRunName; ///< name of the run file
TString fBeamline; ///< e.g. mue4, mue1, pim3, emu, m15, ... (former: run type)
TString fInstitute; ///< e.g. psi, ral, triumf (former: run format)
TString fFileFormat; ///< e.g. root, nexus, psi-bin, mud, ascii, db
int fFitType; ///< fit type: 0=single histo fit, 2=asymmetry fit, 4=asymmetry in RRF, 8=non muSR
int fAlphaParamNo; ///< alpha
int fBetaParamNo; ///<
int fNormParamNo; ///<
int fBkgFitParamNo; ///<
int fPhaseParamNo; ///<
int fLifetimeParamNo; ///<
bool fLifetimeCorrection; ///<
PIntVector fMap; ///<
int fForwardHistoNo; ///<
int fBackwardHistoNo; ///<
bool fBkgFixPresent[2]; ///< flag showing if a fixed background is present
double fBkgFix[2]; ///<
int fBkgRange[4]; ///<
int fDataRange[4]; ///<
int fT0[2]; ///<
double fFitRange[2]; ///<
int fPacking; ///<
double fRRFFreq; ///< rotating reference frequency
int fRRFPacking; ///< rotating reference packing
int fAlpha2ParamNo; ///<
int fBeta2ParamNo; ///<
int fRightHistoNo; ///<
int fLeftHistoNo; ///<
int fXYDataIndex[2]; ///< used to get the data indices when using db-files
TString fXYDataLabel[2]; ///< used to get the indices via labels when using db-files
PStringVector fRunName; ///< name of the run file
PStringVector fBeamline; ///< e.g. mue4, mue1, pim3, emu, m15, ... (former: run type)
PStringVector fInstitute; ///< e.g. psi, ral, triumf (former: run format)
PStringVector fFileFormat; ///< e.g. root, nexus, psi-bin, mud, ascii, db
int fFitType; ///< fit type: 0=single histo fit, 2=asymmetry fit, 4=asymmetry in RRF, 8=non muSR
int fAlphaParamNo; ///< alpha parameter number (fit type 2, 4)
int fBetaParamNo; ///< beta parameter number (fit type 2, 4)
int fNormParamNo; ///< N0 parameter number (fit type 0)
int fBkgFitParamNo; ///< background fit parameter number (fit type 0)
int fPhaseParamNo; ///< ??? NEEDED ??? NEEDS TO BE CHECKED !!!
int fLifetimeParamNo; ///< muon lifetime parameter number (fit type 0)
bool fLifetimeCorrection; ///< lifetime correction flag for viewing (fit type 0)
PIntVector fMap; ///< map vector needed to switch parameters for different runs within a single theory
int fForwardHistoNo; ///< forward histogram number (fit type 0, 2, 4)
int fBackwardHistoNo; ///< backward histogram number (fit type 2, 4)
bool fBkgFixPresent[2]; ///< flag showing if a fixed background is present (fit type 0, 2, 4).
double fBkgFix[2]; ///< fixed background in (1/ns) (fit type 0, 2, 4)
int fBkgRange[4]; ///< background bin range (fit type 0, 2, 4)
int fDataRange[4]; ///< data bin range (fit type 0, 2, 4)
PIntVector fT0; ///< t0 bins (fit type 0, 2, 4). if fit type 0 -> f0, f1, f2, ...; if fit type 2, 4 -> f0, b0, f1, b1, ...
double fFitRange[2]; ///< fit range in (us)
int fPacking; ///< packing/rebinning
double fRRFFreq; ///< rotating reference frequency (fit type 4)
int fRRFPacking; ///< rotating reference packing (fit type 4)
int fAlpha2ParamNo; ///< rotating reference alpha2 (fit type 4)
int fBeta2ParamNo; ///< rotating reference beta2 (fit type 4)
int fRightHistoNo; ///< rotating reference right histogram number (fit type 4)
int fLeftHistoNo; ///< rotating reference left histogram number (fit type 4)
int fXYDataIndex[2]; ///< used to get the data indices when using db-files (fit type 8)
TString fXYDataLabel[2]; ///< used to get the indices via labels when using db-files (fit type 8)
} PMsrRunStructure;
//-------------------------------------------------------------

View File

@ -88,7 +88,7 @@ class PRunBase
PRunData fData; ///< data to be fitted, viewed, i.e. binned data
double fTimeResolution; ///< time resolution
PDoubleVector fT0s; ///< all t0's of a run! The derived classes will handle it
PIntVector fT0s; ///< all t0's of a run! The derived classes will handle it
virtual bool PrepareData() = 0; // pure virtual, i.e. needs to be implemented by the deriving class!!

View File

@ -60,8 +60,8 @@ class PRunDataHandler
PRawRunDataList fData; ///< keeping all the raw data
virtual bool ReadFile();
virtual bool FileAlreadyRead(PMsrRunStructure &runInfo);
virtual bool FileExistsCheck(PMsrRunStructure &runInfo);
virtual bool FileAlreadyRead(TString runName);
virtual bool FileExistsCheck(PMsrRunStructure &runInfo, const unsigned int idx);
virtual bool ReadRootFile(bool notPostPileup);
virtual bool ReadNexusFile();
virtual bool ReadWkmFile();

View File

@ -49,9 +49,9 @@ class PRunSingleHisto : public PRunBase
protected:
virtual bool PrepareData();
virtual bool PrepareFitData();
virtual bool PrepareRawViewData();
virtual bool PrepareViewData();
virtual bool PrepareFitData(PRawRunData* runData, const unsigned int histoNo);
virtual bool PrepareRawViewData(PRawRunData* runData, const unsigned int histoNo);
virtual bool PrepareViewData(PRawRunData* runData, const unsigned int histoNo);
private:
double fFitStartTime;

View File

@ -133,7 +133,13 @@ void musrfit_debug_info(PMsrHandler* msrHandler)
cout << endl << "******";
cout << endl << "run no " << runNo++;
cout << endl << "run (name, beamline, institute, data-file-format): ";
cout << endl << " " << runs_it->fRunName << ", " << runs_it->fBeamline << ", " << runs_it->fInstitute << ", " << runs_it->fFileFormat;
cout << endl << " " << runs_it->fRunName[0] << ", " << runs_it->fBeamline[0] << ", " << runs_it->fInstitute[0] << ", " << runs_it->fFileFormat[0];
if (runs_it->fRunName.size() > 1) {
for (unsigned int i=1; i<runs_it->fRunName.size(); i++) {
cout << endl << "runadd (name, beamline, institute, data-file-format): ";
cout << endl << " " << runs_it->fRunName[i] << ", " << runs_it->fBeamline[i] << ", " << runs_it->fInstitute[i] << ", " << runs_it->fFileFormat[i];
}
}
cout << endl << "fittype " << runs_it->fFitType;
cout << endl << "alpha " << runs_it->fAlphaParamNo;
cout << endl << "beta " << runs_it->fBetaParamNo;
@ -623,7 +629,7 @@ int main(int argc, char *argv[])
success = runListCollection->Add(i, kFit);
if (!success) {
cout << endl << "**ERROR** Couldn't handle run no " << i << " ";
cout << (*msrHandler->GetMsrRunList())[i].fRunName.Data();
cout << (*msrHandler->GetMsrRunList())[i].fRunName[0].Data();
break;
}
}

View File

@ -209,7 +209,7 @@ cout << endl;
success = runListCollection->Add(i, kView);
if (!success) {
cout << endl << "**ERROR** Couldn't handle run no " << i << " ";
cout << (*msrHandler->GetMsrRunList())[i].fRunName.Data();
cout << (*msrHandler->GetMsrRunList())[i].fRunName[0].Data();
break;
}
}