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