ROOT logo
/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitModels                                                     *
 *    File: $Id: RooNDKeysPdf.h 30854 2009-10-23 15:23:44Z wouter $
 * Authors:                                                                  *
 *   Max Baak, CERN, mbaak@cern.ch *
 *                                                                           *
 * Copyright (c) 2000-2005, Regents of the University of California          *
 *                          and Stanford University. All rights reserved.    *
 *                                                                           *
 * Redistribution and use in source and binary forms,                        *
 * with or without modification, are permitted according to the terms        *
 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
 *****************************************************************************/
#ifndef ROO_KEYS_PDF
#define ROO_KEYS_PDF

#include "RooAbsPdf.h"
#include "RooRealProxy.h"
#include "RooSetProxy.h"
#include "RooRealConstant.h"
#include "TVectorD.h"
#include "TMatrixD.h"
#include "TMatrixDSym.h"
#include <map>
#include <vector>
#include <string>

class RooRealVar;
class RooArgList;
class RooArgSet;

using namespace std;

#ifndef __CINT__
class VecVecDouble : public std::vector<std::vector<Double_t> >  { } ;
class VecTVecDouble : public std::vector<TVectorD> { } ;
typedef std::pair<Int_t, VecVecDouble::iterator > iiPair; 
typedef std::vector< iiPair > iiVec; 
typedef std::pair<Int_t, VecTVecDouble::iterator > itPair;
typedef std::vector< itPair > itVec;
#else
class itPair ;
#endif

class RooNDKeysPdf : public RooAbsPdf {

public:


  enum Mirror {NoMirror, MirrorLeft, MirrorRight, MirrorBoth,
               MirrorAsymLeft, MirrorAsymLeftRight,
               MirrorAsymRight, MirrorLeftAsymRight,
               MirrorAsymBoth };

  RooNDKeysPdf(const char *name, const char *title,
               const RooArgList& varList, RooDataSet& data, 
	       TString options="a", Double_t rho=1, Double_t nSigma=3, Bool_t rotate=kTRUE) ; 

  RooNDKeysPdf(const char *name, const char *title,
               RooAbsReal& x, RooDataSet& data, 
               Mirror mirror= NoMirror, Double_t rho=1, Double_t nSigma=3, Bool_t rotate=kTRUE) ; 

  RooNDKeysPdf(const char *name, const char *title,
               RooAbsReal& x, RooAbsReal &y, RooDataSet& data, 
               TString options="a", Double_t rho = 1.0, Double_t nSigma=3, Bool_t rotate=kTRUE); 

  RooNDKeysPdf(const RooNDKeysPdf& other, const char* name=0);
  virtual ~RooNDKeysPdf();

  virtual TObject* clone(const char* newname) const { return new RooNDKeysPdf(*this,newname); }
  
  Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=0) const ;
  Double_t analyticalIntegral(Int_t code, const char* rangeName=0) const ;

  inline void fixShape(Bool_t fix) { 
    createPdf(kFALSE);
    _fixedShape=fix; 
  }

  struct BoxInfo {
    Bool_t filled;
    Bool_t netFluxZ;
    Double_t nEventsBW;
    Double_t nEventsBMSW;
    vector<Double_t> xVarLo, xVarHi;
    vector<Double_t> xVarLoM3s, xVarLoP3s, xVarHiM3s, xVarHiP3s;
    map<Int_t,Bool_t> bpsIdcs;
    vector<Int_t> sIdcs;	
    vector<Int_t> bIdcs;
    vector<Int_t> bmsIdcs;
  } ;

