Logo ROOT  
Reference Guide
tree0.C File Reference

Detailed Description

View in nbviewer Open in SWAN Simple Event class example

execute as: .x tree0.C++

You have to copy it first to a directory where you have write access! Note that .x tree0.C cannot work with this example

Effect of ClassDef() and ClassImp() macros

After running this macro create an instance of Det and Event

Det d;
#define d(i)
Definition: RSha256.hxx:102
#define e(i)
Definition: RSha256.hxx:103

now you can see the effect of the ClassDef() and ClassImp() macros. (for the Det class these commands are commented!) For instance 'e' now knows who it is:


whereas d does not.

The methods that are added by the ClassDef()/Imp() macro can be listed with

.class Event
.class Det
#include <TRandom.h>
#include <TTree.h>
#include <TCanvas.h>
#include <TStyle.h>
#include <Riostream.h>
//class Det : public TObject {
class Det { // each detector gives an energy and time signal
Double_t e; //energy
Double_t t; //time
// ClassDef(Det,1)
//class Event { //TObject is not required by this example
class Event : public TObject {
Det a; // say there are two detectors (a and b) in the experiment
Det b;
void tree0() {
// create a TTree
TTree *tree = new TTree("tree","treelibrated tree");
Event *e = new Event;
// create a branch with energy
// fill some events with random numbers
Int_t nevent=10000;
for (Int_t iev=0;iev<nevent;iev++) {
if (iev%1000==0) cout<<"Processing event "<<iev<<"..."<<endl;
Float_t ea,eb;
gRandom->Rannor(ea,eb); // the two energies follow a gaus distribution
e->a.t=gRandom->Rndm(); // random
e->b.t=e->a.t + gRandom->Gaus(0.,.1); // identical to a.t but a gaussian
// 'resolution' was added with sigma .1
tree->Fill(); // fill the tree with the current event
// start the viewer
// here you can investigate the structure of your Event class
//gROOT->SetStyle("Plain"); // uncomment to set a different style
// now draw some tree variables
TCanvas *c1 = new TCanvas();
tree->Draw("a.e"); //energy of det a
tree->Draw("a.e","3*(-.2<b.e && b.e<.2)","same"); // same but with condition on energy b; scaled by 3
tree->Draw("b.e:a.e","","colz"); // one energy against the other
tree->Draw("b.t","","e"); // time of b with errorbars
tree->Draw("a.t","","same"); // overlay time of detector a
tree->Draw("b.t:a.t"); // plot time b again time a
cout<<"You can now examine the structure of your tree in the TreeViewer"<<endl;
int Int_t
Definition: RtypesCore.h:45
float Float_t
Definition: RtypesCore.h:57
double Double_t
Definition: RtypesCore.h:59
#define ClassDef(name, id)
Definition: Rtypes.h:335
#define ClassImp(name)
Definition: Rtypes.h:375
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t b
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
The Canvas class.
Definition: TCanvas.h:23
Mother of all ROOT objects.
Definition: TObject.h:37
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition: TRandom.cxx:274
Double_t Rndm() override
Machine independent random number generator.
Definition: TRandom.cxx:552
virtual void Rannor(Float_t &a, Float_t &b)
Return 2 numbers distributed following a gaussian with mean=0 and sigma=1.
Definition: TRandom.cxx:500
A TTree represents a columnar dataset.
Definition: TTree.h:79
return c1
Definition: legend1.C:41
Definition: tree.py:1
TArc a
Definition: textangle.C:12

Definition in file tree0.C.