Merged muonspin/musrfit:root6 into master

This commit is contained in:
Zaher Salman 2023-05-22 09:18:22 +02:00
commit 56a8730252
7 changed files with 143 additions and 14 deletions

View File

@ -1,7 +1,7 @@
# - musrfit # - musrfit
cmake_minimum_required(VERSION 3.17) cmake_minimum_required(VERSION 3.17)
project(musrfit VERSION 1.9.0 LANGUAGES C CXX) project(musrfit VERSION 1.9.1 LANGUAGES C CXX)
#--- musrfit specific options ------------------------------------------------- #--- musrfit specific options -------------------------------------------------
option(nexus "build optional NeXus support. Needed for ISIS" OFF) option(nexus "build optional NeXus support. Needed for ISIS" OFF)

View File

@ -12,6 +12,13 @@ or
https://bitbucket.org/muonspin/musrfit/commits/all https://bitbucket.org/muonspin/musrfit/commits/all
Release of V1.9.1, 2023/05/16
=============================
add option [-c, --count] to dump_header which will dump the number of counts
per detector and the total number of counts. Currently for MusrRoot data format
only. For the other data formats it will be implement asap
Release of V1.9.0, 2023/02/17 Release of V1.9.0, 2023/02/17
============================= =============================

View File

@ -52,6 +52,8 @@
#include <TFile.h> #include <TFile.h>
#include <TFolder.h> #include <TFolder.h>
#include <TString.h> #include <TString.h>
#include <TFolder.h>
#include <TH1F.h>
#ifdef HAVE_GIT_REV_H #ifdef HAVE_GIT_REV_H
#include "git-revision.h" #include "git-revision.h"
@ -78,7 +80,8 @@
void dump_header_syntax() void dump_header_syntax()
{ {
std::cout << std::endl << "usage: dump_header [-rn <runNo> | -fn <fileName>] [-ff, --fileFormat <fileFormat>]"; std::cout << std::endl << "usage: dump_header [-rn <runNo> | -fn <fileName>] [-ff, --fileFormat <fileFormat>]";
std::cout << std::endl << " [-y, --year <year>] [-s, --summary] [--psi-bulk <opt>] |"; std::cout << std::endl << " [-y, --year <year>] [-s, --summary] [-i, --instrument <inst>]";
std::cout << std::endl << " [-c, --counts] | ";
std::cout << std::endl << " --help | --version"; std::cout << std::endl << " --help | --version";
std::cout << std::endl; std::cout << std::endl;
std::cout << std::endl << " Dumps the header information of a given muSR data file onto the standard output."; std::cout << std::endl << " Dumps the header information of a given muSR data file onto the standard output.";
@ -97,6 +100,7 @@ void dump_header_syntax()
std::cout << std::endl << " to the header information, print the summary file content."; std::cout << std::endl << " to the header information, print the summary file content.";
std::cout << std::endl << " -i, --instrument <inst> : where <inst> is the requested instrument:"; std::cout << std::endl << " -i, --instrument <inst> : where <inst> is the requested instrument:";
std::cout << std::endl << " lem (default) | gps | ltf | dolly | gpd | hifi."; std::cout << std::endl << " lem (default) | gps | ltf | dolly | gpd | hifi.";
std::cout << std::endl << " -c, --counts : will show detector counts as well.";
std::cout << std::endl << " -h, --help : will show this help"; std::cout << std::endl << " -h, --help : will show this help";
std::cout << std::endl << " -v, --version : will show the current version."; std::cout << std::endl << " -v, --version : will show the current version.";
std::cout << std::endl << std::endl; std::cout << std::endl << std::endl;
@ -108,10 +112,11 @@ void dump_header_syntax()
* *
* @param fileName file name of the ROOT file * @param fileName file name of the ROOT file
* @param summary bool, if true dump the summary * @param summary bool, if true dump the summary
* @param counts bool, if true dump detector counts
* *
* @return 0 on success, otherwise 1. * @return 0 on success, otherwise 1.
*/ */
int dump_header_root(const std::string fileName, const bool summary) int dump_header_root(const std::string fileName, const bool summary, const bool counts)
{ {
TFile f(fileName.c_str()); TFile f(fileName.c_str());
if (f.IsZombie()) { if (f.IsZombie()) {
@ -122,6 +127,8 @@ int dump_header_root(const std::string fileName, const bool summary)
} }
UInt_t fileType = DH_MUSR_ROOT; UInt_t fileType = DH_MUSR_ROOT;
UInt_t noOfHistos{0};
PIntVector redGreenOffset;
TFolder *folder; TFolder *folder;
f.GetObject("RunInfo", folder); // try first LEM-ROOT style file (used until 2011). f.GetObject("RunInfo", folder); // try first LEM-ROOT style file (used until 2011).
@ -208,6 +215,18 @@ int dump_header_root(const std::string fileName, const bool summary)
header->DumpHeader(); header->DumpHeader();
if (counts) {
bool ok;
Int_t ival;
PIntVector ivec;
header->Get("RunInfo/No of Histos", ival, ok);
if (ok)
noOfHistos = ival;
header->Get("RunInfo/RedGreen Offsets", ivec, ok);
if (ok)
redGreenOffset = ivec;
}
delete header; delete header;
} }
@ -232,6 +251,38 @@ int dump_header_root(const std::string fileName, const bool summary)
} }
} }
// detector counts as well?
if (counts && (fileType == DH_MUSR_ROOT)) {
// dump the detector counts
std::cout << "Detector counts" << std::endl;
f.GetObject("histos", folder);
if (folder != nullptr) {
char detectorLabel[64];
TH1F *histo{nullptr};
UInt_t total{0};
for (UInt_t i=0; i<redGreenOffset.size(); i++) {
std::cout << " Group " << i+1 << " (Offset=" << redGreenOffset[i] << ") : " << std::endl;
total = 0;
for (UInt_t j=0; j<noOfHistos; j++) {
snprintf(detectorLabel, sizeof(detectorLabel), "hDecay%03d", redGreenOffset[i]+j+1);
histo = (TH1F*) folder->FindObjectAny(detectorLabel);
if (histo != nullptr) {
std::cout << " " << histo->GetTitle() << ":\t " << histo->GetEntries() << std::endl;
total += histo->GetEntries();
}
}
if (i % 2 == 0)
std::cout << " total counts of group " << i+1 << ":\t\t\t " << total << std::endl;
else
std::cout << " total counts of group " << i+1 << ":\t\t\t\t\t " << total << std::endl;
}
} else {
std::cout << "Sorry, no histos folder found" << std::endl;
f.Close();
return 0;
}
}
f.Close(); f.Close();
return 0; return 0;
@ -242,10 +293,11 @@ int dump_header_root(const std::string fileName, const bool summary)
* <p>dumps the header information of a NeXus file. * <p>dumps the header information of a NeXus file.
* *
* @param fileName file name of the NeXus file. * @param fileName file name of the NeXus file.
* @param counts bool, if true dump detector counts
* *
* @return 0 on success, 1 otherwise * @return 0 on success, 1 otherwise
*/ */
int dump_header_nexus(const std::string fileName) { int dump_header_nexus(const std::string fileName, const bool counts) {
#ifdef PNEXUS_ENABLED #ifdef PNEXUS_ENABLED
PNeXus *nxs_file = new PNeXus(fileName.c_str()); PNeXus *nxs_file = new PNeXus(fileName.c_str());
@ -258,7 +310,7 @@ int dump_header_nexus(const std::string fileName) {
} }
if (nxs_file->IsValid(false)) { if (nxs_file->IsValid(false)) {
nxs_file->Dump(); nxs_file->Dump(counts);
} else { } else {
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << "**ERROR** found invalid NeXus file." << std::endl; std::cerr << "**ERROR** found invalid NeXus file." << std::endl;
@ -344,10 +396,11 @@ std::vector<std::string> dump_header_instrument_info(std::string fileName)
* *
* @param fileName file name of the PSI-BIN * @param fileName file name of the PSI-BIN
* @param fileFormat either PSI-BIN or PSI-MDU * @param fileFormat either PSI-BIN or PSI-MDU
* @param counts bool, if true dump detector counts
* *
* @return 0 on success, 1 otherwise * @return 0 on success, 1 otherwise
*/ */
int dump_header_psi_bin(const std::string fileName, const std::string fileFormat) int dump_header_psi_bin(const std::string fileName, const std::string fileFormat, const bool counts)
{ {
MuSR_td_PSI_bin psiBin; MuSR_td_PSI_bin psiBin;
int status; int status;
@ -439,7 +492,8 @@ int dump_header_psi_bin(const std::string fileName, const std::string fileFormat
std::cout << std::endl << "Time Zero Bin : " << psiBin.GetT0Int(i); std::cout << std::endl << "Time Zero Bin : " << psiBin.GetT0Int(i);
std::cout << std::endl << "First Good Bin : " << psiBin.GetFirstGoodInt(i); std::cout << std::endl << "First Good Bin : " << psiBin.GetFirstGoodInt(i);
std::cout << std::endl << "Last Good Bin : " << psiBin.GetLastGoodInt(i); std::cout << std::endl << "Last Good Bin : " << psiBin.GetLastGoodInt(i);
std::cout << std::endl << "No of Events : " << psiBin.GetEventsHistoLong(i); if (counts)
std::cout << std::endl << "No of Events : " << psiBin.GetEventsHistoLong(i);
} }
std::cout << std::endl << "-------------------" << std::endl << std::endl; std::cout << std::endl << "-------------------" << std::endl << std::endl;
@ -450,10 +504,11 @@ int dump_header_psi_bin(const std::string fileName, const std::string fileFormat
/** /**
* <p>dump the header information of a MUD file. * <p>dump the header information of a MUD file.
* @param fileName file name of the MUD file * @param fileName file name of the MUD file
* @param counts bool, if true dump detector counts
* *
* @return 0 on success, 1 otherwise * @return 0 on success, 1 otherwise
*/ */
int dump_header_mud(const std::string fileName) int dump_header_mud(const std::string fileName, const bool counts)
{ {
int fh; int fh;
UINT32 type, val; UINT32 type, val;
@ -618,6 +673,12 @@ int dump_header_mud(const std::string fileName)
std::cout << std::endl << "Last Good Bin : " << val; std::cout << std::endl << "Last Good Bin : " << val;
else else
std::cout << std::endl << "Last Good Bin : ???"; std::cout << std::endl << "Last Good Bin : ???";
if (counts) {
success = MUD_getHistNumEvents( fh, i+1, &val );
if (success) {
std::cout << std::endl << "#Events : " << val;
}
}
} }
std::cout << std::endl << "-------------------" << std::endl << std::endl; std::cout << std::endl << "-------------------" << std::endl << std::endl;
@ -723,6 +784,7 @@ int main(int argc, char *argv[])
std::string year(""); std::string year("");
std::string instrument("lem"); std::string instrument("lem");
bool summary(false); bool summary(false);
bool counts(false);
for (int i=1; i<argc; i++) { for (int i=1; i<argc; i++) {
if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) { if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) {
@ -812,6 +874,8 @@ int main(int argc, char *argv[])
i++; i++;
} else if (!strcmp(argv[i], "-s") || !strcmp(argv[i], "--summary")) { } else if (!strcmp(argv[i], "-s") || !strcmp(argv[i], "--summary")) {
summary = true; summary = true;
} else if (!strcmp(argv[i], "-c") || !strcmp(argv[i], "--counts")) {
counts = true;
} else if (!strcmp(argv[i], "-i") || !strcmp(argv[i], "--instrument")) { } else if (!strcmp(argv[i], "-i") || !strcmp(argv[i], "--instrument")) {
if (i+1 >= argc) { if (i+1 >= argc) {
std::cerr << std::endl << "**ERROR** found option --instrument without <instrument> input!" << std::endl; std::cerr << std::endl << "**ERROR** found option --instrument without <instrument> input!" << std::endl;
@ -929,17 +993,17 @@ int main(int argc, char *argv[])
boost::to_lower(fileFormat); boost::to_lower(fileFormat);
if (boost::iequals(fileFormat, "MusrRoot") || boost::iequals(fileFormat, "ROOT")) { if (boost::iequals(fileFormat, "MusrRoot") || boost::iequals(fileFormat, "ROOT")) {
dump_header_root(pathFln, summary); dump_header_root(pathFln, summary, counts);
} else if (boost::iequals(fileFormat, "NeXus")) { } else if (boost::iequals(fileFormat, "NeXus")) {
#ifdef PNEXUS_ENABLED #ifdef PNEXUS_ENABLED
dump_header_nexus(pathFln); dump_header_nexus(pathFln, counts);
#else #else
std::cout << std::endl << "Sorry, NeXus is not enabled, hence I cannot help you." << std::endl; std::cout << std::endl << "Sorry, NeXus is not enabled, hence I cannot help you." << std::endl;
#endif #endif
} else if (boost::iequals(fileFormat, "PSI-BIN") || boost::iequals(fileFormat, "PSI-MDU")) { } else if (boost::iequals(fileFormat, "PSI-BIN") || boost::iequals(fileFormat, "PSI-MDU")) {
dump_header_psi_bin(pathFln, fileFormat); dump_header_psi_bin(pathFln, fileFormat, counts);
} else if (boost::iequals(fileFormat, "MUD")) { } else if (boost::iequals(fileFormat, "MUD")) {
dump_header_mud(pathFln); dump_header_mud(pathFln, counts);
} else if (boost::iequals(fileFormat, "WKM")) { } else if (boost::iequals(fileFormat, "WKM")) {
dump_header_wkm(pathFln); dump_header_wkm(pathFln);
} }

View File

@ -635,6 +635,21 @@ unsigned int PNeXusData1::GetHistoLength(unsigned int histoNo)
return fHisto[histoNo].size(); return fHisto[histoNo].size();
} }
//------------------------------------------------------------------------------------------
// GetHistoLength (public)
//------------------------------------------------------------------------------------------
unsigned int PNeXusData1::GetHistoCounts(unsigned int histoNo)
{
if (histoNo >= fHisto.size())
return 0;
unsigned int counts=0;
for (unsigned int i=0; i<fHisto[histoNo].size(); i++)
counts += fHisto[histoNo][i];
return counts;
}
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------
// GetHisto (public) // GetHisto (public)
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------
@ -1258,6 +1273,36 @@ int PNeXusDetector2::SetLastGoodBin(int *lgb)
return result; return result;
} }
//------------------------------------------------------------------------------------------
// GetHistoCounts (public)
//------------------------------------------------------------------------------------------
/**
* <p>Get number of counts in a given histogram histoNo
*
* \param idx_p period index
* \param idx_s spectrum index
*
* \return the number of entries in the selected histogram histoNo, or 0 if the histoNo is out of scope.
*/
unsigned int PNeXusDetector2::GetHistoCounts(int idx_p, int idx_s)
{
unsigned counts = 0;
if (idx_p > 0)
if (idx_p > fNoOfPeriods)
return counts;
if (idx_s > 0)
if (idx_s > fNoOfSpectra)
return counts;
for (int i=0; i<fNoOfBins; i++) {
counts += GetHistoValue(idx_p,idx_s,i);
}
return counts;
}
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------
// GetHistoValue (public) // GetHistoValue (public)
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------
@ -2151,8 +2196,9 @@ int PNeXus::WriteFile(const char *fileName, const char *fileType, const unsigned
/** /**
* <p>Write the content of the NeXus file to stdout. Used for debugging purposes. * <p>Write the content of the NeXus file to stdout. Used for debugging purposes.
* *
* \param counts flag, if true, also dump the counts for all the histograms
*/ */
void PNeXus::Dump() void PNeXus::Dump(const bool counts)
{ {
double dval; double dval;
std::string str; std::string str;
@ -2259,6 +2305,8 @@ void PNeXus::Dump()
std::cout << fNxEntry1->GetData()->GetHisto(i)->at(j) << ", "; std::cout << fNxEntry1->GetData()->GetHisto(i)->at(j) << ", ";
} }
std::cout << "..."; std::cout << "...";
if (counts)
std::cout << " total no of entries: " << fNxEntry1->GetData()->GetHistoCounts(i);
} }
} }
if (fNxEntry1->GetData()->GetAlpha()->size() == 0) { if (fNxEntry1->GetData()->GetAlpha()->size() == 0) {
@ -2408,6 +2456,8 @@ void PNeXus::Dump()
std::cout << fNxEntry2->GetInstrument()->GetDetector()->GetHistoValue(i,j,k) << ", "; std::cout << fNxEntry2->GetInstrument()->GetDetector()->GetHistoValue(i,j,k) << ", ";
} }
std::cout << "..."; std::cout << "...";
if (counts)
std::cout << " total number of entries: " << fNxEntry2->GetInstrument()->GetDetector()->GetHistoCounts(i,j);
} }
} }
} else { } else {
@ -2421,6 +2471,8 @@ void PNeXus::Dump()
std::cout << fNxEntry2->GetInstrument()->GetDetector()->GetHistoValue(0,j,k) << ", "; std::cout << fNxEntry2->GetInstrument()->GetDetector()->GetHistoValue(0,j,k) << ", ";
} }
std::cout << "..."; std::cout << "...";
if (counts)
std::cout << " total number of entries: " << fNxEntry2->GetInstrument()->GetDetector()->GetHistoCounts(0,j);
} }
} else { // counts[ntc] } else { // counts[ntc]
std::cout << std::endl << " (#bins=" << fNxEntry2->GetInstrument()->GetDetector()->GetNoOfBins() << ")"; std::cout << std::endl << " (#bins=" << fNxEntry2->GetInstrument()->GetDetector()->GetNoOfBins() << ")";
@ -2431,6 +2483,8 @@ void PNeXus::Dump()
std::cout << fNxEntry2->GetInstrument()->GetDetector()->GetHistoValue(0,0,k) << ", "; std::cout << fNxEntry2->GetInstrument()->GetDetector()->GetHistoValue(0,0,k) << ", ";
} }
std::cout << "..."; std::cout << "...";
if (counts)
std::cout << " total number of entries: " << fNxEntry2->GetInstrument()->GetDetector()->GetHistoCounts(0,0);
} }
} }
std::cout << std::endl << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"; std::cout << std::endl << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++";

