064eebcacc6653c7f27b8105c6ec338214266aac
[u/mrichter/AliRoot.git] / HMPID / AliHMPIDTracker.cxx
1 #include "AliHMPIDTracker.h"     //class header
2 #include "AliHMPIDCluster.h"     //GetTrackPoint(),PropagateBack() 
3 #include "AliHMPIDParam.h"       //GetTrackPoint(),PropagateBack()
4 #include "AliHMPIDRecon.h"       //PropagateBack()
5 #include <AliESD.h>              //PropagateBack()  
6 #include <AliRun.h>              //GetTrackPoint(),PropagateBack()  
7 #include <AliTrackPointArray.h>  //GetTrackPoint()
8 #include <AliAlignObj.h>         //GetTrackPoint()
9 ClassImp(AliHMPIDTracker)
10 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++    
11 Bool_t AliHMPIDTracker::GetTrackPoint(Int_t idx, AliTrackPoint& point) const
12 {
13 // Interface callback methode invoked from AliReconstruction::WriteAlignmentData() to get position of MIP cluster in MARS associated to a current track.
14 // MIP cluster is reffered by index which is stored in AliESDtrack  ???????
15 // Arguments: idx- cluster index which is stored by HMPID in AliESDtrack
16 //            point- reference to the object where to store the point     
17 //   Returns: status of operation  if FALSE then AliReconstruction::WriteAlignmentData() do not store this point to array of points for current track. 
18   if(idx<0) return kFALSE; //no MIP cluster assigned to this track in PropagateBack()
19   Int_t iCham=idx/1000000;
20   Int_t iClu=idx%1000000;
21   point.SetVolumeID(AliAlignObj::LayerToVolUID(AliAlignObj::kHMPID,iCham-1));//layer and chamber number
22   AliHMPID *pRich=((AliHMPID*)gAlice->GetDetector("HMPID"));  
23   AliHMPIDCluster *pClu=(AliHMPIDCluster*)pRich->CluLst(iCham)->UncheckedAt(iClu);//get pointer to cluster
24   Double_t mars[3];
25   AliHMPIDParam::Instance()->Lors2Mars(iCham,pClu->X(),pClu->Y(),mars);
26   point.SetXYZ(mars[0],mars[1],mars[2]);
27   return kTRUE;
28 }
29 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30 Int_t AliHMPIDTracker::LoadClusters(TTree *pCluTree)
31 {
32 // Interface callback methode invoked from AliReconstruction::RunTracking() to load HMPID clusters before PropagateBack() gets control 
33 // Arguments: pCluTree- pointer to clusters tree got by AliHMPIDLoader::LoadRecPoints("read") then AliHMPIDLoader::TreeR()
34 //   Returns: error code (currently ignored in AliReconstruction::RunTraking())    
35   AliDebug(1,"Start.");  pCluTree->GetEntry(0);  AliDebug(1,"Stop."); return 0;
36 }
37 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
38 Int_t AliHMPIDTracker::Recon(AliESD *pESD,TObjArray *pCluAll)
39 {
40 // Interface callback methode invoked by AliRecontruction::RunTracking() during tracking after TOF. It's done just once per event
41 // Arguments: pESD - pointer to Event Summary Data class instance which contains a list of tracks
42 //   Returns: error code, 0 if no errors   
43   Int_t iNtracks=pESD->GetNumberOfTracks();  AliDebugClass(1,Form("Start with %i tracks",iNtracks));
44   AliHMPIDRecon recon;                                                        //instance of reconstruction class, nothing important in ctor
45    
46   AliHMPIDParam *pParam=AliHMPIDParam::Instance();
47
48   for(Int_t iTrk=0;iTrk<iNtracks;iTrk++){                                                        //ESD tracks loop
49     AliESDtrack *pTrk = pESD->GetTrack(iTrk);                                                    //get next reconstructed track    
50         
51     Float_t xRa=0,yRa=0,xPc=0,yPc=0,th=0,ph=0;                                                   //track intersection point and angles, LORS  
52     Int_t iCh=-1;                                                                                //intersected chamber 
53     for(Int_t i=0;i<7;i++){                                                                      //chambers loop
54       Double_t p1[3],n1[3]; pParam->Norm(i,n1); pParam->Lors2Mars(i,0,0,p1,AliHMPIDParam::kRad);  //point & norm  for RAD
55       Double_t p2[3],n2[3]; pParam->Norm(i,n2); pParam->Lors2Mars(i,0,0,p2,AliHMPIDParam::kPc);   //point & norm  for PC
56       
57       if(pTrk->Intersect(p1,n1,-GetBz())==kFALSE) continue;                                      //try to intersect track with the middle of radiator
58       if(pTrk->Intersect(p2,n2,-GetBz())==kFALSE) continue;                                      //try to intersect track with PC
59       
60       pParam->Mars2LorsVec(i,n1,th,ph);                                                          //track angles
61       pParam->Mars2Lors   (i,p1,xRa,yRa);                                                        //TRKxRAD position
62       pParam->Mars2Lors   (i,p2,xPc,yPc);                                                        //TRKxPC position
63       
64       if(AliHMPIDDigit::IsInside(xPc,yPc)==kFALSE) continue;                                      //not in active area  
65       iCh=i;
66       break;
67     }//chambers loop      
68     
69     if(iCh==-1) continue;                                                                  //no intersection at all, go after next track
70     
71     TClonesArray *pCluLst=(TClonesArray *)pCluAll->At(iCh);                                //get clusters list for intersected chamber
72     
73     Double_t    dMin=999;                                                                  //distance between track-PC intersection point and current cluster
74     Int_t   iMip=-1;                                                                       //index of cluster nearest to intersection point
75     for(Int_t iClu=0;iClu<pCluLst->GetEntries();iClu++){                                   //clusters loop for intersected chamber
76       AliHMPIDCluster *pClu=(AliHMPIDCluster*)pCluLst->At(iClu);                             //get pointer to current cluster
77       if(pClu->Q()<100) continue;                                                          //QDC is incompartible with mip, go after another one
78       
79       Float_t dX=xPc-pClu->X();                                                            //distance between current cluster and intersection point
80       Float_t dY=yPc-pClu->Y();
81       Float_t d =TMath::Sqrt(dX*dX+dY*dY);
82       
83       if( d < dMin) {iMip=iClu; dMin=d;}                                                   //current cluster is closer, overwrite data for min cluster
84     }//clusters loop for intersected chamber    
85     
86                    pTrk->SetHMPIDtrk      (xPc,yPc,th,ph);                                  //store track info
87     if(iMip==-1)  {pTrk->SetHMPIDsignal   (kMipQdcCut);  continue;}                         //no clusters with QDC more the threshold at all
88     
89     AliHMPIDCluster *pMipClu=(AliHMPIDCluster*)pCluLst->At(iMip);                            //take mip cluster 
90     
91                    pTrk->SetHMPIDmip      ((Float_t)pMipClu->X(),(Float_t)pMipClu->Y(),(Int_t)pMipClu->Q());          //store mip info 
92     if(dMin>1)    {pTrk->SetHMPIDsignal   (kMipDistCut); continue;}                          //closest cluster with enough charge is still too far 
93                    pTrk->SetHMPIDcluIdx   (iCh,iMip);                                        //set mip cluster index
94   recon.SetTrack(th,ph,xRa,yRa); Int_t iNphot=0;                                            //initialize track parameters  
95                    pTrk->SetHMPIDsignal   (recon.CkovAngle(pCluLst,iNphot));                 //search for Cerenkov angle for this track
96                    pTrk->SetHMPIDchi2     (recon.CkovSigma2());                              //error squared 
97                    pTrk->SetHMPIDmip      ((Float_t)pMipClu->X(),(Float_t)pMipClu->Y(),(Int_t)pMipClu->Q(),iMip);     //info on mip cluster + n. phot.
98  }//ESD tracks loop
99   AliDebugClass(1,"Stop pattern recognition");
100   return 0; // error code: 0=no error;
101 }//PropagateBack()
102 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++