protected:
  
  RooListProxy _varList ;
  TIterator* _varItr ;   //! do not persist

  Double_t evaluate() const;


  void     createPdf(Bool_t firstCall=kTRUE) const;  
  void     setOptions() const;
  void     initialize() const; 
  void     loadDataSet(Bool_t firstCall) const;
  void     mirrorDataSet() const;
  void     loadWeightSet() const;
  void     calculateShell(BoxInfo* bi) const;
  void     calculatePreNorm(BoxInfo* bi) const;
  void     sortDataIndices(BoxInfo* bi=0) const;
  void     calculateBandWidth() const;
  Double_t gauss(vector<Double_t>& x, vector<vector<Double_t> >& weights) const;
  void     loopRange(vector<Double_t>& x, map<Int_t,Bool_t>& ibMap) const;
  void     boxInfoInit(BoxInfo* bi, const char* rangeName, Int_t code) const;

  RooDataSet& _data;
  mutable TString _options;
  mutable Double_t _widthFactor;
  mutable Double_t _nSigma;

  mutable Bool_t _fixedShape;
  mutable Bool_t _mirror;
  mutable Bool_t _debug;
  mutable Bool_t _verbose;

  mutable Double_t _sqrt2pi;
  mutable Int_t _nDim;
  mutable Int_t _nEvents;
  mutable Int_t _nEventsM;
  mutable Double_t _nEventsW;
  mutable Double_t _d;
  mutable Double_t _n;
  
  // cached info on variable

  mutable vector<vector<Double_t> > _dataPts;
  mutable vector<TVectorD> _dataPtsR;
  mutable vector<vector<Double_t> > _weights0;
  mutable vector<vector<Double_t> > _weights1;
  mutable vector<vector<Double_t> >* _weights; //!

#ifndef __CINT__
  mutable vector<iiVec> _sortIdcs;
  mutable vector<itVec> _sortTVIdcs;
#endif

  mutable vector<string> _varName;
  mutable vector<Double_t> _rho;
  mutable RooArgSet _dataVars;
  mutable vector<Double_t> _x;
  mutable vector<Double_t> _x0, _x1, _x2;
  mutable vector<Double_t> _mean, _sigma;
  mutable vector<Double_t> _xDatLo, _xDatHi;
  mutable vector<Double_t> _xDatLo3s, _xDatHi3s;

  mutable Bool_t _netFluxZ;
  mutable Double_t _nEventsBW;
  mutable Double_t _nEventsBMSW;
  mutable vector<Double_t> _xVarLo, _xVarHi;
  mutable vector<Double_t> _xVarLoM3s, _xVarLoP3s, _xVarHiM3s, _xVarHiP3s;
  mutable map<Int_t,Bool_t> _bpsIdcs;
  mutable vector<Int_t>	_sIdcs;	
  mutable vector<Int_t> _bIdcs;
  mutable vector<Int_t> _bmsIdcs;

  mutable map<pair<string,int>,BoxInfo*> _rangeBoxInfo ;
  mutable BoxInfo _fullBoxInfo ;

  mutable vector<Int_t> _idx;
  mutable Double_t _minWeight;
  mutable Double_t _maxWeight;
  mutable map<Int_t,Double_t> _wMap;

  mutable TMatrixDSym* _covMat; 
  mutable TMatrixDSym* _corrMat; 
  mutable TMatrixD* _rotMat; 
  mutable TVectorD* _sigmaR; 
  mutable TVectorD* _dx;
  mutable Double_t _sigmaAvgR;

  mutable Bool_t _rotate;

  /// sorter function
  struct SorterTV_L2H {
    Int_t idx;
    
    SorterTV_L2H (Int_t index) : idx(index) {}
    bool operator() (const itPair& a, const itPair& b) {
      const TVectorD& aVec = *(a.second); 
      const TVectorD& bVec = *(b.second); 
      return (aVec[idx]<bVec[idx]);
    }
  };

  ClassDef(RooNDKeysPdf,0) // General N-dimensional non-parametric kernel estimation p.d.f
};

