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