Loading [MathJax]/extensions/tex2jax.js
ROOT  6.06/09
Reference Guide
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules 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 //
19 // BEGIN_HTML
20 // RooDataHistSliceIter iterates over all bins in a RooDataHist that
21 // occur in a slice defined by the bin coordinates of the input
22 // sliceSet.
23 // END_HTML
24 //
25 
26 #include "RooFit.h"
27 
28 #if ROOT_VERSION_CODE <= ROOT_VERSION(5,19,04)
29 #ifndef nullptr
30 #define nullptr 0
31 #endif
32 #endif
33 
34 #include "RooDataHist.h"
35 #include "RooArgSet.h"
36 #include "RooAbsLValue.h"
37 #include "RooDataHistSliceIter.h"
38 
39 using namespace std;
40 
42 ;
43 
44 
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// Construct an iterator over all bins of RooDataHist 'hist' in the slice defined
48 /// by the values of the arguments in 'sliceArg'
49 
50 RooDataHistSliceIter::RooDataHistSliceIter(RooDataHist& hist, RooAbsArg& sliceArg) : _hist(&hist), _sliceArg(&sliceArg)
51 {
52  // Calculate base index (for 0th bin) for slice
53  RooAbsArg* sliceArgInt = hist.get()->find(sliceArg.GetName()) ;
54  dynamic_cast<RooAbsLValue&>(*sliceArgInt).setBin(0) ;
55 
56  if (hist._vars.getSize()>1) {
57  _baseIndex = hist.calcTreeIndex() ;
58  } else {
59  _baseIndex = 0 ;
60  }
61 
62  _nStep = dynamic_cast<RooAbsLValue&>(*sliceArgInt).numBins() ;
63 
64 // cout << "RooDataHistSliceIter" << endl ;
65 // hist.Print() ;
66 // cout << "hist._iterator = " << hist._iterator << endl ;
67 
68  hist._iterator->Reset() ;
69  RooAbsArg* arg ;
70  Int_t i=0 ;
71  while((arg=(RooAbsArg*)hist._iterator->Next())) {
72  if (arg==sliceArgInt) break ;
73  i++ ;
74  }
75  _stepSize = hist._idxMult[i] ;
76  _curStep = 0 ;
77 
78 }
79 
80 
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Copy constructor
84 
86  TIterator(other),
87  _hist(other._hist),
88  _sliceArg(other._sliceArg),
89  _baseIndex(other._baseIndex),
90  _stepSize(other._stepSize),
91  _nStep(other._nStep),
92  _curStep(other._curStep)
93 {
94 }
95 
96 
97 
98 ////////////////////////////////////////////////////////////////////////////////
99 /// Destructor
100 
102 {
103 }
104 
105 
106 
107 ////////////////////////////////////////////////////////////////////////////////
108 /// Dummy
109 
111 {
112  return 0 ;
113 }
114 
115 
116 
117 
118 ////////////////////////////////////////////////////////////////////////////////
119 /// Iterator increment operator
120 
122 {
123  if (_curStep==_nStep) {
124  return 0 ;
125  }
126 
127  // Select appropriate entry in RooDataHist
129 
130  // Increment iterator position
131  _curStep++ ;
132 
133  return _sliceArg ;
134 }
135 
136 
137 
138 ////////////////////////////////////////////////////////////////////////////////
139 /// Reset iterator position to beginning
140 
142 {
143  _curStep=0 ;
144 }
145 
146 
147 
148 ////////////////////////////////////////////////////////////////////////////////
149 /// Iterator dereference operator, not functional for this iterator
150 
152 {
153  Int_t step = _curStep == 0 ? _curStep : _curStep - 1;
154  // Select appropriate entry in RooDataHist
155  _hist->get(_baseIndex + step*_stepSize) ;
156 
157  return _sliceArg ;
158 }
159 
160 
161 ////////////////////////////////////////////////////////////////////////////////
162 /// Returns true if position of this iterator differs from position
163 /// of iterator 'aIter'
164 
166 {
167  if ((aIter.IsA() == RooDataHistSliceIter::Class())) {
168  const RooDataHistSliceIter &iter(dynamic_cast<const RooDataHistSliceIter &>(aIter));
169  return (_curStep != iter._curStep);
170  }
171 
172  return false;
173 }
virtual void Reset()=0
ClassImp(RooDataHistSliceIter)
int Int_t
Definition: RtypesCore.h:41
STL namespace.
TIterator * _iterator
External variables cached with this data set.
Definition: RooAbsData.h:256
Iterator abstract base class.
Definition: TIterator.h:32
virtual const RooArgSet * get() const
Definition: RooDataHist.h:77
virtual TObject * Next()
Iterator increment operator.
void Class()
Definition: Class.C:29
std::vector< Int_t > _idxMult
Definition: RooDataHist.h:163
virtual TObject * operator*() const
Iterator dereference operator, not functional for this iterator.
std::map< std::string, std::string >::const_iterator iter
Definition: TAlienJob.cxx:54
virtual void setBin(Int_t ibin, const char *rangeName=0)=0
virtual bool operator!=(const TIterator &aIter) const
Returns true if position of this iterator differs from position of iterator 'aIter'.
RooAbsArg * find(const char *name) const
Find object with given name in list.
Collection abstract base class.
Definition: TCollection.h:48
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
Int_t calcTreeIndex() const
Calculate the index for the weights array corresponding to to the bin enclosing the current coordinat...
Mother of all ROOT objects.
Definition: TObject.h:58
RooDataHistSliceIter(const RooDataHistSliceIter &other)
Copy constructor.
virtual TObject * Next()=0
virtual const TCollection * GetCollection() const
Dummy.
Int_t getSize() const
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