Improvement in HTA
[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"       //Recon()
5 #include <AliESD.h>              //PropagateBack(),Recon()  
6 #include <AliRun.h>              //GetTrackPoint(),PropagateBack()  
7 #include <AliTrackPointArray.h>  //GetTrackPoint()
8 #include <AliAlignObj.h>         //GetTrackPoint()
9 #include <AliCDBManager.h>       //PropageteBack()
10 #include <AliCDBEntry.h>         //PropageteBack()
11 //.
12 // HMPID base class fo tracking
13 //.
14 //.
15 //.
16 ClassImp(AliHMPIDTracker)
17 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
18 AliHMPIDTracker::AliHMPIDTracker():AliTracker()
19 {
20 // ctor. Create TObjArray of TClonesArray of AliHMPIDCluster  
21 // 
22 //  
23   fClu=new TObjArray(AliHMPIDDigit::kMaxCh+1);  fClu->SetOwner(kTRUE);
24   for(int i=AliHMPIDDigit::kMinCh;i<=AliHMPIDDigit::kMaxCh;i++) fClu->AddAt(new TClonesArray("AliHMPIDCluster"),i);
25 }//ctor
26 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++    
27 Bool_t AliHMPIDTracker::GetTrackPoint(Int_t idx, AliTrackPoint& point) const
28 {
29 // Interface callback methode invoked from AliReconstruction::WriteAlignmentData() to get position of MIP cluster in MARS associated to a current track.
30 // MIP cluster is reffered by index which is stored in AliESDtrack  ???????
31 // Arguments: idx- cluster index which is stored by HMPID in AliESDtrack
32 //            point- reference to the object where to store the point     
33 //   Returns: status of operation  if FALSE then AliReconstruction::WriteAlignmentData() do not store this point to array of points for current track. 
34   if(idx<0) return kFALSE; //no MIP cluster assigned to this track in PropagateBack()
35   Int_t iCham=idx/1000000; 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 }//GetTrackPoint()
44 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
45 Int_t AliHMPIDTracker::IntTrkCha(AliESDtrack *pTrk,Float_t &xPc,Float_t &yPc)
46 {
47 // Static method to find intersection in between given track and HMPID chambers
48 // Arguments: pTrk- ESD track; xPc,yPc- track intersection with PC in LORS [cm]
49 //   Returns: intersected chamber ID or -1
50   AliHMPIDParam *pParam=AliHMPIDParam::Instance();
51   Float_t xRa=0,yRa=0,theta=0,phi=0;                                                            //track intersection at PC and angles at RAD, LORS  
52   for(Int_t i=AliHMPIDDigit::kMinCh;i<=AliHMPIDDigit::kMaxCh;i++){                              //chambers loop
53     Double_t p1[3],n1[3]; pParam->Norm(i,n1); pParam->Point(i,p1,AliHMPIDParam::kRad);          //point & norm  for middle of radiator plane
54     Double_t p2[3],n2[3]; pParam->Norm(i,n2); pParam->Point(i,p2,AliHMPIDParam::kPc);           //point & norm  for entrance to PC plane
55     if(pTrk->Intersect(p1,n1,-GetBz())==kFALSE) continue;                                       //try to intersect track with the middle of radiator
56     if(pTrk->Intersect(p2,n2,-GetBz())==kFALSE) continue;                                       //try to intersect track with PC
57     pParam->Mars2LorsVec(i,n1,theta,phi);                                                       //track angles at RAD
58     pParam->Mars2Lors   (i,p1,xRa,yRa);                                                         //TRKxRAD position
59     pParam->Mars2Lors   (i,p2,xPc,yPc);                                                         //TRKxPC position
60     if(AliHMPIDDigit::IsInside(xPc,yPc,pParam->DistCut())==kFALSE) continue;                    //not in active area  
61     pTrk->SetHMPIDtrk      (xRa,yRa,theta,phi);                                                 //store track intersection info
62     pTrk->SetHMPIDcluIdx   (i,0);
63     return i;
64   }                                                                                             //chambers loop
65   return -1; //no intersection with HMPID chambers
66 }//IntTrkCha()
67 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
68 Int_t AliHMPIDTracker::LoadClusters(TTree *pCluTree)
69 {
70 // Interface callback methode invoked from AliReconstruction::RunTracking() to load HMPID clusters before PropagateBack() gets control. Done once per event.
71 // Arguments: pCluTree- pointer to clusters tree got by AliHMPIDLoader::LoadRecPoints("read") then AliHMPIDLoader::TreeR()
72 //   Returns: error code (currently ignored in AliReconstruction::RunTraking())    
73   for(int i=AliHMPIDDigit::kMinCh;i<=AliHMPIDDigit::kMaxCh;i++) pCluTree->SetBranchAddress(Form("HMPID%d",i),&((*fClu)[i]));
74   pCluTree->GetEntry(0);
75   return 0;  
76 }//LoadClusters()
77 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
78 Int_t AliHMPIDTracker::PropagateBack(AliESD *pEsd)
79 {
80 // Interface pure virtual in AliTracker. Invoked from AliReconstruction::RunTracking() after invocation of AliTracker::LoadClusters() once per event
81 // Agruments: pEsd - pointer to ESD
82 //   Returns: error code    
83   AliCDBEntry *pNmeanEnt =AliCDBManager::Instance()->Get("HMPID/Calib/Nmean"); //contains TObjArray of 21 TF1
84   AliCDBEntry *pQthreEnt =AliCDBManager::Instance()->Get("HMPID/Calib/Qthre"); //contains TObjArray of 7 TF1
85   if(!pNmeanEnt) AliFatal("No Nmean C6F14 ");
86   if(!pQthreEnt) AliFatal("No Qthre");
87     
88   return Recon(pEsd,fClu,(TObjArray*)pNmeanEnt->GetObject());  
89 }//PropagateBack()
90 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
91 Int_t AliHMPIDTracker::Recon(AliESD *pEsd,TObjArray *pClus,TObjArray *pNmean)
92 {
93 // Static method to reconstruct Theta Ckov for all valid tracks of a given event.
94 // Arguments: pEsd- pointer ESD; pClu- pointer to clusters for all chambers; pNmean - pointer to all function Nmean=f(time)
95 //   Returns: error code, 0 if no errors   
96   AliHMPIDRecon recon;                                                                       //instance of reconstruction class, nothing important in ctor
97   Float_t xPc,yPc;
98   for(Int_t iTrk=0;iTrk<pEsd->GetNumberOfTracks();iTrk++){                                       //ESD tracks loop
99     AliESDtrack *pTrk = pEsd->GetTrack(iTrk);                                                    //get reconstructed track    
100     Int_t cham=IntTrkCha(pTrk,xPc,yPc);                                                          //get chamber intersected by this track 
101     if(cham<0) continue;                                                                         //no intersection at all, go after next track
102     Double_t nmean=((TF1*)pNmean->At(3*cham))->Eval(pEsd->GetTimeStamp());                       //C6F14 Nmean for this chamber
103     recon.SetImpPC(xPc,yPc);                                                                     //store track impact to PC
104     recon.CkovAngle(pTrk,(TClonesArray *)pClus->At(cham),nmean);                                 //search for Cerenkov angle of this track
105   }                                                                                              //ESD tracks loop
106   return 0; // error code: 0=no error;
107 }//Recon()
108 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
109 Int_t AliHMPIDTracker::ReconHiddenTrk(Int_t iCh,AliESDtrack *pTrk,TClonesArray *pCluLst,TObjArray *pNmean)
110 {
111 // Static method to reconstruct Theta Ckov for all valid tracks of a given event.
112 // Arguments: pEsd- pointer ESD; pClu- pointer to clusters for all chambers; pNmean - pointer to all function Nmean=f(time)
113 //   Returns: error code, 0 if no errors
114   AliHMPIDRecon recon;                                                                          //instance of reconstruction class, nothing important in ctor
115   Double_t nmean=((TF1*)pNmean->At(3*iCh))->Eval(0);                                            //C6F14 Nmean for this chamber
116   if(pCluLst->GetEntriesFast()<4) return 1;                                                     //min 4 clusters (3 + 1 mip) to find a ring! 
117   if(recon.CkovHiddenTrk(pTrk,pCluLst,nmean)) return 0;                                         //search for track parameters and Cerenkov angle of this track
118   else return 1;                                                                                // error code: 0=no error,1=fit not performed;
119 }//Recon()
120 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++