-
Notifications
You must be signed in to change notification settings - Fork 1
/
R5Detector.cxx
1991 lines (1858 loc) · 72.5 KB
/
R5Detector.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//Bool_t R5Detector::SolveSingleTrack(Double_t mass, Double_t pt, Double_t eta, Double_t phi,
//R5Probe* R5Detector::PrepareKalmanTrack(Double_t pt, Double_t lambda, Double_t mass, int charge, Double_t phi, Double_t x,Double_t y, Double_t z, Double_t t)
#include "R5Detector.h"
#include <TMath.h>
#include <TH1F.h>
#include <TProfile.h>
#include <TF1.h>
#include <TMatrixD.h>
#include <TGraph.h>
#include <TAxis.h>
#include <TFormula.h>
#include <TCanvas.h>
#include <TEllipse.h>
#include <TText.h>
#include <TGraphErrors.h>
#include <TStopwatch.h>
#include <TH2.h>
#include <TH1.h>
#include <TArrayI.h>
#include "AliLog.h"
#include "AliESDVertex.h"
#include "TDatabasePDG.h"
#include "TParticle.h"
/***********************************************************
Fast Simulation tool for Inner Tracker Systems
***********************************************************/
#define dNdEtaMinB 1//950//660//950 // Multiplicity per unit Eta (AuAu MinBias = 170, Central = 700)
// #define dNdEtaCent 2300//15000 //1600//2300 // Multiplicity per unit Eta (LHC at 5.5 TeV not known)
#define UPCBackgroundMultiplier 1.0 // Increase multiplicity in detector (0.0 to 1.0 * UPCRate ) (eg 1.0)
#define OtherBackground 0.0 // Increase multiplicity in detector (0.0 to 1.0 * minBias) (eg 0.0)
// -> ChiSquarePlusConfLevel = 2, ChiSquare = 1, Simple = 0.
#define PionMass 0.139 // Mass of the Pion
#define KaonMass 0.498 // Mass of the Kaon
#define D0Mass 1.865 // Mass of the D0
//TMatrixD *probKomb; // table for efficiency kombinatorics
ClassImp(R5Probe);
Int_t R5Probe::fgNLayers = 0;
Double_t R5Probe::fgMissingHitPenalty = 2.;
//__________________________________________________________________________
R5Probe::R5Probe() :
fHits(0),
fFakes(0),
fNHitsFake(0),
fInnerChecked(-1),
fOuterChecked(-1),
fTOFsignal(0)
{
}
//__________________________________________________________________________
R5Probe& R5Probe::operator=(const R5Probe& src)
{
if (this!=&src) {
AliKalmanTrack::operator=(src);
fHits = src.fHits;
fFakes = src.fFakes;
fNHitsFake = src.fNHitsFake;
fInnerChecked = src.fInnerChecked;
fOuterChecked = src.fOuterChecked;
fTOFsignal = src.fTOFsignal;
}
return *this;
}
//__________________________________________________________________________
R5Probe::R5Probe(R5Probe& src)
: AliKalmanTrack(src),
fHits(src.fHits),
fFakes(src.fFakes),
fNHitsFake(src.fNHitsFake),
fInnerChecked(src.fInnerChecked),
fOuterChecked(src.fOuterChecked),
fTOFsignal(fTOFsignal)
{
}
//__________________________________________________________________________
void R5Probe::Reset()
{
SetMass(PionMass);
SetChi2(0);
fHits = fFakes = 0;
fNHitsFake = 0;
SetNumberOfClusters(0);
fInnerChecked = fOuterChecked = -1;
fTOFsignal = 0;
AliKalmanTrack::Reset();
}
//__________________________________________________________________________
void R5Probe::ResetTrackingInfo()
{
SetMass(PionMass);
SetChi2(0);
fHits = fFakes = 0;
fNHitsFake = 0;
SetNumberOfClusters(0);
ResetCovMat();
StartTimeIntegral();
fTOFsignal = 0;
TObject::Clear(); // to clean bits?
}
//__________________________________________________________________________
void R5Probe::ResetCovMat()
{
// reset errors
Double_t *trCov = (Double_t*)GetCovariance();
Double_t *trPars = (Double_t*)GetParameter();
const Double_t kLargeErr2Coord = 50*50;
const Double_t kLargeErr2Dir = 0.6*0.6;
const Double_t kLargeErr2PtI = 0.5*0.5;
for (int ic=15;ic--;) trCov[ic] = 0.;
trCov[kY2] = trCov[kZ2] = kLargeErr2Coord;
trCov[kSnp2] = trCov[kTgl2] = kLargeErr2Dir;
trCov[kPtI2] = kLargeErr2PtI*trPars[kPtI]*trPars[kPtI];
//
}
//__________________________________________________________________________
void R5Probe::Print(Option_t* option) const
{
printf("M=%.3f Chi2=%7.2f (Norm:%6.2f) Checked: %d-%d, Hits: Total:%d Fakes:%d | Y:%+8.4f Z: %+8.4f LInt: %+.2f TOF: %+e|",
GetMass(),GetChi2(),GetNormChi2(kTRUE),fInnerChecked,fOuterChecked, GetNumberOfClusters(),
fNHitsFake, GetY(),GetZ(),GetIntegratedLength(), fTOFsignal);
for (int i=0;i<fgNLayers;i++) {
if (!IsHit(i)) printf(".");
else printf("%c",IsHitFake(i) ? '-':'+');
}
printf("|%s\n",IsKilled() ? " KILLED":"");
TString opt = option;
if (!opt.IsNull()) AliExternalTrackParam::Print(option);
}
//__________________________________________________________________________
Bool_t R5Probe::GetXatLabR(Double_t r,Double_t &x, Double_t bz, Int_t dir) const
{
// Get local X of the track position estimated at the radius lab radius r.
// The track curvature is accounted exactly
//
// The flag "dir" can be used to remove the ambiguity of which intersection to take (out of 2 possible)
// 0 - take the intersection closest to the current track position
// >0 - go along the track (increasing fX)
// <0 - go backward (decreasing fX)
//
// special case of R=0
if (r<kAlmost0) {x=0; return kTRUE;}
const Double_t* pars = GetParameter();
const Double_t &fy=pars[0], &sn = pars[2];
//
Double_t fx = GetX();
Double_t crv = GetC(bz);
if (TMath::Abs(crv)<=kAlmost0) { // this is a straight track
if (TMath::Abs(sn)>=kAlmost1) { // || to Y axis
Double_t det = (r-fx)*(r+fx);
if (det<0) return kFALSE; // does not reach raduis r
x = fx;
if (dir==0) return kTRUE;
det = TMath::Sqrt(det);
if (dir>0) { // along the track direction
if (sn>0) {if (fy>det) return kFALSE;} // track is along Y axis and above the circle
else {if (fy<-det) return kFALSE;} // track is against Y axis amd belo the circle
}
else if(dir>0) { // agains track direction
if (sn>0) {if (fy<-det) return kFALSE;} // track is along Y axis
else if (fy>det) return kFALSE; // track is against Y axis
}
}
else if (TMath::Abs(sn)<=kAlmost0) { // || to X axis
Double_t det = (r-fy)*(r+fy);
if (det<0) return kFALSE; // does not reach raduis r
det = TMath::Sqrt(det);
if (!dir) {
x = fx>0 ? det : -det; // choose the solution requiring the smalest step
return kTRUE;
}
else if (dir>0) { // along the track direction
if (fx > det) return kFALSE; // current point is in on the right from the circle
else if (fx <-det) x = -det; // on the left
else x = det; // within the circle
}
else { // against the track direction
if (fx <-det) return kFALSE;
else if (fx > det) x = det;
else x = -det;
}
}
else { // general case of straight line
Double_t cs = TMath::Sqrt((1-sn)*(1+sn));
Double_t xsyc = fx*sn-fy*cs;
Double_t det = (r-xsyc)*(r+xsyc);
if (det<0) return kFALSE; // does not reach raduis r
det = TMath::Sqrt(det);
Double_t xcys = fx*cs+fy*sn;
Double_t t = -xcys;
if (dir==0) t += t>0 ? -det:det; // chose the solution requiring the smalest step
else if (dir>0) { // go in increasing fX direction. ( t+-det > 0)
if (t>=-det) t += -det; // take minimal step giving t>0
else return kFALSE; // both solutions have negative t
}
else { // go in increasing fx direction. (t+-det < 0)
if (t<det) t -= det; // take minimal step giving t<0
else return kFALSE; // both solutions have positive t
}
x = fx + cs*t;
}
}
else { // helix
// get center of the track circle
Double_t tR = 1./crv; // track radius (for the moment signed)
Double_t cs = TMath::Sqrt((1-sn)*(1+sn));
Double_t x0 = fx - sn*tR;
Double_t y0 = fy + cs*tR;
Double_t r0 = TMath::Sqrt(x0*x0+y0*y0);
// printf("Xc:%+e Yc:%+e\n",x0,y0);
//
if (r0<=kAlmost0) {
AliDebug(2,Form("r0 = %f",r0));
return kFALSE;
} // the track is concentric to circle
tR = TMath::Abs(tR);
Double_t tR2r0 = tR/r0;
Double_t g = 0.5*(r*r/(r0*tR) - tR2r0 - 1./tR2r0);
Double_t det = (1.-g)*(1.+g);
if (det<0) {
AliDebug(2,Form("g=%f tR=%f r0=%f\n",g,tR, r0));
return kFALSE;
} // does not reach raduis r
det = TMath::Sqrt(det);
//
// the intersection happens in 2 points: {x0+tR*C,y0+tR*S}
// with C=f*c0+-|s0|*det and S=f*s0-+c0 sign(s0)*det
// where s0 and c0 make direction for the circle center (=x0/r0 and y0/r0)
//
Double_t tmp = 1.+g*tR2r0;
x = x0*tmp;
Double_t y = y0*tmp;
if (TMath::Abs(y0)>kAlmost0) { // when y0==0 the x,y is unique
Double_t dfx = tR2r0*TMath::Abs(y0)*det;
Double_t dfy = tR2r0*x0*TMath::Sign(det,y0);
if (dir==0) { // chose the one which corresponds to smallest step
Double_t delta = (x-fx)*dfx-(y-fy)*dfy; // the choice of + in C will lead to smaller step if delta<0
if (delta<0) x += dfx;
else x -= dfx;
}
else if (dir>0) { // along track direction: x must be > fx
x -= dfx; // try the smallest step (dfx is positive)
if (x<fx && (x+=dfx+dfx)<fx) return kFALSE;
}
else { // backward: x must be < fx
x += dfx; // try the smallest step (dfx is positive)
if (x>fx && (x-=dfx+dfx)>fx) return kFALSE;
}
}
else { // special case: track touching the circle just in 1 point
if ( (dir>0&&x<fx) || (dir<0&&x>fx) ) return kFALSE;
}
}
//
return kTRUE;
}
//____________________________________
Bool_t R5Probe::PropagateToR(Double_t r, Double_t b, int dir, Bool_t tof)
{
// go to radius R
//
Double_t xR = 0;
Double_t rr = r*r;
int iter = 0;
const Double_t kTiny = 1e-4;
Double_t rcurr2 = GetX()*GetX() + GetY()*GetY();
if (TMath::Abs(rcurr2 - rr)<kTiny*kTiny) { // just rotate and return
if (rr > kAlmost0 && !Rotate(PhiPos())) {
if (AliLog::GetGlobalDebugLevel()>2) {
printf("Failed to rotate to %f to propagate to R=%f\n",PhiPos(),r);
Print("l");
}
return kFALSE;
}
return kTRUE;
}
double xyz0[3], xyz1[3];
while(1) {
if (!GetXatLabR(r ,xR, b, dir)) {
// printf("Track with pt=%f cannot reach radius %f\n",Pt(),r);
// Print("l");
return kFALSE;
}
int sgn = GetX()<xR ? 1:-1;
if (tof) GetXYZ(xyz0);
if (!AliExternalTrackParam::PropagateTo(xR, b)) {
if (AliLog::GetGlobalDebugLevel()>2) {
printf("Failed to propagate to X=%f for R=%f\n",xR,r);
Print("l");
}
return kFALSE;
}
if (tof) {
GetXYZ(xyz1);
double dx = xyz1[0]-xyz0[0], dy = xyz1[1]-xyz0[1], dz = xyz1[2]-xyz0[2];
AddTimeStep( sgn*TMath::Sqrt(dx*dx+dy*dy+dz*dz) );
}
rcurr2 = xR*xR + GetY()*GetY();
if (TMath::Abs(rcurr2-rr)<kTiny || rr<kAlmost0) return kTRUE;
//
// two radii correspond to this X...
Double_t pos[3]; GetXYZ(pos);
Double_t phi = TMath::ATan2(pos[1],pos[0]);
if (!Rotate(phi)) {
if (AliLog::GetGlobalDebugLevel()>2) {
printf("Failed to rotate to %f to propagate to R=%f\n",phi,r);
Print("l");
}
return kFALSE;
}
if (++iter>8) {
if (AliLog::GetGlobalDebugLevel()>2) {
printf("Failed to propagate to R=%f after %d steps\n",r,iter);
Print("l");
}
return kFALSE;
}
}
return kTRUE;
}
//__________________________________________________________________________
Bool_t R5Probe::CorrectForMeanMaterial(const R5Layer* lr, Bool_t inward)
{
// printf("before at r=%.1f p=%.4f\n",lr->fR, P());
if (AliExternalTrackParam::CorrectForMeanMaterial(lr->fx2X0, inward ? lr->fXRho : -lr->fXRho, GetMass() , kTRUE)) {
// printf("after at r=%.1f p=%.4f\n",lr->fR, P());
return kTRUE;
}
AliDebug(2,Form("Failed to apply material correction, X/X0=%.4f", lr->fx2X0));
if (AliLog::GetGlobalDebugLevel()>1) Print();
return kFALSE;
}
/////////////////////////////////////////////////////////////////////////////
ClassImp(R5Cluster);
//_________________________________________________________________________
R5Cluster::R5Cluster(R5Cluster &src)
: TObject(src),
fY(src.fY),fZ(src.fZ),fX(src.fX),fPhi(src.fPhi),fID(src.fID)
{}
//__________________________________________________________________________
R5Cluster& R5Cluster::operator=(const R5Cluster& src)
{
if (this!=&src) {
TObject::operator=(src);
fY = src.fY;
fZ = src.fZ;
fX = src.fX;
fPhi = src.fPhi;
fID = src.fID;
}
return *this;
}
//_________________________________________________________________________
void R5Cluster::Print(Option_t *) const
{
printf(" Local YZ = (%3.4lf,%3.4lf) | X=%3.4lf phi: %+.3f %s\n",fY,fZ,fX,fPhi,IsKilled()?"Killed":"");
}
/////////////////////////////////////////////////////////////////////////////
ClassImp(R5Layer);
//__________________________________________________________________________
R5Layer::R5Layer(char *name) :
TNamed(name,name),fR(0),fZMax(0),fx2X0(0),fXRho(0),fPhiRes(0),fZRes(0),fEff(0),
fIsDead(kFALSE),fActiveID(-1),fClMC()
{
Reset();
}
//__________________________________________________________________________
void R5Layer::CalcExtComb()
{
// calculate combined extrapolation spot
if (fExtInward[kSigY2]<0) { // inward is not defined
if (fExtOutward[kSigY2]>0) {
for (int i=kNPointParam;i--;) fExtComb[i] = fExtOutward[i];
}
else {
for (int i=kNPointParam;i--;) fExtComb[i] = -1; // not defined
return;
}
}
else {
if (fExtOutward[kSigY2]>0) { // both are defined, combine them
Double_t detInw = 1./(fExtInward[kSigY2]*fExtInward[kSigZ2] - fExtInward[kSigZY]*fExtInward[kSigZY]);
Double_t wyyInw = fExtInward[kSigZ2]*detInw, wzzInw = fExtInward[kSigY2]*detInw, wzyInw = -fExtInward[kSigZY]*detInw;
Double_t detOut = 1./(fExtOutward[kSigY2]*fExtOutward[kSigZ2] - fExtOutward[kSigZY]*fExtOutward[kSigZY]);
Double_t wyyOut = fExtOutward[kSigZ2]*detOut, wzzOut = fExtOutward[kSigY2]*detOut, wzyOut = -fExtOutward[kSigZY]*detOut;
Double_t wyyCmb = wyyInw + wyyOut, wzzCmb = wzzInw + wzzOut, wzyCmb = wzyInw + wzyOut;
Double_t detCmb = 1./(wyyCmb*wzzCmb - wzyCmb*wzyCmb);
Double_t wy = fExtInward[kPosY]*wyyInw+fExtInward[kPosZ]*wzyInw + fExtOutward[kPosY]*wyyOut+fExtOutward[kPosZ]*wzyOut;
Double_t wz = fExtInward[kPosZ]*wzyInw+fExtInward[kPosZ]*wzzInw + fExtOutward[kPosY]*wzyOut+fExtOutward[kPosZ]*wzzOut;
fExtComb[kSigY2] = wzzCmb*detCmb;
fExtComb[kSigZ2] = wyyCmb*detCmb;
fExtComb[kSigZY] = -wzyCmb*detCmb;
fExtComb[kPosY] = fExtComb[kSigY2]*wy + fExtComb[kSigZY]*wz;
fExtComb[kPosZ] = fExtComb[kSigZ2]*wz + fExtComb[kSigZY]*wy;
}
else {
for (int i=kNPointParam;i--;) fExtComb[i] = fExtInward[i];
}
}
Diagonalize2x2Matrix(fExtComb[kSigY2],fExtComb[kSigZY],fExtComb[kSigZ2],
fDiagErr[kDiagErr0],fDiagErr[kDiagErr1],fDiagErr[kDiagTheta]);
}
//__________________________________________________________________________
void R5Layer::Print(Option_t *opt) const
{
TString opts = opt; opts.ToLower();
printf("Lr%3d(A%3d) %10s R=%5.1f Zmx=%5.1f X2X0=%.3f XRho=%.3f SigY=%+.5f SigZ=%+.5f Eff:%+4.2f\n",
GetUniqueID(),fActiveID,GetName(), fR,fZMax, fx2X0,fXRho,fPhiRes,fZRes,fEff);
if (opts.Contains("t")) { // print tracking info
printf("ExtInw: Y: %+.3e Z: %+.3e | %+.4e %+.4e %+.4e\n", fExtInward[kPosY],fExtInward[kPosZ],
fExtInward[kSigY2],fExtInward[kSigZY],fExtInward[kSigZ2]);
printf("ExtOut: Y: %+.3e Z: %+.3e | %+.4e %+.4e %+.4e\n", fExtOutward[kPosY],fExtOutward[kPosZ],
fExtOutward[kSigY2],fExtOutward[kSigZY],fExtOutward[kSigZ2]);
printf("ExtCmb: Y: %+.3e Z: %+.3e | %+.4e %+.4e %+.4e | Diag: %.3e %.3e %+.3e\n",
fExtComb[kPosY],fExtComb[kPosZ],fExtComb[kSigY2],fExtComb[kSigZY],fExtComb[kSigZ2],
fDiagErr[kDiagErr0],fDiagErr[kDiagErr1],fDiagErr[kDiagTheta] );
}
if (opts.Contains("c")) {
printf("Cluster: Id: %+3d: %+7.4f:%+7.4f\n",fClMC.GetID(), fClMC.GetY(),fClMC.GetZ());
}
}
//_________________________________________________________
void R5Layer::Diagonalize2x2Matrix(Double_t sigAA, Double_t sigBA, Double_t sigBB, Double_t &sig11, Double_t &sig22, Double_t &theta)
{
// find diagonalied matrix and rotation which diagonalizes it
Double_t diff = (sigAA-sigBB);
if (TMath::Abs(diff)<1e-7) {
if (sigBA>0) theta = TMath::Pi()/4.;
else if (sigBA<0) theta = TMath::Pi()*3./4.;
else {
theta = 0.;
sig11 = TMath::Sqrt(sigAA);
sig22 = TMath::Sqrt(sigBB);
return;
}
}
theta = 0.5*TMath::ATan2(2.*sigBA, diff);
Double_t disc = diff*diff + 4*sigBA*sigBA;
if (disc<0) {
printf("Matrix not positive defined: %e %e %e\n",sigAA,sigBA,sigBB);
theta = 0.;
sig11 = TMath::Sqrt(sigAA);
sig22 = TMath::Sqrt(sigBB);
return;
}
disc = TMath::Sqrt(disc);
sig11 = TMath::Sqrt(0.5*(sigAA + sigBB + disc));
sig22 = TMath::Sqrt(0.5*(sigAA + sigBB - disc));
}
/////////////////////////////////////////////////////////////////////////////
Double_t R5Detector::fgVtxConstraint[2]={-1,-1};
ClassImp(R5Detector);
R5Detector::R5Detector() :
TNamed("test_detector","detector"),
fNLayers(0),
fNActiveLayers(0),
fFirstActiveLayer(-1),
fLastActiveLayer(-1),
fFirstActiveLayerTracked(-1),
fLastActiveLayerTracked(-1),
fLayers(),
fBFieldG(5.),
fIntegrationTime(0.02), // in ms
fdNdEtaCent(2000), // Multiplicity
fDensFactorEta(1),
fMaxChi2Cl(30.),
fMaxNormChi2NDF(7.),
fMinHits(4),
fMaxSnp(0.8),
fPropagateToOrigin(kFALSE),
fTOFResolutionPS(30.),
fProbeInMC0(),
fProbeOutMC(),
fProbeInward(),
fESDtrack(),
fNHitsAssigned(0)
{
//
// default constructor
//
}
R5Detector::R5Detector(char *name, char *title)
: TNamed(name,title),
fNLayers(0),
fNActiveLayers(0),
fFirstActiveLayer(-1),
fLastActiveLayer(-1),
fFirstActiveLayerTracked(-1),
fLastActiveLayerTracked(-1),
fLayers(),
fBFieldG(5.),
fIntegrationTime(0.02), // in ms
fdNdEtaCent(2000), // Multiplicity
fDensFactorEta(1.),
fMaxChi2Cl(30.),
fMaxNormChi2NDF(7.),
fMinHits(4),
fMaxSnp(0.8),
fPropagateToOrigin(kFALSE),
fTOFResolutionPS(30.),
fProbeInMC0(),
fProbeOutMC(),
fProbeInward(),
fESDtrack(),
fNHitsAssigned(0)
{
//
// default constructor, that set the name and title
//
// fLayers = new TObjArray();
}
R5Detector::~R5Detector() { //
// virtual destructor
//
// delete fLayers;
}
void R5Detector::AddLayer(char *name, Double_t radius, Double_t zmax, Double_t x2X0, Double_t xrho, Double_t phiRes, Double_t zRes, Double_t eff) {
//
// Add additional layer to the list of layers (ordered by radius)
//
R5Layer *newLayer = (R5Layer*) fLayers.FindObject(name);
if (!newLayer) {
newLayer = new R5Layer(name);
newLayer->fR = radius;
newLayer->fZMax = zmax;
newLayer->fx2X0 = x2X0;
newLayer->fXRho = xrho;
newLayer->fPhiRes = phiRes;
newLayer->fZRes = zRes;
eff = TMath::Min(1.,eff);
newLayer->fEff = eff;
newLayer->fActiveID = -2;
TString lname = name;
if (lname.Contains("vertex")) newLayer->SetBit(R5Layer::kBitVertex);
//
newLayer->fIsDead = (newLayer->fPhiRes<0 && newLayer->fZRes<0) || newLayer->fEff<=0.;
//
if (fLayers.GetEntries()==0)
fLayers.Add(newLayer);
else {
//
for (Int_t i = 0; i<fLayers.GetEntries(); i++) {
R5Layer *l = (R5Layer*)fLayers.At(i);
if (radius<l->fR) { fLayers.AddBefore(l,newLayer); break; }
if (radius>l->fR && (i+1)==fLayers.GetEntries() ) fLayers.Add(newLayer); // even bigger then last one
}
//
}
//
ClassifyLayers();
fNLayers++;
//
} else {
printf("Layer with the name %s does already exist\n",name);
}
}
//____________________________________________________________
void R5Detector::ClassifyLayers()
{
// assign active Id's, etc
fFirstActiveLayer = fLastActiveLayer = -1;
fNActiveLayers = 0;
//
int nl = GetNLayers();
for (int il=0;il<nl;il++) {
R5Layer* lr = GetLayer(il);
lr->SetUniqueID(il);
if (!lr->IsDead()) {
fLastActiveLayer = il;
if (fFirstActiveLayer<0) fFirstActiveLayer = il;
lr->SetActiveID(fNActiveLayers++);
}
}
//
R5Probe::SetNLayers(fNActiveLayers);
}
//________________________________________________________________________________
Int_t R5Detector::GetLayerID(int actID) const
{
// find physical layer id from active id
if (actID<0 || actID>fNActiveLayers) return -1;
for (int i=fLastActiveLayer+1; i--;) {
if (GetLayer(i)->GetActiveID()==actID) return i;
}
return -1;
}
void R5Detector::Print(const Option_t* opt) const {
//
// Prints the detector layout
//
printf("Detector %s: \"%s\"\n",GetName(),GetTitle());
if (fLayers.GetEntries()>0) printf(" Name \t\t r [cm] \t X0 \t phi & z res [um]\n");
for (Int_t i = 0; i<fLayers.GetEntries(); i++) {
R5Layer* tmp = (R5Layer*)fLayers.At(i);
tmp->Print(opt);
// printf("%d. %s \t %03.2f \t%1.4f\t ",i, tmp->GetName(), tmp->GetRadius(), tmp->GetRadL() );
// if (tmp->IsDead()) printf(" - ");
// else printf("%3.0f ",tmp->GetPhiRes()*10000);
// if (tmp->IsDead()) printf(" -\n");
// else printf("%3.0f\n",tmp->GetZRes()*10000);
}
}
Double_t R5Detector::ThetaMCS ( Double_t mass, Double_t x2X0, Double_t momentum ) const
{
//
// returns the Multiple Couloumb scattering angle (compare PDG boolet, 2010, equ. 27.14)
//
Double_t beta = momentum / TMath::Sqrt(momentum*momentum+mass*mass) ;
Double_t theta = 0.0 ; // Momentum and mass in GeV
// if ( RadLength > 0 ) theta = 0.0136 * TMath::Sqrt(RadLength) / ( beta * momentum );
if ( x2X0 > 0 ) theta = 0.0136 * TMath::Sqrt(x2X0) / ( beta * momentum ) * (1+0.038*TMath::Log(x2X0)) ;
return (theta) ;
}
Double_t R5Detector::ProbGoodHit ( Double_t radius, Double_t searchRadiusRPhi, Double_t searchRadiusZ )
{
// Based on work by Howard Wieman: http://rnc.lbl.gov/~wieman/GhostTracks.htm
// and http://rnc.lbl.gov/~wieman/HitFinding2D.htm
// This is the probability of getting a good hit using 2D Gaussian distribution function and infinite search radius
Double_t sx, sy, goodHit ;
sx = 2 * TMath::Pi() * searchRadiusRPhi * searchRadiusRPhi * HitDensity(radius) ;
sy = 2 * TMath::Pi() * searchRadiusZ * searchRadiusZ * HitDensity(radius) ;
goodHit = TMath::Sqrt(1./((1+sx)*(1+sy))) ;
return ( goodHit ) ;
}
Double_t R5Detector::ProbGoodChiSqHit ( Double_t radius, Double_t searchRadiusRPhi, Double_t searchRadiusZ )
{
// Based on work by Victor Perevoztchikov and Howard Wieman: http://rnc.lbl.gov/~wieman/HitFinding2DXsq.htm
// This is the probability of getting a good hit using a Chi**2 search on a 2D Gaussian distribution function
Double_t sx, goodHit ;
sx = 2 * TMath::Pi() * searchRadiusRPhi * searchRadiusZ * HitDensity(radius) ;
goodHit = 1./(1+sx) ;
return ( goodHit ) ;
}
Double_t R5Detector::ProbGoodChiSqPlusConfHit ( Double_t radius, Double_t leff,
Double_t searchRadiusRPhi, Double_t searchRadiusZ, Double_t confLevel)
{
// Based on work by Ruben Shahoyen
// This is the probability of getting a good hit using a Chi**2 search on a 2D Gaussian distribution function
// Plus, in addition, taking a "confidence level" and the "layer efficiency" into account
// Following is correct for 2 DOF
Double_t c = -2 *TMath::Log(confLevel); // quantile at cut of confidence level
Double_t alpha = (1 + 2 * TMath::Pi() * HitDensity(radius) * searchRadiusRPhi * searchRadiusZ)/2;
Double_t goodHit = leff/(2*alpha) * (1 - TMath::Exp(-alpha*c));
return ( goodHit ) ;
}
Double_t R5Detector::ProbNullChiSqPlusConfHit ( Double_t radius, Double_t leff,
Double_t searchRadiusRPhi, Double_t searchRadiusZ, Double_t confLevel)
{
// Based on work by Ruben Shahoyan
// This is the probability to not have any match to the track (see also :ProbGoodChiSqPlusConfHit:)
Double_t c = -2 *TMath::Log(confLevel); // quantile at cut of confidence level
Double_t alpha = (1 + 2 * TMath::Pi() * HitDensity(radius) * searchRadiusRPhi * searchRadiusZ)/2;
Double_t nullHit = (1-leff+confLevel*leff)*TMath::Exp(-c*(alpha-1./2));
return ( nullHit ) ;
}
Double_t R5Detector::HitDensity ( Double_t radius )
{
// Background (0-1) is included via 'OtherBackground' which multiplies the minBias rate by a scale factor.
// UPC electrons is a temporary kludge that is based on Kai Schweda's summary of Kai Hainken's MC results
// See K. Hencken et al. PRC 69, 054902 (2004) and PPT slides by Kai Schweda.
// Note that this function assumes we are working in CM and CM**2 [not meters].
// Based on work by Yan Lu 12/20/2006, all radii and densities in centimeters or cm**2.
// Double_t MaxRadiusSlowDet = 0.1; //? // Maximum radius for slow detectors. Fast detectors
if (radius<0.01) return 0;
//
Double_t arealDensity = OneEventHitDensity(fdNdEtaCent,radius) + UpcHitDensity(radius) ;
return ( arealDensity ) ;
}
Double_t R5Detector::OneEventHitDensity( Double_t multiplicity, Double_t radius ) const
{
// This is for one event at the vertex. No smearing.
Double_t den = multiplicity / (2.*TMath::Pi()*radius*radius) * fDensFactorEta ; // 2 eta ?
// note: surface of sphere is '4*pi*r^2'
// surface of cylinder is '2*pi*r* h'
return den ;
}
Double_t R5Detector::UpcHitDensity(Double_t radius)
{
// QED electrons ...
Double_t mUPCelectrons = 0;
/*
// mUPCelectrons = fLhcUPCscale * (1.23 - radius/6.5) ; // Fit to Kai Schweda summary tables at RHIC * 'scale' for LHC
mUPCelectrons = fLhcUPCscale*5456/(radius*radius)/dNdEtaMinB; // Fit to 'Rossegger,Sadovsky'-Alice simulation
if ( mUPCelectrons < 0 ) mUPCelectrons = 0.0 ; // UPC electrons fall off quickly and don't go to large R
mUPCelectrons *= IntegratedHitDensity(dNdEtaMinB,radius) ; // UPCs increase Mulitiplicty ~ proportional to MinBias rate
mUPCelectrons *= UPCBackgroundMultiplier ; // Allow for an external multiplier (eg 0-1) to turn off UPC
*/
return mUPCelectrons ;
}
void R5Detector::CalcDensFactorEta(Double_t eta)
{
if (TMath::Abs(eta)<1e-3) fDensFactorEta = 1.;
else {
fDensFactorEta = TMath::Tan( 2.*TMath::ATan(TMath::Exp(-TMath::Abs(eta))) );
fDensFactorEta = 1./TMath::Sqrt( 1. + 1./fDensFactorEta/fDensFactorEta);
}
}
void R5Detector::ApplyMS(R5Probe* trc, Double_t x2X0) const
{
// simulate random modification of track params due to the MS
if (x2X0<=0) return;
Double_t alpha = trc->GetAlpha(); // store original alpha
Double_t mass = trc->GetMass();
//
Double_t snp = trc->GetSnp();
Double_t dip = trc->GetTgl();
Double_t angle=TMath::Sqrt((1.+ dip*dip)/((1-snp)*(1.+snp)));
x2X0 *= angle;
//
static Double_t covCorr[15],covDum[21]={0};
static Double_t mom[3],pos[3];
Double_t *cov = (Double_t*) trc->GetCovariance();
memcpy(covCorr,cov,15*sizeof(double));
trc->GetXYZ(pos);
trc->GetPxPyPz(mom);
Double_t pt2 = mom[0]*mom[0]+mom[1]*mom[1];
Double_t pt = TMath::Sqrt(pt2);
Double_t ptot2 = pt2 + mom[2]*mom[2];
Double_t ptot = TMath::Sqrt(ptot2);
Double_t beta = ptot/TMath::Sqrt(ptot2 + mass*mass);
Double_t sigth = TMath::Sqrt(x2X0)*0.014/(ptot*beta);
//
// a la geant
Double_t phiSC = gRandom->Rndm()*TMath::Pi();
Double_t thtSC = gRandom->Gaus(0,1.4142*sigth);
// printf("MS phi: %+.5f tht: %+.5f\n",phiSC,thtSC);
Double_t sn = TMath::Sin(thtSC);
Double_t dx = sn*TMath::Sin(phiSC);
Double_t dy = sn*TMath::Cos(phiSC);
Double_t dz = TMath::Cos(thtSC);
Double_t v[3];
// printf("Before: %+.3e %+.3e %+.3e | MS: %+.3e %+.3e\n",mom[0],mom[1],mom[2],thtSC,phiSC);
for (int i=3;i--;) mom[i] /= ptot;
Double_t vmm = TMath::Sqrt(mom[0]*mom[0]+mom[1]*mom[1]);
if (!IsZero(pt)) {
Double_t pd1 = mom[0]/vmm;
Double_t pd2 = mom[1]/vmm;
v[0] = pd1*mom[2]*dx - pd2*dy + mom[0]*dz;
v[1] = pd2*mom[2]*dx + pd1*dy + mom[1]*dz;
v[2] = -vmm*dx + mom[2]*dz;
}
else {
v[0] = dx;
v[1] = dy;
v[2] = dz*TMath::Sign(1.,mom[2]);
}
Double_t nrm = TMath::Sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
// printf("before :%+e %+e %+e || %+e %+e %+e %+e\n",mom[0],mom[1],mom[2], sigth, x2X0, pt, beta);
// trc->Print();
// direction cosines -> p
for (int i=3;i--;) mom[i] = ptot*v[i]/nrm;
// printf("After : %+.3e %+.3e %+.3e\n",mom[0],mom[1],mom[2]);
trc->Set(pos,mom,covDum,trc->Charge());
//
trc->Rotate(alpha);
memcpy(cov,covCorr,15*sizeof(double));
//
}
void R5Detector::PrepareKalmanTrack(Double_t pt, Double_t eta, Double_t mass, int charge, Double_t phi, Double_t x,Double_t y, Double_t z, Double_t t)
{
// Prepare trackable Kalman track at the farthest position
//
// Set track parameters
Double_t lambda = TMath::Pi()/2.0 - 2.0*TMath::ATan(TMath::Exp(-eta));
Reset();
fProbeInMC0.Reset();
fProbeInMC0.SetMass(mass);
R5Probe probe(fProbeInMC0);
Double_t *trPars = (Double_t*)probe.GetParameter();
Double_t *trCov = (Double_t*)probe.GetCovariance();
Double_t xyz[3] = {x,y,z};
probe.SetTOFsignal(t*1e12 + gRandom->Gaus(0,fTOFResolutionPS)); // TOF in ps
probe.Global2LocalPosition(xyz,phi);
probe.Set(xyz[0],phi,trPars,trCov);
trPars[R5Probe::kY] = xyz[1];
trPars[R5Probe::kZ] = xyz[2];
trPars[R5Probe::kSnp] = 0; // track along X axis at the vertex
trPars[R5Probe::kTgl] = TMath::Tan(lambda); // dip
trPars[R5Probe::kPtI] = charge/pt; // q/pt
//
// put tiny errors to propagate to the outer-most radius
trCov[R5Probe::kY2] = trCov[R5Probe::kZ2] = trCov[R5Probe::kSnp2] = trCov[R5Probe::kTgl2] = trCov[R5Probe::kPtI2] = 1e-20;
fProbeInMC0 = probe; // store original track
//
TransportKalmanTrackWithMS(&probe);
probe.ResetCovMat();// reset cov.matrix
fProbeOutMC = probe; // store propagated track
//
}
//________________________________________________________________________________
int R5Detector::TransportKalmanTrackWithMS(R5Probe *probTr, Bool_t applyMatCorr)
{
// Transport track till layer maxLr, applying random MS
//
const Double_t kcc = 2.99792458e-2;
int nActLrOK = 0;
Double_t r = TMath::Sqrt(probTr->GetX()*probTr->GetX()+probTr->GetY()*probTr->GetY());
fFirstActiveLayerTracked = -1;
fLastActiveLayerTracked = -1;
double xyz0[3],xyz1[3];
probTr->GetXYZ(xyz0);
for (Int_t j=0; j<fNLayers; j++) {
if (j>fLastActiveLayer) continue;
R5Layer* lr = (R5Layer*)fLayers.At(j);
if (lr->GetRadius() <= r) continue;
if (!PropagateToLayer(probTr,lr,1)) break;
{
probTr->GetXYZ(xyz1);
// calculate TOF
double dst = 0;
for (int i=0;i<3;i++) {
double d = xyz1[i] - xyz0[i];
dst += d*d;
xyz0[i] = xyz1[i];
}
dst = dst>0 ? TMath::Sqrt(dst) : 0;
double q2pt = probTr->GetSigned1Pt(), tgl = probTr->GetTgl(), p2inv = q2pt*q2pt/(1+tgl*tgl);
Double_t correction = TMath::Sqrt( 1. + probTr->GetMass()*probTr->GetMass()*p2inv ); // 1/beta
Double_t time = dst * correction / kcc;
probTr->SetTOFsignal(time + probTr->GetTOFsignal());
}
if (TMath::Abs(probTr->GetSnp())>fMaxSnp) break;
Bool_t accZOK = lr->InZAcceptane(probTr->GetZ());
if (lr->GetRadL()>0 && applyMatCorr && accZOK) {
ApplyMS(probTr,lr->GetRadL()); // apply MS
if (!probTr->CorrectForMeanMaterial(lr,kFALSE)) break;
}
//
if (lr->IsDead()) continue;
if (fFirstActiveLayerTracked<0) fFirstActiveLayerTracked = lr->GetActiveID();
fLastActiveLayerTracked = lr->GetActiveID();
if (!accZOK) continue;
// store randomized cluster local coordinates and phi
Double_t rz,ry;
gRandom->Rannor(rz,ry);
lr->GetMCCluster()->Set(probTr->GetY()+ry*lr->GetPhiRes(),probTr->GetZ()+rz*lr->GetZRes(),
probTr->GetX(), probTr->GetAlpha(), -1);
if (lr->GetLayerEff()<gRandom->Rndm()) { // impose inefficiency
lr->GetMCCluster()->Kill(kTRUE);
}
else {
fNHitsAssigned++;
}
nActLrOK++;
//
}
//
return nActLrOK;
}
//____________________________________________________________________________
Bool_t R5Detector::PropagateToLayer(R5Probe* trc, const R5Layer* lr, int dir) const
{
// bring the track to layer and rotat to frame normal to its surface
if (!trc->PropagateToR(lr->fR,fBFieldG, dir)) return kFALSE;
//
// rotate to frame with X axis normal to the surface (defined by ideal track)
if (!lr->IsVertex()) {
Double_t phi = trc->PhiPos();
//if ( TMath::Abs(TMath::Abs(phi)-TMath::Pi()/2)<1e-3) phi = 0;
if (!trc->Rotate(phi)) {
return kFALSE;
}
}
//
return kTRUE;
}
//____________________________________________________________________________
Bool_t R5Detector::UpdateTrack(R5Probe* trc, R5Layer* lr, R5Cluster* cl) const
{
// update track with measured cluster
// propagate to cluster
Double_t meas[2] = {cl->GetY(),cl->GetZ()}; // ideal cluster coordinate
Double_t measErr2[3] = {lr->fPhiRes*lr->fPhiRes,0,lr->fZRes*lr->fZRes};
//
//
Double_t chi2 = trc->AliExternalTrackParam::GetPredictedChi2(meas,measErr2);
// if (chi2>fMaxChi2Cl) return kTRUE; // chi2 is too large
//
if (!trc->AliExternalTrackParam::Update(meas,measErr2)) {
AliDebug(2,Form("layer %s: Failed to update the track by measurement {%.3f,%3f} err {%.3e %.3e %.3e}",
lr->GetName(),meas[0],meas[1], measErr2[0],measErr2[1],measErr2[2]));
if (AliLog::GetGlobalDebugLevel()>1) trc->Print("l");
return kFALSE;
}
trc->AddHit(lr->GetActiveID(), chi2);
//
return kTRUE;
}
Bool_t R5Detector::ProcessTrack(const TParticle* part)
{
return ProcessTrack(part->Pt(),part->Eta(),part->GetMass(),
TDatabasePDG::Instance()->GetParticle(part->GetPdgCode())->Charge()/3,
part->Phi(),part->Vx(),part->Vy(),part->Vz(),part->T());
}
Bool_t R5Detector::ProcessTrack(Double_t pt, Double_t eta, Double_t mass, int charge, Double_t phi, Double_t x,Double_t y, Double_t z, Double_t t)
{
// find analytical solution for given seed
AliESDVertex vtx0(0.,0.,0.,0);
fNHitsAssigned = 0;
PrepareKalmanTrack(pt, eta, mass, charge, phi, x,y, z, t);
if (fLastActiveLayerTracked<0) return kFALSE; // no hits
// do backward propagation
R5Probe probeInw = fProbeOutMC;
probeInw.ResetTrackingInfo(); // used default (pion) mass for tracking
R5Cluster* cl = 0;
// covariance matrix must be already reset
int innerTracked = GetLayerID(fFirstActiveLayerTracked);
int outerTracked = GetLayerID(fLastActiveLayerTracked);
probeInw.SetOuterChecked(fLastActiveLayerTracked);
// printf("ProbeIni: "); probeInw.Print("t");
int innerReached = -1;
for (int ilr = outerTracked+1 ;ilr--;) {
//if (ilr<innerTracked) break;