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