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 //-----------------------------------------------------------------
17 // Implementation of the TOF PID class
18 // Very naive one... Should be made better by the detector experts...
19 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
20 //-----------------------------------------------------------------
23 #include "TClonesArray.h"
26 #include "AliTOFpidESD.h"
28 #include "AliESDtrack.h"
29 #include "AliTOFdigit.h"
31 #include <TGeant3.h> // For DtoM and InitGeo, should
32 #include "../STRUCT/AliBODY.h" // be removed after we switch to
33 #include "../STRUCT/AliFRAMEv2.h" // AliTOGeometry::GetPos
34 #include "AliTOFv4T0.h"
39 ClassImp(AliTOFpidESD)
41 //_________________________________________________________________________
42 static Int_t InitGeo() {
43 //gSystem->Load("libgeant321");
44 //new TGeant3("C++ Interface to Geant3");
46 AliBODY *body = new AliBODY("BODY", "Alice envelop");
47 body->CreateGeometry();
49 AliFRAMEv2 *frame = new AliFRAMEv2("FRAME", "Space Frame");
51 frame->CreateGeometry();
53 AliTOF *tof = new AliTOFv4T0("TOF", "TOF with Holes");
54 tof->CreateGeometry();
59 //_________________________________________________________________________
60 static Int_t DtoM(Int_t *dig, Float_t *g) {
62 Int_t lnam[kMAX],lnum[kMAX];
64 TGeant3 *geant3=(TGeant3*)gMC;
65 if (!geant3) {::Info("DtoM","no geant3 found !"); return 1;}
67 strncpy((Char_t*)(lnam+0),"ALIC",4); lnum[0]=1;
68 strncpy((Char_t*)(lnam+1),"B077",4); lnum[1]=1;
70 //4 padx if z<=0 then ...
71 if ((dig[1]==4)||(dig[1]==3)) dig[4]=AliTOFGeometry::NpadX()-dig[4];
73 if (dig[2]>7) dig[4]=AliTOFGeometry::NpadX()-dig[4];
75 if (dig[3]==1) dig[4]=AliTOFGeometry::NpadX()-dig[4];
81 if ((dig[1]==3)||(dig[1]==4)) dig[3]=AliTOFGeometry::NpadZ()-dig[3];
85 if (dig[1]==0) dig[2]=AliTOFGeometry::NStripC()-dig[2];
86 else if (dig[1]==1) dig[2]=AliTOFGeometry::NStripB()-dig[2];
90 dig[1]=AliTOFGeometry::NPlates()-dig[1];
93 dig[0]+=(AliTOFGeometry::NSectors()/2); dig[0]%=AliTOFGeometry::NSectors();
99 strncpy((Char_t*)(lnam+2),"B071",4); lnum[2]=9;
100 strncpy((Char_t*)(lnam+3),"BTO1",4); lnum[3]=1;
103 strncpy((Char_t*)(lnam+2),"B071",4); lnum[2]=10;
104 strncpy((Char_t*)(lnam+3),"BTO1",4); lnum[3]=1;
107 strncpy((Char_t*)(lnam+2),"B074",4); lnum[2]=4;
108 strncpy((Char_t*)(lnam+3),"BTO2",4); lnum[3]=1;
109 if (dig[1]>3) lnum[3]=2;
112 strncpy((Char_t*)(lnam+2),"B074",4); lnum[2]=5;
113 strncpy((Char_t*)(lnam+3),"BTO2",4); lnum[3]=1;
114 if (dig[1]>3) lnum[3]=2;
117 strncpy((Char_t*)(lnam+2),"B074",4); lnum[2]=1;
118 strncpy((Char_t*)(lnam+3),"BTO2",4); lnum[3]=1;
119 if (dig[1]>3) lnum[3]=2;
122 strncpy((Char_t*)(lnam+2),"B074",4); lnum[2]=2;
123 strncpy((Char_t*)(lnam+3),"BTO2",4); lnum[3]=1;
124 if (dig[1]>3) lnum[3]=2;
127 strncpy((Char_t*)(lnam+2),"B074",4); lnum[2]=3;
128 strncpy((Char_t*)(lnam+3),"BTO2",4); lnum[3]=1;
129 if (dig[1]>3) lnum[3]=2;
132 strncpy((Char_t*)(lnam+2),"B071",4); lnum[2]=1;
133 strncpy((Char_t*)(lnam+3),"BTO1",4); lnum[3]=1;
136 strncpy((Char_t*)(lnam+2),"B071",4); lnum[2]=2;
137 strncpy((Char_t*)(lnam+3),"BTO1",4); lnum[3]=1;
140 strncpy((Char_t*)(lnam+2),"B075",4); lnum[2]=1;
141 strncpy((Char_t*)(lnam+3),"BTO3",4); lnum[3]=1;
142 if (dig[1]>4) lnum[3]=2;
145 strncpy((Char_t*)(lnam+2),"B075",4); lnum[2]=2;
146 strncpy((Char_t*)(lnam+3),"BTO3",4); lnum[3]=1;
147 if (dig[1]>4) lnum[3]=2;
150 strncpy((Char_t*)(lnam+2),"B075",4); lnum[2]=3;
151 strncpy((Char_t*)(lnam+3),"BTO3",4); lnum[3]=1;
152 if (dig[1]>4) lnum[3]=2;
155 strncpy((Char_t*)(lnam+2),"B071",4); lnum[2]=3;
156 strncpy((Char_t*)(lnam+3),"BTO1",4); lnum[3]=1;
159 strncpy((Char_t*)(lnam+2),"B071",4); lnum[2]=4;
160 strncpy((Char_t*)(lnam+3),"BTO1",4); lnum[3]=1;
163 strncpy((Char_t*)(lnam+2),"B071",4); lnum[2]=5;
164 strncpy((Char_t*)(lnam+3),"BTO1",4); lnum[3]=1;
167 strncpy((Char_t*)(lnam+2),"B071",4); lnum[2]=6;
168 strncpy((Char_t*)(lnam+3),"BTO1",4); lnum[3]=1;
171 strncpy((Char_t*)(lnam+2),"B071",4); lnum[2]=7;
172 strncpy((Char_t*)(lnam+3),"BTO1",4); lnum[3]=1;
175 strncpy((Char_t*)(lnam+2),"B071",4); lnum[2]=8;
176 strncpy((Char_t*)(lnam+3),"BTO1",4); lnum[3]=1;
179 ::Info("DtoM","Wrong sector number : %d !",dig[0]);
185 strncpy((Char_t*)(lnam+4),"FTOC",4); lnum[4]=1;
186 if (dig[0]==1 || dig[0]==2 ) lnum[4]=2;
187 if (dig[0]>=8 && dig[0]<=9) lnum[4]=2;
188 if (dig[0]>=13 && dig[0]<=18) lnum[4]=2;
189 strncpy((Char_t*)(lnam+5),"FLTC",4); lnum[5]=0;
192 strncpy((Char_t*)(lnam+4),"FTOB",4); lnum[4]=1;
193 if (dig[0]==1 || dig[0]==2 ) lnum[4]=2;
194 if (dig[0]>=8 && dig[0]<=9) lnum[4]=2;
195 if (dig[0]>=13 && dig[0]<=18) lnum[4]=2;
196 strncpy((Char_t*)(lnam+5),"FLTB",4); lnum[5]=0;
199 strncpy((Char_t*)(lnam+4),"FTOA",4); lnum[4]=0;
200 strncpy((Char_t*)(lnam+5),"FLTA",4); lnum[5]=0;
203 strncpy((Char_t*)(lnam+4),"FTOB",4); lnum[4]=1;
204 strncpy((Char_t*)(lnam+5),"FLTB",4); lnum[5]=0;
207 strncpy((Char_t*)(lnam+4),"FTOC",4); lnum[4]=1;
208 strncpy((Char_t*)(lnam+5),"FLTC",4); lnum[5]=0;
211 ::Info("DtoM","Wrong module number : %d !",dig[1]);
216 if (dig[2]<0/*1*/ || dig[2]>19) {
217 ::Info("DtoM","Wrong strip number : %d !",dig[2]);
220 strncpy((Char_t*)(lnam+6),"FSTR",4); lnum[6]=dig[2];
221 strncpy((Char_t*)(lnam+7),"FSEN",4); lnum[7]=0;
224 if (dig[3]<1 || dig[3]>2) {
225 ::Info("DtoM","Wrong z-division number : %d !",dig[3]);
228 strncpy((Char_t*)(lnam+8),"FSEZ",4); lnum[8]=dig[3];
231 if (dig[4]<1 || dig[4]>48) {
232 ::Info("DtoM","Wrong x-division number : %d !",dig[4]);
235 strncpy((Char_t*)(lnam+9),"FSEX",4); lnum[9]=dig[4];
236 strncpy((Char_t*)(lnam+10),"FPAD",4); lnum[10]=0;
238 Gcvolu_t *gcvolu=geant3->Gcvolu(); gcvolu->nlevel=0;
239 Int_t err=geant3->Glvolu(11,lnam,lnum); //11-th level
241 ::Info("DtoM","Wrong volume !"); return 3;
243 Float_t l[3]={0.,0.,0}; geant3->Gdtom(l,g,1);
248 //_________________________________________________________________________
249 AliTOFpidESD::AliTOFpidESD(Double_t *param) throw (const Char_t *) {
251 // The main constructor
253 if (InitGeo()) throw "AliTOFpidESD: can not initialize the geometry !\n";
256 if (fTOFGeometry) delete fTOFGeometry;
257 fTOFGeometry = new AliTOFGeometry();
260 fDy=fTOFGeometry->XPad(); fDz=fTOFGeometry->ZPad();
269 //_________________________________________________________________________
271 //_________________________________________________________________________
272 Int_t AliTOFpidESD::LoadClusters(const TFile *df) {
274 //--------------------------------------------------------------------
275 //This function loads the TOF clusters
276 //--------------------------------------------------------------------
278 if (!((TFile *)df)->IsOpen()) {
279 Error("LoadClusters","file with the TOF digits has not been open !\n");
284 sprintf(name,"TreeD%d",GetEventNumber());
285 TTree *dTree=(TTree*)((TFile *)df)->Get(name);
287 Error("LoadClusters"," can't get the tree with digits !\n");
290 TBranch *branch=dTree->GetBranch("TOF");
292 Error("LoadClusters"," can't get the branch with the TOF digits !\n");
296 TClonesArray dummy("AliTOFdigit",10000), *digits=&dummy;
297 branch->SetAddress(&digits);
300 Int_t nd=digits->GetEntriesFast();
301 Info("LoadClusters","number of digits: %d",nd);
303 for (Int_t i=0; i<nd; i++) {
304 AliTOFdigit *d=(AliTOFdigit*)digits->UncheckedAt(i);
305 Int_t dig[5]; Float_t g[3];
306 dig[0]=d->GetSector();
307 dig[1]=d->GetPlate();
308 dig[2]=d->GetStrip();
312 // fTOFGeometry->GetPos(dig,g); // uncomment this
316 h[0]=TMath::Sqrt(g[0]*g[0]+g[1]*g[1]);
317 h[1]=TMath::ATan2(g[1],g[0]); h[2]=g[2];
318 h[3]=d->GetTdc(); h[4]=d->GetAdc();
320 AliTOFcluster *cl=new AliTOFcluster(h,d->GetTracks(),i);
328 //_________________________________________________________________________
329 Int_t AliTOFpidESD::LoadClusters(TTree *dTree) {
330 //--------------------------------------------------------------------
331 //This function loads the TOF clusters
332 //--------------------------------------------------------------------
333 TBranch *branch=dTree->GetBranch("TOF");
335 Error("LoadClusters"," can't get the branch with the TOF digits !\n");
339 TClonesArray dummy("AliTOFdigit",10000), *digits=&dummy;
340 branch->SetAddress(&digits);
343 Int_t nd=digits->GetEntriesFast();
344 Info("LoadClusters","number of digits: %d",nd);
346 for (Int_t i=0; i<nd; i++) {
347 AliTOFdigit *d=(AliTOFdigit*)digits->UncheckedAt(i);
348 Int_t dig[5]; Float_t g[3];
349 dig[0]=d->GetSector();
350 dig[1]=d->GetPlate();
351 dig[2]=d->GetStrip();
355 //fTOFGeometry->GetPos(dig,g);
359 h[0]=TMath::Sqrt(g[0]*g[0]+g[1]*g[1]);
360 h[1]=TMath::ATan2(g[1],g[0]); h[2]=g[2];
361 h[3]=d->GetTdc(); h[4]=d->GetAdc();
363 AliTOFcluster *cl=new AliTOFcluster(h,d->GetTracks(),i);
370 //_________________________________________________________________________
371 void AliTOFpidESD::UnloadClusters() {
372 //--------------------------------------------------------------------
373 //This function unloads TOF clusters
374 //--------------------------------------------------------------------
375 for (Int_t i=0; i<fN; i++) delete fClusters[i];
379 //_________________________________________________________________________
380 Int_t AliTOFpidESD::InsertCluster(AliTOFcluster *c) {
381 //--------------------------------------------------------------------
382 //This function adds a cluster to the array of clusters sorted in Z
383 //--------------------------------------------------------------------
384 if (fN==kMaxCluster) {
385 Error("InsertCluster","Too many clusters !\n");
389 if (fN==0) {fClusters[fN++]=c; return 0;}
390 Int_t i=FindClusterIndex(c->GetZ());
391 memmove(fClusters+i+1 ,fClusters+i,(fN-i)*sizeof(AliTOFcluster*));
392 fClusters[i]=c; fN++;
397 //_________________________________________________________________________
398 Int_t AliTOFpidESD::FindClusterIndex(Double_t z) const {
399 //--------------------------------------------------------------------
400 // This function returns the index of the nearest cluster
401 //--------------------------------------------------------------------
403 if (z <= fClusters[0]->GetZ()) return 0;
404 if (z > fClusters[fN-1]->GetZ()) return fN;
405 Int_t b=0, e=fN-1, m=(b+e)/2;
406 for (; b<e; m=(b+e)/2) {
407 if (z > fClusters[m]->GetZ()) b=m+1;
413 static int cmp(const void *p1, const void *p2) {
414 AliESDtrack *t1=*((AliESDtrack**)p1);
415 AliESDtrack *t2=*((AliESDtrack**)p2);
416 Double_t c1[15]; t1->GetExternalCovariance(c1);
417 Double_t c2[15]; t2->GetExternalCovariance(c2);
418 if (c1[0]*c1[2] <c2[0]*c2[2]) return -1;
419 if (c1[0]*c1[2]==c2[0]*c2[2]) return 0;
423 //_________________________________________________________________________
424 Int_t AliTOFpidESD::MakePID(AliESD *event)
427 // This function calculates the "detector response" PID probabilities
428 // Just for a bare hint...
430 static const Double_t kMasses[]={
431 0.000511, 0.105658, 0.139570, 0.493677, 0.938272, 1.875613
434 Int_t ntrk=event->GetNumberOfTracks();
435 AliESDtrack **tracks=new AliESDtrack*[ntrk];
438 for (i=0; i<ntrk; i++) {
439 AliESDtrack *t=event->GetTrack(i);
442 qsort(tracks,ntrk,sizeof(AliESDtrack*),cmp);
445 for (i=0; i<ntrk; i++) {
446 AliESDtrack *t=tracks[i];
448 if ((t->GetStatus()&AliESDtrack::kTRDout)==0) continue;
450 Double_t x,par[5]; t->GetExternalParameters(x,par);
451 Double_t cov[15]; t->GetExternalCovariance(cov);
453 Double_t dphi=(5*TMath::Sqrt(cov[0]) + 0.5*fDy + 2.5*TMath::Abs(par[2]))/fR;
454 Double_t dz=5*TMath::Sqrt(cov[2]) + 0.5*fDz + 2.5*TMath::Abs(par[3]);
456 Double_t phi=TMath::ATan2(par[0],x) + t->GetAlpha();
457 if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
458 if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
461 Double_t d2max=1000.;
463 for (Int_t k=FindClusterIndex(z-dz); k<fN; k++) {
464 AliTOFcluster *c=fClusters[k];
466 if (c->GetZ() > z+dz) break;
467 if (c->IsUsed()) continue;
469 Double_t dph=TMath::Abs(c->GetPhi()-phi);
470 if (dph>TMath::Pi()) dph-=TMath::Pi();
471 if (dph>dphi) continue;
473 Double_t d2=dph*dph*fR*fR + (c->GetZ()-z)*(c->GetZ()-z);
474 if (d2 > d2max) continue;
481 //Info("MakePID","matching failed ! %d",TMath::Abs(t->GetLabel()));
487 AliTOFcluster *c=fClusters[index];
490 Double_t tof=50*c->GetTDC()+32; // in ps
491 t->SetTOFsignal(tof);
492 t->SetTOFcluster(c->GetIndex());
494 if ((t->GetStatus()&AliESDtrack::kTIME)==0) continue;
496 Double_t time[10]; t->GetIntegratedTimes(time);
498 //track length correction
499 Double_t rc=TMath::Sqrt(c->GetR()*c->GetR() + c->GetZ()*c->GetZ());
500 Double_t rt=TMath::Sqrt(x*x + par[0]*par[0] + par[1]*par[1]);
504 Double_t mom=t->GetP();
505 for (Int_t j=0; j<AliESDtrack::kSPECIES; j++) {
506 Double_t mass=kMasses[j];
507 Double_t dpp=0.01; //mean relative pt resolution;
508 if (mom>0.5) dpp=0.01*mom;
509 Double_t sigma=dpp*time[j]/(1.+ mom*mom/(mass*mass));
510 sigma=TMath::Sqrt(sigma*sigma + fSigma*fSigma);
512 time[j]+=dlt/3e-2*TMath::Sqrt(mom*mom+mass*mass)/mom;
514 if (TMath::Abs(tof-time[j]) > fRange*sigma) {
515 p[j]=TMath::Exp(-0.5*fRange*fRange);
518 p[j]=TMath::Exp(-0.5*(tof-time[j])*(tof-time[j])/(sigma*sigma));
521 if (c->GetLabel(0)!=TMath::Abs(t->GetLabel())) {
522 cerr<<"Wrong matching: "<<t->GetLabel()<<endl;
530 Info("MakePID","Number of matched ESD track: %d",nmatch);