RooTreeDataStore.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  *    File: $Id: RooTreeDataStore.h 34064 2010-06-22 15:05:19Z 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 #ifndef ROO_TREE_DATA_STORE
00017 #define ROO_TREE_DATA_STORE
00018 
00019 #include "RooAbsDataStore.h" 
00020 #include "TString.h"
00021 
00022 class RooAbsArg ;
00023 class RooArgList ;
00024 class TTree ;
00025 class RooFormulaVar ;
00026 class RooArgSet ;
00027 
00028 
00029 class RooTreeDataStore : public RooAbsDataStore {
00030 public:
00031 
00032   RooTreeDataStore() ; 
00033   RooTreeDataStore(TTree* t, const RooArgSet& vars, const char* wgtVarName=0) ; 
00034 
00035   // Empty ctor
00036   RooTreeDataStore(const char* name, const char* title, const RooArgSet& vars, const char* wgtVarName=0) ;
00037   virtual RooAbsDataStore* clone(const RooArgSet& vars, const char* newname=0) const { return new RooTreeDataStore(*this,vars,newname) ; }
00038 
00039   // Ctors from TTree
00040   RooTreeDataStore(const char* name, const char* title, const RooArgSet& vars, TTree& t, const RooFormulaVar& select, const char* wgtVarName=0) ; 
00041   RooTreeDataStore(const char* name, const char* title, const RooArgSet& vars, TTree& t, const char* selExpr=0, const char* wgtVarName=0) ; 
00042 
00043   // Ctors from DataStore
00044   RooTreeDataStore(const char* name, const char* title, const RooArgSet& vars, const RooAbsDataStore& tds, const RooFormulaVar& select, const char* wgtVarName=0) ;
00045   RooTreeDataStore(const char* name, const char* title, const RooArgSet& vars, const RooAbsDataStore& tds, const char* selExpr=0, const char* wgtVarName=0) ;
00046 
00047   RooTreeDataStore(const char *name, const char *title, RooAbsDataStore& tds, 
00048                    const RooArgSet& vars, const RooFormulaVar* cutVar, const char* cutRange,
00049                    Int_t nStart, Int_t nStop, Bool_t /*copyCache*/, const char* wgtVarName=0) ;
00050 
00051   RooTreeDataStore(const RooTreeDataStore& other, const char* newname=0) ;
00052   RooTreeDataStore(const RooTreeDataStore& other, const RooArgSet& vars, const char* newname=0) ;
00053   virtual ~RooTreeDataStore() ;
00054 
00055 
00056   // Write current row
00057   virtual Int_t fill() ;
00058 
00059   // Retrieve a row
00060   using RooAbsDataStore::get ;
00061   virtual const RooArgSet* get(Int_t index) const ;
00062   virtual Double_t weight() const ;
00063   virtual Double_t weightError(RooAbsData::ErrorType etype=RooAbsData::Poisson) const ;
00064   virtual void weightError(Double_t& lo, Double_t& hi, RooAbsData::ErrorType etype=RooAbsData::Poisson) const ; 
00065   virtual Double_t weight(Int_t index) const ;
00066   virtual Bool_t isWeighted() const { return (_wgtVar!=0||_extWgtArray!=0) ; }
00067 
00068   // Change observable name
00069   virtual Bool_t changeObservableName(const char* from, const char* to) ;
00070   
00071   // Add one or more columns
00072   virtual RooAbsArg* addColumn(RooAbsArg& var, Bool_t adjustRange=kTRUE) ;
00073   virtual RooArgSet* addColumns(const RooArgList& varList) ;
00074 
00075   // Merge column-wise
00076   RooAbsDataStore* merge(const RooArgSet& allvars, std::list<RooAbsDataStore*> dstoreList) ;
00077 
00078   // Add rows 
00079   virtual void append(RooAbsDataStore& other) ;
00080 
00081   // General & bookkeeping methods
00082   virtual Bool_t valid() const ;
00083   virtual Int_t numEntries() const ;
00084   virtual void reset() ;
00085   
00086   // Tree access
00087   TTree& tree() { return *_tree ; }
00088   virtual const TTree* tree() const { return _tree ; }  
00089 
00090   // Forwarded from TTree
00091   Stat_t GetEntries() const;
00092   void Reset(Option_t* option=0);
00093   Int_t Fill();
00094   Int_t GetEntry(Int_t entry = 0, Int_t getall = 0);
00095 
00096   void  Draw(Option_t* option = "") ;
00097 
00098   // Constant term  optimizer interface
00099   virtual void cacheArgs(const RooAbsArg* owner, RooArgSet& varSet, const RooArgSet* nset=0) ;
00100   virtual const RooAbsArg* cacheOwner() { return _cacheOwner ; }
00101   virtual void setArgStatus(const RooArgSet& set, Bool_t active) ;
00102   virtual void resetCache() ;
00103 
00104   void loadValues(const TTree *t, const RooFormulaVar* select=0, const char* rangeName=0, Int_t nStart=0, Int_t nStop=2000000000)  ;
00105   void loadValues(const RooAbsDataStore *tds, const RooFormulaVar* select=0, const char* rangeName=0, Int_t nStart=0, Int_t nStop=2000000000)  ;
00106 
00107   virtual void checkInit() const;
00108 
00109   void setExternalWeightArray(Double_t* arrayWgt, Double_t* arrayWgtErrLo, Double_t* arrayWgtErrHi, Double_t* arraySumW2) { 
00110     _extWgtArray = arrayWgt ; 
00111     _extWgtErrLoArray = arrayWgtErrLo ;
00112     _extWgtErrHiArray = arrayWgtErrHi ;
00113     _extSumW2Array = arraySumW2 ;
00114   }
00115   
00116   const RooArgSet& row() { return _varsww ; }
00117 
00118  protected:
00119 
00120   RooArgSet varsNoWeight(const RooArgSet& allVars, const char* wgtName=0) ;
00121   RooRealVar* weightVar(const RooArgSet& allVars, const char* wgtName=0) ;
00122 
00123   void initialize();
00124   void attachCache(const RooAbsArg* newOwner, const RooArgSet& cachedVars) ;
00125 
00126   // TTree Branch buffer size control
00127   void setBranchBufferSize(Int_t size) { _defTreeBufSize = size ; }
00128   Int_t getBranchBufferSize() const { return _defTreeBufSize ; }
00129 
00130   static Int_t _defTreeBufSize ;  
00131 
00132   void createTree(const char* name, const char* title) ; 
00133   TTree *_tree ;           // TTree holding the data points
00134   TTree *_cacheTree ;      //! TTree holding the cached function values
00135   const RooAbsArg* _cacheOwner ; //! Object owning cache contents
00136   mutable Bool_t _defCtor ;//! Was object constructed with default ctor?
00137 
00138   RooArgSet _varsww ;
00139   RooRealVar* _wgtVar ;     // Pointer to weight variable (if set)
00140 
00141   Double_t* _extWgtArray ;         //! External weight array
00142   Double_t* _extWgtErrLoArray ;    //! External weight array - low error
00143   Double_t* _extWgtErrHiArray ;    //! External weight array - high error
00144   Double_t* _extSumW2Array ;       //! External sum of weights array
00145 
00146   mutable Double_t  _curWgt ;      // Weight of current event
00147   mutable Double_t  _curWgtErrLo ; // Weight of current event
00148   mutable Double_t  _curWgtErrHi ; // Weight of current event
00149   mutable Double_t  _curWgtErr ;   // Weight of current event
00150 
00151   ClassDef(RooTreeDataStore,2) // TTree-based Data Storage class
00152 };
00153 
00154 
00155 #endif

Generated on Tue Jul 5 14:26:28 2011 for ROOT_528-00b_version by  doxygen 1.5.1