Logo ROOT   6.18/05
Reference Guide
RooDataHistSliceIter.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$Id$
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17/**
18\file RooDataHistSliceIter.cxx
19\class RooDataHistSliceIter
20\ingroup Roofitcore
21
22RooDataHistSliceIter iterates over all bins in a RooDataHist that
23occur in a slice defined by the bin coordinates of the input
24sliceSet.
25**/
26
27#include "RooFit.h"
28
29#include "RooDataHist.h"
30#include "RooArgSet.h"
31#include "RooAbsLValue.h"
33
34using namespace std;
35
37;
38
39
40
41////////////////////////////////////////////////////////////////////////////////
42/// Construct an iterator over all bins of RooDataHist 'hist' in the slice defined
43/// by the values of the arguments in 'sliceArg'
44
45RooDataHistSliceIter::RooDataHistSliceIter(RooDataHist& hist, RooAbsArg& sliceArg) : _hist(&hist), _sliceArg(&sliceArg)
46{
47 // Calculate base index (for 0th bin) for slice
48 RooAbsArg* sliceArgInt = hist.get()->find(sliceArg.GetName()) ;
49 dynamic_cast<RooAbsLValue&>(*sliceArgInt).setBin(0) ;
50
51 if (hist._vars.getSize()>1) {
52 _baseIndex = hist.calcTreeIndex() ;
53 } else {
54 _baseIndex = 0 ;
55 }
56
57 _nStep = dynamic_cast<RooAbsLValue&>(*sliceArgInt).numBins() ;
58
59// cout << "RooDataHistSliceIter" << endl ;
60// hist.Print() ;
61// cout << "hist._iterator = " << hist._iterator << endl ;
62
63 Int_t i=0 ;
64 for (const auto arg : hist._vars) {
65 if (arg==sliceArgInt) break ;
66 i++ ;
67 }
68 _stepSize = hist._idxMult[i] ;
69 _curStep = 0 ;
70
71}
72
73
74
75////////////////////////////////////////////////////////////////////////////////
76/// Copy constructor
77
79 TIterator(other),
80 _hist(other._hist),
81 _sliceArg(other._sliceArg),
82 _baseIndex(other._baseIndex),
83 _stepSize(other._stepSize),
84 _nStep(other._nStep),
85 _curStep(other._curStep)
86{
87}
88
89
90
91////////////////////////////////////////////////////////////////////////////////
92/// Destructor
93
95{
96}
97
98
99
100////////////////////////////////////////////////////////////////////////////////
101/// Dummy
102
104{
105 return 0 ;
106}
107
108
109
110
111////////////////////////////////////////////////////////////////////////////////
112/// Iterator increment operator
113
115{
116 if (_curStep==_nStep) {
117 return 0 ;
118 }
119
120 // Select appropriate entry in RooDataHist
122
123 // Increment iterator position
124 _curStep++ ;
125
126 return _sliceArg ;
127}
128
129
130
131////////////////////////////////////////////////////////////////////////////////
132/// Reset iterator position to beginning
133
135{
136 _curStep=0 ;
137}
138
139
140
141////////////////////////////////////////////////////////////////////////////////
142/// Iterator dereference operator, not functional for this iterator
143
145{
146 Int_t step = _curStep == 0 ? _curStep : _curStep - 1;
147 // Select appropriate entry in RooDataHist
148 _hist->get(_baseIndex + step*_stepSize) ;
149
150 return _sliceArg ;
151}
152
153
154////////////////////////////////////////////////////////////////////////////////
155/// Returns true if position of this iterator differs from position
156/// of iterator 'aIter'
157
159{
160 if ((aIter.IsA() == RooDataHistSliceIter::Class())) {
161 const RooDataHistSliceIter &iter(dynamic_cast<const RooDataHistSliceIter &>(aIter));
162 return (_curStep != iter._curStep);
163 }
164
165 return false;
166}
void Class()
Definition: Class.C:29
int Int_t
Definition: RtypesCore.h:41
#define ClassImp(name)
Definition: Rtypes.h:365
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:70
Int_t getSize() const
RooAbsArg * find(const char *name) const
Find object with given name in list.
RooArgSet _vars
Definition: RooAbsData.h:260
Abstract base class for objects that are lvalues, i.e.
Definition: RooAbsLValue.h:26
virtual Int_t numBins(const char *rangeName=0) const =0
virtual void setBin(Int_t ibin, const char *rangeName=0)=0
RooDataHistSliceIter iterates over all bins in a RooDataHist that occur in a slice defined by the bin...
RooDataHistSliceIter(const RooDataHistSliceIter &other)
Copy constructor.
virtual ~RooDataHistSliceIter()
Destructor.
virtual TObject * Next()
Iterator increment operator.
virtual bool operator!=(const TIterator &aIter) const
Returns true if position of this iterator differs from position of iterator 'aIter'.
virtual void Reset()
Reset iterator position to beginning.
virtual const TCollection * GetCollection() const
Dummy.
virtual TObject * operator*() const
Iterator dereference operator, not functional for this iterator.
The RooDataHist is a container class to hold N-dimensional binned data.
Definition: RooDataHist.h:40
virtual const RooArgSet * get() const
Definition: RooDataHist.h:79
Int_t calcTreeIndex() const
Calculate the index for the weights array corresponding to to the bin enclosing the current coordinat...
std::vector< Int_t > _idxMult
Definition: RooDataHist.h:176
Collection abstract base class.
Definition: TCollection.h:63
Iterator abstract base class.
Definition: TIterator.h:30
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Mother of all ROOT objects.
Definition: TObject.h:37