#include <Gate.h> class CGate { public: CGate (); Bool_t getChecked(); Bool_t getCachedValue(); void Set (Bool_t fValue); void Reset (); virtual void RecursiveReset(); Bool_t wasChecked (); virtual Bool_t operator() (CEvent& rEvent) ; virtual CConstituentIterator Begin () = 0; virtual CConstituentIterator End () = 0; virtual UInt_t Size () = 0; virtual std::string GetConstituent (CConstituentIterator& rIterator) = 0; virtual CGate* clone () = 0; virtual std::string Type () const = 0; virtual Bool_t inGate (CEvent& rEvent, const std::vector<UInt_t>& Params) = 0; virtual Bool_t inGate (CEvent& rEvent) = 0; virtual Bool_t caches(); }; #include <Cut.h> class CCut : public CGate { public: CCut ( Float_t am_nLow, Float_t am_nHigh, UInt_t am_nId ) ; Float_t getLow() const; Float_t getHigh() const; UInt_t getId() const; virtual std::vector<std::string> getSpecs() const; virtual Bool_t operator()(CEvent& rEvent); virtual CGate* clone () ; virtual CConstituentIterator Begin () ; virtual CConstituentIterator End () ; virtual UInt_t Size () ; virtual std::string GetConstituent (CConstituentIterator& rIterator) ; virtual std::string Type () const; virtual Bool_t inGate(CEvent& rEvent, const std::vector<UInt_t>& Params); virtual Bool_t inGate (CEvent& rEvent); virtual Bool_t inGate (Float_t x); }; #include <FalseGate.h> class CFalseGate { CFalseGate (); virtual Bool_t operator() (CEvent& rEvent) ; virtual CConstituentIterator Begin () ; virtual CConstituentIterator End () ; virtual UInt_t Size () ; virtual std::string GetConstituent (CConstituentIterator& rIterator) ; virtual CGate* clone () ; virtual std::string Type () const; virtual Bool_t inGate(CEvent& rEvent, const std::vector<UInt_t>& Params); virtual Bool_t inGate(CEvent& rEvent); virtual Bool_t caches(); }; #include <TrueGate.h> class CTrueGate : public CGate { CTrueGate () : CGate(); virtual Bool_t operator() (CEvent& rEvent) ; virtual CConstituentIterator Begin () ; virtual CConstituentIterator End () ; virtual UInt_t Size () ; virtual std::string GetConstituent (CConstituentIterator& rIterator) ; virtual CGate* clone () ; virtual std::string Type () const; virtual Bool_t inGate(CEvent& rEvent, const std::vector<UInt_t>& Params); virtual Bool_t inGate(CEvent& rEvent); virtual Bool_t caches(); }; class CMaskGate : public CGate { public: CMaskGate (UInt_t mask); long getCompare() const; virtual Bool_t operator() (CEvent& rEvent) ; virtual UInt_t Size () ; }; class CMaskAndGate : public CMaskGate { public: CMaskAndGate ( UInt_t am_nId, UInt_t am_lCompare ); long getCompare() const; UInt_t getId() const; virtual Bool_t operator() (CEvent& rEvent) ; virtual CGate* clone () ; virtual std::string Type () const; virtual Bool_t inGate(CEvent& rEvent, const std::vector<UInt_t>& Params); virtual Bool_t inGate(CEvent& rEvent); }; #include <MaskEqualGate.h> class CMaskEqualGate : public CMaskGate { public: CMaskEqualGate ( UInt_t am_nId, UInt_t am_lCompare ) ; long getCompare() const; UInt_t getId() const; virtual Bool_t operator() (CEvent& rEvent) ; virtual CGate* clone () ; virtual std::string Type () const; virtual Bool_t inGate(CEvent& rEvent, const std::vector<UInt_t>& Params); virtual Bool_t inGate(CEvent& rEvent); }; #include <MaskEqualGate.h> class CMaskNotGate : public CMaskGate { public: CMaskNotGate ( UInt_t am_nId, UInt_t am_lCompare ); long getCompare() const; UInt_t getId() const; public: virtual Bool_t operator() (CEvent& rEvent) ; virtual CGate* clone () ; virtual std::string Type () const; virtual Bool_t inGate(CEvent& rEvent, const std::vector<UInt_t>& Params); virtual Bool_t inGate(CEvent& rEvent); }; #include <Point.h> // Defines FPoint used below. #include <PointlistGate.h> class CPointListGate : public CGate { public: CPointListGate (UInt_t nXId, UInt_t nYId, const std::vector<FPoint>& Points); CPointListGate(UInt_t nXId, UInt_t nYId, UInt_t nPts, Float_t *xCoords, Float_t *yCoords); CPointListGate(UInt_t nXId, UInt_t nYId, UInt_t nPts, FPoint* pPoints); UInt_t getxId() const; UInt_t getyId() const; std::vector<FPoint> getPoints() const; std::vector<FPoint>::iterator getBegin(); std::vector<FPoint>::iterator getEnd() ; virtual CConstituentIterator Begin () ; virtual CConstituentIterator End () ; virtual UInt_t Size () ; virtual std::string GetConstituent (CConstituentIterator& rIterator) ; virtual Bool_t inGate(CEvent& rEvent); virtual Bool_t Inside(Float_t x, Float_t y) = 0; }; #include <Band.h> class CBand : public CPointListGate { public: //Default constructor CBand (UInt_t nXid, UInt_t nYid, const std::vector<FPoint>& points); CBand (UInt_t nXid, UInt_t nYid, UInt_t nPts, FPoint* pPoints); CBand (UInt_t nXid, UInt_t nYid, UInt_t nPts, Float_t* pX, Float_t* pY); virtual Bool_t operator()(CEvent& rEvent); virtual CGate* clone () ; virtual std::string Type () const; virtual Bool_t Inside(Float_t x, Float_t y) ; protected: Bool_t Interior(Float_t x, Float_t y); }; #include <Contour.h> class CContour : public CPointListGate { public: //Default constructor CContour (UInt_t nXId, UInt_t nYId, const std::vector<FPoint>& Points); CContour (UInt_t nXId, UInt_t NYId, UInt_t nPts, Float_t *xCoords, Float_t *yCoords); CContour (UInt_t nXId, UInt_t NYId, UInt_t nPts, FPoint* pPonts); FPoint getLowerLeft() const; FPoint getUpperRight() const; virtual Bool_t operator()(CEvent& rEvent); virtual CGate* clone () ; virtual std::string Type () const; virtual Bool_t Inside(Float_t x, Float_t y); }; #include <C2Bands> class C2Bands : public CContour { public: C2Bands (UInt_t nXId, UInt_t nYId, std::vector<FPoint>& rLowBand, std::vector<FPoint>& rHiBand); virtual std::string Type () ; }; #include <CompoundGate.h> class CCompoundGate : public CGate { public: CCompoundGate () {} CCompoundGate(std::list<CGateContainer*> pGates); CCompoundGate(std::vector<CGateContainer*> pGates); CCompoundGate(UInt_t nGates, CGateContainer** ppGates); std::list<CGateContainer*>& GetConstituents(); virtual void RecursiveReset(); virtual CConstituentIterator Begin () ; virtual CConstituentIterator End () ; virtual UInt_t Size () ; virtual std::string GetConstituent (CConstituentIterator& rIterator) ; void AddGateFront(CGateContainer& rGate); void AddGateBack(CGateContainer& rGate); void AddGate(CConstituentIterator& rSpot, CGateContainer& rGate); }; #include <AndGate.h> class CAndGate : public CCompoundGate { public CAndGate () : CCompoundGate() ; CAndGate(std::list<CGateContainer*>amp; rGates); CAndGate(std::vector<CGateContainer*>amp; rGates); virtual std::string Type () const; virtual Bool_t inGate(CEvent& rEvent, const std::vector<UInt_t>& Params ); virtual Bool_t inGate(CEvent& rEvent); }; #include <OrGate> class COrGate : public CCompoundGate { COrGate (); COrGate(std::list<CGateContainer*>& rGates); COrGate(std::vector<CGateContainer*>& rGates); virtual CGate* clone () ; virtual std::string Type () const; virtual Bool_t inGate(CEvent& rEvent, const std::vector<UInt_t>& Params); virtual Bool_t inGate(CEvent& rEvent); }; #include <Not.h> class CNot : public CGate { CNot (CGateContainer& rGate); const CGateContainer* getGate(); virtual CConstituentIterator Begin () ; virtual CConstituentIterator End () ; virtual UInt_t Size () ; virtual std::string GetConstituent (CConstituentIterator& rp) ; virtual CGate* clone () ; virtual std::string Type () const; virtual Bool_t inGate(CEvent& rEvent, const std::vector<UInt_t>& Params); virtual Bool_t inGate(CEvent& rEvent); };
The CGate
class provides base class services
and an API definition for SpecTcl's gate classes. SpecTcl has
a rich set of gate types ranging from primitive gates to compound
gates. A primitive gate is one that does not depend on other gates.
A compound gate is one that depends on one or more other gates.
As the same gate may be checked more than once per event, gates can rememer if they've been checkedand, if they have been, the result of the most recent check. For most gates, therefore, the actual computation of the gate is only done once per event with the cached value of that check being used in subsequent attempts to evaluate the gate.
CGate();
Constructs the base class. The gate is set with the cache invalid. The state of the cached value is therefore meaningless.
const Bool_t getChecked();
,
Bool_t wasChecked();
If the gate has a valid cached value returns kfTRUE. Otherwise returns kfFALSE
const Bool_t getCachedValue();
If the gate has a cached value (getChecked
returns kfTRUE) returns the cached value
for that gate. kfTRUE means the
gate was satisifed by its last check.
kfFALSE means the gate was not
satisfied. If
getChecked
returns
kfFalse, the return value
from this method has no meaning.
void Set (Bool_t fValue);
Sets the new value for the gate. If called after
this method call, getChecked
will return kfTRUE until the
cache is reset via a call to Reset
is called on this gate or RecursiveReste
is called on this gate or a gate that contains this gate
either directly or indirectly.
void Reset();
Resets the cache on this gate. Any constituent gates
will not be reset. Therefore, it is preferable
to call RecursiveReset
.
virtual void RecursiveReset();
Resets the cached status of this break. For every constituent gate this method also does a recursive reset on it. Thus this method is expected to Reset all the gates that contribute to this gate as well as this gate itself.
virtual Bool_t operator()(CEvent& rEvent);
If the gate has a valid cached value, that value is returned.
If not, the gate is checked (normally using inGate
).
The result is then cached and returned.
This might be implemented as:
if (!wasChecked()) { Set(inGate(rEvent)); // Sets the gate status and cachce. } return getCachedValue();
virtual = 0 CConstituentIterator Begin ();
Compound gates are gates that depend on other gates. You can think of them as a container for other gates (some may be compound as wel) and a logical relationship required among those gates. For example, an And gate requires all constituent gates to be satisfied if it is to be satisifed for an event. The gates a compound gate depends on are called constituents.
If the gate has constituents, this method should return
an iterator to the first item of the container of
constituents If the gate has no constitutents, the value
returned by End
is returned.
This method is pure virtual to allow each gate type to use the container of constituents appropriate to it.
virtual =0 CConstituentIterator End();
Returns the end of iteration iterator for the consitutents of this gate.
virtual = 0 std::string GetConstituent(CConstituentIterator& rIterator);
Returns a stringified version of the gate 'pointed to' by the constituent iterator. The form of this string may vary from gate type to gate type. Therefore, this method will be documented completely for each concrete gate class so you know what to expect.
virtual = 0 CGate* clone();
Returns a dynamically created gate that is identical in state to this gate. Note that dynamically created means that when the client is done with this gate they must delete it.
virtual const = 0 std::string Type();
Returns a text string that identifies the gate type. This method will be documented for each concrete gate type.
virtual = 0 Bool_t inGate (CEvent& rEvent);
This method is used mostly by non gamma gates. That is gates with only one set of possible parameters. It returns kfTrue if the event satisfies the gate and kfFalse if not.
virtual = 0 Bool_t inGate(CEvent& rEvent, const std::vector<UInt_t>& Params);
This is normally used by gamma gates. If the parameter
ids in Params
select a set of
parameters in rEvent
that make
this gate true, the method returns kfTrue
otherwise kfFalse.
Gamma gates can be used as cuts by trying all legal
combinations of parmeter ids in the
Params
vector.
virtual Bool_t caches();
Returns kfTrue if the gate caches. This can be used to restrict the set of gates that are reset to only those that have a cache.
CCut
gates represent an interval in parameter
space for some parameter. If an event has that parameter and that
parameter lies in that interval, the gate is satisfied. As with
other intervals in SpecTcl, the interval is inclusive of the low
limit but exclusive of the high limit.
CCut (Float_t am_nLow, Float_t am_nHigh, UInt_t am_nId );
Constructs a gate that is satisfied when the
parameter with id am_nId
is in
the interval
[am_nLow
, am_nHigh
)
const Float_t getLow();
Returns the value of the low end of the interval that defines the cut.
const Float_t getHigh();
Returns the value of the high end of the interval that defines the cut.
const UInt_t getId();
Returns the id of the parameter this gate will test.
virtual std::vector<std::string> getSpecs();
Returns a vector of spectrum names involved with the gate. For a cut, no spectra are involved so an empty vector is returned. This is used mainly by gamma gates.
virtual CConstituentIterator Begin();
A cut is a gate with a single constituent - itself. This method returns an iterator that, once incremented is at the end of iteration.
virtual CConstituentIterator End ();
Returns an iterator that points to nothing, and is off the end of constiuents.
virtual UInt_t Size();
Returns 1 indicating there is only one constituent, the gate itself.
virtual std::string GetConstituent (CConstituentIterator& rIterator);
If the iterator is not at end returns a string consisting of three space separated values. The first value is the parameter id. The second and third are the low and high limits of the cut's interval.
virtual const std::string Type();
Returns the string s for slice. This is the type of gate. Note that c is used for the type of contour gates.
virtual Bool_t inGate(Float_t x);
Returns kfTRUE if
x
is in the cut's interval.
virtual Bool_t inGate(CEvent& rEvent);
If the event does not have the parameter whose id was used to construct the cut, returns kfFalse. If it does, the value of that parameter is passed to the previous method and the result of that method is returned.
virtual Bool_t inGate(CEvent& rEvent, const std::vector<UInt_t>& Params);
Same as the previous method, howver instead of using
the id of the parameter used to construct this
object, the parameter id Params[0]
is used.
CFalseGate methods
CFalseGate
is a gate that is never satisfied.
When gates are deleted, they are actually replaced by false gates,
gates are never actually deleted.
virtual Bool_t operator()(CEvent& rEvent);
As the gate name implies, regardless of the content
of rEvent
, this always
returns kfFALSE.
virtual CConstituentIterator Begin();
Returns an iterator at end (same value as
End
). False gates have no
components.
virtual CConstituentIterator End();
virtual UInt_t Size();
Returns 0
virtual std::string GetConstituent (CConstituentIterator& rIterator);
Regardless of the value of
rIterator
; returns an empty string.
virtual const; std::string Type ();
Returns the string F which represents a False gate.
virtual Bool_t inGate(CEvent& rEvent);
,
virtual Bool_t inGate(CEvent& rEvent, const std::vector<UInt_t>& ids);
Both of these return kfFalse regardless of the parameters passed in.
virtual Bool_t caches();
Returns kfFalse as there's no need
for a hard coded gate like CFalseGate
to cache its answers.
CTrueGate methods
CTrueGate
is a gate that is never satisfied.
When a spectrum is created it is initially gated on a true gate.
True gates can also be used as place holders for gate to be defined
later.
virtual Bool_t operator()(CEvent& rEvent);
As the gate name implies, regardless of the content
of rEvent
, this always
returns kfTRUE.
virtual CConstituentIterator Begin();
Returns an iterator at end (same value as
End
). False gates have no
components.
virtual CConstituentIterator End();
virtual UInt_t Size();
Returns 0
virtual std::string GetConstituent (CConstituentIterator& rIterator);
Regardless of the value of
rIterator
; returns an empty string.
virtual const; std::string Type ();
Returns the string T which represents a True gate.
virtual Bool_t inGate(CEvent& rEvent);
,
virtual Bool_t inGate(CEvent& rEvent, const std::vector<UInt_t>& ids);
Both of these return kfTrue regardless of the parameters passed in.
virtual Bool_t caches();
Returns kfFalse as there's no need
for a hard coded gate like CFalseGate
to cache its answers.
Bit mask gates treat a parameter like a bitmask (integer) and
perform various bit logic mask and compare operations.
An abstract base class; CMaskGate
Provides storage for the constant bit mask and the following
meaningful methods:
CMaskGate(UInt_t mask);
This base class constructor stores the
mask
as an object attribute.
Derived classes can use getCompare
to retrieve this value. Gates derived from this
method normally perform some bitwise operation between
the parameter and the mask and then a comparison.
const long getCompare();
Returns the mask that used to instantiate this base class.
virtual Bool_t operator() (CEvent& rEvent);
This just determine is the actual class's
inGate
method has to be invoked.
If not the cached value for the gate is returned.
Psuedo code for this is:
if cache is not valid Set cached value from Actual Class's inGate(rEvent) endif return cached value
These gates check to see if all bits in a mask are present in the parameter.
CMaskAndGate (UInt_t am_nId, UInt_t am_lCompare);
am_nId
is the parameter id
of the parameter to test.
am_lCompare
is the bit
mask used inthe compare.
const long getCompare();
Returns the bit mask used in the test.
const UInt_t getId();
Returns the id of the parameter that is checked by this gate.
virtual const std::string Type();
Returns am for And Mask.
virtual Bool_t inGate(CEvent& rEvent, const std::vector<UInt_t>& Params);
,
virtual Bool_t inGate(CEvent& rEvent);
Check for the parameter to satisfy the gate.
Unfortunately the implementation of both of these
methods are the same (Params
is
totally ignored and the first method just calls
the second.
The Mask used to construct the gate is bitwise anded with the parameter. If the result is equal to the mask, the gate is satisfied, otherwise not.
If the gate is satisfied, the method returns kfTRUE otherwise kfFALSE.
These just test for bitwise equality of the integerized parameter with the specified comparison bitmask.
CMaskEqualGate (UInt_t am_nId, UInt_t am_lCompare );
Provides a parameter id and a comparison mask on which the object (gate) is constructed.
const long getCompare();
Returns the comparison value for the gate.
const UInt_t getId();
Returns the Id of the parameter on which the gate was constructed.
virtual Bool_t inGate(CEvent& rEvent);
Compares the specified parameter to the mask. If bitwise equal the gate is satisfied.
CMaskNotGate
METHODSThis gate tests for bits that are not in a mask.
CMaskNotGate (UInt_t am_nId, UInt_t am_lCompare);
As with all of these mask gate classes,
a parameter id (am_nId
) and
a mask (am_lCompare
) are required
by the constructor. The actual gate pseudo code
will be shown in the inGate
method. However, this gate will be satisfied if
the parameter contains all of the bits that are not
set in the mask.
const long getCompare();
Returns the value of the mask used in the
inGate
operation.
const UInt_t getId();
Returns the id of the parameter checked in the
inGate
method.
virtual Bool_t inGate(CEvent& rEvent);
Determines if the parameter associated with the
gate satisfies it for the event rEvent
.
The psuedo code for this is:
id = getId() if rEvent[id].isValid() then mask = ~getCompare() // Note bitwise complement. return (mask & rEvent[id]) == mask endif return kfFALSE
CPointListGate
methods
2-d gates are normally figures draw in a 2-d space defined by
a pair of parameters. These figures are defined by an array
of points in parameter space.
CPointListGate
is an abstract
base class for simple
2-d gates which stores the ids of both X and Y parameters and
the list of points that define the figure.
While the figure points can be abstracted, the concept of inside-ness of a point in parameter space must be defined by a concrete derived class. It's easy to see that this is the case by considering the difference in the definition of inside-ness for a contour (closed figure) and a band (polyline).
CPointListGate(UInt_t nXId, UInt_t nYId, const std::vector<FPoint>& Points);
,
CPointListGate(UInt_t nXId, UInt_t nYId, UInt_t nPts, Float_t *xCoords, Float_t *yCoords);
,
CPointListGate(UInt_t nXId, UInt_t nYId, UInt_t nPts, FPoint* pPoints);
All constrcutors provide nXId
,
the id of the X parameter for the gate and
nYId
, the
id of the Y parameter for the gate. Constructors
only differ in how the points that define the gate
shape are passed.
In the first constructor, points are passsed in as
Points
, a vector of type
FPoint
. This type is
defined in the Point.h header.
It is an object that encapsulates an X,Y coordinate
pair that represents one point fo the gate shape.
The last two constructors require that the
number of points in the gate shape,
nPts
, be passed to the
constructor.
In the first of those two, the parameters
xCoords
and
yCoords
point to
simple C arrays containing the X aqnd Y coordinates
of each point
respectively. Clearly xCoords
and yCoords
must both have
nPts
elements.
In the final constructor, the parameter
pPoints
points to a C array
of FPoint
objects.
const UInt_t getxId();
,
const UInt_t getyId();
These two methods get the ids of the parameters
on the X and Y axes of the gate shape. An event
that has both of these ids defines a point in
parameter space where the parameter whose id is
returned by getxId
is
on the X axis and that returned by
getyId
is on the Y
axis. Gate points define a figure in this
space whose meaning depends on the actual,
concrete gate type.
const std::vector<FPoint> getPoints();
Returns a copy of the points vector. This may result
in copying a significatn number of
FPoint
objects and should
not be userd to obtain gate points in order to
check gates. Better to iterate or, if appropriate,
use the Crosses
utility method.
std::vector<FPoint>::iterator getBegin();
,
std::vector<FPoint>::iterator getEnd();
These methods provide support for iteration over
the set of points that define the gate. The
getBegin
returns an iterator
to the beginning of the container of
FPoint
objects defining the
gate points while
getEnd
returns an
end of iteration iterator.
If you are not sure what all this means; look up how iterators work in the C++ Standard Template library. These iterators work the same way.
virtual CConstituentIterator Begin();
,
virtual CConstituentIterator End ();
,
virtual UInt_t Size();
The constituents of point list gates are the points
of the gate. Begin
and End
provide for
iteration over the constituents (see
GetConstituent
below).
Size
returns the number
of constituents, in this case, the number of
points in the gate figure.
virtual std::string GetConstituent(CConstituentIterator& rIterator);
Return the text string corresponsding to the
constituent iterator rIterator
.
This will be a string consisting of two space
separated floating point number strings
(%f conversion). The first number
is the X coordinate value of the point corresponding
to the iterator while the second the Y coordinate
of the same point.
virtual Bool_t inGate(CEvent& rEvent);
Performs common code required to check if a gate
is satisfied by an event. The geometry sensitive
part of the check is done by the pure virtual
method Inside
defined
below. Thwe psuedo code for this
method is:
xid = getxId() yid = getyid() if (rEvent[xid].isValid() and rEvent[yid].isValid()) then return Inside(rEvent[xid], rEvent[yid]) endif return kfFalse
Thus this method only checks that both parameters
are defined. If so Inside
is invoked to see if the point defined by the
event satisfies the gate and otherwise,
kfFalse is returned.
virtual =0 Bool_t Inside(Float_t x, Float_t y);
Pure virtual method that has to be implemented by
concrete sub-classes. x
and
y
are a point in the parameter
coordinate space in which the gate is drawn. The
method should return kfTRUE if this
point is 'inside' that gate or
kfFALSE if not.
protected int Crosses(Float_t x, Float_t y, std::vector<FPoint>::iterator f, std::vector<FPoint>::iterator s);
This utility method is useful for determining
inside-edness. The parameters
x
and y
define a point in the parameter space of a gate.
f
and s
are two iterators that indicate two consecutive points
in the figure that defines the gate.
Those two points define a line segment in the gate
parameter space. The method 'draws' a horizontal
ray that extends left from (x
, y
).
The method returns 1 if this
line would intersect (cross) the line segment
defined by f
and
s
. If not,
0 is returned.
Special cases that can speed up the determination are mercilessly exploited.
CBand
methodsA Band is a polyline drawn in a two dimensional space defined by two SpecTcl parameters. Inside-ness is defined as being inside a region of the plane defined by the polyline and vertical lines from the left and right points extending infinitely down. A point is inside this region if a horizontal ray drawn leftward from the point crosses an odd number of line segments that make up the boundaries of the region. The vertical lines described above are included in that count.
This definition provides well defined behavior for bands that are multivalued in y (polylines for which the x coordinate of points is not monotonic). This definition is also consistent withe the definition of inside-ness used by contour gates.
The constructors are not documented below as there are three
of them that have all the same parameterizations as the
three constructors of the PointListGate
base class from which CBand
is defined.
virtual const std::string Type ();
Returns the gate type which is b.
virtual Bool_t Inside(Float_t x, Float_t y);
Just invokes Interior
,
see below.
protected Bool_t Interior(Float_t x, Float_t y);
Determines if a point is inside the band region. A boundary crossing algorithm similar to what is used in flood fill operations is used to define interior points consistently and predictably regardless of any pathologies of the boundary.
The software counts boundary crossings, including the crossings of rays extending from the left and right most points to negative infinity. An odd number of crossings means the point is inside the figure. An even number (zero is even) means the point is outside.
Here is pseudo code:
crossings = 0 if point is to the right and below the left most point crossings = crossings + 1 if point is to the right and below the righ tmost point crossings = crossings + 1 for each line segment in the polyline: if Crosses(point, segment) then // Crosses from base class crossings = crossings + 1 endif end for return (crosses & 1) == 1
CContour
methods
Contour gates are closed figures that are drawn on a 2-d parameter
space. A contour is satisified if the parameters are both defined
and lie within the figure. CContour
implements contour gates and is derived from
CPointListGate
.
As with bands, pathalogical figures are possible. Contours use a definition of inside-ness that is similar to that of bands, with the exception that there's no need to draw rays from a left and right point to negative infinity to complete a semi-infinite closed figure. For a contour a final line segment is drawn from the last point to the first point.
An optimization is performed when the gate is constructed. A bounding rectangle is computed from the points of the figure. When checking the gate; the point is first tested against this rectangle and the gate is not satisifed if the point is outside the rectangle. If the point is inside the rectangle, then a horizontal ray is 'drawn' from the point towards the left. The number of times this ray crosses a segment of the figure is computed and the point is considered inside the figure if this number is odd.
Psuedo code for this will be presented in the description
of the methods below. Note that the constructors for
CContour
are identical
to those for CPointListGate
. They
will not be documented below. Refer to
CPointListGate
for a description of
the constructor signatures.
const FPoint getLowerLeft();
This method returns the point at the lower left of the rectangle that bounds the contour.
const FPoint getUpperRight();
This method returns the point at the upper right of the rectangle that bounds the contour.
virtual const std::string Type ();
Returns the string c indicating this is a contour gate.
virtual Bool_t Inside(Float_t x, Float_t y);
Returns kfTrue if
x
, y
define a point inside the contour figure.
For a conceptual description of the definition
of inside (in the presence of pathalogical shapes),
see the description at the top of this section.
Psuedo code for the check is shown below:
If (x,y) is inside the bounding rectangle then
crossings = 0
for each segment in the figure // Note the last point is connected to first.
if Crosses(x,y, segment) then // From CPointListGate
crossings = crossings + 1
endif
end for
return (crossings & 1) == 1 // true if odd.
endif
return kfFALSE // Outside bounding rectangle.
C2Bands
Methods.This gate is essentially two bands that are made into a countour by joining their left and rightmost points to close the figure defined by the two bands.
C2Bands(UInt_t nXId, UInt_t nYId, std::vector<FPoint>& rLowBand, std::vector<FPoint>& rHiBand);
Constructs a contour from two bands whose
parameters are specified by
nXId
and
nYId
. The points that define
the first band are rLowBand
and those of the second,
rHiBand
.
The constructor simply marshalls these points
for the CContour
constructor. Once that's done, the methods of
CContour
class
provides all of the functionality.
virtual std::string Type();
Returns the string cb2.
CCompoundGate
MethodsCompound gates are gates that are composed of one or more other constituent gates. The compound gate is satisfied if a logical function of its constituent gates is satisfied.
CCompoundGate
is an abstract base
class for compound gates. This section will describe that
gate and the gates that are derived from this class.
CCompoundGate
provides storage of and
access to the constituent gates. The constituents can either
be provided at construction time or built up incrementally..
CCompoundGate();
This constructor creates the base class without
any contituent gates. Method such as
AddGateBack
must be used
to add constituents to the gate.
CCompoundGate(std::list<CGateContainer*> pGates);
,
CCompoundGate(std::vector<CGateContainer*> pGates);
,
CCompoundGate(UInt_t nGates, CGateContainer** ppGates);
These constructors create the object with an initial set of gates. Gates are stored as pointers to a gate container. This allows SpecTcl ot modify what the gate container "points to" without having to locate and fix up all references to an underlying gate.
The constructors only differ in the wa in which the
constituent gates are passed to the constuctor.
The first two use the
std::vector
and
std::list
container for the
constituent gates while the last uses a counted
C array of pointers to GateContainer
pointers.
std::list<CGateContainer*>& GetConstituents();
Returns the list of pointers to the gate containers that make up this gate.
virtual void RecursiveReset();
Resets the cache of this gate and all
constituent gates. The next time this, or any
constituent gate is asked for its value vai
operator()
it must
re-evaluate the gate with respect to the event.
virtual CConstituentIterator Begin ();
,
virtual CConstituentIterator End();
,
virtual UInt_t Size ();
Provides the usual constituent iterator interface
for the compound gate. Begin
produces an iterator at the start of the container
and End
one that is off
the end of the container. Finally
Size
returns the number
of times the iterator returned by
Begin
can be incremented
before it becomes equal to the iterator returned
by End
.
virtual std::string GetConstituent(CConstituentIterator& rIterator);
Returns the name of a constituent gate.
For compound gates, the
ConstituentIterator
can be
thought of as an object that retrieves
constituent gate names.
void AddGateFront(CGateContainer& rGate);
Adds a new constituent gate at the beginning of the constituents for the gate. Normally it's too hard to predicts the effect of constituent order on gates. If these can be predicted, however for And gates, the gates are most efficiently ordered in order of decreasing probability they'll fail, while for OR gates, gates are most efficiently ordered in decreasing probability they willl be satisfied.
void AddGateBack(CGateContainer& rGate);
Adds the gate container rGate
at the end of all of the existing constituents.
See above for notes on ordering gates.
void AddGate(CConstituentIterator& rSpot, CGateContainer& rGate);
Adds the gate container rGate
in the constituent list just prior to rSpot
.
Thus AddGateFront(rGate) is
identical to AddGate(Begin(), rGate).
Similarly, AddGateBack(rGate) is
identical to AddGate(End(), rGate).
CAndGate
methodsAn And gate is a compound gate that is satisfied only if all of its constituent gates are satisfied. Short ciruit evaluation improves the efficiency of evaluating this gate. Gates in the constituent list only get evaluated until the first gate fails at which time the gate is determined not to have been satisifed. If all gates are satisified, the and gate is satisfied.
The constructors for this class mirror those of
CCompoundGate
and therefore will not be
documented below. Refer to the documentation of the
constructors for CCompoundGate
for more
information about the constructors for this class.
virtual const std::string Type();
Returns the string *. This is the symbol for an and gate because the logical and operation is normally called the logical product.
virtual Bool_t inGate(CEvent& rEvent, const std::vector<UInt_t>& Params );
,
virtual Bool_t inGate(CEvent& rEvent);
Determines if the gate is satisfied. Since this is not a gamma gate, the first of these methods simply calls the second. The second method evaluates the gate by recursively evaluating the minimum set of constituents needed to determine if the gate is satisfied.
COrGate
methods
The Or gate is satisfied if any of its consituents is satisfied.
As with CAndGate
, short circuit evaluation
is used to minimize the computation required to evaluate this
gate. Constituent gates are evaluated until the first satisfied
gate at which point, the gate is deemed satisified. If no
gates in the list of consitutents are satisfied, the gate is
deemed to have not been satisfied.
virtual const std::string Type();
Returns the string +. This is the type for a an or gate because the logical OR operation is often called the logical sum of its product terms.
virtual Bool_t inGate(CEvent& rEvent, const std::vector<UInt_t>& Params);
,
virtual Bool_t inGate(CEvent& rEvent);
Recursively evaluates the constituent gates. As soon as a constituent gate is determined to be satisfied, this method returns kfTRUE, if no constituent gates are satisfied, the method return kfFALSE
As the gate does not have fold/gamma gate semantics, the first of these methods simply calls the second.
CNot
MethodsA Not gate is a gate that is true if its single constituent gate is false.
CNot(CGatContainer& rGate);
The rGate
is the single constituent
gate. This gate will
only be true for events that satisfy
this constituent.
const CGateContainer* getGate();
Returns a pointer to the gate container of the gate whose logical sense is inverted by this gate.
virtual CConstituentIterator Begin ();
,
virtual CConstituentIterator End();
,
virtual UInt_t Size();
Supplies the constituent iteration interface for
this gate type. Begin
and
End
provide iterators for
the start of iteration and the end respectively.
Size
returns the number
of constituents (1).
virtual std::string GetConstituent(CConstituentIterator& rp);
Returns the constituent pointed at the iterator
rp
. For the iterator
returned by Begin
, this returns
the name of the constituent gate. Otherwise an empty string
is returned.
virtual const std::string Type();
Returns the string - which is the type strig for a not gate. The string indicates negation of the constituent gate.
virtual Bool_t inGate(CEvent& rEvent, const std::vector<UInt_t>& Params);
,
virtual Bool_t inGate(CEvent& rEvent);
Rturns kfTRUE if
rEvent
satisfies the gate
(does not satisfy the constituent gate).
Otherwise returns kfFALSE.
The gate is not a gamma gate so the first overload of
this method just invokes the second.