ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/FGolf/Tools/getMyHistosNames.C
Revision: 1.2
Committed: Fri Sep 3 23:16:17 2010 UTC (14 years, 8 months ago) by fgolf
Content type: text/plain
Branch: MAIN
Changes since 1.1: +4 -0 lines
Log Message:
changes from Puneeth

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     TObjArray* getMyHistosNames( const char* prefix, const char* postfix, bool keep2D) {
36    
37    
38     TObjArray* array = new TObjArray();
39     bool skip2D = !keep2D;
40    
41     // Get a list of object and their iterator
42     TList* list = gDirectory->GetList() ;
43     TIterator* iter = list->MakeIterator();
44    
45     // Loop over objects
46     TObject* obj;
47     while((obj=iter->Next())) {
48    
49     // Only look at objects beginning with 'prefix' and ending with 'postfix'
50     TString name = obj->GetName();
51     if (name.BeginsWith(prefix) && name.EndsWith(postfix)) {
52    
53     if (skip2D && obj->IsA()->InheritsFrom(TH2::Class())) continue;
54    
55     // Only look at objects that inherit from TH1 or TH2
56     if (obj->IsA()->InheritsFrom(TH1::Class()) ||
57     obj->IsA()->InheritsFrom(TH2::Class())) {
58    
59     // Find the central key, ie, the YY
60     TObjArray* t = name.Tokenize("_");
61     TString z = TString(t->At(1)->GetName());
62     if (t->GetEntries() == 4){
63     z = TString(Form("%s_%s",t->At(1)->GetName(),t->At(2)->GetName()));
64     }
65     // cout << t->At(1)->GetName() << endl;
66    
67     // add to the output array
68     TObjString* zobj = new TObjString(z);
69     array->Add(zobj);
70    
71     }
72     }
73     }
74    
75     return array;
76     }
77    
78 fgolf 1.2 #endif