Skip to content

Commit

Permalink
Removed cut funcs, functionality is now in CutOptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielWielanek committed Jan 14, 2025
1 parent c6cfe6b commit 8c2b08d
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 163 deletions.
1 change: 0 additions & 1 deletion cuts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ TrackCut.cxx
TwoTrackCut.cxx
CutsAndMonitors.cxx
CutMonitorRequest.cxx
CutFuncs.cxx
CutOptions.cxx
#EVENT CUTS
eventcuts/mc/EventImpactParameterCut.cxx
Expand Down
3 changes: 1 addition & 2 deletions cuts/CutContainer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include "AnaFile.h"
#include "Cout.h"
#include "CutFuncs.h"
#include "CutOptions.h"
#include "EventBinningCut.h"
#include "EventComplexCut.h"
Expand Down Expand Up @@ -78,7 +77,7 @@ namespace Hal {
// add to cut containers
auto addCutRaw = [&](ECutUpdate upd, Int_t colNo) {
if (fSize <= static_cast<Int_t>(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",
Expand Down
108 changes: 0 additions & 108 deletions cuts/CutFuncs.cxx

This file was deleted.

47 changes: 0 additions & 47 deletions cuts/CutFuncs.h

This file was deleted.

103 changes: 99 additions & 4 deletions cuts/CutOptions.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <TClass.h>
#include <TRegexp.h>

namespace Hal {
CutOptions::CutOptions(TString opt, Int_t defCol) {
Expand All @@ -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
}

Expand All @@ -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<const Hal::EventBinningCut*>(&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();
}
Expand Down Expand Up @@ -104,5 +112,92 @@ namespace Hal {
MakeComplexAxis(res, i, flag);
return res;
}
std::vector<Int_t> CutOptions::GetCollectionsFlags(Int_t startCol, TString option) const {
std::vector<Int_t> 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<const EventCut&>(cut));
} break;
case ECutUpdate::kTrack: {
res = new TrackRealCut(static_cast<const TrackCut&>(cut));
} break;
case ECutUpdate::kTwoTrack: {
res = new TwoTrackRealCut(static_cast<const TwoTrackCut&>(cut));
} break;
case ECutUpdate::kTwoTrackBackground: {
res = new TwoTrackRealCut(static_cast<const TwoTrackCut&>(cut));
} break;
default: return nullptr; break;
}
} else { // imaginary stuff
switch (upd) {
case ECutUpdate::kEvent: {
res = new EventImaginaryCut(static_cast<const EventCut&>(cut));
if (acceptNulls) static_cast<EventImaginaryCut*>(res)->AcceptNulls(kTRUE);
} break;
case ECutUpdate::kTrack: {
res = new TrackImaginaryCut(static_cast<const TrackCut&>(cut));
if (acceptNulls) static_cast<TrackImaginaryCut*>(res)->AcceptNulls(kTRUE);
} break;
case ECutUpdate::kTwoTrack: {
res = new TwoTrackImaginaryCut(static_cast<const TwoTrackCut&>(cut));
if (acceptNulls) static_cast<TwoTrackImaginaryCut*>(res)->AcceptNulls(kTRUE);
} break;
case ECutUpdate::kTwoTrackBackground: {
res = new TwoTrackImaginaryCut(static_cast<const TwoTrackCut&>(cut));
if (acceptNulls) static_cast<TwoTrackImaginaryCut*>(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<background>"; break;
default:
Cout::PrintInfo("Unknown update ratio", EInfo::kLowWarning);
update_ratio_name = "unknown";
break;
}
return update_ratio_name;
}


} /* namespace Hal */
23 changes: 23 additions & 0 deletions cuts/CutOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <vector>

#include "Object.h"
#include "Std.h"

namespace Hal {
class Cut;
Expand All @@ -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<Int_t> 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);
Expand Down
1 change: 0 additions & 1 deletion cuts/HalCutLinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 + ;
Expand Down

0 comments on commit 8c2b08d

Please sign in to comment.