LCOV - code coverage report
Current view: top level - TOF/TOFrec - AliTOFtrackerMI.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 433 0.2 %
Date: 2016-06-14 17:26:59 Functions: 1 18 5.6 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       7             :  * Permission to use, copy, modify and distribute this software and its   *
       8             :  * documentation strictly for non-commercial purposes is hereby granted   *
       9             :  * without fee, provided that the above copyright notice appears in all   *
      10             :  * copies and that both the copyright notice and this permission notice   *
      11             :  * appear in the supporting documentation. The authors make no claims     *
      12             :  * about the suitability of this software for any purpose. It is          *
      13             :  * provided "as is" without express or implied warranty.                  *
      14             :  **************************************************************************/
      15             : 
      16             : //-----------------------------------------------------------------//
      17             : //                                                                 //
      18             : //   AliTOFtracker Class                                           //
      19             : //   Task: Perform association of the ESD tracks to TOF Clusters   //
      20             : //   and Update ESD track with associated TOF Cluster parameters   //
      21             : //                                                                 //
      22             : //-----------------------------------------------------------------//
      23             : 
      24             : #include <Rtypes.h>
      25             : 
      26             : #include "TClonesArray.h"
      27             : #include "TObjArray.h"
      28             : #include "TTree.h"
      29             : #include "TTreeStream.h"
      30             : 
      31             : #include "AliESDEvent.h"
      32             : #include "AliESDtrack.h"
      33             : #include "AliESDpid.h"
      34             : 
      35             : #include "AliTOFRecoParam.h"
      36             : #include "AliTOFReconstructor.h"
      37             : #include "AliTOFcluster.h"
      38             : #include "AliTOFGeometry.h"
      39             : #include "AliTOFtrackerMI.h"
      40             : #include "AliTOFtrack.h"
      41             : 
      42             : #include "AliMathBase.h"
      43             : 
      44             : class TGeoManager;
      45             : 
      46             : extern TGeoManager *gGeoManager;
      47             : 
      48          26 : ClassImp(AliTOFtrackerMI)
      49             : 
      50             : //_____________________________________________________________________________
      51           0 : AliTOFtrackerMI::AliTOFtrackerMI():
      52           0 :   fkRecoParam(0x0),
      53           0 :   fGeom(0x0),
      54           0 :   fN(0),
      55           0 :   fNseeds(0),
      56           0 :   fNseedsTOF(0),
      57           0 :   fngoodmatch(0),
      58           0 :   fnbadmatch(0),
      59           0 :   fnunmatch(0),
      60           0 :   fnmatch(0),
      61           0 :   fR(379.), 
      62           0 :   fTOFHeigth(15.3),  
      63           0 :   fdCut(3.), 
      64           0 :   fDx(1.5), 
      65           0 :   fDy(0), 
      66           0 :   fDz(0), 
      67           0 :   fTracks(new TClonesArray("AliTOFtrack")),
      68           0 :   fSeeds(new TObjArray(100)),
      69           0 :   fDebugStreamer(0x0)
      70           0 :  { 
      71             :   //AliTOFtrackerMI main Ctor
      72             : 
      73           0 :    for (Int_t ii=0; ii<kMaxCluster; ii++) fClusters[ii]=0x0;
      74             : 
      75           0 :    fDy=AliTOFGeometry::XPad(); 
      76           0 :    fDz=AliTOFGeometry::ZPad(); 
      77           0 :    fDebugStreamer = new TTreeSRedirector("TOFdebug.root");   
      78           0 : }
      79             : 
      80             : //_____________________________________________________________________________
      81           0 : AliTOFtrackerMI::~AliTOFtrackerMI(){
      82             :   //
      83             :   // Destructor
      84             :   //
      85           0 :   if (fDebugStreamer) {    
      86             :     //fDebugStreamer->Close();
      87           0 :     delete fDebugStreamer;
      88             :   }
      89           0 :   delete fkRecoParam;
      90           0 :   delete fGeom;
      91           0 :   if (fTracks){
      92           0 :     fTracks->Delete();
      93           0 :     delete fTracks;
      94           0 :     fTracks=0x0;
      95           0 :   }
      96           0 :   if (fSeeds){
      97           0 :     fSeeds->Delete();
      98           0 :     delete fSeeds;
      99           0 :     fSeeds=0x0;
     100           0 :   }
     101             : 
     102           0 :   for (Int_t ii=0; ii<kMaxCluster; ii++)
     103           0 :     if (fClusters[ii]) fClusters[ii]->Delete();
     104             : 
     105           0 : }
     106             : //_____________________________________________________________________________
     107             : void AliTOFtrackerMI::GetPidSettings(AliESDpid *esdPID) {
     108             :   // 
     109             :   // Sets TOF resolution from RecoParams
     110             :   //
     111           0 :   if (fkRecoParam)
     112           0 :     esdPID->GetTOFResponse().SetTimeResolution(fkRecoParam->GetTimeResolution());
     113             :   else
     114           0 :     AliWarning("fkRecoParam not yet set; cannot set PID settings");
     115           0 : }
     116             : 
     117             : //_____________________________________________________________________________
     118             : Int_t AliTOFtrackerMI::PropagateBack(AliESDEvent * const event) {
     119             :   //
     120             :   // Gets seeds from ESD event and Match with TOF Clusters
     121             :   //
     122             : 
     123             :   // initialize RecoParam for current event
     124           0 :   AliDebug(1,"Initializing params for TOF");
     125             : 
     126           0 :   fkRecoParam = AliTOFReconstructor::GetRecoParam();  // instantiate reco param from STEER...
     127             : 
     128           0 :   if (fkRecoParam == 0x0) { 
     129           0 :     AliFatal("No Reco Param found for TOF!!!");
     130           0 :   }
     131             :   //fkRecoParam->Dump();
     132             :   //if(fkRecoParam->GetApplyPbPbCuts())fkRecoParam=fkRecoParam->GetPbPbparam();
     133             :   //fkRecoParam->PrintParameters();
     134             : 
     135             :   //Initialise some counters
     136             : 
     137           0 :   fNseeds=0;
     138           0 :   fNseedsTOF=0;
     139           0 :   fngoodmatch=0;
     140           0 :   fnbadmatch=0;
     141           0 :   fnunmatch=0;
     142           0 :   fnmatch=0;
     143             : 
     144           0 :   Int_t ntrk=event->GetNumberOfTracks();
     145           0 :   fNseeds = ntrk;
     146             : 
     147             :   //Load ESD tracks into a local Array of ESD Seeds
     148           0 :   for (Int_t i=0; i<fNseeds; i++)
     149           0 :     fSeeds->AddLast(event->GetTrack(i));
     150             : 
     151             :   //Prepare ESD tracks candidates for TOF Matching
     152           0 :   CollectESD();
     153             : 
     154             :   //First Step with Strict Matching Criterion
     155             :   //MatchTracks(kFALSE);
     156             : 
     157             :   //Second Step with Looser Matching Criterion
     158             :   //MatchTracks(kTRUE);
     159           0 :   MatchTracksMI(kFALSE);  // assign track to clusters
     160           0 :   MatchTracksMI(kTRUE);   // assign clusters to esd
     161             :   
     162           0 :   AliInfo(Form("Number of matched tracks = %d (good = %d, bad = %d)",fnmatch,fngoodmatch,fnbadmatch));
     163             : 
     164             :   //Update the matched ESD tracks
     165             : 
     166           0 :   for (Int_t i=0; i<ntrk; i++) {
     167           0 :     AliESDtrack *t=event->GetTrack(i);
     168           0 :     AliESDtrack *seed =(AliESDtrack*)fSeeds->At(i);
     169             : 
     170           0 :     if ( (seed->GetStatus()&AliESDtrack::kTOFin)!=0 ) {
     171           0 :       t->SetStatus(AliESDtrack::kTOFin);
     172             :       //if(seed->GetTOFsignal()>0){
     173           0 :       if ( (seed->GetStatus()&AliESDtrack::kTOFout)!=0 ) {
     174           0 :         t->SetStatus(AliESDtrack::kTOFout);
     175           0 :         t->SetTOFsignal(seed->GetTOFsignal());
     176           0 :         t->SetTOFcluster(seed->GetTOFcluster());
     177           0 :         Int_t tlab[3]; seed->GetTOFLabel(tlab);    
     178           0 :         t->SetTOFLabel(tlab);
     179             : 
     180             :         // Check done:
     181             :         //       by calling the AliESDtrack::UpdateTrackParams,
     182             :         //       the current track parameters are changed
     183             :         //       and it could cause refit problems.
     184             :         //       We need to update only the following track parameters:
     185             :         //            the track length and expected times.
     186             :         //       Removed AliESDtrack::UpdateTrackParams call
     187             :         //       Called AliESDtrack::SetIntegratedTimes(...) and
     188             :         //       AliESDtrack::SetIntegratedLength() routines.
     189             :         /*
     190             :         AliTOFtrack *track = new AliTOFtrack(*seed);
     191             :         t->UpdateTrackParams(track,AliESDtrack::kTOFout);
     192             :         delete track;
     193             :         */
     194             : 
     195           0 :         Double_t times[10]; seed->GetIntegratedTimes(times);
     196           0 :         t->SetIntegratedTimes(times);
     197           0 :         t->SetIntegratedLength(seed->GetIntegratedLength());
     198           0 :         t->SetTOFsignalToT(seed->GetTOFsignalToT());
     199           0 :         t->SetTOFCalChannel(seed->GetTOFCalChannel());
     200           0 :         t->SetTOFDeltaBC(seed->GetTOFDeltaBC());
     201           0 :         t->SetTOFL0L1(seed->GetTOFL0L1());
     202             :         //
     203             :         // Make attention, please:
     204             :         //      AliESDtrack::fTOFInfo array does not be stored in the AliESDs.root file
     205             :         //      it is there only for a check during the reconstruction step.
     206           0 :         Float_t info[10];
     207           0 :         seed->GetTOFInfo(info);
     208           0 :         t->SetTOFInfo(info);
     209           0 :       }
     210             :     }
     211             :   }
     212             : 
     213             : 
     214             :   //Make TOF PID
     215             : 
     216           0 :   fSeeds->Clear();
     217           0 :   fTracks->Delete();
     218           0 :   return 0;
     219             :   
     220             : }
     221             : //_________________________________________________________________________
     222             : void AliTOFtrackerMI::CollectESD() {
     223             :    //prepare the set of ESD tracks to be matched to clusters in TOF
     224             :  
     225           0 :   TClonesArray &aTOFTrack = *fTracks;
     226             :   Int_t c0=0;
     227             :   Int_t c1=0;
     228           0 :   for (Int_t i=0; i<fNseeds; i++) {
     229             : 
     230           0 :     AliESDtrack *t =(AliESDtrack*)fSeeds->At(i);
     231           0 :     if ((t->GetStatus()&AliESDtrack::kTPCout)==0)continue;
     232             : 
     233           0 :     AliTOFtrack *track = new AliTOFtrack(*t); // New
     234           0 :     Float_t x = (Float_t)track->GetX(); //New
     235             : 
     236             :     // TRD good tracks, already propagated at 371 cm
     237           0 :     if ( ( (t->GetStatus()&AliESDtrack::kTRDout)!=0 ) &&
     238           0 :          ( x >= AliTOFGeometry::Rmin() ) ) {
     239           0 :       if  ( track->PropagateToInnerTOF() ) {
     240           0 :         track->SetSeedIndex(i);
     241           0 :         t->UpdateTrackParams(track,AliESDtrack::kTOFin);
     242           0 :         new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
     243           0 :         fNseedsTOF++;
     244           0 :         c0++;
     245           0 :         delete track;
     246             :       }
     247             :     }
     248             : 
     249             :     // Propagate the rest of TPCbp
     250             :     else {
     251           0 :       if ( track->PropagateToInnerTOF() ) { // temporary solution
     252           0 :         track->SetSeedIndex(i);
     253           0 :         t->UpdateTrackParams(track,AliESDtrack::kTOFin);
     254           0 :         new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
     255           0 :         fNseedsTOF++;
     256           0 :         c1++;
     257           0 :       }
     258           0 :       delete track;
     259             :     }
     260           0 :   }
     261             :   //
     262             :   //
     263           0 :   printf("TRD\tOn\t%d\tOff\t%d\n",c0,c1);
     264             : 
     265             :   // Sort according uncertainties on track position 
     266           0 :   fTracks->Sort();
     267             : 
     268           0 : }
     269             : 
     270             : //_________________________________________________________________________
     271             : void AliTOFtrackerMI::MatchTracks( Bool_t /*mLastStep*/) const {
     272           0 :   return;
     273             : }
     274             : //
     275             : //
     276             : //_________________________________________________________________________
     277             : void AliTOFtrackerMI::MatchTracksMI(Bool_t mLastStep){
     278             : 
     279             :   //Match ESD tracks to clusters in TOF
     280             :   const Float_t kTofOffset   = 0;  // time offset
     281             :   const Float_t kMinQuality  = -6.; // minimal quality
     282             :   const Float_t kMaxQualityD = 1.;  // max delta quality if cluster used
     283             :   const Float_t kForbiddenR  = 0.1; // minimal PID according TPC
     284             : 
     285             :   static const Double_t kMasses[AliPID::kSPECIES+1]={
     286             :     0.000511, 0.105658, 0.139570, 0.493677, 0.938272, 1.875613
     287             :   };
     288             :   
     289           0 :   Int_t nSteps=(Int_t)(fTOFHeigth/0.1);
     290             : 
     291             :   //PH Arrays (moved outside of the loop)
     292           0 :   Float_t * trackPos[4];
     293           0 :   for (Int_t ii=0; ii<4; ii++) trackPos[ii] = new Float_t[nSteps];
     294           0 :   Int_t * clind = new Int_t[fN];
     295             : 
     296             :   // Some init 
     297             :   const Int_t kNclusterMax = 1000; // related to fN value  
     298           0 :   AliTOFcluster *clusters[kNclusterMax];
     299           0 :   Int_t         index[kNclusterMax];
     300           0 :   Float_t       quality[kNclusterMax];
     301           0 :   Float_t       dist3D[kNclusterMax][6];
     302           0 :   Double_t      times[kNclusterMax][6];
     303           0 :   Float_t       mintimedist[kNclusterMax];
     304           0 :   Float_t       likelihood[kNclusterMax];
     305           0 :   Float_t       length[kNclusterMax];
     306           0 :   Double_t      tpcpid[AliPID::kSPECIES+1]; // overrun_static - coverity warning
     307           0 :   dist3D[0][0]=1;
     308             :   
     309           0 :   for (Int_t i=0; i<fNseedsTOF; i++) {
     310             : 
     311           0 :     AliTOFtrack *track =(AliTOFtrack*)fTracks->UncheckedAt(i);
     312           0 :     AliESDtrack *t =(AliESDtrack*)fSeeds->At(track->GetSeedIndex());
     313           0 :     Bool_t hasTime = ( (t->GetStatus()& AliESDtrack::kTIME)>0) ? kTRUE:kFALSE;   // did we integrate time
     314           0 :     Float_t trdquality = t->GetTRDQuality();
     315             :     //
     316             :     // Normalize tpc pid
     317             :     //
     318           0 :     t->GetTPCpid(tpcpid);
     319             :     Double_t sumpid=0;
     320           0 :     for (Int_t ipid=0;ipid<AliPID::kSPECIES;ipid++){
     321           0 :       sumpid+=tpcpid[ipid];
     322             :     }
     323           0 :     for (Int_t ipid=0;ipid<AliPID::kSPECIES;ipid++){
     324           0 :       if (sumpid>0) tpcpid[ipid]/=sumpid;
     325             :       else{
     326           0 :         tpcpid[ipid]=0.2;
     327             :       }
     328             :     }
     329             : 
     330           0 :     if (trdquality<0) continue; // no chance 
     331             :     //
     332           0 :     AliTOFtrack *trackTOFin =new AliTOFtrack(*track);     
     333             :     //
     334             :     //propagat track to the middle of TOF
     335             :     //
     336             :     Float_t xs = 379.2;  // should be defined in the TOF geometry
     337           0 :     Double_t ymax=xs*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());  
     338           0 :     Bool_t skip=kFALSE;
     339           0 :     Double_t ysect=trackTOFin->GetYat(xs,skip);
     340           0 :     if (skip){
     341             :       xs = 373.;
     342           0 :       ymax=xs*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());
     343           0 :       ysect=trackTOFin->GetYat(xs,skip);
     344           0 :     }
     345           0 :     if (ysect > ymax) {
     346           0 :       if (!trackTOFin->Rotate(AliTOFGeometry::GetAlpha())) {
     347           0 :         continue;
     348             :       }
     349           0 :     } else if (ysect <-ymax) {
     350           0 :       if (!trackTOFin->Rotate(-AliTOFGeometry::GetAlpha())) {
     351           0 :         continue;
     352             :       }
     353             :     }    
     354           0 :     if(!trackTOFin->PropagateTo(xs)) {
     355           0 :       continue;
     356             :     }
     357             :     //
     358             :     // Determine a window around the track
     359             :     //
     360           0 :     Double_t x,par[5]; 
     361           0 :     trackTOFin->GetExternalParameters(x,par);
     362           0 :     Double_t cov[15]; 
     363           0 :     trackTOFin->GetExternalCovariance(cov);
     364             : 
     365           0 :     if (cov[0]<0. || cov[2]<0.) {
     366           0 :       AliWarning(Form("Very strange track (%d)! At least one of its covariance matrix diagonal elements is negative!",i));
     367             :       //delete trackTOFin;
     368             :       //continue;
     369           0 :     }
     370             : 
     371             :     Float_t scalefact=3.;    
     372             :     Double_t dphi=
     373           0 :       scalefact*
     374           0 :       ((5*TMath::Sqrt(TMath::Abs(cov[0])) + 3.*fDy + 10.*TMath::Abs(par[2]))/fR); 
     375             :     Double_t dz=
     376           0 :       scalefact*
     377           0 :       (5*TMath::Sqrt(TMath::Abs(cov[2])) + 3.*fDz + 10.*TMath::Abs(par[3]));
     378             :     
     379           0 :     Double_t phi=TMath::ATan2(par[0],x) + trackTOFin->GetAlpha();
     380           0 :     if (phi<-TMath::Pi())phi+=2*TMath::Pi();
     381           0 :     if (phi>=TMath::Pi())phi-=2*TMath::Pi();
     382           0 :     Double_t z=par[1];   
     383             : 
     384             :     Int_t nc     =0;
     385             :     Int_t nfound =0;
     386             :     // find the clusters in the window of the track
     387             : 
     388           0 :     for (Int_t k=FindClusterIndex(z-dz); k<fN; k++) {
     389             : 
     390           0 :       if (nc>=kNclusterMax) {
     391           0 :         AliWarning("No more matchable clusters can be stored! Please, increase the corresponding vectors size.");
     392           0 :         break;
     393             :       }
     394             : 
     395           0 :       AliTOFcluster *c=fClusters[k];
     396           0 :       if (c->GetZ() > z+dz) break;
     397             :       //      if (c->IsUsed()) continue;
     398             :       
     399           0 :       Double_t dph=TMath::Abs(c->GetPhi()-phi);
     400           0 :       if (dph>TMath::Pi()) dph-=2.*TMath::Pi();
     401           0 :       if (TMath::Abs(dph)>dphi) continue;
     402             : 
     403           0 :       clind[nc] = k;
     404           0 :       nc++;
     405           0 :     }
     406             : 
     407           0 :     AliDebug(1,Form(" Number of matchable TOF clusters for the track number %d: %d",i,nc));
     408             : 
     409             :     //
     410             :     // select close clusters
     411             :     //
     412           0 :     Double_t mom=t->GetP();
     413             :     //    Bool_t dump = kTRUE;
     414           0 :     for (Int_t icl=0; icl<nc; icl++){
     415           0 :       Float_t distances[5];
     416             : 
     417           0 :       index[nfound]=clind[icl];
     418           0 :       AliTOFcluster *cluster = fClusters[clind[icl]];
     419           0 :       GetLinearDistances(trackTOFin, cluster, distances);
     420           0 :       dist3D[nfound][0] = distances[4];
     421           0 :       dist3D[nfound][1] = distances[1];
     422           0 :       dist3D[nfound][2] = distances[2];
     423             :       // cut on distance
     424           0 :       if (TMath::Abs(dist3D[nfound][1])>20 || TMath::Abs(dist3D[nfound][2])>20) continue;
     425             :       //
     426           0 :       GetLikelihood(distances[1],distances[2],cov,trackTOFin, dist3D[nfound][3], dist3D[nfound][4]);   
     427             :       //
     428             :       // cut on likelihood      
     429           0 :       if (dist3D[nfound][3]*dist3D[nfound][4]<0.00000000000001) continue;  // log likelihood
     430           0 :       if (TMath::Log(dist3D[nfound][3]*dist3D[nfound][4])<-9) continue;  // log likelihood
     431             :       //
     432           0 :       clusters[nfound] = cluster;
     433             :       //
     434             :       //length and TOF updates 
     435           0 :       trackTOFin->GetIntegratedTimes(times[nfound]);
     436           0 :       length[nfound] = trackTOFin->GetIntegratedLength();
     437           0 :       length[nfound]+=distances[4];
     438           0 :       mintimedist[nfound]=1000; 
     439           0 :       Double_t tof2=AliTOFGeometry::TdcBinWidth()*cluster->GetTDC()+kTofOffset; // in ps
     440             :       // Float_t tgamma = TMath::Sqrt(cluster->GetR()*cluster->GetR()+cluster->GetZ()*cluster->GetZ())/0.03;  //time for "primary" gamma
     441             :       //if (trackTOFin->GetPt()<0.7 && TMath::Abs(tgamma-tof2)<350) continue;  // gamma conversion candidate - TEMPORARY
     442           0 :       for(Int_t j=0;j<AliPID::kSPECIES+1;j++){
     443             :         
     444           0 :         Double_t mass=kMasses[j];
     445           0 :         times[nfound][j]+=distances[4]/3e-2*TMath::Sqrt(mom*mom+mass*mass)/mom;   // add time distance
     446           0 :         if ( TMath::Abs(times[nfound][j]-tof2)<mintimedist[nfound] && tpcpid[j]>kForbiddenR){
     447           0 :           mintimedist[nfound]=TMath::Abs(times[nfound][j]-tof2);
     448           0 :         }
     449             :       }
     450             :       //
     451           0 :       Float_t   liketime =  TMath::Exp(-mintimedist[nfound]/90.)+0.25*TMath::Exp(-mintimedist[nfound]/180.);
     452           0 :       if (!hasTime)  liketime=0.2;
     453           0 :       likelihood[nfound] = TMath::Log(dist3D[nfound][3]*dist3D[nfound][4]*liketime);
     454             :       
     455           0 :       if (TMath::Log(dist3D[nfound][3]*dist3D[nfound][4])<-1){
     456           0 :         if (likelihood[nfound]<-9.) continue;
     457             :       }
     458             :       //
     459           0 :       nfound++;
     460           0 :     }
     461             : 
     462           0 :     AliDebug(1,Form(" Number of track points for the track number %d: %d",i,nfound));
     463             : 
     464           0 :     if (nfound == 0 ) {
     465           0 :       fnunmatch++;
     466           0 :       delete trackTOFin;
     467           0 :       continue;
     468             :     } 
     469             :     //
     470             :     //choose the best cluster
     471             :     //
     472             :     //Float_t quality[kNclusterMax];
     473             :     //Int_t   index[kNclusterMax];
     474           0 :     for (Int_t kk=0; kk<kNclusterMax; kk++) quality[kk]=0;
     475             :     //
     476             :     AliTOFcluster * cgold=0;
     477             :     Int_t igold =-1;
     478           0 :     for (Int_t icl=0;icl<nfound;icl++){
     479           0 :       quality[icl] = dist3D[icl][3]*dist3D[icl][4];
     480             :     }
     481           0 :     TMath::Sort(nfound,quality,index,kTRUE);
     482           0 :     igold =  index[0];
     483           0 :     cgold =  clusters[igold];
     484           0 :     if (nfound>1 &&likelihood[index[1]]>likelihood[index[0]]){
     485           0 :       if ( quality[index[0]]<quality[index[1]]+0.5){
     486             :         igold = index[1];
     487           0 :         cgold =  clusters[igold];
     488           0 :       }
     489             :     }
     490             :     //
     491             :     //
     492           0 :     Float_t qualityGold = TMath::Log(0.0000001+(quality[igold]*(0.1+TMath::Exp(-mintimedist[igold]/80.))*(0.2+trdquality)));
     493           0 :     if (!mLastStep){
     494           0 :       if (cgold->GetQuality()<qualityGold) cgold->SetQuality(qualityGold);
     495           0 :       continue;
     496             :     }
     497             :     //
     498           0 :     if (mLastStep){
     499             :       //signed better cluster
     500           0 :       if (cgold->GetQuality()>qualityGold+kMaxQualityD) continue;
     501           0 :       if (2.*qualityGold-cgold->GetQuality()<kMinQuality) continue;
     502             :     }
     503             :  
     504             :     Int_t inonfake=-1;
     505             :     
     506           0 :     for (Int_t icl=0;icl<nfound;icl++){
     507             :       if (
     508           0 :           (clusters[index[icl]]->GetLabel(0)==TMath::Abs(trackTOFin->GetLabel()))
     509           0 :           ||
     510           0 :           (clusters[index[icl]]->GetLabel(1)==TMath::Abs(trackTOFin->GetLabel()))
     511           0 :           ||
     512           0 :           (clusters[index[icl]]->GetLabel(2)==TMath::Abs(trackTOFin->GetLabel()))
     513             :           ) {
     514             :         inonfake = icl;
     515           0 :         break;
     516             :       }
     517             :     }    
     518           0 :     fnmatch++;;
     519           0 :     if (inonfake==0) fngoodmatch++;
     520             :     else{
     521           0 :       fnbadmatch++;
     522             :     }
     523             : 
     524           0 :     Int_t tlab[3];
     525           0 :     tlab[0]=cgold->GetLabel(0);
     526           0 :     tlab[1]=cgold->GetLabel(1);
     527           0 :     tlab[2]=cgold->GetLabel(2);
     528             :     //    Double_t tof2=25.*cgold->GetTDC()-350; // in ps
     529           0 :     Double_t tof2=AliTOFGeometry::TdcBinWidth()*cgold->GetTDC()+kTofOffset; // in ps
     530           0 :     Float_t tgamma = TMath::Sqrt(cgold->GetR()*cgold->GetR()+cgold->GetZ()*cgold->GetZ())/0.03;
     531           0 :     Float_t info[10]={dist3D[igold][0],
     532           0 :                       dist3D[igold][1],
     533           0 :                       dist3D[igold][2],
     534           0 :                       dist3D[igold][3],
     535           0 :                       dist3D[igold][4],
     536           0 :                       mintimedist[igold],
     537             :                       -1,
     538             :                       tgamma,
     539             :                       qualityGold,
     540           0 :                       static_cast<Float_t>(cgold->GetQuality())};
     541             :     //    GetLinearDistances(trackTOFin,cgold,&info[6]);
     542           0 :     if (inonfake>=0){
     543           0 :       info[6] = inonfake;
     544             :       //      info[7] = mintimedist[index[inonfake]];
     545           0 :     }
     546             :     //
     547             :     //  Store quantities to be used for TOF Calibration
     548           0 :     Float_t tToT=cgold->GetToT(); // in ps
     549           0 :     t->SetTOFsignalToT(tToT);
     550           0 :     Int_t ind[5];
     551           0 :     ind[0]=cgold->GetDetInd(0);
     552           0 :     ind[1]=cgold->GetDetInd(1);
     553           0 :     ind[2]=cgold->GetDetInd(2);
     554           0 :     ind[3]=cgold->GetDetInd(3);
     555           0 :     ind[4]=cgold->GetDetInd(4);
     556           0 :     Int_t calindex = AliTOFGeometry::GetIndex(ind);
     557           0 :     t->SetTOFCalChannel(calindex);
     558             : 
     559           0 :     t->SetTOFInfo(info);
     560           0 :     t->SetTOFsignal(tof2);
     561           0 :     t->SetTOFcluster(cgold->GetIndex());  
     562           0 :     t->SetTOFDeltaBC(cgold->GetDeltaBC());
     563           0 :     t->SetTOFL0L1(cgold->GetL0L1Latency());
     564             : 
     565           0 :     AliDebug(2, Form("%7i     %7i     %10i     %10i  %10i  %10i      %7i",
     566             :                      i,
     567             :                      fnmatch-1,
     568             :                      TMath::Abs(trackTOFin->GetLabel()),
     569             :                      tlab[0], tlab[1], tlab[2],
     570             :                      igold)); // AdC
     571             : 
     572           0 :     AliTOFtrack *trackTOFout = new AliTOFtrack(*t); 
     573           0 :     trackTOFout->PropagateTo(379.);
     574             : 
     575             :     // Fill the track residual histograms.
     576           0 :     FillResiduals(trackTOFout,cgold,kFALSE);
     577             : 
     578           0 :     t->UpdateTrackParams(trackTOFout,AliESDtrack::kTOFout);    
     579           0 :     t->SetIntegratedLength(length[igold]);
     580           0 :     t->SetIntegratedTimes(times[igold]);
     581           0 :     t->SetTOFLabel(tlab);
     582             :     //
     583           0 :     delete trackTOFin;
     584           0 :     delete trackTOFout;
     585             :     //
     586           0 :   }
     587             :   //
     588             :   //
     589             :   //
     590           0 :   for (Int_t ii=0; ii<4; ii++) delete [] trackPos[ii];
     591           0 :   delete [] clind;
     592             :   //delete calib; // AdC
     593           0 : }
     594             : //_________________________________________________________________________
     595             : 
     596             : Int_t AliTOFtrackerMI::LoadClusters(TTree *cTree) {
     597             :   //--------------------------------------------------------------------
     598             :   //This function loads the TOF clusters
     599             :   //--------------------------------------------------------------------
     600             : 
     601           0 :   TBranch *branch=cTree->GetBranch("TOF");
     602           0 :   if (!branch) { 
     603           0 :     AliError("can't get the branch with the TOF clusters !");
     604           0 :     return 1;
     605             :   }
     606             : 
     607           0 :   static TClonesArray dummy("AliTOFcluster",10000);
     608           0 :   dummy.Clear();
     609           0 :   TClonesArray *clusters=&dummy;
     610           0 :   branch->SetAddress(&clusters);
     611             : 
     612           0 :   cTree->GetEvent(0);
     613           0 :   Int_t nc=clusters->GetEntriesFast();
     614           0 :   AliInfo(Form("Number of clusters: %d",nc));
     615             : 
     616           0 :   for (Int_t i=0; i<nc; i++) {
     617           0 :     AliTOFcluster *c=(AliTOFcluster*)clusters->UncheckedAt(i);
     618             : 
     619             : //PH    fClusters[i]=new AliTOFcluster(*c); fN++;
     620           0 :     fClusters[i]=c; fN++;
     621             : 
     622             :     //AliInfo(Form("%4i %4i  %f %f %f  %f %f   %2i %1i %2i %1i %2i",i, fClusters[i]->GetIndex(),fClusters[i]->GetZ(),fClusters[i]->GetR(),fClusters[i]->GetPhi(), fClusters[i]->GetTDC(),fClusters[i]->GetADC(),fClusters[i]->GetDetInd(0),fClusters[i]->GetDetInd(1),fClusters[i]->GetDetInd(2),fClusters[i]->GetDetInd(3),fClusters[i]->GetDetInd(4)));
     623             :     //AliInfo(Form("%i %f",i, fClusters[i]->GetZ()));
     624             :   }
     625             : 
     626             :   //AliInfo(Form("Number of clusters: %d",fN));
     627             : 
     628             :   return 0;
     629           0 : }
     630             : //_________________________________________________________________________
     631             : void AliTOFtrackerMI::UnloadClusters() {
     632             :   //--------------------------------------------------------------------
     633             :   //This function unloads TOF clusters
     634             :   //--------------------------------------------------------------------
     635           0 :   for (Int_t i=0; i<fN; i++) {
     636             : //PH    delete fClusters[i];
     637           0 :     fClusters[i] = 0x0;
     638             :   }
     639           0 :   fN=0;
     640           0 : }
     641             : 
     642             : 
     643             : 
     644             : 
     645             : //_________________________________________________________________________
     646             : Int_t AliTOFtrackerMI::InsertCluster(AliTOFcluster *c) {
     647             :   //--------------------------------------------------------------------
     648             :   //This function adds a cluster to the array of clusters sorted in Z
     649             :   //--------------------------------------------------------------------
     650           0 :   if (fN==kMaxCluster) {
     651           0 :     AliError("Too many clusters !");
     652           0 :     return 1;
     653             :   }
     654             : 
     655           0 :   if (fN==0) {fClusters[fN++]=c; return 0;}
     656           0 :   Int_t i=FindClusterIndex(c->GetZ());
     657           0 :   memmove(fClusters+i+1 ,fClusters+i,(fN-i)*sizeof(AliTOFcluster*));
     658           0 :   fClusters[i]=c; fN++;
     659             : 
     660             :   return 0;
     661           0 : }
     662             : 
     663             : //_________________________________________________________________________
     664             : Int_t AliTOFtrackerMI::FindClusterIndex(Double_t z) const {
     665             :   //--------------------------------------------------------------------
     666             :   // This function returns the index of the nearest cluster 
     667             :   //--------------------------------------------------------------------
     668           0 :   if (fN==0) return 0;
     669           0 :   if (z <= fClusters[0]->GetZ()) return 0;
     670           0 :   if (z > fClusters[fN-1]->GetZ()) return fN;
     671           0 :   Int_t b=0, e=fN-1, m=(b+e)/2;
     672           0 :   for (; b<e; m=(b+e)/2) {
     673           0 :     if (z > fClusters[m]->GetZ()) b=m+1;
     674             :     else e=m; 
     675             :   }
     676             :   return m;
     677           0 : }
     678             : 
     679             : //_________________________________________________________________________
     680             : Float_t AliTOFtrackerMI::GetLinearDistances(AliTOFtrack * track, AliTOFcluster *cluster, Float_t distances[5])
     681             : {
     682             :   //
     683             :   // calclates distance between cluster and track
     684             :   // use linear aproximation
     685             :   //
     686             :   //const Float_t kRaddeg = 180/3.14159265358979312;
     687           0 :   const Float_t kRaddeg = TMath::RadToDeg();
     688             :   //
     689             :   //  Float_t tiltangle  = fGeom->GetAngles(cluster->fdetIndex[1],cluster->fdetIndex[2])/kRaddeg;  //tiltangle  
     690           0 :   Int_t cind[5];
     691           0 :   cind[0]= cluster->GetDetInd(0);
     692           0 :   cind[1]= cluster->GetDetInd(1);
     693           0 :   cind[2]= cluster->GetDetInd(2);
     694           0 :   cind[3]= cluster->GetDetInd(3);
     695           0 :   cind[4]= cluster->GetDetInd(4);
     696           0 :   Float_t tiltangle  = AliTOFGeometry::GetAngles(cluster->GetDetInd(1),cluster->GetDetInd(2))/kRaddeg;  //tiltangle  
     697             : 
     698           0 :   Float_t cpos[3];  //cluster position
     699           0 :   Float_t cpos0[3];  //cluster position
     700             :   //  fGeom->GetPos(cluster->fdetIndex,cpos);  
     701             :   //fGeom->GetPos(cluster->fdetIndex,cpos0);  
     702             :   //
     703           0 :   fGeom->GetPos(cind,cpos);  
     704           0 :   fGeom->GetPos(cind,cpos0);  
     705             : 
     706           0 :   Float_t phi = TMath::ATan2(cpos[1],cpos[0]);  
     707           0 :   if(phi<0) phi=2.*TMath::Pi()+phi;
     708             :   //  Get the local angle in the sector philoc
     709           0 :   Float_t phiangle = (Int_t (phi*kRaddeg/20.) + 0.5)*20./kRaddeg;
     710             :   //
     711           0 :   Double_t v0[3];
     712           0 :   Double_t dir[3];
     713           0 :   track->GetXYZ(v0);
     714           0 :   track->GetPxPyPz(dir);
     715           0 :   dir[0]/=track->GetP();
     716           0 :   dir[1]/=track->GetP();
     717           0 :   dir[2]/=track->GetP();
     718             :   //
     719             :   //
     720             :   //rotate 0
     721           0 :   Float_t sinphi = TMath::Sin(phiangle);
     722           0 :   Float_t cosphi = TMath::Cos(phiangle);
     723           0 :   Float_t sinth  = TMath::Sin(tiltangle);
     724           0 :   Float_t costh  = TMath::Cos(tiltangle);
     725             :   //
     726             :   Float_t temp;
     727           0 :   temp    =  cpos[0]*cosphi+cpos[1]*sinphi;
     728           0 :   cpos[1] = -cpos[0]*sinphi+cpos[1]*cosphi;
     729           0 :   cpos[0] = temp;
     730           0 :   temp  =  v0[0]*cosphi+v0[1]*sinphi;
     731           0 :   v0[1] = -v0[0]*sinphi+v0[1]*cosphi;
     732           0 :   v0[0] = temp;
     733             :   //  
     734           0 :   temp    =  cpos[0]*costh+cpos[2]*sinth;
     735           0 :   cpos[2] = -cpos[0]*sinth+cpos[2]*costh;
     736           0 :   cpos[0] = temp;
     737           0 :   temp   =  v0[0]*costh+v0[2]*sinth;
     738           0 :   v0[2]  = -v0[0]*sinth+v0[2]*costh;
     739           0 :   v0[0]  = temp;
     740             :   //
     741             :   //
     742             :   //rotate direction vector
     743             :   //
     744           0 :   temp   =  dir[0]*cosphi+dir[1]*sinphi;
     745           0 :   dir[1] = -dir[0]*sinphi+dir[1]*cosphi;
     746           0 :   dir[0] = temp;
     747             :   //
     748           0 :   temp   =  dir[0]*costh+dir[2]*sinth;
     749           0 :   dir[2] = -dir[0]*sinth+dir[2]*costh;
     750           0 :   dir[0] = temp;
     751             :   //
     752             :   Float_t v3[3];
     753           0 :   Float_t k = (cpos[0]-v0[0])/dir[0];
     754           0 :   v3[0] = v0[0]+k*dir[0];
     755           0 :   v3[1] = v0[1]+k*dir[1];
     756           0 :   v3[2] = v0[2]+k*dir[2];
     757             :   //
     758           0 :   distances[0] = v3[0]-cpos[0];
     759           0 :   distances[1] = v3[1]-cpos[1];
     760           0 :   distances[2] = v3[2]-cpos[2];
     761           0 :   distances[3] = TMath::Sqrt( distances[0]*distances[0]+distances[1]*distances[1]+distances[2]*distances[2]); //distance
     762           0 :   distances[4] = k;  //length
     763             : 
     764             :   //
     765             :   // Debuging part of the matching
     766             :   //
     767           0 :   if (track->GetLabel()==cluster->GetLabel(0) ||
     768           0 :       track->GetLabel()==cluster->GetLabel(1) ||
     769           0 :       track->GetLabel()==cluster->GetLabel(2) ){
     770           0 :     TTreeSRedirector& cstream = *fDebugStreamer;
     771           0 :     Float_t tdc = cluster->GetTDC();
     772           0 :     cstream<<"Tracks"<<
     773           0 :       "TOF.="<<track<<
     774           0 :       "Cx="<<cpos0[0]<<
     775           0 :       "Cy="<<cpos0[1]<<
     776           0 :       "Cz="<<cpos0[2]<<
     777           0 :       "Dist="<<k<<
     778           0 :       "Dist0="<<distances[0]<<
     779           0 :       "Dist1="<<distances[1]<<
     780           0 :       "Dist2="<<distances[2]<<
     781           0 :       "TDC="<<tdc<<
     782             :       "\n";
     783           0 :   }
     784           0 :   return distances[3];
     785           0 : }
     786             : 
     787             : //_________________________________________________________________________
     788             : void AliTOFtrackerMI::GetLikelihood(Float_t dy, Float_t dz, const Double_t *cov, AliTOFtrack * /*track*/, Float_t & py, Float_t &pz) const
     789             : {
     790             :   //
     791             :   //  get likelihood - track covariance taken
     792             :   //  75 % of gauss with expected sigma
     793             :   //  25 % of gauss with extended sigma
     794             :   
     795             :   Double_t kMaxSigmaY  = 0.6;  // ~ 90% of TRD tracks  
     796             :   Double_t kMaxSigmaZ  = 1.2;  // ~ 90% of TRD tracks 
     797             :   Double_t kMeanSigmaY = 0.25; // mean TRD sigma  
     798             :   Double_t kMeanSigmaZ = 0.5;  // mean TRD sigma 
     799             : 
     800             :   
     801             :   Float_t normwidth, normd, p0,p1;  
     802           0 :   Float_t sigmay = TMath::Max(TMath::Sqrt(TMath::Abs(cov[0])+kMeanSigmaY*kMeanSigmaY),kMaxSigmaY);
     803           0 :   Float_t sigmaz = TMath::Max(TMath::Sqrt(TMath::Abs(cov[2])+kMeanSigmaZ*kMeanSigmaZ),kMaxSigmaZ);
     804             : 
     805           0 :   py=0;
     806           0 :   pz=0;  
     807             :   // 
     808             :   // py calculation   - 75% admixture of original sigma - 25% tails 
     809             :   //
     810           0 :   normwidth = fDy/sigmay;
     811           0 :   normd     = dy/sigmay;
     812           0 :   p0 = 0.5*(1+AliMathBase::ErfFast(normd-normwidth*0.5));
     813           0 :   p1 = 0.5*(1+AliMathBase::ErfFast(normd+normwidth*0.5));  
     814           0 :   py+= 0.75*(p1-p0);
     815             :   //
     816           0 :   normwidth = fDy/(3.*sigmay);
     817           0 :   normd     = dy/(3.*sigmay);
     818           0 :   p0 = 0.5*(1+AliMathBase::ErfFast(normd-normwidth*0.5));
     819           0 :   p1 = 0.5*(1+AliMathBase::ErfFast(normd+normwidth*0.5));  
     820           0 :   py+= 0.25*(p1-p0);
     821             :   // 
     822             :   // pz calculation   - 75% admixture of original sigma - 25% tails 
     823             :   //
     824           0 :   normwidth = fDz/sigmaz;
     825           0 :   normd     = dz/sigmaz;
     826           0 :   p0 = 0.5*(1+AliMathBase::ErfFast(normd-normwidth*0.5));
     827           0 :   p1 = 0.5*(1+AliMathBase::ErfFast(normd+normwidth*0.5));  
     828           0 :   pz+= 0.75*(p1-p0);
     829             :   //
     830           0 :   normwidth = fDz/(3.*sigmaz);
     831           0 :   normd     = dz/(3.*sigmaz);
     832           0 :   p0 = 0.5*(1+AliMathBase::ErfFast(normd-normwidth*0.5));
     833           0 :   p1 = 0.5*(1+AliMathBase::ErfFast(normd+normwidth*0.5));  
     834           0 :   pz+= 0.25*(p1-p0);
     835           0 : }
     836             : //_________________________________________________________________________
     837             : 
     838             : void AliTOFtrackerMI::FillClusterArray(TObjArray* arr) const
     839             : {
     840             :   //
     841             :   // Returns the TOF cluster array
     842             :   //
     843             : 
     844           0 :   if (fN==0)
     845           0 :     arr = 0x0;
     846             :   else
     847           0 :     for (Int_t i=0; i<fN; ++i) arr->Add(fClusters[i]);
     848             : 
     849           0 : }

Generated by: LCOV version 1.11