15 #ifndef ROO_NDKEYS_PDF
16 #define ROO_NDKEYS_PDF
35 class RooChangeTracker;
38 class VecVecDouble :
public std::vector<std::vector<Double_t> > { } ;
39 class VecTVecDouble :
public std::vector<TVectorD> { } ;
40 typedef std::pair<Int_t, VecVecDouble::iterator > iiPair;
41 typedef std::vector< iiPair > iiVec;
42 typedef std::pair<Int_t, VecTVecDouble::iterator > itPair;
43 typedef std::vector< itPair > itVec;
48 class RooNDKeysPdf :
public RooAbsPdf {
52 enum Mirror {NoMirror, MirrorLeft, MirrorRight, MirrorBoth,
53 MirrorAsymLeft, MirrorAsymLeftRight,
54 MirrorAsymRight, MirrorLeftAsymRight,
57 RooNDKeysPdf() =
default;
59 RooNDKeysPdf(
const char *name,
const char *title,
const RooArgList &varList,
const RooDataSet &data,
60 TString options =
"ma", Double_t rho = 1, Double_t nSigma = 3, Bool_t rotate = kTRUE,
61 Bool_t sortInput = kTRUE);
63 RooNDKeysPdf(
const char *name,
const char *title,
const RooArgList &varList,
const TH1 &hist, TString options =
"ma",
64 Double_t rho = 1, Double_t nSigma = 3, Bool_t rotate = kTRUE, Bool_t sortInput = kTRUE);
66 RooNDKeysPdf(
const char *name,
const char *title,
const RooArgList &varList,
const RooDataSet &data,
67 const TVectorD &rho, TString options =
"ma", Double_t nSigma = 3, Bool_t rotate = kTRUE,
68 Bool_t sortInput = kTRUE);
70 RooNDKeysPdf(
const char *name,
const char *title,
const RooArgList &varList,
const RooDataSet &data,
71 const RooArgList &rhoList, TString options =
"ma", Double_t nSigma = 3, Bool_t rotate = kTRUE,
72 Bool_t sortInput = kTRUE);
74 RooNDKeysPdf(
const char *name,
const char *title,
const RooArgList &varList,
const TH1 &hist,
75 const RooArgList &rhoList, TString options =
"ma", Double_t nSigma = 3, Bool_t rotate = kTRUE,
76 Bool_t sortInput = kTRUE);
78 RooNDKeysPdf(
const char *name,
const char *title, RooAbsReal &x,
const RooDataSet &data, Mirror mirror = NoMirror,
79 Double_t rho = 1, Double_t nSigma = 3, Bool_t rotate = kTRUE, Bool_t sortInput = kTRUE);
81 RooNDKeysPdf(
const char *name,
const char *title, RooAbsReal &x, RooAbsReal &y,
const RooDataSet &data,
82 TString options =
"ma", Double_t rho = 1.0, Double_t nSigma = 3, Bool_t rotate = kTRUE,
83 Bool_t sortInput = kTRUE);
85 RooNDKeysPdf(
const RooNDKeysPdf& other,
const char* name=0);
86 virtual ~RooNDKeysPdf();
88 virtual TObject* clone(
const char* newname)
const {
return new RooNDKeysPdf(*
this,newname); }
90 Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars,
const char* rangeName=0)
const ;
91 Double_t analyticalIntegral(Int_t code,
const char* rangeName=0)
const ;
93 inline void fixShape(Bool_t fix) {
98 TMatrixD getWeights(
const int &k)
const;
104 Double_t nEventsBMSW;
105 std::vector<Double_t> xVarLo, xVarHi;
106 std::vector<Double_t> xVarLoM3s, xVarLoP3s, xVarHiM3s, xVarHiP3s;
107 std::map<Int_t,Bool_t> bpsIdcs;
108 std::vector<Int_t> sIdcs;
109 std::vector<Int_t> bIdcs;
110 std::vector<Int_t> bmsIdcs;
115 RooListProxy _varList ;
116 RooListProxy _rhoList;
118 Double_t evaluate()
const;
120 void createPdf(Bool_t firstCall = kTRUE);
123 void loadDataSet(Bool_t firstCall)
const;
124 void mirrorDataSet()
const;
125 void loadWeightSet()
const;
126 void calculateShell(BoxInfo *bi)
const;
127 void calculatePreNorm(BoxInfo *bi)
const;
128 void sortDataIndices(BoxInfo *bi = 0);
129 void calculateBandWidth()
const;
130 Double_t gauss(std::vector<Double_t> &x, std::vector<std::vector<Double_t>> &weights)
const;
131 void loopRange(std::vector<Double_t> &x, std::map<Int_t, Bool_t> &ibMap)
const;
132 void boxInfoInit(BoxInfo *bi,
const char *rangeName, Int_t code)
const;
133 RooDataSet *createDatasetFromHist(
const RooArgList &varList,
const TH1 &hist)
const;
134 void updateRho()
const;
136 std::unique_ptr<RooDataSet> _ownedData{
nullptr};
137 const RooDataSet* _data;
138 mutable TString _options;
139 mutable Double_t _widthFactor;
140 mutable Double_t _nSigma;
142 mutable Bool_t _fixedShape{
false};
143 mutable Bool_t _mirror{
false};
144 mutable Bool_t _debug{
false};
145 mutable Bool_t _verbose{
false};
147 mutable Int_t _nDim{0};
148 mutable Int_t _nEvents{0};
149 mutable Int_t _nEventsM{0};
150 mutable Double_t _nEventsW{0.};
151 mutable Double_t _d{0.};
152 mutable Double_t _n{0.};
156 mutable std::vector<std::vector<Double_t> > _dataPts;
157 mutable std::vector<TVectorD> _dataPtsR;
158 mutable std::vector<std::vector<Double_t> > _weights0;
159 mutable std::vector<std::vector<Double_t> > _weights1;
160 mutable std::vector<std::vector<Double_t> >* _weights;
162 std::vector<itVec> _sortTVIdcs;
164 mutable std::vector<std::string> _varName;
165 mutable std::vector<Double_t> _rho;
166 mutable RooArgSet _dataVars;
167 mutable std::vector<Double_t> _x;
168 mutable std::vector<Double_t> _x0, _x1, _x2;
169 mutable std::vector<Double_t> _mean, _sigma;
170 mutable std::vector<Double_t> _xDatLo, _xDatHi;
171 mutable std::vector<Double_t> _xDatLo3s, _xDatHi3s;
173 mutable Bool_t _netFluxZ{
false};
174 mutable Double_t _nEventsBW{0.};
175 mutable Double_t _nEventsBMSW{0.};
176 mutable std::vector<Double_t> _xVarLo, _xVarHi;
177 mutable std::vector<Double_t> _xVarLoM3s, _xVarLoP3s, _xVarHiM3s, _xVarHiP3s;
178 mutable std::map<Int_t,Bool_t> _bpsIdcs;
179 mutable std::map<Int_t, Bool_t> _ibNoSort;
180 mutable std::vector<Int_t> _sIdcs;
181 mutable std::vector<Int_t> _bIdcs;
182 mutable std::vector<Int_t> _bmsIdcs;
184 mutable std::map<std::pair<std::string,int>,BoxInfo*> _rangeBoxInfo ;
185 mutable BoxInfo _fullBoxInfo ;
187 mutable std::vector<Int_t> _idx;
188 mutable Double_t _minWeight{0.};
189 mutable Double_t _maxWeight{0.};
190 mutable std::map<Int_t,Double_t> _wMap;
192 mutable TMatrixDSym* _covMat{
nullptr};
193 mutable TMatrixDSym* _corrMat{
nullptr};
194 mutable TMatrixD* _rotMat{
nullptr};
195 mutable TVectorD* _sigmaR{
nullptr};
196 mutable TVectorD* _dx{
nullptr};
197 mutable Double_t _sigmaAvgR{0.};
199 mutable Bool_t _rotate;
200 mutable Bool_t _sortInput;
201 mutable Int_t _nAdpt;
203 mutable RooChangeTracker *_tracker{
nullptr};
205 ClassDef(RooNDKeysPdf, 1)