]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RICH/AliRICHTracker.cxx
RICH lib splitted
[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 // Interface callback methode invoked by AliRecontruction during tracking after TOF
17 // It steers to different way to provide the final reconstructed information sutable for analisys:
18 // 1. AliESD  - reconstructed tracks are used     
19 // 2. RICH private ntuple for debug- stack particles used instead of reconstructed tracks     
20   AliDebug(1,"Start pattern recognition");
21   if(pESD->GetNumberOfTracks())
22     RecWithESD(pESD);
23   else
24     RecWithStack(0);
25   AliDebug(1,"Stop pattern recognition");
26
27   return 0; // error code: 0=no error;
28 }//PropagateBack()
29 //__________________________________________________________________________________________________
30 void AliRICHTracker::RecWithESD(AliESD *pESD)
31 {
32   //recontruction from ESD
33   //
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   
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); 
46     pTrack->GetPxPyPz(pb); 
47     Int_t status=pTrack->GetStatus()&AliESDtrack::kTOFout;//get running track parameters
48     Int_t charge = (Int_t)(-TMath::Sign(1.,pTrack->GetSign()*b));
49     AliDebug(1,Form("Track %i pmod=%f charge=%i stat=%i",iTrackN,pTrack->GetP(),charge,status));
50     x0.SetXYZ(xb[0],xb[1],xb[2]); p0.SetXYZ(pb[0],pb[1],pb[2]);
51     AliRICHHelix helix(x0,p0,charge,b);   
52     Int_t iChamber=helix.RichIntersect(pRich->P());        
53     AliDebug(1,Form("intersection with %i chamber found",iChamber));
54     if(!iChamber) continue;//intersection with no chamber found
55     
56     Double_t distMip=9999; //min distance between clusters and track position on PC 
57     Int_t iMipId=0; //index of that min distance cluster 
58     for(Int_t iClusN=0;iClusN<pRich->Clusters(iChamber)->GetEntries();iClusN++){//clusters loop for intersected chamber
59       AliRICHcluster *pClus=(AliRICHcluster*)pRich->Clusters(iChamber)->UncheckedAt(iClusN);//get pointer to current cluster
60       Double_t distCurrent=pClus->DistTo(helix.PosPc());//ditance between current cluster and helix intersection with PC
61       if(distCurrent<distMip){
62         distMip=distCurrent;
63         iMipId=iClusN;
64       }//find cluster nearest to the track       
65       AliDebug(1,Form("Ploc (%f,%f,%f) dist= %f",helix.Ploc().Mag(),helix.Ploc().Theta()*TMath::RadToDeg(),
66                                        helix.Ploc().Phi()*TMath::RadToDeg(),pClus->DistTo(helix.PosPc())));
67     }//clusters loop for intersected chamber
68     
69     AliDebug(1,Form("Min distance cluster: %i dist is %f",iMipId,distMip));
70     
71     AliRICHRecon recon(&helix,pRich->Clusters(iChamber),iMipId); //create reconstruction object for helix, list of clusters
72     Double_t thetaCerenkov=recon.ThetaCerenkov(); //search for mean Cerenkov angle for this track
73     AliDebug(1,Form("FINAL Theta Cerenkov=%f",thetaCerenkov));
74     pTrack->SetRICHsignal(thetaCerenkov);
75         
76 //    Double_t richPID[5]={0.2,0.2,0.2,0.2,0.2}; //start with equal probs for (e,mu,pi,k,p)
77 //    CalcProb(thetaCerenkov,p0.Mag(),richPID);
78 //    pTrack->SetRICHpid(richPID);         
79     
80   }//ESD tracks loop
81   AliDebug(1,"Stop.");  
82 } //RecWithESD
83 //__________________________________________________________________________________________________
84 void AliRICHTracker::RecWithStack(TNtupleD *hn)
85 {
86 // Reconstruction for particles from STACK
87   AliRICH *pRich=((AliRICH*)gAlice->GetDetector("RICH"));
88   
89 //  pRich->GetLoader()->GetRunLoader()->LoadHeader();
90   pRich->GetLoader()->GetRunLoader()->LoadKinematics();
91   AliStack *pStack =   pRich->GetLoader()->GetRunLoader()->Stack();
92   if(!pStack) {AliDebug(1,Form("No STACK found in AliRoot"));return;}
93   Int_t iNtracks=pStack->GetNtrack();
94   AliDebug(1,Form(" Start reconstruction with %i track(s) from Stack",iNtracks));
95   
96   Double_t hnvec[20];
97   
98   Double_t b=GetFieldMap()->SolenoidField()/10;// magnetic field in Tesla
99   AliDebug(1,Form("Start with simulated %i tracks in %f Tesla field",iNtracks,b));
100   TVector3 x0(0,0,0); TVector3 p0(0,0,0);//tmp storage for AliRICHHelix
101   
102
103   if(pRich->GetLoader()->LoadRecPoints()) {AliDebug(1,Form("No clusters found in RICH"));return;}
104   pRich->GetLoader()->TreeR()->GetEntry(0);
105
106   for(Int_t iTrackN=0;iTrackN<iNtracks;iTrackN++){//stack particles loop
107     TParticle *pParticle = pStack->Particle(iTrackN);
108     if(!pParticle) {AliDebug(1,Form("Not a valid TParticle pointer. Track skipped"));continue;}
109     AliDebug(1,Form(" PDG code : %i",pParticle->GetPdgCode()));
110 //
111 // problem of PDG code of some extra particles to be solved!!!!!!!!!
112 //
113 // found problem! Look in TRD directory : codes from Fluka are :
114 //
115 //    if ((pdg_code == 10010020) ||
116 //        (pdg_code == 10010030) ||
117 //        (pdg_code == 50000050) ||
118 //        (pdg_code == 50000051) ||
119 //        (pdg_code == 10020040)) {
120 //
121     if(pParticle->GetPdgCode()>=50000050||pParticle->GetPdgCode()==0||pParticle->GetPdgCode()>10000) {AliDebug(1,Form("A photon as track... Track skipped"));continue;}
122 //
123 // to be updated for us!!
124 //
125     AliDebug(1,Form("Track %i is a %s with charge %i and momentum %f",
126             iTrackN,pParticle->GetPDG()->GetName(),Int_t(pParticle->GetPDG()->Charge()),pParticle->P()));
127 //    if(pParticle->GetMother(0)!=-1) continue; //consider only primaries
128     if(pParticle->GetPDG()->Charge()==0||TMath::Abs(Int_t(pParticle->GetPDG()->Charge()))!=3) continue; //to avoid photons from stack...
129     hnvec[0]=pParticle->P();
130     hnvec[1]=pParticle->GetPDG()->Charge();
131     hnvec[2]=pParticle->Theta();
132     hnvec[3]=pParticle->Phi();
133     p0.SetMagThetaPhi(pParticle->P(),pParticle->Theta(),pParticle->Phi());
134     x0.SetXYZ(pParticle->Vx(),pParticle->Vy(),pParticle->Vz());
135     AliRICHHelix helix(x0,p0,TMath::Sign(1,(Int_t)pParticle->GetPDG()->Charge()),b);   
136     Int_t iChamber=helix.RichIntersect(pRich->P());        
137     AliDebug(1,Form("intersection with %i chamber found",iChamber));
138     if(!iChamber) continue;// no intersection with RICH found
139     hnvec[4]=helix.PosPc().X();
140     hnvec[5]=helix.PosPc().Y();
141     Double_t distMip=9999;   //min distance between clusters and track position on PC 
142     Double_t mipX=kBad;      //min distance between clusters and track position on PC 
143     Double_t mipY=kBad;      //min distance between clusters and track position on PC 
144     Double_t chargeMip=kBad; // charge MIP to find
145     Int_t iMipId=kBad;       //index of that min distance cluster 
146     for(Int_t iClusN=0;iClusN<pRich->Clusters(iChamber)->GetEntries();iClusN++){//clusters loop for intersected chamber
147       AliRICHcluster *pClus=(AliRICHcluster*)pRich->Clusters(iChamber)->UncheckedAt(iClusN);//get pointer to current cluster
148       Double_t distCurrent=pClus->DistTo(helix.PosPc());//ditance between current cluster and helix intersection with PC
149       if(distCurrent<distMip){distMip=distCurrent;mipX=pClus->X();
150                                                   mipY=pClus->Y();
151                                                   chargeMip=pClus->Q();iMipId=1000000*iChamber+iClusN;}//find cluster nearest to the track 
152       
153       AliDebug(1,Form("Ploc (%f,%f,%f) dist= %f",helix.Ploc().Mag(),helix.Ploc().Theta()*TMath::RadToDeg(),
154                                                                     helix.Ploc().Phi()*TMath::RadToDeg(),pClus->DistTo(helix.PosPc())));
155     }//clusters loop for intersected chamber
156     
157     AliDebug(1,Form("Min distance cluster: %i dist is %f",iMipId,distMip));
158     hnvec[6]=mipX;hnvec[7]=mipY;
159     hnvec[8]=chargeMip;
160     AliRICHRecon recon(&helix,pRich->Clusters(iChamber),iMipId);
161     Double_t thetaCerenkov=recon.ThetaCerenkov(); //search for mean Cerenkov angle for this track
162     hnvec[9]=thetaCerenkov;
163     hnvec[10]=recon.GetHoughPhotons();
164     hnvec[11]=(Double_t)iMipId;
165     hnvec[12]=(Double_t)iChamber;
166     hnvec[13]=(Double_t)pParticle->GetPdgCode();
167     if(hn) hn->Fill(hnvec);
168     AliDebug(1,Form("FINAL Theta Cerenkov=%f",thetaCerenkov));
169   }//stack particles loop
170   
171   pRich->GetLoader()->UnloadRecPoints();
172   AliDebug(1,"Stop.");  
173 }//RecWithStack
174 //__________________________________________________________________________________________________
175 Int_t AliRICHTracker::LoadClusters(TTree *pTree)
176 {
177 // Load clusters for RICH
178   AliDebug(1,"Start.");  pTree->GetEntry(0);  AliDebug(1,"Stop."); return 0;
179 }
180 //__________________________________________________________________________________________________
181 void AliRICHTracker::CalcProb(Double_t thetaCer,Double_t pmod, Double_t *richPID)
182 {
183 // Calculates probability to be a electron-muon-pion-kaon-proton 
184 // from the given Cerenkov angle and momentum assuming no initial particle composition
185 // (i.e. apriory probability to be the particle of the given sort is the same for all sorts)  
186   Double_t height[AliPID::kSPECIES];Double_t totalHeight=0;
187   for(Int_t iPart=0;iPart<AliPID::kSPECIES;iPart++){
188     Double_t mass = AliPID::ParticleMass(iPart);
189     Double_t refIndex=AliRICHParam::RefIdxC6F14(6.755);
190     Double_t cosThetaTh = TMath::Sqrt(mass*mass+pmod*pmod)/(refIndex*pmod);
191     if(cosThetaTh>=1) {break;}
192     Double_t thetaTh = TMath::ACos(cosThetaTh);
193     Double_t sinThetaThNorm = TMath::Sin(thetaTh)/TMath::Sqrt(1-1/(refIndex*refIndex));
194     Double_t sigmaThetaTh = (0.014*(1/sinThetaThNorm-1) + 0.0043)*1.25;
195     height[iPart] = TMath::Gaus(thetaCer,thetaTh,sigmaThetaTh);
196     totalHeight +=height[iPart];
197   }
198   for(Int_t iPart=0;iPart<AliPID::kSPECIES;iPart++) richPID[iPart] = height[iPart]/totalHeight;    
199 }//CalcProb
200 //__________________________________________________________________________________________________