test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
Tutils Class Reference

#include <utils.h>

Public Member Functions

void drawGFit (TH1 *h1, float nsigmas, float min, float max)
 
void drawGFit (TH1 *h1, float min, float max)
 
void drawGFit (TH1 *h1, float min, float max, float minfit, float maxfit)
 
void plotAndProfileX (TH2 *h2, float min, float max, bool profile=false)
 
void setStyle (TH1 *histo)
 
void setStyle (TH2 *histo)
 

Private Member Functions

TStyle * getStyle (const TString &name)
 

Private Attributes

TStyle * mystyle
 

Detailed Description

Definition at line 9 of file utils.h.

Member Function Documentation

void Tutils::drawGFit ( TH1 *  h1,
float  nsigmas,
float  min,
float  max 
)
void Tutils::drawGFit ( TH1 *  h1,
float  min,
float  max 
)
void Tutils::drawGFit ( TH1 *  h1,
float  min,
float  max,
float  minfit,
float  maxfit 
)

Definition at line 5 of file utils.cc.

References diffTwoXMLs::g1, i, and setStyle().

5  {
6  setStyle(h1);
7  static int i = 0;
8  i++;
9  //h1->SetGrid(1,1);
10  //h1->SetGridColor(15);
11  h1->GetXaxis()->SetRangeUser(min,max);
12  TString fitName = "g";
13  fitName += i;
14  TF1* g1 = new TF1(fitName.Data(),"gaus",minfit,maxfit);
15  g1->SetLineColor(2);
16  g1->SetLineWidth(2);
17  h1->Fit(g1,"RQ");
18  h1->Draw();
19 // TPaveStats *st = (TPaveStats*)h1->GetListOfFunctions()->FindObject("stats");
20 // st->SetX2NDC(0.905);
21 // st->SetY2NDC(0.905);
22 }
int i
Definition: DBlmapReader.cc:9
void setStyle(TH1 *histo)
Definition: utils.cc:23
T min(T a, T b)
Definition: MathUtil.h:58
TStyle * Tutils::getStyle ( const TString &  name)
private

Definition at line 49 of file utils.cc.

Referenced by setStyle().

