Back to home page

sPhenix code displayed by LXR

 
 

    


Warning, /tutorials/HEPData/CreateSubmission.ipynb is written in an unsupported language. File is not indexed.

0001 {
0002  "cells": [
0003   {
0004    "cell_type": "code",
0005    "execution_count": 31,
0006    "id": "149078b1",
0007    "metadata": {},
0008    "outputs": [],
0009    "source": [
0010     "from hepdata_lib import Submission, Table, Variable, Uncertainty, RootFileReader\n",
0011     "\n",
0012     "# Load ROOT file using RootFileReader\n",
0013     "reader = RootFileReader(\"spectrum_output.root\")\n",
0014     "\n",
0015     "# Initialize submission\n",
0016     "submission = Submission()\n",
0017     "\n",
0018     "# ------------------ Table 1: Spectrum -----------------------\n",
0019     "#This objects hold page on HEPDATA - idealy 1 Table per figure\n",
0020     "table1 = Table(\"Exponential Spectrum\")\n",
0021     "table1.description = \"Dummy cross-section with statistical uncertainties and asymmetric systematic uncertainties.\"\n",
0022     "table1.location = \"Data from Figure 1, located on page 3.\"\n",
0023     "# Add some keywords so it is searchable on HEPDATA\n",
0024     "table1.keywords[\"observables\"] = [\"D2SIG/DPT/DETARAP\"]\n",
0025     "table1.keywords[\"cmenergies\"] = [\"200\"]\n",
0026     "table1.keywords[\"reactions\"] = [\"P P --> D0 X\", \"P P --> DBAR0 X\"]\n",
0027     "table1.keywords[\"phrases\"] = [\"Cross Section\", \"Single Differential Cross Section\",\"Proton-Proton Scattering\",\"Transverse Momentum Dependence\"]\n",
0028     "# Add image, can be pdf\n",
0029     "table1.add_image(\"spectrum.png\")\n",
0030     "\n",
0031     "# Get data from TH1D and TGraphAsymmErrors\n",
0032     "hist = reader.read_hist_1d(\"hist_stat\")\n",
0033     "graph = reader.read_graph(\"graph_asym\")\n",
0034     "\n",
0035     "# This is the structure of the loaded objects (dictionary of lists)\n",
0036     "#print(graph.keys())\n",
0037     "#dict_keys(['x', 'y', 'dx', 'dy'])\n",
0038     "\n",
0039     "# Define x-axis (independent)\n",
0040     "histogram_x = Variable(\"$p_{T}$\", is_independent=True, is_binned=False, units=\"GeV\")\n",
0041     "histogram_x.values = hist[\"x\"]\n",
0042     "# Define y-axis values (since we have 1D plot, this is dependent - ir depends on the independent variable x)\n",
0043     "histogram_y = Variable(\"Cross-section\", is_independent=False, is_binned=False, units=\"mb\")\n",
0044     "histogram_y.values = hist[\"y\"]\n",
0045     "#Define urcertainties, you have have any number you want, you are naming them: norm,lumi, etc.\n",
0046     "#stat unc\n",
0047     "stat_unc = Uncertainty(\"stat\", is_symmetric=True)\n",
0048     "stat_unc.values = hist[\"dy\"]\n",
0049     "#sys unc\n",
0050     "sys_unc = Uncertainty(\"sys\", is_symmetric=False)\n",
0051     "sys_unc.values = graph[\"dy\"]\n",
0052     "\n",
0053     "#accidentelly saved symetrical errors in Assymerrors? No problem!\n",
0054     "#sys_unc = Uncertainty(\"sys\", is_symmetric=True)\n",
0055     "#sys_unc.values =[high for (_, high) in graph[\"dy\"]]\n",
0056     "\n",
0057     "# Add uncertainty to data\n",
0058     "histogram_y.add_uncertainty(stat_unc)\n",
0059     "histogram_y.add_uncertainty(sys_unc)\n",
0060     "\n",
0061     "# Add variables to the table\n",
0062     "table1.add_variable(histogram_x)\n",
0063     "table1.add_variable(histogram_y)\n",
0064     "\n",
0065     "#lets add another histogram in the same table, without any uncertainties\n",
0066     "hist_halved = reader.read_hist_1d(\"hist_halved\")\n",
0067     "histogram_y_halved = Variable(\"Cross-section halved\", is_independent=False, is_binned=False, units=\"mb\")\n",
0068     "histogram_y_halved.values = hist_halved[\"y\"]\n",
0069     "table1.add_variable(histogram_y_halved)\n",
0070     "\n",
0071     "# ------------------ Table 2: Correlation Matrix ------------------\n",
0072     "#lib also supports 2D hsitograms!\n",
0073     "table2 = Table(\"Bin-to-bin Correlation Matrix\")\n",
0074     "table2.description = \"Random symmetric bin-to-bin correlation matrix used for uncertainty modeling.\"\n",
0075     "table2.add_image(\"corr_matrix.png\")\n",
0076     "corr_matrix = reader.read_hist_2d(\"corr_matrix\")\n",
0077     "\n",
0078     "# Create variable objects, since we have 2D histogram, x and y are independent variables\n",
0079     "x = Variable(\"First Axis\", is_independent=True, is_binned=True)\n",
0080     "x.values = corr_matrix[\"x_edges\"]\n",
0081     "y = Variable(\"Second Axis\", is_independent=True, is_binned=True)\n",
0082     "y.values = corr_matrix[\"y_edges\"]\n",
0083     "correlation = Variable(\"Correlation coefficient\", is_independent=False, is_binned=False)\n",
0084     "correlation.values = corr_matrix[\"z\"]\n",
0085     "#Uncertainties can be added similarly to the 1D case\n",
0086     "\n",
0087     "for var in [x,y,correlation]:\n",
0088     "    table2.add_variable(var)\n",
0089     "\n",
0090     "# Add tables to submission\n",
0091     "submission.add_table(table1)\n",
0092     "submission.add_table(table2)\n",
0093     "\n",
0094     "# Output submission to directory\n",
0095     "submission.create_files(\"submission_hepdata\",remove_old=True)\n",
0096     "\n"
0097    ]
0098   },
0099   {
0100    "cell_type": "code",
0101    "execution_count": null,
0102    "id": "2a946598",
0103    "metadata": {},
0104    "outputs": [],
0105    "source": []
0106   }
0107  ],
0108  "metadata": {
0109   "kernelspec": {
0110    "display_name": "Python 3",
0111    "language": "python",
0112    "name": "python3"
0113   },
0114   "language_info": {
0115    "codemirror_mode": {
0116     "name": "ipython",
0117     "version": 3
0118    },
0119    "file_extension": ".py",
0120    "mimetype": "text/x-python",
0121    "name": "python",
0122    "nbconvert_exporter": "python",
0123    "pygments_lexer": "ipython3",
0124    "version": "3.11.9"
0125   }
0126  },
0127  "nbformat": 4,
0128  "nbformat_minor": 5
0129 }