Analysis of tree by MakeClass and Modifying ::Loop problems

Hello ROOTers,
I should analysed values in branches of tree and calculate parameter on the basis of these values. I used MakeClass method to produce class including Chain of trees.


detector=7;
sprintf(tree1_name[detector],“treetype2_%d”,detector);
TChain ch1(tree1_name[detector]);
ch1.Add("/export/ppac/ROOT_files2003/Run4845_ppac_v1.root");
ch1.Add("/export/ppac/ROOT_files2003/Run4846_ppac_v1.root");
ch1.Add("/export/ppac/ROOT_files2003/Run4847_ppac_v1.root");
sprintf(classname2[detector],“TYPE2_S%d”,sel);
ch1->MakeClass(classname2[detector]);


and I got two files named TYPE2_S1.C and TYPE2_S1.h
I didn’t change the last one. But I try to modify first as follows


#define TYPE2_S1_cxx
#include “TYPE2_S1.h”
#include “TH2.h”
#include “TStyle.h”
#include “TCanvas.h”

if (!TClassTable::GetDict(“Event”)){
gSystem->Load("$ROOTSYS/test/libEvent.so");}

void TYPE2_S1::Loop()
{
int es=0;
int ef=30;
int bin=3000;
char canvas_name[50];
float pl=183.71;
sprintf(canvas_name,“Fratio_T2”);
ccx = new TCanvas (canvas_name,canvas_name,1000,1000);
if (fChain == 0) return;
Int_t nentries = Int_t(fChain->GetEntries());
// Int_t nbytes = 0, nb = 0;
TH1F h2 = new TH1F(“h2”,“TYPE-2 centre”,bin,es,ef);
for (Int_t jentry=0; jentry<nentries;jentry++) {
// Int_t ientry = LoadTree(jentry);
// nb = fChain->GetEntry(jentry);
// nbytes += nb;
GetEntry(jentry);
h2->Fill(939.56
(sqrt(1/(1-pl*pl/0.0009/(event2.t_0-55880+6210)/(event2.t_0-55880+6210)))-1)*1000000);}
h2->Draw();
h2->SetXTitle(“En, eV”);
h2->Print(“all”);}


where pl is the constant isn’t included in tree.The part of file *.h related to branches is


lass TYPE2_S1 {
public :
TTree *fChain; //!pointer to the analyzed TTree or TChain
Int_t fCurrent; //!current Tree number in a TChain
//Declaration of leaves types
Int_t event2_event;
Int_t event2_t_0;
Float_t event2_amp_0;
Int_t event2_t_1;
Float_t event2_amp_1;
Int_t x_0_tdir;
Int_t x_0_tref;
Float_t x_0_ampdir;
Float_t x_0_ampref;
Int_t x_0_nb_sig;
Int_t y_0_tdir;
Int_t y_0_tref;
Float_t y_0_ampdir;
Float_t y_0_ampref;
Int_t y_0_nb_sig;
Int_t x_1_tdir;
Int_t x_1_tref;
Float_t x_1_ampdir;
Float_t x_1_ampref;
Int_t x_1_nb_sig;
Int_t y_1_tdir;
Int_t y_1_tref;
Float_t y_1_ampdir;
Float_t y_1_ampref;
Int_t y_1_nb_sig;

//List of branches
TBranch *b_event2; //!
TBranch *b_x_0; //!
TBranch *b_y_0; //!
TBranch *b_x_1; //!
TBranch *b_y_1; //!

TYPE2_S1(TTree *tree=0);
~TYPE2_S1();
Int_t Cut(Int_t entry);
Int_t GetEntry(Int_t entry);
Int_t LoadTree(Int_t entry);
void Init(TTree *tree);
void Loop();
Bool_t Notify();
void Show(Int_t entry = -1);
};


and for chains -


void TYPE2_S1::Init(TTree *tree)
{
// Set branch addresses
if (tree == 0) return;
fChain = tree;
fCurrent = -1;
fChain->SetMakeClass(1);

fChain->SetBranchAddress(“event2”,&event2_event);
fChain->SetBranchAddress(“x_0”,&x_0_tdir);
fChain->SetBranchAddress(“y_0”,&y_0_tdir);
fChain->SetBranchAddress(“x_1”,&x_1_tdir);
fChain->SetBranchAddress(“y_1”,&y_1_tdir);
Notify();
}


I started file TYPE2_S1.C and got nothing -
root [0] .x TYPE2_S1.C
element: Double_t fEntries has new type: Stat_t
element: Double_t fTotBytes has new type: Stat_t
element: Double_t fZipBytes has new type: Stat_t
element: Double_t fSavedBytes has new type: Stat_t
(const class TYPE2_S1)140774264
Could you help me, please? What did I do incorrect in files?

Hi,

You have a few problems.
The line:

if (!TClassTable::GetDict("Event")){ gSystem->Load("$ROOTSYS/test/libEvent.so");}
are hanging in the global namespace. This is invalid C++.

This is not suppose to do anything. TYPE2_S1. C is not and executable script. Typicall usage is

root [] .L TYPE2_S1.C root [] TYPE2_S1 s; root [] s.Loop();
Please review carefully the ROOT Users’ Guide and the tutorials (h1analysis in particular).

Cheers,
Philippe.

Thank you Philippe,
now it works.