diff --git a/algo/detectors/tof/Clusterizer.cxx b/algo/detectors/tof/Clusterizer.cxx index 875738135c880742dcb1494acdf62ad2794179bb..14a9aa1e35e331aa5226352f5cb2cbaa395b94ef 100644 --- a/algo/detectors/tof/Clusterizer.cxx +++ b/algo/detectors/tof/Clusterizer.cxx @@ -16,14 +16,14 @@ namespace cbm::algo::tof { - Clusterizer::resultType Clusterizer::operator()(inputType digisIn) + Clusterizer::resultType Clusterizer::operator()(const inputType& digisIn) { //std::vector<inputType> input = calibrateDigis(digisIn); std::vector<inputType> input = chanSortDigis(digisIn); return buildClusters(input); } - std::vector<Clusterizer::inputType> Clusterizer::chanSortDigis(inputType& digisIn) + std::vector<Clusterizer::inputType> Clusterizer::chanSortDigis(const inputType& digisIn) { std::vector<inputType> result(fParams.fChanPar.size()); //[nbCh][nDigis] @@ -38,7 +38,7 @@ namespace cbm::algo::tof //This calibration cannot reproduce the non RPC-parallel version, as the digi indices //will be invalidated whenever digis are discarded in the dead-time check. - std::vector<Clusterizer::inputType> Clusterizer::calibrateDigis(inputType& digisIn) + std::vector<Clusterizer::inputType> Clusterizer::calibrateDigis(const inputType& digisIn) { std::vector<inputType> result(fParams.fChanPar.size()); const int32_t numClWalkBinX = fParams.numClWalkBinX; @@ -249,7 +249,7 @@ namespace cbm::algo::tof inputType& storDigi = input[chan]; if (0 == storDigi.size()) { return false; } - const double clusterTime = cluster.weightedTime / cluster.weightsSum; + const double clusterTime = cluster.hitTime / cluster.weightsSum; const TofCell& cell = fParams.fChanPar[chan].cell; //Get starting position in buffer @@ -280,10 +280,6 @@ namespace cbm::algo::tof const double time = 0.5 * (xDigiA->GetTime() + xDigiB->GetTime()); - //D.Smith 8.9.23: Original continue statement, in general much slower (replaced by the conditions below). - // The optimization relies on time-order. - //if (std::abs(time - clusterTime) >= fParams.fdMaxTimeDist) { continue; } - //Continue if digis are in the past of cluster time if (time <= clusterTime - fParams.fdMaxTimeDist) { continue; } @@ -298,7 +294,7 @@ namespace cbm::algo::tof if (1 != xDigiA->GetSide()) { posY *= -1.; } - if (std::abs(posY - cluster.weightedPos.Y() / cluster.weightsSum) >= fParams.fdMaxSpaceDist) { continue; } + if (std::abs(posY - cluster.hitPos.Y() / cluster.weightsSum) >= fParams.fdMaxSpaceDist) { continue; } // append digi pair to current cluster const double posX = ((-(double) numChan / 2. + chan) + 0.5) * cell.sizeX; diff --git a/algo/detectors/tof/Clusterizer.h b/algo/detectors/tof/Clusterizer.h index 4ddd32ba1f8e0be9dbaf571ea737f041674b2cd9..611a34c1d44ba53b40a558a4722d0a48cfc1cde3 100644 --- a/algo/detectors/tof/Clusterizer.h +++ b/algo/detectors/tof/Clusterizer.h @@ -58,41 +58,35 @@ namespace cbm::algo::tof }; struct TofCluster { - //temporary values - std::vector<int32_t> vDigiIndRef; - ROOT::Math::XYZVector weightedPos = ROOT::Math::XYZVector(0.0, 0.0, 0.0); - double weightedTime = 0.0; - double weightedTimeErr = 0.0; - double weightsSum = 0.0; + ROOT::Math::XYZVector hitPos = ROOT::Math::XYZVector(0.0, 0.0, 0.0); + ROOT::Math::XYZVector hitPosErr = ROOT::Math::XYZVector(0.0, 0.0, 0.0); + double hitTime = 0.0; + double hitTimeErr = 0.0; + int32_t address = 0; - //after finalization - ROOT::Math::XYZVector globalPos = ROOT::Math::XYZVector(0.0, 0.0, 0.0); - ROOT::Math::XYZVector globalErr = ROOT::Math::XYZVector(0.0, 0.0, 0.0); - int32_t channel = 0; - int32_t detId = 0; + std::vector<int32_t> vDigiIndRef; + double weightsSum = 0.0; int32_t numChan() { return vDigiIndRef.size() / 2; } void reset() { vDigiIndRef.clear(); - weightedPos = ROOT::Math::XYZVector(0.0, 0.0, 0.0); - globalPos = ROOT::Math::XYZVector(0.0, 0.0, 0.0); - globalErr = ROOT::Math::XYZVector(0.5, 0.5, 0.5); //D.Smith 15.8.23: Set this back to zero eventually. - weightedTime = 0.0; - weightedTimeErr = 0.0; - weightsSum = 0.0; - channel = 0; - detId = 0; + hitPos = ROOT::Math::XYZVector(0.0, 0.0, 0.0); + hitPosErr = ROOT::Math::XYZVector(0.5, 0.5, 0.5); //D.Smith 15.8.23: Set this back to zero eventually. + hitTime = 0.0; + hitTimeErr = 0.0; + weightsSum = 0.0; + address = 0; } void add(ROOT::Math::XYZVector pos, double time, double timeErr, double weight, int32_t digiIndA, int32_t digiIndB) { vDigiIndRef.push_back(digiIndA); vDigiIndRef.push_back(digiIndB); - weightedPos += pos * weight; - weightedTime += time * weight; - weightedTimeErr += timeErr * weight; + hitPos += pos * weight; + hitTime += time * weight; + hitTimeErr += timeErr * weight; weightsSum += weight; } @@ -103,45 +97,38 @@ namespace cbm::algo::tof // the floor() operation in the finalize() function of this class, and results in a different // channel being associated with the cluster. To reproduce the output of the old hit finder, we // divide element-wise instead. Perhaps floor() should be replaced by round(). - //////// weightedPos /= weightsSum; + //////// hitPos /= weightsSum; - weightedPos.SetXYZ(weightedPos.X() / weightsSum, weightedPos.Y() / weightsSum, weightedPos.Z() / weightsSum); - weightedTime /= weightsSum; - weightedTimeErr = timeErr; + hitPos.SetXYZ(hitPos.X() / weightsSum, hitPos.Y() / weightsSum, hitPos.Z() / weightsSum); + hitTime /= weightsSum; + hitTimeErr = timeErr; } void finalize(const TofCell& trafoCell, const ClusterizerRpcPar& par) { - // prepare local->global trafo - ROOT::Math::Rotation3D rotMatrix = trafoCell.rotation; - - // get offset from weighted cluster position by rotation to master frame - ROOT::Math::XYZVector hitposOffset = rotMatrix(weightedPos); - - //get hit position by adding offset to cell coordinates - globalPos = trafoCell.pos + hitposOffset; - - // Simple errors, not properly done at all for now - // Right way of doing it should take into account the weight distribution - // and real system time resolution - ROOT::Math::XYZVector hitErrLocal(0.5, 0.5, 0.5); - - //store results - //globalErr = rotMatrix(hitErrLocal); - globalErr = hitErrLocal; - channel = par.fChanPar.size() / 2 + floor(weightedPos.X() / trafoCell.sizeX); + //get hit channel + const int32_t channel = par.fChanPar.size() / 2 + floor(hitPos.X() / trafoCell.sizeX); // D.Smith 15.8.23: This channel correction doesn't seem to be needed // if (channel < 0) channel = 0; // if (channel > par.fChanPar.size() - 1) channel = par.fChanPar.size() - 1; - detId = par.fChanPar[channel].address; + address = par.fChanPar[channel].address; //Calibrate hit time if applicable - if (par.fCPTOffYRange == 0) { return; } - const double dBin = (weightedPos.Y() + par.fCPTOffYRange) / par.fCPTOffYBinWidth; - const int i1 = floor(dBin); - const int i2 = ceil(dBin); - weightedTime -= par.fCPTOffY[i1] + (dBin - i1) * (par.fCPTOffY[i2] - par.fCPTOffY[i1]); + if (par.fCPTOffYRange != 0) { + const double dBin = (hitPos.Y() + par.fCPTOffYRange) / par.fCPTOffYBinWidth; + const int i1 = floor(dBin); + const int i2 = ceil(dBin); + hitTime -= par.fCPTOffY[i1] + (dBin - i1) * (par.fCPTOffY[i2] - par.fCPTOffY[i1]); + } + + //get offset by rotation to master frame. get hit position by adding offset to cell coordinates + hitPos = trafoCell.pos + trafoCell.rotation(hitPos); + + // Simple errors, not properly done at all for now + // Right way of doing it should take into account the weight distribution + // and real system time resolution + hitPosErr = ROOT::Math::XYZVector(0.5, 0.5, 0.5); } }; @@ -163,7 +150,7 @@ namespace cbm::algo::tof /** ** @brief Build clusters out of ToF Digis and store the resulting info in a TofHit. **/ - resultType operator()(inputType digisIn); + resultType operator()(const inputType& digisIn); /** @brief Set the parameter container ** @param params Vectorer to parameter container @@ -173,8 +160,8 @@ namespace cbm::algo::tof private: ClusterizerRpcPar fParams = {}; ///< Parameter container - std::vector<inputType> calibrateDigis(inputType& digisIn); - std::vector<inputType> chanSortDigis(inputType& digisIn); + std::vector<inputType> calibrateDigis(const inputType& digisIn); + std::vector<inputType> chanSortDigis(const inputType& digisIn); resultType buildClusters(std::vector<inputType>& input); diff --git a/algo/detectors/tof/Hitfind.cxx b/algo/detectors/tof/Hitfind.cxx index 31542bf0a19d35b9e4fee88a5ccc19c8709cc062..ba1f4bdae6c39cce97f27654c0cd2710b8047a59 100644 --- a/algo/detectors/tof/Hitfind.cxx +++ b/algo/detectors/tof/Hitfind.cxx @@ -65,6 +65,8 @@ namespace cbm::algo::tof xpu::timings timings = xpu::pop_timer(); monitor.fTimeHitfind = timings.wall(); + monitor.fNumDigis = digiIn->size(); + monitor.fNumHits = clusterTs.size(); return result; } // ---------------------------------------------------------------------------- diff --git a/algo/detectors/tof/Hitfind.h b/algo/detectors/tof/Hitfind.h index 802ffcdd3a33b3ffb982c0aa41bd438090b3d2b7..09f761f4d524f7637124f71efba53504a0cfb35b 100644 --- a/algo/detectors/tof/Hitfind.h +++ b/algo/detectors/tof/Hitfind.h @@ -27,22 +27,15 @@ namespace cbm::algo::tof ** @brief Monitoring data for hitfinding **/ struct HitfindMonitorData { - std::vector<tof::HitfindMonitorData> fTof; ///< Monitoring data for TOF - - //// TO DO: Add something sensible here. - double fTimeHitfind = 0; - size_t fNumMs = 0; - size_t fNumBytes = 0; - size_t fNumBytesInTof = 0; - size_t fNumDigis = 0; - size_t fNumCompUsed = 0; - size_t fNumErrInvalidEqId = 0; - size_t fNumErrInvalidSysVer = 0; + //std::vector<tof::ClusterizerMonitorData> fMonitor; //Per RPC monitoring data, to be implemented + double fTimeHitfind = 0; + size_t fNumDigis = 0; + size_t fNumHits = 0; + std::string print() const { std::stringstream ss; - ss << "TS stats: num MS " << fNumMs << ", bytes " << fNumBytes << ", digis " << fNumDigis << ", components " - << fNumCompUsed << ", invalidEqIds " << fNumErrInvalidEqId << ", invalidSysVersions " << fNumErrInvalidSysVer + ss << "Hitfind stats: num digis " << fNumDigis << ", time " << fTimeHitfind << ", num hits " << fNumHits << std::endl; return ss.str(); } diff --git a/reco/tasks/CbmTaskTofClusterizer.cxx b/reco/tasks/CbmTaskTofClusterizer.cxx index 52613a1f710885bec5b2f495f64e5aa6074e5d54..9868752d191c8fa3a9774d365f17de8323469413 100644 --- a/reco/tasks/CbmTaskTofClusterizer.cxx +++ b/reco/tasks/CbmTaskTofClusterizer.cxx @@ -357,10 +357,10 @@ bool CbmTaskTofClusterizer::BuildClusters() //Store hits and match for (auto const& cluster : clusters) { const int32_t hitIndex = fTofHitsColl->GetEntriesFast(); - TVector3 hitpos = TVector3(cluster.globalPos.X(), cluster.globalPos.Y(), cluster.globalPos.Z()); - TVector3 hiterr = TVector3(cluster.globalErr.X(), cluster.globalErr.Y(), cluster.globalErr.Z()); + TVector3 hitpos = TVector3(cluster.hitPos.X(), cluster.hitPos.Y(), cluster.hitPos.Z()); + TVector3 hiterr = TVector3(cluster.hitPosErr.X(), cluster.hitPosErr.Y(), cluster.hitPosErr.Z()); new ((*fTofHitsColl)[hitIndex]) - CbmTofHit(cluster.detId, hitpos, hiterr, fiNbHits, cluster.weightedTime, cluster.weightedTimeErr, + CbmTofHit(cluster.address, hitpos, hiterr, fiNbHits, cluster.hitTime, cluster.hitTimeErr, cluster.vDigiIndRef.size(), int32_t(cluster.weightsSum * 10.)); fiNbHits++;