]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MFT/AliMFTSupport.cxx
coverity warning
[u/mrichter/AliRoot.git] / MFT / AliMFTSupport.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 //====================================================================================================================================================
17 //
18 //      Support class for various common operation on MFT objects
19 //
20 //      Contact author: antonio.uras@cern.ch
21 //
22 //====================================================================================================================================================
23
24 #include "AliMUONTrackParam.h"
25 #include "AliMUONTrackExtrap.h"
26 #include "AliAODTrack.h"
27 #include "AliAODDimuon.h"
28 #include "TLorentzVector.h"
29 #include "AliMFTConstants.h"
30 #include "TDatabasePDG.h"
31 #include "TMath.h"
32 #include "AliLog.h"
33
34 #include "AliMFTSupport.h"
35
36 ClassImp(AliMFTSupport)
37
38 //====================================================================================================================================================
39
40 Bool_t AliMFTSupport::ExtrapAODMuonToZ(AliAODTrack *muon, Double_t z, Double_t xy[2]) {
41
42   if (!(muon->Pz()!=0)) return kFALSE;
43
44   AliMUONTrackParam *param = new AliMUONTrackParam();
45
46   param -> SetNonBendingCoor(muon->XAtDCA());
47   param -> SetBendingCoor(muon->YAtDCA());
48   param -> SetZ(0.);
49   param -> SetNonBendingSlope(muon->Px()/muon->Pz());
50   param -> SetBendingSlope(muon->Py()/muon->Pz());
51   param -> SetInverseBendingMomentum( muon->Charge() * (1./muon->Pz()) / (TMath::Sqrt(1+TMath::Power(muon->Py()/muon->Pz(),2))) );
52
53   AliMUONTrackExtrap::ExtrapToZ(param, z);
54   xy[0] = param->GetNonBendingCoor();
55   xy[1] = param->GetBendingCoor();
56
57   return kTRUE;
58
59 }
60
61 //====================================================================================================================================================
62
63 Bool_t AliMFTSupport::RefitAODDimuonWithCommonVertex(AliAODDimuon *dimuon, Double_t *vertex, TLorentzVector &kinem) {
64
65   Double_t fXPointOfClosestApproach=0, fYPointOfClosestApproach=0, fZPointOfClosestApproach=0;
66
67   AliAODTrack *muon0 = dimuon->GetMu(0);
68   AliAODTrack *muon1 = dimuon->GetMu(1);
69
70   if (!(muon0->Pz()!=0 && muon1->Pz()!=0)) return kFALSE;
71
72   AliMUONTrackParam *param0 = new AliMUONTrackParam();
73   AliMUONTrackParam *param1 = new AliMUONTrackParam();
74
75   param0 -> SetNonBendingCoor(muon0->XAtDCA());
76   param1 -> SetNonBendingCoor(muon1->XAtDCA());
77
78   param0 -> SetBendingCoor(muon0->YAtDCA());
79   param1 -> SetBendingCoor(muon1->YAtDCA());
80
81   param0 -> SetZ(0.);
82   param1 -> SetZ(0.);
83  
84   param0 -> SetNonBendingSlope(muon0->Px()/muon0->Pz());
85   param1 -> SetNonBendingSlope(muon1->Px()/muon1->Pz());
86
87   param0 -> SetBendingSlope(muon0->Py()/muon0->Pz());
88   param1 -> SetBendingSlope(muon1->Py()/muon1->Pz());
89
90   param0 -> SetInverseBendingMomentum( muon0->Charge() * (1./muon0->Pz()) / (TMath::Sqrt(1+TMath::Power(muon0->Py()/muon0->Pz(),2))) );
91   param1 -> SetInverseBendingMomentum( muon1->Charge() * (1./muon1->Pz()) / (TMath::Sqrt(1+TMath::Power(muon1->Py()/muon1->Pz(),2))) );
92
93   Double_t step = 1.;  // in cm
94   Double_t startPoint = 0.;
95
96   Double_t r[3]={0}, z[3]={startPoint, startPoint+step, startPoint+2*step};
97   
98   for (Int_t i=0; i<3; i++) {
99     AliMUONTrackExtrap::ExtrapToZ(param0, z[i]);
100     AliMUONTrackExtrap::ExtrapToZ(param1, z[i]);
101     Double_t dX = param0->GetNonBendingCoor() - param1->GetNonBendingCoor();
102     Double_t dY = param0->GetBendingCoor()    - param1->GetBendingCoor();
103     r[i] = TMath::Sqrt(dX*dX + dY*dY);
104   }
105   
106   Double_t researchDirection=0.;
107   
108   if      (r[0]>r[1] && r[1]>r[2]) researchDirection = +1.;   // towards z positive
109   else if (r[0]<r[1] && r[1]<r[2]) researchDirection = -1.;   // towards z negative
110   else if (r[0]<r[1] && r[1]>r[2]) { 
111     printf("E-AliMFTSupport::RefitAODDimuonWithCommonVertex: Point of closest approach cannot be found for dimuon (no minima)\n");
112     return kFALSE;
113   }
114   
115   while (TMath::Abs(researchDirection)>0.5) {
116     if (researchDirection>0.) {
117       z[0] = z[1];
118       z[1] = z[2];
119       z[2] = z[1]+researchDirection*step;
120     }
121     else {
122       z[2] = z[1];
123       z[1] = z[0];
124       z[0] = z[1]+researchDirection*step;
125     }
126     if (TMath::Abs(z[0])>900.) {
127       printf("E-AliMFTSupport::RefitAODDimuonWithCommonVertex: Point of closest approach cannot be found for dimuon (no minima)\n");
128       return kFALSE;
129     }
130     for (Int_t i=0; i<3; i++) {
131       AliMUONTrackExtrap::ExtrapToZ(param0, z[i]);
132       AliMUONTrackExtrap::ExtrapToZ(param1, z[i]);
133       Double_t dX = param0->GetNonBendingCoor() - param1->GetNonBendingCoor();
134       Double_t dY = param0->GetBendingCoor()    - param1->GetBendingCoor();
135       r[i] = TMath::Sqrt(dX*dX + dY*dY);
136     }
137     researchDirection=0.;
138     if      (r[0]>r[1] && r[1]>r[2]) researchDirection = +1.;   // towards z positive
139     else if (r[0]<r[1] && r[1]<r[2]) researchDirection = -1.;   // towards z negative
140   }
141     
142   step *= 0.5;
143   while (step>AliMFTConstants::fPrecisionPointOfClosestApproach) {
144     z[0] = z[1]-step;
145     z[2] = z[1]+step;
146     for (Int_t i=0; i<3; i++) {
147       AliMUONTrackExtrap::ExtrapToZ(param0, z[i]);
148       AliMUONTrackExtrap::ExtrapToZ(param1, z[i]);
149       Double_t dX = param0->GetNonBendingCoor() - param1->GetNonBendingCoor();
150       Double_t dY = param0->GetBendingCoor()    - param1->GetBendingCoor();
151       r[i] = TMath::Sqrt(dX*dX + dY*dY);
152     }
153     if      (r[0]<r[1]) z[1] = z[0];
154     else if (r[2]<r[1]) z[1] = z[2];
155     else step *= 0.5;
156   }
157   
158   fZPointOfClosestApproach = z[1];
159   AliMUONTrackExtrap::ExtrapToZ(param0, fZPointOfClosestApproach);
160   AliMUONTrackExtrap::ExtrapToZ(param1, fZPointOfClosestApproach);  
161   fXPointOfClosestApproach = 0.5*(param0->GetNonBendingCoor() + param1->GetNonBendingCoor());
162   fYPointOfClosestApproach = 0.5*(param0->GetBendingCoor()    + param1->GetBendingCoor());
163   
164   //-------------------------------------------------------------------------------------------------------------------------------------------------
165
166   vertex[0] = fXPointOfClosestApproach;
167   vertex[1] = fYPointOfClosestApproach;
168   vertex[2] = fZPointOfClosestApproach;
169
170   Double_t pTot[3] = {0};
171   pTot[0] = param0->Px() + param1->Px();
172   pTot[1] = param0->Py() + param1->Py();
173   pTot[2] = param0->Pz() + param1->Pz();
174
175   Double_t massMu = TDatabasePDG::Instance()->GetParticle("mu-")->Mass();
176
177   Double_t energy0 = TMath::Sqrt(massMu*massMu + param0->Px()*param0->Px() + param0->Py()*param0->Py() + param0->Pz()*param0->Pz());
178   Double_t energy1 = TMath::Sqrt(massMu*massMu + param1->Px()*param1->Px() + param1->Py()*param1->Py() + param1->Pz()*param1->Pz());
179
180   kinem.SetPxPyPzE(pTot[0], pTot[1], pTot[2], energy0+energy1);
181
182   return kTRUE;
183
184 }
185
186 //====================================================================================================================================================