Coding convention
[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 #include <AliCDBManager.h>
10 #include <AliCDBEntry.h>
11 //.
12 // HMPID base class fo tracking
13 //.
14 //.
15 //.
16 ClassImp(AliHMPIDTracker)
17 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
18 AliHMPIDTracker::AliHMPIDTracker():AliTracker()
19 {
20 // ctor
21   fClu=new TObjArray(AliHMPIDDigit::kMaxCh+1);
22   fClu->SetOwner(kTRUE);
23   for(int i=AliHMPIDDigit::kMinCh;i<=AliHMPIDDigit::kMaxCh;i++) fClu->AddAt(new TClonesArray("AliHMPIDCluster"),i);
24 }
25 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++    
26 Bool_t AliHMPIDTracker::GetTrackPoint(Int_t idx, AliTrackPoint& point) const
27 {
28 // Interface callback methode invoked from AliReconstruction::WriteAlignmentData() to get position of MIP cluster in MARS associated to a current track.
29 // MIP cluster is reffered by index which is stored in AliESDtrack  ???????
30 // Arguments: idx- cluster index which is stored by HMPID in AliESDtrack
31 //            point- reference to the object where to store the point     
32 //   Returns: status of operation  if FALSE then AliReconstruction::WriteAlignmentData() do not store this point to array of points for current track. 
33   if(idx<0) return kFALSE; //no MIP cluster assigned to this track in PropagateBack()
34   Int_t iCham=idx/1000000;
35   Int_t iClu=idx%1000000;
36   point.SetVolumeID(AliAlignObj::LayerToVolUID(AliAlignObj::kHMPID,iCham-1));//layer and chamber number
37   TClonesArray *pArr=(TClonesArray*)(*fClu)[iCham];
38   AliHMPIDCluster *pClu=(AliHMPIDCluster*)pArr->UncheckedAt(iClu);//get pointer to cluster
39   Double_t mars[3];
40   AliHMPIDParam::Instance()->Lors2Mars(iCham,pClu->X(),pClu->Y(),mars);
41   point.SetXYZ(mars[0],mars[1],mars[2]);
42   return kTRUE;
43 }
44 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
45 Int_t AliHMPIDTracker::LoadClusters(TTree *pCluTree)
46 {
47 // Interface callback methode invoked from AliReconstruction::RunTracking() to load HMPID clusters before PropagateBack() gets control 
48 // Arguments: pCluTree- pointer to clusters tree got by AliHMPIDLoader::LoadRecPoints("read") then AliHMPIDLoader::TreeR()
49 //   Returns: error code (currently ignored in AliReconstruction::RunTraking())    
50   AliDebug(1,"Start.");
51   for(int i=AliHMPIDDigit::kMinCh;i<=AliHMPIDDigit::kMaxCh;i++) pCluTree->SetBranchAddress(Form("HMPID%d",i),&((*fClu)[i]));
52   pCluTree->GetEntry(0);
53   AliDebug(1,"Stop."); 
54   return 0;  
55 }
56 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
57 Int_t AliHMPIDTracker::PropagateBack(AliESD *pEsd)
58 {
59 // This method defined as pure virtual in AliTracker. It is invoked from AliReconstruction::RunTracking() after invocation of AliTracker::LoadClusters()
60 // Agruments: pEsd - pointer to ESD
61 //   Returns: error code    
62   AliCDBEntry *pNmeanEnt =AliCDBManager::Instance()->Get("HMPID/Calib/Nmean"); //contains TObjArray of 21 TF1
63   AliCDBEntry *pQthreEnt =AliCDBManager::Instance()->Get("HMPID/Calib/Qthre"); //contains TObjArray of 7 TF1
64   if(!pNmeanEnt) AliFatal("No Nmean C6F14 ");
65   if(!pQthreEnt) AliFatal("No Qthre");
66     
67   return Recon(pEsd,fClu,(TObjArray*)pNmeanEnt->GetObject());  
68 }
69 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
70 Int_t AliHMPIDTracker::Recon(AliESD *pEsd,TObjArray *pCluAll,TObjArray *pNmean)
71 {
72 // Interface callback method invoked by AliRecontruction::RunTracking() during tracking after TOF. It's done just once per event
73 // Arguments: pEsd - pointer to Event Summary Data class instance which contains a list of tracks
74 //   Returns: error code, 0 if no errors   
75   Int_t iNtracks=pEsd->GetNumberOfTracks();  AliDebugClass(1,Form("Start with %i tracks",iNtracks));
76   
77   AliHMPIDRecon recon;                                                                       //instance of reconstruction class, nothing important in ctor
78   Double_t xPc,yPc;
79   for(Int_t iTrk=0;iTrk<iNtracks;iTrk++){                                                        //ESD tracks loop
80     AliESDtrack *pTrk = pEsd->GetTrack(iTrk);                                                    //get next reconstructed track    
81     Int_t cham=IntTrkCha(pTrk,xPc,yPc);                                                          //get chamber intersected by this track 
82     if(cham<0) continue;                                                                         //no intersection at all, go after next track
83     Double_t nmean=((TF1*)pNmean->At(3*cham))->Eval(pEsd->GetTimeStamp());                       //C6F14 Nmean for this chamber
84     recon.SetImpPC(xPc,yPc);                                                                     //store track impact to PC
85     recon.CkovAngle(pTrk,(TClonesArray *)pCluAll->At(cham),nmean);                               //search for Cerenkov angle of this track
86   }                                                                                              //ESD tracks loop
87   AliDebugClass(1,"Stop pattern recognition");
88   return 0; // error code: 0=no error;
89 }//PropagateBack()
90 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
91 Int_t AliHMPIDTracker::IntTrkCha(AliESDtrack *pTrk,Double_t &xToPc,Double_t &yToPc)
92 {
93 // Static method to find intersection in between given track and HMPID chambers
94 // Arguments: pTrk    - ESD track 
95 //            xPc,yPc - track intersection with PC, LORS
96 //   Returns: intersected chamber ID or -1
97   
98   AliHMPIDParam *pParam=AliHMPIDParam::Instance();
99   Float_t xRa=0,yRa=0,xPc=0,yPc=0,theta=0,phi=0;                                                //track intersection point and angles, LORS  
100   for(Int_t i=AliHMPIDDigit::kMinCh;i<=AliHMPIDDigit::kMaxCh;i++){                              //chambers loop
101     Double_t p1[3],n1[3]; pParam->Norm(i,n1); pParam->Lors2Mars(i,0,0,p1,AliHMPIDParam::kRad);  //point & norm  for RAD
102     Double_t p2[3],n2[3]; pParam->Norm(i,n2); pParam->Lors2Mars(i,0,0,p2,AliHMPIDParam::kPc);   //point & norm  for PC
103       
104     if(pTrk->Intersect(p1,n1,-GetBz())==kFALSE) continue;                                       //try to intersect track with the middle of radiator
105     if(pTrk->Intersect(p2,n2,-GetBz())==kFALSE) continue;                                       //try to intersect track with PC
106       
107     pParam->Mars2LorsVec(i,n1,theta,phi);                                                       //track angles at RAD
108     pParam->Mars2Lors   (i,p1,xRa,yRa);                                                         //TRKxRAD position
109     pParam->Mars2Lors   (i,p2,xPc,yPc);                                                         //TRKxPC position
110     xToPc=(Double_t)xPc;yToPc=(Double_t)yPc;                                                    //conversion float->double only
111     if(AliHMPIDDigit::IsInside(xPc,yPc,pParam->DistCut())==kFALSE) continue;             //not in active area  
112     pTrk->SetHMPIDtrk      (xRa,yRa,theta,phi);                                                 //store track intersection info
113     pTrk->SetHMPIDcluIdx   (i,0);
114     return i;
115   }                                                                                             //chambers loop
116   return -1; //no intersection with HMPID chambers
117 }