Discussion:
Import branch after a MakeClass()
p***@na.infn.it
2014-10-15 16:33:31 UTC
Permalink
Hi All,

I have the following problem:
If I run MakeClass() on a rootfile containing a tree with some branches I
can import in a new tree in .C file generated by MakeClass() all variables
I want (I have verified this for exercise) but when I try to import the
one, the only one (test_h3), I need this don't done.

In .C file I done:

#define analisi_2_cxx
#include "analisi_2.h"
#include <TH2.h>
#include <TH3.h>
#include <TStyle.h>
#include <TCanvas.h>

void analisi_2::Loop()
{

if (fChain == 0) return;

Long64_t nentries = fChain->GetEntriesFast();

Long64_t nbytes = 0, nb = 0;

TFile *f1 = new TFile("/home/perfetto/testolo.root","RECREATE","file
with tree");

Int_t npixels;

TTree *testtree = new TTree("testtree","tree di prova");

// This I import only for testing the all work fine (it's ll ok)
testtree->Branch("clkb", &clkb_pcknumber,
"pcknumber/i:evnt/i:gtime/i:ltime/i:dtime/i:status/i:crccheck/i:ltimems/F:dtimems/F:satsee/i:sattrack/i:month/i:day/i:year/i:hour/i:min/i:sec/i:timestamp/i:gps_alt/F:gps_lat/F:gps_lon/F");
testtree->Branch("cpu", &cpu_header,
"header/i:evnt/i:time/i:pcktype/i:dlenght/i:crccheck/i");
testtree->Branch("ccb", &ccb_messagetype,
"messagetype/i:deviceid/i:triggertime/i:l2count/i:crccheck/i");

// THIS IS I NEED
testtree->Branch("test_h3", "TH3C", &test_h3);

tree->Branch("npixels", &npixels, "npixels/I");

TH3C *test_h3 = 0;
testtree->SetBranchAddress("test_h3", &test_h3);

for (Long64_t jentry = 0; jentry < nentries; jentry++) {
Long64_t ientry = LoadTree(jentry);
if (ientry < 0) break;
nb = fChain->GetEntry(jentry); nbytes += nb;
cout << "jentry = " << jentry << " nb = " << nb << endl;
// if (Cut(ientry) < 0) continue;

tree->GetEntry(jentry);
npixels = (Int_t)test_h3->Project3D("yx")->GetEntries();

testtree->Fill();
}
testtree->Write();
}

And this is from my .h file
...
// Header file for the classes stored in the TTree if any.
#include <TH3.h>

// Fixed size dimensions of array or collections stored in the TTree if any.

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

// Declaration of leaf types
UInt_t clkb_pcknumber;
UInt_t clkb_evnt;
UInt_t clkb_gtime;
UInt_t clkb_ltime;
UInt_t clkb_dtime;
UInt_t clkb_status;
UInt_t clkb_crccheck;
Float_t clkb_ltimems;
Float_t clkb_dtimems;
UInt_t clkb_satsee;
UInt_t clkb_sattrack;
UInt_t clkb_month;
UInt_t clkb_day;
UInt_t clkb_year;
UInt_t clkb_hour;
UInt_t clkb_min;
UInt_t clkb_sec;
UInt_t clkb_timestamp;
Float_t clkb_gps_alt;
Float_t clkb_gps_lat;
Float_t clkb_gps_lon;
UInt_t cpu_header;
UInt_t cpu_evnt;
UInt_t cpu_time;
UInt_t cpu_pcktype;
UInt_t cpu_dlenght;
UInt_t cpu_crccheck;
UInt_t ccb_messagetype;
UInt_t ccb_deviceid;
UInt_t ccb_triggertime;
UInt_t ccb_l2count;
UInt_t ccb_crccheck;
TH3C *test_h3; <<<<------- This is the variable I need

// List of branches
TBranch *b_clkb; //!
TBranch *b_cpu; //!
TBranch *b_ccb; //!
TBranch *b_test_h3; //!

analisi_2(TTree *tree=0);
virtual ~analisi_2();
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);
};
....

Thanks in advance for your help.

Regards
Francesco.
Philippe Canal
2014-10-15 17:02:02 UTC
Permalink
Hi Francesco,

I am not completely sure of what works and what does not work in your example.

Also which version of ROOT are you using?

