ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/FGolf/Tools/getMyHistosNames.cc
Revision: 1.1
Committed: Tue Mar 20 19:08:50 2012 UTC (13 years, 1 month ago) by fgolf
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Error occurred while calculating annotation data.
Log Message:
replace .C file with .cc

File Contents

# Content
1 #include "TList.h"
2 #include "TObjArray.h"
3 #include "TH1.h"
4 #include "TH2.h"
5 #include "TROOT.h"
6 #include "TClass.h"
7 #include "TObjString.h"
8 #include <iostream>
9
10 #include "getMyHistosNames.h"
11 //--------------------------------------------------------
12 // Our histogram are named XX_YY_ZZ
13 // where XX=tt, WW, WZ, etc
14 // YY refers to what is actually plotted
15 // ZZ=em, ee, mm, all
16 //
17 // It is useful to get a list of all the YY's
18 //
19 // We can get this list by looking at all the existing hostograms.
20 //
21 // This list is returned here as TObjArray*
22 //
23 // The passed prefix should be, eg, "tt" and the passed postfix
24 // should be, eg, "ee", so that the list is built only
25 // from the "tt_YY_ee" histograms
26 //
27 // Claudio 4 Sep 2007
28 //
29 // Added feature to skip 2D histograms
30 //--------------------------------------------------------
31
32 TObjArray* getMyHistosNames (const char* prefix, const char* postfix, bool keep2D)
33 {
34 TObjArray* array = new TObjArray();
35 bool skip2D = !keep2D;
36
37 // Get a list of object and their iterator
38 TList* list = gDirectory->GetList() ;
39 TIterator* iter = list->MakeIterator();
40
41 // Loop over objects
42 TObject* obj;
43 while ((obj = iter->Next()))
44 {
45 // Only look at objects beginning with 'prefix' and ending with 'postfix'
46 TString name = obj->GetName();
47 if (name.BeginsWith(prefix) && name.EndsWith(postfix))
48 {
49 if (skip2D && obj->IsA()->InheritsFrom(TH2::Class()))
50 continue;
51
52 // Only look at objects that inherit from TH1 or TH2
53 if (obj->IsA()->InheritsFrom(TH1::Class()) || obj->IsA()->InheritsFrom(TH2::Class()))
54 {
55 // Find the central key, ie, the YY
56 TObjArray* t = name.Tokenize("_");
57 TString z = TString(t->At(1)->GetName());
58 if (t->GetEntries() == 4)
59 z = TString(Form("%s_%s", t->At(1)->GetName(), t->At(2)->GetName()));
60
61 // add to the output array
62 TObjString* zobj = new TObjString(z);
63 array->Add(zobj);
64 }
65 }
66 }
67
68 return array;
69 }