CERN ROOT例子解析——学习向(candledecay.C)兼直方图绘图选项说明

2024-01-28 06:50

本文主要是介绍CERN ROOT例子解析——学习向(candledecay.C)兼直方图绘图选项说明,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

本文主要是为了让自己更好学习CERN ROOT所写,在ROOT的安装路径文件夹中,有一个tutorials的文件夹,里面有许多供用户学习的例子,为了让自己学完不会忘,故而在此对这些例子加以注释,方便日后使用ROOT处理数据时能方便查找使用案例。

void candledecay()
{auto c1 = new TCanvas("c1","Candle Decay",800,600); //新建一个画板c1->Divide(2,1); //画板一分为二,左右各一auto rng = new TRandom();  //新建一个随机变量auto h1 = new TH2I("h1","Decay",1000,0,1000,20,0,20);  //新建一个二维直方图对象//生成1000000个服从高斯分布的随机数,填充到h1对象中float myRand;for (int i = 0; i < 19; i++) {for (int j = 0; j < 1000000; j++) {myRand = rng->Gaus(350+i*8,20+2*i);h1->Fill(myRand,i);}}//设置h1的画图参数h1->SetBarWidth(3); //现款h1->SetFillStyle(0);  //填充类型h1->SetFillColor(kGray);  //填充颜色h1->SetLineColor(kBlue);  //线条颜色h1->GetYaxis()->SetTitle("time");  //Y轴标题h1->GetXaxis()->SetTitle("probability density");  //X轴标题c1->cd(1);  //h1画左边h1->Draw("violiny(112000000)");//复制h1出来在右边画h2c1->cd(2);  auto h2 = (TH2I*)h1->Clone("h2");h2->SetBarWidth(0.8);h2->DrawCopy("candley2");
}

在这里插入图片描述
在上述代码中,

h1->Draw("violiny(112000000)");
h2->DrawCopy("candley2");

Draw或DrawCopy函数中的参数指绘图选择,由THistPainter类提供该直方图的选项进行绘制,不同维度的直方图绘图选项众多,可通过https://root.cern.ch/doc/master/classTHistPainter.html进行查询。
其中,主要选项及其绘图描述如下:
1D和2D直方图支持的绘图选项:

“E” Draw error bars.
“AXIS” Draw only axis.
“AXIG” Draw only grid (if the grid is requested).
“HIST” When an histogram has errors it is visualized by default with error bars. To visualize it without errors use the option “HIST” together with the required option (eg “hist same c”). The “HIST” option can also be used to plot only the histogram and not the associated function(s).
“FUNC” When an histogram has a fitted function, this option allows to draw the fit result only.
“SAME” Superimpose on previous picture in the same pad.
“SAMES” Same as “SAME” and draw the statistics box
“PFC” Palette Fill Color: histogram’s fill color is taken in the current palette.
“PLC” Palette Line Color: histogram’s line color is taken in the current palette.
“PMC” Palette Marker Color: histogram’s marker color is taken in the current palette.
“LEGO” Draw a lego plot with hidden line removal.
“LEGO1” Draw a lego plot with hidden surface removal.
“LEGO2” Draw a lego plot using colors to show the cell contents When the option “0” is used with any LEGO option, the empty bins are not drawn.
“LEGO3” Draw a lego plot with hidden surface removal, like LEGO1 but the border lines of each lego-bar are not drawn.
“LEGO4” Draw a lego plot with hidden surface removal, like LEGO1 but without the shadow effect on each lego-bar.
“TEXT” Draw bin contents as text (format set via gStyle->SetPaintTextFormat).
“TEXTnn” Draw bin contents as text at angle nn (0 < nn <= 90).
“X+” The X-axis is drawn on the top side of the plot.
“Y+” The Y-axis is drawn on the right side of the plot.
“MIN0” Set minimum value for the Y axis to 0, equivalent to gStyle->SetHistMinimumZero().

