-#include "AliRICHTracker.h"
+#include "AliRICHTracker.h" //class header
+#include "AliRICH.h"
+#include "AliRICHRecon.h"
+#include "AliRICHParam.h"
+#include "AliRICHCluster.h"
#include <AliESD.h>
+#include <TGeoManager.h> //EsdQA()
#include <TVector3.h>
-#include <TTree.h>
-#include "AliRICH.h"
+#include <TTree.h> //EsdQA()
+#include <TFile.h> //EsdQA()
+#include <TProfile.h> //EsdQA()
#include "AliRICHHelix.h"
#include <AliMagF.h>
-#include "AliRICHRecon.h"
#include <AliStack.h>
#include <TParticle.h>
#include <TMath.h>
#include <AliRun.h>
+#include <TNtupleD.h> //RecWithStack();
+#include <AliTrackPointArray.h> //GetTrackPoint()
+#include <AliAlignObj.h> //GetTrackPoint()
+#include <TH1F.h> //EsdQA()
+#include <TH2F.h> //EsdQA()
+#include <TCanvas.h> //EsdQA()
ClassImp(AliRICHTracker)
-//__________________________________________________________________________________________________
-Int_t AliRICHTracker::PropagateBack(AliESD *pESD)
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+AliRICHTracker::AliRICHTracker():AliTracker()
{
-// Interface callback methode invoked by AliRecontruction during tracking after TOF
-// It steers to different way to provide the final reconstructed information sutable for analisys:
-// 1. AliESD - reconstructed tracks are used
-// 2. RICH private ntuple for debug- stack particles used instead of reconstructed tracks
- AliDebug(1,"Start pattern recognition");
- if(pESD->GetNumberOfTracks())
- RecWithESD(pESD);
- else
- RecWithStack(0);
- AliDebug(1,"Stop pattern recognition");
- return 0; // error code: 0=no error;
-}//PropagateBack()
-//__________________________________________________________________________________________________
-void AliRICHTracker::RecWithESD(AliESD *pESD)
+// AliRICHTracker is created from AliReconstraction::Run() which invokes AliReconstraction::CreateTrackers()
+// which in turn invokes AliRICHReconstructor::CreateTracker().
+// Note that this is done just once per session before AliReconstruction::Run() goes to events loop.
+}
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Bool_t AliRICHTracker::GetTrackPoint(Int_t idx, AliTrackPoint& point) const
+{
+// Interface callback methode invoked from AliReconstruction::WriteAlignmentData() to get position of MIP cluster in MARS associated to a current track.
+// MIP cluster is reffered by index which is stored in AliESDtrack ???????
+// Arguments: idx- cluster index which is stored by RICH in AliESDtrack
+// point- reference to the object where to store the point
+// Returns: status of operation if FALSE then AliReconstruction::WriteAlignmentData() do not store this point to array of points for current track.
+ if(idx<0) return kFALSE; //no MIP cluster assigned to this track in PropagateBack()
+ Int_t iCham=idx/1000000;
+ Int_t iClu=idx%1000000;
+ point.SetVolumeID(AliAlignObj::LayerToVolUID(AliAlignObj::kRICH,iCham-1));//layer and chamber number
+ AliRICH *pRich=((AliRICH*)gAlice->GetDetector("RICH"));
+ AliRICHCluster *pClu=(AliRICHCluster*)pRich->CluLst(iCham)->UncheckedAt(iClu);//get pointer to cluster
+ TVector3 mars=AliRICHParam::Instance()->Lors2Mars(iCham,pClu->X(),pClu->Y());
+ point.SetXYZ(mars.X(),mars.Y(),mars.Z());
+ return kTRUE;
+}
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Int_t AliRICHTracker::LoadClusters(TTree *pCluTree)
+{
+// Interface callback methode invoked from AliReconstruction::RunTracking() to load RICH clusters before PropagateBack() gets control
+// Arguments: pCluTree- pointer to clusters tree got by AliRICHLoader::LoadRecPoints("read") then AliRICHLoader::TreeR()
+// Returns: error code (currently ignored in AliReconstruction::RunTraking())
+ AliDebug(1,"Start."); pCluTree->GetEntry(0); AliDebug(1,"Stop."); return 0;
+}
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+Int_t AliRICHTracker::PropagateBack(AliESD *pESD)
{
-//recontruction from ESD- primary way to reconstruct particle ID signal from tracks provided by core detectors
+// Interface callback methode invoked by AliRecontruction::RunTracking() during tracking after TOF. It's done just once per event
+// Arguments: pESD - pointer to Event Summary Data class instance which contains a list of tracks
+// Returns: error code, 0 if no errors
+ Int_t iNtracks=pESD->GetNumberOfTracks(); AliDebug(1,Form("Start with %i tracks",iNtracks));
+ AliRICH *pRich=((AliRICH*)gAlice->GetDetector("RICH"));
+ AliRICHRecon recon; //instance of reconstruction class, nothing important in ctor
+
+ AliRICHParam *pParam=AliRICHParam::Instance();
- Int_t iNtracks=pESD->GetNumberOfTracks();
- Double_t b=GetFieldMap()->SolenoidField()/10;// magnetic field in Tesla
- AliDebug(1,Form("Start with %i tracks in %f Tesla field",iNtracks,b));
-
- AliRICH *pRich=((AliRICH*)gAlice->GetDetector("RICH"));
-
- for(Int_t iTrackN=0;iTrackN<iNtracks;iTrackN++){//ESD tracks loop
- AliESDtrack *pTrack = pESD->GetTrack(iTrackN);// get next reconstructed track
-// if((pTrack->GetStatus()&AliESDtrack::kTOFout)==0) continue; //ignore tracks not recontructed by TOF
-// pTrack->GetXYZ(xb);
-// pTrack->GetPxPyPz(pb);
- Int_t status=pTrack->GetStatus()&AliESDtrack::kTOFout;//get running track parameters
- Int_t charge = (Int_t)(-TMath::Sign(1.,pTrack->GetSign()*b));
- AliDebug(1,Form("Track %i pmod=%f charge=%i stat=%i",iTrackN,pTrack->GetP(),charge,status));
- AliRICHHelix helix(pTrack->X3(),pTrack->P3(),charge,b);
- Int_t iChamber=helix.RichIntersect(pRich->P());
- AliDebug(1,Form("intersection with %i chamber found",iChamber));
- if(!iChamber) continue;//intersection with no chamber found
-//find MIP cluster candidate (cluster which is closest to track intersection point)
- Double_t distMip=9999,distX=0,distY=0; //min distance between clusters and track position on PC
- Int_t iMipId=0; //index of that min distance cluster
- Double_t chargeMip=0; //charge of the MIP
- for(Int_t iClusN=0;iClusN<pRich->Clusters(iChamber)->GetEntries();iClusN++){//clusters loop for intersected chamber
- AliRICHCluster *pClus=(AliRICHCluster*)pRich->Clusters(iChamber)->UncheckedAt(iClusN);//get pointer to current cluster
- Double_t distCurrent=pClus->DistTo(helix.PosPc());//distance between current cluster and helix intersection with PC
- if(distCurrent<distMip){
- distMip=distCurrent;
- iMipId=iClusN;
- distX=pClus->DistX(helix.PosPc());
- distY=pClus->DistY(helix.PosPc());
- chargeMip=pClus->Q();
- }//find cluster nearest to the track
- AliDebug(1,Form("Ploc (%f,%f,%f) dist= %f",helix.Ploc().Mag(),helix.Ploc().Theta()*TMath::RadToDeg(),
- helix.Ploc().Phi()*TMath::RadToDeg(),pClus->DistTo(helix.PosPc())));
- }//clusters loop for intersected chamber
+ for(Int_t iTrk=0;iTrk<iNtracks;iTrk++){ //ESD tracks loop
+ AliESDtrack *pTrk = pESD->GetTrack(iTrk); //get next reconstructed track
+
+ Float_t xRa=0,yRa=0,xPc=0,yPc=0,th=0,ph=0; //track intersection point and angles, LORS
+ Int_t iCh=-1; //intersected chamber
+ for(Int_t i=0;i<7;i++){ //chambers loop
+ Double_t p1[3],n1[3]; pParam->Norm(i,n1); pParam->Lors2Mars(i,0,0,p1,AliRICHParam::kRad); //point & norm for RAD
+ Double_t p2[3],n2[3]; pParam->Norm(i,n2); pParam->Lors2Mars(i,0,0,p2,AliRICHParam::kPc); //point & norm for PC
+
+ if(pTrk->Intersect(p1,n1,-GetBz())==kFALSE) continue; //try to intersect track with the middle of radiator
+ if(pTrk->Intersect(p2,n2,-GetBz())==kFALSE) continue; //try to intersect track with PC
+
+ pParam->Mars2LorsVec(i,n1,th,ph); //track angles
+ pParam->Mars2Lors (i,p1,xRa,yRa); //TRKxRAD position
+ pParam->Mars2Lors (i,p2,xPc,yPc); //TRKxPC position
+
+ if(AliRICHDigit::IsInside(xPc,yPc)==kFALSE) continue; //not in active area
+ iCh=i;
+ break;
+ }//chambers loop
- AliDebug(1,Form("Min distance cluster: %i dist is %f",iMipId,distMip));
-//
-// HERE CUTS ON GOLD RINGS....
-//
- if(distMip>1||chargeMip<100) {
- //track not accepted for pattern recognition
- pTrack->SetRICHsignal(-999.); //to be improved by flags...
- continue;
- }
-//
- AliRICHRecon recon(&helix,pRich->Clusters(iChamber),iMipId); //actual job is done there
-
- Double_t thetaCerenkov=recon.ThetaCerenkov(); //search for mean Cerenkov angle for this track
+ if(iCh==-1) continue; //no intersection at all, go after next track
- pTrack->SetRICHcluster(iMipId+100000*iChamber);
- pTrack->SetRICHdxdy(distX,distY);
- pTrack->SetRICHthetaPhi(helix.Ploc().Theta(),helix.Ploc().Phi());
- pTrack->SetRICHsignal(thetaCerenkov);
- pTrack->SetRICHnclusters(recon.GetHoughPhotons());
+ TClonesArray *pCluLst=pRich->CluLst(iCh); //get clusters list for intersected chamber
- AliDebug(1,Form("FINAL Theta Cerenkov=%f",pTrack->GetRICHsignal()));
-//
- if(pTrack->GetRICHsignal()>0) {
- AliDebug(1,Form("Start to assign the probabilities"));
- Double_t sigmaPID[AliPID::kSPECIES];
- Double_t richPID[AliPID::kSPECIES];
- for (Int_t iPart=0;iPart<AliPID::kSPECIES;iPart++) {
- sigmaPID[iPart] = 0;
- for(Int_t iphot=0;iphot<pRich->Clusters(iChamber)->GetEntries();iphot++) {
- recon.SetPhotonIndex(iphot);
- if(recon.GetPhotonFlag() == 2) {
- Double_t sigma = AliRICHParam::SigmaSinglePhoton(iPart,pTrack->GetP(),recon.GetTrackTheta(),recon.GetPhiPoint()-recon.GetTrackPhi()).Mag();
- sigmaPID[iPart] += 1/(sigma*sigma);
- }
- }
- if (sigmaPID[iPart]>0)
- sigmaPID[iPart] = 1/TMath::Sqrt(sigmaPID[iPart])*0.001;
- AliDebug(1,Form("sigma for %s is %f rad",AliPID::ParticleName(iPart),sigmaPID[iPart]));
- }
- CalcProb(thetaCerenkov,pTrack->GetP(),sigmaPID,richPID);
- pTrack->SetRICHpid(richPID);
- AliDebug(1,Form("PROBABILITIES ---> %f - %f - %f - %f - %f",richPID[0],richPID[1],richPID[2],richPID[3],richPID[4]));
- }
+ Double_t dMin=999; //distance between track-PC intersection point and current cluster
+ Int_t iMip=-1; //index of cluster nearest to intersection point
+ for(Int_t iClu=0;iClu<pCluLst->GetEntries();iClu++){ //clusters loop for intersected chamber
+ AliRICHCluster *pClu=(AliRICHCluster*)pCluLst->At(iClu); //get pointer to current cluster
+ if(pClu->Q()<100) continue; //QDC is incompartible with mip, go after another one
+
+ Float_t dX=xPc-pClu->X(); //distance between current cluster and intersection point
+ Float_t dY=yPc-pClu->Y();
+ Float_t d =TMath::Sqrt(dX*dX+dY*dY);
+
+ if( d < dMin) {iMip=iClu; dMin=d;} //current cluster is closer, overwrite data for min cluster
+ }//clusters loop for intersected chamber
+// pTrk->SetRICHtrk (xPc,yPc,th,ph); //store track info
+// if(iMip==-1) {pTrk->SetRICHsignal (kMipQdcCut); continue;} //no clusters with QDC more the threshold at all
- }//ESD tracks loop
- AliDebug(1,"Stop.");
-} //RecWithESD
-//__________________________________________________________________________________________________
-void AliRICHTracker::RecWithStack(TNtupleD *hn)
-{
-//Reconstruction for particles from STACK. This methode is to be used for RICH standalone when no other detectors are switched on,
-//so normal tracking is not available
- AliDebug(1,"Start.");
- AliRICH *pRich=((AliRICH*)gAlice->GetDetector("RICH"));
-
-// pRich->GetLoader()->GetRunLoader()->LoadHeader();
- if(!pRich->GetLoader()->GetRunLoader()->TreeK()) pRich->GetLoader()->GetRunLoader()->LoadKinematics();
- AliStack *pStack = pRich->GetLoader()->GetRunLoader()->Stack();
- if(!pStack) {AliDebug(1,Form("No STACK found in AliRoot"));return;}
- Int_t iNtracks=pStack->GetNtrack();
- AliDebug(1,Form(" Start reconstruction with %i track(s) from Stack",iNtracks));
-
- Double_t hnvec[20];
-
- Double_t b=GetFieldMap()->SolenoidField()/10;// magnetic field in Tesla
- AliDebug(1,Form("Start with simulated %i tracks in %f Tesla field",iNtracks,b));
- TVector3 x0(0,0,0); TVector3 p0(0,0,0);//tmp storage for AliRICHHelix
-
-
- if(pRich->GetLoader()->LoadRecPoints()) {AliDebug(1,Form("No clusters found in RICH"));return;}
- pRich->GetLoader()->TreeR()->GetEntry(0);
-
- for(Int_t iTrackN=0;iTrackN<iNtracks;iTrackN++){//stack particles loop
- TParticle *pParticle = pStack->Particle(iTrackN);
- if(!pParticle) {AliDebug(1,Form("Not a valid TParticle pointer. Track skipped"));continue;}
- AliDebug(1,Form(" PDG code : %i",pParticle->GetPdgCode()));
-//
-// problem of PDG code of some extra particles to be solved!!!!!!!!!
-//
-// found problem! Look in TRD directory : codes from Fluka are :
-//
-// if ((pdg_code == 10010020) ||
-// (pdg_code == 10010030) ||
-// (pdg_code == 50000050) ||
-// (pdg_code == 50000051) ||
-// (pdg_code == 10020040)) {
-//
- if(pParticle->GetPdgCode()>=50000050||pParticle->GetPdgCode()==0||pParticle->GetPdgCode()>10000) {AliDebug(1,Form("A photon as track... Track skipped"));continue;}
-//
-// to be updated for us!!
-//
- AliDebug(1,Form("Track %i is a %s with charge %i and momentum %f",
- iTrackN,pParticle->GetPDG()->GetName(),Int_t(pParticle->GetPDG()->Charge()),pParticle->P()));
-// if(pParticle->GetMother(0)!=-1) continue; //consider only primaries
- if(pParticle->GetPDG()->Charge()==0||TMath::Abs(Int_t(pParticle->GetPDG()->Charge()))!=3) continue; //to avoid photons from stack...
- hnvec[0]=pParticle->P();
- hnvec[1]=pParticle->GetPDG()->Charge();
- p0.SetMagThetaPhi(pParticle->P(),pParticle->Theta(),pParticle->Phi());
- x0.SetXYZ(pParticle->Vx(),pParticle->Vy(),pParticle->Vz());
- AliRICHHelix helix(x0,p0,TMath::Sign(1,(Int_t)pParticle->GetPDG()->Charge()),b);
- Int_t iChamber=helix.RichIntersect(pRich->P());
- hnvec[2]=helix.Ploc().Theta();
- hnvec[3]=helix.Ploc().Phi();
- AliDebug(1,Form("intersection with %i chamber found",iChamber));
- if(!iChamber) continue;// no intersection with RICH found
- hnvec[4]=helix.PosPc().X();
- hnvec[5]=helix.PosPc().Y();
- Double_t distMip=9999; //min distance between clusters and track position on PC
- Double_t mipX=-1; //min distance between clusters and track position on PC
- Double_t mipY=-1; //min distance between clusters and track position on PC
- Double_t chargeMip=-1; // charge MIP to find
- Int_t iMipId=-1; //index of that min distance cluster
- for(Int_t iClusN=0;iClusN<pRich->Clusters(iChamber)->GetEntries();iClusN++){//clusters loop for intersected chamber
- AliRICHCluster *pClus=(AliRICHCluster*)pRich->Clusters(iChamber)->UncheckedAt(iClusN);//get pointer to current cluster
- Double_t distCurrent=pClus->DistTo(helix.PosPc());//ditance between current cluster and helix intersection with PC
- if(distCurrent<distMip){distMip=distCurrent;mipX=pClus->X();
- mipY=pClus->Y();
- chargeMip=pClus->Q();iMipId=1000000*iChamber+iClusN;}//find cluster nearest to the track
-
- AliDebug(1,Form("Ploc (%f,%f,%f) dist= %f",helix.Ploc().Mag(),helix.Ploc().Theta()*TMath::RadToDeg(),
- helix.Ploc().Phi()*TMath::RadToDeg(),pClus->DistTo(helix.PosPc())));
- }//clusters loop for intersected chamber
+// AliRICHCluster *pMipClu=(AliRICHCluster*)pCluLst->At(iMip); //take mip cluster
- AliDebug(1,Form("Min distance cluster: %i dist is %f",iMipId,distMip));
- hnvec[6]=mipX;hnvec[7]=mipY;
- hnvec[8]=chargeMip;
- AliRICHRecon recon(&helix,pRich->Clusters(iChamber),iMipId);
- Double_t thetaCerenkov=recon.ThetaCerenkov(); //search for mean Cerenkov angle for this track
- hnvec[9]=thetaCerenkov;
- hnvec[10]=recon.GetHoughPhotons();
- hnvec[11]=(Double_t)iMipId;
- hnvec[12]=(Double_t)iChamber;
- hnvec[13]=(Double_t)pParticle->GetPdgCode();
- if(hn) hn->Fill(hnvec);
- AliDebug(1,Form("FINAL Theta Cerenkov=%f",thetaCerenkov));
- }//stack particles loop
-
- pRich->GetLoader()->UnloadRecPoints();
- AliDebug(1,"Stop.");
-}//RecWithStack
-//__________________________________________________________________________________________________
-Int_t AliRICHTracker::LoadClusters(TTree *pTree)
-{
-// Load clusters for RICH
- AliDebug(1,"Start."); pTree->GetEntry(0); AliDebug(1,"Stop."); return 0;
-}
-//__________________________________________________________________________________________________
-void AliRICHTracker::CalcProb(Double_t thetaCer,Double_t pmod, Double_t *sigmaPID, Double_t *richPID)
-{
-// Calculates probability to be a electron-muon-pion-kaon-proton
-// from the given Cerenkov angle and momentum assuming no initial particle composition
-// (i.e. apriory probability to be the particle of the given sort is the same for all sorts)
- Double_t height[AliPID::kSPECIES];Double_t totalHeight=0;
- Double_t thetaTh[AliPID::kSPECIES];
- for(Int_t iPart=0;iPart<AliPID::kSPECIES;iPart++){
- height[iPart]=0;
- Double_t mass = AliPID::ParticleMass(iPart);
- Double_t refIndex=AliRICHParam::RefIdxC6F14(AliRICHParam::MeanCkovEnergy());
- Double_t cosThetaTh = TMath::Sqrt(mass*mass+pmod*pmod)/(refIndex*pmod);
- thetaTh[iPart]=0;
- if(cosThetaTh>=1) continue;
- thetaTh[iPart] = TMath::ACos(cosThetaTh);
-// Double_t sinThetaThNorm = TMath::Sin(thetaTh)/TMath::Sqrt(1-1/(refIndex*refIndex));
-// Double_t sigmaThetaTh = (0.014*(1/sinThetaThNorm-1) + 0.0043)*1.25;
-// height[iPart] = TMath::Gaus(thetaCer,thetaTh,sigmaThetaTh);
- height[iPart] = TMath::Gaus(thetaCer,thetaTh[iPart],sigmaPID[iPart],kTRUE);
- totalHeight +=height[iPart];
- AliDebug(1,Form(" Particle %s with mass %f with height %f and thetaTH %f",AliPID::ParticleName(iPart),mass,height[iPart],thetaTh[iPart]));
- AliDebug(1,Form(" partial height %15.14f total height %15.14f",height[iPart],totalHeight));
- }
- if(totalHeight<1e-5) {for(Int_t iPart=0;iPart<AliPID::kSPECIES;iPart++)richPID[iPart]=1.0/AliPID::kSPECIES;return;}
- for(Int_t iPart=0;iPart<AliPID::kSPECIES;iPart++) richPID[iPart] = height[iPart]/totalHeight;
- Int_t iPartNear = TMath::LocMax(AliPID::kSPECIES,richPID);
- if(TMath::Abs(thetaCer-thetaTh[iPartNear])/sigmaPID[iPartNear]>5) for(Int_t iPart=0;iPart<AliPID::kSPECIES;iPart++)richPID[iPart]=1.0/AliPID::kSPECIES;
- //last line is to check if the nearest thetacerenkov to the teorethical one is within 5 sigma, otherwise no response (equal prob to every particle
-
-}//CalcProb
-//__________________________________________________________________________________________________
+// pTrk->SetRICHmip (pMipClu->X(),pMipClu->Y(),pMipClu->Q()); //store mip info
+ if(dMin>1) {pTrk->SetRICHsignal (kMipDistCut); continue;} //closest cluster with enough charge is still too far
+// pTrk->SetRICHcluIdx (iCh,iMip); //set mip cluster index
+ recon.SetTrack(th,ph,xRa,yRa); Int_t iNphot=0; //initialize track parameters
+ pTrk->SetRICHsignal (recon.CkovAngle(pCluLst,iNphot)); //search for Cerenkov angle for this track
+ pTrk->SetRICHchi2 (recon.CkovSigma2()); //error squared
+// pTrk->SetRICHmip (pMipClu->X(),pMipClu->Y(),pMipClu->Q(),iMip); //info on mip cluster + n. phot.
+ Printf("Ch=%i MIP-TRK=%5.2f cm Th=%f+-%f", iCh, dMin,pTrk->GetRICHsignal(),pTrk->GetRICHchi2());
+ }//ESD tracks loop
+ AliDebug(1,"Stop pattern recognition");
+ return 0; // error code: 0=no error;
+}//PropagateBack()
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++