File indexing completed on 2024-04-06 12:32:01
0001 #include "TF1.h"
0002 #include "TProfile.h"
0003 #include "Validation/DTRecHits/interface/utils.h"
0004
0005 void Tutils::drawGFit(TH1 *h1, float min, float max, float minfit, float maxfit) {
0006 setStyle(h1);
0007 static int i = 0;
0008 i++;
0009
0010
0011 h1->GetXaxis()->SetRangeUser(min, max);
0012 TString fitName = "g";
0013 fitName += i;
0014 TF1 *g1 = new TF1(fitName.Data(), "gaus", minfit, maxfit);
0015 g1->SetLineColor(2);
0016 g1->SetLineWidth(2);
0017 h1->Fit(g1, "RQ");
0018 h1->Draw();
0019
0020
0021
0022
0023 }
0024 void Tutils::setStyle(TH1 *histo) {
0025 mystyle = getStyle("tdr");
0026 histo->GetXaxis()->SetTitleFont(mystyle->GetTitleFont());
0027 histo->GetXaxis()->SetTitleSize(mystyle->GetTitleFontSize());
0028 histo->GetXaxis()->SetLabelFont(mystyle->GetLabelFont());
0029 histo->GetXaxis()->SetLabelSize(mystyle->GetLabelSize());
0030
0031 histo->GetYaxis()->SetTitleFont(mystyle->GetTitleFont());
0032 histo->GetYaxis()->SetTitleSize(mystyle->GetTitleFontSize());
0033 histo->GetYaxis()->SetLabelFont(mystyle->GetLabelFont());
0034 histo->GetYaxis()->SetLabelSize(mystyle->GetLabelSize());
0035 }
0036
0037 void Tutils::setStyle(TH2 *histo) {
0038 mystyle = getStyle("tdr");
0039 histo->GetXaxis()->SetTitleFont(mystyle->GetTitleFont());
0040 histo->GetXaxis()->SetTitleSize(mystyle->GetTitleFontSize());
0041 histo->GetXaxis()->SetLabelFont(mystyle->GetLabelFont());
0042 histo->GetXaxis()->SetLabelSize(mystyle->GetLabelSize());
0043
0044 histo->GetYaxis()->SetTitleFont(mystyle->GetTitleFont());
0045 histo->GetYaxis()->SetTitleSize(mystyle->GetTitleFontSize());
0046 histo->GetYaxis()->SetLabelFont(mystyle->GetLabelFont());
0047 histo->GetYaxis()->SetLabelSize(mystyle->GetLabelSize());
0048 }
0049
0050 TStyle *Tutils::getStyle(const TString &name) {
0051 TStyle *theStyle;
0052 if (name == "mstyle") {
0053 theStyle = new TStyle("mstyle", "mstyle");
0054
0055 theStyle->SetPadBorderMode(0);
0056 theStyle->SetCanvasBorderMode(0);
0057 theStyle->SetPadColor(0);
0058 theStyle->SetCanvasColor(0);
0059 theStyle->SetMarkerStyle(8);
0060 theStyle->SetMarkerSize(0.7);
0061 theStyle->SetStatH(0.3);
0062 theStyle->SetStatW(0.15);
0063
0064
0065 theStyle->SetTitleBorderSize(1);
0066 theStyle->SetPalette(1);
0067
0068 } else if (name == "tdr") {
0069 theStyle = new TStyle("tdrStyle", "Style for P-TDR");
0070
0071
0072 theStyle->SetCanvasBorderMode(0);
0073 theStyle->SetCanvasColor(kWhite);
0074 theStyle->SetCanvasDefH(600);
0075 theStyle->SetCanvasDefW(600);
0076 theStyle->SetCanvasDefX(0);
0077 theStyle->SetCanvasDefY(0);
0078
0079
0080 theStyle->SetPadBorderMode(0);
0081
0082 theStyle->SetPadColor(kWhite);
0083 theStyle->SetPadGridX(true);
0084 theStyle->SetPadGridY(true);
0085 theStyle->SetGridColor(0);
0086 theStyle->SetGridStyle(3);
0087 theStyle->SetGridWidth(1);
0088
0089
0090 theStyle->SetFrameBorderMode(0);
0091 theStyle->SetFrameBorderSize(1);
0092 theStyle->SetFrameFillColor(0);
0093 theStyle->SetFrameFillStyle(0);
0094 theStyle->SetFrameLineColor(1);
0095 theStyle->SetFrameLineStyle(1);
0096 theStyle->SetFrameLineWidth(1);
0097
0098
0099
0100
0101 theStyle->SetHistLineColor(1);
0102 theStyle->SetHistLineStyle(0);
0103 theStyle->SetHistLineWidth(1);
0104
0105
0106
0107 theStyle->SetEndErrorSize(2);
0108
0109 theStyle->SetErrorX(0.);
0110
0111 theStyle->SetMarkerStyle(20);
0112
0113
0114 theStyle->SetOptFit(1);
0115 theStyle->SetFitFormat("5.4g");
0116 theStyle->SetFuncColor(2);
0117 theStyle->SetFuncStyle(1);
0118 theStyle->SetFuncWidth(1);
0119
0120
0121 theStyle->SetOptDate(0);
0122
0123
0124
0125
0126 theStyle->SetOptFile(0);
0127
0128
0129 theStyle->SetOptStat(10);
0130 theStyle->SetStatColor(kWhite);
0131 theStyle->SetStatFont(42);
0132 theStyle->SetStatFontSize(0.07);
0133 theStyle->SetStatTextColor(1);
0134 theStyle->SetStatFormat("6.4g");
0135 theStyle->SetStatBorderSize(1);
0136 theStyle->SetStatH(0.3);
0137 theStyle->SetStatW(0.2);
0138
0139
0140
0141
0142
0143 theStyle->SetPadTopMargin(0.05);
0144 theStyle->SetPadBottomMargin(0.13);
0145 theStyle->SetPadLeftMargin(0.16);
0146 theStyle->SetPadRightMargin(0.02);
0147
0148
0149
0150 theStyle->SetOptTitle(0);
0151 theStyle->SetTitleFont(42);
0152 theStyle->SetTitleColor(1);
0153 theStyle->SetTitleTextColor(1);
0154 theStyle->SetTitleFillColor(10);
0155 theStyle->SetTitleFontSize(0.05);
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165 theStyle->SetTitleColor(1, "XYZ");
0166 theStyle->SetTitleFont(42, "XYZ");
0167 theStyle->SetTitleSize(0.06, "XYZ");
0168
0169
0170 theStyle->SetTitleXOffset(0.9);
0171 theStyle->SetTitleYOffset(1.25);
0172
0173
0174
0175
0176 theStyle->SetLabelColor(1, "XYZ");
0177 theStyle->SetLabelFont(42, "XYZ");
0178 theStyle->SetLabelOffset(0.007, "XYZ");
0179 theStyle->SetLabelSize(0.045, "XYZ");
0180
0181
0182
0183 theStyle->SetAxisColor(1, "XYZ");
0184 theStyle->SetStripDecimals(kTRUE);
0185 theStyle->SetTickLength(0.03, "XYZ");
0186 theStyle->SetNdivisions(510, "XYZ");
0187 theStyle->SetPadTickX(1);
0188 theStyle->SetPadTickY(1);
0189
0190
0191 theStyle->SetOptLogx(0);
0192 theStyle->SetOptLogy(0);
0193 theStyle->SetOptLogz(0);
0194
0195
0196 theStyle->SetPaperSize(20., 20.);
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212 } else {
0213
0214 theStyle = gStyle;
0215 }
0216 return theStyle;
0217 }
0218
0219 void Tutils::plotAndProfileX(TH2 *h2, float min, float max, bool profile) {
0220 setStyle(h2);
0221
0222
0223 h2->GetYaxis()->SetRangeUser(min, max);
0224 h2->Draw();
0225 if (profile) {
0226 TProfile *prof = h2->ProfileX();
0227 prof->SetMarkerColor(2);
0228 prof->SetLineColor(2);
0229 prof->Draw("same");
0230 }
0231
0232
0233
0234
0235 }