1D直方图支持的选项:
" " Default.
“AH” Draw histogram without axis. “A” can be combined with any drawing option. For instance, “AC” draws the histogram as a smooth Curve without axis.
“][” When this option is selected the first and last vertical lines of the histogram are not drawn.
“B” Bar chart option.
“BAR” Like option “B”, but bars can be drawn with a 3D effect.
“HBAR” Like option “BAR”, but bars are drawn horizontally.
“C” Draw a smooth Curve through the histogram bins.
“E0” Draw error bars. Markers are drawn for bins with 0 contents. Combined with E1 or E2 it avoids error bars clipping
“E1” Draw error bars with perpendicular lines at the edges.
“E2” Draw error bars with rectangles.
“E3” Draw a fill area through the end points of the vertical error bars.
“E4” Draw a smoothed filled area through the end points of the error bars.
“E5” Like E3 but ignore the bins with 0 contents.
“E6” Like E4 but ignore the bins with 0 contents.
“X0” When used with one of the “E” option, it suppress the error bar along X as gStyle->SetErrorX(0) would do.
“L” Draw a line through the bin contents.
“P” Draw current marker at each bin except empty bins.
"P
" Draw a star marker at each bin except empty bins.
“P0” Draw current marker at each bin including empty bins.
“PIE” Draw histogram as a Pie Chart.
"H" Draw histogram with a * at each bin.
“LF2” Draw histogram like with option “L” but with a fill area. Note that “L” draws also a fill area if the hist fill color is set but the fill area corresponds to the histogram contour.

2D直方图支持的选项:
" " Default (scatter plot).
“ARR” Arrow mode. Shows gradient between adjacent cells.
“BOX” A box is drawn for each cell with surface proportional to the content’s absolute value. A negative content is marked with a X.
“BOX1” A button is drawn for each cell with surface proportional to content’s absolute value. A sunken button is drawn for negative values a raised one for positive.
“COL” A box is drawn for each cell with a color scale varying with contents. All the none empty bins are painted. Empty bins are not painted unless some bins have a negative content because in that case the null bins might be not empty. TProfile2D histograms are handled differently because, for this type of 2D histograms, it is possible to know if an empty bin has been filled or not. So even if all the bins’ contents are positive some empty bins might be painted. And vice versa, if some bins have a negative content some empty bins might be not painted.
“COLZ” Same as “COL”. In addition the color palette is also drawn.
“COL2” Alternative rendering algorithm to “COL”. Can significantly improve rendering performance for large, non-sparse 2-D histograms.
“COLZ2” Same as “COL2”. In addition the color palette is also drawn.
“Z CJUST” In combination with colored options “COL”,“CONT0” etc: Justify labels in the color palette at color boudaries. For more details see TPaletteAxis
“CANDLE” Draw a candle plot along X axis.
“CANDLEX” Same as “CANDLE”.
“CANDLEY” Draw a candle plot along Y axis.
“CANDLEXn” Draw a candle plot along X axis. Different candle-styles with n from 1 to 6.
“CANDLEYn” Draw a candle plot along Y axis. Different candle-styles with n from 1 to 6.
“VIOLIN” Draw a violin plot along X axis.
“VIOLINX” Same as “VIOLIN”.
“VIOLINY” Draw a violin plot along Y axis.
“VIOLINXn” Draw a violin plot along X axis. Different violin-styles with n being 1 or 2.
“VIOLINYn” Draw a violin plot along Y axis. Different violin-styles with n being 1 or 2.
“CONT” Draw a contour plot (same as CONT0).
“CONT0” Draw a contour plot using surface colors to distinguish contours.
“CONT1” Draw a contour plot using line styles to distinguish contours.
“CONT2” Draw a contour plot using the same line style for all contours.
“CONT3” Draw a contour plot using fill area colors.
“CONT4” Draw a contour plot using surface colors (SURF option at theta = 0).
“LIST” Generate a list of TGraph objects for each contour.
“SAME0” Same as “SAME” but do not use the z-axis range of the first plot.
“SAMES0” Same as “SAMES” but do not use the z-axis range of the first plot.
“CYL” Use Cylindrical coordinates. The X coordinate is mapped on the angle and the Y coordinate on the cylinder length.
“POL” Use Polar coordinates. The X coordinate is mapped on the angle and the Y coordinate on the radius.
“SPH” Use Spherical coordinates. The X coordinate is mapped on the latitude and the Y coordinate on the longitude.
“PSR” Use PseudoRapidity/Phi coordinates. The X coordinate is mapped on Phi.
“SURF” Draw a surface plot with hidden line removal.
“SURF1” Draw a surface plot with hidden surface removal.
“SURF2” Draw a surface plot using colors to show the cell contents.
“SURF3” Same as SURF with in addition a contour view drawn on the top.
“SURF4” Draw a surface using Gouraud shading.
“SURF5” Same as SURF3 but only the colored contour is drawn. Used with option CYL, SPH or PSR it allows to draw colored contours on a sphere, a cylinder or a in pseudo rapidity space. In cartesian or polar coordinates, option SURF3 is used.
“AITOFF” Draw a contour via an AITOFF projection.
“MERCATOR” Draw a contour via an Mercator projection.
“SINUSOIDAL” Draw a contour via an Sinusoidal projection.
“PARABOLIC” Draw a contour via an Parabolic projection.
“LEGO9” Draw the 3D axis only. Mainly needed for internal use
“FB” With LEGO or SURFACE, suppress the Front-Box.
“BB” With LEGO or SURFACE, suppress the Back-Box.
“A” With LEGO or SURFACE, suppress the axis.
“SCAT” Draw a scatter-plot (default).
“[cutg]” Draw only the sub-range selected by the TCutG named “cutg”.

3D直方图支持的选项:
" " Default (scatter plot).
“ISO” Draw a Gouraud shaded 3d iso surface through a 3d histogram. It paints one surface at the value computed as follow: SumOfWeights/(NbinsX
NbinsYNbinsZ).
“BOX” Draw a for each cell with volume proportional to the content’s absolute value. An hidden line removal algorithm is used
“BOX1” Same as BOX but an hidden surface removal algorithm is used
“BOX2” The boxes’ colors are picked in the current palette according to the bins’ contents
“BOX2Z” Same as “BOX2”. In addition the color palette is also drawn.
“BOX3” Same as BOX1, but the border lines of each lego-bar are not drawn.
“LEGO” Same as BOX.

直方图堆栈支持的选项(Options supported for histograms’ stacks (THStack))
" " Default, the histograms are drawn on top of each other (as lego plots for 2D histograms).
“NOSTACK” Histograms in the stack are all paint in the same pad as if the option SAME had been specified.
“NOSTACKB” Histograms are drawn next to each other as bar charts.
“PADS” The current pad/canvas is subdivided into a number of pads equal to the number of histograms in the stack and each histogram is paint into a separate pad.
“PFC” Palette Fill Color: stack’s fill color is taken in the current palette.
“PLC” Palette Line Color: stack’s line color is taken in the current palette.
“PMC” Palette Marker Color: stack’s marker color is taken in the current palette.

这篇关于CERN ROOT例子解析——学习向(candledecay.C)兼直方图绘图选项说明的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/652810

相关文章

java脚本使用不同版本jdk的说明介绍

《java脚本使用不同版本jdk的说明介绍》本文介绍了在Java中执行JavaScript脚本的几种方式,包括使用ScriptEngine、Nashorn和GraalVM,ScriptEngine适用... 目录Java脚本使用不同版本jdk的说明1.使用ScriptEngine执行javascript2.

使用Python实现批量访问URL并解析XML响应功能

《使用Python实现批量访问URL并解析XML响应功能》在现代Web开发和数据抓取中,批量访问URL并解析响应内容是一个常见的需求,本文将详细介绍如何使用Python实现批量访问URL并解析XML响... 目录引言1. 背景与需求2. 工具方法实现2.1 单URL访问与解析代码实现代码说明2.2 示例调用

SSID究竟是什么? WiFi网络名称及工作方式解析

《SSID究竟是什么?WiFi网络名称及工作方式解析》SID可以看作是无线网络的名称,类似于有线网络中的网络名称或者路由器的名称,在无线网络中,设备通过SSID来识别和连接到特定的无线网络... 当提到 Wi-Fi 网络时,就避不开「SSID」这个术语。简单来说,SSID 就是 Wi-Fi 网络的名称。比如

SpringCloud配置动态更新原理解析

《SpringCloud配置动态更新原理解析》在微服务架构的浩瀚星海中,服务配置的动态更新如同魔法一般,能够让应用在不重启的情况下,实时响应配置的变更,SpringCloud作为微服务架构中的佼佼者,... 目录一、SpringBoot、Cloud配置的读取二、SpringCloud配置动态刷新三、更新@R

使用Java解析JSON数据并提取特定字段的实现步骤(以提取mailNo为例)

《使用Java解析JSON数据并提取特定字段的实现步骤(以提取mailNo为例)》在现代软件开发中,处理JSON数据是一项非常常见的任务,无论是从API接口获取数据,还是将数据存储为JSON格式,解析... 目录1. 背景介绍1.1 jsON简介1.2 实际案例2. 准备工作2.1 环境搭建2.1.1 添加

Redis分布式锁使用及说明

《Redis分布式锁使用及说明》本文总结了Redis和Zookeeper在高可用性和高一致性场景下的应用,并详细介绍了Redis的分布式锁实现方式,包括使用Lua脚本和续期机制,最后,提到了RedLo... 目录Redis分布式锁加锁方式怎么会解错锁?举个小案例吧解锁方式续期总结Redis分布式锁如果追求

结构体和联合体的区别及说明

《结构体和联合体的区别及说明》文章主要介绍了C语言中的结构体和联合体,结构体是一种自定义的复合数据类型,可以包含多个成员,每个成员可以是不同的数据类型,联合体是一种特殊的数据结构,可以在内存中共享同一... 目录结构体和联合体的区别1. 结构体(Struct)2. 联合体(Union)3. 联合体与结构体的

在C#中合并和解析相对路径方式

《在C#中合并和解析相对路径方式》Path类提供了几个用于操作文件路径的静态方法,其中包括Combine方法和GetFullPath方法,Combine方法将两个路径合并在一起,但不会解析包含相对元素... 目录C#合并和解析相对路径System.IO.Path类幸运的是总结C#合并和解析相对路径对于 C

Java解析JSON的六种方案

《Java解析JSON的六种方案》这篇文章介绍了6种JSON解析方案,包括Jackson、Gson、FastJSON、JsonPath、、手动解析,分别阐述了它们的功能特点、代码示例、高级功能、优缺点... 目录前言1. 使用 Jackson:业界标配功能特点代码示例高级功能优缺点2. 使用 Gson:轻量

Java如何接收并解析HL7协议数据

《Java如何接收并解析HL7协议数据》文章主要介绍了HL7协议及其在医疗行业中的应用,详细描述了如何配置环境、接收和解析数据,以及与前端进行交互的实现方法,文章还分享了使用7Edit工具进行调试的经... 目录一、前言二、正文1、环境配置2、数据接收:HL7Monitor3、数据解析:HL7Busines