# How change a Tree internal array?

I need to create a new Tree from of an old Tree, by modifying the number of entries of some internall arrays. To be more explicit, my Tree contains all kind of particles and I want to keep just the muons in my new Tree. I have seen suggestions of using copytree3.C , but it is not clear to me how to change the size or create a new internal array with selected entries and then save this to the new Tree. If I use Fill method as shown in copytree3.C example it will simply copy the old array into the new Tree. Does anyone has an example of how to implement this ?
Thanks,
Andre

You can reshuffle your array(s) keeping only the interesting elements and changing the array count or create a new array keeping the old pointer, eg
int N;
int *ptype; //[N]
double *px //[N]

# ``` for (int i=0;i<nentries;i++) { //loop on entries oldtree->GetEntry(i); int newN = 0; for (int j=0;j<N;j++) { //loop on particles if (somecondition) { ptype[newN] = ptype[j]; px[newN] = px[j]; newN++; } } N = newN; } ``` Method 2

[code]for (int i=0;i<nentries;i++) { //loop on entries
oldtree->GetEntry(i);
int *oldptype = ptype;
double *oldpx = px;
ptype = new int[N]; //protect case N=0 (or make 2 passes)
px = new double[N];

int newN = 0;
for (int j=0;j<N;j++) { //loop on particles
if (somecondition) {
ptype[newN] = oldptype[j];
px[newN] = oldpx[j];
newN++;
}
}
N = newN;
}
[/code]
Rene