Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRestDataSetPlot improvements #520

Merged
merged 8 commits into from
May 30, 2024
Merged

TRestDataSetPlot improvements #520

merged 8 commits into from
May 30, 2024

Conversation

AlvaroEzq
Copy link
Contributor

@AlvaroEzq AlvaroEzq commented May 12, 2024

AlvaroEzq Medium: 159 Powered by Pull Request Badge

  • Extended the scale option to use any mathematical expression in combination with the special keywords.
    New keywords:

    • entries
    • runLength
    • integral
  • Add cuts, cutNames, panelCut and panelCutNames to paramMap to be able to show them in the panel (in the same way as meanRate for example). Also add RESTinfo message to output the global and additional panel cuts applied.

  • EnableMultiThreading when handling the TRestDataSet (avoids annoying "Warning in <ROOT_TImplicitMT_DisableImplicitMT>: Implicit multi-threading is already disabled" message)

  • Added new key expression in panel definition to parse a mathematical expression that can contain any of the previous key values (variable, metadata and observable). It is a generalization of these previous keys, so this new expression key could replace them for good but I keep them for retrocompatibility.

@AlvaroEzq
Copy link
Contributor Author

Getting rid of the keys variable, metadata and observable would simplify a lot the code as it would get rid of the following duplicated code lines:

TiXmlElement* labelele = GetElement("variable", panelele);
while (labelele != nullptr) {
std::array<std::string, 3> label;
label[0] = GetParameter("value", labelele, "");
label[1] = GetParameter("label", labelele, "");
label[2] = GetParameter("units", labelele, "");
double posX = StringToDouble(GetParameter("x", labelele, "0.1"));
double posY = StringToDouble(GetParameter("y", labelele, "0.1"));
panel.variablePos.push_back(std::make_pair(label, TVector2(posX, posY)));
labelele = GetNextElement(labelele);
}
TiXmlElement* metadata = GetElement("metadata", panelele);
while (metadata != nullptr) {
std::array<std::string, 3> label;
label[0] = GetParameter("value", metadata, "");
label[1] = GetParameter("label", metadata, "");
label[2] = GetParameter("units", metadata, "");
double posX = StringToDouble(GetParameter("x", metadata, "0.1"));
double posY = StringToDouble(GetParameter("y", metadata, "0.1"));
panel.metadataPos.push_back(std::make_pair(label, TVector2(posX, posY)));
metadata = GetNextElement(metadata);
}
TiXmlElement* observable = GetElement("observable", panelele);
while (observable != nullptr) {
std::array<std::string, 3> label;
label[0] = GetParameter("value", observable, "");
label[1] = GetParameter("label", observable, "");
label[2] = GetParameter("units", observable, "");
double posX = StringToDouble(GetParameter("x", observable, "0.1"));
double posY = StringToDouble(GetParameter("y", observable, "0.1"));
panel.obsPos.push_back(std::make_pair(label, TVector2(posX, posY)));
observable = GetNextElement(observable);
}

// Replace panel variables and generate a TLatex label
for (const auto& [key, posLabel] : panel.variablePos) {
auto&& [variable, label, units] = key;
bool found = false;
std::string var = variable;
if (!var.empty()) {
for (const auto& [param, val] : paramMap) {
if (var == param) {
size_t pos = 0;
var = Replace(var, param, val, pos);
found = true;
break;
}
}
if (!found) RESTWarning << "Variable " << variable << " not found" << RESTendl;
}
std::string lab = label + ": " + StringWithPrecision(var, panel.precision) + " " + units;
panel.text.emplace_back(new TLatex(posLabel.X(), posLabel.Y(), lab.c_str()));
}
// Replace metadata variables and generate a TLatex label
for (const auto& [key, posLabel] : panel.metadataPos) {
auto&& [metadata, label, units] = key;
std::string value = "";
for (const auto& [name, quant] : quantity) {
if (quant.metadata == metadata) value = quant.value;
}
if (value.empty()) {
RESTWarning << "Metadata quantity " << metadata << " not found in dataSet" << RESTendl;
continue;
}
std::string lab = label + ": " + StringWithPrecision(value, panel.precision) + " " + units;
panel.text.emplace_back(new TLatex(posLabel.X(), posLabel.Y(), lab.c_str()));
}
// Replace observable variables and generate a TLatex label
for (const auto& [key, posLabel] : panel.obsPos) {
auto&& [obs, label, units] = key;
auto value = *dataFrame.Mean(obs);
std::string lab = label + ": " + StringWithPrecision(value, panel.precision) + " " + units;
panel.text.emplace_back(new TLatex(posLabel.X(), posLabel.Y(), lab.c_str()));
}

But they are needed in TRestDataSetPlot::GenerateDataSetFromFilePattern(). A possible workaround could be to use the double [[]] encapsualting variable keywords ( e.g. [[entries]] ), the single [] encapsulating metadata (e.g. [TRestDetector::fPressure]) and naked observable names (e.g. rawAna_ThresholdIntegral) to identify them inside that method.

@AlvaroEzq AlvaroEzq marked this pull request as ready for review May 19, 2024 17:13
@AlvaroEzq AlvaroEzq requested a review from nkx111 as a code owner May 19, 2024 17:13
@AlvaroEzq AlvaroEzq merged commit ee941b0 into master May 30, 2024
63 checks passed
@AlvaroEzq AlvaroEzq deleted the aezquerro_dsPlot branch May 30, 2024 10:15
lobis added a commit that referenced this pull request Sep 24, 2024
* origin/master:
  TRestDataSetPlot improvements (#520)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants