GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GwUtilities.C
Go to the documentation of this file.
1 
2 
3 #include "TROOT.h"
4 #include "TFolder.h"
5 #include "TRegexp.h"
6 #include "TVirtualPad.h"
7 #include "TH1.h"
8 
9 #include <iostream>
10 
11 
12 namespace {
13  const Int_t nb_color_whell = 20;
14  Color_t color_wheel[nb_color_whell] = {
15  kBlue+0, kMagenta+0, kRed+0, kGreen+0, kCyan+0,
16  kBlue+1, kMagenta+1, kRed+1, kGreen+1, kCyan+1,
17  kBlue+2, kMagenta+2, kRed+2, kGreen+2, kCyan+2,
18  kBlue+3, kMagenta+3, kRed+3, kGreen+3, kCyan+3
19  };
20 }
21 
22 //void AddSpectra(TFolder *top_folder, const Char_t *pattern, const Char_t *destination_folder = "//root/GwWatchers", TH1 *h = 0x0)
23 void AddSpectra(const Char_t *pattern, TH1 *&h, TFolder *top_folder = 0x0)
24 {
25  TObject *obj; TString tmp(pattern); TFolder *f;
26 
27  // pattern expression
28  Bool_t wildcard = false;
29  if ( tmp.Contains("*") )
30  wildcard = true;
31  TRegexp what(pattern,wildcard);
32  ;
33  if ( top_folder == 0x0 ) {
34  f = (TFolder *)gROOT->GetRootFolder()->FindObject("//root/GwWatchers");
35  }
36  else f = top_folder;
37 
38  // iteration over this folder
39  TIter next(f->GetListOfFolders());
40  while ( (obj=next()) ) {
41 
42  tmp = obj->GetName();
43 
44  if ( obj->InheritsFrom("TFolder") ) {
45  AddSpectra(pattern,h,(TFolder *)obj);
46  continue;
47  }
48  if ( tmp.Contains(what) && obj->InheritsFrom("TH1") ) {
49  if ( h == 0x0 ) {
50  std::cout << " clone " << f->GetName() << " " << tmp << std::endl ;
51  h = (TH1 *)obj->Clone(Form("SUM_%s",pattern));
52  h->SetTitle(Form("SUM of %s",h->GetTitle()));
53  h->SetDirectory(0);
54  h->Draw();
55  }
56  else {
57  h->Add((TH1 *)obj);
58  std::cout << " add " << tmp << std::endl ;
59  }
60  }
61  }
62 }
63 
64 void CompSpectra(const Char_t *pattern, TFolder *top_folder = 0x0)
65 {
66  TObject *obj; TString tmp(pattern); TFolder *f; TH1 *h; static Int_t color = 0;
67 
68  // pattern expression
69  Bool_t wildcard = false;
70  if ( tmp.Contains("*") )
71  wildcard = true;
72  TRegexp what(pattern,wildcard);
73 
74  if ( top_folder == 0x0 ) {
75  f = (TFolder *)gROOT->GetRootFolder()->FindObject("//root/GwWatchers");
76  color = 0;
77  }
78  else f = top_folder;
79 
80  // iteration over this folder
81  TIter next(f->GetListOfFolders());
82  while ( (obj=next()) ) {
83 
84  tmp = obj->GetName();
85 
86  if ( obj->InheritsFrom("TFolder") ) {
87  CompSpectra(pattern,(TFolder *)obj);
88  continue;
89  }
90  if ( tmp.Contains(what) && obj->InheritsFrom("TH1") ) {
91  h = (TH1 *)obj->Clone(Form("%s_%s",f->GetName(),obj->GetName()));
92  h->SetDirectory(0);
93  if ( color == 0 )
94  h->Draw("");
95  else
96  h->Draw("same");
97 
98  std::cout << " Show " << h->GetName() << std::endl ;
99  // change color
100  h->SetLineColor( color_wheel[color % nb_color_whell] ); color++;
101  }
102  }
103 }
104 
105 
void CompSpectra(const Char_t *pattern, TFolder *top_folder=0x0)
Definition: GwUtilities.C:64
void AddSpectra(const Char_t *pattern, TH1 *&h, TFolder *top_folder=0x0)
Definition: GwUtilities.C:23
ADF::LogMessage & endl(ADF::LogMessage &log)