50 {
51  TStyle *theStyle;
52  if ( name == "mstyle" ) {
53  theStyle = new TStyle("mstyle", "mstyle");
54  // theStyle->SetOptStat(0);
55  theStyle->SetPadBorderMode(0);
56  theStyle->SetCanvasBorderMode(0);
57  theStyle->SetPadColor(0);
58  theStyle->SetCanvasColor(0);
59  theStyle->SetMarkerStyle(8);
60  theStyle->SetMarkerSize(0.7);
61  theStyle->SetStatH(0.3);
62  theStyle->SetStatW(0.15);
63  // theStyle->SetTextFont(132);
64  // theStyle->SetTitleFont(132);
65  theStyle->SetTitleBorderSize(1);
66  theStyle->SetPalette(1);
67 
68  } else if( name == "tdr" ) {
69  theStyle = new TStyle("tdrStyle","Style for P-TDR");
70 
71  // For the canvas:
72  theStyle->SetCanvasBorderMode(0);
73  theStyle->SetCanvasColor(kWhite);
74  theStyle->SetCanvasDefH(600); //Height of canvas
75  theStyle->SetCanvasDefW(600); //Width of canvas
76  theStyle->SetCanvasDefX(0); //POsition on screen
77  theStyle->SetCanvasDefY(0);
78 
79  // For the Pad:
80  theStyle->SetPadBorderMode(0);
81  // theStyle->SetPadBorderSize(Width_t size = 1);
82  theStyle->SetPadColor(kWhite);
83  theStyle->SetPadGridX(true);
84  theStyle->SetPadGridY(true);
85  theStyle->SetGridColor(0);
86  theStyle->SetGridStyle(3);
87  theStyle->SetGridWidth(1);
88 
89  // For the frame:
90  theStyle->SetFrameBorderMode(0);
91  theStyle->SetFrameBorderSize(1);
92  theStyle->SetFrameFillColor(0);
93  theStyle->SetFrameFillStyle(0);
94  theStyle->SetFrameLineColor(1);
95  theStyle->SetFrameLineStyle(1);
96  theStyle->SetFrameLineWidth(1);
97 
98  // For the histo:
99  // theStyle->SetHistFillColor(1);
100  // theStyle->SetHistFillStyle(0);
101  theStyle->SetHistLineColor(1);
102  theStyle->SetHistLineStyle(0);
103  theStyle->SetHistLineWidth(1);
104  // theStyle->SetLegoInnerR(Float_t rad = 0.5);
105  // theStyle->SetNumberContours(Int_t number = 20);
106 
107  theStyle->SetEndErrorSize(2);
108 // theStyle->SetErrorMarker(20);
109  theStyle->SetErrorX(0.);
110 
111  theStyle->SetMarkerStyle(20);
112 
113  //For the fit/function:
114  theStyle->SetOptFit(1);
115  theStyle->SetFitFormat("5.4g");
116  theStyle->SetFuncColor(2);
117  theStyle->SetFuncStyle(1);
118  theStyle->SetFuncWidth(1);
119 
120  //For the date:
121  theStyle->SetOptDate(0);
122  // theStyle->SetDateX(Float_t x = 0.01);
123  // theStyle->SetDateY(Float_t y = 0.01);
124 
125  // For the statistics box:
126  theStyle->SetOptFile(0);
127 // theStyle->SetOptStat(0); // To display the mean and RMS: SetOptStat("mr");
128  theStyle->SetOptStat(10);
129  theStyle->SetStatColor(kWhite);
130  theStyle->SetStatFont(42);
131  theStyle->SetStatFontSize(0.07);
132  theStyle->SetStatTextColor(1);
133  theStyle->SetStatFormat("6.4g");
134  theStyle->SetStatBorderSize(1);
135  theStyle->SetStatH(0.3);
136  theStyle->SetStatW(0.2);
137  // theStyle->SetStatStyle(Style_t style = 1001);
138  // theStyle->SetStatX(Float_t x = 0);
139  // theStyle->SetStatY(Float_t y = 0);
140 
141  // Margins:
142  theStyle->SetPadTopMargin(0.05);
143  theStyle->SetPadBottomMargin(0.13);
144  theStyle->SetPadLeftMargin(0.16);
145  theStyle->SetPadRightMargin(0.02);
146 
147  // For the Global title:
148 
149  theStyle->SetOptTitle(0);
150  theStyle->SetTitleFont(42);
151  theStyle->SetTitleColor(1);
152  theStyle->SetTitleTextColor(1);
153  theStyle->SetTitleFillColor(10);
154  theStyle->SetTitleFontSize(0.05);
155  // theStyle->SetTitleH(0); // Set the height of the title box
156  // theStyle->SetTitleW(0); // Set the width of the title box
157  // theStyle->SetTitleX(0); // Set the position of the title box
158  // theStyle->SetTitleY(0.985); // Set the position of the title box
159  // theStyle->SetTitleStyle(Style_t style = 1001);
160  // theStyle->SetTitleBorderSize(2);
161 
162  // For the axis titles:
163 
164  theStyle->SetTitleColor(1, "XYZ");
165  theStyle->SetTitleFont(42, "XYZ");
166  theStyle->SetTitleSize(0.06, "XYZ");
167  // theStyle->SetTitleXSize(Float_t size = 0.02); // Another way to set the size?
168  // theStyle->SetTitleYSize(Float_t size = 0.02);
169  theStyle->SetTitleXOffset(0.9);
170  theStyle->SetTitleYOffset(1.25);
171  // theStyle->SetTitleOffset(1.1, "Y"); // Another way to set the Offset
172 
173  // For the axis labels:
174 
175  theStyle->SetLabelColor(1, "XYZ");
176  theStyle->SetLabelFont(42, "XYZ");
177  theStyle->SetLabelOffset(0.007, "XYZ");
178  theStyle->SetLabelSize(0.045, "XYZ");
179 
180  // For the axis:
181 
182  theStyle->SetAxisColor(1, "XYZ");
183  theStyle->SetStripDecimals(kTRUE);
184  theStyle->SetTickLength(0.03, "XYZ");
185  theStyle->SetNdivisions(510, "XYZ");
186  theStyle->SetPadTickX(1); // To get tick marks on the opposite side of the frame
187  theStyle->SetPadTickY(1);
188 
189  // Change for log plots:
190  theStyle->SetOptLogx(0);
191  theStyle->SetOptLogy(0);
192  theStyle->SetOptLogz(0);
193 
194  // Postscript options:
195  theStyle->SetPaperSize(20.,20.);
196  // theStyle->SetLineScalePS(Float_t scale = 3);
197  // theStyle->SetLineStyleString(Int_t i, const char* text);
198  // theStyle->SetHeaderPS(const char* header);
199  // theStyle->SetTitlePS(const char* pstitle);
200 
201  // theStyle->SetBarOffset(Float_t baroff = 0.5);
202  // theStyle->SetBarWidth(Float_t barwidth = 0.5);
203  // theStyle->SetPaintTextFormat(const char* format = "g");
204  // theStyle->SetPalette(Int_t ncolors = 0, Int_t* colors = 0);
205  // theStyle->SetTimeOffset(Double_t toffset);
206  // theStyle->SetHistMinimumZero(kTRUE);
207 
208 
209  // style->SetOptFit(101);
210  // style->SetOptStat(1111111);
211 
212  } else {
213  // Avoid modifying the default style!
214  theStyle = gStyle;
215  }
216  return theStyle;
217 }
void Tutils::plotAndProfileX ( TH2 *  h2,
float  min,
float  max,
bool  profile = false 
)

