Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
Cut.cxx
1#include "Cut.h"
2
3#include "Cout.h"
4#include "DataFormatManager.h"
5#include "Event.h"
6#include "Package.h"
7#include "Parameter.h"
8
9#include <TObjArray.h>
10
11namespace Hal {
12 Cut::Cut(const Int_t size, ECutUpdate update, TString group_flag) :
13 TNamed(),
14 fPassed(0),
15 fFailed(0),
16 fTotal(0),
17 fSubCut(size),
18 fCutSize(size),
19 fInit(kFALSE),
20 fIsCloned(kFALSE),
21 fState(0),
22 fCollectionID(0),
23 fLabel(-1),
24 fUpdateRatio(update),
25 fWeight(1.0),
26 fGroupFlag(group_flag) {}
27
28 Cut::Cut(const Cut& cut) : TNamed(cut), fCutSize(cut.fCutSize), fUpdateRatio(cut.fUpdateRatio), fGroupFlag(cut.fGroupFlag) {
29 this->fPassed = cut.fPassed;
30 this->fFailed = cut.fFailed;
31 this->fTotal = cut.fTotal;
32 this->fSubCut = cut.fSubCut;
33 this->fInit = cut.fInit;
34 this->fIsCloned = cut.fIsCloned;
35 this->fState = cut.fState;
36 this->fCollectionID = cut.fCollectionID;
37 this->fWeight = cut.fWeight;
38 this->fLabel = cut.fLabel;
39 }
40
41 void Cut::Reset() { fPassed = fFailed = fTotal = 0; }
42
43 Bool_t Cut::Validate() {
44 fTotal++;
45 fState = fSubCut.Validate();
46 if (fState) {
47 fPassed++;
48 return kTRUE;
49 } else {
50 fFailed++;
51 return kFALSE;
52 }
53 }
54
56 fTotal++;
57 fState = !fSubCut.Validate();
58 if (fState) {
59 fPassed++;
60 return kTRUE;
61 } else {
62 fFailed++;
63 return kFALSE;
64 }
65 }
66
68 fTotal++;
69 fState = fSubCut.ValidateAbs();
70 if (fState) {
71 fPassed++;
72 return kTRUE;
73 } else {
74 fFailed++;
75 return kFALSE;
76 }
77 }
78
79 Bool_t Cut::ForcedUpdate(Bool_t state) {
80 if (state) {
81 ++fPassed;
82 fState = 1;
83 } else {
84 ++fFailed;
85 fState = 0;
86 }
87 ++fTotal;
88 return state;
89 }
90
91 void Cut::SetMinAndMax(Double_t val, Int_t i) { SetMinMax(val, val, i); }
92
93 void Cut::SetMinMax(Double_t min, Double_t max, Int_t i) {
94 if (i > fSubCut.GetSize() || i < 0) {
95 Cout::PrintInfo(Form("Seting wrong parameter id (%i) in %s", i, ClassName()), EInfo::kError);
96 return;
97 }
98 fSubCut.SetMin(min, i);
99 fSubCut.SetMax(max, i);
100 }
101
102 Cut** Cut::MultiClone(Int_t no, Bool_t increment_collections) {
103 Cut** array = new Cut*[no];
104 for (int i = 0; i < no; i++) {
105 array[i] = this->MakeCopy();
106 }
107 if (increment_collections) {
108 for (int i = 0; i < no; i++) {
109 array[i]->SetCollectionID(i);
110 }
111 }
112 return array;
113 }
114
116 Package* pack = new Package(this);
117 pack->AddObject(new ParameterInt("UpdateRatio", static_cast<Int_t>(fUpdateRatio)));
118 pack->AddObject(new ParameterInt("CutSize", fCutSize));
119 for (Int_t i = 0; i < fCutSize; i++) {
120 pack->AddObject(new ParameterString(Form("UnitName_%i", i), fSubCut.GetUnit(i)));
121 pack->AddObject(new ParameterDouble(Form("MinCut_%i", i), fSubCut.GetMin(i)));
122 pack->AddObject(new ParameterDouble(Form("MaxCut_%i", i), fSubCut.GetMax(i)));
123 }
124 pack->AddObject(new ParameterULong64("Passed", fPassed, '+'));
125 pack->AddObject(new ParameterULong64("Failed", fFailed, '+'));
126 pack->AddObject(new ParameterULong64("Total", fTotal, '+'));
127 pack->AddObject(new ParameterInt("CollectionID", fCollectionID));
128 return pack;
129 }
130
131 TObjArray* Cut::Split(Int_t n, Int_t i, Double_t shift) const {
132 if (i >= fCutSize) {
133 Cout::PrintInfo(Form("Canot split %s along %i", this->ClassName(), n), EInfo::kLowWarning);
134 return NULL;
135 }
136 if (n <= 1) {
137 Cout::PrintInfo(Form("Canot split %s into %i partts", this->ClassName(), i), EInfo::kLowWarning);
138 return NULL;
139 }
140 TObjArray* cuts_array = new TObjArray();
141 Double_t tmin = GetMin(i);
142 Double_t tmax = GetMax(i);
143 Double_t step = (tmax - tmin) / ((Double_t) n);
144 for (int j = 0; j < n; j++) {
145 Cut* copy = this->MakeCopy();
146 Double_t min = tmin + j * step;
147 Double_t max = tmin + (j + 1) * step;
148 if (shift > 0 && j != 0) {
149 min += shift;
150 } else if (shift < 0 && j != n - 1) {
151 max += shift;
152 }
153 copy->SetMinMax(min, max, i);
154 cuts_array->AddLast(copy);
155 }
156 return cuts_array;
157 }
158
159 void Cut::Print(Option_t* /*option*/) const {
160 Cout::InStars(Form("Report %s", this->ClassName()));
161 Cout::Text("Cut ranges", "M");
162 Cout::Database({"Parameter name", "Min", "Max"});
163 for (int i = 0; i < GetCutSize(); i++) {
164 Cout::Database({GetUnit(i), Form("%4.2f", GetMin(i)), Form("%4.2f", GetMax(i))});
165 }
166 Cout::Text(Form("Passed %llu", GetPassed()), "M");
167 Cout::Text(Form("Failed %llu", GetFailed()), "M");
168 }
169
170 Cut& Cut::operator=(const Cut& other) {
171 if (this == &other) return *this;
172 if (other.fCutSize != this->fCutSize) return *this;
173 if (other.fUpdateRatio != this->fUpdateRatio) return *this;
174 fPassed = other.fPassed;
175 fFailed = other.fFailed;
176 fTotal = other.fTotal;
177 fSubCut = other.fSubCut;
178 fInit = other.fInit;
179 fIsCloned = other.fIsCloned;
180 fState = other.fState;
182 fWeight = other.fWeight;
183 fLabel = other.fLabel;
184 return *this;
185 }
186
187 Bool_t Cut::FormatEquals(TString format, Int_t format_id, EFormatDepth depth) const {
188 if (depth == EFormatDepth::kAll) { // default depth, check manually
189 if (this->InheritsFrom("Hal::TwoTrackCut"))
190 depth = EFormatDepth::kBuffered;
191 else
192 depth = EFormatDepth::kNonBuffered;
193 }
194 const Event* ev = DataFormatManager::Instance()->GetFormat(format_id, depth);
195 TString classname = ev->ClassName();
196 if (classname.EqualTo(format))
197 return kTRUE;
198 else
199 return kFALSE;
200 }
201
202 Bool_t Cut::FormatInhertis(TString format, Int_t format_id, EFormatDepth depth) const {
203 if (depth == EFormatDepth::kAll) { // default depth, check manually
204 if (this->InheritsFrom("Hal::TwoTrackCut"))
205 depth = EFormatDepth::kBuffered;
206 else
207 depth = EFormatDepth::kNonBuffered;
208 }
209 const Event* ev = DataFormatManager::Instance()->GetFormat(format_id, depth);
210 if (ev->InheritsFrom(format)) return kTRUE;
211 return kFALSE;
212 }
213
214 TString Cut::CutName(Option_t* opt) const {
215 TString option = opt;
216 TString name;
217 TString className = ClassName();
218 if (fLabel >= 0) className = Form("%s_%i", className.Data(), fLabel);
219 if (option.EqualTo("re")) {
220 if (InheritsFrom("Hal::EventCut")) {
221 name = Form("Hal::EventRealCut(%s)", className.Data());
222 } else if (InheritsFrom("Hal::TrackCut")) {
223 name = Form("Hal::TrackRealCut(%s)", className.Data());
224 } else if (InheritsFrom("Hal::TwoTrackCut")) {
225 name = Form("Hal::TwoTrackRealCut(%s)", className.Data());
226 }
227 } else if (option.EqualTo("im")) {
228 if (InheritsFrom("Hal::EventCut")) {
229 name = Form("Hal::EventImaginaryCut(%s)", className.Data());
230 } else if (InheritsFrom("Hal::TrackCut")) {
231 name = Form("Hal::TrackImaginaryCut(%s)", className.Data());
232 } else if (InheritsFrom("Hal::TwoTrackCut")) {
233 name = Form("Hal::TwoTrackImaginaryCut(%s)", className.Data());
234 }
235 }
236 if (name.Length() == 0) name = className;
237 return name;
238 }
239
240 Bool_t Cut::InLimits(Int_t par) const {
241 if (GetValue(par) < GetMin(par)) return kFALSE;
242 if (GetValue(par) > GetMax(par)) return kFALSE;
243 return kTRUE;
244 }
245
246 std::vector<std::pair<TString, Double_t>> Cut::GetBinLabels(Int_t /*int1*/) const {
247 std::vector<std::pair<TString, Double_t>> x;
248 return x;
249 }
250} // 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...)
Definition Cut.h:40
Bool_t FormatInhertis(TString format, Int_t format_id, EFormatDepth depth=EFormatDepth::kAll) const
Definition Cut.cxx:202
Cut & operator=(const Cut &other)
Definition Cut.cxx:170
virtual TString CutName(Option_t *opt="") const
Definition Cut.cxx:214
Int_t fIsCloned
Definition Cut.h:83
void SetMinAndMax(Double_t val, Int_t i=0)
Definition Cut.cxx:91
Int_t fState
Definition Cut.h:87
Cut ** MultiClone(Int_t no, Bool_t increment_collections=kFALSE)
Definition Cut.cxx:102
virtual void Print(Option_t *option="") const
Definition Cut.cxx:159
Double_t fWeight
Definition Cut.h:103
Int_t fLabel
Definition Cut.h:95
Bool_t FormatEquals(TString format, Int_t format_id, EFormatDepth depth=EFormatDepth::kAll) const
Definition Cut.cxx:187
void SetCollectionID(Int_t i)
Definition Cut.h:247
TString GetUnit(Int_t i) const
Definition Cut.h:311
void Reset()
Definition Cut.cxx:41
virtual Cut * MakeCopy() const
Definition Cut.h:317
Bool_t InLimits(Int_t par) const
Definition Cut.cxx:240
void SetMinMax(Double_t min, Double_t max, Int_t i=0)
Definition Cut.cxx:93
Double_t GetValue(Int_t i=0) const
Definition Cut.h:285
const Int_t fCutSize
Definition Cut.h:75
Bool_t ForcedUpdate(Bool_t state)
Definition Cut.cxx:79
Bool_t ValidateAbs()
Definition Cut.cxx:67
ULong64_t GetFailed() const
Definition Cut.h:305
TObjArray * Split(Int_t n, Int_t i=0, Double_t shift=0) const
Definition Cut.cxx:131
Int_t GetCutSize() const
Definition Cut.h:252
Double_t GetMin(Int_t i=0) const
Definition Cut.h:273
ULong64_t GetPassed() const
Definition Cut.h:295
Bool_t Validate()
Definition Cut.cxx:43
Double_t GetMax(Int_t i=0) const
Definition Cut.h:279
virtual Package * Report() const
Definition Cut.cxx:115
const ECutUpdate fUpdateRatio
Definition Cut.h:99
Bool_t AntiValidate()
Definition Cut.cxx:55
Cut(const Int_t size=1, ECutUpdate update=ECutUpdate::kNo, TString groupFlag="")
Definition Cut.cxx:12
Bool_t fInit
Definition Cut.h:79
Int_t fCollectionID
Definition Cut.h:91
virtual std::vector< std::pair< TString, Double_t > > GetBinLabels(Int_t par=0) const
Definition Cut.cxx:246
const Event * GetFormat(Int_t task_id, EFormatDepth format_depth=EFormatDepth::kAll) const
static DataFormatManager * Instance()
void AddObject(TObject *object)
Definition Package.cxx:209
void SetMax(Double_t val, Int_t i=0)
Definition SubCut.cxx:86
TString GetUnit(Int_t i) const
Definition SubCut.h:70
Bool_t ValidateAbs()
Definition SubCut.cxx:99
void SetMin(Double_t val, Int_t i=0)
Definition SubCut.cxx:84
Double_t GetMax(Int_t i) const
Definition SubCut.h:99
Bool_t Validate()
Definition SubCut.cxx:92
Double_t GetMin(Int_t i) const
Definition SubCut.h:93
Int_t GetSize() const
Definition SubCut.h:81