Hi Michelle,
> that means that I get alpha > 0.15 but I get all the entries for the other variables.
I am not sure what you mean
> for(Long64_t i = 0; i < tree->GetEntries(); ++i)
> {
> tree->GetEntry(i);
> for(int sh = 0; sh < nshower; ++sh) {
> ...
> if (alpha[sh] > 0.15) newtree->Fill();
> }
> }
Here you are filling the TTree way too many times. Each entry in the TTree will be written in the newtree as many time as there is shower matching criteria. (I.e. if they all match you newtree with have newtree->GetEntries() === nshowers * tree->GetEntries()).
Short of carefully copying the data into new arrays you can not copy 'just' a subset of the array within an entry.
A 'correct' version of your code would be:
for(Long64_t i = 0; i < tree->GetEntries(); ++i) {
tree->GetEntry(i); bool match = false; for(int sh = 0; sh < nshower; ++sh) { tgalpha[sh] = (1*55251.1*(pow(30.0,2)/2)*0.000001)/(shower->Energy); alphar[sh] = atan(tgalpha[sh]); alpha[sh] = (alphar[sh] * 180)/3.1415927; if (alpha[sh] > 0.15) match = true; } if (match) { newtree->Fill(); }
However, this might not be what you wanted. What this does, is copying all the data for the entries where at least one show as alpha greater than 0.15.
In order to shrink the array of shower (i.e. keep only the shower where alpha is more than 0.15), you would need to do something like:
Int_t new_nshower = 0;
float new_alpha[max_nshower];
etc ....
newtree->SetBranchAddress("nshower",&new_nshower);
newtree->SetBranchAddress("alpha",&new_alpha);
etc ..
for(Long64_t i = 0; i < tree->GetEntries(); ++i)
{
tree->GetEntry(i); bool match = false; for(int sh = 0; sh < nshower; ++sh) { tgalpha[sh] = (1*55251.1*(pow(30.0,2)/2)*0.000001)/(shower->Energy); alphar[sh] = atan(tgalpha[sh]); alpha[sh] = (alphar[sh] * 180)/3.1415927; if (alpha[sh] > 0.15) { new_alpha[new_nshower] = alpha[sh] new_tgalpha[new_nshower] = rgalpah[sh]; ++new_nshower; } } if (match) { newtree->Fill(); }
(this code is actually _only_ for demonstration purpose, I do not know where your old tree contains alpha values or not etc... The point is that you need at least to set a new value for the number of shower element.
Cheers,
Philippe.
Received on Tue Jun 07 2011 - 18:42:20 CEST
This archive was generated by hypermail 2.2.0 : Thu Jun 09 2011 - 11:50:02 CEST