tdaq-develop-2025-02-12
CrvDQMStyle.hh
1 // ROOT styling for CRV DQM
2 // Samuel Grant 2025
3 
4 #ifndef CRV_DQM_STYLE_H
5 #define CRV_DQM_STYLE_H
6 
7 #include "TH1.h"
8 #include "TH2.h"
9 #include "TStyle.h"
10 #include "TCanvas.h"
11 #include "TPad.h"
12 #include "TROOT.h"
13 
14 class CrvDQMStyle {
15 public:
16  static void SetStyle() {
17 
18  TStyle *style = new TStyle("CrvStyle", "CRV DQM styling");
19 
20  // Basic canvas settings
21  style->SetCanvasColor(kWhite);
22  style->SetCanvasBorderMode(0);
23  style->SetPadColor(kWhite);
24  style->SetPadBorderMode(0);
25  style->SetPadTopMargin(0.05);
26  style->SetPadBottomMargin(0.13);
27  style->SetPadLeftMargin(0.15);
28  style->SetPadRightMargin(0.05);
29 
30  // Font settings
31  style->SetTextFont(42);
32  style->SetLabelFont(42, "xyz");
33  style->SetTitleFont(42, "xyz");
34 
35  // Text sizes
36  style->SetTextSize(0.045);
37  style->SetLabelSize(0.045, "xyz");
38  style->SetTitleSize(0.05, "xyz");
39 
40  // Title positioning
41  style->SetTitleOffset(1.2, "y");
42  style->SetTitleOffset(1.0, "x");
43 
44  // Canvas fill
45  style->SetFillColor(kWhite);
46  style->SetFillStyle(1001);
47 
48  // Ticks and divisions
49  style->SetPadTickX(1);
50  style->SetPadTickY(1);
51  style->SetTickLength(0.015);
52  style->SetNdivisions(505, "xyz");
53 
54  // Frame
55  style->SetFrameLineWidth(1);
56  style->SetLineWidth(1);
57 
58  style->SetOptStat(0);
59 
60  // Use current style - this works in 6.30
61  gROOT->SetStyle("CrvStyle");
62  gROOT->ForceStyle();
63  }
64 
65  static void FormatHist(TH1* hist, const std::string& colour = "blue") {
66  if (!hist) return;
67  // Basic histogram-specific formatting
68  hist->SetStats(0);
69  hist->SetLineWidth(2);
70  hist->SetFillStyle(1001);
71  hist->SetLineStyle(1);
72  hist->GetYaxis()->SetTitleOffset(1.6);
73  hist->GetXaxis()->SetTitleOffset(1.2);
74 
75  // Primary colours
76  if (colour == "blue") {
77  hist->SetLineColor(kAzure+2);
78  hist->SetFillColor(kAzure-9);
79  }
80  else if (colour == "green") {
81  hist->SetLineColor(kGreen+2);
82  hist->SetFillColor(kGreen-9);
83  }
84  else if (colour == "red") {
85  hist->SetLineColor(kRed+2);
86  hist->SetFillColor(kRed-9);
87  }
88  }
89 };
90 
91 #endif