User Tools

Site Tools


root:pyroot_th1

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
root:pyroot_th1 [2017/06/26 17:37] iwnroot:pyroot_th1 [2017/09/05 10:35] (current) – [Handling TH1 histograms] iwn
Line 1: Line 1:
 +[[root:root|Getting started with ROOT]] -> [[root:pyroot|Useful pyROOT snippets]] → [[root:pyroot_th1|Handling TH1 histograms]]
 +
 ====== Handling TH1 histograms ====== ====== Handling TH1 histograms ======
 +
 +[[https://root.cern.ch/doc/master/classTH1.html|Here]] is the class reference for ''TH1''.
 +
  
 ===== Importing ROOT classes ===== ===== Importing ROOT classes =====
  
-To use ''TH1D'' in ''python'', you can either do+To use ''TH1D'' in ''python'', you can either only import a ''TH1D'' class:
 <code python> <code python>
 from ROOT import TH1D from ROOT import TH1D
 hist = TH1D("hist_name","hist_title",100,0,100) hist = TH1D("hist_name","hist_title",100,0,100)
 </code> </code>
-or+or //all// classes:
 <code python> <code python>
 from ROOT import * # loads all classes, and thus takes longer from ROOT import * # loads all classes, and thus takes longer
 hist = TH1D("hist_name","hist_title",100,0,100) hist = TH1D("hist_name","hist_title",100,0,100)
 </code> </code>
-or+or only the ''ROOT'' module:
 <code python> <code python>
 import ROOT import ROOT
Line 57: Line 62:
 tree.Draw("pt1*(eta1<2.4) + pt2*(eta2<2.4) >> hist_name") # boolean expressions tree.Draw("pt1*(eta1<2.4) + pt2*(eta2<2.4) >> hist_name") # boolean expressions
 </code> </code>
-This also includes custom functions, which you can for example load into ''ROOT'' with+This also includes custom functions, which you can load into ''ROOT'' with a ''C'' file:
 <code python> <code python>
-from ROOT import gROOT,+from ROOT import gROOT, ...
 gROOT.Macro("myfunctions.C+") gROOT.Macro("myfunctions.C+")
-</code> +... 
-and use it as +tree.Draw("deltaR(eta1,phi1,eta2,phi2) >> hist_name"   deltaR     function defined in "myfunctions.C+" 
-<code python> +tree.Draw("pt1 >> hist_name","(pt>30)*weightEta1(eta1)") # weightEta1 function defined in "myfunctions.C+"
-tree.Draw("deltaR(eta1,phi1,eta2,phi2) >> hist_name"  # function defined in "myfunctions.C+" +
-tree.Draw("pt1 >> hist_name","(pt>30)*weightEta(eta1)") # function defined in "myfunctions.C+"+
 </code> </code>
  
root/pyroot_th1.1498491426.txt.gz · Last modified: 2017/06/26 17:37 by iwn