RooMultiBinomial.cxx

Go to the documentation of this file.
00001 
00002 /*****************************************************************************
00003  * Project: RooFit                                                           *
00004  * Package: RooFitCore                                                       *
00005  * @(#)root/roofitcore:$Id: RooMultiBinomial.cxx 31258 2009-11-17 22:41:06Z wouter $
00006  * Author:                                                                   *
00007  * Tristan du Pree, Nikhef, Amsterdam, tdupree@nikhef.nl                     * 
00008  *                                                                           *
00009  * Redistribution and use in source and binary forms,                        *
00010  * with or without modification, are permitted according to the terms        *
00011  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
00012  *****************************************************************************/
00013 
00014 //////////////////////////////////////////////////////////////////////////////
00015 // 
00016 // BEGIN_HTML
00017 // RooMultiBinomial is an efficiency function which makes all combinations of 
00018 // efficiencies given as input different effiency functions for different categories.
00019 // 
00020 // Given a dataset with a category C that determines if a given
00021 // event is accepted (1) or rejected (0) for the efficiency to be measured,
00022 // this class evaluates as F if C is 'accept' and as (1-F) if
00023 // C is 'reject'. Values of F below 0 and above 1 are clipped.
00024 // F may have an arbitrary number of dependents and parameters
00025 //
00026 // The combination only 'reject' can be chosen to be visible or not visible
00027 // (and hence this efficiency is then equal to zero).
00028 // END_HTML
00029 //
00030 
00031 #include "RooFit.h"
00032 
00033 #include "RooMultiBinomial.h"
00034 #include "RooStreamParser.h"
00035 #include "RooArgList.h"
00036 #include "RooAbsCategory.h"
00037 #include "RooMsgService.h"
00038 #include <string>
00039 #include <vector>
00040 
00041 using namespace std ;
00042 
00043 ClassImp(RooMultiBinomial)
00044   ;
00045 
00046 
00047 //_____________________________________________________________________________
00048 RooMultiBinomial::RooMultiBinomial(const char *name, const char *title, 
00049                                    const RooArgList& effFuncList, 
00050                                    const RooArgList& catList,
00051                                    Bool_t ignoreNonVisible) :
00052   RooAbsReal(name,title),
00053   _catList("catList","list of cats", this),
00054   _effFuncList("effFuncList","list of eff funcs",this),
00055   _ignoreNonVisible(ignoreNonVisible)
00056 {  
00057   // Construct the efficiency functions from a list of efficiency functions
00058   // and a list of categories cat with two states (0,1) that indicate if a given
00059   // event should be counted as rejected or accepted respectively
00060 
00061   _catList.add(catList);
00062   _effFuncList.add(effFuncList);
00063 
00064   if (_catList.getSize() != effFuncList.getSize()) {
00065     coutE(InputArguments) << "RooMultiBinomial::ctor(" << GetName() << ") ERROR: Wrong input, should have equal number of categories and efficiencies." << endl;
00066     throw string("RooMultiBinomial::ctor() ERROR: Wrong input, should have equal number of categories and efficiencies") ;
00067   }
00068 
00069 }
00070 
00071 
00072 
00073 //_____________________________________________________________________________
00074 RooMultiBinomial::RooMultiBinomial(const RooMultiBinomial& other, const char* name) : 
00075   RooAbsReal(other, name),
00076   _catList("catList",this,other._catList),
00077   _effFuncList("effFuncList",this,other._effFuncList),
00078   _ignoreNonVisible(other._ignoreNonVisible)
00079 {
00080   // Copy constructor
00081 }
00082 
00083 
00084 
00085 //_____________________________________________________________________________
00086 RooMultiBinomial::~RooMultiBinomial() 
00087 {
00088   // Destructor
00089 }
00090 
00091 
00092 
00093 //_____________________________________________________________________________
00094 Double_t RooMultiBinomial::evaluate() const
00095 {
00096   // Calculate the raw value of the function which is the effFunc
00097   // value if cat==1 and it is (1-effFunc) if cat==0
00098 
00099   Int_t effFuncListSize = _effFuncList.getSize();
00100 
00101   // Get efficiency function for category i
00102 
00103   vector<Double_t> effFuncVal(effFuncListSize);
00104   for (int i=0; i<effFuncListSize; ++i) {
00105     effFuncVal[i] = ((RooAbsReal&)_effFuncList[i]).getVal() ;
00106   }
00107 
00108   // Truncate efficiency functions in range 0.0-1.0
00109 
00110   for (int i=0; i<effFuncListSize; ++i) {
00111     if (effFuncVal[i]>1) {
00112       coutW(Eval) << "WARNING: Efficency >1 (equal to " << effFuncVal[i] 
00113                   << " ), for i = " << i << "...TRUNCATED" << endl;
00114       effFuncVal[i] = 1.0 ;
00115     } else if (effFuncVal[i]<0) {
00116       effFuncVal[i] = 0.0 ;
00117       coutW(Eval) << "WARNING: Efficency <0 (equal to " << effFuncVal[i] 
00118                   << " ), for i = " << i << "...TRUNCATED" << endl;
00119     }
00120   }
00121 
00122   vector<Double_t> effValue(effFuncListSize);
00123   Bool_t notVisible = true;
00124 
00125   // Calculate efficiency per accept/reject decision
00126 
00127   for (int i=0; i<effFuncListSize; ++i) {
00128     if ( ((RooAbsCategory&)_catList[i]).getIndex() == 1) {
00129       // Accept case
00130       effValue[i] = effFuncVal[i] ;
00131       notVisible = false;
00132     } else if ( ((RooAbsCategory&)_catList[i]).getIndex() == 0){
00133       // Reject case
00134       effValue[i] = 1 - effFuncVal[i] ;
00135     } else {
00136       coutW(Eval) << "WARNING: WRONG CATEGORY NAMES GIVEN!, label = " << ((RooAbsCategory&)_catList[i]).getIndex() << endl;
00137       effValue[i] = 0;
00138     }
00139   }
00140 
00141   Double_t _effVal = 1.;
00142 
00143   // Calculate efficiency for combination of accept/reject categories
00144   // put equal to zero if combination of only zeros AND chosen to be invisible
00145 
00146   for (int i=0; i<effFuncListSize; ++i) {
00147     _effVal=_effVal*effValue[i];
00148     if (notVisible && _ignoreNonVisible){
00149       _effVal=0;
00150     }
00151   }
00152 
00153   return _effVal;
00154 
00155 }
00156 
00157 
00158 

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