00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef ROO_KEYS_PDF
00016 #define ROO_KEYS_PDF
00017
00018 #include "RooAbsPdf.h"
00019 #include "RooRealProxy.h"
00020 #include "RooSetProxy.h"
00021 #include "RooRealConstant.h"
00022 #include "TVectorD.h"
00023 #include "TMatrixD.h"
00024 #include "TMatrixDSym.h"
00025 #include <map>
00026 #include <vector>
00027 #include <string>
00028
00029 class RooRealVar;
00030 class RooArgList;
00031 class RooArgSet;
00032
00033 using namespace std;
00034
00035 #ifndef __CINT__
00036 class VecVecDouble : public std::vector<std::vector<Double_t> > { } ;
00037 class VecTVecDouble : public std::vector<TVectorD> { } ;
00038 typedef std::pair<Int_t, VecVecDouble::iterator > iiPair;
00039 typedef std::vector< iiPair > iiVec;
00040 typedef std::pair<Int_t, VecTVecDouble::iterator > itPair;
00041 typedef std::vector< itPair > itVec;
00042 #else
00043 class itPair ;
00044 #endif
00045
00046 class RooNDKeysPdf : public RooAbsPdf {
00047
00048 public:
00049
00050
00051 enum Mirror {NoMirror, MirrorLeft, MirrorRight, MirrorBoth,
00052 MirrorAsymLeft, MirrorAsymLeftRight,
00053 MirrorAsymRight, MirrorLeftAsymRight,
00054 MirrorAsymBoth };
00055
00056 RooNDKeysPdf(const char *name, const char *title,
00057 const RooArgList& varList, RooDataSet& data,
00058 TString options="a", Double_t rho=1, Double_t nSigma=3, Bool_t rotate=kTRUE) ;
00059
00060 RooNDKeysPdf(const char *name, const char *title,
00061 RooAbsReal& x, RooDataSet& data,
00062 Mirror mirror= NoMirror, Double_t rho=1, Double_t nSigma=3, Bool_t rotate=kTRUE) ;
00063
00064 RooNDKeysPdf(const char *name, const char *title,
00065 RooAbsReal& x, RooAbsReal &y, RooDataSet& data,
00066 TString options="a", Double_t rho = 1.0, Double_t nSigma=3, Bool_t rotate=kTRUE);
00067
00068 RooNDKeysPdf(const RooNDKeysPdf& other, const char* name=0);
00069 virtual ~RooNDKeysPdf();
00070
00071 virtual TObject* clone(const char* newname) const { return new RooNDKeysPdf(*this,newname); }
00072
00073 Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=0) const ;
00074 Double_t analyticalIntegral(Int_t code, const char* rangeName=0) const ;
00075
00076 inline void fixShape(Bool_t fix) {
00077 createPdf(kFALSE);
00078 _fixedShape=fix;
00079 }
00080
00081 struct BoxInfo {
00082 Bool_t filled;
00083 Bool_t netFluxZ;
00084 Double_t nEventsBW;
00085 Double_t nEventsBMSW;
00086 vector<Double_t> xVarLo, xVarHi;
00087 vector<Double_t> xVarLoM3s, xVarLoP3s, xVarHiM3s, xVarHiP3s;
00088 map<Int_t,Bool_t> bpsIdcs;
00089 vector<Int_t> sIdcs;
00090 vector<Int_t> bIdcs;
00091 vector<Int_t> bmsIdcs;
00092 } ;
00093
00094 protected:
00095
00096 RooListProxy _varList ;
00097 TIterator* _varItr ;
00098
00099 Double_t evaluate() const;
00100
00101
00102 void createPdf(Bool_t firstCall=kTRUE) const;
00103 void setOptions() const;
00104 void initialize() const;
00105 void loadDataSet(Bool_t firstCall) const;
00106 void mirrorDataSet() const;
00107 void loadWeightSet() const;
00108 void calculateShell(BoxInfo* bi) const;
00109 void calculatePreNorm(BoxInfo* bi) const;
00110 void sortDataIndices(BoxInfo* bi=0) const;
00111 void calculateBandWidth() const;
00112 Double_t gauss(vector<Double_t>& x, vector<vector<Double_t> >& weights) const;
00113 void loopRange(vector<Double_t>& x, map<Int_t,Bool_t>& ibMap) const;
00114 void boxInfoInit(BoxInfo* bi, const char* rangeName, Int_t code) const;
00115
00116 RooDataSet& _data;
00117 mutable TString _options;
00118 mutable Double_t _widthFactor;
00119 mutable Double_t _nSigma;
00120
00121 mutable Bool_t _fixedShape;
00122 mutable Bool_t _mirror;
00123 mutable Bool_t _debug;
00124 mutable Bool_t _verbose;
00125
00126 mutable Double_t _sqrt2pi;
00127 mutable Int_t _nDim;
00128 mutable Int_t _nEvents;
00129 mutable Int_t _nEventsM;
00130 mutable Double_t _nEventsW;
00131 mutable Double_t _d;
00132 mutable Double_t _n;
00133
00134
00135
00136 mutable vector<vector<Double_t> > _dataPts;
00137 mutable vector<TVectorD> _dataPtsR;
00138 mutable vector<vector<Double_t> > _weights0;
00139 mutable vector<vector<Double_t> > _weights1;
00140 mutable vector<vector<Double_t> >* _weights;
00141
00142 #ifndef __CINT__
00143 mutable vector<iiVec> _sortIdcs;
00144 mutable vector<itVec> _sortTVIdcs;
00145 #endif
00146
00147 mutable vector<string> _varName;
00148 mutable vector<Double_t> _rho;
00149 mutable RooArgSet _dataVars;
00150 mutable vector<Double_t> _x;
00151 mutable vector<Double_t> _x0, _x1, _x2;
00152 mutable vector<Double_t> _mean, _sigma;
00153 mutable vector<Double_t> _xDatLo, _xDatHi;
00154 mutable vector<Double_t> _xDatLo3s, _xDatHi3s;
00155
00156 mutable Bool_t _netFluxZ;
00157 mutable Double_t _nEventsBW;
00158 mutable Double_t _nEventsBMSW;
00159 mutable vector<Double_t> _xVarLo, _xVarHi;
00160 mutable vector<Double_t> _xVarLoM3s, _xVarLoP3s, _xVarHiM3s, _xVarHiP3s;
00161 mutable map<Int_t,Bool_t> _bpsIdcs;
00162 mutable vector<Int_t> _sIdcs;
00163 mutable vector<Int_t> _bIdcs;
00164 mutable vector<Int_t> _bmsIdcs;
00165
00166 mutable map<pair<string,int>,BoxInfo*> _rangeBoxInfo ;
00167 mutable BoxInfo _fullBoxInfo ;
00168
00169 mutable vector<Int_t> _idx;
00170 mutable Double_t _minWeight;
00171 mutable Double_t _maxWeight;
00172 mutable map<Int_t,Double_t> _wMap;
00173
00174 mutable TMatrixDSym* _covMat;
00175 mutable TMatrixDSym* _corrMat;
00176 mutable TMatrixD* _rotMat;
00177 mutable TVectorD* _sigmaR;
00178 mutable TVectorD* _dx;
00179 mutable Double_t _sigmaAvgR;
00180
00181 mutable Bool_t _rotate;
00182
00183
00184 struct SorterTV_L2H {
00185 Int_t idx;
00186
00187 SorterTV_L2H (Int_t index) : idx(index) {}
00188 bool operator() (const itPair& a, const itPair& b) {
00189 const TVectorD& aVec = *(a.second);
00190 const TVectorD& bVec = *(b.second);
00191 return (aVec[idx]<bVec[idx]);
00192 }
00193 };
00194
00195 ClassDef(RooNDKeysPdf,0)
00196 };
00197
00198 #endif