1414#include <TF1.h>
1515#include <TH1F.h>
1616#include <TH2F.h>
17+ #include <TProfile2D.h>
1718#include <TCanvas.h>
1819#include <TTree.h>
20+ #include <TStyle.h>
1921#endif
2022
21- void plotTreeVsX (TFile * f , const char * treeName , const char * xVar , const char * xTitle , int nBinsX , float xMin , float xMax )
23+ TString makeSel (int lay , const char * extraSel )
24+ {
25+ TString sel = Form ("lay==%d" , lay );
26+ if (extraSel && extraSel [0 ]) {
27+ sel += Form (" && %s" , extraSel );
28+ }
29+ return sel ;
30+ }
31+
32+ void plotTreeVsX (TFile * f , const char * treeName , const char * xVar , const char * xTitle ,
33+ int nBinsX , float xMin , float xMax ,
34+ const char * tag = "" , const char * extraSel = "" )
2235{
2336 auto res = f -> Get < TTree > (treeName );
2437 const int nVar = 2 ;
@@ -27,7 +40,7 @@ void plotTreeVsX(TFile* f, const char* treeName, const char* xVar, const char* x
2740
2841 TCanvas * canvs [nVar ];
2942 for (int iv = 0 ; iv < nVar ; iv ++ ) {
30- canvs [iv ] = new TCanvas (Form ("%s_%s_vs_%s" , treeName , vars [iv ], xVar ), Form ("%s vs %s" , vars [iv ], xVar ), 800 , 1600 );
43+ canvs [iv ] = new TCanvas (Form ("%s_%s_vs_%s%s " , treeName , vars [iv ], xVar , tag ), Form ("%s vs %s %s " , vars [iv ], xVar , tag ), 800 , 1600 );
3144 canvs [iv ]-> Divide (2 , 4 );
3245 }
3346
@@ -37,16 +50,16 @@ void plotTreeVsX(TFile* f, const char* treeName, const char* xVar, const char* x
3750 canvs [iv ]-> cd (lay + 2 );
3851 gPad -> SetRightMargin (0.13 );
3952
40- TString hname = Form ("h_%s_%s_lay%d" , vars [iv ], xVar , lay + 1 );
53+ TString hname = Form ("h_%s_%s% s_lay%d" , vars [iv ], xVar , tag , lay + 1 );
4154 TString expr = Form ("%s*10000:%s>>%s(%d,%f,%f,100,-100,100)" , vars [iv ], xVar , hname .Data (), nBinsX , xMin , xMax );
42- TString sel = Form ( " lay==%d" , lay );
55+ TString sel = makeSel ( lay , extraSel );
4356 res -> Draw (expr , sel , "col" );
4457
4558 auto* h = (TH2F * )gDirectory -> Get (hname );
4659 if (!h ) {
4760 continue ;
4861 }
49- h -> SetTitle (Form ("Layer %d ;%s;%s" , lay , xTitle , titles [iv ]));
62+ h -> SetTitle (Form ("Layer %d %s ;%s;%s" , lay , tag , xTitle , titles [iv ]));
5063 h -> GetZaxis ()-> SetLabelSize (0.035 );
5164
5265 // fit y-slices with gaussian
@@ -69,11 +82,97 @@ void plotTreeVsX(TFile* f, const char* treeName, const char* xVar, const char* x
6982 }
7083}
7184
85+ void plotProfile2D (TFile * f , const char * treeName ,
86+ const char * tag = "" , const char * extraSel = "" )
87+ {
88+ auto res = f -> Get < TTree > (treeName );
89+ const int nVar = 2 ;
90+ const char * vars [nVar ] = {"dY" , "dZ" };
91+ const char * titles [nVar ] = {"#LTd_{Y}#GT (#mum)" , "#LTd_{Z}#GT (#mum)" };
92+
93+ TCanvas * canvs [nVar ];
94+ for (int iv = 0 ; iv < nVar ; iv ++ ) {
95+ canvs [iv ] = new TCanvas (Form ("%s_%s_prof2d%s" , treeName , vars [iv ], tag ), Form ("%s #phi vs #eta %s" , vars [iv ], tag ), 800 , 1600 );
96+ canvs [iv ]-> Divide (2 , 4 );
97+ }
98+
99+ for (int iv = 0 ; iv < nVar ; iv ++ ) {
100+ canvs [iv ]-> cd (0 );
101+ for (int lay = -1 ; lay <= 6 ; lay ++ ) {
102+ canvs [iv ]-> cd (lay + 2 );
103+ gPad -> SetRightMargin (0.15 );
104+
105+ TString hname = Form ("hp_%s%s_lay%d" , vars [iv ], tag , lay + 1 );
106+ TString expr = Form ("%s*10000:eta:phi>>%s(50,0,%f,50,-1.,1.)" , vars [iv ], hname .Data (), 2 * TMath ::Pi ());
107+ TString sel = makeSel (lay , extraSel );
108+ res -> Draw (expr , sel , "prof colz" );
109+
110+ auto* h = (TProfile2D * )gDirectory -> Get (hname );
111+ if (!h ) {
112+ continue ;
113+ }
114+ h -> SetTitle (Form ("Layer %d %s;#phi (rad);#eta;%s" , lay , tag , titles [iv ]));
115+ }
116+ canvs [iv ]-> SaveAs (Form ("%s.png" , canvs [iv ]-> GetName ()));
117+ }
118+ }
119+
120+ void plotPulls (TFile * f , const char * treeName ,
121+ const char * tag = "" , const char * extraSel = "" )
122+ {
123+ auto res = f -> Get < TTree > (treeName );
124+ const int nPar = 5 ;
125+ const char * parNames [nPar ] = {"Y" , "Z" , "Snp" , "Tgl" , "Q2Pt" };
126+ // diagonal covariance indices in mC[]: 0, 2, 5, 9, 14
127+ const int covIdx [nPar ] = {0 , 2 , 5 , 9 , 14 };
128+
129+ for (int lay = -1 ; lay <= 6 ; lay ++ ) {
130+ auto* c = new TCanvas (Form ("%s_pulls_lay%d%s" , treeName , lay , tag ), Form ("Pulls layer %d %s" , lay , tag ), 1200 , 800 );
131+ c -> Divide (3 , 2 );
132+ TString sel = makeSel (lay , extraSel );
133+
134+ for (int ip = 0 ; ip < nPar ; ip ++ ) {
135+ c -> cd (ip + 1 );
136+ TString hname = Form ("hpull_%s%s_lay%d" , parNames [ip ], tag , lay + 1 );
137+ TString expr = Form ("(trk.mP[%d]-mcTrk.mP[%d])/sqrt(trk.mC[%d])>>%s(100,-5,5)" , ip , ip , covIdx [ip ], hname .Data ());
138+ res -> Draw (expr , sel );
139+
140+ auto* h = (TH1F * )gDirectory -> Get (hname );
141+ if (!h ) {
142+ continue ;
143+ }
144+ h -> SetTitle (Form ("Layer %d %s;pull_{%s};counts" , lay , tag , parNames [ip ]));
145+ h -> Fit ("gaus" , "Q" );
146+ }
147+ c -> SaveAs (Form ("%s.png" , c -> GetName ()));
148+ }
149+ }
150+
72151void PlotMisalignment (const char * fname = "its3TrackStudy.root" )
73152{
74153 auto f = TFile ::Open (fname );
154+
155+ const int nPtBins = 5 ;
156+ const float ptEdges [nPtBins + 1 ] = {0. , 0.3 , 0.8 , 2. , 5. , 10. };
157+
75158 for (const char * tree : {"idealRes" , "misRes" }) {
159+ // integrated plots
76160 plotTreeVsX (f , tree , "phi" , "#phi (rad)" , 100 , 0 , 2 * TMath ::Pi ());
77161 plotTreeVsX (f , tree , "eta" , "#eta" , 100 , -1. , 1. );
162+ plotProfile2D (f , tree );
163+ plotPulls (f , tree );
164+
165+ // pT-binned plots
166+ for (int ipt = 0 ; ipt < nPtBins ; ipt ++ ) {
167+ TString tag = Form ("_pt%.0f_%.0f" , ptEdges [ipt ] * 10 , ptEdges [ipt + 1 ] * 10 );
168+ TString ptSel = Form ("trk.getPt()>=%.2f&&trk.getPt()<%.2f" , ptEdges [ipt ], ptEdges [ipt + 1 ]);
169+ TString ptLabel = Form (" (%.1f<p_{T}<%.1f)" , ptEdges [ipt ], ptEdges [ipt + 1 ]);
170+ TString tagLabel = tag + ptLabel ;
171+
172+ plotTreeVsX (f , tree , "phi" , "#phi (rad)" , 100 , 0 , 2 * TMath ::Pi (), tag .Data (), ptSel .Data ());
173+ plotTreeVsX (f , tree , "eta" , "#eta" , 100 , -1. , 1. , tag .Data (), ptSel .Data ());
174+ plotProfile2D (f , tree , tag .Data (), ptSel .Data ());
175+ plotPulls (f , tree , tag .Data (), ptSel .Data ());
176+ }
78177 }
79178}
0 commit comments