22 std::vector<Double_t> width_list;
24 width_list.push_back( width1 );
25 if (width2 > 0) width_list.push_back( width2 );
26 if (width3 > 0) width_list.push_back( width3 );
27 if (width4 > 0) width_list.push_back( width4 );
28 if (width5 > 0) width_list.push_back( width5 );
35 Logger::print(2,
"%20.20s ERROR: Number of non-zero elements in width list (%d) does not match phase space dimensionality (%d)\n",
54 std::vector<Double_t> width_list;
56 width_list.push_back( width1 );
57 if (width2 > 0) width_list.push_back( width2 );
58 if (width3 > 0) width_list.push_back( width3 );
59 if (width4 > 0) width_list.push_back( width4 );
60 if (width5 > 0) width_list.push_back( width5 );
67 Logger::print(2,
"%20.20s ERROR: Number of non-zero elements in width list (%d) does not match phase space dimensionality (%d)\n",
73 Logger::print(2,
"%20.20s ERROR: Phase space definitions for Kernel density and its approximation differ\n",
m_name);
84 std::vector<Double_t> &width,
93 Logger::print(2,
"%20.20s ERROR: Number of elements in width list (%d) does not match phase space dimensionality (%d)\n",
99 Logger::print(2,
"%20.20s ERROR: Phase space definitions for Kernel density and its approximation differ\n",
m_name);
115 std::vector<Double_t>::const_iterator i;
116 for (i=width.begin(); i != width.end(); i++) {
119 Logger::print(2,
"%20.20s ERROR: Kernel width for variable %d less or equal to zero\n",
m_name, n);
138 for (cell = 0; cell < (Int_t)cells; cell++)
141 std::vector<Double_t> point(dimensionality);
143 Logger::print(0,
"%20.20s INFO: Generating approximation sample for %d-dim distribution, %d points, %d cells\n",
144 m_name, dimensionality, apprSize, cells);
147 for (i=0; i<apprSize; i++) {
156 for (var = 0; var < dimensionality; var++) {
159 point[var] = lowerLimit +
m_rnd.Rndm()*(upperLimit-lowerLimit);
169 Logger::print(1,
"%20.20s WARNING: failed to generate a point within phase space after %d tries\n",
m_name, m_maxTries);
178 if (cell < (Int_t)cells && cell >= 0)
181 Logger::print(2,
"%20.20s ERROR: cell number %d exceeds vector size %d\n",
m_name, cell, cells);
185 if (i % 1000 == 0)
Logger::print(0,
"%20.20s INFO: %d%% done (%d/%d)\n",
m_name, (100*i/apprSize), i, apprSize);
193 const char* var3,
const char* var4,
194 const char* var5,
const char* var6, UInt_t maxEvents) {
197 std::vector<TString> varList(dim);
199 if (dim>=1 && var1!=0) varList[0] = TString(var1);
200 if (dim>=2 && var2!=0) varList[1] = TString(var2);
201 if (dim>=3 && var3!=0) varList[2] = TString(var3);
202 if (dim>=4 && var4!=0) varList[3] = TString(var4);
203 if (dim>=5 && var5!=0) varList[4] = TString(var5);
204 if (dim>=6 && var6!=0) varList[5] = TString(var6);
206 return readTuple(tree, varList, maxEvents);
211 const char* var3,
const char* var4,
212 const char* var5, UInt_t maxEvents) {
215 std::vector<TString> varList(dim);
217 if (dim>=1 && var1!=0) varList[0] = TString(var1);
218 if (dim>=2 && var2!=0) varList[1] = TString(var2);
219 if (dim>=3 && var3!=0) varList[2] = TString(var3);
220 if (dim>=4 && var4!=0) varList[3] = TString(var4);
221 if (dim>=5 && var5!=0) varList[4] = TString(var5);
223 return readTuple(tree, varList, maxEvents);
228 const char* var3,
const char* var4,
232 std::vector<TString> varList(dim);
234 if (dim>=1 && var1!=0) varList[0] = TString(var1);
235 if (dim>=2 && var2!=0) varList[1] = TString(var2);
236 if (dim>=3 && var3!=0) varList[2] = TString(var3);
237 if (dim>=4 && var4!=0) varList[3] = TString(var4);
239 return readTuple(tree, varList, maxEvents);
244 const char* var3, UInt_t maxEvents) {
247 std::vector<TString> varList(dim);
249 if (dim>=1 && var1!=0) varList[0] = TString(var1);
250 if (dim>=2 && var2!=0) varList[1] = TString(var2);
251 if (dim>=3 && var3!=0) varList[2] = TString(var3);
253 return readTuple(tree, varList, maxEvents);
261 std::vector<TString> varList(dim);
263 if (dim>=1 && var1!=0) varList[0] = TString(var1);
264 if (dim>=2 && var2!=0) varList[1] = TString(var2);
266 return readTuple(tree, varList, maxEvents);
273 std::vector<TString> varList(dim);
275 if (dim>=1 && var1!=0) varList[0] = TString(var1);
277 return readTuple(tree, varList, maxEvents);
286 for (i = 0; i<dim; i++) {
290 Int_t dimCells = TMath::Ceil( (upper-lower)/
m_width[i] );
304 for (i = 0; i<dim; i++) {
309 if (xi < lower || xi > upper) {
314 Int_t dimCells = TMath::Ceil( (upper-lower)/
m_width[i+1] );
318 Int_t dimCells = TMath::Ceil( (upper-lower)/
m_width[i] );
319 Int_t dimCell = TMath::Floor( (xi-lower)/
m_width[i] );
320 if (dimCell == dimCells) dimCell--;
322 if (dimCell < 0 || dimCell >= dimCells) {
323 Logger::print(2,
"%20.20s ERROR: Something wrong! upper=%f, lower=%f, x=%f, width=%f, cell=%d, ncells=%d\n",
m_name,
324 upper, lower, xi,
m_width[i], dimCell, dimCells);
341 Logger::print(2,
"%20.20s ERROR: Number of TTree variables (%d) in tree \"%s\" does not correspond to phase space dimensionality (%d)\n",
346 UInt_t nvars = vars.size();
348 tree->ResetBranchAddresses();
350 Long64_t nentries = tree->GetEntries();
352 if (maxEvents > 0 && maxEvents < nentries) nentries = maxEvents;
356 std::vector<Float_t> varArray(nvars);
359 for (n=0; n < nvars; n++) {
360 Logger::print(0,
"%20.20s INFO: Will read branch \"%s\" from tree \"%s\"\n",
m_name, vars[n].Data(), tree->GetName());
361 Int_t status = tree->SetBranchAddress(vars[n], &( varArray[n] ));
368 std::vector<Double_t> point(nvars);
375 for (cell = 0; cell < (Int_t)cells; cell++) {
380 for(i=0; i<nentries; i++) {
385 for (n=0; n<nvars; n++) {
386 point[n] = varArray[n];
392 for (n=0; n<nvars; n++) {
395 Logger::print(1,
", %f%%) outside phase space\n", 100.*
float(nout)/
float(i));
401 if (i % 10000 == 0) {
402 Logger::print(0,
"%20.20s INFO: Read %lld/%lld events (%f%%)\n",
m_name, i, nentries, 100.*
float(i)/
float(nentries));
406 Logger::print(0,
"%20.20s INFO: %lld events read in from \"%s\"\n",
m_name, nentries-nout, tree->GetName() );
417 std::vector<UInt_t> iter(dim);
420 for (j=0; j<dim; j++) {
435 std::vector<Double_t> point(dim);
436 for (j=0; j<dim; j++) {
437 point[j] = x[j] + iter[j]*
m_width[j];
448 UInt_t size = vector[cell].size();
450 for (UInt_t i=0; i<size; i++) {
452 for (UInt_t var=0; var < dim; var++) {
453 Double_t dx = (vector[cell][i][var] - x[var])/
m_width[var];
454 if (TMath::Abs(dx) < 1.) {
461 if (sqsum < 1.) d += (1.-sqsum);
468 for (j=0; j<dim; j++) {
495 Double_t corrEff = rawData/rawNorm;
AbsPhaseSpace * m_phaseSpace
std::vector< TCell > m_dataVector
AbsDensity * m_approxDensity
virtual Double_t upperLimit(UInt_t var)=0
Return upper allowed limit of the variable.
KernelDensity(const char *pdfName, AbsPhaseSpace *thePhaseSpace, std::vector< Double_t > &width, UInt_t approxSize, AbsDensity *approxDensity=0)
Abstract class which defines probability density interface.
virtual AbsPhaseSpace * phaseSpace()=0
Return phase space definition for this PDF.
void print(int level, const char *format,...)
char m_name[256]
PDF name.
AbsPhaseSpace * phaseSpace()
Return phase space definition for this PDF.
Bool_t generateApproximation(UInt_t approxSize)
Create normalisation vector.
void setWidth(std::vector< Double_t > &width)
Set kernel width.
TRandom3 m_rnd
Random number generator.
Double_t density(std::vector< Double_t > &x)
Calculate PDF value at the given point.
Abstract class which defines phase space interface.
virtual UInt_t dimensionality()=0
Get dimensionality of phase space.
UInt_t m_maxTries
Maximum number of tries for accept-reject method.
Double_t rawDensity(std::vector< Double_t > &x, std::vector< TCell > &vector)
virtual Double_t lowerLimit(UInt_t var)=0
Return lower allowed limit of the variable.
Double_t generate(std::vector< Double_t > &x)
Generate a single point within the phase space according to the PDF using accept-reject method...
Bool_t readTuple(TTree *tree, std::vector< TString > &vars, UInt_t maxEvents=0)
virtual Bool_t withinLimits(std::vector< Double_t > &x)=0
Check if the point is within phase space limits.
virtual Double_t density(std::vector< Double_t > &x)=0
Calculate PDF value at the given point.
std::vector< TCell > m_apprVector
Int_t cellIndex(std::vector< Double_t > &x)