Cheers,
Philippe.
Post by p***@na.infn.it
Hi All,
If I run MakeClass() on a rootfile containing a tree with some branches I
can import in a new tree in .C file generated by MakeClass() all variables
I want (I have verified this for exercise) but when I try to import the
one, the only one (test_h3), I need this don't done.
#define analisi_2_cxx
#include "analisi_2.h"
#include <TH2.h>
#include <TH3.h>
#include <TStyle.h>
#include <TCanvas.h>
void analisi_2::Loop()
{
if (fChain == 0) return;
Long64_t nentries = fChain->GetEntriesFast();
Long64_t nbytes = 0, nb = 0;
TFile *f1 = new TFile("/home/perfetto/testolo.root","RECREATE","file
with tree");
Int_t npixels;
TTree *testtree = new TTree("testtree","tree di prova");
// This I import only for testing the all work fine (it's ll ok)
testtree->Branch("clkb", &clkb_pcknumber,
"pcknumber/i:evnt/i:gtime/i:ltime/i:dtime/i:status/i:crccheck/i:ltimems/F:dtimems/F:satsee/i:sattrack/i:month/i:day/i:year/i:hour/i:min/i:sec/i:timestamp/i:gps_alt/F:gps_lat/F:gps_lon/F");
testtree->Branch("cpu", &cpu_header,
"header/i:evnt/i:time/i:pcktype/i:dlenght/i:crccheck/i");
testtree->Branch("ccb", &ccb_messagetype,
"messagetype/i:deviceid/i:triggertime/i:l2count/i:crccheck/i");
// THIS IS I NEED
testtree->Branch("test_h3", "TH3C", &test_h3);
tree->Branch("npixels", &npixels, "npixels/I");
TH3C *test_h3 = 0;
testtree->SetBranchAddress("test_h3", &test_h3);
for (Long64_t jentry = 0; jentry < nentries; jentry++) {
Long64_t ientry = LoadTree(jentry);
if (ientry < 0) break;
nb = fChain->GetEntry(jentry); nbytes += nb;
cout << "jentry = " << jentry << " nb = " << nb << endl;
// if (Cut(ientry) < 0) continue;
tree->GetEntry(jentry);
npixels = (Int_t)test_h3->Project3D("yx")->GetEntries();
testtree->Fill();
}
testtree->Write();
}
And this is from my .h file
...
// Header file for the classes stored in the TTree if any.
#include <TH3.h>
// Fixed size dimensions of array or collections stored in the TTree if any.
class analisi_2 {
TTree *fChain; //!pointer to the analyzed TTree or TChain
Int_t fCurrent; //!current Tree number in a TChain
// Declaration of leaf types
UInt_t clkb_pcknumber;
UInt_t clkb_evnt;
UInt_t clkb_gtime;
UInt_t clkb_ltime;
UInt_t clkb_dtime;
UInt_t clkb_status;
UInt_t clkb_crccheck;
Float_t clkb_ltimems;
Float_t clkb_dtimems;
UInt_t clkb_satsee;
UInt_t clkb_sattrack;
UInt_t clkb_month;
UInt_t clkb_day;
UInt_t clkb_year;
UInt_t clkb_hour;
UInt_t clkb_min;
UInt_t clkb_sec;
UInt_t clkb_timestamp;
Float_t clkb_gps_alt;
Float_t clkb_gps_lat;
Float_t clkb_gps_lon;
UInt_t cpu_header;
UInt_t cpu_evnt;
UInt_t cpu_time;
UInt_t cpu_pcktype;
UInt_t cpu_dlenght;
UInt_t cpu_crccheck;
UInt_t ccb_messagetype;
UInt_t ccb_deviceid;
UInt_t ccb_triggertime;
UInt_t ccb_l2count;
UInt_t ccb_crccheck;
TH3C *test_h3; <<<<------- This is the variable I need
// List of branches
TBranch *b_clkb; //!
TBranch *b_cpu; //!
TBranch *b_ccb; //!
TBranch *b_test_h3; //!
analisi_2(TTree *tree=0);
virtual ~analisi_2();
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);
};
....
Thanks in advance for your help.
Regards
Francesco.
Francesco Perfetto
2014-10-15 18:20:42 UTC
Permalink
I Philippe,

with the simple variables (clkb_p knumber, clkb_evnt... ccb_crccheck) that I imported for example, for testing the procedure to import branches after a MakeClass() all work fine, while when I import the test_h3 branch I find void histos.

I use root 5.34.21 on SL6

