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 
22 RooDataHistSliceIter iterates over all bins in a RooDataHist that
23 occur in a slice defined by the bin coordinates of the input
24 sliceSet.
25 **/
26 
27 #include "RooFit.h"
28 
29 #include "RooDataHist.h"
30 #include "RooArgSet.h"
31 #include "RooAbsLValue.h"
32 #include "RooDataHistSliceIter.h"
33 
34 using 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 
45 RooDataHistSliceIter::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 }
RooDataHistSliceIter::RooDataHistSliceIter
RooDataHistSliceIter(const RooDataHistSliceIter &other)
Copy constructor.
Definition: RooDataHistSliceIter.cxx:78
RooFit.h
RooArgSet.h
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
RooAbsLValue::numBins
virtual Int_t numBins(const char *rangeName=0) const =0
RooDataHistSliceIter::operator!=
virtual bool operator!=(const TIterator &aIter) const
Returns true if position of this iterator differs from position of iterator 'aIter'.
Definition: RooDataHistSliceIter.cxx:158
RooDataHist::get
virtual const RooArgSet * get() const
Definition: RooDataHist.h:78
RooDataHistSliceIter::_curStep
Int_t _curStep
Definition: RooDataHistSliceIter.h:48
RooAbsCollection::find
RooAbsArg * find(const char *name) const
Find object with given name in list.
Definition: RooAbsCollection.cxx:813
RooDataHistSliceIter
Definition: RooDataHistSliceIter.h:26
RooDataHistSliceIter::_sliceArg
RooAbsArg * _sliceArg
Definition: RooDataHistSliceIter.h:44
RooDataHistSliceIter::_stepSize
Int_t _stepSize
Definition: RooDataHistSliceIter.h:46
RooDataHistSliceIter.h
RooDataHistSliceIter::_hist
RooDataHist * _hist
Definition: RooDataHistSliceIter.h:43
RooDataHistSliceIter::operator*
virtual TObject * operator*() const
Iterator dereference operator, not functional for this iterator.
Definition: RooDataHistSliceIter.cxx:144
TIterator
Definition: TIterator.h:30
RooDataHistSliceIter::~RooDataHistSliceIter
virtual ~RooDataHistSliceIter()
Destructor.
Definition: RooDataHistSliceIter.cxx:94
RooDataHistSliceIter::GetCollection
virtual const TCollection * GetCollection() const
Dummy.
Definition: RooDataHistSliceIter.cxx:103
RooAbsLValue.h
RooDataHist::_idxMult
std::vector< Int_t > _idxMult
Definition: RooDataHist.h:183
RooDataHistSliceIter::_baseIndex
Int_t _baseIndex
Definition: RooDataHistSliceIter.h:45
RooAbsData::_vars
RooArgSet _vars
Definition: RooAbsData.h:275
RooDataHist::calcTreeIndex
Int_t calcTreeIndex() const
Calculate the index for the weights array corresponding to to the bin enclosing the current coordinat...
Definition: RooDataHist.cxx:980
RooDataHist
Definition: RooDataHist.h:39
RooDataHistSliceIter::Reset
virtual void Reset()
Reset iterator position to beginning.
Definition: RooDataHistSliceIter.cxx:134
RooDataHist.h
RooDataHistSliceIter::_nStep
Int_t _nStep
Definition: RooDataHistSliceIter.h:47
RooAbsLValue::setBin
virtual void setBin(Int_t ibin, const char *rangeName=0)=0
RooDataHistSliceIter::Next
virtual TObject * Next()
Iterator increment operator.
Definition: RooDataHistSliceIter.cxx:114
TObject
Definition: TObject.h:37
RooAbsArg
Definition: RooAbsArg.h:73
TCollection
Definition: TCollection.h:63
RooAbsLValue
Definition: RooAbsLValue.h:26
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:53
Class
void Class()
Definition: Class.C:29
RooAbsCollection::getSize
Int_t getSize() const
Definition: RooAbsCollection.h:171
int