Changes between Version 15 and Version 16 of DatabaseBasedAnalysis/rootifysql


Ignore:
Timestamp:
08/05/18 20:22:56 (6 years ago)
Author:
tbretz
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DatabaseBasedAnalysis/rootifysql

    v15 v16  
    66The idea of {{{rootifysql}}} is to conveniently request data from a MySQL database and write the contents returned into a tree in a root-file. Root trees offer a lot of nice features how to access the data fast and how to create plots easily.
    77
    8 For details, please refer either to the Draw-function of TTree (e.g. https://root.cern.ch/doc/master/classTTree.html#a73450649dc6e54b5b94516c468523e45) or checkout the root user manual (https://root.cern.ch/guides/users-guide), in particular the section about '''Trees'''.
     8For details, please refer either to the Draw-function of TTree (e.g. https://root.cern.ch/doc/master/classTTree.html#a73450649dc6e54b5b94516c468523e45) or checkout the root user manual (https://root.cern.ch/guides/users-guide), in particular the section about '''Trees'''. A mini-tutorial is given at the end of the page.
    99
    1010In the following basic knowledge on C++, {{{root}}} and root trees is assumed.
     
    476476
    477477In case of success, {{{rootifysql}}} returns 0, a value>0 otherwise.
     478
     479== Analysis with root ==
     480
     481Here is a short example how to access the data from the root file, assuming a filename '''rootify.root''', the default tree name '''Result''' and two branches with name '''Col0''' and '''Col1'''
     482{{{#!cpp
     483void example()
     484{
     485    // Create chain for the tree Result
     486    // This is just easier than using TFile/TTree
     487    TChain c("Result");
     488
     489    // Add the input file to the
     490    c.AddFile("rootify.root");
     491
     492    // Assume you want to convert Col1 from RAD to DEG
     493    c.SetAlias("col1deg", "Col1*TMath::RadToDeg()");
     494
     495    // Plot Col0 if Col1>PI
     496    new TCanvas;
     497    c.Draw("Col0", "Col1>TMath::Pi()");
     498
     499    // Plot Col1 in degree versus Col0
     500    new TCanvas;
     501    c.Draw("Col0:col1deg", "");
     502}
     503}}}
     504
     505or
     506
     507{{{#!cpp
     508void example()
     509{
     510    // Create chain for the tree Result
     511    // This is just easier than using TFile/TTree
     512    TChain c("Result");
     513
     514    // Add the input file to the
     515    c.AddFile("rootify.root");
     516
     517    // All columns are stores as doubles
     518    double col0, col1;
     519
     520    // Connect the variables to the coresponding leaves
     521    c.SetBranchAddress("Col0", &col0);
     522    c.SetBranchAddress("Col1", &col1);
     523
     524    for (int i=0; i<c.GetEntries(); i++)
     525    {
     526        // read the i-th event from the file
     527        c.GetEntry(i);
     528
     529        cout << col0 << " " << col1 << endl;
     530    }
     531}
     532}}}
     533
     534Assuming the code is written to '''example.C''', both are executed with {{{root example.C}}}. Instead of {{{Draw()}}} also {{{Select()}}} can be used to print the data to the console.
     535
     536For details, please refer either to the Draw-function of TTree (e.g. https://root.cern.ch/doc/master/classTTree.html#a73450649dc6e54b5b94516c468523e45) or checkout the root user manual (https://root.cern.ch/guides/users-guide), in particular the section about '''Trees'''.