1 |
#ifndef CALOAXIS2_H_ |
2 |
#define CALOAXIS2_H_ |
3 |
|
4 |
#if !defined(__CINT__) || defined(__MAKECINT__) |
5 |
|
6 |
#include <TString.h> |
7 |
#include <TH1F.h> |
8 |
#include <TH2F.h> |
9 |
#include <TMath.h> |
10 |
#include <TLine.h> |
11 |
#include <TPolyMarker.h> |
12 |
#include <TSelector.h> |
13 |
#include <TFile.h> |
14 |
|
15 |
#include <stdlib.h> |
16 |
#include <iostream> |
17 |
using namespace std; |
18 |
|
19 |
#include <PamLevel2.h> |
20 |
//#include <CaloEvent.h> |
21 |
|
22 |
#endif // !defined(__CINT__) || defined(__MAKECINT__) |
23 |
//=============================================================================== |
24 |
// |
25 |
// |
26 |
// |
27 |
// |
28 |
//=============================================================================== |
29 |
class CaloEvent { |
30 |
|
31 |
public: |
32 |
// calo event |
33 |
// ------------------------------ |
34 |
// hit strips |
35 |
// ------------------------------ |
36 |
vector<int> ids; //strip 0-95 |
37 |
vector<int> idp; //plane 0-21 |
38 |
vector<float> q; // signal |
39 |
vector<float> zcoord; |
40 |
vector<float> xycoord; |
41 |
|
42 |
// ------------------------------ |
43 |
// methods |
44 |
// ------------------------------ |
45 |
void Add(int iis, int iip, float fq, float fz, float fxy) { |
46 |
ids.push_back(iis); |
47 |
idp.push_back(iip); |
48 |
q.push_back(fq); |
49 |
zcoord.push_back(fz); |
50 |
xycoord.push_back(fxy); |
51 |
} |
52 |
; |
53 |
|
54 |
int GetN() { |
55 |
return (int) (q.size()); |
56 |
} |
57 |
; |
58 |
|
59 |
void Reset() { |
60 |
ids.clear(); |
61 |
idp.clear(); |
62 |
q.clear(); |
63 |
zcoord.clear(); |
64 |
xycoord.clear(); |
65 |
} |
66 |
; |
67 |
|
68 |
void Delete() { |
69 |
Reset(); |
70 |
} |
71 |
; |
72 |
|
73 |
~CaloEvent() { |
74 |
Delete(); |
75 |
} |
76 |
; |
77 |
|
78 |
CaloEvent() { |
79 |
} |
80 |
; |
81 |
|
82 |
CaloEvent(CaloLevel1* calo, int view, Bool_t usemechanicalalignement) { |
83 |
Set(calo, view, usemechanicalalignement); |
84 |
} |
85 |
; |
86 |
|
87 |
CaloEvent(CaloLevel1* calo, int view) { |
88 |
Set(calo, view); |
89 |
} |
90 |
; |
91 |
|
92 |
void Set(CaloLevel1* calo, int view, Bool_t usemechanicalalignement) { |
93 |
|
94 |
Reset(); |
95 |
// cout << " CaloEvent::Set()"<<endl; |
96 |
CaloStrip cstrip; |
97 |
cstrip = CaloStrip(calo, usemechanicalalignement); |
98 |
|
99 |
for (int ih = 0; ih < calo->istrip; ih++) { |
100 |
int iv = -1; |
101 |
int ip = -1; |
102 |
int is = -1; |
103 |
calo->DecodeEstrip(ih, iv, ip, is); |
104 |
if (iv == view) { |
105 |
cstrip.Set(view, ip, is); |
106 |
float fxy = 0.; |
107 |
if (!view) |
108 |
fxy = cstrip.GetX(); |
109 |
else |
110 |
fxy = cstrip.GetY(); |
111 |
float fz = cstrip.GetZ(); |
112 |
float fq = cstrip.GetE(); |
113 |
if (fq > 0) |
114 |
Add(is, ip, fq, fz, fxy); |
115 |
} |
116 |
} |
117 |
|
118 |
} |
119 |
; |
120 |
void Set(CaloLevel1* calo, int view) { |
121 |
Set(calo, view, 0); |
122 |
} |
123 |
; |
124 |
|
125 |
}; |
126 |
//=============================================================================== |
127 |
// |
128 |
// |
129 |
// |
130 |
// |
131 |
//=============================================================================== |
132 |
class CaloAxis { |
133 |
|
134 |
public: |
135 |
|
136 |
CaloEvent *cevent; |
137 |
|
138 |
// ------------------------------ |
139 |
// selected points along the axis |
140 |
// ------------------------------ |
141 |
// fitted points |
142 |
vector<float> x;// independent coordinates (z) |
143 |
vector<float> y;// dependente coordinate (x/y) |
144 |
vector<float> w;// fit weight |
145 |
vector<float> q;// signal |
146 |
|
147 |
// ------------------------------ |
148 |
// axis parameters |
149 |
// ------------------------------ |
150 |
Float_t par[2]; |
151 |
Float_t covpar[2][2]; |
152 |
|
153 |
// ------------------------------ |
154 |
// general variables |
155 |
// ------------------------------ |
156 |
float cog[22];// baricenter |
157 |
float qpl[22]; // charge in each plane |
158 |
|
159 |
// ------------------------------ |
160 |
// objects to draw the axis |
161 |
// ------------------------------ |
162 |
TPolyMarker *sel; |
163 |
TLine *axis; |
164 |
|
165 |
// ------------------------------ |
166 |
// methods |
167 |
// ------------------------------ |
168 |
void Init() { |
169 |
for (Int_t i = 0; i < 2; i++) { |
170 |
par[i] = 0; |
171 |
for (Int_t j = 0; j < 2; j++) |
172 |
covpar[i][j] = 0; |
173 |
}; |
174 |
sel = 0; |
175 |
axis = 0; |
176 |
for (Int_t i = 0; i < 22; i++) { |
177 |
cog[i] = 0; |
178 |
qpl[i] = 0; |
179 |
} |
180 |
// if(cevent)cevent->Reset(); |
181 |
} |
182 |
|
183 |
void Set(CaloLevel1* calo, Int_t view) { |
184 |
cevent->Set(calo, view, 0); |
185 |
} |
186 |
; |
187 |
void Set(CaloLevel1* calo, Int_t view, Bool_t usemechanicalalignement) { |
188 |
cevent->Set(calo, view, usemechanicalalignement); |
189 |
} |
190 |
; |
191 |
|
192 |
CaloAxis() { |
193 |
cevent = new CaloEvent(); |
194 |
Init(); |
195 |
} |
196 |
; |
197 |
|
198 |
CaloAxis(CaloLevel1* calo, Int_t view) { |
199 |
cevent = new CaloEvent(); |
200 |
Init(); |
201 |
Set(calo, view); |
202 |
} |
203 |
; |
204 |
CaloAxis(CaloLevel1* calo, Int_t view, Bool_t usemechanicalalignement) { |
205 |
cevent = new CaloEvent(); |
206 |
Init(); |
207 |
Set(calo, view, usemechanicalalignement); |
208 |
} |
209 |
; |
210 |
|
211 |
void Reset() { |
212 |
// cout << " CaloAxis::Reset()"<<endl; |
213 |
x.clear(); |
214 |
y.clear(); |
215 |
w.clear(); |
216 |
q.clear(); |
217 |
// cout << sel << endl; |
218 |
if (sel) |
219 |
sel->Delete(); |
220 |
// cout << axis << endl; |
221 |
if (axis) |
222 |
axis->Delete(); |
223 |
// if(cevent)cevent->Reset(); |
224 |
Init(); |
225 |
} |
226 |
|
227 |
void Delete() { |
228 |
Reset(); |
229 |
delete cevent; |
230 |
} |
231 |
; |
232 |
|
233 |
~CaloAxis() { |
234 |
Delete(); |
235 |
} |
236 |
; |
237 |
|
238 |
void Add(float xin, float yin) { |
239 |
x.push_back(xin); |
240 |
y.push_back(yin); |
241 |
w.push_back(1.); |
242 |
q.push_back(0.); |
243 |
/* Int_t nin = x.size(); */ |
244 |
/* if(nin>2)Fit(); */ |
245 |
} |
246 |
; |
247 |
void Add(float xin, float yin, float qin) { |
248 |
x.push_back(xin); |
249 |
y.push_back(yin); |
250 |
q.push_back(qin); |
251 |
w.push_back(1.); |
252 |
/* Int_t nin = x.size(); */ |
253 |
/* if(nin>2)Fit(); */ |
254 |
} |
255 |
; |
256 |
void Add(float xin, float yin, float qin, float win) { |
257 |
x.push_back(xin); |
258 |
y.push_back(yin); |
259 |
w.push_back(win); |
260 |
q.push_back(qin); |
261 |
/* Int_t nin = x.size(); */ |
262 |
/* if(nin>2)Fit(); */ |
263 |
} |
264 |
; |
265 |
|
266 |
int Fit() { |
267 |
|
268 |
// cout << " CaloAxis::Fit()"<<endl; |
269 |
Float_t SSS = 0; |
270 |
Float_t SSX = 0; |
271 |
Float_t SXX = 0; |
272 |
|
273 |
Float_t SSY = 0; |
274 |
Float_t SXY = 0; |
275 |
|
276 |
Int_t np = 0; |
277 |
for (Int_t i = 0; i < (int) (x.size()); i++) { |
278 |
SSS += w[i] * w[i]; |
279 |
SSX += x[i] * w[i] * w[i]; |
280 |
SXX += x[i] * x[i] * w[i] * w[i]; |
281 |
SSY += y[i] * w[i] * w[i]; |
282 |
SXY += x[i] * y[i] * w[i] * w[i]; |
283 |
if (w[i]) |
284 |
np++; |
285 |
} |
286 |
Float_t det = SSS * SXX - SSX * SSX; |
287 |
if (det == 0) |
288 |
return 0; |
289 |
if (np < 3) |
290 |
return 0; |
291 |
// cout << np << " points fitted -- ok "<<endl; |
292 |
par[0] = (SSY * SXX - SXY * SSX) / det; |
293 |
par[1] = (SXY * SSS - SSY * SSX) / det; |
294 |
return 1; |
295 |
} |
296 |
; |
297 |
|
298 |
void Print() { |
299 |
// useful for debug for(Int_t i=0; i<(int)(x.size()); i++)if(w[i])cout << x[i] << " - "<<y[i]<<endl; |
300 |
} |
301 |
|
302 |
float GetPar(Int_t i) { |
303 |
return par[i]; |
304 |
} |
305 |
; |
306 |
|
307 |
int GetN() { |
308 |
return (int) (x.size()); |
309 |
} |
310 |
; |
311 |
|
312 |
float* GetX() { |
313 |
float *xout = new float[(int) (x.size())]; |
314 |
for (Int_t i = 0; i < (int) (x.size()); i++) |
315 |
xout[i] = x[i]; |
316 |
return xout; |
317 |
} |
318 |
|
319 |
float* GetY() { |
320 |
float *yout = new float[(int) (y.size())]; |
321 |
for (Int_t i = 0; i < (int) (y.size()); i++) |
322 |
yout[i] = y[i]; |
323 |
return yout; |
324 |
} |
325 |
|
326 |
float* GetQ() { |
327 |
float *qout = new float[(int) (q.size())]; |
328 |
for (int i = 0; i < (int) (q.size()); i++) |
329 |
qout[i] = q[i]; |
330 |
return qout; |
331 |
} |
332 |
|
333 |
float GetChi2() { |
334 |
float chi2 = 0; |
335 |
int nchi = 0; |
336 |
for (Int_t i = 0; i < (int) (y.size()); i++) { |
337 |
chi2 += w[i] * w[i] * (y[i] - par[0] - par[1] * x[i]) * (y[i] - par[0] - par[1] * x[i]); |
338 |
nchi += (int) w[i]; |
339 |
}; |
340 |
|
341 |
if (nchi < 3) |
342 |
return -999; // original |
343 |
// if(nchi<3 || chi2==0)return -999; // modified by Sergio |
344 |
|
345 |
chi2 = chi2 / (nchi - 2); |
346 |
return chi2; |
347 |
} |
348 |
|
349 |
float GetQaxis() { |
350 |
float qaxis = 0; |
351 |
for (Int_t i = 0; i < (int) (q.size()); i++) |
352 |
qaxis += q[i]; |
353 |
// for(Int_t i=0; i<(int)(q.size()); i++) cout<<q[i]<<endl; |
354 |
return qaxis; |
355 |
} |
356 |
|
357 |
float GetQaxis(float toll) { |
358 |
float qaxis = 0; |
359 |
for (int ih = 0; ih < cevent->GetN(); ih++) { |
360 |
float x = cevent->xycoord[ih]; |
361 |
float z = cevent->zcoord[ih]; |
362 |
float q = cevent->q[ih]; |
363 |
//int ip = cevent->idp[ih]; |
364 |
float d = fabs(x - par[0] - par[1] * z) / sqrt(par[1] * par[1] + 1); |
365 |
if (d < toll) |
366 |
qaxis += q; |
367 |
} |
368 |
return qaxis; |
369 |
} |
370 |
|
371 |
float GetCOG(Int_t ip) { |
372 |
if (ip >= 0 && ip < 22) |
373 |
return cog[ip]; |
374 |
else |
375 |
return 0; |
376 |
} |
377 |
|
378 |
float GetQ(Int_t ip) { |
379 |
if (ip >= 0 && ip < 22) |
380 |
return qpl[ip]; |
381 |
else |
382 |
return 0; |
383 |
} |
384 |
|
385 |
float GetQstrip() { |
386 |
|
387 |
float qaxis = 0; |
388 |
for (Int_t i = 0; i < (int) (q.size()); i++) |
389 |
qaxis += q[i]; |
390 |
if (q.size() == 0) |
391 |
return 0.; |
392 |
return qaxis / q.size(); |
393 |
} |
394 |
|
395 |
float GetYfit(float x) { |
396 |
return par[0] + x * par[1]; |
397 |
} |
398 |
|
399 |
float GetXmin() { |
400 |
float zmin = 9999; |
401 |
for (Int_t i = 0; i < (int) (x.size()); i++) |
402 |
if (x[i] < zmin) |
403 |
zmin = x[i]; |
404 |
return zmin; |
405 |
} |
406 |
float GetXmax() { |
407 |
float zmax = -9999; |
408 |
for (Int_t i = 0; i < (int) (x.size()); i++) |
409 |
if (x[i] > zmax) |
410 |
zmax = x[i]; |
411 |
return zmax; |
412 |
|
413 |
} |
414 |
|
415 |
void Draw() { |
416 |
|
417 |
// cout << " CaloAxis::Draw()"<<endl; |
418 |
if (GetN() < 3) |
419 |
return; |
420 |
|
421 |
sel = new TPolyMarker(GetN(), GetY(), GetX()); |
422 |
sel->SetMarkerSize(0.3); |
423 |
sel->SetMarkerColor(5); |
424 |
|
425 |
axis = new TLine(par[0] + GetXmin() * par[1], GetXmin(), par[0] + GetXmax() * par[1], GetXmax()); |
426 |
axis->SetLineWidth(1); |
427 |
axis->SetLineColor(5); |
428 |
|
429 |
// cout << sel << endl; |
430 |
// cout << axis << endl; |
431 |
|
432 |
sel->Draw(); |
433 |
axis->Draw(); |
434 |
} |
435 |
; |
436 |
|
437 |
//----------------------------------------------------------------- |
438 |
// fit the axis (optimized for non-interacting patterns) |
439 |
//----------------------------------------------------------------- |
440 |
int FitAxis(CaloLevel1* calo, Int_t view, Float_t toll, Int_t nPlanes = 22, Bool_t usemechanicalalignement = 0) { |
441 |
|
442 |
// cout << "CaloAxis::FitAxis(...)"<<endl; |
443 |
|
444 |
Set(calo, view, usemechanicalalignement); |
445 |
|
446 |
// ------------------------------ |
447 |
// first : all hits included, w=1 |
448 |
// ------------------------------ |
449 |
for (int ih = 0; ih < cevent->GetN(); ih++) { |
450 |
float x = cevent->xycoord[ih]; |
451 |
float z = cevent->zcoord[ih]; |
452 |
float q = cevent->q[ih]; |
453 |
Add(z, x, q); |
454 |
} |
455 |
|
456 |
if (GetN() < 3) |
457 |
return 0; |
458 |
Fit(); |
459 |
// useful for debug cout << "(1)"<<endl; |
460 |
// cout << " n. hits :"<<GetN()<<endl; |
461 |
// cout << " P0 P1 :"<<par[0]<< " "<<par[1]<<endl; |
462 |
// cout << " Chi2 :"<<GetChi2()<<endl; |
463 |
// cout << " Q axis :"<<GetQaxis()<<endl; |
464 |
// cout << " Q strip :"<<GetQstrip()<<endl; |
465 |
|
466 |
float P0; |
467 |
float P1; |
468 |
int dof; |
469 |
|
470 |
// --------------------------- |
471 |
// second : iteration |
472 |
// --------------------------- |
473 |
int niter = 0; // number of iterations |
474 |
int pok[nPlanes]; |
475 |
|
476 |
// prova |
477 |
// pesi lineari |
478 |
float W22 = 1.; |
479 |
float W1 = 10.; |
480 |
float b = (W22 - W1) / ((float) nPlanes - 1.);// (w22 - w1)/(22-1) |
481 |
float a = W1 - b; |
482 |
|
483 |
for (int i = 0; i < nPlanes; i++) |
484 |
pok[i] = 0; |
485 |
do { |
486 |
niter++; |
487 |
float ttoll = toll; //tolerance (cm) |
488 |
if (niter == 1) |
489 |
ttoll = 10. * toll; |
490 |
dof = GetN(); //previous fit |
491 |
P0 = par[0]; |
492 |
P1 = par[1]; |
493 |
Reset(); //fit reset |
494 |
for (int ih = 0; ih < cevent->GetN(); ih++) {//loop over selected hits |
495 |
if (cevent->idp[ih] < nPlanes) { |
496 |
float x = cevent->xycoord[ih]; |
497 |
float z = cevent->zcoord[ih]; |
498 |
float q = cevent->q[ih]; |
499 |
int ip = cevent->idp[ih]; |
500 |
float d = fabs(x - P0 - P1 * z) / sqrt(P1 * P1 + 1);//distance to axis |
501 |
// cout<<d<<endl; |
502 |
if (d < ttoll && (niter == 1 || (niter > 1 && pok[ip] == 1))) { |
503 |
// if( d < ttoll ){ |
504 |
float W = a + b * (ip + 1); |
505 |
// cout << ip << " "<<W<<endl; |
506 |
Add(z, x, q, W); |
507 |
pok[ip] = 1; |
508 |
} |
509 |
} |
510 |
} |
511 |
// break the track if more than 3 planes are missing |
512 |
int nmissing = 0; |
513 |
for (int ip = 0; ip < nPlanes; ip++) { |
514 |
if (pok[ip] == 0) { |
515 |
nmissing++; |
516 |
} |
517 |
else { |
518 |
nmissing = 0; |
519 |
} |
520 |
if (nmissing == 3) { |
521 |
for (int ipp = ip + 1; ipp < nPlanes; ipp++) |
522 |
pok[ipp] = 0; |
523 |
break; |
524 |
} |
525 |
} |
526 |
|
527 |
if (niter == 100) |
528 |
break; |
529 |
if (GetN() < 3) |
530 |
break; |
531 |
Fit(); |
532 |
} while (niter == 1 || GetN() != dof); |
533 |
// cout << " >>> "<<GetN()<<endl; |
534 |
if (GetN() < 3) |
535 |
return 0; |
536 |
Fit(); |
537 |
// cout << "(2)"<<endl; |
538 |
// cout << " n. hits :"<<GetN()<<endl; |
539 |
// cout << " P0 P1 :"<<par[0]<< " "<<par[1]<<endl; |
540 |
// cout << " Chi2 :"<<GetChi2()<<endl; |
541 |
// cout << " Q axis :"<<GetQaxis()<<endl; |
542 |
// cout << " Q strip :"<<GetQstrip()<<endl; |
543 |
|
544 |
// --------------------------------------------- |
545 |
// third : selecting only closest strip-clusters |
546 |
// and fit baricenters |
547 |
// --------------------------------------------- |
548 |
P0 = par[0]; |
549 |
P1 = par[1]; |
550 |
Reset(); |
551 |
|
552 |
float dmin[nPlanes]; |
553 |
int closest[nPlanes]; |
554 |
for (int ip = 0; ip < nPlanes; ip++) { |
555 |
dmin[ip] = 999; |
556 |
closest[ip] = -1; |
557 |
} |
558 |
for (int ih = 0; ih < cevent->GetN(); ih++) { |
559 |
if (cevent->idp[ih] < nPlanes) { |
560 |
float x = cevent->xycoord[ih]; |
561 |
float z = cevent->zcoord[ih]; |
562 |
//float q = cevent->q[ih]; |
563 |
int ip = cevent->idp[ih]; |
564 |
//int is = cevent->ids[ih]; |
565 |
float d = fabs(x - P0 - P1 * z) / sqrt(P1 * P1 + 1); |
566 |
if (d < toll && d < dmin[ip] && pok[ip] == 1) { |
567 |
// Add(z,x,q,q); |
568 |
closest[ip] = ih; |
569 |
// cog[ip] += x*q; |
570 |
// qpl[ip] += q; |
571 |
} |
572 |
} |
573 |
} |
574 |
for (Int_t ip = 0; ip < nPlanes; ip++) { |
575 |
if (closest[ip] != -1) { |
576 |
float x = cevent->xycoord[closest[ip]]; |
577 |
float z = cevent->zcoord[closest[ip]]; |
578 |
float q = cevent->q[closest[ip]]; |
579 |
//int is = cevent->ids[closest[ip]]; |
580 |
Add(z, x, q, q); |
581 |
cog[ip] += x * q; |
582 |
qpl[ip] += q; |
583 |
// cout << ip << " -o- "<<is<<endl; |
584 |
} |
585 |
} |
586 |
// ----------------- |
587 |
// add +/- one strip |
588 |
// ----------------- |
589 |
for (int ih = 0; ih < cevent->GetN(); ih++) { |
590 |
if (cevent->idp[ih] < nPlanes) { |
591 |
float x = cevent->xycoord[ih]; |
592 |
float z = cevent->zcoord[ih]; |
593 |
float q = cevent->q[ih]; |
594 |
int ip = cevent->idp[ih]; |
595 |
int is = cevent->ids[ih]; |
596 |
if (closest[ip] != -1) { |
597 |
int isc = cevent->ids[closest[ip]]; |
598 |
if (is == isc + 1 || is == isc - 1) { |
599 |
Add(z, x, q, q); |
600 |
cog[ip] += x * q; |
601 |
qpl[ip] += q; |
602 |
// cout << ip << " -+- "<<is<<endl; |
603 |
} |
604 |
}} |
605 |
} |
606 |
Fit(); |
607 |
|
608 |
if (GetN() < 3) |
609 |
return 0; |
610 |
for (int ip = 0; ip < nPlanes; ip++) { |
611 |
if (qpl[ip] != 0) { |
612 |
cog[ip] = cog[ip] / qpl[ip]; |
613 |
// Add(z,cog[ip],cog[ip],0.7); |
614 |
} |
615 |
} |
616 |
|
617 |
// cout << "(3)"<<endl; |
618 |
// cout << " n. hits :"<<GetN()<<endl; |
619 |
// cout << " P0 P1 :"<<par[0]<< " "<<par[1]<<endl; |
620 |
// cout << " Chi2 :"<<GetChi2()<<endl; |
621 |
// cout << " Q axis :"<<GetQaxis()<<endl; |
622 |
// cout << " Q strip :"<<GetQstrip()<<endl; |
623 |
// cout << " ---------------------------"<<endl; |
624 |
return 1; |
625 |
} |
626 |
; |
627 |
|
628 |
/*int FitAxis(CaloLevel1* calo, Int_t view, Float_t toll, Int_t nPlanes = 22) { |
629 |
return FitAxis(calo, view, toll, 0, nPlanes); |
630 |
} |
631 |
;*/ |
632 |
|
633 |
//----------------------------------------------------------------- |
634 |
// fit the axis (optimized for interacting patterns?? ...forse) |
635 |
//----------------------------------------------------------------- |
636 |
int FitShower(CaloLevel1* calo, Int_t view, Float_t toll, Bool_t usemechanicalalignement) { |
637 |
|
638 |
// cout << "CaloAxis::FitAxis(...)"<<endl; |
639 |
|
640 |
Set(calo, view, usemechanicalalignement); |
641 |
|
642 |
// ------------------------------ |
643 |
// first : |
644 |
// ------------------------------ |
645 |
for (int ih = 0; ih < cevent->GetN(); ih++) { |
646 |
float x = cevent->xycoord[ih]; |
647 |
//float z = cevent->zcoord[ih]; |
648 |
float q = cevent->q[ih]; |
649 |
int ip = cevent->idp[ih]; |
650 |
cog[ip] += x * q; |
651 |
qpl[ip] += q; |
652 |
// Add(z,x,q); |
653 |
} |
654 |
for (int ip = 0; ip < 22; ip++) { |
655 |
if (qpl[ip] != 0) |
656 |
cog[ip] = cog[ip] / qpl[ip]; |
657 |
// cout << ip << " > "<<qpl[ip]<<" "<<cog[ip]<<endl; |
658 |
} |
659 |
// ---------------- |
660 |
// plane of maximum |
661 |
// ---------------- |
662 |
float qplmax = 1; |
663 |
int ipmax = -1; |
664 |
float dmin[22]; |
665 |
int closest[22]; |
666 |
for (int ip = 0; ip < 22; ip++) |
667 |
if (qpl[ip] > qplmax) { |
668 |
ipmax = ip; |
669 |
qplmax = qpl[ip]; |
670 |
dmin[ip] = 1000.;//init |
671 |
closest[ip] = -1;//init |
672 |
} |
673 |
for (int ih = 0; ih < cevent->GetN(); ih++) { |
674 |
float x = cevent->xycoord[ih]; |
675 |
float z = cevent->zcoord[ih]; |
676 |
float q = cevent->q[ih]; |
677 |
int ip = cevent->idp[ih]; |
678 |
// if( (ipmax>3 && ip<=ipmax) || ipmax<=3 )Add(z,x,q); |
679 |
if (ip <= ipmax || ip <= 3) { |
680 |
Add(z, x, q); |
681 |
} |
682 |
} |
683 |
if (GetN() < 3) |
684 |
return 0; |
685 |
Fit(); |
686 |
// cout << " n. hits :"<<GetN()<<endl; |
687 |
// cout << " P0 P1 :"<<par[0]<< " "<<par[1]<<endl; |
688 |
// cout << " Chi2 :"<<GetChi2()<<endl; |
689 |
// cout << " Q axis :"<<GetQaxis()<<endl; |
690 |
// cout << " Q strip :"<<GetQstrip()<<endl; |
691 |
|
692 |
float P0; |
693 |
float P1; |
694 |
int dof; |
695 |
|
696 |
// --------------------------- |
697 |
// second : iteration |
698 |
// --------------------------- |
699 |
int niter = 0; // number of iterations |
700 |
int pok[22]; |
701 |
// prova |
702 |
// pesi lineari |
703 |
float W22 = 1.; |
704 |
float W1 = 10.; |
705 |
float b = (W22 - W1) / (22. - 1.);// (w22 - w1)/(22-1) |
706 |
float a = W1 - b; |
707 |
|
708 |
for (int i = 0; i < 22; i++) { |
709 |
pok[i] = 0; |
710 |
} |
711 |
do { |
712 |
niter++; |
713 |
float ttoll = toll; //tolerance (cm) |
714 |
if (niter == 1) |
715 |
ttoll = 10. * toll; |
716 |
dof = GetN(); //previous fit |
717 |
P0 = par[0]; |
718 |
P1 = par[1]; |
719 |
Reset(); //fit reset |
720 |
for (int i = 0; i < 22; i++) { |
721 |
cog[i] = 0; |
722 |
qpl[i] = 0; |
723 |
} |
724 |
for (int ih = 0; ih < cevent->GetN(); ih++) { |
725 |
float x = cevent->xycoord[ih]; |
726 |
float z = cevent->zcoord[ih]; |
727 |
float q = cevent->q[ih]; |
728 |
int ip = cevent->idp[ih]; |
729 |
float d = fabs(x - P0 - P1 * z) / sqrt(P1 * P1 + 1); |
730 |
// cout<<d<<endl; |
731 |
if ((niter == 1 || (niter > 1 && pok[ip] == 1)) && (ip <= ipmax || ip <= 3) && |
732 |
// ((ipmax>3 && ip<=ipmax) || ipmax<=3) && |
733 |
true) { |
734 |
|
735 |
if (niter == 1 && d < dmin[ip]) { |
736 |
dmin[ip] = d; |
737 |
closest[ip] = ih; |
738 |
} |
739 |
|
740 |
float W = a + b * (ip + 1); |
741 |
// cout << ip << " "<<W<<endl; |
742 |
if (d < ttoll || (niter == 2 && ih == closest[ip])) { |
743 |
/* if(ip==ipmax && ipmax>1)Add(z,x,q,W*q); */ |
744 |
/* else Add(z,x,q,W); */ |
745 |
cog[ip] += x * q; |
746 |
qpl[ip] += q; |
747 |
Add(z, x, q, W); |
748 |
pok[ip] = 1; |
749 |
cout << ip << " " << qpl[ip] << endl; |
750 |
} |
751 |
} |
752 |
} |
753 |
// break the track if more than 3 planes are missing |
754 |
int nmissing = 0; |
755 |
for (int ip = 0; ip < 22; ip++) { |
756 |
if (pok[ip] == 0) { |
757 |
nmissing++; |
758 |
} |
759 |
else { |
760 |
nmissing = 0; |
761 |
} |
762 |
if (nmissing == 6) { |
763 |
for (int ipp = ip + 1; ipp < 22; ipp++) |
764 |
pok[ipp] = 0; |
765 |
break; |
766 |
} |
767 |
} |
768 |
|
769 |
for (int ip = 0; ip < 22; ip++) |
770 |
cout << qpl[ip] << " "; |
771 |
cout << endl; |
772 |
|
773 |
for (int ip = 0; ip < 22; ip++) |
774 |
if (qpl[ip] != 0) |
775 |
cog[ip] = cog[ip] / qpl[ip]; |
776 |
|
777 |
if (niter == 100) |
778 |
break; |
779 |
if (GetN() < 3) |
780 |
break; |
781 |
|
782 |
Fit(); |
783 |
|
784 |
} while (niter == 1 || GetN() != dof); |
785 |
// cout << " >>> "<<GetN()<<endl; |
786 |
if (GetN() < 3) |
787 |
return 0; |
788 |
Fit(); |
789 |
/* // cout << " n. hits :"<<GetN()<<endl; */ |
790 |
/* // cout << " P0 P1 :"<<par[0]<< " "<<par[1]<<endl; */ |
791 |
/* // cout << " Chi2 :"<<GetChi2()<<endl; */ |
792 |
/* // cout << " Q axis :"<<GetQaxis()<<endl; */ |
793 |
/* // cout << " Q strip :"<<GetQstrip()<<endl; */ |
794 |
|
795 |
/* // --------------------------------------------- */ |
796 |
/* // third : selecting only closest strip-clusters */ |
797 |
/* // and fit baricenters */ |
798 |
/* // --------------------------------------------- */ |
799 |
/* P0 = par[0]; */ |
800 |
/* P1 = par[1]; */ |
801 |
/* Reset(); */ |
802 |
|
803 |
/* float dmin[22]; */ |
804 |
/* int closest[22]; */ |
805 |
/* for(int ip=0; ip<22; ip++){ */ |
806 |
/* dmin[ip]=999; */ |
807 |
/* closest[ip]=-1; */ |
808 |
/* } */ |
809 |
/* for(int ih=0;ih<cevent->GetN(); ih++){ */ |
810 |
/* float x = cevent->xycoord[ih]; */ |
811 |
/* float z = cevent->zcoord[ih]; */ |
812 |
/* float q = cevent->q[ih]; */ |
813 |
/* int ip = cevent->idp[ih]; */ |
814 |
/* int is = cevent->ids[ih]; */ |
815 |
/* float d = fabs(x-P0-P1*z)/sqrt(P1*P1+1); */ |
816 |
/* if( d < toll && d<dmin[ip] && pok[ip]==1 ){ */ |
817 |
/* // Add(z,x,q,q); */ |
818 |
/* closest[ip]=ih; */ |
819 |
/* // cog[ip] += x*q; */ |
820 |
/* // qpl[ip] += q; */ |
821 |
/* } */ |
822 |
/* } */ |
823 |
/* for(Int_t ip=0; ip<22; ip++){ */ |
824 |
/* if(closest[ip]!=-1){ */ |
825 |
/* float x = cevent->xycoord[closest[ip]]; */ |
826 |
/* float z = cevent->zcoord[closest[ip]]; */ |
827 |
/* float q = cevent->q[closest[ip]]; */ |
828 |
/* int is = cevent->ids[closest[ip]]; */ |
829 |
/* Add(z,x,q,q); */ |
830 |
/* cog[ip] += x*q; */ |
831 |
/* qpl[ip] += q; */ |
832 |
/* // cout << ip << " -o- "<<is<<endl; */ |
833 |
/* } */ |
834 |
/* } */ |
835 |
/* // add +/- one strip */ |
836 |
/* for(int ih=0;ih<cevent->GetN(); ih++){ */ |
837 |
/* float x = cevent->xycoord[ih]; */ |
838 |
/* float z = cevent->zcoord[ih]; */ |
839 |
/* float q = cevent->q[ih]; */ |
840 |
/* int ip = cevent->idp[ih]; */ |
841 |
/* int is = cevent->ids[ih]; */ |
842 |
/* if( closest[ip]!=-1 ){ */ |
843 |
/* int isc = cevent->ids[closest[ip]]; */ |
844 |
/* if( is == isc+1 || is == isc-1 ){ */ |
845 |
/* Add(z,x,q,q); */ |
846 |
/* cog[ip] += x*q; */ |
847 |
/* qpl[ip] += q; */ |
848 |
/* // cout << ip << " -+- "<<is<<endl; */ |
849 |
/* } */ |
850 |
/* } */ |
851 |
/* } */ |
852 |
/* Fit(); */ |
853 |
|
854 |
/* if(GetN()<3)return 0; */ |
855 |
/* for(int ip=0; ip<22; ip++){ */ |
856 |
/* if(qpl[ip]!=0){ */ |
857 |
/* cog[ip]=cog[ip]/qpl[ip]; */ |
858 |
/* // Add(z,cog[ip],cog[ip],0.7); */ |
859 |
/* } */ |
860 |
/* } */ |
861 |
|
862 |
// cout << " n. hits :"<<GetN()<<endl; |
863 |
// cout << " P0 P1 :"<<par[0]<< " "<<par[1]<<endl; |
864 |
// cout << " Chi2 :"<<GetChi2()<<endl; |
865 |
// cout << " Q axis :"<<GetQaxis()<<endl; |
866 |
// cout << " Q strip :"<<GetQstrip()<<endl; |
867 |
// cout << " ---------------------------"<<endl; |
868 |
return 1; |
869 |
} |
870 |
; |
871 |
|
872 |
int FitShower(CaloLevel1* calo, Int_t view, Float_t toll) { |
873 |
return FitAxis(calo, view, toll, 0); |
874 |
} |
875 |
; |
876 |
|
877 |
}; |
878 |
|
879 |
//=============================================================================== |
880 |
// |
881 |
// |
882 |
// |
883 |
// |
884 |
//=============================================================================== |
885 |
|
886 |
#endif // CALOAXIS2_H_ |