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