From 90ed9df1b6bac6148b87dc0ca3f8478c23c3c95d Mon Sep 17 00:00:00 2001 From: nemu Date: Mon, 7 Feb 2011 06:02:56 +0000 Subject: [PATCH] some more work, including the PSI-BIN write routines which are officially not released yet. --- ChangeLog | 1 + src/any2many.cpp | 4 +- src/classes/PMusr.cpp | 6 + src/classes/PRunDataHandler.cpp | 462 +- .../Class_MuSR_PSI/MuSR_td_PSI_bin.cpp | 4823 ++++++++++------- .../Class_MuSR_PSI/MuSR_td_PSI_bin.h | 347 +- src/include/PMusr.h | 24 + src/include/PRunDataHandler.h | 2 +- .../ASlibs/test-nonlocal.msr | 50 +- .../CheckMusrfitInstall/test-asy-MUD.msr | 26 +- .../test-histo-ROOT-NPP.msr | 24 +- 11 files changed, 3639 insertions(+), 2130 deletions(-) diff --git a/ChangeLog b/ChangeLog index 40ef4078..0f1403d1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ changes since 0.8.0 =================================== +NEW any2many: some more work, including the PSI-BIN write routines which are officially not released yet. NEW extended global mode in msr2data NEW any2many: an attempt to write the universial musr-data-file converter. Just started, needs still some work. NEW musrt0: added the possibility to show the t0 saved in the data file 's'. Furthermore added the option diff --git a/src/any2many.cpp b/src/any2many.cpp index e6a469a2..d956f9fb 100644 --- a/src/any2many.cpp +++ b/src/any2many.cpp @@ -314,6 +314,8 @@ int main(int argc, char *argv[]) if (!strcmp(argv[i], "-p")) { if (i+1 < argc) { info.outPath = argv[i+1]; + if (!info.outPath.EndsWith("/")) + info.outPath += "/"; } else { cerr << endl << ">> any2many **ERROR** found output option '-p' without any argument." << endl; show_syntax = true; @@ -396,7 +398,6 @@ int main(int argc, char *argv[]) show_syntax = true; } -/* cout << endl << "debug> info.year='" << info.year << "', info.year.length()=" << info.year.Length(); cout << endl << "debug> info.useStandardOutput=" << info.useStandardOutput; cout << endl << "debug> info.inFormat=" << info.inFormat; @@ -414,7 +415,6 @@ cout << endl << "debug> info.inFileName="; for (unsigned int i=0; i +#include #include #include #include @@ -474,10 +475,13 @@ Bool_t PRunDataHandler::ReadWriteFilesList() } system(cmd); } - if (fAny2ManyInfo->compressionTag == 1) // gzip + if (fAny2ManyInfo->compressionTag == 1) { // gzip sprintf(cmd, "gzip %s", fln.Data()); - else + fln += ".gz"; + } else { sprintf(cmd, "bzip2 -z %s", fln.Data()); + fln += ".bz2"; + } system(cmd); } @@ -919,6 +923,80 @@ Bool_t PRunDataHandler::ReadRootFile(UInt_t tag) // get setup runData.SetSetup(runHeader->GetLemSetup().GetString()); + // get start time/date + // start date + time_t idt = (time_t)runHeader->GetStartTime(); + runData.SetStartDateTime(idt); + struct tm *dt = localtime(&idt); + TString stime(""); + Int_t yy = dt->tm_year; + if (yy > 100) + yy -= 100; + if (yy < 10) + stime += "0"; + stime += yy; + stime += "-"; + stime += GetMonth(dt->tm_mon); + stime += "-"; + if (dt->tm_mday < 10) + stime += "0"; + stime += dt->tm_mday; + runData.SetStartDate(stime); + // start time + if (dt->tm_hour == 0) + stime = "00"; + else if (dt->tm_hour < 10) + stime = "0"; + else + stime = ""; + stime += dt->tm_hour; + stime += ":"; + if (dt->tm_min < 10) + stime += "0"; + stime += dt->tm_min; + stime += ":"; + if (dt->tm_sec < 10) + stime += "0"; + stime += dt->tm_sec; + runData.SetStartTime(stime); + + // get stop time/date + // stop date + idt = (time_t)runHeader->GetStopTime(); + runData.SetStopDateTime(idt); + dt = localtime(&idt); + stime = ""; + yy = dt->tm_year; + if (yy > 100) + yy -= 100; + if (yy < 10) + stime += "0"; + stime += yy; + stime += "-"; + stime += GetMonth(dt->tm_mon); + stime += "-"; + if (dt->tm_mday < 10) + stime += "0"; + stime += dt->tm_mday; + runData.SetStopDate(stime); + // stop time + if (dt->tm_hour == 0) + stime = "00"; + else if (dt->tm_hour < 10) + stime = "0"; + else + stime = ""; + stime += dt->tm_hour; + stime += ":"; + if (dt->tm_min < 10) + stime += "0"; + stime += dt->tm_min; + stime += ":"; + if (dt->tm_sec < 10) + stime += "0"; + stime += dt->tm_sec; + runData.SetStopTime(stime); + // get time resolution runData.SetTimeResolution(runHeader->GetTimeResolution()); @@ -1486,7 +1564,11 @@ Bool_t PRunDataHandler::ReadPsiBinFile() // get run number runData.SetRunNumber(psiBin.get_runNumber_int()); // get setup - runData.SetSetup(TString(psiBin.get_orient().c_str())); + runData.SetSetup(TString(psiBin.get_comment().c_str())); + // get sample + runData.SetSample(TString(psiBin.get_sample().c_str())); + // get orientation + runData.SetOrientation(TString(psiBin.get_orient().c_str())); // set LEM specific information to default value since it is not in the file and not used... runData.SetEnergy(PMUSR_UNDEFINED); runData.SetTransport(PMUSR_UNDEFINED); @@ -1523,6 +1605,22 @@ Bool_t PRunDataHandler::ReadPsiBinFile() for (UInt_t i=0; i sDateTime = psiBin.get_timeStart_vector(); + if (sDateTime.size() < 2) { + cerr << endl << ">> **WARNING** psi-bin file: couldn't obtain run start date/time" << endl; + } + runData.SetStartDate(sDateTime[0]); + runData.SetStartTime(sDateTime[1]); + sDateTime.clear(); + + sDateTime = psiBin.get_timeStop_vector(); + if (sDateTime.size() < 2) { + cerr << endl << ">> **WARNING** psi-bin file: couldn't obtain run stop date/time" << endl; + } + runData.SetStopDate(sDateTime[0]); + runData.SetStopTime(sDateTime[1]); + // fill raw data PDoubleVector histoData; Int_t *histo; @@ -1598,6 +1696,84 @@ Bool_t PRunDataHandler::ReadMudFile() runData.SetRunNumber((Int_t)val); } + // get start/stop time of the run + struct tm *dt; + TString stime(""); + Int_t yy = 0; + success = MUD_getTimeBegin( fh, &val ); + if (success) { + runData.SetStartDateTime((const time_t)val); + dt = localtime((const time_t*)&val); + yy = dt->tm_year; + if (yy > 100) + yy -= 100; + if (yy < 10) + stime += "0"; + stime += yy; + stime += "-"; + stime += GetMonth(dt->tm_mon); + stime += "-"; + if (dt->tm_mday < 10) + stime += "0"; + stime += dt->tm_mday; + runData.SetStartDate(stime); + // start time + if (dt->tm_hour == 0) + stime = "00"; + else if (dt->tm_hour < 10) + stime = "0"; + else + stime = ""; + stime += dt->tm_hour; + stime += ":"; + if (dt->tm_min < 10) + stime += "0"; + stime += dt->tm_min; + stime += ":"; + if (dt->tm_sec < 10) + stime += "0"; + stime += dt->tm_sec; + runData.SetStartTime(stime); + } + + stime = TString(""); + success = MUD_getTimeEnd( fh, &val ); + if (success) { + runData.SetStopDateTime((const time_t)val); + dt = localtime((const time_t*)&val); + stime = ""; + yy = dt->tm_year; + if (yy > 100) + yy -= 100; + if (yy < 10) + stime += "0"; + stime += yy; + stime += "-"; + stime += GetMonth(dt->tm_mon); + stime += "-"; + if (dt->tm_mday < 10) + stime += "0"; + stime += dt->tm_mday; + runData.SetStopDate(stime); + // stop time + if (dt->tm_hour == 0) + stime = "00"; + else if (dt->tm_hour < 10) + stime = "0"; + else + stime = ""; + stime += dt->tm_hour; + stime += ":"; + if (dt->tm_min < 10) + stime += "0"; + stime += dt->tm_min; + stime += ":"; + if (dt->tm_sec < 10) + stime += "0"; + stime += dt->tm_sec; + runData.SetStopTime(stime); + } + // get setup TString setup; success = MUD_getLab( fh, str, sizeof(str) ); @@ -1615,6 +1791,7 @@ Bool_t PRunDataHandler::ReadMudFile() success = MUD_getSample( fh, str, sizeof(str) ); if (success) { setup += TString(str); + runData.SetSample(str); } runData.SetSetup(setup); @@ -1783,6 +1960,7 @@ Bool_t PRunDataHandler::ReadMudFile() histoData.push_back(pData[j]); } runData.AppendDataBin(histoData); + // estimate T0 from maximum of the data Double_t maxVal = 0.0; Int_t maxBin = 0; @@ -2807,9 +2985,6 @@ Bool_t PRunDataHandler::ReadDBFile() */ Bool_t PRunDataHandler::WriteRootFile(TString fln) { - if (!fAny2ManyInfo->useStandardOutput) - cout << endl << ">> PRunDataHandler::WriteRootFile(): writing a root data file ... " << endl; - // generate output file name if needed if (!fAny2ManyInfo->useStandardOutput || (fAny2ManyInfo->compressionTag > 0)) { if (fln.Length() == 0) { @@ -2834,9 +3009,12 @@ Bool_t PRunDataHandler::WriteRootFile(TString fln) // keep the file name if compression is whished fAny2ManyInfo->outPathFileName.push_back(fln); } else { - fln = TString("__tmp.root"); + fln = fAny2ManyInfo->outPath + TString("__tmp.root"); } + if (!fAny2ManyInfo->useStandardOutput) + cout << endl << ">> PRunDataHandler::WriteRootFile(): writing a root data file (" << fln.Data() << ") ... " << endl; + // generate data file TFolder *histosFolder; TFolder *decayAnaModule; @@ -2855,8 +3033,12 @@ Bool_t PRunDataHandler::WriteRootFile(TString fln) header->SetRunTitle(fData[0].GetRunTitle()->Data()); header->SetLemSetup(fData[0].GetSetup()->Data()); header->SetRunNumber(fData[0].GetRunNumber()); - header->SetStartTime(0); - header->SetStopTime(1); + TString dt = *fData[0].GetStartDate() + "/" + *fData[0].GetStartTime(); + header->SetStartTimeString(dt.Data()); + dt = *fData[0].GetStopDate() + "/" + *fData[0].GetStopTime(); + header->SetStopTimeString(dt.Data()); + header->SetStartTime(fData[0].GetStartDateTime()); + header->SetStopTime(fData[0].GetStopDateTime()); header->SetModeratorHV(-999.9, 0.0); header->SetSampleHV(-999.9, 0.0); header->SetImpEnergy(-999.9); @@ -3020,8 +3202,6 @@ Bool_t PRunDataHandler::WriteNexusFile(TString fln) */ Bool_t PRunDataHandler::WriteWkmFile(TString fln) { - cout << endl << ">> PRunDataHandler::WriteWkmFile(): writing a wkm data file... " << endl; - // generate output file name if (fln.Length() == 0) { Int_t start = fRunPathName.Last('/'); @@ -3045,6 +3225,9 @@ Bool_t PRunDataHandler::WriteWkmFile(TString fln) // keep the file name if compression is whished fAny2ManyInfo->outPathFileName.push_back(fln); + if (!fAny2ManyInfo->useStandardOutput) + cout << endl << ">> PRunDataHandler::WriteWkmFile(): writing a wkm data file (" << fln.Data() << ") ... " << endl; + // write ascii file ofstream fout; streambuf* strm_buffer = 0; @@ -3087,7 +3270,9 @@ Bool_t PRunDataHandler::WriteWkmFile(TString fln) cout << endl << "Setup : " << fData[0].GetSetup()->Data(); cout << endl << "Groups : " << fData[0].GetNoOfHistos(); cout << endl << "Channels : " << static_cast(fData[0].GetDataBin(0)->size()/fAny2ManyInfo->rebin); + cout.precision(10); cout << endl << "Resolution : " << fData[0].GetTimeResolution()*fAny2ManyInfo->rebin; + cout.setf(ios::fixed,ios::floatfield); // floatfield set to fixed // write data if (fAny2ManyInfo->rebin == 1) { @@ -3145,24 +3330,178 @@ Bool_t PRunDataHandler::WriteWkmFile(TString fln) Bool_t PRunDataHandler::WritePsiBinFile(TString fln) { cout << endl << ">> PRunDataHandler::WritePsiBinFile(): will write a psi-bin data file. Not yet implemented ... " << endl; - return true; -} -//-------------------------------------------------------------------------- -// WritePsiMduFile -//-------------------------------------------------------------------------- -/** - *

Write the psi-mdu-file format. - * - * return: - * - true on successful writting, - * - otherwise false. - * - * \param fln file name. If empty, the routine will try to construct one - */ -Bool_t PRunDataHandler::WritePsiMduFile(TString fln) -{ - cout << endl << ">> PRunDataHandler::WritePsiMduFile(): will write a psi-mdu data file. Not yet implemented ... " << endl; + // generate output file name if needed + if (!fAny2ManyInfo->useStandardOutput || (fAny2ManyInfo->compressionTag > 0)) { + if (fln.Length() == 0) { + Int_t start = fRunPathName.Last('/'); + Int_t end = fRunPathName.Last('.'); + if (end == -1) { + cerr << endl << ">> PRunDataHandler::WritePsiBinFile(): **ERROR** couldn't generate the output file name ..." << endl; + return false; + } + // cut out the filename (get rid of the extension, and the path) + Char_t str1[1024], str2[1024]; + strncpy(str1, fRunPathName.Data(), sizeof(str1)); + for (Int_t i=0; ioutPath + str2 + ".bin"; + } else { + fln.Prepend(fAny2ManyInfo->outPath); + } + // keep the file name if compression is whished + fAny2ManyInfo->outPathFileName.push_back(fln); + } else { + fln = fAny2ManyInfo->outPath + TString("__tmp.bin"); + } + + if (!fAny2ManyInfo->useStandardOutput) + cout << endl << ">> PRunDataHandler::WritePsiBinFile(): writing a psi-bin data file (" << fln.Data() << ") ... " << endl; + + MuSR_td_PSI_bin psibin; + int status = 0; + + // fill header information + // run number + psibin.put_runNumber_int(fData[0].GetRunNumber()); + // length of histograms + psibin.put_histoLength_bin((int)(fData[0].GetDataBin(0)->size())); + // number of histograms + psibin.put_numberHisto_int((int)fData[0].GetNoOfHistos()); + // run title = sample (10 char) / temp (10 char) / field (10 char) / orientation (10 char) + char cstr[11]; + // sample + if (fData[0].GetSample()->Length() > 0) + strncpy(cstr, fData[0].GetSample()->Data(), 10); + else + strcpy(cstr, "??"); + cstr[10] = '\0'; + psibin.put_sample(cstr); + // temp + if (fData[0].GetNoOfTemperatures() > 0) + snprintf(cstr, 10, "%.1f K", fData[0].GetTemperature(0)); + else + strcpy(cstr, "?? K"); + cstr[10] = '\0'; + psibin.put_temp(cstr); + // field + if (fData[0].GetField() > 0) + snprintf(cstr, 10, "%.1f G", fData[0].GetField()); + else + strcpy(cstr, "?? G"); + cstr[10] = '\0'; + psibin.put_field(cstr); + // orientation + if (fData[0].GetOrientation()->Length() > 0) + strncpy(cstr, fData[0].GetOrientation()->Data(), 10); + else + strcpy(cstr, "??"); + cstr[10] = '\0'; + psibin.put_orient(cstr); + // setup + if (fData[0].GetSetup()->Length() > 0) + strncpy(cstr, fData[0].GetSetup()->Data(), 10); + else + strcpy(cstr, "??"); + cstr[10] = '\0'; + psibin.put_setup(cstr); + + // run start date + vector svec; + strncpy(cstr, fData[0].GetStartDate()->Data(), 9); + cstr[9] = '\0'; + svec.push_back(cstr); + // run start time + strncpy(cstr, fData[0].GetStartTime()->Data(), 8); + cstr[8] = '\0'; + svec.push_back(cstr); + psibin.put_timeStart_vector(svec); + svec.clear(); + + // run stop date + strncpy(cstr, fData[0].GetStopDate()->Data(), 9); + cstr[9] = '\0'; + svec.push_back(cstr); + // run stop time + strncpy(cstr, fData[0].GetStopTime()->Data(), 8); + cstr[8] = '\0'; + svec.push_back(cstr); + psibin.put_timeStop_vector(svec); + svec.clear(); + + // t0's + for (UInt_t i=0; i dvec; + for (UInt_t i=0; iData()); + + // write histogram labels + vector histoLabel; + histoLabel.resize(fData[0].GetNoOfHistos()); + char hl[32]; + for (UInt_t i=0; i > histo; + histo.resize(fData[0].GetNoOfHistos()); + for (UInt_t i=0; isize(); j++) + histo[i].push_back((Int_t)fData[0].GetDataBin(i)->at(j)); + } + status = psibin.put_histo_array_int(histo); + if (status != 0) { + cerr << endl << ">> PRunDataHandler::WritePsiBinFile(): " << psibin.ConsistencyStatus() << endl; + return false; + } + + if (!psibin.CheckDataConsistency()) { + cerr << endl << ">> PRunDataHandler::WritePsiBinFile(): " << psibin.ConsistencyStatus() << endl; + return false; + } + + // write data to file + status = psibin.write(fln.Data()); + + if (status != 0) { + cerr << endl << ">> PRunDataHandler::WritePsiBinFile(): " << psibin.WriteStatus() << endl; + return false; + } + return true; } @@ -3180,9 +3519,6 @@ Bool_t PRunDataHandler::WritePsiMduFile(TString fln) */ Bool_t PRunDataHandler::WriteMudFile(TString fln) { - if (!fAny2ManyInfo->useStandardOutput) - cout << endl << ">> PRunDataHandler::WriteMudFile(): writing a mud data file ... " << endl; - // generate output file name if needed if (!fAny2ManyInfo->useStandardOutput || (fAny2ManyInfo->compressionTag > 0)) { if (fln.Length() == 0) { @@ -3210,6 +3546,9 @@ Bool_t PRunDataHandler::WriteMudFile(TString fln) fln = TString("__tmp.msr"); } + if (!fAny2ManyInfo->useStandardOutput) + cout << endl << ">> PRunDataHandler::WriteMudFile(): writing a mud data file (" << fln.Data() << ") ... " << endl; + // generate the mud data file int fd = MUD_openWrite((char*)fln.Data(), MUD_FMT_TRI_TD_ID); if (fd == -1) { @@ -3224,8 +3563,8 @@ Bool_t PRunDataHandler::WriteMudFile(TString fln) MUD_setExptNumber(fd, 0); MUD_setRunNumber(fd, fData[0].GetRunNumber()); MUD_setElapsedSec(fd, 0); - MUD_setTimeBegin(fd, 0); - MUD_setTimeEnd(fd, 0); + MUD_setTimeBegin(fd, fData[0].GetStartDateTime()); + MUD_setTimeEnd(fd, fData[0].GetStopDateTime()); MUD_setTitle(fd, (char *)fData[0].GetRunTitle()->Data()); MUD_setLab(fd, dummy); MUD_setArea(fd, dummy); @@ -3359,9 +3698,6 @@ Bool_t PRunDataHandler::WriteMudFile(TString fln) */ Bool_t PRunDataHandler::WriteAsciiFile(TString fln) { - if (!fAny2ManyInfo->useStandardOutput) - cout << endl << ">> PRunDataHandler::WriteAsciiFile(): writing an ascii data file... " << endl; - // generate output file name if (fln.Length() == 0) { Int_t start = fRunPathName.Last('/'); @@ -3385,6 +3721,9 @@ Bool_t PRunDataHandler::WriteAsciiFile(TString fln) // keep the file name if compression is whished fAny2ManyInfo->outPathFileName.push_back(fln); + if (!fAny2ManyInfo->useStandardOutput) + cout << endl << ">> PRunDataHandler::WriteAsciiFile(): writing an ascii data file (" << fln.Data() << ") ... " << endl; + // write ascii file ofstream fout; streambuf* strm_buffer = 0; @@ -3426,8 +3765,11 @@ Bool_t PRunDataHandler::WriteAsciiFile(TString fln) cout << endl << "% energy : " << fData[0].GetEnergy() << " (keV)"; if (fData[0].GetTransport() != PMUSR_UNDEFINED) cout << endl << "% transport : " << fData[0].GetTransport() << " (kV)"; - if (fData[0].GetTimeResolution() != PMUSR_UNDEFINED) + if (fData[0].GetTimeResolution() != PMUSR_UNDEFINED) { + cout.precision(10); cout << endl << "% time resolution : " << fData[0].GetTimeResolution()*fAny2ManyInfo->rebin << " (ns)"; + cout.setf(ios::fixed,ios::floatfield); // floatfield set to fixed + } if (fData[0].GetT0Size() > 0) { cout << endl << "% t0 : "; for (UInt_t i=0; iSpits out the month as MMM for a given numerical month 0..11 + * + * return: + * - constructed file name from template, run number, and year + * - empty string + * + * \param template template string + */ +TString PRunDataHandler::GetMonth(Int_t month) +{ + TString mm(""); + + if (month == 0) + mm = "JAN"; + else if (month == 1) + mm = "FEB"; + else if (month == 2) + mm = "MAR"; + else if (month == 3) + mm = "APR"; + else if (month == 4) + mm = "MAY"; + else if (month == 5) + mm = "JUN"; + else if (month == 6) + mm = "JUL"; + else if (month == 7) + mm = "AUG"; + else if (month == 8) + mm = "SEP"; + else if (month == 9) + mm = "OCT"; + else if (month == 10) + mm = "NOV"; + else if (month == 11) + mm = "DEC"; + else + mm = "???"; + + return mm; +} diff --git a/src/external/MuSR_software/Class_MuSR_PSI/MuSR_td_PSI_bin.cpp b/src/external/MuSR_software/Class_MuSR_PSI/MuSR_td_PSI_bin.cpp index 66b5aaed..a2c75d72 100644 --- a/src/external/MuSR_software/Class_MuSR_PSI/MuSR_td_PSI_bin.cpp +++ b/src/external/MuSR_software/Class_MuSR_PSI/MuSR_td_PSI_bin.cpp @@ -26,14 +26,13 @@ #include -using namespace std ; +using namespace std; #include #include #include #include "MuSR_td_PSI_bin.h" - //******************************* //Implementation constructor //******************************* @@ -41,11 +40,11 @@ using namespace std ; /*! \brief Simple Constructor setting some pointers and variables */ - MuSR_td_PSI_bin::MuSR_td_PSI_bin() - { - histo = NULL; - Clear(); - } +MuSR_td_PSI_bin::MuSR_td_PSI_bin() +{ + histo = NULL; + Clear(); +} //******************************* @@ -56,11 +55,9 @@ using namespace std ; */ MuSR_td_PSI_bin::~MuSR_td_PSI_bin() - { - - Clear(); - - } + { + Clear(); + } //******************************* @@ -83,62 +80,100 @@ using namespace std ; */ int MuSR_td_PSI_bin::read(const char * fileName) - { - ifstream file_name ; + { + ifstream file_name; - Clear(); + Clear(); - filename = fileName; + filename = fileName; - file_name.open(fileName, ios_base::binary); // open file - if (file_name.fail()) - { - readstatus = "ERROR Open "+filename+" failed!"; - return 1; // ERROR open failed - } + file_name.open(fileName, ios_base::binary); // open file + if (file_name.fail()) + { + readstatus = "ERROR Open "+filename+" failed!"; + return 1; // ERROR open failed + } - char *buffer_file = new char[3] ; - if (!buffer_file) - { - readstatus = "ERROR Allocating data buffer"; - return 3; // ERROR allocating data buffer - } + char *buffer_file = new char[3]; + if (!buffer_file) + { + readstatus = "ERROR Allocating data buffer"; + return 3; // ERROR allocating data buffer + } - file_name.read(buffer_file, 2) ; // read format identifier of header - // into buffer - if (file_name.fail()) - { - file_name.close(); - delete [] buffer_file; - readstatus = "ERROR Reading "+filename+" header failed!"; - return 1; // ERROR reading header failed - } + file_name.read(buffer_file, 2); // read format identifier of header + // into buffer + if (file_name.fail()) + { + file_name.close(); + delete [] buffer_file; + readstatus = "ERROR Reading "+filename+" header failed!"; + return 1; // ERROR reading header failed + } - strncpy(format_id,buffer_file,2); - format_id[2] = '\0' ; + strncpy(format_id,buffer_file,2); + format_id[2] = '\0'; - file_name.close(); - delete [] buffer_file; + file_name.close(); + delete [] buffer_file; - // file may either be PSI binary format - if (strncmp(format_id,"1N",2) == 0) - { - return readbin(fileName); // then read it as PSI bin - } + // file may either be PSI binary format + if (strncmp(format_id,"1N",2) == 0) + { + return readbin(fileName); // then read it as PSI bin + } - // or MDU format (pTA, TDC or 32 channel TDC) - else if ((strncmp(format_id,"M3",2) == 0) ||(strncmp(format_id,"T4",2) == 0) || - (strncmp(format_id,"T5",2) == 0)) - { - return readmdu(fileName); // else read it as MDU - } - else - { - readstatus = "ERROR Unknown file format in "+filename+"!"; - return 2 ; // ERROR unsupported version - } + // or MDU format (pTA, TDC or 32 channel TDC) + else if ((strncmp(format_id,"M3",2) == 0) ||(strncmp(format_id,"T4",2) == 0) || + (strncmp(format_id,"T5",2) == 0)) + { + return readmdu(fileName); // else read it as MDU + } + else + { + readstatus = "ERROR Unknown file format in "+filename+"!"; + return 2; // ERROR unsupported version + } - } + } + + //******************************* + //Implementation write (generic write) + //******************************* + + /*! \brief Method to write a PSI-bin or an MDU file + * + * This method gives back: + * - 0 for succesful writing + * - 1 if the open file action or the writing of the header failed + * - 2 for an unsupported version of the data + * - 3 for an error when allocating data buffer + * - 4 if number of histograms per record not equals 1 + * - 5 if the number of histograms is less than 1 + * - 6 if writing data failed + * + * The parameter of the method is a const char * representing the name of the file to + * be opened. + */ + +int MuSR_td_PSI_bin::write(const char *fileName) +{ + string fln = fileName; + size_t found = fln.find_last_of("."); + if (found == fln.npos) { + return 1; // no extension found + } + string ext = fln.substr(found+1); + int status = 0; + if (ext == "bin") + status = writebin(fileName); + else if (ext == "mdu") + status = writemdu(fileName); + else + return 2; + + return status; +} //******************************* //Implementation readbin @@ -182,7 +217,9 @@ typedef long int Int32; typedef float Float32; -/* ----------------------------------------- */ +//******************************* +//Implementation readbin +//******************************* /*! \brief Method to read a PSI-bin file * @@ -199,316 +236,526 @@ typedef float Float32; * be opened. */ - int MuSR_td_PSI_bin::readbin(const char * fileName) +int MuSR_td_PSI_bin::readbin(const char * fileName) +{ + ifstream file_name; + Int16 *dum_Int16; + Int32 *dum_Int32; + Float32 *dum_Float32; + int i; + + Int16 tdc_resolution; + Int16 tdc_overflow ; + + Float32 mon_low[4]; + Float32 mon_high[4]; + Int32 mon_num_events; + char mon_dev[13]; + + Int16 num_data_records_file; + Int16 length_data_records_bins; + Int16 num_data_records_histo; + + Int32 period_save; + Int32 period_mon; + + Clear(); + + if (sizeof(Int16) != 2) { - ifstream file_name ; - Int16 *dum_Int16 ; - Int32 *dum_Int32 ; - Float32 *dum_Float32 ; - int i ; + readstatus = "ERROR Size of Int16 data type is not 2 bytes!"; + return 1; // ERROR open failed + } - Int16 tdc_resolution ; - Int16 tdc_overflow ; + if (sizeof(Int32) != 4) + { + readstatus = "ERROR Sizeof Int32 data type is not 4 bytes"; + return 1; // ERROR open failed + } - Float32 mon_low[4] ; - Float32 mon_high[4] ; - Int32 mon_num_events ; - char mon_dev[13] ; + if (sizeof(Float32) != 4) + { + readstatus = "ERROR Sizeof Float32 data type is not 4 bytes"; + return 1; // ERROR open failed + } - Int16 num_data_records_file ; - Int16 length_data_records_bins ; - Int16 num_data_records_histo ; + filename = fileName; - Int32 period_save ; - Int32 period_mon ; + file_name.open(fileName, ios_base::binary); // open PSI bin file + if (file_name.fail()) + { + readstatus = "ERROR Open "+filename+" failed!"; + return 1; // ERROR open failed + } + char *buffer_file = new char[1024]; + if (!buffer_file) + { + readstatus = "ERROR Allocating buffer to read header failed!"; + return 3; // ERROR allocating data buffer + } + + file_name.read(buffer_file, 1024); // read header into buffer + if (file_name.fail()) + { + file_name.close(); + delete [] buffer_file; + readstatus = "ERROR Reading "+filename+" header failed!"; + return 1; // ERROR reading header failed + } + // fill header data into member variables + strncpy(format_id,buffer_file,2); + format_id[2] = '\0'; + + if (strcmp(format_id,"1N") != 0) + { + file_name.close(); + delete [] buffer_file; + readstatus = "ERROR Unknown file format in "+filename+"!"; + return 2; // ERROR unsupported version + } + + dum_Int16 = (Int16 *) &buffer_file[2]; + tdc_resolution = *dum_Int16; + + dum_Int16 = (Int16 *) &buffer_file[4]; + tdc_overflow = *dum_Int16; + + dum_Int16 = (Int16 *) &buffer_file[6]; + num_run = *dum_Int16; + + dum_Int16 = (Int16 *) &buffer_file[28]; + length_histo = *dum_Int16; + + dum_Int16 = (Int16 *) &buffer_file[30]; + number_histo = *dum_Int16; + + strncpy(sample,buffer_file+138,10); + sample[10] = '\0'; + + strncpy(temp,buffer_file+148,10); + temp[10] = '\0'; + + strncpy(field,buffer_file+158,10); + field[10] = '\0'; + + strncpy(orient,buffer_file+168,10); + orient[10] = '\0'; + + strncpy(setup, buffer_file+178, 10); + setup[10] = '\0'; + + strncpy(comment,buffer_file+860,62); + comment[62] = '\0'; + + strncpy(date_start,buffer_file+218,9); + date_start[9] = '\0'; + + strncpy(date_stop,buffer_file+227,9); + date_stop[9] = '\0'; + + strncpy(time_start,buffer_file+236,8); + time_start[8] = '\0'; + + strncpy(time_stop,buffer_file+244,8); + time_stop[8] = '\0'; + + dum_Int32 = (Int32 *) &buffer_file[424]; + total_events = *dum_Int32; + + for (i=0; i<=15; i++) + { + strncpy(labels_histo[i],buffer_file+948+i*4,4); + labels_histo[i][4] = '\0'; + + dum_Int32 = (Int32 *) &buffer_file[296+i*4]; + events_per_histo[i] = *dum_Int32; + + dum_Int16 = (Int16 *) &buffer_file[458+i*2]; + integer_t0[i] = *dum_Int16; + + dum_Int16 = (Int16 *) &buffer_file[490+i*2]; + first_good[i] = *dum_Int16; + + dum_Int16 = (Int16 *) &buffer_file[522+i*2]; + last_good[i] = *dum_Int16; + } + + for (i=0; i<=15; i++) + { + dum_Float32 = (Float32 *) &buffer_file[792+i*4]; + real_t0[i] = *dum_Float32; + } + + number_scaler = 18; + + for (i=0; i<=5; i++) + { + dum_Int32 = (Int32 *) &buffer_file[670+i*4]; + scalers[i] = *dum_Int32; + + strncpy(labels_scalers[i],buffer_file+924+i*4,4); + labels_scalers[i][4] = '\0'; + } + + for (i=6; i dummy_vector ; - - histos_vector.clear(); - for (i=0; i dummy_vector; + + histos_vector.clear(); + for (i=0; i 0) && (j%MAXREC == 0)) { + fout.write(buffer, 4*MAXREC); + // reinizialize buffer + memset(buffer, 0, 4*MAXREC); + buffer_empty = true; + } + } + // check if there is still a record to be written + if (!buffer_empty) { + fout.write(buffer, 4*MAXREC); + // reinizialize buffer + memset(buffer, 0, 4*MAXREC); + } + } + + fout.close(); + + // clean up + if (buffer) { + delete [] buffer; + buffer = 0; + } + + return 0; +} + + //******************************* //Implementation readmdu //******************************* @@ -633,12 +880,12 @@ typedef struct _pTATagRec { /* - pTA settings relevant for td_musr for pTA M3 format*/ typedef struct _pTASettingsRec { Int32 mode; /* PTAMODE_NORMAL[+PTAMODE_CLOCK] or PTAMODE_ECHO */ - Int32 preps; /* pre pile up [ps] (nearest integer) ; info only */ - Int32 posps; /* post pile up [ps] ; info only */ + Int32 preps; /* pre pile up [ps] (nearest integer) ; info only */ + Int32 posps; /* post pile up [ps] ; info only */ Int32 preb; /* pre pile up [bins] */ Int32 posb; /* post pile up [bins] */ - Int32 ecsps; /* muon echo signal delay (PTAMODE_ECHO) [ps] ; info only */ - Int32 ectps; /* muon echo tolerance (PTAMODE_ECHO) [ps] ; info only */ + Int32 ecsps; /* muon echo signal delay (PTAMODE_ECHO) [ps] ; info only */ + Int32 ectps; /* muon echo tolerance (PTAMODE_ECHO) [ps] ; info only */ Int32 ecsb; /* muon echo signal delay (PTAMODE_ECHO) [bins] */ Int32 ectb; /* muon echo tolerance (PTAMODE_ECHO) [bins] */ Int32 timespan; /* pTA timespan */ @@ -651,12 +898,12 @@ typedef struct _pTASettingsRec { /* - pTA settings relevant for td_musr for TDC T4 format */ typedef struct _pTATDCSettingsRec { Int32 mode; /* PTAMODE_NORMAL[+PTAMODE_CLOCK] or PTAMODE_ECHO */ - Int32 preps; /* pre pile up [ps] (nearest integer) ; info only */ - Int32 posps; /* post pile up [ps] ; info only */ + Int32 preps; /* pre pile up [ps] (nearest integer) ; info only */ + Int32 posps; /* post pile up [ps] ; info only */ Int32 preb; /* pre pile up [bins] */ Int32 posb; /* post pile up [bins] */ - Int32 ecsps; /* muon echo signal delay (PTAMODE_ECHO) [ps] ; info only */ - Int32 ectps; /* muon echo tolerance (PTAMODE_ECHO) [ps] ; info only */ + Int32 ecsps; /* muon echo signal delay (PTAMODE_ECHO) [ps] ; info only */ + Int32 ectps; /* muon echo tolerance (PTAMODE_ECHO) [ps] ; info only */ Int32 ecsb; /* muon echo signal delay (PTAMODE_ECHO) [bins] */ Int32 ectb; /* muon echo tolerance (PTAMODE_ECHO) [bins] */ Int32 resolutioncode; /* type specific TDC resolution code 25 ps, 200ps */ @@ -669,12 +916,12 @@ typedef struct _pTATDCSettingsRec { /* - pTA settings relevant for td_musr for TDC T5 format */ typedef struct _pTATDC32SettingsRec { Int32 mode; /* PTAMODE_NORMAL[+PTAMODE_CLOCK] or PTAMODE_ECHO */ - Int32 preps; /* pre pile up [ps] (nearest integer) ; info only */ - Int32 posps; /* post pile up [ps] ; info only */ + Int32 preps; /* pre pile up [ps] (nearest integer) ; info only */ + Int32 posps; /* post pile up [ps] ; info only */ Int32 preb; /* pre pile up [bins] */ Int32 posb; /* post pile up [bins] */ - Int32 ecsps; /* muon echo signal delay (PTAMODE_ECHO) [ps] ; info only */ - Int32 ectps; /* muon echo tolerance (PTAMODE_ECHO) [ps] ; info only */ + Int32 ecsps; /* muon echo signal delay (PTAMODE_ECHO) [ps] ; info only */ + Int32 ectps; /* muon echo tolerance (PTAMODE_ECHO) [ps] ; info only */ Int32 ecsb; /* muon echo signal delay (PTAMODE_ECHO) [bins] */ Int32 ectb; /* muon echo tolerance (PTAMODE_ECHO) [bins] */ Int32 resolutioncode; /* type specific TDC resolution code 25 ps, 200ps */ @@ -758,6 +1005,10 @@ typedef struct _pTATDC32StatisticRec { /* ---------------------------------------------------------------------- */ +//******************************* +//Implementation readmdu +//******************************* + /*! \brief Method to read a MuSR MDU file * * This method gives back: @@ -772,240 +1023,240 @@ typedef struct _pTATDC32StatisticRec { * file to be opened. */ - int MuSR_td_PSI_bin::readmdu(const char * fileName) +int MuSR_td_PSI_bin::readmdu(const char * fileName) +{ + ifstream file_name; + int i, j; + + Clear(); + + if (sizeof(Int32) != 4) { - ifstream file_name ; - int i, j ; + readstatus = "ERROR Sizeof( Int32 ) data type is not 4 bytes"; + return 1; // ERROR open failed + } - Clear(); + filename = fileName; - if (sizeof(Int32) != 4) - { - readstatus = "ERROR Sizeof( Int32 ) data type is not 4 bytes"; - return 1; // ERROR open failed - } + file_name.open(fileName, ios_base::binary); // open PSI bin file + if (file_name.fail()) + { + readstatus = "ERROR Open "+filename+" failed!"; + return 1; // ERROR open failed + } - filename = fileName; + pTAFileHeaderRec gpTAfhead; + //FeFileHeaderPtr gpFehead = &gpTAfhead.Header; - file_name.open(fileName, ios_base::binary); // open PSI bin file - if (file_name.fail()) - { - readstatus = "ERROR Open "+filename+" failed!"; - return 1; // ERROR open failed - } + file_name.read((char *)&gpTAfhead, sizeof gpTAfhead); // read header into buffer + if (file_name.fail()) + { + file_name.close(); + readstatus = "ERROR Reading "+filename+" header failed!"; + return 1; // ERROR reading header failed + } + // fill header data into member variables + format_id[0] = gpTAfhead.Header.FmtId; + format_id[1] = gpTAfhead.Header.FmtVersion; + format_id[2] = '\0'; - pTAFileHeaderRec gpTAfhead; - //FeFileHeaderPtr gpFehead = &gpTAfhead.Header; + if ((strcmp(format_id,"M3") != 0) && (strcmp(format_id,"T4") != 0) && + (strcmp(format_id,"T5") != 0)) + { + file_name.close(); + readstatus = "ERROR Unknown file format in "+filename+"!"; + return 2; // ERROR unsupported version + } - file_name.read((char *)&gpTAfhead, sizeof gpTAfhead) ; // read header into buffer - if (file_name.fail()) - { - file_name.close(); - readstatus = "ERROR Reading "+filename+" header failed!"; - return 1; // ERROR reading header failed - } - // fill header data into member variables - format_id[0] = gpTAfhead.Header.FmtId; - format_id[1] = gpTAfhead.Header.FmtVersion; - format_id[2] = '\0' ; + if (sizeof(pTAFileHeaderRec) != gpTAfhead.NumBytesHeader) + { + file_name.close(); + readstatus = "ERROR Reading "+filename+" incorrect pTAFileHeaderRec size"; + return 1; // ERROR reading header failed + } - if ((strcmp(format_id,"M3") != 0) && (strcmp(format_id,"T4") != 0) && - (strcmp(format_id,"T5") != 0)) - { - file_name.close(); - readstatus = "ERROR Unknown file format in "+filename+"!"; - return 2 ; // ERROR unsupported version - } + // header size OK read header information + strncpy(sample,&gpTAfhead.Header.RunTitle[0],10); + sample[10] = '\0'; - if (sizeof(pTAFileHeaderRec) != gpTAfhead.NumBytesHeader) - { - file_name.close(); - readstatus = "ERROR Reading "+filename+" incorrect pTAFileHeaderRec size"; - return 1; // ERROR reading header failed - } + strncpy(temp, &gpTAfhead.Header.RunTitle[10],10); + temp[10] = '\0'; - // header size OK read header information - strncpy(sample,&gpTAfhead.Header.RunTitle[0],10) ; - sample[10] = '\0' ; + strncpy(field, &gpTAfhead.Header.RunTitle[20],10); + field[10] = '\0'; - strncpy(temp, &gpTAfhead.Header.RunTitle[10],10) ; - temp[10] = '\0' ; + strncpy(orient,&gpTAfhead.Header.RunTitle[30],10); + orient[10] = '\0'; - strncpy(field, &gpTAfhead.Header.RunTitle[20],10) ; - field[10] = '\0' ; + strncpy(comment,&gpTAfhead.Header.RunSubTitle[0],62); + comment[62] = '\0'; - strncpy(orient,&gpTAfhead.Header.RunTitle[30],10) ; - orient[10] = '\0' ; + strncpy(&date_start[0],&gpTAfhead.Header.StartDate[0],7); + strncpy(&date_start[7],&gpTAfhead.Header.StartDate[9],2); + date_start[9] = '\0'; - strncpy(comment,&gpTAfhead.Header.RunSubTitle[0],62) ; - comment[62] = '\0' ; + strncpy(&date_stop[0],&gpTAfhead.Header.EndDate[0],7); + strncpy(&date_stop[7],&gpTAfhead.Header.EndDate[9],2); + date_stop[9] = '\0'; - strncpy(&date_start[0],&gpTAfhead.Header.StartDate[0],7) ; - strncpy(&date_start[7],&gpTAfhead.Header.StartDate[9],2) ; - date_start[9] = '\0' ; + strncpy(time_start,&gpTAfhead.Header.StartTime[0],8); + time_start[8] = '\0'; - strncpy(&date_stop[0],&gpTAfhead.Header.EndDate[0],7) ; - strncpy(&date_stop[7],&gpTAfhead.Header.EndDate[9],2) ; - date_stop[9] = '\0' ; + strncpy(time_stop,&gpTAfhead.Header.EndTime[0],8); + time_stop[8] = '\0'; - strncpy(time_start,&gpTAfhead.Header.StartTime[0],8) ; - time_start[8] = '\0' ; + num_run = gpTAfhead.Header.RunNumber; - strncpy(time_stop,&gpTAfhead.Header.EndTime[0],8) ; - time_stop[8] = '\0' ; - - num_run = gpTAfhead.Header.RunNumber; - - if (sizeof(pTATagRec) != gpTAfhead.NumBytesTag) - { - file_name.close(); - readstatus = "ERROR Reading "+filename+" incorrect pTATagRec size"; - return 1; // ERROR reading header failed - } + if (sizeof(pTATagRec) != gpTAfhead.NumBytesTag) + { + file_name.close(); + readstatus = "ERROR Reading "+filename+" incorrect pTATagRec size"; + return 1; // ERROR reading header failed + } #ifdef MIDEBUG1 - cout << "Header.MeanTemp = " << gpTAfhead.Header.MeanTemp << endl; - cout << "Header.TempDev = " << gpTAfhead.Header.TempDev << endl; + cout << "Header.MeanTemp = " << gpTAfhead.Header.MeanTemp << endl; + cout << "Header.TempDev = " << gpTAfhead.Header.TempDev << endl; #endif - // read temperature deviation from header string (td0 [td1 [td2 [td3]]]) - number_temper = sscanf(gpTAfhead.Header.TempDev,"%f %f %f %f", - &temp_deviation[0], &temp_deviation[1], &temp_deviation[2], - &temp_deviation[3]); + // read temperature deviation from header string (td0 [td1 [td2 [td3]]]) + number_temper = sscanf(gpTAfhead.Header.TempDev,"%f %f %f %f", + &temp_deviation[0], &temp_deviation[1], &temp_deviation[2], + &temp_deviation[3]); - // fill unused - for (i=number_temper; i= 0) && (it < MAXHISTO)) { - selected[it] = true; + for (i=0,j=0; i <= (int)strlen(gpTAfhead.Header.DetectorNumberList); i++) { + if ((gpTAfhead.Header.DetectorNumberList[i] == ' ') || + (gpTAfhead.Header.DetectorNumberList[i] == '\0')) { + int it; + if (sscanf(&gpTAfhead.Header.DetectorNumberList[j],"%d",&it) == 1) { + j = i+1; // assume next char is start of next number + if ((it >= 0) && (it < MAXHISTO)) { + selected[it] = true; #ifdef MIDEBUG1 - cout << "Histogram " << it << " is selected " << endl; + cout << "Histogram " << it << " is selected " << endl; #endif - } else { - cout << "error " << it << " is out of range |0 - " << MAXHISTO-1 << "|" - < 0) length_histo -= 1; - + // resolution factor for binning + for (i=0; i < timespan+8-gpTAsetpta.timespan; i++) + resolutionfactor *= 2; } - else if (strcmp(format_id,"T4") == 0) + + length_histo = 0; + number_histo = 0; + for (i=0; i 0) length_histo -= 1; + + } + else if (strcmp(format_id,"T4") == 0) + { + + if (sizeof(pTATDCSettingsRec) != gpTAfhead.NumBytesSettings) { - - if (sizeof(pTATDC32SettingsRec) != gpTAfhead.NumBytesSettings) - { - file_name.close(); - readstatus = "ERROR Reading "+filename+" incorrect pTATDC32SettingsRec size"; - return 1; // ERROR reading header failed - } - - if (sizeof(pTATDC32StatisticRec) != gpTAfhead.NumBytesStatistics) - { - file_name.close(); - readstatus = "ERROR Reading "+filename+" incorrect pTATDC32StatisticRec size"; - return 1; // ERROR reading header failed - } - - pTATDC32SettingsRec gpTAsettdc32; - pTATDC32StatisticRec gpTAstattottdc32; - - tothist = TDCMAXTAGS32; - - // read settings into buffer - file_name.read((char *)&gpTAsettdc32, sizeof gpTAsettdc32) ; - if (file_name.fail()) - { - file_name.close(); - readstatus = "ERROR Reading "+filename+" settings failed!"; - return 1; // ERROR reading settings failed - } - - // read stat into buffer - file_name.read((char *)&gpTAstattottdc32, sizeof gpTAstattottdc32) ; - if (file_name.fail()) - { - file_name.close(); - readstatus = "ERROR Reading "+filename+" statistics failed!"; - return 1; // ERROR reading statistics failed - } - - number_scaler = TDCMAXTAGS32; - for (i=0; i < number_scaler; i++) - { - strncpy(labels_scalers[i],gpTAsettdc32.tag[i].Label,MAXLABELSIZE); - labels_scalers[i][MAXLABELSIZE-1] = '\0'; - - scalers[i] = gpTAstattottdc32.TagScaler[i]; - } - - resolutionfactor = gpTAfhead.Header.HistoResolution; - if (gpTAsettdc32.resolutioncode == 25) - bin_width = 0.0000244140625; - else if (gpTAsettdc32.resolutioncode == 100) - bin_width = 0.00009765625; - else if (gpTAsettdc32.resolutioncode == 200) - bin_width = 0.0001953125; - else if (gpTAsettdc32.resolutioncode == 800) - bin_width = 0.0007812500; - else - { - file_name.close(); - readstatus = "ERROR "+filename+" settings resolution code failed!"; - return 1; // ERROR reading settings failed - } - - length_histo = 0; - number_histo = 0; - for (i=0; i MAXHISTO) + length_histo = 0; + number_histo = 0; + for (i=0; i MAXHISTO) + { + cout << "ERROR number of histograms " << tothist << " exceedes maximum " + << MAXHISTO << "! - Setting maximum number " << endl; + tothist = MAXHISTO; + } + #ifdef MIDEBUG1 cout << "Number of histograms is " << number_histo << endl; cout << "Histogram length is " << length_histo << endl; cout << "Resolutionfactor for t0, fg, lg is " << resolutionfactor << endl; #endif - default_binning = resolutionfactor; + default_binning = resolutionfactor; - // allocate histograms - histo = new int* [int(number_histo)]; - if (!histo) + // allocate histograms + histo = new int* [int(number_histo)]; + if (!histo) + { + Clear(); + file_name.close(); + readstatus = "ERROR Allocating histo failed!"; + return 3; // ERROR allocating histogram buffer + } + + for (i=0; i dummy_vector; + + histos_vector.clear(); + for (i=0,ihist=0; i< tothist; i++) + { + file_name.read((char *)&tag, sizeof tag); // read tag into buffer + if (file_name.fail()) { - histo[i] = new int [length_histo]; - - if (!histo[i]) - { - for (j=0; j dummy_vector ; - - histos_vector.clear(); - for (i=0,ihist=0; i< tothist; i++) + /* read histogram data */ + if (tag.Type == PTATAGC_POSITRON) { - file_name.read((char *)&tag, sizeof tag) ; // read tag into buffer - if (file_name.fail()) - { - dummy_vector.clear() ; - Clear(); - if (thist != NULL) delete [] thist; thist = NULL; - file_name.close(); - readstatus = "ERROR Reading "+filename+" tag failed!"; - return 6; // ERROR reading tag failed - } - /* read histogram data */ - if (tag.Type == PTATAGC_POSITRON) - { - int nbins; + int nbins; #ifdef MIDEBUG1 - cout << "Tag[" << i << "] " << tag.Label << " : Histomin = " << tag.Histominb - << " Histomax = " << tag.Histomaxb << endl; + cout << "Tag[" << i << "] " << tag.Label << " : Histomin = " << tag.Histominb + << " Histomax = " << tag.Histomaxb << endl; #endif - // is a histogram there? - if ((nbins=(tag.Histomaxb-tag.Histominb + 1))>1) - { - if (thist == NULL) thist = new Int32[nbins]; - if (thist == NULL) - { - Clear(); - file_name.close(); - readstatus = "ERROR Allocating histogram buffer failed!"; - return 3; // ERROR allocating histogram buffer - } - - file_name.read((char *)thist, sizeof(Int32)*nbins) ;// read hist into buffer - if (file_name.fail()) - { - Clear(); - if (thist != NULL) delete [] thist; thist = NULL; - file_name.close(); - readstatus = "ERROR Reading "+filename+" hist failed!"; - return 6; // ERROR reading hist failed - } - - // for pTA only: use histogram only, if histogram was selected - // else take all histos but mark not selected - if (selected[i] || (strcmp(format_id,"M3") != 0)) - { - - if (ihist < MAXHISTO) // max number of histos not yet reached? - { - dummy_vector.clear() ; - - strncpy(labels_histo[ihist],tag.Label,MAXLABELSIZE) ; - labels_histo[ihist][MAXLABELSIZE-1] = '\0' ; - - // mark with ** when not selected - if (!selected[i] && (strlen(labels_histo[ihist])= first_good[ihist]) && (j <= last_good[ihist])) - events_per_histo[ihist] += *(thist+j-tag.Histominb); - } - histos_vector.push_back(dummy_vector) ; - - // only add selected histo(s) to total events - if (selected[i]) - total_events += events_per_histo[ihist]; - } - ihist++; - } - } + // is a histogram there? + if ((nbins=(tag.Histomaxb-tag.Histominb + 1))>1) + { + if (thist == NULL) thist = new Int32[nbins]; + if (thist == NULL) + { + Clear(); + file_name.close(); + readstatus = "ERROR Allocating histogram buffer failed!"; + return 3; // ERROR allocating histogram buffer } + + file_name.read((char *)thist, sizeof(Int32)*nbins);// read hist into buffer + if (file_name.fail()) + { + Clear(); + if (thist != NULL) delete [] thist; thist = NULL; + file_name.close(); + readstatus = "ERROR Reading "+filename+" hist failed!"; + return 6; // ERROR reading hist failed + } + + // for pTA only: use histogram only, if histogram was selected + // else take all histos but mark not selected + if (selected[i] || (strcmp(format_id,"M3") != 0)) + { + + if (ihist < MAXHISTO) // max number of histos not yet reached? + { + dummy_vector.clear(); + + strncpy(labels_histo[ihist],tag.Label,MAXLABELSIZE); + labels_histo[ihist][MAXLABELSIZE-1] = '\0'; + + // mark with ** when not selected + if (!selected[i] && (strlen(labels_histo[ihist])= first_good[ihist]) && (j <= last_good[ihist])) + events_per_histo[ihist] += *(thist+j-tag.Histominb); + } + histos_vector.push_back(dummy_vector); + + // only add selected histo(s) to total events + if (selected[i]) + total_events += events_per_histo[ihist]; + } + ihist++; + } + } } - - if (thist != NULL) delete [] thist; thist = NULL; - - file_name.close(); - - readstatus = "SUCCESS"; - readingok = true; - - return 0; } + if (thist != NULL) delete [] thist; thist = NULL; + + file_name.close(); + + readstatus = "SUCCESS"; + readingok = true; + + return 0; +} + +//******************************* +//Implementation writemdu +//******************************* + + /*! \brief Method to write a MuSR MDU file + * + * This method gives back: + * - 0 for succesful writing + * - 1 if the open file action or the writing of the header failed + * - 2 for an unsupported version of the data + * - 3 for an error when allocating data buffer + * - 5 if the number of histograms is less than 1 + * - 6 if writing data failed + * + * The parameter of the method is a const char * representing the name of the + * file to be opened. + */ + +int MuSR_td_PSI_bin::writemdu(const char * fileName) +{ + cerr << endl << "MuSR_td_PSI_bin::writemdu - not yet implemented" << endl; + return 0; +} + + //******************************* //Implementation readingOK //******************************* @@ -1437,10 +1713,98 @@ typedef struct _pTATDC32StatisticRec { * - true if reading was OK * - false if reading was NOT OK */ -bool MuSR_td_PSI_bin::readingOK() const { +bool MuSR_td_PSI_bin::readingOK() const +{ return readingok; } +//******************************* +//Implementation writingOK +//******************************* + +/*! \brief Method to obtain if writing and processing of the data file was OK. + * + * This method gives back: + * - true if writing was OK + * - false if writing was NOT OK + */ +bool MuSR_td_PSI_bin::writingOK() const +{ + return writingok; +} + +//******************************* +//Implementation CheckDataConsistency +//******************************* + +/*! \brief Check if a given set of data is consistent with the PSI-BIN limitations. + * If false, the error message can be obtained via ConsistencyStatus(). + * Comment to the tag: the following restriction apply (in parenthesize the level of checking) + * - total number of bins is restricted to 65536 (true for reasonable, and strict) + * - 32767 is the maximum number of bins being stored in an integer*2 (true for reasonable, and strict) + * - the number of bins must be a multiple of 256 (false for reasonable, true for strict) + * - all histograms must have the same number of bins (true for reasonable, and strict) + * + * return: + * - true if everything is within the PSI-BIN limitations + * - false otherwise + * + * \param tag tag provided to tell how strict the tests should be. 0=reasonable, 1=strict + */ + +bool MuSR_td_PSI_bin::CheckDataConsistency(int tag) +{ + if (number_histo <= 0) { + consistencyOk = false; + consistencyStatus = "**ERROR** number histograms is zero or less!"; + return consistencyOk; + } + + if (number_histo > MAXHISTO) { + consistencyOk = false; + consistencyStatus = "**ERROR** number of histograms requested: "; + consistencyStatus += number_histo; + consistencyStatus += ", which is larger than the possible maximum of 32."; + return consistencyOk; + } + + if (length_histo <= 0) { + consistencyOk = false; + consistencyStatus = "**ERROR** histogram length is zero or less!"; + return consistencyOk; + } + + if (length_histo > 32767) { + consistencyOk = false; + consistencyStatus = "**ERROR** histogram length is too large (maximum being 32767)!"; + return consistencyOk; + } + + if ((length_histo % 256 != 0) && (tag == 1)) { + consistencyOk = false; + consistencyStatus = "**ERROR** histogram length is not a multiple of 256!"; + return consistencyOk; + } + + if (number_histo * length_histo > 65536) { + consistencyOk = false; + consistencyStatus = "**ERROR** number_histo * length_histo > 65536!"; + return consistencyOk; + } + + if (histo == 0) { + consistencyOk = false; + consistencyStatus = "**ERROR** no histograms present!"; + return consistencyOk; + } + + consistencyOk = true; + consistencyStatus = "SUCCESS"; + + return consistencyOk; +} + + //******************************* //Implementation ReadStatus //******************************* @@ -1451,10 +1815,41 @@ bool MuSR_td_PSI_bin::readingOK() const { * - "SUCCESS" if reading was OK * - "ERROR " if reading was NOT OK */ -string MuSR_td_PSI_bin::ReadStatus() const { +string MuSR_td_PSI_bin::ReadStatus() const +{ return readstatus; } +//******************************* +//Implementation WriteStatus +//******************************* + +/*! \brief Method to obtain error/success information after writing. + * + * This method gives back: + * - "SUCCESS" if writing was OK + * - "ERROR " if writing was NOT OK + */ +string MuSR_td_PSI_bin::WriteStatus() const +{ + return writestatus; +} + +//******************************* +//Implementation ConsistencyStatus +//******************************* + +/*! \brief Method to obtain error/success information on data consistency check. + * + * This method gives back: + * - "SUCCESS" if data are consistent OK + * - "ERROR " otherwise + */ +string MuSR_td_PSI_bin::ConsistencyStatus() const +{ + return consistencyStatus; +} + //******************************* //Implementation Filename //******************************* @@ -1464,10 +1859,12 @@ string MuSR_td_PSI_bin::ReadStatus() const { * This method gives back: * - */ -string MuSR_td_PSI_bin::Filename() const { +string MuSR_td_PSI_bin::Filename() const +{ return filename; } + //******************************* //Implementation get_histo_int //******************************* @@ -1478,12 +1875,13 @@ string MuSR_td_PSI_bin::Filename() const { * - bin value as int * - 0 if an invalid histogram number or bin is choosen */ -int MuSR_td_PSI_bin::get_histo_int(int histo_num, int j) { +int MuSR_td_PSI_bin::get_histo_int(int histo_num, int j) +{ if (!readingok) return 0; if (( histo_num < 0) || (histo_num >= int(number_histo)) || (j < 0 ) || (j >= length_histo)) - return 0 ; + return 0; #ifdef MIDEBUG cout << "histos_vector[0][0] = " << histos_vector[0][0] << endl; #endif @@ -1500,12 +1898,13 @@ int MuSR_td_PSI_bin::get_histo_int(int histo_num, int j) { * - bin value as double * - 0 if an invalid histogram number or bin is choosen */ -double MuSR_td_PSI_bin::get_histo(int histo_num, int j) { +double MuSR_td_PSI_bin::get_histo(int histo_num, int j) +{ if (!readingok) return 0.; if (( histo_num < 0) || (histo_num >= int(number_histo)) || (j < 0 ) || (j >= length_histo)) - return 0. ; + return 0.; #ifdef MIDEBUG cout << "histos_vector[0][0] = " << histos_vector[0][0] << endl; #endif @@ -1528,27 +1927,196 @@ double MuSR_td_PSI_bin::get_histo(int histo_num, int j) { representing the desired histogram number and binning. */ - double * MuSR_td_PSI_bin::get_histo_array(int histo_num , int binning) +double * MuSR_td_PSI_bin::get_histo_array(int histo_num, int binning) +{ + if (!readingok) return NULL; + + if ( histo_num < 0 || histo_num >= int(number_histo) || binning <= 0 ) + return NULL; + + double *histo_array = new double[int(int(length_histo)/binning)]; + + if (!histo_array) return NULL; + + for (int i = 0; i < int(int(length_histo)/binning); i++) { - if (!readingok) return NULL; - - if ( histo_num < 0 || histo_num >= int(number_histo) || binning <= 0 ) - return NULL ; - - double *histo_array = new double[int(int(length_histo)/binning)] ; - - if (!histo_array) return NULL; - - for (int i = 0 ; i < int(int(length_histo)/binning) ; i++) - { - histo_array[i] = 0 ; - for (int j = 0 ; j < binning ; j++) - histo_array[i] += double(histo[histo_num][i*binning+j]) ; - } - - return histo_array ; + histo_array[i] = 0; + for (int j = 0; j < binning; j++) + histo_array[i] += double(histo[histo_num][i*binning+j]); } + return histo_array; +} + + //******************************* + //Implementation put_histo_array_int + //******************************* + + /*! \brief Method to set the histograms which is a vector of vector of int's (histogram). + * There are two different ways to get the data conform to PSI-BIN limitations: + * -# rebin and zero pad the given data. In this case also a couple of other parameters + * need to be adopted: T0, first good bin, last good bin, and the time resolution. The + * values for these properties needed to be set *before* calling this routine! + * -# truncate the data. In this it is only checked that T0, first good bin, and last good bin + * are staying within proper boundaries. + * + * This method gives back: + * - 0 on success + * - -1 if number of histograms is out of range + * - -2 if not all the histograms given have the same length + * - -3 if unsupported tag is found + * - -4 failed to allocate memory for the histos + * + * \param histoData vector of the histograms + * \param tag 0: rebin and zero pad at need, 1: truncate at need + */ + + int MuSR_td_PSI_bin::put_histo_array_int(vector< vector > histoData, int tag) + { + // check that the number of histograms are within allowed boundaries + if ((histoData.size() == 0) || (histoData.size() > 32)) { + consistencyOk = false; + consistencyStatus = "**ERROR** number of histograms out of range! Must be > 0 and < 32."; + return -1; + } + + // check that all the given histograms have the same length + unsigned int size = histoData[0].size(); + bool ok = true; + for (unsigned int i=1; i 32512) + lengthHisto = 32512; + + // calculate the needed data length + int dataLength = ((int)histoData[0].size()); + int rebin = (int)histoData[0].size() / lengthHisto; + if (tag == 0) { + // calculate what rebinning is needed + if ((int)histoData[0].size() % lengthHisto != 0) + rebin++; + if ((((int)histoData[0].size()/rebin) % 256) == 0) + dataLength = (int)histoData[0].size()/rebin; + else + dataLength = (((int)histoData[0].size()/rebin/256)+1)*256; + } else if (tag == 1) { + if (((int)histoData[0].size() % 256) != 0) + dataLength = (((int)histoData[0].size()/256)+1)*256; + } + + // overwrite length_histo + length_histo = dataLength; + + // clean up if needed + if (histo) { + for (int i=0; i > data; + data.resize(number_histo); + + int val = 0; + for (int i=0; i0) && (j%rebin == 0)) { + data[i].push_back(val); + val = 0; + } + val += histoData[i][j]; + } + } + + // fill the histograms + for (int i=0; i length_histo) + integer_t0[i] = 0; + real_t0[i] = bin_width*integer_t0[i]; + if (first_good[i] > length_histo) + first_good[i] = 0; + if (last_good[i] > length_histo) + last_good[i] = length_histo-1; + } + } else { + consistencyOk = false; + consistencyStatus = "**ERROR** found unsupported tag!"; + return -3; + } + + return 0; + } //******************************* //Implementation get_histo_vector @@ -1565,27 +2133,26 @@ double MuSR_td_PSI_bin::get_histo(int histo_num, int j) { representing the desired histogram number and binning. */ - vector MuSR_td_PSI_bin::get_histo_vector(int histo_num , int binning) - { - vector histo_vector ; //(int(length_histo/binning)) + vector MuSR_td_PSI_bin::get_histo_vector(int histo_num, int binning) + { + vector histo_vector; //(int(length_histo/binning)) - if (!readingok) return histo_vector; + if (!readingok) return histo_vector; - if ( histo_num < 0 || histo_num >= int(number_histo) || binning <= 0 ) - return histo_vector ; + if ( histo_num < 0 || histo_num >= int(number_histo) || binning <= 0 ) + return histo_vector; - for (int i = 0 ; i < int(length_histo/binning) ; i++) - histo_vector.push_back(0.) ; + for (int i = 0; i < int(length_histo/binning); i++) + histo_vector.push_back(0.); - for (int i = 0 ; i < int(length_histo/binning) ; i++) - { - for (int j = 0 ; j < binning ; j++) - histo_vector[i] += double(histo[histo_num][i*binning+j]) ; - } - - return histo_vector ; - } + for (int i = 0; i < int(length_histo/binning); i++) + { + for (int j = 0; j < binning; j++) + histo_vector[i] += double(histo[histo_num][i*binning+j]); + } + return histo_vector; + } //******************************* //Implementation get_histo_vector_no0 @@ -1603,31 +2170,31 @@ double MuSR_td_PSI_bin::get_histo(int histo_num, int j) { * representing the desired histogram number and binning. */ - vector MuSR_td_PSI_bin::get_histo_vector_no0(int histo_num , int binning) - { - vector histo_vector; //(int(length_histo/binning)) ; + vector MuSR_td_PSI_bin::get_histo_vector_no0(int histo_num, int binning) + { + vector histo_vector; //(int(length_histo/binning)); - if (!readingok) return histo_vector; + if (!readingok) return histo_vector; - if ( histo_num < 0 || histo_num >= int(number_histo) || binning <= 0 ) - return histo_vector ; + if ( histo_num < 0 || histo_num >= int(number_histo) || binning <= 0 ) + return histo_vector; - for (int i = 0 ; i < int(length_histo/binning) ; i++) - histo_vector.push_back(0.) ; + for (int i = 0; i < int(length_histo/binning); i++) + histo_vector.push_back(0.); - for (int i = 0 ; i < int(length_histo/binning) ; i++) - { - for (int j = 0 ; j < binning ; j++) - histo_vector[i] += double(histo[histo_num][i*binning+j]) ; + for (int i = 0; i < int(length_histo/binning); i++) + { + for (int j = 0; j < binning; j++) + histo_vector[i] += double(histo[histo_num][i*binning+j]); - if (histo_vector[i] < 0.5 ) - { - histo_vector[i] = 0.1 ; - } - } + if (histo_vector[i] < 0.5 ) + { + histo_vector[i] = 0.1; + } + } - return histo_vector ; - } + return histo_vector; + } //********************************** @@ -1645,24 +2212,24 @@ double MuSR_td_PSI_bin::get_histo(int histo_num, int j) { * histogram number. */ - int * MuSR_td_PSI_bin::get_histo_array_int(int histo_num) - { - if (!readingok) return NULL; + int * MuSR_td_PSI_bin::get_histo_array_int(int histo_num) + { + if (!readingok) return NULL; - if ( histo_num < 0 || histo_num >= int(number_histo)) - return NULL ; + if ( histo_num < 0 || histo_num >= int(number_histo)) + return NULL; - int *histo_array = new int[length_histo] ; + int *histo_array = new int[length_histo]; - if (!histo_array) return NULL; + if (!histo_array) return NULL; - for (int i = 0 ; i < int(length_histo) ; i++) - { - histo_array[i] = int(histo[histo_num][i]) ; - } + for (int i = 0; i < int(length_histo); i++) + { + histo_array[i] = int(histo[histo_num][i]); + } - return histo_array ; - } + return histo_array; + } //******************************* @@ -1682,28 +2249,28 @@ double MuSR_td_PSI_bin::get_histo(int histo_num, int j) { * representing the desired histogram number and binning. */ - double * MuSR_td_PSI_bin::get_histo_fromt0_array(int histo_num , int binning , int offset) - { - if (!readingok) return NULL; + double * MuSR_td_PSI_bin::get_histo_fromt0_array(int histo_num, int binning, int offset) + { + if (!readingok) return NULL; - if ( histo_num < 0 || histo_num >= int(number_histo) || binning <= 0 ) - return NULL ; + if ( histo_num < 0 || histo_num >= int(number_histo) || binning <= 0 ) + return NULL; - double *histo_fromt0_array = - new double[int((int(length_histo)-get_t0_int(histo_num)-offset+1)/binning)] ; + double *histo_fromt0_array = + new double[int((int(length_histo)-get_t0_int(histo_num)-offset+1)/binning)]; - if (!histo_fromt0_array) return NULL; + if (!histo_fromt0_array) return NULL; - for (int i = 0 ; i < int((int(length_histo)-get_t0_int(histo_num)-offset)/binning) ; i++) - { - histo_fromt0_array[i] = 0 ; - for (int j = 0 ; j < binning ; j++) - histo_fromt0_array[i] += - double(histo[histo_num][i*binning+j+get_t0_int(histo_num)+offset]) ; - } + for (int i = 0; i < int((int(length_histo)-get_t0_int(histo_num)-offset)/binning); i++) + { + histo_fromt0_array[i] = 0; + for (int j = 0; j < binning; j++) + histo_fromt0_array[i] += + double(histo[histo_num][i*binning+j+get_t0_int(histo_num)+offset]); + } - return histo_fromt0_array ; - } + return histo_fromt0_array; + } //******************************* @@ -1722,27 +2289,27 @@ double MuSR_td_PSI_bin::get_histo(int histo_num, int j) { * representing the desired histogram number and binning. */ - vector MuSR_td_PSI_bin::get_histo_fromt0_vector(int histo_num , int binning , int offset) - { - vector histo_fromt0_vector ; // (int((int(length_histo)-get_t0_int(histo_num)+1)/binning)) ; + vector MuSR_td_PSI_bin::get_histo_fromt0_vector(int histo_num, int binning, int offset) + { + vector histo_fromt0_vector; // (int((int(length_histo)-get_t0_int(histo_num)+1)/binning)); - if (!readingok) return histo_fromt0_vector; + if (!readingok) return histo_fromt0_vector; - if ( histo_num < 0 || histo_num >= int(number_histo) || binning <= 0 ) - return histo_fromt0_vector ; + if ( histo_num < 0 || histo_num >= int(number_histo) || binning <= 0 ) + return histo_fromt0_vector; - for (int i = 0 ; i < int((int(length_histo)-get_t0_int(histo_num)-offset)/binning) ; i++) - histo_fromt0_vector.push_back(0.) ; + for (int i = 0; i < int((int(length_histo)-get_t0_int(histo_num)-offset)/binning); i++) + histo_fromt0_vector.push_back(0.); - for (int i = 0 ; i < int((int(length_histo)-get_t0_int(histo_num)-offset)/binning) ; i++) - { - for (int j = 0 ; j < binning ; j++) - histo_fromt0_vector[i] += - double(histo[histo_num][i*binning+j+get_t0_int(histo_num)+offset]) ; - } + for (int i = 0; i < int((int(length_histo)-get_t0_int(histo_num)-offset)/binning); i++) + { + for (int j = 0; j < binning; j++) + histo_fromt0_vector[i] += + double(histo[histo_num][i*binning+j+get_t0_int(histo_num)+offset]); + } - return histo_fromt0_vector ; - } + return histo_fromt0_vector; + } //******************************* @@ -1761,27 +2328,27 @@ double MuSR_td_PSI_bin::get_histo(int histo_num, int j) { * representing the desired histogram number and binning. */ - double * MuSR_td_PSI_bin::get_histo_goodBins_array(int histo_num , int binning) - { - if (!readingok) return NULL; - if ( histo_num < 0 || histo_num >= int(number_histo) || binning <= 0 ) - return NULL ; + double * MuSR_td_PSI_bin::get_histo_goodBins_array(int histo_num, int binning) + { + if (!readingok) return NULL; + if ( histo_num < 0 || histo_num >= int(number_histo) || binning <= 0 ) + return NULL; - double *histo_goodBins_array = - new double[int((get_lastGood_int(histo_num)-get_firstGood_int(histo_num)+1)/binning)] ; + double *histo_goodBins_array = + new double[int((get_lastGood_int(histo_num)-get_firstGood_int(histo_num)+1)/binning)]; - if (!histo_goodBins_array) return NULL; + if (!histo_goodBins_array) return NULL; - for (int i = 0 ; i < int((get_lastGood_int(histo_num)-get_firstGood_int(histo_num))/binning) ; i++) - { - histo_goodBins_array[i] = 0 ; - for (int j = 0 ; j < binning ; j++) - histo_goodBins_array[i] += - double(histo[histo_num][i*binning+j+get_firstGood_int(histo_num)]) ; - } + for (int i = 0; i < int((get_lastGood_int(histo_num)-get_firstGood_int(histo_num))/binning); i++) + { + histo_goodBins_array[i] = 0; + for (int j = 0; j < binning; j++) + histo_goodBins_array[i] += + double(histo[histo_num][i*binning+j+get_firstGood_int(histo_num)]); + } - return histo_goodBins_array ; - } + return histo_goodBins_array; + } //******************************* @@ -1800,27 +2367,27 @@ double MuSR_td_PSI_bin::get_histo(int histo_num, int j) { * representing the desired histogram number and binning. */ - vector MuSR_td_PSI_bin::get_histo_goodBins_vector(int histo_num , int binning) - { - vector histo_goodBins_vector ; + vector MuSR_td_PSI_bin::get_histo_goodBins_vector(int histo_num, int binning) + { + vector histo_goodBins_vector; - if (!readingok) return histo_goodBins_vector; + if (!readingok) return histo_goodBins_vector; - if ( histo_num < 0 || histo_num >= int(number_histo) || binning <= 0 ) - return histo_goodBins_vector ; + if ( histo_num < 0 || histo_num >= int(number_histo) || binning <= 0 ) + return histo_goodBins_vector; - for (int i = 0 ; i < int((get_lastGood_int(histo_num)-get_firstGood_int(histo_num))/binning) ; i++) - histo_goodBins_vector.push_back(0.) ; + for (int i = 0; i < int((get_lastGood_int(histo_num)-get_firstGood_int(histo_num))/binning); i++) + histo_goodBins_vector.push_back(0.); - for (int i = 0 ; i < int((get_lastGood_int(histo_num)-get_firstGood_int(histo_num))/binning) ; i++) - { - for (int j = 0 ; j < binning ; j++) - histo_goodBins_vector[i] += - double(histo[histo_num][i*binning+j+get_firstGood_int(histo_num)]) ; - } + for (int i = 0; i < int((get_lastGood_int(histo_num)-get_firstGood_int(histo_num))/binning); i++) + { + for (int j = 0; j < binning; j++) + histo_goodBins_vector[i] += + double(histo[histo_num][i*binning+j+get_firstGood_int(histo_num)]); + } - return histo_goodBins_vector ; - } + return histo_goodBins_vector; + } //******************************* @@ -1846,40 +2413,40 @@ double MuSR_td_PSI_bin::get_histo(int histo_num, int j) { * between which the background is calculated. */ -double * MuSR_td_PSI_bin::get_histo_fromt0_minus_bckgrd_array(int histo_num , - int lower_bckgrd , int higher_bckgrd , int binning, int offset) - { - if (!readingok) return NULL; + double * MuSR_td_PSI_bin::get_histo_fromt0_minus_bckgrd_array(int histo_num, + int lower_bckgrd, int higher_bckgrd, int binning, int offset) + { + if (!readingok) return NULL; - if ( histo_num < 0 || histo_num >= int(number_histo) || binning <= 0 ) - return NULL ; + if ( histo_num < 0 || histo_num >= int(number_histo) || binning <= 0 ) + return NULL; - if ( lower_bckgrd < 0 || higher_bckgrd >= int(length_histo) || lower_bckgrd > higher_bckgrd ) - return NULL ; + if ( lower_bckgrd < 0 || higher_bckgrd >= int(length_histo) || lower_bckgrd > higher_bckgrd ) + return NULL; - double bckgrd = 0 ; + double bckgrd = 0; - for (int k = lower_bckgrd ; k <= higher_bckgrd ; k++) - { - bckgrd += double(histo[histo_num][k]) ; - } - bckgrd = bckgrd/(higher_bckgrd-lower_bckgrd+1) ; + for (int k = lower_bckgrd; k <= higher_bckgrd; k++) + { + bckgrd += double(histo[histo_num][k]); + } + bckgrd = bckgrd/(higher_bckgrd-lower_bckgrd+1); - double *histo_fromt0_minus_bckgrd_array = - new double[int((int(length_histo)-get_t0_int(histo_num)-offset+1)/binning)] ; + double *histo_fromt0_minus_bckgrd_array = + new double[int((int(length_histo)-get_t0_int(histo_num)-offset+1)/binning)]; - if (!histo_fromt0_minus_bckgrd_array) return NULL; + if (!histo_fromt0_minus_bckgrd_array) return NULL; - for (int i = 0 ; i < int((int(length_histo)-get_t0_int(histo_num)-offset)/binning) ; i++) - { - histo_fromt0_minus_bckgrd_array[i] = 0 ; - for (int j = 0 ; j < binning ; j++) - histo_fromt0_minus_bckgrd_array[i] += - double(histo[histo_num][i*binning+j+get_t0_int(histo_num)+offset]) - bckgrd; - } + for (int i = 0; i < int((int(length_histo)-get_t0_int(histo_num)-offset)/binning); i++) + { + histo_fromt0_minus_bckgrd_array[i] = 0; + for (int j = 0; j < binning; j++) + histo_fromt0_minus_bckgrd_array[i] += + double(histo[histo_num][i*binning+j+get_t0_int(histo_num)+offset]) - bckgrd; + } - return histo_fromt0_minus_bckgrd_array ; - } ; + return histo_fromt0_minus_bckgrd_array; + } //******************************* //Implementation get_histo_fromt0_minus_bckgrd_vector @@ -1903,38 +2470,38 @@ double * MuSR_td_PSI_bin::get_histo_fromt0_minus_bckgrd_array(int histo_num , * between which the background is calculated. */ - vector MuSR_td_PSI_bin::get_histo_fromt0_minus_bckgrd_vector(int histo_num , int lower_bckgrd , - int higher_bckgrd , int binning, int offset) - { - vector histo_fromt0_minus_bckgrd_vector ; // (int((int(length_histo)-get_t0_int(histo_num)+1)/binning)) ; + vector MuSR_td_PSI_bin::get_histo_fromt0_minus_bckgrd_vector(int histo_num, int lower_bckgrd, + int higher_bckgrd, int binning, int offset) + { + vector histo_fromt0_minus_bckgrd_vector; // (int((int(length_histo)-get_t0_int(histo_num)+1)/binning)); - if (!readingok) return histo_fromt0_minus_bckgrd_vector; + if (!readingok) return histo_fromt0_minus_bckgrd_vector; - if ( histo_num < 0 || histo_num >= int(number_histo) || binning <= 0 ) - return histo_fromt0_minus_bckgrd_vector ; + if ( histo_num < 0 || histo_num >= int(number_histo) || binning <= 0 ) + return histo_fromt0_minus_bckgrd_vector; - if ( lower_bckgrd < 0 || higher_bckgrd >= int(length_histo) || lower_bckgrd > higher_bckgrd ) - return histo_fromt0_minus_bckgrd_vector ; + if ( lower_bckgrd < 0 || higher_bckgrd >= int(length_histo) || lower_bckgrd > higher_bckgrd ) + return histo_fromt0_minus_bckgrd_vector; - double bckgrd = 0 ; - for (int k = lower_bckgrd ; k <= higher_bckgrd ; k++) - { - bckgrd += double(histo[histo_num][k]) ; - } - bckgrd = bckgrd/(higher_bckgrd-lower_bckgrd+1) ; + double bckgrd = 0; + for (int k = lower_bckgrd; k <= higher_bckgrd; k++) + { + bckgrd += double(histo[histo_num][k]); + } + bckgrd = bckgrd/(higher_bckgrd-lower_bckgrd+1); - for (int i = 0 ; i < int((int(length_histo)-get_t0_int(histo_num)-offset)/binning) ; i++) - histo_fromt0_minus_bckgrd_vector.push_back(0.) ; + for (int i = 0; i < int((int(length_histo)-get_t0_int(histo_num)-offset)/binning); i++) + histo_fromt0_minus_bckgrd_vector.push_back(0.); - for (int i = 0 ; i < int((int(length_histo)-get_t0_int(histo_num)-offset)/binning) ; i++) - { - for (int j = 0 ; j < binning ; j++) - histo_fromt0_minus_bckgrd_vector[i] += - double(histo[histo_num][i*binning+j+get_t0_int(histo_num)+offset]) - bckgrd; - } + for (int i = 0; i < int((int(length_histo)-get_t0_int(histo_num)-offset)/binning); i++) + { + for (int j = 0; j < binning; j++) + histo_fromt0_minus_bckgrd_vector[i] += + double(histo[histo_num][i*binning+j+get_t0_int(histo_num)+offset]) - bckgrd; + } - return histo_fromt0_minus_bckgrd_vector ; - } + return histo_fromt0_minus_bckgrd_vector; + } //******************************* @@ -1960,39 +2527,39 @@ double * MuSR_td_PSI_bin::get_histo_fromt0_minus_bckgrd_array(int histo_num , * between which the background is calculated. */ -double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , int lower_bckgrd , - int higher_bckgrd , int binning) - { - if (!readingok) return NULL; + double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num, int lower_bckgrd, + int higher_bckgrd, int binning) + { + if (!readingok) return NULL; - if ( histo_num < 0 || histo_num >= int(number_histo) || binning <= 0 ) - return NULL ; + if ( histo_num < 0 || histo_num >= int(number_histo) || binning <= 0 ) + return NULL; - if ( lower_bckgrd < 0 || higher_bckgrd >= int(length_histo) || lower_bckgrd > higher_bckgrd ) - return NULL ; + if ( lower_bckgrd < 0 || higher_bckgrd >= int(length_histo) || lower_bckgrd > higher_bckgrd ) + return NULL; - double bckgrd = 0 ; - for (int k = lower_bckgrd ; k <= higher_bckgrd ; k++) - { - bckgrd += double(histo[histo_num][k]) ; - } - bckgrd = bckgrd/(higher_bckgrd-lower_bckgrd+1) ; + double bckgrd = 0; + for (int k = lower_bckgrd; k <= higher_bckgrd; k++) + { + bckgrd += double(histo[histo_num][k]); + } + bckgrd = bckgrd/(higher_bckgrd-lower_bckgrd+1); - double *histo_goodBins_minus_bckgrd_array = - new double[int((get_lastGood_int(histo_num)-get_firstGood_int(histo_num)+1)/binning)] ; + double *histo_goodBins_minus_bckgrd_array = + new double[int((get_lastGood_int(histo_num)-get_firstGood_int(histo_num)+1)/binning)]; - if (!histo_goodBins_minus_bckgrd_array) return NULL; + if (!histo_goodBins_minus_bckgrd_array) return NULL; - for (int i = 0 ; i < int((get_lastGood_int(histo_num)-get_firstGood_int(histo_num))/binning) ; i++) - { - histo_goodBins_minus_bckgrd_array[i] = 0 ; - for (int j = 0 ; j < binning ; j++) - histo_goodBins_minus_bckgrd_array[i] += - double(histo[histo_num][i*binning+j+get_firstGood_int(histo_num)]) - bckgrd; - } + for (int i = 0; i < int((get_lastGood_int(histo_num)-get_firstGood_int(histo_num))/binning); i++) + { + histo_goodBins_minus_bckgrd_array[i] = 0; + for (int j = 0; j < binning; j++) + histo_goodBins_minus_bckgrd_array[i] += + double(histo[histo_num][i*binning+j+get_firstGood_int(histo_num)]) - bckgrd; + } - return histo_goodBins_minus_bckgrd_array ; - } ; + return histo_goodBins_minus_bckgrd_array; + } //******************************* @@ -2017,38 +2584,38 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , * between which the background is calculated. */ - vector MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_vector(int histo_num , int lower_bckgrd , - int higher_bckgrd , int binning) - { - vector histo_goodBins_minus_bckgrd_vector ; ; + vector MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_vector(int histo_num, int lower_bckgrd, + int higher_bckgrd, int binning) + { + vector histo_goodBins_minus_bckgrd_vector; ; - if (!readingok) return histo_goodBins_minus_bckgrd_vector; + if (!readingok) return histo_goodBins_minus_bckgrd_vector; - if ( histo_num < 0 || histo_num >= int(number_histo) || binning <= 0 ) - return histo_goodBins_minus_bckgrd_vector ; + if ( histo_num < 0 || histo_num >= int(number_histo) || binning <= 0 ) + return histo_goodBins_minus_bckgrd_vector; - if ( lower_bckgrd < 0 || higher_bckgrd >= int(length_histo) || lower_bckgrd > higher_bckgrd ) - return histo_goodBins_minus_bckgrd_vector ; + if ( lower_bckgrd < 0 || higher_bckgrd >= int(length_histo) || lower_bckgrd > higher_bckgrd ) + return histo_goodBins_minus_bckgrd_vector; - double bckgrd = 0 ; - for (int k = lower_bckgrd ; k <= higher_bckgrd ; k++) - { - bckgrd += double(histo[histo_num][k]) ; - } - bckgrd = bckgrd/(higher_bckgrd-lower_bckgrd+1) ; + double bckgrd = 0; + for (int k = lower_bckgrd; k <= higher_bckgrd; k++) + { + bckgrd += double(histo[histo_num][k]); + } + bckgrd = bckgrd/(higher_bckgrd-lower_bckgrd+1); - for (int i = 0 ; i < int((get_lastGood_int(histo_num)-get_firstGood_int(histo_num))/binning) ; i++) - histo_goodBins_minus_bckgrd_vector.push_back(0.) ; + for (int i = 0; i < int((get_lastGood_int(histo_num)-get_firstGood_int(histo_num))/binning); i++) + histo_goodBins_minus_bckgrd_vector.push_back(0.); - for (int i = 0 ; i < int((get_lastGood_int(histo_num)-get_firstGood_int(histo_num))/binning) ; i++) - { - for (int j = 0 ; j < binning ; j++) - histo_goodBins_minus_bckgrd_vector[i] += - double(histo[histo_num][i*binning+j+get_firstGood_int(histo_num)]) - bckgrd; - } + for (int i = 0; i < int((get_lastGood_int(histo_num)-get_firstGood_int(histo_num))/binning); i++) + { + for (int j = 0; j < binning; j++) + histo_goodBins_minus_bckgrd_vector[i] += + double(histo[histo_num][i*binning+j+get_firstGood_int(histo_num)]) - bckgrd; + } - return histo_goodBins_minus_bckgrd_vector ; - } + return histo_goodBins_minus_bckgrd_vector; + } //******************************* @@ -2076,55 +2643,55 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , * also required. */ - double * MuSR_td_PSI_bin::get_asymmetry_array(int histo_num_plus , int histo_num_minus , double alpha_param , - int binning , int lower_bckgrd_plus , int higher_bckgrd_plus , - int lower_bckgrd_minus , int higher_bckgrd_minus , int offset , - double y_offset) - { - int max_t0 = tmax(get_t0_int(histo_num_plus),get_t0_int(histo_num_minus)) ; + double * MuSR_td_PSI_bin::get_asymmetry_array(int histo_num_plus, int histo_num_minus, double alpha_param, + int binning, int lower_bckgrd_plus, int higher_bckgrd_plus, + int lower_bckgrd_minus, int higher_bckgrd_minus, int offset, + double y_offset) + { + int max_t0 = tmax(get_t0_int(histo_num_plus),get_t0_int(histo_num_minus)); - if (!readingok) return NULL; + if (!readingok) return NULL; - if ( histo_num_plus < 0 || histo_num_plus >= int(number_histo) || binning <= 0 ) - return NULL ; + if ( histo_num_plus < 0 || histo_num_plus >= int(number_histo) || binning <= 0 ) + return NULL; - if ( histo_num_minus < 0 || histo_num_minus >= int(number_histo) ) - return NULL ; + if ( histo_num_minus < 0 || histo_num_minus >= int(number_histo) ) + return NULL; - if ( lower_bckgrd_plus < 0 || higher_bckgrd_plus >= int(length_histo) || lower_bckgrd_plus > higher_bckgrd_plus ) - return NULL ; + if ( lower_bckgrd_plus < 0 || higher_bckgrd_plus >= int(length_histo) || lower_bckgrd_plus > higher_bckgrd_plus ) + return NULL; - if ( lower_bckgrd_minus < 0 || higher_bckgrd_minus >= int(length_histo) || lower_bckgrd_minus > higher_bckgrd_minus ) - return NULL ; + if ( lower_bckgrd_minus < 0 || higher_bckgrd_minus >= int(length_histo) || lower_bckgrd_minus > higher_bckgrd_minus ) + return NULL; - double *dummy_1 = get_histo_fromt0_minus_bckgrd_array(histo_num_plus , lower_bckgrd_plus , - higher_bckgrd_plus , binning , offset) ; - if (dummy_1 == NULL) return NULL ; + double *dummy_1 = get_histo_fromt0_minus_bckgrd_array(histo_num_plus, lower_bckgrd_plus, + higher_bckgrd_plus, binning, offset); + if (dummy_1 == NULL) return NULL; - double *dummy_2 = get_histo_fromt0_minus_bckgrd_array(histo_num_minus , lower_bckgrd_minus , - higher_bckgrd_minus , binning , offset) ; - if (dummy_2 == NULL) - { - delete [] dummy_1; - return NULL ; - } + double *dummy_2 = get_histo_fromt0_minus_bckgrd_array(histo_num_minus, lower_bckgrd_minus, + higher_bckgrd_minus, binning, offset); + if (dummy_2 == NULL) + { + delete [] dummy_1; + return NULL; + } - double *asymmetry_array = new double[int((int(length_histo)-max_t0-offset+1)/binning)] ; + double *asymmetry_array = new double[int((int(length_histo)-max_t0-offset+1)/binning)]; - if (!asymmetry_array) return NULL; + if (!asymmetry_array) return NULL; - for (int i = 0 ; i < int((int(length_histo)-max_t0)/binning) ; i++) - { - asymmetry_array[i] = (dummy_1[i] - alpha_param * dummy_2[i]) / - (dummy_1[i] + alpha_param * dummy_2[i]) + y_offset ; - } + for (int i = 0; i < int((int(length_histo)-max_t0)/binning); i++) + { + asymmetry_array[i] = (dummy_1[i] - alpha_param * dummy_2[i]) / + (dummy_1[i] + alpha_param * dummy_2[i]) + y_offset; + } - delete [] dummy_1; - delete [] dummy_2; + delete [] dummy_1; + delete [] dummy_2; - return asymmetry_array ; - } + return asymmetry_array; + } //******************************* @@ -2149,54 +2716,54 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , * Integers for the binning and for the background limits for both histograms.are also required. */ - vector MuSR_td_PSI_bin::get_asymmetry_vector(int histo_num_plus , int histo_num_minus , double alpha_param , - int binning , int lower_bckgrd_plus , int higher_bckgrd_plus , - int lower_bckgrd_minus , int higher_bckgrd_minus , int offset , double y_offset) - { - int max_t0 = tmax(get_t0_int(histo_num_plus),get_t0_int(histo_num_minus)) ; + vector MuSR_td_PSI_bin::get_asymmetry_vector(int histo_num_plus, int histo_num_minus, double alpha_param, + int binning, int lower_bckgrd_plus, int higher_bckgrd_plus, + int lower_bckgrd_minus, int higher_bckgrd_minus, int offset, double y_offset) + { + int max_t0 = tmax(get_t0_int(histo_num_plus),get_t0_int(histo_num_minus)); - vector asymmetry_vector ; // (int((int(length_histo)-max_t0+1)/binning)) ; + vector asymmetry_vector; // (int((int(length_histo)-max_t0+1)/binning)); - if (!readingok) return asymmetry_vector; + if (!readingok) return asymmetry_vector; - if ( histo_num_plus < 0 || histo_num_plus >= int(number_histo) || binning <= 0 ) - return asymmetry_vector ; + if ( histo_num_plus < 0 || histo_num_plus >= int(number_histo) || binning <= 0 ) + return asymmetry_vector; - if ( histo_num_minus < 0 || histo_num_minus >= int(number_histo) ) - return asymmetry_vector ; + if ( histo_num_minus < 0 || histo_num_minus >= int(number_histo) ) + return asymmetry_vector; - if ( lower_bckgrd_plus < 0 || higher_bckgrd_plus >= int(length_histo) || lower_bckgrd_plus > higher_bckgrd_plus ) - return asymmetry_vector ; + if ( lower_bckgrd_plus < 0 || higher_bckgrd_plus >= int(length_histo) || lower_bckgrd_plus > higher_bckgrd_plus ) + return asymmetry_vector; - if ( lower_bckgrd_minus < 0 || higher_bckgrd_minus >= int(length_histo) || lower_bckgrd_minus > higher_bckgrd_minus ) - return asymmetry_vector ; + if ( lower_bckgrd_minus < 0 || higher_bckgrd_minus >= int(length_histo) || lower_bckgrd_minus > higher_bckgrd_minus ) + return asymmetry_vector; - double *dummy_1 = get_histo_fromt0_minus_bckgrd_array(histo_num_plus , lower_bckgrd_plus , - higher_bckgrd_plus , binning, offset) ; - if (dummy_1 == NULL) return asymmetry_vector; + double *dummy_1 = get_histo_fromt0_minus_bckgrd_array(histo_num_plus, lower_bckgrd_plus, + higher_bckgrd_plus, binning, offset); + if (dummy_1 == NULL) return asymmetry_vector; - double *dummy_2 = get_histo_fromt0_minus_bckgrd_array(histo_num_minus , lower_bckgrd_minus , - higher_bckgrd_minus , binning, offset) ; - if (dummy_2 == NULL) - { - delete [] dummy_1; - return asymmetry_vector; - } - - for (int i = 0 ; i < int((int(length_histo)-max_t0-offset)/binning) ; i++) - asymmetry_vector.push_back(0.) ; - - for (int i = 0 ; i < int((int(length_histo)-max_t0-offset)/binning) ; i++) + double *dummy_2 = get_histo_fromt0_minus_bckgrd_array(histo_num_minus, lower_bckgrd_minus, + higher_bckgrd_minus, binning, offset); + if (dummy_2 == NULL) { - asymmetry_vector[i] = (dummy_1[i] - alpha_param * dummy_2[i]) / - (dummy_1[i] + alpha_param * dummy_2[i]) + y_offset ; - } + delete [] dummy_1; + return asymmetry_vector; + } - delete [] dummy_1; - delete [] dummy_2; + for (int i = 0; i < int((int(length_histo)-max_t0-offset)/binning); i++) + asymmetry_vector.push_back(0.); - return asymmetry_vector ; - } + for (int i = 0; i < int((int(length_histo)-max_t0-offset)/binning); i++) + { + asymmetry_vector[i] = (dummy_1[i] - alpha_param * dummy_2[i]) / + (dummy_1[i] + alpha_param * dummy_2[i]) + y_offset; + } + + delete [] dummy_1; + delete [] dummy_2; + + return asymmetry_vector; + } //******************************* @@ -2221,56 +2788,56 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , * Integers for the binning and for the background limits for both histograms.are also required. */ - double * MuSR_td_PSI_bin::get_error_asymmetry_array(int histo_num_plus , int histo_num_minus , double alpha_param , - int binning , int lower_bckgrd_plus , int higher_bckgrd_plus , - int lower_bckgrd_minus , int higher_bckgrd_minus, int offset) - { - int max_t0 = tmax(get_t0_int(histo_num_plus),get_t0_int(histo_num_minus)) ; + double * MuSR_td_PSI_bin::get_error_asymmetry_array(int histo_num_plus, int histo_num_minus, double alpha_param, + int binning, int lower_bckgrd_plus, int higher_bckgrd_plus, + int lower_bckgrd_minus, int higher_bckgrd_minus, int offset) + { + int max_t0 = tmax(get_t0_int(histo_num_plus),get_t0_int(histo_num_minus)); - if (!readingok) return NULL; + if (!readingok) return NULL; - if ( histo_num_plus < 0 || histo_num_plus >= int(number_histo) || binning <= 0 ) - return NULL ; + if ( histo_num_plus < 0 || histo_num_plus >= int(number_histo) || binning <= 0 ) + return NULL; - if ( histo_num_minus < 0 || histo_num_minus >= int(number_histo) ) - return NULL ; + if ( histo_num_minus < 0 || histo_num_minus >= int(number_histo) ) + return NULL; - if ( lower_bckgrd_plus < 0 || higher_bckgrd_plus >= int(length_histo) || lower_bckgrd_plus > higher_bckgrd_plus ) - return NULL ; + if ( lower_bckgrd_plus < 0 || higher_bckgrd_plus >= int(length_histo) || lower_bckgrd_plus > higher_bckgrd_plus ) + return NULL; - if ( lower_bckgrd_minus < 0 || higher_bckgrd_minus >= int(length_histo) || lower_bckgrd_minus > higher_bckgrd_minus ) - return NULL ; + if ( lower_bckgrd_minus < 0 || higher_bckgrd_minus >= int(length_histo) || lower_bckgrd_minus > higher_bckgrd_minus ) + return NULL; - double *dummy_1 = get_histo_fromt0_minus_bckgrd_array(histo_num_plus , lower_bckgrd_plus , - higher_bckgrd_plus , binning, offset) ; - if (dummy_1 == NULL) return NULL; + double *dummy_1 = get_histo_fromt0_minus_bckgrd_array(histo_num_plus, lower_bckgrd_plus, + higher_bckgrd_plus, binning, offset); + if (dummy_1 == NULL) return NULL; - double *dummy_2 = get_histo_fromt0_minus_bckgrd_array(histo_num_minus , lower_bckgrd_minus , - higher_bckgrd_minus , binning, offset) ; - if (dummy_2 == NULL) - { - delete [] dummy_1; - return NULL; - } + double *dummy_2 = get_histo_fromt0_minus_bckgrd_array(histo_num_minus, lower_bckgrd_minus, + higher_bckgrd_minus, binning, offset); + if (dummy_2 == NULL) + { + delete [] dummy_1; + return NULL; + } - double *error_asymmetry_array = new double[int((int(length_histo)-max_t0-offset+1)/binning)] ; + double *error_asymmetry_array = new double[int((int(length_histo)-max_t0-offset+1)/binning)]; - if (!error_asymmetry_array) return NULL; + if (!error_asymmetry_array) return NULL; - for (int i = 0 ; i < int((length_histo-max_t0-offset)/binning) ; i++) - { - if (dummy_1[i] < 0.5 || dummy_2[i] < 0.5 ) - error_asymmetry_array[i] = 1.0 ; - else - error_asymmetry_array[i] = double(2.) * alpha_param * sqrt(dummy_1[i]*dummy_2[i]*(dummy_1[i]+dummy_2[i])) / - pow(dummy_1[i] + alpha_param * dummy_2[i],2.) ; - } + for (int i = 0; i < int((length_histo-max_t0-offset)/binning); i++) + { + if (dummy_1[i] < 0.5 || dummy_2[i] < 0.5 ) + error_asymmetry_array[i] = 1.0; + else + error_asymmetry_array[i] = double(2.) * alpha_param * sqrt(dummy_1[i]*dummy_2[i]*(dummy_1[i]+dummy_2[i])) / + pow(dummy_1[i] + alpha_param * dummy_2[i],2.); + } - delete [] dummy_1; - delete [] dummy_2; + delete [] dummy_1; + delete [] dummy_2; - return error_asymmetry_array ; - } + return error_asymmetry_array; + } //******************************* @@ -2294,57 +2861,57 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , * Integers for the binning and for the background limits for both histograms.are also required. */ - vector MuSR_td_PSI_bin::get_error_asymmetry_vector(int histo_num_plus , int histo_num_minus , double alpha_param , - int binning , int lower_bckgrd_plus , int higher_bckgrd_plus , - int lower_bckgrd_minus , int higher_bckgrd_minus, int offset) - { - int max_t0 = tmax(get_t0_int(histo_num_plus),get_t0_int(histo_num_minus)) ; + vector MuSR_td_PSI_bin::get_error_asymmetry_vector(int histo_num_plus, int histo_num_minus, double alpha_param, + int binning, int lower_bckgrd_plus, int higher_bckgrd_plus, + int lower_bckgrd_minus, int higher_bckgrd_minus, int offset) + { + int max_t0 = tmax(get_t0_int(histo_num_plus),get_t0_int(histo_num_minus)); - vector error_asymmetry_vector ; //(int((int(length_histo)-max_t0+1)/binning)) ; + vector error_asymmetry_vector; //(int((int(length_histo)-max_t0+1)/binning)); - if (!readingok) return error_asymmetry_vector; + if (!readingok) return error_asymmetry_vector; - if ( histo_num_plus < 0 || histo_num_plus >= int(number_histo) || binning <= 0 ) - return error_asymmetry_vector ; + if ( histo_num_plus < 0 || histo_num_plus >= int(number_histo) || binning <= 0 ) + return error_asymmetry_vector; - if ( histo_num_minus < 0 || histo_num_minus >= int(number_histo) ) - return error_asymmetry_vector ; + if ( histo_num_minus < 0 || histo_num_minus >= int(number_histo) ) + return error_asymmetry_vector; - if ( lower_bckgrd_plus < 0 || higher_bckgrd_plus >= int(length_histo) || lower_bckgrd_plus > higher_bckgrd_plus ) - return error_asymmetry_vector ; + if ( lower_bckgrd_plus < 0 || higher_bckgrd_plus >= int(length_histo) || lower_bckgrd_plus > higher_bckgrd_plus ) + return error_asymmetry_vector; - if ( lower_bckgrd_minus < 0 || higher_bckgrd_minus >= int(length_histo) || lower_bckgrd_minus > higher_bckgrd_minus ) - return error_asymmetry_vector ; + if ( lower_bckgrd_minus < 0 || higher_bckgrd_minus >= int(length_histo) || lower_bckgrd_minus > higher_bckgrd_minus ) + return error_asymmetry_vector; - double *dummy_1 = get_histo_fromt0_minus_bckgrd_array(histo_num_plus , lower_bckgrd_plus , - higher_bckgrd_plus , binning, offset) ; - if (dummy_1 == NULL) return error_asymmetry_vector ; + double *dummy_1 = get_histo_fromt0_minus_bckgrd_array(histo_num_plus, lower_bckgrd_plus, + higher_bckgrd_plus, binning, offset); + if (dummy_1 == NULL) return error_asymmetry_vector; - double *dummy_2 = get_histo_fromt0_minus_bckgrd_array(histo_num_minus , lower_bckgrd_minus , - higher_bckgrd_minus , binning, offset) ; - if (dummy_2 == NULL) - { - delete [] dummy_1; - return error_asymmetry_vector ; - } + double *dummy_2 = get_histo_fromt0_minus_bckgrd_array(histo_num_minus, lower_bckgrd_minus, + higher_bckgrd_minus, binning, offset); + if (dummy_2 == NULL) + { + delete [] dummy_1; + return error_asymmetry_vector; + } - for (int i = 0 ; i < int((int(length_histo)-max_t0-offset)/binning) ; i++) - error_asymmetry_vector.push_back(0.) ; + for (int i = 0; i < int((int(length_histo)-max_t0-offset)/binning); i++) + error_asymmetry_vector.push_back(0.); - for (int i = 0 ; i < int((int(length_histo-max_t0-offset))/binning) ; i++) - { - if (dummy_1[i] < 0.5 || dummy_2[i] < 0.5 ) - error_asymmetry_vector[i] = 1.0 ; - else - error_asymmetry_vector[i] = double(2.) * alpha_param * sqrt(dummy_1[i]*dummy_2[i]*(dummy_1[i]+dummy_2[i])) / - pow(dummy_1[i] + alpha_param * dummy_2[i],2.) ; - } + for (int i = 0; i < int((int(length_histo-max_t0-offset))/binning); i++) + { + if (dummy_1[i] < 0.5 || dummy_2[i] < 0.5 ) + error_asymmetry_vector[i] = 1.0; + else + error_asymmetry_vector[i] = double(2.) * alpha_param * sqrt(dummy_1[i]*dummy_2[i]*(dummy_1[i]+dummy_2[i])) / + pow(dummy_1[i] + alpha_param * dummy_2[i],2.); + } - delete [] dummy_1; - delete [] dummy_2; + delete [] dummy_1; + delete [] dummy_2; - return error_asymmetry_vector ; - } + return error_asymmetry_vector; + } //******************************* @@ -2370,56 +2937,56 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , * Integers for the binning and for the background limits for both histograms.are also required. */ - double * MuSR_td_PSI_bin::get_asymmetry_goodBins_array(int histo_num_plus , int histo_num_minus , double alpha_param , - int binning , int lower_bckgrd_plus , int higher_bckgrd_plus , - int lower_bckgrd_minus , int higher_bckgrd_minus) - { - int hsize = int((tmin(get_lastGood_int(histo_num_plus)-get_firstGood_int(histo_num_plus), - get_lastGood_int(histo_num_minus)-get_firstGood_int(histo_num_minus))+1)/binning) ; + double * MuSR_td_PSI_bin::get_asymmetry_goodBins_array(int histo_num_plus, int histo_num_minus, double alpha_param, + int binning, int lower_bckgrd_plus, int higher_bckgrd_plus, + int lower_bckgrd_minus, int higher_bckgrd_minus) + { + int hsize = int((tmin(get_lastGood_int(histo_num_plus)-get_firstGood_int(histo_num_plus), + get_lastGood_int(histo_num_minus)-get_firstGood_int(histo_num_minus))+1)/binning); - if (!readingok) return NULL; + if (!readingok) return NULL; - if ( histo_num_plus < 0 || histo_num_plus >= int(number_histo) || binning <= 0 ) - return NULL ; + if ( histo_num_plus < 0 || histo_num_plus >= int(number_histo) || binning <= 0 ) + return NULL; - if ( histo_num_minus < 0 || histo_num_minus >= int(number_histo) ) - return NULL ; + if ( histo_num_minus < 0 || histo_num_minus >= int(number_histo) ) + return NULL; - if ( lower_bckgrd_plus < 0 || higher_bckgrd_plus >= int(length_histo) || lower_bckgrd_plus > higher_bckgrd_plus ) - return NULL ; + if ( lower_bckgrd_plus < 0 || higher_bckgrd_plus >= int(length_histo) || lower_bckgrd_plus > higher_bckgrd_plus ) + return NULL; - if ( lower_bckgrd_minus < 0 || higher_bckgrd_minus >= int(length_histo) || lower_bckgrd_minus > higher_bckgrd_minus ) - return NULL ; + if ( lower_bckgrd_minus < 0 || higher_bckgrd_minus >= int(length_histo) || lower_bckgrd_minus > higher_bckgrd_minus ) + return NULL; - double *dummy_1 = get_histo_fromt0_minus_bckgrd_array(histo_num_plus , lower_bckgrd_plus , - higher_bckgrd_plus , binning) ; - if (dummy_1 == NULL) return NULL; + double *dummy_1 = get_histo_fromt0_minus_bckgrd_array(histo_num_plus, lower_bckgrd_plus, + higher_bckgrd_plus, binning); + if (dummy_1 == NULL) return NULL; - double *dummy_2 = get_histo_fromt0_minus_bckgrd_array(histo_num_minus , lower_bckgrd_minus , - higher_bckgrd_minus , binning) ; - if (dummy_2 == NULL) - { - delete [] dummy_1; - return NULL; - } + double *dummy_2 = get_histo_fromt0_minus_bckgrd_array(histo_num_minus, lower_bckgrd_minus, + higher_bckgrd_minus, binning); + if (dummy_2 == NULL) + { + delete [] dummy_1; + return NULL; + } - int hstart = tmax(get_firstGood_int(histo_num_plus)-get_t0_int(histo_num_plus),get_firstGood_int(histo_num_minus)-get_t0_int(histo_num_minus)) ; + int hstart = tmax(get_firstGood_int(histo_num_plus)-get_t0_int(histo_num_plus),get_firstGood_int(histo_num_minus)-get_t0_int(histo_num_minus)); - double *asymmetry_goodBins_array = new double[hsize] ; + double *asymmetry_goodBins_array = new double[hsize]; - if (!asymmetry_goodBins_array) return NULL; + if (!asymmetry_goodBins_array) return NULL; - for (int i = 0 ; i < hsize ; i++) - { - asymmetry_goodBins_array[i] = (dummy_1[i+hstart] - alpha_param * dummy_2[i+hstart]) / - (dummy_1[i+hstart] + alpha_param * dummy_2[i+hstart]) ; - } + for (int i = 0; i < hsize; i++) + { + asymmetry_goodBins_array[i] = (dummy_1[i+hstart] - alpha_param * dummy_2[i+hstart]) / + (dummy_1[i+hstart] + alpha_param * dummy_2[i+hstart]); + } - delete [] dummy_1; - delete [] dummy_2; + delete [] dummy_1; + delete [] dummy_2; - return asymmetry_goodBins_array ; - } + return asymmetry_goodBins_array; + } //******************************* @@ -2444,56 +3011,56 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , * Integers for the binning and for the background limits for both histograms.are also required. */ - vector MuSR_td_PSI_bin::get_asymmetry_goodBins_vector(int histo_num_plus , int histo_num_minus , double alpha_param , - int binning , int lower_bckgrd_plus , int higher_bckgrd_plus , - int lower_bckgrd_minus , int higher_bckgrd_minus) - { - int hsize = int((tmin(get_lastGood_int(histo_num_plus)-get_firstGood_int(histo_num_plus), - get_lastGood_int(histo_num_minus)-get_firstGood_int(histo_num_minus))+1)/binning) ; + vector MuSR_td_PSI_bin::get_asymmetry_goodBins_vector(int histo_num_plus, int histo_num_minus, double alpha_param, + int binning, int lower_bckgrd_plus, int higher_bckgrd_plus, + int lower_bckgrd_minus, int higher_bckgrd_minus) + { + int hsize = int((tmin(get_lastGood_int(histo_num_plus)-get_firstGood_int(histo_num_plus), + get_lastGood_int(histo_num_minus)-get_firstGood_int(histo_num_minus))+1)/binning); - vector asymmetry_goodBins_vector ; + vector asymmetry_goodBins_vector; - if (!readingok) return asymmetry_goodBins_vector; + if (!readingok) return asymmetry_goodBins_vector; - if ( histo_num_plus < 0 || histo_num_plus >= int(number_histo) || binning <= 0 ) - return asymmetry_goodBins_vector ; + if ( histo_num_plus < 0 || histo_num_plus >= int(number_histo) || binning <= 0 ) + return asymmetry_goodBins_vector; - if ( histo_num_minus < 0 || histo_num_minus >= int(number_histo) ) - return asymmetry_goodBins_vector ; + if ( histo_num_minus < 0 || histo_num_minus >= int(number_histo) ) + return asymmetry_goodBins_vector; - if ( lower_bckgrd_plus < 0 || higher_bckgrd_plus >= int(length_histo) || lower_bckgrd_plus > higher_bckgrd_plus ) - return asymmetry_goodBins_vector ; + if ( lower_bckgrd_plus < 0 || higher_bckgrd_plus >= int(length_histo) || lower_bckgrd_plus > higher_bckgrd_plus ) + return asymmetry_goodBins_vector; - if ( lower_bckgrd_minus < 0 || higher_bckgrd_minus >= int(length_histo) || lower_bckgrd_minus > higher_bckgrd_minus ) - return asymmetry_goodBins_vector ; + if ( lower_bckgrd_minus < 0 || higher_bckgrd_minus >= int(length_histo) || lower_bckgrd_minus > higher_bckgrd_minus ) + return asymmetry_goodBins_vector; - double *dummy_1 = get_histo_fromt0_minus_bckgrd_array(histo_num_plus , lower_bckgrd_plus , - higher_bckgrd_plus , binning) ; - if (dummy_1 == NULL) return asymmetry_goodBins_vector ; + double *dummy_1 = get_histo_fromt0_minus_bckgrd_array(histo_num_plus, lower_bckgrd_plus, + higher_bckgrd_plus, binning); + if (dummy_1 == NULL) return asymmetry_goodBins_vector; - double *dummy_2 = get_histo_fromt0_minus_bckgrd_array(histo_num_minus , lower_bckgrd_minus , - higher_bckgrd_minus , binning) ; - if (dummy_2 == NULL) - { - delete [] dummy_1; - return asymmetry_goodBins_vector ; - } + double *dummy_2 = get_histo_fromt0_minus_bckgrd_array(histo_num_minus, lower_bckgrd_minus, + higher_bckgrd_minus, binning); + if (dummy_2 == NULL) + { + delete [] dummy_1; + return asymmetry_goodBins_vector; + } - for (int i = 0 ; i < hsize ; i++) - asymmetry_goodBins_vector.push_back(0.) ; + for (int i = 0; i < hsize; i++) + asymmetry_goodBins_vector.push_back(0.); - int hstart = tmax(get_firstGood_int(histo_num_plus)-get_t0_int(histo_num_plus),get_firstGood_int(histo_num_minus)-get_t0_int(histo_num_minus)) ; + int hstart = tmax(get_firstGood_int(histo_num_plus)-get_t0_int(histo_num_plus),get_firstGood_int(histo_num_minus)-get_t0_int(histo_num_minus)); - for (int i = 0 ; i < hsize ; i++) - { - asymmetry_goodBins_vector[i] = (dummy_1[i+hstart] - alpha_param * dummy_2[i+hstart]) / - (dummy_1[i+hstart] + alpha_param * dummy_2[i+hstart]) ; - } - delete [] dummy_1; - delete [] dummy_2; + for (int i = 0; i < hsize; i++) + { + asymmetry_goodBins_vector[i] = (dummy_1[i+hstart] - alpha_param * dummy_2[i+hstart]) / + (dummy_1[i+hstart] + alpha_param * dummy_2[i+hstart]); + } + delete [] dummy_1; + delete [] dummy_2; - return asymmetry_goodBins_vector ; - } + return asymmetry_goodBins_vector; + } //******************************* @@ -2518,63 +3085,63 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , * Integers for the binning and for the background limits for both histograms are also required. */ - double * MuSR_td_PSI_bin::get_error_asymmetry_goodBins_array(int histo_num_plus , int histo_num_minus , double alpha_param , - int binning , int lower_bckgrd_plus , int higher_bckgrd_plus , - int lower_bckgrd_minus , int higher_bckgrd_minus) - { - int hsize = int((tmin(get_lastGood_int(histo_num_plus) - -get_firstGood_int(histo_num_plus), - get_lastGood_int(histo_num_minus) - -get_firstGood_int(histo_num_minus))+1)/binning) ; + double * MuSR_td_PSI_bin::get_error_asymmetry_goodBins_array(int histo_num_plus, int histo_num_minus, double alpha_param, + int binning, int lower_bckgrd_plus, int higher_bckgrd_plus, + int lower_bckgrd_minus, int higher_bckgrd_minus) + { + int hsize = int((tmin(get_lastGood_int(histo_num_plus) + -get_firstGood_int(histo_num_plus), + get_lastGood_int(histo_num_minus) + -get_firstGood_int(histo_num_minus))+1)/binning); - if (!readingok) return NULL; + if (!readingok) return NULL; - if ( histo_num_plus < 0 || histo_num_plus >= int(number_histo) || binning <= 0 ) - return NULL ; + if ( histo_num_plus < 0 || histo_num_plus >= int(number_histo) || binning <= 0 ) + return NULL; - if ( histo_num_minus < 0 || histo_num_minus >= int(number_histo) ) - return NULL ; + if ( histo_num_minus < 0 || histo_num_minus >= int(number_histo) ) + return NULL; - if ( lower_bckgrd_plus < 0 || higher_bckgrd_plus >= int(length_histo) || lower_bckgrd_plus > higher_bckgrd_plus ) - return NULL ; + if ( lower_bckgrd_plus < 0 || higher_bckgrd_plus >= int(length_histo) || lower_bckgrd_plus > higher_bckgrd_plus ) + return NULL; - if ( lower_bckgrd_minus < 0 || higher_bckgrd_minus >= int(length_histo) || lower_bckgrd_minus > higher_bckgrd_minus ) - return NULL ; + if ( lower_bckgrd_minus < 0 || higher_bckgrd_minus >= int(length_histo) || lower_bckgrd_minus > higher_bckgrd_minus ) + return NULL; - double *dummy_1 = get_histo_fromt0_minus_bckgrd_array(histo_num_plus , - lower_bckgrd_plus , higher_bckgrd_plus , binning) ; - if (dummy_1 == NULL) return NULL; + double *dummy_1 = get_histo_fromt0_minus_bckgrd_array(histo_num_plus, + lower_bckgrd_plus, higher_bckgrd_plus, binning); + if (dummy_1 == NULL) return NULL; - double *dummy_2 = get_histo_fromt0_minus_bckgrd_array(histo_num_minus , - lower_bckgrd_minus , higher_bckgrd_minus , binning) ; - if (dummy_2 == NULL) - { - delete [] dummy_1; - return NULL; - } - int hstart = tmax(get_firstGood_int(histo_num_plus)-get_t0_int(histo_num_plus), - get_firstGood_int(histo_num_minus)-get_t0_int(histo_num_minus)) ; + double *dummy_2 = get_histo_fromt0_minus_bckgrd_array(histo_num_minus, + lower_bckgrd_minus, higher_bckgrd_minus, binning); + if (dummy_2 == NULL) + { + delete [] dummy_1; + return NULL; + } + int hstart = tmax(get_firstGood_int(histo_num_plus)-get_t0_int(histo_num_plus), + get_firstGood_int(histo_num_minus)-get_t0_int(histo_num_minus)); - double *error_asymmetry_goodBins_array = new double[hsize] ; + double *error_asymmetry_goodBins_array = new double[hsize]; - if (!error_asymmetry_goodBins_array) return NULL; + if (!error_asymmetry_goodBins_array) return NULL; - for (int i = 0 ; i < hsize ; i++) - { - if (dummy_1[i+hstart] < 0.5 || dummy_2[i+hstart] < 0.5 ) - error_asymmetry_goodBins_array[i] = 1.0 ; - else - error_asymmetry_goodBins_array[i] = - double(2.) * alpha_param * sqrt(dummy_1[i+hstart]*dummy_2[i+hstart] - *(dummy_1[i+hstart]+dummy_2[i+hstart])) / - pow(dummy_1[i+hstart] + alpha_param * dummy_2[i+hstart],2.) ; - } + for (int i = 0; i < hsize; i++) + { + if (dummy_1[i+hstart] < 0.5 || dummy_2[i+hstart] < 0.5 ) + error_asymmetry_goodBins_array[i] = 1.0; + else + error_asymmetry_goodBins_array[i] = + double(2.) * alpha_param * sqrt(dummy_1[i+hstart]*dummy_2[i+hstart] + *(dummy_1[i+hstart]+dummy_2[i+hstart])) / + pow(dummy_1[i+hstart] + alpha_param * dummy_2[i+hstart],2.); + } - delete [] dummy_1; - delete [] dummy_2; + delete [] dummy_1; + delete [] dummy_2; - return error_asymmetry_goodBins_array ; - } + return error_asymmetry_goodBins_array; + } //******************************* @@ -2602,63 +3169,63 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , * Integers for the binning and for the background limits for both histograms.are also required. */ - vector MuSR_td_PSI_bin::get_error_asymmetry_goodBins_vector(int histo_num_plus , - int histo_num_minus , double alpha_param , - int binning , int lower_bckgrd_plus , - int higher_bckgrd_plus , - int lower_bckgrd_minus , int higher_bckgrd_minus) - { - int hsize = int((tmin(get_lastGood_int(histo_num_plus)-get_firstGood_int(histo_num_plus), - get_lastGood_int(histo_num_minus)-get_firstGood_int(histo_num_minus))+1)/binning) ; + vector MuSR_td_PSI_bin::get_error_asymmetry_goodBins_vector(int histo_num_plus, + int histo_num_minus, double alpha_param, + int binning, int lower_bckgrd_plus, + int higher_bckgrd_plus, + int lower_bckgrd_minus, int higher_bckgrd_minus) + { + int hsize = int((tmin(get_lastGood_int(histo_num_plus)-get_firstGood_int(histo_num_plus), + get_lastGood_int(histo_num_minus)-get_firstGood_int(histo_num_minus))+1)/binning); - vector error_asymmetry_goodBins_vector ; + vector error_asymmetry_goodBins_vector; - if (!readingok) return error_asymmetry_goodBins_vector; + if (!readingok) return error_asymmetry_goodBins_vector; - if ( histo_num_plus < 0 || histo_num_plus >= int(number_histo) || binning <= 0 ) - return error_asymmetry_goodBins_vector ; + if ( histo_num_plus < 0 || histo_num_plus >= int(number_histo) || binning <= 0 ) + return error_asymmetry_goodBins_vector; - if ( histo_num_minus < 0 || histo_num_minus >= int(number_histo) ) - return error_asymmetry_goodBins_vector ; + if ( histo_num_minus < 0 || histo_num_minus >= int(number_histo) ) + return error_asymmetry_goodBins_vector; - if ( lower_bckgrd_plus < 0 || higher_bckgrd_plus >= int(length_histo) || lower_bckgrd_plus > higher_bckgrd_plus ) - return error_asymmetry_goodBins_vector ; + if ( lower_bckgrd_plus < 0 || higher_bckgrd_plus >= int(length_histo) || lower_bckgrd_plus > higher_bckgrd_plus ) + return error_asymmetry_goodBins_vector; - if ( lower_bckgrd_minus < 0 || higher_bckgrd_minus >= int(length_histo) || lower_bckgrd_minus > higher_bckgrd_minus ) - return error_asymmetry_goodBins_vector ; + if ( lower_bckgrd_minus < 0 || higher_bckgrd_minus >= int(length_histo) || lower_bckgrd_minus > higher_bckgrd_minus ) + return error_asymmetry_goodBins_vector; - double *dummy_1 = get_histo_fromt0_minus_bckgrd_array(histo_num_plus , lower_bckgrd_plus , - higher_bckgrd_plus , binning) ; - if (dummy_1 == NULL) return error_asymmetry_goodBins_vector ; + double *dummy_1 = get_histo_fromt0_minus_bckgrd_array(histo_num_plus, lower_bckgrd_plus, + higher_bckgrd_plus, binning); + if (dummy_1 == NULL) return error_asymmetry_goodBins_vector; - double *dummy_2 = get_histo_fromt0_minus_bckgrd_array(histo_num_minus , lower_bckgrd_minus , - higher_bckgrd_minus , binning) ; - if (dummy_2 == NULL) - { - delete [] dummy_1; - return error_asymmetry_goodBins_vector ; - } + double *dummy_2 = get_histo_fromt0_minus_bckgrd_array(histo_num_minus, lower_bckgrd_minus, + higher_bckgrd_minus, binning); + if (dummy_2 == NULL) + { + delete [] dummy_1; + return error_asymmetry_goodBins_vector; + } - for (int i = 0 ; i < hsize ; i++) - error_asymmetry_goodBins_vector.push_back(0.) ; + for (int i = 0; i < hsize; i++) + error_asymmetry_goodBins_vector.push_back(0.); - int hstart = tmax(get_firstGood_int(histo_num_plus)-get_t0_int(histo_num_plus),get_firstGood_int(histo_num_minus)-get_t0_int(histo_num_minus)) ; + int hstart = tmax(get_firstGood_int(histo_num_plus)-get_t0_int(histo_num_plus),get_firstGood_int(histo_num_minus)-get_t0_int(histo_num_minus)); - for (int i = 0 ; i < hsize ; i++) - { + for (int i = 0; i < hsize; i++) + { if (dummy_1[i+hstart] < 0.5 || dummy_2[i+hstart] < 0.5 ) - error_asymmetry_goodBins_vector[i] = 1.0 ; + error_asymmetry_goodBins_vector[i] = 1.0; else error_asymmetry_goodBins_vector[i] = double(2.) * alpha_param - * sqrt(dummy_1[i+hstart]*dummy_2[i+hstart]*(dummy_1[i+hstart]+dummy_2[i+hstart])) / - pow(dummy_1[i+hstart] + alpha_param * dummy_2[i+hstart],2.) ; - } + * sqrt(dummy_1[i+hstart]*dummy_2[i+hstart]*(dummy_1[i+hstart]+dummy_2[i+hstart])) / + pow(dummy_1[i+hstart] + alpha_param * dummy_2[i+hstart],2.); + } - delete [] dummy_1; - delete [] dummy_2; + delete [] dummy_1; + delete [] dummy_2; - return error_asymmetry_goodBins_vector ; - } + return error_asymmetry_goodBins_vector; + } //******************************* @@ -2669,9 +3236,32 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ int MuSR_td_PSI_bin::get_numberScaler_int() - { - return int(number_scaler) ; - } + { + return int(number_scaler); + } + + //******************************* + //Implementation put_numberScaler_int + //******************************* + + /*! \brief Method seting the number of scalers present + * + * return: + * - 0 on success + * - -1 if val is out of range (32) + * + * \param val the number of scalers present + */ + + int MuSR_td_PSI_bin::put_numberScaler_int(int val) + { + if ((val < 0) || (val >= MAXSCALER)) + return -1; + + number_scaler = val; + + return 0; + } //******************************* //Implementation get_scalers_vector @@ -2681,15 +3271,38 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ vector MuSR_td_PSI_bin::get_scalers_vector() - { - vector scalers_vect(number_scaler) ; + { + vector scalers_vect(number_scaler); - for ( int i = 0 ; i < number_scaler ; i++ ) - scalers_vect[i] = long(scalers[i]) ; + for ( int i = 0; i < number_scaler; i++ ) + scalers_vect[i] = long(scalers[i]); - return scalers_vect ; - } + return scalers_vect; + } + //******************************* + //Implementation put_scalers_vector + //******************************* + + /*! \brief Method set a vector of long containing the values of the scalers + * + * return: + * - 0 on success + * - -1 if scalerData vector is too long (>MAXSCALER) + * + * \param scalerData vector + */ + + int MuSR_td_PSI_bin::put_scalers_vector(vector scalerData) + { + if ((int)scalerData.size() > MAXSCALER) + return -1; + + for (unsigned int i=0; i max_t0) - max_t0 = int(integer_t0[i]) ; - } - return max_t0 ; - } + for (int i = 0; i < int(number_histo); i++) + { + if (int(integer_t0[i]) > max_t0) + max_t0 = int(integer_t0[i]); + } + return max_t0; + } //******************************* @@ -2721,17 +3334,16 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ int MuSR_td_PSI_bin::get_max_2_t0_int(int k, int j) - { - if (( k < 0 || k >= int(number_histo)) || ( j < 0 || j >= int(number_histo))) - return -1 ; + { + if (( k < 0 || k >= int(number_histo)) || ( j < 0 || j >= int(number_histo))) + return -1; - int max_t0 = int(integer_t0[j]) ; - if (int(integer_t0[k]) >= max_t0) - max_t0 = int(integer_t0[k]) ; - - return max_t0 ; - } + int max_t0 = int(integer_t0[j]); + if (int(integer_t0[k]) >= max_t0) + max_t0 = int(integer_t0[k]); + return max_t0; + } //******************************* //Implementation get_min_2_t0_int @@ -2743,17 +3355,16 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ int MuSR_td_PSI_bin::get_min_2_t0_int(int k, int j) - { - if (( k < 0 || k >= int(number_histo)) || ( j < 0 || j >= int(number_histo))) - return -1 ; + { + if (( k < 0 || k >= int(number_histo)) || ( j < 0 || j >= int(number_histo))) + return -1; - int min_t0 = int(integer_t0[j]) ; - if (int(integer_t0[k]) <= min_t0) - min_t0 = int(integer_t0[k]) ; - - return min_t0 ; - } + int min_t0 = int(integer_t0[j]); + if (int(integer_t0[k]) <= min_t0) + min_t0 = int(integer_t0[k]); + return min_t0; + } //******************************* //Implementation get_min_t0_int @@ -2763,20 +3374,20 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ int MuSR_td_PSI_bin::get_min_t0_int() - { - int min_t0 = int(length_histo) ; + { + int min_t0 = int(length_histo); - for (int i = 0 ; i < int(number_histo) ; i++) - { - if (int(integer_t0[i]) < min_t0) - min_t0 = int(integer_t0[i]) ; - } + for (int i = 0; i < int(number_histo); i++) + { + if (int(integer_t0[i]) < min_t0) + min_t0 = int(integer_t0[i]); + } - return min_t0 ; - } + return min_t0; + } - //******************************* +//******************************* //Implementation get_binWidth_ps //******************************* @@ -2784,10 +3395,23 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ double MuSR_td_PSI_bin::get_binWidth_ps() - { - return double((double)bin_width*(double)1000000.) ; - } + { + return double((double)bin_width*(double)1000000.); + } + //******************************* + //Implementation put_binWidth_ps + //******************************* + + /*! \brief Method setting a double representing the bin-width in picoseconds + * + * \param binWidth bin-width given in picoseconds + */ + + void MuSR_td_PSI_bin::put_binWidth_ps(double binWidth) + { + bin_width = (float)(binWidth/1.0e6); + } //******************************* //Implementation get_binWidth_ns @@ -2797,9 +3421,23 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ double MuSR_td_PSI_bin::get_binWidth_ns() - { - return double((double)bin_width*(double)1000.) ; - } + { + return double((double)bin_width*(double)1000.); + } + + //******************************* + //Implementation put_binWidth_ns + //******************************* + + /*! \brief Method setting a double representing the bin-width in nanoseconds + * + * \param binWidth bin-width given in nanoseconds + */ + + void MuSR_td_PSI_bin::put_binWidth_ns(double binWidth) + { + bin_width = (float)(binWidth/1.0e3); + } //******************************* //Implementation get_binWidth_us @@ -2809,10 +3447,23 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ double MuSR_td_PSI_bin::get_binWidth_us() - { - return double(bin_width) ; - } + { + return double(bin_width); + } + //******************************* + //Implementation put_binWidth_us + //******************************* + + /*! \brief Method setting a double representing the bin-width in microseconds + * + * \param binWidth bin-width given in microseconds + */ + + void MuSR_td_PSI_bin::put_binWidth_us(double binWidth) + { + bin_width = (float)binWidth; + } //******************************* //Implementation get_histoLength_bin @@ -2822,10 +3473,9 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ int MuSR_td_PSI_bin::get_histoLength_bin() - { - return int(length_histo) ; - } - + { + return int(length_histo); + } //******************************* //Implementation get_numberHisto_int @@ -2835,10 +3485,9 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ int MuSR_td_PSI_bin::get_numberHisto_int() - { - return int(number_histo) ; - } - + { + return int(number_histo); + } //******************************* //Implementation get_totalEvents_long @@ -2848,10 +3497,9 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ long MuSR_td_PSI_bin::get_totalEvents_long() - { - return long(total_events) ; - } - + { + return long(total_events); + } //******************************* //Implementation get_eventsHisto_long @@ -2863,13 +3511,12 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ long MuSR_td_PSI_bin::get_eventsHisto_long(int i) - { - if ( i < 0 || i >= number_histo) - return -1 ; - else - return long(events_per_histo[i]) ; - } - + { + if ( i < 0 || i >= number_histo) + return -1; + else + return long(events_per_histo[i]); + } //******************************* //Implementation get_eventsHisto_vector @@ -2878,14 +3525,14 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , /*! \brief Method returning a vector of long containing the number of events in the histograms */ - vector MuSR_td_PSI_bin::get_eventsHisto_vector() - { - vector eventsHisto(number_histo) ; + vector MuSR_td_PSI_bin::get_eventsHisto_vector() + { + vector eventsHisto(number_histo); - for ( int i = 0 ; i < number_histo ; i++ ) - eventsHisto[i] = long(events_per_histo[i]) ; - return eventsHisto ; - } + for ( int i = 0; i < number_histo; i++ ) + eventsHisto[i] = long(events_per_histo[i]); + return eventsHisto; + } //******************************* //Implementation get_t0_double @@ -2897,12 +3544,12 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ double MuSR_td_PSI_bin::get_t0_double(int i) - { - if ( i < 0 || i >= int(number_histo)) - return -1. ; - else - return double(real_t0[i]) ; - } + { + if ( i < 0 || i >= int(number_histo)) + return -1.; + else + return double(real_t0[i]); + } //******************************* @@ -2912,13 +3559,14 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , /*! \brief Method returning an integer representing the default binning * */ + int MuSR_td_PSI_bin::get_default_binning() - { - if (default_binning < 1) - return 1; - else - return default_binning ; - } + { + if (default_binning < 1) + return 1; + else + return default_binning; + } //******************************* //Implementation get_t0_int @@ -2930,12 +3578,36 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ int MuSR_td_PSI_bin::get_t0_int(int i) - { - if ( i < 0 || i >= int(number_histo)) - return -1 ; - else - return int(integer_t0[i]) ; - } + { + if ( i < 0 || i >= int(number_histo)) + return -1; + else + return int(integer_t0[i]); + } + + //******************************* + //Implementation put_t0_int + //******************************* + + /*! \brief Method setting an integer representing the t0 point (from the "integer" t0 in the header) for a specified histogram + * + * return: + * - 0 on success + * - -1 if histoNo is out of range + * + * \param histoNo histogram number + * \param t0 t0 bin value + */ + + int MuSR_td_PSI_bin::put_t0_int(int histoNo, int t0) + { + if ((histoNo < 0) || (histoNo >= MAXHISTO)) + return -1; + + integer_t0[histoNo] = t0; + + return 0; + } //******************************* //Implementation get_t0_vector @@ -2945,15 +3617,36 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ vector MuSR_td_PSI_bin::get_t0_vector() - { - vector t0(number_histo) ; + { + vector t0(number_histo); - for ( int i = 0 ; i < int(number_histo) ; i++ ) - t0[i] = int(integer_t0[i]) ; + for ( int i = 0; i < int(number_histo); i++ ) + t0[i] = int(integer_t0[i]); - return t0 ; - } + return t0; + } + //******************************* + //Implementation put_t0_vector + //******************************* + + /*! \brief Method setting a vector of integer containing the t0 values of the histograms specified in the header + * + * return: + * - 0 on success + * - -1 if t0Data is too long (>MAXHISTO) + */ + + int MuSR_td_PSI_bin::put_t0_vector(vector &t0Data) + { + if ((int)t0Data.size() >= MAXHISTO) + return -1; + + for (unsigned int i=0; i= int(number_histo)) - return -1 ; - else - return int(first_good[i]) ; - } + { + if ( i < 0 || i >= int(number_histo)) + return -1; + else + return int(first_good[i]); + } + //******************************* + //Implementation put_firstGood_int + //******************************* + + /*! \brief Method setting an integer representing the first good bin specified in the header for a specified histogram + * + * return: + * - 0 on success + * - -1 if histo index is out of range + * + * \param i index of the histogram + * \param j first good bin value + */ + + int MuSR_td_PSI_bin::put_firstGood_int(int i, int j) + { + if ((i < 0) || (i >= MAXHISTO)) + return -1; + + first_good[i] = j; + + return 0; + } //******************************* //Implementation get_firstGood_vector @@ -2981,36 +3697,14 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ vector MuSR_td_PSI_bin::get_firstGood_vector() - { - vector firstGood(number_histo) ; + { + vector firstGood(number_histo); - for ( int i = 0 ; i < number_histo ; i++ ) - firstGood[i] = int(first_good[i]) ; - - return firstGood ; - } - - -//******************************* -//Implementation put_firstGood_int -//******************************* - -/*! \brief Method to modify the first good bin (value \) of the histogram \ - * - * returns -1 if the histogram specified was invalid - */ - - int MuSR_td_PSI_bin::put_firstGood_int(int i, int j) - { - if ( i < 0 || i >= int(number_histo)) - return -1 ; - else - { - first_good[i] = j ; - return 0; - } - } + for ( int i = 0; i < number_histo; i++ ) + firstGood[i] = int(first_good[i]); + return firstGood; + } //******************************* //Implementation get_lastGood_int @@ -3022,13 +3716,12 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ int MuSR_td_PSI_bin::get_lastGood_int(int i) - { - if ( i < 0 || i >= int(number_histo)) - return -1 ; - else - return int(last_good[i]) ; - } - + { + if ( i < 0 || i >= int(number_histo)) + return -1; + else + return int(last_good[i]); + } //******************************* //Implementation get_lastGood_vector @@ -3038,15 +3731,14 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ vector MuSR_td_PSI_bin::get_lastGood_vector() - { - vector lastGood(number_histo) ; + { + vector lastGood(number_histo); - for ( int i = 0 ; i < number_histo ; i++ ) - lastGood[i] = int(last_good[i]) ; - - return lastGood ; - } + for ( int i = 0; i < number_histo; i++ ) + lastGood[i] = int(last_good[i]); + return lastGood; + } //******************************* //Implementation get_max_lastGoog_int @@ -3056,18 +3748,17 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ int MuSR_td_PSI_bin::get_max_lastGood_int() - { - int max_lastGood = 0 ; + { + int max_lastGood = 0; - for (int i = 0 ; i < int(number_histo) ; i++) - { - if (int(last_good[i]) > max_lastGood) - max_lastGood = int(last_good[i]) ; - } - - return max_lastGood ; - } + for (int i = 0; i < int(number_histo); i++) + { + if (int(last_good[i]) > max_lastGood) + max_lastGood = int(last_good[i]); + } + return max_lastGood; + } //******************************* //Implementation get_max_2_lastGood_int @@ -3079,20 +3770,19 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ int MuSR_td_PSI_bin::get_max_2_lastGood_int(int k, int j) - { - if (( k < 0 || k >= int(number_histo)) || ( j < 0 || j >= int(number_histo))) - return -1 ; - else - { - int max_lastGood = int(last_good[j]) ; + { + if (( k < 0 || k >= int(number_histo)) || ( j < 0 || j >= int(number_histo))) + return -1; + else + { + int max_lastGood = int(last_good[j]); - if (int(last_good[k]) > max_lastGood) - max_lastGood = int(last_good[k]) ; - - return max_lastGood ; - } - } + if (int(last_good[k]) > max_lastGood) + max_lastGood = int(last_good[k]); + return max_lastGood; + } + } //******************************* //Implementation get_min_lastGood_int @@ -3102,18 +3792,17 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ int MuSR_td_PSI_bin::get_min_lastGood_int() - { - int min_lastGood = int(last_good[0]) ; + { + int min_lastGood = int(last_good[0]); - for (int i = 1 ; i < int(number_histo) ; i++) - { - if (int(last_good[i]) < min_lastGood) - min_lastGood = int(last_good[i]) ; - } - - return min_lastGood ; - } + for (int i = 1; i < int(number_histo); i++) + { + if (int(last_good[i]) < min_lastGood) + min_lastGood = int(last_good[i]); + } + return min_lastGood; + } //******************************* //Implementation get_min_2_lastGood_int @@ -3125,20 +3814,19 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ int MuSR_td_PSI_bin::get_min_2_lastGood_int(int k, int j) - { - if (( k < 0 || k >= int(number_histo)) || ( j < 0 || j >= int(number_histo))) - return -1 ; - else - { - int min_lastGood = int(last_good[j]) ; + { + if (( k < 0 || k >= int(number_histo)) || ( j < 0 || j >= int(number_histo))) + return -1; + else + { + int min_lastGood = int(last_good[j]); - if (int(last_good[k]) < min_lastGood) - min_lastGood = int(last_good[k]) ; - - return min_lastGood ; - } - } + if (int(last_good[k]) < min_lastGood) + min_lastGood = int(last_good[k]); + return min_lastGood; + } + } //******************************* //Implementation put_lastGood_int @@ -3150,15 +3838,14 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ int MuSR_td_PSI_bin::put_lastGood_int(int i, int j) - { - if ( i < 0 || i >= int(number_histo)) - return -1 ; - else - { - last_good[i] = j ; - return 0; - } - } + { + if ((i < 0) || (i >= number_histo)) + return -1; + + last_good[i] = j; + + return 0; + } //******************************* @@ -3169,9 +3856,9 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ int MuSR_td_PSI_bin::get_runNumber_int() - { - return int(num_run) ; - } + { + return int(num_run); + } //******************************* @@ -3184,13 +3871,14 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ int MuSR_td_PSI_bin::put_runNumber_int(int i) - { - if (i <= 0 ) - return -1 ; - else - num_run = i ; - return 0 ; - } + { + if (i <= 0 ) + return -1; + + num_run = i; + + return 0; + } //******************************* @@ -3201,14 +3889,36 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ string MuSR_td_PSI_bin::get_sample() - { - string strData ; + { + string strData; - strData = sample ; + strData = sample; - return strData ; - } + return strData; + } + //******************************* + //Implementation put_sample() + //******************************* + + /*! \brief Method setting a string containing the sample name + * + * return: + * - 0 on success + * - -1 if the provided sample string is too long (>= 11 char) + * + * \param sample string containing the sample information + */ + + int MuSR_td_PSI_bin::put_sample(string sampleStr) + { + if (sampleStr.size() >= 11) + return -1; + + strcpy(sample, sampleStr.c_str()); + + return 0; + } //******************************* //Implementation get_temp() @@ -3218,14 +3928,36 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ string MuSR_td_PSI_bin::get_temp() - { - string strData ; + { + string strData; - strData = temp ; + strData = temp; - return strData ; - } + return strData; + } + //******************************* + //Implementation put_temp() + //******************************* + + /*! \brief Method setting a string containing the sample temperature + * + * return: + * - 0 on success + * - -1 if the provided temperature string is too long (>= 11 char) + * + * \param tempStr string containing the sample information + */ + + int MuSR_td_PSI_bin::put_temp(string tempStr) + { + if (tempStr.size() >= 11) + return -1; + + strcpy(temp, tempStr.c_str()); + + return 0; + } //******************************* //Implementation get_orient() @@ -3235,14 +3967,36 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ string MuSR_td_PSI_bin::get_orient() - { - string strData ; + { + string strData; - strData = orient ; + strData = orient; - return strData ; - } + return strData; + } + //******************************* + //Implementation put_orient() + //******************************* + + /*! \brief Method setting a string containing the sample orientation + * + * return: + * - 0 on success + * - -1 if the provided orientation string is too long (>= 11 char) + * + * \param orientStr string containing the sample information + */ + + int MuSR_td_PSI_bin::put_orient(string orientStr) + { + if (orientStr.size() >= 11) + return -1; + + strcpy(orient, orientStr.c_str()); + + return 0; + } //******************************* //Implementation get_field() @@ -3252,14 +4006,75 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ string MuSR_td_PSI_bin::get_field() + { + string strData; + + strData = field; + + return strData; + } + + //******************************* + //Implementation put_field() + //******************************* + + /*! \brief Method setting a string containing the field + * + * return: + * - 0 on success + * - -1 if the provided field string is too long (>= 11 char) + * + * \param fieldStr string containing the field + */ + + int MuSR_td_PSI_bin::put_field(string fieldStr) + { + if (fieldStr.size() >= 11) + return -1; + + strcpy(field, fieldStr.c_str()); + + return 0; + } + + //******************************* + //Implementation get_setup() + //******************************* + + /*! \brief Method returning a string containing the setup + */ + + string MuSR_td_PSI_bin::get_setup() { - string strData ; + string strData; - strData = field ; + strData = setup; - return strData ; + return strData; } + //******************************* + //Implementation put_setup() + //******************************* + + /*! \brief Method setting a string containing the setup + * + * return: + * - 0 on success + * - -1 if the provided setup string is too long (>= 11 char) + * + * \param commentStr string containing the setup + */ + + int MuSR_td_PSI_bin::put_setup(string setupStr) + { + if (setupStr.size() >= 11) + return -1; + + strcpy(setup, setupStr.c_str()); + + return 0; + } //******************************* //Implementation get_comments() @@ -3269,14 +4084,33 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ string MuSR_td_PSI_bin::get_comment() - { - string strData ; + { + string strData; - strData = comment ; + strData = comment; - return strData ; - } + return strData; + } + //******************************* + //Implementation put_comments() + //******************************* + + /*! \brief Method setting a string containing the comment + * + * return: + * - 0 on success + * + * \param commentStr string containing the comment + */ + + int MuSR_td_PSI_bin::put_comment(string commentStr) + { + strncpy(comment, commentStr.c_str(), 62); + comment[62] = '\0'; + + return 0; + } //******************************* //Implementation get_nameHisto() @@ -3288,18 +4122,45 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ string MuSR_td_PSI_bin::get_nameHisto(int i) - { - string strData ; + { + string strData; - if (i < 0 || i >= int(number_histo)) - return NULL ; - else - { - strData = labels_histo[i] ; - return strData ; - } - } + if (i < 0 || i >= int(number_histo)) + return NULL; + else + { + strData = labels_histo[i]; + return strData; + } + } + //******************************* + //Implementation put_nameHisto() + //******************************* + + /*! \brief Method setting a string containing the name of the histogram \ + * + * returns: + * - 0 on success + * - -1 index i out of range + * - -2 histoName is too long + * + * \param histoName name of the histogram + * \param i index of the histogram + */ + + int MuSR_td_PSI_bin::put_nameHisto(string histoName, int i) + { + if ((i<0) || (i>=number_histo)) + return -1; + + if ((int)histoName.length() >= MAXLABELSIZE) + return -2; + + strcpy(labels_histo[i], histoName.c_str()); + + return 0; + } //******************************* //Implementation get_histoNames_vector() @@ -3309,19 +4170,47 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ vector MuSR_td_PSI_bin::get_histoNames_vector() - { - vector str_Vector ; + { + vector str_Vector; - string strData ; - for (int i = 0 ; i < number_histo ; i++) - { - strData = labels_histo[i] ; - str_Vector.push_back(strData) ; - } + string strData; + for (int i = 0; i < number_histo; i++) + { + strData = labels_histo[i]; + str_Vector.push_back(strData); + } - return str_Vector; - } + return str_Vector; + } + //******************************* + //Implementation put_histoNames_vector() + //******************************* + + /*! \brief Method setting a vector containing the names of all the histograms + * + * returns: + * - 0 on success + * - -1 size of vector larger than number of histograms + * - -2 length of label too large + * + * \param histoName name of the histogram + */ + + int MuSR_td_PSI_bin::put_histoNames_vector(vector &histoNames) + { + if ((int)histoNames.size() > number_histo) + return -1; + + for (unsigned int i=0; i= MAXLABELSIZE) + return -2; + else + strcpy(labels_histo[i], histoNames[i].c_str()); + } + + return 0; + } //******************************* //Implementation get_scalersNames_vector() @@ -3331,19 +4220,44 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ vector MuSR_td_PSI_bin::get_scalersNames_vector() - { - vector str_Vector ; + { + vector str_Vector; - string strData ; - for (int i = 0 ; i < number_scaler ; i++) - { - strData = labels_scalers[i] ; - str_Vector.push_back(strData) ; - } + string strData; + for (int i = 0; i < number_scaler; i++) + { + strData = labels_scalers[i]; + str_Vector.push_back(strData); + } - return str_Vector; - } + return str_Vector; + } + //******************************* + //Implementation put_scalersNames_vector() + //******************************* + + /*! \brief Method setting a vector of strings containing the names of the scalers + * + * return: + * - 0 on success + * - -1 of scalersName is too long (>MAXSCALER) + * + * \param scalersName scaler names + */ + + int MuSR_td_PSI_bin::put_scalersNames_vector(vector scalersName) + { + if ((int)scalersName.size() > MAXSCALER) + return -1; + + for (unsigned int i=0; i MAXTEMPER)) + return -1; + + number_temper = noOfTemps; + + return 0; + } //******************************* //Implementation get_temperatures_vector() @@ -3365,16 +4302,40 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ vector MuSR_td_PSI_bin::get_temperatures_vector() - { - vector dbl_Temper ; + { + vector dbl_Temper; - for (int i = 0 ; i < number_temper ; i++) - { - dbl_Temper.push_back(double(temper[i])) ; - } + for (int i = 0; i < number_temper; i++) + { + dbl_Temper.push_back(double(temper[i])); + } - return dbl_Temper; - } + return dbl_Temper; + } + + //******************************* + //Implementation put_temperatures_vector() + //******************************* + + /*! \brief Method setting a vector of doubles containing monitored values (usually temperatures) + * + * return: + * - 0 on success + * - -1 if the number of tempVals elements is out of range + * + * \param tempVals vector containing the monitored values + */ + + int MuSR_td_PSI_bin::put_temperatures_vector(vector &tempVals) + { + if ((int)tempVals.size() > MAXTEMPER) + return -1; + + for (unsigned int i=0; i MuSR_td_PSI_bin::get_devTemperatures_vector() - { - vector dbl_devTemper ; + { + vector dbl_devTemper; - for (int i = 0 ; i < number_temper ; i++) - { - dbl_devTemper.push_back(double(temp_deviation[i])) ; - } + for (int i = 0; i < number_temper; i++) + { + dbl_devTemper.push_back(double(temp_deviation[i])); + } - return dbl_devTemper; - } + return dbl_devTemper; + } + + //******************************* + //Implementation put_devTemperatures_vector() + //******************************* + + /*! \brief Method setting a vector of doubles containing standard deviations of the monitored values (usually temperatures) + * + * return: + * - 0 on success + * - -1 if the number of devTempVals elements is out of range + * + * \param devTempVals vector containing standard deviations of the monitored values + */ + + int MuSR_td_PSI_bin::put_devTemperatures_vector(vector &devTempVals) + { + if ((int)devTempVals.size() > MAXTEMPER) + return -1; + + for (unsigned int i=0; i MuSR_td_PSI_bin::get_timeStart_vector() - { - vector timeStart(2) ; + { + vector timeStart(2); - timeStart[0] = date_start ; - timeStart[1] = time_start ; + timeStart[0] = date_start; + timeStart[1] = time_start; - return timeStart ; - } + return timeStart; + } + //******************************* + //Implementation put_timeStart_vector() + //******************************* + + /*! \brief Method setting a vector of strings containing 1) the date when the run was + * started and 2) the time when the run was started + * + * return: + * - 0 on success + * - -1 timeStart vector has too many elements + * - -2 if date is too long + * - -3 if time is too long + * + * \param timeStart vector where [0] contains the date, [1] the time string + */ + + int MuSR_td_PSI_bin::put_timeStart_vector(vector timeStart) + { + if (timeStart.size() != 2) + return -1; + + // date + if (timeStart[0].length() > 9) + return -2; + + // time + if (timeStart[1].length() > 8) + return -3; + + strcpy(date_start, timeStart[0].c_str()); + strcpy(time_start, timeStart[1].c_str()); + + return 0; + } //******************************* //Implementation get_timeStop_vector() @@ -3424,15 +4443,49 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ vector MuSR_td_PSI_bin::get_timeStop_vector() + { + vector timeStop(2); - { - vector timeStop(2) ; + timeStop[0] = date_stop; + timeStop[1] = time_stop; - timeStop[0] = date_stop ; - timeStop[1] = time_stop ; + return timeStop; + } - return timeStop ; - } + //******************************* + //Implementation put_timeStop_vector() + //******************************* + + /*! \brief Method setting a vector of strings containing 1) the date when the run was + * started and 2) the time when the run was stopped + * + * return: + * - 0 on success + * - -1 timeStart vector has too many elements + * - -2 if date is too long + * - -3 if time is too long + * + * \param timeStop vector where [0] contains the date, [1] the time string + */ + + int MuSR_td_PSI_bin::put_timeStop_vector(vector timeStop) + { + if (timeStop.size() != 2) + return -1; + + // date + if (timeStop[0].length() > 9) + return -2; + + // time + if (timeStop[1].length() > 8) + return -3; + + strcpy(date_stop, timeStop[0].c_str()); + strcpy(time_stop, timeStop[1].c_str()); + + return 0; + } //******************************* //Implementation Clear() @@ -3442,84 +4495,88 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ int MuSR_td_PSI_bin::Clear() - - { - int i,j; + { + int i,j; // NIY maybe flag when histo should not be released - // free private histograms - if (histo != NULL) - { - for (i=0; i < number_histo; i++) - if (*(histo+i) != NULL) - { - delete[] *(histo+i); - *(histo+i) = NULL; - } - delete [] histo; - histo = NULL; - } + // free private histograms + if (histo != NULL) + { + for (i=0; i < number_histo; i++) + if (*(histo+i) != NULL) + { + delete[] *(histo+i); + *(histo+i) = NULL; + } + delete [] histo; + histo = NULL; + } - // free public vector - histos_vector.clear(); + // free public vector + histos_vector.clear(); - // init other member variables - filename = "?"; - readingok = false; - readstatus = ""; + // init other member variables + filename = "?"; + readingok = false; + writingok = false; + consistencyOk = false; + readstatus = ""; + writestatus = ""; + consistencyStatus = ""; - strcpy(format_id,"??"); + strcpy(format_id,"??"); - num_run = 0; - //01234567890 - strcpy(sample, " "); - strcpy(temp, " "); - strcpy(field, " "); - strcpy(orient, " "); - strcpy(comment, " "); - strcpy(date_start," "); - strcpy(time_start," "); - strcpy(date_stop, " "); - strcpy(time_stop, " "); + num_run = 0; + //01234567890 + strcpy(sample, " "); + strcpy(temp, " "); + strcpy(field, " "); + strcpy(orient, " "); + strcpy(setup, " "); + strcpy(comment, " "); + strcpy(date_start," "); + strcpy(time_start," "); + strcpy(date_stop, " "); + strcpy(time_stop, " "); - bin_width = 0.f; - number_histo = 0; - length_histo = 0; - total_events = 0; - default_binning = 1; + bin_width = 0.f; + number_histo = 0; + length_histo = 0; + total_events = 0; + default_binning = 1; - for (i=0; i < MAXHISTO; i++) - { - for (j=0; j < MAXLABELSIZE-1; j++) - labels_histo[i][j] = ' '; - labels_histo[i][MAXLABELSIZE-1] = '\0'; - events_per_histo[i] = 0; - real_t0[i] = 0.f; - integer_t0[i] = 0; - first_good[i] = 0; - last_good[i] = 0; - } + for (i=0; i < MAXHISTO; i++) + { + for (j=0; j < MAXLABELSIZE-1; j++) + labels_histo[i][j] = ' '; + labels_histo[i][MAXLABELSIZE-1] = '\0'; + events_per_histo[i] = 0; + real_t0[i] = 0.f; + integer_t0[i] = 0; + first_good[i] = 0; + last_good[i] = 0; + } - number_scaler = 0; - for (i=0; i < MAXSCALER; i++) - { - for (j=0; j < MAXLABELSIZE-1; j++) - labels_scalers[i][j] = ' '; - labels_scalers[i][MAXLABELSIZE-1] = '\0'; + number_scaler = 0; + for (i=0; i < MAXSCALER; i++) + { + for (j=0; j < MAXLABELSIZE-1; j++) + labels_scalers[i][j] = ' '; + labels_scalers[i][MAXLABELSIZE-1] = '\0'; - scalers[i] = 0; - } + scalers[i] = 0; + } - number_temper = 0; - for (i=0; i < MAXTEMPER; i++) - { - temper[i] = 0.f; - temp_deviation[i] = 0.f; - } + number_temper = 0; + for (i=0; i < MAXTEMPER; i++) + { + temper[i] = 0.f; + temp_deviation[i] = 0.f; + } - return 0; - } + return 0; + } //******************************* //Implementation Show() @@ -3528,73 +4585,71 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , */ int MuSR_td_PSI_bin::Show() const + { + cout << "Filename is " << filename << endl; + if (readingok) { + int i; - { - cout << "Filename is " << filename << endl; - if (readingok) { - int i; + cout << "Format Identifier is " << format_id << endl; - cout << "Format Identifier is " << format_id << endl; + cout << "Run number is " << num_run << endl; + cout << "Sample is " << sample << endl; + cout << "Temperature is " << temp << endl; + cout << "Field is " << field << endl; + cout << "Orientation is " << orient << endl; + cout << "Comment is " << comment << endl; - cout << "Run number is " << num_run << endl; - cout << "Sample is " << sample << endl; - cout << "Temperature is " << temp << endl; - cout << "Field is " << field << endl; - cout << "Orientation is " << orient << endl; - cout << "Comment is " << comment << endl; + cout << "Start Date is " << date_start << endl; + cout << "Start Time is " << time_start << endl; - cout << "Start Date is " << date_start << endl; - cout << "Start Time is " << time_start << endl; + cout << "End Date is " << date_stop << endl; + cout << "End Time is " << time_stop << endl; - cout << "End Date is " << date_stop << endl; - cout << "End Time is " << time_stop << endl; + cout << "Bin width is " << bin_width << " [usec]" << endl; + cout << "Number of histograms is " << number_histo << endl; + cout << "Histogram length is " << length_histo << endl; + cout << "Default binning is " << default_binning << endl; + cout << "Total number of events is " << total_events << endl; - cout << "Bin width is " << bin_width << " [usec]" << endl; - cout << "Number of histograms is " << number_histo << endl; - cout << "Histogram length is " << length_histo << endl; - cout << "Default binning is " << default_binning << endl; - cout << "Total number of events is " << total_events << endl; + for (i=0; i < number_histo; i++) { + cout << "Histogram " << i << " Name is >" << labels_histo[i] + << "< Events per histogram is " << events_per_histo[i] << endl; + cout << " real t0 is " << real_t0[i] << endl; + cout << " t0 is " << integer_t0[i] << endl; + cout << " first good bin is " << first_good[i] << endl; + cout << " last good bin is " << last_good[i] << endl; + } - for (i=0; i < number_histo; i++) { - cout << "Histogram " << i << " Name is >" << labels_histo[i] - << "< Events per histogram is " << events_per_histo[i] << endl; - cout << " real t0 is " << real_t0[i] << endl; - cout << " t0 is " << integer_t0[i] << endl; - cout << " first good bin is " << first_good[i] << endl; - cout << " last good bin is " << last_good[i] << endl; - } + cout << "Number of scalers is " << number_scaler << endl; + for (i=0; i < number_scaler; i++) { + cout << "Scaler " << i << " Name is >" << labels_scalers[i] + << "< Value is " << scalers[i] << endl; + } - cout << "Number of scalers is " << number_scaler << endl; - for (i=0; i < number_scaler; i++) { - cout << "Scaler " << i << " Name is >" << labels_scalers[i] - << "< Value is " << scalers[i] << endl; - } + cout << "Number of temperatures is " << number_temper << endl; + for (i=0; i < number_temper; i++) { + cout << "Temperature " << i << " is " << temper[i] + << " Deviation is " << temp_deviation[i] << endl; + } - cout << "Number of temperatures is " << number_temper << endl; - for (i=0; i < number_temper; i++) { - cout << "Temperature " << i << " is " << temper[i] - << " Deviation is " << temp_deviation[i] << endl; - } - - } else { - cout << readstatus << endl; - } + } else { + cout << readstatus << endl; + } return 0; - } - + } //******************************* //Implementation tmax //******************************* int MuSR_td_PSI_bin::tmax(int x, int y) - { - if (x >= y) - { - return x ; - } - return y ; - } + { + if (x >= y) + { + return x; + } + return y; + } //******************************* @@ -3602,13 +4657,13 @@ double * MuSR_td_PSI_bin::get_histo_goodBins_minus_bckgrd_array(int histo_num , //******************************* int MuSR_td_PSI_bin::tmin(int x, int y) - { - if (x >= y) - { - return y ; - } - return x ; - } + { + if (x >= y) + { + return y; + } + return x; + } /************************************************************************************ * EOF MuSR_td_PSI_bin.cpp * diff --git a/src/external/MuSR_software/Class_MuSR_PSI/MuSR_td_PSI_bin.h b/src/external/MuSR_software/Class_MuSR_PSI/MuSR_td_PSI_bin.h index ba0007f8..bb94dbe9 100644 --- a/src/external/MuSR_software/Class_MuSR_PSI/MuSR_td_PSI_bin.h +++ b/src/external/MuSR_software/Class_MuSR_PSI/MuSR_td_PSI_bin.h @@ -40,11 +40,13 @@ using namespace std ; /* ------------------------------------------------------------------ */ const int MAXHISTO = 32; // maximum number of histos to process/store -const int MAXSCALER = 32; // maximum number of scalers to proces/store +const int MAXSCALER = 32; // maximum number of scalers to process/store const int MAXTEMPER = 4; // maximum number of average temperatures const int MAXLABELSIZE = 12; // maximum size of labels +const int MAXREC = 4096; // maximum allowed data record size + /* ------------------------------------------------------------------ */ class MuSR_td_PSI_bin { @@ -58,48 +60,53 @@ class MuSR_td_PSI_bin { string filename; string readstatus; + string writestatus; + string consistencyStatus; bool readingok; + bool writingok; + bool consistencyOk; - char format_id[3] ; + char format_id[3]; - int num_run ; + int num_run; - char sample[11] ; - char temp[11] ; - char field[11] ; - char orient[11] ; - char comment[63] ; + char sample[11]; + char temp[11]; + char field[11]; + char orient[11]; + char setup[11]; + char comment[63]; - char date_start[10] ; - char date_stop[10] ; - char time_start[9] ; - char time_stop[9] ; + char date_start[10]; + char date_stop[10]; + char time_start[9]; + char time_stop[9]; - float bin_width ; + float bin_width; - int number_histo ; - int length_histo ; - char labels_histo[MAXHISTO][MAXLABELSIZE] ; + int number_histo; + int length_histo; + char labels_histo[MAXHISTO][MAXLABELSIZE]; - int total_events ; - int events_per_histo[MAXHISTO] ; + int total_events; + int events_per_histo[MAXHISTO]; - int default_binning ; + int default_binning; - float real_t0[MAXHISTO] ; - int integer_t0[MAXHISTO] ; - int first_good[MAXHISTO] ; - int last_good[MAXHISTO] ; + float real_t0[MAXHISTO]; + int integer_t0[MAXHISTO]; + int first_good[MAXHISTO]; + int last_good[MAXHISTO]; - int number_scaler ; - int scalers[MAXSCALER] ; - char labels_scalers[MAXSCALER][MAXLABELSIZE] ; + int number_scaler; + int scalers[MAXSCALER]; + char labels_scalers[MAXSCALER][MAXLABELSIZE]; - int number_temper ; - float temper[MAXTEMPER] ; - float temp_deviation[MAXTEMPER] ; + int number_temper; + float temper[MAXTEMPER]; + float temp_deviation[MAXTEMPER]; - int **histo ; + int **histo; public: @@ -118,12 +125,19 @@ class MuSR_td_PSI_bin { public: int read(const char* fileName); // generic read + int write(const char *fileName); // generic write int readbin(const char* fileName); // read MuSR PSI bin format + int writebin(const char *fileName); // write MuSR PSI bin format int readmdu(const char* fileName); // read MuSR mdu format + int writemdu(const char* fileName); // write MuSR mdu format bool readingOK() const; + bool writingOK() const; + bool CheckDataConsistency(int tag=0); // tag: 0=reasonable, 1=strict string ReadStatus() const; + string WriteStatus() const; + string ConsistencyStatus() const; string Filename() const; int Show() const; @@ -133,43 +147,40 @@ class MuSR_td_PSI_bin { double get_histo(int histo_num, int j); int *get_histo_array_int(int histo_num); - double *get_histo_array(int histo_num , int binning) ; - vector get_histo_vector(int histo_num , int binning) ; - vector get_histo_vector_no0(int histo_num , int binning) ; + double *get_histo_array(int histo_num, int binning); + int put_histo_array_int(vector< vector > histo, int tag = 0); + vector get_histo_vector(int histo_num, int binning); + vector get_histo_vector_no0(int histo_num, int binning); - double *get_histo_fromt0_array(int histo_num , - int binning , - int offset = 0) ; + double *get_histo_fromt0_array(int histo_num, int binning, int offset = 0); - vector get_histo_fromt0_vector(int histo_num , - int binning , - int offset = 0) ; + vector get_histo_fromt0_vector(int histo_num, int binning, int offset = 0); - double *get_histo_goodBins_array(int histo_num , int binning) ; + double *get_histo_goodBins_array(int histo_num, int binning); - vector get_histo_goodBins_vector(int histo_num , int binning) ; + vector get_histo_goodBins_vector(int histo_num, int binning); - double *get_histo_fromt0_minus_bckgrd_array(int histo_num , - int lower_bckgdr , - int higher_bckgdr , - int binning , - int offset = 0) ; + double *get_histo_fromt0_minus_bckgrd_array(int histo_num, + int lower_bckgdr, + int higher_bckgdr, + int binning, + int offset = 0); - vector get_histo_fromt0_minus_bckgrd_vector(int histo_num , - int lower_bckgdr , - int higher_bckgdr , - int binning , - int offset = 0) ; + vector get_histo_fromt0_minus_bckgrd_vector(int histo_num, + int lower_bckgdr, + int higher_bckgdr, + int binning, + int offset = 0); - double *get_histo_goodBins_minus_bckgrd_array(int histo_num , - int lower_bckgrd , - int higher_bckgrd , - int binning) ; + double *get_histo_goodBins_minus_bckgrd_array(int histo_num, + int lower_bckgrd, + int higher_bckgrd, + int binning); - vector get_histo_goodBins_minus_bckgrd_vector(int histo_num , - int lower_bckgrd , - int higher_bckgrd , - int binning) ; + vector get_histo_goodBins_minus_bckgrd_vector(int histo_num, + int lower_bckgrd, + int higher_bckgrd, + int binning); double *get_asymmetry_array(int histo_num_plus, int histo_num_minus, @@ -178,88 +189,95 @@ class MuSR_td_PSI_bin { int lower_bckgrd_plus, int higher_bckgrd_plus, int lower_bckgrd_minus, - int higher_bckgrd_minus , + int higher_bckgrd_minus, int offset = 0, - double y_offset = 0.) ; + double y_offset = 0.); - vector get_asymmetry_vector(int histo_num_plus , - int histo_num_minus , - double alpha_param , - int binning , - int lower_bckgrd_plus , - int higher_bckgrd_plus , - int lower_bckgrd_minus , - int higher_bckgrd_minus , - int offset = 0 , - double y_offset = 0.) ; + vector get_asymmetry_vector(int histo_num_plus, + int histo_num_minus, + double alpha_param, + int binning, + int lower_bckgrd_plus, + int higher_bckgrd_plus, + int lower_bckgrd_minus, + int higher_bckgrd_minus, + int offset = 0, + double y_offset = 0.); - double *get_error_asymmetry_array(int histo_num_plus , - int histo_num_minus , - double alpha_param , - int binning , - int lower_bckgrd_plus , - int higher_bckgrd_plus , - int lower_bckgrd_minus , - int higher_bckgrd_minus , - int offset = 0) ; + double *get_error_asymmetry_array(int histo_num_plus, + int histo_num_minus, + double alpha_param, + int binning, + int lower_bckgrd_plus, + int higher_bckgrd_plus, + int lower_bckgrd_minus, + int higher_bckgrd_minus, + int offset = 0); - vector get_error_asymmetry_vector(int histo_num_plus , - int histo_num_minus , - double alpha_param , - int binning , - int lower_bckgrd_plus , - int higher_bckgrd_plus , - int lower_bckgrd_minus , - int higher_bckgrd_minus , - int offset = 0) ; + vector get_error_asymmetry_vector(int histo_num_plus, + int histo_num_minus, + double alpha_param, + int binning, + int lower_bckgrd_plus, + int higher_bckgrd_plus, + int lower_bckgrd_minus, + int higher_bckgrd_minus, + int offset = 0); - double *get_asymmetry_goodBins_array(int histo_num_plus , - int histo_num_minus , - double alpha_param , - int binning , - int lower_bckgrd_plus , - int higher_bckgrd_plus , - int lower_bckgrd_minus , - int higher_bckgrd_minus) ; + double *get_asymmetry_goodBins_array(int histo_num_plus, + int histo_num_minus, + double alpha_param, + int binning, + int lower_bckgrd_plus, + int higher_bckgrd_plus, + int lower_bckgrd_minus, + int higher_bckgrd_minus); - vector get_asymmetry_goodBins_vector(int histo_num_plus , - int histo_num_minus , - double alpha_param , - int binning , - int lower_bckgrd_plus , - int higher_bckgrd_plus , - int lower_bckgrd_minus , - int higher_bckgrd_minus) ; + vector get_asymmetry_goodBins_vector(int histo_num_plus, + int histo_num_minus, + double alpha_param, + int binning, + int lower_bckgrd_plus, + int higher_bckgrd_plus, + int lower_bckgrd_minus, + int higher_bckgrd_minus); - double *get_error_asymmetry_goodBins_array(int histo_num_plus , - int histo_num_minus , - double alpha_param , - int binning , - int lower_bckgrd_plus , - int higher_bckgrd_plus , - int lower_bckgrd_minus , - int higher_bckgrd_minus) ; + double *get_error_asymmetry_goodBins_array(int histo_num_plus, + int histo_num_minus, + double alpha_param, + int binning, + int lower_bckgrd_plus, + int higher_bckgrd_plus, + int lower_bckgrd_minus, + int higher_bckgrd_minus); - vector get_error_asymmetry_goodBins_vector(int histo_num_plus , - int histo_num_minus , - double alpha_param , - int binning , - int lower_bckgrd_plus , - int higher_bckgrd_plus , - int lower_bckgrd_minus , - int higher_bckgrd_minus) ; + vector get_error_asymmetry_goodBins_vector(int histo_num_plus, + int histo_num_minus, + double alpha_param, + int binning, + int lower_bckgrd_plus, + int higher_bckgrd_plus, + int lower_bckgrd_minus, + int higher_bckgrd_minus); double get_binWidth_ps(); + void put_binWidth_ps(double binWidth); double get_binWidth_ns(); + void put_binWidth_ns(double binWidth); double get_binWidth_us(); + void put_binWidth_us(double binWidth); int get_histoLength_bin(); + void put_histoLength_bin(int val) { length_histo = val; } int get_numberHisto_int(); + void put_numberHisto_int(int val) { number_histo = val; } - string get_nameHisto(int i) ; + string get_nameHisto(int i); + int put_nameHisto(string histoName, int i); vector get_histoNames_vector(); + int put_histoNames_vector(vector &histoNames); long get_eventsHisto_long(int i); vector get_eventsHisto_vector(); @@ -267,52 +285,69 @@ class MuSR_td_PSI_bin { long get_totalEvents_long(); int get_numberScaler_int(); - vector get_scalers_vector() ; - vector get_scalersNames_vector() ; + int put_numberScaler_int(int val); + vector get_scalers_vector(); + int put_scalers_vector(vector scalerData); + vector get_scalersNames_vector(); + int put_scalersNames_vector(vector scalersName); - int get_default_binning() ; - int get_t0_int(int i) ; - vector get_t0_vector() ; - double get_t0_double(int i) ; + int get_default_binning(); + int get_t0_int(int i); + int put_t0_int(int histoNo, int t0); + vector get_t0_vector(); + int put_t0_vector(vector &t0Data); + double get_t0_double(int i); - int get_max_t0_int () ; - int get_max_2_t0_int (int k, int j) ; - int get_min_t0_int () ; - int get_min_2_t0_int (int k, int j) ; + int get_max_t0_int (); + int get_max_2_t0_int (int k, int j); + int get_min_t0_int (); + int get_min_2_t0_int (int k, int j); - int get_firstGood_int(int i) ; - vector get_firstGood_vector() ; - int put_firstGood_int(int i, int j) ; + int get_firstGood_int(int i); + vector get_firstGood_vector(); + int put_firstGood_int(int i, int j); - int get_lastGood_int(int i) ; - vector get_lastGood_vector() ; - int put_lastGood_int(int i, int j) ; + int get_lastGood_int(int i); + vector get_lastGood_vector(); + int put_lastGood_int(int i, int j); - int get_max_lastGood_int () ; - int get_max_2_lastGood_int (int k, int j) ; - int get_min_lastGood_int () ; - int get_min_2_lastGood_int (int k, int j) ; + int get_max_lastGood_int (); + int get_max_2_lastGood_int (int k, int j); + int get_min_lastGood_int (); + int get_min_2_lastGood_int (int k, int j); - int get_runNumber_int() ; - int put_runNumber_int(int i) ; + int get_runNumber_int(); + int put_runNumber_int(int i); - string get_sample() ; - string get_field() ; - string get_orient() ; - string get_temp() ; - string get_comment() ; + string get_sample(); + int put_sample(string sample); + string get_field(); + int put_field(string field); + string get_orient(); + int put_orient(string orientation); + string get_temp(); + int put_temp(string temp); + string get_setup(); + int put_setup(string setup); + string get_comment(); + int put_comment(string comment); - vector get_timeStart_vector() ; - vector get_timeStop_vector() ; + vector get_timeStart_vector(); + int put_timeStart_vector(vector timeStart); + vector get_timeStop_vector(); + int put_timeStop_vector(vector timeStop); - int get_numberTemperature_int() ; - vector get_temperatures_vector() ; - vector get_devTemperatures_vector() ; + int get_numberTemperature_int(); + int put_numberTemperature_int(int noOfTemps); + vector get_temperatures_vector(); + int put_temperatures_vector(vector &temps); + vector get_devTemperatures_vector(); + int put_devTemperatures_vector(vector &devTemps); private: - int tmax(int x, int y) ; - int tmin(int x, int y) ; + int tmax(int x, int y); + int tmin(int x, int y); } ; #endif diff --git a/src/include/PMusr.h b/src/include/PMusr.h index 524f36cb..ba615df1 100644 --- a/src/include/PMusr.h +++ b/src/include/PMusr.h @@ -279,6 +279,14 @@ class PRawRunData { virtual const Int_t GetRunNumber() { return fRunNumber; } virtual const TString* GetRunTitle() { return &fRunTitle; } virtual const TString* GetSetup() { return &fSetup; } + virtual const TString* GetStartTime() { return &fStartTime; } + virtual const TString* GetStartDate() { return &fStartDate; } + virtual const time_t GetStartDateTime() { return fStartDateTimeSec; } + virtual const TString* GetStopTime() { return &fStopTime; } + virtual const TString* GetStopDate() { return &fStopDate; } + virtual const time_t GetStopDateTime() { return fStopDateTimeSec; } + virtual const TString* GetSample() { return &fSample; } + virtual const TString* GetOrientation() { return &fOrientation; } virtual const Double_t GetField() { return fField; } virtual const UInt_t GetNoOfTemperatures() { return fTemp.size(); } virtual const PDoublePairVector* GetTemperature() const { return &fTemp; } @@ -303,7 +311,15 @@ class PRawRunData { virtual void SetRunNumber(const Int_t &val) { fRunNumber = val; } virtual void SetRunTitle(const TString str) { fRunTitle = str; } virtual void SetSetup(const TString str) { fSetup = str; } + virtual void SetStartTime(const TString str) { fStartTime = str; } + virtual void SetStartDate(const TString str) { fStartDate = str; } + virtual void SetStartDateTime(const time_t val) { fStartDateTimeSec = val; } + virtual void SetStopTime(const TString str) { fStopTime = str; } + virtual void SetStopDate(const TString str) { fStopDate = str; } + virtual void SetStopDateTime(const time_t val) { fStopDateTimeSec = val; } virtual void SetField(const Double_t dval) { fField = dval; } + virtual void SetSample(const TString str) { fSample = str; } + virtual void SetOrientation(const TString str) { fOrientation = str; } virtual void ClearTemperature() { fTemp.clear(); } virtual void SetTemperature(const UInt_t idx, const Double_t temp, const Double_t errTemp); virtual void SetTempError(const UInt_t idx, const Double_t errTemp); @@ -326,6 +342,14 @@ class PRawRunData { Int_t fRunNumber; ///< run number TString fRunTitle; ///< run title TString fSetup; ///< description of the setup of this run + TString fStartTime; ///< start time of the run + TString fStartDate; ///< start date of the run + time_t fStartDateTimeSec; ///< start run given as time_t object + TString fStopTime; ///< stop time of the run + TString fStopDate; ///< stop date of the run + time_t fStopDateTimeSec; ///< stop run given as time_t object + TString fSample; ///< description of the sample + TString fOrientation; ///< description of the orientation Double_t fField; ///< magnetic field value PDoublePairVector fTemp; ///< measured temperatures and standard deviations during the run Double_t fEnergy; ///< implantation energy of the muon diff --git a/src/include/PRunDataHandler.h b/src/include/PRunDataHandler.h index 38ccadb6..ee88ba28 100644 --- a/src/include/PRunDataHandler.h +++ b/src/include/PRunDataHandler.h @@ -82,7 +82,6 @@ class PRunDataHandler virtual Bool_t WriteNexusFile(TString fln=""); virtual Bool_t WriteWkmFile(TString fln=""); virtual Bool_t WritePsiBinFile(TString fln=""); - virtual Bool_t WritePsiMduFile(TString fln=""); virtual Bool_t WriteMudFile(TString fln=""); virtual Bool_t WriteAsciiFile(TString fln=""); @@ -93,6 +92,7 @@ class PRunDataHandler virtual Int_t GetDataTagIndex(TString &str, const PStringVector* fLabels); virtual TString FileNameFromTemplate(TString &fileNameTemplate, Int_t run, TString &year, Bool_t &ok); + virtual TString GetMonth(Int_t month); }; #endif // _PRUNDATAHANDLER_H_ diff --git a/src/tests/CheckMusrfitInstall/ASlibs/test-nonlocal.msr b/src/tests/CheckMusrfitInstall/ASlibs/test-nonlocal.msr index 04664b73..bb71a9ed 100644 --- a/src/tests/CheckMusrfitInstall/ASlibs/test-nonlocal.msr +++ b/src/tests/CheckMusrfitInstall/ASlibs/test-nonlocal.msr @@ -2,24 +2,24 @@ Sn-210042 B=~48(G)/1.50(A), T=3.31(K), Tr=18.02(kV), Sa=-4.70(kV), En=21.97(keV) ############################################################### FITPARAMETER # Nr. Name Value Step Pos_Error Boundaries - 1 one 1 0 none - 2 zero 0 0 none - 3 Asy 0.207938 0.00663241 none 0 0.33 - 4 energy 22 0 none - 5 redTemp 0.8683 0 none - 6 thickness 5000 0 none - 7 ell 12000 0 none - 8 xi 94 0 none - 9 lambdaL 45.9973 1.19932 none - 10 Bext 47.11 0 none - 11 deadLayer 20.7296 0.054242 none 0 none - 12 RateSmear 0.327307 0.0222695 none - 13 N0_L 297.975 1.29352 none - 14 Bkg_L 24.582 0.122645 none - 15 Phase_L 31.2249 2.7339 none - 16 Alpha_LR 1.08146 0.00759253 none - 17 Bkg_R 27.5568 0.123419 none - 18 RelPhase_R 152.704 1.58788 none + 1 one 1.0 0.0 none + 2 zero 0.0 0.0 none + 3 Asy 0.2079 0.0066 none 0 0.33 + 4 energy 22.0 0.0 none + 5 redTemp 0.9 0.0 none + 6 thickness 5000.0 0.0 none + 7 ell 12000.0 0.0 none + 8 xi 94.0 0.0 none + 9 lambdaL 46.0 1.2 none + 10 Bext 47.1 0.0 none + 11 deadLayer 20.730 0.051 none 0 none + 12 RateSmear 0.327 0.022 none + 13 N0_L 298.0 1.3 none + 14 Bkg_L 24.58 0.12 none + 15 Phase_L 31.2 2.7 none + 16 Alpha_LR 1.0815 0.0076 none + 17 Bkg_R 27.56 0.12 none + 18 RelPhase_R 152.7 1.6 none ############################################################### THEORY @@ -42,7 +42,7 @@ map 1 2 0 0 0 0 0 0 0 0 forward 1 data 3289 65000 t0 3289 -fit 0.2 9.2 +fit 0.2 9.2 packing 250 RUN data/lem10_his_0825 MUE4 PSI ROOT-NPP (name beamline institute data-file-format) @@ -54,7 +54,7 @@ map 16 18 0 0 0 0 0 0 0 0 forward 3 data 3289 65000 t0 3289 -fit 0.2 9.2 +fit 0.2 9.2 packing 250 ############################################################### @@ -66,7 +66,7 @@ SAVE ############################################################### PLOT 0 (single histo plot) runs 1 2 -range 0.00 9.00 -0.30 0.30 +range 0 9 -0.3 0.3 view_packing 500 ############################################################### @@ -75,13 +75,13 @@ units Gauss # units either 'Gauss', 'MHz', or 'Mc/s' fourier_power 10 apodization STRONG # NONE, WEAK, MEDIUM, STRONG plot POWER # REAL, IMAG, REAL_AND_IMAG, POWER, PHASE -phase 8.50 +phase 8.5 #range_for_phase_correction 50.0 70.0 -range 0.00 200.00 +range 0.0 200.0 ############################################################### -STATISTIC --- 2010-11-07 16:46:59 - chisq = 417.37802066449291, NDF = 358, chisq/NDF = 1.1658603929175779 +STATISTIC --- 2011-02-06 14:54:40 + chisq = 417.37802066738652, NDF = 358, chisq/NDF = 1.1658603929256606 diff --git a/src/tests/CheckMusrfitInstall/test-asy-MUD.msr b/src/tests/CheckMusrfitInstall/test-asy-MUD.msr index 173dd1df..84dc7889 100644 --- a/src/tests/CheckMusrfitInstall/test-asy-MUD.msr +++ b/src/tests/CheckMusrfitInstall/test-asy-MUD.msr @@ -1,11 +1,11 @@ -Test asymmetry plot, MUD data file +MgB12H12 No2 ZF T=150 ############################################################### FITPARAMETER # Nr. Name Value Step Pos_Error Boundaries - 1 alpha 1 0 none 0 2 - 2 asy 0.175103 -0.000818844 0.00083464 0 0.33 - 3 rate 0.165184 -0.0015983 0.00159512 0 none - 4 beta 0.888935 -0.0159792 0.0161548 0.5 2 + 1 alpha 1.0 0.0 none 0 2 + 2 asy 0.17503 -0.00081 0.00083 0 0.33 + 3 rate 0.1649 -0.0016 0.0016 0 none + 4 beta 0.892 -0.016 0.016 0.5 2 ############################################################### THEORY @@ -20,12 +20,12 @@ RUN data/000100 XXXX TRIUMF MUD (name beamline institute data-file-format) fittype 2 (asymmetry fit) alpha 1 map 0 0 0 0 0 0 0 0 0 0 0 -forward 1 -backward 2 +forward 1 +backward 2 background 79 391 80 409 data 438 12785 436 12787 t0 432 431 -fit 0.00 8.00 +fit 0 8 packing 100 ############################################################### @@ -41,15 +41,15 @@ units Gauss # units either 'Gauss', 'MHz', or 'Mc/s' fourier_power 12 apodization NONE # NONE, WEAK, MEDIUM, STRONG plot POWER # REAL, IMAG, REAL_AND_IMAG, POWER, PHASE -phase 8.50 +phase 8 #range_for_phase_correction 50.0 70.0 -range 0.00 200.00 +range 0 200 ############################################################### PLOT 2 (asymmetry plot) runs 1 -range 0.00 8.00 0.00 0.25 +range 0 8 0 0.25 ############################################################### -STATISTIC --- 2010-01-08 14:45:37 - chisq = 132.25963, NDF = 99, chisq/NDF = 1.33595586 +STATISTIC --- 2011-02-06 15:03:19 + chisq = 133.92904274288378, NDF = 99, chisq/NDF = 1.3528186135644826 diff --git a/src/tests/CheckMusrfitInstall/test-histo-ROOT-NPP.msr b/src/tests/CheckMusrfitInstall/test-histo-ROOT-NPP.msr index 53252433..29299059 100644 --- a/src/tests/CheckMusrfitInstall/test-histo-ROOT-NPP.msr +++ b/src/tests/CheckMusrfitInstall/test-histo-ROOT-NPP.msr @@ -1,13 +1,13 @@ -Test single histogram plot (with life time correction), ROOT-NPP data file +LSCO (492-494) ZFC T=4.59(K),E=12.49(keV),B=~28(G)/0.89(A),Tr/Sa=15.02/1.63(kV),RAL-RAR=-0.08(kV),RAT-RAB=0.08(kV) ############################################################### FITPARAMETER # No Name Value Step Pos_Error Boundaries - 1 phase 15.1669 -1.62019 1.60987 0 100 - 2 freq 0.373322 -0.00240381 0.00239767 0 300 - 3 asym 0.11972 -0.0037553 0.00385333 0 0.3 - 4 rate 0.142788 -0.0169095 0.0175212 0 100 - 5 Norm_L 432.91 -0.718487 0.722474 - 6 BG_L 29.377 -0.102773 0.102472 + 1 phase 15.2 -1.6 1.6 0 100 + 2 freq 0.3733 -0.0024 0.0024 0 300 + 3 asym 0.1196 -0.0037 0.0039 0 0.3 + 4 rate 0.142 -0.017 0.018 0 100 + 5 Norm_L 432.87 -0.72 0.72 + 6 BG_L 29.38 -0.10 0.10 ############################################################### THEORY @@ -25,10 +25,10 @@ norm 5 backgr.fit 6 lifetimecorrection map 0 0 0 0 0 0 0 0 0 0 -forward 1 +forward 1 data 3419 66000 t0 3419 -fit 0.10 10.00 +fit 0.1 10 packing 250 ############################################################### @@ -40,8 +40,8 @@ SAVE ############################################################### PLOT 0 (single histo plot) runs 1 -range 0.00 8.00 -0.30 0.30 +range 0 8 -0.3 0.3 ############################################################### -STATISTIC --- 2010-01-08 14:45:50 - chisq = 247.622035, NDF = 197, chisq/NDF = 1.25696464 +STATISTIC --- 2011-02-06 14:52:54 + chisq = 248.83532814099809, NDF = 197, chisq/NDF = 1.2631234931015132