ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPlots/Style/src/HistStyles.cc
Revision: 1.2
Committed: Tue Jan 25 11:30:31 2011 UTC (14 years, 3 months ago) by paus
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_029a, Mit_028, Mit_027, Mit_027a, HEAD
Changes since 1.1: +193 -0 lines
Error occurred while calculating annotation data.
Log Message:
2nd try

File Contents

# Content
1 // $Id: HistStyles.cc,v 1.1.2.3 2010/10/12 21:50:11 paus Exp $
2
3 #include "MitAna/DataUtil/interface/Debug.h"
4 #include "MitPlots/Style/interface/HistStyles.h"
5
6 ClassImp(mithep::HistStyles)
7
8 using namespace std;
9 using namespace mithep;
10
11 //--------------------------------------------------------------------------------------------------
12 HistStyles::HistStyles() :
13 fNStyles (0),
14 fIStyle (0),
15 fDataStyle(0)
16 {
17 // Constructor
18
19 HistStyle *s;
20 // add the default Monte Carlo styles
21 s = AddStyle();
22 s->SetColor (kBlack);
23 s->SetFillStyle (0);
24 s = AddStyle();
25 s->SetColor (kBlue);
26 s->SetFillStyle (3001);
27 s = AddStyle();
28 s->SetColor (kRed);
29 s->SetFillStyle (3004);
30 s = AddStyle();
31 s->SetColor (kGreen);
32 s->SetFillStyle (3007);
33 s = AddStyle();
34 s->SetColor (kCyan);
35 s->SetFillStyle (3010);
36 // add the default data style
37 s = SetDataStyle ();
38 s->SetColor (kBlack);
39 s->SetFillStyle (0);
40 s->SetMarkerStyle(20);
41 s->SetMarkerSize (1.0);
42 }
43
44 //--------------------------------------------------------------------------------------------------
45 void HistStyles::Clear()
46 {
47 // Reset all style and start with a clean slate
48
49 fStyles.clear();
50
51 return;
52 }
53 //--------------------------------------------------------------------------------------------------
54 void HistStyles::Show() const
55 {
56 // Show present list of defined samples
57
58 printf("\n ==== Histogram Styles overview ====\n\n");
59 printf(" Dataset name Legend Histogram file");
60 printf(" Cross Section [pb]\n");
61 printf(" -------------------------------------------------------------------");
62 printf("--------------------------------------------------------------------\n");
63 fDataStyle->Show();
64 printf(" -------------------------------------------------------------------");
65 printf("--------------------------------------------------------------------\n");
66 for (UInt_t i=0; i<fStyles.size(); i++)
67 fStyles[i].Show();
68
69 return;
70 }
71
72 //--------------------------------------------------------------------------------------------------
73 const HistStyle *HistStyles::GetStyle(UInt_t iStyle) const
74 {
75 // Get style corresponding to given style index. Return NULL pointer if index out of range.
76
77 if (iStyle >= fNStyles)
78 return 0;
79
80 return &fStyles[iStyle];
81 }
82
83 //--------------------------------------------------------------------------------------------------
84 const HistStyle *HistStyles::GetDataStyle() const
85 {
86 // Get data style. Return NULL pointer if not available.
87
88 return fDataStyle;
89 }
90
91 //--------------------------------------------------------------------------------------------------
92 HistStyle *HistStyles::AddStyle()
93 {
94 // Adding another style (vector takes care of memory management)
95
96 HistStyle* tmpStyle = new HistStyle();
97 fStyles.push_back(*tmpStyle);
98 fNStyles++;
99 // cleanup after yourself
100 delete tmpStyle;
101
102 return &fStyles[fStyles.size()-1];
103 }
104
105 //--------------------------------------------------------------------------------------------------
106 HistStyle *HistStyles::SetDataStyle()
107 {
108 // Setting the data sample (existing definition is overwritten)
109
110 if (fDataStyle != 0)
111 delete fDataStyle;
112
113 fDataStyle = new HistStyle();
114
115 return fDataStyle;
116 }
117
118 //--------------------------------------------------------------------------------------------------
119 const HistStyle *HistStyles::CurrentStyle() const
120 {
121 // Get sample corresponding to current style index. Return NULL pointer if index out of range.
122
123 if (fIStyle >= fNStyles)
124 return 0;
125
126 return &fStyles[fIStyle];
127 }
128
129 //--------------------------------------------------------------------------------------------------
130 void HistStyles::NextStyle()
131 {
132 // Get sample corresponding to given sample number. Loop back to the beginning
133 // if index goes out of range.
134
135 fIStyle++;
136 if (fIStyle >= fNStyles)
137 fIStyle = 0;
138
139 return;
140 }
141
142 //--------------------------------------------------------------------------------------------------
143 void HistStyles::PreviousStyle()
144 {
145 // Get previous style
146
147 if (fIStyle == 0)
148 fIStyle = fStyles.size() - 1;
149 else
150 fIStyle--;
151
152 return;
153 }
154
155 //--------------------------------------------------------------------------------------------------
156 void HistStyles::ResetStyle()
157 {
158 // Get sample corresponding to given sample number. Return NULL pointer if index out of range.
159
160 fIStyle = 0;
161
162 return;
163 }
164
165 //--------------------------------------------------------------------------------------------------
166 void HistStyles::ApplyCurrentStyle(TH1 *h) const
167 {
168 // Apply the present style to the given histogram
169
170 h->SetMarkerColor(fStyles[fIStyle].Color());
171 h->SetLineColor (fStyles[fIStyle].Color());
172 h->SetFillColor (fStyles[fIStyle].Color());
173 h->SetFillStyle (fStyles[fIStyle].FillStyle());
174 h->SetMarkerStyle(fStyles[fIStyle].MarkerStyle());
175 h->SetMarkerSize (fStyles[fIStyle].MarkerSize());
176
177 return;
178 }
179
180 //--------------------------------------------------------------------------------------------------
181 void HistStyles::ApplyDataStyle(TH1 *h) const
182 {
183 // Apply the present style to the given histogram
184
185 h->SetMarkerColor(fDataStyle->Color());
186 h->SetLineColor (fDataStyle->Color());
187 h->SetFillColor (fDataStyle->Color());
188 h->SetFillStyle (fDataStyle->FillStyle());
189 h->SetMarkerStyle(fDataStyle->MarkerStyle());
190 h->SetMarkerSize (fDataStyle->MarkerSize());
191
192 return;
193 }