Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
CutsAndMonitors.cxx
1/*
2 * Cuts.cxx
3 *
4 * Created on: 21 wrz 2020
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9
10#include "CutsAndMonitors.h"
11#include "CutMonitorX.h"
12#include "CutMonitorXY.h"
13#include "CutMonitorXYZ.h"
14
15#include "HistogramManager.h"
16
17#include <TObjArray.h>
18#include <TObjString.h>
19
20namespace Hal {
21 CutsAndMonitors::CutsAndMonitors() :
22 fCuts(nullptr),
23 fCutsOptions(nullptr),
24 fCutMonitors(nullptr),
25 fCutMonitorsOptions(nullptr),
26 fGlobalOptionCuts(""),
27 fGlobalOptionsCutMonitors("") {}
28
29 CutsAndMonitors::CutsAndMonitors(const CutsAndMonitors& other) :
30 TObject(other),
31 fCuts(nullptr),
32 fCutsOptions(nullptr),
33 fCutMonitors(nullptr),
34 fCutMonitorsOptions(nullptr),
35 fGlobalOptionCuts(other.fGlobalOptionCuts),
36 fGlobalOptionsCutMonitors(other.fGlobalOptionsCutMonitors) {
37 if (other.fCuts) {
38 fCuts = new TObjArray();
39 fCuts->SetOwner(kTRUE);
40 fCutsOptions = new TObjArray();
41 fCutsOptions->SetOwner(kTRUE);
42 for (int iCut = 0; iCut < other.fCuts->GetEntries(); iCut++) {
43 Cut* cut = (Cut*) other.fCuts->UncheckedAt(iCut);
44 TObjString* str = (TObjString*) other.fCutsOptions->UncheckedAt(iCut);
45 fCuts->AddLast(cut->MakeCopy());
46 fCutsOptions->AddLast(str->Clone());
47 }
48 }
49 if (other.fCutMonitors) {
50 fCutMonitors = new TObjArray();
51 fCutMonitors->SetOwner(kTRUE);
52 fCutMonitorsOptions = new TObjArray();
53 fCutMonitorsOptions->SetOwner(kTRUE);
54 for (int iCutMon = 0; iCutMon < other.fCutMonitors->GetEntries(); iCutMon++) {
55 CutMonitor* cut = (CutMonitor*) other.fCutMonitors->UncheckedAt(iCutMon);
56 TObjString* str = (TObjString*) other.fCutMonitorsOptions->UncheckedAt(iCutMon);
57 fCutMonitors->AddLast(cut->MakeCopy());
58 fCutMonitorsOptions->AddLast(str->Clone());
59 }
60 }
61 }
62
63 Int_t CutsAndMonitors::GetNCuts() const {
64 if (fCuts == nullptr) return 0;
65 return fCuts->GetEntries();
66 }
67
68 Int_t CutsAndMonitors::GetNCutMonitors() const {
69 if (fCutMonitors == nullptr) return 0;
70 return fCutMonitors->GetEntries();
71 }
72
73 CutsAndMonitors& CutsAndMonitors::operator=(const CutsAndMonitors& other) {
74 if (&other == this) return *this;
75 if (fCuts) {
76 delete fCuts;
77 delete fCutsOptions;
78 fCuts = nullptr;
79 fCutsOptions = nullptr;
80 }
81 if (fCutMonitors) {
82 delete fCutMonitors;
83 delete fCutMonitorsOptions;
84 fCutMonitors = nullptr;
85 fCutMonitorsOptions = nullptr;
86 }
87 fGlobalOptionCuts = other.fGlobalOptionCuts;
88 fGlobalOptionsCutMonitors = other.fGlobalOptionsCutMonitors;
89
90 if (other.fCuts) {
91 fCuts = new TObjArray();
92 fCuts->SetOwner(kTRUE);
93 fCutsOptions = new TObjArray();
94 fCutsOptions->SetOwner(kTRUE);
95 for (int iCut = 0; iCut < other.fCuts->GetEntries(); iCut++) {
96 Cut* cut = (Cut*) other.fCuts->UncheckedAt(iCut);
97 TObjString* str = (TObjString*) other.fCutsOptions->UncheckedAt(iCut);
98 fCuts->AddLast(cut->MakeCopy());
99 fCutsOptions->AddLast(str->Clone());
100 }
101 }
102 if (other.fCutMonitors) {
103 fCutMonitors = new TObjArray();
104 fCutMonitors->SetOwner(kTRUE);
105 fCutMonitorsOptions = new TObjArray();
106 fCutMonitorsOptions->SetOwner(kTRUE);
107 for (int iCutMon = 0; iCutMon < other.fCutMonitors->GetEntries(); iCutMon++) {
108 CutMonitor* cut = (CutMonitor*) other.fCutMonitors->UncheckedAt(iCutMon);
109 TObjString* str = (TObjString*) other.fCutMonitorsOptions->UncheckedAt(iCutMon);
110 fCutMonitors->AddLast(cut->MakeCopy());
111 fCutMonitorsOptions->AddLast(str->Clone());
112 }
113 }
114 return *this;
115 }
116
117 void CutsAndMonitors::AddCut(const Cut& cut, Option_t* opt) {
118 if (fCuts == nullptr) {
119 fCuts = new TObjArray();
120 fCutsOptions = new TObjArray();
121 fCuts->SetOwner(kTRUE);
122 fCutsOptions->SetOwner(kTRUE);
123 }
124 TObjString* str = new TObjString(opt);
125 fCuts->Add(cut.MakeCopy());
126 fCutsOptions->Add(str);
127 }
128
129 void CutsAndMonitors::AddCutMonitor(const CutMonitor& monitor, Option_t* opt) {
130 if (fCutMonitors == nullptr) {
131 fCutMonitors = new TObjArray();
132 fCutMonitorsOptions = new TObjArray();
133 fCutMonitors->SetOwner(kTRUE);
134 fCutMonitorsOptions->SetOwner(kTRUE);
135 }
136 TObjString* str = new TObjString(opt);
137 fCutMonitors->Add(monitor.MakeCopy());
138 fCutMonitorsOptions->Add(str);
139 }
140
141 const Cut* CutsAndMonitors::GetCut(Int_t i) const { return static_cast<Cut*>(fCuts->UncheckedAt(i)); }
142
143 TString CutsAndMonitors::GetCutOption(Int_t i) const {
144 TString opt = static_cast<TObjString*>(fCutsOptions->UncheckedAt(i))->GetString();
145 if (opt == "" || fGlobalOptionCuts == "") { return opt + fGlobalOptionCuts; }
146 return opt + "+" + fGlobalOptionCuts;
147 }
148
149 const CutMonitor* CutsAndMonitors::GetMonitor(Int_t i) const { return static_cast<CutMonitor*>(fCutMonitors->UncheckedAt(i)); }
150
151 TString CutsAndMonitors::GetCutMonitorOption(Int_t i) const {
152 TString opt = static_cast<TObjString*>(fCutMonitorsOptions->UncheckedAt(i))->GetString();
153 if (opt == "" || fGlobalOptionsCutMonitors == "") { return opt + fGlobalOptionsCutMonitors; }
154 return opt + "+" + fGlobalOptionsCutMonitors;
155 }
156
157 CutsAndMonitors::~CutsAndMonitors() {
158 if (fCutMonitors) delete fCutMonitors;
159 if (fCutMonitorsOptions) delete fCutMonitorsOptions;
160 if (fCuts) delete fCuts;
161 if (fCutsOptions) delete fCutsOptions;
162 }
163
164 Cut* CutsAndMonitors::CutAt(Int_t i) const { return static_cast<Cut*>(fCuts->UncheckedAt(i)); }
165
166 CutMonitor* CutsAndMonitors::MonitorAt(Int_t i) const { return static_cast<CutMonitor*>(fCutMonitors->UncheckedAt(i)); }
167
168 void CutsAndMonitors::ClearCuts() {
169 fCuts->Clear();
170 fCutsOptions->Clear();
171 }
172
173 void CutsAndMonitors::ClearMonitors() {
174 fCutMonitors->Clear();
175 fCutMonitorsOptions->Clear();
176 }
177
178 void CutsAndMonitors::AddRawCut(Cut* cut, TObjString* opt) {
179 if (opt == nullptr) { opt = new TObjString(""); }
180 if (fCuts == nullptr) {
181 fCuts = new TObjArray();
182 fCutsOptions = new TObjArray();
183 fCuts->SetOwner(kTRUE);
184 fCutsOptions->SetOwner(kTRUE);
185 }
186 fCuts->Add(cut);
187 fCutsOptions->Add(opt);
188 }
189
190 void CutsAndMonitors::AddRawCutMonitor(CutMonitor* mon, TObjString* opt) {
191 if (opt == nullptr) { opt = new TObjString(""); }
192 if (fCutMonitors == nullptr) {
193 fCutMonitors = new TObjArray();
194 fCutMonitorsOptions = new TObjArray();
195 fCutMonitors->SetOwner(kTRUE);
196 fCutMonitorsOptions->SetOwner(kTRUE);
197 }
198 fCutMonitors->Add(mon);
199 fCutMonitorsOptions->Add(opt);
200 }
201
202 CutMonitor* CutsAndMonitors::MakeCutMonitor(Int_t request_no) const {
203 if (request_no < 0 || request_no > (int) fCutMonitorRequests.size()) return nullptr;
204 CutMonitorRequest req = fCutMonitorRequests[request_no];
205 auto TransformOpt = [](TString opt) {
206 if (Hal::Std::FindParam(opt, "re")) {
207 return "re";
208 } else if (Hal::Std::FindParam(opt, "im")) {
209 return "im";
210 } else {
211 return "";
212 }
213 };
214 Int_t dim = req.GetNDim();
215 switch (dim) {
216 case 1: {
217 CutMonAxisConf x = req.GetConf('x');
218 if (x.GetCutNo() < 0) x.FixCutNo(GetCutNo(x.GetCutClassName()));
219 const Cut* CutX = GetCut(x.GetCutNo());
220 TString optX = TransformOpt(GetCutOption(x.GetCutNo()));
221 CutMonitorX* mon = new CutMonitorX(CutX->CutName(optX), x.GetParameterNo());
222 mon->SetXaxis(x.GetNBins(), x.GetMin(), x.GetMax());
223 return mon;
224 } break;
225 case 2: {
226 CutMonAxisConf x = req.GetConf('x');
227 CutMonAxisConf y = req.GetConf('y');
228 if (x.GetCutNo() < 0) x.FixCutNo(GetCutNo(x.GetCutClassName()));
229 if (y.GetCutNo() < 0) y.FixCutNo(GetCutNo(y.GetCutClassName()));
230 const Cut* CutX = GetCut(x.GetCutNo());
231 const Cut* CutY = GetCut(y.GetCutNo());
232 TString optX = TransformOpt(GetCutOption(x.GetCutNo()));
233 TString optY = TransformOpt(GetCutOption(y.GetCutNo()));
234 CutMonitorXY* mon = new CutMonitorXY(CutX->CutName(optX), x.GetParameterNo(), CutY->CutName(optY), y.GetParameterNo());
235 mon->SetXaxis(x.GetNBins(), x.GetMin(), x.GetMax());
236 mon->SetYaxis(y.GetNBins(), y.GetMin(), y.GetMax());
237 return mon;
238 } break;
239 case 3: {
240 CutMonAxisConf x = req.GetConf('x');
241 CutMonAxisConf y = req.GetConf('y');
242 CutMonAxisConf z = req.GetConf('z');
243 if (x.GetCutNo() < 0) x.FixCutNo(GetCutNo(x.GetCutClassName()));
244 if (y.GetCutNo() < 0) y.FixCutNo(GetCutNo(y.GetCutClassName()));
245 if (z.GetCutNo() < 0) z.FixCutNo(GetCutNo(z.GetCutClassName()));
246 const Cut* CutX = GetCut(x.GetCutNo());
247 const Cut* CutY = GetCut(y.GetCutNo());
248 const Cut* CutZ = GetCut(z.GetCutNo());
249 TString optX = TransformOpt(GetCutOption(x.GetCutNo()));
250 TString optY = TransformOpt(GetCutOption(y.GetCutNo()));
251 TString optZ = TransformOpt(GetCutOption(z.GetCutNo()));
252 CutMonitorXYZ* mon = new CutMonitorXYZ(CutX->CutName(optX),
253 x.GetParameterNo(),
254 CutY->CutName(optY),
255 y.GetParameterNo(),
256 CutZ->CutName(optZ),
257 z.GetParameterNo());
258 mon->SetXaxis(x.GetNBins(), x.GetMin(), x.GetMax());
259 mon->SetYaxis(y.GetNBins(), y.GetMin(), y.GetMax());
260 mon->SetZaxis(z.GetNBins(), z.GetMin(), z.GetMax());
261 return mon;
262 } break;
263 }
264 return nullptr;
265 }
266
267 void CutsAndMonitors::MakeCutMonitors(Option_t* opt) {
268 AddAllCutMonitorRequests(opt);
269 if (GetNRequest() != 0) {
270 for (int iMon = 0; iMon < GetNRequest(); iMon++) {
271 CutMonitor* mon = MakeCutMonitor(iMon);
272 if (mon != nullptr) { AddRawCutMonitor(mon); }
273 }
274 }
275 }
276
277 Int_t CutsAndMonitors::GetCutNo(TString classname) const {
278 for (int i = 0; i < fCuts->GetEntriesFast(); i++) {
279 Cut* cut = static_cast<Cut*>(fCuts->UncheckedAt(i));
280 TString name = cut->ClassName();
281 if (name.EqualTo(classname)) return i;
282 }
283 return -1;
284 }
285
286 void CutsAndMonitors::AddCutMonitorRequest(const CutMonAxisConf& x) { fCutMonitorRequests.push_back(CutMonitorRequest(x)); }
287
288 void CutsAndMonitors::AddCutMonitorRequest(const CutMonAxisConf& x, const CutMonAxisConf& y) {
289 fCutMonitorRequests.push_back(CutMonitorRequest(x, y));
290 }
291
292 void CutsAndMonitors::AddCutMonitorRequest(const CutMonAxisConf& x, const CutMonAxisConf& y, const CutMonAxisConf& z) {
293 fCutMonitorRequests.push_back(CutMonitorRequest(x, y, z));
294 }
295
296 void CutsAndMonitors::SetCollectionID(Int_t id) {
297 for (int i = 0; i < fCuts->GetEntriesFast(); i++) {
298 Cut* cut = static_cast<Cut*>(fCuts->UncheckedAt(i));
299 cut->SetCollectionID(id);
300 }
301 } // namespace Hal
302} // namespace Hal
TString GetCutClassName() const
Int_t GetParameterNo() const
CutMonAxisConf GetConf(Char_t axis) const
void SetYaxis(Int_t bins, Double_t min, Double_t max)
void SetZaxis(Int_t bins, Double_t min, Double_t max)
virtual CutMonitor * MakeCopy() const
void SetXaxis(Int_t bins, Double_t min, Double_t max)
Definition Cut.h:40
virtual TString CutName(Option_t *opt="") const
Definition Cut.cxx:214
void SetCollectionID(Int_t i)
Definition Cut.h:247
virtual Cut * MakeCopy() const
Definition Cut.h:317
Double_t GetMin() const
Double_t GetMax() const