Thanks
Francesco.
Post by Philippe Canal
Hi Francesco,
I am not completely sure of what works and what does not work in your example.
Also which version of ROOT are you using?
Cheers,
Philippe.
Post by p***@na.infn.it
Hi All,
If I run MakeClass() on a rootfile containing a tree with some branches I
can import in a new tree in .C file generated by MakeClass() all variables
I want (I have verified this for exercise) but when I try to import the
one, the only one (test_h3), I need this don't done.
#define analisi_2_cxx
#include "analisi_2.h"
#include <TH2.h>
#include <TH3.h>
#include <TStyle.h>
#include <TCanvas.h>
void analisi_2::Loop()
{
if (fChain == 0) return;
Long64_t nentries = fChain->GetEntriesFast();
Long64_t nbytes = 0, nb = 0;
TFile *f1 = new TFile("/home/perfetto/testolo.root","RECREATE","file
with tree");
Int_t npixels;
TTree *testtree = new TTree("testtree","tree di prova");
// This I import only for testing the all work fine (it's ll ok)
testtree->Branch("clkb", &clkb_pcknumber,
"pcknumber/i:evnt/i:gtime/i:ltime/i:dtime/i:status/i:crccheck/i:ltimems/F:dtimems/F:satsee/i:sattrack/i:month/i:day/i:year/i:hour/i:min/i:sec/i:timestamp/i:gps_alt/F:gps_lat/F:gps_lon/F");
testtree->Branch("cpu", &cpu_header,
"header/i:evnt/i:time/i:pcktype/i:dlenght/i:crccheck/i");
testtree->Branch("ccb", &ccb_messagetype,
"messagetype/i:deviceid/i:triggertime/i:l2count/i:crccheck/i");
// THIS IS I NEED
testtree->Branch("test_h3", "TH3C", &test_h3);
tree->Branch("npixels", &npixels, "npixels/I");
TH3C *test_h3 = 0;
testtree->SetBranchAddress("test_h3", &test_h3);
for (Long64_t jentry = 0; jentry < nentries; jentry++) {
Long64_t ientry = LoadTree(jentry);
if (ientry < 0) break;
nb = fChain->GetEntry(jentry); nbytes += nb;
cout << "jentry = " << jentry << " nb = " << nb << endl;
// if (Cut(ientry) < 0) continue;
tree->GetEntry(jentry);
npixels = (Int_t)test_h3->Project3D("yx")->GetEntries();
testtree->Fill();
}
testtree->Write();
}
And this is from my .h file
...
// Header file for the classes stored in the TTree if any.
#include <TH3.h>
// Fixed size dimensions of array or collections stored in the TTree if any.
class analisi_2 {
TTree *fChain; //!pointer to the analyzed TTree or TChain
Int_t fCurrent; //!current Tree number in a TChain
// Declaration of leaf types
UInt_t clkb_pcknumber;
UInt_t clkb_evnt;
UInt_t clkb_gtime;
UInt_t clkb_ltime;
UInt_t clkb_dtime;
UInt_t clkb_status;
UInt_t clkb_crccheck;
Float_t clkb_ltimems;
Float_t clkb_dtimems;
UInt_t clkb_satsee;
UInt_t clkb_sattrack;
UInt_t clkb_month;
UInt_t clkb_day;
UInt_t clkb_year;
UInt_t clkb_hour;
UInt_t clkb_min;
UInt_t clkb_sec;
UInt_t clkb_timestamp;
Float_t clkb_gps_alt;
Float_t clkb_gps_lat;
Float_t clkb_gps_lon;
UInt_t cpu_header;
UInt_t cpu_evnt;
UInt_t cpu_time;
UInt_t cpu_pcktype;
UInt_t cpu_dlenght;
UInt_t cpu_crccheck;
UInt_t ccb_messagetype;
UInt_t ccb_deviceid;
UInt_t ccb_triggertime;
UInt_t ccb_l2count;
UInt_t ccb_crccheck;
TH3C *test_h3; <<<<------- This is the variable I need
// List of branches
TBranch *b_clkb; //!
TBranch *b_cpu; //!
TBranch *b_ccb; //!
TBranch *b_test_h3; //!
analisi_2(TTree *tree=0);
virtual ~analisi_2();
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);
};
....
Thanks in advance for your help.
Regards
Francesco.
Philippe Canal
2014-10-15 18:41:06 UTC
Permalink
Hi Francesco,

Try adding:

fChain->GetBranch("test_h3")->SetMakeClass(kFALSE);