#endif
 RooNDKeysPdf.h:1
 RooNDKeysPdf.h:2
 RooNDKeysPdf.h:3
 RooNDKeysPdf.h:4
 RooNDKeysPdf.h:5
 RooNDKeysPdf.h:6
 RooNDKeysPdf.h:7
 RooNDKeysPdf.h:8
 RooNDKeysPdf.h:9
 RooNDKeysPdf.h:10
 RooNDKeysPdf.h:11
 RooNDKeysPdf.h:12
 RooNDKeysPdf.h:13
 RooNDKeysPdf.h:14
 RooNDKeysPdf.h:15
 RooNDKeysPdf.h:16
 RooNDKeysPdf.h:17
 RooNDKeysPdf.h:18
 RooNDKeysPdf.h:19
 RooNDKeysPdf.h:20
 RooNDKeysPdf.h:21
 RooNDKeysPdf.h:22
 RooNDKeysPdf.h:23
 RooNDKeysPdf.h:24
 RooNDKeysPdf.h:25
 RooNDKeysPdf.h:26
 RooNDKeysPdf.h:27
 RooNDKeysPdf.h:28
 RooNDKeysPdf.h:29
 RooNDKeysPdf.h:30
 RooNDKeysPdf.h:31
 RooNDKeysPdf.h:32
 RooNDKeysPdf.h:33
 RooNDKeysPdf.h:34
 RooNDKeysPdf.h:35
 RooNDKeysPdf.h:36
 RooNDKeysPdf.h:37
 RooNDKeysPdf.h:38
 RooNDKeysPdf.h:39
 RooNDKeysPdf.h:40
 RooNDKeysPdf.h:41
 RooNDKeysPdf.h:42
 RooNDKeysPdf.h:43
 RooNDKeysPdf.h:44
 RooNDKeysPdf.h:45
 RooNDKeysPdf.h:46
 RooNDKeysPdf.h:47
 RooNDKeysPdf.h:48
 RooNDKeysPdf.h:49
 RooNDKeysPdf.h:50
 RooNDKeysPdf.h:51
 RooNDKeysPdf.h:52
 RooNDKeysPdf.h:53
 RooNDKeysPdf.h:54
 RooNDKeysPdf.h:55
 RooNDKeysPdf.h:56
 RooNDKeysPdf.h:57
 RooNDKeysPdf.h:58
 RooNDKeysPdf.h:59
 RooNDKeysPdf.h:60
 RooNDKeysPdf.h:61
 RooNDKeysPdf.h:62
 RooNDKeysPdf.h:63
 RooNDKeysPdf.h:64
 RooNDKeysPdf.h:65
 RooNDKeysPdf.h:66
 RooNDKeysPdf.h:67
 RooNDKeysPdf.h:68
 RooNDKeysPdf.h:69
 RooNDKeysPdf.h:70
 RooNDKeysPdf.h:71
 RooNDKeysPdf.h:72
 RooNDKeysPdf.h:73
 RooNDKeysPdf.h:74
 RooNDKeysPdf.h:75
 RooNDKeysPdf.h:76
 RooNDKeysPdf.h:77
 RooNDKeysPdf.h:78
 RooNDKeysPdf.h:79
 RooNDKeysPdf.h:80
 RooNDKeysPdf.h:81
 RooNDKeysPdf.h:82
 RooNDKeysPdf.h:83
 RooNDKeysPdf.h:84
 RooNDKeysPdf.h:85
 RooNDKeysPdf.h:86
 RooNDKeysPdf.h:87
 RooNDKeysPdf.h:88
 RooNDKeysPdf.h:89
 RooNDKeysPdf.h:90
 RooNDKeysPdf.h:91
 RooNDKeysPdf.h:92
 RooNDKeysPdf.h:93
 RooNDKeysPdf.h:94
 RooNDKeysPdf.h:95
 RooNDKeysPdf.h:96
 RooNDKeysPdf.h:97
 RooNDKeysPdf.h:98
 RooNDKeysPdf.h:99
 RooNDKeysPdf.h:100
 RooNDKeysPdf.h:101
 RooNDKeysPdf.h:102
 RooNDKeysPdf.h:103
 RooNDKeysPdf.h:104
 RooNDKeysPdf.h:105
 RooNDKeysPdf.h:106
 RooNDKeysPdf.h:107
 RooNDKeysPdf.h:108
 RooNDKeysPdf.h:109
 RooNDKeysPdf.h:110
 RooNDKeysPdf.h:111
 RooNDKeysPdf.h:112
 RooNDKeysPdf.h:113
 RooNDKeysPdf.h:114
 RooNDKeysPdf.h:115
 RooNDKeysPdf.h:116
 RooNDKeysPdf.h:117
 RooNDKeysPdf.h:118
 RooNDKeysPdf.h:119
 RooNDKeysPdf.h:120
 RooNDKeysPdf.h:121
 RooNDKeysPdf.h:122
 RooNDKeysPdf.h:123
 RooNDKeysPdf.h:124
 RooNDKeysPdf.h:125
 RooNDKeysPdf.h:126
 RooNDKeysPdf.h:127
 RooNDKeysPdf.h:128
 RooNDKeysPdf.h:129
 RooNDKeysPdf.h:130
 RooNDKeysPdf.h:131
 RooNDKeysPdf.h:132
 RooNDKeysPdf.h:133
 RooNDKeysPdf.h:134
 RooNDKeysPdf.h:135
 RooNDKeysPdf.h:136
 RooNDKeysPdf.h:137
 RooNDKeysPdf.h:138
 RooNDKeysPdf.h:139
 RooNDKeysPdf.h:140
 RooNDKeysPdf.h:141
 RooNDKeysPdf.h:142
 RooNDKeysPdf.h:143
 RooNDKeysPdf.h:144
 RooNDKeysPdf.h:145
 RooNDKeysPdf.h:146
 RooNDKeysPdf.h:147
 RooNDKeysPdf.h:148
 RooNDKeysPdf.h:149
 RooNDKeysPdf.h:150
 RooNDKeysPdf.h:151
 RooNDKeysPdf.h:152
 RooNDKeysPdf.h:153
 RooNDKeysPdf.h:154
 RooNDKeysPdf.h:155
 RooNDKeysPdf.h:156
 RooNDKeysPdf.h:157
 RooNDKeysPdf.h:158
 RooNDKeysPdf.h:159
 RooNDKeysPdf.h:160
 RooNDKeysPdf.h:161
 RooNDKeysPdf.h:162
 RooNDKeysPdf.h:163
 RooNDKeysPdf.h:164
 RooNDKeysPdf.h:165
 RooNDKeysPdf.h:166
 RooNDKeysPdf.h:167
 RooNDKeysPdf.h:168
 RooNDKeysPdf.h:169
 RooNDKeysPdf.h:170
 RooNDKeysPdf.h:171
 RooNDKeysPdf.h:172
 RooNDKeysPdf.h:173
 RooNDKeysPdf.h:174
 RooNDKeysPdf.h:175
 RooNDKeysPdf.h:176
 RooNDKeysPdf.h:177
 RooNDKeysPdf.h:178
 RooNDKeysPdf.h:179
 RooNDKeysPdf.h:180
 RooNDKeysPdf.h:181
 RooNDKeysPdf.h:182
 RooNDKeysPdf.h:183
 RooNDKeysPdf.h:184
 RooNDKeysPdf.h:185
 RooNDKeysPdf.h:186
 RooNDKeysPdf.h:187
 RooNDKeysPdf.h:188
 RooNDKeysPdf.h:189
 RooNDKeysPdf.h:190
 RooNDKeysPdf.h:191
 RooNDKeysPdf.h:192
 RooNDKeysPdf.h:193
 RooNDKeysPdf.h:194
 RooNDKeysPdf.h:195
 RooNDKeysPdf.h:196
 RooNDKeysPdf.h:197
 RooNDKeysPdf.h:198