]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RICH/AliRICHTracker.cxx
Protection for very low probabilities
[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 #include <AliRun.h>
13 ClassImp(AliRICHTracker)
14 //__________________________________________________________________________________________________
15 Int_t AliRICHTracker::PropagateBack(AliESD *pESD)
16 {
17 // Interface callback methode invoked by AliRecontruction during tracking after TOF
18 // It steers to different way to provide the final reconstructed information sutable for analisys:
19 // 1. AliESD  - reconstructed tracks are used     
20 // 2. RICH private ntuple for debug- stack particles used instead of reconstructed tracks     
21   AliDebug(1,"Start pattern recognition");
22   if(pESD->GetNumberOfTracks())
23     RecWithESD(pESD);
24   else
25     RecWithStack(0);
26   AliDebug(1,"Stop pattern recognition");
27   return 0; // error code: 0=no error;
28 }//PropagateBack()
29 //__________________________________________________________________________________________________
30 void AliRICHTracker::RecWithESD(AliESD *pESD)
31 {
32 //recontruction from ESD- primary way to reconstruct particle ID signal from tracks provided by core detectors
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   
38   AliRICH *pRich=((AliRICH*)gAlice->GetDetector("RICH"));
39   
40   for(Int_t iTrackN=0;iTrackN<iNtracks;iTrackN++){//ESD tracks loop
41     AliESDtrack *pTrack = pESD->GetTrack(iTrackN);// get next reconstructed track
42 //  if((pTrack->GetStatus()&AliESDtrack::kTOFout)==0) continue; //ignore tracks not recontructed by TOF
43 //    pTrack->GetXYZ(xb); 
44 //    pTrack->GetPxPyPz(pb); 
45     Int_t status=pTrack->GetStatus()&AliESDtrack::kTOFout;//get running track parameters
46     Int_t charge = (Int_t)(-TMath::Sign(1.,pTrack->GetSign()*b));
47     AliDebug(1,Form("Track %i pmod=%f charge=%i stat=%i",iTrackN,pTrack->GetP(),charge,status));
48     AliRICHHelix helix(pTrack->X3(),pTrack->P3(),charge,b);   
49     Int_t iChamber=helix.RichIntersect(pRich->P());        
50     AliDebug(1,Form("intersection with %i chamber found",iChamber));
51     if(!iChamber) continue;//intersection with no chamber found
52 //find MIP cluster candidate (cluster which is closest to track intersection point)    
53     Double_t distMip=9999,distX=0,distY=0; //min distance between clusters and track position on PC 
54     Int_t iMipId=0; //index of that min distance cluster
55     Double_t chargeMip=0; //charge of the MIP
56     for(Int_t iClusN=0;iClusN<pRich->Clusters(iChamber)->GetEntries();iClusN++){//clusters loop for intersected chamber
57       AliRICHCluster *pClus=(AliRICHCluster*)pRich->Clusters(iChamber)->UncheckedAt(iClusN);//get pointer to current cluster
58       Double_t distCurrent=pClus->DistTo(helix.PosPc());//distance between current cluster and helix intersection with PC
59       if(distCurrent<distMip){
60         distMip=distCurrent;
61         iMipId=iClusN;
62         distX=pClus->DistX(helix.PosPc());
63         distY=pClus->DistY(helix.PosPc());
64         chargeMip=pClus->Q();
65       }//find cluster nearest to the track       
66       AliDebug(1,Form("Ploc (%f,%f,%f) dist= %f",helix.Ploc().Mag(),helix.Ploc().Theta()*TMath::RadToDeg(),
67                                        helix.Ploc().Phi()*TMath::RadToDeg(),pClus->DistTo(helix.PosPc())));
68     }//clusters loop for intersected chamber
69     
70     AliDebug(1,Form("Min distance cluster: %i dist is %f",iMipId,distMip));
71 //
72 // HERE CUTS ON GOLD RINGS....
73 //
74     if(distMip>1||chargeMip<100) {
75       //track not accepted for pattern recognition
76       pTrack->SetRICHsignal(-999.); //to be improved by flags...
77       continue;
78     }
79 //
80     AliRICHRecon recon(&helix,pRich->Clusters(iChamber),iMipId); //actual job is done there
81
82     Double_t thetaCerenkov=recon.ThetaCerenkov(); //search for mean Cerenkov angle for this track
83     
84     pTrack->SetRICHcluster(iMipId+100000*iChamber);
85     pTrack->SetRICHdxdy(distX,distY);
86     pTrack->SetRICHthetaPhi(helix.Ploc().Theta(),helix.Ploc().Phi());
87     pTrack->SetRICHsignal(thetaCerenkov);
88     pTrack->SetRICHnclusters(recon.GetHoughPhotons());
89     
90     AliDebug(1,Form("FINAL Theta Cerenkov=%f",pTrack->GetRICHsignal()));
91 //
92     if(pTrack->GetRICHsignal()>0) {
93       AliDebug(1,Form("Start to assign the probabilities"));
94       Double_t sigmaPID[AliPID::kSPECIES];
95       Double_t richPID[AliPID::kSPECIES];
96       for (Int_t iPart=0;iPart<AliPID::kSPECIES;iPart++) {
97         sigmaPID[iPart] = 0;
98         for(Int_t iphot=0;iphot<pRich->Clusters(iChamber)->GetEntries();iphot++) {
99           recon.SetPhotonIndex(iphot);
100           if(recon.GetPhotonFlag() == 2) {
101             Double_t sigma = AliRICHParam::SigmaSinglePhoton(iPart,pTrack->GetP(),recon.GetTrackTheta(),recon.GetPhiPoint()-recon.GetTrackPhi()).Mag();
102             sigmaPID[iPart] += 1/(sigma*sigma);
103           }
104         }
105         sigmaPID[iPart] = 1/TMath::Sqrt(sigmaPID[iPart])*0.001;
106         AliDebug(1,Form("sigma for %s is %f rad",AliPID::ParticleName(iPart),sigmaPID[iPart]));
107       }
108       CalcProb(thetaCerenkov,pTrack->GetP(),sigmaPID,richPID);
109       pTrack->SetRICHpid(richPID);         
110       AliDebug(1,Form("PROBABILITIES ---> %f - %f - %f - %f - %f",richPID[0],richPID[1],richPID[2],richPID[3],richPID[4]));
111     }
112     
113     
114   }//ESD tracks loop
115   AliDebug(1,"Stop.");  
116 } //RecWithESD
117 //__________________________________________________________________________________________________
118 void AliRICHTracker::RecWithStack(TNtupleD *hn)
119 {
120 //Reconstruction for particles from STACK. This methode is to be used for RICH standalone when no other detectors are switched on,
121 //so normal tracking is not available   
122   AliDebug(1,"Start.");  
123   AliRICH *pRich=((AliRICH*)gAlice->GetDetector("RICH"));
124   
125 //  pRich->GetLoader()->GetRunLoader()->LoadHeader();
126   if(!pRich->GetLoader()->GetRunLoader()->TreeK()) pRich->GetLoader()->GetRunLoader()->LoadKinematics();
127   AliStack *pStack =   pRich->GetLoader()->GetRunLoader()->Stack();
128   if(!pStack) {AliDebug(1,Form("No STACK found in AliRoot"));return;}
129   Int_t iNtracks=pStack->GetNtrack();
130   AliDebug(1,Form(" Start reconstruction with %i track(s) from Stack",iNtracks));
131   
132   Double_t hnvec[20];
133   
134   Double_t b=GetFieldMap()->SolenoidField()/10;// magnetic field in Tesla
135   AliDebug(1,Form("Start with simulated %i tracks in %f Tesla field",iNtracks,b));
136   TVector3 x0(0,0,0); TVector3 p0(0,0,0);//tmp storage for AliRICHHelix
137   
138
139   if(pRich->GetLoader()->LoadRecPoints()) {AliDebug(1,Form("No clusters found in RICH"));return;}
140   pRich->GetLoader()->TreeR()->GetEntry(0);
141
142   for(Int_t iTrackN=0;iTrackN<iNtracks;iTrackN++){//stack particles loop
143     TParticle *pParticle = pStack->Particle(iTrackN);
144     if(!pParticle) {AliDebug(1,Form("Not a valid TParticle pointer. Track skipped"));continue;}
145     AliDebug(1,Form(" PDG code : %i",pParticle->GetPdgCode()));
146 //
147 // problem of PDG code of some extra particles to be solved!!!!!!!!!
148 //
149 // found problem! Look in TRD directory : codes from Fluka are :
150 //
151 //    if ((pdg_code == 10010020) ||
152 //        (pdg_code == 10010030) ||
153 //        (pdg_code == 50000050) ||
154 //        (pdg_code == 50000051) ||
155 //        (pdg_code == 10020040)) {
156 //
157     if(pParticle->GetPdgCode()>=50000050||pParticle->GetPdgCode()==0||pParticle->GetPdgCode()>10000) {AliDebug(1,Form("A photon as track... Track skipped"));continue;}
158 //
159 // to be updated for us!!
160 //
161     AliDebug(1,Form("Track %i is a %s with charge %i and momentum %f",
162             iTrackN,pParticle->GetPDG()->GetName(),Int_t(pParticle->GetPDG()->Charge()),pParticle->P()));
163 //    if(pParticle->GetMother(0)!=-1) continue; //consider only primaries
164     if(pParticle->GetPDG()->Charge()==0||TMath::Abs(Int_t(pParticle->GetPDG()->Charge()))!=3) continue; //to avoid photons from stack...
165     hnvec[0]=pParticle->P();
166     hnvec[1]=pParticle->GetPDG()->Charge();
167     p0.SetMagThetaPhi(pParticle->P(),pParticle->Theta(),pParticle->Phi());
168     x0.SetXYZ(pParticle->Vx(),pParticle->Vy(),pParticle->Vz());
169     AliRICHHelix helix(x0,p0,TMath::Sign(1,(Int_t)pParticle->GetPDG()->Charge()),b);   
170     Int_t iChamber=helix.RichIntersect(pRich->P());        
171     hnvec[2]=helix.Ploc().Theta();
172     hnvec[3]=helix.Ploc().Phi();
173     AliDebug(1,Form("intersection with %i chamber found",iChamber));
174     if(!iChamber) continue;// no intersection with RICH found
175     hnvec[4]=helix.PosPc().X();
176     hnvec[5]=helix.PosPc().Y();
177     Double_t distMip=9999;   //min distance between clusters and track position on PC 
178     Double_t mipX=-1;      //min distance between clusters and track position on PC 
179     Double_t mipY=-1;      //min distance between clusters and track position on PC 
180     Double_t chargeMip=-1; // charge MIP to find
181     Int_t iMipId=-1;       //index of that min distance cluster 
182     for(Int_t iClusN=0;iClusN<pRich->Clusters(iChamber)->GetEntries();iClusN++){//clusters loop for intersected chamber
183       AliRICHCluster *pClus=(AliRICHCluster*)pRich->Clusters(iChamber)->UncheckedAt(iClusN);//get pointer to current cluster
184       Double_t distCurrent=pClus->DistTo(helix.PosPc());//ditance between current cluster and helix intersection with PC
185       if(distCurrent<distMip){distMip=distCurrent;mipX=pClus->X();
186                                                   mipY=pClus->Y();
187                                                   chargeMip=pClus->Q();iMipId=1000000*iChamber+iClusN;}//find cluster nearest to the track 
188       
189       AliDebug(1,Form("Ploc (%f,%f,%f) dist= %f",helix.Ploc().Mag(),helix.Ploc().Theta()*TMath::RadToDeg(),
190                                                                     helix.Ploc().Phi()*TMath::RadToDeg(),pClus->DistTo(helix.PosPc())));
191     }//clusters loop for intersected chamber
192     
193     AliDebug(1,Form("Min distance cluster: %i dist is %f",iMipId,distMip));
194     hnvec[6]=mipX;hnvec[7]=mipY;
195     hnvec[8]=chargeMip;
196     AliRICHRecon recon(&helix,pRich->Clusters(iChamber),iMipId);
197     Double_t thetaCerenkov=recon.ThetaCerenkov(); //search for mean Cerenkov angle for this track
198     hnvec[9]=thetaCerenkov;
199     hnvec[10]=recon.GetHoughPhotons();
200     hnvec[11]=(Double_t)iMipId;
201     hnvec[12]=(Double_t)iChamber;
202     hnvec[13]=(Double_t)pParticle->GetPdgCode();
203     if(hn) hn->Fill(hnvec);
204     AliDebug(1,Form("FINAL Theta Cerenkov=%f",thetaCerenkov));
205   }//stack particles loop
206   
207   pRich->GetLoader()->UnloadRecPoints();
208   AliDebug(1,"Stop.");  
209 }//RecWithStack
210 //__________________________________________________________________________________________________
211 Int_t AliRICHTracker::LoadClusters(TTree *pTree)
212 {
213 // Load clusters for RICH
214   AliDebug(1,"Start.");  pTree->GetEntry(0);  AliDebug(1,"Stop."); return 0;
215 }
216 //__________________________________________________________________________________________________
217 void AliRICHTracker::CalcProb(Double_t thetaCer,Double_t pmod, Double_t *sigmaPID, Double_t *richPID)
218 {
219 // Calculates probability to be a electron-muon-pion-kaon-proton
220 // from the given Cerenkov angle and momentum assuming no initial particle composition
221 // (i.e. apriory probability to be the particle of the given sort is the same for all sorts)
222   Double_t height[AliPID::kSPECIES];Double_t totalHeight=0;
223   Double_t thetaTh[AliPID::kSPECIES];
224   for(Int_t iPart=0;iPart<AliPID::kSPECIES;iPart++){
225     height[iPart]=0;
226     Double_t mass = AliPID::ParticleMass(iPart);
227     Double_t refIndex=AliRICHParam::RefIdxC6F14(AliRICHParam::MeanCkovEnergy());
228     Double_t cosThetaTh = TMath::Sqrt(mass*mass+pmod*pmod)/(refIndex*pmod);
229     thetaTh[iPart]=0;
230     if(cosThetaTh>=1) continue;
231     thetaTh[iPart] = TMath::ACos(cosThetaTh);
232 //    Double_t sinThetaThNorm = TMath::Sin(thetaTh)/TMath::Sqrt(1-1/(refIndex*refIndex));
233 //    Double_t sigmaThetaTh = (0.014*(1/sinThetaThNorm-1) + 0.0043)*1.25;
234 //    height[iPart] = TMath::Gaus(thetaCer,thetaTh,sigmaThetaTh);
235     height[iPart] = TMath::Gaus(thetaCer,thetaTh[iPart],sigmaPID[iPart],kTRUE);
236     totalHeight +=height[iPart];
237     AliDebug(1,Form(" Particle %s with mass %f with height %f and thetaTH %f",AliPID::ParticleName(iPart),mass,height[iPart],thetaTh[iPart]));
238     AliDebug(1,Form(" partial height %15.14f total height %15.14f",height[iPart],totalHeight));
239   }
240   if(totalHeight<1e-5) {for(Int_t iPart=0;iPart<AliPID::kSPECIES;iPart++)richPID[iPart]=1.0/AliPID::kSPECIES;return;}
241   for(Int_t iPart=0;iPart<AliPID::kSPECIES;iPart++) richPID[iPart] = height[iPart]/totalHeight;
242   Int_t iPartNear = TMath::LocMax(AliPID::kSPECIES,richPID);
243   if(TMath::Abs(thetaCer-thetaTh[iPartNear])/sigmaPID[iPartNear]>3) for(Int_t iPart=0;iPart<AliPID::kSPECIES;iPart++)richPID[iPart]=1.0/AliPID::kSPECIES;
244   //last line is to check if the nearest thetacerenkov to the teorethical one is within 3 sigma, otherwise no response (equal prob to every particle
245
246 }//CalcProb
247 //__________________________________________________________________________________________________