Definition at line 219 of file utils.cc.

References setStyle().

219  {
220  setStyle(h2);
221  // gPad->SetGrid(1,1);
222  //gStyle->SetGridColor(15);
223  h2->GetYaxis()->SetRangeUser(min,max);
224  h2->Draw();
225  if (profile) {
226  TProfile* prof = h2->ProfileX();
227  prof->SetMarkerColor(2);
228  prof->SetLineColor(2);
229  prof->Draw("same");
230  }
231  //TLine * l = new TLine(h2->GetXaxis()->GetXmin(),0,h2->GetXaxis()->GetXmax(),0);
232  //l->SetLineColor(3);
233  //l->Draw();
234 }
void setStyle(TH1 *histo)
Definition: utils.cc:23
T min(T a, T b)
Definition: MathUtil.h:58
void Tutils::setStyle ( TH1 *  histo)

Definition at line 23 of file utils.cc.

References getStyle(), and mystyle.

Referenced by drawGFit(), and plotAndProfileX().

23  {
24  mystyle = getStyle("tdr");
25  histo->GetXaxis()->SetTitleFont(mystyle->GetTitleFont());
26  histo->GetXaxis()->SetTitleSize(mystyle->GetTitleFontSize());
27  histo->GetXaxis()->SetLabelFont(mystyle->GetLabelFont());
28  histo->GetXaxis()->SetLabelSize(mystyle->GetLabelSize());
29 
30  histo->GetYaxis()->SetTitleFont(mystyle->GetTitleFont());
31  histo->GetYaxis()->SetTitleSize(mystyle->GetTitleFontSize());
32  histo->GetYaxis()->SetLabelFont(mystyle->GetLabelFont());
33  histo->GetYaxis()->SetLabelSize(mystyle->GetLabelSize());
34 }
TStyle * mystyle
Definition: utils.h:19
TStyle * getStyle(const TString &name)
Definition: utils.cc:49
void Tutils::setStyle ( TH2 *  histo)

Definition at line 36 of file utils.cc.

References getStyle(), and mystyle.

36  {
37  mystyle = getStyle("tdr");
38  histo->GetXaxis()->SetTitleFont(mystyle->GetTitleFont());
39  histo->GetXaxis()->SetTitleSize(mystyle->GetTitleFontSize());
40  histo->GetXaxis()->SetLabelFont(mystyle->GetLabelFont());
41  histo->GetXaxis()->SetLabelSize(mystyle->GetLabelSize());
42 
43  histo->GetYaxis()->SetTitleFont(mystyle->GetTitleFont());
44  histo->GetYaxis()->SetTitleSize(mystyle->GetTitleFontSize());
45  histo->GetYaxis()->SetLabelFont(mystyle->GetLabelFont());
46  histo->GetYaxis()->SetLabelSize(mystyle->GetLabelSize());
47 }
TStyle * mystyle
Definition: utils.h:19
TStyle * getStyle(const TString &name)
Definition: utils.cc:49

Member Data Documentation

TStyle* Tutils::mystyle
private

Definition at line 19 of file utils.h.

Referenced by setStyle().