From 8c2b08d2be245a7dd17a4b1a4d06610d6151b439 Mon Sep 17 00:00:00 2001 From: Daniel Wielanek Date: Tue, 14 Jan 2025 21:47:54 +0100 Subject: [PATCH] Removed cut funcs, functionality is now in CutOptions. --- cuts/CMakeLists.txt | 1 - cuts/CutContainer.cxx | 3 +- cuts/CutFuncs.cxx | 108 ------------------------------------------ cuts/CutFuncs.h | 47 ------------------ cuts/CutOptions.cxx | 103 ++++++++++++++++++++++++++++++++++++++-- cuts/CutOptions.h | 23 +++++++++ cuts/HalCutLinkDef.h | 1 - 7 files changed, 123 insertions(+), 163 deletions(-) delete mode 100644 cuts/CutFuncs.cxx delete mode 100644 cuts/CutFuncs.h diff --git a/cuts/CMakeLists.txt b/cuts/CMakeLists.txt index 3162979..6095c80 100644 --- a/cuts/CMakeLists.txt +++ b/cuts/CMakeLists.txt @@ -32,7 +32,6 @@ TrackCut.cxx TwoTrackCut.cxx CutsAndMonitors.cxx CutMonitorRequest.cxx -CutFuncs.cxx CutOptions.cxx #EVENT CUTS eventcuts/mc/EventImpactParameterCut.cxx diff --git a/cuts/CutContainer.cxx b/cuts/CutContainer.cxx index b0cec64..967c510 100644 --- a/cuts/CutContainer.cxx +++ b/cuts/CutContainer.cxx @@ -17,7 +17,6 @@ #include "AnaFile.h" #include "Cout.h" -#include "CutFuncs.h" #include "CutOptions.h" #include "EventBinningCut.h" #include "EventComplexCut.h" @@ -78,7 +77,7 @@ namespace Hal { // add to cut containers auto addCutRaw = [&](ECutUpdate upd, Int_t colNo) { if (fSize <= static_cast(upd)) { - TString update_ratio_name = Hal::Cuts::GetCutUpdateRatioName(upd); + TString update_ratio_name = Hal::Std::UpdateEnumToString(upd); Cout::PrintInfo(Form("CutContainer can't hold %s cut because it's update ratio (%s) is " "too big, check fTries or call SetOption(backround) before adding cuts " "or cut monitors", diff --git a/cuts/CutFuncs.cxx b/cuts/CutFuncs.cxx deleted file mode 100644 index dfd0b52..0000000 --- a/cuts/CutFuncs.cxx +++ /dev/null @@ -1,108 +0,0 @@ -/* - * CutFuncs.cxx - * - * Created on: 25 lis 2023 - * Author: Daniel Wielanek - * E-mail: daniel.wielanek@gmail.com - * Warsaw University of Technology, Faculty of Physics - */ -#include "CutFuncs.h" -#include "Cout.h" -#include "EventComplexCut.h" -#include "EventCut.h" -#include "Std.h" -#include "TrackComplexCut.h" -#include "TrackCut.h" -#include "TwoTrackComplexCut.h" -#include "TwoTrackCut.h" - -namespace Hal { - namespace Cuts { - std::vector GetCollectionsFlags(Int_t startCol, TString option) { - std::vector res; - Int_t single = -2; - Bool_t single_exp = Hal::Std::FindExpressionSingleValue(option, single, kTRUE); - Int_t n, jump; - Bool_t two_exp = Hal::Std::FindExpressionTwoValues(option, n, jump, kTRUE); - if (single_exp && two_exp) { // found {}+{x} - for (int i = 0; i < n; i++) { - res.push_back(single); - single += jump; - } - return res; - } - if (two_exp) { //{x} - single = startCol; - for (int i = 0; i < n; i++) { - res.push_back(single); - single += jump; - } - return res; - } - if (single_exp) res.push_back(single); - while (Hal::Std::FindExpressionSingleValue(option, single, kTRUE)) { - res.push_back(single); - } - if (res.size() == 0) res.push_back(startCol); - return res; - } - - Hal::Cut* MakeCutCopy(const Hal::Cut& cut, TString flag, Bool_t acceptNulls) { - Hal::Cut* res = nullptr; - auto upd = cut.GetUpdateRatio(); - if (flag == "re") { // real stuff - switch (upd) { - case ECutUpdate::kEvent: { - res = new EventRealCut(static_cast(cut)); - } break; - case ECutUpdate::kTrack: { - res = new TrackRealCut(static_cast(cut)); - } break; - case ECutUpdate::kTwoTrack: { - res = new TwoTrackRealCut(static_cast(cut)); - } break; - case ECutUpdate::kTwoTrackBackground: { - res = new TwoTrackRealCut(static_cast(cut)); - } break; - default: return nullptr; break; - } - } else { // imaginary stuff - switch (upd) { - case ECutUpdate::kEvent: { - res = new EventImaginaryCut(static_cast(cut)); - if (acceptNulls) static_cast(res)->AcceptNulls(kTRUE); - } break; - case ECutUpdate::kTrack: { - res = new TrackImaginaryCut(static_cast(cut)); - if (acceptNulls) static_cast(res)->AcceptNulls(kTRUE); - } break; - case ECutUpdate::kTwoTrack: { - res = new TwoTrackImaginaryCut(static_cast(cut)); - if (acceptNulls) static_cast(res)->AcceptNulls(kTRUE); - } break; - case ECutUpdate::kTwoTrackBackground: { - res = new TwoTrackImaginaryCut(static_cast(cut)); - if (acceptNulls) static_cast(res)->AcceptNulls(kTRUE); - } break; - default: return nullptr; break; - } - } - if (res) res->SetCollectionID(cut.GetCollectionID()); - return res; - } - TString GetCutUpdateRatioName(ECutUpdate upd) { - TString update_ratio_name; - switch (upd) { - case ECutUpdate::kEvent: update_ratio_name = "event"; break; - case ECutUpdate::kTrack: update_ratio_name = "track"; break; - case ECutUpdate::kTwoTrack: update_ratio_name = "two_track"; break; - case ECutUpdate::kTwoTrackBackground: update_ratio_name = "two_track"; break; - default: - Cout::PrintInfo("Unknown update ratio", EInfo::kLowWarning); - update_ratio_name = "unknown"; - break; - } - return update_ratio_name; - } - } // namespace Cuts -} /* namespace Hal */ diff --git a/cuts/CutFuncs.h b/cuts/CutFuncs.h deleted file mode 100644 index 7b2f013..0000000 --- a/cuts/CutFuncs.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * CutFuncs.h - * - * Created on: 25 lis 2023 - * Author: Daniel Wielanek - * E-mail: daniel.wielanek@gmail.com - * Warsaw University of Technology, Faculty of Physics - */ -#ifndef HAL_CUTS_CUTFUNCS_H_ -#define HAL_CUTS_CUTFUNCS_H_ - -#include - -#include "Object.h" -#include "Std.h" -#include -#include - -namespace Hal { - class Cut; - - namespace Cuts { - /** - * calculate collection Id's from expression - * @param option - * @return - */ - std::vector GetCollectionsFlags(Int_t startCol, TString option); - /** - * make copy of cut - * @param cu cut to copy - * @param flag re for real, other create img flag - * @param acceptNulls for img if true than accept nulls - * @return - */ - Hal::Cut* MakeCutCopy(const Hal::Cut& cut, TString flag, Bool_t acceptNulls = kTRUE); - /** - * return cut update ratio name - * @param upd - * @return - */ - TString GetCutUpdateRatioName(Hal::ECutUpdate upd); - } // namespace Cuts - -} /* namespace Hal */ - -#endif /* HAL_CUTS_CUTFUNCS_H_ */ diff --git a/cuts/CutOptions.cxx b/cuts/CutOptions.cxx index 21f32df..34d1fa7 100644 --- a/cuts/CutOptions.cxx +++ b/cuts/CutOptions.cxx @@ -8,13 +8,21 @@ #include "CutOptions.h" #include "Cout.h" -#include "CutFuncs.h" #include "CutMonitor.h" #include "EventBinningCut.h" #include "Std.h" #include "StdString.h" +#include "CutMonitor.h" +#include "EventComplexCut.h" +#include "EventCut.h" +#include "TrackComplexCut.h" +#include "TrackCut.h" +#include "TwoTrackComplexCut.h" +#include "TwoTrackCut.h" + #include +#include namespace Hal { CutOptions::CutOptions(TString opt, Int_t defCol) { @@ -31,7 +39,7 @@ namespace Hal { fBckg = kTRUE; } fDefCol = defCol; - fCollections = Hal::Cuts::GetCollectionsFlags(fDefCol, opt); + fCollections = GetCollectionsFlags(fDefCol, opt); if (fCollections.size() == 0) fCollections.push_back(fDefCol); // collections where not overwriten } @@ -49,13 +57,13 @@ namespace Hal { Hal::Cout::PrintInfo(Form("%s %i: cannot add binned cut with im flag", __FILE__, __LINE__), EInfo::kError); return nullptr; } - return Hal::Cuts::MakeCutCopy(x, "re", kFALSE); + return MakeCutCopy(x, "re", kFALSE); } else if (fIm) { if (dynamic_cast(&x)) { Hal::Cout::PrintInfo(Form("%s %i: cannot add binned cut with im flag", __FILE__, __LINE__), EInfo::kError); return nullptr; } - return Hal::Cuts::MakeCutCopy(x, "im", fAcceptNull); + return MakeCutCopy(x, "im", fAcceptNull); } return x.MakeCopy(); } @@ -104,5 +112,92 @@ namespace Hal { MakeComplexAxis(res, i, flag); return res; } + std::vector CutOptions::GetCollectionsFlags(Int_t startCol, TString option) const { + std::vector res; + Int_t single = -2; + Bool_t single_exp = Hal::Std::FindExpressionSingleValue(option, single, kTRUE); + Int_t n, jump; + Bool_t two_exp = Hal::Std::FindExpressionTwoValues(option, n, jump, kTRUE); + if (single_exp && two_exp) { // found {}+{x} + for (int i = 0; i < n; i++) { + res.push_back(single); + single += jump; + } + return res; + } + if (two_exp) { //{x} + single = startCol; + for (int i = 0; i < n; i++) { + res.push_back(single); + single += jump; + } + return res; + } + if (single_exp) res.push_back(single); + while (Hal::Std::FindExpressionSingleValue(option, single, kTRUE)) { + res.push_back(single); + } + if (res.size() == 0) res.push_back(startCol); + return res; + } + + Hal::Cut* CutOptions::MakeCutCopy(const Hal::Cut& cut, TString flag, Bool_t acceptNulls) const { + Hal::Cut* res = nullptr; + auto upd = cut.GetUpdateRatio(); + if (flag == "re") { // real stuff + switch (upd) { + case ECutUpdate::kEvent: { + res = new EventRealCut(static_cast(cut)); + } break; + case ECutUpdate::kTrack: { + res = new TrackRealCut(static_cast(cut)); + } break; + case ECutUpdate::kTwoTrack: { + res = new TwoTrackRealCut(static_cast(cut)); + } break; + case ECutUpdate::kTwoTrackBackground: { + res = new TwoTrackRealCut(static_cast(cut)); + } break; + default: return nullptr; break; + } + } else { // imaginary stuff + switch (upd) { + case ECutUpdate::kEvent: { + res = new EventImaginaryCut(static_cast(cut)); + if (acceptNulls) static_cast(res)->AcceptNulls(kTRUE); + } break; + case ECutUpdate::kTrack: { + res = new TrackImaginaryCut(static_cast(cut)); + if (acceptNulls) static_cast(res)->AcceptNulls(kTRUE); + } break; + case ECutUpdate::kTwoTrack: { + res = new TwoTrackImaginaryCut(static_cast(cut)); + if (acceptNulls) static_cast(res)->AcceptNulls(kTRUE); + } break; + case ECutUpdate::kTwoTrackBackground: { + res = new TwoTrackImaginaryCut(static_cast(cut)); + if (acceptNulls) static_cast(res)->AcceptNulls(kTRUE); + } break; + default: return nullptr; break; + } + } + if (res) res->SetCollectionID(cut.GetCollectionID()); + return res; + } + TString CutOptions::GetCutUpdateRatioName(ECutUpdate upd) const { + TString update_ratio_name; + switch (upd) { + case ECutUpdate::kEvent: update_ratio_name = "event"; break; + case ECutUpdate::kTrack: update_ratio_name = "track"; break; + case ECutUpdate::kTwoTrack: update_ratio_name = "two_track"; break; + case ECutUpdate::kTwoTrackBackground: update_ratio_name = "two_track"; break; + default: + Cout::PrintInfo("Unknown update ratio", EInfo::kLowWarning); + update_ratio_name = "unknown"; + break; + } + return update_ratio_name; + } + } /* namespace Hal */ diff --git a/cuts/CutOptions.h b/cuts/CutOptions.h index e19c963..5219de4 100644 --- a/cuts/CutOptions.h +++ b/cuts/CutOptions.h @@ -14,6 +14,7 @@ #include #include "Object.h" +#include "Std.h" namespace Hal { class Cut; @@ -30,6 +31,28 @@ namespace Hal { Bool_t fAcceptDouble = {kFALSE}; Int_t fDefCol = {-1}; + protected: + /** + * calculate collection Id's from expression + * @param option + * @return + */ + std::vector GetCollectionsFlags(Int_t startCol, TString option) const; + /** + * make copy of cut + * @param cu cut to copy + * @param flag re for real, other create img flag + * @param acceptNulls for img if true than accept nulls + * @return + */ + Hal::Cut* MakeCutCopy(const Hal::Cut& cut, TString flag, Bool_t acceptNulls = kTRUE) const; + /** + * return cut update ratio name + * @param upd + * @return + */ + TString GetCutUpdateRatioName(Hal::ECutUpdate upd) const; + public: CutOptions(TString opt = "", Int_t defCol = -1); void ClearFlag(TString flag); diff --git a/cuts/HalCutLinkDef.h b/cuts/HalCutLinkDef.h index 7071559..302bb44 100644 --- a/cuts/HalCutLinkDef.h +++ b/cuts/HalCutLinkDef.h @@ -6,7 +6,6 @@ #pragma link off all typedefs; #ifdef __MAKECINT__ -#pragma link C++ namespace Hal::Cuts; #pragma link C++ class Hal::Cut + ; #pragma link C++ class Hal::SubCut + ; #pragma link C++ class Hal::SubCutHisto + ;