Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
22Iterates over all bins in a RooDataHist that occur in a slice defined by the
23bin coordinates of the input sliceSet.
24**/
25
26#include "RooDataHist.h"
27#include "RooArgSet.h"
28#include "RooAbsLValue.h"
30
32
33////////////////////////////////////////////////////////////////////////////////
34/// Construct an iterator over all bins of RooDataHist 'hist' in the slice defined
35/// by the values of the arguments in 'sliceArg'
36
37RooDataHistSliceIter::RooDataHistSliceIter(RooDataHist& hist, RooAbsArg& sliceArg) : _hist(&hist), _sliceArg(&sliceArg)
38{
39 // Calculate base index (for 0th bin) for slice
40 RooAbsArg* sliceArgInt = hist.get()->find(sliceArg.GetName()) ;
41 dynamic_cast<RooAbsLValue&>(*sliceArgInt).setBin(0) ;
42
43 if (hist._vars.size()>1) {
44 _baseIndex = hist.calcTreeIndex(hist._vars, true);
45 } else {
46 _baseIndex = 0 ;
47 }
48
49 _nStep = dynamic_cast<RooAbsLValue&>(*sliceArgInt).numBins() ;
50
51// cout << "RooDataHistSliceIter" << endl ;
52// hist.Print() ;
53// cout << "hist._iterator = " << hist._iterator << endl ;
54
55 Int_t i=0 ;
56 for (const auto arg : hist._vars) {
57 if (arg==sliceArgInt) break ;
58 i++ ;
59 }
60 _stepSize = hist._idxMult[i] ;
61 _curStep = 0 ;
62
63}
64
65
66
67////////////////////////////////////////////////////////////////////////////////
68/// Copy constructor
69
71 TIterator(other),
72 _hist(other._hist),
73 _sliceArg(other._sliceArg),
74 _baseIndex(other._baseIndex),
75 _stepSize(other._stepSize),
76 _nStep(other._nStep),
77 _curStep(other._curStep)
78{
79}
80
81
82
83////////////////////////////////////////////////////////////////////////////////
84/// Destructor
85
87{
88}
89
90
91
92////////////////////////////////////////////////////////////////////////////////
93/// Dummy
94
96{
97 return nullptr ;
98}
99
100
101
102
103////////////////////////////////////////////////////////////////////////////////
104/// Iterator increment operator
105
107{
108 if (_curStep==_nStep) {
109 return nullptr ;
110 }
111
112 // Select appropriate entry in RooDataHist
114
115 // Increment iterator position
116 _curStep++ ;
117
118 return _sliceArg ;
119}
120
121
122
123////////////////////////////////////////////////////////////////////////////////
124/// Reset iterator position to beginning
125
127{
128 _curStep=0 ;
129}
130
131
132
133////////////////////////////////////////////////////////////////////////////////
134/// Iterator dereference operator, not functional for this iterator
135
137{
138 Int_t step = _curStep == 0 ? _curStep : _curStep - 1;
139 // Select appropriate entry in RooDataHist
140 _hist->get(_baseIndex + step*_stepSize) ;
141
142 return _sliceArg ;
143}
144
145
146////////////////////////////////////////////////////////////////////////////////
147/// Returns true if position of this iterator differs from position
148/// of iterator 'aIter'
149
151{
152 if ((aIter.IsA() == RooDataHistSliceIter::Class())) {
153 const RooDataHistSliceIter &iter(dynamic_cast<const RooDataHistSliceIter &>(aIter));
154 return (_curStep != iter._curStep);
155 }
156
157 return false;
158}
#define ClassImp(name)
Definition Rtypes.h:382
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:77
Storage_t::size_type size() const
RooAbsArg * find(const char *name) const
Find object with given name in list.
RooArgSet _vars
Dimensions of this data set.
Definition RooAbsData.h:350
Abstract base class for objects that are lvalues, i.e.
virtual Int_t numBins(const char *rangeName=nullptr) const =0
virtual void setBin(Int_t ibin, const char *rangeName=nullptr)=0
Iterates over all bins in a RooDataHist that occur in a slice defined by the bin coordinates of the i...
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.
Container class to hold N-dimensional binned data.
Definition RooDataHist.h:40
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
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:41