Cheers,
Philippe.
Post by Francesco Perfetto
I Philippe,
with the simple variables (clkb_p knumber, clkb_evnt... ccb_crccheck) that I imported for example, for testing the procedure to import branches after a MakeClass() all work fine, while when I import the test_h3 branch I find void histos.
I use root 5.34.21 on SL6
Thanks
Francesco.
Post by Philippe Canal
Hi Francesco,
I am not completely sure of what works and what does not work in your example.
Also which version of ROOT are you using?
Cheers,
Philippe.
Post by p***@na.infn.it
Hi All,
If I run MakeClass() on a rootfile containing a tree with some branches I
can import in a new tree in .C file generated by MakeClass() all variables
I want (I have verified this for exercise) but when I try to import the
one, the only one (test_h3), I need this don't done.
#define analisi_2_cxx
#include "analisi_2.h"
#include <TH2.h>
#include <TH3.h>
#include <TStyle.h>
#include <TCanvas.h>
void analisi_2::Loop()
{
if (fChain == 0) return;
Long64_t nentries = fChain->GetEntriesFast();
Long64_t nbytes = 0, nb = 0;
TFile *f1 = new TFile("/home/perfetto/testolo.root","RECREATE","file
with tree");
Int_t npixels;
TTree *testtree = new TTree("testtree","tree di prova");
// This I import only for testing the all work fine (it's ll ok)
testtree->Branch("clkb", &clkb_pcknumber,
"pcknumber/i:evnt/i:gtime/i:ltime/i:dtime/i:status/i:crccheck/i:ltimems/F:dtimems/F:satsee/i:sattrack/i:month/i:day/i:year/i:hour/i:min/i:sec/i:timestamp/i:gps_alt/F:gps_lat/F:gps_lon/F");
testtree->Branch("cpu", &cpu_header,
"header/i:evnt/i:time/i:pcktype/i:dlenght/i:crccheck/i");
testtree->Branch("ccb", &ccb_messagetype,
"messagetype/i:deviceid/i:triggertime/i:l2count/i:crccheck/i");
// THIS IS I NEED
testtree->Branch("test_h3", "TH3C", &test_h3);
tree->Branch("npixels", &npixels, "npixels/I");
TH3C *test_h3 = 0;
testtree->SetBranchAddress("test_h3", &test_h3);
for (Long64_t jentry = 0; jentry < nentries; jentry++) {
Long64_t ientry = LoadTree(jentry);
if (ientry < 0) break;
nb = fChain->GetEntry(jentry); nbytes += nb;
cout << "jentry = " << jentry << " nb = " << nb << endl;
// if (Cut(ientry) < 0) continue;
tree->GetEntry(jentry);
npixels = (Int_t)test_h3->Project3D("yx")->GetEntries();
testtree->Fill();
}
testtree->Write();
}
And this is from my .h file
...
// Header file for the classes stored in the TTree if any.
#include <TH3.h>
// Fixed size dimensions of array or collections stored in the TTree if any.
class analisi_2 {
TTree *fChain; //!pointer to the analyzed TTree or TChain
Int_t fCurrent; //!current Tree number in a TChain
// Declaration of leaf types
UInt_t clkb_pcknumber;
UInt_t clkb_evnt;
UInt_t clkb_gtime;
UInt_t clkb_ltime;
UInt_t clkb_dtime;
UInt_t clkb_status;
UInt_t clkb_crccheck;
Float_t clkb_ltimems;
Float_t clkb_dtimems;
UInt_t clkb_satsee;
UInt_t clkb_sattrack;
UInt_t clkb_month;
UInt_t clkb_day;
UInt_t clkb_year;
UInt_t clkb_hour;
UInt_t clkb_min;
UInt_t clkb_sec;
UInt_t clkb_timestamp;
Float_t clkb_gps_alt;
Float_t clkb_gps_lat;
Float_t clkb_gps_lon;
UInt_t cpu_header;
UInt_t cpu_evnt;
UInt_t cpu_time;
UInt_t cpu_pcktype;
UInt_t cpu_dlenght;
UInt_t cpu_crccheck;
UInt_t ccb_messagetype;
UInt_t ccb_deviceid;
UInt_t ccb_triggertime;
UInt_t ccb_l2count;
UInt_t ccb_crccheck;
TH3C *test_h3; <<<<------- This is the variable I need
// List of branches
TBranch *b_clkb; //!
TBranch *b_cpu; //!
TBranch *b_ccb; //!
TBranch *b_test_h3; //!
analisi_2(TTree *tree=0);
virtual ~analisi_2();
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);
};
....
Thanks in advance for your help.
Regards
Francesco.
Loading...