RooDataHistSliceIter.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooDataHistSliceIter.cxx 36209 2010-10-08 21:37:36Z wouter $
00005  * Authors:                                                                  *
00006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
00007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
00008  *                                                                           *
00009  * Copyright (c) 2000-2005, Regents of the University of California          *
00010  *                          and Stanford University. All rights reserved.    *
00011  *                                                                           *
00012  * Redistribution and use in source and binary forms,                        *
00013  * with or without modification, are permitted according to the terms        *
00014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
00015  *****************************************************************************/
00016 
00017 //////////////////////////////////////////////////////////////////////////////
00018 // 
00019 // BEGIN_HTML
00020 // RooDataHistSliceIter iterates over all bins in a RooDataHist that
00021 // occur in a slice defined by the bin coordinates of the input
00022 // sliceSet.
00023 // END_HTML
00024 //
00025 
00026 #include "RooFit.h"
00027 
00028 #if ROOT_VERSION_CODE <= ROOT_VERSION(5,19,04)
00029 #ifndef nullptr
00030 #define nullptr 0
00031 #endif
00032 #endif
00033 
00034 #include "RooDataHist.h"
00035 #include "RooArgSet.h"
00036 #include "RooAbsLValue.h"
00037 #include "RooDataHistSliceIter.h"
00038 
00039 ClassImp(RooDataHistSliceIter)
00040 ;
00041 
00042 
00043 
00044 //_____________________________________________________________________________
00045 RooDataHistSliceIter::RooDataHistSliceIter(RooDataHist& hist, RooAbsArg& sliceArg) : _hist(&hist), _sliceArg(&sliceArg)
00046 {
00047   // Construct an iterator over all bins of RooDataHist 'hist' in the slice defined
00048   // by the values of the arguments in 'sliceArg'
00049 
00050   // Calculate base index (for 0th bin) for slice    
00051   RooAbsArg* sliceArgInt = hist.get()->find(sliceArg.GetName()) ;
00052   dynamic_cast<RooAbsLValue&>(*sliceArgInt).setBin(0) ;
00053 
00054   if (hist._vars.getSize()>1) {
00055     _baseIndex = hist.calcTreeIndex() ;  
00056   } else {
00057     _baseIndex = 0 ;
00058   }
00059 
00060   _nStep = dynamic_cast<RooAbsLValue&>(*sliceArgInt).numBins() ;
00061 
00062   hist._iterator->Reset() ;
00063   RooAbsArg* arg ;
00064   Int_t i=0 ;
00065   while((arg=(RooAbsArg*)hist._iterator->Next())) {
00066     if (arg==sliceArgInt) break ;
00067     i++ ;
00068   }
00069   _stepSize = hist._idxMult[i] ;  
00070   _curStep = 0 ;  
00071 
00072 }
00073 
00074 
00075 
00076 //_____________________________________________________________________________
00077 RooDataHistSliceIter::RooDataHistSliceIter(const RooDataHistSliceIter& other) : 
00078   TIterator(other), 
00079   _hist(other._hist), 
00080   _sliceArg(other._sliceArg),   
00081   _baseIndex(other._baseIndex),
00082   _stepSize(other._stepSize),
00083   _nStep(other._nStep), 
00084   _curStep(other._curStep)
00085 {
00086   // Copy constructor
00087 }
00088 
00089 
00090 
00091 //_____________________________________________________________________________
00092 RooDataHistSliceIter::~RooDataHistSliceIter() 
00093 {
00094   // Destructor
00095 }
00096 
00097 
00098 
00099 //_____________________________________________________________________________
00100 const TCollection* RooDataHistSliceIter::GetCollection() const 
00101 {
00102   // Dummy
00103   return 0 ;
00104 }
00105 
00106 
00107 
00108 
00109 //_____________________________________________________________________________
00110 TObject* RooDataHistSliceIter::Next() 
00111 {  
00112   // Iterator increment operator
00113 
00114   if (_curStep==_nStep) {
00115     return 0 ;
00116   }
00117   
00118   // Select appropriate entry in RooDataHist 
00119   _hist->get(_baseIndex + _curStep*_stepSize) ;
00120 
00121   // Increment iterator position 
00122   _curStep++ ;
00123 
00124   return _sliceArg ;
00125 }
00126 
00127 
00128 
00129 //_____________________________________________________________________________
00130 void RooDataHistSliceIter::Reset() 
00131 {
00132   // Reset iterator position to beginning
00133   _curStep=0 ;
00134 }
00135 
00136 
00137 
00138 //_____________________________________________________________________________
00139 TObject *RooDataHistSliceIter::operator*() const
00140 {
00141   // Iterator dereference operator, not functional for this iterator
00142 
00143    Int_t step = _curStep == 0 ? _curStep : _curStep - 1;
00144    // Select appropriate entry in RooDataHist 
00145    _hist->get(_baseIndex + step*_stepSize) ;
00146 
00147    return _sliceArg ;
00148 }
00149 
00150 
00151 //_____________________________________________________________________________
00152 bool RooDataHistSliceIter::operator!=(const TIterator &aIter) const
00153 {
00154   // Returns true if position of this iterator differs from position
00155   // of iterator 'aIter'
00156 
00157    if (nullptr == &aIter)
00158       return false;
00159 
00160    if ((aIter.IsA() == RooDataHistSliceIter::Class())) {
00161       const RooDataHistSliceIter &iter(dynamic_cast<const RooDataHistSliceIter &>(aIter));
00162       return (_curStep != iter._curStep);
00163    }
00164    
00165    return false;
00166 }

Generated on Tue Jul 5 15:06:27 2011 for ROOT_528-00b_version by  doxygen 1.5.1