Your code was mangled by the forum’s HTML processor. Please disable HTML in your post containing code.
The short answer to your questing seems to be: yes
However, you did not specify (or I did not understood for sure) your intent and hence I don’t know whether this would do what you expect.
Thank you Philippe.
I have modified a little bit the piece of code:
Float_t E[4];
TTree *ntuple = new TTree(“ntuple”,“nutple”);
ntuple->Branch(“E”,&(E[0]),“E[4]/F”);
for (Int_t j=0; j <= 3; j++)
{
PChain[j]->SetBranchAddress(“x”, &(E[j]));
for (Int_t i=0; i<PChain[j]->GetEntries(); i++)
{
PChain[j]->GetEntry(i);
ntuple->Fill();
}
}
Are you ok with this ?
if yes I have two problems.
The first one appear when I try to draw the last array:
ntuple->Draw(“E[3]”)
give something wrong.
It is strange cause the results are good for E[0],E[1] and E[2].
The second problem appear when I quit ROOT
root [2] .q
[quote]Are you ok with this ?[/quote]Not this is wrong.
When you do ntuple->Fill()it create a whole new entry with the current value of all variables. So in your case (assuming I read correctly and assuming your initialize E to 0). The contain for your ntuple whole
entry E[0] E[1] E[2] E[3]
0 x_0_0 0 0 0
....
n x_0_n 0 0 0
n+1 x_0_n x_1_0 0 0
n+2 x_0_n x_1_1 0 0
...
2*n x_0_n x_1_n 0 0
...
where x_j_i is the content of x for the entry i of your pChain[j]
[quote]The second problem appear when I quit ROOT[/quote]It must be related to code you have not shown.
thanks a lot for your explanations.
Something that I don’t understand is
for (Int_t j=0; j <= 3; j++)
{
PChain[j]->SetBranchAddress(“x”, &(E[j]));
}
for (Int_t i=0; i<PChain[j]->GetEntries(); i++)
…
Correct me if I am wrong but PChain[j]->GetEntries() outside of the j loop have no meaning …
Below you will find my bad code …
(thank you for your patience )
[quote]Correct me if I am wrong but PChain[j]->GetEntries() outside of the j loop have no meaning … [/quote]Yes. That’s why in the code I sent you there j loop is there twice. Once to setup the addresses. Once to call all the GetEntry within the entry loop.
[quote]
Below you will find my bad code … [/quote]Still nothing obvious leading to crash … the only way to help further (about the crash) would be for you to sent a complete running example.
In my case the values PChain[j]->GetEntries() is different for all j.
So the trick I found is :
Int_t max=0;
for (Int_t j=jstar; j <= jend ; j++)
{
…
max=TMath::Max(max,(Int_t)PChain[j]->GetEntries());
}
for (Int_t i=0; i<max; i++){
for (Int_t j=jstar; j <= jend; j++) PChain[j]->GetEntry(i);
ntuple2->Fill();
}
And it work
The only think is that the mean and the rms value change a little bit.
Thank you
cheers
olivier
Yes you can. Yes it makes sense. And Yes you could make the drawing call you wrote.
Now, instead of TNtuple, you should use TTree directly.Float_t E[4];
TTree *ntuple = new TTree("ntuple","nutple");
ntuple->Branch("E",&(E[0]),"E[4]/F");
for (Int_t j=0; j <3>SetBranchAddress("x", &(E[j]));
}
for (Int_t i=0; i<PChain>GetEntries(); i++)
{
for (Int_t j=0; j <3>GetEntry(i);
}
ntuple->Fill();
}
[/quote]
I run the programm ,but it is wrong in
PChain[j]->SetBranchAddress(“x”, &(E[j]));
please upload you complete programm,OK?
you use which root?