10#include "CutContainer.h"
13#include <TCollection.h>
20#include "EventBinningCut.h"
21#include "EventComplexCut.h"
22#include "EventVirtualCut.h"
26#include "TrackComplexCut.h"
27#include "TrackVirtualCut.h"
28#include "TwoTrackComplexCut.h"
29#include "TwoTrackVirtualCut.h"
36 case ECutUpdate::kEvent: fSize = 1;
break;
37 case ECutUpdate::kTrack: fSize = 2;
break;
38 case ECutUpdate::kTwoTrack: fSize = 3;
break;
39 case ECutUpdate::kTwoTrackBackground: fSize = 4;
break;
41 Cout::PrintInfo(
"Unknown update ration in CutContainer", EInfo::kError);
44 fCutContainers =
new TObjArray*[fSize];
45 fTempCutMonitors =
new TObjArray*[fSize];
46 for (
int i = 0; i < fSize; i++) {
47 fCutContainers[i] =
new TObjArray();
48 fTempCutMonitors[i] =
new TObjArray();
53 TObject(cont), fInit(kFALSE), fSize(cont.fSize), fTempCutMonitors(NULL), fCutContainers(NULL) {
54 if (cont.fInit == kTRUE) { Cout::PrintInfo(
"CutContainer already initialized", EInfo::kError); }
55 fCutContainers =
new TObjArray*[fSize];
56 fTempCutMonitors =
new TObjArray*[fSize];
57 for (
int i = 0; i < fSize; i++) {
58 fCutContainers[i] =
new TObjArray();
59 for (
int j = 0; j < cont.fCutContainers[i]->GetEntries(); j++) {
61 fCutContainers[i]->Add(subcont->
MakeNewCopy(fCutContainers));
63 fTempCutMonitors[i] =
new TObjArray();
64 for (
int j = 0; j < cont.fTempCutMonitors[i]->GetEntries(); j++) {
66 fTempCutMonitors[i]->Add(mon->
MakeCopy());
73 if (Hal::Std::FindParam(option,
"im", kTRUE)) {
76 Hal::Cout::PrintInfo(Form(
"%s %i: cannot add binned cut with im flag", __FILE__, __LINE__), EInfo::kError);
79 Bool_t nulls = Hal::Std::FindParam(option,
"null", kTRUE);
80 tempcut = Hal::Cuts::MakeCutCopy(cut,
"im", nulls);
81 if (tempcut ==
nullptr)
return;
86 }
else if (Hal::Std::FindParam(option,
"re", kTRUE)) {
89 Hal::Cout::PrintInfo(Form(
"%s %i: cannot add binned cut with re flag", __FILE__, __LINE__), EInfo::kError);
92 tempcut = Hal::Cuts::MakeCutCopy(cut,
"re", kFALSE);
93 if (tempcut ==
nullptr)
return;
99 auto collections = Hal::Cuts::GetCollectionsFlags(cut.
GetCollectionID(), option);
101 if (CheckTwoTracksOptions(cut, opt)) {
103 Cout::PrintInfo(
"CutContainer using CheckTwoTracksOptions", EInfo::kDebugInfo);
107 if (Hal::Std::FindParam(option,
"bckg")) place = ECutUpdate::kTwoTrackBackground;
108 if (fSize <=
static_cast<Int_t
>(place)) {
109 TString update_ratio_name = Hal::Cuts::GetCutUpdateRatioName(place);
110 Cout::PrintInfo(Form(
"CutContainer can't hold %s cut because it's update ratio (%s) is "
111 "too big, check fTries or call SetOption(backround) before adding cuts "
114 update_ratio_name.Data()),
119 for (
auto collection : collections) {
120 if (GetCutContainer(place)->At(collection) ==
nullptr) {
123 GetCutContainer(place)->AddAtAndExpand(subcont, collection);
124 }
else if ((collection >= GetCutContainer(place)->GetEntriesFast())) {
127 GetCutContainer(place)->AddAtAndExpand(subcont, collection);
135 TString option = opt;
137 ExtractComplexMonitor(monitor_copy, option);
138 if (ExtractRegExp2(*monitor_copy, option)) {
142 if (ExtractRegExp(*monitor_copy, option)) {
147 if (update == ECutUpdate::kNo)
return;
148 if (CheckTwoTracksOptions(*monitor_copy, option)) {
152 if (Hal::Std::FindParam(option,
"bckg")) { update = ECutUpdate::kTwoTrackBackground; }
153 if (fSize <=
static_cast<Int_t
>(update)) {
154 Cout::PrintInfo(
"CutContainer can't hold this cut because it's update ratio is to big, check fTries or call "
155 "SetOption(backround) before adding cuts or cut monitors",
159 fTempCutMonitors[
static_cast<Int_t
>(update)]->AddLast(monitor_copy);
163 for (
int i = 0; i < fSize; i++) {
164 for (
int j = 0; j < fCutContainers[i]->GetEntriesFast(); j++) {
165 ((
CutCollection*) fCutContainers[i]->UncheckedAt(j))->PrintInfo();
171 if (opt_high == opt_low || opt_low > opt_high) {
Cout::PrintInfo(
"Wrong ECut Update in Link Collections", EInfo::kError); }
172 if (
static_cast<Int_t
>(opt_high) >= fSize) {
173 Cout::PrintInfo(
"To big opt_high, link will be ingored", EInfo::kError);
174 }
else if (
static_cast<Int_t
>(opt_low) >= fSize) {
175 Cout::PrintInfo(
"To big opt_low, link will be ingored", EInfo::kError);
179 if (opt_low == ECutUpdate::kEvent) {
181 }
else if (opt_low == ECutUpdate::kTrack) {
184 Cout::PrintInfo(
"Invalid opt_low argument in CutContainer::LinkCollections", EInfo::kError);
187 if (opt_high == ECutUpdate::kTrack) {
188 high = (
CutCollection*) GetCutContainer(opt_high)->At(in_high);
189 }
else if (opt_high == ECutUpdate::kTwoTrack || opt_high == ECutUpdate::kTwoTrackBackground) {
190 high = (
CutCollection*) GetCutContainer(opt_high)->At(in_high);
192 Cout::PrintInfo(
"Invalid opt_high argument in CutContainer::LinkCollections", EInfo::kError);
195 if (low == NULL || high == NULL) {
200 if (opt_high == ECutUpdate::kTwoTrackBackground) {
209 old = (
CutCollection*) GetCutContainer(type)->UncheckedAt(collection_no);
210 GetCutContainer(type)->AddAtAndExpand(old->
Replicate(new_collection_no), new_collection_no);
213 void CutContainer::VerifyOrder(TObjArray* obj) {
214 for (
int i = 0; i < obj->GetEntriesFast(); i++) {
215 if (obj->UncheckedAt(i) == NULL) {
Cout::PrintInfo(Form(
"Null cutsubcontainers at %i", i), EInfo::kError); }
216 Int_t collection_no = ((CutCollection*) obj->UncheckedAt(i))->GetCollectionID();
217 if (collection_no != i) {
Cout::PrintInfo(Form(
"Wrong order of cuts [%i]!=%i", i, collection_no), EInfo::kError); }
223 CutContainer::~CutContainer() {
224 for (
int i = 0; i < fSize; i++) {
225 if (fCutContainers[i] != NULL) fCutContainers[i]->Delete();
227 if (fCutContainers)
delete fCutContainers;
228 if (fTempCutMonitors) {
229 for (
int i = 0; i < fSize; i++) {
230 fTempCutMonitors[i]->Delete();
232 delete[] fTempCutMonitors;
237 if (fInit == kTRUE) {
238 Cout::PrintInfo(
"CutContainer has been initialized before", EInfo::kLowWarning);
241 for (
int i = 0; i < fSize; i++) {
242 VerifyOrder(fCutContainers[i]);
244 for (
int k = 0; k < fSize; k++) {
245 for (
int j = 0; j < fTempCutMonitors[k]->GetEntriesFast(); j++) {
250 if ((
CutCollection*) (fCutContainers[k]->UncheckedAt(collection)) == NULL) {
251 Cout::PrintInfo(Form(
" Collection %i for cut monitor %s not found", collection, clone->ClassName()), EInfo::kError);
253 ((
CutCollection*) (fCutContainers[k]->UncheckedAt(collection)))->AddCutMonitor(clone);
256 for (
int i = 0; i < fCutContainers[k]->GetEntriesFast(); i++) {
258 ((
CutCollection*) (fCutContainers[k]->UncheckedAt(i)))->AddCutMonitor(clone);
265 for (
int i = 0; i < fCutContainers[k]->GetEntriesFast(); i++) {
267 Cout::PrintInfo(Form(
"Initializing cut collection at %i", k), EInfo::kDebugInfo);
269 ((
CutCollection*) (fCutContainers[k]->UncheckedAt(i)))->Init(task_id);
275 for (
int i = 0; i < fSize; i++) {
276 fTempCutMonitors[i]->Delete();
278 delete[] fTempCutMonitors;
279 fTempCutMonitors = NULL;
286 pack->
AddObject(
new ParameterInt(
"Event_collections_No", GetCutContainer(ECutUpdate::kEvent)->GetEntriesFast()));
287 TList* list1 =
new TList();
288 list1->SetOwner(kTRUE);
289 list1->SetName(
"EventCutCollectionList");
290 for (
int i = 0; i < GetCutContainer(ECutUpdate::kEvent)->GetEntriesFast(); i++) {
291 list1->Add(((
CutCollection*) GetCutContainer(ECutUpdate::kEvent)->UncheckedAt(i))->
Report());
296 pack->
AddObject(
new ParameterInt(
"Track_collections_No", GetCutContainer(ECutUpdate::kTrack)->GetEntriesFast()));
297 TList* list2 =
new TList();
298 list2->SetOwner(kTRUE);
299 list2->SetName(
"TrackCutCollectionList");
300 for (
int i = 0; i < GetCutContainer(ECutUpdate::kTrack)->GetEntriesFast(); i++) {
301 list2->Add(((
CutCollection*) GetCutContainer(ECutUpdate::kTrack)->UncheckedAt(i))->
Report());
306 pack->
AddObject(
new ParameterInt(
"TwoTrack_collections_No", GetCutContainer(ECutUpdate::kTwoTrack)->GetEntriesFast()));
307 TList* list3 =
new TList();
308 list3->SetOwner(kTRUE);
309 list3->SetName(
"TwoTrackCutCollectionList");
310 for (
int i = 0; i < GetCutContainer(ECutUpdate::kTwoTrack)->GetEntriesFast(); i++) {
311 list3->Add(((
CutCollection*) GetCutContainer(ECutUpdate::kTwoTrack)->UncheckedAt(i))->
Report());
317 GetCutContainer(ECutUpdate::kTwoTrackBackground)->GetEntriesFast()));
318 TList* list4 =
new TList();
319 list4->SetOwner(kTRUE);
320 list4->SetName(
"TwoTrackBackgroundCutCollectionList");
321 for (
int i = 0; i < GetCutContainer(ECutUpdate::kTwoTrackBackground)->GetEntriesFast(); i++) {
322 list4->Add(((
CutCollection*) GetCutContainer(ECutUpdate::kTwoTrackBackground)->UncheckedAt(i))->
Report());
330 Bool_t CutContainer::ExtractRegExp(
const CutMonitor& cut, Option_t* opt) {
331 TString option = opt;
333 Bool_t found = Hal::Std::FindExpressionTwoValues(option, number, jump, kTRUE);
334 if (!found)
return kFALSE;
337 if (begin_collection == -1) {
338 Cout::PrintInfo(Form(
"Adding cut monitor %s (first cut %s ) with collection no -1, with "
339 "regular expression like {AxB} set initial collection no to 0",
343 begin_collection = 0;
345 CutMonitor* temp_cut;
346 for (
int i = 0; i < number; i++) {
355 Bool_t CutContainer::CheckTwoTracksOptions(
const CutMonitor& cutmon, Option_t* opt) {
356 if (!(cutmon.GetUpdateRatio() == ECutUpdate::kTwoTrack || cutmon.GetUpdateRatio() == ECutUpdate::kTwoTrackBackground)) {
359 TString option = opt;
360 if (Hal::Std::FindParam(option,
"bckg") && Hal::Std::FindParam(option,
"sig")) {
361 Hal::Std::FindParam(option,
"bckg", kTRUE);
362 Hal::Std::FindParam(option,
"im", kTRUE);
366 }
else if (Hal::Std::FindParam(option,
"both", kTRUE)) {
370 }
else if (!Hal::Std::FindParam(option,
"bckg") && !Hal::Std::FindParam(option,
"sig")) {
378 Bool_t CutContainer::CheckTwoTracksOptions(
const Cut& cut, Option_t* opt) {
379 if (!(cut.GetUpdateRatio() == ECutUpdate::kTwoTrack || cut.GetUpdateRatio() == ECutUpdate::kTwoTrackBackground)) {
382 TString option = opt;
383 if (Hal::Std::FindParam(option,
"bckg") && Hal::Std::FindParam(option,
"sig")) {
384 Hal::Std::FindParam(option,
"bckg", kTRUE);
385 Hal::Std::FindParam(option,
"sig", kTRUE);
389 }
else if (Hal::Std::FindParam(option,
"both", kTRUE)) {
390 AddCut(cut, option +
"+sig");
391 AddCut(cut, option +
"+bckg");
393 }
else if (!Hal::Std::FindParam(option,
"bckg") && !Hal::Std::FindParam(option,
"sig")) {
394 AddCut(cut, option +
"+sig");
395 AddCut(cut, option +
"+bckg");
402 if (fSize < 1)
return 0;
403 return GetCutContainer(ECutUpdate::kEvent)->GetEntriesFast();
407 if (fSize < 2)
return 0;
408 return GetCutContainer(ECutUpdate::kTrack)->GetEntriesFast();
412 if (fSize < 3)
return 0;
413 return GetCutContainer(ECutUpdate::kTwoTrack)->GetEntriesFast();
417 if (fSize < 4)
return 0;
418 return GetCutContainer(ECutUpdate::kTwoTrackBackground)->GetEntriesFast();
421 Bool_t CutContainer::ExtractRegExp2(
const CutMonitor& monit, Option_t* opt) {
422 TString option = opt;
424 if (!Hal::Std::FindExpressionSingleValue(option, number, kTRUE))
return kFALSE;
433 if (
static_cast<Int_t
>(update) < 0)
return;
434 if (this->fSize <=
static_cast<Int_t
>(update)) {
435 Cout::PrintInfo(
"Cannot Make Dummy copy of CutCollection!lack of space "
436 "in target cut container!",
440 if (other->fSize <=
static_cast<Int_t
>(update)) {
442 "object in source cut container",
446 if (this->fInit == kTRUE || other->fInit == kFALSE) {
447 Cout::PrintInfo(
"You can't copy sub containers from not initialized cut container to initialized cut container!! ",
450 for (
int i = 0; i < other->GetCutContainer(update)->GetEntriesFast(); i++) {
457 void CutContainer::ExtractComplexMonitor(
CutMonitor* mon, TString& opt) {
459 if (Hal::Std::FindParam(opt,
"im") || Hal::Std::FindParam(opt,
"re")) {
460 if (opt.Contains(
"im")) flag = -1;
461 if (opt.Contains(
"re")) flag = 1;
462 opt.ReplaceAll(
"+im",
"");
463 opt.ReplaceAll(
"+re",
"");
464 opt.ReplaceAll(
"im",
"");
465 opt.ReplaceAll(
"re",
"");
467 if (mon->InheritsFrom(
"Hal::CutMonitorXY")) size = 2;
468 if (mon->InheritsFrom(
"Hal::CutMonitorXYZ")) size = 3;
471 MakeComplexAxis(mon, 0, flag);
474 MakeComplexAxis(mon, 0, flag);
475 MakeComplexAxis(mon, 1, flag);
478 MakeComplexAxis(mon, 0, flag);
479 MakeComplexAxis(mon, 1, flag);
480 MakeComplexAxis(mon, 2, flag);
486 void CutContainer::MakeComplexAxis(CutMonitor* mon, Int_t axis, Int_t flag) {
488 TClass* clas = TClass::GetClass(cut_name, kTRUE, kTRUE);
489 TString pattern =
"";
490 if (clas->InheritsFrom(
"Hal::EventCut")) {
492 pattern =
"Hal::EventImaginaryCut";
494 pattern =
"Hal::EventRealCut";
496 }
else if (clas->InheritsFrom(
"Hal::TrackCut")) {
498 pattern =
"Hal::TrackImaginaryCut";
500 pattern =
"Hal::TrackRealCut";
504 pattern =
"Hal::TwoTrackImaginaryCut";
506 pattern =
"Hal::TwoTrackRealCut";
509 mon->fCutNames[axis] = Form(
"%s(%s)", pattern.Data(), mon->GetCutName(axis).Data());
514 case ECutUpdate::kEvent: {
517 case ECutUpdate::kTrack: {
520 case ECutUpdate::kTwoTrack: {
523 case ECutUpdate::kTwoTrackBackground: {
526 case ECutUpdate::kNo: {
536 case ECutUpdate::kEvent: {
541 case ECutUpdate::kTrack: {
546 case ECutUpdate::kTwoTrack: {
551 case ECutUpdate::kTwoTrackBackground: {
556 case ECutUpdate::kNo: {
568 case ELinkPolicy::kOneToMany: {
570 Cout::PrintInfo(
"EventAna::LinkCollections one-to-many to much first collections!", EInfo::kError);
573 for (
int i = 0; i < highLinks; i++) {
578 case ELinkPolicy::kEqual: {
579 if (lowLinks > highLinks) {
580 Int_t jump = lowLinks / highLinks;
581 if (lowLinks % highLinks) {
582 Cout::PrintInfo(
"EventAna::LinkCollections equal link cannot group cuts!", EInfo::kError);
585 for (
int i = 0; i < highLinks; i++) {
586 for (
int j = 0; j < jump; j++) {
592 Int_t jump = highLinks / lowLinks;
593 if (highLinks % lowLinks) {
594 Cout::PrintInfo(
"EventAna::LinkCollections equal link cannot group cuts!", EInfo::kError);
597 for (
int i = 0; i < lowLinks; i++) {
598 for (
int j = 0; j < jump; j++) {
605 case ELinkPolicy::kReplicateLast: {
606 for (
int i = 1; i < lowLinks; i++) {
607 for (
int j = 0; j < highLinks; j++) {
611 for (
int i = 0; i < lowLinks; i++) {
612 for (
int j = 0; j < highLinks; j++) {
618 case ELinkPolicy::kReplicateFirst: {
619 for (
int i = 1; i < highLinks; i++) {
620 for (
int j = 0; j < lowLinks; j++) {
624 for (
int i = 0; i < highLinks; i++) {
625 for (
int j = 0; j < lowLinks; j++) {
631 case ELinkPolicy::kAnyToAny: {
632 for (
int i = 0; i < lowLinks; i++) {
633 for (
int j = 0; j < highLinks; j++) {
static void PrintInfo(TString text, Hal::EInfo status)
void MakeDummyCopy(const CutCollection *copy, Bool_t copy_high_links=kTRUE)
CutCollection * MakeNewCopy(TObjArray **container) const
void AddPreviousAddr(Int_t value, Bool_t background=kFALSE)
void AddCut(Cut *cut, Option_t *opt=" ")
CutCollection * Replicate(Int_t new_collection) const
void AddNextAddr(Int_t value, Bool_t background=kFALSE)
void ReplicateCollection(ECutUpdate type, Int_t collection_no, Int_t new_collection_no, Option_t *option="")
void MakeDummyCopies(ECutUpdate update, CutContainer *other, Bool_t copy_link)
Int_t GetTwoTrackCollectionsBackgroundNo() const
void LinkCollections(ECutUpdate opt_low, Int_t in_low, ECutUpdate opt_high, Int_t in_high)
void RemoveCollection(ECutUpdate update, Int_t collection)
void AddVirtualCut(ECutUpdate update, Int_t col)
virtual Package * Report() const
Int_t GetTwoTrackCollectionsNo() const
void AddMonitor(const CutMonitor &monitor, Option_t *opt=" ")
void AddCut(const Cut &cut, Option_t *opt=" ")
Int_t GetCollectionsNo(ECutUpdate update) const
void Init(const Int_t task_id=0)
Int_t GetEventCollectionsNo() const
Int_t GetTrackCollectionsNo() const
TString GetCutName(Int_t i) const
Int_t GetCollectionID() const
ECutUpdate GetUpdateRatio() const
virtual CutMonitor * MakeCopy() const
void SetCollectionID(Int_t i)
ECutUpdate GetUpdateRatio() const
void SetCollectionID(Int_t i)
virtual Cut * MakeCopy() const
Int_t GetCollectionID() const
void SetComment(TString name)
void AddObject(TObject *object)