Added functionalities in display the RICH event and pattern recognition. Minor bugs...
[u/mrichter/AliRoot.git] / RICH / AliRICHTracker.cxx
CommitLineData
998b831f 1#include "AliRICHTracker.h"
2#include <AliESD.h>
3#include <TVector3.h>
4#include <TTree.h>
5#include "AliRICH.h"
6#include "AliRICHHelix.h"
7#include <AliMagF.h>
8#include "AliRICHRecon.h"
9#include <AliStack.h>
10#include <TParticle.h>
30c60010 11#include <TDatabasePDG.h>
12#include <TMath.h>
998b831f 13ClassImp(AliRICHTracker)
30c60010 14//__________________________________________________________________________________________________
998b831f 15Int_t AliRICHTracker::PropagateBack(AliESD *pESD)
16{
30c60010 17 //invoked by AliRecontruction for RICH
18 //if ESD doesn't contain tracks, try to reconstruct with particle from STACK
19 //(this case is just to forsee a standalone RICH simulation
1cb5a97c 20 TNtupleD *hn=0;
30c60010 21 AliDebug(1,"Start pattern recognition");
22 if(pESD->GetNumberOfTracks()) RecWithESD(pESD);
23 else
1cb5a97c 24 RecWithStack(hn);
30c60010 25 AliDebug(1,"Stop pattern recognition");
26
27 return 0; // error code: 0=no error;
28} //pure virtual from AliTracker
29//__________________________________________________________________________________________________
30void AliRICHTracker::RecWithESD(AliESD *pESD)
31{
32 //recontruction from ESD
33 //
998b831f 34 Int_t iNtracks=pESD->GetNumberOfTracks();
35 Double_t b=GetFieldMap()->SolenoidField()/10;// magnetic field in Tesla
36 AliDebug(1,Form("Start with %i tracks in %f Tesla field",iNtracks,b));
37 Double_t xb[3],pb[3];//tmp storage for track parameters
38 TVector3 x0(0,0,0); TVector3 p0(0,0,0);//tmp storage for AliRICHHelix
39
40 AliRICH *pRich=((AliRICH*)gAlice->GetDetector("RICH"));
41
998b831f 42 for(Int_t iTrackN=0;iTrackN<iNtracks;iTrackN++){//ESD tracks loop
43 AliESDtrack *pTrack = pESD->GetTrack(iTrackN);// get next reconstructed track
44// if((pTrack->GetStatus()&AliESDtrack::kTOFout)==0) continue; //ignore tracks not recontructed by TOF
45 pTrack->GetXYZ(xb);
1cb5a97c 46 pTrack->GetPxPyPz(pb);
47 Int_t status=pTrack->GetStatus()&AliESDtrack::kTOFout;//get running track parameters
998b831f 48 AliDebug(1,Form("Track %i pmod=%f mass=%f stat=%i",iTrackN,pTrack->GetP(),pTrack->GetMass(),status));
998b831f 49 x0.SetXYZ(xb[0],xb[1],xb[2]); p0.SetXYZ(xb[0],xb[1],xb[2]);
50 AliRICHHelix helix(x0,p0,pTrack->GetSign(),b);
51 Int_t iChamber=helix.RichIntersect(pRich->P());
52 AliDebug(1,Form("intersection with %i chamber found",iChamber));
53 if(!iChamber) continue;//intersection with no chamber found
54
55 Double_t distMip=9999; //min distance between clusters and track position on PC
56 Int_t iMipId=0; //index of that min distance cluster
57 for(Int_t iClusN=0;iClusN<pRich->Clusters(iChamber)->GetEntries();iClusN++){//clusters loop for intersected chamber
58 AliRICHcluster *pClus=(AliRICHcluster*)pRich->Clusters(iChamber)->UncheckedAt(iClusN);//get pointer to current cluster
59 Double_t distCurrent=pClus->DistTo(helix.PosPc());//ditance between current cluster and helix intersection with PC
60 if(distCurrent<distMip){distMip=distCurrent;iMipId=iClusN;}//find cluster nearest to the track
61
62 AliDebug(1,Form("Ploc (%f,%f,%f) dist= %f",helix.Ploc().Mag(),helix.Ploc().Theta()*TMath::RadToDeg(),
63 helix.Ploc().Phi()*TMath::RadToDeg(),pClus->DistTo(helix.PosPc())));
64 }////clusters loop for intersected chamber
65
66 AliDebug(1,Form("Min distance cluster: %i dist is %f",iMipId,distMip));
67
68 AliRICHRecon recon(&helix,pRich->Clusters(iChamber),iMipId);
69 Double_t thetaCerenkov=recon.ThetaCerenkov(); //search for mean Cerenkov angle for this track
70 AliDebug(1,Form("FINAL Theta Cerenkov=%f",thetaCerenkov));
71 pTrack->SetRICHsignal(thetaCerenkov);
72
1cb5a97c 73// Double_t richPID[5]={0.2,0.2,0.2,0.2,0.2}; //start with equal probs for (e,mu,pi,k,p)
74// CalcProb(thetaCerenkov,p0.Mag(),richPID);
75// pTrack->SetRICHpid(richPID);
998b831f 76
77 }//ESD tracks loop
78 AliDebug(1,"Stop.");
30c60010 79} //RecWithESD
80//__________________________________________________________________________________________________
1cb5a97c 81void AliRICHTracker::RecWithStack(TNtupleD *hn)
30c60010 82{
83 // reconstruction for particles from STACK
84 //
85 AliRICH *pRich=((AliRICH*)gAlice->GetDetector("RICH"));
86
1cb5a97c 87// pRich->GetLoader()->GetRunLoader()->LoadHeader();
88 pRich->GetLoader()->GetRunLoader()->LoadKinematics();
30c60010 89 AliStack *pStack = pRich->GetLoader()->GetRunLoader()->Stack();
90 Int_t iNtracks=pStack->GetNtrack();
1cb5a97c 91 AliDebug(1,Form(" Start reconstruction with %i track(s) from Stack",iNtracks));
92
93 Double_t hnvec[12];
94
30c60010 95 Double_t b=GetFieldMap()->SolenoidField()/10;// magnetic field in Tesla
96 AliDebug(1,Form("Start with simulated %i tracks in %f Tesla field",iNtracks,b));
97 TVector3 x0(0,0,0); TVector3 p0(0,0,0);//tmp storage for AliRICHHelix
98
99
1cb5a97c 100 if(pRich->GetLoader()->LoadRecPoints()) {AliDebug(1,Form("No clusters found in RICH"));return;}
101 pRich->GetLoader()->TreeR()->GetEntry(0);
102
30c60010 103 for(Int_t iTrackN=0;iTrackN<iNtracks;iTrackN++){//ESD tracks loop
104 TParticle *pParticle = pStack->Particle(iTrackN);
1cb5a97c 105 if(pParticle->GetMother(0)!=-1) continue; //consider only primaries
106 if(pParticle->GetPDG()->Charge()==0) continue; //to avoid photons from stack...
107 hnvec[0]=pParticle->P();
108 hnvec[1]=pParticle->GetPDG()->Charge();
109 hnvec[2]=pParticle->Theta();
110 hnvec[3]=pParticle->Phi();
30c60010 111 p0.SetMagThetaPhi(pParticle->P(),pParticle->Theta(),pParticle->Phi());
112 x0.SetXYZ(pParticle->Vx(),pParticle->Vy(),pParticle->Vz());
113 AliRICHHelix helix(x0,p0,Int_t(pParticle->GetPDG()->Charge()/3+0.1),b);
114 Int_t iChamber=helix.RichIntersect(pRich->P());
115 AliDebug(1,Form("intersection with %i chamber found",iChamber));
1cb5a97c 116 if(!iChamber) continue;// no intersection with RICH found
117 hnvec[4]=helix.PosPc().X();
118 hnvec[5]=helix.PosPc().Y();
119 Double_t distMip=9999; //min distance between clusters and track position on PC
120 Double_t mipX=kBad; //min distance between clusters and track position on PC
121 Double_t mipY=kBad; //min distance between clusters and track position on PC
122 Double_t chargeMip=kBad; // charge MIP to find
123 Int_t iMipId=kBad; //index of that min distance cluster
30c60010 124 for(Int_t iClusN=0;iClusN<pRich->Clusters(iChamber)->GetEntries();iClusN++){//clusters loop for intersected chamber
125 AliRICHcluster *pClus=(AliRICHcluster*)pRich->Clusters(iChamber)->UncheckedAt(iClusN);//get pointer to current cluster
126 Double_t distCurrent=pClus->DistTo(helix.PosPc());//ditance between current cluster and helix intersection with PC
1cb5a97c 127 if(distCurrent<distMip){distMip=distCurrent;mipX=pClus->X();
128 mipY=pClus->Y();
129 chargeMip=pClus->Q();iMipId=1000000*iChamber+iClusN;}//find cluster nearest to the track
30c60010 130
131 AliDebug(1,Form("Ploc (%f,%f,%f) dist= %f",helix.Ploc().Mag(),helix.Ploc().Theta()*TMath::RadToDeg(),
132 helix.Ploc().Phi()*TMath::RadToDeg(),pClus->DistTo(helix.PosPc())));
133 }////clusters loop for intersected chamber
134
135 AliDebug(1,Form("Min distance cluster: %i dist is %f",iMipId,distMip));
1cb5a97c 136 hnvec[6]=mipX;hnvec[7]=mipY;
137 hnvec[8]=chargeMip;
30c60010 138 AliRICHRecon recon(&helix,pRich->Clusters(iChamber),iMipId);
139 Double_t thetaCerenkov=recon.ThetaCerenkov(); //search for mean Cerenkov angle for this track
1cb5a97c 140 hnvec[9]=thetaCerenkov;
141 hnvec[10]=recon.GetHoughPhotons();
142 hnvec[11]=(Double_t)iMipId;
143 if(hn) hn->Fill(hnvec);
30c60010 144 AliDebug(1,Form("FINAL Theta Cerenkov=%f",thetaCerenkov));
145// pTrack->SetRICHsignal(thetaCerenkov);
146
1cb5a97c 147// Double_t richPID[5]={0.2,0.2,0.2,0.2,0.2}; //start with equal probs for (e,mu,pi,k,p)
148// CalcProb(thetaCerenkov,p0.Mag(),richPID);
30c60010 149
150 }//ESD tracks loop
1cb5a97c 151
152 pRich->GetLoader()->UnloadRecPoints();
153
30c60010 154 AliDebug(1,"Stop.");
155} //RecWithStack
998b831f 156
157Int_t AliRICHTracker::LoadClusters(TTree *pTree)
158{
159// Load clusters for RICH
160 AliDebug(1,"Start."); pTree->GetEntry(0); AliDebug(1,"Stop."); return 0;
161}
30c60010 162
163//__________________________________________________________________________________________________
164void AliRICHTracker::CalcProb(Double_t thetaCer,Double_t pmod, Double_t *richPID)
165{
166//
167 Double_t height[5];Double_t totalHeight=0;
168 Int_t code[5]={kElectron,kMuonPlus,kPiPlus,kKPlus,kProton};
169 TDatabasePDG *db = new TDatabasePDG();
170 for(Int_t iPart=0;iPart<4;iPart++){
171 Double_t mass = db->GetParticle(code[iPart])->Mass();
172 Double_t refIndex=AliRICHParam::IndOfRefC6F14(6.755);
173 Double_t cosThetaTh = TMath::Sqrt(mass*mass+pmod*pmod)/(refIndex*pmod);
174 if(cosThetaTh>=1) {break;}
175 Double_t thetaTh = TMath::ACos(cosThetaTh);
176 Double_t sinThetaThNorm = TMath::Sin(thetaTh)/TMath::Sqrt(1-1/(refIndex*refIndex));
177 Double_t sigmaThetaTh = (0.014*(1/sinThetaThNorm-1) + 0.0043)*1.25;
178 height[iPart] = TMath::Gaus(thetaCer,thetaTh,sigmaThetaTh);
179 totalHeight +=height[iPart];
180 }
181 for(Int_t iPart=0;iPart<5;iPart++) richPID[iPart] = height[iPart]/totalHeight;
182}//CalcProb