proper TDirectory handling for the histos.
All checks were successful
Build and Deploy Documentation / build-and-deploy (push) Successful in 19s

This commit is contained in:
2026-01-26 20:32:34 +01:00
parent 4ac7a7d01c
commit 4e29ad6898

View File

@@ -1946,7 +1946,12 @@ Bool_t PRunDataHandler::ReadRootFile()
runData.SetBeamline(str); runData.SetBeamline(str);
// read run summary to obtain ring anode HV values // read run summary to obtain ring anode HV values
TObjArray *runSummary = dynamic_cast<TObjArray*>(folder->FindObjectAny("RunSummary")); TObjArray *runSummary = nullptr;
if (fileType == PRH_MUSR_ROOT) // TFolder
runSummary = dynamic_cast<TObjArray*>(folder->FindObjectAny("RunSummary"));
else { // TDirectory
f.GetObject("RunHeader/RunSummary", runSummary);
}
// check if run summary is valid // check if run summary is valid
if (!runSummary) { if (!runSummary) {
@@ -2056,59 +2061,110 @@ Bool_t PRunDataHandler::ReadRootFile()
// read data --------------------------------------------------------- // read data ---------------------------------------------------------
// check if histos folder is found if (fileType == PRH_MUSR_ROOT) { // TFolder
f.GetObject("histos", folder); // check if histos folder is found
if (!folder) { f.GetObject("histos", folder);
std::cerr << std::endl << ">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't obtain histos from " << fRunPathName.Data() << std::endl; if (!folder) {
f.Close(); std::cerr << std::endl << ">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't obtain histos from " << fRunPathName.Data() << std::endl;
return false; f.Close();
} return false;
}
// get all the data // get all the data
for (UInt_t i=0; i<redGreenOffsets.size(); i++) { for (UInt_t i=0; i<redGreenOffsets.size(); i++) {
for (Int_t j=0; j<noOfHistos; j++) { for (Int_t j=0; j<noOfHistos; j++) {
str.Form("hDecay%03d", redGreenOffsets[i]+j+1); str.Form("hDecay%03d", redGreenOffsets[i]+j+1);
TH1F *histo = dynamic_cast<TH1F*>(folder->FindObjectAny(str.Data())); TH1F *histo = dynamic_cast<TH1F*>(folder->FindObjectAny(str.Data()));
if (!histo) { if (!histo) {
std::cerr << std::endl << ">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't get histo " << str; std::cerr << std::endl << ">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't get histo " << str;
std::cerr << std::endl; std::cerr << std::endl;
f.Close(); f.Close();
return false; return false;
}
dataSet.Clear();
dataSet.SetTitle(histo->GetTitle());
dataSet.SetHistoNo(redGreenOffsets[i]+j+1);
// get detector info
path.Form("DetectorInfo/Detector%03d/", redGreenOffsets[i]+j+1);
pathName = path + "Name";
header->Get(pathName, str, ok);
if (ok)
dataSet.SetName(str);
pathName = path + "Time Zero Bin";
header->Get(pathName, dval, ok);
if (ok)
dataSet.SetTimeZeroBin(dval);
pathName = path + "First Good Bin";
header->Get(pathName, ival, ok);
if (ok)
dataSet.SetFirstGoodBin(ival);
pathName = path + "Last Good Bin";
header->Get(pathName, ival, ok);
if (ok)
dataSet.SetLastGoodBin(ival);
dataSet.SetTimeZeroBinEstimated(histo->GetMaximumBin());
// fill data
for (Int_t j=1; j<=histo->GetNbinsX(); j++) {
histoData.push_back(histo->GetBinContent(j));
}
dataSet.SetData(histoData);
runData.SetDataSet(dataSet);
// clear histoData for the next histo
histoData.clear();
} }
}
} else { // TDirectory
// get all the data
TH1F *histo;
for (UInt_t i=0; i<redGreenOffsets.size(); i++) {
for (Int_t j=0; j<noOfHistos; j++) {
str.Form("histos/DecayAnaModule/hDecay%03d", redGreenOffsets[i]+j+1);
f.GetObject(str, histo);
if (!histo) {
std::cerr << std::endl << ">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't get histo " << str;
std::cerr << std::endl;
f.Close();
return false;
}
dataSet.Clear(); dataSet.Clear();
dataSet.SetTitle(histo->GetTitle()); dataSet.SetTitle(histo->GetTitle());
dataSet.SetHistoNo(redGreenOffsets[i]+j+1); dataSet.SetHistoNo(redGreenOffsets[i]+j+1);
// get detector info // get detector info
path.Form("DetectorInfo/Detector%03d/", redGreenOffsets[i]+j+1); path.Form("DetectorInfo/Detector%03d/", redGreenOffsets[i]+j+1);
pathName = path + "Name"; pathName = path + "Name";
header->Get(pathName, str, ok); header->Get(pathName, str, ok);
if (ok) if (ok)
dataSet.SetName(str); dataSet.SetName(str);
pathName = path + "Time Zero Bin"; pathName = path + "Time Zero Bin";
header->Get(pathName, dval, ok); header->Get(pathName, dval, ok);
if (ok) if (ok)
dataSet.SetTimeZeroBin(dval); dataSet.SetTimeZeroBin(dval);
pathName = path + "First Good Bin"; pathName = path + "First Good Bin";
header->Get(pathName, ival, ok); header->Get(pathName, ival, ok);
if (ok) if (ok)
dataSet.SetFirstGoodBin(ival); dataSet.SetFirstGoodBin(ival);
pathName = path + "Last Good Bin"; pathName = path + "Last Good Bin";
header->Get(pathName, ival, ok); header->Get(pathName, ival, ok);
if (ok) if (ok)
dataSet.SetLastGoodBin(ival); dataSet.SetLastGoodBin(ival);
dataSet.SetTimeZeroBinEstimated(histo->GetMaximumBin()); dataSet.SetTimeZeroBinEstimated(histo->GetMaximumBin());
// fill data // fill data
for (Int_t j=1; j<=histo->GetNbinsX(); j++) { for (Int_t j=1; j<=histo->GetNbinsX(); j++) {
histoData.push_back(histo->GetBinContent(j)); histoData.push_back(histo->GetBinContent(j));
}
dataSet.SetData(histoData);
runData.SetDataSet(dataSet);
// clear histoData for the next histo
histoData.clear();
} }
dataSet.SetData(histoData);
runData.SetDataSet(dataSet);
// clear histoData for the next histo
histoData.clear();
} }
} }
} }