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