Re: Creating Branches

Rene Brun (Rene.Brun@cern.ch)
Thu, 26 Jun 1997 18:20:12 +0200


Maarten Bruinsma wrote:
>
> Thanks, but I am afraid that wasn't it. I changed it and still get the
> same error. The peculiar thing is, however that it works in
> an interactive session. You guessed it right... I am compiling again.
> Strange...

Below is a complete example ready to compile and link based on your
initial program.
Very likely you forgot the includes !!

Rene Brun

//______________________________________________________________________________
// Simple example with a Tree
// ==========================
//
// This program creates :
// - a ROOT file
// - a TTree with a few branches
// - writes the TTree on the file
//
//*-- Author : Rene Brun 26/06/97

#include "TROOT.h"
#include "TFile.h"
#include "TTree.h"

Int_t Error;

//______________________________________________________________________________
main(int argc, char **argv)
{
TROOT simple("simple","Test of TTree");

TFile hfile("mar.root","RECREATE","ROOT with all info on muons");

typedef struct {Float_t x,y,z;} POINT;
POINT begin_vertex;
POINT end_vertex;
POINT momentum;
Int_t mother;
Float_t p;
Float_t pt;
Float_t track_length;

// this tree contain momenta etc. of several types of muons

TTree *muontree = new TTree("muontree","Data for all muons");

muontree->Branch("Momentum",&momentum,"Px:Py:Pz");
muontree->Branch("Begin_Vertex",&begin_vertex,"Xvert:Yvert:Zvert");
muontree->Branch("EndVertex",&end_vertex,"Xvert2:Yvert2:Zvert2");
muontree->Branch("Tracklength",&track_length,"Tracklength");
muontree->Branch("P",&p,"P");
muontree->Branch("Pt",&pt,"Pt");
muontree->Branch("Mother",&mother,"Mother/I");

muontree->Print();
muontree->Write();
return 0;
}