Facing difficulty to copy an array of variable to a TTree

Dear all,
I have saved some array of variables in a TTree. Now I am trying to copy these variables in another TTree after applying some selection cuts. But I am getting very strange result. Can anybody tell me how to fix this problem? Thanks in advance.

My small piece of code snippet is given below:

TChain *chain = new TChain(“h1”);
chain->Add(“Jpsi_001.root”);

TTree dataTree = (TChain)chain;

TFile *target = new TFile(“Jpsi_Inc.root”,“RECREATE” );
TTree *tree = new TTree(“h1”,“Reduced SPD ntuple”,6400);

Int_t indexmc;
Int_t trkidx[100]; //[indexmc]
Int_t pdgid[100]; //[indexmc]
Int_t motheridx[100]; //[indexmc]

dataTree->SetBranchAddress(“indexmc”, &indexmc);
dataTree->SetBranchAddress(“trkidx”, &trkidx);
dataTree->SetBranchAddress(“pdgid”, &pdgid);
dataTree->SetBranchAddress(“motheridx”, &motheridx);

tree->Branch(“indexmc”, &indexmc, “indexmc/I”);
tree->Branch(“trkidx”, trkidx, “trkidx[100]/I”);
tree->Branch(“pdgid”, pdgid, “pdgid[100]/I”);
tree->Branch(“motheridx”, motheridx, “motheridx[100]/I”);

for (Long64_t ievt=0; ievtGetEntries();ievt++) {
dataTree->GetEntry(ievt);
tree->Fill();
}

Dear all,
The problem has been fixed after making following changes in the code snippet:

dataTree->SetBranchAddress(“indexmc”, &indexmc);
dataTree->SetBranchAddress(“trkidx”, trkidx);
dataTree->SetBranchAddress(“pdgid”, pdgid);
dataTree->SetBranchAddress(“motheridx”, motheridx);

tree->Branch("indexmc",               &indexmc,        "indexmc/I");
tree->Branch("trkidx",                trkidx,         "trkidx[indexmc]/I");
tree->Branch("pdgid",                 pdgid,         "pdgid[indexmc]/I");
tree->Branch("motheridx",             motheridx   ,  "motheridx[indexmc]/I");

with regards,
V. Prasad