Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
36 ClassImp(RooDataHistSliceIter);
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 
78 RooDataHistSliceIter::RooDataHistSliceIter(const RooDataHistSliceIter& other) :
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 
94 RooDataHistSliceIter::~RooDataHistSliceIter()
95 {
96 }
97 
98 
99 
100 ////////////////////////////////////////////////////////////////////////////////
101 /// Dummy
102 
103 const TCollection* RooDataHistSliceIter::GetCollection() const
104 {
105  return 0 ;
106 }
107 
108 
109 
110 
111 ////////////////////////////////////////////////////////////////////////////////
112 /// Iterator increment operator
113 
114 TObject* RooDataHistSliceIter::Next()
115 {
116  if (_curStep==_nStep) {
117  return 0 ;
118  }
119 
120  // Select appropriate entry in RooDataHist
121  _hist->get(_baseIndex + _curStep*_stepSize) ;
122 
123  // Increment iterator position
124  _curStep++ ;
125 
126  return _sliceArg ;
127 }
128 
129 
130 
131 ////////////////////////////////////////////////////////////////////////////////
132 /// Reset iterator position to beginning
133 
134 void RooDataHistSliceIter::Reset()
135 {
136  _curStep=0 ;
137 }
138 
139 
140 
141 ////////////////////////////////////////////////////////////////////////////////
142 /// Iterator dereference operator, not functional for this iterator
143 
144 TObject *RooDataHistSliceIter::operator*() const
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 
158 bool RooDataHistSliceIter::operator!=(const TIterator &aIter) const
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 }