V0.02 The ROOT Collection Classes
V Collection Classes Group of related objects TObjects or descendants from TObject Abstract base class TCollection
V Collection Classes (cont.) Ordered Collections (Sequences) Sorted Collections Unordered Collections
V TClonesArray Array of Identical Objects. Memory for the Objects stored is allocated only once. Use TClonesArray to store heterogeneous object arrays in a TTree.
V Iterators Declare an iterator for a collection “()”operator
V Collection Example Scenario: use a collection of nine histograms and draw them on nine sub pads on a canvas myTree.DrawHistograms();
V Collection Example (cont.) 1. Download needed files. 2. Decide what type of collection we need. 3. Add the collection to the class
V Collection Example (cont.) 4. Change the Loop() to fill the histograms 5. Fill the Array 6. Declare the method to draw the histograms: voidDrawHistograms(void);
V Collection Example (cont.) 7. Implement DrawHistograms(). Create a canvas and divide it into 9 sub-pads. 8. Use the iterator to draw each histogram in a sub-pad.
V Collection Example (cont.) 9. Load and run
V Collection Example:TMap Scenario: Add a method that takes up to nine names of histograms as parameters and draws them in order. myTree.DrawHistograms ("Px", "Py", "Xfirst", "Xlast")
V Collection Example:TMap (cont.) 1. Decide what type of collection we need. 2. Add the collection to the class
V Collection Example:TMap (cont.) 3. Build the map from the array. fHistoMap.Add( new TObjString( theHisto->GetName()),theHisto);
V Collection Example:TMap (cont.) 4. Declare the method to draw the histograms: voidDrawHistograms(char * name1, char * name2 = 0...); 5. Create a TObjArray of names.
V Collection Example:TMap (cont.) 6. Find the histograms in the Map and draw them.
V Collection Example:TMap (cont.) 7. Load and run
V Exercise 4 Add a method to the ABC class with the following signature: void MakeHistos(char * n1, char * n2, char * n3, char * n4) MakeHistos will: –draw the histograms specified in the list of names –save the histograms to a file called ABC_histos.root