Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TCut.cxx
Go to the documentation of this file.
1// @(#)root/tree:$Id$
2// Author: Rene Brun 14/04/97
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/** \class TCut
13\ingroup tree
14
15A specialized string object used for TTree selections.
16A TCut object has a name and a title. It does not add any data
17members compared to a TNamed. It only add a set of operators to
18facilitate logical string concatenation. For example, assume
19~~~ {.cpp}
20 cut1 = "x<1" and cut2 = "y>2"
21~~~
22then
23~~~ {.cpp}
24 cut1 && cut2 will be the string "(x<1)&&(y>2)"
25~~~
26Operators =, +=, +, *, !, &&, || overloaded.
27
28Examples of use:
29~~~ {.cpp}
30 Root > TCut c1 = "x<1"
31 Root > TCut c2 = "y<0"
32 Root > TCut c3 = c1&&c2
33 Root > ntuple.Draw("x", c1)
34 Root > ntuple.Draw("x", c1||"x>0")
35 Root > ntuple.Draw("x", c1&&c2)
36 Root > ntuple.Draw("x", "(x+y)"*(c1&&c2))
37~~~
38*/
39
40#include "TCut.h"
41
42
43////////////////////////////////////////////////////////////////////////////////
44/// Constructor.
45
47{
48}
49
50////////////////////////////////////////////////////////////////////////////////
51/// Constructor.
52
53TCut::TCut(const char *title) : TNamed("CUT",title)
54{
55}
56
57////////////////////////////////////////////////////////////////////////////////
58/// Constructor.
59
60TCut::TCut(const char *name, const char *title) : TNamed(name,title)
61{
62}
63
64////////////////////////////////////////////////////////////////////////////////
65/// Copy Constructor.
66
67TCut::TCut(const TCut &cut) : TNamed(cut)
68{
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// Typical destructor.
73
75{
76}
77
78////////////////////////////////////////////////////////////////////////////////
79/// Comparison.
80
81bool TCut::operator==(const char *rhs) const
82{
83 return fTitle == rhs;
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// Comparison.
88
89bool TCut::operator==(const TCut &rhs) const
90{
91 return fTitle == rhs.fTitle;
92}
93
94////////////////////////////////////////////////////////////////////////////////
95/// Comparison.
96
97bool TCut::operator!=(const char *rhs) const
98{
99 return fTitle != rhs;
100}
101
102////////////////////////////////////////////////////////////////////////////////
103/// Comparison.
104
105bool TCut::operator!=(const TCut &rhs) const
106{
107 return fTitle != rhs.fTitle;
108}
109
110////////////////////////////////////////////////////////////////////////////////
111/// Assignment.
112
114{
115 fTitle = rhs;
116 return *this;
117}
118
119////////////////////////////////////////////////////////////////////////////////
120/// Assignment.
121
123{
124 if (this != &rhs) TNamed::operator=(rhs);
125 return *this;
126}
127
128////////////////////////////////////////////////////////////////////////////////
129/// Addition.
130
132{
133 if (!rhs || !rhs[0]) return *this;
134 if (fTitle.Length() == 0)
135 fTitle = rhs;
136 else
137 fTitle = "(" + fTitle + ")&&(" + TString(rhs) + ")";
138 return *this;
139}
140
141////////////////////////////////////////////////////////////////////////////////
142/// Addition.
143
145{
146 if (rhs.fTitle.Length() == 0) return *this;
147 if (fTitle.Length() == 0)
148 fTitle = rhs;
149 else
150 fTitle = "(" + fTitle + ")&&(" + rhs.fTitle + ")";
151 return *this;
152}
153
154////////////////////////////////////////////////////////////////////////////////
155/// Multiplication.
156
158{
159if (!rhs || !rhs[0]) return *this;
160 if (fTitle.Length() == 0)
161 fTitle = rhs;
162 else
163 fTitle = "(" + fTitle + ")*(" + TString(rhs) + ")";
164 return *this;
165}
166
167////////////////////////////////////////////////////////////////////////////////
168/// Multiplication.
169
171{
172 if (rhs.fTitle.Length() == 0) return *this;
173 if (fTitle.Length() == 0)
174 fTitle = rhs;
175 else
176 fTitle = "(" + fTitle + ")*(" + rhs.fTitle + ")";
177 return *this;
178}
179
180////////////////////////////////////////////////////////////////////////////////
181/// Addition.
182
183TCut operator+(const TCut& lhs, const char *rhs)
184{
185 return TCut(lhs) += rhs;
186}
187
188////////////////////////////////////////////////////////////////////////////////
189/// Addition.
190
191TCut operator+(const char *lhs, const TCut& rhs)
192{
193 return TCut(lhs) += rhs;
194}
195
196////////////////////////////////////////////////////////////////////////////////
197/// Addition.
198
199TCut operator+(const TCut& lhs, const TCut& rhs)
200{
201 return TCut(lhs) += rhs;
202}
203
204////////////////////////////////////////////////////////////////////////////////
205/// Multiplication.
206
207TCut operator*(const TCut& lhs, const char *rhs)
208{
209 return TCut(lhs) *= rhs;
210}
211
212////////////////////////////////////////////////////////////////////////////////
213/// Multiplication.
214
215TCut operator*(const char *lhs, const TCut& rhs)
216{
217 return TCut(lhs) *= rhs;
218}
219
220////////////////////////////////////////////////////////////////////////////////
221/// Multiplication.
222
223TCut operator*(const TCut& lhs, const TCut& rhs)
224{
225 return TCut(lhs) *= rhs;
226}
227
228////////////////////////////////////////////////////////////////////////////////
229/// Logical and.
230
231TCut operator&&(const TCut& lhs, const char *rhs)
232{
233 return TCut(lhs) += rhs;
234}
235
236////////////////////////////////////////////////////////////////////////////////
237/// Logical and.
238
239TCut operator&&(const char *lhs, const TCut& rhs)
240{
241 return TCut(lhs) += rhs;
242}
243
244////////////////////////////////////////////////////////////////////////////////
245/// Logical and.
246
248{
249 return TCut(lhs) += rhs;
250}
251
252////////////////////////////////////////////////////////////////////////////////
253/// Logical or.
254
255TCut operator||(const TCut& lhs, const char *rhs)
256{
257 if (lhs.fTitle.Length() == 0 && (!rhs || !rhs[0])) return TCut();
258 if (lhs.fTitle.Length() == 0) return TCut(rhs);
259 if (!rhs || !rhs[0]) return TCut(lhs);
260 TString s = "(" + lhs.fTitle + ")||(" + TString(rhs) + ")";
261 return TCut(s.Data());
262}
263
264////////////////////////////////////////////////////////////////////////////////
265/// Logical or.
266
267TCut operator||(const char *lhs, const TCut& rhs)
268{
269 if ((!lhs || !lhs[0]) && rhs.fTitle.Length() == 0) return TCut();
270 if (!lhs || !lhs[0]) return TCut(rhs);
271 if (rhs.fTitle.Length() == 0) return TCut(lhs);
272 TString s = "(" + TString(lhs) + ")||(" + rhs.fTitle + ")";
273 return TCut(s.Data());
274}
275
276////////////////////////////////////////////////////////////////////////////////
277/// Logical or.
278
280{
281 if (lhs.fTitle.Length() == 0 && rhs.fTitle.Length() == 0) return TCut();
282 if (lhs.fTitle.Length() == 0) return TCut(rhs);
283 if (rhs.fTitle.Length() == 0) return TCut(lhs);
284 TString s = "(" + lhs.fTitle + ")||(" + rhs.fTitle + ")";
285 return TCut(s.Data());
286}
287
288////////////////////////////////////////////////////////////////////////////////
289/// Logical negation.
290
292{
293 if (rhs.fTitle.Length() == 0) return TCut();
294 TString s = "!(" + rhs.fTitle + ")";
295 return TCut(s.Data());
296}
297
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
TCut operator*(const TCut &lhs, const char *rhs)
Multiplication.
Definition TCut.cxx:207
TCut operator!(const TCut &rhs)
Logical negation.
Definition TCut.cxx:291
TCut operator+(const TCut &lhs, const char *rhs)
Addition.
Definition TCut.cxx:183
TCut operator||(const TCut &lhs, const char *rhs)
Logical or.
Definition TCut.cxx:255
TCut operator&&(const TCut &lhs, const char *rhs)
Logical and.
Definition TCut.cxx:231
char name[80]
Definition TGX11.cxx:110
A specialized string object used for TTree selections.
Definition TCut.h:25
TCut()
Constructor.
Definition TCut.cxx:46
bool operator==(const char *rhs) const
Comparison.
Definition TCut.cxx:81
TCut & operator*=(const char *rhs)
Multiplication.
Definition TCut.cxx:157
~TCut() override
Typical destructor.
Definition TCut.cxx:74
TCut & operator=(const char *rhs)
Assignment.
Definition TCut.cxx:113
TCut & operator+=(const char *rhs)
Addition.
Definition TCut.cxx:131
bool operator!=(const char *rhs) const
Comparison.
Definition TCut.cxx:97
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
TString fTitle
Definition TNamed.h:33
TNamed & operator=(const TNamed &rhs)
TNamed assignment operator.
Definition TNamed.cxx:50
Basic string class.
Definition TString.h:138
Ssiz_t Length() const
Definition TString.h:425
const char * Data() const
Definition TString.h:384