Problem Reading TTree

Hello everyone,

I am new on this forum, I am doing some analysis using Root. First of all I want to apologize for any english mistakes.

Although its not very nice to have the first post asking for help I will do it, sorry x(, so here it goes:

I read a TChain and create a TTree and before writing it to a file I generate 3 different graphics from this TTree I created. The problem I am having is when I read the TTree I wrote. I am reading the same TTree 3 times for making the graphics, and now I need to read it one more time to make more analysis and its causing some strange effects.

For now lets forget I want to read it four times, the four time problem is related to another problem I had when I wanted to read it three or even two times(in fact the problem is related to reading the TTree multiple times).

I have this general function, called genData. In this function I initialize this variables:

	TFile 		*file;
	TChain		*chainAnalysis;
	TTree		*generateData;
	NeuralEfic	*myNeural;
	T2CaloEfic	*myT2Calo;

	generateData	= new TTree("HypoData", "Tree with Hypo data");

Then I create the generate the data and fill my tree, and create the file, but I wont put it here because it probably wont help.

And, finally, the bug. See the following code:


        myNeural->drawNetAns();

        scatterPlot(generateData);

	myT2Calo->drawCutCounter();

If I change the order from this function or it read the TTree with dummy values that are not the real values that is written on it.

Here are the reduced codes from NeuralEfic::drawNetAns(), scatterPlot(TTree tree) and T2CaloEfic::drawCutCounter():

1-drawNetAns

Efic::CODE NeuralEfic::drawNetAns(){


        TH1F *hNans = new TH1F("NeuralNetworkOutput", "L2 Calo Neural Network Output", 220, -1.1, 1.1);

        hNans -> GetXaxis() -> SetTitle("OutPut Neuron Value");

        TCanvas *c2 = new TCanvas("Neural Output", "Neural Output");

        vector<float> *netAns   =       new vector<float>;

        int nEntries            =       static_cast<int>(eficFillingTree->GetEntries());

	eficFillingTree->SetBranchStatus("RingerOut",	true);

	eficFillingTree->SetBranchAddress("RingerOut",	&netAns);

	for(int i=0; i<nEntries;++i){

		eficFillingTree->GetEntry(i);

		for(size_t j=0; j<netAns->size();++j){

                        //here i Fill hNans

                }

        }

        hNans->Draw();

        delete netAns;

        return Efic::OK;

}

NOTE: EficFillingTree is the same as generateData, on constructor:

	myNeural        = new NeuralEfic(chainAnalysis, generateData);
	myT2Calo	= new T2CaloEfic(chainAnalysis, generateData);

	Efic(TChain *outsideChain, TTree *outsideFillingTree){

                eficReadingChain = outsideChain;

                eficFillingTree = outsideFillingTree;
        }

2-scatterPlot (this function does not belong to any class, its declared on the main script genData.cxx)

int scatterPlot(TTree *tree){

        TCanvas *c3 = new TCanvas("Scatter Plot", "Scatter Plot");

	int nEntries	        =       static_cast<int>(tree->GetEntries());

        TH2I *scatterPlot = new TH2I("ScatterPlot", "eGammaHyppo x Ringer; T2Calo; Ringer; Log Scale", 2, -2, 2, 2, -2, 2);

        scatterPlot->SetOption("lego cg(1)");

	vector<int> *ringerDec	=	new vector<int>;

	vector<int> *t2CaDec	=	new vector<int>;

	tree->SetBranchStatus("RingerDec",	true);

	tree->SetBranchAddress("RingerDec",	&ringerDec);

	tree->SetBranchStatus("T2CaDec",	true);

	tree->SetBranchAddress("T2CaDec",	&t2CaDec);


	for(int i=0; i<nEntries;++i){
		tree->GetEntry(i);
		for(size_t j=0; j<ringerDec->size();++j){
                        //here I fill scatterPlot                       
                }
        }
       
        scatterPlot->Draw();

        return 0;
}

3-drawCutCounter

Efic::CODE T2CaloEfic::drawCutCounter(){

	TH1I *hCuts = new TH1I("CutCounter", "L2IDCalo Hypo Passed Cuts; Cut", 12, -1.5, 10.);

        TCanvas *c1 = new TCanvas("T2Calo Output", "T2Calo Output");

	vector<int> *readOutPut	=	new vector<int>;

	int nEntries	        =       static_cast<int>(eficFillingTree->GetEntries());

	eficFillingTree->SetBranchStatus("T2CaOut",	true);

	eficFillingTree->SetBranchAddress("T2CaOut",	&readOutPut);


	for(int i=0; i<nEntries;++i){
		eficFillingTree->GetEntry(i);
		for(size_t j=0; j<readOutPut->size();++j){
                               //here I fill the hCuts
			}
		}
	}

	hCuts->Draw();

        delete readOutPut;

	return Efic::OK;

}

Here are the problems if I change the order:
1-[code]
scatterPlot(generateData);

    myNeural->drawNetAns();

myT2Calo->drawCutCounter();

[/code]

Problem:
It generates scatter plot well;
myNeural->drawNetAns() is drawn with error: all inputs are read as zero(in fact the values are from the order of 10^-47) while they are nonzero values;
myT2Calo->drawCutCounter() is generated correctly.

2-[code]
scatterPlot(generateData);

myT2Calo->drawCutCounter();

    myNeural->drawNetAns();

[/code]

Same as 1.

3-[code]

myT2Calo->drawCutCounter();

    scatterPlot(generateData);

    myNeural->drawNetAns();

[/code]

It doesnt generates scatter plot:
Error in THistPainter::TableInit: log scale is requested but maximum is less or equal 0 (0.000000)
myNeural->drawNetAns() is drawn with error: all inputs are read as zero(in fact the values are from the order of 10^-47) while the are nonzero values;
myT2Calo->drawCutCounter() is generated correctly.

4-[code]
myT2Calo->drawCutCounter();

    myNeural->drawNetAns();

    scatterPlot(generateData);

[/code]
same as 3;

5-[code]
myNeural->drawNetAns();

myT2Calo->drawCutCounter();

    scatterPlot(generateData);

[/code]

Both drawNetAns and drawCutCounter are drawn correctly, but scatterPlot gives the error:
Error in THistPainter::TableInit: log scale is requested but maximum is less or equal 0 (0.000000)

I tried many things to fix this problem, but none worked. I dont know if there is a problem reading the same TTree several times or I am doing something wrong on my code. Note that I am using always the same pointer generateData, and altering him everytime I read the trees.

Thank you.

Hi,

One of the missing calls in your code are calls like:

tree->ResetBranchAddresses();this should be done at the end of every function where there is calls like:tree->SetBranchAddress(name,&pointer);where pointer is a local variable.

Cheers,
Philippe.