COVERITY reports many FORWARD_NULL, corrected; AliEMCALv2: initialization of fHits...
[u/mrichter/AliRoot.git] / FMD / AliFMDESDRevertexer.cxx
CommitLineData
50b9d194 1#include <AliFMDESDRevertexer.h>
2#include <AliFMDGeometry.h>
3#include <AliESDFMD.h>
86878381 4#include <TMath.h>
5#include <AliLog.h>
6
7ClassImp(AliFMDESDRevertexer)
8#if 0 // for emacs
9;
10#endif
50b9d194 11
12//____________________________________________________________________
13AliFMDESDRevertexer::AliFMDESDRevertexer()
14{
15 AliFMDGeometry* geom = AliFMDGeometry::Instance();
16 geom->Init();
86878381 17 geom->InitTransformations();
50b9d194 18}
19
20//____________________________________________________________________
21Bool_t
86878381 22AliFMDESDRevertexer::Revertex(AliESDFMD* fmdEsd, Double_t vz) const
50b9d194 23{
24 if (!fmdEsd) return kFALSE;
25
26 Bool_t ret = kTRUE;
27 for (UShort_t det = 1; det <= 3; det++) {
28 UShort_t nrng = (det == 1 ? 1 : 2);
29 for (UShort_t ir = 0; ir < nrng; ir++) {
30 Char_t rng = (ir == 0 ? 'I' : 'O');
31 UShort_t nsec = (ir == 0 ? 20 : 40);
32 UShort_t nstr = (ir == 0 ? 512 : 256);
33 for (UShort_t str = 0; str < nstr; str++) {
86878381 34 Double_t phi, r, theta;
50b9d194 35 Double_t eta = AliESDFMD::kInvalidEta;
86878381 36 Double_t oldEta = fmdEsd->Eta(det, rng, 0, str);
37 if (oldEta == AliESDFMD::kInvalidEta) continue;
38
50b9d194 39 Double_t oldTheta = Eta2Theta(oldEta);
40 Bool_t ret1 = PhysicalCoordinates(det, rng, 0, str, vz,
86878381 41 eta, phi, r, theta);
42 fmdEsd->SetEta(det, rng, 0, str, eta);
50b9d194 43
44 if (!ret1) {
45 // If the was an error, then there's no reason to go on with
46 // this strip-ring. Note, that the eta is correctly set to
47 // AliESDFMD::kInvalidMult.
48 AliWarning(Form("Failed to calculate eta, phi for "
86878381 49 "FMD%d%c[%02d,%03d] with v_z=%9.4f",
50b9d194 50 det, rng, 0, str, vz));
51 ret = kFALSE;
52 continue;
53 }
86878381 54
50b9d194 55 Double_t corr = TMath::Abs(TMath::Cos(theta));
56 if (fmdEsd->IsAngleCorrected())
57 corr /= TMath::Abs(TMath::Cos(oldTheta));
58 for (UShort_t sec = 0; sec < nsec; sec++) {
59 Double_t mult = fmdEsd->Multiplicity(det, rng, sec, str);
86878381 60 if (mult == AliESDFMD::kInvalidMult) continue;
50b9d194 61 fmdEsd->SetMultiplicity(det, rng, sec, str, corr * mult);
62 }
63 }
64 }
65 }
66
67 return ret;
68}
69
70//____________________________________________________________________
71Double_t
72AliFMDESDRevertexer::Eta2Theta(Double_t eta) const
73{
74 return 2 * TMath::ATan(TMath::Exp(-eta));
75}
76
77
78//____________________________________________________________________
79Bool_t
80AliFMDESDRevertexer::PhysicalCoordinates(UShort_t det,
81 Char_t rng,
82 UShort_t sec,
83 UShort_t str,
84 Double_t vz,
85 Double_t& eta,
86 Double_t& phi,
87 Double_t& r,
88 Double_t& theta) const
89{
90 // Get the eta and phi of a digit
91 //
92 // Get geometry.
93 AliFMDGeometry* geom = AliFMDGeometry::Instance();
94 Double_t x=0, y=0, z=0;
95 geom->Detector2XYZ(det, rng, sec, str, x, y, z);
96
97 // Check that the conversion succeeded
98 if (x == 0 && y == 0 && z == 0) return kFALSE;
99
100 // Correct for vertex offset.
8161c5f7 101 z -= vz;
50b9d194 102 phi = TMath::ATan2(y, x);
103 r = TMath::Sqrt(y * y + x * x);
104 theta = TMath::ATan2(r, z);
105 eta = -TMath::Log(TMath::Tan(theta / 2));
106
107 return kTRUE;
108}
109
110