1407 f.GetObject(
"RunInfo", folder);
1409 TObject *obj = f.FindObjectAny(
"RunHeader");
1410 if (obj ==
nullptr) {
1411 std::cerr << std::endl <<
">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't neither obtain RunInfo (LEM),";
1412 std::cerr << std::endl <<
" nor RunHeader (MusrRoot) from " <<
fRunPathName.Data() << std::endl;
1416 if (!strcmp(obj->ClassName(),
"TFolder"))
1418 else if (!strcmp(obj->ClassName(),
"TDirectoryFile"))
1421 std::cerr << std::endl <<
"PRunDataHandler::ReadRootFile: **ERROR** RunHeader (MusrRoot) from '" <<
fRunPathName.Data() <<
"' is neither a TFolder nor a TDirectory. Found: '" << obj->ClassName() <<
"'" << std::endl;
1431 TLemRunHeader *runHeader =
dynamic_cast<TLemRunHeader*
>(folder->FindObjectAny(
"TLemRunHeader"));
1435 std::cerr << std::endl <<
">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't obtain run header info from ROOT file " <<
fRunPathName.Data() << std::endl;
1448 TObjString ostr = runHeader->GetRunTitle();
1452 runData.
SetRunNumber(
static_cast<Int_t
>(runHeader->GetRunNumber()));
1456 runData.
SetTemperature(0, runHeader->GetSampleTemperature(), runHeader->GetSampleTemperatureError());
1459 runData.
SetField(runHeader->GetSampleBField());
1462 runData.
SetEnergy(runHeader->GetImpEnergy());
1468 runData.
SetSetup(runHeader->GetLemSetup().GetString());
1472 time_t idt =
static_cast<time_t
>(runHeader->GetStartTime());
1474 struct tm *dt = localtime(&idt);
1476 strftime(str,
sizeof(str),
"%F", dt);
1480 memset(str, 0,
sizeof(str));
1481 strftime(str,
sizeof(str),
"%T", dt);
1487 idt =
static_cast<time_t
>(runHeader->GetStopTime());
1489 dt = localtime(&idt);
1490 memset(str, 0,
sizeof(str));
1491 strftime(str,
sizeof(str),
"%F", dt);
1495 memset(str, 0,
sizeof(str));
1496 strftime(str,
sizeof(str),
"%T", dt);
1504 Int_t noOfHistos = runHeader->GetNHist();
1507 Double_t *t0 = runHeader->GetTimeZero();
1510 TObjArray *runSummary =
dynamic_cast<TObjArray*
>(folder->FindObjectAny(
"RunSummary"));
1514 std::cout << std::endl <<
"**INFO** Couldn't obtain run summary info from ROOT file " <<
fRunPathName.Data() << std::endl;
1519 TObjArrayIter summIter(runSummary);
1520 TObjString *os(
dynamic_cast<TObjString*
>(summIter.Next()));
1521 while (os !=
nullptr) {
1522 s = os->GetString();
1525 std::vector<std::string> oa = PStringUtils::Split(s.Data(),
" ");
1526 for (UInt_t k=0; k+2 < oa.size(); k++) {
1529 if (oa[k] ==
"RA-L")
1531 else if (oa[k] ==
"RA-R")
1533 else if (oa[k] ==
"RA-T")
1535 else if (oa[k] ==
"RA-B")
1539 os =
dynamic_cast<TObjString*
>(summIter.Next());
1546 f.GetObject(
"histos", folder);
1548 std::cerr << std::endl <<
">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't obtain histos from " <<
fRunPathName.Data() << std::endl;
1554 Char_t histoName[32];
1555 for (Int_t i=0; i<noOfHistos; i++) {
1556 snprintf(histoName,
sizeof(histoName),
"hDecay%02d", i);
1557 TH1F *histo =
dynamic_cast<TH1F*
>(folder->FindObjectAny(histoName));
1559 std::cerr << std::endl <<
">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't get histo " << histoName;
1560 std::cerr << std::endl;
1566 for (Int_t j=1; j<=histo->GetNbinsX(); j++) {
1567 histoData.push_back(histo->GetBinContent(j));
1572 dataSet.
SetName(histo->GetTitle());
1586 if (!folder->FindObjectAny(histoName)) {
1587 std::cerr << std::endl <<
">> PRunDataHandler::ReadRootFile: **WARNING** Couldn't get histo " << histoName;
1588 std::cerr << std::endl <<
">> most probably this is an old (2006 or earlier) LEM file without post pileup histos.";
1589 std::cerr << std::endl;
1591 for (Int_t i=0; i<noOfHistos; i++) {
1593 TH1F *histo =
dynamic_cast<TH1F*
>(folder->FindObjectAny(histoName));
1595 std::cerr << std::endl <<
">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't get histo " << histoName;
1596 std::cerr << std::endl;
1602 for (Int_t j=1; j<=histo->GetNbinsX(); j++)
1603 histoData.push_back(histo->GetBinContent(j));
1607 dataSet.
SetName(histo->GetTitle());
1622 std::unique_ptr<TMusrRunHeader> header = std::make_unique<TMusrRunHeader>(
true);
1623 if (header ==
nullptr) {
1624 std::cerr << std::endl <<
">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't invoke MusrRoot RunHeader in file:" <<
fRunPathName;
1625 std::cerr << std::endl;
1632 f.GetObject(
"RunHeader", folder);
1635 if (!header->ExtractAll(folder)) {
1636 std::cerr << std::endl <<
">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't invoke MusrRoot RunHeader (TFolder) in file:" <<
fRunPathName;
1637 std::cerr << std::endl;
1642 TDirectoryFile *runHeader =
nullptr;
1643 f.GetObject(
"RunHeader", runHeader);
1646 if (!header->ExtractAll(runHeader)) {
1647 std::cerr << std::endl <<
">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't invoke MusrRoot RunHeader (TDirectoryFile) in file:" <<
fRunPathName;
1648 std::cerr << std::endl;
1656 TString str, path, pathName;
1657 Int_t ival, noOfHistos=0;
1662 header->Get(
"RunInfo/Version", str, ok);
1666 header->Get(
"RunInfo/Generic Validator URL", str, ok);
1670 header->Get(
"RunInfo/Specific Validator URL", str, ok);
1674 header->Get(
"RunInfo/Generator", str, ok);
1678 header->Get(
"RunInfo/File Name", str, ok);
1682 header->Get(
"RunInfo/Run Title", str, ok);
1686 header->Get(
"RunInfo/Run Number", ival, ok);
1690 header->Get(
"RunInfo/Run Start Time", str, ok);
1692 Ssiz_t pos = str.Index(
' ');
1693 TString substr = str;
1694 substr.Remove(pos, str.Length());
1697 substr.Remove(0, pos+1);
1701 header->Get(
"RunInfo/Run Stop Time", str, ok);
1703 Ssiz_t pos = str.Index(
' ');
1704 TString substr = str;
1705 substr.Remove(pos, str.Length());
1708 substr.Remove(0, pos+1);
1712 header->Get(
"RunInfo/Laboratory", str, ok);
1716 header->Get(
"RunInfo/Instrument", str, ok);
1720 header->Get(
"RunInfo/Muon Beam Momentum", prop, ok);
1722 if (!prop.
GetUnit().CompareTo(
"MeV/c"))
1726 header->Get(
"RunInfo/Muon Species", str, ok);
1730 header->Get(
"RunInfo/Muon Source", str, ok);
1734 header->Get(
"RunInfo/Muon Spin Angle", prop, ok);
1739 header->Get(
"RunInfo/Setup", str, ok);
1743 header->Get(
"RunInfo/Comment", str, ok);
1747 header->Get(
"RunInfo/Sample Name", str, ok);
1751 header->Get(
"RunInfo/Sample Temperature", prop, ok);
1755 header->Get(
"RunInfo/Sample Magnetic Field", prop, ok);
1758 if (!prop.
GetUnit().CompareTo(
"G") || !prop.
GetUnit().CompareTo(
"Gauss"))
1760 else if (!prop.
GetUnit().CompareTo(
"T") || !prop.
GetUnit().CompareTo(
"Tesla"))
1765 header->Get(
"RunInfo/No of Histos", ival, ok);
1770 header->Get(
"RunInfo/Time Resolution", prop, ok);
1773 if (!prop.
GetUnit().CompareTo(
"ps") || !prop.
GetUnit().CompareTo(
"picosec"))
1775 else if (!prop.
GetUnit().CompareTo(
"ns") || !prop.
GetUnit().CompareTo(
"nanosec"))
1777 else if (!prop.
GetUnit().CompareTo(
"us") || !prop.
GetUnit().CompareTo(
"microsec"))
1780 std::cerr << std::endl <<
">> PRunDataHandler::ReadRootFile: **ERROR** Found unrecognized Time Resolution unit: " << prop.
GetUnit() << std::endl;
1784 header->Get(
"RunInfo/RedGreen Offsets", ivec, ok);
1789 redGreenOffsets.push_back(0);
1792 Bool_t found =
false;
1793 for (UInt_t i=0; i<
fAny2ManyInfo->groupHistoList.size(); i++) {
1795 for (UInt_t j=0; j<ivec.size(); j++) {
1800 std::cerr << std::endl <<
">> PRunDataHandler::ReadRootFile: **ERROR** requested histo group " <<
fAny2ManyInfo->groupHistoList[i];
1801 std::cerr << std::endl <<
">> which is NOT present in the data file." << std::endl;
1810 redGreenOffsets = ivec;
1815 header->Get(
"RunInfo/Sample Orientation", str, ok);
1821 header->Get(
"RunInfo/Moderator HV", prop, ok);
1825 header->Get(
"RunInfo/Implantation Energy", prop, ok);
1831 header->Get(
"SampleEnvironmentInfo/Cryo", str, ok);
1837 header->Get(
"MagneticFieldEnvironmentInfo/Magnet Name", str, ok);
1843 header->Get(
"BeamlineInfo/Name", str, ok);
1848 TObjArray *runSummary =
nullptr;
1850 runSummary =
dynamic_cast<TObjArray*
>(folder->FindObjectAny(
"RunSummary"));
1852 f.GetObject(
"RunHeader/RunSummary", runSummary);
1857 std::cout << std::endl <<
"**INFO** Couldn't obtain run summary info from ROOT file " <<
fRunPathName.Data() << std::endl;
1862 TObjArrayIter summIter(runSummary);
1863 TObjString *os(
dynamic_cast<TObjString*
>(summIter.Next()));
1864 while (os !=
nullptr) {
1865 s = os->GetString();
1868 std::vector<std::string> oa = PStringUtils::Split(s.Data(),
" ");
1869 for (UInt_t k=0; k+2 < oa.size(); k++) {
1872 if (oa[k] ==
"RA-L")
1874 else if (oa[k] ==
"RA-R")
1876 else if (oa[k] ==
"RA-T")
1878 else if (oa[k] ==
"RA-B")
1882 os =
dynamic_cast<TObjString*
>(summIter.Next());
1890 f.GetObject(
"histos", folder);
1892 std::cerr << std::endl <<
">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't obtain histos from " <<
fRunPathName.Data() << std::endl;
1898 for (UInt_t i=0; i<redGreenOffsets.size(); i++) {
1899 for (Int_t j=0; j<noOfHistos; j++) {
1900 str.Form(
"hDecay%03d", redGreenOffsets[i]+j+1);
1901 TH1F *histo =
dynamic_cast<TH1F*
>(folder->FindObjectAny(str.Data()));
1903 std::cerr << std::endl <<
">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't get histo " << str;
1904 std::cerr << std::endl;
1910 dataSet.
SetTitle(histo->GetTitle());
1914 path.Form(
"DetectorInfo/Detector%03d/", redGreenOffsets[i]+j+1);
1915 pathName = path +
"Name";
1916 header->Get(pathName, str, ok);
1919 pathName = path +
"Time Zero Bin";
1920 header->Get(pathName, dval, ok);
1923 pathName = path +
"First Good Bin";
1924 header->Get(pathName, ival, ok);
1927 pathName = path +
"Last Good Bin";
1928 header->Get(pathName, ival, ok);
1934 for (Int_t j=1; j<=histo->GetNbinsX(); j++) {
1935 histoData.push_back(histo->GetBinContent(j));
1947 for (UInt_t i=0; i<redGreenOffsets.size(); i++) {
1948 for (Int_t j=0; j<noOfHistos; j++) {
1949 str.Form(
"histos/DecayAnaModule/hDecay%03d", redGreenOffsets[i]+j+1);
1950 f.GetObject(str, histo);
1952 std::cerr << std::endl <<
">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't get histo " << str;
1953 std::cerr << std::endl;
1959 dataSet.
SetTitle(histo->GetTitle());
1963 path.Form(
"DetectorInfo/Detector%03d/", redGreenOffsets[i]+j+1);
1964 pathName = path +
"Name";
1965 header->Get(pathName, str, ok);
1968 pathName = path +
"Time Zero Bin";
1969 header->Get(pathName, dval, ok);
1972 pathName = path +
"First Good Bin";
1973 header->Get(pathName, ival, ok);
1976 pathName = path +
"Last Good Bin";
1977 header->Get(pathName, ival, ok);
1983 for (Int_t j=1; j<=histo->GetNbinsX(); j++) {
1984 histoData.push_back(histo->GetBinContent(j));
2002 fData.push_back(runData);
2676 std::cerr << std::endl <<
">> **ERROR** Couldn't open mud-file " <<
fRunPathName.Data() <<
", sorry.";
2677 std::cerr << std::endl;
2687 success = MUD_getLab( fh, str,
sizeof(str) );
2689 std::cerr << std::endl <<
">> **WARNING** Couldn't obtain the laboratory name of run " <<
fRunName.Data();
2690 std::cerr << std::endl;
2696 success = MUD_getArea( fh, str,
sizeof(str) );
2698 std::cerr << std::endl <<
">> **WARNING** Couldn't obtain the beamline of run " <<
fRunName.Data();
2699 std::cerr << std::endl;
2705 success = MUD_getApparatus( fh, str,
sizeof(str) );
2707 std::cerr << std::endl <<
">> **WARNING** Couldn't obtain the instrument name of run " <<
fRunName.Data();
2708 std::cerr << std::endl;
2714 success = MUD_getTitle( fh, str,
sizeof(str) );
2716 std::cerr << std::endl <<
">> **WARNING** Couldn't obtain the run title of run " <<
fRunName.Data();
2717 std::cerr << std::endl;
2722 success = MUD_getRunNumber( fh, &val );
2731 success = MUD_getTimeBegin( fh, (
UINT32*)&tval );
2734 dt = localtime((
const time_t*)&tval);
2738 strftime(str,
sizeof(str),
"%F", dt);
2742 memset(str, 0,
sizeof(str));
2743 strftime(str,
sizeof(str),
"%T", dt);
2747 std::cerr <<
"PRunDataHandler::ReadMudFile: **WARNING** run start time readback wrong, will set it to 1900-01-01, 00:00:00" << std::endl;
2748 stime =
"1900-01-01";
2755 stime = TString(
"");
2756 success = MUD_getTimeEnd( fh, (
UINT32*)&tval );
2759 dt = localtime((
const time_t*)&tval);
2763 strftime(str,
sizeof(str),
"%F", dt);
2767 memset(str, 0,
sizeof(str));
2768 strftime(str,
sizeof(str),
"%T", dt);
2772 std::cerr <<
"PRunDataHandler::ReadMudFile: **WARNING** run stop time readback wrong, will set it to 1900-01-01, 00:00:00" << std::endl;
2773 stime =
"1900-01-01";
2782 REAL64 timeResMultiplier = 1.0e9;
2783 success = MUD_getLab( fh, str,
sizeof(str) );
2785 setup = TString(str) + TString(
"/");
2787 success = MUD_getArea( fh, str,
sizeof(str) );
2789 setup += TString(str) + TString(
"/");
2790 if (TString(str) ==
"BNQR" || TString(str) ==
"BNMR") {
2791 std::cerr <<
"PRunDataHandler::ReadMudFile: **INFORMATION** this run was performed on " << str << std::endl;
2792 std::cerr <<
"PRunDataHandler::ReadMudFile: **INFORMATION** apply correction to time resolution" << std::endl;
2794 timeResMultiplier = 1.0e9;
2797 success = MUD_getApparatus( fh, str,
sizeof(str) );
2799 setup += TString(str) + TString(
"/");
2801 success = MUD_getSample( fh, str,
sizeof(str) );
2803 setup += TString(str);
2813 success = MUD_getField( fh, str,
sizeof(str) );
2815 success = sscanf(str,
"%lf G", &dval);
2826 success = MUD_getTemperature( fh, str,
sizeof(str) );
2828 success = sscanf(str,
"%lf K", &dval);
2839 success = MUD_getHists(fh, &type, &val);
2841 std::cerr << std::endl <<
">> **ERROR** Couldn't obtain the number of histograms of run " <<
fRunName.Data();
2842 std::cerr << std::endl;
2846 Int_t noOfHistos =
static_cast<Int_t
>(val);
2852 REAL64 timeResolution = 0.0;
2854 for (Int_t i=1; i<=noOfHistos; i++) {
2857 std::cerr << std::endl <<
">> **ERROR** Couldn't obtain the time resolution of run " <<
fRunName.Data();
2858 std::cerr << std::endl <<
">> which is fatal, sorry.";
2859 std::cerr << std::endl;
2864 timeResolution = lrval;
2866 if (lrval != timeResolution) {
2867 std::cerr << std::endl <<
">> **ERROR** various time resolutions found in run " <<
fRunName.Data();
2868 std::cerr << std::endl <<
">> this is currently not supported, sorry.";
2869 std::cerr << std::endl;
2876 runData.
SetTimeResolution(
static_cast<Double_t
>(timeResolution) * timeResMultiplier);
2889 for (Int_t i=1; i<=noOfHistos; i++) {
2895 success = MUD_getHistT0_Bin( fh, i, &val );
2897 std::cerr << std::endl <<
">> **WARNING** Couldn't get t0 of histo " << i <<
" of run " <<
fRunName.Data();
2898 std::cerr << std::endl;
2903 success = MUD_getHistBkgd1( fh, i, &val );
2905 std::cerr << std::endl <<
">> **WARNING** Couldn't get bkg bin 1 of histo " << i <<
" of run " <<
fRunName.Data();
2906 std::cerr << std::endl;
2911 success = MUD_getHistBkgd2( fh, i, &val );
2913 std::cerr << std::endl <<
">> **WARNING** Couldn't get bkg bin 2 of histo " << i <<
" of run " <<
fRunName.Data();
2914 std::cerr << std::endl;
2920 success = MUD_getHistGoodBin1( fh, i, &val );
2922 std::cerr << std::endl <<
">> **WARNING** Couldn't get good bin 1 of histo " << i <<
" of run " <<
fRunName.Data();
2923 std::cerr << std::endl;
2928 success = MUD_getHistGoodBin2( fh, i, &val );
2930 std::cerr << std::endl <<
">> **WARNING** Couldn't get good bin 2 of histo " << i <<
" of run " <<
fRunName.Data();
2931 std::cerr << std::endl;
2937 success = MUD_getHistNumBins( fh, i, &val );
2939 std::cerr << std::endl <<
">> **ERROR** Couldn't get the number of bins of histo " << i <<
".";
2940 std::cerr << std::endl <<
">> This is fatal, sorry.";
2941 std::cerr << std::endl;
2945 noOfBins =
static_cast<UInt_t
>(val);
2947 pData = (
UINT32*)malloc(noOfBins*
sizeof(pData));
2948 if (pData ==
nullptr) {
2949 std::cerr << std::endl <<
">> **ERROR** Couldn't allocate memory for data.";
2950 std::cerr << std::endl <<
">> This is fatal, sorry.";
2951 std::cerr << std::endl;
2959 std::cerr << std::endl <<
">> **ERROR** Couldn't get histo no " << i <<
".";
2960 std::cerr << std::endl <<
">> This is fatal, sorry.";
2961 std::cerr << std::endl;
2966 for (UInt_t j=0; j<noOfBins; j++) {
2967 histoData.push_back(pData[j]);
2972 Double_t maxVal = 0.0;
2974 for (UInt_t j=0; j<histoData.size(); j++) {
2975 if (histoData[j] > maxVal) {
2976 maxVal = histoData[j];
2992 fData.push_back(runData);
3028 Bool_t success =
true;
3036 std::cerr << std::endl <<
">> PRunDataHandler::ReadMduAsciiFile **ERROR** Couldn't open data file (" <<
fRunPathName.Data() <<
") for reading, sorry ...";
3037 std::cerr << std::endl;
3048 TString line, workStr;
3049 Bool_t headerTag =
false;
3050 Bool_t dataTag =
false;
3051 Int_t dataLineCounter = 0;
3052 std::vector<std::string> tokens;
3056 Double_t dval = 0.0, unitScaling = 0.0;
3057 std::vector<PDoubleVector> data;
3060 f.getline(instr,
sizeof(instr));
3061 line = TString(instr);
3065 if (line.BeginsWith(
"#") || line.BeginsWith(
"%"))
3069 if (line.IsWhitespace())
3074 workStr.Remove(TString::kLeading,
' ');
3075 if (workStr.BeginsWith(
"header", TString::kIgnoreCase)) {
3083 workStr.Remove(TString::kLeading,
' ');
3084 if (workStr.BeginsWith(
"data", TString::kIgnoreCase)) {
3092 workStr.Remove(TString::kLeading,
' ');
3093 if (workStr.BeginsWith(
"title:", TString::kIgnoreCase)) {
3094 runData.
SetRunTitle(TString(workStr.Data()+workStr.First(
":")+2));
3095 }
else if (workStr.BeginsWith(
"field:", TString::kIgnoreCase)) {
3096 tokens = PStringUtils::Split(workStr.Data(),
":(");
3098 if (tokens.size() != 3) {
3099 std::cerr << std::endl <<
">> PRunDataHandler::ReadMduAsciiFile **ERROR** line no " << lineNo <<
", invalid field entry in header.";
3100 std::cerr << std::endl <<
">> " << line.Data();
3101 std::cerr << std::endl;
3106 if (TString(tokens[1]).IsFloat()) {
3107 dval = TString(tokens[1]).Atof();
3109 std::cerr << std::endl <<
">> PRunDataHandler::ReadMduAsciiFile **ERROR** line no " << lineNo <<
", field value is not float/doulbe.";
3110 std::cerr << std::endl <<
">> " << line.Data();
3111 std::cerr << std::endl;
3116 if (TString(tokens[2]).Contains(
"G"))
3118 else if (TString(tokens[2]).Contains(
"T"))
3119 unitScaling = 1.0e4;
3121 std::cerr << std::endl <<
">> PRunDataHandler::ReadMduAsciiFile **ERROR** line no " << lineNo <<
", unkown field units.";
3122 std::cerr << std::endl <<
">> " << line.Data();
3123 std::cerr << std::endl;
3127 runData.
SetField(dval*unitScaling);
3128 }
else if (workStr.BeginsWith(
"temp:", TString::kIgnoreCase)) {
3129 tokens = PStringUtils::Split(workStr.Data(),
":(");
3131 if (tokens.size() != 3) {
3132 std::cerr << std::endl <<
">> PRunDataHandler::ReadMduAsciiFile **ERROR** line no " << lineNo <<
", invalid temperatue entry in header.";
3133 std::cerr << std::endl <<
">> " << line.Data();
3134 std::cerr << std::endl;
3139 if (TString(tokens[1]).IsFloat()) {
3140 dval = TString(tokens[1]).Atof();
3142 std::cerr << std::endl <<
">> PRunDataHandler::ReadMduAsciiFile **ERROR** line no " << lineNo <<
", temperature value is not float/doulbe.";
3143 std::cerr << std::endl <<
">> " << line.Data();
3144 std::cerr << std::endl;
3149 }
else if (workStr.BeginsWith(
"setup:", TString::kIgnoreCase)) {
3150 runData.
SetSetup(TString(workStr.Data()+workStr.First(
":")+2));
3151 }
else if (workStr.BeginsWith(
"groups:", TString::kIgnoreCase)) {
3152 workStr = TString(workStr.Data()+workStr.First(
":")+2);
3153 groups = workStr.Atoi();
3155 std::cerr << std::endl <<
">> PRunDataHandler::ReadMduAsciiFile **ERROR** line no " << lineNo <<
", groups is not a number or 0.";
3156 std::cerr << std::endl;
3160 data.resize(groups);
3161 }
else if (workStr.BeginsWith(
"channels:", TString::kIgnoreCase)) {
3162 workStr = TString(workStr.Data()+workStr.First(
":")+2);
3163 channels = workStr.Atoi();
3164 if (channels == 0) {
3165 std::cerr << std::endl <<
">> PRunDataHandler::ReadMduAsciiFile **ERROR** line no " << lineNo <<
", channels is not a number or 0.";
3166 std::cerr << std::endl;
3170 }
else if (workStr.BeginsWith(
"resolution:", TString::kIgnoreCase)) {
3171 tokens = PStringUtils::Split(workStr.Data(),
":(");
3173 if (tokens.size() != 3) {
3174 std::cerr << std::endl <<
">> PRunDataHandler::ReadMduAsciiFile **ERROR** line no " << lineNo <<
", invalid time resolution entry in header.";
3175 std::cerr << std::endl << line.Data();
3176 std::cerr << std::endl;
3181 if (TString(tokens[1]).IsFloat()) {
3182 dval = TString(tokens[1]).Atof();
3184 std::cerr << std::endl <<
">> PRunDataHandler::ReadMduAsciiFile **ERROR** line no " << lineNo <<
", time resolution value is not float/doulbe.";
3185 std::cerr << std::endl <<
">> " << line.Data();
3186 std::cerr << std::endl;
3191 if (TString(tokens[2]).Contains(
"fs"))
3192 unitScaling = 1.0e-6;
3193 else if (TString(tokens[2]).Contains(
"ps"))
3194 unitScaling = 1.0e-3;
3195 else if (TString(tokens[2]).Contains(
"ns"))
3197 else if (TString(tokens[2]).Contains(
"us"))
3198 unitScaling = 1.0e3;
3200 std::cerr << std::endl <<
">> PRunDataHandler::ReadMduAsciiFile **ERROR** line no " << lineNo <<
", unkown time resolution units.";
3201 std::cerr << std::endl <<
">> " << line.Data();
3202 std::cerr << std::endl;
3208 std::cerr << std::endl <<
">> PRunDataHandler::ReadMduAsciiFile **ERROR** line no " << lineNo <<
", illegal header line.";
3209 std::cerr << std::endl;
3213 }
else if (dataTag) {
3215 tokens = PStringUtils::Split(line.Data(),
" ,\t");
3217 if (
static_cast<Int_t
>(tokens.size()) != groups+1) {
3218 std::cerr << std::endl <<
">> PRunDataHandler::ReadMduAsciiFile **ERROR** found data line with a wrong data format, cannot be handled (line no " << lineNo <<
")";
3219 std::cerr << std::endl <<
">> line:";
3220 std::cerr << std::endl <<
">> " << line.Data();
3221 std::cerr << std::endl;
3226 for (UInt_t i=1; i<tokens.size(); i++) {
3227 data[i-1].push_back(TString(tokens[i]).Atof());
3236 for (UInt_t i=0; i<data.size(); i++) {
3242 Double_t maxVal = 0.0;
3244 for (UInt_t j=0; j<data[i].size(); j++) {
3245 if (data[i][j] > maxVal) {
3246 maxVal = data[i][j];
3255 for (UInt_t i=0; i<data.size(); i++)
3259 if (dataLineCounter != channels) {
3260 std::cerr << std::endl <<
">> PRunDataHandler::ReadMduAsciiFile **WARNING** found " << dataLineCounter <<
" data bins,";
3261 std::cerr << std::endl <<
">> expected " << channels <<
" according to the header." << std::endl;
3264 fData.push_back(runData);
3617 Bool_t success =
true;
3625 std::cerr << std::endl <<
">> PRunDataHandler::ReadDBFile **ERROR** Couldn't open data file (" <<
fRunPathName.Data() <<
") for reading, sorry ...";
3626 std::cerr << std::endl;
3638 TString line, workStr;
3640 Bool_t firstData =
true;
3641 Bool_t labelledFormat =
true;
3642 Bool_t dataTagsRead =
false;
3646 std::vector<std::string> tokens;
3650 f.getline(instr,
sizeof(instr));
3651 line = TString(instr);
3655 if (line.BeginsWith(
"#") || line.BeginsWith(
"%"))
3659 if (line.IsWhitespace())
3664 workStr.Remove(TString::kLeading,
' ');
3665 if (workStr.BeginsWith(
"title", TString::kIgnoreCase)) {
3668 }
else if (workStr.BeginsWith(
"abstract", TString::kIgnoreCase)) {
3671 }
else if (workStr.BeginsWith(
"comments", TString::kIgnoreCase)) {
3674 }
else if (workStr.BeginsWith(
"label", TString::kIgnoreCase)) {
3677 }
else if (workStr.BeginsWith(
"data", TString::kIgnoreCase) && !dataTagsRead) {
3678 dataTagsRead =
true;
3682 tokens = PStringUtils::Split(workStr.Data(),
" ,\t");
3683 for (UInt_t i=1; i<tokens.size(); i++) {
3704 if (workStr.BeginsWith(
"\\-e", TString::kIgnoreCase) ||
3705 workStr.BeginsWith(
"\\e", TString::kIgnoreCase) ||
3706 workStr.BeginsWith(
"/-e", TString::kIgnoreCase) ||
3707 workStr.BeginsWith(
"/e", TString::kIgnoreCase)) {
3714 tokens = PStringUtils::Split(workStr.Data(),
",");
3715 if (!TString(tokens[0]).IsFloat()) {
3716 labelledFormat =
true;
3718 labelledFormat =
false;
3731 if (labelledFormat) {
3733 const Char_t *str = workStr.Data();
3734 if (isdigit(str[0])) {
3738 std::cerr << std::endl <<
">> PRunDataHandler::ReadDBFile **ERROR** in line no " << lineNo <<
":";
3739 std::cerr << std::endl <<
">> " << workStr.Data();
3740 std::cerr << std::endl <<
">> found potential run data line without run data tag.";
3744 tokens = PStringUtils::Split(workStr.Data(),
",");
3745 tstr = TString(tokens[0]);
3746 if (!tstr.IsFloat()) {
3747 std::cerr << std::endl <<
">> PRunDataHandler::ReadDBFile **ERROR** in line no " << lineNo <<
":";
3748 std::cerr << std::endl <<
">> " << workStr.Data();
3749 std::cerr << std::endl <<
">> Expected db-data line with structure: runNo,,, runTitle";
3750 std::cerr << std::endl <<
">> runNo = " << tstr.Data() <<
", seems to be not a number.";
3758 workStr.ReplaceAll(
" ",
"");
3760 tokens = PStringUtils::Split(workStr.Data(),
"=,");
3761 if (tokens.size() < 3) {
3762 std::cerr << std::endl <<
">> PRunDataHandler::ReadDBFile **ERROR** in line no " << lineNo <<
":";
3763 std::cerr << std::endl <<
">> " << workStr.Data();
3764 std::cerr << std::endl <<
">> Expected db-data line with structure: tag = val,err1,err2,\\";
3767 tstr = TString(tokens[0]);
3770 std::cerr << std::endl <<
">> PRunDataHandler::ReadDBFile **ERROR** in line no " << lineNo <<
":";
3771 std::cerr << std::endl <<
">> " << workStr.Data();
3772 std::cerr << std::endl <<
">> data tag error: " << tstr.Data() <<
" seems not present in the data tag list";
3776 switch (tokens.size()) {
3778 tstr = TString(tokens[1]);
3779 if (!tstr.IsFloat()) {
3780 std::cerr << std::endl <<
">> PRunDataHandler::ReadDBFile **ERROR** in line no " << lineNo <<
":";
3781 std::cerr << std::endl <<
">> " << workStr.Data();
3782 std::cerr << std::endl <<
">> Expected db-data line with structure: tag = val,err1,err2,\\";
3783 std::cerr << std::endl <<
">> val = " << tstr.Data() <<
", seems to be not a number.";
3793 tstr = TString(tokens[1]);
3794 if (!tstr.IsFloat()) {
3795 std::cerr << std::endl <<
">> PRunDataHandler::ReadDBFile **ERROR** in line no " << lineNo <<
":";
3796 std::cerr << std::endl <<
">> " << workStr.Data();
3797 std::cerr << std::endl <<
">> Expected db-data line with structure: tag = val,err1,err2,\\";
3798 std::cerr << std::endl <<
">> val = " << tstr.Data() <<
", seems to be not a number.";
3804 tstr = TString(tokens[2]);
3805 if (!tstr.IsFloat()) {
3806 std::cerr << std::endl <<
">> PRunDataHandler::ReadDBFile **ERROR** in line no " << lineNo <<
":";
3807 std::cerr << std::endl <<
">> " << workStr.Data();
3808 std::cerr << std::endl <<
">> Expected db-data line with structure: tag = val,err1,err2,\\";
3809 std::cerr << std::endl <<
">> err1 = " << tstr.Data() <<
", seems to be not a number.";
3816 std::cerr << std::endl <<
">> PRunDataHandler::ReadDBFile **ERROR** in line no " << lineNo <<
":";
3817 std::cerr << std::endl <<
">> " << workStr.Data();
3818 std::cerr << std::endl <<
">> Expected db-data line with structure: tag = val,err1,err2,\\";
3825 tokens = PStringUtils::Split(workStr.Data(),
",");
3827 std::cerr << std::endl <<
">> PRunDataHandler::ReadDBFile **ERROR** in line no " << lineNo <<
":";
3828 std::cerr << std::endl <<
">> " << workStr.Data();
3829 std::cerr << std::endl <<
">> Expected db-data line with structure: val1, err11, err12, ..., valn, errn1, errn2, runNo, , , , runTitle";
3830 std::cerr << std::endl <<
">> found = " << tokens.size() <<
" tokens, however expected " << 3*runData.
fDataNonMusr.
GetDataTags()->size()+1;
3831 std::cerr << std::endl <<
">> Perhaps there are commas without space inbetween, like 12.3,, 3.2,...";
3836 for (UInt_t i=0; i+1<tokens.size(); i+=3) {
3838 tstr = TString(tokens[i]);
3839 if (!tstr.IsFloat()) {
3840 std::cerr << std::endl <<
">> PRunDataHandler::ReadDBFile **ERROR** in line no " << lineNo <<
":";
3841 std::cerr << std::endl <<
">> " << workStr.Data();
3842 std::cerr << std::endl <<
">> Expected db-data line with structure: val1, err11, err12, ..., valn, errn1, errn2, runNo, , , , runTitle";
3843 std::cerr << std::endl <<
">> value=" << tstr.Data() <<
" seems not to be a number";
3849 tstr = TString(tokens[i+1]);
3850 if (tstr.IsWhitespace()) {
3852 }
else if (tstr.IsFloat()) {
3855 std::cerr << std::endl <<
">> PRunDataHandler::ReadDBFile **ERROR** in line no " << lineNo <<
":";
3856 std::cerr << std::endl <<
">> " << workStr.Data();
3857 std::cerr << std::endl <<
">> Expected db-data line with structure: val1, err11, err12, ..., valn, errn1, errn2, runNo, , , , runTitle";
3858 std::cerr << std::endl <<
">> error1=" << tstr.Data() <<
" seems not to be a number";
3874 std::cerr << std::endl <<
">> PRunDataHandler::ReadDBFile **ERROR**";
3875 std::cerr << std::endl <<
">> number of LABELS found = " << runData.
fDataNonMusr.
GetLabels()->size();
3877 std::cerr << std::endl <<
">> They have to be equal!!";
3884 std::cerr << std::endl <<
">> PRunDataHandler::ReadDBFile **ERROR** in line no " << lineNo;
3887 std::cerr << std::endl <<
">> They have to be equal!!";
3892 std::cerr << std::endl <<
">> PRunDataHandler::ReadDBFile **ERROR** in line no " << lineNo;
3895 std::cerr << std::endl <<
">> They have to be equal!!";
3904 fData.push_back(runData);
4074 std::cout << std::endl <<
">> PRunDataHandler::WriteMusrRootFile(): writing a root data file (" << fln.Data() <<
") ... " << std::endl;
4077 std::unique_ptr<TFile> fout = std::make_unique<TFile>(fln,
"RECREATE", fln);
4078 if (fout ==
nullptr) {
4079 std::cerr << std::endl <<
"PRunDataHandler::WriteMusrRootFile(): **ERROR** Couldn't create ROOT file '" << fln <<
"'" << std::endl;
4085 std::unique_ptr<TMusrRunHeader> header = std::make_unique<TMusrRunHeader>(
true);
4086 TFolder *histosFolder, *decayAnaModule, *runHeader;
4087 TDirectory *histosDir, *decayAnaDir, *runHeaderDir;
4089 histosFolder =
new TFolder(
"histos",
"Histograms");
4090 decayAnaModule = histosFolder->AddFolder(
"DecayAnaModule",
"muSR decay histograms");
4091 runHeader =
new TFolder(
"RunHeader",
"MusrRoot Run Header Info");
4093 histosDir = fout->mkdir(
"histos");
4094 decayAnaDir = histosDir->mkdir(
"decayAnaModule");
4095 runHeaderDir = fout->mkdir(
"RunHeader");
4099 TString str, pathName;
4102 time_t start{0}, stop{0};
4103 Bool_t valid{
false};
4107 str =
fData[0].GetGenericValidatorUrl()->Copy();
4108 header->Set(
"RunInfo/Generic Validator URL", str);
4109 str =
fData[0].GetSpecificValidatorUrl()->Copy();
4110 header->Set(
"RunInfo/Specific Validator URL", str);
4111 str =
fData[0].GetGenerator()->Copy();
4112 header->Set(
"RunInfo/Generator", str);
4113 str =
fData[0].GetFileName()->Copy();
4114 header->Set(
"RunInfo/File Name", str);
4115 str =
fData[0].GetRunTitle()->Copy();
4116 header->Set(
"RunInfo/Run Title", str);
4117 header->Set(
"RunInfo/Run Number",
fData[0].GetRunNumber());
4118 str =
fData[0].GetStartDate()->Copy() +
" " +
fData[0].GetStartTime()->Copy();
4119 header->Set(
"RunInfo/Run Start Time", str);
4120 str =
fData[0].GetStopDate()->Copy() +
" " +
fData[0].GetStopTime()->Copy();
4121 header->Set(
"RunInfo/Run Stop Time", str);
4122 start =
fData[0].CalcStartDateTime(valid);
4124 stop =
fData[0].CalcStopDateTime(valid);
4126 ival = (int)stop - (
int)start;
4127 prop.
Set(
"Run Duration", ival,
"sec");
4128 header->Set(
"RunInfo/Run Duration", prop);
4129 str =
fData[0].GetLaboratory()->Copy();
4130 header->Set(
"RunInfo/Laboratory", str);
4131 str =
fData[0].GetInstrument()->Copy();
4132 header->Set(
"RunInfo/Instrument", str);
4133 dval[0] =
fData[0].GetMuonBeamMomentum();
4134 prop.
Set(
"Muon Beam Momentum", dval[0],
"MeV/c");
4135 header->Set(
"RunInfo/Muon Beam Momentum", prop);
4136 str =
fData[0].GetMuonSpecies()->Copy();
4137 header->Set(
"RunInfo/Muon Species", str);
4138 str =
fData[0].GetMuonSource()->Copy();
4139 header->Set(
"RunInfo/Muon Source", str);
4140 str =
fData[0].GetSetup()->Copy();
4141 header->Set(
"RunInfo/Setup", str);
4142 str =
fData[0].GetComment()->Copy();
4143 header->Set(
"RunInfo/Comment", str);
4144 str =
fData[0].GetSample()->Copy();
4145 header->Set(
"RunInfo/Sample Name", str);
4146 dval[0] =
fData[0].GetTemperature(0);
4147 dval[1] =
fData[0].GetTempError(0);
4149 header->Set(
"RunInfo/Sample Temperature", prop);
4150 dval[0] =
fData[0].GetField();
4151 prop.
Set(
"Sample Magnetic Field", dval[0],
"G");
4152 header->Set(
"RunInfo/Sample Magnetic Field", prop);
4153 header->Set(
"RunInfo/No of Histos",
static_cast<Int_t
>(
fData[0].GetNoOfHistos()));
4154 dval[0] =
fData[0].GetTimeResolution();
4155 prop.
Set(
"Time Resolution", dval[0],
"ns");
4156 header->Set(
"RunInfo/Time Resolution", prop);
4157 header->Set(
"RunInfo/RedGreen Offsets",
fData[0].GetRedGreenOffset());
4162 UInt_t size =
fData[0].GetNoOfHistos();
4163 for (UInt_t i=0; i<size; i++) {
4164 dataSet =
fData[0].GetDataSet(i,
false);
4165 if (dataSet ==
nullptr) {
4166 std::cerr << std::endl <<
">> PRunDataHandler::WriteMusrRootFile: **ERROR** Couldn't get data set (idx=" << i <<
")";
4167 std::cerr << std::endl <<
">> something is really wrong!" << std::endl;
4171 pathName.Form(
"DetectorInfo/Detector%03d/Name", histoNo);
4173 if (!str.CompareTo(
"n/a"))
4174 str.Form(
"Detector%3d", histoNo);
4175 header->Set(pathName, str);
4176 pathName.Form(
"DetectorInfo/Detector%03d/Histo Number", histoNo);
4177 header->Set(pathName, histoNo);
4178 pathName.Form(
"DetectorInfo/Detector%03d/Histo Length", histoNo);
4180 pathName.Form(
"DetectorInfo/Detector%03d/Time Zero Bin", histoNo);
4182 pathName.Form(
"DetectorInfo/Detector%03d/First Good Bin", histoNo);
4184 header->Set(pathName,
static_cast<Int_t
>(ival/
fAny2ManyInfo->rebin));
4185 pathName.Form(
"DetectorInfo/Detector%03d/Last Good Bin", histoNo);
4187 header->Set(pathName,
static_cast<Int_t
>(ival/
fAny2ManyInfo->rebin));
4191 str =
fData[0].GetCryoName()->Copy();
4192 header->Set(
"SampleEnvironmentInfo/Cryo", str);
4195 str =
fData[0].GetMagnetName()->Copy();
4196 header->Set(
"MagneticFieldEnvironmentInfo/Magnet Name", str);
4199 str =
fData[0].GetBeamline()->Copy();
4200 header->Set(
"BeamlineInfo/Name", str);
4203 std::vector<TH1F*> histos;
4204 TH1F *histo =
nullptr;
4207 for (UInt_t i=0; i<size; i++) {
4208 dataSet =
fData[0].GetDataSet(i,
false);
4209 if (dataSet ==
nullptr) {
4210 std::cerr << std::endl <<
">> PRunDataHandler::WriteMusrRootFile: **ERROR** Couldn't get data set (idx=" << i <<
")";
4211 std::cerr << std::endl <<
">> something is really wrong!" << std::endl;
4214 str.Form(
"hDecay%03d", dataSet->
GetHistoNo());
4215 length = dataSet->
GetData()->size();
4216 histo =
new TH1F(str.Data(), str.Data(), length+1, -0.5,
static_cast<Double_t
>(length)+0.5);
4217 Int_t sum=0, entries=0;
4218 for (UInt_t j=0; j<length; j++) {
4219 entries = dataSet->
GetData()->at(j);
4220 histo->SetBinContent(j+1, entries);
4223 histo->SetEntries(sum);
4224 histos.push_back(histo);
4227 UInt_t dataRebin = 0;
4228 UInt_t dataCount = 0;
4229 for (UInt_t i=0; i<size; i++) {
4230 dataSet =
fData[0].GetDataSet(i,
false);
4231 if (dataSet ==
nullptr) {
4232 std::cerr << std::endl <<
">> PRunDataHandler::WriteMusrRootFile: **ERROR** Couldn't get data set (idx=" << i <<
")";
4233 std::cerr << std::endl <<
">> something is really wrong!" << std::endl;
4236 str.Form(
"hDecay%03d", dataSet->
GetHistoNo());
4237 length = dataSet->
GetData()->size();
4238 histo =
new TH1F(str.Data(), str.Data(),
static_cast<Int_t
>(length/
fAny2ManyInfo->rebin)+1, -0.5,
static_cast<Double_t
>(
static_cast<Int_t
>(length/
fAny2ManyInfo->rebin))+0.5);
4240 Int_t sum=0, entries=0;
4241 for (UInt_t j=0; j<length; j++) {
4244 histo->SetBinContent(dataCount, dataRebin);
4247 entries = dataSet->
GetData()->at(j);
4249 dataRebin +=
static_cast<UInt_t
>(entries);
4251 histo->SetEntries(sum);
4252 histos.push_back(histo);
4258 for (UInt_t i=0; i<histos.size(); i++)
4259 decayAnaModule->Add(histos[i]);
4262 for (UInt_t i=0; i<histos.size(); i++)
4263 decayAnaDir->Add(histos[i]);
4267 if (header->FillFolder(runHeader))
4269 histosFolder->Write();
4271 if (header->FillDirectory(runHeaderDir)) {
4272 runHeaderDir->Write();
4285 is.open(fln.Data(), std::ios::binary);
4286 if (!is.is_open()) {
4287 std::cerr << std::endl <<
"PRunDataHandler::WriteMusrRootFile(): **ERROR** Couldn't open the root-file for streaming." << std::endl;
4293 is.seekg(0, std::ios::end);
4294 length = is.tellg();
4295 is.seekg(0, std::ios::beg);
4298 std::cerr << std::endl <<
"PRunDataHandler::WriteMusrRootFile(): **ERROR** Couldn't determine the root-file size." << std::endl;
4304 buffer =
new char [length];
4308 is.read(buffer, length);
4309 std::cout.write(buffer, length);
4525#ifdef PNEXUS_ENABLED
4526 std::string str{
""};
4533 std::cout << std::endl <<
">> PRunDataHandler::WriteNexusFile(): writing a NeXus data file (" << fln.Data() <<
") ... " << std::endl;
4535 if (format.Contains(
"HDF4", TString::kIgnoreCase)) {
4539 std::unique_ptr<nxH4::PNeXus>
nxs = std::make_unique<nxH4::PNeXus>();
4540 if (
nxs ==
nullptr) {
4541 std::cerr << std::endl <<
">> PRunDataHandler::WriteNexusFile(): **ERROR** couldn't invoke the NeXus object." << std::endl;
4546 nxs->AddGroupAttribute(
"/",
"NeXus_version", std::string(
"4.3.0"));
4549 nxs->AddGroupAttribute(
"/",
"HDF_version",
nxs->GetHdf4LibVersion());
4552 nxs->AddGroupAttribute(
"/",
"file_name", std::string(fln.Data()));
4556 nxs->AddGroupAttribute(
"/",
"file_time", dt);
4565 #ifdef HAVE_CONFIG_H
4566 str = PACKAGE_VERSION;
4568 nxs->AddDatasetAttribute<std::string>(
"/run/program_name",
"version", str);
4583 str = *
fData[0].GetLaboratory();
4587 str = *
fData[0].GetBeamline();
4591 str = std::string(
fData[0].GetStartDate()->Data()) + std::string(
"T") + std::string(
fData[0].GetStartTime()->Data());
4595 str = std::string(
fData[0].GetStopDate()->Data()) + std::string(
"T") + std::string(
fData[0].GetStopTime()->Data());
4612 nxs->AddDatasetAttribute<
float>(
"/run/sample/temperature",
"units", std::string(
"Kelvin"));
4616 nxs->AddDatasetAttribute<
float>(
"/run/sample/magnetic_field",
"units", std::string(
"Gauss"));
4626 nxs->AddDatasetAttribute<
float>(
"/run/sample/magnetic_field_vector",
"coordinate_system", std::string(
"cartesian"));
4627 nxs->AddDatasetAttribute<
float>(
"/run/sample/magnetic_field_vector",
"units", std::string(
"Gauss"));
4628 nxs->AddDatasetAttribute<
float>(
"/run/sample/magnetic_field_vector",
"available", 0);
4631 str = *
fData[0].GetInstrument();
4642 double total_counts = 0;
4644 for (
unsigned int i=0; i<
fData[0].GetNoOfHistos(); i++) {
4645 dataSet =
fData[0].GetDataSet(i,
false);
4646 if (dataSet ==
nullptr) {
4647 std::cerr << std::endl <<
">> PRunDataHandler::WriteNexusFile: **ERROR** Couldn't get data set (idx=0" << i <<
")";
4648 std::cerr << std::endl <<
">> something is really wrong!" << std::endl;
4651 for (
unsigned int j=0; j<dataSet->
GetData()->size(); j++)
4652 total_counts += dataSet->
GetData()->at(j);
4654 float total_counts_mev = (float) total_counts / 1.0e6;
4656 nxs->AddDatasetAttribute<
float>(
"/run/instrument/beam/total_counts",
"units", std::string(
"MEv"));
4661 nxs->AddDatasetAttribute<
float>(
"/run/histogram_data_1/resolution",
"units", std::string(
"picoseconds"));
4665 nxs->AddDatasetAttribute<
int>(
"/run/histogram_data_1/time_zero",
"units", std::string(
"microseconds"));
4666 nxs->AddDatasetAttribute<
int>(
"/run/histogram_data_1/time_zero",
"available", 0);
4670 dataSet =
fData[0].GetDataSet(0,
false);
4672 std::vector<float> time;
4673 for (
unsigned int i=0; i<length; i++)
4674 time.push_back(((
float)i+0.5)*res);
4676 nxs->AddDatasetAttribute<
float>(
"/run/histogram_data_1/raw_time",
"axis", 1);
4677 nxs->AddDatasetAttribute<
float>(
"/run/histogram_data_1/raw_time",
"primary", 0);
4678 nxs->AddDatasetAttribute<
float>(
"/run/histogram_data_1/raw_time",
"units", std::string(
"microseconds"));
4679 nxs->AddDatasetAttribute<
float>(
"/run/histogram_data_1/raw_time",
"available", 0);
4683 nxs->AddDatasetAttribute<
float>(
"/run/histogram_data_1/corrected_time",
"axis", 1);
4684 nxs->AddDatasetAttribute<
float>(
"/run/histogram_data_1/corrected_time",
"units", std::string(
"microseconds"));
4685 nxs->AddDatasetAttribute<
float>(
"/run/histogram_data_1/corrected_time",
"available", 0);
4688 std::vector<int> grouping(
fData[0].GetNoOfHistos(), 0);
4690 nxs->AddDatasetAttribute<
int>(
"/run/histogram_data_1/grouping",
"avaliabe", 0);
4695 nxs->AddDatasetAttribute<
int>(
"/run/histogram_data_1/alpha",
"avaliabe", 0);
4701 int noHisto, histoLength;
4703 noHisto =
fData[0].GetNoOfHistos();
4704 for (UInt_t i=0; i<
fData[0].GetNoOfHistos(); i++) {
4705 dataSet =
fData[0].GetDataSet(i,
false);
4706 if (dataSet ==
nullptr) {
4707 std::cerr << std::endl <<
">> PRunDataHandler::WriteNexusFile: **ERROR** Couldn't get data set (idx=" << i <<
")";
4708 std::cerr << std::endl <<
">> something is really wrong!" << std::endl;
4711 size = dataSet->
GetData()->size();
4713 for (UInt_t j=0; j<size; j++) {
4714 data.push_back((UInt_t)dataSet->
GetData()->at(j));
4718 UInt_t dataRebin = 0;
4719 UInt_t dataCount = 0;
4720 noHisto =
fData[0].GetNoOfHistos();
4721 for (UInt_t i=0; i<
fData[0].GetNoOfHistos(); i++) {
4722 dataSet =
fData[0].GetDataSet(i,
false);
4723 if (dataSet ==
nullptr) {
4724 std::cerr << std::endl <<
">> PRunDataHandler::WriteNexusFile: **ERROR** Couldn't get data set (idx=" << i <<
")";
4725 std::cerr << std::endl <<
">> something is really wrong!" << std::endl;
4728 size = dataSet->
GetData()->size();
4730 for (UInt_t j=0; j<size; j++) {
4733 data.push_back(dataRebin);
4736 dataRebin +=
static_cast<UInt_t
>(dataSet->
GetData()->at(j));
4742 nxs->AddDatasetAttribute<
int>(
"/run/histogram_data_1/counts",
"units", std::string(
"counts"));
4743 nxs->AddDatasetAttribute<
int>(
"/run/histogram_data_1/counts",
"signal", 1);
4744 nxs->AddDatasetAttribute<
int>(
"/run/histogram_data_1/counts",
"number", noHisto);
4745 nxs->AddDatasetAttribute<
int>(
"/run/histogram_data_1/counts",
"length", (int)size);
4746 nxs->AddDatasetAttribute<
int>(
"/run/histogram_data_1/counts",
"t0_bin", 0);
4747 nxs->AddDatasetAttribute<
int>(
"/run/histogram_data_1/counts",
"first_good_bin", 0);
4748 nxs->AddDatasetAttribute<
int>(
"/run/histogram_data_1/counts",
"last_good_bin", 0);
4750 nxs->AddDatasetAttribute<
int>(
"/run/histogram_data_1/counts",
"offset", res);
4752 nxs->AddGroupAttribute(
"/raw_data_1",
"NX_class", std::string(
"NXentry"));
4758 str = *
fData[0].GetBeamline();
4771 str = std::string(
fData[0].GetStartDate()->Data()) + std::string(
"T") + std::string(
fData[0].GetStartTime()->Data());
4773 nxs->AddDatasetAttribute<std::string>(
"/raw_data_1/start_time",
"units",
"ISO8601");
4776 str = std::string(
fData[0].GetStopDate()->Data()) + std::string(
"T") + std::string(
fData[0].GetStopTime()->Data());
4778 nxs->AddDatasetAttribute<std::string>(
"/raw_data_1/end_time",
"units",
"ISO8601");
4785 nxs->AddGroupAttribute(
"/raw_data_1/instrument",
"NX_class", std::string(
"NXinstrument"));
4788 str = *
fData[0].GetInstrument();
4792 nxs->AddGroupAttribute(
"/raw_data_1/instrument/source",
"NX_class", std::string(
"NXsource"));
4795 str =
fData[0].GetLaboratory()->Data();
4799 TString tstr = *
fData[0].GetInstrument();
4800 std::string type{
"n/a"};
4801 if (tstr.Contains(
"LEM", TString::kIgnoreCase)) {
4802 type =
"low energy muon source";
4803 }
else if (tstr.Contains(
"GPS", TString::kIgnoreCase) || tstr.Contains(
"GPD", TString::kIgnoreCase) ||
4804 tstr.Contains(
"LTF", TString::kIgnoreCase) || tstr.Contains(
"FLAME", TString::kIgnoreCase) ||
4805 tstr.Contains(
"HAL-9500", TString::kIgnoreCase) || tstr.Contains(
"DOLLY", TString::kIgnoreCase) ||
4806 tstr.Contains(
"VMS", TString::kIgnoreCase)) {
4807 type =
"quasi-continous muon source";
4808 }
else if (tstr.Contains(
"EMU", TString::kIgnoreCase) || tstr.Contains(
"MUSR", TString::kIgnoreCase) ||
4809 tstr.Contains(
"HIFI", TString::kIgnoreCase)) {
4810 type =
"pulsed muon source";
4815 str =
"positive muons";
4819 nxs->AddGroupAttribute(
"/raw_data_1/instrument/detector_1",
"NX_class", std::string(
"NXdetector"));
4822 int noHistos =
fData[0].GetNoOfHistos();
4823 std::vector<int> spectrum_index(noHistos);
4824 for (
unsigned int i=0; i<spectrum_index.size(); i++)
4825 spectrum_index[i] = i+1;
4826 nxs->AddDataset<
int>(
"/raw_data_1/instrument/detector_1/spectrum_index", spectrum_index, {(uint32_t)spectrum_index.size()},
nxH4::H4DataType::kINT32);
4831 nxs->AddDatasetAttribute<
int>(
"/raw_data_1/instrument/detector_1/raw_time",
"available", 0);
4839 int noHisto, histoLength;
4841 noHisto =
fData[0].GetNoOfHistos();
4842 for (UInt_t i=0; i<
fData[0].GetNoOfHistos(); i++) {
4843 dataSet =
fData[0].GetDataSet(i,
false);
4844 if (dataSet ==
nullptr) {
4845 std::cerr << std::endl <<
">> PRunDataHandler::WriteNexusFile: **ERROR** Couldn't get data set (idx=" << i <<
")";
4846 std::cerr << std::endl <<
">> something is really wrong!" << std::endl;
4849 size = dataSet->GetData()->size();
4851 for (UInt_t j=0; j<size; j++) {
4852 data.push_back((UInt_t)dataSet->GetData()->at(j));
4856 UInt_t dataRebin = 0;
4857 UInt_t dataCount = 0;
4858 noHisto =
fData[0].GetNoOfHistos();
4859 for (UInt_t i=0; i<
fData[0].GetNoOfHistos(); i++) {
4860 dataSet =
fData[0].GetDataSet(i,
false);
4861 if (dataSet ==
nullptr) {
4862 std::cerr << std::endl <<
">> PRunDataHandler::WriteNexusFile: **ERROR** Couldn't get data set (idx=" << i <<
")";
4863 std::cerr << std::endl <<
">> something is really wrong!" << std::endl;
4866 size = dataSet->GetData()->size();
4868 for (UInt_t j=0; j<size; j++) {
4871 data.push_back(dataRebin);
4874 dataRebin +=
static_cast<UInt_t
>(dataSet->GetData()->at(j));
4879 nxs->AddDataset<
int>(
"/raw_data_1/instrument/detector_1/counts", data, {(uint32_t)noHisto, (uint32_t)size},
nxH4::H4DataType::kINT32);
4880 nxs->AddDatasetAttribute<
int>(
"/raw_data_1/instrument/detector_1/counts",
"axes", std::string(
"spectrum_index,time_bin"));
4881 nxs->AddDatasetAttribute<
int>(
"/raw_data_1/instrument/detector_1/counts",
"long_name", std::string(
"positon counts"));
4882 nxs->AddDatasetAttribute<
int>(
"/raw_data_1/instrument/detector_1/counts",
"signal", 1);
4884 std::vector<int> t0_bin;
4885 for (
unsigned int i=0; i<
fData[0].GetNoOfHistos(); i++)
4887 nxs->AddDatasetAttribute<
int>(
"/raw_data_1/instrument/detector_1/counts",
"t0_bin", {t0_bin});
4888 nxs->AddDatasetAttribute<
int>(
"/raw_data_1/instrument/detector_1/counts",
"units", std::string(
"counts"));
4891 nxs->AddGroupAttribute(
"/raw_data_1/detector_1",
"NX_class", std::string(
"NXdata"));
4895 nxs->AddDatasetAttribute<
int>(
"/raw_data_1/detector_1/counts",
"axes", std::string(
"spectrum_index,time_bin"));
4896 nxs->AddDatasetAttribute<
int>(
"/raw_data_1/detector_1/counts",
"long_name", std::string(
"positon counts"));
4897 nxs->AddDatasetAttribute<
int>(
"/raw_data_1/detector_1/counts",
"signal", 1);
4902 std::cerr << std::endl <<
"**ERROR** PRunDataHandler::WriteNexusFile, fln=" << fln << std::endl;
4905 }
catch (
const std::runtime_error& e) {
4906 std::cerr << std::endl <<
"HDF4 error: " << e.what() << std::endl;
4913 std::unique_ptr<nxH5::PNeXus>
nxs = std::make_unique<nxH5::PNeXus>();
4914 if (
nxs ==
nullptr) {
4915 std::cerr << std::endl <<
">> PRunDataHandler::WriteNexusFile(): **ERROR** couldn't invoke the NeXus object." << std::endl;
4920 nxs->AddGroupAttribute(
"/",
"NeXus_version", std::string(
"4.3.0"));
4923 nxs->AddGroupAttribute(
"/",
"HDF_version",
nxs->GetHdf5LibVersion());
4926 nxs->AddGroupAttribute(
"/",
"file_name", std::string(fln.Data()));
4930 nxs->AddGroupAttribute(
"/",
"file_time", dt);
4934 nxs->AddDataset<
int>(
"/run/IDF_version", {(int)
fAny2ManyInfo->idf}, {1}, H5::PredType::NATIVE_INT32);
4937 nxs->AddDataset<std::string>(
"/run/program_name", {
"any2many"}, {1}, H5::StrType(H5::PredType::C_S1, H5T_VARIABLE));
4939 #ifdef HAVE_CONFIG_H
4940 str = PACKAGE_VERSION;
4942 nxs->AddDatasetAttribute<std::string>(
"/run/program_name",
"version", str);
4945 nxs->AddDataset<
int>(
"/run/number", {
fData[0].GetRunNumber()}, {1}, H5::PredType::NATIVE_INT32);
4948 nxs->AddDataset<std::string>(
"/run/title", {
fData[0].GetRunTitle()->Data()}, {1}, H5::StrType(H5::PredType::C_S1, H5T_VARIABLE));
4951 nxs->AddDataset<std::string>(
"/run/notes", {std::string(
"n/a")}, {1}, H5::StrType(H5::PredType::C_S1, H5T_VARIABLE));
4954 nxs->AddDataset<std::string>(
"/run/analysis", {std::string(
"muonTD")}, {1}, H5::StrType(H5::PredType::C_S1, H5T_VARIABLE));
4957 str = *
fData[0].GetLaboratory();
4958 nxs->AddDataset<std::string>(
"/run/lab", {str}, {1}, H5::StrType(H5::PredType::C_S1, H5T_VARIABLE));
4961 str = *
fData[0].GetBeamline();
4962 nxs->AddDataset<std::string>(
"/run/beamline", {str}, {1}, H5::StrType(H5::PredType::C_S1, H5T_VARIABLE));
4965 str = std::string(
fData[0].GetStartDate()->Data()) + std::string(
"T") + std::string(
fData[0].GetStartTime()->Data());
4966 nxs->AddDataset<std::string>(
"/run/start_time", {str}, {1}, H5::StrType(H5::PredType::C_S1, H5T_VARIABLE));
4969 str = std::string(
fData[0].GetStopDate()->Data()) + std::string(
"T") + std::string(
fData[0].GetStopTime()->Data());
4970 nxs->AddDataset<std::string>(
"/run/stop_time", {str}, {1}, H5::StrType(H5::PredType::C_S1, H5T_VARIABLE));
4973 nxs->AddDataset<
int>(
"/run/switching_states", {1}, {1}, H5::PredType::NATIVE_INT32);
4976 nxs->AddDataset<std::string>(
"/run/user/name", {std::string(
"n/a")}, {1}, H5::StrType(H5::PredType::C_S1, H5T_VARIABLE));
4979 nxs->AddDataset<std::string>(
"/run/user/experiment_number", {std::string(
"n/a")}, {1}, H5::StrType(H5::PredType::C_S1, H5T_VARIABLE));
4982 nxs->AddDataset<std::string>(
"/run/sample/name", {
fData[0].GetSample()->Data()}, {1}, H5::StrType(H5::PredType::C_S1, H5T_VARIABLE));
4985 nxs->AddDataset<
float>(
"/run/sample/temperature", {(float)
fData[0].GetTemperature(0)}, {1}, H5::PredType::NATIVE_FLOAT);
4986 nxs->AddDatasetAttribute<
float>(
"/run/sample/temperature",
"units", std::string(
"Kelvin"));
4989 nxs->AddDataset<
float>(
"/run/sample/magnetic_field", {(float)
fData[0].GetField()}, {1}, H5::PredType::NATIVE_FLOAT);
4990 nxs->AddDatasetAttribute<
float>(
"/run/sample/magnetic_field",
"units", std::string(
"Gauss"));
4993 nxs->AddDataset<std::string>(
"/run/sample/environment", {
fData[0].GetSetup()->Data()}, {1}, H5::StrType(H5::PredType::C_S1, H5T_VARIABLE));
4996 nxs->AddDataset<std::string>(
"/run/sample/shape", {std::string(
"n/a")}, {1}, H5::StrType(H5::PredType::C_S1, H5T_VARIABLE));
4999 nxs->AddDataset<
float>(
"/run/sample/magnetic_field_vector", {1.0, 1.0, 1.0}, {3}, H5::PredType::NATIVE_FLOAT);
5000 nxs->AddDatasetAttribute<
float>(
"/run/sample/magnetic_field_vector",
"coordinate_system", std::string(
"cartesian"));
5001 nxs->AddDatasetAttribute<
float>(
"/run/sample/magnetic_field_vector",
"units", std::string(
"Gauss"));
5002 nxs->AddDatasetAttribute<
float>(
"/run/sample/magnetic_field_vector",
"available", 0);
5005 str = *
fData[0].GetInstrument();
5006 nxs->AddDataset<std::string>(
"/run/instrument/name", {str}, {1}, H5::StrType(H5::PredType::C_S1, H5T_VARIABLE));
5009 nxs->AddDataset<
int>(
"/run/instrument/detector/number", {(int)
fData[0].GetNoOfHistos()}, {1}, H5::PredType::NATIVE_INT32);
5012 nxs->AddDataset<std::string>(
"/run/instrument/collimator/type", {std::string(
"n/a")}, {1}, H5::StrType(H5::PredType::C_S1, H5T_VARIABLE));
5016 double total_counts = 0;
5018 for (
unsigned int i=0; i<
fData[0].GetNoOfHistos(); i++) {
5019 dataSet =
fData[0].GetDataSet(i,
false);
5020 if (dataSet ==
nullptr) {
5021 std::cerr << std::endl <<
">> PRunDataHandler::WriteNexusFile: **ERROR** Couldn't get data set (idx=0" << i <<
")";
5022 std::cerr << std::endl <<
">> something is really wrong!" << std::endl;
5025 for (
unsigned int j=0; j<dataSet->
GetData()->size(); j++)
5026 total_counts += dataSet->
GetData()->at(j);
5028 float total_counts_mev = (float) total_counts / 1.0e6;
5029 nxs->AddDataset<
float>(
"/run/instrument/beam/total_counts", {total_counts_mev}, {1}, H5::PredType::NATIVE_FLOAT);
5030 nxs->AddDatasetAttribute<
float>(
"/run/instrument/beam/total_counts",
"units", std::string(
"MEv"));
5034 nxs->AddDataset<
float>(
"/run/histogram_data_1/resolution", {res}, {1}, H5::PredType::NATIVE_FLOAT);
5035 nxs->AddDatasetAttribute<
float>(
"/run/histogram_data_1/resolution",
"units", std::string(
"picoseconds"));
5038 nxs->AddDataset<
int>(
"/run/histogram_data_1/time_zero", {0}, {1}, H5::PredType::NATIVE_INT32);
5039 nxs->AddDatasetAttribute<
int>(
"/run/histogram_data_1/time_zero",
"units", std::string(
"microseconds"));
5040 nxs->AddDatasetAttribute<
int>(
"/run/histogram_data_1/time_zero",
"available", 0);
5044 dataSet =
fData[0].GetDataSet(0,
false);
5046 std::vector<float> time;
5047 for (
unsigned int i=0; i<length; i++)
5048 time.push_back(((
float)i+0.5)*res);
5049 nxs->AddDataset<
float>(
"/run/histogram_data_1/raw_time", time, {length}, H5::PredType::NATIVE_FLOAT);
5050 nxs->AddDatasetAttribute<
float>(
"/run/histogram_data_1/raw_time",
"axis", 1);
5051 nxs->AddDatasetAttribute<
float>(
"/run/histogram_data_1/raw_time",
"primary", 0);
5052 nxs->AddDatasetAttribute<
float>(
"/run/histogram_data_1/raw_time",
"units", std::string(
"microseconds"));
5053 nxs->AddDatasetAttribute<
float>(
"/run/histogram_data_1/raw_time",
"available", 0);
5056 nxs->AddDataset<
float>(
"/run/histogram_data_1/corrected_time", time, {length}, H5::PredType::NATIVE_FLOAT);
5057 nxs->AddDatasetAttribute<
float>(
"/run/histogram_data_1/corrected_time",
"axis", 1);
5058 nxs->AddDatasetAttribute<
float>(
"/run/histogram_data_1/corrected_time",
"units", std::string(
"microseconds"));
5059 nxs->AddDatasetAttribute<
float>(
"/run/histogram_data_1/corrected_time",
"available", 0);
5062 std::vector<int> grouping(
fData[0].GetNoOfHistos(), 0);
5063 nxs->AddDataset<
int>(
"/run/histogram_data_1/grouping", grouping, {grouping.size()}, H5::PredType::NATIVE_INT32);
5064 nxs->AddDatasetAttribute<
int>(
"/run/histogram_data_1/grouping",
"avaliabe", 0);
5068 nxs->AddDataset<
int>(
"/run/histogram_data_1/alpha", {ival}, {1}, H5::PredType::NATIVE_INT32);
5069 nxs->AddDatasetAttribute<
int>(
"/run/histogram_data_1/alpha",
"avaliabe", 0);
5075 int noHisto, histoLength;
5077 noHisto =
fData[0].GetNoOfHistos();
5078 for (UInt_t i=0; i<
fData[0].GetNoOfHistos(); i++) {
5079 dataSet =
fData[0].GetDataSet(i,
false);
5080 if (dataSet ==
nullptr) {
5081 std::cerr << std::endl <<
">> PRunDataHandler::WriteNexusFile: **ERROR** Couldn't get data set (idx=" << i <<
")";
5082 std::cerr << std::endl <<
">> something is really wrong!" << std::endl;
5085 size = dataSet->
GetData()->size();
5087 for (UInt_t j=0; j<size; j++) {
5088 data.push_back((UInt_t)dataSet->
GetData()->at(j));
5092 UInt_t dataRebin = 0;
5093 UInt_t dataCount = 0;
5094 noHisto =
fData[0].GetNoOfHistos();
5095 for (UInt_t i=0; i<
fData[0].GetNoOfHistos(); i++) {
5096 dataSet =
fData[0].GetDataSet(i,
false);
5097 if (dataSet ==
nullptr) {
5098 std::cerr << std::endl <<
">> PRunDataHandler::WriteNexusFile: **ERROR** Couldn't get data set (idx=" << i <<
")";
5099 std::cerr << std::endl <<
">> something is really wrong!" << std::endl;
5102 size = dataSet->
GetData()->size();
5104 for (UInt_t j=0; j<size; j++) {
5107 data.push_back(dataRebin);
5110 dataRebin +=
static_cast<UInt_t
>(dataSet->
GetData()->at(j));
5115 nxs->AddDataset<
int>(
"/run/histogram_data_1/counts", data, {(
long unsigned int)noHisto, size}, H5::PredType::NATIVE_INT32);
5116 nxs->AddDatasetAttribute<
int>(
"/run/histogram_data_1/counts",
"units", std::string(
"counts"));
5117 nxs->AddDatasetAttribute<
int>(
"/run/histogram_data_1/counts",
"signal", 1);
5118 nxs->AddDatasetAttribute<
int>(
"/run/histogram_data_1/counts",
"number", noHisto);
5119 nxs->AddDatasetAttribute<
int>(
"/run/histogram_data_1/counts",
"length", size);
5120 nxs->AddDatasetAttribute<
int>(
"/run/histogram_data_1/counts",
"t0_bin", 0);
5121 nxs->AddDatasetAttribute<
int>(
"/run/histogram_data_1/counts",
"first_good_bin", 0);
5122 nxs->AddDatasetAttribute<
int>(
"/run/histogram_data_1/counts",
"last_good_bin", 0);
5124 nxs->AddDatasetAttribute<
int>(
"/run/histogram_data_1/counts",
"offset", res);
5126 nxs->AddGroupAttribute(
"/raw_data_1",
"NX_class", std::string(
"NXentry"));
5129 nxs->AddDataset<
int>(
"/raw_data_1/IDF_version", {(int)
fAny2ManyInfo->idf}, {1}, H5::PredType::NATIVE_INT32);
5132 str = *
fData[0].GetBeamline();
5133 nxs->AddDataset<std::string>(
"/raw_data_1/beamline", {str}, {1}, H5::StrType(H5::PredType::C_S1, H5T_VARIABLE));
5136 nxs->AddDataset<std::string>(
"/raw_data_1/definition", {std::string(
"muonTD")}, {1}, H5::StrType(H5::PredType::C_S1, H5T_VARIABLE));
5139 nxs->AddDataset<
int>(
"/raw_data_1/run_number", {
fData[0].GetRunNumber()}, {1}, H5::PredType::NATIVE_INT32);
5142 nxs->AddDataset<std::string>(
"/raw_data_1/title", {
fData[0].GetRunTitle()->Data()}, {1}, H5::StrType(H5::PredType::C_S1, H5T_VARIABLE));
5145 str = std::string(
fData[0].GetStartDate()->Data()) + std::string(
"T") + std::string(
fData[0].GetStartTime()->Data());
5146 nxs->AddDataset<std::string>(
"/raw_data_1/start_time", {str}, {1}, H5::StrType(H5::PredType::C_S1, H5T_VARIABLE));
5147 nxs->AddDatasetAttribute<std::string>(
"/raw_data_1/start_time",
"units",
"ISO8601");
5150 str = std::string(
fData[0].GetStopDate()->Data()) + std::string(
"T") + std::string(
fData[0].GetStopTime()->Data());
5151 nxs->AddDataset<std::string>(
"/raw_data_1/end_time", {str}, {1}, H5::StrType(H5::PredType::C_S1, H5T_VARIABLE));
5152 nxs->AddDatasetAttribute<std::string>(
"/raw_data_1/end_time",
"units",
"ISO8601");
5156 nxs->AddDataset<std::string>(
"/raw_data_1/experiment_identifier", {str}, {1}, H5::StrType(H5::PredType::C_S1, H5T_VARIABLE));
5159 nxs->AddGroupAttribute(
"/raw_data_1/instrument",
"NX_class", std::string(
"NXinstrument"));
5162 str = *
fData[0].GetInstrument();
5163 nxs->AddDataset<std::string>(
"/raw_data_1/instrument/name", {str}, {1}, H5::StrType(H5::PredType::C_S1, H5T_VARIABLE));
5166 nxs->AddGroupAttribute(
"/raw_data_1/instrument/source",
"NX_class", std::string(
"NXsource"));
5169 str =
fData[0].GetLaboratory()->Data();
5170 nxs->AddDataset<std::string>(
"/raw_data_1/instrument/source/name", {str}, {1}, H5::StrType(H5::PredType::C_S1, H5T_VARIABLE));
5173 TString tstr = *
fData[0].GetInstrument();
5174 std::string type{
"n/a"};
5175 if (tstr.Contains(
"LEM", TString::kIgnoreCase)) {
5176 type =
"low energy muon source";
5177 }
else if (tstr.Contains(
"GPS", TString::kIgnoreCase) || tstr.Contains(
"GPD", TString::kIgnoreCase) ||
5178 tstr.Contains(
"LTF", TString::kIgnoreCase) || tstr.Contains(
"FLAME", TString::kIgnoreCase) ||
5179 tstr.Contains(
"HAL-9500", TString::kIgnoreCase) || tstr.Contains(
"DOLLY", TString::kIgnoreCase) ||
5180 tstr.Contains(
"VMS", TString::kIgnoreCase)) {
5181 type =
"quasi-continous muon source";
5182 }
else if (tstr.Contains(
"EMU", TString::kIgnoreCase) || tstr.Contains(
"MUSR", TString::kIgnoreCase) ||
5183 tstr.Contains(
"HIFI", TString::kIgnoreCase)) {
5184 type =
"pulsed muon source";
5186 nxs->AddDataset<std::string>(
"/raw_data_1/instrument/source/type", {type}, {1}, H5::StrType(H5::PredType::C_S1, H5T_VARIABLE));
5189 str =
"positive muons";
5190 nxs->AddDataset<std::string>(
"/raw_data_1/instrument/source/probe", {str}, {1}, H5::StrType(H5::PredType::C_S1, H5T_VARIABLE));
5193 nxs->AddGroupAttribute(
"/raw_data_1/instrument/detector_1",
"NX_class", std::string(
"NXdetector"));
5196 int noHistos =
fData[0].GetNoOfHistos();
5197 std::vector<int> spectrum_index(noHistos);
5198 for (
unsigned int i=0; i<spectrum_index.size(); i++)
5199 spectrum_index[i] = i+1;
5200 nxs->AddDataset<
int>(
"/raw_data_1/instrument/detector_1/spectrum_index", spectrum_index, {spectrum_index.size()}, H5::PredType::NATIVE_INT32);
5204 nxs->AddDataset<
int>(
"/raw_data_1/instrument/detector_1/raw_time", {ival}, {1}, H5::PredType::NATIVE_INT32);
5205 nxs->AddDatasetAttribute<
int>(
"/raw_data_1/instrument/detector_1/raw_time",
"available", 0);
5213 int noHisto, histoLength;
5215 noHisto =
fData[0].GetNoOfHistos();
5216 for (UInt_t i=0; i<
fData[0].GetNoOfHistos(); i++) {
5217 dataSet =
fData[0].GetDataSet(i,
false);
5218 if (dataSet ==
nullptr) {
5219 std::cerr << std::endl <<
">> PRunDataHandler::WriteNexusFile: **ERROR** Couldn't get data set (idx=" << i <<
")";
5220 std::cerr << std::endl <<
">> something is really wrong!" << std::endl;
5223 size = dataSet->GetData()->size();
5225 for (UInt_t j=0; j<size; j++) {
5226 data.push_back((UInt_t)dataSet->GetData()->at(j));
5230 UInt_t dataRebin = 0;
5231 UInt_t dataCount = 0;
5232 noHisto =
fData[0].GetNoOfHistos();
5233 for (UInt_t i=0; i<
fData[0].GetNoOfHistos(); i++) {
5234 dataSet =
fData[0].GetDataSet(i,
false);
5235 if (dataSet ==
nullptr) {
5236 std::cerr << std::endl <<
">> PRunDataHandler::WriteNexusFile: **ERROR** Couldn't get data set (idx=" << i <<
")";
5237 std::cerr << std::endl <<
">> something is really wrong!" << std::endl;
5240 size = dataSet->GetData()->size();
5242 for (UInt_t j=0; j<size; j++) {
5245 data.push_back(dataRebin);
5248 dataRebin +=
static_cast<UInt_t
>(dataSet->GetData()->at(j));
5253 nxs->AddDataset<
int>(
"/raw_data_1/instrument/detector_1/counts", data, {(
long unsigned int)noHisto, size}, H5::PredType::NATIVE_INT32);
5254 nxs->AddDatasetAttribute<
int>(
"/raw_data_1/instrument/detector_1/counts",
"axes", std::string(
"spectrum_index,time_bin"));
5255 nxs->AddDatasetAttribute<
int>(
"/raw_data_1/instrument/detector_1/counts",
"long_name", std::string(
"positon counts"));
5256 nxs->AddDatasetAttribute<
int>(
"/raw_data_1/instrument/detector_1/counts",
"signal", 1);
5258 std::vector<int> t0_bin;
5259 for (
unsigned int i=0; i<
fData[0].GetNoOfHistos(); i++)
5261 nxs->AddDatasetAttribute<
int>(
"/raw_data_1/instrument/detector_1/counts",
"t0_bin", {t0_bin});
5262 nxs->AddDatasetAttribute<
int>(
"/raw_data_1/instrument/detector_1/counts",
"units", std::string(
"counts"));
5265 nxs->AddGroupAttribute(
"/raw_data_1/detector_1",
"NX_class", std::string(
"NXdata"));
5268 nxs->AddDataset<
int>(
"/raw_data_1/detector_1/counts", data, {(
long unsigned int)noHisto, size}, H5::PredType::NATIVE_INT32);
5269 nxs->AddDatasetAttribute<
int>(
"/raw_data_1/detector_1/counts",
"axes", std::string(
"spectrum_index,time_bin"));
5270 nxs->AddDatasetAttribute<
int>(
"/raw_data_1/detector_1/counts",
"long_name", std::string(
"positon counts"));
5271 nxs->AddDatasetAttribute<
int>(
"/raw_data_1/detector_1/counts",
"signal", 1);
5276 std::cerr << std::endl <<
"**ERROR** PRunDataHandler::WriteNexusFile, fln=" << fln << std::endl;
5279 }
catch (
const H5::Exception& e) {
5280 std::cerr << std::endl <<
"HDF5 error: " << e.getDetailMsg() << std::endl;
5286 std::cout << std::endl <<
">> PRunDataHandler::WriteNexusFile(): Sorry, not enabled at configuration level, i.e. -Dnexus=1 when executing configure" << std::endl << std::endl;