// $Id: AliHLTTPCCAPerformance.cxx,v 1.13 2010/09/01 10:38:27 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 "AliHLTTPCCAPerformance.h" #include "AliHLTTPCCounters.h" #include "AliHLTTPCPerformanceBase.h" #include "AliHLTTPCCAGlobalPerformance.h" #include "AliHLTTPCTopoPerformance.h" #include "AliHLTTPCCAParam.h" #include "AliHLTTPCCAGBHit.h" #include "AliHLTTPCCAMCTrack.h" #ifndef HLTCA_STANDALONE #include "AliHLTTPCCAMCPoint.h" #endif #include "AliHLTTPCCAGBTrack.h" #include "AliHLTTPCCAGBTracker.h" #include "AliHLTTPCCADisplay.h" #include "AliHLTTPCCAParameters.h" #include "TRandom3.h" //dbg #include "TMath.h" #include "TROOT.h" #include "Riostream.h" #include "TFile.h" #include "TH1.h" #include "TH2.h" #include "TProfile.h" #include "TStyle.h" AliHLTTPCCAPerformance::AliHLTTPCCAPerformance() { static bool first_call = true; if (first_call){ typedef TSubPerformance TSP; /// Just define here all sub-performances /// TSP(new __ClassName__ , __Name__ ), #if !defined(KFPARTICLE) const int NSPerfo = 1; #else #ifndef STAR_STANDALONE const int NSPerfo = 2; #else // HLTCA_STANDALONE const int NSPerfo = 2; #endif // HLTCA_STANDALONE #endif const TSP perfos[NSPerfo] = { TSP(new AliHLTTPCCAGlobalPerformance, "Global Performance") #ifdef KFPARTICLE ,TSP(new AliHLTTPCTopoPerformance, "Topo Performance") #endif }; subPerformances.resize(NSPerfo); for (int iP = 0; iP < NSPerfo; iP++){ subPerformances[iP] = perfos[iP]; } } first_call = false; //* constructor } AliHLTTPCCAPerformance::~AliHLTTPCCAPerformance() { //* destructor fHitLabels.Resize( 0 ); fMCTracks.Resize( 0 ); for (unsigned int iPerf = 0; iPerf < subPerformances.size(); iPerf++){ // TODO: why we can't do this in subPerformances.~destructor() ?? if (subPerformances[iPerf].perf) delete subPerformances[iPerf].perf; } } AliHLTTPCCAPerformance &AliHLTTPCCAPerformance::Instance() { // reference to static object static AliHLTTPCCAPerformance gAliHLTTPCCAPerformance; return gAliHLTTPCCAPerformance; } bool AliHLTTPCCAPerformance::SetNewEvent(AliHLTTPCCAGBTracker* const tracker, string mcTracksFile, string mcPointsFile) { fTracker = tracker; // Read MC info from file FILE *file = std::fopen( mcTracksFile.data(), "rb" ); if ( !file ) { return false; } ReadMCEvent( file ); fclose( file ); file = std::fopen( mcPointsFile.data(), "rb" ); if ( !file ) { return false; } ReadLocalMCPoints( file ); fclose( file ); return true; } // void AliHLTTPCCAPerformance::SetNewEvent void AliHLTTPCCAPerformance::InitSubPerformances() { // Init subperformances static bool first_call = true; for (unsigned int iPerf = 0; iPerf < subPerformances.size(); iPerf++){ subPerformances[iPerf]->SetNewEvent(fTracker, &fHitLabels, &fMCTracks, &fLocalMCPoints); } #ifdef KFPARTICLE if ( GetSubPerformance("Topo Performance") ) dynamic_cast(GetSubPerformance("Topo Performance"))->SetNewEvent2(fTopoReconstructor); #endif if (first_call) CreateHistos(); first_call = false; } // void AliHLTTPCCAPerformance::InitSubPerformances void AliHLTTPCCAPerformance::CreateHistos() { for (unsigned int iPerf = 0; iPerf < subPerformances.size(); iPerf++){ if(!(subPerformances[iPerf]->IsHistoCreated())) subPerformances[iPerf]->CreateHistos(subPerformances[iPerf].name, fOutputFile); } } bool AliHLTTPCCAPerformance::CreateHistos(string name) { unsigned i = 0; for( ; i < (subPerformances.size()) && (subPerformances[i].name != name); i++); if(!(subPerformances[i]->IsHistoCreated()) && i != subPerformances.size()) subPerformances[i]->CreateHistos(subPerformances[i].name, fOutputFile); if ( i == subPerformances.size() ) return 0; return 1; } void AliHLTTPCCAPerformance::WriteDir2Current( TObject *obj ) { //* recursive function to write down all created in the file histos if ( !obj->IsFolder() ) obj->Write(); else { TDirectory *cur = gDirectory; ((TDirectory*)obj)->cd(); TList *listSub = ( ( TDirectory* )obj )->GetList(); TIter it( listSub ); while ( TObject *obj1 = it() ) WriteDir2Current( obj1 ); cur->cd(); } } void AliHLTTPCCAPerformance::WriteHistos() { if(fOutputFile) WriteDir2Current(fOutputFile); } void AliHLTTPCCAPerformance::ExecPerformance() { fStatNEvents++; #ifdef KFPARTICLE for (unsigned int iPerf = 0; iPerf < subPerformances.size()-1; iPerf++){ #else for (unsigned int iPerf = 0; iPerf < subPerformances.size(); iPerf++){ #endif if(subPerformances[iPerf].IsGlobalPerf) subPerformances[iPerf]->Exec(0); } #if 1 // current event efficiencies for (unsigned int iPerf = 0; iPerf < subPerformances.size(); iPerf++){ cout << endl << " ---- " << subPerformances[iPerf].name << " event " << fStatNEvents << " ---- "<< endl; subPerformances[iPerf]->PrintEfficiency(); } cout << endl << " ============================== " << endl; #endif //0 for (unsigned int iPerf = 0; iPerf < subPerformances.size(); iPerf++){ cout << endl << " ---- " << subPerformances[iPerf].name << " " << fStatNEvents << " events Statistic ---- " << endl; if(subPerformances[iPerf].IsGlobalPerf) subPerformances[iPerf]->PrintEfficiencyStatistic(); }; } AliHLTTPCPerformanceBase* AliHLTTPCCAPerformance::GetSubPerformance(string name) { unsigned i = 0; for( ; (i < subPerformances.size()) && (subPerformances[i].name != name); i++); //ASSERT ( i != subPerformances.size() , " Incorrect name of subPerformance used."); if ( i == subPerformances.size() ) return 0; return subPerformances[i].perf; } // AliHLTTPCPerformanceBase* AliHLTTPCCAPerformance::GetSubPerformance(string name) /// -------------------- Read\write MC information --------------------- void AliHLTTPCCAPerformance::WriteMCEvent( FILE *file ) const { // write MC information to the file int n = fMCTracks.Size(); std::fwrite( &n, sizeof( int ), 1, file ); n = fHitLabels.Size(); std::fwrite( &n, sizeof( int ), 1, file ); std::fwrite( fMCTracks.Data(), sizeof( AliHLTTPCCAMCTrack ), fMCTracks.Size(), file ); std::fwrite( fHitLabels.Data(), sizeof( AliHLTTPCCAHitLabel ), fHitLabels.Size(), file ); } void AliHLTTPCCAPerformance::ReadMCEvent( FILE *file ) { // read mc info from the file int read; int n; read = std::fread( &n, sizeof( int ), 1, file ); assert( read == 1 ); fMCTracks.Resize( n ); read = std::fread( &n, sizeof( int ), 1, file ); assert( read == 1 ); fHitLabels.Resize( n ); read = std::fread( fMCTracks.Data(), sizeof( AliHLTTPCCAMCTrack ), fMCTracks.Size(), file ); assert( read == fMCTracks.Size() ); read = std::fread( fHitLabels.Data(), sizeof( AliHLTTPCCAHitLabel ), fHitLabels.Size(), file ); assert( read == fHitLabels.Size() ); UNUSED_PARAM1(read); // for (int i = 0; i < fMCTracks.Size(); i++){ // AliHLTTPCCAMCTrack& mc = fMCTracks[i]; // std::cout << mc.PDG() << " "; // std::cout << std::endl; // for (int iPar = 0; iPar < 7; iPar++) // std::cout << mc.Par(iPar) << " "; // std::cout << std::endl; // for (int iPar = 0; iPar < 7; iPar++) // std::cout << mc.TPCPar(iPar) << " "; // std::cout << std::endl; // // std::cout << mc.P() << " "; // }; // for (int i = 0; i < fHitLabels.Size(); i++){ // AliHLTTPCCAHitLabel& l = fHitLabels[i]; // for (int iPar = 0; iPar < 3; iPar++) // std::cout << l.fLab[iPar] << " "; // std::cout << std::endl; // }; } void AliHLTTPCCAPerformance::ReadLocalMCPoints( FILE *file ) { int read; int n; read = std::fread( &n, sizeof( int ), 1, file ); assert( read == 1 ); fLocalMCPoints.Resize( n ); read = std::fread( fLocalMCPoints.Data(), sizeof( AliHLTTPCCALocalMCPoint ), fLocalMCPoints.Size(), file ); assert( read == fLocalMCPoints.Size() ); UNUSED_PARAM1(read); } // void AliHLTTPCCAPerformance::ReadLocalMCPoints( FILE *file ) void AliHLTTPCCAPerformance::SetMCTracks(vector& mcTracks) { const int N = mcTracks.size(); fMCTracks.Resize(N); for(int i = 0; i < N; i++){ fMCTracks[i] = mcTracks[i]; } } void AliHLTTPCCAPerformance::SetMCPoints(vector& mcPoints) { const int N = mcPoints.size(); fLocalMCPoints.Resize(N); for(int i = 0; i < N; i++){ fLocalMCPoints[i] = mcPoints[i]; } } void AliHLTTPCCAPerformance::SetHitLabels(vector& hitLabels) { const int N = hitLabels.size(); fHitLabels.Resize(N); for(int i = 0; i < N; i++){ fHitLabels[i] = hitLabels[i]; } } void AliHLTTPCCAPerformance::SaveDataInFiles(string prefix) const { { ofstream ofile((prefix+"hitLabels.data").data(),ios::out|ios::app); const int Size = fHitLabels.Size(); ofile << Size << std::endl; for (int i = 0; i < fHitLabels.Size(); i++){ const AliHLTTPCCAHitLabel &l = fHitLabels[i]; ofile << l; } ofile.close(); } { ofstream ofile((prefix+"MCTracks.data").data(),ios::out|ios::app); const int Size = fMCTracks.Size(); ofile << Size << std::endl; for (int i = 0; i < fMCTracks.Size(); i++){ const AliHLTTPCCAMCTrack &l = fMCTracks[i]; ofile << l; } ofile.close(); } { ofstream ofile((prefix+"MCPoints.data").data(),ios::out|ios::app); const int Size = fLocalMCPoints.Size(); ofile << Size << std::endl; for (int i = 0; i < fLocalMCPoints.Size(); i++){ const AliHLTTPCCALocalMCPoint &l = fLocalMCPoints[i]; ofile << l; } ofile.close(); } } bool AliHLTTPCCAPerformance::ReadDataFromFiles(string prefix) { { ifstream ifile((prefix+"hitLabels.data").data()); if ( !ifile.is_open() ) return 0; int Size; ifile >> Size; fHitLabels.Resize(Size); for (int i = 0; i < Size; i++){ AliHLTTPCCAHitLabel &l = fHitLabels[i]; ifile >> l; } ifile.close(); } { ifstream ifile((prefix+"MCTracks.data").data()); if ( !ifile.is_open() ) return 0; int Size; ifile >> Size; fMCTracks.Resize(Size); for (int i = 0; i < Size; i++){ AliHLTTPCCAMCTrack &l = fMCTracks[i]; ifile >> l; } ifile.close(); } { ifstream ifile((prefix+"MCPoints.data").data()); if ( !ifile.is_open() ) return 0; int Size; ifile >> Size; fLocalMCPoints.Resize(Size); for (int i = 0; i < Size; i++){ AliHLTTPCCALocalMCPoint &l = fLocalMCPoints[i]; ifile >> l; } ifile.close(); } // calculate needed additional info { const int NMCTracks = fMCTracks.Size(); // NMCRows for (int i = 0; i < NMCTracks; ++i ){ AliHLTTPCCAMCTrack& t = fMCTracks[i]; vector rows; rows.resize( AliHLTTPCCAParameters::MaxNStations, 0 ); for (int j = 0, iP = t.FirstMCPointID(); j < t.NMCPoints(); iP++, j++){ rows[fLocalMCPoints[iP].IRow()]++; } int nRows = 0; int nMCContRows = 0; int istaold = -2, ncont=0; for (unsigned int j = 0 ; j < rows.size(); j++) { if( rows[j] > 0 ) { nRows++; if( istaold == static_cast(j)-1 ) { ncont++; } else { nMCContRows = (nMCContRows > ncont) ? nMCContRows : ncont; ncont = 1; } istaold = j; } } nMCContRows = (nMCContRows > ncont) ? nMCContRows : ncont; t.SetNMCRows( nRows ); t.SetNMCContRows( nMCContRows ); } // NHitRows vector zero(AliHLTTPCCAParameters::MaxNStations, 0); vector< vector > nmchits(NMCTracks,zero); AliHLTResizableArray& hits = const_cast(fTracker)->fHits; for (int i = 0; i < hits.Size(); i++) { int id = hits[i].ID(); for ( int il = 0; il < 3; il++ ) { int trackId = HitLabel(id).fLab[il]; if(trackId < 0) continue; ASSERT(trackId < NMCTracks, "Incorrect MCPoints of MCTracks file. " << trackId << " < " << NMCTracks ); assert( hits[i].IRow() < AliHLTTPCCAParameters::MaxNStations ); nmchits[trackId][hits[i].IRow()]++; } } for (int i = 0; i < NMCTracks; ++i ){ AliHLTTPCCAMCTrack& t = fMCTracks[i]; int nRows = 0; int nHitContRows = 0; int istaold = -1, ncont=0; for (int j = 0; j < AliHLTTPCCAParameters::MaxNStations; ++j ) { if ( nmchits[i][j] ) { nRows++; if( istaold == j-1 ) { ncont++; } else { nHitContRows = (nHitContRows > ncont) ? nHitContRows : ncont; ncont = 1; } istaold = j; } } nHitContRows = (nHitContRows > ncont) ? nHitContRows : ncont; t.SetNHitRows( nRows ); t.SetNHitContRows( nHitContRows ); } // Angle, HitErrors for ( int ih = 0; ih < hits.Size(); ih++ ) { AliHLTTPCCAGBHit &hit = hits[ih]; const AliHLTTPCCAHitLabel &l = (fHitLabels)[hit.ID()]; const int iMC = l.fLab[0]; if( iMC<0 ) continue; AliHLTTPCCAMCTrack &mc = (fMCTracks)[iMC]; int MCindex = -1; int nFirstMC = mc.FirstMCPointID(); int nMCPoints = mc.NMCPoints(); AliHLTTPCCALocalMCPoint *points = &((fLocalMCPoints).Data()[nFirstMC]); for(int iMCPoint=0; iMCPoint 0) continue; fPV[0] = t.X(); fPV[1] = t.Y(); fPV[2] = t.Z(); break; } #ifdef STAR_HFT // Secondary tracks. Tmp for (int i = 0; i < NMCTracks; ++i ){ AliHLTTPCCAMCTrack& t = fMCTracks[i]; if (t.MotherId() > 0) continue; t.SetMotherId( 1 ); if ( ( abs(fPV[0] - t.X()) <= 1e-7 ) && ( abs(fPV[1] - t.Y()) <= 1e-7 ) && ( abs(fPV[2] - t.Z()) <= 1e-7 ) ) t.SetMotherId( -1 ); } #endif } return 1; } int AliHLTTPCCAPerformance::GetMCPoint( const AliHLTTPCCAGBHit& hit ) const { float xHLoc, yHLoc, zHLoc; AliHLTTPCCAParameters::GlobalToCALocal( hit.X(), hit.Y(), hit.Z(), hit.Angle(), xHLoc, yHLoc, zHLoc ); const AliHLTTPCCAHitLabel &l = fHitLabels[hit.ID()]; int iMCP = -1; for( int k = 0; k < 3 && iMCP == -1; k++ ) { const int iMC = l.fLab[k]; if (iMC < 0) continue; const AliHLTTPCCAMCTrack &mc = fMCTracks[iMC]; int nFirstMC = mc.FirstMCPointID(); int nMCPoints = mc.NMCPoints(); // float r2Min = 1e10; const AliHLTTPCCALocalMCPoint *points = &(fLocalMCPoints.Data()[nFirstMC]); for(int iMCPoint=0; iMCPoint 0.5) continue; #else if( fabs(xPLoc - xHLoc) > 2.f || fabs(p.Angle() - hit.Angle()) > 1e-6 ) continue; #endif const float dy = yHLoc - yPLoc; const float dz = zHLoc - zPLoc; // float iC[2][2]; // double determinant = hit.Err2X1()*hit.Err2X2() - hit.ErrX12()*hit.ErrX12(); // can be incorrect errors // double invdet = 1/determinant; // iC[0][0] = hit.Err2X2()*invdet; // iC[1][0] = -hit.ErrX12()*invdet; // iC[1][1] = hit.Err2X1()*invdet; // const float r2 = ( dy*dy*iC[0][0] + // 2*dz*dy*iC[1][0] + dz*dz*iC[1][1] ); // if (r2 < r2Min) { // r2Min = r2; // iMCP = iMCPoint + nFirstMC; // } if( fabs(dy) < 1000*sqrt(hit.Err2X1()) && fabs(dz) < 10*sqrt(hit.Err2X2()) ) // suppose we have only one MCPoint per track per station iMCP = iMCPoint + nFirstMC; } } return iMCP; } #include "AliHLTTPCCADisplay.h" // Use smeared MCposition instead of hits void AliHLTTPCCAPerformance::ShiftHitsToMC( float errorX1, float errorX2 ){ AliHLTResizableArray& hits = const_cast(fTracker)->fHits; std::sort( hits.Data(), hits.Data() + const_cast(fTracker)->NHits(), AliHLTTPCCAGBHit::Compare ); // has an influence on the procedure. CHECKME why? static TRandom3 rand; { int nHits = fTracker->NHits(); for ( int ih = 0; ih < nHits; ih++ ) { AliHLTTPCCAGBHit &hit = hits[ih]; const int iMCP = GetMCPoint(hit); if (iMCP == -1) continue; const AliHLTTPCCALocalMCPoint& point = fLocalMCPoints.Data()[iMCP]; // #ifdef DRAW // AliHLTTPCCADisplay::Instance().SetTPCView(); // AliHLTTPCCADisplay::Instance().DrawTPC(); // for(int iMCPoint=0; iMCPoint& hits = const_cast(fTracker)->fHits; const int NHits = fLocalMCPoints.Size(); const_cast(fTracker)->fNHits = NHits; // hits.Clear(); hits.Resize(NHits); fHitLabels.Resize(NHits); AliHLTResizableArray &fStrips = const_cast(fTracker)->fFStrips; // create a virtual strip for each hit (currently strips position is not used for ITS, so don't have to fill them) AliHLTResizableArray &bStrips = const_cast(fTracker)->fBStrips; // create a virtual strip for each hit fStrips.Resize(NHits); bStrips.Resize(NHits); static TRandom3 rand; for ( int ih = 0; ih < NHits; ih++ ) { AliHLTTPCCALocalMCPoint &mcP = fLocalMCPoints[ih]; AliHLTTPCCAGBHit &hit = hits[ih]; hit.SetID(ih); AliHLTTPCCAHitLabel &l = fHitLabels[ih]; l.fLab[0] = mcP.TrackI(); l.fLab[1] = -1; l.fLab[2] = -1; // get errors if ( errorX2 <= 0 ) errorX2 = errorX1; const float err2X1 = errorX1*errorX1; const float err2X2 = errorX2*errorX2; #ifdef STAR_HFT if ( errorX1 <= 0 ) hit.SetErr2Y(mcP.Err2Y()); else hit.SetErr2Y(err2X1); if ( errorX2 <= 0 ) hit.SetErr2Z(mcP.Err2Z()); else hit.SetErr2Z(err2X2); #else hit.SetErr2Y(err2X1); hit.SetErr2Z(err2X2); #endif sfloat_v Err2Y = hit.Err2Y(), Err2Z = hit.Err2Z(); double mcX = mcP.X(); double mcY = mcP.Y(); double mcZ = mcP.Z(); hit.SetIRow( mcP.IRow() ); hit.SetAngle( mcP.Angle() ); double mcXTmp = mcX*cos( hit.Angle() ) + mcY*sin( hit.Angle() ); double mcYTmp = -mcX*sin( hit.Angle() ) + mcY*cos( hit.Angle() ); mcYTmp -= sqrt(Err2Y[0])*rand.Gaus(); mcZ -= sqrt(Err2Z[0])*rand.Gaus(); mcX = mcXTmp*cos( hit.Angle() ) - mcYTmp*sin( hit.Angle() ); mcY = mcXTmp*sin( hit.Angle() ) + mcYTmp*cos( hit.Angle() ); hit.SetX( mcX ); hit.SetY( mcY ); hit.SetZ( mcZ ); hit.SetFStripP( &fStrips[ih] ); hit.SetBStripP( &bStrips[ih] ); } } // Match hits with closest MCPoint void AliHLTTPCCAPerformance::RematchHits(){ AliHLTResizableArray& hits = const_cast(fTracker)->fHits; const int NHits = fTracker->NHits(); for ( int ih = 0; ih < NHits; ih++ ) { AliHLTTPCCAGBHit &hit = hits[ih]; AliHLTTPCCAHitLabel &l = fHitLabels[ih]; int MCindex = -1; float R2 = 10e30; for(int iMCPoint=0; iMCPoint < fLocalMCPoints.Size(); iMCPoint++) { if(fLocalMCPoints[iMCPoint].IRow() != hit.IRow()) continue; const float dY = hit.Y() - fLocalMCPoints[iMCPoint].Y(); const float dZ = hit.Z() - fLocalMCPoints[iMCPoint].Z(); const float r2 = dY*dY + dZ*dZ; if( r2 < R2 ) { MCindex = iMCPoint; R2 = r2; } } if(MCindex == -1) { l.fLab[0] = -1; l.fLab[1] = -1; l.fLab[2] = -1; continue; } l.fLab[0] = fLocalMCPoints[MCindex].TrackI(); l.fLab[1] = -1; l.fLab[2] = -1; } } #ifdef DRIFT_TUBES struct Vector3 { Vector3( const float& x, const float& y, const float& z):fx(x),fy(y),fz(z){}; float X() const { return fx; } float Y() const { return fy; } float Z() const { return fz; } private: float fx,fy,fz; }; bool operator<(const Vector3& a, const Vector3& b) { if (a.X() != b.X()) return a.X() < b.X(); else if (a.Y() != b.Y()) return a.Y() < b.Y(); else return a.Z() < b.Z(); } // Rid of hits with same wires positions void AliHLTTPCCAPerformance::CombineHits(){ AliHLTResizableArray& hits = const_cast(fTracker)->fHits; const int NHits = hits.Size(); map minR[AliHLTTPCCAParameters::MaxNStations]; map isPileuped[AliHLTTPCCAParameters::MaxNStations]; for (int i = 0; i < NHits; i++){ AliHLTTPCCAGBHit &l = hits[i]; const int iS = l.IRow(); Vector3 v(l.X(), l.Y(), l.Z()); if ( minR[iS].count(v) > 0 ) { minR[iS][v] = min(l.R(), minR[iS][v]); isPileuped[iS][v] = true; assert(iS >= AliHLTTPCCAParameters::NMVDStations); // MVD } else { minR[iS][v] = l.R(); isPileuped[iS][v] = false; } } AliHLTResizableArray hits2; int nHits2 = 0; for( int iS = 0; iS < AliHLTTPCCAParameters::MaxNStations; iS++ ) { nHits2 += minR[iS].size(); } hits2.Resize(nHits2); for (int i = 0, j = 0; i < NHits; i++){ AliHLTTPCCAGBHit &l = hits[i]; Vector3 v(l.X(), l.Y(), l.Z()); const int iS = l.IRow(); if ( minR[iS][v] == l.R() ) { l.SetIsPileuped(isPileuped[iS][v]); hits2[j] = l; j++; } } #ifndef HLTCA_STANDALONE // merge labels for (int j = 0; j < nHits2; j++){ AliHLTTPCCAGBHit &l2 = hits2[j]; const int id2 = l2.ID(); Vector3 v2(l2.X(), l2.Y(), l2.Z()); for (int i = 0; i < NHits; i++){ AliHLTTPCCAGBHit &l = hits[i]; const int id = l.ID(); if ( id2 == id ) continue; Vector3 v(l.X(), l.Y(), l.Z()); if ( l.X() != l2.X() || l.Y() != l2.Y() || l.Z() != l2.Z() ) continue; int k = 0; bool flag = false; for( ; k < 3 && fHitLabels[id2].fLab[k] != -1; k++ ) if ( fHitLabels[id2].fLab[k] == fHitLabels[id].fLab[0] ) flag = true; if (flag) continue; if (k >= 3) continue; fHitLabels[id2].fLab[k] = fHitLabels[id].fLab[0]; // suppose we have only 1 label from the begining } } #endif const_cast(fTracker)->SetNHits(nHits2); for (int i = 0; i < nHits2; i++){ hits[i] = hits2[i]; } // do not need to correct labels, since they are matched with hits by hit::fID } // Rid of hits with same wires positions void AliHLTTPCCAPerformance::DivideHitsOnLR(){ AliHLTResizableArray& hits = const_cast(fTracker)->fHits; const int NHits = hits.Size(); int nMvdHits = 0; for (int i = 0; i < NHits; i++){ AliHLTTPCCAGBHit &hIn = hits[i]; if(hIn.IRow() < AliHLTTPCCAParameters::NMVDStations) nMvdHits++; } AliHLTResizableArray hits2; const int NHits2 = nMvdHits + 2*(NHits-nMvdHits); hits2.Resize(NHits2); for(int i=0; i(fTracker)->SetNHits(NHits2); for (int i = 0; i < NHits2; i++){ hits[i] = hits2[i]; } // create additional hitLables AliHLTResizableArray labs2; const int NLabs = fHitLabels.Size(); labs2.Resize(nMvdHits + 2*(NLabs-nMvdHits)); for (int i = 0; i < nMvdHits; i++){ labs2[i] = fHitLabels[i]; } for (int i = nMvdHits; i < NLabs; i++){ labs2[2*i-nMvdHits] = fHitLabels[i]; labs2[2*i-nMvdHits+1] = fHitLabels[i]; } fHitLabels.Resize(nMvdHits + 2*(NLabs-nMvdHits)); for (int i = 0; i < nMvdHits + 2*(NLabs-nMvdHits); i++){ fHitLabels[i] = labs2[i]; } // clean labels (half of created hits are "fake") const int NMCPoints = GetMCPoints()->Size(); vector > hitsOnPoint(NMCPoints); for(int iH = nMvdHits; iH < hits.Size(); iH++) { const AliHLTTPCCAGBHit &h = hits[iH]; int id = GetMCPoint(h); if(id < 0) { // delete match with MCTracks for( int k = 0; k < 3; k++ ) { fHitLabels[h.ID()].fLab[k] = -1; } continue; } hitsOnPoint[id].push_back(iH); } // clean double hits. Comment this out to calculate efficiency without tacking into account left-right ambiguity #ifdef INCLUDE_LR_EFF for(int iT=0; iT &hop = hitsOnPoint[iT]; if (hop.size() == 0) continue; float r2Min = 1e10; int iBestH = -1; for( unsigned int iH = 0; iH < hop.size(); iH++ ) { const AliHLTTPCCAGBHit &h = hits[hop[iH]]; const int iMCP = GetMCPoint(h); if (iMCP < 0) continue; const AliHLTTPCCALocalMCPoint &p = fLocalMCPoints[iMCP]; const float dx = h.X() - p.X(); const float dy = h.Y() - p.Y(); const float dz = h.Z() - p.Z(); float iC[3][3]; double determinant = +h.C(0,0)*(h.C(1,1)*h.C(2,2)-h.C(2,1)*h.C(1,2)) -h.C(0,1)*(h.C(1,0)*h.C(2,2)-h.C(1,2)*h.C(2,0)) +h.C(0,2)*(h.C(1,0)*h.C(2,1)-h.C(1,1)*h.C(2,0)); double invdet = 1/determinant; iC[0][0] = (h.C(1,1)*h.C(2,2)-h.C(2,1)*h.C(1,2))*invdet; iC[1][0] = -(h.C(0,1)*h.C(2,2)-h.C(0,2)*h.C(2,1))*invdet; iC[2][0] = (h.C(0,1)*h.C(1,2)-h.C(0,2)*h.C(1,1))*invdet; iC[0][1] = -(h.C(1,0)*h.C(2,2)-h.C(1,2)*h.C(2,0))*invdet; iC[1][1] = (h.C(0,0)*h.C(2,2)-h.C(0,2)*h.C(2,0))*invdet; iC[2][1] = -(h.C(0,0)*h.C(1,2)-h.C(1,0)*h.C(0,2))*invdet; iC[0][2] = (h.C(1,0)*h.C(2,1)-h.C(2,0)*h.C(1,1))*invdet; iC[1][2] = -(h.C(0,0)*h.C(2,1)-h.C(2,0)*h.C(0,1))*invdet; iC[2][2] = (h.C(0,0)*h.C(1,1)-h.C(1,0)*h.C(0,1))*invdet; const float r2 = ( dx*dx*iC[0][0] + 2*dy*dx*iC[1][0] + dy*dy*iC[1][1] + 2*dz*dx*iC[2][0] + 2*dz*dy*iC[2][1] + dz*dz*iC[2][2] ); if (r2 < r2Min) { r2Min = r2; iBestH = iH; } } #ifndef HLTCA_STANDALONE for( unsigned int iH = 0; iH < hop.size(); iH++ ) { if (static_cast(iH) == iBestH) continue; const AliHLTTPCCAGBHit &h = hits[hop[iH]]; if (h.R()*h.R() < 9.f*h.Err2R()) continue; // can't really distinguish left and right side of this tubes const int id = GetMCPoint(h); if(id < 0) continue; const int iMCT = fLocalMCPoints[id].TrackI(); // delete match with MCTrack for( int k = 0; k < 3; k++ ) { if ( fHitLabels[h.ID()].fLab[k] == iMCT ) { fHitLabels[h.ID()].fLab[k] = -1; } } } #endif } #endif // 1 } #endif // PANDA_STT #endif //DO_TPCCATRACKER_EFF_PERFORMANCE