GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PadManager.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2004-2006 by Olivier Stezowski & Christian Finck *
3  * stezow(AT)ipnl.in2p3.fr, cfinck(AT)ires.in2p3.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
24 #ifndef Gw_PadManager
25 #include "PadManager.h"
26 #endif
27 
28 #ifndef ROOT_TF1
29 #include "TF1.h"
30 #endif
31 #ifndef ROOT_TPolyLine
32 #include "TPolyLine.h"
33 #endif
34 #ifndef ROOT_TList
35 #include "TList.h"
36 #endif
37 #ifndef ROOT_TCanvas
38 #include "TCanvas.h"
39 #endif
40 #ifndef ROOT_TPolyLine
41 #include "TPolyLine.h"
42 #endif
43 
44 #include "TGraph.h"
45 
46 using namespace Gw;
47 
48 //
50 
52 
53 //__________________________________________________________
55  fLog("PadManager")
56 {
57 
58 }
59 
60 //__________________________________________________________
62 {
63 
64 }
65 
66 //__________________________________________________________
67 TH1* PadManager::GetHisto(TVirtualPad *pad, Option_t * /*opt*/ )
68 {
69  // histograms to be returned
70  TH1* h = 0x0;
71 
72  // to get the pad on which the creator is added
73  TVirtualPad *locpad = 0x0;
74  if ( pad == 0x0 )
75  if ( TVirtualPad::Pad() == 0x0 )
76  return h;
77  else
78  locpad = TVirtualPad::Pad();
79  else
80  locpad = pad;
81 
82  TObject* obj = 0x0;
83  TIter next(locpad->GetListOfPrimitives());
84  while ( (obj = next()) ) { // iterator skips empty slots
85  if ( obj->InheritsFrom("TH1") ) {
86  h = dynamic_cast<TH1*> ( obj );
87  break;
88  }
89  }
90 
91  if(h == 0x0)
92  {
93  TGraph *g = GetGraph(pad);
94  if(g != 0x0) h = g->GetHistogram();
95  }
96 
97  return h;
98 }
99 
100 //__________________________________________________________
101 TGraph* PadManager::GetGraph(TVirtualPad *pad, Option_t * /*opt*/ )
102 {
103  // histograms to be returned
104  TGraph* h = 0x0;
105 
106  // to get the pad on which the creator is added
107  TVirtualPad *locpad = 0x0;
108  if ( pad == 0x0 )
109  if ( TVirtualPad::Pad() == 0x0 )
110  return h;
111  else
112  locpad = TVirtualPad::Pad();
113  else
114  locpad = pad;
115 
116  TObject* obj = 0x0;
117  TIter next(locpad->GetListOfPrimitives());
118  while ( (obj = next()) ) { // iterator skips empty slots
119  if ( obj->InheritsFrom("TGraph") ) {
120  h = dynamic_cast<TGraph*> ( obj );
121  break;
122  }
123  }
124 
125  return h;
126 }
127 
128 TPolyLine *PadManager::ShowDiff(const TH1 *h, const TF1 *f, Double_t xmin, Double_t xmax)
129 {
130  TPolyLine *result = new TPolyLine();
131 
132  //
133  Double_t altitude = 0.9*h->GetMaximum();
134 
135  for (Int_t i = h->GetXaxis()->FindFixBin(xmin); i < h->GetXaxis()->FindFixBin(xmax); i++) {
136  //
137  Double_t yy, xx, yytmp;
138  //
139  xx = h->GetBinLowEdge(i);
140  yy = h->GetBinContent(i) - f->Eval(h->GetBinLowEdge(i)) ;
141  yytmp = h->GetBinContent(i) - f->Eval(h->GetBinCenter(i));
142  if ( TMath::Abs( yytmp ) < TMath::Abs( yy ) ) {
143  xx = h->GetBinCenter(i);
144  yy = yytmp;
145  }
146  yytmp = h->GetBinContent(i) - f->Eval(h->GetBinLowEdge(i)+h->GetBinWidth(i));
147  if ( TMath::Abs( yytmp ) < TMath::Abs( yy ) ){
148  xx = h->GetBinLowEdge(i)+h->GetBinWidth(i);
149  yy = yytmp;
150  }
151  //
152  yytmp = altitude + yy;
153  result->SetNextPoint(xx,yytmp);
154  }
155  if ( TVirtualPad::Pad() )
156  result->Draw();
157 
158  return result;
159 }
160 
161 
162 
163 
header file for PadManager.cpp
static TPolyLine * ShowDiff(const TH1 *h, const TF1 *f, Double_t xmin, Double_t xmax)
show a polyline calculated as the difference between an histogram and a function (used for instance f...
Definition: PadManager.cpp:128
ClassImp(PadManager) PadManager
Definition: PadManager.cpp:51
static EActionMode gActionMode
Global to be applied on Canvas that are not Gw::Canvas or dont't have an individual mode...
Definition: PadManager.h:59
virtual ~PadManager()
Definition: PadManager.cpp:61
static TH1 * GetHisto(TVirtualPad *pad=0x0, Option_t *op="")
look for an histogram into the pad
Definition: PadManager.cpp:67
static TGraph * GetGraph(TVirtualPad *pad=0x0, Option_t *op="")
Definition: PadManager.cpp:101