Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
CutContainer.cxx
1/*
2 * CutContainer.cxx
3 *
4 * Created on: 06-08-2013
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9
10#include "CutContainer.h"
11
12#include <TClass.h>
13#include <TCollection.h>
14#include <TList.h>
15#include <TRegexp.h>
16#include <iostream>
17
18#include "Cout.h"
19#include "CutFuncs.h"
20#include "EventBinningCut.h"
21#include "EventComplexCut.h"
22#include "EventVirtualCut.h"
23#include "Package.h"
24#include "Parameter.h"
25#include "StdString.h"
26#include "TrackComplexCut.h"
27#include "TrackVirtualCut.h"
28#include "TwoTrackComplexCut.h"
29#include "TwoTrackVirtualCut.h"
30
31namespace Hal {
32 CutContainer::CutContainer() : TObject(), fInit(kFALSE), fSize(0), fTempCutMonitors(NULL), fCutContainers(NULL) {}
33
34 CutContainer::CutContainer(ECutUpdate tiers) : fInit(kFALSE), fTempCutMonitors(NULL), fCutContainers(NULL) {
35 switch (tiers) {
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;
40 default: {
41 Cout::PrintInfo("Unknown update ration in CutContainer", EInfo::kError);
42 } break;
43 }
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();
49 }
50 }
51
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++) {
60 CutCollection* subcont = (CutCollection*) cont.fCutContainers[i]->UncheckedAt(j);
61 fCutContainers[i]->Add(subcont->MakeNewCopy(fCutContainers));
62 }
63 fTempCutMonitors[i] = new TObjArray();
64 for (int j = 0; j < cont.fTempCutMonitors[i]->GetEntries(); j++) {
65 CutMonitor* mon = (CutMonitor*) cont.fTempCutMonitors[i]->At(j);
66 fTempCutMonitors[i]->Add(mon->MakeCopy());
67 }
68 }
69 }
70
71 void CutContainer::AddCut(const Cut& cut, Option_t* opt) {
72 TString option = opt;
73 if (Hal::Std::FindParam(option, "im", kTRUE)) {
74 Cut* tempcut = NULL;
75 if (dynamic_cast<const Hal::EventBinningCut*>(&cut)) {
76 Hal::Cout::PrintInfo(Form("%s %i: cannot add binned cut with im flag", __FILE__, __LINE__), EInfo::kError);
77 return;
78 }
79 Bool_t nulls = Hal::Std::FindParam(option, "null", kTRUE);
80 tempcut = Hal::Cuts::MakeCutCopy(cut, "im", nulls);
81 if (tempcut == nullptr) return;
82 tempcut->SetCollectionID(cut.GetCollectionID());
83 AddCut(*tempcut, option);
84 delete tempcut;
85 return;
86 } else if (Hal::Std::FindParam(option, "re", kTRUE)) {
87 Cut* tempcut = NULL;
88 if (dynamic_cast<const Hal::EventBinningCut*>(&cut)) {
89 Hal::Cout::PrintInfo(Form("%s %i: cannot add binned cut with re flag", __FILE__, __LINE__), EInfo::kError);
90 return;
91 }
92 tempcut = Hal::Cuts::MakeCutCopy(cut, "re", kFALSE);
93 if (tempcut == nullptr) return;
94 tempcut->SetCollectionID(cut.GetCollectionID());
95 AddCut(*tempcut, option);
96 delete tempcut;
97 return;
98 }
99 auto collections = Hal::Cuts::GetCollectionsFlags(cut.GetCollectionID(), option);
100 ECutUpdate place = cut.GetUpdateRatio();
101 if (CheckTwoTracksOptions(cut, opt)) {
102#ifdef HAL_DEBUG
103 Cout::PrintInfo("CutContainer using CheckTwoTracksOptions", EInfo::kDebugInfo);
104#endif
105 return;
106 }
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 "
112 "or cut monitors",
113 cut.ClassName(),
114 update_ratio_name.Data()),
115 EInfo::kLowWarning);
116 return;
117 }
118 // add to cut containers
119 for (auto collection : collections) {
120 if (GetCutContainer(place)->At(collection) == nullptr) {
121 CutCollection* subcont = new CutCollection(fCutContainers, fSize, place, collection);
122 subcont->AddCut(cut.MakeCopy(), opt);
123 GetCutContainer(place)->AddAtAndExpand(subcont, collection);
124 } else if ((collection >= GetCutContainer(place)->GetEntriesFast())) {
125 CutCollection* subcont = new CutCollection(fCutContainers, fSize, place, collection);
126 subcont->AddCut(cut.MakeCopy(), opt);
127 GetCutContainer(place)->AddAtAndExpand(subcont, collection);
128 } else {
129 ((CutCollection*) GetCutContainer(place)->UncheckedAt(collection))->AddCut(cut.MakeCopy(), opt);
130 }
131 }
132 }
133
134 void CutContainer::AddMonitor(const CutMonitor& monitor, Option_t* opt) {
135 TString option = opt;
136 CutMonitor* monitor_copy = monitor.MakeCopy();
137 ExtractComplexMonitor(monitor_copy, option);
138 if (ExtractRegExp2(*monitor_copy, option)) {
139 delete monitor_copy;
140 return;
141 }
142 if (ExtractRegExp(*monitor_copy, option)) {
143 delete monitor_copy;
144 return;
145 }
146 ECutUpdate update = monitor.GetUpdateRatio();
147 if (update == ECutUpdate::kNo) return;
148 if (CheckTwoTracksOptions(*monitor_copy, option)) {
149 delete monitor_copy;
150 return;
151 }
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",
156 EInfo::kLowWarning);
157 return;
158 }
159 fTempCutMonitors[static_cast<Int_t>(update)]->AddLast(monitor_copy);
160 }
161
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();
166 }
167 }
168 }
169
170 void CutContainer::LinkCollections(ECutUpdate opt_low, Int_t in_low, ECutUpdate opt_high, Int_t in_high) {
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);
176 }
177 CutCollection* low = NULL;
178 CutCollection* high = NULL;
179 if (opt_low == ECutUpdate::kEvent) {
180 low = (CutCollection*) GetCutContainer(opt_low)->At(in_low);
181 } else if (opt_low == ECutUpdate::kTrack) {
182 low = (CutCollection*) GetCutContainer(opt_low)->At(in_low);
183 } else {
184 Cout::PrintInfo("Invalid opt_low argument in CutContainer::LinkCollections", EInfo::kError);
185 return;
186 }
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);
191 } else {
192 Cout::PrintInfo("Invalid opt_high argument in CutContainer::LinkCollections", EInfo::kError);
193 return;
194 }
195 if (low == NULL || high == NULL) {
196 Cout::PrintInfo("Cant link some collections", EInfo::kError);
197 return;
198 }
199 high->AddPreviousAddr(in_low, 0);
200 if (opt_high == ECutUpdate::kTwoTrackBackground) {
201 if (!high->IsDummy()) low->AddNextAddr(in_high, kTRUE);
202 } else {
203 if (!high->IsDummy()) low->AddNextAddr(in_high, kFALSE);
204 }
205 }
206
207 void CutContainer::ReplicateCollection(ECutUpdate type, Int_t collection_no, Int_t new_collection_no, Option_t* /*option*/) {
208 CutCollection* old = NULL;
209 old = (CutCollection*) GetCutContainer(type)->UncheckedAt(collection_no);
210 GetCutContainer(type)->AddAtAndExpand(old->Replicate(new_collection_no), new_collection_no);
211 }
212
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); }
218 }
219 }
220
221 void CutContainer::RemoveCollection(ECutUpdate update, Int_t collection) { GetCutContainer(update)->RemoveAt(collection); }
222
223 CutContainer::~CutContainer() {
224 for (int i = 0; i < fSize; i++) {
225 if (fCutContainers[i] != NULL) fCutContainers[i]->Delete();
226 }
227 if (fCutContainers) delete fCutContainers;
228 if (fTempCutMonitors) {
229 for (int i = 0; i < fSize; i++) {
230 fTempCutMonitors[i]->Delete();
231 }
232 delete[] fTempCutMonitors;
233 }
234 }
235
236 void CutContainer::Init(const Int_t task_id) {
237 if (fInit == kTRUE) {
238 Cout::PrintInfo("CutContainer has been initialized before", EInfo::kLowWarning);
239 return;
240 }
241 for (int i = 0; i < fSize; i++) {
242 VerifyOrder(fCutContainers[i]);
243 }
244 for (int k = 0; k < fSize; k++) {
245 for (int j = 0; j < fTempCutMonitors[k]->GetEntriesFast(); j++) {
246 CutMonitor* cutmon = (CutMonitor*) fTempCutMonitors[k]->UncheckedAt(j);
247 if (cutmon->GetCollectionID() != -1) {
248 CutMonitor* clone = cutmon->MakeCopy();
249 Int_t collection = cutmon->GetCollectionID();
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);
252 } else {
253 ((CutCollection*) (fCutContainers[k]->UncheckedAt(collection)))->AddCutMonitor(clone);
254 }
255 } else {
256 for (int i = 0; i < fCutContainers[k]->GetEntriesFast(); i++) {
257 CutMonitor* clone = cutmon->MakeCopy();
258 ((CutCollection*) (fCutContainers[k]->UncheckedAt(i)))->AddCutMonitor(clone);
259 }
260 }
261 }
262#ifdef HAL_DEBUG
263 Cout::PrintInfo("Initializing cut collection", EInfo::kDebugInfo);
264#endif
265 for (int i = 0; i < fCutContainers[k]->GetEntriesFast(); i++) {
266#ifdef HAL_DEBUG
267 Cout::PrintInfo(Form("Initializing cut collection at %i", k), EInfo::kDebugInfo);
268#endif
269 ((CutCollection*) (fCutContainers[k]->UncheckedAt(i)))->Init(task_id);
270 }
271 }
272#ifdef HAL_DEBUG
273 Cout::PrintInfo("Deleting temporary cut monitors", EInfo::kDebugInfo);
274#endif
275 for (int i = 0; i < fSize; i++) {
276 fTempCutMonitors[i]->Delete();
277 }
278 delete[] fTempCutMonitors;
279 fTempCutMonitors = NULL;
280 fInit = kTRUE;
281 }
282
284 Package* pack = new Package(this, kTRUE);
285 if (fSize > 0) {
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());
292 }
293 pack->AddObject(list1);
294 }
295 if (fSize > 1) {
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());
302 }
303 pack->AddObject(list2);
304 }
305 if (fSize > 2) {
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());
312 }
313 pack->AddObject(list3);
314 }
315 if (fSize > 3) {
316 pack->AddObject(new ParameterInt("TwoTrack_collections_background_No",
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());
323 }
324 pack->AddObject(list4);
325 }
326 pack->SetComment(this->ClassName());
327 return pack;
328 }
329
330 Bool_t CutContainer::ExtractRegExp(const CutMonitor& cut, Option_t* opt) {
331 TString option = opt;
332 Int_t number, jump;
333 Bool_t found = Hal::Std::FindExpressionTwoValues(option, number, jump, kTRUE);
334 if (!found) return kFALSE;
335 // found regular exprestion like {number x number}
336 Int_t begin_collection = cut.GetCollectionID();
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",
340 cut.ClassName(),
341 cut.GetCutName(0).Data()),
342 EInfo::kLowWarning);
343 begin_collection = 0;
344 }
345 CutMonitor* temp_cut;
346 for (int i = 0; i < number; i++) {
347 temp_cut = cut.MakeCopy();
348 temp_cut->SetCollectionID(begin_collection + i * jump);
349 AddMonitor(*temp_cut, option.Data());
350 delete temp_cut;
351 }
352 return kTRUE;
353 }
354
355 Bool_t CutContainer::CheckTwoTracksOptions(const CutMonitor& cutmon, Option_t* opt) {
356 if (!(cutmon.GetUpdateRatio() == ECutUpdate::kTwoTrack || cutmon.GetUpdateRatio() == ECutUpdate::kTwoTrackBackground)) {
357 return kFALSE;
358 }
359 TString option = opt;
360 if (Hal::Std::FindParam(option, "bckg") && Hal::Std::FindParam(option, "sig")) { // bckg + sig options
361 Hal::Std::FindParam(option, "bckg", kTRUE);
362 Hal::Std::FindParam(option, "im", kTRUE);
363 AddMonitor(cutmon, option + "bckg");
364 AddMonitor(cutmon, option + "sig");
365 return kTRUE;
366 } else if (Hal::Std::FindParam(option, "both", kTRUE)) { // both options
367 AddMonitor(cutmon, option + "+sig");
368 AddMonitor(cutmon, option + "+bckg");
369 return kTRUE;
370 } else if (!Hal::Std::FindParam(option, "bckg") && !Hal::Std::FindParam(option, "sig")) { // no specification
371 AddMonitor(cutmon, option + "+sig");
372 AddMonitor(cutmon, option + "+bckg");
373 return kTRUE;
374 }
375 return kFALSE; // valid option - sig or bckg
376 }
377
378 Bool_t CutContainer::CheckTwoTracksOptions(const Cut& cut, Option_t* opt) {
379 if (!(cut.GetUpdateRatio() == ECutUpdate::kTwoTrack || cut.GetUpdateRatio() == ECutUpdate::kTwoTrackBackground)) {
380 return kFALSE;
381 }
382 TString option = opt;
383 if (Hal::Std::FindParam(option, "bckg") && Hal::Std::FindParam(option, "sig")) { // bckg + sig options
384 Hal::Std::FindParam(option, "bckg", kTRUE);
385 Hal::Std::FindParam(option, "sig", kTRUE);
386 AddCut(cut, option);
387 AddCut(cut, option);
388 return kTRUE;
389 } else if (Hal::Std::FindParam(option, "both", kTRUE)) { // both options
390 AddCut(cut, option + "+sig");
391 AddCut(cut, option + "+bckg");
392 return kTRUE;
393 } else if (!Hal::Std::FindParam(option, "bckg") && !Hal::Std::FindParam(option, "sig")) { // no specification
394 AddCut(cut, option + "+sig");
395 AddCut(cut, option + "+bckg");
396 return kTRUE;
397 }
398 return kFALSE; // valid option - sig or bckg
399 }
400
402 if (fSize < 1) return 0;
403 return GetCutContainer(ECutUpdate::kEvent)->GetEntriesFast();
404 }
405
407 if (fSize < 2) return 0;
408 return GetCutContainer(ECutUpdate::kTrack)->GetEntriesFast();
409 }
410
412 if (fSize < 3) return 0;
413 return GetCutContainer(ECutUpdate::kTwoTrack)->GetEntriesFast();
414 }
415
417 if (fSize < 4) return 0;
418 return GetCutContainer(ECutUpdate::kTwoTrackBackground)->GetEntriesFast();
419 }
420
421 Bool_t CutContainer::ExtractRegExp2(const CutMonitor& monit, Option_t* opt) {
422 TString option = opt;
423 Int_t number;
424 if (!Hal::Std::FindExpressionSingleValue(option, number, kTRUE)) return kFALSE;
425 CutMonitor* temp_mon = monit.MakeCopy();
426 temp_mon->SetCollectionID(number);
427 AddMonitor(*temp_mon, option.Data());
428 delete temp_mon;
429 return kTRUE;
430 }
431
432 void CutContainer::MakeDummyCopies(ECutUpdate update, CutContainer* other, Bool_t copy_link) {
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!",
437 EInfo::kError);
438 return;
439 }
440 if (other->fSize <= static_cast<Int_t>(update)) {
441 Cout::PrintInfo("Cannot Make Dummy copy of CutCollection!! lack of "
442 "object in source cut container",
443 EInfo::kError);
444 return;
445 }
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!! ",
448 EInfo::kLowWarning);
449 }
450 for (int i = 0; i < other->GetCutContainer(update)->GetEntriesFast(); i++) {
451 CutCollection* from = (CutCollection*) other->GetCutContainer(update)->UncheckedAt(i);
452 CutCollection* to = (CutCollection*) this->GetCutContainer(update)->UncheckedAt(i);
453 to->MakeDummyCopy(from, copy_link);
454 }
455 }
456
457 void CutContainer::ExtractComplexMonitor(CutMonitor* mon, TString& opt) {
458 Int_t flag = 0;
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", "");
466 Int_t size = 1;
467 if (mon->InheritsFrom("Hal::CutMonitorXY")) size = 2;
468 if (mon->InheritsFrom("Hal::CutMonitorXYZ")) size = 3;
469 switch (size) {
470 case 1: {
471 MakeComplexAxis(mon, 0, flag);
472 } break;
473 case 2: {
474 MakeComplexAxis(mon, 0, flag);
475 MakeComplexAxis(mon, 1, flag);
476 } break;
477 case 3: {
478 MakeComplexAxis(mon, 0, flag);
479 MakeComplexAxis(mon, 1, flag);
480 MakeComplexAxis(mon, 2, flag);
481 } break;
482 }
483 }
484 }
485
486 void CutContainer::MakeComplexAxis(CutMonitor* mon, Int_t axis, Int_t flag) {
487 TString cut_name = mon->GetCutName(axis);
488 TClass* clas = TClass::GetClass(cut_name, kTRUE, kTRUE);
489 TString pattern = "";
490 if (clas->InheritsFrom("Hal::EventCut")) {
491 if (flag == -1) { // im
492 pattern = "Hal::EventImaginaryCut";
493 } else { // re
494 pattern = "Hal::EventRealCut";
495 }
496 } else if (clas->InheritsFrom("Hal::TrackCut")) {
497 if (flag == -1) { // im
498 pattern = "Hal::TrackImaginaryCut";
499 } else { // re
500 pattern = "Hal::TrackRealCut";
501 }
502 } else {
503 if (flag == -1) { // im
504 pattern = "Hal::TwoTrackImaginaryCut";
505 } else { // re
506 pattern = "Hal::TwoTrackRealCut";
507 }
508 }
509 mon->fCutNames[axis] = Form("%s(%s)", pattern.Data(), mon->GetCutName(axis).Data());
510 }
511
512 Int_t CutContainer::GetCollectionsNo(ECutUpdate update) const {
513 switch (update) {
514 case ECutUpdate::kEvent: {
515 return GetEventCollectionsNo();
516 } break;
517 case ECutUpdate::kTrack: {
518 return GetTrackCollectionsNo();
519 } break;
520 case ECutUpdate::kTwoTrack: {
522 } break;
523 case ECutUpdate::kTwoTrackBackground: {
525 } break;
526 case ECutUpdate::kNo: {
527 return 0;
528 // DO nothing
529 } break;
530 }
531 return 0;
532 }
533
534 void CutContainer::AddVirtualCut(ECutUpdate update, Int_t col) {
535 switch (update) {
536 case ECutUpdate::kEvent: {
538 v.SetCollectionID(col);
539 AddCut(v);
540 } break;
541 case ECutUpdate::kTrack: {
543 v.SetCollectionID(col);
544 AddCut(v);
545 } break;
546 case ECutUpdate::kTwoTrack: {
548 v.SetCollectionID(col);
549 AddCut(v, "sig");
550 } break;
551 case ECutUpdate::kTwoTrackBackground: {
553 v.SetCollectionID(col);
554 AddCut(v, "bckg");
555 } break;
556 case ECutUpdate::kNo: {
557 /* do nothing */
558 } break;
559 }
560 }
561
562 Bool_t CutContainer::LinkCollections(ECutUpdate first, ECutUpdate last, ELinkPolicy policy) {
563 Int_t lowLinks = GetCollectionsNo(first);
564 Int_t highLinks = GetCollectionsNo(last);
565 if (lowLinks == 0) AddVirtualCut(first, 0);
566 if (highLinks == 0) AddVirtualCut(last, 0);
567 switch (policy) {
568 case ELinkPolicy::kOneToMany: {
569 if (lowLinks != 1) {
570 Cout::PrintInfo("EventAna::LinkCollections one-to-many to much first collections!", EInfo::kError);
571 return kFALSE;
572 }
573 for (int i = 0; i < highLinks; i++) {
574 LinkCollections(first, 0, last, i);
575 }
576 return kTRUE;
577 } break;
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);
583 return kFALSE;
584 }
585 for (int i = 0; i < highLinks; i++) {
586 for (int j = 0; j < jump; j++) {
587 LinkCollections(first, i * jump + j, last, i);
588 }
589 }
590 return kTRUE;
591 } else {
592 Int_t jump = highLinks / lowLinks;
593 if (highLinks % lowLinks) {
594 Cout::PrintInfo("EventAna::LinkCollections equal link cannot group cuts!", EInfo::kError);
595 return kFALSE;
596 }
597 for (int i = 0; i < lowLinks; i++) {
598 for (int j = 0; j < jump; j++) {
599 LinkCollections(first, i, last, i * jump + j);
600 }
601 }
602 return kTRUE;
603 }
604 } break;
605 case ELinkPolicy::kReplicateLast: {
606 for (int i = 1; i < lowLinks; i++) {
607 for (int j = 0; j < highLinks; j++) {
608 ReplicateCollection(last, j, i * highLinks + j);
609 }
610 }
611 for (int i = 0; i < lowLinks; i++) {
612 for (int j = 0; j < highLinks; j++) {
613 LinkCollections(first, i, last, i * highLinks + j);
614 }
615 }
616 return kTRUE;
617 } break;
618 case ELinkPolicy::kReplicateFirst: {
619 for (int i = 1; i < highLinks; i++) {
620 for (int j = 0; j < lowLinks; j++) {
621 ReplicateCollection(first, j, i * lowLinks + j);
622 }
623 }
624 for (int i = 0; i < highLinks; i++) {
625 for (int j = 0; j < lowLinks; j++) {
626 LinkCollections(first, i * lowLinks + j, last, i);
627 }
628 }
629 return kTRUE;
630 } break;
631 case ELinkPolicy::kAnyToAny: {
632 for (int i = 0; i < lowLinks; i++) {
633 for (int j = 0; j < highLinks; j++) {
634 LinkCollections(first, i, last, j);
635 }
636 }
637 return kTRUE;
638 } break;
639 }
640 return kFALSE;
641 }
642} // namespace Hal
static void PrintInfo(TString text, Hal::EInfo status)
Definition Cout.cxx:370
Bool_t IsDummy() const
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)
void InitReport() const
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
Definition CutMonitor.h:211
Int_t GetCollectionID() const
Definition CutMonitor.h:188
ECutUpdate GetUpdateRatio() const
virtual CutMonitor * MakeCopy() const
void SetCollectionID(Int_t i)
Definition Cut.h:40
ECutUpdate GetUpdateRatio() const
Definition Cut.h:209
void SetCollectionID(Int_t i)
Definition Cut.h:247
virtual Cut * MakeCopy() const
Definition Cut.h:317
Int_t GetCollectionID() const
Definition Cut.h:257
void SetComment(TString name)
Definition Package.cxx:65
void AddObject(TObject *object)
Definition Package.cxx:209