From edbca182865eb111a2df9d6ccf37690158853421 Mon Sep 17 00:00:00 2001 From: zampolli Date: Thu, 28 Jun 2018 16:05:13 +0200 Subject: [PATCH 01/39] Skeleton for matching --- DataFormats/Reconstruction/CMakeLists.txt | 2 ++ .../Reconstruction/src/ReconstructionDataFormatsLinkDef.h | 1 + Detectors/GlobalTracking/CMakeLists.txt | 2 ++ Detectors/GlobalTracking/src/GlobalTrackingLinkDef.h | 1 + cmake/O2Dependencies.cmake | 4 ++++ 5 files changed, 10 insertions(+) diff --git a/DataFormats/Reconstruction/CMakeLists.txt b/DataFormats/Reconstruction/CMakeLists.txt index 004a1ccceda35..5487d923baecf 100644 --- a/DataFormats/Reconstruction/CMakeLists.txt +++ b/DataFormats/Reconstruction/CMakeLists.txt @@ -7,6 +7,7 @@ set(SRCS src/BaseCluster.cxx src/TrackTPCITS.cxx src/Vertex.cxx + src/MatchInfoTOF.cxx ) Set(HEADERS @@ -14,6 +15,7 @@ Set(HEADERS include/${MODULE_NAME}/BaseCluster.h include/${MODULE_NAME}/TrackTPCITS.h include/${MODULE_NAME}/Vertex.h + include/${MODULE_NAME}/MatchInfoTOF.h ) Set(LINKDEF src/ReconstructionDataFormatsLinkDef.h) diff --git a/DataFormats/Reconstruction/src/ReconstructionDataFormatsLinkDef.h b/DataFormats/Reconstruction/src/ReconstructionDataFormatsLinkDef.h index a62a2da8b7d08..96248e38010b5 100644 --- a/DataFormats/Reconstruction/src/ReconstructionDataFormatsLinkDef.h +++ b/DataFormats/Reconstruction/src/ReconstructionDataFormatsLinkDef.h @@ -18,6 +18,7 @@ #pragma link C++ class o2::track::TrackParCov + ; #pragma link C++ class o2::BaseCluster < float > +; #pragma link C++ class o2::dataformats::TrackTPCITS + ; +#pragma link C++ class o2::dataformats::MatchInfoTOF + ; #pragma link C++ class o2::dataformats::Vertex < int > +; #pragma link C++ class o2::dataformats::Vertex < o2::dataformats::TimeStamp < int >> +; diff --git a/Detectors/GlobalTracking/CMakeLists.txt b/Detectors/GlobalTracking/CMakeLists.txt index a6418cbeaa703..b31d81ca164d4 100644 --- a/Detectors/GlobalTracking/CMakeLists.txt +++ b/Detectors/GlobalTracking/CMakeLists.txt @@ -4,10 +4,12 @@ O2_SETUP(NAME ${MODULE_NAME}) set(SRCS src/MatchTPCITS.cxx + src/MatchTOF.cxx ) set(HEADERS include/${MODULE_NAME}/MatchTPCITS.h + include/${MODULE_NAME}/MatchTOF.h ) set(LINKDEF src/GlobalTrackingLinkDef.h) diff --git a/Detectors/GlobalTracking/src/GlobalTrackingLinkDef.h b/Detectors/GlobalTracking/src/GlobalTrackingLinkDef.h index 12a81052221e1..1ed286e3ea7ea 100644 --- a/Detectors/GlobalTracking/src/GlobalTrackingLinkDef.h +++ b/Detectors/GlobalTracking/src/GlobalTrackingLinkDef.h @@ -15,6 +15,7 @@ #pragma link off all functions; #pragma link C++ class o2::globaltracking::MatchTPCITS + ; +#pragma link C++ class o2::globaltracking::MatchTOF + ; #pragma link C++ class o2::globaltracking::timeBracket + ; #pragma link C++ class o2::globaltracking::TrackLocTPC + ; #pragma link C++ class o2::globaltracking::TrackLocITS + ; diff --git a/cmake/O2Dependencies.cmake b/cmake/O2Dependencies.cmake index 947c36ba969db..aab5f5b3a0cf9 100644 --- a/cmake/O2Dependencies.cmake +++ b/cmake/O2Dependencies.cmake @@ -2100,12 +2100,14 @@ o2_define_bucket( data_format_reconstruction_bucket data_format_common_bucket data_format_TPC_bucket + data_format_TOF_bucket its_reconstruction_bucket data_format_itsmft_bucket common_field_bucket detectors_base_bucket its_base_bucket tpc_base_bucket + tof_base_bucket data_parameters_bucket common_utils_bucket common_math_bucket @@ -2117,9 +2119,11 @@ o2_define_bucket( DataFormatsITSMFT DetectorsBase DataFormatsTPC + DataFormatsTOF DataFormatsParameters ITSBase TPCBase + TOFBase CommonUtils MathUtils Field From b879a035c6382e0b71dfe066ba42978cacb5b72c Mon Sep 17 00:00:00 2001 From: zampolli Date: Thu, 28 Jun 2018 17:15:11 +0200 Subject: [PATCH 02/39] Adding classes for TOF matching --- .../ReconstructionDataFormats/MatchInfoTOF.h | 43 +++ .../Reconstruction/src/MatchInfoTOF.cxx | 18 ++ .../include/GlobalTracking/MatchTOF.h | 148 +++++++++++ Detectors/GlobalTracking/src/MatchTOF.cxx | 248 ++++++++++++++++++ 4 files changed, 457 insertions(+) create mode 100644 DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h create mode 100644 DataFormats/Reconstruction/src/MatchInfoTOF.cxx create mode 100644 Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h create mode 100644 Detectors/GlobalTracking/src/MatchTOF.cxx diff --git a/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h b/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h new file mode 100644 index 0000000000000..cb4d03c28a023 --- /dev/null +++ b/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h @@ -0,0 +1,43 @@ +// Copyright CERN and copyright holders of ALICE O2. This software is +// distributed under the terms of the GNU General Public License v3 (GPL +// Version 3), copied verbatim in the file "COPYING". +// +// See http://alice-o2.web.cern.ch/license for full licensing information. +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +/// \file Cluster.h +/// \brief Definition of the TOF cluster + +#ifndef ALICEO2_MATCHINFOTOF_H +#define ALICEO2_MATCHINFOTOF_H + +namespace o2 +{ +namespace dataformats +{ + +class MatchInfoTOF +{ + public: + void setTOFClIndex(int index) { mTOFClIndex = index; } + int getTOFClIndex() const { return mTOFClIndex; } + + void setTrackIndex(int index) { mTrackIndex = index; } + int getTrackIndex() const { return mTrackIndex; } + + void setChi2(int chi2) { mChi2 = chi2; } + int getChi2() const { return mChi2; } + + private: + int mTOFClIndex; // index of the TOF cluster used for the matching + int mTrackIndex; // index of the track used for the matching + float mChi2; // chi2 of the pair track-TOFcluster + + // ClassDefNV(MatchInfoTOF, 1); +}; +} +} +#endif diff --git a/DataFormats/Reconstruction/src/MatchInfoTOF.cxx b/DataFormats/Reconstruction/src/MatchInfoTOF.cxx new file mode 100644 index 0000000000000..7c4b6eb63c357 --- /dev/null +++ b/DataFormats/Reconstruction/src/MatchInfoTOF.cxx @@ -0,0 +1,18 @@ +// Copyright CERN and copyright holders of ALICE O2. This software is +// distributed under the terms of the GNU General Public License v3 (GPL +// Version 3), copied verbatim in the file "COPYING". +// +// See http://alice-o2.web.cern.ch/license for full licensing information. +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +/// \file Cluster.cxx +/// \brief Implementation of the TOF cluster + +#include "ReconstructionDataFormats/MatchInfoTOF.h" + +using namespace o2::dataformats; + +//ClassImp(o2::dataformats::MatchInfoTOF); diff --git a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h new file mode 100644 index 0000000000000..1320f33e07937 --- /dev/null +++ b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h @@ -0,0 +1,148 @@ +// Copyright CERN and copyright holders of ALICE O2. This software is +// distributed under the terms of the GNU General Public License v3 (GPL +// Version 3), copied verbatim in the file "COPYING". +// +// See http://alice-o2.web.cern.ch/license for full licensing information. +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +/// \file MatchTOF.h +/// \brief Class to perform TOF matching to global tracks +/// \author Francesco.Noferini@cern.ch, Chiara.Zampolli@cern.ch + +#ifndef ALICEO2_GLOBTRACKING_MATCHTOF_ +#define ALICEO2_GLOBTRACKING_MATCHTOF_ + +#define _ALLOW_DEBUG_TREES_ // to allow debug and control tree output + +#include +#include +#include +#include +#include +#include "ReconstructionDataFormats/Track.h" +#include "ReconstructionDataFormats/TrackTPCITS.h" +#include "ReconstructionDataFormats/MatchInfoTOF.h" +#include "CommonDataFormat/EvIndex.h" +#include "SimulationDataFormat/MCCompLabel.h" +#include "CommonUtils/TreeStreamRedirector.h" +#include "DataFormatsTOF/Cluster.h" + +class TTree; + +namespace o2 +{ + +namespace dataformats +{ +template +class MCTruthContainer; +} + +namespace globaltracking +{ + +class MatchTOF +{ + public: + ///< perform matching for provided input + void run(); + + ///< perform all initializations + void init(); + + ///< set tree/chain containing tracks + void setInputTreeTracks(TTree* tree) { mInputTreeTracks = tree; } + + ///< set tree/chain containing TOF clusters + void setInputTreeTOFClusters(TTree* tree) { mTreeTOFClusters = tree; } + + ///< set output tree to write matched tracks + void setOutputTree(TTree* tr) { mOutputTree = tr; } + + ///< set input branch names for the input from the tree + void setTrackBranchName(const std::string& nm) { mTracksBranchName = nm; } + void setTOFClusterBranchName(const std::string& nm) { mTOFClusterBranchName = nm; } + void setTOFMCTruthBranchName(const std::string& nm) { mTOFMCTruthBranchName = nm; } + void setOutTracksBranchName(const std::string& nm) { mOutTracksBranchName = nm; } + + ///< get input branch names for the input from the tree + const std::string& getTracksBranchName() const { return mTracksBranchName; } + const std::string& getTOFClusterBranchName() const { return mTOFClusterBranchName; } + const std::string& getTOFMCTruthBranchName() const { return mTOFMCTruthBranchName; } + + ///< print settings + void print() const; + void printCandidatesTOF() const; + + ///< set time tolerance on track-TOF times comparison + void setTimeTolerance(float val) { mTimeTolerance = val; } + ///< get tolerance on track-TOF times comparison + float getTimeTolerance() const { return mTimeTolerance; } + + ///< set space tolerance on track-TOF times comparison // this in the old AliRoot was the TOF matching window + void setSpaceTolerance(float val) { mSpaceTolerance = val; } + ///< get tolerance on track-TOF times comparison + float getSpaceTolerance() const { return mSpaceTolerance; } + + private: + void attachInputTrees(); + bool prepareTracks(); + bool loadTracksNextChunk(); + void loadTracksChunk(int chunk); + bool loadTOFClustersNextChunk(); + void loadTOFClustersChunk(int chunk); + + void doMatching(int sec); + void selectBestMatches(); + + //================================================================ + + // Data members + + bool mInitDone = false; ///< flag init already done + + int mCurrTracksTreeEntry = -1; ///< current tracks tree entry loaded to memory + int mCurrTOFClustersTreeEntry = -1; ///< current TOF clusters tree entry loaded to memory + + bool mMCTruthON = false; ///< flag availability of MC truth + + ///========== Parameters to be set externally, e.g. from CCDB ==================== + + // to be done later + + float mTimeTolerance = 1e3; ///>>------ these are input arrays which should not be modified by the matching code + // since this info is provided by external device + std::vector* mTracksArrayInp = nullptr; ///< input tracks + + std::vector* mTOFClustersArrayInp = nullptr; ///< input TOF clusters + + o2::dataformats::MCTruthContainer* mTOFTrkLabels = nullptr; ///< input TOF Track MC labels + + /// <<<----- + + /// mMatchedTracks; + + std::string mTracksBranchName = "TPCITS"; ///< name of branch containing input matched tracks + std::string mTOFClusterBranchName = "TOFCluster"; ///< name of branch containing input ITS clusters + std::string mTOFMCTruthBranchName = "TOFClusterMCTruth"; ///< name of branch containing ITS MC labels + std::string mOutTracksBranchName = "TOFMatchInfo"; ///< name of branch containing output matched tracks + + TStopwatch mTimerTot; + ClassDefNV(MatchTOF, 1); +}; +} // namespace globaltracking +} // namespace o2 + +#endif diff --git a/Detectors/GlobalTracking/src/MatchTOF.cxx b/Detectors/GlobalTracking/src/MatchTOF.cxx new file mode 100644 index 0000000000000..9bfe97aae3a06 --- /dev/null +++ b/Detectors/GlobalTracking/src/MatchTOF.cxx @@ -0,0 +1,248 @@ +// Copyright CERN and copyright holders of ALICE O2. This software is +// distributed under the terms of the GNU General Public License v3 (GPL +// Version 3), copied verbatim in the file "COPYING". +// +// See http://alice-o2.web.cern.ch/license for full licensing information. +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. +#include +#include + +#include "FairLogger.h" +#include "Field/MagneticField.h" +#include "Field/MagFieldFast.h" +#include "TOFBase/Geo.h" + +#include "SimulationDataFormat/MCTruthContainer.h" + +#include "DetectorsBase/Propagator.h" + +#include "MathUtils/Cartesian3D.h" +#include "MathUtils/Utils.h" +#include "CommonConstants/MathConstants.h" +#include "CommonConstants/PhysicsConstants.h" +#include "DetectorsBase/GeometryManager.h" + +#include +#include +#include +#include +#include "DataFormatsParameters/GRPObject.h" + +#include "GlobalTracking/MatchTOF.h" + +using namespace o2::globaltracking; + +ClassImp(MatchTOF); + +//______________________________________________ +void MatchTOF::run() +{ + ///< running the matching + + if (!mInitDone) { + LOG(FATAL) << "init() was not done yet" << FairLogger::endl; + } + + mTimerTot.Start(); + + prepareTracks(); + for (int sec = o2::constants::math::NSectors; sec--;) { + doMatching(sec); + } + if (0) { // enabling this creates very verbose output + mTimerTot.Stop(); + printCandidatesTOF(); + mTimerTot.Start(false); + } + + selectBestMatches(); + + mTimerTot.Stop(); + + printf("Timing:\n"); + printf("Total: "); + mTimerTot.Print(); +} + +//______________________________________________ +void MatchTOF::init() +{ + ///< initizalizations + + if (mInitDone) { + LOG(ERROR) << "Initialization was already done" << FairLogger::endl; + return; + } + + attachInputTrees(); + + // create output branch + if (mOutputTree) { + mOutputTree->Branch(mOutTracksBranchName.data(), &mMatchedTracks); + LOG(INFO) << "Matched tracks will be stored in " << mOutTracksBranchName << " branch of tree " + << mOutputTree->GetName() << FairLogger::endl; + } else { + LOG(ERROR) << "Output tree is not attached, matched tracks will not be stored" << FairLogger::endl; + } + + mInitDone = true; + + { + mTimerTot.Stop(); + mTimerTot.Reset(); + } + + print(); +} + +//______________________________________________ +void MatchTOF::print() const +{ + ///< print the settings + + printf("\n****** component for the matching of tracks to TF clusters ******\n"); + if (!mInitDone) { + printf("init is not done yet\n"); + return; + } + + printf("MC truth: %s\n", mMCTruthON ? "on" : "off"); + printf("Time tolerance: %.3f\n", mTimeTolerance); + printf("Space tolerance: %.3f\n", mSpaceTolerance); + + printf("**********************************************************************\n"); +} + +//______________________________________________ +void MatchTOF::printCandidatesTOF() const +{ + ///< print the candidates for the matching +} + +//______________________________________________ +void MatchTOF::attachInputTrees() +{ + ///< attaching the input tree + + if (!mInputTreeTracks) { + LOG(FATAL) << "Input tree with tracks is not set" << FairLogger::endl; + } + + if (!mTreeTOFClusters) { + LOG(FATAL) << "TOF clusters data input tree is not set" << FairLogger::endl; + } + + // input tracks + + if (!mInputTreeTracks->GetBranch(mTracksBranchName.data())) { + LOG(FATAL) << "Did not find tracks branch " << mTracksBranchName << " in the input tree" << FairLogger::endl; + } + mInputTreeTracks->SetBranchAddress(mTracksBranchName.data(), &mTracksArrayInp); + LOG(INFO) << "Attached tracks " << mTracksBranchName << " branch with " << mInputTreeTracks->GetEntries() + << " entries" << FairLogger::endl; + + // input TOF clusters + + if (!mTreeTOFClusters->GetBranch(mTOFClusterBranchName.data())) { + LOG(FATAL) << "Did not find TOF clusters branch " << mTOFClusterBranchName << " in the input tree" + << FairLogger::endl; + } + mTreeTOFClusters->SetBranchAddress(mTOFClusterBranchName.data(), &mTOFClustersArrayInp); + LOG(INFO) << "Attached TOF clusters " << mTOFClusterBranchName << " branch with " << mTreeTOFClusters->GetEntries() + << " entries" << FairLogger::endl; + + // is there MC info available ? + if (mTreeTOFClusters->GetBranch(mTOFMCTruthBranchName.data())) { + mTreeTOFClusters->SetBranchAddress(mTOFMCTruthBranchName.data(), &mTOFTrkLabels); + LOG(INFO) << "Found TOF Clusters MCLabels branch " << mTOFMCTruthBranchName << FairLogger::endl; + } + + mMCTruthON = mTOFTrkLabels; + mCurrTracksTreeEntry = -1; + mCurrTOFClustersTreeEntry = -1; +} + +//______________________________________________ +bool MatchTOF::prepareTracks() +{ + ///< prepare the tracks that we want to match to TOF + + pipo if (!loadTracksNextChunk()) + { + return false; + } + + int ntr = mTracksArrayInp->size(); + + for (int it = 0; it < ntr; it++) { + o2::dataformats::TrackTPCITS& trcOrig = (*mTracksArrayInp)[it]; + } +} + +//_____________________________________________________ +bool MatchTOF::loadTracksNextChunk() +{ + ///< load next chunk of tracks to be matched to TOF + while (++mCurrTracksTreeEntry < mInputTreeTracks->GetEntries()) { + mInputTreeTracks->GetEntry(mCurrTracksTreeEntry); + LOG(DEBUG) << "Loading tracks entry " << mCurrTracksTreeEntry << " -> " << mTracksArrayInp->size() + << " tracks" << FairLogger::endl; + if (!mTracksArrayInp->size()) { + continue; + } + return true; + } + --mCurrTracksTreeEntry; + return false; +} +//______________________________________________ +void MatchTOF::loadTracksChunk(int chunk) +{ + ///< load the next chunk of tracks to be matched to TOF (chunk = timeframe? to be checked) + + // load single entry from tracks tree + if (mCurrTracksTreeEntry != chunk) { + mInputTreeTracks->GetEntry(mCurrTracksTreeEntry = chunk); + } +} + +//______________________________________________ +bool MatchTOF::loadTOFClustersNextChunk() +{ + ///< load next chunk of clusters to be matched to TOF + while (++mCurrTOFClustersTreeEntry < mTreeTOFClusters->GetEntries()) { + mTreeTOFClusters->GetEntry(mCurrTOFClustersTreeEntry); + LOG(DEBUG) << "Loading TOF clusters entry " << mCurrTOFClustersTreeEntry << " -> " << mTOFClustersArrayInp->size() + << " tracks" << FairLogger::endl; + if (!mTOFClustersArrayInp->size()) { + continue; + } + return true; + } + --mCurrTOFClustersTreeEntry; + return false; +} +//______________________________________________ +void MatchTOF::loadTOFClustersChunk(int chunk) +{ + ///< load the next chunk of TOF clusters for the matching (chunk = timeframe? to be checked) + + // load single entry from TOF clusters tree + if (mCurrTOFClustersTreeEntry != chunk) { + mTreeTOFClusters->GetEntry(mCurrTOFClustersTreeEntry = chunk); + } +} +//______________________________________________ +void MatchTOF::doMatching(int sec) +{ + ///< do the real matching +} + +//______________________________________________ +void MatchTOF::selectBestMatches() +{ + ///< define the track-TOFcluster pair +} From 5c0c6c0da585f1270e25ce3c498de569db67178a Mon Sep 17 00:00:00 2001 From: zampolli Date: Mon, 2 Jul 2018 17:29:54 +0200 Subject: [PATCH 03/39] Further progress on TOF matching --- .../include/GlobalTracking/MatchTOF.h | 43 ++++++- Detectors/GlobalTracking/src/MatchTOF.cxx | 115 +++++++++++++++++- 2 files changed, 152 insertions(+), 6 deletions(-) diff --git a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h index 1320f33e07937..14b1be1662970 100644 --- a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h +++ b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h @@ -44,8 +44,23 @@ class MCTruthContainer; namespace globaltracking { +///< original track in the currently loaded TPC-ITS reco output +struct TrackLocTPCITS : public o2::track::TrackParCov { + o2::dataformats::EvIndex source; ///< track origin id + timeBracket timeBins; ///< bracketing time-bins + float zMin = 0; // min possible Z of this track + float zMax = 0; // max possible Z of this track + int matchID = MinusOne; ///< entry (none if MinusOne) of TOF matchTOF struct in the mMatchesTOF + TrackLocTPCITS(const o2::track::TrackParCov& src, int tch, int tid) : o2::track::TrackParCov(src), source(tch, tid) {} + TrackLocTPCITS() = default; + ClassDefNV(TrackLocTPCITS, 1); +}; + class MatchTOF { + using Geo = o2::tof::Geo; + using Cluster = o2::tof::Cluster; + public: ///< perform matching for provided input void run(); @@ -94,9 +109,10 @@ class MatchTOF void loadTracksChunk(int chunk); bool loadTOFClustersNextChunk(); void loadTOFClustersChunk(int chunk); - + void doMatching(int sec); void selectBestMatches(); + bool propagateToRefX(o2::track::TrackParCov& trc); //================================================================ @@ -104,6 +120,8 @@ class MatchTOF bool mInitDone = false; ///< flag init already done + float mXRef = Geo::RMIN; ///< reference radius to propage tracks for matching + int mCurrTracksTreeEntry = -1; ///< current tracks tree entry loaded to memory int mCurrTOFClustersTreeEntry = -1; ///< current TOF clusters tree entry loaded to memory @@ -125,12 +143,28 @@ class MatchTOF // since this info is provided by external device std::vector* mTracksArrayInp = nullptr; ///< input tracks - std::vector* mTOFClustersArrayInp = nullptr; ///< input TOF clusters + std::vector* mTOFClustersArrayInp = nullptr; ///< input TOF clusters + + o2::dataformats::MCTruthContainer* mTracksLabels = nullptr; ///< input TPC Track MC labels + + o2::dataformats::MCTruthContainer* mTOFClusLabels = nullptr; ///< input TOF clusters MC labels + std::vector mTracksLblWork; /// mTTOFClusLblWork; ///* mTOFTrkLabels = nullptr; ///< input TOF Track MC labels /// <<<----- + /// mTracksWork; /// mTOFClusWork; ///, o2::constants::math::NSectors> mTracksSectIndexCache; + ///< per sector indices of TOF cluster entry in mTOFClusWork + std::array, o2::constants::math::NSectors> mTOFClusSectIndexCache; + + + /// mMatchedTracks; @@ -139,6 +173,9 @@ class MatchTOF std::string mTOFMCTruthBranchName = "TOFClusterMCTruth"; ///< name of branch containing ITS MC labels std::string mOutTracksBranchName = "TOFMatchInfo"; ///< name of branch containing output matched tracks + ///----------- aux stuff --------------/// + static constexpr float MaxSnp = 0.85; // max snp of ITS or TPC track at xRef to be matched + TStopwatch mTimerTot; ClassDefNV(MatchTOF, 1); }; diff --git a/Detectors/GlobalTracking/src/MatchTOF.cxx b/Detectors/GlobalTracking/src/MatchTOF.cxx index 9bfe97aae3a06..b8eb492aca57b 100644 --- a/Detectors/GlobalTracking/src/MatchTOF.cxx +++ b/Detectors/GlobalTracking/src/MatchTOF.cxx @@ -34,6 +34,7 @@ #include "GlobalTracking/MatchTOF.h" using namespace o2::globaltracking; +using timeEst = o2::dataformats::TimeStampWithError; ClassImp(MatchTOF); @@ -49,6 +50,7 @@ void MatchTOF::run() mTimerTot.Start(); prepareTracks(); + prepareTOFClusters(); for (int sec = o2::constants::math::NSectors; sec--;) { doMatching(sec); } @@ -156,11 +158,11 @@ void MatchTOF::attachInputTrees() // is there MC info available ? if (mTreeTOFClusters->GetBranch(mTOFMCTruthBranchName.data())) { - mTreeTOFClusters->SetBranchAddress(mTOFMCTruthBranchName.data(), &mTOFTrkLabels); + mTreeTOFClusters->SetBranchAddress(mTOFMCTruthBranchName.data(), &mTOFClusLabels); LOG(INFO) << "Found TOF Clusters MCLabels branch " << mTOFMCTruthBranchName << FairLogger::endl; } - mMCTruthON = mTOFTrkLabels; + mMCTruthON = mTOFClusLabels; mCurrTracksTreeEntry = -1; mCurrTOFClustersTreeEntry = -1; } @@ -170,16 +172,101 @@ bool MatchTOF::prepareTracks() { ///< prepare the tracks that we want to match to TOF - pipo if (!loadTracksNextChunk()) + if (!loadTracksNextChunk()) { return false; } int ntr = mTracksArrayInp->size(); + // copy the track params, propagate to reference X and build sector tables + mTracksWork.clear(); + mTracksWork.reserve(ntr); + if (mMCTruthON) { + mTracksLblWork.clear(); + mTracksLblWork.reserve(ntr); + } + for (int it = 0; it < ntr; it++) { o2::dataformats::TrackTPCITS& trcOrig = (*mTracksArrayInp)[it]; + + // create working copy of track param + mTracksWork.emplace_back(static_cast(trcOrig), mCurrTPCTracksTreeEntry, it); + auto& trc = mTracksWork.back(); + // propagate to matching Xref + if (!propagateToRefX(trc)) { + mTracksWork.pop_back(); // discard track whose propagation to mXRef failed + continue; + } + if (mMCTruthON) { + mTracksLblWork.emplace_back(mTracksLabels->getLabels(it)[0]); + } + // cache work track index + mTracksSectIndexCache[o2::utils::Angle2Sector(trc.getAlpha())].push_back(mTracksWork.size() - 1); } + + // sort tracks in each sector according to their time (increasing in time) + for (int sec = o2::constants::math::NSectors; sec--;) { + auto& indexCache = mTracksSectIndexCache[sec]; + LOG(INFO) << "Sorting sector" << sec << " | " << indexCache.size() << " tracks" << FairLogger::endl; + if (!indexCache.size()) + continue; + std::sort(indexCache.begin(), indexCache.end(), [this](int a, int b) { + auto& trcA = mTracksWork[a]; + auto& trcB = mTracksWork[b]; + return (trcA.getTimeMUS() - trcB.getTimeMUS()) < 0.; + }); + } // loop over tracks of single sector + + return true; +} +//______________________________________________ +bool MatchTOF::prepareTOFClusters() +{ + ///< prepare the tracks that we want to match to TOF + + if (!loadTOFClustersNextChunk()) + { + return false; + } + + int ntr = mTOFClustersArrayInp->size(); + + // copy the track params, propagate to reference X and build sector tables + mTOFClusWork.clear(); + mTOFClusWork.reserve(ntr); + if (mMCTruthON) { + mTOFClusLblWork.clear(); + mTOFClusLblWork.reserve(ntr); + } + + for (int it = 0; it < ntr; it++) { + Cluster& clOrig = (*mTOFClustersArrayInp)[it]; + + // create working copy of track param + mTOFClusWork.emplace_back(clOrig), mCurrTOFClustersTreeEntry, it); + auto& cl = mTOFClusWork.back(); + if (mMCTruthON) { + mTOFClusLblWork.emplace_back(mTOFClusLabels->getLabels(it)[0]); + } + // cache work track index + mTOFClusSectIndexCache[o2::utils::Angle2Sector(cl.getAlpha())].push_back(mTOFClusWork.size() - 1); + } + + // sort tracks in each sector according to their time (increasing in time) + for (int sec = o2::constants::math::NSectors; sec--;) { + auto& indexCache = mTOFClusSectIndexCache[sec]; + LOG(INFO) << "Sorting sector" << sec << " | " << indexCache.size() << " TOF clusters" << FairLogger::endl; + if (!indexCache.size()) + continue; + std::sort(indexCache.begin(), indexCache.end(), [this](int a, int b) { + auto& clA = mTOFClusWork[a]; + auto& clB = mTOFClusWork[b]; + return (clA.getTime() - clB.getTime()) < 0.; + }); + } // loop over tracks of single sector + + return true; } //_____________________________________________________ @@ -246,3 +333,25 @@ void MatchTOF::selectBestMatches() { ///< define the track-TOFcluster pair } + +//______________________________________________ +bool MatchTPCITS::propagateToRefX(o2::track::TrackParCov& trc) +{ + // propagate track to matching reference X + bool refReached = false; + + while (o2::Base::Propagator::Instance()->PropagateToXBxByBz(trc, mXRef, o2::constants::physics::MassPionCharged, MaxSnp, 2., 0.)) { + if (refReached) + break; // RS: tmp + // make sure the track is indeed within the sector defined by alpha + if (fabs(trc.getY()) < mXRef * tan(o2::constants::math::SectorSpanRad / 2)) { + refReached = true; + break; // ok, within + } + auto alphaNew = o2::utils::Angle2Alpha(trc.getPhiPos()); + if (!trc.rotate(alphaNew) != 0) { + break; // failed (RS: check effect on matching tracks to neighbouring sector) + } + } + return refReached && std::abs(trc.getSnp()) < MaxSnp; +} From 83025f22e11655ad875575b79af2c967b4b1b8c2 Mon Sep 17 00:00:00 2001 From: zampolli Date: Tue, 3 Jul 2018 17:16:23 +0200 Subject: [PATCH 04/39] Further changes for TOF matching --- .../ReconstructionDataFormats/MatchInfoTOF.h | 12 +- .../include/GlobalTracking/MatchTOF.h | 14 +- Detectors/GlobalTracking/src/MatchTOF.cxx | 129 +++++++++++++++--- Detectors/TOF/base/src/Geo.cxx | 3 +- 4 files changed, 128 insertions(+), 30 deletions(-) diff --git a/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h b/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h index cb4d03c28a023..4e3faae025cf6 100644 --- a/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h +++ b/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h @@ -18,23 +18,23 @@ namespace o2 { namespace dataformats { - -class MatchInfoTOF + class MatchInfoTOF { public: + + MatchInfoTOF(int indexTOFCl, int indexTrack, float chi2) : mTOFClIndex(indexTOFCl), mTrackIndex(indexTrack), mChi2(chi2); + MatchInfoTOF() = default; void setTOFClIndex(int index) { mTOFClIndex = index; } int getTOFClIndex() const { return mTOFClIndex; } - void setTrackIndex(int index) { mTrackIndex = index; } - int getTrackIndex() const { return mTrackIndex; } - void setChi2(int chi2) { mChi2 = chi2; } int getChi2() const { return mChi2; } private: + int mTOFClIndex; // index of the TOF cluster used for the matching - int mTrackIndex; // index of the track used for the matching float mChi2; // chi2 of the pair track-TOFcluster + // ClassDefNV(MatchInfoTOF, 1); }; diff --git a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h index 14b1be1662970..b2feca12aa60c 100644 --- a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h +++ b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h @@ -112,7 +112,7 @@ class MatchTOF void doMatching(int sec); void selectBestMatches(); - bool propagateToRefX(o2::track::TrackParCov& trc); + bool propagateToRefX(o2::track::TrackParCov& trc, float xRef /*in cm*/, float stepInCm /*in cm*/); //================================================================ @@ -133,7 +133,8 @@ class MatchTOF float mTimeTolerance = 1e3; ///> mMatchedTracksPairs; + + /// mMatchedTracks; + int mNumOfTracks; // number of tracks to be matched + int* mMatchedTracksIndex = nullptr; //[mNumOfTracks] + int mNumOfClusters; // number of clusters to be matched + int* mMatchedClustersIndex = nullptr; //[mNumOfClusters] std::string mTracksBranchName = "TPCITS"; ///< name of branch containing input matched tracks std::string mTOFClusterBranchName = "TOFCluster"; ///< name of branch containing input ITS clusters diff --git a/Detectors/GlobalTracking/src/MatchTOF.cxx b/Detectors/GlobalTracking/src/MatchTOF.cxx index b8eb492aca57b..baac57af6667e 100644 --- a/Detectors/GlobalTracking/src/MatchTOF.cxx +++ b/Detectors/GlobalTracking/src/MatchTOF.cxx @@ -53,6 +53,7 @@ void MatchTOF::run() prepareTOFClusters(); for (int sec = o2::constants::math::NSectors; sec--;) { doMatching(sec); + selectBestMatches(); } if (0) { // enabling this creates very verbose output mTimerTot.Stop(); @@ -60,8 +61,6 @@ void MatchTOF::run() mTimerTot.Start(false); } - selectBestMatches(); - mTimerTot.Stop(); printf("Timing:\n"); @@ -177,24 +176,32 @@ bool MatchTOF::prepareTracks() return false; } - int ntr = mTracksArrayInp->size(); - + mNumOfTracks = mTracksArrayInp->size(); + if (mNumOfTracks == 0) return; // no tracks to be matched + if (mMatchedTracksIndex) delete[] mMatchedTracksIndex; + mMatchedTracksIndex = new int[mNumOfTracks]; + std::fill_n(mMatchedTracksIndex, mNumOfTracks, -1); // initializing all to -1 + // copy the track params, propagate to reference X and build sector tables mTracksWork.clear(); - mTracksWork.reserve(ntr); + mTracksWork.reserve(mNumOfTracks); if (mMCTruthON) { mTracksLblWork.clear(); - mTracksLblWork.reserve(ntr); + mTracksLblWork.reserve(mNumOfTracks); + } + for (int sec = o2::constants::math::NSectors; sec--;) { + mTracksSectIndexCache[sec].clear(); + mTracksSectIndexCache[sec].reserve(100 + 1.2 * mNumOfTracks / o2::constants::math::NSectors); } - - for (int it = 0; it < ntr; it++) { - o2::dataformats::TrackTPCITS& trcOrig = (*mTracksArrayInp)[it]; + + for (int it = 0; it < mNumOfTracks; it++) { + o2::dataformats::TrackTPCITS& trcOrig = (*mTracksArrayInp)[it]; // TODO: check if we cannot directly use the o2::track::TrackParCov class instead of o2::dataformats::TrackTPCITS, and then avoid the casting below // create working copy of track param mTracksWork.emplace_back(static_cast(trcOrig), mCurrTPCTracksTreeEntry, it); auto& trc = mTracksWork.back(); // propagate to matching Xref - if (!propagateToRefX(trc)) { + if (!propagateToRefX(trc, mXRef, 2)) { mTracksWork.pop_back(); // discard track whose propagation to mXRef failed continue; } @@ -205,7 +212,7 @@ bool MatchTOF::prepareTracks() mTracksSectIndexCache[o2::utils::Angle2Sector(trc.getAlpha())].push_back(mTracksWork.size() - 1); } - // sort tracks in each sector according to their time (increasing in time) + // sort tracks in each sector according to their time (increasing in time) for (int sec = o2::constants::math::NSectors; sec--;) { auto& indexCache = mTracksSectIndexCache[sec]; LOG(INFO) << "Sorting sector" << sec << " | " << indexCache.size() << " tracks" << FairLogger::endl; @@ -214,7 +221,7 @@ bool MatchTOF::prepareTracks() std::sort(indexCache.begin(), indexCache.end(), [this](int a, int b) { auto& trcA = mTracksWork[a]; auto& trcB = mTracksWork[b]; - return (trcA.getTimeMUS() - trcB.getTimeMUS()) < 0.; + return ((trcA.getTimeMUS().getTimeStamp() - mSigmaTimeCut*trcA.getTimeMUS().getTimeStampError()) - (trcB.getTimeMUS().getTimeStamp() - mSigmaTimeCut*trcB.getTimeMUS().getTimeStampError()) < 0.; }); } // loop over tracks of single sector @@ -230,17 +237,25 @@ bool MatchTOF::prepareTOFClusters() return false; } - int ntr = mTOFClustersArrayInp->size(); + mNumOfClusters = mTOFClustersArrayInp->size(); + if (mNumOfClusters == 0) return; // no clusters to be matched + if (mMatchedClustersIndex) delete[] mMatchedClustersIndex; + mMatchedClustersIndex = new int[mNumOfClusters]; + std::fill_n(mMatchedClustersIndex, mNumOfClusters, -1); // initializing all to -1 // copy the track params, propagate to reference X and build sector tables mTOFClusWork.clear(); - mTOFClusWork.reserve(ntr); + mTOFClusWork.reserve(mNumOfClusters); if (mMCTruthON) { mTOFClusLblWork.clear(); - mTOFClusLblWork.reserve(ntr); + mTOFClusLblWork.reserve(mNumOfClusters); + } + for (int sec = o2::constants::math::NSectors; sec--;) { + mTOFClusSectIndexCache[sec].clear(); + mTOFClusSectIndexCache[sec].reserve(100 + 1.2 * mNumOfClusters / o2::constants::math::NSectors); } - for (int it = 0; it < ntr; it++) { + for (int it = 0; it < mNumOfClusters; it++) { Cluster& clOrig = (*mTOFClustersArrayInp)[it]; // create working copy of track param @@ -325,22 +340,96 @@ void MatchTOF::loadTOFClustersChunk(int chunk) //______________________________________________ void MatchTOF::doMatching(int sec) { - ///< do the real matching + ///< do the real matching per sector + + mMatchedTracksPairs.clear(); // new sector + + auto& cacheTOF = mTOFClusSectIndexCache[sec]; // array of cached TOF cluster indices for this sector; reminder: they are ordered in time! + auto& cacheTrk = mTracksSectIndexCache[sec]; // array of cached tracks indices for this sector; reminder: they are ordered in time! + int nTracks = cacheTrk.size(), nTOFCls = cacheTOF.size(); + if (!nTracks || !nTOFCls) { + LOG(INFO) << "Matching sector " << sec << " : N tracks:" << nTracks << " TOF:" << nTOFCls << " in sector " + << sec << FairLogger::endl; + return; + } + int itof0 = 0; // starting index in TOF clusters for matching of the track + int detId[2][5]; // at maximum one track can fall in 2 strips during the propagation; the second dimention of the array is the TOF det index + float deltaPos[2][3]; // at maximum one track can fall in 2 strips during the propagation; the second dimention of the array is the residuals + for (int itrk = 0; itrk < cacheTrk.size(); itrk++) { + int nPropagatedInStrip = 0; // how many strips were hit during the propagation + auto& trefTrk = mTracksWork[cacheTrk[itrk]]; + float minTrkTime = (trefTrk.getTimeMUS().getTimeStamp() - mSigmaTimeCut*trefTrk.getTimeMUS().getTimeStampError())*1.E6; // minimum time in ps + float maxTrkTime = (trefTrk.getTimeMUS().getTimeStamp() + mSigmaTimeCut*trefTrk.getTimeMUS().getTimeStampError())*1.E6; // maximum time in ps + int istep = 1; // number of steps + float step = 0.1; // step size in cm + while (propagateToRefX(trefTrk, mXRef+istep*step, step) && nPropagatedInStrip <2 && mXRef+istep*step < Geo::RMAX){ + float pos[3] = {trefTrk.getX(), trefTrk.getY(), trefTrk.getZ()}; + Geo::getPadDxDyDz(pos, detId[nPropagatedInStrip], deltaPos[nPropagatedInStrip]); + // check if after the propagation we are in a TOF strip + if (detId[2] != -1) { // we ended in a TOF strip + nPropagatedInStrip++; + } + } + if (nPropagatedInStrip == 0) continue; // the track never hit a TOF strip during the propagation + for (auto itof = itof0; itof < nTOFCls; itof++) { + auto& trefTOF = mTOFClusWork[cacheTOF[itof]]; + // compare the times of the track and the TOF clusters - remember that they both are ordered in time! + if (trefTOF.getTime() < minTrkTime) { + itof0 = itof; + continue; + } + if (trefTOF.getTime() > maxTrkTime) { // no more TOF clusters can be matched to this track + break; + } + int mainChannel = trefTOF.getMainContributingChannel(); + int indices[5]; + Geo::getVolumeIndices(mainChannel, indices); + for (auto iPropagation = 0; iPropagation < nPropagatedInStrip; iPropagation++){ + if (indices[0] != detId[iPropagation][0]) continue; + if (indices[1] != detId[iPropagation][1]) continue; + if (indices[2] != detId[iPropagation][2]) continue; + float resX = deltaPos[iPropagation][0] - (indices[4] - detId[iPropagation][4])*Geo::XPAD; // readjusting the residuals due to the fact that the propagation fell in a pad that was not exactly the one of the cluster + float resZ = deltaPos[iPropagation][2] - (indices[3] - detId[iPropagation][3])*Geo::ZPAD; // readjusting the residuals due to the fact that the propagation fell in a pad that was not exactly the one of the cluster + float res = TMath::Sqrt(resX*resX + resZ*resZ); + float chi2 = res; // TODO: take into account also the time! + if (res < mSpaceTolerance) { // matching ok! + mMatchedTracksPairs.push_back(std::make_pair(itrk, MatchInfoTOF(itof, chi2))); // TODO: check if this is correct! + } + } + } + } + return; } //______________________________________________ void MatchTOF::selectBestMatches() { - ///< define the track-TOFcluster pair + ///< define the track-TOFcluster pair per sector + + // first, we sort according to the chi2 + std::sort(mMatchedTracksPairs.begin(), mMatchedTracksPairs.end(), [this](std::pair a, std::pair b) { + return (a.second.getChi2() < b.second.getChi2());}); + for (auto matchingPair = mMatchedTracksPairs.begin(); matchingPair!= mMatchedTracksPairs.end(); matchingPair++) { + if (mMatchedTracksIndex[matchingPair.first] != -1) { // the track was already filled + continue; + } + if (mMatchedClustersIndex[matchingPair.second.getTOFClIndex()] != -1) { // the track was already filled + continue; + } + mMatchedTracksIndex[matchingPair.first] = mMatchedTracks.size(); // index of the MatchInfoTOF correspoding to this track + mMatchedClustersIndex[matchingPair.second.getTOFClIndex()] = mMatchedTracksIndex[matchingPair.first]; // index of the track that was matched to this cluster + mMatchedTracks.pushBack(matchingPair.second); // array of MatchInfoTOF + } + } //______________________________________________ -bool MatchTPCITS::propagateToRefX(o2::track::TrackParCov& trc) + bool MatchTPCITS::propagateToRefX(o2::track::TrackParCov& trc, float xRef, float stepInCm) { // propagate track to matching reference X bool refReached = false; - while (o2::Base::Propagator::Instance()->PropagateToXBxByBz(trc, mXRef, o2::constants::physics::MassPionCharged, MaxSnp, 2., 0.)) { + while (o2::Base::Propagator::Instance()->PropagateToXBxByBz(trc, xRef, o2::constants::physics::MassPionCharged, MaxSnp, stepInCm, 0.)) { if (refReached) break; // RS: tmp // make sure the track is indeed within the sector defined by alpha diff --git a/Detectors/TOF/base/src/Geo.cxx b/Detectors/TOF/base/src/Geo.cxx index 64763f69b19e2..e7b885ed4aa68 100644 --- a/Detectors/TOF/base/src/Geo.cxx +++ b/Detectors/TOF/base/src/Geo.cxx @@ -104,7 +104,7 @@ void Geo::Init() void Geo::getVolumePath(const Int_t* ind, Char_t* path) { //-------------------------------------------------------------------- - // This function returns the colume path of a given pad + // This function returns the volume path of a given pad //-------------------------------------------------------------------- Int_t sector = ind[0]; @@ -633,3 +633,4 @@ void Geo::antiRotate(Float_t* xyz, Double_t rotationAngles[6]) return; } + From e57db0f7d104602ed86843f5250bf897aa8a78f0 Mon Sep 17 00:00:00 2001 From: zampolli Date: Fri, 6 Jul 2018 16:48:06 +0200 Subject: [PATCH 05/39] Taking the TPC track after the outwards propagation --- .../ReconstructionDataFormats/MatchInfoTOF.h | 2 +- .../include/GlobalTracking/MatchTOF.h | 8 ++++++- Detectors/GlobalTracking/src/MatchTOF.cxx | 24 ++++++++++++++++--- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h b/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h index 4e3faae025cf6..01d153de4acb3 100644 --- a/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h +++ b/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h @@ -22,7 +22,7 @@ namespace dataformats { public: - MatchInfoTOF(int indexTOFCl, int indexTrack, float chi2) : mTOFClIndex(indexTOFCl), mTrackIndex(indexTrack), mChi2(chi2); + MatchInfoTOF(int indexTOFCl, float chi2) : mTOFClIndex(indexTOFCl), mChi2(chi2); MatchInfoTOF() = default; void setTOFClIndex(int index) { mTOFClIndex = index; } int getTOFClIndex() const { return mTOFClIndex; } diff --git a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h index b2feca12aa60c..790f3c98fc325 100644 --- a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h +++ b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h @@ -71,6 +71,9 @@ class MatchTOF ///< set tree/chain containing tracks void setInputTreeTracks(TTree* tree) { mInputTreeTracks = tree; } + ///< set tree/chain containing TPC tracks + void setInputTreeTPCTracks(TTree* tree) { mTreeTPCTracks = tree; } + ///< set tree/chain containing TOF clusters void setInputTreeTOFClusters(TTree* tree) { mTreeTOFClusters = tree; } @@ -79,12 +82,14 @@ class MatchTOF ///< set input branch names for the input from the tree void setTrackBranchName(const std::string& nm) { mTracksBranchName = nm; } + void setTPCTrackBranchName(const std::string& nm) { mTPCTrackBranchName = nm; } void setTOFClusterBranchName(const std::string& nm) { mTOFClusterBranchName = nm; } void setTOFMCTruthBranchName(const std::string& nm) { mTOFMCTruthBranchName = nm; } void setOutTracksBranchName(const std::string& nm) { mOutTracksBranchName = nm; } ///< get input branch names for the input from the tree const std::string& getTracksBranchName() const { return mTracksBranchName; } + const std::string& getTPCTrackBranchName() const { return mTPCTrackBranchName; } const std::string& getTOFClusterBranchName() const { return mTOFClusterBranchName; } const std::string& getTOFMCTruthBranchName() const { return mTOFMCTruthBranchName; } @@ -136,6 +141,7 @@ class MatchTOF int mSigmaTimeCut = 3; ///< number of sigmas to cut on time when matching the track to the TOF cluster TTree* mInputTreeTracks = nullptr; ///< input tree for tracks + TTree* mTreeTPCTracks = nullptr; ///< input tree for TPC tracks TTree* mTreeTOFClusters = nullptr; ///< input tree for TOF clusters TTree* mOutputTree = nullptr; ///< output tree for matched tracks @@ -143,7 +149,7 @@ class MatchTOF ///>>>------ these are input arrays which should not be modified by the matching code // since this info is provided by external device std::vector* mTracksArrayInp = nullptr; ///< input tracks - + std::vector* mTPCTracksArrayInp = nullptr; ///< input TPC tracks std::vector* mTOFClustersArrayInp = nullptr; ///< input TOF clusters o2::dataformats::MCTruthContainer* mTracksLabels = nullptr; ///< input TPC Track MC labels diff --git a/Detectors/GlobalTracking/src/MatchTOF.cxx b/Detectors/GlobalTracking/src/MatchTOF.cxx index baac57af6667e..3dcc7cc6aa721 100644 --- a/Detectors/GlobalTracking/src/MatchTOF.cxx +++ b/Detectors/GlobalTracking/src/MatchTOF.cxx @@ -35,6 +35,7 @@ using namespace o2::globaltracking; using timeEst = o2::dataformats::TimeStampWithError; +using evIdx = o2::dataformats::EvIndex; ClassImp(MatchTOF); @@ -132,11 +133,15 @@ void MatchTOF::attachInputTrees() LOG(FATAL) << "Input tree with tracks is not set" << FairLogger::endl; } + if (!mTreeTPCTracks) { + LOG(FATAL) << "TPC tracks data input tree is not set" << FairLogger::endl; + } + if (!mTreeTOFClusters) { LOG(FATAL) << "TOF clusters data input tree is not set" << FairLogger::endl; } - // input tracks + // input tracks (this is the pais of ITS-TPC matches) if (!mInputTreeTracks->GetBranch(mTracksBranchName.data())) { LOG(FATAL) << "Did not find tracks branch " << mTracksBranchName << " in the input tree" << FairLogger::endl; @@ -145,6 +150,15 @@ void MatchTOF::attachInputTrees() LOG(INFO) << "Attached tracks " << mTracksBranchName << " branch with " << mInputTreeTracks->GetEntries() << " entries" << FairLogger::endl; + // actual TPC tracks + + if (!mTreeTPCTracks->GetBranch(mTPCTrackBranchName.data())) { + LOG(FATAL) << "Did not find TPC tracks branch " << mTPCTrackBranchName << " in the input tree" << FairLogger::endl; + } + mTreeTPCTracks->SetBranchAddress(mTPCTrackBranchName.data(), &mTPCTracksArrayInp); + LOG(INFO) << "Attached TPC tracks " << mTPCTrackBranchName << " branch with " << mTreeTPCTracks->GetEntries() + << " entries" << FairLogger::endl; + // input TOF clusters if (!mTreeTOFClusters->GetBranch(mTOFClusterBranchName.data())) { @@ -195,10 +209,14 @@ bool MatchTOF::prepareTracks() } for (int it = 0; it < mNumOfTracks; it++) { - o2::dataformats::TrackTPCITS& trcOrig = (*mTracksArrayInp)[it]; // TODO: check if we cannot directly use the o2::track::TrackParCov class instead of o2::dataformats::TrackTPCITS, and then avoid the casting below + o2::dataformats::TrackTPCITS& trcOrig = (*mTracksArrayInp)[it]; // TODO: check if we cannot directly use the o2::track::TrackParCov class instead of o2::dataformats::TrackTPCITS, and then avoid the casting below; this is the track at the vertex + + evIdx evIdxTPC = trcOrig.getRefTPC(); + int indTPC = evIdx.getIndex(); + o2::TPC::TrackTPC& trcTPCOrig = (*mTPCTracksArrayInp)[indTPC]; // we take the track when it is propagated out // create working copy of track param - mTracksWork.emplace_back(static_cast(trcOrig), mCurrTPCTracksTreeEntry, it); + mTracksWork.emplace_back(static_cast(trcTPCOrig), mCurrTracksTreeEntry, it); auto& trc = mTracksWork.back(); // propagate to matching Xref if (!propagateToRefX(trc, mXRef, 2)) { From 7030ac1ff640e3b8975175741330c6476a6f2970 Mon Sep 17 00:00:00 2001 From: noferini Date: Sat, 7 Jul 2018 10:53:19 +0200 Subject: [PATCH 06/39] fix for compilation --- .../TOF/include/DataFormatsTOF/Cluster.h | 2 + DataFormats/Detectors/TOF/src/Cluster.cxx | 9 ++ .../ReconstructionDataFormats/MatchInfoTOF.h | 2 +- .../include/GlobalTracking/MatchTOF.h | 13 ++- Detectors/GlobalTracking/src/MatchTOF.cxx | 92 +++++++++++++------ .../TOF/reconstruction/src/Clusterer.cxx | 7 ++ cmake/O2Dependencies.cmake | 1 + 7 files changed, 93 insertions(+), 33 deletions(-) diff --git a/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h b/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h index c45567b6c9837..d3d039057b629 100644 --- a/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h +++ b/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h @@ -44,6 +44,8 @@ class Cluster : public o2::BaseCluster ~Cluster() = default; + void SetBaseData(std::int16_t sensid, float x, float y, float z, float sy2, float sz2, float syz); + float getTimeRaw() const { return mTimeRaw; } // Cluster ToF getter void setTimeRaw(float timeRaw) { mTimeRaw = timeRaw; } // Cluster ToF setter float getTime() const { return mTime; } // Cluster ToF getter diff --git a/DataFormats/Detectors/TOF/src/Cluster.cxx b/DataFormats/Detectors/TOF/src/Cluster.cxx index d0d9301463aaa..b5883d00865a6 100644 --- a/DataFormats/Detectors/TOF/src/Cluster.cxx +++ b/DataFormats/Detectors/TOF/src/Cluster.cxx @@ -30,7 +30,16 @@ Cluster::Cluster(std::int16_t sensid, float x, float y, float z, float sy2, floa mR = TMath::Sqrt(x * x + y * y); mPhi = TMath::ATan2(y, x); } +//______________________________________________________________________ +void Cluster::SetBaseData(std::int16_t sensid, float x, float y, float z, float sy2, float sz2, float syz){ + setSensorID(sensid); + setXYZ(x,y,z); + setErrors(sy2,sz2,syz); + // caching R and phi + mR = TMath::Sqrt(x * x + y * y); + mPhi = TMath::ATan2(y, x); +} //______________________________________________________________________ int Cluster::getNumOfContributingChannels() const { diff --git a/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h b/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h index 01d153de4acb3..3b8e71d2e0cd0 100644 --- a/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h +++ b/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h @@ -22,7 +22,7 @@ namespace dataformats { public: - MatchInfoTOF(int indexTOFCl, float chi2) : mTOFClIndex(indexTOFCl), mChi2(chi2); + MatchInfoTOF(int indexTOFCl, float chi2) : mTOFClIndex(indexTOFCl), mChi2(chi2){}; MatchInfoTOF() = default; void setTOFClIndex(int index) { mTOFClIndex = index; } int getTOFClIndex() const { return mTOFClIndex; } diff --git a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h index 790f3c98fc325..ba39a64865baa 100644 --- a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h +++ b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h @@ -28,7 +28,10 @@ #include "CommonDataFormat/EvIndex.h" #include "SimulationDataFormat/MCCompLabel.h" #include "CommonUtils/TreeStreamRedirector.h" +#include "TOFBase/Geo.h" #include "DataFormatsTOF/Cluster.h" +#include "GlobalTracking/MatchTPCITS.h" +#include "DataFormatsTPC/TrackTPC.h" class TTree; @@ -55,7 +58,7 @@ struct TrackLocTPCITS : public o2::track::TrackParCov { TrackLocTPCITS() = default; ClassDefNV(TrackLocTPCITS, 1); }; - + class MatchTOF { using Geo = o2::tof::Geo; @@ -82,14 +85,14 @@ class MatchTOF ///< set input branch names for the input from the tree void setTrackBranchName(const std::string& nm) { mTracksBranchName = nm; } - void setTPCTrackBranchName(const std::string& nm) { mTPCTrackBranchName = nm; } + void setTPCTrackBranchName(const std::string& nm) { mTPCTracksBranchName = nm; } void setTOFClusterBranchName(const std::string& nm) { mTOFClusterBranchName = nm; } void setTOFMCTruthBranchName(const std::string& nm) { mTOFMCTruthBranchName = nm; } void setOutTracksBranchName(const std::string& nm) { mOutTracksBranchName = nm; } ///< get input branch names for the input from the tree const std::string& getTracksBranchName() const { return mTracksBranchName; } - const std::string& getTPCTrackBranchName() const { return mTPCTrackBranchName; } + const std::string& getTPCTracksBranchName() const { return mTPCTracksBranchName;} const std::string& getTOFClusterBranchName() const { return mTOFClusterBranchName; } const std::string& getTOFMCTruthBranchName() const { return mTOFMCTruthBranchName; } @@ -110,6 +113,7 @@ class MatchTOF private: void attachInputTrees(); bool prepareTracks(); + bool prepareTOFClusters(); bool loadTracksNextChunk(); void loadTracksChunk(int chunk); bool loadTOFClustersNextChunk(); @@ -162,7 +166,7 @@ class MatchTOF /// <<<----- /// mTracksWork; /// mTracksWork; /// mTOFClusWork; ///GetBranch(mTPCTrackBranchName.data())) { - LOG(FATAL) << "Did not find TPC tracks branch " << mTPCTrackBranchName << " in the input tree" << FairLogger::endl; + if (!mTreeTPCTracks->GetBranch(mTPCTracksBranchName.data())) { + LOG(FATAL) << "Did not find TPC tracks branch " << mTPCTracksBranchName << " in the input tree" << FairLogger::endl; } - mTreeTPCTracks->SetBranchAddress(mTPCTrackBranchName.data(), &mTPCTracksArrayInp); - LOG(INFO) << "Attached TPC tracks " << mTPCTrackBranchName << " branch with " << mTreeTPCTracks->GetEntries() + mTreeTPCTracks->SetBranchAddress(mTPCTracksBranchName.data(), &mTPCTracksArrayInp); + LOG(INFO) << "Attached TPC tracks " << mTPCTracksBranchName << " branch with " << mTreeTPCTracks->GetEntries() << " entries" << FairLogger::endl; // input TOF clusters @@ -191,7 +191,7 @@ bool MatchTOF::prepareTracks() } mNumOfTracks = mTracksArrayInp->size(); - if (mNumOfTracks == 0) return; // no tracks to be matched + if (mNumOfTracks == 0) return false; // no tracks to be matched if (mMatchedTracksIndex) delete[] mMatchedTracksIndex; mMatchedTracksIndex = new int[mNumOfTracks]; std::fill_n(mMatchedTracksIndex, mNumOfTracks, -1); // initializing all to -1 @@ -212,20 +212,20 @@ bool MatchTOF::prepareTracks() o2::dataformats::TrackTPCITS& trcOrig = (*mTracksArrayInp)[it]; // TODO: check if we cannot directly use the o2::track::TrackParCov class instead of o2::dataformats::TrackTPCITS, and then avoid the casting below; this is the track at the vertex evIdx evIdxTPC = trcOrig.getRefTPC(); - int indTPC = evIdx.getIndex(); + int indTPC = evIdxTPC.getIndex(); o2::TPC::TrackTPC& trcTPCOrig = (*mTPCTracksArrayInp)[indTPC]; // we take the track when it is propagated out // create working copy of track param - mTracksWork.emplace_back(static_cast(trcTPCOrig), mCurrTracksTreeEntry, it); + mTracksWork.emplace_back(trcOrig);//, mCurrTracksTreeEntry, it); auto& trc = mTracksWork.back(); // propagate to matching Xref if (!propagateToRefX(trc, mXRef, 2)) { mTracksWork.pop_back(); // discard track whose propagation to mXRef failed continue; } - if (mMCTruthON) { - mTracksLblWork.emplace_back(mTracksLabels->getLabels(it)[0]); - } + // if (mMCTruthON) { + // mTracksLblWork.emplace_back(mTracksLabels->getLabels(it)[0]); + // } // cache work track index mTracksSectIndexCache[o2::utils::Angle2Sector(trc.getAlpha())].push_back(mTracksWork.size() - 1); } @@ -239,7 +239,7 @@ bool MatchTOF::prepareTracks() std::sort(indexCache.begin(), indexCache.end(), [this](int a, int b) { auto& trcA = mTracksWork[a]; auto& trcB = mTracksWork[b]; - return ((trcA.getTimeMUS().getTimeStamp() - mSigmaTimeCut*trcA.getTimeMUS().getTimeStampError()) - (trcB.getTimeMUS().getTimeStamp() - mSigmaTimeCut*trcB.getTimeMUS().getTimeStampError()) < 0.; + return ((trcA.getTimeMUS().getTimeStamp() - mSigmaTimeCut*trcA.getTimeMUS().getTimeStampError()) - (trcB.getTimeMUS().getTimeStamp() - mSigmaTimeCut*trcB.getTimeMUS().getTimeStampError()) < 0.); }); } // loop over tracks of single sector @@ -256,7 +256,7 @@ bool MatchTOF::prepareTOFClusters() } mNumOfClusters = mTOFClustersArrayInp->size(); - if (mNumOfClusters == 0) return; // no clusters to be matched + if (mNumOfClusters == 0) return false; // no clusters to be matched if (mMatchedClustersIndex) delete[] mMatchedClustersIndex; mMatchedClustersIndex = new int[mNumOfClusters]; std::fill_n(mMatchedClustersIndex, mNumOfClusters, -1); // initializing all to -1 @@ -264,10 +264,10 @@ bool MatchTOF::prepareTOFClusters() // copy the track params, propagate to reference X and build sector tables mTOFClusWork.clear(); mTOFClusWork.reserve(mNumOfClusters); - if (mMCTruthON) { - mTOFClusLblWork.clear(); - mTOFClusLblWork.reserve(mNumOfClusters); - } + // if (mMCTruthON) { + // mTOFClusLblWork.clear(); + // mTOFClusLblWork.reserve(mNumOfClusters); + // } for (int sec = o2::constants::math::NSectors; sec--;) { mTOFClusSectIndexCache[sec].clear(); mTOFClusSectIndexCache[sec].reserve(100 + 1.2 * mNumOfClusters / o2::constants::math::NSectors); @@ -277,13 +277,13 @@ bool MatchTOF::prepareTOFClusters() Cluster& clOrig = (*mTOFClustersArrayInp)[it]; // create working copy of track param - mTOFClusWork.emplace_back(clOrig), mCurrTOFClustersTreeEntry, it); + mTOFClusWork.emplace_back(clOrig);//, mCurrTOFClustersTreeEntry, it); auto& cl = mTOFClusWork.back(); - if (mMCTruthON) { - mTOFClusLblWork.emplace_back(mTOFClusLabels->getLabels(it)[0]); - } + // if (mMCTruthON) { + // mTOFClusLblWork.emplace_back(mTOFClusLabels->getLabels(it)[0]); + // } // cache work track index - mTOFClusSectIndexCache[o2::utils::Angle2Sector(cl.getAlpha())].push_back(mTOFClusWork.size() - 1); + mTOFClusSectIndexCache[o2::utils::Angle2Sector(cl.getPhi())].push_back(mTOFClusWork.size() - 1); } // sort tracks in each sector according to their time (increasing in time) @@ -373,6 +373,9 @@ void MatchTOF::doMatching(int sec) int itof0 = 0; // starting index in TOF clusters for matching of the track int detId[2][5]; // at maximum one track can fall in 2 strips during the propagation; the second dimention of the array is the TOF det index float deltaPos[2][3]; // at maximum one track can fall in 2 strips during the propagation; the second dimention of the array is the residuals + int nmatchStrip[2] = {0,0}; + int detIdTemp[5]; + float deltaPosTemp[3]; for (int itrk = 0; itrk < cacheTrk.size(); itrk++) { int nPropagatedInStrip = 0; // how many strips were hit during the propagation auto& trefTrk = mTracksWork[cacheTrk[itrk]]; @@ -382,12 +385,45 @@ void MatchTOF::doMatching(int sec) float step = 0.1; // step size in cm while (propagateToRefX(trefTrk, mXRef+istep*step, step) && nPropagatedInStrip <2 && mXRef+istep*step < Geo::RMAX){ float pos[3] = {trefTrk.getX(), trefTrk.getY(), trefTrk.getZ()}; - Geo::getPadDxDyDz(pos, detId[nPropagatedInStrip], deltaPos[nPropagatedInStrip]); + Geo::getPadDxDyDz(pos, detIdTemp, deltaPosTemp); // check if after the propagation we are in a TOF strip - if (detId[2] != -1) { // we ended in a TOF strip - nPropagatedInStrip++; + if (detId[nPropagatedInStrip][2] != -1) { // we ended in a TOF strip + if(nPropagatedInStrip && nmatchStrip[nPropagatedInStrip]){ // check if we are in new strip + if(detId[nPropagatedInStrip][0] != detIdTemp[0] || + detId[nPropagatedInStrip][1] != detIdTemp[1] || + detId[nPropagatedInStrip][2] != detIdTemp[2]) + nPropagatedInStrip++; + } + + if(nPropagatedInStrip == 2) break; + + if(nmatchStrip[nPropagatedInStrip] == 0){ + detId[nPropagatedInStrip][0] = detIdTemp[0]; + detId[nPropagatedInStrip][1] = detIdTemp[1]; + detId[nPropagatedInStrip][2] = detIdTemp[2]; + detId[nPropagatedInStrip][3] = detIdTemp[3]; + detId[nPropagatedInStrip][4] = detIdTemp[4]; + deltaPos[nPropagatedInStrip][0] = deltaPosTemp[0]; + deltaPos[nPropagatedInStrip][1] = deltaPosTemp[1]; + deltaPos[nPropagatedInStrip][2] = deltaPosTemp[2]; + nmatchStrip[nPropagatedInStrip]++; + } + else{ // a second propagation step in the same strip -> update info (we average on all matching with strip) + deltaPos[nPropagatedInStrip][0] += deltaPosTemp[0] + (detIdTemp[4] - detId[nPropagatedInStrip][4])*Geo::XPAD; + deltaPos[nPropagatedInStrip][1] += deltaPosTemp[1]; + deltaPos[nPropagatedInStrip][2] += deltaPosTemp[2] + (detIdTemp[3] - detId[nPropagatedInStrip][3])*Geo::ZPAD; + nmatchStrip[nPropagatedInStrip]++; + } } } + + for(Int_t imatch=0;imatch a, std::pair b) { return (a.second.getChi2() < b.second.getChi2());}); - for (auto matchingPair = mMatchedTracksPairs.begin(); matchingPair!= mMatchedTracksPairs.end(); matchingPair++) { + for (const std::pair &matchingPair : mMatchedTracksPairs){ if (mMatchedTracksIndex[matchingPair.first] != -1) { // the track was already filled continue; } @@ -436,13 +472,13 @@ void MatchTOF::selectBestMatches() } mMatchedTracksIndex[matchingPair.first] = mMatchedTracks.size(); // index of the MatchInfoTOF correspoding to this track mMatchedClustersIndex[matchingPair.second.getTOFClIndex()] = mMatchedTracksIndex[matchingPair.first]; // index of the track that was matched to this cluster - mMatchedTracks.pushBack(matchingPair.second); // array of MatchInfoTOF + mMatchedTracks.push_back(matchingPair.second); // array of MatchInfoTOF } } //______________________________________________ - bool MatchTPCITS::propagateToRefX(o2::track::TrackParCov& trc, float xRef, float stepInCm) +bool MatchTOF::propagateToRefX(o2::track::TrackParCov& trc, float xRef, float stepInCm) { // propagate track to matching reference X bool refReached = false; diff --git a/Detectors/TOF/reconstruction/src/Clusterer.cxx b/Detectors/TOF/reconstruction/src/Clusterer.cxx index 363025373b662..ccea09f9fdbb6 100644 --- a/Detectors/TOF/reconstruction/src/Clusterer.cxx +++ b/Detectors/TOF/reconstruction/src/Clusterer.cxx @@ -191,5 +191,12 @@ void Clusterer::buildCluster(Cluster& c, MCLabelContainer const* digitMCTruth) } } + // set geometrical variables + int det[5]; + Geo::getVolumeIndices(c.getMainContributingChannel(),det); + float pos[3]; + Geo::getPos(det, pos); + c.SetBaseData(c.getMainContributingChannel(),pos[0],pos[1],pos[2],0,0,0); // error on position set to zero + return; } diff --git a/cmake/O2Dependencies.cmake b/cmake/O2Dependencies.cmake index aab5f5b3a0cf9..638b729a35ae9 100644 --- a/cmake/O2Dependencies.cmake +++ b/cmake/O2Dependencies.cmake @@ -2140,6 +2140,7 @@ o2_define_bucket( ${CMAKE_SOURCE_DIR}/DataFormats/Detectors/ITSMFT/common/include ${CMAKE_SOURCE_DIR}/Detectors/ITSMFT/ITS/base/include ${CMAKE_SOURCE_DIR}/Detectors/TPC/base/include + ${CMAKE_SOURCE_DIR}/Detectors/TOF/base/include ${CMAKE_SOURCE_DIR}/Detectors/Base/include ${CMAKE_SOURCE_DIR}/Common/Utils/include ${CMAKE_SOURCE_DIR}/Common/MathUtils/include From 451fedc52d518456f935927b0e1d7361ac25d77f Mon Sep 17 00:00:00 2001 From: zampolli Date: Tue, 10 Jul 2018 15:10:32 +0200 Subject: [PATCH 07/39] Propagate the TrackTPC corresponding to the track to match --- Detectors/GlobalTracking/src/MatchTOF.cxx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Detectors/GlobalTracking/src/MatchTOF.cxx b/Detectors/GlobalTracking/src/MatchTOF.cxx index 33e3680894f44..c65cd6dd3b476 100644 --- a/Detectors/GlobalTracking/src/MatchTOF.cxx +++ b/Detectors/GlobalTracking/src/MatchTOF.cxx @@ -207,6 +207,7 @@ bool MatchTOF::prepareTracks() mTracksSectIndexCache[sec].clear(); mTracksSectIndexCache[sec].reserve(100 + 1.2 * mNumOfTracks / o2::constants::math::NSectors); } + for (int it = 0; it < mNumOfTracks; it++) { o2::dataformats::TrackTPCITS& trcOrig = (*mTracksArrayInp)[it]; // TODO: check if we cannot directly use the o2::track::TrackParCov class instead of o2::dataformats::TrackTPCITS, and then avoid the casting below; this is the track at the vertex @@ -217,9 +218,11 @@ bool MatchTOF::prepareTracks() // create working copy of track param mTracksWork.emplace_back(trcOrig);//, mCurrTracksTreeEntry, it); - auto& trc = mTracksWork.back(); + // make a copy of the TPC track that we have to propagate + o2::TPC::TrackTPC* trc = new o2::TPC::TrackTPC(trcTPCOrig); + // auto& trc = mTracksWork.back(); // propagate to matching Xref - if (!propagateToRefX(trc, mXRef, 2)) { + if (!propagateToRefX(*trc, mXRef, 2)) { mTracksWork.pop_back(); // discard track whose propagation to mXRef failed continue; } @@ -227,7 +230,8 @@ bool MatchTOF::prepareTracks() // mTracksLblWork.emplace_back(mTracksLabels->getLabels(it)[0]); // } // cache work track index - mTracksSectIndexCache[o2::utils::Angle2Sector(trc.getAlpha())].push_back(mTracksWork.size() - 1); + mTracksSectIndexCache[o2::utils::Angle2Sector(trc->getAlpha())].push_back(mTracksWork.size() - 1); + delete trc; // Check: is this needed? } // sort tracks in each sector according to their time (increasing in time) From 1c83784f6d71ff29de3180ef3c5c9b2eb749ab36 Mon Sep 17 00:00:00 2001 From: zampolli Date: Tue, 10 Jul 2018 16:26:53 +0200 Subject: [PATCH 08/39] Getter and Setter of the value of the number of sigma to cut for the matching --- Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h | 5 +++++ Detectors/GlobalTracking/src/MatchTOF.cxx | 1 + 2 files changed, 6 insertions(+) diff --git a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h index ba39a64865baa..6a1c7d2505eec 100644 --- a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h +++ b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h @@ -110,6 +110,11 @@ class MatchTOF ///< get tolerance on track-TOF times comparison float getSpaceTolerance() const { return mSpaceTolerance; } + ///< set number of sigma used to do the matching + void setSigmaTimeCut(float val) { mSigmaTimeCut = val; } + ///< get number of sigma used to do the matching + float getSigmaTimeCut() const { return mSigmaTimeCut; } + private: void attachInputTrees(); bool prepareTracks(); diff --git a/Detectors/GlobalTracking/src/MatchTOF.cxx b/Detectors/GlobalTracking/src/MatchTOF.cxx index c65cd6dd3b476..f541fd7ac7df5 100644 --- a/Detectors/GlobalTracking/src/MatchTOF.cxx +++ b/Detectors/GlobalTracking/src/MatchTOF.cxx @@ -114,6 +114,7 @@ void MatchTOF::print() const printf("MC truth: %s\n", mMCTruthON ? "on" : "off"); printf("Time tolerance: %.3f\n", mTimeTolerance); printf("Space tolerance: %.3f\n", mSpaceTolerance); + printf("SigmaTimeCut: %d\n", mSigmaTimeCut); printf("**********************************************************************\n"); } From c832464959ac9394a14b68947fd6794b70db9fc5 Mon Sep 17 00:00:00 2001 From: zampolli Date: Fri, 7 Sep 2018 15:40:00 +0200 Subject: [PATCH 09/39] Use TPCITS track for TOF matching --- Detectors/GlobalTracking/src/MatchTOF.cxx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Detectors/GlobalTracking/src/MatchTOF.cxx b/Detectors/GlobalTracking/src/MatchTOF.cxx index f541fd7ac7df5..8c6e2b1e3290a 100644 --- a/Detectors/GlobalTracking/src/MatchTOF.cxx +++ b/Detectors/GlobalTracking/src/MatchTOF.cxx @@ -220,10 +220,10 @@ bool MatchTOF::prepareTracks() // create working copy of track param mTracksWork.emplace_back(trcOrig);//, mCurrTracksTreeEntry, it); // make a copy of the TPC track that we have to propagate - o2::TPC::TrackTPC* trc = new o2::TPC::TrackTPC(trcTPCOrig); - // auto& trc = mTracksWork.back(); + //o2::TPC::TrackTPC* trc = new o2::TPC::TrackTPC(trcTPCOrig); // this would take the TPCout track + auto& trc = mTracksWork.back(); // with this we take the TPCITS track propagated to the vertex // propagate to matching Xref - if (!propagateToRefX(*trc, mXRef, 2)) { + if (!propagateToRefX(trc, mXRef, 2)) { mTracksWork.pop_back(); // discard track whose propagation to mXRef failed continue; } @@ -231,8 +231,8 @@ bool MatchTOF::prepareTracks() // mTracksLblWork.emplace_back(mTracksLabels->getLabels(it)[0]); // } // cache work track index - mTracksSectIndexCache[o2::utils::Angle2Sector(trc->getAlpha())].push_back(mTracksWork.size() - 1); - delete trc; // Check: is this needed? + mTracksSectIndexCache[o2::utils::Angle2Sector(trc.getAlpha())].push_back(mTracksWork.size() - 1); + //delete trc; // Check: is this needed? } // sort tracks in each sector according to their time (increasing in time) From 89e701115022558214b639879f5a6649b46b6a4c Mon Sep 17 00:00:00 2001 From: zampolli Date: Tue, 11 Sep 2018 11:49:19 +0200 Subject: [PATCH 10/39] Fixes for matching (clusters that are loaded, filling of inxed cache...) --- .../TOF/include/DataFormatsTOF/Cluster.h | 9 +- DataFormats/Detectors/TOF/src/Cluster.cxx | 1 - .../include/GlobalTracking/MatchTOF.h | 2 +- Detectors/GlobalTracking/src/MatchTOF.cxx | 90 ++++++++++++------- Detectors/TOF/base/src/Geo.cxx | 2 +- 5 files changed, 65 insertions(+), 39 deletions(-) diff --git a/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h b/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h index d3d039057b629..fc3a027c91a5e 100644 --- a/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h +++ b/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h @@ -16,6 +16,10 @@ #include "ReconstructionDataFormats/BaseCluster.h" #include // for base_object +#include +#include + + namespace o2 { @@ -57,8 +61,9 @@ class Cluster : public o2::BaseCluster int getDeltaBC() const { return mDeltaBC; }; // deltaBC void setDeltaBC(int value) { mDeltaBC = value; }; // deltaBC //float getZ() const {return mZ;} // Cluster Z - already in the definition of the cluster - float getR() const { return mR; } // Cluster Radius - float getPhi() const { return mPhi; } // Cluster Phi + float getR() const { return TMath::Sqrt(getX()*getX() + getY()*getY() + getZ()*getZ()); } // Cluster Radius + float getPhi() const { return TMath::ATan2(getY(), getX()); } // Cluster Phi + int getSector() const { return int((TMath::ATan2(-getY(), -getX())+TMath::Pi())*TMath::RadToDeg()*0.05);} // Cluster Sector int getContributingChannels() const { return mContributingChannels; } void setContributingChannels(int contributingChannels) { mContributingChannels = contributingChannels; } diff --git a/DataFormats/Detectors/TOF/src/Cluster.cxx b/DataFormats/Detectors/TOF/src/Cluster.cxx index b5883d00865a6..1efabe776be3a 100644 --- a/DataFormats/Detectors/TOF/src/Cluster.cxx +++ b/DataFormats/Detectors/TOF/src/Cluster.cxx @@ -14,7 +14,6 @@ #include "DataFormatsTOF/Cluster.h" #include "FairLogger.h" -#include #include #include diff --git a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h index 6a1c7d2505eec..a3f1eff1fa723 100644 --- a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h +++ b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h @@ -192,7 +192,7 @@ class MatchTOF int* mMatchedClustersIndex = nullptr; //[mNumOfClusters] std::string mTracksBranchName = "TPCITS"; ///< name of branch containing input matched tracks - std::string mTPCTracksBranchName = "TPC"; ///< name of branch containing actual TPC tracks + std::string mTPCTracksBranchName = "Tracks"; ///< name of branch containing actual TPC tracks std::string mTOFClusterBranchName = "TOFCluster"; ///< name of branch containing input ITS clusters std::string mTOFMCTruthBranchName = "TOFClusterMCTruth"; ///< name of branch containing ITS MC labels std::string mOutTracksBranchName = "TOFMatchInfo"; ///< name of branch containing output matched tracks diff --git a/Detectors/GlobalTracking/src/MatchTOF.cxx b/Detectors/GlobalTracking/src/MatchTOF.cxx index 8c6e2b1e3290a..f8734570d663f 100644 --- a/Detectors/GlobalTracking/src/MatchTOF.cxx +++ b/Detectors/GlobalTracking/src/MatchTOF.cxx @@ -53,7 +53,9 @@ void MatchTOF::run() prepareTracks(); prepareTOFClusters(); for (int sec = o2::constants::math::NSectors; sec--;) { + printf("doing matching...\n"); doMatching(sec); + printf("...done. Now check the best matches\n"); selectBestMatches(); } if (0) { // enabling this creates very verbose output @@ -211,12 +213,15 @@ bool MatchTOF::prepareTracks() for (int it = 0; it < mNumOfTracks; it++) { - o2::dataformats::TrackTPCITS& trcOrig = (*mTracksArrayInp)[it]; // TODO: check if we cannot directly use the o2::track::TrackParCov class instead of o2::dataformats::TrackTPCITS, and then avoid the casting below; this is the track at the vertex + //o2::dataformats::TrackTPCITS& trcOrig = (*mTracksArrayInp)[it]; // TODO: check if we cannot directly use the o2::track::TrackParCov class instead of o2::dataformats::TrackTPCITS, and then avoid the casting below; this is the track at the vertex + o2::track::TrackParCov& trcOrig = (*mTracksArrayInp)[it]; // TODO: check if we cannot directly use the o2::track::TrackParCov class instead of o2::dataformats::TrackTPCITS, and then avoid the casting below; this is the track at the vertex + /* evIdx evIdxTPC = trcOrig.getRefTPC(); int indTPC = evIdxTPC.getIndex(); o2::TPC::TrackTPC& trcTPCOrig = (*mTPCTracksArrayInp)[indTPC]; // we take the track when it is propagated out - + */ + // create working copy of track param mTracksWork.emplace_back(trcOrig);//, mCurrTracksTreeEntry, it); // make a copy of the TPC track that we have to propagate @@ -255,43 +260,42 @@ bool MatchTOF::prepareTOFClusters() { ///< prepare the tracks that we want to match to TOF - if (!loadTOFClustersNextChunk()) - { - return false; - } - - mNumOfClusters = mTOFClustersArrayInp->size(); - if (mNumOfClusters == 0) return false; // no clusters to be matched - if (mMatchedClustersIndex) delete[] mMatchedClustersIndex; - mMatchedClustersIndex = new int[mNumOfClusters]; - std::fill_n(mMatchedClustersIndex, mNumOfClusters, -1); // initializing all to -1 - // copy the track params, propagate to reference X and build sector tables mTOFClusWork.clear(); - mTOFClusWork.reserve(mNumOfClusters); + // mTOFClusWork.reserve(mNumOfClusters); // we cannot do this, we don't have mNumOfClusters yet // if (mMCTruthON) { // mTOFClusLblWork.clear(); // mTOFClusLblWork.reserve(mNumOfClusters); // } + + for (int sec = o2::constants::math::NSectors; sec--;) { mTOFClusSectIndexCache[sec].clear(); - mTOFClusSectIndexCache[sec].reserve(100 + 1.2 * mNumOfClusters / o2::constants::math::NSectors); + //mTOFClusSectIndexCache[sec].reserve(100 + 1.2 * mNumOfClusters / o2::constants::math::NSectors); } - for (int it = 0; it < mNumOfClusters; it++) { - Cluster& clOrig = (*mTOFClustersArrayInp)[it]; - - // create working copy of track param - mTOFClusWork.emplace_back(clOrig);//, mCurrTOFClustersTreeEntry, it); - auto& cl = mTOFClusWork.back(); - // if (mMCTruthON) { - // mTOFClusLblWork.emplace_back(mTOFClusLabels->getLabels(it)[0]); - // } - // cache work track index - mTOFClusSectIndexCache[o2::utils::Angle2Sector(cl.getPhi())].push_back(mTOFClusWork.size() - 1); + mNumOfClusters = 0; + while (loadTOFClustersNextChunk()) + { + int nClusterInCurrentChunk = mTOFClustersArrayInp->size(); + printf("nClusterInCurrentChunk = %d\n", nClusterInCurrentChunk); + mNumOfClusters += nClusterInCurrentChunk; + for (int it = 0; it < nClusterInCurrentChunk; it++) { + Cluster& clOrig = (*mTOFClustersArrayInp)[it]; + + // create working copy of track param + mTOFClusWork.emplace_back(clOrig);//, mCurrTOFClustersTreeEntry, it); + auto& cl = mTOFClusWork.back(); + // if (mMCTruthON) { + // mTOFClusLblWork.emplace_back(mTOFClusLabels->getLabels(it)[0]); + // } + // cache work track index + mTOFClusSectIndexCache[o2::utils::Angle2Sector(cl.getPhi())].push_back(mTOFClusWork.size() - 1); + } + } - // sort tracks in each sector according to their time (increasing in time) + // sort clusters in each sector according to their time (increasing in time) for (int sec = o2::constants::math::NSectors; sec--;) { auto& indexCache = mTOFClusSectIndexCache[sec]; LOG(INFO) << "Sorting sector" << sec << " | " << indexCache.size() << " TOF clusters" << FairLogger::endl; @@ -302,7 +306,11 @@ bool MatchTOF::prepareTOFClusters() auto& clB = mTOFClusWork[b]; return (clA.getTime() - clB.getTime()) < 0.; }); - } // loop over tracks of single sector + } // loop over TOF clusters of single sector + + if (mMatchedClustersIndex) delete[] mMatchedClustersIndex; + mMatchedClustersIndex = new int[mNumOfClusters]; + std::fill_n(mMatchedClustersIndex, mNumOfClusters, -1); // initializing all to -1 return true; } @@ -338,10 +346,13 @@ void MatchTOF::loadTracksChunk(int chunk) bool MatchTOF::loadTOFClustersNextChunk() { ///< load next chunk of clusters to be matched to TOF + printf("Loading TOF clusters: number of entries in tree = %d\n", mTreeTOFClusters->GetEntries()); while (++mCurrTOFClustersTreeEntry < mTreeTOFClusters->GetEntries()) { mTreeTOFClusters->GetEntry(mCurrTOFClustersTreeEntry); LOG(DEBUG) << "Loading TOF clusters entry " << mCurrTOFClustersTreeEntry << " -> " << mTOFClustersArrayInp->size() - << " tracks" << FairLogger::endl; + << " clusters" << FairLogger::endl; + LOG(INFO) << "Loading TOF clusters entry " << mCurrTOFClustersTreeEntry << " -> " << mTOFClustersArrayInp->size() + << " clusters" << FairLogger::endl; if (!mTOFClustersArrayInp->size()) { continue; } @@ -370,9 +381,8 @@ void MatchTOF::doMatching(int sec) auto& cacheTOF = mTOFClusSectIndexCache[sec]; // array of cached TOF cluster indices for this sector; reminder: they are ordered in time! auto& cacheTrk = mTracksSectIndexCache[sec]; // array of cached tracks indices for this sector; reminder: they are ordered in time! int nTracks = cacheTrk.size(), nTOFCls = cacheTOF.size(); + LOG(INFO) << "Matching sector " << sec << ": number of tracks: " << nTracks << ", number of TOF clusters: " << nTOFCls << FairLogger::endl; if (!nTracks || !nTOFCls) { - LOG(INFO) << "Matching sector " << sec << " : N tracks:" << nTracks << " TOF:" << nTOFCls << " in sector " - << sec << FairLogger::endl; return; } int itof0 = 0; // starting index in TOF clusters for matching of the track @@ -389,8 +399,12 @@ void MatchTOF::doMatching(int sec) int istep = 1; // number of steps float step = 0.1; // step size in cm while (propagateToRefX(trefTrk, mXRef+istep*step, step) && nPropagatedInStrip <2 && mXRef+istep*step < Geo::RMAX){ + istep++; + // printf("istep = %d, currentPosition = %f \n", istep, mXRef+istep*step); float pos[3] = {trefTrk.getX(), trefTrk.getY(), trefTrk.getZ()}; + //printf("getPadDxDyDz:\n"); Geo::getPadDxDyDz(pos, detIdTemp, deltaPosTemp); + //printf("getPadDxDyDz done\n"); // check if after the propagation we are in a TOF strip if (detId[nPropagatedInStrip][2] != -1) { // we ended in a TOF strip if(nPropagatedInStrip && nmatchStrip[nPropagatedInStrip]){ // check if we are in new strip @@ -421,8 +435,9 @@ void MatchTOF::doMatching(int sec) } } } - + //printf("while done\n"); for(Int_t imatch=0;imatchPropagateToXBxByBz(trc, xRef, o2::constants::physics::MassPionCharged, MaxSnp, stepInCm, 0.);; + //printf("refReached = %d\n", (int)refReached); + return refReached; + /* while (o2::Base::Propagator::Instance()->PropagateToXBxByBz(trc, xRef, o2::constants::physics::MassPionCharged, MaxSnp, stepInCm, 0.)) { if (refReached) break; // RS: tmp @@ -501,5 +521,7 @@ bool MatchTOF::propagateToRefX(o2::track::TrackParCov& trc, float xRef, float st break; // failed (RS: check effect on matching tracks to neighbouring sector) } } + printf("returning from propagateToRefX\n"); return refReached && std::abs(trc.getSnp()) < MaxSnp; + */ } diff --git a/Detectors/TOF/base/src/Geo.cxx b/Detectors/TOF/base/src/Geo.cxx index e7b885ed4aa68..fcbc673c5bd3c 100644 --- a/Detectors/TOF/base/src/Geo.cxx +++ b/Detectors/TOF/base/src/Geo.cxx @@ -321,7 +321,7 @@ Int_t Geo::getStripNumberPerSM(Int_t iplate, Int_t istrip) void Geo::fromGlobalToSector(Float_t* pos, Int_t isector) { if (isector == -1) { - LOG(ERROR) << "Sector Index not valid (-1)\n"; + //LOG(ERROR) << "Sector Index not valid (-1)\n"; return; } From 08ee6d4358e2afbea37d04b186ea489f5c7f5932 Mon Sep 17 00:00:00 2001 From: zampolli Date: Fri, 14 Sep 2018 13:38:09 +0200 Subject: [PATCH 11/39] Load geometry for DPL processing --- Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx b/Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx index e252c8b6649ed..32cdadec0040f 100644 --- a/Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx +++ b/Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx @@ -17,6 +17,7 @@ #include "TStopwatch.h" #include "Steer/HitProcessingManager.h" // for RunContext #include "TChain.h" +#include "DetectorsBase/GeometryManager.h" #include "TOFSimulation/Digitizer.h" #include "DataFormatsParameters/GRPObject.h" @@ -158,6 +159,11 @@ DataProcessorSpec getTOFDigitizerSpec(int channel) simChains->back()->AddFile(signalfilename.c_str()); } + // make sure that the geometry is loaded (TODO will this be done centrally?) + if (!gGeoManager) { + o2::Base::GeometryManager::loadGeometry(); + } + // init digitizer digitizer->init(); const bool isContinuous = ctx.options().get("pileup"); From d3238a2cecb3a5e98e8a5a3ae67ab9388c33e17d Mon Sep 17 00:00:00 2001 From: zampolli Date: Fri, 14 Sep 2018 13:38:25 +0200 Subject: [PATCH 12/39] Load geometry if it is not there --- Detectors/TOF/base/src/Geo.cxx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Detectors/TOF/base/src/Geo.cxx b/Detectors/TOF/base/src/Geo.cxx index fcbc673c5bd3c..d0300bc3b4ddc 100644 --- a/Detectors/TOF/base/src/Geo.cxx +++ b/Detectors/TOF/base/src/Geo.cxx @@ -12,6 +12,7 @@ #include "TGeoManager.h" #include "TMath.h" #include "FairLogger.h" +#include "DetectorsBase/GeometryManager.h" ClassImp(o2::tof::Geo); @@ -157,8 +158,12 @@ void Geo::getPos(Int_t* det, Float_t* pos) Char_t path[200]; getVolumePath(det, path); if (!gGeoManager) { - LOG(ERROR) << " no TGeo!" << "\n"; + LOG(ERROR) << " no TGeo! Loading it" << "\n"; + o2::Base::GeometryManager::loadGeometry(); } + FILE* ciccio = fopen("TOF_geo.txt", "w"); + fprintf(ciccio, "path = %s, gGeoManager = %p", path, gGeoManager); + fclose(ciccio); gGeoManager->cd(path); TGeoHMatrix global; global = *gGeoManager->GetCurrentMatrix(); From a7c5be5a5b6559b3bf15590be64d4532f6f78aca Mon Sep 17 00:00:00 2001 From: zampolli Date: Fri, 14 Sep 2018 13:38:50 +0200 Subject: [PATCH 13/39] Temporary push during debugging for DPL --- Detectors/TOF/reconstruction/src/Clusterer.cxx | 9 ++++++++- Detectors/TOF/simulation/src/Digitizer.cxx | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Detectors/TOF/reconstruction/src/Clusterer.cxx b/Detectors/TOF/reconstruction/src/Clusterer.cxx index ccea09f9fdbb6..3ed2ba3491242 100644 --- a/Detectors/TOF/reconstruction/src/Clusterer.cxx +++ b/Detectors/TOF/reconstruction/src/Clusterer.cxx @@ -181,11 +181,16 @@ void Clusterer::buildCluster(Cluster& c, MCLabelContainer const* digitMCTruth) // filling the MC labels of this cluster; the first will be those of the main digit; then the others if (digitMCTruth != nullptr) { int lbl = mClsLabels->getIndexedSize(); // this should correspond to the number of digits also; + printf("lbl = %d\n", lbl); for (int i = 0; i < mNumberOfContributingDigits; i++) { + printf("contributing digit = %d\n", i); int digitLabel = mContributingDigit[i]->getLabel(); + printf("digitLabel = %d\n", digitLabel); gsl::span mcArray = digitMCTruth->getLabels(digitLabel); - for (int j = 0; j < static_cast(mcArray.size()); ++j) { + for (int j = 0; j < static_cast(mcArray.size()); j++) { + printf("checking element %d in the array of labels\n", j); auto label = digitMCTruth->getElement(digitMCTruth->getMCTruthHeader(digitLabel).index + j); + printf("EventID = %d\n", label.getEventID()); mClsLabels->addElement(lbl, label); } } @@ -194,6 +199,8 @@ void Clusterer::buildCluster(Cluster& c, MCLabelContainer const* digitMCTruth) // set geometrical variables int det[5]; Geo::getVolumeIndices(c.getMainContributingChannel(),det); + printf("mainContributingChannel = %d, det[0] = %d, det[1] = %d, det[2] = %d, det[3] = %d, det[4] = %d\n", c.getMainContributingChannel(), det[0], det[1], det[2], det[3], det[4]); + LOG(ERROR) << "mainContributingChannel" << c.getMainContributingChannel() << ", det[0] = " << det[0] << ", det[1] = " << det[1] << ", det[2] = " << det[2] << ", det[3] = " << det[3] << ", det[4] = " << det[4] << FairLogger::endl; float pos[3]; Geo::getPos(det, pos); c.SetBaseData(c.getMainContributingChannel(),pos[0],pos[1],pos[2],0,0,0); // error on position set to zero diff --git a/Detectors/TOF/simulation/src/Digitizer.cxx b/Detectors/TOF/simulation/src/Digitizer.cxx index e991c59dfc2e5..7f693e7ba4743 100644 --- a/Detectors/TOF/simulation/src/Digitizer.cxx +++ b/Detectors/TOF/simulation/src/Digitizer.cxx @@ -283,9 +283,10 @@ void Digitizer::addDigit(Int_t channel, UInt_t istrip, Float_t time, Float_t x, bool iscurrent = true; // if we are in the current readout window Int_t isnext = -1; - if (mContinuous) { + if (mContinuous && 0) { isnext = Int_t(time * 1E-3 * Geo::READOUTWINDOW_INV) - mReadoutWindowCurrent; // to be replaced with uncalibrated time + if (isnext < 0 || isnext >= MAXWINDOWS - 1) { lblCurrent = mFutureIevent.size(); // this is the size of mHeaderArray; From a4bcee3b969c4a52eba28a2cdf835f3d97a23c31 Mon Sep 17 00:00:00 2001 From: zampolli Date: Mon, 1 Oct 2018 10:53:38 +0200 Subject: [PATCH 14/39] Change readout window for DPL (and remove printout) --- Detectors/TOF/base/include/TOFBase/Geo.h | 3 ++- Detectors/TOF/reconstruction/src/Clusterer.cxx | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Detectors/TOF/base/include/TOFBase/Geo.h b/Detectors/TOF/base/include/TOFBase/Geo.h index b81297da4c8fa..324c17df27afc 100644 --- a/Detectors/TOF/base/include/TOFBase/Geo.h +++ b/Detectors/TOF/base/include/TOFBase/Geo.h @@ -94,7 +94,8 @@ class Geo static constexpr Float_t DEADTIME = 25E+03; // Single channel dead time (ps) static constexpr Float_t DEADTIMETDC = DEADTIME/TDCBIN; ///< Single channel TDC dead time (ps) static constexpr Float_t MATCHINGWINDOW = TDCBIN * 8192; // Matching window (ps) 2^13=8192 - static constexpr Float_t READOUTWINDOW = 1000; // Readout window (ns) + // static constexpr Float_t READOUTWINDOW = 1000; // Readout window (ns) + static constexpr Float_t READOUTWINDOW = 1e9; // Readout window (ns) - now put 1s for DPL to work fine, but it will be 29e3 static constexpr Float_t READOUTWINDOW_INV = 1. / READOUTWINDOW; // Readout window (ns) static constexpr Float_t ANGLES[NPLATES][NMAXNSTRIP] = { // Strip Tilt Angles diff --git a/Detectors/TOF/reconstruction/src/Clusterer.cxx b/Detectors/TOF/reconstruction/src/Clusterer.cxx index 3ed2ba3491242..d3d98b8275d5c 100644 --- a/Detectors/TOF/reconstruction/src/Clusterer.cxx +++ b/Detectors/TOF/reconstruction/src/Clusterer.cxx @@ -199,8 +199,6 @@ void Clusterer::buildCluster(Cluster& c, MCLabelContainer const* digitMCTruth) // set geometrical variables int det[5]; Geo::getVolumeIndices(c.getMainContributingChannel(),det); - printf("mainContributingChannel = %d, det[0] = %d, det[1] = %d, det[2] = %d, det[3] = %d, det[4] = %d\n", c.getMainContributingChannel(), det[0], det[1], det[2], det[3], det[4]); - LOG(ERROR) << "mainContributingChannel" << c.getMainContributingChannel() << ", det[0] = " << det[0] << ", det[1] = " << det[1] << ", det[2] = " << det[2] << ", det[3] = " << det[3] << ", det[4] = " << det[4] << FairLogger::endl; float pos[3]; Geo::getPos(det, pos); c.SetBaseData(c.getMainContributingChannel(),pos[0],pos[1],pos[2],0,0,0); // error on position set to zero From 7a66c2968f8b95b8fe9fd1e0bc804b6ca3472486 Mon Sep 17 00:00:00 2001 From: Francesco Noferini Date: Tue, 2 Oct 2018 10:43:58 +0200 Subject: [PATCH 15/39] TOF digitizer switch to vector of vectors for digits (#5) --- .../include/TOFSimulation/Digitizer.h | 10 +- Detectors/TOF/simulation/src/Digitizer.cxx | 155 +++++++++++------- .../src/TOFDigitizerSpec.cxx | 17 +- 3 files changed, 114 insertions(+), 68 deletions(-) diff --git a/Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h b/Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h index 62dc79679ee3e..9c9423c1a6d33 100644 --- a/Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h +++ b/Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h @@ -66,6 +66,9 @@ class Digitizer void setContinuous(bool val) { mContinuous = val; } bool isContinuous() const { return mContinuous; } + const std::vector< std::vector >* getDigitPerTimeFrame() const {return &mDigitsPerTimeFrame;} + const std::vector >* getMCTruthPerTimeFrame() const {return &mMCTruthOutputContainerPerTimeFrame;} + private: // parameters Int_t mMode; @@ -96,7 +99,10 @@ class Digitizer // digit info //std::vector* mDigits; - static const int MAXWINDOWS = 10; // how many readout windows we can buffer + static const int MAXWINDOWS = 2; // how many readout windows we can buffer + + std::vector< std::vector > mDigitsPerTimeFrame; + std::vector > mMCTruthOutputContainerPerTimeFrame; int mIcurrentReadoutWindow = 0; o2::dataformats::MCTruthContainer mMCTruthContainer[MAXWINDOWS]; @@ -123,6 +129,8 @@ class Digitizer void addDigit(Int_t channel, UInt_t istrip, Float_t time, Float_t x, Float_t z, Float_t charge, Int_t iX, Int_t iZ, Int_t padZfired, Int_t trackID); + void checkIfReuseFutureDigits(); + bool isMergable(Digit digit1, Digit digit2) { if (digit1.getChannel() != digit2.getChannel()) { diff --git a/Detectors/TOF/simulation/src/Digitizer.cxx b/Detectors/TOF/simulation/src/Digitizer.cxx index 7f693e7ba4743..7b4835d576c50 100644 --- a/Detectors/TOF/simulation/src/Digitizer.cxx +++ b/Detectors/TOF/simulation/src/Digitizer.cxx @@ -46,73 +46,29 @@ void Digitizer::init() //______________________________________________________________________ -void Digitizer::process(const std::vector* hits, std::vector* digits) -{ - // hits array of TOF hits for a given simulated event - //mDigits = digits; - - Int_t readoutwindow = Int_t((mEventTime)*Geo::READOUTWINDOW_INV); // to be replaced with uncalibrated time - //while(mContinuous && readoutwindow > mReadoutWindowCurrent){ - if (mContinuous && readoutwindow > mReadoutWindowCurrent) { - digits->clear(); - //fillOutputContainer(*digits); - // waiting for the new framework to store previous readout window +void Digitizer::process(const std::vector* hits, std::vector* digits){ + // hits array of TOF hits for a given simulated event + // digits passed from external to be filled, in continuous readout mode we will push it on mDigitsPerTimeFrame vector of vectors of digits + + Int_t readoutwindow = Int_t((mEventTime)*Geo::READOUTWINDOW_INV); // to be replaced with "uncalibrated" time - for (Int_t i = mReadoutWindowCurrent; i < readoutwindow; i++) { // temporary loop because current framework doesn't allow to store outputs in digitizer class - fillOutputContainer(*digits); - } - //mReadoutWindowCurrent++; - mReadoutWindowCurrent = readoutwindow; - - // check if digits stored for future match the new readout windows available - int idigit = 0; - for (auto& digit : mFutureDigits) { - int isnext = Int_t(digit.getTimeStamp() * Geo::READOUTWINDOW_INV) - mReadoutWindowCurrent; // to be replaced with uncalibrated time - - if (isnext < 0) // we jump too ahead in future, digit will be not stored - LOG(INFO) << "Digit lost because we jump too ahead in future. Current RO window=" << isnext << "\n"; - - if (isnext < MAXWINDOWS - 1) { // move from digit buffer array to the proper window - if (isnext >= 0) { - std::vector* strips = mStripsCurrent; - o2::dataformats::MCTruthContainer* mcTruthContainer = mMCTruthContainerCurrent; - - if (isnext) { - strips = mStripsNext[isnext - 1]; - mcTruthContainer = mMCTruthContainerNext[isnext - 1]; - } - - int trackID = mFutureItrackID[digit.getLabel()]; - int sourceID = mFutureIsource[digit.getLabel()]; - int eventID = mFutureIevent[digit.getLabel()]; - fillDigitsInStrip(strips, mcTruthContainer, digit.getTimeStamp(), digit.getChannel(), digit.getTDC(), digit.getTOT(), digit.getBC(), digit.getChannel() / Geo::NPADS, trackID, eventID, sourceID); - } - - // remove the element from the buffers - mFutureItrackID.erase(mFutureItrackID.begin() + digit.getLabel()); - mFutureIsource.erase(mFutureIsource.begin() + digit.getLabel()); - mFutureIevent.erase(mFutureIevent.begin() + digit.getLabel()); - - int labelremoved = digit.getLabel(); - // adjust labels - for (auto& digit2 : mFutureDigits) { - if (digit2.getLabel() > labelremoved) - digit2.setLabel(digit2.getLabel() - 1); - } - // remove also digit from buffer - mFutureDigits.erase(mFutureDigits.begin() + idigit); - } else { - idigit++; // increment when moving to the next only if the current is not removed from the buffer - } - } - } + printf("process TOF -> continuous = %i, %i > %i?\n",mContinuous,readoutwindow,mReadoutWindowCurrent); + if (mContinuous && readoutwindow > mReadoutWindowCurrent) { // if we are moving in future readout windows flush previous ones (only for continuous readout mode) + digits->clear(); + + for (mReadoutWindowCurrent; mReadoutWindowCurrent < readoutwindow; mReadoutWindowCurrent++) { + fillOutputContainer(*digits); // fill all windows which are before (not yet stored) of the new current one + checkIfReuseFutureDigits(); + } // close loop readout window + } // close if continuous + for (auto& hit : *hits) { //TODO: put readout window counting/selection - + processHit(hit, mEventTime); } // end loop over hits - + if (!mContinuous) { // fill output container per event digits->clear(); fillOutputContainer(*digits); @@ -283,7 +239,7 @@ void Digitizer::addDigit(Int_t channel, UInt_t istrip, Float_t time, Float_t x, bool iscurrent = true; // if we are in the current readout window Int_t isnext = -1; - if (mContinuous && 0) { + if (mContinuous) { isnext = Int_t(time * 1E-3 * Geo::READOUTWINDOW_INV) - mReadoutWindowCurrent; // to be replaced with uncalibrated time @@ -304,6 +260,8 @@ void Digitizer::addDigit(Int_t channel, UInt_t istrip, Float_t time, Float_t x, iscurrent = false; } + // printf("add TOF digit c=%i n=%i\n",iscurrent,isnext); + std::vector* strips; o2::dataformats::MCTruthContainer* mcTruthContainer; @@ -722,12 +680,22 @@ void Digitizer::testFromHits(const char* geo, const char* hits) //______________________________________________________________________ void Digitizer::fillOutputContainer(std::vector& digits) { + if(mContinuous){ + digits.clear(); + mMCTruthOutputContainer->clear(); + } + printf("TOF fill output contatiner\n"); // filling the digit container doing a loop on all strips for (auto& strip : *mStripsCurrent) { strip.fillOutputContainer(digits); } + if(mContinuous){ + if(digits.size()) printf("%i) # TOF digits = %i (%x)\n",mIcurrentReadoutWindow,digits.size(),mStripsCurrent); + mDigitsPerTimeFrame.push_back(digits); + } + // if(! digits.size()) return; // copying the transient labels to the output labels (stripping the tdc information) @@ -739,6 +707,7 @@ void Digitizer::fillOutputContainer(std::vector& digits) } } + if(mContinuous) mMCTruthOutputContainerPerTimeFrame.push_back(*mMCTruthOutputContainer); mMCTruthContainerCurrent->clear(); // switch to next mStrip after flushing current readout window data @@ -746,6 +715,9 @@ void Digitizer::fillOutputContainer(std::vector& digits) if (mIcurrentReadoutWindow >= MAXWINDOWS) mIcurrentReadoutWindow = 0; + mStripsCurrent = &(mStrips[mIcurrentReadoutWindow]); + mMCTruthContainerCurrent = &(mMCTruthContainer[mIcurrentReadoutWindow]); + int k = mIcurrentReadoutWindow + 1; for (Int_t i = 0; i < MAXWINDOWS - 1; i++) { if (k >= MAXWINDOWS) @@ -759,5 +731,62 @@ void Digitizer::fillOutputContainer(std::vector& digits) void Digitizer::flushOutputContainer(std::vector& digits) { // flush all residual buffered data // TO be implemented - fillOutputContainer(digits); + printf("flushOutputContainer\n"); + if(! mContinuous) fillOutputContainer(digits); + else{ + for(Int_t i=0;i < MAXWINDOWS;i++){ + fillOutputContainer(digits); // fill all windows which are before (not yet stored) of the new current one + checkIfReuseFutureDigits(); + mReadoutWindowCurrent++; + } + + while(mFutureDigits.size()){ + fillOutputContainer(digits); // fill all windows which are before (not yet stored) of the new current one + checkIfReuseFutureDigits(); + mReadoutWindowCurrent++; + } + } +} +//______________________________________________________________________ +void Digitizer::checkIfReuseFutureDigits(){ + // check if digits stored very far in future match the new readout windows currently available + int idigit = 0; + for (auto& digit : mFutureDigits) { + int isnext = Int_t(digit.getTimeStamp() * Geo::READOUTWINDOW_INV) - (mReadoutWindowCurrent+1); // to be replaced with uncalibrated time + if (isnext < 0) // we jump too ahead in future, digit will be not stored + LOG(INFO) << "Digit lost because we jump too ahead in future. Current RO window=" << isnext << "\n"; + if (isnext < MAXWINDOWS - 1) { // move from digit buffer array to the proper window + if (isnext >= 0) { + std::vector* strips = mStripsCurrent; + o2::dataformats::MCTruthContainer* mcTruthContainer = mMCTruthContainerCurrent; + + if (isnext) { + strips = mStripsNext[isnext - 1]; + mcTruthContainer = mMCTruthContainerNext[isnext - 1]; + } + + int trackID = mFutureItrackID[digit.getLabel()]; + int sourceID = mFutureIsource[digit.getLabel()]; + int eventID = mFutureIevent[digit.getLabel()]; + fillDigitsInStrip(strips, mcTruthContainer, digit.getTimeStamp(), digit.getChannel(), digit.getTDC(), digit.getTOT(), digit.getBC(), digit.getChannel() / Geo::NPADS, trackID, eventID, sourceID); + } + + // remove the element from the buffers + mFutureItrackID.erase(mFutureItrackID.begin() + digit.getLabel()); + mFutureIsource.erase(mFutureIsource.begin() + digit.getLabel()); + mFutureIevent.erase(mFutureIevent.begin() + digit.getLabel()); + + int labelremoved = digit.getLabel(); + // adjust labels + for (auto& digit2 : mFutureDigits) { + if (digit2.getLabel() > labelremoved) + digit2.setLabel(digit2.getLabel() - 1); + } + // remove also digit from buffer + mFutureDigits.erase(mFutureDigits.begin() + idigit); + } + else { + idigit++; // increment when moving to the next only if the current is not removed from the buffer + } + } // close future digit loop } diff --git a/Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx b/Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx index 32cdadec0040f..5e5cb15979c2a 100644 --- a/Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx +++ b/Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx @@ -114,8 +114,8 @@ DataProcessorSpec getTOFDigitizerSpec(int channel) digits->clear(); digitizer->process(&hits, digits.get()); // copy digits into accumulator - std::copy(digits->begin(), digits->end(), std::back_inserter(*digitsAccum.get())); - labelAccum.mergeAtBack(*labels); + //std::copy(digits->begin(), digits->end(), std::back_inserter(*digitsAccum.get())); + //labelAccum.mergeAtBack(*labels); LOG(INFO) << "Have " << digits->size() << " digits "; } } @@ -125,8 +125,17 @@ DataProcessorSpec getTOFDigitizerSpec(int channel) digitizer->flushOutputContainer(*digits.get()); LOG(INFO) << "FLUSHING LEFTOVER STUFF " << digits->size(); // copy digits into accumulator - std::copy(digits->begin(), digits->end(), std::back_inserter(*digitsAccum.get())); - labelAccum.mergeAtBack(*labels); + //std::copy(digits->begin(), digits->end(), std::back_inserter(*digitsAccum.get())); + //labelAccum.mergeAtBack(*labels); + } + + // temporary accumulate vector of vecotors of digits in a single vector + // to be replace once we will be able to write the vector of vectors as different TTree entries + const std::vector< std::vector >* digitsVectOfVect = digitizer->getDigitPerTimeFrame(); + const std::vector >* mcLabVecOfVec = digitizer->getMCTruthPerTimeFrame(); + for(Int_t i=0; i < digitsVectOfVect->size();i++){ + std::copy(digitsVectOfVect->at(i).begin(), digitsVectOfVect->at(i).end(), std::back_inserter(*digitsAccum.get())); + labelAccum.mergeAtBack(mcLabVecOfVec->at(i)); } LOG(INFO) << "Have " << labelAccum.getNElements() << " TOF labels "; From b4be37191005bc98165939b71eec046972f5d100 Mon Sep 17 00:00:00 2001 From: zampolli Date: Wed, 3 Oct 2018 13:16:21 +0200 Subject: [PATCH 16/39] Progress on matching Note that there is a lot of debug printout too in this commit. To be still done: - check how we write out the output - time stored in clustered (we need the absolute one) - further debug :) --- Detectors/GlobalTracking/src/MatchTOF.cxx | 138 ++++++++++++++-------- 1 file changed, 86 insertions(+), 52 deletions(-) diff --git a/Detectors/GlobalTracking/src/MatchTOF.cxx b/Detectors/GlobalTracking/src/MatchTOF.cxx index f8734570d663f..734240d93d99d 100644 --- a/Detectors/GlobalTracking/src/MatchTOF.cxx +++ b/Detectors/GlobalTracking/src/MatchTOF.cxx @@ -211,35 +211,41 @@ bool MatchTOF::prepareTracks() mTracksSectIndexCache[sec].reserve(100 + 1.2 * mNumOfTracks / o2::constants::math::NSectors); } - + int nNotPropagatedToTOF = 0; for (int it = 0; it < mNumOfTracks; it++) { - //o2::dataformats::TrackTPCITS& trcOrig = (*mTracksArrayInp)[it]; // TODO: check if we cannot directly use the o2::track::TrackParCov class instead of o2::dataformats::TrackTPCITS, and then avoid the casting below; this is the track at the vertex - o2::track::TrackParCov& trcOrig = (*mTracksArrayInp)[it]; // TODO: check if we cannot directly use the o2::track::TrackParCov class instead of o2::dataformats::TrackTPCITS, and then avoid the casting below; this is the track at the vertex - + o2::dataformats::TrackTPCITS& trcOrig = (*mTracksArrayInp)[it]; // TODO: check if we cannot directly use the o2::track::TrackParCov class instead of o2::dataformats::TrackTPCITS, and then avoid the casting below; this is the track at the vertex + //o2::track::TrackParCov& trcOrig = (*mTracksArrayInp)[it]; // TODO: check if we cannot directly use the o2::track::TrackParCov class instead of o2::dataformats::TrackTPCITS, and then avoid the casting below; this is the track at the vertex /* evIdx evIdxTPC = trcOrig.getRefTPC(); int indTPC = evIdxTPC.getIndex(); o2::TPC::TrackTPC& trcTPCOrig = (*mTPCTracksArrayInp)[indTPC]; // we take the track when it is propagated out */ - + Printf("Original Track %d: getTimeMUS().getTimeStamp() = %f, getTimeMUS().getTimeStampError() = %f", it, (*mTracksArrayInp)[it].getTimeMUS().getTimeStamp() , (*mTracksArrayInp)[it].getTimeMUS().getTimeStampError()); // create working copy of track param mTracksWork.emplace_back(trcOrig);//, mCurrTracksTreeEntry, it); // make a copy of the TPC track that we have to propagate //o2::TPC::TrackTPC* trc = new o2::TPC::TrackTPC(trcTPCOrig); // this would take the TPCout track auto& trc = mTracksWork.back(); // with this we take the TPCITS track propagated to the vertex + Printf("Copied Track %d: getTimeMUS().getTimeStamp() = %f, getTimeMUS().getTimeStampError() = %f", it, trc.getTimeMUS().getTimeStamp() , trc.getTimeMUS().getTimeStampError()); // propagate to matching Xref - if (!propagateToRefX(trc, mXRef, 2)) { - mTracksWork.pop_back(); // discard track whose propagation to mXRef failed + if (!propagateToRefX(trc, mXRef, 2) || TMath::Abs(trc.getZ()) > Geo::MAXHZTOF) { + mTracksWork.pop_back(); // discard track whose propagation to mXRef failed, or those that go beyond TOF in z + nNotPropagatedToTOF++; continue; } // if (mMCTruthON) { // mTracksLblWork.emplace_back(mTracksLabels->getLabels(it)[0]); // } // cache work track index - mTracksSectIndexCache[o2::utils::Angle2Sector(trc.getAlpha())].push_back(mTracksWork.size() - 1); + std::array globalPos; + trc.getXYZGlo(globalPos); + + mTracksSectIndexCache[o2::utils::Angle2Sector( TMath::ATan2(globalPos[1], globalPos[0]))].push_back(mTracksWork.size() - 1); //delete trc; // Check: is this needed? } + LOG(INFO) << "Total number of tracks = " << mNumOfTracks << ", Number of tracks that failed to be propagated to TOF = " << nNotPropagatedToTOF << FairLogger::endl; + // sort tracks in each sector according to their time (increasing in time) for (int sec = o2::constants::math::NSectors; sec--;) { auto& indexCache = mTracksSectIndexCache[sec]; @@ -388,87 +394,115 @@ void MatchTOF::doMatching(int sec) int itof0 = 0; // starting index in TOF clusters for matching of the track int detId[2][5]; // at maximum one track can fall in 2 strips during the propagation; the second dimention of the array is the TOF det index float deltaPos[2][3]; // at maximum one track can fall in 2 strips during the propagation; the second dimention of the array is the residuals - int nmatchStrip[2] = {0,0}; + int nStepsInsideSameStrip[2] = {0,0}; // number of propagation steps in the same strip (since we have maximum 2 strips, it has dimention = 2) int detIdTemp[5]; float deltaPosTemp[3]; + std::array pos; + std::array posBeforeProp; + float posFloat[3]; + for (int itrk = 0; itrk < cacheTrk.size(); itrk++) { - int nPropagatedInStrip = 0; // how many strips were hit during the propagation + Printf("\n track %d", itrk); + for (int ii = 0; ii < 2; ii++) + detId[ii][2] = -1; // before trying to match, we need to inizialize the detId corresponding to the strip number to -1 + int nStripsCrossedInPropagation = 0; // how many strips were hit during the propagation auto& trefTrk = mTracksWork[cacheTrk[itrk]]; float minTrkTime = (trefTrk.getTimeMUS().getTimeStamp() - mSigmaTimeCut*trefTrk.getTimeMUS().getTimeStampError())*1.E6; // minimum time in ps float maxTrkTime = (trefTrk.getTimeMUS().getTimeStamp() + mSigmaTimeCut*trefTrk.getTimeMUS().getTimeStampError())*1.E6; // maximum time in ps int istep = 1; // number of steps float step = 0.1; // step size in cm - while (propagateToRefX(trefTrk, mXRef+istep*step, step) && nPropagatedInStrip <2 && mXRef+istep*step < Geo::RMAX){ - istep++; - // printf("istep = %d, currentPosition = %f \n", istep, mXRef+istep*step); - float pos[3] = {trefTrk.getX(), trefTrk.getY(), trefTrk.getZ()}; + trefTrk.getXYZGlo(posBeforeProp); + //float posBeforeProp[3] = {trefTrk.getX(), trefTrk.getY(), trefTrk.getZ()}; // in local ref system + printf("Global coordinates: posBeforeProp[0] = %f, posBeforeProp[1] = %f, posBeforeProp[2] = %f\n", posBeforeProp[0], posBeforeProp[1], posBeforeProp[2]); + while (propagateToRefX(trefTrk, mXRef+istep*step, step) && nStripsCrossedInPropagation <2 && mXRef+istep*step < Geo::RMAX){ + if (istep%100 == 0){ + printf("istep = %d, currentPosition = %f \n", istep, mXRef+istep*step); + } + //float pos[3] = {trefTrk.getX(), trefTrk.getY(), trefTrk.getZ()}; // these are the coordinates in the local ref system + trefTrk.getXYZGlo(pos); //printf("getPadDxDyDz:\n"); - Geo::getPadDxDyDz(pos, detIdTemp, deltaPosTemp); - //printf("getPadDxDyDz done\n"); + for (int ii = 0; ii < 3; ii++){ // we need to change the type... + posFloat[ii] = pos[ii]; + } + Geo::getPadDxDyDz(posFloat, detIdTemp, deltaPosTemp); + if (detIdTemp[2] != -1 && nStripsCrossedInPropagation == 0){ // print in case you have a match + Printf("\n\n*********** We have a match!*********"); + printf("Global coordinates: pos[0] = %f, pos[1] = %f, pos[2] = %f\n", pos[0], pos[1], pos[2]); + printf("detIdTemp[0] = %d, detIdTemp[1] = %d, detIdTemp[2] = %d, detIdTemp[3] = %d, detIdTemp[4] = %d\n", detIdTemp[0], detIdTemp[1], detIdTemp[2], detIdTemp[3], detIdTemp[4]); + printf("deltaPosTemp[0] = %f, deltaPosTemp[1] = %f, deltaPosTemp[2] = %f\n", deltaPosTemp[0], deltaPosTemp[1], deltaPosTemp[2]); + } + //printf("getPadDxDyDz done\n"); + istep++; // check if after the propagation we are in a TOF strip - if (detId[nPropagatedInStrip][2] != -1) { // we ended in a TOF strip - if(nPropagatedInStrip && nmatchStrip[nPropagatedInStrip]){ // check if we are in new strip - if(detId[nPropagatedInStrip][0] != detIdTemp[0] || - detId[nPropagatedInStrip][1] != detIdTemp[1] || - detId[nPropagatedInStrip][2] != detIdTemp[2]) - nPropagatedInStrip++; - } - - if(nPropagatedInStrip == 2) break; - - if(nmatchStrip[nPropagatedInStrip] == 0){ - detId[nPropagatedInStrip][0] = detIdTemp[0]; - detId[nPropagatedInStrip][1] = detIdTemp[1]; - detId[nPropagatedInStrip][2] = detIdTemp[2]; - detId[nPropagatedInStrip][3] = detIdTemp[3]; - detId[nPropagatedInStrip][4] = detIdTemp[4]; - deltaPos[nPropagatedInStrip][0] = deltaPosTemp[0]; - deltaPos[nPropagatedInStrip][1] = deltaPosTemp[1]; - deltaPos[nPropagatedInStrip][2] = deltaPosTemp[2]; - nmatchStrip[nPropagatedInStrip]++; + if (detIdTemp[2] != -1) { // we ended in a TOF strip + Printf("We are in a TOF strip!"); + if(nStripsCrossedInPropagation == 0 || detId[nStripsCrossedInPropagation-1][0] != detIdTemp[0] || + detId[nStripsCrossedInPropagation-1][1] != detIdTemp[1] || + detId[nStripsCrossedInPropagation-1][2] != detIdTemp[2]) { + if(nStripsCrossedInPropagation == 2) break; // we have already matched 2 strips, we cannot match more + nStripsCrossedInPropagation++; + } + + if(nStepsInsideSameStrip[nStripsCrossedInPropagation-1] == 0){ + detId[nStripsCrossedInPropagation-1][0] = detIdTemp[0]; + detId[nStripsCrossedInPropagation-1][1] = detIdTemp[1]; + detId[nStripsCrossedInPropagation-1][2] = detIdTemp[2]; + detId[nStripsCrossedInPropagation-1][3] = detIdTemp[3]; + detId[nStripsCrossedInPropagation-1][4] = detIdTemp[4]; + deltaPos[nStripsCrossedInPropagation-1][0] = deltaPosTemp[0]; + deltaPos[nStripsCrossedInPropagation-1][1] = deltaPosTemp[1]; + deltaPos[nStripsCrossedInPropagation-1][2] = deltaPosTemp[2]; + nStepsInsideSameStrip[nStripsCrossedInPropagation-1]++; } - else{ // a second propagation step in the same strip -> update info (we average on all matching with strip) - deltaPos[nPropagatedInStrip][0] += deltaPosTemp[0] + (detIdTemp[4] - detId[nPropagatedInStrip][4])*Geo::XPAD; - deltaPos[nPropagatedInStrip][1] += deltaPosTemp[1]; - deltaPos[nPropagatedInStrip][2] += deltaPosTemp[2] + (detIdTemp[3] - detId[nPropagatedInStrip][3])*Geo::ZPAD; - nmatchStrip[nPropagatedInStrip]++; + else{ // a further propagation step in the same strip -> update info (we average on all matching with strip) + deltaPos[nStripsCrossedInPropagation-1][0] += deltaPosTemp[0] + (detIdTemp[4] - detId[nStripsCrossedInPropagation-1][4])*Geo::XPAD; + deltaPos[nStripsCrossedInPropagation-1][1] += deltaPosTemp[1]; + deltaPos[nStripsCrossedInPropagation-1][2] += deltaPosTemp[2] + (detIdTemp[3] - detId[nStripsCrossedInPropagation-1][3])*Geo::ZPAD; + nStepsInsideSameStrip[nStripsCrossedInPropagation-1]++; } } - } - //printf("while done\n"); - for(Int_t imatch=0;imatch maxTrkTime) { // no more TOF clusters can be matched to this track - break; + // break; } int mainChannel = trefTOF.getMainContributingChannel(); int indices[5]; Geo::getVolumeIndices(mainChannel, indices); - for (auto iPropagation = 0; iPropagation < nPropagatedInStrip; iPropagation++){ + for (auto iPropagation = 0; iPropagation < nStripsCrossedInPropagation; iPropagation++){ printf("iPropagation = %d\n", iPropagation); + Printf("indices[0] = %d, indices[1] = %d, indices[2] = %d, detId[iPropagation][0] = %d, detId[iPropagation][1] = %d, detId[iPropagation][2] = %d", indices[0], indices[1], indices[2], detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2]); if (indices[0] != detId[iPropagation][0]) continue; if (indices[1] != detId[iPropagation][1]) continue; if (indices[2] != detId[iPropagation][2]) continue; float resX = deltaPos[iPropagation][0] - (indices[4] - detId[iPropagation][4])*Geo::XPAD; // readjusting the residuals due to the fact that the propagation fell in a pad that was not exactly the one of the cluster float resZ = deltaPos[iPropagation][2] - (indices[3] - detId[iPropagation][3])*Geo::ZPAD; // readjusting the residuals due to the fact that the propagation fell in a pad that was not exactly the one of the cluster float res = TMath::Sqrt(resX*resX + resZ*resZ); + Printf("resX = %f, resZ = %f, res = %f", resX, resZ, res); float chi2 = res; // TODO: take into account also the time! if (res < mSpaceTolerance) { // matching ok! + Printf("YUHUUUUUUUUU! We have a match!"); mMatchedTracksPairs.push_back(std::make_pair(itrk, o2::dataformats::MatchInfoTOF(itof, chi2))); // TODO: check if this is correct! } } From a8c1cb6ee32c2af2d74f032cde7709db461e1c35 Mon Sep 17 00:00:00 2001 From: Francesco Noferini Date: Wed, 3 Oct 2018 16:52:17 +0200 Subject: [PATCH 17/39] timestamp removed from TOF digits and other fixes (#6) --- .../TOF/include/DataFormatsTOF/Cluster.h | 14 ++++++------- DataFormats/Detectors/TOF/src/Cluster.cxx | 2 +- Detectors/TOF/base/include/TOFBase/Digit.h | 7 +++---- Detectors/TOF/base/src/Digit.cxx | 10 ++++------ .../TOF/reconstruction/src/Clusterer.cxx | 3 ++- .../include/TOFSimulation/Digitizer.h | 20 +++++++++++++++---- .../simulation/include/TOFSimulation/Strip.h | 2 +- Detectors/TOF/simulation/src/Digitizer.cxx | 15 +++++++------- Detectors/TOF/simulation/src/Strip.cxx | 6 +++--- .../TOF/simulation/src/TOFSimulationLinkDef.h | 1 + .../src/TOFDigitizerSpec.cxx | 10 ++++++---- 11 files changed, 52 insertions(+), 38 deletions(-) diff --git a/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h b/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h index fc3a027c91a5e..a03ed31b39726 100644 --- a/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h +++ b/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h @@ -44,16 +44,16 @@ class Cluster : public o2::BaseCluster Cluster() = default; - Cluster(std::int16_t sensid, float x, float y, float z, float sy2, float sz2, float syz, float timeRaw, float time, float tot, int L0L1latency, int deltaBC); + Cluster(std::int16_t sensid, float x, float y, float z, float sy2, float sz2, float syz, double timeRaw, double time, float tot, int L0L1latency, int deltaBC); ~Cluster() = default; void SetBaseData(std::int16_t sensid, float x, float y, float z, float sy2, float sz2, float syz); - float getTimeRaw() const { return mTimeRaw; } // Cluster ToF getter - void setTimeRaw(float timeRaw) { mTimeRaw = timeRaw; } // Cluster ToF setter - float getTime() const { return mTime; } // Cluster ToF getter - void setTime(float time) { mTime = time; } // Cluster ToF setter + double getTimeRaw() const { return mTimeRaw; } // Cluster ToF getter + void setTimeRaw(double timeRaw) { mTimeRaw = timeRaw; } // Cluster ToF setter + double getTime() const { return mTime; } // Cluster ToF getter + void setTime(double time) { mTime = time; } // Cluster ToF setter float getTot() const { return mTot; } // Cluster Charge getter void setTot(int tot) { mTot = tot; } // Cluster ToT setter int getL0L1Latency() const { return mL0L1Latency; }; // L0L1 latency @@ -111,8 +111,8 @@ class Cluster : public o2::BaseCluster private: friend class boost::serialization::access; - float mTimeRaw; // raw TOF time // CZ: in AliRoot it is a double - float mTime; // calibrated TOF time // CZ: in AliRoot it is a double + double mTimeRaw; // raw TOF time // CZ: in AliRoot it is a double + double mTime; // calibrated TOF time // CZ: in AliRoot it is a double float mTot; // Time-Over-threshold // CZ: in AliRoot it is a double int mL0L1Latency; // L0L1 latency // CZ: is it different per cluster? Checking one ESD file, it seems that it is always the same (see: /alice/data/2017/LHC17n/000280235/pass1/17000280235019.100/AliESDs.root) int mDeltaBC; // DeltaBC --> can it be a char or short? // CZ: is it different per cluster? Checking one ESD file, it seems that it can vary (see: /alice/data/2017/LHC17n/000280235/pass1/17000280235019.100/AliESDs.root) diff --git a/DataFormats/Detectors/TOF/src/Cluster.cxx b/DataFormats/Detectors/TOF/src/Cluster.cxx index 1efabe776be3a..cfc625ecf0217 100644 --- a/DataFormats/Detectors/TOF/src/Cluster.cxx +++ b/DataFormats/Detectors/TOF/src/Cluster.cxx @@ -22,7 +22,7 @@ using namespace o2::tof; ClassImp(o2::tof::Cluster); -Cluster::Cluster(std::int16_t sensid, float x, float y, float z, float sy2, float sz2, float syz, float timeRaw, float time, float tot, int L0L1Latency, int deltaBC) : o2::BaseCluster(sensid, x, y, z, sy2, sz2, syz), mTimeRaw(timeRaw), mTime(time), mTot(tot), mL0L1Latency(L0L1Latency), mDeltaBC(deltaBC), mContributingChannels(0) +Cluster::Cluster(std::int16_t sensid, float x, float y, float z, float sy2, float sz2, float syz, double timeRaw, double time, float tot, int L0L1Latency, int deltaBC) : o2::BaseCluster(sensid, x, y, z, sy2, sz2, syz), mTimeRaw(timeRaw), mTime(time), mTot(tot), mL0L1Latency(L0L1Latency), mDeltaBC(deltaBC), mContributingChannels(0) { // caching R and phi diff --git a/Detectors/TOF/base/include/TOFBase/Digit.h b/Detectors/TOF/base/include/TOFBase/Digit.h index 2e8b9edba5721..e56320c82a117 100644 --- a/Detectors/TOF/base/include/TOFBase/Digit.h +++ b/Detectors/TOF/base/include/TOFBase/Digit.h @@ -11,7 +11,6 @@ #ifndef ALICEO2_TOF_DIGIT_H_ #define ALICEO2_TOF_DIGIT_H_ -#include #include #include "Rtypes.h" @@ -21,12 +20,12 @@ namespace o2 { namespace tof { /// \class Digit /// \brief TOF digit implementation -class Digit : public o2::dataformats::TimeStamp +class Digit { public: Digit() = default; - Digit(Double_t time, Int_t channel, Int_t tdc, Int_t tot, Int_t bc, Int_t label = -1); + Digit(Int_t channel, Int_t tdc, Int_t tot, Int_t bc, Int_t label = -1); ~Digit() = default; /// Get global ordering key made of @@ -52,7 +51,7 @@ class Digit : public o2::dataformats::TimeStamp void printStream(std::ostream &stream) const; - void merge(Double_t time, Int_t tdc, Int_t tot); + void merge(Int_t tdc, Int_t tot); void getPhiAndEtaIndex(int& phi, int& eta); diff --git a/Detectors/TOF/base/src/Digit.cxx b/Detectors/TOF/base/src/Digit.cxx index 869972905cce1..4c89cb11b8c46 100644 --- a/Detectors/TOF/base/src/Digit.cxx +++ b/Detectors/TOF/base/src/Digit.cxx @@ -17,8 +17,8 @@ using namespace o2::tof; ClassImp(o2::tof::Digit); -Digit::Digit(Double_t time, Int_t channel, Int_t tdc, Int_t tot, Int_t bc, Int_t label) - : o2::dataformats::TimeStamp(time), mChannel(channel), mTDC(tdc), mTOT(tot), mBC(bc), mLabel(label), mIsUsedInCluster(kFALSE) +Digit::Digit(Int_t channel, Int_t tdc, Int_t tot, Int_t bc, Int_t label) + : mChannel(channel), mTDC(tdc), mTOT(tot), mBC(bc), mLabel(label), mIsUsedInCluster(kFALSE) { } @@ -26,8 +26,7 @@ Digit::Digit(Double_t time, Int_t channel, Int_t tdc, Int_t tot, Int_t bc, Int_t void Digit::printStream(std::ostream& stream) const { - stream << "TOF Digit: Channel " << mChannel << " TDC " << mTDC << " TOT " << mTOT << " Time " << getTimeStamp() - << "Bunch Crossing index" << mBC << " Label " << mLabel << "\n"; + stream << "TOF Digit: Channel " << mChannel << " TDC " << mTDC << " TOT " << mTOT << "Bunch Crossing index" << mBC << " Label " << mLabel << "\n"; } //______________________________________________________________________ @@ -40,14 +39,13 @@ std::ostream& operator<<(std::ostream& stream, const Digit& digi) //______________________________________________________________________ -void Digit::merge(Double_t time, Int_t tdc, Int_t tot) +void Digit::merge(Int_t tdc, Int_t tot) { // merging two digits if (tdc < mTDC) { mTDC = tdc; - setTimeStamp(time); // TODO: adjust TOT } else { // TODO: adjust TOT diff --git a/Detectors/TOF/reconstruction/src/Clusterer.cxx b/Detectors/TOF/reconstruction/src/Clusterer.cxx index d3d98b8275d5c..d7296ff1e81e0 100644 --- a/Detectors/TOF/reconstruction/src/Clusterer.cxx +++ b/Detectors/TOF/reconstruction/src/Clusterer.cxx @@ -131,7 +131,8 @@ void Clusterer::buildCluster(Cluster& c, MCLabelContainer const* digitMCTruth) } c.setMainContributingChannel(mContributingDigit[0]->getChannel()); - c.setTime(mContributingDigit[0]->getTDC() * Geo::TDCBIN); // time in ps (for now we assume it calibrated) + c.setTime(mContributingDigit[0]->getTDC() * Geo::TDCBIN + double(mContributingDigit[0]->getBC()*25000.)); // time in ps (for now we assume it calibrated) + c.setTot(mContributingDigit[0]->getTOT() * Geo::TOTBIN * 1E-3); // TOT in ns (for now we assume it calibrated) //setL0L1Latency(); // to be filled (maybe) //setDeltaBC(); // to be filled (maybe) diff --git a/Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h b/Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h index 9c9423c1a6d33..d34978e5bcb5f 100644 --- a/Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h +++ b/Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h @@ -22,6 +22,18 @@ namespace o2 { namespace tof { + +class DigitOutput +{ + public: + std::vector< std::vector > *get() {return &mVector;} + + private: + std::vector< std::vector > mVector; + + ClassDefNV(DigitOutput, 1); +}; + class Digitizer { public: @@ -66,8 +78,8 @@ class Digitizer void setContinuous(bool val) { mContinuous = val; } bool isContinuous() const { return mContinuous; } - const std::vector< std::vector >* getDigitPerTimeFrame() const {return &mDigitsPerTimeFrame;} - const std::vector >* getMCTruthPerTimeFrame() const {return &mMCTruthOutputContainerPerTimeFrame;} + DigitOutput* getDigitPerTimeFrame() {return &mDigitsPerTimeFrame;} + std::vector >* getMCTruthPerTimeFrame() {return &mMCTruthOutputContainerPerTimeFrame;} private: // parameters @@ -101,7 +113,7 @@ class Digitizer static const int MAXWINDOWS = 2; // how many readout windows we can buffer - std::vector< std::vector > mDigitsPerTimeFrame; + DigitOutput mDigitsPerTimeFrame; std::vector > mMCTruthOutputContainerPerTimeFrame; int mIcurrentReadoutWindow = 0; @@ -123,7 +135,7 @@ class Digitizer o2::dataformats::MCTruthContainer mFutureMCTruthContainer; - void fillDigitsInStrip(std::vector* strips, o2::dataformats::MCTruthContainer* mcTruthContainer, double time, int channel, int tdc, int tot, int nbc, UInt_t istrip, Int_t trackID, Int_t eventID, Int_t sourceID); + void fillDigitsInStrip(std::vector* strips, o2::dataformats::MCTruthContainer* mcTruthContainer, int channel, int tdc, int tot, int nbc, UInt_t istrip, Int_t trackID, Int_t eventID, Int_t sourceID); Int_t processHit(const HitType& hit, Double_t event_time); void addDigit(Int_t channel, UInt_t istrip, Float_t time, Float_t x, Float_t z, Float_t charge, Int_t iX, Int_t iZ, Int_t padZfired, diff --git a/Detectors/TOF/simulation/include/TOFSimulation/Strip.h b/Detectors/TOF/simulation/include/TOFSimulation/Strip.h index 244991832e500..557854a220b2b 100644 --- a/Detectors/TOF/simulation/include/TOFSimulation/Strip.h +++ b/Detectors/TOF/simulation/include/TOFSimulation/Strip.h @@ -93,7 +93,7 @@ class Strip /// @return Hit at given index (nullptr if index is out of bounds) inline const o2::tof::HitType* getHitAt(Int_t index) const { return mHits.at(index); } - Int_t addDigit(Double_t time, Int_t channel, Int_t tdc, Int_t tot, Int_t bc, Int_t lbl); // returns the MC label + Int_t addDigit(Int_t channel, Int_t tdc, Int_t tot, Int_t bc, Int_t lbl); // returns the MC label void fillOutputContainer(std::vector& digits); diff --git a/Detectors/TOF/simulation/src/Digitizer.cxx b/Detectors/TOF/simulation/src/Digitizer.cxx index 7b4835d576c50..417f567de1857 100644 --- a/Detectors/TOF/simulation/src/Digitizer.cxx +++ b/Detectors/TOF/simulation/src/Digitizer.cxx @@ -251,7 +251,7 @@ void Digitizer::addDigit(Int_t channel, UInt_t istrip, Float_t time, Float_t x, mFutureItrackID.push_back(trackID); // fill temporary digits array - mFutureDigits.emplace_back(time, channel, tdc, tot * Geo::NTOTBIN_PER_NS, nbc, lblCurrent); + mFutureDigits.emplace_back(channel, tdc, tot * Geo::NTOTBIN_PER_NS, nbc, lblCurrent); return; // don't fill if doesn't match any available readout window } @@ -273,17 +273,17 @@ void Digitizer::addDigit(Int_t channel, UInt_t istrip, Float_t time, Float_t x, mcTruthContainer = mMCTruthContainerNext[isnext - 1]; } - fillDigitsInStrip(strips, mcTruthContainer, time, channel, tdc, tot, nbc, istrip, trackID, mEventID, mSrcID); + fillDigitsInStrip(strips, mcTruthContainer, channel, tdc, tot, nbc, istrip, trackID, mEventID, mSrcID); } //______________________________________________________________________ -void Digitizer::fillDigitsInStrip(std::vector* strips, o2::dataformats::MCTruthContainer* mcTruthContainer, double time, int channel, int tdc, int tot, int nbc, UInt_t istrip, Int_t trackID, Int_t eventID, Int_t sourceID) +void Digitizer::fillDigitsInStrip(std::vector* strips, o2::dataformats::MCTruthContainer* mcTruthContainer, int channel, int tdc, int tot, int nbc, UInt_t istrip, Int_t trackID, Int_t eventID, Int_t sourceID) { int lblCurrent; if (mcTruthContainer) { lblCurrent = mcTruthContainer->getIndexedSize(); // this is the size of mHeaderArray; } - Int_t lbl = (*strips)[istrip].addDigit(time, channel, tdc, tot * Geo::NTOTBIN_PER_NS, nbc, lblCurrent); + Int_t lbl = (*strips)[istrip].addDigit(channel, tdc, tot * Geo::NTOTBIN_PER_NS, nbc, lblCurrent); if (mcTruthContainer) { if (lbl == lblCurrent) { // it means that the digit was a new one --> we have to add the info in the MC container @@ -693,7 +693,7 @@ void Digitizer::fillOutputContainer(std::vector& digits) if(mContinuous){ if(digits.size()) printf("%i) # TOF digits = %i (%x)\n",mIcurrentReadoutWindow,digits.size(),mStripsCurrent); - mDigitsPerTimeFrame.push_back(digits); + mDigitsPerTimeFrame.get()->push_back(digits); } // if(! digits.size()) return; @@ -752,7 +752,8 @@ void Digitizer::checkIfReuseFutureDigits(){ // check if digits stored very far in future match the new readout windows currently available int idigit = 0; for (auto& digit : mFutureDigits) { - int isnext = Int_t(digit.getTimeStamp() * Geo::READOUTWINDOW_INV) - (mReadoutWindowCurrent+1); // to be replaced with uncalibrated time + double timestamp = digit.getBC()*25 + digit.getTDC() * Geo::TDCBIN*1E-3; // in ns + int isnext = Int_t(timestamp * Geo::READOUTWINDOW_INV) - (mReadoutWindowCurrent+1); // to be replaced with uncalibrated time if (isnext < 0) // we jump too ahead in future, digit will be not stored LOG(INFO) << "Digit lost because we jump too ahead in future. Current RO window=" << isnext << "\n"; if (isnext < MAXWINDOWS - 1) { // move from digit buffer array to the proper window @@ -768,7 +769,7 @@ void Digitizer::checkIfReuseFutureDigits(){ int trackID = mFutureItrackID[digit.getLabel()]; int sourceID = mFutureIsource[digit.getLabel()]; int eventID = mFutureIevent[digit.getLabel()]; - fillDigitsInStrip(strips, mcTruthContainer, digit.getTimeStamp(), digit.getChannel(), digit.getTDC(), digit.getTOT(), digit.getBC(), digit.getChannel() / Geo::NPADS, trackID, eventID, sourceID); + fillDigitsInStrip(strips, mcTruthContainer, digit.getChannel(), digit.getTDC(), digit.getTOT(), digit.getBC(), digit.getChannel() / Geo::NPADS, trackID, eventID, sourceID); } // remove the element from the buffers diff --git a/Detectors/TOF/simulation/src/Strip.cxx b/Detectors/TOF/simulation/src/Strip.cxx index 0dccfcacbb4d2..492d5beae3e2e 100644 --- a/Detectors/TOF/simulation/src/Strip.cxx +++ b/Detectors/TOF/simulation/src/Strip.cxx @@ -56,7 +56,7 @@ Int_t Strip::getStripIndex(const HitType* hit) return channelID / Geo::NPADS; } //_______________________________________________________________________ -Int_t Strip::addDigit(Double_t time, Int_t channel, Int_t tdc, Int_t tot, Int_t bc, Int_t lbl) +Int_t Strip::addDigit(Int_t channel, Int_t tdc, Int_t tot, Int_t bc, Int_t lbl) { // return the MC label. We pass it also as argument, but it can change in @@ -66,9 +66,9 @@ Int_t Strip::addDigit(Double_t time, Int_t channel, Int_t tdc, Int_t tot, Int_t auto dig = findDigit(key); if (dig) { lbl = dig->getLabel(); // getting the label from the already existing digit - dig->merge(time, tdc, tot); // merging to the existing digit + dig->merge(tdc, tot); // merging to the existing digit } else { - auto digIter = mDigits.emplace(std::make_pair(key, Digit(time, channel, tdc, tot, bc, lbl))); + auto digIter = mDigits.emplace(std::make_pair(key, Digit(channel, tdc, tot, bc, lbl))); } return lbl; diff --git a/Detectors/TOF/simulation/src/TOFSimulationLinkDef.h b/Detectors/TOF/simulation/src/TOFSimulationLinkDef.h index cac2381512719..e50dfbc07b2dc 100644 --- a/Detectors/TOF/simulation/src/TOFSimulationLinkDef.h +++ b/Detectors/TOF/simulation/src/TOFSimulationLinkDef.h @@ -15,6 +15,7 @@ #pragma link off all functions; #pragma link C++ class o2::tof::Detector+; +#pragma link C++ class o2::tof::DigitOutput+; #pragma link C++ class o2::tof::Digitizer+; #pragma link C++ class o2::tof::DigitizerTask+; #pragma link C++ class o2::tof::Strip + ; diff --git a/Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx b/Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx index 5e5cb15979c2a..29c5d3d787830 100644 --- a/Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx +++ b/Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx @@ -131,15 +131,17 @@ DataProcessorSpec getTOFDigitizerSpec(int channel) // temporary accumulate vector of vecotors of digits in a single vector // to be replace once we will be able to write the vector of vectors as different TTree entries - const std::vector< std::vector >* digitsVectOfVect = digitizer->getDigitPerTimeFrame(); - const std::vector >* mcLabVecOfVec = digitizer->getMCTruthPerTimeFrame(); - for(Int_t i=0; i < digitsVectOfVect->size();i++){ - std::copy(digitsVectOfVect->at(i).begin(), digitsVectOfVect->at(i).end(), std::back_inserter(*digitsAccum.get())); + DigitOutput* digitsVectOfVect = digitizer->getDigitPerTimeFrame(); + std::vector >* mcLabVecOfVec = digitizer->getMCTruthPerTimeFrame(); + for(Int_t i=0; i < digitsVectOfVect->get()->size();i++){ + std::copy(digitsVectOfVect->get()->at(i).begin(), digitsVectOfVect->get()->at(i).end(), std::back_inserter(*digitsAccum.get())); labelAccum.mergeAtBack(mcLabVecOfVec->at(i)); } LOG(INFO) << "Have " << labelAccum.getNElements() << " TOF labels "; // here we have all digits and we can send them to consumer (aka snapshot it onto output) + //pc.outputs().snapshot(Output{ "TOF", "DIGITS", 0, Lifetime::Timeframe }, *digitsVectOfVect); + // pc.outputs().snapshot(Output{ "TOF", "DIGITSMCTR", 0, Lifetime::Timeframe }, labelAccum); pc.outputs().snapshot(Output{ "TOF", "DIGITS", 0, Lifetime::Timeframe }, *digitsAccum.get()); pc.outputs().snapshot(Output{ "TOF", "DIGITSMCTR", 0, Lifetime::Timeframe }, labelAccum); LOG(INFO) << "TOF: Sending ROMode= " << roMode << " to GRPUpdater"; From e4d19c6823cc2c6ff348ccf41fcd680ea2667224 Mon Sep 17 00:00:00 2001 From: zampolli Date: Tue, 9 Oct 2018 10:40:40 +0200 Subject: [PATCH 18/39] Important changes in digitizer output and matching - Digitizer output is now a vector of vectors (each "sub-vector" is per TOF readout frame) - Matching now seems to work (but we still don't check the time) --- .../include/GlobalTracking/MatchTOF.h | 3 ++- Detectors/GlobalTracking/src/MatchTOF.cxx | 14 ++++++++++---- Detectors/TOF/base/src/TOFBaseLinkDef.h | 1 + Steer/DigitizerWorkflow/src/TOFClusterizerSpec.cxx | 10 +++++++--- Steer/DigitizerWorkflow/src/TOFDigitWriterSpec.cxx | 4 ++-- Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx | 4 +--- 6 files changed, 23 insertions(+), 13 deletions(-) diff --git a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h index a3f1eff1fa723..c670fb7733411 100644 --- a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h +++ b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h @@ -185,7 +185,8 @@ class MatchTOF std::vector> mMatchedTracksPairs; /// mMatchedTracks; + //std::vector mMatchedTracks; + std::vector> mMatchedTracks; int mNumOfTracks; // number of tracks to be matched int* mMatchedTracksIndex = nullptr; //[mNumOfTracks] int mNumOfClusters; // number of clusters to be matched diff --git a/Detectors/GlobalTracking/src/MatchTOF.cxx b/Detectors/GlobalTracking/src/MatchTOF.cxx index 734240d93d99d..f7489eecf9ac5 100644 --- a/Detectors/GlobalTracking/src/MatchTOF.cxx +++ b/Detectors/GlobalTracking/src/MatchTOF.cxx @@ -64,6 +64,7 @@ void MatchTOF::run() mTimerTot.Start(false); } + mOutputTree->Fill(); mTimerTot.Stop(); printf("Timing:\n"); @@ -425,8 +426,8 @@ void MatchTOF::doMatching(int sec) posFloat[ii] = pos[ii]; } Geo::getPadDxDyDz(posFloat, detIdTemp, deltaPosTemp); - if (detIdTemp[2] != -1 && nStripsCrossedInPropagation == 0){ // print in case you have a match - Printf("\n\n*********** We have a match!*********"); + if (detIdTemp[2] != -1 && nStripsCrossedInPropagation == 0){ // print in case you have a useful propagation + Printf("\n\n*********** We have crossed a strip during propagation!*********"); printf("Global coordinates: pos[0] = %f, pos[1] = %f, pos[2] = %f\n", pos[0], pos[1], pos[2]); printf("detIdTemp[0] = %d, detIdTemp[1] = %d, detIdTemp[2] = %d, detIdTemp[3] = %d, detIdTemp[4] = %d\n", detIdTemp[0], detIdTemp[1], detIdTemp[2], detIdTemp[3], detIdTemp[4]); printf("deltaPosTemp[0] = %f, deltaPosTemp[1] = %f, deltaPosTemp[2] = %f\n", deltaPosTemp[0], deltaPosTemp[1], deltaPosTemp[2]); @@ -503,7 +504,7 @@ void MatchTOF::doMatching(int sec) float chi2 = res; // TODO: take into account also the time! if (res < mSpaceTolerance) { // matching ok! Printf("YUHUUUUUUUUU! We have a match!"); - mMatchedTracksPairs.push_back(std::make_pair(itrk, o2::dataformats::MatchInfoTOF(itof, chi2))); // TODO: check if this is correct! + mMatchedTracksPairs.push_back(std::make_pair(mTracksSectIndexCache[indices[0]][itrk], o2::dataformats::MatchInfoTOF(mTOFClusSectIndexCache[indices[0]][itof], chi2))); // TODO: check if this is correct! } } } @@ -519,7 +520,9 @@ void MatchTOF::selectBestMatches() // first, we sort according to the chi2 std::sort(mMatchedTracksPairs.begin(), mMatchedTracksPairs.end(), [this](std::pair a, std::pair b) { return (a.second.getChi2() < b.second.getChi2());}); + int i = 0; for (const std::pair &matchingPair : mMatchedTracksPairs){ + Printf("selectBestMatches: i = %d", i); if (mMatchedTracksIndex[matchingPair.first] != -1) { // the track was already filled continue; } @@ -528,7 +531,10 @@ void MatchTOF::selectBestMatches() } mMatchedTracksIndex[matchingPair.first] = mMatchedTracks.size(); // index of the MatchInfoTOF correspoding to this track mMatchedClustersIndex[matchingPair.second.getTOFClIndex()] = mMatchedTracksIndex[matchingPair.first]; // index of the track that was matched to this cluster - mMatchedTracks.push_back(matchingPair.second); // array of MatchInfoTOF + //mMatchedTracks.push_back(matchingPair.second); // array of MatchInfoTOF + mMatchedTracks.push_back(matchingPair); // array of MatchInfoTOF + Printf("size of mMatchedTracks = %d", mMatchedTracks.size()); + i++; } } diff --git a/Detectors/TOF/base/src/TOFBaseLinkDef.h b/Detectors/TOF/base/src/TOFBaseLinkDef.h index 4ce5aa3b7b478..3a6031119a972 100644 --- a/Detectors/TOF/base/src/TOFBaseLinkDef.h +++ b/Detectors/TOF/base/src/TOFBaseLinkDef.h @@ -17,5 +17,6 @@ #pragma link C++ class o2::tof::Geo+; #pragma link C++ class o2::tof::Digit+; #pragma link C++ class vector+; +#pragma link C++ class vector+; #endif diff --git a/Steer/DigitizerWorkflow/src/TOFClusterizerSpec.cxx b/Steer/DigitizerWorkflow/src/TOFClusterizerSpec.cxx index c7dd523b11fe8..b426bbdd8c2e1 100644 --- a/Steer/DigitizerWorkflow/src/TOFClusterizerSpec.cxx +++ b/Steer/DigitizerWorkflow/src/TOFClusterizerSpec.cxx @@ -47,16 +47,20 @@ class TOFDPLClustererTask return; } // get digit data - auto digits = pc.inputs().get*>("tofdigits"); + auto digits = pc.inputs().get>*>("tofdigits"); auto digitlabels = pc.inputs().get*>("tofdigitlabels"); - mReader.setDigitArray(digits.get()); mClusterer.setMCTruthContainer(&mClsLabels); // call actual clustering routine mClustersArray.clear(); mClsLabels.clear(); - mClusterer.process(mReader, mClustersArray, digitlabels.get()); + for(int i=0;i < digits->size();i++){ + printf("# TOF readout window for clusterization = %i\n",i); + auto digitsRO = digits->at(i); + mReader.setDigitArray(&digitsRO); + mClusterer.process(mReader, mClustersArray, digitlabels.get()); + } LOG(INFO) << "TOF CLUSTERER : TRANSFORMED " << digits->size() << " DIGITS TO " << mClustersArray.size() << " CLUSTERS"; diff --git a/Steer/DigitizerWorkflow/src/TOFDigitWriterSpec.cxx b/Steer/DigitizerWorkflow/src/TOFDigitWriterSpec.cxx index e1465ec6dacd2..56fb729cfa5cb 100644 --- a/Steer/DigitizerWorkflow/src/TOFDigitWriterSpec.cxx +++ b/Steer/DigitizerWorkflow/src/TOFDigitWriterSpec.cxx @@ -54,7 +54,7 @@ DataProcessorSpec getTOFDigitWriterSpec() auto outputtree = std::make_shared(treename.c_str(), treename.c_str()); // container for incoming digits - auto digits = std::make_shared>(); + auto digits = std::make_shared>>(); // the callback to be set as hook at stop of processing for the framework auto finishWriting = [outputfile, outputtree]() { @@ -76,7 +76,7 @@ DataProcessorSpec getTOFDigitWriterSpec() } // retrieve the digits from the input - auto indata = pc.inputs().get>("tofdigits"); + auto indata = pc.inputs().get>>("tofdigits"); LOG(INFO) << "RECEIVED DIGITS SIZE " << indata.size(); *digits.get() = std::move(indata); diff --git a/Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx b/Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx index 29c5d3d787830..406668e40f72e 100644 --- a/Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx +++ b/Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx @@ -140,9 +140,7 @@ DataProcessorSpec getTOFDigitizerSpec(int channel) LOG(INFO) << "Have " << labelAccum.getNElements() << " TOF labels "; // here we have all digits and we can send them to consumer (aka snapshot it onto output) - //pc.outputs().snapshot(Output{ "TOF", "DIGITS", 0, Lifetime::Timeframe }, *digitsVectOfVect); - // pc.outputs().snapshot(Output{ "TOF", "DIGITSMCTR", 0, Lifetime::Timeframe }, labelAccum); - pc.outputs().snapshot(Output{ "TOF", "DIGITS", 0, Lifetime::Timeframe }, *digitsAccum.get()); + pc.outputs().snapshot(Output{ "TOF", "DIGITS", 0, Lifetime::Timeframe }, *digitsVectOfVect->get()); pc.outputs().snapshot(Output{ "TOF", "DIGITSMCTR", 0, Lifetime::Timeframe }, labelAccum); LOG(INFO) << "TOF: Sending ROMode= " << roMode << " to GRPUpdater"; pc.outputs().snapshot(Output{ "TOF", "ROMode", 0, Lifetime::Timeframe }, roMode); From 00785c8f2b0bb119ff2346e8d48b5c2cbf674264 Mon Sep 17 00:00:00 2001 From: zampolli Date: Mon, 15 Oct 2018 13:14:52 +0200 Subject: [PATCH 19/39] More changes for TOF matching - including macros to run and check it --- .../ReconstructionDataFormats/MatchInfoTOF.h | 2 +- .../include/GlobalTracking/MatchTOF.h | 2 +- .../src/GlobalTrackingLinkDef.h | 6 ++ Detectors/GlobalTracking/src/MatchTOF.cxx | 38 ++++---- macro/checkTOFmatching.C | 91 +++++++++++++++++++ macro/run_match_tof.C | 72 +++++++++++++++ 6 files changed, 193 insertions(+), 18 deletions(-) create mode 100644 macro/checkTOFmatching.C create mode 100644 macro/run_match_tof.C diff --git a/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h b/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h index 3b8e71d2e0cd0..754d429347e2f 100644 --- a/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h +++ b/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h @@ -28,7 +28,7 @@ namespace dataformats int getTOFClIndex() const { return mTOFClIndex; } void setChi2(int chi2) { mChi2 = chi2; } - int getChi2() const { return mChi2; } + float getChi2() const { return mChi2; } private: diff --git a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h index c670fb7733411..41faa6cafbb7a 100644 --- a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h +++ b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h @@ -146,7 +146,7 @@ class MatchTOF // to be done later float mTimeTolerance = 1e3; /// + ; +#pragma link C++ class std::vector> + ; +#pragma link C++ class std::vector + ; +#pragma link C++ class std::vector + ; +#pragma link C++ class std::vector + ; +#pragma link C++ class std::vector + ; #endif diff --git a/Detectors/GlobalTracking/src/MatchTOF.cxx b/Detectors/GlobalTracking/src/MatchTOF.cxx index f7489eecf9ac5..fd8b33f161296 100644 --- a/Detectors/GlobalTracking/src/MatchTOF.cxx +++ b/Detectors/GlobalTracking/src/MatchTOF.cxx @@ -50,23 +50,28 @@ void MatchTOF::run() mTimerTot.Start(); - prepareTracks(); + // we load all TOF clusters (to be checked if we need to split per time frame) prepareTOFClusters(); - for (int sec = o2::constants::math::NSectors; sec--;) { - printf("doing matching...\n"); - doMatching(sec); - printf("...done. Now check the best matches\n"); - selectBestMatches(); - } - if (0) { // enabling this creates very verbose output - mTimerTot.Stop(); - printCandidatesTOF(); - mTimerTot.Start(false); - } - mOutputTree->Fill(); + // we do the matching per entry of the TPCITS matched tracks tree + while (mCurrTracksTreeEntry+1 < mInputTreeTracks->GetEntries()) { // we add "+1" because mCurrTracksTreeEntry starts from -1, and it is incremented in loadTracksNextChunk which is called by prepareTracks + mMatchedTracks.clear(); + prepareTracks(); + for (int sec = o2::constants::math::NSectors; sec--;) { + printf("\n\ndoing matching for sector %i...\n", sec); + doMatching(sec); + printf("...done. Now check the best matches\n"); + selectBestMatches(); + } + if (0) { // enabling this creates very verbose output + mTimerTot.Stop(); + printCandidatesTOF(); + mTimerTot.Start(false); + } + mOutputTree->Fill(); + } + mTimerTot.Stop(); - printf("Timing:\n"); printf("Total: "); mTimerTot.Print(); @@ -211,7 +216,8 @@ bool MatchTOF::prepareTracks() mTracksSectIndexCache[sec].clear(); mTracksSectIndexCache[sec].reserve(100 + 1.2 * mNumOfTracks / o2::constants::math::NSectors); } - + + Printf("We have %d tracks to try to match to TOF", mNumOfTracks); int nNotPropagatedToTOF = 0; for (int it = 0; it < mNumOfTracks; it++) { o2::dataformats::TrackTPCITS& trcOrig = (*mTracksArrayInp)[it]; // TODO: check if we cannot directly use the o2::track::TrackParCov class instead of o2::dataformats::TrackTPCITS, and then avoid the casting below; this is the track at the vertex @@ -328,7 +334,7 @@ bool MatchTOF::loadTracksNextChunk() ///< load next chunk of tracks to be matched to TOF while (++mCurrTracksTreeEntry < mInputTreeTracks->GetEntries()) { mInputTreeTracks->GetEntry(mCurrTracksTreeEntry); - LOG(DEBUG) << "Loading tracks entry " << mCurrTracksTreeEntry << " -> " << mTracksArrayInp->size() + LOG(INFO) << "Loading tracks entry " << mCurrTracksTreeEntry << " -> " << mTracksArrayInp->size() << " tracks" << FairLogger::endl; if (!mTracksArrayInp->size()) { continue; diff --git a/macro/checkTOFmatching.C b/macro/checkTOFmatching.C new file mode 100644 index 0000000000000..fb2a241416b8d --- /dev/null +++ b/macro/checkTOFmatching.C @@ -0,0 +1,91 @@ +void checkTOFMatching(){ + + // macro to check the matching TOF-ITSTPC tracks + + // getting TOF info + TFile* fmatchTOF = new TFile("o2match_tof.root"); + TTree* matchTOF = (TTree*)fmatchTOF->Get("matchTOF"); + std::vector>* TOFMatchInfo; + TOFMatchInfo = new std::vector>; + matchTOF->SetBranchAddress("TOFMatchInfo", &TOFMatchInfo); + + // getting the ITSTPCtracks + TFile* fmatchITSTPC = new TFile("o2match_itstpc.root"); + TTree* matchTPCITS = (TTree*)fmatchITSTPC->Get("matchTPCITS"); + std::vector* mTracksArrayInp = new std::vector; + matchTPCITS->SetBranchAddress("TPCITS", &mTracksArrayInp); + + // getting the TPC tracks + TFile* ftracksTPC = new TFile("tpctracks.root"); + TTree* tpcTree = (TTree*) ftracksTPC->Get("events"); + std::vector* mTPCTracksArrayInp = new std::vector; + tpcTree->SetBranchAddress("TPCTracks", &mTPCTracksArrayInp); + o2::dataformats::MCTruthContainer* mcTPC = new o2::dataformats::MCTruthContainer(); + tpcTree->SetBranchAddress("TPCTracksMCTruth", &mcTPC); + + // getting the ITS tracks + TFile* ftracksITS = new TFile("o2trac_its.root"); + TTree* itsTree = (TTree*) ftracksITS->Get("o2sim"); + std::vector* mITSTracksArrayInp = new std::vector; + itsTree->SetBranchAddress("ITSTrack", &mITSTracksArrayInp); + o2::dataformats::MCTruthContainer* mcITS = new o2::dataformats::MCTruthContainer(); + itsTree->SetBranchAddress("ITSTrackMCTruth", &mcITS); + + // getting the TOF clusters + TFile* fclustersTOF = new TFile("tofclusters.root"); + TTree* tofClTree = (TTree*) fclustersTOF->Get("o2sim"); + std::vector* mTOFClustersArrayInp = new std::vector; + tofClTree->SetBranchAddress("TOFCluster", &mTOFClustersArrayInp); + o2::dataformats::MCTruthContainer* mcTOF = new o2::dataformats::MCTruthContainer(); + tofClTree->SetBranchAddress("TOFClusterMCTruth", &mcTOF); + + tpcTree->GetEntry(0); + tofClTree->GetEntry(0); + + // now looping over the entries in the matching tree + for (int ientry = 0; ientry < matchTOF->GetEntries(); ientry++){ + matchTOF->GetEvent(ientry); + matchTPCITS->GetEntry(ientry); + // now looping over the matched tracks + for (int imatch = 0; imatch < TOFMatchInfo->size(); imatch++){ + int indexITSTPCtrack = TOFMatchInfo->at(imatch).first; + o2::dataformats::MatchInfoTOF infoTOF = TOFMatchInfo->at(imatch).second; + int tofClIndex = infoTOF.getTOFClIndex(); + float chi2 = infoTOF.getChi2(); + Printf("\nentry in tree %d, matching %d, indexITSTPCtrack = %d, tofClIndex = %d, chi2 = %f", ientry, imatch, indexITSTPCtrack, tofClIndex, chi2); + // o2::MCCompLabel label = mcTOF->getElement(mcTOF->getMCTruthHeader(tofClIndex).index); + const auto& labelsTOF = mcTOF->getLabels(tofClIndex); + for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++){ + Printf("TOF label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTOF[ilabel].getTrackID(), labelsTOF[ilabel].getEventID(), labelsTOF[ilabel].getSourceID()); + } + o2::dataformats::TrackTPCITS trackITSTPC = mTracksArrayInp->at(indexITSTPCtrack); + const o2::dataformats::EvIndex &evIdxTPC = trackITSTPC.getRefTPC(); + Printf("matched TPCtrack: eventID = %d, indexID = %d", evIdxTPC.getEvent(), evIdxTPC.getIndex()); + const o2::dataformats::EvIndex &evIdxITS = trackITSTPC.getRefITS(); + Printf("matched ITStrack: eventID = %d, indexID = %d", evIdxITS.getEvent(), evIdxITS.getIndex()); + itsTree->GetEntry(evIdxITS.getEvent()); + + // getting the TPC labels + const auto& labelsTPC = mcTPC->getLabels(evIdxTPC.getIndex()); + for (int ilabel = 0; ilabel < labelsTPC.size(); ilabel++){ + Printf("TPC label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTPC[ilabel].getTrackID(), labelsTPC[ilabel].getEventID(), labelsTPC[ilabel].getSourceID()); + } + + // getting the ITS labels + const auto& labelsITS = mcITS->getLabels(evIdxITS.getIndex()); + for (int ilabel = 0; ilabel < labelsITS.size(); ilabel++){ + Printf("ITS label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsITS[ilabel].getTrackID(), labelsITS[ilabel].getEventID(), labelsITS[ilabel].getSourceID()); + } + + } + + } + + + + + return; +} + + + diff --git a/macro/run_match_tof.C b/macro/run_match_tof.C new file mode 100644 index 0000000000000..d55b8d82196b6 --- /dev/null +++ b/macro/run_match_tof.C @@ -0,0 +1,72 @@ +#if !defined(__CLING__) || defined(__ROOTCLING__) +#include +#include +#include +#include +#include +#include + +#include "Field/MagneticField.h" +#include "DataFormatsParameters/GRPObject.h" +#include "DetectorsBase/GeometryManager.h" +#include "DetectorsBase/Propagator.h" + +#include "GlobalTracking/MatchTOF.h" +#endif + +void run_match_tof(std::string path = "./", std::string outputfile = "o2match_tof.root", + std::string inputTracksTPCITS = "o2match_itstpc.root", + std::string inputTracksTPC = "tpctracks.root", + std::string inputClustersTOF = "tofclusters.root", std::string inputGeom = "O2geometry.root", + std::string inputGRP = "o2sim_grp.root") +{ + + o2::globaltracking::MatchTOF matching; + + if (path.back() != '/') { + path += '/'; + } + + //>>>---------- attach input data --------------->>> + TChain tracks("matchTPCITS"); + tracks.AddFile((path + inputTracksTPCITS).data()); + matching.setInputTreeTracks(&tracks); + + TChain tpcTracks("events"); + tpcTracks.AddFile((path + inputTracksTPC).data()); + matching.setInputTreeTPCTracks(&tpcTracks); + matching.setTPCTrackBranchName("TPCTracks"); + + TChain tofClusters("o2sim"); + tofClusters.AddFile((path + inputClustersTOF).data()); + matching.setInputTreeTOFClusters(&tofClusters); + + //<<<---------- attach input data ---------------<<< + + // create/attach output tree + TFile outFile((path + outputfile).data(), "recreate"); + TTree outTree("matchTOF", "Matched TOF-tracks"); + matching.setOutputTree(&outTree); + + //-------- init geometry and field --------// + o2::Base::GeometryManager::loadGeometry(path + inputGeom, "FAIRGeom"); + o2::Base::Propagator::initFieldFromGRP(path + inputGRP); + + //-------------------- settings -----------// + /* + matching.setITSROFrameLengthMUS(5.0f); // ITS ROFrame duration in \mus + matching.setCutMatchingChi2(100.); + std::array cutsAbs = { 2.f, 2.f, 0.2f, 0.2f, 4.f }; + std::array cutsNSig2 = { 49.f, 49.f, 49.f, 49.f, 49.f }; + matching.setCrudeAbsDiffCut(cutsAbs); + matching.setCrudeNSigma2Cut(cutsNSig2); + matching.setTPCTimeEdgeZSafeMargin(3); + */ + matching.init(); + + matching.run(); + + outFile.cd(); + outTree.Write(); + outFile.Close(); +} From fbb6393d6293f7cfc9e495b593ee2c79aa9150bb Mon Sep 17 00:00:00 2001 From: Francesco Noferini Date: Tue, 16 Oct 2018 09:57:40 +0200 Subject: [PATCH 20/39] Tof rec (#8) * move tof digitizer to vec of vecs also for MC labels * ad tof test generator --- .../include/TOFSimulation/Digitizer.h | 15 +-- Detectors/TOF/simulation/src/Digitizer.cxx | 2 +- .../TOF/simulation/src/TOFSimulationLinkDef.h | 1 - Generators/src/GeneratorFactory.cxx | 12 +++ .../src/TOFClusterizerSpec.cxx | 4 +- .../src/TOFDigitWriterSpec.cxx | 6 +- .../src/TOFDigitizerSpec.cxx | 10 +- macro/checkTOFMatching.C | 91 +++++++++++++++++++ 8 files changed, 117 insertions(+), 24 deletions(-) create mode 100644 macro/checkTOFMatching.C diff --git a/Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h b/Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h index d34978e5bcb5f..3d003191c32bd 100644 --- a/Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h +++ b/Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h @@ -23,17 +23,6 @@ namespace o2 namespace tof { -class DigitOutput -{ - public: - std::vector< std::vector > *get() {return &mVector;} - - private: - std::vector< std::vector > mVector; - - ClassDefNV(DigitOutput, 1); -}; - class Digitizer { public: @@ -78,7 +67,7 @@ class Digitizer void setContinuous(bool val) { mContinuous = val; } bool isContinuous() const { return mContinuous; } - DigitOutput* getDigitPerTimeFrame() {return &mDigitsPerTimeFrame;} + std::vector< std::vector>* getDigitPerTimeFrame() {return &mDigitsPerTimeFrame;} std::vector >* getMCTruthPerTimeFrame() {return &mMCTruthOutputContainerPerTimeFrame;} private: @@ -113,7 +102,7 @@ class Digitizer static const int MAXWINDOWS = 2; // how many readout windows we can buffer - DigitOutput mDigitsPerTimeFrame; + std::vector< std::vector > mDigitsPerTimeFrame; std::vector > mMCTruthOutputContainerPerTimeFrame; int mIcurrentReadoutWindow = 0; diff --git a/Detectors/TOF/simulation/src/Digitizer.cxx b/Detectors/TOF/simulation/src/Digitizer.cxx index 417f567de1857..06557439ba3f6 100644 --- a/Detectors/TOF/simulation/src/Digitizer.cxx +++ b/Detectors/TOF/simulation/src/Digitizer.cxx @@ -693,7 +693,7 @@ void Digitizer::fillOutputContainer(std::vector& digits) if(mContinuous){ if(digits.size()) printf("%i) # TOF digits = %i (%x)\n",mIcurrentReadoutWindow,digits.size(),mStripsCurrent); - mDigitsPerTimeFrame.get()->push_back(digits); + mDigitsPerTimeFrame.push_back(digits); } // if(! digits.size()) return; diff --git a/Detectors/TOF/simulation/src/TOFSimulationLinkDef.h b/Detectors/TOF/simulation/src/TOFSimulationLinkDef.h index e50dfbc07b2dc..cac2381512719 100644 --- a/Detectors/TOF/simulation/src/TOFSimulationLinkDef.h +++ b/Detectors/TOF/simulation/src/TOFSimulationLinkDef.h @@ -15,7 +15,6 @@ #pragma link off all functions; #pragma link C++ class o2::tof::Detector+; -#pragma link C++ class o2::tof::DigitOutput+; #pragma link C++ class o2::tof::Digitizer+; #pragma link C++ class o2::tof::DigitizerTask+; #pragma link C++ class o2::tof::Strip + ; diff --git a/Generators/src/GeneratorFactory.cxx b/Generators/src/GeneratorFactory.cxx index 758c9de09cf29..89bfa2456ea50 100644 --- a/Generators/src/GeneratorFactory.cxx +++ b/Generators/src/GeneratorFactory.cxx @@ -176,6 +176,18 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair auto extgen_ptr = (TGenerator**)gROOT->GetGlobal("__extgen")->GetAddress(); tgen->setTGenerator(*extgen_ptr); primGen->AddGenerator(tgen); + } else if (genconfig.compare("toftest") == 0) { // 1 muon per sector and per module + LOG(INFO) << "Init tof test generator -> 1 muon per sector and per module"; + for(int i=0;i<18;i++){ + for(int j=0;j<5;j++){ + auto boxGen = new FairBoxGenerator(13, 1); /*protons*/ + boxGen->SetEtaRange(-0.8+0.32*j+0.15,-0.8+0.32*j + 0.17); + boxGen->SetPRange(9, 10); + boxGen->SetPhiRange(10+20.*i-1, 10+20.*i +1); + boxGen->SetDebug(kTRUE); + primGen->AddGenerator(boxGen); + } + } } else { LOG(FATAL) << "Invalid generator"; } diff --git a/Steer/DigitizerWorkflow/src/TOFClusterizerSpec.cxx b/Steer/DigitizerWorkflow/src/TOFClusterizerSpec.cxx index b426bbdd8c2e1..66114477e7a2d 100644 --- a/Steer/DigitizerWorkflow/src/TOFClusterizerSpec.cxx +++ b/Steer/DigitizerWorkflow/src/TOFClusterizerSpec.cxx @@ -48,7 +48,7 @@ class TOFDPLClustererTask } // get digit data auto digits = pc.inputs().get>*>("tofdigits"); - auto digitlabels = pc.inputs().get*>("tofdigitlabels"); + auto digitlabels = pc.inputs().get>*>("tofdigitlabels"); mClusterer.setMCTruthContainer(&mClsLabels); // call actual clustering routine @@ -59,7 +59,7 @@ class TOFDPLClustererTask printf("# TOF readout window for clusterization = %i\n",i); auto digitsRO = digits->at(i); mReader.setDigitArray(&digitsRO); - mClusterer.process(mReader, mClustersArray, digitlabels.get()); + mClusterer.process(mReader, mClustersArray, &(digitlabels->at(i))); } LOG(INFO) << "TOF CLUSTERER : TRANSFORMED " << digits->size() << " DIGITS TO " << mClustersArray.size() << " CLUSTERS"; diff --git a/Steer/DigitizerWorkflow/src/TOFDigitWriterSpec.cxx b/Steer/DigitizerWorkflow/src/TOFDigitWriterSpec.cxx index 56fb729cfa5cb..332767d234ec3 100644 --- a/Steer/DigitizerWorkflow/src/TOFDigitWriterSpec.cxx +++ b/Steer/DigitizerWorkflow/src/TOFDigitWriterSpec.cxx @@ -85,8 +85,10 @@ DataProcessorSpec getTOFDigitWriterSpec() br->Fill(); // retrieve labels from the input - auto labeldata = pc.inputs().get*>("tofdigitlabels"); - LOG(INFO) << "TOF GOT " << labeldata->getNElements() << " LABELS "; + auto labeldata = pc.inputs().get>*>("tofdigitlabels"); + for(int i=0;isize();i++){ + LOG(INFO) << "TOF GOT " << labeldata->at(i).getNElements() << " LABELS "; + } auto labeldataraw = labeldata.get(); // connect this to a particular branch auto labelbr = getOrMakeBranch(*outputtree.get(), "TOFDigitMCTruth", &labeldataraw); diff --git a/Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx b/Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx index 406668e40f72e..9c27a585542a0 100644 --- a/Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx +++ b/Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx @@ -131,17 +131,17 @@ DataProcessorSpec getTOFDigitizerSpec(int channel) // temporary accumulate vector of vecotors of digits in a single vector // to be replace once we will be able to write the vector of vectors as different TTree entries - DigitOutput* digitsVectOfVect = digitizer->getDigitPerTimeFrame(); + std::vector< std::vector>* digitsVectOfVect = digitizer->getDigitPerTimeFrame(); std::vector >* mcLabVecOfVec = digitizer->getMCTruthPerTimeFrame(); - for(Int_t i=0; i < digitsVectOfVect->get()->size();i++){ - std::copy(digitsVectOfVect->get()->at(i).begin(), digitsVectOfVect->get()->at(i).end(), std::back_inserter(*digitsAccum.get())); + for(Int_t i=0; i < digitsVectOfVect->size();i++){ + std::copy(digitsVectOfVect->at(i).begin(), digitsVectOfVect->at(i).end(), std::back_inserter(*digitsAccum.get())); labelAccum.mergeAtBack(mcLabVecOfVec->at(i)); } LOG(INFO) << "Have " << labelAccum.getNElements() << " TOF labels "; // here we have all digits and we can send them to consumer (aka snapshot it onto output) - pc.outputs().snapshot(Output{ "TOF", "DIGITS", 0, Lifetime::Timeframe }, *digitsVectOfVect->get()); - pc.outputs().snapshot(Output{ "TOF", "DIGITSMCTR", 0, Lifetime::Timeframe }, labelAccum); + pc.outputs().snapshot(Output{ "TOF", "DIGITS", 0, Lifetime::Timeframe }, *digitsVectOfVect); + pc.outputs().snapshot(Output{ "TOF", "DIGITSMCTR", 0, Lifetime::Timeframe }, *mcLabVecOfVec); LOG(INFO) << "TOF: Sending ROMode= " << roMode << " to GRPUpdater"; pc.outputs().snapshot(Output{ "TOF", "ROMode", 0, Lifetime::Timeframe }, roMode); diff --git a/macro/checkTOFMatching.C b/macro/checkTOFMatching.C new file mode 100644 index 0000000000000..fb2a241416b8d --- /dev/null +++ b/macro/checkTOFMatching.C @@ -0,0 +1,91 @@ +void checkTOFMatching(){ + + // macro to check the matching TOF-ITSTPC tracks + + // getting TOF info + TFile* fmatchTOF = new TFile("o2match_tof.root"); + TTree* matchTOF = (TTree*)fmatchTOF->Get("matchTOF"); + std::vector>* TOFMatchInfo; + TOFMatchInfo = new std::vector>; + matchTOF->SetBranchAddress("TOFMatchInfo", &TOFMatchInfo); + + // getting the ITSTPCtracks + TFile* fmatchITSTPC = new TFile("o2match_itstpc.root"); + TTree* matchTPCITS = (TTree*)fmatchITSTPC->Get("matchTPCITS"); + std::vector* mTracksArrayInp = new std::vector; + matchTPCITS->SetBranchAddress("TPCITS", &mTracksArrayInp); + + // getting the TPC tracks + TFile* ftracksTPC = new TFile("tpctracks.root"); + TTree* tpcTree = (TTree*) ftracksTPC->Get("events"); + std::vector* mTPCTracksArrayInp = new std::vector; + tpcTree->SetBranchAddress("TPCTracks", &mTPCTracksArrayInp); + o2::dataformats::MCTruthContainer* mcTPC = new o2::dataformats::MCTruthContainer(); + tpcTree->SetBranchAddress("TPCTracksMCTruth", &mcTPC); + + // getting the ITS tracks + TFile* ftracksITS = new TFile("o2trac_its.root"); + TTree* itsTree = (TTree*) ftracksITS->Get("o2sim"); + std::vector* mITSTracksArrayInp = new std::vector; + itsTree->SetBranchAddress("ITSTrack", &mITSTracksArrayInp); + o2::dataformats::MCTruthContainer* mcITS = new o2::dataformats::MCTruthContainer(); + itsTree->SetBranchAddress("ITSTrackMCTruth", &mcITS); + + // getting the TOF clusters + TFile* fclustersTOF = new TFile("tofclusters.root"); + TTree* tofClTree = (TTree*) fclustersTOF->Get("o2sim"); + std::vector* mTOFClustersArrayInp = new std::vector; + tofClTree->SetBranchAddress("TOFCluster", &mTOFClustersArrayInp); + o2::dataformats::MCTruthContainer* mcTOF = new o2::dataformats::MCTruthContainer(); + tofClTree->SetBranchAddress("TOFClusterMCTruth", &mcTOF); + + tpcTree->GetEntry(0); + tofClTree->GetEntry(0); + + // now looping over the entries in the matching tree + for (int ientry = 0; ientry < matchTOF->GetEntries(); ientry++){ + matchTOF->GetEvent(ientry); + matchTPCITS->GetEntry(ientry); + // now looping over the matched tracks + for (int imatch = 0; imatch < TOFMatchInfo->size(); imatch++){ + int indexITSTPCtrack = TOFMatchInfo->at(imatch).first; + o2::dataformats::MatchInfoTOF infoTOF = TOFMatchInfo->at(imatch).second; + int tofClIndex = infoTOF.getTOFClIndex(); + float chi2 = infoTOF.getChi2(); + Printf("\nentry in tree %d, matching %d, indexITSTPCtrack = %d, tofClIndex = %d, chi2 = %f", ientry, imatch, indexITSTPCtrack, tofClIndex, chi2); + // o2::MCCompLabel label = mcTOF->getElement(mcTOF->getMCTruthHeader(tofClIndex).index); + const auto& labelsTOF = mcTOF->getLabels(tofClIndex); + for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++){ + Printf("TOF label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTOF[ilabel].getTrackID(), labelsTOF[ilabel].getEventID(), labelsTOF[ilabel].getSourceID()); + } + o2::dataformats::TrackTPCITS trackITSTPC = mTracksArrayInp->at(indexITSTPCtrack); + const o2::dataformats::EvIndex &evIdxTPC = trackITSTPC.getRefTPC(); + Printf("matched TPCtrack: eventID = %d, indexID = %d", evIdxTPC.getEvent(), evIdxTPC.getIndex()); + const o2::dataformats::EvIndex &evIdxITS = trackITSTPC.getRefITS(); + Printf("matched ITStrack: eventID = %d, indexID = %d", evIdxITS.getEvent(), evIdxITS.getIndex()); + itsTree->GetEntry(evIdxITS.getEvent()); + + // getting the TPC labels + const auto& labelsTPC = mcTPC->getLabels(evIdxTPC.getIndex()); + for (int ilabel = 0; ilabel < labelsTPC.size(); ilabel++){ + Printf("TPC label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTPC[ilabel].getTrackID(), labelsTPC[ilabel].getEventID(), labelsTPC[ilabel].getSourceID()); + } + + // getting the ITS labels + const auto& labelsITS = mcITS->getLabels(evIdxITS.getIndex()); + for (int ilabel = 0; ilabel < labelsITS.size(); ilabel++){ + Printf("ITS label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsITS[ilabel].getTrackID(), labelsITS[ilabel].getEventID(), labelsITS[ilabel].getSourceID()); + } + + } + + } + + + + + return; +} + + + From 3ed62ff9a1f811f344546d3795f649e5ea5ae561 Mon Sep 17 00:00:00 2001 From: zampolli Date: Tue, 16 Oct 2018 10:06:51 +0200 Subject: [PATCH 21/39] Removing macro with wrong name --- macro/checkTOFmatching.C | 91 ---------------------------------------- 1 file changed, 91 deletions(-) delete mode 100644 macro/checkTOFmatching.C diff --git a/macro/checkTOFmatching.C b/macro/checkTOFmatching.C deleted file mode 100644 index fb2a241416b8d..0000000000000 --- a/macro/checkTOFmatching.C +++ /dev/null @@ -1,91 +0,0 @@ -void checkTOFMatching(){ - - // macro to check the matching TOF-ITSTPC tracks - - // getting TOF info - TFile* fmatchTOF = new TFile("o2match_tof.root"); - TTree* matchTOF = (TTree*)fmatchTOF->Get("matchTOF"); - std::vector>* TOFMatchInfo; - TOFMatchInfo = new std::vector>; - matchTOF->SetBranchAddress("TOFMatchInfo", &TOFMatchInfo); - - // getting the ITSTPCtracks - TFile* fmatchITSTPC = new TFile("o2match_itstpc.root"); - TTree* matchTPCITS = (TTree*)fmatchITSTPC->Get("matchTPCITS"); - std::vector* mTracksArrayInp = new std::vector; - matchTPCITS->SetBranchAddress("TPCITS", &mTracksArrayInp); - - // getting the TPC tracks - TFile* ftracksTPC = new TFile("tpctracks.root"); - TTree* tpcTree = (TTree*) ftracksTPC->Get("events"); - std::vector* mTPCTracksArrayInp = new std::vector; - tpcTree->SetBranchAddress("TPCTracks", &mTPCTracksArrayInp); - o2::dataformats::MCTruthContainer* mcTPC = new o2::dataformats::MCTruthContainer(); - tpcTree->SetBranchAddress("TPCTracksMCTruth", &mcTPC); - - // getting the ITS tracks - TFile* ftracksITS = new TFile("o2trac_its.root"); - TTree* itsTree = (TTree*) ftracksITS->Get("o2sim"); - std::vector* mITSTracksArrayInp = new std::vector; - itsTree->SetBranchAddress("ITSTrack", &mITSTracksArrayInp); - o2::dataformats::MCTruthContainer* mcITS = new o2::dataformats::MCTruthContainer(); - itsTree->SetBranchAddress("ITSTrackMCTruth", &mcITS); - - // getting the TOF clusters - TFile* fclustersTOF = new TFile("tofclusters.root"); - TTree* tofClTree = (TTree*) fclustersTOF->Get("o2sim"); - std::vector* mTOFClustersArrayInp = new std::vector; - tofClTree->SetBranchAddress("TOFCluster", &mTOFClustersArrayInp); - o2::dataformats::MCTruthContainer* mcTOF = new o2::dataformats::MCTruthContainer(); - tofClTree->SetBranchAddress("TOFClusterMCTruth", &mcTOF); - - tpcTree->GetEntry(0); - tofClTree->GetEntry(0); - - // now looping over the entries in the matching tree - for (int ientry = 0; ientry < matchTOF->GetEntries(); ientry++){ - matchTOF->GetEvent(ientry); - matchTPCITS->GetEntry(ientry); - // now looping over the matched tracks - for (int imatch = 0; imatch < TOFMatchInfo->size(); imatch++){ - int indexITSTPCtrack = TOFMatchInfo->at(imatch).first; - o2::dataformats::MatchInfoTOF infoTOF = TOFMatchInfo->at(imatch).second; - int tofClIndex = infoTOF.getTOFClIndex(); - float chi2 = infoTOF.getChi2(); - Printf("\nentry in tree %d, matching %d, indexITSTPCtrack = %d, tofClIndex = %d, chi2 = %f", ientry, imatch, indexITSTPCtrack, tofClIndex, chi2); - // o2::MCCompLabel label = mcTOF->getElement(mcTOF->getMCTruthHeader(tofClIndex).index); - const auto& labelsTOF = mcTOF->getLabels(tofClIndex); - for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++){ - Printf("TOF label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTOF[ilabel].getTrackID(), labelsTOF[ilabel].getEventID(), labelsTOF[ilabel].getSourceID()); - } - o2::dataformats::TrackTPCITS trackITSTPC = mTracksArrayInp->at(indexITSTPCtrack); - const o2::dataformats::EvIndex &evIdxTPC = trackITSTPC.getRefTPC(); - Printf("matched TPCtrack: eventID = %d, indexID = %d", evIdxTPC.getEvent(), evIdxTPC.getIndex()); - const o2::dataformats::EvIndex &evIdxITS = trackITSTPC.getRefITS(); - Printf("matched ITStrack: eventID = %d, indexID = %d", evIdxITS.getEvent(), evIdxITS.getIndex()); - itsTree->GetEntry(evIdxITS.getEvent()); - - // getting the TPC labels - const auto& labelsTPC = mcTPC->getLabels(evIdxTPC.getIndex()); - for (int ilabel = 0; ilabel < labelsTPC.size(); ilabel++){ - Printf("TPC label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTPC[ilabel].getTrackID(), labelsTPC[ilabel].getEventID(), labelsTPC[ilabel].getSourceID()); - } - - // getting the ITS labels - const auto& labelsITS = mcITS->getLabels(evIdxITS.getIndex()); - for (int ilabel = 0; ilabel < labelsITS.size(); ilabel++){ - Printf("ITS label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsITS[ilabel].getTrackID(), labelsITS[ilabel].getEventID(), labelsITS[ilabel].getSourceID()); - } - - } - - } - - - - - return; -} - - - From f646a46070e6e6e0f4114864065c325a5cb4c119 Mon Sep 17 00:00:00 2001 From: zampolli Date: Tue, 16 Oct 2018 12:22:42 +0200 Subject: [PATCH 22/39] Further steps in TOF matching. In this commit, there are many debug printing. At this point, we reconstruct muons generated in a box, but we fail in PbPb. --- .../include/GlobalTracking/MatchTOF.h | 4 +- Detectors/GlobalTracking/src/MatchTOF.cxx | 78 ++++++++++++------- 2 files changed, 54 insertions(+), 28 deletions(-) diff --git a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h index 41faa6cafbb7a..883e8e42b7b81 100644 --- a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h +++ b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h @@ -147,7 +147,7 @@ class MatchTOF float mTimeTolerance = 1e3; /// globalPos; + Printf("\nOriginal Track %d: getTimeMUS().getTimeStamp() = %f, getTimeMUS().getTimeStampError() = %f", it, (*mTracksArrayInp)[it].getTimeMUS().getTimeStamp() , (*mTracksArrayInp)[it].getTimeMUS().getTimeStampError()); // create working copy of track param mTracksWork.emplace_back(trcOrig);//, mCurrTracksTreeEntry, it); // make a copy of the TPC track that we have to propagate @@ -235,18 +236,24 @@ bool MatchTOF::prepareTracks() auto& trc = mTracksWork.back(); // with this we take the TPCITS track propagated to the vertex Printf("Copied Track %d: getTimeMUS().getTimeStamp() = %f, getTimeMUS().getTimeStampError() = %f", it, trc.getTimeMUS().getTimeStamp() , trc.getTimeMUS().getTimeStampError()); // propagate to matching Xref + trc.getXYZGlo(globalPos); + printf("Global coordinates Before propagating to 371 cm: globalPos[0] = %f, globalPos[1] = %f, globalPos[2] = %f\n", globalPos[0], globalPos[1], globalPos[2]); + Printf("Radius xy Before propagating to 371 cm = %f", TMath::Sqrt(globalPos[0]*globalPos[0] + globalPos[1]*globalPos[1])); + Printf("Radius xyz Before propagating to 371 cm = %f", TMath::Sqrt(globalPos[0]*globalPos[0] + globalPos[1]*globalPos[1] + globalPos[2]*globalPos[2])); + mTracksSectIndexCache[o2::utils::Angle2Sector( TMath::ATan2(globalPos[1], globalPos[0]))].push_back(mTracksWork.size() - 1); if (!propagateToRefX(trc, mXRef, 2) || TMath::Abs(trc.getZ()) > Geo::MAXHZTOF) { mTracksWork.pop_back(); // discard track whose propagation to mXRef failed, or those that go beyond TOF in z nNotPropagatedToTOF++; continue; } - // if (mMCTruthON) { + // if (mMCTruthON) { // mTracksLblWork.emplace_back(mTracksLabels->getLabels(it)[0]); // } // cache work track index - std::array globalPos; trc.getXYZGlo(globalPos); - + printf("Global coordinates After propagating to 371 cm: globalPos[0] = %f, globalPos[1] = %f, globalPos[2] = %f\n", globalPos[0], globalPos[1], globalPos[2]); + Printf("Radius xy After propagating to 371 cm = %f", TMath::Sqrt(globalPos[0]*globalPos[0] + globalPos[1]*globalPos[1])); + Printf("Radius xyz After propagating to 371 cm = %f", TMath::Sqrt(globalPos[0]*globalPos[0] + globalPos[1]*globalPos[1] + globalPos[2]*globalPos[2])); mTracksSectIndexCache[o2::utils::Angle2Sector( TMath::ATan2(globalPos[1], globalPos[0]))].push_back(mTracksWork.size() - 1); //delete trc; // Check: is this needed? } @@ -402,14 +409,13 @@ void MatchTOF::doMatching(int sec) int detId[2][5]; // at maximum one track can fall in 2 strips during the propagation; the second dimention of the array is the TOF det index float deltaPos[2][3]; // at maximum one track can fall in 2 strips during the propagation; the second dimention of the array is the residuals int nStepsInsideSameStrip[2] = {0,0}; // number of propagation steps in the same strip (since we have maximum 2 strips, it has dimention = 2) - int detIdTemp[5]; float deltaPosTemp[3]; std::array pos; std::array posBeforeProp; float posFloat[3]; for (int itrk = 0; itrk < cacheTrk.size(); itrk++) { - Printf("\n track %d", itrk); + Printf("\n\n\n\n ************ track %d **********", itrk); for (int ii = 0; ii < 2; ii++) detId[ii][2] = -1; // before trying to match, we need to inizialize the detId corresponding to the strip number to -1 int nStripsCrossedInPropagation = 0; // how many strips were hit during the propagation @@ -421,8 +427,10 @@ void MatchTOF::doMatching(int sec) trefTrk.getXYZGlo(posBeforeProp); //float posBeforeProp[3] = {trefTrk.getX(), trefTrk.getY(), trefTrk.getZ()}; // in local ref system printf("Global coordinates: posBeforeProp[0] = %f, posBeforeProp[1] = %f, posBeforeProp[2] = %f\n", posBeforeProp[0], posBeforeProp[1], posBeforeProp[2]); + Printf("Radius xy = %f", TMath::Sqrt(posBeforeProp[0]*posBeforeProp[0] + posBeforeProp[1]*posBeforeProp[1])); + Printf("Radius xyz = %f", TMath::Sqrt(posBeforeProp[0]*posBeforeProp[0] + posBeforeProp[1]*posBeforeProp[1] + posBeforeProp[2]*posBeforeProp[2])); while (propagateToRefX(trefTrk, mXRef+istep*step, step) && nStripsCrossedInPropagation <2 && mXRef+istep*step < Geo::RMAX){ - if (istep%100 == 0){ + if (1 || istep%100 == 0){ printf("istep = %d, currentPosition = %f \n", istep, mXRef+istep*step); } //float pos[3] = {trefTrk.getX(), trefTrk.getY(), trefTrk.getZ()}; // these are the coordinates in the local ref system @@ -431,9 +439,14 @@ void MatchTOF::doMatching(int sec) for (int ii = 0; ii < 3; ii++){ // we need to change the type... posFloat[ii] = pos[ii]; } + Printf("posFloat[0] = %f, posFloat[1] = %f, posFloat[2] = %f", posFloat[0], posFloat[1], posFloat[2]); + Printf("radius xy = %f", TMath::Sqrt(posFloat[0]*posFloat[0] + posFloat[1]*posFloat[1])); + Printf("radius xyz = %f", TMath::Sqrt(posFloat[0]*posFloat[0] + posFloat[1]*posFloat[1] + posFloat[2]*posFloat[2])); + int detIdTemp[5] = {-1, -1, -1, -1, -1}; Geo::getPadDxDyDz(posFloat, detIdTemp, deltaPosTemp); + Printf("detIdTemp[0] = %d, detIdTemp[1] = %d, detIdTemp[2] = %d, detIdTemp[3] = %d, detIdTemp[4] = %d", detIdTemp[0], detIdTemp[1], detIdTemp[2], detIdTemp[3], detIdTemp[4]); if (detIdTemp[2] != -1 && nStripsCrossedInPropagation == 0){ // print in case you have a useful propagation - Printf("\n\n*********** We have crossed a strip during propagation!*********"); + Printf("*********** We have crossed a strip during propagation!*********"); printf("Global coordinates: pos[0] = %f, pos[1] = %f, pos[2] = %f\n", pos[0], pos[1], pos[2]); printf("detIdTemp[0] = %d, detIdTemp[1] = %d, detIdTemp[2] = %d, detIdTemp[3] = %d, detIdTemp[4] = %d\n", detIdTemp[0], detIdTemp[1], detIdTemp[2], detIdTemp[3], detIdTemp[4]); printf("deltaPosTemp[0] = %f, deltaPosTemp[1] = %f, deltaPosTemp[2] = %f\n", deltaPosTemp[0], deltaPosTemp[1], deltaPosTemp[2]); @@ -550,24 +563,37 @@ bool MatchTOF::propagateToRefX(o2::track::TrackParCov& trc, float xRef, float st { // printf("in propagateToRefX\n"); // propagate track to matching reference X - bool refReached = o2::Base::Propagator::Instance()->PropagateToXBxByBz(trc, xRef, o2::constants::physics::MassPionCharged, MaxSnp, stepInCm, 0.);; - //printf("refReached = %d\n", (int)refReached); - return refReached; - /* - while (o2::Base::Propagator::Instance()->PropagateToXBxByBz(trc, xRef, o2::constants::physics::MassPionCharged, MaxSnp, stepInCm, 0.)) { - if (refReached) - break; // RS: tmp - // make sure the track is indeed within the sector defined by alpha - if (fabs(trc.getY()) < mXRef * tan(o2::constants::math::SectorSpanRad / 2)) { - refReached = true; - break; // ok, within + bool refReached = false; + float xStart = trc.getX(); + // the first propagation will be from 2m, if the track is not at least at 2m + if (xStart < 50.) xStart = 50.; + int istep = 1; + bool hasPropagated = o2::Base::Propagator::Instance()->PropagateToXBxByBz(trc, xStart + istep*stepInCm, o2::constants::physics::MassPionCharged, MAXSNP, stepInCm, 0.); + while (hasPropagated) { + //Printf("propagateToRefX: istep = %d", istep); + if (trc.getX() > xRef) { + refReached = true; // we reached the 371cm reference + Printf("propagateToRefX: trc.getX() > xRef --> refReached = true"); } - auto alphaNew = o2::utils::Angle2Alpha(trc.getPhiPos()); - if (!trc.rotate(alphaNew) != 0) { - break; // failed (RS: check effect on matching tracks to neighbouring sector) + istep++; + if (fabs(trc.getY()) > trc.getX() * tan(o2::constants::math::SectorSpanRad / 2)) { // we are still in the same sector + // we need to rotate the track to go to the new sector + Printf("propagateToRefX: changing sector"); + auto alphaNew = o2::utils::Angle2Alpha(trc.getPhiPos()); + if (!trc.rotate(alphaNew) != 0) { + Printf("propagateToRefX: failed to rotate"); + break; // failed (RS: check effect on matching tracks to neighbouring sector) + } } + if (refReached) break; + hasPropagated = o2::Base::Propagator::Instance()->PropagateToXBxByBz(trc, xStart + istep*stepInCm, o2::constants::physics::MassPionCharged, MAXSNP, stepInCm, 0.); } - printf("returning from propagateToRefX\n"); - return refReached && std::abs(trc.getSnp()) < MaxSnp; - */ + Printf("propagateToXRef: hasPropagate(%d) = %d", istep, hasPropagated); + if (std::abs(trc.getSnp()) > MAXSNP) Printf("propagateToRefX: condition on snp not ok, returning false"); + Printf("propagateToRefX: final x of the track = %f, refReached at the end is %d", trc.getX(), (int)refReached); + Printf("propagateToRefX: snp of teh track is %f (--> %f grad)", trc.getSnp(), TMath::ASin(trc.getSnp())*TMath::RadToDeg()); + return refReached && std::abs(trc.getSnp()) < 0.95; + //return refReached; } + + From 16f09939c71320c900d49c140c16bb1681e3bf0a Mon Sep 17 00:00:00 2001 From: zampolli Date: Tue, 30 Oct 2018 09:33:45 +0100 Subject: [PATCH 23/39] Fixing a few bugs. The current version of teh code has a lot of debug printouts, which need to be polish. I am also committing some changes to the macros. --- .../include/GlobalTracking/MatchTOF.h | 38 +++- Detectors/GlobalTracking/src/MatchTOF.cxx | 214 ++++++++++++++---- macro/checkTOFMatching.C | 94 +++++++- macro/run_match_tof.C | 10 + 4 files changed, 308 insertions(+), 48 deletions(-) diff --git a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h index 883e8e42b7b81..74480598c0756 100644 --- a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h +++ b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h @@ -115,6 +115,35 @@ class MatchTOF ///< get number of sigma used to do the matching float getSigmaTimeCut() const { return mSigmaTimeCut; } +#ifdef _ALLOW_DEBUG_TREES_ + enum DebugFlagTypes : UInt_t { + MatchTreeAll = 0x1 << 1, ///< produce matching candidates tree for all candidates + }; + ///< check if partucular flags are set + bool isDebugFlag(UInt_t flags) const { return mDBGFlags & flags; } + + ///< get debug trees flags + UInt_t getDebugFlags() const { return mDBGFlags; } + + ///< set or unset debug stream flag + void setDebugFlag(UInt_t flag, bool on = true); + + ///< set the name of output debug file + void setDebugTreeFileName(std::string name) + { + if (!name.empty()) { + mDebugTreeFileName = name; + } + } + + ///< get the name of output debug file + const std::string& getDebugTreeFileName() const { return mDebugTreeFileName; } + + ///< fill matching debug tree + void fillTOFmatchTree(const char* tname, int cacheTOF, int sectTOF, int plateTOF, int stripTOF, int padXTOF, int padZTOF, int cacheeTrk, int crossedStrip, int sectPropagation, int platePropagation, int stripPropagation, int padXPropagation, int padZPropagation, float resX, float resZ, float res, o2::dataformats::TrackTPCITS& trk); + void dumpWinnerMatches(); +#endif + private: void attachInputTrees(); bool prepareTracks(); @@ -146,7 +175,7 @@ class MatchTOF // to be done later float mTimeTolerance = 1e3; /// mDBGOut; + UInt_t mDBGFlags = 0; + std::string mDebugTreeFileName = "dbg_matchTOF.root"; ///< name for the debug tree file +#endif + ///----------- aux stuff --------------/// static constexpr float MAXSNP = 0.85; // max snp of ITS or TPC track at xRef to be matched TStopwatch mTimerTot; + TStopwatch mTimerDBG; ClassDefNV(MatchTOF, 1); }; } // namespace globaltracking diff --git a/Detectors/GlobalTracking/src/MatchTOF.cxx b/Detectors/GlobalTracking/src/MatchTOF.cxx index fe8292d152242..19c56f12febb5 100644 --- a/Detectors/GlobalTracking/src/MatchTOF.cxx +++ b/Detectors/GlobalTracking/src/MatchTOF.cxx @@ -55,8 +55,27 @@ void MatchTOF::run() // we do the matching per entry of the TPCITS matched tracks tree while (mCurrTracksTreeEntry+1 < mInputTreeTracks->GetEntries()) { // we add "+1" because mCurrTracksTreeEntry starts from -1, and it is incremented in loadTracksNextChunk which is called by prepareTracks + Printf("mCurrTracksTreeEntry = %d", mCurrTracksTreeEntry); mMatchedTracks.clear(); prepareTracks(); + + Printf("*************** Printing the tracks before starting the matching"); + + // printing the tracks + std::array globalPosTmp; + int totTracks = 0; + for (int sec = o2::constants::math::NSectors; sec--;) { + Printf("\nsector %d", sec); + auto& cacheTrkTmp = mTracksSectIndexCache[sec]; // array of cached tracks indices for this sector; reminder: they are ordered in time! + for (int itrk = 0; itrk < cacheTrkTmp.size(); itrk++){ + auto& trc = mTracksWork[cacheTrkTmp[itrk]]; + trc.getXYZGlo(globalPosTmp); + printf("Track %d [in this sector it is the %d]: Global coordinates After propagating to 371 cm: globalPos[0] = %f, globalPos[1] = %f, globalPos[2] = %f\n", totTracks, itrk, globalPosTmp[0], globalPosTmp[1], globalPosTmp[2]); + Printf("The phi angle is %f", TMath::ATan2(globalPosTmp[1], globalPosTmp[0])); + totTracks++; + } + } + for (int sec = o2::constants::math::NSectors; sec--;) { printf("\n\ndoing matching for sector %i...\n", sec); doMatching(sec); @@ -71,6 +90,10 @@ void MatchTOF::run() mOutputTree->Fill(); } +#ifdef _ALLOW_DEBUG_TREES_ + mDBGOut.reset(); +#endif + mTimerTot.Stop(); printf("Timing:\n"); printf("Total: "); @@ -98,6 +121,13 @@ void MatchTOF::init() LOG(ERROR) << "Output tree is not attached, matched tracks will not be stored" << FairLogger::endl; } +#ifdef _ALLOW_DEBUG_TREES_ + // debug streamer + if (mDBGFlags) { + mDBGOut = std::make_unique(mDebugTreeFileName.data(), "recreate"); + } +#endif + mInitDone = true; { @@ -231,6 +261,7 @@ bool MatchTOF::prepareTracks() Printf("\nOriginal Track %d: getTimeMUS().getTimeStamp() = %f, getTimeMUS().getTimeStampError() = %f", it, (*mTracksArrayInp)[it].getTimeMUS().getTimeStamp() , (*mTracksArrayInp)[it].getTimeMUS().getTimeStampError()); // create working copy of track param mTracksWork.emplace_back(trcOrig);//, mCurrTracksTreeEntry, it); + Printf("Before checking propagation: mTracksWork size = %d", mTracksWork.size()); // make a copy of the TPC track that we have to propagate //o2::TPC::TrackTPC* trc = new o2::TPC::TrackTPC(trcTPCOrig); // this would take the TPCout track auto& trc = mTracksWork.back(); // with this we take the TPCITS track propagated to the vertex @@ -240,13 +271,20 @@ bool MatchTOF::prepareTracks() printf("Global coordinates Before propagating to 371 cm: globalPos[0] = %f, globalPos[1] = %f, globalPos[2] = %f\n", globalPos[0], globalPos[1], globalPos[2]); Printf("Radius xy Before propagating to 371 cm = %f", TMath::Sqrt(globalPos[0]*globalPos[0] + globalPos[1]*globalPos[1])); Printf("Radius xyz Before propagating to 371 cm = %f", TMath::Sqrt(globalPos[0]*globalPos[0] + globalPos[1]*globalPos[1] + globalPos[2]*globalPos[2])); - mTracksSectIndexCache[o2::utils::Angle2Sector( TMath::ATan2(globalPos[1], globalPos[0]))].push_back(mTracksWork.size() - 1); + // mTracksSectIndexCache[o2::utils::Angle2Sector( TMath::ATan2(globalPos[1], globalPos[0]))].push_back(mTracksWork.size() - 1); if (!propagateToRefX(trc, mXRef, 2) || TMath::Abs(trc.getZ()) > Geo::MAXHZTOF) { - mTracksWork.pop_back(); // discard track whose propagation to mXRef failed, or those that go beyond TOF in z + Printf("The track failed propagation"); + Printf("After checking propagation: mTracksWork size = %d", mTracksWork.size()); + //mTracksWork.pop_back(); // discard track whose propagation to mXRef failed, or those that go beyond TOF in z nNotPropagatedToTOF++; continue; } - // if (mMCTruthON) { + else { + Printf("The track succeeded propagation"); + } + Printf("After checking propagation: mTracksWork size = %d", mTracksWork.size()); + + // if (mMCTruthON) { // mTracksLblWork.emplace_back(mTracksLabels->getLabels(it)[0]); // } // cache work track index @@ -254,7 +292,10 @@ bool MatchTOF::prepareTracks() printf("Global coordinates After propagating to 371 cm: globalPos[0] = %f, globalPos[1] = %f, globalPos[2] = %f\n", globalPos[0], globalPos[1], globalPos[2]); Printf("Radius xy After propagating to 371 cm = %f", TMath::Sqrt(globalPos[0]*globalPos[0] + globalPos[1]*globalPos[1])); Printf("Radius xyz After propagating to 371 cm = %f", TMath::Sqrt(globalPos[0]*globalPos[0] + globalPos[1]*globalPos[1] + globalPos[2]*globalPos[2])); - mTracksSectIndexCache[o2::utils::Angle2Sector( TMath::ATan2(globalPos[1], globalPos[0]))].push_back(mTracksWork.size() - 1); + Printf("Before pushing: mTracksWork size = %d", mTracksWork.size()); + Printf("The track will go to sector %d", o2::utils::Angle2Sector(TMath::ATan2(globalPos[1], globalPos[0]))); + //mTracksSectIndexCache[o2::utils::Angle2Sector(TMath::ATan2(globalPos[1], globalPos[0]))].push_back(mTracksWork.size() - 1); + mTracksSectIndexCache[o2::utils::Angle2Sector(TMath::ATan2(globalPos[1], globalPos[0]))].push_back(it); //delete trc; // Check: is this needed? } @@ -273,6 +314,23 @@ bool MatchTOF::prepareTracks() }); } // loop over tracks of single sector + /* + // printing the tracks + std::array globalPos; + int itmp = 0; + for (int sec = o2::constants::math::NSectors; sec--;) { + Printf("sector %d", sec); + auto& cacheTrk = mTracksSectIndexCache[sec]; // array of cached tracks indices for this sector; reminder: they are ordered in time! + for (int itrk = 0; itrk < cacheTrk.size(); itrk++){ + itmp++; + auto& trc = mTracksWork[cacheTrk[itrk]]; + trc.getXYZGlo(globalPos); + printf("Track %d: Global coordinates After propagating to 371 cm: globalPos[0] = %f, globalPos[1] = %f, globalPos[2] = %f\n", itrk, globalPos[0], globalPos[1], globalPos[2]); + // Printf("The phi angle is %f", TMath::ATan2(globalPos[1], globalPos[0])); + } + } + Printf("we have %d tracks",itmp); + */ return true; } //______________________________________________ @@ -398,6 +456,18 @@ void MatchTOF::doMatching(int sec) mMatchedTracksPairs.clear(); // new sector + /* + // printing the tracks + std::array globalPosTmp; + Printf("sector %d", sec); + auto& cacheTrkTmp = mTracksSectIndexCache[sec]; // array of cached tracks indices for this sector; reminder: they are ordered in time! + for (int itrk = 0; itrk < cacheTrkTmp.size(); itrk++){ + auto& trc = mTracksWork[cacheTrkTmp[itrk]]; + trc.getXYZGlo(globalPosTmp); + printf("Track %d: Global coordinates After propagating to 371 cm: globalPos[0] = %f, globalPos[1] = %f, globalPos[2] = %f\n", itrk, globalPosTmp[0], globalPosTmp[1], globalPosTmp[2]); + Printf("The phi angle is %f", TMath::ATan2(globalPosTmp[1], globalPosTmp[0])); + } + */ auto& cacheTOF = mTOFClusSectIndexCache[sec]; // array of cached TOF cluster indices for this sector; reminder: they are ordered in time! auto& cacheTrk = mTracksSectIndexCache[sec]; // array of cached tracks indices for this sector; reminder: they are ordered in time! int nTracks = cacheTrk.size(), nTOFCls = cacheTOF.size(); @@ -416,9 +486,11 @@ void MatchTOF::doMatching(int sec) for (int itrk = 0; itrk < cacheTrk.size(); itrk++) { Printf("\n\n\n\n ************ track %d **********", itrk); - for (int ii = 0; ii < 2; ii++) - detId[ii][2] = -1; // before trying to match, we need to inizialize the detId corresponding to the strip number to -1 - int nStripsCrossedInPropagation = 0; // how many strips were hit during the propagation + for (int ii = 0; ii < 2; ii++) { + detId[ii][2] = -1; // before trying to match, we need to inizialize the detId corresponding to the strip number to -1; this is the array that we will use to save the det id of the maximum 2 strips matched + nStepsInsideSameStrip[ii] = 0; + } + int nStripsCrossedInPropagation = 0; // how many strips were hit during the propagation auto& trefTrk = mTracksWork[cacheTrk[itrk]]; float minTrkTime = (trefTrk.getTimeMUS().getTimeStamp() - mSigmaTimeCut*trefTrk.getTimeMUS().getTimeStampError())*1.E6; // minimum time in ps float maxTrkTime = (trefTrk.getTimeMUS().getTimeStamp() + mSigmaTimeCut*trefTrk.getTimeMUS().getTimeStampError())*1.E6; // maximum time in ps @@ -429,8 +501,17 @@ void MatchTOF::doMatching(int sec) printf("Global coordinates: posBeforeProp[0] = %f, posBeforeProp[1] = %f, posBeforeProp[2] = %f\n", posBeforeProp[0], posBeforeProp[1], posBeforeProp[2]); Printf("Radius xy = %f", TMath::Sqrt(posBeforeProp[0]*posBeforeProp[0] + posBeforeProp[1]*posBeforeProp[1])); Printf("Radius xyz = %f", TMath::Sqrt(posBeforeProp[0]*posBeforeProp[0] + posBeforeProp[1]*posBeforeProp[1] + posBeforeProp[2]*posBeforeProp[2])); - while (propagateToRefX(trefTrk, mXRef+istep*step, step) && nStripsCrossedInPropagation <2 && mXRef+istep*step < Geo::RMAX){ - if (1 || istep%100 == 0){ + + (*mDBGOut) << "propOK" + << "track=" << trefTrk << "\n"; + // initializing + for (int ii = 0; ii < 2; ii++){ + for (int iii = 0; iii < 5; iii++){ + detId[ii][iii] = -1; + } + } + while (propagateToRefX(trefTrk, mXRef+istep*step, step) && nStripsCrossedInPropagation <=2 && mXRef+istep*step < Geo::RMAX){ + if (0 || istep%100 == 0){ printf("istep = %d, currentPosition = %f \n", istep, mXRef+istep*step); } //float pos[3] = {trefTrk.getX(), trefTrk.getY(), trefTrk.getZ()}; // these are the coordinates in the local ref system @@ -439,12 +520,13 @@ void MatchTOF::doMatching(int sec) for (int ii = 0; ii < 3; ii++){ // we need to change the type... posFloat[ii] = pos[ii]; } - Printf("posFloat[0] = %f, posFloat[1] = %f, posFloat[2] = %f", posFloat[0], posFloat[1], posFloat[2]); - Printf("radius xy = %f", TMath::Sqrt(posFloat[0]*posFloat[0] + posFloat[1]*posFloat[1])); - Printf("radius xyz = %f", TMath::Sqrt(posFloat[0]*posFloat[0] + posFloat[1]*posFloat[1] + posFloat[2]*posFloat[2])); - int detIdTemp[5] = {-1, -1, -1, -1, -1}; + //Printf("posFloat[0] = %f, posFloat[1] = %f, posFloat[2] = %f", posFloat[0], posFloat[1], posFloat[2]); + //Printf("radius xy = %f", TMath::Sqrt(posFloat[0]*posFloat[0] + posFloat[1]*posFloat[1])); + //Printf("radius xyz = %f", TMath::Sqrt(posFloat[0]*posFloat[0] + posFloat[1]*posFloat[1] + posFloat[2]*posFloat[2])); + int detIdTemp[5] = {-1, -1, -1, -1, -1}; // TOF detector id at the current propagation point Geo::getPadDxDyDz(posFloat, detIdTemp, deltaPosTemp); - Printf("detIdTemp[0] = %d, detIdTemp[1] = %d, detIdTemp[2] = %d, detIdTemp[3] = %d, detIdTemp[4] = %d", detIdTemp[0], detIdTemp[1], detIdTemp[2], detIdTemp[3], detIdTemp[4]); + + //Printf("detIdTemp[0] = %d, detIdTemp[1] = %d, detIdTemp[2] = %d, detIdTemp[3] = %d, detIdTemp[4] = %d", detIdTemp[0], detIdTemp[1], detIdTemp[2], detIdTemp[3], detIdTemp[4]); if (detIdTemp[2] != -1 && nStripsCrossedInPropagation == 0){ // print in case you have a useful propagation Printf("*********** We have crossed a strip during propagation!*********"); printf("Global coordinates: pos[0] = %f, pos[1] = %f, pos[2] = %f\n", pos[0], pos[1], pos[2]); @@ -455,15 +537,18 @@ void MatchTOF::doMatching(int sec) istep++; // check if after the propagation we are in a TOF strip if (detIdTemp[2] != -1) { // we ended in a TOF strip - Printf("We are in a TOF strip!"); - if(nStripsCrossedInPropagation == 0 || detId[nStripsCrossedInPropagation-1][0] != detIdTemp[0] || - detId[nStripsCrossedInPropagation-1][1] != detIdTemp[1] || - detId[nStripsCrossedInPropagation-1][2] != detIdTemp[2]) { - if(nStripsCrossedInPropagation == 2) break; // we have already matched 2 strips, we cannot match more - nStripsCrossedInPropagation++; - } - - if(nStepsInsideSameStrip[nStripsCrossedInPropagation-1] == 0){ + Printf("We are in a TOF strip! %d", detIdTemp[2]); + Printf("nStripsCrossedInPropagation = %d, detId[nStripsCrossedInPropagation-1][0] = %d, detIdTemp[0] = %d, detId[nStripsCrossedInPropagation-1][1] = %d, detIdTemp[1] =%d, detId[nStripsCrossedInPropagation-1][2] = %d, detIdTemp[2] = %d", nStripsCrossedInPropagation, detId[nStripsCrossedInPropagation-1][0], detIdTemp[0], detId[nStripsCrossedInPropagation-1][1], detIdTemp[1], detId[nStripsCrossedInPropagation-1][2], detIdTemp[2]); + if(nStripsCrossedInPropagation == 0 || // we are crossing a strip for the first time... + (nStripsCrossedInPropagation >= 1 && (detId[nStripsCrossedInPropagation-1][0] != detIdTemp[0] || detId[nStripsCrossedInPropagation-1][1] != detIdTemp[1] || detId[nStripsCrossedInPropagation-1][2] != detIdTemp[2]))) { // ...or we are crossing a new strip + if (nStripsCrossedInPropagation == 0) Printf("We cross a strip for the first time"); + if(nStripsCrossedInPropagation == 2) { + break; // we have already matched 2 strips, we cannot match more + } + nStripsCrossedInPropagation++; + } + Printf("nStepsInsideSameStrip[nStripsCrossedInPropagation-1] = %d", nStepsInsideSameStrip[nStripsCrossedInPropagation-1]); + if(nStepsInsideSameStrip[nStripsCrossedInPropagation-1] == 0){ detId[nStripsCrossedInPropagation-1][0] = detIdTemp[0]; detId[nStripsCrossedInPropagation-1][1] = detIdTemp[1]; detId[nStripsCrossedInPropagation-1][2] = detIdTemp[2]; @@ -474,59 +559,72 @@ void MatchTOF::doMatching(int sec) deltaPos[nStripsCrossedInPropagation-1][2] = deltaPosTemp[2]; nStepsInsideSameStrip[nStripsCrossedInPropagation-1]++; } - else{ // a further propagation step in the same strip -> update info (we average on all matching with strip) - deltaPos[nStripsCrossedInPropagation-1][0] += deltaPosTemp[0] + (detIdTemp[4] - detId[nStripsCrossedInPropagation-1][4])*Geo::XPAD; - deltaPos[nStripsCrossedInPropagation-1][1] += deltaPosTemp[1]; - deltaPos[nStripsCrossedInPropagation-1][2] += deltaPosTemp[2] + (detIdTemp[3] - detId[nStripsCrossedInPropagation-1][3])*Geo::ZPAD; + else{ // a further propagation step in the same strip -> update info (we sum up on all matching with strip - we will divide for the number of steps a bit below) + deltaPos[nStripsCrossedInPropagation-1][0] += deltaPosTemp[0] + (detIdTemp[4] - detId[nStripsCrossedInPropagation-1][4])*Geo::XPAD; // residual in x + deltaPos[nStripsCrossedInPropagation-1][1] += deltaPosTemp[1]; // residual in y + deltaPos[nStripsCrossedInPropagation-1][2] += deltaPosTemp[2] + (detIdTemp[3] - detId[nStripsCrossedInPropagation-1][3])*Geo::ZPAD; // residual in z nStepsInsideSameStrip[nStripsCrossedInPropagation-1]++; } } } printf("while done, we propagated track %d in %d strips\n", itrk, nStripsCrossedInPropagation); - for(Int_t imatch = 0; imatch < nStripsCrossedInPropagation;imatch++){ + for(Int_t imatch = 0; imatch < nStripsCrossedInPropagation; imatch++){ //printf("imatch = %d\n", imatch); // we take as residual the average of the residuals along the propagation in the same strip deltaPos[imatch][0] /= nStepsInsideSameStrip[imatch]; deltaPos[imatch][1] /= nStepsInsideSameStrip[imatch]; deltaPos[imatch][2] /= nStepsInsideSameStrip[imatch]; - printf("matched strip %d: deltaPos[0] = %f, deltaPos[1] = %f, deltaPos[2] = %f\n", imatch, deltaPos[imatch][0], deltaPos[imatch][1], deltaPos[imatch][2]); + printf("matched strip %d: deltaPos[0] = %f, deltaPos[1] = %f, deltaPos[2] = %f, residual (x, z) = %f\n", imatch, deltaPos[imatch][0], deltaPos[imatch][1], deltaPos[imatch][2], TMath::Sqrt(deltaPos[imatch][0]*deltaPos[imatch][0] + deltaPos[imatch][2]*deltaPos[imatch][2])); } - + if (nStripsCrossedInPropagation == 0) continue; // the track never hit a TOF strip during the propagation Printf("We will check now the %d TOF clusters", nTOFCls); + bool foundCluster = false; for (auto itof = itof0; itof < nTOFCls; itof++) { printf("itof = %d\n", itof); auto& trefTOF = mTOFClusWork[cacheTOF[itof]]; // compare the times of the track and the TOF clusters - remember that they both are ordered in time! Printf("trefTOF.getTime() = %f, maxTrkTime = %f, minTrkTime = %f", trefTOF.getTime(), maxTrkTime, minTrkTime); - if (trefTOF.getTime() < minTrkTime) { - itof0 = itof; - // continue; + /* This part is commented out for now, as we don't want to have any check on the time enabled + if (trefTOF.getTime() < minTrkTime) { // this cluster has a time that is too small for the current track, we will get to the next one + Printf("In trefTOF.getTime() < minTrkTime"); + itof0 = itof+1; // but for the next track that we will check, we will ignore this cluster (the time is anyway too small) + //continue; } if (trefTOF.getTime() > maxTrkTime) { // no more TOF clusters can be matched to this track // break; } + */ int mainChannel = trefTOF.getMainContributingChannel(); int indices[5]; Geo::getVolumeIndices(mainChannel, indices); for (auto iPropagation = 0; iPropagation < nStripsCrossedInPropagation; iPropagation++){ printf("iPropagation = %d\n", iPropagation); - Printf("indices[0] = %d, indices[1] = %d, indices[2] = %d, detId[iPropagation][0] = %d, detId[iPropagation][1] = %d, detId[iPropagation][2] = %d", indices[0], indices[1], indices[2], detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2]); - if (indices[0] != detId[iPropagation][0]) continue; - if (indices[1] != detId[iPropagation][1]) continue; - if (indices[2] != detId[iPropagation][2]) continue; + Printf("TOF Cluster [%d, %d]: indices = %d, %d, %d, %d, %d", itof, cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4]); + Printf("Propagated Track [%d, %d]: detId[%d] = %d, %d, %d, %d, %d", itrk, cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4]); float resX = deltaPos[iPropagation][0] - (indices[4] - detId[iPropagation][4])*Geo::XPAD; // readjusting the residuals due to the fact that the propagation fell in a pad that was not exactly the one of the cluster float resZ = deltaPos[iPropagation][2] - (indices[3] - detId[iPropagation][3])*Geo::ZPAD; // readjusting the residuals due to the fact that the propagation fell in a pad that was not exactly the one of the cluster float res = TMath::Sqrt(resX*resX + resZ*resZ); Printf("resX = %f, resZ = %f, res = %f", resX, resZ, res); +#ifdef _ALLOW_DEBUG_TREES_ + Printf("Ready to fill the debug tree"); + fillTOFmatchTree("match0",cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk); +#endif + if (indices[0] != detId[iPropagation][0]) continue; + if (indices[1] != detId[iPropagation][1]) continue; + if (indices[2] != detId[iPropagation][2]) continue; float chi2 = res; // TODO: take into account also the time! + fillTOFmatchTree("match1",cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk); + if (res < mSpaceTolerance) { // matching ok! - Printf("YUHUUUUUUUUU! We have a match!"); + Printf("YUHUUUUUUUUU! We have a match! between track %d and TOF cluster %d", mTracksSectIndexCache[indices[0]][itrk], mTOFClusSectIndexCache[indices[0]][itof]); + foundCluster = true; mMatchedTracksPairs.push_back(std::make_pair(mTracksSectIndexCache[indices[0]][itrk], o2::dataformats::MatchInfoTOF(mTOFClusSectIndexCache[indices[0]][itof], chi2))); // TODO: check if this is correct! } } } + if (!foundCluster) Printf("We did not find any TOF cluster for track %d", cacheTrk[itrk]); } return; } @@ -573,27 +671,53 @@ bool MatchTOF::propagateToRefX(o2::track::TrackParCov& trc, float xRef, float st //Printf("propagateToRefX: istep = %d", istep); if (trc.getX() > xRef) { refReached = true; // we reached the 371cm reference - Printf("propagateToRefX: trc.getX() > xRef --> refReached = true"); + // Printf("propagateToRefX: trc.getX() > xRef --> refReached = true"); } istep++; if (fabs(trc.getY()) > trc.getX() * tan(o2::constants::math::SectorSpanRad / 2)) { // we are still in the same sector // we need to rotate the track to go to the new sector - Printf("propagateToRefX: changing sector"); + //Printf("propagateToRefX: changing sector"); auto alphaNew = o2::utils::Angle2Alpha(trc.getPhiPos()); if (!trc.rotate(alphaNew) != 0) { - Printf("propagateToRefX: failed to rotate"); + //Printf("propagateToRefX: failed to rotate"); break; // failed (RS: check effect on matching tracks to neighbouring sector) } } if (refReached) break; hasPropagated = o2::Base::Propagator::Instance()->PropagateToXBxByBz(trc, xStart + istep*stepInCm, o2::constants::physics::MassPionCharged, MAXSNP, stepInCm, 0.); } - Printf("propagateToXRef: hasPropagate(%d) = %d", istep, hasPropagated); + // Printf("propagateToXRef: hasPropagate(%d) = %d", istep, hasPropagated); if (std::abs(trc.getSnp()) > MAXSNP) Printf("propagateToRefX: condition on snp not ok, returning false"); - Printf("propagateToRefX: final x of the track = %f, refReached at the end is %d", trc.getX(), (int)refReached); - Printf("propagateToRefX: snp of teh track is %f (--> %f grad)", trc.getSnp(), TMath::ASin(trc.getSnp())*TMath::RadToDeg()); + //Printf("propagateToRefX: final x of the track = %f, refReached at the end is %d", trc.getX(), (int)refReached); + //Printf("propagateToRefX: snp of teh track is %f (--> %f grad)", trc.getSnp(), TMath::ASin(trc.getSnp())*TMath::RadToDeg()); return refReached && std::abs(trc.getSnp()) < 0.95; //return refReached; } - +#ifdef _ALLOW_DEBUG_TREES_ +//______________________________________________ +void MatchTOF::setDebugFlag(UInt_t flag, bool on) +{ + ///< set debug stream flag + if (on) { + mDBGFlags |= flag; + } else { + mDBGFlags &= ~flag; + } +} + +//_________________________________________________________ +void MatchTOF::fillTOFmatchTree(const char* trname, int cacheTOF, int sectTOF, int plateTOF, int stripTOF, int padXTOF, int padZTOF, int cacheeTrk, int crossedStrip, int sectPropagation, int platePropagation, int stripPropagation, int padXPropagation, int padZPropagation, float resX, float resZ, float res, o2::dataformats::TrackTPCITS &trk) +{ + ///< fill debug tree for TOF tracks matching check + + mTimerDBG.Start(false); + + Printf("************** Filling the debug tree with %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %f, %f, %f", cacheTOF, sectTOF, plateTOF, stripTOF, padXTOF, padZTOF, cacheeTrk, crossedStrip, sectPropagation, platePropagation, stripPropagation, padXPropagation, padZPropagation, resX, resZ, res); + (*mDBGOut) << trname + << "clusterTOF=" << cacheTOF << "sectTOF=" << sectTOF << "plateTOF=" << plateTOF << "stripTOF=" << stripTOF << "padXTOF=" << padXTOF << "padZTOF=" << padZTOF + << "crossedStrip=" << crossedStrip << "sectPropagation=" << sectPropagation << "platePropagation=" << platePropagation << "stripPropagation=" << stripPropagation << "padXPropagation=" << padXPropagation + << "resX=" << resX << "resZ=" << resZ << "res=" << res << "track=" << trk << "\n"; + mTimerDBG.Stop(); +} +#endif diff --git a/macro/checkTOFMatching.C b/macro/checkTOFMatching.C index fb2a241416b8d..0686028d2581a 100644 --- a/macro/checkTOFMatching.C +++ b/macro/checkTOFMatching.C @@ -41,23 +41,77 @@ void checkTOFMatching(){ tpcTree->GetEntry(0); tofClTree->GetEntry(0); - + + int nMatches = 0; + int nGoodMatches = 0; + int nBadMatches = 0; + // now looping over the entries in the matching tree for (int ientry = 0; ientry < matchTOF->GetEntries(); ientry++){ matchTOF->GetEvent(ientry); matchTPCITS->GetEntry(ientry); // now looping over the matched tracks + nMatches += TOFMatchInfo->size(); for (int imatch = 0; imatch < TOFMatchInfo->size(); imatch++){ int indexITSTPCtrack = TOFMatchInfo->at(imatch).first; o2::dataformats::MatchInfoTOF infoTOF = TOFMatchInfo->at(imatch).second; int tofClIndex = infoTOF.getTOFClIndex(); float chi2 = infoTOF.getChi2(); Printf("\nentry in tree %d, matching %d, indexITSTPCtrack = %d, tofClIndex = %d, chi2 = %f", ientry, imatch, indexITSTPCtrack, tofClIndex, chi2); + // o2::MCCompLabel label = mcTOF->getElement(mcTOF->getMCTruthHeader(tofClIndex).index); const auto& labelsTOF = mcTOF->getLabels(tofClIndex); + int trackIdTOF; + int eventIdTOF; + int sourceIdTOF; for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++){ Printf("TOF label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTOF[ilabel].getTrackID(), labelsTOF[ilabel].getEventID(), labelsTOF[ilabel].getSourceID()); + if (ilabel == 0){ + trackIdTOF = labelsTOF[ilabel].getTrackID(); + eventIdTOF = labelsTOF[ilabel].getEventID(); + sourceIdTOF = labelsTOF[ilabel].getSourceID(); + } + } + o2::tof::Cluster tofCluster = mTOFClustersArrayInp->at(tofClIndex); + int nContributingChannels = tofCluster.getNumOfContributingChannels(); + int mainContributingChannel = tofCluster.getMainContributingChannel(); + Printf("The TOF cluster has %d contributing channels, and the main one is %d", nContributingChannels, mainContributingChannel); + int* indices; + o2::tof::Geo::getVolumeIndices(mainContributingChannel, indices); + Printf("Indices of main contributing channel are %d, %d, %d, %d, %d", indices[0], indices[1], indices[2], indices[3], indices[4]); + int* secondaryContributingChannels = new int[nContributingChannels]; + for (int ich = 1; ich < nContributingChannels; ich++) { + bool isUpLeft = tofCluster.isUpLeftContributing(); + bool isUp = tofCluster.isUpContributing(); + bool isUpRight = tofCluster.isUpRightContributing(); + bool isRight = tofCluster.isRightContributing(); + bool isDownRight = tofCluster.isDownRightContributing(); + bool isDown = tofCluster.isDownContributing(); + bool isDownLeft = tofCluster.isDownLeftContributing(); + bool isLeft = tofCluster.isLeftContributing(); + Printf("isUpLeft = %d, isUp = %d, isUpRight = %d, isRight = %d, isDownRight = %d, isDown = %d, isDownLeft = %d, isLeft = %d", isUpLeft, isUp, isUpRight, isRight, isDownRight, isDown, isDownLeft, isLeft); + int* indexCont = new int(); + indexCont[0] = indices[0]; + indexCont[1] = indices[1]; + indexCont[2] = indices[2]; + indexCont[3] = indices[3]; + indexCont[4] = indices[4]; + if (isDown || isDownRight || isDownLeft) { // decrease padZ + indexCont[3]--; + } + if (isUp || isUpRight || isUpLeft) { // decrease padZ + indexCont[3]++; + } + if (isRight || isDownRight || isUpRight) { // decrease padZ + indexCont[4]++; + } + if (isLeft || isDownLeft || isUpLeft) { // decrease padZ + indexCont[4]--; + } + secondaryContributingChannels[ich-1] = o2::tof::Geo::getIndex(indexCont); + Printf("secondaryContributingChannels[%d] = %d", ich-1, secondaryContributingChannels[ich-1]); } + o2::dataformats::TrackTPCITS trackITSTPC = mTracksArrayInp->at(indexITSTPCtrack); const o2::dataformats::EvIndex &evIdxTPC = trackITSTPC.getRefTPC(); Printf("matched TPCtrack: eventID = %d, indexID = %d", evIdxTPC.getEvent(), evIdxTPC.getIndex()); @@ -77,11 +131,47 @@ void checkTOFMatching(){ Printf("ITS label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsITS[ilabel].getTrackID(), labelsITS[ilabel].getEventID(), labelsITS[ilabel].getSourceID()); } + bool bMatched = kFALSE; + for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++){ + if ((labelsTPC[0].getTrackID() == labelsTOF[ilabel].getTrackID() && labelsTPC[0].getEventID() == labelsTOF[ilabel].getEventID() && labelsTPC[0].getSourceID() == labelsTOF[ilabel].getSourceID()) || (labelsITS[0].getTrackID() == labelsTOF[ilabel].getTrackID() && labelsITS[0].getEventID() == labelsTOF[ilabel].getEventID() && labelsITS[0].getSourceID() == labelsTOF[ilabel].getSourceID())) { + nGoodMatches++; + bMatched = kTRUE; + break; + } + } + if (!bMatched) nBadMatches++; + + bool TPCfound = false; + bool ITSfound = false; + for (int i = 0; i < mTracksArrayInp->size(); i++){ + o2::dataformats::TrackTPCITS trackITSTPC = mTracksArrayInp->at(i); + const o2::dataformats::EvIndex &evIdxTPCcheck = trackITSTPC.getRefTPC(); + const o2::dataformats::EvIndex &evIdxITScheck = trackITSTPC.getRefITS(); + itsTree->GetEntry(evIdxITScheck.getEvent()); + const auto& labelsTPCcheck = mcTPC->getLabels(evIdxTPCcheck.getIndex()); + for (int ilabel = 0; ilabel < labelsTPCcheck.size(); ilabel++){ + if (labelsTPCcheck[ilabel].getTrackID() == trackIdTOF && labelsTPCcheck[ilabel].getEventID() == eventIdTOF && labelsTPCcheck[ilabel].getSourceID() == sourceIdTOF){ + Printf("The TPC track that should have been matched to TOF is number %d", i); + TPCfound = true; + } + } + const auto& labelsITScheck = mcITS->getLabels(evIdxITScheck.getIndex()); + for (int ilabel = 0; ilabel < labelsITScheck.size(); ilabel++){ + if (labelsITScheck[ilabel].getTrackID() == trackIdTOF && labelsITScheck[ilabel].getEventID() == eventIdTOF && labelsITScheck[ilabel].getSourceID() == sourceIdTOF){ + Printf("The ITS track that should have been matched to TOF is number %d", i); + ITSfound = true; + } + } + } + if (!TPCfound) Printf("There is no TPC track found that should have corresponded to this TOF cluster!"); + if (!ITSfound) Printf("There is no ITS track found that should have corresponded to this TOF cluster!"); } } - + Printf("Number of matches = %d", nMatches); + Printf("Number of GOOD matches = %d (%.2f)", nGoodMatches, (float)nGoodMatches/nMatches); + Printf("Number of BAD matches = %d (%.2f)", nBadMatches, (float)nBadMatches/nMatches); return; diff --git a/macro/run_match_tof.C b/macro/run_match_tof.C index d55b8d82196b6..a68cd23e578dd 100644 --- a/macro/run_match_tof.C +++ b/macro/run_match_tof.C @@ -48,6 +48,16 @@ void run_match_tof(std::string path = "./", std::string outputfile = "o2match_to TTree outTree("matchTOF", "Matched TOF-tracks"); matching.setOutputTree(&outTree); +#ifdef _ALLOW_DEBUG_TREES_ + matching.setDebugTreeFileName(path + matching.getDebugTreeFileName()); + // dump accepted pairs only + //matching.setDebugFlag(o2::globaltracking::MatchTPCITS::MatchTreeAccOnly); + // dump all checked pairs + matching.setDebugFlag(o2::globaltracking::MatchTPCITS::MatchTreeAll); + // dump winner matches + //matching.setDebugFlag(o2::globaltracking::MatchTPCITS::WinnerMatchesTree); +#endif + //-------- init geometry and field --------// o2::Base::GeometryManager::loadGeometry(path + inputGeom, "FAIRGeom"); o2::Base::Propagator::initFieldFromGRP(path + inputGRP); From ba2cf6f1fe2f876fe5a1787011a748d37a21367f Mon Sep 17 00:00:00 2001 From: zampolli Date: Sat, 10 Nov 2018 17:34:57 +0100 Subject: [PATCH 24/39] One more bug fix, and a lot more. We save also the labels now. This commit contains a lot of debug printouts, and debug trees, to be removed. --- .../simulation/src/SimulationDataLinkDef.h | 1 + .../include/GlobalTracking/MatchTOF.h | 36 ++- Detectors/GlobalTracking/src/MatchTOF.cxx | 206 ++++++++++++++---- Detectors/TOF/base/src/Geo.cxx | 35 ++- Detectors/TOF/base/src/TOFBaseLinkDef.h | 2 +- 5 files changed, 225 insertions(+), 55 deletions(-) diff --git a/DataFormats/simulation/src/SimulationDataLinkDef.h b/DataFormats/simulation/src/SimulationDataLinkDef.h index 3313d9dddc3fd..50695e47cf3a4 100644 --- a/DataFormats/simulation/src/SimulationDataLinkDef.h +++ b/DataFormats/simulation/src/SimulationDataLinkDef.h @@ -37,6 +37,7 @@ #pragma link C++ struct o2::dataformats::MCTruthHeaderElement + ; #pragma link C++ class o2::dataformats::MCTruthContainer < long > +; #pragma link C++ class o2::dataformats::MCTruthContainer < o2::MCCompLabel > +; +#pragma link C++ class std::vector> +; #pragma link C++ class std::vector < o2::MCCompLabel > +; #pragma link C++ class std::vector < o2::dataformats::MCTruthHeaderElement > +; diff --git a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h index 74480598c0756..c7add030da27a 100644 --- a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h +++ b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h @@ -86,15 +86,25 @@ class MatchTOF ///< set input branch names for the input from the tree void setTrackBranchName(const std::string& nm) { mTracksBranchName = nm; } void setTPCTrackBranchName(const std::string& nm) { mTPCTracksBranchName = nm; } - void setTOFClusterBranchName(const std::string& nm) { mTOFClusterBranchName = nm; } + void setTPCMCTruthBranchName(const std::string& nm) { mTPCMCTruthBranchName = nm; } + void setITSMCTruthBranchName(const std::string& nm) { mITSMCTruthBranchName = nm; } void setTOFMCTruthBranchName(const std::string& nm) { mTOFMCTruthBranchName = nm; } + void setTOFClusterBranchName(const std::string& nm) { mTOFClusterBranchName = nm; } + void setOutTOFMCTruthBranchName(const std::string& nm) { mOutTOFMCTruthBranchName = nm; } + void setOutTPCMCTruthBranchName(const std::string& nm) { mOutTPCMCTruthBranchName = nm; } + void setOutITSMCTruthBranchName(const std::string& nm) { mOutITSMCTruthBranchName = nm; } void setOutTracksBranchName(const std::string& nm) { mOutTracksBranchName = nm; } ///< get input branch names for the input from the tree const std::string& getTracksBranchName() const { return mTracksBranchName; } const std::string& getTPCTracksBranchName() const { return mTPCTracksBranchName;} + const std::string& getTPCMCTruthBranchName() const { return mTPCMCTruthBranchName;} + const std::string& getITSMCTruthBranchName() const { return mITSMCTruthBranchName;} + const std::string& getTOFMCTruthBranchName() const { return mTOFMCTruthBranchName;} const std::string& getTOFClusterBranchName() const { return mTOFClusterBranchName; } - const std::string& getTOFMCTruthBranchName() const { return mTOFMCTruthBranchName; } + const std::string& getOutTOFMCTruthBranchName() const { return mOutTOFMCTruthBranchName; } + const std::string& getOutTPCMCTruthBranchName() const { return mOutTPCMCTruthBranchName; } + const std::string& getOutITSMCTruthBranchName() const { return mOutITSMCTruthBranchName; } ///< print settings void print() const; @@ -141,6 +151,7 @@ class MatchTOF ///< fill matching debug tree void fillTOFmatchTree(const char* tname, int cacheTOF, int sectTOF, int plateTOF, int stripTOF, int padXTOF, int padZTOF, int cacheeTrk, int crossedStrip, int sectPropagation, int platePropagation, int stripPropagation, int padXPropagation, int padZPropagation, float resX, float resZ, float res, o2::dataformats::TrackTPCITS& trk); + void fillTOFmatchTreeWithLabels(const char* tname, int cacheTOF, int sectTOF, int plateTOF, int stripTOF, int padXTOF, int padZTOF, int cacheeTrk, int crossedStrip, int sectPropagation, int platePropagation, int stripPropagation, int padXPropagation, int padZPropagation, float resX, float resZ, float res, o2::dataformats::TrackTPCITS& trk, int TPClabelTrackID, int TPClabelEventID, int TPClabelSourceID, int ITSlabelTrackID, int ITSlabelEventID, int ITSlabelSourceID, int TOFlabelTrackID0, int TOFlabelEventID0, int TOFlabelSourceID0, int TOFlabelTrackID1, int TOFlabelEventID1, int TOFlabelSourceID1, int TOFlabelTrackID2, int TOFlabelEventID2, int TOFlabelSourceID2); void dumpWinnerMatches(); #endif @@ -190,12 +201,12 @@ class MatchTOF std::vector* mTPCTracksArrayInp = nullptr; ///< input TPC tracks std::vector* mTOFClustersArrayInp = nullptr; ///< input TOF clusters - o2::dataformats::MCTruthContainer* mTracksLabels = nullptr; ///< input TPC Track MC labels - o2::dataformats::MCTruthContainer* mTOFClusLabels = nullptr; ///< input TOF clusters MC labels std::vector mTracksLblWork; /// mTTOFClusLblWork; ///* mTPCLabels = nullptr; ///< TPC label of input tracks + std::vector* mITSLabels = nullptr; ///< ITS label of input tracks + /// <<<----- @@ -215,7 +226,11 @@ class MatchTOF /// mMatchedTracks; - std::vector> mMatchedTracks; + std::vector> mMatchedTracks; // this is the output of the matching + std::vector mOutTOFLabels; ///< TOF label of matched tracks + std::vector mOutTPCLabels; ///< TPC label of matched tracks + std::vector mOutITSLabels; ///< ITS label of matched tracks + int mNumOfTracks; // number of tracks to be matched int* mMatchedTracksIndex = nullptr; //[mNumOfTracks] int mNumOfClusters; // number of clusters to be matched @@ -223,9 +238,14 @@ class MatchTOF std::string mTracksBranchName = "TPCITS"; ///< name of branch containing input matched tracks std::string mTPCTracksBranchName = "Tracks"; ///< name of branch containing actual TPC tracks + std::string mTPCMCTruthBranchName = "MatchTPCMCTruth"; ///< name of branch containing TPC labels + std::string mITSMCTruthBranchName = "MatchITSMCTruth"; ///< name of branch containing ITS labels + std::string mTOFMCTruthBranchName = "TOFClusterMCTruth"; ///< name of branch containing TOF clusters labels std::string mTOFClusterBranchName = "TOFCluster"; ///< name of branch containing input ITS clusters - std::string mTOFMCTruthBranchName = "TOFClusterMCTruth"; ///< name of branch containing ITS MC labels std::string mOutTracksBranchName = "TOFMatchInfo"; ///< name of branch containing output matched tracks + std::string mOutTOFMCTruthBranchName = "MatchTOFMCTruth"; ///< name of branch containing TOF labels for output matched tracks + std::string mOutTPCMCTruthBranchName = "MatchTPCMCTruth"; ///< name of branch containing TOF labels for output matched tracks + std::string mOutITSMCTruthBranchName = "MatchITSMCTruth"; ///< name of branch containing TOF labels for output matched tracks #ifdef _ALLOW_DEBUG_TREES_ std::unique_ptr mDBGOut; diff --git a/Detectors/GlobalTracking/src/MatchTOF.cxx b/Detectors/GlobalTracking/src/MatchTOF.cxx index 19c56f12febb5..b4d156e96fbe8 100644 --- a/Detectors/GlobalTracking/src/MatchTOF.cxx +++ b/Detectors/GlobalTracking/src/MatchTOF.cxx @@ -45,7 +45,7 @@ void MatchTOF::run() ///< running the matching if (!mInitDone) { - LOG(FATAL) << "init() was not done yet" << FairLogger::endl; + LOG(FATAL) << "init() was not done yet"; } mTimerTot.Start(); @@ -57,6 +57,9 @@ void MatchTOF::run() while (mCurrTracksTreeEntry+1 < mInputTreeTracks->GetEntries()) { // we add "+1" because mCurrTracksTreeEntry starts from -1, and it is incremented in loadTracksNextChunk which is called by prepareTracks Printf("mCurrTracksTreeEntry = %d", mCurrTracksTreeEntry); mMatchedTracks.clear(); + mOutTOFLabels.clear(); + mOutTPCLabels.clear(); + mOutITSLabels.clear(); prepareTracks(); Printf("*************** Printing the tracks before starting the matching"); @@ -64,6 +67,7 @@ void MatchTOF::run() // printing the tracks std::array globalPosTmp; int totTracks = 0; + /* for (int sec = o2::constants::math::NSectors; sec--;) { Printf("\nsector %d", sec); auto& cacheTrkTmp = mTracksSectIndexCache[sec]; // array of cached tracks indices for this sector; reminder: they are ordered in time! @@ -75,7 +79,7 @@ void MatchTOF::run() totTracks++; } } - + */ for (int sec = o2::constants::math::NSectors; sec--;) { printf("\n\ndoing matching for sector %i...\n", sec); doMatching(sec); @@ -106,7 +110,7 @@ void MatchTOF::init() ///< initizalizations if (mInitDone) { - LOG(ERROR) << "Initialization was already done" << FairLogger::endl; + LOG(ERROR) << "Initialization was already done"; return; } @@ -116,9 +120,18 @@ void MatchTOF::init() if (mOutputTree) { mOutputTree->Branch(mOutTracksBranchName.data(), &mMatchedTracks); LOG(INFO) << "Matched tracks will be stored in " << mOutTracksBranchName << " branch of tree " - << mOutputTree->GetName() << FairLogger::endl; + << mOutputTree->GetName(); + if (mMCTruthON) { + mOutputTree->Branch(mOutTPCMCTruthBranchName.data(), &mOutITSLabels); + LOG(INFO) << "ITS Tracks Labels branch: " << mOutITSMCTruthBranchName; + mOutputTree->Branch(mOutITSMCTruthBranchName.data(), &mOutTPCLabels); + LOG(INFO) << "TPC Tracks Labels branch: " << mOutTPCMCTruthBranchName; + mOutputTree->Branch(mOutTOFMCTruthBranchName.data(), &mOutTOFLabels); + LOG(INFO) << "TOF Tracks Labels branch: " << mOutTOFMCTruthBranchName; + } + } else { - LOG(ERROR) << "Output tree is not attached, matched tracks will not be stored" << FairLogger::endl; + LOG(ERROR) << "Output tree is not attached, matched tracks will not be stored"; } #ifdef _ALLOW_DEBUG_TREES_ @@ -169,52 +182,60 @@ void MatchTOF::attachInputTrees() ///< attaching the input tree if (!mInputTreeTracks) { - LOG(FATAL) << "Input tree with tracks is not set" << FairLogger::endl; + LOG(FATAL) << "Input tree with tracks is not set"; } if (!mTreeTPCTracks) { - LOG(FATAL) << "TPC tracks data input tree is not set" << FairLogger::endl; + LOG(FATAL) << "TPC tracks data input tree is not set"; } if (!mTreeTOFClusters) { - LOG(FATAL) << "TOF clusters data input tree is not set" << FairLogger::endl; + LOG(FATAL) << "TOF clusters data input tree is not set"; } // input tracks (this is the pais of ITS-TPC matches) if (!mInputTreeTracks->GetBranch(mTracksBranchName.data())) { - LOG(FATAL) << "Did not find tracks branch " << mTracksBranchName << " in the input tree" << FairLogger::endl; + LOG(FATAL) << "Did not find tracks branch " << mTracksBranchName << " in the input tree"; } mInputTreeTracks->SetBranchAddress(mTracksBranchName.data(), &mTracksArrayInp); LOG(INFO) << "Attached tracks " << mTracksBranchName << " branch with " << mInputTreeTracks->GetEntries() - << " entries" << FairLogger::endl; + << " entries"; // actual TPC tracks - if (!mTreeTPCTracks->GetBranch(mTPCTracksBranchName.data())) { - LOG(FATAL) << "Did not find TPC tracks branch " << mTPCTracksBranchName << " in the input tree" << FairLogger::endl; + /* if (!mTreeTPCTracks->GetBranch(mTPCTracksBranchName.data())) { + LOG(FATAL) << "Did not find TPC tracks branch " << mTPCTracksBranchName << " in the input tree"; } mTreeTPCTracks->SetBranchAddress(mTPCTracksBranchName.data(), &mTPCTracksArrayInp); LOG(INFO) << "Attached TPC tracks " << mTPCTracksBranchName << " branch with " << mTreeTPCTracks->GetEntries() - << " entries" << FairLogger::endl; - + << " entries"; + */ // input TOF clusters if (!mTreeTOFClusters->GetBranch(mTOFClusterBranchName.data())) { LOG(FATAL) << "Did not find TOF clusters branch " << mTOFClusterBranchName << " in the input tree" - << FairLogger::endl; + ; } mTreeTOFClusters->SetBranchAddress(mTOFClusterBranchName.data(), &mTOFClustersArrayInp); LOG(INFO) << "Attached TOF clusters " << mTOFClusterBranchName << " branch with " << mTreeTOFClusters->GetEntries() - << " entries" << FairLogger::endl; + << " entries"; // is there MC info available ? if (mTreeTOFClusters->GetBranch(mTOFMCTruthBranchName.data())) { mTreeTOFClusters->SetBranchAddress(mTOFMCTruthBranchName.data(), &mTOFClusLabels); - LOG(INFO) << "Found TOF Clusters MCLabels branch " << mTOFMCTruthBranchName << FairLogger::endl; + LOG(INFO) << "Found TOF Clusters MCLabels branch " << mTOFMCTruthBranchName; } - - mMCTruthON = mTOFClusLabels; + if (mInputTreeTracks->GetBranch(mTPCMCTruthBranchName.data())) { + mInputTreeTracks->SetBranchAddress(mTPCMCTruthBranchName.data(), &mTPCLabels); + LOG(INFO) << "Found TPC tracks MCLabels branch " << mTPCMCTruthBranchName.data(); + } + if (mInputTreeTracks->GetBranch(mITSMCTruthBranchName.data())) { + mInputTreeTracks->SetBranchAddress(mITSMCTruthBranchName.data(), &mITSLabels); + LOG(INFO) << "Found ITS tracks MCLabels branch " << mITSMCTruthBranchName.data(); + } + + mMCTruthON = (mTOFClusLabels && mTPCLabels && mITSLabels); mCurrTracksTreeEntry = -1; mCurrTOFClustersTreeEntry = -1; } @@ -296,15 +317,19 @@ bool MatchTOF::prepareTracks() Printf("The track will go to sector %d", o2::utils::Angle2Sector(TMath::ATan2(globalPos[1], globalPos[0]))); //mTracksSectIndexCache[o2::utils::Angle2Sector(TMath::ATan2(globalPos[1], globalPos[0]))].push_back(mTracksWork.size() - 1); mTracksSectIndexCache[o2::utils::Angle2Sector(TMath::ATan2(globalPos[1], globalPos[0]))].push_back(it); + int labelTPC = mTPCLabels->at(it); + int labelITS = mITSLabels->at(it); + Printf("TPC label of the track = %d", labelTPC); + Printf("ITS label of the track = %d", labelITS); //delete trc; // Check: is this needed? } - LOG(INFO) << "Total number of tracks = " << mNumOfTracks << ", Number of tracks that failed to be propagated to TOF = " << nNotPropagatedToTOF << FairLogger::endl; + LOG(INFO) << "Total number of tracks = " << mNumOfTracks << ", Number of tracks that failed to be propagated to TOF = " << nNotPropagatedToTOF; // sort tracks in each sector according to their time (increasing in time) for (int sec = o2::constants::math::NSectors; sec--;) { auto& indexCache = mTracksSectIndexCache[sec]; - LOG(INFO) << "Sorting sector" << sec << " | " << indexCache.size() << " tracks" << FairLogger::endl; + LOG(INFO) << "Sorting sector" << sec << " | " << indexCache.size() << " tracks"; if (!indexCache.size()) continue; std::sort(indexCache.begin(), indexCache.end(), [this](int a, int b) { @@ -376,7 +401,7 @@ bool MatchTOF::prepareTOFClusters() // sort clusters in each sector according to their time (increasing in time) for (int sec = o2::constants::math::NSectors; sec--;) { auto& indexCache = mTOFClusSectIndexCache[sec]; - LOG(INFO) << "Sorting sector" << sec << " | " << indexCache.size() << " TOF clusters" << FairLogger::endl; + LOG(INFO) << "Sorting sector" << sec << " | " << indexCache.size() << " TOF clusters"; if (!indexCache.size()) continue; std::sort(indexCache.begin(), indexCache.end(), [this](int a, int b) { @@ -400,7 +425,7 @@ bool MatchTOF::loadTracksNextChunk() while (++mCurrTracksTreeEntry < mInputTreeTracks->GetEntries()) { mInputTreeTracks->GetEntry(mCurrTracksTreeEntry); LOG(INFO) << "Loading tracks entry " << mCurrTracksTreeEntry << " -> " << mTracksArrayInp->size() - << " tracks" << FairLogger::endl; + << " tracks"; if (!mTracksArrayInp->size()) { continue; } @@ -428,9 +453,9 @@ bool MatchTOF::loadTOFClustersNextChunk() while (++mCurrTOFClustersTreeEntry < mTreeTOFClusters->GetEntries()) { mTreeTOFClusters->GetEntry(mCurrTOFClustersTreeEntry); LOG(DEBUG) << "Loading TOF clusters entry " << mCurrTOFClustersTreeEntry << " -> " << mTOFClustersArrayInp->size() - << " clusters" << FairLogger::endl; + << " clusters"; LOG(INFO) << "Loading TOF clusters entry " << mCurrTOFClustersTreeEntry << " -> " << mTOFClustersArrayInp->size() - << " clusters" << FairLogger::endl; + << " clusters"; if (!mTOFClustersArrayInp->size()) { continue; } @@ -471,7 +496,7 @@ void MatchTOF::doMatching(int sec) auto& cacheTOF = mTOFClusSectIndexCache[sec]; // array of cached TOF cluster indices for this sector; reminder: they are ordered in time! auto& cacheTrk = mTracksSectIndexCache[sec]; // array of cached tracks indices for this sector; reminder: they are ordered in time! int nTracks = cacheTrk.size(), nTOFCls = cacheTOF.size(); - LOG(INFO) << "Matching sector " << sec << ": number of tracks: " << nTracks << ", number of TOF clusters: " << nTOFCls << FairLogger::endl; + LOG(INFO) << "Matching sector " << sec << ": number of tracks: " << nTracks << ", number of TOF clusters: " << nTOFCls; if (!nTracks || !nTOFCls) { return; } @@ -483,14 +508,15 @@ void MatchTOF::doMatching(int sec) std::array pos; std::array posBeforeProp; float posFloat[3]; - + + Printf("Trying to match %d tracks", cacheTrk.size()); for (int itrk = 0; itrk < cacheTrk.size(); itrk++) { Printf("\n\n\n\n ************ track %d **********", itrk); for (int ii = 0; ii < 2; ii++) { detId[ii][2] = -1; // before trying to match, we need to inizialize the detId corresponding to the strip number to -1; this is the array that we will use to save the det id of the maximum 2 strips matched nStepsInsideSameStrip[ii] = 0; } - int nStripsCrossedInPropagation = 0; // how many strips were hit during the propagation + int nStripsCrossedInPropagation = 0; // how many strips were hit during the propagation auto& trefTrk = mTracksWork[cacheTrk[itrk]]; float minTrkTime = (trefTrk.getTimeMUS().getTimeStamp() - mSigmaTimeCut*trefTrk.getTimeMUS().getTimeStampError())*1.E6; // minimum time in ps float maxTrkTime = (trefTrk.getTimeMUS().getTimeStamp() + mSigmaTimeCut*trefTrk.getTimeMUS().getTimeStampError())*1.E6; // maximum time in ps @@ -510,8 +536,9 @@ void MatchTOF::doMatching(int sec) detId[ii][iii] = -1; } } + int detIdTemp[5] = {-1, -1, -1, -1, -1}; // TOF detector id at the current propagation point while (propagateToRefX(trefTrk, mXRef+istep*step, step) && nStripsCrossedInPropagation <=2 && mXRef+istep*step < Geo::RMAX){ - if (0 || istep%100 == 0){ + if (0 && istep%100 == 0){ printf("istep = %d, currentPosition = %f \n", istep, mXRef+istep*step); } //float pos[3] = {trefTrk.getX(), trefTrk.getY(), trefTrk.getZ()}; // these are the coordinates in the local ref system @@ -523,31 +550,37 @@ void MatchTOF::doMatching(int sec) //Printf("posFloat[0] = %f, posFloat[1] = %f, posFloat[2] = %f", posFloat[0], posFloat[1], posFloat[2]); //Printf("radius xy = %f", TMath::Sqrt(posFloat[0]*posFloat[0] + posFloat[1]*posFloat[1])); //Printf("radius xyz = %f", TMath::Sqrt(posFloat[0]*posFloat[0] + posFloat[1]*posFloat[1] + posFloat[2]*posFloat[2])); - int detIdTemp[5] = {-1, -1, -1, -1, -1}; // TOF detector id at the current propagation point + for (int idet = 0; idet < 5; idet++) detIdTemp[idet] = -1; Geo::getPadDxDyDz(posFloat, detIdTemp, deltaPosTemp); //Printf("detIdTemp[0] = %d, detIdTemp[1] = %d, detIdTemp[2] = %d, detIdTemp[3] = %d, detIdTemp[4] = %d", detIdTemp[0], detIdTemp[1], detIdTemp[2], detIdTemp[3], detIdTemp[4]); if (detIdTemp[2] != -1 && nStripsCrossedInPropagation == 0){ // print in case you have a useful propagation Printf("*********** We have crossed a strip during propagation!*********"); + //printf("Global coordinates: pos[0] = %f, pos[1] = %f, pos[2] = %f\n", pos[0], pos[1], pos[2]); + // printf("detIdTemp[0] = %d, detIdTemp[1] = %d, detIdTemp[2] = %d, detIdTemp[3] = %d, detIdTemp[4] = %d\n", detIdTemp[0], detIdTemp[1], detIdTemp[2], detIdTemp[3], detIdTemp[4]); + //printf("deltaPosTemp[0] = %f, deltaPosTemp[1] = %f, deltaPosTemp[2] = %f\n", deltaPosTemp[0], deltaPosTemp[1], deltaPosTemp[2]); + } + else { + Printf("*********** We have NOT crossed a strip during propagation!*********"); printf("Global coordinates: pos[0] = %f, pos[1] = %f, pos[2] = %f\n", pos[0], pos[1], pos[2]); printf("detIdTemp[0] = %d, detIdTemp[1] = %d, detIdTemp[2] = %d, detIdTemp[3] = %d, detIdTemp[4] = %d\n", detIdTemp[0], detIdTemp[1], detIdTemp[2], detIdTemp[3], detIdTemp[4]); printf("deltaPosTemp[0] = %f, deltaPosTemp[1] = %f, deltaPosTemp[2] = %f\n", deltaPosTemp[0], deltaPosTemp[1], deltaPosTemp[2]); - } + } //printf("getPadDxDyDz done\n"); istep++; // check if after the propagation we are in a TOF strip if (detIdTemp[2] != -1) { // we ended in a TOF strip - Printf("We are in a TOF strip! %d", detIdTemp[2]); - Printf("nStripsCrossedInPropagation = %d, detId[nStripsCrossedInPropagation-1][0] = %d, detIdTemp[0] = %d, detId[nStripsCrossedInPropagation-1][1] = %d, detIdTemp[1] =%d, detId[nStripsCrossedInPropagation-1][2] = %d, detIdTemp[2] = %d", nStripsCrossedInPropagation, detId[nStripsCrossedInPropagation-1][0], detIdTemp[0], detId[nStripsCrossedInPropagation-1][1], detIdTemp[1], detId[nStripsCrossedInPropagation-1][2], detIdTemp[2]); + // Printf("nStripsCrossedInPropagation = %d, detId[nStripsCrossedInPropagation-1][0] = %d, detIdTemp[0] = %d, detId[nStripsCrossedInPropagation-1][1] = %d, detIdTemp[1] =%d, detId[nStripsCrossedInPropagation-1][2] = %d, detIdTemp[2] = %d", nStripsCrossedInPropagation, detId[nStripsCrossedInPropagation-1][0], detIdTemp[0], detId[nStripsCrossedInPropagation-1][1], detIdTemp[1], detId[nStripsCrossedInPropagation-1][2], detIdTemp[2]); if(nStripsCrossedInPropagation == 0 || // we are crossing a strip for the first time... (nStripsCrossedInPropagation >= 1 && (detId[nStripsCrossedInPropagation-1][0] != detIdTemp[0] || detId[nStripsCrossedInPropagation-1][1] != detIdTemp[1] || detId[nStripsCrossedInPropagation-1][2] != detIdTemp[2]))) { // ...or we are crossing a new strip - if (nStripsCrossedInPropagation == 0) Printf("We cross a strip for the first time"); + // if (nStripsCrossedInPropagation == 0) Printf("We cross a strip for the first time"); + Printf("We are in a TOF strip! %d", detIdTemp[2]); if(nStripsCrossedInPropagation == 2) { break; // we have already matched 2 strips, we cannot match more } nStripsCrossedInPropagation++; } - Printf("nStepsInsideSameStrip[nStripsCrossedInPropagation-1] = %d", nStepsInsideSameStrip[nStripsCrossedInPropagation-1]); + //Printf("nStepsInsideSameStrip[nStripsCrossedInPropagation-1] = %d", nStepsInsideSameStrip[nStripsCrossedInPropagation-1]); if(nStepsInsideSameStrip[nStripsCrossedInPropagation-1] == 0){ detId[nStripsCrossedInPropagation-1][0] = detIdTemp[0]; detId[nStripsCrossedInPropagation-1][1] = detIdTemp[1]; @@ -568,7 +601,16 @@ void MatchTOF::doMatching(int sec) } } printf("while done, we propagated track %d in %d strips\n", itrk, nStripsCrossedInPropagation); - + if (nStripsCrossedInPropagation == 0) { + auto labelTPCNoStripsCrossed = mTPCLabels->at(mTracksSectIndexCache[sec][itrk]); + Printf("The current track (index = %d) never crossed a strip", cacheTrk[itrk]); + Printf("TrackID = %d, EventID = %d, SourceID = %d", labelTPCNoStripsCrossed.getTrackID(), labelTPCNoStripsCrossed.getEventID(), labelTPCNoStripsCrossed.getSourceID()); + printf("Global coordinates: pos[0] = %f, pos[1] = %f, pos[2] = %f\n", pos[0], pos[1], pos[2]); + printf("detIdTemp[0] = %d, detIdTemp[1] = %d, detIdTemp[2] = %d, detIdTemp[3] = %d, detIdTemp[4] = %d\n", detIdTemp[0], detIdTemp[1], detIdTemp[2], detIdTemp[3], detIdTemp[4]); + printf("deltaPosTemp[0] = %f, deltaPosTemp[1] = %f, deltaPosTemp[2] = %f\n", deltaPosTemp[0], deltaPosTemp[1], deltaPosTemp[2]); + } + Printf("We will check now the %d TOF clusters", nTOFCls); + for(Int_t imatch = 0; imatch < nStripsCrossedInPropagation; imatch++){ //printf("imatch = %d\n", imatch); // we take as residual the average of the residuals along the propagation in the same strip @@ -578,11 +620,13 @@ void MatchTOF::doMatching(int sec) printf("matched strip %d: deltaPos[0] = %f, deltaPos[1] = %f, deltaPos[2] = %f, residual (x, z) = %f\n", imatch, deltaPos[imatch][0], deltaPos[imatch][1], deltaPos[imatch][2], TMath::Sqrt(deltaPos[imatch][0]*deltaPos[imatch][0] + deltaPos[imatch][2]*deltaPos[imatch][2])); } - if (nStripsCrossedInPropagation == 0) continue; // the track never hit a TOF strip during the propagation + if (nStripsCrossedInPropagation == 0) { + continue; // the track never hit a TOF strip during the propagation + } Printf("We will check now the %d TOF clusters", nTOFCls); bool foundCluster = false; for (auto itof = itof0; itof < nTOFCls; itof++) { - printf("itof = %d\n", itof); + // printf("itof = %d\n", itof); auto& trefTOF = mTOFClusWork[cacheTOF[itof]]; // compare the times of the track and the TOF clusters - remember that they both are ordered in time! Printf("trefTOF.getTime() = %f, maxTrkTime = %f, minTrkTime = %f", trefTOF.getTime(), maxTrkTime, minTrkTime); @@ -599,6 +643,10 @@ void MatchTOF::doMatching(int sec) int mainChannel = trefTOF.getMainContributingChannel(); int indices[5]; Geo::getVolumeIndices(mainChannel, indices); + const auto& labelsTOF = mTOFClusLabels->getLabels(mTOFClusSectIndexCache[indices[0]][itof]); + int trackIdTOF; + int eventIdTOF; + int sourceIdTOF; for (auto iPropagation = 0; iPropagation < nStripsCrossedInPropagation; iPropagation++){ printf("iPropagation = %d\n", iPropagation); Printf("TOF Cluster [%d, %d]: indices = %d, %d, %d, %d, %d", itof, cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4]); @@ -608,19 +656,40 @@ void MatchTOF::doMatching(int sec) float res = TMath::Sqrt(resX*resX + resZ*resZ); Printf("resX = %f, resZ = %f, res = %f", resX, resZ, res); #ifdef _ALLOW_DEBUG_TREES_ - Printf("Ready to fill the debug tree"); - fillTOFmatchTree("match0",cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk); + fillTOFmatchTree("match0", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk); #endif + int tofLabelTrackID[3] = {-1, -1, -1}; + int tofLabelEventID[3] = {-1, -1, -1}; + int tofLabelSourceID[3] = {-1, -1, -1}; + for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++){ + tofLabelTrackID[ilabel] = labelsTOF[ilabel].getTrackID(); + tofLabelEventID[ilabel] = labelsTOF[ilabel].getEventID(); + tofLabelSourceID[ilabel] = labelsTOF[ilabel].getSourceID(); + } + auto labelTPC = mTPCLabels->at(mTracksSectIndexCache[indices[0]][itrk]); + auto labelITS = mITSLabels->at(mTracksSectIndexCache[indices[0]][itrk]); + fillTOFmatchTreeWithLabels("matchPossibleWithLabels", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk, labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID(), labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID(), tofLabelTrackID[0], tofLabelEventID[0], tofLabelSourceID[0], tofLabelTrackID[1], tofLabelEventID[1], tofLabelSourceID[1], tofLabelTrackID[2], tofLabelEventID[2], tofLabelSourceID[2]); if (indices[0] != detId[iPropagation][0]) continue; if (indices[1] != detId[iPropagation][1]) continue; if (indices[2] != detId[iPropagation][2]) continue; float chi2 = res; // TODO: take into account also the time! - fillTOFmatchTree("match1",cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk); + fillTOFmatchTree("match1", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk); + fillTOFmatchTreeWithLabels("matchOkWithLabels", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk, labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID(), labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID(), tofLabelTrackID[0], tofLabelEventID[0], tofLabelSourceID[0], tofLabelTrackID[1], tofLabelEventID[1], tofLabelSourceID[1], tofLabelTrackID[2], tofLabelEventID[2], tofLabelSourceID[2]); + if (res < mSpaceTolerance) { // matching ok! Printf("YUHUUUUUUUUU! We have a match! between track %d and TOF cluster %d", mTracksSectIndexCache[indices[0]][itrk], mTOFClusSectIndexCache[indices[0]][itof]); foundCluster = true; mMatchedTracksPairs.push_back(std::make_pair(mTracksSectIndexCache[indices[0]][itrk], o2::dataformats::MatchInfoTOF(mTOFClusSectIndexCache[indices[0]][itof], chi2))); // TODO: check if this is correct! + for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++){ + Printf("TOF label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTOF[ilabel].getTrackID(), labelsTOF[ilabel].getEventID(), labelsTOF[ilabel].getSourceID()); + } + Printf("TPC label of the track: trackID = %d, eventID = %d, sourceID = %d", labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID()); + Printf("ITS label of the track: trackID = %d, eventID = %d, sourceID = %d", labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID()); + fillTOFmatchTreeWithLabels("matchOkWithLabelsInSpaceTolerance", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk, labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID(), labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID(), tofLabelTrackID[0], tofLabelEventID[0], tofLabelSourceID[0], tofLabelTrackID[1], tofLabelEventID[1], tofLabelSourceID[1], tofLabelTrackID[2], tofLabelEventID[2], tofLabelSourceID[2]); + } + else { + Printf("We have not matched with any TOF cluster"); } } } @@ -638,6 +707,7 @@ void MatchTOF::selectBestMatches() std::sort(mMatchedTracksPairs.begin(), mMatchedTracksPairs.end(), [this](std::pair a, std::pair b) { return (a.second.getChi2() < b.second.getChi2());}); int i = 0; + // then we take discard the pairs if their track or cluster was already matched (since they are ordered in chi2, we will take the best matching) for (const std::pair &matchingPair : mMatchedTracksPairs){ Printf("selectBestMatches: i = %d", i); if (mMatchedTracksIndex[matchingPair.first] != -1) { // the track was already filled @@ -651,8 +721,38 @@ void MatchTOF::selectBestMatches() //mMatchedTracks.push_back(matchingPair.second); // array of MatchInfoTOF mMatchedTracks.push_back(matchingPair); // array of MatchInfoTOF Printf("size of mMatchedTracks = %d", mMatchedTracks.size()); + int labelTPCint = mTPCLabels->at(matchingPair.first); + int labelITSint = mITSLabels->at(matchingPair.first); + Printf("TPC label of the track = %d", labelTPCint); + Printf("ITS label of the track = %d", labelITSint); + const auto& labelTPC = mTPCLabels->at(matchingPair.first); + Printf("labelTPC: trackID = %d, eventID = %d, sourceID = %d", labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID()); + const auto& labelITS = mITSLabels->at(matchingPair.first); + Printf("labelITS: trackID = %d, eventID = %d, sourceID = %d", labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID()); + const auto& labelsTOF = mTOFClusLabels->getLabels(matchingPair.second.getTOFClIndex()); + bool labelOk = false; // whether we have found or not the same TPC label of the track among the labels of the TOF cluster + for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++){ + Printf("TOF label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTOF[ilabel].getTrackID(), labelsTOF[ilabel].getEventID(), labelsTOF[ilabel].getSourceID()); + if (labelsTOF[ilabel].getTrackID() == labelTPC.getTrackID() && labelsTOF[ilabel].getEventID() == labelTPC.getEventID() && labelsTOF[ilabel].getSourceID() == labelTPC.getSourceID() && !labelOk) { // if we find one TOF cluster label that is the same as the TPC one, we are happy - even if it is not the first one + mOutTOFLabels.push_back(labelsTOF[ilabel]); + Printf("Adding label for good match %d", mOutTOFLabels.size() ); + labelOk = true; + } + } + if (!labelOk) { + // we have not found the track label among those associated to the TOF cluster --> fake match! We will associate the label of the main channel, but negative + o2::MCCompLabel fakeTOFlabel; + fakeTOFlabel.set(-labelsTOF[0].getTrackID(), labelsTOF[0].getEventID(), labelsTOF[0].getSourceID()); + mOutTOFLabels.push_back(fakeTOFlabel); + Printf("Adding label for fake match %d", mOutTOFLabels.size()); + } + mOutTPCLabels.push_back(labelTPC); + mOutITSLabels.push_back(labelITS); i++; } + Printf("size of mOutTPCLabels = %d", mOutTPCLabels.size()); + Printf("size of mOutITSLabels = %d", mOutITSLabels.size()); + Printf("size of mOutTOFLabels = %d", mOutTOFLabels.size()); } @@ -679,7 +779,7 @@ bool MatchTOF::propagateToRefX(o2::track::TrackParCov& trc, float xRef, float st //Printf("propagateToRefX: changing sector"); auto alphaNew = o2::utils::Angle2Alpha(trc.getPhiPos()); if (!trc.rotate(alphaNew) != 0) { - //Printf("propagateToRefX: failed to rotate"); + // Printf("propagateToRefX: failed to rotate"); break; // failed (RS: check effect on matching tracks to neighbouring sector) } } @@ -713,11 +813,31 @@ void MatchTOF::fillTOFmatchTree(const char* trname, int cacheTOF, int sectTOF, i mTimerDBG.Start(false); - Printf("************** Filling the debug tree with %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %f, %f, %f", cacheTOF, sectTOF, plateTOF, stripTOF, padXTOF, padZTOF, cacheeTrk, crossedStrip, sectPropagation, platePropagation, stripPropagation, padXPropagation, padZPropagation, resX, resZ, res); +// Printf("************** Filling the debug tree with %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %f, %f, %f", cacheTOF, sectTOF, plateTOF, stripTOF, padXTOF, padZTOF, cacheeTrk, crossedStrip, sectPropagation, platePropagation, stripPropagation, padXPropagation, padZPropagation, resX, resZ, res); (*mDBGOut) << trname << "clusterTOF=" << cacheTOF << "sectTOF=" << sectTOF << "plateTOF=" << plateTOF << "stripTOF=" << stripTOF << "padXTOF=" << padXTOF << "padZTOF=" << padZTOF << "crossedStrip=" << crossedStrip << "sectPropagation=" << sectPropagation << "platePropagation=" << platePropagation << "stripPropagation=" << stripPropagation << "padXPropagation=" << padXPropagation << "resX=" << resX << "resZ=" << resZ << "res=" << res << "track=" << trk << "\n"; mTimerDBG.Stop(); } + +//_________________________________________________________ +void MatchTOF::fillTOFmatchTreeWithLabels(const char* trname, int cacheTOF, int sectTOF, int plateTOF, int stripTOF, int padXTOF, int padZTOF, int cacheeTrk, int crossedStrip, int sectPropagation, int platePropagation, int stripPropagation, int padXPropagation, int padZPropagation, float resX, float resZ, float res, o2::dataformats::TrackTPCITS &trk, int TPClabelTrackID, int TPClabelEventID, int TPClabelSourceID, int ITSlabelTrackID, int ITSlabelEventID, int ITSlabelSourceID, int TOFlabelTrackID0, int TOFlabelEventID0, int TOFlabelSourceID0, int TOFlabelTrackID1, int TOFlabelEventID1, int TOFlabelSourceID1, int TOFlabelTrackID2, int TOFlabelEventID2, int TOFlabelSourceID2) +{ + ///< fill debug tree for TOF tracks matching check + + mTimerDBG.Start(false); + + (*mDBGOut) << trname + << "clusterTOF=" << cacheTOF << "sectTOF=" << sectTOF << "plateTOF=" << plateTOF << "stripTOF=" << stripTOF << "padXTOF=" << padXTOF << "padZTOF=" << padZTOF + << "crossedStrip=" << crossedStrip << "sectPropagation=" << sectPropagation << "platePropagation=" << platePropagation << "stripPropagation=" << stripPropagation << "padXPropagation=" << padXPropagation + << "resX=" << resX << "resZ=" << resZ << "res=" << res << "track=" << trk + << "TPClabelTrackID=" << TPClabelTrackID << "TPClabelEventID=" << TPClabelEventID << "TPClabelSourceID=" << TPClabelSourceID + << "ITSlabelTrackID=" << ITSlabelTrackID << "ITSlabelEventID=" << ITSlabelEventID << "ITSlabelSourceID=" << ITSlabelSourceID + << "TOFlabelTrackID0=" << TOFlabelTrackID0 << "TOFlabelEventID0=" << TOFlabelEventID0 << "TOFlabelSourceID0=" << TOFlabelSourceID0 + << "TOFlabelTrackID1=" << TOFlabelTrackID1 << "TOFlabelEventID1=" << TOFlabelEventID1 << "TOFlabelSourceID1=" << TOFlabelSourceID1 + << "TOFlabelTrackID2=" << TOFlabelTrackID2 << "TOFlabelEventID2=" << TOFlabelEventID2 << "TOFlabelSourceID2=" << TOFlabelSourceID2 + << "\n"; + mTimerDBG.Stop(); +} #endif diff --git a/Detectors/TOF/base/src/Geo.cxx b/Detectors/TOF/base/src/Geo.cxx index d0300bc3b4ddc..1f18deeea12fa 100644 --- a/Detectors/TOF/base/src/Geo.cxx +++ b/Detectors/TOF/base/src/Geo.cxx @@ -370,14 +370,40 @@ Int_t Geo::fromPlateToStrip(Float_t* pos, Int_t iplate) for (Int_t istrip = 0; istrip < nstrips; istrip++) { Float_t posLoc2[3] = { pos[0], pos[1], pos[2] }; + /* + for (int ii = 0; ii < 3; ii++){ + Printf("posLoc2[%d] = %f", ii, posLoc2[ii]); + } + */ step[0] = 0.; step[1] = getHeights(iplate, istrip); step[2] = -getDistances(iplate, istrip); + /* for (int ii = 0; ii < 3; ii++){ + Printf("step[%d] = %f", ii, step[ii]); + } + */ translate(posLoc2, step); - + /* + Printf("After translation"); + for (int ii = 0; ii < 3; ii++){ + Printf("posLoc2[%d] = %f", ii, posLoc2[ii]); + } + */ rotateToStrip(posLoc2, iplate, istrip); - - if ((TMath::Abs(posLoc2[0]) <= STRIPLENGTH * 0.5) && (TMath::Abs(posLoc2[1]) <= HSTRIPY * 0.5) && + /* +Printf("After rotation"); + for (int ii = 0; ii < 3; ii++){ + Printf("posLoc2[%d] = %f", ii, posLoc2[ii]); + } + */ + /* + Printf("STRIPLENGTH = %f", STRIPLENGTH); + Printf("HSTRIPY = %f", HSTRIPY); + Printf("WCPCBZ = %f", WCPCBZ); + Printf("TMath::Abs(posLoc2[0]) <= STRIPLENGTH * 0.5 = %d", (int)(TMath::Abs(posLoc2[0]) <= STRIPLENGTH * 0.5)); + Printf("TMath::Abs(posLoc2[1]) <= HSTRIPY * 0.5 = %d", (int)(TMath::Abs(posLoc2[1]) <= HSTRIPY * 0.5)); + Printf("TMath::Abs(posLoc2[2]) <= WCPCBZ * 0.5 = %d", (int)(TMath::Abs(posLoc2[2]) <= WCPCBZ * 0.5)); + */ if ((TMath::Abs(posLoc2[0]) <= STRIPLENGTH * 0.5) && (TMath::Abs(posLoc2[1]) <= HSTRIPY * 0.5) && (TMath::Abs(posLoc2[2]) <= WCPCBZ * 0.5)) { step[0] = -0.5 * NPADX * XPAD; step[1] = 0.; @@ -531,6 +557,8 @@ Int_t Geo::getPadX(const Float_t* pos) // Int_t iPadX = (Int_t)(pos[0] / XPAD); + //Int_t iPadX = (Int_t)(-1. / XPAD); // just for CZ debugging + // Printf("pos[0] = %f, XPAD = %f, iPadX = %d", pos[0], XPAD, iPadX); if (iPadX == NPADX) iPadX--; else if (iPadX > NPADX) @@ -556,6 +584,7 @@ void Geo::rotateToSector(Float_t* xyz, Int_t isector) Float_t xyzDummy[3] = { 0., 0., 0. }; for (Int_t ii = 0; ii < 3; ii++) { + // Printf("mRotationMatrixSector[isector][ii][0] = %f, mRotationMatrixSector[isector][ii][1] = %f, mRotationMatrixSector[isector][ii][2] = %f", mRotationMatrixSector[isector][ii][0], mRotationMatrixSector[isector][ii][1], mRotationMatrixSector[isector][ii][2]); xyzDummy[ii] = xyz[0] * mRotationMatrixSector[isector][ii][0] + xyz[1] * mRotationMatrixSector[isector][ii][1] + xyz[2] * mRotationMatrixSector[isector][ii][2]; } diff --git a/Detectors/TOF/base/src/TOFBaseLinkDef.h b/Detectors/TOF/base/src/TOFBaseLinkDef.h index 3a6031119a972..1dd54f644f680 100644 --- a/Detectors/TOF/base/src/TOFBaseLinkDef.h +++ b/Detectors/TOF/base/src/TOFBaseLinkDef.h @@ -17,6 +17,6 @@ #pragma link C++ class o2::tof::Geo+; #pragma link C++ class o2::tof::Digit+; #pragma link C++ class vector+; -#pragma link C++ class vector+; +#pragma link C++ class vector>+; #endif From 7c2a2fbcaf5b0bd43fcf6449b77d4a7fd294c5b5 Mon Sep 17 00:00:00 2001 From: zampolli Date: Tue, 13 Nov 2018 12:45:58 +0100 Subject: [PATCH 25/39] Polishing TOF matching code. A lot of debug printing is possible. Two macros added for debugging. --- .../include/GlobalTracking/MatchTOF.h | 2 - Detectors/GlobalTracking/src/MatchTOF.cxx | 214 +++++++----------- Detectors/TOF/base/src/Geo.cxx | 33 +-- Detectors/TOF/prototyping/findLabels.C | 86 +++++++ .../TOF/prototyping/findTOFclusterFromLabel.C | 114 ++++++++++ macro/run_match_tof.C | 19 +- 6 files changed, 290 insertions(+), 178 deletions(-) create mode 100644 Detectors/TOF/prototyping/findLabels.C create mode 100644 Detectors/TOF/prototyping/findTOFclusterFromLabel.C diff --git a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h index c7add030da27a..728ac6ed861ad 100644 --- a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h +++ b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h @@ -15,8 +15,6 @@ #ifndef ALICEO2_GLOBTRACKING_MATCHTOF_ #define ALICEO2_GLOBTRACKING_MATCHTOF_ -#define _ALLOW_DEBUG_TREES_ // to allow debug and control tree output - #include #include #include diff --git a/Detectors/GlobalTracking/src/MatchTOF.cxx b/Detectors/GlobalTracking/src/MatchTOF.cxx index b4d156e96fbe8..716753717b9f8 100644 --- a/Detectors/GlobalTracking/src/MatchTOF.cxx +++ b/Detectors/GlobalTracking/src/MatchTOF.cxx @@ -55,13 +55,14 @@ void MatchTOF::run() // we do the matching per entry of the TPCITS matched tracks tree while (mCurrTracksTreeEntry+1 < mInputTreeTracks->GetEntries()) { // we add "+1" because mCurrTracksTreeEntry starts from -1, and it is incremented in loadTracksNextChunk which is called by prepareTracks - Printf("mCurrTracksTreeEntry = %d", mCurrTracksTreeEntry); + LOG(DEBUG) << "Number of entries in track tree = " << mCurrTracksTreeEntry; mMatchedTracks.clear(); mOutTOFLabels.clear(); mOutTPCLabels.clear(); mOutITSLabels.clear(); prepareTracks(); + /* Uncomment for local debug Printf("*************** Printing the tracks before starting the matching"); // printing the tracks @@ -74,16 +75,17 @@ void MatchTOF::run() for (int itrk = 0; itrk < cacheTrkTmp.size(); itrk++){ auto& trc = mTracksWork[cacheTrkTmp[itrk]]; trc.getXYZGlo(globalPosTmp); - printf("Track %d [in this sector it is the %d]: Global coordinates After propagating to 371 cm: globalPos[0] = %f, globalPos[1] = %f, globalPos[2] = %f\n", totTracks, itrk, globalPosTmp[0], globalPosTmp[1], globalPosTmp[2]); - Printf("The phi angle is %f", TMath::ATan2(globalPosTmp[1], globalPosTmp[0])); + LOG(INFO) << "Track" << totTracks << " [in this sector it is the " << itrk << "]: Global coordinates After propagating to 371 cm: globalPos[0] = " << globalPosTmp[0] << ", globalPos[1] = " << globalPosTmp[1] << ", globalPos[2] = " << globalPosTmp[2]; + LOG(INFO) << "The phi angle is " << TMath::ATan2(globalPosTmp[1], globalPosTmp[0]); totTracks++; } } */ + for (int sec = o2::constants::math::NSectors; sec--;) { - printf("\n\ndoing matching for sector %i...\n", sec); + LOG(INFO) << "Doing matching for sector " << sec << "..."; doMatching(sec); - printf("...done. Now check the best matches\n"); + LOG(INFO) << "...done. Now check the best matches"; selectBestMatches(); } if (0) { // enabling this creates very verbose output @@ -156,18 +158,18 @@ void MatchTOF::print() const { ///< print the settings - printf("\n****** component for the matching of tracks to TF clusters ******\n"); + LOG(INFO) << "****** component for the matching of tracks to TOF clusters ******"; if (!mInitDone) { - printf("init is not done yet\n"); + LOG(INFO) << "init is not done yet - nothing to print"; return; } - printf("MC truth: %s\n", mMCTruthON ? "on" : "off"); - printf("Time tolerance: %.3f\n", mTimeTolerance); - printf("Space tolerance: %.3f\n", mSpaceTolerance); - printf("SigmaTimeCut: %d\n", mSigmaTimeCut); + LOG(INFO) << "MC truth: " << (mMCTruthON ? "on" : "off"); + LOG(INFO) << "Time tolerance: " << mTimeTolerance; + LOG(INFO) << "Space tolerance: " << mSpaceTolerance; + LOG(INFO) << "SigmaTimeCut: " << mSigmaTimeCut; - printf("**********************************************************************\n"); + LOG(INFO) << "**********************************************************************"; } //______________________________________________ @@ -202,15 +204,6 @@ void MatchTOF::attachInputTrees() LOG(INFO) << "Attached tracks " << mTracksBranchName << " branch with " << mInputTreeTracks->GetEntries() << " entries"; - // actual TPC tracks - - /* if (!mTreeTPCTracks->GetBranch(mTPCTracksBranchName.data())) { - LOG(FATAL) << "Did not find TPC tracks branch " << mTPCTracksBranchName << " in the input tree"; - } - mTreeTPCTracks->SetBranchAddress(mTPCTracksBranchName.data(), &mTPCTracksArrayInp); - LOG(INFO) << "Attached TPC tracks " << mTPCTracksBranchName << " branch with " << mTreeTPCTracks->GetEntries() - << " entries"; - */ // input TOF clusters if (!mTreeTOFClusters->GetBranch(mTOFClusterBranchName.data())) { @@ -272,55 +265,32 @@ bool MatchTOF::prepareTracks() int nNotPropagatedToTOF = 0; for (int it = 0; it < mNumOfTracks; it++) { o2::dataformats::TrackTPCITS& trcOrig = (*mTracksArrayInp)[it]; // TODO: check if we cannot directly use the o2::track::TrackParCov class instead of o2::dataformats::TrackTPCITS, and then avoid the casting below; this is the track at the vertex - //o2::track::TrackParCov& trcOrig = (*mTracksArrayInp)[it]; // TODO: check if we cannot directly use the o2::track::TrackParCov class instead of o2::dataformats::TrackTPCITS, and then avoid the casting below; this is the track at the vertex - /* - evIdx evIdxTPC = trcOrig.getRefTPC(); - int indTPC = evIdxTPC.getIndex(); - o2::TPC::TrackTPC& trcTPCOrig = (*mTPCTracksArrayInp)[indTPC]; // we take the track when it is propagated out - */ std::array globalPos; - Printf("\nOriginal Track %d: getTimeMUS().getTimeStamp() = %f, getTimeMUS().getTimeStampError() = %f", it, (*mTracksArrayInp)[it].getTimeMUS().getTimeStamp() , (*mTracksArrayInp)[it].getTimeMUS().getTimeStampError()); + // create working copy of track param mTracksWork.emplace_back(trcOrig);//, mCurrTracksTreeEntry, it); - Printf("Before checking propagation: mTracksWork size = %d", mTracksWork.size()); // make a copy of the TPC track that we have to propagate //o2::TPC::TrackTPC* trc = new o2::TPC::TrackTPC(trcTPCOrig); // this would take the TPCout track auto& trc = mTracksWork.back(); // with this we take the TPCITS track propagated to the vertex - Printf("Copied Track %d: getTimeMUS().getTimeStamp() = %f, getTimeMUS().getTimeStampError() = %f", it, trc.getTimeMUS().getTimeStamp() , trc.getTimeMUS().getTimeStampError()); + // propagate to matching Xref trc.getXYZGlo(globalPos); - printf("Global coordinates Before propagating to 371 cm: globalPos[0] = %f, globalPos[1] = %f, globalPos[2] = %f\n", globalPos[0], globalPos[1], globalPos[2]); - Printf("Radius xy Before propagating to 371 cm = %f", TMath::Sqrt(globalPos[0]*globalPos[0] + globalPos[1]*globalPos[1])); - Printf("Radius xyz Before propagating to 371 cm = %f", TMath::Sqrt(globalPos[0]*globalPos[0] + globalPos[1]*globalPos[1] + globalPos[2]*globalPos[2])); - // mTracksSectIndexCache[o2::utils::Angle2Sector( TMath::ATan2(globalPos[1], globalPos[0]))].push_back(mTracksWork.size() - 1); + LOG(DEBUG) << "Global coordinates Before propagating to 371 cm: globalPos[0] = " << globalPos[0] << ", globalPos[1] = " << globalPos[1] << ", globalPos[2] = " << globalPos[2]; + LOG(DEBUG) << "Radius xy Before propagating to 371 cm = " << TMath::Sqrt(globalPos[0]*globalPos[0] + globalPos[1]*globalPos[1]); + LOG(DEBUG) << "Radius xyz Before propagating to 371 cm = " << TMath::Sqrt(globalPos[0]*globalPos[0] + globalPos[1]*globalPos[1] + globalPos[2]*globalPos[2]); if (!propagateToRefX(trc, mXRef, 2) || TMath::Abs(trc.getZ()) > Geo::MAXHZTOF) { - Printf("The track failed propagation"); - Printf("After checking propagation: mTracksWork size = %d", mTracksWork.size()); - //mTracksWork.pop_back(); // discard track whose propagation to mXRef failed, or those that go beyond TOF in z nNotPropagatedToTOF++; continue; } - else { - Printf("The track succeeded propagation"); - } - Printf("After checking propagation: mTracksWork size = %d", mTracksWork.size()); - - // if (mMCTruthON) { - // mTracksLblWork.emplace_back(mTracksLabels->getLabels(it)[0]); - // } - // cache work track index + trc.getXYZGlo(globalPos); - printf("Global coordinates After propagating to 371 cm: globalPos[0] = %f, globalPos[1] = %f, globalPos[2] = %f\n", globalPos[0], globalPos[1], globalPos[2]); - Printf("Radius xy After propagating to 371 cm = %f", TMath::Sqrt(globalPos[0]*globalPos[0] + globalPos[1]*globalPos[1])); - Printf("Radius xyz After propagating to 371 cm = %f", TMath::Sqrt(globalPos[0]*globalPos[0] + globalPos[1]*globalPos[1] + globalPos[2]*globalPos[2])); - Printf("Before pushing: mTracksWork size = %d", mTracksWork.size()); - Printf("The track will go to sector %d", o2::utils::Angle2Sector(TMath::ATan2(globalPos[1], globalPos[0]))); - //mTracksSectIndexCache[o2::utils::Angle2Sector(TMath::ATan2(globalPos[1], globalPos[0]))].push_back(mTracksWork.size() - 1); + + LOG(DEBUG) << "Global coordinates After propagating to 371 cm: globalPos[0] = " << globalPos[0] << ", globalPos[1] = " << globalPos[1] << ", globalPos[2] = " << globalPos[2]; + LOG(DEBUG) << "Radius xy After propagating to 371 cm = " << TMath::Sqrt(globalPos[0]*globalPos[0] + globalPos[1]*globalPos[1]); + LOG(DEBUG) << "Radius xyz After propagating to 371 cm = " << TMath::Sqrt(globalPos[0]*globalPos[0] + globalPos[1]*globalPos[1] + globalPos[2]*globalPos[2]); + LOG(DEBUG) << "The track will go to sector " << o2::utils::Angle2Sector(TMath::ATan2(globalPos[1], globalPos[0])); + mTracksSectIndexCache[o2::utils::Angle2Sector(TMath::ATan2(globalPos[1], globalPos[0]))].push_back(it); - int labelTPC = mTPCLabels->at(it); - int labelITS = mITSLabels->at(it); - Printf("TPC label of the track = %d", labelTPC); - Printf("ITS label of the track = %d", labelITS); //delete trc; // Check: is this needed? } @@ -339,7 +309,8 @@ bool MatchTOF::prepareTracks() }); } // loop over tracks of single sector - /* + // Uncomment for local debug + /* // printing the tracks std::array globalPos; int itmp = 0; @@ -356,6 +327,7 @@ bool MatchTOF::prepareTracks() } Printf("we have %d tracks",itmp); */ + return true; } //______________________________________________ @@ -374,24 +346,21 @@ bool MatchTOF::prepareTOFClusters() for (int sec = o2::constants::math::NSectors; sec--;) { mTOFClusSectIndexCache[sec].clear(); - //mTOFClusSectIndexCache[sec].reserve(100 + 1.2 * mNumOfClusters / o2::constants::math::NSectors); + //mTOFClusSectIndexCache[sec].reserve(100 + 1.2 * mNumOfClusters / o2::constants::math::NSectors); // we cannot do this, we don't have mNumOfClusters yet } mNumOfClusters = 0; while (loadTOFClustersNextChunk()) { int nClusterInCurrentChunk = mTOFClustersArrayInp->size(); - printf("nClusterInCurrentChunk = %d\n", nClusterInCurrentChunk); + LOG(DEBUG) << "nClusterInCurrentChunk = " << nClusterInCurrentChunk; mNumOfClusters += nClusterInCurrentChunk; for (int it = 0; it < nClusterInCurrentChunk; it++) { Cluster& clOrig = (*mTOFClustersArrayInp)[it]; // create working copy of track param - mTOFClusWork.emplace_back(clOrig);//, mCurrTOFClustersTreeEntry, it); + mTOFClusWork.emplace_back(clOrig); auto& cl = mTOFClusWork.back(); - // if (mMCTruthON) { - // mTOFClusLblWork.emplace_back(mTOFClusLabels->getLabels(it)[0]); - // } // cache work track index mTOFClusSectIndexCache[o2::utils::Angle2Sector(cl.getPhi())].push_back(mTOFClusWork.size() - 1); } @@ -481,6 +450,7 @@ void MatchTOF::doMatching(int sec) mMatchedTracksPairs.clear(); // new sector + //uncomment for local debug /* // printing the tracks std::array globalPosTmp; @@ -509,9 +479,8 @@ void MatchTOF::doMatching(int sec) std::array posBeforeProp; float posFloat[3]; - Printf("Trying to match %d tracks", cacheTrk.size()); + LOG(DEBUG) << "Trying to match %d tracks" << cacheTrk.size(); for (int itrk = 0; itrk < cacheTrk.size(); itrk++) { - Printf("\n\n\n\n ************ track %d **********", itrk); for (int ii = 0; ii < 2; ii++) { detId[ii][2] = -1; // before trying to match, we need to inizialize the detId corresponding to the strip number to -1; this is the array that we will use to save the det id of the maximum 2 strips matched nStepsInsideSameStrip[ii] = 0; @@ -522,14 +491,20 @@ void MatchTOF::doMatching(int sec) float maxTrkTime = (trefTrk.getTimeMUS().getTimeStamp() + mSigmaTimeCut*trefTrk.getTimeMUS().getTimeStampError())*1.E6; // maximum time in ps int istep = 1; // number of steps float step = 0.1; // step size in cm - trefTrk.getXYZGlo(posBeforeProp); + //uncomment for local debug + /* + //trefTrk.getXYZGlo(posBeforeProp); //float posBeforeProp[3] = {trefTrk.getX(), trefTrk.getY(), trefTrk.getZ()}; // in local ref system - printf("Global coordinates: posBeforeProp[0] = %f, posBeforeProp[1] = %f, posBeforeProp[2] = %f\n", posBeforeProp[0], posBeforeProp[1], posBeforeProp[2]); - Printf("Radius xy = %f", TMath::Sqrt(posBeforeProp[0]*posBeforeProp[0] + posBeforeProp[1]*posBeforeProp[1])); - Printf("Radius xyz = %f", TMath::Sqrt(posBeforeProp[0]*posBeforeProp[0] + posBeforeProp[1]*posBeforeProp[1] + posBeforeProp[2]*posBeforeProp[2])); + //printf("Global coordinates: posBeforeProp[0] = %f, posBeforeProp[1] = %f, posBeforeProp[2] = %f\n", posBeforeProp[0], posBeforeProp[1], posBeforeProp[2]); + //Printf("Radius xy = %f", TMath::Sqrt(posBeforeProp[0]*posBeforeProp[0] + posBeforeProp[1]*posBeforeProp[1])); + //Printf("Radius xyz = %f", TMath::Sqrt(posBeforeProp[0]*posBeforeProp[0] + posBeforeProp[1]*posBeforeProp[1] + posBeforeProp[2]*posBeforeProp[2])); + */ +#ifdef _ALLOW_DEBUG_TREES_ (*mDBGOut) << "propOK" << "track=" << trefTrk << "\n"; +#endif + // initializing for (int ii = 0; ii < 2; ii++){ for (int iii = 0; iii < 5; iii++){ @@ -541,40 +516,40 @@ void MatchTOF::doMatching(int sec) if (0 && istep%100 == 0){ printf("istep = %d, currentPosition = %f \n", istep, mXRef+istep*step); } - //float pos[3] = {trefTrk.getX(), trefTrk.getY(), trefTrk.getZ()}; // these are the coordinates in the local ref system trefTrk.getXYZGlo(pos); - //printf("getPadDxDyDz:\n"); for (int ii = 0; ii < 3; ii++){ // we need to change the type... posFloat[ii] = pos[ii]; } - //Printf("posFloat[0] = %f, posFloat[1] = %f, posFloat[2] = %f", posFloat[0], posFloat[1], posFloat[2]); - //Printf("radius xy = %f", TMath::Sqrt(posFloat[0]*posFloat[0] + posFloat[1]*posFloat[1])); - //Printf("radius xyz = %f", TMath::Sqrt(posFloat[0]*posFloat[0] + posFloat[1]*posFloat[1] + posFloat[2]*posFloat[2])); + // uncomment below only for local debug; this will produce A LOT of output - one print per propagation step + /* + Printf("posFloat[0] = %f, posFloat[1] = %f, posFloat[2] = %f", posFloat[0], posFloat[1], posFloat[2]); + Printf("radius xy = %f", TMath::Sqrt(posFloat[0]*posFloat[0] + posFloat[1]*posFloat[1])); + Printf("radius xyz = %f", TMath::Sqrt(posFloat[0]*posFloat[0] + posFloat[1]*posFloat[1] + posFloat[2]*posFloat[2])); + */ for (int idet = 0; idet < 5; idet++) detIdTemp[idet] = -1; Geo::getPadDxDyDz(posFloat, detIdTemp, deltaPosTemp); + // uncomment below only for local debug; this will produce A LOT of output - one print per propagation step //Printf("detIdTemp[0] = %d, detIdTemp[1] = %d, detIdTemp[2] = %d, detIdTemp[3] = %d, detIdTemp[4] = %d", detIdTemp[0], detIdTemp[1], detIdTemp[2], detIdTemp[3], detIdTemp[4]); if (detIdTemp[2] != -1 && nStripsCrossedInPropagation == 0){ // print in case you have a useful propagation - Printf("*********** We have crossed a strip during propagation!*********"); - //printf("Global coordinates: pos[0] = %f, pos[1] = %f, pos[2] = %f\n", pos[0], pos[1], pos[2]); - // printf("detIdTemp[0] = %d, detIdTemp[1] = %d, detIdTemp[2] = %d, detIdTemp[3] = %d, detIdTemp[4] = %d\n", detIdTemp[0], detIdTemp[1], detIdTemp[2], detIdTemp[3], detIdTemp[4]); - //printf("deltaPosTemp[0] = %f, deltaPosTemp[1] = %f, deltaPosTemp[2] = %f\n", deltaPosTemp[0], deltaPosTemp[1], deltaPosTemp[2]); + LOG(DEBUG) << "*********** We have crossed a strip during propagation!*********"; + LOG(DEBUG) << "Global coordinates: pos[0] = " << pos[0] << ", pos[1] = " << pos[1] << ", pos[2] = " << pos[2]; + LOG(DEBUG) << "detIdTemp[0] = " << detIdTemp[0] << ", detIdTemp[1] = " << detIdTemp[1] << ", detIdTemp[2] = " << detIdTemp[2] << ", detIdTemp[3] = " << detIdTemp[3] << ", detIdTemp[4] = " << detIdTemp[4]; + LOG(DEBUG) << "deltaPosTemp[0] = " << deltaPosTemp[0] << ", deltaPosTemp[1] = " << deltaPosTemp[1] << " deltaPosTemp[2] = " << deltaPosTemp[2]; } else { - Printf("*********** We have NOT crossed a strip during propagation!*********"); - printf("Global coordinates: pos[0] = %f, pos[1] = %f, pos[2] = %f\n", pos[0], pos[1], pos[2]); - printf("detIdTemp[0] = %d, detIdTemp[1] = %d, detIdTemp[2] = %d, detIdTemp[3] = %d, detIdTemp[4] = %d\n", detIdTemp[0], detIdTemp[1], detIdTemp[2], detIdTemp[3], detIdTemp[4]); - printf("deltaPosTemp[0] = %f, deltaPosTemp[1] = %f, deltaPosTemp[2] = %f\n", deltaPosTemp[0], deltaPosTemp[1], deltaPosTemp[2]); + LOG(DEBUG) << "*********** We have NOT crossed a strip during propagation!*********"; + LOG(DEBUG) << "Global coordinates: pos[0] = " << pos[0] << ", pos[1] = " << pos[1] << ", pos[2] = " << pos[2]; + LOG(DEBUG) << "detIdTemp[0] = " << detIdTemp[0] << ", detIdTemp[1] = " << detIdTemp[1] << ", detIdTemp[2] = " << detIdTemp[2] << ", detIdTemp[3] = " << detIdTemp[3] << ", detIdTemp[4] = " << detIdTemp[4]; + LOG(DEBUG) << "deltaPosTemp[0] = " << deltaPosTemp[0] << ", deltaPosTemp[1] = " << deltaPosTemp[1] << " deltaPosTemp[2] = " << deltaPosTemp[2]; } - //printf("getPadDxDyDz done\n"); istep++; // check if after the propagation we are in a TOF strip if (detIdTemp[2] != -1) { // we ended in a TOF strip - // Printf("nStripsCrossedInPropagation = %d, detId[nStripsCrossedInPropagation-1][0] = %d, detIdTemp[0] = %d, detId[nStripsCrossedInPropagation-1][1] = %d, detIdTemp[1] =%d, detId[nStripsCrossedInPropagation-1][2] = %d, detIdTemp[2] = %d", nStripsCrossedInPropagation, detId[nStripsCrossedInPropagation-1][0], detIdTemp[0], detId[nStripsCrossedInPropagation-1][1], detIdTemp[1], detId[nStripsCrossedInPropagation-1][2], detIdTemp[2]); + LOG(DEBUG) << "nStripsCrossedInPropagation = " << nStripsCrossedInPropagation << ", detId[nStripsCrossedInPropagation-1][0] = " << detId[nStripsCrossedInPropagation-1][0] << ", detIdTemp[0] = " << detIdTemp[0] << ", detId[nStripsCrossedInPropagation-1][1] = " << detId[nStripsCrossedInPropagation-1][1] << ", detIdTemp[1] = " << detIdTemp[1] << ", detId[nStripsCrossedInPropagation-1][2] = " << detId[nStripsCrossedInPropagation-1][2] << ", detIdTemp[2] = " << detIdTemp[2]; if(nStripsCrossedInPropagation == 0 || // we are crossing a strip for the first time... (nStripsCrossedInPropagation >= 1 && (detId[nStripsCrossedInPropagation-1][0] != detIdTemp[0] || detId[nStripsCrossedInPropagation-1][1] != detIdTemp[1] || detId[nStripsCrossedInPropagation-1][2] != detIdTemp[2]))) { // ...or we are crossing a new strip - // if (nStripsCrossedInPropagation == 0) Printf("We cross a strip for the first time"); - Printf("We are in a TOF strip! %d", detIdTemp[2]); + if (nStripsCrossedInPropagation == 0) LOG(DEBUG) << "We cross a strip for the first time"; if(nStripsCrossedInPropagation == 2) { break; // we have already matched 2 strips, we cannot match more } @@ -600,7 +575,10 @@ void MatchTOF::doMatching(int sec) } } } - printf("while done, we propagated track %d in %d strips\n", itrk, nStripsCrossedInPropagation); + LOG(DEBUG) << "while done, we propagated track " << itrk << " in %d strips" << nStripsCrossedInPropagation; + + // uncomment for debug purposes, to check tracks that did not cross any strip + /* if (nStripsCrossedInPropagation == 0) { auto labelTPCNoStripsCrossed = mTPCLabels->at(mTracksSectIndexCache[sec][itrk]); Printf("The current track (index = %d) never crossed a strip", cacheTrk[itrk]); @@ -609,15 +587,14 @@ void MatchTOF::doMatching(int sec) printf("detIdTemp[0] = %d, detIdTemp[1] = %d, detIdTemp[2] = %d, detIdTemp[3] = %d, detIdTemp[4] = %d\n", detIdTemp[0], detIdTemp[1], detIdTemp[2], detIdTemp[3], detIdTemp[4]); printf("deltaPosTemp[0] = %f, deltaPosTemp[1] = %f, deltaPosTemp[2] = %f\n", deltaPosTemp[0], deltaPosTemp[1], deltaPosTemp[2]); } - Printf("We will check now the %d TOF clusters", nTOFCls); + */ for(Int_t imatch = 0; imatch < nStripsCrossedInPropagation; imatch++){ - //printf("imatch = %d\n", imatch); // we take as residual the average of the residuals along the propagation in the same strip deltaPos[imatch][0] /= nStepsInsideSameStrip[imatch]; deltaPos[imatch][1] /= nStepsInsideSameStrip[imatch]; deltaPos[imatch][2] /= nStepsInsideSameStrip[imatch]; - printf("matched strip %d: deltaPos[0] = %f, deltaPos[1] = %f, deltaPos[2] = %f, residual (x, z) = %f\n", imatch, deltaPos[imatch][0], deltaPos[imatch][1], deltaPos[imatch][2], TMath::Sqrt(deltaPos[imatch][0]*deltaPos[imatch][0] + deltaPos[imatch][2]*deltaPos[imatch][2])); + LOG(DEBUG) << "matched strip " << imatch << ": deltaPos[0] = " << deltaPos[imatch][0] << ", deltaPos[1] = " << deltaPos[imatch][1] << ", deltaPos[2] = " << deltaPos[imatch][2] << ", residual (x, z) = " << TMath::Sqrt(deltaPos[imatch][0]*deltaPos[imatch][0] + deltaPos[imatch][2]*deltaPos[imatch][2]); } if (nStripsCrossedInPropagation == 0) { @@ -625,11 +602,12 @@ void MatchTOF::doMatching(int sec) } Printf("We will check now the %d TOF clusters", nTOFCls); bool foundCluster = false; + auto labelTPC = mTPCLabels->at(mTracksSectIndexCache[sec][itrk]); for (auto itof = itof0; itof < nTOFCls; itof++) { // printf("itof = %d\n", itof); auto& trefTOF = mTOFClusWork[cacheTOF[itof]]; // compare the times of the track and the TOF clusters - remember that they both are ordered in time! - Printf("trefTOF.getTime() = %f, maxTrkTime = %f, minTrkTime = %f", trefTOF.getTime(), maxTrkTime, minTrkTime); + //Printf("trefTOF.getTime() = %f, maxTrkTime = %f, minTrkTime = %f", trefTOF.getTime(), maxTrkTime, minTrkTime); /* This part is commented out for now, as we don't want to have any check on the time enabled if (trefTOF.getTime() < minTrkTime) { // this cluster has a time that is too small for the current track, we will get to the next one Printf("In trefTOF.getTime() < minTrkTime"); @@ -648,13 +626,12 @@ void MatchTOF::doMatching(int sec) int eventIdTOF; int sourceIdTOF; for (auto iPropagation = 0; iPropagation < nStripsCrossedInPropagation; iPropagation++){ - printf("iPropagation = %d\n", iPropagation); - Printf("TOF Cluster [%d, %d]: indices = %d, %d, %d, %d, %d", itof, cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4]); - Printf("Propagated Track [%d, %d]: detId[%d] = %d, %d, %d, %d, %d", itrk, cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4]); + LOG(DEBUG) << "TOF Cluster [" << itof << ", " << cacheTOF[itof] << "]: indices = " << indices[0], indices[1], indices[2], indices[3], indices[4]; + LOG(DEBUG) << "Propagated Track [" << itrk << ", " << cacheTrk[itrk] << "]: detId[" << iPropagation << "] = " << detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4]; float resX = deltaPos[iPropagation][0] - (indices[4] - detId[iPropagation][4])*Geo::XPAD; // readjusting the residuals due to the fact that the propagation fell in a pad that was not exactly the one of the cluster float resZ = deltaPos[iPropagation][2] - (indices[3] - detId[iPropagation][3])*Geo::ZPAD; // readjusting the residuals due to the fact that the propagation fell in a pad that was not exactly the one of the cluster float res = TMath::Sqrt(resX*resX + resZ*resZ); - Printf("resX = %f, resZ = %f, res = %f", resX, resZ, res); + LOG(DEBUG) << "resX = " << resX << ", resZ = " << resZ << ", res = " << res; #ifdef _ALLOW_DEBUG_TREES_ fillTOFmatchTree("match0", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk); #endif @@ -666,7 +643,7 @@ void MatchTOF::doMatching(int sec) tofLabelEventID[ilabel] = labelsTOF[ilabel].getEventID(); tofLabelSourceID[ilabel] = labelsTOF[ilabel].getSourceID(); } - auto labelTPC = mTPCLabels->at(mTracksSectIndexCache[indices[0]][itrk]); + //auto labelTPC = mTPCLabels->at(mTracksSectIndexCache[indices[0]][itrk]); auto labelITS = mITSLabels->at(mTracksSectIndexCache[indices[0]][itrk]); fillTOFmatchTreeWithLabels("matchPossibleWithLabels", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk, labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID(), labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID(), tofLabelTrackID[0], tofLabelEventID[0], tofLabelSourceID[0], tofLabelTrackID[1], tofLabelEventID[1], tofLabelSourceID[1], tofLabelTrackID[2], tofLabelEventID[2], tofLabelSourceID[2]); if (indices[0] != detId[iPropagation][0]) continue; @@ -678,22 +655,19 @@ void MatchTOF::doMatching(int sec) fillTOFmatchTreeWithLabels("matchOkWithLabels", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk, labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID(), labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID(), tofLabelTrackID[0], tofLabelEventID[0], tofLabelSourceID[0], tofLabelTrackID[1], tofLabelEventID[1], tofLabelSourceID[1], tofLabelTrackID[2], tofLabelEventID[2], tofLabelSourceID[2]); if (res < mSpaceTolerance) { // matching ok! - Printf("YUHUUUUUUUUU! We have a match! between track %d and TOF cluster %d", mTracksSectIndexCache[indices[0]][itrk], mTOFClusSectIndexCache[indices[0]][itof]); + LOG(DEBUG) << "MATCHING FOUND: We have a match! between track " << mTracksSectIndexCache[indices[0]][itrk] << " and TOF cluster " << mTOFClusSectIndexCache[indices[0]][itof]; foundCluster = true; mMatchedTracksPairs.push_back(std::make_pair(mTracksSectIndexCache[indices[0]][itrk], o2::dataformats::MatchInfoTOF(mTOFClusSectIndexCache[indices[0]][itof], chi2))); // TODO: check if this is correct! for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++){ - Printf("TOF label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTOF[ilabel].getTrackID(), labelsTOF[ilabel].getEventID(), labelsTOF[ilabel].getSourceID()); + LOG(DEBUG) << "TOF label " << ilabel << ": trackID = " << labelsTOF[ilabel].getTrackID() << ", eventID = " << labelsTOF[ilabel].getEventID() << ", sourceID = " << labelsTOF[ilabel].getSourceID(); } - Printf("TPC label of the track: trackID = %d, eventID = %d, sourceID = %d", labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID()); - Printf("ITS label of the track: trackID = %d, eventID = %d, sourceID = %d", labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID()); + LOG(DEBUG) << "TPC label of the track: trackID = " << labelTPC.getTrackID() << ", eventID = " << labelTPC.getEventID() << ", sourceID = " << labelTPC.getSourceID(); + LOG(DEBUG) << "ITS label of the track: trackID = " << labelITS.getTrackID() << ", eventID = " << labelITS.getEventID() << ", sourceID = " << labelITS.getSourceID(); fillTOFmatchTreeWithLabels("matchOkWithLabelsInSpaceTolerance", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk, labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID(), labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID(), tofLabelTrackID[0], tofLabelEventID[0], tofLabelSourceID[0], tofLabelTrackID[1], tofLabelEventID[1], tofLabelSourceID[1], tofLabelTrackID[2], tofLabelEventID[2], tofLabelSourceID[2]); } - else { - Printf("We have not matched with any TOF cluster"); - } } } - if (!foundCluster) Printf("We did not find any TOF cluster for track %d", cacheTrk[itrk]); + if (!foundCluster) LOG(DEBUG) << "We did not find any TOF cluster for track " << cacheTrk[itrk] << " (label = " << labelTPC.getTrackID() << ", pt = " << trefTrk.getPt(); } return; } @@ -709,7 +683,6 @@ void MatchTOF::selectBestMatches() int i = 0; // then we take discard the pairs if their track or cluster was already matched (since they are ordered in chi2, we will take the best matching) for (const std::pair &matchingPair : mMatchedTracksPairs){ - Printf("selectBestMatches: i = %d", i); if (mMatchedTracksIndex[matchingPair.first] != -1) { // the track was already filled continue; } @@ -718,24 +691,17 @@ void MatchTOF::selectBestMatches() } mMatchedTracksIndex[matchingPair.first] = mMatchedTracks.size(); // index of the MatchInfoTOF correspoding to this track mMatchedClustersIndex[matchingPair.second.getTOFClIndex()] = mMatchedTracksIndex[matchingPair.first]; // index of the track that was matched to this cluster - //mMatchedTracks.push_back(matchingPair.second); // array of MatchInfoTOF mMatchedTracks.push_back(matchingPair); // array of MatchInfoTOF - Printf("size of mMatchedTracks = %d", mMatchedTracks.size()); - int labelTPCint = mTPCLabels->at(matchingPair.first); - int labelITSint = mITSLabels->at(matchingPair.first); - Printf("TPC label of the track = %d", labelTPCint); - Printf("ITS label of the track = %d", labelITSint); const auto& labelTPC = mTPCLabels->at(matchingPair.first); - Printf("labelTPC: trackID = %d, eventID = %d, sourceID = %d", labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID()); + LOG(DEBUG) << "labelTPC: trackID = " << labelTPC.getTrackID() << ", eventID = " << labelTPC.getEventID() << ", sourceID = " << labelTPC.getSourceID(); const auto& labelITS = mITSLabels->at(matchingPair.first); - Printf("labelITS: trackID = %d, eventID = %d, sourceID = %d", labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID()); + LOG(DEBUG) << "labelITS: trackID = " << labelITS.getTrackID() << ", eventID = " << labelITS.getEventID() << ", sourceID = " << labelITS.getSourceID(); const auto& labelsTOF = mTOFClusLabels->getLabels(matchingPair.second.getTOFClIndex()); bool labelOk = false; // whether we have found or not the same TPC label of the track among the labels of the TOF cluster for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++){ - Printf("TOF label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTOF[ilabel].getTrackID(), labelsTOF[ilabel].getEventID(), labelsTOF[ilabel].getSourceID()); + LOG(DEBUG) << "TOF label " << ilabel << ": trackID = " << labelsTOF[ilabel].getTrackID() << ", eventID = " << labelsTOF[ilabel].getEventID() << ", sourceID = " << labelsTOF[ilabel].getSourceID(); if (labelsTOF[ilabel].getTrackID() == labelTPC.getTrackID() && labelsTOF[ilabel].getEventID() == labelTPC.getEventID() && labelsTOF[ilabel].getSourceID() == labelTPC.getSourceID() && !labelOk) { // if we find one TOF cluster label that is the same as the TPC one, we are happy - even if it is not the first one mOutTOFLabels.push_back(labelsTOF[ilabel]); - Printf("Adding label for good match %d", mOutTOFLabels.size() ); labelOk = true; } } @@ -744,22 +710,17 @@ void MatchTOF::selectBestMatches() o2::MCCompLabel fakeTOFlabel; fakeTOFlabel.set(-labelsTOF[0].getTrackID(), labelsTOF[0].getEventID(), labelsTOF[0].getSourceID()); mOutTOFLabels.push_back(fakeTOFlabel); - Printf("Adding label for fake match %d", mOutTOFLabels.size()); } mOutTPCLabels.push_back(labelTPC); mOutITSLabels.push_back(labelITS); i++; } - Printf("size of mOutTPCLabels = %d", mOutTPCLabels.size()); - Printf("size of mOutITSLabels = %d", mOutITSLabels.size()); - Printf("size of mOutTOFLabels = %d", mOutTOFLabels.size()); } //______________________________________________ bool MatchTOF::propagateToRefX(o2::track::TrackParCov& trc, float xRef, float stepInCm) { - // printf("in propagateToRefX\n"); // propagate track to matching reference X bool refReached = false; float xStart = trc.getX(); @@ -768,10 +729,8 @@ bool MatchTOF::propagateToRefX(o2::track::TrackParCov& trc, float xRef, float st int istep = 1; bool hasPropagated = o2::Base::Propagator::Instance()->PropagateToXBxByBz(trc, xStart + istep*stepInCm, o2::constants::physics::MassPionCharged, MAXSNP, stepInCm, 0.); while (hasPropagated) { - //Printf("propagateToRefX: istep = %d", istep); if (trc.getX() > xRef) { refReached = true; // we reached the 371cm reference - // Printf("propagateToRefX: trc.getX() > xRef --> refReached = true"); } istep++; if (fabs(trc.getY()) > trc.getX() * tan(o2::constants::math::SectorSpanRad / 2)) { // we are still in the same sector @@ -780,18 +739,16 @@ bool MatchTOF::propagateToRefX(o2::track::TrackParCov& trc, float xRef, float st auto alphaNew = o2::utils::Angle2Alpha(trc.getPhiPos()); if (!trc.rotate(alphaNew) != 0) { // Printf("propagateToRefX: failed to rotate"); - break; // failed (RS: check effect on matching tracks to neighbouring sector) + break; // failed (this line is taken from MatchTPCITS and the following comment too: RS: check effect on matching tracks to neighbouring sector) } } if (refReached) break; hasPropagated = o2::Base::Propagator::Instance()->PropagateToXBxByBz(trc, xStart + istep*stepInCm, o2::constants::physics::MassPionCharged, MAXSNP, stepInCm, 0.); } - // Printf("propagateToXRef: hasPropagate(%d) = %d", istep, hasPropagated); - if (std::abs(trc.getSnp()) > MAXSNP) Printf("propagateToRefX: condition on snp not ok, returning false"); - //Printf("propagateToRefX: final x of the track = %f, refReached at the end is %d", trc.getX(), (int)refReached); + // if (std::abs(trc.getSnp()) > MAXSNP) Printf("propagateToRefX: condition on snp not ok, returning false"); //Printf("propagateToRefX: snp of teh track is %f (--> %f grad)", trc.getSnp(), TMath::ASin(trc.getSnp())*TMath::RadToDeg()); - return refReached && std::abs(trc.getSnp()) < 0.95; - //return refReached; + return refReached && std::abs(trc.getSnp()) < 0.95; // Here we need to put MAXSNP + } #ifdef _ALLOW_DEBUG_TREES_ @@ -814,6 +771,7 @@ void MatchTOF::fillTOFmatchTree(const char* trname, int cacheTOF, int sectTOF, i mTimerDBG.Start(false); // Printf("************** Filling the debug tree with %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %f, %f, %f", cacheTOF, sectTOF, plateTOF, stripTOF, padXTOF, padZTOF, cacheeTrk, crossedStrip, sectPropagation, platePropagation, stripPropagation, padXPropagation, padZPropagation, resX, resZ, res); + (*mDBGOut) << trname << "clusterTOF=" << cacheTOF << "sectTOF=" << sectTOF << "plateTOF=" << plateTOF << "stripTOF=" << stripTOF << "padXTOF=" << padXTOF << "padZTOF=" << padZTOF << "crossedStrip=" << crossedStrip << "sectPropagation=" << sectPropagation << "platePropagation=" << platePropagation << "stripPropagation=" << stripPropagation << "padXPropagation=" << padXPropagation diff --git a/Detectors/TOF/base/src/Geo.cxx b/Detectors/TOF/base/src/Geo.cxx index 1f18deeea12fa..342650af2d0d1 100644 --- a/Detectors/TOF/base/src/Geo.cxx +++ b/Detectors/TOF/base/src/Geo.cxx @@ -370,40 +370,12 @@ Int_t Geo::fromPlateToStrip(Float_t* pos, Int_t iplate) for (Int_t istrip = 0; istrip < nstrips; istrip++) { Float_t posLoc2[3] = { pos[0], pos[1], pos[2] }; - /* - for (int ii = 0; ii < 3; ii++){ - Printf("posLoc2[%d] = %f", ii, posLoc2[ii]); - } - */ step[0] = 0.; step[1] = getHeights(iplate, istrip); step[2] = -getDistances(iplate, istrip); - /* for (int ii = 0; ii < 3; ii++){ - Printf("step[%d] = %f", ii, step[ii]); - } - */ translate(posLoc2, step); - /* - Printf("After translation"); - for (int ii = 0; ii < 3; ii++){ - Printf("posLoc2[%d] = %f", ii, posLoc2[ii]); - } - */ rotateToStrip(posLoc2, iplate, istrip); - /* -Printf("After rotation"); - for (int ii = 0; ii < 3; ii++){ - Printf("posLoc2[%d] = %f", ii, posLoc2[ii]); - } - */ - /* - Printf("STRIPLENGTH = %f", STRIPLENGTH); - Printf("HSTRIPY = %f", HSTRIPY); - Printf("WCPCBZ = %f", WCPCBZ); - Printf("TMath::Abs(posLoc2[0]) <= STRIPLENGTH * 0.5 = %d", (int)(TMath::Abs(posLoc2[0]) <= STRIPLENGTH * 0.5)); - Printf("TMath::Abs(posLoc2[1]) <= HSTRIPY * 0.5 = %d", (int)(TMath::Abs(posLoc2[1]) <= HSTRIPY * 0.5)); - Printf("TMath::Abs(posLoc2[2]) <= WCPCBZ * 0.5 = %d", (int)(TMath::Abs(posLoc2[2]) <= WCPCBZ * 0.5)); - */ if ((TMath::Abs(posLoc2[0]) <= STRIPLENGTH * 0.5) && (TMath::Abs(posLoc2[1]) <= HSTRIPY * 0.5) && + if ((TMath::Abs(posLoc2[0]) <= STRIPLENGTH * 0.5) && (TMath::Abs(posLoc2[1]) <= HSTRIPY * 0.5) && (TMath::Abs(posLoc2[2]) <= WCPCBZ * 0.5)) { step[0] = -0.5 * NPADX * XPAD; step[1] = 0.; @@ -557,8 +529,6 @@ Int_t Geo::getPadX(const Float_t* pos) // Int_t iPadX = (Int_t)(pos[0] / XPAD); - //Int_t iPadX = (Int_t)(-1. / XPAD); // just for CZ debugging - // Printf("pos[0] = %f, XPAD = %f, iPadX = %d", pos[0], XPAD, iPadX); if (iPadX == NPADX) iPadX--; else if (iPadX > NPADX) @@ -584,7 +554,6 @@ void Geo::rotateToSector(Float_t* xyz, Int_t isector) Float_t xyzDummy[3] = { 0., 0., 0. }; for (Int_t ii = 0; ii < 3; ii++) { - // Printf("mRotationMatrixSector[isector][ii][0] = %f, mRotationMatrixSector[isector][ii][1] = %f, mRotationMatrixSector[isector][ii][2] = %f", mRotationMatrixSector[isector][ii][0], mRotationMatrixSector[isector][ii][1], mRotationMatrixSector[isector][ii][2]); xyzDummy[ii] = xyz[0] * mRotationMatrixSector[isector][ii][0] + xyz[1] * mRotationMatrixSector[isector][ii][1] + xyz[2] * mRotationMatrixSector[isector][ii][2]; } diff --git a/Detectors/TOF/prototyping/findLabels.C b/Detectors/TOF/prototyping/findLabels.C new file mode 100644 index 0000000000000..69d24dbc75485 --- /dev/null +++ b/Detectors/TOF/prototyping/findLabels.C @@ -0,0 +1,86 @@ +void findLabels(int itrk, int ientry){ + + // macro to find the labels of a TPCITS track and the corresponding TOF cluster + + // getting the ITSTPCtracks + TFile* fmatchITSTPC = new TFile("o2match_itstpc.root"); + TTree* matchTPCITS = (TTree*)fmatchITSTPC->Get("matchTPCITS"); + std::vector* mTracksArrayInp = new std::vector; + matchTPCITS->SetBranchAddress("TPCITS", &mTracksArrayInp); + matchTPCITS->GetEntry(ientry); + + // getting the TPC tracks + TFile* ftracksTPC = new TFile("tpctracks.root"); + TTree* tpcTree = (TTree*) ftracksTPC->Get("events"); + std::vector* mTPCTracksArrayInp = new std::vector; + tpcTree->SetBranchAddress("Tracks", &mTPCTracksArrayInp); + o2::dataformats::MCTruthContainer* mcTPC = new o2::dataformats::MCTruthContainer(); + tpcTree->SetBranchAddress("TPCTracksMCTruth", &mcTPC); + + // getting the ITS tracks + TFile* ftracksITS = new TFile("o2trac_its.root"); + TTree* itsTree = (TTree*) ftracksITS->Get("o2sim"); + std::vector* mITSTracksArrayInp = new std::vector; + itsTree->SetBranchAddress("ITSTrack", &mITSTracksArrayInp); + o2::dataformats::MCTruthContainer* mcITS = new o2::dataformats::MCTruthContainer(); + itsTree->SetBranchAddress("ITSTrackMCTruth", &mcITS); + + // getting the TOF clusters + TFile* fclustersTOF = new TFile("tofclusters.root"); + TTree* tofClTree = (TTree*) fclustersTOF->Get("o2sim"); + std::vector* mTOFClustersArrayInp = new std::vector; + tofClTree->SetBranchAddress("TOFCluster", &mTOFClustersArrayInp); + o2::dataformats::MCTruthContainer* mcTOF = new o2::dataformats::MCTruthContainer(); + tofClTree->SetBranchAddress("TOFClusterMCTruth", &mcTOF); + + tpcTree->GetEntry(0); + tofClTree->GetEntry(0); + + o2::dataformats::TrackTPCITS trackITSTPC = mTracksArrayInp->at(itrk); + const o2::dataformats::EvIndex &evIdxTPC = trackITSTPC.getRefTPC(); + Printf("matched TPCtrack: eventID = %d, indexID = %d", evIdxTPC.getEvent(), evIdxTPC.getIndex()); + const o2::dataformats::EvIndex &evIdxITS = trackITSTPC.getRefITS(); + Printf("matched ITStrack: eventID = %d, indexID = %d", evIdxITS.getEvent(), evIdxITS.getIndex()); + itsTree->GetEntry(evIdxITS.getEvent()); + + // getting the TPC labels + const auto& labelsTPC = mcTPC->getLabels(evIdxTPC.getIndex()); + for (int ilabel = 0; ilabel < labelsTPC.size(); ilabel++){ + Printf("TPC label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTPC[ilabel].getTrackID(), labelsTPC[ilabel].getEventID(), labelsTPC[ilabel].getSourceID()); + } + + // getting the ITS labels + const auto& labelsITS = mcITS->getLabels(evIdxITS.getIndex()); + for (int ilabel = 0; ilabel < labelsITS.size(); ilabel++){ + Printf("ITS label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsITS[ilabel].getTrackID(), labelsITS[ilabel].getEventID(), labelsITS[ilabel].getSourceID()); + } + + // now checking if we have a corresponding cluster + bool found = false; + for (int tofClIndex = 0; tofClIndex < mTOFClustersArrayInp->size(); tofClIndex++){ + o2::tof::Cluster tofCluster = mTOFClustersArrayInp->at(tofClIndex); + const auto& labelsTOF = mcTOF->getLabels(tofClIndex); + int trackIdTOF; + int eventIdTOF; + int sourceIdTOF; + for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++){ + if ((labelsTPC[0].getTrackID() == labelsTOF[ilabel].getTrackID() && labelsTPC[0].getEventID() == labelsTOF[ilabel].getEventID() && labelsTPC[0].getSourceID() == labelsTOF[ilabel].getSourceID()) || (labelsITS[0].getTrackID() == labelsTOF[ilabel].getTrackID() && labelsITS[0].getEventID() == labelsTOF[ilabel].getEventID() && labelsITS[0].getSourceID() == labelsTOF[ilabel].getSourceID())) { + Printf("The corresponding TOF cluster is %d", tofClIndex); + Printf("TOF label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTOF[ilabel].getTrackID(), labelsTOF[ilabel].getEventID(), labelsTOF[ilabel].getSourceID()); + found = true; + int nContrChannels = tofCluster.getNumOfContributingChannels(); + int mainContrChannel = tofCluster.getMainContributingChannel(); + int* indices = new int[5]; + o2::tof::Geo::getVolumeIndices(mainContrChannel, indices); + Printf("main contributing channel: sector = %d, plate = %d, strip = %d, padz = %d, padx = %d", indices[0], indices[1] , indices[2], indices[3], indices[4]); + break; + } + } + } + if (!found) Printf("No TOF cluster corresponding to this track was found"); + + return; +} + + + diff --git a/Detectors/TOF/prototyping/findTOFclusterFromLabel.C b/Detectors/TOF/prototyping/findTOFclusterFromLabel.C new file mode 100644 index 0000000000000..571f0ad500e6a --- /dev/null +++ b/Detectors/TOF/prototyping/findTOFclusterFromLabel.C @@ -0,0 +1,114 @@ +void findTOFclusterFromLabel(int trackID, int eventID = 0, int sourceID = 0){ + + // macro to find the labels of a TPCITS track and the corresponding TOF cluster + + // getting the TOF clusters + TFile* fclustersTOF = new TFile("tofclusters.root"); + TTree* tofClTree = (TTree*) fclustersTOF->Get("o2sim"); + std::vector* mTOFClustersArrayInp = new std::vector; + tofClTree->SetBranchAddress("TOFCluster", &mTOFClustersArrayInp); + o2::dataformats::MCTruthContainer* mcTOF = new o2::dataformats::MCTruthContainer(); + tofClTree->SetBranchAddress("TOFClusterMCTruth", &mcTOF); + + tofClTree->GetEntry(0); + + // now checking if we have a corresponding cluster + bool found = false; + for (int tofClIndex = 0; tofClIndex < mTOFClustersArrayInp->size(); tofClIndex++){ + o2::tof::Cluster tofCluster = mTOFClustersArrayInp->at(tofClIndex); + const auto& labelsTOF = mcTOF->getLabels(tofClIndex); + int trackIdTOF; + int eventIdTOF; + int sourceIdTOF; + for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++){ + if (trackID == labelsTOF[ilabel].getTrackID() && eventID == labelsTOF[ilabel].getEventID() && sourceID == labelsTOF[ilabel].getSourceID()) { + Printf("The corresponding TOF cluster is %d", tofClIndex); + Printf("TOF label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTOF[ilabel].getTrackID(), labelsTOF[ilabel].getEventID(), labelsTOF[ilabel].getSourceID()); + found = true; + int nContrChannels = tofCluster.getNumOfContributingChannels(); + int mainContrChannel = tofCluster.getMainContributingChannel(); + int* indices = new int[5]; + o2::tof::Geo::getVolumeIndices(mainContrChannel, indices); + Printf("main contributing channel: sector = %d, plate = %d, strip = %d, padz = %d, padx = %d", indices[0], indices[1] , indices[2], indices[3], indices[4]); + break; + } + } + } + if (!found) Printf("No TOF cluster corresponding to this label was found"); + + TFile* fdigitsTOF = new TFile("tofdigits.root"); + TTree* tofDigTree = (TTree*) fdigitsTOF->Get("o2sim"); + std::vector>* mTOFDigitsArrayInp = nullptr; + tofDigTree->SetBranchAddress("TOFDigit", &mTOFDigitsArrayInp); + std::vector>* mcTOFDig = nullptr; + tofDigTree->SetBranchAddress("TOFDigitMCTruth", &mcTOFDig); + bool foundInDigits = false; + Printf("Now looking in the digits"); + for (int ientry = 0; ientry < tofDigTree->GetEntries(); ientry++){ + //Printf("\n\nEntry in tree %d", ientry); + tofDigTree->GetEntry(ientry); + for (int iVect = 0; iVect < mTOFDigitsArrayInp->size(); iVect++){ + //Printf("\nEntry in vector of digits and MC truth %d", iVect); + std::vector digitVector = mTOFDigitsArrayInp->at(iVect); + o2::dataformats::MCTruthContainer digitMCTruth = mcTOFDig->at(iVect); + for (int iDig = 0; iDig < digitVector.size(); iDig++){ + //Printf("Digit %d", iDig); + o2::tof::Digit digit = digitVector.at(iDig); + int digitLabel = digit.getLabel(); + gsl::span mcArray = digitMCTruth.getLabels(digitLabel); + for (int j = 0; j < static_cast(mcArray.size()); j++) { + //printf("checking element %d in the array of labels\n", j); + auto label = digitMCTruth.getElement(digitMCTruth.getMCTruthHeader(digitLabel).index + j); + //printf("TrackID = %d, EventID = %d, SourceID = %d\n", label.getTrackID(), label.getEventID(), label.getSourceID()); + if (label.getTrackID() == trackID && label.getEventID() == eventID && label.getSourceID() == sourceID){ + Printf("We found the label that we were looking for! tree entry = %d, vector entry = %d, digit = %d", ientry, iVect, iDig); + foundInDigits = true; + } + } + } + } + } + if (!foundInDigits) Printf("The label was NEVER found in the digits"); + + TFile* fKine = new TFile("o2sim.root"); + TTree* tKine = (TTree*)fKine->Get("o2sim"); + std::vector* mcArr = nullptr; + tKine->SetBranchAddress("MCTrack", &mcArr); + tKine->GetEntry(eventID); + for (int i = 0; i < mcArr->size(); ++i) { + const auto& mcTrack = (*mcArr)[i]; + if (i == trackID) { + Printf("Particle %d: pdg = %d, pT = %f, px = %f, py = %f, pz = %f, vx = %f, vy = %f, vz = %f", i, mcTrack.GetPdgCode(), TMath::Abs(mcTrack.GetStartVertexMomentumX()*mcTrack.GetStartVertexMomentumX() + mcTrack.GetStartVertexMomentumY()*mcTrack.GetStartVertexMomentumY()), mcTrack.GetStartVertexMomentumX(), mcTrack.GetStartVertexMomentumY(), mcTrack.GetStartVertexMomentumZ(), mcTrack.GetStartVertexCoordinatesX(), mcTrack.GetStartVertexCoordinatesY(), mcTrack.GetStartVertexCoordinatesZ() ); + } + } + + TFile* fmatch = new TFile("o2match_itstpc.root"); + TTree* matchTPCITS = (TTree*)fmatch->Get("matchTPCITS"); + std::vector* mTracksArrayInp = new std::vector; + matchTPCITS->SetBranchAddress("TPCITS", &mTracksArrayInp); + matchTPCITS->GetEntry(eventID); + + // getting the TPC tracks + TFile* ftracksTPC = new TFile("tpctracks.root"); + TTree* tpcTree = (TTree*) ftracksTPC->Get("events"); + std::vector* mTPCTracksArrayInp = new std::vector; + tpcTree->SetBranchAddress("Tracks", &mTPCTracksArrayInp); + o2::dataformats::MCTruthContainer* mcTPC = new o2::dataformats::MCTruthContainer(); + tpcTree->SetBranchAddress("TPCTracksMCTruth", &mcTPC); + tpcTree->GetEntry(eventID); + + for (int i = 0; i < mTracksArrayInp->size(); i++){ + o2::dataformats::TrackTPCITS trackITSTPC = mTracksArrayInp->at(i); + const o2::dataformats::EvIndex &evIdxTPC = trackITSTPC.getRefTPC(); + const auto& labelsTPC = mcTPC->getLabels(evIdxTPC.getIndex()); + for (int ilabel = 0; ilabel < labelsTPC.size(); ilabel++){ + //Printf("TPC label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTPC[ilabel].getTrackID(), labelsTPC[ilabel].getEventID(), labelsTPC[ilabel].getSourceID()); + if (labelsTPC[ilabel].getTrackID() == trackID && labelsTPC[ilabel].getEventID() == eventID) Printf("TPC track found"); + } + } + + return; +} + + + diff --git a/macro/run_match_tof.C b/macro/run_match_tof.C index a68cd23e578dd..d9ceed40806b8 100644 --- a/macro/run_match_tof.C +++ b/macro/run_match_tof.C @@ -14,6 +14,8 @@ #include "GlobalTracking/MatchTOF.h" #endif +#define _ALLOW_DEBUG_TREES_ // to allow debug and control tree output + void run_match_tof(std::string path = "./", std::string outputfile = "o2match_tof.root", std::string inputTracksTPCITS = "o2match_itstpc.root", std::string inputTracksTPC = "tpctracks.root", @@ -50,28 +52,13 @@ void run_match_tof(std::string path = "./", std::string outputfile = "o2match_to #ifdef _ALLOW_DEBUG_TREES_ matching.setDebugTreeFileName(path + matching.getDebugTreeFileName()); - // dump accepted pairs only - //matching.setDebugFlag(o2::globaltracking::MatchTPCITS::MatchTreeAccOnly); - // dump all checked pairs - matching.setDebugFlag(o2::globaltracking::MatchTPCITS::MatchTreeAll); - // dump winner matches - //matching.setDebugFlag(o2::globaltracking::MatchTPCITS::WinnerMatchesTree); + matching.setDebugFlag(o2::globaltracking::MatchTOF::MatchTreeAll); #endif //-------- init geometry and field --------// o2::Base::GeometryManager::loadGeometry(path + inputGeom, "FAIRGeom"); o2::Base::Propagator::initFieldFromGRP(path + inputGRP); - //-------------------- settings -----------// - /* - matching.setITSROFrameLengthMUS(5.0f); // ITS ROFrame duration in \mus - matching.setCutMatchingChi2(100.); - std::array cutsAbs = { 2.f, 2.f, 0.2f, 0.2f, 4.f }; - std::array cutsNSig2 = { 49.f, 49.f, 49.f, 49.f, 49.f }; - matching.setCrudeAbsDiffCut(cutsAbs); - matching.setCrudeNSigma2Cut(cutsNSig2); - matching.setTPCTimeEdgeZSafeMargin(3); - */ matching.init(); matching.run(); From 89facef69021ac8263a5b75dfd7cfa51152751fb Mon Sep 17 00:00:00 2001 From: zampolli Date: Mon, 26 Nov 2018 15:45:43 +0100 Subject: [PATCH 26/39] Applying style --- .../TOF/include/DataFormatsTOF/Cluster.h | 20 +- DataFormats/Detectors/TOF/src/Cluster.cxx | 7 +- .../ReconstructionDataFormats/MatchInfoTOF.h | 5 +- .../simulation/src/SimulationDataLinkDef.h | 2 +- .../include/GlobalTracking/MatchTOF.h | 79 ++-- .../src/GlobalTrackingLinkDef.h | 12 +- Detectors/GlobalTracking/src/MatchTOF.cxx | 341 +++++++++--------- Detectors/TOF/base/include/TOFBase/Geo.h | 2 +- Detectors/TOF/base/src/Geo.cxx | 6 +- Detectors/TOF/base/src/TOFBaseLinkDef.h | 2 +- Detectors/TOF/prototyping/findLabels.C | 55 ++- .../TOF/prototyping/findTOFclusterFromLabel.C | 93 ++--- .../TOF/reconstruction/src/Clusterer.cxx | 10 +- .../include/TOFSimulation/Digitizer.h | 8 +- Detectors/TOF/simulation/src/Digitizer.cxx | 91 ++--- Detectors/TOF/simulation/src/Strip.cxx | 2 +- Generators/src/GeneratorFactory.cxx | 16 +- .../src/TOFClusterizerSpec.cxx | 10 +- .../src/TOFDigitWriterSpec.cxx | 4 +- .../src/TOFDigitizerSpec.cxx | 6 +- macro/checkTOFMatching.C | 173 +++++---- macro/run_match_tof.C | 10 +- 22 files changed, 475 insertions(+), 479 deletions(-) diff --git a/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h b/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h index a03ed31b39726..38d8a8d57ae46 100644 --- a/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h +++ b/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h @@ -19,8 +19,6 @@ #include #include - - namespace o2 { namespace tof @@ -50,10 +48,10 @@ class Cluster : public o2::BaseCluster void SetBaseData(std::int16_t sensid, float x, float y, float z, float sy2, float sz2, float syz); - double getTimeRaw() const { return mTimeRaw; } // Cluster ToF getter - void setTimeRaw(double timeRaw) { mTimeRaw = timeRaw; } // Cluster ToF setter - double getTime() const { return mTime; } // Cluster ToF getter - void setTime(double time) { mTime = time; } // Cluster ToF setter + double getTimeRaw() const { return mTimeRaw; } // Cluster ToF getter + void setTimeRaw(double timeRaw) { mTimeRaw = timeRaw; } // Cluster ToF setter + double getTime() const { return mTime; } // Cluster ToF getter + void setTime(double time) { mTime = time; } // Cluster ToF setter float getTot() const { return mTot; } // Cluster Charge getter void setTot(int tot) { mTot = tot; } // Cluster ToT setter int getL0L1Latency() const { return mL0L1Latency; }; // L0L1 latency @@ -61,9 +59,9 @@ class Cluster : public o2::BaseCluster int getDeltaBC() const { return mDeltaBC; }; // deltaBC void setDeltaBC(int value) { mDeltaBC = value; }; // deltaBC //float getZ() const {return mZ;} // Cluster Z - already in the definition of the cluster - float getR() const { return TMath::Sqrt(getX()*getX() + getY()*getY() + getZ()*getZ()); } // Cluster Radius - float getPhi() const { return TMath::ATan2(getY(), getX()); } // Cluster Phi - int getSector() const { return int((TMath::ATan2(-getY(), -getX())+TMath::Pi())*TMath::RadToDeg()*0.05);} // Cluster Sector + float getR() const { return TMath::Sqrt(getX() * getX() + getY() * getY() + getZ() * getZ()); } // Cluster Radius + float getPhi() const { return TMath::ATan2(getY(), getX()); } // Cluster Phi + int getSector() const { return int((TMath::ATan2(-getY(), -getX()) + TMath::Pi()) * TMath::RadToDeg() * 0.05); } // Cluster Sector int getContributingChannels() const { return mContributingChannels; } void setContributingChannels(int contributingChannels) { mContributingChannels = contributingChannels; } @@ -111,8 +109,8 @@ class Cluster : public o2::BaseCluster private: friend class boost::serialization::access; - double mTimeRaw; // raw TOF time // CZ: in AliRoot it is a double - double mTime; // calibrated TOF time // CZ: in AliRoot it is a double + double mTimeRaw; // raw TOF time // CZ: in AliRoot it is a double + double mTime; // calibrated TOF time // CZ: in AliRoot it is a double float mTot; // Time-Over-threshold // CZ: in AliRoot it is a double int mL0L1Latency; // L0L1 latency // CZ: is it different per cluster? Checking one ESD file, it seems that it is always the same (see: /alice/data/2017/LHC17n/000280235/pass1/17000280235019.100/AliESDs.root) int mDeltaBC; // DeltaBC --> can it be a char or short? // CZ: is it different per cluster? Checking one ESD file, it seems that it can vary (see: /alice/data/2017/LHC17n/000280235/pass1/17000280235019.100/AliESDs.root) diff --git a/DataFormats/Detectors/TOF/src/Cluster.cxx b/DataFormats/Detectors/TOF/src/Cluster.cxx index cfc625ecf0217..5b58d527d2cf8 100644 --- a/DataFormats/Detectors/TOF/src/Cluster.cxx +++ b/DataFormats/Detectors/TOF/src/Cluster.cxx @@ -30,10 +30,11 @@ Cluster::Cluster(std::int16_t sensid, float x, float y, float z, float sy2, floa mPhi = TMath::ATan2(y, x); } //______________________________________________________________________ -void Cluster::SetBaseData(std::int16_t sensid, float x, float y, float z, float sy2, float sz2, float syz){ +void Cluster::SetBaseData(std::int16_t sensid, float x, float y, float z, float sy2, float sz2, float syz) +{ setSensorID(sensid); - setXYZ(x,y,z); - setErrors(sy2,sz2,syz); + setXYZ(x, y, z); + setErrors(sy2, sz2, syz); // caching R and phi mR = TMath::Sqrt(x * x + y * y); diff --git a/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h b/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h index 754d429347e2f..73d8f9a6bf187 100644 --- a/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h +++ b/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h @@ -18,10 +18,9 @@ namespace o2 { namespace dataformats { - class MatchInfoTOF +class MatchInfoTOF { public: - MatchInfoTOF(int indexTOFCl, float chi2) : mTOFClIndex(indexTOFCl), mChi2(chi2){}; MatchInfoTOF() = default; void setTOFClIndex(int index) { mTOFClIndex = index; } @@ -31,10 +30,8 @@ namespace dataformats float getChi2() const { return mChi2; } private: - int mTOFClIndex; // index of the TOF cluster used for the matching float mChi2; // chi2 of the pair track-TOFcluster - // ClassDefNV(MatchInfoTOF, 1); }; diff --git a/DataFormats/simulation/src/SimulationDataLinkDef.h b/DataFormats/simulation/src/SimulationDataLinkDef.h index 50695e47cf3a4..8820d35a5f030 100644 --- a/DataFormats/simulation/src/SimulationDataLinkDef.h +++ b/DataFormats/simulation/src/SimulationDataLinkDef.h @@ -37,7 +37,7 @@ #pragma link C++ struct o2::dataformats::MCTruthHeaderElement + ; #pragma link C++ class o2::dataformats::MCTruthContainer < long > +; #pragma link C++ class o2::dataformats::MCTruthContainer < o2::MCCompLabel > +; -#pragma link C++ class std::vector> +; +#pragma link C++ class std::vector < o2::dataformats::MCTruthContainer < o2::MCCompLabel >> +; #pragma link C++ class std::vector < o2::MCCompLabel > +; #pragma link C++ class std::vector < o2::dataformats::MCTruthHeaderElement > +; diff --git a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h index 728ac6ed861ad..6d94f2e455f7e 100644 --- a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h +++ b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h @@ -61,7 +61,7 @@ class MatchTOF { using Geo = o2::tof::Geo; using Cluster = o2::tof::Cluster; - + public: ///< perform matching for provided input void run(); @@ -95,10 +95,10 @@ class MatchTOF ///< get input branch names for the input from the tree const std::string& getTracksBranchName() const { return mTracksBranchName; } - const std::string& getTPCTracksBranchName() const { return mTPCTracksBranchName;} - const std::string& getTPCMCTruthBranchName() const { return mTPCMCTruthBranchName;} - const std::string& getITSMCTruthBranchName() const { return mITSMCTruthBranchName;} - const std::string& getTOFMCTruthBranchName() const { return mTOFMCTruthBranchName;} + const std::string& getTPCTracksBranchName() const { return mTPCTracksBranchName; } + const std::string& getTPCMCTruthBranchName() const { return mTPCMCTruthBranchName; } + const std::string& getITSMCTruthBranchName() const { return mITSMCTruthBranchName; } + const std::string& getTOFMCTruthBranchName() const { return mTOFMCTruthBranchName; } const std::string& getTOFClusterBranchName() const { return mTOFClusterBranchName; } const std::string& getOutTOFMCTruthBranchName() const { return mOutTOFMCTruthBranchName; } const std::string& getOutTPCMCTruthBranchName() const { return mOutTPCMCTruthBranchName; } @@ -125,7 +125,7 @@ class MatchTOF #ifdef _ALLOW_DEBUG_TREES_ enum DebugFlagTypes : UInt_t { - MatchTreeAll = 0x1 << 1, ///< produce matching candidates tree for all candidates + MatchTreeAll = 0x1 << 1, ///< produce matching candidates tree for all candidates }; ///< check if partucular flags are set bool isDebugFlag(UInt_t flags) const { return mDBGFlags & flags; } @@ -161,7 +161,7 @@ class MatchTOF void loadTracksChunk(int chunk); bool loadTOFClustersNextChunk(); void loadTOFClustersChunk(int chunk); - + void doMatching(int sec); void selectBestMatches(); bool propagateToRefX(o2::track::TrackParCov& trc, float xRef /*in cm*/, float stepInCm /*in cm*/); @@ -172,8 +172,8 @@ class MatchTOF bool mInitDone = false; ///< flag init already done - float mXRef = Geo::RMIN; ///< reference radius to propage tracks for matching - + float mXRef = Geo::RMIN; ///< reference radius to propage tracks for matching + int mCurrTracksTreeEntry = -1; ///< current tracks tree entry loaded to memory int mCurrTOFClustersTreeEntry = -1; ///< current TOF clusters tree entry loaded to memory @@ -185,8 +185,8 @@ class MatchTOF float mTimeTolerance = 1e3; ///>>------ these are input arrays which should not be modified by the matching code // since this info is provided by external device std::vector* mTracksArrayInp = nullptr; ///< input tracks - std::vector* mTPCTracksArrayInp = nullptr; ///< input TPC tracks - std::vector* mTOFClustersArrayInp = nullptr; ///< input TOF clusters + std::vector* mTPCTracksArrayInp = nullptr; ///< input TPC tracks + std::vector* mTOFClustersArrayInp = nullptr; ///< input TOF clusters o2::dataformats::MCTruthContainer* mTOFClusLabels = nullptr; ///< input TOF clusters MC labels - std::vector mTracksLblWork; /// mTracksLblWork; ///* mTPCLabels = nullptr; ///< TPC label of input tracks std::vector* mITSLabels = nullptr; ///< ITS label of input tracks - /// <<<----- /// mTracksWork; /// mTOFClusWork; /// mTracksWork; /// mTOFClusWork; ///, o2::constants::math::NSectors> mTracksSectIndexCache; ///< per sector indices of TOF cluster entry in mTOFClusWork std::array, o2::constants::math::NSectors> mTOFClusSectIndexCache; - - ///> mMatchedTracksPairs; /// mMatchedTracks; std::vector> mMatchedTracks; // this is the output of the matching - std::vector mOutTOFLabels; ///< TOF label of matched tracks - std::vector mOutTPCLabels; ///< TPC label of matched tracks - std::vector mOutITSLabels; ///< ITS label of matched tracks - - int mNumOfTracks; // number of tracks to be matched - int* mMatchedTracksIndex = nullptr; //[mNumOfTracks] - int mNumOfClusters; // number of clusters to be matched - int* mMatchedClustersIndex = nullptr; //[mNumOfClusters] - - std::string mTracksBranchName = "TPCITS"; ///< name of branch containing input matched tracks - std::string mTPCTracksBranchName = "Tracks"; ///< name of branch containing actual TPC tracks - std::string mTPCMCTruthBranchName = "MatchTPCMCTruth"; ///< name of branch containing TPC labels - std::string mITSMCTruthBranchName = "MatchITSMCTruth"; ///< name of branch containing ITS labels - std::string mTOFMCTruthBranchName = "TOFClusterMCTruth"; ///< name of branch containing TOF clusters labels - std::string mTOFClusterBranchName = "TOFCluster"; ///< name of branch containing input ITS clusters - std::string mOutTracksBranchName = "TOFMatchInfo"; ///< name of branch containing output matched tracks - std::string mOutTOFMCTruthBranchName = "MatchTOFMCTruth"; ///< name of branch containing TOF labels for output matched tracks - std::string mOutTPCMCTruthBranchName = "MatchTPCMCTruth"; ///< name of branch containing TOF labels for output matched tracks - std::string mOutITSMCTruthBranchName = "MatchITSMCTruth"; ///< name of branch containing TOF labels for output matched tracks + std::vector mOutTOFLabels; ///< TOF label of matched tracks + std::vector mOutTPCLabels; ///< TPC label of matched tracks + std::vector mOutITSLabels; ///< ITS label of matched tracks + + int mNumOfTracks; // number of tracks to be matched + int* mMatchedTracksIndex = nullptr; //[mNumOfTracks] + int mNumOfClusters; // number of clusters to be matched + int* mMatchedClustersIndex = nullptr; //[mNumOfClusters] + + std::string mTracksBranchName = "TPCITS"; ///< name of branch containing input matched tracks + std::string mTPCTracksBranchName = "Tracks"; ///< name of branch containing actual TPC tracks + std::string mTPCMCTruthBranchName = "MatchTPCMCTruth"; ///< name of branch containing TPC labels + std::string mITSMCTruthBranchName = "MatchITSMCTruth"; ///< name of branch containing ITS labels + std::string mTOFMCTruthBranchName = "TOFClusterMCTruth"; ///< name of branch containing TOF clusters labels + std::string mTOFClusterBranchName = "TOFCluster"; ///< name of branch containing input ITS clusters + std::string mOutTracksBranchName = "TOFMatchInfo"; ///< name of branch containing output matched tracks + std::string mOutTOFMCTruthBranchName = "MatchTOFMCTruth"; ///< name of branch containing TOF labels for output matched tracks + std::string mOutTPCMCTruthBranchName = "MatchTPCMCTruth"; ///< name of branch containing TOF labels for output matched tracks + std::string mOutITSMCTruthBranchName = "MatchITSMCTruth"; ///< name of branch containing TOF labels for output matched tracks #ifdef _ALLOW_DEBUG_TREES_ std::unique_ptr mDBGOut; @@ -252,8 +249,8 @@ class MatchTOF #endif ///----------- aux stuff --------------/// - static constexpr float MAXSNP = 0.85; // max snp of ITS or TPC track at xRef to be matched - + static constexpr float MAXSNP = 0.85; // max snp of ITS or TPC track at xRef to be matched + TStopwatch mTimerTot; TStopwatch mTimerDBG; ClassDefNV(MatchTOF, 1); diff --git a/Detectors/GlobalTracking/src/GlobalTrackingLinkDef.h b/Detectors/GlobalTracking/src/GlobalTrackingLinkDef.h index dfba2f222a16d..e1404038712dd 100644 --- a/Detectors/GlobalTracking/src/GlobalTrackingLinkDef.h +++ b/Detectors/GlobalTracking/src/GlobalTrackingLinkDef.h @@ -19,11 +19,11 @@ #pragma link C++ class o2::globaltracking::timeBracket + ; #pragma link C++ class o2::globaltracking::TrackLocTPC + ; #pragma link C++ class o2::globaltracking::TrackLocITS + ; -#pragma link C++ class std::pair + ; -#pragma link C++ class std::vector> + ; -#pragma link C++ class std::vector + ; -#pragma link C++ class std::vector + ; -#pragma link C++ class std::vector + ; -#pragma link C++ class std::vector + ; +#pragma link C++ class std::pair < int, o2::dataformats::MatchInfoTOF > +; +#pragma link C++ class std::vector < std::pair < int, o2::dataformats::MatchInfoTOF >> +; +#pragma link C++ class std::vector < o2::dataformats::TrackTPCITS > +; +#pragma link C++ class std::vector < o2::TPC::TrackTPC > +; +#pragma link C++ class std::vector < o2::ITS::TrackITS > +; +#pragma link C++ class std::vector < o2::tof::Cluster > +; #endif diff --git a/Detectors/GlobalTracking/src/MatchTOF.cxx b/Detectors/GlobalTracking/src/MatchTOF.cxx index 716753717b9f8..1b3b16948c9a5 100644 --- a/Detectors/GlobalTracking/src/MatchTOF.cxx +++ b/Detectors/GlobalTracking/src/MatchTOF.cxx @@ -54,7 +54,7 @@ void MatchTOF::run() prepareTOFClusters(); // we do the matching per entry of the TPCITS matched tracks tree - while (mCurrTracksTreeEntry+1 < mInputTreeTracks->GetEntries()) { // we add "+1" because mCurrTracksTreeEntry starts from -1, and it is incremented in loadTracksNextChunk which is called by prepareTracks + while (mCurrTracksTreeEntry + 1 < mInputTreeTracks->GetEntries()) { // we add "+1" because mCurrTracksTreeEntry starts from -1, and it is incremented in loadTracksNextChunk which is called by prepareTracks LOG(DEBUG) << "Number of entries in track tree = " << mCurrTracksTreeEntry; mMatchedTracks.clear(); mOutTOFLabels.clear(); @@ -81,7 +81,7 @@ void MatchTOF::run() } } */ - + for (int sec = o2::constants::math::NSectors; sec--;) { LOG(INFO) << "Doing matching for sector " << sec << "..."; doMatching(sec); @@ -95,7 +95,7 @@ void MatchTOF::run() } mOutputTree->Fill(); } - + #ifdef _ALLOW_DEBUG_TREES_ mDBGOut.reset(); #endif @@ -142,7 +142,7 @@ void MatchTOF::init() mDBGOut = std::make_unique(mDebugTreeFileName.data(), "recreate"); } #endif - + mInitDone = true; { @@ -207,8 +207,7 @@ void MatchTOF::attachInputTrees() // input TOF clusters if (!mTreeTOFClusters->GetBranch(mTOFClusterBranchName.data())) { - LOG(FATAL) << "Did not find TOF clusters branch " << mTOFClusterBranchName << " in the input tree" - ; + LOG(FATAL) << "Did not find TOF clusters branch " << mTOFClusterBranchName << " in the input tree"; } mTreeTOFClusters->SetBranchAddress(mTOFClusterBranchName.data(), &mTOFClustersArrayInp); LOG(INFO) << "Attached TOF clusters " << mTOFClusterBranchName << " branch with " << mTreeTOFClusters->GetEntries() @@ -227,7 +226,7 @@ void MatchTOF::attachInputTrees() mInputTreeTracks->SetBranchAddress(mITSMCTruthBranchName.data(), &mITSLabels); LOG(INFO) << "Found ITS tracks MCLabels branch " << mITSMCTruthBranchName.data(); } - + mMCTruthON = (mTOFClusLabels && mTPCLabels && mITSLabels); mCurrTracksTreeEntry = -1; mCurrTOFClustersTreeEntry = -1; @@ -238,17 +237,18 @@ bool MatchTOF::prepareTracks() { ///< prepare the tracks that we want to match to TOF - if (!loadTracksNextChunk()) - { + if (!loadTracksNextChunk()) { return false; } mNumOfTracks = mTracksArrayInp->size(); - if (mNumOfTracks == 0) return false; // no tracks to be matched - if (mMatchedTracksIndex) delete[] mMatchedTracksIndex; + if (mNumOfTracks == 0) + return false; // no tracks to be matched + if (mMatchedTracksIndex) + delete[] mMatchedTracksIndex; mMatchedTracksIndex = new int[mNumOfTracks]; std::fill_n(mMatchedTracksIndex, mNumOfTracks, -1); // initializing all to -1 - + // copy the track params, propagate to reference X and build sector tables mTracksWork.clear(); mTracksWork.reserve(mNumOfTracks); @@ -268,7 +268,7 @@ bool MatchTOF::prepareTracks() std::array globalPos; // create working copy of track param - mTracksWork.emplace_back(trcOrig);//, mCurrTracksTreeEntry, it); + mTracksWork.emplace_back(trcOrig); //, mCurrTracksTreeEntry, it); // make a copy of the TPC track that we have to propagate //o2::TPC::TrackTPC* trc = new o2::TPC::TrackTPC(trcTPCOrig); // this would take the TPCout track auto& trc = mTracksWork.back(); // with this we take the TPCITS track propagated to the vertex @@ -276,18 +276,18 @@ bool MatchTOF::prepareTracks() // propagate to matching Xref trc.getXYZGlo(globalPos); LOG(DEBUG) << "Global coordinates Before propagating to 371 cm: globalPos[0] = " << globalPos[0] << ", globalPos[1] = " << globalPos[1] << ", globalPos[2] = " << globalPos[2]; - LOG(DEBUG) << "Radius xy Before propagating to 371 cm = " << TMath::Sqrt(globalPos[0]*globalPos[0] + globalPos[1]*globalPos[1]); - LOG(DEBUG) << "Radius xyz Before propagating to 371 cm = " << TMath::Sqrt(globalPos[0]*globalPos[0] + globalPos[1]*globalPos[1] + globalPos[2]*globalPos[2]); + LOG(DEBUG) << "Radius xy Before propagating to 371 cm = " << TMath::Sqrt(globalPos[0] * globalPos[0] + globalPos[1] * globalPos[1]); + LOG(DEBUG) << "Radius xyz Before propagating to 371 cm = " << TMath::Sqrt(globalPos[0] * globalPos[0] + globalPos[1] * globalPos[1] + globalPos[2] * globalPos[2]); if (!propagateToRefX(trc, mXRef, 2) || TMath::Abs(trc.getZ()) > Geo::MAXHZTOF) { nNotPropagatedToTOF++; continue; } trc.getXYZGlo(globalPos); - + LOG(DEBUG) << "Global coordinates After propagating to 371 cm: globalPos[0] = " << globalPos[0] << ", globalPos[1] = " << globalPos[1] << ", globalPos[2] = " << globalPos[2]; - LOG(DEBUG) << "Radius xy After propagating to 371 cm = " << TMath::Sqrt(globalPos[0]*globalPos[0] + globalPos[1]*globalPos[1]); - LOG(DEBUG) << "Radius xyz After propagating to 371 cm = " << TMath::Sqrt(globalPos[0]*globalPos[0] + globalPos[1]*globalPos[1] + globalPos[2]*globalPos[2]); + LOG(DEBUG) << "Radius xy After propagating to 371 cm = " << TMath::Sqrt(globalPos[0] * globalPos[0] + globalPos[1] * globalPos[1]); + LOG(DEBUG) << "Radius xyz After propagating to 371 cm = " << TMath::Sqrt(globalPos[0] * globalPos[0] + globalPos[1] * globalPos[1] + globalPos[2] * globalPos[2]); LOG(DEBUG) << "The track will go to sector " << o2::utils::Angle2Sector(TMath::ATan2(globalPos[1], globalPos[0])); mTracksSectIndexCache[o2::utils::Angle2Sector(TMath::ATan2(globalPos[1], globalPos[0]))].push_back(it); @@ -295,18 +295,18 @@ bool MatchTOF::prepareTracks() } LOG(INFO) << "Total number of tracks = " << mNumOfTracks << ", Number of tracks that failed to be propagated to TOF = " << nNotPropagatedToTOF; - - // sort tracks in each sector according to their time (increasing in time) + + // sort tracks in each sector according to their time (increasing in time) for (int sec = o2::constants::math::NSectors; sec--;) { auto& indexCache = mTracksSectIndexCache[sec]; LOG(INFO) << "Sorting sector" << sec << " | " << indexCache.size() << " tracks"; if (!indexCache.size()) continue; std::sort(indexCache.begin(), indexCache.end(), [this](int a, int b) { - auto& trcA = mTracksWork[a]; - auto& trcB = mTracksWork[b]; - return ((trcA.getTimeMUS().getTimeStamp() - mSigmaTimeCut*trcA.getTimeMUS().getTimeStampError()) - (trcB.getTimeMUS().getTimeStamp() - mSigmaTimeCut*trcB.getTimeMUS().getTimeStampError()) < 0.); - }); + auto& trcA = mTracksWork[a]; + auto& trcB = mTracksWork[b]; + return ((trcA.getTimeMUS().getTimeStamp() - mSigmaTimeCut * trcA.getTimeMUS().getTimeStampError()) - (trcB.getTimeMUS().getTimeStamp() - mSigmaTimeCut * trcB.getTimeMUS().getTimeStampError()) < 0.); + }); } // loop over tracks of single sector // Uncomment for local debug @@ -327,7 +327,7 @@ bool MatchTOF::prepareTracks() } Printf("we have %d tracks",itmp); */ - + return true; } //______________________________________________ @@ -343,28 +343,25 @@ bool MatchTOF::prepareTOFClusters() // mTOFClusLblWork.reserve(mNumOfClusters); // } - for (int sec = o2::constants::math::NSectors; sec--;) { mTOFClusSectIndexCache[sec].clear(); //mTOFClusSectIndexCache[sec].reserve(100 + 1.2 * mNumOfClusters / o2::constants::math::NSectors); // we cannot do this, we don't have mNumOfClusters yet } - - mNumOfClusters = 0; - while (loadTOFClustersNextChunk()) - { + + mNumOfClusters = 0; + while (loadTOFClustersNextChunk()) { int nClusterInCurrentChunk = mTOFClustersArrayInp->size(); LOG(DEBUG) << "nClusterInCurrentChunk = " << nClusterInCurrentChunk; mNumOfClusters += nClusterInCurrentChunk; for (int it = 0; it < nClusterInCurrentChunk; it++) { Cluster& clOrig = (*mTOFClustersArrayInp)[it]; - + // create working copy of track param mTOFClusWork.emplace_back(clOrig); auto& cl = mTOFClusWork.back(); // cache work track index mTOFClusSectIndexCache[o2::utils::Angle2Sector(cl.getPhi())].push_back(mTOFClusWork.size() - 1); } - } // sort clusters in each sector according to their time (increasing in time) @@ -374,13 +371,14 @@ bool MatchTOF::prepareTOFClusters() if (!indexCache.size()) continue; std::sort(indexCache.begin(), indexCache.end(), [this](int a, int b) { - auto& clA = mTOFClusWork[a]; - auto& clB = mTOFClusWork[b]; - return (clA.getTime() - clB.getTime()) < 0.; - }); + auto& clA = mTOFClusWork[a]; + auto& clB = mTOFClusWork[b]; + return (clA.getTime() - clB.getTime()) < 0.; + }); } // loop over TOF clusters of single sector - if (mMatchedClustersIndex) delete[] mMatchedClustersIndex; + if (mMatchedClustersIndex) + delete[] mMatchedClustersIndex; mMatchedClustersIndex = new int[mNumOfClusters]; std::fill_n(mMatchedClustersIndex, mNumOfClusters, -1); // initializing all to -1 @@ -394,7 +392,7 @@ bool MatchTOF::loadTracksNextChunk() while (++mCurrTracksTreeEntry < mInputTreeTracks->GetEntries()) { mInputTreeTracks->GetEntry(mCurrTracksTreeEntry); LOG(INFO) << "Loading tracks entry " << mCurrTracksTreeEntry << " -> " << mTracksArrayInp->size() - << " tracks"; + << " tracks"; if (!mTracksArrayInp->size()) { continue; } @@ -424,7 +422,7 @@ bool MatchTOF::loadTOFClustersNextChunk() LOG(DEBUG) << "Loading TOF clusters entry " << mCurrTOFClustersTreeEntry << " -> " << mTOFClustersArrayInp->size() << " clusters"; LOG(INFO) << "Loading TOF clusters entry " << mCurrTOFClustersTreeEntry << " -> " << mTOFClustersArrayInp->size() - << " clusters"; + << " clusters"; if (!mTOFClustersArrayInp->size()) { continue; } @@ -449,7 +447,7 @@ void MatchTOF::doMatching(int sec) ///< do the real matching per sector mMatchedTracksPairs.clear(); // new sector - + //uncomment for local debug /* // printing the tracks @@ -463,36 +461,36 @@ void MatchTOF::doMatching(int sec) Printf("The phi angle is %f", TMath::ATan2(globalPosTmp[1], globalPosTmp[0])); } */ - auto& cacheTOF = mTOFClusSectIndexCache[sec]; // array of cached TOF cluster indices for this sector; reminder: they are ordered in time! - auto& cacheTrk = mTracksSectIndexCache[sec]; // array of cached tracks indices for this sector; reminder: they are ordered in time! + auto& cacheTOF = mTOFClusSectIndexCache[sec]; // array of cached TOF cluster indices for this sector; reminder: they are ordered in time! + auto& cacheTrk = mTracksSectIndexCache[sec]; // array of cached tracks indices for this sector; reminder: they are ordered in time! int nTracks = cacheTrk.size(), nTOFCls = cacheTOF.size(); LOG(INFO) << "Matching sector " << sec << ": number of tracks: " << nTracks << ", number of TOF clusters: " << nTOFCls; if (!nTracks || !nTOFCls) { return; } - int itof0 = 0; // starting index in TOF clusters for matching of the track - int detId[2][5]; // at maximum one track can fall in 2 strips during the propagation; the second dimention of the array is the TOF det index - float deltaPos[2][3]; // at maximum one track can fall in 2 strips during the propagation; the second dimention of the array is the residuals - int nStepsInsideSameStrip[2] = {0,0}; // number of propagation steps in the same strip (since we have maximum 2 strips, it has dimention = 2) + int itof0 = 0; // starting index in TOF clusters for matching of the track + int detId[2][5]; // at maximum one track can fall in 2 strips during the propagation; the second dimention of the array is the TOF det index + float deltaPos[2][3]; // at maximum one track can fall in 2 strips during the propagation; the second dimention of the array is the residuals + int nStepsInsideSameStrip[2] = { 0, 0 }; // number of propagation steps in the same strip (since we have maximum 2 strips, it has dimention = 2) float deltaPosTemp[3]; std::array pos; std::array posBeforeProp; - float posFloat[3]; + float posFloat[3]; LOG(DEBUG) << "Trying to match %d tracks" << cacheTrk.size(); for (int itrk = 0; itrk < cacheTrk.size(); itrk++) { for (int ii = 0; ii < 2; ii++) { - detId[ii][2] = -1; // before trying to match, we need to inizialize the detId corresponding to the strip number to -1; this is the array that we will use to save the det id of the maximum 2 strips matched + detId[ii][2] = -1; // before trying to match, we need to inizialize the detId corresponding to the strip number to -1; this is the array that we will use to save the det id of the maximum 2 strips matched nStepsInsideSameStrip[ii] = 0; } int nStripsCrossedInPropagation = 0; // how many strips were hit during the propagation auto& trefTrk = mTracksWork[cacheTrk[itrk]]; - float minTrkTime = (trefTrk.getTimeMUS().getTimeStamp() - mSigmaTimeCut*trefTrk.getTimeMUS().getTimeStampError())*1.E6; // minimum time in ps - float maxTrkTime = (trefTrk.getTimeMUS().getTimeStamp() + mSigmaTimeCut*trefTrk.getTimeMUS().getTimeStampError())*1.E6; // maximum time in ps - int istep = 1; // number of steps - float step = 0.1; // step size in cm - //uncomment for local debug - /* + float minTrkTime = (trefTrk.getTimeMUS().getTimeStamp() - mSigmaTimeCut * trefTrk.getTimeMUS().getTimeStampError()) * 1.E6; // minimum time in ps + float maxTrkTime = (trefTrk.getTimeMUS().getTimeStamp() + mSigmaTimeCut * trefTrk.getTimeMUS().getTimeStampError()) * 1.E6; // maximum time in ps + int istep = 1; // number of steps + float step = 0.1; // step size in cm + //uncomment for local debug + /* //trefTrk.getXYZGlo(posBeforeProp); //float posBeforeProp[3] = {trefTrk.getX(), trefTrk.getY(), trefTrk.getZ()}; // in local ref system //printf("Global coordinates: posBeforeProp[0] = %f, posBeforeProp[1] = %f, posBeforeProp[2] = %f\n", posBeforeProp[0], posBeforeProp[1], posBeforeProp[2]); @@ -502,23 +500,23 @@ void MatchTOF::doMatching(int sec) #ifdef _ALLOW_DEBUG_TREES_ (*mDBGOut) << "propOK" - << "track=" << trefTrk << "\n"; + << "track=" << trefTrk << "\n"; #endif // initializing - for (int ii = 0; ii < 2; ii++){ - for (int iii = 0; iii < 5; iii++){ - detId[ii][iii] = -1; + for (int ii = 0; ii < 2; ii++) { + for (int iii = 0; iii < 5; iii++) { + detId[ii][iii] = -1; } } - int detIdTemp[5] = {-1, -1, -1, -1, -1}; // TOF detector id at the current propagation point - while (propagateToRefX(trefTrk, mXRef+istep*step, step) && nStripsCrossedInPropagation <=2 && mXRef+istep*step < Geo::RMAX){ - if (0 && istep%100 == 0){ - printf("istep = %d, currentPosition = %f \n", istep, mXRef+istep*step); + int detIdTemp[5] = { -1, -1, -1, -1, -1 }; // TOF detector id at the current propagation point + while (propagateToRefX(trefTrk, mXRef + istep * step, step) && nStripsCrossedInPropagation <= 2 && mXRef + istep * step < Geo::RMAX) { + if (0 && istep % 100 == 0) { + printf("istep = %d, currentPosition = %f \n", istep, mXRef + istep * step); } trefTrk.getXYZGlo(pos); - for (int ii = 0; ii < 3; ii++){ // we need to change the type... - posFloat[ii] = pos[ii]; + for (int ii = 0; ii < 3; ii++) { // we need to change the type... + posFloat[ii] = pos[ii]; } // uncomment below only for local debug; this will produce A LOT of output - one print per propagation step /* @@ -526,55 +524,55 @@ void MatchTOF::doMatching(int sec) Printf("radius xy = %f", TMath::Sqrt(posFloat[0]*posFloat[0] + posFloat[1]*posFloat[1])); Printf("radius xyz = %f", TMath::Sqrt(posFloat[0]*posFloat[0] + posFloat[1]*posFloat[1] + posFloat[2]*posFloat[2])); */ - for (int idet = 0; idet < 5; idet++) detIdTemp[idet] = -1; + for (int idet = 0; idet < 5; idet++) + detIdTemp[idet] = -1; Geo::getPadDxDyDz(posFloat, detIdTemp, deltaPosTemp); - + // uncomment below only for local debug; this will produce A LOT of output - one print per propagation step //Printf("detIdTemp[0] = %d, detIdTemp[1] = %d, detIdTemp[2] = %d, detIdTemp[3] = %d, detIdTemp[4] = %d", detIdTemp[0], detIdTemp[1], detIdTemp[2], detIdTemp[3], detIdTemp[4]); - if (detIdTemp[2] != -1 && nStripsCrossedInPropagation == 0){ // print in case you have a useful propagation - LOG(DEBUG) << "*********** We have crossed a strip during propagation!*********"; - LOG(DEBUG) << "Global coordinates: pos[0] = " << pos[0] << ", pos[1] = " << pos[1] << ", pos[2] = " << pos[2]; - LOG(DEBUG) << "detIdTemp[0] = " << detIdTemp[0] << ", detIdTemp[1] = " << detIdTemp[1] << ", detIdTemp[2] = " << detIdTemp[2] << ", detIdTemp[3] = " << detIdTemp[3] << ", detIdTemp[4] = " << detIdTemp[4]; - LOG(DEBUG) << "deltaPosTemp[0] = " << deltaPosTemp[0] << ", deltaPosTemp[1] = " << deltaPosTemp[1] << " deltaPosTemp[2] = " << deltaPosTemp[2]; + if (detIdTemp[2] != -1 && nStripsCrossedInPropagation == 0) { // print in case you have a useful propagation + LOG(DEBUG) << "*********** We have crossed a strip during propagation!*********"; + LOG(DEBUG) << "Global coordinates: pos[0] = " << pos[0] << ", pos[1] = " << pos[1] << ", pos[2] = " << pos[2]; + LOG(DEBUG) << "detIdTemp[0] = " << detIdTemp[0] << ", detIdTemp[1] = " << detIdTemp[1] << ", detIdTemp[2] = " << detIdTemp[2] << ", detIdTemp[3] = " << detIdTemp[3] << ", detIdTemp[4] = " << detIdTemp[4]; + LOG(DEBUG) << "deltaPosTemp[0] = " << deltaPosTemp[0] << ", deltaPosTemp[1] = " << deltaPosTemp[1] << " deltaPosTemp[2] = " << deltaPosTemp[2]; + } else { + LOG(DEBUG) << "*********** We have NOT crossed a strip during propagation!*********"; + LOG(DEBUG) << "Global coordinates: pos[0] = " << pos[0] << ", pos[1] = " << pos[1] << ", pos[2] = " << pos[2]; + LOG(DEBUG) << "detIdTemp[0] = " << detIdTemp[0] << ", detIdTemp[1] = " << detIdTemp[1] << ", detIdTemp[2] = " << detIdTemp[2] << ", detIdTemp[3] = " << detIdTemp[3] << ", detIdTemp[4] = " << detIdTemp[4]; + LOG(DEBUG) << "deltaPosTemp[0] = " << deltaPosTemp[0] << ", deltaPosTemp[1] = " << deltaPosTemp[1] << " deltaPosTemp[2] = " << deltaPosTemp[2]; } - else { - LOG(DEBUG) << "*********** We have NOT crossed a strip during propagation!*********"; - LOG(DEBUG) << "Global coordinates: pos[0] = " << pos[0] << ", pos[1] = " << pos[1] << ", pos[2] = " << pos[2]; - LOG(DEBUG) << "detIdTemp[0] = " << detIdTemp[0] << ", detIdTemp[1] = " << detIdTemp[1] << ", detIdTemp[2] = " << detIdTemp[2] << ", detIdTemp[3] = " << detIdTemp[3] << ", detIdTemp[4] = " << detIdTemp[4]; - LOG(DEBUG) << "deltaPosTemp[0] = " << deltaPosTemp[0] << ", deltaPosTemp[1] = " << deltaPosTemp[1] << " deltaPosTemp[2] = " << deltaPosTemp[2]; - } istep++; // check if after the propagation we are in a TOF strip if (detIdTemp[2] != -1) { // we ended in a TOF strip - LOG(DEBUG) << "nStripsCrossedInPropagation = " << nStripsCrossedInPropagation << ", detId[nStripsCrossedInPropagation-1][0] = " << detId[nStripsCrossedInPropagation-1][0] << ", detIdTemp[0] = " << detIdTemp[0] << ", detId[nStripsCrossedInPropagation-1][1] = " << detId[nStripsCrossedInPropagation-1][1] << ", detIdTemp[1] = " << detIdTemp[1] << ", detId[nStripsCrossedInPropagation-1][2] = " << detId[nStripsCrossedInPropagation-1][2] << ", detIdTemp[2] = " << detIdTemp[2]; - if(nStripsCrossedInPropagation == 0 || // we are crossing a strip for the first time... - (nStripsCrossedInPropagation >= 1 && (detId[nStripsCrossedInPropagation-1][0] != detIdTemp[0] || detId[nStripsCrossedInPropagation-1][1] != detIdTemp[1] || detId[nStripsCrossedInPropagation-1][2] != detIdTemp[2]))) { // ...or we are crossing a new strip - if (nStripsCrossedInPropagation == 0) LOG(DEBUG) << "We cross a strip for the first time"; - if(nStripsCrossedInPropagation == 2) { - break; // we have already matched 2 strips, we cannot match more - } - nStripsCrossedInPropagation++; - } - //Printf("nStepsInsideSameStrip[nStripsCrossedInPropagation-1] = %d", nStepsInsideSameStrip[nStripsCrossedInPropagation-1]); - if(nStepsInsideSameStrip[nStripsCrossedInPropagation-1] == 0){ - detId[nStripsCrossedInPropagation-1][0] = detIdTemp[0]; - detId[nStripsCrossedInPropagation-1][1] = detIdTemp[1]; - detId[nStripsCrossedInPropagation-1][2] = detIdTemp[2]; - detId[nStripsCrossedInPropagation-1][3] = detIdTemp[3]; - detId[nStripsCrossedInPropagation-1][4] = detIdTemp[4]; - deltaPos[nStripsCrossedInPropagation-1][0] = deltaPosTemp[0]; - deltaPos[nStripsCrossedInPropagation-1][1] = deltaPosTemp[1]; - deltaPos[nStripsCrossedInPropagation-1][2] = deltaPosTemp[2]; - nStepsInsideSameStrip[nStripsCrossedInPropagation-1]++; - } - else{ // a further propagation step in the same strip -> update info (we sum up on all matching with strip - we will divide for the number of steps a bit below) - deltaPos[nStripsCrossedInPropagation-1][0] += deltaPosTemp[0] + (detIdTemp[4] - detId[nStripsCrossedInPropagation-1][4])*Geo::XPAD; // residual in x - deltaPos[nStripsCrossedInPropagation-1][1] += deltaPosTemp[1]; // residual in y - deltaPos[nStripsCrossedInPropagation-1][2] += deltaPosTemp[2] + (detIdTemp[3] - detId[nStripsCrossedInPropagation-1][3])*Geo::ZPAD; // residual in z - nStepsInsideSameStrip[nStripsCrossedInPropagation-1]++; - } + LOG(DEBUG) << "nStripsCrossedInPropagation = " << nStripsCrossedInPropagation << ", detId[nStripsCrossedInPropagation-1][0] = " << detId[nStripsCrossedInPropagation - 1][0] << ", detIdTemp[0] = " << detIdTemp[0] << ", detId[nStripsCrossedInPropagation-1][1] = " << detId[nStripsCrossedInPropagation - 1][1] << ", detIdTemp[1] = " << detIdTemp[1] << ", detId[nStripsCrossedInPropagation-1][2] = " << detId[nStripsCrossedInPropagation - 1][2] << ", detIdTemp[2] = " << detIdTemp[2]; + if (nStripsCrossedInPropagation == 0 || // we are crossing a strip for the first time... + (nStripsCrossedInPropagation >= 1 && (detId[nStripsCrossedInPropagation - 1][0] != detIdTemp[0] || detId[nStripsCrossedInPropagation - 1][1] != detIdTemp[1] || detId[nStripsCrossedInPropagation - 1][2] != detIdTemp[2]))) { // ...or we are crossing a new strip + if (nStripsCrossedInPropagation == 0) + LOG(DEBUG) << "We cross a strip for the first time"; + if (nStripsCrossedInPropagation == 2) { + break; // we have already matched 2 strips, we cannot match more + } + nStripsCrossedInPropagation++; + } + //Printf("nStepsInsideSameStrip[nStripsCrossedInPropagation-1] = %d", nStepsInsideSameStrip[nStripsCrossedInPropagation-1]); + if (nStepsInsideSameStrip[nStripsCrossedInPropagation - 1] == 0) { + detId[nStripsCrossedInPropagation - 1][0] = detIdTemp[0]; + detId[nStripsCrossedInPropagation - 1][1] = detIdTemp[1]; + detId[nStripsCrossedInPropagation - 1][2] = detIdTemp[2]; + detId[nStripsCrossedInPropagation - 1][3] = detIdTemp[3]; + detId[nStripsCrossedInPropagation - 1][4] = detIdTemp[4]; + deltaPos[nStripsCrossedInPropagation - 1][0] = deltaPosTemp[0]; + deltaPos[nStripsCrossedInPropagation - 1][1] = deltaPosTemp[1]; + deltaPos[nStripsCrossedInPropagation - 1][2] = deltaPosTemp[2]; + nStepsInsideSameStrip[nStripsCrossedInPropagation - 1]++; + } else { // a further propagation step in the same strip -> update info (we sum up on all matching with strip - we will divide for the number of steps a bit below) + deltaPos[nStripsCrossedInPropagation - 1][0] += deltaPosTemp[0] + (detIdTemp[4] - detId[nStripsCrossedInPropagation - 1][4]) * Geo::XPAD; // residual in x + deltaPos[nStripsCrossedInPropagation - 1][1] += deltaPosTemp[1]; // residual in y + deltaPos[nStripsCrossedInPropagation - 1][2] += deltaPosTemp[2] + (detIdTemp[3] - detId[nStripsCrossedInPropagation - 1][3]) * Geo::ZPAD; // residual in z + nStepsInsideSameStrip[nStripsCrossedInPropagation - 1]++; + } } - } + } LOG(DEBUG) << "while done, we propagated track " << itrk << " in %d strips" << nStripsCrossedInPropagation; // uncomment for debug purposes, to check tracks that did not cross any strip @@ -588,21 +586,21 @@ void MatchTOF::doMatching(int sec) printf("deltaPosTemp[0] = %f, deltaPosTemp[1] = %f, deltaPosTemp[2] = %f\n", deltaPosTemp[0], deltaPosTemp[1], deltaPosTemp[2]); } */ - - for(Int_t imatch = 0; imatch < nStripsCrossedInPropagation; imatch++){ + + for (Int_t imatch = 0; imatch < nStripsCrossedInPropagation; imatch++) { // we take as residual the average of the residuals along the propagation in the same strip - deltaPos[imatch][0] /= nStepsInsideSameStrip[imatch]; + deltaPos[imatch][0] /= nStepsInsideSameStrip[imatch]; deltaPos[imatch][1] /= nStepsInsideSameStrip[imatch]; deltaPos[imatch][2] /= nStepsInsideSameStrip[imatch]; - LOG(DEBUG) << "matched strip " << imatch << ": deltaPos[0] = " << deltaPos[imatch][0] << ", deltaPos[1] = " << deltaPos[imatch][1] << ", deltaPos[2] = " << deltaPos[imatch][2] << ", residual (x, z) = " << TMath::Sqrt(deltaPos[imatch][0]*deltaPos[imatch][0] + deltaPos[imatch][2]*deltaPos[imatch][2]); + LOG(DEBUG) << "matched strip " << imatch << ": deltaPos[0] = " << deltaPos[imatch][0] << ", deltaPos[1] = " << deltaPos[imatch][1] << ", deltaPos[2] = " << deltaPos[imatch][2] << ", residual (x, z) = " << TMath::Sqrt(deltaPos[imatch][0] * deltaPos[imatch][0] + deltaPos[imatch][2] * deltaPos[imatch][2]); } - + if (nStripsCrossedInPropagation == 0) { continue; // the track never hit a TOF strip during the propagation } Printf("We will check now the %d TOF clusters", nTOFCls); bool foundCluster = false; - auto labelTPC = mTPCLabels->at(mTracksSectIndexCache[sec][itrk]); + auto labelTPC = mTPCLabels->at(mTracksSectIndexCache[sec][itrk]); for (auto itof = itof0; itof < nTOFCls; itof++) { // printf("itof = %d\n", itof); auto& trefTOF = mTOFClusWork[cacheTOF[itof]]; @@ -625,49 +623,53 @@ void MatchTOF::doMatching(int sec) int trackIdTOF; int eventIdTOF; int sourceIdTOF; - for (auto iPropagation = 0; iPropagation < nStripsCrossedInPropagation; iPropagation++){ - LOG(DEBUG) << "TOF Cluster [" << itof << ", " << cacheTOF[itof] << "]: indices = " << indices[0], indices[1], indices[2], indices[3], indices[4]; - LOG(DEBUG) << "Propagated Track [" << itrk << ", " << cacheTrk[itrk] << "]: detId[" << iPropagation << "] = " << detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4]; - float resX = deltaPos[iPropagation][0] - (indices[4] - detId[iPropagation][4])*Geo::XPAD; // readjusting the residuals due to the fact that the propagation fell in a pad that was not exactly the one of the cluster - float resZ = deltaPos[iPropagation][2] - (indices[3] - detId[iPropagation][3])*Geo::ZPAD; // readjusting the residuals due to the fact that the propagation fell in a pad that was not exactly the one of the cluster - float res = TMath::Sqrt(resX*resX + resZ*resZ); - LOG(DEBUG) << "resX = " << resX << ", resZ = " << resZ << ", res = " << res; + for (auto iPropagation = 0; iPropagation < nStripsCrossedInPropagation; iPropagation++) { + LOG(DEBUG) << "TOF Cluster [" << itof << ", " << cacheTOF[itof] << "]: indices = " << indices[0], indices[1], indices[2], indices[3], indices[4]; + LOG(DEBUG) << "Propagated Track [" << itrk << ", " << cacheTrk[itrk] << "]: detId[" << iPropagation << "] = " << detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4]; + float resX = deltaPos[iPropagation][0] - (indices[4] - detId[iPropagation][4]) * Geo::XPAD; // readjusting the residuals due to the fact that the propagation fell in a pad that was not exactly the one of the cluster + float resZ = deltaPos[iPropagation][2] - (indices[3] - detId[iPropagation][3]) * Geo::ZPAD; // readjusting the residuals due to the fact that the propagation fell in a pad that was not exactly the one of the cluster + float res = TMath::Sqrt(resX * resX + resZ * resZ); + LOG(DEBUG) << "resX = " << resX << ", resZ = " << resZ << ", res = " << res; #ifdef _ALLOW_DEBUG_TREES_ - fillTOFmatchTree("match0", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk); + fillTOFmatchTree("match0", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk); #endif - int tofLabelTrackID[3] = {-1, -1, -1}; - int tofLabelEventID[3] = {-1, -1, -1}; - int tofLabelSourceID[3] = {-1, -1, -1}; - for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++){ - tofLabelTrackID[ilabel] = labelsTOF[ilabel].getTrackID(); - tofLabelEventID[ilabel] = labelsTOF[ilabel].getEventID(); - tofLabelSourceID[ilabel] = labelsTOF[ilabel].getSourceID(); - } - //auto labelTPC = mTPCLabels->at(mTracksSectIndexCache[indices[0]][itrk]); - auto labelITS = mITSLabels->at(mTracksSectIndexCache[indices[0]][itrk]); - fillTOFmatchTreeWithLabels("matchPossibleWithLabels", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk, labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID(), labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID(), tofLabelTrackID[0], tofLabelEventID[0], tofLabelSourceID[0], tofLabelTrackID[1], tofLabelEventID[1], tofLabelSourceID[1], tofLabelTrackID[2], tofLabelEventID[2], tofLabelSourceID[2]); - if (indices[0] != detId[iPropagation][0]) continue; - if (indices[1] != detId[iPropagation][1]) continue; - if (indices[2] != detId[iPropagation][2]) continue; - float chi2 = res; // TODO: take into account also the time! - fillTOFmatchTree("match1", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk); - - fillTOFmatchTreeWithLabels("matchOkWithLabels", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk, labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID(), labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID(), tofLabelTrackID[0], tofLabelEventID[0], tofLabelSourceID[0], tofLabelTrackID[1], tofLabelEventID[1], tofLabelSourceID[1], tofLabelTrackID[2], tofLabelEventID[2], tofLabelSourceID[2]); - - if (res < mSpaceTolerance) { // matching ok! - LOG(DEBUG) << "MATCHING FOUND: We have a match! between track " << mTracksSectIndexCache[indices[0]][itrk] << " and TOF cluster " << mTOFClusSectIndexCache[indices[0]][itof]; - foundCluster = true; - mMatchedTracksPairs.push_back(std::make_pair(mTracksSectIndexCache[indices[0]][itrk], o2::dataformats::MatchInfoTOF(mTOFClusSectIndexCache[indices[0]][itof], chi2))); // TODO: check if this is correct! - for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++){ - LOG(DEBUG) << "TOF label " << ilabel << ": trackID = " << labelsTOF[ilabel].getTrackID() << ", eventID = " << labelsTOF[ilabel].getEventID() << ", sourceID = " << labelsTOF[ilabel].getSourceID(); - } - LOG(DEBUG) << "TPC label of the track: trackID = " << labelTPC.getTrackID() << ", eventID = " << labelTPC.getEventID() << ", sourceID = " << labelTPC.getSourceID(); - LOG(DEBUG) << "ITS label of the track: trackID = " << labelITS.getTrackID() << ", eventID = " << labelITS.getEventID() << ", sourceID = " << labelITS.getSourceID(); - fillTOFmatchTreeWithLabels("matchOkWithLabelsInSpaceTolerance", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk, labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID(), labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID(), tofLabelTrackID[0], tofLabelEventID[0], tofLabelSourceID[0], tofLabelTrackID[1], tofLabelEventID[1], tofLabelSourceID[1], tofLabelTrackID[2], tofLabelEventID[2], tofLabelSourceID[2]); - } + int tofLabelTrackID[3] = { -1, -1, -1 }; + int tofLabelEventID[3] = { -1, -1, -1 }; + int tofLabelSourceID[3] = { -1, -1, -1 }; + for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++) { + tofLabelTrackID[ilabel] = labelsTOF[ilabel].getTrackID(); + tofLabelEventID[ilabel] = labelsTOF[ilabel].getEventID(); + tofLabelSourceID[ilabel] = labelsTOF[ilabel].getSourceID(); + } + //auto labelTPC = mTPCLabels->at(mTracksSectIndexCache[indices[0]][itrk]); + auto labelITS = mITSLabels->at(mTracksSectIndexCache[indices[0]][itrk]); + fillTOFmatchTreeWithLabels("matchPossibleWithLabels", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk, labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID(), labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID(), tofLabelTrackID[0], tofLabelEventID[0], tofLabelSourceID[0], tofLabelTrackID[1], tofLabelEventID[1], tofLabelSourceID[1], tofLabelTrackID[2], tofLabelEventID[2], tofLabelSourceID[2]); + if (indices[0] != detId[iPropagation][0]) + continue; + if (indices[1] != detId[iPropagation][1]) + continue; + if (indices[2] != detId[iPropagation][2]) + continue; + float chi2 = res; // TODO: take into account also the time! + fillTOFmatchTree("match1", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk); + + fillTOFmatchTreeWithLabels("matchOkWithLabels", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk, labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID(), labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID(), tofLabelTrackID[0], tofLabelEventID[0], tofLabelSourceID[0], tofLabelTrackID[1], tofLabelEventID[1], tofLabelSourceID[1], tofLabelTrackID[2], tofLabelEventID[2], tofLabelSourceID[2]); + + if (res < mSpaceTolerance) { // matching ok! + LOG(DEBUG) << "MATCHING FOUND: We have a match! between track " << mTracksSectIndexCache[indices[0]][itrk] << " and TOF cluster " << mTOFClusSectIndexCache[indices[0]][itof]; + foundCluster = true; + mMatchedTracksPairs.push_back(std::make_pair(mTracksSectIndexCache[indices[0]][itrk], o2::dataformats::MatchInfoTOF(mTOFClusSectIndexCache[indices[0]][itof], chi2))); // TODO: check if this is correct! + for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++) { + LOG(DEBUG) << "TOF label " << ilabel << ": trackID = " << labelsTOF[ilabel].getTrackID() << ", eventID = " << labelsTOF[ilabel].getEventID() << ", sourceID = " << labelsTOF[ilabel].getSourceID(); + } + LOG(DEBUG) << "TPC label of the track: trackID = " << labelTPC.getTrackID() << ", eventID = " << labelTPC.getEventID() << ", sourceID = " << labelTPC.getSourceID(); + LOG(DEBUG) << "ITS label of the track: trackID = " << labelITS.getTrackID() << ", eventID = " << labelITS.getEventID() << ", sourceID = " << labelITS.getSourceID(); + fillTOFmatchTreeWithLabels("matchOkWithLabelsInSpaceTolerance", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk, labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID(), labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID(), tofLabelTrackID[0], tofLabelEventID[0], tofLabelSourceID[0], tofLabelTrackID[1], tofLabelEventID[1], tofLabelSourceID[1], tofLabelTrackID[2], tofLabelEventID[2], tofLabelSourceID[2]); + } } } - if (!foundCluster) LOG(DEBUG) << "We did not find any TOF cluster for track " << cacheTrk[itrk] << " (label = " << labelTPC.getTrackID() << ", pt = " << trefTrk.getPt(); + if (!foundCluster) + LOG(DEBUG) << "We did not find any TOF cluster for track " << cacheTrk[itrk] << " (label = " << labelTPC.getTrackID() << ", pt = " << trefTrk.getPt(); } return; } @@ -678,31 +680,30 @@ void MatchTOF::selectBestMatches() ///< define the track-TOFcluster pair per sector // first, we sort according to the chi2 - std::sort(mMatchedTracksPairs.begin(), mMatchedTracksPairs.end(), [this](std::pair a, std::pair b) { - return (a.second.getChi2() < b.second.getChi2());}); + std::sort(mMatchedTracksPairs.begin(), mMatchedTracksPairs.end(), [this](std::pair a, std::pair b) { return (a.second.getChi2() < b.second.getChi2()); }); int i = 0; // then we take discard the pairs if their track or cluster was already matched (since they are ordered in chi2, we will take the best matching) - for (const std::pair &matchingPair : mMatchedTracksPairs){ + for (const std::pair& matchingPair : mMatchedTracksPairs) { if (mMatchedTracksIndex[matchingPair.first] != -1) { // the track was already filled continue; } if (mMatchedClustersIndex[matchingPair.second.getTOFClIndex()] != -1) { // the track was already filled continue; } - mMatchedTracksIndex[matchingPair.first] = mMatchedTracks.size(); // index of the MatchInfoTOF correspoding to this track + mMatchedTracksIndex[matchingPair.first] = mMatchedTracks.size(); // index of the MatchInfoTOF correspoding to this track mMatchedClustersIndex[matchingPair.second.getTOFClIndex()] = mMatchedTracksIndex[matchingPair.first]; // index of the track that was matched to this cluster - mMatchedTracks.push_back(matchingPair); // array of MatchInfoTOF + mMatchedTracks.push_back(matchingPair); // array of MatchInfoTOF const auto& labelTPC = mTPCLabels->at(matchingPair.first); LOG(DEBUG) << "labelTPC: trackID = " << labelTPC.getTrackID() << ", eventID = " << labelTPC.getEventID() << ", sourceID = " << labelTPC.getSourceID(); const auto& labelITS = mITSLabels->at(matchingPair.first); LOG(DEBUG) << "labelITS: trackID = " << labelITS.getTrackID() << ", eventID = " << labelITS.getEventID() << ", sourceID = " << labelITS.getSourceID(); const auto& labelsTOF = mTOFClusLabels->getLabels(matchingPair.second.getTOFClIndex()); bool labelOk = false; // whether we have found or not the same TPC label of the track among the labels of the TOF cluster - for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++){ + for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++) { LOG(DEBUG) << "TOF label " << ilabel << ": trackID = " << labelsTOF[ilabel].getTrackID() << ", eventID = " << labelsTOF[ilabel].getEventID() << ", sourceID = " << labelsTOF[ilabel].getSourceID(); if (labelsTOF[ilabel].getTrackID() == labelTPC.getTrackID() && labelsTOF[ilabel].getEventID() == labelTPC.getEventID() && labelsTOF[ilabel].getSourceID() == labelTPC.getSourceID() && !labelOk) { // if we find one TOF cluster label that is the same as the TPC one, we are happy - even if it is not the first one - mOutTOFLabels.push_back(labelsTOF[ilabel]); - labelOk = true; + mOutTOFLabels.push_back(labelsTOF[ilabel]); + labelOk = true; } } if (!labelOk) { @@ -715,7 +716,6 @@ void MatchTOF::selectBestMatches() mOutITSLabels.push_back(labelITS); i++; } - } //______________________________________________ @@ -725,9 +725,10 @@ bool MatchTOF::propagateToRefX(o2::track::TrackParCov& trc, float xRef, float st bool refReached = false; float xStart = trc.getX(); // the first propagation will be from 2m, if the track is not at least at 2m - if (xStart < 50.) xStart = 50.; + if (xStart < 50.) + xStart = 50.; int istep = 1; - bool hasPropagated = o2::Base::Propagator::Instance()->PropagateToXBxByBz(trc, xStart + istep*stepInCm, o2::constants::physics::MassPionCharged, MAXSNP, stepInCm, 0.); + bool hasPropagated = o2::Base::Propagator::Instance()->PropagateToXBxByBz(trc, xStart + istep * stepInCm, o2::constants::physics::MassPionCharged, MAXSNP, stepInCm, 0.); while (hasPropagated) { if (trc.getX() > xRef) { refReached = true; // we reached the 371cm reference @@ -738,19 +739,19 @@ bool MatchTOF::propagateToRefX(o2::track::TrackParCov& trc, float xRef, float st //Printf("propagateToRefX: changing sector"); auto alphaNew = o2::utils::Angle2Alpha(trc.getPhiPos()); if (!trc.rotate(alphaNew) != 0) { - // Printf("propagateToRefX: failed to rotate"); - break; // failed (this line is taken from MatchTPCITS and the following comment too: RS: check effect on matching tracks to neighbouring sector) + // Printf("propagateToRefX: failed to rotate"); + break; // failed (this line is taken from MatchTPCITS and the following comment too: RS: check effect on matching tracks to neighbouring sector) } } - if (refReached) break; - hasPropagated = o2::Base::Propagator::Instance()->PropagateToXBxByBz(trc, xStart + istep*stepInCm, o2::constants::physics::MassPionCharged, MAXSNP, stepInCm, 0.); + if (refReached) + break; + hasPropagated = o2::Base::Propagator::Instance()->PropagateToXBxByBz(trc, xStart + istep * stepInCm, o2::constants::physics::MassPionCharged, MAXSNP, stepInCm, 0.); } // if (std::abs(trc.getSnp()) > MAXSNP) Printf("propagateToRefX: condition on snp not ok, returning false"); //Printf("propagateToRefX: snp of teh track is %f (--> %f grad)", trc.getSnp(), TMath::ASin(trc.getSnp())*TMath::RadToDeg()); return refReached && std::abs(trc.getSnp()) < 0.95; // Here we need to put MAXSNP - } - + #ifdef _ALLOW_DEBUG_TREES_ //______________________________________________ void MatchTOF::setDebugFlag(UInt_t flag, bool on) @@ -764,13 +765,13 @@ void MatchTOF::setDebugFlag(UInt_t flag, bool on) } //_________________________________________________________ -void MatchTOF::fillTOFmatchTree(const char* trname, int cacheTOF, int sectTOF, int plateTOF, int stripTOF, int padXTOF, int padZTOF, int cacheeTrk, int crossedStrip, int sectPropagation, int platePropagation, int stripPropagation, int padXPropagation, int padZPropagation, float resX, float resZ, float res, o2::dataformats::TrackTPCITS &trk) +void MatchTOF::fillTOFmatchTree(const char* trname, int cacheTOF, int sectTOF, int plateTOF, int stripTOF, int padXTOF, int padZTOF, int cacheeTrk, int crossedStrip, int sectPropagation, int platePropagation, int stripPropagation, int padXPropagation, int padZPropagation, float resX, float resZ, float res, o2::dataformats::TrackTPCITS& trk) { ///< fill debug tree for TOF tracks matching check mTimerDBG.Start(false); -// Printf("************** Filling the debug tree with %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %f, %f, %f", cacheTOF, sectTOF, plateTOF, stripTOF, padXTOF, padZTOF, cacheeTrk, crossedStrip, sectPropagation, platePropagation, stripPropagation, padXPropagation, padZPropagation, resX, resZ, res); + // Printf("************** Filling the debug tree with %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %f, %f, %f", cacheTOF, sectTOF, plateTOF, stripTOF, padXTOF, padZTOF, cacheeTrk, crossedStrip, sectPropagation, platePropagation, stripPropagation, padXPropagation, padZPropagation, resX, resZ, res); (*mDBGOut) << trname << "clusterTOF=" << cacheTOF << "sectTOF=" << sectTOF << "plateTOF=" << plateTOF << "stripTOF=" << stripTOF << "padXTOF=" << padXTOF << "padZTOF=" << padZTOF @@ -780,7 +781,7 @@ void MatchTOF::fillTOFmatchTree(const char* trname, int cacheTOF, int sectTOF, i } //_________________________________________________________ -void MatchTOF::fillTOFmatchTreeWithLabels(const char* trname, int cacheTOF, int sectTOF, int plateTOF, int stripTOF, int padXTOF, int padZTOF, int cacheeTrk, int crossedStrip, int sectPropagation, int platePropagation, int stripPropagation, int padXPropagation, int padZPropagation, float resX, float resZ, float res, o2::dataformats::TrackTPCITS &trk, int TPClabelTrackID, int TPClabelEventID, int TPClabelSourceID, int ITSlabelTrackID, int ITSlabelEventID, int ITSlabelSourceID, int TOFlabelTrackID0, int TOFlabelEventID0, int TOFlabelSourceID0, int TOFlabelTrackID1, int TOFlabelEventID1, int TOFlabelSourceID1, int TOFlabelTrackID2, int TOFlabelEventID2, int TOFlabelSourceID2) +void MatchTOF::fillTOFmatchTreeWithLabels(const char* trname, int cacheTOF, int sectTOF, int plateTOF, int stripTOF, int padXTOF, int padZTOF, int cacheeTrk, int crossedStrip, int sectPropagation, int platePropagation, int stripPropagation, int padXPropagation, int padZPropagation, float resX, float resZ, float res, o2::dataformats::TrackTPCITS& trk, int TPClabelTrackID, int TPClabelEventID, int TPClabelSourceID, int ITSlabelTrackID, int ITSlabelEventID, int ITSlabelSourceID, int TOFlabelTrackID0, int TOFlabelEventID0, int TOFlabelSourceID0, int TOFlabelTrackID1, int TOFlabelEventID1, int TOFlabelSourceID1, int TOFlabelTrackID2, int TOFlabelEventID2, int TOFlabelSourceID2) { ///< fill debug tree for TOF tracks matching check diff --git a/Detectors/TOF/base/include/TOFBase/Geo.h b/Detectors/TOF/base/include/TOFBase/Geo.h index 324c17df27afc..26be900a21f2d 100644 --- a/Detectors/TOF/base/include/TOFBase/Geo.h +++ b/Detectors/TOF/base/include/TOFBase/Geo.h @@ -95,7 +95,7 @@ class Geo static constexpr Float_t DEADTIMETDC = DEADTIME/TDCBIN; ///< Single channel TDC dead time (ps) static constexpr Float_t MATCHINGWINDOW = TDCBIN * 8192; // Matching window (ps) 2^13=8192 // static constexpr Float_t READOUTWINDOW = 1000; // Readout window (ns) - static constexpr Float_t READOUTWINDOW = 1e9; // Readout window (ns) - now put 1s for DPL to work fine, but it will be 29e3 + static constexpr Float_t READOUTWINDOW = 1e9; // Readout window (ns) - now put 1s for DPL to work fine, but it will be 29e3 static constexpr Float_t READOUTWINDOW_INV = 1. / READOUTWINDOW; // Readout window (ns) static constexpr Float_t ANGLES[NPLATES][NMAXNSTRIP] = { // Strip Tilt Angles diff --git a/Detectors/TOF/base/src/Geo.cxx b/Detectors/TOF/base/src/Geo.cxx index 342650af2d0d1..af8bfe08bcff7 100644 --- a/Detectors/TOF/base/src/Geo.cxx +++ b/Detectors/TOF/base/src/Geo.cxx @@ -158,7 +158,8 @@ void Geo::getPos(Int_t* det, Float_t* pos) Char_t path[200]; getVolumePath(det, path); if (!gGeoManager) { - LOG(ERROR) << " no TGeo! Loading it" << "\n"; + LOG(ERROR) << " no TGeo! Loading it" + << "\n"; o2::Base::GeometryManager::loadGeometry(); } FILE* ciccio = fopen("TOF_geo.txt", "w"); @@ -326,7 +327,7 @@ Int_t Geo::getStripNumberPerSM(Int_t iplate, Int_t istrip) void Geo::fromGlobalToSector(Float_t* pos, Int_t isector) { if (isector == -1) { - //LOG(ERROR) << "Sector Index not valid (-1)\n"; + //LOG(ERROR) << "Sector Index not valid (-1)\n"; return; } @@ -636,4 +637,3 @@ void Geo::antiRotate(Float_t* xyz, Double_t rotationAngles[6]) return; } - diff --git a/Detectors/TOF/base/src/TOFBaseLinkDef.h b/Detectors/TOF/base/src/TOFBaseLinkDef.h index 1dd54f644f680..3cef9f5920fb7 100644 --- a/Detectors/TOF/base/src/TOFBaseLinkDef.h +++ b/Detectors/TOF/base/src/TOFBaseLinkDef.h @@ -17,6 +17,6 @@ #pragma link C++ class o2::tof::Geo+; #pragma link C++ class o2::tof::Digit+; #pragma link C++ class vector+; -#pragma link C++ class vector>+; +#pragma link C++ class vector < vector < o2::tof::Digit >> +; #endif diff --git a/Detectors/TOF/prototyping/findLabels.C b/Detectors/TOF/prototyping/findLabels.C index 69d24dbc75485..e1cd2439adc00 100644 --- a/Detectors/TOF/prototyping/findLabels.C +++ b/Detectors/TOF/prototyping/findLabels.C @@ -1,17 +1,18 @@ -void findLabels(int itrk, int ientry){ +void findLabels(int itrk, int ientry) +{ // macro to find the labels of a TPCITS track and the corresponding TOF cluster // getting the ITSTPCtracks TFile* fmatchITSTPC = new TFile("o2match_itstpc.root"); TTree* matchTPCITS = (TTree*)fmatchITSTPC->Get("matchTPCITS"); - std::vector* mTracksArrayInp = new std::vector; + std::vector* mTracksArrayInp = new std::vector; matchTPCITS->SetBranchAddress("TPCITS", &mTracksArrayInp); matchTPCITS->GetEntry(ientry); - + // getting the TPC tracks TFile* ftracksTPC = new TFile("tpctracks.root"); - TTree* tpcTree = (TTree*) ftracksTPC->Get("events"); + TTree* tpcTree = (TTree*)ftracksTPC->Get("events"); std::vector* mTPCTracksArrayInp = new std::vector; tpcTree->SetBranchAddress("Tracks", &mTPCTracksArrayInp); o2::dataformats::MCTruthContainer* mcTPC = new o2::dataformats::MCTruthContainer(); @@ -19,7 +20,7 @@ void findLabels(int itrk, int ientry){ // getting the ITS tracks TFile* ftracksITS = new TFile("o2trac_its.root"); - TTree* itsTree = (TTree*) ftracksITS->Get("o2sim"); + TTree* itsTree = (TTree*)ftracksITS->Get("o2sim"); std::vector* mITSTracksArrayInp = new std::vector; itsTree->SetBranchAddress("ITSTrack", &mITSTracksArrayInp); o2::dataformats::MCTruthContainer* mcITS = new o2::dataformats::MCTruthContainer(); @@ -27,60 +28,58 @@ void findLabels(int itrk, int ientry){ // getting the TOF clusters TFile* fclustersTOF = new TFile("tofclusters.root"); - TTree* tofClTree = (TTree*) fclustersTOF->Get("o2sim"); + TTree* tofClTree = (TTree*)fclustersTOF->Get("o2sim"); std::vector* mTOFClustersArrayInp = new std::vector; tofClTree->SetBranchAddress("TOFCluster", &mTOFClustersArrayInp); o2::dataformats::MCTruthContainer* mcTOF = new o2::dataformats::MCTruthContainer(); tofClTree->SetBranchAddress("TOFClusterMCTruth", &mcTOF); - + tpcTree->GetEntry(0); tofClTree->GetEntry(0); o2::dataformats::TrackTPCITS trackITSTPC = mTracksArrayInp->at(itrk); - const o2::dataformats::EvIndex &evIdxTPC = trackITSTPC.getRefTPC(); + const o2::dataformats::EvIndex& evIdxTPC = trackITSTPC.getRefTPC(); Printf("matched TPCtrack: eventID = %d, indexID = %d", evIdxTPC.getEvent(), evIdxTPC.getIndex()); - const o2::dataformats::EvIndex &evIdxITS = trackITSTPC.getRefITS(); + const o2::dataformats::EvIndex& evIdxITS = trackITSTPC.getRefITS(); Printf("matched ITStrack: eventID = %d, indexID = %d", evIdxITS.getEvent(), evIdxITS.getIndex()); itsTree->GetEntry(evIdxITS.getEvent()); - + // getting the TPC labels const auto& labelsTPC = mcTPC->getLabels(evIdxTPC.getIndex()); - for (int ilabel = 0; ilabel < labelsTPC.size(); ilabel++){ + for (int ilabel = 0; ilabel < labelsTPC.size(); ilabel++) { Printf("TPC label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTPC[ilabel].getTrackID(), labelsTPC[ilabel].getEventID(), labelsTPC[ilabel].getSourceID()); } - + // getting the ITS labels const auto& labelsITS = mcITS->getLabels(evIdxITS.getIndex()); - for (int ilabel = 0; ilabel < labelsITS.size(); ilabel++){ + for (int ilabel = 0; ilabel < labelsITS.size(); ilabel++) { Printf("ITS label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsITS[ilabel].getTrackID(), labelsITS[ilabel].getEventID(), labelsITS[ilabel].getSourceID()); } // now checking if we have a corresponding cluster bool found = false; - for (int tofClIndex = 0; tofClIndex < mTOFClustersArrayInp->size(); tofClIndex++){ + for (int tofClIndex = 0; tofClIndex < mTOFClustersArrayInp->size(); tofClIndex++) { o2::tof::Cluster tofCluster = mTOFClustersArrayInp->at(tofClIndex); const auto& labelsTOF = mcTOF->getLabels(tofClIndex); int trackIdTOF; int eventIdTOF; int sourceIdTOF; - for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++){ + for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++) { if ((labelsTPC[0].getTrackID() == labelsTOF[ilabel].getTrackID() && labelsTPC[0].getEventID() == labelsTOF[ilabel].getEventID() && labelsTPC[0].getSourceID() == labelsTOF[ilabel].getSourceID()) || (labelsITS[0].getTrackID() == labelsTOF[ilabel].getTrackID() && labelsITS[0].getEventID() == labelsTOF[ilabel].getEventID() && labelsITS[0].getSourceID() == labelsTOF[ilabel].getSourceID())) { - Printf("The corresponding TOF cluster is %d", tofClIndex); - Printf("TOF label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTOF[ilabel].getTrackID(), labelsTOF[ilabel].getEventID(), labelsTOF[ilabel].getSourceID()); - found = true; - int nContrChannels = tofCluster.getNumOfContributingChannels(); - int mainContrChannel = tofCluster.getMainContributingChannel(); - int* indices = new int[5]; - o2::tof::Geo::getVolumeIndices(mainContrChannel, indices); - Printf("main contributing channel: sector = %d, plate = %d, strip = %d, padz = %d, padx = %d", indices[0], indices[1] , indices[2], indices[3], indices[4]); - break; + Printf("The corresponding TOF cluster is %d", tofClIndex); + Printf("TOF label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTOF[ilabel].getTrackID(), labelsTOF[ilabel].getEventID(), labelsTOF[ilabel].getSourceID()); + found = true; + int nContrChannels = tofCluster.getNumOfContributingChannels(); + int mainContrChannel = tofCluster.getMainContributingChannel(); + int* indices = new int[5]; + o2::tof::Geo::getVolumeIndices(mainContrChannel, indices); + Printf("main contributing channel: sector = %d, plate = %d, strip = %d, padz = %d, padx = %d", indices[0], indices[1], indices[2], indices[3], indices[4]); + break; } } } - if (!found) Printf("No TOF cluster corresponding to this track was found"); + if (!found) + Printf("No TOF cluster corresponding to this track was found"); return; } - - - diff --git a/Detectors/TOF/prototyping/findTOFclusterFromLabel.C b/Detectors/TOF/prototyping/findTOFclusterFromLabel.C index 571f0ad500e6a..b5ae58b0120b8 100644 --- a/Detectors/TOF/prototyping/findTOFclusterFromLabel.C +++ b/Detectors/TOF/prototyping/findTOFclusterFromLabel.C @@ -1,74 +1,77 @@ -void findTOFclusterFromLabel(int trackID, int eventID = 0, int sourceID = 0){ +void findTOFclusterFromLabel(int trackID, int eventID = 0, int sourceID = 0) +{ // macro to find the labels of a TPCITS track and the corresponding TOF cluster // getting the TOF clusters TFile* fclustersTOF = new TFile("tofclusters.root"); - TTree* tofClTree = (TTree*) fclustersTOF->Get("o2sim"); + TTree* tofClTree = (TTree*)fclustersTOF->Get("o2sim"); std::vector* mTOFClustersArrayInp = new std::vector; tofClTree->SetBranchAddress("TOFCluster", &mTOFClustersArrayInp); o2::dataformats::MCTruthContainer* mcTOF = new o2::dataformats::MCTruthContainer(); tofClTree->SetBranchAddress("TOFClusterMCTruth", &mcTOF); - + tofClTree->GetEntry(0); // now checking if we have a corresponding cluster bool found = false; - for (int tofClIndex = 0; tofClIndex < mTOFClustersArrayInp->size(); tofClIndex++){ + for (int tofClIndex = 0; tofClIndex < mTOFClustersArrayInp->size(); tofClIndex++) { o2::tof::Cluster tofCluster = mTOFClustersArrayInp->at(tofClIndex); const auto& labelsTOF = mcTOF->getLabels(tofClIndex); int trackIdTOF; int eventIdTOF; int sourceIdTOF; - for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++){ + for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++) { if (trackID == labelsTOF[ilabel].getTrackID() && eventID == labelsTOF[ilabel].getEventID() && sourceID == labelsTOF[ilabel].getSourceID()) { - Printf("The corresponding TOF cluster is %d", tofClIndex); - Printf("TOF label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTOF[ilabel].getTrackID(), labelsTOF[ilabel].getEventID(), labelsTOF[ilabel].getSourceID()); - found = true; - int nContrChannels = tofCluster.getNumOfContributingChannels(); - int mainContrChannel = tofCluster.getMainContributingChannel(); - int* indices = new int[5]; - o2::tof::Geo::getVolumeIndices(mainContrChannel, indices); - Printf("main contributing channel: sector = %d, plate = %d, strip = %d, padz = %d, padx = %d", indices[0], indices[1] , indices[2], indices[3], indices[4]); - break; + Printf("The corresponding TOF cluster is %d", tofClIndex); + Printf("TOF label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTOF[ilabel].getTrackID(), labelsTOF[ilabel].getEventID(), labelsTOF[ilabel].getSourceID()); + found = true; + int nContrChannels = tofCluster.getNumOfContributingChannels(); + int mainContrChannel = tofCluster.getMainContributingChannel(); + int* indices = new int[5]; + o2::tof::Geo::getVolumeIndices(mainContrChannel, indices); + Printf("main contributing channel: sector = %d, plate = %d, strip = %d, padz = %d, padx = %d", indices[0], indices[1], indices[2], indices[3], indices[4]); + break; } } } - if (!found) Printf("No TOF cluster corresponding to this label was found"); + if (!found) + Printf("No TOF cluster corresponding to this label was found"); TFile* fdigitsTOF = new TFile("tofdigits.root"); - TTree* tofDigTree = (TTree*) fdigitsTOF->Get("o2sim"); + TTree* tofDigTree = (TTree*)fdigitsTOF->Get("o2sim"); std::vector>* mTOFDigitsArrayInp = nullptr; tofDigTree->SetBranchAddress("TOFDigit", &mTOFDigitsArrayInp); std::vector>* mcTOFDig = nullptr; tofDigTree->SetBranchAddress("TOFDigitMCTruth", &mcTOFDig); bool foundInDigits = false; Printf("Now looking in the digits"); - for (int ientry = 0; ientry < tofDigTree->GetEntries(); ientry++){ + for (int ientry = 0; ientry < tofDigTree->GetEntries(); ientry++) { //Printf("\n\nEntry in tree %d", ientry); tofDigTree->GetEntry(ientry); - for (int iVect = 0; iVect < mTOFDigitsArrayInp->size(); iVect++){ + for (int iVect = 0; iVect < mTOFDigitsArrayInp->size(); iVect++) { //Printf("\nEntry in vector of digits and MC truth %d", iVect); std::vector digitVector = mTOFDigitsArrayInp->at(iVect); o2::dataformats::MCTruthContainer digitMCTruth = mcTOFDig->at(iVect); - for (int iDig = 0; iDig < digitVector.size(); iDig++){ - //Printf("Digit %d", iDig); - o2::tof::Digit digit = digitVector.at(iDig); - int digitLabel = digit.getLabel(); - gsl::span mcArray = digitMCTruth.getLabels(digitLabel); - for (int j = 0; j < static_cast(mcArray.size()); j++) { - //printf("checking element %d in the array of labels\n", j); - auto label = digitMCTruth.getElement(digitMCTruth.getMCTruthHeader(digitLabel).index + j); - //printf("TrackID = %d, EventID = %d, SourceID = %d\n", label.getTrackID(), label.getEventID(), label.getSourceID()); - if (label.getTrackID() == trackID && label.getEventID() == eventID && label.getSourceID() == sourceID){ - Printf("We found the label that we were looking for! tree entry = %d, vector entry = %d, digit = %d", ientry, iVect, iDig); - foundInDigits = true; - } - } + for (int iDig = 0; iDig < digitVector.size(); iDig++) { + //Printf("Digit %d", iDig); + o2::tof::Digit digit = digitVector.at(iDig); + int digitLabel = digit.getLabel(); + gsl::span mcArray = digitMCTruth.getLabels(digitLabel); + for (int j = 0; j < static_cast(mcArray.size()); j++) { + //printf("checking element %d in the array of labels\n", j); + auto label = digitMCTruth.getElement(digitMCTruth.getMCTruthHeader(digitLabel).index + j); + //printf("TrackID = %d, EventID = %d, SourceID = %d\n", label.getTrackID(), label.getEventID(), label.getSourceID()); + if (label.getTrackID() == trackID && label.getEventID() == eventID && label.getSourceID() == sourceID) { + Printf("We found the label that we were looking for! tree entry = %d, vector entry = %d, digit = %d", ientry, iVect, iDig); + foundInDigits = true; + } + } } } } - if (!foundInDigits) Printf("The label was NEVER found in the digits"); + if (!foundInDigits) + Printf("The label was NEVER found in the digits"); TFile* fKine = new TFile("o2sim.root"); TTree* tKine = (TTree*)fKine->Get("o2sim"); @@ -78,37 +81,35 @@ void findTOFclusterFromLabel(int trackID, int eventID = 0, int sourceID = 0){ for (int i = 0; i < mcArr->size(); ++i) { const auto& mcTrack = (*mcArr)[i]; if (i == trackID) { - Printf("Particle %d: pdg = %d, pT = %f, px = %f, py = %f, pz = %f, vx = %f, vy = %f, vz = %f", i, mcTrack.GetPdgCode(), TMath::Abs(mcTrack.GetStartVertexMomentumX()*mcTrack.GetStartVertexMomentumX() + mcTrack.GetStartVertexMomentumY()*mcTrack.GetStartVertexMomentumY()), mcTrack.GetStartVertexMomentumX(), mcTrack.GetStartVertexMomentumY(), mcTrack.GetStartVertexMomentumZ(), mcTrack.GetStartVertexCoordinatesX(), mcTrack.GetStartVertexCoordinatesY(), mcTrack.GetStartVertexCoordinatesZ() ); + Printf("Particle %d: pdg = %d, pT = %f, px = %f, py = %f, pz = %f, vx = %f, vy = %f, vz = %f", i, mcTrack.GetPdgCode(), TMath::Abs(mcTrack.GetStartVertexMomentumX() * mcTrack.GetStartVertexMomentumX() + mcTrack.GetStartVertexMomentumY() * mcTrack.GetStartVertexMomentumY()), mcTrack.GetStartVertexMomentumX(), mcTrack.GetStartVertexMomentumY(), mcTrack.GetStartVertexMomentumZ(), mcTrack.GetStartVertexCoordinatesX(), mcTrack.GetStartVertexCoordinatesY(), mcTrack.GetStartVertexCoordinatesZ()); } } TFile* fmatch = new TFile("o2match_itstpc.root"); TTree* matchTPCITS = (TTree*)fmatch->Get("matchTPCITS"); - std::vector* mTracksArrayInp = new std::vector; + std::vector* mTracksArrayInp = new std::vector; matchTPCITS->SetBranchAddress("TPCITS", &mTracksArrayInp); matchTPCITS->GetEntry(eventID); // getting the TPC tracks TFile* ftracksTPC = new TFile("tpctracks.root"); - TTree* tpcTree = (TTree*) ftracksTPC->Get("events"); + TTree* tpcTree = (TTree*)ftracksTPC->Get("events"); std::vector* mTPCTracksArrayInp = new std::vector; tpcTree->SetBranchAddress("Tracks", &mTPCTracksArrayInp); o2::dataformats::MCTruthContainer* mcTPC = new o2::dataformats::MCTruthContainer(); tpcTree->SetBranchAddress("TPCTracksMCTruth", &mcTPC); tpcTree->GetEntry(eventID); - for (int i = 0; i < mTracksArrayInp->size(); i++){ + for (int i = 0; i < mTracksArrayInp->size(); i++) { o2::dataformats::TrackTPCITS trackITSTPC = mTracksArrayInp->at(i); - const o2::dataformats::EvIndex &evIdxTPC = trackITSTPC.getRefTPC(); - const auto& labelsTPC = mcTPC->getLabels(evIdxTPC.getIndex()); - for (int ilabel = 0; ilabel < labelsTPC.size(); ilabel++){ - //Printf("TPC label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTPC[ilabel].getTrackID(), labelsTPC[ilabel].getEventID(), labelsTPC[ilabel].getSourceID()); - if (labelsTPC[ilabel].getTrackID() == trackID && labelsTPC[ilabel].getEventID() == eventID) Printf("TPC track found"); - } + const o2::dataformats::EvIndex& evIdxTPC = trackITSTPC.getRefTPC(); + const auto& labelsTPC = mcTPC->getLabels(evIdxTPC.getIndex()); + for (int ilabel = 0; ilabel < labelsTPC.size(); ilabel++) { + //Printf("TPC label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTPC[ilabel].getTrackID(), labelsTPC[ilabel].getEventID(), labelsTPC[ilabel].getSourceID()); + if (labelsTPC[ilabel].getTrackID() == trackID && labelsTPC[ilabel].getEventID() == eventID) + Printf("TPC track found"); + } } return; } - - - diff --git a/Detectors/TOF/reconstruction/src/Clusterer.cxx b/Detectors/TOF/reconstruction/src/Clusterer.cxx index d7296ff1e81e0..10d2bc1aadf27 100644 --- a/Detectors/TOF/reconstruction/src/Clusterer.cxx +++ b/Detectors/TOF/reconstruction/src/Clusterer.cxx @@ -131,7 +131,7 @@ void Clusterer::buildCluster(Cluster& c, MCLabelContainer const* digitMCTruth) } c.setMainContributingChannel(mContributingDigit[0]->getChannel()); - c.setTime(mContributingDigit[0]->getTDC() * Geo::TDCBIN + double(mContributingDigit[0]->getBC()*25000.)); // time in ps (for now we assume it calibrated) + c.setTime(mContributingDigit[0]->getTDC() * Geo::TDCBIN + double(mContributingDigit[0]->getBC() * 25000.)); // time in ps (for now we assume it calibrated) c.setTot(mContributingDigit[0]->getTOT() * Geo::TOTBIN * 1E-3); // TOT in ns (for now we assume it calibrated) //setL0L1Latency(); // to be filled (maybe) @@ -189,9 +189,9 @@ void Clusterer::buildCluster(Cluster& c, MCLabelContainer const* digitMCTruth) printf("digitLabel = %d\n", digitLabel); gsl::span mcArray = digitMCTruth->getLabels(digitLabel); for (int j = 0; j < static_cast(mcArray.size()); j++) { - printf("checking element %d in the array of labels\n", j); + printf("checking element %d in the array of labels\n", j); auto label = digitMCTruth->getElement(digitMCTruth->getMCTruthHeader(digitLabel).index + j); - printf("EventID = %d\n", label.getEventID()); + printf("EventID = %d\n", label.getEventID()); mClsLabels->addElement(lbl, label); } } @@ -199,10 +199,10 @@ void Clusterer::buildCluster(Cluster& c, MCLabelContainer const* digitMCTruth) // set geometrical variables int det[5]; - Geo::getVolumeIndices(c.getMainContributingChannel(),det); + Geo::getVolumeIndices(c.getMainContributingChannel(), det); float pos[3]; Geo::getPos(det, pos); - c.SetBaseData(c.getMainContributingChannel(),pos[0],pos[1],pos[2],0,0,0); // error on position set to zero + c.SetBaseData(c.getMainContributingChannel(), pos[0], pos[1], pos[2], 0, 0, 0); // error on position set to zero return; } diff --git a/Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h b/Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h index 3d003191c32bd..9d6b9ca1d4c1c 100644 --- a/Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h +++ b/Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h @@ -67,8 +67,8 @@ class Digitizer void setContinuous(bool val) { mContinuous = val; } bool isContinuous() const { return mContinuous; } - std::vector< std::vector>* getDigitPerTimeFrame() {return &mDigitsPerTimeFrame;} - std::vector >* getMCTruthPerTimeFrame() {return &mMCTruthOutputContainerPerTimeFrame;} + std::vector>* getDigitPerTimeFrame() { return &mDigitsPerTimeFrame; } + std::vector>* getMCTruthPerTimeFrame() { return &mMCTruthOutputContainerPerTimeFrame; } private: // parameters @@ -102,8 +102,8 @@ class Digitizer static const int MAXWINDOWS = 2; // how many readout windows we can buffer - std::vector< std::vector > mDigitsPerTimeFrame; - std::vector > mMCTruthOutputContainerPerTimeFrame; + std::vector> mDigitsPerTimeFrame; + std::vector> mMCTruthOutputContainerPerTimeFrame; int mIcurrentReadoutWindow = 0; o2::dataformats::MCTruthContainer mMCTruthContainer[MAXWINDOWS]; diff --git a/Detectors/TOF/simulation/src/Digitizer.cxx b/Detectors/TOF/simulation/src/Digitizer.cxx index 06557439ba3f6..d4469c0c69f40 100644 --- a/Detectors/TOF/simulation/src/Digitizer.cxx +++ b/Detectors/TOF/simulation/src/Digitizer.cxx @@ -46,29 +46,30 @@ void Digitizer::init() //______________________________________________________________________ -void Digitizer::process(const std::vector* hits, std::vector* digits){ - // hits array of TOF hits for a given simulated event +void Digitizer::process(const std::vector* hits, std::vector* digits) +{ + // hits array of TOF hits for a given simulated event // digits passed from external to be filled, in continuous readout mode we will push it on mDigitsPerTimeFrame vector of vectors of digits - + Int_t readoutwindow = Int_t((mEventTime)*Geo::READOUTWINDOW_INV); // to be replaced with "uncalibrated" time - printf("process TOF -> continuous = %i, %i > %i?\n",mContinuous,readoutwindow,mReadoutWindowCurrent); + printf("process TOF -> continuous = %i, %i > %i?\n", mContinuous, readoutwindow, mReadoutWindowCurrent); if (mContinuous && readoutwindow > mReadoutWindowCurrent) { // if we are moving in future readout windows flush previous ones (only for continuous readout mode) digits->clear(); - + for (mReadoutWindowCurrent; mReadoutWindowCurrent < readoutwindow; mReadoutWindowCurrent++) { - fillOutputContainer(*digits); // fill all windows which are before (not yet stored) of the new current one + fillOutputContainer(*digits); // fill all windows which are before (not yet stored) of the new current one checkIfReuseFutureDigits(); - } // close loop readout window - } // close if continuous - + } // close loop readout window + } // close if continuous + for (auto& hit : *hits) { //TODO: put readout window counting/selection - + processHit(hit, mEventTime); } // end loop over hits - + if (!mContinuous) { // fill output container per event digits->clear(); fillOutputContainer(*digits); @@ -242,7 +243,6 @@ void Digitizer::addDigit(Int_t channel, UInt_t istrip, Float_t time, Float_t x, if (mContinuous) { isnext = Int_t(time * 1E-3 * Geo::READOUTWINDOW_INV) - mReadoutWindowCurrent; // to be replaced with uncalibrated time - if (isnext < 0 || isnext >= MAXWINDOWS - 1) { lblCurrent = mFutureIevent.size(); // this is the size of mHeaderArray; @@ -680,7 +680,7 @@ void Digitizer::testFromHits(const char* geo, const char* hits) //______________________________________________________________________ void Digitizer::fillOutputContainer(std::vector& digits) { - if(mContinuous){ + if (mContinuous) { digits.clear(); mMCTruthOutputContainer->clear(); } @@ -691,8 +691,9 @@ void Digitizer::fillOutputContainer(std::vector& digits) strip.fillOutputContainer(digits); } - if(mContinuous){ - if(digits.size()) printf("%i) # TOF digits = %i (%x)\n",mIcurrentReadoutWindow,digits.size(),mStripsCurrent); + if (mContinuous) { + if (digits.size()) + printf("%i) # TOF digits = %i (%x)\n", mIcurrentReadoutWindow, digits.size(), mStripsCurrent); mDigitsPerTimeFrame.push_back(digits); } @@ -707,7 +708,8 @@ void Digitizer::fillOutputContainer(std::vector& digits) } } - if(mContinuous) mMCTruthOutputContainerPerTimeFrame.push_back(*mMCTruthOutputContainer); + if (mContinuous) + mMCTruthOutputContainerPerTimeFrame.push_back(*mMCTruthOutputContainer); mMCTruthContainerCurrent->clear(); // switch to next mStrip after flushing current readout window data @@ -732,15 +734,16 @@ void Digitizer::flushOutputContainer(std::vector& digits) { // flush all residual buffered data // TO be implemented printf("flushOutputContainer\n"); - if(! mContinuous) fillOutputContainer(digits); - else{ - for(Int_t i=0;i < MAXWINDOWS;i++){ + if (!mContinuous) + fillOutputContainer(digits); + else { + for (Int_t i = 0; i < MAXWINDOWS; i++) { fillOutputContainer(digits); // fill all windows which are before (not yet stored) of the new current one checkIfReuseFutureDigits(); mReadoutWindowCurrent++; } - while(mFutureDigits.size()){ + while (mFutureDigits.size()) { fillOutputContainer(digits); // fill all windows which are before (not yet stored) of the new current one checkIfReuseFutureDigits(); mReadoutWindowCurrent++; @@ -748,46 +751,46 @@ void Digitizer::flushOutputContainer(std::vector& digits) } } //______________________________________________________________________ -void Digitizer::checkIfReuseFutureDigits(){ +void Digitizer::checkIfReuseFutureDigits() +{ // check if digits stored very far in future match the new readout windows currently available - int idigit = 0; + int idigit = 0; for (auto& digit : mFutureDigits) { - double timestamp = digit.getBC()*25 + digit.getTDC() * Geo::TDCBIN*1E-3; // in ns - int isnext = Int_t(timestamp * Geo::READOUTWINDOW_INV) - (mReadoutWindowCurrent+1); // to be replaced with uncalibrated time - if (isnext < 0) // we jump too ahead in future, digit will be not stored + double timestamp = digit.getBC() * 25 + digit.getTDC() * Geo::TDCBIN * 1E-3; // in ns + int isnext = Int_t(timestamp * Geo::READOUTWINDOW_INV) - (mReadoutWindowCurrent + 1); // to be replaced with uncalibrated time + if (isnext < 0) // we jump too ahead in future, digit will be not stored LOG(INFO) << "Digit lost because we jump too ahead in future. Current RO window=" << isnext << "\n"; if (isnext < MAXWINDOWS - 1) { // move from digit buffer array to the proper window if (isnext >= 0) { - std::vector* strips = mStripsCurrent; - o2::dataformats::MCTruthContainer* mcTruthContainer = mMCTruthContainerCurrent; - - if (isnext) { - strips = mStripsNext[isnext - 1]; - mcTruthContainer = mMCTruthContainerNext[isnext - 1]; - } - - int trackID = mFutureItrackID[digit.getLabel()]; - int sourceID = mFutureIsource[digit.getLabel()]; - int eventID = mFutureIevent[digit.getLabel()]; - fillDigitsInStrip(strips, mcTruthContainer, digit.getChannel(), digit.getTDC(), digit.getTOT(), digit.getBC(), digit.getChannel() / Geo::NPADS, trackID, eventID, sourceID); + std::vector* strips = mStripsCurrent; + o2::dataformats::MCTruthContainer* mcTruthContainer = mMCTruthContainerCurrent; + + if (isnext) { + strips = mStripsNext[isnext - 1]; + mcTruthContainer = mMCTruthContainerNext[isnext - 1]; + } + + int trackID = mFutureItrackID[digit.getLabel()]; + int sourceID = mFutureIsource[digit.getLabel()]; + int eventID = mFutureIevent[digit.getLabel()]; + fillDigitsInStrip(strips, mcTruthContainer, digit.getChannel(), digit.getTDC(), digit.getTOT(), digit.getBC(), digit.getChannel() / Geo::NPADS, trackID, eventID, sourceID); } - + // remove the element from the buffers mFutureItrackID.erase(mFutureItrackID.begin() + digit.getLabel()); mFutureIsource.erase(mFutureIsource.begin() + digit.getLabel()); mFutureIevent.erase(mFutureIevent.begin() + digit.getLabel()); - + int labelremoved = digit.getLabel(); // adjust labels for (auto& digit2 : mFutureDigits) { - if (digit2.getLabel() > labelremoved) - digit2.setLabel(digit2.getLabel() - 1); + if (digit2.getLabel() > labelremoved) + digit2.setLabel(digit2.getLabel() - 1); } // remove also digit from buffer mFutureDigits.erase(mFutureDigits.begin() + idigit); - } - else { + } else { idigit++; // increment when moving to the next only if the current is not removed from the buffer - } + } } // close future digit loop } diff --git a/Detectors/TOF/simulation/src/Strip.cxx b/Detectors/TOF/simulation/src/Strip.cxx index 492d5beae3e2e..02b9a55e8f8db 100644 --- a/Detectors/TOF/simulation/src/Strip.cxx +++ b/Detectors/TOF/simulation/src/Strip.cxx @@ -66,7 +66,7 @@ Int_t Strip::addDigit(Int_t channel, Int_t tdc, Int_t tot, Int_t bc, Int_t lbl) auto dig = findDigit(key); if (dig) { lbl = dig->getLabel(); // getting the label from the already existing digit - dig->merge(tdc, tot); // merging to the existing digit + dig->merge(tdc, tot); // merging to the existing digit } else { auto digIter = mDigits.emplace(std::make_pair(key, Digit(channel, tdc, tot, bc, lbl))); } diff --git a/Generators/src/GeneratorFactory.cxx b/Generators/src/GeneratorFactory.cxx index 89bfa2456ea50..b13474a89f343 100644 --- a/Generators/src/GeneratorFactory.cxx +++ b/Generators/src/GeneratorFactory.cxx @@ -178,14 +178,14 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair primGen->AddGenerator(tgen); } else if (genconfig.compare("toftest") == 0) { // 1 muon per sector and per module LOG(INFO) << "Init tof test generator -> 1 muon per sector and per module"; - for(int i=0;i<18;i++){ - for(int j=0;j<5;j++){ - auto boxGen = new FairBoxGenerator(13, 1); /*protons*/ - boxGen->SetEtaRange(-0.8+0.32*j+0.15,-0.8+0.32*j + 0.17); - boxGen->SetPRange(9, 10); - boxGen->SetPhiRange(10+20.*i-1, 10+20.*i +1); - boxGen->SetDebug(kTRUE); - primGen->AddGenerator(boxGen); + for (int i = 0; i < 18; i++) { + for (int j = 0; j < 5; j++) { + auto boxGen = new FairBoxGenerator(13, 1); /*protons*/ + boxGen->SetEtaRange(-0.8 + 0.32 * j + 0.15, -0.8 + 0.32 * j + 0.17); + boxGen->SetPRange(9, 10); + boxGen->SetPhiRange(10 + 20. * i - 1, 10 + 20. * i + 1); + boxGen->SetDebug(kTRUE); + primGen->AddGenerator(boxGen); } } } else { diff --git a/Steer/DigitizerWorkflow/src/TOFClusterizerSpec.cxx b/Steer/DigitizerWorkflow/src/TOFClusterizerSpec.cxx index 66114477e7a2d..cb341f0d4ba93 100644 --- a/Steer/DigitizerWorkflow/src/TOFClusterizerSpec.cxx +++ b/Steer/DigitizerWorkflow/src/TOFClusterizerSpec.cxx @@ -55,11 +55,11 @@ class TOFDPLClustererTask mClustersArray.clear(); mClsLabels.clear(); - for(int i=0;i < digits->size();i++){ - printf("# TOF readout window for clusterization = %i\n",i); - auto digitsRO = digits->at(i); - mReader.setDigitArray(&digitsRO); - mClusterer.process(mReader, mClustersArray, &(digitlabels->at(i))); + for (int i = 0; i < digits->size(); i++) { + printf("# TOF readout window for clusterization = %i\n", i); + auto digitsRO = digits->at(i); + mReader.setDigitArray(&digitsRO); + mClusterer.process(mReader, mClustersArray, &(digitlabels->at(i))); } LOG(INFO) << "TOF CLUSTERER : TRANSFORMED " << digits->size() << " DIGITS TO " << mClustersArray.size() << " CLUSTERS"; diff --git a/Steer/DigitizerWorkflow/src/TOFDigitWriterSpec.cxx b/Steer/DigitizerWorkflow/src/TOFDigitWriterSpec.cxx index 332767d234ec3..c72f7682d3a9d 100644 --- a/Steer/DigitizerWorkflow/src/TOFDigitWriterSpec.cxx +++ b/Steer/DigitizerWorkflow/src/TOFDigitWriterSpec.cxx @@ -86,8 +86,8 @@ DataProcessorSpec getTOFDigitWriterSpec() // retrieve labels from the input auto labeldata = pc.inputs().get>*>("tofdigitlabels"); - for(int i=0;isize();i++){ - LOG(INFO) << "TOF GOT " << labeldata->at(i).getNElements() << " LABELS "; + for (int i = 0; i < labeldata->size(); i++) { + LOG(INFO) << "TOF GOT " << labeldata->at(i).getNElements() << " LABELS "; } auto labeldataraw = labeldata.get(); // connect this to a particular branch diff --git a/Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx b/Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx index 9c27a585542a0..d563dd97dffd3 100644 --- a/Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx +++ b/Steer/DigitizerWorkflow/src/TOFDigitizerSpec.cxx @@ -131,9 +131,9 @@ DataProcessorSpec getTOFDigitizerSpec(int channel) // temporary accumulate vector of vecotors of digits in a single vector // to be replace once we will be able to write the vector of vectors as different TTree entries - std::vector< std::vector>* digitsVectOfVect = digitizer->getDigitPerTimeFrame(); - std::vector >* mcLabVecOfVec = digitizer->getMCTruthPerTimeFrame(); - for(Int_t i=0; i < digitsVectOfVect->size();i++){ + std::vector>* digitsVectOfVect = digitizer->getDigitPerTimeFrame(); + std::vector>* mcLabVecOfVec = digitizer->getMCTruthPerTimeFrame(); + for (Int_t i = 0; i < digitsVectOfVect->size(); i++) { std::copy(digitsVectOfVect->at(i).begin(), digitsVectOfVect->at(i).end(), std::back_inserter(*digitsAccum.get())); labelAccum.mergeAtBack(mcLabVecOfVec->at(i)); } diff --git a/macro/checkTOFMatching.C b/macro/checkTOFMatching.C index 0686028d2581a..fba15edf5b890 100644 --- a/macro/checkTOFMatching.C +++ b/macro/checkTOFMatching.C @@ -1,4 +1,5 @@ -void checkTOFMatching(){ +void checkTOFMatching() +{ // macro to check the matching TOF-ITSTPC tracks @@ -12,12 +13,12 @@ void checkTOFMatching(){ // getting the ITSTPCtracks TFile* fmatchITSTPC = new TFile("o2match_itstpc.root"); TTree* matchTPCITS = (TTree*)fmatchITSTPC->Get("matchTPCITS"); - std::vector* mTracksArrayInp = new std::vector; + std::vector* mTracksArrayInp = new std::vector; matchTPCITS->SetBranchAddress("TPCITS", &mTracksArrayInp); // getting the TPC tracks TFile* ftracksTPC = new TFile("tpctracks.root"); - TTree* tpcTree = (TTree*) ftracksTPC->Get("events"); + TTree* tpcTree = (TTree*)ftracksTPC->Get("events"); std::vector* mTPCTracksArrayInp = new std::vector; tpcTree->SetBranchAddress("TPCTracks", &mTPCTracksArrayInp); o2::dataformats::MCTruthContainer* mcTPC = new o2::dataformats::MCTruthContainer(); @@ -25,7 +26,7 @@ void checkTOFMatching(){ // getting the ITS tracks TFile* ftracksITS = new TFile("o2trac_its.root"); - TTree* itsTree = (TTree*) ftracksITS->Get("o2sim"); + TTree* itsTree = (TTree*)ftracksITS->Get("o2sim"); std::vector* mITSTracksArrayInp = new std::vector; itsTree->SetBranchAddress("ITSTrack", &mITSTracksArrayInp); o2::dataformats::MCTruthContainer* mcITS = new o2::dataformats::MCTruthContainer(); @@ -33,12 +34,12 @@ void checkTOFMatching(){ // getting the TOF clusters TFile* fclustersTOF = new TFile("tofclusters.root"); - TTree* tofClTree = (TTree*) fclustersTOF->Get("o2sim"); + TTree* tofClTree = (TTree*)fclustersTOF->Get("o2sim"); std::vector* mTOFClustersArrayInp = new std::vector; tofClTree->SetBranchAddress("TOFCluster", &mTOFClustersArrayInp); o2::dataformats::MCTruthContainer* mcTOF = new o2::dataformats::MCTruthContainer(); tofClTree->SetBranchAddress("TOFClusterMCTruth", &mcTOF); - + tpcTree->GetEntry(0); tofClTree->GetEntry(0); @@ -47,12 +48,12 @@ void checkTOFMatching(){ int nBadMatches = 0; // now looping over the entries in the matching tree - for (int ientry = 0; ientry < matchTOF->GetEntries(); ientry++){ + for (int ientry = 0; ientry < matchTOF->GetEntries(); ientry++) { matchTOF->GetEvent(ientry); matchTPCITS->GetEntry(ientry); // now looping over the matched tracks nMatches += TOFMatchInfo->size(); - for (int imatch = 0; imatch < TOFMatchInfo->size(); imatch++){ + for (int imatch = 0; imatch < TOFMatchInfo->size(); imatch++) { int indexITSTPCtrack = TOFMatchInfo->at(imatch).first; o2::dataformats::MatchInfoTOF infoTOF = TOFMatchInfo->at(imatch).second; int tofClIndex = infoTOF.getTOFClIndex(); @@ -64,13 +65,13 @@ void checkTOFMatching(){ int trackIdTOF; int eventIdTOF; int sourceIdTOF; - for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++){ - Printf("TOF label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTOF[ilabel].getTrackID(), labelsTOF[ilabel].getEventID(), labelsTOF[ilabel].getSourceID()); - if (ilabel == 0){ - trackIdTOF = labelsTOF[ilabel].getTrackID(); - eventIdTOF = labelsTOF[ilabel].getEventID(); - sourceIdTOF = labelsTOF[ilabel].getSourceID(); - } + for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++) { + Printf("TOF label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTOF[ilabel].getTrackID(), labelsTOF[ilabel].getEventID(), labelsTOF[ilabel].getSourceID()); + if (ilabel == 0) { + trackIdTOF = labelsTOF[ilabel].getTrackID(); + eventIdTOF = labelsTOF[ilabel].getEventID(); + sourceIdTOF = labelsTOF[ilabel].getSourceID(); + } } o2::tof::Cluster tofCluster = mTOFClustersArrayInp->at(tofClIndex); int nContributingChannels = tofCluster.getNumOfContributingChannels(); @@ -81,101 +82,99 @@ void checkTOFMatching(){ Printf("Indices of main contributing channel are %d, %d, %d, %d, %d", indices[0], indices[1], indices[2], indices[3], indices[4]); int* secondaryContributingChannels = new int[nContributingChannels]; for (int ich = 1; ich < nContributingChannels; ich++) { - bool isUpLeft = tofCluster.isUpLeftContributing(); - bool isUp = tofCluster.isUpContributing(); - bool isUpRight = tofCluster.isUpRightContributing(); - bool isRight = tofCluster.isRightContributing(); - bool isDownRight = tofCluster.isDownRightContributing(); - bool isDown = tofCluster.isDownContributing(); - bool isDownLeft = tofCluster.isDownLeftContributing(); - bool isLeft = tofCluster.isLeftContributing(); - Printf("isUpLeft = %d, isUp = %d, isUpRight = %d, isRight = %d, isDownRight = %d, isDown = %d, isDownLeft = %d, isLeft = %d", isUpLeft, isUp, isUpRight, isRight, isDownRight, isDown, isDownLeft, isLeft); - int* indexCont = new int(); - indexCont[0] = indices[0]; - indexCont[1] = indices[1]; - indexCont[2] = indices[2]; - indexCont[3] = indices[3]; - indexCont[4] = indices[4]; - if (isDown || isDownRight || isDownLeft) { // decrease padZ - indexCont[3]--; - } - if (isUp || isUpRight || isUpLeft) { // decrease padZ - indexCont[3]++; - } - if (isRight || isDownRight || isUpRight) { // decrease padZ - indexCont[4]++; - } - if (isLeft || isDownLeft || isUpLeft) { // decrease padZ - indexCont[4]--; - } - secondaryContributingChannels[ich-1] = o2::tof::Geo::getIndex(indexCont); - Printf("secondaryContributingChannels[%d] = %d", ich-1, secondaryContributingChannels[ich-1]); + bool isUpLeft = tofCluster.isUpLeftContributing(); + bool isUp = tofCluster.isUpContributing(); + bool isUpRight = tofCluster.isUpRightContributing(); + bool isRight = tofCluster.isRightContributing(); + bool isDownRight = tofCluster.isDownRightContributing(); + bool isDown = tofCluster.isDownContributing(); + bool isDownLeft = tofCluster.isDownLeftContributing(); + bool isLeft = tofCluster.isLeftContributing(); + Printf("isUpLeft = %d, isUp = %d, isUpRight = %d, isRight = %d, isDownRight = %d, isDown = %d, isDownLeft = %d, isLeft = %d", isUpLeft, isUp, isUpRight, isRight, isDownRight, isDown, isDownLeft, isLeft); + int* indexCont = new int(); + indexCont[0] = indices[0]; + indexCont[1] = indices[1]; + indexCont[2] = indices[2]; + indexCont[3] = indices[3]; + indexCont[4] = indices[4]; + if (isDown || isDownRight || isDownLeft) { // decrease padZ + indexCont[3]--; + } + if (isUp || isUpRight || isUpLeft) { // decrease padZ + indexCont[3]++; + } + if (isRight || isDownRight || isUpRight) { // decrease padZ + indexCont[4]++; + } + if (isLeft || isDownLeft || isUpLeft) { // decrease padZ + indexCont[4]--; + } + secondaryContributingChannels[ich - 1] = o2::tof::Geo::getIndex(indexCont); + Printf("secondaryContributingChannels[%d] = %d", ich - 1, secondaryContributingChannels[ich - 1]); } o2::dataformats::TrackTPCITS trackITSTPC = mTracksArrayInp->at(indexITSTPCtrack); - const o2::dataformats::EvIndex &evIdxTPC = trackITSTPC.getRefTPC(); + const o2::dataformats::EvIndex& evIdxTPC = trackITSTPC.getRefTPC(); Printf("matched TPCtrack: eventID = %d, indexID = %d", evIdxTPC.getEvent(), evIdxTPC.getIndex()); - const o2::dataformats::EvIndex &evIdxITS = trackITSTPC.getRefITS(); + const o2::dataformats::EvIndex& evIdxITS = trackITSTPC.getRefITS(); Printf("matched ITStrack: eventID = %d, indexID = %d", evIdxITS.getEvent(), evIdxITS.getIndex()); itsTree->GetEntry(evIdxITS.getEvent()); // getting the TPC labels const auto& labelsTPC = mcTPC->getLabels(evIdxTPC.getIndex()); - for (int ilabel = 0; ilabel < labelsTPC.size(); ilabel++){ - Printf("TPC label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTPC[ilabel].getTrackID(), labelsTPC[ilabel].getEventID(), labelsTPC[ilabel].getSourceID()); + for (int ilabel = 0; ilabel < labelsTPC.size(); ilabel++) { + Printf("TPC label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsTPC[ilabel].getTrackID(), labelsTPC[ilabel].getEventID(), labelsTPC[ilabel].getSourceID()); } // getting the ITS labels const auto& labelsITS = mcITS->getLabels(evIdxITS.getIndex()); - for (int ilabel = 0; ilabel < labelsITS.size(); ilabel++){ - Printf("ITS label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsITS[ilabel].getTrackID(), labelsITS[ilabel].getEventID(), labelsITS[ilabel].getSourceID()); + for (int ilabel = 0; ilabel < labelsITS.size(); ilabel++) { + Printf("ITS label %d: trackID = %d, eventID = %d, sourceID = %d", ilabel, labelsITS[ilabel].getTrackID(), labelsITS[ilabel].getEventID(), labelsITS[ilabel].getSourceID()); } bool bMatched = kFALSE; - for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++){ - if ((labelsTPC[0].getTrackID() == labelsTOF[ilabel].getTrackID() && labelsTPC[0].getEventID() == labelsTOF[ilabel].getEventID() && labelsTPC[0].getSourceID() == labelsTOF[ilabel].getSourceID()) || (labelsITS[0].getTrackID() == labelsTOF[ilabel].getTrackID() && labelsITS[0].getEventID() == labelsTOF[ilabel].getEventID() && labelsITS[0].getSourceID() == labelsTOF[ilabel].getSourceID())) { - nGoodMatches++; - bMatched = kTRUE; - break; - } + for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++) { + if ((labelsTPC[0].getTrackID() == labelsTOF[ilabel].getTrackID() && labelsTPC[0].getEventID() == labelsTOF[ilabel].getEventID() && labelsTPC[0].getSourceID() == labelsTOF[ilabel].getSourceID()) || (labelsITS[0].getTrackID() == labelsTOF[ilabel].getTrackID() && labelsITS[0].getEventID() == labelsTOF[ilabel].getEventID() && labelsITS[0].getSourceID() == labelsTOF[ilabel].getSourceID())) { + nGoodMatches++; + bMatched = kTRUE; + break; + } } - if (!bMatched) nBadMatches++; - + if (!bMatched) + nBadMatches++; + bool TPCfound = false; bool ITSfound = false; - for (int i = 0; i < mTracksArrayInp->size(); i++){ - o2::dataformats::TrackTPCITS trackITSTPC = mTracksArrayInp->at(i); - const o2::dataformats::EvIndex &evIdxTPCcheck = trackITSTPC.getRefTPC(); - const o2::dataformats::EvIndex &evIdxITScheck = trackITSTPC.getRefITS(); - itsTree->GetEntry(evIdxITScheck.getEvent()); - const auto& labelsTPCcheck = mcTPC->getLabels(evIdxTPCcheck.getIndex()); - for (int ilabel = 0; ilabel < labelsTPCcheck.size(); ilabel++){ - if (labelsTPCcheck[ilabel].getTrackID() == trackIdTOF && labelsTPCcheck[ilabel].getEventID() == eventIdTOF && labelsTPCcheck[ilabel].getSourceID() == sourceIdTOF){ - Printf("The TPC track that should have been matched to TOF is number %d", i); - TPCfound = true; - } - } - const auto& labelsITScheck = mcITS->getLabels(evIdxITScheck.getIndex()); - for (int ilabel = 0; ilabel < labelsITScheck.size(); ilabel++){ - if (labelsITScheck[ilabel].getTrackID() == trackIdTOF && labelsITScheck[ilabel].getEventID() == eventIdTOF && labelsITScheck[ilabel].getSourceID() == sourceIdTOF){ - Printf("The ITS track that should have been matched to TOF is number %d", i); - ITSfound = true; - } - } + for (int i = 0; i < mTracksArrayInp->size(); i++) { + o2::dataformats::TrackTPCITS trackITSTPC = mTracksArrayInp->at(i); + const o2::dataformats::EvIndex& evIdxTPCcheck = trackITSTPC.getRefTPC(); + const o2::dataformats::EvIndex& evIdxITScheck = trackITSTPC.getRefITS(); + itsTree->GetEntry(evIdxITScheck.getEvent()); + const auto& labelsTPCcheck = mcTPC->getLabels(evIdxTPCcheck.getIndex()); + for (int ilabel = 0; ilabel < labelsTPCcheck.size(); ilabel++) { + if (labelsTPCcheck[ilabel].getTrackID() == trackIdTOF && labelsTPCcheck[ilabel].getEventID() == eventIdTOF && labelsTPCcheck[ilabel].getSourceID() == sourceIdTOF) { + Printf("The TPC track that should have been matched to TOF is number %d", i); + TPCfound = true; + } + } + const auto& labelsITScheck = mcITS->getLabels(evIdxITScheck.getIndex()); + for (int ilabel = 0; ilabel < labelsITScheck.size(); ilabel++) { + if (labelsITScheck[ilabel].getTrackID() == trackIdTOF && labelsITScheck[ilabel].getEventID() == eventIdTOF && labelsITScheck[ilabel].getSourceID() == sourceIdTOF) { + Printf("The ITS track that should have been matched to TOF is number %d", i); + ITSfound = true; + } + } } - if (!TPCfound) Printf("There is no TPC track found that should have corresponded to this TOF cluster!"); - if (!ITSfound) Printf("There is no ITS track found that should have corresponded to this TOF cluster!"); + if (!TPCfound) + Printf("There is no TPC track found that should have corresponded to this TOF cluster!"); + if (!ITSfound) + Printf("There is no ITS track found that should have corresponded to this TOF cluster!"); } - } - Printf("Number of matches = %d", nMatches); - Printf("Number of GOOD matches = %d (%.2f)", nGoodMatches, (float)nGoodMatches/nMatches); - Printf("Number of BAD matches = %d (%.2f)", nBadMatches, (float)nBadMatches/nMatches); + Printf("Number of matches = %d", nMatches); + Printf("Number of GOOD matches = %d (%.2f)", nGoodMatches, (float)nGoodMatches / nMatches); + Printf("Number of BAD matches = %d (%.2f)", nBadMatches, (float)nBadMatches / nMatches); - return; } - - - diff --git a/macro/run_match_tof.C b/macro/run_match_tof.C index d9ceed40806b8..e7adf4799e628 100644 --- a/macro/run_match_tof.C +++ b/macro/run_match_tof.C @@ -17,10 +17,10 @@ #define _ALLOW_DEBUG_TREES_ // to allow debug and control tree output void run_match_tof(std::string path = "./", std::string outputfile = "o2match_tof.root", - std::string inputTracksTPCITS = "o2match_itstpc.root", - std::string inputTracksTPC = "tpctracks.root", - std::string inputClustersTOF = "tofclusters.root", std::string inputGeom = "O2geometry.root", - std::string inputGRP = "o2sim_grp.root") + std::string inputTracksTPCITS = "o2match_itstpc.root", + std::string inputTracksTPC = "tpctracks.root", + std::string inputClustersTOF = "tofclusters.root", std::string inputGeom = "O2geometry.root", + std::string inputGRP = "o2sim_grp.root") { o2::globaltracking::MatchTOF matching; @@ -38,7 +38,7 @@ void run_match_tof(std::string path = "./", std::string outputfile = "o2match_to tpcTracks.AddFile((path + inputTracksTPC).data()); matching.setInputTreeTPCTracks(&tpcTracks); matching.setTPCTrackBranchName("TPCTracks"); - + TChain tofClusters("o2sim"); tofClusters.AddFile((path + inputClustersTOF).data()); matching.setInputTreeTOFClusters(&tofClusters); From d7c26a546d48da2b6bf3062f584cbf40e368fbcc Mon Sep 17 00:00:00 2001 From: zampolli Date: Mon, 26 Nov 2018 15:51:50 +0100 Subject: [PATCH 27/39] Some replies to comments to the PR implemented --- .../ReconstructionDataFormats/MatchInfoTOF.h | 4 ++-- .../Reconstruction/src/MatchInfoTOF.cxx | 4 ++-- .../include/GlobalTracking/MatchTOF.h | 2 -- Detectors/GlobalTracking/src/MatchTOF.cxx | 21 ------------------- 4 files changed, 4 insertions(+), 27 deletions(-) diff --git a/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h b/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h index 73d8f9a6bf187..0d0cfdbd10869 100644 --- a/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h +++ b/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h @@ -8,8 +8,8 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -/// \file Cluster.h -/// \brief Definition of the TOF cluster +/// \file MatchInfoTOF.h +/// \brief Class to store the output of the matching to TOF #ifndef ALICEO2_MATCHINFOTOF_H #define ALICEO2_MATCHINFOTOF_H diff --git a/DataFormats/Reconstruction/src/MatchInfoTOF.cxx b/DataFormats/Reconstruction/src/MatchInfoTOF.cxx index 7c4b6eb63c357..0dabe8ae8a42e 100644 --- a/DataFormats/Reconstruction/src/MatchInfoTOF.cxx +++ b/DataFormats/Reconstruction/src/MatchInfoTOF.cxx @@ -8,8 +8,8 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -/// \file Cluster.cxx -/// \brief Implementation of the TOF cluster +/// \file MatchInfoTOF.cxx +/// \brief Class to store the output of the matching to TOF #include "ReconstructionDataFormats/MatchInfoTOF.h" diff --git a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h index 6d94f2e455f7e..55f05e8b50dd1 100644 --- a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h +++ b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h @@ -158,9 +158,7 @@ class MatchTOF bool prepareTracks(); bool prepareTOFClusters(); bool loadTracksNextChunk(); - void loadTracksChunk(int chunk); bool loadTOFClustersNextChunk(); - void loadTOFClustersChunk(int chunk); void doMatching(int sec); void selectBestMatches(); diff --git a/Detectors/GlobalTracking/src/MatchTOF.cxx b/Detectors/GlobalTracking/src/MatchTOF.cxx index 1b3b16948c9a5..8412bdee0dc9a 100644 --- a/Detectors/GlobalTracking/src/MatchTOF.cxx +++ b/Detectors/GlobalTracking/src/MatchTOF.cxx @@ -401,17 +401,6 @@ bool MatchTOF::loadTracksNextChunk() --mCurrTracksTreeEntry; return false; } -//______________________________________________ -void MatchTOF::loadTracksChunk(int chunk) -{ - ///< load the next chunk of tracks to be matched to TOF (chunk = timeframe? to be checked) - - // load single entry from tracks tree - if (mCurrTracksTreeEntry != chunk) { - mInputTreeTracks->GetEntry(mCurrTracksTreeEntry = chunk); - } -} - //______________________________________________ bool MatchTOF::loadTOFClustersNextChunk() { @@ -432,16 +421,6 @@ bool MatchTOF::loadTOFClustersNextChunk() return false; } //______________________________________________ -void MatchTOF::loadTOFClustersChunk(int chunk) -{ - ///< load the next chunk of TOF clusters for the matching (chunk = timeframe? to be checked) - - // load single entry from TOF clusters tree - if (mCurrTOFClustersTreeEntry != chunk) { - mTreeTOFClusters->GetEntry(mCurrTOFClustersTreeEntry = chunk); - } -} -//______________________________________________ void MatchTOF::doMatching(int sec) { ///< do the real matching per sector From db47a36732c8043caaf4d3a843fd936837966faf Mon Sep 17 00:00:00 2001 From: zampolli Date: Tue, 27 Nov 2018 10:51:30 +0100 Subject: [PATCH 28/39] Fix for compilation on mac --- Detectors/TOF/simulation/src/Digitizer.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/TOF/simulation/src/Digitizer.cxx b/Detectors/TOF/simulation/src/Digitizer.cxx index d4469c0c69f40..12da7184282d3 100644 --- a/Detectors/TOF/simulation/src/Digitizer.cxx +++ b/Detectors/TOF/simulation/src/Digitizer.cxx @@ -693,7 +693,7 @@ void Digitizer::fillOutputContainer(std::vector& digits) if (mContinuous) { if (digits.size()) - printf("%i) # TOF digits = %i (%x)\n", mIcurrentReadoutWindow, digits.size(), mStripsCurrent); + printf("%i) # TOF digits = %lu (%p)\n", mIcurrentReadoutWindow, digits.size(), mStripsCurrent); mDigitsPerTimeFrame.push_back(digits); } From 4c27d561e32f2535d773ba2f4a95f1992572dec3 Mon Sep 17 00:00:00 2001 From: zampolli Date: Tue, 27 Nov 2018 15:11:05 +0100 Subject: [PATCH 29/39] Another fix for mac compilation - of course they are incremental fixes... --- Detectors/TOF/simulation/src/Digitizer.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/TOF/simulation/src/Digitizer.cxx b/Detectors/TOF/simulation/src/Digitizer.cxx index 12da7184282d3..2f308fb31da86 100644 --- a/Detectors/TOF/simulation/src/Digitizer.cxx +++ b/Detectors/TOF/simulation/src/Digitizer.cxx @@ -58,7 +58,7 @@ void Digitizer::process(const std::vector* hits, std::vector* di if (mContinuous && readoutwindow > mReadoutWindowCurrent) { // if we are moving in future readout windows flush previous ones (only for continuous readout mode) digits->clear(); - for (mReadoutWindowCurrent; mReadoutWindowCurrent < readoutwindow; mReadoutWindowCurrent++) { + for (; mReadoutWindowCurrent < readoutwindow; mReadoutWindowCurrent++) { fillOutputContainer(*digits); // fill all windows which are before (not yet stored) of the new current one checkIfReuseFutureDigits(); } // close loop readout window From 5ceab1d9c05a73a3f12cff9883075e0254e4d1f8 Mon Sep 17 00:00:00 2001 From: zampolli Date: Tue, 27 Nov 2018 15:17:11 +0100 Subject: [PATCH 30/39] Making the tan of the width of a sector a constant --- Detectors/GlobalTracking/src/MatchTOF.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Detectors/GlobalTracking/src/MatchTOF.cxx b/Detectors/GlobalTracking/src/MatchTOF.cxx index 8412bdee0dc9a..28dfd3cf126d3 100644 --- a/Detectors/GlobalTracking/src/MatchTOF.cxx +++ b/Detectors/GlobalTracking/src/MatchTOF.cxx @@ -701,6 +701,7 @@ void MatchTOF::selectBestMatches() bool MatchTOF::propagateToRefX(o2::track::TrackParCov& trc, float xRef, float stepInCm) { // propagate track to matching reference X + const float tanHalfSector = tan(o2::constants::math::SectorSpanRad / 2); bool refReached = false; float xStart = trc.getX(); // the first propagation will be from 2m, if the track is not at least at 2m @@ -713,7 +714,7 @@ bool MatchTOF::propagateToRefX(o2::track::TrackParCov& trc, float xRef, float st refReached = true; // we reached the 371cm reference } istep++; - if (fabs(trc.getY()) > trc.getX() * tan(o2::constants::math::SectorSpanRad / 2)) { // we are still in the same sector + if (fabs(trc.getY()) > trc.getX() * tanHalfSector) { // we are still in the same sector // we need to rotate the track to go to the new sector //Printf("propagateToRefX: changing sector"); auto alphaNew = o2::utils::Angle2Alpha(trc.getPhiPos()); From ebc5d7eb33170cab9ad632807edd7077249b9ae1 Mon Sep 17 00:00:00 2001 From: zampolli Date: Tue, 27 Nov 2018 15:38:04 +0100 Subject: [PATCH 31/39] Following suggestion during PR - don't calculate sector, phi, r every time Adding also a fix in a method name. --- .../TOF/include/DataFormatsTOF/Cluster.h | 15 ++++++++------- DataFormats/Detectors/TOF/src/Cluster.cxx | 6 ++++-- Detectors/TOF/reconstruction/src/Clusterer.cxx | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h b/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h index 38d8a8d57ae46..cd44b787888ca 100644 --- a/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h +++ b/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h @@ -46,7 +46,7 @@ class Cluster : public o2::BaseCluster ~Cluster() = default; - void SetBaseData(std::int16_t sensid, float x, float y, float z, float sy2, float sz2, float syz); + void setBaseData(std::int16_t sensid, float x, float y, float z, float sy2, float sz2, float syz); double getTimeRaw() const { return mTimeRaw; } // Cluster ToF getter void setTimeRaw(double timeRaw) { mTimeRaw = timeRaw; } // Cluster ToF setter @@ -59,9 +59,9 @@ class Cluster : public o2::BaseCluster int getDeltaBC() const { return mDeltaBC; }; // deltaBC void setDeltaBC(int value) { mDeltaBC = value; }; // deltaBC //float getZ() const {return mZ;} // Cluster Z - already in the definition of the cluster - float getR() const { return TMath::Sqrt(getX() * getX() + getY() * getY() + getZ() * getZ()); } // Cluster Radius - float getPhi() const { return TMath::ATan2(getY(), getX()); } // Cluster Phi - int getSector() const { return int((TMath::ATan2(-getY(), -getX()) + TMath::Pi()) * TMath::RadToDeg() * 0.05); } // Cluster Sector + float getR() { if (mR > 9990) mR = TMath::Sqrt(getX() * getX() + getY() * getY() + getZ() * getZ()); return mR; } // Cluster Radius + float getPhi() {if (mPhi > 9990) mPhi = TMath::ATan2(getY(), getX()); return mPhi; } // Cluster Phi + int getSector() {if (mSector == -1) mSector = (TMath::ATan2(-getY(), -getX()) + TMath::Pi()) * TMath::RadToDeg() * 0.05; return mSector; } // Cluster Sector int getContributingChannels() const { return mContributingChannels; } void setContributingChannels(int contributingChannels) { mContributingChannels = contributingChannels; } @@ -115,8 +115,9 @@ class Cluster : public o2::BaseCluster int mL0L1Latency; // L0L1 latency // CZ: is it different per cluster? Checking one ESD file, it seems that it is always the same (see: /alice/data/2017/LHC17n/000280235/pass1/17000280235019.100/AliESDs.root) int mDeltaBC; // DeltaBC --> can it be a char or short? // CZ: is it different per cluster? Checking one ESD file, it seems that it can vary (see: /alice/data/2017/LHC17n/000280235/pass1/17000280235019.100/AliESDs.root) //float mZ; //! z-coordinate // CZ: to be verified if it is the same in the BaseCluster class - float mR; //! radius - float mPhi; //! phi coordinate + float mR = 9999.; //! radius + float mPhi = 9999.; //! phi coordinate + int mSector = -1; //! sector number int mContributingChannels; // index of the channels that contributed to the cluster; to be read like this: // channel & 0x3FFFF -> first 18 bits to store the main channel // channel & bit19 (0x40000) -> alsoUPLEFT @@ -131,7 +132,7 @@ class Cluster : public o2::BaseCluster ClassDefNV(Cluster, 1); }; -std::ostream& operator<<(std::ostream& os, const Cluster& c); +std::ostream& operator<<(std::ostream& os, Cluster& c); } // namespace TOF } // namespace o2 #endif diff --git a/DataFormats/Detectors/TOF/src/Cluster.cxx b/DataFormats/Detectors/TOF/src/Cluster.cxx index 5b58d527d2cf8..f25298a7c91ce 100644 --- a/DataFormats/Detectors/TOF/src/Cluster.cxx +++ b/DataFormats/Detectors/TOF/src/Cluster.cxx @@ -28,9 +28,10 @@ Cluster::Cluster(std::int16_t sensid, float x, float y, float z, float sy2, floa // caching R and phi mR = TMath::Sqrt(x * x + y * y); mPhi = TMath::ATan2(y, x); + mSector = (TMath::ATan2(-getY(), -getX()) + TMath::Pi()) * TMath::RadToDeg() * 0.05; } //______________________________________________________________________ -void Cluster::SetBaseData(std::int16_t sensid, float x, float y, float z, float sy2, float sz2, float syz) +void Cluster::setBaseData(std::int16_t sensid, float x, float y, float z, float sy2, float sz2, float syz) { setSensorID(sensid); setXYZ(x, y, z); @@ -39,6 +40,7 @@ void Cluster::SetBaseData(std::int16_t sensid, float x, float y, float z, float // caching R and phi mR = TMath::Sqrt(x * x + y * y); mPhi = TMath::ATan2(y, x); + mSector = (TMath::ATan2(-getY(), -getX()) + TMath::Pi()) * TMath::RadToDeg() * 0.05; } //______________________________________________________________________ int Cluster::getNumOfContributingChannels() const @@ -72,7 +74,7 @@ int Cluster::getNumOfContributingChannels() const } //______________________________________________________________________ -std::ostream& operator<<(std::ostream& os, const Cluster& c) +std::ostream& operator<<(std::ostream& os, Cluster& c) { os << (o2::BaseCluster&)c; os << " TOF cluster: raw time = " << std::scientific << c.getTimeRaw() << ", time = " << std::scientific << c.getTime() << ", Tot = " << std::scientific << c.getTot() << ", L0L1Latency = " << c.getL0L1Latency() << ", deltaBC = " << c.getDeltaBC() << ", R = " << c.getR() << ", mPhi = " << c.getPhi() << ", ContributingChannels = " << c.getNumOfContributingChannels() << "\n"; diff --git a/Detectors/TOF/reconstruction/src/Clusterer.cxx b/Detectors/TOF/reconstruction/src/Clusterer.cxx index 10d2bc1aadf27..a276e4f340cbc 100644 --- a/Detectors/TOF/reconstruction/src/Clusterer.cxx +++ b/Detectors/TOF/reconstruction/src/Clusterer.cxx @@ -202,7 +202,7 @@ void Clusterer::buildCluster(Cluster& c, MCLabelContainer const* digitMCTruth) Geo::getVolumeIndices(c.getMainContributingChannel(), det); float pos[3]; Geo::getPos(det, pos); - c.SetBaseData(c.getMainContributingChannel(), pos[0], pos[1], pos[2], 0, 0, 0); // error on position set to zero + c.setBaseData(c.getMainContributingChannel(), pos[0], pos[1], pos[2], 0, 0, 0); // error on position set to zero return; } From 9e3b9d73466d348a8bd927d27f6c7eed6fddbf37 Mon Sep 17 00:00:00 2001 From: zampolli Date: Wed, 5 Dec 2018 15:16:42 +0100 Subject: [PATCH 32/39] fixes for build/o2checkcode/o2 --- Detectors/GlobalTracking/src/MatchTOF.cxx | 14 +++++++------- .../include/TOFReconstruction/Clusterer.h | 2 +- Detectors/TOF/reconstruction/src/Clusterer.cxx | 6 ------ .../simulation/include/TOFSimulation/Digitizer.h | 2 +- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/Detectors/GlobalTracking/src/MatchTOF.cxx b/Detectors/GlobalTracking/src/MatchTOF.cxx index 28dfd3cf126d3..b7dfae1b96fe3 100644 --- a/Detectors/GlobalTracking/src/MatchTOF.cxx +++ b/Detectors/GlobalTracking/src/MatchTOF.cxx @@ -68,13 +68,13 @@ void MatchTOF::run() // printing the tracks std::array globalPosTmp; int totTracks = 0; - /* + for (int sec = o2::constants::math::NSectors; sec--;) { - Printf("\nsector %d", sec); + Printf("\nsector %d", sec); auto& cacheTrkTmp = mTracksSectIndexCache[sec]; // array of cached tracks indices for this sector; reminder: they are ordered in time! for (int itrk = 0; itrk < cacheTrkTmp.size(); itrk++){ auto& trc = mTracksWork[cacheTrkTmp[itrk]]; - trc.getXYZGlo(globalPosTmp); + trc.getXYZGlo(globalPosTmp); LOG(INFO) << "Track" << totTracks << " [in this sector it is the " << itrk << "]: Global coordinates After propagating to 371 cm: globalPos[0] = " << globalPosTmp[0] << ", globalPos[1] = " << globalPosTmp[1] << ", globalPos[2] = " << globalPosTmp[2]; LOG(INFO) << "The phi angle is " << TMath::ATan2(globalPosTmp[1], globalPosTmp[0]); totTracks++; @@ -405,7 +405,7 @@ bool MatchTOF::loadTracksNextChunk() bool MatchTOF::loadTOFClustersNextChunk() { ///< load next chunk of clusters to be matched to TOF - printf("Loading TOF clusters: number of entries in tree = %d\n", mTreeTOFClusters->GetEntries()); + printf("Loading TOF clusters: number of entries in tree = %lld\n", mTreeTOFClusters->GetEntries()); while (++mCurrTOFClustersTreeEntry < mTreeTOFClusters->GetEntries()) { mTreeTOFClusters->GetEntry(mCurrTOFClustersTreeEntry); LOG(DEBUG) << "Loading TOF clusters entry " << mCurrTOFClustersTreeEntry << " -> " << mTOFClustersArrayInp->size() @@ -603,8 +603,8 @@ void MatchTOF::doMatching(int sec) int eventIdTOF; int sourceIdTOF; for (auto iPropagation = 0; iPropagation < nStripsCrossedInPropagation; iPropagation++) { - LOG(DEBUG) << "TOF Cluster [" << itof << ", " << cacheTOF[itof] << "]: indices = " << indices[0], indices[1], indices[2], indices[3], indices[4]; - LOG(DEBUG) << "Propagated Track [" << itrk << ", " << cacheTrk[itrk] << "]: detId[" << iPropagation << "] = " << detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4]; + LOG(DEBUG) << "TOF Cluster [" << itof << ", " << cacheTOF[itof] << "]: indices = " << indices[0] << ", " << indices[1] << ", " << indices[2] << ", " << indices[3] << ", " << indices[4]; + LOG(DEBUG) << "Propagated Track [" << itrk << ", " << cacheTrk[itrk] << "]: detId[" << iPropagation << "] = " << detId[iPropagation][0] << ", " << detId[iPropagation][1] << ", " << detId[iPropagation][2] << ", " << detId[iPropagation][3] << ", " << detId[iPropagation][4]; float resX = deltaPos[iPropagation][0] - (indices[4] - detId[iPropagation][4]) * Geo::XPAD; // readjusting the residuals due to the fact that the propagation fell in a pad that was not exactly the one of the cluster float resZ = deltaPos[iPropagation][2] - (indices[3] - detId[iPropagation][3]) * Geo::ZPAD; // readjusting the residuals due to the fact that the propagation fell in a pad that was not exactly the one of the cluster float res = TMath::Sqrt(resX * resX + resZ * resZ); @@ -637,7 +637,7 @@ void MatchTOF::doMatching(int sec) if (res < mSpaceTolerance) { // matching ok! LOG(DEBUG) << "MATCHING FOUND: We have a match! between track " << mTracksSectIndexCache[indices[0]][itrk] << " and TOF cluster " << mTOFClusSectIndexCache[indices[0]][itof]; foundCluster = true; - mMatchedTracksPairs.push_back(std::make_pair(mTracksSectIndexCache[indices[0]][itrk], o2::dataformats::MatchInfoTOF(mTOFClusSectIndexCache[indices[0]][itof], chi2))); // TODO: check if this is correct! + mMatchedTracksPairs.emplace_back(std::make_pair(mTracksSectIndexCache[indices[0]][itrk], o2::dataformats::MatchInfoTOF(mTOFClusSectIndexCache[indices[0]][itof], chi2))); // TODO: check if this is correct! for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++) { LOG(DEBUG) << "TOF label " << ilabel << ": trackID = " << labelsTOF[ilabel].getTrackID() << ", eventID = " << labelsTOF[ilabel].getEventID() << ", sourceID = " << labelsTOF[ilabel].getSourceID(); } diff --git a/Detectors/TOF/reconstruction/include/TOFReconstruction/Clusterer.h b/Detectors/TOF/reconstruction/include/TOFReconstruction/Clusterer.h index 80a47b2b4a467..06de9d5df5424 100644 --- a/Detectors/TOF/reconstruction/include/TOFReconstruction/Clusterer.h +++ b/Detectors/TOF/reconstruction/include/TOFReconstruction/Clusterer.h @@ -34,7 +34,7 @@ class Clusterer using Digit = o2::tof::Digit; public: - Clusterer(); + Clusterer() = default; ~Clusterer() = default; Clusterer(const Clusterer&) = delete; diff --git a/Detectors/TOF/reconstruction/src/Clusterer.cxx b/Detectors/TOF/reconstruction/src/Clusterer.cxx index a276e4f340cbc..327a5f31711ed 100644 --- a/Detectors/TOF/reconstruction/src/Clusterer.cxx +++ b/Detectors/TOF/reconstruction/src/Clusterer.cxx @@ -19,12 +19,6 @@ using namespace o2::tof; -//__________________________________________________ -Clusterer::Clusterer() -{ - - // empty for now -} //__________________________________________________ void Clusterer::process(DataReader& reader, std::vector& clusters, MCLabelContainer const* digitMCTruth) { diff --git a/Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h b/Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h index 9d6b9ca1d4c1c..935153c92976e 100644 --- a/Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h +++ b/Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h @@ -90,7 +90,7 @@ class Digitizer Float_t mEffBoundary3; // info TOF timewindow - Int_t mReadoutWindowCurrent; + Int_t mReadoutWindowCurrent = 0; Double_t mEventTime; Int_t mEventID = 0; Int_t mSrcID = 0; From 054984f7681c5276d75a138ce205e114b1ec3937 Mon Sep 17 00:00:00 2001 From: zampolli Date: Wed, 5 Dec 2018 16:38:03 +0100 Subject: [PATCH 33/39] One more fix for the o2checkcode --- Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h b/Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h index 935153c92976e..9963cc4949583 100644 --- a/Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h +++ b/Detectors/TOF/simulation/include/TOFSimulation/Digitizer.h @@ -26,7 +26,7 @@ namespace tof class Digitizer { public: - Digitizer(Int_t mode = 0) : mMode(mode), mReadoutWindowCurrent(0) { init(); }; + Digitizer(Int_t mode = 0) : mMode(mode) { init(); }; ~Digitizer() = default; void init(); From 9292840f8d3840dd7020913ac411a40d9fe34920 Mon Sep 17 00:00:00 2001 From: zampolli Date: Thu, 6 Dec 2018 15:37:14 +0100 Subject: [PATCH 34/39] Updating debug printout --- Detectors/GlobalTracking/src/MatchTOF.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Detectors/GlobalTracking/src/MatchTOF.cxx b/Detectors/GlobalTracking/src/MatchTOF.cxx index b7dfae1b96fe3..c8d62d30fa543 100644 --- a/Detectors/GlobalTracking/src/MatchTOF.cxx +++ b/Detectors/GlobalTracking/src/MatchTOF.cxx @@ -523,7 +523,7 @@ void MatchTOF::doMatching(int sec) istep++; // check if after the propagation we are in a TOF strip if (detIdTemp[2] != -1) { // we ended in a TOF strip - LOG(DEBUG) << "nStripsCrossedInPropagation = " << nStripsCrossedInPropagation << ", detId[nStripsCrossedInPropagation-1][0] = " << detId[nStripsCrossedInPropagation - 1][0] << ", detIdTemp[0] = " << detIdTemp[0] << ", detId[nStripsCrossedInPropagation-1][1] = " << detId[nStripsCrossedInPropagation - 1][1] << ", detIdTemp[1] = " << detIdTemp[1] << ", detId[nStripsCrossedInPropagation-1][2] = " << detId[nStripsCrossedInPropagation - 1][2] << ", detIdTemp[2] = " << detIdTemp[2]; + LOG(DEBUG) << "nStripsCrossedInPropagation = " << nStripsCrossedInPropagation << ", detId[nStripsCrossedInPropagation][0] = " << detId[nStripsCrossedInPropagation][0] << ", detIdTemp[0] = " << detIdTemp[0] << ", detId[nStripsCrossedInPropagation][1] = " << detId[nStripsCrossedInPropagation][1] << ", detIdTemp[1] = " << detIdTemp[1] << ", detId[nStripsCrossedInPropagation][2] = " << detId[nStripsCrossedInPropagation][2] << ", detIdTemp[2] = " << detIdTemp[2]; if (nStripsCrossedInPropagation == 0 || // we are crossing a strip for the first time... (nStripsCrossedInPropagation >= 1 && (detId[nStripsCrossedInPropagation - 1][0] != detIdTemp[0] || detId[nStripsCrossedInPropagation - 1][1] != detIdTemp[1] || detId[nStripsCrossedInPropagation - 1][2] != detIdTemp[2]))) { // ...or we are crossing a new strip if (nStripsCrossedInPropagation == 0) From dc41dbc012927f5b8af17aaf25384dabd366498c Mon Sep 17 00:00:00 2001 From: zampolli Date: Fri, 7 Dec 2018 11:23:49 +0100 Subject: [PATCH 35/39] git-clang-format change --- .../TOF/include/DataFormatsTOF/Cluster.h | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h b/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h index cd44b787888ca..7487277eb8dbd 100644 --- a/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h +++ b/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h @@ -59,9 +59,24 @@ class Cluster : public o2::BaseCluster int getDeltaBC() const { return mDeltaBC; }; // deltaBC void setDeltaBC(int value) { mDeltaBC = value; }; // deltaBC //float getZ() const {return mZ;} // Cluster Z - already in the definition of the cluster - float getR() { if (mR > 9990) mR = TMath::Sqrt(getX() * getX() + getY() * getY() + getZ() * getZ()); return mR; } // Cluster Radius - float getPhi() {if (mPhi > 9990) mPhi = TMath::ATan2(getY(), getX()); return mPhi; } // Cluster Phi - int getSector() {if (mSector == -1) mSector = (TMath::ATan2(-getY(), -getX()) + TMath::Pi()) * TMath::RadToDeg() * 0.05; return mSector; } // Cluster Sector + float getR() + { + if (mR > 9990) + mR = TMath::Sqrt(getX() * getX() + getY() * getY() + getZ() * getZ()); + return mR; + } // Cluster Radius + float getPhi() + { + if (mPhi > 9990) + mPhi = TMath::ATan2(getY(), getX()); + return mPhi; + } // Cluster Phi + int getSector() + { + if (mSector == -1) + mSector = (TMath::ATan2(-getY(), -getX()) + TMath::Pi()) * TMath::RadToDeg() * 0.05; + return mSector; + } // Cluster Sector int getContributingChannels() const { return mContributingChannels; } void setContributingChannels(int contributingChannels) { mContributingChannels = contributingChannels; } @@ -115,7 +130,7 @@ class Cluster : public o2::BaseCluster int mL0L1Latency; // L0L1 latency // CZ: is it different per cluster? Checking one ESD file, it seems that it is always the same (see: /alice/data/2017/LHC17n/000280235/pass1/17000280235019.100/AliESDs.root) int mDeltaBC; // DeltaBC --> can it be a char or short? // CZ: is it different per cluster? Checking one ESD file, it seems that it can vary (see: /alice/data/2017/LHC17n/000280235/pass1/17000280235019.100/AliESDs.root) //float mZ; //! z-coordinate // CZ: to be verified if it is the same in the BaseCluster class - float mR = 9999.; //! radius + float mR = 9999.; //! radius float mPhi = 9999.; //! phi coordinate int mSector = -1; //! sector number int mContributingChannels; // index of the channels that contributed to the cluster; to be read like this: From 985afd1b9e55e75af355eb99be1a48ff6060727e Mon Sep 17 00:00:00 2001 From: zampolli Date: Tue, 11 Dec 2018 11:49:15 +0100 Subject: [PATCH 36/39] Addressing comments in PR1486 In particular we changed the propagation: now we go to 371 cm using only a TrackPar object, and using only the z component of the B field; if this succeeds, we propagate again considering the errors. --- .../TOF/include/DataFormatsTOF/Cluster.h | 16 +++-- .../include/GlobalTracking/MatchTOF.h | 3 +- Detectors/GlobalTracking/src/MatchTOF.cxx | 65 ++++++++++++++++--- 3 files changed, 69 insertions(+), 15 deletions(-) diff --git a/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h b/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h index 7487277eb8dbd..811546162597a 100644 --- a/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h +++ b/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h @@ -29,6 +29,9 @@ namespace tof class Cluster : public o2::BaseCluster { + static constexpr float RadiusOutOfRange = 9999; // used to check if the radius was already calculated or not + static constexpr float PhiOutOfRange = 9999; // used to check if phi was already calculated or not + public: enum { kMain = 0x3FFFF, kUpLeft = 0x40000, // 2^18, 19th bit @@ -61,20 +64,23 @@ class Cluster : public o2::BaseCluster //float getZ() const {return mZ;} // Cluster Z - already in the definition of the cluster float getR() { - if (mR > 9990) + if (mR == RadiusOutOfRange) { mR = TMath::Sqrt(getX() * getX() + getY() * getY() + getZ() * getZ()); + } return mR; } // Cluster Radius float getPhi() { - if (mPhi > 9990) + if (mPhi == PhiOutOfRange) { mPhi = TMath::ATan2(getY(), getX()); + } return mPhi; } // Cluster Phi int getSector() { - if (mSector == -1) + if (mSector == -1) { mSector = (TMath::ATan2(-getY(), -getX()) + TMath::Pi()) * TMath::RadToDeg() * 0.05; + } return mSector; } // Cluster Sector @@ -130,8 +136,8 @@ class Cluster : public o2::BaseCluster int mL0L1Latency; // L0L1 latency // CZ: is it different per cluster? Checking one ESD file, it seems that it is always the same (see: /alice/data/2017/LHC17n/000280235/pass1/17000280235019.100/AliESDs.root) int mDeltaBC; // DeltaBC --> can it be a char or short? // CZ: is it different per cluster? Checking one ESD file, it seems that it can vary (see: /alice/data/2017/LHC17n/000280235/pass1/17000280235019.100/AliESDs.root) //float mZ; //! z-coordinate // CZ: to be verified if it is the same in the BaseCluster class - float mR = 9999.; //! radius - float mPhi = 9999.; //! phi coordinate + float mR = RadiusOutOfRange; //! radius + float mPhi = PhiOutOfRange; //! phi coordinate int mSector = -1; //! sector number int mContributingChannels; // index of the channels that contributed to the cluster; to be read like this: // channel & 0x3FFFF -> first 18 bits to store the main channel diff --git a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h index 55f05e8b50dd1..80137b7651fce 100644 --- a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h +++ b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h @@ -163,6 +163,7 @@ class MatchTOF void doMatching(int sec); void selectBestMatches(); bool propagateToRefX(o2::track::TrackParCov& trc, float xRef /*in cm*/, float stepInCm /*in cm*/); + bool propagateToRefXWithoutCov(o2::track::TrackParCov& trc, float xRef /*in cm*/, float stepInCm /*in cm*/, float bz); //================================================================ @@ -225,7 +226,7 @@ class MatchTOF std::vector mOutITSLabels; ///< ITS label of matched tracks int mNumOfTracks; // number of tracks to be matched - int* mMatchedTracksIndex = nullptr; //[mNumOfTracks] + std::vector mMatchedTracksIndex; // vector of indexes of the tracks to be matched int mNumOfClusters; // number of clusters to be matched int* mMatchedClustersIndex = nullptr; //[mNumOfClusters] diff --git a/Detectors/GlobalTracking/src/MatchTOF.cxx b/Detectors/GlobalTracking/src/MatchTOF.cxx index c8d62d30fa543..ce0067d44cf10 100644 --- a/Detectors/GlobalTracking/src/MatchTOF.cxx +++ b/Detectors/GlobalTracking/src/MatchTOF.cxx @@ -244,10 +244,8 @@ bool MatchTOF::prepareTracks() mNumOfTracks = mTracksArrayInp->size(); if (mNumOfTracks == 0) return false; // no tracks to be matched - if (mMatchedTracksIndex) - delete[] mMatchedTracksIndex; - mMatchedTracksIndex = new int[mNumOfTracks]; - std::fill_n(mMatchedTracksIndex, mNumOfTracks, -1); // initializing all to -1 + mMatchedTracksIndex.resize(mNumOfTracks); + std::fill(mMatchedTracksIndex.begin(), mMatchedTracksIndex.end(), -1); // initializing all to -1 // copy the track params, propagate to reference X and build sector tables mTracksWork.clear(); @@ -261,6 +259,10 @@ bool MatchTOF::prepareTracks() mTracksSectIndexCache[sec].reserve(100 + 1.2 * mNumOfTracks / o2::constants::math::NSectors); } + // getting Bz (mag field) + auto o2field = static_cast(TGeoGlobalMagField::Instance()->GetField()); + float bzField = o2field->solenoidField(); // magnetic field in kGauss + Printf("\n\nWe have %d tracks to try to match to TOF", mNumOfTracks); int nNotPropagatedToTOF = 0; for (int it = 0; it < mNumOfTracks; it++) { @@ -278,11 +280,17 @@ bool MatchTOF::prepareTracks() LOG(DEBUG) << "Global coordinates Before propagating to 371 cm: globalPos[0] = " << globalPos[0] << ", globalPos[1] = " << globalPos[1] << ", globalPos[2] = " << globalPos[2]; LOG(DEBUG) << "Radius xy Before propagating to 371 cm = " << TMath::Sqrt(globalPos[0] * globalPos[0] + globalPos[1] * globalPos[1]); LOG(DEBUG) << "Radius xyz Before propagating to 371 cm = " << TMath::Sqrt(globalPos[0] * globalPos[0] + globalPos[1] * globalPos[1] + globalPos[2] * globalPos[2]); - if (!propagateToRefX(trc, mXRef, 2) || TMath::Abs(trc.getZ()) > Geo::MAXHZTOF) { + if (!propagateToRefXWithoutCov(trc, mXRef, 2, bzField)) { // we first propagate to 371 cm without considering the covariance matrix nNotPropagatedToTOF++; continue; } + // the "rough" propagation worked; now we can propagate considering also the cov matrix + if (!propagateToRefX(trc, mXRef, 2) || TMath::Abs(trc.getZ()) > Geo::MAXHZTOF) { // we check that the propagation with the cov matrix worked; CHECK: can it happen that it does not if the progataion without the errors succeeded? + nNotPropagatedToTOF++; + continue; + } + trc.getXYZGlo(globalPos); LOG(DEBUG) << "Global coordinates After propagating to 371 cm: globalPos[0] = " << globalPos[0] << ", globalPos[1] = " << globalPos[1] << ", globalPos[2] = " << globalPos[2]; @@ -579,7 +587,8 @@ void MatchTOF::doMatching(int sec) } Printf("We will check now the %d TOF clusters", nTOFCls); bool foundCluster = false; - auto labelTPC = mTPCLabels->at(mTracksSectIndexCache[sec][itrk]); +[itrk], mTPCLabels->size()); + auto labelTPC = (*mTPCLabels)[mTracksSectIndexCache[sec][itrk]]; for (auto itof = itof0; itof < nTOFCls; itof++) { // printf("itof = %d\n", itof); auto& trefTOF = mTOFClusWork[cacheTOF[itof]]; @@ -621,7 +630,7 @@ void MatchTOF::doMatching(int sec) tofLabelSourceID[ilabel] = labelsTOF[ilabel].getSourceID(); } //auto labelTPC = mTPCLabels->at(mTracksSectIndexCache[indices[0]][itrk]); - auto labelITS = mITSLabels->at(mTracksSectIndexCache[indices[0]][itrk]); + auto labelITS = (*mITSLabels)[mTracksSectIndexCache[indices[0]][itrk]]; fillTOFmatchTreeWithLabels("matchPossibleWithLabels", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk, labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID(), labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID(), tofLabelTrackID[0], tofLabelEventID[0], tofLabelSourceID[0], tofLabelTrackID[1], tofLabelEventID[1], tofLabelSourceID[1], tofLabelTrackID[2], tofLabelEventID[2], tofLabelSourceID[2]); if (indices[0] != detId[iPropagation][0]) continue; @@ -672,9 +681,9 @@ void MatchTOF::selectBestMatches() mMatchedTracksIndex[matchingPair.first] = mMatchedTracks.size(); // index of the MatchInfoTOF correspoding to this track mMatchedClustersIndex[matchingPair.second.getTOFClIndex()] = mMatchedTracksIndex[matchingPair.first]; // index of the track that was matched to this cluster mMatchedTracks.push_back(matchingPair); // array of MatchInfoTOF - const auto& labelTPC = mTPCLabels->at(matchingPair.first); + const auto& labelTPC = (*mTPCLabels)[matchingPair.first]; LOG(DEBUG) << "labelTPC: trackID = " << labelTPC.getTrackID() << ", eventID = " << labelTPC.getEventID() << ", sourceID = " << labelTPC.getSourceID(); - const auto& labelITS = mITSLabels->at(matchingPair.first); + const auto& labelITS = (*mITSLabels)[matchingPair.first]; LOG(DEBUG) << "labelITS: trackID = " << labelITS.getTrackID() << ", eventID = " << labelITS.getEventID() << ", sourceID = " << labelITS.getSourceID(); const auto& labelsTOF = mTOFClusLabels->getLabels(matchingPair.second.getTOFClIndex()); bool labelOk = false; // whether we have found or not the same TPC label of the track among the labels of the TOF cluster @@ -732,6 +741,44 @@ bool MatchTOF::propagateToRefX(o2::track::TrackParCov& trc, float xRef, float st return refReached && std::abs(trc.getSnp()) < 0.95; // Here we need to put MAXSNP } +//______________________________________________ +bool MatchTOF::propagateToRefXWithoutCov(o2::track::TrackParCov& trc, float xRef, float stepInCm, float bzField) +{ + // propagate track to matching reference X without using the covariance matrix + // we create the copy of the track in a TrackPar object (no cov matrix) + o2::track::TrackPar trcNoCov(trc); + const float tanHalfSector = tan(o2::constants::math::SectorSpanRad / 2); + bool refReached = false; + float xStart = trcNoCov.getX(); + // the first propagation will be from 2m, if the track is not at least at 2m + if (xStart < 50.) + xStart = 50.; + int istep = 1; + bool hasPropagated = trcNoCov.propagateParamTo(xStart + istep * stepInCm, bzField); + while (hasPropagated) { + if (trcNoCov.getX() > xRef) { + refReached = true; // we reached the 371cm reference + } + istep++; + if (fabs(trcNoCov.getY()) > trcNoCov.getX() * tanHalfSector) { // we are still in the same sector + // we need to rotate the track to go to the new sector + //Printf("propagateToRefX: changing sector"); + auto alphaNew = o2::utils::Angle2Alpha(trcNoCov.getPhiPos()); + if (!trcNoCov.rotateParam(alphaNew) != 0) { + // Printf("propagateToRefX: failed to rotate"); + break; // failed (this line is taken from MatchTPCITS and the following comment too: RS: check effect on matching tracks to neighbouring sector) + } + } + if (refReached) + break; + hasPropagated = trcNoCov.propagateParamTo(xStart + istep * stepInCm, bzField); + } + // if (std::abs(trc.getSnp()) > MAXSNP) Printf("propagateToRefX: condition on snp not ok, returning false"); + //Printf("propagateToRefX: snp of teh track is %f (--> %f grad)", trcNoCov.getSnp(), TMath::ASin(trcNoCov.getSnp())*TMath::RadToDeg()); + + return refReached && std::abs(trcNoCov.getSnp()) < 0.95 && TMath::Abs(trcNoCov.getZ()) < Geo::MAXHZTOF; // Here we need to put MAXSNP +} + #ifdef _ALLOW_DEBUG_TREES_ //______________________________________________ void MatchTOF::setDebugFlag(UInt_t flag, bool on) From a6664974686d6e134c16e76d631944744cde1def Mon Sep 17 00:00:00 2001 From: zampolli Date: Tue, 11 Dec 2018 12:06:08 +0100 Subject: [PATCH 37/39] Leftover fixed --- Detectors/GlobalTracking/src/MatchTOF.cxx | 121 +++++++++++----------- 1 file changed, 60 insertions(+), 61 deletions(-) diff --git a/Detectors/GlobalTracking/src/MatchTOF.cxx b/Detectors/GlobalTracking/src/MatchTOF.cxx index ce0067d44cf10..50de8f91d4ee3 100644 --- a/Detectors/GlobalTracking/src/MatchTOF.cxx +++ b/Detectors/GlobalTracking/src/MatchTOF.cxx @@ -286,11 +286,11 @@ bool MatchTOF::prepareTracks() } // the "rough" propagation worked; now we can propagate considering also the cov matrix - if (!propagateToRefX(trc, mXRef, 2) || TMath::Abs(trc.getZ()) > Geo::MAXHZTOF) { // we check that the propagation with the cov matrix worked; CHECK: can it happen that it does not if the progataion without the errors succeeded? + if (!propagateToRefX(trc, mXRef, 2) || TMath::Abs(trc.getZ()) > Geo::MAXHZTOF) { // we check that the propagation with the cov matrix worked; CHECK: can it happen that it does not if the progataion without the errors succeeded? nNotPropagatedToTOF++; continue; } - + trc.getXYZGlo(globalPos); LOG(DEBUG) << "Global coordinates After propagating to 371 cm: globalPos[0] = " << globalPos[0] << ", globalPos[1] = " << globalPos[1] << ", globalPos[2] = " << globalPos[2]; @@ -463,7 +463,7 @@ void MatchTOF::doMatching(int sec) std::array pos; std::array posBeforeProp; float posFloat[3]; - + LOG(DEBUG) << "Trying to match %d tracks" << cacheTrk.size(); for (int itrk = 0; itrk < cacheTrk.size(); itrk++) { for (int ii = 0; ii < 2; ii++) { @@ -478,18 +478,18 @@ void MatchTOF::doMatching(int sec) float step = 0.1; // step size in cm //uncomment for local debug /* - //trefTrk.getXYZGlo(posBeforeProp); - //float posBeforeProp[3] = {trefTrk.getX(), trefTrk.getY(), trefTrk.getZ()}; // in local ref system - //printf("Global coordinates: posBeforeProp[0] = %f, posBeforeProp[1] = %f, posBeforeProp[2] = %f\n", posBeforeProp[0], posBeforeProp[1], posBeforeProp[2]); - //Printf("Radius xy = %f", TMath::Sqrt(posBeforeProp[0]*posBeforeProp[0] + posBeforeProp[1]*posBeforeProp[1])); - //Printf("Radius xyz = %f", TMath::Sqrt(posBeforeProp[0]*posBeforeProp[0] + posBeforeProp[1]*posBeforeProp[1] + posBeforeProp[2]*posBeforeProp[2])); - */ - + //trefTrk.getXYZGlo(posBeforeProp); + //float posBeforeProp[3] = {trefTrk.getX(), trefTrk.getY(), trefTrk.getZ()}; // in local ref system + //printf("Global coordinates: posBeforeProp[0] = %f, posBeforeProp[1] = %f, posBeforeProp[2] = %f\n", posBeforeProp[0], posBeforeProp[1], posBeforeProp[2]); + //Printf("Radius xy = %f", TMath::Sqrt(posBeforeProp[0]*posBeforeProp[0] + posBeforeProp[1]*posBeforeProp[1])); + //Printf("Radius xyz = %f", TMath::Sqrt(posBeforeProp[0]*posBeforeProp[0] + posBeforeProp[1]*posBeforeProp[1] + posBeforeProp[2]*posBeforeProp[2])); + */ + #ifdef _ALLOW_DEBUG_TREES_ (*mDBGOut) << "propOK" << "track=" << trefTrk << "\n"; #endif - + // initializing for (int ii = 0; ii < 2; ii++) { for (int iii = 0; iii < 5; iii++) { @@ -514,7 +514,7 @@ void MatchTOF::doMatching(int sec) for (int idet = 0; idet < 5; idet++) detIdTemp[idet] = -1; Geo::getPadDxDyDz(posFloat, detIdTemp, deltaPosTemp); - + // uncomment below only for local debug; this will produce A LOT of output - one print per propagation step //Printf("detIdTemp[0] = %d, detIdTemp[1] = %d, detIdTemp[2] = %d, detIdTemp[3] = %d, detIdTemp[4] = %d", detIdTemp[0], detIdTemp[1], detIdTemp[2], detIdTemp[3], detIdTemp[4]); if (detIdTemp[2] != -1 && nStripsCrossedInPropagation == 0) { // print in case you have a useful propagation @@ -587,7 +587,6 @@ void MatchTOF::doMatching(int sec) } Printf("We will check now the %d TOF clusters", nTOFCls); bool foundCluster = false; -[itrk], mTPCLabels->size()); auto labelTPC = (*mTPCLabels)[mTracksSectIndexCache[sec][itrk]]; for (auto itof = itof0; itof < nTOFCls; itof++) { // printf("itof = %d\n", itof); @@ -595,13 +594,13 @@ void MatchTOF::doMatching(int sec) // compare the times of the track and the TOF clusters - remember that they both are ordered in time! //Printf("trefTOF.getTime() = %f, maxTrkTime = %f, minTrkTime = %f", trefTOF.getTime(), maxTrkTime, minTrkTime); /* This part is commented out for now, as we don't want to have any check on the time enabled - if (trefTOF.getTime() < minTrkTime) { // this cluster has a time that is too small for the current track, we will get to the next one - Printf("In trefTOF.getTime() < minTrkTime"); - itof0 = itof+1; // but for the next track that we will check, we will ignore this cluster (the time is anyway too small) - //continue; - } - if (trefTOF.getTime() > maxTrkTime) { // no more TOF clusters can be matched to this track - // break; + if (trefTOF.getTime() < minTrkTime) { // this cluster has a time that is too small for the current track, we will get to the next one + Printf("In trefTOF.getTime() < minTrkTime"); + itof0 = itof+1; // but for the next track that we will check, we will ignore this cluster (the time is anyway too small) + //continue; + } + if (trefTOF.getTime() > maxTrkTime) { // no more TOF clusters can be matched to this track + // break; } */ int mainChannel = trefTOF.getMainContributingChannel(); @@ -612,48 +611,48 @@ void MatchTOF::doMatching(int sec) int eventIdTOF; int sourceIdTOF; for (auto iPropagation = 0; iPropagation < nStripsCrossedInPropagation; iPropagation++) { - LOG(DEBUG) << "TOF Cluster [" << itof << ", " << cacheTOF[itof] << "]: indices = " << indices[0] << ", " << indices[1] << ", " << indices[2] << ", " << indices[3] << ", " << indices[4]; - LOG(DEBUG) << "Propagated Track [" << itrk << ", " << cacheTrk[itrk] << "]: detId[" << iPropagation << "] = " << detId[iPropagation][0] << ", " << detId[iPropagation][1] << ", " << detId[iPropagation][2] << ", " << detId[iPropagation][3] << ", " << detId[iPropagation][4]; - float resX = deltaPos[iPropagation][0] - (indices[4] - detId[iPropagation][4]) * Geo::XPAD; // readjusting the residuals due to the fact that the propagation fell in a pad that was not exactly the one of the cluster - float resZ = deltaPos[iPropagation][2] - (indices[3] - detId[iPropagation][3]) * Geo::ZPAD; // readjusting the residuals due to the fact that the propagation fell in a pad that was not exactly the one of the cluster - float res = TMath::Sqrt(resX * resX + resZ * resZ); - LOG(DEBUG) << "resX = " << resX << ", resZ = " << resZ << ", res = " << res; + LOG(DEBUG) << "TOF Cluster [" << itof << ", " << cacheTOF[itof] << "]: indices = " << indices[0] << ", " << indices[1] << ", " << indices[2] << ", " << indices[3] << ", " << indices[4]; + LOG(DEBUG) << "Propagated Track [" << itrk << ", " << cacheTrk[itrk] << "]: detId[" << iPropagation << "] = " << detId[iPropagation][0] << ", " << detId[iPropagation][1] << ", " << detId[iPropagation][2] << ", " << detId[iPropagation][3] << ", " << detId[iPropagation][4]; + float resX = deltaPos[iPropagation][0] - (indices[4] - detId[iPropagation][4]) * Geo::XPAD; // readjusting the residuals due to the fact that the propagation fell in a pad that was not exactly the one of the cluster + float resZ = deltaPos[iPropagation][2] - (indices[3] - detId[iPropagation][3]) * Geo::ZPAD; // readjusting the residuals due to the fact that the propagation fell in a pad that was not exactly the one of the cluster + float res = TMath::Sqrt(resX * resX + resZ * resZ); + LOG(DEBUG) << "resX = " << resX << ", resZ = " << resZ << ", res = " << res; #ifdef _ALLOW_DEBUG_TREES_ - fillTOFmatchTree("match0", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk); + fillTOFmatchTree("match0", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk); #endif - int tofLabelTrackID[3] = { -1, -1, -1 }; - int tofLabelEventID[3] = { -1, -1, -1 }; - int tofLabelSourceID[3] = { -1, -1, -1 }; - for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++) { - tofLabelTrackID[ilabel] = labelsTOF[ilabel].getTrackID(); - tofLabelEventID[ilabel] = labelsTOF[ilabel].getEventID(); - tofLabelSourceID[ilabel] = labelsTOF[ilabel].getSourceID(); - } - //auto labelTPC = mTPCLabels->at(mTracksSectIndexCache[indices[0]][itrk]); - auto labelITS = (*mITSLabels)[mTracksSectIndexCache[indices[0]][itrk]]; - fillTOFmatchTreeWithLabels("matchPossibleWithLabels", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk, labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID(), labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID(), tofLabelTrackID[0], tofLabelEventID[0], tofLabelSourceID[0], tofLabelTrackID[1], tofLabelEventID[1], tofLabelSourceID[1], tofLabelTrackID[2], tofLabelEventID[2], tofLabelSourceID[2]); - if (indices[0] != detId[iPropagation][0]) - continue; - if (indices[1] != detId[iPropagation][1]) - continue; - if (indices[2] != detId[iPropagation][2]) - continue; - float chi2 = res; // TODO: take into account also the time! - fillTOFmatchTree("match1", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk); - - fillTOFmatchTreeWithLabels("matchOkWithLabels", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk, labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID(), labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID(), tofLabelTrackID[0], tofLabelEventID[0], tofLabelSourceID[0], tofLabelTrackID[1], tofLabelEventID[1], tofLabelSourceID[1], tofLabelTrackID[2], tofLabelEventID[2], tofLabelSourceID[2]); - - if (res < mSpaceTolerance) { // matching ok! - LOG(DEBUG) << "MATCHING FOUND: We have a match! between track " << mTracksSectIndexCache[indices[0]][itrk] << " and TOF cluster " << mTOFClusSectIndexCache[indices[0]][itof]; - foundCluster = true; - mMatchedTracksPairs.emplace_back(std::make_pair(mTracksSectIndexCache[indices[0]][itrk], o2::dataformats::MatchInfoTOF(mTOFClusSectIndexCache[indices[0]][itof], chi2))); // TODO: check if this is correct! - for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++) { - LOG(DEBUG) << "TOF label " << ilabel << ": trackID = " << labelsTOF[ilabel].getTrackID() << ", eventID = " << labelsTOF[ilabel].getEventID() << ", sourceID = " << labelsTOF[ilabel].getSourceID(); - } - LOG(DEBUG) << "TPC label of the track: trackID = " << labelTPC.getTrackID() << ", eventID = " << labelTPC.getEventID() << ", sourceID = " << labelTPC.getSourceID(); - LOG(DEBUG) << "ITS label of the track: trackID = " << labelITS.getTrackID() << ", eventID = " << labelITS.getEventID() << ", sourceID = " << labelITS.getSourceID(); - fillTOFmatchTreeWithLabels("matchOkWithLabelsInSpaceTolerance", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk, labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID(), labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID(), tofLabelTrackID[0], tofLabelEventID[0], tofLabelSourceID[0], tofLabelTrackID[1], tofLabelEventID[1], tofLabelSourceID[1], tofLabelTrackID[2], tofLabelEventID[2], tofLabelSourceID[2]); - } + int tofLabelTrackID[3] = { -1, -1, -1 }; + int tofLabelEventID[3] = { -1, -1, -1 }; + int tofLabelSourceID[3] = { -1, -1, -1 }; + for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++) { + tofLabelTrackID[ilabel] = labelsTOF[ilabel].getTrackID(); + tofLabelEventID[ilabel] = labelsTOF[ilabel].getEventID(); + tofLabelSourceID[ilabel] = labelsTOF[ilabel].getSourceID(); + } + //auto labelTPC = mTPCLabels->at(mTracksSectIndexCache[indices[0]][itrk]); + auto labelITS = (*mITSLabels)[mTracksSectIndexCache[indices[0]][itrk]]; + fillTOFmatchTreeWithLabels("matchPossibleWithLabels", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk, labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID(), labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID(), tofLabelTrackID[0], tofLabelEventID[0], tofLabelSourceID[0], tofLabelTrackID[1], tofLabelEventID[1], tofLabelSourceID[1], tofLabelTrackID[2], tofLabelEventID[2], tofLabelSourceID[2]); + if (indices[0] != detId[iPropagation][0]) + continue; + if (indices[1] != detId[iPropagation][1]) + continue; + if (indices[2] != detId[iPropagation][2]) + continue; + float chi2 = res; // TODO: take into account also the time! + fillTOFmatchTree("match1", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk); + + fillTOFmatchTreeWithLabels("matchOkWithLabels", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk, labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID(), labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID(), tofLabelTrackID[0], tofLabelEventID[0], tofLabelSourceID[0], tofLabelTrackID[1], tofLabelEventID[1], tofLabelSourceID[1], tofLabelTrackID[2], tofLabelEventID[2], tofLabelSourceID[2]); + + if (res < mSpaceTolerance) { // matching ok! + LOG(DEBUG) << "MATCHING FOUND: We have a match! between track " << mTracksSectIndexCache[indices[0]][itrk] << " and TOF cluster " << mTOFClusSectIndexCache[indices[0]][itof]; + foundCluster = true; + mMatchedTracksPairs.emplace_back(std::make_pair(mTracksSectIndexCache[indices[0]][itrk], o2::dataformats::MatchInfoTOF(mTOFClusSectIndexCache[indices[0]][itof], chi2))); // TODO: check if this is correct! + for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++) { + LOG(DEBUG) << "TOF label " << ilabel << ": trackID = " << labelsTOF[ilabel].getTrackID() << ", eventID = " << labelsTOF[ilabel].getEventID() << ", sourceID = " << labelsTOF[ilabel].getSourceID(); + } + LOG(DEBUG) << "TPC label of the track: trackID = " << labelTPC.getTrackID() << ", eventID = " << labelTPC.getEventID() << ", sourceID = " << labelTPC.getSourceID(); + LOG(DEBUG) << "ITS label of the track: trackID = " << labelITS.getTrackID() << ", eventID = " << labelITS.getEventID() << ", sourceID = " << labelITS.getSourceID(); + fillTOFmatchTreeWithLabels("matchOkWithLabelsInSpaceTolerance", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk, labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID(), labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID(), tofLabelTrackID[0], tofLabelEventID[0], tofLabelSourceID[0], tofLabelTrackID[1], tofLabelEventID[1], tofLabelSourceID[1], tofLabelTrackID[2], tofLabelEventID[2], tofLabelSourceID[2]); + } } } if (!foundCluster) @@ -775,7 +774,7 @@ bool MatchTOF::propagateToRefXWithoutCov(o2::track::TrackParCov& trc, float xRef } // if (std::abs(trc.getSnp()) > MAXSNP) Printf("propagateToRefX: condition on snp not ok, returning false"); //Printf("propagateToRefX: snp of teh track is %f (--> %f grad)", trcNoCov.getSnp(), TMath::ASin(trcNoCov.getSnp())*TMath::RadToDeg()); - + return refReached && std::abs(trcNoCov.getSnp()) < 0.95 && TMath::Abs(trcNoCov.getZ()) < Geo::MAXHZTOF; // Here we need to put MAXSNP } From 8f6f7a08560c0562eb4b5e267880fe7fefed1735 Mon Sep 17 00:00:00 2001 From: zampolli Date: Tue, 11 Dec 2018 12:06:29 +0100 Subject: [PATCH 38/39] git-clang-format changes --- .../Detectors/TOF/include/DataFormatsTOF/Cluster.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h b/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h index 811546162597a..d5e84e7fcfead 100644 --- a/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h +++ b/DataFormats/Detectors/TOF/include/DataFormatsTOF/Cluster.h @@ -30,8 +30,8 @@ namespace tof class Cluster : public o2::BaseCluster { static constexpr float RadiusOutOfRange = 9999; // used to check if the radius was already calculated or not - static constexpr float PhiOutOfRange = 9999; // used to check if phi was already calculated or not - + static constexpr float PhiOutOfRange = 9999; // used to check if phi was already calculated or not + public: enum { kMain = 0x3FFFF, kUpLeft = 0x40000, // 2^18, 19th bit @@ -136,9 +136,9 @@ class Cluster : public o2::BaseCluster int mL0L1Latency; // L0L1 latency // CZ: is it different per cluster? Checking one ESD file, it seems that it is always the same (see: /alice/data/2017/LHC17n/000280235/pass1/17000280235019.100/AliESDs.root) int mDeltaBC; // DeltaBC --> can it be a char or short? // CZ: is it different per cluster? Checking one ESD file, it seems that it can vary (see: /alice/data/2017/LHC17n/000280235/pass1/17000280235019.100/AliESDs.root) //float mZ; //! z-coordinate // CZ: to be verified if it is the same in the BaseCluster class - float mR = RadiusOutOfRange; //! radius - float mPhi = PhiOutOfRange; //! phi coordinate - int mSector = -1; //! sector number + float mR = RadiusOutOfRange; //! radius + float mPhi = PhiOutOfRange; //! phi coordinate + int mSector = -1; //! sector number int mContributingChannels; // index of the channels that contributed to the cluster; to be read like this: // channel & 0x3FFFF -> first 18 bits to store the main channel // channel & bit19 (0x40000) -> alsoUPLEFT From 963d38bf8539bca6fed542dcfddd18da40021a83 Mon Sep 17 00:00:00 2001 From: zampolli Date: Tue, 11 Dec 2018 12:07:26 +0100 Subject: [PATCH 39/39] git-clang-format - again --- Detectors/GlobalTracking/src/MatchTOF.cxx | 88 +++++++++++------------ 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/Detectors/GlobalTracking/src/MatchTOF.cxx b/Detectors/GlobalTracking/src/MatchTOF.cxx index 50de8f91d4ee3..757b0b5555650 100644 --- a/Detectors/GlobalTracking/src/MatchTOF.cxx +++ b/Detectors/GlobalTracking/src/MatchTOF.cxx @@ -463,7 +463,7 @@ void MatchTOF::doMatching(int sec) std::array pos; std::array posBeforeProp; float posFloat[3]; - + LOG(DEBUG) << "Trying to match %d tracks" << cacheTrk.size(); for (int itrk = 0; itrk < cacheTrk.size(); itrk++) { for (int ii = 0; ii < 2; ii++) { @@ -484,12 +484,12 @@ void MatchTOF::doMatching(int sec) //Printf("Radius xy = %f", TMath::Sqrt(posBeforeProp[0]*posBeforeProp[0] + posBeforeProp[1]*posBeforeProp[1])); //Printf("Radius xyz = %f", TMath::Sqrt(posBeforeProp[0]*posBeforeProp[0] + posBeforeProp[1]*posBeforeProp[1] + posBeforeProp[2]*posBeforeProp[2])); */ - + #ifdef _ALLOW_DEBUG_TREES_ (*mDBGOut) << "propOK" << "track=" << trefTrk << "\n"; #endif - + // initializing for (int ii = 0; ii < 2; ii++) { for (int iii = 0; iii < 5; iii++) { @@ -514,7 +514,7 @@ void MatchTOF::doMatching(int sec) for (int idet = 0; idet < 5; idet++) detIdTemp[idet] = -1; Geo::getPadDxDyDz(posFloat, detIdTemp, deltaPosTemp); - + // uncomment below only for local debug; this will produce A LOT of output - one print per propagation step //Printf("detIdTemp[0] = %d, detIdTemp[1] = %d, detIdTemp[2] = %d, detIdTemp[3] = %d, detIdTemp[4] = %d", detIdTemp[0], detIdTemp[1], detIdTemp[2], detIdTemp[3], detIdTemp[4]); if (detIdTemp[2] != -1 && nStripsCrossedInPropagation == 0) { // print in case you have a useful propagation @@ -611,48 +611,48 @@ void MatchTOF::doMatching(int sec) int eventIdTOF; int sourceIdTOF; for (auto iPropagation = 0; iPropagation < nStripsCrossedInPropagation; iPropagation++) { - LOG(DEBUG) << "TOF Cluster [" << itof << ", " << cacheTOF[itof] << "]: indices = " << indices[0] << ", " << indices[1] << ", " << indices[2] << ", " << indices[3] << ", " << indices[4]; - LOG(DEBUG) << "Propagated Track [" << itrk << ", " << cacheTrk[itrk] << "]: detId[" << iPropagation << "] = " << detId[iPropagation][0] << ", " << detId[iPropagation][1] << ", " << detId[iPropagation][2] << ", " << detId[iPropagation][3] << ", " << detId[iPropagation][4]; - float resX = deltaPos[iPropagation][0] - (indices[4] - detId[iPropagation][4]) * Geo::XPAD; // readjusting the residuals due to the fact that the propagation fell in a pad that was not exactly the one of the cluster - float resZ = deltaPos[iPropagation][2] - (indices[3] - detId[iPropagation][3]) * Geo::ZPAD; // readjusting the residuals due to the fact that the propagation fell in a pad that was not exactly the one of the cluster - float res = TMath::Sqrt(resX * resX + resZ * resZ); - LOG(DEBUG) << "resX = " << resX << ", resZ = " << resZ << ", res = " << res; + LOG(DEBUG) << "TOF Cluster [" << itof << ", " << cacheTOF[itof] << "]: indices = " << indices[0] << ", " << indices[1] << ", " << indices[2] << ", " << indices[3] << ", " << indices[4]; + LOG(DEBUG) << "Propagated Track [" << itrk << ", " << cacheTrk[itrk] << "]: detId[" << iPropagation << "] = " << detId[iPropagation][0] << ", " << detId[iPropagation][1] << ", " << detId[iPropagation][2] << ", " << detId[iPropagation][3] << ", " << detId[iPropagation][4]; + float resX = deltaPos[iPropagation][0] - (indices[4] - detId[iPropagation][4]) * Geo::XPAD; // readjusting the residuals due to the fact that the propagation fell in a pad that was not exactly the one of the cluster + float resZ = deltaPos[iPropagation][2] - (indices[3] - detId[iPropagation][3]) * Geo::ZPAD; // readjusting the residuals due to the fact that the propagation fell in a pad that was not exactly the one of the cluster + float res = TMath::Sqrt(resX * resX + resZ * resZ); + LOG(DEBUG) << "resX = " << resX << ", resZ = " << resZ << ", res = " << res; #ifdef _ALLOW_DEBUG_TREES_ - fillTOFmatchTree("match0", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk); + fillTOFmatchTree("match0", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk); #endif - int tofLabelTrackID[3] = { -1, -1, -1 }; - int tofLabelEventID[3] = { -1, -1, -1 }; - int tofLabelSourceID[3] = { -1, -1, -1 }; - for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++) { - tofLabelTrackID[ilabel] = labelsTOF[ilabel].getTrackID(); - tofLabelEventID[ilabel] = labelsTOF[ilabel].getEventID(); - tofLabelSourceID[ilabel] = labelsTOF[ilabel].getSourceID(); - } - //auto labelTPC = mTPCLabels->at(mTracksSectIndexCache[indices[0]][itrk]); - auto labelITS = (*mITSLabels)[mTracksSectIndexCache[indices[0]][itrk]]; - fillTOFmatchTreeWithLabels("matchPossibleWithLabels", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk, labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID(), labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID(), tofLabelTrackID[0], tofLabelEventID[0], tofLabelSourceID[0], tofLabelTrackID[1], tofLabelEventID[1], tofLabelSourceID[1], tofLabelTrackID[2], tofLabelEventID[2], tofLabelSourceID[2]); - if (indices[0] != detId[iPropagation][0]) - continue; - if (indices[1] != detId[iPropagation][1]) - continue; - if (indices[2] != detId[iPropagation][2]) - continue; - float chi2 = res; // TODO: take into account also the time! - fillTOFmatchTree("match1", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk); - - fillTOFmatchTreeWithLabels("matchOkWithLabels", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk, labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID(), labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID(), tofLabelTrackID[0], tofLabelEventID[0], tofLabelSourceID[0], tofLabelTrackID[1], tofLabelEventID[1], tofLabelSourceID[1], tofLabelTrackID[2], tofLabelEventID[2], tofLabelSourceID[2]); - - if (res < mSpaceTolerance) { // matching ok! - LOG(DEBUG) << "MATCHING FOUND: We have a match! between track " << mTracksSectIndexCache[indices[0]][itrk] << " and TOF cluster " << mTOFClusSectIndexCache[indices[0]][itof]; - foundCluster = true; - mMatchedTracksPairs.emplace_back(std::make_pair(mTracksSectIndexCache[indices[0]][itrk], o2::dataformats::MatchInfoTOF(mTOFClusSectIndexCache[indices[0]][itof], chi2))); // TODO: check if this is correct! - for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++) { - LOG(DEBUG) << "TOF label " << ilabel << ": trackID = " << labelsTOF[ilabel].getTrackID() << ", eventID = " << labelsTOF[ilabel].getEventID() << ", sourceID = " << labelsTOF[ilabel].getSourceID(); - } - LOG(DEBUG) << "TPC label of the track: trackID = " << labelTPC.getTrackID() << ", eventID = " << labelTPC.getEventID() << ", sourceID = " << labelTPC.getSourceID(); - LOG(DEBUG) << "ITS label of the track: trackID = " << labelITS.getTrackID() << ", eventID = " << labelITS.getEventID() << ", sourceID = " << labelITS.getSourceID(); - fillTOFmatchTreeWithLabels("matchOkWithLabelsInSpaceTolerance", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk, labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID(), labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID(), tofLabelTrackID[0], tofLabelEventID[0], tofLabelSourceID[0], tofLabelTrackID[1], tofLabelEventID[1], tofLabelSourceID[1], tofLabelTrackID[2], tofLabelEventID[2], tofLabelSourceID[2]); - } + int tofLabelTrackID[3] = { -1, -1, -1 }; + int tofLabelEventID[3] = { -1, -1, -1 }; + int tofLabelSourceID[3] = { -1, -1, -1 }; + for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++) { + tofLabelTrackID[ilabel] = labelsTOF[ilabel].getTrackID(); + tofLabelEventID[ilabel] = labelsTOF[ilabel].getEventID(); + tofLabelSourceID[ilabel] = labelsTOF[ilabel].getSourceID(); + } + //auto labelTPC = mTPCLabels->at(mTracksSectIndexCache[indices[0]][itrk]); + auto labelITS = (*mITSLabels)[mTracksSectIndexCache[indices[0]][itrk]]; + fillTOFmatchTreeWithLabels("matchPossibleWithLabels", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk, labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID(), labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID(), tofLabelTrackID[0], tofLabelEventID[0], tofLabelSourceID[0], tofLabelTrackID[1], tofLabelEventID[1], tofLabelSourceID[1], tofLabelTrackID[2], tofLabelEventID[2], tofLabelSourceID[2]); + if (indices[0] != detId[iPropagation][0]) + continue; + if (indices[1] != detId[iPropagation][1]) + continue; + if (indices[2] != detId[iPropagation][2]) + continue; + float chi2 = res; // TODO: take into account also the time! + fillTOFmatchTree("match1", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk); + + fillTOFmatchTreeWithLabels("matchOkWithLabels", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk, labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID(), labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID(), tofLabelTrackID[0], tofLabelEventID[0], tofLabelSourceID[0], tofLabelTrackID[1], tofLabelEventID[1], tofLabelSourceID[1], tofLabelTrackID[2], tofLabelEventID[2], tofLabelSourceID[2]); + + if (res < mSpaceTolerance) { // matching ok! + LOG(DEBUG) << "MATCHING FOUND: We have a match! between track " << mTracksSectIndexCache[indices[0]][itrk] << " and TOF cluster " << mTOFClusSectIndexCache[indices[0]][itof]; + foundCluster = true; + mMatchedTracksPairs.emplace_back(std::make_pair(mTracksSectIndexCache[indices[0]][itrk], o2::dataformats::MatchInfoTOF(mTOFClusSectIndexCache[indices[0]][itof], chi2))); // TODO: check if this is correct! + for (int ilabel = 0; ilabel < labelsTOF.size(); ilabel++) { + LOG(DEBUG) << "TOF label " << ilabel << ": trackID = " << labelsTOF[ilabel].getTrackID() << ", eventID = " << labelsTOF[ilabel].getEventID() << ", sourceID = " << labelsTOF[ilabel].getSourceID(); + } + LOG(DEBUG) << "TPC label of the track: trackID = " << labelTPC.getTrackID() << ", eventID = " << labelTPC.getEventID() << ", sourceID = " << labelTPC.getSourceID(); + LOG(DEBUG) << "ITS label of the track: trackID = " << labelITS.getTrackID() << ", eventID = " << labelITS.getEventID() << ", sourceID = " << labelITS.getSourceID(); + fillTOFmatchTreeWithLabels("matchOkWithLabelsInSpaceTolerance", cacheTOF[itof], indices[0], indices[1], indices[2], indices[3], indices[4], cacheTrk[itrk], iPropagation, detId[iPropagation][0], detId[iPropagation][1], detId[iPropagation][2], detId[iPropagation][3], detId[iPropagation][4], resX, resZ, res, trefTrk, labelTPC.getTrackID(), labelTPC.getEventID(), labelTPC.getSourceID(), labelITS.getTrackID(), labelITS.getEventID(), labelITS.getSourceID(), tofLabelTrackID[0], tofLabelEventID[0], tofLabelSourceID[0], tofLabelTrackID[1], tofLabelEventID[1], tofLabelSourceID[1], tofLabelTrackID[2], tofLabelEventID[2], tofLabelSourceID[2]); + } } } if (!foundCluster)