diff --git a/macro/L1/configs/ca_params_mcbm.yaml b/macro/L1/configs/ca_params_mcbm.yaml index d1a1f9dc4f181591cb899cc990960060f464f665..4593b811243a679c336ec07e5d24d3678a2a1579 100644 --- a/macro/L1/configs/ca_params_mcbm.yaml +++ b/macro/L1/configs/ca_params_mcbm.yaml @@ -26,7 +26,7 @@ ca: # 3) Turn the full TOF off # inactive_stations: [TOF] #inactive_stations: ['MUCH'] - inactive_stations: [] + inactive_stations: ['MUCH'] # Random seed random_seed: 1 diff --git a/reco/L1/CMakeLists.txt b/reco/L1/CMakeLists.txt index b35b111739491a676d2922f65e8fa11935ccb764..1564b7318a78a618cf330a75c7c03a624d3c0c94 100644 --- a/reco/L1/CMakeLists.txt +++ b/reco/L1/CMakeLists.txt @@ -170,10 +170,6 @@ set(PUBLIC_DEPENDENCIES ROOT::Physics ) -if(OpenMP_CXX_FOUND) - list(APPEND PUBLIC_DEPENDENCIES OpenMP::OpenMP_CXX) -endif() - set(PRIVATE_DEPENDENCIES CbmMuchBase CbmMvdBase diff --git a/reco/L1/CbmL1.cxx b/reco/L1/CbmL1.cxx index 8e31e77d08c8f2e74a37c0de5a31e58b33da6c96..56dac242b2851b495cc46631e819c4c59af55a89 100644 --- a/reco/L1/CbmL1.cxx +++ b/reco/L1/CbmL1.cxx @@ -176,14 +176,6 @@ InitStatus CbmL1::Init() cout << endl << endl; } - if (fVerbose > 1) { -#ifdef _OPENMP - LOG(info) << "L1 is running with OpenMP" << endl; -#else - LOG(info) << "L1 is running without OpenMP" << endl; -#endif - } - fHistoDir = gROOT->mkdir("L1"); fHistoDir->mkdir("Input"); fHistoDir->mkdir("Fit"); @@ -715,9 +707,6 @@ void CbmL1::Reconstruct(CbmEvent* event) } if (fVerbose > 1) { cout << "\nCbmL1::Exec event " << fEventNo << " ...\n\n"; } -#ifdef _OPENMP - omp_set_num_threads(1); -#endif // ----- Read data from branches and send data from IODataManager to L1Algo ---------------------------------------- diff --git a/reco/L1/L1Algo/L1Algo.cxx b/reco/L1/L1Algo/L1Algo.cxx index b0a6dcff61929fb3632af8dc27c6cf3cf8e8df8f..7e4e734b467e038586a3be934170cba4bf47dd9f 100644 --- a/reco/L1/L1Algo/L1Algo.cxx +++ b/reco/L1/L1Algo/L1Algo.cxx @@ -10,52 +10,16 @@ #include "L1Grid.h" #include "L1HitPoint.h" -L1Algo::L1Algo(unsigned int nThreads) +L1Algo::L1Algo() { - SetNThreads(nThreads); for (unsigned int i = 0; i < L1Constants::size::kMaxNstations; i++) { - vGridTime[i].AllocateMemory(fNThreads); + vGridTime[i].AllocateMemory(); + fTriplets[i].SetName(std::stringstream() << "L1Algo::fTriplets[" << i << "]"); } } -void L1Algo::SetNThreads(unsigned int n) -{ - if (n > static_cast<unsigned int>(L1Constants::size::kMaxNthreads)) { - LOG(fatal) << "L1Algo: n threads " << n << " is greater than the maximum " - << static_cast<unsigned int>(L1Constants::size::kMaxNthreads); - } - fNThreads = n; - - for (int i = 0; i < fNThreads; i++) { - - fSliceRecoTracks_thread[i].SetName(std::stringstream() << "L1Algo::fSliceRecoTracks_thread[" << i << "]"); - - fSliceRecoHits_thread[i].SetName(std::stringstream() << "L1Algo::fSliceRecoHits_thread[" << i << "]"); - - fTrackCandidates[i].SetName(std::stringstream() << "L1Algo::fTrackCandidates[" << i << "]"); - - for (unsigned int j = 0; j < L1Constants::size::kMaxNstations; j++) { - fTriplets[j][i].SetName(std::stringstream() << "L1Algo::fTriplets[" << i << "][" << j << "]"); - } - } -} - - -void L1Algo::Init(const TrackingMode mode) -{ - for (int iProc = 0; iProc < 4; iProc++) { - for (int i = 0; i < 8; i++) { - threadNumberToCpuMap[2 * i + 0 + iProc * 20] = 4 * i + iProc; - threadNumberToCpuMap[2 * i + 1 + iProc * 20] = 4 * i + 32 + iProc; - } - for (int i = 0; i < 2; i++) { - threadNumberToCpuMap[2 * i + 0 + 16 + iProc * 20] = 4 * i + iProc + 64; - threadNumberToCpuMap[2 * i + 1 + 16 + iProc * 20] = 4 * i + 8 + iProc + 64; - } - } - fTrackingMode = mode; -} +void L1Algo::Init(const TrackingMode mode) { fTrackingMode = mode; } void L1Algo::Finish() { ca::tools::Debugger::Instance().Write(); } @@ -90,31 +54,18 @@ void L1Algo::ResetSliceData() fStripToTrack.reset(fInputData.GetNhitKeys(), -1); -#ifdef _OPENMP - fStripToTrackLock.reset(fInputData.GetNhitKeys()); - for (unsigned int j = 0; j < fStripToTrackLock.size(); j++) { - omp_init_lock(&fStripToTrackLock[j]); - } -#endif - fSliceRecoTracks.clear(); fSliceRecoTracks.reserve(2 * nHits / fParameters.GetNstationsActive()); fSliceRecoHits.clear(); fSliceRecoHits.reserve(2 * nHits); - for (int iT = 0; iT < fNThreads; iT++) { - fSliceRecoTracks_thread[iT].clear(); - fSliceRecoTracks_thread[iT].reserve(nHits / 10); - fSliceRecoHits_thread[iT].clear(); - fSliceRecoHits_thread[iT].reserve(nHits); - fTrackCandidates[iT].clear(); - fTrackCandidates[iT].reserve(nHits / 10); - for (unsigned int iS = 0; iS < L1Constants::size::kMaxNstations; iS++) { - int nHitsStation = fSliceHitIds[iS].size(); - fTriplets[iS][iT].clear(); - fTriplets[iS][iT].reserve(2 * nHitsStation); - } + fTrackCandidates.clear(); + fTrackCandidates.reserve(nHits / 10); + for (unsigned int iS = 0; iS < L1Constants::size::kMaxNstations; iS++) { + int nHitsStation = fSliceHitIds[iS].size(); + fTriplets[iS].clear(); + fTriplets[iS].reserve(2 * nHitsStation); } } diff --git a/reco/L1/L1Algo/L1Algo.h b/reco/L1/L1Algo/L1Algo.h index a641957c1f0cc998d439c66d6d53b88329f3439d..875c9d617fd1d3254eea14e6e617f6c27adc065d 100644 --- a/reco/L1/L1Algo/L1Algo.h +++ b/reco/L1/L1Algo/L1Algo.h @@ -46,10 +46,6 @@ class L1AlgoDraw; class CbmL1MCTrack; -#ifdef _OPENMP -#include "omp.h" -#endif - // ******************************* // ** Types definition (global) ** // ******************************* @@ -99,8 +95,7 @@ public: // ** Constructors and destructor /// Constructor - /// \param nThreads Number of threads for multi-threaded mode - L1Algo(unsigned int nThreads = 1); + L1Algo(); /// Copy constructor L1Algo(const L1Algo&) = delete; @@ -118,38 +113,22 @@ public: ~L1Algo() = default; - // ** Functions, which pack and unpack indexes of station, thread and triplet ** + // ** Functions, which pack and unpack indexes of station and triplet ** // TODO: move to L1Triplet class (S.Zharko) - /// Packs station, thread and triplet indices to an unique triplet ID + /// Packs station and triplet indices to an unique triplet ID /// \param iStation Index of station in the active stations array - /// \param iThread Index of thread processing triplet /// \param iTriplet Index of triplet - static unsigned int PackTripletId(unsigned int iStation, unsigned int iThread, unsigned int iTriplet); + static unsigned int PackTripletId(unsigned int iStation, unsigned int iTriplet); /// Unpacks the triplet ID to its station index /// \param id Unique triplet ID static unsigned int TripletId2Station(unsigned int id); - /// Unpacks the triplet ID to its thread index - /// \param id Unique triplet ID - static unsigned int TripletId2Thread(unsigned int id); - /// Unpacks the triplet ID to its triplet index /// \param id Unique triplet ID static unsigned int TripletId2Triplet(unsigned int id); - /// pack thread and track indices to an unique track ID - static int PackTrackId(int Thread, int Track) - { - return PackTripletId(0, (unsigned int) Thread, (unsigned int) Track); - } - - /// unpack the track ID to its thread index - static int TrackId2Thread(int ID) { return TripletId2Thread((unsigned int) ID); } - - /// unpack the track ID to its track index - static int TrackId2Track(int ID) { return TripletId2Triplet((unsigned int) ID); } /// Sets L1Algo parameters object /// \param other - reference to the L1Parameters object @@ -233,32 +212,6 @@ public: /// \return chi2 fscal BranchExtender(L1Branch& t); - [[gnu::always_inline]] void PackLocation(unsigned int& location, unsigned int& triplet, unsigned int iStation, - unsigned int& thread) - { - location = (triplet << 11) | (thread << 3) | iStation; - } - - [[gnu::always_inline]] void UnPackStation(unsigned int& location, unsigned int& iStation) - { - iStation = location & 0x7; - } - - [[gnu::always_inline]] void UnPackThread(unsigned int& location, unsigned int& thread) - { - thread = (location >> 3) & 0xFF; - } - - [[gnu::always_inline]] void UnPackTriplet(unsigned int& location, unsigned int& triplet) - { - triplet = (location >> 11); - } - - [[gnu::always_inline]] void SetFStation(unsigned char& flag, unsigned int iStation) - { - flag = iStation * 4 + (flag % 4); - } - #ifdef DRAW L1AlgoDraw* draw {nullptr}; void DrawRecoTracksTime(const L1Vector<CbmL1Track>& tracks); @@ -291,8 +244,6 @@ public: float GetMaxInvMom() const { return fMaxInvMom[0]; } - void SetNThreads(unsigned int n); - public: /// Gets number of stations before the pipe (MVD stations in CBM) int GetNstationsBeforePipe() const { return fNstationsBeforePipe; } @@ -346,13 +297,12 @@ public: L1Vector<L1Track> fSliceRecoTracks {"L1Algo::fSliceRecoTracks"}; ///< reconstructed tracks in sub-timeslice L1Vector<L1HitIndex_t> fSliceRecoHits {"L1Algo::fSliceRecoHits"}; ///< packed hits of reconstructed tracks - /// Created triplets vs station and thread index - L1Vector<L1Triplet> fTriplets[L1Constants::size::kMaxNstations][L1Constants::size::kMaxNthreads] { - {"L1Algo::fTriplets"}}; + /// Created triplets vs station index + L1Vector<L1Triplet> fTriplets[L1Constants::size::kMaxNstations] {{"L1Algo::fTriplets"}}; /// Track candidates created out of adjacent triplets before the final track selection. /// The candidates may share any amount of hits. - L1Vector<L1Branch> fTrackCandidates[L1Constants::size::kMaxNthreads] {"L1Algo::fTrackCandidates"}; + L1Vector<L1Branch> fTrackCandidates {"L1Algo::fTrackCandidates"}; ///< indices of the sub-slice hits L1Vector<L1HitIndex_t> fSliceHitIds[L1Constants::size::kMaxNstations] {"L1Algo::fSliceHitIds"}; @@ -369,22 +319,12 @@ public: L1HitIndex_t fGridHitStartIndex[L1Constants::size::kMaxNstations + 1] {0}; L1HitIndex_t fGridHitStopIndex[L1Constants::size::kMaxNstations + 1] {0}; - L1Vector<L1Track> fSliceRecoTracks_thread[L1Constants::size::kMaxNthreads] {"L1Algo::fSliceRecoTracks_thread"}; - L1Vector<L1HitIndex_t> fSliceRecoHits_thread[L1Constants::size::kMaxNthreads] {"L1Algo::fSliceRecoHits_thread"}; - + L1Vector<int> fStripToTrack {"L1Algo::fStripToTrack"}; // strip to track pointers -#ifdef _OPENMP - L1Vector<omp_lock_t> fStripToTrackLock {"L1Algo::fStripToTrackLock"}; -#endif - - L1Vector<int> fStripToTrack {"L1Algo::fStripToTrack"}; // front strip to track pointers - // L1Vector<int> fStripToTrack1B {"L1Algo::fStripToTrackB"}; // back strip to track pointers - - int fNThreads {0}; TrackingMode fTrackingMode {kSts}; - fvec EventTime[L1Constants::size::kMaxNthreads][L1Constants::size::kMaxNthreads] {{0}}; - fvec Err[L1Constants::size::kMaxNthreads][L1Constants::size::kMaxNthreads] {{0}}; + fvec EventTime {0.f}; + fvec Err {0.f}; /// --- data used during finding iterations int isec {0}; // iteration TODO: to be dispatched (S.Zharko, 21.06.2022) @@ -409,8 +349,6 @@ private: int fNFindIterations = -1; // TODO investigate kAllPrimJumpIter & kAllSecJumpIter - std::map<int, int> threadNumberToCpuMap {}; - float fTrackChi2Cut {10.f}; float fTripletFinalChi2Cut {10.f}; float fTripletChi2Cut {5.f}; // cut for selecting triplets before collecting tracks.per one DoF @@ -438,9 +376,6 @@ private: L1FieldValue fTargB _fvecalignment {}; // field in the target point (modifiable, do not touch!!) L1XYMeasurementInfo TargetXYInfo _fvecalignment {}; // target constraint [cm] - - // int TripNumThread; - int fGhostSuppression {1}; // NOTE: Should be equal to 0 in TRACKS_FROM_TRIPLETS mode! /// ----- Debug features ----- @@ -463,36 +398,24 @@ private: // --------------------------------------------------------------------------------------------------------------------- // -[[gnu::always_inline]] inline unsigned int L1Algo::PackTripletId(unsigned int iStation, unsigned int iThread, - unsigned int iTriplet) +[[gnu::always_inline]] inline unsigned int L1Algo::PackTripletId(unsigned int iStation, unsigned int iTriplet) { #ifndef FAST_CODE assert(iStation < L1Constants::size::kMaxNstations); - assert(iThread < L1Constants::size::kMaxNthreads); assert(iTriplet < L1Constants::size::kMaxNtriplets); #endif - constexpr unsigned int kMoveThread = L1Constants::size::kTripletBits; - constexpr unsigned int kMoveStation = L1Constants::size::kTripletBits + L1Constants::size::kThreadBits; - return (iStation << kMoveStation) + (iThread << kMoveThread) + iTriplet; + constexpr unsigned int kMoveStation = L1Constants::size::kTripletBits; + return (iStation << kMoveStation) + iTriplet; } // --------------------------------------------------------------------------------------------------------------------- // [[gnu::always_inline]] inline unsigned int L1Algo::TripletId2Station(unsigned int id) { - constexpr unsigned int kMoveStation = L1Constants::size::kTripletBits + L1Constants::size::kThreadBits; + constexpr unsigned int kMoveStation = L1Constants::size::kTripletBits; return id >> kMoveStation; } -// --------------------------------------------------------------------------------------------------------------------- -// -[[gnu::always_inline]] inline unsigned int L1Algo::TripletId2Thread(unsigned int id) -{ - constexpr unsigned int kMoveThread = L1Constants::size::kTripletBits; - constexpr unsigned int kThreadMask = (1u << L1Constants::size::kThreadBits) - 1u; - return (id >> kMoveThread) & kThreadMask; -} - // --------------------------------------------------------------------------------------------------------------------- // [[gnu::always_inline]] inline unsigned int L1Algo::TripletId2Triplet(unsigned int id) diff --git a/reco/L1/L1Algo/L1CaTrackFinderSlice.cxx b/reco/L1/L1Algo/L1CaTrackFinderSlice.cxx index d2e9a0d04f4f406243e6a72e90fe76e8f7300299..ddbb447b2910005edb9c4c145bdb365594b33cbd 100644 --- a/reco/L1/L1Algo/L1CaTrackFinderSlice.cxx +++ b/reco/L1/L1Algo/L1CaTrackFinderSlice.cxx @@ -32,16 +32,6 @@ #include "L1Track.h" #include "L1TrackPar.h" #include "L1TripletConstructor.h" - -#ifdef _OPENMP -#include "omp.h" -#include "pthread.h" -#endif // _OPENMP - -#include "TRandom.h" -#include "TStopwatch.h" - -#include "L1Timer.h" #ifdef DRAW #include "utils/L1AlgoDraw.h" #endif // DRAW @@ -123,7 +113,6 @@ bool L1Algo::checkTripletMatch(const L1Triplet& l, const L1Triplet& r, fscal& dc } - // ************************************************************************************************** // * * // * ------ CATrackFinder procedure ------ * @@ -134,11 +123,6 @@ void L1Algo::CaTrackFinderSlice() { fNFindIterations = fParameters.GetNcaIterations(); - -#ifdef _OPENMP - omp_set_num_threads(fNThreads); -#endif - /*******************************/ /** * Performance monitors setting **********************************/ @@ -173,34 +157,6 @@ void L1Algo::CaTrackFinderSlice() stat_N++; #endif -#ifdef XXX - TStopwatch c_timerG; // global - TStopwatch c_timerI; // for iterations - - L1CATFIterTimerInfo gti; // global - gti.Add("init "); - gti.Add("iterts"); - gti.Add("merge "); - - L1CATFTimerInfo ti; - ti.SetNIter(fNFindIterations); // for iterations - ti.Add("init "); - // ti.Add("dblte1"); - // ti.Add("dblte2"); - ti.Add("tripl1"); - - - ti.Add("tracks"); - ti.Add("table"); - ti.Add("save"); - ti.Add("delete"); - ti.Add("copy"); - ti.Add("finish"); - - static L1CATFIterTimerInfo stat_gti = gti; - static L1CATFTimerInfo stat_ti = ti; -#endif // XXX - #ifdef COUNTERS static Tindex stat_nStartHits = 0; static Tindex stat_nHits[fNFindIterations] = {0}; @@ -224,10 +180,6 @@ void L1Algo::CaTrackFinderSlice() ResetSliceData(); -#ifdef XXX - c_timerG.Start(); -#endif // XXX - L1HitIndex_t nGridHitsFilled = 0; for (int iS = 0; iS < fParameters.GetNstationsActive(); ++iS) { @@ -304,19 +256,10 @@ void L1Algo::CaTrackFinderSlice() fGridPointsBuf.reduce(nGridHitsFilled); -#ifdef _OPENMP -#pragma omp parallel for schedule(dynamic, 5) -#endif for (unsigned int ih = 0; ih < fGridHits.size(); ++ih) { fGridPoints[ih].Set(fGridHits[ih]); } -#ifdef XXX - c_timerG.Stop(); - gti["init "] = c_timerG; - c_timerG.Start(); -#endif - /********************************/ /** * Loop over tracking iterations ***********************************/ @@ -332,10 +275,8 @@ void L1Algo::CaTrackFinderSlice() { fpCurrentIteration = &caIteration; // select current iteration - for (int n = 0; n < fNThreads; n++) { - for (int j = 0; j < fParameters.GetNstationsActive(); j++) { - fTriplets[j][n].clear(); - } + for (int j = 0; j < fParameters.GetNstationsActive(); j++) { + fTriplets[j].clear(); } /// isec - number of current iterations, fNFindIterations - number of all iterations #ifdef COUNTERS @@ -428,18 +369,18 @@ void L1Algo::CaTrackFinderSlice() constructor3.CreateTripletsForHit(istal, istal + 2, istal + 3, ih); } - auto oldSize = fTriplets[istal][0].size(); + auto oldSize = fTriplets[istal].size(); - fTriplets[istal][0].insert(fTriplets[istal][0].end(), constructor1.GetTriplets().begin(), - constructor1.GetTriplets().end()); - fTriplets[istal][0].insert(fTriplets[istal][0].end(), constructor2.GetTriplets().begin(), - constructor2.GetTriplets().end()); - fTriplets[istal][0].insert(fTriplets[istal][0].end(), constructor3.GetTriplets().begin(), - constructor3.GetTriplets().end()); + fTriplets[istal].insert(fTriplets[istal].end(), constructor1.GetTriplets().begin(), + constructor1.GetTriplets().end()); + fTriplets[istal].insert(fTriplets[istal].end(), constructor2.GetTriplets().begin(), + constructor2.GetTriplets().end()); + fTriplets[istal].insert(fTriplets[istal].end(), constructor3.GetTriplets().begin(), + constructor3.GetTriplets().end()); const L1HitIndex_t ihitl = ih + fGridHitStartIndex[istal]; - fHitFirstTriplet[ihitl] = PackTripletId(istal, 0, oldSize); - fHitNtriplets[ihitl] = fTriplets[istal][0].size() - oldSize; + fHitFirstTriplet[ihitl] = PackTripletId(istal, oldSize); + fHitNtriplets[ihitl] = fTriplets[istal].size() - oldSize; } } // istal @@ -449,9 +390,9 @@ void L1Algo::CaTrackFinderSlice() for (int istal = fParameters.GetNstationsActive() - 2; istal >= fFirstCAstation; istal--) { // start with downstream chambers - for (unsigned int it = 0; it < fTriplets[istal][0].size(); ++it) { + for (unsigned int it = 0; it < fTriplets[istal].size(); ++it) { - L1Triplet& tr = fTriplets[istal][0][it]; + L1Triplet& tr = fTriplets[istal][it]; tr.SetLevel(0); tr.SetFNeighbour(0); tr.SetNNeighbours(0); @@ -462,7 +403,6 @@ void L1Algo::CaTrackFinderSlice() unsigned int neighLocation = fHitFirstTriplet[tr.GetMHit()]; unsigned int neighStation = TripletId2Station(neighLocation); - unsigned int neighThread = TripletId2Thread(neighLocation); unsigned int neighTriplet = TripletId2Triplet(neighLocation); if (nNeighbours > 0) { assert((int) neighStation == istal + 1 || (int) neighStation == istal + 2); } @@ -471,7 +411,7 @@ void L1Algo::CaTrackFinderSlice() for (unsigned int iN = 0; iN < nNeighbours; ++iN, ++neighTriplet, ++neighLocation) { - L1Triplet& neighbour = fTriplets[neighStation][neighThread][neighTriplet]; + L1Triplet& neighbour = fTriplets[neighStation][neighTriplet]; fscal dchi2 = 0.; if (!checkTripletMatch(tr, neighbour, dchi2)) continue; @@ -518,7 +458,6 @@ void L1Algo::CaTrackFinderSlice() for (int firstTripletLevel = fParameters.GetNstationsActive() - 3; firstTripletLevel >= min_level; firstTripletLevel--) { // choose length in triplets number - firstTripletLevel - the maximum possible triplet level among all triplets in the searched candidate - TStopwatch Time; // how many levels to check int nlevel = (fParameters.GetNstationsActive() - 2) - firstTripletLevel + 1; @@ -527,9 +466,7 @@ void L1Algo::CaTrackFinderSlice() (firstTripletLevel > min_level) ? firstTripletLevel + 2 : min_level + 3; // loose maximum - for (int i = 0; i < fNThreads; ++i) { - fTrackCandidates[i].clear(); - } + fTrackCandidates.clear(); fStripToTrack.reset(fInputData.GetNhitKeys(), -1); @@ -539,95 +476,83 @@ void L1Algo::CaTrackFinderSlice() if (--nlevel == 0) break; //TODO: SG: this is not needed -#ifdef _OPENMP -#pragma omp parallel for firstprivate(curr_tr, new_tr, best_tr, curr_chi2, best_chi2, best_L, curr_L, \ - ndf) // schedule(dynamic, 10) -#endif - for (Tindex iThread = 0; iThread < fNThreads; ++iThread) { - for (Tindex itrip = 0; itrip < (Tindex) fTriplets[istaF][iThread].size(); ++itrip) { + for (Tindex itrip = 0; itrip < (Tindex) fTriplets[istaF].size(); ++itrip) { -#ifdef _OPENMP - int thread_num = omp_get_thread_num(); -#else - int thread_num = 0; -#endif - L1Triplet& first_trip = (fTriplets[istaF][iThread][itrip]); - if (fvHitKeyFlags[fGridHits[first_trip.GetLHit()].f] || fvHitKeyFlags[fGridHits[first_trip.GetLHit()].b]) { - continue; - } - // ghost suppression !!! - // + L1Triplet& first_trip = (fTriplets[istaF][itrip]); + if (fvHitKeyFlags[fGridHits[first_trip.GetLHit()].f] || fvHitKeyFlags[fGridHits[first_trip.GetLHit()].b]) { + continue; + } + // ghost suppression !!! + // - if (!fpCurrentIteration->GetTrackFromTripletsFlag()) { // ghost suppression !!! - int nHits = 3 + first_trip.GetLevel(); - if (fGridHits[first_trip.GetLHit()].iSt == 0) { - if (nHits < fpCurrentIteration->GetMinNhitsStation0()) { continue; } - } - else { - if (nHits < fpCurrentIteration->GetMinNhits()) { continue; } - } + if (!fpCurrentIteration->GetTrackFromTripletsFlag()) { // ghost suppression !!! + int nHits = 3 + first_trip.GetLevel(); + if (fGridHits[first_trip.GetLHit()].iSt == 0) { + if (nHits < fpCurrentIteration->GetMinNhitsStation0()) { continue; } } + else { + if (nHits < fpCurrentIteration->GetMinNhits()) { continue; } + } + } - // Collect triplets, which can start a track with length equal to firstTipletLevel + 3. This cut suppresses - // ghost tracks, but does not affect the efficiency - if (first_trip.GetLevel() < firstTripletLevel) { continue; } + // Collect triplets, which can start a track with length equal to firstTipletLevel + 3. This cut suppresses + // ghost tracks, but does not affect the efficiency + if (first_trip.GetLevel() < firstTripletLevel) { continue; } - // curr_tr.Momentum = 0.f; - curr_tr.chi2 = 0.f; - // curr_tr.Lengtha = 0; - curr_tr.ista = 0; - curr_tr.fHits.clear(); - curr_tr.fHits.push_back(fGridHitIds[first_trip.GetLHit()]); - curr_tr.NHits = 1; + // curr_tr.Momentum = 0.f; + curr_tr.chi2 = 0.f; + // curr_tr.Lengtha = 0; + curr_tr.ista = 0; + curr_tr.fHits.clear(); + curr_tr.fHits.push_back(fGridHitIds[first_trip.GetLHit()]); + curr_tr.NHits = 1; - curr_L = 1; - curr_chi2 = first_trip.GetChi2(); + curr_L = 1; + curr_chi2 = first_trip.GetChi2(); - best_tr = (curr_tr); - best_chi2 = curr_chi2; - best_L = curr_L; + best_tr = (curr_tr); + best_chi2 = curr_chi2; + best_L = curr_L; - CAFindTrack(istaF, best_tr, best_L, best_chi2, &first_trip, (curr_tr), curr_L, curr_chi2, min_best_l, - new_tr); /// reqursive func to build a tree of possible track-candidates and choose the best - // if ( best_L < min_best_l ) continue; - if (best_L < firstTripletLevel + 2) continue; // lose maximum one hit + CAFindTrack(istaF, best_tr, best_L, best_chi2, &first_trip, (curr_tr), curr_L, curr_chi2, min_best_l, + new_tr); /// reqursive func to build a tree of possible track-candidates and choose the best + // if ( best_L < min_best_l ) continue; + if (best_L < firstTripletLevel + 2) continue; // lose maximum one hit - if (best_L < min_level + 3) continue; // should find all hits for min_level + if (best_L < min_level + 3) continue; // should find all hits for min_level - ndf = best_L * 2 - 5; + ndf = best_L * 2 - 5; - if (kGlobal == fTrackingMode || kMcbm == fTrackingMode) { ndf = best_L * 2 - 4; } + // TODO: automatize the NDF calculation - best_chi2 = best_chi2 / ndf; //normalize + if (kGlobal == fTrackingMode || kMcbm == fTrackingMode) { ndf = best_L * 2 - 4; } - if (fGhostSuppression) { - if (3 == best_L) { - if (!fpCurrentIteration->GetPrimaryFlag() && (istaF != 0)) continue; // too /*short*/ non-MAPS track - if (fpCurrentIteration->GetPrimaryFlag() && (best_chi2 > 5.0)) continue; - } + best_chi2 = best_chi2 / ndf; //normalize + + if (fGhostSuppression) { + if (3 == best_L) { + if (!fpCurrentIteration->GetPrimaryFlag() && (istaF != 0)) continue; // too /*short*/ non-MAPS track + if (fpCurrentIteration->GetPrimaryFlag() && (best_chi2 > 5.0)) continue; } - fTrackCandidates[thread_num].push_back(best_tr); - L1Branch& tr = fTrackCandidates[thread_num].back(); - tr.Set(istaF, best_L, best_chi2, first_trip.GetQp(), - PackTrackId(thread_num, fTrackCandidates[thread_num].size() - 1)); - if (0) { // debug - cout << "track " << fTrackCandidates[thread_num].size() - 1 << " found, L = " << (int) best_L - << " chi2= " << best_chi2 << endl; - cout << " hits: "; - for (unsigned int i = 0; i < tr.fHits.size(); i++) { - cout << GetMcTrackIdForCaHit(tr.fHits[i]) << " "; - } - cout << endl; + } + fTrackCandidates.push_back(best_tr); + L1Branch& tr = fTrackCandidates.back(); + tr.Set(istaF, best_L, best_chi2, first_trip.GetQp(), fTrackCandidates.size() - 1); + if (0) { // debug + cout << "track " << fTrackCandidates.size() - 1 << " found, L = " << (int) best_L << " chi2= " << best_chi2 + << endl; + cout << " hits: "; + for (unsigned int i = 0; i < tr.fHits.size(); i++) { + cout << GetMcTrackIdForCaHit(tr.fHits[i]) << " "; } - } // itrip - } // iThread - } // istaF - - for (Tindex iThread = 0; iThread < fNThreads; ++iThread) { - for (Tindex iTrack = 0; iTrack < (Tindex) fTrackCandidates[iThread].size(); ++iTrack) { - L1Branch& tr = fTrackCandidates[iThread][iTrack]; - tr.fIsAlive = false; - } + cout << endl; + } + } // itrip + } // istaF + + for (Tindex iTrack = 0; iTrack < (Tindex) fTrackCandidates.size(); ++iTrack) { + L1Branch& tr = fTrackCandidates[iTrack]; + tr.fIsAlive = false; } bool repeatCompetition = true; @@ -635,193 +560,129 @@ void L1Algo::CaTrackFinderSlice() for (iComp = 0; (iComp < 100) && repeatCompetition; ++iComp) { // == Loop over track candidates and mark their strips - // TODO: OpenMP repeatCompetition = false; - for (Tindex iThread = 0; iThread < fNThreads; ++iThread) { - for (Tindex iTrack = 0; iTrack < (Tindex) fTrackCandidates[iThread].size(); ++iTrack) { - L1Branch& tr = fTrackCandidates[iThread][iTrack]; - if (tr.fIsAlive) continue; - - for (int iHit = 0; iHit < (int) tr.fHits.size(); ++iHit) { - const L1Hit& h = fInputData.GetHit(tr.fHits[iHit]); - bool isAlive = true; - { // front strip -#ifdef _OPENMP - omp_set_lock(&fStripToTrackLock[h.f]); -#endif - auto& stripF = (fStripToTrack)[h.f]; - if ((stripF >= 0) && (stripF != tr.fID)) { // strip is used by other candidate - const auto& other = fTrackCandidates[TrackId2Thread(stripF)][TrackId2Track(stripF)]; - if (!other.fIsAlive && L1Branch::compareCand(tr, other)) { stripF = tr.fID; } - else { - isAlive = false; - } - } + for (Tindex iTrack = 0; iTrack < (Tindex) fTrackCandidates.size(); ++iTrack) { + L1Branch& tr = fTrackCandidates[iTrack]; + if (tr.fIsAlive) continue; + + for (int iHit = 0; iHit < (int) tr.fHits.size(); ++iHit) { + const L1Hit& h = fInputData.GetHit(tr.fHits[iHit]); + bool isAlive = true; + { // front strip + auto& stripF = (fStripToTrack)[h.f]; + if ((stripF >= 0) && (stripF != tr.fID)) { // strip is used by other candidate + const auto& other = fTrackCandidates[stripF]; + if (!other.fIsAlive && L1Branch::compareCand(tr, other)) { stripF = tr.fID; } else { - stripF = tr.fID; + isAlive = false; } -#ifdef _OPENMP - omp_unset_lock(&fStripToTrackLock[h.f]); -#endif - if (!isAlive) { break; } } + else { + stripF = tr.fID; + } + if (!isAlive) { break; } + } - { // back strip -#ifdef _OPENMP - omp_set_lock(&fStripToTrackLock[h.b]); -#endif - auto& stripB = (fStripToTrack)[h.b]; - if ((stripB >= 0) && (stripB != tr.fID)) { // strip is used by other candidate - const auto& other = fTrackCandidates[TrackId2Thread(stripB)][TrackId2Track(stripB)]; - if (!other.fIsAlive && L1Branch::compareCand(tr, other)) { stripB = tr.fID; } - else { - isAlive = false; - } - } + { // back strip + auto& stripB = (fStripToTrack)[h.b]; + if ((stripB >= 0) && (stripB != tr.fID)) { // strip is used by other candidate + const auto& other = fTrackCandidates[stripB]; + if (!other.fIsAlive && L1Branch::compareCand(tr, other)) { stripB = tr.fID; } else { - stripB = tr.fID; + isAlive = false; } -#ifdef _OPENMP - omp_unset_lock(&fStripToTrackLock[h.b]); -#endif - if (!isAlive) { break; } } - } // loop over hits - } // itrack - } // iThread - - // == Loop over track candidates and select those that are alive - // TODO: OpenMP - for (Tindex iThread = 0; iThread < fNThreads; ++iThread) { - for (Tindex iTrack = 0; iTrack < (Tindex) fTrackCandidates[iThread].size(); ++iTrack) { - L1Branch& tr = fTrackCandidates[iThread][iTrack]; - if (tr.fIsAlive) { continue; } - - tr.fIsAlive = true; - for (int iHit = 0; tr.fIsAlive && (iHit < (int) tr.fHits.size()); ++iHit) { - const L1Hit& h = fInputData.GetHit(tr.fHits[iHit]); - tr.fIsAlive = tr.fIsAlive && ((fStripToTrack)[h.f] == tr.fID) && ((fStripToTrack)[h.b] == tr.fID); - } - - if (!tr.fIsAlive) { // release strips - for (int iHit = 0; (iHit < (int) tr.fHits.size()); ++iHit) { - const L1Hit& h = fInputData.GetHit(tr.fHits[iHit]); - if (fStripToTrack[h.f] == tr.fID) { fStripToTrack[h.f] = -1; } - if (fStripToTrack[h.b] == tr.fID) { fStripToTrack[h.b] = -1; } + else { + stripB = tr.fID; } + if (!isAlive) { break; } } - else { - repeatCompetition = true; - } - } // itrack - } // iThread - } // competitions + } // loop over hits + } // itrack - // cout << " N Competitions: " << iComp << endl; - - // == - - for (int i = 0; i < fNThreads; ++i) { - fSliceRecoTracks_thread[i].clear(); - fSliceRecoHits_thread[i].clear(); - } + // == Loop over track candidates and select those that are alive - for (int i = 0; i < fNThreads; ++i) { - L1Track t; + for (Tindex iTrack = 0; iTrack < (Tindex) fTrackCandidates.size(); ++iTrack) { + L1Branch& tr = fTrackCandidates[iTrack]; + if (tr.fIsAlive) { continue; } -#ifdef _OPENMP -#pragma omp parallel for schedule(dynamic, 10) firstprivate(t) -#endif - for (Tindex iCandidate = 0; iCandidate < (Tindex) fTrackCandidates[i].size(); ++iCandidate) { - L1Branch& tr = fTrackCandidates[i][iCandidate]; - if (!tr.fIsAlive) continue; - if (kMcbm == fTrackingMode) { - if (tr.NHits <= 3) { continue; } + tr.fIsAlive = true; + for (int iHit = 0; tr.fIsAlive && (iHit < (int) tr.fHits.size()); ++iHit) { + const L1Hit& h = fInputData.GetHit(tr.fHits[iHit]); + tr.fIsAlive = tr.fIsAlive && ((fStripToTrack)[h.f] == tr.fID) && ((fStripToTrack)[h.b] == tr.fID); } - else if (kGlobal == fTrackingMode) { - if (tr.NHits < 3) { continue; } + + if (!tr.fIsAlive) { // release strips + for (int iHit = 0; (iHit < (int) tr.fHits.size()); ++iHit) { + const L1Hit& h = fInputData.GetHit(tr.fHits[iHit]); + if (fStripToTrack[h.f] == tr.fID) { fStripToTrack[h.f] = -1; } + if (fStripToTrack[h.b] == tr.fID) { fStripToTrack[h.b] = -1; } + } } else { - if (tr.NHits < 3) { continue; } + repeatCompetition = true; } - if (fpCurrentIteration->GetExtendTracksFlag()) { - if (tr.NHits != fParameters.GetNstationsActive()) BranchExtender(tr); - } - fscal sumTime = 0; + } // itrack -#ifdef _OPENMP - int num_thread = omp_get_thread_num(); -#else - int num_thread = 0; -#endif - for (L1Vector<L1HitIndex_t>::iterator phIt = tr.fHits.begin(); /// used strips are marked - phIt != tr.fHits.end(); ++phIt) { - const L1Hit& hit = fInputData.GetHit(*phIt); - fvHitKeyFlags[hit.f] = 1; - fvHitKeyFlags[hit.b] = 1; - fSliceRecoHits_thread[num_thread].push_back(*phIt); - fscal dx = hit.x - fParameters.GetTargetPositionX()[0]; - fscal dy = hit.y - fParameters.GetTargetPositionY()[0]; - fscal dz = hit.z - fParameters.GetTargetPositionZ()[0]; - - fscal timeFlight = sqrt(dx * dx + dy * dy + dz * dz) / 30.f; // c = 30[cm/ns] - sumTime += (hit.t - timeFlight); - } + } // competitions - t.NHits = tr.NHits; - fSliceRecoTracks_thread[num_thread].push_back(t); - if (0) { // SG debug - cout << "store track " << iCandidate << " chi2= " << tr.chi2 << endl; - cout << " hits: "; - for (unsigned int ih = 0; ih < tr.fHits.size(); ih++) { - cout << GetMcTrackIdForCaHit(tr.fHits[ih]) << " "; - } - cout << '\n'; - } + // cout << " N Competitions: " << iComp << endl; - } // tracks - } // threads + // == -#ifdef XXX - Time.Stop(); - ti[isec]["table"] += Time; + for (Tindex iCandidate = 0; iCandidate < (Tindex) fTrackCandidates.size(); ++iCandidate) { + L1Branch& tr = fTrackCandidates[iCandidate]; + if (!tr.fIsAlive) continue; + if (kMcbm == fTrackingMode) { + if (tr.NHits <= 3) { continue; } + } + else if (kGlobal == fTrackingMode) { + if (tr.NHits < 3) { continue; } + } + else { + if (tr.NHits < 3) { continue; } + } + if (fpCurrentIteration->GetExtendTracksFlag()) { + if (tr.NHits != fParameters.GetNstationsActive()) BranchExtender(tr); + } + fscal sumTime = 0; - Time.Start(); + for (auto iHit : tr.fHits) { + const L1Hit& hit = fInputData.GetHit(iHit); -#endif - int nRecoTracks = fSliceRecoTracks.size(); - int nRecoHits = fSliceRecoHits.size(); + /// used strips are marked - L1Vector<int> offset_tracks("L1CATrackFinder::offset_tracks", fNThreads, nRecoTracks); - L1Vector<int> offset_hits("L1CATrackFinder::offset_hits", fNThreads, nRecoHits); + fvHitKeyFlags[hit.f] = 1; + fvHitKeyFlags[hit.b] = 1; + fSliceRecoHits.push_back(iHit); - nRecoTracks += fSliceRecoTracks_thread[0].size(); - nRecoHits += fSliceRecoHits_thread[0].size(); + fscal dx = hit.x - fParameters.GetTargetPositionX()[0]; + fscal dy = hit.y - fParameters.GetTargetPositionY()[0]; + fscal dz = hit.z - fParameters.GetTargetPositionZ()[0]; - for (int i = 1; i < fNThreads; ++i) { - offset_tracks[i] = offset_tracks[i - 1] + fSliceRecoTracks_thread[i - 1].size(); - offset_hits[i] = offset_hits[i - 1] + fSliceRecoHits_thread[i - 1].size(); - nRecoTracks += fSliceRecoTracks_thread[i].size(); - nRecoHits += fSliceRecoHits_thread[i].size(); - } - fSliceRecoTracks.enlarge(nRecoTracks); - fSliceRecoHits.enlarge(nRecoHits); -#ifdef _OPENMP -#pragma omp parallel for -#endif - for (int i = 0; i < fNThreads; ++i) { - for (Tindex iC = 0; iC < (Tindex) fSliceRecoTracks_thread[i].size(); ++iC) { - fSliceRecoTracks[offset_tracks[i] + iC] = fSliceRecoTracks_thread[i][iC]; + fscal timeFlight = sqrt(dx * dx + dy * dy + dz * dz) / 30.f; // c = 30[cm/ns] + sumTime += (hit.t - timeFlight); } - for (Tindex iH = 0; iH < (Tindex) fSliceRecoHits_thread[i].size(); ++iH) { - fSliceRecoHits[offset_hits[i] + iH] = fSliceRecoHits_thread[i][iH]; + L1Track t; + t.NHits = tr.NHits; + fSliceRecoTracks.push_back(t); + if (0) { // SG debug + cout << "store track " << iCandidate << " chi2= " << tr.chi2 << endl; + cout << " hits: "; + for (unsigned int ih = 0; ih < tr.fHits.size(); ih++) { + cout << GetMcTrackIdForCaHit(tr.fHits[ih]) << " "; + } + cout << '\n'; } - } + + } // tracks + } // firstTripletLevel + // suppress strips of suppressed hits for (L1HitIndex_t ip = 0; ip < fGridPoints.size(); ip++) { const L1HitPoint& hp = fGridPoints[ip]; @@ -832,13 +693,6 @@ void L1Algo::CaTrackFinderSlice() } } -#ifdef XXX - c_timer.Stop(); - ti[isec]["tracks"] = c_timer; - c_timer.Start(); -#endif - - if (isec < (fNFindIterations - 1)) { int NHitsOnStation = 0; @@ -863,16 +717,6 @@ void L1Algo::CaTrackFinderSlice() fGridHitStopIndex[ista] = NHitsOnStation; } -#ifdef XXX - c_timer.Stop(); - ti[isec]["finish"] = c_timer; -#endif - -#ifdef XXX - // if( stat_max_n_trip<stat_n_trip ) stat_max_n_trip = vTriplets.size(); - // Tindex tsize = vTripletsP.size()*sizeof(L1Triplet); - // if( stat_max_trip_size < tsize ) stat_max_trip_size = tsize; -#endif // #ifdef DRAW // draw->ClearVeiw(); // // draw->DrawInfo(); @@ -900,12 +744,6 @@ void L1Algo::CaTrackFinderSlice() } // for (int isec // ---- Loop over Track Finder iterations: END -----------------------------------------------------------// -#ifdef XXX - c_timerG.Stop(); - gti["iterts"] = c_timerG; - c_timerG.Start(); -#endif - if constexpr (L1Constants::control::kIfMergeClones) { //CAMergeClones(); // Fit tracks @@ -915,68 +753,8 @@ void L1Algo::CaTrackFinderSlice() fCloneMerger.Exec(fSliceRecoTracks, fSliceRecoHits); } -#ifdef XXX - c_timerG.Stop(); - gti["merge "] = c_timerG; -#endif - //================================== -#ifdef XXX - - - cout << endl << " --- Timers, ms --- " << endl; - ti.Calc(); - stat_ti += ti; - L1CATFTimerInfo tmp_ti = stat_ti / 0.001 / stat_N; // ms - - tmp_ti.PrintReal(); - stat_gti += gti; - L1CATFIterTimerInfo tmp_gti = stat_gti / 0.001 / stat_N; // ms - tmp_gti.PrintReal(1); - fstream filestr; - filestr.open("speedUp.log", fstream::out | fstream::app); - fscal tripl_speed = 1000. / (tmp_ti.GetTimerAll()["tripl1"].Real()); - filestr << tripl_speed << " "; - filestr.close(); - - -#if 0 - static long int NTimes =0, NHits=0, HitSize =0, NStrips=0, StripSize =0, NStripsB=0, StripSizeB =0, - NDup=0, DupSize=0, NTrip=0, TripSize=0, NBranches=0, BranchSize=0, NTracks=0, TrackSize=0 ; - - NTimes++; - NHits += fGridHits.size(); - HitSize += fGridHits.size()*sizeof(L1Hit); - NStrips+= vStrips.size(); - StripSize += vStrips.size()*sizeof(fscal) + (*fStripFlag).size()*sizeof(unsigned char); - NStripsB+= (*fStripFlagB).size(); - StripSizeB += vStripsB.size()*sizeof(fscal) + (*fStripFlagB).size()*sizeof(unsigned char); - NDup += stat_max_n_dup; - DupSize += stat_max_n_dup*sizeof(/*short*/ int); - NTrip += stat_max_n_trip; - TripSize += stat_max_trip_size; - - NBranches += stat_max_n_branches; - BranchSize += stat_max_BranchSize; - NTracks += fSliceRecoTracks.size(); - TrackSize += sizeof(L1Track)*fSliceRecoTracks.size() + sizeof(L1HitIndex_t)*fSliceRecoHits.size(); - int k = 1024*NTimes; - - cout<<"L1 Event size: \n" - <<HitSize/k<<"kB for "<<NHits/NTimes<<" hits, \n" - <<StripSize/k<<"kB for "<<NStrips/NTimes<<" strips, \n" - <<StripSizeB/k<<"kB for "<<NStripsB/NTimes<<" stripsB, \n" - <<DupSize/k<<"kB for "<<NDup/NTimes<<" doublets, \n" - <<TripSize/k<<"kB for "<<NTrip/NTimes<<" triplets\n" - <<BranchSize/k<<"kB for "<<NBranches/NTimes<<" branches, \n" - <<TrackSize/k<<"kB for "<<NTracks/NTimes<<" tracks. "<<endl; - cout<<" L1 total event size = " - <<( HitSize + StripSize + StripSizeB + DupSize + TripSize + BranchSize + TrackSize )/k - <<" Kb"<<endl; -#endif // 0 -#endif - #ifdef DRAW draw->ClearVeiw(); // draw->DrawInputHits(); @@ -1098,10 +876,9 @@ void L1Algo::CAFindTrack(int ista, L1Branch& best_tr, unsigned char& best_L, fsc unsigned int ID = curr_trip->GetFNeighbour() + in; unsigned int Station = TripletId2Station(ID); - unsigned int Thread = TripletId2Thread(ID); unsigned int Triplet = TripletId2Triplet(ID); - const L1Triplet& new_trip = fTriplets[Station][Thread][Triplet]; + const L1Triplet& new_trip = fTriplets[Station][Triplet]; fscal dchi2 = 0.; if (!checkTripletMatch(*curr_trip, new_trip, dchi2)) continue; diff --git a/reco/L1/L1Algo/L1Constants.h b/reco/L1/L1Algo/L1Constants.h index e228cbea1efee888ee60312cb8df4bb7fe5418f5..6b8012a991b7ba3294f9ed3a27486050195ac9de 100644 --- a/reco/L1/L1Algo/L1Constants.h +++ b/reco/L1/L1Algo/L1Constants.h @@ -32,14 +32,12 @@ namespace L1Constants constexpr int kMaxFieldApproxPolynomialOrder {5}; /// Amount of bits to code a station, thread or triplet. This values determine the ma - constexpr unsigned int kStationBits = 6u; ///< Amount of bits to code one station - constexpr unsigned int kThreadBits = 6u; ///< Amount of bits to code one thread - constexpr unsigned int kTripletBits = 32u - kStationBits - kThreadBits; ///< Amount of bits to code one triplet + constexpr unsigned int kStationBits = 6u; ///< Amount of bits to code one station + constexpr unsigned int kTripletBits = 32u - kStationBits; ///< Amount of bits to code one triplet constexpr int kMaxNdetectors = 5; ///< Max number of tracking detectors constexpr int kMaxNstations = 1u << kStationBits; ///< Max number of stations, 2^6 = 64 - constexpr int kMaxNthreads = 1u << kThreadBits; ///< Max number of threads, 2^6 = 64 - constexpr int kMaxNtriplets = 1u << kTripletBits; ///< Max number of triplets, 2^20 = 1,048,576 + constexpr int kMaxNtriplets = 1u << kTripletBits; ///< Max number of triplets, 2^26 = 67,108,864 constexpr uint8_t kDetBits = 4u; // Max 16 detectors @@ -47,12 +45,8 @@ namespace L1Constants /// NOTE: For a "track group" definition see L1Parameters.h, GetSearchWindow function constexpr int kMaxNtrackGroups = 4; - // TODO: Clarify the meaning of these coefficients - constexpr int kCoeff = 64 / 4; ///< TODO: - constexpr int kMaxPortionDoublets = 10000 / 5 * 64 / 2 / kCoeff; ///< Max size of the doublets portion - constexpr int kMaxPortionTriplets = 10000 * 5 * 64 / 2 / kCoeff; ///< Max size of the triplets portion - constexpr int kMaxPortionTripletsP = kMaxPortionTriplets / fvec::size(); ///< Max size of the triplets portion - } // namespace size + } // namespace size + /// Control flags namespace control diff --git a/reco/L1/L1Algo/L1Grid.cxx b/reco/L1/L1Algo/L1Grid.cxx index 9bade04c188cdd21d31d456efa5173e547f81bbc..8a291e75e952cd6e816a535d52e7e74f9237ab98 100644 --- a/reco/L1/L1Algo/L1Grid.cxx +++ b/reco/L1/L1Algo/L1Grid.cxx @@ -11,9 +11,6 @@ #include <string.h> #include "L1Def.h" -#ifdef _OPENMP -#include "omp.h" -#endif #include "L1Algo.h" @@ -48,9 +45,6 @@ void L1Grid::UpdateIterGrid(unsigned int Nelements, L1Hit* hits, L1Vector<L1HitI fscal xs = 0; fscal ys = 0; -#ifdef _OPENMP -#pragma omp parallel for schedule(dynamic, 250) firstprivate(xs, ys) -#endif for (L1HitIndex_t x = 0; x < Nelements; x++) { const L1Hit& hit = hits[x]; @@ -60,9 +54,6 @@ void L1Grid::UpdateIterGrid(unsigned int Nelements, L1Hit* hits, L1Vector<L1HitI const L1HitIndex_t& bin = GetBinBounded(xs, ys, hit.t); fHitsInBin[x] = fFirstHitInBin[bin + 1]; -#ifdef _OPENMP -#pragma omp atomic -#endif fFirstHitInBin[bin + 1]++; } } @@ -71,9 +62,6 @@ void L1Grid::UpdateIterGrid(unsigned int Nelements, L1Hit* hits, L1Vector<L1HitI /* Up-Sweep Phase */ for (unsigned int k = 1; k < fN + 2; k = kk) { kk = k << 1; -#ifdef _OPENMP -#pragma omp parallel for //schedule(guided) -#endif for (unsigned int i = kk - 1; i < fN + 2; i += kk) { fFirstHitInBin[i] = fFirstHitInBin[i - k] + fFirstHitInBin[i]; } @@ -82,17 +70,11 @@ void L1Grid::UpdateIterGrid(unsigned int Nelements, L1Hit* hits, L1Vector<L1HitI /* Down-Sweep Phase */ for (int k = kk >> 1; k > 1; k = kk) { kk = k >> 1; -#ifdef _OPENMP -#pragma omp parallel for //schedule(guided) -#endif for (unsigned int i = k - 1; i < fN + 2 - kk; i += k) { fFirstHitInBin[i + kk] = fFirstHitInBin[i] + fFirstHitInBin[i + kk]; } } -#ifdef _OPENMP -#pragma omp parallel for schedule(dynamic, 250) firstprivate(xs, ys) -#endif for (L1HitIndex_t x = 0; x < Nelements; x++) { const L1Hit& hit = hits[x]; @@ -117,28 +99,12 @@ void L1Grid::UpdateIterGrid(unsigned int Nelements, L1Hit* hits, L1Vector<L1HitI } -void L1Grid::AllocateMemory(int NThreads) +void L1Grid::AllocateMemory() { - - fNThreads = NThreads * 1; - - // fFirstHitInBinArray.resize(fNThreads, 0); - - int binsGrid = 600000; fFirstHitInBin.reset(binsGrid, 0); fHitsInBin.reset(binsGrid, 0); - - // for( int i = 0; i < fNThreads; i++ ) - // { - // delete[] fFirstHitInBinArray[i]; - // delete[] fFirstHitInBin[i]; - // fFirstHitInBinArray[i] = new L1HitIndex_t[binsGrid];// TODO calculate safe number of bins - // fFirstHitInBin[i] = new L1HitIndex_t[binsGrid]; - // } - // fOffsets.resize(fNThreads +1, 0); - // fNumberHitsInBin.resize(binsGrid, 0); } @@ -161,7 +127,7 @@ void L1Grid::BuildBins(float xMin, float xMax, float yMin, float yMax, float tMi fN = fNx * fNy * fNt; - fBinInGrid = (((fN) / fNThreads) + 1); + fBinInGrid = fN + 1; } @@ -173,29 +139,19 @@ void L1Grid::StoreHits(L1Algo& algo, int iS, L1HitIndex_t& nGridHitsFilled) fFirstHitInBin.reset(fN + 2, 0); -#ifdef _OPENMP -#pragma omp parallel for -#endif for (L1HitIndex_t ih = 0; ih < nHits; ih++) { L1HitIndex_t caHitId = algo.fSliceHitIds[iS][ih]; const L1Hit& h = algo.GetInputData().GetHit(caHitId); auto [x, y] = algo.GetHitCoorOnGrid(h); auto bin = GetBinBounded(x, y, h.t); fHitsInBin[ih] = fFirstHitInBin[bin + 1]; -#ifdef _OPENMP -#pragma omp atomic -#endif fFirstHitInBin[bin + 1]++; } - int kk = 2; /* Up-Sweep Phase */ for (unsigned int k = 1; k < fN + 2; k = kk) { kk = k << 1; -#ifdef _OPENMP -#pragma omp parallel for //schedule(guided) -#endif for (unsigned int i = kk - 1; i < fN + 2; i += kk) { fFirstHitInBin[i] = fFirstHitInBin[i - k] + fFirstHitInBin[i]; } @@ -204,16 +160,11 @@ void L1Grid::StoreHits(L1Algo& algo, int iS, L1HitIndex_t& nGridHitsFilled) /* Down-Sweep Phase */ for (unsigned int k = kk >> 1; k > 1; k = kk) { kk = k >> 1; -#ifdef _OPENMP -#pragma omp parallel for //schedule(guided) -#endif for (unsigned int i = k - 1; i < fN + 2 - kk; i += k) { fFirstHitInBin[i + kk] = fFirstHitInBin[i] + fFirstHitInBin[i + kk]; } } - -#pragma omp parallel for for (L1HitIndex_t ih = 0; ih < nHits; ih++) { L1HitIndex_t caHitId = algo.fSliceHitIds[iS][ih]; const L1Hit& h = algo.GetInputData().GetHit(caHitId); diff --git a/reco/L1/L1Algo/L1Grid.h b/reco/L1/L1Algo/L1Grid.h index 9945ab3441321a36d44fc09a7a18756f3759ba52..eb51e2d3a25143c70c1371035138175b797be3d5 100644 --- a/reco/L1/L1Algo/L1Grid.h +++ b/reco/L1/L1Algo/L1Grid.h @@ -16,9 +16,6 @@ #include <string.h> #include "L1Def.h" -#ifdef _OPENMP -#include "omp.h" -#endif #include "L1Hit.h" #include "L1HitPoint.h" #include "L1Vector.h" @@ -48,8 +45,7 @@ public: void CreatePar0(float xMin, float xMax, float yMin, float yMax, float sx, float sy); void BuildBins(float xMin, float xMax, float yMin, float yMax, float tMin, float tMax, float sx, float sy, float st); - void Initial1(int NThreads); - void AllocateMemory(int NThreads); + void AllocateMemory(); void Create(float xMin, float xMax, float yMin, float yMax, float sx, float sy); void Fill(const L1HitPoint* points, L1HitIndex_t n); // call after sort @@ -113,7 +109,6 @@ private: float fStepYInv {0.f}; //* inverse bin size in Y float fStepTInv {0.f}; //* inverse bin size in T int fBinInGrid {0}; - unsigned short fNThreads {0}; L1Vector<L1HitIndex_t> fFirstHitInBin {"L1Grid::fFirstHitInBin"}; L1Vector<L1HitIndex_t> fHitsInBin {"L1Grid::fHitsInBin"}; diff --git a/reco/L1/L1Algo/L1Parameters.cxx b/reco/L1/L1Algo/L1Parameters.cxx index 2de0fd80eab4dff7c47dd135c538724bb454f3ed..184c118030be32a4119f6dbc5fb3b52e8517712b 100644 --- a/reco/L1/L1Algo/L1Parameters.cxx +++ b/reco/L1/L1Algo/L1Parameters.cxx @@ -224,11 +224,9 @@ std::string L1Parameters::ToString(int verbosity, int indentLevel) const msg << " ----- CA parameters list -----\n"; msg << indent << kCLb << "COMPILE TIME CONSTANTS:\n" << kCL; msg << indent << indentCh << "Bits to code one station: " << L1Constants::size::kStationBits << '\n'; - msg << indent << indentCh << "Bits to code one thread: " << L1Constants::size::kThreadBits << '\n'; msg << indent << indentCh << "Bits to code one triplet: " << L1Constants::size::kTripletBits << '\n'; msg << indent << indentCh << "Max number of detectors: " << L1Constants::size::kMaxNdetectors << '\n'; msg << indent << indentCh << "Max number of stations: " << L1Constants::size::kMaxNstations << '\n'; - msg << indent << indentCh << "Max number of threads: " << L1Constants::size::kMaxNthreads << '\n'; msg << indent << indentCh << "Max number of triplets: " << L1Constants::size::kMaxNtriplets << '\n'; msg << indent << kCLb << "RUNTIME CONSTANTS:\n" << kCL; msg << indent << indentCh << "Random seed: " << fRandomSeed << '\n'; diff --git a/reco/L1/L1Algo/L1Timer.h b/reco/L1/L1Algo/L1Timer.h deleted file mode 100644 index 5ffdadb0ee3f5364c0960f4e1c33d82f6717e701..0000000000000000000000000000000000000000 --- a/reco/L1/L1Algo/L1Timer.h +++ /dev/null @@ -1,170 +0,0 @@ -/* Copyright (C) 2012-2019 Frankfurt Institute for Advanced Studies, Goethe-Universitaet Frankfurt, Frankfurt - SPDX-License-Identifier: GPL-3.0-only - Authors: Igor Kulakov [committer], Maksym Zyzak */ - -#ifndef _L1Timer_H -#define _L1Timer_H - -#include <iomanip> -#include <iostream> -#include <string> -#include <vector> - -#include "L1Def.h" - -class TimerInfo { -public: - TimerInfo() : fName(""), fReal(0), fCpu(0) {}; - TimerInfo(const std::string& name) : fName(name), fReal(0), fCpu(0) {}; - - TimerInfo& operator=(TStopwatch& sw) - { - fReal = sw.RealTime(); - fCpu = sw.CpuTime(); - return (*this); - }; - TimerInfo& operator+=(TStopwatch& sw) - { - fReal += sw.RealTime(); - fCpu += sw.CpuTime(); - return (*this); - }; - void operator+=(const TimerInfo& t) - { - fReal += t.fReal; - fCpu += t.fCpu; - } - TimerInfo operator/(const float f) const - { - TimerInfo r; - r.fName = fName; - r.fReal = fReal / f; - r.fCpu = fCpu / f; - return r; - } - - // void Print(){ std::cout << fReal << "/" << fCpu; }; - void PrintReal() { std::cout << fReal; }; - float Real() { return fReal; }; - std::string& Name() { return fName; }; - -private: - std::string fName; - float fReal, fCpu; -}; - -class L1CATFIterTimerInfo { -public: - L1CATFIterTimerInfo() : fNameToI(), fTIs() {}; - void Add(std::string name) - { - fNameToI[name] = fTIs.size(); - fTIs.push_back(TimerInfo(name)); - }; - TimerInfo& operator[](std::string name) { return fTIs[fNameToI[name]]; }; - TimerInfo& operator[](int i) { return fTIs[i]; }; - void operator+=(L1CATFIterTimerInfo& t) - { - for (unsigned int i = 0; i < fTIs.size(); ++i) - fTIs[i] += t[i]; - } - L1CATFIterTimerInfo operator/(float f) - { - L1CATFIterTimerInfo r; - r.fNameToI = fNameToI; - r.fTIs.resize(fTIs.size()); - for (unsigned int i = 0; i < fTIs.size(); ++i) { - r.fTIs[i] = fTIs[i] / f; - } - return r; - } - - void PrintReal(int f = 0) - { - if (f) { - PrintNames(); - std::cout << '\n'; - } - fTIs[0].PrintReal(); - for (unsigned int i = 1; i < fTIs.size(); ++i) { - std::cout << " | " << std::setw(fTIs[i].Name().size()); - fTIs[i].PrintReal(); - } - if (f) std::cout << '\n'; - }; - void PrintNames() - { - std::cout << fTIs[0].Name(); - for (unsigned int i = 1; i < fTIs.size(); ++i) { - std::cout << " | " << fTIs[i].Name(); - } - }; - -private: - std::map<std::string, int> fNameToI; - std::vector<TimerInfo> fTIs; -}; - -class L1CATFTimerInfo { -public: - L1CATFTimerInfo() : fTIIs(), fTIAll() {}; - void SetNIter(int n) { fTIIs.resize(n); }; - - void Add(std::string name) - { - for (unsigned int i = 0; i < fTIIs.size(); ++i) - fTIIs[i].Add(name); - fTIAll.Add(name); - }; // use after setniter - L1CATFIterTimerInfo& GetTimerAll() { return fTIAll; }; - L1CATFIterTimerInfo& operator[](int i) { return fTIIs[i]; }; - void operator+=(L1CATFTimerInfo& t) - { - for (unsigned int i = 0; i < fTIIs.size(); ++i) - fTIIs[i] += t[i]; - fTIAll += t.GetAllInfo(); - } - L1CATFTimerInfo operator/(float f) - { - L1CATFTimerInfo r; - r.fTIAll = fTIAll / f; - r.SetNIter(fTIIs.size()); - for (unsigned int i = 0; i < fTIIs.size(); ++i) { - r.fTIIs[i] = fTIIs[i] / f; - } - return r; - } - - void Calc() - { - fTIAll = fTIIs[0]; - for (unsigned int i = 1; i < fTIIs.size(); ++i) - fTIAll += fTIIs[i]; - } - - L1CATFIterTimerInfo& GetAllInfo() { return fTIAll; }; - void PrintReal() - { - std::cout.precision(1); - std::cout.setf(std::ios::fixed); - std::cout << " stage " - << " : "; - fTIAll.PrintNames(); - std::cout << '\n'; - for (unsigned int i = 0; i < fTIIs.size(); ++i) { - std::cout << " iter " << i << " : "; - fTIIs[i].PrintReal(); - std::cout << '\n'; - } - std::cout << " all " - << " : "; - fTIAll.PrintReal(); - std::cout << '\n'; - }; - -private: - std::vector<L1CATFIterTimerInfo> fTIIs; - L1CATFIterTimerInfo fTIAll; -}; - -#endif diff --git a/reco/L1/L1Algo/L1TripletConstructor.cxx b/reco/L1/L1Algo/L1TripletConstructor.cxx index 96f4b28f62103848d747d18c76415e51f181d5b3..29e6bff76a0a868e7b12885239f409a1f6e4ad97 100644 --- a/reco/L1/L1Algo/L1TripletConstructor.cxx +++ b/reco/L1/L1Algo/L1TripletConstructor.cxx @@ -285,13 +285,13 @@ void L1TripletConstructor::FitDoublets() void L1TripletConstructor::FindTriplets() { if (fIstaR >= fAlgo->fParameters.GetNstationsActive()) { return; } - findRightHit(); - fitTriplets(); - storeTriplets(); + FindRightHit(); + FitTriplets(); + StoreTriplets(); } -void L1TripletConstructor::findRightHit() +void L1TripletConstructor::FindRightHit() { /// Add the middle hits to parameters estimation. Propagate to right station. @@ -360,7 +360,7 @@ void L1TripletConstructor::findRightHit() } -void L1TripletConstructor::fitTriplets() +void L1TripletConstructor::FitTriplets() { constexpr bool dumpTriplets = 0; @@ -546,7 +546,7 @@ void L1TripletConstructor::fitTriplets() } // findTripletsStep2 -void L1TripletConstructor::storeTriplets() +void L1TripletConstructor::StoreTriplets() { /// Selects good triplets and saves them into fTriplets. /// Finds neighbouring triplets at the next station. diff --git a/reco/L1/L1Algo/L1TripletConstructor.h b/reco/L1/L1Algo/L1TripletConstructor.h index 6cf5a6b31d038549658072f2c5f32e2bda6d259a..3e1e8c64680fcf48554ba06f8094d33088d405b6 100644 --- a/reco/L1/L1Algo/L1TripletConstructor.h +++ b/reco/L1/L1Algo/L1TripletConstructor.h @@ -58,13 +58,13 @@ public: /// Add the middle hits to parameters estimation. Propagate to right station. /// Find the triplets (right hit). Reformat data in the portion of triplets. - void findRightHit(); + void FindRightHit(); /// Fit Triplets - void fitTriplets(); + void FitTriplets(); /// Select triplets. Save them into vTriplets. - void storeTriplets(); + void StoreTriplets(); void CollectHits(const L1TrackPar& Tr, const int iSta, const double chi2Cut, const int iMC, L1Vector<L1HitIndex_t>& collectedHits, int maxNhits);