1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 //====================================================================================================================================================
18 // Support class for various common operation on MFT objects
20 // Contact author: antonio.uras@cern.ch
22 //====================================================================================================================================================
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"
33 #include "TObjArray.h"
34 #include "TDecompLU.h"
36 #include "AliMFTAnalysisTools.h"
38 ClassImp(AliMFTAnalysisTools)
40 //====================================================================================================================================================
42 Bool_t AliMFTAnalysisTools::ExtrapAODMuonToZ(AliAODTrack *muon, Double_t z, Double_t xy[2]) {
44 if (!(muon->PzAtDCA()!=0)) return kFALSE;
46 AliMUONTrackParam *param = new AliMUONTrackParam();
48 param -> SetNonBendingCoor(muon->XAtDCA());
49 param -> SetBendingCoor(muon->YAtDCA());
50 param -> SetZ(AliMFTConstants::fZEvalKinem);
51 param -> SetNonBendingSlope(muon->PxAtDCA()/muon->PzAtDCA());
52 param -> SetBendingSlope(muon->PyAtDCA()/muon->PzAtDCA());
53 param -> SetInverseBendingMomentum( muon->Charge() * (1./muon->PzAtDCA()) / (TMath::Sqrt(1+TMath::Power(muon->PyAtDCA()/muon->PzAtDCA(),2))) );
55 AliMUONTrackExtrap::ExtrapToZ(param, z);
56 xy[0] = param->GetNonBendingCoor();
57 xy[1] = param->GetBendingCoor();
65 //====================================================================================================================================================
67 Bool_t AliMFTAnalysisTools::ExtrapAODMuonToZ(AliAODTrack *muon, Double_t z, Double_t xy[2], TLorentzVector &kinem) {
69 if (!(muon->PzAtDCA()!=0)) return kFALSE;
71 AliMUONTrackParam *param = new AliMUONTrackParam();
73 param -> SetNonBendingCoor(muon->XAtDCA());
74 param -> SetBendingCoor(muon->YAtDCA());
75 param -> SetZ(AliMFTConstants::fZEvalKinem);
76 param -> SetNonBendingSlope(muon->PxAtDCA()/muon->PzAtDCA());
77 param -> SetBendingSlope(muon->PyAtDCA()/muon->PzAtDCA());
78 param -> SetInverseBendingMomentum( muon->Charge() * (1./muon->PzAtDCA()) / (TMath::Sqrt(1+TMath::Power(muon->PyAtDCA()/muon->PzAtDCA(),2))) );
80 AliMUONTrackExtrap::ExtrapToZ(param, z);
81 xy[0] = param->GetNonBendingCoor();
82 xy[1] = param->GetBendingCoor();
84 Double_t massMu = TDatabasePDG::Instance()->GetParticle("mu-")->Mass();
85 Double_t energy = TMath::Sqrt(massMu*massMu + param->Px()*param->Px() + param->Py()*param->Py() + param->Pz()*param->Pz());
87 kinem.SetPxPyPzE(param->Px(), param->Py(), param->Pz(), energy);
95 //====================================================================================================================================================
97 Bool_t AliMFTAnalysisTools::ExtrapAODMuonToZ(AliAODTrack *muon, Double_t z, Double_t xy[2], TLorentzVector &kinem, TMatrixD &cov) {
99 // Extrapolate muon to a given z providing the corresponding (x,y) position and updating kinematics and covariance matrix
101 if (!(muon->PzAtDCA()!=0)) return kFALSE;
103 AliMUONTrackParam *param = new AliMUONTrackParam();
105 param -> SetNonBendingCoor(muon->XAtDCA());
106 param -> SetBendingCoor(muon->YAtDCA());
107 param -> SetZ(AliMFTConstants::fZEvalKinem);
108 param -> SetNonBendingSlope(muon->PxAtDCA()/muon->PzAtDCA());
109 param -> SetBendingSlope(muon->PyAtDCA()/muon->PzAtDCA());
110 param -> SetInverseBendingMomentum( muon->Charge() * (1./muon->PzAtDCA()) / (TMath::Sqrt(1+TMath::Power(muon->PyAtDCA()/muon->PzAtDCA(),2))) );
112 param -> SetCovariances(ConvertCovMatrixAOD2MUON(muon));
114 AliMUONTrackExtrap::ExtrapToZCov(param, z);
115 xy[0] = param->GetNonBendingCoor();
116 xy[1] = param->GetBendingCoor();
118 Double_t massMu = TDatabasePDG::Instance()->GetParticle("mu-")->Mass();
119 Double_t energy = TMath::Sqrt(massMu*massMu + param->Px()*param->Px() + param->Py()*param->Py() + param->Pz()*param->Pz());
121 kinem.SetPxPyPzE(param->Px(), param->Py(), param->Pz(), energy);
123 cov = param->GetCovariances();
131 //====================================================================================================================================================
133 Bool_t AliMFTAnalysisTools::ExtrapAODMuonToXY(AliAODTrack *muon, Double_t xy[2], Double_t &zFinal, TLorentzVector &kinem, TMatrixD &cov) {
135 // Find the point of closest approach between the muon and the direction parallel to the z-axis defined by the given (x,y)
136 // Provide the z of the above point as weel as the updated kinematics and covariance matrix
138 // We look for the above-defined PCA
140 AliMUONTrackParam *param = new AliMUONTrackParam();
141 param -> SetNonBendingCoor(muon->XAtDCA());
142 param -> SetBendingCoor(muon->YAtDCA());
143 param -> SetZ(AliMFTConstants::fZEvalKinem);
144 param -> SetNonBendingSlope(muon->PxAtDCA()/muon->PzAtDCA());
145 param -> SetBendingSlope(muon->PyAtDCA()/muon->PzAtDCA());
146 param -> SetInverseBendingMomentum( muon->Charge() * (1./muon->PzAtDCA()) / (TMath::Sqrt(1+TMath::Power(muon->PyAtDCA()/muon->PzAtDCA(),2))) );
148 // here we want to understand in which direction we have to search the minimum...
150 Double_t step = 1.; // initial step, in cm
151 Double_t startPoint = 0.;
153 Double_t r[3]={0}, z[3]={startPoint-step, startPoint, startPoint+step};
155 TVector3 **points = new TVector3*[2]; // points[0] for the muon, points[1] for the direction parallel to the z-axis defined by the given (x,y)
157 for (Int_t i=0; i<3; i++) {
158 AliMUONTrackExtrap::ExtrapToZ(param, z[i]);
159 points[0] = new TVector3(param->GetNonBendingCoor(),param->GetBendingCoor(),z[i]);
160 points[1] = new TVector3(xy[0],xy[1],z[i]);
161 r[i] = GetDistanceBetweenPoints(points,2);
162 for (Int_t iMu=0; iMu<2; iMu++) delete points[iMu];
165 Int_t researchDirection = 0;
167 if (r[0]>r[1] && r[1]>r[2]) researchDirection = +1; // towards z positive
168 else if (r[0]<r[1] && r[1]<r[2]) researchDirection = -1; // towards z negative
169 else if (r[0]<r[1] && r[1]>r[2]) {
170 printf("E-AliMFTAnalysisTools::ExtrapAODMuonToXY: Point of closest approach cannot be found (no minima)\n");
176 while (TMath::Abs(researchDirection)>0.5) {
178 if (researchDirection>0) {
181 z[2] = z[1]+researchDirection*step;
186 z[0] = z[1]+researchDirection*step;
188 if (TMath::Abs(z[0])>900.) {
189 printf("E-AliMFTAnalysisTools::ExtrapAODMuonToXY: Point of closest approach cannot be found (no minima in the fiducial region)\n");
195 for (Int_t i=0; i<3; i++) {
196 AliMUONTrackExtrap::ExtrapToZ(param, z[i]);
197 points[0] = new TVector3(param->GetNonBendingCoor(),param->GetBendingCoor(),z[i]);
198 points[1] = new TVector3(xy[0],xy[1],z[i]);
199 r[i] = GetDistanceBetweenPoints(points,2);
200 for (Int_t iMu=0; iMu<2; iMu++) delete points[iMu];
204 if (r[0]>r[1] && r[1]>r[2]) researchDirection = +1; // towards z positive
205 else if (r[0]<r[1] && r[1]<r[2]) researchDirection = -1; // towards z negative
209 // now we now that the minimum is between z[0] and z[2] and we search for it
212 while (step>AliMFTConstants::fPrecisionPointOfClosestApproach) {
215 for (Int_t i=0; i<3; i++) {
216 AliMUONTrackExtrap::ExtrapToZ(param, z[i]);
217 points[0] = new TVector3(param->GetNonBendingCoor(),param->GetBendingCoor(),z[i]);
218 points[1] = new TVector3(xy[0],xy[1],z[i]);
219 r[i] = GetDistanceBetweenPoints(points,2);
220 for (Int_t iMu=0; iMu<2; iMu++) delete points[iMu];
222 if (r[0]<r[1]) z[1] = z[0];
223 else if (r[2]<r[1]) z[1] = z[2];
229 Double_t xyMuon[2] = {0};
230 ExtrapAODMuonToZ(muon, zFinal, xyMuon, kinem, cov);
236 //====================================================================================================================================================
238 Bool_t AliMFTAnalysisTools::GetAODMuonOffset(AliAODTrack *muon, Double_t xv, Double_t yv, Double_t zv, Double_t &offset) {
240 Double_t xy[2] = {0};
241 ExtrapAODMuonToZ(muon, zv, xy);
243 offset = TMath::Sqrt((xv-xy[0])*(xv-xy[0]) + (yv-xy[1])*(yv-xy[1]));
249 //====================================================================================================================================================
251 Bool_t AliMFTAnalysisTools::GetAODMuonOffsetZ(AliAODTrack *muon, Double_t xv, Double_t yv, Double_t zv, Double_t &offset) {
253 Double_t xy[2] = {xv, yv};
255 TLorentzVector kinem(0,0,0,0);
258 ExtrapAODMuonToXY(muon, xy, zFinal, kinem, cov);
260 offset = TMath::Abs(zFinal - zv);
266 //====================================================================================================================================================
268 Bool_t AliMFTAnalysisTools::GetAODMuonWeightedOffset(AliAODTrack *muon, Double_t xv, Double_t yv, Double_t zv, Double_t &offset) {
270 Double_t xy[2] = {0};
271 TLorentzVector kinem(0,0,0,0);
274 ExtrapAODMuonToZ(muon, zv, xy, kinem, cov);
276 TMatrixD covCoordinates(2,2);
277 covCoordinates(0,0) = cov(0,0);
278 covCoordinates(0,1) = cov(0,2);
279 covCoordinates(1,0) = cov(2,0);
280 covCoordinates(1,1) = cov(2,2);
282 if (covCoordinates.Determinant() < covCoordinates.GetTol()) return kFALSE;
284 if (TDecompLU::InvertLU(covCoordinates,covCoordinates.GetTol(),0)) {
286 TMatrixD covCoordinatesInverse = covCoordinates;
287 Double_t dX = xy[0] - xv;
288 Double_t dY = xy[1] - yv;
290 offset = TMath::Sqrt(0.5*(dX*dX*covCoordinatesInverse(0,0) +
291 dY*dY*covCoordinatesInverse(1,1) +
292 2.*dX*dY*covCoordinatesInverse(0,1)));
302 //====================================================================================================================================================
304 Double_t AliMFTAnalysisTools::GetPseudoProperDecayTimeXY(Double_t xVtx, Double_t yVtx,
305 Double_t xDimu, Double_t yDimu,
306 Double_t mDimu, Double_t ptDimu) {
308 // pseudo-proper decay time of a particle produced in the primary vertex and decaying into a dimuon (+ X)
309 // evaluated using the transverse degree of freedom of the decay topology
312 Double_t decayLengthXY = TMath::Sqrt((xVtx-xDimu)*(xVtx-xDimu)+(yVtx-yDimu)*(yVtx-yDimu));
313 return (decayLengthXY * mDimu/ptDimu)/TMath::Ccgs()*1E12; // in ps
320 //====================================================================================================================================================
322 Double_t AliMFTAnalysisTools::GetPseudoProperDecayTimeZ(Double_t zVtx,
324 Double_t mDimu, Double_t pzDimu) {
326 // pseudo-proper decay time of a particle produced in the primary vertex and decaying into a dimuon (+ X)
327 // evaluated using the longitudinal degree of freedom of the decay topology
330 Double_t decayLengthZ = zDimu - zVtx;
331 return (decayLengthZ * mDimu/pzDimu)/TMath::Ccgs()*1E12; // in ps
338 //====================================================================================================================================================
340 Bool_t AliMFTAnalysisTools::CalculatePCA(AliAODDimuon *dimuon, Double_t *pca, Double_t &pcaQuality, TLorentzVector &kinem) {
342 TObjArray *muons = new TObjArray();
343 muons -> Add(dimuon->GetMu(0));
344 muons -> Add(dimuon->GetMu(1));
346 Bool_t result = CalculatePCA(muons, pca, pcaQuality, kinem);
352 //====================================================================================================================================================
354 Bool_t AliMFTAnalysisTools::CalculatePCA(TObjArray *muons, Double_t *pca, Double_t &pcaQuality, TLorentzVector &kinem) {
356 const Int_t nMuons = muons->GetEntriesFast();
357 if (nMuons<2 || nMuons>AliMFTConstants::fNMaxMuonsForPCA) {
358 printf("W-AliMFTAnalysisTools::CalculatePCA: number of muons not valid\n");
362 Double_t fXPointOfClosestApproach=0, fYPointOfClosestApproach=0, fZPointOfClosestApproach=0;
364 AliAODTrack *muon[AliMFTConstants::fNMaxMuonsForPCA] = {0};
365 AliMUONTrackParam *param[AliMFTConstants::fNMaxMuonsForPCA] = {0};
367 // Finding AliMUONTrackParam objects for each muon
369 for (Int_t iMu=0; iMu<nMuons; iMu++) {
370 muon[iMu] = (AliAODTrack*) muons->At(iMu);
371 if (TMath::Abs(muon[iMu]->PzAtDCA())<1.e-6) {
372 for(Int_t i=0;i<iMu;i++) delete param[i];
375 param[iMu] = new AliMUONTrackParam();
376 param[iMu] -> SetNonBendingCoor(muon[iMu]->XAtDCA());
377 param[iMu] -> SetBendingCoor(muon[iMu]->YAtDCA());
378 param[iMu] -> SetZ(AliMFTConstants::fZEvalKinem);
379 param[iMu] -> SetNonBendingSlope(muon[iMu]->PxAtDCA()/muon[iMu]->PzAtDCA());
380 param[iMu] -> SetBendingSlope(muon[iMu]->PyAtDCA()/muon[iMu]->PzAtDCA());
381 param[iMu] -> SetInverseBendingMomentum( muon[iMu]->Charge() * (1./muon[iMu]->PzAtDCA()) / (TMath::Sqrt(1+TMath::Power(muon[iMu]->PyAtDCA()/muon[iMu]->PzAtDCA(),2))) );
384 // here we want to understand in which direction we have to search the minimum...
386 Double_t step = 1.; // initial step, in cm
387 Double_t startPoint = 0.;
389 Double_t r[3]={0}, z[3]={startPoint-step, startPoint, startPoint+step};
391 TVector3 **points = new TVector3*[AliMFTConstants::fNMaxMuonsForPCA];
393 for (Int_t i=0; i<3; i++) {
394 for (Int_t iMu=0; iMu<nMuons; iMu++) {
395 // if (TMath::Abs(param[iMu]->GetInverseBendingMomentum())<1.) {
396 // printf("W-AliMFTAnalysisTools::CalculatePCA: Evoiding floating point exception in PCA finding\n");
399 AliMUONTrackExtrap::ExtrapToZ(param[iMu], z[i]);
400 points[iMu] = new TVector3(param[iMu]->GetNonBendingCoor(),param[iMu]->GetBendingCoor(),z[i]);
402 r[i] = GetDistanceBetweenPoints(points,nMuons);
403 for (Int_t iMu=0; iMu<nMuons; iMu++) delete points[iMu];
406 Int_t researchDirection = 0;
408 if (r[0]>r[1] && r[1]>r[2]) researchDirection = +1; // towards z positive
409 else if (r[0]<r[1] && r[1]<r[2]) researchDirection = -1; // towards z negative
410 else if (r[0]<r[1] && r[1]>r[2]) {
411 printf("E-AliMFTAnalysisTools::CalculatePCA: Point of closest approach cannot be found for dimuon (no minima)\n");
412 for (Int_t iMu=0;iMu<nMuons;iMu++) delete param[iMu];
417 while (TMath::Abs(researchDirection)>0.5) {
419 if (researchDirection>0) {
422 z[2] = z[1]+researchDirection*step;
427 z[0] = z[1]+researchDirection*step;
429 if (TMath::Abs(z[0])>900.) {
430 printf("E-AliMFTAnalysisTools::CalculatePCA: Point of closest approach cannot be found for dimuon (no minima in the fiducial region)\n");
431 for (Int_t iMu=0;iMu<nMuons;iMu++) delete param[iMu];
436 for (Int_t i=0; i<3; i++) {
437 for (Int_t iMu=0; iMu<nMuons; iMu++) {
438 AliMUONTrackExtrap::ExtrapToZ(param[iMu], z[i]);
439 points[iMu] = new TVector3(param[iMu]->GetNonBendingCoor(),param[iMu]->GetBendingCoor(),z[i]);
441 r[i] = GetDistanceBetweenPoints(points,nMuons);
442 for (Int_t iMu=0;iMu<nMuons;iMu++) delete points[iMu];
445 if (r[0]>r[1] && r[1]>r[2]) researchDirection = +1; // towards z positive
446 else if (r[0]<r[1] && r[1]<r[2]) researchDirection = -1; // towards z negative
450 // now we now that the minimum is between z[0] and z[2] and we search for it
455 while (step>AliMFTConstants::fPrecisionPointOfClosestApproach) {
458 for (Int_t i=0; i<3; i++) {
459 for (Int_t iMu=0; iMu<nMuons; iMu++) {
460 AliMUONTrackExtrap::ExtrapToZ(param[iMu], z[i]);
461 points[iMu] = new TVector3(param[iMu]->GetNonBendingCoor(),param[iMu]->GetBendingCoor(),z[i]);
463 r[i] = GetDistanceBetweenPoints(points,nMuons);
464 for (Int_t iMu=0;iMu<nMuons;iMu++) delete points[iMu];
466 // printf("Step #%d : %f %f %f\n",nSteps,r[0],r[1],r[2]);
467 if (r[0]<r[1]) z[1] = z[0];
468 else if (r[2]<r[1]) z[1] = z[2];
473 // if (TMath::Abs(z[1]-1.)<0.1) {
474 // printf("Minimum found in %f in %d steps. Step = %f. p1->X() = %f, p2->X() = %f, p1->Y() = %f, p2->Y() = %f\n",
475 // z[1], nSteps, step, points[0]->X(), points[1]->X(), points[0]->Y(), points[1]->Y());
476 // printf("m1->X() = %f, m2->X() = %f, m1->Y() = %f, m2->Y() = %f\n",
477 // muon[0]->XAtDCA(),muon[1]->XAtDCA(), muon[0]->YAtDCA(),muon[1]->YAtDCA());
480 // Once z of minimum is found, we evaluate the x and y coordinates by averaging over the contributing tracks
482 fZPointOfClosestApproach = z[1];
483 fXPointOfClosestApproach = 0.;
484 fYPointOfClosestApproach = 0.;
485 for (Int_t iMu=0; iMu<nMuons; iMu++) {
486 AliMUONTrackExtrap::ExtrapToZ(param[iMu], fZPointOfClosestApproach);
487 fXPointOfClosestApproach += param[iMu]->GetNonBendingCoor();
488 fYPointOfClosestApproach += param[iMu]->GetBendingCoor();
490 fXPointOfClosestApproach /= Double_t(nMuons);
491 fYPointOfClosestApproach /= Double_t(nMuons);
493 pca[0] = fXPointOfClosestApproach;
494 pca[1] = fYPointOfClosestApproach;
495 pca[2] = fZPointOfClosestApproach;
497 // Evaluating the kinematics of the N-muon
499 Double_t pTot[3] = {0};
501 Double_t massMu = TDatabasePDG::Instance()->GetParticle("mu-")->Mass();
502 for (Int_t iMu=0; iMu<nMuons; iMu++) {
503 pTot[0] += param[iMu]->Px();
504 pTot[1] += param[iMu]->Py();
505 pTot[2] += param[iMu]->Pz();
506 ene += TMath::Sqrt(massMu*massMu + param[iMu]->Px()*param[iMu]->Px() + param[iMu]->Py()*param[iMu]->Py() + param[iMu]->Pz()*param[iMu]->Pz());
509 kinem.SetPxPyPzE(pTot[0], pTot[1], pTot[2], ene);
511 // Evaluating the PCA quality of the N-muon
513 Double_t sum=0.,squareSum=0.;
514 for (Int_t iMu=0; iMu<nMuons; iMu++) {
515 Double_t wOffset = 0;
516 if (!GetAODMuonWeightedOffset(muon[iMu],fXPointOfClosestApproach, fYPointOfClosestApproach, fZPointOfClosestApproach, wOffset)) {
517 for(Int_t jMu=0;jMu<nMuons;jMu++) delete param[jMu];
521 Double_t f = TMath::Exp(-0.5 * wOffset);
525 if (sum > 0.) pcaQuality = (sum-squareSum/sum) / (nMuons-1);
526 else pcaQuality = 0.;
528 for(Int_t iMu=0;iMu<nMuons;iMu++) delete param[iMu];
534 //=========================================================================================================================
536 Double_t AliMFTAnalysisTools::GetDistanceBetweenPoints(TVector3 **points, Int_t nPoints) {
538 if (nPoints>AliMFTConstants::fNMaxMuonsForPCA) {
539 printf("W-AliMFTAnalysisTools::GetDistanceBetweenPoints: number of points not valid\n");
543 if (nPoints<2) return 0.;
544 if (nPoints<3) return TMath::Sqrt( (points[0]->X()-points[1]->X()) * (points[0]->X()-points[1]->X()) +
545 (points[0]->Y()-points[1]->Y()) * (points[0]->Y()-points[1]->Y()) );
546 // (points[0]->Z()-points[1]->Z()) * (points[0]->Z()-points[1]->Z()) );
548 const Int_t nEdgesMax = ((AliMFTConstants::fNMaxMuonsForPCA) * (AliMFTConstants::fNMaxMuonsForPCA - 1)) / 2;
550 Int_t startID[nEdgesMax] = {0};
551 Int_t stopID[nEdgesMax] = {0};
552 Double_t edgeLength[nEdgesMax] = {0};
554 Bool_t pointStatus[AliMFTConstants::fNMaxMuonsForPCA] = {0};
557 for (Int_t i=0; i<nPoints-1; i++) {
558 for (Int_t j=i+1; j<nPoints; j++) {
559 edgeLength[nEdges] = TMath::Sqrt( (points[i]->X()-points[j]->X()) * (points[i]->X()-points[j]->X()) +
560 (points[i]->Y()-points[j]->Y()) * (points[i]->Y()-points[j]->Y()) +
561 (points[i]->Z()-points[j]->Z()) * (points[i]->Z()-points[j]->Z()) );
573 for (Int_t iEdge=0; iEdge<nEdges-1; iEdge++) {
574 min = edgeLength[iEdge];
576 for (Int_t j=iEdge+1; j<nEdges; j++) {
577 if (edgeLength[j]<min) {
585 Double_t edgeLengthMin = edgeLength[iMin];
586 Int_t startIDmin = startID[iMin];
587 Int_t stopIDmin = stopID[iMin];
589 edgeLength[iMin] = edgeLength[iEdge];
590 startID[iMin] = startID[iEdge];
591 stopID[iMin] = stopID[iEdge];
593 edgeLength[iEdge] = edgeLengthMin;
594 startID[iEdge] = startIDmin;
595 stopID[iEdge] = stopIDmin;
603 Double_t length = 0.;
604 for (Int_t i=0; i<nEdges; i++) {
605 if (!(pointStatus[startID[i]] && pointStatus[stopID[i]])) {
606 pointStatus[startID[i]] = kTRUE;
607 pointStatus[stopID[i]] = kTRUE;
608 length += edgeLength[i];
616 //====================================================================================================================================================
618 void AliMFTAnalysisTools::ConvertCovMatrixMUON2AOD(const TMatrixD& covMUON, Double_t covAOD[21]) {
620 // Converts the cov matrix from the MUON format (TMatrixD) to the AOD one (Double_t[21])
622 // Cov(x,x) ... : cv[0]
623 // Cov(x,slopeX) ... : cv[1] cv[2]
624 // Cov(x,y) ... : cv[3] cv[4] cv[5]
625 // Cov(x,slopeY) ... : cv[6] cv[7] cv[8] cv[9]
626 // Cov(x,invP_yz) ... : cv[10] cv[11] cv[12] cv[13] cv[14]
627 // not-used ... : cv[15] cv[16] cv[17] cv[18] cv[19] cv[20]
629 covAOD[0] = covMUON(0,0);
631 covAOD[1] = covMUON(1,0);
632 covAOD[2] = covMUON(1,1);
634 covAOD[3] = covMUON(2,0);
635 covAOD[4] = covMUON(2,1);
636 covAOD[5] = covMUON(2,2);
638 covAOD[6] = covMUON(3,0);
639 covAOD[7] = covMUON(3,1);
640 covAOD[8] = covMUON(3,2);
641 covAOD[9] = covMUON(3,3);
643 covAOD[10] = covMUON(4,0);
644 covAOD[11] = covMUON(4,1);
645 covAOD[12] = covMUON(4,2);
646 covAOD[13] = covMUON(4,3);
647 covAOD[14] = covMUON(4,4);
658 //====================================================================================================================================================
660 const TMatrixD AliMFTAnalysisTools::ConvertCovMatrixAOD2MUON(AliAODTrack *muon) {
662 Double_t covAOD[21] = {0};
663 muon -> GetCovarianceXYZPxPyPz(covAOD);
665 TMatrixD covMUON(5,5);
667 covMUON(0,0) = covAOD[0];
669 covMUON(1,0) = covAOD[1];
670 covMUON(1,1) = covAOD[2];
672 covMUON(2,0) = covAOD[3];
673 covMUON(2,1) = covAOD[4];
674 covMUON(2,2) = covAOD[5];
676 covMUON(3,0) = covAOD[6];
677 covMUON(3,1) = covAOD[7];
678 covMUON(3,2) = covAOD[8];
679 covMUON(3,3) = covAOD[9];
681 covMUON(4,0) = covAOD[10];
682 covMUON(4,1) = covAOD[11];
683 covMUON(4,2) = covAOD[12];
684 covMUON(4,3) = covAOD[13];
685 covMUON(4,4) = covAOD[14];
691 //====================================================================================================================================================
693 Bool_t AliMFTAnalysisTools::IsCorrectMatch(AliAODTrack *muon) {
695 for (Int_t iPlane=0; iPlane<AliMFTConstants::fNMaxPlanes; iPlane++) if (IsWrongCluster(muon, iPlane)) return kFALSE;
700 //====================================================================================================================================================
702 TString AliMFTAnalysisTools::GetGenerator(Int_t label, AliAODMCHeader* header) {
704 // get the name of the generator that produced a given particle
706 Int_t partCounter = 0;
707 TList *genHeaders = header->GetCocktailHeaders();
708 Int_t nGenHeaders = genHeaders->GetEntries();
710 for (Int_t i=0; i<nGenHeaders; i++){
711 AliGenEventHeader *gh = (AliGenEventHeader*) genHeaders->At(i);
712 TString genName = gh->GetName();
713 Int_t nPart = gh->NProduced();
714 if (label>=partCounter && label<(partCounter+nPart)) return genName;
715 partCounter += nPart;
723 //====================================================================================================================================================
725 void AliMFTAnalysisTools::GetTrackPrimaryGenerator(AliAODTrack *track, AliAODMCHeader *header, TClonesArray *arrayMC, TString &nameGen) {
727 // method to check if a track comes from a given generator
729 Int_t label = TMath::Abs(track->GetLabel());
730 nameGen = GetGenerator(label,header);
732 // In case the particle is not primary nameGen will contain blank spaces. In this case, we search backward for the primary which originated the chain
734 while (nameGen.IsWhitespace()) {
735 AliAODMCParticle *mcPart = (AliAODMCParticle*) arrayMC->At(label);
737 printf("AliMFTAnalysisTools::GetTrackPrimaryGenerator - BREAK: No valid AliAODMCParticle at label %i\n",label);
740 Int_t motherLabel = mcPart->GetMother();
741 if (motherLabel < 0) {
742 printf("AliMFTAnalysisTools::GetTrackPrimaryGenerator - BREAK: Reached primary particle without valid mother\n");
746 nameGen = GetGenerator(label,header);
753 //====================================================================================================================================================
755 Bool_t AliMFTAnalysisTools::IsTrackInjected(AliAODTrack *track, AliAODMCHeader *header, TClonesArray *arrayMC) {
757 // method to check if a track comes from the signal event or from the underlying Hijing event
761 GetTrackPrimaryGenerator(track,header,arrayMC,nameGen);
763 if (nameGen.IsWhitespace() || nameGen.Contains("ijing")) return kFALSE;
769 //====================================================================================================================================================
771 Bool_t AliMFTAnalysisTools::TranslateMuon(AliAODTrack *muon, Double_t vtxInitial[3], Double_t vtxFinal[3]) {
773 if (!(muon->PzAtDCA()!=0)) return kFALSE;
775 AliMUONTrackParam *param = new AliMUONTrackParam();
777 Double_t deltaVtx[3] = {0};
778 for (Int_t i=0; i<3; i++) deltaVtx[i] = vtxInitial[i] - vtxFinal[i];
780 param -> SetNonBendingCoor(muon->XAtDCA());
781 param -> SetBendingCoor(muon->YAtDCA());
782 param -> SetZ(AliMFTConstants::fZEvalKinem);
783 param -> SetNonBendingSlope(muon->PxAtDCA()/muon->PzAtDCA());
784 param -> SetBendingSlope(muon->PyAtDCA()/muon->PzAtDCA());
785 param -> SetInverseBendingMomentum( muon->Charge() * (1./muon->PzAtDCA()) / (TMath::Sqrt(1+TMath::Power(muon->PyAtDCA()/muon->PzAtDCA(),2))) );
787 // This will be interpreted as if the track (produced in an event having the primary vertex in vtxInitial)
788 // were produced in an event having the primary vertex in vtxFinal
790 AliMUONTrackExtrap::ExtrapToZ(param, deltaVtx[2]);
791 muon->SetXYAtDCA(param->GetNonBendingCoor() - deltaVtx[0], param->GetBendingCoor() - deltaVtx[1]);
792 muon->SetPxPyPzAtDCA(param->Px(), param->Py(), param->Pz());
800 //====================================================================================================================================================
802 Bool_t AliMFTAnalysisTools::TranslateMuonToOrigin(AliAODTrack *muon, Double_t vtx[3]) {
804 Double_t origin[3] = {0,0,0};
806 return TranslateMuon(muon, vtx, origin);
810 //====================================================================================================================================================
812 Bool_t AliMFTAnalysisTools::IsPDGCharm(Int_t pdgCode) {
814 pdgCode = TMath::Abs(pdgCode/100);
815 if (pdgCode>9) pdgCode /= 10;
816 if (pdgCode == 4 ) return kTRUE;
821 //====================================================================================================================================================
823 Bool_t AliMFTAnalysisTools::IsPDGBeauty(Int_t pdgCode) {
825 pdgCode = TMath::Abs(pdgCode/100);
826 if (pdgCode>9) pdgCode /= 10;
827 if (pdgCode == 5) return kTRUE;
832 //====================================================================================================================================================
834 Bool_t AliMFTAnalysisTools::IsPDGResonance(Int_t pdgCode) {
836 Int_t id = pdgCode%100000;
837 return (!((id-id%10)%110));
841 //====================================================================================================================================================