1
+ /** Detray library, part of the ACTS project (R&D line)
2
+ *
3
+ * (c) 2024 CERN for the benefit of the ACTS project
4
+ *
5
+ * Mozilla Public License Version 2.0
6
+ */
7
+
8
+ // ROOT include(s).
9
+ #include <TCanvas.h>
10
+ #include <TFile.h>
11
+ #include <TGaxis.h>
12
+ #include <TGraph.h>
13
+ #include <TLatex.h>
14
+ #include <TLegend.h>
15
+ #include <TLegendEntry.h>
16
+ #include <TMath.h>
17
+ #include <TMultiGraph.h>
18
+ #include <TROOT.h>
19
+ #include <TStyle.h>
20
+
21
+ #include <ROOT/RCsvDS.hxx>
22
+ #include <ROOT/RDataFrame.hxx>
23
+
24
+ // System include(s).
25
+ #include <array>
26
+ #include <iostream>
27
+ #include <sstream>
28
+ #include <string>
29
+ #include <vector>
30
+
31
+ namespace {
32
+
33
+ double x_pos1 = -13.4f ;
34
+ double x_pos2 = 0.06f ;
35
+ double y_pos1 = 2e5 ;
36
+ double y_pos2 = 6.75e4 ;
37
+
38
+ // double title_x = x_pos;
39
+ // double title_y = 0.8197f;
40
+
41
+ int label_font = 132 ;
42
+ double label_font_size = 0.055 ;
43
+ double header_text_size = 0.055 ;
44
+ double geom_text_size = 0.0434028 ;
45
+ double titleX_font_size = 0.05 ;
46
+ double titleY_font_size = 0.055 ;
47
+ double x_title_offset = 1.75 ;
48
+ double y_title_offset = 1.34 ;
49
+ double x_label_offset = 0.015 ;
50
+ double y_label_offset = 0.015 ;
51
+
52
+ const std ::array < float , 2 > cdim {700 , 600 };
53
+ double maximum = 1e6 ;
54
+
55
+ double pad_x0 = 0.00f ;
56
+ double pad_x1 = 1.f ;
57
+ double pad_y0 = 0.00f ;
58
+ double pad_y1 = 1.f ;
59
+
60
+ double bin_width = 0.2f ;
61
+ } // namespace
62
+
63
+ void draw_text (double x1 , double y1 , double y2 , double s1 , double s2 ,
64
+ std ::string t1 , std ::string t2 ) {
65
+ TLatex * ttext1 = new TLatex (x1 , y1 , t1 .c_str ());
66
+ TLatex * ttext2 = new TLatex (x1 , y2 , t2 .c_str ());
67
+ ttext1 -> SetTextFont (22 );
68
+ ttext1 -> SetTextSize (s1 );
69
+ ttext2 -> SetTextFont (132 );
70
+ ttext2 -> SetTextSize (s2 );
71
+
72
+ ttext1 -> Draw ();
73
+ ttext2 -> Draw ();
74
+ }
75
+
76
+ void histo_setup (TH1D * histo ) {
77
+ histo -> GetXaxis ()-> SetLabelFont (label_font );
78
+ histo -> GetYaxis ()-> SetLabelFont (label_font );
79
+ histo -> GetXaxis ()-> SetLabelSize (label_font_size );
80
+ histo -> GetYaxis ()-> SetLabelSize (label_font_size );
81
+ histo -> GetXaxis ()-> SetTitleSize (titleX_font_size );
82
+ histo -> GetYaxis ()-> SetTitleSize (titleY_font_size );
83
+ histo -> GetYaxis ()-> SetTitleOffset (y_title_offset );
84
+ histo -> GetXaxis ()-> SetTitleOffset (x_title_offset + 0.1 );
85
+ histo -> GetXaxis ()-> SetLabelOffset (x_label_offset );
86
+ histo -> GetYaxis ()-> SetLabelOffset (y_label_offset );
87
+ histo -> GetYaxis ()-> SetNdivisions (504 );
88
+ histo -> GetYaxis ()-> SetMaxDigits (1 );
89
+ histo -> GetXaxis ()-> CenterTitle (true);
90
+ histo -> GetYaxis ()-> CenterTitle (true);
91
+ histo -> GetXaxis ()-> SetTitleFont (132 );
92
+ histo -> GetYaxis ()-> SetTitleFont (132 );
93
+ }
94
+
95
+ void set_yaxis_title (TH1D * h , const double text_size ) {
96
+ double bin_width = h -> GetBinWidth (0u );
97
+ std ::string str = std ::to_string (bin_width );
98
+ str .erase (str .find_last_not_of ('0' ) + 1 , std ::string ::npos );
99
+ str .erase (str .find_last_not_of ('.' ) + 1 , std ::string ::npos );
100
+ std ::string y_axis_title = "Counts / (" + str + ")" ;
101
+ h -> GetYaxis ()-> SetTitle (y_axis_title .c_str ());
102
+ h -> GetYaxis ()-> SetTitleSize (text_size );
103
+ }
104
+
105
+ void draw_histogram (const std ::string root_name , const int num ) {
106
+
107
+ const std ::string rect_title = "Bound-to-bound transport" ;
108
+ const std ::string geom_title = "RKN with the ODD magnetic field and CsI" ;
109
+
110
+ TFile * f = TFile ::Open (root_name .c_str (), "read" );
111
+ TTree * t = (TTree * )f -> Get ("inhom_rect_material" );
112
+
113
+ auto dthetadl0_canvas =
114
+ new TCanvas ("dthetadl0_canvas" , "dthetadl0_canvas" , cdim [0 ], cdim [1 ]);
115
+ dthetadl0_canvas -> SetLogy ();
116
+
117
+ TPad * pad1 = new TPad ("pad1" , "pad1" , pad_x0 , pad_y0 , pad_x1 , pad_y1 );
118
+ pad1 -> Draw ();
119
+ pad1 -> cd ();
120
+ pad1 -> SetLeftMargin (110. / pad1 -> GetWw ());
121
+ pad1 -> SetBottomMargin (125. / pad1 -> GetWh ());
122
+ pad1 -> SetLogy ();
123
+
124
+ t -> Draw ("log10(abs(dthetadl0_E)) >> htemp(100,-14,-4)" );
125
+ TH1D * dthetadl0_hist = (TH1D * )gPad -> GetPrimitive ("htemp" );
126
+ histo_setup (dthetadl0_hist );
127
+ set_yaxis_title (dthetadl0_hist , titleY_font_size );
128
+ dthetadl0_hist -> GetXaxis ()-> SetNdivisions (505 );
129
+ dthetadl0_hist -> GetXaxis ()-> SetTitle (
130
+ "log_{10}( #left|#frac{#partial#theta_{F}}{#partiall_{0I}}#right| "
131
+ "[mm^{-1}] )" );
132
+ dthetadl0_hist -> SetMaximum (maximum );
133
+ dthetadl0_hist -> SetLineColor (kOrange + 3 );
134
+ dthetadl0_hist -> SetFillColor (kOrange + 2 );
135
+ dthetadl0_hist -> SetFillStyle (3001 );
136
+
137
+ draw_text (x_pos1 , y_pos1 , y_pos2 , header_text_size , geom_text_size ,
138
+ rect_title .c_str (), geom_title .c_str ());
139
+
140
+ dthetadl0_canvas -> Draw ();
141
+ dthetadl0_canvas -> SaveAs ("bound_to_bound_dthetadl0_E_histo.pdf" );
142
+
143
+ auto dqopdqop_canvas =
144
+ new TCanvas ("dqopdqop_canvas" , "dqopdqop_canvas" , cdim [0 ], cdim [1 ]);
145
+ dqopdqop_canvas -> SetLogy ();
146
+
147
+ TPad * pad2 = new TPad ("pad2" , "pad2" , pad_x0 , pad_y0 , pad_x1 , pad_y1 );
148
+ pad2 -> Draw ();
149
+ pad2 -> cd ();
150
+ pad2 -> SetLeftMargin (110. / pad2 -> GetWw ());
151
+ pad2 -> SetBottomMargin (125. / pad2 -> GetWh ());
152
+ pad2 -> SetLogy ();
153
+
154
+ t -> Draw ("log10(dqopdqop_E) >> htemp2(100,0,1)" );
155
+ TH1D * dqopdqop_hist = (TH1D * )gPad -> GetPrimitive ("htemp2" );
156
+ histo_setup (dqopdqop_hist );
157
+ set_yaxis_title (dqopdqop_hist , titleY_font_size );
158
+
159
+ histo_setup (dqopdqop_hist );
160
+ dqopdqop_hist -> GetXaxis ()-> SetNdivisions (505 );
161
+ dqopdqop_hist -> GetXaxis ()-> SetTitle (
162
+ "log_{10}( "
163
+ "#left|#frac{#partial#lambda_{F}}{#partial#lambda_{I}}#right| )" );
164
+ dqopdqop_hist -> SetMaximum (maximum );
165
+ dqopdqop_hist -> SetLineColor (kGreen + 3 );
166
+ dqopdqop_hist -> SetFillColor (kGreen + 2 );
167
+ dqopdqop_hist -> SetFillStyle (3001 );
168
+
169
+ draw_text (x_pos2 , y_pos1 , y_pos2 , header_text_size , geom_text_size ,
170
+ rect_title .c_str (), geom_title .c_str ());
171
+
172
+ dqopdqop_canvas -> Draw ();
173
+ dqopdqop_canvas -> SaveAs ("bound_to_bound_dqopdqop_E_histo.pdf" );
174
+ }
175
+
176
+ void jacobian_histogram (int num ) {
177
+ gStyle -> SetOptTitle (0 );
178
+ gStyle -> SetOptStat (0 );
179
+
180
+ const std ::string name = "inhom_rect_material_" + std ::to_string (num );
181
+ const std ::string csv_name = name + ".csv" ;
182
+ const std ::string root_name = "residual_histogram.root" ;
183
+
184
+ std ::cout << "Processing file: " << csv_name << std ::endl ;
185
+
186
+ auto rdf = ROOT ::RDF ::FromCSV (csv_name );
187
+ // Create root file
188
+ rdf .Snapshot ("inhom_rect_material" , root_name .c_str ());
189
+
190
+ draw_histogram (root_name , num );
191
+ }
0 commit comments