How to automatically generate classes code

Hi,

I want to generate a Class similar to the below one (look at the end of the mail).

I have this class “Singles” which helps me in processing data stored in .root format. This class looks like it got generated using root.

I need to generate a similar class “Hits” to do similar processing but for a different data set. Could some body guide me to the Documentation or Tutorials for doing this.

Thanks
Phani

Sample: Singles.h

Code:

//////////////////////////////////////////////////////////
// This class has been automatically generated on
// Fri Oct 21 16:49:19 2005 by ROOT version 4.02/00
// from TTree Singles/The root tree for singles
// found on file: microSPECT.root
//////////////////////////////////////////////////////////

#ifndef Singles_h
#define Singles_h

#include <TROOT.h>
#include <TChain.h>
#include <TFile.h>

class Singles {
public :
TTree *fChain; //!pointer to the analyzed TTree or TChain
Int_t fCurrent; //!current Tree number in a TChain

// Declaration of leave types
Int_t runID;
Int_t eventID;
Int_t sourceID;
Float_t sourcePosX;
Float_t sourcePosY;
Float_t sourcePosZ;
Double_t time;
Float_t energy;
Float_t globalPosX;
Float_t globalPosY;
Float_t globalPosZ;
Int_t headID;
Int_t crystalID;
Int_t pixelID;
Int_t unused3ID;
Int_t unused4ID;
Int_t unused5ID;
Int_t comptonPhantom;
Int_t comptonCrystal;
Int_t RayleighPhantom;
Int_t RayleighCrystal;
Float_t axialPos;
Float_t rotationAngle;
Char_t comptVolName[13];
Char_t RayleighVolName[13];

// List of branches
TBranch *b_runID; //!
TBranch *b_eventID; //!
TBranch *b_sourceID; //!
TBranch *b_sourcePosX; //!
TBranch *b_sourcePosY; //!
TBranch *b_sourcePosZ; //!
TBranch *b_time; //!
TBranch *b_energy; //!
TBranch *b_globalPosX; //!
TBranch *b_globalPosY; //!
TBranch *b_globalPosZ; //!
TBranch *b_headID; //!
TBranch *b_crystalID; //!
TBranch *b_pixelID; //!
TBranch *b_unused3ID; //!
TBranch *b_unused4ID; //!
TBranch *b_unused5ID; //!
TBranch *b_comptonPhantom; //!
TBranch *b_comptonCrystal; //!
TBranch *b_RayleighPhantom; //!
TBranch *b_RayleighCrystal; //!
TBranch *b_axialPos; //!
TBranch *b_rotationAngle; //!
TBranch *b_comptVolName; //!
TBranch *b_RayleighVolName; //!

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

#endif

#ifdef Singles_cxx
Singles::Singles(TTree tree)
{
// if parameter tree is not specified (or zero), connect the file
// used to generate this class and read the Tree.
if (tree == 0) {
TFile f = (TFile)gROOT->GetListOfFiles()->FindObject(“output.root”);
if (!f) {
f = new TFile(“output.root”);
}
tree = (TTree
)gDirectory->Get(“Singles”);

}
Init(tree);
}

Singles::~Singles()
{
if (!fChain) return;
delete fChain->GetCurrentFile();
}

Int_t Singles::GetEntry(Long64_t entry)
{
// Read contents of entry.
if (!fChain) return 0;
return fChain->GetEntry(entry);
}
Long64_t Singles::LoadTree(Long64_t entry)
{
// Set the environment to read one entry
if (!fChain) return -5;
Long64_t centry = fChain->LoadTree(entry);
if (centry < 0) return centry;
if (fChain->IsA() != TChain::Class()) return centry;
TChain chain = (TChain)fChain;
if (chain->GetTreeNumber() != fCurrent) {
fCurrent = chain->GetTreeNumber();
Notify();
}
return centry;
}

void Singles::Init(TTree *tree)
{
// The Init() function is called when the selector needs to initialize
// a new tree or chain. Typically here the branch addresses of the tree
// will be set. It is normaly not necessary to make changes to the
// generated code, but the routine can be extended by the user if needed.
// Init() will be called many times when running with PROOF.

// Set branch addresses
if (tree == 0) return;
fChain = tree;
fCurrent = -1;
fChain->SetMakeClass(1);

fChain->SetBranchAddress(“runID”,&runID);
fChain->SetBranchAddress(“eventID”,&eventID);
fChain->SetBranchAddress(“sourceID”,&sourceID);
fChain->SetBranchAddress(“sourcePosX”,&sourcePosX);
fChain->SetBranchAddress(“sourcePosY”,&sourcePosY);
fChain->SetBranchAddress(“sourcePosZ”,&sourcePosZ);
fChain->SetBranchAddress(“time”,&time);
fChain->SetBranchAddress(“energy”,&energy);
fChain->SetBranchAddress(“globalPosX”,&globalPosX);
fChain->SetBranchAddress(“globalPosY”,&globalPosY);
fChain->SetBranchAddress(“globalPosZ”,&globalPosZ);
//fChain->SetBranchAddress(“headID”,&headID);
fChain->SetBranchAddress(“crystalID”,&crystalID);
//fChain->SetBranchAddress(“pixelID”,&pixelID);
//fChain->SetBranchAddress(“unused3ID”,&unused3ID);
//fChain->SetBranchAddress(“unused4ID”,&unused4ID);
//fChain->SetBranchAddress(“unused5ID”,&unused5ID);
fChain->SetBranchAddress(“comptonPhantom”,&comptonPhantom);
fChain->SetBranchAddress(“comptonCrystal”,&comptonCrystal);
fChain->SetBranchAddress(“RayleighPhantom”,&RayleighPhantom);
fChain->SetBranchAddress(“RayleighCrystal”,&RayleighCrystal);
fChain->SetBranchAddress(“axialPos”,&axialPos);
fChain->SetBranchAddress(“rotationAngle”,&rotationAngle);
fChain->SetBranchAddress(“comptVolName”,comptVolName);
fChain->SetBranchAddress(“RayleighVolName”,RayleighVolName);
Notify();
}

Bool_t Singles::Notify()
{
// The Notify() function is called when a new file is opened. This
// can be either for a new TTree in a TChain or when when a new TTree
// is started when using PROOF. Typically here the branch pointers
// will be retrieved. It is normaly not necessary to make changes
// to the generated code, but the routine can be extended by the
// user if needed.

// Get branch pointers
b_runID = fChain->GetBranch(“runID”);
b_eventID = fChain->GetBranch(“eventID”);
b_sourceID = fChain->GetBranch(“sourceID”);
b_sourcePosX = fChain->GetBranch(“sourcePosX”);
b_sourcePosY = fChain->GetBranch(“sourcePosY”);
b_sourcePosZ = fChain->GetBranch(“sourcePosZ”);
b_time = fChain->GetBranch(“time”);
b_energy = fChain->GetBranch(“energy”);
b_globalPosX = fChain->GetBranch(“globalPosX”);
b_globalPosY = fChain->GetBranch(“globalPosY”);
b_globalPosZ = fChain->GetBranch(“globalPosZ”);
b_headID = fChain->GetBranch(“headID”);
b_crystalID = fChain->GetBranch(“crystalID”);
b_pixelID = fChain->GetBranch(“pixelID”);
b_unused3ID = fChain->GetBranch(“unused3ID”);
b_unused4ID = fChain->GetBranch(“unused4ID”);
b_unused5ID = fChain->GetBranch(“unused5ID”);
b_comptonPhantom = fChain->GetBranch(“comptonPhantom”);
b_comptonCrystal = fChain->GetBranch(“comptonCrystal”);
b_RayleighPhantom = fChain->GetBranch(“RayleighPhantom”);
b_RayleighCrystal = fChain->GetBranch(“RayleighCrystal”);
b_axialPos = fChain->GetBranch(“axialPos”);
b_rotationAngle = fChain->GetBranch(“rotationAngle”);
b_comptVolName = fChain->GetBranch(“comptVolName”);
b_RayleighVolName = fChain->GetBranch(“RayleighVolName”);

return kTRUE;
}

void Singles::Show(Long64_t entry)
{
// Print contents of entry.
// If entry is not specified, print current entry
if (!fChain) return;
fChain->Show(entry);
}
Int_t Singles::Cut(Long64_t entry)
{
// This function may be called from Loop.
// returns 1 if entry is accepted.
// returns -1 otherwise.
return 1;
}
#endif // #ifdef Singles_cxx

Use TTree::MakeClass, eg

mytree.MakeClass("mycode") will generate mycode.h and mycode.C

Rene

Thanks