Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
QATrackTask.cxx
1/*
2 * QATrackTask.cxx
3 *
4 * Created on: 14 paź 2020
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9#include "QATrackTask.h"
10#include "QAPlot.h"
11
12#include "Cout.h"
13#include "CutCollection.h"
14#include "CutContainer.h"
15#include "Event.h"
16#include "Package.h"
17#include "Parameter.h"
18#include "Track.h"
19
20#include <iostream>
21
22namespace Hal {
23 QATrackTask::QATrackTask() :
24 TrackAna(), fEventQA(nullptr), fTempEventPlot(nullptr), fTrackQA(nullptr), fTempTrackPlot(nullptr) {
25 AddTags("qa");
26 }
27
28 QATrackTask::~QATrackTask() {
29 if (fEventQA) delete fEventQA;
30 if (fTempEventPlot) delete fTempEventPlot;
31 if (fTrackQA) delete fTrackQA;
32 if (fTempTrackPlot) delete fTempTrackPlot;
33 }
34
35 QATrackTask::QATrackTask(const QATrackTask& other) :
36 TrackAna(other), fEventQA(nullptr), fTempEventPlot(nullptr), fTrackQA(nullptr), fTempTrackPlot(nullptr) {
37 if (other.fEventQA) {
38 fEventQA = new TObjArray();
39 for (int i = 0; i < other.fEventQA->GetEntriesFast(); i++) {
40 QAPlot* plot = (QAPlot*) other.fEventQA->UncheckedAt(i);
41 fEventQA->Add(plot->MakeCopy());
42 }
43 }
44 if (other.fTempEventPlot) { fTempEventPlot = other.fTempEventPlot->MakeCopy(); }
45
46 if (other.fTrackQA) {
47 fTrackQA = new TObjArray();
48 for (int i = 0; i < other.fTrackQA->GetEntriesFast(); i++) {
49 QAPlot* plot = (QAPlot*) other.fTrackQA->UncheckedAt(i);
50 fTrackQA->Add(plot->MakeCopy());
51 }
52 }
53 fEventColNames = other.fEventColNames;
54 fTrackColNames = other.fTrackColNames;
55 if (other.fTempTrackPlot) { fTempTrackPlot = other.fTempTrackPlot->MakeCopy(); }
56 }
57
58 void QATrackTask::SetQAPlot(const QAPlot& plot) {
59 switch (plot.GetUpdateRatio()) {
60 case ECutUpdate::kEvent: {
61 fTempEventPlot = plot.MakeCopy();
62 } break;
63 case ECutUpdate::kTrack: {
64 fTempTrackPlot = plot.MakeCopy();
65 } break;
66 default: {
67 Cout::PrintInfo("Unkown QAPlot::GetUpdateRatio()", EInfo::kLowWarning);
68 } break;
69 }
70 }
71
72 void QATrackTask::ProcessEvent() {
73 TrackAna::ProcessEvent();
74 GetEventQAPlot(fCurrentEventCollectionID)->Fill(fCurrentEvent);
75 }
76
77 void QATrackTask::ProcessTrack() {
78 Int_t id = fCurrentEventCollectionID * fTrackCollectionsNo + fCurrentTrackCollectionID;
79 GetTrackQAPlot(id)->Fill(fCurrentTrack);
80 }
81
82 Task::EInitFlag QATrackTask::Init() {
83 Task::EInitFlag stat = TrackAna::Init();
84 if (stat == Task::EInitFlag::kFATAL) return stat;
85 if (fTempEventPlot == nullptr) { fTempEventPlot = new QAPlot("Null", ECutUpdate::kEvent); }
86 if (fTempTrackPlot == nullptr) {
87 Cout::PrintInfo("Lack of Track QA", EInfo::kError);
88 return Task::EInitFlag::kFATAL;
89 }
90 fEventQA = new TObjArray();
91 for (int i = 0; i < fEventCollectionsNo; i++) {
92 QAPlot* plot = fTempEventPlot->MakeCopy();
93 plot->Init(GetTaskID());
94 fEventQA->Add(plot);
95 }
96 delete fTempEventPlot;
97 fTempEventPlot = nullptr;
98
99 fTrackQA = new TObjArray();
100 for (int i = 0; i < fTrackCollectionsNo * fEventCollectionsNo; i++) {
101 QAPlot* plot = fTempTrackPlot->MakeCopy();
102 plot->Init(GetTaskID());
103 fTrackQA->Add(plot);
104 }
105 delete fTempTrackPlot;
106 fTempTrackPlot = nullptr;
107 return Task::EInitFlag::kSUCCESS;
108 }
109
110 QATrackTask& QATrackTask::operator=(const QATrackTask& other) {
111 if (this == &other) return *this;
112 if (other.fTempEventPlot) {
113 if (fTempEventPlot) delete fTempEventPlot;
114 fTempEventPlot = other.fTempEventPlot->MakeCopy();
115 }
116 if (other.fTempTrackPlot) {
117 if (fTempTrackPlot) delete fTempTrackPlot;
118 fTempTrackPlot = other.fTempTrackPlot->MakeCopy();
119 }
120 fEventColNames = other.fEventColNames;
121 fTrackColNames = other.fTrackColNames;
122 return *this;
123 }
124
125 void QATrackTask::LinkCollections() {
126 fCutContainer->LinkCollections(ECutUpdate::kEvent, ECutUpdate::kTrack, CutContainer::ELinkPolicy::kAnyToAny);
127 }
128
129 Package* QATrackTask::Report() const {
130 Package* pack = TrackAna::Report();
131 const Int_t eventCol = fEventQA->GetEntries();
132 const Int_t trackCol = fTrackQA->GetEntries() / fEventQA->GetEntries();
133
134 for (int iEventCol = 0; iEventCol < eventCol; iEventCol++) {
135 QAPlot* qa_event = (QAPlot*) fEventQA->At(iEventCol);
136 QAPlotReport* event_report = qa_event->GetReport();
137 event_report->Recalculate();
138 TString eventColName = Form("Event coll. %i", iEventCol);
139 if ((int) fEventColNames.size() > iEventCol) { eventColName = fEventColNames[iEventCol]; }
140 event_report->SetName(eventColName);
141 pack->AddObject(event_report);
142 for (int jTrackCol = 0; jTrackCol < trackCol; jTrackCol++) {
143 QAPlot* qa_track = (QAPlot*) fTrackQA->At(iEventCol * trackCol + jTrackCol);
144 QAPlotReport* track_report = qa_track->GetReport();
145 track_report->Recalculate();
146 if (jTrackCol < (int) fTrackColNames.size()) {
147 TString name = Form("%s %s", eventColName.Data(), fTrackColNames[jTrackCol].Data());
148 track_report->SetName(name);
149 } else {
150 track_report->SetName(Form("Event coll. %i Track coll. %i", iEventCol, jTrackCol));
151 }
152 pack->AddObject(track_report);
153 }
154 }
155 return pack;
156 }
157
158 void QATrackTask::SetEventCollectionNames(const std::initializer_list<TString>& init) {
159 fEventColNames.clear();
160 for (auto const name : init) {
161 fEventColNames.push_back(name);
162 }
163 }
164
165 void QATrackTask::SetTrackCollectionNames(const std::initializer_list<TString>& init) {
166 fTrackColNames.clear();
167 for (auto const name : init) {
168 fTrackColNames.push_back(name);
169 }
170 }
171} // namespace Hal
void AddObject(TObject *object)
Definition Package.cxx:209
virtual void Recalculate()
virtual Bool_t Init(Int_t id_task=-1)
Definition QAPlot.cxx:47
virtual QAPlot * MakeCopy() const
Definition QAPlot.h:142