RooDataWeightedAverage.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooDataWeightedAverage.cxx 30378 2009-09-23 13:42:12Z 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 // Class RooDataWeightedAverage calculate a weighted
00021 // average of a function or p.d.f given a dataset with observable
00022 // values, i.e. DWA(f(x),D(x)) = sum_i f(x_i) where x_i is draw from
00023 // D(i). This class is an implementation of RooAbsOptTestStatistics 
00024 // can make use of the optimization and parallization infrastructure
00025 // of that base class. The main use of RooDataWeightedAverage is
00026 // to calculate curves in RooPlots that are added with ProjWData()
00027 // plot option.
00028 //
00029 // END_HTML
00030 //
00031 
00032 #include "RooFit.h"
00033 #include "Riostream.h"
00034 
00035 #include "RooDataWeightedAverage.h"
00036 #include "RooAbsData.h"
00037 #include "RooAbsPdf.h"
00038 #include "RooCmdConfig.h"
00039 #include "RooMsgService.h"
00040 
00041 
00042 
00043 ClassImp(RooDataWeightedAverage)
00044 ;
00045 
00046 
00047 //_____________________________________________________________________________
00048 RooDataWeightedAverage::RooDataWeightedAverage(const char *name, const char *title, RooAbsReal& pdf, RooAbsData& indata, 
00049                                                const RooArgSet& projdeps, Int_t nCPU, Bool_t interleave, Bool_t showProgress, Bool_t verbose) : 
00050   RooAbsOptTestStatistic(name,title,pdf,indata,projdeps,0,0,nCPU,interleave,verbose,kFALSE),
00051   _showProgress(showProgress)
00052 {
00053   // Constructor of data weighted average of given p.d.f over given data. If nCPU>1 the calculation is parallelized
00054   // over multuple processes. If showProgress is true a progress indicator printing a single dot for each evaluation
00055   // is shown. If interleave is true, the dataset split over multiple processes is done with an interleave pattern
00056   // rather than a bulk-split pattern.
00057 
00058   if (_showProgress) {
00059     coutI(Plotting) << "RooDataWeightedAverage::ctor(" << GetName() << ") constructing data weighted average of function " << pdf.GetName() 
00060                     << " over " << indata.numEntries() << " data points of " << *(indata.get()) << " with a total weight of " << indata.sumEntries() << endl ;
00061   }
00062   _sumWeight = indata.sumEntries() ;
00063 }
00064 
00065 
00066 //_____________________________________________________________________________
00067 RooDataWeightedAverage::RooDataWeightedAverage(const RooDataWeightedAverage& other, const char* name) : 
00068   RooAbsOptTestStatistic(other,name),
00069   _sumWeight(other._sumWeight),
00070   _showProgress(other._showProgress)
00071 {
00072   // Copy constructor
00073 }
00074 
00075 
00076 
00077 //_____________________________________________________________________________
00078 RooDataWeightedAverage::~RooDataWeightedAverage()
00079 {
00080   // Destructor
00081 }
00082 
00083 
00084 
00085 //_____________________________________________________________________________
00086 Double_t RooDataWeightedAverage::globalNormalization() const 
00087 {
00088   // Return global normalization term by which raw (combined) test statistic should
00089   // be defined to obtain final test statistic. For a data weighted avarage this
00090   // the the sum of all weights
00091 
00092   return _sumWeight ;
00093 }
00094 
00095 
00096 
00097 //_____________________________________________________________________________
00098 Double_t RooDataWeightedAverage::evaluatePartition(Int_t firstEvent, Int_t lastEvent, Int_t stepSize) const 
00099 {
00100   // Calculate the data weighted average for events [firstEVent,lastEvent] with step size stepSize
00101 
00102   Int_t i ;
00103   Double_t result(0) ;
00104 
00105   if (setNum()==0 && _showProgress) {
00106     ccoutP(Plotting) << "." ;
00107     cout.flush() ;
00108   }
00109 
00110   for (i=firstEvent ; i<lastEvent ; i+=stepSize) {
00111     
00112     // get the data values for this event
00113     _dataClone->get(i);
00114     if (_dataClone->weight()==0) continue ;
00115 
00116     Double_t term = _dataClone->weight() * _funcClone->getVal(_normSet);
00117     result += term;
00118   }
00119   
00120   return result  ;
00121 }
00122 
00123 
00124 

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