Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
CutCollection.cxx
1/*
2 * CutCollection.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 "CutCollection.h"
11
12#include "Cout.h"
13#include "CutMonitor.h"
14#include "CutMonitorX.h"
15#include "CutMonitorXY.h"
16#include "CutMonitorXYZ.h"
17#include "Event.h"
18#include "EventCut.h"
19#include "Package.h"
20#include "Parameter.h"
21#include "StdString.h"
22#include "Track.h"
23#include "TrackCut.h"
24#include "TwoTrack.h"
25#include "TwoTrackCut.h"
26
27#include <TClass.h>
28#include <TCollection.h>
29#include <TList.h>
30
31
32// template CutCollection<UEvent,UParticle>//
33namespace Hal {
34 CutCollection::CutCollection(TObjArray** container, Int_t cont_size, ECutUpdate mode, Int_t collectionNo) :
35 fCutMonitors(NULL),
36 fCuts(NULL),
37 fFastCuts(NULL),
38 fPassedSlow(0),
39 fFailedSlow(0),
40 fPassedFast(0),
41 fFailedFast(0),
42 fFastCutsNo(0),
43 fSlowCutsNo(0),
44 fCutMonitorsNo(0),
45 fInit(kFALSE),
46 fDummy(kFALSE),
47 fCollectionID(0),
48 fContainerSize(cont_size),
49 fStep(1),
50 fCutContainerArr(NULL) // this is needed to link cut monitors in case of cloning
51 {
52 fCutContainerArr = container;
53 fCutMonitors = new TObjArray();
54 fCuts = new TObjArray();
55 fFastCuts = new TObjArray();
56 fInit = kFALSE;
57 fMode = mode;
58 fCollectionID = collectionNo;
59 }
60
61 void CutCollection::AddCut(Cut* cut, Option_t* opt) {
62 if (fDummy) return;
63 if (cut == NULL) {
64 Cout::PrintInfo("Empty cut", EInfo::kLowWarning);
65 return;
66 }
67 TString option = opt;
68 Bool_t keepDouble = Hal::Std::FindParam(option, "double");
69 if (!Hal::Std::FindParam(option, "fast")) { // add normal cut
70 for (int i = 0; i < fCuts->GetEntriesFast(); i++) {
71 if (cut->CutName() == ((Cut*) fCuts->UncheckedAt(i))->CutName()) {
73 Form("Cut used %s in collection no %i, cut will be removed", cut->CutName().Data(), cut->GetCollectionID()),
74 EInfo::kLowWarning);
75 return;
76 }
77 }
78 for (int i = 0; i < fFastCuts->GetEntriesFast(); i++) {
79 if (cut->CutName() == ((Cut*) fFastCuts->UncheckedAt(i))->CutName()) {
80 if (!keepDouble) {
81 Cout::PrintInfo(Form("Cut used %s in collection no %i in fast cuts group, cut will "
82 "be "
83 "removed",
84 cut->ClassName(),
85 cut->GetCollectionID()),
86 EInfo::kLowWarning);
87 return;
88 }
89 }
90 }
91 fCuts->AddLast(cut);
92 } else {
93 for (int i = 0; i < fFastCuts->GetEntriesFast(); i++) {
94 if (cut->CutName() == ((Cut*) fFastCuts->UncheckedAt(i))->CutName()) {
95 Cout::PrintInfo(Form("Cut used %s in collection no %i in as fast, cut will be "
96 "removed",
97 cut->CutName().Data(),
98 cut->GetCollectionID()),
99 EInfo::kLowWarning);
100 return;
101 }
102 }
103 if (!keepDouble) {
104 for (int i = 0; i < fCuts->GetEntriesFast(); i++) {
105 if (cut->CutName() == ((Cut*) fCuts->UncheckedAt(i))->CutName()) {
107 Form("Cut used %s in collection no %i but cut will be removed", cut->CutName().Data(), cut->GetCollectionID()),
108 EInfo::kLowWarning);
109 return;
110 }
111 }
112 }
113 fFastCuts->AddLast(cut);
114 }
115 }
116
117 Bool_t CutCollection::CheckIfComptatiblie(Cut* cut1, Cut* cut2) {
118 if (cut1 == NULL || cut2 == NULL) return kFALSE;
119 if (cut1->GetUpdateRatio() != cut2->GetUpdateRatio()) return kFALSE;
120 if (cut1->GetCollectionID() != cut2->GetCollectionID()) return kFALSE;
121 return kTRUE;
122 }
123
125 if (fDummy) return;
126 if (monitor == NULL) {
127 Cout::PrintInfo("Empty monitor", EInfo::kError);
128 return;
129 }
130
131 for (int i = 0; i < fCutMonitors->GetEntriesFast(); i++) {
132 if (monitor == (CutMonitor*) fCutMonitors->UncheckedAt(i)) {
133 Cout::PrintInfo("Monitor cut used", EInfo::kLowWarning);
134 return;
135 }
136 }
137 fCutMonitors->AddLast(monitor);
138 }
139
140 void CutCollection::Update(Bool_t val, TObject* obj) {
141 if (val) {
142 ++fPassedSlow;
143 } else {
144 ++fFailedSlow;
145 }
146 for (int i = 0; i < fCutMonitorsNo; i++)
147 ((CutMonitor*) fCutMonitors->UncheckedAt(i))->Update(val, obj);
148 }
149
150 void CutCollection::Init(Int_t task_id) {
151 if (fDummy) {
152 fInit = kTRUE;
153 fNext.SafeInit();
154 fPrev.SafeInit();
155 return;
156 }
157 if (fInit) {
158 Cout::PrintInfo("CutCollection has been initialized", EInfo::kError);
159 } else {
160 for (int i = 0; i < fCuts->GetEntriesFast(); i++) {
161 Bool_t ok = ((Cut*) fCuts->UncheckedAt(i))->Init(task_id);
162 if (!ok) {
163#ifdef HAL_DEBUG
165 Form("Failed to init %s in cut collection %i", ((Cut*) fCuts->UncheckedAt(i))->CutName().Data(), GetCollectionID()),
166 EInfo::kDebugInfo);
167#endif
168 fCuts->RemoveAt(i);
169 fCuts->Compress();
170 i--;
171 } else {
172#ifdef HAL_DEBUG
173 Cout::PrintInfo(Form("Succesfully inited %s in cut collection %i",
174 ((Cut*) fCuts->UncheckedAt(i))->CutName().Data(),
176 EInfo::kDebugInfo);
177#endif
178 }
179 }
180 for (int i = 0; i < fFastCuts->GetEntriesFast(); i++) {
181 Bool_t ok = ((Cut*) fFastCuts->UncheckedAt(i))->Init(task_id);
182 if (!ok) {
183#ifdef HAL_DEBUG
184 Cout::PrintInfo(Form("Failed to init %s in cut collection %i",
185 ((Cut*) fFastCuts->UncheckedAt(i))->CutName().Data(),
187 EInfo::kDebugInfo);
188#endif
189 fFastCuts->RemoveAt(i);
190 fFastCuts->Compress();
191 i--;
192 } else {
193#ifdef HAL_DEBUG
194 Cout::PrintInfo(Form("Succesfully inited %s in cut collection %i",
195 ((Cut*) fFastCuts->UncheckedAt(i))->CutName().Data(),
197 EInfo::kDebugInfo);
198#endif
199 }
200 }
201#ifdef HAL_DEBUG
202 Cout::PrintInfo("Initializing cut monitors", EInfo::kDebugInfo);
203#endif
204 AdvancedMonitorInitialization(task_id);
205 fInit = kTRUE;
206 if (fNext.GetSize() == 0) {
207 fNext.SafeInit();
208 } else {
209 fNext.MakeUsed();
210 }
211 if (fPrev.GetSize() == 0) {
212 fPrev.SafeInit();
213 } else {
214 fPrev.MakeUsed();
215 }
216 }
217 fFastCutsNo = fFastCuts->GetEntriesFast();
218 fSlowCutsNo = fCuts->GetEntriesFast();
219 fCutMonitorsNo = fCutMonitors->GetEntriesFast();
220 }
221
222 Int_t CutCollection::MatchCut(Cut* adreess, CutCollection* input) {
223 for (int i = 0; i < input->GetCutNo(); i++) {
224 if (adreess == input->GetCut(i)) return i;
225 }
226 return -1;
227 }
228
229 CutMonitor* CutCollection::GetCutMonitor(Int_t index) const { return (CutMonitor*) fCutMonitors->At(index); }
230
231 void CutCollection::AddPreviousAddr(Int_t value, Bool_t backround) {
232 if (fDummy) return;
233 if (backround) {
234 fPrevBckg.AddAddr(value);
235 } else {
236 fPrev.AddAddr(value);
237 }
238 }
239
240 void CutCollection::AddNextAddr(Int_t value, Bool_t backround) {
241 if (fDummy) return;
242 if (backround) {
243 fNextBckg.AddAddr(value);
244 } else {
245 fNext.AddAddr(value);
246 }
247 }
248
249 Cut* CutCollection::FindCut(TString name) const {
250#ifdef HAL_DEBUG
251 Cout::PrintInfo(Form("Looking for %s in subcontainer %i", name.Data(), GetCollectionID()), EInfo::kDebugInfo);
252#endif
253 for (int i = 0; i < fCuts->GetEntriesFast(); i++) {
254 TString name2 = ((Cut*) fCuts->UncheckedAt(i))->CutName();
255 if (name2 == name) {
256 return (Cut*) fCuts->UncheckedAt(i);
257 } else {
258 // Hal::Cout::PrintInfo(Form("try %s %s ", name.Data(), name2.Data()), EInfo::kDebugInfo);
259 }
260 } // cut not found in standard cuts, looking in complex cuts
261 return NULL;
262 }
263
264 CutCollection* CutCollection::Replicate(Int_t new_collection) const {
265 if (fInit == kTRUE) {
266 Cout::PrintInfo("Cant replicate initialized CutCollection - this lead "
267 "to mess with cut monitors !",
268 EInfo::kLowWarning);
269 }
270 CutCollection* clone = new CutCollection(fCutContainerArr, fContainerSize, fMode, new_collection);
271 clone->fStep = this->fStep;
272 for (int i = 0; i < this->fCuts->GetEntriesFast(); i++) {
273 Cut* cut = ((Cut*) fCuts->UncheckedAt(i))->MakeCopy();
274 cut->SetCollectionID(new_collection);
275 clone->AddCut(cut);
276 }
277 for (int i = 0; i < fFastCuts->GetEntriesFast(); i++) {
278 Cut* cut = ((Cut*) fFastCuts->UncheckedAt(i))->MakeCopy();
279 cut->SetCollectionID(new_collection);
280 clone->fFastCuts->AddLast(cut);
281 }
282 for (int i = 0; i < this->fCutMonitors->GetEntriesFast(); i++) {
283 TString orig = fCutMonitors->UncheckedAt(i)->ClassName();
284 if (orig == "Hal::CutMonitorX") {
285 CutMonitorX* cutmon = new CutMonitorX(*(CutMonitorX*) fCutMonitors->UncheckedAt(i));
286 clone->AddCutMonitor(cutmon);
287 } else if (orig == "Hal::CutMonitorXY") {
288 CutMonitorXY* cutmon = new CutMonitorXY(*(CutMonitorXY*) fCutMonitors->UncheckedAt(i));
289 clone->AddCutMonitor(cutmon);
290 } else if (orig == "Hal::CutMonitorXYZ") {
291 CutMonitorXYZ* cutmon = new CutMonitorXYZ(*(CutMonitorXYZ*) fCutMonitors->UncheckedAt(i));
292 clone->AddCutMonitor(cutmon);
293 } else {
294 clone->AddCutMonitor((CutMonitor*) fCutMonitors->UncheckedAt(i)->Clone());
295 }
296 }
297 clone->fCutMonitorsNo = fCutMonitorsNo;
298 clone->fFastCutsNo = fFastCutsNo;
299 clone->fSlowCutsNo = fSlowCutsNo;
300 return clone;
301 }
302
303 void CutCollection::AdvancedMonitorInitialization(Int_t task_id) {
304 // linking cuts by names with pointers with cuts
305 Int_t oryginal_monitors_no = fCutMonitors->GetEntries();
306 Int_t prev_size = 0;
307 if (fPrev.IsUsed()) prev_size = fPrev.GetSize();
308 for (int i = 0; i < oryginal_monitors_no; i++) {
309 CutMonitor* cutmon = (CutMonitor*) fCutMonitors->UncheckedAt(i);
310 if (cutmon->ObjMonitor()) {
311 Bool_t init = cutmon->Init(task_id);
312 if (init == kFALSE) {
313 Cout::PrintInfo(Form("Problem with initalization [%s]", cutmon->ClassName()), EInfo::kLowWarning);
314 fCutMonitors->RemoveAt(i);
315 }
316 continue;
317 }
318 TString monName = cutmon->ClassName();
319 if (monName == "Hal::CutMonitorX") {
320 TString cut = cutmon->GetCutName(0);
321 Cut* newCut = this->FindCut(cut);
322 if (newCut) {
323 if (newCut->GetCutSize() <= cutmon->GetCutParameter(0)) {
324 Cout::PrintInfo(Form("Problem with initalization CutMonitorXY [%s]", newCut->ClassName()), EInfo::kLowWarning);
326 Form("Cut %s has only %i not %i parameters", newCut->ClassName(), newCut->GetCutSize(), cutmon->GetCutParameter(0)),
327 EInfo::kLowWarning);
328 fCutMonitors->RemoveAt(i);
329 } else {
330 cutmon->AddForcedCut(newCut, 0);
331 }
332 } else {
333 Cout::PrintInfo(Form("Hal::CutMonitorX [%s] not found!", cut.Data()), EInfo::kError);
334 fCutMonitors->RemoveAt(i);
335 }
336 } else if (monName == "Hal::CutMonitorXY") {
337 TString cut1_name = cutmon->GetCutName(0);
338 TString cut2_name = cutmon->GetCutName(1);
339 TObjArray* Ncut1 = LocateCuts(cut1_name);
340 TObjArray* Ncut2 = LocateCuts(cut2_name);
341
342 if (Ncut1->GetEntries() == 0 || Ncut2->GetEntries() == 0) {
343 Cout::PrintInfo(Form("Problem with initalization CutMonitorXY [%s] vs [%s]", cut1_name.Data(), cut2_name.Data()),
344 EInfo::kLowWarning);
345 if (Ncut1->GetEntries() == 0) { Cout::PrintInfo(Form("Cut %s not found", cut1_name.Data()), EInfo::kLowWarning); }
346 if (Ncut2->GetEntries() == 0) { Cout::PrintInfo(Form("Cut %s not found", cut2_name.Data()), EInfo::kLowWarning); }
347 fCutMonitors->RemoveAt(i);
348 } else if (Ncut1->GetEntriesFast() > 1 || Ncut2->GetEntriesFast() > 1 || prev_size > 1) {
350 Form("There is too many links or cuts cut monitor %s %s will be removed", cut1_name.Data(), cut2_name.Data()),
351 EInfo::kError);
352 fCutMonitors->RemoveAt(i);
353 } else {
354 Cut* cut1 = (Cut*) Ncut1->UncheckedAt(0);
355 Cut* cut2 = (Cut*) Ncut2->UncheckedAt(0);
356 if (cut1->GetCutSize() <= cutmon->GetCutParameter(0)) {
357 Cout::PrintInfo(Form("Problem with initalization CutMonitorXY [%s] vs [%s]", cut1_name.Data(), cut2_name.Data()),
358 EInfo::kLowWarning);
360 Form("Cut %s has only %i not %i parameters", cut1->ClassName(), cut1->GetCutSize(), cutmon->GetCutParameter(0)),
361 EInfo::kLowWarning);
362 fCutMonitors->RemoveAt(i);
363 } else if (cut2->GetCutSize() <= cutmon->GetCutParameter(1)) {
364 Cout::PrintInfo(Form("Problem with initalization CutMonitorXY [%s] vs [%s]", cut1_name.Data(), cut2_name.Data()),
365 EInfo::kLowWarning);
367 Form("Cut %s has only %i not %i parameters", cut1->ClassName(), cut1->GetCutSize(), cutmon->GetCutParameter(1)),
368 EInfo::kLowWarning);
369 fCutMonitors->RemoveAt(i);
370 } else {
371 cutmon->AddForcedCut(cut1, 0);
372 cutmon->AddForcedCut(cut2, 1);
373 }
374 }
375 Ncut1->SetOwner(kFALSE);
376 Ncut2->SetOwner(kFALSE);
377 delete Ncut1;
378 delete Ncut2;
379 } else if (monName == "Hal::CutMonitorXYZ") {
380 TString cut1_name = cutmon->GetCutName(0);
381 TString cut2_name = cutmon->GetCutName(1);
382 TString cut3_name = cutmon->GetCutName(2);
383 TObjArray* Ncut1 = LocateCuts(cut1_name);
384 TObjArray* Ncut2 = LocateCuts(cut2_name);
385 TObjArray* Ncut3 = LocateCuts(cut3_name);
386 if (Ncut1->GetEntries() == 0 || Ncut2->GetEntries() == 0 || Ncut3->GetEntries() == 0) {
388 Form(" Problem with Hal::CutMonitorXYZ [%s] vs [%s] vs [%s]", cut1_name.Data(), cut2_name.Data(), cut3_name.Data()),
389 EInfo::kLowWarning);
390 if (Ncut1->GetEntries() == 0) Cout::PrintInfo(Form("Cut %s not found", cut1_name.Data()), EInfo::kLowWarning);
391 if (Ncut2->GetEntries() == 0) Cout::PrintInfo(Form("Cut %s not found", cut2_name.Data()), EInfo::kLowWarning);
392 if (Ncut3->GetEntries() == 0) Cout::PrintInfo(Form("Cut %s not found", cut3_name.Data()), EInfo::kLowWarning);
393 fCutMonitors->RemoveAt(i);
394 } else if (Ncut1->GetEntries() > 1 || Ncut2->GetEntries() > 1 || Ncut3->GetEntriesFast() > 1 || prev_size > 1) {
395 Cout::PrintInfo("There is too many links or cuts monitor %s %s will be removed", EInfo::kError);
396 fCutMonitors->RemoveAt(i);
397 } else {
398 Cut* cut1 = (Cut*) Ncut1->UncheckedAt(0);
399 Cut* cut2 = (Cut*) Ncut2->UncheckedAt(0);
400 Cut* cut3 = (Cut*) Ncut3->UncheckedAt(0);
401 Int_t own_cuts = 0;
402 ECutUpdate upd = fMode;
403 if (fMode == ECutUpdate::kTwoTrackBackground) { upd = ECutUpdate::kTwoTrack; }
404 if (cut1->GetUpdateRatio() == upd) own_cuts = 1;
405 if (cut2->GetUpdateRatio() == upd) own_cuts += 2;
406 if (cut3->GetUpdateRatio() == upd) own_cuts += 4;
407 ;
408 switch (own_cuts) {
409 case 0: {
410 Cout::PrintInfo("Hal::CutMonitorXYZ has no cuts compatible with "
411 "container that own it",
412 EInfo::kLowWarning);
413 fCutMonitors->RemoveAt(i);
414 } break;
415 case 1: { // 1 local
416 cutmon->AddForcedCut(cut1, 0);
417 if (CheckIfComptatiblie(cut2, cut3)) {
418 cutmon->AddForcedCut(cut2, 1);
419 cutmon->AddForcedCut(cut3, 2);
420 } else {
421 Cout::PrintInfo("Couldn't find compatible cuts for monitoring", EInfo::kLowWarning);
422 fCutMonitors->RemoveAt(i);
423 }
424 } break;
425 case 2: // 2 local
426 cutmon->AddForcedCut(cut2, 1);
427 if (CheckIfComptatiblie(cut1, cut3)) {
428 cutmon->AddForcedCut(cut1, 0);
429 cutmon->AddForcedCut(cut3, 2);
430 } else {
431 Cout::PrintInfo("Couldn't find compatible cuts for monitoring", EInfo::kLowWarning);
432 fCutMonitors->RemoveAt(i);
433 }
434 break;
435 case 4: // 3 local
436 cutmon->AddForcedCut(cut3, 2);
437 if (CheckIfComptatiblie(cut1, cut2)) {
438 cutmon->AddForcedCut(cut1, 0);
439 cutmon->AddForcedCut(cut2, 1);
440 } else {
441 Cout::PrintInfo("Couldn't find compatible cuts for monitoring", EInfo::kLowWarning);
442 fCutMonitors->RemoveAt(i);
443 }
444 break;
445 default: {
446 if (cut1->GetCutSize() <= cutmon->GetCutParameter(0)) {
447 Cout::PrintInfo(Form("Problem with initalization Hal::CutMonitorXY [%s] vs [%s] vs "
448 "[%s]",
449 cut1_name.Data(),
450 cut2_name.Data(),
451 cut3_name.Data()),
452 EInfo::kLowWarning);
454 Form("Cut %s has only %i not %i parameters", cut1->ClassName(), cut1->GetCutSize(), cutmon->GetCutParameter(0)),
455 EInfo::kLowWarning);
456 fCutMonitors->RemoveAt(i);
457 } else if (cut2->GetCutSize() <= cutmon->GetCutParameter(1)) {
458 Cout::PrintInfo(Form("Problem with initalization Hal::CutMonitorXY [%s] vs [%s] vs "
459 "[%s]",
460 cut1_name.Data(),
461 cut2_name.Data(),
462 cut3_name.Data()),
463 EInfo::kLowWarning);
465 Form("Cut %s has only %i not %i parameters", cut2->ClassName(), cut2->GetCutSize(), cutmon->GetCutParameter(1)),
466 EInfo::kLowWarning);
467 fCutMonitors->RemoveAt(i);
468 } else if (cut3->GetCutSize() <= cutmon->GetCutParameter(2)) {
469 Cout::PrintInfo(Form("Problem with initalization Hal::CutMonitorXY [%s] vs [%s] vs "
470 "[%s]",
471 cut1_name.Data(),
472 cut2_name.Data(),
473 cut3_name.Data()),
474 EInfo::kLowWarning);
476 Form("Cut %s has only %i not %i parameters", cut3->ClassName(), cut3->GetCutSize(), cutmon->GetCutParameter(2)),
477 EInfo::kLowWarning);
478 fCutMonitors->RemoveAt(i);
479 } else {
480 cutmon->AddForcedCut(cut1, 0);
481 cutmon->AddForcedCut(cut2, 1);
482 cutmon->AddForcedCut(cut3, 2);
483 }
484 } break;
485 }
486 }
487 Ncut1->SetOwner(kFALSE);
488 Ncut2->SetOwner(kFALSE);
489 Ncut3->SetOwner(kFALSE);
490 delete Ncut1;
491 delete Ncut2;
492 delete Ncut3;
493 } else {
494 Cout::PrintInfo(Form("Problems with class name %s of cuts this is an critial error", monName.Data()),
495 EInfo::kCriticalError);
496 }
497 }
498 fCutMonitors->Compress();
499 // standard initialization
500 for (int i = 0; i < fCutMonitors->GetEntriesFast(); i++) {
501 CutMonitor* mon = ((CutMonitor*) fCutMonitors->UncheckedAt(i));
502 mon->SetCollectionID(this->fCollectionID);
503 if (!mon->ObjMonitor()) mon->Init(task_id);
504 }
505 }
506
507 TObjArray* CutCollection::LocateInLowerCollections(TString cut) {
508 TObjArray* obj = new TObjArray();
509 obj->SetOwner(kFALSE);
510 if (this->fMode == ECutUpdate::kEvent) { return obj; }
511 if (this->fMode == ECutUpdate::kTrack) {
512 for (int i = 0; i < this->GetPrevNo(); i++) {
513 CutCollection* subcont = (CutCollection*) (GetCutContainerArray(ECutUpdate::kEvent)->At(this->GetPrevAddr(i)));
514 if (subcont->FindCut(cut)) { obj->AddLast(subcont->FindCut(cut)); }
515 }
516 return obj;
517 }
518 if (this->fMode == ECutUpdate::kTwoTrack) {
519 // look over track containers
520 for (int i = 0; i < this->GetPrevNo(); i++) {
521 CutCollection* subcont = (CutCollection*) (GetCutContainerArray(ECutUpdate::kTrack)->At(this->GetPrevAddr(i)));
522 if (subcont->FindCut(cut)) { obj->AddLast(subcont->FindCut(cut)); }
523 }
524 // still not found - we need go deeper !! to event cuts
525 for (int i = 0; i < this->GetPrevNo(); i++) {
526 CutCollection* subcont = (CutCollection*) (GetCutContainerArray(ECutUpdate::kTrack)->At(this->GetPrevAddr(i)));
527 for (int j = 0; j < subcont->GetPrevNo(); j++) {
528 CutCollection* subsubcont = (CutCollection*) (GetCutContainerArray(ECutUpdate::kTwoTrack)->At(this->GetPrevAddr(j)));
529 if (subsubcont->FindCut(cut)) { obj->AddLast(subsubcont->FindCut(cut)); }
530 }
531 }
532 return obj;
533 }
534 if (this->fMode == ECutUpdate::kTwoTrackBackground) {
535 // look over track containers
536 for (int i = 0; i < this->GetPrevNo(); i++) {
537 CutCollection* subcont = (CutCollection*) (GetCutContainerArray(ECutUpdate::kTrack)->At(this->GetPrevAddr(i)));
538 if (subcont->FindCut(cut)) { obj->AddLast(subcont->FindCut(cut)); }
539 }
540 // still not found - we need go deeper !! to event cuts
541 for (int i = 0; i < this->GetPrevNo(); i++) {
542 CutCollection* subcont = (CutCollection*) (GetCutContainerArray(ECutUpdate::kTrack)->At(this->GetPrevAddr(i)));
543 for (int j = 0; j < subcont->GetPrevNo(); j++) {
544 CutCollection* subsubcont =
545 (CutCollection*) (GetCutContainerArray(ECutUpdate::kTwoTrackBackground)->At(this->GetPrevAddr(j)));
546 if (subsubcont->FindCut(cut)) { obj->AddLast(subsubcont->FindCut(cut)); }
547 }
548 }
549 return obj;
550 }
551 return obj;
552 }
553
554 Int_t CutCollection::Compare(const TObject* obj) const {
555 if (obj->ClassName() != this->ClassName()) return 0;
556 Int_t trigg = ((CutCollection*) obj)->GetCollectionID();
557 if (trigg == fCollectionID) return 0;
558 if (trigg > fCollectionID) return -1;
559 return 1;
560 }
561
562 TObjArray* CutCollection::LocateCuts(TString classname) {
563 TObjArray* arr = new TObjArray();
564 arr->SetOwner(kFALSE);
565 ECutUpdate cut_up = ECutUpdate::kNo;
566 cut_up = GetUpdateFromName(classname);
567 if (fMode == cut_up) {
568 Cut* cut = FindCut(classname);
569 arr->AddLast(cut);
570 return arr;
571 }
572 if (fMode == ECutUpdate::kTwoTrackBackground && cut_up == ECutUpdate::kTwoTrack) {
573 Cut* cut = FindCut(classname);
574 arr->AddLast(cut);
575 return arr;
576 } else if (fPrev.IsUsed()) {
577#ifdef HAL_DEBUG
578 Cout::PrintInfo("Looking for cuts in lower collections", EInfo::kDebugInfo);
579#endif
580 arr = LocateInLowerCollections(classname);
581 return arr;
582 } else {
583#ifdef HAL_DEBUG
584 Cout::PrintInfo("Cut not found cut and no lower collections present", EInfo::kDebugInfo);
585#endif
586 return arr;
587 }
588 }
589
591 Cout::InStars(Form("Subcontainer trig %i", fCollectionID));
592 TString mode;
593 switch (fMode) {
594 case (ECutUpdate::kEvent): {
595 mode = "Event Upd";
596 } break;
597 case (ECutUpdate::kTrack): {
598 mode = "Track upd";
599 } break;
600 case (ECutUpdate::kTwoTrack): {
601 mode = "TTrack mod";
602 } break;
603 case (ECutUpdate::kTwoTrackBackground): {
604 mode = "TTRack mixed";
605 } break;
606 default: Cout::PrintInfo("Unknown update mode inf CutCollection", EInfo::kLowWarning); break;
607 }
608 Cout::Text(Form("Mode %s", mode.Data()), "L", kYellow);
609 for (int i = 0; i < fCuts->GetEntriesFast(); i++) {
610 Cout::Text(fCuts->UncheckedAt(i)->ClassName(), "L");
611 }
612
613 Cout::Text("Fast cuts", "L", kYellow);
614 for (int i = 0; i < fFastCuts->GetEntriesFast(); i++) {
615 Cout::Text(fFastCuts->UncheckedAt(i)->ClassName(), "L");
616 }
617
618 for (int i = 0; i < fCutMonitors->GetEntriesFast(); i++) {
619 Cout::Text(fCutMonitors->UncheckedAt(i)->ClassName(), "L");
620 CutMonitor* cutmon = (CutMonitor*) fCutMonitors->UncheckedAt(i);
621 Cout::Database({cutmon->GetCutName(0)});
622 }
623 }
624
626 Bool_t result = kTRUE;
627 for (int i = 0; i < fFastCutsNo; i++) {
628 if (kFALSE == ((EventCut*) fFastCuts->UncheckedAt(i))->Pass(obj)) {
629 ++fFailedFast;
630 return kFALSE;
631 }
632 }
633 ++fPassedFast;
634 for (int i = 0; i < fSlowCutsNo; i++) {
635 if (kFALSE == ((EventCut*) fCuts->UncheckedAt(i))->Pass(obj)) { result = kFALSE; }
636 }
637 Update(result, obj);
638 return result;
639 }
640
642 Bool_t result = kTRUE;
643 for (int i = 0; i < fFastCutsNo; i++) {
644 if (kFALSE == ((TrackCut*) fFastCuts->UncheckedAt(i))->Pass(obj)) {
645 ++fFailedFast;
646 return kFALSE;
647 }
648 }
649 ++fPassedFast;
650 for (int i = 0; i < fSlowCutsNo; i++) {
651 if (kFALSE == ((TrackCut*) fCuts->UncheckedAt(i))->Pass(obj)) { result = kFALSE; }
652 }
653 Update(result, obj);
654 return result;
655 }
656
658 Bool_t result = kTRUE;
659 for (int i = 0; i < fFastCutsNo; i++) {
660 if (kFALSE == ((TwoTrackCut*) fFastCuts->UncheckedAt(i))->Pass(pair)) {
661 ++fFailedFast;
662 return kFALSE;
663 }
664 }
665 ++fPassedFast;
666 for (int i = 0; i < fSlowCutsNo; i++) {
667 if (kFALSE == ((TwoTrackCut*) fCuts->UncheckedAt(i))->Pass(pair)) { result = kFALSE; }
668 }
669 Update(result, pair);
670 return result;
671 }
672
674 Package* pack = new Package(this, kTRUE);
675 switch (fMode) {
676 case (ECutUpdate::kEvent): {
677 pack->AddObject(new ParameterString("UpdateMode", "Event"));
678 } break;
679 case (ECutUpdate::kTrack): {
680 pack->AddObject(new ParameterString("UpdateMode", "Track"));
681 } break;
682 case (ECutUpdate::kTwoTrack): {
683 pack->AddObject(new ParameterString("UpdateMode", "TwoTrack"));
684 } break;
685 default: pack->AddObject(new ParameterString("UpdateMode", "Unknown")); break;
686 }
687 pack->AddObject(new ParameterInt("CollectionID", fCollectionID));
688 pack->AddObject(new ParameterInt("CutMonitorNo", fCutMonitors->GetEntriesFast()));
689 pack->AddObject(new ParameterInt("CutNo", fCuts->GetEntriesFast()));
690 pack->AddObject(new ParameterULong64("PassedFast", fPassedFast, '+'));
691 pack->AddObject(new ParameterULong64("FailedFast", fFailedFast, '+'));
692 pack->AddObject(new ParameterULong64("PassedSlow", fPassedSlow, '+'));
693 pack->AddObject(new ParameterULong64("FailedSlow", fFailedSlow, '+'));
694 if (fDummy) {
695 pack->AddObject(new ParameterString("State", "Dummy"));
696 } else {
697 pack->AddObject(new ParameterString("State", "Normal"));
698 }
699
700 auto MakeList = [](TString name, const CutCollectionLinks& col) {
701 TList* list = new TList();
702 list->SetOwner(kTRUE);
703 list->SetName(name);
704 for (int i = 0; i < col.GetSize(); i++) {
705 list->AddAt(new ParameterInt(Form("%i", i), col.GetAddr(i)), i);
706 }
707 return list;
708 };
709 int used = 0;
710 if (fNext.IsUsed()) used++;
711 if (fNextBckg.IsUsed()) used++;
712 pack->AddObject(new ParameterInt("NextLayers", used));
713 if (fNext.IsUsed()) pack->AddObject(MakeList("NextObj_0", fNext));
714 if (fNextBckg.IsUsed()) pack->AddObject(MakeList("NextObj_1", fNextBckg));
715
716 used = 0;
717 if (fPrev.IsUsed()) used++;
718 if (fPrevBckg.IsUsed()) used++;
719
720 pack->AddObject(new ParameterInt("PreviousLayers", used));
721 if (fPrev.IsUsed()) pack->AddObject(MakeList("PrevObj_0", fPrev));
722 if (fPrevBckg.IsUsed()) pack->AddObject(MakeList("PrevObj_1", fPrevBckg));
723
724 TList* CutMonitorList = new TList();
725 CutMonitorList->SetOwner(kTRUE);
726 CutMonitorList->SetName("CutMonitorList");
727 for (int i = 0; i < fCutMonitors->GetEntriesFast(); i++)
728 CutMonitorList->Add(((CutMonitor*) fCutMonitors->At(i))->Report());
729 TList* CutList = new TList();
730 CutList->SetOwner(kTRUE);
731 CutList->SetName("CutList");
732 for (int i = 0; i < fCuts->GetEntriesFast(); i++)
733 CutList->Add(((Cut*) fCuts->At(i))->Report());
734 pack->AddObject(CutMonitorList);
735 pack->AddObject(CutList);
736 TList* CutList2 = new TList();
737 CutList2->SetOwner(kTRUE);
738 CutList2->SetName("FastCutList");
739 for (int i = 0; i < fFastCuts->GetEntriesFast(); i++)
740 CutList2->Add(((Cut*) fFastCuts->At(i))->Report());
741 pack->AddObject(CutList2);
742 pack->AddObject(new ParameterInt("Step", fStep, '='));
743 return pack;
744 }
745
747 fCutMonitors(NULL),
748 fCuts(NULL),
749 fFastCuts(NULL),
750 fPassedSlow(0),
751 fFailedSlow(0),
752 fPassedFast(0),
753 fFailedFast(0),
754 fFastCutsNo(0),
755 fSlowCutsNo(0),
756 fCutMonitorsNo(0),
757 fMode(ECutUpdate::kNo),
758 fInit(kFALSE),
759 fDummy(kFALSE),
760 fCollectionID(0),
761 fContainerSize(0),
762 fStep(1),
763 fCutContainerArr(0) {
764 Cout::PrintInfo("default constructor of CutCollection should never be used !!", EInfo::kLowWarning);
765 }
766
767 CutCollection* CutCollection::MakeNewCopy(TObjArray** container) const {
768 CutCollection* subcont = new CutCollection(container, this->fContainerSize, this->fMode, this->fCollectionID);
769 for (int i = 0; i < fCutMonitors->GetEntriesFast(); i++) {
770 subcont->fCutMonitors->Add(((CutMonitor*) fCutMonitors->UncheckedAt(i))->MakeCopy());
771 }
772 for (int i = 0; i < fCuts->GetEntriesFast(); i++) {
773 subcont->fCuts->Add(((Cut*) fCuts->UncheckedAt(i))->MakeCopy());
774 }
775 for (int i = 0; i < fFastCuts->GetEntriesFast(); i++) {
776 subcont->fFastCuts->Add(((Cut*) fFastCuts->UncheckedAt(i))->MakeCopy());
777 }
778 return subcont;
779 }
780
781 void CutCollection::MakeDummyCopy(const CutCollection* copy, Bool_t copy_high_links) {
782 if (fDummy == kFALSE) {
783 delete fCutMonitors;
784 delete fCuts;
785 delete fFastCuts;
786 }
787 fCutMonitors = copy->fCutMonitors;
788 fCuts = copy->fCuts;
789 fFastCuts = copy->fFastCuts;
790 fPassedSlow = copy->fPassedSlow;
791 fFailedSlow = copy->fFailedSlow;
792 fPassedFast = copy->fPassedFast;
793 fFailedFast = copy->fPassedFast;
794 fMode = copy->fMode;
795 fInit = copy->fInit;
796 fDummy = copy->fDummy;
797 fCollectionID = copy->fCollectionID;
798 fContainerSize = copy->fContainerSize;
799 fFailedFast = copy->fFailedFast;
800 fFailedSlow = copy->fFailedSlow;
801 fPassedFast = copy->fPassedFast;
802 fPassedSlow = copy->fPassedSlow;
803 fCutMonitorsNo = copy->fCutMonitorsNo;
804 fFastCutsNo = copy->fFastCutsNo;
805 fSlowCutsNo = copy->fSlowCutsNo;
806 if (copy->fPrev.IsUsed()) fPrev = copy->fPrev;
807 if (copy->fPrevBckg.IsUsed()) fPrevBckg = copy->fPrevBckg;
808 if (copy_high_links) {
809 if (copy->fNext.IsUsed()) fNext = copy->fNext;
810 if (copy->fNextBckg.IsUsed()) fNextBckg = copy->fNextBckg;
811 }
812 fDummy = kTRUE;
813 }
814
815 CutCollection::~CutCollection() {
816 if (fDummy == kFALSE) {
817 if (fCuts) fCuts->Delete();
818 if (fCutMonitors) fCutMonitors->Delete();
819 delete fCuts;
820 delete fFastCuts;
821 delete fCutMonitors;
822 }
823 }
824
825 ULong64_t CutCollection::GetPassed(Option_t* opt) const {
826 TString option = opt;
827 if (option == "fast") {
828 return fPassedFast;
829 } else {
830 return fPassedSlow;
831 }
832 }
833
834 ULong64_t CutCollection::GetFailed(Option_t* opt) const {
835 TString option = opt;
836 if (option == "fast") {
837 return fFailedFast;
838 } else {
839 return fFailedSlow;
840 }
841 }
842
843 void CutCollection::MarkAsDummy() { fDummy = kTRUE; }
844
845 ECutUpdate CutCollection::GetUpdateFromName(TString cutname) const {
846 if (cutname.BeginsWith("Hal::EventComplexCut")) return ECutUpdate::kEvent;
847 if (cutname.BeginsWith("Hal::TrackComplexCut")) return ECutUpdate::kTrack;
848 if (cutname.BeginsWith("Hal::TwoTrackComplexCut")) return ECutUpdate::kTwoTrack;
849 if (cutname.BeginsWith("Hal::EventRealCut")) return ECutUpdate::kEvent;
850 if (cutname.BeginsWith("Hal::TrackRealCut")) return ECutUpdate::kTrack;
851 if (cutname.BeginsWith("Hal::TwoTrackRealCut")) return ECutUpdate::kTwoTrack;
852 if (cutname.BeginsWith("Hal::EventImaginaryCut")) return ECutUpdate::kEvent;
853 if (cutname.BeginsWith("Hal::TrackImaginaryCut")) return ECutUpdate::kTrack;
854 if (cutname.BeginsWith("Hal::TwoTrackImaginaryCut")) return ECutUpdate::kTwoTrack;
855 TClass* cl = TClass::GetClass(cutname, kFALSE, kTRUE);
856 if (cl->InheritsFrom("Hal::EventCut")) {
857 return ECutUpdate::kEvent;
858 } else if (cl->InheritsFrom("Hal::TrackCut")) {
859 return ECutUpdate::kTrack;
860 } else {
861 return ECutUpdate::kTwoTrack;
862 }
863 }
864
865 void CutCollectionLinks::SafeInit() {
866 if (fLinks.size() == 0) fLinks.push_back(0);
867 }
868
869 void CutCollectionLinks::AddAddr(Int_t addr) {
870 if (addr < 0) return;
871 fLinks.push_back(addr);
872 fUsed = kTRUE;
873 }
874
875} // namespace Hal
static void Text(TString text, TString option="L", Color_t color=-1)
Definition Cout.cxx:92
static void PrintInfo(TString text, Hal::EInfo status)
Definition Cout.cxx:370
static void Database(Int_t no...)
Int_t GetPrevAddr(Int_t index) const
void MakeDummyCopy(const CutCollection *copy, Bool_t copy_high_links=kTRUE)
CutCollection * MakeNewCopy(TObjArray **container) const
Int_t GetCollectionID() const
Bool_t PassEvent(Event *obj)
void AddPreviousAddr(Int_t value, Bool_t background=kFALSE)
void AddCutMonitor(CutMonitor *monitor)
Bool_t PassTwoTrack(TwoTrack *pair)
Cut * GetCut(Int_t index) const
void AddCut(Cut *cut, Option_t *opt=" ")
Bool_t PassTrack(Track *obj)
virtual Package * Report() const
CutCollection * Replicate(Int_t new_collection) const
Cut * FindCut(TString name) const
Int_t Compare(const TObject *obj) const
void AddNextAddr(Int_t value, Bool_t background=kFALSE)
CutMonitor * GetCutMonitor(Int_t index) const
ULong64_t GetFailed(Option_t *opt="") const
Int_t GetPrevNo() const
void Init(Int_t task_id)
Int_t GetCutNo() const
ULong64_t GetPassed(Option_t *opt="") const
Int_t GetCutParameter(Int_t i) const
void AddForcedCut(Cut *cut, Int_t no)
TString GetCutName(Int_t i) const
Definition CutMonitor.h:211
virtual Bool_t Init(Int_t task_id)
virtual Bool_t ObjMonitor() const
Definition CutMonitor.h:221
Definition Cut.h:40
virtual TString CutName(Option_t *opt="") const
Definition Cut.cxx:214
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 AddObject(TObject *object)
Definition Package.cxx:209