Dear ROOTers: Recently, I have downloaded version 2.24/04 of ROOT, this really excellent framework, to my PowerBook G3/Wallstreet running LinuxPPC. Everything did work immediately. Since I am new to ROOT I am trying some code and have already some questions: 1, I have stored an ascii-table (5 columns: num, idx, x, y, z) in one TBranch of a TTree. Now I would like to extract "x:y:z" for each idx. First I tried it interactively: root [0] .x TestTree.C root [3] idTree->Draw(">>myList","idx==2") root [4] idTree->SetEventList(myList) root [8] a=idTree->GetV1() (Float_t*)0x30027010 root [12] for(int i=0;i<40;i++) cout<<a[i]<<"," root [13] cout<<endl In this way I can extract "x,y,z" using GetV1(), GetV2(), GetV3(). However, when I used TTree->MakeCode("Code4idTree.cc"), and use printf() in the loop of the automatically generated code, I get strange values instead of my table. Can someone help me and tell me what I did wrong? Below I enclose the files: a, TestTree.C: this file stores the data in the tree b, Code4idTree.cc: the automatically generated file with modified loop only c, Code4idTree1.cc: the automatically generated but modified file 2, I have a second ascii-table (4 columns: x, y, data1, data2), which I have currently stored in a Ttuple as: data1[x][y] and data2[x][y] I would like to extract data1, data2 from this table for each idx of the first table. What is the best way to do this? Should I store data1, data2 differently? Thank you very much in advance for your help Christian (Christian Stratowa, Vienna, Austria) APPENDICES a, TestTree.C: this file stores the data in the tree { // example of macro to read data from ascii file mytest.txt // and create a root file with a tree. gROOT->Reset(); #include <iostream.h> ifstream in; in.open("mytest.txt", ios::in); Int_t num, idx, x, y, z; typedef struct { Int_t idx, x, y, z; } INDEX; // static INDEX id; INDEX id; TFile *f = new TFile("TestTree.root","RECREATE"); TTree *idTree = new TTree("idTree","data from file mytest.txt"); TBranch *idBranch = idTree->Branch("idBranch",&id,"idx/I:x:y:z"); // read header line Int_t nlines = 0; if(nlines == 0) { char header[81]; in.getline(header,80); nlines++; } while (1) { in >> num >> idx >> x >> y >> z; if (!in.good()) break; id.idx = idx; id.x = x; id.y = y; id.z = z; if (nlines < 5) printf("idx=%8i,z=%8i,x=%8i,y=%8i\n",idx,z,x,y); idTree->Fill(); nlines++; } printf(" found %d lines\n",nlines); in.close(); f->Write(); } b, Code4idTree.cc: the automatically generated file with modified loop only { ////////////////////////////////////////////////////////// // This file has been automatically generated // (Sun Jun 4 17:23:33 2000 by ROOT version2.24/04) // from TTree idTree/data from file mytest.txt // found on file: TestTree.root ////////////////////////////////////////////////////////// //Reset ROOT and connect tree file // gROOT->Reset(); TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject("TestTree.root"); if (!f) { f = new TFile("TestTree.root"); } TTree *idTree = (TTree*)gDirectory->Get("idTree"); //Declaration of leaves types Int_t idBranch_idx; Int_t idBranch_x; Int_t idBranch_y; Int_t idBranch_z; //Set branch addresses idTree->SetBranchAddress("idBranch",&idBranch_idx); idTree->SetBranchAddress("idBranch",&idBranch_x); idTree->SetBranchAddress("idBranch",&idBranch_y); idTree->SetBranchAddress("idBranch",&idBranch_z); // This is the loop skeleton // To read only selected branches, Insert statements like: // idTree->SetBranchStatus("*",0); // disable all branches // TTreePlayer->SetBranchStatus("branchname",1); // activate branchname Int_t nentries = idTree->GetEntries(); Int_t nbytes = 0; for (Int_t i=0; i<nentries;i++) { nbytes += idTree->GetEntry(i); if(i<100) { printf("idx,x,y,z= %8i,%8i,%8i,%8i\n",idBranch_idx,idBranch_x,idBranch_y,idBranch_z); // printf("idx,x,y,z= \n"); } } printf("nentries= %8i, nbytes= %8i \n",nentries,nbytes); } c, Code4idTree1.cc: the automatically generated but modified file { ////////////////////////////////////////////////////////// // This file has been automatically generated // (Sun Jun 4 17:23:33 2000 by ROOT version2.24/04) // from TTree idTree/data from file mytest.txt // found on file: TestTree.root ////////////////////////////////////////////////////////// //Reset ROOT and connect tree file // gROOT->Reset(); TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject("TestTree.root"); if (!f) { f = new TFile("TestTree.root"); } TTree *idTree = (TTree*)gDirectory->Get("idTree"); // TBranch *idBranch = idTree->GetBranch("idBranch"); //Declaration of leaves types typedef struct { Int_t idx, x, y, z; } INDEX; INDEX id; //Set branch addresses idTree->SetBranchAddress("idBranch",&id.idx); idTree->SetBranchAddress("idBranch",&id.x); idTree->SetBranchAddress("idBranch",&id.y); idTree->SetBranchAddress("idBranch",&id.z); // This is the loop skeleton // To read only selected branches, Insert statements like: // idTree->SetBranchStatus("*",0); // disable all branches // TTreePlayer->SetBranchStatus("branchname",1); // activate branchname Int_t nentries = idTree->GetEntries(); Int_t nbytes = 0; for (Int_t i=0; i<nentries;i++) { nbytes += idTree->GetEntry(i); // nbytes += idBranch->GetEntry(i); if(i<100) { printf("idx,x,y,z= %8i,%8i,%8i,%8i\n",id.idx,id.x,id.y,id.z); } } printf("nentries= %8i, nbytes= %8i \n",nentries,nbytes); }
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:27 MET