Logo ROOT   6.14/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 
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  hist._iterator->Reset() ;
64  RooAbsArg* arg ;
65  Int_t i=0 ;
66  while((arg=(RooAbsArg*)hist._iterator->Next())) {
67  if (arg==sliceArgInt) break ;
68  i++ ;
69  }
70  _stepSize = hist._idxMult[i] ;
71  _curStep = 0 ;
72 
73 }
74 
75 
76 
77 ////////////////////////////////////////////////////////////////////////////////
78 /// Copy constructor
79 
81  TIterator(other),
82  _hist(other._hist),
83  _sliceArg(other._sliceArg),
84  _baseIndex(other._baseIndex),
85  _stepSize(other._stepSize),
86  _nStep(other._nStep),
87  _curStep(other._curStep)
88 {
89 }
90 
91 
92 
93 ////////////////////////////////////////////////////////////////////////////////
94 /// Destructor
95 
97 {
98 }
99 
100 
101 
102 ////////////////////////////////////////////////////////////////////////////////
103 /// Dummy
104 
106 {
107  return 0 ;
108 }
109 
110 
111 
112 
113 ////////////////////////////////////////////////////////////////////////////////
114 /// Iterator increment operator
115 
117 {
118  if (_curStep==_nStep) {
119  return 0 ;
120  }
121 
122  // Select appropriate entry in RooDataHist
124 
125  // Increment iterator position
126  _curStep++ ;
127 
128  return _sliceArg ;
129 }
130 
131 
132 
133 ////////////////////////////////////////////////////////////////////////////////
134 /// Reset iterator position to beginning
135 
137 {
138  _curStep=0 ;
139 }
140 
141 
142 
143 ////////////////////////////////////////////////////////////////////////////////
144 /// Iterator dereference operator, not functional for this iterator
145 
147 {
148  Int_t step = _curStep == 0 ? _curStep : _curStep - 1;
149  // Select appropriate entry in RooDataHist
150  _hist->get(_baseIndex + step*_stepSize) ;
151 
152  return _sliceArg ;
153 }
154 
155 
156 ////////////////////////////////////////////////////////////////////////////////
157 /// Returns true if position of this iterator differs from position
158 /// of iterator 'aIter'
159 
161 {
162  if ((aIter.IsA() == RooDataHistSliceIter::Class())) {
163  const RooDataHistSliceIter &iter(dynamic_cast<const RooDataHistSliceIter &>(aIter));
164  return (_curStep != iter._curStep);
165  }
166 
167  return false;
168 }
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
virtual const RooArgSet * get() const
Definition: RooDataHist.h:77
virtual void Reset()=0
virtual bool operator!=(const TIterator &aIter) const
Returns true if position of this iterator differs from position of iterator &#39;aIter&#39;.
int Int_t
Definition: RtypesCore.h:41
STL namespace.
TIterator * _iterator
External variables cached with this data set.
Definition: RooAbsData.h:260
Iterator abstract base class.
Definition: TIterator.h:30
virtual TObject * operator*() const
Iterator dereference operator, not functional for this iterator.
virtual const TCollection * GetCollection() const
Dummy.
virtual TObject * Next()
Iterator increment operator.
RooDataSet is a container class to hold N-dimensional binned data.
Definition: RooDataHist.h:40
void Class()
Definition: Class.C:29
std::vector< Int_t > _idxMult
Definition: RooDataHist.h:174
Int_t calcTreeIndex() const
Calculate the index for the weights array corresponding to to the bin enclosing the current coordinat...
virtual void setBin(Int_t ibin, const char *rangeName=0)=0
Int_t getSize() const
Collection abstract base class.
Definition: TCollection.h:63
#define ClassImp(name)
Definition: Rtypes.h:359
RooAbsArg * find(const char *name) const
Find object with given name in list.
Mother of all ROOT objects.
Definition: TObject.h:37
RooDataHistSliceIter(const RooDataHistSliceIter &other)
Copy constructor.
RooDataHistSliceIter iterates over all bins in a RooDataHist that occur in a slice defined by the bin...
virtual TObject * Next()=0
Abstract base class for objects that are lvalues, i.e.
Definition: RooAbsLValue.h:26
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
RooArgSet _vars
Definition: RooAbsData.h:257
virtual void Reset()
Reset iterator position to beginning.
virtual ~RooDataHistSliceIter()
Destructor.
virtual Int_t numBins(const char *rangeName=0) const =0