void testMassFit() { TFile* file = TFile::Open("plots_btodmunu_TTJets_Filtered.root"); TH1F* correctedBHisto = (TH1F*)file->Get("massBCorrected/massBCorrected_sig"); RooRealVar correctedBMass("correctedBMass", "correctedBMass", 2.0, 10.0); RooDataHist data("data", "data", correctedBMass, correctedBHisto); RooRealVar mean1("mean1", "mean1", 5.1, 4.0, 6.0); RooRealVar sigma1("sigma1", "sigma1", 0.5, 0.1, 1.0); RooGaussian gaus1("gaus1", "gaus1", correctedBMass, mean1, sigma1); RooRealVar mean2("mean2", "mean2", 4.8, 3.0, 6.0); RooRealVar sigma2("sigma2", "sigma2", 0.9, 0.1, 3.5); RooGaussian gaus2("gaus2", "gaus2", correctedBMass, mean2, sigma2); RooRealVar fGaus1("fGaus1", "fGaus1", 0.7, 0.0, 1.0); RooAddPdf model("model", "model", gaus1, gaus2, fGaus1); model.fitTo(data); RooPlot* frame = correctedBMass.frame(); data.plotOn(frame); model.plotOn(frame); model.paramOn(frame); frame->Draw(); }
real_t total2 (int i) const { return mean2(i) + fluctuating2(i); }
void BVHAccel::FindBestSplit(std::vector<BVHAccelTreeNode *> &list, unsigned int begin, unsigned int end, float *splitValue, unsigned int *bestAxis) { if (end - begin == 2) { // Trivial case with two elements *splitValue = (list[begin]->bbox.pMax[0] + list[begin]->bbox.pMin[0] + list[end - 1]->bbox.pMax[0] + list[end - 1]->bbox.pMin[0]) / 2; *bestAxis = 0; } else { // Calculate BBs mean center (times 2) Point mean2(0, 0, 0), var(0, 0, 0); for (unsigned int i = begin; i < end; i++) mean2 += list[i]->bbox.pMax + list[i]->bbox.pMin; mean2 /= static_cast<float>(end - begin); // Calculate variance for (unsigned int i = begin; i < end; i++) { Vector v = list[i]->bbox.pMax + list[i]->bbox.pMin - mean2; v.x *= v.x; v.y *= v.y; v.z *= v.z; var += v; } // Select axis with more variance if (var.x > var.y && var.x > var.z) *bestAxis = 0; else if (var.y > var.z) *bestAxis = 1; else *bestAxis = 2; if (costSamples > 1) { BBox nodeBounds; for (unsigned int i = begin; i < end; i++) nodeBounds = Union(nodeBounds, list[i]->bbox); Vector d = nodeBounds.pMax - nodeBounds.pMin; const float invTotalSA = 1.f / nodeBounds.SurfaceArea(); // Sample cost for split at some points float increment = 2 * d[*bestAxis] / (costSamples + 1); float bestCost = INFINITY; for (float splitVal = 2 * nodeBounds.pMin[*bestAxis] + increment; splitVal < 2 * nodeBounds.pMax[*bestAxis]; splitVal += increment) { int nBelow = 0, nAbove = 0; BBox bbBelow, bbAbove; for (unsigned int j = begin; j < end; j++) { if ((list[j]->bbox.pMax[*bestAxis] + list[j]->bbox.pMin[*bestAxis]) < splitVal) { nBelow++; bbBelow = Union(bbBelow, list[j]->bbox); } else { nAbove++; bbAbove = Union(bbAbove, list[j]->bbox); } } const float pBelow = bbBelow.SurfaceArea() * invTotalSA; const float pAbove = bbAbove.SurfaceArea() * invTotalSA; float eb = (nAbove == 0 || nBelow == 0) ? emptyBonus : 0.f; float cost = traversalCost + isectCost * (1.f - eb) * (pBelow * nBelow + pAbove * nAbove); // Update best split if this is lowest cost so far if (cost < bestCost) { bestCost = cost; *splitValue = splitVal; } } } else { // Split in half around the mean center *splitValue = mean2[*bestAxis]; } } }
real_t total2 () const { return mean2() + fluctuating2(); }