BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
L1AlgoPulls.h
Go to the documentation of this file.
1#ifndef L1AlgoPulls_h
2#define L1AlgoPulls_h
3
4// #define BUILD_HISTO_FOR_EACH_STANTION
5
6#ifdef BUILD_HISTO_FOR_EACH_STANTION
7const int NStations = 8;
8#else
9const int NStations = 0;
10#endif // BUILD_HISTO_FOR_EACH_STANTION
11
12#include "CbmL1.h"
13#include "L1Algo/CbmL1Def.h"
14#include "L1Algo/L1Algo.h"
15#include "L1Algo/L1StsHit.h"
16#include "L1Algo/L1TrackPar.h"
17#include "TCanvas.h"
18#include "TF1.h"
19#include "TStyle.h"
20
21#include <iostream>
22#include <vector>
23
24using std::cout;
25using std::endl;
26using std::vector;
27
29{
30 double x, y, tx, ty, qp;
31
32 static const int NParameters = 5;
33
36 : x(T.x[i])
37 , y(T.y[i])
38 , tx(T.tx[i])
39 , ty(T.ty[i])
40 , qp(T.qp[i]) {};
42 : x(T.x)
43 , y(T.y)
44 , tx(T.px / T.pz)
45 , ty(T.py / T.pz)
46 , qp(T.q / T.p) {};
47
48 double operator[](int i)
49 {
50 switch (i) {
51 case 0:
52 return x;
53 case 1:
54 return y;
55 case 2:
56 return tx;
57 case 3:
58 return ty;
59 case 4:
60 return qp;
61 };
62 }
63
65 {
67 c.x = x - b.x;
68 c.y = y - b.y;
69 c.tx = tx - b.tx;
70 c.ty = ty - b.ty;
71 c.qp = qp - b.qp;
72 return c;
73 }
74
76 {
78 c.x = x / b.x;
79 c.y = y / b.y;
80 c.tx = tx / b.tx;
81 c.ty = ty / b.ty;
82 c.qp = qp / b.qp;
83 return c;
84 }
85
86 void Print() { cout << x << " " << y << " " << tx << " " << ty << " " << qp << endl; }
87};
88
90
92{
93 public:
95 : fNAllPulls(0)
96 {
97 fGPulls.clear();
98 for (int i = 0; i < NStations; i++)
99 fStaPulls[i].clear();
100 };
101 void Init();
102
103 // void AddVec(L1TrackPar& T, THitI ih);
104 void AddOne(L1TrackPar& T, int i, THitI ih);
105 void Print(); // fast method to see pulls :)
106 void Build(bool draw = 1);
107
108 int fNAllPulls; // number of AddOne calls
109 private:
110 void makeUpHisto(TH1* hist, TString title, float& sigma);
111
113 vector<TL1TrackParameters> fGPulls; // pulls for all stations
114 vector<TL1TrackParameters> fStaPulls[NStations]; // pulls for each station
116
117 vector<TL1TrackParameters> fGRes; // residuals for all stations
119
120 static const float TailCut = 5000.; //
121 static const float csCut = 5.; // chi-square cut
122 static const int textFont = 22; // TNewRoman
124};
125
126// ===================================================================================
127
129{
131
132 static bool first_call = 1;
133 if (first_call) {
134 // TDirectory *curdir = gDirectory;
135 // fL1->histodir->cd();
136 // gDirectory->mkdir("L1AlgoPulls");
137 // gDirectory->cd("L1AlgoPulls");
138
139 // add global pulls
140 for (int i = 0; i < TL1TrackParameters::NParameters; i++) {
141 TString name = "pull_";
142 name += L1TrackParametersNames[i];
143 histoPull[i] = new TH1F(name, name, 50, -10, 10);
144 }
145
146#ifdef BUILD_HISTO_FOR_EACH_STANTION
147 // add station pulls
149 int ista = i / TL1TrackParameters::NParameters - 1;
150 TString name = "pull_sta";
151 name += ista;
152 name += "_";
154 histoPull[i] = new TH1F(name, name, 50, -10, 10);
155 }
156#endif // BUILD_HISTO_FOR_EACH_STANTION
157 // add global residuals
158 for (int i = 0; i < TL1TrackParameters::NParameters; i++) {
159 TString name = "residual_";
160 name += L1TrackParametersNames[i];
161 float size = 10;
162 switch (i) {
163 case 0:
164 size = .01;
165 break;
166 case 1:
167 size = .01;
168 break;
169 case 2:
170 size = 0.003;
171 break;
172 case 3:
173 size = 0.003;
174 break;
175 case 4:
176 size = 0.1;
177 break;
178 };
179 histoRes[i] = new TH1F(name, name, 50, -size, size);
180 }
181
182 // define style
183 histoStyle = new TStyle("histoStyle", "Plain Style(no colors/fill areas)");
184
185 histoStyle->SetTextFont(textFont);
186 histoStyle->SetPadColor(0);
187 histoStyle->SetCanvasColor(0);
188 histoStyle->SetTitleColor(0);
189 histoStyle->SetStatColor(0);
190
191 histoStyle->SetOptTitle(0); // without main up title
192 histoStyle->SetOptStat(1000001010);
193 // The parameter mode can be = ksiourmen (default = 000001111)
194 // k = 1; kurtosis printed
195 // k = 2; kurtosis and kurtosis error printed
196 // s = 1; skewness printed
197 // s = 2; skewness and skewness error printed
198 // i = 1; integral of bins printed
199 // o = 1; number of overflows printed
200 // u = 1; number of underflows printed
201 // r = 1; rms printed
202 // r = 2; rms and rms error printed
203 // m = 1; mean value printed
204 // m = 2; mean and mean error values printed
205 // e = 1; number of entries printed
206 // n = 1; name of histogram is printed
207
208 histoStyle->SetOptFit(10001);
209 // The parameter mode can be = pcev (default = 0111)
210 // p = 1; print Probability
211 // c = 1; print Chisquare/Number of degress of freedom
212 // e = 1; print errors (if e=1, v must be 1)
213 // v = 1; print name/values of parameters
214
215 histoStyle->SetStatW(0.175);
216 histoStyle->SetStatH(0.02);
217 histoStyle->SetStatX(0.95);
218 histoStyle->SetStatY(0.97);
219 histoStyle->SetStatFontSize(0.05);
220
221 histoStyle->SetStatFont(textFont);
222
223 // gDirectory->cd("..");
224 // curdir->cd();
225 first_call = 0;
226 }
227};
228
229// inline void L1AlgoPulls::AddVec(L1TrackPar& T_, THitI ih)
230// {
231// for (int i = 0; i < fvecLen; i++)
232// AddOne(T_,i,ih);
233// }
234
235inline void L1AlgoPulls::AddOne(L1TrackPar& T_, int i, THitI ih)
236{
237 fNAllPulls++;
238 TL1TrackParameters T(T_, i);
239
240 if (T_.chi2[i] > csCut * T_.NDF[i])
241 return;
242 // get error
244 if (!(finite(T_.C00[i]) && T_.C00[i] > 0))
245 return;
246 if (!(finite(T_.C11[i]) && T_.C11[i] > 0))
247 return;
248 if (!(finite(T_.C22[i]) && T_.C22[i] > 0))
249 return;
250 if (!(finite(T_.C33[i]) && T_.C33[i] > 0))
251 return;
252 if (!(finite(T_.C44[i]) && T_.C44[i] > 0))
253 return;
254 err.x = sqrt(T_.C00[i]);
255 err.y = sqrt(T_.C11[i]);
256 err.tx = sqrt(T_.C22[i]);
257 err.ty = sqrt(T_.C33[i]);
258 err.qp = sqrt(T_.C44[i]);
259
260 // mc data
261 int iMCP = fL1->vHitMCRef[ih];
262 if (iMCP < 0)
263 return;
264 CbmL1MCPoint& mcP = fL1->vMCPoints[iMCP];
265 TL1TrackParameters mc(mcP);
266
267 // fill residuals
268 TL1TrackParameters res = (mc - T);
269 fGRes.push_back(res);
270
271 // fill pulls
272 TL1TrackParameters P = res / err;
273 fGPulls.push_back(P);
274
275#ifdef BUILD_HISTO_FOR_EACH_STANTION
276 int ista = mcP.iStation - 2; // last hit
277 // int ista = fL1->algo->vSFlag[ fL1->algo->vStsHits[ih].f ]/4 - 2; // last hit
278 fStaPulls[ista].push_back(P);
279#endif // BUILD_HISTO_FOR_EACH_STANTION
280};
281
283{ // TODO: renew
284 cout << "All pulls: " << fNAllPulls << endl;
285 cout << "Correct pulls: " << fGPulls.size() << endl;
286 cout << "x y tx ty qp" << endl;
287 for (int i = 0; i < fGPulls.size(); i++) {
289 pull.Print();
290 }
291};
292
293inline void L1AlgoPulls::Build(bool draw)
294{
295 // --- fill histograms ---
296 // global pulls
297 for (int i = 0; i < fGPulls.size(); i++) {
299 for (int ih = 0; ih < TL1TrackParameters::NParameters; ih++) {
300 if (TailCut > fabs(pull[ih]))
301 histoPull[ih]->Fill(pull[ih]);
302 }
303 }
304#ifdef BUILD_HISTO_FOR_EACH_STANTION
305 // station pulls
306 for (int iSta = 0; iSta < NStations; iSta++) {
307 vector<TL1TrackParameters>& Pulls = fStaPulls[iSta];
308 for (int i = 0; i < Pulls.size(); i++) {
309 TL1TrackParameters& pull = Pulls[i];
310 for (int ih = 0; ih < TL1TrackParameters::NParameters; ih++) {
311 if (TailCut > fabs(pull[ih]))
312 histoPull[(iSta + 1) * TL1TrackParameters::NParameters + ih]->Fill(pull[ih]);
313 }
314 }
315 }
316#endif // BUILD_HISTO_FOR_EACH_STANTION
317
318 // global residuals
319 for (int i = 0; i < fGRes.size(); i++) {
320 TL1TrackParameters& res = fGRes[i];
321 for (int ih = 0; ih < TL1TrackParameters::NParameters; ih++) {
322 if (TailCut > fabs(res[ih]))
323 histoRes[ih]->Fill(res[ih]);
324 }
325 }
326
327 // --- draw histograms --- and save info
328 float pulls[(NStations + 1) * TL1TrackParameters::NParameters][2], // 0 - sigma, 1 - RMS
329 residuals[(NStations + 1) * TL1TrackParameters::NParameters][2];
330
331 system("mkdir L1_Pulls -p");
332 chdir("L1_Pulls");
333 TCanvas* c2 = new TCanvas("c2", "c2", 0, 0, 600, 400);
334 c2->cd();
335 histoStyle->cd();
336 for (int ih = 0; ih < (NStations + 1) * TL1TrackParameters::NParameters; ih++) {
337 makeUpHisto(histoPull[ih], histoPull[ih]->GetName(), pulls[ih][0]);
338 pulls[ih][1] = histoPull[ih]->GetRMS();
339 if (draw) {
340 histoPull[ih]->Draw();
341 TString name = histoPull[ih]->GetName();
342 name += ".pdf";
343 c2->SaveAs(name);
344 }
345 }
346 for (int ih = 0; ih < (0 + 1) * TL1TrackParameters::NParameters; ih++) {
347 makeUpHisto(histoRes[ih], histoRes[ih]->GetName(), residuals[ih][0]);
348 residuals[ih][1] = histoRes[ih]->GetRMS();
349 if (draw) {
350 histoRes[ih]->Draw();
351 TString name = histoRes[ih]->GetName();
352 name += ".pdf";
353 c2->SaveAs(name);
354 }
355 }
356 chdir("..");
357
358 // --- print information ---
359 cout << "All entries: " << fNAllPulls << endl;
360 cout << "Correct entries: " << fGPulls.size() << endl;
361 cout << "Pulls sigma & RMS: " << endl;
362 for (int ih = 0; ih < (NStations + 1) * TL1TrackParameters::NParameters; ih++) {
363 int ipar = ih % TL1TrackParameters::NParameters;
364 int ista = ih / TL1TrackParameters::NParameters;
365 if ((ista > 0) && (ipar == 0))
366 cout << "Station " << ista - 1 << endl;
367 cout << L1TrackParametersNames[ipar] << "\t" << pulls[ih][0] << "\t" << pulls[ih][1] << endl;
368 }
369 cout << "Residuals sigma & RMS: " << endl;
370 for (int ih = 0; ih < (0 + 1) * TL1TrackParameters::NParameters; ih++) {
371 int ipar = ih % TL1TrackParameters::NParameters;
372 cout << L1TrackParametersNames[ipar] << "\t" << residuals[ih][0] << "\t" << residuals[ih][1] << endl;
373 }
374};
375
376inline void L1AlgoPulls::makeUpHisto(TH1* hist, TString title, float& sigma)
377{
378 if (hist && (hist->GetEntries() != 0)) {
379 TF1* fit = new TF1("fit", "gaus");
380 fit->SetLineColor(2);
381 fit->SetLineWidth(3);
382 hist->Fit("fit", "", "", hist->GetXaxis()->GetXmin(), hist->GetXaxis()->GetXmax());
383 sigma = fit->GetParameter(2);
384
389
390 hist->GetXaxis()->SetTitle(title);
391 hist->GetXaxis()->SetTitleOffset(1);
392 hist->GetYaxis()->SetTitle("Entries");
393 hist->GetYaxis()->SetTitleOffset(1.05); // good then entries per bit <= 9999
394 } else {
395 std::cout << " E: Read hists error! " << std::endl;
396 }
397}
398
399#endif
const int NStations
Definition L1AlgoPulls.h:9
const TString L1TrackParametersNames[TL1TrackParameters::NParameters]
Definition L1AlgoPulls.h:89
void Pulls(int i, int j, int k, double *mc, L1TrackPar &T, fvec qp0, L1FieldRegion &fld)
Definition L1CADebug.h:14
unsigned int THitI
Definition L1StsHit.h:6
friend F32vec4 fabs(const F32vec4 &a)
Definition P4_F32vec4.h:52
int i
Definition P4_F32vec4.h:22
Definition CbmL1.h:48
static CbmL1 * Instance()
reconstructed tracks
Definition CbmL1.h:59
static const float TailCut
vector< TL1TrackParameters > fGPulls
vector< TL1TrackParameters > fStaPulls[NStations]
void makeUpHisto(TH1 *hist, TString title, float &sigma)
TStyle * histoStyle
vector< TL1TrackParameters > fGRes
CbmL1 * fL1
TH1F * histoPull[(1+NStations) *TL1TrackParameters::NParameters]
static const float csCut
void AddOne(L1TrackPar &T, int i, THitI ih)
void Build(bool draw=1)
TH1F * histoRes[(1+NStations) *TL1TrackParameters::NParameters]
static const int textFont
virtual void SetTitleOffset(Float_t offset=1)
virtual void SetTitleFont(Style_t font=62)
virtual void SetLabelFont(Style_t font=62)
virtual void SetLineWidth(Width_t lwidth)
virtual void SetLineColor(Color_t lcolor)
Double_t GetXmax() const
Double_t GetXmin() const
TVirtualPad * cd(Int_t subpadnumber=0) override
virtual Double_t GetParameter(const TString &name) const
TAxis * GetXaxis()
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Double_t xmin=0, Double_t xmax=0)
TAxis * GetYaxis()
virtual Double_t GetEntries() const
virtual void SetTitle(const char *title="")
void SaveAs(const char *filename="", Option_t *option="") const override
RVec< PromoteType< T > > sqrt(const RVec< T > &v)
TL1TrackParameters(L1TrackPar &T, int i)
Definition L1AlgoPulls.h:35
TL1TrackParameters(CbmL1MCPoint &T)
Definition L1AlgoPulls.h:41
TL1TrackParameters operator-(TL1TrackParameters &b)
Definition L1AlgoPulls.h:64
static const int NParameters
Definition L1AlgoPulls.h:32
double operator[](int i)
Definition L1AlgoPulls.h:48
TL1TrackParameters operator/(TL1TrackParameters &b)
Definition L1AlgoPulls.h:75