LCOV - code coverage report
Current view: top level - HMPID/HMPIDrec - AliHMPIDTracker.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 160 432 37.0 %
Date: 2016-06-14 17:26:59 Functions: 12 15 80.0 %

          Line data    Source code
       1             : #include "AliHMPIDTracker.h"     //class header
       2             : #include "AliHMPIDtrack.h"       //class header
       3             : #include "AliHMPIDCluster.h"     //GetTrackPoint(),PropagateBack() 
       4             : #include "AliHMPIDParam.h"       //GetTrackPoint(),PropagateBack()
       5             : #include "AliHMPIDPid.h"         //Recon(),reconHTA()
       6             : #include "AliHMPIDRecon.h"       //Recon()
       7             : #include "AliHMPIDRecoParamV1.h"   //Recon()
       8             : #include "AliHMPIDReconstructor.h"//Recon()
       9             : #include "AliHMPIDReconHTA.h"    //ReconHTA()
      10             : #include <AliLog.h>              //Recon()  
      11             : #include <AliESDEvent.h>         //PropagateBack(),Recon()  
      12             : #include <AliESDtrack.h>         //Intersect() 
      13             : #include <AliTracker.h> 
      14             : #include <AliRun.h>              //GetTrackPoint(),PropagateBack()  
      15             : #include <AliTrackPointArray.h>  //GetTrackPoint()
      16             : #include <AliAlignObj.h>         //GetTrackPoint()
      17             : #include <AliCDBManager.h>       //PropageteBack()
      18             : #include <AliCDBEntry.h>         //PropageteBack()
      19             : #include "TTreeStream.h"         // debug streamer
      20             : //
      21             : // HMPID base class fo tracking
      22             : //.
      23             : //.
      24             : //.
      25          12 : ClassImp(AliHMPIDTracker)
      26             : //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      27             : AliHMPIDTracker::AliHMPIDTracker():
      28           2 :   AliTracker(),
      29           6 :   fClu(new TObjArray(AliHMPIDParam::kMaxCh+1)),
      30           2 :   fDebugStreamer(0)
      31          10 : {
      32             : // ctor. Create TObjArray of TClonesArray of AliHMPIDCluster  
      33             : // 
      34             : //  
      35           2 :   fClu->SetOwner(kTRUE);
      36          74 :   for(int i=AliHMPIDParam::kMinCh;i<=AliHMPIDParam::kMaxCh;i++) fClu->AddAt(new TClonesArray("AliHMPIDCluster"),i);
      37           6 :   fDebugStreamer = new TTreeSRedirector("HMPIDdebug.root");
      38             : 
      39           4 : }//ctor
      40             : 
      41             : 
      42          12 : AliHMPIDTracker::~AliHMPIDTracker(){
      43             :   //
      44             :   // destructor
      45             :   // 
      46           4 :   delete fClu;
      47           6 :   if (fDebugStreamer) delete fDebugStreamer;
      48           6 : }
      49             : 
      50             : //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++    
      51             : Bool_t AliHMPIDTracker::GetTrackPoint(Int_t idx, AliTrackPoint& point) const
      52             : {
      53             : // Interface callback methode invoked from AliReconstruction::WriteAlignmentData() to get position of MIP cluster in MARS associated to a current track.
      54             : // MIP cluster is reffered by index which is stored in AliESDtrack  ???????
      55             : // Arguments: idx- cluster index which is stored by HMPID in AliESDtrack
      56             : //            point- reference to the object where to store the point     
      57             : //   Returns: status of operation  if FALSE then AliReconstruction::WriteAlignmentData() do not store this point to array of points for current track. 
      58          16 :   if(idx<0) return kFALSE; //no MIP cluster assigned to this track in PropagateBack()
      59           8 :   Int_t iCham=idx/1000000; Int_t iClu=idx%1000000;
      60           8 :   iClu = iClu%1000; //GetHMPIDcluIdx -> 1e+6*ch + 1e+3*clusize + cluIdx;
      61           8 :   point.SetVolumeID(AliGeomManager::LayerToVolUID(AliGeomManager::kHMPID,iCham));//layer and chamber number
      62           8 :   TClonesArray *pArr=(TClonesArray*)(*fClu)[iCham];
      63           8 :   if(!pArr) return kFALSE;
      64           8 :   AliHMPIDCluster *pClu=(AliHMPIDCluster*)pArr->UncheckedAt(iClu);//get pointer to cluster
      65           8 :   if(!pClu) return kFALSE;
      66           8 :   Float_t xyz[3];
      67           8 :   pClu->GetGlobalXYZ(xyz);
      68           8 :   Float_t cov[6];
      69           8 :   pClu->GetGlobalCov(cov);
      70           8 :   point.SetXYZ(xyz,cov);
      71             :   return kTRUE;
      72          16 : }//GetTrackPoint()
      73             : //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      74             : Int_t AliHMPIDTracker::IntTrkCha(AliESDtrack *pTrk,Float_t &xPc,Float_t &yPc,Float_t &xRa,Float_t &yRa,Float_t &theta,Float_t &phi)
      75             : {
      76             : // Static method to find intersection in between given track and HMPID chambers
      77             : // Arguments: pTrk- ESD track; xPc,yPc- track intersection with PC in LORS [cm]
      78             : //   Returns: intersected chamber ID or -1
      79         268 :   AliHMPIDtrack *hmpTrk = new AliHMPIDtrack(*pTrk);                                             //create a hmpid track to be used for propagation and matching 
      80        2086 :   for(Int_t i=AliHMPIDParam::kMinCh;i<=AliHMPIDParam::kMaxCh;i++){                              //chambers loop
      81         866 :     Int_t chInt = IntTrkCha(i,hmpTrk,xPc,yPc,xRa,yRa,theta,phi);
      82         914 :     if(chInt>=0) {delete hmpTrk;hmpTrk=0x0;return chInt;}
      83         850 :   }                                                                                             //chambers loop
      84         236 :   delete hmpTrk; hmpTrk=0x0;
      85         118 :   return -1;                                                                                    //no intersection with HMPID chambers
      86         134 : }//IntTrkCha()
      87             : //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      88             : Int_t AliHMPIDTracker::IntTrkCha(Int_t ch,AliHMPIDtrack *pTrk,Float_t &xPc,Float_t &yPc,Float_t &xRa,Float_t &yRa,Float_t &theta,Float_t &phi)
      89             : {
      90             : // Static method to find intersection in between given track and HMPID chambers
      91             : // Arguments: pTrk- HMPID track; xPc,yPc- track intersection with PC in LORS [cm]
      92             : //   Returns: intersected chamber ID or -1
      93        1792 :     AliHMPIDParam *pParam=AliHMPIDParam::Instance();
      94         896 :     Double_t p1[3],n1[3]; 
      95         896 :     pParam->Norm(ch,n1); 
      96         896 :     pParam->Point(ch,p1,AliHMPIDParam::kRad);                                                    //point & norm  for middle of radiator plane
      97         896 :     Double_t p2[3],n2[3]; 
      98         896 :     pParam->Norm(ch,n2);
      99         896 :     pParam->Point(ch,p2,AliHMPIDParam::kPc);                                                     //point & norm  for entrance to PC plane
     100        1278 :     if(pTrk->Intersect(p1,n1)==kFALSE) return -1;                                                //try to intersect track with the middle of radiator
     101         516 :     if(pTrk->Intersect(p2,n2)==kFALSE) return -1;   
     102         512 :     pParam->Mars2LorsVec(ch,n1,theta,phi);                                                       //track angles at RAD
     103         512 :     pParam->Mars2Lors   (ch,p1,xRa,yRa);                                                         //TRKxRAD position
     104         512 :     pParam->Mars2Lors   (ch,p2,xPc,yPc);                                                         //TRKxPC position
     105         558 :     if(AliHMPIDParam::IsInside(xPc,yPc,pParam->DistCut())==kTRUE) return ch;                     //return intersected chamber  
     106         466 :   return -1;                                                                                     //no intersection with HMPID chambers
     107         896 : }//IntTrkCha()
     108             : //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     109             : Int_t AliHMPIDTracker::LoadClusters(TTree *pCluTree)
     110             : {
     111             : // Interface callback methode invoked from AliReconstruction::RunTracking() to load HMPID clusters before PropagateBack() gets control. Done once per event.
     112             : // Arguments: pCluTree- pointer to clusters tree got by AliHMPIDLoader::LoadRecPoints("read") then AliHMPIDLoader::TreeR()
     113             : //   Returns: error code (currently ignored in AliReconstruction::RunTraking())    
     114         136 :   for(int i=AliHMPIDParam::kMinCh;i<=AliHMPIDParam::kMaxCh;i++) pCluTree->SetBranchAddress(Form("HMPID%d",i),&((*fClu)[i]));
     115           8 :   pCluTree->GetEntry(0);
     116           8 :   return 0;  
     117             : }//LoadClusters()
     118             : //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     119             : Int_t AliHMPIDTracker::PropagateBack(AliESDEvent *pEsd)
     120             : {
     121             : // Interface pure virtual in AliTracker. Invoked from AliReconstruction::RunTracking() after invocation of AliTracker::LoadClusters() once per event
     122             : // Agruments: pEsd - pointer to ESD
     123             : //   Returns: error code    
     124          24 :   AliCDBEntry *pNmeanEnt =AliCDBManager::Instance()->Get("HMPID/Calib/Nmean"); //contains TObjArray of 42 TF1 + 1 EPhotMean
     125          16 :   AliCDBEntry *pQthreEnt =AliCDBManager::Instance()->Get("HMPID/Calib/Qthre"); //contains TObjArray of 42 (7ch * 6sec) TF1
     126           8 :   if(!pNmeanEnt) AliError("No Nmean C6F14 ");
     127           8 :   if(!pQthreEnt) AliError("No Qthre");
     128             :     
     129           8 :   return Recon(pEsd,fClu,(TObjArray*)pNmeanEnt->GetObject(),(TObjArray*)pQthreEnt->GetObject());  
     130           0 : }//PropagateBack()
     131             : //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     132             : Int_t AliHMPIDTracker::Recon(AliESDEvent *pEsd,TObjArray *pClus,TObjArray *pNmean, TObjArray *pQthre)
     133             : {
     134             : // Static method to reconstruct the Cherenkov angle for all valid tracks of a given event.
     135             : // Arguments: pEsd- pointer ESD; pClu- pointer to clusters for all chambers; pNmean - pointer to all function Nmean=f(time)
     136             : // Returns: error code, 0 if no errors   
     137             : //
     138             : // Algortihm: Loop over tracks
     139             : //
     140             : // 1. Find the closest MIP cluster using fast tracks extrapolation method
     141             : // 2. Propagate track to the MIP cluster using the STEER method
     142             : // 3. Update the track information with MIP cluster (Improved angular and position resolution - to be used for Cherenkov angle calculation)
     143             : // 4. Propagate back the constrained track to the radiator radius ( not exact yet)
     144             : // 5. Propagation in the last 10 cm with the fast method 
     145             : // 6. Set ESDtrack information
     146             : // 7. Calculate the Cherenkov angle
     147             : 
     148             :   const Double_t kMaxSnp=0.9;   //maximal snp for prolongation
     149             :   const Double_t kdRadiator=10; // distance between radiator and the plane
     150          16 :   AliHMPIDRecon recon;                                                                           //instance of reconstruction class, nothing important in ctor
     151           8 :   AliHMPIDParam *pParam = AliHMPIDParam::Instance();                                             //Instance of AliHMPIDParam
     152           8 :   Float_t xPc,yPc,xRa,yRa,theta,phi;
     153             :   
     154             :   Double_t cluLORS[2]={0};
     155             :   Int_t nMipClusTot=0;
     156             :   
     157             :   Double_t qthre = 0;   Double_t nmean=0; Int_t hvsec=0;
     158             : //  Int_t nClusCh[AliHMPIDParam::kMaxCh+1];
     159             : 
     160             :   Bool_t tsRight = kTRUE;
     161             :   
     162          24 :   UInt_t tsmin = (UInt_t)((TF1*)pQthre->At(0))->GetXmin();                                        //
     163          24 :   UInt_t tsmax = (UInt_t)((TF1*)pQthre->At(0))->GetXmax();                                        //
     164           8 :   UInt_t ts = pEsd->GetTimeStamp();
     165             :   
     166          16 :   if(ts<tsmin || ts>tsmax) {
     167           0 :     AliWarning(Form(" in HMPID time stamp out of range!!! Please check!!! ts = %i",ts));
     168             :     tsRight = kFALSE;
     169           0 :   }
     170             :    
     171         480 :   for(Int_t iTrk=0;iTrk<pEsd->GetNumberOfTracks();iTrk++){                                        //loop on the ESD tracks in the event
     172             :            
     173             :     //    Double_t bestChi2=99999;chi2=99999;                                                     //init. track matching params
     174             : //    Double_t dmin=999999,bz=0,distCut=1,distParams[5]={1};
     175         152 :     Double_t dmin=999999,distCut=1,distParams[5]={1};
     176             : 
     177             :     Bool_t isOkDcut=kFALSE;
     178             :     Bool_t isOkQcut=kFALSE;
     179             :     Bool_t isMatched=kFALSE;
     180             :     
     181             :     AliHMPIDCluster *bestHmpCluster=0x0;                                                          //the best matching cluster
     182         152 :     AliESDtrack *pTrk = pEsd->GetTrack(iTrk);                                                     //get reconstructed track   
     183             :     
     184         322 :     if(!pTrk->IsOn(AliESDtrack::kTPCout)) continue;
     185             :  
     186         268 :     if(pTrk->IsOn(AliESDtrack::kTPCrefit)) continue;
     187         134 :     AliESDfriendTrack *ftrack= (AliESDfriendTrack *)pTrk->GetFriendTrack();
     188         134 :     if (!ftrack) continue; 
     189         268 :     if (!ftrack->GetTPCOut()) continue;
     190         268 :     AliHMPIDtrack *hmpTrk = new AliHMPIDtrack(*pTrk);                                             //create a hmpid track to be used for propagation and matching 
     191             :     AliHMPIDtrack *hmpTrkConstrained = 0;                                                         //create a hmpid track to be used for propagation and matching 
     192        1072 :     hmpTrk->Set(ftrack->GetTPCOut()->GetX(), ftrack->GetTPCOut()->GetAlpha(),ftrack->GetTPCOut()->GetParameter(), ftrack->GetTPCOut()->GetCovariance());
     193             :     //
     194             :     //bz=AliTracker::GetBz();
     195             :           
     196             :     //initial flags for HMPID ESD infos    
     197         134 :     pTrk->SetHMPIDtrk(0,0,0,0);                                                                //no intersection found
     198         134 :     pTrk->SetHMPIDmip(0,0,0,0);                                                                //store mip info in any case 
     199         134 :     pTrk->SetHMPIDcluIdx(99,99999);                                                            //chamber not found, mip not yet considered
     200         134 :     pTrk->SetHMPIDsignal(AliHMPIDRecon::kNotPerformed);                                        //ring reconstruction not yet performed
     201             :     
     202         134 :     Int_t ipCh=IntTrkCha(pTrk,xPc,yPc,xRa,yRa,theta,phi);                                        //find the intersected chamber for this track 
     203         488 :     if(ipCh<0) {delete hmpTrk;hmpTrk=0x0;continue;}                                                                         //no intersection at all, go after next track
     204             : 
     205          16 :     pTrk->SetHMPIDtrk(xPc,yPc,theta,phi);                                                        //store initial infos
     206          16 :     pTrk->SetHMPIDcluIdx(ipCh,9999);                                                             //set chamber, index of cluster + cluster size
     207             :     
     208             :     // track intersects the chamber ipCh: find the MIP          
     209             :     
     210          32 :     TClonesArray *pMipCluLst=(TClonesArray *)pClus->At(ipCh);                                   //get the list of clusters
     211          16 :     nMipClusTot = pMipCluLst->GetEntries();                                                     //total number of clusters in the given chamber
     212             :    // nClusCh[ipCh] = nMipClusTot;
     213             :     
     214          19 :     if(nMipClusTot==0) {delete hmpTrk;hmpTrk=0x0;continue;}                                                                         
     215             :     
     216             :     Int_t index=-1;                                                                               //index of the "best" matching cluster
     217             :     //
     218             :     // 1. Find the closest MIP cluster using fast tracks extrapolation method
     219             :     //
     220         572 :     for (Int_t iClu=0; iClu<nMipClusTot;iClu++) {                                                 //clusters loop
     221             :       
     222         271 :       AliHMPIDCluster *pClu=(AliHMPIDCluster*)pMipCluLst->UncheckedAt(iClu);                      //get the cluster
     223             :       // evaluate qThre
     224         271 :       if(tsRight){
     225         542 :         if(pQthre->GetEntriesFast()==pParam->kMaxCh+1) {
     226           0 :           qthre=((TF1*)pQthre->At(pClu->Ch()))->Eval(ts);                                          //
     227           0 :         } else {                                                                                   // in the past just 1 qthre
     228         271 :           hvsec = pParam->InHVSector(pClu->Y());                                                   //  per chamber
     229        1069 :           if(hvsec>=0) qthre=((TF1*)pQthre->At(6*ipCh+hvsec))->Eval(ts);                                     //
     230             :         } 
     231           0 :       } else qthre = pParam->QCut();
     232             :       
     233             :       //      
     234         488 :       if(pClu->Q()<qthre) continue;                                                                      //charge compartible with MIP clusters      
     235             :       isOkQcut = kTRUE;
     236             :       //
     237          54 :       cluLORS[0]=pClu->X(); cluLORS[1]=pClu->Y();                                                        //get the LORS coordinates of the cluster
     238          54 :       Double_t dist = TMath::Sqrt((xPc-cluLORS[0])*(xPc-cluLORS[0])+(yPc-cluLORS[1])*(yPc-cluLORS[1]));
     239             :       
     240          54 :       if(dist<dmin) {
     241             :         dmin = dist;
     242             :         index=iClu;
     243             :         bestHmpCluster=pClu;
     244          23 :       }
     245          54 :     } // clusters loop
     246             : 
     247             :     // moved down
     248             :     /*if(!isOkQcut) {
     249             :       pTrk->SetHMPIDsignal(pParam->kMipQdcCut);
     250             :       delete hmpTrk;hmpTrk=0x0; continue;                                                                     
     251             :     }*/
     252             :     
     253             :     //
     254             :     // 2. Propagate track to the MIP cluster using the STEER method
     255             :     //
     256             :         
     257          15 :     if(!bestHmpCluster) {delete hmpTrk;hmpTrk=0x0; delete hmpTrkConstrained;hmpTrkConstrained=0x0;  continue;}     
     258             :         
     259          15 :     TVector3 vG = pParam->Lors2Mars(ipCh,bestHmpCluster->X(),bestHmpCluster->Y());    
     260          30 :     Double_t gx = vG[0];
     261          30 :     Double_t gy = vG[1];
     262          30 :     Double_t gz = vG[2];
     263          15 :     Double_t alpha=TMath::ATan2(gy,gx);
     264          15 :     Double_t radiusH=TMath::Sqrt(gy*gy+gx*gx);
     265          30 :     if (!(hmpTrk->Rotate(alpha,kTRUE))) continue;
     266          45 :     if(!AliTrackerBase::PropagateTrackToBxByBz(hmpTrk,radiusH,pTrk->GetMass(),1,kFALSE,kMaxSnp,-1)) {delete hmpTrk;hmpTrk=0x0; delete hmpTrkConstrained;hmpTrkConstrained=0x0; continue;}    
     267             :     //
     268             :     // 3. Update the track with MIP cluster (Improved angular and position resolution - to be used for Cherenkov angle calculation)
     269             :     //
     270          15 :     AliExternalTrackParam trackC(*hmpTrk);
     271          15 :     Double_t posC[2]={0,gz};
     272          15 :     Double_t covC[3]={0.1*0.1, 0, 0.1*0.1};
     273          15 :     trackC.Update(posC,covC);
     274             :     //
     275             :     // 4. Propagate back the constrained track to the radiator radius ( not exact yet)
     276             :     //
     277          30 :     hmpTrkConstrained = new AliHMPIDtrack(*pTrk);
     278          15 :     hmpTrkConstrained->Set(trackC.GetX(), trackC.GetAlpha(),trackC.GetParameter(), trackC.GetCovariance());
     279          45 :     if(!AliTrackerBase::PropagateTrackToBxByBz(hmpTrkConstrained,radiusH-kdRadiator,pTrk->GetMass(),1,kFALSE,kMaxSnp,1)) {delete hmpTrk;hmpTrk=0x0; delete hmpTrkConstrained;hmpTrkConstrained=0x0;continue;}
     280             :     //
     281             :     // 5. Propagation in the last 10 cm with the fast method 
     282             :     //
     283          15 :     Float_t xPc0=0, yPc0=0;
     284             :     
     285          15 :     IntTrkCha(ipCh, hmpTrk, xPc0,yPc0,xRa,yRa,theta,phi);  
     286          15 :     IntTrkCha(ipCh, hmpTrkConstrained, xPc,yPc,xRa,yRa,theta,phi);  
     287             :     //
     288             :     // 6. Set ESDtrack information
     289             :     //
     290          15 :     Int_t cluSiz = bestHmpCluster->Size();
     291          15 :     pTrk->SetHMPIDmip(bestHmpCluster->X(),bestHmpCluster->Y(),(Int_t)bestHmpCluster->Q(),0);  //store mip info in any case 
     292          15 :     pTrk->SetHMPIDcluIdx(ipCh,index+1000*cluSiz);                                             //set chamber, index of cluster + cluster size    
     293          15 :     pTrk->SetHMPIDtrk(xPc0,yPc0,theta,phi);
     294             :     //
     295             :     //
     296             :     // Dump debug info if specified
     297             :     // 
     298          15 :     if (AliHMPIDReconstructor::StreamLevel()>0) {    
     299           0 :       AliExternalTrackParam * trackTPC=new AliExternalTrackParam(*(ftrack->GetTPCOut()));
     300           0 :       AliExternalTrackParam * trackCurrent=new AliExternalTrackParam(*pTrk);      
     301           0 :       if(!trackTPC->Rotate(alpha)) continue;
     302           0 :       if(!trackCurrent->Rotate(alpha)) continue;      
     303           0 :       Bool_t statusTPC= AliTracker::PropagateTrackToBxByBz(trackTPC,radiusH,pTrk->GetMass(),1,kFALSE,kMaxSnp,-1);      
     304           0 :       Bool_t statusCurrent=AliTracker::PropagateTrackToBxByBz(trackCurrent,radiusH,pTrk->GetMass(),1,kFALSE,kMaxSnp,-1);  
     305           0 :       AliExternalTrackParam * trackTPCNB=new AliExternalTrackParam(*(ftrack->GetTPCOut()));
     306           0 :       if(!trackTPCNB->Rotate(alpha)) continue;
     307             :       Bool_t statusTPCNB=kTRUE;
     308           0 :       Double_t bfield[3]={0,0,0};
     309           0 :       for (Double_t radius=trackTPCNB->GetX(); radius<radiusH; radius+=1){
     310           0 :         Double_t xyz[3];
     311           0 :         trackTPCNB->GetXYZ(xyz);
     312           0 :         GetBxByBz(xyz,bfield);
     313           0 :         statusTPCNB&=trackTPCNB->PropagateToBxByBz(radius,bfield);
     314           0 :       }
     315           0 :       statusTPCNB&=trackTPCNB->PropagateToBxByBz(radiusH,bfield);
     316             :       //        
     317           0 :       Double_t tanAlpha=TMath::Tan(TMath::ASin(trackTPC->GetSnp()));
     318           0 :       Double_t deltaC= trackTPC->GetC(AliTrackerBase::GetBz())-ftrack->GetTPCOut()->GetC(AliTrackerBase::GetBz());    
     319             :       //
     320           0 :       AliExternalTrackParam * trackTPCConstrained= new AliExternalTrackParam(*trackTPC);
     321           0 :       Double_t pos[2]={0,gz};
     322           0 :       Double_t cov[3]={0.1*0.1, 0, 0.1*0.1};
     323           0 :       Double_t chi2C =  trackTPCConstrained->GetPredictedChi2(pos,cov);
     324           0 :       trackTPCConstrained->Update(pos,cov);
     325           0 :       (*fDebugStreamer)<<"track"<<
     326           0 :         "rH="<<radiusH<<                      // radius of cluster
     327           0 :         "angle="<<tanAlpha<<                  // tan of the local inlination angle
     328           0 :         "dC="<<deltaC<<                       // delta of the curvature
     329           0 :         "trackTPC.="<<trackTPC<<              // TPC outer param extrapolated to the HMPID
     330           0 :         "trackTPCNB.="<<trackTPCNB<<          // TPC track prpagated with material budget correction
     331           0 :         "chi2C="<<chi2C<<
     332           0 :         "trackTPCC.="<<trackTPCConstrained<<  // TPC outer param extrapolated to the HMPID constrained
     333           0 :         "trackCurrent.="<<trackCurrent<<      // current track extrapolated to the HMPID
     334           0 :         "sTPC="<<statusTPC<<                  // status for the current TPC  track
     335           0 :         "sCurrent="<<statusCurrent<<          // status for the current global track
     336           0 :         "cl.="<<bestHmpCluster<<              // HMPID cluster
     337             :         //
     338           0 :         "t.="<<pTrk<<                        // curent esd track
     339           0 :         "ft.="<<ftrack<<                     // friend track
     340           0 :         "hmpTrk.="<<hmpTrk<<                 // hmpid tracks as used in the following code
     341           0 :         "hmpTrkC.="<<hmpTrkConstrained<<     // constrained hmpid tracks as used in the following code
     342           0 :         "gx="<<gx<<                          // global cluster position X
     343           0 :         "gy="<<gy<<                          // Y
     344           0 :         "gz="<<gz<<                          // Z
     345             :         "\n";
     346           0 :     }                 
     347             :     //
     348             :     //
     349             :     //    
     350          15 :     if(!isOkQcut) {
     351           0 :       pTrk->SetHMPIDsignal(pParam->kMipQdcCut);
     352           0 :       delete hmpTrk;hmpTrk=0x0; 
     353           0 :       delete hmpTrkConstrained;hmpTrkConstrained=0x0; 
     354           0 :       continue;                                                                     
     355             :     }        
     356             :     
     357          30 :     if(AliHMPIDReconstructor::GetRecoParam())                                                 //retrieve distance cut
     358             :     {
     359          30 :       if(AliHMPIDReconstructor::GetRecoParam()->IsFixedDistCut()==kTRUE)                      //distance cut is fixed number
     360             :       { 
     361          30 :         distCut=AliHMPIDReconstructor::GetRecoParam()->GetHmpTrackMatchingDist();
     362          15 :       }
     363             :       else 
     364             :       {
     365           0 :         for(Int_t ipar=0;ipar<5;ipar++) distParams[ipar]=AliHMPIDReconstructor::GetRecoParam()->GetHmpTrackMatchingDistParam(ipar);      //prevision: distance cut is function of momentum
     366           0 :         distCut=distParams[0]+distParams[1]*TMath::Power(distParams[2]*pTrk->GetP(),distParams[3]); //prevision: change functional form to be more precise
     367             :       }
     368             :     }
     369           0 :     else {distCut=pParam->DistCut();}
     370             :      
     371             :     //dmin recalculated
     372             :     
     373          15 :     dmin = TMath::Sqrt((xPc0-bestHmpCluster->X())*(xPc0-bestHmpCluster->X())+(yPc0-bestHmpCluster->Y())*(yPc0-bestHmpCluster->Y()));
     374             :              
     375          15 :     if(dmin < distCut) {
     376             :       isOkDcut = kTRUE;
     377           8 :     }   
     378             :     //isOkDcut = kTRUE; // switch OFF cut
     379             :     
     380          15 :     if(!isOkDcut) {
     381           7 :       pTrk->SetHMPIDsignal(pParam->kMipDistCut);                                                //closest cluster with enough charge is still too far from intersection
     382           7 :     }
     383             :     
     384          23 :     if(isOkQcut*isOkDcut) isMatched = kTRUE;                                                    // MIP-Track matched !!    
     385             :     
     386          50 :     if(!isMatched) {delete hmpTrk;hmpTrk=0x0;delete hmpTrkConstrained;hmpTrkConstrained=0x0;continue;}                                           // If matched continue...
     387             : 
     388             :     Bool_t isOk = kTRUE; 
     389           8 :     if(!isOk) {delete hmpTrk;hmpTrk=0x0; delete hmpTrkConstrained;hmpTrkConstrained=0x0; continue;}
     390           8 :     pTrk->SetOuterHmpParam(hmpTrkConstrained,AliESDtrack::kHMPIDout);                 
     391             : 
     392           8 :     FillResiduals(hmpTrk,bestHmpCluster,kFALSE);
     393             :  
     394           8 :     Int_t iRad = pParam->Radiator(yRa);                                                          //evaluate the radiator involved
     395             :     
     396             :     //evaluate nMean
     397           8 :     if(tsRight){
     398          16 :      if(pNmean->GetEntries()==21) {                                                              //for backward compatibility
     399           0 :        nmean=((TF1*)pNmean->At(3*ipCh))->Eval(ts);                                               //C6F14 Nmean for this chamber
     400           0 :      } else {
     401           8 :        if(iRad < 0) {
     402             :         nmean = -1;
     403           0 :        } else {
     404          16 :        Double_t tLow  = ((TF1*)pNmean->At(6*ipCh+2*iRad  ))->Eval(ts);                           //C6F14 low  temp for this chamber
     405          16 :        Double_t tHigh = ((TF1*)pNmean->At(6*ipCh+2*iRad+1))->Eval(ts);                           //C6F14 high temp for this chamber
     406           8 :        Double_t tExp  = pParam->FindTemp(tLow,tHigh,yRa);                                        //estimated temp for that chamber at that y
     407          16 :        nmean = pParam->NIdxRad(AliHMPIDParam::Instance()->GetEPhotMean(),tExp);                  //mean ref idx @ a given temp
     408             :        }
     409           8 :        if(nmean < 0){                                                                            //track didn' t pass through the radiator
     410           0 :          pTrk->SetHMPIDsignal(AliHMPIDRecon::kNoRad);                                           //set the appropriate flag
     411           0 :          pTrk->SetHMPIDcluIdx(ipCh,index+1000*cluSiz);                                          //set index of cluster
     412           0 :          delete hmpTrk;hmpTrk=0x0; 
     413           0 :          delete hmpTrkConstrained;hmpTrkConstrained=0x0; 
     414           0 :          continue;
     415             :         }
     416             :      }
     417           0 :     } else nmean = pParam->MeanIdxRad();    
     418             :     //
     419             :     // 7. Calculate the Cherenkov angle
     420             :     //
     421           8 :     recon.SetImpPC(xPc0,yPc0);                                                                     //store track impact to PC           
     422          16 :     recon.CkovAngle(pTrk,(TClonesArray *)pClus->At(ipCh),index,nmean,xRa,yRa);                   //search for Cerenkov angle of this track
     423             :     
     424          16 :     Double_t thetaCkov = pTrk->GetHMPIDsignal();
     425             :     
     426           8 :     if (AliHMPIDReconstructor::StreamLevel()>0) {    
     427           0 :       AliExternalTrackParam * trackTPC=new AliExternalTrackParam(*(ftrack->GetTPCOut()));
     428           0 :       AliExternalTrackParam * trackCurrent=new AliExternalTrackParam(*pTrk);      
     429           0 :       if(!trackTPC->Rotate(alpha)) continue;
     430           0 :       if(!trackCurrent->Rotate(alpha)) continue;      
     431           0 :       Bool_t statusTPC= AliTracker::PropagateTrackToBxByBz(trackTPC,radiusH,pTrk->GetMass(),1,kFALSE,kMaxSnp,-1);      
     432           0 :       Bool_t statusCurrent=AliTracker::PropagateTrackToBxByBz(trackCurrent,radiusH,pTrk->GetMass(),1,kFALSE,kMaxSnp,-1);    
     433           0 :       Double_t tanAlpha=TMath::Tan(TMath::ASin(trackTPC->GetSnp()));
     434           0 :       Double_t deltaC= trackTPC->GetC(AliTrackerBase::GetBz())-ftrack->GetTPCOut()->GetC(AliTrackerBase::GetBz());    
     435             :       //
     436           0 :       AliExternalTrackParam * trackTPCNB=new AliExternalTrackParam(*(ftrack->GetTPCOut()));
     437           0 :       if(!trackTPCNB->Rotate(alpha)) continue;
     438             :       Bool_t statusTPCNB=kTRUE;
     439           0 :       Double_t bfield[3]={0,0,0};
     440           0 :       for (Double_t radius=trackTPCNB->GetX(); radius<radiusH; radius+=1){
     441           0 :         Double_t xyz[3];
     442           0 :         trackTPCNB->GetXYZ(xyz);
     443           0 :         GetBxByBz(xyz,bfield);
     444           0 :         statusTPCNB&=trackTPCNB->PropagateToBxByBz(radius,bfield);
     445           0 :       }
     446           0 :       statusTPCNB&=trackTPCNB->PropagateToBxByBz(radiusH,bfield);
     447             : 
     448           0 :       AliExternalTrackParam * trackTPCConstrained= new AliExternalTrackParam(*trackTPC);
     449           0 :       Double_t pos[2]={0,gz};
     450           0 :       Double_t cov[3]={0.1*0.1, 0, 0.1*0.1};
     451           0 :       Double_t chi2C =  trackTPCConstrained->GetPredictedChi2(pos,cov);
     452           0 :       trackTPCConstrained->Update(pos,cov);
     453           0 :       (*fDebugStreamer)<<"track2"<<
     454           0 :         "rH="<<radiusH<<                      // radius of cluster
     455           0 :         "angle="<<tanAlpha<<                  // tan of the local inlination angle
     456           0 :         "dC="<<deltaC<<                       // delta of the curvature
     457           0 :         "trackTPC.="<<trackTPC<<              // TPC outer param extrapolated to the HMPID
     458           0 :         "trackTPCNB.="<<trackTPCNB<<          // TPC outer param extrapolated to the HMPID
     459           0 :         "chi2C="<<chi2C<<
     460           0 :         "trackTPCC.="<<trackTPCConstrained<<  // TPC outer param extrapolated to the HMPID constrained
     461           0 :         "trackCurrent.="<<trackCurrent<<      // current track extrapolated to the HMPID
     462           0 :         "sTPC="<<statusTPC<<                  // status for the current TPC  track
     463           0 :         "sCurrent="<<statusCurrent<<          // status for the current global track
     464           0 :         "cl.="<<bestHmpCluster<<              // HMPID cluster
     465             :         //
     466           0 :         "t.="<<pTrk<<                         // curent esd track
     467           0 :         "ft.="<<ftrack<<                      // friend track
     468           0 :         "hmpTrk.="<<hmpTrk<<                  // hmpid tracks as used in the following code
     469           0 :         "hmpTrkC.="<<hmpTrkConstrained<<      // constrained hmpid tracks as used in the following code
     470           0 :         "gx="<<gx<<                           // global cluster position X
     471           0 :         "gy="<<gy<<                           // Y
     472           0 :         "gz="<<gz<<                           // Z
     473           0 :         "thetaCkov="<<thetaCkov<<             // Cherenkov angle
     474             :         "\n";
     475           0 :     } 
     476             :                 
     477          16 :     if(pTrk->GetHMPIDsignal()<0) {
     478           0 :       delete hmpTrk;hmpTrk=0x0;
     479           0 :       delete hmpTrkConstrained; hmpTrkConstrained=0x0;
     480           0 :       continue;}
     481             :         
     482           8 :     AliHMPIDPid pID;
     483           8 :     Double_t prob[5];
     484           8 :     pID.FindPid(pTrk,nmean,5,prob);
     485           8 :     pTrk->SetHMPIDpid(prob);
     486          16 :     delete hmpTrk; hmpTrk=0x0;
     487          16 :     delete hmpTrkConstrained; hmpTrkConstrained=0x0;
     488         213 :   }//iTrk
     489             : 
     490             :   return 0; // error code: 0=no error;
     491           8 : }//Recon()
     492             : //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     493             : Int_t AliHMPIDTracker::ReconFromKin(AliESDEvent *pEsd,TObjArray *pClus,TObjArray *pNmean, TObjArray *pQthre)
     494             : {
     495             : // Static method to reconstruct Theta Ckov for all valid tracks of a given event.
     496             : // Arguments: pEsd- pointer ESD; pClu- pointer to clusters for all chambers; pNmean - pointer to all function Nmean=f(time)
     497             : //   Returns: error code, 0 if no errors   
     498             :   
     499           0 :   AliHMPIDRecon recon;                                                                           //instance of reconstruction class, nothing important in ctor
     500           0 :   AliHMPIDParam *pParam = AliHMPIDParam::Instance();                                             //Instance of AliHMPIDParam
     501           0 :   Float_t xPc,yPc,xRa,yRa,theta,phi;
     502             :   Double_t cluLORS[2]={0};
     503             :   Int_t nMipClusTot=0;
     504             :   Double_t qthre = 0;   Double_t nmean=0; Int_t hvsec=0;
     505             :   //Int_t nClusCh[AliHMPIDParam::kMaxCh+1];
     506             : 
     507             :   Bool_t tsRight = kTRUE;
     508             :   
     509           0 :   UInt_t tsmin = (UInt_t)((TF1*)pQthre->At(0))->GetXmin();                                        //
     510           0 :   UInt_t tsmax = (UInt_t)((TF1*)pQthre->At(0))->GetXmax();                                        //
     511           0 :   UInt_t ts = pEsd->GetTimeStamp();
     512             :   
     513           0 :   if(ts<tsmin || ts>tsmax) {
     514           0 :     AliWarning(Form(" in HMPID time stamp out of range!!! Please check!!! ts = %i",ts));
     515             :     tsRight = kFALSE;
     516           0 :   }
     517             :    
     518           0 :   for(Int_t iTrk=0;iTrk<pEsd->GetNumberOfTracks();iTrk++){                                        //loop on the ESD tracks in the event
     519             :            
     520           0 :     Double_t dmin=999999,distCut=1,distParams[5]={1};
     521             : 
     522             :     Bool_t isOkDcut=kFALSE;
     523             :     Bool_t isOkQcut=kFALSE;
     524             :     Bool_t isMatched=kFALSE;
     525             :     
     526             :     AliHMPIDCluster *bestHmpCluster=0x0;                                                          //the best matching cluster
     527           0 :     AliESDtrack *pTrk = pEsd->GetTrack(iTrk);                                                     //get reconstructed track   
     528             :     
     529           0 :     AliHMPIDtrack *hmpTrk = new AliHMPIDtrack(*pTrk);                                             //create a hmpid track to be used for propagation and matching 
     530             :    // bz=AliTracker::GetBz();  
     531             : //initial flags for HMPID ESD infos    
     532           0 :     pTrk->SetHMPIDtrk(0,0,0,0);                                                                //no intersection found
     533           0 :     pTrk->SetHMPIDmip(0,0,0,0);                                                                //store mip info in any case 
     534           0 :     pTrk->SetHMPIDcluIdx(99,99999);                                                            //chamber not found, mip not yet considered
     535           0 :     pTrk->SetHMPIDsignal(AliHMPIDRecon::kNotPerformed);                                        //ring reconstruction not yet performed
     536             :     
     537           0 :     Int_t ipCh=IntTrkCha(pTrk,xPc,yPc,xRa,yRa,theta,phi);                                        //find the intersected chamber for this track 
     538           0 :     if(ipCh<0) {delete hmpTrk;hmpTrk=0x0;continue;}                                                                         //no intersection at all, go after next track
     539             : 
     540           0 :     pTrk->SetHMPIDtrk(xPc,yPc,theta,phi);                                                        //store initial infos
     541           0 :     pTrk->SetHMPIDcluIdx(ipCh,9999);                                                             //set chamber, index of cluster + cluster size
     542             :     
     543             : // track intersects the chamber ipCh: find the MIP          
     544             :     
     545           0 :     TClonesArray *pMipCluLst=(TClonesArray *)pClus->At(ipCh);                                   //get the list of clusters
     546           0 :     nMipClusTot = pMipCluLst->GetEntries();                                                     //total number of clusters in the given chamber
     547             :    // nClusCh[ipCh] = nMipClusTot;
     548             :     
     549           0 :     if(nMipClusTot==0) {delete hmpTrk;hmpTrk=0x0;continue;}                                                                         
     550             :     
     551             :     Int_t index=-1;                                                                             //index of the "best" matching cluster
     552             :     
     553           0 :     for (Int_t iClu=0; iClu<nMipClusTot;iClu++) {                                               //clusters loop
     554             :       
     555           0 :       AliHMPIDCluster *pClu=(AliHMPIDCluster*)pMipCluLst->UncheckedAt(iClu);                    //get the cluster
     556             : // evaluate qThre
     557           0 :       if(tsRight){
     558           0 :        if(pQthre->GetEntriesFast()==pParam->kMaxCh+1) {
     559           0 :          qthre=((TF1*)pQthre->At(pClu->Ch()))->Eval(ts);                                         //
     560           0 :        } else {                                                                                  // in the past just 1 qthre
     561           0 :          hvsec = pParam->InHVSector(pClu->Y());                                                  //  per chamber
     562           0 :          if(hvsec>=0) qthre=((TF1*)pQthre->At(6*ipCh+hvsec))->Eval(ts);                                     //
     563             :         } 
     564           0 :       } else qthre = pParam->QCut();
     565             :             
     566             : //      
     567           0 :       if(pClu->Q()<qthre) continue;                                                                      //charge compartible with MIP clusters      
     568             :       isOkQcut = kTRUE;
     569             : //
     570           0 :       cluLORS[0]=pClu->X(); cluLORS[1]=pClu->Y();                                            //get the LORS coordinates of the cluster
     571           0 :       Double_t dist = TMath::Sqrt((xPc-cluLORS[0])*(xPc-cluLORS[0])+(yPc-cluLORS[1])*(yPc-cluLORS[1]));
     572             :       
     573           0 :       if(dist<dmin) {
     574             :         dmin = dist;
     575             :         index=iClu;
     576             :         bestHmpCluster=pClu;
     577           0 :       }
     578           0 :     } // clusters loop
     579             : 
     580           0 :     if(!isOkQcut) {
     581           0 :       pTrk->SetHMPIDsignal(pParam->kMipQdcCut);
     582           0 :       delete hmpTrk;hmpTrk=0x0; continue;                                                                     
     583             :     }
     584             : 
     585           0 :     Double_t radius = (pParam->Lors2Mars(ipCh,pParam->SizeAllX()/2,pParam->SizeAllY()/2)).Mag(); 
     586             :     
     587           0 :     if(!AliTracker::PropagateTrackToBxByBz(hmpTrk,radius,pTrk->GetMass(),1,kFALSE)) {delete hmpTrk;hmpTrk=0x0;continue;}
     588             :               
     589           0 :     if(!hmpTrk->PropagateTo(bestHmpCluster)) {delete hmpTrk;hmpTrk=0x0;continue;}
     590             : 
     591           0 :     Int_t cluSiz = bestHmpCluster->Size();
     592           0 :     pTrk->SetHMPIDmip(bestHmpCluster->X(),bestHmpCluster->Y(),(Int_t)bestHmpCluster->Q(),0);  //store mip info in any case 
     593           0 :     pTrk->SetHMPIDcluIdx(ipCh,index+1000*cluSiz);                                             //set chamber, index of cluster + cluster size
     594             : 
     595           0 :     if(AliHMPIDReconstructor::GetRecoParam())                                                 //retrieve distance cut
     596             :     {
     597           0 :       if(AliHMPIDReconstructor::GetRecoParam()->IsFixedDistCut()==kTRUE)                      //distance cut is fixed number
     598             :       { 
     599           0 :         distCut=AliHMPIDReconstructor::GetRecoParam()->GetHmpTrackMatchingDist();
     600           0 :       }
     601             :       else 
     602             :       {
     603           0 :         for(Int_t ipar=0;ipar<5;ipar++) distParams[ipar]=AliHMPIDReconstructor::GetRecoParam()->GetHmpTrackMatchingDistParam(ipar);      //prevision: distance cut is function of momentum
     604           0 :         distCut=distParams[0]+distParams[1]*TMath::Power(distParams[2]*pTrk->GetP(),distParams[3]); //prevision: change functional form to be more precise
     605             :       }
     606             :     }
     607           0 :     else {distCut=pParam->DistCut();}
     608             :       
     609           0 :     if(dmin < distCut) {
     610             :       isOkDcut = kTRUE;
     611           0 :     }   
     612             :     
     613           0 :     if(!isOkDcut) {
     614           0 :       pTrk->SetHMPIDsignal(pParam->kMipDistCut);                                                //closest cluster with enough charge is still too far from intersection
     615           0 :     }
     616             :     
     617           0 :     if(isOkQcut*isOkDcut) isMatched = kTRUE;                                                    // MIP-Track matched !!    
     618             :     
     619           0 :     if(!isMatched) {delete hmpTrk;hmpTrk=0x0;continue;}                                           // If matched continue...
     620             : 
     621           0 :     Bool_t isOk = hmpTrk->Update(bestHmpCluster,0.1,0);
     622           0 :     if(!isOk) {delete hmpTrk;hmpTrk=0x0;continue;}
     623           0 :     pTrk->SetOuterHmpParam(hmpTrk,AliESDtrack::kHMPIDout);                 
     624             : 
     625           0 :     FillResiduals(hmpTrk,bestHmpCluster,kFALSE);
     626             :  
     627           0 :     Int_t iRad     = pParam->Radiator(yRa);                                                      //evaluate the radiator involved
     628             :     
     629             :     //evaluate nMean
     630           0 :     if(tsRight){
     631           0 :      if(pNmean->GetEntries()==21) {                                                              //for backward compatibility
     632           0 :        nmean=((TF1*)pNmean->At(3*ipCh))->Eval(ts);                                               //C6F14 Nmean for this chamber
     633           0 :      } else {
     634           0 :        if(iRad < 0) {
     635             :         nmean = -1;
     636           0 :        } else {
     637           0 :        Double_t tLow  = ((TF1*)pNmean->At(6*ipCh+2*iRad  ))->Eval(ts);                           //C6F14 low  temp for this chamber
     638           0 :        Double_t tHigh = ((TF1*)pNmean->At(6*ipCh+2*iRad+1))->Eval(ts);                           //C6F14 high temp for this chamber
     639           0 :        Double_t tExp  = pParam->FindTemp(tLow,tHigh,yRa);                                        //estimated temp for that chamber at that y
     640           0 :        nmean = pParam->NIdxRad(AliHMPIDParam::Instance()->GetEPhotMean(),tExp);                  //mean ref idx @ a given temp
     641             :        }
     642           0 :        if(nmean < 0){                                                                            //track didn' t pass through the radiator
     643           0 :          pTrk->SetHMPIDsignal(AliHMPIDRecon::kNoRad);                                           //set the appropriate flag
     644           0 :          pTrk->SetHMPIDcluIdx(ipCh,index+1000*cluSiz);                                          //set index of cluster
     645           0 :          delete hmpTrk;hmpTrk=0x0; 
     646           0 :          continue;
     647             :         }
     648             :       }
     649           0 :     } else nmean = pParam->MeanIdxRad();
     650             :     
     651             :     //
     652           0 :     recon.SetImpPC(xPc,yPc);                                                                     //store track impact to PC
     653           0 :     recon.CkovAngle(pTrk,(TClonesArray *)pClus->At(ipCh),index,nmean,xRa,yRa);                   //search for Cerenkov angle of this track
     654             : 
     655           0 :     if(pTrk->GetHMPIDsignal()<0) {delete hmpTrk;hmpTrk=0x0;continue;}
     656             :         
     657           0 :     AliHMPIDPid pID;
     658           0 :     Double_t prob[5];
     659           0 :     pID.FindPid(pTrk,nmean,5,prob);
     660             :   //  Printf("Tracker RefIndex = %f, chmaber = %i, prob1 = %f, prob2 = %f, prob3 = %f, prob4 = %f, prob5 = %f", nmean,ipCh,prob[0],prob[1],prob[2],prob[3],prob[4]);
     661           0 :     pTrk->SetHMPIDpid(prob);
     662           0 :     delete hmpTrk;hmpTrk=0x0;
     663           0 :   }//iTrk
     664             : 
     665             :   return 0; // error code: 0=no error;
     666           0 : }//ReconFromKin()
     667             : //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     668             : Int_t AliHMPIDTracker::ReconHiddenTrk(AliESDEvent *pEsd,TObjArray *pClus,TObjArray *pNmean, TObjArray *pQthre)
     669             : {
     670             : // Static method to reconstruct Theta Ckov for all valid tracks of a given event.
     671             : // Arguments: pEsd- pointer ESD; pClu- pointer to clusters for all chambers; pNmean - pointer to all function Nmean=f(time), pQthre - pointer to all function Qthre=f(time)
     672             : //   Returns: error code, 0 if no errors
     673             :   
     674           0 :   AliHMPIDReconHTA reconHTA;                                                                     //instance of reconstruction class, nothing important in ctor
     675             :   
     676           0 :   AliHMPIDParam *pParam = AliHMPIDParam::Instance();                                             //Instance of AliHMPIDParam
     677             :  
     678             :   Bool_t tsRight = kTRUE;
     679             :  
     680           0 :   UInt_t tsmin = (UInt_t)((TF1*)pQthre->At(0))->GetXmin();                                        //
     681           0 :   UInt_t tsmax = (UInt_t)((TF1*)pQthre->At(0))->GetXmax();                                        //
     682           0 :   UInt_t ts = pEsd->GetTimeStamp();
     683             : 
     684           0 :   if(ts<tsmin || ts>tsmax) {
     685           0 :     AliWarning(Form(" in HMPID time stamp out of range!!! Please check!!! ts = %i",ts));
     686             :     tsRight = kFALSE;
     687           0 :   }
     688             :    
     689           0 :   for(Int_t iTrk=0;iTrk<pEsd->GetNumberOfTracks();iTrk++){                                        //loop on the ESD tracks in the event
     690             :     
     691           0 :     AliESDtrack *pTrk = pEsd->GetTrack(iTrk);                                                     //here it is simulated or just empty track
     692             :     Int_t ipCh;
     693           0 :     ipCh = pTrk->GetHMPIDcluIdx();ipCh/=1000000;
     694           0 :     if(ipCh<0) continue;
     695             : 
     696           0 :     TClonesArray *pMipCluLst=(TClonesArray *)pClus->At(ipCh);                                   //get the list of clusters
     697           0 :     Int_t nMipClusTot = pMipCluLst->GetEntries();                                               //total number of clusters in the given chamber
     698             :     
     699             :     Double_t qMip=-1;
     700             :     Int_t chMip=-1;    
     701             :     Double_t xMip = 0;
     702             :     Double_t yMip = 0;
     703             :     Int_t indMip  = 0;
     704             :     Int_t cluMipSiz = 0;
     705             : 
     706           0 :     for (Int_t iClu=0; iClu<nMipClusTot;iClu++) {                                               //clusters loop
     707             :       
     708           0 :       AliHMPIDCluster *pClu=(AliHMPIDCluster*)pMipCluLst->UncheckedAt(iClu);                    //get the cluster
     709           0 :       Double_t qClus = pClu->Q();
     710           0 :       if(qClus>qMip) {
     711             :         qMip  = qClus;
     712           0 :         chMip = pClu->Ch();
     713           0 :         xMip = pClu->X();
     714           0 :         yMip = pClu->Y();
     715             :         indMip = iClu;
     716           0 :         cluMipSiz = pClu->Size();
     717           0 :       }
     718             :     }//clus loop
     719             : 
     720           0 :     if(chMip<0) return 1;    
     721             :     
     722             :     Int_t hvsec;
     723             :     Double_t qthre=0;
     724             :     
     725             : // evaluate qThre
     726           0 :     if(tsRight){
     727           0 :     if(pQthre->GetEntriesFast()==pParam->kMaxCh+1) {                                              // just for backward compatibility
     728           0 :       qthre=((TF1*)pQthre->At(chMip))->Eval(ts);                                                  //
     729           0 :     } else {                                                                                      // in the past just 1 qthre
     730           0 :       hvsec = pParam->InHVSector(yMip);                                                           //  per chamber
     731           0 :       if(hvsec>=0) qthre=((TF1*)pQthre->At(6*chMip+hvsec))->Eval(ts);                             //
     732             :     } 
     733           0 :    } else qthre = pParam->QCut();
     734             : //
     735           0 :     if(qMip<qthre) {
     736           0 :       pTrk->SetHMPIDmip(xMip,yMip,(Int_t)qMip,0);                                                 //store mip info in any case 
     737           0 :       pTrk->SetHMPIDcluIdx(chMip,indMip+1000*cluMipSiz);                                                          
     738           0 :       pTrk->SetHMPIDsignal(pParam->kMipQdcCut);
     739           0 :       return 1;                                                                                   //charge compatible with MIP clusters      
     740             :     }
     741             :       
     742             :     pTrk->SetHMPIDmip(xMip,yMip,(Int_t)qMip,0);                                                   //store mip info in any case 
     743             :     pTrk->SetHMPIDcluIdx(chMip,indMip+1000*cluMipSiz);                                                          
     744             : 
     745             :     Double_t yRa = yMip;                                                                        //just an approx...
     746             :     Double_t nmean;
     747             : 
     748           0 :     Int_t iRad     = pParam->Radiator(yRa);                                                   //evaluate the radiator involved
     749             :     
     750             :     //evaluate nMean
     751           0 :     if(tsRight){
     752           0 :     if(pNmean->GetEntries()==21) {                                                              //for backward compatibility
     753           0 :       nmean=((TF1*)pNmean->At(3*chMip))->Eval(ts);                                              //C6F14 Nmean for this chamber
     754           0 :     } else {
     755           0 :       if(iRad < 0) {
     756             :         nmean = -1;
     757           0 :       } else {
     758           0 :       Double_t tLow  = ((TF1*)pNmean->At(6*chMip+2*iRad  ))->Eval(ts);                          //C6F14 low  temp for this chamber
     759           0 :       Double_t tHigh = ((TF1*)pNmean->At(6*chMip+2*iRad+1))->Eval(ts);                          //C6F14 high temp for this chamber
     760           0 :       Double_t tExp  = pParam->FindTemp(tLow,tHigh,yRa);                                        //estimated temp for that chamber at that y
     761           0 :       nmean = pParam->NIdxRad(AliHMPIDParam::Instance()->GetEPhotMean(),tExp);                  //mean ref idx @ a given temp
     762             :       }
     763           0 :       if(nmean < 0){                                                                            //track didn' t pass through the radiator
     764           0 :          pTrk->SetHMPIDsignal(AliHMPIDRecon::kNoRad);                                           //set the appropriate flag
     765           0 :          return 1;
     766             :         }
     767             :       } 
     768           0 :     } else nmean = pParam->MeanIdxRad();
     769             :     //
     770           0 :     if(!reconHTA.CkovHiddenTrk(pTrk,(TClonesArray *)pClus->At(ipCh),indMip,nmean)) {                 //search for track parameters and Cerenkov angle of this track
     771           0 :       AliHMPIDPid pID;
     772           0 :       Double_t prob[5];
     773           0 :       pID.FindPid(pTrk,nmean,5,prob);
     774           0 :       pTrk->SetHMPIDpid(prob);
     775           0 :     }
     776             : //      Printf(" Prob e- %6.2f mu %6.2f pi %6.2f k %6.2f p %6.2f",prob[0]*100,prob[1]*100,prob[2]*100,prob[3]*100,prob[4]*100);
     777           0 :   }//iTrk
     778             : 
     779           0 :   return 0; // error code: 0=no error;
     780             : 
     781           0 : }//Recon()
     782             : //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     783             : void AliHMPIDTracker::FillClusterArray(TObjArray* array) const {
     784             :   
     785             :  // Publishes all pointers to clusters known to the tracker into the
     786             :   // passed object array.
     787             :   // The ownership is not transfered - the caller is not expected to delete
     788             :   // the clusters
     789             :  
     790           0 :   for(Int_t iCh=AliHMPIDParam::kMinCh;iCh<=AliHMPIDParam::kMaxCh;iCh++){    
     791           0 :     TClonesArray *pCluArr=(TClonesArray*)(*fClu)[iCh];
     792           0 :     for (Int_t iClu=0; iClu<pCluArr->GetEntriesFast();iClu++){
     793           0 :       AliHMPIDCluster *pClu=(AliHMPIDCluster*)pCluArr->UncheckedAt(iClu);    
     794           0 :       array->AddLast(pClu);
     795             :     }//cluster loop in iCh
     796           0 :     pCluArr->Delete();
     797             :   }//Ch loop
     798             :     
     799           0 :   return;
     800             : }
     801             : //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Generated by: LCOV version 1.11