Logo ROOT   6.08/07
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 #if ROOT_VERSION_CODE <= ROOT_VERSION(5,19,04)
30 #ifndef nullptr
31 #define nullptr 0
32 #endif
33 #endif
34 
35 #include "RooDataHist.h"
36 #include "RooArgSet.h"
37 #include "RooAbsLValue.h"
38 #include "RooDataHistSliceIter.h"
39 
40 using namespace std;
41 
43 ;
44 
45 
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 /// Construct an iterator over all bins of RooDataHist 'hist' in the slice defined
49 /// by the values of the arguments in 'sliceArg'
50 
51 RooDataHistSliceIter::RooDataHistSliceIter(RooDataHist& hist, RooAbsArg& sliceArg) : _hist(&hist), _sliceArg(&sliceArg)
52 {
53  // Calculate base index (for 0th bin) for slice
54  RooAbsArg* sliceArgInt = hist.get()->find(sliceArg.GetName()) ;
55  dynamic_cast<RooAbsLValue&>(*sliceArgInt).setBin(0) ;
56 
57  if (hist._vars.getSize()>1) {
58  _baseIndex = hist.calcTreeIndex() ;
59  } else {
60  _baseIndex = 0 ;
61  }
62 
63  _nStep = dynamic_cast<RooAbsLValue&>(*sliceArgInt).numBins() ;
64 
65 // cout << "RooDataHistSliceIter" << endl ;
66 // hist.Print() ;
67 // cout << "hist._iterator = " << hist._iterator << endl ;
68 
69  hist._iterator->Reset() ;
70  RooAbsArg* arg ;
71  Int_t i=0 ;
72  while((arg=(RooAbsArg*)hist._iterator->Next())) {
73  if (arg==sliceArgInt) break ;
74  i++ ;
75  }
76  _stepSize = hist._idxMult[i] ;
77  _curStep = 0 ;
78 
79 }
80 
81 
82 
83 ////////////////////////////////////////////////////////////////////////////////
84 /// Copy constructor
85 
87  TIterator(other),
88  _hist(other._hist),
89  _sliceArg(other._sliceArg),
90  _baseIndex(other._baseIndex),
91  _stepSize(other._stepSize),
92  _nStep(other._nStep),
93  _curStep(other._curStep)
94 {
95 }
96 
97 
98 
99 ////////////////////////////////////////////////////////////////////////////////
100 /// Destructor
101 
103 {
104 }
105 
106 
107 
108 ////////////////////////////////////////////////////////////////////////////////
109 /// Dummy
110 
112 {
113  return 0 ;
114 }
115 
116 
117 
118 
119 ////////////////////////////////////////////////////////////////////////////////
120 /// Iterator increment operator
121 
123 {
124  if (_curStep==_nStep) {
125  return 0 ;
126  }
127 
128  // Select appropriate entry in RooDataHist
130 
131  // Increment iterator position
132  _curStep++ ;
133 
134  return _sliceArg ;
135 }
136 
137 
138 
139 ////////////////////////////////////////////////////////////////////////////////
140 /// Reset iterator position to beginning
141 
143 {
144  _curStep=0 ;
145 }
146 
147 
148 
149 ////////////////////////////////////////////////////////////////////////////////
150 /// Iterator dereference operator, not functional for this iterator
151 
153 {
154  Int_t step = _curStep == 0 ? _curStep : _curStep - 1;
155  // Select appropriate entry in RooDataHist
156  _hist->get(_baseIndex + step*_stepSize) ;
157 
158  return _sliceArg ;
159 }
160 
161 
162 ////////////////////////////////////////////////////////////////////////////////
163 /// Returns true if position of this iterator differs from position
164 /// of iterator 'aIter'
165 
167 {
168  if ((aIter.IsA() == RooDataHistSliceIter::Class())) {
169  const RooDataHistSliceIter &iter(dynamic_cast<const RooDataHistSliceIter &>(aIter));
170  return (_curStep != iter._curStep);
171  }
172 
173  return false;
174 }
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
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.
const char * Class
Definition: TXMLSetup.cxx:64
TIterator * _iterator
External variables cached with this data set.
Definition: RooAbsData.h:256
Iterator abstract base class.
Definition: TIterator.h:32
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
std::vector< Int_t > _idxMult
Definition: RooDataHist.h:163
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:48
#define ClassImp(name)
Definition: Rtypes.h:279
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:27
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:253
virtual void Reset()
Reset iterator position to beginning.
virtual ~RooDataHistSliceIter()
Destructor.
virtual Int_t numBins(const char *rangeName=0) const =0