GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GCondition.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2010 by Olivier Stezowski *
3  * stezow(AT)ipnl.in2p3.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
21 #ifndef Gw_GCondition
22 #define Gw_GCondition
23 
24 
25 #include "TNamed.h"
26 #include "TObjArray.h"
27 
28 #include <vector>
29 #include <utility>
30 
31 class TCut;
32 class TCutG;
33 
34 namespace Gw {
35 
36 class Peak1D;
37 class PeakCreator;
38 
40 
49 class GCondition : public TNamed
50 {
51 public:
52  static const Style_t gCoincStyle = 3004;
53  static const Style_t gAnticStyle = 3005;
54 
55 protected:
56  TObjArray fListOfConditions; // list of TCut or TGCut
57 
58 protected:
59  Bool_t fEnable; // switch on/off the cut
60  Bool_t fExpectedResult; // used for coincidence/anti coincidence treatment
61  //
62  mutable Bool_t fHasPassed; // true if last test has been passed
63  mutable std::vector<Bool_t> fHasPassed_; // individual gate
64 
65 public:
66  GCondition();
67  GCondition(const char * name, const char * title);
68  GCondition(const GCondition& p);
69  virtual ~GCondition();
70 
72  const TObjArray &GetListOfConditions()
73  {
74  return fListOfConditions;
75  }
76 
77  // Root copy this to object
78  virtual void Copy(TObject &o) const
79  {
80  ((GCondition &)o) = (*this);
81  }
82 
84  virtual void SetVarName(const Char_t * /*var_name*/, const Char_t * /*which_var*/ = "X")
85  {;}
86 
88  virtual void Browse(TBrowser* /*b*/)
89  {
90  Draw();
91  }
92 
94  virtual void Delete(Option_t* option = ""); //*MENU*
95 
97  virtual Bool_t IsPassed(Double_t, Double_t = 0.0) const
98  {
99  return !fExpectedResult;
100  }
101 
103  virtual Bool_t HasPassed() const
104  {
105  return fHasPassed;
106  }
107  virtual Bool_t HasPassed(UInt_t i) const
108  {
109  if ( i < fHasPassed_.size() )
110  return fHasPassed_[i];
111 
112  return false;
113  }
114 
116  virtual void Enable(); //*TOGGLE* *GETTER=IsEnable
117  virtual Bool_t IsEnable() const
118  {
119  return fEnable;
120  }
122  virtual void UseAsAnti(Bool_t r = false); //*TOGGLE* *GETTER=IsAnti
123  virtual Bool_t IsAnti() const
124  {
125  return fExpectedResult == false;
126  }
127 
128 
129  virtual Short_t Import(const char * /*what*/ = "*", const char * /*from*/ = "gpad", Option_t * /*opt*/ = "+")
130  {
131  return 0;
132  }
133 
134  virtual Short_t Export(const char * /*what*/ = "*", const char * /*to*/ = "MyCuts", Option_t * /*opt*/ = "") const
135  {
136  return 0;
137  }
138 
140  virtual void Print(Option_t* option = "") const; //*MENU*
141 
142  ClassDef(GCondition,1) // a graphical cut (1d,2d)
143 };
144 
146 
154 class GCond1D : public GCondition
155 {
156 private:
157  TString fVarX;
158 
159 protected:
160  // methods to convert peak to/from TCut
161  TCut *PeakToCut(const Gw::Peak1D *) const;
162  Gw::Peak1D * CutToPeak(TCut *);
163 
164 public:
165  // static method to convert a cut to a gate (gw::peak). Peak name is cut name while title is the variable on which this cut applys
166  static Gw::Peak1D *TCutToPeak(TCut *);
167 
168 public:
169  GCond1D();
170  GCond1D(const char * name, const char * title);
171  GCond1D(const GCond1D &p);
172  virtual ~GCond1D();
173 
174  // Root copy, this to o
175  virtual void Copy(TObject &o) const
176  {
177  ((GCond1D &)o) = (*this);
178  }
179 
181  virtual void SetVarName(const Char_t * var_name, const Char_t * /*which_var*/ = "X")
182  {
183  fVarX = var_name;
184  }
185 
186  void Draw(Option_t* option = "");
187 
189  virtual void UseAsAnti(Bool_t r = false); //*TOGGLE* *GETTER=IsAnti
190 
192  Gw::Peak1D *AddWindow(Double_t, Double_t, Option_t *opt = "+"); //*MENU*
193 
195  virtual Bool_t IsPassed(Double_t, Double_t = 0.0) const;
196 
198 
208  virtual Short_t Import(const char *what = "*", const char *from = "gpad", Option_t *opt = "+"); //*MENU*
209 
211 
215  virtual Short_t Export(const char *what = "*", const char *to = "MyCuts", Option_t *opt = "") const; //*MENU*
216 
217 
219  Gw::PeakCreator *WindowGCreator(const char *c_name = ""); //*MENU*
220 
221  ClassDef(GCond1D,1) // a graphical cut 1d
222 
223 };
224 
226 
233 class GCond2D : public GCondition
234 {
235 private:
236  TString fVarX;
237  TString fVarY;
238 
239 public:
240  GCond2D();
241  GCond2D(const char * name, const char * title);
242  GCond2D(const GCond2D &p);
243  virtual ~GCond2D();
244 
245  // Root copy
246  virtual void Copy(TObject &o) const
247  {
248  ((GCond2D &)o) = (*this);
249  }
250 
251  void Draw(Option_t* option = "");
252 
254  virtual void SetVarName(const Char_t * var_name, const Char_t * which_var = "X")
255  {
256  TString which(which_var);
257  if ( which == "X" )
258  fVarX = var_name;
259  if ( which == "Y" )
260  fVarY = var_name;
261  }
262 
264  TCutG *AddWindow(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax, Option_t *opt = "+"); //*MENU*
265 
267  virtual Bool_t IsPassed(Double_t, Double_t) const;
268 
270 
280  virtual Short_t Import(const char *what = "*", const char *from = "gpad", Option_t *opt = "+"); //*MENU*
281 
282  virtual Short_t Export(const char *what = "*", const char *to = "MyCuts", Option_t *opt = "") const; //*MENU*
283 
285  virtual void WindowGCreator(const char *c_name = ""); //*MENU*
286 
287 
288  ClassDef(GCond2D,1) // a graphical cut 2d
289 
290 };
291 
292 
294 
298 {
299 protected:
301 public:
302  GCondHandler(GCondition *cond) : fCond(cond)
303  {;}
304  virtual ~GCondHandler()
305  {;}
306 
309  {
310  return fCond;
311  }
312 
313  virtual Bool_t Check()
314  {
315  return false;
316  }
317  virtual void Fill()
318  {
319  ;
320  }
321 };
322 
323 
324 } // namespace
325 
326 #endif
TObjArray fListOfConditions
Definition: GCondition.h:56
virtual ~GCond1D()
Definition: GCondition.cpp:148
virtual void Copy(TObject &o) const
Definition: GCondition.h:246
virtual Bool_t Check()
Definition: GCondition.h:313
virtual Bool_t IsPassed(Double_t, Double_t=0.0) const
returns true if the condition is passed with success
Definition: GCondition.h:97
virtual void UseAsAnti(Bool_t r=false)
need to be redefined since Peak does not inherits from TAttFill
Definition: GCondition.cpp:181
Base for a Graphical condition 2D.
Definition: GCondition.h:233
GCondition * GetGCondition()
to get back the condition
Definition: GCondition.h:308
virtual Short_t Import(const char *="*", const char *="gpad", Option_t *="+")
Definition: GCondition.h:129
virtual void Browse(TBrowser *)
Browser means Draw.
Definition: GCondition.h:88
virtual Bool_t IsPassed(Double_t, Double_t) const
returns true if the condition is passed with success
Definition: GCondition.cpp:674
virtual ~GCondition()
Definition: GCondition.cpp:81
virtual Short_t Export(const char *="*", const char *="MyCuts", Option_t *="") const
Definition: GCondition.h:134
const TObjArray & GetListOfConditions()
to get one by one the individual list of conditions
Definition: GCondition.h:72
static const Style_t gAnticStyle
Definition: GCondition.h:53
virtual Bool_t HasPassed(UInt_t i) const
Definition: GCondition.h:107
Gw::Peak1D * CutToPeak(TCut *)
Definition: GCondition.cpp:475
virtual void SetVarName(const Char_t *var_name, const Char_t *which_var="X")
Set var name.
Definition: GCondition.h:254
Bool_t fHasPassed
Definition: GCondition.h:62
virtual void Enable()
toggle on/off the cut. if off returns always passed
Definition: GCondition.cpp:110
virtual Short_t Export(const char *what="*", const char *to="MyCuts", Option_t *opt="") const
Export 1D conditions.
Definition: GCondition.cpp:489
virtual void SetVarName(const Char_t *, const Char_t *="X")
Set var name.
Definition: GCondition.h:84
void Draw(Option_t *option="")
Definition: GCondition.cpp:643
virtual Short_t Export(const char *what="*", const char *to="MyCuts", Option_t *opt="") const
Definition: GCondition.cpp:894
virtual Short_t Import(const char *what="*", const char *from="gpad", Option_t *opt="+")
Import 2D conditions.
Definition: GCondition.cpp:694
virtual void SetVarName(const Char_t *var_name, const Char_t *="X")
Set var name.
Definition: GCondition.h:181
GCondition * fCond
Definition: GCondition.h:300
virtual Bool_t IsEnable() const
Definition: GCondition.h:117
Bool_t fExpectedResult
Definition: GCondition.h:60
void Draw(Option_t *option="")
Definition: GCondition.cpp:197
virtual Bool_t IsAnti() const
Definition: GCondition.h:123
Gw::PeakCreator * WindowGCreator(const char *c_name="")
add to the current canvas the way to add graphically 1D gates (type h after in the canvas to get list...
Definition: GCondition.cpp:153
static Gw::Peak1D * TCutToPeak(TCut *)
Definition: GCondition.cpp:428
TCut * PeakToCut(const Gw::Peak1D *) const
Definition: GCondition.cpp:463
TCutG * AddWindow(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax, Option_t *opt="+")
Add a window to the list of conditions.
Definition: GCondition.cpp:596
virtual Bool_t IsPassed(Double_t, Double_t=0.0) const
returns true if the condition is passed with success
Definition: GCondition.cpp:247
virtual void WindowGCreator(const char *c_name="")
prepare current canvas to draw a TCutG.
Definition: GCondition.cpp:968
virtual Short_t Import(const char *what="*", const char *from="gpad", Option_t *opt="+")
Import 1D conditions.
Definition: GCondition.cpp:270
virtual void Copy(TObject &o) const
Definition: GCondition.h:175
virtual void Delete(Option_t *option="")
delete all object from fListOfConditions
Definition: GCondition.cpp:86
GCondHandler(GCondition *cond)
Definition: GCondition.h:302
Base for a Graphical condition 1D.
Definition: GCondition.h:154
virtual void Print(Option_t *option="") const
overwritte print method ... should be to gw log system
Definition: GCondition.cpp:115
Gw::Peak1D * AddWindow(Double_t, Double_t, Option_t *opt="+")
Add a window to the list of conditions.
Definition: GCondition.cpp:218
virtual ~GCond2D()
Definition: GCondition.cpp:591
A graphical interface for placing schematic peak onto a 1D histogram with a given position...
Definition: Peak1D.h:79
virtual Bool_t HasPassed() const
return true if last condition has been passed. Set to false at the beginning of IsPassed ...
Definition: GCondition.h:103
std::vector< Bool_t > fHasPassed_
Definition: GCondition.h:63
Link between the leaf, the condition and the histogram.
Definition: GCondition.h:297
virtual void Fill()
Definition: GCondition.h:317
Bool_t fEnable
Definition: GCondition.h:59
virtual void UseAsAnti(Bool_t r=false)
to change gate into an anti gate
Definition: GCondition.cpp:91
static const Style_t gCoincStyle
Definition: GCondition.h:52
Base for a Graphical condition on a spectrum (1D, 2D)
Definition: GCondition.h:49
virtual ~GCondHandler()
Definition: GCondition.h:304
virtual void Copy(TObject &o) const
Definition: GCondition.h:78