Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format crosscheck, downstream pipeline #16

Closed
mmikhasenko opened this issue Apr 28, 2024 · 2 comments
Closed

Format crosscheck, downstream pipeline #16

mmikhasenko opened this issue Apr 28, 2024 · 2 comments
Labels
⚙️ Enhancement Improvements and optimizations of existing features

Comments

@mmikhasenko
Copy link
Collaborator

A lot of time will pass before we start seeing ROOT capability to read the files with amplitude model.
However, some cross-check of the format can done at earlier stages.

This issue gives example on how to write HS3 json from root.

@mmikhasenko mmikhasenko added the ⚙️ Enhancement Improvements and optimizations of existing features label Apr 28, 2024
@mmikhasenko
Copy link
Collaborator Author

mmikhasenko commented Apr 28, 2024

Extended example of root json

ROOT script
#include "RooRealVar.h"
#include "RooGaussian.h"
#include "RooExponential.h"
#include "RooBreitWigner.h"
#include "RooWorkspace.h"
#include "RooFitHS3/RooJSONFactoryWSTool.h"

int export_pdf()
{
    RooRealVar x("x", "x", -10, 10);
    RooRealVar mean("mean", "mean of gaussian", 1, -10, 10);
    RooRealVar sigma("sigma", "width of gaussian", 1, 0.1, 10);
    RooGaussian gauss("gauss", "gaussian PDF", x, mean, sigma);
    // w.factory(“Gaussian::f(x[-10,10],mean[5],sigma[3])”)

    RooRealVar alpha("alpha", "slope or exp", 1, 0.1, 10);
    RooExponential exp("exp", "exponential PDF", x, alpha);

    RooRealVar gamma("gamma", "width of bw", 1, 0.1, 10);
    RooBreitWigner bw("bw", "non-rel bw", x, mean, gamma);

    RooWorkspace w("ws");
    w.import(gauss);
    w.import(exp);
    w.import(bw);

    RooJSONFactoryWSTool tool(w);
    tool.exportJSON("standard_pdf.json");
    return 0;
}
JSON output
{
  "distributions": [
    { "name": "bw" },
    {
      "c": "alpha_exponential_inverted",
      "name": "exp",
      "type": "exponential_dist",
      "x": "x"
    },
    {
      "mean": "mean",
      "name": "gauss",
      "sigma": "sigma",
      "type": "gaussian_dist",
      "x": "x"
    }
  ],
  "domains": [
    {
      "axes": [
        { "max": 10.0, "min": 0.1, "name": "alpha" },
        { "max": 10.0, "min": -10.0, "name": "mean" },
        { "max": 10.0, "min": 0.1, "name": "sigma" },
        { "max": 10.0, "min": -10.0, "name": "x" }
      ],
      "name": "default_domain",
      "type": "product_domain"
    }
  ],
  "functions": [
    {
      "expression": "-alpha",
      "name": "alpha_exponential_inverted",
      "type": "generic_function"
    }
  ],
  "metadata": {
    "hs3_version": "0.2",
    "packages": [{ "name": "ROOT", "version": "6.33.01" }]
  },
  "misc": {
    "ROOT_internal": {
      "attributes": {
        "alpha_exponential_inverted": {
          "dict": { "autogen_transform_exponential_original": "alpha" },
          "tags": ["autogen_transform_exponential"]
        }
      }
    }
  },
  "parameter_points": [
    {
      "name": "default_values",
      "parameters": [
        { "name": "x", "value": 0.0 },
        { "name": "alpha", "value": 1.0 },
        { "name": "mean", "value": 1.0 },
        { "name": "sigma", "value": 1.0 }
      ]
    }
  ]
}
Warning about BreitWigner
Processing export_pdf.cxx++...
Info in <TUnixSystem::ACLiC>: creating shared library /afs/cern.ch/user/m/mimikhas/Documents/HS3/./export_pdf_cxx.so
[#1] INFO:ObjectHandling -- RooWorkspace::import(ws) importing RooGaussian::gauss
[#1] INFO:ObjectHandling -- RooWorkspace::import(ws) importing RooRealVar::x
[#1] INFO:ObjectHandling -- RooWorkspace::import(ws) importing RooRealVar::mean
[#1] INFO:ObjectHandling -- RooWorkspace::import(ws) importing RooRealVar::sigma
[#1] INFO:ObjectHandling -- RooWorkspace::import(ws) importing RooExponential::exp
[#1] INFO:ObjectHandling -- RooWorkspace::import(ws) importing RooRealVar::alpha
[#1] INFO:ObjectHandling -- RooWorkspace::import(ws) importing RooBreitWigner::bw
[#1] INFO:ObjectHandling -- RooWorkspace::import(ws) importing RooRealVar::gamma
unable to export class 'RooBreitWigner' - no export keys available!
there are several possible reasons for this:
 1. RooBreitWigner is a custom class that you or some package you are using added.
 2. RooBreitWigner is a ROOT class that nobody ever bothered to write a serialization definition for.
 3. something is wrong with your setup, e.g. you might have called RooFit::JSONIO::clearExportKeys() and/or never successfully read a file defining these keys with RooFit::JSONIO::loadExportKeys(filename)
either way, please make sure that:
 3: you are reading a file with export keys - call RooFit::JSONIO::printExportKeys() to see what is available
 2 & 1: you might need to write a serialization definition yourself. check https://github.com/root-project/root/blob/master/roofit/hs3/README.md to see how to do this!

@mmikhasenko
Copy link
Collaborator Author

Superseded by #58

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚙️ Enhancement Improvements and optimizations of existing features
Projects
None yet
Development

No branches or pull requests

1 participant