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图片压缩三种高效压缩方案详细解析

《Java图片压缩三种高效压缩方案详细解析》图片压缩通常涉及减少图片的尺寸缩放、调整图片的质量(针对JPEG、PNG等)、使用特定的算法来减少图片的数据量等,:本文主要介绍Java图片压缩三种高效... 目录一、基于OpenCV的智能尺寸压缩技术亮点:适用场景:二、JPEG质量参数压缩关键技术:压缩效果对比

关于WebSocket协议状态码解析

《关于WebSocket协议状态码解析》:本文主要介绍关于WebSocket协议状态码的使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录WebSocket协议状态码解析1. 引言2. WebSocket协议状态码概述3. WebSocket协议状态码详解3

CSS Padding 和 Margin 区别全解析

《CSSPadding和Margin区别全解析》CSS中的padding和margin是两个非常基础且重要的属性,它们用于控制元素周围的空白区域,本文将详细介绍padding和... 目录css Padding 和 Margin 全解析1. Padding: 内边距2. Margin: 外边距3. Padd

Oracle数据库常见字段类型大全以及超详细解析

《Oracle数据库常见字段类型大全以及超详细解析》在Oracle数据库中查询特定表的字段个数通常需要使用SQL语句来完成,:本文主要介绍Oracle数据库常见字段类型大全以及超详细解析,文中通过... 目录前言一、字符类型(Character)1、CHAR:定长字符数据类型2、VARCHAR2:变长字符数

使用Jackson进行JSON生成与解析的新手指南

《使用Jackson进行JSON生成与解析的新手指南》这篇文章主要为大家详细介绍了如何使用Jackson进行JSON生成与解析处理,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. 核心依赖2. 基础用法2.1 对象转 jsON(序列化)2.2 JSON 转对象(反序列化)3.

Springboot @Autowired和@Resource的区别解析

《Springboot@Autowired和@Resource的区别解析》@Resource是JDK提供的注解,只是Spring在实现上提供了这个注解的功能支持,本文给大家介绍Springboot@... 目录【一】定义【1】@Autowired【2】@Resource【二】区别【1】包含的属性不同【2】@

SpringCloud动态配置注解@RefreshScope与@Component的深度解析

《SpringCloud动态配置注解@RefreshScope与@Component的深度解析》在现代微服务架构中,动态配置管理是一个关键需求,本文将为大家介绍SpringCloud中相关的注解@Re... 目录引言1. @RefreshScope 的作用与原理1.1 什么是 @RefreshScope1.

Java并发编程必备之Synchronized关键字深入解析

《Java并发编程必备之Synchronized关键字深入解析》本文我们深入探索了Java中的Synchronized关键字,包括其互斥性和可重入性的特性,文章详细介绍了Synchronized的三种... 目录一、前言二、Synchronized关键字2.1 Synchronized的特性1. 互斥2.

Tomcat版本与Java版本的关系及说明

《Tomcat版本与Java版本的关系及说明》:本文主要介绍Tomcat版本与Java版本的关系及说明,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Tomcat版本与Java版本的关系Tomcat历史版本对应的Java版本Tomcat支持哪些版本的pythonJ

Java的IO模型、Netty原理解析

《Java的IO模型、Netty原理解析》Java的I/O是以流的方式进行数据输入输出的,Java的类库涉及很多领域的IO内容:标准的输入输出,文件的操作、网络上的数据传输流、字符串流、对象流等,这篇... 目录1.什么是IO2.同步与异步、阻塞与非阻塞3.三种IO模型BIO(blocking I/O)NI