Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
RooAbsTestStatistic.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * File: $Id: RooAbsGoodnessOfFit.h,v 1.15 2007/05/11 09:11:30 verkerke Exp $
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 #ifndef ROO_ABS_TEST_STATISTIC
17 #define ROO_ABS_TEST_STATISTIC
18 
19 #include "RooAbsReal.h"
20 #include "RooSetProxy.h"
21 #include "RooRealProxy.h"
22 #include "TStopwatch.h"
23 #include <string>
24 
25 class RooArgSet ;
26 class RooAbsData ;
27 class RooAbsReal ;
28 class RooSimultaneous ;
29 class RooRealMPFE ;
30 
31 class RooAbsTestStatistic ;
32 typedef RooAbsTestStatistic* pRooAbsTestStatistic ;
33 typedef RooAbsData* pRooAbsData ;
34 typedef RooRealMPFE* pRooRealMPFE ;
35 
36 class RooAbsTestStatistic : public RooAbsReal {
37  friend class RooRealMPFE;
38 public:
39 
40  // Constructors, assignment etc
41  RooAbsTestStatistic() ;
42  RooAbsTestStatistic(const char *name, const char *title, RooAbsReal& real, RooAbsData& data,
43  const RooArgSet& projDeps, const char* rangeName=0, const char* addCoefRangeName=0,
44  Int_t nCPU=1, RooFit::MPSplit interleave=RooFit::BulkPartition, Bool_t verbose=kTRUE, Bool_t splitCutRange=kTRUE) ;
45  RooAbsTestStatistic(const RooAbsTestStatistic& other, const char* name=0);
46  virtual ~RooAbsTestStatistic();
47  virtual RooAbsTestStatistic* create(const char *name, const char *title, RooAbsReal& real, RooAbsData& data,
48  const RooArgSet& projDeps, const char* rangeName=0, const char* addCoefRangeName=0,
49  Int_t nCPU=1, RooFit::MPSplit interleave=RooFit::BulkPartition, Bool_t verbose=kTRUE, Bool_t splitCutRange=kFALSE, Bool_t binnedL=kFALSE) = 0 ;
50 
51  virtual void constOptimizeTestStatistic(ConstOpCode opcode, Bool_t doAlsoTrackingOpt=kTRUE) ;
52 
53  virtual Double_t combinedValue(RooAbsReal** gofArray, Int_t nVal) const = 0 ;
54  virtual Double_t globalNormalization() const {
55  // Default value of global normalization factor is 1.0
56  return 1.0 ;
57  }
58 
59  Bool_t setData(RooAbsData& data, Bool_t cloneData=kTRUE) ;
60 
61  void enableOffsetting(Bool_t flag) ;
62  Bool_t isOffsetting() const { return _doOffset ; }
63  virtual Double_t offset() const { return _offset ; }
64  virtual Double_t offsetCarry() const { return _offsetCarry; }
65 
66 protected:
67 
68  virtual void printCompactTreeHook(std::ostream& os, const char* indent="") ;
69 
70  virtual Bool_t redirectServersHook(const RooAbsCollection& newServerList, Bool_t mustReplaceAll, Bool_t nameChange, Bool_t isRecursive) ;
71  virtual Double_t evaluate() const ;
72 
73  virtual Double_t evaluatePartition(std::size_t firstEvent, std::size_t lastEvent, std::size_t stepSize) const = 0 ;
74  virtual Double_t getCarry() const;
75 
76  void setMPSet(Int_t setNum, Int_t numSets) ;
77  void setSimCount(Int_t simCount) {
78  // Store total number of components p.d.f. of a RooSimultaneous in this component test statistic
79  _simCount = simCount ;
80  }
81 
82  void setEventCount(Int_t nEvents) {
83  // Store total number of events in this component test statistic
84  _nEvents = nEvents ;
85  }
86 
87  Int_t numSets() const {
88  // Return total number of sets for parallel calculation
89  return _numSets ;
90  }
91  Int_t setNum() const {
92  // Return parallel calculation set number for this instance
93  return _setNum ;
94  }
95 
96  RooSetProxy _paramSet ; // Parameters of the test statistic (=parameters of the input function)
97 
98  enum GOFOpMode { SimMaster,MPMaster,Slave } ;
99  GOFOpMode operMode() const {
100  // Return test statistic operation mode of this instance (SimMaster, MPMaster or Slave)
101  return _gofOpMode ;
102  }
103 
104  // Original arguments
105  RooAbsReal* _func ; // Pointer to original input function
106  RooAbsData* _data ; // Pointer to original input dataset
107  const RooArgSet* _projDeps ; // Pointer to set with projected observables
108  std::string _rangeName ; // Name of range in which to calculate test statistic
109  std::string _addCoefRangeName ; // Name of reference to be used for RooAddPdf components
110  Bool_t _splitRange ; // Split rangeName in RooSimultaneous index labels if true
111  Int_t _simCount ; // Total number of component p.d.f.s in RooSimultaneous (if any)
112  Bool_t _verbose ; // Verbose messaging if true
113 
114  virtual Bool_t setDataSlave(RooAbsData& /*data*/, Bool_t /*cloneData*/=kTRUE, Bool_t /*ownNewDataAnyway*/=kFALSE) { return kTRUE ; }
115 
116  //private:
117 
118 
119  virtual Bool_t processEmptyDataSets() const { return kTRUE ; }
120 
121  Bool_t initialize() ;
122  void initSimMode(RooSimultaneous* pdf, RooAbsData* data, const RooArgSet* projDeps, const char* rangeName, const char* addCoefRangeName) ;
123  void initMPMode(RooAbsReal* real, RooAbsData* data, const RooArgSet* projDeps, const char* rangeName, const char* addCoefRangeName) ;
124 
125  mutable Bool_t _init ; //! Is object initialized
126  GOFOpMode _gofOpMode ; // Operation mode of test statistic instance
127 
128  Int_t _nEvents ; // Total number of events in test statistic calculation
129  Int_t _setNum ; // Partition number of this instance in parallel calculation mode
130  Int_t _numSets ; // Total number of partitions in parallel calculation mode
131  Int_t _extSet ; //! Number of designated set to calculated extended term
132 
133  // Simultaneous mode data
134  Int_t _nGof ; // Number of sub-contexts
135  pRooAbsTestStatistic* _gofArray ; //! Array of sub-contexts representing part of the combined test statistic
136  std::vector<RooFit::MPSplit> _gofSplitMode ; //! GOF MP Split mode specified by component (when Auto is active)
137 
138  // Parallel mode data
139  Int_t _nCPU ; // Number of processors to use in parallel calculation mode
140  pRooRealMPFE* _mpfeArray ; //! Array of parallel execution frond ends
141 
142  RooFit::MPSplit _mpinterl ; // Use interleaving strategy rather than N-wise split for partioning of dataset for multiprocessor-split
143  Bool_t _doOffset ; // Apply interval value offset to control numeric precision?
144  mutable Double_t _offset ; //! Offset
145  mutable Double_t _offsetCarry; //! avoids loss of precision
146  mutable Double_t _evalCarry; //! carry of Kahan sum in evaluatePartition
147 
148  ClassDef(RooAbsTestStatistic,2) // Abstract base class for real-valued test statistics
149 
150 };
151 
152 #endif