59 #include "TRestDataBase.h"
60 #include "TRestManager.h"
61 #include "TRestProcessRunner.h"
62 #include "TRestStringOutput.h"
67 TRestCut::TRestCut() { Initialize(); }
72 auto ele = GetElement(
"cut");
73 while (ele !=
nullptr) {
74 string name = GetParameter(
"name", ele,
"");
75 if (name.empty() || name ==
"Not defined") {
76 RESTError <<
"< cut does not contain a name!" << RESTendl;
80 string cutStr = GetParameter(
"value", ele,
"");
81 string variable = GetParameter(
"variable", ele,
"");
82 string condition = GetParameter(
"condition", ele,
"");
84 if (!cutStr.empty()) {
85 cutStr =
Replace(cutStr,
" AND ",
" && ");
86 cutStr =
Replace(cutStr,
" OR ",
" || ");
87 fCutStrings.push_back(cutStr);
88 AddCut(TCut(name.c_str(), cutStr.c_str()));
89 }
else if (!variable.empty() && !condition.empty()) {
90 fParamCut.push_back(std::make_pair(variable, condition));
91 string cutVar = variable + condition;
92 AddCut(TCut(name.c_str(), cutVar.c_str()));
94 RESTError <<
"TRestCut does not contain a valid parameter/condition or cut string!" << RESTendl;
95 RESTError <<
"<cut name='cc1' value='XX>10 AND XX<90'/>" << RESTendl;
96 RESTError <<
"<cut name='cc3' variable='sAna_ThresholdIntegral' condition='>0'" << RESTendl;
100 ele = GetNextElement(ele);
105 SetName(cut.GetName());
106 SetTitle(cut.GetTitle());
107 fCuts = cut.GetCuts();
108 fCutStrings = cut.GetCutStrings();
109 fParamCut = cut.GetParamCut();
113 void TRestCut::AddCut(
const TCut& cut) {
114 if ((
string)cut.GetName() ==
"") {
115 RESTWarning <<
"TRestCut::AddCut: cannot add cut without name!" << RESTendl;
118 if ((
string)cut.GetTitle() ==
"") {
119 RESTWarning <<
"TRestCut::AddCut: cannot add empty cut!" << RESTendl;
122 for (
const auto& c : fCuts) {
123 if ((
string)c.GetName() == (
string)cut.GetName()) {
124 RESTWarning <<
"TRestCut::AddCut: cut with name \"" << c.GetName() <<
"\" already added!"
129 fCuts.push_back(cut);
132 TCut TRestCut::GetCut(
string name) {
133 for (
auto c : fCuts) {
134 if ((
string)c.GetName() == name) {
141 void TRestCut::AddCut(
TRestCut* cut) {
142 if (cut ==
nullptr) {
143 RESTWarning <<
"Cut to be added is nullptr, skipping" << RESTendl;
146 for (
const auto& c : cut->GetCuts()) {
150 const auto paramCut = cut->GetParamCut();
151 fParamCut.insert(fParamCut.end(), paramCut.begin(), paramCut.end());
153 const auto cutStrings = cut->GetCutStrings();
154 fCutStrings.insert(fCutStrings.end(), cutStrings.begin(), cutStrings.end());
159 RESTMetadata <<
" " << RESTendl;
160 RESTMetadata <<
"Cuts added: " << RESTendl;
161 for (
const auto& cut : fCuts) {
162 RESTMetadata << cut.GetName() <<
" " << cut.GetTitle() << RESTendl;
164 RESTMetadata <<
"+++" << RESTendl;
170 for (
auto c : fCuts) {
A class to help on cuts definitions. To be used with TRestAnalysisTree.
void PrintMetadata() override
Implemented it in the derived metadata class to print out specific metadata information.
Int_t Write(const char *name, Int_t option, Int_t bufsize) override
overwriting the write() method with fStore considered
void Initialize() override
Making default settings.
void InitFromConfigFile() override
To make settings from rml file. This method must be implemented in the derived class.
std::string Replace(std::string in, std::string thisString, std::string byThisString, size_t fromPosition=0, Int_t N=0)
Replace any occurences of thisSring by byThisString inside string in.