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

Adding possibility to add a cut on observable parameters in TRestDataSet #386

Merged
merged 21 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9ebc9f4
Adding possibility to add an observable cut in TRestDataSet
juanangp Mar 3, 2023
47ced4c
Trying to optimize dataSet observable selection
juanangp Mar 3, 2023
95488b6
Reverting changes since the observable list is not applied at the RDa…
juanangp Mar 3, 2023
f67d948
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 3, 2023
ebe5aae
Merge branch 'master' into datasetCut
jgalan Mar 9, 2023
ec81007
TRestDataSet now stores a list of the files used to generate the dataset
jgalan Mar 13, 2023
974c3f4
Changes on TRestCut, adding possibility of adding cut by parameter
juanangp Mar 14, 2023
a1e02c9
Implementing TRestCut inside TRestDataSet
juanangp Mar 14, 2023
3ce28f5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 14, 2023
1d1c788
Update source/framework/core/inc/TRestCut.h
jgalan Mar 22, 2023
b3946ec
Adding copy operator to TRestCut
juanangp Mar 22, 2023
87da402
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 22, 2023
1aff997
Merge pull request #391 from rest-for-physics/trestcut
juanangp Mar 22, 2023
3a8b00e
Adding possitility to Import a TRestDataSet
juanangp Mar 22, 2023
a91e20c
New function MakeCut that returns a RDataFrame with the cuts applied
juanangp Mar 22, 2023
6e4567e
Using GenerateDataSet to create a TRESTDataSet from TRestRuns instead…
juanangp Mar 22, 2023
380628d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 22, 2023
599a80d
Update source/framework/core/inc/TRestCut.h
juanangp Mar 23, 2023
83e10e9
Update source/framework/core/inc/TRestCut.h
juanangp Mar 23, 2023
5468e20
Update source/framework/core/inc/TRestCut.h
juanangp Mar 23, 2023
f23d1b1
Adding brief description of the changes
juanangp Mar 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions source/framework/core/inc/TRestDataSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,14 @@ class TRestDataSet : public TRestMetadata {
/// The properties of a relevant quantity that we want to store together with the dataset
std::map<std::string, RelevantQuantity> fQuantity; //<

/// Parameter cuts over the selected dataset
std::vector<std::pair<std::string, std::string> > fParamCut;

/// The total integrated run time of selected files
Double_t fTotalDuration = 0; //<

/// The resulting RDataFrame object after initialization
ROOT::RDataFrame fDataSet = 0; //!
/// The resulting RDF::RNode object after initialization
ROOT::RDF::RNode fDataSet = ROOT::RDataFrame(0); //!

/// A pointer to the generated tree
TTree* fTree = nullptr; //!
Expand All @@ -95,7 +98,7 @@ class TRestDataSet : public TRestMetadata {

public:
/// Gives access to the RDataFrame
ROOT::RDataFrame GetDataFrame() const {
ROOT::RDF::RNode GetDataFrame() const {
if (fTree == nullptr) RESTWarning << "DataFrame has not been yet initialized" << RESTendl;
return fDataSet;
}
Expand Down
45 changes: 43 additions & 2 deletions source/framework/core/src/TRestDataSet.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@
/// // Will add to the final tree only the specific observables
/// <observables list="g4Ana_totalEdep:hitsAna_energy" />
///
/// // Will apply a cut to the observables
jgalan marked this conversation as resolved.
Show resolved Hide resolved
/// <cut variable="rawAna_NumberOfGoodSignals" condition=">10" />
/// <cut variable="rawAna_NumberOfGoodSignals" condition="<100" />
///
/// // Will add all the observables from the process `rawAna`
/// <processObservables list="rate:rawAna" />
///
Expand Down Expand Up @@ -266,7 +270,7 @@ void TRestDataSet::Initialize() {
if (fFileSelection.empty()) return;

///// Disentangling process observables --> producing finalList
TRestRun run(fFileSelection[0]);
TRestRun run(fFileSelection.front());
std::vector<std::string> finalList;
finalList.push_back("runOrigin");
finalList.push_back("eventID");
Expand All @@ -284,7 +288,25 @@ void TRestDataSet::Initialize() {

ROOT::EnableImplicitMT();

fDataSet = ROOT::RDataFrame("AnalysisTree", fFileSelection);
ROOT::RDataFrame df("AnalysisTree", fFileSelection);

std::string pCut = "";
for (const auto& [param, cut] : fParamCut) {
if (std::find(finalList.begin(), finalList.end(), param) != finalList.end()) {
if (!pCut.empty()) pCut += " && ";
pCut += param + cut;
} else {
RESTWarning << " Cut observable " << param << " not found in observable list, skipping..."
<< RESTendl;
}
}

if (!pCut.empty()) {
RESTDebug << "Applying cut " << pCut << RESTendl;
fDataSet = df.Filter(pCut);
} else {
fDataSet = df;
}

std::string user = getenv("USER");
std::string fOutName = "/tmp/rest_output_" + user + ".root";
Expand Down Expand Up @@ -562,6 +584,25 @@ void TRestDataSet::InitFromConfigFile() {

quantityDefinition = GetNextElement(quantityDefinition);
}

jgalan marked this conversation as resolved.
Show resolved Hide resolved
TiXmlElement* cutDefinition = GetElement("cut");
while (cutDefinition != nullptr) {
std::string variable = GetFieldValue("variable", cutDefinition);
if (variable.empty() || variable == "Not defined") {
RESTError << "< paramCut variable key does not contain a name!" << RESTendl;
exit(1);
}

std::string condition = GetFieldValue("condition", cutDefinition);
if (condition.empty() || condition == "Not defined") {
RESTError << "< paramCut condition key does not contain a metadata value!" << RESTendl;
exit(1);
}

fParamCut.push_back(std::make_pair(variable, condition));

cutDefinition = GetNextElement(cutDefinition);
}
}

///////////////////////////////////////////////
Expand Down