Logo ROOT   6.12/06
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Namespaces
tdf014_CSVDataSource.py File Reference

Namespaces

 tdf014_CSVDataSource
 

Detailed Description

This tutorial illustrates how use the TDataFrame in combination with a TDataSource.

In this case we use a TCsvDS. This data source allows to read a CSV file from a TDataFrame. As a result of running this tutorial, we will produce plots of the dimuon spectrum starting from a subset of the CMS collision events of Run2010B. Dataset Reference: McCauley, T. (2014). Dimuon event information derived from the Run2010B public Mu dataset. CERN Open Data Portal. DOI: 10.7483/OPENDATA.CMS.CB8H.MFFA.

1 
2 import ROOT
3 
4 # Let's first create a TDF that will read from the CSV file.
5 # The types of the columns will be automatically inferred.
6 fileName = "tdf014_CsvDataSource_MuRun2010B.csv"
7 MakeCsvDataFrame = ROOT.ROOT.Experimental.TDF.MakeCsvDataFrame
8 tdf = MakeCsvDataFrame(fileName)
9 
10 # Now we will apply a first filter based on two columns of the CSV,
11 # and we will define a new column that will contain the invariant mass.
12 # Note how the new invariant mass column is defined from several other
13 # columns that already existed in the CSV file.
14 filteredEvents = tdf.Filter("Q1 * Q2 == -1") \
15  .Define("m", "sqrt(pow(E1 + E2, 2) - (pow(px1 + px2, 2) + pow(py1 + py2, 2) + pow(pz1 + pz2, 2)))")
16 
17 # Next we create a histogram to hold the invariant mass values and we draw it.
18 invMass = filteredEvents.Histo1D(("invMass", "CMS Opendata: #mu#mu mass;#mu#mu mass [GeV];Events", 512, 2, 110), "m")
19 
20 c = ROOT.TCanvas()
21 c.SetLogx()
22 c.SetLogy()
23 invMass.Draw()
24 
25 # We will now produce a plot also for the J/Psi particle. We will plot
26 # on the same canvas the full spectrum and the zoom in the J/psi particle.
27 # First we will create the full spectrum histogram from the invariant mass
28 # column, using a different histogram model than before.
29 fullSpectrum = filteredEvents.Histo1D(("Spectrum", "Subset of CMS Run 2010B;#mu#mu mass [GeV];Events", 1024, 2, 110), "m")
30 
31 # Next we will create the histogram for the J/psi particle, applying first
32 # the corresponding cut.
33 jpsiLow = 2.95
34 jpsiHigh = 3.25
35 jpsiCut = 'm < %s && m > %s' % (jpsiHigh, jpsiLow)
36 jpsi = filteredEvents.Filter(jpsiCut) \
37  .Histo1D(("jpsi", "Subset of CMS Run 2010B: J/#psi window;#mu#mu mass [GeV];Events", 128, jpsiLow, jpsiHigh), "m")
38 
39 # Finally we draw the two histograms side by side.
40 dualCanvas = ROOT.TCanvas("DualCanvas", "DualCanvas", 800, 512)
41 dualCanvas.Divide(2, 1)
42 leftPad = dualCanvas.cd(1)
43 leftPad.SetLogx()
44 leftPad.SetLogy()
45 fullSpectrum.Draw("Hist")
46 dualCanvas.cd(2)
47 jpsi.Draw("HistP")
Date
October 2017
Author
Enric Tejedor

Definition in file tdf014_CSVDataSource.py.