GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
TGo4WinCond.cxx
Go to the documentation of this file.
1// $Id$
2//-----------------------------------------------------------------------
3// The GSI Online Offline Object Oriented (Go4) Project
4// Experiment Data Processing at EE department, GSI
5//-----------------------------------------------------------------------
6// Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7// Planckstr. 1, 64291 Darmstadt, Germany
8// Contact: http://go4.gsi.de
9//-----------------------------------------------------------------------
10// This software can be used under the license agreements as stated
11// in Go4License.txt file which is part of the distribution.
12//-----------------------------------------------------------------------
13
14#include "TGo4WinCond.h"
15
16#include "TH1.h"
17
18#include "TGo4WinCondPainter.h"
19#include "TGo4Log.h"
20
21TString TGo4WinCond::fgxURL_XLOW="xmin";
22TString TGo4WinCond::fgxURL_XUP="xmax";
23TString TGo4WinCond::fgxURL_YLOW="ymin";
24TString TGo4WinCond::fgxURL_YUP="ymax";
25
26
27// -----------------------------------------------
28// Constructors
29// -----------------------------------------------
32 fLow1(0),
33 fUp1(0),
34 fLow2(0),
35 fUp2(0),
36 fiSaveXMin(0),
37 fiSaveXMax(0),
38 fiSaveYMin(0),
39 fiSaveYMax(0)
40{
41 GO4TRACE((15,"TGo4WinCond::TGo4WinCond()",__LINE__, __FILE__));
42}
43// -----------------------------------------------
44TGo4WinCond::TGo4WinCond(const char *name, const char *title) :
45 TGo4Condition(name,title),
46 fLow1(0),
47 fUp1(0),
48 fLow2(0),
49 fUp2(0),
50 fiSaveXMin(0),
51 fiSaveXMax(0),
52 fiSaveYMin(0),
53 fiSaveYMax(0)
54{
55GO4TRACE((15,"TGo4WinCond::TGo4WinCond(name,title)",__LINE__, __FILE__));
56}
57
58// -----------------------------------------------
60{
61GO4TRACE((15,"TGo4WinCond::~TGo4WinCond()",__LINE__, __FILE__));
62}
63
64// -----------------------------------------------
65Bool_t TGo4WinCond::Test(Double_t v1, Double_t v2)
66{
67 IncCounts();
68 if (!IsEnabled()) {
69 if (FixedResult())
71 return FixedResult();
72 }
73 if (v1 < fLow1)
74 return IsFalse();
75 if (v1 >= fUp1)
76 return IsFalse();
77 if (v2 < fLow2)
78 return IsFalse();
79 if (v2 >= fUp2)
80 return IsFalse();
82 return IsTrue();
83}
84
85// -----------------------------------------------
86Bool_t TGo4WinCond::Test(Double_t v1)
87{
88 IncCounts();
89 if (!IsEnabled()) {
90 if (FixedResult())
92 return FixedResult();
93 }
94 if (v1 < fLow1)
95 return IsFalse();
96 if (v1 >= fUp1)
97 return IsFalse();
99 return IsTrue();
100}
101// -----------------------------------------------
102void TGo4WinCond::SetValues(Double_t low1, Double_t up1, Double_t low2, Double_t up2)
103{
104 fLow1 = low1;
105 fUp1 = up1;
106 fLow2 = low2;
107 fUp2 = up2;
108 SetDimension(2);
109}
110
111// -----------------------------------------------
112void TGo4WinCond::SetValues(Double_t low1, Double_t up1)
113{
114 fLow1 = low1;
115 fUp1 = up1;
116 SetDimension(1);
117}
118
119// -----------------------------------------------
120void TGo4WinCond::GetValues(Int_t &dim, Double_t &x1, Double_t &y1, Double_t &x2, Double_t &y2)
121{
122 x1 = fLow1;
123 y1 = fUp1;
124 x2 = fLow2;
125 y2 = fUp2;
126 dim = GetDimension();
127}
128
129// -----------------------------------------------
131{
133 if (limits) {
134 if (GetDimension() == 1)
135 std::cout << TString::Format("[%8.2f,%8.2f]", fLow1, fUp1) << std::endl;
136 else
137 std::cout << TString::Format("[%8.2f,%8.2f][%8.2f,%8.2f]", fLow1, fUp1, fLow2, fUp2) << std::endl;
138 }
139}
140
141// -----------------------------------------------
142Double_t TGo4WinCond::GetIntegral(TH1 *histo, Option_t *opt)
143{
144 if(!histo) return 0;
145 SetHistogramRanges(histo);
146 Double_t result = histo->Integral(opt);
148 return result;
149}
150
151// -----------------------------------------------
152Double_t TGo4WinCond::GetMean(TH1 *histo, Int_t axis)
153{
154 if(!histo) return 0;
155 SetHistogramRanges(histo);
156 Double_t result = histo->GetMean(axis);
158 return result;
159}
160
161// -----------------------------------------------
162Double_t TGo4WinCond::GetRMS(TH1 *histo, Int_t axis)
163{
164 if(!histo) return 0;
165 SetHistogramRanges(histo);
166 Double_t result = histo->GetRMS(axis);
168 return result;
169}
170
171// -----------------------------------------------
172Double_t TGo4WinCond::GetSkewness(TH1 *histo, Int_t axis)
173{
174 if(!histo) return 0;
175 SetHistogramRanges(histo);
176 Double_t result = histo->GetSkewness(axis);
178 return result;
179}
180
181// -----------------------------------------------
182Double_t TGo4WinCond::GetCurtosis(TH1 *histo, Int_t axis)
183{
184 if(!histo) return 0;
185 SetHistogramRanges(histo);
186 Double_t result = histo->GetKurtosis(axis);
188 return result;
189}
190
191// -----------------------------------------------
192Double_t TGo4WinCond::GetXMax(TH1 *histo)
193{
194 if(!histo) return 0;
195 Double_t result = 0.;
196 SetHistogramRanges(histo);
197 TAxis *xax = histo->GetXaxis();
198 Int_t maxbin = histo->GetMaximumBin();
199 if (histo->GetDimension() == 1) {
200 result = xax->GetBinCenter(maxbin);
201 } else if (histo->GetDimension() == 2) {
202 Int_t xmaxbin = maxbin % (histo->GetNbinsX() + 2);
203 result = xax->GetBinCenter(xmaxbin);
204 } else {
205 result = 0; // no support for 3d histos at the moment!
206 }
208 return result;
209}
210
211// -----------------------------------------------
212Double_t TGo4WinCond::GetYMax(TH1 *histo)
213{
214 if(!histo) return 0;
215 Double_t result = 0;
216 SetHistogramRanges(histo);
217 if (histo->GetDimension() == 1) {
218 result = histo->GetMaximum();
219 } else if (histo->GetDimension() == 2) {
220 TAxis *yax = histo->GetYaxis();
221 Int_t maxbin = histo->GetMaximumBin();
222 Int_t maxybin = maxbin / (histo->GetNbinsX() + 2);
223 result = yax->GetBinCenter(maxybin);
224 } else {
225 result = 0; // no support for 3d histos at the moment!
226 }
228 return result;
229}
230
231// -----------------------------------------------
232Double_t TGo4WinCond::GetCMax(TH1 *histo)
233{
234 if(!histo) return 0;
235 SetHistogramRanges(histo);
236 Double_t result = histo->GetMaximum();
238 return result;
239}
240
241// -----------------------------------------------
243{
244 if(!histo) return;
245 Double_t xmin = fLow1;
246 Double_t xmax = fUp1;
247 Double_t ymin = fLow2;
248 Double_t ymax = fUp2;
249 TAxis *xax = histo->GetXaxis();
250 fiSaveXMin = xax->GetFirst();
251 fiSaveXMax = xax->GetLast();
252 Int_t xminbin = xax->FindBin(xmin);
253 Int_t xmaxbin = xax->FindBin(xmax);
254 Int_t yminbin = 0;
255 Int_t ymaxbin = 0;
256 TAxis *yax = histo->GetYaxis();
257 if (yax && histo->GetDimension() > 1) {
258 fiSaveYMin = yax->GetFirst();
259 fiSaveYMax = yax->GetLast();
260 yminbin = yax->FindBin(ymin);
261 ymaxbin = yax->FindBin(ymax);
262 }
263 // set histo range to condition limits
264 xax->SetRange(xminbin, xmaxbin);
265 if (yax && histo->GetDimension() > 1)
266 yax->SetRange(yminbin, ymaxbin);
267}
268
269// -----------------------------------------------
271{
272 if(!histo) return;
273 TAxis *xax=histo->GetXaxis();
274 TAxis *yax=histo->GetYaxis();
275 xax->SetRange(fiSaveXMin,fiSaveXMax);
276 if(yax&& histo->GetDimension()>1)
277 yax->SetRange(fiSaveYMin,fiSaveYMax);
278}
279
280// -----------------------------------------------
281Bool_t TGo4WinCond::UpdateFrom(TGo4Condition *cond, Bool_t counts)
282{
283 if(!TGo4Condition::UpdateFrom(cond,counts)) return kFALSE;
284 if(!cond->InheritsFrom(TGo4WinCond::Class())) {
285 std::cout << "Cannot update " << GetName() << " from " << cond->ClassName() << std::endl;
286 return kFALSE;
287 }
288 Int_t dimension = 0;
289 ((TGo4WinCond*)cond)->GetValues(dimension,fLow1,fUp1,fLow2,fUp2); // get limits from source
290 SetDimension(dimension);
291 return kTRUE;
292}
293
294// -----------------------------------------------
295
296Bool_t TGo4WinCond::UpdateFromUrl(const char *rest_url_opt)
297{
298 if (!TGo4Condition::UpdateFromUrl(rest_url_opt))
299 return kFALSE;
300 TGo4Log::Message(1, "TGo4WinCond::UpdateFromUrl - condition %s: with url:%s", GetName(), rest_url_opt);
301 TString message;
307 message.Form("Set Window condition %s:", GetName());
308 Int_t dim = GetDimension();
309 switch (dim) {
310 case 1:
311 SetValues(xmin, xmax);
312 message.Append(TString::Format(", set limits to (%f, %f)", xmin, xmax));
313 break;
314 case 2:
315 SetValues(xmin, xmax, ymin, ymax);
316 message.Append(TString::Format(", set limits to (%f, %f) (%f, %f)", xmin, xmax, ymin, ymax));
317 break;
318 default:
319 message.Append(TString::Format(" !wrong condition dimension %d, NEVER COME HERE", dim));
320 break;
321 };
322 } else {
323 std::cout << "DEBUG- no limits to change received" << std::endl;
324 }
325 if (message.Length() > 0)
326 TGo4Log::Message(1, "%s", message.Data());
327 return kTRUE;
328}
329
331{
332 // delete old painter, replace by the new one
333 // overwritten method in subclass may check if painter is correct type
334 if(!painter) return;
335 if(painter->InheritsFrom(TGo4WinCondPainter::Class())) {
336 if(fxPainter) delete fxPainter;
337 fxPainter = painter;
338 fxPainter->SetCondition(this);
339 } else {
340 TGo4Log::Warn("Could not set painter of class %s for TGo4WinCond %s",
341 painter->ClassName(),GetName());
342 }
343}
344
346{
347 auto painter = new TGo4WinCondPainter(GetName());
348 painter->SetCondition(this);
349 return painter;
350}
351
353{
354 Int_t size = sizeof(*this);
355 if (GetName()) size += strlen(GetName());
356 if (GetTitle()) size += strlen(GetTitle());
357 return size;
358}
359
360void TGo4WinCond::SavePrimitive(std::ostream &out, Option_t *opt)
361{
362 static int cnt = 0;
363
364 TString varname = MakeScript(out, TString::Format("wincond%d", cnt++), opt);
365
366 Int_t dim;
367 Double_t xl,xu,yl,yu;
368 GetValues(dim,xl,xu,yl,yu);
369
370 if(dim==1) out << TString::Format(" %s->SetValues(%f, %f);", varname.Data(), xl, xu) << std::endl;
371 else out << TString::Format(" %s->SetValues(%f, %f, %f, %f);", varname.Data(), xl, xu, yl, yu) << std::endl;
372}
373
374
#define GO4TRACE(X)
Definition TGo4Log.h:25
virtual Bool_t UpdateFrom(TGo4Condition *cond, Bool_t counts)
Copy values from cond to this.
Double_t GetUrlOptionAsDouble(const char *key, Double_t def_value)
Scan list of url options for key.
virtual Bool_t UpdateFromUrl(const char *rest_url_opt)
Method used by HTTP server to update some fields, specified in URL syntax.
Int_t GetDimension() const
void IncCounts()
Increment the test counter.
TGo4ConditionPainter * fxPainter
Painter instance to display the condition in root pad.
Bool_t FixedResult() const
Returns the value set by Disable(value).
void SetDimension(Int_t d)
void IncTrueCounts()
Increment the "test was true" counter.
Bool_t IsTrue() const
Use this as return, if test was true.
Bool_t UrlOptionHasKey(const char *key)
returns true if key is present in list of url options.
virtual void PrintCondition(Bool_t full=kTRUE)
Prints counters and boolean members.
Bool_t IsFalse() const
Use this as return, if test was false.
const char * MakeScript(std::ostream &out, const char *varname, Option_t *opt="", const char *arrextraargs=nullptr)
Bool_t IsEnabled() const
Returns true if condition is enabled.
static void Warn(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 2.
Definition TGo4Log.cxx:307
static const char * Message(Int_t prio, const char *text,...) GO4_PRINTF2_ARGS
Display a message.
Definition TGo4Log.cxx:206
virtual ~TGo4WinCond()
void GetValues(Int_t &dim, Double_t &x1, Double_t &y1, Double_t &x2, Double_t &y2) override
Returns limits.
Double_t GetMean(TH1 *histo, Int_t axis=1) override
Calculate value for histogram inside condition limits.
void SetPainter(TGo4ConditionPainter *painter) override
Replace default painter of this condition by external one.
static TString fgxURL_YUP
web condition editor keyword used in UpdateFromUrl.
Double_t GetXLow() const override
Definition TGo4WinCond.h:62
Int_t GetMemorySize() const override
Int_t fiSaveYMax
Saved maximum y-axis bin number for active histogram range.
Double_t fLow2
inclusive lower limit
static TString fgxURL_XUP
web condition editor keyword used in UpdateFromUrl.
Int_t fiSaveYMin
Saved minimum y-axis bin number for active histogram range.
Double_t GetYLow() const override
Definition TGo4WinCond.h:64
Double_t GetSkewness(TH1 *histo, Int_t axis=1) override
Calculate value for histogram inside condition limits.
virtual void SetValues()
Set values needed, i.e.
Double_t fUp1
exclusive upper limit
static TString fgxURL_XLOW
web condition editor keyword used in UpdateFromUrl.
Int_t fiSaveXMin
Saved minimum x-axis bin number for active histogram range.
Bool_t UpdateFromUrl(const char *rest_url_opt) override
Method used by HTTP server to update some fields, specified in URL syntax.
Double_t fUp2
exclusive upper limit
Double_t GetIntegral(TH1 *histo, Option_t *opt="") override
Calculate value for histogram inside condition limits.
void SetHistogramRanges(TH1 *histo)
Remember ranges of current histo and set range to active window.
virtual Bool_t Test()
Test if condition is true.
Int_t fiSaveXMax
Saved maximum x-axis bin number for active histogram range.
static TString fgxURL_YLOW
web condition editor keyword used in UpdateFromUrl.
Double_t GetXMax(TH1 *histo) override
Calculate value for histogram inside condition limits.
Double_t GetXUp() const override
Definition TGo4WinCond.h:63
Double_t GetCMax(TH1 *histo) override
Calculate value for histogram inside condition limits.
Double_t fLow1
inclusive lower limit
void SavePrimitive(std::ostream &fs, Option_t *opt="") override
Standard way to store parameter in form of macro.
void PrintCondition(Bool_t full=kTRUE) override
Printout.
Double_t GetYMax(TH1 *histo) override
Calculate value for histogram inside condition limits.
void RestoreHistogramRanges(TH1 *histo)
Restore original ranges of current histo.
Bool_t UpdateFrom(TGo4Condition *cond, Bool_t counts) override
Copy values from cond to this.
Double_t GetCurtosis(TH1 *histo, Int_t axis=1) override
Calculate value for histogram inside condition limits.
Double_t GetRMS(TH1 *histo, Int_t axis=1) override
Calculate value for histogram inside condition limits.
Double_t GetYUp() const override
Definition TGo4WinCond.h:65
TGo4ConditionPainter * CreatePainter() override
Factory method to generate the subclass implementation for painter.