Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In PSANA framework we need in package which allows to accumulate data in form of histograms and tuples and save them in file for further analysis. An official package which performs this job is PSHist. PSHist provides an abstract interface to the selected set of methods. Actual implementation of these methods is provided in the RootHist package, which is based on CERN's ROOT library. In case if user would need in full brute force of ROOT, we could suggest to use it directly. In this note we present only the basic interface, equivalent to the PSHist, which allows to accumulate data save the file and browse this file interactively in ROOT. Complete documentation for ROOT library can be found here.

...

Code Block
//-----------------
// C/C++ Headers --
//-----------------
#include <iostream>

using std::cout;
using std::endl;

//----------------------
// Root Class Headers --
//----------------------

#include "root/TROOT.h"
#include "root/TFile.h"
#include "root/TH1D.h"
#include "root/TTree.h"
#include "root/TBranch.h"
#include "root/TRandom.h"

int main ()
{
  cout << "Start main()" << endl;

  TFile *pfile = new TFile("file.root", "RECREATE", "Created for you by RootManager" );
  cout << "Open Root file with name : " << pfile -> GetName() << endl;

  cout << "Create histogram" << endl;
  TH1D *pHis1 = new TH1D("pHis1","My comment to TH1D", 100, 0.5, 100+0.5);

  cout << "Reset and fill histogram" << endl;
        pHis1 -> Reset();
        for (int i=0 ;i<10000;i++)
          {
            double random = 100 * gRandom->Rndm(1);
            //pHis1 -> Fill( double(i), 0.1*i );
            pHis1 -> Fill( random );

          }

  cout << "Write histogram in file" << endl;
        pHis1 -> Write();

// Define some simple structures
   typedef struct {float x,y,z;} POINT;
   static POINT point;

  cout << "Create tree" << endl;
//TTree *t3 = (TTree*) -> Get("t3"); // if tuple existed
  TTree *ptree = new TTree("ptree", "My comment to TTree");

  cout << "Create  a couple of branches" << endl;
  float new_v;
  TBranch *pbranch = ptree -> Branch("new_v", &new_v, "new_v/F");
                     ptree -> Branch("point",&point,"x:y:z");

  cout << "Fill branch" << endl;
  for (int i = 0; i < 10000; i++){

      new_v   = gRandom->Gaus(0, 1); // Gaus(0, 1) generates a random number 
                                     // for normal distribution with mean=0 and sigma=1
      point.x = gRandom->Gaus(1, 1);
      point.y = gRandom->Gaus(2, 1);
      point.z = gRandom->Gaus(3, 1);

      ptree->Fill();
  }

  cout << "Write tree in file" << endl;
  ptree -> Write();

  cout << "Close file" << endl;
  pfile -> Close();

  return 0;

}

...