static double Vwin(double t, double e) { return pdf(t - e) / cdf(t - e); }
int main() { std::cout << "____________________________________" << std::endl << " Testing transformations from cdf to pdf and inversely" <<std::endl; int zval[5] = {1,2,3,4,5}; double prob[5] = {0.2, 0.3, 0.6, 0.8, 1}; typedef Non_param_pdf<int> Pdf; typedef Categ_non_param_cdf<int> Cdf; Cdf categ_cdf( 5, prob); Pdf pdf(zval, zval+5); cdf_to_pdf(pdf, categ_cdf); for(int i=0; i<=4; i++) std::cout << pdf.prob(i) << " " ; std::cout << std::endl; Cdf back(5); pdf_to_cdf(back,pdf); for(int i=0; i<=4; i++) std::cout << back.prob(i) << " " ; std::cout << std::endl; cdf_to_pdf(pdf, back); for(int i=0; i<=4; i++) std::cout << pdf.prob(i) << " " ; std::cout << std::endl; Pdf new_pdf(categ_cdf); for(int i=0; i<=4; i++) std::cout << new_pdf.prob(i) << " " ; std::cout << std::endl; std::cout << std::endl << "____________________________________" << std::endl << " Testing transformations from cdf to pdf and inversely "<<std::endl; Gaussian_cdf normal(0,1); std::vector<double> range(1000); for(std::vector<double>::iterator it=range.begin(); it!=range.end(); it++) *it = drand48()*100; std::ofstream out1( "uniform.dbg" ); std::copy( range.begin(), range.end(), std::ostream_iterator<double>( out1, "\n" ) ); cdf_transform(range.begin(), range.end(), normal); std::ofstream out2( "nscore.dbg" ); std::copy( range.begin(), range.end(), std::ostream_iterator<double>( out2, "\n" ) ); std::cout << std::endl << "____________________________________" << std::endl << " Testing cdf correction "<<std::endl; double order_relation[5] = {0.2, 0.3, -0.2, 0.1, 1.2}; Cdf bad_cdf(5, order_relation); std::cout << "Is bad cdf ok? " << is_valid_cdf(bad_cdf) << std::endl; make_cdf_valid(bad_cdf); std::cout << "Corrected cdf: " << std::endl; for(int i=0; i<bad_cdf.size(); i++) std::cout << bad_cdf.prob(i) << " " ; std::cout << std::endl; std::cout << std::endl << "____________________________________" << std::endl << " Testing cdf construction "<<std::endl; double val_range[9] = {1,1,1,4,7,12,31,55,60}; double z_values[7] = {1,4,7,12,31,55,60}; Non_param_cdf<> new_cdf( z_values, z_values+7); build_cdf( val_range, val_range+9, new_cdf.z_begin(), new_cdf.z_end(), new_cdf.p_begin() ); Non_param_cdf<>::z_iterator z_it = new_cdf.z_begin(); for( ; z_it != new_cdf.z_end(); z_it++ ) { std::cout << "P( " << *z_it << " ) = " << new_cdf.prob( *z_it ) << std::endl; } std::cout << std::endl; build_cdf( val_range, val_range+9, new_cdf, true ); z_it = new_cdf.z_begin(); for( ; z_it != new_cdf.z_end(); z_it++ ) { std::cout << "P( " << *z_it << " ) = " << new_cdf.prob( *z_it ) << std::endl; } }
void DrawPlots(TString fn="rootplots/ttbar_partonLevel_histos_"+run+".root") { TFile *f = TFile::Open(fn); if (f==NULL) fatal("Cannot open file "+fn); TString pdf("Pdfs/top_plot_"+run+".pdf"); c = new TCanvas(); c->Print(pdf+"["); //divide canvas into quadrants c->Divide(2,2); TLatex tex; tex.SetNDC(); tex.DrawLatex(0.35,0.49,"Leptonic pseudotop"); c->cd(1); GetHisto(f,"pseudo_mass_matched")->Draw("e1"); c->Update(); c->cd(2); GetHisto(f,"pseudo_mass_unmatched")->Draw("e1"); c->Update(); c->cd(3); GetHisto(f,"pseudo_pt_matched")->Draw("e1 "); c->Update(); c->cd(4); GetHisto(f,"pseudo_pt_unmatched") ->Draw("e1 "); c->Print(pdf); c->cd(1); GetHisto(f,"pseudo_eta_matched")->Draw("e1 "); c->Update(); c->cd(2); GetHisto(f,"pseudo_eta_unmatched")->Draw("e1 "); c->Update(); c->cd(3); GetHisto(f,"whadronic")->Draw("e1 y+ "); c->Update(); c->cd(4); GetHisto(f,"wleptonic")->Draw("e1"); c->Print(pdf); c->cd(1); GetHisto(f,"m_top")->Draw("e1"); c->cd(2); GetHisto(f,"eta_top")->Draw("e1 c "); c->cd(3); GetHisto(f,"pt_top") ->Draw("e1 "); c->cd(4); GetHisto(f,"y_top")->Draw("e1 "); c->Print(pdf); c->cd(1); GetHisto(f,"eff_vs_topPt")->Draw("e1 "); c->cd(2); GetHisto(f,"neff_vs_topPt")->Draw("e1 "); c->cd(3); GetHisto(f,"eff_vs_topMass") ->Draw("e1 "); c->cd(4); GetHisto(f,"eff_vs_topeta") ->Draw("e1"); c->Print(pdf); c->cd(1); GetHisto(f,"pseudo_btop_mass")->Draw("e1 "); c->cd(2); GetHisto(f,"pseudo_HW_top")->Draw("e1 "); c->cd(3); GetHisto(f,"pseudb")->Draw("e1"); c->cd(4); GetHisto(f,"eff_vs_bmass")->Draw("e1"); c->Print(pdf); c->Print(pdf+"]"); }
double MVT::logp(const Vector &x) const { return pdf(x, true); }
double MVT::pdf(const Data *dp, bool logscale) const { const Vector &v(dynamic_cast<const VectorData *>(dp)->value()); return pdf(v, logscale); }
/** Computes the probability density function * * @param x Value * @param n Degrees of freedom * * \warning "n" must be > 0, otherwise n = |n|. */ virtual double pdf(double x, int n) { setNDF(n); return pdf(x); };
double WeightedMvnModel::pdf(Ptr<Data> dp, bool logscale)const{ return pdf(DAT(dp), logscale); }
double CM::pdf(const Ptr<Data> &dp, bool logscale) const { return pdf(*DAT(dp), logscale); }
double CM::pdf(const Data *dp, bool logscale) const { return pdf(*DAT(dp), logscale); }
double EuropeanPutBlack76::getVegaAnalytic() { if (!internalParamtersSet) calculateInternalOptionParameters(); return forward * sqrt(yearsToSettlement) * pdf(n_0_1, d1) * discountFactor; }
void fit_and_weights_norm(){ gROOT->ProcessLine(".x ~/cern/scripts/lhcbStyle.C"); //lhcbStyle(); gStyle->SetLabelSize(0.05,"x"); gStyle->SetLabelSize(0.05,"y"); gStyle->SetTitleSize(0.05,"x"); gStyle->SetPaperSize(20,26); gStyle->SetPadTopMargin(0.0); gStyle->SetPadRightMargin(0.05); // increase for colz plots gStyle->SetPadBottomMargin(0.0); gStyle->SetPadLeftMargin(0.14); gStyle->SetTitleH(0.01); // const std::string filename("/afs/cern.ch/work/a/apmorris/private/cern/ntuples/new_tuples/normalisation_samples/Lb2JpsipK_2011_2012_signal_withbdt_cut_05.root"); const std::string treename = "withbdt"; const std::string out_file_mass("~/cern/plots/fitting/Lb2JpsipK_2011_2012_mass_fit_after_bdtg3_05.png"); // TFile* file = TFile::Open( filename.c_str() ); if( !file ) std::cout << "file " << filename << " does not exist" << std::endl; TTree* tree = (TTree*)file->Get( treename.c_str() ); if( !tree ) std::cout << "tree " << treename << " does not exist" << std::endl; // -- signal, mass shape RooRealVar Lambda_b0_DTF_MASS_constr1("Lambda_b0_DTF_MASS_constr1","m(#chi_{c}pK^{-})", 5550., 5700., "MeV/c^{2}"); RooRealVar Jpsi_M("Jpsi_M","m(#mu#mu)", 3000., 3200., "MeV/c^{2}"); //RooRealVar chi_c_M("chi_c_M","m(J/#psi#gamma)", 3400., 3700., "MeV/c^{2}"); RooRealVar mean("mean","mean", 5630., 5610., 5650.); RooRealVar sigma1("sigma1","sigma1", 10., 1., 100.); RooRealVar sigma2("sigma2","sigma2", 30.0, 5.0, 300.0); RooRealVar alpha1("alpha1","alpha1", 1.0, 0.5, 5.0); RooRealVar n1("n1","n1", 1.8, 0.2, 15.0); RooRealVar alpha2("alpha2","alpha2", -0.5, -5.5, 0.0); RooRealVar n2("n2","n2", 0.7, 0.2, 10.0); //RooRealVar bkgcat_chic("bkgcat_chic","bkgcat_chic", 0, 100); RooRealVar bdtg3("bdtg3", "bdtg3", -1.0, 1.0); // RooRealVar frac2("frac2","frac2", 0.3, 0., 1.); Lambda_b0_DTF_MASS_constr1.setBins(75); RooGaussian gauss1("gauss1","gauss1", Lambda_b0_DTF_MASS_constr1, mean, sigma1); RooGaussian gauss2("gauss2","gauss2", Lambda_b0_DTF_MASS_constr1, mean, sigma2); RooCBShape cb1("cb1","cb1", Lambda_b0_DTF_MASS_constr1, mean, sigma1, alpha1, n1); RooCBShape cb2("cb2","cb2", Lambda_b0_DTF_MASS_constr1, mean, sigma2, alpha2, n2); RooAddPdf sig("sig", "sig", RooArgList(cb1, cb2), RooArgList( frac2 )); RooRealVar cbRatio("cbRatio","cb Ratio", 0.8, 0.1, 1.0); RooRealVar sigYield("sigYield","sig Yield", 4e2, 1e1, 1e4); RooRealVar bgYield("bgYield","bg Yield", 1e2, 1e0, 5e5); //put in values from fit_MC here <<--- DON'T FORGET TO CHANGE THESE IF THE FIT CHANGES!!! /* EXT PARAMETER INTERNAL INTERNAL NO. NAME VALUE ERROR STEP SIZE VALUE 1 alpha1 1.74154e+00 3.36750e-02 1.24897e-04 -4.64754e-01 2 alpha2 -2.02379e+00 6.38694e-02 1.18078e-04 2.87434e+00 3 cbRatio 3.81630e-01 2.53217e-02 1.04396e-03 -3.83487e-01 4 mean 5.61983e+03 1.06900e-02 5.57074e-05 -9.73350e-02 5 n1 3.61886e+00 1.29299e-01 2.50836e-04 -5.68053e-01 6 n2 3.28978e+00 1.59452e-01 3.00100e-04 -3.78398e-01 7 sigma1 7.37006e+00 1.49989e-01 2.60360e-05 -1.05787e+00 8 sigma2 4.90330e+00 4.88847e-02 5.78092e-06 -1.44570e+00 */ alpha1.setVal( 1.74154e+00 ); alpha2.setVal( -2.02379e+00 ); n1.setVal( 3.61886e+00 ); n2.setVal( 3.28978e+00 ); frac2.setVal( 3.81630e-01 ); sigma1.setVal( 7.37006e+00 ); sigma2.setVal( 4.90330e+00 ); alpha1.setConstant( true ); alpha2.setConstant( true ); frac2.setConstant( true ); n1.setConstant( true ); n2.setConstant( true ); sigma1.setConstant( true ); sigma2.setConstant( true ); // -- bg, mass shape RooRealVar a1("a1","a1", -0.1, -0.5, 0.5); RooChebychev comb("comb","comb", Lambda_b0_DTF_MASS_constr1, a1); RooRealVar mean3("mean3","mean3", 5560., 5500., 5600.); RooRealVar sigma3("sigma3","sigma3", 5., 1., 10.); RooRealVar frac3("frac3","frac", 0.2, 0.0, 0.3); RooGaussian gauss3("gauss3","gauss3", Lambda_b0_DTF_MASS_constr1, mean3, sigma3); RooAddPdf bg("bg","bg", RooArgList(gauss3, comb), RooArgList(frac3)); // -- add signal & bg RooAddPdf pdf("pdf", "pdf", RooArgList(sig, comb), RooArgList( sigYield, bgYield)); RooArgSet obs; obs.add(Lambda_b0_DTF_MASS_constr1); obs.add(Jpsi_M); //obs.add(chi_c_M); //obs.add(proton_ProbNNp); //obs.add(proton_ProbNNk); //obs.add(kaon_ProbNNp); //obs.add(kaon_ProbNNk); RooDataSet ds("ds","ds", obs, RooFit::Import(*tree)); RooPlot* plot = Lambda_b0_DTF_MASS_constr1.frame(); RooFitResult * result = pdf.fitTo( ds, RooFit::Extended() ); ds.plotOn( plot ); pdf.plotOn( plot ); RooPlot* plotPullMass = Lambda_b0_DTF_MASS_constr1.frame(); plotPullMass->addPlotable( plot->pullHist() ); //plotPullMass->SetMinimum(); //plotPullMass->SetMaximum(); TCanvas* c = new TCanvas(); TPad* pad1 = new TPad("pad1","pad1", 0, 0.3, 1, 1.0); pad1->SetBottomMargin(0.0); pad1->SetTopMargin(0.01); pad1->Draw(); c->cd(); TPad* pad2 = new TPad("pad2","pad2", 0, 0., 1, 0.3); pad2->SetBottomMargin(0.0); pad2->SetTopMargin(0.0); pad2->Draw(); pdf.plotOn( plot, RooFit::Components( sig ), RooFit::LineColor( kTeal ), RooFit::LineStyle(kDashed) ); pdf.plotOn( plot, RooFit::Components( comb ), RooFit::LineColor( kOrange ), RooFit::LineStyle(kDashed) ); pdf.plotOn( plot, RooFit::Components( gauss3 ), RooFit::LineColor( kViolet ), RooFit::LineStyle(kDashed) ); pad1->cd(); plot->Draw(); pad2->cd(); plotPullMass->Draw("AP"); c->SaveAs(out_file_mass.c_str()); /* RooStats::SPlot* sData = new RooStats::SPlot("sData","An SPlot", ds, &pdf, RooArgList(sigYield, bgYield) ); RooDataSet * dataw_z = new RooDataSet(ds.GetName(),ds.GetTitle(),&ds,*(ds.get()),0,"sigYield_sw") ; TTree *tree_data = (TTree*)dataw_z->tree(); TFile * newfile = TFile::Open("/afs/cern.ch/work/a/apmorris/private/cern/ntuples/new_tuples/weighted_data.root","RECREATE"); tree_data->Write(); newfile->Close(); */ /* TCanvas* d = new TCanvas(); RooPlot* w_chi_c_Mp = chi_c_Mp.frame(); dataw_z->plotOn(w_chi_c_Mp, RooFit::DataError(RooAbsData::SumW2), RooFit::Binning(20)) ; w_chi_c_Mp->Draw(); d->SaveAs("m_chicp_sweighted.png"); TCanvas* e = new TCanvas(); RooPlot* w_mass_pK = mass_pK.frame(); dataw_z->plotOn(w_mass_pK, RooFit::DataError(RooAbsData::SumW2), RooFit::Binning(20)) ; w_mass_pK->Draw(); e->SaveAs("m_pK_sweighted.png"); */ /* TCanvas* f = new TCanvas(); RooPlot* w_Jpsi_M = Jpsi_M.frame(); dataw_z->plotOn(w_Jpsi_M, RooFit::DataError(RooAbsData::SumW2), RooFit::Binning(20)) ; w_Jpsi_M->Draw(); f->SaveAs("~/cern/plots/m_Jpsi_sweighted.png"); TCanvas* g = new TCanvas(); RooPlot* w_chi_c_M = chi_c_M.frame(); dataw_z->plotOn(w_chi_c_M, RooFit::DataError(RooAbsData::SumW2), RooFit::Binning(20)) ; w_chi_c_M->Draw(); g->SaveAs("~/cern/plots/m_Chic_sweighted.png"); */ }
double EuropeanPutBlack76::getGammaAnalytic() { if (!internalParamtersSet) calculateInternalOptionParameters(); return pdf(n_0_1, d1) * discountFactor / (forward * standardDeviation); }
static double Wdraw(double t, double e) { double vdraw = Vdraw(t, e); double n = (vdraw * vdraw) + ((e - t) * pdf(e - t) + (e + t) * pdf(e + t)); double d = cdf(e - t) - cdf(-e - t); return n / d; }
static double Vdraw(double t, double e) { return (pdf(-e - t) - pdf(e - t)) / (cdf(e - t) - cdf(-e - t)); }
Real JohnsonSBDistribution::pdf(const Real & x) const { return pdf(x, _lower, _upper, _alpha_1, _alpha_2); }
static void constraints() { typedef typename Distribution::value_type value_type; const Distribution& dist = DistributionConcept<Distribution>::get_object(); value_type x = 0; // The result values are ignored in all these checks. check_result<value_type>(cdf(dist, x)); check_result<value_type>(cdf(complement(dist, x))); check_result<value_type>(pdf(dist, x)); check_result<value_type>(quantile(dist, x)); check_result<value_type>(quantile(complement(dist, x))); check_result<value_type>(mean(dist)); check_result<value_type>(mode(dist)); check_result<value_type>(standard_deviation(dist)); check_result<value_type>(variance(dist)); check_result<value_type>(hazard(dist, x)); check_result<value_type>(chf(dist, x)); check_result<value_type>(coefficient_of_variation(dist)); check_result<value_type>(skewness(dist)); check_result<value_type>(kurtosis(dist)); check_result<value_type>(kurtosis_excess(dist)); check_result<value_type>(median(dist)); // // we can't actually test that at std::pair is returned from these // because that would mean including some std lib headers.... // range(dist); support(dist); check_result<value_type>(cdf(dist, f)); check_result<value_type>(cdf(complement(dist, f))); check_result<value_type>(pdf(dist, f)); check_result<value_type>(quantile(dist, f)); check_result<value_type>(quantile(complement(dist, f))); check_result<value_type>(hazard(dist, f)); check_result<value_type>(chf(dist, f)); check_result<value_type>(cdf(dist, d)); check_result<value_type>(cdf(complement(dist, d))); check_result<value_type>(pdf(dist, d)); check_result<value_type>(quantile(dist, d)); check_result<value_type>(quantile(complement(dist, d))); check_result<value_type>(hazard(dist, d)); check_result<value_type>(chf(dist, d)); check_result<value_type>(cdf(dist, l)); check_result<value_type>(cdf(complement(dist, l))); check_result<value_type>(pdf(dist, l)); check_result<value_type>(quantile(dist, l)); check_result<value_type>(quantile(complement(dist, l))); check_result<value_type>(hazard(dist, l)); check_result<value_type>(chf(dist, l)); check_result<value_type>(cdf(dist, i)); check_result<value_type>(cdf(complement(dist, i))); check_result<value_type>(pdf(dist, i)); check_result<value_type>(quantile(dist, i)); check_result<value_type>(quantile(complement(dist, i))); check_result<value_type>(hazard(dist, i)); check_result<value_type>(chf(dist, i)); unsigned long li = 1; check_result<value_type>(cdf(dist, li)); check_result<value_type>(cdf(complement(dist, li))); check_result<value_type>(pdf(dist, li)); check_result<value_type>(quantile(dist, li)); check_result<value_type>(quantile(complement(dist, li))); check_result<value_type>(hazard(dist, li)); check_result<value_type>(chf(dist, li)); }
void quantile_sanity_check(T& data, const char* type_name, const char* test) { #ifndef ERROR_REPORTING_MODE typedef Real value_type; // // Tests with type real_concept take rather too long to run, so // for now we'll disable them: // if(!boost::is_floating_point<value_type>::value) return; std::cout << "Testing: " << type_name << " quantile sanity check, with tests " << test << std::endl; // // These sanity checks test for a round trip accuracy of one half // of the bits in T, unless T is type float, in which case we check // for just one decimal digit. The problem here is the sensitivity // of the functions, not their accuracy. This test data was generated // for the forward functions, which means that when it is used as // the input to the inverses then it is necessarily inexact. This rounding // of the input is what makes the data unsuitable for use as an accuracy check, // and also demonstrates that you can't in general round-trip these functions. // It is however a useful sanity check. // value_type precision = static_cast<value_type>(ldexp(1.0, 1 - boost::math::policies::digits<value_type, boost::math::policies::policy<> >() / 2)) * 100; if(boost::math::policies::digits<value_type, boost::math::policies::policy<> >() < 50) precision = 1; // 1% or two decimal digits, all we can hope for when the input is truncated to float for(unsigned i = 0; i < data.size(); ++i) { // // Test case 493 fails at float precision: not enough bits to get // us back where we started: // if((i == 493) && boost::is_same<float, value_type>::value) continue; if(data[i][4] == 0) { BOOST_CHECK(0 == quantile(boost::math::non_central_beta_distribution<value_type>(data[i][0], data[i][1], data[i][2]), data[i][4])); } else if(data[i][4] < 0.9999f) { value_type p = quantile(boost::math::non_central_beta_distribution<value_type>(data[i][0], data[i][1], data[i][2]), data[i][4]); value_type pt = data[i][3]; BOOST_CHECK_CLOSE_EX(pt, p, precision, i); } if(data[i][5] == 0) { BOOST_CHECK(1 == quantile(complement(boost::math::non_central_beta_distribution<value_type>(data[i][0], data[i][1], data[i][2]), data[i][5]))); } else if(data[i][5] < 0.9999f) { value_type p = quantile(complement(boost::math::non_central_beta_distribution<value_type>(data[i][0], data[i][1], data[i][2]), data[i][5])); value_type pt = data[i][3]; BOOST_CHECK_CLOSE_EX(pt, p, precision, i); } if(boost::math::tools::digits<value_type>() > 50) { // // Sanity check mode, accuracy of // the mode is at *best* the square root of the accuracy of the PDF: // value_type m = mode(boost::math::non_central_beta_distribution<value_type>(data[i][0], data[i][1], data[i][2])); if((m == 1) || (m == 0)) break; value_type p = pdf(boost::math::non_central_beta_distribution<value_type>(data[i][0], data[i][1], data[i][2]), m); if(m * (1 + sqrt(precision) * 10) < 1) { BOOST_CHECK_EX(pdf(boost::math::non_central_beta_distribution<value_type>(data[i][0], data[i][1], data[i][2]), m * (1 + sqrt(precision) * 10)) <= p, i); } if(m * (1 - sqrt(precision)) * 10 > boost::math::tools::min_value<value_type>()) { BOOST_CHECK_EX(pdf(boost::math::non_central_beta_distribution<value_type>(data[i][0], data[i][1], data[i][2]), m * (1 - sqrt(precision)) * 10) <= p, i); } } } #endif }
double DM::pdf(const Data *dp, bool logscale) const { return pdf(DAT(dp)->value(), logscale); }
double EvtPropSLPole::calBreitWigner(EvtParticle *pmeson, EvtPoint1D point){ EvtId mesnum = pmeson->getId(); double _mass = EvtPDL::getMeanMass(mesnum); double _width = EvtPDL::getWidth(mesnum); double _maxRange = EvtPDL::getMaxRange(mesnum); EvtSpinType::spintype mesontype=EvtPDL::getSpinType(mesnum); _includeDecayFact=true; _includeBirthFact=true; _spin = mesontype; _blatt = 3.0; double maxdelta = 15.0*_width; if ( _maxRange > 0.00001 ) { _massMax=_mass+maxdelta; _massMin=_mass-_maxRange; } else{ _massMax=_mass+maxdelta; _massMin=_mass-15.0*_width; } _massMax=_mass+maxdelta; if ( _massMin< 0. ) _massMin=0.; EvtParticle* par=pmeson->getParent(); double maxMass=-1.; if ( par != 0 ) { if ( par->hasValidP4() ) maxMass=par->mass(); for ( size_t i=0;i<par->getNDaug();i++) { EvtParticle *tDaug=par->getDaug(i); if ( pmeson != tDaug ) maxMass-=EvtPDL::getMinMass(tDaug->getId()); } } EvtId *dauId=0; double *dauMasses=0; size_t nDaug = pmeson->getNDaug(); if ( nDaug > 0) { dauId=new EvtId[nDaug]; dauMasses=new double[nDaug]; for (size_t j=0;j<nDaug;j++) { dauId[j]=pmeson->getDaug(j)->getId(); dauMasses[j]=pmeson->getDaug(j)->mass(); } } EvtId *parId=0; EvtId *othDaugId=0; EvtParticle *tempPar=pmeson->getParent(); if (tempPar) { parId=new EvtId(tempPar->getId()); if ( tempPar->getNDaug()==2 ) { if ( tempPar->getDaug(0) == pmeson ) othDaugId=new EvtId(tempPar->getDaug(1)->getId()); else othDaugId=new EvtId(tempPar->getDaug(0)->getId()); } } if ( nDaug!=2) return calBreitWignerBasic(maxMass); if ( _width< 0.00001) return 1.0; //first figure out L - take the lowest allowed. EvtSpinType::spintype spinD1=EvtPDL::getSpinType(dauId[0]); EvtSpinType::spintype spinD2=EvtPDL::getSpinType(dauId[1]); int t1=EvtSpinType::getSpin2(spinD1); int t2=EvtSpinType::getSpin2(spinD2); int t3=EvtSpinType::getSpin2(_spin); int Lmin=-10; // allow for special cases. if (Lmin<-1 ) { //There are some things I don't know how to deal with if ( t3>4) return calBreitWignerBasic(maxMass); if ( t1>4) return calBreitWignerBasic(maxMass); if ( t2>4) return calBreitWignerBasic(maxMass); //figure the min and max allowwed "spins" for the daughters state Lmin=std::max(t3-t2-t1,std::max(t2-t3-t1,t1-t3-t2)); if (Lmin<0) Lmin=0; assert(Lmin==0||Lmin==2||Lmin==4); } //double massD1=EvtPDL::getMeanMass(dauId[0]); //double massD2=EvtPDL::getMeanMass(dauId[1]); double massD1=dauMasses[0]; double massD2=dauMasses[1]; // I'm not sure how to define the vertex factor here - so retreat to nonRel code. if ( (massD1+massD2)> _mass ) return calBreitWignerBasic(maxMass); //parent vertex factor not yet implemented double massOthD=-10.; double massParent=-10.; int birthl=-10; if ( othDaugId) { EvtSpinType::spintype spinOth=EvtPDL::getSpinType(*othDaugId); EvtSpinType::spintype spinPar=EvtPDL::getSpinType(*parId); int tt1=EvtSpinType::getSpin2(spinOth); int tt2=EvtSpinType::getSpin2(spinPar); int tt3=EvtSpinType::getSpin2(_spin); //figure the min and max allowwed "spins" for the daughters state if ( (tt1<=4) && ( tt2<=4) ) { birthl=std::max(tt3-tt2-tt1,std::max(tt2-tt3-tt1,tt1-tt3-tt2)); if (birthl<0) birthl=0; massOthD=EvtPDL::getMeanMass(*othDaugId); massParent=EvtPDL::getMeanMass(*parId); } } double massM=_massMax; if ( (maxMass > -0.5) && (maxMass < massM) ) massM=maxMass; //special case... if the parent mass is _fixed_ we can do a little better //and only for a two body decay as that seems to be where we have problems // Define relativistic propagator amplitude EvtTwoBodyVertex vd(massD1,massD2,_mass,Lmin/2); vd.set_f(_blatt); EvtPropBreitWignerRel bw(_mass,_width); EvtMassAmp amp(bw,vd); // if ( _fixMassForMax) amp.fixUpMassForMax(); // else std::cout << "problem problem\n"; if ( _includeDecayFact) { amp.addDeathFact(); amp.addDeathFactFF(); } if ( massParent>-1.) { if ( _includeBirthFact ) { EvtTwoBodyVertex vb(_mass,massOthD,massParent,birthl/2); amp.setBirthVtx(vb); amp.addBirthFact(); amp.addBirthFactFF(); } } EvtAmpPdf<EvtPoint1D> pdf(amp); double ampVal = sqrt(pdf.evaluate(point)); if ( parId) delete parId; if ( othDaugId) delete othDaugId; if ( dauId) delete [] dauId; if ( dauMasses) delete [] dauMasses; return ampVal; }
Spectrum sample(BSDFSamplingRecord &bRec, const Point2 &sample) const { if (Frame::cosTheta(bRec.wi) < 0 || ((bRec.component != -1 && bRec.component != 0) || !(bRec.typeMask & EGlossyReflection))) return Spectrum(0.0f); djb::vec3 wm = djb::vec3(m_tabular->sample(djb::dir(djb::vec3(bRec.wi.x, bRec.wi.y, bRec.wi.z)), sample.x, sample.y)); Normal m(wm.x, wm.y, wm.z); /* Perfect specular reflection based on the microfacet normal */ bRec.wo = reflect(bRec.wi, m); bRec.eta = 1.0f; bRec.sampledComponent = 0; bRec.sampledType = EGlossyReflection; /* Side check */ if (Frame::cosTheta(bRec.wo) <= 0) return Spectrum(0.0f); djb::vec3 weight = m_sgd->evalp(djb::dir(djb::vec3(bRec.wo.x, bRec.wo.y, bRec.wo.z)), djb::dir(djb::vec3(bRec.wi.x, bRec.wi.y, bRec.wi.z))) / pdf(bRec, ESolidAngle); return Color3(weight.x, weight.y, weight.z); }
void SensorModel< BeliefCell<N> >::computeBeliefLUT() { /* // Old calculation (before IJAR 2015) double L = 1.0, L_i = 1.0, eta = 1.0; double m, bel, pl, eta_e; */ // /* // New calculation (since IJAR 2015) double eta = 0.0, phi_c_i = 0.0; double m, bel, pl, eta_e, halfCellDist, sigmaDist; // */ BeliefFunction *bf; // FIXME: Lookup table not correct, because iteration is done over more values than cells because of discretization m_beliefDistScale = 1000.0; // default scaling factor /* l_wrn( "XXX" ); m_beliefDistScale = 1.0 / 0.05; // XXX */ world_t maxDist = m_beliefSigmaInverse * 6; // Calculate the values up to 6 sigma. Before and after this point, the values are aprox. equal to belief[Before]Zero size_t maxDistIdx = maxDist * m_beliefDistScale; if( maxDistIdx > MAX_SIZE ) { maxDistIdx = MAX_SIZE; m_beliefDistScale = maxDistIdx / maxDist; l_wrn( "Distance scale for belief LUT was reduced to " << m_beliefDistScale << " in order to limit LUT size to " << MAX_SIZE << " entries." ); } halfCellDist = m_beliefDistScale * Config::getDouble( "MAP_DELTA", 0.05 ) * 0.5; sigmaDist = m_beliefDistScale * m_beliefSigmaInverse; l_dbg( "Belief LUT size " << maxDistIdx << ", distance scale " << m_beliefDistScale << "." ); size_t numDist = 2 * maxDistIdx, // in front of and behind the hit cell hitIdx = maxDistIdx; // hit cell is in the middle assert( maxDistIdx > 0 ); m_beliefLUT.resize( maxDistIdx + 1 ); // zero is saved twice m_beliefBehindLUT.resize( maxDistIdx ); /* // Old calculation (before IJAR 2015) std::vector<double> pl_z( numDist ); // belief calculation part 1 (according to Reineking 2014, Figure 4.6 first for-loop) for( size_t i = 0; i < numDist; i++ ) { world_t dist = ( i <= hitIdx ? hitIdx - i : i - hitIdx ) / m_beliefDistScale; // actual distance to hit cell // pl_z[i] = NormalDistribution::pl( dist, m_beliefSigmaInverseSqr ); // pl[x_t, C=i, \not r](z_t) (a normalized Gaussian) pl_z[i] = NormalDistribution::cdfStddev( dist + 2*m_beliefSigmaInverse, m_beliefSigmaInverse ) - NormalDistribution::cdfStddev( dist - 2*m_beliefSigmaInverse, m_beliefSigmaInverse ); L *= (1.0 - pl_z[i]); // \prod_i=0^M (1 - pl_{z;i}) } eta = 1.0 / (1.0 - L); // normalization for GBT */ //std::cerr << "\n\n\n\n"; // /* // New calculation (since IJAR 2015) (TODO: Ref to journal paper equation) std::vector<double> pdf( numDist ); for( size_t i = 0; i < numDist; i++ ) { world_t dist = ( i <= hitIdx ? hitIdx - i : i - hitIdx ) / m_beliefDistScale; // actual distance to hit cell pdf[i] = NormalDistribution::pdf( dist, m_beliefSigmaInverseSqr ); // phi( z_t, mu_c, sigma_z^2 ) eta += pdf[i]; //std::cerr << dist << " " << pdf[i] << std::endl; } eta = 1.0 / eta; // */ //std::cerr << 1.0 / eta << std::endl; // iterate over all distances for( size_t i = 0; i < numDist; i++ ) { // calc index in LUT if( i <= hitIdx ) { // in front of hit cell bf = &m_beliefLUT[hitIdx - i]; } else { // behind hit cell bf = &m_beliefBehindLUT[i - hitIdx]; } /* // Old calculation (before IJAR 2015) // belief calculation part 2 (according to Reineking 2014, Figure 4.6 second for-loop) L_i *= (1.0 - pl_z[i]); // \prod_j=0^i (1 - pl_{z;j}) bel = eta * (L_i - L); // bel[x_t, z_t, \not r](C=C_i) pl = eta * pl_z[i]; // pl[x_t, z_t, \not r](C=i) eta_e = 1.0 / ( 1.0 - m_beliefOccPrior * (1.0 - pl) ); // normalization for e_i if( pl_z[i] == 1.0 ) { // we have to prevent division by zero (compare sensor_models_laser.py -> inverse_sensor_model) if( i > 1 && pl_z[i-1] == 1.0 ) { m = 0.0; // the resulting product might be 0 anyways -> check neighboring cell } else { double L_new = 1.0; for( int j = 0; j < numDist; j++ ) { if( j != i ) L_new *= (1.0 - pl_z[j]); } m = eta * pl_z[i] * L_new; } } else { m = eta * pl_z[i] * L / (1.0 - pl_z[i]); // m[x_t, z_t, \not r](C=i) } //l_dbg( pl_z[d] << " " << L_i << " "<< m << " "<< bel<< " "<< pl << " "<< eta_e ); bf->o = (1 - m_beliefRandom) * eta_e * (m_beliefOccPrior * pl + (1 - m_beliefOccPrior) * m); bf->e = (1 - m_beliefRandom) * eta_e * (1 - m_beliefOccPrior) * bel; bf->Theta = 1 - bf->o - bf->e; */ // /* // New calculation (since IJAR 2015) (TODO: Ref to journal paper equation) //phi_c_i += pdf[i]; // Cumulative calulation of sum_{c in compl C_i) phi_c phi_c_i = 0; for( size_t j = 0; (j <= i + m_beliefSigmaInverseFactor*sigmaDist + halfCellDist) && (j < numDist); j++ ) phi_c_i += pdf[j]; //m = pdf[i] * eta; // m(C={i}|x_t, z_t, not r) m = 0; for( size_t j = i >= halfCellDist ? i - halfCellDist : 0; (j <= i + halfCellDist) && (j < numDist); j++ ) // take cell size into account m += pdf[j]; m *= eta; pl = m; // pl(C={i}|x_t, z_t, not r), actual the same as m for this special case bel = 1 - phi_c_i * eta; // bel(C_i|x_t, z_t, not r) eta_e = 1.0 / (1 - m_beliefOccPrior * (1 - pl)); bf->o = (1 - m_beliefRandom) * eta_e * (m_beliefOccPrior * pl + (1 - m_beliefOccPrior) * m); bf->e = (1 - m_beliefRandom) * eta_e * (1 - m_beliefOccPrior) * bel; bf->Theta = 1 - bf->o - bf->e; // */ } // set zero dist in behindLUT as well m_beliefBehindLUT[0] = m_beliefLUT[0]; m_beliefZero.set( m_beliefRandom, 0.0, 1 - m_beliefRandom ); // random on Theta, rest on empty m_beliefBehindZero.set( 1.0, 0.0, 0.0 ); // only mass on Theta }
Spectrum sample(BSDFSamplingRecord &bRec, Float &pdf_, const Point2 &sample_) const { Spectrum res = sample(bRec, sample_); pdf_ = pdf(bRec, ESolidAngle); return res; }
double MVT::pdf(const VectorData *dp, bool logscale) const { return pdf(dp->value(), logscale); }
//! Evaluate the negative log-likelihood function value double eval(double mu_on, double mu_off) const { boost::math::poisson pmf_off(mu_off); boost::math::poisson pmf_on(mu_on); return -2. * log(pdf(pmf_on, n_on_) * pdf(pmf_off, n_off_)); }
void testPDF (double (*f) (void), double (*pdf)(double), const char *name) { double count[BINS], p[BINS]; double a = -5.0, b = +5.0 ; double dx = (b - a) / BINS ; int i,j,status = 0, status_i =0 ; for (i = 0; i < BINS; i++) count[i] = 0 ; for (i = 0; i < N; i++) { double r = f (); if (r < b && r > a) { j = (int)((r - a)/dx) ; count[j]++; } } for (i = 0; i < BINS; i++) { /* Compute an approximation to the integral of p(x) from x to x+dx using Simpson's rule */ double x = a + i * dx ; #define STEPS 100 double sum = 0 ; if (fabs(x) < 1e-10) /* hit the origin exactly */ x = 0.0 ; for (j = 1; j < STEPS; j++) sum += pdf(x + j * dx / STEPS) ; p[i] = 0.5 * (pdf(x) + 2*sum + pdf(x + dx - 1e-7)) * dx / STEPS ; } for (i = 0; i < BINS; i++) { double x = a + i * dx ; double d = fabs(count[i] - N*p[i]) ; if (p[i] != 0) { double s = d / sqrt(N*p[i]) ; status_i = (s > 5) && (d > 1) ; } else { status_i = (count[i] != 0) ; } status |= status_i ; if (status_i) gsl_test (status_i, "%s [%g,%g) (%g/%d=%g observed vs %g expected)", name, x, x+dx, count[i],N,count[i]/N, p[i]) ; } if (status == 0) gsl_test (status, "%s, sampling against pdf over range [%g,%g) ", name, a, b) ; }
FormSimularCuotas::FormSimularCuotas(QWidget *parent) : EVentana(parent), Ui::FormSimularCuotasBase() { setupUi(this); setWindowTitle( "Simulador de cuotas" ); setWindowIcon( QIcon( ":/imagenes/simular_cuota.png" ) ); ActSimular = new QAction( this ); ActSimular->setText( "Simular" ); ActSimular->setStatusTip( "Simula los pagos según los datos ingresados" ); ActSimular->setIcon( QIcon( ":/imagenes/simular_cuota.png" ) ); connect( ActSimular, SIGNAL( triggered() ), this, SLOT( simular() ) ); ActImprimir = new QAction( this ); ActImprimir->setText( "Imprimir" ); ActImprimir->setText( QString::fromUtf8( "Imprimir" ) ); ActImprimir->setIcon( QIcon( ":/imagenes/impresora.png" ) ); connect( ActImprimir, SIGNAL( triggered() ), this, SLOT( imprimir() ) ); ActPdf = new QAction( this ); ActPdf->setText( "PDF" ); ActPdf->setStatusTip( "Convierte a PDF la simulacion actual" ); ActPdf->setIcon( QIcon( ":/imagenes/acroread.png" ) ); connect( ActPdf, SIGNAL( triggered() ), this, SLOT( pdf() ) ); ActConfirmar = new QAction( this ); ActConfirmar->setText( "Confirmar" ); connect( ActConfirmar, SIGNAL( triggered() ), this, SLOT( confirmar() ) ); modelo = new MSimularCuotas( this ); connect( DSBEntrega, SIGNAL( valueChanged( double ) ), this, SLOT( cambioEntrega( double ) ) ); connect( DSBImporte, SIGNAL( valueChanged( double ) ), this, SLOT( cambioImporte( double ) ) ); connect( DSBInteres, SIGNAL( valueChanged( double ) ), this, SLOT( cambioInteres( double ) ) ); connect( SBCantidad, SIGNAL( valueChanged( int ) ), this, SLOT( cambioCantidad( int ) ) ); connect( CBPeriodo , SIGNAL( currentIndexChanged( int ) ), this, SLOT( cambioPeriodo( int ) ) ); connect( DEInicio , SIGNAL( dateChanged( QDate ) ), this, SLOT( cambioFechaInicio( QDate ) ) ); CBPeriodo->insertItem( MPlanCuota::Semanal , "Semanal" , MPlanCuota::Semanal ); CBPeriodo->insertItem( MPlanCuota::Quincenal , "Quincenal" , MPlanCuota::Quincenal ); CBPeriodo->insertItem( MPlanCuota::Mensual , "Mensual" , MPlanCuota::Mensual ); CBPeriodo->insertItem( MPlanCuota::BiMensual , "Bimensual" , MPlanCuota::BiMensual ); CBPeriodo->insertItem( MPlanCuota::Trimestral , "Trimestral" , MPlanCuota::Trimestral ); CBPeriodo->insertItem( MPlanCuota::Cuatrimestral, "Cuatrimestral" , MPlanCuota::Cuatrimestral ); CBPeriodo->insertItem( MPlanCuota::Seximestral , "Semestral" , MPlanCuota::Seximestral ); CBPeriodo->insertItem( MPlanCuota::Anual , "Anual" , MPlanCuota::Anual ); DEInicio->setDate( QDate::currentDate() ); preferencias *p = preferencias::getInstancia(); p->inicio(); p->beginGroup( "Preferencias" ); p->beginGroup( "Cuotas" ); CBPeriodo->setCurrentIndex( p->value( "id-periodo", 2 ).toInt() ); DSBInteres->setValue( p->value( "interes", 10.00 ).toDouble() ); //CkBInicioPeriodo->setChecked( p->value( "inicio-periodo", false ).toBool() ); p->endGroup(); p->endGroup(); p = 0; addAction( ActSimular ); addAction( ActImprimir ); addAction( ActPdf ); addAction( new EActCerrar( this ) ); _id_cliente = -1; _tipo_comprobante = MPlanCuota::Factura; }
bool Recola_Interface::Initialize(const string &path,const string &file, MODEL::Model_Base *const model, BEAM::Beam_Spectra_Handler *const beam, PDF::ISR_Handler *const isr) { // find RECOLA installation prefix with several overwrite options struct stat st; Data_Reader reader(" ",";","#","="); s_ignore_model = reader.GetValue<int>("RECOLA_IGNORE_MODEL",0); s_exit_on_error = reader.GetValue<int>("RECOLA_EXIT_ON_ERROR",1); if (s_ignore_model) msg_Info()<<METHOD<<"(): Recola will use the " <<"Standard Model even if you set a " <<"different model without warning." <<std::endl; s_recolaprefix = rpa->gen.Variable("SHERPA_CPP_PATH")+"/Process/Recola"; s_getPDF_default = reader.GetValue<int>("RECOLA_GETPDF_DEFAULT",0); if(stat(s_recolaprefix.c_str(),&st) != 0) s_recolaprefix = RECOLA_PREFIX; s_recolaprefix = reader.GetValue<string>("RECOLA_PREFIX", s_recolaprefix); msg_Info()<<"Initialising Recola generator from "<<s_recolaprefix<<endl; if(MODEL::s_model->Name() != "SM"){ THROW(fatal_error, "ONLY Standard Model so far supported in RECOLA"); } // load library dynamically s_loader->AddPath(s_recolaprefix); if (!s_loader->LoadLibrary("recola")) THROW(fatal_error, "Failed to load librecola."); int recolaVerbosity=0; recolaVerbosity = reader.GetValue<int>("RECOLA_VERBOSITY",recolaVerbosity); if(recolaVerbosity<0 || recolaVerbosity >2){ cout << "no valid Value for RECOLA_VERBOSITY"<< endl; cout << "Verbosity set to 'silent'" << endl; recolaVerbosity = 0; } set_print_level_squared_amplitude_rcl(recolaVerbosity); set_print_level_amplitude_rcl(recolaVerbosity); set_print_level_correlations_rcl(recolaVerbosity); string recolaOutput = reader.GetValue<string>("RECOLA_OUTPUT","*"); set_output_file_rcl(recolaOutput); int recolaOnShellZW = reader.GetValue<int>("RECOLA_ONSHELLZW",0); // set particle masses/widths if(recolaOnShellZW != 0){ set_onshell_mass_z_rcl(Flavour(kf_Z).Mass(),Flavour(kf_Z).Width()); set_onshell_mass_w_rcl(Flavour(kf_Wplus).Mass(),Flavour(kf_Wplus).Width()); } else{ set_pole_mass_z_rcl(Flavour(kf_Z).Mass(),Flavour(kf_Z).Width()); set_pole_mass_w_rcl(Flavour(kf_Wplus).Mass(),Flavour(kf_Wplus).Width()); } set_pole_mass_h_rcl(Flavour(kf_h0).Mass(),Flavour(kf_h0).Width()); set_pole_mass_electron_rcl(Flavour(kf_e).Mass()); set_pole_mass_muon_rcl(Flavour(kf_mu).Mass(),Flavour(kf_mu).Width()); set_pole_mass_tau_rcl(Flavour(kf_tau).Mass(),Flavour(kf_tau).Width()); set_pole_mass_up_rcl(Flavour(kf_u).Mass()); set_pole_mass_down_rcl(Flavour(kf_d).Mass()); set_pole_mass_strange_rcl(Flavour(kf_s).Mass()); set_pole_mass_charm_rcl(Flavour(kf_c).Mass(),Flavour(kf_c).Width()); set_pole_mass_bottom_rcl(Flavour(kf_b).Mass(),Flavour(kf_b).Width()); set_pole_mass_top_rcl(Flavour(kf_t).Mass(),Flavour(kf_t).Width()); s_light_fermion_threshold = reader.GetValue<double>("RECOLA_LIGHT_FERMION_THRESHOLD",0); set_light_fermions_rcl(s_light_fermion_threshold); set_delta_ir_rcl(0.0,M_PI*M_PI/6.0); // adapts the conventions from COLLIER to Catani-Seymour PDF::PDF_Base *pdf(NULL); pdf=isr->PDF(0); s_default_alphaqcd=pdf->ASInfo().m_asmz; s_default_scale=pdf->ASInfo().m_mz2; int pdfnf=pdf->ASInfo().m_flavs.size(); s_default_flav=pdfnf; if (pdfnf>10) pdfnf-=10; if (pdfnf==-1) pdfnf=6; double cmass(0), bmass(0), tmass(0); if (pdf->ASInfo().m_allflavs.size()==0){ cmass=Flavour(kf_c).Mass(); bmass=Flavour(kf_b).Mass(); tmass=Flavour(kf_t).Mass(); } else{ cmass=pdf->ASInfo().m_allflavs[3].m_mass; bmass=pdf->ASInfo().m_allflavs[4].m_mass; tmass=pdf->ASInfo().m_allflavs[5].m_mass; } cmass=reader.GetValue<double>("RECOLA_AS_RUN_MASS_C", cmass); cmass=reader.GetValue<double>("RECOLA_AS_REN_MASS_C", cmass); bmass=reader.GetValue<double>("RECOLA_AS_RUN_MASS_B", bmass); bmass=reader.GetValue<double>("RECOLA_AS_REN_MASS_B", bmass); tmass=reader.GetValue<double>("RECOLA_AS_RUN_MASS_T", tmass); tmass=reader.GetValue<double>("RECOLA_AS_REN_MASS_T", tmass); for (int i=0; i<3; i++){ if (i<pdfnf) s_pdfmass[i]=pdf->ASInfo().m_flavs[i].m_thres; } s_pdfmass[3]=cmass; s_pdfmass[4]=bmass; s_pdfmass[5]=tmass; set_alphas_masses_rcl(cmass,bmass,tmass,Flavour(kf_c).Width(),Flavour(kf_b).Width(),Flavour(kf_t).Width()); return true; }
bool HairBcsdf::sample(SurfaceScatterEvent &event) const { if (!event.requestedLobe.test(BsdfLobes::GlossyLobe)) return false; Vec2f xiN = event.sampler->next2D(); Vec2f xiM = event.sampler->next2D(); float sinThetaI = event.wi.y(); float cosThetaI = trigInverse(sinThetaI); float thetaI = std::asin(clamp(sinThetaI, -1.0f, 1.0f)); float thetaIR = thetaI - 2.0f*_scaleAngleRad; float thetaITT = thetaI + _scaleAngleRad; float thetaITRT = thetaI + 4.0f*_scaleAngleRad; // The following lines are just lobe selection float weightR = _nR ->weight(cosThetaI); float weightTT = _nTT ->weight(cosThetaI); float weightTRT = _nTRT->weight(cosThetaI); const PrecomputedAzimuthalLobe *lobe; float v; float theta; float target = xiN.x()*(weightR + weightTT + weightTRT); if (target < weightR) { v = _vR; theta = thetaIR; lobe = _nR.get(); } else if (target < weightR + weightTT) { v = _vTT; theta = thetaITT; lobe = _nTT.get(); } else { v = _vTRT; theta = thetaITRT; lobe = _nTRT.get(); } // Actual sampling of the direction starts here float sinThetaO = sampleM(v, std::sin(theta), std::cos(theta), xiM.x(), xiM.y()); float cosThetaO = trigInverse(sinThetaO); float thetaO = std::asin(clamp(sinThetaO, -1.0f, 1.0f)); float thetaD = (thetaO - thetaI)*0.5f; float cosThetaD = std::cos(thetaD); float phi, phiPdf; lobe->sample(cosThetaD, xiN.y(), phi, phiPdf); float sinPhi = std::sin(phi); float cosPhi = std::cos(phi); event.wo = Vec3f(sinPhi*cosThetaO, sinThetaO, cosPhi*cosThetaO); event.pdf = pdf(event); event.weight = eval(event)/event.pdf; event.sampledLobe = BsdfLobes::GlossyLobe; return true; }
void fit_MC_norm(std::string input_file = "/afs/cern.ch/work/a/apmorris/private/cern/ntuples/new_tuples/normalisation_samples/reduced_Lb2JpsipK_MC_2011_2012_norm.root", std::string out_file_mass = "~/cern/plots/fitting/Lb2JpsipK_MC_2011_2012_cut_mass_fit.png"){ // gROOT->ProcessLine(".L ~/cern/scripts/lhcbStyle.C"); //lhcbStyle(); const std::string filename(input_file.c_str()); const std::string treename = "DecayTree"; TFile* file = TFile::Open( filename.c_str() ); if( !file ) std::cout << "file " << filename << " does not exist" << std::endl; TTree* tree = (TTree*)file->Get( treename.c_str() ); if( !tree ) std::cout << "tree " << treename << " does not exist" << std::endl; // -- signal, mass shape RooRealVar Lambda_b0_DTF_MASS_constr1("Lambda_b0_DTF_MASS_constr1","m(J/#psi pK^{-})", 5450., 5850., "MeV/c^{2}"); RooRealVar Jpsi_M("Jpsi_M","m(#mu#mu)", 3000., 3200., "MeV/c^{2}"); //RooRealVar chi_c_M("chi_c_M","m(J/#psi#gamma)", 3350., 3750., "MeV/c^{2}"); RooRealVar mean("mean","mean", 5620., 5595., 5650.); RooRealVar sigma1("sigma1","sigma1", 10., 1., 100.); RooRealVar sigma2("sigma2","sigma2", 100., 1., 1000.); RooRealVar alpha1("alpha1","alpha1", 1.0, 0.5, 5.0); RooRealVar n1("n1","n1", 1.8, 0.2, 15.0); RooRealVar alpha2("alpha2","alpha2", -0.5, -5.5, 0.0); RooRealVar n2("n2","n2", 0.7, 0.2, 10.0); //RooRealVar bkgcat_chic("bkgcat_chic","bkgcat_chic", 0, 100); RooGaussian gauss1("gauss1","gauss1", Lambda_b0_DTF_MASS_constr1, mean, sigma1); RooGaussian gauss2("gauss2","gauss2", Lambda_b0_DTF_MASS_constr1, mean, sigma2); RooCBShape cb1("cb1","cb1", Lambda_b0_DTF_MASS_constr1, mean, sigma1, alpha1, n1); RooCBShape cb2("cb2","cb2", Lambda_b0_DTF_MASS_constr1, mean, sigma2, alpha2, n2); /* // the chi_c2 component RooRealVar mean3("mean3","mean3", 5570., 5520., 5580.); RooRealVar sigma3("sigma3","sigma3", 10., 1., 20.); RooGaussian gauss3("gauss3","gauss3", Lambda_b0_DTF_MASS_constr1, mean3, sigma3); */ RooRealVar cbRatio("cbRatio","cbRatio", 0.8, 0.1, 1.0); RooRealVar frac2("frac2","frac2", 0.3, 0., 1.); /* alpha1.setVal( 2.1 ); alpha2.setVal( -4.9 ); n1.setVal( 3.2 ); n2.setVal( 7.9 ); cbRatio.setVal( 0.6808 ); alpha1.setConstant( true ); alpha2.setConstant( true ); cbRatio.setConstant( true ); n1.setConstant( true ); n2.setConstant( true ); */ // -- add signal & bg //RooAddPdf pdf("pdf", "pdf", RooArgList(gauss1, gauss2), RooArgList( frac2 )); RooAddPdf pdf("pdf", "pdf", RooArgList(cb1, cb2), RooArgList( cbRatio )); RooArgSet obs; obs.add(Lambda_b0_DTF_MASS_constr1); obs.add(Jpsi_M); //obs.add(chi_c_M); //obs.add(bkgcat_chic); RooDataSet ds("ds","ds", obs, RooFit::Import(*tree)); //RooFit::Cut("Lambda_b0_DTF_MASS_constr1 > 5580") RooPlot* plot = Lambda_b0_DTF_MASS_constr1.frame(); plot->SetAxisRange(5500., 5750.); pdf.fitTo( ds ); ds.plotOn( plot, RooFit::Binning(200) ); pdf.plotOn( plot ); //gauss3.plotOn( plot ); RooPlot* plotPullMass = Lambda_b0_DTF_MASS_constr1.frame(); plotPullMass->addPlotable( plot->pullHist() ); //plotPullMass->SetMinimum(); //plotPullMass->SetMaximum(); plotPullMass->SetAxisRange(5500., 5750.); TCanvas* c = new TCanvas(); c->cd(); TPad* pad1 = new TPad("pad1","pad1", 0, 0.3, 1, 1.0); pad1->SetBottomMargin(0.1); pad1->SetTopMargin(0.1); pad1->Draw(); //TPad* pad2 = new TPad("pad2","pad2", 0, 0.05, 1, 0.4); TPad* pad2 = new TPad("pad2","pad2", 0, 0, 1, 0.3); pad2->SetBottomMargin(0.1); pad2->SetTopMargin(0.0); pad2->Draw(); pdf.plotOn( plot, RooFit::Components( cb1 ), RooFit::LineColor( kRed ), RooFit::LineStyle(kDashed) ); pdf.plotOn( plot, RooFit::Components( cb2 ), RooFit::LineColor( kOrange ), RooFit::LineStyle(kDotted) ); //pdf.plotOn( plot, RooFit::Components( bgPdf ), RooFit::LineColor( kBlue ), RooFit::LineStyle(kDashDotted) ); pad1->cd(); //pad1->SetLogy(); plot->Draw(); pad2->cd(); plotPullMass->Draw("AP"); c->SaveAs(out_file_mass.c_str()); }
inline Spectrum sample(BSDFSamplingRecord &bRec, Float &_pdf, const Point2 &_sample) const { Point2 sample(_sample); bool hasSpecular = (bRec.typeMask & EGlossyReflection) && (bRec.component == -1 || bRec.component == 0); bool hasDiffuse = (bRec.typeMask & EDiffuseReflection) && (bRec.component == -1 || bRec.component == 1); if (!hasSpecular && !hasDiffuse) return Spectrum(0.0f); bool choseSpecular = hasSpecular; if (hasDiffuse && hasSpecular) { if (sample.x <= m_specularSamplingWeight) { sample.x /= m_specularSamplingWeight; } else { sample.x = (sample.x - m_specularSamplingWeight) / (1-m_specularSamplingWeight); choseSpecular = false; } } if (choseSpecular) { Float alphaU = m_alphaU->eval(bRec.its).average(); Float alphaV = m_alphaV->eval(bRec.its).average(); Float phiH = std::atan(alphaV/alphaU * std::tan(2.0f * M_PI * sample.y)); if (sample.y > 0.5f) phiH += M_PI; Float cosPhiH = std::cos(phiH); Float sinPhiH = math::safe_sqrt(1.0f-cosPhiH*cosPhiH); Float thetaH = std::atan(math::safe_sqrt( -math::fastlog(sample.x) / ( (cosPhiH*cosPhiH) / (alphaU*alphaU) + (sinPhiH*sinPhiH) / (alphaV*alphaV) ))); Vector H = sphericalDirection(thetaH, phiH); bRec.wo = H * (2.0f * dot(bRec.wi, H)) - bRec.wi; bRec.sampledComponent = 1; bRec.sampledType = EGlossyReflection; if (Frame::cosTheta(bRec.wo) <= 0.0f) return Spectrum(0.0f); } else { bRec.wo = Warp::squareToCosineHemisphere(sample); bRec.sampledComponent = 0; bRec.sampledType = EDiffuseReflection; } bRec.eta = 1.0f; _pdf = pdf(bRec, ESolidAngle); if (_pdf == 0) return Spectrum(0.0f); else return eval(bRec, ESolidAngle) / _pdf; }