View File

@ -254,6 +254,7 @@ class PNeXusData1 {
virtual void GetHistoName(unsigned int idx, std::string &name, bool &ok); virtual void GetHistoName(unsigned int idx, std::string &name, bool &ok);
virtual unsigned int GetNoOfHistos() { return fHisto.size(); } virtual unsigned int GetNoOfHistos() { return fHisto.size(); }
virtual unsigned int GetHistoLength(unsigned int histoNo=0); virtual unsigned int GetHistoLength(unsigned int histoNo=0);
virtual unsigned int GetHistoCounts(unsigned int histoNo=0);
virtual std::vector<unsigned int> *GetHisto(unsigned int histoNo); virtual std::vector<unsigned int> *GetHisto(unsigned int histoNo);
virtual std::vector<int> *GetGrouping() { return &fGrouping; } virtual std::vector<int> *GetGrouping() { return &fGrouping; }
virtual std::vector<PNeXusAlpha1> *GetAlpha() { return &fAlpha; } virtual std::vector<PNeXusAlpha1> *GetAlpha() { return &fAlpha; }
@ -399,6 +400,7 @@ class PNeXusDetector2 {
virtual int GetNoOfPeriods() { return fNoOfPeriods; } virtual int GetNoOfPeriods() { return fNoOfPeriods; }
virtual int GetNoOfSpectra() { return fNoOfSpectra; } virtual int GetNoOfSpectra() { return fNoOfSpectra; }
virtual int GetNoOfBins() { return fNoOfBins; } virtual int GetNoOfBins() { return fNoOfBins; }
virtual unsigned int GetHistoCounts(int idx_p, int idx_s);
virtual int GetHistoValue(int idx_p, int idx_s, int idx_b); virtual int GetHistoValue(int idx_p, int idx_s, int idx_b);
virtual int* GetHistos() { return fHisto; } virtual int* GetHistos() { return fHisto; }
virtual unsigned int GetSpectrumIndexSize() { return fSpectrumIndex.size(); } virtual unsigned int GetSpectrumIndexSize() { return fSpectrumIndex.size(); }
@ -586,7 +588,7 @@ class PNeXus {
virtual void SetCreator(std::string str) { fCreator = str; } virtual void SetCreator(std::string str) { fCreator = str; }
virtual void Dump(); virtual void Dump(const bool counts);
private: private:
bool fValid; bool fValid;

View File

@ -2949,6 +2949,7 @@ void PTextEdit::musrDump()
cmd.append(str); cmd.append(str);
cmd.append("-fn"); cmd.append("-fn");
cmd.append(fileName); cmd.append(fileName);
cmd.append("-c");
PDumpOutputHandler dumpOutputHandler(cmd); PDumpOutputHandler dumpOutputHandler(cmd);
dumpOutputHandler.setModal(false); dumpOutputHandler.setModal(false);

View File

@ -2934,6 +2934,7 @@ void PTextEdit::musrDump()
cmd.append(str); cmd.append(str);
cmd.append("-fn"); cmd.append("-fn");
cmd.append(fileName); cmd.append(fileName);
cmd.append("-c");
PDumpOutputHandler dumpOutputHandler(cmd); PDumpOutputHandler dumpOutputHandler(cmd);
dumpOutputHandler.setModal(false); dumpOutputHandler.setModal(false);