GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4WinCond.cxx
Go to the documentation of this file.
1 // $Id: TGo4WinCond.cxx 2746 2020-04-16 09:10:17Z linev $
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 
21 TString TGo4WinCond::fgxURL_XLOW="xmin";
22 TString TGo4WinCond::fgxURL_XUP="xmax";
23 TString TGo4WinCond::fgxURL_YLOW="ymin";
24 TString TGo4WinCond::fgxURL_YUP="ymax";
25 
26 
27 // -----------------------------------------------
28 // Constructors
29 // -----------------------------------------------
31  TGo4Condition(),
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 // -----------------------------------------------
44 TGo4WinCond::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 {
55 GO4TRACE((15,"TGo4WinCond::TGo4WinCond(name,title)",__LINE__, __FILE__));
56 }
57 
58 // -----------------------------------------------
60 {
61 GO4TRACE((15,"TGo4WinCond::~TGo4WinCond()",__LINE__, __FILE__));
62 }
63 
64 // -----------------------------------------------
65 Bool_t TGo4WinCond::Test(Double_t v1, Double_t v2)
66 {
67  IncCounts();
68  if (!IsEnabled()) {
69  if (FixedResult())
70  IncTrueCounts();
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();
81  IncTrueCounts();
82  return IsTrue();
83 }
84 
85 // -----------------------------------------------
86 Bool_t TGo4WinCond::Test(Double_t v1)
87 {
88  IncCounts();
89  if (!IsEnabled()) {
90  if (FixedResult())
91  IncTrueCounts();
92  return FixedResult();
93  }
94  if (v1 < fLow1)
95  return IsFalse();
96  if (v1 >= fUp1)
97  return IsFalse();
98  IncTrueCounts();
99  return IsTrue();
100 }
101 // -----------------------------------------------
102 void 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 // -----------------------------------------------
112 void TGo4WinCond::SetValues(Double_t low1, Double_t up1)
113 {
114  fLow1 = low1;
115  fUp1 = up1;
116  SetDimension(1);
117 }
118 
119 // -----------------------------------------------
120 void 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 // -----------------------------------------------
130 void TGo4WinCond::PrintCondition(Bool_t limits)
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 // -----------------------------------------------
142 Double_t TGo4WinCond::GetIntegral(TH1* histo, Option_t* opt)
143 {
144  if(histo==0) return 0;
145  Double_t result=0;
146  SetHistogramRanges(histo);
147  result=histo->Integral(opt);
148  RestoreHistogramRanges(histo);
149  return result;
150 }
151 
152 // -----------------------------------------------
153 Double_t TGo4WinCond::GetMean(TH1* histo, Int_t axis)
154 {
155  if(histo==0) return 0;
156  Double_t result=0;
157  SetHistogramRanges(histo);
158  result=histo->GetMean(axis);
159  RestoreHistogramRanges(histo);
160  return result;
161 }
162 
163 // -----------------------------------------------
164 Double_t TGo4WinCond::GetRMS(TH1* histo, Int_t axis)
165 {
166  if(histo==0) return 0;
167  Double_t result=0;
168  SetHistogramRanges(histo);
169  result=histo->GetRMS(axis);
170  RestoreHistogramRanges(histo);
171  return result;
172 }
173 
174 // -----------------------------------------------
175 Double_t TGo4WinCond::GetSkewness(TH1* histo, Int_t axis)
176 {
177  if(histo==0) return 0;
178  Double_t result=0;
179  SetHistogramRanges(histo);
180  result=histo->GetSkewness(axis);
181  RestoreHistogramRanges(histo);
182  return result;
183 }
184 
185 // -----------------------------------------------
186 Double_t TGo4WinCond::GetCurtosis(TH1* histo, Int_t axis)
187 {
188  if(histo==0) return 0;
189  Double_t result=0;
190  SetHistogramRanges(histo);
191  result=histo->GetKurtosis(axis);
192  RestoreHistogramRanges(histo);
193  return result;
194 }
195 
196 // -----------------------------------------------
197 Double_t TGo4WinCond::GetXMax(TH1* histo)
198 {
199  if(histo==0) return 0;
200  Double_t result=0;
201  SetHistogramRanges(histo);
202  TAxis* xax=histo->GetXaxis();
203  Int_t maxbin=histo->GetMaximumBin();
204  if(histo->GetDimension()==1)
205  {
206  result=xax->GetBinCenter(maxbin);
207 
208  }
209  else if (histo->GetDimension()==2)
210  {
211  Int_t xmaxbin=maxbin%(histo->GetNbinsX()+2);
212  result=xax->GetBinCenter(xmaxbin);
213  }
214  else
215  {
216  result=0; // no support for 3d histos at the moment!
217  }
218  RestoreHistogramRanges(histo);
219  return result;
220 }
221 
222 // -----------------------------------------------
223 Double_t TGo4WinCond::GetYMax(TH1* histo)
224 {
225  if(histo==0) return 0;
226  Double_t result=0;
227  SetHistogramRanges(histo);
228  if(histo->GetDimension()==1)
229  {
230  result=histo->GetMaximum();
231  }
232  else if (histo->GetDimension()==2)
233  {
234  TAxis* yax=histo->GetYaxis();
235  Int_t maxbin=histo->GetMaximumBin();
236  Int_t maxybin=maxbin/(histo->GetNbinsX()+2);
237  result=yax->GetBinCenter(maxybin);
238  }
239  else
240  {
241  result=0; // no support for 3d histos at the moment!
242  }
243  RestoreHistogramRanges(histo);
244  return result;
245 }
246 
247 // -----------------------------------------------
248 Double_t TGo4WinCond::GetCMax(TH1* histo)
249 {
250  if(histo==0) return 0;
251  Double_t result=0;
252  SetHistogramRanges(histo);
253  result=histo->GetMaximum();
254  RestoreHistogramRanges(histo);
255  return result;
256 }
257 
258 // -----------------------------------------------
260 {
261  if(histo==0) return;
262  Double_t xmin=fLow1;
263  Double_t xmax=fUp1;
264  Double_t ymin=fLow2;
265  Double_t ymax=fUp2;
266  TAxis* xax=histo->GetXaxis();
267  fiSaveXMin=xax->GetFirst();
268  fiSaveXMax=xax->GetLast();
269  Int_t xminbin=xax->FindBin(xmin);
270  Int_t xmaxbin=xax->FindBin(xmax);
271  Int_t yminbin=0;
272  Int_t ymaxbin=0;
273  TAxis* yax=histo->GetYaxis();
274  if(yax && histo->GetDimension()>1)
275  {
276  fiSaveYMin=yax->GetFirst();
277  fiSaveYMax=yax->GetLast();
278  yminbin=yax->FindBin(ymin);
279  ymaxbin=yax->FindBin(ymax);
280  }
281  // set histo range to condition limits
282  xax->SetRange(xminbin,xmaxbin);
283  if(yax&& histo->GetDimension()>1)
284  yax->SetRange(yminbin,ymaxbin);
285 }
286 
287 // -----------------------------------------------
289 {
290  if(histo==0) return;
291  TAxis* xax=histo->GetXaxis();
292  TAxis* yax=histo->GetYaxis();
293  xax->SetRange(fiSaveXMin,fiSaveXMax);
294  if(yax&& histo->GetDimension()>1)
295  yax->SetRange(fiSaveYMin,fiSaveYMax);
296 }
297 
298 // -----------------------------------------------
299 Bool_t TGo4WinCond::UpdateFrom(TGo4Condition * cond, Bool_t counts)
300 {
301  if(!TGo4Condition::UpdateFrom(cond,counts)) return kFALSE;
302  if(!cond->InheritsFrom(TGo4WinCond::Class())) {
303  std::cout << "Cannot update " << GetName() << " from " << cond->ClassName() << std::endl;
304  return kFALSE;
305  }
306  Int_t dimension=0;
307  ((TGo4WinCond*)cond)->GetValues(dimension,fLow1,fUp1,fLow2,fUp2); // get limits from source
308  SetDimension(dimension);
309  return kTRUE;
310 }
311 
312 // -----------------------------------------------
313 
314 Bool_t TGo4WinCond::UpdateFromUrl(const char* rest_url_opt)
315 {
316  if (!TGo4Condition::UpdateFromUrl(rest_url_opt))
317  return kFALSE;
318  TString message;
319  message.Form("TGo4WinCond::UpdateFromUrl - condition %s: with url:%s", GetName(), rest_url_opt);
320  TGo4Log::Message(1, message.Data());
322  {
327  message.Form("Set Window condition %s:", GetName());
328  Int_t dim = GetDimension();
329  switch (dim)
330  {
331  case 1:
332  SetValues(xmin, xmax);
333  message.Append(TString::Format(", set limits to (%f, %f)", xmin, xmax));
334  break;
335  case 2:
336  SetValues(xmin, xmax, ymin, ymax);
337  message.Append(TString::Format(", set limits to (%f, %f) (%f, %f)", xmin, xmax, ymin, ymax));
338  break;
339  default:
340  message.Append(TString::Format(" !wrong condition dimension %d, NEVER COME HERE", dim));
341  break;
342  };
343 
344  }
345  else
346  {
347  std::cout << "DEBUG- no limits to change received" << std::endl;
348  }
349  TGo4Log::Message(1, message.Data());
350  return kTRUE;
351 }
352 
353 
354 
356 {
357  // delete old painter, replace by the new one
358  // overwritten method in subclass may check if painter is correct type
359  if(painter==0) return;
360  if(painter->InheritsFrom(TGo4WinCondPainter::Class()))
361  {
362  if(fxPainter) delete fxPainter;
363  fxPainter=painter;
364  fxPainter->SetCondition(this);
365  }
366  else
367  {
368  TGo4Log::Warn("Could not set painter of class %s for TGo4WinCond %s",
369  painter->ClassName(),GetName());
370  }
371 }
372 
374 {
375  TGo4ConditionPainter* painter=new TGo4WinCondPainter(GetName());
376  painter->SetCondition(this);
377  return painter;
378 }
379 
381 {
382  Int_t size = sizeof(*this);
383  if (GetName()!=0) size+=strlen(GetName());
384  if (GetTitle()!=0) size+=strlen(GetTitle());
385  return size;
386 }
387 
388 void TGo4WinCond::SavePrimitive(std::ostream& out, Option_t* opt)
389 {
390  static int cnt = 0;
391 
392  TString varname = MakeScript(out, Form("wincond%d", cnt++), opt);
393 
394  Int_t dim;
395  Double_t xl,xu,yl,yu;
396  GetValues(dim,xl,xu,yl,yu);
397 
398  if(dim==1) out << Form(" %s->SetValues(%f, %f);", varname.Data(), xl, xu) << std::endl;
399  else out << Form(" %s->SetValues(%f, %f, %f, %f);", varname.Data(), xl, xu, yl, yu) << std::endl;
400 }
401 
402 
static TString fgxURL_YLOW
Definition: TGo4WinCond.h:113
virtual Double_t GetYLow()
Definition: TGo4WinCond.h:59
Bool_t UrlOptionHasKey(const char *key)
virtual Double_t GetIntegral(TH1 *histo, Option_t *opt="")
Int_t fiSaveYMax
Definition: TGo4WinCond.h:141
virtual Bool_t UpdateFrom(TGo4Condition *cond, Bool_t counts)
virtual void SavePrimitive(std::ostream &fs, Option_t *="")
Int_t fiSaveXMin
Definition: TGo4WinCond.h:132
virtual void PrintCondition(Bool_t full=kTRUE)
Double_t fUp2
Definition: TGo4WinCond.h:129
Bool_t IsFalse() const
virtual Double_t GetYMax(TH1 *histo)
virtual Double_t GetSkewness(TH1 *histo, Int_t axis=1)
Int_t GetDimension()
virtual Double_t GetCMax(TH1 *histo)
virtual void PrintCondition(Bool_t full=kTRUE)
virtual Double_t GetCurtosis(TH1 *histo, Int_t axis=1)
static void Warn(const char *text,...)
Definition: TGo4Log.cxx:300
Bool_t IsEnabled() const
Definition: TGo4Condition.h:82
virtual Double_t GetXUp()
Definition: TGo4WinCond.h:58
virtual void GetValues(Int_t &dim, Double_t &x1, Double_t &y1, Double_t &x2, Double_t &y2)
virtual void SetValues()
Definition: TGo4Condition.h:93
virtual TGo4ConditionPainter * CreatePainter()
Int_t fiSaveYMin
Definition: TGo4WinCond.h:138
static TString fgxURL_XUP
Definition: TGo4WinCond.h:111
Bool_t FixedResult() const
void SetHistogramRanges(TH1 *histo)
virtual Double_t GetMean(TH1 *histo, Int_t axis=1)
Int_t fiSaveXMax
Definition: TGo4WinCond.h:135
Double_t fLow1
Definition: TGo4WinCond.h:120
Double_t fLow2
Definition: TGo4WinCond.h:126
virtual Bool_t UpdateFromUrl(const char *rest_url_opt)
static TString fgxURL_XLOW
Definition: TGo4WinCond.h:109
virtual void SetPainter(TGo4ConditionPainter *painter)
static TString fgxURL_YUP
Definition: TGo4WinCond.h:115
virtual Int_t GetMemorySize()
Double_t fUp1
Definition: TGo4WinCond.h:123
static const char * Message(Int_t prio, const char *text,...)
Definition: TGo4Log.cxx:209
Bool_t IsTrue() const
virtual Double_t GetXLow()
Definition: TGo4WinCond.h:57
virtual Double_t GetYUp()
Definition: TGo4WinCond.h:60
virtual void SetCondition(TGo4Condition *con)
const char * MakeScript(std::ostream &out, const char *varname, Option_t *opt="", const char *arrextraargs=0)
virtual Bool_t Test()
#define GO4TRACE(X)
Definition: TGo4Log.h:26
TGo4ConditionPainter * fxPainter
virtual void GetValues(Int_t &dim, Double_t &x1, Double_t &y1, Double_t &x2, Double_t &y2)
virtual Double_t GetXMax(TH1 *histo)
void RestoreHistogramRanges(TH1 *histo)
Bool_t UpdateFrom(TGo4Condition *cond, Bool_t counts)
virtual Double_t GetRMS(TH1 *histo, Int_t axis=1)
virtual ~TGo4WinCond()
Definition: TGo4WinCond.cxx:59
virtual Bool_t UpdateFromUrl(const char *rest_url_opt)
Double_t GetUrlOptionAsDouble(const char *key, Double_t def_value)
void SetDimension(Int_t d)