ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/FGolf/Tools/getMyHistosNames.C
Revision: 1.4
Committed: Tue Mar 20 19:08:14 2012 UTC (13 years, 1 month ago) by fgolf
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +0 -0 lines
State: FILE REMOVED
Log Message:
replace .C file with .cc

File Contents

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