// ************************************************************************** // 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. * // * //*************************************************************************** #include #ifdef KFPARTICLEFINDER #include "AliHLTTPCTopoReconstructor.h" #endif #include #include #include #include #include using namespace std; #ifndef NVALGRIND #include #endif #ifndef DO_TPCCATRACKER_EFF_PERFORMANCE #define HLTCA_STANDALONE #endif //DO_TPCCATRACKER_EFF_PERFORMANCE #ifndef HLTCA_STANDALONE #include #include "TFile.h" #endif #ifdef DRAW #define MAIN_DRAW #endif //DRAW static bool SAVE = false; extern bool SINGLE_THREADED; static bool file_exists( const char *filename ) { FILE *f = 0; if ( ( f = std::fopen( filename, "r" ) ) != NULL ) { std::fclose( f ); return true; } return false; } static void usage(const char *execName) { std::cout << "Usage: " << execName << " [OPTION] [event number]\n" "Reconstruct slice tracks and merge them from cluster data read from the Events directory.\n\n" " -h, --help print this message\n" #ifdef MAIN_DRAW " -links let it draw every vector of links the NeighboursFinder found.\n" #else " -single force tracker to run on only one core. Per default all available cores will be used\n" #endif " -save dump result of the tracker/merger into a file for later analysis\n" #ifndef HLTCA_STANDALONE " -perf do a performance analysis against Monte-Carlo information right after reconstruction\n\n" #endif "You may specify a specific event to reconstruct if there is more than one available in the Events directory" << std::endl; } int main(int argc, char **argv) { bool fullTiming = false; #ifndef HLTCA_STANDALONE bool doPerf = false; TFile* perfHistoFile = new TFile("HLTTPCCATrackerPerformance.root","RECREATE"); AliHLTTPCCAPerformance *perf = &AliHLTTPCCAPerformance::Instance(); #endif int firstEvent = 0; int lastEvent = 1000000; int repetitions = 1; string filePrefix = "./Events/"; for( int i=1; i < argc; i++ ){ if ( !std::strcmp( argv[i], "-h" ) || !std::strcmp( argv[i], "--help" ) || !std::strcmp( argv[i], "-help" ) ) { usage(argv[0]); return 0; } else if ( !std::strcmp( argv[i], "-save" ) ) { SAVE = true; #ifndef HLTCA_STANDALONE } else if ( !std::strcmp( argv[i], "-perf" ) ) { doPerf = true; #endif } else if ( !std::strcmp( argv[i], "-time" ) ) { fullTiming = true; } else if ( !std::strcmp( argv[i], "-repeat" ) && ++i < argc ) { repetitions = atoi( argv[i] ); } else if ( !std::strcmp( argv[i], "-dir" ) && ++i < argc ) { filePrefix = argv[i]; } else if ( !std::strcmp( argv[i], "-ev" ) && ++i < argc ) { firstEvent = atoi( argv[i] ); if (++i < argc){ lastEvent = atoi( argv[i] ); std::cout << "Only process events " << firstEvent << ",..," << lastEvent << std::endl; } else{ lastEvent = firstEvent; std::cout << "Only process event " << lastEvent << std::endl; } } else { firstEvent = atoi( argv[i] ); lastEvent = firstEvent; std::cout << "Only process event " << lastEvent << std::endl; } } #ifndef HLTCA_STANDALONE #ifdef MAIN_DRAW SINGLE_THREADED = true; #endif #endif AliHLTTPCCAGBTracker *tracker = 0; const AliHLTTPCCAGBTracker *trackerConst = 0; tracker = new AliHLTTPCCAGBTracker; filePrefix += "/"; if ( !tracker->ReadSettingsFromFile(filePrefix) ) { cout << "ERROR: Settings file can't be opened!" << endl; } trackerConst = tracker; for ( int kEvents = firstEvent; kEvents <= lastEvent; kEvents++ ) { char buf[6]; sprintf( buf, "%d", kEvents ); const string fileName = filePrefix + "event" + string(buf) + "_"; std::cout << "Loading Event " << kEvents << "..." << std::endl; const int err = tracker->ReadHitsFromFile(fileName); if (err == 0) { cout << "Hits Data for Event " << kEvents << " can't be read." << std::endl; break; } else if (err == -1) { cout << "Hits Data for Event " << kEvents << " will be skipped." << std::endl; continue; } std::cout << "Event " << kEvents << " CPU reconstruction..." << std::endl; #ifdef KFPARTICLEFINDER AliHLTTPCTopoReconstructor topoReconstructor; // TODO don't recreate with each event #endif #ifndef HLTCA_STANDALONE if ( perf ) { perf->SetOutputFile(perfHistoFile); perf->SetTracker(tracker); #ifdef KFPARTICLEFINDER perf->SetTopoReconstructor(&topoReconstructor); #endif std::cout << "Loading Monte-Carlo Data for Event " << kEvents << "..." << std::endl; if (!perf->ReadDataFromFiles(fileName)) { cout << "Monte-Carlo Data for Event " << kEvents << " can't be read." << std::endl; break; } //perf->ShiftHitsToMC(); //perf->ResimulateHits(); } #ifdef STAR_HFT //perf->ResimulateHits(); // dbg // perf->ShiftHitsToMC(0.001); // dbg // for ( int ih = 0; ih < NHits(); ih++ ) { // dbg // fHits[ih].SetErr2X( 0.0001 ); // fHits[ih].SetErr2Y( 0.0001 ); // } #elif ALICE_ITS //perf->ResimulateHits( 0.1 ); // dbg // perf->ShiftHitsToMC(0.005, 0.025); // dbg #elif defined(DRIFT_TUBES) perf->CombineHits(); perf->DivideHitsOnLR(); #endif #endif // HLTCA_STANDALONE tracker->FindTracks(); // tracker->SaveTracksInFile(fileName); #ifndef HLTCA_STANDALONE if ( doPerf ) { if (trackerConst->NHits() > 0) { perf->InitSubPerformances(); perf->ExecPerformance(); } else { cout << "Event " << kEvents << " contains 0 hits." << std::endl; } } #endif #ifdef KFPARTICLEFINDER topoReconstructor.Init( tracker ); topoReconstructor.ReconstructPrimVertex(); topoReconstructor.ReconstructParticles(); #ifndef HLTCA_STANDALONE if ( perf ) { if (trackerConst->NHits() > 0) { perf->GetSubPerformance("Topo Performance")->Exec(0); } } #endif #endif //KFPARTICLEFINDER const bool ifAvarageTime = 1; if (!ifAvarageTime){ std::cout << "Reconstruction Time" << " Real = " << std::setw( 10 ) << (trackerConst->SliceTrackerTime() + trackerConst->StatTime( 9 )) * 1.e3 << " ms," << " CPU = " << std::setw( 10 ) << (trackerConst->SliceTrackerCpuTime() + trackerConst->StatTime( 10 )) * 1.e3 << " ms," << " parallelization speedup (only SectorTracker): " << trackerConst->SliceTrackerCpuTime() / trackerConst->SliceTrackerTime() << std::endl; if ( fullTiming ) { std::cout << " | ------ Sector trackers (w\\o init): " << std::setw( 10 ) << trackerConst->StatTime( 0 ) * 1000. << " ms\n" << " | Initialization: " << std::setw( 10 ) << trackerConst->StatTime( 12 ) * 1000. << " ms\n" << " | NeighboursFinder: " << std::setw( 10 ) << trackerConst->StatTime( 1 ) * 1000. << " ms, " << std::setw( 12 ) << trackerConst->StatTime( 5 ) << " cycles\n" << " | NeighboursCleaner: " << std::setw( 10 ) << trackerConst->StatTime( 11 ) * 1000. << " ms\n" << " | StartHitsFinder: " << std::setw( 10 ) << trackerConst->StatTime( 4 ) * 1000. << " ms\n" << " | TrackletConstructor: " << std::setw( 10 ) << trackerConst->StatTime( 2 ) * 1000. << " ms, " << std::setw( 12 ) << trackerConst->StatTime( 7 ) << " cycles\n" << " | TrackletSelector: " << std::setw( 10 ) << trackerConst->StatTime( 3 ) * 1000. << " ms, " << std::setw( 12 ) << trackerConst->StatTime( 8 ) << " cycles\n" << " | WriteOutput: " << std::setw( 10 ) << trackerConst->StatTime( 6 ) * 1000. << " ms\n" << " | ------------------------- Merge: " << std::setw( 10 ) << trackerConst->StatTime( 9 ) * 1000. << " ms\n" << " | Initialization: " << std::setw( 10 ) << trackerConst->StatTime( 13 ) * 1000. << " ms\n" << " | -- NoOverlapTrackMerge: " << std::setw( 10 ) << trackerConst->StatTime( 14 ) * 1000. << " ms\n" << " | Merge: " << std::setw( 10 ) << trackerConst->StatTime( 16 ) * 1000. << " ms\n" << " | DataStore: " << std::setw( 10 ) << trackerConst->StatTime( 18 ) * 1000. << " ms\n" << " | ---- OverlapTrackMerge: " << std::setw( 10 ) << trackerConst->StatTime( 15 ) * 1000. << " ms\n" << " | Merge: " << std::setw( 10 ) << trackerConst->StatTime( 17 ) * 1000. << " ms\n" << " | DataStore: " << std::setw( 10 ) << trackerConst->StatTime( 19 ) * 1000. << " ms\n" ; } } else{ const int NTimers = trackerConst->NTimers(); static int statIEvent = 0; static double *statTime = new double[NTimers]; static double statTime_SliceTrackerTime = 0; static double statTime_SliceTrackerCpuTime = 0; if (!statIEvent){ for (int i = 0; i < NTimers; i++){ statTime[i] = 0; } } statIEvent++; for (int i = 0; i < NTimers; i++){ statTime[i] += trackerConst->StatTime( i ); } statTime_SliceTrackerTime += trackerConst->SliceTrackerTime(); statTime_SliceTrackerCpuTime += trackerConst->SliceTrackerCpuTime(); std::cout << "Reconstruction Time" << " Real = " << std::setw( 10 ) << 1./statIEvent*(statTime_SliceTrackerTime+statTime[ 9 ]) * 1.e3 << " ms," << " CPU = " << std::setw( 10 ) << 1./statIEvent*(statTime_SliceTrackerCpuTime+statTime[ 10 ]) * 1.e3 << " ms," << " parallelization speedup: " << statTime_SliceTrackerCpuTime / statTime_SliceTrackerTime << std::endl; if ( fullTiming ) { std::cout << " | ------ Sector trackers (w\\o init): " << std::setw( 10 ) << 1./statIEvent*statTime[ 0 ] * 1000. << " ms\n" << " | Initialization: " << std::setw( 10 ) << 1./statIEvent*statTime[ 12 ] * 1000. << " ms\n" << " | NeighboursFinder: " << std::setw( 10 ) << 1./statIEvent*statTime[ 1 ] * 1000. << " ms, " << std::setw( 12 ) << 1./statIEvent*statTime[ 5 ] << " cycles\n" << " | NeighboursCleaner: " << std::setw( 10 ) << 1./statIEvent*statTime[ 11 ] * 1000. << " ms\n" << " | StartHitsFinder: " << std::setw( 10 ) << 1./statIEvent*statTime[ 4 ] * 1000. << " ms\n" << " | TrackletConstructor: " << std::setw( 10 ) << 1./statIEvent*statTime[ 2 ] * 1000. << " ms, " << std::setw( 12 ) << 1./statIEvent*statTime[ 7 ] << " cycles\n" << " | TrackletSelector: " << std::setw( 10 ) << 1./statIEvent*statTime[ 3 ] * 1000. << " ms, " << std::setw( 12 ) << 1./statIEvent*statTime[ 8 ] << " cycles\n" << " | WriteOutput: " << std::setw( 10 ) << 1./statIEvent*statTime[ 6 ] * 1000. << " ms\n" << " | -------------------------- Merge: " << std::setw( 10 ) << 1./statIEvent*statTime[ 9 ] * 1000. << " ms\n" << " | Initialization: " << std::setw( 10 ) << 1./statIEvent*statTime[ 13 ] * 1000. << " ms\n" << " | -- NoOverlapTrackMerge: " << std::setw( 10 ) << 1./statIEvent*statTime[ 14 ] * 1000. << " ms\n" << " | Merge: " << std::setw( 10 ) << 1./statIEvent*statTime[ 16 ] * 1000. << " ms\n" << " | DataStore: " << std::setw( 10 ) << 1./statIEvent*statTime[ 18 ] * 1000. << " ms\n" << " | ---- OverlapTrackMerge: " << std::setw( 10 ) << 1./statIEvent*statTime[ 15 ] * 1000. << " ms\n" << " | Merge: " << std::setw( 10 ) << 1./statIEvent*statTime[ 17 ] * 1000. << " ms\n" << " | DataStore: " << std::setw( 10 ) << 1./statIEvent*statTime[ 19 ] * 1000. << " ms\n" ; } } } // kEvent #ifndef HLTCA_STANDALONE if ( doPerf) { perf->WriteHistos(); } perfHistoFile->Close(); #endif delete tracker; return 0; }