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