Robert Casties wrote: > > A beginners question: How do I store and process arrays(16x16 Bytes)as > event-data? > > I would like to store one array per event in an NTuple or such.I want to > do some manipulation on the data as computing means, subtracting pedestals > and eliminating bad events. Afterwards I need to do some histograms and > statistics. > > Can I use the NTuple-class for my purpose? I have seen that it is possible > to allocate arbitrary variables and store the data via pointer. But how do > I get the data back out? Or do I have to write my own TTree subclass and > which methods does it have to have? > Root version 0.9 supports variable length arrays (for example the ones converted from hbook column-wise ntuples), but (yes), it does not support fixed one or more dimension arrays! However, you can still do the following as illustrated by a small macro generating a Tree file and a second macro reading this file and doing one histogram. The Producer macro ================== { gROOT->Reset(); Int_t i,j,event; Float_t adc[16][16]; TFile *file = new TFile("adc.root","RECREATE"); TTree *tree = new TTree("tree","Testing root trees"); tree->Branch("adc",adc,"adc[nadc]/F"); for (event=0;event<100;event++) { for (j=0;j<16;j++) { for (i=0;i<16;i++) { adc[i][j] = 100*i +j; } } tree->Fill(); } tree->Print(); tree->Write(); file->Close(); } The read macro ============== { ////////////////////////////////////////////////////////// // This file has been automatically generated // (Thu Feb 27 08:36:42 1997 by ROOT version 1.00/00) // from TTree tree/Testing root trees // found on file: adc.root ////////////////////////////////////////////////////////// //Reset ROOT and connect tree file gROOT->Reset(); TFile *f = new TFile("adc.root"); //Declaration of leaves types Float_t adc[256]; //Get a pointer to individual leaves and set their addresses TObjArray *leaves = tree->GetListOfLeaves(); TLeaf *l_adc = (TLeaf*)leaves->At(0); l_adc->SetAddress(&adc[0]); //This is the loop skeleton //To read only selected branches, Insert a statement like: // afname->GetBranch()->GetEvent(i); instead of tree->GetEvent(i); TH1F *hadc = new TH1F("hadc","ADC distribution",100,0,1600); Int_t nentries = tree->GetEntries(); for (Int_t i=0; i<nentries;i++) { tree->GetEvent(i); hadc->Fill(adc[64]); } hadc->Draw(); } The skeleton of the "read macro" can be generated automatically in version 0.9: see http://root.cern.ch/root/html/examples/MakeCode.C.html in version 1.0, TTree::MakeCode replaces this macro. Version 1.0 supports fix arrays in TTree::Draw Rene Brun
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:26:18 MET