// $Id: AliHLTTPCCASlicePerformance.cxx,v 1.11 2010/08/18 20:46:09 ikulakov Exp $ // ************************************************************************** // This file is property of and copyright by the ALICE HLT Project * // ALICE Experiment at CERN, All rights reserved. * // * // Primary Authors: Sergey Gorbunov * // Ivan Kisel * // for The ALICE HLT Project. * // * // Developed by: Igor Kulakov * // Maksym Zyzak * // * // Permission to use, copy, modify and distribute this software and its * // documentation strictly for non-commercial purposes is hereby granted * // without fee, provided that the above copyright notice appears in all * // copies and that both the copyright notice and this permission notice * // appear in the supporting documentation. The authors make no claims * // about the suitability of this software for any purpose. It is * // provided "as is" without express or implied warranty. * // * //*************************************************************************** #ifdef DO_TPCCATRACKER_EFF_PERFORMANCE #include "AliHLTTPCCounters.h" #include "AliHLTTPCCATrackPerformanceBase.h" #include "AliHLTTPCCASlicePerformance.h" #include "AliHLTTPCCAGBHit.h" #include "AliHLTTPCCAMCTrack.h" #ifndef HLTCA_STANDALONE #include "AliHLTTPCCAMCPoint.h" #endif #include "AliHLTTPCCAOutTrack.h" #include "AliHLTTPCCAGBTrack.h" #include "AliHLTTPCCAGBTracker.h" #include "AliHLTTPCCATracker.h" #include "AliHLTTPCCASliceOutput.h" #include "AliHLTTPCCADisplay.h" #include "AliHLTTPCCAClusterData.h" #include "TMath.h" #include "TROOT.h" #include "Riostream.h" #include "TFile.h" #include "TH1.h" #include "TH2.h" #include "TProfile.h" #include "TStyle.h" #define IsOutTrack1 // define to use reffited with materials track parameters void AliHLTTPCCASlicePerformance::SetNewEvent(const AliHLTTPCCAGBTracker * const Tracker, AliHLTResizableArray *hitLabels, AliHLTResizableArray *mcTracks, AliHLTResizableArray *localMCPoints) { AliHLTTPCCATrackPerformanceBase::SetNewEvent(Tracker, hitLabels, mcTracks, localMCPoints); sliceTracker = &fTracker->Slice( fISlice ); firstSliceHit = 0; endSliceHit = 0; for ( ; firstSliceHit < fTracker->NHits(); firstSliceHit++ ) { if ( fTracker->Hit( firstSliceHit ).ISlice() == fISlice ) break; } endSliceHit = firstSliceHit; for ( ; endSliceHit < fTracker->NHits(); endSliceHit++ ) { if ( fTracker->Hit( endSliceHit ).ISlice() != fISlice ) break; }; #ifdef IsOutTrack1 nRecoTracks = sliceTracker->NOutTracks1(); #else nRecoTracks = sliceTracker->NOutTracks(); #endif } // void AliHLTTPCCASlicePerformance::SetNewEvent void AliHLTTPCCASlicePerformance::CheckMCTracks() { for ( int imc = 0; imc < nMCTracks; imc++ ) (*fMCTracks)[imc].SetNHits( 0 ); std::vector iLastRow; // last row with hit for iMCTrack std::vector nLastRows; // last row with hit for iMCTrack for ( int imc = 0; imc < nMCTracks; imc++ ){ iLastRow.push_back(-1); nLastRows.push_back(0); }; for ( int ih = firstSliceHit; ih < endSliceHit; ih++ ) { int id = fTracker->Hit( ih ).ID(); int iRow = fTracker->Hit( ih ).IRow(); if ( (id < 0) || (id >= (*fHitLabels).Size()) ) break; const AliHLTTPCCAHitLabel &l = (*fHitLabels)[id]; for (int j = 0; j < 3; j++){ int iMCTrack = l.fLab[j]; if ( iMCTrack >= nMCTracks ){ cout << "ERROR: Memory corruption or Incorrect MC Data! " << endl; cout << "HitLabels[" << id << "].fLab[" << j << "] = " << iMCTrack << endl; exit (1); } if ( iMCTrack >= 0 ){ if ( iLastRow[iMCTrack] != iRow ){ if ((iLastRow[iMCTrack] == iRow - 1) && (nLastRows[iMCTrack] != -10)){ nLastRows[iMCTrack] += 1; if (nLastRows[iMCTrack] >= SPParameters::MinimumConsHitsForMCTrack) nLastRows[iMCTrack] = -10; } (*fMCTracks)[iMCTrack].SetNHits( (*fMCTracks)[iMCTrack].NHits() + 1 ); iLastRow[iMCTrack] = iRow; } } } // for j } // for ih mcData.resize(nMCTracks); for ( int imc = 0; imc < nMCTracks; imc++ ) { AliHLTTPCCAMCTrack &mc = (*fMCTracks)[imc]; AliHLTTPCCAPerformanceMCTrackData &mcTrackData = mcData[imc]; mc.SetSet( 0 ); mc.SetNReconstructed( 0 ); mc.SetNTurns( 1 ); if ((nLastRows[imc] == -10) && (mc.NHits() >= SPParameters::MinimumHitsForMCTrack)){ mcTrackData.SetAsReconstructable(); } // recoable if ( mc.P() >= AliHLTTPCCAParameters::ExtraThreshold ) { if ( mc.P() >= AliHLTTPCCAParameters::RefThreshold ) { mc.SetSet( 2 ); mcTrackData.SetSet( 2 ); } // ref else{ mc.SetSet( 1 ); mcTrackData.SetSet( 1 ); } // extra } // recoable } // for iMC } // void AliHLTTPCCASlicePerformance::CheckMCTracks() void AliHLTTPCCASlicePerformance::MatchTracks() { const AliHLTTPCCASliceOutput *SliceData = sliceTracker->Output(); for(int i=0; iNOutTracks1(); i++) { int sliceTracker_tr_id = sliceTracker->OutTrack1(i).OrigTrackID(); sliceTracker->fOutTracks1[i].SetFirstHitRef(-1); sliceTracker->fOutTracks1[i].SetNHits(-1); sliceTracker->fOutTracks1[i].SetFirstHitRef(SliceData->Track(sliceTracker_tr_id).FirstClusterRef()); sliceTracker->fOutTracks1[i].SetNHits(SliceData->Track(sliceTracker_tr_id).NClusters()); } recoData.resize(nRecoTracks); for ( int itr = 0; itr < nRecoTracks; itr++ ) { #ifdef IsOutTrack1 if( SliceData->Track(itr).NClusters() == -1) continue; #endif int traLabels = -1; double traPurity = 0; #ifdef IsOutTrack1 const AliHLTTPCCAOutTrack &tCA = sliceTracker->OutTrack1( itr ); #else const AliHLTTPCCASliceTrack &tCA = SliceData->Track( itr ); #endif int nhits = tCA.NHits(); int *lb = new int[nhits*3]; int nla = 0; //cout<<"\nHit labels:"<NTrackClusters() ); int iClu = SliceData->ClusterIDrc( outTrackHitIndex ).Cluster(); int iRow = SliceData->ClusterIDrc( outTrackHitIndex ).Row(); const int index = firstSliceHit + sliceTracker->ClusterData().RowOffset( iRow ) + iClu; const AliHLTTPCCAHitLabel &l = (*fHitLabels)[fTracker->Hit( index ).ID()]; //cout<= 0 ) lb[nla++] = l.fLab[0]; if ( l.fLab[1] >= 0 ) lb[nla++] = l.fLab[1]; if ( l.fLab[2] >= 0 ) lb[nla++] = l.fLab[2]; } // find one with maximum entries. sort( lb, lb + nla ); int labmax = -1, labcur = -1, lmax = 0, lcurr = 0; for ( int i = 0; i < nla; i++ ) { if ( lb[i] != labcur ) { if ( labcur >= 0 && lmax < lcurr ) { lmax = lcurr; labmax = labcur; } labcur = lb[i]; lcurr = 0; } lcurr++; } if ( labcur >= 0 && lmax < lcurr ) { lmax = lcurr; labmax = labcur; } // count n hits with max label lmax = 0; for ( int ihit = 0; ihit < nhits; ihit++ ) { const int outTrackHitIndex = tCA.FirstHitRef() + ihit; int iClu = SliceData->ClusterIDrc( outTrackHitIndex ).Cluster(); int iRow = SliceData->ClusterIDrc( outTrackHitIndex ).Row(); const int index = firstSliceHit + sliceTracker->ClusterData().RowOffset( iRow ) + iClu; const AliHLTTPCCAHitLabel &l = (*fHitLabels)[fTracker->Hit( index ).ID()]; if ( l.fLab[0] == labmax || l.fLab[1] == labmax || l.fLab[2] == labmax ) lmax++; // cout << index << " "; } traLabels = labmax; traPurity = ( ( nhits > 0 ) ? double( lmax ) / double( nhits ) : 0 ); // cout<<"perf track "< 0){ // // std::cout << mc.PDG() << " "; // switch (abs(mc.PDG())){ // case 11: // nElectrons++; // break; // case 13: // nMuons++; // break; // case 211: // nPions++; // break; // case 2212: // nProtons++; // break; // } // } // } // if (collectPDG && fISlice == 23){ // std::cout << " nElectrons " << nElectrons << std::endl; // std::cout << " nMuons " << nMuons << std::endl; // std::cout << " nPions " << nPions << std::endl; // std::cout << " nProtons " << nProtons << std::endl; // } } // SlicePerformance void AliHLTTPCCASlicePerformance::FillHistos() { const AliHLTTPCCASliceOutput *SliceData = sliceTracker->Output(); AliHLTTPCCATrackPerformanceBase::FillHistos(); for(int iRTr=0; iRTr < nRecoTracks; iRTr++){ // TODO: make common AliHLTTPCCAPerformanceRecoTrackData &recoD = recoData[iRTr]; #ifdef IsOutTrack1 const AliHLTTPCCAOutTrack &recoTr = sliceTracker->OutTrack1( iRTr ); // TODO: make common #else const AliHLTTPCCAOutTrack &recoTr = sliceTracker->OutTrack( iRTr ); #endif AliHLTTPCCAMCTrack &mcTr = (*fMCTracks)[ recoD.GetMCTrackId() ]; AliHLTTPCCATrackParam param = recoTr.EndPoint(); const int nHits = recoTr.NHits(); const double p = 1. / param.QPt() * sqrt(1. + param.DzDs()*param.DzDs()); const double pMC = mcTr.P(); const double chi2 = param.Chi2() / nHits; if ( recoD.IsGhost(SPParameters::MinTrackPurity) ) { GetHisto("ghostsLength")->Fill( nHits ); GetHisto("ghostsRMom")->Fill( p ); GetHisto("ghostsMCMom")->Fill( pMC ); GetHisto("ghostsLengthAndRMom")->Fill( nHits , p ); // TODO add same for other perfs GetHisto("ghostsLengthAndMCMom")->Fill( nHits , pMC ); GetHisto("ghostsLengthAndChi2")->Fill( nHits , chi2 ); GetHisto("ghostsChi2")->Fill( chi2 ); } else { GetHisto("recosLength")->Fill( nHits ); GetHisto("recosRMom")->Fill( p ); GetHisto("recosMCMom")->Fill( pMC ); GetHisto("recosLengthAndRMom")->Fill( nHits , p ); GetHisto("recosLengthAndMCMom")->Fill( nHits , pMC ); GetHisto("recosLengthAndChi2")->Fill( nHits , chi2 ); GetHisto("recosChi2")->Fill( chi2 ); } } ///mvz start 27.01.2010 const int nMCTr = nMCTracks; map NHitsRecoTrack; for(int iMCTr=0; iMCTrfOutTracks1[itr].NHits() == -1) continue; #endif if ( recoData[itr].IsGhost() ) continue; const int iMC = recoData[itr].GetMCTrackId(); AliHLTTPCCAMCTrack &mc = (*fMCTracks)[iMC]; /// mvz begin // while ( mc.Set() == 2 && TMath::Abs( mc.TPCPar()[0] ) + TMath::Abs( mc.TPCPar()[1] ) > 1 ) { while ( 1 ) { if ( recoData[itr].GetPurity() < .90 ) break; #ifdef IsOutTrack1 const AliHLTTPCCAOutTrack &t = sliceTracker->OutTrack1( itr ); #else const AliHLTTPCCAOutTrack &t = sliceTracker->OutTrack( itr ); #endif AliHLTTPCCATrackParam p = t.StartPoint(); ///mvz start 27.01.2010 if( mc.NReconstructed() == 1 ) NHitsRecoTrack[iMC] = t.NHits(); if( mc.NReconstructed() > 1 && NHitsRecoTrack[iMC] > t.NHits()) NHitsRecoTrack[iMC] = t.NHits(); ///mvz end 27.01.2010 //cout <<"Start "<< p.X() << " "<ClusterIDrc( outTrackHitIndex ).Cluster(); int iRow = SliceData->ClusterIDrc( outTrackHitIndex ).Row(); const int iTrHit = firstSliceHit + sliceTracker->ClusterData().RowOffset( iRow ) + iClu; AliHLTTPCCAGBHit hit = fTracker->Hits()[iTrHit]; int MCindex=-1; for(int iMCPoint=0; iMCPointSlice( 0 ).Param().cBz(); #ifdef DRAW2 AliHLTTPCCATracker &sliceM = const_cast(*sliceTracker); AliHLTTPCCADisplay::Instance().ClearView(); AliHLTTPCCADisplay::Instance().SetSliceView(); AliHLTTPCCADisplay::Instance().SetCurrentSlice( &sliceM); AliHLTTPCCADisplay::Instance().DrawSlice( &sliceM, 1 ); AliHLTTPCCADisplay::Instance().DrawTrackParam( t.StartPoint() ); for(int i=0; iFill( p.GetY() - mcY ); GetHisto("resZ")->Fill( p.GetZ() - mcZ ); GetHisto("resSinPhi")->Fill( p.GetSinPhi() - mcSinPhi ); GetHisto("resDzDs")->Fill( p.GetDzDs() - mcDzDs ); if(CAMath::Abs(qPt) > 1.e-8){ GetHisto("resPt")->Fill( (pt - mcPt)/mcPt ); } // cout << qPt << " "<< mcQPt << endl; if ( p.GetErr2Y() > 0 ) GetHisto("pullY")->Fill( ( p.GetY() - mcY ) / TMath::Sqrt( p.GetErr2Y() ) ); if ( p.GetErr2Z() > 0 ) GetHisto("pullZ")->Fill( ( p.GetZ() - mcZ ) / TMath::Sqrt( p.GetErr2Z() ) ); if ( p.GetErr2SinPhi() > 0 ) GetHisto("pullSinPhi")->Fill( ( p.GetSinPhi() - mcSinPhi ) / TMath::Sqrt( p.GetErr2SinPhi() ) ); if ( p.GetErr2DzDs() > 0 ) GetHisto("pullDzDs")->Fill( ( p.DzDs() - mcDzDs ) / TMath::Sqrt( p.GetErr2DzDs() ) ); if(CAMath::Abs(qPt) > 1.e-7 && p.GetErr2QPt()>0 ) GetHisto("pullQPt")->Fill( (qPt - mcQPt)/TMath::Sqrt(p.GetErr2QPt()) ); break; } /// mvz end } { // TODO int nHits = fTracker->NHits(); for ( int ih = 0; ih < nHits; ih++ ) { const AliHLTTPCCAGBHit &hit = fTracker->Hit( ih ); const AliHLTTPCCAHitLabel &l = (*fHitLabels)[hit.ID()]; // fhHitErrY->Fill( hit.ErrY() ); // fhHitErrZ->Fill( hit.ErrZ() ); const int iMC = l.fLab[0]; AliHLTTPCCAMCTrack &mc = (*fMCTracks)[iMC]; int MCindex = -1; int nFirstMC = mc.FirstMCPointID(); int nMCPoints = mc.NMCPoints(); AliHLTTPCCALocalMCPoint *points = &((*fLocalMCPoints).Data()[nFirstMC]); for(int iMCPoint=0; iMCPointFill( hit.Y() - points[MCindex].Y() ); GetHisto("resZHit")->Fill( hit.Z() - points[MCindex].Z() ); } } } // void AliHLTTPCCASlicePerformance::FillHistos() #endif //DO_TPCCATRACKER_EFF_PERFORMANCE