Logo ROOT  
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 "RooDataHist.h"
28#include "RooArgSet.h"
29#include "RooAbsLValue.h"
31
32using namespace std;
33
35;
36
37
38
39////////////////////////////////////////////////////////////////////////////////
40/// Construct an iterator over all bins of RooDataHist 'hist' in the slice defined
41/// by the values of the arguments in 'sliceArg'
42
43RooDataHistSliceIter::RooDataHistSliceIter(RooDataHist& hist, RooAbsArg& sliceArg) : _hist(&hist), _sliceArg(&sliceArg)
44{
45 // Calculate base index (for 0th bin) for slice
46 RooAbsArg* sliceArgInt = hist.get()->find(sliceArg.GetName()) ;
47 dynamic_cast<RooAbsLValue&>(*sliceArgInt).setBin(0) ;
48
49 if (hist._vars.getSize()>1) {
50 _baseIndex = hist.calcTreeIndex(hist._vars, true);
51 } else {
52 _baseIndex = 0 ;
53 }
54
55 _nStep = dynamic_cast<RooAbsLValue&>(*sliceArgInt).numBins() ;
56
57// cout << "RooDataHistSliceIter" << endl ;
58// hist.Print() ;
59// cout << "hist._iterator = " << hist._iterator << endl ;
60
61 Int_t i=0 ;
62 for (const auto arg : hist._vars) {
63 if (arg==sliceArgInt) break ;
64 i++ ;
65 }
66 _stepSize = hist._idxMult[i] ;
67 _curStep = 0 ;
68
69}
70
71
72
73////////////////////////////////////////////////////////////////////////////////
74/// Copy constructor
75
77 TIterator(other),
78 _hist(other._hist),
79 _sliceArg(other._sliceArg),
80 _baseIndex(other._baseIndex),
81 _stepSize(other._stepSize),
82 _nStep(other._nStep),
83 _curStep(other._curStep)
84{
85}
86
87
88
89////////////////////////////////////////////////////////////////////////////////
90/// Destructor
91
93{
94}
95
96
97
98////////////////////////////////////////////////////////////////////////////////
99/// Dummy
100
102{
103 return 0 ;
104}
105
106
107
108
109////////////////////////////////////////////////////////////////////////////////
110/// Iterator increment operator
111
113{
114 if (_curStep==_nStep) {
115 return 0 ;
116 }
117
118 // Select appropriate entry in RooDataHist
120
121 // Increment iterator position
122 _curStep++ ;
123
124 return _sliceArg ;
125}
126
127
128
129////////////////////////////////////////////////////////////////////////////////
130/// Reset iterator position to beginning
131
133{
134 _curStep=0 ;
135}
136
137
138
139////////////////////////////////////////////////////////////////////////////////
140/// Iterator dereference operator, not functional for this iterator
141
143{
144 Int_t step = _curStep == 0 ? _curStep : _curStep - 1;
145 // Select appropriate entry in RooDataHist
146 _hist->get(_baseIndex + step*_stepSize) ;
147
148 return _sliceArg ;
149}
150
151
152////////////////////////////////////////////////////////////////////////////////
153/// Returns true if position of this iterator differs from position
154/// of iterator 'aIter'
155
157{
158 if ((aIter.IsA() == RooDataHistSliceIter::Class())) {
159 const RooDataHistSliceIter &iter(dynamic_cast<const RooDataHistSliceIter &>(aIter));
160 return (_curStep != iter._curStep);
161 }
162
163 return false;
164}
#define ClassImp(name)
Definition: Rtypes.h:375
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:71
Int_t getSize() const
Return the number of elements in the collection.
RooAbsArg * find(const char *name) const
Find object with given name in list.
RooArgSet _vars
Dimensions of this data set.
Definition: RooAbsData.h:362
Abstract base class for objects that are lvalues, i.e.
Definition: RooAbsLValue.h:26
virtual Int_t numBins(const char *rangeName=nullptr) const =0
virtual void setBin(Int_t ibin, const char *rangeName=nullptr)=0
RooDataHistSliceIter iterates over all bins in a RooDataHist that occur in a slice defined by the bin...
RooDataHistSliceIter(const RooDataHistSliceIter &other)
Copy constructor.
~RooDataHistSliceIter() override
Destructor.
TObject * Next() override
Iterator increment operator.
void Reset() override
Reset iterator position to beginning.
const TCollection * GetCollection() const override
Dummy.
static TClass * Class()
bool operator!=(const TIterator &aIter) const override
Returns true if position of this iterator differs from position of iterator 'aIter'.
TObject * operator*() const override
Iterator dereference operator, not functional for this iterator.
The RooDataHist is a container class to hold N-dimensional binned data.
Definition: RooDataHist.h:45
std::size_t calcTreeIndex(const RooAbsCollection &coords, bool fast) const
Calculate the bin index corresponding to the coordinates passed as argument.
std::vector< Int_t > _idxMult
Definition: RooDataHist.h:262
const RooArgSet * get() const override
Get bin centre of current bin.
Definition: RooDataHist.h:82
Collection abstract base class.
Definition: TCollection.h:65
Iterator abstract base class.
Definition: TIterator.h:30
virtual TClass * IsA() const
Definition: TIterator.h:48
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47
Mother of all ROOT objects.
Definition: TObject.h:37