ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/FGolf/ss/Tools/getMyHistosNames.C
Revision: 1.2
Committed: Fri Sep 3 22:57:21 2010 UTC (14 years, 8 months ago) by fgolf
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
State: FILE REMOVED
Error occurred while calculating annotation data.
Log Message:
remove this directory as these tools are now in a general Tools directory

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