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 **************************************************************************/
18 #include "AliExternalComparison.h"
19 #include "AliExternalTrackParam.h"
20 #include "AliTrackReference.h"
21 #include "THnSparse.h"
22 #include "TParticle.h"
24 #include "TParticlePDG.h"
25 #include "TParticle.h"
26 #include "TTreeStream.h"
29 ClassImp(AliExternalComparison)
32 AliExternalComparison::AliExternalComparison()
40 // Default constructor
45 AliExternalComparison::AliExternalComparison(const Text_t *name, const Text_t *title)
53 // Non default cosntructor
57 AliExternalComparison::AliExternalComparison(const AliExternalComparison& comp)
59 fResolHistos(new TObjArray(*(comp.fResolHistos))),
60 fPullHistos(new TObjArray(*(comp.fPullHistos))),
61 fRangeMatrix(new TMatrixD(*(comp.fRangeMatrix))),
62 fCutMatrix(new TMatrixD(*(comp.fCutMatrix)))
69 AliExternalComparison& AliExternalComparison::operator=(const AliExternalComparison& comp)
75 TNamed::operator=(comp);
76 fResolHistos=new TObjArray(*(comp.fResolHistos));
77 fPullHistos=new TObjArray(*(comp.fPullHistos));
78 fRangeMatrix=new TMatrixD(*(comp.fRangeMatrix));
79 fCutMatrix=new TMatrixD(*(comp.fCutMatrix));
85 AliExternalComparison::~AliExternalComparison(){
89 if (fResolHistos) fResolHistos->Delete();
90 if (fPullHistos) fPullHistos->Delete();
91 delete fResolHistos; // resolution histogram
92 delete fPullHistos; // pull histogram
93 delete fRangeMatrix; // range matrix
94 delete fCutMatrix; // range matrix
98 void AliExternalComparison::Analyze() {
105 Long64_t AliExternalComparison::Merge(TCollection *const li) {
109 TIterator* iter = li->MakeIterator();
110 AliExternalComparison* comp = 0;
111 TString strName(GetName());
112 while ((comp = (AliExternalComparison*)iter->Next())) {
113 if (!comp->InheritsFrom(AliExternalComparison::Class())) {
116 if (strName.CompareTo(comp->GetName())!=0) return -1;
117 // add histograms here...
123 void AliExternalComparison::Add(AliExternalComparison *const comp){
125 // Add comparison object
127 if (!fResolHistos) return;
128 for (Int_t i=0;i<5;i++){
129 THnSparse * h0 = (THnSparse*)fResolHistos->At(i);
130 THnSparse * h1 = (THnSparse*)comp->fResolHistos->At(i);
131 if (h0&&h1) h0->Add(h1);
132 h0 = (THnSparse*)fPullHistos->At(i);
133 h1 = (THnSparse*)comp->fPullHistos->At(i);
134 if (h0&&h1) h0->Add(h1);
140 void AliExternalComparison::Process(const AliExternalTrackParam *param0, const AliExternalTrackParam *param1){
142 // Process- fill histogram with residuals
143 // Tracks has to be in the same local X
145 if (!AcceptPair(param0,param1)) return;
147 if (!fResolHistos) MakeHistos();
150 const Double_t *p0 = param0->GetParameter();
151 const Double_t *p1 = param1->GetParameter();
152 const Double_t *c0 = param0->GetCovariance();
153 const Double_t *c1 = param1->GetCovariance();
162 vec[4] = TMath::Sqrt(TMath::Abs(p1[4]))* ((p1[4]>0)? 1:-1);
163 vec[5] = TMath::Sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]);
164 vec[6] = TMath::ATan2(xyz[1],xyz[0]);
169 vec[7] = p0[0]-p1[0];
170 his = (THnSparse*)fResolHistos->At(0);
172 vec[7]=(p0[0]-p1[0])/TMath::Sqrt(c0[0]+c1[0]);
173 his = (THnSparse*)fPullHistos->At(0);
177 vec[7] = p0[1]-p1[1];
178 his = (THnSparse*)fResolHistos->At(1);
180 vec[7]=(p0[1]-p1[1])/TMath::Sqrt(c0[2]+c1[2]);
181 his = (THnSparse*)fPullHistos->At(1);
184 vec[7] = p0[2]-p1[2];
185 his = (THnSparse*)fResolHistos->At(2);
187 vec[7]=(p0[2]-p1[2])/TMath::Sqrt(c0[5]+c1[5]);
188 his = (THnSparse*)fPullHistos->At(2);
191 vec[7] = p0[3]-p1[3];
192 his = (THnSparse*)fResolHistos->At(3);
194 vec[7]=(p0[3]-p1[3])/TMath::Sqrt(c0[9]+c1[9]);
195 his = (THnSparse*)fPullHistos->At(3);
198 vec[7] = p0[4]-p1[4];
199 his = (THnSparse*)fResolHistos->At(4);
201 vec[7]=(p0[4]-p1[4])/TMath::Sqrt(c0[14]+c1[14]);
202 his = (THnSparse*)fPullHistos->At(4);
206 void AliExternalComparison::Process(const AliExternalTrackParam *param0, TParticle *part){
210 AliExternalTrackParam *param1 = MakeExternalParam(part);
211 param1->Rotate(param0->GetAlpha());
212 if (param0&¶m1) Process(param0, param1);
214 void AliExternalComparison::Process(const AliExternalTrackParam *param0, TParticle *part, const AliTrackReference *ref){
218 AliExternalTrackParam *param1 = MakeExternalParam(part,ref);
219 param1->Rotate(param0->GetAlpha());
220 if (param0&¶m1) Process(param0, param1);
223 THnSparse * AliExternalComparison::GetHisto(Int_t ivar, Int_t type) {
227 if (!fResolHistos) return 0;
228 if (ivar<0 || ivar>4) return 0;
229 if (type==0) return (THnSparse*)fResolHistos->At(ivar);
230 if (type==1) return (THnSparse*)fPullHistos->At(ivar);
234 void AliExternalComparison::MakeHistos(){
238 if (!fRangeMatrix) SetDefaultRange();
239 TMatrixD & mat = *fRangeMatrix;
241 Double_t xmin[8], xmax[8];
242 Double_t xpmin[8], xpmax[8];
244 for (Int_t i=0;i<7;i++){
249 nbins[i]=TMath::Nint(mat(i,2));
252 fResolHistos = new TObjArray(5);
253 fPullHistos = new TObjArray(5);
255 for (Int_t idelta=0;idelta<5;idelta++){
256 xmin[7]=mat(idelta+7,0);
257 xmax[7]=mat(idelta+7,1);
258 nbins[7]=TMath::Nint(mat(idelta+7,2));
259 fResolHistos->AddAt(new THnSparseF(Form("Resol%s",GetName()),Form("Resol%s",GetTitle()),
260 8,nbins,xmin,xmax),idelta);
263 fPullHistos->AddAt(new THnSparseF(Form("Pull%s",GetName()),Form("Pull%s",GetTitle()),
264 8,nbins,xmin,xmax),idelta);
270 void AliExternalComparison::SetDefaultRange(Float_t scale,Float_t arm, Int_t nbins){
272 // set default binning
273 // scale - define position range
279 if (!fRangeMatrix) fRangeMatrix = new TMatrixD(12,3);
280 TMatrixD & mat = *fRangeMatrix;
284 mat(0,0)=-50; mat(0,1)=50; mat(0,2)=50; // P0 -y range
285 mat(1,0)=-250; mat(1,1)=250; mat(1,2)=50; // P1 -Z range
286 mat(2,0)=-0.99; mat(2,1)=0.99; mat(2,2)=20; // P2 -snp range
287 mat(3,0)=-1.5; mat(3,1)=1.5; mat(3,2)=20; // P3 -tantheta range
288 mat(4,0)=-3; mat(4,1)=3; mat(4,2)=50; // sqrt(P4) -sqrt(1/pt) range
290 mat(5,0)= 0; mat(5,1)=250; mat(5,2)=50; // R range
291 mat(6,0)= -TMath::Pi(); mat(6,1)=TMath::Pi(); mat(6,2)=18*4; // fi range
295 mat(7,0)=-scale; mat(7,1)=scale; mat(7,2)=nbins; // P0 -y range
296 mat(8,0)=-scale; mat(8,1)=scale; mat(8,2)=nbins; // P1 -Z range
297 mat(9,0)=-scale/arm; mat(9,1)=scale/arm; mat(9,2)=nbins; // P2 -snp range
298 mat(10,0)=-scale/arm; mat(10,1)=scale/arm; mat(10,2)=nbins; // P3 -tantheta range
299 mat(11,0)=-1; mat(11,1)=1; mat(11,2)=nbins; // sqrt(P4) -sqrt(1/pt) range
303 void AliExternalComparison::SetDefaultCuts(){
306 if (!fCutMatrix) fCutMatrix = new TMatrixD(10,1);
307 TMatrixD & mat = *fCutMatrix;
323 void AliExternalComparison::SetParameterRange(Int_t param, Float_t min, Float_t max, Int_t nbins){
327 if (!fRangeMatrix) SetDefaultRange();
328 TMatrixD & mat = *fRangeMatrix;
331 mat(param,0)=min; mat(param,1)=max; mat(param,2)=nbins;
334 void AliExternalComparison::SetResolRange(Int_t param, Float_t min, Float_t max, Int_t nbins){
338 if (!fRangeMatrix) SetDefaultRange();
339 TMatrixD & mat = *fRangeMatrix;
342 mat(7+param,0)=min; mat(7+param,1)=max; mat(7+param,2)=nbins;
345 void AliExternalComparison::SetDistCut(Float_t dP0, Float_t dP1,Float_t dP2,Float_t dP3, Float_t dP4){
349 if (!fCutMatrix) SetDefaultCuts();
350 TMatrixD & mat = *fCutMatrix;
359 void AliExternalComparison::SetPullDistCut(Float_t dnP0, Float_t dnP1,Float_t dnP2,Float_t dnP3, Float_t dnP4){
363 if (!fCutMatrix) SetDefaultCuts();
364 TMatrixD & mat = *fCutMatrix;
365 mat(5,0)=dnP0; //dnP0
366 mat(6,0)=dnP1; //dnP1
367 mat(7,0)=dnP2; //dnP2
368 mat(8,0)=dnP3; //dnP3
369 mat(9,0)=dnP4; //dnP4
372 Bool_t AliExternalComparison::AcceptPair(const AliExternalTrackParam *param0, const AliExternalTrackParam *param1){
377 if (!fCutMatrix) SetDefaultCuts();
378 TMatrixD & mat = *fCutMatrix;
380 const Double_t *p0 = param0->GetParameter();
381 const Double_t *p1 = param1->GetParameter();
382 const Double_t *c0 = param0->GetCovariance();
383 const Double_t *c1 = param1->GetCovariance();
385 if (TMath::Abs(p0[0]-p1[0])>mat(0,0)) return kFALSE;
386 if (TMath::Abs(p0[1]-p1[1])>mat(1,0)) return kFALSE;
387 if (TMath::Abs(p0[2]-p1[2])>mat(2,0)) return kFALSE;
388 if (TMath::Abs(p0[3]-p1[3])>mat(3,0)) return kFALSE;
389 if (TMath::Abs(p0[4]-p1[4])>mat(4,0)) return kFALSE;
390 if ((c0[0]+c1[0])<0) return kFALSE;
391 if ((c0[2]+c1[2])<0) return kFALSE;
392 if ((c0[5]+c1[5])<0) return kFALSE;
393 if ((c0[9]+c1[9])<0) return kFALSE;
394 if ((c0[14]+c1[14])<0) return kFALSE;
396 if (TMath::Abs((p0[0]-p1[0])/TMath::Sqrt(c0[0]+c1[0]))>mat(5,0)) return kFALSE;
397 if (TMath::Abs((p0[1]-p1[1])/TMath::Sqrt(c0[2]+c1[2]))>mat(6,0)) return kFALSE;
398 if (TMath::Abs((p0[2]-p1[2])/TMath::Sqrt(c0[5]+c1[5]))>mat(7,0)) return kFALSE;
399 if (TMath::Abs((p0[3]-p1[3])/TMath::Sqrt(c0[9]+c1[9]))>mat(8,0)) return kFALSE;
400 if (TMath::Abs((p0[4]-p1[4])/TMath::Sqrt(c0[14]+c1[14]))>mat(9,0)) return kFALSE;
405 AliExternalTrackParam *AliExternalComparison::MakeExternalParam(TParticle *part, const AliTrackReference *ref){
407 // make a Kalman track from track reference
409 Double_t xyz[3]={ref->X(),ref->Y(),ref->Z()};
410 Double_t pxyz[3]={ref->Px(),ref->Py(),ref->Pz()};
412 for (Int_t i=0; i<21;i++) cv[i]=0;
413 if (!part->GetPDG()) return 0;
414 AliExternalTrackParam * param = new AliExternalTrackParam(xyz,pxyz,cv,TMath::Nint(part->GetPDG()->Charge()/3.));
419 AliExternalTrackParam * AliExternalComparison::MakeExternalParam(TParticle *part){
423 Double_t xyz[3]={part->Vx(),part->Vy(),part->Vz()};
424 Double_t pxyz[3]={part->Px(),part->Py(),part->Pz()};
426 for (Int_t i=0; i<21;i++) cv[i]=0;
427 if (!part->GetPDG()) return 0;
428 AliExternalTrackParam * param = new AliExternalTrackParam(xyz,pxyz,cv,TMath::Nint(part->GetPDG()->Charge()/3.));
435 void AliExternalComparison::MakeComparisonTree(const char * outname){
437 // make a comparison tree
438 // the tree will be written to the file - outname
441 TFile f("comp.root");
442 AliExternalComparison *comp = (AliExternalComparison*)f.Get("compAlign");
443 outname="compTree.root";
445 AliExternalComparison *comp = this;
446 TTreeSRedirector *pcstream = new TTreeSRedirector(outname);
449 Double_t position[10];
451 Int_t *bins = new Int_t[10];
454 for (Int_t isPull=0; isPull<2; isPull++){
455 for (Int_t ires=0;ires<5; ires++){
456 his = comp->GetHisto(ires,isPull);
459 Int_t ndim = his->GetNdimensions();
461 for (Long64_t i = 0; i < his->GetNbins(); ++i) {
462 value = his->GetBinContent(i, bins);
463 for (Int_t idim = 0; idim < ndim; idim++) {
464 position[idim] = his->GetAxis(idim)->GetBinCenter(bins[idim]);
466 (*pcstream)<<"Resol"<<
467 "isPull="<<isPull<< // normalized error indication
468 "index="<<ires<< // parameter difference index
469 "bincont="<<value<< // bin content
470 "val="<<position[7]<< // parameter difference
471 "p0="<<position[0]<< //P0
472 "p1="<<position[1]<< //P1
473 "p2="<<position[2]<< //P2
474 "p3="<<position[3]<< //P3
475 "p4="<<position[4]<< //P4
476 "R="<<position[5]<< //Radius
477 "phi="<<position[6]<< //Radius