diff --git a/reco/CMakeLists.txt b/reco/CMakeLists.txt index d9d1512d4c66837d14c8d5344ca4d0ad106f3a74..73c3644c357be5aea7018216b96ec0492e65ce99 100644 --- a/reco/CMakeLists.txt +++ b/reco/CMakeLists.txt @@ -20,6 +20,5 @@ add_subdirectory(offline) add_subdirectory(qa) add_subdirectory(steer) add_subdirectory(tasks) -add_subdirectory(tracking) diff --git a/reco/tracking/CMakeLists.txt b/reco/tracking/CMakeLists.txt deleted file mode 100644 index 1581466c115bdf0b759d3577629102cefa37e5b4..0000000000000000000000000000000000000000 --- a/reco/tracking/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -Add_subdirectory(lx) -#Add_subdirectory(lxTriplet) -Add_subdirectory(global) diff --git a/reco/tracking/global/CMakeLists.txt b/reco/tracking/global/CMakeLists.txt deleted file mode 100755 index 01db524b6231aeb2da1a52c7dbc954c41427a19e..0000000000000000000000000000000000000000 --- a/reco/tracking/global/CMakeLists.txt +++ /dev/null @@ -1,45 +0,0 @@ -# Create a library called "libLxTrack" which includes the source files given in -# the array . -# The extension is already found. Any number of sources could be listed -# here. - -set(INCLUDE_DIRECTORIES - ${CMAKE_CURRENT_SOURCE_DIR} - ) - - -set(SRCS - CbmGlobalTrackingTask.cxx - CbmGlobalTrackingQa.cxx - ) - -set(NO_DICT_SRCS - CbmGlobalTrackingTof.cxx - ) - - -set(LIBRARY_NAME CbmGlobalTracking) -set(LINKDEF GlobalLinkDef.h) -set(PUBLIC_DEPENDENCIES - CbmBase - CbmData - KF - ) - -set(PRIVATE_DEPENDENCIES - CbmMuchSim - Littrack - CbmMuchBase - ROOT::Geom - ROOT::Hist - ROOT::MathCore - KFParticleInterface - ) - -set(INTERFACE_DEPENDENCIES - FairRoot::Base - ROOT::Core - ) - - -generate_cbm_library() diff --git a/reco/tracking/global/CbmGlobalTrackingDefs.h b/reco/tracking/global/CbmGlobalTrackingDefs.h deleted file mode 100644 index 7be930dc9a1004045d2976520e6822b6c96ee143..0000000000000000000000000000000000000000 --- a/reco/tracking/global/CbmGlobalTrackingDefs.h +++ /dev/null @@ -1,17 +0,0 @@ -/* Copyright (C) 2017 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -#ifndef CBMGLOBALTRACKINGDEFS_H -#define CBMGLOBALTRACKINGDEFS_H - -#define scaltype double -#define timetype double - -#endif /* CBMGLOBALTRACKINGDEFS_H */ diff --git a/reco/tracking/global/CbmGlobalTrackingQa.cxx b/reco/tracking/global/CbmGlobalTrackingQa.cxx deleted file mode 100644 index ec224b513c0146c5f4042cf086eaf317623d38a0..0000000000000000000000000000000000000000 --- a/reco/tracking/global/CbmGlobalTrackingQa.cxx +++ /dev/null @@ -1,387 +0,0 @@ -/* Copyright (C) 2017-2020 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer], Volker Friese */ - -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -#include "CbmGlobalTrackingQa.h" - -#include "CbmDigiManager.h" -#include "CbmGlobalTrack.h" -#include "CbmMCDataManager.h" -#include "CbmMCTrack.h" -#include "CbmStsCluster.h" -#include "CbmStsDigi.h" -#include "CbmStsHit.h" -#include "CbmStsPoint.h" -#include "CbmStsTrack.h" -#include "CbmTofPoint.h" - -#include <FairRootManager.h> -#include <Logger.h> - -#include <map> - -using std::cout; -using std::endl; -using std::list; -using std::map; -using std::set; -using std::vector; - - -CbmGlobalTrackingQa::CbmGlobalTrackingQa() {} - -InitStatus CbmGlobalTrackingQa::Init() -{ - // FairRootManager - FairRootManager* ioman = FairRootManager::Instance(); - if (nullptr == ioman) LOG(fatal) << "No FairRootManager"; - - // MC data - CbmMCDataManager* mcManager = static_cast<CbmMCDataManager*>(ioman->GetObject("MCDataManager")); - if (nullptr == mcManager) LOG(fatal) << "No MC data manager"; - fMCTracks = mcManager->InitBranch("MCTrack"); - if (nullptr == fMCTracks) LOG(fatal) << "No MC tracks"; - fStsMCPoints = mcManager->InitBranch("StsPoint"); - if (nullptr == fStsMCPoints) LOG(fatal) << "No STS MC points"; - fTofMCPoints = mcManager->InitBranch("TofPoint"); - if (nullptr == fTofMCPoints) LOG(fatal) << "No ToF MC points"; - - // Digi data - fDigiMan = CbmDigiManager::Instance(); - fDigiMan->Init(); - if (!fDigiMan->IsPresent(ECbmModuleId::kSts)) LOG(fatal) << "No STS digis"; - if (!fDigiMan->IsMatchPresent(ECbmModuleId::kSts)) LOG(fatal) << "No STS digi matches"; - if (!fDigiMan->IsPresent(ECbmModuleId::kTof)) LOG(fatal) << "No ToF digis"; - - // STS data - fStsClusters = static_cast<TClonesArray*>(ioman->GetObject("StsCluster")); - if (nullptr == fStsClusters) LOG(fatal) << "No STS clusters"; - fStsHits = static_cast<TClonesArray*>(ioman->GetObject("StsHit")); - if (nullptr == fStsHits) LOG(fatal) << "No STS hits"; - fStsTracks = static_cast<TClonesArray*>(ioman->GetObject("StsTrack")); - if (nullptr == fStsTracks) LOG(fatal) << "No STS tracks"; - - // TOF data - fTofHits = static_cast<TClonesArray*>(ioman->GetObject("TofHit")); - if (nullptr == fTofHits) LOG(fatal) << "No ToF hits"; - fTofHitMatches = static_cast<TClonesArray*>(ioman->GetObject("TofHitMatch")); - if (nullptr == fTofHitMatches) LOG(fatal) << "No ToF hit matches"; - - // Global track - fGlobalTracks = static_cast<TClonesArray*>(ioman->GetObject("GlobalTrack")); - if (nullptr == fGlobalTracks) LOG(fatal) << "No global tracks"; - - // Internal arrays - fTracks.resize(fNofEvents); - - for (int i = 0; i < fNofEvents; ++i) { - int nofTracks = fMCTracks->Size(0, i); - - if (nofTracks > 0) fTracks[i].resize(nofTracks); - - vector<TrackData>& evTracks = fTracks[i]; - - for (int j = 0; j < nofTracks; ++j) { - TrackData& track = evTracks[j]; - track.hasSts = false; - track.z = -1000; - track.use = false; - track.evN = i; - track.ind = j; - track.used = false; - const CbmMCTrack* mcTrack = static_cast<const CbmMCTrack*>(fMCTracks->Get(0, i, j)); - int motherId = mcTrack->GetMotherId(); - - if (motherId < 0) track.parent = 0; - else { - track.parent = &evTracks[motherId]; - evTracks[motherId].offsprings.push_back(&track); - } - } - } - - - fStsPoints.resize(fNofEvents); - - for (int i = 0; i < fNofEvents; ++i) { - int nofStsPoints = fStsMCPoints->Size(0, i); - - if (nofStsPoints > 0) fStsPoints[i].resize(nofStsPoints); - - vector<PointData>& evPoints = fStsPoints[i]; - - for (int j = 0; j < nofStsPoints; ++j) { - PointData& point = evPoints[j]; - point.evN = i; - point.ind = j; - const CbmStsPoint* stsPoint = static_cast<const CbmStsPoint*>(fStsMCPoints->Get(0, i, j)); - Int_t trackId = stsPoint->GetTrackID(); - fTracks[i][trackId].hasSts = true; - TrackData& track = fTracks[i][trackId]; - point.track = &track; - point.x = (stsPoint->GetXIn() + stsPoint->GetXOut()) / 2; - point.y = (stsPoint->GetYIn() + stsPoint->GetYOut()) / 2; - point.z = (stsPoint->GetZIn() + stsPoint->GetZOut()) / 2; - point.t = stsPoint->GetTime(); - } - } - - - fTofPoints.resize(fNofEvents); - - for (int i = 0; i < fNofEvents; ++i) { - int nofTofPoints = fTofMCPoints->Size(0, i); - - if (nofTofPoints > 0) fTofPoints[i].resize(nofTofPoints); - - vector<PointData>& evPoints = fTofPoints[i]; - - for (int j = 0; j < nofTofPoints; ++j) { - PointData& point = evPoints[j]; - point.evN = i; - point.ind = j; - const CbmTofPoint* tofPoint = static_cast<const CbmTofPoint*>(fTofMCPoints->Get(0, i, j)); - Int_t trackId = tofPoint->GetTrackID(); - TrackData& track = fTracks[i][trackId]; - point.track = &track; - point.x = tofPoint->GetX(); - point.y = tofPoint->GetY(); - point.z = tofPoint->GetZ(); - point.t = tofPoint->GetTime(); - track.tofPoints.push_back(&point); - - if (track.z > 0 && !track.use) { - double deltaZ = point.z - track.z; - track.tx = (point.x - track.x) / deltaZ; - track.ty = (point.y - track.y) / deltaZ; - track.use = true; - } - } - } - - return kSUCCESS; -} - -bool CbmGlobalTrackingQa::CheckMatch(const TrackData* stsMCTrack, Int_t tofHitInd, bool deepSearch) const -{ - set<TrackData*> tofMCTracks; - - const CbmMatch* tofHitMatch = static_cast<const CbmMatch*>(fTofHitMatches->At(tofHitInd)); - int nofTofPoints = tofHitMatch->GetNofLinks(); - - for (Int_t j = 0; j < nofTofPoints; ++j) { - const CbmLink& pointLnk = tofHitMatch->GetLink(j); - Int_t evN = pointLnk.GetEntry() - 1; - Int_t pointInd = pointLnk.GetIndex(); - tofMCTracks.insert(fTofPoints[evN][pointInd].track); - } - - - for (set<TrackData*>::const_iterator i = tofMCTracks.begin(); i != tofMCTracks.end(); ++i) { - const TrackData* tofMCTrack = *i; - - if (deepSearch) { - for (const TrackData* mcTrack = tofMCTrack; 0 != mcTrack; mcTrack = mcTrack->parent) { - if (mcTrack == stsMCTrack) return true; - } - } - else if (tofMCTrack == stsMCTrack) - return true; - } - - return false; -} - -bool CbmGlobalTrackingQa::SemiTofTrack(const TrackData* mcTrack) const -{ - if (!mcTrack->tofPoints.empty()) return true; - - for (list<TrackData*>::const_iterator i = mcTrack->offsprings.begin(); i != mcTrack->offsprings.end(); ++i) { - if (SemiTofTrack(*i)) return true; - } - - return false; -} - -int nofReferenceTofTracks = 0; -int nofCorMergedReferenceTofTracks = 0; -int nofWroMergedReferenceTofTracks = 0; -int nofNonMergedReferenceTofTracks = 0; - -int nofSemiTofTracks = 0; -int nofCorMergedSemiTofTracks = 0; -int nofWroMergedSemiTofTracks = 0; -int nofNonMergedSemiTofTracks = 0; - -int nofNonTofTracks = 0; -int nofMergedNonTofTracks = 0; -int nofNonMergedNonTofTracks = 0; - -void CbmGlobalTrackingQa::Exec(Option_t*) -{ - Int_t nofHits = fTofHits->GetEntriesFast(); - - for (int i = 0; i < nofHits; ++i) { - const CbmTofHit* tofHit = static_cast<const CbmTofHit*>(fTofHits->At(i)); - const CbmMatch* hitMatch = static_cast<const CbmMatch*>(fTofHitMatches->At(i)); - int nofPoints = hitMatch->GetNofLinks(); - for (Int_t k = 0; k < nofPoints; ++k) { - const CbmLink& pointLnk = hitMatch->GetLink(k); - Int_t evN = pointLnk.GetEntry() - 1; - Int_t pointInd = pointLnk.GetIndex(); - const PointData& point = fTofPoints[evN][pointInd]; - point.track->tofHits.insert(tofHit); - } - } //for (int i = 0; i < nofHits; ++i) - - int nofGlobalTracks = fGlobalTracks->GetEntriesFast(); - - for (int i = 0; i < nofGlobalTracks; ++i) { - const CbmGlobalTrack* globalTrack = static_cast<const CbmGlobalTrack*>(fGlobalTracks->At(i)); - int stsTrackInd = globalTrack->GetStsTrackIndex(); - - if (stsTrackInd < 0) continue; - - const CbmStsTrack* stsTrack = static_cast<const CbmStsTrack*>(fStsTracks->At(stsTrackInd)); - map<TrackData*, int> stsMCTracks; - int nofStsHits = stsTrack->GetNofStsHits(); - int nofStsMatches = 0; - - for (int j = 0; j < nofStsHits; ++j) { - int stsHitInd = stsTrack->GetStsHitIndex(j); - const CbmStsHit* stsHit = static_cast<const CbmStsHit*>(fStsHits->At(stsHitInd)); - int frontClusterInd = stsHit->GetFrontClusterId(); - int backClusterInd = stsHit->GetBackClusterId(); - const CbmStsCluster* frontCluster = static_cast<const CbmStsCluster*>(fStsClusters->At(frontClusterInd)); - const CbmStsCluster* backCluster = static_cast<const CbmStsCluster*>(fStsClusters->At(backClusterInd)); - int nofFrontDigis = frontCluster->GetNofDigis(); - - for (int k = 0; k < nofFrontDigis; ++k) { - int stsDigiInd = frontCluster->GetDigi(k); - const CbmMatch* stsDigiMatch = fDigiMan->GetMatch(ECbmModuleId::kSts, stsDigiInd); - int nofLinks = stsDigiMatch->GetNofLinks(); - - for (int l = 0; l < nofLinks; ++l) { - const CbmLink& link = stsDigiMatch->GetLink(l); - int eventId = link.GetEntry(); - int mcPointId = link.GetIndex(); - ++nofStsMatches; - map<TrackData*, int>::iterator iter = stsMCTracks.find(fStsPoints[eventId][mcPointId].track); - - if (iter != stsMCTracks.end()) ++iter->second; - else - stsMCTracks[fStsPoints[eventId][mcPointId].track] = 1; - } - } - - int nofBackDigis = backCluster->GetNofDigis(); - - for (int k = 0; k < nofBackDigis; ++k) { - int stsDigiInd = backCluster->GetDigi(k); - const CbmMatch* stsDigiMatch = fDigiMan->GetMatch(ECbmModuleId::kSts, stsDigiInd); - int nofLinks = stsDigiMatch->GetNofLinks(); - - for (int l = 0; l < nofLinks; ++l) { - const CbmLink& link = stsDigiMatch->GetLink(l); - int eventId = link.GetEntry(); - int mcPointId = link.GetIndex(); - ++nofStsMatches; - map<TrackData*, int>::iterator iter = stsMCTracks.find(fStsPoints[eventId][mcPointId].track); - - if (iter != stsMCTracks.end()) ++iter->second; - else - stsMCTracks[fStsPoints[eventId][mcPointId].track] = 1; - } - } - } // for (int j = 0; j < nofStsHits; ++j) - - if (stsMCTracks.empty()) continue; - - map<TrackData*, int>::iterator lastStsTrackIter = stsMCTracks.end(); - --lastStsTrackIter; - - if (lastStsTrackIter->second < 0.7 * nofStsMatches) continue; - - int tofHitInd = globalTrack->GetTofHitIndex(); - - if (lastStsTrackIter->first->tofPoints.empty()) { - if (SemiTofTrack(lastStsTrackIter->first)) { - ++nofSemiTofTracks; - - if (tofHitInd >= 0) { - if (CheckMatch(lastStsTrackIter->first, tofHitInd, true)) ++nofCorMergedSemiTofTracks; - else - ++nofWroMergedSemiTofTracks; - } - else - ++nofNonMergedSemiTofTracks; - } - else { - ++nofNonTofTracks; - - if (tofHitInd >= 0) ++nofMergedNonTofTracks; - else - ++nofNonMergedNonTofTracks; - } - } - - if (lastStsTrackIter->first->tofPoints.empty() || lastStsTrackIter->first->tofHits.empty()) continue; - - ++nofReferenceTofTracks; - - if (tofHitInd < 0) { - ++nofNonMergedReferenceTofTracks; - continue; - } - - if (CheckMatch(lastStsTrackIter->first, tofHitInd)) ++nofCorMergedReferenceTofTracks; - else - ++nofWroMergedReferenceTofTracks; - } //for (int i = 0; i < nofGlobalTracks; ++i) -} - -void CbmGlobalTrackingQa::Finish() -{ - double eff = 100 * nofCorMergedReferenceTofTracks; - eff /= nofReferenceTofTracks; - cout << "The correctly merged reference tracks: " << eff << " % [" << nofCorMergedReferenceTofTracks << " / " - << nofReferenceTofTracks << " ]" << endl; - eff = 100 * nofWroMergedReferenceTofTracks; - eff /= nofReferenceTofTracks; - cout << "The incorrectly merged reference tracks: " << eff << " % [" << nofWroMergedReferenceTofTracks << " / " - << nofReferenceTofTracks << " ]" << endl; - eff = 100 * nofNonMergedReferenceTofTracks; - eff /= nofReferenceTofTracks; - cout << "The non merged reference tracks: " << eff << " % [" << nofNonMergedReferenceTofTracks << " / " - << nofReferenceTofTracks << " ]" << endl; - - eff = 100 * nofCorMergedSemiTofTracks; - eff /= nofSemiTofTracks; - cout << "The correctly merged semi ToF tracks: " << eff << " % [" << nofCorMergedSemiTofTracks << " / " - << nofSemiTofTracks << " ]" << endl; - eff = 100 * nofWroMergedSemiTofTracks; - eff /= nofSemiTofTracks; - cout << "The incorrectly merged semi ToF tracks: " << eff << " % [" << nofWroMergedSemiTofTracks << " / " - << nofSemiTofTracks << " ]" << endl; - eff = 100 * nofNonMergedReferenceTofTracks; - eff /= nofSemiTofTracks; - cout << "The non merged semi ToF tracks: " << eff << " % [" << nofNonMergedReferenceTofTracks << " / " - << nofSemiTofTracks << " ]" << endl; - - eff = 100 * nofMergedNonTofTracks; - eff /= nofNonTofTracks; - cout << "The merged non ToF tracks: " << eff << " % [" << nofMergedNonTofTracks << " / " << nofNonTofTracks << " ]" - << endl; - eff = 100 * nofNonMergedNonTofTracks; - eff /= nofNonTofTracks; - cout << "The non merged non ToF tracks: " << eff << " % [" << nofNonMergedNonTofTracks << " / " << nofNonTofTracks - << " ]" << endl; -} - -ClassImp(CbmGlobalTrackingQa) diff --git a/reco/tracking/global/CbmGlobalTrackingQa.h b/reco/tracking/global/CbmGlobalTrackingQa.h deleted file mode 100644 index 485eb4e9f222b7c7362316b13f08f6e02cc077eb..0000000000000000000000000000000000000000 --- a/reco/tracking/global/CbmGlobalTrackingQa.h +++ /dev/null @@ -1,119 +0,0 @@ -/* Copyright (C) 2017-2020 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer], Volker Friese */ - -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -#ifndef CBMGLOBALTRACKINGQA_H -#define CBMGLOBALTRACKINGQA_H - -#include "CbmGlobalTrackingDefs.h" -#include "CbmMCDataArray.h" -#include "CbmMatch.h" -#include "CbmTofDigi.h" -#include "CbmTofHit.h" - -#include "FairTask.h" - -#include "TClonesArray.h" - -#include <list> -#include <set> -#include <vector> - -class CbmDigiManager; - - -class CbmGlobalTrackingQa : public FairTask { -public: - struct PointData; - - struct TrackData { - bool hasSts; - scaltype x; - scaltype y; - scaltype z; - scaltype t; - scaltype tx; - scaltype ty; - std::list<PointData*> tofPoints; - bool use; - int evN; - int ind; - std::set<const CbmTofHit*> tofHits; - bool used; - TrackData* parent; - std::list<TrackData*> offsprings; - - TrackData() - : hasSts(false) - , x(0) - , y(0) - , z(0) - , t(0) - , tx(0) - , ty(0) - , tofPoints() - , use(false) - , evN(0) - , ind(0) - , tofHits() - , used(false) - , parent(nullptr) - , offsprings() - { - } - TrackData(const TrackData&) = default; - TrackData& operator=(const TrackData&) = delete; - }; - - struct PointData { - scaltype x; - scaltype y; - scaltype z; - scaltype t; - TrackData* track; - int evN; - int ind; - }; - -public: - CbmGlobalTrackingQa(); - - CbmGlobalTrackingQa(const CbmGlobalTrackingQa&) = delete; - CbmGlobalTrackingQa& operator=(const CbmGlobalTrackingQa&) = delete; - - InitStatus Init(); // Overridden from FairTask - void Exec(Option_t* opt); // Overridden from FairTask - void Finish(); // Overridden from FairTask - - void SetNofEvents(Int_t v) { fNofEvents = v; } - -private: - bool CheckMatch(const TrackData* stsMCTrack, Int_t tofHitInd, bool deepSearch = false) const; - bool SemiTofTrack(const TrackData* mcTrack) const; - -private: - CbmDigiManager* fDigiMan = nullptr; - TClonesArray* fTofHits = nullptr; - TClonesArray* fStsTracks = nullptr; - TClonesArray* fGlobalTracks = nullptr; - TClonesArray* fTofHitMatches = nullptr; - TClonesArray* fStsHits = nullptr; - TClonesArray* fStsClusters = nullptr; - CbmMCDataArray* fMCTracks = nullptr; - CbmMCDataArray* fStsMCPoints = nullptr; - CbmMCDataArray* fTrdMCPoints = nullptr; - CbmMCDataArray* fTofMCPoints = nullptr; - std::vector<std::vector<TrackData>> fTracks {}; - std::vector<std::vector<PointData>> fTofPoints {}; - std::vector<std::vector<PointData>> fStsPoints {}; - Int_t fNofEvents = 0; - ClassDef(CbmGlobalTrackingQa, 1) -}; - -#endif /* CBMGLOBALTRACKINGQA_H */ diff --git a/reco/tracking/global/CbmGlobalTrackingTask.cxx b/reco/tracking/global/CbmGlobalTrackingTask.cxx deleted file mode 100644 index 7d7217045ca5dfd111df48e2a8aa3ceaab478192..0000000000000000000000000000000000000000 --- a/reco/tracking/global/CbmGlobalTrackingTask.cxx +++ /dev/null @@ -1,279 +0,0 @@ -/* Copyright (C) 2017-2020 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer], Florian Uhlig */ - -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -#include "CbmGlobalTrackingTask.h" - -#include "CbmGlobalTrack.h" -#include "CbmKFParticleInterface.h" -#include "CbmKFStsHit.h" -#include "CbmMvdHit.h" -#include "CbmStsCluster.h" -#include "CbmStsHit.h" -#include "CbmStsTrack.h" - -#include <FairRootManager.h> -#include <Logger.h> - -#include "TH1F.h" - -#include <iostream> - -#define CBM_GLOBALTB_PRINT_PERF - -#ifdef CBM_GLOBALTB_PRINT_PERF -#ifdef __MACH__ -#include <mach/mach_time.h> -#include <sys/time.h> -#ifndef CLOCK_REALTIME -#define CLOCK_REALTIME 0 -#endif -#ifndef CLOCK_MONOTONIC -#define CLOCK_MONOTONIC 0 -#endif -inline int clock_gettime(int /*clk_id*/, struct timespec* t) -{ - mach_timebase_info_data_t timebase; - mach_timebase_info(&timebase); - uint64_t time; - time = mach_absolute_time(); - double nseconds = ((double) time * (double) timebase.numer) / ((double) timebase.denom); - double seconds = ((double) time * (double) timebase.numer) / ((double) timebase.denom * 1e9); - t->tv_sec = seconds; - t->tv_nsec = nseconds; - return 0; -} -#else -#include <time.h> -#endif -#endif //CBM_GLOBALTB_PRINT_PERF - -using std::cout; -using std::endl; -using std::list; -using std::map; -using std::set; -using std::vector; - -CbmGlobalTrackingTask::CbmGlobalTrackingTask() - : fTofGeometry() - , fTimeSlice(0) - , fTofHits(0) - , fStsTracks(0) - , fStsHits(0) - , fMvdHits(0) - , fGlobalTracks(0) - , fKFTrack() - , fPrimVertex(0) -{ -} - -InitStatus CbmGlobalTrackingTask::Init() -{ - fKFTrack.SetPID(211); - - if (!fTofGeometry.Read()) LOG(fatal) << "Could not read the ToF geometry information"; - - FairRootManager* ioman = FairRootManager::Instance(); - - if (0 == ioman) LOG(fatal) << "No FairRootManager"; - - fTimeSlice = static_cast<CbmTimeSlice*>(ioman->GetObject("TimeSlice.")); - - if (0 == fTimeSlice) LOG(fatal) << "No time slice"; - - fTofHits = static_cast<TClonesArray*>(ioman->GetObject("TofHit")); - - if (0 == fTofHits) LOG(fatal) << "No ToF hits"; - - fTofGeometry.SetTofHits(fTofHits); - - fStsTracks = static_cast<TClonesArray*>(ioman->GetObject("StsTrack")); - - if (0 == fStsTracks) LOG(fatal) << "No STS tracks"; - - fStsHits = static_cast<TClonesArray*>(ioman->GetObject("StsHit")); - - if (0 == fStsHits) LOG(fatal) << "No STS hits"; - - fMvdHits = static_cast<TClonesArray*>(ioman->GetObject("MvdHit")); - //fPrimVertex = static_cast<CbmVertex*> (ioman->GetObject("PrimaryVertex")); - // Get pointer to PrimaryVertex object from IOManager if it exists - // The old name for the object is "PrimaryVertex" the new one - // "PrimaryVertex." Check first for the new name - fPrimVertex = dynamic_cast<CbmVertex*>(ioman->GetObject("PrimaryVertex.")); - if (nullptr == fPrimVertex) { fPrimVertex = dynamic_cast<CbmVertex*>(ioman->GetObject("PrimaryVertex")); } - if (nullptr == fPrimVertex) { LOG(fatal) << "No primary vertex"; } - - fGlobalTracks = new TClonesArray("CbmGlobalTrack", 100); - ioman->Register("GlobalTrack", "Global", fGlobalTracks, IsOutputBranchPersistent("GlobalTrack")); - - return kSUCCESS; -} - -#ifdef CBM_GLOBALTB_PRINT_PERF -static long fullDuration = 0; -#endif //CBM_GLOBALTB_PRINT_PERF - -void CbmGlobalTrackingTask::Exec(Option_t* /*opt*/) -{ - fGlobalTracks->Clear(); - Double_t startTime = fTimeSlice->GetStartTime(); - fTofGeometry.Prepare(startTime); - int nofStsTracks = fStsTracks->GetEntriesFast(); - - for (int i = 0; i < nofStsTracks; ++i) { - const CbmStsTrack* track = static_cast<const CbmStsTrack*>(fStsTracks->At(i)); - CbmGlobalTrack* globalTrack = new ((*fGlobalTracks)[i]) CbmGlobalTrack(); - globalTrack->SetStsTrackIndex(i); - Int_t tofHitInd; - Double_t stsTrackLength = CalcStsTrackLength(track); - Double_t trackLength = stsTrackLength; - FairTrackParam param = *track->GetParamLast(); -#ifdef CBM_GLOBALTB_PRINT_PERF - timespec ts; - clock_gettime(CLOCK_REALTIME, &ts); - long beginTime = ts.tv_sec * 1000000000 + ts.tv_nsec; -#endif //CBM_GLOBALTB_PRINT_PERF - //fTofGeometry.Find(param->GetX(), param->GetCovariance(0, 0), param->GetY(), param->GetCovariance(1, 1), param->GetZ(), - //track->GetTime(), track->GetTimeError(), param->GetTx(), TMath::Sqrt(param->GetCovariance(2, 2)), param->GetTy(), TMath::Sqrt(param->GetCovariance(3, 3)), tofHitInd); - fTofGeometry.Find(param, track->GetLastHitTime(), track->GetLastHitTimeError(), tofHitInd, trackLength); - globalTrack->SetTofHitIndex(tofHitInd); - globalTrack->SetLength(stsTrackLength + trackLength); - globalTrack->SetParamFirst(track->GetParamFirst()); - globalTrack->SetParamLast(¶m); - - if (fPrimVertex) { - FairTrackParam vtxTrackParam; - float chiSqPrimary = 0; - CbmKFParticleInterface::ExtrapolateTrackToPV(track, fPrimVertex, &vtxTrackParam, chiSqPrimary); - globalTrack->SetParamPrimaryVertex(&vtxTrackParam); - } -#ifdef CBM_GLOBALTB_PRINT_PERF - clock_gettime(CLOCK_REALTIME, &ts); - long endTime = ts.tv_sec * 1000000000 + ts.tv_nsec; - fullDuration += endTime - beginTime; -#endif //CBM_GLOBALTB_PRINT_PERF - - } //for (int i = 0; i < nofStsTracks; ++i) -} - -extern int nofMRPCIntersections; -extern int nofToFIntersections; -extern int nofMRPCIntersectionsT; -extern int globalNofHits; -extern int globalNofHitsT; -extern int globalNofHitsM; - -void CbmGlobalTrackingTask::Finish() -{ - cout << "nofMRPCIntersections: " << nofMRPCIntersections << endl; - cout << "nofToFIntersections: " << nofToFIntersections << endl; - cout << "nofMRPCIntersectionsT: " << nofMRPCIntersectionsT << endl; - cout << "globalNofHits: " << globalNofHits << endl; - cout << "globalNofHitsT: " << globalNofHitsT << endl; - cout << "globalNofHitsM: " << globalNofHitsM << endl << endl << endl; - cout << "Full merging duration was: " << fullDuration << endl << endl << endl; -} - -Double_t CbmGlobalTrackingTask::CalcStsTrackLength(const CbmStsTrack* track) -{ - Double_t length = 0; - Double_t* T = fKFTrack.GetTrack(); - Double_t zVert = fPrimVertex ? fPrimVertex->GetZ() : 0; - const FairTrackParam* paramFirst = track->GetParamFirst(); - Double_t x = paramFirst->GetX(); - Double_t y = paramFirst->GetY(); - Double_t z = paramFirst->GetZ(); - Double_t p = paramFirst->GetQp() ? TMath::Abs(1 / paramFirst->GetQp()) : 1; - fKFTrack.SetTrackParam(*paramFirst); - - while (z > zVert) { - Double_t xOld = x; - Double_t yOld = y; - Double_t zOld = z; - - if (z - p > zVert) z -= p; - else - z = zVert; - - fKFTrack.Extrapolate(z); - x = T[0]; - y = T[1]; - length += TMath::Sqrt(TMath::Power(x - xOld, 2) + TMath::Power(y - yOld, 2) + TMath::Power(z - zOld, 2)); - } - - x = paramFirst->GetX(); - y = paramFirst->GetY(); - z = paramFirst->GetZ(); - - const FairTrackParam* paramLast = track->GetParamLast(); - int nofHits = track->GetTotalNofHits(); - - for (int i = 1; i < nofHits; ++i) { - bool isMvdHit = true; - CbmPixelHit* hit = nullptr; - if (i < track->GetNofMvdHits()) { - isMvdHit = true; - hit = static_cast<CbmPixelHit*>(fMvdHits->At(track->GetMvdHitIndex(i))); - } - else { - isMvdHit = false; - hit = static_cast<CbmPixelHit*>(fStsHits->At(track->GetStsHitIndex(i - track->GetNofMvdHits()))); - } - // Double_t nextX; (VF) not used - // Double_t nextY; (VF) not used - Double_t nextZ; - - if (i == nofHits - 1) { - // nextX = paramLast->GetX(); (VF) not used - // nextY = paramLast->GetY(); (VF) not used - nextZ = paramLast->GetZ(); - } - else { - // nextX = hit->GetX(); (VF) not used - // nextY = hit->GetY(); (VF) not used - nextZ = hit->GetZ(); - } - - while (z < nextZ) { - Double_t xOld = x; - Double_t yOld = y; - Double_t zOld = z; - - if (z + p < nextZ) z += p; - else - z = nextZ; - - fKFTrack.Extrapolate(z); - - if (z == nextZ) { - CbmKFStsHit stsKFHit; - - if (isMvdHit) { - stsKFHit.Create(static_cast<CbmMvdHit*>(hit)); - } - else { - stsKFHit.Create(static_cast<CbmStsHit*>(hit)); - } - - Double_t qp0 = T[4]; - stsKFHit.Filter(fKFTrack, kTRUE, qp0); - } - - x = T[0]; - y = T[1]; - length += TMath::Sqrt(TMath::Power(x - xOld, 2) + TMath::Power(y - yOld, 2) + TMath::Power(z - zOld, 2)); - } - } - - return length; -} - -ClassImp(CbmGlobalTrackingTask) diff --git a/reco/tracking/global/CbmGlobalTrackingTask.h b/reco/tracking/global/CbmGlobalTrackingTask.h deleted file mode 100644 index 17d4900a33a0967469b36c46124119d454807315..0000000000000000000000000000000000000000 --- a/reco/tracking/global/CbmGlobalTrackingTask.h +++ /dev/null @@ -1,60 +0,0 @@ -/* Copyright (C) 2017 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -#ifndef CBMGLOBALTRACKINGTASK_H -#define CBMGLOBALTRACKINGTASK_H - -#include "CbmGlobalTrackingTof.h" -#include "CbmKFTrack.h" -#include "CbmTimeSlice.h" -#include "CbmTofHit.h" -#include "CbmVertex.h" - -#include "FairTask.h" - -#include "TClonesArray.h" - -class CbmGlobalTrackingTask : public FairTask { -public: - CbmGlobalTrackingTask(); - - CbmGlobalTrackingTask(const CbmGlobalTrackingTask&) = delete; - CbmGlobalTrackingTask& operator=(const CbmGlobalTrackingTask&) = delete; - - InitStatus Init(); // Overridden from FairTask - void Exec(Option_t* opt); // Overridden from FairTask - void Finish(); // Overridden from FairTask - - void SetNofTBins(int v) { fTofGeometry.SetNofTBins(v); } - - void SetTBinSize(scaltype v) { fTofGeometry.SetTBinSize(v); } - - void SetPropagatePdg(Int_t v) { fTofGeometry.SetPdg(v); } - - void SetChi2Cut(Double_t v) { fTofGeometry.SetChi2Cut(v); } - -private: - Double_t CalcStsTrackLength(const CbmStsTrack* track); - -private: - CbmGlobalTrackingTofGeometry fTofGeometry; - CbmTimeSlice* fTimeSlice; - TClonesArray* fTofHits; - TClonesArray* fStsTracks; - TClonesArray* fStsHits; - TClonesArray* fMvdHits; - TClonesArray* fGlobalTracks; - CbmKFTrack fKFTrack; - CbmVertex* fPrimVertex; - - ClassDef(CbmGlobalTrackingTask, 1) -}; - -#endif /* CBMGLOBALTRACKINGTASK_H */ diff --git a/reco/tracking/global/CbmGlobalTrackingTof.cxx b/reco/tracking/global/CbmGlobalTrackingTof.cxx deleted file mode 100644 index aa04eb9bd6d3f49f8374fe115e4a60dff827a292..0000000000000000000000000000000000000000 --- a/reco/tracking/global/CbmGlobalTrackingTof.cxx +++ /dev/null @@ -1,1171 +0,0 @@ -/* Copyright (C) 2017-2019 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -#include "CbmGlobalTrackingTof.h" - -#include "CbmPixelHit.h" -#include "CbmTofAddress.h" -#include "CbmTofHit.h" -#include "base/CbmLitToolFactory.h" -#include "utils/CbmLitConverter.h" - -#include "TGeoBBox.h" -#include "TGeoManager.h" -#include "TMath.h" - -#include <iostream> -#include <utility> - -TrackPropagatorPtr fPropagator; -TrackPropagatorPtr fLinePropagator; -TrackUpdatePtr fFilter; - -using std::cout; -using std::endl; -using std::list; -using std::map; -using std::pair; -using std::set; -using std::swap; - -/* (VF) Unused function -static bool GaussSolve(double coeffs[3][4], double result[3]) -{ - int indices[3]; - - for (int i = 0; i < 3; ++i) - indices[i] = i; - - for (int i = 2; i > 0; --i) - { - if (0 == coeffs[i][i + 1]) - { - for (int j = i; j > 0; --j) - { - if (0 != coeffs[i][j]) - { - for (int k = 0; k < 3; ++k) - swap(coeffs[k][j], coeffs[k][i + 1]); - - swap(indices[j - 1], indices[i]); - break; - } - } - } - - double den = coeffs[i][i + 1]; - - if (0 == den) - return false; - - for (int j = 0; j < i; ++j) - { - for (int k = 0; k <= i; ++k) - coeffs[j][k] += -coeffs[j][i + 1] * coeffs[i][k] / den; - } - } - - double solution[3]; - - for (int i = 0; i < 3; ++i) - { - double s = coeffs[i][0]; - - for (int j = 0; j < i; ++j) - s += coeffs[i][j + 1] * solution[j]; - - if (0 == coeffs[i][i + 1]) - return false; - - solution[i] = -s / coeffs[i][i + 1]; - } - - for (int i = 0; i < 3; ++i) - result[indices[i]] = solution[i]; - - return true; -} -*/ - -struct Point { - double x; - double y; - double z; -}; - -struct Line { - double x0; - double y0; - double z0; - - double cosX; - double cosY; - double cosZ; -}; - -struct Segment { - Point a; - Point b; -}; - -struct Plane { - double x0; - double y0; - double z0; - - double cosX1; - double cosY1; - double cosZ1; - - double cosX2; - double cosY2; - double cosZ2; -}; - -/* (VF) Unused function -static bool Intersect(const Plane& plane, const Line& line, double result[3]) -{ - double coeffs[3][4] = { - { plane.x0 - line.x0, plane.cosX1, plane.cosX2, -line.cosX }, - { plane.y0 - line.y0, plane.cosY1, plane.cosY2, -line.cosY }, - { plane.z0 - line.z0, plane.cosZ1, plane.cosZ2, -line.cosZ } - }; - - return GaussSolve(coeffs, result); -} -*/ - -struct Rectangle { - Plane plane; - double s1; - double s2; -}; - -/* (VF) Unused function -static bool Intersect(const Rectangle& rect, const Line& line, double result[3]) -{ - if (!Intersect(rect.plane, line, result)) - return false; - - return 0 <= result[0] && result[0] <= rect.s1 && 0 <= result[1] && result[1] <= rect.s2; -} -*/ - -/* (VF) Unused function -static bool Intersect(const Rectangle& rect, const Line& line) -{ - double result[3]; - - if (!Intersect(rect.plane, line, result)) - return false; - - return 0 <= result[0] && result[0] <= rect.s1 && 0 <= result[1] && result[1] <= rect.s2; -} -*/ - -/* (VF) Unused function -static bool Intersect(const Rectangle& rect, const Segment& segment) -{ - double len = TMath::Sqrt((segment.b.x - segment.a.x) * (segment.b.x - segment.a.x) + - (segment.b.y - segment.a.y) * (segment.b.y - segment.a.y) + - (segment.b.z - segment.a.z) * (segment.b.z - segment.a.z)); - double cosX = (segment.b.x - segment.a.x) / len; - double cosY = (segment.b.y - segment.a.y) / len; - double cosZ = (segment.b.z - segment.a.z) / len; - Line line = { segment.a.x, segment.a.y, segment.a.z, cosX, cosY, cosZ }; - double result[3]; - - if (!Intersect(rect.plane, line, result)) - return false; - - return 0 <= result[2] && result[2] <= len; -} -*/ - -struct Direction { - double cosX; - double cosY; - double cosZ; -}; - -struct TBin { - list<Int_t> fHitInds; - - TBin() : fHitInds() {} - - void Clear() { fHitInds.clear(); } -}; - -#ifdef CBM_GLOBALTB_TOF_3D_CUBOIDS -struct Cuboid { - double width; - double height; - double thickness; - double minX; - double maxX; - double minY; - double maxY; - double minZ; - double maxZ; - Direction dirWidth; - Direction dirHeight; - Direction dirThickness; - Point vertices[2][2][2]; - Segment edges[12]; - Rectangle faces[3][2]; - - //Plane plane1; - //Plane plane2; - - int fNofTBins; - TBin* fTBins; - - Int_t fFullModId; - - void Clear() - { - for (int i = 0; i < fNofTBins; ++i) - fTBins[i].Clear(); - } - - void Calc(int nofTBins = 0) - { - fNofTBins = nofTBins; - - if (fNofTBins) fTBins = new TBin[fNofTBins]; - - dirWidth = {(vertices[0][0][1].x - vertices[0][0][0].x) / width, - (vertices[0][0][1].y - vertices[0][0][0].y) / width, - (vertices[0][0][1].z - vertices[0][0][0].z) / width}; - dirHeight = {(vertices[0][1][0].x - vertices[0][0][0].x) / height, - (vertices[0][1][0].y - vertices[0][0][0].y) / height, - (vertices[0][1][0].z - vertices[0][0][0].z) / height}; - dirThickness = {(vertices[1][0][0].x - vertices[0][0][0].x) / thickness, - (vertices[1][0][0].y - vertices[0][0][0].y) / thickness, - (vertices[1][0][0].z - vertices[0][0][0].z) / thickness}; - - minX = 1000000; - maxX = -1000000; - minY = 1000000; - maxY = -1000000; - minZ = 1000000; - maxZ = -1000000; - - int dims[3]; - int ind = 0; - - for (int i = 0; i < 2; ++i) { - dims[0] = i; - - for (int j = 0; j < 2; ++j) { - dims[1] = j; - - for (int k = 0; k < 2; ++k) { - dims[2] = k; - - for (int l = 0; l < 3; ++l) { - if (0 == dims[l]) { - int dims2[3] = {dims[0], dims[1], dims[2]}; - dims2[l] = 1; - edges[ind++] = {{vertices[dims[0]][dims[1]][dims[2]].x, vertices[dims[0]][dims[1]][dims[2]].y, - vertices[dims[0]][dims[1]][dims[2]].z}, - {vertices[dims2[0]][dims2[1]][dims2[2]].x, vertices[dims2[0]][dims2[1]][dims2[2]].y, - vertices[dims2[0]][dims2[1]][dims2[2]].z}}; - } - } - - if (minX > vertices[i][j][k].x) minX = vertices[i][j][k].x; - - if (maxX < vertices[i][j][k].x) maxX = vertices[i][j][k].x; - - if (minY > vertices[i][j][k].y) minY = vertices[i][j][k].y; - - if (maxY < vertices[i][j][k].y) maxY = vertices[i][j][k].y; - - if (minZ > vertices[i][j][k].z) minZ = vertices[i][j][k].z; - - if (maxZ < vertices[i][j][k].z) maxZ = vertices[i][j][k].z; - } - } - } - - for (int i = 0; i < 3; ++i) { - int j = (i + 1) % 3; - int k = (i + 2) % 3; - int dims0[3] = {0, 0, 0}; - int dims1[3] = {0, 0, 0}; - int dims2[3] = {0, 0, 0}; - dims1[j] = 1; - dims2[k] = 1; - double len1 = - TMath::Sqrt((vertices[dims1[0]][dims1[1]][dims1[2]].x - vertices[dims0[0]][dims0[1]][dims0[2]].x) - * (vertices[dims1[0]][dims1[1]][dims1[2]].x - vertices[dims0[0]][dims0[1]][dims0[2]].x) - + (vertices[dims1[0]][dims1[1]][dims1[2]].y - vertices[dims0[0]][dims0[1]][dims0[2]].y) - * (vertices[dims1[0]][dims1[1]][dims1[2]].y - vertices[dims0[0]][dims0[1]][dims0[2]].y) - + (vertices[dims1[0]][dims1[1]][dims1[2]].z - vertices[dims0[0]][dims0[1]][dims0[2]].z) - * (vertices[dims1[0]][dims1[1]][dims1[2]].z - vertices[dims0[0]][dims0[1]][dims0[2]].z)); - double cosX1 = (vertices[dims1[0]][dims1[1]][dims1[2]].x - vertices[dims0[0]][dims0[1]][dims0[2]].x) / len1; - double cosY1 = (vertices[dims1[0]][dims1[1]][dims1[2]].y - vertices[dims0[0]][dims0[1]][dims0[2]].y) / len1; - double cosZ1 = (vertices[dims1[0]][dims1[1]][dims1[2]].z - vertices[dims0[0]][dims0[1]][dims0[2]].z) / len1; - - double len2 = - TMath::Sqrt((vertices[dims2[0]][dims2[1]][dims2[2]].x - vertices[dims0[0]][dims0[1]][dims0[2]].x) - * (vertices[dims2[0]][dims2[1]][dims2[2]].x - vertices[dims0[0]][dims0[1]][dims0[2]].x) - + (vertices[dims2[0]][dims2[1]][dims2[2]].y - vertices[dims0[0]][dims0[1]][dims0[2]].y) - * (vertices[dims2[0]][dims2[1]][dims2[2]].y - vertices[dims0[0]][dims0[1]][dims0[2]].y) - + (vertices[dims2[0]][dims2[1]][dims2[2]].z - vertices[dims0[0]][dims0[1]][dims0[2]].z) - * (vertices[dims2[0]][dims2[1]][dims2[2]].z - vertices[dims0[0]][dims0[1]][dims0[2]].z)); - double cosX2 = (vertices[dims2[0]][dims2[1]][dims2[2]].x - vertices[dims0[0]][dims0[1]][dims0[2]].x) / len2; - double cosY2 = (vertices[dims2[0]][dims2[1]][dims2[2]].y - vertices[dims0[0]][dims0[1]][dims0[2]].y) / len2; - double cosZ2 = (vertices[dims2[0]][dims2[1]][dims2[2]].z - vertices[dims0[0]][dims0[1]][dims0[2]].z) / len2; - - faces[i][0] = {{vertices[dims0[0]][dims0[1]][dims0[2]].x, vertices[dims0[0]][dims0[1]][dims0[2]].y, - vertices[dims0[0]][dims0[1]][dims0[2]].z, cosX1, cosY1, cosZ1, cosX2, cosY2, cosZ2}, - len1, - len2}; - - dims0[i] = 1; - dims1[i] = 1; - dims2[i] = 1; - len1 = TMath::Sqrt((vertices[dims1[0]][dims1[1]][dims1[2]].x - vertices[dims0[0]][dims0[1]][dims0[2]].x) - * (vertices[dims1[0]][dims1[1]][dims1[2]].x - vertices[dims0[0]][dims0[1]][dims0[2]].x) - + (vertices[dims1[0]][dims1[1]][dims1[2]].y - vertices[dims0[0]][dims0[1]][dims0[2]].y) - * (vertices[dims1[0]][dims1[1]][dims1[2]].y - vertices[dims0[0]][dims0[1]][dims0[2]].y) - + (vertices[dims1[0]][dims1[1]][dims1[2]].z - vertices[dims0[0]][dims0[1]][dims0[2]].z) - * (vertices[dims1[0]][dims1[1]][dims1[2]].z - vertices[dims0[0]][dims0[1]][dims0[2]].z)); - cosX1 = (vertices[dims1[0]][dims1[1]][dims1[2]].x - vertices[dims0[0]][dims0[1]][dims0[2]].x) / len1; - cosY1 = (vertices[dims1[0]][dims1[1]][dims1[2]].y - vertices[dims0[0]][dims0[1]][dims0[2]].y) / len1; - cosZ1 = (vertices[dims1[0]][dims1[1]][dims1[2]].z - vertices[dims0[0]][dims0[1]][dims0[2]].z) / len1; - - len2 = TMath::Sqrt((vertices[dims2[0]][dims2[1]][dims2[2]].x - vertices[dims0[0]][dims0[1]][dims0[2]].x) - * (vertices[dims2[0]][dims2[1]][dims2[2]].x - vertices[dims0[0]][dims0[1]][dims0[2]].x) - + (vertices[dims2[0]][dims2[1]][dims2[2]].y - vertices[dims0[0]][dims0[1]][dims0[2]].y) - * (vertices[dims2[0]][dims2[1]][dims2[2]].y - vertices[dims0[0]][dims0[1]][dims0[2]].y) - + (vertices[dims2[0]][dims2[1]][dims2[2]].z - vertices[dims0[0]][dims0[1]][dims0[2]].z) - * (vertices[dims2[0]][dims2[1]][dims2[2]].z - vertices[dims0[0]][dims0[1]][dims0[2]].z)); - cosX2 = (vertices[dims2[0]][dims2[1]][dims2[2]].x - vertices[dims0[0]][dims0[1]][dims0[2]].x) / len2; - cosY2 = (vertices[dims2[0]][dims2[1]][dims2[2]].y - vertices[dims0[0]][dims0[1]][dims0[2]].y) / len2; - cosZ2 = (vertices[dims2[0]][dims2[1]][dims2[2]].z - vertices[dims0[0]][dims0[1]][dims0[2]].z) / len2; - - faces[i][1] = {{vertices[dims0[0]][dims0[1]][dims0[2]].x, vertices[dims0[0]][dims0[1]][dims0[2]].y, - vertices[dims0[0]][dims0[1]][dims0[2]].z, cosX1, cosY1, cosZ1, cosX2, cosY2, cosZ2}, - len1, - len2}; - } - } -}; - -static bool Inside(const Cuboid& cuboid, const Point& point) -{ - const Point& O = cuboid.vertices[0][0][0]; - double projX = (point.x - O.x) * cuboid.dirWidth.cosX + (point.y - O.y) * cuboid.dirWidth.cosY - + (point.z - O.z) * cuboid.dirWidth.cosZ; - - if (0 > projX || projX > cuboid.width) return false; - - double projY = (point.x - O.x) * cuboid.dirHeight.cosX + (point.y - O.y) * cuboid.dirHeight.cosY - + (point.z - O.z) * cuboid.dirHeight.cosZ; - - if (0 > projY || projY > cuboid.height) return false; - - double projZ = (point.x - O.x) * cuboid.dirThickness.cosX + (point.y - O.y) * cuboid.dirThickness.cosY - + (point.z - O.z) * cuboid.dirThickness.cosZ; - - if (0 > projZ || projZ > cuboid.thickness) return false; - - return true; -} - -static bool Intersect(const Cuboid& cuboid1, const Cuboid& cuboid2) -{ - // Check if cuboid2 is inside cuboid1 - for (int i = 0; i < 2; ++i) { - for (int j = 0; j < 2; ++j) { - for (int k = 0; k < 2; ++k) { - if (Inside(cuboid1, cuboid2.vertices[i][j][k])) return true; - } - } - } - - // Check if cuboid1 is inside cuboid2 - for (int i = 0; i < 2; ++i) { - for (int j = 0; j < 2; ++j) { - for (int k = 0; k < 2; ++k) { - if (Inside(cuboid2, cuboid1.vertices[i][j][k])) return true; - } - } - } - - // Check if one edge of the cuboid2 intersects one face of the cuboid1 - for (int i = 0; i < 3; ++i) { - for (int j = 0; j < 2; ++j) { - const Rectangle& face = cuboid1.faces[i][j]; - - for (int k = 0; k < 12; ++k) { - const Segment& edge = cuboid2.edges[k]; - - if (Intersect(face, edge)) return true; - } - } - } - - // Check if one edge of the cuboid1 intersects one face of the cuboid2 - for (int i = 0; i < 3; ++i) { - for (int j = 0; j < 2; ++j) { - const Rectangle& face = cuboid2.faces[i][j]; - - for (int k = 0; k < 12; ++k) { - const Segment& edge = cuboid1.edges[k]; - - if (Intersect(face, edge)) return true; - } - } - } - - return false; -} -#endif //CBM_GLOBALTB_TOF_3D_CUBOIDS - -struct XBin { -#ifdef CBM_GLOBALTB_TOF_3D_CUBOIDS - list<Cuboid*> fCuboids; - - void Clear() - { - for (list<Cuboid*>::iterator i = fCuboids.begin(); i != fCuboids.end(); ++i) { - Cuboid* cuboid = *i; - cuboid->Clear(); - } - } -#else //CBM_GLOBALTB_TOF_3D_CUBOIDS - int fNofTBins; - TBin* fTBins; - explicit XBin(int nofTBins) : fNofTBins(nofTBins), fTBins(new TBin[fNofTBins]) {} - - void Clear() - { - for (int i = 0; i < fNofTBins; ++i) { - fTBins[i].Clear(); - } - } -#endif //CBM_GLOBALTB_TOF_3D_CUBOIDS -}; - -struct YBin { - int fNofXBins; - XBin* fXBins; - - YBin(int nofXBins, int nofTBins) - : fNofXBins(nofXBins) - , fXBins(reinterpret_cast<XBin*>(new unsigned char[fNofXBins * sizeof(XBin)])) - { - for (int i = 0; i < fNofXBins; ++i) -#ifdef CBM_GLOBALTB_TOF_3D_CUBOIDS - new (&fXBins[i]) XBin; -#else //CBM_GLOBALTB_TOF_3D_CUBOIDS - new (&fXBins[i]) XBin(nofTBins); -#endif //CBM_GLOBALTB_TOF_3D_CUBOIDS - } - - void Clear() - { - for (int i = 0; i < fNofXBins; ++i) - fXBins[i].Clear(); - } -}; - -struct ZBin { - int fNofYBins; - YBin* fYBins; - - ZBin(int nofYBins, int nofXBins, int nofTBins) - : fNofYBins(nofYBins) - , fYBins(reinterpret_cast<YBin*>(new unsigned char[fNofYBins * sizeof(YBin)])) - { - for (int i = 0; i < fNofYBins; ++i) - new (&fYBins[i]) YBin(nofXBins, nofTBins); - } - - void Clear() - { - for (int i = 0; i < fNofYBins; ++i) - fYBins[i].Clear(); - } -}; - -CbmGlobalTrackingTofGeometry::CbmGlobalTrackingTofGeometry() - : fC(0) - , fPDG(211) - , fChi2Cut(50) - , -#ifdef CBM_GLOBALTB_TOF_3D_CUBOIDS - fCuboids() - , -#endif //CBM_GLOBALTB_TOF_3D_CUBOIDS - fNofTBins(1000) - , fNofXBins(60) - , fNofYBins(60) - , fNofZBins(5) - , fZBins(0) - , fTBinSize(100) - , fMinX(1000000) - , fMaxX(-1000000) - , fXBinSize(0) - , fMinY(1000000) - , fMaxY(-1000000) - , fYBinSize(0) - , fMinZ(1000000) - , fMaxZ(-1000000) - , fZBinSize(0) - , fStartTime(0) - , fEndTime(0) - , fTofHits(0) //, fPropagator() -{ -} - -CbmGlobalTrackingTofGeometry::~CbmGlobalTrackingTofGeometry() -{ -#ifdef CBM_GLOBALTB_TOF_3D_CUBOIDS - for (list<Cuboid*>::iterator i = fCuboids.begin(); i != fCuboids.end(); ++i) - delete *i; -#endif //CBM_GLOBALTB_TOF_3D_CUBOIDS -} - -static void FindGeoChild(TGeoNode* node, const char* name, list<TGeoNode*>& results) -{ - Int_t nofChildren = node->GetNdaughters(); - - for (Int_t i = 0; i < nofChildren; ++i) { - TGeoNode* child = node->GetDaughter(i); - TString childName(child->GetName()); - - if (childName.Contains(name, TString::kIgnoreCase)) results.push_back(child); - } -} - -bool CbmGlobalTrackingTofGeometry::Read() -{ - fC = 1.e-7 * TMath::C(); - fPropagator = CbmLitToolFactory::CreateTrackPropagator("lit"); - fLinePropagator = CbmLitToolFactory::CreateTrackPropagator("line"); - fFilter = CbmLitToolFactory::CreateTrackUpdate("kalman"); - TGeoNavigator* pNavigator = gGeoManager->GetCurrentNavigator(); - gGeoManager->cd("/cave_1"); - list<TGeoNode*> tofNodes; - FindGeoChild(gGeoManager->GetCurrentNode(), "tof", tofNodes); - - if (tofNodes.empty()) return false; - - TGeoNode* tofNode = tofNodes.front(); - pNavigator->CdDown(tofNode); - - list<TGeoNode*> tofModules; - FindGeoChild(tofNode, "module", tofModules); - - for (list<TGeoNode*>::iterator i = tofModules.begin(); i != tofModules.end(); ++i) { - TGeoNode* tofModule = *i; - const char* modName = tofModule->GetName(); - const char* firstUnd = strchr(modName, '_'); - const char* lastUnd = strrchr(modName, '_'); - - if (0 == firstUnd || 0 == lastUnd) continue; - - //int modType = atoi(firstUnd + 1); (VF) unused - //int modNum = atoi(lastUnd + 1); (VF) unused - - pNavigator->CdDown(tofModule); - list<TGeoNode*> tofGasBoxes; - FindGeoChild(tofModule, "gas_box", tofGasBoxes); - - for (list<TGeoNode*>::iterator j = tofGasBoxes.begin(); j != tofGasBoxes.end(); ++j) { - TGeoNode* tofGasBox = *j; - pNavigator->CdDown(tofGasBox); - list<TGeoNode*> tofModuleCounters; - FindGeoChild(tofGasBox, "counter", tofModuleCounters); - - for (list<TGeoNode*>::iterator k = tofModuleCounters.begin(); k != tofModuleCounters.end(); ++k) { - TGeoNode* tofModuleCounter = *k; - const char* counterName = tofModuleCounter->GetName(); - - const char* lastUnd2 = strrchr(counterName, '_'); - - if (0 == lastUnd2) continue; - - //int counterNum = atoi(lastUnd2 + 1); (VF) unused - - pNavigator->CdDown(tofModuleCounter); - TGeoVolume* tofModuleCounterVol = gGeoManager->GetCurrentVolume(); - const TGeoBBox* tofModuleCounterShape = static_cast<const TGeoBBox*>(tofModuleCounterVol->GetShape()); - Double_t halfwidth = tofModuleCounterShape->GetDX(); - Double_t halfheight = tofModuleCounterShape->GetDY(); - Double_t halfthickness = tofModuleCounterShape->GetDZ(); - -#ifdef CBM_GLOBALTB_TOF_3D_CUBOIDS - Cuboid* cuboid = new Cuboid({2 * halfwidth, 2 * halfheight, 2 * halfthickness}); - cuboid->fFullModId = - CbmTofAddress::GetModFullId(CbmTofAddress::GetUniqueAddress(modNum, counterNum, 0, 0, modType)); -#endif //CBM_GLOBALTB_TOF_3D_CUBOIDS - - /*Int_t modId0 = CbmTofAddress::GetModFullId(CbmTofAddress::GetUniqueAddress(modNum, counterNum, 0, 0, modType)); - Int_t modId1 = CbmTofAddress::GetModFullId(CbmTofAddress::GetUniqueAddress(modNum, counterNum, 1, 0, modType)); - Int_t modId2 = CbmTofAddress::GetModFullId(CbmTofAddress::GetUniqueAddress(modNum, counterNum, 2, 0, modType)); - Int_t modId3 = CbmTofAddress::GetModFullId(CbmTofAddress::GetUniqueAddress(modNum, counterNum, 3, 0, modType)); - Int_t modId0_1 = CbmTofAddress::GetModFullId(CbmTofAddress::GetUniqueAddress(modNum, counterNum, 0, 1, modType)); - Int_t modId1_1 = CbmTofAddress::GetModFullId(CbmTofAddress::GetUniqueAddress(modNum, counterNum, 1, 1, modType)); - Int_t modId2_1 = CbmTofAddress::GetModFullId(CbmTofAddress::GetUniqueAddress(modNum, counterNum, 2, 1, modType)); - Int_t modId3_1 = CbmTofAddress::GetModFullId(CbmTofAddress::GetUniqueAddress(modNum, counterNum, 3, 1, modType));*/ - - for (int t = 0; t < 2; ++t) // t means thickness - { - for (int h = 0; h < 2; ++h) // h means height - { - for (int w = 0; w < 2; ++w) // w means width - { - Double_t localCoords[3] = {w > 0 ? halfwidth : -halfwidth, h > 0 ? halfheight : -halfheight, - t > 0 ? halfthickness : -halfthickness}; - Double_t globalCoords[3]; - gGeoManager->LocalToMaster(localCoords, globalCoords); -#ifdef CBM_GLOBALTB_TOF_3D_CUBOIDS - cuboid->vertices[t][h][w] = {globalCoords[0], globalCoords[1], globalCoords[2]}; -#endif //CBM_GLOBALTB_TOF_3D_CUBOIDS - - if (fMinX > globalCoords[0]) fMinX = globalCoords[0]; - - if (fMaxX < globalCoords[0]) fMaxX = globalCoords[0]; - - if (fMinY > globalCoords[1]) fMinY = globalCoords[1]; - - if (fMaxY < globalCoords[1]) fMaxY = globalCoords[1]; - - if (fMinZ > globalCoords[2]) fMinZ = globalCoords[2]; - - if (fMaxZ < globalCoords[2]) fMaxZ = globalCoords[2]; - } - } - } - -#ifdef CBM_GLOBALTB_TOF_3D_CUBOIDS - cuboid->Calc(fNofTBins); - fCuboids.push_back(cuboid); -#endif //CBM_GLOBALTB_TOF_3D_CUBOIDS - pNavigator->CdUp(); - } - - pNavigator->CdUp(); - } - - pNavigator->CdUp(); - } - - pNavigator->CdUp(); - - fXBinSize = (fMaxX - fMinX) / fNofXBins; - fYBinSize = (fMaxY - fMinY) / fNofYBins; - fZBinSize = (fMaxZ - fMinZ) / fNofZBins; - - // Create search bins - fZBins = reinterpret_cast<ZBin*>(new unsigned char[fNofZBins * sizeof(ZBin)]); - - for (int i = 0; i < fNofZBins; ++i) - new (&fZBins[i]) ZBin(fNofYBins, fNofXBins, fNofTBins); - -#ifdef CBM_GLOBALTB_TOF_3D_CUBOIDS - // Create references to the existing cuboids - for (list<Cuboid*>::iterator iter = fCuboids.begin(); iter != fCuboids.end(); ++iter) { - Cuboid* cuboid = *iter; - int zIndMin = GetZInd(cuboid->minZ); - int zIndMax = GetZInd(cuboid->maxZ); - int yIndMin = GetYInd(cuboid->minY); - int yIndMax = GetYInd(cuboid->maxY); - int xIndMin = GetXInd(cuboid->minX); - int xIndMax = GetXInd(cuboid->maxX); - - for (int zInd = zIndMin; zInd <= zIndMax; ++zInd) { - ZBin& zBin = fZBins[zInd]; - - for (int yInd = yIndMin; yInd <= yIndMax; ++yInd) { - YBin& yBin = zBin.fYBins[yInd]; - - for (int xInd = xIndMin; xInd <= xIndMax; ++xInd) { - XBin& xBin = yBin.fXBins[xInd]; - Cuboid cuboid2 = {fXBinSize, fYBinSize, fZBinSize}; - - for (int i = 0; i < 2; ++i) { - for (int j = 0; j < 2; ++j) { - for (int k = 0; k < 2; ++k) - cuboid2.vertices[i][j][k] = {fMinX + (xInd + k) * fXBinSize, fMinY + (yInd + j) * fYBinSize, - fMinZ + (zInd + i) * fZBinSize}; - } - } - - cuboid2.Calc(); - - if (Intersect(*cuboid, cuboid2)) xBin.fCuboids.push_back(cuboid); - } - } - } - } // for (list<Cuboid*>::iterator i = fCuboids.begin(); i != fCuboids.end(); ++i) -#endif //CBM_GLOBALTB_TOF_3D_CUBOIDS - - return true; -} - -void CbmGlobalTrackingTofGeometry::Clear() -{ - for (int i = 0; i < fNofZBins; ++i) - fZBins[i].Clear(); -} - -int globalNofHits = 0; -int globalNofHitsT = 0; -int globalNofHitsM = 0; - -void CbmGlobalTrackingTofGeometry::Prepare(timetype startTime) -{ - Clear(); - fStartTime = startTime; - fEndTime = fStartTime + fNofTBins * fTBinSize; - - int nofHits = fTofHits->GetEntriesFast(); - globalNofHits += nofHits; - - for (int i = 0; i < nofHits; ++i) { - const CbmTofHit* hit = static_cast<const CbmTofHit*>(fTofHits->At(i)); - scaltype z = hit->GetZ(); - - if (z < fMinZ || z > fMaxZ) continue; - - int zInd = GetZInd(z); - ZBin& zBin = fZBins[zInd]; - scaltype y = hit->GetY(); - - if (y < fMinY || y > fMaxY) continue; - - int yInd = GetYInd(y); - YBin& yBin = zBin.fYBins[yInd]; - scaltype x = hit->GetX(); - - if (x < fMinX || x > fMaxX) continue; - - int xInd = GetXInd(x); - XBin& xBin = yBin.fXBins[xInd]; - -#ifdef CBM_GLOBALTB_TOF_3D_CUBOIDS - if (xBin.fCuboids.empty()) continue; -#endif //CBM_GLOBALTB_TOF_3D_CUBOIDS - - timetype t = hit->GetTime(); - - if (t < fStartTime || t > fEndTime) continue; - - ++globalNofHitsT; - - int tInd = GetTInd(t); - -#ifdef CBM_GLOBALTB_TOF_3D_CUBOIDS - Int_t address = hit->GetAddress(); - Int_t moduleId = CbmTofAddress::GetModFullId(address); - - for (list<Cuboid*>::iterator j = xBin.fCuboids.begin(); j != xBin.fCuboids.end(); ++j) { - Cuboid* mrpc = *j; - - if (mrpc->fFullModId == moduleId) { - mrpc->fTBins[tInd].fHitInds.push_back(i); - ++globalNofHitsM; - } - } -#else //CBM_GLOBALTB_TOF_3D_CUBOIDS - TBin& tBin = xBin.fTBins[tInd]; - tBin.fHitInds.push_back(i); -#endif //CBM_GLOBALTB_TOF_3D_CUBOIDS - } -} - -int nofMRPCIntersections = 0; -int nofToFIntersections = 0; -int nofMRPCIntersectionsT = 0; - -void CbmGlobalTrackingTofGeometry::Find(FairTrackParam& trackParams, timetype trackTime, timetype errT, - Int_t& tofHitInd, Double_t& length) -//void CbmGlobalTrackingTofGeometry::Find(scaltype x0, scaltype errX, scaltype y0, scaltype errY, scaltype z0, scaltype t0, scaltype errT, -//scaltype tx, scaltype errTx, scaltype ty, scaltype errTy, Int_t& tofHitInd) -//void CbmGlobalTrackingTofGeometry::Find(scaltype x0, scaltype errXSq, scaltype y0, scaltype errYSq, scaltype z0, scaltype t0, scaltype errT, -//scaltype tx, scaltype errTx, scaltype ty, scaltype errTy, Int_t& tofHitInd) -{ - tofHitInd = -1; - Double_t stsTrackLength = length; - length = 0; - //double x0 = trackParams.GetX(); - - //if (x0 < fMinX || x0 > fMaxX) - //return; - - //double y0 = trackParams.GetY(); - - //if (y0 < fMinY || y0 > fMaxY) - //return; - - //double z0 = trackParams.GetZ(); - //double t0 = fStartTime;//trackParams.GetTime(); - //double tx = trackParams.GetTx(); - //double ty = trackParams.GetTy(); - - //double deltaZ1 = fMinZ - z0; - //double x1 = x0 + tx * deltaZ1; - //double y1 = y0 + ty * deltaZ1; - double z1 = fMinZ; - CbmTrackParam cbmTrackParams; - cbmTrackParams.Set(trackParams, trackTime, errT); - CbmLitTrackParam litTrackParams; - CbmLitConverterFairTrackParam::FairTrackParamToCbmLitTrackParam(&cbmTrackParams, &litTrackParams); - - if (fPropagator->Propagate(&litTrackParams, z1, fPDG, 0, &length) == kLITERROR) { - length = 0; - return; - } - - double x1 = litTrackParams.GetX(); - double y1 = litTrackParams.GetY(); - - //if (fMinX > x1 || x1 > fMaxX || fMinY > y1 || y1 > fMaxY) - //return; - - // First check if track exits from the ToF XYZ manifold from the back face. - double deltaZMax = fMaxZ - z1; - double tx = litTrackParams.GetTx(); - double xMax = x1 + tx * deltaZMax; - double ty = litTrackParams.GetTy(); - double yMax = y1 + ty * deltaZMax; - double normLen = TMath::Sqrt(1 + tx * tx + ty * ty); - //double t1 = trackTime + z1 * normLen / fC; - double t1 = trackTime + (stsTrackLength + length) / fC; - //double t1 = litTrackParams.GetTime(); - double zMax; - - map<int, map<int, map<int, double>>> inds; - - /*for (int i = 0; i < 25; ++i) - { - double val = litTrackParams.GetCovariance(i); - int qq = 0; - }*/ - - double deltaX = 4 * TMath::Sqrt(litTrackParams.GetCovariance(0)); - double deltaY = 4 * TMath::Sqrt(litTrackParams.GetCovariance(6)); - double deltaT = 4 * errT; - //double deltaT = 4 * litTrackParams.GetTimeError(); - //Find(x1 - deltaX, y1 - deltaY, z1, tx, ty, inds); - //Find(x1 + deltaX, y1 - deltaY, z1, tx, ty, inds); - //Find(x1 - deltaX, y1 + deltaY, z1, tx, ty, inds); - //Find(x1 + deltaX, y1 + deltaY, z1, tx, ty, inds); - - - if (fMinX <= xMax && xMax <= fMaxX && fMinY <= yMax && yMax <= fMaxY) zMax = fMaxZ; - else if (ty > 0 && (fMaxY - y1) / ty < fMaxZ - z1 && fMinX <= x1 + tx * (fMaxY - y1) / ty - && x1 + tx * (fMaxY - y1) / ty <= fMaxX) { - zMax = z1 + (fMaxY - y1) / ty; - yMax = fMaxY; - xMax = x1 + tx * (fMaxY - y1) / ty; - } - else if (ty < 0 && (fMinY - y1) / ty < fMaxZ - z1 && fMinX <= x1 + tx * (fMinY - y1) / ty - && x1 + tx * (fMinY - y1) / ty <= fMaxX) { - zMax = z1 + (fMinY - y1) / ty; - yMax = fMinY; - xMax = x1 + tx * (fMinY - y1) / ty; - } - else if (tx > 0 && (fMaxX - x1) / tx < fMaxZ - z1 && fMinY <= y1 + ty * (fMaxX - x1) / tx - && y1 + ty * (fMaxX - x1) / tx <= fMaxY) { - zMax = z1 + (fMaxX - x1) / tx; - yMax = y1 + ty * (fMaxX - x1) / tx; - xMax = fMaxX; - } - else if (tx < 0 && (fMinX - x1) / tx < fMaxZ - z1 && fMinY <= y1 + ty * (fMinX - x1) / tx - && y1 + ty * (fMinX - x1) / tx <= fMaxY) { - zMax = z1 + (fMinX - x1) / tx; - yMax = y1 + ty * (fMinX - x1) / tx; - xMax = fMinX; - } - else - return; - - ++nofToFIntersections; - -#ifdef CBM_GLOBALTB_TOF_3D_CUBOIDS - set<const Cuboid*> cuboidSet; -#else //CBM_GLOBALTB_TOF_3D_CUBOIDS - double minChi2 = std::numeric_limits<double>::max(); - const CbmTofHit* mergingHit = 0; - double deltaLength = 0; - Line line = {x1, y1, z1, tx / normLen, ty / normLen, 1 / normLen}; -#endif //CBM_GLOBALTB_TOF_3D_CUBOIDS - - set<const TBin*> neighbourhood; - - int zMinInd = GetZInd(fMinZ); - int zMaxInd = GetZInd(zMax); - - for (int zInd = zMinInd; zInd <= zMaxInd; ++zInd) { - const ZBin& zBin = fZBins[zInd]; - double startZ = fMinZ + zInd * fZBinSize; - double stopZ = startZ + fZBinSize; - int yIndDelta = ty < 0 ? -1 : 1; - double startY = y1 + (startZ - z1) * ty; // - yIndDelta * deltaY; - double stopY = y1 + (stopZ - z1) * ty; // + yIndDelta * deltaY; - int yStartInd = GetYInd(startY); - int yStopInd = GetYInd(stopY); - - for (int yInd = yStartInd; true; yInd += yIndDelta) { - //const YBin& yBin = zBin.fYBins[yInd]; (VF) unused - double startZy; - double stopZy; - - if (0 == ty) { - startZy = startZ; - stopZy = stopZ; - } - else if (0 > ty) { - startZy = z1 + (fMinY + (yInd + 1) * fYBinSize - y1) / ty; - stopZy = z1 + (fMinY + yInd * fYBinSize - y1) / ty; - } - else { - startZy = z1 + (fMinY + yInd * fYBinSize - y1) / ty; - stopZy = z1 + (fMinY + (yInd + 1) * fYBinSize - y1) / ty; - } - - if (startZy < startZ) startZy = startZ; - - if (stopZy > stopZ) stopZy = stopZ; - - //int xIndDelta = tx < 0 ? -1 : 1; (VF) unused - double startX = x1 + (startZy - z1) * tx; // - xIndDelta * deltaX; - double stopX = x1 + (stopZy - z1) * tx; // + xIndDelta * deltaX; - //int xStartInd = GetXInd(startX); (VF) unused - //int xStopInd = GetXInd(stopX); (VF) unused - //#ifndef CBM_GLOBALTB_TOF_3D_CUBOIDS - double extLen = ((startZy + stopZy) / 2 - z1) * normLen; - double extT = t1 + extLen / fC; - //int tInd = (extT - fStartTime) / fTBinSize; - int tLowInd = (extT - deltaT - fStartTime) / fTBinSize; - int tHighInd = (extT + deltaT - fStartTime) / fTBinSize; - - if (tHighInd >= 0 || tLowInd < fNofTBins) { - if (tLowInd < 0) tLowInd = 0; - - if (tHighInd >= fNofTBins) tHighInd = fNofTBins - 1; - - double startY2 = startY < stopY ? startY - deltaY : stopY - deltaY; - double stopY2 = startY < stopY ? stopY + deltaY : startY + deltaY; - int yStartInd2 = GetYInd(startY2); - int yStopInd2 = GetYInd(stopY2); - double startX2 = startX < stopX ? startX - deltaX : stopX - deltaX; - double stopX2 = startX < stopX ? stopX + deltaX : startX + deltaX; - int xStartInd2 = GetXInd(startX2); - int xStopInd2 = GetXInd(stopX2); - - for (int yInd2 = yStartInd2; yInd2 <= yStopInd2; ++yInd2) { - const YBin& yBin2 = zBin.fYBins[yInd2]; - - for (int xInd2 = xStartInd2; xInd2 <= xStopInd2; ++xInd2) { - const XBin& xBin2 = yBin2.fXBins[xInd2]; - - for (int tInd2 = tLowInd; tInd2 <= tHighInd; ++tInd2) - neighbourhood.insert(&xBin2.fTBins[tInd2]); - } - } - } - - if (yInd == yStopInd) break; - } - } - - for (set<const TBin*>::const_iterator tBinIter = neighbourhood.begin(); tBinIter != neighbourhood.end(); ++tBinIter) { - const TBin* tBin = *tBinIter; - - for (list<Int_t>::const_iterator hitIndIter = tBin->fHitInds.begin(); hitIndIter != tBin->fHitInds.end(); - ++hitIndIter) { - Int_t hitInd = *hitIndIter; - const CbmTofHit* hit = static_cast<const CbmTofHit*>(fTofHits->At(hitInd)); - double L01Sq = (hit->GetX() - x1) * (hit->GetX() - x1) + (hit->GetY() - y1) * (hit->GetY() - y1) - + (hit->GetZ() - z1) * (hit->GetZ() - z1); - //double L01 = TMath::Sqrt(L01Sq); - double L02 = (hit->GetX() - x1) * line.cosX + (hit->GetY() - y1) * line.cosY + (hit->GetZ() - z1) * line.cosZ; - double extT2 = t1 + L02 / fC; - /*double x = x1 + L02 * line.cosX; - double y = y1 + L02 * line.cosY; - double z = z1 + L02 * line.cosZ; - double extT2 = t1 + TMath::Sqrt(x * x + y * y + z * z) / fC;*/ - double chi2 = (L01Sq - L02 * L02) - / (litTrackParams.GetCovariance(0) + hit->GetDx() * hit->GetDx() + litTrackParams.GetCovariance(5) - + hit->GetDy() * hit->GetDy()) - + (hit->GetTime() - extT2) * (hit->GetTime() - extT2) - / (/*litTrackParams.GetTimeError() * litTrackParams.GetTimeError()*/ - errT * errT + hit->GetTimeError() * hit->GetTimeError()); - - if (chi2 < minChi2) { - tofHitInd = hitInd; - mergingHit = hit; - minChi2 = chi2; - deltaLength = L02; - } - } - } - - if (minChi2 > fChi2Cut) { - tofHitInd = -1; - length = 0; - } - else { - length += deltaLength; - fLinePropagator->Propagate(&litTrackParams, mergingHit->GetZ(), fPDG); - CbmLitPixelHit litHit; - CbmLitConverter::CbmPixelHitToCbmLitPixelHit(mergingHit, tofHitInd, &litHit); - double mergingChi2 = 0; - fFilter->Update(&litTrackParams, &litHit, mergingChi2); - CbmLitConverterFairTrackParam::CbmLitTrackParamToFairTrackParam(&litTrackParams, &trackParams); - } - -#if 0 - if (tInd >= 0 && tInd < fNofTBins) - { -//#endif//CBM_GLOBALTB_TOF_3D_CUBOIDS - for (int xInd = xStartInd; true; xInd += xIndDelta) - { - const XBin& xBin = yBin.fXBins[xInd]; - -#ifdef CBM_GLOBALTB_TOF_3D_CUBOIDS - for (list<Cuboid*>::const_iterator i = xBin.fCuboids.begin(); i != xBin.fCuboids.end(); ++i) - cuboidSet.insert(*i); -#else //CBM_GLOBALTB_TOF_3D_CUBOIDS - const TBin& tBin = xBin.fTBins[tInd]; - - for (list<Int_t>::const_iterator hitIndIter = tBin.fHitInds.begin(); hitIndIter != tBin.fHitInds.end(); ++hitIndIter) - { - Int_t hitInd = *hitIndIter; - const CbmTofHit* hit = static_cast<const CbmTofHit*> (fTofHits->At(hitInd)); - double L01Sq = (hit->GetX() - x1) * (hit->GetX() - x1) + (hit->GetY() - y1) * (hit->GetY() - y1) + (hit->GetZ() - z1) * (hit->GetZ() - z1); - //double L01 = TMath::Sqrt(L01Sq); - double L02 = (hit->GetX() - x1) * line.cosX + (hit->GetY() - y1) * line.cosY + (hit->GetZ() - z1) * line.cosZ; - double extT2 = t1 + L02 / fC; - double chi2 = (L01Sq - L02 * L02) / (litTrackParams.GetCovariance(0) + hit->GetDx() * hit->GetDx() + litTrackParams.GetCovariance(6) + hit->GetDy() * hit->GetDy()) + - (hit->GetTime() - extT2) * (hit->GetTime() - extT2) / (litTrackParams.GetTimeError() * litTrackParams.GetTimeError() + hit->GetTimeError() * hit->GetTimeError()); - - if (chi2 < minChi2) - { - tofHitInd = hitInd; - minChi2 = chi2; - } - } -#endif //CBM_GLOBALTB_TOF_3D_CUBOIDS - - if (xInd == xStopInd) - break; - } -#ifndef CBM_GLOBALTB_TOF_3D_CUBOIDS - } -#endif //CBM_GLOBALTB_TOF_3D_CUBOIDS - - if (yInd == yStopInd) - break; - } - } -#endif // 0 - - /*double minChi2 = std::numeric_limits<double>::max(); - Line line = { x1, y1, z1, tx / normLen, ty / normLen, 1 / normLen }; - - for (map<int, map<int, map<int, double> > >::const_iterator i = inds.begin(); i != inds.end(); ++i) - { - const map<int, map<int, double> >& yInds = i->second; - - for (map<int, map<int, double> >::const_iterator j = yInds.begin(); j != yInds.end(); ++j) - { - const map<int, double>& xInds = j->second; - - for (map<int, double>::const_iterator k = xInds.begin(); k != xInds.end(); ++k) - { - const XBin& xBin = fZBins[i->first].fYBins[j->first].fXBins[k->first]; - double extT = t1 + k->second / fC; - int tInd = (extT - fStartTime) / fTBinSize; - const TBin& tBin = xBin.fTBins[tInd]; - - for (list<Int_t>::const_iterator hitIndIter = tBin.fHitInds.begin(); hitIndIter != tBin.fHitInds.end(); ++hitIndIter) - { - Int_t hitInd = *hitIndIter; - const CbmTofHit* hit = static_cast<const CbmTofHit*> (fTofHits->At(hitInd)); - double L01Sq = (hit->GetX() - x1) * (hit->GetX() - x1) + (hit->GetY() - y1) * (hit->GetY() - y1) + (hit->GetZ() - z1) * (hit->GetZ() - z1); - //double L01 = TMath::Sqrt(L01Sq); - double L02 = (hit->GetX() - x1) * line.cosX + (hit->GetY() - y1) * line.cosY + (hit->GetZ() - z1) * line.cosZ; - double extT2 = t1 + L02 / fC; - double chi2 = (L01Sq - L02 * L02) / (litTrackParams.GetCovariance(0) + hit->GetDx() * hit->GetDx() + litTrackParams.GetCovariance(6) + hit->GetDy() * hit->GetDy()) + - (hit->GetTime() - extT2) * (hit->GetTime() - extT2) / (errT * errT + hit->GetTimeError() * hit->GetTimeError()); - - if (chi2 < minChi2) { - tofHitInd = hitInd; - minChi2 = chi2; - } - } - } - } - }*/ - -#ifdef CBM_GLOBALTB_TOF_3D_CUBOIDS - if (cuboidSet.empty()) return; - - bool inMRPC = false; - bool inMRPCT = false; - - double minChi2 = std::numeric_limits<double>::max(); - double normLen = TMath::Sqrt(1 + tx * tx + ty * ty); - Line line = {x1, y1, z1, tx / normLen, ty / normLen, 1 / normLen}; - - for (set<const Cuboid*>::const_iterator i = cuboidSet.begin(); i != cuboidSet.end(); ++i) { - const Cuboid* cuboid = *i; - const Rectangle& face1 = cuboid->faces[0][0]; - const Rectangle& face2 = cuboid->faces[0][1]; - double result[3]; - - if (Intersect(face1, line, result) || Intersect(face2, line, result)) { - inMRPC = true; - double extT = t0 + result[2] / fC; - int tInd = (extT - fStartTime) / fTBinSize; - - if (tInd < 0 || tInd >= fNofTBins) continue; - - inMRPCT = true; - - //const TBin& tBin = xBin.f - double extX = x1 + line.cosX * result[2]; - double extY = y1 + line.cosY * result[2]; - double extZ = z1 + line.cosZ * result[2]; - TBin& tBin = cuboid->fTBins[tInd]; - - for (list<Int_t>::const_iterator hitIndIter = tBin.fHitInds.begin(); hitIndIter != tBin.fHitInds.end(); - ++hitIndIter) { - Int_t hitInd = *hitIndIter; - const CbmTofHit* hit = static_cast<const CbmTofHit*>(fTofHits->At(hitInd)); - double chi2 = (hit->GetX() - extX) * (hit->GetX() - extX) / (errX * errX + hit->GetDx() * hit->GetDx()) - + (hit->GetY() - extY) * (hit->GetY() - extY) / (errY * errY + hit->GetDy() * hit->GetDy()) - + (hit->GetTime() - extT) * (hit->GetTime() - extT) - / (litTrackParams.GetTimeError() * litTrackParams.GetTimeError() - + hit->GetTimeError() * hit->GetTimeError()); - - if (chi2 < minChi2) { - tofHitInd = hitInd; - minChi2 = chi2; - } - } - } - } - - if (inMRPC) ++nofMRPCIntersections; - - if (inMRPCT) ++nofMRPCIntersectionsT; -#endif //CBM_GLOBALTB_TOF_3D_CUBOIDS -} diff --git a/reco/tracking/global/CbmGlobalTrackingTof.h b/reco/tracking/global/CbmGlobalTrackingTof.h deleted file mode 100644 index c6e36c6beb47b37dc9eed3a06b0020c3424fecc1..0000000000000000000000000000000000000000 --- a/reco/tracking/global/CbmGlobalTrackingTof.h +++ /dev/null @@ -1,141 +0,0 @@ -/* Copyright (C) 2017 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -#ifndef CBMGLOBALTRACKINGTOF_H -#define CBMGLOBALTRACKINGTOF_H - -#include "CbmGlobalTrackingDefs.h" - -#include "FairTrackParam.h" - -#include "TClonesArray.h" - -#include <list> -#include <map> -#include <set> - -#define CBM_GLOBALTB_TOF_3D - -#ifdef CBM_GLOBALTB_TOF_3D -//#define CBM_GLOBALTB_TOF_3D_CUBOIDS -#endif //CBM_GLOBALTB_TOF_3D - -#ifdef CBM_GLOBALTB_TOF_3D -#ifdef CBM_GLOBALTB_TOF_3D_CUBOIDS -struct Cuboid; -#endif //CBM_GLOBALTB_TOF_3D_CUBOIDS -struct ZBin; -#endif //CBM_GLOBALTB_TOF_3D - -class CbmGlobalTrackingTofGeometry { -public: - struct Rect { - scaltype minX; - scaltype maxX; - scaltype minY; - scaltype maxY; - }; - - CbmGlobalTrackingTofGeometry(); - - CbmGlobalTrackingTofGeometry(const CbmGlobalTrackingTofGeometry&) = delete; - CbmGlobalTrackingTofGeometry& operator=(const CbmGlobalTrackingTofGeometry&) = delete; - - ~CbmGlobalTrackingTofGeometry(); - bool Read(); - - void SetPdg(Int_t v) { fPDG = v; } - - void SetChi2Cut(Double_t v) { fChi2Cut = v; } - - int GetXInd(scaltype x) const - { - int ind = (x - fMinX) / fXBinSize; - - if (ind < 0) ind = 0; - else if (ind >= fNofXBins) - ind = fNofXBins - 1; - - return ind; - } - - int GetYInd(scaltype y) const - { - int ind = (y - fMinY) / fYBinSize; - - if (ind < 0) ind = 0; - else if (ind >= fNofYBins) - ind = fNofYBins - 1; - - return ind; - } - - int GetZInd(scaltype z) const - { - int ind = (z - fMinZ) / fZBinSize; - - if (ind < 0) ind = 0; - else if (ind >= fNofZBins) - ind = fNofZBins - 1; - - return ind; - } - - int GetTInd(timetype t) const - { - int ind = (t - fStartTime) / fTBinSize; - - if (ind < 0) ind = 0; - else if (ind >= fNofTBins) - ind = fNofTBins - 1; - - return ind; - } - - void SetNofTBins(int v) { fNofTBins = v; } - - void SetTBinSize(scaltype v) { fStartTime = v; } - - void SetStartTime(timetype v) { fTBinSize = v; } - - void SetTofHits(TClonesArray* v) { fTofHits = v; } - - void Clear(); - void Prepare(timetype startTime); - void Find(FairTrackParam& trackParams, timetype trackTime, timetype errT, Int_t& tofHitInd, Double_t& length); - -private: - scaltype fC; - Int_t fPDG; - Double_t fChi2Cut; -#ifdef CBM_GLOBALTB_TOF_3D_CUBOIDS - std::list<Cuboid*> fCuboids; -#endif //CBM_GLOBALTB_TOF_3D_CUBOIDS - int fNofTBins; - int fNofXBins; - int fNofYBins; - int fNofZBins; - ZBin* fZBins; - scaltype fTBinSize; - scaltype fMinX; - scaltype fMaxX; - scaltype fXBinSize; - scaltype fMinY; - scaltype fMaxY; - scaltype fYBinSize; - scaltype fMinZ; - scaltype fMaxZ; - scaltype fZBinSize; - timetype fStartTime; - timetype fEndTime; - TClonesArray* fTofHits; -}; - -#endif /* CBMGLOBALTRACKINGTOF_H */ diff --git a/reco/tracking/global/GlobalLinkDef.h b/reco/tracking/global/GlobalLinkDef.h deleted file mode 100644 index 7bd6f19ab433ae903818816d0521b73127bd9696..0000000000000000000000000000000000000000 --- a/reco/tracking/global/GlobalLinkDef.h +++ /dev/null @@ -1,16 +0,0 @@ -/* Copyright (C) 2017 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -// $Id: LxLinkDef.h,v 1.10 2013/09/30 11:36:47 tablyaz Exp $ - -#ifdef __CINT__ - -#pragma link off all globals; -#pragma link off all classes; -#pragma link off all functions; - -#pragma link C++ class CbmGlobalTrackingTask + ; -#pragma link C++ class CbmGlobalTrackingQa + ; - -#endif diff --git a/reco/tracking/lx/CMakeLists.txt b/reco/tracking/lx/CMakeLists.txt deleted file mode 100755 index c427d71c882334a3a664761d53c96b97082df7eb..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/CMakeLists.txt +++ /dev/null @@ -1,53 +0,0 @@ -# Create a library called "libLxTrack" which includes the source files given in -# the array . -# The extension is already found. Any number of sources could be listed -# here. - -set(INCLUDE_DIRECTORIES - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/TBBinned - ${CMAKE_CURRENT_SOURCE_DIR}/GenNoiseElectrons - ${CMAKE_CURRENT_SOURCE_DIR}/CalcStats - ) -set(SRCS - TBBinned/LxTBTask.cxx -# TBBinned/LxTBMLTask.cxx - TBBinned/LxTBTieTracks.cxx - TBBinned/LxTBTrdTask.cxx - GenNoiseElectrons/GenNoiseElectrons.cxx - CalcStats/CalcStats.cxx - ) - -set(NO_DICT_SRCS -# LxTBMatEffs.cxx -# LxTBNaive.cxx -) - - -set(LIBRARY_NAME LxTrack) -set(LINKDEF LxLinkDef.h) -set(PUBLIC_DEPENDENCIES - CbmBase - CbmData - KF - ROOT::Core - ROOT::Geom - ROOT::Hist - ) - -set(PRIVATE_DEPENDENCIES - ROOT::Gpad - CbmMuchSim - Littrack - ) - -set(INTERFACE_DEPENDENCIES - CbmMuchBase - ROOT::EG - ROOT::Graf - ROOT::MathCore - ROOT::RIO - ) - - -generate_cbm_library() diff --git a/reco/tracking/lx/CalcStats/CalcStats.cxx b/reco/tracking/lx/CalcStats/CalcStats.cxx deleted file mode 100644 index dedce8a766ea1390f1d7696d1553faa6ffc7584d..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/CalcStats/CalcStats.cxx +++ /dev/null @@ -1,198 +0,0 @@ -/* Copyright (C) 2016-2020 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#include "CalcStats.h" - -#include "CbmMCTrack.h" -#include "CbmMuchGeoScheme.h" -#include "CbmMuchPoint.h" -#include "CbmTrdAddress.h" -#include "CbmTrdPoint.h" - -#include <FairRootManager.h> -#include <Logger.h> - -#include "TClonesArray.h" -#include <TFile.h> - -#include <list> -#include <map> - -ClassImp(LxCalcStats) - - using namespace std; - -struct LxStatTrack { - list<Int_t> muchPoints[4][3]; - list<Int_t> trdPoints[4]; -}; - -LxCalcStats::LxCalcStats() : fMCTracks(0), fMuchPoints(0), fTrdPoints(0) {} - -InitStatus LxCalcStats::Init() -{ - FairRootManager* ioman = FairRootManager::Instance(); - - if (0 == ioman) LOG(fatal) << "No FairRootManager"; - - fMCTracks = static_cast<TClonesArray*>(ioman->GetObject("MCTrack")); - fMuchPoints = static_cast<TClonesArray*>(ioman->GetObject("MuchPoint")); - fTrdPoints = static_cast<TClonesArray*>(ioman->GetObject("TrdPoint")); - - if (0 == fMCTracks || (0 == fMuchPoints && 0 == fTrdPoints)) LOG(fatal) << "No MC tracks or points"; - - size_t buf_size = 128; - char buf[buf_size]; - - for (int i = 0; i < 4; ++i) { - for (int j = 0; j < 3; ++j) { - snprintf(buf, buf_size - 1, "noise_e_x_%d_%d", i, j); - xHistos[i][j] = new TH1F(buf, buf, 240, -30., 30.); - snprintf(buf, buf_size - 1, "noise_e_y_%d_%d", i, j); - yHistos[i][j] = new TH1F(buf, buf, 240, -30., 30.); - } - } - - for (int i = 1; i < 4; ++i) { - snprintf(buf, buf_size - 1, "trdDeltaThetaX_%d", i); - trdDeltaThetaXHistos[i - 1] = new TH1F(buf, buf, 100, -1.0, 1.0); - snprintf(buf, buf_size - 1, "trdDeltaThetaY_%d", i); - trdDeltaThetaYHistos[i - 1] = new TH1F(buf, buf, 100, -1.0, 1.0); - } - - return kSUCCESS; -} - -void LxCalcStats::Exec(Option_t* /*opt*/) -{ - map<Int_t, LxStatTrack> eNoiseTracks; - Int_t nofMuchPoints = 0 == fMuchPoints ? 0 : fMuchPoints->GetEntriesFast(); - - for (Int_t i = 0; i < nofMuchPoints; ++i) { - const CbmMuchPoint* point = static_cast<const CbmMuchPoint*>(fMuchPoints->At(i)); - Int_t stationNumber = CbmMuchGeoScheme::GetStationIndex(point->GetDetectorId()); - Int_t layerNumber = CbmMuchGeoScheme::GetLayerIndex(point->GetDetectorId()); - Int_t trackId = point->GetTrackID(); - map<Int_t, LxStatTrack>::iterator trIt = eNoiseTracks.find(trackId); - - if (trIt == eNoiseTracks.end()) eNoiseTracks[trackId] = LxStatTrack(); - - eNoiseTracks[trackId].muchPoints[stationNumber][layerNumber].push_back(i); - } - - for (Int_t i = 0; i < nofMuchPoints; ++i) { - const CbmMuchPoint* point = static_cast<const CbmMuchPoint*>(fMuchPoints->At(i)); - Int_t stationNumber = CbmMuchGeoScheme::GetStationIndex(point->GetDetectorId()); - Int_t layerNumber = CbmMuchGeoScheme::GetLayerIndex(point->GetDetectorId()); - Int_t trackId = point->GetTrackID(); - const CbmMCTrack* track = static_cast<const CbmMCTrack*>(fMCTracks->At(trackId)); - Int_t pdgCode = track->GetPdgCode(); - - if (11 == pdgCode) { - Double_t x = (point->GetXIn() + point->GetXOut()) / 2; - Double_t y = (point->GetYIn() + point->GetYOut()) / 2; - Int_t parentId = track->GetMotherId(); - - while (parentId >= 0) { - const CbmMCTrack* parent = static_cast<const CbmMCTrack*>(fMCTracks->At(parentId)); - const list<Int_t> parentPts = eNoiseTracks[parentId].muchPoints[stationNumber][layerNumber]; - - for (list<Int_t>::const_iterator j = parentPts.begin(); j != parentPts.end(); ++j) { - Int_t parentPtId = *j; - const CbmMuchPoint* parentPt = static_cast<const CbmMuchPoint*>(fMuchPoints->At(parentPtId)); - Double_t pX = (parentPt->GetXIn() + parentPt->GetXOut()) / 2; - Double_t pY = (parentPt->GetYIn() + parentPt->GetYOut()) / 2; - xHistos[stationNumber][layerNumber]->Fill(x - pX); - yHistos[stationNumber][layerNumber]->Fill(y - pY); - } - - parentId = parent->GetMotherId(); - } - } - } - - map<Int_t, LxStatTrack> jPsiMuTracks; - Int_t nofTrdPoints = 0 == fTrdPoints ? 0 : fTrdPoints->GetEntriesFast(); - - for (Int_t i = 0; i < nofTrdPoints; ++i) { - const CbmTrdPoint* point = static_cast<const CbmTrdPoint*>(fTrdPoints->At(i)); - Int_t layerNumber = CbmTrdAddress::GetLayerId(point->GetModuleAddress()); - Int_t trackId = point->GetTrackID(); - const CbmMCTrack* track = static_cast<const CbmMCTrack*>(fMCTracks->At(trackId)); - - if (-11 != track->GetPdgCode() && 11 != track->GetPdgCode()) continue; - - Int_t motherId = track->GetMotherId(); - - if (0 > motherId) continue; - - const CbmMCTrack* mother = static_cast<const CbmMCTrack*>(fMCTracks->At(motherId)); - - if (443 != mother->GetPdgCode()) continue; - - map<Int_t, LxStatTrack>::iterator trIt = jPsiMuTracks.find(trackId); - - if (trIt == jPsiMuTracks.end()) jPsiMuTracks[trackId] = LxStatTrack(); - - jPsiMuTracks[trackId].trdPoints[layerNumber].push_back(i); - } - - for (map<Int_t, LxStatTrack>::const_iterator i = jPsiMuTracks.begin(); i != jPsiMuTracks.end(); ++i) { - const LxStatTrack& track = i->second; - - for (int j = 1; j < 4; ++j) { - const list<Int_t>& lPoints = track.trdPoints[j - 1]; - const list<Int_t>& rPoints = track.trdPoints[j]; - - for (list<Int_t>::const_iterator k = rPoints.begin(); k != rPoints.end(); ++k) { - const CbmTrdPoint* rPoint = static_cast<const CbmTrdPoint*>(fTrdPoints->At(*k)); - Double_t rX = (rPoint->GetXIn() + rPoint->GetXOut()) / 2; - Double_t rY = (rPoint->GetYIn() + rPoint->GetYOut()) / 2; - Double_t rZ = (rPoint->GetZIn() + rPoint->GetZOut()) / 2; - Double_t rTx = rX / rZ; - Double_t rTy = rY / rZ; - - for (list<Int_t>::const_iterator l = lPoints.begin(); l != lPoints.end(); ++l) { - const CbmTrdPoint* lPoint = static_cast<const CbmTrdPoint*>(fTrdPoints->At(*l)); - Double_t lX = (lPoint->GetXIn() + lPoint->GetXOut()) / 2; - Double_t lY = (lPoint->GetYIn() + lPoint->GetYOut()) / 2; - Double_t lZ = (lPoint->GetZIn() + lPoint->GetZOut()) / 2; - Double_t deltaZ = lZ - rZ; - Double_t x = rX + rTx * deltaZ; - Double_t y = rY + rTy * deltaZ; - trdDeltaThetaXHistos[j - 1]->Fill((lX - x) / deltaZ); - trdDeltaThetaYHistos[j - 1]->Fill((lY - y) / deltaZ); - } - } - } - } -} - -static void SaveHisto(TH1F* h) -{ - TFile* curFile = TFile::CurrentFile(); - size_t buf_size = 128; - char name[buf_size]; - snprintf(name, buf_size - 1, "%s.root", h->GetName()); - TFile fh(name, "RECREATE"); - h->Write(); - fh.Close(); - delete h; - TFile::CurrentFile() = curFile; -} - -void LxCalcStats::Finish() -{ - for (int i = 0; i < 4; ++i) { - for (int j = 0; j < 3; ++j) { - SaveHisto(xHistos[i][j]); - SaveHisto(yHistos[i][j]); - } - } - - for (int i = 0; i < 3; ++i) { - SaveHisto(trdDeltaThetaXHistos[i]); - SaveHisto(trdDeltaThetaYHistos[i]); - } -} diff --git a/reco/tracking/lx/CalcStats/CalcStats.h b/reco/tracking/lx/CalcStats/CalcStats.h deleted file mode 100644 index 0f4d7b139d2bbfacffb7dfc44d488711fb642111..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/CalcStats/CalcStats.h +++ /dev/null @@ -1,35 +0,0 @@ -/* Copyright (C) 2016-2021 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifndef LX_CALC_STATS -#define LX_CALC_STATS - -#include "FairTask.h" - -#include "TH1F.h" - -class TClonesArray; - -class LxCalcStats : public FairTask { -public: - LxCalcStats(); - LxCalcStats(const LxCalcStats& orig) = delete; - LxCalcStats& operator=(const LxCalcStats& orig) = delete; - InitStatus Init(); // Overridden from FairTask - void Exec(Option_t* opt); // Overridden from FairTask - void Finish(); // Overridden from FairTask - -private: - TClonesArray* fMCTracks; - TClonesArray* fMuchPoints; - TClonesArray* fTrdPoints; - TH1F* xHistos[4][3]; - TH1F* yHistos[4][3]; - TH1F* trdDeltaThetaXHistos[3]; - TH1F* trdDeltaThetaYHistos[3]; - - ClassDef(LxCalcStats, 1) -}; - -#endif //LX_CALC_STATS diff --git a/reco/tracking/lx/GenNoiseElectrons/GenNoiseElectrons.cxx b/reco/tracking/lx/GenNoiseElectrons/GenNoiseElectrons.cxx deleted file mode 100644 index ac1527782f665fb16ea4075bf4065bec54538c8b..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/GenNoiseElectrons/GenNoiseElectrons.cxx +++ /dev/null @@ -1,196 +0,0 @@ -/* Copyright (C) 2016-2021 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#include "GenNoiseElectrons.h" - -#include "CbmMCTrack.h" -#include "CbmMuchGeoScheme.h" -#include "CbmMuchPoint.h" -#include "CbmTrdPoint.h" - -#include <FairRootManager.h> -#include <Logger.h> - -#include "TClonesArray.h" -#include "TGeoManager.h" -#include "TH1F.h" -#include "TRandom3.h" -#include <TFile.h> - -ClassImp(LxGenNoiseElectrons) - - LxGenNoiseElectrons::LxGenNoiseElectrons() - : fNofNoiseE(1) - , fNofStations(4) - , fMCTracks(0) - , fMuchPoints(0) - , fTrdPoints(0) - , fOutMCTracks(0) - , fOutMuchPoints(0) - , fOutTrdPoints(0) -{ -} - -LxGenNoiseElectrons::~LxGenNoiseElectrons() -{ - delete fOutMCTracks; - delete fOutMuchPoints; - delete fOutTrdPoints; -} - -static Double_t x_rmss[4][3]; -static Double_t y_rmss[4][3]; - -static Double_t GetRMS(const char* name) -{ - Double_t result = -1.; - size_t buf_size = 128; - char fileName[buf_size]; - snprintf(fileName, buf_size - 1, "%s.root", name); - TFile* curFile = TFile::CurrentFile(); - - /// Save old global file and folder pointer to avoid messing with FairRoot - TFile* oldFile = gFile; - TDirectory* oldDir = gDirectory; - - TFile* f = new TFile(fileName); - - if (!f->IsZombie()) { - TH1F* h = f->Get<TH1F>(name); - - if (h) result = h->GetRMS(); - } - - delete f; - TFile::CurrentFile() = curFile; - - /// Restore old global file and folder pointer to avoid messing with FairRoot - gFile = oldFile; - gDirectory = oldDir; - - return result; -} - -InitStatus LxGenNoiseElectrons::Init() -{ - FairRootManager* ioman = FairRootManager::Instance(); - - if (0 == ioman) LOG(fatal) << "No FairRootManager"; - - fMCTracks = static_cast<TClonesArray*>(ioman->GetObject("MCTrack")); - fMuchPoints = static_cast<TClonesArray*>(ioman->GetObject("MuchPoint")); - fTrdPoints = static_cast<TClonesArray*>(ioman->GetObject("TrdPoint")); - - if (0 == fMCTracks || 0 == fMuchPoints || 0 == fTrdPoints) LOG(fatal) << "No MC tracks or points"; - - size_t buf_size = 128; - char name[buf_size]; - - for (int i = 0; i < 4; ++i) { - for (int j = 0; j < 3; ++j) { - snprintf(name, buf_size - 1, "noise_e_x_%d_%d", i, j); - x_rmss[i][j] = GetRMS(name); - - if (x_rmss[i][j] < 0) { - snprintf(name, buf_size - 1, "Couldn't read noise_e_x_%d_%d", i, j); - LOG(fatal) << name; - } - - snprintf(name, buf_size - 1, "noise_e_y_%d_%d", i, j); - y_rmss[i][j] = GetRMS(name); - - if (y_rmss[i][j] < 0) { - snprintf(name, buf_size - 1, "Couldn't read noise_e_y_%d_%d", i, j); - LOG(fatal) << name; - } - } - } - - fOutMCTracks = new TClonesArray("CbmMCTrack", 1000); - ioman->Register("MCTrack", "MC", fOutMCTracks, kTRUE); - fOutMuchPoints = new TClonesArray("CbmMuchPoint", 1000); - ioman->Register("MuchPoint", "MUCH", fOutMuchPoints, kTRUE); - fOutTrdPoints = new TClonesArray("CbmTrdPoint", 1000); - ioman->Register("TrdPoint", "TRD", fOutTrdPoints, kTRUE); - - return kSUCCESS; -} - -void LxGenNoiseElectrons::Exec(Option_t* /*opt*/) -{ - fOutMCTracks->Delete(); - fOutMuchPoints->Delete(); - fOutTrdPoints->Delete(); - - Int_t nofMCTracks = fMCTracks->GetEntriesFast(); - TClonesArray& mctref = *fOutMCTracks; - - for (Int_t i = 0; i < nofMCTracks; ++i) { - const CbmMCTrack* mcTrack = static_cast<const CbmMCTrack*>(fMCTracks->At(i)); - new (mctref[i]) CbmMCTrack(*mcTrack); - } - - Int_t nofMuchPoints = fMuchPoints->GetEntriesFast(); - TClonesArray& mpref = *fOutMuchPoints; - - for (Int_t i = 0; i < nofMuchPoints; ++i) { - const CbmMuchPoint* muchPoint = static_cast<const CbmMuchPoint*>(fMuchPoints->At(i)); - new (mpref[i]) CbmMuchPoint(*muchPoint); - } - - Int_t nofTrdPoints = fTrdPoints->GetEntriesFast(); - TClonesArray& tpref = *fOutTrdPoints; - - for (Int_t i = 0; i < nofTrdPoints; ++i) { - const CbmTrdPoint* trdPoint = static_cast<const CbmTrdPoint*>(fTrdPoints->At(i)); - new (tpref[i]) CbmTrdPoint(*trdPoint); - } - - Int_t ind = nofMuchPoints; - - for (Int_t i = 0; i < nofMuchPoints; ++i) { - const CbmMuchPoint* pMuchPt = static_cast<const CbmMuchPoint*>(fMuchPoints->At(i)); - Int_t stationNumber = CbmMuchGeoScheme::GetStationIndex(pMuchPt->GetDetectorId()); - Int_t layerNumber = CbmMuchGeoScheme::GetLayerIndex(pMuchPt->GetDetectorId()); - - for (int j = 0; j < fNofNoiseE; ++j) { - TVector3 posIn; - pMuchPt->PositionIn(posIn); - TVector3 posOut; - pMuchPt->PositionOut(posOut); - TVector3 posDelta = posOut - posIn; - - for (int k = 0; k < 20; ++k) { - TVector3 noiseDelta(gRandom->Gaus(0, x_rmss[stationNumber][layerNumber]), - gRandom->Gaus(0, y_rmss[stationNumber][layerNumber]), 0); - TVector3 newIn = posIn + noiseDelta; - TGeoNode* node = gGeoManager->FindNode(newIn.X(), newIn.Y(), newIn.Z()); - - if (0 == node) continue; - - TString nodeName(node->GetName()); - - if (!nodeName.Contains("active", TString::kIgnoreCase)) continue; - - TVector3 newOut = newIn + 0.5 * posDelta; - node = gGeoManager->FindNode(newOut.X(), newOut.Y(), newOut.Z()); - - if (0 == node) continue; - - TString nodeName2(node->GetName()); - - if (!nodeName2.Contains("active", TString::kIgnoreCase)) continue; - - CbmMuchPoint noiseMuchPt(*pMuchPt); - noiseMuchPt.SetPosition(newIn); - noiseMuchPt.SetPositionOut(newOut); - noiseMuchPt.SetTrackID(-1); - new (mpref[ind++]) CbmMuchPoint(noiseMuchPt); - break; - } - } - } -} - -void LxGenNoiseElectrons::Finish() {} diff --git a/reco/tracking/lx/GenNoiseElectrons/GenNoiseElectrons.h b/reco/tracking/lx/GenNoiseElectrons/GenNoiseElectrons.h deleted file mode 100644 index c98d74b21be442ec0af6f92d1927d51af5c1b6ee..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/GenNoiseElectrons/GenNoiseElectrons.h +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright (C) 2016-2017 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifndef LX_GEN_NOISE_ELECTRONS -#define LX_GEN_NOISE_ELECTRONS - -#include "FairTask.h" - -class TClonesArray; - -class LxGenNoiseElectrons : public FairTask { -public: - LxGenNoiseElectrons(); - LxGenNoiseElectrons(const LxGenNoiseElectrons& orig) = delete; - LxGenNoiseElectrons& operator=(const LxGenNoiseElectrons& orig) = delete; - ~LxGenNoiseElectrons(); - InitStatus Init(); // Overridden from FairTask - void Exec(Option_t* opt); // Overridden from FairTask - void Finish(); // Overridden from FairTask - - void SetNofNoiseE(Int_t v) { fNofNoiseE = v; } - void SetNofStations(Int_t v) { fNofStations = v; } - -private: - Int_t fNofNoiseE; - Int_t fNofStations; - TClonesArray* fMCTracks; - TClonesArray* fMuchPoints; - TClonesArray* fTrdPoints; - TClonesArray* fOutMCTracks; - TClonesArray* fOutMuchPoints; - TClonesArray* fOutTrdPoints; - ClassDef(LxGenNoiseElectrons, 1) -}; - -#endif //LX_GEN_NOISE_ELECTRONS diff --git a/reco/tracking/lx/LxLinkDef.h b/reco/tracking/lx/LxLinkDef.h deleted file mode 100644 index d884bf998ae1e458ae481ca3039629b3456f577c..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/LxLinkDef.h +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright (C) 2016-2017 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -// $Id: LxLinkDef.h,v 1.10 2013/09/30 11:36:47 tablyaz Exp $ - -#ifdef __CINT__ - -#pragma link off all globals; -#pragma link off all classes; -#pragma link off all functions; - -#pragma link C++ class LxTBFinder + ; -#pragma link C++ class LxTBTrdFinder + ; -//#pragma link C++ class LxTBMLFinder+; -//#pragma link C++ class LxTBMPFinder+; -#pragma link C++ class LxGenNoiseElectrons + ; -#pragma link C++ class LxCalcStats + ; - -#endif diff --git a/reco/tracking/lx/Simple/CMakeLists.txt b/reco/tracking/lx/Simple/CMakeLists.txt deleted file mode 100644 index 5b53647a122e6c114b2c38a1e360ec45369108e2..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/Simple/CMakeLists.txt +++ /dev/null @@ -1,67 +0,0 @@ -# Create a library called "libLxTrack" which includes the source files given in -# the array . -# The extension is already found. Any number of sources could be listed -# here. - -Set(INCLUDE_DIRECTORIES - ${BASE_INCLUDE_DIRECTORIES} - ${CBMROOT_SOURCE_DIR}/tracking/lx - ${CBMBASE_DIR} - ${CBMDATA_DIR} - ${CBMDATA_DIR}/much - ${CBMDATA_DIR}/sts - ${CBMDATA_DIR}/global - ${CBMROOT_SOURCE_DIR}/KF - ${CBMROOT_SOURCE_DIR}/KF/Interface - ${CBMROOT_SOURCE_DIR}/sts - ${CBMROOT_SOURCE_DIR}/littrack/std - ${CBMROOT_SOURCE_DIR}/littrack/cbm -) - -Include_Directories( ${INCLUDE_DIRECTORIES}) - -Set(SYSTEM_INCLUDE_DIRECTORIES - ${Boost_INCLUDE_DIRS} -) - -Include_Directories(SYSTEM ${SYSTEM_INCLUDE_DIRECTORIES}) - -Set(LINK_DIRECTORIES - ${ROOT_LIBRARY_DIR} - ${FAIRROOT_LIBRARY_DIR} - ${Boost_LIBRARY_DIRS} -) - -Link_Directories( ${LINK_DIRECTORIES}) - -Set(SRCS - Lx.cxx - LxTrackAna.cxx -) - -If (OPENMP_FOUND) - Set(SRCS ${SRCS} LxParall.cxx) -EndIf (OPENMP_FOUND) - -Set(NO_DICT_SRCS - LxCA.cxx - LxDraw.cxx - LxEff.cxx - LxMC.cxx - LxTrackAnaSegments.cxx - LxTrigger.cxx - LxUtils.cxx -) - -If (OPENMP_FOUND) - Set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx -fopenmp -DLXPARALL" ) -EndIf (OPENMP_FOUND) - -set(LINKDEF LxLinkDef.h) -Set(LIBRARY_NAME LxTrack) -Set(DEPENDENCIES - CbmBase CbmData Base boost_regex -) - -GENERATE_LIBRARY() - diff --git a/reco/tracking/lx/Simple/Lx.cxx b/reco/tracking/lx/Simple/Lx.cxx deleted file mode 100644 index c3dc51595ad0471bd6c1ea125e2aff73779addcc..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/Simple/Lx.cxx +++ /dev/null @@ -1,1628 +0,0 @@ -/* Copyright (C) 2014-2021 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#include "Lx.h" - -#include "CbmKFTrack.h" -#include "CbmMCTrack.h" -#include "CbmMuchCluster.h" -#include "CbmMuchDigiMatch.h" -#include "CbmMuchGeoScheme.h" -#include "CbmMuchPoint.h" -#include "CbmMuchTrack.h" -#include "CbmStsAddress.h" -#include "CbmStsPoint.h" -#include "LxDraw.h" -#include "TDatabasePDG.h" -#include "TGeoManager.h" - -#include <iostream> - -#include <sys/time.h> - -ClassImp(LxFinder) - - using namespace std; - -LxFinder* LxFinder::fInstance = 0; - -#ifdef MAKE_HISTOS -TH1F* LxFinder::massHisto = 0; -//TH1F* LxFinder::backgroundMassHisto = 0; -TTree* LxFinder::superEventTracks = 0; -TH1F* LxFinder::signalChi2Histo = 0; -TH1F* LxFinder::backgroundChi2Histo = 0; -TProfile* LxFinder::effByMomentumProfile = 0; -TH1F* LxFinder::muPlusDtxHisto = 0; -TH1F* LxFinder::muMinusDtxHisto = 0; -TH1F* LxFinder::signalXAtZ0 = 0; -TH1F* LxFinder::signalYAtZ0 = 0; -TH1F* LxFinder::bgrXAtZ0 = 0; -TH1F* LxFinder::bgrYAtZ0 = 0; -TH1F* LxFinder::signalInterTracksDistance = 0; -TH1F* LxFinder::bgrInterTracksDistance = 0; -TH1F* LxFinder::signalTanSigns = 0; -TH1F* LxFinder::signalCoordSigns = 0; -TH1F* LxFinder::bgrTanSigns = 0; -TH1F* LxFinder::bgrCoordSigns = 0; -TH1F* LxFinder::numberOfTracks = 0; -TH1F* LxFinder::signalInterTracksDistanceOn1st = 0; -TH1F* LxFinder::bgrInterTracksDistanceOn1st = 0; -TH1F* LxFinder::bgrInterTracksDistanceOn1stSigns = 0; -TH1F* LxFinder::signalInterTracksAngle = 0; -TH1F* LxFinder::bgrInterTracksAngle = 0; -TH2F* LxFinder::signalInterTrackCorrDA = 0; -TH2F* LxFinder::bgrInterTrackCorrDA = 0; -TH1F* LxFinder::muchMomErrSig = 0; -TH1F* LxFinder::muchMomErrBgr = 0; -#endif //MAKE_HISTOS - -#ifdef MAKE_DISPERSE_2D_HISTOS -TProfile2D* disperseLHistos[LXSTATIONS]; -TProfile2D* disperseRHistos[LXSTATIONS]; -TProfile2D* disperseDHistos[LXSTATIONS]; -#endif //MAKE_DISPERSE_2D_HISTOS - -#ifdef MAKE_TRIGGERING_HISTOS -TH1F* LxFinder::triggeringAllTracksVertices = 0; -TH1F* LxFinder::triggeringDistTracksVertices = 0; -TH1F* LxFinder::triggeringSignTracksVertices = 0; -TH1F* LxFinder::triggeringTrigTracksVertices = 0; -#endif //MAKE_TRIGGERING_HISTOS - -#ifdef MAKE_HISTOS -static TH1F* stsTrackChi2 = 0; -static TH1F* stsTrackX = 0; -static TH1F* stsTrackY = 0; -#endif //MAKE_HISTOS - -LxHitFile::LxHitFile() : useForWrite(false), fd(-1), evBuf(0), bufSize(0), evPtr(0), evEnd(0) {} - -LxHitFile::~LxHitFile() { delete[] evBuf; } - -bool LxHitFile::Open(TString fileName, bool forWrite) -{ - useForWrite = forWrite; - - if (forWrite) - fd = open(fileName.Data(), O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - else - fd = open(fileName.Data(), O_RDONLY); - - return -1 != fd; -} - -bool LxHitFile::StartEvent(Int_t nEnt) -{ - off_t curOff = lseek(fd, 0, SEEK_CUR); - - if (-1 == curOff) return false; - - eventOffs.push_back(curOff); - bufSize = (2 * sizeof(Int_t) + 6 * sizeof(Double_t)) * nEnt; - evBuf = new char[bufSize]; - evPtr = evBuf; - evEnd = evBuf + bufSize; - return true; -} - -bool LxHitFile::EndEvent() -{ - ssize_t res = write(fd, evBuf, bufSize); - delete[] evBuf; - evBuf = 0; - bufSize = 0; - evPtr = 0; - evEnd = 0; - return -1 != res; -} - -bool LxHitFile::WriteHit(Int_t stationNumber, Int_t layerNumber, Double_t x, Double_t y, Double_t z, Double_t xErr, - Double_t yErr, Double_t zErr) -{ - if (evPtr + 2 * sizeof(Int_t) + 6 * sizeof(Double_t) > evEnd) return false; - - memcpy(evPtr, &stationNumber, sizeof(stationNumber)); - evPtr += sizeof(stationNumber); - memcpy(evPtr, &layerNumber, sizeof(layerNumber)); - evPtr += sizeof(layerNumber); - memcpy(evPtr, &x, sizeof(x)); - evPtr += sizeof(x); - memcpy(evPtr, &y, sizeof(y)); - evPtr += sizeof(y); - memcpy(evPtr, &z, sizeof(z)); - evPtr += sizeof(z); - memcpy(evPtr, &xErr, sizeof(xErr)); - evPtr += sizeof(xErr); - memcpy(evPtr, &yErr, sizeof(yErr)); - evPtr += sizeof(yErr); - memcpy(evPtr, &zErr, sizeof(zErr)); - evPtr += sizeof(zErr); - return true; -} - -bool LxHitFile::ReadEvent(Int_t eventNumber) -{ - off_t footerOfFooterOff = lseek(fd, -sizeof(off_t), SEEK_END); - - if (-1 == footerOfFooterOff) return false; - - off_t footerOff; - ssize_t readBytes = read(fd, &footerOff, sizeof(footerOff)); - - if (-1 == readBytes) return false; - - Int_t numFooterEntries = (footerOfFooterOff - footerOff) / sizeof(off_t); - - if (eventNumber >= numFooterEntries) return false; - - off_t eventOff; - readBytes = pread(fd, &eventOff, sizeof(eventOff), footerOff + eventNumber * sizeof(off_t)); - - if (-1 == readBytes) return false; - - off_t nextEvOff; - - if (eventNumber == numFooterEntries - 1) - nextEvOff = footerOff; - else { - readBytes = pread(fd, &nextEvOff, sizeof(nextEvOff), footerOff + (eventNumber + 1) * sizeof(off_t)); - - if (-1 == readBytes) return false; - } - - delete[] evBuf; - evBuf = 0; - bufSize = 0; - - bufSize = nextEvOff - eventOff; - evBuf = new char[bufSize]; - readBytes = pread(fd, evBuf, bufSize, eventOff); - - if (readBytes != bufSize) { - delete[] evBuf; - evBuf = 0; - bufSize = 0; - evPtr = 0; - evEnd = 0; - return false; - } - - evPtr = evBuf; - evEnd = evBuf + bufSize; - return true; -} - -bool LxHitFile::ReadHit(Int_t& stationNumber, Int_t& layerNumber, Double_t& x, Double_t& y, Double_t& z, Double_t& xErr, - Double_t& yErr, Double_t& zErr) -{ - if (evPtr + 2 * sizeof(Int_t) + 6 * sizeof(Double_t) > evEnd) return false; - - memcpy(&stationNumber, evPtr, sizeof(stationNumber)); - evPtr += sizeof(stationNumber); - memcpy(&layerNumber, evPtr, sizeof(layerNumber)); - evPtr += sizeof(layerNumber); - memcpy(&x, evPtr, sizeof(x)); - evPtr += sizeof(x); - memcpy(&y, evPtr, sizeof(y)); - evPtr += sizeof(y); - memcpy(&z, evPtr, sizeof(z)); - evPtr += sizeof(z); - memcpy(&xErr, evPtr, sizeof(xErr)); - evPtr += sizeof(xErr); - memcpy(&yErr, evPtr, sizeof(yErr)); - evPtr += sizeof(yErr); - memcpy(&zErr, evPtr, sizeof(zErr)); - evPtr += sizeof(zErr); - return true; -} - -bool LxHitFile::Close() -{ - if (!useForWrite) return -1 != close(fd); - - off_t footerOff = lseek(fd, 0, SEEK_CUR); - ssize_t res; - int res2; - - for (list<off_t>::iterator i = eventOffs.begin(); i != eventOffs.end(); ++i) { - off_t o = *i; - res = write(fd, &o, sizeof(o)); - - if (-1 == res) goto end; - } - - res = write(fd, &footerOff, sizeof(footerOff)); - -end: - res2 = close(fd); - return -1 != res && -1 != res2; -} - -LxFinder* LxFinder::Instance() { return fInstance; } - -LxFinder::LxFinder() : muchPixelHits(0), listMCTracks(0), listMuchPts(0), listMuchClusters(0), - listMuchPixelDigiMatches(0), listStsTracks(0), listStsMatches(0), listStsPts(0), listRecoTracks(0), - superEventData(0), extFitter(), fPrimVtx(0), positiveTracks(), negativeTracks(), - generateInvMass(false), generateBackground(false), generateChi2(false), - linkWithSts(true), useMCPInsteadOfHits(false), calcMiddlePoints(true), cutCoeff(4.0), verbosity(1), - parallMode(false), hitFileName(""), fileSaveSuffix(""), particleType("jpsi"), pPtCut(true), - MCPoints(), MCTracks(), MCStsPoints() - , MCStsPointsByStations() -#ifdef MAKE_DISPERSE_2D_HISTOS - , MCPointsByStations(), - , zCoordsByStations(), -#endif //MAKE_DISPERSE_2D_HISTOS - , caSpace() -#ifdef MAKE_EFF_CALC - , incomplete_events() - , falseSignalTriggerings(0) - , trueSignalTriggerings(0) - , hasSignalInEvent(false) - , signalCounter(0) -#endif //MAKE_EFF_CALC - , eventNumber(0) -#ifdef CALC_MUCH_DETECTORS_EFF - , mcPointsCount(0), mcPointsTriggered(0) -#endif //CALC_MUCH_DETECTORS_EFF - , saveOnlyTriggeringTracks(true) -{ - fInstance = this; -} - -LxFinder::~LxFinder() {} - -TString lxFinderParticleType = "jpsi"; - -static bool GetHistoRMS(const char* histoNameBase, Int_t histoNumber, scaltype& retVal) -{ - bool result = false; -#pragma omp critical - { - char name[256]; - char dir_name[256]; - sprintf(dir_name, "configuration.%s", lxFinderParticleType.Data()); - - if (histoNumber < 0) - sprintf(name, "%s/%s.root", dir_name, histoNameBase); - else - sprintf(name, "%s/%s_%d.root", dir_name, histoNameBase, histoNumber); - - TFile* curFile = TFile::CurrentFile(); - - /// Save old global file and folder pointer to avoid messing with FairRoot - TFile* oldFile = gFile; - TDirectory* oldDir = gDirectory; - - TFile* f = new TFile(name); - - if (!f->IsZombie()) { - if (histoNumber < 0) - sprintf(name, "%s", histoNameBase); - else - sprintf(name, "%s_%d", histoNameBase, histoNumber); - - TH1F* h = f->Get<TH1F>(name); - if (h) { - retVal = h->GetRMS(); - result = true; - } - } - - delete f; - TFile::CurrentFile() = curFile; - - /// Restore old global file and folder pointer to avoid messing with FairRoot - gFile = oldFile; - gDirectory = oldDir; - } - return result; -} - -static bool GetHistoCOV(const char* histoNameBase, Int_t histoNumber, Int_t axis1, Int_t axis2, scaltype& retVal) -{ - bool result = false; -#pragma omp critical - { - char name[256]; - char dir_name[256]; - sprintf(dir_name, "configuration.%s", lxFinderParticleType.Data()); - sprintf(name, "%s/%s_%d.root", dir_name, histoNameBase, histoNumber); - TFile* curFile = TFile::CurrentFile(); - - /// Save old global file and folder pointer to avoid messing with FairRoot - TFile* oldFile = gFile; - TDirectory* oldDir = gDirectory; - - TFile* f = new TFile(name); - - if (!f->IsZombie()) { - sprintf(name, "%s_%d", histoNameBase, histoNumber); - TH2F* h = f->Get<TH2F>(name); - if (h) { - retVal = h->GetCovariance(axis1, axis2); - result = true; - } - } - - delete f; - TFile::CurrentFile() = curFile; - - /// Restore old global file and folder pointer to avoid messing with FairRoot - gFile = oldFile; - gDirectory = oldDir; - } - return result; -} - -InitStatus LxFinder::Init() -{ - static Int_t nTimes = 1; - cout << "LxFinder::Init() called at " << nTimes++ << " time" << endl; - - if (parallMode) - hitFile.Open(hitFileName, false); - else if (hitFileName != "") - hitFile.Open(hitFileName, true); - - superEventData = new CbmStsTrack; - - FairRootManager* fRootManager = 0; - - if (!parallMode) { - fRootManager = FairRootManager::Instance(); - muchPixelHits = LX_DYNAMIC_CAST<TClonesArray*>(fRootManager->GetObject("MuchPixelHit")); - listMCTracks = LX_DYNAMIC_CAST<TClonesArray*>(fRootManager->GetObject("MCTrack")); - listMuchPts = LX_DYNAMIC_CAST<TClonesArray*>(fRootManager->GetObject("MuchPoint")); - listMuchClusters = LX_DYNAMIC_CAST<TClonesArray*>(fRootManager->GetObject("MuchCluster")); - listMuchPixelDigiMatches = LX_DYNAMIC_CAST<TClonesArray*>(fRootManager->GetObject("MuchDigiMatch")); - listStsTracks = LX_DYNAMIC_CAST<TClonesArray*>(fRootManager->GetObject("StsTrack")); - listStsMatches = LX_DYNAMIC_CAST<TClonesArray*>(fRootManager->GetObject("StsTrackMatch")); - listStsPts = LX_DYNAMIC_CAST<TClonesArray*>(fRootManager->GetObject("StsPoint")); - //fPrimVtx = LX_DYNAMIC_CAST<CbmVertex*> (fManager->GetObject("PrimaryVertex")); - /* - // Get pointer to PrimaryVertex object from IOManager if it exists - // The old name for the object is "PrimaryVertex" the new one - // "PrimaryVertex." Check first for the new name - fPrimVtx = LX_DYNAMIC_CAST<CbmVertex*>(fManager->GetObject("PrimaryVertex.")); - if (nullptr == fPrimVtx) { - fPrimVtx = LX_DYNAMIC_CAST<CbmVertex*>(fManager->GetObject("PrimaryVertex")); - } - if (nullptr == fPrimVtx) { - Error("CbmL1SttTrackFinder::ReInit","vertex not found!"); - return kERROR; - } - */ - } // if (!parallMode) - - fPrimVtx = new CbmVertex; - scaltype rms; - - // Read Z-positions of MUCH station layers and save them in LxLayer objects. - - for (Int_t i = 0; i < LXSTATIONS; ++i) { - LxStation* aStation = caSpace.stations[i]; - - for (Int_t j = 0; j < LXLAYERS; ++j) { -#pragma omp critical - { - TString muchStLrPath = Form("/cave_1/much_0/muchstation%02i_0/muchstation%02ilayer%01i_0", i + 1, i + 1, j + 1); - gGeoManager->cd(muchStLrPath.Data()); - Double_t localCoords[3] = {0., 0., 0.}; - Double_t globalCoords[3]; - gGeoManager->LocalToMaster(localCoords, globalCoords); - aStation->layers[j]->zCoord = globalCoords[2]; -#ifdef MAKE_DISPERSE_2D_HISTOS - zCoordsByStations[i][j] = globalCoords[2]; -#endif //MAKE_DISPERSE_2D_HISTOS - } - } - - aStation->zCoord = aStation->layers[LXMIDDLE]->zCoord; - - //if (0 == i) - //cout << "First MUCH station Z-coord = " << aStation->zCoord << endl; - - if (!GetHistoRMS("muchInStationXDispLeft", i, rms)) return kFATAL; - - x_disp_left_limits[i] = cutCoeff * rms; - x_disp_left_limits_sq[i] = x_disp_left_limits[i] * x_disp_left_limits[i]; - - if (!GetHistoRMS("muchInStationYDispLeft", i, rms)) return kFATAL; - - y_disp_left_limits[i] = cutCoeff * rms; - y_disp_left_limits_sq[i] = y_disp_left_limits[i] * y_disp_left_limits[i]; - - if (!GetHistoRMS("muchInStationXDispRight", i, rms)) return kFATAL; - - x_disp_right_limits[i] = cutCoeff * rms; - x_disp_right_limits_sq[i] = x_disp_right_limits[i] * x_disp_right_limits[i]; - - if (!GetHistoRMS("muchInStationYDispRight", i, rms)) return kFATAL; - - y_disp_right_limits[i] = cutCoeff * rms; - y_disp_right_limits_sq[i] = y_disp_right_limits[i] * y_disp_right_limits[i]; - - if (i > 0) { - if (!GetHistoRMS("muchLongSegmentTxHisto", i, rms)) return kFATAL; - - aStation->txLimit = cutCoeff * rms; - tx_limits[i] = aStation->txLimit; - tx_limits_sq[i] = aStation->txLimit * aStation->txLimit; - - if (!GetHistoRMS("muchLongSegmentTyHisto", i, rms)) return kFATAL; - - aStation->tyLimit = cutCoeff * rms; - ty_limits[i] = aStation->tyLimit; - ty_limits_sq[i] = aStation->tyLimit * aStation->tyLimit; - -#ifdef CLUSTER_MODE - if (!GetHistoRMS("muchClusterXDispHisto", i, rms)) return kFATAL; - - aStation->clusterXLimit = rms; - aStation->clusterXLimit2 = rms * rms; - - if (!GetHistoRMS("muchClusterYDispHisto", i, rms)) return kFATAL; - - aStation->clusterYLimit = rms; - aStation->clusterYLimit2 = rms * rms; - - if (!GetHistoRMS("muchClusterTxDispHisto", i, rms)) return kFATAL; - - aStation->clusterTxLimit = rms; - aStation->clusterTxLimit2 = rms * rms; - - if (!GetHistoRMS("muchClusterTyDispHisto", i, rms)) return kFATAL; - - aStation->clusterTyLimit = rms; - aStation->clusterTyLimit2 = rms * rms; -#endif //CLUSTER_MODE - - if (i < LXSTATIONS - 1) { - if (!GetHistoRMS("muchSegmentTxBreakHisto", i, rms)) return kFATAL; - - aStation->txBreakSigma = rms; - aStation->txBreakLimit = cutCoeff * rms; - - if (!GetHistoRMS("muchSegmentTyBreakHisto", i, rms)) return kFATAL; - - aStation->tyBreakSigma = rms; - aStation->tyBreakLimit = cutCoeff * rms; - } - } - -#ifdef USE_KALMAN_FIT - if (i < LXSTATIONS - 1) { - for (Int_t j = 0; j <= 1; ++j) { - for (Int_t k = 0; k <= 1; ++k) { - if (!GetHistoCOV("muchXTxCovHisto", i, j + 1, k + 1, aStation->MSNoise[0][j][k])) return kFATAL; - - if (!GetHistoCOV("muchYTyCovHisto", i, j + 1, k + 1, aStation->MSNoise[1][j][k])) return kFATAL; - } - } - } -#endif //USE_KALMAN_FIT - } - - if (!GetHistoRMS("muchStsBreakX", -1, caSpace.muchStsBreakX)) { - cout << "LxFinder::Init(): Failed to read RMS from muchStsBreakX" << endl; - return kFATAL; - } - - if (!GetHistoRMS("muchStsBreakY", -1, caSpace.muchStsBreakY)) { - cout << "LxFinder::Init(): Failed to read RMS from muchStsBreakY" << endl; - return kFATAL; - } - - if (!GetHistoRMS("muchStsBreakTx", -1, caSpace.muchStsBreakTx)) { - cout << "LxFinder::Init(): Failed to read RMS from muchStsBreakTx" << endl; - return kFATAL; - } - - if (!GetHistoRMS("muchStsBreakTy", -1, caSpace.muchStsBreakTy)) { - cout << "LxFinder::Init(): Failed to read RMS from muchStsBreakTy" << endl; - return kFATAL; - } - - // Create an output array. - if (!parallMode) { - listRecoTracks = new TClonesArray("CbmMuchTrack", 100); - fRootManager->Register("MuchTrack", "Much", listRecoTracks, IsOutputBranchPersistent("MuchTrack")); - } - -#ifdef MAKE_HISTOS - if (generateInvMass) massHisto = new TH1F("jpsi_mass", "jpsi_mass", 100, 2., 4.); - - if (generateBackground) { - //backgroundMassHisto = new TH1F("background_mass", "background_mass", 400, 2., 4.); - superEventTracks = new TTree("SuperEventTracks", "Tracks for building a super event"); - superEventTracks->Branch("tracks", "CbmStsTrack", &superEventData); - } - - if (generateChi2) { - signalChi2Histo = new TH1F("signal_chi2", "signal_chi2", 100, 0., 20.); - backgroundChi2Histo = new TH1F("background_chi2", "background_chi2", 100, 0., 20.); - } -#endif //MAKE_HISTOS - -#ifdef MAKE_HISTOS - // char histoName[128]; - - for (int i = 0; i < 6; ++i) { -#ifdef MAKE_DISPERSE_2D_HISTOS - sprintf(histoName, "disperseL_%d", i); - disperseLHistos[i] = new TProfile2D(histoName, histoName, 30, -3., 3., 30, -3., 3.); - disperseLHistos[i]->StatOverflows(); - sprintf(histoName, "disperseR_%d", i); - disperseRHistos[i] = new TProfile2D(histoName, histoName, 30, -3., 3., 30, -3., 3.); - disperseRHistos[i]->StatOverflows(); - sprintf(histoName, "disperseD_%d", i); - disperseDHistos[i] = new TProfile2D(histoName, histoName, 30, -3., 3., 30, -3., 3.); - disperseDHistos[i]->StatOverflows(); -#endif //MAKE_DISPERSE_2D_HISTOS - } - -#endif //MAKE_HISTOS - -#ifdef MAKE_HISTOS - muPlusDtxHisto = new TH1F("muPlusDtxHisto", "Mu+ Tx difference", 200, -0.15, 0.15); - muPlusDtxHisto->StatOverflows(); - muMinusDtxHisto = new TH1F("muMinusDtxHisto", "Mu- Tx difference", 200, -0.15, 0.15); - muMinusDtxHisto->StatOverflows(); - signalXAtZ0 = new TH1F("signalXAtZ0", "Signal track X at Z=0", 200, -40.0, 40.0); - signalXAtZ0->StatOverflows(); - signalYAtZ0 = new TH1F("signalYAtZ0", "Signal track Y at Z=0", 200, -40.0, 40.0); - signalYAtZ0->StatOverflows(); - bgrXAtZ0 = new TH1F("bgrXAtZ0", "Background track X at Z=0", 200, -40.0, 40.0); - bgrXAtZ0->StatOverflows(); - bgrYAtZ0 = new TH1F("bgrYAtZ0", "Background track Y at Z=0", 200, -40.0, 40.0); - bgrYAtZ0->StatOverflows(); - signalInterTracksDistance = new TH1F("signalInterTracksDistance", "Distance between signal tracks", 200, 0.0, 30.0); - signalInterTracksDistance->StatOverflows(); - bgrInterTracksDistance = new TH1F("bgrInterTracksDistance", "Distance between background tracks", 200, 0.0, 30.0); - bgrInterTracksDistance->StatOverflows(); - signalTanSigns = new TH1F("signalTanSigns", "Signs of signal tracks tangents products", 20, -2.0, 2.0); - signalTanSigns->StatOverflows(); - signalCoordSigns = new TH1F("signalCoordSigns", "Signs of signal tracks coordinates products", 20, -2.0, 2.0); - signalCoordSigns->StatOverflows(); - bgrTanSigns = new TH1F("bgrTanSigns", "Signs of background tracks tangents products", 20, -2.0, 2.0); - bgrTanSigns->StatOverflows(); - bgrCoordSigns = new TH1F("bgrCoordSigns", "Signs of background tracks coordinates products", 20, -2.0, 2.0); - bgrCoordSigns->StatOverflows(); - numberOfTracks = new TH1F("numberOfTracks", "The number of reconstructed tracks in an event", 6, 0.0, 6.0); - numberOfTracks->StatOverflows(); - signalInterTracksDistanceOn1st = - new TH1F("signalInterTracksDistanceOn1st", "Distance between signal tracks on the 1st station", 200, 0.0, 250.0); - signalInterTracksDistanceOn1st->StatOverflows(); - bgrInterTracksDistanceOn1st = - new TH1F("bgrInterTracksDistanceOn1st", "Distance between background tracks on the 1st station", 200, 0.0, 250.0); - bgrInterTracksDistanceOn1st->StatOverflows(); - bgrInterTracksDistanceOn1stSigns = - new TH1F("bgrInterTracksDistanceOn1stSigns", - "Distance between background tracks on the 1st station separated by signs", 200, 0.0, 250.0); - bgrInterTracksDistanceOn1stSigns->StatOverflows(); - signalInterTracksAngle = - new TH1F("signalInterTracksAngle", "Angle between signal tracks by hits on 1st station", 200, 0.0, 60.0); - signalInterTracksAngle->StatOverflows(); - bgrInterTracksAngle = - new TH1F("bgrInterTracksAngle", "Angle between background tracks by hits on 1st station", 200, 0.0, 60.0); - bgrInterTracksAngle->StatOverflows(); - signalInterTrackCorrDA = - new TH2F("signalInterTrackCorrDA", "signalInterTrackCorrDA", 200, 0.0, 250.0, 200, 0.0, 60.0); - signalInterTrackCorrDA->StatOverflows(); - bgrInterTrackCorrDA = new TH2F("bgrInterTrackCorrDA", "bgrInterTrackCorrDA", 200, 0.0, 250.0, 200, 0.0, 60.0); - bgrInterTrackCorrDA->StatOverflows(); - muchMomErrSig = new TH1F("muchMomErrSig", "Momentum determination error for signal", 600, -300.0, 300.0); - muchMomErrSig->StatOverflows(); - muchMomErrBgr = new TH1F("muchMomErrBgr", "Momentum determination error for background", 600, -300.0, 300.0); - muchMomErrBgr->StatOverflows(); - - effByMomentumProfile = new TProfile("Reconstruction efficiency by momentum", "Reconstruction efficiency by momentum", - 100, 0.0, 50.0, 0.0, 100.0); -#endif //MAKE_HISTOS - -#ifdef MAKE_TRIGGERING_HISTOS - triggeringAllTracksVertices = - new TH1F("triggeringAllTracksVertices", "triggeringAllTracksVertices", 330, -10.0, 320.0); - triggeringAllTracksVertices->StatOverflows(); - triggeringDistTracksVertices = - new TH1F("triggeringDistTracksVertices", "triggeringDistTracksVertices", 330, -10.0, 320.0); - triggeringDistTracksVertices->StatOverflows(); - triggeringSignTracksVertices = - new TH1F("triggeringSignTracksVertices", "triggeringSignTracksVertices", 330, -10.0, 320.0); - triggeringSignTracksVertices->StatOverflows(); - triggeringTrigTracksVertices = - new TH1F("triggeringTrigTracksVertices", "triggeringTrigTracksVertices", 330, -10.0, 320.0); - triggeringTrigTracksVertices->StatOverflows(); -#endif //MAKE_TRIGGERING_HISTOS - -#ifdef MAKE_HISTOS - stsTrackChi2 = new TH1F("stsTrackChi2", "stsTrackChi2", 200, 0., 10.); - stsTrackChi2->StatOverflows(); - stsTrackX = new TH1F("stsTrackX", "stsTrackX", 200, -0.2, 0.2); - stsTrackX->StatOverflows(); - stsTrackY = new TH1F("stsTrackY", "stsTrackY", 200, -0.2, 0.2); - stsTrackY->StatOverflows(); -#endif //MAKE_HISTOS - -#ifdef MAKE_EFF_CALC - incomplete_events.open("incomplete_events.txt"); -#endif //MAKE_EFF_CALC - - return kSUCCESS; -} - -static Int_t nTimes = 1; -static Int_t wholeDuration = 0; -static Int_t averageDuration = 0; - -void LxFinder::Exec(Option_t* opt) -{ - cout << "LxFinder::Exec() called at " << nTimes << " time" << endl; - timeval bTime, eTime; - int exeDuration; - gettimeofday(&bTime, 0); - - // Clean all previously created data. - MCTracks.clear(); - MCPoints.clear(); - MCStsPoints.clear(); - - for (int i = 0; i < 8; ++i) - MCStsPointsByStations[i].clear(); - -#ifdef MAKE_DISPERSE_2D_HISTOS - for (int i = 0; i < LXSTATIONS; ++i) { - for (int j = 0; j < LXLAYERS; ++j) - MCPointsByStations[i][j].clear(); - } -#endif //MAKE_DISPERSE_2D_HISTOS - - caSpace.Clear(); - - if (!parallMode) listRecoTracks->Clear(); - - Int_t nEnt = 0; - -#ifdef MAKE_EFF_CALC - // Read MC tracks - nEnt = listMCTracks->GetEntriesFast(); - cout << "There are: " << nEnt << " of MC tracks" << endl; - LxMCTrack mcTrack; - - MCTracks.reserve(nEnt); - Int_t* root2lxmctrackmap = new Int_t[nEnt]; - Int_t mapCnt = 0; - - for (int i = 0; i < nEnt; ++i) { - CbmMCTrack* mct = LX_DYNAMIC_CAST<CbmMCTrack*>(listMCTracks->At(i)); - mcTrack.p = mct->GetP(); - Int_t pdgCode = mct->GetPdgCode(); - - if (abs(pdgCode) >= 10000) { - root2lxmctrackmap[i] = -1; - continue; - } - - root2lxmctrackmap[i] = mapCnt++; - - mcTrack.q = TDatabasePDG::Instance()->GetParticle(pdgCode)->Charge() / 3.0; - mcTrack.x = mct->GetStartX(); - mcTrack.y = mct->GetStartY(); - mcTrack.z = mct->GetStartZ(); - mcTrack.px = mct->GetPx(); - mcTrack.py = mct->GetPy(); - mcTrack.pz = mct->GetPz(); - mcTrack.mother_ID = mct->GetMotherId(); - mcTrack.fUniqueID = mct->GetUniqueID(); - mcTrack.pdg = pdgCode; - mcTrack.externalTrack = 0; - MCTracks.push_back(mcTrack); - } - - nEnt = listStsPts->GetEntriesFast(); - cout << "There are: " << nEnt << " of STS MC points" << endl; - - for (int i = 0; i < nEnt; ++i) { - TVector3 xyzI, PI, xyzO, PO; - CbmStsPoint* stsPt = LX_DYNAMIC_CAST<CbmStsPoint*>(listStsPts->At(i)); - - if (0 == stsPt) continue; - - LxStsMCPoint stsMCPoint; - stsPt->Position(xyzI); - stsPt->Momentum(PI); - stsPt->PositionOut(xyzO); - stsPt->MomentumOut(PO); - TVector3 xyz = .5 * (xyzI + xyzO); - TVector3 P = .5 * (PI + PO); - stsMCPoint.x = xyz.X(); - stsMCPoint.y = xyz.Y(); - stsMCPoint.z = xyz.Z(); - stsMCPoint.px = P.X(); - stsMCPoint.py = P.Y(); - stsMCPoint.pz = P.Z(); - stsMCPoint.p = - sqrt(fabs(stsMCPoint.px * stsMCPoint.px + stsMCPoint.py * stsMCPoint.py + stsMCPoint.pz * stsMCPoint.pz)); - stsMCPoint.stationNumber = CbmStsAddress::GetElementId(stsPt->GetDetectorID(), kStsStation); - Int_t trackId = root2lxmctrackmap[stsPt->GetTrackID()]; - - if (-1 != trackId) { - stsMCPoint.mcTrack = &MCTracks[trackId]; - MCStsPoints.push_back(stsMCPoint); - MCTracks[trackId].stsPoints[stsMCPoint.stationNumber].push_back(&MCStsPoints.back()); - MCStsPointsByStations[stsMCPoint.stationNumber].push_back(&MCStsPoints.back()); - } - } - - nEnt = listMuchPts->GetEntriesFast(); - cout << "There are: " << nEnt << " of MUCH MC points" << endl; - LxMCPoint mcPoint; - - MCPoints.reserve(nEnt); - Int_t* root2lxmcpointmap = new Int_t[nEnt]; // Unfortunately we have to use this map because in the loop - // below some iterations can not to produce a point. - mapCnt = 0; - // Int_t mcPtsCount = nEnt; - Int_t maxReferencedPtsIndex = 0; - - for (int i = 0; i < nEnt; ++i) { - TVector3 xyzI, PI, xyzO, PO; - CbmMuchPoint* pt = LX_DYNAMIC_CAST<CbmMuchPoint*>(listMuchPts->At(i)); - - if (!pt) { - root2lxmcpointmap[i] = -1; - continue; - } - - Int_t trackId = root2lxmctrackmap[pt->GetTrackID()]; - - if (-1 == trackId) { - root2lxmcpointmap[i] = -1; - continue; - } - - mcPoint.trackId = trackId; - mcPoint.track = &MCTracks[trackId]; - - root2lxmcpointmap[i] = mapCnt++; - - pt->Position(xyzI); - pt->Momentum(PI); - pt->PositionOut(xyzO); - pt->MomentumOut(PO); - TVector3 xyz = .5 * (xyzI + xyzO); - TVector3 P = .5 * (PI + PO); - mcPoint.x = xyz.X(); - mcPoint.y = xyz.Y(); - mcPoint.z = xyz.Z(); - mcPoint.px = P.X(); - mcPoint.py = P.Y(); - mcPoint.pz = P.Z(); - mcPoint.p = sqrt(fabs(mcPoint.px * mcPoint.px + mcPoint.py * mcPoint.py + mcPoint.pz * mcPoint.pz)); - mcPoint.stationNumber = CbmMuchGeoScheme::GetStationIndex(pt->GetDetectorId()); - mcPoint.layerNumber = CbmMuchGeoScheme::GetLayerIndex(pt->GetDetectorId()); - MCPoints.push_back(mcPoint); - Int_t ptId = root2lxmcpointmap[i]; - - /* -#ifdef MAKE_HISTOS - scaltype trackPt2 = MCTracks[trackId].px * MCTracks[trackId].px + MCTracks[trackId].py * MCTracks[trackId].py; -#endif//MAKE_HISTOS -*/ - - MCTracks[trackId].Points.push_back(&MCPoints[ptId]); -#ifdef MAKE_DISPERSE_2D_HISTOS - MCPointsByStations[mcPoint.stationNumber][mcPoint.layerNumber].push_back(&MCPoints[ptId]); -#endif //MAKE_DISPERSE_2D_HISTOS - } - -#ifdef MAKE_HISTOS - // Build angle (tangent) breaks distribution < - for (vector<LxMCTrack>::iterator i = MCTracks.begin(); i != MCTracks.end(); ++i) { - LxMCTrack& track = *i; - - if ((13 != track.pdg && -13 == track.pdg) || track.mother_ID >= 0) continue; - - if (track.p < 3) continue; - - scaltype pt2 = track.px * track.px + track.py * track.py; - - if (pt2 < 1) continue; - - LxMCPoint* points[LXSTATIONS][LXLAYERS]; - memset(points, 0, sizeof(points)); - - for (vector<LxMCPoint*>::iterator j = track.Points.begin(); j != track.Points.end(); ++j) { - LxMCPoint* point = *j; - points[point->stationNumber][point->layerNumber] = point; - } - - for (int j = 0; j < LXSTATIONS; ++j) { -#ifdef MAKE_DISPERSE_2D_HISTOS - if (0 != points[j][1]) { - LxMCPoint* mPoint = points[j][1]; - scaltype tx = mPoint->x / mPoint->z; - scaltype ty = mPoint->y / mPoint->z; - scaltype diffZ = zCoordsByStations[j][0] - mPoint->z; - scaltype x = mPoint->x + tx * diffZ; - scaltype y = mPoint->y + ty * diffZ; - list<LxMCPoint*>& lPoints = MCPointsByStations[j][0]; - - for (list<LxMCPoint*>::iterator k = lPoints.begin(); k != lPoints.end(); ++k) { - LxMCPoint* lPoint = *k; - - if (lPoint->trackId == mPoint->trackId) - disperseLHistos[j]->Fill(lPoint->x - x, lPoint->y - y, 100.); - else - disperseLHistos[j]->Fill(lPoint->x - x, lPoint->y - y, 0.); - } - - diffZ = zCoordsByStations[j][2] - mPoint->z; - x = mPoint->x + tx * diffZ; - y = mPoint->y + ty * diffZ; - list<LxMCPoint*>& rPoints = MCPointsByStations[j][2]; - - for (list<LxMCPoint*>::iterator k = rPoints.begin(); k != rPoints.end(); ++k) { - LxMCPoint* rPoint = *k; - - if (rPoint->trackId == mPoint->trackId) - disperseRHistos[j]->Fill(rPoint->x - x, rPoint->y - y, 100.); - else - disperseRHistos[j]->Fill(rPoint->x - x, rPoint->y - y, 0.); - } - } - - if (0 != points[j][2]) { - LxMCPoint* rPoint = points[j][2]; - scaltype tx = rPoint->x / rPoint->z; - scaltype ty = rPoint->y / rPoint->z; - scaltype diffZ = zCoordsByStations[j][0] - rPoint->z; - scaltype x = rPoint->x + tx * diffZ; - scaltype y = rPoint->y + ty * diffZ; - list<LxMCPoint*>& lPoints = MCPointsByStations[j][0]; - - for (list<LxMCPoint*>::iterator k = lPoints.begin(); k != lPoints.end(); ++k) { - LxMCPoint* lPoint = *k; - - if (lPoint->trackId == rPoint->trackId) - disperseDHistos[j]->Fill(lPoint->x - x, lPoint->y - y, 100.); - else - disperseDHistos[j]->Fill(lPoint->x - x, lPoint->y - y, 0.); - } - } -#endif //MAKE_DISPERSE_2D_HISTOS - } //for (int j = 0; j < LXSTATIONS; ++j) - } //for (vector<LxMCTrack>::iterator i = MCTracks.begin(); i != MCTracks.end(); ++i) - // > angle (tangent) breaks distribution -#endif //MAKE_HISTOS - -#endif //MAKE_EFF_CALC - - // Read MUCH pixel hits. - scaltype minXErr = 1000; - scaltype minYErr = 1000; - - // At last start invocation of CA procedures. - gettimeofday(&bTime, 0); - caSpace.InitGlobalCAArrays(); - gettimeofday(&eTime, 0); - exeDuration = (eTime.tv_sec - bTime.tv_sec) * 1000000 + eTime.tv_usec - bTime.tv_usec; - Int_t runTime = exeDuration; - bTime.tv_sec = eTime.tv_sec; - bTime.tv_usec = eTime.tv_usec; - - if (parallMode) { - nEnt = 0; - - Int_t stationNumber, layerNumber, i = 0; - Double_t x, y, z, errX, errY, errZ; - - while (hitFile.ReadHit(stationNumber, layerNumber, x, y, z, errX, errY, errZ)) { - LxPoint* lxPoint = caSpace.AddPoint(stationNumber, layerNumber, i++, x, y, z, errX, errY, errZ); - int point_number = caSpace.points_counts[stationNumber][layerNumber]; - caSpace.x_coords[stationNumber][layerNumber][point_number] = x; - caSpace.x_errs[stationNumber][layerNumber][point_number] = errX; - caSpace.y_coords[stationNumber][layerNumber][point_number] = y; - caSpace.y_errs[stationNumber][layerNumber][point_number] = errY; - caSpace.z_coords[stationNumber][layerNumber][point_number] = z; - caSpace.point_refs[stationNumber][layerNumber][point_number] = lxPoint; - ++caSpace.points_counts[stationNumber][layerNumber]; - ++nEnt; - } - } - else // (!parallMode) - { - nEnt = muchPixelHits->GetEntriesFast(); - cout << "There are: " << nEnt << " of MUCH pixel hits" << endl; - - if (hitFileName != "") hitFile.StartEvent(nEnt); - - for (Int_t i = 0; i < nEnt; ++i) { - CbmMuchPixelHit* mh = LX_DYNAMIC_CAST<CbmMuchPixelHit*>(muchPixelHits->At(i)); - - Int_t stationNumber = CbmMuchGeoScheme::GetStationIndex(mh->GetAddress()); - Int_t layerNumber = CbmMuchGeoScheme::GetLayerIndex(mh->GetAddress()); - TVector3 pos, err; - mh->Position(pos); - mh->PositionError(err); - scaltype x = pos.X(); - scaltype y = pos.Y(); - scaltype z = pos.Z(); - - //if (x != x || y != y || z != z)// Test for NaN - //continue; - - if (minXErr > err.X()) minXErr = err.X(); - - if (minYErr > err.Y()) minYErr = err.Y(); - - LxPoint* lxPoint = 0; - - if (!useMCPInsteadOfHits) { - lxPoint = caSpace.AddPoint(stationNumber, layerNumber, i, x, y, z, err.X(), err.Y(), err.Z()); - int point_number = caSpace.points_counts[stationNumber][layerNumber]; - caSpace.x_coords[stationNumber][layerNumber][point_number] = x; - caSpace.x_errs[stationNumber][layerNumber][point_number] = err.X(); - caSpace.y_coords[stationNumber][layerNumber][point_number] = y; - caSpace.y_errs[stationNumber][layerNumber][point_number] = err.Y(); - caSpace.z_coords[stationNumber][layerNumber][point_number] = z; - caSpace.point_refs[stationNumber][layerNumber][point_number] = lxPoint; - ++caSpace.points_counts[stationNumber][layerNumber]; - - if (hitFileName != "") - hitFile.WriteHit(stationNumber, layerNumber, pos.X(), pos.Y(), pos.Z(), err.X(), err.Y(), err.Z()); - } - -#ifdef MAKE_EFF_CALC - Int_t clusterId = mh->GetRefId(); - CbmMuchCluster* cluster = LX_DYNAMIC_CAST<CbmMuchCluster*>(listMuchClusters->At(clusterId)); - Int_t nDigis = cluster->GetNofDigis(); - - for (Int_t j = 0; j < nDigis; ++j) { - CbmMuchDigiMatch* digiMatch = - LX_DYNAMIC_CAST<CbmMuchDigiMatch*>(listMuchPixelDigiMatches->At(cluster->GetDigi(j))); - Int_t nMCs = digiMatch->GetNofLinks(); - - for (Int_t k = 0; k < nMCs; ++k) { - const CbmLink& lnk = digiMatch->GetLink(k); - Int_t mcIndex = lnk.GetIndex(); - - if (-1 == mcIndex) continue; - - if (mcIndex > maxReferencedPtsIndex) maxReferencedPtsIndex = mcIndex; - - Int_t mcIndexMapped = root2lxmcpointmap[mcIndex]; - - if (-1 == mcIndexMapped) continue; - - if (!useMCPInsteadOfHits) { - MCPoints[mcIndexMapped].lxPoints.push_back(lxPoint); -#ifdef MAKE_EFF_CALC - lxPoint->mcPoints.push_back(&MCPoints[mcIndexMapped]); -#endif //MAKE_EFF_CALC - } -#ifdef MAKE_EFF_CALC - else if (MCPoints[mcIndexMapped].lxPoints.empty()) { - LxMCPoint& mcp = MCPoints[mcIndexMapped]; - lxPoint = caSpace.AddPoint(stationNumber, layerNumber, i, mcp.x, mcp.y, mcp.z, err.X(), err.Y(), err.Z()); - MCPoints[mcIndexMapped].lxPoints.push_back(lxPoint); - lxPoint->mcPoints.push_back(&MCPoints[mcIndexMapped]); - } -#endif //MAKE_EFF_CALC - } - } -#endif //MAKE_EFF_CALC - } // for (Int_t i = 0; i < nEnt; ++i) - - if (hitFileName != "") hitFile.EndEvent(); - } //else (!parallMode) - - cout << "minXErr = " << minXErr << " ; minYErr = " << minYErr << endl << endl; - - // At last start invocation of CA procedures. - gettimeofday(&eTime, 0); - exeDuration = (eTime.tv_sec - bTime.tv_sec) * 1000000 + eTime.tv_usec - bTime.tv_usec; - - if (verbosity > 0) cout << "Execution duration 1 was: " << exeDuration << endl; - - if (calcMiddlePoints) caSpace.RestoreMiddlePoints(); - - bTime.tv_sec = eTime.tv_sec; - bTime.tv_usec = eTime.tv_usec; - gettimeofday(&eTime, 0); - exeDuration = (eTime.tv_sec - bTime.tv_sec) * 1000000 + eTime.tv_usec - bTime.tv_usec; - - if (verbosity > 0) cout << "Execution duration 2 was: " << exeDuration << endl; -#ifdef CLUSTER_MODE - caSpace.BuildRays2(); -#else //CLUSTER_MODE - //caSpace.BuildRays(); - caSpace.RefineMiddlePoints(); - caSpace.BuildRaysGlobal(); -#endif //CLUSTER_MODE - bTime.tv_sec = eTime.tv_sec; - bTime.tv_usec = eTime.tv_usec; - gettimeofday(&eTime, 0); - exeDuration = (eTime.tv_sec - bTime.tv_sec) * 1000000 + eTime.tv_usec - bTime.tv_usec; - //Int_t runTime = exeDuration; - runTime += exeDuration; - - if (verbosity > 0) cout << "Execution duration 3 was: " << exeDuration << endl; - -#ifdef CLUSTER_MODE - caSpace.ConnectNeighbours2(); -#else //CLUSTER_MODE - caSpace.ConnectNeighbours(); -#endif //CLUSTER_MODE - bTime.tv_sec = eTime.tv_sec; - bTime.tv_usec = eTime.tv_usec; - gettimeofday(&eTime, 0); - exeDuration = (eTime.tv_sec - bTime.tv_sec) * 1000000 + eTime.tv_usec - bTime.tv_usec; - runTime += exeDuration; - - if (verbosity > 0) cout << "Execution duration 4 was: " << exeDuration << endl; -#ifdef CLUSTER_MODE - caSpace.Reconstruct2(); -#else //CLUSTER_MODE - caSpace.Reconstruct(); -#endif //CLUSTER_MODE - //caSpace.FitTracks(); - bTime.tv_sec = eTime.tv_sec; - bTime.tv_usec = eTime.tv_usec; - gettimeofday(&eTime, 0); - exeDuration = (eTime.tv_sec - bTime.tv_sec) * 1000000 + eTime.tv_usec - bTime.tv_usec; - runTime += exeDuration; - - wholeDuration += runTime; - averageDuration = wholeDuration / nTimes; - cout << "Average execution duration 3 + 4 + 5 was: " << averageDuration << endl; - - if (parallMode) { - Int_t* pOutRunTime = reinterpret_cast<Int_t*>(const_cast<char*>(opt)); - *pOutRunTime = runTime; - } - - if (verbosity > 0) cout << "Execution duration 5 was: " << exeDuration << endl; - - //caSpace.FitTracks(); - //cout << "maxReferencedPtsIndex=" << maxReferencedPtsIndex << " mcPtsCount=" << mcPtsCount << " GEF=" << listMuchPts->GetEntriesFast() << endl; - //cout << "Hits=" << muchPixelHits->GetEntriesFast() << " clusters=" << listMuchClusters->GetEntriesFast() << " digi ms=" << listMuchPixelDigiMatches->GetEntriesFast() << endl; - //sleep(3); - - ///////////////////////////////////////////////////////////////////////////////// - // Join MUCH-tracks with STS-tracks. - ///////////////////////////////////////////////////////////////////////////////// - - if (linkWithSts) { - // STS-tracks fulfilling the limitations peculiar for muons are picked up in the loop below. - nEnt = listStsTracks->GetEntriesFast(); - - for (int i = 0; i < nEnt; ++i) { - CbmStsTrack* stsTrack = LX_DYNAMIC_CAST<CbmStsTrack*>(listStsTracks->At(i)); - - scaltype lpa[5] = {static_cast<Float_t>(stsTrack->GetParamLast()->GetX()), - static_cast<Float_t>(stsTrack->GetParamLast()->GetY()), - static_cast<Float_t>(stsTrack->GetParamLast()->GetTx()), - static_cast<Float_t>(stsTrack->GetParamLast()->GetTy()), - static_cast<Float_t>(stsTrack->GetParamLast()->GetQp())}; - - if (lpa[0] != lpa[0] || lpa[1] != lpa[1] || lpa[2] != lpa[2] || lpa[3] != lpa[3] || lpa[4] != lpa[4]) continue; - - CbmStsTrack aTrack = *stsTrack; - - Int_t pdgHypo = 13; - - if (stsTrack->GetParamLast()->GetTx() > stsTrack->GetParamFirst()->GetTx()) pdgHypo = -13; - - extFitter.DoFit(&aTrack, pdgHypo); - scaltype chi2Prim = extFitter.GetChiToVertex(&aTrack, fPrimVtx); - FairTrackParam params; - extFitter.Extrapolate(&aTrack, fPrimVtx->GetZ(), ¶ms); - scaltype p = 1 / params.GetQp(); - scaltype p2 = p * p; - - if (p2 < 3.0 * 3.0) continue; - - /* - scaltype xDelta = 0.05;//5.0 * sqrt(params.GetCovariance(0, 0)); - scaltype yDelta = 0.05;//5.0 * sqrt(params.GetCovariance(1, 1)); - - if (params.GetX() < -xDelta || params.GetX() > xDelta || params.GetY() < -yDelta || params.GetY() > yDelta) - continue; -*/ - - scaltype tx2 = params.GetTx() * params.GetTx(); - scaltype ty2 = params.GetTy() * params.GetTy(); - scaltype pt2 = p2 * (tx2 + ty2) / (1 + tx2 + ty2); - - if (pt2 < 1.0) continue; - - LxExtTrack extTrack; - extTrack.track = stsTrack; - extTrack.extId = i; - -#ifdef MAKE_EFF_CALC - CbmTrackMatch* match = LX_DYNAMIC_CAST<CbmTrackMatch*>(listStsMatches->At(i)); - Int_t numberOfHits = match->GetNofTrueHits() + match->GetNofWrongHits() + match->GetNofFakeHits(); - - if (match->GetNofTrueHits() >= 0.7 * numberOfHits) { - Int_t mcTrackId = match->GetMCTrackId(); - Int_t mappedId = root2lxmctrackmap[mcTrackId]; - - if (-1 != mappedId) { - MCTracks[mappedId].externalTrack = stsTrack; - extTrack.mcTrack = &MCTracks[mappedId]; - - if (13 == MCTracks[mappedId].pdg || -13 == MCTracks[mappedId].pdg) { -#ifdef MAKE_HISTOS - stsTrackChi2->Fill(chi2Prim); - stsTrackX->Fill(params.GetX()); - stsTrackY->Fill(params.GetY()); -#endif //MAKE_HISTOS - } - } - } -#endif //MAKE_EFF_CALC - - caSpace.extTracks.push_back(extTrack); - } - - cout << "External tracks are read" << endl; - - // Join reconstructed tracks with external tracks. - caSpace.JoinExtTracks(); - cout << "External tracks are connected" << endl; - } // if(linkWithSts) - - // Measure a reconstruction efficiency. -#ifdef MAKE_EFF_CALC - if (!parallMode) { - MatchMCToReco(); - MatchRecoToMC(); - } -#endif //MAKE_EFF_CALC - if (Trigger()) { - if (hasSignalInEvent) ++trueSignalTriggerings; - - ++falseSignalTriggerings; - } - - { - Double_t result = 100 * trueSignalTriggerings; - result /= signalCounter; - cout << "Signal true hypotheses: " << result << "% ( " << trueSignalTriggerings << " / " << signalCounter << " )" - << endl; - cout << "Signal all hypotheses: " << falseSignalTriggerings << endl; - } - - // Draw some result. - //static LxDraw drawer; - - //drawer.ClearView(); - //drawer.DrawMuch(); - //drawer.SaveCanvas("Geometry_"); - - //drawer.ClearView(); - //drawer.DrawInputHits(); - //drawer.SaveCanvas("Hits_"); - //drawer.Ask(); - - //drawer.ClearView(); - //drawer.DrawInputHits(); - //drawer.DrawMCTracks(); - //gPad->WaitPrimitive(); - //drawer.ClearView(); - //drawer.DrawInputHits(); - //drawer.DrawRecoTracks(); - //drawer.DrawExtTracks(); - //drawer.SaveCanvas("MC_"); - //gPad->WaitPrimitive(); - - /*drawer.ClearView(); - drawer.DrawInputHits(); - drawer.DrawMCTracks(); - drawer.DrawRays(); - gPad->WaitPrimitive();*/ - - //drawer.ClearView(); - //drawer.DrawInputHits(); - //drawer.DrawRecoTracks(); - //drawer.SaveCanvas("Reco_"); - //drawer.Ask(); - - //drawer.ClearView(); - //drawer.DrawInputHits(); - //drawer.DrawRecoTracks(); - //drawer.DrawExtTracks(); - //drawer.Ask(); - - if (generateInvMass) CalcInvMass(); - - if (generateBackground) SaveEventTracks(); - - // Finally save reconstructed tracks. - if (!parallMode) SaveRecoTracks(); - -#ifdef MAKE_EFF_CALC - // Hopefully we don't need these two maps any more. - delete[] root2lxmctrackmap; - delete[] root2lxmcpointmap; -#endif //MAKE_EFF_CALC - - ++eventNumber; - ++nTimes; -} - -void LxFinder::SaveRecoTracks() -{ - Int_t trackNo = listRecoTracks->GetEntriesFast(); - - for (list<LxTrack*>::iterator i = caSpace.tracks.begin(); i != caSpace.tracks.end(); ++i) { - LxTrack* recoTrack = *i; - - if (recoTrack->clone) continue; - - if (saveOnlyTriggeringTracks && !recoTrack->triggering) continue; - - LxExtTrack* stsTrack = recoTrack->externalTrack; - - if (0 == stsTrack) continue; - - CbmMuchTrack muchTrack; - - for (int j = 0; j < LXSTATIONS * LXLAYERS; ++j) { - LxPoint* pPoint = recoTrack->points[j]; - - if (0 != pPoint) muchTrack.AddHit(pPoint->hitId, kMUCHPIXELHIT); - } - - muchTrack.SetChiSq(recoTrack->chi2); - muchTrack.SetNDF(4 * recoTrack->length); // Probably need to calculate it more accurately. - muchTrack.SetPreviousTrackId(stsTrack->extId); - - FairTrackParam parFirst; - parFirst = *stsTrack->track->GetParamLast(); - muchTrack.SetFlag(0); // Good track. - - FairTrackParam parLast(parFirst); - muchTrack.SetParamFirst(&parFirst); - muchTrack.SetParamLast(&parLast); - - new ((*listRecoTracks)[trackNo++]) CbmMuchTrack(muchTrack); - } -} - -void LxFinder::CalcInvMass() -{ -#ifdef MAKE_HISTOS - for (list<LxTrack*>::iterator i = caSpace.tracks.begin(); i != caSpace.tracks.end(); ++i) { - LxTrack* firstTrack = *i; - LxMCTrack* mcTrack1 = firstTrack->mcTrack; - - if (0 == firstTrack->externalTrack) continue; - - LxMCTrack* mcTrack2 = firstTrack->externalTrack->mcTrack; - - if (mcTrack1) { - // Int_t pdg1 = mcTrack1 ? mcTrack1->pdg : 10000; - //map<Int_t, map<Int_t, int> >::iterator j = particleCounts.find(pdg1); - - //if (j == particleCounts.end()) - //j = particleCounts.insert(pair<Int_t, map<Int_t, int> > (pdg1, map<Int_t, int> ())).first; - - // Int_t pdg2 = mcTrack2 ? mcTrack2->pdg : 10000; - - //map<Int_t, int>::iterator k = j->second.find(pdg2); - - //if (k != j->second.end()) - //++(k->second); - //else - //j->second.insert(pair<Int_t, int> (pdg2, 1)); - } - - CbmStsTrack t1 = *firstTrack->externalTrack->track; - - // Add entry to the respective chi2 histogram if needed. This can be used for placing chi2 cuts determining J/psi. - // pdg == 13 | -13 -- it is a muon. - // mother_ID < 0 -- it is a primary particle. URQMD doesn't produce primary muons. So it from PLUTO <=> is J/psi. - - if (generateChi2) { - scaltype normalizedChi2 = firstTrack->chi2 / (firstTrack->length * 4); // length * 4 == NDF. - - if (mcTrack2 && (mcTrack2->pdg == 13 || mcTrack2->pdg == -13) && mcTrack2->mother_ID < 0) - signalChi2Histo->Fill(normalizedChi2); - else - backgroundChi2Histo->Fill(normalizedChi2); - } - - if (!mcTrack2 || (mcTrack2->pdg != 13 && mcTrack2->pdg != -13) || mcTrack2->mother_ID >= 0) continue; - - extFitter.DoFit(&t1, 13); - scaltype chi2Prim = extFitter.GetChiToVertex(&t1, fPrimVtx); - FairTrackParam t1param; - extFitter.Extrapolate(&t1, fPrimVtx->GetZ(), &t1param); - - if (t1param.GetQp() <= 0) continue; - - scaltype p1 = 1 / t1param.GetQp(); - scaltype tx12 = t1param.GetTx() * t1param.GetTx(); - scaltype ty12 = t1param.GetTy() * t1param.GetTy(); - scaltype pt12 = p1 * p1 * (tx12 + ty12) / (1 + tx12 + ty12); - - if (pt12 < 1) continue; - - CbmKFTrack muPlus(t1); - - for (list<LxTrack*>::iterator j = caSpace.tracks.begin(); j != caSpace.tracks.end(); ++j) { - LxTrack* secondTrack = *j; - - if (0 == secondTrack->externalTrack) continue; - - LxMCTrack* mcSecondTrack = secondTrack->externalTrack->mcTrack; - - if (!mcSecondTrack || (mcSecondTrack->pdg != 13 && mcSecondTrack->pdg != -13) || mcSecondTrack->mother_ID >= 0) - continue; - - CbmStsTrack t2 = *secondTrack->externalTrack->track; - extFitter.DoFit(&t2, 13); - chi2Prim = extFitter.GetChiToVertex(&t2, fPrimVtx); - FairTrackParam t2param; - extFitter.Extrapolate(&t2, fPrimVtx->GetZ(), &t2param); - - if (t2param.GetQp() >= 0) continue; - - scaltype p2 = 1 / t2param.GetQp(); - scaltype tx22 = t2param.GetTx() * t2param.GetTx(); - scaltype ty22 = t2param.GetTy() * t2param.GetTy(); - scaltype pt22 = p2 * p2 * (tx22 + ty22) / (1 + tx22 + ty22); - - if (pt22 < 1) continue; - - CbmKFTrack muMinus(t2); - vector<CbmKFTrackInterface*> kfData; - kfData.push_back(&muPlus); - kfData.push_back(&muMinus); - } - } -#endif //MAKE_HISTOS -} - -//#ifdef MAKE_HISTOS -// It also deletes the histogram. -static void SaveHisto(TH1* histo, const char* name) -{ - TFile fh(name, "RECREATE"); - histo->Write(); - fh.Close(); - delete histo; -} - -static void SaveHisto(TH2* histo, const char* name) -{ - TFile fh(name, "RECREATE"); - histo->Write(); - fh.Close(); - delete histo; -} -//#endif//MAKE_HISTOS - -void LxFinder::FinishTask() -{ - TString complexFileName; - - if (generateInvMass) SaveInvMass(); - - if (generateBackground) SaveBackground(); - - /*if (generateChi2) - { - SaveSignalChi2(); - SaveBackgroundChi2(); - } - - cout << "Statistics on particles found:" << endl; - - for (map<Int_t, map<Int_t, int> >::iterator i = particleCounts.begin(); i != particleCounts.end(); ++i) - { - string muchParticle = (10000 <= i->first || -10000 >= i->first) ? "Undefined MUCH particle" : TDatabasePDG::Instance()->GetParticle(i->first)->GetName(); - cout << "For MUCH particle [ " << muchParticle << " ] ( PDG = " << i->first << " ) found STS joints to:" << endl; - - for (map<Int_t, int>::iterator j = i->second.begin(); j != i->second.end(); ++j) - { - string stsParticle = (10000 <= j->first || -10000 >= j->first) ? "Undefined STS particle" : TDatabasePDG::Instance()->GetParticle(j->first)->GetName(); - cout << "\t" << j->second << " [ " << stsParticle << " ] ( PDG = " << j->first << " )" << endl; - } - }*/ - TFile* curFile = TFile::CurrentFile(); -#ifdef MAKE_HISTOS -#ifdef MAKE_DISPERSE_2D_HISTOS - char histoFileName[128]; - - for (int i = 0; i < 6; ++i) { - sprintf(histoFileName, "disperseL_histo_%d.root", i); - SaveHisto(disperseLHistos[i], histoFileName); - sprintf(histoFileName, "disperseR_histo_%d.root", i); - SaveHisto(disperseRHistos[i], histoFileName); - sprintf(histoFileName, "disperseD_histo_%d.root", i); - SaveHisto(disperseDHistos[i], histoFileName); - } -#endif //MAKE_DISPERSE_2D_HISTOS -#endif //MAKE_HISTOS - -#ifdef MAKE_HISTOS - { - TFile fh("effByMomentumProfile.root", "RECREATE"); - effByMomentumProfile->Write(); - fh.Close(); - delete effByMomentumProfile; - } - - SaveHisto(stsTrackChi2, "stsTrackChi2.root"); - SaveHisto(stsTrackX, "stsTrackX.root"); - SaveHisto(stsTrackY, "stsTrackY.root"); - - SaveHisto(muPlusDtxHisto, "muPlusDtxHisto.root"); - SaveHisto(muMinusDtxHisto, "muMinusDtxHisto.root"); - SaveHisto(signalXAtZ0, "signalXAtZ0.root"); - SaveHisto(signalYAtZ0, "signalYAtZ0.root"); - SaveHisto(bgrXAtZ0, "bgrXAtZ0.root"); - SaveHisto(bgrYAtZ0, "bgrYAtZ0.root"); - SaveHisto(signalInterTracksDistance, "signalInterTracksDistance.root"); - SaveHisto(bgrInterTracksDistance, "bgrInterTracksDistance.root"); - SaveHisto(signalTanSigns, "signalTanSigns.root"); - SaveHisto(signalCoordSigns, "signalCoordSigns.root"); - SaveHisto(bgrTanSigns, "bgrTanSigns.root"); - SaveHisto(bgrCoordSigns, "bgrCoordSigns.root"); - SaveHisto(numberOfTracks, "numberOfTracks.root"); - SaveHisto(signalInterTracksDistanceOn1st, "signalInterTracksDistanceOn1st.root"); - SaveHisto(bgrInterTracksDistanceOn1st, "bgrInterTracksDistanceOn1st.root"); - SaveHisto(bgrInterTracksDistanceOn1stSigns, "bgrInterTracksDistanceOn1stSigns.root"); - SaveHisto(signalInterTracksAngle, "signalInterTracksAngle.root"); - SaveHisto(bgrInterTracksAngle, "bgrInterTracksAngle.root"); - SaveHisto(signalInterTrackCorrDA, "signalInterTrackCorrDA.root"); - SaveHisto(bgrInterTrackCorrDA, "bgrInterTrackCorrDA.root"); - SaveHisto(muchMomErrSig, "muchMomErrSig.root"); - SaveHisto(muchMomErrBgr, "muchMomErrBgr.root"); -#ifdef MAKE_TRIGGERING_HISTOS - complexFileName = "triggeringAllTracksVertices"; - complexFileName += fileSaveSuffix; - complexFileName += ".root"; - SaveHisto(triggeringAllTracksVertices, complexFileName); - complexFileName = "triggeringDistTracksVertices"; - complexFileName += fileSaveSuffix; - complexFileName += ".root"; - SaveHisto(triggeringDistTracksVertices, complexFileName); - complexFileName = "triggeringSignTracksVertices"; - complexFileName += fileSaveSuffix; - complexFileName += ".root"; - SaveHisto(triggeringSignTracksVertices, complexFileName); - complexFileName = "triggeringTrigTracksVertices"; - complexFileName += fileSaveSuffix; - complexFileName += ".root"; - SaveHisto(triggeringTrigTracksVertices, complexFileName); -#endif //MAKE_TRIGGERING_HISTOS - -#endif //MAKE_HISTOS - - TFile::CurrentFile() = curFile; - -#ifdef MAKE_EFF_CALC - incomplete_events.close(); -#endif //MAKE_EFF_CALC - - delete superEventData; - -#ifdef MAKE_EFF_CALC - ofstream fjtofs("../false_jpsi_triggerings.txt", ios_base::out | ios_base::app); - fjtofs << falseSignalTriggerings << endl; -#endif //MAKE_EFF_CALC - - complexFileName = "particles_count_all"; - complexFileName += fileSaveSuffix; - complexFileName += ".txt"; - ofstream pcaofs(complexFileName); - - for (map<string, unsigned int>::iterator i = particlesCountAll.begin(); i != particlesCountAll.end(); ++i) - pcaofs << i->first << ": " << i->second << endl; - - complexFileName = "particles_count_sign"; - complexFileName += fileSaveSuffix; - complexFileName += ".txt"; - ofstream pcsofs(complexFileName); - - for (map<string, unsigned int>::iterator i = particlesCountSign.begin(); i != particlesCountSign.end(); ++i) - pcsofs << i->first << ": " << i->second << endl; - - complexFileName = "particles_count_dist"; - complexFileName += fileSaveSuffix; - complexFileName += ".txt"; - ofstream pcdofs(complexFileName); - - for (map<string, unsigned int>::iterator i = particlesCountDist.begin(); i != particlesCountDist.end(); ++i) - pcdofs << i->first << ": " << i->second << endl; - - complexFileName = "particles_count_trig"; - complexFileName += fileSaveSuffix; - complexFileName += ".txt"; - ofstream pctofs(complexFileName); - - for (map<string, unsigned int>::iterator i = particlesCountTrig.begin(); i != particlesCountTrig.end(); ++i) - pctofs << i->first << ": " << i->second << endl; - - if (hitFileName != "") hitFile.Close(); - - FairTask::FinishTask(); -} - -void LxFinder::SaveInvMass() -{ -#ifdef MAKE_HISTOS - TFile* curFile = TFile::CurrentFile(); - - TFile fh("jpsi_inv_mass_histo.root", "RECREATE"); - massHisto->Write(); - fh.Close(); - delete massHisto; - - TFile::CurrentFile() = curFile; -#endif //MAKE_HISTOS -} - -void LxFinder::SaveBackground() -{ -#ifdef MAKE_HISTOS - for (list<CbmStsTrack>::iterator i = positiveTracks.begin(); i != positiveTracks.end(); ++i) { - CbmStsTrack& t1 = *i; - CbmKFTrack muPlus(t1); - - for (list<CbmStsTrack>::iterator j = negativeTracks.begin(); j != negativeTracks.end(); ++j) { - CbmStsTrack& t2 = *j; - CbmKFTrack muMinus(t2); - vector<CbmKFTrackInterface*> kfData; - kfData.push_back(&muPlus); - kfData.push_back(&muMinus); - } - } - - TFile* curFile = TFile::CurrentFile(); - - TFile fh("tracks_tree.root", "RECREATE"); - superEventTracks->Write(); - fh.Close(); - delete superEventTracks; - - TFile::CurrentFile() = curFile; -#endif //MAKE_HISTOS -} - -void LxFinder::SaveSignalChi2() -{ -#ifdef MAKE_HISTOS - TFile* curFile = TFile::CurrentFile(); - - TFile fh("signal_chi2_histo.root", "RECREATE"); - signalChi2Histo->Write(); - fh.Close(); - delete signalChi2Histo; - - TFile::CurrentFile() = curFile; -#endif //MAKE_HISTOS -} - -void LxFinder::SaveBackgroundChi2() -{ -#ifdef MAKE_HISTOS - TFile* curFile = TFile::CurrentFile(); - - TFile fh("background_chi2_histo.root", "RECREATE"); - backgroundChi2Histo->Write(); - fh.Close(); - delete backgroundChi2Histo; - - TFile::CurrentFile() = curFile; -#endif //MAKE_HISTOS -} - -bool LxFinder::ReadEvent(Int_t evNum) { return hitFile.ReadEvent(evNum); } diff --git a/reco/tracking/lx/Simple/Lx.h b/reco/tracking/lx/Simple/Lx.h deleted file mode 100644 index 1e75edd6fcb33029855400bd27eebbde74111815..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/Simple/Lx.h +++ /dev/null @@ -1,238 +0,0 @@ -/* Copyright (C) 2014-2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifndef LX_INCLUDED -#define LX_INCLUDED - -#pragma GCC diagnostic ignored "-Weffc++" - -#include "CbmMuchPixelHit.h" - -#include "FairTask.h" - -#include "TClonesArray.h" - -#include <unistd.h> - -#include "LxCA.h" -#include "LxMC.h" -//#include "LxEff.h" -#include "CbmStsKFTrackFitter.h" -#include "CbmTrackMatch.h" -#include "CbmVertex.h" - -#include "FairFileHeader.h" -#include "FairRunAna.h" - -#include "TH1.h" -#include "TProfile.h" -#include "TProfile2D.h" - -#include <fstream> - -#ifdef FAST_CODE -#define LX_DYNAMIC_CAST static_cast -#else // FAST_CODE -#define LX_DYNAMIC_CAST dynamic_cast -#endif // FAST_CODE - -class LxHitFile { -public: - LxHitFile(); - ~LxHitFile(); - bool Open(TString fileName, bool forWrite); - bool StartEvent(Int_t nEnt); - bool EndEvent(); - bool WriteHit(Int_t stationNumber, Int_t layerNumber, Double_t x, Double_t y, Double_t z, Double_t xErr, - Double_t yErr, Double_t zErr); - bool ReadEvent(Int_t eventNumber); - bool ReadHit(Int_t& stationNumber, Int_t& layerNumber, Double_t& x, Double_t& y, Double_t& z, Double_t& xErr, - Double_t& yErr, Double_t& zErr); - bool Close(); - -private: - bool useForWrite; - int fd; - std::list<off_t> eventOffs; - char* evBuf; - int bufSize; - char* evPtr; - char* evEnd; -}; - -extern TString lxFinderParticleType; - -struct LxStsMCPoint { - scaltype p, q, x, y, z, px, py, pz; - Int_t stationNumber; - LxMCTrack* mcTrack; -}; - -class LxFinder : public FairTask { - //friend struct LxEff; - friend class LxDraw; - friend class LxParallFinder; - friend class FinderCapsule; - -public: - static LxFinder* Instance(); - explicit LxFinder(); - ~LxFinder(); - InitStatus Init(); // Inherited virtual. - void Exec(Option_t* opt); // Inherited virtual. - - void SetGenInvMass(bool value) { generateInvMass = value; } - - void SetGenBackground(bool value) { generateBackground = value; } - - void SetGenChi2(bool value) { generateChi2 = value; } - - void SetLinkWithSts(bool value) { linkWithSts = value; } - - void SetUseMCPInsteadOfHits(bool value) { useMCPInsteadOfHits = value; } - - void SetCalcMiddlePoints(bool value) { calcMiddlePoints = value; } - - void SetCutCoeff(scaltype value) { cutCoeff = value; } - - void SetSaveOnlyTriggeringTracks(bool value) { saveOnlyTriggeringTracks = value; } - - void SetVerbosity(Int_t v) { verbosity = v; } - - void SetParallMode(bool v) { parallMode = v; } - - void SetHitFileName(TString v) { hitFileName = v; } - - void SetFileSaveSuffix(TString v) { fileSaveSuffix = v; } - - void SetParticleType(TString v) - { - particleType = v; - lxFinderParticleType = v; - - if (v == "omega") { - caSpace.stationsInAlgo = 5; -#ifdef MAKE_EFF_CALC - pPtCut = false; -#endif //MAKE_EFF_CALC - } - } - -private: - void SaveRecoTracks(); - void CalcInvMass(); - void FinishTask(); // Inherited virtual. - void SaveEventTracks(); - void SaveInvMass(); - void SaveBackground(); - void SaveSignalChi2(); - void SaveBackgroundChi2(); - bool Trigger(); - bool ReadEvent(Int_t evNum); - static LxFinder* fInstance; - TClonesArray* muchPixelHits; - TClonesArray* listMCTracks; - TClonesArray* listMuchPts; - TClonesArray* listMuchClusters; - TClonesArray* listMuchPixelDigiMatches; - TClonesArray* listStsTracks; - TClonesArray* listStsMatches; - TClonesArray* listStsPts; // STS MC-points array. Used for experiments with STS matching. - TClonesArray* listRecoTracks; // It is an output array. -#ifdef MAKE_EFF_CALC - //LxEff effCounter; - void MatchMCToReco(); - void MatchRecoToMC(); -#endif //MAKE_EFF_CALC - CbmStsTrack* superEventData; -#ifdef MAKE_HISTOS - static TH1F* massHisto; - //static TH1F* backgroundMassHisto; - static TTree* superEventTracks; - static TH1F* signalChi2Histo; - static TH1F* backgroundChi2Histo; - static TProfile* effByMomentumProfile; - static TH1F* muPlusDtxHisto; - static TH1F* muMinusDtxHisto; - static TH1F* signalXAtZ0; - static TH1F* signalYAtZ0; - static TH1F* bgrXAtZ0; - static TH1F* bgrYAtZ0; - static TH1F* signalInterTracksDistance; - static TH1F* bgrInterTracksDistance; - static TH1F* signalTanSigns; - static TH1F* signalCoordSigns; - static TH1F* bgrTanSigns; - static TH1F* bgrCoordSigns; - static TH1F* numberOfTracks; - static TH1F* signalInterTracksDistanceOn1st; - static TH1F* signalInterTracksAngle; - static TH2F* signalInterTrackCorrDA; - static TH1F* bgrInterTracksDistanceOn1st; - static TH1F* bgrInterTracksAngle; - static TH2F* bgrInterTrackCorrDA; - static TH1F* bgrInterTracksDistanceOn1stSigns; - static TH1F* muchMomErrSig; - static TH1F* muchMomErrBgr; -#endif // static CbmStsTrack* superEventData; - - CbmStsKFTrackFitter extFitter; - CbmVertex* fPrimVtx; - // These two containers below accumulates respectively all positive and all negative reconstructed tracks for all events. - std::list<CbmStsTrack> positiveTracks; - std::list<CbmStsTrack> negativeTracks; - bool generateInvMass; - bool generateBackground; - bool generateChi2; - bool linkWithSts; - bool useMCPInsteadOfHits; - bool calcMiddlePoints; - scaltype cutCoeff; - Int_t verbosity; - bool parallMode; - TString hitFileName; - TString fileSaveSuffix; - TString particleType; - bool pPtCut; - std::vector<LxMCPoint> MCPoints; // Points should lay here in the same order as in listMuchPts. - std::vector<LxMCTrack> MCTracks; // Tracks should lay here in the same order as in listMCTracks. - std::list<LxStsMCPoint> MCStsPoints; - std::list<LxStsMCPoint*> MCStsPointsByStations[8]; -#ifdef MAKE_DISPERSE_2D_HISTOS - std::list<LxMCPoint*> MCPointsByStations[LXSTATIONS][LXLAYERS]; - scaltype zCoordsByStations[LXSTATIONS][LXLAYERS]; -#endif //MAKE_DISPERSE_2D_HISTOS - LxSpace caSpace; - //std::map<Int_t, std::map<Int_t, int> > particleCounts; -#ifdef MAKE_EFF_CALC - std::ofstream incomplete_events; // Events where not all tracks are reconstructed. - Int_t falseSignalTriggerings; - Int_t trueSignalTriggerings; - bool hasSignalInEvent; //hasJPsiInEvent; - Int_t signalCounter; //jpsiCounter; -#endif //MAKE_EFF_CALC - Int_t eventNumber; -#ifdef CALC_MUCH_DETECTORS_EFF - Int_t mcPointsCount; - Int_t mcPointsTriggered; -#endif //CALC_MUCH_DETECTORS_EFF - bool saveOnlyTriggeringTracks; -#ifdef MAKE_TRIGGERING_HISTOS - static TH1F* triggeringAllTracksVertices; - static TH1F* triggeringDistTracksVertices; - static TH1F* triggeringSignTracksVertices; - static TH1F* triggeringTrigTracksVertices; -#endif //MAKE_TRIGGERING_HISTOS - std::map<string, unsigned int> particlesCountAll; - std::map<string, unsigned int> particlesCountSign; - std::map<string, unsigned int> particlesCountDist; - std::map<string, unsigned int> particlesCountTrig; - LxHitFile hitFile; - - ClassDef(LxFinder, 1); -}; - -#pragma GCC diagnostic warning "-Weffc++" - -#endif //LX_INCLUDED diff --git a/reco/tracking/lx/Simple/LxCA.cxx b/reco/tracking/lx/Simple/LxCA.cxx deleted file mode 100644 index a9a7441f18a56df089bffdce6085b9078c7dddf0..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/Simple/LxCA.cxx +++ /dev/null @@ -1,2417 +0,0 @@ -/* Copyright (C) 2014-2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#include "LxCA.h" - -#include <iostream> - -#include "Lx.h" -#pragma GCC diagnostic ignored "-Weffc++" - -#ifdef CLUSTER_MODE -#include "kdtree++/kdtree.hpp" -#endif //CLUSTER_MODE - -#include <sys/time.h> -#ifdef BEST_SIX_POINTS -#include <set> -#endif //BEST_SIX_POINTS - -#include "base/CbmLitToolFactory.h" -#include "utils/CbmLitConverterFairTrackParam.h" - -#include <cmath> - -using namespace std; - -scaltype tx_limits[LXSTATIONS]; -scaltype tx_limits_sq[LXSTATIONS]; -scaltype ty_limits[LXSTATIONS]; -scaltype ty_limits_sq[LXSTATIONS]; -scaltype x_disp_left_limits[LXSTATIONS]; -scaltype x_disp_left_limits_sq[LXSTATIONS]; -scaltype y_disp_left_limits[LXSTATIONS]; -scaltype y_disp_left_limits_sq[LXSTATIONS]; -scaltype x_disp_right_limits[LXSTATIONS]; -scaltype x_disp_right_limits_sq[LXSTATIONS]; -scaltype y_disp_right_limits[LXSTATIONS]; -scaltype y_disp_right_limits_sq[LXSTATIONS]; -/*scaltype x_coords[LXSTATIONS][LXLAYERS][LXMAXPOINTSONSTATION]; -scaltype tx_vals[LXSTATIONS - 1][LXMAXPOINTSONSTATION]; -scaltype x_errs[LXSTATIONS][LXLAYERS][LXMAXPOINTSONSTATION]; -scaltype y_coords[LXSTATIONS][LXLAYERS][LXMAXPOINTSONSTATION]; -scaltype ty_vals[LXSTATIONS][LXMAXPOINTSONSTATION]; -scaltype y_errs[LXSTATIONS][LXLAYERS][LXMAXPOINTSONSTATION]; -scaltype z_coords[LXSTATIONS][LXLAYERS][LXMAXPOINTSONSTATION]; -LxPoint* point_refs[LXSTATIONS][LXLAYERS][LXMAXPOINTSONSTATION]; -bool use_points[LXSTATIONS - 1][LXMAXPOINTSONSTATION]; -int points_counts[LXSTATIONS][LXLAYERS];*/ - -void LxSpace::InitGlobalCAArrays() -{ - memset(x_coords, 0, sizeof(scaltype) * LXSTATIONS * LXLAYERS * LXMAXPOINTSONSTATION); - memset(tx_vals, 0, sizeof(scaltype) * (LXSTATIONS - 1) * LXLAYERS * LXMAXPOINTSONSTATION); - memset(x_errs, 0, sizeof(scaltype) * LXSTATIONS * LXLAYERS * LXMAXPOINTSONSTATION); - memset(y_coords, 0, sizeof(scaltype) * LXSTATIONS * LXLAYERS * LXMAXPOINTSONSTATION); - memset(ty_vals, 0, sizeof(scaltype) * (LXSTATIONS - 1) * LXLAYERS * LXMAXPOINTSONSTATION); - memset(y_errs, 0, sizeof(scaltype) * LXSTATIONS * LXLAYERS * LXMAXPOINTSONSTATION); - memset(z_coords, 0, sizeof(scaltype) * LXSTATIONS * LXLAYERS * LXMAXPOINTSONSTATION); - memset(point_refs, 0, sizeof(LxPoint*) * LXSTATIONS * LXLAYERS * LXMAXPOINTSONSTATION); - memset(points_counts, 0, sizeof(int) * LXSTATIONS * LXLAYERS); - - for (int i = 0; i < stationsInAlgo - 2; ++i) - memset(&use_points[i][0], 0, sizeof(use_points[i])); - - for (int i = stationsInAlgo - 2; i < LXSTATIONS - 1; ++i) - memset(&use_points[i][0], 1, sizeof(use_points[LXSTATIONS - 2])); -} - -//#define LXSIMDIZE - -#ifdef LXSIMDIZE - -#include "immintrin.h" - -#define vectype __m256 -#define veclen 8 -#define vec_load_ps _mm256_load_ps -#define vec_store_ps _mm256_store_ps -#define vec_set1_ps _mm256_set1_ps -#define vec_add_ps _mm256_add_ps -#define vec_sub_ps _mm256_sub_ps -#define vec_mul_ps _mm256_mul_ps -#define vec_div_ps _mm256_div_ps -#define vec_cmp_ps _mm256_cmp_ps -#define vec_or_ps _mm256_or_ps -#define vec_sqrt_ps _mm256_sqrt_ps - -void LxSpace::RefineMiddlePoints() -{ - for (int station_number = LXSTATIONS - 1; station_number >= stationsInAlgo - 1; --station_number) { - for (int i = 0; i < points_counts[station_number][1]; ++i) { - scaltype xC = x_coords[station_number][1][i]; - scaltype yC = y_coords[station_number][1][i]; - scaltype zC = z_coords[station_number][1][i]; - scaltype tx = xC / zC; - scaltype ty = yC / zC; - scaltype xErrCSq = x_errs[station_number][1][i] * x_errs[station_number][1][i]; - scaltype yErrCSq = y_errs[station_number][1][i] * y_errs[station_number][1][i]; - bool validC = false; - - for (int j = 0; j < points_counts[station_number][2]; ++j) { - scaltype zR = z_coords[station_number][2][j]; - scaltype deltaZ = zR - zC; - scaltype xR = x_coords[station_number][2][j]; - scaltype xErrRSq = x_errs[station_number][2][j] * x_errs[station_number][2][j]; - scaltype x = xC + tx * deltaZ; - scaltype deltaX = x - xR; - scaltype deltaXSq = deltaX * deltaX; - - if (deltaXSq > 16 * (xErrCSq + xErrRSq) + x_disp_right_limits_sq[station_number]) continue; - - scaltype yR = y_coords[station_number][2][j]; - scaltype yErrRSq = y_errs[station_number][2][j] * y_errs[station_number][2][j]; - scaltype y = yC + ty * deltaZ; - scaltype deltaY = y - yR; - scaltype deltaYSq = deltaY * deltaY; - - if (deltaYSq > 16 * (yErrCSq + yErrRSq) + y_disp_right_limits_sq[station_number]) continue; - - validC = true; - break; - } - - if (validC) continue; - - for (int j = 0; j < points_counts[station_number][0]; ++j) { - scaltype zL = z_coords[station_number][0][j]; - scaltype deltaZ = zL - zC; - scaltype xL = x_coords[station_number][0][j]; - scaltype xErrLSq = x_errs[station_number][0][j] * x_errs[station_number][0][j]; - scaltype x = xC + tx * deltaZ; - scaltype deltaX = x - xL; - scaltype deltaXSq = deltaX * deltaX; - - if (deltaXSq > 16 * (xErrCSq + xErrLSq) + x_disp_left_limits_sq[station_number]) continue; - - scaltype yL = y_coords[station_number][0][j]; - scaltype yErrLSq = y_errs[station_number][0][j] * y_errs[station_number][0][j]; - scaltype y = yC + ty * deltaZ; - scaltype deltaY = y - yL; - scaltype deltaYSq = deltaY * deltaY; - - if (deltaYSq > 16 * (yErrCSq + yErrLSq) + y_disp_left_limits_sq[station_number]) continue; - - validC = true; - break; - } - - if (!validC) { - use_points[station_number - 1][i] = 0; - point_refs[station_number][1][i]->valid = false; - } - } - } -} - -//#include <omp.h> - -void LxSpace::CalcTangents(int station_number) -{ - int l_station_number = station_number - 1; - - if (points_counts[station_number][1] > 200) { - //omp_set_num_threads(4); - //#pragma omp parallel for - for (int i = 0; i < points_counts[station_number][1]; i += veclen) { - if (!*reinterpret_cast<unsigned long long*>(&use_points[l_station_number][i])) continue; - - vectype x = vec_load_ps(&x_coords[station_number][1][i]); - vectype y = vec_load_ps(&y_coords[station_number][1][i]); - vectype z = vec_load_ps(&z_coords[station_number][1][i]); - vectype tx = vec_div_ps(x, z); - vectype ty = vec_div_ps(y, z); - vec_store_ps(&tx_vals[l_station_number][i], tx); - vec_store_ps(&ty_vals[l_station_number][i], ty); - } - } - else { - for (int i = 0; i < points_counts[station_number][1]; i += veclen) { - if (!*reinterpret_cast<unsigned long long*>(&use_points[l_station_number][i])) continue; - - vectype x = vec_load_ps(&x_coords[station_number][1][i]); - vectype y = vec_load_ps(&y_coords[station_number][1][i]); - vectype z = vec_load_ps(&z_coords[station_number][1][i]); - vectype tx = vec_div_ps(x, z); - vectype ty = vec_div_ps(y, z); - vec_store_ps(&tx_vals[l_station_number][i], tx); - vec_store_ps(&ty_vals[l_station_number][i], ty); - } - } -} - -void LxSpace::BuildRaysGlobal() -{ - vectype tx_coeff_sq = vec_set1_ps(errorTxCoeffSq); - vectype ty_coeff_sq = vec_set1_ps(errorTyCoeffSq); - scaltype res_buf[veclen]; - scaltype tx_buf[veclen]; - scaltype ty_buf[veclen]; - scaltype dtx_buf[veclen]; - scaltype dty_buf[veclen]; - int iter; - - //#pragma omp parallel for - for (int i = LXSTATIONS - 1; i > 0; --i) { - vectype tx_limit_sq = vec_set1_ps(tx_limits_sq[i]); - vectype ty_limit_sq = vec_set1_ps(ty_limits_sq[i]); - CalcTangents(i); - int i2 = i - 1; - int i3 = i2 - 1; - - for (int j = 0; j < points_counts[i][1]; ++j) { - if (!use_points[i2][j]) continue; - - vectype r_x = vec_set1_ps(x_coords[i][1][j]); - vectype r_dx = vec_set1_ps(x_errs[i][1][j]); - vectype r_y = vec_set1_ps(y_coords[i][1][j]); - vectype r_dy = vec_set1_ps(y_errs[i][1][j]); - vectype r_z = vec_set1_ps(z_coords[i][1][j]); - vectype tx0 = vec_set1_ps(tx_vals[i2][j]); - vectype ty0 = vec_set1_ps(ty_vals[i2][j]); - - vectype r_dx_sq = vec_mul_ps(r_dx, r_dx); - vectype r_dy_sq = vec_mul_ps(r_dy, r_dy); - - //#pragma omp parallel for - for (int k = 0; k < points_counts[i2][1]; k += veclen) { - vectype l_x = vec_load_ps(&x_coords[i2][1][k]); - vectype l_dx = vec_load_ps(&x_errs[i2][1][k]); - vectype l_y = vec_load_ps(&y_coords[i2][1][k]); - vectype l_dy = vec_load_ps(&y_errs[i2][1][k]); - vectype l_z = vec_load_ps(&z_coords[i2][1][k]); - - vectype delta_x = vec_sub_ps(l_x, r_x); - vectype delta_y = vec_sub_ps(l_y, r_y); - vectype delta_z = vec_sub_ps(l_z, r_z); - vectype delta_z_sq = vec_mul_ps(delta_z, delta_z); - - vectype tx = vec_div_ps(delta_x, delta_z); - vectype ty = vec_div_ps(delta_y, delta_z); - vectype l_dx_sq = vec_mul_ps(l_dx, l_dx); - vectype l_dy_sq = vec_mul_ps(l_dy, l_dy); - - vectype dtx_sq = vec_add_ps(r_dx_sq, l_dx_sq); - dtx_sq = vec_div_ps(dtx_sq, delta_z_sq); - vectype dtx = vec_sqrt_ps(dtx_sq); - dtx_sq = vec_mul_ps(dtx_sq, tx_coeff_sq); - dtx_sq = vec_add_ps(dtx_sq, tx_limit_sq); - vectype dty_sq = vec_add_ps(r_dy_sq, l_dy_sq); - dty_sq = vec_div_ps(dty_sq, delta_z_sq); - vectype dty = vec_sqrt_ps(dty_sq); - dty_sq = vec_mul_ps(dty_sq, ty_coeff_sq); - dty_sq = vec_add_ps(dtx_sq, ty_limit_sq); - - vectype diff_tx = vec_sub_ps(tx, tx0); - vectype diff_ty = vec_sub_ps(ty, ty0); - vectype diff_tx_sq = vec_mul_ps(diff_tx, diff_tx); - vectype diff_ty_sq = vec_mul_ps(diff_ty, diff_ty); - - vectype res_tx = vec_cmp_ps(diff_tx_sq, dtx_sq, _CMP_GT_OS); - vectype res_ty = vec_cmp_ps(diff_ty_sq, dty_sq, _CMP_GT_OS); - vectype res = vec_or_ps(res_tx, res_ty); - vec_store_ps(res_buf, res); - vec_store_ps(tx_buf, tx); - vec_store_ps(ty_buf, ty); - vec_store_ps(dtx_buf, dtx); - vec_store_ps(dty_buf, dty); - iter = k; - - for (int l = 0; l < veclen; ++l) { - if (res_buf[l]) { - ++iter; - continue; - } - - if (iter >= points_counts[i2][1]) break; - - point_refs[i][1][j]->CreateRay(point_refs[i2][1][iter], tx_buf[l], ty_buf[l], dtx_buf[l], dty_buf[l]); - - if (i3 > -1) use_points[i3][iter] = true; - - ++iter; - } - } - } - } -} - -#else //LXSIMDIZE - -#define _mm_malloc(X, Y) malloc((X)) -#define _mm_free free - -scaltype x_coords[LXSTATIONS][LXLAYERS][LXMAXPOINTSONSTATION]; -scaltype tx_vals[LXSTATIONS - 1][LXMAXPOINTSONSTATION]; -scaltype x_errs[LXSTATIONS][LXLAYERS][LXMAXPOINTSONSTATION]; -scaltype y_coords[LXSTATIONS][LXLAYERS][LXMAXPOINTSONSTATION]; -scaltype ty_vals[LXSTATIONS][LXMAXPOINTSONSTATION]; -scaltype y_errs[LXSTATIONS][LXLAYERS][LXMAXPOINTSONSTATION]; -scaltype z_coords[LXSTATIONS][LXLAYERS][LXMAXPOINTSONSTATION]; -LxPoint* point_refs[LXSTATIONS][LXLAYERS][LXMAXPOINTSONSTATION]; -bool use_points[LXSTATIONS - 1][LXMAXPOINTSONSTATION]; -int points_counts[LXSTATIONS][LXLAYERS]; - -static void CalcTangents(int station_number) -{ - int l_station_number = station_number - 1; - - for (int i = 0; i < points_counts[station_number][1]; ++i) { - if (!use_points[l_station_number][i]) continue; - - tx_vals[l_station_number][i] = x_coords[station_number][1][i] / z_coords[station_number][1][i]; - ty_vals[l_station_number][i] = y_coords[station_number][1][i] / z_coords[station_number][1][i]; - } -} - -void BuildRaysGlobal() -{ - for (int i = LXSTATIONS - 1; i > 0; --i) { - scaltype tx_limit_sq = tx_limits[i] * tx_limits[i]; - scaltype ty_limit_sq = ty_limits[i] * ty_limits[i]; - CalcTangents(i); - int i2 = i - 1; - int i3 = i2 - 1; - - for (int j = 0; j < points_counts[i][1]; ++j) { - if (!use_points[i2][j]) continue; - - scaltype r_x = x_coords[i][1][j]; - scaltype r_y = y_coords[i][1][j]; - scaltype r_z = z_coords[i][1][j]; - scaltype r_dx_sq = x_errs[i][1][j] * x_errs[i][1][j]; - scaltype r_dy_sq = y_errs[i][1][j] * y_errs[i][1][j]; - - for (int k = 0; k < points_counts[i2][1]; ++k) { - scaltype delta_x = x_coords[i2][1][k] - r_x; - scaltype delta_y = y_coords[i2][1][k] - r_y; - scaltype delta_z = z_coords[i2][1][k] - r_z; - scaltype delta_z_sq = delta_z * delta_z; - - scaltype tx = delta_x / delta_z; - scaltype ty = delta_y / delta_z; - scaltype l_dx_sq = x_errs[i2][1][k] * x_errs[i2][1][k]; - scaltype l_dy_sq = y_errs[i2][1][k] * y_errs[i2][1][k]; - - scaltype dtx_sq = (r_dx_sq + l_dx_sq) / delta_z_sq; - scaltype dtx = sqrt(dtx_sq); - dtx_sq *= errorTxCoeffSq; - dtx_sq += tx_limit_sq; - scaltype dty_sq = (r_dy_sq + l_dy_sq) / delta_z_sq; - scaltype dty = sqrt(dty_sq); - dty_sq *= errorTyCoeffSq; - dty_sq += ty_limit_sq; - - scaltype diff_tx = tx - tx_vals[i2][j]; - scaltype diff_ty = ty - ty_vals[i2][j]; - scaltype diff_tx_sq = diff_tx * diff_tx; - scaltype diff_ty_sq = diff_ty * diff_ty; - - if ((diff_tx_sq > dtx_sq) || (diff_ty_sq > dty_sq)) continue; - - point_refs[i][1][j]->CreateRay(point_refs[i2][1][k], tx, ty, dtx, dty); - - if (i3 > -1) use_points[i3][k] = true; - } - } - } -} - -#endif //LXSIMDIZE - -/////////////////////////////////////////////////////////////////////////////////////////////////// -// Global declarations -/////////////////////////////////////////////////////////////////////////////////////////////////// - -#ifdef CLUSTER_MODE -static scaltype squareRoot2 = sqrt(2.0); -static scaltype errorXcoeff = 4.0; -static scaltype errorYcoeff = 4.0; -static scaltype errorTxCoeff = 4.0; -static scaltype errorTyCoeff = 4.0; -#else //CLUSTER_MODE -static scaltype errorXcoeff = 4.0; -static scaltype errorYcoeff = 4.0; -#endif //CLUSTER_MODE - -static scaltype errorTxBreakCoeff = 4.0; -static scaltype errorTyBreakCoeff = 4.0; - -// These ..Ext.. coefficients are applied to squares of uncertainties. So they can be bigger than the previous. -//static scaltype errorExtXcoeff = 16; -//static scaltype errorExtYcoeff = 16; -//static scaltype errorExtTxCoeff = 16; -//static scaltype errorExtTyCoeff = 16; - -//static LxFinder* finderInstance = 0; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// LxTrackCandidate -////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -struct LxTrackCandidate { - LxRay* rays[LXSTATIONS - 1]; // Rays are stored left to right. - Int_t length; - scaltype chi2; - - LxTrackCandidate(LxRay** rr, Int_t len, scaltype c2) : length(len), chi2(c2) - { - for (int i = 0; i < len; ++i) - rays[i] = rr[i]; - - for (int i = len; i < LXSTATIONS - 1; ++i) - rays[i] = 0; - } -}; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// LxTrack -////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -#ifdef CLUSTER_MODE -LxTrack::LxTrack(LxTrackCandidate* tc) - : matched(false) - , length(tc->length) - , chi2(tc->chi2) - , mcTrack(0) - , aX(0) - , bX(0) - , aY(0) - , bY(0) - , restoredPoints(0) - , externalTrack(0) -#ifdef USE_KALMAN_FIT - , x(0) - , y(0) - , z(0) - , dx(0) - , dy(0) - , tx(0) - , ty(0) - , dtx(0) - , dty(0) -#endif //USE_KALMAN_FIT -{ - memset(rays, 0, sizeof(rays)); - memset(points, 0, sizeof(points)); - - for (Int_t i = 0; i < length; ++i) { - LxRay* ray = tc->rays[i]; - rays[i] = ray; - LxPoint* point = ray->source; - point->used = true; - point->track = this; - - for (list<LxPoint*>::iterator j = ray->clusterPoints.begin(); j != ray->clusterPoints.end(); ++j) { - LxPoint* p = *j; - p->track = this; - } - } - - LxRay* ray = tc->rays[0]; - LxPoint* point = ray->end; - point->used = true; - point->track = this; -} -#else //CLUSTER_MODE -LxTrack::LxTrack(LxTrackCandidate* tc) - : externalTrack(NULL) -#ifdef LX_EXT_LINK_SOPH - , extTrackCandidates() -#else //LX_EXT_LINK_SOPH - , extLinkChi2() -#endif - , matched(false) - , mcTrack(NULL) -#ifdef CALC_LINK_WITH_STS_EFF - , mcTracks() -#endif //CALC_LINK_WITH_STS_EFF - , length(tc->length) - , rays() - , points() - , chi2(tc->chi2) - , aX(0) - , bX(0) - , aY(0) - , bY(0) - , restoredPoints(0) -#ifdef USE_KALMAN_FIT - , x(0) - , y(0) - , z(0) - , dx(0) - , dy(0) - , tx(0) - , ty(0) - , dtx(0) - , dty(0) -#endif //USE_KALMAN_FIT - , clone(false) - , distanceOk(false) - , oppCharged(false) - , triggering(false) -{ - memset(rays, 0, sizeof(rays)); - memset(points, 0, sizeof(points)); - - for (int i = 0; i < length; ++i) { - LxRay* ray = tc->rays[i]; - rays[i] = ray; - LxPoint* point = ray->source; - point->used = true; - point->track = this; - points[(i + 1) * LXLAYERS + LXMIDDLE] = point; - - if (point->artificial) ++restoredPoints; - - LxStation* station = ray->station; - - for (int j = 0; j < LXLAYERS; ++j) { - if (LXMIDDLE == j) continue; - - LxLayer* layer = station->layers[j]; - LxPoint* p = layer->PickNearestPoint(ray); - - if (0 != p && !p->used) { - p->used = true; - p->track = this; - points[(i + 1) * LXLAYERS + j] = p; - } - } - } - - LxRay* ray = tc->rays[0]; - LxPoint* point = ray->end; - point->used = true; - point->track = this; - points[LXMIDDLE] = point; - - if (point->artificial) ++restoredPoints; - - LxStation* station = ray->station->space->stations[0]; - - for (int i = 0; i < LXLAYERS; ++i) { - if (LXMIDDLE == i) continue; - - LxLayer* layer = station->layers[i]; - scaltype diffZ = layer->zCoord - ray->end->z; - scaltype x = ray->end->x + ray->tx * diffZ; - scaltype y = ray->end->y + ray->ty * diffZ; - LxPoint* p = layer->PickNearestPoint(x, y); - - if (0 != p && !p->used) { - p->used = true; - p->track = this; - points[i] = p; - } - } - - //cout << "This track contains: " << restoredPoints << " restored points" << endl; -} -#endif //CLUSTER_MODE - -static inline void Ask() -{ - char symbol; - - cout << "ask>"; - - do { - cin.get(symbol); - } while (symbol != '\n'); - - cout << endl; -} - -#ifdef USE_KALMAN_FIT -struct KFParams { - scaltype coord, tg, C11, C12, C21, C22; -}; - -void LxTrack::Fit() -{ - LxRay* firstRay = rays[LXSTATIONS - LXFIRSTSTATION - 2]; - LxPoint* firstPoint = firstRay->source; - KFParams params[2] = {{firstPoint->x, firstRay->tx, firstPoint->dx, 0, 0, 1.0}, - {firstPoint->y, firstRay->ty, firstPoint->dy, 0, 0, 1.0}}; - - LxPoint* prevPoint = firstPoint; - scaltype aChi2 = 0; - - for (Int_t i = LXSTATIONS - LXFIRSTSTATION - 2; i >= 0; --i) { - LxRay* ray = rays[i]; - LxPoint* point = ray->end; - LxStation* station = point->layer->station; - scaltype m[2] = {point->x, point->y}; - scaltype V[2] = {point->dx * point->dx, point->dy * point->dy}; - KFParams pPrev[2] = {params[0], params[1]}; - scaltype deltaZ = point->z - prevPoint->z; - scaltype deltaZ2 = deltaZ * deltaZ; - - for (Int_t k = 0; k <= 1; ++k) { - // Extrapolate. - params[k].coord += pPrev[k].tg * deltaZ; // params[k].tg is unchanged. - - // Filter. - params[k].C11 += - pPrev[k].C12 * deltaZ + pPrev[k].C21 * deltaZ + pPrev[k].C22 * deltaZ2 + station->MSNoise[k][0][0]; - params[k].C12 += pPrev[k].C22 * deltaZ + station->MSNoise[k][0][1]; - params[k].C21 += pPrev[k].C22 * deltaZ + station->MSNoise[k][1][0]; - params[k].C22 += station->MSNoise[k][1][1]; - - scaltype S = 1.0 / (V[k] + params[k].C11); - scaltype Kcoord = params[k].C11 * S; - scaltype Ktg = params[k].C21 * S; - scaltype dzeta = m[k] - params[k].coord; - params[k].coord += Kcoord * dzeta; - params[k].tg += Ktg * dzeta; - params[k].C21 -= params[k].C11 * Ktg; - params[k].C22 -= params[k].C12 * Ktg; - params[k].C11 *= 1.0 - Kcoord; - params[k].C12 *= 1.0 - Kcoord; - aChi2 += dzeta * S * dzeta; - } - - prevPoint = point; - } - - x = params[0].coord; - dx = sqrt(params[0].C11); - tx = params[0].tg; - dtx = sqrt(params[0].C22); - y = params[1].coord; - dy = sqrt(params[1].C11); - ty = params[1].tg; - dty = sqrt(params[1].C22); - z = rays[0]->end->z; -} -#else //USE_KALMAN_FIT -void LxTrack::Fit() -{ - scaltype sumZ = 0; - scaltype sumZ2 = 0; - scaltype sumX = 0; - scaltype sumZX = 0; - scaltype sumY = 0; - scaltype sumZY = 0; - - for (int i = 0; i < LXSTATIONS - LXFIRSTSTATION; ++i) { - LxPoint* point = points[LXLAYERS * i + LXMIDDLE]; - scaltype z = point->z; - scaltype x = point->x; - scaltype y = point->y; - - sumZ += z; - sumZ2 += z * z; - sumX += x; - sumZX += z * x; - sumY += y; - sumZY += z * y; - } - - aX = (LXSTATIONS * sumZX - sumZ * sumX) / (LXSTATIONS * sumZ2 - sumZ * sumZ); - bX = (sumX - aX * sumZ) / LXSTATIONS; - aY = (LXSTATIONS * sumZY - sumZ * sumY) / (LXSTATIONS * sumZ2 - sumZ * sumZ); - bY = (sumY - aY * sumZ) / LXSTATIONS; - - //LxPoint* point = points[LXLAYERS * (LXSTATIONS - 1) + LXMIDDLE]; - //cout << "bX = " << bX << " , aX = " << aX << " , X / Z = " << point->x / point->z << endl; - //cout << "bY = " << bY << " , aY = " << aY << " , Y / Z = " << point->y / point->z << endl; - //Ask(); -} -#endif //USE_KALMAN_FIT - -#ifdef LX_EXT_LINK_SOPH -void LxTrack::Rebind() -{ - externalTrack = 0; - - for (list<pair<LxExtTrack*, scaltype>>::iterator i = extTrackCandidates.begin(); i != extTrackCandidates.end(); ++i) { - LxExtTrack* extTrack = i->first; - scaltype aChi2 = i->second; - - if (0 == extTrack->recoTrack.first) { - extTrack->recoTrack.first = this; - extTrack->recoTrack.second = aChi2; - externalTrack = extTrack; - break; - } - else if (aChi2 < extTrack->recoTrack.second) { - LxTrack* anotherTrack = extTrack->recoTrack.first; - extTrack->recoTrack.first = this; - extTrack->recoTrack.second = aChi2; - externalTrack = extTrack; - anotherTrack->Rebind(); - break; - } - } -} -#endif // LX_EXT_LINK_SOPH - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// LxPoint -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -LxPoint::~LxPoint() -{ - for (list<LxRay*>::iterator i = rays.begin(); i != rays.end(); ++i) - delete *i; -} - -void LxPoint::CreateRay(LxPoint* lPoint, scaltype tx, scaltype ty, scaltype dtx, scaltype dty) -{ - rays.push_back(new LxRay(this, lPoint, tx, ty, dtx, dty -#ifdef CLUSTER_MODE - , - 4 -#endif //CLUSTER_MODE - )); -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// LxRay -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -LxRay::LxRay(LxPoint* s, LxPoint* e -#ifdef CLUSTER_MODE - , - Int_t l -#endif //CLUSTER_MODE - ) - : tx((e->x - s->x) / (e->z - s->z)) - , ty((e->y - s->y) / (e->z - s->z)) - , dtx(sqrt(e->dx * e->dx + s->dx * s->dx) / (s->z - e->z)) - , dty(sqrt(e->dy * e->dy + s->dy * s->dy) / (s->z - e->z)) - , source(s) - , end(e) - , station(s->layer->station) - , neighbours() -#ifdef CLUSTER_MODE - , level(l) - , used(false) - , neighbourhood() - , clusterPoints() -#endif //CLUSTER_MODE -#ifdef USE_KALMAN - , kalman() -#endif -{ -} - -LxRay::LxRay(LxPoint* s, LxPoint* e, scaltype Tx, scaltype Ty, scaltype Dtx, scaltype Dty -#ifdef CLUSTER_MODE - , - Int_t l -#endif //CLUSTER_MODE - ) - : tx(Tx) - , ty(Ty) - , dtx(Dtx) - , dty(Dty) - , source(s) - , end(e) - , station(s->layer->station) - , neighbours() -#ifdef CLUSTER_MODE - , level(l) - , used(false) - , neighbourhood() - , clusterPoints() -#endif //CLUSTER_MODE -#ifdef USE_KALMAN - , kalman() -#endif - -{ -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// LxLayer -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -LxLayer::LxLayer(LxStation* st, int lNum) : station(st), layerNumber(lNum), zCoord(0) {} - -LxLayer::~LxLayer() { Clear(); } - -void LxLayer::Clear() -{ - for (list<LxPoint*>::iterator i = points.begin(); i != points.end(); ++i) - delete *i; - - points.clear(); -} - -LxPoint* LxLayer::PickNearestPoint(scaltype x, scaltype y) -{ - LxPoint* result = 0; - scaltype minR2 = 0; - - for (list<LxPoint*>::iterator i = points.begin(); i != points.end(); ++i) { - LxPoint* point = *i; - - if (point->used) continue; - - scaltype diffX = point->x - x; - scaltype diffY = point->y - y; - - if (diffX < 0) diffX = -diffX; - - if (diffX > errorXcoeff * point->dx) continue; - - if (diffY < 0) diffY = -diffY; - - if (diffY > errorYcoeff * point->dy) continue; - - scaltype r2 = diffX * diffX + diffY * diffY; - - if (0 == result || r2 < minR2) { - result = point; - minR2 = r2; - } - } - - return result; -} - -LxPoint* LxLayer::PickNearestPoint(LxRay* ray) -{ - LxPoint* point = ray->source; - scaltype diffZ = zCoord - point->z; - scaltype x = point->x + ray->tx * diffZ; - scaltype y = point->y + ray->ty * diffZ; - return PickNearestPoint(x, y); -} - -LxPoint* LxLayer::PickNearestPoint(scaltype x, scaltype y, scaltype deltaX, scaltype deltaY) -{ - LxPoint* result = 0; - scaltype minR2 = 0; - scaltype xLBound = x - deltaX; - scaltype xUBound = x + deltaX; - scaltype yLBound = y - deltaY; - scaltype yUBound = y + deltaY; - - for (list<LxPoint*>::iterator i = points.begin(); i != points.end(); ++i) { - LxPoint* point = *i; - - if (point->x < xLBound || point->x > xUBound || point->y < yLBound || point->y > yUBound) continue; - - scaltype diffX = point->x - x; - scaltype diffY = point->y - y; - scaltype r2 = diffX * diffX + diffY * diffY; - - if (0 == result || r2 < minR2) { - result = point; - minR2 = r2; - } - } - - return result; -} - -bool LxLayer::HasPointInRange(scaltype x, scaltype y, scaltype deltaX, scaltype deltaY) -{ - scaltype xLBound = x - deltaX; - scaltype xUBound = x + deltaX; - scaltype yLBound = y - deltaY; - scaltype yUBound = y + deltaY; - - for (list<LxPoint*>::iterator i = points.begin(); i != points.end(); ++i) { - LxPoint* point = *i; - - if (xLBound < point->x && point->x < xUBound && yLBound < point->y && point->y < yUBound) return true; - } - - return false; -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// LxStation -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -// These arrays are filled with data obtained during Monte Carlo simulations. -//static scaltype txLimits[] = { 0., 0.13, 0.11, 0.11, 0.125, 0.17 }; -//static scaltype tyLimits[] = { 0., 0.125, 0.07, 0.07, 0.1, 0.21 }; - -//static scaltype txBreakLimits[] = { 0., 0.085, 0.09, 0.13, 0.21, 0. }; -//static scaltype tyBreakLimits[] = { 0., 0.07, 0.085, 0.11, 0.23, 0. }; - -//static scaltype txBreakSigmas[] = { 0., 0.01242, 0.0115, 0.0134, 0.02955, 0. }; -//static scaltype tyBreakSigmas[] = { 0., 0.01473, 0.01174, 0.0136, 0.02827, 0. }; - -static scaltype dispersions01XSmall[] = {0.6, 1.0, 0.8, 0.8, 1.2, 1.2}; -static scaltype dispersions01XBig[] = {1.9, 1.8, 1.6, 1.6, 1.9, 2.9}; -static scaltype dispersions01YSmall[] = {0.4, 0.5, 0.7, 0.7, 1.0, 1.0}; -static scaltype dispersions01YBig[] = {1.2, 1.3, 1.3, 1.3, 1.6, 2.9}; - -static scaltype dispersions02XSmall[] = {0.7, 1.2, 1.2, 1.2, 1.1, 1.4}; -static scaltype dispersions02XBig[] = {2.0, 1.9, 1.6, 1.7, 1.8, 2.3}; -static scaltype dispersions02YSmall[] = {0.2, 0.6, 1.0, 0.9, 0.9, 1.4}; -static scaltype dispersions02YBig[] = {1.5, 1.3, 1.3, 1.4, 1.7, 2.2}; - -#ifdef CLUSTER_MODE -struct KDRayWrap { - LxRay* ray; - scaltype data[4]; - static bool destroyRays; - - KDRayWrap(scaltype x, scaltype y, LxRay* r) : ray(r) - { - data[0] = x; - data[1] = y; - data[2] = ray->tx; - data[3] = ray->ty; - } - - KDRayWrap(scaltype x, scaltype y, scaltype tx, scaltype ty) - : ray(0) // This constructor is used when setting search-range bounds. - { - data[0] = x; - data[1] = y; - data[2] = tx; - data[3] = ty; - } - - ~KDRayWrap() - { - //if (destroyRays) - //delete ray; - } - - // Stuff required by libkdtree++ - typedef scaltype value_type; - - value_type operator[](size_t n) const { return data[n]; } -}; - -bool KDRayWrap::destroyRays = false; - -typedef KDTree::KDTree<4, KDRayWrap> KDRaysStorageType; -#endif //CLUSTER_MODE - -LxStation::LxStation(LxSpace* sp, int stNum) - : space(sp) - , stationNumber(stNum) - , zCoord(0) - , txLimit(0) - , tyLimit(0) - , txBreakLimit(0) - , tyBreakLimit(0) - , txBreakSigma(0) - , tyBreakSigma(0) - , disp01XSmall(dispersions01XSmall[stNum]) - , disp01XBig(dispersions01XBig[stNum]) - , disp01YSmall(dispersions01YSmall[stNum]) - , disp01YBig(dispersions01YBig[stNum]) - , disp02XSmall(dispersions02XSmall[stNum]) - , disp02XBig(dispersions02XBig[stNum]) - , disp02YSmall(dispersions02YSmall[stNum]) - , disp02YBig(dispersions02YBig[stNum]) -#ifdef CLUSTER_MODE - , raysHandle(0) - , clusteredRaysHandle(0) - , clusterXLimit(0) - , clusterXLimit2(0) - , clusterYLimit(0) - , clusterYLimit2(0) - , clusterTxLimit(0) - , clusterTxLimit2(0) - , clusterTyLimit(0) - , clusterTyLimit2(0) -#endif //CLUSTER_MODE -{ - for (int i = 0; i < LXLAYERS; ++i) - layers.push_back(new LxLayer(this, i)); - -#ifdef CLUSTER_MODE - raysHandle = new KDRaysStorageType; - clusteredRaysHandle = new KDRaysStorageType; -#endif //CLUSTER_MODE -} - -LxStation::~LxStation() -{ - Clear(); -#ifdef CLUSTER_MODE - KDRaysStorageType* rays = static_cast<KDRaysStorageType*>(raysHandle); - delete rays; - KDRaysStorageType* clusteredRays = static_cast<KDRaysStorageType*>(clusteredRaysHandle); - delete clusteredRays; -#endif //CLUSTER_MODE -} - -void LxStation::Clear() -{ - for (vector<LxLayer*>::iterator i = layers.begin(); i != layers.end(); ++i) - (*i)->Clear(); - -#ifdef CLUSTER_MODE - KDRaysStorageType* rays = static_cast<KDRaysStorageType*>(raysHandle); - KDRayWrap::destroyRays = true; - rays->clear(); - KDRaysStorageType* clusteredRays = static_cast<KDRaysStorageType*>(clusteredRaysHandle); - clusteredRays->clear(); - KDRayWrap::destroyRays = false; - - for (list<LxPoint*>::iterator i = clusteredPoints.begin(); i != clusteredPoints.end(); ++i) - delete *i; - - clusteredPoints.clear(); - - for (Int_t i = 0; i < 2 * LXLAYERS; ++i) { - for (vector<list<LxRay*>*>::iterator j = clusters[i].begin(); j != clusters[i].end(); ++j) - delete *j; - - clusters[i].clear(); - } -#endif //CLUSTER_MODE -} - -void LxStation::RestoreMiddlePoints() -{ - LxLayer* lLayer = layers[0]; - LxLayer* mLayer = layers[LXMIDDLE]; - LxLayer* rLayer = layers[2]; - list<LxPoint*>& mPoints = mLayer->points; - list<LxPoint*>& rPoints = rLayer->points; - - // 1. Loop through the points of the middle layer and check if they have at least on corresponding point on either left or right layer. - for (list<LxPoint*>::iterator i = mPoints.begin(); i != mPoints.end(); ++i) { - LxPoint* point = *i; - scaltype tx = point->x / point->z; - scaltype ty = point->y / point->z; - scaltype diffZ = lLayer->zCoord - point->z; - scaltype x = point->x + tx * diffZ; - scaltype y = point->y + ty * diffZ; - - if (!lLayer->HasPointInRange(x, y, disp01XBig, disp01YBig)) { - diffZ = rLayer->zCoord - point->z; - x = point->x + tx * diffZ; - y = point->y + tx * diffZ; - - if (!rLayer->HasPointInRange(x, y, disp01XBig, disp01YBig)) point->valid = false; - } - } - - // 2. Loop through the points of the right station. If there are corresponding points in the middle station -- it is OK. - // If there are no -- check corresponding points on the left station. If such points exist, choose the point nearest - // to the predicted value among them and reconstruct a middle point as a point of intersection of the segment between - // the left and corresponding right points and the middle layer. - for (list<LxPoint*>::iterator i = rPoints.begin(); i != rPoints.end(); ++i) { - LxPoint* rPoint = *i; - scaltype tx = rPoint->x / rPoint->z; - scaltype ty = rPoint->y / rPoint->z; - scaltype diffZ = mLayer->zCoord - rPoint->z; - scaltype x = rPoint->x + tx * diffZ; - scaltype y = rPoint->y + ty * diffZ; - - if (mLayer->HasPointInRange(x, y, disp01XBig, disp01YBig)) continue; - - diffZ = lLayer->zCoord - rPoint->z; - x = rPoint->x + tx * diffZ; - y = rPoint->y + ty * diffZ; - - LxPoint* lPoint = lLayer->PickNearestPoint(x, y, disp02XSmall, disp02YSmall); - - if (0 == lPoint) continue; - - x = (lPoint->x + rPoint->x) / 2; - y = (lPoint->y + rPoint->y) / 2; - mLayer->AddPoint(-1, x, y, mLayer->zCoord, rPoint->dx, rPoint->dy, rPoint->dz, true); - } -} - -void LxStation::BuildRays() -{ - if (stationNumber < LXFIRSTSTATION + 1) return; - - LxLayer* rLayer = layers[LXMIDDLE]; - LxStation* lStation = space->stations[stationNumber - 1]; // Pointer to 'left' station. 'This' station is 'right'. - LxLayer* lLayer = lStation->layers[LXMIDDLE]; - - for (list<LxPoint*>::iterator rIter = rLayer->points.begin(); rIter != rLayer->points.end(); ++rIter) { - LxPoint* rPoint = *rIter; - - if (!rPoint->valid) continue; - - scaltype tx1 = rPoint->x / rPoint->z; - scaltype ty1 = rPoint->y / rPoint->z; - - for (list<LxPoint*>::iterator lIter = lLayer->points.begin(); lIter != lLayer->points.end(); ++lIter) { - LxPoint* lPoint = *lIter; - - if (!lPoint->valid) continue; - - scaltype diffZ = lPoint->z - rPoint->z; - scaltype tx = (lPoint->x - rPoint->x) / diffZ; - scaltype ty = (lPoint->y - rPoint->y) / diffZ; - scaltype dtx = -sqrt(lPoint->dx * lPoint->dx + rPoint->dx * rPoint->dx) / diffZ; - scaltype dty = -sqrt(lPoint->dy * lPoint->dy + rPoint->dy * rPoint->dy) / diffZ; - scaltype diffTx = tx - tx1; - scaltype diffTy = ty - ty1; - - if (diffTx < 0) diffTx = -diffTx; - - if (diffTy < 0) diffTy = -diffTy; - - if (diffTx > txLimit + dtx * errorTxCoeff || diffTy > tyLimit + dty * errorTyCoeff) continue; - - rPoint->CreateRay(lPoint, tx, ty, dtx, dty); - } - } -} - -#ifdef CLUSTER_MODE -static void AddRayData(LxRay* ray, scaltype& lX, scaltype& lY, scaltype& lDx2, scaltype& lDy2, scaltype& rX, - scaltype& rY, scaltype& rDx2, scaltype& rDy2) -{ - LxPoint* lPoint = ray->end; - scaltype deltaZ = lPoint->layer->station->zCoord - lPoint->z; - lX += lPoint->x + ray->tx * deltaZ; - lY += lPoint->y + ray->ty * deltaZ; - lDx2 += lPoint->dx * lPoint->dx; - lDy2 += lPoint->dy * lPoint->dy; - - LxPoint* rPoint = ray->source; - deltaZ = rPoint->layer->station->zCoord - rPoint->z; - rX += rPoint->x + ray->tx * deltaZ; - rY += rPoint->y + ray->ty * deltaZ; - rDx2 += rPoint->dx * rPoint->dx; - rDy2 += rPoint->dy * rPoint->dy; -} - -void LxStation::InsertClusterRay(Int_t levels, Int_t cardinality, LxRay* clusterRay) -{ - if (levels < (LXLAYERS - 1) * (LXLAYERS - 1)) return; - - levels -= (LXLAYERS - 1) * (LXLAYERS - 1); - - while (clusters[levels].size() < cardinality) - clusters[levels].push_back(new list<LxRay*>); - - clusters[levels][cardinality - 1]->push_back(clusterRay); -} - -#ifdef BEST_SIX_POINTS -struct LxLess { - bool operator()(pair<LxPoint*, LxPoint*> lVal, pair<LxPoint*, LxPoint*> rVal) const - { - if (lVal.first < rVal.first) return true; - - return lVal.second < rVal.second; - } -}; - -struct LxRaysCandidates { - LxRay* data[LXLAYERS * LXLAYERS]; - scaltype chi2; - - LxRaysCandidates() : chi2(-1.0) { memset(data, 0, sizeof(data)); } -}; -#endif //BEST_SIX_POINTS - -void LxStation::BuildRays2() -{ - if (stationNumber < LXFIRSTSTATION + 1) return; - - KDRaysStorageType* rays = static_cast<KDRaysStorageType*>(raysHandle); - LxStation* lStation = space->stations[stationNumber - 1]; // Pointer to 'left' station. 'This' station is 'right'. - - for (Int_t i = 0; i < LXLAYERS; ++i) { - LxLayer* rLayer = layers[i]; - - for (Int_t j = 0; j < LXLAYERS; ++j) { - LxLayer* lLayer = lStation->layers[j]; - - for (list<LxPoint*>::iterator rIter = rLayer->points.begin(); rIter != rLayer->points.end(); ++rIter) { - LxPoint* rPoint = *rIter; - scaltype tx1 = rPoint->x / rPoint->z; - scaltype ty1 = rPoint->y / rPoint->z; - scaltype zShift = zCoord - rPoint->z; - - for (list<LxPoint*>::iterator lIter = lLayer->points.begin(); lIter != lLayer->points.end(); ++lIter) { - LxPoint* lPoint = *lIter; - scaltype diffZ = lPoint->z - rPoint->z; - scaltype tx = (lPoint->x - rPoint->x) / diffZ; - scaltype ty = (lPoint->y - rPoint->y) / diffZ; - scaltype dtx = -sqrt(lPoint->dx * lPoint->dx + rPoint->dx * rPoint->dx) / diffZ; - scaltype dty = -sqrt(lPoint->dy * lPoint->dy + rPoint->dy * rPoint->dy) / diffZ; - scaltype diffTx = abs(tx - tx1); - scaltype diffTy = abs(ty - ty1); - - if (diffTx > txLimit + dtx * errorTxCoeff || diffTy > tyLimit + dty * errorTyCoeff) continue; - - scaltype x = rPoint->x + tx * zShift; - scaltype y = rPoint->y + ty * zShift; - LxRay* ray = new LxRay(rPoint, lPoint, LXLAYERS * i + j); - KDRayWrap rayWrap(x, y, ray); - rays->insert(rayWrap); - rPoint->rays.push_back(ray); - } - } - } - } - - timeval bTime, eTime; - Int_t exeDuration; - static Int_t maxExeDuration = 0; - static Int_t goodClusters = 0; - gettimeofday(&bTime, 0); - - for (KDRaysStorageType::iterator i = rays->begin(); i != rays->end(); ++i) { - KDRayWrap& wrap = const_cast<KDRayWrap&>(*i); - LxRay* ray = wrap.ray; - KDTree::_Region<4, KDRayWrap, scaltype, KDTree::_Bracket_accessor<KDRayWrap>, - std::less<KDTree::_Bracket_accessor<KDRayWrap>::result_type>> - range(wrap); - scaltype limitX = errorXcoeff * sqrt(clusterXLimit2 + 2.0 * ray->source->dx * ray->source->dx); - scaltype limitY = errorYcoeff * sqrt(clusterYLimit2 + 2.0 * ray->source->dy * ray->source->dy); - scaltype limitTx = errorTxCoeff * sqrt(clusterTxLimit2 + 2.0 * ray->dtx * ray->dtx); - scaltype limitTy = errorTyCoeff * sqrt(clusterTyLimit2 + 2.0 * ray->dty * ray->dty); - KDRayWrap boundsWrap(wrap.data[0] - limitX, wrap.data[1] - limitY, wrap.data[2] - limitTx, wrap.data[3] - limitTy); - range.set_low_bound(boundsWrap, 0); - range.set_low_bound(boundsWrap, 1); - range.set_low_bound(boundsWrap, 2); - range.set_low_bound(boundsWrap, 3); - boundsWrap.data[0] = wrap.data[0] + limitX; - boundsWrap.data[1] = wrap.data[1] + limitY; - boundsWrap.data[2] = wrap.data[2] + limitTx; - boundsWrap.data[3] = wrap.data[3] + limitTy; - range.set_high_bound(boundsWrap, 0); - range.set_high_bound(boundsWrap, 1); - range.set_high_bound(boundsWrap, 2); - range.set_high_bound(boundsWrap, 3); - list<KDRayWrap> neighbours; - rays->find_within_range(range, back_insert_iterator<list<KDRayWrap>>(neighbours)); - Int_t level_occupancy[LXLAYERS * LXLAYERS] = {}; - - for (list<KDRayWrap>::iterator j = neighbours.begin(); j != neighbours.end(); ++j) { - KDRayWrap& w = *j; - LxRay* r = w.ray; - level_occupancy[r->level] = 1; - - if (ray != r) ray->neighbourhood.push_back(r); - } - - Int_t levels = 0; - - for (Int_t j = 0; j < LXLAYERS * LXLAYERS; ++j) - levels += level_occupancy[j]; - - InsertClusterRay(levels, ray->neighbourhood.size() + 1, ray); - } // for (KDRaysStorageType::iterator i = rays->begin(); i != rays->end(); ++i) - - KDRaysStorageType* clusteredRays = static_cast<KDRaysStorageType*>(clusteredRaysHandle); - - for (Int_t i = 2 * LXLAYERS - 1; i >= 0; --i) { -#ifdef DENSE_CLUSTERS_FIRST - for (Int_t j = clusters[i].size() - 1; j >= 0; --j) -#else //DENSE_CLUSTERS_FIRST - for (Int_t j = 0; j < clusters[i].size(); ++j) -#endif //DENSE_CLUSTERS_FIRST - { - list<LxRay*>* clusterRays = clusters[i][j]; - - for (list<LxRay*>::iterator k = clusterRays->begin(); k != clusterRays->end(); ++k) { - LxRay* ray = *k; - - if (0 == ray) continue; - -#ifdef BEST_SIX_POINTS - if (ray->source->used || ray->end->used) - //if (ray->used) - continue; -#else //BEST_SIX_POINTS - if (ray->used) continue; -#endif //BEST_SIX_POINTS - - Int_t levels = 0; - Int_t level_occupancy[LXLAYERS * LXLAYERS] = {}; - scaltype lX = 0; - scaltype lY = 0; - scaltype lDx2 = 0; - scaltype lDy2 = 0; - scaltype lZ = ray->end->layer->station->zCoord; - scaltype rX = 0; - scaltype rY = 0; - scaltype rDx2 = 0; - scaltype rDy2 = 0; - scaltype rZ = ray->source->layer->station->zCoord; - scaltype deltaZ = rZ - lZ; - AddRayData(ray, lX, lY, lDx2, lDy2, rX, rY, rDx2, rDy2); - level_occupancy[ray->level] = 1; - Int_t numRays = 1; - -#ifdef BEST_RAYS_ONLY - pair<LxRay*, scaltype> bestNeighbours[LXLAYERS * LXLAYERS]; // Neigbours and chi2 to the cluster owner. - - for (Int_t l = 0; l < LXLAYERS * LXLAYERS; ++l) { - bestNeighbours[l].first = 0; - bestNeighbours[l].second = 0; - } - -#ifdef BEST_SIX_POINTS - set<LxPoint*> leftBestPoints[LXLAYERS]; - set<LxPoint*> rightBestPoints[LXLAYERS]; - map<pair<LxPoint*, LxPoint*>, LxRay*, LxLess> bestRaysMap[LXLAYERS * LXLAYERS]; - LxPoint* rayLeftPoint = ray->end; - Int_t rayLeftInd = rayLeftPoint->layer->layerNumber; - leftBestPoints[rayLeftInd].insert(rayLeftPoint); - LxPoint* rayRightPoint = ray->source; - Int_t rayRightInd = rayRightPoint->layer->layerNumber; - rightBestPoints[rayRightInd].insert(rayRightPoint); - bestRaysMap[ray->level][make_pair(rayLeftPoint, rayRightPoint)] = ray; - - for (list<LxRay*>::iterator l = ray->neighbourhood.begin(); l != ray->neighbourhood.end(); ++l) { - LxRay* r = *l; - - /*if (r->used) - continue; - - if (r->level == ray->level) - continue;*/ - - LxPoint* rLeftPoint = r->end; - Int_t rLeftInd = rLeftPoint->layer->layerNumber; - - if (rLeftPoint->used) continue; - - LxPoint* rRightPoint = r->source; - Int_t rRightInd = rRightPoint->layer->layerNumber; - - if (rRightPoint->used) continue; - - if (rLeftInd == rayLeftInd && rRightInd == rayRightInd) continue; - - leftBestPoints[rLeftInd].insert(rLeftPoint); - rightBestPoints[rRightInd].insert(rRightPoint); - bestRaysMap[r->level][make_pair(rLeftPoint, rRightPoint)] = r; - } -#endif //BEST_SIX_POINTS - -#endif //BEST_RAYS_ONLY - -#ifdef BEST_SIX_POINTS - LxRaysCandidates bestRaysCandidates; - - for (set<LxPoint*>::iterator r0 = rightBestPoints[0].begin(); r0 != rightBestPoints[0].end(); ++r0) { - for (set<LxPoint*>::iterator r1 = rightBestPoints[1].begin(); r1 != rightBestPoints[1].end(); ++r1) { - for (set<LxPoint*>::iterator r2 = rightBestPoints[2].begin(); r2 != rightBestPoints[2].end(); ++r2) { - for (set<LxPoint*>::iterator l0 = leftBestPoints[0].begin(); l0 != leftBestPoints[0].end(); ++l0) { - for (set<LxPoint*>::iterator l1 = leftBestPoints[1].begin(); l1 != leftBestPoints[1].end(); ++l1) { - for (set<LxPoint*>::iterator l2 = leftBestPoints[2].begin(); l2 != leftBestPoints[2].end(); ++l2) { - LxRaysCandidates cand; - - for (Int_t rInd = 0; rInd < LXLAYERS; ++rInd) { - LxPoint* rPoint = 0; - - switch (rInd) { - case 0: rPoint = *r0; break; - - case 1: rPoint = *r1; break; - - default: rPoint = *r2; - } - - for (Int_t lInd = 0; lInd < LXLAYERS; ++lInd) { - LxPoint* lPoint = 0; - - switch (lInd) { - case 0: lPoint = *l0; break; - - case 1: lPoint = *l1; break; - - default: lPoint = *l2; - } - - Int_t level = rPoint->layer->layerNumber * LXLAYERS + lPoint->layer->layerNumber; - map<pair<LxPoint*, LxPoint*>, LxRay*, LxLess>::iterator rIter = - bestRaysMap[level].find(make_pair(lPoint, rPoint)); - - if (rIter == bestRaysMap[level].end()) continue; - - if (level == ray->level) continue; - - cand.data[level] = rIter->second; - } - } - - Int_t candLevels = 0; - cand.chi2 = 0; - - for (Int_t l = 0; l < LXLAYERS * LXLAYERS; ++l) { - if (0 == cand.data[l]) continue; - - ++candLevels; - LxRay* r = cand.data[l]; - scaltype diffTx = r->tx - ray->tx; - scaltype diffTy = r->ty - ray->ty; - scaltype diffZ = ray->source->z - r->source->z; - scaltype diffX = r->source->x + r->tx * diffZ - ray->source->x; - scaltype diffY = r->source->y + r->ty * diffZ - ray->source->y; - cand.chi2 += diffTx * diffTx / (ray->dtx * ray->dtx) + diffTy * diffTy / (ray->dty * ray->dty) - + diffX * diffX / (ray->source->dx * ray->source->dx) - + diffY * diffY / (ray->source->dy * ray->source->dy); - } - - if (candLevels < LXLAYERS * LXLAYERS - 1) continue; - - if (bestRaysCandidates.chi2 < 0 || bestRaysCandidates.chi2 > cand.chi2) bestRaysCandidates = cand; - } - } - } - } - } - } - - if (bestRaysCandidates.chi2 < 0) continue; - - levels = LXLAYERS * LXLAYERS; - - for (Int_t l = 0; l < LXLAYERS * LXLAYERS; ++l) { - bestNeighbours[l].first = bestRaysCandidates.data[l]; - bestNeighbours[l].second = 0; - } - -#else //BEST_SIX_POINTS - for (list<LxRay*>::iterator l = ray->neighbourhood.begin(); l != ray->neighbourhood.end(); ++l) { - LxRay* r = *l; - - if (r->used) continue; - -#ifdef BEST_RAYS_ONLY - if (r->level == ray->level) continue; -#endif //BEST_RAYS_ONLY - - scaltype diffTx = r->tx - ray->tx; - scaltype diffTy = r->ty - ray->ty; - scaltype diffZ = ray->source->z - r->source->z; - scaltype diffX = r->source->x + r->tx * diffZ - ray->source->x; - scaltype diffY = r->source->y + r->ty * diffZ - ray->source->y; - scaltype aChi2 = diffTx * diffTx / (ray->dtx * ray->dtx) + diffTy * diffTy / (ray->dty * ray->dty) - + diffX * diffX / (ray->source->dx * ray->source->dx) - + diffY * diffY / (ray->source->dy * ray->source->dy); - -#ifdef BEST_RAYS_ONLY - if (0 == bestNeighbours[r->level].first || aChi2 < bestNeighbours[r->level].second) { - bestNeighbours[r->level].first = r; - bestNeighbours[r->level].second = aChi2; - } -#else //BEST_RAYS_ONLY - AddRayData(r, lX, lY, lDx2, lDy2, rX, rY, rDx2, rDy2); -#endif //BEST_RAYS_ONLY - - level_occupancy[r->level] = 1; - ++numRays; - } - - for (Int_t l = 0; l < LXLAYERS * LXLAYERS; ++l) - levels += level_occupancy[l]; -#endif //BEST_SIX_POINTS - - if (levels < LXLAYERS * LXLAYERS /*(LXLAYERS - 1) * (LXLAYERS - 1)*/) continue; - else if (levels < i + (LXLAYERS - 1) * (LXLAYERS - 1) -#if defined(DENSE_CLUSTERS_FIRST) && !defined(BEST_RAYS_ONLY) - || numRays < j + 1 -#endif //defined(DENSE_CLUSTERS_FIRST) && !defined(BEST_RAYS_ONLY) - ) { - InsertClusterRay(levels, numRays, - ray); // It should be safe to leave ray also in its previous place. - continue; - } - -#ifdef BEST_RAYS_ONLY - numRays = 1; - - for (Int_t l = 0; l < LXLAYERS * LXLAYERS; ++l) { - LxRay* r = bestNeighbours[l].first; - - if (0 == r) continue; - - AddRayData(r, lX, lY, lDx2, lDy2, rX, rY, rDx2, rDy2); -#ifdef BEST_SIX_POINTS - r->source->used = true; - r->end->used = true; -#else //BEST_SIX_POINTS - r->used = true; -#endif //BEST_SIX_POINTS - ++numRays; - } -#endif //BEST_RAYS_ONLY - - lX /= numRays; - lY /= numRays; - scaltype lDx = ray->end->dx; //sqrt(lDx2) / numRays; - scaltype lDy = ray->end->dy; //sqrt(lDy2) / numRays; - rX /= numRays; - rY /= numRays; - scaltype rDx = ray->source->dx; //sqrt(rDx2) / numRays; - scaltype rDy = ray->source->dy; //sqrt(rDy2) / numRays; - - LxPoint* lPoint = new LxPoint(lX, lY, lZ, lDx, lDy, 0, ray->end->layer, -1); - clusteredPoints.push_back(lPoint); - LxPoint* rPoint = new LxPoint(rX, rY, rZ, rDx, rDy, 0, ray->source->layer, -1); - clusteredPoints.push_back(rPoint); - LxRay* clRay = new LxRay(rPoint, lPoint, LXLAYERS + LXMIDDLE); - clRay->clusterPoints.push_back(ray->source); - clRay->clusterPoints.push_back(ray->end); -#ifdef REMEMBER_CLUSTERED_RAYS_IN_POINTS - ray->source->leftClusteredRay = clRay; - ray->end->rightClusteredRay = clRay; -#endif // REMEMBER_CLUSTERED_RAYS_IN_POINTS -#ifdef BEST_SIX_POINTS - ray->source->used = true; - ray->end->used = true; - //ray->used = true; -#else //BEST_SIX_POINTS - ray->used = true; -#endif //BEST_SIX_POINTS - -#ifdef BEST_RAYS_ONLY - for (Int_t l = 0; l < LXLAYERS * LXLAYERS; ++l) { - LxRay* r = bestNeighbours[l].first; - - if (0 == r) continue; - - clRay->clusterPoints.push_back(r->source); - clRay->clusterPoints.push_back(r->end); -#ifdef REMEMBER_CLUSTERED_RAYS_IN_POINTS - ray->source->leftClusteredRay = clRay; - ray->end->rightClusteredRay = clRay; -#endif // REMEMBER_CLUSTERED_RAYS_IN_POINTS - } - -#ifdef REMOVE_SUBCLUSTER - for (list<LxRay*>::iterator l = ray->neighbourhood.begin(); l != ray->neighbourhood.end(); ++l) { - LxRay* r = *l; - -#ifdef BEST_SIX_POINTS - //if (r->source->used || r->end->used) - //continue; -#else //BEST_SIX_POINTS - if (r->used) continue; -#endif //BEST_SIX_POINTS - - /*scaltype diffTx = r->tx - ray->tx; - - if (diffTx < 0) - diffTx = -diffTx; - - if (diffTx > errorTxCoeff * ray->dtx * 2) - continue; - - scaltype diffTy = r->ty - ray->ty; - - if (diffTy < 0) - diffTy = -diffTy; - - if (diffTy > errorTyCoeff * ray->dty * 2) - continue; - - scaltype diffZ = ray->source->z - r->source->z; - scaltype diffX = ray->source->x - r->source->x - r->tx * diffZ; - - if (diffX < 0) - diffX = -diffX; - - if (diffX > errorXcoeff * ray->source->dx * 2) - continue; - - scaltype diffY = ray->source->y - r->source->y - r->ty * diffZ; - - if (diffY < 0) - diffY = -diffY; - - if (diffY > errorYcoeff * ray->source->dy * 2) - continue;*/ - - clRay->clusterPoints.push_back(r->source); - clRay->clusterPoints.push_back(r->end); -#ifdef BEST_SIX_POINTS - //r->source->used = true; - //r->end->used = true; -#else //BEST_SIX_POINTS - r->used = true; -#endif //BEST_SIX_POINTS - } -#endif //REMOVE_SUBCLUSTER - -#else //BEST_RAYS_ONLY - for (list<LxRay*>::iterator l = ray->neighbourhood.begin(); l != ray->neighbourhood.end(); ++l) { - LxRay* r = *l; - - if (r->used) continue; - - clRay->clusterPoints.push_back(r->source); - clRay->clusterPoints.push_back(r->end); - r->used = true; - } -#endif //BEST_RAYS_ONLY - - KDRayWrap clRayWrap(rX, rY, clRay); - clusteredRays->insert(clRayWrap); - } // for (list<LxRay*>::iterator k = rays->begin(); k != rays->end(); ++k) - } // for (vector<list<LxRay*>*>::reverse_iterator j = clusters[i].rbegin(); j != clusters[i].rend(); ++j) - } // for (Int_t i = 2 * LXLAYERS - 1; i >= 0; --i) - - gettimeofday(&eTime, 0); - exeDuration = (eTime.tv_sec - bTime.tv_sec) * 1000000 + eTime.tv_usec - bTime.tv_usec; - - if (exeDuration > maxExeDuration) maxExeDuration = exeDuration; - - cout << "Max execution duration was: " << maxExeDuration << endl; -} -#endif //CLUSTER_MODE - -void LxStation::ConnectNeighbours() -{ - if (stationNumber < LXFIRSTSTATION + 2) return; - - LxLayer* layer = layers[LXMIDDLE]; - LxStation* lStation = space->stations[stationNumber - 1]; - - for (list<LxPoint*>::iterator i = layer->points.begin(); i != layer->points.end(); ++i) { - LxPoint* rPoint = *i; - - if (!rPoint->valid) continue; - - for (list<LxRay*>::iterator j = rPoint->rays.begin(); j != rPoint->rays.end(); ++j) { - LxRay* rRay = *j; - LxPoint* ePoint = rRay->end; - - if (!ePoint->valid) continue; - - for (list<LxRay*>::iterator k = ePoint->rays.begin(); k != ePoint->rays.end(); ++k) { - LxRay* lRay = *k; - scaltype diffTx = lRay->tx - rRay->tx; - scaltype diffTy = lRay->ty - rRay->ty; - - if (diffTx < 0) diffTx = -diffTx; - - if (diffTy < 0) diffTy = -diffTy; - - scaltype dtxb = sqrt(lRay->dtx * lRay->dtx + rRay->dtx * rRay->dtx); - scaltype dtyb = sqrt(lRay->dty * lRay->dty + rRay->dty * rRay->dty); - - if (diffTx > lStation->txBreakLimit + dtxb * errorTxBreakCoeff - || diffTy > lStation->tyBreakLimit + dtyb * errorTyBreakCoeff) - continue; - - rRay->neighbours.push_back(lRay); - } - } - } -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// LxSpace -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -LxSpace::LxSpace() - : muchStsBreakX(0) - , muchStsBreakY(0) - , muchStsBreakTx(0) - , muchStsBreakTy(0) - , stationsInAlgo(LXSTATIONS) -{ - for (int i = 0; i < LXSTATIONS; ++i) - stations.push_back(new LxStation(this, i)); - - x_coords = - reinterpret_cast<scal_coords*>(_mm_malloc(sizeof(scaltype) * LXSTATIONS * LXLAYERS * LXMAXPOINTSONSTATION, 32)); - tx_vals = reinterpret_cast<scal_tans*>(_mm_malloc(sizeof(scaltype) * (LXSTATIONS - 1) * LXMAXPOINTSONSTATION, 32)); - x_errs = - reinterpret_cast<scal_coords*>(_mm_malloc(sizeof(scaltype) * LXSTATIONS * LXLAYERS * LXMAXPOINTSONSTATION, 32)); - y_coords = - reinterpret_cast<scal_coords*>(_mm_malloc(sizeof(scaltype) * LXSTATIONS * LXLAYERS * LXMAXPOINTSONSTATION, 32)); - ty_vals = reinterpret_cast<scal_tans*>(_mm_malloc(sizeof(scaltype) * (LXSTATIONS - 1) * LXMAXPOINTSONSTATION, 32)); - y_errs = - reinterpret_cast<scal_coords*>(_mm_malloc(sizeof(scaltype) * LXSTATIONS * LXLAYERS * LXMAXPOINTSONSTATION, 32)); - z_coords = - reinterpret_cast<scal_coords*>(_mm_malloc(sizeof(scaltype) * LXSTATIONS * LXLAYERS * LXMAXPOINTSONSTATION, 32)); -} - -LxSpace::~LxSpace() -{ - _mm_free(x_coords); - _mm_free(tx_vals); - _mm_free(x_errs); - _mm_free(y_coords); - _mm_free(ty_vals); - _mm_free(y_errs); - _mm_free(z_coords); -} - -void LxSpace::Clear() -{ - for (vector<LxStation*>::iterator i = stations.begin(); i != stations.end(); ++i) - (*i)->Clear(); - - for (list<LxTrack*>::iterator i = tracks.begin(); i != tracks.end(); ++i) - delete *i; - - tracks.clear(); - extTracks.clear(); -} - -void LxSpace::RestoreMiddlePoints() -{ - for (int i = LXFIRSTSTATION; i < LXSTATIONS; ++i) - stations[i]->RestoreMiddlePoints(); -} - -void LxSpace::BuildRays() -{ - for (int i = LXFIRSTSTATION + 1; i < LXSTATIONS; ++i) - stations[i]->BuildRays(); -} - -#ifdef CLUSTER_MODE -void LxSpace::BuildRays2() -{ - for (Int_t i = LXSTATIONS - 1; i > LXFIRSTSTATION; --i) { - stations[i]->BuildRays2(); - - if (i <= LXFIRSTSTATION + 1) continue; - - for (Int_t j = 0; j < LXLAYERS; ++j) { - LxLayer* layer = stations[i - 1]->layers[j]; - - for (list<LxPoint*>::iterator k = layer->points.begin(); k != layer->points.end(); ++k) { - LxPoint* point = *k; - point->used = false; - } - } - } -} - -void LxSpace::ConnectNeighbours2() -{ - for (Int_t i = LXSTATIONS - 1; i > LXFIRSTSTATION + 1; --i) { - KDRaysStorageType* leftRays = static_cast<KDRaysStorageType*>(stations[i - 1]->clusteredRaysHandle); - KDRaysStorageType* rightRays = static_cast<KDRaysStorageType*>(stations[i]->clusteredRaysHandle); - scaltype txSigma = stations[i - 1]->txBreakSigma; - scaltype txSigma2 = txSigma * txSigma; - scaltype tySigma = stations[i - 1]->tyBreakSigma; - scaltype tySigma2 = tySigma * tySigma; - scaltype deltaZ = stations[i - 1]->zCoord - stations[i]->zCoord; - scaltype deltaZ2 = deltaZ * deltaZ; - scaltype deltaZ23 = 1.0; //deltaZ2 / 3.0; - - for (KDRaysStorageType::iterator j = rightRays->begin(); j != rightRays->end(); ++j) { - KDRayWrap& wrap = const_cast<KDRayWrap&>(*j); - LxRay* ray = wrap.ray; - KDTree::_Region<4, KDRayWrap, scaltype, KDTree::_Bracket_accessor<KDRayWrap>, - std::less<KDTree::_Bracket_accessor<KDRayWrap>::result_type>> - range(wrap); - LxPoint* point = ray->end; - scaltype x = wrap.data[0] + wrap.data[2] * deltaZ; - scaltype y = wrap.data[1] + wrap.data[3] * deltaZ; - scaltype tx = wrap.data[2]; - scaltype ty = wrap.data[3]; - scaltype xRange = 4 * sqrt(2 * point->dx * point->dx + txSigma2 * deltaZ23); - scaltype yRange = 4 * sqrt(2 * point->dy * point->dy + tySigma2 * deltaZ23); - scaltype txRange = 4 * sqrt(2 * ray->dtx * ray->dtx + txSigma2); - scaltype tyRange = 4 * sqrt(2 * ray->dty * ray->dty + tySigma2); - KDRayWrap boundsWrap(x - xRange, y - yRange, tx - txRange, ty - tyRange); - range.set_low_bound(boundsWrap, 0); - range.set_low_bound(boundsWrap, 1); - range.set_low_bound(boundsWrap, 2); - range.set_low_bound(boundsWrap, 3); - boundsWrap.data[0] = x + xRange; - boundsWrap.data[1] = y + yRange; - boundsWrap.data[2] = tx + txRange; - boundsWrap.data[3] = ty + tyRange; - range.set_high_bound(boundsWrap, 0); - range.set_high_bound(boundsWrap, 1); - range.set_high_bound(boundsWrap, 2); - range.set_high_bound(boundsWrap, 3); - list<KDRayWrap> neighbours; - leftRays->find_within_range(range, back_insert_iterator<list<KDRayWrap>>(neighbours)); - - for (list<KDRayWrap>::iterator k = neighbours.begin(); k != neighbours.end(); ++k) { - KDRayWrap& w = *k; - LxRay* r = w.ray; - ray->neighbours.push_back(r); - } - } - } -} - -void LxSpace::BuildCandidates2(LxRay* ray, LxRay** rays, list<LxTrackCandidate*>& candidates, scaltype chi2) -{ - int level = ray->station->stationNumber - LXFIRSTSTATION - 1; - rays[level] = ray; - - if (0 == level) { - LxTrackCandidate* tc = new LxTrackCandidate(rays, LXSTATIONS - LXFIRSTSTATION - 1, chi2); - candidates.push_back(tc); - return; - } - - LxPoint* point = ray->end; - - for (list<LxRay*>::iterator i = ray->neighbours.begin(); i != ray->neighbours.end(); ++i) { - LxRay* lRay = *i; - - if (lRay->source->used) continue; - - LxPoint* lPoint = lRay->source; - LxStation* station = lRay->station; - scaltype dx = point->x - lPoint->x; - scaltype dx2 = dx * dx; - scaltype sigmaX2 = point->dx * point->dx + lPoint->dx * lPoint->dx; - scaltype dy = point->y - lPoint->y; - scaltype dy2 = dy * dy; - scaltype sigmaY2 = point->dy * point->dy + lPoint->dy * lPoint->dy; - scaltype dtx = ray->tx - lRay->tx; - scaltype dtx2 = dtx * dtx; - scaltype sigmaTx2 = ray->dtx * ray->dtx + lRay->dtx * lRay->dtx + station->txBreakSigma * station->txBreakSigma; - scaltype dty = ray->ty - lRay->ty; - scaltype dty2 = dty * dty; - scaltype sigmaTy2 = ray->dty * ray->dty + lRay->dty * lRay->dty + station->tyBreakSigma * station->tyBreakSigma; - - // Continue process of track building. - BuildCandidates2(lRay, rays, candidates, chi2 + dx2 / sigmaX2 + dy2 / sigmaY2 + dtx2 / sigmaTx2 + dty2 / sigmaTy2); - } -} - -void LxSpace::Reconstruct2() -{ - LxStation* startStation = stations[LXSTATIONS - 1]; - KDRaysStorageType* startRays = static_cast<KDRaysStorageType*>(startStation->clusteredRaysHandle); - - for (KDRaysStorageType::iterator i = startRays->begin(); i != startRays->end(); ++i) { - KDRayWrap& wrap = const_cast<KDRayWrap&>(*i); - LxRay* ray = wrap.ray; - LxRay* rays[LXSTATIONS - LXFIRSTSTATION - 1]; - list<LxTrackCandidate*> candidates; - scaltype chi2 = 0; - BuildCandidates2(ray, rays, candidates, chi2); - LxTrackCandidate* bestCandidate = 0; - - for (list<LxTrackCandidate*>::iterator j = candidates.begin(); j != candidates.end(); ++j) { - LxTrackCandidate* candidate = *j; - - if (0 == bestCandidate || candidate->chi2 < bestCandidate->chi2) bestCandidate = candidate; - } - - if (0 != bestCandidate) { - LxTrack* track = new LxTrack(bestCandidate); - tracks.push_back(track); - } - - for (list<LxTrackCandidate*>::iterator j = candidates.begin(); j != candidates.end(); ++j) - delete *j; - } // for (KDRaysStorageType::iterator i = rays->begin(); i != rays->end(); ++i) - - cout << "LxSpace::Reconstruct() found: " << tracks.size() << " tracks" << endl; -} -#endif //CLUSTER_MODE - -void LxSpace::ConnectNeighbours() -{ - for (int i = LXFIRSTSTATION + 2; i < LXSTATIONS; ++i) - stations[i]->ConnectNeighbours(); -} - -void LxSpace::BuildCandidates(int endStNum, LxRay* ray, LxRay** rays, list<LxTrackCandidate*>& candidates, - scaltype chi2) -{ - int level = ray->station->stationNumber - 1; - rays[level] = ray; - - if (0 == level) { -#ifdef USE_KALMAN - LxTrackCandidate* tc = new LxTrackCandidate(rays, LXSTATIONS - 1, ray->kalman.chi2); -#else // USE_KALMAN - LxTrackCandidate* tc = new LxTrackCandidate(rays, endStNum, chi2); -#endif //USE_KALMAN - candidates.push_back(tc); - return; - } - - for (list<LxRay*>::iterator i = ray->neighbours.begin(); i != ray->neighbours.end(); ++i) { - LxRay* lRay = *i; - - if (lRay->source->used) continue; - - LxStation* station = lRay->station; - //scaltype dtx = ray->tx - lRay->tx; - //dtx /= station->txBreakSigma; - //scaltype dty = ray->ty - lRay->ty; - //dty /= station->tyBreakSigma; - - scaltype dtx = ray->tx - lRay->tx; - scaltype dtx2 = dtx * dtx; - scaltype sigmaTx2 = ray->dtx * ray->dtx + lRay->dtx * lRay->dtx + station->txBreakSigma * station->txBreakSigma; - scaltype dty = ray->ty - lRay->ty; - scaltype dty2 = dty * dty; - scaltype sigmaTy2 = ray->dty * ray->dty + lRay->dty * lRay->dty + station->tyBreakSigma * station->tyBreakSigma; - -#ifdef USE_KALMAN - LxKalmanParams& kPrev = ray->kalman; - LxKalmanParams& kalman = lRay->kalman; - kalman.tx = kPrev.tx; - kalman.ty = kPrev.ty; - kalman.C11 = kPrev.C11 + station->txBreakSigma * station->txBreakSigma; - kalman.C22 = kPrev.C22 + station->tyBreakSigma * station->tyBreakSigma; - scaltype S11 = 1 / (kalman.C11 + lRay->dtx * lRay->dtx); - scaltype S22 = 1 / (kalman.C22 + lRay->dty * lRay->dty); - scaltype K11 = kalman.C11 * S11; - scaltype K22 = kalman.C22 * S22; - scaltype zetaTx = lRay->tx - kalman.tx; - scaltype zetaTy = lRay->ty - kalman.ty; - kalman.tx += K11 * zetaTx; - kalman.ty += K22 * zetaTy; - kalman.C11 = (1.0 - K11) * kalman.C11; - kalman.C22 = (1.0 - K22) * kalman.C22; - kalman.chi2 = kPrev.chi2 + zetaTx * S11 * zetaTx + zetaTy * S22 * zetaTy; -#endif //USE_KALMAN - - // Continue process of track building. - //BuildCandidates(lRay, rays, candidates, chi2 + dtx * dtx + dty * dty); - BuildCandidates(endStNum, lRay, rays, candidates, chi2 + dtx2 / sigmaTx2 + dty2 / sigmaTy2); - } -} - -void LxSpace::Reconstruct() -{ - for (int endStNum = LXSTATIONS - 1; endStNum >= stationsInAlgo - 1; --endStNum) { - LxStation* startStation = stations[endStNum]; - LxLayer* startLayer = startStation->layers[LXMIDDLE]; - list<LxPoint*>& startPoints = startLayer->points; - - for (list<LxPoint*>::iterator i = startPoints.begin(); i != startPoints.end(); ++i) { - LxPoint* point = *i; - - if (point->used) continue; - - if (!point->valid) continue; - - LxRay* rays[endStNum]; - list<LxTrackCandidate*> candidates; - list<LxRay*>& startRays = point->rays; - - for (list<LxRay*>::iterator j = startRays.begin(); j != startRays.end(); ++j) { - LxRay* ray = *j; - scaltype chi2 = 0; - -#ifdef USE_KALMAN - LxKalmanParams& kalman = ray->kalman; - kalman.tx = ray->tx; - kalman.ty = ray->ty; - kalman.C11 = ray->dtx * ray->dtx; - kalman.C22 = ray->dty * ray->dty; - kalman.chi2 = 0; -#endif //USE_KALMAN - - BuildCandidates(endStNum, ray, rays, candidates, chi2); - } - - LxTrackCandidate* bestCandidate = 0; - - for (list<LxTrackCandidate*>::iterator j = candidates.begin(); j != candidates.end(); ++j) { - LxTrackCandidate* candidate = *j; - - if (0 == bestCandidate || candidate->chi2 < bestCandidate->chi2) bestCandidate = candidate; - } - - if (0 != bestCandidate) { - LxTrack* track = new LxTrack(bestCandidate); - tracks.push_back(track); - } - - for (list<LxTrackCandidate*>::iterator j = candidates.begin(); j != candidates.end(); ++j) - delete *j; - } - } // for (int stNum = LXSTATIONS - 1; stNum >= stationsInAlgo - 1; --stNum) - - for (list<LxTrack*>::iterator i = tracks.begin(); i != tracks.end(); ++i) { - LxTrack* track = *i; - //cout << "LxSpace::Reconstruct(): found track with length = " << track->length << endl << "With points:"; - - for (int j = 0; j < track->length * LXLAYERS; ++j) { - LxPoint* point = track->points[j]; - - //if (point) - //cout << " " << point->z; - //else - //cout << " *"; - } - - //cout << endl; - } - - RemoveClones(); -} - -void LxSpace::RemoveClones() -{ - for (list<LxTrack*>::iterator i = tracks.begin(); i != tracks.end(); ++i) { - LxTrack* firstTrack = *i; - list<LxTrack*>::iterator i2 = i; - ++i2; - - if (i2 == tracks.end()) break; - - LxTrack* secondTrack = *i2; - Int_t neighbourPoints = 0; - int minLength = firstTrack->length < secondTrack->length ? firstTrack->length : secondTrack->length; - - for (Int_t j = 0; j < minLength * LXLAYERS; ++j) { - LxPoint* point1 = firstTrack->points[j]; - LxPoint* point2 = secondTrack->points[j]; - - if (0 == point1 || 0 == point2) continue; - - scaltype dx = point1->dx > point2->dx ? point1->dx : point2->dx; - scaltype dy = point1->dy > point2->dy ? point1->dy : point2->dy; - - if (abs(point2->x - point1->x) < 5.0 * dx && abs(point2->y - point1->y) < 5.0 * dy) ++neighbourPoints; - } - - if (neighbourPoints < minLength * LXLAYERS / 2) continue; - - if (firstTrack->length > secondTrack->length) secondTrack->clone = true; - else if (secondTrack->length > firstTrack->length) - firstTrack->clone = true; - else if (firstTrack->chi2 < secondTrack->chi2) - secondTrack->clone = true; - else - firstTrack->clone = true; - } -} - -void LxSpace::FitTracks() -{ - for (list<LxTrack*>::iterator i = tracks.begin(); i != tracks.end(); ++i) - (*i)->Fit(); -} - -void LxSpace::JoinExtTracks() -{ - /*scaltype sigmaX = 0.8548;//0.89;//1.202; - scaltype sigmaX2 = sigmaX * sigmaX; - scaltype sigmaY = 0.6233;//1.061; - scaltype sigmaY2 = sigmaY * sigmaY; - scaltype sigmaTx = 0.02349;//0.02426; - scaltype sigmaTx2 = sigmaTx * sigmaTx; - scaltype sigmaTy = 0.007941;//0.01082; - scaltype sigmaTy2 = sigmaTy * sigmaTy; - scaltype deltaMuPlus = -0.01883; - scaltype sigmaTxMuPlus = 0.01105; - scaltype sigmaTxMuPlus2 = sigmaTxMuPlus * sigmaTxMuPlus; - scaltype deltaMuMinus = 0.020; - scaltype sigmaTxMuMinus = 0.0118; - scaltype sigmaTxMuMinus2 = sigmaTxMuMinus * sigmaTxMuMinus; - scaltype covXTx = 0.155612; - scaltype covYTy = 0.157198;*/ - //scaltype cutCoeff = 5.0; -#ifdef USE_OLD_STS_LINKING_RULE - scaltype sigmaX2 = muchStsBreakX * muchStsBreakX; - scaltype sigmaY2 = muchStsBreakY * muchStsBreakY; - scaltype sigmaTx2 = muchStsBreakTx * muchStsBreakTx; - scaltype sigmaTy2 = muchStsBreakTy * muchStsBreakTy; -#endif //USE_OLD_STS_LINKING_RULE - - TrackPropagatorPtr fPropagator = CbmLitToolFactory::CreateTrackPropagator("lit"); - - for (list<LxTrack*>::iterator i = tracks.begin(); i != tracks.end(); ++i) { - LxTrack* track = *i; - - if (track->clone) continue; - -#ifdef USE_KALMAN_FIT - scaltype x = track->x; - scaltype y = track->y; - scaltype z = track->z; - scaltype tx0 = track->tx; - scaltype ty = track->ty; - scaltype dxMuch = track->dx; - scaltype dyMuch = track->dy; - scaltype dtxMuch = track->dtx; - scaltype dtyMuch = track->dty; -#else //USE_KALMAN_FIT - LxRay* ray = track->rays[0]; - LxPoint* point = ray->end; - scaltype x = point->x; - scaltype y = point->y; - scaltype z = point->z; - //scaltype tx0 = ray->tx; - scaltype tx = ray->tx; - scaltype ty = ray->ty; - scaltype dxMuch = point->dx; - scaltype dyMuch = point->dy; - scaltype dtxMuch = ray->dtx; - scaltype dtyMuch = ray->dty; -#endif //USE_KALMAN_FIT - - // External track are already filtered by P and Pt. - for (list<LxExtTrack>::iterator j = extTracks.begin(); j != extTracks.end(); ++j) { - LxExtTrack* extTrack = &(*j); - const FairTrackParam* firstParam = extTrack->track->GetParamFirst(); - const FairTrackParam* lastParam = extTrack->track->GetParamLast(); - -#ifndef USE_OLD_STS_LINKING_RULE - CbmLitTrackParam litLastParam; - CbmLitConverterFairTrackParam::FairTrackParamToCbmLitTrackParam(lastParam, &litLastParam); - - if (kLITERROR == fPropagator->Propagate(&litLastParam, stations[0]->zCoord, 13)) continue; - - scaltype deltaX = abs(litLastParam.GetX() - x); - scaltype deltaY = abs(litLastParam.GetY() - y); - scaltype deltaTx = abs(litLastParam.GetTx() - tx0); - scaltype deltaTy = abs(litLastParam.GetTy() - ty); - scaltype sigmaX2 = dxMuch * dxMuch + litLastParam.GetCovariance(0); - scaltype sigmaX = sqrt(sigmaX2); - scaltype sigmaY2 = dyMuch * dyMuch + litLastParam.GetCovariance(5); - scaltype sigmaY = sqrt(sigmaY2); - scaltype sigmaTx2 = dtxMuch * dtxMuch + litLastParam.GetCovariance(9); - scaltype sigmaTx = sqrt(sigmaTx2); - scaltype sigmaTy2 = dtyMuch * dtyMuch + litLastParam.GetCovariance(12); - scaltype sigmaTy = sqrt(sigmaTy2); - - //if (deltaX > cutCoeff * sigmaX || deltaY > cutCoeff * sigmaY || - //deltaTx > cutCoeff * sigmaTx || deltaTy > cutCoeff * sigmaTy) - //{ - //continue; - //} - - scaltype chi2 = deltaX * deltaX / sigmaX2 + deltaY * deltaY / sigmaY2 + deltaTx * deltaTx / sigmaTx2 - + deltaTy * deltaTy / sigmaTy2; -#else //USE_OLD_STS_LINKING_RULE - - //if ((tx0 - lastParam->GetTx()) * (lastParam->GetTx() - firstParam->GetTx()) < 0) - //continue; - - /*scaltype muchCharge = tx0 - firstParam->GetTx(); - scaltype tx = muchCharge > 0 ? tx0 + deltaMuPlus : tx0 + deltaMuMinus; - - if (muchCharge > 0) - { - sigmaTx = sigmaTxMuPlus; - sigmaTx2 = sigmaTxMuPlus2; - } - else - { - sigmaTx = sigmaTxMuMinus; - sigmaTx2 = sigmaTxMuMinus2; - }*/ - - scaltype deltaZ = lastParam->GetZ() - z; - scaltype deltaX = abs(lastParam->GetX() - x - tx * deltaZ); - scaltype dxSts2 = lastParam->GetCovariance(0, 0); - scaltype dySts2 = lastParam->GetCovariance(1, 1); - scaltype dtxSts2 = lastParam->GetCovariance(2, 2); - scaltype dtySts2 = lastParam->GetCovariance(3, 3); - //scaltype sigmaXMeas2 = dxMuch * dxMuch + dxSts2 - covXTx * deltaZ;// deltaZ is negative. - scaltype sigmaXMeas2 = dxMuch * dxMuch + dxSts2 + dtxMuch * dtxMuch * deltaZ * deltaZ; - //scaltype sigmaXMeas = sqrt(sigmaXMeas2); - //scaltype sigmaYMeas2 = dyMuch * dyMuch + dySts2 - covYTy * deltaZ;// deltaZ is negative. - scaltype sigmaYMeas2 = dyMuch * dyMuch + dySts2 + dtyMuch * dtyMuch * deltaZ * deltaZ; - //scaltype sigmaYMeas = sqrt(sigmaYMeas2); - scaltype sigmaTxMeas2 = dtxMuch * dtxMuch + dtxSts2; - //scaltype sigmaTxMeas = sqrt(sigmaTxMeas2); - scaltype sigmaTyMeas2 = dtyMuch * dtyMuch + dtySts2; - //scaltype sigmaTyMeas = sqrt(sigmaTyMeas2); - - //if (deltaX > cutCoeff * sqrt(sigmaX2 + sigmaXMeas2)) - //continue; - - scaltype deltaY = abs(lastParam->GetY() - y - ty * deltaZ); - - //if (deltaY > cutCoeff * sqrt(sigmaY2 + sigmaYMeas2)) - //continue; - - scaltype deltaTx = abs(lastParam->GetTx() - tx); - - //if (deltaTx > cutCoeff * sqrt(sigmaTx2 + sigmaTxMeas2)) - //continue; - - scaltype deltaTy = abs(lastParam->GetTy() - ty); - - //if (deltaTy > cutCoeff * sqrt(sigmaTy2 + sigmaTyMeas2)) - //continue; - - // Take the charge sign into account. - //scaltype stsCharge = firstParam->GetQp(); - //scaltype angMomInv = muchCharge / stsCharge; - //scaltype dAmi = abs(sqrt(dtxMuch * dtxMuch + firstParam->GetCovariance(2, 2)) / stsCharge); - - // Check if the MUCH track projection to XZ plane angle fit the STS track momentum. - //if (0.18 - dAmi > angMomInv || 0.52 + dAmi < angMomInv) - //if (0.26 - dAmi > angMomInv || 0.44 + dAmi < angMomInv) - //continue; - - scaltype chi2 = deltaX * deltaX / (sigmaX2 + sigmaXMeas2) + deltaY * deltaY / (sigmaY2 + sigmaYMeas2) - + deltaTx * deltaTx / (sigmaTx2 + sigmaTxMeas2) + deltaTy * deltaTy / (sigmaTy2 + sigmaTyMeas2); -#endif //USE_OLD_STS_LINKING_RULE - -#ifdef LX_EXT_LINK_SOPH - list<pair<LxExtTrack*, scaltype>>::iterator k = track->extTrackCandidates.begin(); - - for (; k != track->extTrackCandidates.end() && chi2 >= k->second; ++k) - ; - - pair<LxExtTrack*, scaltype> linkDesc(extTrack, chi2); - track->extTrackCandidates.insert(k, linkDesc); -#else //LX_EXT_LINK_SOPH - if (0 == track->externalTrack || track->extLinkChi2 > chi2) { - track->externalTrack = extTrack; - track->extLinkChi2 = chi2; - } -#endif //LX_EXT_LINK_SOPH - } // for (list<LxExtTrack>::iterator j = extTracks.begin(); j != extTracks.end(); ++j) - -#ifdef LX_EXT_LINK_SOPH - for (list<pair<LxExtTrack*, scaltype>>::iterator j = track->extTrackCandidates.begin(); - j != track->extTrackCandidates.end(); ++j) { - LxExtTrack* extTrack = j->first; - scaltype chi2 = j->second; - - if (0 == extTrack->recoTrack.first) { - extTrack->recoTrack.first = track; - extTrack->recoTrack.second = chi2; - track->externalTrack = extTrack; - break; - } - else if (chi2 < extTrack->recoTrack.second) { - LxTrack* anotherTrack = extTrack->recoTrack.first; - extTrack->recoTrack.first = track; - extTrack->recoTrack.second = chi2; - track->externalTrack = extTrack; - anotherTrack->Rebind(); - break; - } - } -#endif // LX_EXT_LINK_SOPH - } // for (list<LxTrack*>::iterator i = tracks.begin(); i != tracks.end(); ++i) -} - -void LxSpace::CheckArray(scaltype xs[LXSTATIONS][LXLAYERS], scaltype ys[LXSTATIONS][LXLAYERS], - scaltype zs[LXSTATIONS][LXLAYERS], scaltype xDisp2Limits[LXSTATIONS], - scaltype yDisp2Limits[LXSTATIONS], scaltype tx2Limits[LXSTATIONS], - scaltype ty2Limits[LXSTATIONS], scaltype txBreak2Limits[LXSTATIONS], - scaltype tyBreak2Limits[LXSTATIONS]) -{ - for (int i = 0; i < LXSTATIONS; ++i) { - scaltype diffZ = zs[i][0] - zs[i][1]; - scaltype tx = xs[i][1] / zs[i][1]; - scaltype ty = ys[i][1] / zs[i][1]; - scaltype dispXL = xs[i][0] - tx * diffZ - xs[i][1]; - scaltype dispYL = ys[i][0] - ty * diffZ - ys[i][1]; - - if (dispXL < 0) dispXL = -dispXL; - - if (dispYL < 0) dispYL = -dispYL; - - diffZ = zs[i][2] - zs[i][1]; - scaltype dispXR = xs[i][2] - tx * diffZ - xs[i][1]; - scaltype dispYR = ys[i][2] - ty * diffZ - ys[i][1]; - - if (dispXR < 0) dispXR = -dispXR; - - if (dispYR < 0) dispYR = -dispYR; - - scaltype dispX = dispXL < dispXR ? dispXL : dispXR; - scaltype dispY = dispYL < dispYR ? dispYL : dispYR; - - if (stations[i]->disp01XBig - dispX < xDisp2Limits[i]) xDisp2Limits[i] = stations[i]->disp01XBig - dispX; - - if (stations[i]->disp01YBig - dispY < yDisp2Limits[i]) yDisp2Limits[i] = stations[i]->disp01YBig - dispY; - - if (i > 0) { - diffZ = zs[i][1] - zs[i - 1][1]; - scaltype tx1 = xs[i][1] / zs[i][1]; - tx = (xs[i][1] - xs[i - 1][1]) / diffZ; - scaltype dtx = tx - tx1; - - if (dtx < 0) dtx = -dtx; - - scaltype ty1 = ys[i][1] / zs[i][1]; - ty = (ys[i][1] - ys[i - 1][1]) / diffZ; - scaltype dty = ty - ty1; - - if (dty < 0) dty = -dty; - - if (stations[i]->txLimit - dtx < tx2Limits[i]) tx2Limits[i] = stations[i]->txLimit - dtx; - - if (stations[i]->tyLimit - dty < ty2Limits[i]) ty2Limits[i] = stations[i]->tyLimit - dty; - - if (i < LXSTATIONS - 1) { - diffZ = zs[i + 1][1] - zs[i][1]; - scaltype tx2 = (xs[i + 1][1] - xs[i][1]) / diffZ; - scaltype ty2 = (ys[i + 1][1] - ys[i][1]) / diffZ; - scaltype txBreak = tx2 - tx; - scaltype tyBreak = ty2 - ty; - - if (txBreak < 0) txBreak = -txBreak; - - if (tyBreak < 0) tyBreak = -tyBreak; - - if (stations[i]->txBreakLimit - txBreak < txBreak2Limits[i]) - txBreak2Limits[i] = stations[i]->txBreakLimit - txBreak; - - if (stations[i]->tyBreakLimit - tyBreak < tyBreak2Limits[i]) - tyBreak2Limits[i] = stations[i]->tyBreakLimit - tyBreak; - } - } - } -} - -void LxSpace::CheckArray(scaltype xs[LXSTATIONS][LXLAYERS], scaltype ys[LXSTATIONS][LXLAYERS], - scaltype zs[LXSTATIONS][LXLAYERS], list<LxPoint*> pts[LXSTATIONS][LXLAYERS], int level, - scaltype xDisp2Limits[LXSTATIONS], scaltype yDisp2Limits[LXSTATIONS], - scaltype tx2Limits[LXSTATIONS], scaltype ty2Limits[LXSTATIONS], - scaltype txBreak2Limits[LXSTATIONS], scaltype tyBreak2Limits[LXSTATIONS]) -{ - if (LXSTATIONS * LXLAYERS == level) { - CheckArray(xs, ys, zs, xDisp2Limits, yDisp2Limits, tx2Limits, ty2Limits, txBreak2Limits, tyBreak2Limits); - return; - } - - int stNum = level / LXLAYERS; - int lyNum = level % LXLAYERS; - list<LxPoint*>& points = pts[stNum][lyNum]; - - for (list<LxPoint*>::iterator i = points.begin(); i != points.end(); ++i) { - LxPoint* point = *i; - - xs[stNum][lyNum] = point->x; - ys[stNum][lyNum] = point->y; - zs[stNum][lyNum] = point->z; - - CheckArray(xs, ys, zs, pts, level + 1, xDisp2Limits, yDisp2Limits, tx2Limits, ty2Limits, txBreak2Limits, - tyBreak2Limits); - } -} - -void LxSpace::CheckArray(ostream& out, LxMCTrack& track) -{ - scaltype xs[LXSTATIONS][LXLAYERS]; - scaltype ys[LXSTATIONS][LXLAYERS]; - scaltype zs[LXSTATIONS][LXLAYERS]; - list<LxPoint*> pts[LXSTATIONS][LXLAYERS]; - int inits[LXSTATIONS][LXLAYERS]; - scaltype xDisp2Limits[LXSTATIONS]; - scaltype yDisp2Limits[LXSTATIONS]; - scaltype tx2Limits[LXSTATIONS]; - scaltype ty2Limits[LXSTATIONS]; - scaltype txBreak2Limits[LXSTATIONS]; - scaltype tyBreak2Limits[LXSTATIONS]; - bool busyHits[LXSTATIONS]; - - for (int i = 0; i < LXSTATIONS; ++i) { - for (int j = 0; j < LXLAYERS; ++j) - inits[i][j] = 0; - - xDisp2Limits[i] = stations[i]->disp01XBig; - yDisp2Limits[i] = stations[i]->disp01YBig; - tx2Limits[i] = stations[i]->txLimit; - ty2Limits[i] = stations[i]->tyLimit; - txBreak2Limits[i] = stations[i]->txBreakLimit; - tyBreak2Limits[i] = stations[i]->tyBreakLimit; - busyHits[i] = false; - } - - for (vector<LxMCPoint*>::iterator i = track.Points.begin(); i != track.Points.end(); ++i) { - LxMCPoint* point = *i; - - for (list<LxPoint*>::iterator j = point->lxPoints.begin(); j != point->lxPoints.end(); ++j) { - LxPoint* lxPoint = *j; - pts[point->stationNumber][point->layerNumber].push_back(lxPoint); - - if (lxPoint->used) busyHits[point->stationNumber] = true; - } - - inits[point->stationNumber][point->layerNumber] += point->lxPoints.size(); - } - - bool ini = true; - - for (int i = 0; i < LXSTATIONS; ++i) { - for (int j = 0; j < LXLAYERS; ++j) - ini = ini && 0 < inits[i][j]; - } - - if (!ini) { - out << "CheckArray: track does not contain all the points" << endl; - return; - } - - CheckArray(xs, ys, zs, pts, 0, xDisp2Limits, yDisp2Limits, tx2Limits, ty2Limits, txBreak2Limits, tyBreak2Limits); - - for (int i = 0; i < LXSTATIONS; ++i) { - out << "CheckArray on station " << i << ": "; - out << "dispX to limit: " << xDisp2Limits[i]; - out << "; dispY to limit: " << yDisp2Limits[i]; - - if (i > 0) { - out << "; Tx to limit: " << tx2Limits[i]; - out << "; Ty to limit: " << ty2Limits[i]; - - if (i < LXSTATIONS - 1) { - out << "; tx break to limit: " << txBreak2Limits[i]; - out << "; ty break to limit: " << tyBreak2Limits[i]; - } - } - - if (busyHits[i]) out << "; have busy hits"; - - out << endl; - } - - out << endl; -} diff --git a/reco/tracking/lx/Simple/LxCA.h b/reco/tracking/lx/Simple/LxCA.h deleted file mode 100644 index a2c34c114f2ce57fa3e997bddb6eacff3a76a97c..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/Simple/LxCA.h +++ /dev/null @@ -1,347 +0,0 @@ -/* Copyright (C) 2014-2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifndef LXCA_INCLUDED -#define LXCA_INCLUDED - -#pragma GCC diagnostic ignored "-Weffc++" - -#include "Rtypes.h" - -#include <list> - -#include <math.h> - -#include "LxMC.h" -#include "LxSettings.h" - -struct LxPoint; - -#define errorTxCoeff 4.0 -#define errorTxCoeffSq errorTxCoeff* errorTxCoeff -#define errorTyCoeff 4.0 -#define errorTyCoeffSq errorTyCoeff* errorTyCoeff - -extern scaltype tx_limits[LXSTATIONS]; -extern scaltype tx_limits_sq[LXSTATIONS]; -extern scaltype ty_limits[LXSTATIONS]; -extern scaltype ty_limits_sq[LXSTATIONS]; -extern scaltype x_disp_left_limits[LXSTATIONS]; -extern scaltype x_disp_left_limits_sq[LXSTATIONS]; -extern scaltype y_disp_left_limits[LXSTATIONS]; -extern scaltype y_disp_left_limits_sq[LXSTATIONS]; -extern scaltype x_disp_right_limits[LXSTATIONS]; -extern scaltype x_disp_right_limits_sq[LXSTATIONS]; -extern scaltype y_disp_right_limits[LXSTATIONS]; -extern scaltype y_disp_right_limits_sq[LXSTATIONS]; -/*extern scaltype x_coords[LXSTATIONS][LXLAYERS][LXMAXPOINTSONSTATION]; -extern scaltype tx_vals[LXSTATIONS - 1][LXMAXPOINTSONSTATION]; -extern scaltype x_errs[LXSTATIONS][LXLAYERS][LXMAXPOINTSONSTATION]; -extern scaltype y_coords[LXSTATIONS][LXLAYERS][LXMAXPOINTSONSTATION]; -extern scaltype ty_vals[LXSTATIONS][LXMAXPOINTSONSTATION]; -extern scaltype y_errs[LXSTATIONS][LXLAYERS][LXMAXPOINTSONSTATION]; -extern scaltype z_coords[LXSTATIONS][LXLAYERS][LXMAXPOINTSONSTATION]; -extern LxPoint* point_refs[LXSTATIONS][LXLAYERS][LXMAXPOINTSONSTATION]; -extern bool use_points[LXSTATIONS - 1][LXMAXPOINTSONSTATION]; -extern int points_counts[LXSTATIONS][LXLAYERS]; - -void InitGlobalCAArrays(); -void BuildRaysGlobal();*/ - -struct LxRay; -struct LxLayer; -struct LxTrack; -struct LxStation; -struct LxSpace; -struct LxTrackCandidate; - -struct LxPoint { - scaltype x, y, z; - scaltype dx, dy, dz; - bool used; - bool valid; - bool artificial; - LxTrack* track; - std::list<LxRay*> rays; - LxLayer* layer; - Int_t hitId; -#ifdef MAKE_EFF_CALC - std::list<LxMCPoint*> mcPoints; -#endif //MAKE_EFF_CALC - -#ifdef REMEMBER_CLUSTERED_RAYS_IN_POINTS - LxRay* leftClusteredRay; - LxRay* rightClusteredRay; -#endif //REMEMBER_CLUSTERED_RAYS_IN_POINTS - - LxPoint(scaltype X, scaltype Y, scaltype Z, scaltype Dx, scaltype Dy, scaltype Dz, LxLayer* lay, int hId, - bool isArtificial = false) - : x(X) - , y(Y) - , z(Z) - , dx(Dx) - , dy(Dy) - , dz(Dz) - , used(false) - , valid(true) - , artificial(isArtificial) - , track(NULL) - , rays() - , layer(lay) - , hitId(hId) -#ifdef REMEMBER_CLUSTERED_RAYS_IN_POINTS - , leftClusteredRay(0) - , rightClusteredRay(0) -#endif //REMEMBER_CLUSTERED_RAYS_IN_POINTS - { - } - ~LxPoint(); - void CreateRay(LxPoint* lPoint, scaltype tx, scaltype ty, scaltype dtx, scaltype dty); -}; - -#ifdef USE_KALMAN -struct LxKalmanParams { - scaltype tx, ty; - scaltype C11, C22; - scaltype chi2; -}; -#endif //USE_KALMAN - -struct LxRay { - scaltype tx, ty; - scaltype dtx, dty; - LxPoint* source; - LxPoint* end; - LxStation* station; - std::list<LxRay*> neighbours; -#ifdef CLUSTER_MODE - Int_t level; - bool used; - std::list<LxRay*> neighbourhood; - std::list<LxPoint*> clusterPoints; -#endif //CLUSTER_MODE - -#ifdef USE_KALMAN - LxKalmanParams kalman; -#endif //USE_KALMAN - LxRay(LxPoint* s, LxPoint* e -#ifdef CLUSTER_MODE - , - Int_t -#endif //CLUSTER_MODE - ); - LxRay(LxPoint* s, LxPoint* e, scaltype Tx, scaltype Ty, scaltype Dtx, scaltype Dty -#ifdef CLUSTER_MODE - , - Int_t -#endif //CLUSTER_MODE - ); -}; - -struct LxLayer { - std::list<LxPoint*> points; - LxStation* station; - int layerNumber; - scaltype zCoord; - LxLayer(LxStation* st, int lNum); - ~LxLayer(); - void Clear(); - - LxPoint* AddPoint(int hitId, scaltype x, scaltype y, scaltype z, scaltype dx, scaltype dy, scaltype dz, - bool isArtificial = false) - { - LxPoint* result = new LxPoint(x, y, z, dx, dy, dz, this, hitId, isArtificial); - points.push_back(result); - return result; - } - - LxPoint* PickNearestPoint(scaltype x, scaltype y); // Used in track building. - LxPoint* PickNearestPoint(LxRay* ray); // Used in track building. - LxPoint* PickNearestPoint(scaltype x, scaltype y, scaltype deltaX, - scaltype deltaY); // Used in middle point building. - bool HasPointInRange(scaltype x, scaltype y, scaltype deltaX, scaltype deltaY); -}; - -#ifdef CLUSTER_MODE -typedef void* kdt_rays_handle; -#endif //CLUSTER_MODE - -struct LxStation { - std::vector<LxLayer*> layers; -#ifdef CLUSTER_MODE - kdt_rays_handle raysHandle; - std::vector<std::list<LxRay*>*> clusters[2 * LXLAYERS]; - kdt_rays_handle clusteredRaysHandle; - std::list<LxPoint*> clusteredPoints; - scaltype clusterXLimit; - scaltype clusterXLimit2; - scaltype clusterYLimit; - scaltype clusterYLimit2; - scaltype clusterTxLimit; - scaltype clusterTxLimit2; - scaltype clusterTyLimit; - scaltype clusterTyLimit2; -#endif //CLUSTER_MODE - LxSpace* space; - int stationNumber; - scaltype zCoord; - scaltype txLimit; - scaltype tyLimit; - scaltype txBreakLimit; - scaltype tyBreakLimit; - scaltype txBreakSigma; - scaltype tyBreakSigma; - scaltype disp01XSmall; // 'disp' -- means: dispersion. - scaltype disp01XBig; - scaltype disp01YSmall; - scaltype disp01YBig; - scaltype disp02XSmall; - scaltype disp02XBig; - scaltype disp02YSmall; - scaltype disp02YBig; -#ifdef USE_KALMAN_FIT - scaltype MSNoise[2][2][2]; -#endif //USE_KALMAN_FIT - LxStation(LxSpace* sp, int stNum); - ~LxStation(); - void Clear(); - - LxPoint* AddPoint(int layerNumber, int hitId, scaltype x, scaltype y, scaltype z, scaltype dx, scaltype dy, - scaltype dz) - { - return layers[layerNumber]->AddPoint(hitId, x, y, z, dx, dy, dz); - } - - void RestoreMiddlePoints(); - void BuildRays(); -#ifdef CLUSTER_MODE - void BuildRays2(); - void InsertClusterRay(Int_t levels, Int_t cardinality, LxRay* clusterRay); -#endif //CLUSTER_MODE - void ConnectNeighbours(); -}; - -struct LxExtTrack { - CbmStsTrack* track; - Int_t extId; - LxMCTrack* mcTrack; -#ifdef LX_EXT_LINK_SOPH - std::pair<LxTrack*, scaltype> recoTrack; -#endif //LX_EXT_LINK_SOPH - - LxExtTrack() - : track(0) - , extId(-1) - , mcTrack(0) -#ifdef LX_EXT_LINK_SOPH - , recoTrack(0, 0) -#endif //LX_EXT_LINK_SOPH - { - } -}; - -struct LxTrack { - LxExtTrack* externalTrack; -#ifdef LX_EXT_LINK_SOPH - std::list<std::pair<LxExtTrack*, scaltype>> extTrackCandidates; -#else //LX_EXT_LINK_SOPH - scaltype extLinkChi2; -#endif //LX_EXT_LINK_SOPH - bool matched; - LxMCTrack* mcTrack; -#ifdef CALC_LINK_WITH_STS_EFF - std::list<LxMCTrack*> mcTracks; -#endif //CALC_LINK_WITH_STS_EFF - int length; - LxRay* rays[LXSTATIONS - 1]; // Rays are stored left to right. - LxPoint* points[LXSTATIONS * LXLAYERS]; - scaltype chi2; - scaltype aX; - scaltype bX; - scaltype aY; - scaltype bY; - int restoredPoints; -#ifdef USE_KALMAN_FIT - scaltype x, y, z, dx, dy, tx, ty, dtx, dty; -#endif //USE_KALMAN_FIT - bool clone; - // The following variables used in triggering: - bool distanceOk; - bool oppCharged; - bool triggering; - // . - - explicit LxTrack(LxTrackCandidate* tc); - void Fit(); -#ifdef LX_EXT_LINK_SOPH - void Rebind(); -#endif //LX_EXT_LINK_SOPH -}; - -typedef scaltype scal_coords[LXLAYERS][LXMAXPOINTSONSTATION]; -typedef scaltype scal_tans[LXMAXPOINTSONSTATION]; - -struct LxSpace { - scal_coords* x_coords; - scal_tans* tx_vals; - scal_coords* x_errs; - scal_coords* y_coords; - scal_tans* ty_vals; - scal_coords* y_errs; - scal_coords* z_coords; - LxPoint* point_refs[LXSTATIONS][LXLAYERS][LXMAXPOINTSONSTATION]; - bool use_points[LXSTATIONS - 1][LXMAXPOINTSONSTATION]; - int points_counts[LXSTATIONS][LXLAYERS]; - void InitGlobalCAArrays(); - void CalcTangents(int station_number); - void BuildRaysGlobal(); - void RefineMiddlePoints(); - - std::vector<LxStation*> stations; - std::list<LxTrack*> tracks; - std::list<LxExtTrack> extTracks; - scaltype muchStsBreakX; - scaltype muchStsBreakY; - scaltype muchStsBreakTx; - scaltype muchStsBreakTy; - - Int_t stationsInAlgo; - - LxSpace(); - ~LxSpace(); - void Clear(); - - LxPoint* AddPoint(int stationNumber, int layerNumber, int hitId, scaltype x, scaltype y, scaltype z, scaltype dx, - scaltype dy, scaltype dz) - { - return stations[stationNumber]->AddPoint(layerNumber, hitId, x, y, z, dx, dy, dz); - } - - void RestoreMiddlePoints(); - void BuildRays(); -#ifdef CLUSTER_MODE - void BuildRays2(); - void ConnectNeighbours2(); - void BuildCandidates2(LxRay* ray, LxRay** rays, std::list<LxTrackCandidate*>& candidates, scaltype chi2); - void Reconstruct2(); -#endif //CLUSTER_MODE - void ConnectNeighbours(); - void BuildCandidates(int endStNum, LxRay* ray, LxRay** rays, std::list<LxTrackCandidate*>& candidates, scaltype chi2); - void Reconstruct(); - void RemoveClones(); - void FitTracks(); - void JoinExtTracks(); - void CheckArray(scaltype xs[LXSTATIONS][LXLAYERS], scaltype ys[LXSTATIONS][LXLAYERS], - scaltype zs[LXSTATIONS][LXLAYERS], scaltype xDisp2Limits[LXSTATIONS], - scaltype yDisp2Limits[LXSTATIONS], scaltype tx2Limits[LXSTATIONS], scaltype ty2Limits[LXSTATIONS], - scaltype txBreak2Limits[LXSTATIONS], scaltype tyBreak2Limits[LXSTATIONS]); - void CheckArray(scaltype xs[LXSTATIONS][LXLAYERS], scaltype ys[LXSTATIONS][LXLAYERS], - scaltype zs[LXSTATIONS][LXLAYERS], std::list<LxPoint*> pts[LXSTATIONS][LXLAYERS], int level, - scaltype xDisp2Limits[LXSTATIONS], scaltype yDisp2Limits[LXSTATIONS], scaltype tx2Limits[LXSTATIONS], - scaltype ty2Limits[LXSTATIONS], scaltype txBreak2Limits[LXSTATIONS], - scaltype tyBreak2Limits[LXSTATIONS]); - void CheckArray(std::ostream& out, LxMCTrack& track); -}; - -#endif //LXCA_INCLUDED diff --git a/reco/tracking/lx/Simple/LxDraw.cxx b/reco/tracking/lx/Simple/LxDraw.cxx deleted file mode 100644 index adc2bff246494580a06b298766164ebf651e6dc8..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/Simple/LxDraw.cxx +++ /dev/null @@ -1,936 +0,0 @@ -/* Copyright (C) 2014-2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#include "LxDraw.h" - -#include "CbmKF.h" - -#include "TEllipse.h" -#include "TGeoArb8.h" -#include "TGeoBoolNode.h" -#include "TGeoCompositeShape.h" -#include "TGeoCone.h" -#include "TGeoManager.h" -#include "TLatex.h" -#include "TLine.h" -#include "TMCProcess.h" -#include "TMarker.h" -#include "TPolyLine.h" -#include "TPolyMarker.h" -#include "TStyle.h" - -#include <iostream> - -#include <math.h> -#include <stdlib.h> -#include <unistd.h> - -#include "Lx.h" - -#ifdef CLUSTER_MODE -#include "kdtree++/kdtree.hpp" -#endif //CLUSTER_MODE - -#define USE_MUCH_ABSORBER - -using namespace std; - -static int StaColour = 17; - -LxDraw::LxDraw() - : YZ("YZ", "YZ Side View", -10, -50, 650, 1000) - , YX("YX", "YX Front View", -500, 0, 1000, 1000) - , XZ("XZ", "XZ Top View", -10, -50, 650, 1000) - , ask(true) -{ - gStyle->SetCanvasBorderMode(0); - gStyle->SetCanvasBorderSize(1); - gStyle->SetCanvasColor(0); - - YZ.Range(-15.0, -300.0, 600.0, 300.0); - YZ.Draw(); - YZ.Update(); - - XZ.Range(-15.0, -300.0, 600.0, 300.0); - XZ.Draw(); - XZ.Update(); - - YX.Range(-300.0, -300.0, 300.0, 300.0); - YX.Draw(); - YX.Update(); -} - -void LxDraw::ClearView() -{ - YZ.Clear(); - XZ.Clear(); - YX.Clear(); -} - -void LxDraw::Ask() -{ - char symbol; - - if (ask) { - cout << "ask>"; - - do { - cin.get(symbol); - - if (symbol == 'r') ask = false; - - if (symbol == 'q') exit(1); - } while (symbol != '\n'); - - cout << endl; - } -} - -void LxDraw::DrawMCTracks() -{ - // char buf[128]; - int NRegMCTracks = 0; - LxFinder* finder = LxFinder::Instance(); - TPolyLine pline; - - static int mc_tr_count = 0; - - for (vector<LxMCTrack>::iterator it = finder->MCTracks.begin(); it != finder->MCTracks.end(); ++it) { - LxMCTrack& T = *it; - - //if ((13 != T.pdg && -13 != T.pdg) || T.mother_ID >= 0) - //continue; - - bool mcPointOnSta[18] = {false, false, false, false, false, false, false, false, false, - false, false, false, false, false, false, false, false, false}; - int mcpCount = 0; - - for (vector<LxMCPoint*>::iterator j = T.Points.begin(); j != T.Points.end(); ++j) { - LxMCPoint* pMCPoint = *j; - mcPointOnSta[pMCPoint->stationNumber * 3 + pMCPoint->layerNumber] = true; - ++mcpCount; - } - - bool isRefTrack = true; - - for (int j = 0; j < 15; ++j) { - if (!mcPointOnSta[j]) isRefTrack = false; - } - - if (!isRefTrack) - //if (mcpCount < 15) - continue; - - pline.SetLineColor(kRed); - - if (T.p < 0.5) pline.SetLineColor(kBlue); - - if (T.mother_ID != -1) pline.SetLineColor(8); - - if ((T.mother_ID != -1) && (T.p < 0.5)) pline.SetLineColor(12); - - Double_t z00 = finder->caSpace.stations[0]->zCoord; - Double_t x0 = 0; - Double_t y0 = 0; - Double_t z0 = 0; - Double_t dz0 = 1000; - - double par[6]; - par[0] = T.x; - par[1] = T.y; - par[2] = T.px / T.pz; - par[3] = T.py / T.pz; - par[4] = T.q / T.p; - par[5] = T.z; - - if (T.Points.size() < 1) continue; - - vector<double> lx, ly, lz; - lx.push_back(par[0]); - ly.push_back(par[1]); - lz.push_back(par[5]); - - bool ok = true; - /*cout << "LxDraw: drawing MC track with " << T.stationsWithHits << " hitted stations and " << T.layersWithHits << " hitted layers"; - - if (T.layersWithHits < LXSTATIONS * LXLAYERS) - { - cout << " "; - - for (Int_t j = 0; j < LXSTATIONS; ++j) - { - cout << "["; - - for (Int_t k = 0; k < LXLAYERS; ++k) - { - if (T.hitsOnStations[j][k]) - cout << "x"; - else - cout << "o"; - } - - cout << "]"; - } - } - - cout << endl;*/ - - for (std::vector<LxMCPoint*>::iterator ip = T.Points.begin(); ip != T.Points.end(); ++ip) { - LxMCPoint* p = *ip; - double par1[6]; - par1[0] = p->x; - par1[1] = p->y; - par1[2] = p->px / p->pz; - par1[3] = p->py / p->pz; - par1[4] = p->q / p->p; - par1[5] = p->z; - - double Zfrst = par[5]; - double Zlast = par1[5]; - double step = .5; - - if (step > fabs(Zfrst - Zlast) / 5) step = fabs(Zfrst - Zlast) / 5; - - if (Zlast < par[5]) step = -step; - - while (fabs(par[5] - Zlast) > fabs(step)) { - double znxt = par[5] + step; - CbmKF::Instance()->Propagate(par1, 0, znxt, par1[4]); - CbmKF::Instance()->Propagate(par, 0, znxt, par[4]); - double w = fabs(znxt - Zfrst); - double w1 = fabs(znxt - Zlast); - - if (w + w1 < 1.e-3) { - w = 1; - w1 = 0; - } - - float xl = (w1 * par[0] + w * par1[0]) / (w + w1); - float yl = (w1 * par[1] + w * par1[1]) / (w + w1); - float zl = (w1 * par[5] + w * par1[5]) / (w + w1); - - if (fabs(zl - z00) < dz0) { - x0 = xl; - y0 = yl; - z0 = zl; - dz0 = fabs(zl - z00); - } - - if ((fabs(xl) > 400.0) || (fabs(yl) > 400.0)) { - //cout << "*** track " << NRegMCTracks+1 << " xl = " << xl << ", zl = " << zl << endl; - //cout << "*** track " << NRegMCTracks+1 << " yl = " << yl << ", zl = " << zl << endl; - ok = false; // Timur - continue; // Timur - } - - lx.push_back((w1 * par[0] + w * par1[0]) / (w + w1)); - ly.push_back((w1 * par[1] + w * par1[1]) / (w + w1)); - lz.push_back((w1 * par[5] + w * par1[5]) / (w + w1)); - - if (lx.size() > 200) break; - } - - par[0] = p->x; - par[1] = p->y; - - if (p->pz != 0) { - par[2] = p->px / p->pz; - par[3] = p->py / p->pz; - } - else { - par[2] = 1000 * 1000 * 1000; - par[3] = 1000 * 1000 * 1000; - } - - if (p->p != 0) par[4] = p->q / p->p; - else - par[4] = 1000 * 1000 * 1000; - - par[5] = p->z; - lx.push_back(par[0]); - ly.push_back(par[1]); - lz.push_back(par[5]); - } - - if (ok) { - double max_z = 0, min_z = 500; - - for (vector<double>::iterator i = lz.begin(); i != lz.end(); ++i) { - if (*i > max_z) max_z = *i; - - if (*i < min_z) min_z = *i; - } - - if (min_z < 10 && max_z > 503) ++mc_tr_count; - - NRegMCTracks++; - YZ.cd(); - pline.DrawPolyLine(lx.size(), &(lz[0]), &(ly[0])); - TMarker* xMarker = new TMarker(z0, y0, 30); - xMarker->SetMarkerColor(kRed); - xMarker->Draw(); - XZ.cd(); - pline.DrawPolyLine(lx.size(), &(lz[0]), &(lx[0])); - TMarker* yMarker = new TMarker(z0, x0, 30); - yMarker->SetMarkerColor(kRed); - yMarker->Draw(); - YX.cd(); - pline.DrawPolyLine(lx.size(), &(lx[0]), &(ly[0])); - TMarker* zMarker = new TMarker(x0, y0, 30); - zMarker->SetMarkerColor(kRed); - zMarker->Draw(); - } - } - - cout << "LxDraw: number of registered MC tracks: " << NRegMCTracks << endl; - YZ.cd(); - YZ.Update(); - XZ.cd(); - XZ.Update(); - YX.cd(); - YX.Update(); -} - -void LxDraw::DrawInputHits() -{ - DrawMuch(); - - // Draw hits - int mcolour = 4; - int hitsMStyle = 1; //5; - double HitSize = 1; - LxFinder* finder = LxFinder::Instance(); - LxSpace& lxSpace = finder->caSpace; - - int nhits = 0; - - for (int i = 0; i < 6; ++i) - //for (int i = 0; i < 1; ++i) - { - LxStation* pSt = lxSpace.stations[i]; - - for (int j = 0; j < 3; ++j) - //for (int j = 0; j < 1; ++j) - { - LxLayer* pLa = pSt->layers[j]; - //nhits += static_cast<KDTreePointsType*> (pLa->pointsHandle)->size(); - nhits += pLa->points.size(); - } - } - - scaltype x_poly[nhits], y_poly[nhits], z_poly[nhits]; - scaltype x_poly2[nhits], y_poly2[nhits], z_poly2[nhits]; // Removed. - scaltype x_poly3[nhits], y_poly3[nhits], z_poly3[nhits]; // Restored. - TVector3 pos, err; - int n_poly = 0; - int n_poly2 = 0; - int n_poly3 = 0; - - for (int i = 5; i >= 0; --i) - //for (int i = 0; i >= 0; --i) - { - LxStation* pSt = lxSpace.stations[i]; - - for (int j = 2; j >= 0; --j) - //for (int j = 1; j >= 1; --j) - { - LxLayer* pLa = pSt->layers[j]; - - //for (KDTreePointsType::iterator k = static_cast<KDTreePointsType*> (pLa->pointsHandle)->begin(); k != static_cast<KDTreePointsType*> (pLa->pointsHandle)->end(); ++k) - for (list<LxPoint*>::iterator k = pLa->points.begin(); k != pLa->points.end(); ++k) { - LxPoint* pPo = *k; - - if (pPo->artificial) { - x_poly3[n_poly3] = pPo->x; - y_poly3[n_poly3] = pPo->y; - z_poly3[n_poly3] = pPo->z; - ++n_poly3; - } - else if (!pPo->valid) { - x_poly2[n_poly2] = pPo->x; - y_poly2[n_poly2] = pPo->y; - z_poly2[n_poly2] = pPo->z; - ++n_poly2; - } - else { - x_poly[n_poly] = pPo->x; - y_poly[n_poly] = pPo->y; - z_poly[n_poly] = pPo->z; - ++n_poly; - } - } - } - } - - YZ.cd(); - - TPolyMarker* pmyz = new TPolyMarker(n_poly, z_poly, y_poly); - pmyz->SetMarkerColor(mcolour); - pmyz->SetMarkerStyle(hitsMStyle); - pmyz->SetMarkerSize(HitSize); - pmyz->Draw(); - - TPolyMarker* pmyz2 = new TPolyMarker(n_poly2, z_poly2, y_poly2); - pmyz2->SetMarkerColor(2); - pmyz2->SetMarkerStyle(hitsMStyle); - pmyz2->SetMarkerSize(HitSize); - pmyz2->Draw(); - - TPolyMarker* pmyz3 = new TPolyMarker(n_poly3, z_poly3, y_poly3); - pmyz3->SetMarkerColor(3); - pmyz3->SetMarkerStyle(hitsMStyle); - pmyz3->SetMarkerSize(HitSize); - pmyz3->Draw(); - - XZ.cd(); - - TPolyMarker* pmxz = new TPolyMarker(n_poly, z_poly, x_poly); - pmxz->SetMarkerColor(mcolour); - pmxz->SetMarkerStyle(hitsMStyle); - pmxz->SetMarkerSize(HitSize); - pmxz->Draw(); - - TPolyMarker* pmxz2 = new TPolyMarker(n_poly2, z_poly2, x_poly2); - pmxz2->SetMarkerColor(2); - pmxz2->SetMarkerStyle(hitsMStyle); - pmxz2->SetMarkerSize(HitSize); - pmxz2->Draw(); - - TPolyMarker* pmxz3 = new TPolyMarker(n_poly3, z_poly3, x_poly3); - pmxz3->SetMarkerColor(3); - pmxz3->SetMarkerStyle(hitsMStyle); - pmxz3->SetMarkerSize(HitSize); - pmxz3->Draw(); - - YX.cd(); - - TPolyMarker* pmyx = new TPolyMarker(n_poly, x_poly, y_poly); - pmyx->SetMarkerColor(mcolour); - pmyx->SetMarkerStyle(hitsMStyle); - pmyx->SetMarkerSize(HitSize); - pmyx->Draw(); - - TPolyMarker* pmyx2 = new TPolyMarker(n_poly2, x_poly2, y_poly2); - pmyx2->SetMarkerColor(2); - pmyx2->SetMarkerStyle(hitsMStyle); - pmyx2->SetMarkerSize(HitSize); - pmyx2->Draw(); - - TPolyMarker* pmyx3 = new TPolyMarker(n_poly3, x_poly3, y_poly3); - pmyx3->SetMarkerColor(3); - pmyx3->SetMarkerStyle(hitsMStyle); - pmyx3->SetMarkerSize(HitSize); - pmyx3->Draw(); -} - -void LxDraw::DrawMuch(TGeoNode* node) -{ - TObjArray* children; - TObject* childO; - - if (0 != strstr(node->GetName(), "active")) { - TGeoCompositeShape* cs = dynamic_cast<TGeoCompositeShape*>(node->GetVolume()->GetShape()); - - if (cs) { - TGeoBoolNode* bn = cs->GetBoolNode(); - TGeoTrap* trap = dynamic_cast<TGeoTrap*>(bn->GetLeftShape()); - - if (trap) { - scaltype minY = 0, maxY = 0, minX = 0, maxX = 0, Z = 0; - Double_t* xy = trap->GetVertices(); - scaltype trapX[5]; - scaltype trapY[5]; - - for (int i = 0; i < 4; ++i) { - Double_t localCoords[3] = {xy[2 * i], xy[2 * i + 1], 0.}; - Double_t globalCoords[3]; - gGeoManager->LocalToMaster(localCoords, globalCoords); - - if (minY > globalCoords[1]) minY = globalCoords[1]; - - if (maxY < globalCoords[1]) maxY = globalCoords[1]; - - if (minX > globalCoords[0]) minX = globalCoords[0]; - - if (maxX < globalCoords[0]) maxX = globalCoords[0]; - - Z = globalCoords[2]; - trapX[i] = globalCoords[0]; - trapY[i] = globalCoords[1]; - } - - trapX[4] = trapX[0]; - trapY[4] = trapY[0]; - - YZ.cd(); - TLine* line = new TLine(); - line->SetLineColor(StaColour); - line->DrawLine(Z, minY, Z, maxY); - - XZ.cd(); - line->DrawLine(Z, minX, Z, maxX); - - YX.cd(); - TPolyLine* pline = new TPolyLine(5, trapX, trapY); - pline->SetFillColor(StaColour); - pline->SetLineColor(kCyan + 4); - pline->SetLineWidth(1); - pline->Draw("f"); - pline->Draw(); - } - } - - goto exit; - } - - children = node->GetNodes(); - - if (0 == children) goto exit; - - childO = children->First(); - - while (childO) { - TGeoNode* child = dynamic_cast<TGeoNode*>(childO); - - if ( - child) // Commented because this version on CdDown() is not supported in older versions on ROOT. Possibly should be fixed. - { - gGeoManager->GetCurrentNavigator()->CdDown(child); - DrawMuch(child); - } - - childO = children->After(childO); - } - -exit: - gGeoManager->CdUp(); -} - -void LxDraw::DrawMuch() -{ - TLatex latex; - latex.SetTextFont(132); - latex.SetTextAlign(12); - latex.SetTextSize(0.035); - - YZ.cd(); - latex.DrawLatex(0.0, 250.0, "YZ Side View"); - YZ.Draw(); - - XZ.cd(); - latex.DrawLatex(0.0, 250.0, "XZ Top View"); - XZ.Draw(); - - YX.cd(); - latex.DrawLatex(-270.0, 250.0, "YX Front View"); - YX.Draw(); - - for (int i = 6; i > 0; --i) { - char buf[128]; - // Draw 3 layers of the much station - //if (i < 7) - { - sprintf(buf, "/cave_1/much_0/muchstation0%d_0", i); - gGeoManager->cd(buf); - DrawMuch(gGeoManager->GetCurrentNode()); - } -#ifdef USE_MUCH_ABSORBER - // Draw an absorber - sprintf(buf, "/cave_1/much_0/muchabsorber0%d_0", i); - gGeoManager->cd(buf); - Double_t localCoords[3] = {0., 0., 0.}; - Double_t globalCoords[3]; - gGeoManager->LocalToMaster(localCoords, globalCoords); - TGeoVolume* muchAbsVol = gGeoManager->GetCurrentVolume(); - TGeoShape* muchAbsShape = muchAbsVol->GetShape(); - TGeoCone* muchAbsCone = dynamic_cast<TGeoCone*>(muchAbsShape); - - scaltype fRmax1 = muchAbsCone->GetRmax1(); - scaltype fRmax2 = muchAbsCone->GetRmax2(); - scaltype fDz = muchAbsCone->GetDz(); - scaltype fZ = globalCoords[2]; - - scaltype maXs[5] = {fZ - fDz, fZ - fDz, fZ + fDz, fZ + fDz, fZ - fDz}; - scaltype maYs[5] = {-fRmax1, fRmax1, fRmax2, -fRmax2, -fRmax1}; - TPolyLine* muchAbsorber = new TPolyLine(5, maXs, maYs); - muchAbsorber->SetFillColor(kYellow); - muchAbsorber->SetLineColor(kYellow); - muchAbsorber->SetLineWidth(1); - YZ.cd(); - muchAbsorber->Draw("f"); - muchAbsorber->Draw(); - XZ.cd(); - muchAbsorber->Draw("f"); - muchAbsorber->Draw(); - YX.cd(); - TEllipse* ellipse = new TEllipse(0.0, 0.0, fRmax2); - ellipse->SetFillColor(kYellow); - ellipse->SetLineColor(kYellow); - ellipse->SetLineWidth(1); - ellipse->SetFillStyle(3002); - ellipse->Draw("f"); - ellipse->Draw(); - TEllipse* ellipseInner = new TEllipse(0.0, 0.0, fRmax1); - ellipseInner->SetFillColor(kYellow - 7); - ellipseInner->SetLineColor(kYellow - 7); - ellipseInner->SetLineWidth(1); - ellipseInner->SetFillStyle(3002); - ellipseInner->Draw("f"); - ellipseInner->Draw(); -#endif //USE_MUCH_ABSORBER - } -} - -#ifdef CLUSTER_MODE -struct KDRayWrap { - LxRay* ray; - scaltype data[4]; - static bool destroyRays; - - KDRayWrap(scaltype x, scaltype y, LxRay* r) : ray(r) - { - data[0] = x; - data[1] = y; - data[2] = ray->tx; - data[3] = ray->ty; - } - - KDRayWrap(scaltype x, scaltype y, scaltype tx, scaltype ty) - : ray(0) // This constructor is used when setting search-range bounds. - { - data[0] = x; - data[1] = y; - data[2] = tx; - data[3] = ty; - } - - ~KDRayWrap() - { - if (destroyRays) delete ray; - } - - // Stuff required by libkdtree++ - typedef scaltype value_type; - - value_type operator[](size_t n) const { return data[n]; } -}; - -//bool KDRayWrap::destroyRays = false; - -typedef KDTree::KDTree<4, KDRayWrap> KDRaysStorageType; -#endif //CLUSTER_MODE - -void LxDraw::DrawRays() -{ - LxFinder* finder = LxFinder::Instance(); - LxSpace& caSpace = finder->caSpace; - int stationsNumber = caSpace.stations.size(); - - for (Int_t i = stationsNumber - 1; i > 0; --i) { - LxStation* rSt = caSpace.stations[i]; -#ifdef CLUSTER_MODE - KDRaysStorageType* rays = static_cast<KDRaysStorageType*>(rSt->clusteredRaysHandle); - scaltype lZ = caSpace.stations[i - 1]->zCoord; - - for (KDRaysStorageType::iterator j = rays->begin(); j != rays->end(); ++j) { - KDRayWrap& wrap = const_cast<KDRayWrap&>(*j); - LxRay* ray = wrap.ray; - LxPoint* rPo = ray->source; - scaltype deltaZ = lZ - rPo->z; - scaltype lX = rPo->x + ray->tx * deltaZ; - scaltype lY = rPo->y + ray->ty * deltaZ; - - YZ.cd(); - TLine* yzLine = new TLine(rPo->z, rPo->y, lZ, lY); - yzLine->SetLineColor(kRed); - yzLine->Draw(); - - XZ.cd(); - TLine* xzLine = new TLine(rPo->z, rPo->x, lZ, lX); - xzLine->SetLineColor(kRed); - xzLine->Draw(); - - YX.cd(); - TLine* yxLine = new TLine(rPo->x, rPo->y, lX, lY); - yxLine->SetLineColor(kRed); - yxLine->Draw(); - } -#else //CLUSTER_MODE - LxLayer* rLa = rSt->layers[0]; - LxStation* lSt = caSpace.stations[i - 1]; - int lLaInd = lSt->layers.size() - 1; - LxLayer* lLa = lSt->layers[lLaInd]; - - if (rLa->points.size() == 0 || lLa->points.size() == 0) continue; - - scaltype lZ = (*lLa->points.begin())->z; - - for (list<LxPoint*>::iterator j = rLa->points.begin(); j != rLa->points.end(); ++j) { - LxPoint* rPo = *j; - scaltype deltaZ = lZ - rPo->z; - - for (list<LxRay*>::iterator k = rPo->rays.begin(); k != rPo->rays.end(); ++k) { - LxRay* ray = *k; - - scaltype lX = rPo->x + ray->tx * deltaZ; - scaltype lY = rPo->y + ray->ty * deltaZ; - - YZ.cd(); - TLine* yzLine = new TLine(rPo->z, rPo->y, lZ, lY); - yzLine->SetLineColor(kRed); - yzLine->Draw(); - - XZ.cd(); - TLine* xzLine = new TLine(rPo->z, rPo->x, lZ, lX); - xzLine->SetLineColor(kRed); - xzLine->Draw(); - - YX.cd(); - TLine* yxLine = new TLine(rPo->x, rPo->y, lX, lY); - yxLine->SetLineColor(kRed); - yxLine->Draw(); - } - } -#endif //CLUSTER_MODE - } - - YZ.cd(); - YZ.Update(); - XZ.cd(); - XZ.Update(); - YX.cd(); - YX.Update(); -} - -void LxDraw::DrawRecoTracks() -{ - LxFinder* finder = LxFinder::Instance(); - LxSpace& caSpace = finder->caSpace; - // int stationsNumber = caSpace.stations.size(); - - for (list<LxTrack*>::iterator i = caSpace.tracks.begin(); i != caSpace.tracks.end(); ++i) { - LxTrack* track = *i; - -#ifdef USE_KALMAN_FIT - bool kalmanDrawn = false; -#endif //USE_KALMAN_FIT - - for (int j = 0; j < track->length; ++j) { - LxRay* ray = track->rays[j]; - - if (0 == ray) break; - - scaltype rX = ray->source->x; - scaltype rY = ray->source->y; - scaltype rZ = ray->source->z; - - scaltype lZ = caSpace.stations[ray->station->stationNumber - 1]->zCoord; - scaltype deltaZ = lZ - rZ; - scaltype lX = rX + ray->tx * deltaZ; - scaltype lY = rY + ray->ty * deltaZ; - -#ifdef USE_KALMAN_FIT - scaltype kalmanZl = track->z; - scaltype kalmanXl = track->x; - scaltype kalmanYl = track->y; - scaltype kalmanZr = ray->source->z; - scaltype kalmanXr = kalmanXl + track->tx * (kalmanZr - kalmanZl); - scaltype kalmanYr = kalmanYl + track->ty * (kalmanZr - kalmanZl); -#endif //USE_KALMAN_FIT - - YZ.cd(); - TLine* yzLineL = new TLine(rZ, rY, lZ, lY); - yzLineL->SetLineColor(kBlue); - yzLineL->Draw(); - -#ifdef USE_KALMAN_FIT - if (!kalmanDrawn) { - TLine* kalmanYZLine = new TLine(kalmanZr, kalmanYr, kalmanZl, kalmanYl); - kalmanYZLine->SetLineColor(kBlack); - kalmanYZLine->Draw(); - } -#endif //USE_KALMAN_FIT - - XZ.cd(); - TLine* xzLineL = new TLine(rZ, rX, lZ, lX); - xzLineL->SetLineColor(kBlue); - xzLineL->Draw(); - -#ifdef USE_KALMAN_FIT - if (!kalmanDrawn) { - TLine* kalmanXZLine = new TLine(kalmanZr, kalmanXr, kalmanZl, kalmanXl); - kalmanXZLine->SetLineColor(kBlack); - kalmanXZLine->Draw(); - } -#endif //USE_KALMAN_FIT - - YX.cd(); - TLine* yxLineL = new TLine(rX, rY, lX, lY); - yxLineL->SetLineColor(kBlue); - yxLineL->Draw(); - -#ifdef USE_KALMAN_FIT - if (!kalmanDrawn) { - TLine* kalmanYXLine = new TLine(kalmanXr, kalmanYr, kalmanXl, kalmanYl); - kalmanYXLine->SetLineColor(kBlack); - kalmanYXLine->Draw(); - } -#endif //USE_KALMAN_FIT - -#ifdef USE_KALMAN_FIT - kalmanDrawn = true; -#endif //USE_KALMAN_FIT - } - - // Draw a segment of an external track if it is set. - - //if (track->externalTrack) - if (false) { - scaltype rZ = caSpace.stations[0]->layers[0]->zCoord; - const FairTrackParam* param = track->externalTrack->track->GetParamLast(); - - scaltype lX = param->GetX(); - scaltype lY = param->GetY(); - scaltype lZ = param->GetZ(); - scaltype deltaZ = rZ - lZ; - scaltype rX = lX + param->GetTx() * deltaZ; - scaltype rY = lY + param->GetTy() * deltaZ; - - YZ.cd(); - TLine* yzLine = new TLine(lZ, lY, rZ, rY); - yzLine->SetLineColor(kPink); - yzLine->Draw(); - - XZ.cd(); - TLine* xzLine = new TLine(lZ, lX, rZ, rX); - xzLine->SetLineColor(kPink); - xzLine->Draw(); - - YX.cd(); - TLine* yxLine = new TLine(lX, lY, rX, rY); - yxLine->SetLineColor(kPink); - yxLine->Draw(); - } - } - - YZ.cd(); - YZ.Update(); - XZ.cd(); - XZ.Update(); - YX.cd(); - YX.Update(); -} - -void LxDraw::DrawMCPoints() -{ - int mcolour = 2; - int hitsMStyle = 2; - double HitSize = 1; - LxFinder* finder = LxFinder::Instance(); - - int nhits = finder->MCPoints.size(); - scaltype x_poly[nhits], y_poly[nhits], z_poly[nhits]; - TVector3 pos; - int n_poly = 0; - - for (vector<LxMCPoint>::iterator i = finder->MCPoints.begin(); i != finder->MCPoints.end(); ++i) { - LxMCPoint& point = *i; - - x_poly[n_poly] = point.x; - y_poly[n_poly] = point.y; - z_poly[n_poly] = point.z; - - ++n_poly; - } - - YZ.cd(); - - TPolyMarker* pmyz = new TPolyMarker(n_poly, z_poly, y_poly); - pmyz->SetMarkerColor(mcolour); - pmyz->SetMarkerStyle(hitsMStyle); - pmyz->SetMarkerSize(HitSize); - pmyz->Draw(); - YZ.Update(); - - XZ.cd(); - - TPolyMarker* pmxz = new TPolyMarker(n_poly, z_poly, x_poly); - pmxz->SetMarkerColor(mcolour); - pmxz->SetMarkerStyle(hitsMStyle); - pmxz->SetMarkerSize(HitSize); - pmxz->Draw(); - XZ.Update(); - - YX.cd(); - - TPolyMarker* pmyx = new TPolyMarker(n_poly, x_poly, y_poly); - pmyx->SetMarkerColor(mcolour); - pmyx->SetMarkerStyle(hitsMStyle); - pmyx->SetMarkerSize(HitSize); - pmyx->Draw(); - YX.Update(); -} - -void LxDraw::DrawExtTracks() -{ - LxFinder* finder = LxFinder::Instance(); - LxSpace& caSpace = finder->caSpace; - scaltype rZ = caSpace.stations[0]->layers[0]->zCoord; - - for (list<LxExtTrack>::iterator i = caSpace.extTracks.begin(); i != caSpace.extTracks.end(); ++i) { - LxExtTrack& extTrack = *i; - const FairTrackParam* param = extTrack.track->GetParamLast(); - - scaltype lX = param->GetX(); - scaltype lY = param->GetY(); - scaltype lZ = param->GetZ(); - scaltype deltaZ = rZ - lZ; - scaltype rX = lX + param->GetTx() * deltaZ; - scaltype rY = lY + param->GetTy() * deltaZ; - - YZ.cd(); - TLine* yzLine = new TLine(lZ, lY, rZ, rY); - yzLine->SetLineColor(kPink); - yzLine->Draw(); - - XZ.cd(); - TLine* xzLine = new TLine(lZ, lX, rZ, rX); - xzLine->SetLineColor(kPink); - xzLine->Draw(); - - YX.cd(); - TLine* yxLine = new TLine(lX, lY, rX, rY); - yxLine->SetLineColor(kPink); - yxLine->Draw(); - } - - YZ.cd(); - YZ.Update(); - XZ.cd(); - XZ.Update(); - YX.cd(); - YX.Update(); -} - -void LxDraw::SaveCanvas(TString name) -{ - system("mkdir LxDraw -p"); - chdir("LxDraw"); - TString tmp = name; - tmp += "YXView.pdf"; - YX.cd(); - YX.SaveAs(tmp); - - tmp = name; - tmp += "XZView.pdf"; - XZ.cd(); - XZ.SaveAs(tmp); - - tmp = name; - tmp += "YZView.pdf"; - YZ.cd(); - YZ.SaveAs(tmp); - - chdir(".."); -} diff --git a/reco/tracking/lx/Simple/LxDraw.h b/reco/tracking/lx/Simple/LxDraw.h deleted file mode 100644 index 40afe21546436e8505f3279868a133673b13a343..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/Simple/LxDraw.h +++ /dev/null @@ -1,35 +0,0 @@ -/* Copyright (C) 2014 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifndef LXDRAW_INCLUDED -#define LXDRAW_INCLUDED - -#pragma GCC diagnostic ignored "-Weffc++" - -#include "TCanvas.h" -#include "TGeoNode.h" - -class LxDraw { -public: - LxDraw(); - void ClearView(); - void Ask(); - void DrawMCTracks(); - void DrawInputHits(); - void DrawMuch(TGeoNode* node); - void DrawMuch(); - void DrawRays(); - void DrawRecoTracks(); - void DrawMCPoints(); - void DrawExtTracks(); - void SaveCanvas(TString name); - -private: - TCanvas YZ; - TCanvas YX; - TCanvas XZ; - bool ask; -}; - -#endif //LXDRAW_INCLUDED diff --git a/reco/tracking/lx/Simple/LxEff.cxx b/reco/tracking/lx/Simple/LxEff.cxx deleted file mode 100644 index 7794dea966f8fe4d0f92383e4c59bf8ad9c0388a..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/Simple/LxEff.cxx +++ /dev/null @@ -1,284 +0,0 @@ -/* Copyright (C) 2014-2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#include "Lx.h" -#ifdef MAKE_EFF_CALC -//#include <cmath> -#include <iostream> - -using namespace std; - -void LxFinder::MatchMCToReco() -{ - static Int_t referenceMCTracks = 0; - static Int_t reconstructedRefTracks = 0; - bool hasPositiveSignalMuon = false; - bool hasNegativeSignalMuon = false; - hasSignalInEvent = false; - - for (vector<LxMCTrack>::iterator i = MCTracks.begin(); i != MCTracks.end(); ++i) { - LxMCTrack& mcTrack = *i; - Int_t pdgCode = mcTrack.pdg; - map<LxTrack*, Int_t> recoTracks; // Mapped value is the number of common points in MC and reconstructed tracks. - memset(mcTrack.hitsOnStations, 0, sizeof(mcTrack.hitsOnStations)); - bool isSignal = true; - //list<LxPoint*> mcTrackHits[LXSTATIONS][LXLAYERS]; - bool mcTrackMCPoints[LXSTATIONS][LXLAYERS]; - memset(mcTrackMCPoints, 0, sizeof(mcTrackMCPoints)); - - for (vector<LxMCPoint*>::iterator j = mcTrack.Points.begin(); j != mcTrack.Points.end(); ++j) { - LxMCPoint* pMCPoint = *j; - mcTrackMCPoints[pMCPoint->stationNumber][pMCPoint->layerNumber] = true; - - for (list<LxPoint*>::iterator k = pMCPoint->lxPoints.begin(); k != pMCPoint->lxPoints.end(); ++k) { - LxPoint* point = *k; - mcTrack.hitsOnStations[point->layer->station->stationNumber][point->layer->layerNumber] = true; - //mcTrackHits[point->layer->station->stationNumber][point->layer->layerNumber].push_back(point); - LxTrack* track = point->track; - - if (0 == track) continue; - - if (track->matched) continue; - - if (track->clone) continue; - - map<LxTrack*, int>::iterator l = recoTracks.find(track); - - if (l != recoTracks.end()) ++(l->second); - else - recoTracks[track] = 1; - } // for (list<LxPoint*>::iterator k = pMCPoint->lxPoints.begin(); k != pMCPoint->lxPoints.end(); ++k) - } // for (vector<LxMCPoint*>::iterator j = mcTrack.Points.begin(); j != mcTrack.Points.end(); ++j) - - bool enoughHits = true; - bool enoughMCPoints = true; - mcTrack.stationsWithHits = 0; - mcTrack.layersWithHits = 0; - Int_t mcpCount = 0; - - for (Int_t j = 0; j < LXSTATIONS; ++j) { - Int_t hitsOnSt = 0; - Int_t mcpOnSt = 0; - - for (Int_t k = 0; k < LXLAYERS; ++k) { - if (mcTrack.hitsOnStations[j][k]) { - ++hitsOnSt; - ++mcTrack.layersWithHits; - } - - if (mcTrackMCPoints[j][k]) { - ++mcpOnSt; - ++mcpCount; - } - } // for (Int_t k = 0; k < LXLAYERS; ++k) - - if (hitsOnSt < LXLAYERS) { - if (j < caSpace.stationsInAlgo) enoughHits = false; - } - else - ++mcTrack.stationsWithHits; - - if (j < caSpace.stationsInAlgo && mcpOnSt < LXLAYERS) enoughMCPoints = false; - } // for (Int_t j = 0; j < LXSTATIONS; ++j) - - scaltype pt2 = mcTrack.px * mcTrack.px + mcTrack.py * mcTrack.py; - - if (!enoughMCPoints || mcTrack.mother_ID >= 0 || (pdgCode != 13 && pdgCode != -13) - || (pPtCut && (mcTrack.p < 3.0 || pt2 < 1.0))) - isSignal = false; - else - ++referenceMCTracks; - - if (!isSignal) continue; - - if (-13 == pdgCode) hasPositiveSignalMuon = true; - else - hasNegativeSignalMuon = true; - - LxTrack* matchTrack = 0; - Int_t matchedPoints = 0; - - for (map<LxTrack*, Int_t>::iterator j = recoTracks.begin(); j != recoTracks.end(); ++j) { - if (0 == matchTrack || matchedPoints < j->second + j->first->restoredPoints) { - matchTrack = j->first; - matchedPoints = j->second + j->first->restoredPoints; - } - } - - if (0 == matchTrack) continue; - - if (matchedPoints < mcpCount * 0.7) continue; - - ++reconstructedRefTracks; - } // for (vector<LxMCTrack>::iterator i = MCTracks.begin(); i != MCTracks.end(); ++i) - - if (hasPositiveSignalMuon && hasNegativeSignalMuon) { - hasSignalInEvent = true; - ++signalCounter; - } - - Double_t result = 100 * reconstructedRefTracks; - result /= referenceMCTracks; - cout << "LxFinder::MatchMCToReco(): efficiency = " << result << "% (" << reconstructedRefTracks << "/" - << referenceMCTracks << ")" << endl; -} // void LxFinder::MatchMCToReco() - -void LxFinder::MatchRecoToMC() -{ - static Int_t recoTracksCount = 0; - static Int_t matchedTracksCount = 0; - LxTrack* signalMuPlus = 0; - LxTrack* signalMuMinus = 0; - list<LxTrack*> bgrMuPlusTracks; - list<LxTrack*> bgrMuMinusTracks; - - for (list<LxTrack*>::iterator i = caSpace.tracks.begin(); i != caSpace.tracks.end(); ++i) { - LxTrack* recoTrack = *i; - - if (recoTrack->clone) continue; - - ++recoTracksCount; - - map<LxMCTrack*, Int_t> mcTracks; - - for (Int_t j = 0; j < LXSTATIONS * LXLAYERS; ++j) { - LxPoint* recoPoint = recoTrack->points[j]; - - if (0 == recoPoint) continue; - - for (list<LxMCPoint*>::iterator k = recoPoint->mcPoints.begin(); k != recoPoint->mcPoints.end(); ++k) { - LxMCPoint* mcPoint = *k; - LxMCTrack* mcTrack = mcPoint->track; - - if (0 == mcTrack) continue; - - map<LxMCTrack*, Int_t>::iterator mcIter = mcTracks.find(mcTrack); - - if (mcIter == mcTracks.end()) mcTracks[mcTrack] = 1; - else - ++(mcIter->second); - } - } // for (Int_t j = 0; j < LXSTATIONS * LXLAYERS; ++j) - - LxMCTrack* bestMatch = 0; - Int_t matchedPoints = 0; - - for (map<LxMCTrack*, Int_t>::iterator j = mcTracks.begin(); j != mcTracks.end(); ++j) { - if (0 == bestMatch || j->second > matchedPoints) { - bestMatch = j->first; - matchedPoints = j->second; - } - } - - if (0 == bestMatch) continue; - - Int_t recoPoints = 0; - - for (Int_t j = 0; j < LXSTATIONS * LXLAYERS; ++j) { - LxPoint* recoPoint = recoTrack->points[j]; - - if (0 != recoPoint) ++recoPoints; - } - - if (matchedPoints < 0.7 * recoPoints) continue; - - ++matchedTracksCount; - - LxRay* ray0 = recoTrack->rays[0]; - LxPoint* point0 = ray0->end; - scaltype x0 = point0->x - point0->z * ray0->tx; - scaltype y0 = point0->y - point0->z * ray0->ty; - - if (0 != bestMatch && bestMatch->mother_ID < 0 && (-13 == bestMatch->pdg || 13 == bestMatch->pdg)) { - signalXAtZ0->Fill(x0); - signalYAtZ0->Fill(y0); - - if (-13 == bestMatch->pdg) signalMuPlus = recoTrack; - else - signalMuMinus = recoTrack; - } - else { - bgrXAtZ0->Fill(x0); - bgrYAtZ0->Fill(y0); - scaltype charge = ray0->tx - point0->x / point0->z; - - if (charge > 0) bgrMuPlusTracks.push_back(recoTrack); - else if (charge < 0) - bgrMuMinusTracks.push_back(recoTrack); - } - } // for (list<LxTrack*>::iterator i = caSpace.tracks.begin(); i != caSpace.tracks.end(); ++i) - - Double_t result = 100 * matchedTracksCount; - result /= recoTracksCount; - cout << "LxFinder::MatchRecoToMC(): efficiency = " << result << "% (" << matchedTracksCount << "/" << recoTracksCount - << ")" << endl; - - if (0 != signalMuPlus && 0 != signalMuMinus) { - scaltype x1 = signalMuPlus->rays[0]->end->x; - scaltype y1 = signalMuPlus->rays[0]->end->y; - scaltype z1 = signalMuPlus->rays[0]->end->z; - scaltype x2 = signalMuMinus->rays[0]->end->x; - scaltype y2 = signalMuMinus->rays[0]->end->y; - scaltype z2 = signalMuMinus->rays[0]->end->z; - scaltype deltaX = x1 - x2; - scaltype deltaY = y1 - y2; - scaltype deltaZ = z1 - z2; - scaltype d = sqrt(deltaX * deltaX + deltaY * deltaY); - signalInterTracksDistanceOn1st->Fill(d); - scaltype aSq = x1 * x1 + y1 * y1 + z1 * z1; - scaltype a = sqrt(aSq); - scaltype bSq = x2 * x2 + y2 * y2 + z2 * z2; - scaltype b = sqrt(bSq); - scaltype cSq = deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ; - scaltype cosC = (aSq + bSq - cSq) / (2 * a * b); - scaltype C = acos(cosC); - C *= 180; - C /= 3.14159265; - signalInterTracksAngle->Fill(C); - signalInterTrackCorrDA->Fill(d, C); - } // if (0 != signalMuPlus && 0 != signalMuMinus) - - scaltype bgrMuDistSq = 0; - scaltype bgrMuAngle = 0; - - for (list<LxTrack*>::iterator i = bgrMuPlusTracks.begin(); i != bgrMuPlusTracks.end(); ++i) { - LxTrack* mupt = *i; - scaltype x1 = mupt->rays[0]->end->x; - scaltype y1 = mupt->rays[0]->end->y; - scaltype z1 = mupt->rays[0]->end->z; - - for (list<LxTrack*>::iterator j = bgrMuMinusTracks.begin(); j != bgrMuMinusTracks.end(); ++j) { - LxTrack* mumt = *j; - scaltype x2 = mumt->rays[0]->end->x; - scaltype y2 = mumt->rays[0]->end->y; - scaltype z2 = mumt->rays[0]->end->z; - scaltype deltaX = x1 - x2; - scaltype deltaY = y1 - y2; - scaltype deltaZ = z1 - z2; - scaltype dSq = deltaX * deltaX + deltaY * deltaY; - - if (dSq > bgrMuDistSq) bgrMuDistSq = dSq; - - scaltype aSq = x1 * x1 + y1 * y1 + z1 * z1; - scaltype a = sqrt(aSq); - scaltype bSq = x2 * x2 + y2 * y2 + z2 * z2; - scaltype b = sqrt(bSq); - scaltype cSq = deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ; - scaltype cosC = (aSq + bSq - cSq) / (2 * a * b); - scaltype C = acos(cosC); - C *= 180; - C /= 3.14159265; - - if (C > bgrMuAngle) bgrMuAngle = C; - } // for (list<LxTrack*>::iterator j = bgrMuMinusTracks.begin(); j != bgrMuMinusTracks.end(); ++j) - } // for (list<LxTrack*>::iterator i = bgrMuPlusTracks.begin(); i != bgrMuPlusTracks.end(); ++i) - - if (bgrMuDistSq > 0) bgrInterTracksDistanceOn1st->Fill(sqrt(bgrMuDistSq)); - - if (bgrMuAngle > 0) bgrInterTracksAngle->Fill(bgrMuAngle); - - if (bgrMuDistSq > 0 && bgrMuAngle > 0) bgrInterTrackCorrDA->Fill(sqrt(bgrMuDistSq), bgrMuAngle); -} // void LxFinder::MatchRecoToMC() - -#endif //MAKE_EFF_CALC diff --git a/reco/tracking/lx/Simple/LxLinkDef.h b/reco/tracking/lx/Simple/LxLinkDef.h deleted file mode 100644 index 672416a180d8337a471b2dffd378bdeb969ac234..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/Simple/LxLinkDef.h +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright (C) 2014-2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -// $Id: LxLinkDef.h,v 1.10 2013/09/30 11:36:47 tablyaz Exp $ - -#ifdef __CINT__ - -#pragma link off all globals; -#pragma link off all classes; -#pragma link off all functions; - -#pragma link C++ class LxFinder + ; -#pragma link C++ class LxTrackAna + ; - -#ifdef LXPARALL -#pragma link C++ class LxParallFinder + ; -#endif - -#endif diff --git a/reco/tracking/lx/Simple/LxMC.cxx b/reco/tracking/lx/Simple/LxMC.cxx deleted file mode 100644 index 48c866a1a01b7bb8c64f481777aa55c3caebe35d..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/Simple/LxMC.cxx +++ /dev/null @@ -1,5 +0,0 @@ -/* Copyright (C) 2014 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#include "LxMC.h" diff --git a/reco/tracking/lx/Simple/LxMC.h b/reco/tracking/lx/Simple/LxMC.h deleted file mode 100644 index a2781e25a16964bc96cc2d40ded7da8282b7dc5e..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/Simple/LxMC.h +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright (C) 2014-2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifndef LXMC_INCLUDED -#define LXMC_INCLUDED - -#pragma GCC diagnostic ignored "-Weffc++" - -#include "CbmStsTrack.h" - -#include "Rtypes.h" - -#include <list> -#include <vector> - -#include "LxSettings.h" - -struct LxPoint; -struct LxStsMCPoint; -struct LxMCTrack; - -struct LxMCPoint { - scaltype p, q, x, y, z, px, py, pz; - Int_t stationNumber, layerNumber; - std::list<LxPoint*> lxPoints; - Int_t trackId; // Original track id -- an index (offset) in the array of MC tracks. - LxMCTrack* track; - - //LxMCPoint() : p(0), q(0), x(0), y(0), z(0), px(0), py(0), pz(0), stationNumber(0), layerNumber(0), trackId(0), track(0) {} -}; - -struct LxMCTrack { - scaltype p, q, x, y, z, px, py, pz; - Int_t mother_ID; - Int_t pdg; - std::vector<LxMCPoint*> Points; -#ifdef MAKE_STS_MC_RESEARCHES - std::list<LxStsMCPoint*> stsPoints[8]; -#endif //MAKE_STS_MC_RESEARCHES - UInt_t fUniqueID; - CbmStsTrack* externalTrack; - Int_t stationsWithHits; - Int_t layersWithHits; - bool hitsOnStations[LXSTATIONS][LXLAYERS]; - - //LxMCTrack() : p(0), q(0), x(0), y(0), z(0), px(0), py(0), pz(0), mother_ID(0), pdg(0), fUniqueID(0), externalTrack(0), - //stationsWithHits(0), layersWithHits(0) {} -}; - -#endif //LXMC_INCLUDED diff --git a/reco/tracking/lx/Simple/LxParall.cxx b/reco/tracking/lx/Simple/LxParall.cxx deleted file mode 100644 index 7e0fbf7fb38d9ae63679fefc3f783159637e6472..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/Simple/LxParall.cxx +++ /dev/null @@ -1,128 +0,0 @@ -/* Copyright (C) 2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#include "LxParall.h" - -#include <iostream> - -#include <omp.h> -#include <sys/time.h> - -#include "Lx.h" - -using namespace std; - -ClassImp(LxParallFinder) - - LxParallFinder::LxParallFinder() - : generateInvMass(false) - , generateBackground(false) - , generateChi2(false) - , linkWithSts(true) - , useMCPInsteadOfHits(false) - , calcMiddlePoints(true) - , cutCoeff(4.0) - , ev_start(0) - , ev_end(0) - , hitFileName("") -{ -} - -class FinderCapsule { - friend class LxParallFinder; - -public: - FinderCapsule() : finder(0) {} - ~FinderCapsule() - { - if (finder) { - finder->FinishTask(); - delete finder; - } - } - -private: - LxFinder* finder; - FinderCapsule(const FinderCapsule&); - FinderCapsule& operator=(const FinderCapsule&); -}; - -//#define LXPARALL_SEPARATE_SINGLE - -Double_t LxParallFinder::Reconstruct(Int_t numThreads) -{ - omp_set_num_threads(numThreads); - - timeval bTime, eTime; - gettimeofday(&bTime, 0); - - Int_t i; - Int_t createdFinderInstances = 0; - Int_t totalRunTime = 0; - FinderCapsule finderCapsule; - -#ifdef LXPARALL_SEPARATE_SINGLE - if (1 == numThreads) { - for (i = ev_start; i < ev_end; ++i) { - if (0 == finderCapsule.finder) { - finderCapsule.finder = new LxFinder; - finderCapsule.finder->SetLinkWithSts(linkWithSts); - finderCapsule.finder->SetUseMCPInsteadOfHits(useMCPInsteadOfHits); - finderCapsule.finder->SetCalcMiddlePoints(calcMiddlePoints); - finderCapsule.finder->SetCutCoeff(cutCoeff); - finderCapsule.finder->SetGenBackground(generateBackground); - finderCapsule.finder->SetGenInvMass(generateInvMass); - finderCapsule.finder->SetVerbosity(0); - finderCapsule.finder->SetParallMode(true); - finderCapsule.finder->SetHitFileName(hitFileName); - finderCapsule.finder->Init(); - createdFinderInstances++; - } - - finderCapsule.finder->ReadEvent(i); - Int_t runTime = 0; - finderCapsule.finder->Exec(reinterpret_cast<Option_t*>(&runTime)); - totalRunTime += runTime; - } - } - else { -#endif //LXPARALL_SEPARATE_SINGLE -#pragma omp parallel for firstprivate(finderCapsule) - for (i = ev_start; i < ev_end; ++i) { - if (0 == finderCapsule.finder) { - finderCapsule.finder = new LxFinder; - finderCapsule.finder->SetLinkWithSts(linkWithSts); - finderCapsule.finder->SetUseMCPInsteadOfHits(useMCPInsteadOfHits); - finderCapsule.finder->SetCalcMiddlePoints(calcMiddlePoints); - finderCapsule.finder->SetCutCoeff(cutCoeff); - finderCapsule.finder->SetGenBackground(generateBackground); - finderCapsule.finder->SetGenInvMass(generateInvMass); - finderCapsule.finder->SetVerbosity(0); - finderCapsule.finder->SetParallMode(true); - finderCapsule.finder->SetHitFileName(hitFileName); - finderCapsule.finder->Init(); -#pragma omp atomic - createdFinderInstances++; - } - - finderCapsule.finder->ReadEvent(i); - Int_t runTime = 0; - finderCapsule.finder->Exec(reinterpret_cast<Option_t*>(&runTime)); -#pragma omp atomic - totalRunTime += runTime; - } -#ifdef LXPARALL_SEPARATE_SINGLE - } -#endif //LXPARALL_SEPARATE_SINGLE - - gettimeofday(&eTime, 0); - int exeDuration = (eTime.tv_sec - bTime.tv_sec) * 1000000 + eTime.tv_usec - bTime.tv_usec; - cout << "Execution duration was: " << exeDuration << endl; - cout << "Created finder instances: " << createdFinderInstances << endl; - cout << "Total run time: " << totalRunTime << endl; - Double_t result = totalRunTime; - result /= (ev_end - ev_start) * numThreads; - cout << "Average run time: " << result << endl; - return result; -} diff --git a/reco/tracking/lx/Simple/LxParall.h b/reco/tracking/lx/Simple/LxParall.h deleted file mode 100644 index 7cca02dbe8263e766ee20719ad24fc2370ca61d0..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/Simple/LxParall.h +++ /dev/null @@ -1,55 +0,0 @@ -/* Copyright (C) 2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifndef LX_PARALL_INCLUDED - -#pragma GCC diagnostic ignored "-Weffc++" -#include "TString.h" - -#include "LxSettings.h" - -class LxParallFinder { -public: - LxParallFinder(); - ~LxParallFinder() { ; } - - Double_t Reconstruct(Int_t numThreads); - - void SetGenInvMass(bool value) { generateInvMass = value; } - - void SetGenBackground(bool value) { generateBackground = value; } - - void SetGenChi2(bool value) { generateChi2 = value; } - - void SetLinkWithSts(bool value) { linkWithSts = value; } - - void SetUseMCPInsteadOfHits(bool value) { useMCPInsteadOfHits = value; } - - void SetCalcMiddlePoints(bool value) { calcMiddlePoints = value; } - - void SetCutCoeff(scaltype value) { cutCoeff = value; } - - void SetStartEvent(Int_t n) { ev_start = n; } - - void SetEndEvent(Int_t n) { ev_end = n; } - - void SetHitFileName(TString v) { hitFileName = v; } - -private: - bool generateInvMass; - bool generateBackground; - bool generateChi2; - bool linkWithSts; - bool useMCPInsteadOfHits; - bool calcMiddlePoints; - scaltype cutCoeff; - Int_t ev_start; - Int_t ev_end; - TString hitFileName; - ClassDef(LxParallFinder, 1); -}; - -#pragma GCC diagnostic warning "-Weffc++" - -#endif //LX_PARALL_INCLUDED diff --git a/reco/tracking/lx/Simple/LxSettings.h b/reco/tracking/lx/Simple/LxSettings.h deleted file mode 100644 index 660cd85fd3d4fa046202b0b3c3525f5e901c8901..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/Simple/LxSettings.h +++ /dev/null @@ -1,66 +0,0 @@ -/* Copyright (C) 2014-2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifndef LXSETTINGS_INCLUDED -#define LXSETTINGS_INCLUDED - -#define LXPI 3.141592653589793238462643383279 - -#define scaltype float - -#define LXLAYERS 3 -#define LXSTATIONS 6 -#define LXMIDDLE 1 -#define LXFIRSTSTATION 0 -#define LXSTSSTATIONS 8 -#define LXMAXPOINTSONSTATION 4096 - -#define MAKE_HISTOS - -#ifdef MAKE_HISTOS -//#define MAKE_ANGLE_HISTOS -//#define MAKE_BRAKE_ANGLE_HISTOS -//#define MAKE_DISPERSE_HISTOS -//#define MAKE_DISPERSE_2D_HISTOS -//#define MAKE_MU_PLUS_MU_MINUS_HISTOS -//#define MAKE_DIFF_FIT_HISTOS -//#define MAKE_DIFF_FIRST_HISTOS -//#define MAKE_FIT_COEFFS_HISTOS -//#define MAKE_LAST_STS_NEAREST_Y -#define MAKE_TRIGGERING_HISTOS - -#endif //MAKE_HISTOS - -#define MAKE_STS_MC_RESEARCHES -#define MAKE_EFF_CALC -//#define CALC_MUCH_DETECTORS_EFF -//#define CALC_LINK_WITH_STS_EFF - -//#define CLUSTER_MODE - -#ifdef CLUSTER_MODE - -#define DENSE_CLUSTERS_FIRST -#define BEST_RAYS_ONLY - -#ifdef BEST_RAYS_ONLY - -#define REMOVE_SUBCLUSTER -#define BEST_SIX_POINTS - -#endif //BEST_RAYS_ONLY - -#define REMEMBER_CLUSTERED_RAYS_IN_POINTS - -#endif //CLUSTER_MODE - -//#define USE_KALMAN -//#define USE_KALMAN_FIT - -#define LX_DEBUG - -#define USE_OLD_STS_LINKING_RULE -//#define LX_EXT_LINK_SOPH - -#endif //LXSETTINGS_INCLUDED diff --git a/reco/tracking/lx/Simple/LxTrackAna.cxx b/reco/tracking/lx/Simple/LxTrackAna.cxx deleted file mode 100644 index 70545993e02877d2cc6807edcb34496f9bbf2d28..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/Simple/LxTrackAna.cxx +++ /dev/null @@ -1,1080 +0,0 @@ -/* Copyright (C) 2014-2021 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#include "LxTrackAna.h" - -#include "CbmKFTrack.h" -#include "CbmMCTrack.h" -#include "CbmMuchCluster.h" -#include "CbmMuchDigiMatch.h" -#include "CbmMuchGeoScheme.h" -#include "CbmMuchPoint.h" -#include "CbmStsAddress.h" -#include "CbmStsPoint.h" -#include "CbmStsTrack.h" -#include "TDatabasePDG.h" -#include "TGeoManager.h" -#include "TH1.h" -#include "TH2.h" - -#include <iostream> - -#include <dirent.h> -#include <sys/stat.h> -#include <sys/types.h> - -ClassImp(LxTrackAna) - - using namespace std; - -//static scaltype xRms = 1.005;// Averaged MC -static scaltype xRms = 1.202; // Nearest hit -static scaltype xRms2 = xRms * xRms; -//static scaltype yRms = 0.9467;// Averaged MC -static scaltype yRms = 1.061; // Nearest hit -static scaltype yRms2 = yRms * yRms; -//static scaltype txRms = 0.02727;// Averaged MC -static scaltype txRms = 0.02426; // Nearest hit -static scaltype txRms2 = txRms * txRms; -//static scaltype tyRms = 0.01116;// Averaged MC -static scaltype tyRms = 0.01082; // Nearest hit -static scaltype tyRms2 = tyRms * tyRms; -static scaltype cutCoeff = 3.0; - -static TH1F* muchStsBreakX = 0; -static TH1F* muchStsBreakY = 0; -static TH1F* muchStsBreakTx = 0; -static TH1F* muchStsBreakTy = 0; - -static TH1F* stsMuchBreakX = 0; -static TH1F* stsMuchBreakY = 0; - -static TH1F* signalChi2 = 0; -static TH1F* bgrChi2 = 0; - -static TH1F* bgrInvMass = 0; -static list<LxSimpleTrack*> positiveTracks; -static list<LxSimpleTrack*> negativeTracks; -static TH1F* sigInvMass = 0; - -static TH1F* nearestHitDist[LXSTATIONS] = {0}; -static TH1F* hitsDist[LXSTATIONS] = {0}; - -static TH1F* muPlusStsTxDiff = 0; -static TH1F* muMinusStsTxDiff = 0; -static TH1F* muPlusStsXDiff = 0; -static TH1F* muMinusStsXDiff = 0; -static TH1F* muPlusVertexTxDiff = 0; -static TH1F* muMinusVertexTxDiff = 0; - -static TH2F* muPlusStsBeginTxDiff2D = 0; -static TH2F* muMinusStsBeginTxDiff2D = 0; - -static TH1F* deltaPhiPi = 0; - -static TH1F* jPsiMuonsMomsHisto = 0; - -static scaltype magnetCenterZ = 0; - -static TH1F* dtxMomProductHisto = 0; - -static TH1F* stsEndTrackCount = 0; -static TH1F* muchBeginTrackCount = 0; - -struct MomVsTxRange { - scaltype momLow; - scaltype momHigh; - scaltype txLow; - scaltype txHigh; -}; - -static bool momFitTxBreak(scaltype mom, scaltype txBreak) -{ - if (mom < 3.0) return false; - - if (txBreak < 0) txBreak = -txBreak; - - scaltype inv = mom * txBreak; - return inv > 0.18 && inv < 0.52; -} - -void LxSimpleTrack::RebindMuchTrack() -{ - linkedStsTrack = 0; - - while (!linkedStsTracks.empty()) { - pair<LxSimpleTrack*, scaltype> trackDesc = linkedStsTracks.front(); - linkedStsTracks.pop_front(); - LxSimpleTrack* anotherMuchTrack = trackDesc.first->linkedMuchTrack.first; - - if (0 == anotherMuchTrack || trackDesc.second < trackDesc.first->linkedMuchTrack.second) { - trackDesc.first->linkedMuchTrack.first = this; - trackDesc.first->linkedMuchTrack.second = trackDesc.second; - linkedStsTrack = trackDesc.first; - - if (0 != anotherMuchTrack) anotherMuchTrack->RebindMuchTrack(); - - break; - } - } -} - -LxTrackAna::LxTrackAna() - : listMCTracks(0) - , listStsPts(0) - , listMuchPts(0) - , listMuchPixelHits(0) - , listMuchClusters(0) - , listMuchPixelDigiMatches(0) - , allTracks() - , posTracks() - , negTracks() - , superEventTracks(0) - , superEventBrachTrack(0, 0, 0, 0, 0, 0, 0, 0) - , useHitsInStat(false) - , averagePoints(false) - , dontTouchNonPrimary(true) - , useChargeSignInCuts(false) - , buildConnectStat(false) - , buildBgrInvMass(false) - , buildSigInvMass(false) - , joinData(false) - , buildNearestHitDist(false) - , cropHits(false) - , buildSegmentsStat(true) - , particleType("jpsi") - , segmentsAnalyzer(*this) -{ -} - -LxTrackAna::~LxTrackAna() { Clean(); } - -void LxTrackAna::Clean() -{ - for (vector<LxSimpleTrack*>::iterator i = allTracks.begin(); i != allTracks.end(); ++i) - delete *i; - - allTracks.clear(); - posTracks.clear(); - negTracks.clear(); -} - -InitStatus LxTrackAna::Init() -{ - FairRootManager* fManager = FairRootManager::Instance(); - listMCTracks = static_cast<TClonesArray*>(fManager->GetObject("MCTrack")); - - if (0 == listMCTracks) return kFATAL; - - listStsPts = static_cast<TClonesArray*>(fManager->GetObject("StsPoint")); - - if (0 == listStsPts) return kFATAL; - - listMuchPts = static_cast<TClonesArray*>(fManager->GetObject("MuchPoint")); - - if (0 == listMuchPts) return kFATAL; - - if (useHitsInStat) { - listMuchPixelHits = static_cast<TClonesArray*>(fManager->GetObject("MuchPixelHit")); - - if (0 == listMuchPixelHits) return kFATAL; - - listMuchClusters = static_cast<TClonesArray*>(fManager->GetObject("MuchCluster")); - - if (0 == listMuchClusters) return kFATAL; - - listMuchPixelDigiMatches = static_cast<TClonesArray*>(fManager->GetObject("MuchDigiMatch")); - - if (0 == listMuchPixelDigiMatches) return kFATAL; - } - - if (buildConnectStat) { - muchStsBreakX = new TH1F("muchStsBreakX", "Break in prediction of X in STS", 100, -20., 20.); - muchStsBreakX->StatOverflows(); - muchStsBreakY = new TH1F("muchStsBreakY", "Break in prediction of Y in STS", 100, -20., 20.); - muchStsBreakY->StatOverflows(); - muchStsBreakTx = new TH1F("muchStsBreakTx", "Break in prediction of Tx in STS", 100, -0.15, 0.15); - muchStsBreakTx->StatOverflows(); - muchStsBreakTy = new TH1F("muchStsBreakTy", "Break in prediction of Ty in STS", 100, -0.15, 0.15); - muchStsBreakTy->StatOverflows(); - - stsMuchBreakX = new TH1F("stsMuchBreakX", "Break in prediction of X in MUCH", 100, -20., 20.); - stsMuchBreakX->StatOverflows(); - stsMuchBreakY = new TH1F("stsMuchBreakY", "Break in prediction of Y in MUCH", 100, -20., 20.); - stsMuchBreakY->StatOverflows(); - - signalChi2 = new TH1F("signalChi2", "Chi2 of signal", 100, 0., 15.); - signalChi2->StatOverflows(); - bgrChi2 = new TH1F("bgrChi2", "Chi2 of background", 100, 0., 20.); - bgrChi2->StatOverflows(); - } // if (buildConnectStat) - - if (buildBgrInvMass) { - if (joinData) { - bgrInvMass = new TH1F("bgrInvMass", "Invariant mass distribution for background", 1000, 2., 4.); - bgrInvMass->StatOverflows(); - } - else { - superEventTracks = new TTree("SuperEventTracks", "Tracks for building a super event"); - superEventTracks->Branch("tracks", &superEventBrachTrack.px, "px/D:py:pz:e:charge"); - } - } // if (buildBgrInvMass) - - if (buildSigInvMass) { - sigInvMass = new TH1F("sigInvMass", "Invariant mass distribution for signal", 1000, 2., 4.); - sigInvMass->StatOverflows(); - } // if (buildSigInvMass) - - if (buildNearestHitDist && useHitsInStat) { - char name[32]; - char title[128]; - - for (Int_t i = 0; i < LXSTATIONS; ++i) { - sprintf(name, "nearestHitDist_%d", i); - sprintf(title, "Distance from a MC point to the nearest hit at %d station", i); - nearestHitDist[i] = new TH1F(name, title, 100, 0., 5.); - nearestHitDist[i]->StatOverflows(); - sprintf(name, "hitsDist_%d", i); - sprintf(title, "Distance from a MC point to the hits at %d station", i); - hitsDist[i] = new TH1F(name, title, 100, 0., 7.); - hitsDist[i]->StatOverflows(); - } - } - - muPlusStsTxDiff = new TH1F("muPlusStsTxDiff", "muPlusStsTxDiff", 100, -0.2, 0.2); - muPlusStsTxDiff->StatOverflows(); - muMinusStsTxDiff = new TH1F("muMinusStsTxDiff", "muMinusStsTxDiff", 100, -0.2, 0.2); - muMinusStsTxDiff->StatOverflows(); - muPlusStsXDiff = new TH1F("muPlusStsXDiff", "muPlusStsXDiff", 100, -10.0, 10.0); - muPlusStsXDiff->StatOverflows(); - muMinusStsXDiff = new TH1F("muMinusStsXDiff", "muMinusStsXDiff", 100, -10.0, 10.0); - muMinusStsXDiff->StatOverflows(); - muPlusVertexTxDiff = new TH1F("muPlusVertexTxDiff", "muPlusVertexTxDiff", 100, -0.2, 0.2); - muPlusVertexTxDiff->StatOverflows(); - muMinusVertexTxDiff = new TH1F("muMinusVertexTxDiff", "muMinusVertexTxDiff", 100, -0.2, 0.2); - muMinusVertexTxDiff->StatOverflows(); - - muPlusStsBeginTxDiff2D = new TH2F("muPlusStsBeginTxDiff2D", "muPlusStsBeginTxDiff2D", 100, 0., 25., 100, -0.2, 0.2); - muPlusStsBeginTxDiff2D->StatOverflows(); - muMinusStsBeginTxDiff2D = - new TH2F("muMinusStsBeginTxDiff2D", "muMinusStsBeginTxDiff2D", 100, 0., 25.0, 100, -0.2, 0.2); - muMinusStsBeginTxDiff2D->StatOverflows(); - - deltaPhiPi = new TH1F("deltaPhiPi", "deltaPhiPi", 100, 0., 1.0); - deltaPhiPi->StatOverflows(); - - jPsiMuonsMomsHisto = new TH1F("jPsiMuonsMomsHisto", "J/Psi muons momenta distribution", 200, 0., 25.); - jPsiMuonsMomsHisto->StatOverflows(); - - gGeoManager->cd("/cave_1/Magnet_container_0"); - Double_t localCoords[3] = {0., 0., 0.}; - Double_t globalCoords[3]; - gGeoManager->LocalToMaster(localCoords, globalCoords); - magnetCenterZ = globalCoords[2]; - //cout << "magnetCenterZ = " << magnetCenterZ << endl; - //return kFATAL; - - dtxMomProductHisto = new TH1F("dtxMomProductHisto", "Dtx x Momentum distribution", 100, -0.5, 2.5); - dtxMomProductHisto->StatOverflows(); - - stsEndTrackCount = new TH1F("stsEndTrackCountHisto", "stsEndTrackCountHisto", 200, 0, 2000.0); - stsEndTrackCount->StatOverflows(); - muchBeginTrackCount = new TH1F("muchBeginTrackCountHisto", "muchBeginTrackCountHisto", 200, 0, 3000.0); - muchBeginTrackCount->StatOverflows(); - - segmentsAnalyzer.Init(); - - return kSUCCESS; -} - -static void SaveHisto(TH1* histo, const char* particleType, const char* name) -{ - char dir_name[256]; - sprintf(dir_name, "configuration.%s", particleType); - DIR* dir = opendir(dir_name); - - if (dir) - closedir(dir); - else - mkdir(dir_name, 0700); - - char file_name[256]; - sprintf(file_name, "%s/%s", dir_name, name); - TFile fh(file_name, "RECREATE"); - histo->Write(); - fh.Close(); - delete histo; -} - -static void BuildInvMass(list<LxSimpleTrack*>& pTracks, list<LxSimpleTrack*>& nTracks, TH1* histo) -{ - for (list<LxSimpleTrack*>::iterator i = pTracks.begin(); i != pTracks.end(); ++i) { - LxSimpleTrack* posTrack = *i; - - for (list<LxSimpleTrack*>::iterator j = nTracks.begin(); j != nTracks.end(); ++j) { - LxSimpleTrack* negTrack = *j; - scaltype E12 = posTrack->e + negTrack->e; - scaltype px12 = posTrack->px + negTrack->px; - scaltype py12 = posTrack->py + negTrack->py; - scaltype pz12 = posTrack->pz + negTrack->pz; - scaltype m122 = E12 * E12 - px12 * px12 - py12 * py12 - pz12 * pz12; - scaltype m12 = m122 > 1.e-20 ? sqrt(m122) : 0.; - histo->Fill(m12); - } - } -} - -static void BuildInvMass2(list<CbmStsTrack*>& stsTracks, TH1* /*histo*/) -{ - for (list<CbmStsTrack*>::iterator i = stsTracks.begin(); i != stsTracks.end(); ++i) { - CbmStsTrack* posTrack = *i; - //CbmStsTrack t1(*posTrack); - //extFitter.DoFit(&t1, 13); - //scaltype chi2Prim = extFitter.GetChiToVertex(&t1, fPrimVtx); - const FairTrackParam* t1param = posTrack->GetParamFirst(); - //extFitter.Extrapolate(&t1, fPrimVtx->GetZ(), &t1param); - CbmKFTrack muPlus(*posTrack); - scaltype t1Qp = t1param->GetQp(); - list<CbmStsTrack*>::iterator j = i; - ++j; - - for (; j != stsTracks.end(); ++j) { - CbmStsTrack* negTrack = *j; - //CbmStsTrack t2(*negTrack); - //extFitter.DoFit(&t2, 13); - //chi2Prim = extFitter.GetChiToVertex(&t2, fPrimVtx); - const FairTrackParam* t2param = negTrack->GetParamLast(); - //extFitter.Extrapolate(&t2, fPrimVtx->GetZ(), &t2param); - scaltype t2Qp = t2param->GetQp(); - - if (t1Qp * t2Qp >= 0) continue; - - CbmKFTrack muMinus(*negTrack); - vector<CbmKFTrackInterface*> kfData; - - if (t1Qp > 0) { - kfData.push_back(&muPlus); - kfData.push_back(&muMinus); - } - else { - kfData.push_back(&muMinus); - kfData.push_back(&muPlus); - } - } - } -} - -void LxTrackAna::FinishTask() -{ - TFile* curFile = TFile::CurrentFile(); - - if (buildConnectStat) { - SaveHisto(muchStsBreakX, particleType.Data(), "muchStsBreakX.root"); - SaveHisto(muchStsBreakY, particleType.Data(), "muchStsBreakY.root"); - SaveHisto(muchStsBreakTx, particleType.Data(), "muchStsBreakTx.root"); - SaveHisto(muchStsBreakTy, particleType.Data(), "muchStsBreakTy.root"); - - SaveHisto(stsMuchBreakX, particleType.Data(), "stsMuchBreakX.root"); - SaveHisto(stsMuchBreakY, particleType.Data(), "stsMuchBreakY.root"); - - SaveHisto(signalChi2, particleType.Data(), "signalChi2.root"); - SaveHisto(bgrChi2, particleType.Data(), "bgrChi2.root"); - } // if (buildConnectStat) - - if (buildBgrInvMass) { - if (joinData) { - TFile fh("tracks_tree.root"); - superEventTracks = fh.Get<TTree>("SuperEventTracks"); - //LxSimpleTrack st(0, 0, 0, 0, 0, 0, 0, 0); - //superEventTracks->SetBranchAddress("tracks", &st.px); - CbmStsTrack* st = new CbmStsTrack; - superEventTracks->SetBranchAddress("tracks", &st); - list<CbmStsTrack*> stsTracks; - Int_t nEnt = superEventTracks->GetEntries(); - - for (Int_t i = 0; i < nEnt; ++i) { - superEventTracks->GetEntry(i); - //LxSimpleTrack* t = new LxSimpleTrack(0, 0, 0, 0, st.px, st.py, st.pz, st.e); - //t->charge = st.charge; - CbmStsTrack* t = new CbmStsTrack(*st); - stsTracks.push_back(t); - } - - BuildInvMass2(stsTracks, bgrInvMass); - SaveHisto(bgrInvMass, particleType.Data(), "bgrInvMass.root"); - - for (list<CbmStsTrack*>::iterator i = stsTracks.begin(); i != stsTracks.end(); ++i) - delete *i; - } - else { - TFile fh("tracks_tree.root", "RECREATE"); - superEventTracks->Write(); - fh.Close(); - delete superEventTracks; - } - } // if (buildBgrInvMass) - - if (buildSigInvMass) SaveHisto(sigInvMass, particleType.Data(), "sigInvMass.root"); - - if (buildNearestHitDist && useHitsInStat) { - char fileName[32]; - - for (Int_t i = 0; i < LXSTATIONS; ++i) { - sprintf(fileName, "%s.root", nearestHitDist[i]->GetName()); - SaveHisto(nearestHitDist[i], particleType.Data(), fileName); - sprintf(fileName, "%s.root", hitsDist[i]->GetName()); - SaveHisto(hitsDist[i], particleType.Data(), fileName); - } - } - - SaveHisto(muPlusStsTxDiff, particleType.Data(), "muPlusStsTxDiff.root"); - SaveHisto(muMinusStsTxDiff, particleType.Data(), "muMinusStsTxDiff.root"); - SaveHisto(muPlusStsXDiff, particleType.Data(), "muPlusStsXDiff.root"); - SaveHisto(muMinusStsXDiff, particleType.Data(), "muMinusStsXDiff.root"); - SaveHisto(muPlusVertexTxDiff, particleType.Data(), "muPlusVertexTxDiff.root"); - SaveHisto(muMinusVertexTxDiff, particleType.Data(), "muMinusVertexTxDiff.root"); - - SaveHisto(muPlusStsBeginTxDiff2D, particleType.Data(), "muPlusStsBeginTxDiff2D.root"); - SaveHisto(muMinusStsBeginTxDiff2D, particleType.Data(), "muMinusStsBeginTxDiff2D.root"); - - SaveHisto(deltaPhiPi, particleType.Data(), "deltaPhiPi.root"); - - SaveHisto(jPsiMuonsMomsHisto, particleType.Data(), "jPsiMuonsMomsHisto.root"); - SaveHisto(dtxMomProductHisto, particleType.Data(), "dtxMomProductHisto.root"); - - SaveHisto(stsEndTrackCount, particleType.Data(), "stsEndTrackCountHisto.root"); - SaveHisto(muchBeginTrackCount, particleType.Data(), "muchBeginTrackCountHisto.root"); - - segmentsAnalyzer.Finish(); - - TFile::CurrentFile() = curFile; - FairTask::FinishTask(); -} - -// Our goal here is to investigate various properties of Monte Carlo tracks derivable from points of there intersections -// with detector stations. At the same time in MUCH we use not the Monte Carlo points but hits corresponding to them. -// -- This is done to make the statistical properties more realistic. -void LxTrackAna::Exec(Option_t*) -{ - Clean(); - - Int_t nEnt = listMCTracks->GetEntriesFast(); - cout << "There are: " << nEnt << " of MC tracks" << endl; - - for (Int_t i = 0; i < nEnt; ++i) { - CbmMCTrack* mct = static_cast<CbmMCTrack*>(listMCTracks->At(i)); - LxSimpleTrack* t = new LxSimpleTrack(mct->GetPdgCode(), mct->GetMotherId(), mct->GetP(), mct->GetPt(), mct->GetPx(), - mct->GetPy(), mct->GetPz(), mct->GetEnergy()); - allTracks.push_back(t); - } - - nEnt = listStsPts->GetEntriesFast(); - cout << "There are: " << nEnt << " of STS MC points" << endl; - - for (Int_t i = 0; i < nEnt; ++i) { - CbmStsPoint* stsPt = static_cast<CbmStsPoint*>(listStsPts->At(i)); - Int_t mcTrackId = stsPt->GetTrackID(); - LxSimpleTrack* track = allTracks[mcTrackId]; - TVector3 xyzI, xyzO; - stsPt->Position(xyzI); - stsPt->PositionOut(xyzO); - TVector3 xyz = .5 * (xyzI + xyzO); - TVector3 pxyzI, pxyzO; - stsPt->Momentum(pxyzI); - stsPt->MomentumOut(pxyzO); - TVector3 pxyz = .5 * (pxyzI + pxyzO); - LxSimplePoint point(xyz.X(), xyz.Y(), xyz.Z(), pxyz.X() / pxyz.Z(), pxyz.Y() / pxyz.Z()); - Int_t stationNr = CbmStsAddress::GetElementId(stsPt->GetDetectorID(), kStsStation); - track->stsPoints[stationNr].push_back(point); - } - - nEnt = listMuchPts->GetEntriesFast(); - cout << "There are: " << nEnt << " of MUCH MC points" << endl; - - for (Int_t i = 0; i < nEnt; ++i) { - CbmMuchPoint* mcPoint = static_cast<CbmMuchPoint*>(listMuchPts->At(i)); - Int_t mcTrackId = mcPoint->GetTrackID(); - LxSimpleTrack* track = allTracks[mcTrackId]; - Int_t stationNr = CbmMuchGeoScheme::GetStationIndex(mcPoint->GetDetectorId()); - Int_t layerNr = CbmMuchGeoScheme::GetLayerIndex(mcPoint->GetDetectorId()); - TVector3 xyzI, xyzO; - mcPoint->Position(xyzI); - mcPoint->PositionOut(xyzO); - TVector3 xyz = .5 * (xyzI + xyzO); - TVector3 pxyzI, pxyzO; - mcPoint->Momentum(pxyzI); - mcPoint->MomentumOut(pxyzO); - TVector3 pxyz = .5 * (pxyzI + pxyzO); - LxSimplePoint point(xyz.X(), xyz.Y(), xyz.Z(), pxyz.X() / pxyz.Z(), pxyz.Y() / pxyz.Z()); - - if (useHitsInStat) - track->muchMCPts[stationNr][layerNr].push_back(point); - else - track->muchPoints[stationNr][layerNr].push_back(point); - } - - if (useHitsInStat) { - nEnt = listMuchPixelHits->GetEntriesFast(); - cout << "There are: " << nEnt << " of MUCH pixel hits" << endl; - - for (Int_t i = 0; i < nEnt; ++i) { - CbmMuchPixelHit* mh = static_cast<CbmMuchPixelHit*>(listMuchPixelHits->At(i)); - - // Int_t stationNumber = CbmMuchGeoScheme::GetStationIndex(mh->GetAddress()); - // Int_t layerNumber = CbmMuchGeoScheme::GetLayerIndex(mh->GetAddress()); - TVector3 pos, err; - mh->Position(pos); - mh->PositionError(err); - scaltype x = pos.X(); - scaltype y = pos.Y(); - scaltype z = pos.Z(); - - if (x != x || y != y || z != z) // Test for NaN - continue; - - Int_t clusterId = mh->GetRefId(); - CbmMuchCluster* cluster = static_cast<CbmMuchCluster*>(listMuchClusters->At(clusterId)); - Int_t nDigis = cluster->GetNofDigis(); - - for (Int_t j = 0; j < nDigis; ++j) { - CbmMuchDigiMatch* digiMatch = static_cast<CbmMuchDigiMatch*>(listMuchPixelDigiMatches->At(cluster->GetDigi(j))); - Int_t nMCs = digiMatch->GetNofLinks(); - - for (Int_t k = 0; k < nMCs; ++k) { - const CbmLink& lnk = digiMatch->GetLink(k); - Int_t mcIndex = lnk.GetIndex(); - CbmMuchPoint* mcPoint = static_cast<CbmMuchPoint*>(listMuchPts->At(mcIndex)); - Int_t mcTrackId = mcPoint->GetTrackID(); - LxSimpleTrack* track = allTracks[mcTrackId]; - Int_t stationNr = CbmMuchGeoScheme::GetStationIndex(mcPoint->GetDetectorId()); - Int_t layerNr = CbmMuchGeoScheme::GetLayerIndex(mcPoint->GetDetectorId()); - LxSimplePoint point(x, y, z, 0, 0); - track->muchPoints[stationNr][layerNr].push_back(point); - } - } - } - - nEnt = listMuchClusters->GetEntriesFast(); - cout << "There are: " << nEnt << " of MUCH clusters" << endl; - - nEnt = listMuchPixelDigiMatches->GetEntriesFast(); - cout << "There are: " << nEnt << " of MUCH pixel digi matches" << endl; - } //if (useHitsInStat) - - if (averagePoints) AveragePoints(); - - if (buildConnectStat) BuildStatistics(); - - //Connect(false); - Connect(true); - - if (buildSigInvMass) BuildInvMass(posTracks, negTracks, sigInvMass); - - if (buildSegmentsStat) segmentsAnalyzer.BuildStatistics(); -} - -static inline void AveragePoints(list<LxSimplePoint>& points) -{ - if (points.empty() || points.size() == 1) return; - - scaltype x = 0; - scaltype y = 0; - scaltype z = 0; - scaltype tx = 0; - scaltype ty = 0; - - for (list<LxSimplePoint>::iterator i = points.begin(); i != points.end(); ++i) { - LxSimplePoint p = *i; - x += p.x; - y += p.y; - z += p.z; - tx += p.tx; - ty += p.ty; - } - - x /= points.size(); - y /= points.size(); - z /= points.size(); - tx /= points.size(); - ty /= points.size(); - LxSimplePoint averagedPoint(x, y, z, tx, ty); - points.clear(); - points.push_back(averagedPoint); -} - -// If hits are used in statistics average MC points in MUCH. -static inline void AveragePoints(LxSimpleTrack* track, bool useHitsInStat) -{ - for (Int_t i = 0; i < LXSTSSTATIONS; ++i) - AveragePoints(track->stsPoints[i]); - - if (useHitsInStat) { - for (Int_t i = 0; i < LXSTATIONS; ++i) { - for (Int_t j = 0; j < LXLAYERS; ++j) - AveragePoints(track->muchMCPts[i][j]); - } - } - else { - for (Int_t i = 0; i < LXSTATIONS; ++i) { - for (Int_t j = 0; j < LXLAYERS; ++j) - AveragePoints(track->muchPoints[i][j]); - } - } -} - -void LxTrackAna::AveragePoints() -{ - for (vector<LxSimpleTrack*>::iterator i = allTracks.begin(); i != allTracks.end(); ++i) - ::AveragePoints(*i, useHitsInStat); -} - -static UInt_t maxTracks = 0; -static UInt_t maxMuchPts1 = 0; -static UInt_t maxMuchPts0 = 0; -static UInt_t maxStsPts7 = 0; -static UInt_t maxStsPts6 = 0; - -static inline void BuildStatistics(LxSimpleTrack* track) -{ - if (track->muchPoints[1][LXMIDDLE].size() > maxMuchPts1) maxMuchPts1 = track->muchPoints[1][LXMIDDLE].size(); - - if (track->muchPoints[0][LXMIDDLE].size() > maxMuchPts0) maxMuchPts0 = track->muchPoints[0][LXMIDDLE].size(); - - if (track->stsPoints[7].size() > maxStsPts7) maxStsPts7 = track->stsPoints[7].size(); - - if (track->stsPoints[6].size() > maxStsPts6) maxStsPts6 = track->stsPoints[6].size(); - - jPsiMuonsMomsHisto->Fill(track->p); - - for (list<LxSimplePoint>::iterator j = track->muchPoints[1][LXMIDDLE].begin(); - j != track->muchPoints[1][LXMIDDLE].end(); ++j) { - LxSimplePoint muchPt1 = *j; - - for (list<LxSimplePoint>::iterator k = track->muchPoints[0][LXMIDDLE].begin(); - k != track->muchPoints[0][LXMIDDLE].end(); ++k) { - LxSimplePoint muchPt0 = *k; - scaltype diffZMuch = muchPt0.z - muchPt1.z; - scaltype txMuch = (muchPt0.x - muchPt1.x) / diffZMuch; - scaltype tyMuch = (muchPt0.y - muchPt1.y) / diffZMuch; - - scaltype diffZMag = magnetCenterZ - muchPt0.z; - scaltype magX = muchPt0.x + txMuch * diffZMag; - scaltype magTx = magX / magnetCenterZ; - scaltype diffMagTx = txMuch - magTx; - - if (-13 == track->pdgCode) - dtxMomProductHisto->Fill(diffMagTx * track->p); - else if (13 == track->pdgCode) - dtxMomProductHisto->Fill(-diffMagTx * track->p); - - if (-13 == track->pdgCode) { - scaltype txDiff = txMuch - muchPt0.x / muchPt0.z; - muPlusVertexTxDiff->Fill(txDiff); - - if (!track->stsPoints[0].empty() && !track->stsPoints[1].empty()) { - LxSimplePoint p0 = track->stsPoints[0].front(); - LxSimplePoint p1 = track->stsPoints[1].front(); - muPlusStsBeginTxDiff2D->Fill(track->p, txMuch - (p1.x - p0.x) / (p1.z - p0.z)); - muMinusStsBeginTxDiff2D->Fill(track->p, (p1.x - p0.x) / (p1.z - p0.z) - txMuch); - deltaPhiPi->Fill(track->p * (txMuch - (p1.x - p0.x) / (p1.z - p0.z))); - } - } - else if (13 == track->pdgCode) { - scaltype txDiff = txMuch - muchPt0.x / muchPt0.z; - muMinusVertexTxDiff->Fill(txDiff); - - if (!track->stsPoints[0].empty() && !track->stsPoints[1].empty()) { - LxSimplePoint p0 = track->stsPoints[0].front(); - LxSimplePoint p1 = track->stsPoints[1].front(); - muMinusStsBeginTxDiff2D->Fill(track->p, txMuch - (p1.x - p0.x) / (p1.z - p0.z)); - muPlusStsBeginTxDiff2D->Fill(track->p, (p1.x - p0.x) / (p1.z - p0.z) - txMuch); - deltaPhiPi->Fill(track->p * ((p1.x - p0.x) / (p1.z - p0.z) - txMuch)); - } - } - - for (list<LxSimplePoint>::iterator l = track->stsPoints[7].begin(); l != track->stsPoints[7].end(); ++l) { - LxSimplePoint stsPt7 = *l; - scaltype diffZ = stsPt7.z - muchPt0.z; - scaltype extX = muchPt0.x + txMuch * diffZ; - scaltype extY = muchPt0.y + tyMuch * diffZ; - scaltype dx = stsPt7.x - extX; - scaltype dy = stsPt7.y - extY; - muchStsBreakX->Fill(dx); - muchStsBreakY->Fill(dy); - - if (-13 == track->pdgCode) { - scaltype extXmu = muchPt0.x + (txMuch - 0.00671) * diffZ; - muPlusStsXDiff->Fill(stsPt7.x - extXmu); - } - else if (13 == track->pdgCode) { - scaltype extXmu = muchPt0.x + (txMuch + 0.00691) * diffZ; - muMinusStsXDiff->Fill(stsPt7.x - extXmu); - } - - for (list<LxSimplePoint>::iterator m = track->stsPoints[6].begin(); m != track->stsPoints[6].end(); ++m) { - LxSimplePoint stsPt6 = *m; - scaltype diffZSts = stsPt6.z - stsPt7.z; - scaltype txSts = (stsPt6.x - stsPt7.x) / diffZSts; - scaltype tySts = (stsPt6.y - stsPt7.y) / diffZSts; - //muchStsBreakX->Fill(dx); - //muchStsBreakY->Fill(dy); - scaltype dtx = txSts - txMuch; - scaltype dty = tySts - tyMuch; - muchStsBreakTx->Fill(dtx); - muchStsBreakTy->Fill(dty); - - if (-13 == track->pdgCode) - muPlusStsTxDiff->Fill(dtx); - else if (13 == track->pdgCode) - muMinusStsTxDiff->Fill(dtx); - - scaltype chi2 = dx * dx / xRms2 + dy * dy / yRms2 + dtx * dtx / txRms2 + dty * dty / tyRms2; - - if (0 > track->motherId && (13 == track->pdgCode || -13 == track->pdgCode)) // JPsi - signalChi2->Fill(chi2); - else - bgrChi2->Fill(chi2); - - diffZ = muchPt0.z - stsPt7.z; - extX = stsPt7.x + txSts * diffZ; - extY = stsPt7.y + tySts * diffZ; - dx = muchPt0.x - extX; - dy = muchPt0.y - extY; - stsMuchBreakX->Fill(dx); - stsMuchBreakY->Fill(dy); - } - } - } - } -} - -static inline void BuildNearestHitStat(LxSimpleTrack* track, bool cropHits) -{ - static scaltype maxDist = 0; - static scaltype mcX = 0; - static scaltype hitX = 0; - static scaltype mcY = 0; - static scaltype hitY = 0; - - static scaltype maxMinDist = 0; - static scaltype mcMinX = 0; - static scaltype hitMinX = 0; - static scaltype mcMinY = 0; - static scaltype hitMinY = 0; - static Int_t nMinHits = 0; - - for (Int_t i = 0; i < LXSTATIONS; ++i) { - if (track->muchMCPts[i][LXMIDDLE].empty() || track->muchPoints[i][LXMIDDLE].empty()) continue; - - LxSimplePoint mcPoint = track->muchMCPts[i][LXMIDDLE] - .front(); // We assume the MC points were averaged and there can be at most one point. - scaltype minDist = -1; - scaltype mcMinX0 = 0; - scaltype hitMinX0 = 0; - scaltype mcMinY0 = 0; - scaltype hitMinY0 = 0; - scaltype hitMinZ0 = 0; - Int_t nMinHits0 = 0; - - for (list<LxSimplePoint>::iterator j = track->muchPoints[i][LXMIDDLE].begin(); - j != track->muchPoints[i][LXMIDDLE].end(); ++j) { - LxSimplePoint hitPoint = *j; - scaltype dx = hitPoint.x - mcPoint.x; - scaltype dy = hitPoint.y - mcPoint.y; - scaltype dist = sqrt(dx * dx + dy * dy); - - if (track->motherId < 0 && (13 == track->pdgCode || -13 == track->pdgCode)) hitsDist[i]->Fill(dist); - - if (minDist > dist || minDist < 0) { - minDist = dist; - - mcMinX0 = mcPoint.x; - hitMinX0 = hitPoint.x; - mcMinY0 = mcPoint.y; - hitMinY0 = hitPoint.y; - hitMinZ0 = hitPoint.z; - nMinHits0 = track->muchPoints[i][LXMIDDLE].size(); - } - - if (maxDist < dist) { - maxDist = dist; - mcX = mcPoint.x; - hitX = hitPoint.x; - mcY = mcPoint.y; - hitY = hitPoint.y; - } - } // for (list<LxSimplePoint>::iterator j = track->muchPoints[i].begin(); j != track->muchPoints[i].end(); ++j) - - if (minDist >= 0) { - if (track->motherId < 0 && (13 == track->pdgCode || -13 == track->pdgCode)) nearestHitDist[i]->Fill(minDist); - - if (cropHits) { - track->muchPoints[i][LXMIDDLE].clear(); - LxSimplePoint point(hitMinX0, hitMinY0, hitMinZ0, 0, 0); - track->muchPoints[i][LXMIDDLE].push_back(point); - } - - if (maxMinDist < minDist) { - maxMinDist = minDist; - mcMinX = mcMinX0; - hitMinX = hitMinX0; - mcMinY = mcMinY0; - hitMinY = hitMinY0; - nMinHits = nMinHits0; - } - } - } - - cout << "BuildNearestHitStat: maxDist=" << maxDist << " MC x=" << mcX << " Hit x=" << hitX << " MC y=" << mcY - << " Hit y=" << hitY << endl; - cout << "BuildNearestHitStat: maxMinDist=" << maxMinDist << " MC x=" << mcMinX << " Hit x=" << hitMinX - << " MC y=" << mcMinY << " Hit y=" << hitMinY << " n hits=" << nMinHits << endl; -} - -void LxTrackAna::BuildStatistics() -{ - if (allTracks.size() > maxTracks) maxTracks = allTracks.size(); - - Int_t stsEndTracks = 0; - Int_t muchBeginTracks = 0; - - for (vector<LxSimpleTrack*>::iterator i = allTracks.begin(); i != allTracks.end(); ++i) { - LxSimpleTrack* track = *i; - - if (!track->stsPoints[7].empty()) ++stsEndTracks; - - if (!track->muchPoints[0][0].empty() || !track->muchPoints[0][1].empty() || !track->muchPoints[0][2].empty()) - ++muchBeginTracks; - - if (track->muchPoints[0][LXMIDDLE].empty() || track->muchPoints[1][LXMIDDLE].empty() - || track->muchPoints[5][LXMIDDLE].empty()) - continue; - - if (buildNearestHitDist && useHitsInStat) - ::BuildNearestHitStat(track, - cropHits); // Hits can be cropped (only the nearest to MC hit is left) here! - - if (track->motherId > -1 || (13 != track->pdgCode && -13 != track->pdgCode)) continue; - - ::BuildStatistics(track); - } - - stsEndTrackCount->Fill(stsEndTracks); - muchBeginTrackCount->Fill(muchBeginTracks); - - cout << "Statistics is built maxTracks=" << maxTracks << " maxMuchPts1=" << maxMuchPts1 - << " maxMuchPts0=" << maxMuchPts0 << " maxStsPts7=" << maxStsPts7 << " maxStsPts6=" << maxStsPts6 << endl; -} - -void LxTrackAna::Connect(bool useCuts) -{ - static Int_t jpsiTrackCount = 0; - static Int_t jpsiTrackCountCutted = 0; - static Int_t jpsiMatchedCount = 0; - static Int_t jpsiMatchedCountCutted = 0; - - static Int_t otherTrackCount = 0; - static Int_t otherTrackCountCutted = 0; - static Int_t otherMatchedCount = 0; - static Int_t otherMatchedCountCutted = 0; - - for (vector<LxSimpleTrack*>::iterator i = allTracks.begin(); i != allTracks.end(); ++i) { - LxSimpleTrack* muchTrack = *i; - - if (muchTrack->muchPoints[0][LXMIDDLE].empty() || muchTrack->muchPoints[1][LXMIDDLE].empty() - || muchTrack->muchPoints[5][LXMIDDLE].empty()) - continue; - - for (list<LxSimplePoint>::iterator j = muchTrack->muchPoints[1][LXMIDDLE].begin(); - j != muchTrack->muchPoints[1][LXMIDDLE].end(); ++j) { - LxSimplePoint muchPt1 = *j; - - for (list<LxSimplePoint>::iterator k = muchTrack->muchPoints[0][LXMIDDLE].begin(); - k != muchTrack->muchPoints[0][LXMIDDLE].end(); ++k) { - LxSimplePoint muchPt0 = *k; - scaltype diffZMuch = muchPt0.z - muchPt1.z; - scaltype txMuch = (muchPt0.x - muchPt1.x) / diffZMuch; - // scaltype txMuchVertex = muchPt0.x / muchPt0.z; - scaltype tyMuch = (muchPt0.y - muchPt1.y) / diffZMuch; - Connect(muchTrack, muchPt0, txMuch, tyMuch, useCuts); - } // for (list<LxSimplePoint>::iterator k = muchTrack->muchPoints[0].begin(); k != muchTrack->muchPoints[0].end(); ++k) - } // for (list<LxSimplePoint>::iterator j = muchTrack->muchPoints[1].begin(); j != muchTrack->muchPoints[1].end(); ++j) - - if (0 > muchTrack->motherId && (13 == muchTrack->pdgCode || -13 == muchTrack->pdgCode)) // JPsi - { - if (useCuts) { - ++jpsiTrackCountCutted; - - if (muchTrack == muchTrack->linkedStsTrack) ++jpsiMatchedCountCutted; - - if (buildSigInvMass && 0 != muchTrack->linkedStsTrack) { - if (muchTrack->linkedStsTrack->charge > 0) - posTracks.push_back(muchTrack->linkedStsTrack); - else if (muchTrack->linkedStsTrack->charge < 0) - negTracks.push_back(muchTrack->linkedStsTrack); - } - } - else { - ++jpsiTrackCount; - - if (muchTrack == muchTrack->linkedStsTrack) ++jpsiMatchedCount; - } - } - else // Background track handled here. - { - if (useCuts) { - ++otherTrackCountCutted; - - if (muchTrack == muchTrack->linkedStsTrack || 0 == muchTrack->linkedStsTrack) ++otherMatchedCountCutted; - - if (buildBgrInvMass && !joinData && 0 != muchTrack->linkedStsTrack) { - superEventBrachTrack.px = muchTrack->linkedStsTrack->px; - superEventBrachTrack.py = muchTrack->linkedStsTrack->py; - superEventBrachTrack.pz = muchTrack->linkedStsTrack->pz; - superEventBrachTrack.e = muchTrack->linkedStsTrack->e; - superEventBrachTrack.charge = muchTrack->linkedStsTrack->charge; - superEventTracks->Fill(); - } - } - else { - ++otherTrackCount; - - if (muchTrack == muchTrack->linkedStsTrack || 0 == muchTrack->linkedStsTrack) ++otherMatchedCount; - } - } - } // for (vector<LxSimpleTrack*>::iterator i = allTracks.begin(); i != allTracks.end(); ++i) - - if (useCuts) { - scaltype efficiency = jpsiMatchedCountCutted * 100; - efficiency /= jpsiTrackCountCutted; - cout << "J/psi (with cuts) connection efficiency = " << efficiency << "% ( " << jpsiMatchedCountCutted << " / " - << jpsiTrackCountCutted << " )" << endl; - efficiency = otherMatchedCountCutted * 100; - efficiency /= otherTrackCountCutted; - cout << "Others (with cuts) connection efficiency = " << efficiency << "% ( " << otherMatchedCountCutted << " / " - << otherTrackCountCutted << " )" << endl; - } - else { - scaltype efficiency = jpsiMatchedCount * 100; - efficiency /= jpsiTrackCount; - cout << "J/psi (without cuts) connection efficiency = " << efficiency << "% ( " << jpsiMatchedCount << " / " - << jpsiTrackCount << " )" << endl; - efficiency = otherMatchedCount * 100; - efficiency /= otherTrackCount; - cout << "Others (without cuts) connection efficiency = " << efficiency << "% ( " << otherMatchedCount << " / " - << otherTrackCount << " )" << endl; - } -} - -void LxTrackAna::Connect(LxSimpleTrack* muchTrack, LxSimplePoint muchPt0, scaltype txMuch, scaltype tyMuch, - bool useCuts) -{ - for (vector<LxSimpleTrack*>::iterator l = allTracks.begin(); l != allTracks.end(); ++l) { - LxSimpleTrack* stsTrack = *l; - - if (stsTrack->p < 3.0 || stsTrack->pt < 1.0) continue; - - Int_t m0 = 0; - Int_t n0 = -1; - - for (; m0 < LXSTSSTATIONS - 1; ++m0) { - if (!stsTrack->stsPoints[m0].empty()) { - n0 = m0 + 1; - - for (; n0 <= m0 + 2 && n0 < LXSTSSTATIONS; ++n0) { - if (!stsTrack->stsPoints[n0].empty()) break; - } - } - - if (n0 <= m0 + 2) break; - } - - Int_t m = LXSTSSTATIONS - 1; - Int_t n = -1; - - for (; m > 0; --m) { - if (!stsTrack->stsPoints[m].empty()) { - n = m - 1; - - for (; n >= m - 2 && n >= 0; --n) { - if (!stsTrack->stsPoints[n].empty()) break; - } - } - - if (n >= m - 2) break; - } - - if (n >= 0 && m > n && n >= m - 2) { - if (m0 >= LXSTSSTATIONS - 1 || n0 >= LXSTSSTATIONS || m0 >= n0) { - m0 = n; - n0 = m; - } - - LxSimplePoint stsPtM0 = stsTrack->stsPoints[m0].front(); - LxSimplePoint stsPtN0 = stsTrack->stsPoints[n0].front(); - scaltype txSts0 = (stsPtN0.x - stsPtM0.x) / (stsPtN0.z - stsPtM0.z); - - for (list<LxSimplePoint>::iterator o = stsTrack->stsPoints[m].begin(); o != stsTrack->stsPoints[m].end(); ++o) { - LxSimplePoint stsPtM = *o; - scaltype deltaZ = stsPtM.z - muchPt0.z; - scaltype extX = muchPt0.x + txMuch * deltaZ; - scaltype extY = muchPt0.y + tyMuch * deltaZ; - scaltype dx = stsPtM.x - extX; - scaltype dy = stsPtM.y - extY; - - if (dx < 0) dx = -dx; - - if (dy < 0) dy = -dy; - - if (useCuts && (dx > xRms * cutCoeff || dy > yRms * cutCoeff)) continue; - - for (list<LxSimplePoint>::iterator p = stsTrack->stsPoints[n].begin(); p != stsTrack->stsPoints[n].end(); ++p) { - LxSimplePoint stsPtN = *p; - scaltype diffZSts = stsPtN.z - stsPtM.z; - scaltype txSts = (stsPtN.x - stsPtM.x) / diffZSts; - scaltype tySts = (stsPtN.y - stsPtM.y) / diffZSts; - scaltype dtx = txSts - txMuch; - scaltype dty = tySts - tyMuch; - - scaltype stsCharge = TDatabasePDG::Instance()->GetParticle(stsTrack->pdgCode)->Charge(); - scaltype muchCharge = txMuch - txSts0; - bool chargesSignsTheSame = (stsCharge > 0 && muchCharge > 0) || (stsCharge < 0 && muchCharge < 0); - - if (dtx < 0) dtx = -dtx; - - if (dty < 0) dty = -dty; - - if (useCuts - && ((useChargeSignInCuts && (!chargesSignsTheSame || !momFitTxBreak(stsTrack->p, muchCharge))) - || dtx > txRms * cutCoeff || dty > tyRms * cutCoeff)) - continue; - - scaltype chi2 = dx * dx / xRms2 + dy * dy / yRms2 + dtx * dtx / txRms2 + dty * dty / tyRms2; - stsTrack->charge = stsCharge; - - if (0 == stsTrack->linkedMuchTrack.first || chi2 < stsTrack->linkedMuchTrack.second) { - list<pair<LxSimpleTrack*, scaltype>>::iterator r = muchTrack->linkedStsTracks.begin(); - - for (; r != muchTrack->linkedStsTracks.end() && r->second <= chi2; ++r) - ; - - pair<LxSimpleTrack*, scaltype> trackDesc(stsTrack, chi2); - muchTrack->linkedStsTracks.insert(r, trackDesc); - } - } - } - } - } // for (vector<LxSimpleTrack*>::iterator l = allTracks.begin(); l != allTracks.end(); ++l) - - if (!muchTrack->linkedStsTracks.empty()) { - pair<LxSimpleTrack*, scaltype> trackDesc = muchTrack->linkedStsTracks.front(); - muchTrack->linkedStsTracks.pop_front(); - LxSimpleTrack* anotherMuchTrack = trackDesc.first->linkedMuchTrack.first; - trackDesc.first->linkedMuchTrack.first = muchTrack; - trackDesc.first->linkedMuchTrack.second = trackDesc.second; - muchTrack->linkedStsTrack = trackDesc.first; - - if (0 != anotherMuchTrack) anotherMuchTrack->RebindMuchTrack(); - } -} diff --git a/reco/tracking/lx/Simple/LxTrackAna.h b/reco/tracking/lx/Simple/LxTrackAna.h deleted file mode 100644 index 79783db4b25f63b55c4949ff4be6bac385e48388..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/Simple/LxTrackAna.h +++ /dev/null @@ -1,141 +0,0 @@ -/* Copyright (C) 2014-2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifndef LXTRACKANA_INCLUDED -#define LXTRACKANA_INCLUDED - -#pragma GCC diagnostic ignored "-Weffc++" - -#include "CbmMuchPixelHit.h" - -#include "FairTask.h" - -#include "TClonesArray.h" - -#include <list> -#include <vector> - -#include "LxSettings.h" -#include "LxTrackAnaSegments.h" - -struct LxSimplePoint { - scaltype x; - scaltype y; - scaltype z; - scaltype tx; - scaltype ty; - LxSimplePoint() : x(0), y(0), z(0), tx(0), ty(0) {} - LxSimplePoint(scaltype X, scaltype Y, scaltype Z, scaltype Tx, scaltype Ty) : x(X), y(Y), z(Z), tx(Tx), ty(Ty) {} -}; - -struct LxSimpleTrack { - Int_t pdgCode; - Int_t motherId; - scaltype p; - scaltype pt; - scaltype px; - scaltype py; - scaltype pz; - scaltype e; - scaltype charge; - LxSimpleTrack(Int_t pdgc, Int_t mid, scaltype P, scaltype Pt, scaltype Px, scaltype Py, scaltype Pz, scaltype E) - : pdgCode(pdgc) - , motherId(mid) - , p(P) - , pt(Pt) - , px(Px) - , py(Py) - , pz(Pz) - , e(E) - , charge(0) - , linkedMuchTrack(0, 0) - , linkedStsTrack(0) - { - } - std::list<LxSimplePoint> stsPoints[LXSTSSTATIONS]; - std::list<LxSimplePoint> muchPoints[LXSTATIONS][LXLAYERS]; - std::list<LxSimplePoint> - muchMCPts[LXSTATIONS] - [LXLAYERS]; // These array is used for storing MUCH MC points when the 'main' array contains hits. - std::pair<LxSimpleTrack*, scaltype> linkedMuchTrack; - std::list<std::pair<LxSimpleTrack*, scaltype>> - linkedStsTracks; // The front() contains STS track with the minimal chi2. - LxSimpleTrack* linkedStsTrack; - void RebindMuchTrack(); -}; - -class LxTrackAna : public FairTask { -public: - LxTrackAna(); - ~LxTrackAna(); - InitStatus Init(); // Inherited virtual. - void Exec(Option_t* opt); // Inherited virtual. - void FinishTask(); // Inherited virtual. - bool GetUseHitsInStat() const { return useHitsInStat; } - void SetUseHitsInStat(bool v) { useHitsInStat = v; } - bool GetAveragePoints() const { return averagePoints; } - void SetAveragePoints(bool v) { averagePoints = v; } - bool GetDontTouchNonPrimary() const { return dontTouchNonPrimary; } - void SetDontTouchNonPrimary(bool v) { dontTouchNonPrimary = v; } - bool GetUseChargeSignInCuts() const { return useChargeSignInCuts; } - void SetUseChargeSignInCuts(bool v) { useChargeSignInCuts = v; } - bool GetBuildConnectStat() const { return buildConnectStat; } - void SetBuildConnectStat(bool v) { buildConnectStat = v; } - bool GetBuildBgrInvMass() const { return buildBgrInvMass; } - void SetBuildBgrInvMass(bool v) { buildBgrInvMass = v; } - bool GetBuildSigInvMass() const { return buildSigInvMass; } - void SetBuildSigInvMass(bool v) { buildSigInvMass = v; } - bool GetJoinData() const { return joinData; } - void SetJoinData(bool v) { joinData = v; } - bool GetBuildNearestHitDist() const { return buildNearestHitDist; } - void SetBuildNearestHitDist(bool v) { buildNearestHitDist = v; } - bool GetCropHits() const { return cropHits; } - void SetCropHits(bool v) { cropHits = v; } - bool GetBuildSegmentsStat() const { return buildSegmentsStat; } - void SetBuildSegmentsStat(bool v) { buildSegmentsStat = v; } - TString GetParticleType() const { return particleType; } - void SetParticleType(TString v) - { - particleType = v; - segmentsAnalyzer.SetParticleType(v); - } - -private: - void Clean(); - void AveragePoints(); - void BuildStatistics(); - void Connect(bool useCuts); - void Connect(LxSimpleTrack* muchTrack, LxSimplePoint muchPt0, scaltype txMuch, scaltype tyMuch, bool useCuts); - - TClonesArray* listMCTracks; - TClonesArray* listStsPts; - TClonesArray* listMuchPts; - TClonesArray* listMuchPixelHits; - TClonesArray* listMuchClusters; - TClonesArray* listMuchPixelDigiMatches; - std::vector<LxSimpleTrack*> allTracks; - std::list<LxSimpleTrack*> posTracks; - std::list<LxSimpleTrack*> negTracks; - TTree* superEventTracks; - LxSimpleTrack superEventBrachTrack; - bool useHitsInStat; - bool averagePoints; - bool dontTouchNonPrimary; - bool useChargeSignInCuts; - bool buildConnectStat; - bool buildBgrInvMass; - bool buildSigInvMass; - bool joinData; - bool buildNearestHitDist; - bool cropHits; - bool buildSegmentsStat; - TString particleType; - LxTrackAnaSegments segmentsAnalyzer; - - friend class LxTrackAnaSegments; - - ClassDef(LxTrackAna, 1); -}; - -#endif //LXTRACKANA_INCLUDED diff --git a/reco/tracking/lx/Simple/LxTrackAnaSegments.cxx b/reco/tracking/lx/Simple/LxTrackAnaSegments.cxx deleted file mode 100644 index dc650c098ef93b0041876754f053fcfae4f9a5a0..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/Simple/LxTrackAnaSegments.cxx +++ /dev/null @@ -1,530 +0,0 @@ -/* Copyright (C) 2014-2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#include "LxTrackAnaSegments.h" - -#include "TH1.h" -#include "TH2.h" - -#include <cmath> -#include <dirent.h> -#include <sys/stat.h> -#include <sys/types.h> - -#include "LxTrackAna.h" - -using namespace std; - -static TH1F* muchInStationXDispLeft[LXSTATIONS]; -static TH1F* muchInStationXDispRight[LXSTATIONS]; -static TH1F* muchInStationYDispLeft[LXSTATIONS]; -static TH1F* muchInStationYDispRight[LXSTATIONS]; - -static TH1F* muchInStationXDispRL[LXSTATIONS]; -static TH1F* muchInStationYDispRL[LXSTATIONS]; - -static TH1F* muchInStationTxBreak[LXSTATIONS]; -static TH1F* muchInStationTyBreak[LXSTATIONS]; - -static TH1F* muchOutStationTxBreakLeft[LXSTATIONS - 1]; -static TH1F* muchOutStationTxBreakRight[LXSTATIONS - 1]; -static TH1F* muchOutStationTyBreakLeft[LXSTATIONS - 1]; -static TH1F* muchOutStationTyBreakRight[LXSTATIONS - 1]; - -static TH1F* muchOutStationXDispByTriplet[LXSTATIONS - 1]; -static TH1F* muchOutStationYDispByTriplet[LXSTATIONS - 1]; - -static TH1F* muchOutStationXDispByVertex[LXSTATIONS - 1]; -static TH1F* muchOutStationYDispByVertex[LXSTATIONS - 1]; - -static TH1F* muchLongSegmentTxHisto[LXSTATIONS - 1]; -static TH1F* muchLongSegmentTyHisto[LXSTATIONS - 1]; - -static TH1F* muchSegmentTxBreakHisto[LXSTATIONS - 2]; -static TH1F* muchSegmentTyBreakHisto[LXSTATIONS - 2]; - -static TH1F* muchStationTxDispHisto[LXSTATIONS - 1]; -static TH1F* muchStationTyDispHisto[LXSTATIONS - 1]; - -static TH2F* muchXTxCovHisto[LXSTATIONS - 1]; -static TH2F* muchYTyCovHisto[LXSTATIONS - 1]; - -static TH1F* muchClusterXDispHisto[LXSTATIONS - 1]; -static TH1F* muchClusterYDispHisto[LXSTATIONS - 1]; -static TH1F* muchClusterTxDispHisto[LXSTATIONS - 1]; -static TH1F* muchClusterTyDispHisto[LXSTATIONS - 1]; - -LxTrackAnaSegments::LxTrackAnaSegments(LxTrackAna& o) : owner(o), stationsInAlgo(LXSTATIONS) {} - -static TString particleType("jpsi"); - -void LxTrackAnaSegments::SetParticleType(TString v) -{ - particleType = v; - - if (v == "omega") stationsInAlgo = 5; -} - -void LxTrackAnaSegments::Init() -{ - char name[64]; - char title[256]; - - for (Int_t i = 0; i < LXSTATIONS; ++i) { - sprintf(name, "muchInStationXDispLeft_%d", i); - sprintf(title, "X dispersion from central to left layer inside station: %d", i); - muchInStationXDispLeft[i] = new TH1F(name, title, 100, -3.0, 3.0); - muchInStationXDispLeft[i]->StatOverflows(); - - sprintf(name, "muchInStationXDispRight_%d", i); - sprintf(title, "X dispersion from central to right layer inside station: %d", i); - muchInStationXDispRight[i] = new TH1F(name, title, 100, -3.0, 3.0); - muchInStationXDispRight[i]->StatOverflows(); - - sprintf(name, "muchInStationYDispLeft_%d", i); - sprintf(title, "Y dispersion from central to left layer inside station: %d", i); - muchInStationYDispLeft[i] = new TH1F(name, title, 100, -3.0, 3.0); - muchInStationYDispLeft[i]->StatOverflows(); - - sprintf(name, "muchInStationYDispRight_%d", i); - sprintf(title, "Y dispersion from central to right layer inside station: %d", i); - muchInStationYDispRight[i] = new TH1F(name, title, 100, -3.0, 3.0); - muchInStationYDispRight[i]->StatOverflows(); - - sprintf(name, "muchInStationXDispRL_%d", i); - sprintf(title, "X dispersion on left layer predicted by right station: %d", i); - muchInStationXDispRL[i] = new TH1F(name, title, 100, -0.1, 0.1); - muchInStationXDispRL[i]->StatOverflows(); - - sprintf(name, "muchInStationYDispRL_%d", i); - sprintf(title, "Y dispersion on left layer predicted by right station: %d", i); - muchInStationYDispRL[i] = new TH1F(name, title, 100, -0.1, 0.1); - muchInStationYDispRL[i]->StatOverflows(); - - sprintf(name, "muchInStationTxBreak_%d", i); - sprintf(title, "Tx break inside station: %d", i); - muchInStationTxBreak[i] = new TH1F(name, title, 100, -0.02, 0.02); - muchInStationTxBreak[i]->StatOverflows(); - - sprintf(name, "muchInStationTyBreak_%d", i); - sprintf(title, "Ty break inside station: %d", i); - muchInStationTyBreak[i] = new TH1F(name, title, 100, -0.02, 0.02); - muchInStationTyBreak[i]->StatOverflows(); - - if (i > 0) { - sprintf(name, "muchLongSegmentTxHisto_%d", i); - sprintf(title, "Tx tangents distribution for segments between stations: %d and %d", i - 1, i); - muchLongSegmentTxHisto[i - 1] = new TH1F(name, title, 100, -.15, .15); - muchLongSegmentTxHisto[i - 1]->StatOverflows(); - - sprintf(name, "muchLongSegmentTyHisto_%d", i); - sprintf(title, "Ty tangents distribution for segments between stations: %d and %d", i - 1, i); - muchLongSegmentTyHisto[i - 1] = new TH1F(name, title, 100, -.15, .15); - muchLongSegmentTyHisto[i - 1]->StatOverflows(); - - sprintf(name, "muchClusterXDispHisto_%d", i); - sprintf(title, - "X coordinate dispersion for cluster segments between stations: " - "%d and %d", - i - 1, i); - muchClusterXDispHisto[i - 1] = new TH1F(name, title, 100, .0, 3.0); - muchClusterXDispHisto[i - 1]->StatOverflows(); - - sprintf(name, "muchClusterYDispHisto_%d", i); - sprintf(title, - "Y coordinate dispersion for cluster segments between stations: " - "%d and %d", - i - 1, i); - muchClusterYDispHisto[i - 1] = new TH1F(name, title, 100, .0, 3.0); - muchClusterYDispHisto[i - 1]->StatOverflows(); - - sprintf(name, "muchClusterTxDispHisto_%d", i); - sprintf(title, - "Tx tangent dispersion for cluster segments between stations: %d " - "and %d", - i - 1, i); - muchClusterTxDispHisto[i - 1] = new TH1F(name, title, 100, .0, .05); - muchClusterTxDispHisto[i - 1]->StatOverflows(); - - sprintf(name, "muchClusterTyDispHisto_%d", i); - sprintf(title, - "Ty tangent dispersion for cluster segments between stations: %d " - "and %d", - i - 1, i); - muchClusterTyDispHisto[i - 1] = new TH1F(name, title, 100, .0, .05); - muchClusterTyDispHisto[i - 1]->StatOverflows(); - - sprintf(name, "muchOutStationTxBreakLeft_%d", i); - sprintf(title, - "Tx break between right segment of station and left tip of the " - "interstation segment: %d", - i); - muchOutStationTxBreakLeft[i - 1] = new TH1F(name, title, 100, -0.15, 0.15); - muchOutStationTxBreakLeft[i - 1]->StatOverflows(); - - sprintf(name, "muchOutStationTxBreakRight_%d", i); - sprintf(title, - "Tx break between left segment of station and right tip of the " - "interstation segment: %d", - i); - muchOutStationTxBreakRight[i - 1] = new TH1F(name, title, 100, -0.15, 0.15); - muchOutStationTxBreakRight[i - 1]->StatOverflows(); - - sprintf(name, "muchOutStationTyBreakLeft_%d", i); - sprintf(title, - "Ty break between right segment of station and left tip of the " - "interstation segment: %d", - i); - muchOutStationTyBreakLeft[i - 1] = new TH1F(name, title, 100, -0.15, 0.15); - muchOutStationTyBreakLeft[i - 1]->StatOverflows(); - - sprintf(name, "muchOutStationTyBreakRight_%d", i); - sprintf(title, - "Ty break between left segment of station and right tip of the " - "interstation segment: %d", - i); - muchOutStationTyBreakRight[i - 1] = new TH1F(name, title, 100, -0.15, 0.15); - muchOutStationTyBreakRight[i - 1]->StatOverflows(); - - sprintf(name, "muchOutStationXDispByTriplet_%d", i); - sprintf(title, "X dispersion of prediction by triplet angle for station: %d", i); - muchOutStationXDispByTriplet[i - 1] = new TH1F(name, title, 100, -10.0, 10.0); - muchOutStationXDispByTriplet[i - 1]->StatOverflows(); - - sprintf(name, "muchOutStationYDispByTriplet_%d", i); - sprintf(title, "Y dispersion of prediction by triplet angle for station: %d", i); - muchOutStationYDispByTriplet[i - 1] = new TH1F(name, title, 100, -10.0, 10.0); - muchOutStationYDispByTriplet[i - 1]->StatOverflows(); - - sprintf(name, "muchOutStationXDispByVertex_%d", i); - sprintf(title, "X dispersion of prediction by an angle to vertex for station: %d", i); - muchOutStationXDispByVertex[i - 1] = new TH1F(name, title, 100, -10.0, 10.0); - muchOutStationXDispByVertex[i - 1]->StatOverflows(); - - sprintf(name, "muchOutStationYDispByVertex_%d", i); - sprintf(title, "Y dispersion of prediction by an angle to vertex for station: %d", i); - muchOutStationYDispByVertex[i - 1] = new TH1F(name, title, 100, -10.0, 10.0); - muchOutStationYDispByVertex[i - 1]->StatOverflows(); - - if (i < LXSTATIONS - 1) { - sprintf(name, "muchSegmentTxBreakHisto_%d", i); - sprintf(title, - "Tx tangents breaks distribution for adjacent segments on " - "station: %d", - i); - muchSegmentTxBreakHisto[i - 1] = new TH1F(name, title, 100, -.15, .15); - muchSegmentTxBreakHisto[i - 1]->StatOverflows(); - - sprintf(name, "muchSegmentTyBreakHisto_%d", i); - sprintf(title, - "Ty tangents breaks distribution for adjacent segments on " - "station: %d", - i); - muchSegmentTyBreakHisto[i - 1] = new TH1F(name, title, 100, -.15, .15); - muchSegmentTyBreakHisto[i - 1]->StatOverflows(); - } - - sprintf(name, "muchStationTxDispHisto_%d", i); - sprintf(title, "Tx tangents dispersion for segments between stations: %d and %d", i - 1, i); - muchStationTxDispHisto[i - 1] = new TH1F(name, title, 100, -.05, .05); - muchStationTxDispHisto[i - 1]->StatOverflows(); - - sprintf(name, "muchStationTyDispHisto_%d", i); - sprintf(title, "Ty tangents dispersion for segments between stations: %d and %d", i - 1, i); - muchStationTyDispHisto[i - 1] = new TH1F(name, title, 100, -.05, .05); - muchStationTyDispHisto[i - 1]->StatOverflows(); - } - - if (i < LXSTATIONS - 1) { - sprintf(name, "muchXTxCovHisto_%d", i); - sprintf(title, "muchXTxCovHisto on %d", i); - muchXTxCovHisto[i] = new TH2F(name, title, 100, -5.0, 5.0, 100, -0.15, 0.15); - muchXTxCovHisto[i]->StatOverflows(); - - sprintf(name, "muchYTyCovHisto_%d", i); - sprintf(title, "muchYTyCovHisto on %d", i); - muchYTyCovHisto[i] = new TH2F(name, title, 100, -5.0, 5.0, 100, -0.15, 0.15); - muchYTyCovHisto[i]->StatOverflows(); - } - } -} - -static void SaveHisto(TH1* histo) -{ - char dir_name[256]; - sprintf(dir_name, "configuration.%s", particleType.Data()); - DIR* dir = opendir(dir_name); - - if (dir) closedir(dir); - else - mkdir(dir_name, 0700); - - char name[256]; - sprintf(name, "%s/%s.root", dir_name, histo->GetName()); - TFile fh(name, "RECREATE"); - histo->Write(); - fh.Close(); - delete histo; -} - -void LxTrackAnaSegments::Finish() -{ - for (Int_t i = 0; i < LXSTATIONS; ++i) { - SaveHisto(muchInStationXDispLeft[i]); - SaveHisto(muchInStationXDispRight[i]); - SaveHisto(muchInStationYDispLeft[i]); - SaveHisto(muchInStationYDispRight[i]); - SaveHisto(muchInStationXDispRL[i]); - SaveHisto(muchInStationYDispRL[i]); - SaveHisto(muchInStationTxBreak[i]); - SaveHisto(muchInStationTyBreak[i]); - - if (i > 0) { - SaveHisto(muchLongSegmentTxHisto[i - 1]); - SaveHisto(muchLongSegmentTyHisto[i - 1]); - - SaveHisto(muchClusterXDispHisto[i - 1]); - SaveHisto(muchClusterYDispHisto[i - 1]); - SaveHisto(muchClusterTxDispHisto[i - 1]); - SaveHisto(muchClusterTyDispHisto[i - 1]); - - SaveHisto(muchOutStationTxBreakLeft[i - 1]); - SaveHisto(muchOutStationTxBreakRight[i - 1]); - SaveHisto(muchOutStationTyBreakLeft[i - 1]); - SaveHisto(muchOutStationTyBreakRight[i - 1]); - - SaveHisto(muchOutStationXDispByTriplet[i - 1]); - SaveHisto(muchOutStationYDispByTriplet[i - 1]); - SaveHisto(muchOutStationXDispByVertex[i - 1]); - SaveHisto(muchOutStationYDispByVertex[i - 1]); - - if (i < LXSTATIONS - 1) { - SaveHisto(muchSegmentTxBreakHisto[i - 1]); - SaveHisto(muchSegmentTyBreakHisto[i - 1]); - } - - SaveHisto(muchStationTxDispHisto[i - 1]); - SaveHisto(muchStationTyDispHisto[i - 1]); - } - - if (i < LXSTATIONS - 1) { - SaveHisto(muchXTxCovHisto[i]); - SaveHisto(muchYTyCovHisto[i]); - } - } -} - -void LxTrackAnaSegments::BuildStatistics() -{ - vector<LxSimpleTrack*>& tracks = owner.allTracks; - - for (vector<LxSimpleTrack*>::iterator i = tracks.begin(); i != tracks.end(); ++i) { - LxSimpleTrack* track = *i; - - if (0 > track->motherId && (13 == track->pdgCode || -13 == track->pdgCode)) StatForTrack(track); - } -} - -struct LxSimpleSegment { - LxSimplePoint source; - LxSimplePoint end; - scaltype tx; - scaltype ty; - - LxSimpleSegment() : tx(0), ty(0) {} - LxSimpleSegment(LxSimplePoint s, LxSimplePoint e) - : source(s) - , end(e) - , tx((e.x - s.x) / (e.z - s.z)) - , ty((e.y - s.y) / (e.z - s.z)) - { - } -}; - -void LxTrackAnaSegments::StatForTrack(LxSimpleTrack* track) -{ - for (Int_t i = 0; i < stationsInAlgo; ++i) { - for (Int_t j = 0; j < LXLAYERS; ++j) { - if (track->muchPoints[i][j].empty()) return; - } - } - - LxSimplePoint p1; - LxSimplePoint p2; - LxSimplePoint p3; - scaltype deltaZ; - scaltype deltaZ2; - scaltype tx; - scaltype tx2; - scaltype ty; - scaltype ty2; - scaltype stTx; - scaltype stTy; - scaltype stTxP; - scaltype stTyP; - - for (Int_t i = 0; i < LXSTATIONS; ++i) { - if (track->muchPoints[i][0].empty() || track->muchPoints[i][1].empty() || track->muchPoints[i][2].empty()) continue; - - p1 = track->muchPoints[i][1].front(); - scaltype txEst = p1.x / p1.z; - scaltype tyEst = p1.y / p1.z; - - p2 = track->muchPoints[i][0].front(); - deltaZ = p2.z - p1.z; - scaltype xEst = p1.x + txEst * deltaZ; - scaltype yEst = p1.y + tyEst * deltaZ; - muchInStationXDispLeft[i]->Fill(p2.x - xEst); - muchInStationYDispLeft[i]->Fill(p2.y - yEst); - tx = (p2.x - p1.x) / deltaZ; - ty = (p2.y - p1.y) / deltaZ; - - p2 = track->muchPoints[i][2].front(); - deltaZ = p2.z - p1.z; - xEst = p1.x + txEst * deltaZ; - yEst = p1.y + tyEst * deltaZ; - muchInStationXDispRight[i]->Fill(p2.x - xEst); - muchInStationYDispRight[i]->Fill(p2.y - yEst); - - tx2 = (p2.x - p1.x) / deltaZ; - ty2 = (p2.y - p1.y) / deltaZ; - - muchInStationTxBreak[i]->Fill(tx2 - tx); - muchInStationTyBreak[i]->Fill(ty2 - ty); - - stTxP = stTx; - stTyP = stTy; - p1 = track->muchPoints[i][0].front(); - deltaZ = p2.z - p1.z; - stTx = (p2.x - p1.x) / deltaZ; - stTy = (p2.y - p1.y) / deltaZ; - muchInStationXDispRL[i]->Fill(p1.x - p2.x + tx2 * deltaZ); - muchInStationYDispRL[i]->Fill(p1.y - p2.y + ty2 * deltaZ); - - if (i > 0) { - p1 = track->muchPoints[i - 1][LXMIDDLE].front(); - p2 = track->muchPoints[i][LXMIDDLE].front(); - deltaZ = p2.z - p1.z; - tx = (p2.x - p1.x) / deltaZ; - muchLongSegmentTxHisto[i - 1]->Fill(tx - p2.x / p2.z); - ty = (p2.y - p1.y) / deltaZ; - muchLongSegmentTyHisto[i - 1]->Fill(ty - p2.y / p2.z); - - muchOutStationTxBreakRight[i - 1]->Fill(tx - stTx); - muchOutStationTyBreakRight[i - 1]->Fill(ty - stTy); - - muchOutStationTxBreakLeft[i - 1]->Fill(tx - stTxP); - muchOutStationTyBreakLeft[i - 1]->Fill(ty - stTyP); - - muchOutStationXDispByTriplet[i - 1]->Fill(p1.x - p2.x + stTx * deltaZ); - muchOutStationYDispByTriplet[i - 1]->Fill(p1.y - p2.y + stTy * deltaZ); - - muchOutStationXDispByVertex[i - 1]->Fill(p1.x - p2.x + (p2.x / p2.z) * deltaZ); - muchOutStationYDispByVertex[i - 1]->Fill(p1.y - p2.y + (p2.y / p2.z) * deltaZ); - - // Rather complex part for implementation: calculate the dispersion characteristics for segment clusters. - scaltype maxXdisp = 0; - scaltype maxYdisp = 0; - scaltype maxTxdisp = 0; - scaltype maxTydisp = 0; - - for (list<LxSimplePoint>::iterator l0 = track->muchPoints[i - 1][0].begin(); - l0 != track->muchPoints[i - 1][0].end(); ++l0) { - for (list<LxSimplePoint>::iterator l1 = track->muchPoints[i - 1][1].begin(); - l1 != track->muchPoints[i - 1][1].end(); ++l1) { - for (list<LxSimplePoint>::iterator l2 = track->muchPoints[i - 1][2].begin(); - l2 != track->muchPoints[i - 1][2].end(); ++l2) { - for (list<LxSimplePoint>::iterator r0 = track->muchPoints[i][0].begin(); - r0 != track->muchPoints[i][0].end(); ++r0) { - for (list<LxSimplePoint>::iterator r1 = track->muchPoints[i][1].begin(); - r1 != track->muchPoints[i][1].end(); ++r1) { - for (list<LxSimplePoint>::iterator r2 = track->muchPoints[i][2].begin(); - r2 != track->muchPoints[i][2].end(); ++r2) { - LxSimplePoint lPoints[LXLAYERS] = {*l0, *l1, *l2}; - LxSimplePoint rPoints[LXLAYERS] = {*r0, *r1, *r2}; - LxSimpleSegment segments[LXLAYERS * LXLAYERS] = {}; - - for (Int_t j = 0; j < LXLAYERS; ++j) { - for (Int_t k = 0; k < LXLAYERS; ++k) - segments[j * LXLAYERS + k] = LxSimpleSegment(rPoints[j], lPoints[k]); - } - - for (Int_t j = 0; j < LXLAYERS * LXLAYERS - 1; ++j) { - LxSimpleSegment s1 = segments[j]; - - for (Int_t k = j + 1; k < LXLAYERS * LXLAYERS; ++k) { - LxSimpleSegment s2 = segments[k]; - scaltype diffZ = s1.source.z - s2.source.z; - scaltype dtx = abs(s2.tx - s1.tx); - scaltype dty = abs(s2.ty - s1.ty); - scaltype dx = abs(s2.source.x + s2.tx * diffZ - s1.source.x); - scaltype dy = abs(s2.source.y + s2.ty * diffZ - s1.source.y); - - if (maxXdisp < dx) maxXdisp = dx; - - if (maxYdisp < dy) maxYdisp = dy; - - if (maxTxdisp < dtx) maxTxdisp = dtx; - - if (maxTydisp < dty) maxTydisp = dty; - } - } - } - } - } - } - } - } // for (list<LxSimplePoint>::iterator l0 = track->muchPoints[i - 1][0].begin(); l0 != track->muchPoints[i - 1][0].end(); ++l0) - - muchClusterXDispHisto[i - 1]->Fill(maxXdisp); - muchClusterYDispHisto[i - 1]->Fill(maxYdisp); - muchClusterTxDispHisto[i - 1]->Fill(maxTxdisp); - muchClusterTyDispHisto[i - 1]->Fill(maxTydisp); - - if (i < LXSTATIONS - 1) { - p1 = track->muchPoints[i - 1][LXMIDDLE].front(); - p2 = track->muchPoints[i][LXMIDDLE].front(); - deltaZ = p2.z - p1.z; - tx = (p2.x - p1.x) / deltaZ; - ty = (p2.y - p1.y) / deltaZ; - p3 = track->muchPoints[i + 1][LXMIDDLE].front(); - deltaZ2 = p3.z - p2.z; - tx2 = (p3.x - p2.x) / deltaZ2; - muchSegmentTxBreakHisto[i - 1]->Fill(tx2 - tx); - ty2 = (p3.y - p2.y) / deltaZ2; - muchSegmentTyBreakHisto[i - 1]->Fill(ty2 - ty); - } - - for (Int_t j = 0; j < LXLAYERS * LXLAYERS; ++j) { - p1 = track->muchPoints[i - 1][j % LXLAYERS].front(); - p2 = track->muchPoints[i][j / LXLAYERS].front(); - deltaZ = p2.z - p1.z; - tx = (p2.x - p1.x) / deltaZ; - ty = (p2.y - p1.y) / deltaZ; - - for (Int_t k = j + 1; k < LXLAYERS * LXLAYERS; ++k) { - p1 = track->muchPoints[i - 1][k % LXLAYERS].front(); - p2 = track->muchPoints[i][k / LXLAYERS].front(); - deltaZ = p2.z - p1.z; - tx2 = (p2.x - p1.x) / deltaZ; - muchStationTxDispHisto[i - 1]->Fill(tx2 - tx); - ty2 = (p2.y - p1.y) / deltaZ; - muchStationTyDispHisto[i - 1]->Fill(ty2 - ty); - } - } - } - - if (i < LXSTATIONS - 1) { - p1 = track->muchPoints[i + 1][LXMIDDLE].front(); - p2 = track->muchPoints[i][LXMIDDLE].front(); - deltaZ = p2.z - p1.z; - scaltype deltaX = p2.x - p1.x - p1.tx * deltaZ; - scaltype deltaY = p2.y - p1.y - p1.ty * deltaZ; - scaltype deltaTx = p2.tx - p1.tx; - scaltype deltaTy = p2.ty - p1.ty; - muchXTxCovHisto[i]->Fill(deltaX, deltaTx); - muchYTyCovHisto[i]->Fill(deltaY, deltaTy); - } - } -} diff --git a/reco/tracking/lx/Simple/LxTrackAnaSegments.h b/reco/tracking/lx/Simple/LxTrackAnaSegments.h deleted file mode 100644 index 04e876aa46aa4d645750f5f59b8f5f3b6293d07c..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/Simple/LxTrackAnaSegments.h +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (C) 2014-2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifndef LXTRACKANASEGMENTS_INCLUDED -#define LXTRACKANASEGMENTS_INCLUDED - -#pragma GCC diagnostic ignored "-Weffc++" - -#include "TString.h" - -struct LxSimpleTrack; -class LxTrackAna; - -class LxTrackAnaSegments { -public: - explicit LxTrackAnaSegments(LxTrackAna& o); - void Init(); - void Finish(); - void BuildStatistics(); - void SetParticleType(TString v); - -private: - void StatForTrack(LxSimpleTrack* track); - LxTrackAna& owner; - Int_t stationsInAlgo; -}; - -#endif //LXTRACKANASEGMENTS_INCLUDED diff --git a/reco/tracking/lx/Simple/LxTrigger.cxx b/reco/tracking/lx/Simple/LxTrigger.cxx deleted file mode 100644 index ba02fa7c04e2b15d3459ab0bc0e48e1a19853119..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/Simple/LxTrigger.cxx +++ /dev/null @@ -1,116 +0,0 @@ -/* Copyright (C) 2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#include "TDatabasePDG.h" - -#include "Lx.h" - -using namespace std; - -bool LxFinder::Trigger() -{ - bool trigging = false; - - for (list<LxTrack*>::iterator i = caSpace.tracks.begin(); i != caSpace.tracks.end(); ++i) { - LxTrack* first = *i; - - if (first->clone) continue; - - list<LxTrack*>::iterator j = i; - ++j; - - for (; j != caSpace.tracks.end(); ++j) { - LxTrack* second = *j; - - if (second->clone) continue; - - LxRay* firstRay = first->rays[0]; - LxPoint* firstPoint = firstRay->end; - LxRay* secondRay = second->rays[0]; - LxPoint* secondPoint = secondRay->end; - - scaltype firstParticleCharge = firstRay->tx - firstPoint->x / firstPoint->z; - scaltype secondParticleCharge = secondRay->tx - secondPoint->x / secondPoint->z; - bool distanceOk = true; - - if (pPtCut) { - scaltype deltaX = firstPoint->x - secondPoint->x; - scaltype deltaY = firstPoint->y - secondPoint->y; - scaltype distance = sqrt(deltaX * deltaX + deltaY * deltaY); - distanceOk = distance >= 50.0; - } - - first->distanceOk = first->distanceOk || distanceOk; - second->distanceOk = second->distanceOk || distanceOk; - bool oppCharged = firstParticleCharge * secondParticleCharge < 0; - first->oppCharged = first->oppCharged || oppCharged; - second->oppCharged = second->oppCharged || oppCharged; - bool triggering = distanceOk && oppCharged; - first->triggering = first->triggering || triggering; - second->triggering = second->triggering || triggering; - trigging = trigging || triggering; - } - } - -#ifdef MAKE_TRIGGERING_HISTOS - for (list<LxTrack*>::iterator i = caSpace.tracks.begin(); i != caSpace.tracks.end(); ++i) { - LxTrack* recoTrack = *i; - - if (recoTrack->clone) continue; - - LxMCTrack* mcTrack = recoTrack->mcTrack; - string particleName(mcTrack ? TDatabasePDG::Instance()->GetParticle(mcTrack->pdg)->GetName() : "ghost"); - - if (!particleName.empty() && (particleName.back() == '+' || particleName.back() == '-')) particleName.pop_back(); - - map<string, unsigned int>::iterator j = particlesCountAll.find(particleName); - - if (j != particlesCountAll.end()) ++(j->second); - else - particlesCountAll[particleName] = 1; - - if (recoTrack->distanceOk) { - j = particlesCountDist.find(particleName); - - if (j != particlesCountDist.end()) ++(j->second); - else - particlesCountDist[particleName] = 1; - } - - if (recoTrack->oppCharged) { - j = particlesCountSign.find(particleName); - - if (j != particlesCountSign.end()) ++(j->second); - else - particlesCountSign[particleName] = 1; - } - - if (recoTrack->triggering) { - j = particlesCountTrig.find(particleName); - - if (j != particlesCountTrig.end()) ++(j->second); - else - particlesCountTrig[particleName] = 1; - } - - if (0 == mcTrack) continue; - - if (13 != mcTrack->pdg && -13 != mcTrack->pdg) continue; - - triggeringAllTracksVertices->Fill(mcTrack->z); // Save arbitrary track info. - - if (recoTrack->distanceOk) - triggeringDistTracksVertices->Fill(mcTrack->z); // Save track fulfilling distance criterion info. - - if (recoTrack->oppCharged) - triggeringSignTracksVertices->Fill(mcTrack->z); // Save track fulfilling signs criterion info. - - if (recoTrack->triggering) - triggeringTrigTracksVertices->Fill( - mcTrack->z); // Save track fulfilling the both criteria above (triggering track) info. - } -#endif //MAKE_TRIGGERING_HISTOS - - return trigging; -} diff --git a/reco/tracking/lx/Simple/LxUtils.cxx b/reco/tracking/lx/Simple/LxUtils.cxx deleted file mode 100644 index 80261d0bfd1f52dc215887154d6216c1196bb106..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/Simple/LxUtils.cxx +++ /dev/null @@ -1,45 +0,0 @@ -/* Copyright (C) 2014-2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#include "Lx.h" - -using namespace std; - -// Used for building of the background on an invariant mass. -void LxFinder::SaveEventTracks() -{ -#ifdef MAKE_HISTOS - for (list<LxTrack*>::iterator i = caSpace.tracks.begin(); i != caSpace.tracks.end(); ++i) { - LxTrack* firstTrack = *i; - - if (0 == firstTrack->externalTrack) continue; - - CbmStsTrack t = *firstTrack->externalTrack->track; - - if (t.GetParamLast()->GetQp() > 0) extFitter.DoFit(&t, -13); - else - extFitter.DoFit(&t, 13); - - // scaltype chi2Prim = extFitter.GetChiToVertex(&t, fPrimVtx); - extFitter.GetChiToVertex(&t, fPrimVtx); - FairTrackParam params; - extFitter.Extrapolate(&t, fPrimVtx->GetZ(), ¶ms); - - scaltype p = 1 / params.GetQp(); - scaltype p2 = p * p; - - if (p2 < 9) continue; - - scaltype tx2 = params.GetTx() * params.GetTx(); - scaltype ty2 = params.GetTy() * params.GetTy(); - scaltype pt2 = p2 * (tx2 + ty2) / (1 + tx2 + ty2); - - if (pt2 < 1) continue; - - t.SetParamFirst(¶ms); - *superEventData = t; - superEventTracks->Fill(); - } -#endif //MAKE_HISTOS -} diff --git a/reco/tracking/lx/Simple/LxUtils.h b/reco/tracking/lx/Simple/LxUtils.h deleted file mode 100644 index 9c4b8e00b58236e403778703f12f92c15ea16f03..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/Simple/LxUtils.h +++ /dev/null @@ -1,12 +0,0 @@ -/* Copyright (C) 2014 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifndef LXUTILS_INCLUDED -#define LXUTILS_INCLUDED - -#pragma GCC diagnostic ignored "-Weffc++" - -// Just to make happy the building system -- now it does not contain any definition. - -#endif //LXUTILS_INCLUDED diff --git a/reco/tracking/lx/TBBinned/LxTBBinned.h b/reco/tracking/lx/TBBinned/LxTBBinned.h deleted file mode 100644 index 1d20e1e1fd7d4fcf74bfa9bd8311b55b693226f0..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/TBBinned/LxTBBinned.h +++ /dev/null @@ -1,1312 +0,0 @@ -/* Copyright (C) 2016-2018 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt - SPDX-License-Identifier: GPL-3.0-only - Authors: Florian Uhlig [committer] */ - -/* To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor.*/ - -#ifndef LXTBBINNED_H -#define LXTBBINNED_H - -#include "LxTBDefinitions.h" -#include "LxTBMatEffs.h" - - -#ifdef __MACH__ -#include <mach/mach_time.h> -#include <sys/time.h> -#ifndef CLOCK_REALTIME -#define CLOCK_REALTIME 0 -#endif -#ifndef CLOCK_MONOTONIC -#define CLOCK_MONOTONIC 0 -#endif -inline int clock_gettime(int /*clk_id*/, struct timespec* t) -{ - mach_timebase_info_data_t timebase; - mach_timebase_info(&timebase); - uint64_t time; - time = mach_absolute_time(); - double nseconds = ((double) time * (double) timebase.numer) / ((double) timebase.denom); - double seconds = ((double) time * (double) timebase.numer) / ((double) timebase.denom * 1e9); - t->tv_sec = seconds; - t->tv_nsec = nseconds; - return 0; -} -#else -#include <time.h> -#endif - -#include "CbmPixelHit.h" - -#include <list> -#include <memory> -#include <set> - -#define NOF_SIGMAS 1 -#define NOF_SIGMAS_SQ NOF_SIGMAS* NOF_SIGMAS -#define TIME_ERROR 4 - -extern Double_t speedOfLight; - -struct LxTbBinnedPoint; - -struct LxTbBinnedRay { - const LxTbBinnedPoint* lPoint; - scaltype tx; - scaltype dtxSq; - scaltype ty; - scaltype dtySq; - scaltype chi2; - - LxTbBinnedRay(scaltype deltaZ, const LxTbBinnedPoint& rP, const LxTbBinnedPoint& lP, - scaltype Chi2); /* : lPoint(&lP), tx((lP.x - rP.x) / deltaZ), - dtxSq((lP.dx - rP.dx) * (lP.dx - rP.dx) / (deltaZ * deltaZ)), ty((lP.y - rP.y) / deltaZ), - dtySq((lP.dy - rP.dy) * (lP.dy - rP.dy) / (deltaZ * deltaZ)), chi2(Chi2) - { - }*/ -}; - -struct LxTbBinnedPoint { - scaltype x; - scaltype dx; - scaltype y; - scaltype dy; - timetype t; - timetype dt; - bool use; - std::list<LxTbBinnedRay> neighbours; - Int_t refId; - -#ifdef LXTB_QA - const CbmPixelHit* pHit; - bool isTrd; - Int_t stationNumber; - - struct PointDesc { - Int_t eventId; - Int_t pointId; - Int_t trackId; - }; - - std::list<PointDesc> mcRefs; -#endif //LXTB_QA - - LxTbBinnedPoint(scaltype X, scaltype Dx, scaltype Y, scaltype Dy, timetype T, timetype Dt, Int_t ri, bool Use) - : x(X) - , dx(Dx) - , y(Y) - , dy(Dy) - , t(T) - , dt(Dt) - , use(Use) - , neighbours() - , refId(ri) -#ifdef LXTB_QA - , pHit(0) - , isTrd(false) - , stationNumber(-1) - , mcRefs() -#endif //LXTB_QA - { - } - - LxTbBinnedPoint(const LxTbBinnedPoint& orig) = default; - LxTbBinnedPoint& operator=(const LxTbBinnedPoint& orig) = delete; -}; - -inline LxTbBinnedRay::LxTbBinnedRay(scaltype deltaZ, const LxTbBinnedPoint& rP, const LxTbBinnedPoint& lP, - scaltype Chi2) - : lPoint(&lP) - , tx((lP.x - rP.x) / deltaZ) - , dtxSq((lP.dx - rP.dx) * (lP.dx - rP.dx) / (deltaZ * deltaZ)) - , ty((lP.y - rP.y) / deltaZ) - , dtySq((lP.dy - rP.dy) * (lP.dy - rP.dy) / (deltaZ * deltaZ)) - , chi2(Chi2) -{ -} - -struct LxTbXBin { - std::list<LxTbBinnedPoint> points; - bool use; - - LxTbXBin() : points(), use(false), maxDx() {} - - void Clear() - { - points.clear(); - use = false; - } - - // New feature - scaltype maxDx; - - void AddPoint(const LxTbBinnedPoint& point) { points.push_back(point); } -}; - -struct LxTbYXBin { - LxTbXBin* xBins; - int nofXBins; - bool use; - - LxTbYXBin(int nxbs) : xBins(new LxTbXBin[nxbs]), nofXBins(nxbs), use(false) {} - LxTbYXBin(const LxTbYXBin&) = delete; - LxTbYXBin& operator=(const LxTbYXBin&) = delete; - - ~LxTbYXBin() { delete[] xBins; } - - void Clear() - { - for (int i = 0; i < nofXBins; ++i) - xBins[i].Clear(); - - use = false; - } -}; - -struct LxTbTYXBin { - LxTbYXBin* yxBins; - int nofYXBins; - bool use; - - LxTbTYXBin(int nxbs, int nybs) - : yxBins(reinterpret_cast<LxTbYXBin*>(new unsigned char[nybs * sizeof(LxTbYXBin)])) - , nofYXBins(nybs) - , use(false) - { - for (int i = 0; i < nybs; ++i) - new (&yxBins[i]) LxTbYXBin(nxbs); - } - LxTbTYXBin(const LxTbTYXBin&) = delete; - LxTbTYXBin& operator=(const LxTbTYXBin&) = delete; - - ~LxTbTYXBin() { delete[] reinterpret_cast<unsigned char*>(yxBins); } - - void Clear() - { - for (int i = 0; i < nofYXBins; ++i) - yxBins[i].Clear(); - - use = false; - } -}; - -struct LxTbBinnedStation { - struct Q { - scaltype Q11, Q12, Q21, Q22; - }; - - int stationNumber; - scaltype z; - int nofXBins; - int nofYBins; - int nofTYXBins; - int lastXBin; - int lastYBin; - scaltype minX; - scaltype maxX; - scaltype binSizeX; - scaltype minY; - scaltype maxY; - scaltype binSizeY; - LxTbAbsorber absorber; - scaltype deltaThetaX; - scaltype deltaThetaY; - scaltype dispX; - scaltype dispY; - LxTbTYXBin* tyxBins; - Q qs[2]; - - LxTbBinnedStation(int nofxb, int nofyb, int noftb) - : stationNumber(-1) - , z() - , nofXBins(nofxb) - , nofYBins(nofyb) - , nofTYXBins(noftb) - , lastXBin(nofxb - 1) - , lastYBin(nofyb - 1) - , minX() - , maxX() - , binSizeX() - , minY() - , maxY() - , binSizeY() - , absorber() - , deltaThetaX() - , deltaThetaY() - , dispX() - , dispY() - , tyxBins(reinterpret_cast<LxTbTYXBin*>(new unsigned char[noftb * sizeof(LxTbTYXBin)])) - , qs() - { - for (int i = 0; i < noftb; ++i) - new (&tyxBins[i]) LxTbTYXBin(nofXBins, nofYBins); - } - LxTbBinnedStation(const LxTbBinnedStation&) = delete; - LxTbBinnedStation& operator=(const LxTbBinnedStation&) = delete; - - ~LxTbBinnedStation() { delete[] reinterpret_cast<unsigned char*>(tyxBins); } - - void Clear() - { - for (int i = 0; i < nofTYXBins; ++i) - tyxBins[i].Clear(); - } -}; - -struct LxTbBinnedTrdStation { - scaltype Zs[4]; - int nofXBins; - int nofYBins; - int nofTYXBins; - int lastXBin; - int lastYBin; - scaltype minX; - scaltype maxX; - scaltype binSizeX; - scaltype minY; - scaltype maxY; - scaltype binSizeY; - LxTbAbsorber absorber; - scaltype deltaThetaX; - scaltype deltaThetaY; - scaltype dispXs[4]; - scaltype dispYs[4]; - LxTbTYXBin* tyxBinsArr[4]; - - LxTbBinnedTrdStation(int nofxb, int nofyb, int noftb) - : Zs() - , nofXBins(nofxb) - , nofYBins(nofyb) - , nofTYXBins(noftb) - , lastXBin(nofxb - 1) - , lastYBin(nofyb - 1) - , minX() - , maxX() - , binSizeX() - , minY() - , maxY() - , binSizeY() - , absorber() - , deltaThetaX() - , deltaThetaY() - , dispXs() - , dispYs() - , tyxBinsArr() - - { - for (int i = 0; i < 4; ++i) { - tyxBinsArr[i] = reinterpret_cast<LxTbTYXBin*>(new unsigned char[noftb * sizeof(LxTbTYXBin)]); - - for (int j = 0; j < noftb; ++j) { - new (&tyxBinsArr[i][j]) LxTbTYXBin(nofXBins, nofYBins); - } - } - } - LxTbBinnedTrdStation(const LxTbBinnedTrdStation&) = delete; - LxTbBinnedTrdStation& operator=(const LxTbBinnedTrdStation&) = delete; - - ~LxTbBinnedTrdStation() - { - for (int i = 0; i < 4; ++i) - delete[] reinterpret_cast<unsigned char*>(tyxBinsArr[i]); - } - - void Clear() - { - for (int i = 0; i < 4; ++i) { - for (int j = 0; j < nofTYXBins; ++j) - tyxBinsArr[i][j].Clear(); - } - } -}; - -static long fullDuration = 0; - -struct LxTbBinnedFinder { - - struct KFParamsCoord { - scaltype coord, tg, C11, C12, C21, C22; - }; - - struct KFParams { - KFParamsCoord xParams; - KFParamsCoord yParams; - scaltype chi2; - }; - - void KFAddPointCoord(KFParamsCoord& param, const KFParamsCoord& prevParam, scaltype m, scaltype V, scaltype& chi2, - int stationNumber, int coordNumber) - { - const LxTbBinnedStation& station = stations[stationNumber]; - const LxTbBinnedStation::Q& Q = station.qs[coordNumber]; - scaltype deltaZ = station.z - stations[stationNumber + 1].z; - scaltype deltaZSq = deltaZ * deltaZ; - - // Extrapolate. - param.coord += prevParam.tg * deltaZ; // params[k].tg is unchanged. - - // Filter. - param.C11 += prevParam.C12 * deltaZ + prevParam.C21 * deltaZ + prevParam.C22 * deltaZSq + Q.Q11; - param.C12 += prevParam.C22 * deltaZ + Q.Q12; - param.C21 += prevParam.C22 * deltaZ + Q.Q21; - param.C22 += Q.Q22; - - scaltype S = 1.0 / (V + param.C11); - scaltype Kcoord = param.C11 * S; - scaltype Ktg = param.C21 * S; - scaltype dzeta = m - param.coord; - param.coord += Kcoord * dzeta; - param.tg += Ktg * dzeta; - param.C21 -= param.C11 * Ktg; - param.C22 -= param.C12 * Ktg; - param.C11 *= 1.0 - Kcoord; - param.C12 *= 1.0 - Kcoord; - chi2 += dzeta * S * dzeta; - } - - void KFAddPoint(KFParams& param, const KFParams& prevParam, scaltype m[2], scaltype V[2], int stationNumber) - { - /*LxRay* ray = rays[i]; - LxPoint* point = ray->end; - LxStation* station = point->layer->station; - scaltype m[2] = { point->x, point->y }; - scaltype V[2] = { point->dx * point->dx, point->dy * point->dy }; - KFParams pPrev[2] = { params[0], params[1] }; - scaltype deltaZ = point->z - prevPoint->z; - scaltype deltaZ2 = deltaZ * deltaZ;*/ - - KFAddPointCoord(param.xParams, prevParam.xParams, m[0], V[0], param.chi2, stationNumber, 0); - KFAddPointCoord(param.yParams, prevParam.yParams, m[1], V[1], param.chi2, stationNumber, 1); - } - - struct Chain { - LxTbBinnedPoint** points; - int nofPoints; - scaltype chi2; - bool highMom; - - Chain(const LxTbBinnedPoint* const* pts, int nofPts, scaltype Chi2) - : points(new LxTbBinnedPoint*[nofPts]) - , nofPoints(nofPts) - , chi2(Chi2) - , highMom(false) - { - for (int i = 0; i < nofPoints; ++i) - points[i] = new LxTbBinnedPoint(*pts[i]); - } - Chain(const Chain&) = delete; - Chain& operator=(const Chain&) = delete; - - ~Chain() - { - for (int i = 0; i < nofPoints; ++i) - delete points[i]; - - delete[] points; - } - }; - - struct ChainImpl { - //const LxTbBinnedPoint* points[];// Change to dynamical allocation - const LxTbBinnedPoint** points; - scaltype chi2; - - ChainImpl(const LxTbBinnedPoint** pts, int nofPts, scaltype Chi2) - : points(new const LxTbBinnedPoint*[nofPts]) - , chi2(Chi2) - { - memcpy(points, pts, nofPts * sizeof(const LxTbBinnedPoint*)); - } - - void Destroy() { delete[] points; } - }; - - struct TriggerTimeArray { - TriggerTimeArray(int noftb, int tbl, timetype& mt) - : nofTimebins(noftb) - , tbLength(tbl) - , minT(mt) - , triggerTimeBins(new std::list<std::pair<timetype, timetype>>[noftb]) - { - } - TriggerTimeArray(const TriggerTimeArray&) = delete; - TriggerTimeArray& operator=(const TriggerTimeArray&) = delete; - - ~TriggerTimeArray() { delete[] triggerTimeBins; } - - void Clear() - { - for (int i = 0; i < nofTimebins; ++i) - triggerTimeBins[i].clear(); - } - - void Insert(const std::pair<timetype, timetype>& v) - { - timetype wT = NOF_SIGMAS * sqrt(2.0) * v.second; - int minInd = (v.first - wT - minT) / tbLength; - int maxInd = (v.first + wT - minT) / tbLength; - - if (minInd < 0) minInd = 0; - else if (minInd >= nofTimebins) - minInd = nofTimebins - 1; - - if (maxInd < 0) maxInd = 0; - else if (maxInd >= nofTimebins) - maxInd = nofTimebins - 1; - - bool busy = false; - - for (int i = minInd; i <= maxInd; ++i) { - for (std::list<std::pair<timetype, timetype>>::const_iterator j = triggerTimeBins[i].begin(); - j != triggerTimeBins[i].end(); ++j) { - const std::pair<timetype, timetype>& p = *j; - - if (fabs(v.first - p.first) <= NOF_SIGMAS * sqrt(v.second * v.second + p.second * p.second)) { - busy = true; - break; - } - } - - if (busy) break; - } - - if (!busy) { - int ind = (v.first - minT) / tbLength; - - if (ind < 0) ind = 0; - else if (ind >= nofTimebins) - ind = nofTimebins - 1; - - triggerTimeBins[ind].push_back(v); - } - } - - int nofTimebins; - int tbLength; - timetype& minT; - std::list<std::pair<timetype, timetype>>* triggerTimeBins; - }; - - struct SignalParticle { - const char* fName; - int fPdgCode; - scaltype fMinEnergy; - bool fHasTrd; - }; - - static SignalParticle particleDescs[]; - SignalParticle* fSignalParticle; - - LxTbBinnedStation* stations; - //int nofStations; - LxTbBinnedTrdStation trdStation; - timetype minT; - timetype maxT; - std::list<Chain*>* recoTracks; - int nofTrackBins; - bool fHasTrd; - int fNofTrdLayers; - - TriggerTimeArray triggerTimes_trd0_sign0_dist0; - TriggerTimeArray triggerTimes_trd0_sign0_dist1; - TriggerTimeArray triggerTimes_trd0_sign1_dist0; - TriggerTimeArray triggerTimes_trd0_sign1_dist1; - TriggerTimeArray triggerTimes_trd1_sign0_dist0; - TriggerTimeArray triggerTimes_trd1_sign0_dist1; - TriggerTimeArray triggerTimes_trd1_sign1_dist0; - TriggerTimeArray triggerTimes_trd1_sign1_dist1; - TriggerTimeArray triggerTimes_trd05_sign0_dist0; - TriggerTimeArray triggerTimes_trd05_sign0_dist1; - TriggerTimeArray triggerTimes_trd05_sign1_dist0; - TriggerTimeArray triggerTimes_trd05_sign1_dist1; -#ifdef LXTB_QA - std::set<Int_t> triggerEventNumber; -#endif //LXTB_QA - - int fNofStations; - int fLastStationNumber; - int fNofTimeBins; - int fLastTimeBinNumber; - int fTimeBinLength; - int fTimeSliceLength; - - LxTbBinnedFinder(int nofTrdLayers, int nofStations, int nofTimeBins, std::pair<int, int>* nofSpatBins, - int nofTrdXBins, int nofTrdYBins, int timeBinLength) - : fSignalParticle(&particleDescs[0]) - , stations(reinterpret_cast<LxTbBinnedStation*>(new unsigned char[nofStations * sizeof(LxTbBinnedStation)])) - , trdStation(nofTrdXBins, nofTrdYBins, nofTimeBins) - , minT(0) - , maxT(0) - , recoTracks(new std::list<Chain*>[nofTimeBins]) - , nofTrackBins(nofTimeBins) - , fHasTrd(nofTrdLayers > 0) - , fNofTrdLayers(nofTrdLayers) - , triggerTimes_trd0_sign0_dist0(nofTimeBins, timeBinLength, minT) - , triggerTimes_trd0_sign0_dist1(nofTimeBins, timeBinLength, minT) - , triggerTimes_trd0_sign1_dist0(nofTimeBins, timeBinLength, minT) - , triggerTimes_trd0_sign1_dist1(nofTimeBins, timeBinLength, minT) - , triggerTimes_trd1_sign0_dist0(nofTimeBins, timeBinLength, minT) - , triggerTimes_trd1_sign0_dist1(nofTimeBins, timeBinLength, minT) - , triggerTimes_trd1_sign1_dist0(nofTimeBins, timeBinLength, minT) - , triggerTimes_trd1_sign1_dist1(nofTimeBins, timeBinLength, minT) - , triggerTimes_trd05_sign0_dist0(nofTimeBins, timeBinLength, minT) - , triggerTimes_trd05_sign0_dist1(nofTimeBins, timeBinLength, minT) - , triggerTimes_trd05_sign1_dist0(nofTimeBins, timeBinLength, minT) - , triggerTimes_trd05_sign1_dist1(nofTimeBins, timeBinLength, minT) - , -#ifdef LXTB_QA - triggerEventNumber() - , -#endif //LXTB_QA - fNofStations(nofStations) - , fLastStationNumber(nofStations - 1) - , fNofTimeBins(nofTimeBins) - , fLastTimeBinNumber(nofTimeBins - 1) - , fTimeBinLength(timeBinLength) - , fTimeSliceLength(nofTimeBins * timeBinLength) - { - for (int i = 0; i < fNofStations; ++i) - new (&stations[i]) LxTbBinnedStation(nofSpatBins[i].first, nofSpatBins[i].second, nofTimeBins); - } - - LxTbBinnedFinder(const LxTbBinnedFinder&) = delete; - LxTbBinnedFinder& operator=(const LxTbBinnedFinder&) = delete; - - virtual ~LxTbBinnedFinder() - { - for (int i = 0; i < fNofStations; ++i) - delete[] reinterpret_cast<unsigned char*>(&stations[i]); - - delete[] recoTracks; - } - - void SetSignalParticle(const char* name) - { - for (int i = 0; true; ++i) { - if (0 == strlen(particleDescs[i].fName)) break; - - if (0 == strcmp(particleDescs[i].fName, name)) { - fSignalParticle = &particleDescs[i]; - break; - } - } - } - - void Clear() - { - for (int i = 0; i < fNofStations; ++i) - stations[i].Clear(); - - trdStation.Clear(); - - for (int i = 0; i < nofTrackBins; ++i) - recoTracks[i].clear(); - - triggerTimes_trd0_sign0_dist0.Clear(); - triggerTimes_trd0_sign0_dist1.Clear(); - triggerTimes_trd0_sign1_dist0.Clear(); - triggerTimes_trd0_sign1_dist1.Clear(); - triggerTimes_trd1_sign0_dist0.Clear(); - triggerTimes_trd1_sign0_dist1.Clear(); - triggerTimes_trd1_sign1_dist0.Clear(); - triggerTimes_trd1_sign1_dist1.Clear(); - triggerTimes_trd05_sign0_dist0.Clear(); - triggerTimes_trd05_sign0_dist1.Clear(); - triggerTimes_trd05_sign1_dist0.Clear(); - triggerTimes_trd05_sign1_dist1.Clear(); -#ifdef LXTB_QA - triggerEventNumber.clear(); -#endif //LXTB_QA - } - - void SetTSBegin(unsigned long long tsLowBound) { minT = tsLowBound; } - - void Init() - { - fHasTrd = fHasTrd && fSignalParticle->fHasTrd; - scaltype E = fSignalParticle->fMinEnergy; // GeV - scaltype E0 = E; - - for (int i = 0; i < fNofStations; ++i) { - stations[i].binSizeX = (stations[i].maxX - stations[i].minX) / stations[i].nofXBins; - stations[i].binSizeY = (stations[i].maxY - stations[i].minY) / stations[i].nofYBins; - scaltype L = stations[i].absorber.width; // / cos(3.14159265 * 15 / 180); - E -= EnergyLoss(E, L, &stations[i].absorber); - - if (i > 0) { - scaltype Escat = (E0 + E) / 2; - scaltype deltaTheta = CalcThetaPrj(Escat, L, &stations[i].absorber); - stations[i].deltaThetaX = deltaTheta; - stations[i].deltaThetaY = deltaTheta; - scaltype q0XSq = stations[i].deltaThetaX * stations[i].deltaThetaX; - scaltype q0YSq = stations[i].deltaThetaY * stations[i].deltaThetaY; - stations[i].qs[0] = {q0XSq * L * L / 3, q0XSq * L / 2, q0XSq * L / 2, q0XSq}; - stations[i].qs[1] = {q0YSq * L * L / 3, q0YSq * L / 2, q0YSq * L / 2, q0YSq}; - } - - E0 = E; - } - - scaltype Ls[fNofStations + 1]; - Ls[0] = stations[0].absorber.zCoord; - - for (int i = 1; i < fNofStations; ++i) - Ls[i] = stations[i].absorber.zCoord - Ls[i - 1]; - - Ls[fNofStations] = stations[fLastStationNumber].z - Ls[fLastStationNumber]; - - scaltype Ls1[fNofStations + 1]; - scaltype Ls2[fNofStations + 1]; - - Ls1[0] = 0; - Ls2[0] = stations[0].absorber.zCoord; - - for (int i = 1; i < fNofStations; ++i) { - Ls1[i] = stations[i - 1].z - stations[i - 1].absorber.zCoord; - Ls2[i] = stations[i].absorber.zCoord - stations[i - 1].z; - } - - Ls1[fNofStations] = stations[fLastStationNumber].z - stations[fLastStationNumber].absorber.zCoord; - Ls2[fNofStations] = 0; - - for (int s = 1; s < fNofStations; ++s) { - LxTbBinnedStation& station = stations[s]; - scaltype L = station.z; - int n = s + 1; - scaltype thetaXSq = 0; - scaltype thetaYSq = 0; - - for (int i = 1; i < n; ++i) { - scaltype sumLi = 0; - - for (int j = 0; j < i; ++j) - sumLi += Ls[j]; - - thetaXSq += sumLi * sumLi * stations[i].deltaThetaX * stations[i].deltaThetaX; - thetaYSq += sumLi * sumLi * stations[i].deltaThetaY * stations[i].deltaThetaY; - } - - thetaXSq /= L * L; - thetaYSq /= L * L; - - thetaXSq += stations[s].deltaThetaX * stations[s].deltaThetaX * Ls2[n - 1] * Ls2[n - 1] - / ((Ls2[n - 1] + Ls1[n]) * (Ls2[n - 1] + Ls1[n])); - thetaYSq += stations[s].deltaThetaY * stations[s].deltaThetaY * Ls2[n - 1] * Ls2[n - 1] - / ((Ls2[n - 1] + Ls1[n]) * (Ls2[n - 1] + Ls1[n])); - - scaltype deltaZ = stations[s].z - stations[s - 1].z; - station.dispX = deltaZ * sqrt(thetaXSq); - station.dispY = deltaZ * sqrt(thetaYSq); - } - - if (fHasTrd) { - trdStation.binSizeX = (trdStation.maxX - trdStation.minX) / trdStation.nofXBins; - trdStation.binSizeY = (trdStation.maxY - trdStation.minY) / trdStation.nofYBins; - scaltype L = trdStation.absorber.width; // / cos(3.14159265 * 15 / 180); - E -= EnergyLoss(E, L, &trdStation.absorber); - scaltype Escat = (E0 + E) / 2; - scaltype deltaTheta = CalcThetaPrj(Escat, L, &trdStation.absorber); - trdStation.deltaThetaX = deltaTheta; - trdStation.deltaThetaY = deltaTheta; - - for (int i = 0; i < fNofTrdLayers; ++i) { - scaltype deltaZ = trdStation.Zs[i] - stations[fLastStationNumber].z; - trdStation.dispXs[i] = trdStation.deltaThetaX * deltaZ; - trdStation.dispYs[i] = trdStation.deltaThetaY * deltaZ; - } - - E0 = E; - } - } - - void FindNeighbours(scaltype x, scaltype wX, scaltype y, scaltype wY, timetype t, timetype wT, int layerIndex, - std::list<LxTbBinnedPoint*>& results) - { - if (x + wX < trdStation.minX || x - wX > trdStation.maxX || y + wY < trdStation.minY || y - wY > trdStation.maxY - || t + wT < minT || t - wT > maxT) - return; - - int lTindMin = (t - wT - minT) / fTimeBinLength; - - if (lTindMin < 0) lTindMin = 0; - else if (lTindMin > fLastTimeBinNumber) - lTindMin = fLastTimeBinNumber; - - int lTindMax = (t + wT - minT) / fTimeBinLength; - - if (lTindMax < 0) lTindMax = 0; - else if (lTindMax > fLastTimeBinNumber) - lTindMax = fLastTimeBinNumber; - - int lYindMin = (y - wY - trdStation.minY) / trdStation.binSizeY; - - if (lYindMin < 0) lYindMin = 0; - else if (lYindMin > trdStation.lastYBin) - lYindMin = trdStation.lastYBin; - - int lYindMax = (y + wY - trdStation.minY) / trdStation.binSizeY; - - if (lYindMax < 0) lYindMax = 0; - else if (lYindMax > trdStation.lastYBin) - lYindMax = trdStation.lastYBin; - - int lXindMin = (x - wX - trdStation.minX) / trdStation.binSizeX; - - if (lXindMin < 0) lXindMin = 0; - else if (lXindMin > trdStation.lastXBin) - lXindMin = trdStation.lastXBin; - - int lXindMax = (x + wX - trdStation.minX) / trdStation.binSizeX; - - if (lXindMax < 0) lXindMax = 0; - else if (lXindMax > trdStation.lastXBin) - lXindMax = trdStation.lastXBin; - - LxTbTYXBin* tyxBins = trdStation.tyxBinsArr[layerIndex]; - - for (int lTind = lTindMin; lTind <= lTindMax; ++lTind) { - LxTbTYXBin& lTyxBin = tyxBins[lTind]; - - for (int lYind = lYindMin; lYind <= lYindMax; ++lYind) { - LxTbYXBin& lYxBin = lTyxBin.yxBins[lYind]; - - for (int lXind = lXindMin; lXind <= lXindMax; ++lXind) { - LxTbXBin& lXBin = lYxBin.xBins[lXind]; - - for (std::list<LxTbBinnedPoint>::iterator i = lXBin.points.begin(); i != lXBin.points.end(); ++i) { - LxTbBinnedPoint& point = *i; - - if (point.x > x - wX && point.x < x + wX && point.y > y - wY && point.y < y + wY && point.t > t - wT - && point.t < t + wT) - results.push_back(&point); - } - } - } - } - } - - void Reconstruct() - { - //cout << "LxTbBinnedFinder::Reconstruct() started" << endl; - timespec ts; - clock_gettime(CLOCK_REALTIME, &ts); - long beginTime = ts.tv_sec * 1000000000 + ts.tv_nsec; - timetype c = speedOfLight; - maxT = minT + fTimeSliceLength; - LxTbBinnedStation& lastStation = stations[fLastStationNumber]; - int nofXBins = lastStation.nofXBins; - int nofYBins = lastStation.nofYBins; - - /*if (hasTrd) - { - scaltype lastZ = lastStation.z; - scaltype deltaZsTrd[4] = {trdStation.Zs[0] - lastZ, trdStation.Zs[2] - lastZ, trdStation.Zs[2] - lastZ, trdStation.Zs[3] - lastZ}; - - for (int i = 0; i < NOF_TIMEBINS; ++i) - { - - LxTbTYXBin& lTyxBin = lastStation.tyxBins[i]; - - for (int j = 0; j < nofYBins; ++j) - { - LxTbYXBin& lYxBin = lTyxBin.yxBins[j]; - - for (int k = 0; k < nofXBins; ++k) - { - LxTbXBin& lXBin = lYxBin.xBins[k]; - - for (std::list<LxTbBinnedPoint>::iterator l = lXBin.points.begin(); l != lXBin.points.end(); ++l) - { - LxTbBinnedPoint& lPoint = *l; - scaltype tx = lPoint.x / lastZ; - scaltype ty = lPoint.y / lastZ; - scaltype trdPx0 = lPoint.x + tx * deltaZsTrd[0]; - scaltype trdPy0 = lPoint.y + ty * deltaZsTrd[0]; - scaltype trajLen0 = sqrt(1 + tx * tx + ty * ty) * deltaZsTrd[0]; - scaltype trdPt0 = lPoint.t + 1.e9 * trajLen0 / c; // 1.e9 to convert to ns. - scaltype wX0 = NOF_SIGMAS * trdStation.dispXs[0]; - scaltype wY0 = NOF_SIGMAS * trdStation.dispYs[0]; - scaltype wT0 = NOF_SIGMAS * sqrt(2.0) * lPoint.dt; - std::list<LxTbBinnedPoint*> results0; - FindNeighbours(trdPx0, wX0, trdPy0, wY0, trdPt0, wT0, 0, results0); - - scaltype trdPx1 = lPoint.x + tx * deltaZsTrd[1]; - scaltype trdPy1 = lPoint.y + ty * deltaZsTrd[1]; - scaltype trajLen1 = sqrt(1 + tx * tx + ty * ty) * deltaZsTrd[1]; - scaltype trdPt1 = lPoint.t + 1.e9 * trajLen1 / c; // 1.e9 to convert to ns. - scaltype wX1 = NOF_SIGMAS * trdStation.dispXs[1]; - scaltype wY1 = NOF_SIGMAS * trdStation.dispYs[1]; - scaltype wT1 = NOF_SIGMAS * sqrt(2.0) * lPoint.dt; - std::list<LxTbBinnedPoint*> results1; - FindNeighbours(trdPx1, wX1, trdPy1, wY1, trdPt1, wT1, 1, results1); - - for (std::list<LxTbBinnedPoint*>::const_iterator m = results0.begin(); m != results0.end(); ++m) - { - LxTbBinnedPoint& trdPoint0 = *(*m); - - for (std::list<LxTbBinnedPoint*>::const_iterator n = results1.begin(); n != results1.end(); ++n) - { - LxTbBinnedPoint& trdPoint1 = *(*n); - scaltype trdTx = (trdPoint1.x - trdPoint0.x) / (trdStation.Zs[1] - trdStation.Zs[0]); - scaltype trdTy = (trdPoint1.y - trdPoint0.y) / (trdStation.Zs[1] - trdStation.Zs[0]); - - scaltype trdPx2 = trdPoint1.x + trdTx * (trdStation.Zs[2] - trdStation.Zs[1]); - scaltype trdPy2 = trdPoint1.y + trdTy * (trdStation.Zs[2] - trdStation.Zs[1]); - scaltype trajLen2 = sqrt(1 + trdTx * trdTx + trdTx * trdTx) * (trdStation.Zs[2] - trdStation.Zs[1]); - scaltype trdPt2 = trdPoint1.t + 1.e9 * trajLen2 / c; // 1.e9 to convert to ns. - scaltype wX2 = 0.35135; - scaltype wY2 = 0.33515; - scaltype wT2 = NOF_SIGMAS * sqrt(2.0) * trdPoint1.dt; - std::list<LxTbBinnedPoint*> results2; - FindNeighbours(trdPx2, wX2, trdPy2, wY2, trdPt2, wT2, 2, results2); - - if (results2.empty()) - continue; - - scaltype trdPx3 = trdPoint1.x + trdTx * (trdStation.Zs[3] - trdStation.Zs[1]); - scaltype trdPy3 = trdPoint1.y + trdTy * (trdStation.Zs[3] - trdStation.Zs[1]); - scaltype trajLen3 = sqrt(1 + trdTx * trdTx + trdTx * trdTx) * (trdStation.Zs[3] - trdStation.Zs[1]); - scaltype trdPt3 = trdPoint1.t + 1.e9 * trajLen3 / c; // 1.e9 to convert to ns. - scaltype wX3 = 0.909; - scaltype wY3 = 0.8455; - scaltype wT3 = NOF_SIGMAS * sqrt(2.0) * trdPoint1.dt; - std::list<LxTbBinnedPoint*> results3; - FindNeighbours(trdPx3, wX3, trdPy3, wY3, trdPt3, wT3, 3, results3); - - if (results3.empty()) - continue; - - lPoint.use = true; - lXBin.use = true; - lYxBin.use = true; - lTyxBin.use = true; - } - } - } - } - } - } - }*/ - - for (int i = fLastStationNumber; i >= 1; --i) { - LxTbBinnedStation& rStation = stations[i]; - LxTbBinnedStation& lStation = stations[i - 1]; - scaltype binSizeX = lStation.binSizeX; - scaltype binSizeY = lStation.binSizeY; - scaltype rZ = rStation.z; - scaltype lZ = lStation.z; - scaltype deltaZ = lZ - rZ; - scaltype dispXSq = rStation.dispX * rStation.dispX; - scaltype dispYSq = rStation.dispY * rStation.dispY; - scaltype minX = lStation.minX; - scaltype maxX = lStation.maxX; - scaltype minY = lStation.minY; - scaltype maxY = lStation.maxY; - int rNofXBins = rStation.nofXBins; - int rNofYBins = rStation.nofYBins; - int lastXBin = lStation.nofXBins - 1; - int lastYBin = lStation.nofYBins - 1; - - for (int j = 0; j < fNofTimeBins; ++j) { - LxTbTYXBin& rTyxBin = rStation.tyxBins[j]; - - if (!rTyxBin.use) continue; - - for (int k = 0; k < rNofYBins; ++k) { - LxTbYXBin& rYxBin = rTyxBin.yxBins[k]; - - if (!rYxBin.use) continue; - - for (int l = 0; l < rNofXBins; ++l) { - LxTbXBin& rXBin = rYxBin.xBins[l]; - - if (!rXBin.use) continue; - - for (std::list<LxTbBinnedPoint>::iterator m = rXBin.points.begin(); m != rXBin.points.end(); ++m) { - LxTbBinnedPoint& rPoint = *m; - - if (!rPoint.use) continue; - - scaltype tx = rPoint.x / rZ; - scaltype ty = rPoint.y / rZ; - scaltype pX = rPoint.x + tx * deltaZ; - scaltype pY = rPoint.y + ty * deltaZ; - scaltype trajLen = sqrt(1 + tx * tx + ty * ty) * deltaZ; - timetype pT = rPoint.t + 1.e9 * trajLen / c; // 1.e9 to convert to ns and trajLen is negative. - scaltype rDxSq = rPoint.dx * rPoint.dx; - scaltype xDiv0 = dispXSq + rDxSq; - scaltype wX = NOF_SIGMAS * sqrt(xDiv0 + rDxSq); - scaltype rDySq = rPoint.dy * rPoint.dy; - scaltype yDiv0 = dispYSq + rDySq; - scaltype wY = NOF_SIGMAS * sqrt(yDiv0 + rDySq); - timetype wT = NOF_SIGMAS * sqrt(2.0) * rPoint.dt; - - if (pX + wX < minX || pX - wX > maxX || pY + wY < minY || pY - wY > maxY || pT + wT < minT - || pT - wT > maxT) - continue; - - int lTindMin = (pT - wT - minT) / fTimeBinLength; - - if (lTindMin < 0) lTindMin = 0; - else if (lTindMin > fLastTimeBinNumber) - lTindMin = fLastTimeBinNumber; - - int lTindMax = (pT + wT - minT) / fTimeBinLength; - - if (lTindMax < 0) lTindMax = 0; - else if (lTindMax > fLastTimeBinNumber) - lTindMax = fLastTimeBinNumber; - - int lYindMin = (pY - wY - minY) / binSizeY; - - if (lYindMin < 0) lYindMin = 0; - else if (lYindMin > lastYBin) - lYindMin = lastYBin; - - int lYindMax = (pY + wY - minY) / binSizeY; - - if (lYindMax < 0) lYindMax = 0; - else if (lYindMax > lastYBin) - lYindMax = lastYBin; - - int lXindMin = (pX - wX - minX) / binSizeX; - - if (lXindMin < 0) lXindMin = 0; - else if (lXindMin > lastXBin) - lXindMin = lastXBin; - - int lXindMax = (pX + wX - minX) / binSizeX; - - if (lXindMax < 0) lXindMax = 0; - else if (lXindMax > lastXBin) - lXindMax = lastXBin; - - for (int lTind = lTindMin; lTind <= lTindMax; ++lTind) { - LxTbTYXBin& lTyxBin = lStation.tyxBins[lTind]; - - for (int lYind = lYindMin; lYind <= lYindMax; ++lYind) { - LxTbYXBin& lYxBin = lTyxBin.yxBins[lYind]; - - for (int lXind = lXindMin; lXind <= lXindMax; ++lXind) { - LxTbXBin& lXBin = lYxBin.xBins[lXind]; - - for (std::list<LxTbBinnedPoint>::iterator n = lXBin.points.begin(); n != lXBin.points.end(); ++n) { - LxTbBinnedPoint& lPoint = *n; - scaltype xDiv = xDiv0 + lPoint.dx * lPoint.dx; - scaltype wX_prec_sq = NOF_SIGMAS_SQ * xDiv; - scaltype yDiv = yDiv0 + lPoint.dy * lPoint.dy; - scaltype wY_prec_sq = NOF_SIGMAS_SQ * yDiv; - scaltype deltaX = lPoint.x - pX; - scaltype deltaXSq = deltaX * deltaX; - scaltype deltaY = lPoint.y - pY; - scaltype deltaYSq = deltaY * deltaY; - timetype deltaT = lPoint.t - pT; - timetype deltaTSq = deltaT * deltaT; - - if (deltaXSq < wX_prec_sq && deltaYSq < wY_prec_sq && deltaTSq < wT * wT) { - lPoint.use = true; - lXBin.use = true; - rPoint.neighbours.push_back( - LxTbBinnedRay(deltaZ, rPoint, lPoint, - deltaXSq / xDiv + deltaYSq / yDiv - + deltaTSq / (rPoint.dt * rPoint.dt + lPoint.dt * lPoint.dt))); - } - } - - if (lXBin.use) lYxBin.use = true; - } - - if (lYxBin.use) lTyxBin.use = true; - } - } - } // for (std::list<LxTbBinnedPoint>::iterator m = rStation - } // for (int l = 0; l < NOF_XBINS; ++l) - } // for (int k = 0; k < NOF_YBINS; ++k) - } // for (int j = 0; j < NOF_TIMEBINS; ++j) - } // for (int i = fLastStationNumber; i >=1; --i) - - const LxTbBinnedPoint* points[fNofStations]; - - for (int i = 0; i < fNofTimeBins; ++i) { - LxTbTYXBin& rTyxBin = lastStation.tyxBins[i]; - - if (!rTyxBin.use) continue; - - for (int j = 0; j < nofYBins; ++j) { - LxTbYXBin& rYxBin = rTyxBin.yxBins[j]; - - if (!rYxBin.use) continue; - - for (int k = 0; k < nofXBins; ++k) { - LxTbXBin& rXBin = rYxBin.xBins[k]; - - if (!rXBin.use) continue; - - for (std::list<LxTbBinnedPoint>::iterator l = rXBin.points.begin(); l != rXBin.points.end(); ++l) { - LxTbBinnedPoint& rPoint = *l; - std::list<ChainImpl> chains; - - KFParams kfParams = {{rPoint.x, rPoint.x / lastStation.z, rPoint.dx * rPoint.dx, 0, 0, 1.0}, - {rPoint.y, rPoint.y / lastStation.z, rPoint.dy * rPoint.dy, 0, 0, 1.0}, - 0}; - - FindChains(fLastStationNumber, &rPoint, 0, points, kfParams, chains); - const ChainImpl* bestChain = 0; - scaltype chi2 = 0; - - for (std::list<ChainImpl>::const_iterator m = chains.begin(); m != chains.end(); ++m) { - const ChainImpl& chain = *m; - - if (0 == bestChain || chain.chi2 < chi2) { - bestChain = &chain; - chi2 = chain.chi2; - } - } - - if (0 != bestChain) { - int trackBinInd = (bestChain->points[fLastStationNumber]->t - minT) / fTimeBinLength; - - if (trackBinInd < 0) trackBinInd = 0; - else if (trackBinInd > nofTrackBins) - trackBinInd = nofTrackBins; - - recoTracks[trackBinInd].push_back(new Chain(bestChain->points, fNofStations, chi2)); - } - - for (std::list<ChainImpl>::iterator m = chains.begin(); m != chains.end(); ++m) { - ChainImpl& chain = *m; - delete[] chain.points; - } - } - } - } - } - - if (fHasTrd) { - scaltype lastZ = lastStation.z; - LxTbBinnedStation& beforeLastStation = stations[fLastStationNumber - 1]; - scaltype beforeLastZ = beforeLastStation.z; - scaltype deltaZsTrd[4] = {trdStation.Zs[0] - lastZ, trdStation.Zs[2] - lastZ, trdStation.Zs[2] - lastZ, - trdStation.Zs[3] - lastZ}; - scaltype dispX0Sq = trdStation.dispXs[0] * trdStation.dispXs[0]; - scaltype dispY0Sq = trdStation.dispYs[0] * trdStation.dispYs[0]; - scaltype dispX1Sq = trdStation.dispXs[1] * trdStation.dispXs[1]; - scaltype dispY1Sq = trdStation.dispYs[1] * trdStation.dispYs[1]; - scaltype trdDeltaZ10 = (trdStation.Zs[1] - trdStation.Zs[0]); - scaltype trdDeltaZ10Sq = trdDeltaZ10 * trdDeltaZ10; - scaltype trdDeltaZ21 = (trdStation.Zs[2] - trdStation.Zs[1]); - scaltype trdDeltaZ21Sq = trdDeltaZ21 * trdDeltaZ21; - scaltype trdDeltaZ31 = (trdStation.Zs[3] - trdStation.Zs[1]); - scaltype trdDeltaZ31Sq = trdDeltaZ31 * trdDeltaZ31; - - for (int i = 0; i < nofTrackBins; ++i) { - std::list<Chain*>& recoTracksBin = recoTracks[i]; - - for (std::list<Chain*>::iterator j = recoTracksBin.begin(); j != recoTracksBin.end(); ++j) { - Chain* track = *j; - LxTbBinnedPoint& lPoint = *track->points[track->nofPoints - 1]; - LxTbBinnedPoint& lPointL = *track->points[track->nofPoints - 2]; - scaltype tx = (lPoint.x - lPointL.x) / (lastZ - beforeLastZ); - scaltype ty = (lPoint.y - lPointL.y) / (lastZ - beforeLastZ); - scaltype trdPx0 = lPoint.x + tx * deltaZsTrd[0]; - scaltype trdPy0 = lPoint.y + ty * deltaZsTrd[0]; - scaltype trajLen0 = sqrt(1 + tx * tx + ty * ty) * deltaZsTrd[0]; - timetype trdPt0 = lPoint.t + 1.e9 * trajLen0 / c; // 1.e9 to convert to ns. - scaltype wX0 = NOF_SIGMAS * sqrt(dispX0Sq + 2 * lPoint.dx * lPoint.dx); - scaltype wY0 = NOF_SIGMAS * sqrt(dispY0Sq + 2 * lPoint.dy * lPoint.dy); - timetype wT0 = NOF_SIGMAS * sqrt(2.0) * lPoint.dt; - std::list<LxTbBinnedPoint*> results0; - FindNeighbours(trdPx0, wX0, trdPy0, wY0, trdPt0, wT0, 0, results0); - - scaltype trdPx1 = lPoint.x + tx * deltaZsTrd[1]; - scaltype trdPy1 = lPoint.y + ty * deltaZsTrd[1]; - scaltype trajLen1 = sqrt(1 + tx * tx + ty * ty) * deltaZsTrd[1]; - timetype trdPt1 = lPoint.t + 1.e9 * trajLen1 / c; // 1.e9 to convert to ns. - scaltype wX1 = NOF_SIGMAS * sqrt(dispX1Sq + 2 * lPoint.dx * lPoint.dx); - scaltype wY1 = NOF_SIGMAS * sqrt(dispY1Sq + 2 * lPoint.dy * lPoint.dy); - timetype wT1 = NOF_SIGMAS * sqrt(2.0) * lPoint.dt; - std::list<LxTbBinnedPoint*> results1; - FindNeighbours(trdPx1, wX1, trdPy1, wY1, trdPt1, wT1, 1, results1); - - for (std::list<LxTbBinnedPoint*>::const_iterator k = results0.begin(); k != results0.end(); ++k) { - LxTbBinnedPoint& trdPoint0 = *(*k); - - for (std::list<LxTbBinnedPoint*>::const_iterator l = results1.begin(); l != results1.end(); ++l) { - LxTbBinnedPoint& trdPoint1 = *(*l); - scaltype trdTx = (trdPoint1.x - trdPoint0.x) / trdDeltaZ10; - scaltype trdTy = (trdPoint1.y - trdPoint0.y) / trdDeltaZ10; - scaltype trdDtxSq = (trdPoint0.dx * trdPoint0.dx + trdPoint1.dx * trdPoint1.dx) / trdDeltaZ10Sq; - scaltype trdDtySq = (trdPoint0.dy * trdPoint0.dy + trdPoint1.dy * trdPoint1.dy) / trdDeltaZ10Sq; - - scaltype trdPx2 = trdPoint1.x + trdTx * trdDeltaZ21; - scaltype trdPy2 = trdPoint1.y + trdTy * trdDeltaZ21; - scaltype trajLen2 = sqrt(1 + trdTx * trdTx + trdTx * trdTx) * trdDeltaZ21; - timetype trdPt2 = trdPoint1.t + 1.e9 * trajLen2 / c; // 1.e9 to convert to ns. - scaltype wX2 = - NOF_SIGMAS - * sqrt(0.0878375 * 0.0878375 + trdDtxSq * trdDeltaZ21Sq + trdPoint1.dx * trdPoint1.dx); //0.35135; - scaltype wY2 = - NOF_SIGMAS - * sqrt(0.0837875 * 0.0837875 + trdDtySq * trdDeltaZ21Sq + trdPoint1.dy * trdPoint1.dy); //0.33515; - timetype wT2 = NOF_SIGMAS * sqrt(2.0) * trdPoint1.dt; - std::list<LxTbBinnedPoint*> results2; - FindNeighbours(trdPx2, wX2, trdPy2, wY2, trdPt2, wT2, 2, results2); - - if (results2.empty()) continue; - - scaltype trdPx3 = trdPoint1.x + trdTx * trdDeltaZ31; - scaltype trdPy3 = trdPoint1.y + trdTy * trdDeltaZ31; - scaltype trajLen3 = sqrt(1 + trdTx * trdTx + trdTx * trdTx) * trdDeltaZ31; - timetype trdPt3 = trdPoint1.t + 1.e9 * trajLen3 / c; // 1.e9 to convert to ns. - scaltype wX3 = - NOF_SIGMAS * sqrt(0.22725 * 0.22725 + trdDtxSq * trdDeltaZ31Sq + trdPoint1.dx * trdPoint1.dx); //0.909; - scaltype wY3 = - NOF_SIGMAS - * sqrt(0.211375 * 0.211375 + trdDtySq * trdDeltaZ31Sq + trdPoint1.dy * trdPoint1.dy); //0.8455; - timetype wT3 = NOF_SIGMAS * sqrt(2.0) * trdPoint1.dt; - std::list<LxTbBinnedPoint*> results3; - FindNeighbours(trdPx3, wX3, trdPy3, wY3, trdPt3, wT3, 3, results3); - - if (!results3.empty()) { - track->highMom = true; - break; - } - } - - if (track->highMom) break; - } - } - } - } - - Trigger(); - - clock_gettime(CLOCK_REALTIME, &ts); - long endTime = ts.tv_sec * 1000000000 + ts.tv_nsec; - fullDuration += endTime - beginTime; - //cout << "LxTbNaiveFinder::Reconstruct() full duration was: " << fullDuration << endl; - //cout << "LxTbNaiveFinder::Reconstruct() the number of found tracks: " << recoTracks.size() << endl; - } - - void FindChains(int stationIndex, const LxTbBinnedPoint* rPoint, const LxTbBinnedRay* /*rRay*/, - const LxTbBinnedPoint** points, KFParams kfParamsPrev, std::list<ChainImpl>& chains) - { - points[stationIndex] = rPoint; - - if (0 == stationIndex) { - ChainImpl chain(points, fNofStations, kfParamsPrev.chi2); - chains.push_back(chain); - return; - } - - for (std::list<LxTbBinnedRay>::const_iterator i = rPoint->neighbours.begin(); i != rPoint->neighbours.end(); ++i) { - const LxTbBinnedRay& lRay = *i; - const LxTbBinnedPoint* lPoint = lRay.lPoint; - /*scaltype chi2_2 = chi2 + lRay.chi2; - - if (0 != rRay) - //chi2_2 += (lRay.tx - rRay->tx) * (lRay.tx - rRay->tx) / (rRay->dtxSq + lRay.dtxSq) + - //(lRay.ty - rRay->ty) * (lRay.ty - rRay->ty) / (rRay->dtySq + lRay.dtySq); - chi2_2 += (lRay.tx - rRay->tx) * (lRay.tx - rRay->tx) / (stations[stationIndex].deltaThetaX * stations[stationIndex].deltaThetaX) + - (lRay.ty - rRay->ty) * (lRay.ty - rRay->ty) / (stations[stationIndex].deltaThetaY * stations[stationIndex].deltaThetaY);*/ - KFParams kfParams = kfParamsPrev; - scaltype m[2] = {lPoint->x, lPoint->y}; - scaltype V[2] = {lPoint->dx * lPoint->dx, lPoint->dy * lPoint->dy}; - KFAddPoint(kfParams, kfParamsPrev, m, V, stationIndex - 1); - FindChains(stationIndex - 1, lPoint, &lRay, points, kfParams, chains); - } - } - - void TriggerBin(std::list<Chain*>& recoTracksBin, std::list<Chain*>& borderTracks, int i, bool handleBorder) - { - std::list<Chain*>::const_iterator it = handleBorder ? borderTracks.begin() : recoTracksBin.begin(); - std::list<Chain*>::const_iterator endIt = handleBorder ? borderTracks.end() : recoTracksBin.end(); - - for (; it != endIt; ++it) { - Chain* track = *it; - LxTbBinnedPoint* point = track->points[fLastStationNumber]; - timetype dt = point->dt; - timetype dtSq = dt * dt; - timetype wt = NOF_SIGMAS * sqrt(2.0) * dt; - - if (!handleBorder && point->t + wt > minT + (i + 1) * fTimeBinLength) borderTracks.push_back(track); - - scaltype trackSign = (track->points[1]->x - track->points[0]->x) / (stations[1].z - stations[0].z) - - track->points[0]->x / stations[0].z; - std::list<Chain*>::const_iterator it2 = handleBorder ? recoTracksBin.begin() : it; - std::list<Chain*>::const_iterator endIt2 = recoTracksBin.end(); - - if (!handleBorder) ++it2; - - for (; it2 != endIt2; ++it2) { - Chain* track2 = *it2; - LxTbBinnedPoint* point2 = track2->points[fLastStationNumber]; - timetype dt2 = point2->dt; - timetype dt2Sq = dt2 * dt2; - - if (fabs(point2->t - point->t) > NOF_SIGMAS * sqrt(dtSq + dt2Sq)) continue; - - scaltype track2Sign = (track2->points[1]->x - track2->points[0]->x) / (stations[1].z - stations[0].z) - - track2->points[0]->x / stations[0].z; - scaltype dist = - sqrt((track2->points[0]->x - track->points[0]->x) * (track2->points[0]->x - track->points[0]->x) - + (track2->points[0]->y - track->points[0]->y) * (track2->points[0]->y - track->points[0]->y)); - std::pair<timetype, timetype> pairTime((point->t + point2->t) / 2, sqrt(dtSq + dt2Sq) / 2); - - if (track->highMom && track2->highMom) { - if (trackSign * track2Sign < 0) { - if (dist >= 50.0) { - triggerTimes_trd1_sign1_dist1.Insert(pairTime); -#ifdef LXTB_QA - triggerEventNumber.insert(point->mcRefs.front().eventId); -#endif //LXTB_QA - } - - triggerTimes_trd1_sign1_dist0.Insert(pairTime); - } - - if (dist >= 50.0) triggerTimes_trd1_sign0_dist1.Insert(pairTime); - - triggerTimes_trd1_sign0_dist0.Insert(pairTime); - } - - if (track->highMom || track2->highMom) { - if (trackSign * track2Sign < 0) { - if (dist >= 50.0) triggerTimes_trd05_sign1_dist1.Insert(pairTime); - - triggerTimes_trd05_sign1_dist0.Insert(pairTime); - } - - if (dist >= 50.0) triggerTimes_trd05_sign0_dist1.Insert(pairTime); - - triggerTimes_trd05_sign0_dist0.Insert(pairTime); - } - - if (trackSign * track2Sign < 0) { - if (dist >= 50.0) triggerTimes_trd0_sign1_dist1.Insert(pairTime); - - triggerTimes_trd0_sign1_dist0.Insert(pairTime); - } - - if (dist >= 50.0) triggerTimes_trd0_sign0_dist1.Insert(pairTime); - - triggerTimes_trd0_sign0_dist0.Insert(pairTime); - } - } - } - - void Trigger() - { - std::list<Chain*> borderTracks; - - for (int i = 0; i < nofTrackBins; ++i) { - TriggerBin(recoTracks[i], borderTracks, 0, true); - borderTracks.clear(); - TriggerBin(recoTracks[i], borderTracks, i, false); - } - } -}; - -#endif /* LXTBBINNED_H */ diff --git a/reco/tracking/lx/TBBinned/LxTBBinned2.h b/reco/tracking/lx/TBBinned/LxTBBinned2.h deleted file mode 100644 index 79dd59faa5936de64ce8801fae559c0ddf4b4fac..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/TBBinned/LxTBBinned2.h +++ /dev/null @@ -1,469 +0,0 @@ -/* Copyright (C) 2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifndef LXTBBINNED2_H -#define LXTBBINNED2_H - -#include "CbmPixelHit.h" - -#include <list> - -#include "LxTBDefinitions.h" - - -#define NOF_LAYERS 3 -#define LAST_LAYER NOF_LAYERS - 1 -#define NOF_STATIONS 4 -#define LAST_STATION NOF_STATIONS - 1 - -#define TIMEBIN_LENGTH 100 -#define NOF_SIGMAS 4 -#define NOF_SIGMAS_SQ NOF_SIGMAS* NOF_SIGMAS - -struct LxTbBinnedTriplet; - -struct LxTbBinnedPoint { - scaltype x; - scaltype dx; - scaltype y; - scaltype dy; - timetype t; - timetype dt; - bool use; - std::list<LxTbBinnedTriplet*> triplets; - Int_t refId; - -#ifdef LXTB_QA - const CbmPixelHit* pHit; - bool isTrd; - Int_t stationNumber; - Int_t layerNumber; - - struct PointDesc { - Int_t eventId; - Int_t pointId; - Int_t trackId; - }; - - std::list<PointDesc> mcRefs; -#endif //LXTB_QA - - LxTbBinnedPoint(scaltype X, scaltype Dx, scaltype Y, scaltype Dy, timetype T, timetype Dt, Int_t ri, bool Use) - : x(X) - , dx(Dx) - , y(Y) - , dy(Dy) - , t(T) - , dt(Dt) - , refId(ri) - , use(Use) -#ifdef LXTB_QA - , pHit(0) - , isTrd(false) - , stationNumber(-1) - , layerNumber(-1) -#endif //LXTB_QA - { - } - - LxTbBinnedPoint(const LxTbBinnedPoint& original) - : x(original.x) - , dx(original.dx) - , y(original.y) - , dy(original.dy) - , t(original.t) - , dt(original.dt) - , use(original.use) - , triplets() - , refId(original.refId) -#ifdef LXTB_QA - , pHit(original.pHit) - , isTrd(original.isTrd) - , stationNumber(original.stationNumber) - , layerNumber(original.layerNumber) - , mcRefs(original.mcRefs) -#endif //LXTB_QA - { - } - - ~LxTbBinnedPoint(); -}; - -struct LxTbBinnedTriplet { - LxTbBinnedPoint* lPoint; - LxTbBinnedPoint* rPoint; - scaltype tx; - scaltype dtx; - scaltype ty; - scaltype dty; - std::list<LxTbBinnedPoint*> neighbours; - - LxTbBinnedTriplet(LxTbBinnedPoint* lp, LxTbBinnedPoint* rp, scaltype deltaZ) - : lPoint(lp) - , rPoint(rp) - , tx((lPoint->x - rPoint->x) / deltaZ) - , ty((lPoint->y - rPoint->y) / deltaZ) - , dtx(-sqrt(lPoint->dx * lPoint->dx + rPoint->dx * rPoint->dx) / deltaZ) - , dty(-sqrt(lPoint->dy * lPoint->dy + rPoint->dy * rPoint->dy) / deltaZ) - { - } -}; - -inline LxTbBinnedPoint::~LxTbBinnedPoint() -{ - for (std::list<LxTbBinnedTriplet*>::iterator i = triplets.begin(); i != triplets.end(); ++i) - delete *i; -} - -struct LxTbXBin { - LxTbXBin() : use(false), maxDx(0), maxDy(0), maxDt(0) {} - - void Clear() - { - points.clear(); - maxDx = 0; - maxDy = 0; - maxDt = 0; - use = false; - } - - void AddPoint(const LxTbBinnedPoint& point) - { - points.push_back(point); - - if (point.dx > maxDx) maxDx = point.dx; - - if (point.dy > maxDy) maxDy = point.dy; - - if (point.dt > maxDt) maxDt = point.dt; - } - - std::list<LxTbBinnedPoint> points; - bool use; - scaltype maxDx; - scaltype maxDy; - timetype maxDt; -}; - -struct LxTbYXBin { - LxTbYXBin(int nxbs) : xBins(new LxTbXBin[nxbs]), nofXBins(nxbs), use(false) {} - - ~LxTbYXBin() { delete[] xBins; } - - void Clear() - { - for (int i = 0; i < nofXBins; ++i) - xBins[i].Clear(); - - use = false; - } - - LxTbXBin* xBins; - int nofXBins; - bool use; -}; - -struct LxTbTYXBin { - LxTbTYXBin(int nxbs, int nybs) - : yxBins(reinterpret_cast<LxTbYXBin*>(new unsigned char[nybs * sizeof(LxTbYXBin)])) - , nofYXBins(nybs) - , use(false) - { - for (int i = 0; i < nybs; ++i) - new (&yxBins[i]) LxTbYXBin(nxbs); - } - - ~LxTbTYXBin() { delete[] reinterpret_cast<unsigned char*>(yxBins); } - - void Clear() - { - for (int i = 0; i < nofYXBins; ++i) - yxBins[i].Clear(); - - use = false; - } - - LxTbYXBin* yxBins; - int nofYXBins; - bool use; -}; - -struct LxTbLayer { - LxTbLayer(int nofxb, int nofyb, int noftb) - : tyxBins(reinterpret_cast<LxTbTYXBin*>(new unsigned char[noftb * sizeof(LxTbTYXBin)])) - , nofTYXBins(noftb) - , nofYXBins(nofyb) - , nofXBins(nofxb) - , lastTimeBinNumber(noftb - 1) - , lastYBinNumber(nofyb - 1) - , lastXBinNumber(nofxb - 1) - , minX(0) - , maxX(0) - , minY(0) - , maxY(0) - , minT(0) - , maxT(0) - , xBinLength(0) - , yBinLength(0) - , timeBinLength(TIMEBIN_LENGTH) - , z(0) - { - for (int i = 0; i < noftb; ++i) - new (&tyxBins[i]) LxTbTYXBin(nofyb, nofxb); - } - - ~LxTbLayer() { delete[] reinterpret_cast<unsigned char*>(tyxBins); } - - void Clear() - { - for (int i = 0; i < nofTYXBins; ++i) - tyxBins[i].Clear(); - } - - void Init() - { - xBinLength = (maxX - minX) / nofXBins; - yBinLength = (maxY - minY) / nofYXBins; - maxT = minT + TIMEBIN_LENGTH * nofTYXBins; - } - - void SetMinT(timetype v) - { - minT = v; - maxT = minT + TIMEBIN_LENGTH * nofTYXBins; - } - - LxTbTYXBin* tyxBins; - int nofTYXBins; - int nofYXBins; - int nofXBins; - int lastTimeBinNumber; - int lastYBinNumber; - int lastXBinNumber; - scaltype minX; - scaltype maxX; - scaltype minY; - scaltype maxY; - timetype minT; - timetype maxT; - scaltype xBinLength; - scaltype yBinLength; - timetype timeBinLength; - scaltype z; -}; - - -#define LXTB_ITERATE_LAYER_BEGIN \ - if (maxX > layer.minX && minX < layer.maxX && maxY > layer.minY && minY < layer.maxY && maxT > layer.minT \ - && minT < layer.maxT) { \ - int minTind = (minT - layer.minT) / layer.timeBinLength; \ - \ - if (minTind < 0) minTind = 0; \ - else if (minTind > layer.lastTimeBinNumber) \ - minTind = layer.lastTimeBinNumber; \ - \ - int maxTind = (maxT - layer.minT) / layer.timeBinLength; \ - \ - if (maxTind < 0) maxTind = 0; \ - else if (maxTind > layer.lastTimeBinNumber) \ - maxTind = layer.lastTimeBinNumber; \ - \ - int minYind = (minY - layer.minY) / layer.yBinLength; \ - \ - if (minYind < 0) minYind = 0; \ - else if (minYind > layer.lastYBinNumber) \ - minYind = layer.lastYBinNumber; \ - \ - int maxYind = (maxY - layer.minY) / layer.yBinLength; \ - \ - if (maxYind < 0) maxYind = 0; \ - else if (maxYind > layer.lastYBinNumber) \ - maxYind = layer.lastYBinNumber; \ - \ - int minXind = (minX - layer.minX) / layer.xBinLength; \ - \ - if (minXind < 0) minXind = 0; \ - else if (minXind > layer.lastXBinNumber) \ - minXind = layer.lastXBinNumber; \ - \ - int maxXind = (maxX - minX) / layer.xBinLength; \ - \ - if (maxXind < 0) maxXind = 0; \ - else if (maxXind > layer.lastXBinNumber) \ - maxXind = layer.lastXBinNumber; \ - \ - for (int tInd = minTind; tInd <= maxTind; ++tInd) { \ - LxTbTYXBin& tyxBin = layer.tyxBins[tInd]; \ - \ - for (int yInd = minYind; yInd <= maxYind; ++yInd) { \ - LxTbYXBin& yxBin = tyxBin.yxBins[yInd]; \ - \ - for (int xInd = minXind; xInd <= maxXind; ++xInd) { \ - LxTbXBin& xBin = yxBin.xBins[xInd]; \ - \ - for (std::list<LxTbBinnedPoint>::iterator pointIterator = xBin.points.begin(); \ - pointIterator != xBin.points.end(); ++pointIterator) { \ - LxTbBinnedPoint& point = *pointIterator; \ - \ - if (point.x >= minX && point.x <= maxX && point.y >= minY && point.y <= maxY && point.t >= minT \ - && point.t <= maxT) { - -#define LXTB_ITERATE_LAYER_END \ - point.use = true; \ - xBin.use = true; \ - } \ - } \ - \ - if (xBin.use) yxBin.use = true; \ - } \ - \ - if (yxBin.use) tyxBin.use = true; \ - } \ - } \ - } - -#define LXTB_ITERATE_LAYER_END_NO_USE \ - } \ - } \ - } \ - } \ - } \ - } \ - } - - -template<class HandlePoint> -void IterateLayer(LxTbLayer& layer, HandlePoint& handlePoint) -{ - for (int i = 0; i < layer.nofTYXBins; ++i) { - LxTbTYXBin& tyxBin = layer.tyxBins[i]; - - if (!tyxBin.use) continue; - - for (int j = 0; j < layer.nofYXBins; ++j) { - LxTbYXBin& yxBin = tyxBin.yxBins[j]; - - if (!yxBin.use) continue; - - for (int k = 0; k < layer.nofXBins; ++k) { - LxTbXBin& xBin = yxBin.xBins[k]; - - if (!xBin.use) continue; - - for (std::list<LxTbBinnedPoint>::iterator l = xBin.points.begin(); l != xBin.points.end(); ++l) { - LxTbBinnedPoint& point = *l; - - if (!point.use) continue; - - handlePoint(point); - } // for (list<LxTbBinnedPoint>::iterator l = xBin.points.begin(); l != xBin.points.end(); ++l) - } // for (int k = 0; k < layer.nofXBins; ++k) - } // for (int j = 0; j < layer.nofYXBins; ++j) - } // for (int i = 0; i < lastLayer.nofTYXBins; ++i) -} - -template<class HandlePoint> -void IterateNeighbourhood(LxTbLayer& layer, scaltype x, scaltype dx, scaltype scatX, scaltype y, scaltype dy, - scaltype scatY, timetype t, timetype dt, HandlePoint& handlePoint) -{ - scaltype dxSq = dx * dx; - scaltype scatXSq = scatX * scatX; - scaltype varX0 = scatXSq + dxSq; - scaltype wX = NOF_SIGMAS * sqrt(varX0 + dxSq); - scaltype minX = x - wX; - scaltype maxX = x + wX; - scaltype dySq = dy * dy; - scaltype scatYSq = scatY * scatY; - scaltype varY0 = scatYSq + dySq; - scaltype wY = NOF_SIGMAS * sqrt(varY0 + dySq); - scaltype minY = y - wY; - scaltype maxY = y + wY; - timetype varT0 = dt * dt; - timetype wT = NOF_SIGMAS * sqrt(2.0) * dt; - timetype minT = t - wT; - timetype maxT = t + wT; - - if (maxX < layer.minX || minX > layer.maxX || maxY < layer.minY || minY > layer.maxY || maxT < layer.minT - || minT > layer.maxT) - return; - - int minTind = (minT - layer.minT) / layer.timeBinLength; - - if (minTind < 0) minTind = 0; - else if (minTind > layer.lastTimeBinNumber) - minTind = layer.lastTimeBinNumber; - - int maxTind = (maxT - layer.minT) / layer.timeBinLength; - - if (maxTind < 0) maxTind = 0; - else if (maxTind > layer.lastTimeBinNumber) - maxTind = layer.lastTimeBinNumber; - - int minYind = (minY - layer.minY) / layer.yBinLength; - - if (minYind < 0) minYind = 0; - else if (minYind > layer.lastYBinNumber) - minYind = layer.lastYBinNumber; - - int maxYind = (maxY - layer.minY) / layer.yBinLength; - - if (maxYind < 0) maxYind = 0; - else if (maxYind > layer.lastYBinNumber) - maxYind = layer.lastYBinNumber; - - int minXind = (minX - layer.minX) / layer.xBinLength; - - if (minXind < 0) minXind = 0; - else if (minXind > layer.lastXBinNumber) - minXind = layer.lastXBinNumber; - - int maxXind = (maxX - layer.minX) / layer.xBinLength; - - if (maxXind < 0) maxXind = 0; - else if (maxXind > layer.lastXBinNumber) - maxXind = layer.lastXBinNumber; - - for (int tInd = minTind; tInd <= maxTind; ++tInd) { - LxTbTYXBin& tyxBin = layer.tyxBins[tInd]; - - for (int yInd = minYind; yInd <= maxYind; ++yInd) { - LxTbYXBin& yxBin = tyxBin.yxBins[yInd]; - - for (int xInd = minXind; xInd <= maxXind; ++xInd) { - LxTbXBin& xBin = yxBin.xBins[xInd]; - - for (std::list<LxTbBinnedPoint>::iterator pointIterator = xBin.points.begin(); - pointIterator != xBin.points.end(); ++pointIterator) { - LxTbBinnedPoint& point = *pointIterator; - scaltype errWinXSq = NOF_SIGMAS_SQ * (varX0 + point.dx * point.dx); - scaltype errWinYSq = NOF_SIGMAS_SQ * (varY0 + point.dy * point.dy); - scaltype errWinTSq = NOF_SIGMAS_SQ * (varT0 + point.dt * point.dt); - scaltype deltaX = point.x - x; - scaltype deltaXSq = deltaX * deltaX; - scaltype deltaY = point.y - y; - scaltype deltaYSq = deltaY * deltaY; - scaltype deltaT = point.t - t; - scaltype deltaTSq = deltaT * deltaT; - - if (deltaXSq > errWinXSq || deltaYSq > errWinYSq || deltaTSq > errWinTSq) continue; - - point.use = true; - xBin.use = true; - handlePoint(point); - } - - if (xBin.use) yxBin.use = true; - } - - if (yxBin.use) tyxBin.use = true; - } - } -} - -template<class HandlePoint> -void IterateNeighbourhoodConst(LxTbLayer& layer, HandlePoint& handlePoint) -{ -} - -#endif /* LXTBBINNED2_H */ diff --git a/reco/tracking/lx/TBBinned/LxTBDefinitions.h b/reco/tracking/lx/TBBinned/LxTBDefinitions.h deleted file mode 100644 index 3bd1df58d341b8fbd7105ab1acd23dbbbf9afaaa..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/TBBinned/LxTBDefinitions.h +++ /dev/null @@ -1,19 +0,0 @@ -/* Copyright (C) 2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifndef LXTBDEFINITIONS_H -#define LXTBDEFINITIONS_H - -//#define LXTB_TIE -#define LXTB_QA - -#ifdef LXTB_QA -#define LXTB_EMU_TS -//#define LXTB_DEBUG -#endif //LXTB_QA - -#define scaltype float -#define timetype double - -#endif /* LXTBDEFINITIONS_H */ diff --git a/reco/tracking/lx/TBBinned/LxTBMLTask.cxx b/reco/tracking/lx/TBBinned/LxTBMLTask.cxx deleted file mode 100644 index 1894b80a27e7f3d12378119ba3e23579c831fc1d..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/TBBinned/LxTBMLTask.cxx +++ /dev/null @@ -1,1730 +0,0 @@ -/* Copyright (C) 2016-2020 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -#include "LxTBMLTask.h" - -#include "CbmCluster.h" -#include "CbmMCDataManager.h" -#include "CbmMCTrack.h" -#include "CbmMatch.h" -#include "CbmMuchGeoScheme.h" -#include "CbmMuchPixelHit.h" -#include "CbmMuchPoint.h" - -#include <Logger.h> - -#include "TClonesArray.h" -#include "TDatabasePDG.h" -#include "TGeoArb8.h" -#include "TGeoBoolNode.h" -#include "TGeoCompositeShape.h" -#include "TGeoManager.h" -#include "TH1F.h" -#include "TMath.h" -#include "TRandom3.h" - -#include "LxTBMatEffs.h" -#include "Simple/LxCA.h" -#include "Simple/LxSettings.h" - -#ifdef __MACH__ -#include <mach/mach_time.h> -#include <sys/time.h> -#define CLOCK_REALTIME 0 -#define CLOCK_MONOTONIC 0 -inline int clock_gettime(int clk_id, struct timespec* t) -{ - mach_timebase_info_data_t timebase; - mach_timebase_info(&timebase); - uint64_t time; - time = mach_absolute_time(); - double nseconds = ((double) time * (double) timebase.numer) / ((double) timebase.denom); - double seconds = ((double) time * (double) timebase.numer) / ((double) timebase.denom * 1e9); - t->tv_sec = seconds; - t->tv_nsec = nseconds; - return 0; -} -#else -#include <time.h> -#endif - -using namespace std; - -ClassImp(LxTBMLFinder) - - Double_t speedOfLight = 0; -//static scaltype magneticFieldCorrections[] = { 1.5, 1.0, 1.7, 1.1 }; -static scaltype magneticFieldCorrections[] = {0, 0, 0, 0}; - -#ifdef LXTB_DEBUG -struct DebugTrack2 { - list<LxTbBinnedPoint*> points[NOF_STATIONS][NOF_LAYERS]; -}; - -static map<Int_t, DebugTrack2> debugTracks2; -static int nofOverXR = 0; -static int nofOverYR = 0; -static int nofOverTR = 0; - -static int nofOverXL = 0; -static int nofOverYL = 0; -static int nofOverTL = 0; - -static int nofFoundR = 0; -static int nofNotFoundR = 0; - -vector<vector<LxTBMLFinder::TrackDataHolder>>* gMCTracks = 0; -#endif //LXTB_DEBUG - -struct LxTbMLStation { - struct Q { - scaltype Q11, Q12, Q21, Q22; - }; - - int fStationNumber; - LxTbLayer* fLayers; - LxTbAbsorber fAbsorber; - scaltype fDeltaThetaX; - scaltype fThetaX; - scaltype fScatXRL; - scaltype fScatXLS; - scaltype fDeltaThetaY; - scaltype fThetaY; - scaltype fScatYRL; - scaltype fScatYLS; - Q qs[2]; - - LxTbMLStation(int stationNumber, int nofxb, int nofyb, int noftb) - : fStationNumber(stationNumber) - , fLayers(reinterpret_cast<LxTbLayer*>(new unsigned char[NOF_LAYERS * sizeof(LxTbLayer)])) - , fDeltaThetaX(0) - , fThetaX(0) - , fScatXRL(0) - , fScatXLS(0) - , fDeltaThetaY(0) - , fThetaY(0) - , fScatYRL(0) - , fScatYLS(0) - , fHandleMPoint(*this) - , fHandleRPoint(*this) - , fHandleLPoint(*this) - { - for (int i = 0; i < NOF_LAYERS; ++i) - new (&fLayers[i]) LxTbLayer(nofxb, nofyb, noftb); - } - - void Init() - { - for (int i = 0; i < NOF_LAYERS; ++i) { - //fLayers[i].xBinLength = (fLayers[i].maxX - fLayers[i].minX) / fLayers[i].nofXBins; - //fLayers[i].yBinLength = (fLayers[i].maxY - fLayers[i].minY) / fLayers[i].nofYXBins; - fLayers[i].Init(); - } - } - - void Init2() - { - fHandleMPoint.Init(); - fHandleRPoint.Init(); - fHandleLPoint.Init(); - } - - void Clear() - { - for (int i = 0; i < NOF_LAYERS; ++i) - fLayers[i].Clear(); - } - - void SetMinT(timetype v) - { - for (int i = 0; i < NOF_LAYERS; ++i) - fLayers[i].SetMinT(v); - } - - struct HandleMPoint { - LxTbMLStation& station; - timetype c; - scaltype deltaZr; - scaltype scatXRL; - - explicit HandleMPoint(LxTbMLStation& parent) : station(parent), c(0), deltaZr(0), scatXRL(0) {} - - void Init() - { - c = speedOfLight; - deltaZr = station.fLayers[2].z - station.fLayers[1].z; - scatXRL = - sqrt(station.fScatXRL * station.fScatXRL - + magneticFieldCorrections[station.fStationNumber] * magneticFieldCorrections[station.fStationNumber]); - } - - void operator()(LxTbBinnedPoint& point) - { - scaltype txR = point.x / station.fLayers[1].z; - scaltype tyR = point.y / station.fLayers[1].z; - scaltype pXr = point.x + txR * deltaZr; - scaltype pYr = point.y + tyR * deltaZr; - scaltype trajLenR = sqrt(1 + txR * txR + tyR * tyR) * deltaZr; - timetype pTr = point.t + 1.e9 * trajLenR / c; // 1.e9 to convert to ns. - station.fHandleRPoint.mPoint = &point; - station.fHandleLPoint.mPoint = &point; -#ifdef LXTB_DEBUG - struct Debug { - list<LxTbBinnedPoint*> points; - - void operator()(LxTbBinnedPoint& point) { points.push_back(&point); } - }; - - Debug debug; - IterateNeighbourhood(station.fLayers[2], pXr, point.dx, scatXRL, pYr, point.dy, station.fScatYRL, pTr, point.dt, - debug); - - if (LAST_STATION == station.fStationNumber) { - bool isSignal = false; - bool found = false; - - for (list<LxTbBinnedPoint::PointDesc>::const_iterator i = point.mcRefs.begin(); i != point.mcRefs.end(); ++i) { - const LxTbBinnedPoint::PointDesc& pd = *i; - const vector<vector<LxTBMLFinder::TrackDataHolder>>& mcTracks = *gMCTracks; - - if (mcTracks[pd.eventId][pd.trackId].isSignal) isSignal = true; - - for (list<LxTbBinnedPoint*>::iterator j = debugTracks2[pd.trackId].points[point.stationNumber][2].begin(); - j != debugTracks2[pd.trackId].points[point.stationNumber][2].end(); ++j) { - LxTbBinnedPoint* a = *j; - - for (list<LxTbBinnedPoint*>::iterator k = debug.points.begin(); k != debug.points.end(); ++k) { - LxTbBinnedPoint* b = *k; - - if (a == b) found = true; - } - } - } - - if (isSignal) { - if (!found) ++nofNotFoundR; - else - ++nofFoundR; - } - - struct Debug2 { - void operator()(LxTbBinnedPoint& point) - { - cout << "Debug2: Point: (" << point.x << ", " << point.y << ", " << point.t << ")" << endl; - } - }; - - Debug2 debug2; - IterateLayer(station.fLayers[2], debug2); - } -#endif //LXTB_DEBUG - IterateNeighbourhood(station.fLayers[2], pXr, point.dx, scatXRL, pYr, point.dy, station.fScatYRL, pTr, point.dt, - station.fHandleRPoint); -#ifdef LXTB_DEBUG - int qq = 0; - qq += 10; -#endif //LXTB_DEBUG - } - }; - - HandleMPoint fHandleMPoint; - - struct HandleRPoint { - LxTbMLStation& station; - timetype c; - scaltype deltaZl; - scaltype scatXLL; - LxTbBinnedPoint* mPoint; - - explicit HandleRPoint(LxTbMLStation& parent) : station(parent), c(0), deltaZl(0), scatXLL(0), mPoint(0) {} - - void Init() - { - c = speedOfLight; - deltaZl = station.fLayers[0].z - station.fLayers[1].z; - scatXLL = magneticFieldCorrections[station.fStationNumber]; - } - - void operator()(LxTbBinnedPoint& point) - { - scaltype txL = (point.x - mPoint->x) / (station.fLayers[2].z - station.fLayers[1].z); - scaltype tyL = (point.y - mPoint->y) / (station.fLayers[2].z - station.fLayers[1].z); - scaltype pXl = mPoint->x + txL * deltaZl; - scaltype pYl = mPoint->y + tyL * deltaZl; - scaltype trajLenL = sqrt(1 + txL * txL + tyL * tyL) * deltaZl; - timetype pTl = mPoint->t + 1.e9 * trajLenL / c; // 1.e9 to convert to ns and trajLenL is negative. - station.fHandleLPoint.rPoint = &point; - IterateNeighbourhood(station.fLayers[0], pXl, sqrt(mPoint->dx * mPoint->dx + point.dx * point.dx), scatXLL, pYl, - sqrt(mPoint->dy * mPoint->dy + point.dy * point.dy), 0, pTl, - mPoint->dt /*sqrt(mPoint->dt * mPoint->dt + point.dt * point.dt) / 2*/, - station.fHandleLPoint); - } - }; - - HandleRPoint fHandleRPoint; - - struct HandleLPoint { - LxTbMLStation& station; - scaltype deltaZ; - LxTbBinnedPoint* mPoint; - LxTbBinnedPoint* rPoint; - - explicit HandleLPoint(LxTbMLStation& parent) - : station(parent) - , deltaZ(parent.fLayers[2].z - parent.fLayers[0].z) - , mPoint(0) - , rPoint(0) - { - } - - void Init() { deltaZ = station.fLayers[0].z - station.fLayers[2].z; } - - void operator()(LxTbBinnedPoint& point) - { - LxTbBinnedTriplet* triplet = new LxTbBinnedTriplet(&point, rPoint, deltaZ); - mPoint->triplets.push_back(triplet); - } - }; - - HandleLPoint fHandleLPoint; - - void Reconstruct() { IterateLayer<HandleMPoint>(fLayers[1], fHandleMPoint); } -}; - -static void FindGeoChild(TGeoNode* node, const char* name, list<TGeoNode*>& results) -{ - Int_t nofChildren = node->GetNdaughters(); - - for (Int_t i = 0; i < nofChildren; ++i) { - TGeoNode* child = node->GetDaughter(i); - TString childName(child->GetName()); - - if (childName.Contains(name, TString::kIgnoreCase)) results.push_back(child); - } -} - -struct SignalParticle { - const char* fName; - Int_t fPdgCode; - scaltype fMinEnergy; -}; - -static SignalParticle particleDescs[] = {{"omega", 223, 1.5}, {"", -1, 0}}; - -struct LxTbDetector { - LxTbMLStation* fStations; - list<LxTBMLFinder::Chain*> recoTracks; - SignalParticle* fSignalParticle; - - LxTbDetector(int nofxb, int nofyb, int noftb) - : fStations(reinterpret_cast<LxTbMLStation*>(new unsigned char[NOF_STATIONS * sizeof(LxTbMLStation)])) - , fSignalParticle(&particleDescs[0]) - , fHandleLastPoint(*this) - { - for (int i = 0; i < NOF_STATIONS; ++i) - new (&fStations[i]) LxTbMLStation(i, nofxb, nofyb, noftb); - } - - void Init() - { - speedOfLight = 100 * TMath::C(); // Multiply by 100 to express in centimeters. - gMuonMass = TDatabasePDG::Instance()->GetParticle(13)->Mass(); - gElectronMass = TDatabasePDG::Instance()->GetParticle(11)->Mass(); - HandleGeometry(); - - for (int i = 0; i < NOF_STATIONS; ++i) { - LxTbMLStation& station = fStations[i]; - station.Init(); - } - - scaltype E = fSignalParticle->fMinEnergy; // GeV - scaltype E0 = E; - - for (int i = 0; i < NOF_STATIONS; ++i) { - LxTbMLStation& station = fStations[i]; - scaltype L = station.fAbsorber.width; // / cos(3.14159265 * 15 / 180); - E -= EnergyLoss(E, L, &station.fAbsorber); - scaltype Escat = (E0 + E) / 2; - //scaltype Escat = E; - scaltype deltaTheta = CalcThetaPrj(Escat, L, &station.fAbsorber); - station.fDeltaThetaX = deltaTheta; - station.fDeltaThetaY = deltaTheta; - - if (i > 0) { - scaltype deltaZLS = station.fLayers[1].z - fStations[i - 1].fLayers[1].z; - station.fScatXLS = station.fDeltaThetaX * deltaZLS; - station.fScatYLS = station.fDeltaThetaY * deltaZLS; - } - - scaltype q0XSq = station.fDeltaThetaX * station.fDeltaThetaX; - scaltype q0YSq = station.fDeltaThetaY * station.fDeltaThetaY; - station.qs[0] = {q0XSq * L * L / 3, q0XSq * L / 2, q0XSq * L / 2, q0XSq}; - station.qs[1] = {q0YSq * L * L / 3, q0YSq * L / 2, q0YSq * L / 2, q0YSq}; - E0 = E; - } - - scaltype Ls[NOF_STATIONS + 1]; - Ls[0] = fStations[0].fAbsorber.zCoord; - - for (int i = 1; i < NOF_STATIONS; ++i) - Ls[i] = fStations[i].fAbsorber.zCoord - Ls[i - 1]; - - Ls[NOF_STATIONS] = fStations[LAST_STATION].fLayers[1].z - Ls[LAST_STATION]; - - for (int s = 0; s < NOF_STATIONS; ++s) { - LxTbMLStation& station = fStations[s]; - scaltype L = station.fLayers[1].z; - int n = s + 1; - scaltype thetaXSq = 0; - scaltype thetaYSq = 0; - - for (int i = 1; i <= n; ++i) { - scaltype sumLi = 0; - - for (int j = 0; j < i; ++j) - sumLi += Ls[j]; - - thetaXSq += sumLi * sumLi * fStations[i].fDeltaThetaX * fStations[i].fDeltaThetaX; - thetaYSq += sumLi * sumLi * fStations[i].fDeltaThetaY * fStations[i].fDeltaThetaY; - } - - station.fThetaX = sqrt(thetaXSq) / L; - station.fThetaY = sqrt(thetaYSq) / L; - scaltype deltaZRL = station.fLayers[2].z - station.fLayers[1].z; - station.fScatXRL = station.fThetaX * deltaZRL; - station.fScatYRL = station.fThetaY * deltaZRL; - } - - for (int i = 0; i < NOF_STATIONS; ++i) { - LxTbMLStation& station = fStations[i]; - station.Init2(); - } - - fHandleRPoint.Init(); - } - - void Clear() - { - recoTracks.clear(); - - for (int i = 0; i < NOF_STATIONS; ++i) - fStations[i].Clear(); - } - - void SetMinT(timetype v) - { - for (int i = 0; i < NOF_STATIONS; ++i) - fStations[i].SetMinT(v); - } - - void HandleGeometry() - { - Double_t localCoords[3] = {0., 0., 0.}; - Double_t globalCoords[3]; - TGeoNavigator* pNavigator = gGeoManager->GetCurrentNavigator(); - gGeoManager->cd("/cave_1"); - list<TGeoNode*> detectors; - FindGeoChild(gGeoManager->GetCurrentNode(), "much", detectors); - - for (list<TGeoNode*>::iterator i = detectors.begin(); i != detectors.end(); ++i) { - TGeoNode* detector = *i; - pNavigator->CdDown(detector); - list<TGeoNode*> stations; - FindGeoChild(detector, "station", stations); - int stationNumber = 0; - - for (list<TGeoNode*>::iterator j = stations.begin(); j != stations.end(); ++j) { - TGeoNode* station = *j; - pNavigator->CdDown(station); - list<TGeoNode*> layers; - FindGeoChild(station, "layer", layers); - int layerNumber = 0; - - for (list<TGeoNode*>::iterator k = layers.begin(); k != layers.end(); ++k) { - TGeoNode* layer = *k; - pNavigator->CdDown(layer); - gGeoManager->LocalToMaster(localCoords, globalCoords); - - fStations[stationNumber].fLayers[layerNumber].z = globalCoords[2]; - fStations[stationNumber].fLayers[layerNumber].minX = 0; - fStations[stationNumber].fLayers[layerNumber].maxX = 0; - fStations[stationNumber].fLayers[layerNumber].xBinLength = 0; - fStations[stationNumber].fLayers[layerNumber].minY = 0; - fStations[stationNumber].fLayers[layerNumber].maxY = 0; - fStations[stationNumber].fLayers[layerNumber].yBinLength = 0; - - list<TGeoNode*> actives; - FindGeoChild(layer, "active", actives); - - for (list<TGeoNode*>::iterator l = actives.begin(); l != actives.end(); ++l) { - TGeoNode* active = *l; - pNavigator->CdDown(active); - TGeoCompositeShape* cs = dynamic_cast<TGeoCompositeShape*>(active->GetVolume()->GetShape()); - TGeoBoolNode* bn = cs->GetBoolNode(); - TGeoTrap* trap = dynamic_cast<TGeoTrap*>(bn->GetLeftShape()); - - if (0 != trap) { - Double_t* xy = trap->GetVertices(); - - for (int m = 0; m < 4; ++m) { - Double_t localActiveCoords[3] = {xy[2 * m], xy[2 * m + 1], 0.}; - Double_t globalActiveCoords[3]; - gGeoManager->LocalToMaster(localActiveCoords, globalActiveCoords); - - if (fStations[stationNumber].fLayers[layerNumber].minY > globalActiveCoords[1]) - fStations[stationNumber].fLayers[layerNumber].minY = globalActiveCoords[1]; - - if (fStations[stationNumber].fLayers[layerNumber].maxY < globalActiveCoords[1]) - fStations[stationNumber].fLayers[layerNumber].maxY = globalActiveCoords[1]; - - if (fStations[stationNumber].fLayers[layerNumber].minX > globalActiveCoords[0]) - fStations[stationNumber].fLayers[layerNumber].minX = globalActiveCoords[0]; - - if (fStations[stationNumber].fLayers[layerNumber].maxX < globalActiveCoords[0]) - fStations[stationNumber].fLayers[layerNumber].maxX = globalActiveCoords[0]; - } - } - - pNavigator->CdUp(); - } - - pNavigator->CdUp(); - ++layerNumber; - } - - ++stationNumber; - pNavigator->CdUp(); - } - - int nofStations = stationNumber; - - list<TGeoNode*> absorbers; - FindGeoChild(detector, "absorber", absorbers); - int absorberNumber = 0; - - for (list<TGeoNode*>::iterator j = absorbers.begin(); j != absorbers.end(); ++j) { - TGeoNode* absorber = *j; - pNavigator->CdDown(absorber); - TGeoVolume* absVol = gGeoManager->GetCurrentVolume(); - const TGeoBBox* absShape = static_cast<const TGeoBBox*>(absVol->GetShape()); - - if (absorberNumber < nofStations) { - gGeoManager->LocalToMaster(localCoords, globalCoords); - fStations[absorberNumber].fAbsorber.zCoord = globalCoords[2] - absShape->GetDZ(); - fStations[absorberNumber].fAbsorber.width = 2 * absShape->GetDZ(); - fStations[absorberNumber].fAbsorber.radLength = absVol->GetMaterial()->GetRadLen(); - fStations[absorberNumber].fAbsorber.rho = absVol->GetMaterial()->GetDensity(); - fStations[absorberNumber].fAbsorber.Z = absVol->GetMaterial()->GetZ(); - fStations[absorberNumber].fAbsorber.A = absVol->GetMaterial()->GetA(); - } - - ++absorberNumber; - pNavigator->CdUp(); - } - - pNavigator->CdUp(); - } - } // void HandleGeometry() - - struct HandleRPoint { - LxTbMLStation* rStation; - LxTbLayer* lLayer; - scaltype deltaZ; - timetype c; - - HandleRPoint() : rStation(0), lLayer(0), deltaZ(0), c(0) {} - - void Init() { c = speedOfLight; } - - void operator()(LxTbBinnedPoint& point) - { - for (list<LxTbBinnedTriplet*>::iterator i = point.triplets.begin(); i != point.triplets.end(); ++i) { - LxTbBinnedTriplet* triplet = *i; - scaltype x = point.x + triplet->tx * deltaZ; - scaltype y = point.y + triplet->ty * deltaZ; - scaltype trajLen = sqrt(1 + triplet->tx * triplet->tx + triplet->ty * triplet->ty) * deltaZ; - timetype t = point.t + 1.e9 * trajLen / c; // 1.e9 to convert to ns and trajLenL is negative. - handleLPoint.rTriplet = triplet; - IterateNeighbourhood(*lLayer, x, sqrt(point.dx * point.dx + triplet->dtx * triplet->dtx * deltaZ * deltaZ), - rStation->fDeltaThetaX * deltaZ, y, - sqrt(point.dy * point.dy + triplet->dty * triplet->dty * deltaZ * deltaZ), - rStation->fDeltaThetaY * deltaZ, t, point.dt, handleLPoint); - } - } - - struct HandleLPoint { - LxTbBinnedTriplet* rTriplet; - HandleLPoint() : rTriplet(0) {} - - void operator()(LxTbBinnedPoint& point) { rTriplet->neighbours.push_back(&point); } - }; - - HandleLPoint handleLPoint; - }; - - HandleRPoint fHandleRPoint; - - struct HandleLastPoint { - struct KFParamsCoord { - scaltype coord, tg, C11, C12, C21, C22; - - void Clear() - { - coord = 0; - tg = 0; - C11 = 1.0; - C12 = 0; - C21 = 0; - C22 = 0; - } - }; - - struct KFParams { - KFParamsCoord xParams; - KFParamsCoord yParams; - scaltype chi2; - - void Clear() - { - xParams.Clear(); - yParams.Clear(); - chi2 = 0; - } - }; - - LxTbDetector& detector; - - explicit HandleLastPoint(LxTbDetector& parent) : detector(parent) {} - - KFParamsCoord KFAddPointCoord(KFParamsCoord prevParam, scaltype m, scaltype V, scaltype& chi2, int stationNumber, - int layerNumber, int coordNumber) - { - KFParamsCoord param = prevParam; - const LxTbMLStation& station = detector.fStations[stationNumber]; - const LxTbLayer& layer = station.fLayers[layerNumber]; - const LxTbMLStation::Q& Q = station.qs[coordNumber]; - scaltype deltaZ = - LAST_LAYER == layerNumber - ? LAST_STATION == stationNumber ? 0 : layer.z - detector.fStations[stationNumber + 1].fLayers[0].z - : layer.z - station.fLayers[layerNumber + 1].z; - scaltype deltaZSq = deltaZ * deltaZ; - - // Extrapolate. - param.coord += prevParam.tg * deltaZ; // params[k].tg is unchanged. - - // Filter. - if (LAST_LAYER == layerNumber) { - param.C11 += prevParam.C12 * deltaZ + prevParam.C21 * deltaZ + prevParam.C22 * deltaZSq + Q.Q11; - param.C12 += prevParam.C22 * deltaZ + Q.Q12; - param.C21 += prevParam.C22 * deltaZ + Q.Q21; - param.C22 += Q.Q22; - } - else { - param.C11 += prevParam.C12 * deltaZ + prevParam.C21 * deltaZ + prevParam.C22 * deltaZSq; - param.C12 += prevParam.C22 * deltaZ; - param.C21 += prevParam.C22 * deltaZ; - } - - scaltype S = 1.0 / (V + param.C11); - scaltype Kcoord = param.C11 * S; - scaltype Ktg = param.C21 * S; - scaltype dzeta = m - param.coord; - param.coord += Kcoord * dzeta; - param.tg += Ktg * dzeta; - param.C21 -= param.C11 * Ktg; - param.C22 -= param.C12 * Ktg; - param.C11 *= 1.0 - Kcoord; - param.C12 *= 1.0 - Kcoord; - chi2 += dzeta * S * dzeta; - return param; - } - - KFParams KFAddPoint(KFParams prevParam, scaltype m[2], scaltype V[2], int stationNumber, int layerNumber) - { - KFParams param = {KFAddPointCoord(prevParam.xParams, m[0], V[0], param.chi2, stationNumber, layerNumber, 0), - KFAddPointCoord(prevParam.yParams, m[1], V[1], param.chi2, stationNumber, layerNumber, 1)}; - return param; - } - - KFParams KFAddTriplet(KFParams param, LxTbBinnedPoint* trackCandidatePoints[NOF_STATIONS][NOF_LAYERS], int level) - { - LxTbBinnedPoint** points = trackCandidatePoints[level]; - - for (int i = LAST_LAYER; i >= 0; --i) { - LxTbBinnedPoint* point = points[i]; - scaltype m[2] = {point->x, point->y}; - scaltype V[2] = {point->dx * point->dx, point->dy * point->dy}; - param = KFAddPoint(param, m, V, level, i); - } - - return param; - } - - void HandleTriplet(LxTbBinnedTriplet* triplet, LxTbBinnedPoint* trackCandidatePoints[NOF_STATIONS][NOF_LAYERS], - list<LxTBMLFinder::Chain>& chains, int level, KFParams kfParams) - { - trackCandidatePoints[level][0] = triplet->lPoint; - trackCandidatePoints[level][2] = triplet->rPoint; - kfParams = KFAddTriplet(kfParams, trackCandidatePoints, level); - - if (0 == level) chains.push_back(LxTBMLFinder::Chain(trackCandidatePoints, kfParams.chi2)); - else { - for (list<LxTbBinnedPoint*>::iterator i = triplet->neighbours.begin(); i != triplet->neighbours.end(); ++i) - HandlePoint(*i, trackCandidatePoints, chains, level - 1, kfParams); - } - } - - void HandlePoint(LxTbBinnedPoint* point, LxTbBinnedPoint* trackCandidatePoints[NOF_STATIONS][NOF_LAYERS], - list<LxTBMLFinder::Chain>& chains, int level, KFParams kfParams) - { - trackCandidatePoints[level][1] = point; - - for (list<LxTbBinnedTriplet*>::iterator i = point->triplets.begin(); i != point->triplets.end(); ++i) { - LxTbBinnedTriplet* triplet = *i; - HandleTriplet(triplet, trackCandidatePoints, chains, level, kfParams); - } - } - - void operator()(LxTbBinnedPoint& point) - { - LxTbBinnedPoint* trackCandidatePoints[NOF_STATIONS][NOF_LAYERS]; - list<LxTBMLFinder::Chain> chains; - KFParams kfParams = {{0, 0, 1.0, 0, 0, 1.0}, {0, 0, 1.0, 0, 0, 1.0}, 0}; - HandlePoint(&point, trackCandidatePoints, chains, LAST_STATION, kfParams); - const LxTBMLFinder::Chain* bestChain = 0; - scaltype chi2 = 0; - - for (list<LxTBMLFinder::Chain>::const_iterator i = chains.begin(); i != chains.end(); ++i) { - const LxTBMLFinder::Chain& chain = *i; - - if (0 == bestChain || chain.chi2 < chi2) { - bestChain = &chain; - chi2 = chain.chi2; - } - } - - if (0 != bestChain) detector.recoTracks.push_back(new LxTBMLFinder::Chain(*bestChain)); - } - }; - - HandleLastPoint fHandleLastPoint; - -#ifdef LXTB_DEBUG - struct Debug { - void operator()(LxTbBinnedPoint& point) - { - cout << "Point Point Point!!!" << endl; - - for (list<LxTbBinnedTriplet*>::iterator i = point.triplets.begin(); i != point.triplets.end(); ++i) - cout << "Triplet Triplet Triplet!!!" << endl; - } - }; - - Debug debug; -#endif //LXTB_DEBUG - - void Reconstruct() - { - for (int i = LAST_STATION; i >= 0; --i) { - LxTbMLStation& rStation = fStations[i]; - rStation.Reconstruct(); - -#ifdef LXTB_DEBUG - if (LAST_STATION == i) { - cout << "Points and triplets dump for the station #:" << i << endl; - IterateLayer(rStation.fLayers[0], debug); - IterateLayer(rStation.fLayers[1], debug); - IterateLayer(rStation.fLayers[2], debug); - } -#endif //LXTB_DEBUG - - if (i > 0) { - LxTbLayer& rLayer = rStation.fLayers[1]; - LxTbMLStation& lStation = fStations[i - 1]; - LxTbLayer& lLayer = lStation.fLayers[1]; - fHandleRPoint.rStation = &rStation; - fHandleRPoint.lLayer = &lLayer; - fHandleRPoint.deltaZ = lLayer.z - rLayer.z; - IterateLayer(rLayer, fHandleRPoint); - } - } - - LxTbMLStation& lastStation = fStations[LAST_STATION]; - LxTbLayer& lastLayer = lastStation.fLayers[1]; - IterateLayer(lastLayer, fHandleLastPoint); - } -}; - -static LxTbMLStation* gStations; - -LxTBMLFinder::LxTBMLFinder() - : fReconstructor(0) - , fIsEvByEv(true) - , fNofXBins(20) - , fNofYBins(20) - , fNofTBins(fIsEvByEv ? 5 : 1000) - , fNEvents(1000) -{ -} - -#ifdef LXTB_DEBUG -TH1F* deltaXRHisto[NOF_STATIONS]; -TH1F* deltaYRHisto[NOF_STATIONS]; -TH1F* deltaTRHisto[NOF_STATIONS]; - -TH1F* deltaXLHisto[NOF_STATIONS]; -TH1F* deltaYLHisto[NOF_STATIONS]; -TH1F* deltaTLHisto[NOF_STATIONS]; -#endif //LXTB_DEBUG - -InitStatus LxTBMLFinder::Init() -{ -#ifdef LXTB_DEBUG - gMCTracks = &fMCTracks; -#endif //LXTB_DEBUG - FairRootManager* ioman = FairRootManager::Instance(); - - if (0 == ioman) LOG(fatal) << "No FairRootManager"; - - int nofEventsInFile = ioman->CheckMaxEventNo(); - - if (nofEventsInFile < fNEvents) fNEvents = nofEventsInFile; - - LxTbDetector* pReconstructor = new LxTbDetector(fNofXBins, fNofYBins, fNofTBins); - fReconstructor = pReconstructor; - pReconstructor->Init(); - - fMuchPixelHits = static_cast<TClonesArray*>(ioman->GetObject("MuchPixelHit")); - -#ifdef LXTB_QA - CbmMCDataManager* mcManager = static_cast<CbmMCDataManager*>(ioman->GetObject("MCDataManager")); - fMuchMCPoints = mcManager->InitBranch("MuchPoint"); - fMuchClusters = static_cast<TClonesArray*>(ioman->GetObject("MuchCluster")); - fMuchPixelDigiMatches = static_cast<TClonesArray*>(ioman->GetObject("MuchDigiMatch")); - CbmMCDataArray* mcTracks = mcManager->InitBranch("MCTrack"); - - for (int i = 0; i < fNEvents; ++i) { - Int_t evSize = mcTracks->Size(0, i); - fMCTracks.push_back(vector<TrackDataHolder>()); - - if (0 >= evSize) continue; - - vector<TrackDataHolder>& evTracks = fMCTracks.back(); - const CbmMCTrack* posTrack = 0; - const CbmMCTrack* negTrack = 0; - - for (int j = 0; j < evSize; ++j) { - evTracks.push_back(TrackDataHolder()); - const CbmMCTrack* mcTrack = static_cast<const CbmMCTrack*>(mcTracks->Get(0, i, j)); - - if (mcTrack->GetPdgCode() == 13 || mcTrack->GetPdgCode() == -13) { - Double_t m = mcTrack->GetMass(); - Int_t motherId = mcTrack->GetMotherId(); - - if (motherId >= 0 - && static_cast<const CbmMCTrack*>(mcTracks->Get(0, i, motherId))->GetPdgCode() - == pReconstructor->fSignalParticle->fPdgCode) { - //const CbmMCTrack* motherTrack = static_cast<const CbmMCTrack*> (mcTracks->Get(0, i, motherId)); - - //if (fFinder->fSignalParticle->fPdgCode == motherTrack->GetPdgCode()) - { - evTracks.back().isSignal = true; - evTracks.back().isPos = mcTrack->GetPdgCode() == -13; - - if (-13 == mcTrack->GetPdgCode()) posTrack = mcTrack; - else - negTrack = mcTrack; - } - } - } - } // for (int j = 0; j < evSize; ++j) - } // for (int i = 0; i < fNEvents; ++i) - - fEventTimes.resize(fNEvents); - fEventTimes[0] = 50; - - for (int i = 1; i < fNEvents; ++i) - fEventTimes[i] = fEventTimes[i - 1] + 100; - - for (int i = 0; i < fNEvents; ++i) { - Int_t evSize = fMuchMCPoints->Size(0, i); - fMuchPoints.push_back(vector<PointDataHolder>()); - - if (0 >= evSize) continue; - - //++numEvents; - vector<PointDataHolder>& evPoints = fMuchPoints.back(); - - for (int j = 0; j < evSize; ++j) { - const CbmMuchPoint* pMuchPt = static_cast<const CbmMuchPoint*>(fMuchMCPoints->Get(0, i, j)); - PointDataHolder muchPt; - muchPt.x = (pMuchPt->GetXIn() + pMuchPt->GetXOut()) / 2; - muchPt.y = (pMuchPt->GetYIn() + pMuchPt->GetYOut()) / 2; - muchPt.t = fEventTimes[i] + pMuchPt->GetTime(); - muchPt.eventId = i; - muchPt.trackId = pMuchPt->GetTrackID(); - muchPt.pointId = j; - muchPt.stationNumber = CbmMuchGeoScheme::GetStationIndex(pMuchPt->GetDetectorId()); - muchPt.layerNumber = CbmMuchGeoScheme::GetLayerIndex(pMuchPt->GetDetectorId()); - evPoints.push_back(muchPt); - fMCTracks[muchPt.eventId][muchPt.trackId].pointInds[muchPt.stationNumber][muchPt.layerNumber] = muchPt.pointId; - } - } - - for (vector<vector<TrackDataHolder>>::iterator i = fMCTracks.begin(); i != fMCTracks.end(); ++i) { - vector<TrackDataHolder>& evTracks = *i; - - for (vector<TrackDataHolder>::iterator j = evTracks.begin(); j != evTracks.end(); ++j) { - TrackDataHolder& track = *j; - - if (!track.isSignal) continue; - - for (int k = 0; k < NOF_STATIONS; ++k) { - for (int l = 0; l < NOF_LAYERS; ++l) { - if (track.pointInds[k][l] < 0) { - track.isSignal = false; - break; - } - } - - if (!track.isSignal) break; - } - } - } - -#ifdef LXTB_DEBUG - for (int i = 0; i < NOF_STATIONS; ++i) { - char buf[64]; - sprintf(buf, "deltaXRHisto_%d", i); - deltaXRHisto[i] = new TH1F(buf, buf, 300, -15., 15.); - sprintf(buf, "deltaYRHisto_%d", i); - deltaYRHisto[i] = new TH1F(buf, buf, 300, -15., 15.); - sprintf(buf, "deltaTRHisto_%d", i); - deltaTRHisto[i] = new TH1F(buf, buf, 300, -15., 15.); - - sprintf(buf, "deltaXLHisto_%d", i); - deltaXLHisto[i] = new TH1F(buf, buf, 300, -15., 15.); - sprintf(buf, "deltaYLHisto_%d", i); - deltaYLHisto[i] = new TH1F(buf, buf, 300, -15., 15.); - sprintf(buf, "deltaTLHisto_%d", i); - deltaTLHisto[i] = new TH1F(buf, buf, 300, -15., 15.); - } -#endif //LXTB_DEBUG -#endif //LXTB_QA - - return kSUCCESS; //, kERROR, kFATAL -} - -static Int_t currentEventN = 0; -static unsigned long long tsStartTime = 0; - -#ifdef LXTB_QA -static long fullDuration = 0; -static int nofTriggerings = 0; -#endif //LXTB_QA - -#ifdef LXTB_EMU_TS -static Double_t min_ts_time = 100000; -static Double_t max_ts_time = -100000; -static list<LxTbBinnedPoint> ts_points; -#endif //LXTB_EMU_TS - -#ifdef LXTB_DEBUG -/*struct LxTbDebug - { - struct Triplet - { - Int_t left; - Int_t middle; - Int_t right; - - Triplet(Int_t l, Int_t m, Int_t r) : left(l), middle(m), right(r) {} - }; - - struct TrLess - { - bool operator()(const Triplet& a, const Triplet& b) const - { - if (a.left < b.left) - return true; - else if (a.middle < b.middle) - return true; - else if (a.right < b.right) - return true; - - return false; - } - }; - - map<Triplet, bool, TrLess> triplets[NOF_STATIONS]; - int stationNumber; - - explicit LxTbDebug(vector<LxTBMLFinder::TrackDataHolder>& mcTracks) : stationNumber(-1) - { - for (vector<LxTBMLFinder::TrackDataHolder>::const_iterator i = mcTracks.begin(); i != mcTracks.end(); ++i) - { - const LxTBMLFinder::TrackDataHolder& track = *i; - - if (!track.isSignal) - continue; - - for (int j = 0; j < NOF_STATIONS; ++j) - { - Triplet trip(track.pointInds[j][0], track.pointInds[j][1], track.pointInds[j][2]); - triplets[j][trip] = false; - } - } - } - - void operator()(const LxTbBinnedPoint& point) - { - if (!point.use) - return; - - for (list<LxTbBinnedTriplet*>::const_iterator i = point.triplets.begin(); i != point.triplets.end(); ++i) - { - LxTbBinnedTriplet* trip = *i; - - for (list<LxTbBinnedPoint::PointDesc>::const_iterator j = point.mcRefs.begin(); j != point.mcRefs.end(); ++j) - { - Int_t mId = j->pointId; - - for (list<LxTbBinnedPoint::PointDesc>::const_iterator k = trip->rPoint->mcRefs.begin(); k != trip->rPoint->mcRefs.end(); ++k) - { - Int_t rId = k->pointId; - - for (list<LxTbBinnedPoint::PointDesc>::const_iterator l = trip->lPoint->mcRefs.begin(); l != trip->lPoint->mcRefs.end(); ++l) - { - Int_t lId = l->pointId; - Triplet mcTrip(lId, mId, rId); - map<Triplet, bool, TrLess>::iterator iter = triplets[stationNumber].find(mcTrip); - - if (iter != triplets[stationNumber].end()) - { - iter->second = true; - cout << stationNumber << " " << iter->first.left << " " << iter->first.middle << " " << iter->first.right << " " << iter->second << endl; - } - } - } - } - } - } - };*/ -#endif //LXTB_DEBUG - -void LxTBMLFinder::Exec(Option_t* opt) -{ -#ifdef LXTB_DEBUG - debugTracks2.clear(); -#endif //LXTB_DEBUG - LxTbDetector* pReconstructor = static_cast<LxTbDetector*>(fReconstructor); - pReconstructor->Clear(); - pReconstructor->SetMinT(tsStartTime); - - for (int i = 0; i < fMuchPixelHits->GetEntriesFast(); ++i) { - const CbmMuchPixelHit* hit = static_cast<const CbmMuchPixelHit*>(fMuchPixelHits->At(i)); - Int_t stationNumber = CbmMuchGeoScheme::GetStationIndex(hit->GetAddress()); - Int_t layerNumber = CbmMuchGeoScheme::GetLayerIndex(hit->GetAddress()); - scaltype x = hit->GetX(); - scaltype y = hit->GetY(); - timetype t = hit->GetTime(); - scaltype dx = hit->GetDx(); - scaltype dy = hit->GetDy(); - timetype dt = 4; //hit->GetTimeError(); - LxTbBinnedPoint point(x, dx, y, dy, t, dt, i, LAST_STATION == stationNumber); -#ifdef LXTB_QA - point.isTrd = false; - point.stationNumber = stationNumber; - point.layerNumber = layerNumber; - Int_t clusterId = hit->GetRefId(); - const CbmCluster* cluster = static_cast<const CbmCluster*>(fMuchClusters->At(clusterId)); - Int_t nDigis = cluster->GetNofDigis(); - double avT = 0; -#ifdef LXTB_EMU_TS - double avTErr = 0; -#endif //LXTB_EMU_TS - int nofT = 0; - - for (Int_t j = 0; j < nDigis; ++j) { - const CbmMatch* digiMatch = static_cast<const CbmMatch*>(fMuchPixelDigiMatches->At(cluster->GetDigi(j))); - Int_t nMCs = digiMatch->GetNofLinks(); - - for (Int_t k = 0; k < nMCs; ++k) { - const CbmLink& lnk = digiMatch->GetLink(k); - Int_t eventId = fIsEvByEv ? currentEventN : lnk.GetEntry(); - Int_t pointId = lnk.GetIndex(); - const FairMCPoint* pMCPt = static_cast<const FairMCPoint*>(fMuchMCPoints->Get(0, eventId, pointId)); - Int_t trackId = pMCPt->GetTrackID(); - LxTbBinnedPoint::PointDesc ptDesc = {eventId, pointId, trackId}; - point.mcRefs.push_back(ptDesc); - Double_t deltaT = fMuchPoints[eventId][pointId].t; -#ifdef LXTB_EMU_TS - deltaT += gRandom->Gaus(0, 4); - avTErr += 4 * 4; -#endif //LXTB_EMU_TS - avT += deltaT; - ++nofT; - } - } - - if (nofT > 0) { - avT /= nofT; -#ifdef LXTB_EMU_TS - avTErr = TMath::Sqrt(avTErr); - avTErr /= nofT; - dt = avT; -#endif //LXTB_EMU_TS - } - - t = avT; -#endif //LXTB_QA - point.t = t; - //point.t = tsStartTime + hit->GetTime(); - //point.dt = hit->GetTimeError(); - -#ifdef LXTB_EMU_TS - ts_points.push_back(point); - - if (min_ts_time > t) min_ts_time = t; - - if (max_ts_time < t) max_ts_time = t; -#else //LXTB_EMU_TS - -#ifdef LXTB_DEBUG - int qq = 0; - - if (LAST_STATION == stationNumber && LAST_LAYER == layerNumber) qq += 10; -#endif //LXTB_DEBUG - scaltype minY = pReconstructor->fStations[stationNumber].fLayers[layerNumber].minY; - scaltype binSizeY = pReconstructor->fStations[stationNumber].fLayers[layerNumber].yBinLength; - int lastYBin = (pReconstructor->fStations[stationNumber].fLayers[layerNumber].lastYBinNumber); - scaltype minX = pReconstructor->fStations[stationNumber].fLayers[layerNumber].minX; - scaltype binSizeX = pReconstructor->fStations[stationNumber].fLayers[layerNumber].xBinLength; - int lastXBin = pReconstructor->fStations[stationNumber].fLayers[layerNumber].lastXBinNumber; - int last_timebin = pReconstructor->fStations[stationNumber].fLayers[layerNumber].lastTimeBinNumber; - - int tInd = (t - pReconstructor->fStations[stationNumber].fLayers[layerNumber].minT) / TIMEBIN_LENGTH; - - if (tInd < 0) tInd = 0; - else if (tInd > last_timebin) - tInd = last_timebin; - - LxTbTYXBin& tyxBin = pReconstructor->fStations[stationNumber].fLayers[layerNumber].tyxBins[tInd]; - int yInd = (y - minY) / binSizeY; - - if (yInd < 0) yInd = 0; - else if (yInd > lastYBin) - yInd = lastYBin; - - LxTbYXBin& yxBin = tyxBin.yxBins[yInd]; - int xInd = (x - minX) / binSizeX; - - if (xInd < 0) xInd = 0; - else if (xInd > lastXBin) - xInd = lastXBin; - - LxTbXBin& xBin = yxBin.xBins[xInd]; - xBin.points.push_back(point); - - if (LAST_STATION == stationNumber) { - xBin.use = true; - yxBin.use = true; - tyxBin.use = true; - - if (0 == layerNumber) xBin.use = true; - else if (1 == layerNumber) - xBin.use = true; - else if (2 == layerNumber) - xBin.use = true; - } -#endif //LXTB_EMU_TS - } // for (int i = 0; i < fMuchPixelHits->GetEntriesFast(); ++i) - -#ifdef LXTB_DEBUG - struct DebugTrack { - list<Int_t> pointIds[NOF_STATIONS][NOF_LAYERS]; - }; - - map<Int_t, DebugTrack> debugTracks; - - for (int i = 0; i < NOF_STATIONS; ++i) { - for (int j = 0; j < NOF_LAYERS; ++j) { - const LxTbLayer& layer = pReconstructor->fStations[i].fLayers[j]; - - for (int k = 0; k < layer.nofTYXBins; ++k) { - LxTbTYXBin& tyxBin = layer.tyxBins[k]; - - for (int l = 0; l < layer.nofYXBins; ++l) { - LxTbYXBin& yxBin = tyxBin.yxBins[l]; - - for (int m = 0; m < layer.nofXBins; ++m) { - LxTbXBin& xBin = yxBin.xBins[m]; - - for (std::list<LxTbBinnedPoint>::iterator n = xBin.points.begin(); n != xBin.points.end(); ++n) { - LxTbBinnedPoint& point = *n; - - for (list<LxTbBinnedPoint::PointDesc>::const_iterator o = point.mcRefs.begin(); o != point.mcRefs.end(); - ++o) { - const LxTbBinnedPoint::PointDesc& pd = *o; - debugTracks[pd.trackId].pointIds[point.stationNumber][point.layerNumber].push_back(pd.pointId); - debugTracks2[pd.trackId].points[point.stationNumber][point.layerNumber].push_back(&point); - } - } - } - } - } - } - } -#endif //LXTB_DEBUG - - timespec ts; - clock_gettime(CLOCK_REALTIME, &ts); - long beginTime = ts.tv_sec * 1000000000 + ts.tv_nsec; - - pReconstructor->Reconstruct(); - - clock_gettime(CLOCK_REALTIME, &ts); - long endTime = ts.tv_sec * 1000000000 + ts.tv_nsec; - fullDuration += endTime - beginTime; - -#ifdef LXTB_DEBUG - static int nofTriplesAll[NOF_STATIONS] = {0, 0, 0, 0}; - static int nofTriplesFound[NOF_STATIONS] = {0, 0, 0, 0}; - - struct Debug { - struct Triplet { - Int_t left; - Int_t middle; - Int_t right; - - Triplet(Int_t l, Int_t m, Int_t r) : left(l), middle(m), right(r) {} - }; - - struct TrLess { - bool operator()(const Triplet& a, const Triplet& b) const - { - if (a.left < b.left) return true; - else if (a.middle < b.middle) - return true; - else if (a.right < b.right) - return true; - - return false; - } - }; - - map<Triplet, bool, TrLess> triplets[NOF_STATIONS]; - int stationNumber; - - explicit Debug(vector<TrackDataHolder>& mcTracks) : stationNumber(-1) - { - for (vector<TrackDataHolder>::const_iterator i = mcTracks.begin(); i != mcTracks.end(); ++i) { - const TrackDataHolder& track = *i; - - if (!track.isSignal) continue; - - for (int j = 0; j < NOF_STATIONS; ++j) { - Triplet trip(track.pointInds[j][0], track.pointInds[j][1], track.pointInds[j][2]); - triplets[j][trip] = false; - } - } - } - - void operator()(const LxTbBinnedPoint& point) - { - if (!point.use) return; - - for (list<LxTbBinnedTriplet*>::const_iterator i = point.triplets.begin(); i != point.triplets.end(); ++i) { - LxTbBinnedTriplet* trip = *i; - - for (list<LxTbBinnedPoint::PointDesc>::const_iterator j = point.mcRefs.begin(); j != point.mcRefs.end(); ++j) { - Int_t mId = j->pointId; - - for (list<LxTbBinnedPoint::PointDesc>::const_iterator k = trip->rPoint->mcRefs.begin(); - k != trip->rPoint->mcRefs.end(); ++k) { - Int_t rId = k->pointId; - - for (list<LxTbBinnedPoint::PointDesc>::const_iterator l = trip->lPoint->mcRefs.begin(); - l != trip->lPoint->mcRefs.end(); ++l) { - Int_t lId = l->pointId; - Triplet mcTrip(lId, mId, rId); - map<Triplet, bool, TrLess>::iterator iter = triplets[stationNumber].find(mcTrip); - - if (iter != triplets[stationNumber].end()) iter->second = true; - } - } - } - } - } - }; - - Debug debug(fMCTracks[currentEventN]); - - /*for (int i = 0; i < fMuchPixelHits->GetEntriesFast(); ++i) - { - const CbmMuchPixelHit* hit = static_cast<const CbmMuchPixelHit*> (fMuchPixelHits->At(i)); - Int_t stationNumber = CbmMuchGeoScheme::GetStationIndex(hit->GetAddress()); - Int_t layerNumber = CbmMuchGeoScheme::GetLayerIndex(hit->GetAddress()); - Int_t clusterId = hit->GetRefId(); - const CbmCluster* cluster = static_cast<const CbmCluster*> (fMuchClusters->At(clusterId)); - Int_t nDigis = cluster->GetNofDigis(); - - for (Int_t j = 0; j < nDigis; ++j) - { - const CbmMatch* digiMatch = static_cast<const CbmMatch*> (fMuchPixelDigiMatches->At(cluster->GetDigi(j))); - Int_t nMCs = digiMatch->GetNofLinks(); - - for (Int_t k = 0; k < nMCs; ++k) - { - const CbmLink& lnk = digiMatch->GetLink(k); - Int_t pointId = lnk.GetIndex(); - const FairMCPoint* pMCPt = static_cast<const FairMCPoint*> (fMuchMCPoints->Get(0, currentEventN, pointId)); - Int_t trackId = pMCPt->GetTrackID(); - debugTracks[trackId].pointIds[stationNumber][layerNumber].push_back(pointId); - } - } - }*/ - - /*for (map<Int_t, DebugTrack>::const_iterator i = debugTracks.begin(); i != debugTracks.end(); ++i) - { - const DebugTrack& dt = i->second; - - for (int j = 0; j < NOF_STATIONS; ++j) - { - for (list<Int_t>::const_iterator k = dt.pointIds[j][1].begin(); k != dt.pointIds[j][1].end(); ++k) - { - Int_t mId = *k; - - for (list<Int_t>::const_iterator l = dt.pointIds[j][2].begin(); l != dt.pointIds[j][2].end(); ++l) - { - Int_t rId = *l; - - for (list<Int_t>::const_iterator m = dt.pointIds[j][0].begin(); m != dt.pointIds[j][0].end(); ++m) - { - Int_t lId = *m; - Debug::Triplet mcTrip(lId, mId, rId); - map<Debug::Triplet, bool, Debug::TrLess>::iterator iter = debug.triplets[j].find(mcTrip); - - if (iter != debug.triplets[j].end()) - iter->second = true; - } - } - } - } - }*/ - - for (map<Int_t, DebugTrack2>::const_iterator i = debugTracks2.begin(); i != debugTracks2.end(); ++i) { - const DebugTrack2& dt = i->second; - - for (int j = 0; j < NOF_STATIONS; ++j) { - scaltype deltaZr = pReconstructor->fStations[j].fLayers[2].z - pReconstructor->fStations[j].fLayers[1].z; - scaltype deltaZl = pReconstructor->fStations[j].fLayers[0].z - pReconstructor->fStations[j].fLayers[1].z; - - for (list<LxTbBinnedPoint*>::const_iterator k = dt.points[j][1].begin(); k != dt.points[j][1].end(); ++k) { - LxTbBinnedPoint* mPt = *k; - scaltype rTx = mPt->x / pReconstructor->fStations[j].fLayers[1].z; - scaltype rTy = mPt->y / pReconstructor->fStations[j].fLayers[1].z; - scaltype rX = mPt->x + rTx * deltaZr; - scaltype rY = mPt->y + rTy * deltaZr; - scaltype trajLenR = sqrt(1 + rTx * rTx + rTy * rTy) * deltaZr; - timetype rT = mPt->t + 1.e9 * trajLenR / speedOfLight; // 1.e9 to convert to ns. - - for (list<LxTbBinnedPoint*>::const_iterator l = dt.points[j][2].begin(); l != dt.points[j][2].end(); ++l) { - LxTbBinnedPoint* rPt = *l; - scaltype wXr = NOF_SIGMAS - * sqrt(pReconstructor->fStations[j].fHandleMPoint.scatXRL - * pReconstructor->fStations[j].fHandleMPoint.scatXRL - + mPt->dx * mPt->dx + rPt->dx * rPt->dx); - scaltype wYr = NOF_SIGMAS - * sqrt(pReconstructor->fStations[j].fScatYRL * pReconstructor->fStations[j].fScatYRL - + mPt->dy * mPt->dy + rPt->dy * rPt->dy); - scaltype wTr = NOF_SIGMAS * sqrt(mPt->dt * mPt->dt + rPt->dt * rPt->dt); - deltaXRHisto[j]->Fill(rPt->x - rX); - deltaYRHisto[j]->Fill(rPt->y - rY); - deltaTRHisto[j]->Fill(rPt->t - rT); - - if (LAST_STATION == j) { - if (abs(rPt->x - rX) > wXr) ++nofOverXR; - - if (abs(rPt->y - rY) > wYr) ++nofOverYR; - - if (abs(rPt->t - rT) > wTr) ++nofOverTR; - } - - for (list<LxTbBinnedPoint*>::const_iterator m = dt.points[j][0].begin(); m != dt.points[j][0].end(); ++m) { - LxTbBinnedPoint* lPt = *m; - scaltype wXl = NOF_SIGMAS - * sqrt(pReconstructor->fStations[j].fHandleRPoint.scatXLL - * pReconstructor->fStations[j].fHandleRPoint.scatXLL - + mPt->dx * mPt->dx + rPt->dx * rPt->dx + lPt->dx * lPt->dx); - scaltype wYl = NOF_SIGMAS * sqrt(mPt->dy * mPt->dy + rPt->dy * rPt->dy + lPt->dy * lPt->dy); - scaltype wTl = NOF_SIGMAS * sqrt(mPt->dt * mPt->dt + lPt->dt * lPt->dt); - scaltype lTx = (rPt->x - mPt->x) - / (pReconstructor->fStations[j].fLayers[2].z - pReconstructor->fStations[j].fLayers[1].z); - scaltype lTy = (rPt->y - mPt->y) - / (pReconstructor->fStations[j].fLayers[2].z - pReconstructor->fStations[j].fLayers[1].z); - scaltype lX = mPt->x + lTx * deltaZl; - scaltype lY = mPt->y + lTy * deltaZl; - scaltype trajLenL = sqrt(1 + lTx * lTx + lTy * lTy) * deltaZl; - timetype lT = mPt->t + 1.e9 * trajLenL / speedOfLight; // 1.e9 to convert to ns and trajLenL is negative. - deltaXLHisto[j]->Fill(lPt->x - lX); - deltaYLHisto[j]->Fill(lPt->y - lY); - deltaTLHisto[j]->Fill(lPt->t - lT); - - if (LAST_STATION == j) { - if (abs(lPt->x - lX) > wXl) ++nofOverXL; - - if (abs(lPt->y - lY) > wYl) ++nofOverYL; - - if (abs(lPt->t - lT) > wTl) ++nofOverTL; - } - } - } - } - } - } - - cout << "nofOverXR = " << nofOverXR << endl; - cout << "nofOverYR = " << nofOverYR << endl; - cout << "nofOverTR = " << nofOverTR << endl; - - cout << "nofOverXL = " << nofOverXL << endl; - cout << "nofOverYL = " << nofOverYL << endl; - cout << "nofOverTL = " << nofOverTL << endl; - - cout << "nofFoundR = " << nofFoundR << endl; - cout << "nofNotFoundR = " << nofNotFoundR << endl; - - for (int i = LAST_STATION; i >= 0; --i) { - debug.stationNumber = i; - IterateLayer(pReconstructor->fStations[i].fLayers[1], debug); - - nofTriplesAll[i] += debug.triplets[i].size(); - - for (map<Debug::Triplet, bool, Debug::TrLess>::const_iterator j = debug.triplets[i].begin(); - j != debug.triplets[i].end(); ++j) { - if (j->second) ++nofTriplesFound[i]; - } - - double foundPerc = 100 * nofTriplesFound[i]; - foundPerc /= nofTriplesAll[i]; - cout << "For station #:" << i << " found triplets: " << foundPerc << " ( " << nofTriplesFound[i] << " / " - << nofTriplesAll[i] << " )" << endl; - } -#endif //LXTB_DEBUG - - cout << "In event #" << currentEventN << " reconstructed: " << pReconstructor->recoTracks.size() << " tracks" << endl; - - static int nofSignals = 0; - static int nofRecoSignals = 0; - bool hasPos = false; - bool hasNeg = false; - - for (vector<TrackDataHolder>::const_iterator i = fMCTracks[currentEventN].begin(); - i != fMCTracks[currentEventN].end(); ++i) { - const TrackDataHolder& dh = *i; - - if (!dh.isSignal) continue; - - if (dh.isPos) hasPos = true; - else - hasNeg = true; - } - - if (hasPos && hasNeg) ++nofSignals; - - bool hasPos2 = false; - bool hasNeg2 = false; - - for (list<Chain*>::const_iterator i = pReconstructor->recoTracks.begin(); i != pReconstructor->recoTracks.end(); - ++i) { - const Chain* track = *i; - - if ((track->points[0][2]->x - track->points[0][0]->x) - / (pReconstructor->fStations[0].fLayers[2].z - pReconstructor->fStations[0].fLayers[0].z) - - track->points[0][1]->x / pReconstructor->fStations[0].fLayers[1].z - > 0) - hasPos2 = true; - else - hasNeg2 = true; - } - - if (hasPos2 && hasNeg2) { - ++nofTriggerings; - - if (hasNeg && hasPos) ++nofRecoSignals; - } - - cout << "The number of triggerings: " << nofTriggerings << endl; - cout << "The triggering efficiency: " << (0 == nofSignals ? 100 : 100 * nofRecoSignals / nofSignals) << " % ( " - << nofRecoSignals << " / " << nofSignals << " )" << endl; - - recoTracks.splice(recoTracks.end(), pReconstructor->recoTracks); - ++currentEventN; - tsStartTime += 100; -} - -struct RecoTrackData { - Int_t eventId; - Int_t trackId; - - RecoTrackData(Int_t eId, Int_t tId) : eventId(eId), trackId(tId) {} -}; - -struct RTDLess { - bool operator()(const RecoTrackData& x, const RecoTrackData& y) const - { - if (x.eventId < y.eventId) return true; - - return x.trackId < y.trackId; - } -}; - -static void SaveHisto(TH1* histo) -{ - TFile* curFile = TFile::CurrentFile(); - TString histoName = histo->GetName(); - histoName += ".root"; - TFile fh(histoName.Data(), "RECREATE"); - histo->Write(); - fh.Close(); - delete histo; - TFile::CurrentFile() = curFile; -} - -void LxTBMLFinder::Finish() -{ -#ifdef LXTB_EMU_TS - Double_t tCoeff = TIMEBIN_LENGTH * nof_timebins / (max_ts_time - min_ts_time); - - for (list<LxTbBinnedPoint>::iterator i = ts_points.begin(); i != ts_points.end(); ++i) { - LxTbBinnedPoint& point = *i; - point.t = (point.t - min_ts_time) * tCoeff; - point.dt *= tCoeff; - - bool isTrd = point.isTrd; - Int_t stationNumber = point.stationNumber; - scaltype minY = (isTrd ? fFinder->trdStation.minY : fFinder->stations[stationNumber].minY); - scaltype binSizeY = (isTrd ? fFinder->trdStation.binSizeY : fFinder->stations[stationNumber].binSizeY); - int lastYBin = (isTrd ? fFinder->trdStation.lastYBin : fFinder->stations[stationNumber].lastYBin); - scaltype minX = (isTrd ? fFinder->trdStation.minX : fFinder->stations[stationNumber].minX); - scaltype binSizeX = (isTrd ? fFinder->trdStation.binSizeX : fFinder->stations[stationNumber].binSizeX); - int lastXBin = (isTrd ? fFinder->trdStation.lastXBin : fFinder->stations[stationNumber].lastXBin); - - int tInd = (point.t - fFinder->minT) / CUR_TIMEBIN_LENGTH; - - if (tInd < 0) tInd = 0; - else if (tInd > last_timebin) - tInd = last_timebin; - - LxTbTYXBin& tyxBin = - (isTrd ? fFinder->trdStation.tyxBinsArr[stationNumber][tInd] : fFinder->stations[stationNumber].tyxBins[tInd]); - int yInd = (point.y - minY) / binSizeY; - - if (yInd < 0) yInd = 0; - else if (yInd > lastYBin) - yInd = lastYBin; - - LxTbYXBin& yxBin = tyxBin.yxBins[yInd]; - int xInd = (point.x - minX) / binSizeX; - - if (xInd < 0) xInd = 0; - else if (xInd > lastXBin) - xInd = lastXBin; - - LxTbXBin& xBin = yxBin.xBins[xInd]; - xBin.points.push_back(point); - - if (/*!hasTrd && */ CUR_LAST_STATION == stationNumber) { - xBin.use = true; - yxBin.use = true; - tyxBin.use = true; - } - } - -#ifdef LXTB_TIE - fDetector->SetTSBegin(0); -#endif //LXTB_TIE - - fFinder->Reconstruct(); - - for (list<timetype>::iterator i = shortSignalMCTimes.begin(); i != shortSignalMCTimes.end(); ++i) { - timetype& v = *i; - v = (v - min_ts_time) * tCoeff; - } - - for (list<timetype>::iterator i = longSignalMCTimes.begin(); i != longSignalMCTimes.end(); ++i) { - timetype& v = *i; - v = (v - min_ts_time) * tCoeff; - } - - for (int i = 0; i < fFinder->nofTrackBins; ++i) { - list<LxTbBinnedFinder::Chain*>& recoTracksBin = fFinder->recoTracks[i]; - - for (list<LxTbBinnedFinder::Chain*>::const_iterator j = recoTracksBin.begin(); j != recoTracksBin.end(); ++j) - recoTracks.push_back(*j); - } - - SpliceTriggerings(triggerTimes_trd0_sign0_dist0, fFinder->triggerTimes_trd0_sign0_dist0); - SpliceTriggerings(triggerTimes_trd0_sign0_dist1, fFinder->triggerTimes_trd0_sign0_dist1); - SpliceTriggerings(triggerTimes_trd0_sign1_dist0, fFinder->triggerTimes_trd0_sign1_dist0); - SpliceTriggerings(triggerTimes_trd0_sign1_dist1, fFinder->triggerTimes_trd0_sign1_dist1); - SpliceTriggerings(triggerTimes_trd1_sign0_dist0, fFinder->triggerTimes_trd1_sign0_dist0); - SpliceTriggerings(triggerTimes_trd1_sign0_dist1, fFinder->triggerTimes_trd1_sign0_dist1); - SpliceTriggerings(triggerTimes_trd1_sign1_dist0, fFinder->triggerTimes_trd1_sign1_dist0); - SpliceTriggerings(triggerTimes_trd1_sign1_dist1, fFinder->triggerTimes_trd1_sign1_dist1); -#endif //LXTB_EMU_TS - cout << "LxTbBinnedFinder::Reconstruct() full duration was: " << fullDuration << endl; - - int nofRecoTracks = recoTracks.size(); - cout << "LxTbBinnedFinder::Reconstruct() the number of found tracks: " << nofRecoTracks << endl; - -#ifdef LXTB_QA - static int nofSignalTracks = 0; - static int nofRecoSignalTracks = 0; - int eventN = 0; - - for (vector<vector<TrackDataHolder>>::iterator i = fMCTracks.begin(); i != fMCTracks.end(); ++i) { - vector<TrackDataHolder>& evTracks = *i; - - for (vector<TrackDataHolder>::iterator j = evTracks.begin(); j != evTracks.end(); ++j) { - TrackDataHolder& track = *j; - - if (!track.isSignal) continue; - - ++nofSignalTracks; - - int nofMatchPoints = 0; - - for (list<Chain*>::const_iterator k = recoTracks.begin(); k != recoTracks.end(); ++k) { - const Chain* chain = *k; - - for (int l = 0; l < NOF_STATIONS; ++l) { - for (int m = 0; m < NOF_LAYERS; ++m) { - bool pointsMatched = false; - - for (list<LxTbBinnedPoint::PointDesc>::const_iterator n = chain->points[l][m]->mcRefs.begin(); - n != chain->points[l][m]->mcRefs.end(); ++n) { - if (n->eventId == eventN && n->pointId == track.pointInds[l][m]) { - pointsMatched = true; - break; - } - } - - if (pointsMatched) ++nofMatchPoints; - } - } - } - - if (nofMatchPoints >= NOF_STATIONS * NOF_LAYERS * 0.7) { - ++nofRecoSignalTracks; - continue; - } - } - - ++eventN; - } - - double eff = 0 == nofSignalTracks ? 100 : 100.0 * nofRecoSignalTracks / nofSignalTracks; - cout << "Reconstruction efficiency is: " << eff << "% [ " << nofRecoSignalTracks << " / " << nofSignalTracks << " ]" - << endl; - - int nofRightRecoTracks = 0; - - for (list<Chain*>::const_iterator i = recoTracks.begin(); i != recoTracks.end(); ++i) { - const Chain* chain = *i; - map<RecoTrackData, int, RTDLess> nofTracks; - - for (int j = 0; j < NOF_STATIONS; ++j) { - for (int k = 0; k < NOF_LAYERS; ++k) { - int stMask = 1 << j * NOF_LAYERS + k; - - for (list<LxTbBinnedPoint::PointDesc>::const_iterator l = chain->points[j][k]->mcRefs.begin(); - l != chain->points[j][k]->mcRefs.end(); ++l) { - RecoTrackData st(l->eventId, l->trackId); - map<RecoTrackData, int, RTDLess>::iterator nofTIter = nofTracks.find(st); - - if (nofTIter != nofTracks.end()) nofTIter->second |= stMask; - else - nofTracks[st] = stMask; - } - } - } - - int nofPoints = 0; - - for (map<RecoTrackData, int, RTDLess>::const_iterator j = nofTracks.begin(); j != nofTracks.end(); ++j) { - int nofp = 0; - - for (int k = 0; k < NOF_STATIONS; ++k) { - for (int l = 0; l < NOF_LAYERS; ++l) { - if (j->second & (1 << k * NOF_LAYERS + l)) ++nofp; - } - } - - if (nofp > nofPoints) nofPoints = nofp; - } - - if (nofPoints >= NOF_STATIONS * NOF_LAYERS * 0.7) ++nofRightRecoTracks; - } - - eff = 0 == recoTracks.size() ? 100 : 100.0 * nofRightRecoTracks / nofRecoTracks; - cout << "Non ghosts are: " << eff << "% [ " << nofRightRecoTracks << " / " << nofRecoTracks << " ]" << endl; - - //cout << "Have: " << shortSignalMCTimes.size() << " short signaling events" << endl; - //cout << "Have: " << longSignalMCTimes.size() << " long signaling events" << endl; - cout << "Have: " << currentEventN << " events" << endl; - - ofstream nofEventsFile("nof_events.txt", ios_base::out | ios_base::trunc); - nofEventsFile << currentEventN; - - ofstream nofTriggeringsFile("nof_triggerings.txt", ios_base::out | ios_base::trunc); - nofTriggeringsFile << nofTriggerings; - - /*ofstream nofShortSignalsFile("nof_short_signals.txt", ios_base::out | ios_base::trunc); - nofShortSignalsFile << shortSignalMCTimes.size(); - - ofstream nofLongSignalsFile("nof_long_signals.txt", ios_base::out | ios_base::trunc); - nofLongSignalsFile << longSignalMCTimes.size(); - - PrintTrigger(triggerTimes_trd0_sign0_dist0, shortSignalMCTimes, "triggerTimes_trd0_sign0_dist0"); - PrintTrigger(triggerTimes_trd0_sign0_dist1, shortSignalMCTimes, "triggerTimes_trd0_sign0_dist1"); - PrintTrigger(triggerTimes_trd0_sign1_dist0, shortSignalMCTimes, "triggerTimes_trd0_sign1_dist0"); - PrintTrigger(triggerTimes_trd0_sign1_dist1, shortSignalMCTimes, "triggerTimes_trd0_sign1_dist1"); - PrintTrigger(triggerTimes_trd1_sign0_dist0, longSignalMCTimes, "triggerTimes_trd1_sign0_dist0"); - PrintTrigger(triggerTimes_trd1_sign0_dist1, longSignalMCTimes, "triggerTimes_trd1_sign0_dist1"); - PrintTrigger(triggerTimes_trd1_sign1_dist0, longSignalMCTimes, "triggerTimes_trd1_sign1_dist0"); - PrintTrigger(triggerTimes_trd1_sign1_dist1, longSignalMCTimes, "triggerTimes_trd1_sign1_dist1", true); - - Int_t nofTriggerDigis = 0; - - for (set<Int_t>::const_iterator i = fFinder->triggerEventNumber.begin(); i != fFinder->triggerEventNumber.end(); ++i) - nofTriggerDigis += nof_ev_digis[*i]; - - ofstream nofTriggerDigisFile("nof_trigger_digis.txt", ios_base::out | ios_base::trunc); - nofTriggerDigisFile << nofTriggerDigis; - ofstream nofDigisFile("nof_digis.txt", ios_base::out | ios_base::trunc); - nofDigisFile << nof_digis;*/ - -#ifdef LXTB_DEBUG - for (int i = 0; i < NOF_STATIONS; ++i) { - SaveHisto(deltaXRHisto[i]); - SaveHisto(deltaYRHisto[i]); - SaveHisto(deltaTRHisto[i]); - SaveHisto(deltaXLHisto[i]); - SaveHisto(deltaYLHisto[i]); - SaveHisto(deltaTLHisto[i]); - } -#endif //LXTB_DEBUG -#endif //LXTB_QA - - for (list<Chain*>::iterator i = recoTracks.begin(); i != recoTracks.end(); ++i) - delete *i; -} diff --git a/reco/tracking/lx/TBBinned/LxTBMLTask.h b/reco/tracking/lx/TBBinned/LxTBMLTask.h deleted file mode 100644 index c854109927944f97bdb9371463c6812a9a2f752b..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/TBBinned/LxTBMLTask.h +++ /dev/null @@ -1,109 +0,0 @@ -/* Copyright (C) 2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifndef LXTBMLTASK_H -#define LXTBMLTASK_H - -#include "CbmMCDataArray.h" - -#include "FairTask.h" - -#include "LxTBBinned2.h" - -class LxTBMLFinder : public FairTask { -public: - struct Chain { - LxTbBinnedPoint* points[NOF_STATIONS][NOF_LAYERS]; - scaltype chi2; - - Chain(LxTbBinnedPoint* pts[NOF_STATIONS][NOF_LAYERS], scaltype Chi2) : chi2(Chi2) - { - for (int i = 0; i < NOF_STATIONS; ++i) { - for (int j = 0; j < NOF_LAYERS; ++j) - points[i][j] = new LxTbBinnedPoint(*pts[i][j]); - } - } - - Chain(const Chain& origingal) : chi2(origingal.chi2) - { - for (int i = 0; i < NOF_STATIONS; ++i) { - for (int j = 0; j < NOF_LAYERS; ++j) - points[i][j] = new LxTbBinnedPoint(*origingal.points[i][j]); - } - } - - ~Chain() - { - for (int i = 0; i < NOF_STATIONS; ++i) { - for (int j = 0; j < NOF_LAYERS; ++j) - delete points[i][j]; - } - } - }; - -#ifdef LXTB_QA - struct PointDataHolder { - Double_t x; - Double_t y; - Double_t z; - Double_t t; - Int_t eventId; - Int_t trackId; - Int_t pointId; - Int_t stationNumber; - Int_t layerNumber; - }; - - struct TrackDataHolder { - Int_t pointInds[NOF_STATIONS][NOF_LAYERS]; - bool isSignal; - bool isPos; - - TrackDataHolder() : isSignal(false), isPos(false) - { - for (int i = 0; i < NOF_STATIONS; ++i) { - for (int j = 0; j < NOF_LAYERS; ++j) - pointInds[i][j] = -1; - } - } - }; -#endif //LXTB_QA - - LxTBMLFinder(); - InitStatus Init(); // Overridden from FairTask - void Exec(Option_t* opt); // Overridden from FairTask - void Finish(); // Overridden from FairTask - - void SetEvByEv(bool v) - { - fIsEvByEv = v; - fNofTBins = fIsEvByEv ? 5 : 1000; - } - - void SetNEvents(int v) { fNEvents = v; } - -private: - void* fReconstructor; - bool fIsEvByEv; - int fNofXBins; - int fNofYBins; - int fNofTBins; - - CbmMCDataArray* fMuchMCPoints; - TClonesArray* fMuchPixelHits; - TClonesArray* fMuchClusters; - TClonesArray* fMuchPixelDigiMatches; - std::list<Chain*> recoTracks; - -#ifdef LXTB_QA - std::vector<std::vector<PointDataHolder>> fMuchPoints; - std::vector<std::vector<TrackDataHolder>> fMCTracks; - std::vector<Double_t> fEventTimes; -#endif //LXTB_QA - int fNEvents; - - ClassDef(LxTBMLFinder, 1) -}; - -#endif /* LXTBMLTASK_H */ diff --git a/reco/tracking/lx/TBBinned/LxTBMatEffs.h b/reco/tracking/lx/TBBinned/LxTBMatEffs.h deleted file mode 100644 index 973b62a85e51b3893e7762f42b15dab87053ede3..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/TBBinned/LxTBMatEffs.h +++ /dev/null @@ -1,132 +0,0 @@ -/* Copyright (C) 2016 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov, Florian Uhlig [committer] */ - -#ifndef LXTBMATEFFS_H -#define LXTBMATEFFS_H - -#include <cmath> - -static scaltype gMuonMass = 0; -static scaltype gElectronMass = 0; - -struct LxTbAbsorber { - scaltype zCoord; // Z-coordinate of the absorber beginning. - scaltype width; - scaltype radLength; // Radiation length - scaltype rho; // Density - scaltype Z; // Atomic number - scaltype A; // Atomic weight - - //LxTbAbsorber(scaltype w, scaltype rl, scaltype d, scaltype z, scaltype a) : width(w), radLength(rl), rho(d), Z(z), A(a) {} -}; - -static inline scaltype CalcI(scaltype Z) -{ - // mean excitation energy in eV - if (Z > 16.) { return 10 * Z; } - else { - return 16 * std::pow(Z, 0.9); - } -} - -static inline scaltype BetheBloch(scaltype E, const LxTbAbsorber* mat) -{ - scaltype K = 0.000307075; // GeV * g^-1 * cm^2 - scaltype z = 1.; //(par->GetQp() > 0.) ? 1 : -1.; - scaltype Z = mat->Z; - scaltype A = mat->A; - - scaltype M = gMuonMass; - //scaltype p = std::abs(1. / par->GetQp()); //GeV - //scaltype E = std::sqrt(M * M + p * p); - - scaltype p = std::sqrt(E * E - M * M); //GeV - scaltype beta = p / E; - scaltype betaSq = beta * beta; - scaltype gamma = E / M; - scaltype gammaSq = gamma * gamma; - - scaltype I = CalcI(Z) * 1e-9; // GeV - - scaltype me = gElectronMass; // GeV - scaltype ratio = me / M; - scaltype Tmax = (2 * me * betaSq * gammaSq) / (1 + 2 * gamma * ratio + ratio * ratio); - - // density correction - scaltype dc = 0.; - if (p > 0.5) { // for particles above 1 Gev - scaltype rho = mat->rho; - scaltype hwp = 28.816 * std::sqrt(rho * Z / A) * 1e-9; // GeV - dc = std::log(hwp / I) + std::log(beta * gamma) - 0.5; - } - - return K * z * z * (Z / A) * (1. / betaSq) - * (0.5 * std::log(2 * me * betaSq * gammaSq * Tmax / (I * I)) - betaSq - dc); -} - -static inline scaltype EnergyLoss(scaltype E, scaltype L, const LxTbAbsorber* mat) -{ - return BetheBloch(E, mat) * mat->rho * L; - - /*scaltype result = 0; - - if (L < 10) - { - result = BetheBloch(E, mat) * mat->rho * L; - - if (result <= 0) - return 0; - - if (result > E - gMuonMass) - result = E - gMuonMass; - - return result; - } - - scaltype delta = 10; - - for (scaltype l = 10; l <= L;) - { - scaltype r = BetheBloch(E, mat) * mat->rho * delta; - - if (r <= 0) - return result; - - if (r > E - gMuonMass) - r = E - gMuonMass; - - result += r; - E -= r; - delta = L - l; - - if (delta < 0.5) - break; - else if (delta < 10) - l = L; - else - l += 10; - } - - return result;*/ -} - -static inline scaltype CalcThetaPrj(scaltype E, scaltype x, const LxTbAbsorber* mat) -{ - //scaltype p = std::abs(1. / par->GetQp()); //GeV - scaltype muMass = gMuonMass; - //scaltype E = std::sqrt(muMass * muMass + p * p); - //scaltype p = std::abs(1. / par->GetQp()); //GeV - scaltype p = std::sqrt(E * E - muMass * muMass); //GeV - scaltype beta = p / E; - //scaltype x = mat->GetLength(); //cm - scaltype X0 = mat->radLength; //cm - scaltype bcp = beta * p; - scaltype z = 1.; - - scaltype theta = 0.0136 * (1. / bcp) * z * std::sqrt(x / X0) * (1. + 0.038 * std::log(x / X0)); - return theta / std::sqrt(2.0); - //return theta * theta; -} - -#endif /* LXTBMATEFFS_H */ diff --git a/reco/tracking/lx/TBBinned/LxTBTask.cxx b/reco/tracking/lx/TBBinned/LxTBTask.cxx deleted file mode 100644 index 03aced559ed9d4cd40998026b4ee724dc117bf7e..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/TBBinned/LxTBTask.cxx +++ /dev/null @@ -1,1622 +0,0 @@ -/* Copyright (C) 2017-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt - SPDX-License-Identifier: GPL-3.0-only - Authors: Florian Uhlig [committer] */ - -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -#include "LxTBTask.h" - -#include "CbmCluster.h" -#include "CbmMCDataManager.h" -#include "CbmMCTrack.h" -#include "CbmMatch.h" -#include "CbmMuchGeoScheme.h" -#include "CbmMuchPixelHit.h" -#include "CbmTrdHit.h" - -#include <FairRootManager.h> -#include <Logger.h> - -#include "TClonesArray.h" -#include "TDatabasePDG.h" -#include "TGeoArb8.h" -#include "TGeoBoolNode.h" -#include "TGeoCompositeShape.h" -#include "TMath.h" -#include "TParticlePDG.h" -#include "TRandom3.h" - -#include <map> -#include <set> - -#include "LxTBTieTracks.h" - -#ifdef LXTB_QA -#include "CbmStsHit.h" - -#include "TH1F.h" -#include "TH2F.h" -#endif //LXTB_QA - -#include <TFile.h> - -using std::cout; -using std::endl; -using std::ifstream; -using std::ios_base; -using std::list; -using std::map; -using std::ofstream; -using std::pair; -using std::set; -using std::vector; - -ClassImp(LxTBFinder) - - Double_t speedOfLight = 0; - -LxTbBinnedFinder::SignalParticle LxTbBinnedFinder::particleDescs[] = {{"jpsi", 443, 3.0, true}, - {"omega", 223, 1.5, true}, - {"", -1, 0, false}}; - -LxTBFinder::LxTBFinder() - : fMuchPoints() - , fMuchMCPoints(nullptr) - , fMuchPixelHits(nullptr) - , fMuchClusters(nullptr) - , fMuchPixelDigiMatches(nullptr) - , fTrdPoints() - , fTrdMCPoints(nullptr) - , fTrdHits(nullptr) - , fTrdClusters(nullptr) - , fTrdDigiMatches(nullptr) - , -#ifdef LXTB_QA - fMvdDigis(nullptr) - , fStsDigis(nullptr) - , fTofDigis(nullptr) - , fMCTracks() - , -#endif //LXTB_QA - isEvByEv(false) - , fFinder(nullptr) - , recoTracks() - , hasTrd(false) - , useTrd(true) - , useIdeal(false) - , useAsciiSig(false) - , fSignalParticle("jpsi") - , -#ifdef LXTB_EMU_TS - nof_timebins(1000) - , -#else //LXTB_EMU_TS - nof_timebins(isEvByEv ? 5 : 1000) - , -#endif //LXTB_EMU_TS - last_timebin(nof_timebins - 1) - , fNEvents(1000) - , fEventTimes() - , -#ifdef LXTB_TIE - fStsHits(nullptr) - , fStsTracks(nullptr) - , fStsClusters(nullptr) - , fStsDigiMatches(nullptr) - , fDetector(nullptr) - , -#endif //LXTB_TIE - dummy(0) -{ -} - -static bool HasTrd() -{ - gGeoManager->cd("/cave_1"); - TObjArray* children = gGeoManager->GetCurrentNode()->GetNodes(); - - if (0 != children) { - TObject* child = children->First(); - - while (child) { - TString name(static_cast<TGeoNode*>(child)->GetName()); - - if (name.Contains("trd", TString::kIgnoreCase)) return true; - - child = children->After(child); - } - } - - return false; -} - -static void FindGeoChild(TGeoNode* node, const char* name, list<TGeoNode*>& results) -{ - Int_t nofChildren = node->GetNdaughters(); - - for (Int_t i = 0; i < nofChildren; ++i) { - TGeoNode* child = node->GetDaughter(i); - TString childName(child->GetName()); - - if (childName.Contains(name, TString::kIgnoreCase)) results.push_back(child); - } -} - -void LxTBFinder::HandleGeometry() -{ - Double_t localCoords[3] = {0., 0., 0.}; - Double_t globalCoords[3]; - TGeoNavigator* pNavigator = gGeoManager->GetCurrentNavigator(); - gGeoManager->cd("/cave_1"); - list<TGeoNode*> detectors; - FindGeoChild(gGeoManager->GetCurrentNode(), "much", detectors); - - for (list<TGeoNode*>::iterator i = detectors.begin(); i != detectors.end(); ++i) { - TGeoNode* detector = *i; - pNavigator->CdDown(detector); - list<TGeoNode*> stations; - FindGeoChild(detector, "station", stations); - int stationNumber = 0; - - for (list<TGeoNode*>::iterator j = stations.begin(); j != stations.end(); ++j) { - TGeoNode* station = *j; - pNavigator->CdDown(station); - list<TGeoNode*> layers; - FindGeoChild(station, "layer", layers); - int layerNumber = 0; - - for (list<TGeoNode*>::iterator k = layers.begin(); k != layers.end(); ++k) { - TGeoNode* layer = *k; - pNavigator->CdDown(layer); - gGeoManager->LocalToMaster(localCoords, globalCoords); - - if (1 == layerNumber) { - fFinder->stations[stationNumber].stationNumber = stationNumber; - fFinder->stations[stationNumber].z = globalCoords[2]; - fFinder->stations[stationNumber].minX = 0; - fFinder->stations[stationNumber].maxX = 0; - fFinder->stations[stationNumber].binSizeX = 0; - fFinder->stations[stationNumber].minY = 0; - fFinder->stations[stationNumber].maxY = 0; - fFinder->stations[stationNumber].binSizeY = 0; - } - -#ifdef LXTB_TIE - fDetector->fLayers[stationNumber * 3 + layerNumber].z = globalCoords[2]; - fDetector->fLayers[stationNumber * 3 + layerNumber].minX = 0; - fDetector->fLayers[stationNumber * 3 + layerNumber].maxX = 0; - fDetector->fLayers[stationNumber * 3 + layerNumber].binSizeX = 0; - fDetector->fLayers[stationNumber * 3 + layerNumber].minY = 0; - fDetector->fLayers[stationNumber * 3 + layerNumber].maxY = 0; - fDetector->fLayers[stationNumber * 3 + layerNumber].binSizeY = 0; -#endif //LXTB_TIE - - list<TGeoNode*> actives; - FindGeoChild(layer, "active", actives); - - for (list<TGeoNode*>::iterator l = actives.begin(); l != actives.end(); ++l) { - TGeoNode* active = *l; - pNavigator->CdDown(active); - TGeoCompositeShape* cs = dynamic_cast<TGeoCompositeShape*>(active->GetVolume()->GetShape()); - TGeoBoolNode* bn = cs->GetBoolNode(); - TGeoTrap* trap = dynamic_cast<TGeoTrap*>(bn->GetLeftShape()); - - if (0 != trap) { - Double_t* xy = trap->GetVertices(); - - for (int m = 0; m < 4; ++m) { - Double_t localActiveCoords[3] = {xy[2 * m], xy[2 * m + 1], 0.}; - Double_t globalActiveCoords[3]; - gGeoManager->LocalToMaster(localActiveCoords, globalActiveCoords); - -#ifdef LXTB_TIE - if (fDetector->fLayers[stationNumber * 3 + layerNumber].minY > globalActiveCoords[1]) - fDetector->fLayers[stationNumber * 3 + layerNumber].minY = globalActiveCoords[1]; - - if (fDetector->fLayers[stationNumber * 3 + layerNumber].maxY < globalActiveCoords[1]) - fDetector->fLayers[stationNumber * 3 + layerNumber].maxY = globalActiveCoords[1]; - - if (fDetector->fLayers[stationNumber * 3 + layerNumber].minX > globalActiveCoords[0]) - fDetector->fLayers[stationNumber * 3 + layerNumber].minX = globalActiveCoords[0]; - - if (fDetector->fLayers[stationNumber * 3 + layerNumber].maxX < globalActiveCoords[0]) - fDetector->fLayers[stationNumber * 3 + layerNumber].maxX = globalActiveCoords[0]; -#endif //LXTB_TIE - - if (1 == layerNumber) { - if (fFinder->stations[stationNumber].minY > globalActiveCoords[1]) - fFinder->stations[stationNumber].minY = globalActiveCoords[1]; - - if (fFinder->stations[stationNumber].maxY < globalActiveCoords[1]) - fFinder->stations[stationNumber].maxY = globalActiveCoords[1]; - - if (fFinder->stations[stationNumber].minX > globalActiveCoords[0]) - fFinder->stations[stationNumber].minX = globalActiveCoords[0]; - - if (fFinder->stations[stationNumber].maxX < globalActiveCoords[0]) - fFinder->stations[stationNumber].maxX = globalActiveCoords[0]; - } - } - } - - pNavigator->CdUp(); - } - - pNavigator->CdUp(); - ++layerNumber; - } - - ++stationNumber; - pNavigator->CdUp(); - } - - int nofStations = stationNumber; - - list<TGeoNode*> absorbers; - FindGeoChild(detector, "absorber", absorbers); - int absorberNumber = 0; - - for (list<TGeoNode*>::iterator j = absorbers.begin(); j != absorbers.end(); ++j) { - TGeoNode* absorber = *j; - pNavigator->CdDown(absorber); - TGeoVolume* absVol = gGeoManager->GetCurrentVolume(); - const TGeoBBox* absShape = static_cast<const TGeoBBox*>(absVol->GetShape()); - - if (absorberNumber < nofStations) { - gGeoManager->LocalToMaster(localCoords, globalCoords); - fFinder->stations[absorberNumber].absorber.zCoord = globalCoords[2] - absShape->GetDZ(); - fFinder->stations[absorberNumber].absorber.width = 2 * absShape->GetDZ(); - fFinder->stations[absorberNumber].absorber.radLength = absVol->GetMaterial()->GetRadLen(); - fFinder->stations[absorberNumber].absorber.rho = absVol->GetMaterial()->GetDensity(); - fFinder->stations[absorberNumber].absorber.Z = absVol->GetMaterial()->GetZ(); - fFinder->stations[absorberNumber].absorber.A = absVol->GetMaterial()->GetA(); - } - else { - fFinder->trdStation.absorber.width = 2 * absShape->GetDZ(); - fFinder->trdStation.absorber.radLength = absVol->GetMaterial()->GetRadLen(); - fFinder->trdStation.absorber.rho = absVol->GetMaterial()->GetDensity(); - fFinder->trdStation.absorber.Z = absVol->GetMaterial()->GetZ(); - fFinder->trdStation.absorber.A = absVol->GetMaterial()->GetA(); - } - - ++absorberNumber; - pNavigator->CdUp(); - } - - pNavigator->CdUp(); - } - - fFinder->trdStation.minX = 0; - fFinder->trdStation.maxX = 0; - fFinder->trdStation.binSizeX = 0; - fFinder->trdStation.minY = 0; - fFinder->trdStation.maxY = 0; - fFinder->trdStation.binSizeY = 0; - detectors.clear(); - FindGeoChild(gGeoManager->GetCurrentNode(), "trd", detectors); - - for (list<TGeoNode*>::iterator i = detectors.begin(); i != detectors.end(); ++i) { - TGeoNode* detector = *i; - pNavigator->CdDown(detector); - list<TGeoNode*> layers; - FindGeoChild(detector, "layer", layers); - int layerNumber = 0; - - for (list<TGeoNode*>::iterator j = layers.begin(); j != layers.end(); ++j) { - TGeoNode* layer = *j; - pNavigator->CdDown(layer); - list<TGeoNode*> modules; - FindGeoChild(layer, "module", modules); - - for (list<TGeoNode*>::iterator k = modules.begin(); k != modules.end(); ++k) { - TGeoNode* module = *k; - pNavigator->CdDown(module); - list<TGeoNode*> padCoppers; - FindGeoChild(module, "padcopper", padCoppers); - - for (list<TGeoNode*>::iterator l = padCoppers.begin(); l != padCoppers.end(); ++l) { - TGeoNode* padCopper = *l; - pNavigator->CdDown(padCopper); - TGeoBBox* pBox = static_cast<TGeoBBox*>(padCopper->GetVolume()->GetShape()); - pBox->ComputeBBox(); - gGeoManager->LocalToMaster(localCoords, globalCoords); - fFinder->trdStation.Zs[layerNumber] = globalCoords[2]; - -#ifdef LXTB_TIE - fDetector->fLayers[CUR_NOF_STATIONS * 3 + layerNumber].z = globalCoords[2]; -#endif //LXTB_TIE - - if (fFinder->trdStation.minY > globalCoords[1] - pBox->GetDY()) - fFinder->trdStation.minY = globalCoords[1] - pBox->GetDY(); - - if (fFinder->trdStation.maxY < globalCoords[1] + pBox->GetDY()) - fFinder->trdStation.maxY = globalCoords[1] + pBox->GetDY(); - - if (fFinder->trdStation.minX > globalCoords[0] - pBox->GetDX()) - fFinder->trdStation.minX = globalCoords[0] - pBox->GetDX(); - - if (fFinder->trdStation.maxX < globalCoords[0] + pBox->GetDX()) - fFinder->trdStation.maxX = globalCoords[0] + pBox->GetDX(); - - pNavigator->CdUp(); - } - - pNavigator->CdUp(); - } - - ++layerNumber; - pNavigator->CdUp(); - } - - pNavigator->CdUp(); - } - -#ifdef LXTB_TIE - for (int i = 0; i < CUR_NOF_TRD_LAYERS; ++i) { - fDetector->fLayers[CUR_NOF_STATIONS * 3 + i].minX = fFinder->trdStation.minX; - fDetector->fLayers[CUR_NOF_STATIONS * 3 + i].maxX = fFinder->trdStation.maxX; - fDetector->fLayers[CUR_NOF_STATIONS * 3 + i].binSizeX = 0; - fDetector->fLayers[CUR_NOF_STATIONS * 3 + i].minY = fFinder->trdStation.minY; - fDetector->fLayers[CUR_NOF_STATIONS * 3 + i].maxY = fFinder->trdStation.maxY; - fDetector->fLayers[CUR_NOF_STATIONS * 3 + i].binSizeY = 0; - } -#endif //LXTB_TIE -} - -#ifdef LXTB_QA -static list<timetype> shortSignalMCTimes; -static list<timetype> longSignalMCTimes; -static list<timetype> middleSignalMCTimes; -static list<pair<timetype, timetype>> triggerTimes_trd0_sign0_dist0; -static list<pair<timetype, timetype>> triggerTimes_trd0_sign0_dist1; -static list<pair<timetype, timetype>> triggerTimes_trd0_sign1_dist0; -static list<pair<timetype, timetype>> triggerTimes_trd0_sign1_dist1; -static list<pair<timetype, timetype>> triggerTimes_trd1_sign0_dist0; -static list<pair<timetype, timetype>> triggerTimes_trd1_sign0_dist1; -static list<pair<timetype, timetype>> triggerTimes_trd1_sign1_dist0; -static list<pair<timetype, timetype>> triggerTimes_trd1_sign1_dist1; -static list<pair<timetype, timetype>> triggerTimes_trd05_sign0_dist0; -static list<pair<timetype, timetype>> triggerTimes_trd05_sign0_dist1; -static list<pair<timetype, timetype>> triggerTimes_trd05_sign1_dist0; -static list<pair<timetype, timetype>> triggerTimes_trd05_sign1_dist1; -#endif //LXTB_QA - -InitStatus LxTBFinder::Init() -{ - FairRootManager* ioman = FairRootManager::Instance(); - - if (0 == ioman) LOG(fatal) << "No FairRootManager"; - - Int_t nofEventsInFile = ioman->CheckMaxEventNo(); - - if (nofEventsInFile < fNEvents) fNEvents = nofEventsInFile; - - speedOfLight = 100 * TMath::C(); // Multiply by 100 to express in centimeters. - gMuonMass = TDatabasePDG::Instance()->GetParticle(13)->Mass(); - gElectronMass = TDatabasePDG::Instance()->GetParticle(11)->Mass(); - - //TObjArray* absorbers = CbmMuchGeoScheme::Instance()->GetAbsorbers(); (VF) unused - - hasTrd = useTrd ? HasTrd() : false; - pair<int, int> stSpatLimits[] = {{20, 20}, {20, 20}, {20, 20}, {20, 20}, {20, 20}, {20, 20}}; - fFinder = new LxTbBinnedFinder(hasTrd ? CUR_NOF_TRD_LAYERS : 0, CUR_NOF_STATIONS, nof_timebins, stSpatLimits, 20, 20, - CUR_TIMEBIN_LENGTH); - fFinder->SetSignalParticle(fSignalParticle); - hasTrd = fFinder->fSignalParticle->fHasTrd; - -#ifdef LXTB_TIE - int nofLayers = CUR_NOF_STATIONS * 3; - - if (hasTrd) nofLayers += CUR_NOF_TRD_LAYERS; - - fDetector = new LxTBBinnedDetector(nofLayers, 20, 20, nof_timebins, CUR_TIMEBIN_LENGTH); - - fStsHits = static_cast<TClonesArray*>(ioman->GetObject("StsHit")); - fStsTracks = static_cast<TClonesArray*>(ioman->GetObject("StsTrack")); - fStsClusters = static_cast<TClonesArray*>(ioman->GetObject("StsCluster")); - fStsDigiMatches = static_cast<TClonesArray*>(ioman->GetObject("StsDigiMatch")); - - fDetector->fMuchTracks = new TClonesArray("CbmMuchTrack", 100); - ioman->Register("MuchTrack", "Much", fDetector->fMuchTracks, IsOutputBranchPersistent("MuchTrack")); - fDetector->fGlobalTracks = new TClonesArray("CbmGlobalTrack", 100); - ioman->Register("GlobalTrack", "Global", fDetector->fGlobalTracks, IsOutputBranchPersistent("GlobalTrack")); -#endif //LXTB_TIE - - HandleGeometry(); - fFinder->Init(); - -#ifdef LXTB_TIE - fDetector->Init(); -#endif //LXTB_TIE - - fMuchPixelHits = static_cast<TClonesArray*>(ioman->GetObject("MuchPixelHit")); - fTrdHits = static_cast<TClonesArray*>(ioman->GetObject("TrdHit")); - -#ifdef LXTB_QA - CbmMCDataManager* mcManager = static_cast<CbmMCDataManager*>(ioman->GetObject("MCDataManager")); - fMuchMCPoints = mcManager->InitBranch("MuchPoint"); - fMuchClusters = static_cast<TClonesArray*>(ioman->GetObject("MuchCluster")); - fMuchPixelDigiMatches = static_cast<TClonesArray*>(ioman->GetObject("MuchDigiMatch")); - fTrdMCPoints = mcManager->InitBranch("TrdPoint"); - fTrdClusters = static_cast<TClonesArray*>(ioman->GetObject("TrdCluster")); - fTrdDigiMatches = static_cast<TClonesArray*>(ioman->GetObject("TrdDigiMatch")); - fMvdDigis = static_cast<TClonesArray*>(ioman->GetObject("MvdDigi")); - fStsDigis = static_cast<TClonesArray*>(ioman->GetObject("StsDigi")); - fTofDigis = static_cast<TClonesArray*>(ioman->GetObject("TofDigi")); - CbmMCDataArray* mcTracks = mcManager->InitBranch("MCTrack"); - - TH1F* jpsiPHisto = new TH1F("jpsiPHisto", "jpsiPHisto", 90, 0., 30.); - TH1F* jpsiMHisto = new TH1F("jpsiMHisto", "jpsiMHisto", 200, 3., 3.2); - TH1F* jpsiEHisto = new TH1F("jpsiEHisto", "jpsiEHisto", 90, 0., 30.); - TH1F* signalMHisto = new TH1F("signalMHisto", "signalMHisto", 600, 0., 6.0); - - for (int i = 0; i < fNEvents; ++i) { - Int_t evSize = mcTracks->Size(0, i); - fMCTracks.push_back(vector<TrackDataHolder>()); - - if (0 >= evSize) continue; - - vector<TrackDataHolder>& evTracks = fMCTracks.back(); - const CbmMCTrack* posTrack = 0; - const CbmMCTrack* negTrack = 0; - - for (int j = 0; j < evSize; ++j) { - evTracks.push_back(TrackDataHolder()); - const CbmMCTrack* mcTrack = static_cast<const CbmMCTrack*>(mcTracks->Get(0, i, j)); - - if (mcTrack->GetPdgCode() == 443) { - Double_t p = mcTrack->GetP(); - jpsiPHisto->Fill(p); - Double_t m = mcTrack->GetMass(); - jpsiMHisto->Fill(m); - Double_t e = mcTrack->GetEnergy(); - jpsiEHisto->Fill(e); - } - - if (mcTrack->GetPdgCode() == 13 || mcTrack->GetPdgCode() == -13) { - //Double_t m = mcTrack->GetMass(); - Int_t motherId = mcTrack->GetMotherId(); - - if ((useAsciiSig && motherId < 0) - || (motherId >= 0 - && static_cast<const CbmMCTrack*>(mcTracks->Get(0, i, motherId))->GetPdgCode() - == fFinder->fSignalParticle->fPdgCode)) { - //const CbmMCTrack* motherTrack = static_cast<const CbmMCTrack*> (mcTracks->Get(0, i, motherId)); - - //if (fFinder->fSignalParticle->fPdgCode == motherTrack->GetPdgCode()) - { - evTracks.back().isSignalShort = true; - evTracks.back().isSignalLong = true; - evTracks.back().isPos = mcTrack->GetPdgCode() == -13; - - if (-13 == mcTrack->GetPdgCode()) posTrack = mcTrack; - else - negTrack = mcTrack; - } - } - } - } // for (int j = 0; j < evSize; ++j) - - if (0 != posTrack && 0 != negTrack) { - Double_t E12 = posTrack->GetEnergy() + negTrack->GetEnergy(); - Double_t E12Sq = E12 * E12; - Double_t P12Sq = (posTrack->GetPx() + negTrack->GetPx()) * (posTrack->GetPx() + negTrack->GetPx()) - + (posTrack->GetPy() + negTrack->GetPy()) * (posTrack->GetPy() + negTrack->GetPy()) - + (posTrack->GetPz() + negTrack->GetPz()) * (posTrack->GetPz() + negTrack->GetPz()); - Double_t m = sqrt(E12Sq - P12Sq); - signalMHisto->Fill(m); - } - } // for (int i = 0; i < fNEvents; ++i) - - { - TFile* curFile = TFile::CurrentFile(); - TString histoName = "jpsiMHisto.root"; - - TFile fh(histoName.Data(), "RECREATE"); - jpsiMHisto->Write(); - fh.Close(); - delete jpsiMHisto; - - TFile::CurrentFile() = curFile; - } - - { - TFile* curFile = TFile::CurrentFile(); - TString histoName = "jpsiPHisto.root"; - - TFile fh(histoName.Data(), "RECREATE"); - jpsiPHisto->Write(); - fh.Close(); - delete jpsiPHisto; - - TFile::CurrentFile() = curFile; - } - - { - TFile* curFile = TFile::CurrentFile(); - TString histoName = "jpsiEHisto.root"; - - TFile fh(histoName.Data(), "RECREATE"); - jpsiEHisto->Write(); - fh.Close(); - delete jpsiEHisto; - - TFile::CurrentFile() = curFile; - } - - { - TFile* curFile = TFile::CurrentFile(); - TString histoName = "signalMHisto.root"; - - TFile fh(histoName.Data(), "RECREATE"); - signalMHisto->Write(); - fh.Close(); - delete signalMHisto; - - TFile::CurrentFile() = curFile; - } - - TH2F* trdHisto = new TH2F("TRD", "TRD", 500, -50., 1000., 500, 0., 600.); - TH2F* trdHistoXY = new TH2F("TRD_XY", "TRD_XY", 400, -400., 400., 300, -300., 300.); - - //Int_t numEvents = 0; - //Int_t numPoints[] = { 0, 0, 0, 0, 0, 0 }; (VF) unused - fEventTimes.resize(fNEvents); - -#ifdef LXTB_EMU_TS - fEventTimes[0] = 0; - - for (int i = 1; i < fNEvents; ++i) - fEventTimes[i] = fEventTimes[i - 1] + gRandom->Exp(CUR_TIMEBIN_LENGTH); -#else - fEventTimes[0] = 50; - - for (int i = 1; i < fNEvents; ++i) - fEventTimes[i] = fEventTimes[i - 1] + 100; -#endif //LXTB_EMU_TS - - for (int i = 0; i < fNEvents; ++i) { - Int_t evSize = fMuchMCPoints->Size(0, i); - fMuchPoints.push_back(vector<PointDataHolder>()); - - if (0 >= evSize) continue; - - //++numEvents; - vector<PointDataHolder>& evPoints = fMuchPoints.back(); - - for (int j = 0; j < evSize; ++j) { - const CbmMuchPoint* pMuchPt = static_cast<const CbmMuchPoint*>(fMuchMCPoints->Get(0, i, j)); - - Int_t layerNumber = CbmMuchGeoScheme::GetLayerIndex(pMuchPt->GetDetectorId()); - - //if (1 == layerNumber) - { - PointDataHolder muchPt; - muchPt.x = (pMuchPt->GetXIn() + pMuchPt->GetXOut()) / 2; - muchPt.y = (pMuchPt->GetYIn() + pMuchPt->GetYOut()) / 2; - muchPt.t = fEventTimes[i] + pMuchPt->GetTime(); - muchPt.eventId = i; - muchPt.trackId = pMuchPt->GetTrackID(); - muchPt.pointId = j; - muchPt.stationNumber = CbmMuchGeoScheme::GetStationIndex(pMuchPt->GetDetectorId()); - muchPt.layerNumber = layerNumber; - evPoints.push_back(muchPt); - } - } - } - - if (hasTrd) { - for (int i = 0; i < fNEvents; ++i) { - Int_t evSize = fTrdMCPoints->Size(0, i); - fTrdPoints.push_back(vector<PointDataHolder>()); - - if (0 >= evSize) continue; - - set<Int_t> trdTracks; - vector<PointDataHolder>& evPoints = fTrdPoints.back(); - - for (int j = 0; j < evSize; ++j) { - const CbmTrdPoint* pTrdPt = static_cast<const CbmTrdPoint*>(fTrdMCPoints->Get(0, i, j)); - Int_t trackId = pTrdPt->GetTrackID(); - trdTracks.insert(trackId); - - Int_t layerNumber = CbmTrdAddress::GetLayerId(pTrdPt->GetModuleAddress()); - - //if (0 != layerNumber) - //continue; - - PointDataHolder trdPt; - trdPt.x = (pTrdPt->GetXIn() + pTrdPt->GetXOut()) / 2; - trdPt.y = (pTrdPt->GetYIn() + pTrdPt->GetYOut()) / 2; - trdPt.z = (pTrdPt->GetZIn() + pTrdPt->GetZOut()) / 2; - trdPt.t = fEventTimes[i] + pTrdPt->GetTime(); - trdPt.eventId = i; - trdPt.trackId = pTrdPt->GetTrackID(); - trdPt.pointId = j; - trdPt.stationNumber = layerNumber; - evPoints.push_back(trdPt); - - trdHistoXY->Fill(trdPt.x, trdPt.y); - } - - for (set<Int_t>::const_iterator j = trdTracks.begin(); j != trdTracks.end(); ++j) { - Int_t trackId = *j; - const CbmMCTrack* mcTrack = static_cast<const CbmMCTrack*>(mcTracks->Get(0, i, trackId)); - Double_t startZ = mcTrack->GetStartZ(); - Double_t startR = - sqrt(mcTrack->GetStartX() * mcTrack->GetStartX() + mcTrack->GetStartY() * mcTrack->GetStartY()); - trdHisto->Fill(startZ, startR); - } - } - } - - for (vector<vector<PointDataHolder>>::iterator i = fMuchPoints.begin(); i != fMuchPoints.end(); ++i) { - vector<PointDataHolder>& evPoints = *i; - - for (vector<PointDataHolder>::iterator j = evPoints.begin(); j != evPoints.end(); ++j) { - PointDataHolder& pt = *j; - - if (1 == pt.layerNumber) fMCTracks[pt.eventId][pt.trackId].pointInds[pt.stationNumber] = pt.pointId; - } - } - - if (hasTrd) { - for (vector<vector<PointDataHolder>>::iterator i = fTrdPoints.begin(); i != fTrdPoints.end(); ++i) { - vector<PointDataHolder>& evPoints = *i; - - for (vector<PointDataHolder>::iterator j = evPoints.begin(); j != evPoints.end(); ++j) { - PointDataHolder& pt = *j; - fMCTracks[pt.eventId][pt.trackId].trdPointInds[pt.stationNumber] = pt.pointId; - } - } - } - - TH1F* trd2XHisto = new TH1F("trd2XHisto", "trd2XHisto", 100, -2.5, 2.5); - TH1F* trd2YHisto = new TH1F("trd2YHisto", "trd2YHisto", 100, -2.5, 2.5); - TH1F* trd3XHisto = new TH1F("trd3XHisto", "trd3XHisto", 100, -2.5, 2.5); - TH1F* trd3YHisto = new TH1F("trd3YHisto", "trd3YHisto", 100, -2.5, 2.5); - int eventId = 0; - - for (vector<vector<TrackDataHolder>>::iterator i = fMCTracks.begin(); i != fMCTracks.end(); ++i) { - vector<TrackDataHolder>& evTracks = *i; - - for (vector<TrackDataHolder>::iterator j = evTracks.begin(); j != evTracks.end(); ++j) { - TrackDataHolder& track = *j; - - if (!track.isSignalShort) continue; - - for (int k = 0; k < CUR_NOF_STATIONS; ++k) { - if (track.pointInds[k] < 0) { - track.isSignalShort = false; - track.isSignalLong = false; - break; - } - } - - if (hasTrd) { - for (int k = 0; k < CUR_NOF_TRD_LAYERS; ++k) { - if (track.trdPointInds[k] < 0) { - track.isSignalLong = false; - break; - } - } - - if (!track.isSignalLong) continue; - - PointDataHolder& trdPt0 = fTrdPoints[eventId][track.trdPointInds[0]]; - PointDataHolder& trdPt1 = fTrdPoints[eventId][track.trdPointInds[1]]; - PointDataHolder& trdPt2 = fTrdPoints[eventId][track.trdPointInds[2]]; - PointDataHolder& trdPt3 = fTrdPoints[eventId][track.trdPointInds[3]]; - - Double_t tx = (trdPt1.x - trdPt0.x) / (trdPt1.z - trdPt0.z); - Double_t ty = (trdPt1.y - trdPt0.y) / (trdPt1.z - trdPt0.z); - Double_t p2X = trdPt1.x + tx * (trdPt2.z - trdPt1.z); - trd2XHisto->Fill(p2X - trdPt2.x); - Double_t p2Y = trdPt1.y + ty * (trdPt2.z - trdPt1.z); - trd2YHisto->Fill(p2Y - trdPt2.y); - Double_t p3X = trdPt1.x + tx * (trdPt3.z - trdPt1.z); - trd3XHisto->Fill(p3X - trdPt3.x); - Double_t p3Y = trdPt1.y + ty * (trdPt3.z - trdPt1.z); - trd3YHisto->Fill(p3Y - trdPt3.y); - } - } - - ++eventId; - } - - if (hasTrd) { - { - TFile* curFile = TFile::CurrentFile(); - TString histoName = "trd2XHisto.root"; - - TFile fh(histoName.Data(), "RECREATE"); - trd2XHisto->Write(); - fh.Close(); - delete trd2XHisto; - - TFile::CurrentFile() = curFile; - } - - { - TFile* curFile = TFile::CurrentFile(); - TString histoName = "trd2YHisto.root"; - - TFile fh(histoName.Data(), "RECREATE"); - trd2YHisto->Write(); - fh.Close(); - delete trd2YHisto; - - TFile::CurrentFile() = curFile; - } - - { - TFile* curFile = TFile::CurrentFile(); - TString histoName = "trd3XHisto.root"; - - TFile fh(histoName.Data(), "RECREATE"); - trd3XHisto->Write(); - fh.Close(); - delete trd3XHisto; - - TFile::CurrentFile() = curFile; - } - - { - TFile* curFile = TFile::CurrentFile(); - TString histoName = "trd3YHisto.root"; - - TFile fh(histoName.Data(), "RECREATE"); - trd3YHisto->Write(); - fh.Close(); - delete trd3YHisto; - - TFile::CurrentFile() = curFile; - } - } - - int evNum = 0; - TH1F* signalDistHisto = new TH1F("signalDistHisto", "signalDistHisto", 200, 0., 200.); - - for (vector<vector<TrackDataHolder>>::iterator i = fMCTracks.begin(); i != fMCTracks.end(); ++i) { - vector<TrackDataHolder>& evTracks = *i; - bool hasShortPos = false; - bool hasShortNeg = false; - bool hasLongPos = false; - bool hasLongNeg = false; - timetype posTime = 0; - timetype negTime = 0; - Double_t posX = 0; - Double_t posY = 0; - Double_t negX = 0; - Double_t negY = 0; - - for (vector<TrackDataHolder>::iterator j = evTracks.begin(); j != evTracks.end(); ++j) { - TrackDataHolder& track = *j; - - if (!track.isSignalShort) continue; - - if (track.isPos) { - hasShortPos = true; - posTime = fMuchPoints[evNum][track.pointInds[CUR_LAST_STATION]].t; - posX = fMuchPoints[evNum][track.pointInds[0]].x; - posY = fMuchPoints[evNum][track.pointInds[0]].y; - - if (track.isSignalLong) hasLongPos = true; - } - else { - hasShortNeg = true; - negTime = fMuchPoints[evNum][track.pointInds[CUR_LAST_STATION]].t; - negX = fMuchPoints[evNum][track.pointInds[0]].x; - negY = fMuchPoints[evNum][track.pointInds[0]].y; - - if (track.isSignalLong) hasLongNeg = true; - } - } - - if (hasShortPos && hasShortNeg) { - shortSignalMCTimes.push_back((posTime + negTime) / 2); - - if (hasLongPos && hasLongNeg) { - longSignalMCTimes.push_back((posTime + negTime) / 2); - signalDistHisto->Fill(sqrt((posX - negX) * (posX - negX) + (posY - negY) * (posY - negY))); - } - - if (hasLongPos || hasLongNeg) middleSignalMCTimes.push_back((posTime + negTime) / 2); - } - - ++evNum; - } - - { - TFile* curFile = TFile::CurrentFile(); - TString histoName = "signalDistHisto.root"; - - TFile fh(histoName.Data(), "RECREATE"); - signalDistHisto->Write(); - fh.Close(); - delete signalDistHisto; - - TFile::CurrentFile() = curFile; - } - - if (hasTrd) { - { - TFile* curFile = TFile::CurrentFile(); - TString histoName = "trdMctByZR_All.root"; - - TFile fh(histoName.Data(), "RECREATE"); - trdHisto->Write(); - fh.Close(); - delete trdHisto; - - TFile::CurrentFile() = curFile; - } - - { - TFile* curFile = TFile::CurrentFile(); - TString histoName = "trdMctByXY_All.root"; - - TFile fh(histoName.Data(), "RECREATE"); - trdHistoXY->Write(); - fh.Close(); - delete trdHistoXY; - - TFile::CurrentFile() = curFile; - } - } -#endif //LXTB_QA - - return kSUCCESS; -} - -static Int_t currentEventN = 0; -static unsigned long long tsStartTime = 0; - -#ifdef LXTB_EMU_TS -static Double_t min_ts_time = 100000; -static Double_t max_ts_time = -100000; -static list<LxTbBinnedPoint> ts_points; -#endif //LXTB_EMU_TS - -#ifdef LXTB_QA -void LxTBFinder::AddHit(const CbmPixelHit* hit, Int_t stationNumber, Int_t refId, bool isTrd) -#else -void LxTBFinder::AddHit(const CbmPixelHit* hit, Int_t stationNumber, Int_t refId) -#endif //LXTB_QA -{ - scaltype x = hit->GetX(); - scaltype y = hit->GetY(); - timetype t = hit->GetTime(); - scaltype dx = hit->GetDx(); - scaltype dy = hit->GetDy(); - timetype dt = 4; //hit->GetTimeError(); - LxTbBinnedPoint point(x, dx, y, dy, t, dt, refId, - /*!hasTrd && */ CUR_LAST_STATION == stationNumber); -#ifdef LXTB_QA - point.isTrd = isTrd; - point.stationNumber = stationNumber; - //point.eventId = pt.eventId; - //point.trackId = pt.trackId; - //fMCTracks[point.eventId][point.trackId].hasPoint[stationNumber] = true; - //point.pHit = hit; - //point.isTrd = isTrd; - Int_t clusterId = hit->GetRefId(); - - if (useIdeal) { - const FairMCPoint* pMCPt = static_cast<const FairMCPoint*>(isTrd ? fTrdMCPoints->Get(0, currentEventN, clusterId) - : fMuchMCPoints->Get(0, currentEventN, clusterId)); - Int_t trackId = pMCPt->GetTrackID(); - LxTbBinnedPoint::PointDesc ptDesc = {currentEventN, clusterId, trackId}; - t = isTrd ? fTrdPoints[currentEventN][clusterId].t : fMuchPoints[currentEventN][clusterId].t; -#ifdef LXTB_EMU_TS - t += gRandom->Gaus(0, 4); -#endif //LXTB_EMU_TS - point.mcRefs.push_back(ptDesc); - } - else { - const CbmCluster* cluster = - static_cast<const CbmCluster*>(isTrd ? fTrdClusters->At(clusterId) : fMuchClusters->At(clusterId)); - Int_t nDigis = cluster->GetNofDigis(); - double avT = 0; -#ifdef LXTB_EMU_TS - double avTErr = 0; -#endif //LXTB_EMU_TS - int nofT = 0; - - for (Int_t i = 0; i < nDigis; ++i) { - const CbmMatch* digiMatch = static_cast<const CbmMatch*>(isTrd ? fTrdDigiMatches->At(cluster->GetDigi(i)) - : fMuchPixelDigiMatches->At(cluster->GetDigi(i))); - Int_t nMCs = digiMatch->GetNofLinks(); - - for (Int_t j = 0; j < nMCs; ++j) { - const CbmLink& lnk = digiMatch->GetLink(j); - Int_t eventId = isEvByEv ? currentEventN : lnk.GetEntry(); - Int_t pointId = lnk.GetIndex(); - - if ((isTrd && fTrdPoints[eventId].size() <= static_cast<size_t>(pointId)) - || (!isTrd - && fMuchPoints[eventId].size() <= static_cast<size_t>( - pointId))) // Do this check because of possible addition of noise electrons in runtime. - continue; - - const FairMCPoint* pMCPt = static_cast<const FairMCPoint*>(isTrd ? fTrdMCPoints->Get(0, eventId, pointId) - : fMuchMCPoints->Get(0, eventId, pointId)); - Int_t trackId = pMCPt->GetTrackID(); - LxTbBinnedPoint::PointDesc ptDesc = {eventId, pointId, trackId}; - point.mcRefs.push_back(ptDesc); - Double_t deltaT = isTrd ? fTrdPoints[eventId][pointId].t : fMuchPoints[eventId][pointId].t; -#ifdef LXTB_EMU_TS - deltaT += gRandom->Gaus(0, 4); - avTErr += 4 * 4; -#endif //LXTB_EMU_TS - avT += deltaT; - ++nofT; - } - } - - if (nofT > 0) { - avT /= nofT; -#ifdef LXTB_EMU_TS - avTErr = TMath::Sqrt(avTErr); - avTErr /= nofT; - dt = avT; -#endif //LXTB_EMU_TS - } - - t = avT; - } -#endif //LXTB_QA - point.t = t; - -#ifdef LXTB_EMU_TS - ts_points.push_back(point); - - if (min_ts_time > t) min_ts_time = t; - - if (max_ts_time < t) max_ts_time = t; -#else //LXTB_EMU_TS - scaltype minY = (isTrd ? fFinder->trdStation.minY : fFinder->stations[stationNumber].minY); - scaltype binSizeY = (isTrd ? fFinder->trdStation.binSizeY : fFinder->stations[stationNumber].binSizeY); - int lastYBin = (isTrd ? fFinder->trdStation.lastYBin : fFinder->stations[stationNumber].lastYBin); - scaltype minX = (isTrd ? fFinder->trdStation.minX : fFinder->stations[stationNumber].minX); - scaltype binSizeX = (isTrd ? fFinder->trdStation.binSizeX : fFinder->stations[stationNumber].binSizeX); - int lastXBin = (isTrd ? fFinder->trdStation.lastXBin : fFinder->stations[stationNumber].lastXBin); - - int tInd = (t - fFinder->minT) / CUR_TIMEBIN_LENGTH; - - if (tInd < 0) tInd = 0; - else if (tInd > last_timebin) - tInd = last_timebin; - - LxTbTYXBin& tyxBin = - (isTrd ? fFinder->trdStation.tyxBinsArr[stationNumber][tInd] : fFinder->stations[stationNumber].tyxBins[tInd]); - int yInd = (y - minY) / binSizeY; - - if (yInd < 0) yInd = 0; - else if (yInd > lastYBin) - yInd = lastYBin; - - LxTbYXBin& yxBin = tyxBin.yxBins[yInd]; - int xInd = (x - minX) / binSizeX; - - if (xInd < 0) xInd = 0; - else if (xInd > lastXBin) - xInd = lastXBin; - - LxTbXBin& xBin = yxBin.xBins[xInd]; - xBin.points.push_back(point); - - if (/*!hasTrd && */ CUR_LAST_STATION == stationNumber) { - xBin.use = true; - yxBin.use = true; - tyxBin.use = true; - } -#endif //LXTB_EMU_TS -} - -#ifdef LXTB_TIE -void LxTBFinder::AddLayerHit(const CbmPixelHit* hit, Int_t layerNumber, Int_t refId, bool isTrd) -{ - scaltype x = hit->GetX(); - scaltype y = hit->GetY(); - timetype t = hit->GetTime(); - scaltype dx = hit->GetDx(); - scaltype dy = hit->GetDy(); - timetype dt = 4; //hit->GetTimeError(); - - LxTBBinndedLayer& layer = fDetector->fLayers[layerNumber]; - - if (layer.maxDx < dx) layer.maxDx = dx; - - if (layer.maxDy < dy) layer.maxDy = dy; - - if (layer.maxDt < dt) layer.maxDt = dt; - - LxTbBinnedPoint point(x, dx, y, dy, t, dt, refId, false); -#ifdef LXTB_QA - point.isTrd = isTrd; - point.stationNumber = layerNumber; // Station number does not matter in this context. - Int_t clusterId = hit->GetRefId(); - - /*if (useIdeal) - { - const FairMCPoint* pMCPt = static_cast<const FairMCPoint*> (isTrd ? fTrdMCPoints->Get(0, currentEventN, clusterId) : fMuchMCPoints->Get(0, currentEventN, clusterId)); - Int_t trackId = pMCPt->GetTrackID(); - LxTbBinnedPoint::PointDesc ptDesc = {currentEventN, clusterId, trackId}; - t = isTrd ? fTrdPoints[currentEventN][clusterId].t : fMuchPoints[currentEventN][clusterId].t; -#ifdef LXTB_EMU_TS - t += gRandom->Gaus(0, 4); -#endif//LXTB_EMU_TS - point.mcRefs.push_back(ptDesc); - } - else*/ - { - const CbmCluster* cluster = - static_cast<const CbmCluster*>(isTrd ? fTrdClusters->At(clusterId) : fMuchClusters->At(clusterId)); - Int_t nDigis = cluster->GetNofDigis(); - double avT = 0; -#ifdef LXTB_EMU_TS - double avTErr = 0; -#endif //LXTB_EMU_TS - int nofT = 0; - - for (Int_t i = 0; i < nDigis; ++i) { - const CbmMatch* digiMatch = static_cast<const CbmMatch*>(isTrd ? fTrdDigiMatches->At(cluster->GetDigi(i)) - : fMuchPixelDigiMatches->At(cluster->GetDigi(i))); - Int_t nMCs = digiMatch->GetNofLinks(); - - for (Int_t j = 0; j < nMCs; ++j) { - const CbmLink& lnk = digiMatch->GetLink(j); - Int_t eventId = isEvByEv ? currentEventN : lnk.GetEntry(); - Int_t pointId = lnk.GetIndex(); - - if ((isTrd && fTrdPoints[eventId].size() <= pointId) - || (!isTrd - && fMuchPoints[eventId].size() - <= pointId)) // Do this check because of possible addition of noise electrons in runtime. - continue; - - const FairMCPoint* pMCPt = static_cast<const FairMCPoint*>(isTrd ? fTrdMCPoints->Get(0, eventId, pointId) - : fMuchMCPoints->Get(0, eventId, pointId)); - Int_t trackId = pMCPt->GetTrackID(); - LxTbBinnedPoint::PointDesc ptDesc = {eventId, pointId, trackId}; - point.mcRefs.push_back(ptDesc); - Double_t deltaT = isTrd ? fTrdPoints[eventId][pointId].t : fMuchPoints[eventId][pointId].t; -#ifdef LXTB_EMU_TS - deltaT += gRandom->Gaus(0, 4); - avTErr += 4 * 4; -#endif //LXTB_EMU_TS - avT += deltaT; - ++nofT; - } - } - - if (nofT > 0) { - avT /= nofT; -#ifdef LXTB_EMU_TS - avTErr = TMath::Sqrt(avTErr); - avTErr /= nofT; - dt = avT; -#endif //LXTB_EMU_TS - } - - t = avT; - } -#endif //LXTB_QA - point.t = t; - - /*#ifdef LXTB_EMU_TS - ts_points.push_back(point); - - if (min_ts_time > t) - min_ts_time = t; - - if (max_ts_time < t) - max_ts_time = t; -#else//LXTB_EMU_TS*/ - scaltype minY = fDetector->fLayers[layerNumber].minY; - scaltype binSizeY = fDetector->fLayers[layerNumber].binSizeY; - int lastYBin = fDetector->fLayers[layerNumber].lastYBin; - scaltype minX = fDetector->fLayers[layerNumber].minX; - scaltype binSizeX = fDetector->fLayers[layerNumber].binSizeX; - int lastXBin = fDetector->fLayers[layerNumber].lastXBin; - timetype minT = fDetector->fLayers[layerNumber].minT; - int binSizeT = fDetector->fLayers[layerNumber].binSizeT; - int lastTBin = fDetector->fLayers[layerNumber].lastTBin; - - int tInd = (t - minT) / binSizeT; - - if (tInd < 0) tInd = 0; - else if (tInd > lastTBin) - tInd = lastTBin; - - LxTbTYXBin& tyxBin = fDetector->fLayers[layerNumber].tyxBins[tInd]; - int yInd = (y - minY) / binSizeY; - - if (yInd < 0) yInd = 0; - else if (yInd > lastYBin) - yInd = lastYBin; - - LxTbYXBin& yxBin = tyxBin.yxBins[yInd]; - int xInd = (x - minX) / binSizeX; - - if (xInd < 0) xInd = 0; - else if (xInd > lastXBin) - xInd = lastXBin; - - LxTbXBin& xBin = yxBin.xBins[xInd]; - xBin.points.push_back(point); - //#endif//LXTB_EMU_TS -} - -void LxTBFinder::AddStsTrack(const CbmStsTrack& stsTrack, Int_t selfId) -{ - const FairTrackParam& par = *stsTrack.GetParamLast(); - - if (0 == par.GetQp()) return; - - Int_t nofHits = stsTrack.GetNofHits(); - - if (nofHits < 1) return; - - Int_t lastHitNr = nofHits - 1; - - if (kSTSHIT != stsTrack.GetHitType(lastHitNr)) return; - - Int_t lastHitIndex = stsTrack.GetHitIndex(lastHitNr); - const CbmStsHit& lastHit = *static_cast<const CbmStsHit*>(fStsHits->At(lastHitIndex)); - Double_t lastHitTime = fEventTimes[currentEventN] + lastHit.GetTime(); - Double_t lastHitTimeErr = lastHit.GetTimeError(); - fDetector->AddStsTrack(par, stsTrack.GetChiSq(), lastHitTime, selfId); -} -#endif //LXTB_TIE - -#ifdef LXTB_QA -static vector<int> nof_ev_digis(1000); -static int nof_digis = 0; -#endif //LXTB_QA - -static void SpliceTriggerings(list<pair<timetype, timetype>>& out, LxTbBinnedFinder::TriggerTimeArray& in) -{ - for (int i = 0; i < in.nofTimebins; ++i) - out.splice(out.end(), in.triggerTimeBins[i]); -} - -void LxTBFinder::Exec(Option_t*) -{ - FairRootManager* ioman = FairRootManager::Instance(); - - if (0 == ioman) LOG(fatal) << "No FairRootManager"; - - Int_t evNumb = ioman->GetEntryNr(); - cout << "evNumb = " << evNumb << endl; - //Double_t evTi = ioman->GetEventTime(); (VF) unused - - fFinder->Clear(); - fFinder->SetTSBegin(tsStartTime); - -#ifdef LXTB_TIE - fDetector->fMuchTracks->Delete(); - fDetector->fGlobalTracks->Clear(); - fDetector->SetTSBegin(tsStartTime); -#endif //LXTB_TIE - - // As the SIS100 geometry contains 4 MUCH and 1 TRD stations we need to read both MUCH and TRD hits. - for (int i = 0; i < fMuchPixelHits->GetEntriesFast(); ++i) { - const CbmMuchPixelHit* mh = static_cast<const CbmMuchPixelHit*>(fMuchPixelHits->At(i)); - Int_t hitLrN = CbmMuchGeoScheme::GetLayerIndex(mh->GetAddress()); - - if (1 != hitLrN) continue; - - Int_t hitStN = CbmMuchGeoScheme::GetStationIndex(mh->GetAddress()); -#ifdef LXTB_QA - AddHit(mh, hitStN, i, false); -#else - AddHit(mh, hitStN, i); -#endif //LXTB_QA - } - - if (hasTrd) { - for (int i = 0; i < fTrdHits->GetEntriesFast(); ++i) { - const CbmTrdHit* th = static_cast<const CbmTrdHit*>(fTrdHits->At(i)); - Int_t hitStN = th->GetPlaneId(); - - //if (0 != hitStN) - //continue; - - //hitStN = CUR_LAST_STATION; -#ifdef LXTB_QA - AddHit(th, hitStN, i, true); -#else - AddHit(th, hitStN, i); -#endif //LXTB_QA - } - } - -#ifndef LXTB_EMU_TS - fFinder->Reconstruct(); - tsStartTime += 100; - - for (int i = 0; i < fFinder->nofTrackBins; ++i) { - list<LxTbBinnedFinder::Chain*>& recoTracksBin = fFinder->recoTracks[i]; - - for (list<LxTbBinnedFinder::Chain*>::const_iterator j = recoTracksBin.begin(); j != recoTracksBin.end(); ++j) - recoTracks.push_back(*j); - } - - SpliceTriggerings(triggerTimes_trd0_sign0_dist0, fFinder->triggerTimes_trd0_sign0_dist0); - SpliceTriggerings(triggerTimes_trd0_sign0_dist1, fFinder->triggerTimes_trd0_sign0_dist1); - SpliceTriggerings(triggerTimes_trd0_sign1_dist0, fFinder->triggerTimes_trd0_sign1_dist0); - SpliceTriggerings(triggerTimes_trd0_sign1_dist1, fFinder->triggerTimes_trd0_sign1_dist1); - SpliceTriggerings(triggerTimes_trd1_sign0_dist0, fFinder->triggerTimes_trd1_sign0_dist0); - SpliceTriggerings(triggerTimes_trd1_sign0_dist1, fFinder->triggerTimes_trd1_sign0_dist1); - SpliceTriggerings(triggerTimes_trd1_sign1_dist0, fFinder->triggerTimes_trd1_sign1_dist0); - - int prevTrigTimeSize = - triggerTimes_trd1_sign1_dist1.size(); // Not very elegant! >--------------------------------------- - SpliceTriggerings(triggerTimes_trd1_sign1_dist1, - fFinder->triggerTimes_trd1_sign1_dist1); // | -#ifdef LXTB_TIE - // | - if (triggerTimes_trd1_sign1_dist1.size() - prevTrigTimeSize - > 0) // Triggering event. Do global tracks generation. <------ - { - fDetector->Clear(); - Int_t nofStsTracks = fStsTracks->GetEntriesFast(); - - for (int i = 0; i < nofStsTracks; ++i) { - const CbmStsTrack* stsTrack = static_cast<const CbmStsTrack*>(fStsTracks->At(i)); - AddStsTrack(*stsTrack, i); - } - - for (int i = 0; i < fMuchPixelHits->GetEntriesFast(); ++i) { - const CbmMuchPixelHit* mh = static_cast<const CbmMuchPixelHit*>(fMuchPixelHits->At(i)); - Int_t hitStN = CbmMuchGeoScheme::GetStationIndex(mh->GetAddress()); - Int_t hitLrN = CbmMuchGeoScheme::GetLayerIndex(mh->GetAddress()); - AddLayerHit(mh, hitStN * 3 + hitLrN, i, false); - } - - for (int i = 0; i < fTrdHits->GetEntriesFast(); ++i) { - const CbmTrdHit* th = static_cast<const CbmTrdHit*>(fTrdHits->At(i)); - Int_t hitStN = th->GetPlaneId(); - AddLayerHit(th, CUR_NOF_STATIONS * 3 + hitStN, i, true); - } - - fDetector->TieTracks(*fFinder); - } -#endif //LXTB_TIE - SpliceTriggerings(triggerTimes_trd05_sign0_dist0, fFinder->triggerTimes_trd05_sign0_dist0); - SpliceTriggerings(triggerTimes_trd05_sign0_dist1, fFinder->triggerTimes_trd05_sign0_dist1); - SpliceTriggerings(triggerTimes_trd05_sign1_dist0, fFinder->triggerTimes_trd05_sign1_dist0); - SpliceTriggerings(triggerTimes_trd05_sign1_dist1, fFinder->triggerTimes_trd05_sign1_dist1); -#endif //LXTB_EMU_TS - -#ifdef LXTB_QA - if (fMvdDigis) { - nof_ev_digis[currentEventN] += fMvdDigis->GetEntriesFast(); - nof_digis += fMvdDigis->GetEntriesFast(); - } - - if (fStsDigis) { - nof_ev_digis[currentEventN] += fStsDigis->GetEntriesFast(); - nof_digis += fStsDigis->GetEntriesFast(); - } - - nof_ev_digis[currentEventN] += fMuchPixelDigiMatches->GetEntriesFast(); - nof_digis += fMuchPixelDigiMatches->GetEntriesFast(); - nof_ev_digis[currentEventN] += fTrdDigiMatches->GetEntriesFast(); - nof_digis += fTrdDigiMatches->GetEntriesFast(); - - if (fTofDigis) { - nof_ev_digis[currentEventN] += fTofDigis->GetEntriesFast(); - nof_digis += fTofDigis->GetEntriesFast(); - } -#endif //LXTB_QA - - ++currentEventN; -} - -struct RecoTrackData { - Int_t eventId; - Int_t trackId; - - RecoTrackData(Int_t eId, Int_t tId) : eventId(eId), trackId(tId) {} -}; - -struct RTDLess { - bool operator()(const RecoTrackData& x, const RecoTrackData& y) const - { - if (x.eventId < y.eventId) return true; - - return x.trackId < y.trackId; - } -}; - -static void PrintTrigger(list<pair<timetype, timetype>>& signalRecoTimes, list<timetype>& signalMCTimes, - const char* name, bool write_eff_for_inv_m = false) -{ - int nofRecoSignals = 0; - - for (list<timetype>::const_iterator i = signalMCTimes.begin(); i != signalMCTimes.end(); ++i) { - timetype mcTime = *i; - bool matched = false; - - for (list<pair<timetype, timetype>>::const_iterator j = signalRecoTimes.begin(); j != signalRecoTimes.end(); ++j) { - timetype recoTime = j->first; - timetype dt = j->second; - - if (fabs(recoTime - mcTime) < NOF_SIGMAS * dt) matched = true; - } - - if (matched) ++nofRecoSignals; - } - - cout << "Have: " << signalRecoTimes.size() << " signaled " << name << " events" << endl; - double eff = 0 == signalMCTimes.size() ? 100 : 100.0 * nofRecoSignals / signalMCTimes.size(); - cout << "Triggered signals(" << name << "): " << eff << "% [ " << nofRecoSignals << " / " << signalMCTimes.size() - << " ]" << endl; - - size_t buf_size = 256; - char buf[buf_size]; - snprintf(buf, buf_size - 1, "triggerings_%s.txt", name); - ofstream triggeringsFile(buf, ios_base::out | ios_base::trunc); - triggeringsFile << signalRecoTimes.size(); - - snprintf(buf, buf_size - 1, "signal_triggerings_%s.txt", name); - ofstream signalTriggeringsFile(buf, ios_base::out | ios_base::trunc); - signalTriggeringsFile << nofRecoSignals; - - if (write_eff_for_inv_m) { - ifstream invMFile("inv_m.txt"); - - if (invMFile.is_open()) { - double invM; - invMFile >> invM; - ofstream invMEffFile("inv_m_eff.txt", ios_base::out | ios_base::trunc); - invMEffFile << invM << " " << eff << endl; - } - } -} - -void LxTBFinder::Finish() -{ -#ifdef LXTB_EMU_TS - Double_t tCoeff = CUR_TIMEBIN_LENGTH * nof_timebins / (max_ts_time - min_ts_time); - - for (list<LxTbBinnedPoint>::iterator i = ts_points.begin(); i != ts_points.end(); ++i) { - LxTbBinnedPoint& point = *i; - point.t = (point.t - min_ts_time) * tCoeff; - point.dt *= tCoeff; - - bool isTrd = point.isTrd; - Int_t stationNumber = point.stationNumber; - scaltype minY = (isTrd ? fFinder->trdStation.minY : fFinder->stations[stationNumber].minY); - scaltype binSizeY = (isTrd ? fFinder->trdStation.binSizeY : fFinder->stations[stationNumber].binSizeY); - int lastYBin = (isTrd ? fFinder->trdStation.lastYBin : fFinder->stations[stationNumber].lastYBin); - scaltype minX = (isTrd ? fFinder->trdStation.minX : fFinder->stations[stationNumber].minX); - scaltype binSizeX = (isTrd ? fFinder->trdStation.binSizeX : fFinder->stations[stationNumber].binSizeX); - int lastXBin = (isTrd ? fFinder->trdStation.lastXBin : fFinder->stations[stationNumber].lastXBin); - - int tInd = (point.t - fFinder->minT) / CUR_TIMEBIN_LENGTH; - - if (tInd < 0) tInd = 0; - else if (tInd > int(last_timebin)) - tInd = last_timebin; - - LxTbTYXBin& tyxBin = - (isTrd ? fFinder->trdStation.tyxBinsArr[stationNumber][tInd] : fFinder->stations[stationNumber].tyxBins[tInd]); - int yInd = (point.y - minY) / binSizeY; - - if (yInd < 0) yInd = 0; - else if (yInd > lastYBin) - yInd = lastYBin; - - LxTbYXBin& yxBin = tyxBin.yxBins[yInd]; - int xInd = (point.x - minX) / binSizeX; - - if (xInd < 0) xInd = 0; - else if (xInd > lastXBin) - xInd = lastXBin; - - LxTbXBin& xBin = yxBin.xBins[xInd]; - xBin.points.push_back(point); - - if (/*!hasTrd && */ CUR_LAST_STATION == stationNumber) { - xBin.use = true; - yxBin.use = true; - tyxBin.use = true; - } - } - -#ifdef LXTB_TIE - fDetector->SetTSBegin(0); -#endif //LXTB_TIE - - fFinder->Reconstruct(); - - for (list<timetype>::iterator i = shortSignalMCTimes.begin(); i != shortSignalMCTimes.end(); ++i) { - timetype& v = *i; - v = (v - min_ts_time) * tCoeff; - } - - for (list<timetype>::iterator i = longSignalMCTimes.begin(); i != longSignalMCTimes.end(); ++i) { - timetype& v = *i; - v = (v - min_ts_time) * tCoeff; - } - - for (list<timetype>::iterator i = middleSignalMCTimes.begin(); i != middleSignalMCTimes.end(); ++i) { - timetype& v = *i; - v = (v - min_ts_time) * tCoeff; - } - - for (int i = 0; i < fFinder->nofTrackBins; ++i) { - list<LxTbBinnedFinder::Chain*>& recoTracksBin = fFinder->recoTracks[i]; - - for (list<LxTbBinnedFinder::Chain*>::const_iterator j = recoTracksBin.begin(); j != recoTracksBin.end(); ++j) - recoTracks.push_back(*j); - } - - SpliceTriggerings(triggerTimes_trd0_sign0_dist0, fFinder->triggerTimes_trd0_sign0_dist0); - SpliceTriggerings(triggerTimes_trd0_sign0_dist1, fFinder->triggerTimes_trd0_sign0_dist1); - SpliceTriggerings(triggerTimes_trd0_sign1_dist0, fFinder->triggerTimes_trd0_sign1_dist0); - SpliceTriggerings(triggerTimes_trd0_sign1_dist1, fFinder->triggerTimes_trd0_sign1_dist1); - SpliceTriggerings(triggerTimes_trd1_sign0_dist0, fFinder->triggerTimes_trd1_sign0_dist0); - SpliceTriggerings(triggerTimes_trd1_sign0_dist1, fFinder->triggerTimes_trd1_sign0_dist1); - SpliceTriggerings(triggerTimes_trd1_sign1_dist0, fFinder->triggerTimes_trd1_sign1_dist0); - SpliceTriggerings(triggerTimes_trd1_sign1_dist1, fFinder->triggerTimes_trd1_sign1_dist1); - SpliceTriggerings(triggerTimes_trd05_sign0_dist0, fFinder->triggerTimes_trd05_sign0_dist0); - SpliceTriggerings(triggerTimes_trd05_sign0_dist1, fFinder->triggerTimes_trd05_sign0_dist1); - SpliceTriggerings(triggerTimes_trd05_sign1_dist0, fFinder->triggerTimes_trd05_sign1_dist0); - SpliceTriggerings(triggerTimes_trd05_sign1_dist1, fFinder->triggerTimes_trd05_sign1_dist1); -#endif //LXTB_EMU_TS - cout << "LxTbBinnedFinder::Reconstruct() full duration was: " << fullDuration << endl; - - int nofRecoTracks = 0; - - for (list<LxTbBinnedFinder::Chain*>::const_iterator i = recoTracks.begin(); i != recoTracks.end(); ++i) { - const LxTbBinnedFinder::Chain* chain = *i; - - if (!hasTrd || chain->highMom) ++nofRecoTracks; - } - - cout << "LxTbBinnedFinder::Reconstruct() the number of found tracks: " << nofRecoTracks << endl; - -#ifdef LXTB_QA - static int nofSignalTracks = 0; - static int nofRecoSignalTracks = 0; - int eventN = 0; - - for (vector<vector<TrackDataHolder>>::iterator i = fMCTracks.begin(); i != fMCTracks.end(); ++i) { - vector<TrackDataHolder>& evTracks = *i; - - for (vector<TrackDataHolder>::iterator j = evTracks.begin(); j != evTracks.end(); ++j) { - TrackDataHolder& track = *j; - - if (!track.isSignalShort || (hasTrd && !track.isSignalLong)) continue; - - ++nofSignalTracks; - - int nofMatchPoints = 0; - - for (list<LxTbBinnedFinder::Chain*>::const_iterator k = recoTracks.begin(); k != recoTracks.end(); ++k) { - const LxTbBinnedFinder::Chain* chain = *k; - - if (hasTrd && !chain->highMom) continue; - - for (int l = 0; l < CUR_NOF_STATIONS; ++l) { - bool pointsMatched = false; - - for (list<LxTbBinnedPoint::PointDesc>::const_iterator m = chain->points[l]->mcRefs.begin(); - m != chain->points[l]->mcRefs.end(); ++m) { - if (m->eventId == eventN && m->pointId == track.pointInds[l]) { - pointsMatched = true; - break; - } - } - - if (pointsMatched) ++nofMatchPoints; - } - } - - if (nofMatchPoints >= 2) { - ++nofRecoSignalTracks; - continue; - } - } - - ++eventN; - } - - double eff = 0 == nofSignalTracks ? 100 : 100.0 * nofRecoSignalTracks / nofSignalTracks; - cout << "Reconstruction efficiency is: " << eff << "% [ " << nofRecoSignalTracks << " / " << nofSignalTracks << " ]" - << endl; - - int nofRightRecoTracks = 0; - - for (list<LxTbBinnedFinder::Chain*>::const_iterator i = recoTracks.begin(); i != recoTracks.end(); ++i) { - const LxTbBinnedFinder::Chain* chain = *i; - - if (hasTrd && !chain->highMom) continue; - - map<RecoTrackData, int, RTDLess> nofTracks; - - for (int j = 0; j < CUR_NOF_STATIONS; ++j) { - int stMask = 1 << j; - - for (list<LxTbBinnedPoint::PointDesc>::const_iterator k = chain->points[j]->mcRefs.begin(); - k != chain->points[j]->mcRefs.end(); ++k) { - RecoTrackData st(k->eventId, k->trackId); - map<RecoTrackData, int, RTDLess>::iterator nofTIter = nofTracks.find(st); - - if (nofTIter != nofTracks.end()) nofTIter->second |= stMask; - else - nofTracks[st] = stMask; - } - } - - int nofPoints = 0; - - for (map<RecoTrackData, int, RTDLess>::const_iterator j = nofTracks.begin(); j != nofTracks.end(); ++j) { - int nofp = 0; - - for (int k = 0; k < CUR_NOF_STATIONS; ++k) { - if (j->second & (1 << k)) ++nofp; - } - - if (nofp > nofPoints) nofPoints = nofp; - } - - if (nofPoints >= 2) ++nofRightRecoTracks; - } - - eff = 0 == recoTracks.size() ? 100 : 100.0 * nofRightRecoTracks / nofRecoTracks; - cout << "Non ghosts are: " << eff << "% [ " << nofRightRecoTracks << " / " << nofRecoTracks << " ]" << endl; - - cout << "Have: " << shortSignalMCTimes.size() << " short signaling events" << endl; - cout << "Have: " << longSignalMCTimes.size() << " long signaling events" << endl; - cout << "Have: " << middleSignalMCTimes.size() << " middle signaling events" << endl; - cout << "Have: " << currentEventN << " events" << endl; - - ofstream nofEventsFile("nof_events.txt", ios_base::out | ios_base::trunc); - nofEventsFile << currentEventN; - - ofstream nofShortSignalsFile("nof_short_signals.txt", ios_base::out | ios_base::trunc); - nofShortSignalsFile << shortSignalMCTimes.size(); - - ofstream nofLongSignalsFile("nof_long_signals.txt", ios_base::out | ios_base::trunc); - nofLongSignalsFile << longSignalMCTimes.size(); - - ofstream nofMiddleSignalsFile("nof_middle_signals.txt", ios_base::out | ios_base::trunc); - nofMiddleSignalsFile << middleSignalMCTimes.size(); - - PrintTrigger(triggerTimes_trd0_sign0_dist0, shortSignalMCTimes, "triggerTimes_trd0_sign0_dist0"); - PrintTrigger(triggerTimes_trd0_sign0_dist1, shortSignalMCTimes, "triggerTimes_trd0_sign0_dist1"); - PrintTrigger(triggerTimes_trd0_sign1_dist0, shortSignalMCTimes, "triggerTimes_trd0_sign1_dist0"); - PrintTrigger(triggerTimes_trd0_sign1_dist1, shortSignalMCTimes, "triggerTimes_trd0_sign1_dist1"); - PrintTrigger(triggerTimes_trd1_sign0_dist0, longSignalMCTimes, "triggerTimes_trd1_sign0_dist0"); - PrintTrigger(triggerTimes_trd1_sign0_dist1, longSignalMCTimes, "triggerTimes_trd1_sign0_dist1"); - PrintTrigger(triggerTimes_trd1_sign1_dist0, longSignalMCTimes, "triggerTimes_trd1_sign1_dist0"); - PrintTrigger(triggerTimes_trd1_sign1_dist1, longSignalMCTimes, "triggerTimes_trd1_sign1_dist1", true); - PrintTrigger(triggerTimes_trd05_sign0_dist0, middleSignalMCTimes, "triggerTimes_trd05_sign0_dist0"); - PrintTrigger(triggerTimes_trd05_sign0_dist1, middleSignalMCTimes, "triggerTimes_trd05_sign0_dist1"); - PrintTrigger(triggerTimes_trd05_sign1_dist0, middleSignalMCTimes, "triggerTimes_trd05_sign1_dist0"); - PrintTrigger(triggerTimes_trd05_sign1_dist1, middleSignalMCTimes, "triggerTimes_trd05_sign1_dist1"); - - Int_t nofTriggerDigis = 0; - - for (set<Int_t>::const_iterator i = fFinder->triggerEventNumber.begin(); i != fFinder->triggerEventNumber.end(); ++i) - nofTriggerDigis += nof_ev_digis[*i]; - - ofstream nofTriggerDigisFile("nof_trigger_digis.txt", ios_base::out | ios_base::trunc); - nofTriggerDigisFile << nofTriggerDigis; - ofstream nofDigisFile("nof_digis.txt", ios_base::out | ios_base::trunc); - nofDigisFile << nof_digis; -#endif //LXTB_QA - - for (list<LxTbBinnedFinder::Chain*>::iterator i = recoTracks.begin(); i != recoTracks.end(); ++i) - delete *i; -} diff --git a/reco/tracking/lx/TBBinned/LxTBTask.h b/reco/tracking/lx/TBBinned/LxTBTask.h deleted file mode 100644 index c54f460bc0a2ada55f401a570124f4249161a7f8..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/TBBinned/LxTBTask.h +++ /dev/null @@ -1,158 +0,0 @@ -/* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov, Florian Uhlig [committer] */ - -#ifndef LXTBTASK_H -#define LXTBTASK_H - -#include "CbmMuchPoint.h" -#include "CbmTrdPoint.h" - -#include "FairTask.h" - -#include <vector> - -#include "LxTBDefinitions.h" - -#define CUR_NOF_TRD_LAYERS 4 -#define CUR_LAST_TRD_LAYER CUR_NOF_TRD_LAYERS - 1 - -#include "CbmMCDataArray.h" -#include "CbmPixelHit.h" -#include "CbmStsTrack.h" - -#include "TGeoManager.h" - -#include "LxTBTieTracks.h" - -#define CUR_NOF_STATIONS 4 -#define CUR_LAST_STATION CUR_NOF_STATIONS - 1 -//#define CUR_NOF_TIMEBINS 5 -//#define CUR_LAST_TIMEBIN CUR_NOF_TIMEBINS - 1 -#define CUR_TIMEBIN_LENGTH 100 - -#include "LxTBBinned.h" - -class LxTBFinder : public FairTask { -public: -#ifdef LXTB_QA - struct PointDataHolder { - Double_t x; - Double_t y; - Double_t z; - Double_t t; - Int_t eventId; - Int_t trackId; - Int_t pointId; - Int_t stationNumber; - Int_t layerNumber; - }; - - struct TrackDataHolder { - Int_t pointInds[CUR_NOF_STATIONS]; - Int_t trdPointInds[CUR_NOF_TRD_LAYERS]; - bool isSignalShort; - bool isSignalLong; - bool isPos; - - TrackDataHolder() : isSignalShort(false), isSignalLong(false), isPos(false) - { - for (int i = 0; i < CUR_NOF_STATIONS; ++i) - pointInds[i] = -1; - - for (int i = 0; i < CUR_NOF_TRD_LAYERS; ++i) - trdPointInds[i] = -1; - } - }; -#endif //LXTB_QA - -public: - LxTBFinder(); - LxTBFinder(const LxTBFinder&) = delete; - LxTBFinder& operator=(const LxTBFinder&) = delete; - - InitStatus Init(); // Overridden from FairTask - void Exec(Option_t* opt); // Overridden from FairTask - void Finish(); // Overridden from FairTask - - void SetEvByEv(bool v = true) - { - isEvByEv = v; - - if (isEvByEv) -#ifdef LXTB_EMU_TS - nof_timebins = 1000; -#else //LXTB_EMU_TS - nof_timebins = 5; -#endif //LXTB_EMU_TS - else - nof_timebins = 1000; - - last_timebin = nof_timebins - 1; - } - - void SetUseTrd(bool v = true) { useTrd = v; } - void SetUseIdeal(bool v = true) { useIdeal = v; } - void SetUseAsciiSig(bool v = true) { useAsciiSig = v; } - void SetSignalParticle(const char* name) { fSignalParticle = name; } - void SetNEvents(Int_t v) { fNEvents = v; } - -private: - void HandleGeometry(); -#ifdef LXTB_QA - void AddHit(const CbmPixelHit* hit, Int_t stationNumber, Int_t refId, bool isTrd); -#else - void AddHit(const CbmPixelHit* hit, Int_t stationNumber, Int_t refId); -#endif //LXTB_QA - -#ifdef LXTB_TIE - void AddLayerHit(const CbmPixelHit* hit, Int_t layerNumber, Int_t refId, bool isTrd); - void AddStsTrack(const CbmStsTrack& stsTrack, Int_t selfId); -#endif //LXTB_TIE - - std::vector<std::vector<PointDataHolder>> fMuchPoints; - CbmMCDataArray* fMuchMCPoints; - TClonesArray* fMuchPixelHits; - TClonesArray* fMuchClusters; - TClonesArray* fMuchPixelDigiMatches; - - std::vector<std::vector<PointDataHolder>> fTrdPoints; - CbmMCDataArray* fTrdMCPoints; - TClonesArray* fTrdHits; - TClonesArray* fTrdClusters; - TClonesArray* fTrdDigiMatches; - -#ifdef LXTB_QA - TClonesArray* fMvdDigis; - TClonesArray* fStsDigis; - TClonesArray* fTofDigis; -#endif //LXTB_QA - -#ifdef LXTB_QA - std::vector<std::vector<TrackDataHolder>> fMCTracks; -#endif //LXTB_QA - bool isEvByEv; - LxTbBinnedFinder* fFinder; - std::list<LxTbBinnedFinder::Chain*> recoTracks; - bool hasTrd; - bool useTrd; - bool useIdeal; - bool useAsciiSig; - const char* fSignalParticle; - unsigned int nof_timebins; - unsigned int last_timebin; - Int_t fNEvents; - std::vector<Double_t> fEventTimes; -#ifdef LXTB_TIE - TClonesArray* fStsHits; - TClonesArray* fStsTracks; - TClonesArray* fStsClusters; - TClonesArray* fStsDigiMatches; - LxTBBinnedDetector* fDetector; -#endif //LXTB_TIE - int dummy; - - ClassDef(LxTBFinder, 1) -}; - -#endif /* LXTBTASK_H */ diff --git a/reco/tracking/lx/TBBinned/LxTBTieTracks.cxx b/reco/tracking/lx/TBBinned/LxTBTieTracks.cxx deleted file mode 100644 index bea71b18b1cb1e787e4bc3699c5c40658c3272e4..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/TBBinned/LxTBTieTracks.cxx +++ /dev/null @@ -1,207 +0,0 @@ -/* Copyright (C) 2016-2019 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -#include "LxTBTieTracks.h" - -#include "CbmMuch.h" -#include "CbmMuchPixelHit.h" -#include "CbmTrdHit.h" -#include "base/CbmLitToolFactory.h" -#include "data/CbmLitTrackParam.h" -#include "utils/CbmLitConverter.h" - -using std::list; - -void LxTBBinnedDetector::AddStsTrack(const FairTrackParam& par, Double_t chiSq, Double_t time, - Int_t selfId /*, Int_t eventId, Int_t fileId*/) -{ - LxTBBinnedStsTrack stsTrack = {par, chiSq, time, selfId /*, eventId, fileId*/}; - fStsTracks.push_back(stsTrack); -} - -struct TieHandlePoint : public LxTBBinndedLayer::PointHandler { - TrackUpdatePtr fFilter; - CbmLitTrackParam fPar; - CbmLitTrackParam fOutPar; - litfloat fChiSq; - litfloat fZ; - const LxTbBinnedPoint* fPoint; - - TieHandlePoint() : fFilter(), fPar(), fOutPar(), fChiSq(), fZ(), fPoint(nullptr) {} - TieHandlePoint(const TieHandlePoint&) = delete; - TieHandlePoint& operator=(const TieHandlePoint&) = delete; - - void HandlePoint(const LxTbBinnedPoint& point) - { - litfloat chiSq = std::numeric_limits<litfloat>::max(); - CbmLitPixelHit litHit; - litHit.SetX(point.x); - litHit.SetY(point.y); - litHit.SetZ(fZ); - litHit.SetDx(point.dx); - litHit.SetDy(point.dy); - litHit.SetDz(0); - litHit.SetDxy(0); - litHit.SetRefId(0); - CbmLitTrackParam par = fPar; - fFilter->Update(&par, &litHit, chiSq); - - if (chiSq < 25 && chiSq < fChiSq) { - fChiSq = chiSq; - fPoint = &point; - fOutPar = par; - } - } -}; - -LxTBBinnedDetector::LxTBBinnedDetector(int nofl, int nofxb, int nofyb, int noftb, int binSizeT) - : fLayers(reinterpret_cast<LxTBBinndedLayer*>(new unsigned char[nofl * sizeof(LxTBBinndedLayer)])) - , fNofLayers(nofl) - , fStsTracks() - , fMuchTracks(nullptr) - , fGlobalTracks(nullptr) -{ - for (int i = 0; i < fNofLayers; ++i) - new (&fLayers[i]) LxTBBinndedLayer(nofxb, nofyb, noftb, binSizeT); -} - -void LxTBBinnedDetector::Init() -{ - for (int i = 0; i < fNofLayers; ++i) - fLayers[i].Init(); -} - -void LxTBBinnedDetector::Clear() -{ - fStsTracks.clear(); - - for (int i = 0; i < fNofLayers; ++i) - fLayers[i].Clear(); -} - -void LxTBBinnedDetector::SetTSBegin(unsigned long long tsLowBound) -{ - for (int i = 0; i < fNofLayers; ++i) - fLayers[i].SetTSBegin(tsLowBound); -} - -void LxTBBinnedDetector::TieTracks(LxTbBinnedFinder&) -{ - //for (int i = 0; i < fFinder.nofTrackBins; ++i) - //{ - //list<LxTbBinnedFinder::Chain*>& recoTracksBin = fFinder.recoTracks[i]; - - //for (list<LxTbBinnedFinder::Chain*>::const_iterator j = recoTracksBin.begin(); j != recoTracksBin.end(); ++j) - //recoTracks.push_back(*j); - //} - TrackPropagatorPtr propagator = CbmLitToolFactory::CreateTrackPropagator("lit"); - TrackUpdatePtr filter = CbmLitToolFactory::CreateTrackUpdate("kalman"); - //TrackFitterPtr fFitter = CbmLitToolFactory::CreateTrackFitter("lit_kalman"); - int muchTrackNo = 0; - int globalTrackNo = 0; - - for (list<LxTBBinnedStsTrack>::const_iterator i = fStsTracks.begin(); i != fStsTracks.end(); ++i) { - const LxTBBinnedStsTrack& stsTrack = *i; - CbmGlobalTrack* globalTrack = new ((*fGlobalTracks)[globalTrackNo]) CbmGlobalTrack(); - globalTrack->SetStsTrackIndex(globalTrackNo++); - Double_t qp = stsTrack.fPar.GetQp(); - - if (0 == qp) // We want propagate J/psi tracks only. - continue; - - Double_t p = 1 / qp; - - if (p < 3) // We want propagate J/psi tracks only. - continue; - - Double_t txSq = stsTrack.fPar.GetTx() * stsTrack.fPar.GetTx(); - Double_t tySq = stsTrack.fPar.GetTy() * stsTrack.fPar.GetTy(); - Double_t ptSq = p * p * (txSq + tySq) / (1 + txSq + tySq); - - if (ptSq < 1) // We want propagate J/psi tracks only. - continue; - - Double_t trackChiSq = stsTrack.fChiSq; - CbmTrackParam cbmPar; - cbmPar.Set(stsTrack.fPar, stsTrack.fTime, 2); - CbmLitTrackParam par; - CbmLitConverterFairTrackParam::FairTrackParamToCbmLitTrackParam(&cbmPar, &par); - CbmLitTrackParam prevPar; - CbmLitTrackParam firstPar; - bool firstTime = true; - timetype t = stsTrack.fTime; - int nofMissingHits = 0; - - struct PointData { - const LxTbBinnedPoint* point; - bool isTrd; - }; - - list<PointData> points; - - for (int j = 0; j < fNofLayers; ++j) { - prevPar = par; - - if (propagator->Propagate(&par, fLayers[j].z, 13) == kLITERROR) break; - - scaltype x = par.GetX(); - scaltype y = par.GetY(); - timetype length = sqrt((par.GetX() - prevPar.GetX()) * (par.GetX() - prevPar.GetX()) - + (par.GetY() - prevPar.GetY()) * (par.GetY() - prevPar.GetY()) - + (par.GetZ() - prevPar.GetZ()) * (par.GetZ() - prevPar.GetZ())); - t += 1.e9 * length / speedOfLight; - scaltype sigmaXSq = par.GetCovariance(0); - scaltype sigmaYSq = par.GetCovariance(6); - TieHandlePoint pointHandler; - pointHandler.fFilter = filter; - pointHandler.fPar = par; - pointHandler.fZ = fLayers[j].z; - pointHandler.fChiSq = std::numeric_limits<litfloat>::max(); - pointHandler.fPoint = 0; - fLayers[j].Search(x, sigmaXSq, y, sigmaYSq, t, &pointHandler); - - if (pointHandler.fPoint) { - par = pointHandler.fOutPar; - trackChiSq += pointHandler.fChiSq; - PointData pd = {pointHandler.fPoint, j > 11}; - points.push_back(pd); - - if (firstTime) { - firstPar = par; - firstTime = false; - } - } - else - ++nofMissingHits; - - if (nofMissingHits > 4) break; - } - - if (points.empty()) continue; - - CbmMuchTrack* muchTrack = new ((*fMuchTracks)[muchTrackNo]) CbmMuchTrack(); - globalTrack->SetMuchTrackIndex(muchTrackNo++); - Int_t ndf = points.size() * 2 - 5; - muchTrack->SetChiSq(trackChiSq); - muchTrack->SetNDF(ndf < 1 ? 1 : ndf); - muchTrack->SetPreviousTrackId(stsTrack.fSelfId); - muchTrack->SetFlag(kLITGOOD); - FairTrackParam parLast, parFirst; - CbmLitConverterFairTrackParam::CbmLitTrackParamToFairTrackParam(&par, &parLast); - CbmLitConverterFairTrackParam::CbmLitTrackParamToFairTrackParam(&firstPar, &parFirst); - muchTrack->SetParamLast(&parLast); - muchTrack->SetParamFirst(&parFirst); - - for (list<PointData>::const_iterator j = points.begin(); j != points.end(); ++j) { - const PointData pd = *j; - muchTrack->AddHit(pd.point->refId, pd.isTrd ? kTRDHIT : kMUCHPIXELHIT); - } - } -} diff --git a/reco/tracking/lx/TBBinned/LxTBTieTracks.h b/reco/tracking/lx/TBBinned/LxTBTieTracks.h deleted file mode 100644 index fba9bd7fb5c5d953423a761dd16293e0071367ca..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/TBBinned/LxTBTieTracks.h +++ /dev/null @@ -1,199 +0,0 @@ -/* Copyright (C) 2016-2017 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifndef LXTBTIETRACKS_H -#define LXTBTIETRACKS_H - -#include "FairTrackParam.h" - -#include "LxTBBinned.h" -#include "LxTBDefinitions.h" - -class TClonesArray; - -struct LxTBBinndedLayer { - scaltype z; - int nofXBins; - int nofYBins; - int nofTBins; - int lastXBin; - int lastYBin; - int lastTBin; - scaltype minX; - scaltype maxX; - scaltype binSizeX; - scaltype minY; - scaltype maxY; - scaltype binSizeY; - timetype minT; - timetype maxT; - int binSizeT; - int timeSliceLength; - scaltype maxDx; - scaltype maxDy; - timetype maxDt; - LxTbTYXBin* tyxBins; - - LxTBBinndedLayer(int nofxb, int nofyb, int noftb, int bst) - : z() - , nofXBins(nofxb) - , nofYBins(nofyb) - , nofTBins(noftb) - , lastXBin(nofxb - 1) - , lastYBin(nofyb - 1) - , lastTBin(noftb - 1) - , minX() - , maxX() - , binSizeX() - , minY() - , maxY() - , binSizeY() - , minT(0) - , maxT(0) - , binSizeT(bst) - , timeSliceLength(nofTBins * binSizeT) - , maxDx(0) - , maxDy(0) - , maxDt(0) - , tyxBins(reinterpret_cast<LxTbTYXBin*>(new unsigned char[noftb * sizeof(LxTbTYXBin)])) - { - for (int i = 0; i < noftb; ++i) - new (&tyxBins[i]) LxTbTYXBin(nofXBins, nofYBins); - } - LxTBBinndedLayer(const LxTBBinndedLayer&) = delete; - LxTBBinndedLayer& operator=(const LxTBBinndedLayer&) = delete; - - ~LxTBBinndedLayer() { delete[] reinterpret_cast<unsigned char*>(tyxBins); } - - void Clear() - { - for (int i = 0; i < nofTBins; ++i) - tyxBins[i].Clear(); - } - - void Init() - { - binSizeX = (maxX - minX) / nofXBins; - binSizeY = (maxY - minY) / nofYBins; - } - - void SetTSBegin(unsigned long long tsLowBound) - { - minT = tsLowBound; - maxT = tsLowBound + timeSliceLength; - } - - struct PointHandler { - virtual ~PointHandler() {} - virtual void HandlePoint(const LxTbBinnedPoint& point) = 0; - }; - - void Search(scaltype x, scaltype xDiv0, scaltype y, scaltype yDiv0, timetype t, PointHandler* pointHandler) - { - scaltype wX = NOF_SIGMAS * std::sqrt(xDiv0 + maxDx * maxDx); - scaltype wY = NOF_SIGMAS * std::sqrt(yDiv0 + maxDy * maxDy); - timetype wT = NOF_SIGMAS * std::sqrt(2.0) * maxDt; - - if (x + wX < minX || x - wX > maxX || y + wY < minY || y - wY > maxY || t + wT < minT || t - wT > maxT) return; - - int tIndMin = (t - wT - minT) / binSizeT; - - if (tIndMin < 0) tIndMin = 0; - else if (tIndMin > lastTBin) - tIndMin = lastTBin; - - int tIndMax = (t + wT - minT) / binSizeT; - - if (tIndMax < 0) tIndMax = 0; - else if (tIndMax > lastTBin) - tIndMax = lastTBin; - - int yIndMin = (y - wY - minY) / binSizeY; - - if (yIndMin < 0) yIndMin = 0; - else if (yIndMin > lastYBin) - yIndMin = lastYBin; - - int yIndMax = (y + wY - minY) / binSizeY; - - if (yIndMax < 0) yIndMax = 0; - else if (yIndMax > lastYBin) - yIndMax = lastYBin; - - int xIndMin = (x - wX - minX) / binSizeX; - - if (xIndMin < 0) xIndMin = 0; - else if (xIndMin > lastXBin) - xIndMin = lastXBin; - - int xIndMax = (x + wX - minX) / binSizeX; - - if (xIndMax < 0) xIndMax = 0; - else if (xIndMax > lastXBin) - xIndMax = lastXBin; - - for (int tInd = tIndMin; tInd <= tIndMax; ++tInd) { - LxTbTYXBin& tyxBin = tyxBins[tInd]; - - for (int yInd = yIndMin; yInd <= yIndMax; ++yInd) { - LxTbYXBin& yxBin = tyxBin.yxBins[yInd]; - - for (int xInd = xIndMin; xInd <= xIndMax; ++xInd) { - LxTbXBin& xBin = yxBin.xBins[xInd]; - - for (std::list<LxTbBinnedPoint>::iterator i = xBin.points.begin(); i != xBin.points.end(); ++i) { - LxTbBinnedPoint& point = *i; - scaltype xDiv = xDiv0 + point.dx * point.dx; - scaltype wX_prec_sq = NOF_SIGMAS_SQ * xDiv; - scaltype yDiv = yDiv0 + point.dy * point.dy; - scaltype wY_prec_sq = NOF_SIGMAS_SQ * yDiv; - scaltype deltaX = point.x - x; - scaltype deltaXSq = deltaX * deltaX; - scaltype deltaY = point.y - y; - scaltype deltaYSq = deltaY * deltaY; - timetype deltaT = point.t - t; - timetype deltaTSq = deltaT * deltaT; - - if (deltaXSq < wX_prec_sq && deltaYSq < wY_prec_sq && deltaTSq < wT * wT) - //{ - //rPoint.neighbours.push_back(LxTbBinnedRay(deltaZ, rPoint, lPoint, deltaXSq / xDiv + - //deltaYSq / yDiv + deltaTSq / (rPoint.dt * rPoint.dt + lPoint.dt * lPoint.dt))); - pointHandler->HandlePoint(point); - //} - } - } - } - } - } -}; - -struct LxTBBinnedStsTrack { - FairTrackParam fPar; - Double_t fChiSq; - Double_t fTime; - Int_t fSelfId; - //Int_t fEventId; - //Int_t fFileId; -}; - -struct LxTBBinnedDetector { - LxTBBinndedLayer* fLayers; - int fNofLayers; - std::list<LxTBBinnedStsTrack> fStsTracks; - TClonesArray* fMuchTracks; - TClonesArray* fGlobalTracks; - - LxTBBinnedDetector(int nofl, int nofxb, int nofyb, int noftb, int binSizeT); - LxTBBinnedDetector(const LxTBBinnedDetector&) = delete; - LxTBBinnedDetector& operator=(const LxTBBinnedDetector&) = delete; - - void Init(); - void Clear(); - void SetTSBegin(unsigned long long tsLowBound); - void AddStsTrack(const FairTrackParam& par, Double_t chiSq, Double_t time, - Int_t selfId /*, Int_t eventId, Int_t fileId*/); - void TieTracks(LxTbBinnedFinder& fFinder); -}; - -#endif /* LXTBTIETRACKS_H */ diff --git a/reco/tracking/lx/TBBinned/LxTBTrdTask.cxx b/reco/tracking/lx/TBBinned/LxTBTrdTask.cxx deleted file mode 100644 index 65aa87d93ade6df92b8e0baa91d90acb378ecdd2..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/TBBinned/LxTBTrdTask.cxx +++ /dev/null @@ -1,678 +0,0 @@ -/* Copyright (C) 2016-2021 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -#include "LxTBTrdTask.h" - -#include "CbmCluster.h" -#include "CbmGlobalTrack.h" -#include "CbmMCDataManager.h" -#include "CbmMCTrack.h" -#include "CbmMatch.h" -#include "CbmTrdHit.h" -#include "CbmTrdPoint.h" -#include "CbmTrdTrack.h" - -#include <FairRootManager.h> -#include <Logger.h> - -#include "TClonesArray.h" -#include "TGeoBBox.h" -#include "TGeoManager.h" -#include "TH1F.h" -#include "TMath.h" -#include <TFile.h> - -#include "LxTBTask.h" - -using std::cout; -using std::endl; -using std::ifstream; -using std::ios_base; -using std::list; -using std::map; -using std::ofstream; -using std::pair; -using std::set; -using std::vector; - -ClassImp(LxTBTrdFinder) - - LxTBTrdFinder::LxTBTrdFinder() - : fFinder(nullptr) - , fTrigDistance(200) - , recoTracks() - , nof_timebins(5) - , last_timebin(nof_timebins - 1) - , fTrdHits(nullptr) - , fTrdClusters(nullptr) - , fTrdDigiMatches(nullptr) - , fTrdTracks(nullptr) - , fGlobalTracks(nullptr) -#ifdef LXTB_QA - , fTrdMCPoints(nullptr) - , fMCTracks() - , fTrdPoints() - , fNEvents(1000) -#endif //LXTB_QA -{ -} - -static void FindGeoChild(TGeoNode* node, const char* name, list<TGeoNode*>& results) -{ - Int_t nofChildren = node->GetNdaughters(); - - for (Int_t i = 0; i < nofChildren; ++i) { - TGeoNode* child = node->GetDaughter(i); - TString childName(child->GetName()); - - if (childName.Contains(name, TString::kIgnoreCase)) results.push_back(child); - } -} - -void LxTBTrdFinder::HandleGeometry() -{ - Double_t localCoords[3] = {0., 0., 0.}; - Double_t globalCoords[3]; - TGeoNavigator* pNavigator = gGeoManager->GetCurrentNavigator(); - gGeoManager->cd("/cave_1"); - list<TGeoNode*> detectors; - FindGeoChild(gGeoManager->GetCurrentNode(), "trd", detectors); - - for (list<TGeoNode*>::iterator i = detectors.begin(); i != detectors.end(); ++i) { - TGeoNode* detector = *i; - pNavigator->CdDown(detector); - list<TGeoNode*> layers; - FindGeoChild(detector, "layer", layers); - int layerNumber = 0; - - for (list<TGeoNode*>::iterator j = layers.begin(); j != layers.end(); ++j) { - TGeoNode* layer = *j; - pNavigator->CdDown(layer); - list<TGeoNode*> modules; - FindGeoChild(layer, "module", modules); - - for (list<TGeoNode*>::iterator k = modules.begin(); k != modules.end(); ++k) { - TGeoNode* module = *k; - pNavigator->CdDown(module); - list<TGeoNode*> padCoppers; - FindGeoChild(module, "padcopper", padCoppers); - - for (list<TGeoNode*>::iterator l = padCoppers.begin(); l != padCoppers.end(); ++l) { - TGeoNode* padCopper = *l; - pNavigator->CdDown(padCopper); - TGeoBBox* pBox = static_cast<TGeoBBox*>(padCopper->GetVolume()->GetShape()); - pBox->ComputeBBox(); - gGeoManager->LocalToMaster(localCoords, globalCoords); - fFinder->stations[layerNumber].z = globalCoords[2]; - - if (fFinder->stations[layerNumber].minY > globalCoords[1] - pBox->GetDY()) - fFinder->stations[layerNumber].minY = globalCoords[1] - pBox->GetDY(); - - if (fFinder->stations[layerNumber].maxY < globalCoords[1] + pBox->GetDY()) - fFinder->stations[layerNumber].maxY = globalCoords[1] + pBox->GetDY(); - - if (fFinder->stations[layerNumber].minX > globalCoords[0] - pBox->GetDX()) - fFinder->stations[layerNumber].minX = globalCoords[0] - pBox->GetDX(); - - if (fFinder->stations[layerNumber].maxX < globalCoords[0] + pBox->GetDX()) - fFinder->stations[layerNumber].maxX = globalCoords[0] + pBox->GetDX(); - - pNavigator->CdUp(); - } - - pNavigator->CdUp(); - } - - ++layerNumber; - pNavigator->CdUp(); - } - - pNavigator->CdUp(); - } -} - -static bool GetHistoRMS(const char* name, Double_t& retVal) -{ - size_t buf_size = 64; - char fileName[buf_size]; - snprintf(fileName, buf_size - 1, "%s.root", name); - bool result = false; - TFile* curFile = TFile::CurrentFile(); - - /// Save old global file and folder pointer to avoid messing with FairRoot - TFile* oldFile = gFile; - TDirectory* oldDir = gDirectory; - - TFile* f = new TFile(fileName); - - if (!f->IsZombie()) { - TH1F* h = f->Get<TH1F>(name); - retVal = h->GetRMS(); - result = true; - } - - delete f; - TFile::CurrentFile() = curFile; - - /// Restore old global file and folder pointer to avoid messing with FairRoot - gFile = oldFile; - gDirectory = oldDir; - - return result; -} - -static TH1F* signalDistanceHisto = 0; - -InitStatus LxTBTrdFinder::Init() -{ - signalDistanceHisto = new TH1F("signalDistanceHisto", "signalDistanceHisto", 200, 0., 800.); - speedOfLight = 100 * TMath::C(); // Multiply by 100 to express in centimeters. - nof_timebins = 5; // Corresponds to event by event mode. - pair<int, int> stSpatLimits[] = {{20, 20}, {20, 20}, {20, 20}, {20, 20}}; - fFinder = new LxTbBinnedFinder(0, CUR_NOF_STATIONS, nof_timebins, stSpatLimits, 20, 20, CUR_TIMEBIN_LENGTH); - fFinder->fHasTrd = false; - HandleGeometry(); - - for (int i = 0; i < 4; ++i) { - fFinder->stations[i].binSizeX = - (fFinder->stations[i].maxX - fFinder->stations[i].minX) / fFinder->stations[i].nofXBins; - fFinder->stations[i].binSizeY = - (fFinder->stations[i].maxY - fFinder->stations[i].minY) / fFinder->stations[i].nofYBins; - } - - for (int i = 1; i < 4; ++i) { - size_t buf_size = 64; - char name[buf_size]; - snprintf(name, buf_size - 1, "trdDeltaThetaX_%d", i); - Double_t deltaThetaX = 0; - - if (!GetHistoRMS(name, deltaThetaX)) return kFATAL; - - fFinder->stations[i].deltaThetaX = deltaThetaX; - snprintf(name, buf_size - 1, "trdDeltaThetaY_%d", i); - Double_t deltaThetaY = 0; - - if (!GetHistoRMS(name, deltaThetaY)) return kFATAL; - - fFinder->stations[i].deltaThetaY = deltaThetaY; - scaltype deltaZ = fFinder->stations[i].z - fFinder->stations[i - 1].z; - fFinder->stations[i].dispX = deltaThetaX * deltaZ; - fFinder->stations[i].dispY = deltaThetaY * deltaZ; - } - - FairRootManager* ioman = FairRootManager::Instance(); - - if (0 == ioman) LOG(fatal) << "No FairRootManager"; - - Int_t nofEventsInFile = ioman->CheckMaxEventNo(); - - if (nofEventsInFile < fNEvents) fNEvents = nofEventsInFile; - - fTrdHits = static_cast<TClonesArray*>(ioman->GetObject("TrdHit")); - - fTrdTracks = new TClonesArray("CbmTrdTrack", 100); - LOG(info) << "IsOutputBranchPersistent(TrdTrack) is: " << (IsOutputBranchPersistent("TrdTrack") ? "true" : "false"); - ioman->Register("TrdTrack", "Trd", fTrdTracks, IsOutputBranchPersistent("TrdTrack")); - - fGlobalTracks = new TClonesArray("CbmGlobalTrack", 100); - LOG(info) << "IsOutputBranchPersistent(GlobalTrack) is: " - << (IsOutputBranchPersistent("GlobalTrack") ? "true" : "false"); - ioman->Register("GlobalTrack", "Global", fGlobalTracks, IsOutputBranchPersistent("GlobalTrack")); - -#ifdef LXTB_QA - CbmMCDataManager* mcManager = static_cast<CbmMCDataManager*>(ioman->GetObject("MCDataManager")); - fTrdMCPoints = mcManager->InitBranch("TrdPoint"); - fTrdClusters = static_cast<TClonesArray*>(ioman->GetObject("TrdCluster")); - fTrdDigiMatches = static_cast<TClonesArray*>(ioman->GetObject("TrdDigiMatch")); - CbmMCDataArray* mcTracks = mcManager->InitBranch("MCTrack"); - - for (int i = 0; i < fNEvents; ++i) { - Int_t evSize = mcTracks->Size(0, i); - fMCTracks.push_back(vector<TrackDataHolder>()); - - if (0 >= evSize) continue; - - vector<TrackDataHolder>& evTracks = fMCTracks.back(); - - for (int j = 0; j < evSize; ++j) { - evTracks.push_back(TrackDataHolder()); - const CbmMCTrack* mcTrack = static_cast<const CbmMCTrack*>(mcTracks->Get(0, i, j)); - evTracks.back().pdg = mcTrack->GetPdgCode(); - evTracks.back().z = mcTrack->GetStartZ(); - - if (mcTrack->GetPdgCode() == 11 || mcTrack->GetPdgCode() == -11) { - //Double_t m = mcTrack->GetMass(); (VF) Unused - Int_t motherId = mcTrack->GetMotherId(); - - if (static_cast<const CbmMCTrack*>(mcTracks->Get(0, i, motherId))->GetPdgCode() == 443) - evTracks.back().isSignal = true; - } - } // for (int j = 0; j < evSize; ++j) - } // for (int i = 0; i < fNEvents; ++i) - - for (int i = 0; i < fNEvents; ++i) { - Int_t evSize = fTrdMCPoints->Size(0, i); - fTrdPoints.push_back(vector<PointDataHolder>()); - - if (0 >= evSize) continue; - - vector<PointDataHolder>& evPoints = fTrdPoints.back(); - - for (int j = 0; j < evSize; ++j) { - const CbmTrdPoint* pTrdPt = static_cast<const CbmTrdPoint*>(fTrdMCPoints->Get(0, i, j)); - //Int_t trackId = pTrdPt->GetTrackID(); (VF) Unused - Int_t layerNumber = CbmTrdAddress::GetLayerId(pTrdPt->GetModuleAddress()); - PointDataHolder trdPt; - trdPt.x = (pTrdPt->GetXIn() + pTrdPt->GetXOut()) / 2; - trdPt.y = (pTrdPt->GetYIn() + pTrdPt->GetYOut()) / 2; - trdPt.z = (pTrdPt->GetZIn() + pTrdPt->GetZOut()) / 2; - trdPt.t = 0; //fEventTimes[i] + pTrdPt->GetTime(); - trdPt.eventId = i; - trdPt.trackId = pTrdPt->GetTrackID(); - trdPt.pointId = j; - trdPt.layerNumber = layerNumber; - evPoints.push_back(trdPt); - fMCTracks[trdPt.eventId][trdPt.trackId].pointInds[trdPt.layerNumber] = trdPt.pointId; - } - } - - int eventId = 0; - - for (vector<vector<TrackDataHolder>>::iterator i = fMCTracks.begin(); i != fMCTracks.end(); ++i) { - vector<TrackDataHolder>& evTracks = *i; - list<TrackDataHolder*> eles; - list<TrackDataHolder*> poss; - - for (vector<TrackDataHolder>::iterator j = evTracks.begin(); j != evTracks.end(); ++j) { - TrackDataHolder& track = *j; - - if (11 == track.pdg && 15 > track.z) { - bool use = true; - - for (int k = 0; k < CUR_NOF_STATIONS; ++k) { - if (track.pointInds[k] < 0) { - use = false; - break; - } - } - - if (use) eles.push_back(&track); - } - else if (-11 == track.pdg && 15 > track.z) { - bool use = true; - - for (int k = 0; k < CUR_NOF_STATIONS; ++k) { - if (track.pointInds[k] < 0) { - use = false; - break; - } - } - - if (use) poss.push_back(&track); - } - - if (!track.isSignal) continue; - - /*if (11 == track.pdg) - negTrack = &track; - else - posTrack = &track;*/ - - for (int k = 0; k < CUR_NOF_STATIONS; ++k) { - if (track.pointInds[k] < 0) { - track.isSignal = false; - break; - } - } - - /*if (track.isSignal) - { - if (11 == track.pdg) - negTrack = &track; - else - posTrack = &track; - }*/ - } - - /*if (0 != posTrack && 0 != negTrack && posTrack->pointInds[0] >= 0 && negTrack->pointInds[0] >= 0) - { - const PointDataHolder& posPt = fTrdPoints[eventId][posTrack->pointInds[0]]; - const PointDataHolder& negPt = fTrdPoints[eventId][negTrack->pointInds[0]]; - signalDistanceHisto->Fill(sqrt((posPt.x - negPt.x) * (posPt.x - negPt.x) + (posPt.y - negPt.y) * (posPt.y - negPt.y))); - }*/ - - for (list<TrackDataHolder*>::const_iterator k = eles.begin(); k != eles.end(); ++k) { - const TrackDataHolder* negTrack = *k; - - for (list<TrackDataHolder*>::const_iterator l = poss.begin(); l != poss.end(); ++l) { - const TrackDataHolder* posTrack = *l; - const PointDataHolder& posPt = fTrdPoints[eventId][posTrack->pointInds[0]]; - const PointDataHolder& negPt = fTrdPoints[eventId][negTrack->pointInds[0]]; - signalDistanceHisto->Fill( - sqrt((posPt.x - negPt.x) * (posPt.x - negPt.x) + (posPt.y - negPt.y) * (posPt.y - negPt.y))); - } - } - - ++eventId; - } -#endif //LXTB_QA - - return kSUCCESS; //, kERROR, kFATAL -} - -static Int_t currentEventN = 0; -static unsigned long long tsStartTime = 0; - -static void SpliceTriggerings(list<pair<timetype, timetype>>& out, LxTbBinnedFinder::TriggerTimeArray& in) -{ - for (int i = 0; i < in.nofTimebins; ++i) - out.splice(out.end(), in.triggerTimeBins[i]); -} - -#ifdef LXTB_QA -static list<pair<timetype, timetype>> triggerTimes_trd0_sign0_dist0; -static list<pair<timetype, timetype>> triggerTimes_trd0_sign0_dist1; -static list<pair<timetype, timetype>> triggerTimes_trd0_sign1_dist0; -static list<pair<timetype, timetype>> triggerTimes_trd0_sign1_dist1; -static list<pair<timetype, timetype>> triggerTimes_trd1_sign0_dist0; -static list<pair<timetype, timetype>> triggerTimes_trd1_sign0_dist1; -static list<pair<timetype, timetype>> triggerTimes_trd1_sign1_dist0; -static list<pair<timetype, timetype>> triggerTimes_trd1_sign1_dist1; -static scaltype gMaxDx = 0; -static scaltype gMaxDy = 0; -#endif //LXTB_QA - -void LxTBTrdFinder::Exec(Option_t*) -{ - fFinder->Clear(); - fFinder->SetTSBegin(tsStartTime); - - for (int i = 0; i < fTrdHits->GetEntriesFast(); ++i) { - const CbmTrdHit* hit = static_cast<const CbmTrdHit*>(fTrdHits->At(i)); - Int_t stationNumber = hit->GetPlaneId(); - scaltype x = hit->GetX(); - scaltype y = hit->GetY(); - timetype t = tsStartTime + 50; //hit->GetTime(); - scaltype dx = hit->GetDx(); - - if (gMaxDx < dx) gMaxDx = dx; - - scaltype dy = hit->GetDy(); - - if (gMaxDy < dy) gMaxDy = dy; - - timetype dt = 4; //hit->GetTimeError(); - LxTbBinnedPoint point(x, dx, y, dy, t, dt, i, CUR_LAST_STATION == stationNumber); -#ifdef LXTB_QA - point.isTrd = true; - point.stationNumber = stationNumber; - Int_t clusterId = hit->GetRefId(); - const CbmCluster* cluster = static_cast<const CbmCluster*>(fTrdClusters->At(clusterId)); - Int_t nDigis = cluster->GetNofDigis(); - - for (Int_t j = 0; j < nDigis; ++j) { - const CbmMatch* digiMatch = static_cast<const CbmMatch*>(fTrdDigiMatches->At(cluster->GetDigi(j))); - Int_t nMCs = digiMatch->GetNofLinks(); - - for (Int_t k = 0; k < nMCs; ++k) { - const CbmLink& lnk = digiMatch->GetLink(k); - Int_t eventId = currentEventN; // : lnk.GetEntry(); - Int_t pointId = lnk.GetIndex(); - const FairMCPoint* pMCPt = static_cast<const FairMCPoint*>(fTrdMCPoints->Get(0, eventId, pointId)); - Int_t trackId = pMCPt->GetTrackID(); - LxTbBinnedPoint::PointDesc ptDesc = {eventId, pointId, trackId}; - point.mcRefs.push_back(ptDesc); - } - } // for (Int_t j = 0; j < nDigis; ++j) - - scaltype minY = fFinder->stations[stationNumber].minY; - scaltype binSizeY = fFinder->stations[stationNumber].binSizeY; - int lastYBin = fFinder->stations[stationNumber].lastYBin; - scaltype minX = fFinder->stations[stationNumber].minX; - scaltype binSizeX = fFinder->stations[stationNumber].binSizeX; - int lastXBin = fFinder->stations[stationNumber].lastXBin; - - int tInd = (t - fFinder->minT) / CUR_TIMEBIN_LENGTH; - - if (tInd < 0) tInd = 0; - else if (tInd > int(last_timebin)) - tInd = last_timebin; - - LxTbTYXBin& tyxBin = fFinder->stations[stationNumber].tyxBins[tInd]; - int yInd = (y - minY) / binSizeY; - - if (yInd < 0) yInd = 0; - else if (yInd > lastYBin) - yInd = lastYBin; - - LxTbYXBin& yxBin = tyxBin.yxBins[yInd]; - int xInd = (x - minX) / binSizeX; - - if (xInd < 0) xInd = 0; - else if (xInd > lastXBin) - xInd = lastXBin; - - LxTbXBin& xBin = yxBin.xBins[xInd]; - xBin.points.push_back(point); - - if (CUR_LAST_STATION == stationNumber) { - xBin.use = true; - yxBin.use = true; - tyxBin.use = true; - } -#endif //LXTB_QA - } - - fFinder->Reconstruct(); - - //recoTracks.clear(); - fTrdTracks->Delete(); - fGlobalTracks->Clear(); - int trdTrackNo = 0; - - for (int i = 0; i < fFinder->nofTrackBins; ++i) { - list<LxTbBinnedFinder::Chain*>& recoTracksBin = fFinder->recoTracks[i]; - - for (list<LxTbBinnedFinder::Chain*>::const_iterator j = recoTracksBin.begin(); j != recoTracksBin.end(); ++j) { - LxTbBinnedFinder::Chain* chain = *j; - recoTracks.push_back(chain); - - CbmTrdTrack* track = new ((*fTrdTracks)[trdTrackNo]) CbmTrdTrack(); - - for (int k = 0; k < chain->nofPoints; ++k) - track->AddHit(chain->points[k]->refId, kTRDHIT); - - track->SetChiSq(chain->chi2); - track->SetNDF(2 * chain->nofPoints - 5); - - CbmGlobalTrack* globalTrack = new ((*fGlobalTracks)[trdTrackNo]) CbmGlobalTrack(); - globalTrack->SetTrdTrackIndex(trdTrackNo); - ++trdTrackNo; - } - } - - //cout << "In the event #: " << currentEventN << " " << recoTracks.size() << " reconstructed" << endl; - - SpliceTriggerings(triggerTimes_trd0_sign0_dist0, fFinder->triggerTimes_trd0_sign0_dist0); - SpliceTriggerings(triggerTimes_trd0_sign0_dist1, fFinder->triggerTimes_trd0_sign0_dist1); - SpliceTriggerings(triggerTimes_trd0_sign1_dist0, fFinder->triggerTimes_trd0_sign1_dist0); - SpliceTriggerings(triggerTimes_trd0_sign1_dist1, fFinder->triggerTimes_trd0_sign1_dist1); - SpliceTriggerings(triggerTimes_trd1_sign0_dist0, fFinder->triggerTimes_trd1_sign0_dist0); - SpliceTriggerings(triggerTimes_trd1_sign0_dist1, fFinder->triggerTimes_trd1_sign0_dist1); - SpliceTriggerings(triggerTimes_trd1_sign1_dist0, fFinder->triggerTimes_trd1_sign1_dist0); - SpliceTriggerings(triggerTimes_trd1_sign1_dist1, fFinder->triggerTimes_trd1_sign1_dist1); - - ++currentEventN; - tsStartTime += CUR_TIMEBIN_LENGTH; -} - -struct RecoTrackData { - Int_t eventId; - Int_t trackId; - - RecoTrackData(Int_t eId, Int_t tId) : eventId(eId), trackId(tId) {} -}; - -struct RTDLess { - bool operator()(const RecoTrackData& x, const RecoTrackData& y) const - { - if (x.eventId < y.eventId) return true; - - return x.trackId < y.trackId; - } -}; - -static void SaveHisto(TH1* histo) -{ - TFile* curFile = TFile::CurrentFile(); - TString histoName = histo->GetName(); - histoName += ".root"; - TFile fh(histoName.Data(), "RECREATE"); - histo->Write(); - fh.Close(); - delete histo; - TFile::CurrentFile() = curFile; -} - -void LxTBTrdFinder::Finish() -{ - int nofRecoTracks = recoTracks.size(); - cout << "LxTbBinnedFinder::Reconstruct() the number of found tracks: " << nofRecoTracks << endl; -#ifdef LXTB_QA - static int nofSignalTracks = 0; - static int nofRecoSignalTracks = 0; - int eventN = 0; - - for (vector<vector<TrackDataHolder>>::iterator i = fMCTracks.begin(); i != fMCTracks.end(); ++i) { - vector<TrackDataHolder>& evTracks = *i; - - for (vector<TrackDataHolder>::iterator j = evTracks.begin(); j != evTracks.end(); ++j) { - TrackDataHolder& track = *j; - - if (!track.isSignal) continue; - - ++nofSignalTracks; - - int nofMatchPoints = 0; - - for (list<LxTbBinnedFinder::Chain*>::const_iterator k = recoTracks.begin(); k != recoTracks.end(); ++k) { - const LxTbBinnedFinder::Chain* chain = *k; - - for (int l = 0; l < CUR_NOF_STATIONS; ++l) { - bool pointsMatched = false; - - for (list<LxTbBinnedPoint::PointDesc>::const_iterator m = chain->points[l]->mcRefs.begin(); - m != chain->points[l]->mcRefs.end(); ++m) { - if (m->eventId == eventN && m->pointId == track.pointInds[l]) { - pointsMatched = true; - break; - } - } - - if (pointsMatched) ++nofMatchPoints; - } - } - - if (nofMatchPoints >= CUR_NOF_STATIONS - 1) { - ++nofRecoSignalTracks; - continue; - } - } - - ++eventN; - } - - double eff = 0 == nofSignalTracks ? 100 : 100.0 * nofRecoSignalTracks / nofSignalTracks; - cout << "Reconstruction efficiency is: " << eff << "% [ " << nofRecoSignalTracks << " / " << nofSignalTracks << " ]" - << endl; - - int nofRightRecoTracks = 0; - map<Int_t, pair<list<LxTbBinnedPoint*>, list<LxTbBinnedPoint*>>> elecPositrons; - - for (list<LxTbBinnedFinder::Chain*>::const_iterator i = recoTracks.begin(); i != recoTracks.end(); ++i) { - const LxTbBinnedFinder::Chain* chain = *i; - map<RecoTrackData, int, RTDLess> nofTracks; - - for (int j = 0; j < CUR_NOF_STATIONS; ++j) { - int stMask = 1 << j; - - for (list<LxTbBinnedPoint::PointDesc>::const_iterator k = chain->points[j]->mcRefs.begin(); - k != chain->points[j]->mcRefs.end(); ++k) { - RecoTrackData st(k->eventId, k->trackId); - map<RecoTrackData, int, RTDLess>::iterator nofTIter = nofTracks.find(st); - - if (nofTIter != nofTracks.end()) nofTIter->second |= stMask; - else - nofTracks[st] = stMask; - } - } - - int nofPoints = 0; - const RecoTrackData* bestMCTrack = 0; - - for (map<RecoTrackData, int, RTDLess>::const_iterator j = nofTracks.begin(); j != nofTracks.end(); ++j) { - int nofp = 0; - - for (int k = 0; k < CUR_NOF_STATIONS; ++k) { - if (j->second & (1 << k)) ++nofp; - } - - if (nofp > nofPoints) { - nofPoints = nofp; - bestMCTrack = &j->first; - } - } - - if (nofPoints >= CUR_NOF_STATIONS - 1) { - ++nofRightRecoTracks; - - //if (35 > fMCTracks[bestMCTrack->eventId][bestMCTrack->trackId].z) - { - if (11 == fMCTracks[bestMCTrack->eventId][bestMCTrack->trackId].pdg) - elecPositrons[bestMCTrack->eventId].first.push_back(chain->points[0]); - else if (-11 == fMCTracks[bestMCTrack->eventId][bestMCTrack->trackId].pdg) - elecPositrons[bestMCTrack->eventId].second.push_back(chain->points[0]); - } - } - } - - eff = 0 == recoTracks.size() ? 100 : 100.0 * nofRightRecoTracks / nofRecoTracks; - cout << "Non ghosts are: " << eff << "% [ " << nofRightRecoTracks << " / " << nofRecoTracks << " ]" << endl; - - int nofTriggPairs = 0; - - for (map<Int_t, pair<list<LxTbBinnedPoint*>, list<LxTbBinnedPoint*>>>::iterator i = elecPositrons.begin(); - i != elecPositrons.end(); ++i) { - list<LxTbBinnedPoint*>& evEls = i->second.first; - list<LxTbBinnedPoint*>& evPos = i->second.second; - bool trigPair = false; - - for (list<LxTbBinnedPoint*>::const_iterator j = evEls.begin(); j != evEls.end(); ++j) { - const LxTbBinnedPoint* elp = *j; - scaltype negX = elp->x; - scaltype negY = elp->y; - - for (list<LxTbBinnedPoint*>::const_iterator k = evPos.begin(); k != evPos.end(); ++k) { - const LxTbBinnedPoint* pop = *k; - scaltype posX = pop->x; - scaltype posY = pop->y; - - if (sqrt((posX - negX) * (posX - negX) + (posY - negY) * (posY - negY)) > fTrigDistance) trigPair = true; - } - } - - if (trigPair) ++nofTriggPairs; - } - - cout << "NOF triggering events: " << nofTriggPairs << endl; - - SaveHisto(signalDistanceHisto); -#endif //LXTB_QA -} diff --git a/reco/tracking/lx/TBBinned/LxTBTrdTask.h b/reco/tracking/lx/TBBinned/LxTBTrdTask.h deleted file mode 100644 index 73d9a650582dd165f25766a890fc577f0cc53258..0000000000000000000000000000000000000000 --- a/reco/tracking/lx/TBBinned/LxTBTrdTask.h +++ /dev/null @@ -1,83 +0,0 @@ -/* Copyright (C) 2016-2017 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifndef LXTBTRDTASK_H -#define LXTBTRDTASK_H - -#include "CbmMCDataArray.h" - -#include "FairTask.h" - -#include "LxTBBinned.h" - -#define CUR_TIMEBIN_LENGTH 100 -#define CUR_NOF_STATIONS 4 -#define CUR_LAST_STATION CUR_NOF_STATIONS - 1 - -class LxTBTrdFinder : public FairTask { -public: -#ifdef LXTB_QA - struct TrackDataHolder { - Int_t pointInds[CUR_NOF_STATIONS]; - bool isSignal; - Int_t pdg; - Double_t z; - - TrackDataHolder() : isSignal(false), pdg(-1), z(0) - { - for (int i = 0; i < CUR_NOF_STATIONS; ++i) - pointInds[i] = -1; - } - }; - - struct PointDataHolder { - Double_t x; - Double_t y; - Double_t z; - Double_t t; - Int_t eventId; - Int_t trackId; - Int_t pointId; - Int_t layerNumber; - }; -#endif //LXTB_QA - -public: - LxTBTrdFinder(); - LxTBTrdFinder(const LxTBTrdFinder&) = delete; - LxTBTrdFinder& operator=(const LxTBTrdFinder&) = delete; - - InitStatus Init(); // Overridden from FairTask - void Exec(Option_t* opt); // Overridden from FairTask - void Finish(); // Overridden from FairTask - - void SetTrigDistance(Double_t v) { fTrigDistance = v; } - -#ifdef LXTB_QA - void SetNEvents(Int_t v) { fNEvents = v; } -#endif //LXTB_QA - -private: - void HandleGeometry(); - LxTbBinnedFinder* fFinder; - Double_t fTrigDistance; - std::list<LxTbBinnedFinder::Chain*> recoTracks; - unsigned int nof_timebins; - unsigned int last_timebin; - TClonesArray* fTrdHits; - TClonesArray* fTrdClusters; - TClonesArray* fTrdDigiMatches; - TClonesArray* fTrdTracks; - TClonesArray* fGlobalTracks; -#ifdef LXTB_QA - CbmMCDataArray* fTrdMCPoints; - std::vector<std::vector<TrackDataHolder>> fMCTracks; - std::vector<std::vector<PointDataHolder>> fTrdPoints; - Int_t fNEvents; -#endif //LXTB_QA - - ClassDef(LxTBTrdFinder, 1) -}; - -#endif /* LXTBTRDTASK_H */ diff --git a/reco/tracking/lxTriplet/CMakeLists.txt b/reco/tracking/lxTriplet/CMakeLists.txt deleted file mode 100644 index e0599c6c9e7cb3020b828c49354d3f0ee8b86ef5..0000000000000000000000000000000000000000 --- a/reco/tracking/lxTriplet/CMakeLists.txt +++ /dev/null @@ -1,56 +0,0 @@ -# Create a library called "libLxTrack" which includes the source files given in -# the array . -# The extension is already found. Any number of sources could be listed -# here. - -Set(INCLUDE_DIRECTORIES - ${BASE_INCLUDE_DIRECTORIES} - ${CBMROOT_SOURCE_DIR}/tracking/lxTriplet - ${CBMBASE_DIR} - ${CBMDATA_DIR} - ${CBMDATA_DIR}/much - ${CBMDATA_DIR}/sts - ${CBMDATA_DIR}/global - ${CBMROOT_SOURCE_DIR}/KF - ${CBMROOT_SOURCE_DIR}/KF/Interface - ${CBMROOT_SOURCE_DIR}/sts - ${CBMROOT_SOURCE_DIR}/littrack/std - ${CBMROOT_SOURCE_DIR}/littrack/cbm -) - -Include_Directories( ${INCLUDE_DIRECTORIES}) - -Set(SYSTEM_INCLUDE_DIRECTORIES - ${Boost_INCLUDE_DIRS} -) - -Include_Directories(SYSTEM ${SYSTEM_INCLUDE_DIRECTORIES}) - -Set(LINK_DIRECTORIES - ${ROOT_LIBRARY_DIR} - ${FAIRROOT_LIBRARY_DIR} - ${Boost_LIBRARY_DIRS} -) - -Link_Directories( ${LINK_DIRECTORIES}) - -Set(SRCS - Lx.cxx - LxTrackAna.cxx -) - -Set(NO_DICT_SRCS - LxCATriplets.cxx - LxEff.cxx - LxMC.cxx - LxTrackAnaSegments.cxx - LxUtils.cxx -) - -set(LINKDEF LxLinkDef.h) -Set(LIBRARY_NAME LxTrackTripplet) -Set(DEPENDENCIES - CbmBase CbmData Base boost_regex -) - -GENERATE_LIBRARY() diff --git a/reco/tracking/lxTriplet/Lx.cxx b/reco/tracking/lxTriplet/Lx.cxx deleted file mode 100644 index 9ff40f9c6e941cb44cf2fc7f6515f12b1f4e80f9..0000000000000000000000000000000000000000 --- a/reco/tracking/lxTriplet/Lx.cxx +++ /dev/null @@ -1,1153 +0,0 @@ -/* Copyright (C) 2016-2021 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#include "Lx.h" - -#include "CbmKFTrack.h" -#include "CbmMCTrack.h" -#include "CbmMuchCluster.h" -#include "CbmMuchDigiMatch.h" -#include "CbmMuchGeoScheme.h" -#include "CbmMuchPoint.h" -#include "CbmMuchTrack.h" -#include "CbmStsAddress.h" -#include "CbmStsPoint.h" -#include "LxDraw.h" -#include "TDatabasePDG.h" -#include "TGeoManager.h" - -#include <iostream> - -#include <sys/time.h> - -ClassImp(LxFinderTriplet) - - using namespace std; - -LxFinderTriplet* LxFinderTriplet::fInstance = 0; -TH1F* LxFinderTriplet::massHisto = 0; -//TH1F* LxFinderTriplet::backgroundMassHisto = 0; -CbmStsTrack* LxFinderTriplet::superEventData = 0; -TTree* LxFinderTriplet::superEventTracks = 0; -TH1F* LxFinderTriplet::signalChi2Histo = 0; -TH1F* LxFinderTriplet::backgroundChi2Histo = 0; -TH1F* LxFinderTriplet::unknownChi2Histo = 0; -TProfile* LxFinderTriplet::effByMomentumProfile = 0; -TH1F* LxFinderTriplet::signalInterTracksDistance = 0; -TH1F* LxFinderTriplet::bgrInterTracksDistance = 0; -TH1F* LxFinderTriplet::signalSignDefect = 0; -TH1F* LxFinderTriplet::bgrSignDefect = 0; -TH1F* LxFinderTriplet::signalYAtZ0 = 0; -TH1F* LxFinderTriplet::bgrYAtZ0 = 0; -TH1F* LxFinderTriplet::signalYAtZ0_2 = 0; -TH1F* LxFinderTriplet::bgrYAtZ0_2 = 0; - -#ifdef MAKE_DISPERSE_2D_HISTOS -TProfile2D* disperseLHistos[LXSTATIONS]; -TProfile2D* disperseRHistos[LXSTATIONS]; -TProfile2D* disperseDHistos[LXSTATIONS]; -#endif //MAKE_DISPERSE_2D_HISTOS - -static TH1F* stsTrackChi2 = 0; -static TH1F* stsTrackX = 0; -static TH1F* stsTrackY = 0; - -LxFinderTriplet* LxFinderTriplet::Instance() { return fInstance; } - -std::list<CbmStsTrack> positiveTracks; -std::list<CbmStsTrack> negativeTracks; -bool generateInvMass; -bool generateBackground; -bool generateChi2; -bool linkWithSts; -bool useMCPInsteadOfHits; -bool calcMiddlePoints; -Double_t cutCoeff; -bool pPtCut; -std::vector<LxMCPoint> MCPoints; // Points should lay here in the same order as in listMuchPts. -std::vector<LxMCTrack> MCTracks; // Tracks should lay here in the same order as in listMCTracks. -std::list<LxStsMCPoint> MCStsPoints; -std::list<LxStsMCPoint*> MCStsPointsByStations[8]; -#ifdef MAKE_DISPERSE_2D_HISTOS -std::list<LxMCPoint*> MCPointsByStations[LXSTATIONS][LXLAYERS]; -Double_t zCoordsByStations[LXSTATIONS][LXLAYERS]; -#endif //MAKE_DISPERSE_2D_HISTOS -LxSpace caSpace; -std::map<Int_t, std::map<Int_t, int>> particleCounts; -#ifdef MAKE_EFF_CALC -std::ofstream incomplete_events; // Events where not all tracks are reconstructed. -#endif //MAKE_EFF_CALC -Int_t eventNumber; -#ifdef CALC_MUCH_DETECTORS_EFF -Int_t mcPointsCount; -Int_t mcPointsTriggered; -#endif //CALC_MUCH_DETECTORS_EFF - - -LxFinderTriplet::LxFinderTriplet() - : muchPixelHits(0) - , listMCTracks(0) - , listMuchPts(0) - , listMuchClusters(0) - , listMuchPixelDigiMatches(0) - , listStsTracks(0) - , listStsMatches(0) - , listStsPts(0) - , listRecoTracks(0) - , effCounter(*this) - , extFitter() - , fPrimVtx(0) - , positiveTracks() - , negativeTracks() - , generateInvMass(false) - , generateBackground(false) - , generateChi2(false) - , linkWithSts(true) - , useMCPInsteadOfHits(false) - , calcMiddlePoints(true) - , cutCoeff(4.0) - , pPtCut(true) - , MCPoints() - , MCTracks() - , MCStsPoints() - , MCStsPointsByStations() -#ifdef MAKE_DISPERSE_2D_HISTOS - , MCPointsByStations() - , zCoordsByStations() -#endif //MAKE_DISPERSE_2D_HISTOS - , caSpace() - , particleCounts() -#ifdef MAKE_EFF_CALC - , incomplete_events() -#endif //MAKE_EFF_CALC - , eventNumber(0) -#ifdef CALC_MUCH_DETECTORS_EFF - , mcPointsCount(0) - , mcPointsTriggered(0) -#endif //CALC_MUCH_DETECTORS_EFF -{ - fInstance = this; -} - -LxFinderTriplet::~LxFinderTriplet() {} - -TString lxFinderParticleType = "jpsi"; - -static bool GetHistoRMS(const char* histoNameBase, Int_t histoNumber, Double_t& retVal) -{ - char name[256]; - char dir_name[256]; - sprintf(dir_name, "configuration.%s", lxFinderParticleType.Data()); - bool result = false; - sprintf(name, "%s/%s_%d.root", dir_name, histoNameBase, histoNumber); - TFile* curFile = TFile::CurrentFile(); - - /// Save old global file and folder pointer to avoid messing with FairRoot - TFile* oldFile = gFile; - TDirectory* oldDir = gDirectory; - - TFile* f = new TFile(name); - - if (!f->IsZombie()) { - sprintf(name, "%s_%d", histoNameBase, histoNumber); - TH1F* h = f->Get<TH1F>(name); - retVal = h->GetRMS(); - result = true; - } - - delete f; - TFile::CurrentFile() = curFile; - - /// Restore old global file and folder pointer to avoid messing with FairRoot - gFile = oldFile; - gDirectory = oldDir; - - return result; -} - -static bool GetHistoCOV(const char* histoNameBase, Int_t histoNumber, Int_t axis1, Int_t axis2, Double_t& retVal) -{ - char name[256]; - bool result = false; - sprintf(name, "configuration/%s_%d.root", histoNameBase, histoNumber); - TFile* curFile = TFile::CurrentFile(); - - /// Save old global file and folder pointer to avoid messing with FairRoot - TFile* oldFile = gFile; - TDirectory* oldDir = gDirectory; - - TFile* f = new TFile(name); - - if (!f->IsZombie()) { - sprintf(name, "%s_%d", histoNameBase, histoNumber); - TH2F* h = f->Get<TH2F>(name); - retVal = h->GetCovariance(axis1, axis2); - result = true; - } - - delete f; - TFile::CurrentFile() = curFile; - - /// Restore old global file and folder pointer to avoid messing with FairRoot - gFile = oldFile; - gDirectory = oldDir; - - return result; -} - -InitStatus LxFinderTriplet::Init() -{ - static Int_t nTimes = 1; - cout << "LxFinderTriplet::Init() called at " << nTimes++ << " time" << endl; - - superEventData = new CbmStsTrack; - - FairRootManager* fManager = FairRootManager::Instance(); - - muchPixelHits = LX_DYNAMIC_CAST<TClonesArray*>(fManager->GetObject("MuchPixelHit")); - listMCTracks = LX_DYNAMIC_CAST<TClonesArray*>(fManager->GetObject("MCTrack")); - listMuchPts = LX_DYNAMIC_CAST<TClonesArray*>(fManager->GetObject("MuchPoint")); - listMuchClusters = LX_DYNAMIC_CAST<TClonesArray*>(fManager->GetObject("MuchCluster")); - listMuchPixelDigiMatches = LX_DYNAMIC_CAST<TClonesArray*>(fManager->GetObject("MuchDigiMatch")); - listStsTracks = LX_DYNAMIC_CAST<TClonesArray*>(fManager->GetObject("StsTrack")); - listStsMatches = LX_DYNAMIC_CAST<TClonesArray*>(fManager->GetObject("StsTrackMatch")); - listStsPts = LX_DYNAMIC_CAST<TClonesArray*>(fManager->GetObject("StsPoint")); - //fPrimVtx = LX_DYNAMIC_CAST<CbmVertex*> (fManager->GetObject("PrimaryVertex")); - /* - // Get pointer to PrimaryVertex object from IOManager if it exists - // The old name for the object is "PrimaryVertex" the new one - // "PrimaryVertex." Check first for the new name - fPrimVtx = LX_DYNAMIC_CAST<CbmVertex*>(fManager->GetObject("PrimaryVertex.")); - if (nullptr == fPrimVtx) { - fPrimVtx = LX_DYNAMIC_CAST<CbmVertex*>(fManager->GetObject("PrimaryVertex")); - } - if (nullptr == fPrimVtx) { - Error("CbmL1SttTrackFinder::ReInit","vertex not found!"); - return kERROR; - } - */ - fPrimVtx = new CbmVertex; - - // Read Z-positions of MUCH station layers and save them in LxLayer objects. - - for (Int_t i = 0; i < LXSTATIONS; ++i) { - LxStation* aStation = caSpace.stations[i]; - - for (Int_t j = 0; j < LXLAYERS; ++j) { - TString muchStLrPath = Form("/cave_1/much_0/muchstation%02i_0/muchstation%02ilayer%01i_0", i + 1, i + 1, j + 1); - gGeoManager->cd(muchStLrPath.Data()); - Double_t localCoords[3] = {0., 0., 0.}; - Double_t globalCoords[3]; - gGeoManager->LocalToMaster(localCoords, globalCoords); - aStation->layers[j]->zCoord = globalCoords[2]; -#ifdef MAKE_DISPERSE_2D_HISTOS - zCoordsByStations[i][j] = globalCoords[2]; -#endif //MAKE_DISPERSE_2D_HISTOS - } - - aStation->zCoord = aStation->layers[LXMIDDLE]->zCoord; - - bool readHistoResult = true; - - readHistoResult &= GetHistoRMS("muchInStationXDispLeft", i, aStation->xDispLeft); - aStation->xDispLeft2 = aStation->xDispLeft * aStation->xDispLeft; - readHistoResult &= GetHistoRMS("muchInStationYDispLeft", i, aStation->yDispLeft); - aStation->yDispLeft2 = aStation->yDispLeft * aStation->yDispLeft; - readHistoResult &= GetHistoRMS("muchInStationXDispRight", i, aStation->xDispRight); - aStation->xDispRight2 = aStation->xDispRight * aStation->xDispRight; - readHistoResult &= GetHistoRMS("muchInStationYDispRight", i, aStation->yDispRight); - aStation->yDispRight2 = aStation->yDispRight * aStation->yDispRight; - readHistoResult &= GetHistoRMS("muchInStationXDispRL", i, aStation->xDispRL); - aStation->xDispRL2 = aStation->xDispRL * aStation->xDispRL; - readHistoResult &= GetHistoRMS("muchInStationYDispRL", i, aStation->yDispRL); - aStation->yDispRL2 = aStation->yDispRL * aStation->yDispRL; - - if (i > 0) { -#ifdef OUT_DISP_BY_TRIPLET_DIR - readHistoResult &= GetHistoRMS("muchOutStationXDispByTriplet", i, aStation->xOutDispTriplet); - aStation->xOutDispTriplet2 = aStation->xOutDispTriplet * aStation->xOutDispTriplet; - readHistoResult &= GetHistoRMS("muchOutStationYDispByTriplet", i, aStation->yOutDispTriplet); - aStation->yOutDispTriplet2 = aStation->yOutDispTriplet * aStation->yOutDispTriplet; -#else //OUT_DISP_BY_TRIPLET_DIR - readHistoResult &= GetHistoRMS("muchOutStationXDispByVertex", i, aStation->xOutDispVertex); - aStation->xOutDispVertex2 = aStation->xOutDispVertex * aStation->xOutDispVertex; - readHistoResult &= GetHistoRMS("muchOutStationYDispByVertex", i, aStation->yOutDispVertex); - aStation->yOutDispVertex2 = aStation->yOutDispVertex * aStation->yOutDispVertex; -#endif //OUT_DISP_BY_TRIPLET_DIR - -#ifdef USE_SEGMENTS - LxStation* anLStation = caSpace.stations[i - 1]; - readHistoResult &= GetHistoRMS("muchOutStationTxBreakLeft", i, anLStation->txBreakRight); - anLStation->txBreakRight2 = anLStation->txBreakRight * anLStation->txBreakRight; - readHistoResult &= GetHistoRMS("muchOutStationTyBreakLeft", i, anLStation->tyBreakRight); - anLStation->tyBreakRight2 = anLStation->tyBreakRight * anLStation->tyBreakRight; - readHistoResult &= GetHistoRMS("muchOutStationTxBreakRight", i, aStation->txBreakLeft); - aStation->txBreakLeft2 = aStation->txBreakLeft * aStation->txBreakLeft; - readHistoResult &= GetHistoRMS("muchOutStationTyBreakRight", i, aStation->tyBreakLeft); - aStation->tyBreakLeft2 = aStation->tyBreakLeft * aStation->tyBreakLeft; -#else //USE_SEGMENTS - readHistoResult &= GetHistoRMS("muchTripletTxBreak", i, aStation->txInterTripletBreak); - aStation->txInterTripletBreak2 = aStation->txInterTripletBreak * aStation->txInterTripletBreak; - readHistoResult &= GetHistoRMS("muchTripletTyBreak", i, aStation->tyInterTripletBreak); - aStation->tyInterTripletBreak2 = aStation->tyInterTripletBreak * aStation->tyInterTripletBreak; -#endif //USE_SEGMENTS - -#ifdef CLUSTER_MODE - if (!GetHistoRMS("muchClusterXDispHisto", i, rms)) return kFATAL; - - aStation->clusterXLimit = rms; - aStation->clusterXLimit2 = rms * rms; - - if (!GetHistoRMS("muchClusterYDispHisto", i, rms)) return kFATAL; - - aStation->clusterYLimit = rms; - aStation->clusterYLimit2 = rms * rms; - - if (!GetHistoRMS("muchClusterTxDispHisto", i, rms)) return kFATAL; - - aStation->clusterTxLimit = rms; - aStation->clusterTxLimit2 = rms * rms; - - if (!GetHistoRMS("muchClusterTyDispHisto", i, rms)) return kFATAL; - - aStation->clusterTyLimit = rms; - aStation->clusterTyLimit2 = rms * rms; -#endif //CLUSTER_MODE - -#ifdef USE_SEGMENTS - if (i < LXSTATIONS - 1) { - readHistoResult &= GetHistoRMS("muchSegmentTxBreakHisto", i, aStation->txInterStationBreak); - aStation->txInterStationBreak2 = aStation->txInterStationBreak * aStation->txInterStationBreak; - readHistoResult &= GetHistoRMS("muchSegmentTyBreakHisto", i, aStation->tyInterStationBreak); - aStation->tyInterStationBreak2 = aStation->tyInterStationBreak * aStation->tyInterStationBreak; - } -#endif //USE_SEGMENTS - } - - if (!readHistoResult) return kFATAL; - -#ifdef USE_KALMAN_FIT - if (i < LXSTATIONS - 1) { - for (Int_t j = 0; j <= 1; ++j) { - for (Int_t k = 0; k <= 1; ++k) { - //if (!GetHistoCOV("muchXTxCovHisto", i, j + 1, k + 1, aStation->MSNoise[0][j][k])) - //return kFATAL; - - //if (!GetHistoCOV("muchYTyCovHisto", i, j + 1, k + 1, aStation->MSNoise[1][j][k])) - //return kFATAL; - } - } - } -#endif //USE_KALMAN_FIT - } - - // Create an output array. - listRecoTracks = new TClonesArray("CbmMuchTrack", 100); - fManager->Register("MuchTrack", "Much", listRecoTracks, IsOutputBranchPersistent("MuchTrack")); - - if (generateInvMass) massHisto = new TH1F("jpsi_mass", "jpsi_mass", 100, 2., 4.); - - if (generateBackground) { - //backgroundMassHisto = new TH1F("background_mass", "background_mass", 400, 2., 4.); - superEventTracks = new TTree("SuperEventTracks", "Tracks for building a super event"); - superEventTracks->Branch("tracks", "CbmStsTrack", &superEventData); - } - - //if (generateChi2) - //{ - signalChi2Histo = new TH1F("signal_chi2", "signal_chi2", 200, 0., 20.); - signalChi2Histo->StatOverflows(); - backgroundChi2Histo = new TH1F("background_chi2", "background_chi2", 200, 0., 20.); - backgroundChi2Histo->StatOverflows(); - unknownChi2Histo = new TH1F("unknown_chi2", "unknown_chi2", 200, 0., 20.); - unknownChi2Histo->StatOverflows(); - //} - -#ifdef MAKE_HISTOS - char histoName[128]; - - for (int i = 0; i < 6; ++i) { -#ifdef MAKE_DISPERSE_2D_HISTOS - sprintf(histoName, "disperseL_%d", i); - disperseLHistos[i] = new TProfile2D(histoName, histoName, 30, -3., 3., 30, -3., 3.); - disperseLHistos[i]->StatOverflows(); - sprintf(histoName, "disperseR_%d", i); - disperseRHistos[i] = new TProfile2D(histoName, histoName, 30, -3., 3., 30, -3., 3.); - disperseRHistos[i]->StatOverflows(); - sprintf(histoName, "disperseD_%d", i); - disperseDHistos[i] = new TProfile2D(histoName, histoName, 30, -3., 3., 30, -3., 3.); - disperseDHistos[i]->StatOverflows(); -#endif //MAKE_DISPERSE_2D_HISTOS - } - -#endif //MAKE_HISTOS - - effByMomentumProfile = new TProfile("Reconstruction efficiency by momentum", "Reconstruction efficiency by momentum", - 100, 0.0, 50.0, 0.0, 100.0); - - stsTrackChi2 = new TH1F("stsTrackChi2", "stsTrackChi2", 200, 0., 10.); - stsTrackChi2->StatOverflows(); - stsTrackX = new TH1F("stsTrackX", "stsTrackX", 200, -0.2, 0.2); - stsTrackX->StatOverflows(); - stsTrackY = new TH1F("stsTrackY", "stsTrackY", 200, -0.2, 0.2); - stsTrackY->StatOverflows(); - - signalInterTracksDistance = new TH1F("signalInterTracksDistance", "Distance between signal tracks", 200, 0.0, 40.0); - signalInterTracksDistance->StatOverflows(); - bgrInterTracksDistance = new TH1F("bgrInterTracksDistance", "Distance between background tracks", 200, 0.0, 40.0); - bgrInterTracksDistance->StatOverflows(); - signalSignDefect = new TH1F("signalSignDefect", "signalSignDefect", 200, -0.15, 0.15); - signalSignDefect->StatOverflows(); - bgrSignDefect = new TH1F("bgrSignDefect", "bgrSignDefect", 200, -0.15, 0.15); - bgrSignDefect->StatOverflows(); - signalYAtZ0 = new TH1F("signalYAtZ0", "Signal track Y at Z=0", 200, -40.0, 40.0); - signalYAtZ0->StatOverflows(); - bgrYAtZ0 = new TH1F("bgrYAtZ0", "Background track Y at Z=0", 200, -40.0, 40.0); - bgrYAtZ0->StatOverflows(); - signalYAtZ0_2 = new TH1F("signalYAtZ0_2", "Signal track Y at Z=0 (2)", 200, -40.0, 40.0); - signalYAtZ0_2->StatOverflows(); - bgrYAtZ0_2 = new TH1F("bgrYAtZ0_2", "Background track Y at Z=0 (2)", 200, -40.0, 40.0); - bgrYAtZ0_2->StatOverflows(); - -#ifdef MAKE_EFF_CALC - incomplete_events.open("incomplete_events.txt"); -#endif //MAKE_EFF_CALC - - return kSUCCESS; -} - -static Int_t nTimes = 1; - -void LxFinderTriplet::Exec(Option_t*) -{ - cout << "LxFinderTriplet::Exec() called at " << nTimes++ << " time" << endl; - timeval bTime, eTime; - int exeDuration; - gettimeofday(&bTime, 0); - - // Clean all previously created data. - MCTracks.clear(); - MCPoints.clear(); - MCStsPoints.clear(); - - for (int i = 0; i < 8; ++i) - MCStsPointsByStations[i].clear(); - -#ifdef MAKE_DISPERSE_2D_HISTOS - for (int i = 0; i < LXSTATIONS; ++i) { - for (int j = 0; j < LXLAYERS; ++j) - MCPointsByStations[i][j].clear(); - } -#endif //MAKE_DISPERSE_2D_HISTOS - - caSpace.Clear(); - listRecoTracks->Clear(); - - // Read MC tracks - Int_t nEnt = listMCTracks->GetEntriesFast(); - cout << "There are: " << nEnt << " of MC tracks" << endl; - LxMCTrack mcTrack; - - MCTracks.reserve(nEnt); - Int_t* root2lxmctrackmap = new Int_t[nEnt]; - Int_t mapCnt = 0; - - for (int i = 0; i < nEnt; ++i) { - CbmMCTrack* mct = LX_DYNAMIC_CAST<CbmMCTrack*>(listMCTracks->At(i)); - mcTrack.p = mct->GetP(); - Int_t pdgCode = mct->GetPdgCode(); - - if (abs(pdgCode) >= 10000) { - root2lxmctrackmap[i] = -1; - continue; - } - - root2lxmctrackmap[i] = mapCnt++; - - mcTrack.q = TDatabasePDG::Instance()->GetParticle(pdgCode)->Charge() / 3.0; - mcTrack.x = mct->GetStartX(); - mcTrack.y = mct->GetStartY(); - mcTrack.z = mct->GetStartZ(); - mcTrack.px = mct->GetPx(); - mcTrack.py = mct->GetPy(); - mcTrack.pz = mct->GetPz(); - mcTrack.mother_ID = mct->GetMotherId(); - mcTrack.fUniqueID = mct->GetUniqueID(); - mcTrack.pdg = pdgCode; - mcTrack.externalTrack = 0; - MCTracks.push_back(mcTrack); - } - - nEnt = listStsPts->GetEntriesFast(); - cout << "There are: " << nEnt << " of STS MC points" << endl; - - for (int i = 0; i < nEnt; ++i) { - TVector3 xyzI, PI, xyzO, PO; - CbmStsPoint* stsPt = LX_DYNAMIC_CAST<CbmStsPoint*>(listStsPts->At(i)); - - if (0 == stsPt) continue; - - LxStsMCPoint stsMCPoint; - stsPt->Position(xyzI); - stsPt->Momentum(PI); - stsPt->PositionOut(xyzO); - stsPt->MomentumOut(PO); - TVector3 xyz = .5 * (xyzI + xyzO); - TVector3 P = .5 * (PI + PO); - stsMCPoint.x = xyz.X(); - stsMCPoint.y = xyz.Y(); - stsMCPoint.z = xyz.Z(); - stsMCPoint.px = P.X(); - stsMCPoint.py = P.Y(); - stsMCPoint.pz = P.Z(); - stsMCPoint.p = - sqrt(fabs(stsMCPoint.px * stsMCPoint.px + stsMCPoint.py * stsMCPoint.py + stsMCPoint.pz * stsMCPoint.pz)); - stsMCPoint.stationNumber = CbmStsAddress::GetElementId(stsPt->GetDetectorID(), kStsStation); - Int_t trackId = root2lxmctrackmap[stsPt->GetTrackID()]; - - if (-1 != trackId) { - stsMCPoint.mcTrack = &MCTracks[trackId]; - MCStsPoints.push_back(stsMCPoint); - MCTracks[trackId].stsPoints[stsMCPoint.stationNumber].push_back(&MCStsPoints.back()); - MCStsPointsByStations[stsMCPoint.stationNumber].push_back(&MCStsPoints.back()); - } - } - - nEnt = listMuchPts->GetEntriesFast(); - cout << "There are: " << nEnt << " of MUCH MC points" << endl; - LxMCPoint mcPoint; - - MCPoints.reserve(nEnt); - Int_t* root2lxmcpointmap = new Int_t[nEnt]; // Unfortunately we have to use this map because in the loop - // below some iterations can not to produce a point. - mapCnt = 0; - // Int_t mcPtsCount = nEnt; - Int_t maxReferencedPtsIndex = 0; - - for (int i = 0; i < nEnt; ++i) { - TVector3 xyzI, PI, xyzO, PO; - CbmMuchPoint* pt = LX_DYNAMIC_CAST<CbmMuchPoint*>(listMuchPts->At(i)); - - if (!pt) { - root2lxmcpointmap[i] = -1; - continue; - } - - Int_t trackId = root2lxmctrackmap[pt->GetTrackID()]; - - if (-1 == trackId) { - root2lxmcpointmap[i] = -1; - continue; - } - - mcPoint.trackId = trackId; - mcPoint.track = &MCTracks[trackId]; - - root2lxmcpointmap[i] = mapCnt++; - - pt->Position(xyzI); - pt->Momentum(PI); - pt->PositionOut(xyzO); - pt->MomentumOut(PO); - TVector3 xyz = .5 * (xyzI + xyzO); - TVector3 P = .5 * (PI + PO); - mcPoint.x = xyz.X(); - mcPoint.y = xyz.Y(); - mcPoint.z = xyz.Z(); - mcPoint.px = P.X(); - mcPoint.py = P.Y(); - mcPoint.pz = P.Z(); - mcPoint.p = sqrt(fabs(mcPoint.px * mcPoint.px + mcPoint.py * mcPoint.py + mcPoint.pz * mcPoint.pz)); - mcPoint.stationNumber = CbmMuchGeoScheme::GetStationIndex(pt->GetDetectorId()); - mcPoint.layerNumber = CbmMuchGeoScheme::GetLayerIndex(pt->GetDetectorId()); - MCPoints.push_back(mcPoint); - Int_t ptId = root2lxmcpointmap[i]; - - /* -#ifdef MAKE_HISTOS - Double_t trackPt2 = MCTracks[trackId].px * MCTracks[trackId].px + MCTracks[trackId].py * MCTracks[trackId].py; -#endif//MAKE_HISTOS -*/ - - MCTracks[trackId].Points.push_back(&MCPoints[ptId]); -#ifdef MAKE_DISPERSE_2D_HISTOS - MCPointsByStations[mcPoint.stationNumber][mcPoint.layerNumber].push_back(&MCPoints[ptId]); -#endif //MAKE_DISPERSE_2D_HISTOS - } - -#ifdef MAKE_HISTOS - // Build angle (tangent) breaks distribution < - for (vector<LxMCTrack>::iterator i = MCTracks.begin(); i != MCTracks.end(); ++i) { - LxMCTrack& track = *i; - - if ((13 != track.pdg && -13 == track.pdg) || track.mother_ID >= 0) continue; - - if (track.p < 3) continue; - - Double_t pt2 = track.px * track.px + track.py * track.py; - - if (pt2 < 1) continue; - - LxMCPoint* points[LXSTATIONS][LXLAYERS]; - memset(points, 0, sizeof(points)); - - for (vector<LxMCPoint*>::iterator j = track.Points.begin(); j != track.Points.end(); ++j) { - LxMCPoint* point = *j; - points[point->stationNumber][point->layerNumber] = point; - } - - for (int j = 0; j < LXSTATIONS; ++j) { -#ifdef MAKE_DISPERSE_2D_HISTOS - if (0 != points[j][1]) { - LxMCPoint* mPoint = points[j][1]; - Double_t tx = mPoint->x / mPoint->z; - Double_t ty = mPoint->y / mPoint->z; - Double_t diffZ = zCoordsByStations[j][0] - mPoint->z; - Double_t x = mPoint->x + tx * diffZ; - Double_t y = mPoint->y + ty * diffZ; - list<LxMCPoint*>& lPoints = MCPointsByStations[j][0]; - - for (list<LxMCPoint*>::iterator k = lPoints.begin(); k != lPoints.end(); ++k) { - LxMCPoint* lPoint = *k; - - if (lPoint->trackId == mPoint->trackId) - disperseLHistos[j]->Fill(lPoint->x - x, lPoint->y - y, 100.); - else - disperseLHistos[j]->Fill(lPoint->x - x, lPoint->y - y, 0.); - } - - diffZ = zCoordsByStations[j][2] - mPoint->z; - x = mPoint->x + tx * diffZ; - y = mPoint->y + ty * diffZ; - list<LxMCPoint*>& rPoints = MCPointsByStations[j][2]; - - for (list<LxMCPoint*>::iterator k = rPoints.begin(); k != rPoints.end(); ++k) { - LxMCPoint* rPoint = *k; - - if (rPoint->trackId == mPoint->trackId) - disperseRHistos[j]->Fill(rPoint->x - x, rPoint->y - y, 100.); - else - disperseRHistos[j]->Fill(rPoint->x - x, rPoint->y - y, 0.); - } - } - - if (0 != points[j][2]) { - LxMCPoint* rPoint = points[j][2]; - Double_t tx = rPoint->x / rPoint->z; - Double_t ty = rPoint->y / rPoint->z; - Double_t diffZ = zCoordsByStations[j][0] - rPoint->z; - Double_t x = rPoint->x + tx * diffZ; - Double_t y = rPoint->y + ty * diffZ; - list<LxMCPoint*>& lPoints = MCPointsByStations[j][0]; - - for (list<LxMCPoint*>::iterator k = lPoints.begin(); k != lPoints.end(); ++k) { - LxMCPoint* lPoint = *k; - - if (lPoint->trackId == rPoint->trackId) - disperseDHistos[j]->Fill(lPoint->x - x, lPoint->y - y, 100.); - else - disperseDHistos[j]->Fill(lPoint->x - x, lPoint->y - y, 0.); - } - } -#endif //MAKE_DISPERSE_2D_HISTOS - } //for (int j = 0; j < LXSTATIONS; ++j) - } //for (vector<LxMCTrack>::iterator i = MCTracks.begin(); i != MCTracks.end(); ++i) - // > angle (tangent) breaks distribution -#endif //MAKE_HISTOS - - // Read MUCH pixel hits. - nEnt = muchPixelHits->GetEntriesFast(); - cout << "There are: " << nEnt << " of MUCH pixel hits" << endl; - - Double_t minXErr = 1000; - Double_t minYErr = 1000; - - for (Int_t i = 0; i < nEnt; ++i) { - CbmMuchPixelHit* mh = LX_DYNAMIC_CAST<CbmMuchPixelHit*>(muchPixelHits->At(i)); - - Int_t stationNumber = CbmMuchGeoScheme::GetStationIndex(mh->GetAddress()); - Int_t layerNumber = CbmMuchGeoScheme::GetLayerIndex(mh->GetAddress()); - TVector3 pos, err; - mh->Position(pos); - mh->PositionError(err); - Double_t x = pos.X(); - Double_t y = pos.Y(); - Double_t z = pos.Z(); - - if (x != x || y != y || z != z) // Test for NaN - continue; - - if (minXErr > err.X()) minXErr = err.X(); - - if (minYErr > err.Y()) minYErr = err.Y(); - - LxPoint* lxPoint = 0; - - if (!useMCPInsteadOfHits) - lxPoint = caSpace.AddPoint(stationNumber, layerNumber, i, x, y, z, err.X(), err.Y(), err.Z()); - - Int_t clusterId = mh->GetRefId(); - CbmMuchCluster* cluster = LX_DYNAMIC_CAST<CbmMuchCluster*>(listMuchClusters->At(clusterId)); - Int_t nDigis = cluster->GetNofDigis(); - - for (Int_t j = 0; j < nDigis; ++j) { - CbmMuchDigiMatch* digiMatch = - LX_DYNAMIC_CAST<CbmMuchDigiMatch*>(listMuchPixelDigiMatches->At(cluster->GetDigi(j))); - Int_t nMCs = digiMatch->GetNofLinks(); - - for (Int_t k = 0; k < nMCs; ++k) { - const CbmLink& lnk = digiMatch->GetLink(k); - Int_t mcIndex = lnk.GetIndex(); - - if (mcIndex > maxReferencedPtsIndex) maxReferencedPtsIndex = mcIndex; - - Int_t mcIndexMapped = root2lxmcpointmap[mcIndex]; - - if (-1 == mcIndexMapped) continue; - - if (!useMCPInsteadOfHits) { - MCPoints[mcIndexMapped].lxPoints.push_back(lxPoint); - lxPoint->mcPoints.push_back(&MCPoints[mcIndexMapped]); - } - else if (MCPoints[mcIndexMapped].lxPoints.empty()) { - LxMCPoint& mcp = MCPoints[mcIndexMapped]; - lxPoint = caSpace.AddPoint(stationNumber, layerNumber, i, mcp.x, mcp.y, mcp.z, err.X(), err.Y(), err.Z()); - MCPoints[mcIndexMapped].lxPoints.push_back(lxPoint); - lxPoint->mcPoints.push_back(&MCPoints[mcIndexMapped]); - } - } - } - } // for (Int_t i = 0; i < nEnt; ++i) - - cout << "minXErr = " << minXErr << " ; minYErr = " << minYErr << endl << endl; - - // At last start invocation of CA procedures. - gettimeofday(&eTime, 0); - exeDuration = (eTime.tv_sec - bTime.tv_sec) * 1000000 + eTime.tv_usec - bTime.tv_usec; - cout << "Execution duration 1 was: " << exeDuration << endl; - - //if (calcMiddlePoints) - //caSpace.RestoreMiddlePoints(); - - bTime.tv_sec = eTime.tv_sec; - bTime.tv_usec = eTime.tv_usec; - gettimeofday(&eTime, 0); - exeDuration = (eTime.tv_sec - bTime.tv_sec) * 1000000 + eTime.tv_usec - bTime.tv_usec; - cout << "Execution duration 2 was: " << exeDuration << endl; -#ifdef CLUSTER_MODE - caSpace.BuildRays2(); -#else //CLUSTER_MODE - //caSpace.BuildRays(); -#endif //CLUSTER_MODE - bTime.tv_sec = eTime.tv_sec; - bTime.tv_usec = eTime.tv_usec; - gettimeofday(&eTime, 0); - exeDuration = (eTime.tv_sec - bTime.tv_sec) * 1000000 + eTime.tv_usec - bTime.tv_usec; - cout << "Execution duration 3 was: " << exeDuration << endl; -#ifdef CLUSTER_MODE - caSpace.ConnectNeighbours2(); -#else //CLUSTER_MODE - //caSpace.ConnectNeighbours(); -#endif //CLUSTER_MODE - bTime.tv_sec = eTime.tv_sec; - bTime.tv_usec = eTime.tv_usec; - gettimeofday(&eTime, 0); - exeDuration = (eTime.tv_sec - bTime.tv_sec) * 1000000 + eTime.tv_usec - bTime.tv_usec; - cout << "Execution duration 4 was: " << exeDuration << endl; -#ifdef CLUSTER_MODE - caSpace.Reconstruct2(); -#else //CLUSTER_MODE - caSpace.Reconstruct(); -#endif //CLUSTER_MODE - //caSpace.FitTracks(); - bTime.tv_sec = eTime.tv_sec; - bTime.tv_usec = eTime.tv_usec; - gettimeofday(&eTime, 0); - exeDuration = (eTime.tv_sec - bTime.tv_sec) * 1000000 + eTime.tv_usec - bTime.tv_usec; - cout << "Execution duration 5 was: " << exeDuration << endl; - caSpace.FitTracks(); - //cout << "maxReferencedPtsIndex=" << maxReferencedPtsIndex << " mcPtsCount=" << mcPtsCount << " GEF=" << listMuchPts->GetEntriesFast() << endl; - //cout << "Hits=" << muchPixelHits->GetEntriesFast() << " clusters=" << listMuchClusters->GetEntriesFast() << " digi ms=" << listMuchPixelDigiMatches->GetEntriesFast() << endl; - //sleep(3); - - ///////////////////////////////////////////////////////////////////////////////// - // Join MUCH-tracks with STS-tracks. - ///////////////////////////////////////////////////////////////////////////////// - - // STS-tracks fulfilling the limitations peculiar for muons are picked up in the loop below. - nEnt = listStsTracks->GetEntriesFast(); - - for (int i = 0; i < nEnt; ++i) { - CbmStsTrack* stsTrack = LX_DYNAMIC_CAST<CbmStsTrack*>(listStsTracks->At(i)); - - Double_t lpa[5] = {stsTrack->GetParamLast()->GetX(), stsTrack->GetParamLast()->GetY(), - stsTrack->GetParamLast()->GetTx(), stsTrack->GetParamLast()->GetTy(), - stsTrack->GetParamLast()->GetQp()}; - - if (lpa[0] != lpa[0] || lpa[1] != lpa[1] || lpa[2] != lpa[2] || lpa[3] != lpa[3] || lpa[4] != lpa[4]) continue; - - CbmStsTrack aTrack = *stsTrack; - - Int_t pdgHypo = 13; - - if (stsTrack->GetParamLast()->GetTx() > stsTrack->GetParamFirst()->GetTx()) pdgHypo = -13; - - extFitter.DoFit(&aTrack, pdgHypo); - Double_t chi2Prim = extFitter.GetChiToVertex(&aTrack, fPrimVtx); - FairTrackParam params; - extFitter.Extrapolate(&aTrack, fPrimVtx->GetZ(), ¶ms); - Double_t p = 1 / params.GetQp(); - Double_t p2 = p * p; - - if (p2 < 3.0 * 3.0) continue; - - /* - Double_t xDelta = 0.05;//5.0 * sqrt(params.GetCovariance(0, 0)); - Double_t yDelta = 0.05;//5.0 * sqrt(params.GetCovariance(1, 1)); - - if (params.GetX() < -xDelta || params.GetX() > xDelta || params.GetY() < -yDelta || params.GetY() > yDelta) - continue; -*/ - Double_t tx2 = params.GetTx() * params.GetTx(); - Double_t ty2 = params.GetTy() * params.GetTy(); - Double_t pt2 = p2 * (tx2 + ty2) / (1 + tx2 + ty2); - - if (pt2 < 1.0) continue; - - LxExtTrack extTrack; - extTrack.track = stsTrack; - extTrack.extId = i; - - CbmTrackMatch* match = LX_DYNAMIC_CAST<CbmTrackMatch*>(listStsMatches->At(i)); - Int_t numberOfHits = match->GetNofTrueHits() + match->GetNofWrongHits() + match->GetNofFakeHits(); - - if (match->GetNofTrueHits() >= 0.7 * numberOfHits) { - Int_t mcTrackId = match->GetMCTrackId(); - Int_t mappedId = root2lxmctrackmap[mcTrackId]; - - if (-1 != mappedId) { - MCTracks[mappedId].externalTrack = stsTrack; - extTrack.mcTrack = &MCTracks[mappedId]; - - if (13 == MCTracks[mappedId].pdg || -13 == MCTracks[mappedId].pdg) { - stsTrackChi2->Fill(chi2Prim); - stsTrackX->Fill(params.GetX()); - stsTrackY->Fill(params.GetY()); - } - } - } - - caSpace.extTracks.push_back(extTrack); - } - - cout << "External tracks are read" << endl; - - // Join reconstructed tracks with external tracks. - caSpace.JoinExtTracks(); - cout << "External tracks are connected" << endl; - - // Measure a reconstruction efficiency. - effCounter.CalcRecoEff(linkWithSts); - MatchRecoToMC(); - - // Draw some result. - //static LxDraw drawer; - - //drawer.ClearView(); - //drawer.DrawMuch(); - //drawer.SaveCanvas("Geometry_"); - - //drawer.ClearView(); - //drawer.DrawInputHits(); - //drawer.SaveCanvas("Hits_"); - //drawer.Ask(); - - //drawer.ClearView(); - //drawer.DrawInputHits(); - //drawer.DrawMCTracks(); - //drawer.DrawRecoTracks(); - //drawer.DrawExtTracks(); - //drawer.SaveCanvas("MC_"); - //gPad->WaitPrimitive(); - - /*drawer.ClearView(); - drawer.DrawInputHits(); - drawer.DrawMCTracks(); - drawer.DrawRays(); - gPad->WaitPrimitive();*/ - - //drawer.ClearView(); - //drawer.DrawInputHits(); - //drawer.DrawRecoTracks(); - //drawer.SaveCanvas("Reco_"); - //drawer.Ask(); - - //drawer.ClearView(); - //drawer.DrawInputHits(); - //drawer.DrawRecoTracks(); - //drawer.DrawExtTracks(); - //drawer.Ask(); - - if (generateInvMass) CalcInvMass(); - - if (generateBackground) SaveEventTracks(); - - // Finally save reconstructed tracks. - //SaveRecoTracks(); - - // Hopefully we don't need these two maps any more. - delete[] root2lxmctrackmap; - delete[] root2lxmcpointmap; - ++eventNumber; -} - -void LxFinderTriplet::SaveRecoTracks() -{ - Int_t trackNo = listRecoTracks->GetEntriesFast(); - - for (list<LxTrack*>::iterator i = caSpace.tracks.begin(); i != caSpace.tracks.end(); ++i) { - LxTrack* recoTrack = *i; - LxExtTrack* stsTrack = recoTrack->externalTrack; - - if (0 == stsTrack) continue; - - CbmMuchTrack muchTrack; - - for (int j = 0; j < LXSTATIONS * LXLAYERS; ++j) { - LxPoint* pPoint = recoTrack->points[j]; - - if (0 != pPoint) muchTrack.AddHit(pPoint->hitId, kMUCHPIXELHIT); - } - - muchTrack.SetChiSq(recoTrack->chi2); - muchTrack.SetNDF(4 * LXSTATIONS); // Probably need to calculate it more accurately. - muchTrack.SetPreviousTrackId(stsTrack->extId); - - FairTrackParam parFirst; - parFirst = *stsTrack->track->GetParamLast(); - muchTrack.SetFlag(0); // Good track. - - FairTrackParam parLast(parFirst); - muchTrack.SetParamFirst(&parFirst); - muchTrack.SetParamLast(&parLast); - - new ((*listRecoTracks)[trackNo++]) CbmMuchTrack(muchTrack); - } -} - -void LxFinderTriplet::CalcInvMass() -{ - for (list<LxTrack*>::iterator i = caSpace.tracks.begin(); i != caSpace.tracks.end(); ++i) { - LxTrack* firstTrack = *i; - LxMCTrack* mcTrack1 = firstTrack->mcTrack; - - if (0 == firstTrack->externalTrack) continue; - - LxMCTrack* mcTrack2 = firstTrack->externalTrack->mcTrack; - - if (mcTrack1) { - Int_t pdg1 = mcTrack1 ? mcTrack1->pdg : 10000; - map<Int_t, map<Int_t, int>>::iterator j = particleCounts.find(pdg1); - - if (j == particleCounts.end()) - j = particleCounts.insert(pair<Int_t, map<Int_t, int>>(pdg1, map<Int_t, int>())).first; - - Int_t pdg2 = mcTrack2 ? mcTrack2->pdg : 10000; - - map<Int_t, int>::iterator k = j->second.find(pdg2); - - if (k != j->second.end()) - ++(k->second); - else - j->second.insert(pair<Int_t, int>(pdg2, 1)); - } - - CbmStsTrack t1 = *firstTrack->externalTrack->track; - - // Add entry to the respective chi2 histogram if needed. This can be used for placing chi2 cuts determining J/psi. - // pdg == 13 | -13 -- it is a muon. - // mother_ID < 0 -- it is a primary particle. URQMD doesn't produce primary muons. So it from PLUTO <=> is J/psi. - - if (generateChi2) { - // Double_t normalizedChi2 = firstTrack->chi2 / (LXSTATIONS * 4);// length * 4 == NDF. - - //if (mcTrack2 && (mcTrack2->pdg == 13 || mcTrack2->pdg == -13) && mcTrack2->mother_ID < 0) - //signalChi2Histo->Fill(normalizedChi2); - //else - //backgroundChi2Histo->Fill(normalizedChi2); - } - - if (!mcTrack2 || (mcTrack2->pdg != 13 && mcTrack2->pdg != -13) || mcTrack2->mother_ID >= 0) continue; - - extFitter.DoFit(&t1, 13); - Double_t chi2Prim = extFitter.GetChiToVertex(&t1, fPrimVtx); - FairTrackParam t1param; - extFitter.Extrapolate(&t1, fPrimVtx->GetZ(), &t1param); - - if (t1param.GetQp() <= 0) continue; - - Double_t p1 = 1 / t1param.GetQp(); - Double_t tx12 = t1param.GetTx() * t1param.GetTx(); - Double_t ty12 = t1param.GetTy() * t1param.GetTy(); - Double_t pt12 = p1 * p1 * (tx12 + ty12) / (1 + tx12 + ty12); - - if (pt12 < 1) continue; - - CbmKFTrack muPlus(t1); - - for (list<LxTrack*>::iterator j = caSpace.tracks.begin(); j != caSpace.tracks.end(); ++j) { - LxTrack* secondTrack = *j; - - if (0 == secondTrack->externalTrack) continue; - - LxMCTrack* mcSecondTrack = secondTrack->externalTrack->mcTrack; - - if (!mcSecondTrack || (mcSecondTrack->pdg != 13 && mcSecondTrack->pdg != -13) || mcSecondTrack->mother_ID >= 0) - continue; - - CbmStsTrack t2 = *secondTrack->externalTrack->track; - extFitter.DoFit(&t2, 13); - chi2Prim = extFitter.GetChiToVertex(&t2, fPrimVtx); - FairTrackParam t2param; - extFitter.Extrapolate(&t2, fPrimVtx->GetZ(), &t2param); - - if (t2param.GetQp() >= 0) continue; - - Double_t p2 = 1 / t2param.GetQp(); - Double_t tx22 = t2param.GetTx() * t2param.GetTx(); - Double_t ty22 = t2param.GetTy() * t2param.GetTy(); - Double_t pt22 = p2 * p2 * (tx22 + ty22) / (1 + tx22 + ty22); - - if (pt22 < 1) continue; - - CbmKFTrack muMinus(t2); - vector<CbmKFTrackInterface*> kfData; - kfData.push_back(&muPlus); - kfData.push_back(&muMinus); - } - } -} - -//#ifdef MAKE_HISTOS -// It also deletes the histogram. -static void SaveHisto(TH1* histo, const char* name) -{ - TFile fh(name, "RECREATE"); - histo->Write(); - fh.Close(); - delete histo; -} -//#endif//MAKE_HISTOS - -void LxFinderTriplet::FinishTask() -{ - if (generateInvMass) SaveInvMass(); - - if (generateBackground) SaveBackground(); - - /*if (generateChi2) - { - SaveSignalChi2(); - SaveBackgroundChi2(); - } - - cout << "Statistics on particles found:" << endl; - - for (map<Int_t, map<Int_t, int> >::iterator i = particleCounts.begin(); i != particleCounts.end(); ++i) - { - string muchParticle = (10000 <= i->first || -10000 >= i->first) ? "Undefined MUCH particle" : TDatabasePDG::Instance()->GetParticle(i->first)->GetName(); - cout << "For MUCH particle [ " << muchParticle << " ] ( PDG = " << i->first << " ) found STS joints to:" << endl; - - for (map<Int_t, int>::iterator j = i->second.begin(); j != i->second.end(); ++j) - { - string stsParticle = (10000 <= j->first || -10000 >= j->first) ? "Undefined STS particle" : TDatabasePDG::Instance()->GetParticle(j->first)->GetName(); - cout << "\t" << j->second << " [ " << stsParticle << " ] ( PDG = " << j->first << " )" << endl; - } - }*/ - TFile* curFile = TFile::CurrentFile(); -#ifdef MAKE_HISTOS - char histoFileName[128]; - - for (int i = 0; i < 6; ++i) { -#ifdef MAKE_DISPERSE_2D_HISTOS - sprintf(histoFileName, "disperseL_histo_%d.root", i); - SaveHisto(disperseLHistos[i], histoFileName); - sprintf(histoFileName, "disperseR_histo_%d.root", i); - SaveHisto(disperseRHistos[i], histoFileName); - sprintf(histoFileName, "disperseD_histo_%d.root", i); - SaveHisto(disperseDHistos[i], histoFileName); -#endif //MAKE_DISPERSE_2D_HISTOS - } -#endif //MAKE_HISTOS - - { - TFile fh("effByMomentumProfile.root", "RECREATE"); - effByMomentumProfile->Write(); - fh.Close(); - delete effByMomentumProfile; - } - - SaveHisto(stsTrackChi2, "stsTrackChi2.root"); - SaveHisto(stsTrackX, "stsTrackX.root"); - SaveHisto(stsTrackY, "stsTrackY.root"); - - SaveHisto(signalInterTracksDistance, "signalInterTracksDistance.root"); - SaveHisto(bgrInterTracksDistance, "bgrInterTracksDistance.root"); - SaveHisto(signalChi2Histo, "signalChi2Histo.root"); - SaveHisto(backgroundChi2Histo, "backgroundChi2Histo.root"); - SaveHisto(unknownChi2Histo, "unknownChi2Histo.root"); - SaveHisto(signalSignDefect, "signalSignDefectHisto.root"); - SaveHisto(bgrSignDefect, "bgrSignDefectHisto.root"); - SaveHisto(signalYAtZ0, "signalYAtZ0.root"); - SaveHisto(bgrYAtZ0, "bgrYAtZ0.root"); - SaveHisto(signalYAtZ0_2, "signalYAtZ0_2.root"); - SaveHisto(bgrYAtZ0_2, "bgrYAtZ0_2.root"); - - TFile::CurrentFile() = curFile; - -#ifdef MAKE_EFF_CALC - incomplete_events.close(); -#endif //MAKE_EFF_CALC - - delete superEventData; - - FairTask::FinishTask(); -} - -void LxFinderTriplet::SaveInvMass() -{ - TFile* curFile = TFile::CurrentFile(); - - TFile fh("jpsi_inv_mass_histo.root", "RECREATE"); - massHisto->Write(); - fh.Close(); - delete massHisto; - - TFile::CurrentFile() = curFile; -} - -void LxFinderTriplet::SaveBackground() -{ - for (list<CbmStsTrack>::iterator i = positiveTracks.begin(); i != positiveTracks.end(); ++i) { - CbmStsTrack& t1 = *i; - CbmKFTrack muPlus(t1); - - for (list<CbmStsTrack>::iterator j = negativeTracks.begin(); j != negativeTracks.end(); ++j) { - CbmStsTrack& t2 = *j; - CbmKFTrack muMinus(t2); - vector<CbmKFTrackInterface*> kfData; - kfData.push_back(&muPlus); - kfData.push_back(&muMinus); - } - } - - TFile* curFile = TFile::CurrentFile(); - - TFile fh("tracks_tree.root", "RECREATE"); - superEventTracks->Write(); - fh.Close(); - delete superEventTracks; - - TFile::CurrentFile() = curFile; -} diff --git a/reco/tracking/lxTriplet/Lx.h b/reco/tracking/lxTriplet/Lx.h deleted file mode 100644 index 58f648b759e09468aaf7d4a7d0161d4fd5a79ad0..0000000000000000000000000000000000000000 --- a/reco/tracking/lxTriplet/Lx.h +++ /dev/null @@ -1,144 +0,0 @@ -/* Copyright (C) 2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifndef LX_INCLUDED -#define LX_INCLUDED - -#pragma GCC diagnostic ignored "-Weffc++" - -#include "CbmMuchPixelHit.h" -#include "CbmStsKFTrackFitter.h" -#include "CbmTrackMatch.h" -#include "CbmVertex.h" - -#include "FairTask.h" - -#include "TClonesArray.h" -#include "TH1.h" -#include "TProfile.h" -#include "TProfile2D.h" - -#include <fstream> - -#include "LxCATriplets.h" -#include "LxEff.h" -#include "LxMC.h" - -#ifdef FAST_CODE -#define LX_DYNAMIC_CAST static_cast -#else // FAST_CODE -#define LX_DYNAMIC_CAST dynamic_cast -#endif // FAST_CODE - -extern TString lxFinderParticleType; - -class LxFinderTriplet : public FairTask { - friend struct LxEff; - friend class LxDraw; - -public: - static LxFinderTriplet* Instance(); - explicit LxFinderTriplet(); - ~LxFinderTriplet(); - InitStatus Init(); // Inherited virtual. - void Exec(Option_t* opt); // Inherited virtual. - - void SetGenInvMass(bool value) { generateInvMass = value; } - - void SetGenBackground(bool value) { generateBackground = value; } - - void SetGenChi2(bool value) { generateChi2 = value; } - - void SetLinkWithSts(bool value) { linkWithSts = value; } - - void SetUseMCPInsteadOfHits(bool value) { useMCPInsteadOfHits = value; } - - void SetCalcMiddlePoints(bool value) { calcMiddlePoints = value; } - - void SetCutCoeff(Double_t value) { cutCoeff = value; } - - void SetParticleType(TString v) - { - //particleType = v; - lxFinderParticleType = v; - - if (v == "omega") { - caSpace.stationsInAlgo = 5; -#ifdef MAKE_EFF_CALC - pPtCut = false; -#endif //MAKE_EFF_CALC - } - } - -private: - void SaveRecoTracks(); - void CalcInvMass(); - void FinishTask(); // Inherited virtual. - void SaveEventTracks(); - void SaveInvMass(); - void SaveBackground(); - void MatchRecoToMC(); - static LxFinderTriplet* fInstance; - TClonesArray* muchPixelHits; - TClonesArray* listMCTracks; - TClonesArray* listMuchPts; - TClonesArray* listMuchClusters; - TClonesArray* listMuchPixelDigiMatches; - TClonesArray* listStsTracks; - TClonesArray* listStsMatches; - TClonesArray* listStsPts; // STS MC-points array. Used for experiments with STS matching. - TClonesArray* listRecoTracks; // It is an output array. - LxEff effCounter; - static TH1F* massHisto; - //static TH1F* backgroundMassHisto; - static CbmStsTrack* superEventData; - static TTree* superEventTracks; - static TH1F* signalChi2Histo; - static TH1F* backgroundChi2Histo; - static TH1F* unknownChi2Histo; - static TProfile* effByMomentumProfile; - static TH1F* signalInterTracksDistance; - static TH1F* bgrInterTracksDistance; - static TH1F* signalSignDefect; - static TH1F* bgrSignDefect; - static TH1F* signalYAtZ0; - static TH1F* bgrYAtZ0; - static TH1F* signalYAtZ0_2; - static TH1F* bgrYAtZ0_2; - CbmStsKFTrackFitter extFitter; - CbmVertex* fPrimVtx; - // These two containers below accumulates respectively all positive and all negative reconstructed tracks for all events. - std::list<CbmStsTrack> positiveTracks; - std::list<CbmStsTrack> negativeTracks; - bool generateInvMass; - bool generateBackground; - bool generateChi2; - bool linkWithSts; - bool useMCPInsteadOfHits; - bool calcMiddlePoints; - Double_t cutCoeff; - bool pPtCut; - std::vector<LxMCPoint> MCPoints; // Points should lay here in the same order as in listMuchPts. - std::vector<LxMCTrack> MCTracks; // Tracks should lay here in the same order as in listMCTracks. - std::list<LxStsMCPoint> MCStsPoints; - std::list<LxStsMCPoint*> MCStsPointsByStations[8]; -#ifdef MAKE_DISPERSE_2D_HISTOS - std::list<LxMCPoint*> MCPointsByStations[LXSTATIONS][LXLAYERS]; - Double_t zCoordsByStations[LXSTATIONS][LXLAYERS]; -#endif //MAKE_DISPERSE_2D_HISTOS - LxSpace caSpace; - std::map<Int_t, std::map<Int_t, int>> particleCounts; -#ifdef MAKE_EFF_CALC - std::ofstream incomplete_events; // Events where not all tracks are reconstructed. -#endif //MAKE_EFF_CALC - Int_t eventNumber; -#ifdef CALC_MUCH_DETECTORS_EFF - Int_t mcPointsCount; - Int_t mcPointsTriggered; -#endif //CALC_MUCH_DETECTORS_EFF - - ClassDef(LxFinderTriplet, 1); -}; - -#endif //LX_INCLUDED diff --git a/reco/tracking/lxTriplet/LxCATriplets.cxx b/reco/tracking/lxTriplet/LxCATriplets.cxx deleted file mode 100644 index cae1aea8ac7a7f314c26a404e82a969c44de016c..0000000000000000000000000000000000000000 --- a/reco/tracking/lxTriplet/LxCATriplets.cxx +++ /dev/null @@ -1,854 +0,0 @@ -/* Copyright (C) 2016-2017 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#include "LxCATriplets.h" - -#include "base/CbmLitToolFactory.h" -#include "utils/CbmLitConverterFairTrackParam.h" - -#include <iostream> - -#include "kdtree++/kdtree.hpp" - -using namespace std; - -static Double_t errCoeffTripletRXs[] = {4.0, 4.0, 4.0, 4.0, 4.0, 4.0}; -static Double_t errCoeffTripletRYs[] = {4.0, 4.0, 4.0, 4.0, 4.0, 4.0}; -static Double_t errCoeffTripletRLXs[] = {4.0, 4.0, 4.0, 4.0, 4.0, 4.0}; -static Double_t errCoeffTripletRLYs[] = {4.0, 4.0, 4.0, 4.0, 4.0, 4.0}; -static Double_t errCoeffInterTripletXs[] = {4.0, 4.0, 4.0, 4.0, 4.0, 4.0}; -static Double_t errCoeffInterTripletYs[] = {4.0, 4.0, 4.0, 4.0, 4.0, 4.0}; -static Double_t errCoeffInterTripletTxs[] = {4.0, 4.0, 4.0, 4.0, 4.0, 4.0}; -static Double_t errCoeffInterTripletTys[] = {4.0, 4.0, 4.0, 4.0, 4.0, 4.0}; - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// LxPoint -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -LxPoint::~LxPoint() -{ - for (list<LxTriplet*>::iterator i = triplets.begin(); i != triplets.end(); ++i) - delete *i; - -#ifdef USE_SEGMENTS - for (list<LxSegment*>::iterator i = segments.begin(); i != segments.end(); ++i) - delete *i; -#endif //USE_SEGMENTS -} - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// LxLayer -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -struct KDTPointWrap { - LxPoint* point; - Double_t data[2]; - - explicit KDTPointWrap(LxPoint* p) : point(p) - { - data[0] = p->x; - data[1] = p->y; - } - - KDTPointWrap(Double_t x, Double_t y) : point(0) // This constructor is used when setting search-range bounds. - { - data[0] = x; - data[1] = y; - } - - // Stuff required by libkdtree++ - typedef Double_t value_type; - - value_type operator[](size_t n) const { return data[n]; } -}; - -typedef KDTree::KDTree<2, KDTPointWrap> KDTPointsStorageType; - -LxLayer::LxLayer(LxStation* Station, int LayerNumber) - : points_handle(0) - , zCoord(0) - , station(Station) - , layerNumber(LayerNumber) -{ - points_handle = new KDTPointsStorageType; -} - -LxLayer::~LxLayer() -{ - KDTPointsStorageType* points = static_cast<KDTPointsStorageType*>(points_handle); - Clear(); - delete points; -} - -void LxLayer::Clear() -{ - KDTPointsStorageType* points = static_cast<KDTPointsStorageType*>(points_handle); - - for (KDTPointsStorageType::iterator i = points->begin(); i != points->end(); ++i) { - KDTPointWrap& wrap = const_cast<KDTPointWrap&>(*i); - LxPoint* point = wrap.point; - delete point; - } - - points->clear(); -} - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// LxStation -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -LxStation::LxStation(LxSpace* sp, Int_t stN) - : space(sp) - , stationNumber(stN) - , zCoord(0) - , xDispLeft(0) - , yDispLeft(0) - , xDispRight(0) - , yDispRight(0) - , xDispLeft2(0) - , yDispLeft2(0) - , xDispRight2(0) - , yDispRight2(0) - , xDispRL(0) - , yDispRL(0) - , xDispRL2(0) - , yDispRL2(0) - , -#ifdef OUT_DISP_BY_TRIPLET_DIR - xOutDispTriplet(0) - , yOutDispTriplet(0) - , xOutDispTriplet2(0) - , yOutDispTriplet2(0) - , -#else //OUT_DISP_BY_TRIPLET_DIR - xOutDispVertex(0) - , yOutDispVertex(0) - , xOutDispVertex2(0) - , yOutDispVertex2(0) - , -#endif //OUT_DISP_BY_TRIPLET_DIR -#ifdef USE_SEGMENTS - txBreakLeft(0) - , tyBreakLeft(0) - , txBreakRight(0) - , tyBreakRight(0) - , txBreakLeft2(0) - , tyBreakLeft2(0) - , txBreakRight2(0) - , tyBreakRight2(0) - , txInterStationBreak(0) - , tyInterStationBreak(0) - , txInterStationBreak2(0) - , tyInterStationBreak2(0) - , -#else //USE_SEGMENTS - txInterTripletBreak(0) - , tyInterTripletBreak(0) - , txInterTripletBreak2(0) - , tyInterTripletBreak2(0) - , -#endif //USE_SEGMENTS - errCoeffTripletRX(errCoeffTripletRXs[stN]) - , errCoeffTripletRX2(errCoeffTripletRX * errCoeffTripletRX) - , errCoeffTripletRY(errCoeffTripletRYs[stN]) - , errCoeffTripletRY2(errCoeffTripletRY * errCoeffTripletRY) - , errCoeffTripletRLX(errCoeffTripletRLXs[stN]) - , errCoeffTripletRLX2(errCoeffTripletRLX * errCoeffTripletRLX) - , errCoeffTripletRLY(errCoeffTripletRLYs[stN]) - , errCoeffTripletRLY2(errCoeffTripletRLY * errCoeffTripletRLY) - , errCoeffInterTripletX(errCoeffInterTripletXs[stN]) - , errCoeffInterTripletX2(errCoeffInterTripletX * errCoeffInterTripletX) - , errCoeffInterTripletY(errCoeffInterTripletYs[stN]) - , errCoeffInterTripletY2(errCoeffInterTripletY * errCoeffInterTripletY) - , errCoeffInterTripletTx(errCoeffInterTripletTxs[stN]) - , errCoeffInterTripletTx2(errCoeffInterTripletTx * errCoeffInterTripletTx) - , errCoeffInterTripletTy(errCoeffInterTripletTys[stN]) - , errCoeffInterTripletTy2(errCoeffInterTripletTy * errCoeffInterTripletTy) -{ - for (Int_t i = 0; i < LXLAYERS; ++i) - layers[i] = new LxLayer(this, i); -} - -LxStation::~LxStation() -{ - for (Int_t i = 0; i < LXLAYERS; ++i) - delete layers[i]; -} - -void LxStation::Clear() -{ - for (Int_t i = 0; i < LXLAYERS; ++i) - layers[i]->Clear(); -} - -void LxStation::BuildTriplets() -{ - LxLayer* lLayer = layers[0]; - LxLayer* cLayer = layers[1]; - LxLayer* rLayer = layers[2]; - - KDTPointsStorageType* lPoints = static_cast<KDTPointsStorageType*>(lLayer->points_handle); - KDTPointsStorageType* cPoints = static_cast<KDTPointsStorageType*>(cLayer->points_handle); - KDTPointsStorageType* rPoints = static_cast<KDTPointsStorageType*>(rLayer->points_handle); - - //cout << "[" << stationNumber << "] LxStation::BuildTriplets() hit count: " << lPoints->size() << " : " << - //cPoints->size() << " : " << rPoints->size() << endl; - - Double_t lZCoord = lLayer->zCoord; - Double_t rZCoord = rLayer->zCoord; - - UInt_t tripletCount = 0; - - for (KDTPointsStorageType::iterator i = cPoints->begin(); i != cPoints->end(); ++i) { - KDTPointWrap& cWrap = const_cast<KDTPointWrap&>(*i); - LxPoint* cPoint = cWrap.point; - Double_t deltaZc = rZCoord - cPoint->z; - Double_t cTx = cPoint->x / cPoint->z; - Double_t cTy = cPoint->y / cPoint->z; - Double_t rX = cPoint->x + cTx * deltaZc; - Double_t rY = cPoint->y + cTy * deltaZc; - - // Search corresponding points at right layer. - Double_t rXLimit = errCoeffTripletRX * sqrt(xDispRight2 + 2 * cPoint->dx2); - Double_t rYLimit = errCoeffTripletRY * sqrt(yDispRight2 + 2 * cPoint->dy2); - KDTPointWrap rBoundsWrap(rX - rXLimit, rY - rYLimit); - KDTree::_Region<2, KDTPointWrap, Double_t, KDTree::_Bracket_accessor<KDTPointWrap>, - std::less<KDTree::_Bracket_accessor<KDTPointWrap>::result_type>> - rRange(rBoundsWrap); - rRange.set_low_bound(rBoundsWrap, 0); - rRange.set_low_bound(rBoundsWrap, 1); - rBoundsWrap.data[0] = rX + rXLimit; - rBoundsWrap.data[1] = rY + rYLimit; - rRange.set_high_bound(rBoundsWrap, 0); - rRange.set_high_bound(rBoundsWrap, 1); - list<KDTPointWrap> rNeighbours; - rPoints->find_within_range(rRange, back_insert_iterator<list<KDTPointWrap>>(rNeighbours)); - - for (list<KDTPointWrap>::iterator j = rNeighbours.begin(); j != rNeighbours.end(); ++j) { - KDTPointWrap& rWrap = *j; - LxPoint* rPoint = rWrap.point; - Double_t rDeltaX = rPoint->x - rX; - Double_t rDeltaY = rPoint->y - rY; - Double_t chi2R = rDeltaX * rDeltaX / (xDispRight2 + cPoint->dx2 + rPoint->dx2) - + rDeltaY * rDeltaY / (yDispRight2 + cPoint->dy2 + rPoint->dy2); - - // Search a point on left layer which corresponds to this pair of points: central and right. - Double_t deltaZr = rPoint->z - cPoint->z; - Double_t tx = (rPoint->x - cPoint->x) / deltaZr; - Double_t ty = (rPoint->y - cPoint->y) / deltaZr; - deltaZr = lZCoord - cPoint->z; - Double_t lX = cPoint->x + tx * deltaZr; - Double_t lY = cPoint->y + ty * deltaZr; - Double_t lXLimit = errCoeffTripletRLX * sqrt(xDispRL2 + 2 * cPoint->dx2 + rPoint->dx2); - Double_t lYLimit = errCoeffTripletRLY * sqrt(yDispRL2 + 2 * cPoint->dy2 + rPoint->dy2); - KDTPointWrap lBoundsWrap(lX - lXLimit, lY - lYLimit); - KDTree::_Region<2, KDTPointWrap, Double_t, KDTree::_Bracket_accessor<KDTPointWrap>, - std::less<KDTree::_Bracket_accessor<KDTPointWrap>::result_type>> - lRange(lBoundsWrap); - lRange.set_low_bound(lBoundsWrap, 0); - lRange.set_low_bound(lBoundsWrap, 1); - lBoundsWrap.data[0] = lX + lXLimit; - lBoundsWrap.data[1] = lY + lYLimit; - lRange.set_high_bound(lBoundsWrap, 0); - lRange.set_high_bound(lBoundsWrap, 1); - list<KDTPointWrap> lNeighbours; - lPoints->find_within_range(lRange, back_insert_iterator<list<KDTPointWrap>>(lNeighbours)); - - for (list<KDTPointWrap>::iterator k = lNeighbours.begin(); k != lNeighbours.end(); ++k) { - KDTPointWrap& lWrap = *k; - LxPoint* lPoint = lWrap.point; - Double_t lDeltaX = lPoint->x - lX; - Double_t lDeltaY = lPoint->y - lY; - Double_t chi2 = chi2R + lDeltaX * lDeltaX / (xDispRL2 + lPoint->dx2 + cPoint->dx2 + rPoint->dx2) - + lDeltaY * lDeltaY / (yDispRL2 + lPoint->dy2 + cPoint->dy2 + rPoint->dy2); - LxTriplet* triplet = new LxTriplet(lPoint, cPoint, rPoint, chi2); - cPoint->triplets.push_back(triplet); - ++tripletCount; - } - } - } - - //cout << "[" << stationNumber << "] LxStation::BuildTriplets() triplet count: " << tripletCount << endl; -} - -#ifdef USE_SEGMENTS - -void LxStation::BuildSegments() -{ - LxStation* lStation = space->stations[stationNumber - 1]; - Double_t lZCoord = lStation->zCoord; - KDTPointsStorageType* rPoints = static_cast<KDTPointsStorageType*>(layers[1]->points_handle); - KDTPointsStorageType* lPoints = static_cast<KDTPointsStorageType*>(lStation->layers[1]->points_handle); - - UInt_t segmentCount = 0; - - for (KDTPointsStorageType::iterator i = rPoints->begin(); i != rPoints->end(); ++i) { - KDTPointWrap& rWrap = const_cast<KDTPointWrap&>(*i); - LxPoint* rPoint = rWrap.point; - - if (rPoint->triplets.empty()) continue; - - // Search corresponding points at the left station. - Double_t txVertex = rPoint->x / rPoint->z; - Double_t tyVertex = rPoint->y / rPoint->z; - Double_t deltaZ = lZCoord - rPoint->z; - Double_t lX = rPoint->x + txVertex * deltaZ; - Double_t lY = rPoint->y + tyVertex * deltaZ; - Double_t lXLimit = errorXcoeff * sqrt(xOutDispVertex2 + 2 * rPoint->dx2); - Double_t lYLimit = errorYcoeff * sqrt(yOutDispVertex2 + 2 * rPoint->dy2); - KDTPointWrap lBoundsWrap(lX - lXLimit, lY - lYLimit); - KDTree::_Region<2, KDTPointWrap, Double_t, KDTree::_Bracket_accessor<KDTPointWrap>, - std::less<KDTree::_Bracket_accessor<KDTPointWrap>::result_type>> - lRange(lBoundsWrap); - lRange.set_low_bound(lBoundsWrap, 0); - lRange.set_low_bound(lBoundsWrap, 1); - lBoundsWrap.data[0] = lX + lXLimit; - lBoundsWrap.data[1] = lY + lYLimit; - lRange.set_high_bound(lBoundsWrap, 0); - lRange.set_high_bound(lBoundsWrap, 1); - list<KDTPointWrap> lNeighbours; - lPoints->find_within_range(lRange, back_insert_iterator<list<KDTPointWrap>>(lNeighbours)); - - for (list<KDTPointWrap>::iterator k = lNeighbours.begin(); k != lNeighbours.end(); ++k) { - KDTPointWrap& lWrap = *k; - LxPoint* lPoint = lWrap.point; - - if (lPoint->triplets.empty()) continue; - - deltaZ = lPoint->z - rPoint->z; - Double_t deltaZ2 = deltaZ * deltaZ; - Double_t tx = (lPoint->x - rPoint->x) / deltaZ; - Double_t ty = (lPoint->y - rPoint->y) / deltaZ; - Double_t dtx2 = (lPoint->dx2 + rPoint->dx2) / deltaZ2; - Double_t dty2 = (lPoint->dy2 + rPoint->dy2) / deltaZ2; - LxSegment* segment = 0; - - for (list<LxTriplet*>::iterator l = rPoint->triplets.begin(); l != rPoint->triplets.end(); ++l) { - LxTriplet* rTriplet = *l; - Double_t rDeltaTx = rTriplet->tx - tx; - Double_t rDeltaTx2 = rDeltaTx * rDeltaTx; - - if (rDeltaTx2 > errorTXcoeff2 * (txBreakLeft2 + dtx2 + rTriplet->dtx2)) continue; - - Double_t rDeltaTy = rTriplet->ty - ty; - Double_t rDeltaTy2 = rDeltaTy * rDeltaTy; - - if (rDeltaTy2 > errorTYcoeff2 * (tyBreakLeft2 + dty2 + rTriplet->dty2)) continue; - - for (list<LxTriplet*>::iterator m = lPoint->triplets.begin(); m != lPoint->triplets.end(); ++m) { - LxTriplet* lTriplet = *m; - Double_t lDeltaTx = lTriplet->tx - tx; - Double_t lDeltaTx2 = lDeltaTx * rDeltaTx; - - if (lDeltaTx2 > errorTXcoeff2 * (txBreakRight2 + dtx2 + lTriplet->dtx2)) continue; - - Double_t lDeltaTy = lTriplet->ty - ty; - Double_t lDeltaTy2 = lDeltaTy * rDeltaTy; - - if (lDeltaTy2 > errorTYcoeff2 * (tyBreakRight2 + dty2 + lTriplet->dty2)) continue; - - if (0 == segment) { - Double_t lDeltaX = lPoint->x - lX; - Double_t lDeltaY = lPoint->y - lY; - Double_t chi2 = lDeltaX * lDeltaX / (xOutDispVertex2 + lPoint->dx2 + rPoint->dx2) - + lDeltaY * lDeltaY / (yOutDispVertex2 + lPoint->dy2 + rPoint->dy2); - segment = new LxSegment(rPoint, lPoint, tx, ty, dtx2, dty2, chi2); - rPoint->segments.push_back(segment); - ++segmentCount; - } - - segment->neighbours.push_back(lTriplet); - rTriplet->neighbours.push_back(segment); - } - } - } - } - - //cout << "[" << stationNumber << "] LxStation::BuildSegments() segment count: " << segmentCount << endl; -} - -#else //USE_SEGMENTS - -#ifdef OUT_DISP_BY_TRIPLET_DIR - -void LxStation::ConnectTriplets() -{ - LxStation* lStation = space->stations[stationNumber - 1]; - Double_t lZCoord = lStation->zCoord; - KDTPointsStorageType* rPoints = static_cast<KDTPointsStorageType*>(layers[1]->points_handle); - KDTPointsStorageType* lPoints = static_cast<KDTPointsStorageType*>(lStation->layers[1]->points_handle); - - for (KDTPointsStorageType::iterator i = rPoints->begin(); i != rPoints->end(); ++i) { - KDTPointWrap& rWrap = const_cast<KDTPointWrap&>(*i); - LxPoint* rPoint = rWrap.point; - - for (list<LxTriplet*>::iterator j = rPoint->triplets.begin(); j != rPoint->triplets.end(); ++j) { - LxTriplet* rTriplet = *j; - Double_t deltaZ = lZCoord - rPoint->z; - Double_t lX = rPoint->x + rTriplet->tx * deltaZ; - Double_t lY = rPoint->y + rTriplet->ty * deltaZ; - Double_t lXLimit = errorXcoeff * sqrt(xOutDispTriplet2 + 2 * rPoint->dx2); - Double_t lYLimit = errorYcoeff * sqrt(yOutDispTriplet2 + 2 * rPoint->dy2); - KDTPointWrap lBoundsWrap(lX - lXLimit, lY - lYLimit); - KDTree::_Region<2, KDTPointWrap, Double_t, KDTree::_Bracket_accessor<KDTPointWrap>, - std::less<KDTree::_Bracket_accessor<KDTPointWrap>::result_type>> - lRange(lBoundsWrap); - lRange.set_low_bound(lBoundsWrap, 0); - lRange.set_low_bound(lBoundsWrap, 1); - lBoundsWrap.data[0] = lX + lXLimit; - lBoundsWrap.data[1] = lY + lYLimit; - lRange.set_high_bound(lBoundsWrap, 0); - lRange.set_high_bound(lBoundsWrap, 1); - list<KDTPointWrap> lNeighbours; - lPoints->find_within_range(lRange, back_insert_iterator<list<KDTPointWrap>>(lNeighbours)); - - for (list<KDTPointWrap>::iterator k = lNeighbours.begin(); k != lNeighbours.end(); ++k) { - KDTPointWrap& lWrap = *k; - LxPoint* lPoint = lWrap.point; - - for (list<LxTriplet*>::iterator l = lPoint->triplets.begin(); l != lPoint->triplets.end(); ++l) { - LxTriplet* lTriplet = *l; - Double_t txBreak = lTriplet->tx - rTriplet->tx; - Double_t txBreak2 = txBreak * txBreak; - - if (txBreak2 > errorTXcoeff2 * (txInterTripletBreak2 + lTriplet->dtx2 + rTriplet->dtx2)) continue; - - Double_t tyBreak = lTriplet->ty - rTriplet->ty; - Double_t tyBreak2 = tyBreak * tyBreak; - - if (tyBreak2 > errorTYcoeff2 * (tyInterTripletBreak2 + lTriplet->dty2 + rTriplet->dty2)) continue; - - Double_t lDeltaX = lPoint->x - lX; - Double_t lDeltaX2 = lDeltaX * lDeltaX; - Double_t lDeltaY = lPoint->y - lY; - Double_t lDeltaY2 = lDeltaY * lDeltaY; - Double_t chi2 = lDeltaX2 / (xOutDispTriplet2 + lPoint->dx2 + rPoint->dx2) - + lDeltaY2 / (yOutDispTriplet2 + lPoint->dy2 + rPoint->dy2) - + txBreak2 / (txInterTripletBreak2 + lTriplet->dtx2 + rTriplet->dtx2) - + tyBreak2 / (tyInterTripletBreak2 + lTriplet->dty2 + rTriplet->dty2); - rTriplet->neighbours.push_back(make_pair(lTriplet, chi2)); - } - } - } - } -} - -#else //OUT_DISP_BY_TRIPLET_DIR - -void LxStation::ConnectTriplets() -{ - LxStation* lStation = space->stations[stationNumber - 1]; - Double_t lZCoord = lStation->zCoord; - KDTPointsStorageType* rPoints = static_cast<KDTPointsStorageType*>(layers[1]->points_handle); - KDTPointsStorageType* lPoints = static_cast<KDTPointsStorageType*>(lStation->layers[1]->points_handle); - - for (KDTPointsStorageType::iterator i = rPoints->begin(); i != rPoints->end(); ++i) { - KDTPointWrap& rWrap = const_cast<KDTPointWrap&>(*i); - LxPoint* rPoint = rWrap.point; - - if (rPoint->triplets.empty()) continue; - - // Search corresponding points at the left station. - Double_t txVertex = rPoint->x / rPoint->z; - Double_t tyVertex = rPoint->y / rPoint->z; - Double_t deltaZ = lZCoord - rPoint->z; - Double_t lX = rPoint->x + txVertex * deltaZ; - Double_t lY = rPoint->y + tyVertex * deltaZ; - //Double_t scatCoeff2 = 1 + txVertex * txVertex + tyVertex * tyVertex; - Double_t lXLimit = errCoeffInterTripletX * sqrt(/*scatCoeff2 * */ xOutDispVertex2 + 2 * rPoint->dx2); - Double_t lYLimit = errCoeffInterTripletY * sqrt(/*scatCoeff2 * */ yOutDispVertex2 + 2 * rPoint->dy2); - KDTPointWrap lBoundsWrap(lX - lXLimit, lY - lYLimit); - KDTree::_Region<2, KDTPointWrap, Double_t, KDTree::_Bracket_accessor<KDTPointWrap>, - std::less<KDTree::_Bracket_accessor<KDTPointWrap>::result_type>> - lRange(lBoundsWrap); - lRange.set_low_bound(lBoundsWrap, 0); - lRange.set_low_bound(lBoundsWrap, 1); - lBoundsWrap.data[0] = lX + lXLimit; - lBoundsWrap.data[1] = lY + lYLimit; - lRange.set_high_bound(lBoundsWrap, 0); - lRange.set_high_bound(lBoundsWrap, 1); - list<KDTPointWrap> lNeighbours; - lPoints->find_within_range(lRange, back_insert_iterator<list<KDTPointWrap>>(lNeighbours)); - - for (list<KDTPointWrap>::iterator k = lNeighbours.begin(); k != lNeighbours.end(); ++k) { - KDTPointWrap& lWrap = *k; - LxPoint* lPoint = lWrap.point; - - if (lPoint->triplets.empty()) continue; - - for (list<LxTriplet*>::iterator l = rPoint->triplets.begin(); l != rPoint->triplets.end(); ++l) { - LxTriplet* rTriplet = *l; - - for (list<LxTriplet*>::iterator m = lPoint->triplets.begin(); m != lPoint->triplets.end(); ++m) { - LxTriplet* lTriplet = *m; - Double_t txBreak = lTriplet->tx - rTriplet->tx; - Double_t txBreak2 = txBreak * txBreak; - - if (txBreak2 > errCoeffInterTripletTx2 * (txInterTripletBreak2 + lTriplet->dtx2 + rTriplet->dtx2)) continue; - - Double_t tyBreak = lTriplet->ty - rTriplet->ty; - Double_t tyBreak2 = tyBreak * tyBreak; - - if (tyBreak2 > errCoeffInterTripletTy2 * (tyInterTripletBreak2 + lTriplet->dty2 + rTriplet->dty2)) continue; - - Double_t lDeltaX = lPoint->x - lX; - Double_t lDeltaX2 = lDeltaX * lDeltaX; - Double_t lDeltaY = lPoint->y - lY; - Double_t lDeltaY2 = lDeltaY * lDeltaY; - Double_t chi2 = lDeltaX2 / (/*scatCoeff2 * */ xOutDispVertex2 + lPoint->dx2 + rPoint->dx2) - + // Comment to improve suppression ration. - lDeltaY2 / (/*scatCoeff2 * */ yOutDispVertex2 + lPoint->dy2 + rPoint->dy2) - + // Comment to improve suppression ration. - txBreak2 / (txInterTripletBreak2 + lTriplet->dtx2 + rTriplet->dtx2) - + tyBreak2 / (tyInterTripletBreak2 + lTriplet->dty2 + rTriplet->dty2); - rTriplet->neighbours.push_back(make_pair(lTriplet, chi2)); - } - } - } - } -} - -#endif //OUT_DISP_BY_TRIPLET_DIR - -#endif //USE_SEGMENTS - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// LxTrack -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -void LxTrack::Rebind() -{ - externalTrack = 0; - - for (list<pair<LxExtTrack*, Double_t>>::iterator i = extTrackCandidates.begin(); i != extTrackCandidates.end(); ++i) { - LxExtTrack* extTrack = i->first; - Double_t aChi2 = i->second; - - if (0 == extTrack->recoTrack.first) { - extTrack->recoTrack.first = this; - extTrack->recoTrack.second = aChi2; - externalTrack = extTrack; - break; - } - else if (aChi2 < extTrack->recoTrack.second) { - LxTrack* anotherTrack = extTrack->recoTrack.first; - extTrack->recoTrack.first = this; - extTrack->recoTrack.second = aChi2; - externalTrack = extTrack; - anotherTrack->Rebind(); - break; - } - } -} - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// LxSpace -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -LxSpace::LxSpace() : stationsInAlgo(LXSTATIONS) -{ - for (Int_t i = 0; i < LXSTATIONS; ++i) - stations[i] = new LxStation(this, i); -} - -LxSpace::~LxSpace() -{ - Clear(); - - for (Int_t i = 0; i < LXSTATIONS; ++i) - delete stations[i]; -} - -void LxSpace::Clear() -{ - for (Int_t i = 0; i < LXSTATIONS; ++i) - stations[i]->Clear(); - - for (list<LxTrack*>::iterator i = tracks.begin(); i != tracks.end(); ++i) - delete *i; - - tracks.clear(); - extTracks.clear(); -} - -void LxSpace::BuildTriplets() -{ - for (Int_t i = 0; i < LXSTATIONS; ++i) - stations[i]->BuildTriplets(); -} - -#ifdef USE_SEGMENTS - -void LxSpace::BuildSegments() -{ - for (Int_t i = 1; i < LXSTATIONS; ++i) - stations[i]->BuildSegments(); -} - -#else //USE_SEGMENTS - -void LxSpace::ConnectTriplets() -{ - for (Int_t i = 1; i < LXSTATIONS; ++i) - stations[i]->ConnectTriplets(); -} - -#endif //USE_SEGMENTS - -#ifdef USE_SEGMENTS -void LxSpace::BuildCandidates(LxTriplet* begin, LxTriplet* triplet, pair<LxSegment*, LxTriplet*>* branches, - list<LxTrackCandidate*>& candidates, Int_t level, Double_t chi2) -{ - for (list<LxSegment*>::iterator i = triplet->neighbours.begin(); i != triplet->neighbours.end(); ++i) { - LxSegment* segment = *i; - LxStation* lStation = stations[level - 1]; - LxStation* rStation = stations[level]; - Double_t dtx_1 = segment->tx - triplet->tx; - Double_t dty_1 = segment->ty - triplet->ty; - Double_t chi2_1 = chi2 + segment->chi2 + dtx_1 * dtx_1 / (rStation->txBreakLeft2 + triplet->dtx2 + segment->dtx2) - + dty_1 * dty_1 / (rStation->tyBreakLeft2 + triplet->dty2 + segment->dty2); - - if (false && level < LXSTATIONS - 1) { - LxSegment* rSegment = branches[level].first; - Double_t dtx_1_s = abs(segment->tx - rSegment->tx); - Double_t slopeCoeff2 = 1 + rSegment->tx * rSegment->tx + rSegment->ty * rSegment->ty; - Double_t segTxSigma2 = rStation->txInterStationBreak2 * slopeCoeff2 + segment->dtx2 + rSegment->dtx2; - - if (dtx_1_s > errorTXcoeff * sqrt(segTxSigma2)) continue; - - Double_t dty_1_s = abs(segment->ty - rSegment->ty); - Double_t segTySigma2 = rStation->tyInterStationBreak2 * slopeCoeff2 + segment->dty2 + rSegment->dty2; - - if (dty_1_s > errorTYcoeff * sqrt(segTySigma2)) continue; - - chi2_1 += dtx_1_s * dtx_1_s / segTxSigma2 + dty_1_s * dty_1_s / segTySigma2; - } - - for (list<LxTriplet*>::iterator j = segment->neighbours.begin(); j != segment->neighbours.end(); ++j) { - LxTriplet* triplet2 = *j; - - if (triplet2->left->used || triplet2->center->used || triplet2->right->used) continue; - - Double_t dtx_2 = triplet2->tx - segment->tx; - Double_t dty_2 = triplet2->ty - segment->ty; - Double_t chi2_2 = chi2_1 + triplet2->chi2 - + dtx_2 * dtx_2 / (lStation->txBreakRight2 + segment->dtx2 + triplet2->dtx2) - + dty_2 * dty_2 / (lStation->tyBreakRight2 + segment->dty2 + triplet2->dty2); - branches[level - 1] = make_pair(segment, triplet2); - - if (1 == level) { - LxTrackCandidate* trackCandidate = new LxTrackCandidate(begin, branches, chi2_2); - candidates.push_back(trackCandidate); - } - else - BuildCandidates(begin, triplet2, branches, candidates, level - 1, chi2_2); - } - } -} -#else //USE_SEGMENTS -void LxSpace::BuildCandidates(Int_t endStNum, LxTriplet* triplet, LxTriplet** branches, - list<LxTrackCandidate*>& candidates, Int_t level, Double_t chi2) -{ - for (list<pair<LxTriplet*, Double_t>>::iterator i = triplet->neighbours.begin(); i != triplet->neighbours.end(); - ++i) { - pair<LxTriplet*, Double_t>& tc2 = *i; - LxTriplet* triplet2 = tc2.first; - - if (triplet2->left->used || triplet2->center->used || triplet2->right->used) continue; - - branches[level - 1] = triplet2; - - if (1 == level) { - LxTrackCandidate* trackCandidate = new LxTrackCandidate(endStNum, branches, chi2 + tc2.second + triplet2->chi2); - candidates.push_back(trackCandidate); - } - else - BuildCandidates(endStNum, triplet2, branches, candidates, level - 1, chi2 + tc2.second + triplet2->chi2); - } -} -#endif //USE_SEGMENTS - -void LxSpace::Reconstruct() -{ - BuildTriplets(); -#ifdef USE_SEGMENTS - BuildSegments(); -#else //USE_SEGMENTS - ConnectTriplets(); -#endif //USE_SEGMENTS - - for (int endStNum = LXSTATIONS - 1; endStNum >= stationsInAlgo - 1; --endStNum) { - LxStation* startStation = stations[endStNum]; - KDTPointsStorageType* points = static_cast<KDTPointsStorageType*>(startStation->layers[1]->points_handle); - - for (KDTPointsStorageType::iterator i = points->begin(); i != points->end(); ++i) { - KDTPointWrap& wrap = const_cast<KDTPointWrap&>(*i); - LxPoint* point = wrap.point; - list<LxTrackCandidate*> candidates; - //cout << "LxSpace::Reconstruct(): track candidate maximum size: " << candidates.max_size() << endl; - - for (list<LxTriplet*>::iterator j = point->triplets.begin(); j != point->triplets.end(); ++j) { - LxTriplet* triplet = *j; - - if (triplet->left->used || triplet->center->used || triplet->right->used) continue; - - Double_t chi2 = triplet->chi2; -#ifdef USE_SEGMENTS - pair<LxSegment*, LxTriplet*> branches[LXSTATIONS - 1]; - BuildCandidates(triplet, triplet, branches, candidates, LXSTATIONS - 1, chi2); -#else //USE_SEGMENTS - LxTriplet* branches[endStNum + 1]; - branches[endStNum] = triplet; - BuildCandidates(endStNum, triplet, branches, candidates, endStNum, chi2); -#endif //USE_SEGMENTS - } - - cout << "LxSpace::Reconstruct(): track candidate number: " << candidates.size() << endl; - - LxTrackCandidate* bestCandidate = 0; - - for (list<LxTrackCandidate*>::iterator j = candidates.begin(); j != candidates.end(); ++j) { - LxTrackCandidate* candidate = *j; - - if (0 == bestCandidate || candidate->chi2 < bestCandidate->chi2) bestCandidate = candidate; - } - - if (0 != bestCandidate) { - LxTrack* track = new LxTrack(bestCandidate); - tracks.push_back(track); - } - - for (list<LxTrackCandidate*>::iterator j = candidates.begin(); j != candidates.end(); ++j) - delete *j; - } // for (KDTPointsStorageType::iterator i = points->begin(); i != points->end(); ++i) - } // for (int endStNum = LXSTATIONS - 1; endStNum >= stationsInAlgo - 1; --endStNum) - - RemoveClones(); -} - -void LxSpace::RemoveClones() -{ - for (list<LxTrack*>::iterator i = tracks.begin(); i != tracks.end(); ++i) { - LxTrack* firstTrack = *i; - list<LxTrack*>::iterator i2 = i; - ++i2; - - for (; i2 != tracks.end(); ++i2) { - LxTrack* secondTrack = *i2; - Int_t neighbourPoints = 0; - Int_t minLen = firstTrack->length < secondTrack->length ? firstTrack->length : secondTrack->length; - Int_t minPoints = minLen * LXLAYERS; - - for (Int_t j = 0; j < LXSTATIONS * LXLAYERS; ++j) { - if (j >= minPoints) continue; - - LxPoint* point1 = firstTrack->points[j]; - LxPoint* point2 = secondTrack->points[j]; - - Double_t dx = point1->dx > point2->dx ? point1->dx : point2->dx; - Double_t dy = point1->dy > point2->dy ? point1->dy : point2->dy; - - if (abs(point2->x - point1->x) < 5.0 * dx && abs(point2->y - point1->y) < 5.0 * dy) ++neighbourPoints; - } - - if (neighbourPoints < minPoints / 2) continue; - - if (firstTrack->length > secondTrack->length) secondTrack->clone = true; - else if (secondTrack->length > firstTrack->length) - firstTrack->clone = true; - else if (firstTrack->chi2 < secondTrack->chi2) - secondTrack->clone = true; - else - firstTrack->clone = true; - } // for (; i2 != tracks.end(); ++i2) - } // for (list<LxTrack*>::iterator i = tracks.begin(); i != tracks.end(); ++i) -} - -void LxSpace::JoinExtTracks() -{ - Double_t cutCoeff = 5.0; - - TrackPropagatorPtr fPropagator = CbmLitToolFactory::CreateTrackPropagator("lit"); - - for (list<LxTrack*>::iterator i = tracks.begin(); i != tracks.end(); ++i) { - LxTrack* track = *i; - - if (track->clone) continue; - - LxTriplet* leftTriplet = track->branches[0]; - LxPoint* muchPoint = leftTriplet->center; - - for (list<LxExtTrack>::iterator j = extTracks.begin(); j != extTracks.end(); ++j) { - LxExtTrack* extTrack = &(*j); - const FairTrackParam* lastL1Param = extTrack->track->GetParamLast(); - CbmLitTrackParam lastParam; - CbmLitConverterFairTrackParam::FairTrackParamToCbmLitTrackParam(lastL1Param, &lastParam); - - if (kLITERROR == fPropagator->Propagate(&lastParam, stations[0]->zCoord, 13)) continue; - - Double_t deltaX = abs(lastParam.GetX() - muchPoint->x); - Double_t deltaY = abs(lastParam.GetY() - muchPoint->y); - Double_t deltaTx = abs(lastParam.GetTx() - leftTriplet->tx); - Double_t deltaTy = abs(lastParam.GetTy() - leftTriplet->ty); - Double_t sigmaX2 = muchPoint->dx2 + lastParam.GetCovariance(0); - Double_t sigmaX = sqrt(sigmaX2); - Double_t sigmaY2 = muchPoint->dy2 + lastParam.GetCovariance(6); - Double_t sigmaY = sqrt(sigmaY2); - Double_t sigmaTx2 = leftTriplet->dtx2 + lastParam.GetCovariance(11); - Double_t sigmaTx = sqrt(sigmaTx2); - Double_t sigmaTy2 = leftTriplet->dty2 + lastParam.GetCovariance(15); - Double_t sigmaTy = sqrt(sigmaTy2); - - if (deltaX > cutCoeff * sigmaX || deltaY > cutCoeff * sigmaY || deltaTx > cutCoeff * sigmaTx - || deltaTy > cutCoeff * sigmaTy) { - continue; - } - - Double_t chi2 = deltaX * deltaX / sigmaX2 + deltaY * deltaY / sigmaY2 + deltaTx * deltaTx / sigmaTx2 - + deltaTy * deltaTy / sigmaTy2; - - list<pair<LxExtTrack*, Double_t>>::iterator k = track->extTrackCandidates.begin(); - - for (; k != track->extTrackCandidates.end() && chi2 >= k->second; ++k) - ; - - pair<LxExtTrack*, Double_t> linkDesc(extTrack, chi2); - track->extTrackCandidates.insert(k, linkDesc); - } // for (list<LxExtTrack>::iterator j = extTracks.begin(); j != extTracks.end(); ++j) - - for (list<pair<LxExtTrack*, Double_t>>::iterator j = track->extTrackCandidates.begin(); - j != track->extTrackCandidates.end(); ++j) { - LxExtTrack* extTrack = j->first; - Double_t chi2 = j->second; - - if (0 == extTrack->recoTrack.first) { - extTrack->recoTrack.first = track; - extTrack->recoTrack.second = chi2; - track->externalTrack = extTrack; - break; - } - else if (chi2 < extTrack->recoTrack.second) { - LxTrack* anotherTrack = extTrack->recoTrack.first; - extTrack->recoTrack.first = track; - extTrack->recoTrack.second = chi2; - track->externalTrack = extTrack; - anotherTrack->Rebind(); - break; - } - } - } -} - -void LxSpace::FitTracks() {} - -LxPoint* LxSpace::AddPoint(Int_t stationNumber, Int_t layerNumber, Int_t hitId, Double_t x, Double_t y, Double_t z, - Double_t dx, Double_t dy, Double_t dz) -{ - LxLayer* layer = stations[stationNumber]->layers[layerNumber]; - LxPoint* point = new LxPoint(x, y, z, dx, dy, dz, layer, hitId); - KDTPointsStorageType* points = static_cast<KDTPointsStorageType*>(layer->points_handle); - KDTPointWrap pointWrap(point); - points->insert(pointWrap); - return point; -} diff --git a/reco/tracking/lxTriplet/LxCATriplets.h b/reco/tracking/lxTriplet/LxCATriplets.h deleted file mode 100644 index ef0da813edc8c6acdf2f45d452b626cd8ec0d1f3..0000000000000000000000000000000000000000 --- a/reco/tracking/lxTriplet/LxCATriplets.h +++ /dev/null @@ -1,363 +0,0 @@ -/* Copyright (C) 2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifndef LXCATRIPLETS_INCLUDED -#define LXCATRIPLETS_INCLUDED - -#pragma GCC diagnostic ignored "-Weffc++" - -#include "Rtypes.h" - -#include <list> - -#include <cmath> - -#include "LxMC.h" -#include "LxSettings.h" - -struct LxTriplet; -#ifdef USE_SEGMENTS -struct LxSegment; -#endif //USE_SEGMENTS -struct LxLayer; -struct LxTrack; - -struct LxPoint { - Double_t x, y, z; - Double_t dx, dy, dz; - Double_t dx2, dy2, dz2; - bool used; - LxLayer* layer; - Int_t hitId; - LxTrack* track; - std::list<LxTriplet*> triplets; -#ifdef USE_SEGMENTS - std::list<LxSegment*> segments; -#endif //USE_SEGMENTS -#ifdef MAKE_EFF_CALC - std::list<LxMCPoint*> mcPoints; -#endif //MAKE_EFF_CALC - - LxPoint(Double_t X, Double_t Y, Double_t Z, Double_t Dx, Double_t Dy, Double_t Dz, LxLayer* Layer, Int_t HitId) - : x(X) - , y(Y) - , z(Z) - , dx(Dx) - , dy(Dy) - , dz(Dz) - , dx2(Dx * Dx) - , dy2(Dy * Dy) - , dz2(Dz * Dz) - , used(false) - , layer(Layer) - , hitId(HitId) - , track(0) - { - } - ~LxPoint(); -}; - -struct LxTriplet { - LxPoint* left; - LxPoint* center; - LxPoint* right; - Double_t deltaZ; - Double_t deltaZ2; - Double_t tx; - Double_t ty; - Double_t dtx2; - Double_t dty2; - Double_t dtx; - Double_t dty; - Double_t chi2; -#ifdef USE_SEGMENTS - std::list<LxSegment*> neighbours; -#else //USE_SEGMENTS - std::list<std::pair<LxTriplet*, Double_t>> neighbours; -#endif //USE_SEGMENTS - - LxTriplet(LxPoint* l, LxPoint* c, LxPoint* r, Double_t c2) - : left(l) - , center(c) - , right(r) - , deltaZ(r->z - l->z) - , deltaZ2(deltaZ * deltaZ) - , tx((r->x - l->x) / deltaZ) - , ty((r->y - l->y) / deltaZ) - , dtx2((l->dx2 + r->dx2) / deltaZ2) - , dty2((l->dy2 + r->dy2) / deltaZ2) - , dtx(sqrt(dtx2)) - , dty(sqrt(dty2)) - , chi2(c2) - { - } -}; - -#ifdef USE_SEGMENTS -struct LxSegment { - LxPoint* source; - LxPoint* end; - Double_t tx; - Double_t ty; - Double_t dtx; - Double_t dty; - Double_t dtx2; - Double_t dty2; - Double_t chi2; - std::list<LxTriplet*> neighbours; - - LxSegment(LxPoint* s, LxPoint* e, Double_t Tx, Double_t Ty, Double_t Dtx2, Double_t Dty2, Double_t Chi2) - : source(s) - , end(e) - , tx(Tx) - , ty(Ty) - , dtx2(Dtx2) - , dty2(Dty2) - , dtx(sqrt(Dtx2)) - , dty(sqrt(Dty2)) - , chi2(Chi2) - { - } -}; -#endif //USE_SEGMENTS - -struct LxStation; - -typedef void* kdt_points_handle; - -struct LxLayer { - kdt_points_handle points_handle; - Double_t zCoord; - LxStation* station; - Int_t layerNumber; - - LxLayer(LxStation* Station, int LayerNumber); - ~LxLayer(); - void Clear(); -}; - -struct LxSpace; - -struct LxStation { - LxSpace* space; - Int_t stationNumber; - Double_t zCoord; - LxLayer* layers[LXLAYERS]; - Double_t xDispLeft; - Double_t yDispLeft; - Double_t xDispRight; - Double_t yDispRight; - Double_t xDispLeft2; - Double_t yDispLeft2; - Double_t xDispRight2; - Double_t yDispRight2; - - Double_t xDispRL; - Double_t yDispRL; - Double_t xDispRL2; - Double_t yDispRL2; - -#ifdef OUT_DISP_BY_TRIPLET_DIR - Double_t xOutDispTriplet; - Double_t yOutDispTriplet; - Double_t xOutDispTriplet2; - Double_t yOutDispTriplet2; -#else //OUT_DISP_BY_TRIPLET_DIR - Double_t xOutDispVertex; - Double_t yOutDispVertex; - Double_t xOutDispVertex2; - Double_t yOutDispVertex2; -#endif //OUT_DISP_BY_TRIPLET_DIR - -#ifdef USE_SEGMENTS - Double_t txBreakLeft; - Double_t tyBreakLeft; - Double_t txBreakRight; - Double_t tyBreakRight; - Double_t txBreakLeft2; - Double_t tyBreakLeft2; - Double_t txBreakRight2; - Double_t tyBreakRight2; - - Double_t txInterStationBreak; - Double_t tyInterStationBreak; - Double_t txInterStationBreak2; - Double_t tyInterStationBreak2; -#else //USE_SEGMENTS - Double_t txInterTripletBreak; - Double_t tyInterTripletBreak; - Double_t txInterTripletBreak2; - Double_t tyInterTripletBreak2; -#endif //USE_SEGMENTS - - Double_t errCoeffTripletRX; - Double_t errCoeffTripletRX2; - Double_t errCoeffTripletRY; - Double_t errCoeffTripletRY2; - Double_t errCoeffTripletRLX; - Double_t errCoeffTripletRLX2; - Double_t errCoeffTripletRLY; - Double_t errCoeffTripletRLY2; - Double_t errCoeffInterTripletX; - Double_t errCoeffInterTripletX2; - Double_t errCoeffInterTripletY; - Double_t errCoeffInterTripletY2; - Double_t errCoeffInterTripletTx; - Double_t errCoeffInterTripletTx2; - Double_t errCoeffInterTripletTy; - Double_t errCoeffInterTripletTy2; - - LxStation(LxSpace* sp, Int_t stN); - ~LxStation(); - void Clear(); - void BuildTriplets(); -#ifdef USE_SEGMENTS - void BuildSegments(); -#else //USE_SEGMENTS - void ConnectTriplets(); -#endif //USE_SEGMENTS -}; - -struct LxTrackCandidate { -#ifdef USE_SEGMENTS - LxTriplet* begin; - std::pair<LxSegment*, LxTriplet*> branches[LXSTATIONS - 1]; -#else //USE_SEGMENTS - LxTriplet* branches[LXSTATIONS]; -#endif //USE_SEGMENTS - Double_t chi2; - Int_t length; - -#ifdef USE_SEGMENTS - LxTrackCandidate(LxTriplet* Begin, std::pair<LxSegment*, LxTriplet*>* Branches, Double_t Chi2) - : begin(Begin) - , chi2(Chi2) - { - for (Int_t i = 0; i < LXSTATIONS - 1; ++i) - branches[i] = Branches[i]; - } -#else //USE_SEGMENTS - LxTrackCandidate(Int_t len, LxTriplet** Branches, Double_t Chi2) : chi2(Chi2), length(len) - { - for (Int_t i = 0; i < length; ++i) - branches[i] = Branches[i]; - } -#endif //USE_SEGMENTS -}; - -struct LxExtTrack { - CbmStsTrack* track; - Int_t extId; - LxMCTrack* mcTrack; - std::pair<LxTrack*, Double_t> recoTrack; - - LxExtTrack() : track(0), extId(-1), mcTrack(0), recoTrack(0, 0) {} -}; - -struct LxTrack { -#ifdef USE_SEGMENTS - LxTriplet* begin; - std::pair<LxSegment*, LxTriplet*> branches[LXSTATIONS - 1]; -#else //USE_SEGMENTS - LxTriplet* branches[LXSTATIONS]; -#endif //USE_SEGMENTS - Double_t chi2; - LxExtTrack* externalTrack; - std::list<std::pair<LxExtTrack*, Double_t>> extTrackCandidates; - bool matched; - LxMCTrack* mcTrack; - LxPoint* points[LXSTATIONS * LXLAYERS]; -#ifdef CALC_LINK_WITH_STS_EFF - std::list<LxMCTrack*> mcTracks; -#endif //CALC_LINK_WITH_STS_EFF - bool clone; - Int_t length; - - explicit LxTrack(LxTrackCandidate* trackCandidate) - : -#ifdef USE_SEGMENTS - begin(trackCandidate->begin) - , -#endif //USE_SEGMENTS - chi2(trackCandidate->chi2) - , externalTrack(0) - , matched(false) - , mcTrack(0) - , clone(false) - , length(trackCandidate->length) - { -#ifdef USE_SEGMENTS - begin->left->used = true; - begin->left->track = this; - begin->center->used = true; - begin->center->track = this; - begin->right->used = true; - begin->right->track = this; - points[(LXSTATIONS - 1) * LXLAYERS] = begin->left; - points[(LXSTATIONS - 1) * LXLAYERS + 1] = begin->center; - points[(LXSTATIONS - 1) * LXLAYERS + 2] = begin->right; -#endif //USE_SEGMENTS - -#ifdef USE_SEGMENTS - for (Int_t i = 0; i < LXSTATIONS - 1; ++i) -#else //USE_SEGMENTS - for (Int_t i = 0; i < length; ++i) -#endif //USE_SEGMENTS - { - branches[i] = trackCandidate->branches[i]; -#ifdef USE_SEGMENTS - LxTriplet* triplet = branches[i].second; -#else //USE_SEGMENTS - LxTriplet* triplet = branches[i]; -#endif //USE_SEGMENTS - triplet->left->used = true; - triplet->left->track = this; - triplet->center->used = true; - triplet->center->track = this; - triplet->right->used = true; - triplet->right->track = this; - points[i * LXLAYERS] = triplet->left; - points[i * LXLAYERS + 1] = triplet->center; - points[i * LXLAYERS + 2] = triplet->right; - } - - for (Int_t i = length; i < LXSTATIONS; ++i) { - branches[i] = 0; - points[i * LXLAYERS] = 0; - points[i * LXLAYERS + 1] = 0; - points[i * LXLAYERS + 2] = 0; - } - } - - void Rebind(); -}; - -struct LxSpace { - LxStation* stations[LXSTATIONS]; - std::list<LxTrack*> tracks; - std::list<LxExtTrack> extTracks; - Int_t stationsInAlgo; - - LxSpace(); - ~LxSpace(); - void Clear(); - void BuildTriplets(); -#ifdef USE_SEGMENTS - void BuildSegments(); - void BuildCandidates(LxTriplet* begin, LxTriplet* triplet, std::pair<LxSegment*, LxTriplet*>* branches, - std::list<LxTrackCandidate*>& candidates, Int_t level, Double_t chi2); -#else //USE_SEGMENTS - void ConnectTriplets(); - void BuildCandidates(Int_t endStNum, LxTriplet* triplet, LxTriplet** branches, - std::list<LxTrackCandidate*>& candidates, Int_t level, Double_t chi2); -#endif //USE_SEGMENTS - void RemoveClones(); - void Reconstruct(); - void JoinExtTracks(); - void FitTracks(); - LxPoint* AddPoint(Int_t stationNumber, Int_t layerNumber, Int_t hitId, Double_t x, Double_t y, Double_t z, - Double_t dx, Double_t dy, Double_t dz); -}; - -#endif //LXCATRIPLETS_INCLUDED diff --git a/reco/tracking/lxTriplet/LxDraw.cxx b/reco/tracking/lxTriplet/LxDraw.cxx deleted file mode 100644 index bd48675b74332815a4afa4354298bb3875544c6f..0000000000000000000000000000000000000000 --- a/reco/tracking/lxTriplet/LxDraw.cxx +++ /dev/null @@ -1,903 +0,0 @@ -/* Copyright (C) 2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifdef LXDRAW - -#include "LxDraw.h" - -#include "CbmKF.h" - -#include "TEllipse.h" -#include "TGeoArb8.h" -#include "TGeoBoolNode.h" -#include "TGeoCompositeShape.h" -#include "TGeoCone.h" -#include "TGeoManager.h" -#include "TLatex.h" -#include "TLine.h" -#include "TMCProcess.h" -#include "TPolyLine.h" -#include "TPolyMarker.h" -#include "TStyle.h" - -#include <iostream> - -#include <math.h> -#include <stdlib.h> -#include <unistd.h> - -#include "Lx.h" - -#ifdef CLUSTER_MODE -#include "kdtree++/kdtree.hpp" -#endif //CLUSTER_MODE - -#define USE_MUCH_ABSORBER - -using namespace std; - -static int StaColour = 17; - -LxDraw::LxDraw() - : YZ("YZ", "YZ Side View", -10, -50, 650, 1000) - , XZ("XZ", "XZ Top View", -10, -50, 650, 1000) - , YX("YX", "YX Front View", -500, 0, 1000, 1000) - , ask(true) -{ - gStyle->SetCanvasBorderMode(0); - gStyle->SetCanvasBorderSize(1); - gStyle->SetCanvasColor(0); - - YZ.Range(-15.0, -300.0, 600.0, 300.0); - YZ.Draw(); - YZ.Update(); - - XZ.Range(-15.0, -300.0, 600.0, 300.0); - XZ.Draw(); - XZ.Update(); - - YX.Range(-300.0, -300.0, 300.0, 300.0); - YX.Draw(); - YX.Update(); -} - -void LxDraw::ClearView() -{ - YZ.Clear(); - XZ.Clear(); - YX.Clear(); -} - -void LxDraw::Ask() -{ - char symbol; - - if (ask) { - cout << "ask>"; - - do { - cin.get(symbol); - - if (symbol == 'r') ask = false; - - if (symbol == 'q') exit; - } while (symbol != '\n'); - - cout << endl; - } -} - -void LxDraw::DrawMCTracks() -{ - char buf[128]; - int NRegMCTracks = 0; - LxFinder* finder = LxFinder::Instance(); - TPolyLine pline; - - static int mc_tr_count = 0; - - for (vector<LxMCTrack>::iterator it = finder->MCTracks.begin(); it != finder->MCTracks.end(); ++it) { - LxMCTrack& T = *it; - - //if ((13 != T.pdg && -13 != T.pdg) || T.mother_ID >= 0) - //continue; - - bool mcPointOnSta[18] = {true, true, true, false, false, false, false, false, false, - false, false, false, false, false, false, false, false, false}; - int mcpCount = 0; - - for (vector<LxMCPoint*>::iterator j = T.Points.begin(); j != T.Points.end(); ++j) { - LxMCPoint* pMCPoint = *j; - mcPointOnSta[pMCPoint->stationNumber * 3 + pMCPoint->layerNumber] = true; - ++mcpCount; - } - - bool isRefTrack = true; - - for (int j = 0; j < 18; ++j) { - if (!mcPointOnSta[j]) isRefTrack = false; - } - - //if (!isRefTrack) - if (mcpCount < 15) continue; - - pline.SetLineColor(kRed); - - if (T.p < 0.5) pline.SetLineColor(kBlue); - - if (T.mother_ID != -1) pline.SetLineColor(8); - - if ((T.mother_ID != -1) && (T.p < 0.5)) pline.SetLineColor(12); - - double par[6]; - par[0] = T.x; - par[1] = T.y; - par[2] = T.px / T.pz; - par[3] = T.py / T.pz; - par[4] = T.q / T.p; - par[5] = T.z; - - if (T.Points.size() < 1) continue; - - vector<double> lx, ly, lz; - lx.push_back(par[0]); - ly.push_back(par[1]); - lz.push_back(par[5]); - - bool ok = true; - cout << "LxDraw: drawing MC track with " << T.stationsWithHits << " hitted stations and " << T.layersWithHits - << " hitted layers"; - - if (T.layersWithHits < LXSTATIONS * LXLAYERS) { - cout << " "; - - for (Int_t j = 0; j < LXSTATIONS; ++j) { - cout << "["; - - for (Int_t k = 0; k < LXLAYERS; ++k) { - if (T.hitsOnStations[j][k]) cout << "x"; - else - cout << "o"; - } - - cout << "]"; - } - } - - cout << endl; - - for (std::vector<LxMCPoint*>::iterator ip = T.Points.begin(); ip != T.Points.end(); ++ip) { - LxMCPoint* p = *ip; - double par1[6]; - par1[0] = p->x; - par1[1] = p->y; - par1[2] = p->px / p->pz; - par1[3] = p->py / p->pz; - par1[4] = p->q / p->p; - par1[5] = p->z; - - double Zfrst = par[5]; - double Zlast = par1[5]; - double step = .5; - - if (step > fabs(Zfrst - Zlast) / 5) step = fabs(Zfrst - Zlast) / 5; - - if (Zlast < par[5]) step = -step; - - while (fabs(par[5] - Zlast) > fabs(step)) { - double znxt = par[5] + step; - CbmKF::Instance()->Propagate(par1, 0, znxt, par1[4]); - CbmKF::Instance()->Propagate(par, 0, znxt, par[4]); - double w = fabs(znxt - Zfrst); - double w1 = fabs(znxt - Zlast); - - if (w + w1 < 1.e-3) { - w = 1; - w1 = 0; - } - - float xl = (w1 * par[0] + w * par1[0]) / (w + w1); - float yl = (w1 * par[1] + w * par1[1]) / (w + w1); - float zl = (w1 * par[5] + w * par1[5]) / (w + w1); - - if ((fabs(xl) > 400.0) || (fabs(yl) > 400.0)) { - //cout << "*** track " << NRegMCTracks+1 << " xl = " << xl << ", zl = " << zl << endl; - //cout << "*** track " << NRegMCTracks+1 << " yl = " << yl << ", zl = " << zl << endl; - ok = false; // Timur - continue; // Timur - } - - lx.push_back((w1 * par[0] + w * par1[0]) / (w + w1)); - ly.push_back((w1 * par[1] + w * par1[1]) / (w + w1)); - lz.push_back((w1 * par[5] + w * par1[5]) / (w + w1)); - - if (lx.size() > 200) break; - } - - par[0] = p->x; - par[1] = p->y; - - if (p->pz != 0) { - par[2] = p->px / p->pz; - par[3] = p->py / p->pz; - } - else { - par[2] = 1000 * 1000 * 1000; - par[3] = 1000 * 1000 * 1000; - } - - if (p->p != 0) par[4] = p->q / p->p; - else - par[4] = 1000 * 1000 * 1000; - - par[5] = p->z; - lx.push_back(par[0]); - ly.push_back(par[1]); - lz.push_back(par[5]); - } - - if (ok) { - double max_z = 0, min_z = 500; - - for (vector<double>::iterator i = lz.begin(); i != lz.end(); ++i) { - if (*i > max_z) max_z = *i; - - if (*i < min_z) min_z = *i; - } - - if (min_z < 10 && max_z > 503) ++mc_tr_count; - - NRegMCTracks++; - YZ.cd(); - pline.DrawPolyLine(lx.size(), &(lz[0]), &(ly[0])); - XZ.cd(); - pline.DrawPolyLine(lx.size(), &(lz[0]), &(lx[0])); - YX.cd(); - pline.DrawPolyLine(lx.size(), &(lx[0]), &(ly[0])); - } - } - - cout << "LxDraw: number of registered MC tracks: " << NRegMCTracks << endl; - YZ.cd(); - YZ.Update(); - XZ.cd(); - XZ.Update(); - YX.cd(); - YX.Update(); -} - -void LxDraw::DrawInputHits() -{ - DrawMuch(); - - // Draw hits - int mcolour = 4; - int hitsMStyle = 1; //5; - double HitSize = 1; - LxFinder* finder = LxFinder::Instance(); - LxSpace& lxSpace = finder->caSpace; - - int nhits = 0; - - for (int i = 0; i < 6; ++i) - //for (int i = 0; i < 1; ++i) - { - LxStation* pSt = lxSpace.stations[i]; - - for (int j = 0; j < 3; ++j) - //for (int j = 0; j < 1; ++j) - { - LxLayer* pLa = pSt->layers[j]; - //nhits += static_cast<KDTreePointsType*> (pLa->pointsHandle)->size(); - nhits += pLa->points.size(); - } - } - - Double_t x_poly[nhits], y_poly[nhits], z_poly[nhits]; - Double_t x_poly2[nhits], y_poly2[nhits], z_poly2[nhits]; // Removed. - Double_t x_poly3[nhits], y_poly3[nhits], z_poly3[nhits]; // Restored. - TVector3 pos, err; - int n_poly = 0; - int n_poly2 = 0; - int n_poly3 = 0; - - //for (int i = 5; i >= 0; --i) - for (int i = 0; i >= 0; --i) { - LxStation* pSt = lxSpace.stations[i]; - - //for (int j = 2; j >= 0; --j) - for (int j = 1; j >= 1; --j) { - LxLayer* pLa = pSt->layers[j]; - - //for (KDTreePointsType::iterator k = static_cast<KDTreePointsType*> (pLa->pointsHandle)->begin(); k != static_cast<KDTreePointsType*> (pLa->pointsHandle)->end(); ++k) - for (list<LxPoint*>::iterator k = pLa->points.begin(); k != pLa->points.end(); ++k) { - LxPoint* pPo = *k; - - if (pPo->artificial) { - x_poly3[n_poly3] = pPo->x; - y_poly3[n_poly3] = pPo->y; - z_poly3[n_poly3] = pPo->z; - ++n_poly3; - } - else if (!pPo->valid) { - x_poly2[n_poly2] = pPo->x; - y_poly2[n_poly2] = pPo->y; - z_poly2[n_poly2] = pPo->z; - ++n_poly2; - } - else { - x_poly[n_poly] = pPo->x; - y_poly[n_poly] = pPo->y; - z_poly[n_poly] = pPo->z; - ++n_poly; - } - } - } - } - - YZ.cd(); - - TPolyMarker* pmyz = new TPolyMarker(n_poly, z_poly, y_poly); - pmyz->SetMarkerColor(mcolour); - pmyz->SetMarkerStyle(hitsMStyle); - pmyz->SetMarkerSize(HitSize); - pmyz->Draw(); - - TPolyMarker* pmyz2 = new TPolyMarker(n_poly2, z_poly2, y_poly2); - pmyz2->SetMarkerColor(2); - pmyz2->SetMarkerStyle(hitsMStyle); - pmyz2->SetMarkerSize(HitSize); - pmyz2->Draw(); - - TPolyMarker* pmyz3 = new TPolyMarker(n_poly3, z_poly3, y_poly3); - pmyz3->SetMarkerColor(3); - pmyz3->SetMarkerStyle(hitsMStyle); - pmyz3->SetMarkerSize(HitSize); - pmyz3->Draw(); - - XZ.cd(); - - TPolyMarker* pmxz = new TPolyMarker(n_poly, z_poly, x_poly); - pmxz->SetMarkerColor(mcolour); - pmxz->SetMarkerStyle(hitsMStyle); - pmxz->SetMarkerSize(HitSize); - pmxz->Draw(); - - TPolyMarker* pmxz2 = new TPolyMarker(n_poly2, z_poly2, x_poly2); - pmxz2->SetMarkerColor(2); - pmxz2->SetMarkerStyle(hitsMStyle); - pmxz2->SetMarkerSize(HitSize); - pmxz2->Draw(); - - TPolyMarker* pmxz3 = new TPolyMarker(n_poly3, z_poly3, x_poly3); - pmxz3->SetMarkerColor(3); - pmxz3->SetMarkerStyle(hitsMStyle); - pmxz3->SetMarkerSize(HitSize); - pmxz3->Draw(); - - YX.cd(); - - TPolyMarker* pmyx = new TPolyMarker(n_poly, x_poly, y_poly); - pmyx->SetMarkerColor(mcolour); - pmyx->SetMarkerStyle(hitsMStyle); - pmyx->SetMarkerSize(HitSize); - pmyx->Draw(); - - TPolyMarker* pmyx2 = new TPolyMarker(n_poly2, x_poly2, y_poly2); - pmyx2->SetMarkerColor(2); - pmyx2->SetMarkerStyle(hitsMStyle); - pmyx2->SetMarkerSize(HitSize); - pmyx2->Draw(); - - TPolyMarker* pmyx3 = new TPolyMarker(n_poly3, x_poly3, y_poly3); - pmyx3->SetMarkerColor(3); - pmyx3->SetMarkerStyle(hitsMStyle); - pmyx3->SetMarkerSize(HitSize); - pmyx3->Draw(); -} - -void LxDraw::DrawMuch(TGeoNode* node) -{ - TObjArray* children; - TObject* childO; - - if (0 != strstr(node->GetName(), "active")) { - TGeoCompositeShape* cs = dynamic_cast<TGeoCompositeShape*>(node->GetVolume()->GetShape()); - - if (cs) { - TGeoBoolNode* bn = cs->GetBoolNode(); - TGeoTrap* trap = dynamic_cast<TGeoTrap*>(bn->GetLeftShape()); - - if (trap) { - Double_t minY = 0, maxY = 0, minX = 0, maxX = 0, Z = 0; - Double_t* xy = trap->GetVertices(); - Double_t trapX[5]; - Double_t trapY[5]; - - for (int i = 0; i < 4; ++i) { - Double_t localCoords[3] = {xy[2 * i], xy[2 * i + 1], 0.}; - Double_t globalCoords[3]; - gGeoManager->LocalToMaster(localCoords, globalCoords); - - if (minY > globalCoords[1]) minY = globalCoords[1]; - - if (maxY < globalCoords[1]) maxY = globalCoords[1]; - - if (minX > globalCoords[0]) minX = globalCoords[0]; - - if (maxX < globalCoords[0]) maxX = globalCoords[0]; - - Z = globalCoords[2]; - trapX[i] = globalCoords[0]; - trapY[i] = globalCoords[1]; - } - - trapX[4] = trapX[0]; - trapY[4] = trapY[0]; - - YZ.cd(); - TLine* line = new TLine(); - line->SetLineColor(StaColour); - line->DrawLine(Z, minY, Z, maxY); - - XZ.cd(); - line->DrawLine(Z, minX, Z, maxX); - - YX.cd(); - TPolyLine* pline = new TPolyLine(5, trapX, trapY); - pline->SetFillColor(StaColour); - pline->SetLineColor(kCyan + 4); - pline->SetLineWidth(1); - pline->Draw("f"); - pline->Draw(); - } - } - - goto exit; - } - - children = node->GetNodes(); - - if (0 == children) goto exit; - - childO = children->First(); - - while (childO) { - TGeoNode* child = dynamic_cast<TGeoNode*>(childO); - - if (child) { - gGeoManager->GetCurrentNavigator()->CdDown(child); - DrawMuch(child); - } - - childO = children->After(childO); - } - -exit: - gGeoManager->CdUp(); -} - -void LxDraw::DrawMuch() -{ - TLatex latex; - latex.SetTextFont(132); - latex.SetTextAlign(12); - latex.SetTextSize(0.035); - - YZ.cd(); - latex.DrawLatex(0.0, 250.0, "YZ Side View"); - YZ.Draw(); - - XZ.cd(); - latex.DrawLatex(0.0, 250.0, "XZ Top View"); - XZ.Draw(); - - YX.cd(); - latex.DrawLatex(-270.0, 250.0, "YX Front View"); - YX.Draw(); - - for (int i = 6; i > 0; --i) { - char buf[128]; - // Draw 3 layers of the much station - //if (i < 7) - { - sprintf(buf, "/cave_1/much_0/muchstation0%d_0", i); - gGeoManager->cd(buf); - DrawMuch(gGeoManager->GetCurrentNode()); - } -#ifdef USE_MUCH_ABSORBER - // Draw an absorber - sprintf(buf, "/cave_1/much_0/muchabsorber0%d_0", i); - gGeoManager->cd(buf); - Double_t localCoords[3] = {0., 0., 0.}; - Double_t globalCoords[3]; - gGeoManager->LocalToMaster(localCoords, globalCoords); - TGeoVolume* muchAbsVol = gGeoManager->GetCurrentVolume(); - TGeoShape* muchAbsShape = muchAbsVol->GetShape(); - TGeoCone* muchAbsCone = dynamic_cast<TGeoCone*>(muchAbsShape); - - Double_t fRmax1 = muchAbsCone->GetRmax1(); - Double_t fRmax2 = muchAbsCone->GetRmax2(); - Double_t fDz = muchAbsCone->GetDz(); - Double_t fZ = globalCoords[2]; - - Double_t maXs[5] = {fZ - fDz, fZ - fDz, fZ + fDz, fZ + fDz, fZ - fDz}; - Double_t maYs[5] = {-fRmax1, fRmax1, fRmax2, -fRmax2, -fRmax1}; - TPolyLine* muchAbsorber = new TPolyLine(5, maXs, maYs); - muchAbsorber->SetFillColor(kYellow); - muchAbsorber->SetLineColor(kYellow); - muchAbsorber->SetLineWidth(1); - YZ.cd(); - muchAbsorber->Draw("f"); - muchAbsorber->Draw(); - XZ.cd(); - muchAbsorber->Draw("f"); - muchAbsorber->Draw(); - YX.cd(); - TEllipse* ellipse = new TEllipse(0.0, 0.0, fRmax2); - ellipse->SetFillColor(kYellow); - ellipse->SetLineColor(kYellow); - ellipse->SetLineWidth(1); - ellipse->SetFillStyle(3002); - ellipse->Draw("f"); - ellipse->Draw(); - TEllipse* ellipseInner = new TEllipse(0.0, 0.0, fRmax1); - ellipseInner->SetFillColor(kYellow - 7); - ellipseInner->SetLineColor(kYellow - 7); - ellipseInner->SetLineWidth(1); - ellipseInner->SetFillStyle(3002); - ellipseInner->Draw("f"); - ellipseInner->Draw(); -#endif //USE_MUCH_ABSORBER - } -} - -#ifdef CLUSTER_MODE -struct KDRayWrap { - LxRay* ray; - Double_t data[4]; - static bool destroyRays; - - KDRayWrap(Double_t x, Double_t y, LxRay* r) : ray(r) - { - data[0] = x; - data[1] = y; - data[2] = ray->tx; - data[3] = ray->ty; - } - - KDRayWrap(Double_t x, Double_t y, Double_t tx, Double_t ty) - : ray(0) // This constructor is used when setting search-range bounds. - { - data[0] = x; - data[1] = y; - data[2] = tx; - data[3] = ty; - } - - ~KDRayWrap() - { - if (destroyRays) delete ray; - } - - // Stuff required by libkdtree++ - typedef Double_t value_type; - - value_type operator[](size_t n) const { return data[n]; } -}; - -//bool KDRayWrap::destroyRays = false; - -typedef KDTree::KDTree<4, KDRayWrap> KDRaysStorageType; -#endif //CLUSTER_MODE - -void LxDraw::DrawRays() -{ - LxFinder* finder = LxFinder::Instance(); - LxSpace& caSpace = finder->caSpace; - int stationsNumber = caSpace.stations.size(); - - for (Int_t i = stationsNumber - 1; i > 0; --i) { - LxStation* rSt = caSpace.stations[i]; -#ifdef CLUSTER_MODE - KDRaysStorageType* rays = static_cast<KDRaysStorageType*>(rSt->clusteredRaysHandle); - Double_t lZ = caSpace.stations[i - 1]->zCoord; - - for (KDRaysStorageType::iterator j = rays->begin(); j != rays->end(); ++j) { - KDRayWrap& wrap = const_cast<KDRayWrap&>(*j); - LxRay* ray = wrap.ray; - LxPoint* rPo = ray->source; - Double_t deltaZ = lZ - rPo->z; - Double_t lX = rPo->x + ray->tx * deltaZ; - Double_t lY = rPo->y + ray->ty * deltaZ; - - YZ.cd(); - TLine* yzLine = new TLine(rPo->z, rPo->y, lZ, lY); - yzLine->SetLineColor(kRed); - yzLine->Draw(); - - XZ.cd(); - TLine* xzLine = new TLine(rPo->z, rPo->x, lZ, lX); - xzLine->SetLineColor(kRed); - xzLine->Draw(); - - YX.cd(); - TLine* yxLine = new TLine(rPo->x, rPo->y, lX, lY); - yxLine->SetLineColor(kRed); - yxLine->Draw(); - } -#else //CLUSTER_MODE - LxLayer* rLa = rSt->layers[0]; - LxStation* lSt = caSpace.stations[i - 1]; - int lLaInd = lSt->layers.size() - 1; - LxLayer* lLa = lSt->layers[lLaInd]; - - if (rLa->points.size() == 0 || lLa->points.size() == 0) continue; - - Double_t lZ = (*lLa->points.begin())->z; - - for (list<LxPoint*>::iterator j = rLa->points.begin(); j != rLa->points.end(); ++j) { - LxPoint* rPo = *j; - Double_t deltaZ = lZ - rPo->z; - - for (list<LxRay*>::iterator k = rPo->rays.begin(); k != rPo->rays.end(); ++k) { - LxRay* ray = *k; - - Double_t lX = rPo->x + ray->tx * deltaZ; - Double_t lY = rPo->y + ray->ty * deltaZ; - - YZ.cd(); - TLine* yzLine = new TLine(rPo->z, rPo->y, lZ, lY); - yzLine->SetLineColor(kRed); - yzLine->Draw(); - - XZ.cd(); - TLine* xzLine = new TLine(rPo->z, rPo->x, lZ, lX); - xzLine->SetLineColor(kRed); - xzLine->Draw(); - - YX.cd(); - TLine* yxLine = new TLine(rPo->x, rPo->y, lX, lY); - yxLine->SetLineColor(kRed); - yxLine->Draw(); - } - } -#endif //CLUSTER_MODE - } - - YZ.cd(); - YZ.Update(); - XZ.cd(); - XZ.Update(); - YX.cd(); - YX.Update(); -} - -void LxDraw::DrawRecoTracks() -{ - LxFinder* finder = LxFinder::Instance(); - LxSpace& caSpace = finder->caSpace; - int stationsNumber = caSpace.stations.size(); - - for (list<LxTrack*>::iterator i = caSpace.tracks.begin(); i != caSpace.tracks.end(); ++i) { - LxTrack* track = *i; - -#ifdef USE_KALMAN_FIT - bool kalmanDrawn = false; -#endif //USE_KALMAN_FIT - - for (int j = 0; j < track->length; ++j) { - LxRay* ray = track->rays[j]; - - if (0 == ray) break; - - Double_t rX = ray->source->x; - Double_t rY = ray->source->y; - Double_t rZ = ray->source->z; - - Double_t lZ = caSpace.stations[ray->station->stationNumber - 1]->zCoord; - Double_t deltaZ = lZ - rZ; - Double_t lX = rX + ray->tx * deltaZ; - Double_t lY = rY + ray->ty * deltaZ; - -#ifdef USE_KALMAN_FIT - Double_t kalmanZl = track->z; - Double_t kalmanXl = track->x; - Double_t kalmanYl = track->y; - Double_t kalmanZr = ray->source->z; - Double_t kalmanXr = kalmanXl + track->tx * (kalmanZr - kalmanZl); - Double_t kalmanYr = kalmanYl + track->ty * (kalmanZr - kalmanZl); -#endif //USE_KALMAN_FIT - - YZ.cd(); - TLine* yzLineL = new TLine(rZ, rY, lZ, lY); - yzLineL->SetLineColor(kBlue); - yzLineL->Draw(); - - if (!kalmanDrawn) { - TLine* kalmanYZLine = new TLine(kalmanZr, kalmanYr, kalmanZl, kalmanYl); - kalmanYZLine->SetLineColor(kBlack); - kalmanYZLine->Draw(); - } - - XZ.cd(); - TLine* xzLineL = new TLine(rZ, rX, lZ, lX); - xzLineL->SetLineColor(kBlue); - xzLineL->Draw(); - - if (!kalmanDrawn) { - TLine* kalmanXZLine = new TLine(kalmanZr, kalmanXr, kalmanZl, kalmanXl); - kalmanXZLine->SetLineColor(kBlack); - kalmanXZLine->Draw(); - } - - YX.cd(); - TLine* yxLineL = new TLine(rX, rY, lX, lY); - yxLineL->SetLineColor(kBlue); - yxLineL->Draw(); - - if (!kalmanDrawn) { - TLine* kalmanYXLine = new TLine(kalmanXr, kalmanYr, kalmanXl, kalmanYl); - kalmanYXLine->SetLineColor(kBlack); - kalmanYXLine->Draw(); - } - -#ifdef USE_KALMAN_FIT - kalmanDrawn = true; -#endif //USE_KALMAN_FIT - } - - // Draw a segment of an external track if it is set. - - //if (track->externalTrack) - if (false) { - Double_t rZ = caSpace.stations[0]->layers[0]->zCoord; - const FairTrackParam* param = track->externalTrack->track->GetParamLast(); - - Double_t lX = param->GetX(); - Double_t lY = param->GetY(); - Double_t lZ = param->GetZ(); - Double_t deltaZ = rZ - lZ; - Double_t rX = lX + param->GetTx() * deltaZ; - Double_t rY = lY + param->GetTy() * deltaZ; - - YZ.cd(); - TLine* yzLine = new TLine(lZ, lY, rZ, rY); - yzLine->SetLineColor(kPink); - yzLine->Draw(); - - XZ.cd(); - TLine* xzLine = new TLine(lZ, lX, rZ, rX); - xzLine->SetLineColor(kPink); - xzLine->Draw(); - - YX.cd(); - TLine* yxLine = new TLine(lX, lY, rX, rY); - yxLine->SetLineColor(kPink); - yxLine->Draw(); - } - } - - YZ.cd(); - YZ.Update(); - XZ.cd(); - XZ.Update(); - YX.cd(); - YX.Update(); -} - -void LxDraw::DrawMCPoints() -{ - int mcolour = 2; - int hitsMStyle = 2; - double HitSize = 1; - LxFinder* finder = LxFinder::Instance(); - - int nhits = finder->MCPoints.size(); - Double_t x_poly[nhits], y_poly[nhits], z_poly[nhits]; - TVector3 pos; - int n_poly = 0; - - for (vector<LxMCPoint>::iterator i = finder->MCPoints.begin(); i != finder->MCPoints.end(); ++i) { - LxMCPoint& point = *i; - - x_poly[n_poly] = point.x; - y_poly[n_poly] = point.y; - z_poly[n_poly] = point.z; - - ++n_poly; - } - - YZ.cd(); - - TPolyMarker* pmyz = new TPolyMarker(n_poly, z_poly, y_poly); - pmyz->SetMarkerColor(mcolour); - pmyz->SetMarkerStyle(hitsMStyle); - pmyz->SetMarkerSize(HitSize); - pmyz->Draw(); - YZ.Update(); - - XZ.cd(); - - TPolyMarker* pmxz = new TPolyMarker(n_poly, z_poly, x_poly); - pmxz->SetMarkerColor(mcolour); - pmxz->SetMarkerStyle(hitsMStyle); - pmxz->SetMarkerSize(HitSize); - pmxz->Draw(); - XZ.Update(); - - YX.cd(); - - TPolyMarker* pmyx = new TPolyMarker(n_poly, x_poly, y_poly); - pmyx->SetMarkerColor(mcolour); - pmyx->SetMarkerStyle(hitsMStyle); - pmyx->SetMarkerSize(HitSize); - pmyx->Draw(); - YX.Update(); -} - -void LxDraw::DrawExtTracks() -{ - LxFinder* finder = LxFinder::Instance(); - LxSpace& caSpace = finder->caSpace; - Double_t rZ = caSpace.stations[0]->layers[0]->zCoord; - - for (list<LxExtTrack>::iterator i = caSpace.extTracks.begin(); i != caSpace.extTracks.end(); ++i) { - LxExtTrack& extTrack = *i; - const FairTrackParam* param = extTrack.track->GetParamLast(); - - Double_t lX = param->GetX(); - Double_t lY = param->GetY(); - Double_t lZ = param->GetZ(); - Double_t deltaZ = rZ - lZ; - Double_t rX = lX + param->GetTx() * deltaZ; - Double_t rY = lY + param->GetTy() * deltaZ; - - YZ.cd(); - TLine* yzLine = new TLine(lZ, lY, rZ, rY); - yzLine->SetLineColor(kPink); - yzLine->Draw(); - - XZ.cd(); - TLine* xzLine = new TLine(lZ, lX, rZ, rX); - xzLine->SetLineColor(kPink); - xzLine->Draw(); - - YX.cd(); - TLine* yxLine = new TLine(lX, lY, rX, rY); - yxLine->SetLineColor(kPink); - yxLine->Draw(); - } - - YZ.cd(); - YZ.Update(); - XZ.cd(); - XZ.Update(); - YX.cd(); - YX.Update(); -} - -void LxDraw::SaveCanvas(TString name) -{ - system("mkdir LxDraw -p"); - chdir("LxDraw"); - TString tmp = name; - tmp += "YXView.pdf"; - YX.cd(); - YX.SaveAs(tmp); - - tmp = name; - tmp += "XZView.pdf"; - XZ.cd(); - XZ.SaveAs(tmp); - - tmp = name; - tmp += "YZView.pdf"; - YZ.cd(); - YZ.SaveAs(tmp); - - chdir(".."); -} - -#endif //LXDRAW diff --git a/reco/tracking/lxTriplet/LxDraw.h b/reco/tracking/lxTriplet/LxDraw.h deleted file mode 100644 index c7d8c3ccc23bc57af7937c579b3f9157e8d5d329..0000000000000000000000000000000000000000 --- a/reco/tracking/lxTriplet/LxDraw.h +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (C) 2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifndef LXDRAW_INCLUDED -#define LXDRAW_INCLUDED - -#pragma GCC diagnostic ignored "-Weffc++" - -#ifdef LXDRAW - -#include "TCanvas.h" -#include "TGeoNode.h" - -class LxDraw { -public: - LxDraw(); - void ClearView(); - void Ask(); - void DrawMCTracks(); - void DrawInputHits(); - void DrawMuch(TGeoNode* node); - void DrawMuch(); - void DrawRays(); - void DrawRecoTracks(); - void DrawMCPoints(); - void DrawExtTracks(); - void SaveCanvas(TString name); - -private: - TCanvas YZ; - TCanvas YX; - TCanvas XZ; - bool ask; -}; - -#endif //LXDRAW - -#endif //LXDRAW_INCLUDED diff --git a/reco/tracking/lxTriplet/LxEff.cxx b/reco/tracking/lxTriplet/LxEff.cxx deleted file mode 100644 index 1e5f70589632c88ad3357087edfa5c63aad824b4..0000000000000000000000000000000000000000 --- a/reco/tracking/lxTriplet/LxEff.cxx +++ /dev/null @@ -1,1054 +0,0 @@ -/* Copyright (C) 2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#include "LxEff.h" - -#include <set> - -#include <cmath> - -#include "Lx.h" - -//#define LXDRAW - -#ifdef LXDRAW -#include "LxDraw.h" -//#define LXDRAWSAVE -//#define LXDRAWWAIT -#endif //LXDRAW - -using namespace std; - -LxEff::LxEff(LxFinderTriplet& owner) : finder(owner) {} - -#ifdef CLUSTER_MODE -void LxEff::AnalyzeNotMatched(ofstream& out, list<LxPoint*> hits[LXSTATIONS][LXLAYERS]) -{ - out << "AnalyzeNotMatched:" << endl; - - for (Int_t stNum = LXFIRSTSTATION; stNum < LXSTATIONS - 1; ++stNum) { - out << "Segments #" << stNum << endl; - list<LxPoint*> lHits[LXLAYERS] = hits[stNum]; - list<LxPoint*> rHits[LXLAYERS] = hits[stNum + 1]; - - Double_t maxDx = 0; - Double_t maxDy = 0; - Double_t maxDtx = 0; - Double_t maxDty = 0; - Double_t minDx = 1000; - Double_t minDy = 1000; - Double_t minDtx = 1000; - Double_t minDty = 1000; - - for (list<LxPoint*>::iterator l0 = lHits[0].begin(); l0 != lHits[0].end(); ++l0) { - for (list<LxPoint*>::iterator l1 = lHits[1].begin(); l1 != lHits[1].end(); ++l1) { - for (list<LxPoint*>::iterator l2 = lHits[2].begin(); l2 != lHits[2].end(); ++l2) { - for (list<LxPoint*>::iterator r0 = rHits[0].begin(); r0 != rHits[0].end(); ++r0) { - for (list<LxPoint*>::iterator r1 = rHits[1].begin(); r1 != rHits[1].end(); ++r1) { - for (list<LxPoint*>::iterator r2 = rHits[2].begin(); r2 != rHits[2].end(); ++r2) { - LxPoint* lPoints[LXLAYERS] = {*l0, *l1, *l2}; - LxPoint* rPoints[LXLAYERS] = {*r0, *r1, *r2}; - LxRay* rays[LXLAYERS * LXLAYERS] = {}; - - for (Int_t i = 0; i < LXLAYERS; ++i) { - for (Int_t j = 0; j < LXLAYERS; ++j) - rays[j * LXLAYERS + i] = new LxRay(rPoints[j], lPoints[i], j * LXLAYERS + i); - } - - for (Int_t i = 0; i < LXLAYERS * LXLAYERS; ++i) { - LxRay* ray1 = rays[i]; - Double_t tx1 = ray1->tx; - Double_t ty1 = ray1->ty; - Double_t z1 = ray1->source->z; - Double_t x1 = ray1->source->x; - Double_t y1 = ray1->source->y; - - if (minDx > ray1->source->dx) minDx = ray1->source->dx; - - if (minDy > ray1->source->dy) minDy = ray1->source->dy; - - if (minDtx > ray1->dtx) minDtx = ray1->dtx; - - if (minDty > ray1->dty) minDty = ray1->dty; - - for (Int_t j = i; j < LXLAYERS * LXLAYERS; ++j) { - LxRay* ray2 = rays[j]; - Double_t tx2 = ray2->tx; - Double_t ty2 = ray2->ty; - Double_t z2 = ray2->source->z; - Double_t diffZ = z1 - z2; - Double_t x2 = ray2->source->x + tx2 * diffZ; - Double_t y2 = ray2->source->y + ty2 * diffZ; - - Double_t dtx = abs(tx2 - tx1); - Double_t dty = abs(ty2 - ty1); - Double_t dx = abs(x2 - x1); - Double_t dy = abs(y2 - y1); - - if (maxDx < dx) maxDx = dx; - - if (maxDy < dy) maxDy = dy; - - if (maxDtx < dtx) maxDtx = dtx; - - if (maxDty < dty) maxDty = dty; - } - } - - for (Int_t i = 0; i < LXLAYERS * LXLAYERS; ++i) - delete rays[i]; - } - } - } - } - } - } - - out << 4.0 * sqrt(minDx * minDx + finder.caSpace.stations[stNum + 1]->clusterXLimit2) - maxDx << " " - << 4.0 * sqrt(minDy * minDy + finder.caSpace.stations[stNum + 1]->clusterYLimit2) - maxDy << " " - << 4.0 * sqrt(minDtx * minDtx + finder.caSpace.stations[stNum + 1]->clusterTxLimit2) - maxDtx << " " - << 4.0 * sqrt(minDty * minDty + finder.caSpace.stations[stNum + 1]->clusterTyLimit2) - maxDty << endl - << endl; - } -} - -void LxEff::AnalyzeNotMatched2(ofstream& out, list<LxPoint*> hits[LXSTATIONS][LXLAYERS]) -{ - out << "AnalyzeNotMatched2:" << endl; - - for (Int_t stNum = LXFIRSTSTATION; stNum < LXSTATIONS - 1; ++stNum) { - out << "Segments #" << stNum << " has "; - list<LxPoint*> lHits[LXLAYERS] = hits[stNum]; - list<LxPoint*> rHits[LXLAYERS] = hits[stNum + 1]; - - Int_t maxOccupiedLevels = 0; - Int_t maxNumPointsWithRays = 0; - - for (list<LxPoint*>::iterator l0 = lHits[0].begin(); l0 != lHits[0].end(); ++l0) { - for (list<LxPoint*>::iterator l1 = lHits[1].begin(); l1 != lHits[1].end(); ++l1) { - for (list<LxPoint*>::iterator l2 = lHits[2].begin(); l2 != lHits[2].end(); ++l2) { - for (list<LxPoint*>::iterator r0 = rHits[0].begin(); r0 != rHits[0].end(); ++r0) { - for (list<LxPoint*>::iterator r1 = rHits[1].begin(); r1 != rHits[1].end(); ++r1) { - for (list<LxPoint*>::iterator r2 = rHits[2].begin(); r2 != rHits[2].end(); ++r2) { - LxPoint* lPoints[LXLAYERS] = {*l0, *l1, *l2}; - LxPoint* rPoints[LXLAYERS] = {*r0, *r1, *r2}; - Int_t occupiedLevels = 0; - Int_t numPointsWithRays = 0; - - for (Int_t i = 0; i < LXLAYERS; ++i) { - LxPoint* rPoint = rPoints[i]; - - if (!rPoint->rays.empty()) ++numPointsWithRays; - - for (Int_t j = 0; j < LXLAYERS; ++j) { - LxPoint* lPoint = lPoints[j]; - - for (list<LxRay*>::iterator k = rPoint->rays.begin(); k != rPoint->rays.end(); ++k) { - LxRay* ray = *k; - - if (ray->end == lPoint) { - ++occupiedLevels; - break; - } - } - } - } - - if (occupiedLevels > maxOccupiedLevels) maxOccupiedLevels = occupiedLevels; - - if (numPointsWithRays > maxNumPointsWithRays) maxNumPointsWithRays = numPointsWithRays; - } - } - } - } - } - } // for (list<LxPoint*>::iterator l0 = lHits[0].begin(); l0 != lHits[0].end(); ++l0) - - out << maxOccupiedLevels << " of occupied levels and " << maxNumPointsWithRays << " points with rays" << endl - << endl; - } -} - -void LxEff::DumpNotMatchedMC(list<LxPoint*> hits[LXSTATIONS][LXLAYERS]) -{ - AnalyzeNotMatched(finder.incomplete_events, hits); - AnalyzeNotMatched2(finder.incomplete_events, hits); - finder.incomplete_events << "Dumping not matched MC track" << endl; - - for (Int_t i = 0; i < LXSTATIONS; ++i) { - finder.incomplete_events << "S" << i << " "; - - for (Int_t j = 0; j < LXLAYERS; ++j) { - finder.incomplete_events << "L" << j << " "; - - for (list<LxPoint*>::iterator k = hits[i][j].begin(); k != hits[i][j].end(); ++k) { - LxPoint* point = *k; - finder.incomplete_events << "["; - - if (point->track) finder.incomplete_events << "t"; - else { - if (point->leftClusteredRay) finder.incomplete_events << "r"; - - finder.incomplete_events << "/"; - - if (point->rightClusteredRay) finder.incomplete_events << "r"; - } - - finder.incomplete_events << "] "; - } - - finder.incomplete_events << " "; - } - - finder.incomplete_events << " "; - } - - finder.incomplete_events << endl << endl; -} -#endif //CLUSTER_MODE - -void LxEff::AnalyzeNotMatchedMC(ofstream& out, list<LxPoint*> hits[LXSTATIONS][LXLAYERS]) -{ - out << "Not matched MC track:" << endl; - out << "All triplets: "; - - for (Int_t i = 0; i < LXSTATIONS; ++i) { - Int_t tripletsCount = 0; - - for (list<LxPoint*>::iterator j = hits[i][1].begin(); j != hits[i][1].end(); ++j) { - LxPoint* point = *j; - tripletsCount += point->triplets.size(); - } - - out << "[" << tripletsCount << "]"; - } - - out << endl << "True triplets: "; - - for (Int_t i = 0; i < LXSTATIONS; ++i) { - Int_t trueTripletsCount = 0; - - for (list<LxPoint*>::iterator j = hits[i][1].begin(); j != hits[i][1].end(); ++j) { - LxPoint* point = *j; - - for (list<LxTriplet*>::iterator k = point->triplets.begin(); k != point->triplets.end(); ++k) { - LxTriplet* triplet = *k; - LxPoint* lPoint = triplet->left; - LxPoint* rPoint = triplet->right; - bool trueLPoint = false; - bool trueRPoint = false; - - for (list<LxPoint*>::iterator l = hits[i][0].begin(); l != hits[i][0].end(); ++l) { - if (*l == lPoint) trueLPoint = true; - } - - for (list<LxPoint*>::iterator l = hits[i][2].begin(); l != hits[i][2].end(); ++l) { - if (*l == rPoint) trueRPoint = true; - } - - if (trueLPoint && trueRPoint) ++trueTripletsCount; - } - } - - out << "[" << trueTripletsCount << "]"; - } - - out << endl << "Have neighbors: "; - - for (Int_t i = 0; i < LXSTATIONS; ++i) { - out << "["; - - if (0 == i) out << " "; - else { - set<LxTriplet*> neighbours; - - for (list<LxPoint*>::iterator j = hits[i][1].begin(); j != hits[i][1].end(); ++j) { - LxPoint* rPoint = *j; - - for (list<LxTriplet*>::iterator k = rPoint->triplets.begin(); k != rPoint->triplets.end(); ++k) { - LxTriplet* rTriplet = *k; - - for (list<LxPoint*>::iterator l = hits[i - 1][1].begin(); l != hits[i - 1][1].end(); ++l) { - LxPoint* lPoint = *l; - - for (list<LxTriplet*>::iterator m = lPoint->triplets.begin(); m != lPoint->triplets.end(); ++m) { - LxTriplet* lTriplet = *m; - - for (list<pair<LxTriplet*, Double_t>>::iterator n = rTriplet->neighbours.begin(); - n != rTriplet->neighbours.end(); ++n) { - pair<LxTriplet*, Double_t>& tc2 = *n; - - if (tc2.first == lTriplet) neighbours.insert(lTriplet); - } - } - } - } - } - - out << neighbours.size(); - } - - out << "]"; - } - - Double_t maxCrDx[LXSTATIONS] = {}; - Double_t crDxDx2[LXSTATIONS] = {}; - Double_t maxCrDy[LXSTATIONS] = {}; - Double_t crDyDy2[LXSTATIONS] = {}; - Double_t maxClDx[LXSTATIONS] = {}; - Double_t clDxDx2[LXSTATIONS] = {}; - Double_t maxClDy[LXSTATIONS] = {}; - Double_t clDyDy2[LXSTATIONS] = {}; - - for (Int_t i = 0; i < LXSTATIONS; ++i) { - for (list<LxPoint*>::iterator j = hits[i][1].begin(); j != hits[i][1].end(); ++j) { - LxPoint* cPoint = *j; - Double_t cTx = cPoint->x / cPoint->z; - Double_t cTy = cPoint->y / cPoint->z; - - for (list<LxPoint*>::iterator k = hits[i][2].begin(); k != hits[i][2].end(); ++k) { - LxPoint* rPoint = *k; - Double_t crDeltaZ = rPoint->z - cPoint->z; - Double_t crTx = (rPoint->x - cPoint->x) / crDeltaZ; - Double_t crTy = (rPoint->y - cPoint->y) / crDeltaZ; - Double_t crDx = abs(rPoint->x - cPoint->x - cTx * crDeltaZ); - Double_t crDy = abs(rPoint->y - cPoint->y - cTy * crDeltaZ); - - if (maxCrDx[i] < crDx) { - maxCrDx[i] = crDx; - crDxDx2[i] = cPoint->dx * cPoint->dx + rPoint->dx * rPoint->dx; - } - - if (maxCrDy[i] < crDy) { - maxCrDy[i] = crDy; - crDyDy2[i] = cPoint->dy * cPoint->dy + rPoint->dy * rPoint->dy; - } - - for (list<LxPoint*>::iterator l = hits[i][0].begin(); l != hits[i][0].end(); ++l) { - LxPoint* lPoint = *l; - Double_t clDeltaZ = lPoint->z - cPoint->z; - Double_t clDx = abs(lPoint->x - cPoint->x - crTx * clDeltaZ); - Double_t clDy = abs(lPoint->y - cPoint->y - crTy * clDeltaZ); - - if (maxClDx[i] < clDx) { - maxClDx[i] = clDx; - clDxDx2[i] = lPoint->dx * lPoint->dx + cPoint->dx * cPoint->dx + rPoint->dx * rPoint->dx; - } - - if (maxClDy[i] < clDy) { - maxClDy[i] = clDy; - clDyDy2[i] = lPoint->dy * lPoint->dy + cPoint->dy * cPoint->dy + rPoint->dy * rPoint->dy; - } - } - } - } - } - - out << endl << "Triplet C-->R X dispersions: "; - - for (Int_t i = 0; i < LXSTATIONS; ++i) - out << "[" << maxCrDx[i] / sqrt(finder.caSpace.stations[i]->xDispRight2 + crDxDx2[i]) << "]"; - - out << endl << "Triplet C-->R Y dispersions: "; - - for (Int_t i = 0; i < LXSTATIONS; ++i) - out << "[" << maxCrDy[i] / sqrt(finder.caSpace.stations[i]->yDispRight2 + crDyDy2[i]) << "]"; - - out << endl << "Triplet C-->L X dispersions: "; - - for (Int_t i = 0; i < LXSTATIONS; ++i) - out << "[" << maxClDx[i] / sqrt(finder.caSpace.stations[i]->xDispRL2 + clDxDx2[i]) << "]"; - - out << endl << "Triplet C-->L Y dispersions: "; - - for (Int_t i = 0; i < LXSTATIONS; ++i) - out << "[" << maxClDy[i] / sqrt(finder.caSpace.stations[i]->yDispRL2 + clDyDy2[i]) << "]"; - - Double_t maxDx[LXSTATIONS - 1] = {}; - Double_t dxDx2[LXSTATIONS - 1] = {}; - Double_t maxDy[LXSTATIONS - 1] = {}; - Double_t dyDy2[LXSTATIONS - 1] = {}; - Double_t maxDtx[LXSTATIONS - 1] = {}; - Double_t dtxDtx2[LXSTATIONS - 1] = {}; - Double_t maxDty[LXSTATIONS - 1] = {}; - Double_t dtyDty2[LXSTATIONS - 1] = {}; - - for (Int_t i = 1; i < LXSTATIONS; ++i) { - for (list<LxPoint*>::iterator j = hits[i][1].begin(); j != hits[i][1].end(); ++j) { - LxPoint* rPoint = *j; - - for (list<LxPoint*>::iterator k = hits[i - 1][1].begin(); k != hits[i - 1][1].end(); ++k) { - LxPoint* lPoint = *k; - Double_t deltaZ = lPoint->z - rPoint->z; - - for (list<LxPoint*>::iterator l = hits[i][0].begin(); l != hits[i][0].end(); ++l) { - LxPoint* rPoint0 = *l; - - for (list<LxPoint*>::iterator m = hits[i][2].begin(); m != hits[i][2].end(); ++m) { - LxPoint* rPoint2 = *m; - Double_t rdz = rPoint2->z - rPoint0->z; - Double_t rdz2 = rdz * rdz; - Double_t rtx = (rPoint2->x - rPoint0->x) / rdz; - Double_t rty = (rPoint2->y - rPoint0->y) / rdz; - Double_t rdtx2 = (rPoint0->dx2 + rPoint2->dx2) / rdz2; - Double_t rdty2 = (rPoint0->dy2 + rPoint2->dy2) / rdz2; - -#ifdef OUT_DISP_BY_TRIPLET_DIR - Double_t dx = abs(lPoint->x - rPoint->x - rtx * deltaZ); - Double_t dy = abs(lPoint->y - rPoint->y - rty * deltaZ); -#else //OUT_DISP_BY_TRIPLET_DIR - Double_t dx = abs(lPoint->x - rPoint->x - deltaZ * rPoint->x / rPoint->z); - Double_t dy = abs(lPoint->y - rPoint->y - deltaZ * rPoint->y / rPoint->z); -#endif //OUT_DISP_BY_TRIPLET_DIR - - if (dx > maxDx[i - 1]) { - maxDx[i - 1] = dx; - dxDx2[i - 1] = lPoint->dx2 + rPoint->dx2; - } - - if (dy > maxDy[i - 1]) { - maxDy[i - 1] = dy; - dyDy2[i - 1] = lPoint->dy2 + rPoint->dy2; - } - - for (list<LxPoint*>::iterator n = hits[i - 1][0].begin(); n != hits[i - 1][0].end(); ++n) { - LxPoint* lPoint0 = *n; - - for (list<LxPoint*>::iterator o = hits[i - 1][2].begin(); o != hits[i - 1][2].end(); ++o) { - LxPoint* lPoint2 = *o; - Double_t ldz = lPoint2->z - lPoint0->z; - Double_t ldz2 = ldz * ldz; - Double_t ltx = (lPoint2->x - lPoint0->x) / ldz; - Double_t lty = (lPoint2->y - lPoint0->y) / ldz; - Double_t ldtx2 = (lPoint0->dx2 + lPoint2->dx2) / ldz2; - Double_t ldty2 = (lPoint0->dy2 + lPoint2->dy2) / ldz2; - - Double_t dtx = abs(ltx - rtx); - Double_t dty = abs(lty - rty); - - if (dtx > maxDtx[i - 1]) { - maxDtx[i - 1] = dtx; - dtxDtx2[i - 1] = rdtx2 + ldtx2; - } - - if (dty > maxDty[i - 1]) { - maxDty[i - 1] = dty; - dtyDty2[i - 1] = rdty2 + ldty2; - } - } - } - } - } - } - } - } - - out << endl << "X dispersions: "; - - for (Int_t i = 0; i < LXSTATIONS - 1; ++i) -#ifdef OUT_DISP_BY_TRIPLET_DIR - out << "[" << maxDx[i] / sqrt(finder.caSpace.stations[i + 1]->xOutDispTriplet2 + dxDx2[i]) << "]"; -#else //OUT_DISP_BY_TRIPLET_DIR - out << "[" << maxDx[i] / sqrt(finder.caSpace.stations[i + 1]->xOutDispVertex2 + dxDx2[i]) << "]"; -#endif //OUT_DISP_BY_TRIPLET_DIR - - out << endl << "Y dispersions: "; - - for (Int_t i = 0; i < LXSTATIONS - 1; ++i) -#ifdef OUT_DISP_BY_TRIPLET_DIR - out << "[" << maxDy[i] / sqrt(finder.caSpace.stations[i + 1]->yOutDispTriplet2 + dyDy2[i]) << "]"; -#else //OUT_DISP_BY_TRIPLET_DIR - out << "[" << maxDy[i] / sqrt(finder.caSpace.stations[i + 1]->yOutDispVertex2 + dyDy2[i]) << "]"; -#endif //OUT_DISP_BY_TRIPLET_DIR - - out << endl << "Tx dispersions: "; - - for (Int_t i = 0; i < LXSTATIONS - 1; ++i) - out << "[" << maxDtx[i] / sqrt(finder.caSpace.stations[i + 1]->txInterTripletBreak2 + dtxDtx2[i]) << "]"; - - out << endl << "Ty dispersions: "; - - for (Int_t i = 0; i < LXSTATIONS - 1; ++i) - out << "[" << maxDty[i] / sqrt(finder.caSpace.stations[i + 1]->tyInterTripletBreak2 + dtyDty2[i]) << "]"; - - out << endl; -} - -static Double_t InterLinesDist(LxTrack* track1, LxTrack* track2) -{ - LxTriplet* triplet1 = track1->branches[0]; - LxPoint* point1 = triplet1->center; - Double_t x1 = point1->x; - Double_t y1 = point1->y; - Double_t z1 = point1->z; - - //Double_t tx1 = point1->x / point1->z; - //Double_t delta1 = triplet1->tx - tx1; - - Double_t ax = triplet1->tx; // - 2 * delta1; - Double_t ay = triplet1->ty; - Double_t az = 1.0; - - LxTriplet* triplet2 = track2->branches[0]; - LxPoint* point2 = triplet2->center; - Double_t x2 = point2->x; - Double_t y2 = point2->y; - Double_t z2 = point2->z; - - //Double_t tx2 = point2->x / point2->z; - //Double_t delta2 = triplet2->tx - tx2; - - Double_t bx = triplet2->tx; // - 2 * delta2; - Double_t by = triplet2->ty; - Double_t bz = 1.0; - - Double_t A = ay * bz - az * by; - Double_t B = az * bx - ax * bz; - Double_t C = ax * by - ay * bx; - Double_t P = A * x2 + B * y2 + C * z2; - - Double_t ABCLen = sqrt(A * A + B * B + C * C); - - Double_t cosA = A / ABCLen; - Double_t cosB = B / ABCLen; - Double_t cosC = C / ABCLen; - Double_t p = P / ABCLen; - Double_t interTrackDistance = abs(cosA * x1 + cosB * y1 + cosC * z1 - p); - - return interTrackDistance; -} - -static Double_t RecoTrackChi2(LxTrack* recoTrack) -{ - Double_t breakChi2 = 0; - - for (Int_t j = recoTrack->length - 1; j > 0; --j) { - LxTriplet* rTriplet = recoTrack->branches[j]; - LxTriplet* lTriplet = recoTrack->branches[j - 1]; - - LxStation* station = rTriplet->center->layer->station; - breakChi2 += (lTriplet->tx - rTriplet->tx) * (lTriplet->tx - rTriplet->tx) - / (station->txInterTripletBreak2 + lTriplet->dtx2 + rTriplet->dtx2) - + (lTriplet->ty - rTriplet->ty) * (lTriplet->ty - rTriplet->ty) - / (station->tyInterTripletBreak2 + lTriplet->dty2 + rTriplet->dty2); - } - - breakChi2 /= 2 * (recoTrack->length - 1); - - return breakChi2; -} - -void LxEff::CalcRecoEff(bool joinExt) -{ - Double_t result = 0; - static Int_t signalRecoTracks = 0; - static Int_t signalMCTracks = 0; - // static Int_t bgrRecoTracks = 0; - // static Int_t bgrMCTracks = 0; - static Int_t mc2recoZeroMatched = 0; - static Int_t mc2recoIncomplete = 0; - - bool hasPositiveMCTrack = false; - bool hasNegativeMCTrack = false; - - for (vector<LxMCTrack>::iterator i = finder.MCTracks.begin(); i != finder.MCTracks.end(); ++i) { - LxMCTrack& mcTrack = *i; - Int_t pdgCode = mcTrack.pdg; - map<LxTrack*, Int_t> recoTracks; // Mapped value is the number of common points in MC and reconstructed tracks. - memset(mcTrack.hitsOnStations, 0, sizeof(mcTrack.hitsOnStations)); - bool isSignal = true; - list<LxPoint*> mcTrackHits[LXSTATIONS][LXLAYERS]; - - for (vector<LxMCPoint*>::iterator j = mcTrack.Points.begin(); j != mcTrack.Points.end(); ++j) { - LxMCPoint* pMCPoint = *j; - - for (list<LxPoint*>::iterator k = pMCPoint->lxPoints.begin(); k != pMCPoint->lxPoints.end(); ++k) { - LxPoint* point = *k; - mcTrack.hitsOnStations[point->layer->station->stationNumber][point->layer->layerNumber] = true; - mcTrackHits[point->layer->station->stationNumber][point->layer->layerNumber].push_back(point); - LxTrack* track = point->track; - - if (0 == track) continue; - - if (track->matched) continue; - - if (track->clone) continue; - - map<LxTrack*, int>::iterator l = recoTracks.find(track); - - if (l != recoTracks.end()) ++(l->second); - else - recoTracks[track] = 1; - } - } - - bool enoughHits = true; - mcTrack.stationsWithHits = 0; - mcTrack.layersWithHits = 0; - - for (Int_t j = 0; j < LXSTATIONS; ++j) { - Int_t hitsOnSt = 0; - - for (Int_t k = 0; k < LXLAYERS; ++k) { - if (mcTrack.hitsOnStations[j][k]) { - ++hitsOnSt; - ++mcTrack.layersWithHits; - } - } - - if (hitsOnSt < 3) { - if (j < finder.caSpace.stationsInAlgo) enoughHits = false; - } - else - ++mcTrack.stationsWithHits; - } - - Double_t pt2 = mcTrack.px * mcTrack.px + mcTrack.py * mcTrack.py; - - if (!enoughHits || mcTrack.mother_ID >= 0 || (pdgCode != 13 && pdgCode != -13) - || (finder.pPtCut && (mcTrack.p < 3.0 || pt2 < 1.0))) - isSignal = false; - else - ++signalMCTracks; - - if (isSignal) { - if (-13 == pdgCode) hasPositiveMCTrack = true; - else - hasNegativeMCTrack = true; - } - - LxTrack* matchTrack = 0; - Int_t matchedPoints = 0; - - for (map<LxTrack*, Int_t>::iterator j = recoTracks.begin(); j != recoTracks.end(); ++j) { - if (0 == matchTrack || matchedPoints < j->second) { - matchTrack = j->first; - matchedPoints = j->second; - } - } - - if (0 == matchTrack) { -#ifdef MAKE_EFF_CALC - //finder.incomplete_events << finder.eventNumber << " matched points: " << matchedPoints << " ; MC points: " << mcTrack.Points.size() << endl; - //finder.caSpace.CheckArray(finder.incomplete_events, mcTrack); -#endif //MAKE_EFF_CALC \ - //cout << "MC track does not have common point with a reconstructed" << endl; - if (isSignal) { - ++mc2recoZeroMatched; - AnalyzeNotMatchedMC(finder.incomplete_events, mcTrackHits); - } - -#ifdef CLUSTER_MODE - if (isSignal) DumpNotMatchedMC(mcTrackHits); -#endif //CLUSTER_MODE - - continue; - } - - Int_t numberOfMuchMCPoints = LXLAYERS * finder.caSpace.stationsInAlgo; - - if (matchedPoints < 0.7 * numberOfMuchMCPoints) { -#ifdef MAKE_EFF_CALC - //finder.incomplete_events << finder.eventNumber << " matched points: " << matchedPoints << " ; MC points: " << mcTrack.Points.size() << endl; - //finder.caSpace.CheckArray(finder.incomplete_events, mcTrack); -#endif //MAKE_EFF_CALC \ - //cout << "MC track have only " << matchedPoints << " common points with reconstructed" << endl; - if (isSignal) { - ++mc2recoIncomplete; - AnalyzeNotMatchedMC(finder.incomplete_events, mcTrackHits); - } - -#ifdef CLUSTER_MODE - if (isSignal) DumpNotMatchedMC(mcTrackHits); -#endif //CLUSTER_MODE - - continue; - } - - matchTrack->mcTrack = &mcTrack; - matchTrack->matched = true; - - if (!isSignal) continue; - -#ifdef CALC_LINK_WITH_STS_EFF - if (0 != matchTrack && matchedPoints >= 0.7 * numberOfMuchMCPoints) matchTrack->mcTracks.push_back(&mcTrack); -#endif //CALC_LINK_WITH_STS_EFF - - if (!joinExt) ++signalRecoTracks; - else { - if (0 == matchTrack->externalTrack) { - if (0 == mcTrack.externalTrack) ++signalRecoTracks; - } - else if (matchTrack->externalTrack->track == mcTrack.externalTrack) - ++signalRecoTracks; - } - } - - result = 100 * signalRecoTracks; - result /= signalMCTracks; - -#ifdef MAKE_EFF_CALC - //if (foundNow != mcNow) - //finder.incomplete_events << finder.eventNumber << endl; -#endif //MAKE_EFF_CALC - - cout << "LxEff::CalcRecoEff signal efficiency: " << result << "( " << signalRecoTracks << " / " << signalMCTracks - << " )" << endl; - cout << "LxEff::CalcRecoEff: zero-matched: " << mc2recoZeroMatched << ", incomplete: " << mc2recoIncomplete << endl; - - bool hasPositiveTrack = false; - bool hasNegativeTrack = false; - - for (list<LxTrack*>::iterator i = finder.caSpace.tracks.begin(); i != finder.caSpace.tracks.end(); ++i) { - LxTrack* recoTrack = *i; - - if (recoTrack->clone) continue; - - //if (recoTrack->length > finder.caSpace.stationsInAlgo) - //continue; - - LxTriplet* firstTriplet = recoTrack->branches[0]; - LxPoint* firstPoint = firstTriplet->center; - Double_t particleSign = firstTriplet->tx - firstPoint->x / firstPoint->z; - LxTriplet* secondTriplet = recoTrack->branches[1]; - LxPoint* secondPoint = secondTriplet->center; - Double_t tx = (secondPoint->x - firstPoint->x) / (secondPoint->z - firstPoint->z); - Double_t particleSign2 = tx - firstPoint->x / firstPoint->z; - // Double_t yAtZ0 = firstPoint->y - firstTriplet->ty * firstPoint->z; - // Double_t breakChi2 = RecoTrackChi2(recoTrack); - - //if (-9 <= yAtZ0 && 9 >= yAtZ0) - //if (breakChi2 <= 3) - { - if (particleSign > 0 && particleSign2 > 0) hasPositiveTrack = true; - else if (particleSign < 0 && particleSign2 < 0) - hasNegativeTrack = true; - } - } - - static Int_t numberOfJpsi = 0; - - if (hasPositiveTrack && hasNegativeTrack) ++numberOfJpsi; - - static Int_t numberOfMCJpsi = 0; - static Int_t numberOfTrueJpsi = 0; - - if (hasPositiveMCTrack && hasNegativeMCTrack) { - ++numberOfMCJpsi; - - if (hasPositiveTrack && hasNegativeTrack) ++numberOfTrueJpsi; - } - - cout << "LxEff::CalcRecoEff: number of J/Psi hypoteses " << numberOfJpsi << endl; - result = 100 * numberOfTrueJpsi; - result /= numberOfMCJpsi; - cout << "LxEff::CalcRecoEff: J/Psi efficiency " << result << " % ( " << numberOfTrueJpsi << " / " << numberOfMCJpsi - << " )" << endl; - - return; - - // The code below is mostly dedicated to counting ghosts. - static Int_t recoTracks = 0; - static Int_t matchedMCTracks = 0; - static Int_t completeleyUnmatched = 0; - static Int_t notEnoughPoints = 0; - static Int_t notEnoughStations = 0; - static Int_t incompleteStations[LXSTATIONS] = {}; - static Int_t doesntHaveStsPart = 0; - static Int_t doesntHaveStsPart1 = 0; - static Int_t doesntHaveStsPart2 = 0; - static Int_t unmatchedButHaveStsPart = 0; - - for (list<LxTrack*>::iterator i = finder.caSpace.tracks.begin(); i != finder.caSpace.tracks.end(); ++i) { - //++recoTracks; - LxTrack* recoTrack = *i; - - if (recoTrack->clone) continue; - - map<LxMCTrack*, Int_t> mcTracks; // Mapped value is the number of common points in MC and reconstructed tracks. - -#ifdef CLUSTER_MODE - for (Int_t ii = 0; ii < recoTrack->length; ++ii) { - LxRay* ray = recoTrack->rays[ii]; - - for (list<LxPoint*>::iterator j = ray->clusterPoints.begin(); j != ray->clusterPoints.end(); ++j) { - LxPoint* recoPoint = *j; -#else //CLUSTER_MODE - for (Int_t j = 0; j < finder.caSpace.stationsInAlgo * LXLAYERS; ++j) { - LxPoint* recoPoint = recoTrack->points[j]; -#endif //CLUSTER_MODE - - if (0 == recoPoint) continue; - - for (list<LxMCPoint*>::iterator k = recoPoint->mcPoints.begin(); k != recoPoint->mcPoints.end(); ++k) { - LxMCPoint* mcPoint = *k; - LxMCTrack* mcTrack = mcPoint->track; - - if (0 == mcTrack) continue; - - map<LxMCTrack*, Int_t>::iterator mcIter = mcTracks.find(mcTrack); - - if (mcIter == mcTracks.end()) mcTracks[mcTrack] = 1; - else - ++(mcIter->second); - } -#ifdef CLUSTER_MODE - } -#endif //CLUSTER_MODE - } // for (Int_t j = 0; j < (LXSTATIONS - LXFIRSTSTATION) * LXLAYERS; ++j) - - LxMCTrack* bestMatch = 0; - Int_t matchedPoints = 0; - - for (map<LxMCTrack*, Int_t>::iterator j = mcTracks.begin(); j != mcTracks.end(); ++j) { - if (0 == bestMatch || j->second > matchedPoints) { - bestMatch = j->first; - matchedPoints = j->second; - } - } - - if (0 == bestMatch) { - ++completeleyUnmatched; - cout << "This reconstructed track is not intersected with any MC track " - "in any point" - << endl; - - if (!joinExt || 0 != recoTrack->externalTrack) ++recoTracks; - - continue; - } - - ++recoTracks; - - bool unmatched = false; - - if (matchedPoints < 0.7 * finder.caSpace.stationsInAlgo * LXLAYERS) { - ++notEnoughPoints; - cout << "This reconstructed track match with an MC track in only " << matchedPoints << "points" << endl; - unmatched = true; - } - - if (bestMatch->stationsWithHits < finder.caSpace.stationsInAlgo) { - ++notEnoughStations; - -#ifdef LXDRAW - LxDraw drawer; - drawer.ClearView(); - drawer.DrawInputHits(); - drawer.DrawMCTracks(); - drawer.DrawRays(); - -#ifdef LXDRAWSAVE - char drawSaveName[64]; - sprintf(drawSaveName, "MC_Rays_%d_", finder.eventNumber); - drawer.SaveCanvas(drawSaveName); -#endif //LXDRAWSAVE - -#ifdef LXDRAWWAIT - gPad->WaitPrimitive(); -#endif //LXDRAWWAIT -#endif //LXDRAW - - for (Int_t j = 0; j < finder.caSpace.stationsInAlgo; ++j) { - Int_t hitsOnStation = 0; - - for (Int_t k = 0; k < LXLAYERS; ++k) { - if (bestMatch->hitsOnStations[j][k]) ++hitsOnStation; - } - - if (hitsOnStation < 3) ++incompleteStations[j]; - } - - cout << "The matched MC track has hits not on all stations. Only on: " << bestMatch->stationsWithHits << endl; - unmatched = true; - } - - if (0 == bestMatch->externalTrack) { - ++doesntHaveStsPart; - - if (unmatched) ++doesntHaveStsPart1; - else - ++doesntHaveStsPart2; - } - - if (!unmatched) { - if (!joinExt) ++matchedMCTracks; - else { - if (0 == recoTrack->externalTrack) { - if (0 == bestMatch->externalTrack) ++matchedMCTracks; - else - cout << "LxEff::CalcRecoEff: STS track not found" << endl; - } - else { - if (bestMatch->externalTrack == recoTrack->externalTrack->track) ++matchedMCTracks; - else - cout << "LxEff::CalcRecoEff: STS track determined wrongly" << endl; - } - } - } - else if (0 != bestMatch->externalTrack) - ++unmatchedButHaveStsPart; - } // for (list<LxTrack*>::iterator i = finder.caSpace.tracks.begin(); i != finder.caSpace.tracks.end(); ++i) - - result = 100 * matchedMCTracks; - result /= recoTracks; - cout << "LxEff::CalcRecoEff matching reconstucted efficiency: " << result << "( " << matchedMCTracks << " / " - << recoTracks << " )" << endl; - cout << "LxEff::CalcRecoEff 0-matched: " << completeleyUnmatched << ", not enough points: " << notEnoughPoints - << ", not enough stations: " << notEnoughStations << " : "; - - for (Int_t i = 0; i < finder.caSpace.stationsInAlgo; ++i) - cout << "[" << incompleteStations[i] << "]"; - - cout << endl; - cout << "LxEff::CalcRecoEff doesn't have an STS part: " << doesntHaveStsPart << ", unmatched: " << doesntHaveStsPart1 - << ", matched: " << doesntHaveStsPart2 << endl; - cout << "LxEff::CalcRecoEff unmatched but have an STS part: " << unmatchedButHaveStsPart << endl; -} // void LxEff::CalcRecoEff(bool joinExt) - -void LxFinderTriplet::MatchRecoToMC() -{ - static Int_t recoTracks = 0; - static Int_t matchedTracks = 0; - LxTrack* positiveSignal = 0; - Double_t positiveDelta = 0; - Double_t negativeDelta = 0; - LxTrack* negativeSignal = 0; - list<LxTrack*> positiveBgrs; - list<LxTrack*> negativeBgrs; - - for (list<LxTrack*>::iterator i = caSpace.tracks.begin(); i != caSpace.tracks.end(); ++i) { - LxTrack* recoTrack = *i; - - if (recoTrack->clone) continue; - - ++recoTracks; - - map<LxMCTrack*, Int_t> mcTracks; // Mapped value is the number of common points in MC and reconstructed tracks. - - for (Int_t j = 0; j < caSpace.stationsInAlgo * LXLAYERS; ++j) { - LxPoint* recoPoint = recoTrack->points[j]; - - if (0 == recoPoint) continue; - - for (list<LxMCPoint*>::iterator k = recoPoint->mcPoints.begin(); k != recoPoint->mcPoints.end(); ++k) { - LxMCPoint* mcPoint = *k; - LxMCTrack* mcTrack = mcPoint->track; - - if (0 == mcTrack) continue; - - map<LxMCTrack*, Int_t>::iterator mcIter = mcTracks.find(mcTrack); - - if (mcIter == mcTracks.end()) mcTracks[mcTrack] = 1; - else - ++(mcIter->second); - } // for (list<LxMCPoint*>::iterator k = recoPoint->mcPoints.begin(); k != recoPoint->mcPoints.end(); ++k) - } // for (Int_t j = 0; j < caSpace.stationsInAlgo * LXLAYERS; ++j) - - LxMCTrack* bestMatch = 0; - Int_t matchedPoints = 0; - - for (map<LxMCTrack*, Int_t>::iterator j = mcTracks.begin(); j != mcTracks.end(); ++j) { - if (0 == bestMatch || j->second > matchedPoints) { - bestMatch = j->first; - matchedPoints = j->second; - } - } - - LxTriplet* firstTriplet = recoTrack->branches[0]; - LxPoint* firstPoint = firstTriplet->center; - Double_t particleSign = firstTriplet->tx - firstPoint->x / firstPoint->z; - Double_t yAtZ0 = firstPoint->y - firstTriplet->ty * firstPoint->z; - LxTriplet* secondTriplet = recoTrack->branches[1]; - LxPoint* secondPoint = secondTriplet->center; - Double_t yAtZ0_2 = - firstPoint->y - firstPoint->z * (secondPoint->y - firstPoint->y) / (secondPoint->z - firstPoint->z); - Double_t breakChi2 = RecoTrackChi2(recoTrack); - - if (0 == bestMatch || matchedPoints < 0.7 * caSpace.stationsInAlgo * LXLAYERS) { - if (particleSign > 0) positiveBgrs.push_back(recoTrack); - else if (particleSign < 0) - negativeBgrs.push_back(recoTrack); - - bgrYAtZ0->Fill(yAtZ0); - bgrYAtZ0_2->Fill(yAtZ0_2); - backgroundChi2Histo->Fill(breakChi2); - - continue; - } - - ++matchedTracks; - - if (0 > bestMatch->mother_ID && (-13 == bestMatch->pdg || 13 == bestMatch->pdg)) { - if (particleSign > 0 && -13 == bestMatch->pdg) { - positiveSignal = recoTrack; - positiveDelta = particleSign; - } - else if (particleSign < 0 && 13 == bestMatch->pdg) { - negativeSignal = recoTrack; - negativeDelta = particleSign; - } - - signalYAtZ0->Fill(yAtZ0); - signalYAtZ0_2->Fill(yAtZ0_2); - signalChi2Histo->Fill(breakChi2); - } - else { - if (particleSign > 0) positiveBgrs.push_back(recoTrack); - else if (particleSign < 0) - negativeBgrs.push_back(recoTrack); - - bgrYAtZ0->Fill(yAtZ0); - bgrYAtZ0_2->Fill(yAtZ0_2); - backgroundChi2Histo->Fill(breakChi2); - } - } // for (list<LxTrack*>::iterator i = caSpace.tracks.begin(); i != caSpace.tracks.end(); ++i) - - Double_t result = 100 * matchedTracks; - result /= recoTracks; - cout << "LxFinderTriplet::MatchRecoToMC(): efficiency: " << result << " % ( " << matchedTracks << " / " << recoTracks - << " )" << endl; - - if (0 != positiveSignal && 0 != negativeSignal) { - signalInterTracksDistance->Fill(InterLinesDist(positiveSignal, negativeSignal)); - signalSignDefect->Fill(positiveDelta + negativeDelta); - } - - LxTrack* posBgr = 0; - LxTrack* negBgr = 0; - Double_t bgrDist = 10000; - Double_t signDefect = 10000; - - for (list<LxTrack*>::iterator i = positiveBgrs.begin(); i != positiveBgrs.end(); ++i) { - LxTrack* track1 = *i; - - for (list<LxTrack*>::iterator j = negativeBgrs.begin(); j != negativeBgrs.end(); ++j) { - LxTrack* track2 = *j; - Double_t dist = InterLinesDist(track1, track2); - - if (dist < bgrDist) { - posBgr = track1; - negBgr = track2; - bgrDist = dist; - } - - LxTriplet* firstTriplet1 = track1->branches[0]; - LxPoint* firstPoint1 = firstTriplet1->center; - Double_t particleSign1 = firstTriplet1->tx - firstPoint1->x / firstPoint1->z; - - LxTriplet* firstTriplet2 = track2->branches[0]; - LxPoint* firstPoint2 = firstTriplet2->center; - Double_t particleSign2 = firstTriplet2->tx - firstPoint2->x / firstPoint2->z; - - Double_t defect = particleSign1 + particleSign2; - - if (abs(defect) < abs(signDefect)) signDefect = defect; - } - } // for (list<LxTrack*>::iterator i = positiveBgrs.begin(); i != positiveBgrs.end(); ++i) - - if (0 != posBgr && 0 != negBgr) { - bgrInterTracksDistance->Fill(bgrDist); - bgrSignDefect->Fill(signDefect); - } -} // void LxFinderTriplet::MatchRecoToMC() diff --git a/reco/tracking/lxTriplet/LxEff.h b/reco/tracking/lxTriplet/LxEff.h deleted file mode 100644 index fd4cb7d3857956e4313a106cbd447d7decd8c526..0000000000000000000000000000000000000000 --- a/reco/tracking/lxTriplet/LxEff.h +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright (C) 2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifndef LXEFF_INCLUDED -#define LXEFF_INCLUDED - -#pragma GCC diagnostic ignored "-Weffc++" - -#include "Rtypes.h" - -#include <iostream> -#include <list> -#include <map> - -#include "LxSettings.h" - -class LxFinderTriplet; -class LxPoint; - -struct LxEff { - explicit LxEff(LxFinderTriplet& owner); - void CalcRecoEff(bool joinExt); - void AnalyzeNotMatchedMC(std::ofstream& out, std::list<LxPoint*> hits[LXSTATIONS][LXLAYERS]); -#ifdef CLUSTER_MODE - void AnalyzeNotMatched(std::ofstream& out, std::list<LxPoint*> hits[LXSTATIONS][LXLAYERS]); - void AnalyzeNotMatched2(std::ofstream& out, std::list<LxPoint*> hits[LXSTATIONS][LXLAYERS]); - void DumpNotMatchedMC(std::list<LxPoint*> hits[LXSTATIONS][LXLAYERS]); -#endif //CLUSTER_MODE - LxFinderTriplet& finder; -}; - -struct LxMCTrack; - -struct LxStsMCPoint { - Double_t p, q, x, y, z, px, py, pz; - Int_t stationNumber; - LxMCTrack* mcTrack; -}; - -#endif //LXEFF_INCLUDED diff --git a/reco/tracking/lxTriplet/LxLinkDef.h b/reco/tracking/lxTriplet/LxLinkDef.h deleted file mode 100644 index 7f1de45d5b63612a76f37c61ad21d59ae5818382..0000000000000000000000000000000000000000 --- a/reco/tracking/lxTriplet/LxLinkDef.h +++ /dev/null @@ -1,16 +0,0 @@ -/* Copyright (C) 2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -// $Id: LxLinkDef.h,v 1.10 2013/09/30 11:36:47 tablyaz Exp $ - -#ifdef __CINT__ - -#pragma link off all globals; -#pragma link off all classes; -#pragma link off all functions; - -#pragma link C++ class LxFinderTriplet + ; -#pragma link C++ class LxTrackAnaTriplet + ; - -#endif diff --git a/reco/tracking/lxTriplet/LxMC.cxx b/reco/tracking/lxTriplet/LxMC.cxx deleted file mode 100644 index 69ee3402021639ac9300d2a64072bbe038fb1296..0000000000000000000000000000000000000000 --- a/reco/tracking/lxTriplet/LxMC.cxx +++ /dev/null @@ -1,5 +0,0 @@ -/* Copyright (C) 2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#include "LxMC.h" diff --git a/reco/tracking/lxTriplet/LxMC.h b/reco/tracking/lxTriplet/LxMC.h deleted file mode 100644 index b3c010c38b4ef4bf9eff58304ba1bcf40d3492c3..0000000000000000000000000000000000000000 --- a/reco/tracking/lxTriplet/LxMC.h +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright (C) 2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifndef LXMC_INCLUDED -#define LXMC_INCLUDED - -#pragma GCC diagnostic ignored "-Weffc++" - -#include "CbmStsTrack.h" - -#include "Rtypes.h" - -#include <list> -#include <vector> - -#include "LxSettings.h" - -struct LxPoint; -struct LxStsMCPoint; -struct LxMCTrack; - -struct LxMCPoint { - Double_t p, q, x, y, z, px, py, pz; - Int_t stationNumber, layerNumber; - std::list<LxPoint*> lxPoints; - Int_t trackId; // Original track id -- an index (offset) in the array of MC tracks. - LxMCTrack* track; -}; - -struct LxMCTrack { - Double_t p, q, x, y, z, px, py, pz; - Int_t mother_ID; - Int_t pdg; - std::vector<LxMCPoint*> Points; -#ifdef MAKE_STS_MC_RESEARCHES - std::list<LxStsMCPoint*> stsPoints[8]; -#endif //MAKE_STS_MC_RESEARCHES - UInt_t fUniqueID; - CbmStsTrack* externalTrack; - Int_t stationsWithHits; - Int_t layersWithHits; - bool hitsOnStations[LXSTATIONS][LXLAYERS]; -}; - -#endif //LXMC_INCLUDED diff --git a/reco/tracking/lxTriplet/LxSettings.h b/reco/tracking/lxTriplet/LxSettings.h deleted file mode 100644 index 266c4e4352a6d6d1236784933e1fdf101d709f60..0000000000000000000000000000000000000000 --- a/reco/tracking/lxTriplet/LxSettings.h +++ /dev/null @@ -1,62 +0,0 @@ -/* Copyright (C) 2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifndef LXSETTINGS_INCLUDED -#define LXSETTINGS_INCLUDED - -#define LXPI 3.141592653589793238462643383279 - -#define LXLAYERS 3 -#define LXSTATIONS 6 -#define LXMIDDLE 1 -#define LXFIRSTSTATION 0 -#define LXSTSSTATIONS 8 - -#define MAKE_HISTOS - -#ifdef MAKE_HISTOS -//#define MAKE_ANGLE_HISTOS -//#define MAKE_BRAKE_ANGLE_HISTOS -//#define MAKE_DISPERSE_HISTOS -#define MAKE_DISPERSE_2D_HISTOS -//#define MAKE_MU_PLUS_MU_MINUS_HISTOS -//#define MAKE_DIFF_FIT_HISTOS -//#define MAKE_DIFF_FIRST_HISTOS -//#define MAKE_FIT_COEFFS_HISTOS -//#define MAKE_LAST_STS_NEAREST_Y - -#endif //MAKE_HISTOS - -#define MAKE_STS_MC_RESEARCHES -#define MAKE_EFF_CALC -//#define CALC_MUCH_DETECTORS_EFF -#define CALC_LINK_WITH_STS_EFF - -//#define CLUSTER_MODE - -#ifdef CLUSTER_MODE - -#define DENSE_CLUSTERS_FIRST -#define BEST_RAYS_ONLY - -#ifdef BEST_RAYS_ONLY - -#define REMOVE_SUBCLUSTER -#define BEST_SIX_POINTS - -#endif //BEST_RAYS_ONLY - -#define REMEMBER_CLUSTERED_RAYS_IN_POINTS - -#endif //CLUSTER_MODE - -//#define USE_KALMAN -//#define USE_KALMAN_FIT - -//#define USE_SEGMENTS -//#define OUT_DISP_BY_TRIPLET_DIR - -#define LX_DEBUG - -#endif //LXSETTINGS_INCLUDED diff --git a/reco/tracking/lxTriplet/LxTrackAna.cxx b/reco/tracking/lxTriplet/LxTrackAna.cxx deleted file mode 100644 index 208d3650ab6339beabaf6910aefc7587593c7a77..0000000000000000000000000000000000000000 --- a/reco/tracking/lxTriplet/LxTrackAna.cxx +++ /dev/null @@ -1,1044 +0,0 @@ -/* Copyright (C) 2016-2021 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#include "LxTrackAna.h" - -#include "CbmKFTrack.h" -#include "CbmMCTrack.h" -#include "CbmMuchCluster.h" -#include "CbmMuchDigiMatch.h" -#include "CbmMuchGeoScheme.h" -#include "CbmMuchPoint.h" -#include "CbmStsAddress.h" -#include "CbmStsPoint.h" -#include "CbmStsTrack.h" -#include "TDatabasePDG.h" -#include "TH1.h" -#include "TH2.h" - -#include <iostream> - -#include <dirent.h> -#include <sys/stat.h> -#include <sys/types.h> - -ClassImp(LxTrackAnaTriplet) - - using namespace std; - -//static Double_t xRms = 1.005;// Averaged MC -static Double_t xRms = 1.202; // Nearest hit -static Double_t xRms2 = xRms * xRms; -//static Double_t yRms = 0.9467;// Averaged MC -static Double_t yRms = 1.061; // Nearest hit -static Double_t yRms2 = yRms * yRms; -//static Double_t txRms = 0.02727;// Averaged MC -static Double_t txRms = 0.02426; // Nearest hit -static Double_t txRms2 = txRms * txRms; -//static Double_t tyRms = 0.01116;// Averaged MC -static Double_t tyRms = 0.01082; // Nearest hit -static Double_t tyRms2 = tyRms * tyRms; -static Double_t cutCoeff = 3.0; - -static TH1F* muchStsBreakX = 0; -static TH1F* muchStsBreakY = 0; -static TH1F* muchStsBreakTx = 0; -static TH1F* muchStsBreakTy = 0; - -static TH1F* stsMuchBreakX = 0; -static TH1F* stsMuchBreakY = 0; - -static TH1F* signalChi2 = 0; -static TH1F* bgrChi2 = 0; - -static TH1F* bgrInvMass = 0; -static list<LxSimpleTrack*> positiveTracks; -static list<LxSimpleTrack*> negativeTracks; -static TH1F* sigInvMass = 0; - -static TH1F* nearestHitDist[LXSTATIONS] = {0}; -static TH1F* hitsDist[LXSTATIONS] = {0}; - -static TH1F* muPlusStsTxDiff = 0; -static TH1F* muMinusStsTxDiff = 0; -static TH1F* muPlusStsXDiff = 0; -static TH1F* muMinusStsXDiff = 0; -static TH1F* muPlusVertexTxDiff = 0; -static TH1F* muMinusVertexTxDiff = 0; - -static TH2F* muPlusStsBeginTxDiff2D = 0; -static TH2F* muMinusStsBeginTxDiff2D = 0; - -static TH1F* deltaPhiPi = 0; - -static TH1F* jPsiMuonsMomsHisto = 0; - -struct MomVsTxRange { - Double_t momLow; - Double_t momHigh; - Double_t txLow; - Double_t txHigh; -}; - -static bool momFitTxBreak(Double_t mom, Double_t txBreak) -{ - if (mom < 3.0) return false; - - if (txBreak < 0) txBreak = -txBreak; - - Double_t inv = mom * txBreak; - return inv > 0.18 && inv < 0.52; -} - -void LxSimpleTrack::RebindMuchTrack() -{ - linkedStsTrack = 0; - - while (!linkedStsTracks.empty()) { - pair<LxSimpleTrack*, Double_t> trackDesc = linkedStsTracks.front(); - linkedStsTracks.pop_front(); - LxSimpleTrack* anotherMuchTrack = trackDesc.first->linkedMuchTrack.first; - - if (0 == anotherMuchTrack || trackDesc.second < trackDesc.first->linkedMuchTrack.second) { - trackDesc.first->linkedMuchTrack.first = this; - trackDesc.first->linkedMuchTrack.second = trackDesc.second; - linkedStsTrack = trackDesc.first; - - if (0 != anotherMuchTrack) anotherMuchTrack->RebindMuchTrack(); - - break; - } - } -} - -LxTrackAnaTriplet::LxTrackAnaTriplet() - : listMCTracks(0) - , listStsPts(0) - , listMuchPts(0) - , listMuchPixelHits(0) - , listMuchClusters(0) - , listMuchPixelDigiMatches(0) - , allTracks() - , posTracks() - , negTracks() - , superEventTracks(0) - , superEventBrachTrack(0, 0, 0, 0, 0, 0, 0, 0) - , useHitsInStat(false) - , averagePoints(false) - , dontTouchNonPrimary(true) - , useChargeSignInCuts(false) - , buildConnectStat(false) - , buildBgrInvMass(false) - , buildSigInvMass(false) - , joinData(false) - , buildNearestHitDist(false) - , cropHits(false) - , buildSegmentsStat(true) - , particleType("jpsi") - , segmentsAnalyzer(*this) -{ -} - -LxTrackAnaTriplet::~LxTrackAnaTriplet() { Clean(); } - -void LxTrackAnaTriplet::Clean() -{ - for (vector<LxSimpleTrack*>::iterator i = allTracks.begin(); i != allTracks.end(); ++i) - delete *i; - - allTracks.clear(); - posTracks.clear(); - negTracks.clear(); -} - -InitStatus LxTrackAnaTriplet::Init() -{ - FairRootManager* fManager = FairRootManager::Instance(); - listMCTracks = static_cast<TClonesArray*>(fManager->GetObject("MCTrack")); - - if (0 == listMCTracks) return kFATAL; - - listStsPts = static_cast<TClonesArray*>(fManager->GetObject("StsPoint")); - - if (0 == listStsPts) return kFATAL; - - listMuchPts = static_cast<TClonesArray*>(fManager->GetObject("MuchPoint")); - - if (0 == listMuchPts) return kFATAL; - - if (useHitsInStat) { - listMuchPixelHits = static_cast<TClonesArray*>(fManager->GetObject("MuchPixelHit")); - - if (0 == listMuchPixelHits) return kFATAL; - - listMuchClusters = static_cast<TClonesArray*>(fManager->GetObject("MuchCluster")); - - if (0 == listMuchClusters) return kFATAL; - - listMuchPixelDigiMatches = static_cast<TClonesArray*>(fManager->GetObject("MuchDigiMatch")); - - if (0 == listMuchPixelDigiMatches) return kFATAL; - } - - if (buildConnectStat) { - muchStsBreakX = new TH1F("muchStsBreakX", "Break in prediction of X in STS", 100, -20., 20.); - muchStsBreakX->StatOverflows(); - muchStsBreakY = new TH1F("muchStsBreakY", "Break in prediction of Y in STS", 100, -20., 20.); - muchStsBreakY->StatOverflows(); - muchStsBreakTx = new TH1F("muchStsBreakTx", "Break in prediction of Tx in STS", 100, -0.15, 0.15); - muchStsBreakTx->StatOverflows(); - muchStsBreakTy = new TH1F("muchStsBreakTy", "Break in prediction of Ty in STS", 100, -0.15, 0.15); - muchStsBreakTy->StatOverflows(); - - stsMuchBreakX = new TH1F("stsMuchBreakX", "Break in prediction of X in MUCH", 100, -20., 20.); - stsMuchBreakX->StatOverflows(); - stsMuchBreakY = new TH1F("stsMuchBreakY", "Break in prediction of Y in MUCH", 100, -20., 20.); - stsMuchBreakY->StatOverflows(); - - signalChi2 = new TH1F("signalChi2", "Chi2 of signal", 100, 0., 15.); - signalChi2->StatOverflows(); - bgrChi2 = new TH1F("bgrChi2", "Chi2 of background", 100, 0., 20.); - bgrChi2->StatOverflows(); - } // if (buildConnectStat) - - if (buildBgrInvMass) { - if (joinData) { - bgrInvMass = new TH1F("bgrInvMass", "Invariant mass distribution for background", 1000, 2., 4.); - bgrInvMass->StatOverflows(); - } - else { - superEventTracks = new TTree("SuperEventTracks", "Tracks for building a super event"); - superEventTracks->Branch("tracks", &superEventBrachTrack.px, "px/D:py:pz:e:charge"); - } - } // if (buildBgrInvMass) - - if (buildSigInvMass) { - sigInvMass = new TH1F("sigInvMass", "Invariant mass distribution for signal", 1000, 2., 4.); - sigInvMass->StatOverflows(); - } // if (buildSigInvMass) - - if (buildNearestHitDist && useHitsInStat) { - char name[32]; - char title[128]; - - for (Int_t i = 0; i < LXSTATIONS; ++i) { - sprintf(name, "nearestHitDist_%d", i); - sprintf(title, "Distance from a MC point to the nearest hit at %d station", i); - nearestHitDist[i] = new TH1F(name, title, 100, 0., 5.); - nearestHitDist[i]->StatOverflows(); - sprintf(name, "hitsDist_%d", i); - sprintf(title, "Distance from a MC point to the hits at %d station", i); - hitsDist[i] = new TH1F(name, title, 100, 0., 7.); - hitsDist[i]->StatOverflows(); - } - } - - muPlusStsTxDiff = new TH1F("muPlusStsTxDiff", "muPlusStsTxDiff", 100, -0.2, 0.2); - muPlusStsTxDiff->StatOverflows(); - muMinusStsTxDiff = new TH1F("muMinusStsTxDiff", "muMinusStsTxDiff", 100, -0.2, 0.2); - muMinusStsTxDiff->StatOverflows(); - muPlusStsXDiff = new TH1F("muPlusStsXDiff", "muPlusStsXDiff", 100, -10.0, 10.0); - muPlusStsXDiff->StatOverflows(); - muMinusStsXDiff = new TH1F("muMinusStsXDiff", "muMinusStsXDiff", 100, -10.0, 10.0); - muMinusStsXDiff->StatOverflows(); - muPlusVertexTxDiff = new TH1F("muPlusVertexTxDiff", "muPlusVertexTxDiff", 100, -0.2, 0.2); - muPlusVertexTxDiff->StatOverflows(); - muMinusVertexTxDiff = new TH1F("muMinusVertexTxDiff", "muMinusVertexTxDiff", 100, -0.2, 0.2); - muMinusVertexTxDiff->StatOverflows(); - - muPlusStsBeginTxDiff2D = new TH2F("muPlusStsBeginTxDiff2D", "muPlusStsBeginTxDiff2D", 100, 0., 25., 100, -0.2, 0.2); - muPlusStsBeginTxDiff2D->StatOverflows(); - muMinusStsBeginTxDiff2D = - new TH2F("muMinusStsBeginTxDiff2D", "muMinusStsBeginTxDiff2D", 100, 0., 25.0, 100, -0.2, 0.2); - muMinusStsBeginTxDiff2D->StatOverflows(); - - deltaPhiPi = new TH1F("deltaPhiPi", "deltaPhiPi", 100, 0., 1.0); - deltaPhiPi->StatOverflows(); - - jPsiMuonsMomsHisto = new TH1F("jPsiMuonsMomsHisto", "J/Psi muons momenta distribution", 200, 0., 25.); - jPsiMuonsMomsHisto->StatOverflows(); - - segmentsAnalyzer.Init(); - - return kSUCCESS; -} - -static void SaveHisto(TH1* histo, const char* particleType, const char* name) -{ - if (!saveHistos) return; - - char dir_name[256]; - sprintf(dir_name, "configuration.%s", particleType); - DIR* dir = opendir(dir_name); - - if (dir) - closedir(dir); - else - mkdir(dir_name, 0700); - - char file_name[256]; - sprintf(file_name, "%s/%s", dir_name, name); - TFile fh(file_name, "RECREATE"); - histo->Write(); - fh.Close(); - delete histo; -} - -static void BuildInvMass(list<LxSimpleTrack*>& pTracks, list<LxSimpleTrack*>& nTracks, TH1* histo) -{ - for (list<LxSimpleTrack*>::iterator i = pTracks.begin(); i != pTracks.end(); ++i) { - LxSimpleTrack* posTrack = *i; - - for (list<LxSimpleTrack*>::iterator j = nTracks.begin(); j != nTracks.end(); ++j) { - LxSimpleTrack* negTrack = *j; - Double_t E12 = posTrack->e + negTrack->e; - Double_t px12 = posTrack->px + negTrack->px; - Double_t py12 = posTrack->py + negTrack->py; - Double_t pz12 = posTrack->pz + negTrack->pz; - Double_t m122 = E12 * E12 - px12 * px12 - py12 * py12 - pz12 * pz12; - Double_t m12 = m122 > 1.e-20 ? sqrt(m122) : 0.; - histo->Fill(m12); - } - } -} - -static void BuildInvMass2(list<CbmStsTrack*>& stsTracks, TH1* /*histo*/) -{ - for (list<CbmStsTrack*>::iterator i = stsTracks.begin(); i != stsTracks.end(); ++i) { - CbmStsTrack* posTrack = *i; - //CbmStsTrack t1(*posTrack); - //extFitter.DoFit(&t1, 13); - //Double_t chi2Prim = extFitter.GetChiToVertex(&t1, fPrimVtx); - const FairTrackParam* t1param = posTrack->GetParamFirst(); - //extFitter.Extrapolate(&t1, fPrimVtx->GetZ(), &t1param); - CbmKFTrack muPlus(*posTrack); - Double_t t1Qp = t1param->GetQp(); - list<CbmStsTrack*>::iterator j = i; - ++j; - - for (; j != stsTracks.end(); ++j) { - CbmStsTrack* negTrack = *j; - //CbmStsTrack t2(*negTrack); - //extFitter.DoFit(&t2, 13); - //chi2Prim = extFitter.GetChiToVertex(&t2, fPrimVtx); - const FairTrackParam* t2param = negTrack->GetParamLast(); - //extFitter.Extrapolate(&t2, fPrimVtx->GetZ(), &t2param); - Double_t t2Qp = t2param->GetQp(); - - if (t1Qp * t2Qp >= 0) continue; - - CbmKFTrack muMinus(*negTrack); - vector<CbmKFTrackInterface*> kfData; - - if (t1Qp > 0) { - kfData.push_back(&muPlus); - kfData.push_back(&muMinus); - } - else { - kfData.push_back(&muMinus); - kfData.push_back(&muPlus); - } - } - } -} - -void LxTrackAnaTriplet::FinishTask() -{ - TFile* curFile = TFile::CurrentFile(); - - if (buildConnectStat) { - SaveHisto(muchStsBreakX, particleType.Data(), "muchStsBreakX.root"); - SaveHisto(muchStsBreakY, particleType.Data(), "muchStsBreakY.root"); - SaveHisto(muchStsBreakTx, particleType.Data(), "muchStsBreakTx.root"); - SaveHisto(muchStsBreakTy, particleType.Data(), "muchStsBreakTy.root"); - - SaveHisto(stsMuchBreakX, particleType.Data(), "stsMuchBreakX.root"); - SaveHisto(stsMuchBreakY, particleType.Data(), "stsMuchBreakY.root"); - - SaveHisto(signalChi2, particleType.Data(), "signalChi2.root"); - SaveHisto(bgrChi2, particleType.Data(), "bgrChi2.root"); - } // if (buildConnectStat) - - if (buildBgrInvMass) { - if (joinData) { - TFile fh("tracks_tree.root"); - superEventTracks = fh.Get<TTree>("SuperEventTracks"); - //LxSimpleTrack st(0, 0, 0, 0, 0, 0, 0, 0); - //superEventTracks->SetBranchAddress("tracks", &st.px); - CbmStsTrack* st = new CbmStsTrack; - superEventTracks->SetBranchAddress("tracks", &st); - list<CbmStsTrack*> stsTracks; - Int_t nEnt = superEventTracks->GetEntries(); - - for (Int_t i = 0; i < nEnt; ++i) { - superEventTracks->GetEntry(i); - //LxSimpleTrack* t = new LxSimpleTrack(0, 0, 0, 0, st.px, st.py, st.pz, st.e); - //t->charge = st.charge; - CbmStsTrack* t = new CbmStsTrack(*st); - stsTracks.push_back(t); - } - - BuildInvMass2(stsTracks, bgrInvMass); - SaveHisto(bgrInvMass, particleType.Data(), "bgrInvMass.root"); - - for (list<CbmStsTrack*>::iterator i = stsTracks.begin(); i != stsTracks.end(); ++i) - delete *i; - } - else { - TFile fh("tracks_tree.root", "RECREATE"); - superEventTracks->Write(); - fh.Close(); - delete superEventTracks; - } - } // if (buildBgrInvMass) - - if (buildSigInvMass) SaveHisto(sigInvMass, particleType.Data(), "sigInvMass.root"); - - if (buildNearestHitDist && useHitsInStat) { - char fileName[32]; - - for (Int_t i = 0; i < LXSTATIONS; ++i) { - sprintf(fileName, "%s.root", nearestHitDist[i]->GetName()); - SaveHisto(nearestHitDist[i], particleType.Data(), fileName); - sprintf(fileName, "%s.root", hitsDist[i]->GetName()); - SaveHisto(hitsDist[i], particleType.Data(), fileName); - } - } - - SaveHisto(muPlusStsTxDiff, particleType.Data(), "muPlusStsTxDiff.root"); - SaveHisto(muMinusStsTxDiff, particleType.Data(), "muMinusStsTxDiff.root"); - SaveHisto(muPlusStsXDiff, particleType.Data(), "muPlusStsXDiff.root"); - SaveHisto(muMinusStsXDiff, particleType.Data(), "muMinusStsXDiff.root"); - SaveHisto(muPlusVertexTxDiff, particleType.Data(), "muPlusVertexTxDiff.root"); - SaveHisto(muMinusVertexTxDiff, particleType.Data(), "muMinusVertexTxDiff.root"); - - SaveHisto(muPlusStsBeginTxDiff2D, particleType.Data(), "muPlusStsBeginTxDiff2D.root"); - SaveHisto(muMinusStsBeginTxDiff2D, particleType.Data(), "muMinusStsBeginTxDiff2D.root"); - - SaveHisto(deltaPhiPi, particleType.Data(), "deltaPhiPi.root"); - - SaveHisto(jPsiMuonsMomsHisto, particleType.Data(), "jPsiMuonsMomsHisto.root"); - - segmentsAnalyzer.Finish(); - - TFile::CurrentFile() = curFile; - FairTask::FinishTask(); -} - -// Our goal here is to investigate various properties of Monte Carlo tracks derivable from points of there intersections -// with detector stations. At the same time in MUCH we use not the Monte Carlo points but hits corresponding to them. -// -- This is done to make the statistical properties more realistic. -void LxTrackAnaTriplet::Exec(Option_t*) -{ - Clean(); - - Int_t nEnt = listMCTracks->GetEntriesFast(); - cout << "There are: " << nEnt << " of MC tracks" << endl; - - for (Int_t i = 0; i < nEnt; ++i) { - CbmMCTrack* mct = static_cast<CbmMCTrack*>(listMCTracks->At(i)); - LxSimpleTrack* t = new LxSimpleTrack(mct->GetPdgCode(), mct->GetMotherId(), mct->GetP(), mct->GetPt(), mct->GetPx(), - mct->GetPy(), mct->GetPz(), mct->GetEnergy()); - - if (t->motherId >= 0) t->parent = allTracks[t->motherId]; - - allTracks.push_back(t); - } - - nEnt = listStsPts->GetEntriesFast(); - cout << "There are: " << nEnt << " of STS MC points" << endl; - - for (Int_t i = 0; i < nEnt; ++i) { - CbmStsPoint* stsPt = static_cast<CbmStsPoint*>(listStsPts->At(i)); - Int_t mcTrackId = stsPt->GetTrackID(); - LxSimpleTrack* track = allTracks[mcTrackId]; - TVector3 xyzI, xyzO; - stsPt->Position(xyzI); - stsPt->PositionOut(xyzO); - TVector3 xyz = .5 * (xyzI + xyzO); - TVector3 pxyzI, pxyzO; - stsPt->Momentum(pxyzI); - stsPt->MomentumOut(pxyzO); - TVector3 pxyz = .5 * (pxyzI + pxyzO); - LxSimplePoint point(xyz.X(), xyz.Y(), xyz.Z(), pxyz.X() / pxyz.Z(), pxyz.Y() / pxyz.Z()); - Int_t stationNr = CbmStsAddress::GetElementId(stsPt->GetDetectorID(), kStsStation); - track->stsPoints[stationNr].push_back(point); - } - - nEnt = listMuchPts->GetEntriesFast(); - cout << "There are: " << nEnt << " of MUCH MC points" << endl; - - for (Int_t i = 0; i < nEnt; ++i) { - CbmMuchPoint* mcPoint = static_cast<CbmMuchPoint*>(listMuchPts->At(i)); - Int_t mcTrackId = mcPoint->GetTrackID(); - LxSimpleTrack* track = allTracks[mcTrackId]; - Int_t stationNr = CbmMuchGeoScheme::GetStationIndex(mcPoint->GetDetectorId()); - Int_t layerNr = CbmMuchGeoScheme::GetLayerIndex(mcPoint->GetDetectorId()); - TVector3 xyzI, xyzO; - mcPoint->Position(xyzI); - mcPoint->PositionOut(xyzO); - TVector3 xyz = .5 * (xyzI + xyzO); - TVector3 pxyzI, pxyzO; - mcPoint->Momentum(pxyzI); - mcPoint->MomentumOut(pxyzO); - TVector3 pxyz = .5 * (pxyzI + pxyzO); - LxSimplePoint point(xyz.X(), xyz.Y(), xyz.Z(), pxyz.X() / pxyz.Z(), pxyz.Y() / pxyz.Z()); - - if (useHitsInStat) - track->muchMCPts[stationNr][layerNr].push_back(point); - else - track->muchPoints[stationNr][layerNr].push_back(point); - } - - if (useHitsInStat) { - nEnt = listMuchPixelHits->GetEntriesFast(); - cout << "There are: " << nEnt << " of MUCH pixel hits" << endl; - - for (Int_t i = 0; i < nEnt; ++i) { - CbmMuchPixelHit* mh = static_cast<CbmMuchPixelHit*>(listMuchPixelHits->At(i)); - - Int_t stationNumber = CbmMuchGeoScheme::GetStationIndex(mh->GetAddress()); - Int_t layerNumber = CbmMuchGeoScheme::GetLayerIndex(mh->GetAddress()); - TVector3 pos, err; - mh->Position(pos); - mh->PositionError(err); - Double_t x = pos.X(); - Double_t y = pos.Y(); - Double_t z = pos.Z(); - - if (x != x || y != y || z != z) // Test for NaN - continue; - - set<LxSimpleTrack*> tracks; - - Int_t clusterId = mh->GetRefId(); - CbmMuchCluster* cluster = static_cast<CbmMuchCluster*>(listMuchClusters->At(clusterId)); - Int_t nDigis = cluster->GetNofDigis(); - - for (Int_t j = 0; j < nDigis; ++j) { - CbmMuchDigiMatch* digiMatch = static_cast<CbmMuchDigiMatch*>(listMuchPixelDigiMatches->At(cluster->GetDigi(j))); - Int_t nMCs = digiMatch->GetNofLinks(); - - for (Int_t k = 0; k < nMCs; ++k) { - const CbmLink& lnk = digiMatch->GetLink(k); - Int_t mcIndex = lnk.GetIndex(); - CbmMuchPoint* mcPoint = static_cast<CbmMuchPoint*>(listMuchPts->At(mcIndex)); - Int_t mcTrackId = mcPoint->GetTrackID(); - tracks.insert(allTracks[mcTrackId]); - //Int_t stationNr = CbmMuchGeoScheme::GetStationIndex(mcPoint->GetDetectorId()); - //Int_t layerNr = CbmMuchGeoScheme::GetLayerIndex(mcPoint->GetDetectorId()); - //LxSimplePoint point(x, y, z, 0, 0); - //track->muchPoints[stationNr][layerNr].push_back(point); - } - } // j - - for (set<LxSimpleTrack*>::iterator j = tracks.begin(); j != tracks.end(); ++j) { - LxSimplePoint point(x, y, z, 0, 0); - LxSimpleTrack* track = *j; - track->muchPoints[stationNumber][layerNumber].push_back(point); - } // j - } // i - - nEnt = listMuchClusters->GetEntriesFast(); - cout << "There are: " << nEnt << " of MUCH clusters" << endl; - - nEnt = listMuchPixelDigiMatches->GetEntriesFast(); - cout << "There are: " << nEnt << " of MUCH pixel digi matches" << endl; - } //if (useHitsInStat) - - if (averagePoints) AveragePoints(); - - if (buildConnectStat) BuildStatistics(); - - //Connect(false); - Connect(true); - - if (buildSigInvMass) BuildInvMass(posTracks, negTracks, sigInvMass); - - if (buildSegmentsStat) segmentsAnalyzer.BuildStatistics(); -} - -static inline void AveragePoints(list<LxSimplePoint>& points) -{ - if (points.empty() || points.size() == 1) return; - - Double_t x = 0; - Double_t y = 0; - Double_t z = 0; - Double_t tx = 0; - Double_t ty = 0; - - for (list<LxSimplePoint>::iterator i = points.begin(); i != points.end(); ++i) { - LxSimplePoint p = *i; - x += p.x; - y += p.y; - z += p.z; - tx += p.tx; - ty += p.ty; - } - - x /= points.size(); - y /= points.size(); - z /= points.size(); - tx /= points.size(); - ty /= points.size(); - LxSimplePoint averagedPoint(x, y, z, tx, ty); - points.clear(); - points.push_back(averagedPoint); -} - -// If hits are used in statistics average MC points in MUCH. -static inline void AveragePoints(LxSimpleTrack* track, bool useHitsInStat) -{ - for (Int_t i = 0; i < LXSTSSTATIONS; ++i) - AveragePoints(track->stsPoints[i]); - - if (useHitsInStat) { - for (Int_t i = 0; i < LXSTATIONS; ++i) { - for (Int_t j = 0; j < LXLAYERS; ++j) - AveragePoints(track->muchMCPts[i][j]); - } - } - else { - for (Int_t i = 0; i < LXSTATIONS; ++i) { - for (Int_t j = 0; j < LXLAYERS; ++j) - AveragePoints(track->muchPoints[i][j]); - } - } -} - -void LxTrackAnaTriplet::AveragePoints() -{ - for (vector<LxSimpleTrack*>::iterator i = allTracks.begin(); i != allTracks.end(); ++i) - ::AveragePoints(*i, useHitsInStat); -} - -static UInt_t maxTracks = 0; -static UInt_t maxMuchPts1 = 0; -static UInt_t maxMuchPts0 = 0; -static UInt_t maxStsPts7 = 0; -static UInt_t maxStsPts6 = 0; - -static inline void BuildStatistics(LxSimpleTrack* track) -{ - if (track->muchPoints[1][LXMIDDLE].size() > maxMuchPts1) maxMuchPts1 = track->muchPoints[1][LXMIDDLE].size(); - - if (track->muchPoints[0][LXMIDDLE].size() > maxMuchPts0) maxMuchPts0 = track->muchPoints[0][LXMIDDLE].size(); - - if (track->stsPoints[7].size() > maxStsPts7) maxStsPts7 = track->stsPoints[7].size(); - - if (track->stsPoints[6].size() > maxStsPts6) maxStsPts6 = track->stsPoints[6].size(); - - jPsiMuonsMomsHisto->Fill(track->p); - - for (list<LxSimplePoint>::iterator j = track->muchPoints[1][LXMIDDLE].begin(); - j != track->muchPoints[1][LXMIDDLE].end(); ++j) { - LxSimplePoint muchPt1 = *j; - - for (list<LxSimplePoint>::iterator k = track->muchPoints[0][LXMIDDLE].begin(); - k != track->muchPoints[0][LXMIDDLE].end(); ++k) { - LxSimplePoint muchPt0 = *k; - Double_t diffZMuch = muchPt0.z - muchPt1.z; - Double_t txMuch = (muchPt0.x - muchPt1.x) / diffZMuch; - Double_t tyMuch = (muchPt0.y - muchPt1.y) / diffZMuch; - - if (-13 == track->pdgCode) { - Double_t txDiff = txMuch - muchPt0.x / muchPt0.z; - muPlusVertexTxDiff->Fill(txDiff); - - if (!track->stsPoints[0].empty() && !track->stsPoints[1].empty()) { - LxSimplePoint p0 = track->stsPoints[0].front(); - LxSimplePoint p1 = track->stsPoints[1].front(); - muPlusStsBeginTxDiff2D->Fill(track->p, txMuch - (p1.x - p0.x) / (p1.z - p0.z)); - muMinusStsBeginTxDiff2D->Fill(track->p, (p1.x - p0.x) / (p1.z - p0.z) - txMuch); - deltaPhiPi->Fill(track->p * (txMuch - (p1.x - p0.x) / (p1.z - p0.z))); - } - } - else if (13 == track->pdgCode) { - Double_t txDiff = txMuch - muchPt0.x / muchPt0.z; - muMinusVertexTxDiff->Fill(txDiff); - - if (!track->stsPoints[0].empty() && !track->stsPoints[1].empty()) { - LxSimplePoint p0 = track->stsPoints[0].front(); - LxSimplePoint p1 = track->stsPoints[1].front(); - muMinusStsBeginTxDiff2D->Fill(track->p, txMuch - (p1.x - p0.x) / (p1.z - p0.z)); - muPlusStsBeginTxDiff2D->Fill(track->p, (p1.x - p0.x) / (p1.z - p0.z) - txMuch); - deltaPhiPi->Fill(track->p * ((p1.x - p0.x) / (p1.z - p0.z) - txMuch)); - } - } - - for (list<LxSimplePoint>::iterator l = track->stsPoints[7].begin(); l != track->stsPoints[7].end(); ++l) { - LxSimplePoint stsPt7 = *l; - Double_t diffZ = stsPt7.z - muchPt0.z; - Double_t extX = muchPt0.x + txMuch * diffZ; - Double_t extY = muchPt0.y + tyMuch * diffZ; - Double_t dx = stsPt7.x - extX; - Double_t dy = stsPt7.y - extY; - muchStsBreakX->Fill(dx); - muchStsBreakY->Fill(dy); - - if (-13 == track->pdgCode) { - Double_t extXmu = muchPt0.x + (txMuch - 0.00671) * diffZ; - muPlusStsXDiff->Fill(stsPt7.x - extXmu); - } - else if (13 == track->pdgCode) { - Double_t extXmu = muchPt0.x + (txMuch + 0.00691) * diffZ; - muMinusStsXDiff->Fill(stsPt7.x - extXmu); - } - - for (list<LxSimplePoint>::iterator m = track->stsPoints[6].begin(); m != track->stsPoints[6].end(); ++m) { - LxSimplePoint stsPt6 = *m; - Double_t diffZSts = stsPt6.z - stsPt7.z; - Double_t txSts = (stsPt6.x - stsPt7.x) / diffZSts; - Double_t tySts = (stsPt6.y - stsPt7.y) / diffZSts; - //muchStsBreakX->Fill(dx); - //muchStsBreakY->Fill(dy); - Double_t dtx = txSts - txMuch; - Double_t dty = tySts - tyMuch; - muchStsBreakTx->Fill(dtx); - muchStsBreakTy->Fill(dty); - - if (-13 == track->pdgCode) - muPlusStsTxDiff->Fill(dtx); - else if (13 == track->pdgCode) - muMinusStsTxDiff->Fill(dtx); - - Double_t chi2 = dx * dx / xRms2 + dy * dy / yRms2 + dtx * dtx / txRms2 + dty * dty / tyRms2; - - if (0 > track->motherId && (13 == track->pdgCode || -13 == track->pdgCode)) // JPsi - signalChi2->Fill(chi2); - else - bgrChi2->Fill(chi2); - - diffZ = muchPt0.z - stsPt7.z; - extX = stsPt7.x + txSts * diffZ; - extY = stsPt7.y + tySts * diffZ; - dx = muchPt0.x - extX; - dy = muchPt0.y - extY; - stsMuchBreakX->Fill(dx); - stsMuchBreakY->Fill(dy); - } - } - } - } -} - -static inline void BuildNearestHitStat(LxSimpleTrack* track, bool cropHits) -{ - static Double_t maxDist = 0; - static Double_t mcX = 0; - static Double_t hitX = 0; - static Double_t mcY = 0; - static Double_t hitY = 0; - - static Double_t maxMinDist = 0; - static Double_t mcMinX = 0; - static Double_t hitMinX = 0; - static Double_t mcMinY = 0; - static Double_t hitMinY = 0; - static Int_t nMinHits = 0; - - for (Int_t i = 0; i < LXSTATIONS; ++i) { - if (track->muchMCPts[i][LXMIDDLE].empty() || track->muchPoints[i][LXMIDDLE].empty()) continue; - - LxSimplePoint mcPoint = track->muchMCPts[i][LXMIDDLE] - .front(); // We assume the MC points were averaged and there can be at most one point. - Double_t minDist = -1; - Double_t mcMinX0 = 0; - Double_t hitMinX0 = 0; - Double_t mcMinY0 = 0; - Double_t hitMinY0 = 0; - Double_t hitMinZ0 = 0; - Int_t nMinHits0 = 0; - - for (list<LxSimplePoint>::iterator j = track->muchPoints[i][LXMIDDLE].begin(); - j != track->muchPoints[i][LXMIDDLE].end(); ++j) { - LxSimplePoint hitPoint = *j; - Double_t dx = hitPoint.x - mcPoint.x; - Double_t dy = hitPoint.y - mcPoint.y; - Double_t dist = sqrt(dx * dx + dy * dy); - - if (track->motherId < 0 && (13 == track->pdgCode || -13 == track->pdgCode)) hitsDist[i]->Fill(dist); - - if (minDist > dist || minDist < 0) { - minDist = dist; - - mcMinX0 = mcPoint.x; - hitMinX0 = hitPoint.x; - mcMinY0 = mcPoint.y; - hitMinY0 = hitPoint.y; - hitMinZ0 = hitPoint.z; - nMinHits0 = track->muchPoints[i][LXMIDDLE].size(); - } - - if (maxDist < dist) { - maxDist = dist; - mcX = mcPoint.x; - hitX = hitPoint.x; - mcY = mcPoint.y; - hitY = hitPoint.y; - } - } // for (list<LxSimplePoint>::iterator j = track->muchPoints[i].begin(); j != track->muchPoints[i].end(); ++j) - - if (minDist >= 0) { - if (track->motherId < 0 && (13 == track->pdgCode || -13 == track->pdgCode)) nearestHitDist[i]->Fill(minDist); - - if (cropHits) { - track->muchPoints[i][LXMIDDLE].clear(); - LxSimplePoint point(hitMinX0, hitMinY0, hitMinZ0, 0, 0); - track->muchPoints[i][LXMIDDLE].push_back(point); - } - - if (maxMinDist < minDist) { - maxMinDist = minDist; - mcMinX = mcMinX0; - hitMinX = hitMinX0; - mcMinY = mcMinY0; - hitMinY = hitMinY0; - nMinHits = nMinHits0; - } - } - } - - cout << "BuildNearestHitStat: maxDist=" << maxDist << " MC x=" << mcX << " Hit x=" << hitX << " MC y=" << mcY - << " Hit y=" << hitY << endl; - cout << "BuildNearestHitStat: maxMinDist=" << maxMinDist << " MC x=" << mcMinX << " Hit x=" << hitMinX - << " MC y=" << mcMinY << " Hit y=" << hitMinY << " n hits=" << nMinHits << endl; -} - -void LxTrackAnaTriplet::BuildStatistics() -{ - if (allTracks.size() > maxTracks) maxTracks = allTracks.size(); - - for (vector<LxSimpleTrack*>::iterator i = allTracks.begin(); i != allTracks.end(); ++i) { - LxSimpleTrack* track = *i; - - if (track->muchPoints[0][LXMIDDLE].empty() || track->muchPoints[1][LXMIDDLE].empty() - || track->muchPoints[5][LXMIDDLE].empty()) - continue; - - if (buildNearestHitDist && useHitsInStat) - ::BuildNearestHitStat(track, - cropHits); // Hits can be cropped (only the nearest to MC hit is left) here! - - if (track->motherId > -1 || (13 != track->pdgCode && -13 != track->pdgCode)) continue; - - ::BuildStatistics(track); - } - - cout << "Statistics is built maxTracks=" << maxTracks << " maxMuchPts1=" << maxMuchPts1 - << " maxMuchPts0=" << maxMuchPts0 << " maxStsPts7=" << maxStsPts7 << " maxStsPts6=" << maxStsPts6 << endl; -} - -void LxTrackAnaTriplet::Connect(bool useCuts) -{ - static Int_t jpsiTrackCount = 0; - static Int_t jpsiTrackCountCutted = 0; - static Int_t jpsiMatchedCount = 0; - static Int_t jpsiMatchedCountCutted = 0; - - static Int_t otherTrackCount = 0; - static Int_t otherTrackCountCutted = 0; - static Int_t otherMatchedCount = 0; - static Int_t otherMatchedCountCutted = 0; - - for (vector<LxSimpleTrack*>::iterator i = allTracks.begin(); i != allTracks.end(); ++i) { - LxSimpleTrack* muchTrack = *i; - - if (muchTrack->muchPoints[0][LXMIDDLE].empty() || muchTrack->muchPoints[1][LXMIDDLE].empty() - || muchTrack->muchPoints[5][LXMIDDLE].empty()) - continue; - - for (list<LxSimplePoint>::iterator j = muchTrack->muchPoints[1][LXMIDDLE].begin(); - j != muchTrack->muchPoints[1][LXMIDDLE].end(); ++j) { - LxSimplePoint muchPt1 = *j; - - for (list<LxSimplePoint>::iterator k = muchTrack->muchPoints[0][LXMIDDLE].begin(); - k != muchTrack->muchPoints[0][LXMIDDLE].end(); ++k) { - LxSimplePoint muchPt0 = *k; - Double_t diffZMuch = muchPt0.z - muchPt1.z; - Double_t txMuch = (muchPt0.x - muchPt1.x) / diffZMuch; - // Double_t txMuchVertex = muchPt0.x / muchPt0.z; - Double_t tyMuch = (muchPt0.y - muchPt1.y) / diffZMuch; - Connect(muchTrack, muchPt0, txMuch, tyMuch, useCuts); - } // for (list<LxSimplePoint>::iterator k = muchTrack->muchPoints[0].begin(); k != muchTrack->muchPoints[0].end(); ++k) - } // for (list<LxSimplePoint>::iterator j = muchTrack->muchPoints[1].begin(); j != muchTrack->muchPoints[1].end(); ++j) - - if (0 > muchTrack->motherId && (13 == muchTrack->pdgCode || -13 == muchTrack->pdgCode)) // JPsi - { - if (useCuts) { - ++jpsiTrackCountCutted; - - if (muchTrack == muchTrack->linkedStsTrack) ++jpsiMatchedCountCutted; - - if (buildSigInvMass && 0 != muchTrack->linkedStsTrack) { - if (muchTrack->linkedStsTrack->charge > 0) - posTracks.push_back(muchTrack->linkedStsTrack); - else if (muchTrack->linkedStsTrack->charge < 0) - negTracks.push_back(muchTrack->linkedStsTrack); - } - } - else { - ++jpsiTrackCount; - - if (muchTrack == muchTrack->linkedStsTrack) ++jpsiMatchedCount; - } - } - else // Background track handled here. - { - if (useCuts) { - ++otherTrackCountCutted; - - if (muchTrack == muchTrack->linkedStsTrack || 0 == muchTrack->linkedStsTrack) ++otherMatchedCountCutted; - - if (buildBgrInvMass && !joinData && 0 != muchTrack->linkedStsTrack) { - superEventBrachTrack.px = muchTrack->linkedStsTrack->px; - superEventBrachTrack.py = muchTrack->linkedStsTrack->py; - superEventBrachTrack.pz = muchTrack->linkedStsTrack->pz; - superEventBrachTrack.e = muchTrack->linkedStsTrack->e; - superEventBrachTrack.charge = muchTrack->linkedStsTrack->charge; - superEventTracks->Fill(); - } - } - else { - ++otherTrackCount; - - if (muchTrack == muchTrack->linkedStsTrack || 0 == muchTrack->linkedStsTrack) ++otherMatchedCount; - } - } - } // for (vector<LxSimpleTrack*>::iterator i = allTracks.begin(); i != allTracks.end(); ++i) - - if (useCuts) { - Double_t efficiency = jpsiMatchedCountCutted * 100; - efficiency /= jpsiTrackCountCutted; - cout << "J/psi (with cuts) connection efficiency = " << efficiency << "% ( " << jpsiMatchedCountCutted << " / " - << jpsiTrackCountCutted << " )" << endl; - efficiency = otherMatchedCountCutted * 100; - efficiency /= otherTrackCountCutted; - cout << "Others (with cuts) connection efficiency = " << efficiency << "% ( " << otherMatchedCountCutted << " / " - << otherTrackCountCutted << " )" << endl; - } - else { - Double_t efficiency = jpsiMatchedCount * 100; - efficiency /= jpsiTrackCount; - cout << "J/psi (without cuts) connection efficiency = " << efficiency << "% ( " << jpsiMatchedCount << " / " - << jpsiTrackCount << " )" << endl; - efficiency = otherMatchedCount * 100; - efficiency /= otherTrackCount; - cout << "Others (without cuts) connection efficiency = " << efficiency << "% ( " << otherMatchedCount << " / " - << otherTrackCount << " )" << endl; - } -} - -void LxTrackAnaTriplet::Connect(LxSimpleTrack* muchTrack, LxSimplePoint muchPt0, Double_t txMuch, Double_t tyMuch, - bool useCuts) -{ - for (vector<LxSimpleTrack*>::iterator l = allTracks.begin(); l != allTracks.end(); ++l) { - LxSimpleTrack* stsTrack = *l; - - if (stsTrack->p < 3.0 || stsTrack->pt < 1.0) continue; - - Int_t m0 = 0; - Int_t n0 = -1; - - for (; m0 < LXSTSSTATIONS - 1; ++m0) { - if (!stsTrack->stsPoints[m0].empty()) { - n0 = m0 + 1; - - for (; n0 <= m0 + 2 && n0 < LXSTSSTATIONS; ++n0) { - if (!stsTrack->stsPoints[n0].empty()) break; - } - } - - if (n0 <= m0 + 2) break; - } - - Int_t m = LXSTSSTATIONS - 1; - Int_t n = -1; - - for (; m > 0; --m) { - if (!stsTrack->stsPoints[m].empty()) { - n = m - 1; - - for (; n >= m - 2 && n >= 0; --n) { - if (!stsTrack->stsPoints[n].empty()) break; - } - } - - if (n >= m - 2) break; - } - - if (n >= 0 && m > n && n >= m - 2) { - if (m0 >= LXSTSSTATIONS - 1 || n0 >= LXSTSSTATIONS || m0 >= n0) { - m0 = n; - n0 = m; - } - - LxSimplePoint stsPtM0 = stsTrack->stsPoints[m0].front(); - LxSimplePoint stsPtN0 = stsTrack->stsPoints[n0].front(); - Double_t txSts0 = (stsPtN0.x - stsPtM0.x) / (stsPtN0.z - stsPtM0.z); - - for (list<LxSimplePoint>::iterator o = stsTrack->stsPoints[m].begin(); o != stsTrack->stsPoints[m].end(); ++o) { - LxSimplePoint stsPtM = *o; - Double_t deltaZ = stsPtM.z - muchPt0.z; - Double_t extX = muchPt0.x + txMuch * deltaZ; - Double_t extY = muchPt0.y + tyMuch * deltaZ; - Double_t dx = stsPtM.x - extX; - Double_t dy = stsPtM.y - extY; - - if (dx < 0) dx = -dx; - - if (dy < 0) dy = -dy; - - if (useCuts && (dx > xRms * cutCoeff || dy > yRms * cutCoeff)) continue; - - for (list<LxSimplePoint>::iterator p = stsTrack->stsPoints[n].begin(); p != stsTrack->stsPoints[n].end(); ++p) { - LxSimplePoint stsPtN = *p; - Double_t diffZSts = stsPtN.z - stsPtM.z; - Double_t txSts = (stsPtN.x - stsPtM.x) / diffZSts; - Double_t tySts = (stsPtN.y - stsPtM.y) / diffZSts; - Double_t dtx = txSts - txMuch; - Double_t dty = tySts - tyMuch; - - Double_t stsCharge = TDatabasePDG::Instance()->GetParticle(stsTrack->pdgCode)->Charge(); - Double_t muchCharge = txMuch - txSts0; - bool chargesSignsTheSame = (stsCharge > 0 && muchCharge > 0) || (stsCharge < 0 && muchCharge < 0); - - if (dtx < 0) dtx = -dtx; - - if (dty < 0) dty = -dty; - - if (useCuts - && ((useChargeSignInCuts && (!chargesSignsTheSame || !momFitTxBreak(stsTrack->p, muchCharge))) - || dtx > txRms * cutCoeff || dty > tyRms * cutCoeff)) - continue; - - Double_t chi2 = dx * dx / xRms2 + dy * dy / yRms2 + dtx * dtx / txRms2 + dty * dty / tyRms2; - stsTrack->charge = stsCharge; - - if (0 == stsTrack->linkedMuchTrack.first || chi2 < stsTrack->linkedMuchTrack.second) { - list<pair<LxSimpleTrack*, Double_t>>::iterator r = muchTrack->linkedStsTracks.begin(); - - for (; r != muchTrack->linkedStsTracks.end() && r->second <= chi2; ++r) - ; - - pair<LxSimpleTrack*, Double_t> trackDesc(stsTrack, chi2); - muchTrack->linkedStsTracks.insert(r, trackDesc); - } - } - } - } - } // for (vector<LxSimpleTrack*>::iterator l = allTracks.begin(); l != allTracks.end(); ++l) - - if (!muchTrack->linkedStsTracks.empty()) { - pair<LxSimpleTrack*, Double_t> trackDesc = muchTrack->linkedStsTracks.front(); - muchTrack->linkedStsTracks.pop_front(); - LxSimpleTrack* anotherMuchTrack = trackDesc.first->linkedMuchTrack.first; - trackDesc.first->linkedMuchTrack.first = muchTrack; - trackDesc.first->linkedMuchTrack.second = trackDesc.second; - muchTrack->linkedStsTrack = trackDesc.first; - - if (0 != anotherMuchTrack) anotherMuchTrack->RebindMuchTrack(); - } -} diff --git a/reco/tracking/lxTriplet/LxTrackAna.h b/reco/tracking/lxTriplet/LxTrackAna.h deleted file mode 100644 index 80f21ac430fb7cea1b49004b1366bc96dbf0b65d..0000000000000000000000000000000000000000 --- a/reco/tracking/lxTriplet/LxTrackAna.h +++ /dev/null @@ -1,143 +0,0 @@ -/* Copyright (C) 2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifndef LXTRACKANA_INCLUDED -#define LXTRACKANA_INCLUDED - -#pragma GCC diagnostic ignored "-Weffc++" - -#include "CbmMuchPixelHit.h" - -#include "FairTask.h" - -#include "TClonesArray.h" - -#include <list> -#include <vector> - -#include "LxSettings.h" -#include "LxTrackAnaSegments.h" - -struct LxSimplePoint { - Double_t x; - Double_t y; - Double_t z; - Double_t tx; - Double_t ty; - LxSimplePoint() : x(0), y(0), z(0), tx(0), ty(0) {} - LxSimplePoint(Double_t X, Double_t Y, Double_t Z, Double_t Tx, Double_t Ty) : x(X), y(Y), z(Z), tx(Tx), ty(Ty) {} -}; - -struct LxSimpleTrack { - Int_t pdgCode; - Int_t motherId; - Double_t p; - Double_t pt; - Double_t px; - Double_t py; - Double_t pz; - Double_t e; - Double_t charge; - LxSimpleTrack(Int_t pdgc, Int_t mid, Double_t P, Double_t Pt, Double_t Px, Double_t Py, Double_t Pz, Double_t E) - : pdgCode(pdgc) - , motherId(mid) - , p(P) - , pt(Pt) - , px(Px) - , py(Py) - , pz(Pz) - , e(E) - , charge(0) - , linkedMuchTrack(0, 0) - , linkedStsTrack(0) - , parent(0) - { - } - std::list<LxSimplePoint> stsPoints[LXSTSSTATIONS]; - std::list<LxSimplePoint> muchPoints[LXSTATIONS][LXLAYERS]; - std::list<LxSimplePoint> - muchMCPts[LXSTATIONS] - [LXLAYERS]; // These array is used for storing MUCH MC points when the 'main' array contains hits. - std::pair<LxSimpleTrack*, Double_t> linkedMuchTrack; - std::list<std::pair<LxSimpleTrack*, Double_t>> - linkedStsTracks; // The front() contains STS track with the minimal chi2. - LxSimpleTrack* linkedStsTrack; - LxSimpleTrack* parent; - void RebindMuchTrack(); -}; - -class LxTrackAnaTriplet : public FairTask { -public: - LxTrackAnaTriplet(); - ~LxTrackAnaTriplet(); - InitStatus Init(); // Inherited virtual. - void Exec(Option_t* opt); // Inherited virtual. - void FinishTask(); // Inherited virtual. - bool GetUseHitsInStat() const { return useHitsInStat; } - void SetUseHitsInStat(bool v) { useHitsInStat = v; } - bool GetAveragePoints() const { return averagePoints; } - void SetAveragePoints(bool v) { averagePoints = v; } - bool GetDontTouchNonPrimary() const { return dontTouchNonPrimary; } - void SetDontTouchNonPrimary(bool v) { dontTouchNonPrimary = v; } - bool GetUseChargeSignInCuts() const { return useChargeSignInCuts; } - void SetUseChargeSignInCuts(bool v) { useChargeSignInCuts = v; } - bool GetBuildConnectStat() const { return buildConnectStat; } - void SetBuildConnectStat(bool v) { buildConnectStat = v; } - bool GetBuildBgrInvMass() const { return buildBgrInvMass; } - void SetBuildBgrInvMass(bool v) { buildBgrInvMass = v; } - bool GetBuildSigInvMass() const { return buildSigInvMass; } - void SetBuildSigInvMass(bool v) { buildSigInvMass = v; } - bool GetJoinData() const { return joinData; } - void SetJoinData(bool v) { joinData = v; } - bool GetBuildNearestHitDist() const { return buildNearestHitDist; } - void SetBuildNearestHitDist(bool v) { buildNearestHitDist = v; } - bool GetCropHits() const { return cropHits; } - void SetCropHits(bool v) { cropHits = v; } - bool GetBuildSegmentsStat() const { return buildSegmentsStat; } - void SetBuildSegmentsStat(bool v) { buildSegmentsStat = v; } - void SetParticleType(TString v) - { - particleType = v; - segmentsAnalyzer.SetParticleType(v); - } - void SetUseBgr(bool v) { segmentsAnalyzer.SetUseBgr(v); } - -private: - void Clean(); - void AveragePoints(); - void BuildStatistics(); - void Connect(bool useCuts); - void Connect(LxSimpleTrack* muchTrack, LxSimplePoint muchPt0, Double_t txMuch, Double_t tyMuch, bool useCuts); - - TClonesArray* listMCTracks; - TClonesArray* listStsPts; - TClonesArray* listMuchPts; - TClonesArray* listMuchPixelHits; - TClonesArray* listMuchClusters; - TClonesArray* listMuchPixelDigiMatches; - std::vector<LxSimpleTrack*> allTracks; - std::list<LxSimpleTrack*> posTracks; - std::list<LxSimpleTrack*> negTracks; - TTree* superEventTracks; - LxSimpleTrack superEventBrachTrack; - bool useHitsInStat; - bool averagePoints; - bool dontTouchNonPrimary; - bool useChargeSignInCuts; - bool buildConnectStat; - bool buildBgrInvMass; - bool buildSigInvMass; - bool joinData; - bool buildNearestHitDist; - bool cropHits; - bool buildSegmentsStat; - TString particleType; - LxTrackAnaSegments segmentsAnalyzer; - - friend class LxTrackAnaSegments; - - ClassDef(LxTrackAnaTriplet, 1); -}; - -#endif //LXTRACKANA_INCLUDED diff --git a/reco/tracking/lxTriplet/LxTrackAnaSegments.cxx b/reco/tracking/lxTriplet/LxTrackAnaSegments.cxx deleted file mode 100644 index bc1ed46592bce407cbbd080fb99b8c83c1da0907..0000000000000000000000000000000000000000 --- a/reco/tracking/lxTriplet/LxTrackAnaSegments.cxx +++ /dev/null @@ -1,725 +0,0 @@ -/* Copyright (C) 2016-2021 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#include "LxTrackAnaSegments.h" - -#include "TH1.h" -#include "TH2.h" - -#include <iostream> - -#include <cmath> -#include <dirent.h> -#include <sys/stat.h> -#include <sys/types.h> - -#include "LxTrackAna.h" - -bool saveHistos = true; - -using namespace std; - -static TH1F* muchInStationXDispLeft[LXSTATIONS]; -static TH1F* muchInStationXDispRight[LXSTATIONS]; -static TH1F* muchInStationYDispLeft[LXSTATIONS]; -static TH1F* muchInStationYDispRight[LXSTATIONS]; - -static TH1F* muchInStationXDispRL[LXSTATIONS]; -static TH1F* muchInStationYDispRL[LXSTATIONS]; - -static TH1F* muchInStationTxBreak[LXSTATIONS]; -static TH1F* muchInStationTyBreak[LXSTATIONS]; - -static TH1F* muchOutStationTxBreakLeft[LXSTATIONS - 1]; -static TH1F* muchOutStationTxBreakRight[LXSTATIONS - 1]; -static TH1F* muchOutStationTyBreakLeft[LXSTATIONS - 1]; -static TH1F* muchOutStationTyBreakRight[LXSTATIONS - 1]; - -static TH1F* muchTripletTxBreak[LXSTATIONS - 1]; -static TH1F* muchTripletTyBreak[LXSTATIONS - 1]; - -static TH1F* muchOutStationXDispByTriplet[LXSTATIONS - 1]; -static TH1F* muchOutStationYDispByTriplet[LXSTATIONS - 1]; - -static TH1F* muchOutStationXDispByVertex[LXSTATIONS - 1]; -static TH1F* muchOutStationYDispByVertex[LXSTATIONS - 1]; - -static TH1F* muchLongSegmentTxHisto[LXSTATIONS - 1]; -static TH1F* muchLongSegmentTyHisto[LXSTATIONS - 1]; - -static TH1F* muchSegmentTxBreakHisto[LXSTATIONS - 2]; -static TH1F* muchSegmentTyBreakHisto[LXSTATIONS - 2]; - -static TH1F* muchStationTxDispHisto[LXSTATIONS - 1]; -static TH1F* muchStationTyDispHisto[LXSTATIONS - 1]; - -static TH2F* muchXTxCovHisto[LXSTATIONS - 1]; -static TH2F* muchYTyCovHisto[LXSTATIONS - 1]; - -static TH1F* muchClusterXDispHisto[LXSTATIONS - 1]; -static TH1F* muchClusterYDispHisto[LXSTATIONS - 1]; -static TH1F* muchClusterTxDispHisto[LXSTATIONS - 1]; -static TH1F* muchClusterTyDispHisto[LXSTATIONS - 1]; - -static bool GetHistoRMS(const char* histoNameBase, Int_t histoNumber, Double_t& retVal) -{ - char name[256]; - char dir_name[256]; - sprintf(dir_name, "configuration.%s", "omega"); - bool result = false; - sprintf(name, "%s/%s_%d.root", dir_name, histoNameBase, histoNumber); - TFile* curFile = TFile::CurrentFile(); - - /// Save old global file and folder pointer to avoid messing with FairRoot - TFile* oldFile = gFile; - TDirectory* oldDir = gDirectory; - - TFile* f = new TFile(name); - - if (!f->IsZombie()) { - sprintf(name, "%s_%d", histoNameBase, histoNumber); - TH1F* h = f->Get<TH1F>(name); - retVal = h->GetRMS(); - result = true; - } - - delete f; - TFile::CurrentFile() = curFile; - - /// Restore old global file and folder pointer to avoid messing with FairRoot - gFile = oldFile; - gDirectory = oldDir; - - return result; -} - -LxTrackAnaSegments::LxTrackAnaSegments(LxTrackAnaTriplet& o) : owner(o), stationsInAlgo(LXSTATIONS), useBgr(false) {} - -static TString particleType("jpsi"); - -void LxTrackAnaSegments::SetParticleType(TString v) -{ - particleType = v; - - if (v == "omega") stationsInAlgo = 5; -} - -void LxTrackAnaSegments::Init() -{ - char name[64]; - char title[256]; - - for (Int_t i = 0; i < LXSTATIONS; ++i) { - sprintf(name, "muchInStationXDispLeft_%d", i); - sprintf(title, "X dispersion from central to left layer inside station: %d", i); - muchInStationXDispLeft[i] = new TH1F(name, title, 100, -3.0, 3.0); - muchInStationXDispLeft[i]->StatOverflows(); - - sprintf(name, "muchInStationXDispRight_%d", i); - sprintf(title, "X dispersion from central to right layer inside station: %d", i); - muchInStationXDispRight[i] = new TH1F(name, title, 100, -3.0, 3.0); - muchInStationXDispRight[i]->StatOverflows(); - - sprintf(name, "muchInStationYDispLeft_%d", i); - sprintf(title, "Y dispersion from central to left layer inside station: %d", i); - muchInStationYDispLeft[i] = new TH1F(name, title, 100, -3.0, 3.0); - muchInStationYDispLeft[i]->StatOverflows(); - - sprintf(name, "muchInStationYDispRight_%d", i); - sprintf(title, "Y dispersion from central to right layer inside station: %d", i); - muchInStationYDispRight[i] = new TH1F(name, title, 100, -3.0, 3.0); - muchInStationYDispRight[i]->StatOverflows(); - - sprintf(name, "muchInStationXDispRL_%d", i); - sprintf(title, "X dispersion on left layer predicted by right station: %d", i); - muchInStationXDispRL[i] = new TH1F(name, title, 100, -0.1, 0.1); - muchInStationXDispRL[i]->StatOverflows(); - - sprintf(name, "muchInStationYDispRL_%d", i); - sprintf(title, "Y dispersion on left layer predicted by right station: %d", i); - muchInStationYDispRL[i] = new TH1F(name, title, 100, -0.1, 0.1); - muchInStationYDispRL[i]->StatOverflows(); - - sprintf(name, "muchInStationTxBreak_%d", i); - sprintf(title, "Tx break inside station: %d", i); - muchInStationTxBreak[i] = new TH1F(name, title, 100, -0.02, 0.02); - muchInStationTxBreak[i]->StatOverflows(); - - sprintf(name, "muchInStationTyBreak_%d", i); - sprintf(title, "Ty break inside station: %d", i); - muchInStationTyBreak[i] = new TH1F(name, title, 100, -0.02, 0.02); - muchInStationTyBreak[i]->StatOverflows(); - - if (i > 0) { - sprintf(name, "muchLongSegmentTxHisto_%d", i); - sprintf(title, "Tx tangents distribution for segments between stations: %d and %d", i - 1, i); - muchLongSegmentTxHisto[i - 1] = new TH1F(name, title, 100, -.15, .15); - muchLongSegmentTxHisto[i - 1]->StatOverflows(); - - sprintf(name, "muchLongSegmentTyHisto_%d", i); - sprintf(title, "Ty tangents distribution for segments between stations: %d and %d", i - 1, i); - muchLongSegmentTyHisto[i - 1] = new TH1F(name, title, 100, -.15, .15); - muchLongSegmentTyHisto[i - 1]->StatOverflows(); - - sprintf(name, "muchClusterXDispHisto_%d", i); - sprintf(title, - "X coordinate dispersion for cluster segments between stations: " - "%d and %d", - i - 1, i); - muchClusterXDispHisto[i - 1] = new TH1F(name, title, 100, .0, 3.0); - muchClusterXDispHisto[i - 1]->StatOverflows(); - - sprintf(name, "muchClusterYDispHisto_%d", i); - sprintf(title, - "Y coordinate dispersion for cluster segments between stations: " - "%d and %d", - i - 1, i); - muchClusterYDispHisto[i - 1] = new TH1F(name, title, 100, .0, 3.0); - muchClusterYDispHisto[i - 1]->StatOverflows(); - - sprintf(name, "muchClusterTxDispHisto_%d", i); - sprintf(title, - "Tx tangent dispersion for cluster segments between stations: %d " - "and %d", - i - 1, i); - muchClusterTxDispHisto[i - 1] = new TH1F(name, title, 100, .0, .05); - muchClusterTxDispHisto[i - 1]->StatOverflows(); - - sprintf(name, "muchClusterTyDispHisto_%d", i); - sprintf(title, - "Ty tangent dispersion for cluster segments between stations: %d " - "and %d", - i - 1, i); - muchClusterTyDispHisto[i - 1] = new TH1F(name, title, 100, .0, .05); - muchClusterTyDispHisto[i - 1]->StatOverflows(); - - sprintf(name, "muchOutStationTxBreakLeft_%d", i); - sprintf(title, - "Tx break between right segment of station and left tip of the " - "interstation segment: %d", - i); - muchOutStationTxBreakLeft[i - 1] = new TH1F(name, title, 100, -0.15, 0.15); - muchOutStationTxBreakLeft[i - 1]->StatOverflows(); - - sprintf(name, "muchOutStationTxBreakRight_%d", i); - sprintf(title, - "Tx break between left segment of station and right tip of the " - "interstation segment: %d", - i); - muchOutStationTxBreakRight[i - 1] = new TH1F(name, title, 100, -0.15, 0.15); - muchOutStationTxBreakRight[i - 1]->StatOverflows(); - - sprintf(name, "muchOutStationTyBreakLeft_%d", i); - sprintf(title, - "Ty break between right segment of station and left tip of the " - "interstation segment: %d", - i); - muchOutStationTyBreakLeft[i - 1] = new TH1F(name, title, 100, -0.15, 0.15); - muchOutStationTyBreakLeft[i - 1]->StatOverflows(); - - sprintf(name, "muchOutStationTyBreakRight_%d", i); - sprintf(title, - "Ty break between left segment of station and right tip of the " - "interstation segment: %d", - i); - muchOutStationTyBreakRight[i - 1] = new TH1F(name, title, 100, -0.15, 0.15); - muchOutStationTyBreakRight[i - 1]->StatOverflows(); - - sprintf(name, "muchOutStationXDispByTriplet_%d", i); - sprintf(title, "X dispersion of prediction by triplet angle for station: %d", i); - muchOutStationXDispByTriplet[i - 1] = new TH1F(name, title, 100, -10.0, 10.0); - muchOutStationXDispByTriplet[i - 1]->StatOverflows(); - - sprintf(name, "muchOutStationYDispByTriplet_%d", i); - sprintf(title, "Y dispersion of prediction by triplet angle for station: %d", i); - muchOutStationYDispByTriplet[i - 1] = new TH1F(name, title, 100, -10.0, 10.0); - muchOutStationYDispByTriplet[i - 1]->StatOverflows(); - - sprintf(name, "muchOutStationXDispByVertex_%d", i); - sprintf(title, "X dispersion of prediction by an angle to vertex for station: %d", i); - muchOutStationXDispByVertex[i - 1] = new TH1F(name, title, 100, -10.0, 10.0); - muchOutStationXDispByVertex[i - 1]->StatOverflows(); - - sprintf(name, "muchOutStationYDispByVertex_%d", i); - sprintf(title, "Y dispersion of prediction by an angle to vertex for station: %d", i); - muchOutStationYDispByVertex[i - 1] = new TH1F(name, title, 100, -10.0, 10.0); - muchOutStationYDispByVertex[i - 1]->StatOverflows(); - - sprintf(name, "muchTripletTxBreak_%d", i); - sprintf(title, "Tx break between triplets on stations %d and %d", i - 1, i); - muchTripletTxBreak[i - 1] = new TH1F(name, title, 200, -0.2, 0.2); - muchTripletTxBreak[i - 1]->StatOverflows(); - - sprintf(name, "muchTripletTyBreak_%d", i); - sprintf(title, "Ty break between triplets on stations %d and %d", i - 1, i); - muchTripletTyBreak[i - 1] = new TH1F(name, title, 200, -0.2, 0.2); - muchTripletTyBreak[i - 1]->StatOverflows(); - - if (i < LXSTATIONS - 1) { - sprintf(name, "muchSegmentTxBreakHisto_%d", i); - sprintf(title, - "Tx tangents breaks distribution for adjacent segments on " - "station: %d", - i); - muchSegmentTxBreakHisto[i - 1] = new TH1F(name, title, 100, -.15, .15); - muchSegmentTxBreakHisto[i - 1]->StatOverflows(); - - sprintf(name, "muchSegmentTyBreakHisto_%d", i); - sprintf(title, - "Ty tangents breaks distribution for adjacent segments on " - "station: %d", - i); - muchSegmentTyBreakHisto[i - 1] = new TH1F(name, title, 100, -.15, .15); - muchSegmentTyBreakHisto[i - 1]->StatOverflows(); - } - - sprintf(name, "muchStationTxDispHisto_%d", i); - sprintf(title, "Tx tangents dispersion for segments between stations: %d and %d", i - 1, i); - muchStationTxDispHisto[i - 1] = new TH1F(name, title, 100, -.05, .05); - muchStationTxDispHisto[i - 1]->StatOverflows(); - - sprintf(name, "muchStationTyDispHisto_%d", i); - sprintf(title, "Ty tangents dispersion for segments between stations: %d and %d", i - 1, i); - muchStationTyDispHisto[i - 1] = new TH1F(name, title, 100, -.05, .05); - muchStationTyDispHisto[i - 1]->StatOverflows(); - } - - if (i < LXSTATIONS - 1) { - sprintf(name, "muchXTxCovHisto_%d", i); - sprintf(title, "muchXTxCovHisto on %d", i); - muchXTxCovHisto[i] = new TH2F(name, title, 100, -5.0, 5.0, 100, -0.15, 0.15); - muchXTxCovHisto[i]->StatOverflows(); - - sprintf(name, "muchYTyCovHisto_%d", i); - sprintf(title, "muchYTyCovHisto on %d", i); - muchYTyCovHisto[i] = new TH2F(name, title, 100, -5.0, 5.0, 100, -0.15, 0.15); - muchYTyCovHisto[i]->StatOverflows(); - } - } -} - -static void SaveHisto(TH1* histo) -{ - if (!saveHistos) return; - - char dir_name[256]; - sprintf(dir_name, "configuration.%s", particleType.Data()); - DIR* dir = opendir(dir_name); - - if (dir) closedir(dir); - else - mkdir(dir_name, 0700); - - char name[256]; - sprintf(name, "%s/%s.root", dir_name, histo->GetName()); - TFile fh(name, "RECREATE"); - histo->Write(); - fh.Close(); - delete histo; -} - -void LxTrackAnaSegments::Finish() -{ - for (Int_t i = 0; i < LXSTATIONS; ++i) { - SaveHisto(muchInStationXDispLeft[i]); - SaveHisto(muchInStationXDispRight[i]); - SaveHisto(muchInStationYDispLeft[i]); - SaveHisto(muchInStationYDispRight[i]); - SaveHisto(muchInStationXDispRL[i]); - SaveHisto(muchInStationYDispRL[i]); - SaveHisto(muchInStationTxBreak[i]); - SaveHisto(muchInStationTyBreak[i]); - - if (i > 0) { - SaveHisto(muchLongSegmentTxHisto[i - 1]); - SaveHisto(muchLongSegmentTyHisto[i - 1]); - - SaveHisto(muchClusterXDispHisto[i - 1]); - SaveHisto(muchClusterYDispHisto[i - 1]); - SaveHisto(muchClusterTxDispHisto[i - 1]); - SaveHisto(muchClusterTyDispHisto[i - 1]); - - SaveHisto(muchOutStationTxBreakLeft[i - 1]); - SaveHisto(muchOutStationTxBreakRight[i - 1]); - SaveHisto(muchOutStationTyBreakLeft[i - 1]); - SaveHisto(muchOutStationTyBreakRight[i - 1]); - - SaveHisto(muchOutStationXDispByTriplet[i - 1]); - SaveHisto(muchOutStationYDispByTriplet[i - 1]); - SaveHisto(muchOutStationXDispByVertex[i - 1]); - SaveHisto(muchOutStationYDispByVertex[i - 1]); - - SaveHisto(muchTripletTxBreak[i - 1]); - SaveHisto(muchTripletTyBreak[i - 1]); - - if (i < LXSTATIONS - 1) { - SaveHisto(muchSegmentTxBreakHisto[i - 1]); - SaveHisto(muchSegmentTyBreakHisto[i - 1]); - } - - SaveHisto(muchStationTxDispHisto[i - 1]); - SaveHisto(muchStationTyDispHisto[i - 1]); - } - - if (i < LXSTATIONS - 1) { - SaveHisto(muchXTxCovHisto[i]); - SaveHisto(muchYTyCovHisto[i]); - } - } -} - -static bool GetPoints(LxSimpleTrack* track, LxSimplePoint points[LXSTATIONS][LXLAYERS], Int_t i, Int_t j) -{ - for (; i >= 0; --i) { - for (; j >= 0; --j) { - if (!track->muchPoints[i][j].empty()) points[i][j] = track->muchPoints[i][j].front(); - else { - if (0 != track->parent) return GetPoints(track->parent, points, i, j); - else - return false; - } - } - - j = LXLAYERS - 1; - } - - return true; -} - -static bool GetPoints2(LxSimpleTrack* track, list<LxSimplePoint> points[LXSTATIONS][LXLAYERS], Int_t i, Int_t j) -{ - for (; i >= 0; --i) { - for (; j >= 0; --j) { - if (!track->muchPoints[i][j].empty()) - points[i][j].insert(points[i][j].end(), track->muchPoints[i][j].begin(), track->muchPoints[i][j].end()); - else { - if (0 != track->parent) return GetPoints2(track->parent, points, i, j); - else - return false; - } - } - - j = LXLAYERS - 1; - } - - return true; -} - -void LxTrackAnaSegments::BuildStatistics() -{ - Double_t cutCoeff = 4.0; - bool readHistoResult = true; - Double_t xDispLeft[LXSTATIONS]; - Double_t yDispLeft[LXSTATIONS]; - Double_t xDispRight[LXSTATIONS]; - Double_t yDispRight[LXSTATIONS]; - Double_t xDispRL[LXSTATIONS]; - Double_t yDispRL[LXSTATIONS]; - - for (int i = 0; i < LXSTATIONS; ++i) { - readHistoResult &= GetHistoRMS("muchInStationXDispLeft", i, xDispLeft[i]); - readHistoResult &= GetHistoRMS("muchInStationYDispLeft", i, yDispLeft[i]); - readHistoResult &= GetHistoRMS("muchInStationXDispRight", i, xDispRight[i]); - readHistoResult &= GetHistoRMS("muchInStationYDispRight", i, yDispRight[i]); - readHistoResult &= GetHistoRMS("muchInStationXDispRL", i, xDispRL[i]); - readHistoResult &= GetHistoRMS("muchInStationYDispRL", i, yDispRL[i]); - } - - if (!readHistoResult) return; - - vector<LxSimpleTrack*>& tracks = owner.allTracks; - - static Int_t triggerEvents = 0; - bool hasPositive = false; - bool hasNegative = false; - - for (vector<LxSimpleTrack*>::iterator i = tracks.begin(); i != tracks.end(); ++i) { - LxSimpleTrack* track = *i; - - if (useBgr || (0 > track->motherId && (13 == track->pdgCode || -13 == track->pdgCode))) StatForTrack(track); - - list<LxSimplePoint> points[LXSTATIONS][LXLAYERS]; - - if (!GetPoints2(track, points, stationsInAlgo - 1, LXLAYERS - 1)) continue; - - bool checkSign = true; - bool aOkS[6] = {false, false, false, false, false, false}; - - for (Int_t j = 0; j < stationsInAlgo; ++j) { - bool angleOk = false; - - for (list<LxSimplePoint>::iterator k = points[j][1].begin(); k != points[j][1].end(); ++k) { - LxSimplePoint p1 = *k; - Double_t txEst = p1.x / p1.z; - Double_t tyEst = p1.y / p1.z; - - for (list<LxSimplePoint>::iterator l = points[j][2].begin(); l != points[j][2].end(); ++l) { - LxSimplePoint p2 = *l; - Double_t deltaZ = p2.z - p1.z; - Double_t rX = p1.x + txEst * deltaZ; - Double_t rY = p1.y + tyEst * deltaZ; - - if (abs(rX - p2.x) <= cutCoeff * xDispRight[j] && abs(rY - p2.y) <= cutCoeff * yDispRight[j]) { - angleOk = true; - break; - } - } // l - - if (angleOk) break; - } // k - - if (angleOk) aOkS[j] = true; - } // j - - int okSts = 0; - - for (int j = 0; j < 6; ++j) { - if (aOkS[j]) ++okSts; - } // j - - if (okSts < stationsInAlgo) checkSign = false; - - if (!checkSign) continue; - - for (list<LxSimplePoint>::iterator j = points[0][1].begin(); j != points[0][1].end(); ++j) { - LxSimplePoint p01 = *j; - Double_t txEst = p01.x / p01.z; - - for (list<LxSimplePoint>::iterator k = points[1][1].begin(); k != points[1][1].end(); ++k) { - LxSimplePoint p11 = *k; - Double_t tx2 = (p11.x - p01.x) / (p11.z - p01.z); - Double_t sign2 = tx2 - txEst; - - for (list<LxSimplePoint>::iterator l = points[0][0].begin(); l != points[0][0].end(); ++l) { - LxSimplePoint p00 = *l; - - for (list<LxSimplePoint>::iterator m = points[0][2].begin(); m != points[0][2].end(); ++m) { - LxSimplePoint p02 = *m; - Double_t tx1 = (p02.x - p00.x) / (p02.z - p00.z); - Double_t sign1 = tx1 - txEst; - - if (sign1 > 0 && sign2 > 0) hasPositive = true; - else if (sign1 < 0 && sign2 < 0) - hasNegative = true; - } // m - } // l - } // k - } // j - } // i - - if (hasPositive && hasNegative) ++triggerEvents; - - cout << "LxTrackAnaSegments::BuildStatistics(): triggered: " << triggerEvents << " times" << endl; -} - -struct LxSimpleSegment { - LxSimplePoint source; - LxSimplePoint end; - Double_t tx; - Double_t ty; - - LxSimpleSegment() : tx(0), ty(0) {} - LxSimpleSegment(LxSimplePoint s, LxSimplePoint e) - : source(s) - , end(e) - , tx((e.x - s.x) / (e.z - s.z)) - , ty((e.y - s.y) / (e.z - s.z)) - { - } -}; - -void LxTrackAnaSegments::StatForTrack(LxSimpleTrack* track) -{ - for (Int_t i = 0; i < stationsInAlgo; ++i) { - for (Int_t j = 0; j < LXLAYERS; ++j) { - if (track->muchPoints[i][j].empty()) return; - } - } - - LxSimplePoint p1; - LxSimplePoint p2; - LxSimplePoint p3; - Double_t deltaZ; - Double_t deltaZ2; - Double_t tx; - Double_t tx2; - Double_t ty; - Double_t ty2; - Double_t stTx; - Double_t stTy; - Double_t stTxP; - Double_t stTyP; - - for (Int_t i = 0; i < LXSTATIONS; ++i) { - if (track->muchPoints[i][0].empty() || track->muchPoints[i][1].empty() || track->muchPoints[i][2].empty()) continue; - - p1 = track->muchPoints[i][1].front(); - Double_t txEst = p1.x / p1.z; - Double_t tyEst = p1.y / p1.z; - - p2 = track->muchPoints[i][0].front(); - deltaZ = p2.z - p1.z; - Double_t xEst = p1.x + txEst * deltaZ; - Double_t yEst = p1.y + tyEst * deltaZ; - muchInStationXDispLeft[i]->Fill(p2.x - xEst); - muchInStationYDispLeft[i]->Fill(p2.y - yEst); - tx = (p2.x - p1.x) / deltaZ; - ty = (p2.y - p1.y) / deltaZ; - - p2 = track->muchPoints[i][2].front(); - deltaZ = p2.z - p1.z; - xEst = p1.x + txEst * deltaZ; - yEst = p1.y + tyEst * deltaZ; - muchInStationXDispRight[i]->Fill(p2.x - xEst); - muchInStationYDispRight[i]->Fill(p2.y - yEst); - - tx2 = (p2.x - p1.x) / deltaZ; - ty2 = (p2.y - p1.y) / deltaZ; - - muchInStationTxBreak[i]->Fill(tx2 - tx); - muchInStationTyBreak[i]->Fill(ty2 - ty); - - stTxP = stTx; - stTyP = stTy; - p1 = track->muchPoints[i][0].front(); - deltaZ = p2.z - p1.z; - stTx = (p2.x - p1.x) / deltaZ; - stTy = (p2.y - p1.y) / deltaZ; - muchInStationXDispRL[i]->Fill(p1.x - p2.x + tx2 * deltaZ); - muchInStationYDispRL[i]->Fill(p1.y - p2.y + ty2 * deltaZ); - - if (i > 0) { - p1 = track->muchPoints[i - 1][LXMIDDLE].front(); - p2 = track->muchPoints[i][LXMIDDLE].front(); - deltaZ = p2.z - p1.z; - tx = (p2.x - p1.x) / deltaZ; - muchLongSegmentTxHisto[i - 1]->Fill(tx - p2.x / p2.z); - ty = (p2.y - p1.y) / deltaZ; - muchLongSegmentTyHisto[i - 1]->Fill(ty - p2.y / p2.z); - - muchOutStationTxBreakRight[i - 1]->Fill(tx - stTx); - muchOutStationTyBreakRight[i - 1]->Fill(ty - stTy); - - muchOutStationTxBreakLeft[i - 1]->Fill(tx - stTxP); - muchOutStationTyBreakLeft[i - 1]->Fill(ty - stTyP); - - muchOutStationXDispByTriplet[i - 1]->Fill(p1.x - p2.x + stTx * deltaZ); - muchOutStationYDispByTriplet[i - 1]->Fill(p1.y - p2.y + stTy * deltaZ); - - Double_t txVertex = p2.x / p2.z; - Double_t tyVertex = p2.y / p2.z; - //Double_t scatCoeff = sqrt(1 + txVertex * txVertex + tyVertex * tyVertex); - - muchOutStationXDispByVertex[i - 1]->Fill(p1.x - p2.x + txVertex * deltaZ /* / scatCoeff*/); - muchOutStationYDispByVertex[i - 1]->Fill(p1.y - p2.y + tyVertex * deltaZ /* / scatCoeff*/); - - muchTripletTxBreak[i - 1]->Fill(stTxP - stTx); - muchTripletTyBreak[i - 1]->Fill(stTyP - stTy); - - // Rather complex part for implementation: calculate the dispersion characteristics for segment clusters. - Double_t maxXdisp = 0; - Double_t maxYdisp = 0; - Double_t maxTxdisp = 0; - Double_t maxTydisp = 0; - - for (list<LxSimplePoint>::iterator l0 = track->muchPoints[i - 1][0].begin(); - l0 != track->muchPoints[i - 1][0].end(); ++l0) { - for (list<LxSimplePoint>::iterator l1 = track->muchPoints[i - 1][1].begin(); - l1 != track->muchPoints[i - 1][1].end(); ++l1) { - for (list<LxSimplePoint>::iterator l2 = track->muchPoints[i - 1][2].begin(); - l2 != track->muchPoints[i - 1][2].end(); ++l2) { - for (list<LxSimplePoint>::iterator r0 = track->muchPoints[i][0].begin(); - r0 != track->muchPoints[i][0].end(); ++r0) { - for (list<LxSimplePoint>::iterator r1 = track->muchPoints[i][1].begin(); - r1 != track->muchPoints[i][1].end(); ++r1) { - for (list<LxSimplePoint>::iterator r2 = track->muchPoints[i][2].begin(); - r2 != track->muchPoints[i][2].end(); ++r2) { - LxSimplePoint lPoints[LXLAYERS] = {*l0, *l1, *l2}; - LxSimplePoint rPoints[LXLAYERS] = {*r0, *r1, *r2}; - LxSimpleSegment segments[LXLAYERS * LXLAYERS] = {}; - - for (Int_t j = 0; j < LXLAYERS; ++j) { - for (Int_t k = 0; k < LXLAYERS; ++k) - segments[j * LXLAYERS + k] = LxSimpleSegment(rPoints[j], lPoints[k]); - } - - for (Int_t j = 0; j < LXLAYERS * LXLAYERS - 1; ++j) { - LxSimpleSegment s1 = segments[j]; - - for (Int_t k = j + 1; k < LXLAYERS * LXLAYERS; ++k) { - LxSimpleSegment s2 = segments[k]; - Double_t diffZ = s1.source.z - s2.source.z; - Double_t dtx = abs(s2.tx - s1.tx); - Double_t dty = abs(s2.ty - s1.ty); - Double_t dx = abs(s2.source.x + s2.tx * diffZ - s1.source.x); - Double_t dy = abs(s2.source.y + s2.ty * diffZ - s1.source.y); - - if (maxXdisp < dx) maxXdisp = dx; - - if (maxYdisp < dy) maxYdisp = dy; - - if (maxTxdisp < dtx) maxTxdisp = dtx; - - if (maxTydisp < dty) maxTydisp = dty; - } - } - } - } - } - } - } - } // for (list<LxSimplePoint>::iterator l0 = track->muchPoints[i - 1][0].begin(); l0 != track->muchPoints[i - 1][0].end(); ++l0) - - muchClusterXDispHisto[i - 1]->Fill(maxXdisp); - muchClusterYDispHisto[i - 1]->Fill(maxYdisp); - muchClusterTxDispHisto[i - 1]->Fill(maxTxdisp); - muchClusterTyDispHisto[i - 1]->Fill(maxTydisp); - - if (i < LXSTATIONS - 1) { - p1 = track->muchPoints[i - 1][LXMIDDLE].front(); - p2 = track->muchPoints[i][LXMIDDLE].front(); - deltaZ = p2.z - p1.z; - tx = (p2.x - p1.x) / deltaZ; - ty = (p2.y - p1.y) / deltaZ; - p3 = track->muchPoints[i + 1][LXMIDDLE].front(); - deltaZ2 = p3.z - p2.z; - tx2 = (p3.x - p2.x) / deltaZ2; - Double_t slopeCoeff = sqrt(1 + tx2 * tx2 + ty2 * ty2); - muchSegmentTxBreakHisto[i - 1]->Fill((tx2 - tx) / slopeCoeff); - ty2 = (p3.y - p2.y) / deltaZ2; - muchSegmentTyBreakHisto[i - 1]->Fill((ty2 - ty) / slopeCoeff); - } - - for (Int_t j = 0; j < LXLAYERS * LXLAYERS; ++j) { - p1 = track->muchPoints[i - 1][j % LXLAYERS].front(); - p2 = track->muchPoints[i][j / LXLAYERS].front(); - deltaZ = p2.z - p1.z; - tx = (p2.x - p1.x) / deltaZ; - ty = (p2.y - p1.y) / deltaZ; - - for (Int_t k = j + 1; k < LXLAYERS * LXLAYERS; ++k) { - p1 = track->muchPoints[i - 1][k % LXLAYERS].front(); - p2 = track->muchPoints[i][k / LXLAYERS].front(); - deltaZ = p2.z - p1.z; - tx2 = (p2.x - p1.x) / deltaZ; - muchStationTxDispHisto[i - 1]->Fill(tx2 - tx); - ty2 = (p2.y - p1.y) / deltaZ; - muchStationTyDispHisto[i - 1]->Fill(ty2 - ty); - } - } - } - - if (i < LXSTATIONS - 1) { - p1 = track->muchPoints[i + 1][LXMIDDLE].front(); - p2 = track->muchPoints[i][LXMIDDLE].front(); - deltaZ = p2.z - p1.z; - Double_t deltaX = p2.x - p1.x - p1.tx * deltaZ; - Double_t deltaY = p2.y - p1.y - p1.ty * deltaZ; - Double_t deltaTx = p2.tx - p1.tx; - Double_t deltaTy = p2.ty - p1.ty; - muchXTxCovHisto[i]->Fill(deltaX, deltaTx); - muchYTyCovHisto[i]->Fill(deltaY, deltaTy); - } - } -} diff --git a/reco/tracking/lxTriplet/LxTrackAnaSegments.h b/reco/tracking/lxTriplet/LxTrackAnaSegments.h deleted file mode 100644 index eebc2d83e7b6a479bf9ec7b725ed9f8b10accfa2..0000000000000000000000000000000000000000 --- a/reco/tracking/lxTriplet/LxTrackAnaSegments.h +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright (C) 2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifndef LXTRACKANASEGMENTS_INCLUDED -#define LXTRACKANASEGMENTS_INCLUDED - -#pragma GCC diagnostic ignored "-Weffc++" - -#include "TString.h" - -struct LxSimpleTrack; -class LxTrackAnaTriplet; - -extern bool saveHistos; - -class LxTrackAnaSegments { -public: - explicit LxTrackAnaSegments(LxTrackAnaTriplet& o); - void Init(); - void Finish(); - void BuildStatistics(); - void SetParticleType(TString v); - void SetUseBgr(bool v) - { - useBgr = v; - saveHistos = !v; - } - -private: - void StatForTrack(LxSimpleTrack* track); - LxTrackAnaTriplet& owner; - Int_t stationsInAlgo; - bool useBgr; -}; - -#endif //LXTRACKANASEGMENTS_INCLUDED diff --git a/reco/tracking/lxTriplet/LxUtils.cxx b/reco/tracking/lxTriplet/LxUtils.cxx deleted file mode 100644 index 467f6871012fd61ebdf0aa58a3ef35a3826f2a4d..0000000000000000000000000000000000000000 --- a/reco/tracking/lxTriplet/LxUtils.cxx +++ /dev/null @@ -1,43 +0,0 @@ -/* Copyright (C) 2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#include "Lx.h" - -using namespace std; - -// Used for building of the background on an invariant mass. -void LxFinderTriplet::SaveEventTracks() -{ - for (list<LxTrack*>::iterator i = caSpace.tracks.begin(); i != caSpace.tracks.end(); ++i) { - LxTrack* firstTrack = *i; - - if (0 == firstTrack->externalTrack) continue; - - CbmStsTrack t = *firstTrack->externalTrack->track; - - if (t.GetParamLast()->GetQp() > 0) extFitter.DoFit(&t, -13); - else - extFitter.DoFit(&t, 13); - - // Double_t chi2Prim = extFitter.GetChiToVertex(&t, fPrimVtx); - extFitter.GetChiToVertex(&t, fPrimVtx); - FairTrackParam params; - extFitter.Extrapolate(&t, fPrimVtx->GetZ(), ¶ms); - - Double_t p = 1 / params.GetQp(); - Double_t p2 = p * p; - - if (p2 < 9) continue; - - Double_t tx2 = params.GetTx() * params.GetTx(); - Double_t ty2 = params.GetTy() * params.GetTy(); - Double_t pt2 = p2 * (tx2 + ty2) / (1 + tx2 + ty2); - - if (pt2 < 1) continue; - - t.SetParamFirst(¶ms); - *superEventData = t; - superEventTracks->Fill(); - } -} diff --git a/reco/tracking/lxTriplet/LxUtils.h b/reco/tracking/lxTriplet/LxUtils.h deleted file mode 100644 index 1ea294fce64c5e5780ce0897e98a60be45f57281..0000000000000000000000000000000000000000 --- a/reco/tracking/lxTriplet/LxUtils.h +++ /dev/null @@ -1,12 +0,0 @@ -/* Copyright (C) 2016 Laboratory of Information Technologies, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Timur Ablyazimov [committer] */ - -#ifndef LXUTILS_INCLUDED -#define LXUTILS_INCLUDED - -#pragma GCC diagnostic ignored "-Weffc++" - -// Just to make happy the building system -- now it does not contain any definition. - -#endif //LXUTILS_INCLUDED diff --git a/reco/tracking/vector/CMakeLists.txt b/reco/tracking/vector/CMakeLists.txt deleted file mode 100644 index 1b1188ce5ee4471342bcd356974e0144fde51380..0000000000000000000000000000000000000000 --- a/reco/tracking/vector/CMakeLists.txt +++ /dev/null @@ -1,72 +0,0 @@ -# Create a library called "libBase" which includes the source files given in -# the array . -# The extension is already found. Any number of sources could be listed -# here. - -Set(INCLUDE_DIRECTORIES -${CBMROOT_SOURCE_DIR}/tracking/vector -${CBMBASE_DIR} -${CBMROOT_SOURCE_DIR}/run -${CBMDATA_DIR} -${CBMDATA_DIR}/much -${CBMROOT_SOURCE_DIR}/much -${CBMROOT_SOURCE_DIR}/much/geo -${CBMROOT_SOURCE_DIR}/much/reco -${CBMROOT_SOURCE_DIR}/much/tracking -${CBMROOT_SOURCE_DIR}/trd/param -${CBMROOT_SOURCE_DIR}/trd/data - -# needed by run/FairMCBuffer.h -${CBMDATA_DIR}/mvd -${CBMDATA_DIR}/rich -${CBMDATA_DIR}/sts -${CBMDATA_DIR}/trd -${CBMDATA_DIR}/tof -${CBMDATA_DIR}/psd - -# needed by CbmMuchFindVectors -${CBMROOT_SOURCE_DIR}/KF -${CBMROOT_SOURCE_DIR}/KF/Interface -) - -Include_Directories( ${INCLUDE_DIRECTORIES}) - -Set(SYSTEM_INCLUDE_DIRECTORIES - ${BASE_INCLUDE_DIRECTORIES} -) - -Include_Directories(SYSTEM ${SYSTEM_INCLUDE_DIRECTORIES}) - -set(LINK_DIRECTORIES -${ROOT_LIBRARY_DIR} -${FAIRROOT_LIBRARY_DIR} -${Boost_LIBRARY_DIRS} -) - -link_directories( ${LINK_DIRECTORIES}) - -set(SRCS -CbmVectorFinder.cxx -CbmTrdFindVectors.cxx -CbmTrdToTofVector.cxx -CbmMuchFindVectors.cxx -CbmMuchFindVectorsGem.cxx -#CbmMuchFindVectorsQa.cxx -CbmMuchMergeVectors.cxx -#CbmMuchMergeVectorsQa.cxx -CbmMuchToTrdVectors.cxx -CbmMuchToTofVectors.cxx -) - -#AZ - debug -#SET_SOURCE_FILES_PROPERTIES(${SRCS} PROPERTIES COMPILE_FLAGS -# "-gdwarf-2 -O0") - -set(LINKDEF CbmVectorLinkDef.h) -Set(LIBRARY_NAME CbmVector) -Set(DEPENDENCIES - CbmBase CbmData Base KF -) - -GENERATE_LIBRARY() - diff --git a/reco/tracking/vector/CbmMuchFindVectors.cxx b/reco/tracking/vector/CbmMuchFindVectors.cxx deleted file mode 100644 index 23561a7aeefe2b30db0f5b52a910cb8b6132e96b..0000000000000000000000000000000000000000 --- a/reco/tracking/vector/CbmMuchFindVectors.cxx +++ /dev/null @@ -1,1433 +0,0 @@ -/* Copyright (C) 2014-2018 Veksler and Baldin Laboratory of High Energy Physics, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Alexander Zinchenko [committer] */ - -/** CbmMuchFindVectors.cxx - *@author A.Zinchenko <Alexander.Zinchenko@jinr.ru> - *@since 2014 - **/ -#include "CbmMuchFindVectors.h" - -#include "CbmMuchDigiMatch.h" -#include "CbmMuchMergeVectors.h" -#include "CbmMuchModule.h" -#include "CbmMuchPoint.h" -#include "CbmMuchStation.h" -#include "CbmMuchTrack.h" - -#include "FairEventHeader.h" -#include "FairRootManager.h" - -#include <TClonesArray.h> -#include <TGeoManager.h> -#include <TMath.h> -#include <TMatrixD.h> -#include <TMatrixFLazy.h> -#include <TVectorD.h> - -#include <iostream> - -using std::cout; -using std::endl; -using std::map; -using std::multimap; -using std::pair; -using std::set; -using std::vector; - -//FILE *lun = fopen("chi2.dat","w"); - -// ----- Default constructor ------------------------------------------- -CbmMuchFindVectors::CbmMuchFindVectors() - : FairTask("MuchFindVectors") - , fGeoScheme(CbmMuchGeoScheme::Instance()) - , fTrackArray(NULL) - , fNofTracks(0) - , fHits(NULL) - , fPoints(NULL) - , fDigiMatches(NULL) - , fStatFirst(-1) - , fErrU(-1.0) - , fDiam(0.0) - , fCutChi2(24.0) - , // chi2/ndf=6 for 8 hits - //fCutChi2(20.0), // chi2/ndf=5 for 8 hits - fMinHits(10) -{ -} -// ------------------------------------------------------------------------- - -// ----- Destructor ---------------------------------------------------- -CbmMuchFindVectors::~CbmMuchFindVectors() -{ - fTrackArray->Delete(); - for (Int_t i = 0; i < fgkStat; ++i) { - Int_t nVecs = fVectors[i].size(); - for (Int_t j = 0; j < nVecs; ++j) - delete fVectors[i][j]; - //nVecs = fVectorsHigh[i].size(); - //for (Int_t j = 0; j < nVecs; ++j) delete fVectorsHigh[i][j]; - } - for (map<Int_t, TDecompLU*>::iterator it = fLus.begin(); it != fLus.end(); ++it) - delete it->second; -} -// ------------------------------------------------------------------------- - -// ----- Public method Init (abstract in base class) -------------------- -InitStatus CbmMuchFindVectors::Init() -{ - - // Get and check FairRootManager - FairRootManager* ioman = FairRootManager::Instance(); - if (ioman == NULL) Fatal("Init", "RootManager not instantiated!"); - - // Create and register MuchTrack array (if necessary) - fTrackArray = static_cast<TClonesArray*>(ioman->GetObject("MuchVector")); - if (fTrackArray == NULL) { - fTrackArray = new TClonesArray("CbmMuchTrack", 100); - ioman->Register("MuchVector", "Much", fTrackArray, kTRUE); - } - - CbmMuchFindHitsStraws* hitFinder = (CbmMuchFindHitsStraws*) FairRun::Instance()->GetTask("CbmMuchFindHitsStraws"); - //if (hitFinder == NULL) Fatal("Init", "CbmMuchFindHitsStraws is not run!"); - if (hitFinder == NULL) return kSUCCESS; // no straws - - fDiam = hitFinder->GetDiam(0); - - fHits = static_cast<TClonesArray*>(ioman->GetObject("MuchStrawHit")); - fPoints = static_cast<TClonesArray*>(ioman->GetObject("MuchPoint")); - fDigiMatches = static_cast<TClonesArray*>(ioman->GetObject("MuchStrawDigiMatch")); - - // Find first straw station and get some geo constants - Int_t nSt = fGeoScheme->GetNStations(); - for (Int_t i = 0; i < nSt; ++i) { - CbmMuchStation* st = fGeoScheme->GetStation(i); - CbmMuchModule* mod = fGeoScheme->GetModule(i, 0, 0, 0); - if (mod->GetDetectorType() == 2) { - if (fStatFirst < 0) fStatFirst = CbmMuchAddress::GetStationIndex(st->GetDetectorId()); - //cout << " First station: " << fStatFirst << endl; - Int_t nLays = st->GetNLayers(); - fRmin[i - fStatFirst] = st->GetRmin(); - fRmax[i - fStatFirst] = st->GetRmax(); - for (Int_t lay = 0; lay < nLays; ++lay) { - CbmMuchLayer* layer = st->GetLayer(lay); - Double_t phi = hitFinder->GetPhi(lay); - for (Int_t iside = 0; iside < 2; ++iside) { - CbmMuchLayerSide* side = layer->GetSide(iside); - Int_t plane = lay * 2 + iside; - if (plane == 0) fZ0[i - fStatFirst] = side->GetZ(); - //plane += (i - fStatFirst) * fgkPlanes; - fDz[plane] = side->GetZ(); - fCosa[plane] = TMath::Cos(phi); - fSina[plane] = TMath::Sin(phi); - if (lay) { - fDtubes[i - fStatFirst][lay - 1] = - fRmax[i - fStatFirst] * TMath::Tan(TMath::ASin(fSina[plane]) - TMath::ASin(fSina[plane - 2])); - fDtubes[i - fStatFirst][lay - 1] = TMath::Abs(fDtubes[i - fStatFirst][lay - 1]) / fDiam + 10; - } - } - } - } - } - for (Int_t i = fgkPlanes - 1; i >= 0; --i) { - fDz[i] -= fDz[0]; - //cout << fDz[i] << " "; - } - //cout << endl; - - // Get absorbers - Double_t dzAbs[9] = {0}, zAbs[9] = {0}, radlAbs[9] = {0}, xyzl[3] = {0}, xyzg[3] = {0}; - Int_t nAbs = 0; - TGeoVolume* vol = 0x0; - for (Int_t i = 1; i < 10; ++i) { - TString abso = "muchabsorber0"; - abso += i; - vol = gGeoManager->GetVolume(abso); - if (vol == 0x0) break; - TString path = "/cave_1/much_0/"; - path += abso; - path += "_0"; - gGeoManager->cd(path); - gGeoManager->LocalToMaster(xyzl, xyzg); - zAbs[nAbs] = xyzg[2]; - cout << vol->GetName() << " " << vol->GetShape()->GetName() << " " << ((TGeoBBox*) vol->GetShape())->GetDZ() - << endl; - //dzAbs[nAbs] = ((TGeoCone*) vol->GetShape())->GetDz(); - dzAbs[nAbs] = ((TGeoBBox*) vol->GetShape())->GetDZ(); - radlAbs[nAbs] = vol->GetMaterial()->GetRadLen(); - fZabs0[nAbs][0] = zAbs[nAbs] - dzAbs[nAbs]; - fZabs0[nAbs][1] = zAbs[nAbs] + dzAbs[nAbs]; - fX0abs[nAbs] = radlAbs[nAbs]; - ++nAbs; - } - - cout << " \n !!! MUCH Absorbers: " << nAbs << "\n Zbeg, Zend, X0:"; - for (Int_t j = 0; j < nAbs; ++j) - cout << " " << fZabs0[j][0] << ", " << fZabs0[j][1] << ", " << fX0abs[j] << ";"; - cout << endl << endl; - - if (fStatFirst < 0) return kSUCCESS; // only GEM configuration - - ComputeMatrix(); // compute system matrices - return kSUCCESS; -} -// ------------------------------------------------------------------------- - -// ----- SetParContainers ------------------------------------------------- -void CbmMuchFindVectors::SetParContainers() {} -// ------------------------------------------------------------------------- - -// ----- Public method Exec -------------------------------------------- -void CbmMuchFindVectors::Exec(Option_t* opt) -{ - - fTrackArray->Delete(); - if (fStatFirst < 0) return; // only GEM configuration - - //FairTask *vecFinderGem = (FairTask*) FairRun::Instance()->GetTask("MuchFindVectorsGem"); - //if (vecFinderGem == NULL) fTrackArray->Delete(); - - for (Int_t i = 0; i < fgkStat; ++i) { - Int_t nVecs = fVectors[i].size(); - for (Int_t j = 0; j < nVecs; ++j) - delete fVectors[i][j]; - fVectors[i].clear(); - //nVecs = fVectorsHigh[i].size(); - //for (Int_t j = 0; j < nVecs; ++j) delete fVectorsHigh[i][j]; - fVectorsHigh[i].clear(); - } - - // Do all processing - - // Get hits - GetHits(); - - // Build vectors - MakeVectors(); - - // Remove vectors with wrong orientation - // (using empirical cuts for omega muons at 8 GeV) - CheckParams(); - - // Match vectors from 2 stations - MatchVectors(); - - // Go to the high resolution mode processing - Double_t err = fErrU; - //fErrU = 0.02; - fErrU = 0.04; - if (fErrU < 0.1) HighRes(); - fErrU = err; - - // Remove clones - //RemoveClones(); - - // Remove short tracks - RemoveShorts(); - - // Store vectors - StoreVectors(); -} -// ------------------------------------------------------------------------- - -// ----- Public method Finish ------------------------------------------ -void CbmMuchFindVectors::Finish() -{ - fTrackArray->Clear(); - for (Int_t i = 0; i < fgkStat; ++i) { - Int_t nVecs = fVectors[i].size(); - for (Int_t j = 0; j < nVecs; ++j) - delete fVectors[i][j]; - //nVecs = fVectorsHigh[i].size(); - //for (Int_t j = 0; j < nVecs; ++j) delete fVectorsHigh[i][j]; - } - for (map<Int_t, TDecompLU*>::iterator it = fLus.begin(); it != fLus.end(); ++it) - delete it->second; -} -// ------------------------------------------------------------------------- - -// ----- Private method ComputeMatrix ---------------------------------- -void CbmMuchFindVectors::ComputeMatrix() -{ - // Compute system matrices for different hit plane patterns - - Double_t cos2[fgkPlanes], sin2[fgkPlanes], sincos[fgkPlanes], dz2[fgkPlanes]; - Bool_t onoff[fgkPlanes]; - - for (Int_t i = 0; i < fgkPlanes; ++i) { - cos2[i] = fCosa[i] * fCosa[i]; - sin2[i] = fSina[i] * fSina[i]; - sincos[i] = fSina[i] * fCosa[i]; - dz2[i] = fDz[i] * fDz[i]; - onoff[i] = kTRUE; - } - - TMatrixD coef(4, 4); - Int_t pattMax = 1 << fgkPlanes, nDouble = 0, nTot = 0; - - // Loop over doublet patterns - for (Int_t ipat = 1; ipat < pattMax; ++ipat) { - - // Check if the pattern is valid: - // either all doublets are active or 3 the first ones (for high resolution mode) - nDouble = 0; - for (Int_t j = 0; j < fgkPlanes; j += 2) - if (ipat & (3 << j)) ++nDouble; - else - break; - if ((ipat & (3 << 6)) == 0) ++nDouble; // 3 doublets - if (nDouble < fgkPlanes / 2) continue; - ++nTot; - - for (Int_t j = 0; j < fgkPlanes; ++j) - onoff[j] = (ipat & (1 << j)); - - coef = 0.0; - for (Int_t i = 0; i < fgkPlanes; ++i) { - if (!onoff[i]) continue; - coef(0, 0) += cos2[i]; - coef(0, 1) += sincos[i]; - coef(0, 2) += fDz[i] * cos2[i]; - coef(0, 3) += fDz[i] * sincos[i]; - } - for (Int_t i = 0; i < fgkPlanes; ++i) { - if (!onoff[i]) continue; - coef(1, 0) += sincos[i]; - coef(1, 1) += sin2[i]; - coef(1, 2) += fDz[i] * sincos[i]; - coef(1, 3) += fDz[i] * sin2[i]; - } - for (Int_t i = 0; i < fgkPlanes; ++i) { - if (!onoff[i]) continue; - coef(2, 0) += fDz[i] * cos2[i]; - coef(2, 1) += fDz[i] * sincos[i]; - coef(2, 2) += dz2[i] * cos2[i]; - coef(2, 3) += dz2[i] * sincos[i]; - } - for (Int_t i = 0; i < fgkPlanes; ++i) { - if (!onoff[i]) continue; - coef(3, 0) += fDz[i] * sincos[i]; - coef(3, 1) += fDz[i] * sin2[i]; - coef(3, 2) += dz2[i] * sincos[i]; - coef(3, 3) += dz2[i] * sin2[i]; - } - - TDecompLU* lu = new TDecompLU(4); - lu->SetMatrix(coef); - lu->SetTol(0.1 * lu->GetTol()); - lu->Decompose(); - fLus.insert(pair<Int_t, TDecompLU*>(ipat, lu)); - TMatrixDSym cov(4); - cov.SetMatrixArray(coef.GetMatrixArray()); - cov.Invert(); // covar. matrix - fMatr.insert(pair<Int_t, TMatrixDSym*>(ipat, new TMatrixDSym(cov))); - TString buf = ""; - for (Int_t jp = 0; jp < fgkPlanes; ++jp) - buf += Bool_t(ipat & (1 << jp)); - cout << " Determinant: " << buf << " " << ipat << " " << coef.Determinant() << endl; - if (ipat == 255) { - coef.Print(); - cout << " Number of configurations: " << nTot << endl; - } - cov *= (0.02 * 0.02); - cout << TMath::Sqrt(cov(0, 0)) << " " << TMath::Sqrt(cov(1, 1)) << " " << TMath::Sqrt(cov(2, 2)) << " " - << TMath::Sqrt(cov(3, 3)) << endl; - } -} -// ------------------------------------------------------------------------- - -// ----- Private method GetHits ---------------------------------------- -void CbmMuchFindVectors::GetHits() -{ - // Group hits according to their plane number - - for (Int_t ista = 0; ista < fgkStat; ++ista) { - for (Int_t i = 0; i < fgkPlanes; ++i) - fHitPl[ista][i].clear(); - for (Int_t i = 0; i < fgkPlanes / 2; ++i) - fHit2d[ista][i].clear(); - } - - Int_t nHits = fHits->GetEntriesFast(), nSelTu[fgkStat] = {0}, sel = 0; - for (Int_t i = 0; i < nHits; ++i) { - CbmMuchStrawHit* hit = (CbmMuchStrawHit*) fHits->UncheckedAt(i); - - //!!! For debug - select hits with certain track IDs - sel = 1; //SelectHitId(hit); - if (!sel) continue; - // - - Int_t detId = hit->GetAddress(); - CbmMuchModule* module = fGeoScheme->GetModuleByDetId(detId); - if (module->GetDetectorType() != 2) continue; // skip GEM hits - UInt_t address = CbmMuchAddress::GetElementAddress(detId, kMuchModule); - Int_t station3 = CbmMuchAddress::GetStationIndex(address); // station - Int_t doublet = CbmMuchAddress::GetLayerIndex(address); // doublet - Int_t layer = CbmMuchAddress::GetLayerSideIndex(address); // layer in doublet - //cout << hit->GetZ() << " " << station3 << " " << doublet << " " << layer << endl; - //Int_t plane = (station3 - fStatFirst) * 8 + doublet * 2 + layer; - Int_t plane = doublet * 2 + layer; - fHitPl[station3 - fStatFirst][plane].insert(pair<Int_t, Int_t>(hit->GetTube() + 1000 * hit->GetSegment(), i)); - if (fErrU < 0) fErrU = hit->GetDu(); - if (sel) ++nSelTu[station3 - fStatFirst]; - } - - // Merge neighbouring hits from 2 layers of 1 doublet. - // If there is no neighbour, takes hit from a single layer (to account for inefficiency) - Int_t nlay2 = fgkPlanes / 2, indx1, indx2, tube1, tube2, next1, next2; - CbmMuchStrawHit *hit1 = NULL, *hit2 = NULL; - - for (Int_t ista = 0; ista < fgkStat; ++ista) { - // Loop over stations - Int_t nSelDouble = 0; - - for (Int_t i1 = 0; i1 < nlay2; ++i1) { - /* Debug - cout << " Doublet: " << ista << " " << i1 << " " << fHitPl[ista][i1*2].size() << " " << fHitPl[ista][i1*2+1].size() << endl << " Layer 1: " << endl; - for (multimap<Int_t,Int_t>::iterator it = fHitPl[ista][i1*2].begin(); it != fHitPl[ista][i1*2].end(); ++it) - cout << it->second << " "; - cout << endl; - for (multimap<Int_t,Int_t>::iterator it = fHitPl[ista][i1*2].begin(); it != fHitPl[ista][i1*2].end(); ++it) - cout << it->first << " "; - cout << endl << " Layer 2: " << endl; - for (multimap<Int_t,Int_t>::iterator it = fHitPl[ista][i1*2+1].begin(); it != fHitPl[ista][i1*2+1].end(); ++it) - cout << it->second << " "; - cout << endl; - for (multimap<Int_t,Int_t>::iterator it = fHitPl[ista][i1*2+1].begin(); it != fHitPl[ista][i1*2+1].end(); ++it) - cout << it->first << " "; - cout << endl; - */ - - // Loop over doublets - multimap<Int_t, Int_t>::iterator it1 = fHitPl[ista][i1 * 2].begin(), it2 = fHitPl[ista][i1 * 2 + 1].begin(); - multimap<Int_t, Int_t>::iterator it1end = fHitPl[ista][i1 * 2].end(), it2end = fHitPl[ista][i1 * 2 + 1].end(); - set<Int_t> tubeOk[2]; - next1 = next2 = 1; - if (it1 == it1end) next1 = 0; - if (it2 == it2end) next2 = 0; - - while (next1 || next2) { - // Loop over tubes - if (next1) { - indx1 = it1->second; - hit1 = (CbmMuchStrawHit*) fHits->UncheckedAt(indx1); - tube1 = it1->first; - } - if (next2) { - indx2 = it2->second; - hit2 = (CbmMuchStrawHit*) fHits->UncheckedAt(indx2); - tube2 = it2->first; - } - - if (it2 != it2end && tube2 < tube1 || it1 == it1end) { - // Single layer hit2 ? - if (tubeOk[1].find(tube2) == tubeOk[1].end()) { - sel = SelDoubleId(-1, indx2); - nSelDouble += sel; - if (sel) fHit2d[ista][i1].push_back(pair<Int_t, Int_t>(-1, indx2)); - tubeOk[1].insert(tube2); - } - ++it2; - next2 = 1; - next1 = 0; - if (it2 == fHitPl[ista][i1 * 2 + 1].end()) next2 = 0; - continue; - } - if (it1 != it1end && tube2 > tube1 + 1 || it2 == it2end) { - // Single layer hit1 ? - if (tubeOk[0].find(tube1) == tubeOk[0].end()) { - sel = SelDoubleId(indx1, -1); - nSelDouble += sel; - if (sel) fHit2d[ista][i1].push_back(pair<Int_t, Int_t>(indx1, -1)); - tubeOk[0].insert(tube1); - } - ++it1; - next1 = 1; - next2 = 0; - if (it1 == fHitPl[ista][i1 * 2].end()) next1 = 0; - continue; - } - // Double layer hit - sel = SelDoubleId(indx1, indx2); - nSelDouble += sel; - if (sel) fHit2d[ista][i1].push_back(pair<Int_t, Int_t>(indx1, indx2)); - tubeOk[0].insert(tube1); - tubeOk[1].insert(tube2); - if (tube2 == tube1) { - ++it2; - next2 = 1; - next1 = 0; - if (it2 == fHitPl[ista][i1 * 2 + 1].end()) { - next2 = 0; - next1 = 1; - if (it1 == fHitPl[ista][i1 * 2].end()) next1 = 0; - } - } - else { - ++it1; - next1 = 1; - next2 = 0; - if (it1 == fHitPl[ista][i1 * 2].end()) { - next1 = 0; - next2 = 1; - if (it2 == fHitPl[ista][i1 * 2 + 1].end()) next2 = 0; - } - } - continue; - } // while (next1... - } - cout << " Selected tubes: " << ista << " " << nSelTu[ista] << endl; - - cout << " Selected doublets: " << ista << " " << nSelDouble << endl; - } -} -// ------------------------------------------------------------------------- - -// ----- Private method SelectHitId ------------------------------------ -Bool_t CbmMuchFindVectors::SelectHitId(const CbmMuchStrawHit* hit) -{ - // Select hits with certain track IDs (for debugging) - - Int_t nSel = 2, idSel[2] = {0, 1}, id = 0; - - for (Int_t i = 0; i < nSel; ++i) { - if (hit->GetFlag() % 2) { - //if (0) { - // Mirror hit - return kFALSE; - } - else { - CbmMuchDigiMatch* digiM = (CbmMuchDigiMatch*) fDigiMatches->UncheckedAt(hit->GetRefId()); - Int_t np = digiM->GetNofLinks(); - for (Int_t ip = 0; ip < np; ++ip) { - CbmMuchPoint* point = (CbmMuchPoint*) fPoints->UncheckedAt(digiM->GetLink(ip).GetIndex()); - id = point->GetTrackID(); - if (id == idSel[i]) return kTRUE; - } - } - } - return kFALSE; -} -// ------------------------------------------------------------------------- - -// ----- Private method SelDoubleId ------------------------------------ -Bool_t CbmMuchFindVectors::SelDoubleId(Int_t indx1, Int_t indx2) -{ - // Select doublets with certain track IDs (for debugging) - - return kTRUE; // no selection - - Int_t nId = 2, idSel[2] = {0, 1}, id = 0; - CbmMuchStrawHit* hit = NULL; - CbmMuchDigiMatch* digiM = NULL; - CbmMuchPoint* point = NULL; - - if (indx1 >= 0) { - hit = (CbmMuchStrawHit*) fHits->UncheckedAt(indx1); - if (hit->GetFlag() % 2 == 0) { - // Not a mirror hit - for (Int_t i = 0; i < nId; ++i) { - digiM = (CbmMuchDigiMatch*) fDigiMatches->UncheckedAt(hit->GetRefId()); - Int_t np = digiM->GetNofLinks(); - for (Int_t ip = 0; ip < np; ++ip) { - point = (CbmMuchPoint*) fPoints->UncheckedAt(digiM->GetLink(ip).GetIndex()); - id = point->GetTrackID(); - if (id == idSel[i]) return kTRUE; - } - } - } - } - if (indx2 >= 0) { - hit = (CbmMuchStrawHit*) fHits->UncheckedAt(indx2); - if (hit->GetFlag() % 2 == 0) { - // Not a mirror hit - for (Int_t i = 0; i < nId; ++i) { - digiM = (CbmMuchDigiMatch*) fDigiMatches->UncheckedAt(hit->GetRefId()); - Int_t np = digiM->GetNofLinks(); - for (Int_t ip = 0; ip < np; ++ip) { - point = (CbmMuchPoint*) fPoints->UncheckedAt(digiM->GetLink(ip).GetIndex()); - id = point->GetTrackID(); - if (id == idSel[i]) return kTRUE; - } - } - } - } - return kFALSE; -} -// ------------------------------------------------------------------------- - -// ----- Private method MakeVectors ------------------------------------ -void CbmMuchFindVectors::MakeVectors() -{ - // Make vectors for stations - - for (Int_t ista = 0; ista < fgkStat; ++ista) { - Int_t nvec = fVectors[ista].size(); - for (Int_t j = 0; j < nvec; ++j) - delete fVectors[ista][j]; - fVectors[ista].clear(); - Int_t lay2 = 0, patt = 0, flag = 0, ndoubl = fHit2d[ista][lay2].size(); - CbmMuchStrawHit* hit = NULL; - - cout << " Doublets: " << ista << " " << ndoubl << endl; - for (Int_t id = 0; id < ndoubl; ++id) { - Int_t indx1 = fHit2d[ista][lay2][id].first; - Int_t indx2 = fHit2d[ista][lay2][id].second; - if (indx1 >= 0) { - hit = (CbmMuchStrawHit*) fHits->UncheckedAt(indx1); - fUz[lay2 * 2][0] = hit->GetU(); - //fUz[lay2*2][2] = hit->GetPhi(); - fUzi[lay2 * 2][0] = hit->GetSegment(); - fUzi[lay2 * 2][1] = indx1; - fUzi[lay2 * 2][2] = hit->GetTube(); - } - if (indx2 >= 0) { - hit = (CbmMuchStrawHit*) fHits->UncheckedAt(indx2); - fUz[lay2 * 2 + 1][0] = hit->GetU(); - //fUz[lay2*2+1][2] = hit->GetPhi(); - fUzi[lay2 * 2 + 1][0] = hit->GetSegment(); - fUzi[lay2 * 2 + 1][1] = indx2; - fUzi[lay2 * 2 + 1][2] = hit->GetTube(); - } - Bool_t ind1 = indx1 + 1; - Bool_t ind2 = indx2 + 1; - patt = ind1; - patt |= (ind2 << 1); - //cout << plane0 << " " << hit->GetX() << " " << hit->GetY() << " " << hit->GetZ() << " " << hit->GetU() << " " << u << endl; - ProcessDouble(ista, lay2 + 1, patt, flag, hit->GetTube(), hit->GetSegment()); - } - } -} -// ------------------------------------------------------------------------- - -// ----- Private method ProcessDouble ---------------------------------- -void CbmMuchFindVectors::ProcessDouble(Int_t ista, Int_t lay2, Int_t patt, Int_t flag, Int_t tube0, Int_t segment0) -{ - // Main processing engine (recursively adds doublet hits to the vector) - - // !!! Tube differences between the same views for mu from omega at 8 GeV !!! - const Int_t dTubes2 = 30; - Double_t pars[4] = {0.0}; - - Int_t ndoubl = fHit2d[ista][lay2].size(); - - for (Int_t id = 0; id < ndoubl; ++id) { - Int_t indx1 = fHit2d[ista][lay2][id].first; - Int_t indx2 = fHit2d[ista][lay2][id].second; - CbmMuchStrawHit* hit = (CbmMuchStrawHit*) fHits->UncheckedAt(TMath::Max(indx1, indx2)); - Int_t segment = hit->GetSegment(); - Int_t tube = hit->GetTube(); - //if (segment != segment0) continue; // do not combine two half-stations - wrong due to stereo angles - - if (TMath::Abs(tube - tube0) > fDtubes[ista][lay2 - 1]) continue; // !!! cut - - // Check the same views - Int_t ok = 1; - for (Int_t il = 0; il < lay2; ++il) { - Int_t pl = il * 2; - if (TMath::Abs(fSina[pl] - fSina[lay2 * 2]) < 0.01) { - // The same views - Int_t seg = fUzi[pl][0]; - if (!(patt & (1 << pl))) seg = fUzi[pl + 1][0]; - if (segment != seg) { - ok = 0; - break; - } - // Check tube difference - Double_t z = fDz[pl]; - Int_t tu = fUzi[pl][2]; - if (!(patt & (1 << pl))) { - z = fDz[pl + 1]; - tu = fUzi[pl + 1][2]; - } - z += fZ0[ista]; - Double_t dzz = (hit->GetZ() - z) / z; - if (TMath::Abs(tube - tu - dzz * tu) > dTubes2) { - ok = 0; - break; - } // !!! cut - } - } - if (!ok) continue; // !!! cut - - /* - if (lay2 > 1) { - // Tube difference with previous to previous doublet - Int_t pl = (lay2 - 2) * 2; - Int_t tu = fUzi[pl][2]; - if (patt & (1 << pl+1)) tu = fUzi[pl+1][2]; - Double_t dtu = tube - tu; - if (lay2 == 3) dtu -= slope[ista] * tu; - //if (TMath::Abs(dtu) > dTubes2[lay2-2]) continue; // !!! cut - } - */ - - if (indx1 >= 0) { - hit = (CbmMuchStrawHit*) fHits->UncheckedAt(indx1); - fUz[lay2 * 2][0] = hit->GetU(); - //fUz[lay2*2][2] = hit->GetPhi(); - fUzi[lay2 * 2][0] = hit->GetSegment(); - fUzi[lay2 * 2][1] = indx1; - fUzi[lay2 * 2][2] = hit->GetTube(); - } - if (indx2 >= 0) { - hit = (CbmMuchStrawHit*) fHits->UncheckedAt(indx2); - fUz[lay2 * 2 + 1][0] = hit->GetU(); - //fUz[lay2*2+1][2] = hit->GetPhi(); - fUzi[lay2 * 2 + 1][0] = hit->GetSegment(); - fUzi[lay2 * 2 + 1][1] = indx2; - fUzi[lay2 * 2 + 1][2] = hit->GetTube(); - } - - // Check intersection - //if (!IntersectViews(ista, lay2, indx1, indx2, patt)) continue; - - Bool_t ind1 = indx1 + 1; - Bool_t ind2 = indx2 + 1; - // Clear bits - patt &= ~(1 << lay2 * 2); - patt &= ~(1 << lay2 * 2 + 1); - // Set bits - patt |= (ind1 << lay2 * 2); - patt |= (ind2 << lay2 * 2 + 1); - //cout << plane << " " << patt << " " << hit->GetX() << " " << hit->GetY() << " " << hit->GetZ() << " " << hit->GetU() << " " << u << endl; - - if (lay2 + 1 < fgkPlanes / 2) ProcessDouble(ista, lay2 + 1, patt, flag, tube, segment); - else { - // Straight line fit of the vector - FindLine(patt, pars); - Double_t chi2 = FindChi2(ista, patt, pars); - //cout << " *** Stat: " << ista << " " << id << " " << indx1 << " " << indx2 << " " << chi2 << " " << pars[0] << " " << pars[1] << endl; - if (chi2 <= fCutChi2) AddVector(ista, patt, chi2, pars); // add vector to the temporary container - } - } // for (id = 0; id < ndoubl; -} -// ------------------------------------------------------------------------- - -// ----- Private method IntersectViews --------------------------------- -Bool_t CbmMuchFindVectors::IntersectViews(Int_t ista, Int_t curLay, Int_t indx1, Int_t indx2, Int_t patt) -{ - // Intersect 2 views - - Int_t lay2 = curLay * 2; - if (indx1 < 0) ++lay2; - Double_t u2 = fUz[lay2][0]; - - Int_t lay1 = curLay * 2 - 2; - if (!(patt & (1 << lay1))) ++lay1; - Double_t u1 = fUz[lay1][0]; - - Double_t yint = u1 * fCosa[lay2] - u2 * fCosa[lay1]; - yint /= (fSina[lay1] * fCosa[lay2] - fSina[lay2] * fCosa[lay1]); - if (TMath::Abs(yint) > fRmax[ista] + 10.0) return kFALSE; // outside outer dim. + safety margin - - Double_t xint = u2 / fCosa[lay2] - yint * fSina[lay2] / fCosa[lay2]; - - Double_t v1 = -xint * fSina[lay1] + yint * fCosa[lay1]; - Double_t v2 = -xint * fSina[lay2] + yint * fCosa[lay2]; - - cout << xint << " " << yint << " " << v1 << " " << v2 << " " << fUzi[lay1][0] << " " << fUzi[lay2][0] << endl; - if (TMath::Abs(v1) > 10.0 && v1 * fUzi[lay1][0] < 0) cout << " Outside !!! " << endl; - if (TMath::Abs(v2) > 10.0 && v2 * fUzi[lay2][0] < 0) cout << " Outside !!! " << endl; - if (TMath::Abs(v1) > 30.0 && v1 * fUzi[lay1][0] < 0) return kFALSE; - if (TMath::Abs(v2) > 30.0 && v2 * fUzi[lay2][0] < 0) return kFALSE; - return kTRUE; -} -// ------------------------------------------------------------------------- - -// ----- Private method AddVector -------------------------------------- -void CbmMuchFindVectors::AddVector(Int_t ista, Int_t patt, Double_t chi2, Double_t* pars, Bool_t lowRes) -{ - // Add vector to the temporary container (as a MuchTrack) - - CbmMuchTrack* track = new CbmMuchTrack(); - track->SetChiSq(chi2); - TMatrixDSym cov(*fMatr[patt]); - cov *= (fErrU * fErrU); - //cov *= (0.2 * 0.2); // - cov.ResizeTo(5, 5); - FairTrackParam par(pars[0], pars[1], fZ0[ista], pars[2], pars[3], 0.0, cov); - track->SetParamFirst(&par); - par.SetZ(fZ0[ista] + fDz[fgkPlanes - 1]); - par.SetX(pars[0] + fDz[fgkPlanes - 1] * pars[2]); - par.SetY(pars[1] + fDz[fgkPlanes - 1] * pars[3]); - track->SetParamLast(&par); - track->SetUniqueID(ista + fStatFirst); // just to pass the value - - for (Int_t ipl = 0; ipl < fgkPlanes; ++ipl) { - if (!(patt & (1 << ipl))) continue; - track->AddHit(fUzi[ipl][1], kMUCHSTRAWHIT); - if (lowRes) continue; - // Store selected hit coordinate (resolved left-right ambig.) as data member fDphi - CbmMuchStrawHit* hit = (CbmMuchStrawHit*) fHits->UncheckedAt(fUzi[ipl][1]); - hit->SetDphi(fUz[ipl][0]); - } - Int_t ndf = (track->GetNofHits() > 4) ? track->GetNofHits() - 4 : 1; - track->SetNDF(ndf); - SetTrackId(track); // set track ID as its flag - if (lowRes) fVectors[ista].push_back(track); - else - fVectorsHigh[ista].push_back(track); -} -// ------------------------------------------------------------------------- - -// ----- Private method SetTrackId ------------------------------------- -void CbmMuchFindVectors::SetTrackId(CbmMuchTrack* vec) -{ - // Set vector ID as its flag (maximum track ID of its poins) - - map<Int_t, Int_t> ids; - Int_t nhits = vec->GetNofHits(), id = 0; - - for (Int_t ih = 0; ih < nhits; ++ih) { - CbmMuchStrawHit* hit = (CbmMuchStrawHit*) fHits->UncheckedAt(vec->GetHitIndex(ih)); - if (hit->GetFlag() % 2) { - //if (0) { - // Mirror hit - id = -1; - if (ids.find(id) == ids.end()) ids.insert(pair<Int_t, Int_t>(id, 1)); - else - ++ids[id]; - } - else { - CbmMuchDigiMatch* digiM = (CbmMuchDigiMatch*) fDigiMatches->UncheckedAt(hit->GetRefId()); - Int_t np = digiM->GetNofLinks(); - for (Int_t ip = 0; ip < np; ++ip) { - //CbmMuchPoint* point = (CbmMuchPoint*) fPoints->UncheckedAt(digiM->GetLink(0).GetIndex()); - CbmMuchPoint* point = (CbmMuchPoint*) fPoints->UncheckedAt(digiM->GetLink(ip).GetIndex()); - id = point->GetTrackID(); - //if (np > 1) cout << ip << " " << id << endl; - if (ids.find(id) == ids.end()) ids.insert(pair<Int_t, Int_t>(id, 1)); - else - ++ids[id]; - } - //if (np > 1) { cout << " digi " << digiM->GetNofLinks() << " " << ista << " " << hit->GetX() << " " << hit->GetY() << endl; exit(0); } - } - } - Int_t maxim = -1, idmax = -9; - for (map<Int_t, Int_t>::iterator it = ids.begin(); it != ids.end(); ++it) { - if (it->second > maxim) { - maxim = it->second; - idmax = it->first; - } - } - // Set vector ID as its flag - vec->SetFlag(idmax); -} -// ------------------------------------------------------------------------- - -// ----- Private method FindLine --------------------------------------- -void CbmMuchFindVectors::FindLine(Int_t patt, Double_t* pars) -{ - // Fit of hits to the straight line - - // Solve system of linear equations - Bool_t ok = kFALSE, onoff; - TVectorD b(4); - for (Int_t i = 0; i < fgkPlanes; ++i) { - onoff = patt & (1 << i); - if (!onoff) continue; - b[0] += fUz[i][0] * fCosa[i]; - b[1] += fUz[i][0] * fSina[i]; - b[2] += fUz[i][0] * fDz[i] * fCosa[i]; - b[3] += fUz[i][0] * fDz[i] * fSina[i]; - } - - //lu.Print(); - TVectorD solve = fLus[patt]->Solve(b, ok); - //TVectorD solve = lu.TransSolve(b, ok); - //lu.Print(); - for (Int_t i = 0; i < 4; ++i) - pars[i] = solve[i]; - //for (Int_t i = 0; i < 4; ++i) { cout << pars[i] << " "; if (i == 3) cout << endl; } - //Double_t y1 = cosa / sina * (uz[1][0] * cosa - uz[0][0]) + uz[1][0] * sina; - //Double_t y2 = -cosa / sina * (uz[2][0] * cosa - uz[0][0]) - uz[2][0] * sina; - //cout << " OK " << ok << " " << y1 << " " << y2 << endl; -} -// ------------------------------------------------------------------------- - -// ----- Private method FindChi2 --------------------------------------- -Double_t CbmMuchFindVectors::FindChi2(Int_t ista, Int_t patt, Double_t* pars) -{ - // Compute chi2 of the fit - - Double_t chi2 = 0, x = 0, y = 0, u = 0, errv = 1.; - if (fErrU > 0.1) errv = 10; - static Int_t first = 1; - if (first) { - first = 0; - /* - mcFile->Get("FairBaseParSet"); - cout << gGeoManager << " " << gGeoManager->GetVolume("muchstation05") << " " << gGeoManager->GetVolume("muchstation06") << endl; - for (Int_t i = 0; i < 2; ++i) { - TString volName = "muchstation0"; - volName += (i+4); - TGeoVolume *vol = gGeoManager->GetVolume(volName); - TGeoTube *shape = (TGeoTube*) vol->GetShape(); - rad[i] = shape->GetRmin(); - } - cout << " Rads: " << rad[0] << " " << rad[1] << endl; - */ - } - - fChi2Map.clear(); - Bool_t onoff; - for (Int_t i = 0; i < fgkPlanes; ++i) { - onoff = patt & (1 << i); - if (!onoff) continue; - x = pars[0] + pars[2] * fDz[i]; - y = pars[1] + pars[3] * fDz[i]; - u = x * fCosa[i] + y * fSina[i]; - Double_t du = (u - fUz[i][0]) / fErrU, du2 = du * du; - chi2 += du2; - multimap<Double_t, Int_t>::iterator it = fChi2Map.insert(pair<Double_t, Int_t>(du2, i)); - //cout << " " << i << " " << x << " " << y << " " << u << " " << fUz[i][0] << " " << du*du << endl; - - // Edge effect - //if (errv < 2.0) continue; // skip for high-res. mode - Int_t iseg = fUzi[i][0]; - Double_t v = -x * fSina[i] + y * fCosa[i]; - Double_t v0 = 0; - //cout << v << " " << iseg << endl; - if (TMath::Abs(fUz[i][0]) > fRmin[ista] && v * iseg > 0) continue; - - if (TMath::Abs(fUz[i][0]) < fRmin[ista]) { - v0 = TMath::Sign(TMath::Sqrt(fRmin[ista] * fRmin[ista] - fUz[i][0] * fUz[i][0]), - iseg * 1.); // beam hole - if ((v - v0) * iseg > 0) continue; - } - Double_t dv = (v - v0) / errv, dv2 = dv * dv; - chi2 += dv2; - fChi2Map.erase(it); - fChi2Map.insert(pair<Double_t, Int_t>(du2 + dv2, i)); - } - //cout << " Chi2 = " << chi2 << endl; - return chi2; -} -// ------------------------------------------------------------------------- - -// ----- Private method CheckParams ------------------------------------ -void CbmMuchFindVectors::CheckParams() -{ - // Remove vectors with wrong orientation - // using empirical cuts for omega muons at 8 Gev - - Double_t cut[2] = {0.6, 0.7}; // !!! empirical !!! - - for (Int_t ista = 0; ista < fgkStat; ++ista) { - Int_t nvec = fVectors[ista].size(); - - for (Int_t iv = 0; iv < nvec; ++iv) { - CbmMuchTrack* vec = fVectors[ista][iv]; - const FairTrackParam* params = vec->GetParamFirst(); - Double_t dTx = params->GetTx() - params->GetX() / params->GetZ(); - Double_t dTy = params->GetTy() - params->GetY() / params->GetZ(); - if (TMath::Abs(dTx) > cut[0] || TMath::Abs(dTy) > cut[1]) vec->SetChiSq(-1.0); - } - - for (Int_t iv = nvec - 1; iv >= 0; --iv) { - CbmMuchTrack* vec = fVectors[ista][iv]; - if (vec->GetChiSq() < 0) { - delete fVectors[ista][iv]; - fVectors[ista].erase(fVectors[ista].begin() + iv); - } - } - cout << " Vectors after parameter check in station " << ista << ": " << nvec << " " << fVectors[ista].size() - << endl; - } -} -// ------------------------------------------------------------------------- - -// ----- Private method HighRes ---------------------------------------- -void CbmMuchFindVectors::HighRes() -{ - // High resolution processing (resolve ghost hits and make high resolution vectors) - - for (Int_t ista = 0; ista < fgkStat; ++ista) { - Int_t nvec = fVectors[ista].size(); - - for (Int_t iv = 0; iv < nvec; ++iv) { - CbmMuchTrack* vec = fVectors[ista][iv]; - Int_t nhits = vec->GetNofHits(), patt = 0, size0 = fVectorsHigh[ista].size(); - Double_t uu[fgkPlanes][2]; - - for (Int_t ih = 0; ih < nhits; ++ih) { - CbmMuchStrawHit* hit = (CbmMuchStrawHit*) fHits->UncheckedAt(vec->GetHitIndex(ih)); - Int_t lay = fGeoScheme->GetLayerIndex(hit->GetAddress()); - Int_t side = fGeoScheme->GetLayerSideIndex(hit->GetAddress()); - Int_t plane = lay * 2 + side; - uu[plane][0] = hit->GetU(); - uu[plane][1] = hit->GetDouble()[2]; - patt |= (1 << plane); - fUzi[plane][0] = hit->GetSegment(); - fUzi[plane][1] = vec->GetHitIndex(ih); - } - - // Number of hit combinations is 2 - // - left-right ambiguity resolution does not really work for doublets - Int_t nCombs = (patt & 1) ? 2 : 1, flag = 1, nok = nCombs - 1; - fFailed.clear(); - - for (Int_t icomb = -1; icomb < nCombs; icomb += 2) { - fUz[0][0] = (nCombs == 2) ? uu[0][0] + uu[0][1] * icomb : 0.0; - ProcessSingleHigh(ista, 1, patt, flag, nok, uu); - } - if (Int_t(fVectorsHigh[ista].size()) > size0) continue; // successful fit - // Failed fit - RemoveOutliers(ista, patt, uu); - - } // for (Int_t iv = 0; - } // for (Int_t ista = 0; - - MoveVectors(); // move vectors from one container to another, i.e. drop low resolution ones -} -// ------------------------------------------------------------------------- - -// ----- Private method ProcessDoubleHigh ------------------------------ -void CbmMuchFindVectors::ProcessSingleHigh(Int_t ista, Int_t plane, Int_t patt, Int_t flag, Int_t nok, - Double_t uu[fgkPlanes][2]) -{ - // Main processing engine for high resolution mode - // (recursively adds singlet hits to the vector) - - Double_t pars[4] = {0.0}; - const Double_t thresh = 10.0; // chi2-threshold - - // Number of hit combinations is 2 - Int_t nCombs = (patt & (1 << plane)) ? 2 : 1; - nok += (nCombs - 1); - - for (Int_t icomb = -1; icomb < nCombs; icomb += 2) { - fUz[plane][0] = (nCombs == 2) ? uu[plane][0] + uu[plane][1] * icomb : 0.0; - if (plane == fgkPlanes - 1 || nok == fMinHits && flag) { - // Straight line fit of the vector - Int_t patt1 = patt & ((1 << plane + 1) - 1); // apply mask - FindLine(patt1, pars); - Double_t chi2 = FindChi2(ista, patt1, pars); - /* - TString str; - str += patt1; - str = TString::BaseConvert(str,10,2); - cout << " *** Stat: " << ista << " " << plane << " " << str.CountChar('1') << " " << chi2 << " " - << pars[0] << " " << pars[1] << endl; - for (multimap<Double_t,Int_t>::reverse_iterator rit = fChi2Map.rbegin(); rit != fChi2Map.rend(); ++rit) - cout << rit->first << " "; - cout << endl; - */ - if (icomb > -1) flag = 0; - if (chi2 > fCutChi2) { - /* - Double_t qual = 0.0, c2sum = 0.0, outl = 0.0; - for (multimap<Double_t,Int_t>::reverse_iterator rit = fChi2Map.rbegin(); rit != fChi2Map.rend(); ++rit) { - if (rit->first > thresh) { outl += 1; c2sum += rit->first; } - else break; - } - qual = outl + TMath::Min(c2sum,999.) / 1000; - fFailed.insert(pair<Double_t,multimap<Double_t,Int_t> >(qual,fChi2Map)); - */ - Int_t lrbits = 0; - for (Int_t j = 0; j <= plane; ++j) { - if (!(patt1 & (1 << j))) continue; - if (fUz[j][0] > uu[j][0]) lrbits |= (1 << j); - } - fFailed.insert(pair<Int_t, multimap<Double_t, Int_t>>(lrbits, fChi2Map)); - continue; // too high chi2 - do not extend line - } - //if (plane + 1 < fgkPlanes) ProcessSingleHigh(ista, plane + 1, patt, flag, nok, uu); - if (plane + 1 < fgkPlanes) ProcessSingleHigh(ista, plane + 1, patt, 0, nok, uu); - else - AddVector(ista, patt, chi2, pars, - kFALSE); // add vector to the temporary container - } - else { - ProcessSingleHigh(ista, plane + 1, patt, flag, nok, uu); - } - } -} -// ------------------------------------------------------------------------- - -// ----- Private method MoveVectors ------------------------------------ -void CbmMuchFindVectors::MoveVectors() -{ - // Drop low-resolution vectors and move high-res. ones to their container - - for (Int_t ista = 0; ista < fgkStat; ++ista) { - Int_t nVecs = fVectors[ista].size(); - for (Int_t j = 0; j < nVecs; ++j) - delete fVectors[ista][j]; - fVectors[ista].clear(); - - nVecs = fVectorsHigh[ista].size(); - for (Int_t j = 0; j < nVecs; ++j) - fVectors[ista].push_back(fVectorsHigh[ista][j]); - } -} -// ------------------------------------------------------------------------- - -// ----- Private method RemoveClones ----------------------------------- -void CbmMuchFindVectors::RemoveClones() -{ - // Remove clone vectors (having at least 1 the same hit in each doublet (min. 4 the same hits)) - - Int_t nthr = 4, planes[20]; - - for (Int_t ista = 0; ista < fgkStat; ++ista) { - Int_t nvec = fVectors[ista].size(); - - // Do sorting according to "quality" - multimap<Double_t, CbmMuchTrack*> qMap; - multimap<Double_t, CbmMuchTrack*>::iterator it, it1; - - for (Int_t iv = 0; iv < nvec; ++iv) { - CbmMuchTrack* vec = fVectors[ista][iv]; - Double_t qual = vec->GetNofHits() + (99 - TMath::Min(vec->GetChiSq(), 99.0)) / 100; - qMap.insert(pair<Double_t, CbmMuchTrack*>(-qual, vec)); - } - - for (it = qMap.begin(); it != qMap.end(); ++it) { - CbmMuchTrack* vec = it->second; - if (vec->GetChiSq() < 0) continue; - for (Int_t j = 0; j < fgkPlanes; ++j) - planes[j] = -1; - - Int_t nhits = vec->GetNofHits(); - for (Int_t ih = 0; ih < nhits; ++ih) { - CbmMuchStrawHit* hit = (CbmMuchStrawHit*) fHits->UncheckedAt(vec->GetHitIndex(ih)); - Int_t lay = fGeoScheme->GetLayerIndex(hit->GetAddress()); - Int_t side = fGeoScheme->GetLayerSideIndex(hit->GetAddress()); - planes[lay * 2 + side] = vec->GetHitIndex(ih); - //cout << iv << " " << lay*2+side << " " << vec->GetHitIndex(ih) << endl; - } - - it1 = it; - for (++it1; it1 != qMap.end(); ++it1) { - CbmMuchTrack* vec1 = it1->second; - if (vec1->GetChiSq() < 0) continue; - Int_t nsame = 0, same[fgkPlanes / 2] = {0}; - - Int_t nhits1 = vec1->GetNofHits(); - //nthr = TMath::Min(nhits,nhits1) / 2; - //nthr = TMath::Min(nhits,nhits1) * 0.75; - for (Int_t ih = 0; ih < nhits1; ++ih) { - CbmMuchStrawHit* hit = (CbmMuchStrawHit*) fHits->UncheckedAt(vec1->GetHitIndex(ih)); - Int_t lay = fGeoScheme->GetLayerIndex(hit->GetAddress()); - Int_t side = fGeoScheme->GetLayerSideIndex(hit->GetAddress()); - if (planes[lay * 2 + side] >= 0) { - if (vec1->GetHitIndex(ih) == planes[lay * 2 + side]) same[lay] = 1; - //else same[lay] = 0; - } - } - for (Int_t lay = 0; lay < fgkPlanes / 2; ++lay) - nsame += same[lay]; - - if (nsame >= nthr) { - // Too many the same hits - Int_t clone = 0; - if (nhits > nhits1 + 0) clone = 1; - //else if (vec->GetChiSq() * 3.0 <= vec1->GetChiSq()) vec1->SetChiSq(-1.0); // the same number of hits on 2 tracks - else if (fgkPlanes > -8 && vec->GetChiSq() * 1 <= vec1->GetChiSq()) - clone = 1; // the same number of hits on 2 tracks - if (clone) { - vec1->SetChiSq(-1.0); - /* Debug - const FairTrackParam *params = vec->GetParamFirst(); - const FairTrackParam *params1 = vec1->GetParamFirst(); - if (vec1->GetFlag() < 2) cout << " Remove: " << vec->GetFlag() << " " << vec1->GetFlag() << " " << nhits << " " << nhits1 << " " << nsame << " " << vec->GetChiSq() << " " << vec1->GetChiSq() << " " << params->GetX() << " " << params1->GetX() << " " << params->GetY() << " " << params1->GetY() << endl; - // - Double_t dx = params->GetX() - params1->GetX(); - dx /= 0.2; - Double_t dy = params->GetY() - params1->GetY(); - dy /= 1.5; - Double_t chi2 = dx * dx + dy * dy; - if (chi2 < 10) vec1->SetChiSq(-1.0); - */ - } - } - } - } - - for (Int_t iv = nvec - 1; iv >= 0; --iv) { - CbmMuchTrack* vec = fVectors[ista][iv]; - if (vec->GetChiSq() < 0) { - delete fVectors[ista][iv]; - fVectors[ista].erase(fVectors[ista].begin() + iv); - } - } - cout << " Vectors after clones removed: " << nvec << " " << fVectors[ista].size() << endl; - - } // for (Int_t ista = 0; ista < fgkStat; -} -// ------------------------------------------------------------------------- - -// ----- Private method RemoveShorts ----------------------------------- -void CbmMuchFindVectors::RemoveShorts() -{ - // Remove short tracks - - Int_t nshort = fgkPlanes / 2, planes[20]; - - for (Int_t ista = 0; ista < fgkStat; ++ista) { - Int_t nvec = fVectors[ista].size(); - Int_t remove = 0; - - for (Int_t iv = 0; iv < nvec; ++iv) { - CbmMuchTrack* vec = fVectors[ista][iv]; - if (vec->GetChiSq() < 0) continue; - Int_t nhits = vec->GetNofHits(); - if (nhits != nshort) continue; - set<Int_t> overlap; - //multiset<Int_t> overlap1; - for (Int_t j = 0; j < fgkPlanes; ++j) - planes[j] = -1; - for (Int_t ih = 0; ih < nhits; ++ih) { - CbmMuchStrawHit* hit = (CbmMuchStrawHit*) fHits->UncheckedAt(vec->GetHitIndex(ih)); - Int_t lay = fGeoScheme->GetLayerIndex(hit->GetAddress()); - Int_t side = fGeoScheme->GetLayerSideIndex(hit->GetAddress()); - planes[lay * 2 + side] = vec->GetHitIndex(ih); - } - - for (Int_t iv1 = iv + 1; iv1 < nvec; ++iv1) { - CbmMuchTrack* vec1 = fVectors[ista][iv1]; - if (vec1->GetChiSq() < 0) continue; - Int_t nhits1 = vec1->GetNofHits(); - - // Compare hits - for (Int_t ih = 0; ih < nhits1; ++ih) { - CbmMuchStrawHit* hit = (CbmMuchStrawHit*) fHits->UncheckedAt(vec1->GetHitIndex(ih)); - Int_t lay = fGeoScheme->GetLayerIndex(hit->GetAddress()); - Int_t side = fGeoScheme->GetLayerSideIndex(hit->GetAddress()); - if (vec1->GetHitIndex(ih) == planes[lay * 2 + side] && planes[lay * 2 + side] >= 0) overlap.insert(ih); - } - //if (overlap.size() == nshort) { - if (overlap.size() > 0) { - // Hits are shared with other tracks - remove = 1; - break; - } - } // for (Int_t iv1 = iv + 1; - if (remove) vec->SetChiSq(-1.0); - } // for (Int_t iv = 0; iv < nvec; - - for (Int_t iv = nvec - 1; iv >= 0; --iv) { - CbmMuchTrack* vec = fVectors[ista][iv]; - if (vec->GetChiSq() < 0) { - delete fVectors[ista][iv]; - fVectors[ista].erase(fVectors[ista].begin() + iv); - } - } - cout << " Vectors after shorts removed: " << nvec << " " << fVectors[ista].size() << endl; - - } // for (Int_t ista = 0; -} -// ------------------------------------------------------------------------- - -// ----- Private method StoreVectors ----------------------------------- -void CbmMuchFindVectors::StoreVectors() -{ - // Store vectors (CbmMuchTracks) into TClonesArray - - Int_t ntrs = fTrackArray->GetEntriesFast(); - Int_t nHitsTot = fHits->GetEntriesFast(); - - for (Int_t ist = 0; ist < fgkStat; ++ist) { - set<Int_t> usedHits; - Int_t nvec = fVectors[ist].size(); - - for (Int_t iv = 0; iv < nvec; ++iv) { - CbmMuchTrack* tr = new ((*fTrackArray)[ntrs++]) CbmMuchTrack(*(fVectors[ist][iv])); - //cout << " Track: " << tr->GetNofHits() << endl; - //for (Int_t j = 0; j < tr->GetNofHits(); ++j) cout << j << " " << tr->GetHitIndex(j) << " " << fVectors[ist][iv]->GetHitIndex(j) << endl; - // Set hit flag (to check Lit tracking) - Int_t nhits = tr->GetNofHits(); - /* - for (Int_t j = 0; j < nhits; ++j) { - CbmMuchStrawHit *hit = (CbmMuchStrawHit*) fHits->UncheckedAt(tr->GetHitIndex(j)); - if (usedHits.find(tr->GetHitIndex(j)) == usedHits.end()) { - hit->SetFlag(ntrs-1); - usedHits.insert(tr->GetHitIndex(j)); - } else { - // Ugly interim solution for the tracking - create new hit - CbmMuchStrawHit *hitNew = new ((*fHits)[nHitsTot++]) CbmMuchStrawHit(*hit); - hitNew->SetFlag(ntrs-1); - usedHits.insert(nHitsTot-1); - } - } - */ - } - } -} -// ------------------------------------------------------------------------- - -// ----- Private method CountBits -------------------------------------- -//This is better when most bits in x are 0 -//It uses 3 arithmetic operations and one comparison/branch per "1" bit in x. -// Wikipedia "Hamming weight" -Int_t CbmMuchFindVectors::CountBits(Int_t x) -{ - - Int_t count; - for (count = 0; x; count++) - x &= x - 1; - return count; -} -// ------------------------------------------------------------------------- - -// ----- Private method MatchVectors ----------------------------------- -void CbmMuchFindVectors::MatchVectors() -{ - // Match vectors from 2 stations - - const Int_t iabs = 3; - CbmMuchMergeVectors* merger = (CbmMuchMergeVectors*) FairRun::Instance()->GetTask("MuchMergeVectors"); - TMatrixF matr = TMatrixF(5, 5); - TMatrixF unit(TMatrixF::kUnit, matr); - - for (Int_t ista = 0; ista < fgkStat; ++ista) { - Int_t nvec = fVectors[ista].size(); - - // Propagate vectors to the absorber face - for (Int_t iv = 0; iv < nvec; ++iv) { - CbmMuchTrack* vec = fVectors[ista][iv]; - FairTrackParam parFirst = *vec->GetParamFirst(); - Double_t zbeg = parFirst.GetZ(); - Double_t dz = fZabs0[iabs][0] - zbeg; - // Propagate params - parFirst.SetX(parFirst.GetX() + dz * parFirst.GetTx()); - parFirst.SetY(parFirst.GetY() + dz * parFirst.GetTy()); - parFirst.SetZ(parFirst.GetZ() + dz); - TMatrixFSym cov(5); - parFirst.CovMatrix(cov); - cov(4, 4) = 1.0; - TMatrixF ff = unit; - ff(2, 0) = ff(3, 1) = dz; - TMatrixF cf(cov, TMatrixF::kMult, ff); - TMatrixF fcf(ff, TMatrixF::kTransposeMult, cf); - cov.SetMatrixArray(fcf.GetMatrixArray()); - if (ista == 1) merger->PassAbsorber(ista + iabs * 2, fZabs0[iabs], fX0abs[iabs], parFirst, cov, 0); - cov.Invert(); // weight matrix - parFirst.SetCovMatrix(cov); - vec->SetParamLast(&parFirst); - } - } - - Int_t ista0 = 0, ista1 = 1; - vector<Int_t> matchOK[2]; - Int_t nvec0 = fVectors[ista0].size(), nvec1 = fVectors[ista1].size(); - matchOK[0].assign(nvec0, -1); - matchOK[1].assign(nvec1, -1); - - for (Int_t iv = 0; iv < nvec0; ++iv) { - CbmMuchTrack* tr1 = fVectors[ista0][iv]; - FairTrackParam parOk = *tr1->GetParamLast(); - FairTrackParam par1 = *tr1->GetParamLast(); - TMatrixFSym w1(5); - par1.CovMatrix(w1); - Float_t pars1[5] = {(Float_t) par1.GetX(), (Float_t) par1.GetY(), (Float_t) par1.GetTx(), (Float_t) par1.GetTy(), - 1.0}; - TMatrixF p1(5, 1, pars1); - TMatrixF wp1(w1, TMatrixF::kTransposeMult, p1); - - for (Int_t iv1 = 0; iv1 < nvec1; ++iv1) { - CbmMuchTrack* tr2 = fVectors[ista1][iv1]; - FairTrackParam par2 = *tr2->GetParamLast(); - TMatrixFSym w2(5); - par2.CovMatrix(w2); - TMatrixFSym w20 = w2; - Float_t pars2[5] = {(Float_t) par2.GetX(), (Float_t) par2.GetY(), (Float_t) par2.GetTx(), (Float_t) par2.GetTy(), - 1.0}; - TMatrixF p2(5, 1, pars2); - TMatrixF wp2(w2, TMatrixF::kTransposeMult, p2); - wp2 += wp1; - w2 += w1; - w2.Invert(); - TMatrixF p12(w2, TMatrixF::kTransposeMult, wp2); - - // Compute Chi2 - TMatrixF p122 = p12; - TMatrixF pMerge = p12; - p12 -= p1; - TMatrixF wDp1(w1, TMatrixF::kMult, p12); - TMatrixF chi21(p12, TMatrixF::kTransposeMult, wDp1); - p122 -= p2; - TMatrixF wDp2(w20, TMatrixF::kMult, p122); - TMatrixF chi22(p122, TMatrixF::kTransposeMult, wDp2); - Double_t c2 = chi21(0, 0) + chi22(0, 0); - //cout << " Chi2: " << chi21(0,0) << " " << chi22(0,0) << " " << c2 << endl; - if (c2 < 0 || c2 > fCutChi2 * 2) continue; - matchOK[0][iv] = matchOK[1][iv1] = 1; // match OK - // Merged track parameters - parOk.SetX(pMerge(0, 0)); - parOk.SetY(pMerge(1, 0)); - parOk.SetZ(par2.GetZ()); - parOk.SetTx(pMerge(2, 0)); - parOk.SetTy(pMerge(3, 0)); - parOk.SetCovMatrix(w2); - //AddTrack(ista0, tr1, tr2, it->first, it1->first, parOk, c2); // add track - //Int_t evNo = FairRun::Instance()->GetEventHeader()->GetMCEntryNumber(); - } - } - - for (Int_t ista = 0; ista < fgkStat; ++ista) { - Int_t nvec = fVectors[ista].size(); - - for (Int_t iv = nvec - 1; iv >= 0; --iv) { - if (matchOK[ista][iv] > 0) continue; - fVectors[ista].erase(fVectors[ista].begin() + iv); - } - } - - cout << " Vectors after matching: " << fVectors[0].size() << " " << fVectors[1].size() << endl; -} -// ------------------------------------------------------------------------- - -// ----- Private method RemoveOutliers --------------------------------- -void CbmMuchFindVectors::RemoveOutliers(Int_t ista, Int_t patt0, Double_t uu[fgkPlanes][2]) -{ - // Find line with the lowest number of outliers and smallest sum of their chi2 - // - remove outliers and refit - - const Double_t thresh = 6.0; // chi2-cut - Double_t qualmin = 99.0, qual = 0.0; - multimap<Int_t, multimap<Double_t, Int_t>>::iterator mit = fFailed.begin(), mit0 = mit; - Int_t patt = patt0, pattmin = patt0; - - for (; mit != fFailed.end(); ++mit) { - multimap<Double_t, Int_t>& chi2s = mit->second; - Double_t c2sum = 0.0, outl = 0.0; - patt = patt0; - - for (multimap<Double_t, Int_t>::reverse_iterator rit = chi2s.rbegin(); rit != chi2s.rend(); ++rit) { - if (rit->first <= thresh) break; - outl += 1; - c2sum += rit->first; - patt &= ~(1 << rit->second); - } - // Check doublets - Int_t nDouble = 0; - for (Int_t j = 0; j < fgkPlanes; j += 2) - if (patt & (3 << j)) ++nDouble; - else - break; - if (nDouble < fgkPlanes / 2) continue; - qual = outl + TMath::Min(c2sum, 999.) / 1000; - if (qual < qualmin) { - qualmin = qual; - mit0 = mit; - pattmin = patt; - } - } - - if (Int_t(qualmin) > 3) return; // too many outliers - - Int_t nCombs = (patt & 1) ? 2 : 1, flag = 1, nok = nCombs - 1; - - for (Int_t icomb = -1; icomb < nCombs; icomb += 2) { - fUz[0][0] = (nCombs == 2) ? uu[0][0] + uu[0][1] * icomb : 0.0; - //if (ichoice > 1 && nCombs > 1 && icomb != vecTmp.GetLR(0)) continue; - //ProcessSingleHigh(ichoice, 1, patt, 1, 1, uu, &vecTmp); - ProcessSingleHigh(ista, 1, pattmin, flag, nok, uu); - } -} -// ------------------------------------------------------------------------- - -ClassImp(CbmMuchFindVectors); diff --git a/reco/tracking/vector/CbmMuchFindVectors.h b/reco/tracking/vector/CbmMuchFindVectors.h deleted file mode 100644 index d1ddcbe7f48f98bdcd5fee0bd7017512ccecede6..0000000000000000000000000000000000000000 --- a/reco/tracking/vector/CbmMuchFindVectors.h +++ /dev/null @@ -1,121 +0,0 @@ -/* Copyright (C) 2014-2018 Veksler and Baldin Laboratory of High Energy Physics, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Alexander Zinchenko [committer] */ - -/** CbmMuchFindVectors.h - *@author A.Zinchenko <Alexander.Zinchenko@jinr.ru> - *@since 2014 - ** - ** Task class for vector finding in MUCH. - ** Input: TClonesArray of CbmMuchHit - ** Output: TClonesArray of CbmMuchTrack - ** - **/ - -#ifndef CBMMUCHFINDVECTORS_H_ -#define CBMMUCHFINDVECTORS_H_ 1 - -#include "CbmMuchGeoScheme.h" - -#include "FairTask.h" -#include "FairTrackParam.h" - -#include <TDecompLU.h> - -#include <map> -#include <set> -#include <vector> - -class CbmMuchTrack; -class TClonesArray; - -class CbmMuchFindVectors : public FairTask { -public: - /** Default constructor **/ - CbmMuchFindVectors(); - - /** Destructor **/ - virtual ~CbmMuchFindVectors(); - - /** Initialisation **/ - virtual InitStatus Init(); - - /** Task execution **/ - virtual void Exec(Option_t* opt); - - /** Finish at the end **/ - virtual void Finish(); - - /** SetParContainers **/ - virtual void SetParContainers(); - - /** Accessors **/ - Int_t GetNofTracks() { return fNofTracks; } - Int_t GetNofStat() const { return fgkStat; } - -private: - // Some constants - static const Int_t fgkStat = 2; // Number of stations - static const Int_t fgkPlanes = 8; // Number of straw planes per station - static const Int_t fgkPlanes2 = 16; // Number of straw planes in 2 stations - -private: - CbmMuchGeoScheme* fGeoScheme; // Geometry scheme - TClonesArray* fTrackArray; // Output array of CbmMuchVectors - Int_t fNofTracks; // Number of tracks created - TClonesArray* fHits; // Input array of CbmMuchHit - TClonesArray* fPoints; // Input array of CbmMuchHit - TClonesArray* fDigiMatches; // Input array of CbmMuchHit - Int_t fStatFirst; // First straw station No. - std::multimap<Int_t, Int_t> fHitPl[fgkStat][fgkPlanes2]; // hit indices on planes vs tube No - std::vector<CbmMuchTrack*> fVectors[fgkStat]; // track vectors for stations - std::vector<CbmMuchTrack*> fVectorsHigh[fgkStat]; // track vectors for stations (high resolution) - Double_t fUz[fgkPlanes2][3]; // hit float data - Double_t fUzi[fgkPlanes2][3]; // hit int data - Double_t fDz[fgkPlanes2]; // geometrical constants (Z-distances from layer 0) - Double_t fCosa[fgkPlanes2]; // geometrical constants (cos of stereo angles) - Double_t fSina[fgkPlanes2]; // geometrical constants (sin of stereo angles) - std::map<Int_t, TDecompLU*> fLus; // system matrices (for different hit layer patterns) - Double_t fErrU; // hit measurement error - Double_t fDiam; // tube diameter - Double_t fCutChi2; // Chi2-cut - Int_t fMinHits; // Min. number of hits on track to do fit - Double_t fZ0[fgkStat]; // Z-positions of the first layers - Double_t fRmin[fgkStat]; // inner radii of stations - Double_t fRmax[fgkStat]; // outer radii of stations - Double_t fDtubes[fgkStat][fgkPlanes2]; // max. tube difference between views - std::map<Int_t, TMatrixDSym*> fMatr; // system matrices (for different hit layer patterns) - std::vector<std::pair<Int_t, Int_t>> fHit2d[fgkStat][fgkPlanes2]; // Indx1,Indx2 of doublet hits - Double_t fZabs0[9][2]; // Z-positions of absorber faces - Double_t fX0abs[9]; // radiation lengths of the absorbers - std::multimap<Double_t, Int_t> fChi2Map; // chi2 vs plane - std::multimap<Int_t, std::multimap<Double_t, Int_t>> fFailed; //! failed fits - - void ComputeMatrix(); - void GetHits(); - void MakeVectors(); - void ProcessDouble(Int_t ista, Int_t lay2, Int_t patt, Int_t flag, Int_t tube0, Int_t segment0); - Bool_t IntersectViews(Int_t ista, Int_t curLay, Int_t indx1, Int_t indx2, Int_t patt); - void AddVector(Int_t ista, Int_t patt, Double_t chi2, Double_t* pars, Bool_t lowRes = kTRUE); - void SetTrackId(CbmMuchTrack* vec); - Bool_t SelDoubleId(Int_t indx1, Int_t indx2); - void FindLine(Int_t patt, Double_t* pars); - Double_t FindChi2(Int_t ista, Int_t patt, Double_t* pars); - void CheckParams(); - void HighRes(); - void ProcessSingleHigh(Int_t ista, Int_t plane, Int_t patt, Int_t flag, Int_t nok, Double_t uu[fgkPlanes][2]); - void MoveVectors(); - void RemoveClones(); - void RemoveShorts(); - void StoreVectors(); - Int_t CountBits(Int_t x); - void MatchVectors(); - void RemoveOutliers(Int_t ista, Int_t patt, Double_t uu[fgkPlanes][2]); - - CbmMuchFindVectors(const CbmMuchFindVectors&); - CbmMuchFindVectors& operator=(const CbmMuchFindVectors&); - - ClassDef(CbmMuchFindVectors, 0) -}; - -#endif diff --git a/reco/tracking/vector/CbmMuchFindVectorsGem.cxx b/reco/tracking/vector/CbmMuchFindVectorsGem.cxx deleted file mode 100644 index 4920d4c713f389578862a161b2e167baa7f66561..0000000000000000000000000000000000000000 --- a/reco/tracking/vector/CbmMuchFindVectorsGem.cxx +++ /dev/null @@ -1,1337 +0,0 @@ -/* Copyright (C) 2014-2019 Veksler and Baldin Laboratory of High Energy Physics, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Alexander Zinchenko [committer] */ - -/** CbmMuchFindVectorsGem.cxx - *@author A.Zinchenko <Alexander.Zinchenko@jinr.ru> - *@since 2014 - **/ -#include "CbmMuchFindVectorsGem.h" - -#include "CbmMCDataArray.h" -#include "CbmMCDataManager.h" -#include "CbmMuchCluster.h" -#include "CbmMuchDigiMatch.h" -#include "CbmMuchMergeVectors.h" -#include "CbmMuchModule.h" -#include "CbmMuchModuleGem.h" -#include "CbmMuchPixelHit.h" -#include "CbmMuchPoint.h" -#include "CbmMuchStation.h" -#include "CbmMuchTrack.h" -#include "CbmSetup.h" - -#include "FairEventHeader.h" -#include "FairRootManager.h" - -#include <TClonesArray.h> -#include <TGeoManager.h> -#include <TMath.h> -#include <TMatrixD.h> -#include <TMatrixFLazy.h> -#include <TVectorD.h> - -#include <iostream> - -using std::cout; -using std::endl; -using std::map; -using std::multimap; -using std::pair; -using std::set; -using std::vector; - -//FILE *lun = fopen("chi2.dat","w"); - -// ----- Default constructor ------------------------------------------- -CbmMuchFindVectorsGem::CbmMuchFindVectorsGem() - : FairTask("MuchFindVectorsGem") - , fGeoScheme(CbmMuchGeoScheme::Instance()) - , fVecPool(NULL) - , fTrackArray(NULL) - , fNofTracks(0) - , fHits(NULL) - , fClusters(NULL) - , fPoints(NULL) - , fDigiMatches(NULL) - , fTrdVectors(NULL) - , fStatFirst(-1) -//fCutChi2(40.0) -{ - for (Int_t i = 0; i < 9; ++i) - fCutChi2[i] = 12; // chi2/ndf = 6 for 3 hits - //for (Int_t i = 0; i < 9; ++i) fCutChi2[i] = 20; - //AZ fCutChi2[0] *= 2; -} -// ------------------------------------------------------------------------- - -// ----- Destructor ---------------------------------------------------- -CbmMuchFindVectorsGem::~CbmMuchFindVectorsGem() -{ - fTrackArray->Delete(); - fVecPool->Delete(); - - for (map<Int_t, TDecompLU*>::iterator it = fLus.begin(); it != fLus.end(); ++it) - delete it->second; -} -// ------------------------------------------------------------------------- - -// ----- Public method Init (abstract in base class) -------------------- -InitStatus CbmMuchFindVectorsGem::Init() -{ - - // Get and check FairRootManager - FairRootManager* ioman = FairRootManager::Instance(); - if (ioman == NULL) Fatal("Init", "RootManager not instantiated!"); - - // Create and register MuchTrack array (if necessary) - fTrackArray = static_cast<TClonesArray*>(ioman->GetObject("MuchVector")); - if (fTrackArray == NULL) { - fTrackArray = new TClonesArray("CbmMuchTrack", 100); - ioman->Register("MuchVector", "Much", fTrackArray, kTRUE); - } - else { - // MuchVector already exists (from CbmMuchFindVector task) - //Fatal("Init", "CbmMuchFindVectors should go after !!!"); - } - fVecPool = new TClonesArray("CbmMuchTrack", 1000); - - /* - CbmMuchFindHitsStraws *hitFinder = (CbmMuchFindHitsStraws*) - FairRun::Instance()->GetTask("CbmMuchFindHitsStraws"); - if (hitFinder == NULL) Fatal("CbmMuchFindTracks::Init", "CbmMuchFindHitsStraws not run!"); - fDiam = hitFinder->GetDiam(0); - */ - - fHits = static_cast<TClonesArray*>(ioman->GetObject("MuchPixelHit")); - fClusters = static_cast<TClonesArray*>(ioman->GetObject("MuchCluster")); - fDigiMatches = static_cast<TClonesArray*>(ioman->GetObject("MuchDigiMatch")); - fTrdVectors = static_cast<TClonesArray*>(ioman->GetObject("TrdVector")); - CbmMCDataManager* mcManager = (CbmMCDataManager*) ioman->GetObject("MCDataManager"); - if (NULL == mcManager) LOG(fatal) << GetName() << ": No CbmMCDataManager!"; - //fPoints = static_cast<TClonesArray*> (ioman->GetObject("MuchPoint")); - fPoints = mcManager->InitBranch("MuchPoint"); - - // Find first GEM station and get some geo constants - Int_t nSt = fGeoScheme->GetNStations(); - for (Int_t i = 0; i < nSt; ++i) { - CbmMuchStation* st = fGeoScheme->GetStation(i); - CbmMuchModule* mod = fGeoScheme->GetModule(i, 0, 0, 0); - fRmax[i] = 0; - if (mod->GetDetectorType() == 2) continue; - if (fStatFirst < 0) fStatFirst = CbmMuchAddress::GetStationIndex(st->GetDetectorId()); - //cout << " First station: " << fStatFirst << endl; - Int_t nLays = st->GetNLayers(); - fRmin[i - fStatFirst] = st->GetRmin(); - fRmax[i - fStatFirst] = st->GetRmax(); - for (Int_t lay = 0; lay < nLays; ++lay) { - CbmMuchLayer* layer = st->GetLayer(lay); - //Double_t phi = hitFinder->GetPhi(lay); - for (Int_t iside = 0; iside < 2; ++iside) { - CbmMuchLayerSide* side = layer->GetSide(iside); - Int_t plane = lay * 2 + iside; - fDz[plane] = side->GetZ(); - //fCosa[plane] = TMath::Cos(phi); - //fSina[plane] = TMath::Sin(phi); - if (plane == 0) fZ0[i - fStatFirst] = side->GetZ(); - fNsect[i - fStatFirst] = side->GetNModules() * 2; - /* - if (lay) { - fDtubes[i-fStatFirst][lay-1] = - fRmax[i-fStatFirst] * TMath::Tan (TMath::ASin(fSina[plane]) - TMath::ASin(fSina[plane-2])); - fDtubes[i-fStatFirst][lay-1] = TMath::Abs(fDtubes[i-fStatFirst][lay-1]) / fDiam + 10; - } - */ - } - } - } - for (Int_t i = fgkPlanes - 1; i >= 0; --i) { - fDz[i] -= fDz[0]; - //cout << fDz[i] << " "; - } - //cout << endl; - - // Get absorbers - TString tag, fileName; - CbmSetup::Instance()->GetGeoTag(kMuch, tag); - //CbmSetup::Instance()->GetGeoFileName(kMuch, fileName); - cout << " ******* MUCH tag ******** " << tag << endl; - tag.Prepend("much_"); - - Double_t dzAbs[9] = {0}, zAbs[9] = {0}, radlAbs[9] = {0}, xyzl[3] = {0}, xyzg[3] = {0}; - Int_t nAbs = 0; - TGeoVolume* vol = NULL; - TGeoNode* much = NULL; - - // Go to MUCH - gGeoManager->CdTop(); - TGeoNode* cave = gGeoManager->GetCurrentNode(); - for (Int_t iNode = 0; iNode < cave->GetNdaughters(); iNode++) { - TGeoNode* node = cave->GetDaughter(iNode); - TString name = node->GetName(); - if (name.Contains("much")) { - much = node; - gGeoManager->CdDown(iNode); - break; - } - } - - TGeoVolume* muchV = gGeoManager->GetVolume(tag); - Int_t ndaught = muchV->GetNdaughters(); - - // Loop over daughters - for (Int_t i = 0; i < ndaught; ++i) { - vol = muchV->GetNode(i)->GetVolume(); - if (!(TString(vol->GetName()).Contains("absorber"))) continue; - gGeoManager->CdDown(i); - nAbs = vol->GetNdaughters(); - //cout << " aaaaa " << nAbs << endl; - - for (Int_t iabs = 0; iabs < nAbs; ++iabs) { - TGeoVolume* block = vol->GetNode(iabs)->GetVolume(); - gGeoManager->CdDown(iabs); - TGeoVolume* abso = block->GetNode(0)->GetVolume(); - gGeoManager->CdDown(0); - //cout << gGeoManager->GetPath() << endl; - gGeoManager->LocalToMaster(xyzl, xyzg); - zAbs[iabs] = xyzg[2]; - //cout << abso->GetName() << " " << abso->GetShape()->GetName() << " " - // << ((TGeoBBox*)abso->GetShape())->GetDZ() << " " << xyzg[2] << endl; - dzAbs[iabs] = ((TGeoBBox*) abso->GetShape())->GetDZ(); - radlAbs[iabs] = abso->GetMaterial()->GetRadLen(); - fZabs0[iabs][0] = zAbs[iabs] - dzAbs[iabs]; - fZabs0[iabs][1] = zAbs[iabs] + dzAbs[iabs]; - fX0abs[iabs] = radlAbs[iabs]; - gGeoManager->CdUp(); - gGeoManager->CdUp(); - } - } - - // Combine 2 first absorbers into 1 - for (Int_t i = 1; i < nAbs; ++i) { - if (i == 1) fZabs0[i - 1][1] = fZabs0[i][1]; - else { - fZabs0[i - 1][0] = fZabs0[i][0]; - fZabs0[i - 1][1] = fZabs0[i][1]; - fX0abs[i - 1] = fX0abs[i]; - } - } - --nAbs; - fX0abs[nAbs] = 1.e9; // flag - - cout << " \n !!! MUCH Absorbers: " << nAbs << "\n Zbeg, Zend, X0:"; - for (Int_t j = 0; j < nAbs; ++j) - cout << " " << std::setprecision(4) << fZabs0[j][0] << ", " << fZabs0[j][1] << ", " << fX0abs[j] << ";"; - cout << endl << endl; - - // Station dependent errors - //Double_t errs[9] = {0.4, 0.6, 1.2, 1.7, 0}; - Double_t errs[9] = {0.6, 0.8, 1.2, 1.7, 0}; - for (Int_t j = 0; j < fgkStat; ++j) - fErrX[j] = fErrY[j] = errs[j]; - - ComputeMatrix(); // compute system matrices - - return kSUCCESS; -} -// ------------------------------------------------------------------------- - -// ----- SetParContainers ------------------------------------------------- -void CbmMuchFindVectorsGem::SetParContainers() {} -// ------------------------------------------------------------------------- - -// ----- Public method Exec -------------------------------------------- -void CbmMuchFindVectorsGem::Exec(Option_t* opt) -{ - - //fTrackArray->Delete(); - fVecPool->Delete(); - FairTask* strawHitFinder = FairRun::Instance()->GetTask("CbmMuchFindHitsStraws"); - if (strawHitFinder == NULL) fTrackArray->Delete(); - - for (Int_t i = 0; i < fgkStat; ++i) { - fVectors[i].clear(); - fSecVec[i].clear(); - } - - // Do all processing - - // Get hits - GetHits(); - - for (Int_t ista = fgkStat - 1; ista >= 0; --ista) { - // Build vectors - MakeVectors(ista); - - // Remove vectors with wrong orientation - // (using empirical cuts for omega muons at 8 GeV) - CheckParams(ista); - - // Match vectors from 2 stations - //MatchVectors(); - - // Remove clones - RemoveClones(ista); - } - - // Store vectors - StoreVectors(); -} -// ------------------------------------------------------------------------- - -// ----- Public method Finish ------------------------------------------ -void CbmMuchFindVectorsGem::Finish() -{ - fTrackArray->Delete(); - fVecPool->Delete(); - - for (map<Int_t, TDecompLU*>::iterator it = fLus.begin(); it != fLus.end(); ++it) - delete it->second; -} -// ------------------------------------------------------------------------- - -// ----- Private method ComputeMatrix ---------------------------------- -void CbmMuchFindVectorsGem::ComputeMatrix() -{ - // Compute system matrices for different hit plane patterns - - Double_t dz2[fgkPlanes]; - Bool_t onoff[fgkPlanes]; - - for (Int_t i = 0; i < fgkPlanes; ++i) { - dz2[i] = fDz[i] * fDz[i]; - onoff[i] = kTRUE; - } - - TMatrixD coef(4, 4); - Int_t pattMax = 1 << fgkPlanes, nDouble = 0, nTot = 0; - - // Loop over doublet patterns - for (Int_t ipat = 1; ipat < pattMax; ++ipat) { - - // Check if the pattern is valid: all doublets are active - nDouble = 0; - //AZ for (Int_t j = 0; j < fgkPlanes; j += 2) if (ipat & (3 << j)) ++nDouble; else break; - for (Int_t j = 0; j < fgkPlanes; j += 2) - if (ipat & (3 << j)) ++nDouble; - if (nDouble < fgkPlanes / 2 - 1) continue; // allow 2-hit vectors - ++nTot; - - for (Int_t j = 0; j < fgkPlanes; ++j) - onoff[j] = (ipat & (1 << j)); - - coef = 0.0; - for (Int_t i = 0; i < fgkPlanes; ++i) { - if (!onoff[i]) continue; - coef(0, 0) += 1; - coef(0, 1) += 0; - coef(0, 2) += fDz[i]; - coef(0, 3) += 0; - } - for (Int_t i = 0; i < fgkPlanes; ++i) { - if (!onoff[i]) continue; - coef(1, 0) += 0; - coef(1, 1) += 1; - coef(1, 2) += 0; - coef(1, 3) += fDz[i]; - } - for (Int_t i = 0; i < fgkPlanes; ++i) { - if (!onoff[i]) continue; - coef(2, 0) += fDz[i]; - coef(2, 1) += 0; - coef(2, 2) += dz2[i]; - coef(2, 3) += 0; - } - for (Int_t i = 0; i < fgkPlanes; ++i) { - if (!onoff[i]) continue; - coef(3, 0) += 0; - coef(3, 1) += fDz[i]; - coef(3, 2) += 0; - coef(3, 3) += dz2[i]; - } - - TDecompLU* lu = new TDecompLU(4); - lu->SetMatrix(coef); - lu->SetTol(0.1 * lu->GetTol()); - lu->Decompose(); - fLus.insert(pair<Int_t, TDecompLU*>(ipat, lu)); - TMatrixDSym cov(4); - cov.SetMatrixArray(coef.GetMatrixArray()); - cov.Invert(); // covar. matrix - fMatr.insert(pair<Int_t, TMatrixDSym*>(ipat, new TMatrixDSym(cov))); - TString buf = ""; - for (Int_t jp = 0; jp < fgkPlanes; ++jp) - buf += Bool_t(ipat & (1 << jp)); - Info("ComputeMatrix", " Determinant: %s %i %f", buf.Data(), ipat, coef.Determinant()); - if (ipat == 63) { - coef.Print(); - Info("ComputeMatrix", " Number of configurations: %i", nTot); - } - //cout << " Number of configurations: " << nTot << endl; } - cov *= (1.2 * 1.2); - cout << TMath::Sqrt(cov(0, 0)) << " " << TMath::Sqrt(cov(1, 1)) << " " << TMath::Sqrt(cov(2, 2)) << " " - << TMath::Sqrt(cov(3, 3)) << endl; - cov *= (1.7 * 1.7 / 1.2 / 1.2); - cout << TMath::Sqrt(cov(0, 0)) << " " << TMath::Sqrt(cov(1, 1)) << " " << TMath::Sqrt(cov(2, 2)) << " " - << TMath::Sqrt(cov(3, 3)) << endl; - } -} -// ------------------------------------------------------------------------- - -// ----- Private method GetHits ---------------------------------------- -void CbmMuchFindVectorsGem::GetHits() -{ - // Group hits according to their plane number - - for (Int_t ista = 0; ista < fgkStat; ++ista) { - for (Int_t i = 0; i < fgkPlanes; ++i) { - fHitPl[ista][i].clear(); - fHitX[ista][i].clear(); - } - //for (Int_t i = 0; i < fgkPlanes / 2; ++i) fHit2d[ista][i].clear(); - } - - Int_t nHits = fHits->GetEntriesFast(), nSelTu[fgkStat] = {0}, sel = 0; - for (Int_t i = 0; i < nHits; ++i) { - CbmMuchPixelHit* hit = (CbmMuchPixelHit*) fHits->UncheckedAt(i); - - //!!! For debug - select hits with certain track IDs - sel = 1; //SelectHitId(hit); - if (!sel) continue; - // - - Int_t detId = hit->GetAddress(); - CbmMuchModule* module = fGeoScheme->GetModuleByDetId(detId); - if (module->GetDetectorType() == 2) continue; // skip straw hits - UInt_t address = CbmMuchAddress::GetElementAddress(detId, kMuchModule); - Int_t station3 = CbmMuchAddress::GetStationIndex(address); // station - Int_t doublet = CbmMuchAddress::GetLayerIndex(address); // doublet - Int_t layer = CbmMuchAddress::GetLayerSideIndex(address); // layer in doublet - Int_t sector = CbmMuchAddress::GetModuleIndex(address); // sector - fHitPl[station3 - fStatFirst][doublet].insert(pair<Int_t, Int_t>(sector, i)); - fHitX[station3 - fStatFirst][doublet].insert(pair<Double_t, Int_t>(hit->GetX(), i)); - //cout << station3 << " " << doublet << " " << sector << endl; - //if (fErrU < 0) fErrU = hit->GetDu(); - if (sel) ++nSelTu[station3 - fStatFirst]; - } -} -// ------------------------------------------------------------------------- - -// ----- Private method SelectHitId ------------------------------------ -Bool_t CbmMuchFindVectorsGem::SelectHitId(const CbmMuchPixelHit* hit) -{ - // Select hits with certain track IDs (for debugging) - FIXME (it is for straws) - - Int_t nSel = 2, idSel[2] = {0, 1}, id = 0; - - for (Int_t i = 0; i < nSel; ++i) { - if (hit->GetFlag() % 2) { - //if (0) { - // Mirror hit - return kFALSE; - } - else { - CbmMuchDigiMatch* digiM = (CbmMuchDigiMatch*) fDigiMatches->UncheckedAt(hit->GetRefId()); - Int_t np = digiM->GetNofLinks(); - for (Int_t ip = 0; ip < np; ++ip) { - //CbmMuchPoint* point = (CbmMuchPoint*) fPoints->UncheckedAt(digiM->GetLink(ip).GetIndex()); - CbmLink link = digiM->GetLink(ip); - //CbmMuchPoint* point = (CbmMuchPoint*) - //fPoints->Get(0,digiM->GetLink(ip).GetEntry(),digiM->GetLink(ip).GetIndex()); - CbmMuchPoint* point = (CbmMuchPoint*) fPoints->Get(0, link.GetEntry(), link.GetIndex()); - id = point->GetTrackID(); - if (id == idSel[i]) return kTRUE; - } - } - } - return kFALSE; -} -// ------------------------------------------------------------------------- - -// ----- Private method GetDowns --------------------------------------- -Int_t CbmMuchFindVectorsGem::GetDowns(Int_t ista, vector<pair<Double_t, Double_t>>& vecDowns) -{ - // Get extrapolated coordinates of vectors from the downstream station - - Int_t nvec = 0, straw = 0; - if (ista != fgkStat - 1 && fRmax[ista + 1] < 1.0) { - nvec = fTrackArray->GetEntriesFast(); - straw = 1; - } - else if (ista != fgkStat - 1) - nvec = fVectors[ista + 1].size(); - - for (Int_t i = 0; i < nvec; ++i) { - CbmMuchTrack* tr = (straw) ? (CbmMuchTrack*) fTrackArray->UncheckedAt(i) : fVectors[ista + 1][i]; - if (tr->GetUniqueID() != ista + 1) continue; - FairTrackParam parFirst = *tr->GetParamFirst(); - Double_t zbeg = parFirst.GetZ(); - Double_t dz = fZ0[ista] + fDz[fgkPlanes - 1] - zbeg; - // Propagate params - Double_t x = parFirst.GetX() + dz * parFirst.GetTx(); - Double_t y = parFirst.GetY() + dz * parFirst.GetTy(); - vecDowns.push_back(pair<Double_t, Double_t>(x, y)); - } - return vecDowns.size(); -} -// ------------------------------------------------------------------------- - -// ----- Private method MakeVectors ------------------------------------ -void CbmMuchFindVectorsGem::MakeVectors(Int_t ista0) -{ - // Make vectors for stations - either all or using windows defined - // by vectors from the next (downstream) station - - const Double_t window0 = 5.0; //7.0; //10.0; - //const Double_t window0 = 7.5; //10.0; - Int_t nvec = 0; - - //for (Int_t ista = 0; ista < fgkStat; ++ista) { - //for (Int_t ista = fgkStat-1; ista >= 0; --ista) { - for (Int_t ista = ista0; ista >= ista0; --ista) { - fVectors[ista].clear(); - CbmMuchPixelHit* hit = NULL; - - // Get vectors from the downstream station - if (fRmax[ista] < 1.0) continue; - //Int_t lay2 = 0, patt = 0, flag = 0, nhits = fHitPl[ista][lay2].size(); - Int_t lay2 = fgkPlanes / 2 - 1, patt = 0, flag = 0, nhits = fHitPl[ista][lay2].size(); - cout << " Hits: " << ista << " " << lay2 << " " << nhits << endl; - vector<pair<Double_t, Double_t>> vecDowns; - //nvec = GetDowns(ista, vecDowns); - multimap<Double_t, Int_t>::iterator mit, mitb, mite, mit1; - Double_t window = window0; - //if (ista == 0) window /= 1.5; - - //if (ista == fgkStat - 1) { // no constraints for st. 4 - if (ista >= fgkStat - 2) { // no constraints for st. 3 and 4 - // All-GEM configuration - //if (CbmSetup::Instance()->IsActive(kTrd)) { - if (0) { - // Use TRD vectors for guidance - nvec = GetTrdVectors(vecDowns); - } - else { - // No TRD present - nvec = 2; // account for missing last layer - vecDowns.push_back(pair<Double_t, Double_t>(0.0, 0.0)); - vecDowns.push_back(pair<Double_t, Double_t>(0.0, 0.0)); - window = 999.0; - } - } - else - nvec = GetDowns(ista, vecDowns); - Int_t indsta0 = 1 + ista * fgkPlanes; - - for (Int_t iv = 0; iv < nvec; ++iv) { - if (ista > 1 && iv == 1) --lay2; // take last but one layer - Double_t xv = vecDowns[iv].first, yv = vecDowns[iv].second; - mitb = fHitX[ista][lay2].lower_bound(xv - window); // lower X-window edge - mite = fHitX[ista][lay2].upper_bound(xv + window); // upper X-window edge - /* - if (mitb == mite && ista > 1) { - // If no hit in the last layer of the last or last but one stations - take last but one layer - --lay2; - mitb = fHitX[ista][lay2].lower_bound(xv-window); // lower X-window edge - mite = fHitX[ista][lay2].upper_bound(xv+window); // upper X-window edge - } - */ - mit1 = mite; - Int_t inWin = 0; - Double_t ywin1 = yv - window, ywin2 = yv + window; - - for (mit = mitb; mit != mite; ++mit) { - if (mit1 != mite) { - fHitX[ista][lay2].erase(mit1); // remove processed hit - mit1 = mite; - } - Int_t indx = mit->second; - hit = (CbmMuchPixelHit*) fHits->UncheckedAt(indx); - if (hit->GetY() < ywin1 || hit->GetY() > ywin2) continue; - //Int_t lay = hit->GetPlaneId() - 1 - ista * fgkPlanes; - Int_t lay = hit->GetPlaneId() - indsta0; - fXy[lay][0] = hit->GetX(); - fXy[lay][1] = hit->GetY(); - //fXy[lay][2] = hit->GetDx(); - //fXy[lay][3] = hit->GetDy(); - fXy[lay][2] = TMath::Max(hit->GetDx(), fErrX[ista]); - fXy[lay][3] = TMath::Max(hit->GetDy(), fErrY[ista]); - fXy[lay][4] = hit->GetZ(); - fXyi[lay][0] = CbmMuchAddress::GetModuleIndex(hit->GetAddress()); // sector No. - fXyi[lay][1] = indx; - //patt = lay + 1; - patt = (1 << lay); - //cout << lay << " " << hit->GetX() << " " << hit->GetY() << " " << hit->GetZ() << " " << endl; - //ProcessPlane(ista, lay2+1, patt, flag); - ProcessPlane(ista, lay2 - 1, patt, flag); - mit1 = mit; - inWin = 1; - } - - if (inWin == 0 && ista == 1) { - //if (0) { - // No hits inside window - increase window size and repeat (for one station only) - window = window0 * 1.5; - mitb = fHitX[ista][lay2].lower_bound(xv - window); // lower X-window edge - mite = fHitX[ista][lay2].upper_bound(xv + window); // upper X-window edge - mit1 = mite; - - for (mit = mitb; mit != mite; ++mit) { - //AZ if (mit1 != mite) fHitX[ista][lay2].erase(mit1); // remove processed hit - if (mit1 != mite) { - fHitX[ista][lay2].erase(mit1); - break; - } // remove processed hit - mit1 = mite; - Int_t indx = mit->second; - hit = (CbmMuchPixelHit*) fHits->UncheckedAt(indx); - if (hit->GetY() < yv - window || hit->GetY() > yv + window) continue; - Int_t lay = hit->GetPlaneId() - indsta0; - fXy[lay][0] = hit->GetX(); - fXy[lay][1] = hit->GetY(); - //fXy[lay][2] = hit->GetDx(); - //fXy[lay][3] = hit->GetDy(); - fXy[lay][2] = TMath::Max(hit->GetDx(), fErrX[ista]); - fXy[lay][3] = TMath::Max(hit->GetDy(), fErrY[ista]); - fXy[lay][4] = hit->GetZ(); - fXyi[lay][0] = CbmMuchAddress::GetModuleIndex(hit->GetAddress()); // sector No. - fXyi[lay][1] = indx; - //patt = lay + 1; - patt = (1 << lay); - //cout << lay << " " << hit->GetX() << " " << hit->GetY() << " " << hit->GetZ() << " " << endl; - //ProcessPlane(ista, lay2+1, patt, flag); - ProcessPlane(ista, lay2 - 1, patt, flag); - mit1 = mit; - } - window = window0; - } - } // for (Int_t iv = 0; - } -} -// ------------------------------------------------------------------------- - -// ----- Private method GetTrdVectors ---------------------------------- -Int_t CbmMuchFindVectorsGem::GetTrdVectors(vector<pair<Double_t, Double_t>>& vecDowns) -{ - // Get extrapolated coordinates of vectors from the TRD - - Int_t nvec = fTrdVectors->GetEntriesFast(); - - for (Int_t i = 0; i < nvec; ++i) { - CbmMuchTrack* tr = (CbmMuchTrack*) fTrdVectors->UncheckedAt(i); - FairTrackParam parFirst = *tr->GetParamFirst(); - Double_t zbeg = parFirst.GetZ(); - Double_t dz = fZ0[fgkStat - 1] + fDz[fgkPlanes - 1] - zbeg; - // Propagate params - Double_t x = parFirst.GetX() + dz * parFirst.GetTx(); - Double_t y = parFirst.GetY() + dz * parFirst.GetTy(); - vecDowns.push_back(pair<Double_t, Double_t>(x, y)); - } - return vecDowns.size(); -} -// ------------------------------------------------------------------------- - -// ----- Private method ProcessPlane ----------------------------------- -void CbmMuchFindVectorsGem::ProcessPlane(Int_t ista, Int_t lay2, Int_t patt, Int_t flag) -{ - // Main processing engine (recursively adds layer hits to the vector) - - //const Double_t cut[2] = {0.8, 0.8}; // !!! empirical !!! - //const Double_t cut[2] = {0.5, 0.5}; // !!! empirical !!! - //AZ const Double_t cut[2][2] = {{0.5, 0.5},{0.6,0.6}}; // !!! empirical !!! - //const Double_t cut[2][2] = {{0.5,0.6}, {0.5,0.6}}; // !!! empirical !!! - //const Double_t cut[2][2] = {{0.45,0.55}, {0.45,0.55}}; // !!! empirical !!! - const Double_t cut[2][2] = {{0.4, 0.5}, {0.4, 0.5}}; // !!! empirical !!! - - Double_t pars[4] = {0.0}; - Int_t nhits = fHitPl[ista][lay2].size(); - //Int_t sec0 = (patt & (1 << lay2*2-1)) ? fXyi[lay2*2-1][0] : fXyi[lay2*2-2][0]; - Int_t sec0 = (patt & (1 << lay2 * 2 + 3)) ? fXyi[lay2 * 2 + 3][0] : fXyi[lay2 * 2 + 2][0]; - multimap<Int_t, Int_t>::iterator it; - pair<multimap<Int_t, Int_t>::iterator, multimap<Int_t, Int_t>::iterator> ret; - Int_t indsta0 = 1 + ista * fgkPlanes; - - for (Int_t dsec = -1; dsec < 2; ++dsec) { - Int_t isec = sec0 + dsec; - if (isec < 0) isec += fNsect[ista]; - else if (isec == fNsect[ista]) - isec = 0; - - ret = fHitPl[ista][lay2].equal_range(isec); - for (it = ret.first; it != ret.second; ++it) { - Int_t indx = it->second, sector = it->first; - - CbmMuchPixelHit* hit = (CbmMuchPixelHit*) fHits->UncheckedAt(indx); - //Int_t lay = hit->GetPlaneId() - 1 - ista * fgkPlanes; - Int_t lay = hit->GetPlaneId() - indsta0; - fXy[lay][0] = hit->GetX(); - fXy[lay][1] = hit->GetY(); - //fXy[lay][2] = hit->GetDx(); - //fXy[lay][3] = hit->GetDy(); - fXy[lay][2] = TMath::Max(hit->GetDx(), fErrX[ista]); - fXy[lay][3] = TMath::Max(hit->GetDy(), fErrY[ista]); - fXy[lay][4] = hit->GetZ(); - - // Check slopes - //AZ Int_t lay0 = fgkPlanes - 1; - //AZ if (!(patt & (1 << lay0))) --lay0;; - Int_t lay0 = TString::Itoa(patt, 2).Length() - 1; - Double_t dx = fXy[lay][0] - fXy[lay0][0]; - Double_t dz = fXy[lay][4] - fXy[lay0][4]; - Double_t dTx = TMath::Abs(dx / dz - fXy[lay][0] / fXy[lay][4]); - if (TMath::Abs(dTx) > cut[0][TMath::Min(ista, 1)]) continue; - Double_t dy = fXy[lay][1] - fXy[lay0][1]; - Double_t dTy = TMath::Abs(dy / dz - fXy[lay][1] / fXy[lay][4]); - if (TMath::Abs(dTy) > cut[1][TMath::Min(ista, 1)]) continue; - - fXyi[lay][0] = sector; - fXyi[lay][1] = indx; - - // Clear bits - patt &= ~(1 << lay2 * 2); - patt &= ~(1 << lay2 * 2 + 1); - // Set bit - patt |= (1 << lay); - //cout << lay << " " << patt << " " << hit->GetX() << " " << hit->GetY() << " " << hit->GetZ() << " " << endl; - - //if (lay2 < fgkPlanes / 2 - 1) ProcessPlane(ista, lay2+1, patt, flag); - if (lay2 > 0) ProcessPlane(ista, lay2 - 1, patt, flag); - else { - // Straight line fit of the vector - FindLine(patt, pars); - Double_t chi2 = FindChi2(ista, patt, pars); - //cout << " *** Stat: " << ista << " " << id << " " << indx1 << " " << indx2 << " " << chi2 << " " << pars[0] << " " << pars[1] << endl; - if (chi2 <= fCutChi2[ista]) AddVector(ista, patt, chi2, pars); // add vector to the temporary container - } - } // for (it = ret.first; - } // for (Int_t dsec = -1; dsec < 2; -} -// ------------------------------------------------------------------------- - -// ----- Private method AddVector -------------------------------------- -void CbmMuchFindVectorsGem::AddVector(Int_t ista, Int_t patt, Double_t chi2, Double_t* pars) -{ - // Add vector to the temporary container (as a MuchTrack) - - Bool_t refit = kFALSE; //kTRUE; - TMatrixDSym cov(4); - - if (refit) { - // Refit line with individual hit errors - //cout << " Before: " << chi2 << endl; - Refit(patt, chi2, pars, cov); - //cout << " After: " << chi2 << endl; - } - else { - cov = *fMatr[patt]; - cov *= (fErrX[ista] * fErrX[ista]); // the same error in X and Y - } - cov.ResizeTo(5, 5); - cov(4, 4) = 1.0; - - Int_t npool = fVecPool->GetEntriesFast(); - //CbmMuchTrack *track = new ((*fVecPool)[npool]) CbmMuchTrack(); - CbmMuchTrack* track = (CbmMuchTrack*) fVecPool->ConstructedAt(npool); - track->SetChiSq(chi2); - FairTrackParam par(pars[0], pars[1], fZ0[ista], pars[2], pars[3], 0.0, cov); - track->SetParamFirst(&par); - par.SetZ(fZ0[ista] + fDz[fgkPlanes - 1]); - par.SetX(pars[0] + fDz[fgkPlanes - 1] * pars[2]); - par.SetY(pars[1] + fDz[fgkPlanes - 1] * pars[3]); - track->SetParamLast(&par); - track->SetUniqueID(ista); // just to pass the value - - for (Int_t ipl = 0; ipl < fgkPlanes; ++ipl) { - if (!(patt & (1 << ipl))) continue; - track->AddHit(fXyi[ipl][1], kMUCHPIXELHIT); - } - Int_t ndf = (track->GetNofHits() > 2) ? track->GetNofHits() * 2 - 4 : 1; - track->SetNDF(ndf); - SetTrackId(track); // set track ID as its flag - fVectors[ista].push_back(track); -} -// ------------------------------------------------------------------------- - -// ----- Private method SetTrackId ------------------------------------- -void CbmMuchFindVectorsGem::SetTrackId(CbmMuchTrack* vec) -{ - // Set vector ID as its flag (maximum track ID of its poins) - - map<Int_t, Int_t> ids; - Int_t nhits = vec->GetNofHits(), id = 0; - - for (Int_t ih = 0; ih < nhits; ++ih) { - CbmMuchPixelHit* hit = (CbmMuchPixelHit*) fHits->UncheckedAt(vec->GetHitIndex(ih)); - CbmMuchCluster* clus = (CbmMuchCluster*) fClusters->UncheckedAt(hit->GetRefId()); - Int_t nDigis = clus->GetNofDigis(); - for (Int_t j = 0; j < nDigis; ++j) { - CbmMuchDigiMatch* digiM = (CbmMuchDigiMatch*) fDigiMatches->UncheckedAt(clus->GetDigi(j)); - Int_t np = digiM->GetNofLinks(); - for (Int_t ip = 0; ip < np; ++ip) { - //CbmMuchPoint* point = (CbmMuchPoint*) fPoints->UncheckedAt(digiM->GetLink(0).GetIndex()); - //cout << nhits << " " << ih << " " << j << " " << nDigis << " " << ip << " " << np << " " << fPoints->GetEntriesFast() << " " << fHits->GetEntriesFast() << endl; - CbmLink link = digiM->GetLink(ip); - //cout << nhits << " " << ih << " " << j << " " << nDigis << " " << ip << " " << np << " " << fPoints->Size(link.GetFile(),link.GetEntry()) << " " << fHits->GetEntriesFast() << endl; - //CbmMuchPoint* point = (CbmMuchPoint*) fPoints->UncheckedAt(digiM->GetLink(ip).GetIndex()); - CbmMuchPoint* point = (CbmMuchPoint*) fPoints->Get(0, link.GetEntry(), link.GetIndex()); - id = point->GetTrackID(); - //if (np > 1) cout << ip << " " << id << endl; - if (ids.find(id) == ids.end()) ids.insert(pair<Int_t, Int_t>(id, 1)); - else - ++ids[id]; - } - //if (np > 1) { cout << " digi " << digiM->GetNofLinks() << " " << ista << " " << hit->GetX() << " " << hit->GetY() << endl; exit(0); } - } - } - Int_t maxim = -1, idmax = -9; - for (map<Int_t, Int_t>::iterator it = ids.begin(); it != ids.end(); ++it) { - if (it->second > maxim) { - maxim = it->second; - idmax = it->first; - } - } - // Set vector ID as its flag - vec->SetFlag(idmax); -} -// ------------------------------------------------------------------------- - -// ----- Private method FindLine --------------------------------------- -void CbmMuchFindVectorsGem::FindLine(Int_t patt, Double_t* pars) -{ - // Fit of hits to the straight line - - // Solve system of linear equations - Bool_t ok = kFALSE, onoff; - TVectorD b(4); - for (Int_t i = 0; i < fgkPlanes; ++i) { - onoff = patt & (1 << i); - if (!onoff) continue; - b[0] += fXy[i][0]; - b[1] += fXy[i][1]; - b[2] += fXy[i][0] * fDz[i]; - b[3] += fXy[i][1] * fDz[i]; - } - - //lu.Print(); - TVectorD solve = fLus[patt]->Solve(b, ok); - //TVectorD solve = lu.TransSolve(b, ok); - //lu.Print(); - for (Int_t i = 0; i < 4; ++i) - pars[i] = solve[i]; - //for (Int_t i = 0; i < 4; ++i) { cout << pars[i] << " "; if (i == 3) cout << endl; } - //Double_t y1 = cosa / sina * (uz[1][0] * cosa - uz[0][0]) + uz[1][0] * sina; - //Double_t y2 = -cosa / sina * (uz[2][0] * cosa - uz[0][0]) - uz[2][0] * sina; - //cout << " OK " << ok << " " << y1 << " " << y2 << endl; -} -// ------------------------------------------------------------------------- - -// ----- Private method FindChi2 --------------------------------------- -Double_t CbmMuchFindVectorsGem::FindChi2(Int_t ista, Int_t patt, Double_t* pars) -{ - // Compute chi2 of the fit - - Double_t chi2 = 0, x = 0, y = 0; - Bool_t onoff; - - for (Int_t i = 0; i < fgkPlanes; ++i) { - onoff = patt & (1 << i); - if (!onoff) continue; - x = pars[0] + pars[2] * fDz[i]; - y = pars[1] + pars[3] * fDz[i]; - Double_t dx = (x - fXy[i][0]) / fErrX[ista]; - Double_t dy = (y - fXy[i][1]) / fErrY[ista]; - chi2 += dx * dx; - chi2 += dy * dy; - } - //cout << " Chi2 = " << chi2 << endl; - return chi2; -} -// ------------------------------------------------------------------------- - -// ----- Private method CheckParams ------------------------------------ -void CbmMuchFindVectorsGem::CheckParams(Int_t ista0) -{ - // Remove vectors with wrong orientation - // using empirical cuts for omega muons at 8 Gev - - //AZ const Double_t cut[2] = {0.6, 0.6}; // !!! empirical !!! - const Double_t cut[2] = {0.7, 0.7}; // !!! empirical !!! - - //AZ for (Int_t ista = 0; ista < fgkStat; ++ista) { - for (Int_t ista = ista0; ista <= ista0; ++ista) { - Int_t nvec = fVectors[ista].size(); - - for (Int_t iv = 0; iv < nvec; ++iv) { - CbmMuchTrack* vec = fVectors[ista][iv]; - const FairTrackParam* params = vec->GetParamFirst(); - Double_t dTx = params->GetTx() - params->GetX() / params->GetZ(); - if (TMath::Abs(dTx) > cut[0]) vec->SetChiSq(-1.0); - else { - Double_t dTy = params->GetTy() - params->GetY() / params->GetZ(); - if (TMath::Abs(dTy) > cut[1]) vec->SetChiSq(-1.0); - } - } - - for (Int_t iv = nvec - 1; iv >= 0; --iv) { - CbmMuchTrack* vec = fVectors[ista][iv]; - if (vec->GetChiSq() < 0) fVectors[ista].erase(fVectors[ista].begin() + iv); - } - cout << " Vectors after parameter check in station " << ista << ": " << nvec << " " << fVectors[ista].size() - << endl; - - nvec = fVectors[ista].size(); - for (Int_t iv = 0; iv < nvec; ++iv) { - CbmMuchTrack* vec = fVectors[ista][iv]; - CbmMuchPixelHit* hit = (CbmMuchPixelHit*) fHits->UncheckedAt(vec->GetHitIndex(0)); - UInt_t address = hit->GetAddress(); - Int_t isec = CbmMuchAddress::GetModuleIndex(address); // sector - fSecVec[ista].insert(pair<Int_t, CbmMuchTrack*>(isec, vec)); - } - } -} -// ------------------------------------------------------------------------- - -// ----- Private method HighRes ---------------------------------------- -/* -void CbmMuchFindVectorsGem::HighRes() -{ - // High resolution processing (resolve ghost hits and make high resolution vectors) - - for (Int_t ista = 0; ista < fgkStat; ++ista) { - Int_t nvec = fVectors[ista].size(); - - for (Int_t iv = 0; iv < nvec; ++iv) { - CbmMuchTrack *vec = fVectors[ista][iv]; - Int_t nhits = vec->GetNofHits(), patt = 0; - Double_t uu[fgkPlanes][2]; - - for (Int_t ih = 0; ih < nhits; ++ih) { - CbmMuchPixelHit *hit = (CbmMuchPixelHit*) fHits->UncheckedAt(vec->GetHitIndex(ih)); - Int_t lay = fGeoScheme->GetLayerIndex(hit->GetAddress()); - Int_t side = fGeoScheme->GetLayerSideIndex(hit->GetAddress()); - Int_t plane = lay*2+side; - uu[plane][0] = hit->GetU(); - uu[plane][1] = hit->GetDouble()[2]; - patt |= (1 << plane); - fUzi[plane][0] = hit->GetSegment(); - fUzi[plane][1] = vec->GetHitIndex(ih); - } - - // Number of hit combinations is 2 - // - left-right ambiguity resolution does not really work for doublets - Int_t nCombs = (patt & 1) ? 2 : 1, flag = 1, nok = nCombs - 1; - - for (Int_t icomb = -1; icomb < nCombs; icomb += 2) { - fUz[0][0] = (nCombs == 2) ? uu[0][0] + uu[0][1] * icomb : 0.0; - ProcessSingleHigh(ista, 1, patt, flag, nok, uu); - } - - } // for (Int_t iv = 0; - } // for (Int_t ista = 0; - - MoveVectors(); // move vectors from one container to another, i.e. drop low resolution ones - -} -*/ -// ------------------------------------------------------------------------- - -// ----- Private method ProcessDoubleHigh ------------------------------ -/* -void CbmMuchFindVectorsGem::ProcessSingleHigh(Int_t ista, Int_t plane, Int_t patt, Int_t flag, - Int_t nok, Double_t uu[fgkPlanes][2]) -{ - // Main processing engine for high resolution mode - // (recursively adds singlet hits to the vector) - - Double_t pars[4] = {0.0}; - - // Number of hit combinations is 2 - Int_t nCombs = (patt & (1 << plane)) ? 2 : 1; - nok += (nCombs - 1); - - for (Int_t icomb = -1; icomb < nCombs; icomb += 2) { - fUz[plane][0] = (nCombs == 2) ? uu[plane][0] + uu[plane][1] * icomb : 0.0; - if (plane == fgkPlanes - 1 || nok == fMinHits && flag) { - // Straight line fit of the vector - Int_t patt1 = patt & ((1 << plane + 1) - 1); // apply mask - FindLine(patt1, pars); - Double_t chi2 = FindChi2(ista, patt1, pars); - //cout << " *** Stat: " << ista << " " << plane << " " << chi2 << " " << pars[0] << " " << pars[1] << endl; - if (icomb > -1) flag = 0; - if (chi2 > fCutChi2[ista]) continue; // too high chi2 - do not extend line - //if (plane + 1 < fgkPlanes) ProcessSingleHigh(ista, plane + 1, patt, flag, nok, uu); - if (plane + 1 < fgkPlanes) ProcessSingleHigh(ista, plane + 1, patt, 0, nok, uu); - else AddVector(ista, patt, chi2, pars, kFALSE); // add vector to the temporary container - } else { - ProcessSingleHigh(ista, plane + 1, patt, flag, nok, uu); - } - } - -} -*/ -// ------------------------------------------------------------------------- - -// ----- Private method RemoveClones ----------------------------------- -void CbmMuchFindVectorsGem::RemoveClones(Int_t ista0) -{ - // Remove clone vectors (having at least 1 the same hit) - - Int_t nthr = 2, planes[20]; - //Int_t nthr = 1, planes[20]; - pair<multimap<Int_t, CbmMuchTrack*>::iterator, multimap<Int_t, CbmMuchTrack*>::iterator> ret; - multimap<Int_t, CbmMuchTrack*>::iterator itsec; - - //AZ for (Int_t ista = 0; ista < fgkStat; ++ista) { - for (Int_t ista = ista0; ista <= ista0; ++ista) { - // Process according to sector number of the first hit in vector - Int_t nvec = fVectors[ista].size(); - - for (Int_t isec = 0; isec < fNsect[ista]; ++isec) { - ret = fSecVec[ista].equal_range(isec); - // Do sorting according to "quality" - multimap<Double_t, CbmMuchTrack*> qMap; - multimap<Double_t, CbmMuchTrack*>::iterator it, it1; - - for (itsec = ret.first; itsec != ret.second; ++itsec) { - CbmMuchTrack* vec = itsec->second; - Double_t qual = vec->GetNofHits() + (99 - TMath::Min(vec->GetChiSq(), 99.0)) / 100; - qMap.insert(pair<Double_t, CbmMuchTrack*>(-qual, vec)); - } - - for (it = qMap.begin(); it != qMap.end(); ++it) { - CbmMuchTrack* vec = it->second; - if (vec->GetChiSq() < 0) continue; - for (Int_t j = 0; j < fgkPlanes; ++j) - planes[j] = -1; - - Int_t nhits = vec->GetNofHits(); - for (Int_t ih = 0; ih < nhits; ++ih) { - CbmMuchPixelHit* hit = (CbmMuchPixelHit*) fHits->UncheckedAt(vec->GetHitIndex(ih)); - Int_t lay = fGeoScheme->GetLayerIndex(hit->GetAddress()); - Int_t side = fGeoScheme->GetLayerSideIndex(hit->GetAddress()); - planes[lay * 2 + side] = vec->GetHitIndex(ih); - //cout << iv << " " << lay*2+side << " " << vec->GetHitIndex(ih) << endl; - } - - it1 = it; - for (++it1; it1 != qMap.end(); ++it1) { - CbmMuchTrack* vec1 = it1->second; - if (vec1->GetChiSq() < 0) continue; - Int_t nsame = 0, same[fgkPlanes / 2] = {0}; - - Int_t nhits1 = vec1->GetNofHits(); - //nthr = TMath::Min(nhits,nhits1) / 2; - //nthr = TMath::Min(nhits,nhits1) * 0.75; - for (Int_t ih = 0; ih < nhits1; ++ih) { - CbmMuchPixelHit* hit = (CbmMuchPixelHit*) fHits->UncheckedAt(vec1->GetHitIndex(ih)); - Int_t lay = fGeoScheme->GetLayerIndex(hit->GetAddress()); - Int_t side = fGeoScheme->GetLayerSideIndex(hit->GetAddress()); - if (planes[lay * 2 + side] >= 0) { - if (vec1->GetHitIndex(ih) == planes[lay * 2 + side]) same[lay] = 1; - //else same[lay] = 0; - } - } - for (Int_t lay = 0; lay < fgkPlanes / 2; ++lay) - nsame += same[lay]; - - if (nsame >= nthr) { - // Too many the same hits - Int_t clone = 0; - if (nhits > nhits1 + 0) clone = 1; - //else if (vec->GetChiSq() * 1 <= vec1->GetChiSq()) clone = 1; // the same number of hits on 2 tracks - else if (vec->GetChiSq() * 1.5 <= vec1->GetChiSq()) - clone = 1; // the same number of hits on 2 tracks - if (clone) vec1->SetChiSq(-1.0); - } - } - } // for (it = qMap.begin(); - } // for (Int_t isec = 0; isec < fNsect[ista]; - - for (Int_t iv = nvec - 1; iv >= 0; --iv) { - CbmMuchTrack* vec = fVectors[ista][iv]; - if (vec->GetChiSq() < 0) fVectors[ista].erase(fVectors[ista].begin() + iv); - } - cout << " Vectors after clones removed: " << nvec << " " << fVectors[ista].size() << endl; - - } // for (Int_t ista = 0; ista < fgkStat; -} -// ------------------------------------------------------------------------- - -// ----- Private method StoreVectors ----------------------------------- -void CbmMuchFindVectorsGem::StoreVectors() -{ - // Store vectors (CbmMuchTracks) into TClonesArray - - Int_t ntrs = fTrackArray->GetEntriesFast(); - Int_t nHitsTot = fHits->GetEntriesFast(); - - for (Int_t ist = 0; ist < fgkStat; ++ist) { - //set<Int_t> usedHits; - Int_t nvec = fVectors[ist].size(); - - for (Int_t iv = 0; iv < nvec; ++iv) { - CbmMuchTrack* tr = new ((*fTrackArray)[ntrs++]) CbmMuchTrack(*(fVectors[ist][iv])); - //cout << " Track: " << tr->GetNofHits() << endl; - //for (Int_t j = 0; j < tr->GetNofHits(); ++j) cout << j << " " << tr->GetHitIndex(j) << " " << fVectors[ist][iv]->GetHitIndex(j) << endl; - // Set hit flag (to check Lit tracking) - Int_t nhits = tr->GetNofHits(); - /* - for (Int_t j = 0; j < nhits; ++j) { - CbmMuchStrawHit *hit = (CbmMuchStrawHit*) fHits->UncheckedAt(tr->GetHitIndex(j)); - if (usedHits.find(tr->GetHitIndex(j)) == usedHits.end()) { - hit->SetFlag(ntrs-1); - usedHits.insert(tr->GetHitIndex(j)); - } else { - // Ugly interim solution for the tracking - create new hit - CbmMuchStrawHit *hitNew = new ((*fHits)[nHitsTot++]) CbmMuchStrawHit(*hit); - hitNew->SetFlag(ntrs-1); - usedHits.insert(nHitsTot-1); - } - } - */ - } - } -} -// ------------------------------------------------------------------------- - -// ----- Private method CountBits -------------------------------------- -//This is better when most bits in x are 0 -//It uses 3 arithmetic operations and one comparison/branch per "1" bit in x. -// Wikipedia "Hamming weight" -Int_t CbmMuchFindVectorsGem::CountBits(Int_t x) -{ - - Int_t count; - for (count = 0; x; count++) - x &= x - 1; - return count; -} -// ------------------------------------------------------------------------- - -// ----- Private method Refit ------------------------------------------ -void CbmMuchFindVectorsGem::Refit(Int_t patt, Double_t& chi2, Double_t* pars, TMatrixDSym& cov) -{ - // Refit line with individual hit errors - - Double_t dz2[fgkPlanes], errx2[fgkPlanes], erry2[fgkPlanes]; - Bool_t onoff[fgkPlanes]; - - for (Int_t i = 0; i < fgkPlanes; ++i) { - dz2[i] = fDz[i] * fDz[i]; - onoff[i] = kTRUE; - } - - TMatrixD coef(4, 4); - - for (Int_t j = 0; j < fgkPlanes; ++j) { - onoff[j] = (patt & (1 << j)); - if (!onoff[j]) continue; - errx2[j] = fXy[j][2] * fXy[j][2]; - erry2[j] = fXy[j][3] * fXy[j][3]; - } - - coef = 0.0; - for (Int_t i = 0; i < fgkPlanes; ++i) { - if (!onoff[i]) continue; - coef(0, 0) += 1 / errx2[i]; - coef(0, 1) += 0; - coef(0, 2) += fDz[i] / errx2[i]; - coef(0, 3) += 0; - } - for (Int_t i = 0; i < fgkPlanes; ++i) { - if (!onoff[i]) continue; - coef(1, 0) += 0; - coef(1, 1) += 1 / erry2[i]; - coef(1, 2) += 0; - coef(1, 3) += fDz[i] / erry2[i]; - } - for (Int_t i = 0; i < fgkPlanes; ++i) { - if (!onoff[i]) continue; - coef(2, 0) += fDz[i] / errx2[i]; - coef(2, 1) += 0; - coef(2, 2) += dz2[i] / errx2[i]; - coef(2, 3) += 0; - } - for (Int_t i = 0; i < fgkPlanes; ++i) { - if (!onoff[i]) continue; - coef(3, 0) += 0; - coef(3, 1) += fDz[i] / erry2[i]; - coef(3, 2) += 0; - coef(3, 3) += dz2[i] / erry2[i]; - } - - /* - TDecompLU *lu = new TDecompLU(4); - lu->SetMatrix(coef); - lu->SetTol(0.1*lu->GetTol()); - lu->Decompose(); - */ - TDecompLU lu(4); - lu.SetMatrix(coef); - lu.SetTol(0.1 * lu.GetTol()); - lu.Decompose(); - //fLus.insert(pair<Int_t,TDecompLU*>(ipat,lu)); - - TVectorD b(4); - for (Int_t i = 0; i < fgkPlanes; ++i) { - if (!onoff[i]) continue; - b[0] += fXy[i][0] / errx2[i]; - b[1] += fXy[i][1] / erry2[i]; - b[2] += fXy[i][0] * fDz[i] / errx2[i]; - b[3] += fXy[i][1] * fDz[i] / erry2[i]; - } - - Bool_t ok = kFALSE; - //TVectorD solve = fLus[patt]->Solve(b, ok); - //TVectorD solve = lu->Solve(b, ok); - TVectorD solve = lu.Solve(b, ok); - for (Int_t i = 0; i < 4; ++i) - pars[i] = solve[i]; - - cov.SetMatrixArray(coef.GetMatrixArray()); - cov.Invert(); // covar. matrix - - // Compute Chi2 - Double_t x = 0, y = 0; - chi2 = 0; - - for (Int_t i = 0; i < fgkPlanes; ++i) { - if (!onoff[i]) continue; - x = pars[0] + pars[2] * fDz[i]; - y = pars[1] + pars[3] * fDz[i]; - Double_t dx = (x - fXy[i][0]) / fXy[i][2]; - Double_t dy = (y - fXy[i][1]) / fXy[i][3]; - chi2 += dx * dx; - chi2 += dy * dy; - } - //cout << " Chi2 = " << chi2 << endl; -} -// ------------------------------------------------------------------------- - -// ----- Private method MatchVectors ----------------------------------- -void CbmMuchFindVectorsGem::MatchVectors() -{ - // Match vectors from 2 stations - - const Int_t iabs = 1; - CbmMuchMergeVectors* merger = (CbmMuchMergeVectors*) FairRun::Instance()->GetTask("MuchMergeVectors"); - TMatrixF matr = TMatrixF(5, 5); - TMatrixF unit(TMatrixF::kUnit, matr); - - for (Int_t ista = 0; ista < fgkStat; ++ista) { - Int_t nvec = fVectors[ista].size(); - - // Propagate vectors to the absorber face - for (Int_t iv = 0; iv < nvec; ++iv) { - CbmMuchTrack* vec = fVectors[ista][iv]; - FairTrackParam parFirst = *vec->GetParamFirst(); - Double_t zbeg = parFirst.GetZ(); - Double_t dz = fZabs0[iabs][0] - zbeg; - // Propagate params - parFirst.SetX(parFirst.GetX() + dz * parFirst.GetTx()); - parFirst.SetY(parFirst.GetY() + dz * parFirst.GetTy()); - parFirst.SetZ(parFirst.GetZ() + dz); - TMatrixFSym cov(5); - parFirst.CovMatrix(cov); - cov(4, 4) = 1.0; - TMatrixF ff = unit; - ff(2, 0) = ff(3, 1) = dz; - TMatrixF cf(cov, TMatrixF::kMult, ff); - TMatrixF fcf(ff, TMatrixF::kTransposeMult, cf); - cov.SetMatrixArray(fcf.GetMatrixArray()); - if (ista == 1) merger->PassAbsorber(ista + iabs * 2, fZabs0[iabs], fX0abs[iabs], parFirst, cov, 0); - cov.Invert(); // weight matrix - parFirst.SetCovMatrix(cov); - vec->SetParamLast(&parFirst); - } - } - - Int_t ista0 = 0, ista1 = 1; - vector<Int_t> matchOK[2]; - Int_t nvec0 = fVectors[ista0].size(), nvec1 = fVectors[ista1].size(); - matchOK[0].assign(nvec0, -1); - matchOK[1].assign(nvec1, -1); - - for (Int_t iv = 0; iv < nvec0; ++iv) { - CbmMuchTrack* tr1 = fVectors[ista0][iv]; - FairTrackParam parOk = *tr1->GetParamLast(); - FairTrackParam par1 = *tr1->GetParamLast(); - TMatrixFSym w1(5); - par1.CovMatrix(w1); - Float_t pars1[5] = {(Float_t) par1.GetX(), (Float_t) par1.GetY(), (Float_t) par1.GetTx(), (Float_t) par1.GetTy(), - 1.0}; - TMatrixF p1(5, 1, pars1); - TMatrixF wp1(w1, TMatrixF::kTransposeMult, p1); - - for (Int_t iv1 = 0; iv1 < nvec1; ++iv1) { - CbmMuchTrack* tr2 = fVectors[ista1][iv1]; - FairTrackParam par2 = *tr2->GetParamLast(); - TMatrixFSym w2(5); - par2.CovMatrix(w2); - TMatrixFSym w20 = w2; - Float_t pars2[5] = {(Float_t) par2.GetX(), (Float_t) par2.GetY(), (Float_t) par2.GetTx(), (Float_t) par2.GetTy(), - 1.0}; - TMatrixF p2(5, 1, pars2); - TMatrixF wp2(w2, TMatrixF::kTransposeMult, p2); - wp2 += wp1; - w2 += w1; - w2.Invert(); - TMatrixF p12(w2, TMatrixF::kTransposeMult, wp2); - - // Compute Chi2 - TMatrixF p122 = p12; - TMatrixF pMerge = p12; - p12 -= p1; - TMatrixF wDp1(w1, TMatrixF::kMult, p12); - TMatrixF chi21(p12, TMatrixF::kTransposeMult, wDp1); - p122 -= p2; - TMatrixF wDp2(w20, TMatrixF::kMult, p122); - TMatrixF chi22(p122, TMatrixF::kTransposeMult, wDp2); - Double_t c2 = chi21(0, 0) + chi22(0, 0); - //cout << " Chi2: " << chi21(0,0) << " " << chi22(0,0) << " " << c2 << endl; - if (c2 < 0 || c2 > fCutChi2[0]) continue; - matchOK[0][iv] = matchOK[1][iv1] = 1; // match OK - // Merged track parameters - parOk.SetX(pMerge(0, 0)); - parOk.SetY(pMerge(1, 0)); - parOk.SetZ(par2.GetZ()); - parOk.SetTx(pMerge(2, 0)); - parOk.SetTy(pMerge(3, 0)); - parOk.SetCovMatrix(w2); - //AddTrack(ista0, tr1, tr2, it->first, it1->first, parOk, c2); // add track - //Int_t evNo = FairRun::Instance()->GetEventHeader()->GetMCEntryNumber(); - } - } - - for (Int_t ista = 0; ista < fgkStat; ++ista) { - Int_t nvec = fVectors[ista].size(); - - for (Int_t iv = nvec - 1; iv >= 0; --iv) { - if (matchOK[ista][iv] > 0) continue; - fVectors[ista].erase(fVectors[ista].begin() + iv); - } - } - - cout << " Vectors after matching: " << fVectors[0].size() << " " << fVectors[1].size() << endl; -} -// ------------------------------------------------------------------------- - -// ------ Public method GetAbsorbers ----------------------------------- -Int_t CbmMuchFindVectorsGem::GetAbsorbers(Double_t zabs[9][2], Double_t* x0abs) -{ - // Get information about absorbers - - Int_t nabs = 0; - - while (fX0abs[nabs] < 1.e+8) { - zabs[nabs][0] = fZabs0[nabs][0]; - zabs[nabs][1] = fZabs0[nabs][1]; - x0abs[nabs] = fX0abs[nabs]; - ++nabs; - } - return nabs; -} - -// ------------------------------------------------------------------------- - -ClassImp(CbmMuchFindVectorsGem); diff --git a/reco/tracking/vector/CbmMuchFindVectorsGem.h b/reco/tracking/vector/CbmMuchFindVectorsGem.h deleted file mode 100644 index 1d25306da3cce0a42fd0e210c16dee0052660eb7..0000000000000000000000000000000000000000 --- a/reco/tracking/vector/CbmMuchFindVectorsGem.h +++ /dev/null @@ -1,125 +0,0 @@ -/* Copyright (C) 2014-2018 Veksler and Baldin Laboratory of High Energy Physics, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Alexander Zinchenko [committer] */ - -/** CbmMuchFindVectorsGem.h - *@author A.Zinchenko <Alexander.Zinchenko@jinr.ru> - *@since 2014 - ** - ** Task class for vector finding in MUCH GEMs. - ** Input: TClonesArray of CbmMuchHit - ** Output: TClonesArray of CbmMuchTrack - ** - **/ - -#ifndef CBMMUCHFINDVECTORSGEM_H_ -#define CBMMUCHFINDVECTORSGEM_H_ 1 - -#include "CbmMuchGeoScheme.h" - -#include "FairTask.h" -#include "FairTrackParam.h" - -#include <TDecompLU.h> - -#include <map> -#include <set> -#include <vector> - -class CbmMuchPixelHit; -class CbmMuchTrack; -class CbmMCDataArray; -class TClonesArray; - -class CbmMuchFindVectorsGem : public FairTask { -public: - /** Default constructor **/ - CbmMuchFindVectorsGem(); - - /** Destructor **/ - virtual ~CbmMuchFindVectorsGem(); - - /** Initialisation **/ - virtual InitStatus Init(); - - /** Task execution **/ - virtual void Exec(Option_t* opt); - - /** Finish at the end **/ - virtual void Finish(); - - /** SetParContainers **/ - virtual void SetParContainers(); - - /** Accessors **/ - Int_t GetNofTracks() { return fNofTracks; }; - Int_t GetNofStat() const { return fgkStat; } - - // Return info about absorbers - Int_t GetAbsorbers(Double_t zabs[9][2], Double_t* x0abs); - -private: - // Some constants - //static const Int_t fgkStat = 2; // Number of stations - 2 GEMs - static const Int_t fgkStat = 4; // Number of stations - 4 GEMs - static const Int_t fgkPlanes = 6; // Number of GEM planes per station - -private: - CbmMuchGeoScheme* fGeoScheme; // Geometry scheme - TClonesArray* fTrackArray; // Output array of CbmMuchVectors - TClonesArray* fVecPool; // Transient array of CbmMuchVectors (instead of heap) - Int_t fNofTracks; // Number of tracks created - TClonesArray* fHits; // Input array of CbmMuchHit - TClonesArray* fClusters; // Input array of CbmMuchCluster - TClonesArray* fDigiMatches; // Input array of CbmMatch - TClonesArray* fTrdVectors; // Input array of CbmMuchTrack - CbmMCDataArray* fPoints; // Input array of CbmMuchPoint - Int_t fStatFirst; // First straw station No. - std::multimap<Int_t, Int_t> fHitPl[fgkStat][fgkPlanes]; // hit indices on planes vs tube No - std::multimap<Double_t, Int_t> fHitX[fgkStat][fgkPlanes]; // hit indices on planes vs X-coord. - std::vector<CbmMuchTrack*> fVectors[fgkStat]; // track vectors for stations - //std::vector<CbmMuchTrack*> fVectorsHigh[fgkStat]; // track vectors for stations (high resolution) - Double_t fXy[fgkPlanes][5]; // hit float data - Double_t fXyi[fgkPlanes][3]; // hit int data - Double_t fDz[fgkPlanes]; // geometrical constants (Z-distances from layer 0) - std::map<Int_t, TDecompLU*> fLus; // system matrices (for different hit layer patterns) - Double_t fErrX[9]; // hit measurement error in X - Double_t fErrY[9]; // hit measurement error in Y - Double_t fCutChi2[9]; // Chi2-cuts for each station - Double_t fZ0[fgkStat]; // Z-positions of the first layers - Double_t fRmin[fgkStat]; // inner radii of stations - Double_t fRmax[fgkStat]; // outer radii of stations - Int_t fNsect[fgkStat]; // number of sectors per layer - //Double_t fDtubes[fgkStat][fgkPlanes]; // max. tube difference between views - std::map<Int_t, TMatrixDSym*> fMatr; // system matrices (for different hit layer patterns) - std::multimap<Int_t, CbmMuchTrack*> fSecVec[fgkStat]; // to arrange vectors according to sectors - Double_t fZabs0[9][2]; // Z-positions of absorber faces - Double_t fX0abs[9]; // radiation lengths of the absorbers - - //std::vector<pair<Int_t,Int_t> > fHit2d[fgkStat][fgkPlanes/2]; // Indx1,Indx2 of doublet hits - - void ComputeMatrix(); - void GetHits(); - Bool_t SelectHitId(const CbmMuchPixelHit* hit); - Int_t GetDowns(Int_t ista, std::vector<std::pair<Double_t, Double_t>>& vecDowns); - void MakeVectors(Int_t ista); - Int_t GetTrdVectors(std::vector<std::pair<Double_t, Double_t>>& vecDowns); - void ProcessPlane(Int_t ista, Int_t lay2, Int_t patt, Int_t flag); - void AddVector(Int_t ista, Int_t patt, Double_t chi2, Double_t* pars); - void SetTrackId(CbmMuchTrack* vec); - void FindLine(Int_t patt, Double_t* pars); - Double_t FindChi2(Int_t ista, Int_t patt, Double_t* pars); - void CheckParams(Int_t ista); - void RemoveClones(Int_t ista); - void StoreVectors(); - Int_t CountBits(Int_t x); - void Refit(Int_t patt, Double_t& chi2, Double_t* pars, TMatrixDSym& cov); - void MatchVectors(); - - CbmMuchFindVectorsGem(const CbmMuchFindVectorsGem&); - CbmMuchFindVectorsGem& operator=(const CbmMuchFindVectorsGem&); - - ClassDef(CbmMuchFindVectorsGem, 0) -}; - -#endif diff --git a/reco/tracking/vector/CbmMuchFindVectorsQa.cxx b/reco/tracking/vector/CbmMuchFindVectorsQa.cxx deleted file mode 100644 index 41a584e848275a2bd99b409a4175b579bc8087d4..0000000000000000000000000000000000000000 --- a/reco/tracking/vector/CbmMuchFindVectorsQa.cxx +++ /dev/null @@ -1,758 +0,0 @@ -/* Copyright (C) 2014-2018 Veksler and Baldin Laboratory of High Energy Physics, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Alexander Zinchenko [committer] */ - -/** CbmMuchFindVectorsQa.cxx - *@author A.Zinchenko <Alexander.Zinchenko@jinr.ru> - *@since 2014 - **/ -#include "CbmMuchFindVectorsQa.h" - -#include "CbmMuchCluster.h" -#include "CbmMuchDigiMatch.h" -#include "CbmMuchFindHitsStraws.h" -#include "CbmMuchFindVectors.h" -#include "CbmMuchModule.h" -#include "CbmMuchPixelHit.h" -#include "CbmMuchPoint.h" -#include "CbmMuchStation.h" -#include "CbmMuchStrawHit.h" -#include "CbmMuchTrack.h" - -#include "FairEventHeader.h" -#include "FairRootManager.h" -#include "FairRunAna.h" - -#include <TClonesArray.h> -#include <TF1.h> -#include <TH1D.h> -#include <TH2D.h> -#include <TMath.h> -#include <TROOT.h> - -#include <iostream> - -using std::cout; -using std::endl; -using std::map; -using std::multiset; -using std::pair; -using std::set; - -// ----- Default (stabdard) constructor -------------------------------- -CbmMuchFindVectorsQa::CbmMuchFindVectorsQa() - : FairTask("MuchFindVectorsQA") - , fGeoScheme(CbmMuchGeoScheme::Instance()) - , fStatFirst(-1) - , fNstat(0) -{ -} -// ------------------------------------------------------------------------- - -// ----- Destructor ---------------------------------------------------- -CbmMuchFindVectorsQa::~CbmMuchFindVectorsQa() {} -// ------------------------------------------------------------------------- - -// ----- Public method Init (abstract in base class) -------------------- -InitStatus CbmMuchFindVectorsQa::Init() -{ - - // Get and check FairRootManager - FairRootManager* ioman = FairRootManager::Instance(); - if (ioman == NULL) Fatal("CbmMuchFindTracksQA::Init", "RootManager not instantiated!"); - - //CbmMuchFindHitsStraws *hitFinder = (CbmMuchFindHitsStraws*) - //FairRun::Instance()->GetTask("CbmMuchFindHitsStraws"); - //if (hitFinder == NULL) Fatal("CbmMuchFindTracks::Init", "CbmMuchFindHitsStraws not run!"); - - fVectors = static_cast<TClonesArray*>(ioman->GetObject("MuchVector")); - fMCTracks = static_cast<TClonesArray*>(ioman->GetObject("MCTrack")); - fPoints = static_cast<TClonesArray*>(ioman->GetObject("MuchPoint")); - fHits = static_cast<TClonesArray*>(ioman->GetObject("MuchStrawHit")); - fHitsGem = static_cast<TClonesArray*>(ioman->GetObject("MuchPixelHit")); - fDigis = static_cast<TClonesArray*>(ioman->GetObject("MuchStrawDigi")); - fDigisGem = static_cast<TClonesArray*>(ioman->GetObject("MuchDigi")); - fDigiMatches = static_cast<TClonesArray*>(ioman->GetObject("MuchStrawDigiMatch")); - fDigiMatchesGem = static_cast<TClonesArray*>(ioman->GetObject("MuchDigiMatch")); - fClusters = static_cast<TClonesArray*>(ioman->GetObject("MuchCluster")); - - // Get straw system configuration - Int_t nSt = fGeoScheme->GetNStations(); - - for (Int_t i = 0; i < nSt; ++i) { - CbmMuchStation* st = fGeoScheme->GetStation(i); - CbmMuchModule* mod = fGeoScheme->GetModule(i, 0, 0, 0); - Int_t stat = CbmMuchAddress::GetStationIndex(st->GetDetectorId()); - if (mod->GetDetectorType() == 2 && fStatFirst < 0) fStatFirst = stat; - ++fNstat; - Int_t nLays = st->GetNLayers(); - fNdoubl[stat] = nLays; - - for (Int_t lay = 0; lay < nLays; ++lay) { - CbmMuchLayer* layer = st->GetLayer(lay); - - for (Int_t iside = 0; iside < 2; ++iside) { - CbmMuchLayerSide* side = layer->GetSide(iside); - Int_t plane = lay * 2 + iside; - fZpos[stat][plane] = side->GetZ(); - } - } - } - if (fStatFirst < 0) fStatFirst = 99; // all GEM stations - - // Create directory for histograms - TDirectory* dir = new TDirectory("muchQA", "", ""); - dir->cd(); - - BookHistos(); - - return kSUCCESS; -} -// ------------------------------------------------------------------------- - -// ----- SetParContainers ------------------------------------------------- -void CbmMuchFindVectorsQa::SetParContainers() {} -// ------------------------------------------------------------------------- - -// ----- Private method BookHistos ------------------------------------- -void CbmMuchFindVectorsQa::BookHistos() -{ - // Book histograms - - fhNvec = new TH1D*[fNstat]; - fhNdoubl = new TH1D*[fNstat]; - fhNhits = new TH1D*[fNstat]; - fhNhitsOk = new TH1D*[fNstat]; - fhChi2 = new TH1D*[fNstat]; - fhNgood = new TH1D*[fNstat]; - fhNghost = new TH1D*[fNstat]; - fhChi2ok = new TH1D*[fNstat]; - fhChi2bad = new TH1D*[fNstat]; - fhDx = new TH1D*[fNstat]; - fhDy = new TH1D*[fNstat]; - fhDtx = new TH1D*[fNstat]; - fhDty = new TH1D*[fNstat]; - fhIds = new TH1D*[fNstat]; - fhIdVsEv = new TH2D*[fNstat]; - fhDtxAll = new TH1D*[fNstat]; - fhDtyAll = new TH1D*[fNstat]; - fhDtxOk = new TH1D*[fNstat]; - fhDtyOk = new TH1D*[fNstat]; - fhShort = new TH1D*[fNstat]; - fhOverlap = new TH2D*[fNstat]; - fhChi2mat = new TH1D*[fNstat]; - fhMatchMult = new TH1D*[fNstat]; - fhOccup = new TH1D*[fNstat]; - //fhSim = new TH1D*[fNstat]; - //fhRec = new TH1D*[fNstat]; - fhDx12 = new TH2D*[fNstat]; - fhDx23 = new TH2D*[fNstat]; - fhDy12 = new TH2D*[fNstat]; - fhDy23 = new TH2D*[fNstat]; - - for (Int_t ist = 0; ist < fNstat; ++ist) { - Int_t stat = ist; - fhNvec[ist] = new TH1D(Form("hNvec%i", stat), Form("Number of vectors in station %i", stat), 200, 0, 1000); - fhNdoubl[ist] = - new TH1D(Form("hNdoubl%i", stat), Form("Number of tubes in lay. 1 in station %i", stat), 200, 0, 200); - fhNhits[ist] = new TH1D(Form("hNhits%i", stat), Form("Number of hits/vector in station %i", stat), 20, 0, 20); - fhNhitsOk[ist] = - new TH1D(Form("hNhitsOk%i", stat), Form("Number of hits/good vector in station %i", stat), 20, 0, 20); - fhChi2[ist] = new TH1D(Form("hChi2all%i", stat), Form("Chi2 of all vectors in station %i", stat), 200, 0, 200); - fhNgood[ist] = new TH1D(Form("hNgood%i", stat), Form("Number of good vectors in station %i", stat), 100, 0, 100); - fhNghost[ist] = new TH1D(Form("hNghost%i", stat), Form("Number of ghost vectors in station %i", stat), 200, 0, 200); - fhChi2ok[ist] = new TH1D(Form("hChi2ok%i", stat), Form("Chi2 of good vectors in station %i", stat), 200, 0, 200); - fhChi2bad[ist] = new TH1D(Form("hChi2bad%i", stat), Form("Chi2 of ghost vectors in station %i", stat), 200, 0, 200); - fhDx[ist] = new TH1D(Form("hDx%i", stat), Form("Xrec-Xmc in station %i", stat), 100, -2, 2); - fhDy[ist] = new TH1D(Form("hDy%i", stat), Form("Yrec-Ymc in station %i", stat), 100, -15, 15); - fhDtx[ist] = new TH1D(Form("hDtx%i", stat), Form("TXrec-TXmc in station %i", stat), 100, -0.2, 0.2); - fhDty[ist] = new TH1D(Form("hDty%i", stat), Form("TYrec-TYmc in station %i", stat), 100, -1, 1); - fhIds[ist] = new TH1D(Form("hIds%i", stat), Form("Good track ID in station %i", stat), 100, 0, 100); - fhIdVsEv[ist] = - new TH2D(Form("hIdVsEv%i", stat), Form("Good track ID vs ev. No. in station %i", stat), 100, -1, 99, 20, -1, 19); - fhIdVsEv[ist]->SetOption("box"); - fhDtxAll[ist] = new TH1D(Form("hDtxAll%i", stat), Form("TXvec-TXhit in station %i", stat), 100, -2, 2); - fhDtyAll[ist] = new TH1D(Form("hDtyAll%i", stat), Form("TYvec-TYhit in station %i", stat), 100, -2, 2); - fhDtxOk[ist] = new TH1D(Form("hDtxOk%i", stat), Form("TXvec-TXhit in station %i (ok)", stat), 100, -2, 2); - fhDtyOk[ist] = new TH1D(Form("hDtyOk%i", stat), Form("TYvec-TYhit in station %i (ok)", stat), 100, -2, 2); - fhDtube[ist][0] = new TH1D(Form("hDtube21_%i", stat), Form("Dtube 21 vs tube in station %i", stat), 100, -50, 50); - fhDtube[ist][1] = new TH1D(Form("hDtube32_%i", stat), Form("Dtube 32 vs tube in station %i", stat), 100, -100, 100); - fhDtube[ist][2] = new TH1D(Form("hDtube43_%i", stat), Form("Dtube 43 vs tube in station %i", stat), 100, -200, 200); - fhShort[ist] = new TH1D(Form("hShort%i", stat), Form("Number of shared hits in station %i", stat), 20, 0, 20); - fhOverlap[ist] = - new TH2D(Form("hOverlap%i", stat), Form("Overlap multipl. in station %i", stat), 20, 0, 20, 20, 0, 20); - fhChi2mat[ist] = new TH1D(Form("hChi2mat%i", stat), Form("Chi2 of matching in station %i", stat), 100, 0, 50); - fhMatchMult[ist] = - new TH1D(Form("hMatchMult%i", stat), Form("Multiplicity of matching in station %i", stat), 10, 0, 10); - fhOccup[ist] = new TH1D(Form("hOccup%i", stat), Form("Occupancy in station %i", stat), 600, -300, 300); - fhDtube2[ist][0] = - new TH2D(Form("hDtube31_%i", stat), Form("Dtube 31 vs tube in station %i", stat), 100, -300, 300, 100, -200, 200); - fhDtube2[ist][1] = - new TH2D(Form("hDtube42_%i", stat), Form("Dtube 42 vs tube in station %i", stat), 100, -300, 300, 100, -100, 100); - fhMCFit[ist][0] = new TH1D(Form("hMCFitX_%i", stat), Form("Chi2 of fit in X in station %i", stat), 100, 0, 50); - fhMCFit[ist][1] = new TH1D(Form("hMCFitY_%i", stat), Form("Chi2 of fit in Y in station %i", stat), 100, 0, 50); - fhDx12[ist] = new TH2D(Form("hDx12_%i", stat), Form("Dx2 vs Dx1 in station %i", stat), 50, -10, 10, 50, -10, 10); - fhDx23[ist] = new TH2D(Form("hDx23_%i", stat), Form("Dx3 vs Dx2 in station %i", stat), 50, -10, 10, 50, -10, 10); - fhDy12[ist] = new TH2D(Form("hDy12_%i", stat), Form("Dy2 vs Dy1 in station %i", stat), 50, -10, 10, 50, -10, 10); - fhDy23[ist] = new TH2D(Form("hDy23_%i", stat), Form("Dy3 vs Dy2 in station %i", stat), 50, -10, 10, 50, -10, 10); - } - fhSim = new TH1D("hSim", "Number of reconstructable muons", 10, 0, 10); - fhRec = new TH1D("hRec", "Number of reconstructed muons", 10, 0, 10); - fhZXY[0] = new TH1D("hZX", "Z - X", 180, 0, 45); - fhZXY[1] = new TH1D("hZY", "Z - Y", 180, 0, 45); - fhEvents = new TH1D("hEvents", "Number of processed events", 5, 0, 5); -} -// ------------------------------------------------------------------------- - -// ----- Public method Exec -------------------------------------------- -void CbmMuchFindVectorsQa::Exec(Option_t* opt) -{ - // Do all processing - - Int_t* mult = new Int_t[fNstat]; - Int_t* multOk = new Int_t[fNstat]; - Int_t* multBad = new Int_t[fNstat]; - for (Int_t i = 0; i < fNstat; ++i) - mult[i] = multOk[i] = multBad[i] = 0; - fhEvents->Fill(1); - - Int_t nvec = fVectors->GetEntriesFast(); - cout << " nvec " << nvec << endl; - for (Int_t iv = 0; iv < nvec; ++iv) { - CbmMuchTrack* vec = (CbmMuchTrack*) fVectors->UncheckedAt(iv); - Int_t ista = vec->GetUniqueID(); - const FairTrackParam* params = vec->GetParamFirst(); - ++mult[ista]; - fhChi2[ista]->Fill(vec->GetChiSq()); - fhNhits[ista]->Fill(vec->GetNofHits()); - fhDtxAll[ista]->Fill(params->GetTx() - params->GetX() / params->GetZ()); - fhDtyAll[ista]->Fill(params->GetTy() - params->GetY() / params->GetZ()); - if (CheckMatch(vec)) { - // "Good" vector - ++multOk[ista]; - fhChi2ok[ista]->Fill(vec->GetChiSq()); - } - else { - // Ghost - ++multBad[ista]; - fhChi2bad[ista]->Fill(vec->GetChiSq()); - } - } - cout << mult[0] << " " << mult[1] << endl; - - for (Int_t i = 0; i < fNstat; ++i) { - fhNvec[i]->Fill(mult[i]); - fhNgood[i]->Fill(multOk[i]); - fhNghost[i]->Fill(multBad[i]); - } - - // Check short tracks - CheckShorts(fHits); - - // Check efficiency - CheckEffic(); - - // For straws: fill occupancy histos as well (for completeness) - // and number of hits in the first layer of the first doublet - Int_t nhits = fHits->GetEntriesFast(), nDouble[10] = {0}; - for (Int_t i = 0; i < nhits; ++i) { - CbmMuchStrawHit* hit = (CbmMuchStrawHit*) fHits->UncheckedAt(i); - Int_t ista = fGeoScheme->GetStationIndex(hit->GetAddress()); - fhOccup[ista]->Fill(hit->GetTube()); - Int_t lay = fGeoScheme->GetLayerIndex(hit->GetAddress()); - Int_t side = fGeoScheme->GetLayerSideIndex(hit->GetAddress()); - if (lay == 0 && side == 0) ++nDouble[ista]; - } - //for (Int_t ista = 0; ista < 2; ++ista) fhNdoubl[ista]->Fill(nDouble[ista]); - for (Int_t ista = 0; ista < fNstat; ++ista) - fhNdoubl[ista]->Fill(nDouble[ista]); - - delete[] mult; - delete[] multOk; - delete[] multBad; -} -// ------------------------------------------------------------------------- - -// ----- Private method CheckMatch ------------------------------------- -Bool_t CbmMuchFindVectorsQa::CheckMatch(CbmMuchTrack* vec) -{ - // Check matching quality of the vector - - Int_t ista = vec->GetUniqueID(); - if (ista < fStatFirst) return CheckMatchGem(vec); - - Int_t nhits = vec->GetNofHits(), nthr = nhits / 2, id = 0; - //Int_t nhits = vec->GetNofHits(), nthr = nhits - 1, id = 0; - map<Int_t, Int_t> ids; - - for (Int_t ih = 0; ih < nhits; ++ih) { - CbmMuchStrawHit* hit = (CbmMuchStrawHit*) fHits->UncheckedAt(vec->GetHitIndex(ih)); - //if (hit->GetFlag() > 1) { cout << " hit " << hit->GetFlag() << endl; /*exit(0);*/ } - if (hit->GetFlag() % 2) { - //if (0) { - // Mirror hit - id = -1; - if (ids.find(id) == ids.end()) ids.insert(pair<Int_t, Int_t>(id, 1)); - else - ++ids[id]; - } - else { - CbmMuchDigiMatch* digiM = (CbmMuchDigiMatch*) fDigiMatches->UncheckedAt(hit->GetRefId()); - Int_t np = digiM->GetNofLinks(); - for (Int_t ip = 0; ip < np; ++ip) { - //CbmMuchPoint* point = (CbmMuchPoint*) fPoints->UncheckedAt(digiM->GetLink(0).GetIndex()); - CbmMuchPoint* point = (CbmMuchPoint*) fPoints->UncheckedAt(digiM->GetLink(ip).GetIndex()); - id = point->GetTrackID(); - //if (np > 1) cout << ip << " " << id << endl; - if (ids.find(id) == ids.end()) ids.insert(pair<Int_t, Int_t>(id, 1)); - else - ++ids[id]; - } - //if (np > 1) { cout << " digi " << digiM->GetNofLinks() << " " << ista << " " << hit->GetX() << " " << hit->GetY() << endl; exit(0); } - } - } - Int_t maxim = -1, idmax = -9; - for (map<Int_t, Int_t>::iterator it = ids.begin(); it != ids.end(); ++it) { - if (it->second > maxim) { - maxim = it->second; - idmax = it->first; - } - } - // Set vector ID as its flag - //vec->SetFlag(idmax); - if (maxim <= nthr || idmax < 0) return kFALSE; - - if (idmax > 1) return kFALSE; // !!! look only at muons from Pluto - - fhNhitsOk[ista]->Fill(vec->GetNofHits()); - fhIds[ista]->Fill(idmax); - Int_t evID = FairRunAna::Instance()->GetEventHeader()->GetMCEntryNumber() + 1; - fhIdVsEv[ista]->Fill(evID, idmax); - - // Fill true track parameters - Double_t zp = 0.0, parsTr[4] = {0.0}; - Int_t ok = 0; - for (Int_t ih = 0; ih < nhits; ++ih) { - CbmMuchStrawHit* hit = (CbmMuchStrawHit*) fHits->UncheckedAt(vec->GetHitIndex(ih)); - CbmMuchDigiMatch* digiM = (CbmMuchDigiMatch*) fDigiMatches->UncheckedAt(hit->GetRefId()); - Int_t np = digiM->GetNofLinks(); - for (Int_t ip = 0; ip < np; ++ip) { - CbmMuchPoint* point = (CbmMuchPoint*) fPoints->UncheckedAt(digiM->GetLink(ip).GetIndex()); - id = point->GetTrackID(); - if (id != idmax) continue; - parsTr[0] = (point->GetXIn() + point->GetXOut()) / 2; - parsTr[1] = (point->GetYIn() + point->GetYOut()) / 2; - zp = (point->GetZIn() + point->GetZOut()) / 2; - parsTr[2] = point->GetPx() / point->GetPz(); - parsTr[3] = point->GetPy() / point->GetPz(); - ok = 1; - break; - } - if (ok) break; - } - // Adjust track coordinates - const FairTrackParam* params = vec->GetParamFirst(); - parsTr[0] += parsTr[2] * (params->GetZ() - zp); - parsTr[1] += parsTr[3] * (params->GetZ() - zp); - fhDx[ista]->Fill(params->GetX() - parsTr[0]); - fhDy[ista]->Fill(params->GetY() - parsTr[1]); - fhDtx[ista]->Fill(params->GetTx() - parsTr[2]); - fhDty[ista]->Fill(params->GetTy() - parsTr[3]); - fhDtxOk[ista]->Fill(params->GetTx() - params->GetX() / params->GetZ()); - fhDtyOk[ista]->Fill(params->GetTy() - params->GetY() / params->GetZ()); - cout << " Good: " << idmax << " " << zp << " " << params->GetZ() << " " << parsTr[0] << " " << params->GetX() << " " - << parsTr[1] << " " << params->GetY() << " " << parsTr[2] << " " << params->GetTx() << " " << parsTr[3] << " " - << params->GetTy() << " " << vec->GetChiSq() << endl; - - // Fill tube difference between doublets - map<Int_t, Int_t> tubes[2]; - Int_t id0 = -1; - // Check configuration - Int_t combi = 0; - if (fNdoubl[fNstat - 1] == 3) combi = 3; // combined stations for 3-layer config. - - for (Int_t ih = 0; ih < nhits; ++ih) { - CbmMuchStrawHit* hit = (CbmMuchStrawHit*) fHits->UncheckedAt(vec->GetHitIndex(ih)); - CbmMuchDigiMatch* digiM = (CbmMuchDigiMatch*) fDigiMatches->UncheckedAt(hit->GetRefId()); - Int_t np = digiM->GetNofLinks(); - for (Int_t ip = 0; ip < np; ++ip) { - CbmMuchPoint* point = (CbmMuchPoint*) fPoints->UncheckedAt(digiM->GetLink(ip).GetIndex()); - id = point->GetTrackID(); - if (id > 1) continue; // look only at muons from vector mesons - if (id0 < 0) id0 = id; - break; - } - if (id0 < 0 || id != id0) continue; - Int_t stat = fGeoScheme->GetStationIndex(hit->GetAddress()) - fStatFirst; - Int_t lay = fGeoScheme->GetLayerIndex(hit->GetAddress()); - tubes[id].insert(pair<Int_t, Int_t>(lay + stat * combi, hit->GetTube())); - } - Double_t slope[2] = {0.08, 0.06}; - for (Int_t j = 0; j < 2; ++j) { - // Loop over trackID - Int_t nd = tubes[j].size(); - if (nd < 2) continue; - Int_t tubeNos[6] = {1000, 1000, 1000, 1000, 1000, 1000}; - map<Int_t, Int_t>::iterator it = tubes[j].begin(); - tubeNos[it->first] = it->second; - ++it; - for (; it != tubes[j].end(); ++it) - tubeNos[it->first] = it->second; - for (Int_t lay = 1; lay < 4; ++lay) { - if (tubeNos[lay] < 1000 & tubeNos[lay - 1] < 1000) fhDtube[ista][lay - 1]->Fill(tubeNos[lay] - tubeNos[lay - 1]); - if (combi == 0) { - // 4-layer config. - if (lay == 2 && tubeNos[lay] < 1000 & tubeNos[lay - 2] < 1000) - fhDtube2[ista][lay - 2]->Fill(tubeNos[lay - 2], tubeNos[lay] - tubeNos[lay - 2]); - if (lay == 3 && tubeNos[lay] < 1000 & tubeNos[lay - 2] < 1000) { - //fhDtube2[ista][lay-2]->Fill(tubeNos[lay-2],tubeNos[lay]-tubeNos[lay-2]-slope[ista]*tubeNos[lay-2]); - Double_t dzz = (fZpos[ista][lay * 2] - fZpos[ista][lay * 2 - 4]) / fZpos[ista][lay * 2 - 4]; - fhDtube2[ista][lay - 2]->Fill(tubeNos[lay - 2], tubeNos[lay] - tubeNos[lay - 2] - dzz * tubeNos[lay - 2]); - } - } - else { - // 3-layer config. - if (lay == 3 && tubeNos[lay] < 1000 & tubeNos[lay - 3] < 1000) - fhDtube2[ista][lay - 3]->Fill(tubeNos[lay - 3], tubeNos[lay] - tubeNos[lay - 3]); - if (lay == 1 && tubeNos[lay] < 1000 & tubeNos[lay + 3] < 1000) { - //fhDtube2[ista][lay-2]->Fill(tubeNos[lay-2],tubeNos[lay]-tubeNos[lay-2]-slope[ista]*tubeNos[lay-2]); - Double_t dzz = (fZpos[ista + 1][lay * 2] - fZpos[ista][lay * 2]) / fZpos[ista][lay * 2]; - fhDtube2[ista][lay]->Fill(tubeNos[lay], tubeNos[lay + 3] - tubeNos[lay] - dzz * tubeNos[lay]); - } - } - } - if (ok) break; - } - - return kTRUE; -} -// ------------------------------------------------------------------------- - -// ----- Private method CheckMatchGem ---------------------------------- -Bool_t CbmMuchFindVectorsQa::CheckMatchGem(CbmMuchTrack* vec) -{ - // Check matching quality of the vector for GEM stations - - Int_t ista = vec->GetUniqueID(); - Int_t nhits = vec->GetNofHits(), nthr = nhits / 2, id = 0; - //Int_t nhits = vec->GetNofHits(), nthr = nhits - 1, id = 0; - map<Int_t, Int_t> ids; - - for (Int_t ih = 0; ih < nhits; ++ih) { - CbmMuchPixelHit* hit = (CbmMuchPixelHit*) fHitsGem->UncheckedAt(vec->GetHitIndex(ih)); - CbmMuchCluster* clus = (CbmMuchCluster*) fClusters->UncheckedAt(hit->GetRefId()); - Int_t nDigis = clus->GetNofDigis(); - for (Int_t j = 0; j < nDigis; ++j) { - CbmMuchDigiMatch* digiM = (CbmMuchDigiMatch*) fDigiMatchesGem->UncheckedAt(clus->GetDigi(j)); - Int_t np = digiM->GetNofLinks(); - for (Int_t ip = 0; ip < np; ++ip) { - //CbmMuchPoint* point = (CbmMuchPoint*) fPoints->UncheckedAt(digiM->GetLink(0).GetIndex()); - CbmMuchPoint* point = (CbmMuchPoint*) fPoints->UncheckedAt(digiM->GetLink(ip).GetIndex()); - id = point->GetTrackID(); - //if (np > 1) cout << ip << " " << id << endl; - ids[id]++; - } - //if (np > 1) { cout << " digi " << digiM->GetNofLinks() << " " << ista << " " << hit->GetX() << " " << hit->GetY() << endl; exit(0); } - } - } - - Int_t maxim = -1, idmax = -9; - for (map<Int_t, Int_t>::iterator it = ids.begin(); it != ids.end(); ++it) { - if (it->second > maxim) { - maxim = it->second; - idmax = it->first; - } - } - //cout << " GEMS: " << ista << " " << nhits << " " << maxim << " " << idmax << endl; - // Set vector ID as its flag - //vec->SetFlag(idmax); - if (maxim <= nthr || idmax < 0) return kFALSE; - - if (idmax > 1) return kFALSE; // !!! look only at muons from Pluto - - fhNhitsOk[ista]->Fill(vec->GetNofHits()); - fhIds[ista]->Fill(idmax); - Int_t evID = FairRunAna::Instance()->GetEventHeader()->GetMCEntryNumber() + 1; - fhIdVsEv[ista]->Fill(evID, idmax); - - // Fill true track parameters - Double_t zp = 0.0, parsTr[4] = {0.0}; - Int_t ok = 0; - - for (Int_t ih = 0; ih < nhits; ++ih) { - CbmMuchPixelHit* hit = (CbmMuchPixelHit*) fHitsGem->UncheckedAt(vec->GetHitIndex(ih)); - CbmMuchCluster* clus = (CbmMuchCluster*) fClusters->UncheckedAt(hit->GetRefId()); - Int_t nDigis = clus->GetNofDigis(); - for (Int_t j = 0; j < nDigis; ++j) { - CbmMuchDigiMatch* digiM = (CbmMuchDigiMatch*) fDigiMatchesGem->UncheckedAt(clus->GetDigi(j)); - Int_t np = digiM->GetNofLinks(); - for (Int_t ip = 0; ip < np; ++ip) { - CbmMuchPoint* point = (CbmMuchPoint*) fPoints->UncheckedAt(digiM->GetLink(ip).GetIndex()); - id = point->GetTrackID(); - if (id != idmax) continue; - parsTr[0] = (point->GetXIn() + point->GetXOut()) / 2; - parsTr[1] = (point->GetYIn() + point->GetYOut()) / 2; - zp = (point->GetZIn() + point->GetZOut()) / 2; - parsTr[2] = point->GetPx() / point->GetPz(); - parsTr[3] = point->GetPy() / point->GetPz(); - ok = 1; - break; - } - if (ok) break; - } - if (ok) break; - } - // Adjust track coordinates - const FairTrackParam* params = vec->GetParamFirst(); - parsTr[0] += parsTr[2] * (params->GetZ() - zp); - parsTr[1] += parsTr[3] * (params->GetZ() - zp); - fhDx[ista]->Fill(params->GetX() - parsTr[0]); - fhDy[ista]->Fill(params->GetY() - parsTr[1]); - fhDtx[ista]->Fill(params->GetTx() - parsTr[2]); - fhDty[ista]->Fill(params->GetTy() - parsTr[3]); - fhDtxOk[ista]->Fill(params->GetTx() - params->GetX() / params->GetZ()); - fhDtyOk[ista]->Fill(params->GetTy() - params->GetY() / params->GetZ()); - cout << " Good: " << idmax << " " << zp << " " << params->GetZ() << " " << parsTr[0] << " " << params->GetX() << " " - << parsTr[1] << " " << params->GetY() << " " << parsTr[2] << " " << params->GetTx() << " " << parsTr[3] << " " - << params->GetTy() << " " << vec->GetChiSq() << endl; - - return kTRUE; -} -// ------------------------------------------------------------------------- - -// ----- Private method CheckShorts ------------------------------------ -void CbmMuchFindVectorsQa::CheckShorts(TClonesArray* hitArray) -{ - // Check short tracks - - Int_t nvec = fVectors->GetEntriesFast(); - Int_t nhits0 = 4; - for (Int_t iv = 0; iv < nvec; ++iv) { - CbmMuchTrack* vec = (CbmMuchTrack*) fVectors->UncheckedAt(iv); - Int_t nhits = vec->GetNofHits(); - if (nhits != nhits0) continue; - Int_t ista = vec->GetUniqueID(); - set<Int_t> overlap; - multiset<Int_t> overlap1; - - for (Int_t iv1 = iv + 1; iv1 < nvec; ++iv1) { - CbmMuchTrack* vec1 = (CbmMuchTrack*) fVectors->UncheckedAt(iv1); - if (vec1->GetUniqueID() != ista) continue; - Int_t nhits1 = vec1->GetNofHits(); - - // Compare hits - Int_t ih1 = 0; - for (Int_t ih = 0; ih < nhits; ++ih) { - //CbmMuchStrawHit *hit = (CbmMuchStrawHit*) hitArray->UncheckedAt(vec->GetHitIndex(ih)); - CbmHit* hit = (CbmHit*) hitArray->UncheckedAt(vec->GetHitIndex(ih)); - Int_t lay = fGeoScheme->GetLayerIndex(hit->GetAddress()); - Int_t side = fGeoScheme->GetLayerSideIndex(hit->GetAddress()); - Int_t plane = lay * 2 + side; - - for (; ih1 < nhits1; ++ih1) { - //CbmMuchStrawHit *hit1 = (CbmMuchStrawHit*) hitArray->UncheckedAt(vec1->GetHitIndex(ih1)); - CbmHit* hit1 = (CbmHit*) hitArray->UncheckedAt(vec1->GetHitIndex(ih1)); - Int_t lay1 = fGeoScheme->GetLayerIndex(hit1->GetAddress()); - Int_t side1 = fGeoScheme->GetLayerSideIndex(hit1->GetAddress()); - Int_t plane1 = lay1 * 2 + side1; - if (plane1 < plane) continue; - if (plane1 > plane) break; - if (hit == hit1) { - overlap.insert(ih); - overlap1.insert(ih); - } - } - } - if (overlap.size() == nhits0) { - // All hits are shared with other tracks - //break; - } - } // for (Int_t iv1 = iv + 1; - fhShort[ista]->Fill(overlap.size()); - if (overlap.size()) fhOverlap[ista]->Fill(overlap.size(), overlap1.size()); - } // for (Int_t iv = 0; iv < nvec; -} -// ------------------------------------------------------------------------- - -// ----- Private method CheckEffic ------------------------------------- -void CbmMuchFindVectorsQa::CheckEffic() -{ - // Check efficiency of the vector reco - - // Find "reconstructable" vectors - having points in all doublets (GEM or straw) - // !!! Take only trackID = 0, 1 (from signal mesons) - const Int_t nMu = 2; - set<Int_t> doublets[20][nMu], singlets[20][nMu]; - Int_t nPoints = fPoints->GetEntriesFast(); - Double_t xp[7][20][nMu], yp[7][20][nMu]; - Bool_t lstraws = kFALSE; - - for (Int_t ip = 0; ip < nPoints; ++ip) { - CbmMuchPoint* p = (CbmMuchPoint*) fPoints->UncheckedAt(ip); - Int_t id = p->GetTrackID(); - if (id > 1) continue; - if (p->GetZ() < fZpos[0][0] - 2.0) continue; - Int_t ista = fGeoScheme->GetStationIndex(p->GetDetectorId()); - Int_t lay = fGeoScheme->GetLayerIndex(p->GetDetectorId()); - Int_t side = fGeoScheme->GetLayerSideIndex(p->GetDetectorId()); - - doublets[ista][id].insert(lay); - singlets[ista][id].insert(lay * 2 + side); - xp[ista][lay * 2 + side][id] = (p->GetXIn() + p->GetXOut()) / 2; - yp[ista][lay * 2 + side][id] = (p->GetYIn() + p->GetYOut()) / 2; - - if (!lstraws) { - if (fGeoScheme->GetModuleByDetId(p->GetDetectorId())->GetDetectorType() == 2) lstraws = kTRUE; - } - } - - Int_t muons[7][nMu] = {{0}, {0}}, nMuVec = 0; - for (Int_t ista = 0; ista < fNstat; ++ista) { - if (doublets[ista][0].size() == fNdoubl[ista]) { - fhSim->Fill(ista); - muons[ista][0] = 1; - ++nMuVec; - } - if (doublets[ista][1].size() == fNdoubl[ista]) { - fhSim->Fill(ista); - muons[ista][1] = 1; - ++nMuVec; - } - } - //if (muons[0][0] == 0 && muons[0][1] == 0 && muons[1][0] == 0 && muons[1][1] == 0) return; - if (nMuVec == 0) return; - - // Fit to straight lines in 2 projections - /* - for (Int_t ista = 0; ista < fNstat; ++ista) { - - for (Int_t mu = 0; mu < 2; ++ mu) { - if (muons[ista][mu] == 0) continue; - - fhZXY[0]->Reset(); - fhZXY[1]->Reset(); - for (Int_t plane = 0; plane < nLays2; ++plane) { - if (singlets[ista][mu].find(plane) == singlets[ista][mu].end()) continue; - fhZXY[0]->Fill(zPos[ista][plane]-zPos[ista][0]+5, xp[ista][plane][mu]); - Int_t ib = fhZXY[1]->Fill(zPos[ista][plane]-zPos[ista][0]+5, yp[ista][plane][mu]); - fhZXY[0]->SetBinError(ib, 0.1); - fhZXY[1]->SetBinError(ib, 0.1); - } - for (Int_t jxy = 0; jxy < 2; ++jxy) { - fhZXY[jxy]->Fit("pol1","Q0"); - TF1 *f = fhZXY[jxy]->GetFunction("pol1"); - fhMCFit[ista][jxy]->Fill(f->GetChisquare() / f->GetNDF()); - } - } - } - */ - - // Match reconstructed vectors - Int_t nvec = fVectors->GetEntriesFast(); - Int_t pluto = 1; // !!! set to 1 to check exact matching for Pluto - //Double_t errx = 0.22, erry = 1.41, chi2cut = 10.0; // 10 deg - //Double_t errx = 0.2, erry = 1.9, chi2cut = 10.0; // 5 doublets - Double_t errxS[6] = {0.33, 0.50, 0.2, 0.2, 1, 1}; - Double_t erryS[6] = {0.33, 0.50, 1.9, 1.9, 1, 1}, - chi2cut = 10.0; // 2 GEMS, 2 straws - //Double_t errxS[6] = {0.33, 0.50, 0.03, 0.03, 1, 1}; - //Double_t erryS[6] = {0.33, 0.50, 0.26, 0.26, 1, 1}, chi2cut = 10.0; // 2 GEMS, 2 straws - Double_t errxG[6] = {0.33, 0.54, 1.0, 1.7, 1, 1}; - Double_t erryG[6] = {0.33, 0.54, 1.0, 1.7, 1, 1}; // 4 GEMS - Int_t nMatch[7][nMu] = {{0}, {0}}, combi = 0; - Double_t *errx = errxG, *erry = erryG; - if (lstraws) { - errx = errxS; - erry = erryS; - if (fNdoubl[fNstat - 1] == 3) combi = 6; // combined stations for 3-layer config. - } - - for (Int_t iv = 0; iv < nvec; ++iv) { - CbmMuchTrack* vec = (CbmMuchTrack*) fVectors->UncheckedAt(iv); - Int_t nhits = vec->GetNofHits(); - Int_t ista = vec->GetUniqueID(); - if (muons[ista][0] == 0 && muons[ista][1] == 0) continue; - Int_t id = vec->GetFlag(); - if (pluto && id > 1) continue; // !!! this is only for Pluto sample - exact ID match!!! - const FairTrackParam* params = vec->GetParamFirst(); - TClonesArray* hitArray = (ista < fStatFirst) ? fHitsGem : fHits; - - Double_t chi2[nMu] = {0.0}; - for (Int_t mu = 0; mu < nMu; ++mu) { - if (!muons[ista][mu]) { - chi2[mu] = 999999.; - continue; - } - Int_t nm = 0; - Double_t dx0 = 0, dy0 = 0; - - for (Int_t ih = 0; ih < nhits; ++ih) { - //CbmMuchStrawHit *hit = (CbmMuchStrawHit*) fHits->UncheckedAt(vec->GetHitIndex(ih)); - CbmHit* hit = (CbmHit*) hitArray->UncheckedAt(vec->GetHitIndex(ih)); - Int_t stat = fGeoScheme->GetStationIndex(hit->GetAddress()) - fStatFirst; - Int_t lay = fGeoScheme->GetLayerIndex(hit->GetAddress()); - Int_t side = fGeoScheme->GetLayerSideIndex(hit->GetAddress()); - Int_t plane = lay * 2 + side; - plane += stat * combi; - if (singlets[ista][mu].find(plane) == singlets[ista][mu].end()) continue; - Double_t x = params->GetX() + params->GetTx() * (fZpos[ista][plane] - params->GetZ()); - Double_t y = params->GetY() + params->GetTy() * (fZpos[ista][plane] - params->GetZ()); - Double_t dx = x - xp[ista][plane][mu]; - Double_t dy = y - yp[ista][plane][mu]; - chi2[mu] += dx * dx / errx[ista] / errx[ista]; - chi2[mu] += dy * dy / erry[ista] / erry[ista]; - ++nm; - if (lay) { - if (lay == 1) { - fhDx12[ista]->Fill(dx0, dx); - fhDy12[ista]->Fill(dy0, dy); - } - else if (lay == 2) { - fhDx23[ista]->Fill(dx0, dx); - fhDy23[ista]->Fill(dy0, dy); - } - } - dx0 = dx; - dy0 = dy; - //cout << nm << " " << dx << " " << dy << endl; - } - nm *= 2; - if (nm > 4) chi2[mu] /= (nm - 4); // per NDF - } - if (pluto) fhChi2mat[ista]->Fill(chi2[id]); // !!! this is only for Pluto sample - exact ID match!!! - else - fhChi2mat[ista]->Fill(TMath::Min(chi2[0], chi2[1])); - if (chi2[0] < chi2cut) ++nMatch[ista][0]; - if (chi2[1] < chi2cut) ++nMatch[ista][1]; - cout << chi2[0] << " " << chi2[1] << endl; - } // for (Int_t iv = 0; iv < nvec; - for (Int_t ista = 0; ista < fNstat; ++ista) { - if (combi && ista == fNstat - 1) continue; // 2 combined stations - for (Int_t id = 0; id < nMu; ++id) { - if (muons[ista][id]) { - if (combi && ista == fNstat - 2 && muons[ista + 1][id] == 0) continue; // 2 combined stations - fhMatchMult[ista]->Fill(nMatch[ista][id]); - if (nMatch[ista][id] == 0) cout << " !!! No match found !!! " << ista << " " << id << endl; - } - } - } -} -// ------------------------------------------------------------------------- - -// ----- Public method Finish ------------------------------------------ -void CbmMuchFindVectorsQa::Finish() -{ - for (Int_t ista = 0; ista < fNstat; ++ista) { - if (fNdoubl[ista]) fhOccup[ista]->Scale(1. / 2 / fNdoubl[ista] / 2 / fhEvents->GetEntries()); - } - - TDirectory* dir = (TDirectory*) gROOT->FindObjectAny("muchQA"); - gDirectory->mkdir("muchQA"); - gDirectory->cd("muchQA"); - dir->GetList()->Write(); -} -// ------------------------------------------------------------------------- - -// ------------------------------------------------------------------------- - -ClassImp(CbmMuchFindVectorsQa); diff --git a/reco/tracking/vector/CbmMuchFindVectorsQa.h b/reco/tracking/vector/CbmMuchFindVectorsQa.h deleted file mode 100644 index 6297d6c52db6a4e447583eb188945d8f03417c76..0000000000000000000000000000000000000000 --- a/reco/tracking/vector/CbmMuchFindVectorsQa.h +++ /dev/null @@ -1,117 +0,0 @@ -/* Copyright (C) 2014-2018 Veksler and Baldin Laboratory of High Energy Physics, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Alexander Zinchenko [committer] */ - -/** CbmMuchFindVectorsQa.h - *@author A.Zinchenko <Alexander.Zinchenko@jinr.ru> - *@since 2014 - ** - ** Task class for MUCH vector finder QA. - ** - **/ - -#ifndef CBMMUCHFINDVECTORSQA_H_ -#define CBMMUCHFINDVECTORSQA_H_ 1 - -#include "CbmMuchGeoScheme.h" - -#include "FairTask.h" - -#include <set> -#include <vector> - -class CbmMuchTrack; -class TClonesArray; -class TH1D; -class TH2D; - -class CbmMuchFindVectorsQa : public FairTask { -public: - /** Default (standard) constructor **/ - CbmMuchFindVectorsQa(); - - /** Destructor **/ - virtual ~CbmMuchFindVectorsQa(); - - /** Initialisation **/ - virtual InitStatus Init(); - - /** Task execution **/ - virtual void Exec(Option_t* opt); - - /** Finish at the end **/ - virtual void Finish(); - - /** SetParContainers **/ - virtual void SetParContainers(); - - /** Accessors **/ - //Int_t GetNofTracks() { return fNofTracks; }; - -private: - CbmMuchGeoScheme* fGeoScheme; // Geometry scheme - Int_t fStatFirst; // First straw station No. - Int_t fNstat; // Number of straw stations - Int_t fNdoubl[10]; // Number of double layers in stations - Double_t fZpos[7][10]; // Z-pos. of double layers in stations - - TClonesArray* fVectors; - TClonesArray* fMCTracks; - TClonesArray* fPoints; - TClonesArray* fHits; - TClonesArray* fHitsGem; - TClonesArray* fDigis; - TClonesArray* fDigisGem; - TClonesArray* fDigiMatches; - TClonesArray* fDigiMatchesGem; - TClonesArray* fClusters; - - TH1D** fhNvec; - TH1D** fhNdoubl; - TH1D** fhNhits; - TH1D** fhNhitsOk; - TH1D** fhChi2; - TH1D** fhNgood; - TH1D** fhNghost; - TH1D** fhChi2ok; - TH1D** fhChi2bad; - TH1D** fhDx; - TH1D** fhDy; - TH1D** fhDtx; - TH1D** fhDty; - TH1D** fhIds; - TH2D** fhIdVsEv; - TH1D** fhDtxAll; - TH1D** fhDtyAll; - TH1D** fhDtxOk; - TH1D** fhDtyOk; - TH1D* fhDtube[7][10]; - TH2D* fhDtube2[7][10]; - TH1D** fhShort; - TH2D** fhOverlap; - TH1D* fhSim; - TH1D* fhRec; - TH1D** fhChi2mat; - TH1D** fhMatchMult; - TH1D** fhOccup; - TH1D* fhMCFit[7][10]; - TH1D* fhZXY[2]; //! transient histos - TH1D* fhEvents; //! transient histo - TH2D** fhDx12; - TH2D** fhDx23; - TH2D** fhDy12; - TH2D** fhDy23; - - void BookHistos(); - Bool_t CheckMatch(CbmMuchTrack* vec); - Bool_t CheckMatchGem(CbmMuchTrack* vec); - void CheckShorts(TClonesArray* hitArray); - void CheckEffic(); - - CbmMuchFindVectorsQa(const CbmMuchFindVectorsQa&); - CbmMuchFindVectorsQa& operator=(const CbmMuchFindVectorsQa&); - - ClassDef(CbmMuchFindVectorsQa, 1) -}; - -#endif diff --git a/reco/tracking/vector/CbmMuchMergeVectors.cxx b/reco/tracking/vector/CbmMuchMergeVectors.cxx deleted file mode 100644 index f6700d5ee030aaac9caa19908b8b4395d9dc7ee9..0000000000000000000000000000000000000000 --- a/reco/tracking/vector/CbmMuchMergeVectors.cxx +++ /dev/null @@ -1,1092 +0,0 @@ -/* Copyright (C) 2014-2018 Veksler and Baldin Laboratory of High Energy Physics, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Alexander Zinchenko [committer] */ - -/** CbmMuchMergeVectors.cxx - *@author A.Zinchenko <Alexander.Zinchenko@jinr.ru> - *@since 2014 - **/ -#include "CbmMuchMergeVectors.h" - -#include "CbmKFTrack.h" -#include "CbmMuchDigiMatch.h" -#include "CbmMuchFindVectorsGem.h" -#include "CbmMuchModule.h" -#include "CbmMuchPoint.h" -#include "CbmMuchStation.h" -#include "CbmMuchTrack.h" -#include "CbmStsTrack.h" -//#include "CbmTrackMatch.h" -#include "CbmTrackMatchNew.h" - -#include "FairEventHeader.h" -#include "FairField.h" -#include "FairRootManager.h" -#include <Logger.h> - -#include <TClonesArray.h> -#include <TGeoManager.h> -#include <TMath.h> -#include <TMatrixD.h> -#include <TMatrixFLazy.h> -#include <TROOT.h> -#include <TVectorD.h> - -#include <iostream> - -using std::cout; -using std::endl; -using std::map; -using std::multimap; -using std::pair; -using std::set; - -FILE* lun1 = 0x0; //fopen("chi21.dat","w"); - -// ----- Default constructor ------------------------------------------- -CbmMuchMergeVectors::CbmMuchMergeVectors() - : FairTask("MuchMergeVectors") - , fGeoScheme(CbmMuchGeoScheme::Instance()) - , fTrackArray(NULL) - , fNofTracks(0) - , fHits(NULL) - , fGemHits(NULL) - , fPoints(NULL) - , fDigiMatches(NULL) - , fVecArray(NULL) - , fTracksSts(NULL) - , fTrStsMatch(NULL) - , fTracksLit(NULL) - , fStatFirst(-1) -//fCutChi2(40)//200.0) -{ - for (Int_t i = 0; i < 9; ++i) - fCutChi2[i] = 40; - fCutChi2[0] *= 2; - //fCutChi2[fgkStat-2] *= 2; -} -// ------------------------------------------------------------------------- - -// ----- Destructor ---------------------------------------------------- -CbmMuchMergeVectors::~CbmMuchMergeVectors() -{ - fTrackArray->Delete(); - - for (map<Int_t, TMatrixDSym*>::iterator it = fMatr.begin(); it != fMatr.end(); ++it) - delete it->second; -} -// ------------------------------------------------------------------------- - -// ----- Public method Init (abstract in base class) -------------------- -InitStatus CbmMuchMergeVectors::Init() -{ - - // Get and check FairRootManager - FairRootManager* ioman = FairRootManager::Instance(); - if (ioman == NULL) Fatal("Init", "RootManager not instantiated!"); - - // Create and register MuchTrack array - fTrackArray = new TClonesArray("CbmMuchTrack", 100); - ioman->Register("MuchVectorTrack", "Much", fTrackArray, kTRUE); - - CbmMuchFindHitsStraws* hitFinder = (CbmMuchFindHitsStraws*) FairRun::Instance()->GetTask("CbmMuchFindHitsStraws"); - //if (hitFinder == NULL) Fatal("Init", "CbmMuchFindHitsStraws not run!"); - //fDiam = hitFinder->GetDiam(0); - - fGemHits = static_cast<TClonesArray*>(ioman->GetObject("MuchPixelHit")); - fPoints = static_cast<TClonesArray*>(ioman->GetObject("MuchPoint")); - fVecArray = static_cast<TClonesArray*>(ioman->GetObject("MuchVector")); - fTracksSts = static_cast<TClonesArray*>(ioman->GetObject("StsTrack")); - fTrStsMatch = static_cast<TClonesArray*>(ioman->GetObject("StsTrackMatch")); - fTracksLit = static_cast<TClonesArray*>(ioman->GetObject("MuchTrack")); - - // Find first straw station and get some geo constants - Int_t nSt = fGeoScheme->GetNStations(); - for (Int_t i = 0; i < nSt; ++i) { - CbmMuchStation* st = fGeoScheme->GetStation(i); - CbmMuchModule* mod = fGeoScheme->GetModule(i, 0, 0, 0); - fRmin[i] = st->GetRmin(); - fRmax[i] = st->GetRmax(); - if (mod->GetDetectorType() == 2) { - if (fStatFirst < 0) fStatFirst = CbmMuchAddress::GetStationIndex(st->GetDetectorId()); - //cout << " First station: " << fStatFirst << endl; - Int_t nLays = st->GetNLayers(); - fNdoubl = nLays; - for (Int_t lay = 0; lay < nLays; ++lay) { - CbmMuchLayer* layer = st->GetLayer(lay); - Double_t phi = hitFinder->GetPhi(lay); - for (Int_t iside = 0; iside < 2; ++iside) { - CbmMuchLayerSide* side = layer->GetSide(iside); - Int_t plane = lay * 2 + iside; - fDz[plane] = side->GetZ(); - fCosa[plane] = TMath::Cos(phi); - fSina[plane] = TMath::Sin(phi); - if (plane == 0) fZ0[i - fStatFirst] = side->GetZ(); - } - } - } - } - for (Int_t i = fgkPlanes - 1; i >= 0; --i) { - fDz[i] -= fDz[0]; - //cout << fDz[i] << " "; - } - //cout << endl; - - // Get absorbers from GEM vector finder - FairTask* vecFinder = FairRun::Instance()->GetTask("VectorFinder"); - vecFinder->GetListOfTasks()->ls(); - CbmMuchFindVectorsGem* gemFinder = - (CbmMuchFindVectorsGem*) vecFinder->GetListOfTasks()->FindObject("MuchFindVectorsGem"); - if (gemFinder == NULL) Fatal("Init", "CbmMuchFindVectorsGem not run!"); - - Int_t nAbs = gemFinder->GetAbsorbers(fZabs0, fX0abs); - - cout << " \n !!! MUCH Absorbers: " << nAbs << "\n Zbeg, Zend, X0:"; - for (Int_t j = 0; j < nAbs; ++j) - cout << " " << std::setprecision(4) << fZabs0[j][0] << ", " << fZabs0[j][1] << ", " << fX0abs[j] << ";"; - cout << endl << endl; - - return kSUCCESS; -} -// ------------------------------------------------------------------------- - -// ----- SetParContainers ------------------------------------------------- -void CbmMuchMergeVectors::SetParContainers() {} -// ------------------------------------------------------------------------- - -// ----- Public method Exec -------------------------------------------- -void CbmMuchMergeVectors::Exec(Option_t* opt) -{ - - //gErrorIgnoreLevel = kInfo; //debug level - //gErrorIgnoreLevel = kWarning; //debug level - gLogger->SetLogScreenLevel("INFO"); - //gLogger->SetLogScreenLevel("WARNING"); - - fTrackArray->Delete(); - - // Do all processing - - // Get vectors - GetVectors(); - - // Match vectors - MatchVectors(); - - // Merge vectors - MergeVectors(); - - // Select final tracks - remove ghosts - SelectTracks(); - - // Add first station (as a filter) - //AddStation1(); -} -// ------------------------------------------------------------------------- - -// ----- Public method Finish ------------------------------------------ -void CbmMuchMergeVectors::Finish() -{ - fTrackArray->Clear(); - - for (map<Int_t, TMatrixDSym*>::iterator it = fMatr.begin(); it != fMatr.end(); ++it) - delete it->second; -} -// ------------------------------------------------------------------------- - -// ----- Private method GetVectors ------------------------------------- -void CbmMuchMergeVectors::GetVectors() -{ - // Group vectors according to the station number - - std::map<Int_t, CbmMuchTrack*>::iterator it; - for (Int_t ista = 0; ista < fgkStat; ++ista) { - if (ista == 0) { - // STS tracks - for (it = fVectors[ista].begin(); it != fVectors[ista].end(); ++it) - if (it->first >= 0) delete it->second; - } - fVectors[ista].clear(); - } - - Int_t nVecs = fVecArray->GetEntriesFast(), sel = 0; - for (Int_t i = 0; i < nVecs; ++i) { - CbmMuchTrack* vec = (CbmMuchTrack*) fVecArray->UncheckedAt(i); - - //!!! For debug - select hits with certain track IDs - sel = 1; //SelectHitId(hit); - if (!sel) continue; - // - - Int_t ista = vec->GetUniqueID() + 1; // offset due to STS tracks - fVectors[ista].insert(pair<Int_t, CbmMuchTrack*>(i, vec)); - } - - // Get STS tracks and extrapolate them to the first absorber face - if (fTracksSts == NULL) return; - Int_t nSts = fTracksSts->GetEntriesFast(), ista = 0; - FairTrackParam param, parRear; - Double_t pMin = 0.25; - //Double_t pMin = 0.7; //AZ - - for (Int_t i = 0; i < nSts; ++i) { - CbmStsTrack* tr = (CbmStsTrack*) fTracksSts->UncheckedAt(i); - if (tr->GetNofHits() < 4) continue; // too few hits - Double_t ppp = 1. / TMath::Abs(tr->GetParamLast()->GetQp()); - //if (ppp < pMin + 0.1) continue; // too low momentum - if (ppp < pMin + 0.05) continue; // too low momentum - CbmKFTrack kfTrack = CbmKFTrack(*tr, 0); - if (kfTrack.Extrapolate(fZabs0[ista][0])) continue; // extrapolation error to absorber front face - kfTrack.GetTrackParam(param); - if (kfTrack.Extrapolate(fZabs0[ista][1])) continue; // extrapolation error to absorber rear face - kfTrack.GetTrackParam(parRear); - Double_t r2 = param.GetX() * param.GetX() + param.GetY() * param.GetY(); - if (TMath::Sqrt(r2) > fRmax[0]) continue; // outside outer acceptance - // Take into account track angle - Double_t cos2th = 1.0 + param.GetTx() * param.GetTx() + param.GetTy() * param.GetTy(); - //if (ppp / TMath::Sqrt(cos2th) < pMin + 0.1) continue; // too low momentum - if (ppp / TMath::Sqrt(cos2th) < pMin + 0.05) continue; // too low momentum - CbmMuchTrack* vec = new CbmMuchTrack(); - param.SetQp(1.0 / ppp); - vec->SetParamFirst(¶m); - vec->SetPreviousTrackId(i); // store STS track index - vec->SetUniqueID(9); // station "No. 9" - parRear.SetQp(TMath::Abs(parRear.GetQp())); - vec->SetParamLast(&parRear); - //CbmTrackMatch *trMatch = (CbmTrackMatch*) fTrStsMatch->UncheckedAt(i); - //vec->SetFlag(trMatch->GetMCTrackId()); - if (fTrStsMatch) { - CbmTrackMatchNew* trMatch = (CbmTrackMatchNew*) fTrStsMatch->UncheckedAt(i); - vec->SetFlag(trMatch->GetMatchedLink().GetIndex()); - //} else vec->SetFlag(SetStsTrackId(i)); - } - else if (tr->GetMatch() && tr->GetMatch()->GetNofLinks()) { - vec->SetFlag(tr->GetMatch()->GetMatchedLink().GetIndex()); - } - else - vec->SetFlag(-1); - fVectors[ista].insert(pair<Int_t, CbmMuchTrack*>(i + nVecs, vec)); - //cout << " Before absorber: " << i << " " << nVecs << " " << i+nVecs << endl; - } - - // Extrapolate STS tracks through the first absorber - TMatrixF matr = TMatrixF(5, 5); - TMatrixF unit(TMatrixF::kUnit, matr); - for (it = fVectors[ista].begin(); it != fVectors[ista].end(); ++it) { - CbmMuchTrack* tr = it->second; - FairTrackParam parFirst = *tr->GetParamFirst(); - FairTrackParam parLast = *tr->GetParamLast(); - parFirst = parLast; - TMatrixFSym cov(5); - parFirst.CovMatrix(cov); - /* - Double_t zbeg = parFirst.GetZ(); - Double_t dz = fZabs0[0][1] - zbeg; - // Propagate params - //parFirst.SetX(parFirst.GetX() + dz * parFirst.GetTx()); - //parFirst.SetY(parFirst.GetY() + dz * parFirst.GetTy()); - //parFirst.SetZ(parFirst.GetZ() + dz); - parFirst.SetX(parLast.GetX()); - parFirst.SetY(parLast.GetY()); - parFirst.SetZ(parLast.GetZ()); - parFirst.SetTx(parLast.GetTx()); - parFirst.SetTy(parLast.GetTy()); - TMatrixFSym cov(5); - parFirst.CovMatrix(cov); - cov(4,4) = 1.0; - TMatrixF ff = unit; - ff(2,0) = ff(3,1) = dz; - TMatrixF cf(cov,TMatrixF::kMult,ff); - TMatrixF fcf(ff,TMatrixF::kTransposeMult,cf); - cov.SetMatrixArray(fcf.GetMatrixArray()); - */ - PassAbsorber(0, fZabs0[0], fX0abs[0], parFirst, cov, 1); - parFirst.SetCovMatrix(cov); - //tr->SetParamLast(&parFirst); - tr->SetParamFirst(&parFirst); - //cout << " After absorber: " << it->first << " " << parFirst.GetX() << " " << parFirst.GetY() << endl; - } -} -// ------------------------------------------------------------------------- - -// ----- Private method SetStsTrackId ---------------------------------- -/* -Int_t CbmMuchMergeVectors::SetStsTrackId(Int_t indx) -{ - // Set STS track ID - - CbmStsTrack *tr = (CbmStsTrack*) fTracksSts->UncheckedAt(indx); - Int_t nHits = tr->GetNofStsHits(); - - for (Int_t i = 0; i < nHits; ++i) { - CbmStsHit *hit = fStsHits->UncheckedAt(tr->GetStsHitIndex(i)); - } -} -*/ -// ------------------------------------------------------------------------- - -// ----- Private method MatchVectors ----------------------------------- -void CbmMuchMergeVectors::MatchVectors() -{ - // Match vectors (CbmMuchTracks) from 2 stations going upstream - - // remove vectors without matching - - const Double_t window0 = 7.0; //10.0; // - TMatrixF matr = TMatrixF(5, 5); - TMatrixF unit(TMatrixF::kUnit, matr); - map<Int_t, CbmMuchTrack*>::iterator it, it1; - multimap<Double_t, pair<Int_t, CbmMuchTrack*>> xMap[2]; - multimap<Double_t, pair<Int_t, CbmMuchTrack*>>::iterator mit, mit1, mitb, mite; - map<CbmMuchTrack*, Int_t> matchOK[2]; - TMatrixFSym cov(5); - - //AZ for (Int_t iabs = 2; iabs >= 0; --iabs) { // last absorber has been checked already - for (Int_t iabs = 3; iabs >= 0; --iabs) { // last absorber has been checked already - Double_t window = window0; - if (iabs == fgkStat - 2) window = window0 * 2.0; - //Int_t ibeg = fTrackArray->GetEntriesFast(); - xMap[0].clear(); - xMap[1].clear(); - matchOK[0].clear(); - matchOK[1].clear(); - - for (Int_t ist = 0; ist < 2; ++ist) { - // Propagate vectors to the absorber faces - Int_t ista = iabs - 1 + ist + 1; - - for (it = fVectors[ista].begin(); it != fVectors[ista].end(); ++it) { - CbmMuchTrack* tr = it->second; - FairTrackParam parFirst = *tr->GetParamFirst(); - parFirst.CovMatrix(cov); - cov(4, 4) = 1.0; - if (ista > 0) { // STS tracks has been propagated already - Double_t zbeg = parFirst.GetZ(); - Double_t dz = fZabs0[iabs][1] - zbeg; - // Propagate params - parFirst.SetX(parFirst.GetX() + dz * parFirst.GetTx()); - parFirst.SetY(parFirst.GetY() + dz * parFirst.GetTy()); - parFirst.SetZ(parFirst.GetZ() + dz); - TMatrixF ff = unit; - ff(2, 0) = ff(3, 1) = dz; - //cout << " Cov: " << dz << " " << cov(0,0) << " " << cov(1,1) << endl; - TMatrixF cf(cov, TMatrixF::kMult, ff); - TMatrixF fcf(ff, TMatrixF::kTransposeMult, cf); - cov.SetMatrixArray(fcf.GetMatrixArray()); - if (ist == 0 && iabs > 0) PassAbsorber(ist + iabs * 2, fZabs0[iabs], fX0abs[iabs], parFirst, cov, 0); - //if (ist) cov.Print(); ; - } - cov.Invert(); // weight matrix - parFirst.SetCovMatrix(cov); - //tr->SetParamFirst(&parFirst); - tr->SetParamLast(&parFirst); - xMap[ist].insert(pair<Double_t, pair<Int_t, CbmMuchTrack*>>(parFirst.GetX(), *it)); - matchOK[ist][tr] = -1; - } - } // for (Int_t ist = 0; ist < 2; - - Int_t ista0 = iabs - 1 + 1, ista1 = iabs + 1; - - for (mit = xMap[0].begin(); mit != xMap[0].end(); ++mit) { - CbmMuchTrack* tr1 = mit->second.second; - FairTrackParam parOk = *tr1->GetParamLast(); - FairTrackParam par1 = *tr1->GetParamLast(); - TMatrixFSym w1(5); - par1.CovMatrix(w1); - Float_t pars1[5] = {(Float_t) par1.GetX(), (Float_t) par1.GetY(), (Float_t) par1.GetTx(), (Float_t) par1.GetTy(), - 1.0}; - TMatrixF p1(5, 1, pars1); - TMatrixF wp1(w1, TMatrixF::kTransposeMult, p1); - Double_t x0 = parOk.GetX(), y0 = parOk.GetY(); - mitb = xMap[1].lower_bound(x0 - window); // lower X-window edge - mite = xMap[1].upper_bound(x0 + window); // upper X-window edge - - for (mit1 = mitb; mit1 != mite; ++mit1) { - CbmMuchTrack* tr2 = mit1->second.second; - FairTrackParam par2 = *tr2->GetParamLast(); - if (par2.GetY() - y0 < -window) continue; - if (par2.GetY() - y0 > window) continue; - TMatrixFSym w2(5); - par2.CovMatrix(w2); - TMatrixFSym w20 = w2; - Float_t pars2[5] = {(Float_t) par2.GetX(), (Float_t) par2.GetY(), (Float_t) par2.GetTx(), - (Float_t) par2.GetTy(), 1.0}; - TMatrixF p2(5, 1, pars2); - TMatrixF wp2(w2, TMatrixF::kTransposeMult, p2); - wp2 += wp1; - w2 += w1; - w2.Invert(); - TMatrixF p12(w2, TMatrixF::kTransposeMult, wp2); - - // Compute Chi2 - TMatrixF p122 = p12; - TMatrixF pMerge = p12; - p12 -= p1; - TMatrixF wDp1(w1, TMatrixF::kMult, p12); - TMatrixF chi21(p12, TMatrixF::kTransposeMult, wDp1); - p122 -= p2; - TMatrixF wDp2(w20, TMatrixF::kMult, p122); - TMatrixF chi22(p122, TMatrixF::kTransposeMult, wDp2); - Double_t c2 = chi21(0, 0) + chi22(0, 0); - //cout << " Chi2: " << chi21(0,0) << " " << chi22(0,0) << " " << c2 << endl; - if (c2 < 0 || c2 > fCutChi2[iabs]) continue; - matchOK[0][tr1] = 1; - matchOK[1][tr2] = 1; - // Merged track parameters - /* - parOk.SetX(pMerge(0,0)); - parOk.SetY(pMerge(1,0)); - parOk.SetZ(par2.GetZ()); - parOk.SetTx(pMerge(2,0)); - parOk.SetTy(pMerge(3,0)); - parOk.SetCovMatrix(w2); - */ - //AddTrack(ista0, tr1, tr2, mit->second.first, mit1->second.first, parOk, c2); // add track - } // for (mit1 = xMap[1].begin(); - } // for (mit = xMap[0].begin(); - - for (Int_t ist = 0; ist < 2; ++ist) { - Int_t ista = iabs - 1 + ist + 1; - - for (it = fVectors[ista].begin(); it != fVectors[ista].end(); ++it) { - CbmMuchTrack* tr = it->second; - if (matchOK[ist][tr] > 0) continue; - if (ista == 0) delete tr; - fVectors[ista].erase(it); - } - cout << " MergeVectors: vectors after matching in station " << ista << ": " << fVectors[ista].size() << endl; - } - } // for (Int_t iabs = 2; iabs >= 0; -} -// ------------------------------------------------------------------------- - -// ----- Private method MergeVectors ----------------------------------- -void CbmMuchMergeVectors::MergeVectors() -{ - // Match vectors (CbmMuchTracks) from 2 stations - - const Double_t window0 = 5.0; //10.0; // - TMatrixF matr = TMatrixF(5, 5); - TMatrixF unit(TMatrixF::kUnit, matr); - map<Int_t, CbmMuchTrack*>::iterator it, it1; - multimap<Double_t, pair<Int_t, CbmMuchTrack*>> xMap[2]; - multimap<Double_t, pair<Int_t, CbmMuchTrack*>>::iterator mit, mit1; - - for (Int_t iabs = 0; iabs <= 3; ++iabs) { - Int_t ibeg = fTrackArray->GetEntriesFast(); - xMap[0].clear(); - xMap[1].clear(); - - for (Int_t ist = 0; ist < 2; ++ist) { - // Propagate vectors to the absorber faces - Int_t ista = iabs - 1 + ist + 1; - //if (iabs == 1 && ist == 0) --ista; // !!! take extrapolated STS tracks - skip first station - Int_t imerged = (fVectors[ista].begin()->first < 0) ? 1 : 0; // merged vectors stored with negative station No. - for (it = fVectors[ista].begin(); it != fVectors[ista].end(); ++it) { - if (imerged && it->first >= 0) break; // for merged vectors: skip original (unmerged) vectors - CbmMuchTrack* tr = it->second; - FairTrackParam parFirst = *tr->GetParamFirst(); - //if (ist == 0) parFirst = *tr->GetParamLast(); - Double_t zbeg = parFirst.GetZ(); - //Double_t dz = zAbs0[iabs][ist] - zbeg; - Double_t dz = fZabs0[iabs][1] - zbeg; - //Double_t dz = fZabs0[iabs][0] - zbeg; - //Double_t dz = (zAbs0[iabs][0] + zAbs0[iabs][1]) / 2 - zbeg; - // Propagate params - parFirst.SetX(parFirst.GetX() + dz * parFirst.GetTx()); - parFirst.SetY(parFirst.GetY() + dz * parFirst.GetTy()); - parFirst.SetZ(parFirst.GetZ() + dz); - TMatrixFSym cov(5); - parFirst.CovMatrix(cov); - cov(4, 4) = 1.0; - //cov.Print(); - TMatrixF ff = unit; - //ff.Print(); - //ff(0,2) = ff(1,3) = dz; - ff(2, 0) = ff(3, 1) = dz; - //cout << " Cov: " << dz << " " << cov(0,0) << " " << cov(1,1) << endl; - TMatrixF cf(cov, TMatrixF::kMult, ff); - TMatrixF fcf(ff, TMatrixF::kTransposeMult, cf); - cov.SetMatrixArray(fcf.GetMatrixArray()); - //cout << " Cov1: " << dz << " " << cov(0,0) << " " << cov(1,1) << endl; - // Go thru absorber - //if (ist) { cov.Print(); cout << " -0- " << endl; } - //AZ if (ist == 0) { - if (ist == 0 && iabs > 0) { - if (iabs == 1) PassAbsorber(ist + iabs * 2, fZabs0[iabs], fX0abs[iabs], parFirst, cov, - 1); // STS track - else - PassAbsorber(ist + iabs * 2, fZabs0[iabs], fX0abs[iabs], parFirst, cov, 1); - } - //if (ist) cov.Print(); ; - cov.Invert(); // weight matrix - parFirst.SetCovMatrix(cov); - //tr->SetParamFirst(&parFirst); - tr->SetParamLast(&parFirst); - xMap[ist].insert(pair<Double_t, pair<Int_t, CbmMuchTrack*>>(parFirst.GetX(), *it)); - - //Info("MergeVectors", "Absorber %i, station %i, trID %i, X = %f, Y = %f, Z = %f", iabs,ista, - // tr->GetFlag(),parFirst.GetX(),parFirst.GetY(),parFirst.GetZ()); - //cov.Print(); - } - } // for (Int_t ist = 0; ist < 2; - - Int_t ista0 = iabs - 1 + 1, ista1 = iabs + 1; - //if (iabs == 1 && ista0 == 1) --ista0; // !!! take extrapolated STS tracks - skip first station - map<Int_t, CbmMuchTrack*> mapMerged; - Double_t window = window0; - if (iabs == 3) window *= 2; - - for (mit = xMap[0].begin(); mit != xMap[0].end(); ++mit) { - //Int_t imerged0 = (fVectors[ista0].begin()->first < 0) ? 1: 0; - //if (iabs && !imerged0) break; //!!! no track merging occured for previous absorber - //Int_t imerged1 = (fVectors[ista1].begin()->first < 0) ? 1: 0; - //if (imerged0 && it->first >= 0) break; // for merged tracks: exclude original vectors - CbmMuchTrack* tr1 = mit->second.second; - FairTrackParam parOk = *tr1->GetParamLast(); - //if (1./parOk.GetQp() < 0.1) continue; // too low momentum - if (1. / parOk.GetQp() < 0.05) continue; // too low momentum - FairTrackParam par1 = *tr1->GetParamLast(); - TMatrixFSym w1(5); - par1.CovMatrix(w1); - Float_t pars1[5] = {(Float_t) par1.GetX(), (Float_t) par1.GetY(), (Float_t) par1.GetTx(), (Float_t) par1.GetTy(), - 1.0}; - TMatrixF p1(5, 1, pars1); - TMatrixF wp1(w1, TMatrixF::kTransposeMult, p1); - Double_t x0 = parOk.GetX(), y0 = parOk.GetY(); - - for (mit1 = xMap[1].begin(); mit1 != xMap[1].end(); ++mit1) { - //if (imerged1 && it1->first >= 0) break; // for merged tracks: exclude original vectors - CbmMuchTrack* tr2 = mit1->second.second; - //if (tr2->GetUniqueID() == 2 && fNdoubl == 3 && 1./parOk.GetQp() < 0.05+0.37) break; // exclude low-mom. tracks - for merged straw stations (0.37 - energy loss in last absorber) - //FairTrackParam par2 = *tr2->GetParamFirst(); - FairTrackParam par2 = *tr2->GetParamLast(); - if (par2.GetX() - x0 < -window) continue; - if (par2.GetX() - x0 > window) break; - if (par2.GetY() - y0 < -window) continue; - if (par2.GetY() - y0 > window) continue; - TMatrixFSym w2(5); - par2.CovMatrix(w2); - TMatrixFSym w20 = w2; - Float_t pars2[5] = {(Float_t) par2.GetX(), (Float_t) par2.GetY(), (Float_t) par2.GetTx(), - (Float_t) par2.GetTy(), 1.0}; - TMatrixF p2(5, 1, pars2); - TMatrixF wp2(w2, TMatrixF::kTransposeMult, p2); - wp2 += wp1; - w2 += w1; - w2.Invert(); - TMatrixF p12(w2, TMatrixF::kTransposeMult, wp2); - //p12.Print(); - - // Compute Chi2 - TMatrixF p122 = p12; - TMatrixF pMerge = p12; - p12 -= p1; - TMatrixF wDp1(w1, TMatrixF::kMult, p12); - TMatrixF chi21(p12, TMatrixF::kTransposeMult, wDp1); - p122 -= p2; - TMatrixF wDp2(w20, TMatrixF::kMult, p122); - TMatrixF chi22(p122, TMatrixF::kTransposeMult, wDp2); - Double_t c2 = chi21(0, 0) + chi22(0, 0); - //cout << " Chi2: " << chi21(0,0) << " " << chi22(0,0) << " " << c2 << endl; - if (c2 < 0 || c2 > fCutChi2[iabs]) continue; - // Merged track parameters - parOk.SetX(pMerge(0, 0)); - parOk.SetY(pMerge(1, 0)); - parOk.SetZ(par2.GetZ()); - parOk.SetTx(pMerge(2, 0)); - parOk.SetTy(pMerge(3, 0)); - parOk.SetCovMatrix(w2); - AddTrack(ista0, tr1, tr2, mit->second.first, mit1->second.first, parOk, - c2); // add track - Int_t evNo = FairRun::Instance()->GetEventHeader()->GetMCEntryNumber(); - //fprintf(lun1,"%6d %6d %6d %10.3e \n",evNo,tr1->GetFlag(),tr2->GetFlag(),c2); - /* Debug - TMatrixFSym covA = w1; - covA.Invert(); - if (lun1 && tr1->GetFlag() == tr2->GetFlag() && tr1->GetFlag() < 2) fprintf(lun1,"%6d %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e\n",evNo,par1.GetX()-par2.GetX(),par1.GetY()-par2.GetY(),par1.GetTx()-par2.GetTx(),par1.GetTy()-par2.GetTy(),TMath::Sqrt(covA(0,0)),TMath::Sqrt(covA(1,1)),TMath::Sqrt(covA(2,2)),TMath::Sqrt(covA(3,3))); - */ - } // for (it1 = fVectors[ista1].begin(); - } // for (it = fVectors[ista0].begin(); - - // Remove clones for each absorber - //RemoveClones(ibeg, iabs, mapMerged); - RemoveClones(ibeg, -1, mapMerged); - //if (iabs == 3) RemoveClones(ibeg, -1, mapMerged); // !!! remove clones - //else RemoveClones(ibeg, 1, mapMerged); // !!! do not remove clones - if (mapMerged.size() == 0) break; // no merging with STS tracks !!! - - // Add merged tracks - for (it = mapMerged.begin(); it != mapMerged.end(); ++it) { - fVectors[ista1][it->first] = it->second; - } - - } // for (Int_t iabs = 0; iabs <= 3; -} -// ------------------------------------------------------------------------- - -// ----- Private method PassAbsorber ----------------------------------- -void CbmMuchMergeVectors::PassAbsorber(Int_t ist, Double_t* zabs, Double_t x0, FairTrackParam& parFirst, - TMatrixFSym& cov, Int_t pFlag) -{ - // Go thru absorber - - Double_t x = parFirst.GetX(); - Double_t y = parFirst.GetY(); - Double_t z = parFirst.GetZ(); - Double_t tx = parFirst.GetTx(); - Double_t ty = parFirst.GetTy(); - //Double_t dz = zabs[0] - z; - Double_t dz = (zabs[0] - zabs[1]) / 1; - - // Propagate params - //parFirst.SetX(x + dz * tx); - //parFirst.SetY(y + dz * ty); - //parFirst.SetZ(z + dz); - //return; - - Double_t aaa = 1.0 + tx * tx + ty * ty; - dz *= TMath::Sqrt(aaa); // - Double_t l = TMath::Abs(dz); - Double_t l2 = l * l; - Double_t l3 = l2 * l; - - TMatrixFSym covMS(5); - //covMS(0,0) = l3 / 3 * (1.0 + tx * tx); - //covMS(1,1) = l3 / 3 * (1.0 + ty * ty); - //covMS(2,2) = l * (1.0 + tx * tx); - //covMS(3,3) = l * (1.0 + ty * ty); - covMS(0, 0) = l2 / 3 * (1.0 + tx * tx); - covMS(1, 1) = l2 / 3 * (1.0 + ty * ty); - covMS(2, 2) = 1 * (1.0 + tx * tx); - covMS(3, 3) = 1 * (1.0 + ty * ty); - - //covMS(0,1) = covMS(1,0) = l3 / 3 * tx * ty; - covMS(0, 1) = covMS(1, 0) = l2 / 3 * tx * ty; - - Int_t icor = (ist % 2 == 0) ? 1 : -1; - //icor = -1; // - - //covMS(0,2) = covMS(2,0) = icor * l2 / 2 * (1.0 + tx * tx); - //covMS(1,2) = covMS(2,1) = icor * l2 / 2 * tx * ty; - covMS(0, 2) = covMS(2, 0) = icor * l / 2 * (1.0 + tx * tx); - covMS(1, 2) = covMS(2, 1) = icor * l / 2 * tx * ty; - - //covMS(0,3) = covMS(3,0) = icor * l2 / 2 * tx * ty; - //covMS(1,3) = covMS(3,1) = icor * l2 / 2 * (1.0 + ty * ty); - //covMS(2,3) = covMS(3,2) = l * tx * ty; - covMS(0, 3) = covMS(3, 0) = icor * l / 2 * tx * ty; - covMS(1, 3) = covMS(3, 1) = icor * l / 2 * (1.0 + ty * ty); - covMS(2, 3) = covMS(3, 2) = 1 * tx * ty; - - covMS *= aaa; - - Double_t dxx0 = l / x0, angle = 0.0; - if (pFlag == 0) angle = 0.0136 / 0.985 / 0.6 * (1. + 0.038 * TMath::Log(dxx0)); // mu at p = 0.6 - peak at 8A GeV - //if (pFlag == 0) angle = 0.0136 / 0.997 / 1.3 * (1. + 0.038 * TMath::Log(dxx0)); // mu at p = 1.3 GeV - else { - Double_t pmom = 1.0 / TMath::Abs(parFirst.GetQp()); - Double_t beta = pmom / TMath::Sqrt(pmom * pmom + 0.106 * 0.106); - angle = 0.0136 / beta / pmom * (1. + 0.038 * TMath::Log(dxx0)); - } - //covMS *= (angle * angle / x0); - covMS *= (angle * angle * dxx0); - cov += covMS; - if (pFlag == 0) return; // no momentum update - - // Momentum update due to energy loss - Double_t pLoss[6] = {0.25, 0.25, 0.25, 0.37, 0, 0}; - Double_t ppp = 1. / parFirst.GetQp(); - ppp -= (pLoss[ist / 2] * TMath::Sqrt(aaa)); // ppp is always non-negative - parFirst.SetQp(1. / ppp); -} -// ------------------------------------------------------------------------- - -// ----- Private method AddTrack --------------------------------------- -void CbmMuchMergeVectors::AddTrack(Int_t ista0, CbmMuchTrack* tr1, CbmMuchTrack* tr2, Int_t indx1, Int_t indx2, - FairTrackParam& parOk, Double_t c2) -{ - // Store merged vector (CbmMuchTracks) into TClonesArray - - Int_t ntrs = fTrackArray->GetEntriesFast(); - - CbmMuchTrack* track = new ((*fTrackArray)[ntrs]) CbmMuchTrack(); - //track->SetParamFirst(tr2->GetParamFirst()); - track->SetParamFirst(&parOk); - if (tr1->GetUniqueID() == -9) { - // Exclude STS track chi2 - track->SetChiSq(c2 + tr2->GetChiSq()); - track->SetNDF(4 + tr2->GetNDF()); - } - else { - track->SetChiSq(c2 + tr1->GetChiSq() + tr2->GetChiSq()); - track->SetNDF(4 + tr1->GetNDF() + tr2->GetNDF()); - } - track->SetUniqueID(tr2->GetUniqueID()); // station number - //track->SetPreviousTrackId(tr1->GetPreviousTrackId()); - track->SetPreviousTrackId(indx1); - if (indx1 >= 0) { - if (ista0) track->AddHit(indx1, kMUCHSTRAWHIT); // add vector index - //else track->AddHit(indx1, kHIT); // add STS vector index - else - track->AddHit(tr1->GetPreviousTrackId(), kHIT); // add STS track index - //if (indx2 < 0) track->SetPreviousTrackId(-indx2 - 1); // index of previous track - } - else { - // Merged track - Int_t nmerged = tr1->GetNofHits(); - for (Int_t j = 0; j < nmerged; ++j) - track->AddHit(tr1->GetHitIndex(j), - tr1->GetHitType(j)); // add vector index - if (indx1 < 0) track->SetPreviousTrackId(-indx1 - 1); // index of previous track - } - if (indx2 >= 0) track->AddHit(indx2, kMUCHSTRAWHIT); // add vector index - else { - // Merged track - Int_t nmerged = tr2->GetNofHits(); - for (Int_t j = 0; j < nmerged; ++j) - track->AddHit(tr2->GetHitIndex(j), - tr2->GetHitType(j)); // add vector index - } - if (tr1->GetFlag() == tr2->GetFlag()) track->SetFlag(tr1->GetFlag()); - else - track->SetFlag(-1); - - //Info("AddTrack", "trID1=%i, trID2=%i, chi2=%f, merged vectors %i", tr1->GetFlag(),tr2->GetFlag(),track->GetChiSq(),track->GetNofHits()); - gLogger->Info(MESSAGE_ORIGIN, - "CbmMuchMergeVectors::AddTrack: ista=%i, trID1=%i, trID2=%i, " - "chi2=%f, merged vectors %i", - ista0, tr1->GetFlag(), tr2->GetFlag(), track->GetChiSq(), track->GetNofHits()); -} -// ------------------------------------------------------------------------- - -// ----- Private method RemoveClones ----------------------------------- -void CbmMuchMergeVectors::RemoveClones(Int_t ibeg, Int_t iabs, map<Int_t, CbmMuchTrack*>& mapMerged) -{ - // Remove clone tracks (having at least 1 the same vector) - - Int_t ntrs = fTrackArray->GetEntriesFast(); - - if (iabs != 1) { // Do not remove clones when merging stations 0 and 1 - multimap<Double_t, Int_t> c2merge; - for (Int_t i1 = ibeg; i1 < ntrs; ++i1) { - CbmMuchTrack* tr1 = (CbmMuchTrack*) fTrackArray->UncheckedAt(i1); - /* - Double_t qual = 0.0; - if (tr1->GetUniqueID() == 9) { - CbmMuchTrack *trLit = (CbmMuchTrack*) fTracksLit->UncheckedAt(tr1->GetHitIndex(0)); - qual = trLit->GetNofHits() + (499 - TMath::Min(tr1->GetChiSq(),499.0)) / 500; - } else qual = tr1->GetNofHits() + (499 - TMath::Min(tr1->GetChiSq(),499.0)) / 500; - */ - Double_t qual = tr1->GetNofHits() + (499 - TMath::Min(tr1->GetChiSq() / tr1->GetNDF(), 499.0)) / 500; - c2merge.insert(pair<Double_t, Int_t>(-qual, i1)); - } - - multimap<Double_t, Int_t>::iterator it, it1; - for (it = c2merge.begin(); it != c2merge.end(); ++it) { - CbmMuchTrack* tr1 = (CbmMuchTrack*) fTrackArray->UncheckedAt(it->second); - if (tr1 == NULL) continue; - Int_t nvecs1 = tr1->GetNofHits(); - - it1 = it; - for (++it1; it1 != c2merge.end(); ++it1) { - CbmMuchTrack* tr2 = (CbmMuchTrack*) fTrackArray->UncheckedAt(it1->second); - if (tr2 == NULL) continue; - Int_t nvecs2 = tr2->GetNofHits(); - if (tr2->GetUniqueID() != tr1->GetUniqueID()) continue; - - Bool_t over = kFALSE; - for (Int_t iv1 = 0; iv1 < nvecs1; ++iv1) { - for (Int_t iv2 = iv1; iv2 < nvecs2; ++iv2) { - //for (Int_t iv1 = 0; iv1 < 2; ++iv1) { - //for (Int_t iv2 = iv1; iv2 < 2; ++iv2) { - if (iv2 != iv1) continue; - if (tr1->GetHitType(iv1) != tr2->GetHitType(iv2)) continue; - //if (tr1->GetUniqueID() == 9 && iv1 == 1) continue; // !!! share vectors in 1st station - if (tr1->GetHitIndex(iv1) != tr2->GetHitIndex(iv2)) continue; - // Count number of overlaps for the given vector - if (iv2) { - CbmMuchTrack* vec = (CbmMuchTrack*) fVecArray->UncheckedAt(tr2->GetHitIndex(iv2)); - Int_t clones = vec->GetPreviousTrackId(); - ++clones; - if (clones == 0) ++clones; - vec->SetPreviousTrackId(clones); - } - gLogger->Info(MESSAGE_ORIGIN, - "CbmMuchMergeVectors:RemoveClones: qual1 %f, qual2 " - "%f, trID1 %i, trID2 %i, ista %i, p1 %f, p2 %f", - it->first, it1->first, tr1->GetFlag(), tr2->GetFlag(), iv1, 1 / tr1->GetParamFirst()->GetQp(), - 1 / tr2->GetParamFirst()->GetQp()); - fTrackArray->RemoveAt(it1->second); - over = kTRUE; - break; - } - if (over) break; - } - } - } - fTrackArray->Compress(); - } // if (iabs != 1) - - ntrs = fTrackArray->GetEntriesFast(); - // Add track to the map (with negative index) - for (Int_t i1 = ibeg; i1 < ntrs; ++i1) { - CbmMuchTrack* tr1 = (CbmMuchTrack*) fTrackArray->UncheckedAt(i1); - mapMerged[-i1 - 1] = tr1; - } -} -// ------------------------------------------------------------------------- - -// ----- Private method SelectTracks ----------------------------------- -void CbmMuchMergeVectors::SelectTracks() -{ - // Remove ghost tracks (having at least N the same hits (i.e. fired tubes)) - - const Int_t nMax[2] = {2, 2}, nPl = 40; - //Int_t nVecMin = (fNdoubl == 3) ? 4 : 5; - Int_t nVecMin = 4; - Int_t planes[nPl], ntrs = fTrackArray->GetEntriesFast(); - - multimap<Double_t, Int_t> c2merge; - for (Int_t i = 0; i < ntrs; ++i) { - CbmMuchTrack* tr = (CbmMuchTrack*) fTrackArray->UncheckedAt(i); - if (tr->GetNofHits() < nVecMin) continue; - /* - Double_t qual = 0.0; - if (tr->GetUniqueID() == 9) { - CbmMuchTrack *trLit = (CbmMuchTrack*) fTracksLit->UncheckedAt(tr->GetHitIndex(0)); - qual = trLit->GetNofHits() + (499 - TMath::Min(tr->GetChiSq(),499.0)) / 500; - } else qual = tr->GetNofHits() + (499 - TMath::Min(tr->GetChiSq(),499.0)) / 500; - */ - Double_t qual = tr->GetNofHits() + (499 - TMath::Min(tr->GetChiSq() / tr->GetNDF(), 499.0)) / 500; - c2merge.insert(pair<Double_t, Int_t>(-qual, i)); - } - if (c2merge.size() < 2) return; - - multimap<Double_t, Int_t>::iterator it, it1; - for (it = c2merge.begin(); it != c2merge.end(); ++it) { - CbmMuchTrack* tr1 = (CbmMuchTrack*) fTrackArray->UncheckedAt(it->second); - if (tr1 == NULL) continue; - Int_t nvecs1 = tr1->GetNofHits(); - for (Int_t j = 0; j < nPl; ++j) - planes[j] = -1; - - for (Int_t iv = 0; iv < nvecs1; ++iv) { - if (tr1->GetHitType(iv) == kHIT) { - // STS track - planes[nPl - 1] = tr1->GetHitIndex(iv); - continue; - } - CbmMuchTrack* vec = (CbmMuchTrack*) fVecArray->UncheckedAt(tr1->GetHitIndex(iv)); - TClonesArray* hits = fHits; - if (vec->GetUniqueID() < 2 || fStatFirst < 0) hits = fGemHits; - Int_t nh = vec->GetNofHits(); - for (Int_t ih = 0; ih < nh; ++ih) { - CbmHit* hit = (CbmHit*) hits->UncheckedAt(vec->GetHitIndex(ih)); - Int_t ipl = hit->GetPlaneId() - 1; - planes[ipl] = vec->GetHitIndex(ih); - } - } - - it1 = it; - for (++it1; it1 != c2merge.end(); ++it1) { - CbmMuchTrack* tr2 = (CbmMuchTrack*) fTrackArray->UncheckedAt(it1->second); - if (tr2 == NULL) continue; - //if (tr2->GetUniqueID() != tr1->GetUniqueID()) continue; - Int_t nvecs2 = tr2->GetNofHits(), nover[2] = {0}; - Bool_t over = kFALSE; - - for (Int_t iv = 0; iv < nvecs2; ++iv) { - if (tr2->GetHitType(iv) == kHIT) { - // STS track - if (planes[nPl - 1] >= 0 && planes[nPl - 1] == tr2->GetHitIndex(iv)) { - // The same STS track - gLogger->Info(MESSAGE_ORIGIN, - "Track quality: qual1 %f, qual2 %f, trID1 %i, trID2 " - "%i, the same STS track: %i", - it->first, it1->first, tr1->GetFlag(), tr2->GetFlag(), tr2->GetHitIndex(iv)); - fTrackArray->RemoveAt(it1->second); - break; - } - if (tr2->GetUniqueID() != tr1->GetUniqueID()) break; - continue; - } - CbmMuchTrack* vec = (CbmMuchTrack*) fVecArray->UncheckedAt(tr2->GetHitIndex(iv)); - Int_t nh = vec->GetNofHits(); - TClonesArray* hits = fHits; - if (vec->GetUniqueID() < 2 || fStatFirst < 0) hits = fGemHits; - for (Int_t ih = 0; ih < nh; ++ih) { - CbmHit* hit = (CbmHit*) hits->UncheckedAt(vec->GetHitIndex(ih)); - Int_t ipl = hit->GetPlaneId() - 1; - if (planes[ipl] < 0) continue; - if (planes[ipl] == vec->GetHitIndex(ih)) { - if (hits == fGemHits) ++nover[0]; - else - ++nover[1]; - if (nover[0] >= nMax[0] || nover[1] >= nMax[1]) { - //cout << ipl << " " << vec->GetHitIndex(ih) << endl; - gLogger->Info(MESSAGE_ORIGIN, - "Track quality: qual1 %f, qual2 %f, trID1 %i, " - "trID2 %i, overlaps: %i, %i", - it->first, it1->first, tr1->GetFlag(), tr2->GetFlag(), nover[0], nover[1]); - fTrackArray->RemoveAt(it1->second); - over = kTRUE; - break; - } - } - } - if (over) break; - } // for (Int_t iv = 0; iv < nvecs2; - - } // for (++it1; it1 != c2merge.end(); - } - fTrackArray->Compress(); -} -// ------------------------------------------------------------------------- - -// ------ Private method AddStation1 ----------------------------------- -void CbmMuchMergeVectors::AddStation1() -{ - // Add vector from the first station as a filter - - const Int_t nVecsMin = 4; - map<Int_t, CbmMuchTrack*>::iterator it, it1; - TMatrixF matr = TMatrixF(5, 5); - TMatrixF unit(TMatrixF::kUnit, matr); - - if (fVectors[0].size() == 0) return; - //if (fVectors[0].begin()->first >= 0) return; // no merged tracks were found - if (fVectors[0].begin()->second->GetNofHits() != nVecsMin) return; // no long tracks were found - - for (Int_t ist = 0; ist < 1; ++ist) { - - // Propagate vectors to the absorber faces - Int_t iabs = 0, ista = 1; - for (it = fVectors[ista].begin(); it != fVectors[ista].end(); ++it) { - //if (imerged && it->first >= 0) break; // for merged vectors: skip original (unmerged) vectors - CbmMuchTrack* tr = it->second; - FairTrackParam parFirst = *tr->GetParamFirst(); - //if (ist == 0) parFirst = *tr->GetParamLast(); - Double_t zbeg = parFirst.GetZ(); - Double_t dz = fZabs0[iabs][1] - zbeg; - // Propagate params - parFirst.SetX(parFirst.GetX() + dz * parFirst.GetTx()); - parFirst.SetY(parFirst.GetY() + dz * parFirst.GetTy()); - parFirst.SetZ(parFirst.GetZ() + dz); - TMatrixFSym cov(5); - parFirst.CovMatrix(cov); - cov(4, 4) = 1.0; - TMatrixF ff = unit; - ff(2, 0) = ff(3, 1) = dz; - TMatrixF cf(cov, TMatrixF::kMult, ff); - TMatrixF fcf(ff, TMatrixF::kTransposeMult, cf); - cov.SetMatrixArray(fcf.GetMatrixArray()); - cov.Invert(); // weight matrix - parFirst.SetCovMatrix(cov); - tr->SetParamFirst(&parFirst); - } // for (it = fVectors[ista].begin(); - } // for (Int_t ist = 0; ist < 1; - - // Get STS tracks extrapolated through the first absorber - Int_t nvecs = fVecArray->GetEntriesFast(); - for (it = fVectors[0].begin(); it != fVectors[0].end(); ++it) { - if (it->first >= 0) break; // no merged tracks anymore - Int_t indSts = (it->second)->GetHitIndex(0); // STS track index - CbmMuchTrack* tr1 = fVectors[0][nvecs + indSts]; - //cout << " STS index: " << indSts << " " << tr1->GetParamFirst()->GetX() << " " << tr1->GetParamFirst()->GetY() << endl; - - // Merge with vectors from first station - FairTrackParam parOk = *tr1->GetParamFirst(); - FairTrackParam par1 = *tr1->GetParamFirst(); - TMatrixFSym w1(5); - par1.CovMatrix(w1); - w1.Invert(); // weight matrix - Float_t pars1[5] = {(Float_t) par1.GetX(), (Float_t) par1.GetY(), (Float_t) par1.GetTx(), (Float_t) par1.GetTy(), - 1.0}; - TMatrixF p1(5, 1, pars1); - TMatrixF wp1(w1, TMatrixF::kTransposeMult, p1); - Double_t c2min = 999999.0; - //cout << " STS " << endl; - //par1.Print(); - //cout << TMath::Sqrt(par1.GetCovariance(0,0)) << " " << TMath::Sqrt(par1.GetCovariance(1,1)) << endl; - - Int_t iabs = 0, ista1 = 1; - for (it1 = fVectors[ista1].begin(); it1 != fVectors[ista1].end(); ++it1) { - CbmMuchTrack* tr2 = it1->second; - FairTrackParam par2 = *tr2->GetParamFirst(); - //cout << " MUCH " << endl; - //par2.Print(); - //cout << TMath::Sqrt(par2.GetCovariance(0,0)) << " " << TMath::Sqrt(par2.GetCovariance(1,1)) << endl; - TMatrixFSym w2(5); - par2.CovMatrix(w2); - //w2.Invert(); // weight matrix - TMatrixFSym w20 = w2; - Float_t pars2[5] = {(Float_t) par2.GetX(), (Float_t) par2.GetY(), (Float_t) par2.GetTx(), (Float_t) par2.GetTy(), - 1.0}; - TMatrixF p2(5, 1, pars2); - TMatrixF wp2(w2, TMatrixF::kTransposeMult, p2); - wp2 += wp1; - w2 += w1; - w2.Invert(); - TMatrixF p12(w2, TMatrixF::kTransposeMult, wp2); - //p12.Print(); - - // Compute Chi2 - TMatrixF p122 = p12; - p12 -= p1; - TMatrixF wDp1(w1, TMatrixF::kMult, p12); - TMatrixF chi21(p12, TMatrixF::kTransposeMult, wDp1); - p122 -= p2; - TMatrixF wDp2(w20, TMatrixF::kMult, p122); - TMatrixF chi22(p122, TMatrixF::kTransposeMult, wDp2); - Double_t c2 = chi21(0, 0) + chi22(0, 0); - //cout << " Chi2: " << chi21(0,0) << " " << chi22(0,0) << " " << c2 << endl; - if (c2 < 0 || c2 > fCutChi2[iabs]) continue; - // Add track - if (c2 < c2min) c2min = c2; - //AddTrack(0, tr1, tr2, it->first, it1->first, parOk, c2); // add track - } // for (it1 = fVectors[ista1].begin(); - if (c2min / 4 > 5) { - gLogger->Info(MESSAGE_ORIGIN, "Stat.1: removed track: c2min %f", c2min / 4); - fTrackArray->RemoveAt(-it->first - 1); - } - else - cout << " Chi2: " << c2min / 4 << endl; - } // for (it = fVectors[0].begin(); - fTrackArray->Compress(); -} -// ------------------------------------------------------------------------- - -// ----- Private method AddTrack1 -------------------------------------- -void CbmMuchMergeVectors::AddTrack1(Int_t ista0, CbmMuchTrack* tr1, CbmMuchTrack* tr2, Int_t indx1, Int_t indx2, - FairTrackParam& parOk, Double_t c2) -{ - // Store merged vector (CbmMuchTracks) into TClonesArray - - Int_t ntrs = fTrackArray->GetEntriesFast(); - - CbmMuchTrack* track = new ((*fTrackArray)[ntrs]) CbmMuchTrack(); - track->SetParamFirst(&parOk); - track->SetChiSq(c2 + tr1->GetChiSq() + tr2->GetChiSq()); - track->SetNDF(4 + tr1->GetNDF() + tr2->GetNDF()); - track->SetUniqueID(tr1->GetUniqueID()); // station number - //track->SetPreviousTrackId(tr1->GetPreviousTrackId()); - track->SetPreviousTrackId(indx2); - // Add vectors - Int_t nmerged = tr1->GetNofHits(); - for (Int_t j = 0; j < nmerged; ++j) { - if (j == 0) track->AddHit(tr1->GetHitIndex(j), tr1->GetHitType(j)); // STS - else if (j == 1) - track->AddHit(indx2, kMUCHSTRAWHIT); // add stat.1 vector index - else - track->AddHit(tr1->GetHitIndex(j - 1), tr1->GetHitType(j - 1)); - } - if (tr1->GetFlag() == tr2->GetFlag()) track->SetFlag(tr1->GetFlag()); - else - track->SetFlag(-1); - - Info("AddTrack", "trID1=%i, trID2=%i, chi2=%f, merged vectors %i", tr1->GetFlag(), tr2->GetFlag(), track->GetChiSq(), - track->GetNofHits()); -} -// ------------------------------------------------------------------------- - -ClassImp(CbmMuchMergeVectors); diff --git a/reco/tracking/vector/CbmMuchMergeVectors.h b/reco/tracking/vector/CbmMuchMergeVectors.h deleted file mode 100644 index 4761ea2a493b5770513aca1799f699b666ddc239..0000000000000000000000000000000000000000 --- a/reco/tracking/vector/CbmMuchMergeVectors.h +++ /dev/null @@ -1,108 +0,0 @@ -/* Copyright (C) 2014-2018 Veksler and Baldin Laboratory of High Energy Physics, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Alexander Zinchenko [committer] */ - -/** CbmMuchMergeVectors.h - *@author A.Zinchenko <Alexander.Zinchenko@jinr.ru> - *@since 2014 - ** - ** Task class for vector merging in MUCH. - ** Input: TClonesArray of CbmMuchTrack - ** Output: TClonesArray of CbmMuchTrack - ** - **/ - -#ifndef CBMMUCHMERGEVECTORS_H_ -#define CBMMUCHMERGEVECTORS_H_ 1 - -#include "CbmMuchGeoScheme.h" - -#include "FairTask.h" -#include "FairTrackParam.h" - -#include <TDecompLU.h> - -#include <map> - -class CbmMuchTrack; -class TClonesArray; - -class CbmMuchMergeVectors : public FairTask { -public: - /** Default constructor **/ - CbmMuchMergeVectors(); - - /** Destructor **/ - virtual ~CbmMuchMergeVectors(); - - /** Initialisation **/ - virtual InitStatus Init(); - - /** Task execution **/ - virtual void Exec(Option_t* opt); - - /** Finish at the end **/ - virtual void Finish(); - - /** SetParContainers **/ - virtual void SetParContainers(); - - /** Accessors **/ - Int_t GetNofTracks() { return fNofTracks; }; - Int_t GetNofStat() const { return fgkStat; } - - void PassAbsorber(Int_t ist, Double_t* zabs, Double_t x0, FairTrackParam& parFirst, TMatrixFSym& cov, - Int_t pFlag = 0); - -private: - // Some constants - static const Int_t fgkPlanes = 8; // Number of straw planes per station - static const Int_t fgkStat = 5; //2; // Number of stations (including STS tracks) - -private: - CbmMuchGeoScheme* fGeoScheme; // Geometry scheme - TClonesArray* fTrackArray; // Output array of CbmMuchTrack - Int_t fNofTracks; // Number of tracks created - TClonesArray* fHits; // Input array of CbmMuchHit - TClonesArray* fGemHits; // Input array of CbmMuchHit - TClonesArray* fPoints; // Input array of CbmMuchPoint - TClonesArray* fDigiMatches; // Input array of CbmMatch - TClonesArray* fVecArray; // Input array of CbmMuchTrack - TClonesArray* fTracksSts; // Input array of CbmStsTrack - TClonesArray* fTrStsMatch; // Input array of CbmTrackMatch - TClonesArray* fTracksLit; // Input array of LIT MuchTrack - - Int_t fNstat; // Number of MUCH stations - Int_t fNdoubl; // Number of straw doublets per station - Int_t fStatFirst; // First straw station No. - std::map<Int_t, CbmMuchTrack*> fVectors[fgkStat]; // track vectors for stations - Double_t fDz[fgkPlanes]; // geometrical constants (Z-distances from layer 0) - Double_t fCosa[fgkPlanes]; // geometrical constants (cos of stereo angles) - Double_t fSina[fgkPlanes]; // geometrical constants (sin of stereo angles) - Double_t fCutChi2[9]; // Chi2-cuts for each absorber - Double_t fZ0[9]; // Z-positions of the first layers - Double_t fRmin[9]; // inner radii of stations - Double_t fRmax[9]; // outer radii of stations - std::map<Int_t, TMatrixDSym*> fMatr; // system matrices (for different hit layer patterns) - Double_t fZabs0[9][2]; // Z-positions of absorber faces - Double_t fX0abs[9]; // radiation lengths of the absorbers - - void GetVectors(); - void MatchVectors(); - void MergeVectors(); - void AddTrack(Int_t ista0, CbmMuchTrack* tr1, CbmMuchTrack* tr2, Int_t indx1, Int_t indx2, - //TMatrixF &par, Double_t c2); - FairTrackParam& parOk, Double_t c2); - void RemoveClones(Int_t ibeg, Int_t iabs, std::map<Int_t, CbmMuchTrack*>& mapMerged); - void SelectTracks(); - void AddStation1(); - void AddTrack1(Int_t ista0, CbmMuchTrack* tr1, CbmMuchTrack* tr2, Int_t indx1, Int_t indx2, FairTrackParam& parOk, - Double_t c2); - - CbmMuchMergeVectors(const CbmMuchMergeVectors&); - CbmMuchMergeVectors& operator=(const CbmMuchMergeVectors&); - - ClassDef(CbmMuchMergeVectors, 0) -}; - -#endif diff --git a/reco/tracking/vector/CbmMuchMergeVectorsQa.cxx b/reco/tracking/vector/CbmMuchMergeVectorsQa.cxx deleted file mode 100644 index df75d257970f3e39e3f33461f68d6b52e8dca5f4..0000000000000000000000000000000000000000 --- a/reco/tracking/vector/CbmMuchMergeVectorsQa.cxx +++ /dev/null @@ -1,453 +0,0 @@ -/* Copyright (C) 2014-2018 Veksler and Baldin Laboratory of High Energy Physics, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Alexander Zinchenko [committer] */ - -/** CbmMuchMergeVectorsQa.cxx - *@author A.Zinchenko <Alexander.Zinchenko@jinr.ru> - *@since 2014 - **/ -#include "CbmMuchMergeVectorsQa.h" -//#include "CbmMuchFindVectors.h" -#include "CbmMuchDigiMatch.h" -#include "CbmMuchFindHitsStraws.h" -#include "CbmMuchModule.h" -#include "CbmMuchPoint.h" -#include "CbmMuchStation.h" -#include "CbmMuchStrawHit.h" -#include "CbmMuchTrack.h" - -#include "FairEventHeader.h" -#include "FairRootManager.h" -#include "FairRunAna.h" - -#include <TClonesArray.h> -#include <TF1.h> -#include <TH1D.h> -#include <TH2D.h> -#include <TMath.h> -#include <TROOT.h> - -#include <iostream> - -using std::cout; -using std::endl; -using std::set; - -// ----- Default (stabdard) constructor -------------------------------- -CbmMuchMergeVectorsQa::CbmMuchMergeVectorsQa() - : FairTask("MuchMergeVectorsQA") - , fGeoScheme(CbmMuchGeoScheme::Instance()) - , fStatFirst(-1) - , fNstat(0) -{ -} -// ------------------------------------------------------------------------- - -// ----- Destructor ---------------------------------------------------- -CbmMuchMergeVectorsQa::~CbmMuchMergeVectorsQa() {} -// ------------------------------------------------------------------------- - -// ----- Public method Init (abstract in base class) -------------------- -InitStatus CbmMuchMergeVectorsQa::Init() -{ - - // Get and check FairRootManager - FairRootManager* ioman = FairRootManager::Instance(); - if (ioman == NULL) Fatal("Init", "RootManager not instantiated!"); - - //CbmMuchFindHitsStraws *hitFinder = (CbmMuchFindHitsStraws*) - //FairRun::Instance()->GetTask("CbmMuchFindHitsStraws"); - //if (hitFinder == NULL) Fatal("CbmMuchFindTracks::Init", "CbmMuchFindHitsStraws not run!"); - - fTracks = static_cast<TClonesArray*>(ioman->GetObject("MuchVectorTrack")); - fVectors = static_cast<TClonesArray*>(ioman->GetObject("MuchVector")); - fMCTracks = static_cast<TClonesArray*>(ioman->GetObject("MCTrack")); - fPoints = static_cast<TClonesArray*>(ioman->GetObject("MuchPoint")); - fHits = static_cast<TClonesArray*>(ioman->GetObject("MuchStrawHit")); - fHitsGem = static_cast<TClonesArray*>(ioman->GetObject("MuchPixelHit")); - fDigis = static_cast<TClonesArray*>(ioman->GetObject("MuchStrawDigi")); - fDigisGem = static_cast<TClonesArray*>(ioman->GetObject("MuchDigi")); - fDigiMatches = static_cast<TClonesArray*>(ioman->GetObject("MuchStrawDigiMatch")); - fDigiMatchesGem = static_cast<TClonesArray*>(ioman->GetObject("MuchDigiMatch")); - fClusters = static_cast<TClonesArray*>(ioman->GetObject("MuchCluster")); - - // Get straw system configuration - Int_t nSt = fGeoScheme->GetNStations(); - - for (Int_t i = 0; i < nSt; ++i) { - CbmMuchStation* st = fGeoScheme->GetStation(i); - CbmMuchModule* mod = fGeoScheme->GetModule(i, 0, 0, 0); - Int_t stat = CbmMuchAddress::GetStationIndex(st->GetDetectorId()); - if (mod->GetDetectorType() == 2 && fStatFirst < 0) fStatFirst = stat; - ++fNstat; - Int_t nLays = st->GetNLayers(); - fNdoubl[stat] = nLays; - - for (Int_t lay = 0; lay < nLays; ++lay) { - CbmMuchLayer* layer = st->GetLayer(lay); - - for (Int_t iside = 0; iside < 2; ++iside) { - CbmMuchLayerSide* side = layer->GetSide(iside); - Int_t plane = lay * 2 + iside; - fZpos[stat][plane] = side->GetZ(); - } - } - } - - if (fStatFirst < 0) fStatFirst = 99; // all GEM stations - - // Create directory for histograms - TDirectory* dir0 = (TDirectory*) gROOT->FindObjectAny("muchQA"); - TDirectory* dir = new TDirectory("muchQA1", "", "", dir0); - dir->cd(); - - BookHistos(); - - return kSUCCESS; -} -// ------------------------------------------------------------------------- - -// ----- SetParContainers ------------------------------------------------- -void CbmMuchMergeVectorsQa::SetParContainers() {} -// ------------------------------------------------------------------------- - -// ----- Private method BookHistos ------------------------------------- -void CbmMuchMergeVectorsQa::BookHistos() -{ - // Book histograms - - fhChi2mat = new TH1D*[fNstat + 2]; - - for (Int_t ist = 0; ist < fNstat; ++ist) { - //Int_t stat = fStatFirst + ist; - Int_t stat = 1 + ist; - fhChi2mat[ist] = new TH1D(Form("hChi2mat%i", stat), Form("Chi2 of matching in station %i", stat), 100, 0, 50); - } - fhChi2mat[fNstat] = new TH1D("hChi2mat", "Chi2 of matching in 2 stations", 100, 0, 100); - fhChi2mat[fNstat + 1] = new TH1D("hChi2Abs", "Chi2 of 2 vector matching", 100, 0, 50); - fhSim = new TH1D("hSim", "Number of reconstructable muons", 10, 0, 10); - fhRec = new TH1D("hRec", "Number of reconstructed muons", 10, 0, 10); - fhMatchMult = new TH1D("hMatchMult", "Multiplicity of matching", 10, 0, 10); - fhMatchOver = new TH1D("hMatchOver", "Matching overlaps", 10, 0, 10); - fhOverlap = new TH1D("hOverlap", "Matching overlap flag", 10, 0, 10); - fhSimRec = new TH2D("hSimRec", "Reco muons vs simulated", 4, 0, 4, 4, 0, 4); -} -// ------------------------------------------------------------------------- - -// ----- Public method Exec -------------------------------------------- -void CbmMuchMergeVectorsQa::Exec(Option_t* opt) -{ - // Do all processing - - // Check efficiency - CheckEffic(); -} -// ------------------------------------------------------------------------- - -// ----- Private method CheckMatch ------------------------------------- -Bool_t CbmMuchMergeVectorsQa::CheckMatch(CbmMuchTrack* vec) -{ - // Check matching quality of the vector - - /* - Int_t nhits = vec->GetNofHits(), nthr = nhits / 2, id = 0; - //Int_t nhits = vec->GetNofHits(), nthr = nhits - 1, id = 0; - Int_t ista = vec->GetPreviousTrackId(); - map<Int_t,Int_t> ids; - - for (Int_t ih = 0; ih < nhits; ++ih) { - CbmMuchStrawHit *hit = (CbmMuchStrawHit*) fHits->UncheckedAt(vec->GetHitIndex(ih)); - //if (hit->GetFlag() > 1) { cout << " hit " << hit->GetFlag() << endl; } - if (hit->GetFlag() % 2) { - //if (0) { - // Mirror hit - id = -1; - if (ids.find(id) == ids.end()) ids.insert(pair<Int_t,Int_t>(id,1)); - else ++ids[id]; - } else { - CbmMuchDigiMatch* digiM = (CbmMuchDigiMatch*) fDigiMatches->UncheckedAt(hit->GetRefId()); - Int_t np = digiM->GetNofLinks(); - for (Int_t ip = 0; ip < np; ++ip) { - //CbmMuchPoint* point = (CbmMuchPoint*) fPoints->UncheckedAt(digiM->GetLink(0).GetIndex()); - CbmMuchPoint* point = (CbmMuchPoint*) fPoints->UncheckedAt(digiM->GetLink(ip).GetIndex()); - id = point->GetTrackID(); - //if (np > 1) cout << ip << " " << id << endl; - if (ids.find(id) == ids.end()) ids.insert(pair<Int_t,Int_t>(id,1)); - else ++ids[id]; - } - //if (np > 1) { cout << " digi " << digiM->GetNofLinks() << " " << ista << " " << hit->GetX() << " " << hit->GetY() << endl; exit(0); } - } - } - Int_t maxim = -1, idmax = -9; - for (map<Int_t,Int_t>::iterator it = ids.begin(); it != ids.end(); ++it) { - if (it->second > maxim) { - maxim = it->second; - idmax = it->first; - } - } - // Set vector ID as its flag - //vec->SetFlag(idmax); - if (maxim <= nthr || idmax < 0) return kFALSE; - - if (idmax > 1) return kFALSE; // !!! look only at muons from Pluto - - fhNhitsOk[ista]->Fill(vec->GetNofHits()); - fhIds[ista]->Fill(idmax); - Int_t evID = FairRunAna::Instance()->GetEventHeader()->GetMCEntryNumber() + 1; - fhIdVsEv[ista]->Fill(evID,idmax); - - // Fill true track parameters - Double_t zp = 0.0, parsTr[4] = {0.0}; - Int_t ok = 0; - for (Int_t ih = 0; ih < nhits; ++ih) { - CbmMuchStrawHit *hit = (CbmMuchStrawHit*) fHits->UncheckedAt(vec->GetHitIndex(ih)); - CbmMuchDigiMatch* digiM = (CbmMuchDigiMatch*) fDigiMatches->UncheckedAt(hit->GetRefId()); - Int_t np = digiM->GetNofLinks(); - for (Int_t ip = 0; ip < np; ++ip) { - CbmMuchPoint* point = (CbmMuchPoint*) fPoints->UncheckedAt(digiM->GetLink(ip).GetIndex()); - id = point->GetTrackID(); - if (id != idmax) continue; - parsTr[0] = (point->GetXIn() + point->GetXOut()) / 2; - parsTr[1] = (point->GetYIn() + point->GetYOut()) / 2; - zp = (point->GetZIn() + point->GetZOut()) / 2; - parsTr[2] = point->GetPx() / point->GetPz(); - parsTr[3] = point->GetPy() / point->GetPz(); - ok = 1; - break; - } - if (ok) break; - } - // Adjust track coordinates - const FairTrackParam *params = vec->GetParamFirst(); - parsTr[0] += parsTr[2] * (params->GetZ() - zp); - parsTr[1] += parsTr[3] * (params->GetZ() - zp); - fhDx[ista]->Fill(params->GetX()-parsTr[0]); - fhDy[ista]->Fill(params->GetY()-parsTr[1]); - fhDtx[ista]->Fill(params->GetTx()-parsTr[2]); - fhDty[ista]->Fill(params->GetTy()-parsTr[3]); - fhDtxOk[ista]->Fill(params->GetTx()-params->GetX()/params->GetZ()); - fhDtyOk[ista]->Fill(params->GetTy()-params->GetY()/params->GetZ()); - cout << " Good: " << idmax << " " << zp << " " << params->GetZ() << " " << parsTr[0] << " " << params->GetX() << " " << parsTr[1] << " " << params->GetY() << " " << parsTr[2] << " " << params->GetTx() << " " << parsTr[3] << " " << params->GetTy() << " " << vec->GetChiSq() << endl; - - // Fill tube difference between doublets - map<Int_t,Int_t> tubes[2]; - Int_t id0 = -1; - for (Int_t ih = 0; ih < nhits; ++ih) { - CbmMuchStrawHit *hit = (CbmMuchStrawHit*) fHits->UncheckedAt(vec->GetHitIndex(ih)); - CbmMuchDigiMatch* digiM = (CbmMuchDigiMatch*) fDigiMatches->UncheckedAt(hit->GetRefId()); - Int_t np = digiM->GetNofLinks(); - for (Int_t ip = 0; ip < np; ++ip) { - CbmMuchPoint* point = (CbmMuchPoint*) fPoints->UncheckedAt(digiM->GetLink(ip).GetIndex()); - id = point->GetTrackID(); - if (id > 1) continue; // look only at muons from vector mesons - if (id0 < 0) id0 = id; - break; - } - if (id0 < 0 || id != id0) continue; - Int_t lay = fGeoScheme->GetLayerIndex(hit->GetAddress()); - tubes[id].insert(pair<Int_t,Int_t>(lay,hit->GetTube())); - } - Double_t slope[2] = {0.08, 0.06}; - for (Int_t j = 0; j < 2; ++j) { - // Loop over trackID - Int_t nd = tubes[j].size(); - if (nd < 2) continue; - Int_t tubeNos[4] = {1000, 1000, 1000, 1000}; - map<Int_t,Int_t>::iterator it = tubes[j].begin(); - tubeNos[it->first] = it->second; - ++it; - for ( ; it != tubes[j].end(); ++it) tubeNos[it->first] = it->second; - for (Int_t lay = 1; lay < 4; ++lay) { - if (tubeNos[lay] < 1000 & tubeNos[lay-1] < 1000) - fhDtube[ista][lay-1]->Fill(tubeNos[lay]-tubeNos[lay-1]); - if (lay == 2 && tubeNos[lay] < 1000 & tubeNos[lay-2] < 1000) - fhDtube2[ista][lay-2]->Fill(tubeNos[lay-2],tubeNos[lay]-tubeNos[lay-2]); - if (lay == 3 && tubeNos[lay] < 1000 & tubeNos[lay-2] < 1000) { - //fhDtube2[ista][lay-2]->Fill(tubeNos[lay-2],tubeNos[lay]-tubeNos[lay-2]-slope[ista]*tubeNos[lay-2]); - Double_t dzz = (fZpos[ista][lay*2]-fZpos[ista][lay*2-4]) / fZpos[ista][lay*2-4]; - fhDtube2[ista][lay-2]->Fill(tubeNos[lay-2],tubeNos[lay]-tubeNos[lay-2]-dzz*tubeNos[lay-2]); - } - } - if (ok) break; - } - */ - - return kTRUE; -} -// ------------------------------------------------------------------------- - -// ----- Private method CheckEffic ------------------------------------- -void CbmMuchMergeVectorsQa::CheckEffic() -{ - // Check efficiency of the vector reco - - // Find "reconstructable" vectors - having points in all straw doublets - // !!! Take only trackID = 0, 1 (from signal mesons) - const Int_t nMu = 2; - set<Int_t> doublets[20][nMu], singlets[20][nMu]; - Int_t nPoints = fPoints->GetEntriesFast(); - Double_t xp[7][20][nMu], yp[7][20][nMu]; - Bool_t lstraws = kFALSE; - - for (Int_t ip = 0; ip < nPoints; ++ip) { - CbmMuchPoint* p = (CbmMuchPoint*) fPoints->UncheckedAt(ip); - Int_t id = p->GetTrackID(); - if (id > 1) continue; - //if (p->GetZ() < fZpos[0][0] - 2.0) continue; - Int_t ista = fGeoScheme->GetStationIndex(p->GetDetectorId()); // - fStatFirst; - Int_t lay = fGeoScheme->GetLayerIndex(p->GetDetectorId()); - Int_t side = fGeoScheme->GetLayerSideIndex(p->GetDetectorId()); - - doublets[ista][id].insert(lay); - singlets[ista][id].insert(lay * 2 + side); - xp[ista][lay * 2 + side][id] = (p->GetXIn() + p->GetXOut()) / 2; - yp[ista][lay * 2 + side][id] = (p->GetYIn() + p->GetYOut()) / 2; - - if (!lstraws) { - if (fGeoScheme->GetModuleByDetId(p->GetDetectorId())->GetDetectorType() == 2) lstraws = kTRUE; - } - } - - Int_t muons[7][nMu] = {{0}, {0}}, nMuVec = 0, nMuRec = 0; - for (Int_t ista = 0; ista < fNstat; ++ista) { - if (doublets[ista][0].size() == fNdoubl[ista]) { - muons[ista][0] = 1; - ++nMuVec; - } - if (doublets[ista][1].size() == fNdoubl[ista]) { - muons[ista][1] = 1; - ++nMuVec; - } - } - //if ((muons[0][0] == 0 || muons[1][0] == 0) && (muons[0][1] == 0 || muons[1][1] == 0)) return; - if (nMuVec == 0) return; - nMuVec = 0; - for (Int_t mu = 0; mu < nMu; ++mu) { - Int_t simOk = 0; - for (Int_t ista = 0; ista < fNstat; ++ista) - simOk += muons[ista][mu]; - nMuVec += simOk / fNstat; - } - - // Match merged vectors - Int_t ntracks = fTracks->GetEntriesFast(); - Int_t pluto = 0; // !!! set to 1 to check exact matching for Pluto - Double_t errxS[6] = {0.33, 0.50, 0.2, 0.2, 1, 1}; - Double_t erryS[6] = {0.33, 0.50, 1.9, 1.9, 1, 1}, - chi2cut = 10.0; // 2 GEMS, 2 straws - //Double_t errxS[6] = {0.33, 0.50, 0.03, 0.03, 1, 1}; - //Double_t erryS[6] = {0.33, 0.50, 0.26, 0.26, 1, 1}, chi2cut = 10.0; // 2 GEMS, 2 straws - Double_t errxG[6] = {0.33, 0.54, 1.0, 1.7, 1, 1}; - Double_t erryG[6] = {0.33, 0.54, 1.0, 1.7, 1, 1}; // 4 GEMS - Double_t chi2tot = 0.0, chi2min = 0.0, chi2[10][nMu] = {{0.0}, {0.0}}; - Int_t iMatch[nMu] = {0}; - Double_t *errx = errxG, *erry = erryG; - if (lstraws) { - errx = errxS; - erry = erryS; - } - - for (Int_t mu = 0; mu < nMu; ++mu) { - iMatch[mu] = -1; - //fhSim->Fill(muons[0][mu]+muons[1][mu]); - //if (muons[0][mu] == 0 || muons[1][mu] == 0) continue; - fhSim->Fill(muons[2][mu] + muons[3][mu]); // stations 3 and 4 - if (muons[2][mu] == 0 || muons[3][mu] == 0) continue; - for (Int_t j = 0; j < 10; ++j) - chi2[j][mu] = 999999.0; - chi2tot = chi2min = 999999.0; - Int_t nmatch = 0; - - for (Int_t itr = 0; itr < ntracks; ++itr) { - CbmMuchTrack* track = (CbmMuchTrack*) fTracks->UncheckedAt(itr); - Int_t nvecs = track->GetNofHits(); - if (nvecs < 5) continue; - Double_t c2[10] = {0.0}, c2tot = 0.0; - - for (Int_t ivec = 0; ivec < nvecs; ++ivec) { - if (track->GetHitType(ivec) != kMUCHSTRAWHIT) continue; // skip STS vector - CbmMuchTrack* vec = (CbmMuchTrack*) fVectors->UncheckedAt(track->GetHitIndex(ivec)); - Int_t nhits = vec->GetNofHits(); - Int_t ista = vec->GetUniqueID(); - //if (ivec == 0 && ista < 2 || ivec > 0 && ista == 2) continue; // only 2 last stations - - Int_t id = vec->GetFlag(); - if (pluto && id != mu) continue; // !!! this is only for Pluto sample - exact ID match!!! - const FairTrackParam* params = vec->GetParamFirst(); - //cout << " Oops: " << ivec << " " << params->GetZ() << endl; - Int_t nm = 0; - TClonesArray* hitArray = (ista < fStatFirst) ? fHitsGem : fHits; - - for (Int_t ih = 0; ih < nhits; ++ih) { - //CbmMuchStrawHit *hit = (CbmMuchStrawHit*) fHits->UncheckedAt(vec->GetHitIndex(ih)); - CbmHit* hit = (CbmHit*) hitArray->UncheckedAt(vec->GetHitIndex(ih)); - Int_t lay = fGeoScheme->GetLayerIndex(hit->GetAddress()); - Int_t side = fGeoScheme->GetLayerSideIndex(hit->GetAddress()); - Int_t plane = lay * 2 + side; - if (singlets[ista][mu].find(plane) == singlets[ista][mu].end()) continue; - Double_t x = params->GetX() + params->GetTx() * (fZpos[ista][plane] - params->GetZ()); - Double_t y = params->GetY() + params->GetTy() * (fZpos[ista][plane] - params->GetZ()); - Double_t dx = x - xp[ista][plane][mu]; - Double_t dy = y - yp[ista][plane][mu]; - c2[ista] += dx * dx / errx[ista] / errx[ista]; - c2[ista] += dy * dy / erry[ista] / erry[ista]; - ++nm; - //cout << nm << " " << dx << " " << dy << endl; - } - nm *= 2; - if (nm > 4) c2[ista] /= (nm - 4); // per NDF - c2tot += c2[ista]; - } // for (Int_t ivec = 0; ivec < nvecs; - //if (pluto) fhChi2mat[ista]->Fill(chi2[id]); // !!! this is only for Pluto sample - exact ID match!!! - //if (c2[2] + c2[3] < chi2[2][mu] + chi2[3][mu]) { - if (c2tot < chi2tot * 1.2 && track->GetChiSq() < chi2min - || c2tot < chi2tot && track->GetChiSq() < chi2min * 1.2) { - for (Int_t j = 0; j < 10; ++j) - chi2[j][mu] = c2[j]; - chi2tot = c2tot; - chi2min = track->GetChiSq(); - iMatch[mu] = itr; - } - //if (c2[0] < chi2cut && c2[1] < chi2cut && track->GetChiSq() < chi2cut * 2) ++nmatch; - if (c2[0] < chi2cut && c2[1] < chi2cut && c2[2] < chi2cut && c2[3] < chi2cut && track->GetChiSq() < chi2cut * 4) - ++nmatch; - //cout << nvecs << " " << c2tot << endl; - } // for (Int_t itr = 0; itr < ntracks; - cout << " Nover " << ntracks << " " << nmatch << endl; - if (iMatch[mu] < 0) continue; - fhMatchOver->Fill(nmatch); - nMuRec += TMath::Min(1, nmatch); - - for (Int_t ista = 0; ista < fNstat; ++ista) - fhChi2mat[ista]->Fill(chi2[ista][mu]); - //fhChi2mat[fNstat]->Fill(chi2[2][mu]+chi2[3][mu]); - fhChi2mat[fNstat]->Fill(chi2tot); - CbmMuchTrack* track = (CbmMuchTrack*) fTracks->UncheckedAt(iMatch[mu]); - fhChi2mat[fNstat + 1]->Fill(track->GetChiSq()); - //if (track->GetChiSq() > 20) { cout << track->GetChiSq() << " " << chi2tot << endl; exit(0); } - - nmatch = 0; - for (Int_t ista = 0; ista < fNstat; ++ista) - if (chi2[ista][mu] < chi2cut) ++nmatch; - fhMatchMult->Fill(nmatch); - } // for (Int_t mu = 0; mu < nMu; - if (iMatch[0] == iMatch[1] && iMatch[0] >= 0) fhOverlap->Fill(1); // the same track matches 2 muons - fhSimRec->Fill(nMuVec, nMuRec); -} -// ------------------------------------------------------------------------- - -// ----- Public method Finish ------------------------------------------ -void CbmMuchMergeVectorsQa::Finish() -{ - - TDirectory* dir0 = (TDirectory*) gROOT->FindObjectAny("muchQA"); - TDirectory* dir = (TDirectory*) dir0->FindObjectAny("muchQA1"); - gDirectory->mkdir("muchQA1"); - gDirectory->cd("muchQA1"); - dir->GetList()->Write(); -} -// ------------------------------------------------------------------------- - -// ------------------------------------------------------------------------- - -ClassImp(CbmMuchMergeVectorsQa); diff --git a/reco/tracking/vector/CbmMuchMergeVectorsQa.h b/reco/tracking/vector/CbmMuchMergeVectorsQa.h deleted file mode 100644 index ca999042ecf58503bd42b7c816542297dc9d6f54..0000000000000000000000000000000000000000 --- a/reco/tracking/vector/CbmMuchMergeVectorsQa.h +++ /dev/null @@ -1,88 +0,0 @@ -/* Copyright (C) 2014-2018 Veksler and Baldin Laboratory of High Energy Physics, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Alexander Zinchenko [committer] */ - -/** CbmMuchMergeVectorsQa.h - *@author A.Zinchenko <Alexander.Zinchenko@jinr.ru> - *@since 2014 - ** - ** Task class for MUCH vector merger QA. - ** - **/ - -#ifndef CBMMUCHMERGEVECTORSQA_H_ -#define CBMMUCHMERGEVECTORSQA_H_ 1 - -#include "CbmMuchGeoScheme.h" - -#include "FairTask.h" - -#include <set> -#include <vector> - -class CbmMuchTrack; -class TClonesArray; -class TH1D; -class TH2D; - -class CbmMuchMergeVectorsQa : public FairTask { -public: - /** Default (standard) constructor **/ - CbmMuchMergeVectorsQa(); - - /** Destructor **/ - virtual ~CbmMuchMergeVectorsQa(); - - /** Initialisation **/ - virtual InitStatus Init(); - - /** Task execution **/ - virtual void Exec(Option_t* opt); - - /** Finish at the end **/ - virtual void Finish(); - - /** SetParContainers **/ - virtual void SetParContainers(); - - /** Accessors **/ - //Int_t GetNofTracks() { return fNofTracks; }; - -private: - CbmMuchGeoScheme* fGeoScheme; // Geometry scheme - Int_t fStatFirst; // First straw station No. - Int_t fNstat; // Number of straw stations - Int_t fNdoubl[10]; // Number of double layers in stations - Double_t fZpos[5][10]; // Z-pos. of double layers in stations - - TClonesArray* fTracks; - TClonesArray* fVectors; - TClonesArray* fMCTracks; - TClonesArray* fPoints; - TClonesArray* fHits; - TClonesArray* fHitsGem; - TClonesArray* fDigis; - TClonesArray* fDigisGem; - TClonesArray* fDigiMatches; - TClonesArray* fDigiMatchesGem; - TClonesArray* fClusters; - - TH1D* fhSim; - TH1D* fhRec; - TH1D* fhMatchMult; - TH1D* fhMatchOver; - TH1D* fhOverlap; - TH1D** fhChi2mat; - TH2D* fhSimRec; - - void BookHistos(); - Bool_t CheckMatch(CbmMuchTrack* vec); - void CheckEffic(); - - CbmMuchMergeVectorsQa(const CbmMuchMergeVectorsQa&); - CbmMuchMergeVectorsQa& operator=(const CbmMuchMergeVectorsQa&); - - ClassDef(CbmMuchMergeVectorsQa, 1) -}; - -#endif diff --git a/reco/tracking/vector/CbmMuchToTofVectors.cxx b/reco/tracking/vector/CbmMuchToTofVectors.cxx deleted file mode 100644 index f4365609f58ae4f5ba95ab3add94a9af528778a1..0000000000000000000000000000000000000000 --- a/reco/tracking/vector/CbmMuchToTofVectors.cxx +++ /dev/null @@ -1,690 +0,0 @@ -/* Copyright (C) 2017-2019 Veksler and Baldin Laboratory of High Energy Physics, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Alexander Zinchenko [committer] */ - -/** CbmMuchToTofVectors.cxx - *@author A.Zinchenko <Alexander.Zinchenko@jinr.ru> - *@since 2017 - **/ -#include "CbmMuchToTofVectors.h" - -#include "CbmDefs.h" -#include "CbmMCDataArray.h" -#include "CbmMCDataManager.h" -#include "CbmMatch.h" -#include "CbmMuchTrack.h" -#include "CbmSetup.h" -#include "CbmTofAddress.h" -#include "CbmTofDigi.h" -#include "CbmTofHit.h" -#include "CbmTofPoint.h" - -#include "FairRootManager.h" - -#include <TClonesArray.h> -#include <TGeoBBox.h> -#include <TGeoManager.h> -#include <TMath.h> -#include <TMatrixDSym.h> -#include <TVectorD.h> - -#include <iostream> - -using std::cout; -using std::endl; -using std::map; -using std::multimap; -using std::pair; -using std::set; - -// ----- Default constructor ------------------------------------------- -CbmMuchToTofVectors::CbmMuchToTofVectors() - : FairTask("Much2TofVec") - , fTrackArray(NULL) - , fNofTracks(0) - , fHits(NULL) - , fHitMatches(NULL) - , fPoints(NULL) - , fDigis(NULL) - , fDigiMatches(NULL) - , fMuchTracks(NULL) - , fErrX(1.0) - , fErrY(1.0) - , fCutChi2(24.0) // chi2/ndf = 6 for 4 hits -{ -} -// ------------------------------------------------------------------------- - -// ----- Destructor ---------------------------------------------------- -CbmMuchToTofVectors::~CbmMuchToTofVectors() {} -// ------------------------------------------------------------------------- - -// ----- Public method Init (abstract in base class) -------------------- -InitStatus CbmMuchToTofVectors::Init() -{ - - // Get and check FairRootManager - FairRootManager* ioman = FairRootManager::Instance(); - if (ioman == NULL) Fatal("Init", "RootManager not instantiated!"); - - // Create and register TrdTrack array (if necessary) - //fTrackArray = static_cast<TClonesArray*> (ioman->GetObject("MuchVector")); - //if (fTrackArray == NULL) { - fTrackArray = new TClonesArray("CbmMuchTrack", 100); - ioman->Register("Tof1Vector", "Tof", fTrackArray, kTRUE); - //} - fHits = static_cast<TClonesArray*>(ioman->GetObject("TofHit")); - fHitMatches = static_cast<TClonesArray*>(ioman->GetObject("TofDigiMatch")); - //fPoints = static_cast<TClonesArray*> (ioman->GetObject("TofPoint")); - CbmMCDataManager* mcManager = (CbmMCDataManager*) ioman->GetObject("MCDataManager"); - if (NULL == mcManager) LOG(fatal) << GetName() << ": No CbmMCDataManager!"; - fPoints = mcManager->InitBranch("TofPoint"); - fDigis = static_cast<TClonesArray*>(ioman->GetObject("TofDigi")); - fDigiMatches = static_cast<TClonesArray*>(ioman->GetObject("TofDigiMatchPoints")); - fMuchTracks = static_cast<TClonesArray*>(ioman->GetObject("MuchVectorTrack")); - - TString tag; - CbmSetup::Instance()->GetGeoTag(kTof, tag); - cout << " ******* TOF tag ******** " << tag << endl; - tag.Prepend("tof_"); - - //CbmTofGeoHandler geoHandler; - //geoHandler.Init(); - - // Get TOF location in Z - TGeoVolume* tofV = gGeoManager->GetVolume(tag); - TGeoBBox* shape = (TGeoBBox*) tofV->GetShape(); - shape->GetAxisRange(3, fZ[0], fZ[1]); - cout << " TOF span in Z: " << fZ[0] << " " << fZ[1] << endl; - - return kSUCCESS; -} -// ------------------------------------------------------------------------- - -// ----- SetParContainers ------------------------------------------------- -void CbmMuchToTofVectors::SetParContainers() -{ - /* - fDigiPar = (CbmTrdDigiPar*) FairRunAna::Instance()->GetRuntimeDb()->getContainer("CbmTrdDigiPar"); - cout << " ******* digiPar ******** " << fDigiPar << endl; - exit(0); - */ -} -// ------------------------------------------------------------------------- - -// ----- Public method Exec -------------------------------------------- -void CbmMuchToTofVectors::Exec(Option_t* opt) -{ - - fTrackArray->Delete(); - - // Do all processing - - // Get hits - GetHits(); - - // Build vectors (extrapolate MUCH vectors thru the thickness of TOF) - MakeVectors(); - - // Remove vectors with wrong orientation - // (using empirical cuts for omega muons at 8 GeV) - //CheckParams(); - - // Match TOF hits to MUCH vectors - MatchTofToMuch(); - - // Remove clones - //RemoveClones(); - - // Store vectors - StoreVectors(); -} -// ------------------------------------------------------------------------- - -// ----- Public method Finish ------------------------------------------ -void CbmMuchToTofVectors::Finish() {} -// ------------------------------------------------------------------------- - -// ----- Private method GetHits ---------------------------------------- -void CbmMuchToTofVectors::GetHits() -{ - // Arrange hits according to their Phi-angle - - fHitX.clear(); - fHitY.clear(); - fHitIds.clear(); - fHitTime.clear(); - - Int_t nHits = fHits->GetEntriesFast(), sel = 0; - - for (Int_t i = 0; i < nHits; ++i) { - CbmTofHit* hit = (CbmTofHit*) fHits->UncheckedAt(i); - - //!!! For debug - select hits with certain track IDs - sel = 1; //SelectHitId(hit); - if (!sel) continue; - // - fHitX.insert(pair<Double_t, Int_t>(hit->GetX(), i)); - fHitY.insert(pair<Double_t, Int_t>(hit->GetY(), i)); - CbmMatch* match = (CbmMatch*) fHitMatches->UncheckedAt(i); - Int_t nlinks = match->GetNofLinks(); - set<Int_t> ids; - fHitIds[i] = ids; - - for (Int_t il = 0; il < nlinks; ++il) { - const CbmLink link = match->GetLink(il); - CbmTofDigi* digi = (CbmTofDigi*) fDigis->UncheckedAt(link.GetIndex()); - //AZ CbmMatch *digiM = (CbmMatch*) fDigiMatches->UncheckedAt(link.GetIndex()); - CbmMatch* digiM = digi->GetMatch(); - Int_t npoints = digiM->GetNofLinks(); - - for (Int_t ip = 0; ip < npoints; ++ip) { - const CbmLink link1 = digiM->GetLink(ip); - //CbmTofPoint *point = (CbmTofPoint*) fPoints->UncheckedAt(link1.GetIndex()); - CbmTofPoint* point = (CbmTofPoint*) fPoints->Get(link1.GetFile(), link1.GetEntry(), link1.GetIndex()); - fHitIds[i].insert(point->GetTrackID()); - if (fHitTime.find(i) == fHitTime.end()) fHitTime[i] = point->GetTime(); - else - fHitTime[i] = TMath::Min(point->GetTime(), fHitTime[i]); - //cout << point->GetTrackID() << endl; - } - } - } -} -// ------------------------------------------------------------------------- - -// ----- Private method MakeVectors ------------------------------------ -void CbmMuchToTofVectors::MakeVectors() -{ - // Make vectors (extrapolate MUCH vectors through the TOF thickness) - - const Int_t nMinSeg = 5; - Int_t nvec = fVectors.size(); - for (Int_t j = 0; j < nvec; ++j) - delete fVectors[j]; - fVectors.clear(); - - fLineX.clear(); - - Int_t nMuch = fMuchTracks->GetEntriesFast(); - cout << " MUCH tracks: " << nMuch << endl; - - for (Int_t iv = 0; iv < nMuch; ++iv) { - CbmMuchTrack* tr = (CbmMuchTrack*) fMuchTracks->UncheckedAt(iv); - if (tr->GetNofHits() < nMinSeg) continue; - const FairTrackParam& param = *tr->GetParamFirst(); - TLine line; - line.SetUniqueID(iv); - - for (Int_t i = 0; i < 2; ++i) { - Double_t dz = fZ[i] - param.GetZ(); - if (i == 0) { - line.SetX1(param.GetX() + param.GetTx() * dz); - line.SetY1(param.GetY() + param.GetTy() * dz); - } - else { - line.SetX2(param.GetX() + param.GetTx() * dz); - line.SetY2(param.GetY() + param.GetTy() * dz); - } - } - fLineX.insert(pair<Double_t, TLine>(TMath::Min(line.GetX1(), line.GetX2()), line)); - } -} -// ------------------------------------------------------------------------- - -// ----- Private method MatchTofToMuch --------------------------------- -void CbmMuchToTofVectors::MatchTofToMuch() -{ - // Match TOF hits to MUCH vectors - - //const Double_t window = 30.0; - const Double_t window = 50.0; - multimap<Double_t, Int_t>::iterator mitb, mite, mit1; - multimap<Double_t, pair<Int_t, Int_t>> rads; - map<pair<Int_t, Int_t>, pair<Double_t, Double_t>> dtdl; - set<Int_t> setVec, setHit; - - for (multimap<Double_t, TLine>::iterator mit = fLineX.begin(); mit != fLineX.end(); ++mit) { - Double_t rmin = 999999, dtmin = 0, dlmin = 0; - TVector3 trd(mit->second.GetX2() - mit->second.GetX1(), mit->second.GetY2() - mit->second.GetY1(), 0.0); - Double_t trdLeng = trd.Mag(); - Int_t indVec = mit->second.GetUniqueID(); - CbmMuchTrack* tr = (CbmMuchTrack*) fMuchTracks->UncheckedAt(indVec); - Int_t id = tr->GetFlag(), ihit = -1; - - // Select TOF hits for matching (apply coordinate windows) - mitb = fHitX.lower_bound(mit->first - window); - mite = fHitX.upper_bound(TMath::Max(mit->second.GetX1(), mit->second.GetX2()) + window); - set<Int_t> inds; - for (mit1 = mitb; mit1 != mite; ++mit1) - inds.insert(mit1->second); - mitb = fHitY.lower_bound(TMath::Min(mit->second.GetY1(), mit->second.GetY2()) - window); - mite = fHitY.upper_bound(TMath::Max(mit->second.GetY1(), mit->second.GetY2()) + window); - - for (mit1 = mitb; mit1 != mite; ++mit1) { - if (inds.find(mit1->second) == inds.end()) continue; // outside window - CbmTofHit* hit = (CbmTofHit*) fHits->UncheckedAt(mit1->second); - TVector3 tof(hit->GetX() - mit->second.GetX1(), hit->GetY() - mit->second.GetY1(), 0.0); - Double_t dt = TMath::Abs(trd.Cross(tof).Z()) / trdLeng; - Double_t dl = trd * tof / trdLeng; - if (dl > trdLeng) dl -= trdLeng; - else if (dl > 0) - dl = 0; - Double_t rad = dl * dl + dt * dt; - // Save matches - rads.insert(pair<Double_t, pair<Int_t, Int_t>>(rad, pair<Int_t, Int_t>(indVec, mit1->second))); - dtdl[pair<Int_t, Int_t>(indVec, mit1->second)] = pair<Double_t, Double_t>(dt, dl); - setVec.insert(indVec); - setHit.insert(mit1->second); - /* - if (rad < rmin) { - rmin = rad; - dtmin = dt; - dlmin = dl; - ihit = mit1->second; - } - */ - } - /* - if (ihit >= 0) { - Bool_t match = kFALSE; - if (fHitIds[ihit].find(id) != fHitIds[ihit].end()) match = kTRUE; - //cout << dtmin << " " << dlmin << " " << id << " " << match << endl; - CbmMuchTrack *trTof = new CbmMuchTrack(*tr); - trTof->SetPreviousTrackId(mit->second.GetUniqueID()); // index of TRD vector - FairTrackParam param; - param.SetX(dtmin); // use storage - param.SetY(dlmin); - trTof->SetParamLast(¶m); - trTof->SetFlag(match); - trTof->SetUniqueID(id); - fVectors.push_back(trTof); - } - */ - } // for (multimap<Double_t,TLine>::iterator mit = fLineX.begin(); - - // Create vectors - for (multimap<Double_t, pair<Int_t, Int_t>>::iterator rmit = rads.begin(); rmit != rads.end(); ++rmit) { - Int_t indVec = rmit->second.first, ihit = rmit->second.second; - if (setVec.find(indVec) == setVec.end()) continue; // already matched vector - if (setHit.find(ihit) == setHit.end()) continue; // already matched hit - - Bool_t match = kFALSE; - CbmMuchTrack* tr = (CbmMuchTrack*) fMuchTracks->UncheckedAt(indVec); - Int_t id = tr->GetFlag(); - if (id < 0) id = 9999; - if (fHitIds[ihit].find(id) != fHitIds[ihit].end()) match = kTRUE; - //cout << dtmin << " " << dlmin << " " << id << " " << match << endl; - CbmMuchTrack* trTof = new CbmMuchTrack(*tr); - trTof->SetPreviousTrackId(indVec); // index of TRD vector - FairTrackParam param; - param.SetX(dtdl[rmit->second].first); // use storage - param.SetY(dtdl[rmit->second].second); - param.SetZ(rmit->first); - trTof->SetParamLast(¶m); - trTof->SetFlag(match); - trTof->SetUniqueID(id); - trTof->SetNDF(ihit); // TOF hit index - use storage - trTof->SetChiSq(fHitTime[ihit]); // min. time - use storage - fVectors.push_back(trTof); - - setVec.erase(indVec); - if (setVec.size() == 0) break; - setHit.erase(ihit); - if (setHit.size() == 0) break; - } -} -// ------------------------------------------------------------------------- - -// ----- Private method CheckParams ------------------------------------ -void CbmMuchToTofVectors::CheckParams() -{ - // Remove vectors with wrong orientation - // using empirical cuts for omega muons at 8 Gev - - const Double_t cut[2] = {0.6, 0.6}; // !!! empirical !!! - - Int_t nvec = fVectors.size(); - - for (Int_t iv = 0; iv < nvec; ++iv) { - CbmMuchTrack* vec = fVectors[iv]; - const FairTrackParam* params = vec->GetParamFirst(); - Double_t dTx = params->GetTx() - params->GetX() / params->GetZ(); - if (TMath::Abs(dTx) > cut[0]) vec->SetChiSq(-1.0); - else { - Double_t dTy = params->GetTy() - params->GetY() / params->GetZ(); - if (TMath::Abs(dTy) > cut[1]) vec->SetChiSq(-1.0); - } - } - - for (Int_t iv = nvec - 1; iv >= 0; --iv) { - CbmMuchTrack* vec = fVectors[iv]; - if (vec->GetChiSq() < 0) { - delete fVectors[iv]; - fVectors.erase(fVectors.begin() + iv); - } - } - cout << " Vectors after parameter check: " << nvec << " " << fVectors.size() << endl; -} -// ------------------------------------------------------------------------- - -// ----- Private method RemoveClones ----------------------------------- -void CbmMuchToTofVectors::RemoveClones() -{ - // Remove clone vectors (having at least 3 the same hits) - - //Int_t nthr = 3, planes[20]; - Int_t nthr = 2, planes[20]; - - Int_t nvec = fVectors.size(); - - // Do sorting according to "quality" - multimap<Double_t, CbmMuchTrack*> qMap; - multimap<Double_t, CbmMuchTrack*>::iterator it, it1; - - for (Int_t i = 0; i < nvec; ++i) { - CbmMuchTrack* vec = fVectors[i]; - Double_t qual = vec->GetNofHits() + (99 - TMath::Min(vec->GetChiSq(), 99.0)) / 100; - qMap.insert(pair<Double_t, CbmMuchTrack*>(-qual, vec)); - } - - for (it = qMap.begin(); it != qMap.end(); ++it) { - CbmMuchTrack* vec = it->second; - if (vec->GetChiSq() < 0) continue; - for (Int_t j = 0; j < fgkPlanes; ++j) - planes[j] = -1; - - Int_t nhits = vec->GetNofHits(); - for (Int_t ih = 0; ih < nhits; ++ih) { - CbmTofHit* hit = (CbmTofHit*) fHits->UncheckedAt(vec->GetHitIndex(ih)); - Int_t lay = hit->GetPlaneId(); - planes[lay] = vec->GetHitIndex(ih); - } - - it1 = it; - for (++it1; it1 != qMap.end(); ++it1) { - CbmMuchTrack* vec1 = it1->second; - if (vec1->GetChiSq() < 0) continue; - Int_t nsame = 0, same[fgkPlanes] = {0}; - - Int_t nhits1 = vec1->GetNofHits(); - //nthr = TMath::Min(nhits,nhits1) / 2; - //nthr = TMath::Min(nhits,nhits1) * 0.75; - for (Int_t ih = 0; ih < nhits1; ++ih) { - CbmTofHit* hit = (CbmTofHit*) fHits->UncheckedAt(vec1->GetHitIndex(ih)); - Int_t lay = hit->GetPlaneId(); - if (planes[lay] >= 0) { - if (vec1->GetHitIndex(ih) == planes[lay]) same[lay] = 1; - //else same[lay] = 0; - } - } - for (Int_t lay = 0; lay < fgkPlanes; ++lay) - nsame += same[lay]; - - if (nsame >= nthr) { - // Too many the same hits - Int_t clone = 0; - if (nhits > nhits1 + 0) clone = 1; - else if (vec->GetChiSq() * 1 <= vec1->GetChiSq()) - clone = 1; // the same number of hits on 2 tracks - //else if (vec->GetChiSq() * 1.5 <= vec1->GetChiSq()) clone = 1; // the same number of hits on 2 tracks - if (clone) vec1->SetChiSq(-1.0); - } - } - } // for (it = qMap.begin(); - - for (Int_t iv = nvec - 1; iv >= 0; --iv) { - CbmMuchTrack* vec = fVectors[iv]; - if (vec->GetChiSq() < 0) { - delete fVectors[iv]; - fVectors.erase(fVectors.begin() + iv); - } - } - cout << " CbmTrdToTofVector:: Vectors after clones removed: " << nvec << " " << fVectors.size() << endl; -} -// ------------------------------------------------------------------------- - -// ----- Private method StoreVectors ----------------------------------- -void CbmMuchToTofVectors::StoreVectors() -{ - // Store vectors (CbmMuchTracks) into TClonesArray - - Int_t ntrs = fTrackArray->GetEntriesFast(); - Int_t nHitsTot = fHits->GetEntriesFast(); - - //set<Int_t> usedHits; - Int_t nvec = fVectors.size(); - - for (Int_t iv = 0; iv < nvec; ++iv) { - CbmMuchTrack* tr = new ((*fTrackArray)[ntrs++]) CbmMuchTrack(*(fVectors[iv])); - //cout << " Track: " << tr->GetNofHits() << endl; - //for (Int_t j = 0; j < tr->GetNofHits(); ++j) cout << j << " " << tr->GetHitIndex(j) << " " << fVectors[ist][iv]->GetHitIndex(j) << endl; - // Set hit flag (to check Lit tracking) - //Int_t nhits = tr->GetNofHits(); - - // Save IDs of contributing points to the hit - CbmMatch* match = new CbmMatch; - Int_t ihit = fVectors[iv]->GetNDF(); - for (set<Int_t>::iterator sit = fHitIds[ihit].begin(); sit != fHitIds[ihit].end(); ++sit) - match->AddLink(1.0, *sit); - tr->SetMatch(match); - } -} -// ------------------------------------------------------------------------- - -// ----- Private method ProcessPlane ----------------------------------- -void CbmMuchToTofVectors::ProcessPlane(Int_t lay, Int_t patt, Int_t flag0) -{ - // Main processing engine (recursively adds layer hits to the vector) - - //const Double_t cut[2] = {0.8, 0.8}; // !!! empirical !!! - const Double_t cut[2] = {0.6, 0.6}; // !!! empirical !!! - - Double_t pars[4] = {0.0}; - Int_t flag = 0; - multimap<Int_t, Int_t>::iterator mit; - // Clear bits - patt &= ~(1 << lay); - /* - for (mit = fHitPl[lay].begin(); mit != fHitPl[lay].end(); ++mit) { - Int_t indx = mit->second; - - CbmTofHit *hit = (CbmTofHit*) fHits->UncheckedAt(indx); - fXy[lay][0] = hit->GetX(); - fXy[lay][1] = hit->GetY(); - fXy[lay][2] = hit->GetDx(); - fXy[lay][3] = hit->GetDy(); - //fXy[lay][2] = TMath::Max (hit->GetDx(),fErrX[ista]); - //fXy[lay][3] = TMath::Max (hit->GetDy(),fErrY[ista]); - fXy[lay][4] = hit->GetZ(); - // Clear bits - patt &= ~(1 << lay); - - // Check slopes - Int_t lay0 = 0; - if (!(patt & (1 << lay0))) ++lay0;; - Double_t dx = fXy[lay][0] - fXy[lay0][0]; - Double_t dz = fXy[lay][4] - fXy[lay0][4]; - Double_t dTx = TMath::Abs(dx/dz) - TMath::Abs(fXy[lay][0]/fXy[lay][4]); - if (TMath::Abs(dTx) > cut[0]) continue; - Double_t dy = fXy[lay][1] - fXy[lay0][1]; - Double_t dTy = TMath::Abs(dy/dz) - TMath::Abs(fXy[lay][1]/fXy[lay][4]); - if (TMath::Abs(dTy) > cut[1]) continue; - - fXyi[lay][1] = indx; - flag = 1; - - // Set bit - patt |= (1 << lay); - //cout << lay << " " << patt << " " << hit->GetX() << " " << hit->GetY() << " " << hit->GetZ() << " " << endl; - - if (lay < fgkPlanes - 1) ProcessPlane(lay+1, patt, flag); - else if (TString::Itoa(patt,2).CountChar('1') > 2) { - // Straight line fit of the vector with > 2 hits - FindLine(patt, pars); - Double_t chi2 = FindChi2(patt, pars); - cout << " *** Stat: " << chi2 << " " << pars[0] << " " << pars[1] << endl; - if (chi2 <= fCutChi2) AddVector(patt, chi2, pars); // add vector to the temporary container - } - } // for (mit = fHitPl[lay].begin(); - - //if (flag == 0) { - if (flag >= 0) { - // Missing plane - if (flag0 == 0) return; // 2 consecutive missing planes - // Clear bits - patt &= ~(1 << lay); - if (lay < fgkPlanes - 1) ProcessPlane(lay+1, patt, flag); - else if (TString::Itoa(patt,2).CountChar('1') > 2) { - // Straight line fit of the vector with > 2 hits - FindLine(patt, pars); - Double_t chi2 = FindChi2(patt, pars); - cout << " *** Stat: " << chi2 << " " << pars[0] << " " << pars[1] << endl; - if (chi2 <= fCutChi2) AddVector(patt, chi2, pars); // add vector to the temporary container - } - } - */ -} -// ------------------------------------------------------------------------- - -// ----- Private method FindLine --------------------------------------- -void CbmMuchToTofVectors::FindLine(Int_t patt, Double_t* pars) -{ - // Fit of hits to the straight line - - // Solve system of linear equations - Bool_t ok = kFALSE, onoff; - TVectorD b(4); - /* - for (Int_t i = 0; i < fgkPlanes; ++i) { - onoff = patt & (1 << i); - if (!onoff) continue; - b[0] += fXy[i][0]; - b[1] += fXy[i][1]; - b[2] += fXy[i][0] * fDz[i]; - b[3] += fXy[i][1] * fDz[i]; - } - - //lu.Print(); - TVectorD solve = fLus[patt]->Solve(b, ok); - //TVectorD solve = lu.TransSolve(b, ok); - //lu.Print(); - for (Int_t i = 0; i < 4; ++i) pars[i] = solve[i]; - //for (Int_t i = 0; i < 4; ++i) { cout << pars[i] << " "; if (i == 3) cout << endl; } - //Double_t y1 = cosa / sina * (uz[1][0] * cosa - uz[0][0]) + uz[1][0] * sina; - //Double_t y2 = -cosa / sina * (uz[2][0] * cosa - uz[0][0]) - uz[2][0] * sina; - //cout << " OK " << ok << " " << y1 << " " << y2 << endl; - */ -} -// ------------------------------------------------------------------------- - -// ----- Private method FindChi2 --------------------------------------- -Double_t CbmMuchToTofVectors::FindChi2(Int_t patt, Double_t* pars) -{ - // Compute chi2 of the fit - - Double_t chi2 = 0, x = 0, y = 0; - Bool_t onoff; - /* - for (Int_t i = 0; i < fgkPlanes; ++i) { - onoff = patt & (1 << i); - if (!onoff) continue; - x = pars[0] + pars[2] * fDz[i]; - y = pars[1] + pars[3] * fDz[i]; - //Double_t dx = (x - fXy[i][0]) / fErrX; - //Double_t dy = (y - fXy[i][1]) / fErrY; - Double_t dx = (x - fXy[i][0]) / TMath::Max(fXy[i][2],fErrX); - Double_t dy = (y - fXy[i][1]) / TMath::Max(fXy[i][3],fErrY); - chi2 += dx * dx; - chi2 += dy * dy; - } - */ - return chi2; -} -// ------------------------------------------------------------------------- - -// ----- Private method AddVector -------------------------------------- -void CbmMuchToTofVectors::AddVector(Int_t patt, Double_t chi2, Double_t* pars) -{ - // Add vector to the temporary container (as a MuchTrack) - - Bool_t refit = kFALSE; //kTRUE; - TMatrixDSym cov(4); - /* - if (refit) { - // Refit line with individual hit errors - //cout << " Before: " << chi2 << endl; - //Refit(patt, chi2, pars, cov); - //cout << " After: " << chi2 << endl; - } else { - cov = *fMatr[patt]; - cov *= (fErrX * fErrX); // the same error in X and Y - } - cov.ResizeTo(5,5); - cov(4,4) = 1.0; - - CbmMuchTrack *track = new CbmMuchTrack(); - track->SetChiSq(chi2); - FairTrackParam par(pars[0], pars[1], fZ0, pars[2], pars[3], 0.0, cov); - track->SetParamFirst(&par); - par.SetZ(fZ0 + fDz[fgkPlanes-1]); - par.SetX(pars[0] + fDz[fgkPlanes-1] * pars[2]); - par.SetY(pars[1] + fDz[fgkPlanes-1] * pars[3]); - track->SetParamLast(&par); - //track->SetUniqueID(ista); // just to pass the value - - for (Int_t ipl = 0; ipl < fgkPlanes; ++ipl) { - if (!(patt & (1 << ipl))) continue; - track->AddHit(fXyi[ipl][1], kTRDHIT); - } - Int_t ndf = (track->GetNofHits() > 2) ? track->GetNofHits() * 2 - 4 : 1; - track->SetNDF(ndf); - SetTrackId(track); // set track ID as its flag - fVectors.push_back(track); - */ -} -// ------------------------------------------------------------------------- - -// ----- Private method SetTrackId ------------------------------------- -void CbmMuchToTofVectors::SetTrackId(CbmMuchTrack* vec) -{ - // Set vector ID as its flag (maximum track ID of its poins) - - map<Int_t, Int_t> ids; - Int_t nhits = vec->GetNofHits(), id = 0; - - /* - for (Int_t ih = 0; ih < nhits; ++ih) { - CbmTofHit *hit = (CbmTofHit*) fHits->UncheckedAt(vec->GetHitIndex(ih)); - CbmTrdCluster *clus = (CbmTrdCluster*) fClusters->UncheckedAt(hit->GetRefId()); - Int_t nDigis = clus->GetNofDigis(); - - for (Int_t j = 0; j < nDigis; ++j) { - CbmMatch* digiM = (CbmMatch*) fDigiMatches->UncheckedAt(clus->GetDigi(j)); - Int_t np = digiM->GetNofLinks(); - - for (Int_t ip = 0; ip < np; ++ip) { - //CbmMuchPoint* point = (CbmMuchPoint*) fPoints->UncheckedAt(digiM->GetLink(0).GetIndex()); - CbmTrdPoint* point = (CbmTrdPoint*) fPoints->UncheckedAt(digiM->GetLink(ip).GetIndex()); - id = point->GetTrackID(); - //if (np > 1) cout << ip << " " << id << endl; - if (ids.find(id) == ids.end()) ids.insert(pair<Int_t,Int_t>(id,1)); - else ++ids[id]; - } - //if (np > 1) { cout << " digi " << digiM->GetNofLinks() << " " << ista << " " << hit->GetX() << " " << hit->GetY() << endl; exit(0); } - } - } - Int_t maxim = -1, idmax = -9; - for (map<Int_t,Int_t>::iterator it = ids.begin(); it != ids.end(); ++it) { - if (it->second > maxim) { - maxim = it->second; - idmax = it->first; - } - } - // Set vector ID as its flag - vec->SetFlag(idmax); - */ -} -// ------------------------------------------------------------------------- - -ClassImp(CbmMuchToTofVectors); diff --git a/reco/tracking/vector/CbmMuchToTofVectors.h b/reco/tracking/vector/CbmMuchToTofVectors.h deleted file mode 100644 index 24222825b1d342599f5c0e3a2053a95a0086ab9f..0000000000000000000000000000000000000000 --- a/reco/tracking/vector/CbmMuchToTofVectors.h +++ /dev/null @@ -1,98 +0,0 @@ -/* Copyright (C) 2017-2018 Veksler and Baldin Laboratory of High Energy Physics, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Alexander Zinchenko [committer] */ - -/** CbmMuchToTofVectors.h - *@author A.Zinchenko <Alexander.Zinchenko@jinr.ru> - *@since 2017 - ** - ** Task class for vector matching between CBM MUCH and TOF. - ** Input: - ** Output: - ** - **/ - -#ifndef CBMMUCHTOTOFVECTORS_H_ -#define CBMMUCHTOTOFVECTORS_H_ 1 - -#include "FairTask.h" - -#include <TLine.h> - -#include <map> -#include <set> -#include <vector> - -class CbmMuchTrack; -class CbmMCDataArray; - -class CbmMuchToTofVectors : public FairTask { -public: - /** Default constructor **/ - CbmMuchToTofVectors(); - - /** Destructor **/ - virtual ~CbmMuchToTofVectors(); - - /** Initialisation **/ - virtual InitStatus Init(); - - /** Task execution **/ - virtual void Exec(Option_t* opt); - - /** Finish at the end **/ - virtual void Finish(); - - /** SetParContainers **/ - virtual void SetParContainers(); - - /** Accessors **/ - Int_t GetNofTracks() { return fNofTracks; }; - -private: - // Some constants - static const Int_t fgkPlanes = 4; // Number of TRD layers - -private: - TClonesArray* fTrackArray; // Output array of CbmMuchTracks - Int_t fNofTracks; // Number of tracks created - TClonesArray* fHits; // Input array of CbmTofHit - TClonesArray* fHitMatches; // Input array of CbmMatch - //TClonesArray* fPoints; // Input array of CbmTofPoint - CbmMCDataArray* fPoints; // Input array of CbmTofPoint - TClonesArray* fDigis; // Input array of CbmDigi - TClonesArray* fDigiMatches; // Input array of CbmMatch - TClonesArray* fMuchTracks; // Input array of - Double_t fZ[2]; // TOF location in Z - Double_t fErrX; // hit measurement error in X - Double_t fErrY; // hit measurement error in Y - Double_t fCutChi2; // Chi2-cuts - std::multimap<Double_t, Int_t> fHitX; // hit index vs X - std::multimap<Double_t, Int_t> fHitY; // hit index vs Y - std::map<Int_t, Double_t> fHitTime; // hit time (min. of all contributing points) - std::map<Int_t, std::set<Int_t>> fHitIds; // hit index - to - contributing track IDs - std::vector<CbmMuchTrack*> fVectors; // track vectors for stations - std::multimap<Double_t, TLine> fLineX; // projected TRD vectors vs min X - Double_t fXy[fgkPlanes][5]; // hit float data - Double_t fXyi[fgkPlanes][3]; // hit int data - - void GetHits(); // get TRD hits - void MakeVectors(); // make vectors - void MatchTofToMuch(); // match TOF hits to TRD vectors - void CheckParams(); // check vector parameters (apriory constraints) - void RemoveClones(); // remove clones - void StoreVectors(); // store vectors - void ProcessPlane(Int_t lay, Int_t patt, Int_t flag); // process next plane - void FindLine(Int_t patt, Double_t* pars); // line fit - Double_t FindChi2(Int_t patt, Double_t* pars); // fit chi2 - void AddVector(Int_t patt, Double_t chi2, - Double_t* pars); // add vector to temp. container - void SetTrackId(CbmMuchTrack* vec); // set track ID - - CbmMuchToTofVectors(const CbmMuchToTofVectors&); - CbmMuchToTofVectors& operator=(const CbmMuchToTofVectors&); - - ClassDef(CbmMuchToTofVectors, 0) -}; - -#endif diff --git a/reco/tracking/vector/CbmMuchToTrdVectors.cxx b/reco/tracking/vector/CbmMuchToTrdVectors.cxx deleted file mode 100644 index 9a87b341fddcd3ed165424e701868b13db9b3cad..0000000000000000000000000000000000000000 --- a/reco/tracking/vector/CbmMuchToTrdVectors.cxx +++ /dev/null @@ -1,331 +0,0 @@ -/* Copyright (C) 2018 Veksler and Baldin Laboratory of High Energy Physics, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Alexander Zinchenko [committer] */ - -/** CbmMuchToTrdVectors.cxx - *@author A.Zinchenko <Alexander.Zinchenko@jinr.ru> - *@since 2018 - **/ -#include "CbmMuchToTrdVectors.h" -//#include "CbmDefs.h" -//#include "CbmSetup.h" -#include "CbmMuchTrack.h" - -#include "FairRootManager.h" -#include "FairTrackParam.h" -#include <Logger.h> - -#include <TClonesArray.h> -//#include <TGeoManager.h> -#include <TMath.h> -#include <TMatrixF.h> -#include <TMatrixFSym.h> - -#include <iostream> - -using std::cout; -using std::endl; -using std::multimap; -using std::pair; - -// ----- Default constructor ------------------------------------------- -CbmMuchToTrdVectors::CbmMuchToTrdVectors() - : FairTask("MuchToTrdVectors") - , fTrackArray(NULL) - , fNofTracks(0) - , fMuchTracks(NULL) - , fTrdTracks(NULL) - , fZ0(-1) -{ -} -// ------------------------------------------------------------------------- - -// ----- Destructor ---------------------------------------------------- -CbmMuchToTrdVectors::~CbmMuchToTrdVectors() {} -// ------------------------------------------------------------------------- - -// ----- Public method Init (abstract in base class) -------------------- -InitStatus CbmMuchToTrdVectors::Init() -{ - - // Get and check FairRootManager - FairRootManager* ioman = FairRootManager::Instance(); - if (ioman == NULL) Fatal("Init", "RootManager not instantiated!"); - - // Create and register GlobalVector array - fTrackArray = new TClonesArray("CbmMuchTrack", 100); - ioman->Register("GlobalVector", "Much", fTrackArray, kTRUE); - fMuchTracks = static_cast<TClonesArray*>(ioman->GetObject("MuchVectorTrack")); - fTrdTracks = static_cast<TClonesArray*>(ioman->GetObject("TrdVector")); - - return kSUCCESS; -} -// ------------------------------------------------------------------------- - -// ----- SetParContainers ------------------------------------------------- -void CbmMuchToTrdVectors::SetParContainers() -{ - /* - fDigiPar = (CbmTrdDigiPar*) FairRunAna::Instance()->GetRuntimeDb()->getContainer("CbmTrdDigiPar"); - cout << " ******* digiPar ******** " << fDigiPar << endl; - exit(0); - */ -} -// ------------------------------------------------------------------------- - -// ----- Public method Exec -------------------------------------------- -void CbmMuchToTrdVectors::Exec(Option_t* opt) -{ - - fTrackArray->Delete(); - - // Do all processing - Int_t nTrd = fTrdTracks->GetEntriesFast(); - if (nTrd == 0) return; - - GetMuchVectors(); - - // Merge vectors - MergeVectors(); - - // Remove clones - RemoveClones(); -} -// ------------------------------------------------------------------------- - -// ----- Public method Finish ------------------------------------------ -void CbmMuchToTrdVectors::Finish() {} -// ------------------------------------------------------------------------- - -// ----- Private method GetMuchVectors --------------------------------- -void CbmMuchToTrdVectors::GetMuchVectors() -{ - // Get MUCH vectors, propagate to TRD - - const Int_t nMinSeg = 5; - Int_t nMuch = fMuchTracks->GetEntriesFast(); - fXmap.clear(); - - /* - if (fZ0 < 0) { - // Get TRD first layer position - CbmMuchTrack *tr = (CbmMuchTrack*) fTrdTracks->UncheckedAt(0); - fZ0 = tr->GetParamFirst()->GetZ(); - } - */ - - TMatrixF matr = TMatrixF(5, 5); - TMatrixF unit(TMatrixF::kUnit, matr); - - for (Int_t itr = 0; itr < nMuch; ++itr) { - CbmMuchTrack* tr = (CbmMuchTrack*) fMuchTracks->UncheckedAt(itr); - Int_t nvecTr = tr->GetNofHits(); - if (nvecTr < nMinSeg) continue; // track is too short - - if (fZ0 < 0) { - // Get MUCH first layer position of the last station - fZ0 = tr->GetParamFirst()->GetZ(); - } - - // Propagate to TRD - FairTrackParam parFirst = *tr->GetParamFirst(); - /* - Double_t zbeg = parFirst.GetZ(); - Double_t dz = fZ0 - zbeg; - // Propagate params - parFirst.SetX(parFirst.GetX() + dz * parFirst.GetTx()); - parFirst.SetY(parFirst.GetY() + dz * parFirst.GetTy()); - parFirst.SetZ(parFirst.GetZ() + dz); - TMatrixFSym cov(5); - parFirst.CovMatrix(cov); - cov(4,4) = 1.0; - //cov.Print(); - TMatrixF ff = unit; - //ff.Print(); - //ff(0,2) = ff(1,3) = dz; - ff(2,0) = ff(3,1) = dz; - //cout << " Cov: " << dz << " " << cov(0,0) << " " << cov(1,1) << endl; - TMatrixF cf(cov,TMatrixF::kMult,ff); - TMatrixF fcf(ff,TMatrixF::kTransposeMult,cf); - cov.SetMatrixArray(fcf.GetMatrixArray()); - //cout << " Cov1: " << dz << " " << cov(0,0) << " " << cov(1,1) << endl; - cov.Invert(); // weight matrix - parFirst.SetCovMatrix(cov); - */ - tr->SetParamLast(&parFirst); - fXmap.insert(pair<Double_t, Int_t>(parFirst.GetX(), itr)); - } -} -// ------------------------------------------------------------------------- - -// ----- Private method MergeVectors ----------------------------------- -void CbmMuchToTrdVectors::MergeVectors() -{ - // Merge MUCH and TRD tracks - - //const Double_t window = 25.0, chi2max = 24; - const Double_t window = 35.0, chi2max = 24; - multimap<Double_t, Int_t>::iterator mit, mitb, mite; - FairTrackParam parOk; - - TMatrixF matr = TMatrixF(5, 5); - TMatrixF unit(TMatrixF::kUnit, matr); - - Int_t nTrd = fTrdTracks->GetEntriesFast(); - - for (Int_t itr = 0; itr < nTrd; ++itr) { - CbmMuchTrack* tr = (CbmMuchTrack*) fTrdTracks->UncheckedAt(itr); - //const FairTrackParam *par1 = tr->GetParamFirst(); - FairTrackParam par1 = *tr->GetParamFirst(); - // AZ - Double_t zbeg = par1.GetZ(); - Double_t dz = fZ0 - zbeg; - // Propagate params - par1.SetX(par1.GetX() + dz * par1.GetTx()); - par1.SetY(par1.GetY() + dz * par1.GetTy()); - par1.SetZ(par1.GetZ() + dz); - TMatrixFSym cov(5); - par1.CovMatrix(cov); - cov(4, 4) = 1.0; - //cov.Print(); - TMatrixF ff = unit; - //ff.Print(); - //ff(0,2) = ff(1,3) = dz; - ff(2, 0) = ff(3, 1) = dz; - //cout << " Cov: " << dz << " " << cov(0,0) << " " << cov(1,1) << endl; - TMatrixF cf(cov, TMatrixF::kMult, ff); - TMatrixF fcf(ff, TMatrixF::kTransposeMult, cf); - cov.SetMatrixArray(fcf.GetMatrixArray()); - //cout << " Cov1: " << dz << " " << cov(0,0) << " " << cov(1,1) << endl; - cov.Invert(); // weight matrix - par1.SetCovMatrix(cov); - //AZ - //Double_t xv = par1->GetX(); - //Double_t yv = par1->GetY(); - Double_t xv = par1.GetX(); - Double_t yv = par1.GetY(); - mitb = fXmap.lower_bound(xv - window); // lower X-window edge - mite = fXmap.upper_bound(xv + window); // upper X-window edge - TMatrixFSym w1(5); - //par1->CovMatrix(w1); - //Float_t pars1[5] = {(Float_t)par1->GetX(), (Float_t)par1->GetY(), (Float_t)par1->GetTx(), (Float_t)par1->GetTy(), 1.0}; - par1.CovMatrix(w1); - Float_t pars1[5] = {(Float_t) par1.GetX(), (Float_t) par1.GetY(), (Float_t) par1.GetTx(), (Float_t) par1.GetTy(), - 1.0}; - TMatrixF p1(5, 1, pars1); - TMatrixF wp1(w1, TMatrixF::kTransposeMult, p1); - //Double_t x0 = parOk.GetX(), y0 = parOk.GetY(); - - for (mit = mitb; mit != mite; ++mit) { - Int_t indx = mit->second; - CbmMuchTrack* muchTr = (CbmMuchTrack*) fMuchTracks->UncheckedAt(indx); - const FairTrackParam* par2 = muchTr->GetParamLast(); - if (par2->GetY() < yv - window || par2->GetY() > yv + window) continue; - - TMatrixFSym w2(5); - par2->CovMatrix(w2); - TMatrixFSym w20 = w2; - Float_t pars2[5] = {(Float_t) par2->GetX(), (Float_t) par2->GetY(), (Float_t) par2->GetTx(), - (Float_t) par2->GetTy(), 1.0}; - TMatrixF p2(5, 1, pars2); - TMatrixF wp2(w2, TMatrixF::kTransposeMult, p2); - wp2 += wp1; - w2 += w1; - w2.Invert(); - TMatrixF p12(w2, TMatrixF::kTransposeMult, wp2); - //p12.Print(); - - // Compute Chi2 - TMatrixF p122 = p12; - TMatrixF pMerge = p12; - p12 -= p1; - TMatrixF wDp1(w1, TMatrixF::kMult, p12); - TMatrixF chi21(p12, TMatrixF::kTransposeMult, wDp1); - p122 -= p2; - TMatrixF wDp2(w20, TMatrixF::kMult, p122); - TMatrixF chi22(p122, TMatrixF::kTransposeMult, wDp2); - Double_t c2 = chi21(0, 0) + chi22(0, 0); - //cout << " Chi2: " << chi21(0,0) << " " << chi22(0,0) << " " << c2 << endl; - if (c2 < 0 || c2 > chi2max) continue; - - // Merged track parameters - parOk.SetX(pMerge(0, 0)); - parOk.SetY(pMerge(1, 0)); - parOk.SetZ(par2->GetZ()); - parOk.SetTx(pMerge(2, 0)); - parOk.SetTy(pMerge(3, 0)); - parOk.SetCovMatrix(w2); - AddTrack(muchTr, tr, indx, itr, parOk, c2); // add track - } - } -} -// ------------------------------------------------------------------------- - -// ----- Private method AddTrack --------------------------------------- -void CbmMuchToTrdVectors::AddTrack(CbmMuchTrack* tr1, CbmMuchTrack* tr2, Int_t indx1, Int_t indx2, - FairTrackParam& parOk, Double_t c2) -{ - // Store merged vector (CbmMuchTracks) into TClonesArray - - Int_t ntrs = fTrackArray->GetEntriesFast(); - - CbmMuchTrack* track = new ((*fTrackArray)[ntrs]) CbmMuchTrack(); - track->SetParamFirst(&parOk); - track->SetChiSq(c2 + tr1->GetChiSq() + tr2->GetChiSq()); - track->SetNDF(4 + tr1->GetNDF() + tr2->GetNDF()); - - track->SetPreviousTrackId(indx1); // MUCH track index - track->AddHit(indx2, kMUCHSTRAWHIT); // TRD vector index - - if (tr1->GetFlag() == tr2->GetFlag()) track->SetFlag(tr1->GetFlag()); - else - track->SetFlag(-1); - - gLogger->Info(MESSAGE_ORIGIN, "CbmMuchToTrdVectors::AddTrack: trID1=%i, trID2=%i, chi2=%f", tr1->GetFlag(), - tr2->GetFlag(), track->GetChiSq()); -} -// ------------------------------------------------------------------------- - -// ----- Private method RemoveClones ----------------------------------- -void CbmMuchToTrdVectors::RemoveClones() -{ - // Remove clone tracks (having the same MUCH track) - - Int_t nvec = fTrackArray->GetEntriesFast(); - - // Do sorting according to "quality" - multimap<Double_t, Int_t> qMap; - multimap<Double_t, Int_t>::iterator it, it1; - - for (Int_t i = 0; i < nvec; ++i) { - CbmMuchTrack* vec = (CbmMuchTrack*) fTrackArray->UncheckedAt(i); - //Double_t qual = vec->GetNofHits() + (99 - TMath::Min(vec->GetChiSq(),99.0)) / 100; - Double_t qual = vec->GetChiSq() / vec->GetNDF(); - qMap.insert(pair<Double_t, Int_t>(qual, i)); - } - - for (it = qMap.begin(); it != qMap.end(); ++it) { - CbmMuchTrack* vec = (CbmMuchTrack*) fTrackArray->UncheckedAt(it->second); - if (vec == NULL) continue; - Int_t prevIndx = vec->GetPreviousTrackId(); - - it1 = it; - for (++it1; it1 != qMap.end(); ++it1) { - CbmMuchTrack* vec1 = (CbmMuchTrack*) fTrackArray->UncheckedAt(it1->second); - if (vec1 == NULL) continue; - - if (vec1->GetPreviousTrackId() == prevIndx) { - fTrackArray->RemoveAt(it1->second); - continue; - } - } - } // for (it = qMap.begin(); - - fTrackArray->Compress(); - fNofTracks = fTrackArray->GetEntriesFast(); - - cout << " Global vectors after clones removed: " << nvec << " " << fNofTracks << endl; -} -// ------------------------------------------------------------------------- - -ClassImp(CbmMuchToTrdVectors); diff --git a/reco/tracking/vector/CbmMuchToTrdVectors.h b/reco/tracking/vector/CbmMuchToTrdVectors.h deleted file mode 100644 index ed15d12d225d55b502a65b5aaa5006e517ef72fe..0000000000000000000000000000000000000000 --- a/reco/tracking/vector/CbmMuchToTrdVectors.h +++ /dev/null @@ -1,76 +0,0 @@ -/* Copyright (C) 2018 Veksler and Baldin Laboratory of High Energy Physics, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Alexander Zinchenko [committer] */ - -/** CbmMuchToTrdVectors.h - *@author A.Zinchenko <Alexander.Zinchenko@jinr.ru> - *@since 2018 - ** - ** Task class for MUCH-to-TRD vector merging in CBM. - ** Input: - ** Output: - ** - **/ - -#ifndef CBMMUCHTOTRDVECTORS_H_ -#define CBMMUCHTOTRDVECTORS_H_ 1 - -#include "FairTask.h" -//#include "FairTrackParam.h" - -#include <map> - -class CbmMuchTrack; -class FairTrackParam; -class TClonesArray; -//class CbmTrdDigiPar; - -class CbmMuchToTrdVectors : public FairTask { -public: - /** Default constructor **/ - CbmMuchToTrdVectors(); - - /** Destructor **/ - virtual ~CbmMuchToTrdVectors(); - - /** Initialisation **/ - virtual InitStatus Init(); - - /** Task execution **/ - virtual void Exec(Option_t* opt); - - /** Finish at the end **/ - virtual void Finish(); - - /** SetParContainers **/ - virtual void SetParContainers(); - - /** Accessors **/ - Int_t GetNofTracks() { return fNofTracks; }; - -private: - // Some constants - -private: - //CbmTrdDigiPar *fDigiPar; // digi params - TClonesArray* fTrackArray; // Output array of CbmMuchVectors - Int_t fNofTracks; // Number of tracks created - TClonesArray* fMuchTracks; // Input array of CbmMuchTrack - TClonesArray* fTrdTracks; // Input array of CbmMuchTrack - TClonesArray* fDigiMatches; // Input array of - Double_t fZ0; // Z-position of the TRD first layer - std::multimap<Double_t, Int_t> fXmap; // track indices vs X-coord. - - void GetMuchVectors(); // get MUCH vectors - void MergeVectors(); // merge vectors - void AddTrack(CbmMuchTrack* tr1, CbmMuchTrack* tr2, Int_t indx1, Int_t indx2, FairTrackParam& parOk, - Double_t c2); // add track - void RemoveClones(); // remove clones - - CbmMuchToTrdVectors(const CbmMuchToTrdVectors&); - CbmMuchToTrdVectors& operator=(const CbmMuchToTrdVectors&); - - ClassDef(CbmMuchToTrdVectors, 0) -}; - -#endif diff --git a/reco/tracking/vector/CbmTrdFindVectors.cxx b/reco/tracking/vector/CbmTrdFindVectors.cxx deleted file mode 100644 index b31ca1db00621c12b967e10c4a0a326aa8627542..0000000000000000000000000000000000000000 --- a/reco/tracking/vector/CbmTrdFindVectors.cxx +++ /dev/null @@ -1,723 +0,0 @@ -/* Copyright (C) 2017-2019 Veksler and Baldin Laboratory of High Energy Physics, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Alexander Zinchenko [committer] */ - -/** CbmTrdFindVectors.cxx - *@author A.Zinchenko <Alexander.Zinchenko@jinr.ru> - *@since 2017 - **/ -#include "CbmTrdFindVectors.h" - -#include "CbmDefs.h" -#include "CbmSetup.h" -//#include "CbmTrdModule.h" -//#include "CbmTrdDigiPar.h" -#include "CbmMCDataArray.h" -#include "CbmMCDataManager.h" -#include "CbmMatch.h" -#include "CbmMuchTrack.h" -#include "CbmTrdAddress.h" -#include "CbmTrdCluster.h" -#include "CbmTrdHit.h" -#include "CbmTrdPoint.h" - -//#include "FairRunAna.h" -//#include "FairRuntimeDb.h" -#include "FairRootManager.h" - -#include <TClonesArray.h> -#include <TGeoManager.h> -#include <TMath.h> - -#include <iostream> - -using std::cout; -using std::endl; -using std::map; -using std::multimap; -using std::pair; - -// ----- Default constructor ------------------------------------------- -CbmTrdFindVectors::CbmTrdFindVectors() - : FairTask("TrdFindVectors") - , fTrackArray(NULL) - , fNofTracks(0) - , fHits(NULL) - , fClusters(NULL) - , fPoints(NULL) - , fDigiMatches(NULL) - , fZ0(99999) - , fErrX(1.0) - , fErrY(1.0) - , fCutChi2(24.0) // chi2/ndf = 6 for 4 hits -{ -} -// ------------------------------------------------------------------------- - -// ----- Destructor ---------------------------------------------------- -CbmTrdFindVectors::~CbmTrdFindVectors() {} -// ------------------------------------------------------------------------- - -// ----- Public method Init (abstract in base class) -------------------- -InitStatus CbmTrdFindVectors::Init() -{ - - // Get and check FairRootManager - FairRootManager* ioman = FairRootManager::Instance(); - if (ioman == NULL) Fatal("Init", "RootManager not instantiated!"); - - // Create and register TrdTrack array (if necessary) - //fTrackArray = static_cast<TClonesArray*> (ioman->GetObject("MuchVector")); - //if (fTrackArray == NULL) { - fTrackArray = new TClonesArray("CbmMuchTrack", 100); - ioman->Register("TrdVector", "Trd", fTrackArray, kTRUE); - //} - fHits = static_cast<TClonesArray*>(ioman->GetObject("TrdHit")); - fClusters = static_cast<TClonesArray*>(ioman->GetObject("TrdCluster")); - //fPoints = static_cast<TClonesArray*> (ioman->GetObject("TrdPoint")); - CbmMCDataManager* mcManager = (CbmMCDataManager*) ioman->GetObject("MCDataManager"); - if (NULL == mcManager) LOG(fatal) << GetName() << ": No CbmMCDataManager!"; - fPoints = mcManager->InitBranch("TrdPoint"); - fDigiMatches = static_cast<TClonesArray*>(ioman->GetObject("TrdDigiMatch")); - - TString tag; - CbmSetup::Instance()->GetGeoTag(kTrd, tag); - cout << " ******* digiPar ******** " << tag << endl; - tag.Prepend("trd_"); - - //CbmTrdGeoHandler geoHandler; - //geoHandler.Init(); - - // Go to TRD - TGeoVolume* trdV = gGeoManager->GetVolume(tag); - TGeoNode* trd = NULL; - gGeoManager->CdTop(); - TGeoNode* cave = gGeoManager->GetCurrentNode(); - for (Int_t iNode = 0; iNode < cave->GetNdaughters(); iNode++) { - TGeoNode* node = cave->GetDaughter(iNode); - TString name = node->GetName(); - if (name.Contains("trd")) { - trd = node; - gGeoManager->CdDown(iNode); - break; - } - } - if (!trd) { - cout << "-E- CbmTrdFindVectors::Init: Cannot find top TRD node" << endl; - return kFATAL; - } - - Int_t nlays = trdV->GetNdaughters(); - - // Loop over layers - for (Int_t i = 0; i < nlays; ++i) { - TGeoVolume* lay = trdV->GetNode(i)->GetVolume(); - if (!(TString(lay->GetName()).Contains("layer"))) continue; - gGeoManager->CdDown(i); - Int_t nmod = lay->GetNdaughters(); - - // Loop over modules - for (Int_t j = 0; j < nmod; ++j) { - TGeoVolume* mod = lay->GetNode(j)->GetVolume(); - if (!(TString(mod->GetName()).Contains("module"))) continue; - gGeoManager->CdDown(j); - Int_t nparts = mod->GetNdaughters(); - - // Loop over module parts - for (Int_t k = 0; k < nparts; ++k) { - TGeoNode* part = mod->GetNode(k); - if (!(TString(part->GetName()).Contains("gas"))) continue; - gGeoManager->CdDown(k); - Double_t posLoc[3] = {0}, posGlob[3] = {0}; - gGeoManager->LocalToMaster(posLoc, posGlob); - cout << " gas " << gGeoManager->GetPath() << " " << std::setprecision(4) << posGlob[2] << endl; - if (i == 0) fZ0 = posGlob[2]; - fDz[i] = posGlob[2] - fZ0; - gGeoManager->CdUp(); - break; - } - gGeoManager->CdUp(); - break; - } // for (Int_t j = 0; j < nmod; - - gGeoManager->CdUp(); - } // for (Int_t i = 0; i < nlays; - - //exit(0); - ComputeMatrix(); // compute system matrices - - return kSUCCESS; -} -// ------------------------------------------------------------------------- - -// ----- SetParContainers ------------------------------------------------- -void CbmTrdFindVectors::SetParContainers() -{ - /* - fDigiPar = (CbmTrdDigiPar*) FairRunAna::Instance()->GetRuntimeDb()->getContainer("CbmTrdDigiPar"); - cout << " ******* digiPar ******** " << fDigiPar << endl; - exit(0); - */ -} -// ------------------------------------------------------------------------- - -// ----- Public method Exec -------------------------------------------- -void CbmTrdFindVectors::Exec(Option_t* opt) -{ - - fTrackArray->Delete(); - - Int_t nVecs = fVectors.size(); - for (Int_t j = 0; j < nVecs; ++j) - delete fVectors[j]; - fVectors.clear(); - - // Do all processing - - // Get hits - GetHits(); - - // Build vectors - MakeVectors(); - - // Remove vectors with wrong orientation - // (using empirical cuts for omega muons at 8 GeV) - CheckParams(); - - // Match vectors from 2 stations - //MatchVectors(); - - // Remove clones - RemoveClones(); - - // Store vectors - StoreVectors(); -} -// ------------------------------------------------------------------------- - -// ----- Public method Finish ------------------------------------------ -void CbmTrdFindVectors::Finish() {} -// ------------------------------------------------------------------------- - -// ----- Private method ComputeMatrix ---------------------------------- -void CbmTrdFindVectors::ComputeMatrix() -{ - // Compute system matrices for different hit plane patterns - - Double_t dz2[fgkPlanes]; - Bool_t onoff[fgkPlanes]; - - for (Int_t i = 0; i < fgkPlanes; ++i) { - dz2[i] = fDz[i] * fDz[i]; - onoff[i] = kTRUE; - } - - TMatrixD coef(4, 4); - Int_t pattMax = 1 << fgkPlanes, nDouble = 0, nTot = 0; - - // Loop over doublet patterns - for (Int_t ipat = 1; ipat < pattMax; ++ipat) { - - // Check if the pattern is valid: all doublets are active - nDouble = 0; - //for (Int_t j = 0; j < fgkPlanes; j += 2) if (ipat & (3 << j)) ++nDouble; else break; - for (Int_t j = 0; j < fgkPlanes; j += 1) - if (ipat & (1 << j)) ++nDouble; - if (nDouble < 3) continue; - ++nTot; - - for (Int_t j = 0; j < fgkPlanes; ++j) - onoff[j] = (ipat & (1 << j)); - - coef = 0.0; - for (Int_t i = 0; i < fgkPlanes; ++i) { - if (!onoff[i]) continue; - coef(0, 0) += 1; - coef(0, 1) += 0; - coef(0, 2) += fDz[i]; - coef(0, 3) += 0; - } - for (Int_t i = 0; i < fgkPlanes; ++i) { - if (!onoff[i]) continue; - coef(1, 0) += 0; - coef(1, 1) += 1; - coef(1, 2) += 0; - coef(1, 3) += fDz[i]; - } - for (Int_t i = 0; i < fgkPlanes; ++i) { - if (!onoff[i]) continue; - coef(2, 0) += fDz[i]; - coef(2, 1) += 0; - coef(2, 2) += dz2[i]; - coef(2, 3) += 0; - } - for (Int_t i = 0; i < fgkPlanes; ++i) { - if (!onoff[i]) continue; - coef(3, 0) += 0; - coef(3, 1) += fDz[i]; - coef(3, 2) += 0; - coef(3, 3) += dz2[i]; - } - - TDecompLU* lu = new TDecompLU(4); - lu->SetMatrix(coef); - lu->SetTol(0.1 * lu->GetTol()); - lu->Decompose(); - //fLus.insert(pair<Int_t,TDecompLU*>(ipat,lu)); - fLus[ipat] = lu; - TMatrixDSym cov(4); - cov.SetMatrixArray(coef.GetMatrixArray()); - cov.Invert(); // covar. matrix - //fMatr.insert(pair<Int_t,TMatrixDSym*>(ipat,new TMatrixDSym(cov))); - fMatr[ipat] = new TMatrixDSym(cov); - TString buf = ""; - for (Int_t jp = 0; jp < fgkPlanes; ++jp) - buf += Bool_t(ipat & (1 << jp)); - Info("ComputeMatrix", " Determinant: %s %i %f", buf.Data(), ipat, coef.Determinant()); - //if (ipat == 63) { coef.Print(); Info("ComputeMatrix"," Number of configurations: %i", nTot); } - //cout << " Number of configurations: " << nTot << endl; } - cov *= (1.2 * 1.2); - cout << TMath::Sqrt(cov(0, 0)) << " " << TMath::Sqrt(cov(1, 1)) << " " << TMath::Sqrt(cov(2, 2)) << " " - << TMath::Sqrt(cov(3, 3)) << endl; - cov *= (1.7 * 1.7 / 1.2 / 1.2); - cout << TMath::Sqrt(cov(0, 0)) << " " << TMath::Sqrt(cov(1, 1)) << " " << TMath::Sqrt(cov(2, 2)) << " " - << TMath::Sqrt(cov(3, 3)) << endl; - } -} -// ------------------------------------------------------------------------- - -// ----- Private method GetHits ---------------------------------------- -void CbmTrdFindVectors::GetHits() -{ - // Group hits according to their plane number - - for (Int_t i = 0; i < fgkPlanes; ++i) { - fHitPl[i].clear(); - fHitX[i].clear(); - } - - Int_t nHits = fHits->GetEntriesFast(), sel = 0; - - for (Int_t i = 0; i < nHits; ++i) { - CbmTrdHit* hit = (CbmTrdHit*) fHits->UncheckedAt(i); - - //!!! For debug - select hits with certain track IDs - sel = 1; //SelectHitId(hit); - if (!sel) continue; - // - /* - Int_t address = hit->GetAddress(); - Int_t layer = CbmTrdAddress::GetLayerId(address); // layer - Int_t colId = CbmTrdAddress::GetColumnId(address); - Int_t rowId = CbmTrdAddress::GetRowId(address); - */ - Int_t layer = hit->GetPlaneId(), colId = 0; - fHitPl[layer].insert(pair<Int_t, Int_t>(colId, i)); - fHitX[layer].insert(pair<Double_t, Int_t>(hit->GetX(), i)); - } -} -// ------------------------------------------------------------------------- - -// ----- Private method MakeVectors ------------------------------------ -void CbmTrdFindVectors::MakeVectors() -{ - // Make vectors - - Int_t nvec = fVectors.size(); - for (Int_t j = 0; j < nvec; ++j) - delete fVectors[j]; - fVectors.clear(); - CbmTrdHit* hit = NULL; - - cout << " TRD hits: " << fHits->GetEntriesFast() << endl; - for (Int_t lay = 0; lay < 2; ++lay) { - Int_t patt = 0, flag = 1, nhits = fHitPl[lay].size(); - cout << " Hits: " << lay << " " << nhits << endl; - multimap<Int_t, Int_t>::iterator mit; - - for (mit = fHitPl[lay].begin(); mit != fHitPl[lay].end(); ++mit) { - Int_t indx = mit->second; - hit = (CbmTrdHit*) fHits->UncheckedAt(indx); - fXy[lay][0] = hit->GetX(); - fXy[lay][1] = hit->GetY(); - fXy[lay][2] = hit->GetDx(); - fXy[lay][3] = hit->GetDy(); - //fXy[lay][2] = TMath::Max (hit->GetDx(),fErrX[ista]); - //fXy[lay][3] = TMath::Max (hit->GetDy(),fErrY[ista]); - fXy[lay][4] = hit->GetZ(); - //fXyi[lay][0] = CbmMuchAddress::GetModuleIndex(hit->GetAddress()); // sector No. - fXyi[lay][1] = indx; - patt = (1 << lay); - //cout << lay << " " << hit->GetX() << " " << hit->GetY() << " " << hit->GetZ() << " " << endl; - ProcessPlane(lay + 1, patt, flag); - } - } -} -// ------------------------------------------------------------------------- - -// ----- Private method CheckParams ------------------------------------ -void CbmTrdFindVectors::CheckParams() -{ - // Remove vectors with wrong orientation - // using empirical cuts for omega muons at 8 Gev - - const Double_t cut[2] = {0.6, 0.5}; // !!! empirical !!! - - Int_t nvec = fVectors.size(); - - for (Int_t iv = 0; iv < nvec; ++iv) { - CbmMuchTrack* vec = fVectors[iv]; - const FairTrackParam* params = vec->GetParamFirst(); - Double_t dTx = params->GetTx() - params->GetX() / params->GetZ(); - if (TMath::Abs(dTx) > cut[0]) vec->SetChiSq(-1.0); - else { - Double_t dTy = params->GetTy() - params->GetY() / params->GetZ(); - if (TMath::Abs(dTy) > cut[1]) vec->SetChiSq(-1.0); - } - } - - for (Int_t iv = nvec - 1; iv >= 0; --iv) { - CbmMuchTrack* vec = fVectors[iv]; - if (vec->GetChiSq() < 0) { - delete fVectors[iv]; - fVectors.erase(fVectors.begin() + iv); - } - } - cout << " Vectors after parameter check: " << nvec << " " << fVectors.size() << endl; -} -// ------------------------------------------------------------------------- - -// ----- Private method RemoveClones ----------------------------------- -void CbmTrdFindVectors::RemoveClones() -{ - // Remove clone vectors (having at least 3 the same hits) - - //Int_t nthr = 3, planes[20]; - Int_t nthr = 2, planes[20]; - - Int_t nvec = fVectors.size(); - - // Do sorting according to "quality" - multimap<Double_t, CbmMuchTrack*> qMap; - multimap<Double_t, CbmMuchTrack*>::iterator it, it1; - - for (Int_t i = 0; i < nvec; ++i) { - CbmMuchTrack* vec = fVectors[i]; - Double_t qual = vec->GetNofHits() + (99 - TMath::Min(vec->GetChiSq(), 99.0)) / 100; - qMap.insert(pair<Double_t, CbmMuchTrack*>(-qual, vec)); - } - - for (it = qMap.begin(); it != qMap.end(); ++it) { - CbmMuchTrack* vec = it->second; - if (vec->GetChiSq() < 0) continue; - for (Int_t j = 0; j < fgkPlanes; ++j) - planes[j] = -1; - - Int_t nhits = vec->GetNofHits(); - for (Int_t ih = 0; ih < nhits; ++ih) { - CbmTrdHit* hit = (CbmTrdHit*) fHits->UncheckedAt(vec->GetHitIndex(ih)); - Int_t lay = hit->GetPlaneId(); - planes[lay] = vec->GetHitIndex(ih); - } - - it1 = it; - for (++it1; it1 != qMap.end(); ++it1) { - CbmMuchTrack* vec1 = it1->second; - if (vec1->GetChiSq() < 0) continue; - Int_t nsame = 0, same[fgkPlanes] = {0}; - - Int_t nhits1 = vec1->GetNofHits(); - //nthr = TMath::Min(nhits,nhits1) / 2; - //nthr = TMath::Min(nhits,nhits1) * 0.75; - for (Int_t ih = 0; ih < nhits1; ++ih) { - CbmTrdHit* hit = (CbmTrdHit*) fHits->UncheckedAt(vec1->GetHitIndex(ih)); - Int_t lay = hit->GetPlaneId(); - if (planes[lay] >= 0) { - if (vec1->GetHitIndex(ih) == planes[lay]) same[lay] = 1; - //else same[lay] = 0; - } - } - for (Int_t lay = 0; lay < fgkPlanes; ++lay) - nsame += same[lay]; - - if (nsame >= nthr) { - // Too many the same hits - Int_t clone = 0; - if (nhits > nhits1 + 0) clone = 1; - else if (vec->GetChiSq() * 1 <= vec1->GetChiSq()) - clone = 1; // the same number of hits on 2 tracks - //else if (vec->GetChiSq() * 1.5 <= vec1->GetChiSq()) clone = 1; // the same number of hits on 2 tracks - if (clone) vec1->SetChiSq(-1.0); - } - } - } // for (it = qMap.begin(); - - for (Int_t iv = nvec - 1; iv >= 0; --iv) { - CbmMuchTrack* vec = fVectors[iv]; - if (vec->GetChiSq() < 0) { - delete fVectors[iv]; - fVectors.erase(fVectors.begin() + iv); - } - } - cout << " Vectors after clones removed: " << nvec << " " << fVectors.size() << endl; -} -// ------------------------------------------------------------------------- - -// ----- Private method StoreVectors ----------------------------------- -void CbmTrdFindVectors::StoreVectors() -{ - // Store vectors (CbmMuchTracks) into TClonesArray - - Int_t ntrs = fTrackArray->GetEntriesFast(); - Int_t nHitsTot = fHits->GetEntriesFast(); - - //set<Int_t> usedHits; - Int_t nvec = fVectors.size(); - - for (Int_t iv = 0; iv < nvec; ++iv) { - CbmMuchTrack* tr = new ((*fTrackArray)[ntrs++]) CbmMuchTrack(*(fVectors[iv])); - //cout << " Track: " << tr->GetNofHits() << endl; - //for (Int_t j = 0; j < tr->GetNofHits(); ++j) cout << j << " " << tr->GetHitIndex(j) << " " << fVectors[ist][iv]->GetHitIndex(j) << endl; - // Set hit flag (to check Lit tracking) - Int_t nhits = tr->GetNofHits(); - } -} -// ------------------------------------------------------------------------- - -// ----- Private method ProcessPlane ----------------------------------- -void CbmTrdFindVectors::ProcessPlane(Int_t lay, Int_t patt, Int_t flag0) -{ - // Main processing engine (recursively adds layer hits to the vector) - - const Double_t cut[2] = {0.6, 0.5}; // !!! empirical !!! - cut on Tx(y) - x(y)/z - const Double_t cut1[2] = {0.25, 0.15}; // !!! empirical !!! - cut on Tx(y) - Tx(y) (between segments) - - Double_t pars[4] = {0.0}; - Int_t flag = 0; - multimap<Int_t, Int_t>::iterator mit; - // Clear bits - patt &= ~(1 << lay); - - for (mit = fHitPl[lay].begin(); mit != fHitPl[lay].end(); ++mit) { - Int_t indx = mit->second; - - CbmTrdHit* hit = (CbmTrdHit*) fHits->UncheckedAt(indx); - fXy[lay][0] = hit->GetX(); - fXy[lay][1] = hit->GetY(); - fXy[lay][2] = hit->GetDx(); - fXy[lay][3] = hit->GetDy(); - //fXy[lay][2] = TMath::Max (hit->GetDx(),fErrX[ista]); - //fXy[lay][3] = TMath::Max (hit->GetDy(),fErrY[ista]); - fXy[lay][4] = hit->GetZ(); - // Clear bits - patt &= ~(1 << lay); - - // Check slopes - Int_t lay0 = 0; - if (!(patt & (1 << lay0))) ++lay0; - ; - if (TString::Itoa(patt, 2).CountChar('1') < 2) { - // First segment - Double_t dx = fXy[lay][0] - fXy[lay0][0]; - Double_t dz = fXy[lay][4] - fXy[lay0][4]; - //Double_t dTx = TMath::Abs(dx/dz) - TMath::Abs(fXy[lay][0]/fXy[lay][4]); - Double_t dTx = dx / dz - fXy[lay][0] / fXy[lay][4]; - if (TMath::Abs(dTx) > cut[0]) continue; - Double_t dy = fXy[lay][1] - fXy[lay0][1]; - //Double_t dTy = TMath::Abs(dy/dz) - TMath::Abs(fXy[lay][1]/fXy[lay][4]); - Double_t dTy = dy / dz - fXy[lay][1] / fXy[lay][4]; - if (TMath::Abs(dTy) > cut[1]) continue; - } - else { - Double_t dx = fXy[lay][0] - fXy[lay0][0]; - Double_t dz = fXy[lay][4] - fXy[lay0][4]; - Int_t lay1 = lay - 1; - if (!(patt & (1 << lay1))) --lay1; - ; - Double_t dx1 = fXy[lay][0] - fXy[lay1][0]; - Double_t dz1 = fXy[lay][4] - fXy[lay1][4]; - Double_t dTx = dx / dz - dx1 / dz1; - if (TMath::Abs(dTx) > cut1[0]) continue; - Double_t dy = fXy[lay][1] - fXy[lay0][1]; - Double_t dy1 = fXy[lay][1] - fXy[lay1][1]; - Double_t dTy = dy / dz - dy1 / dz1; - if (TMath::Abs(dTy) > cut1[1]) continue; - } - - fXyi[lay][1] = indx; - flag = 1; - - // Set bit - patt |= (1 << lay); - //cout << lay << " " << patt << " " << hit->GetX() << " " << hit->GetY() << " " << hit->GetZ() << " " << endl; - - if (lay < fgkPlanes - 1) ProcessPlane(lay + 1, patt, flag); - else if (TString::Itoa(patt, 2).CountChar('1') > 2) { - // Straight line fit of the vector with > 2 hits - FindLine(patt, pars); - Double_t chi2 = FindChi2(patt, pars); - cout << " *** Stat: " << chi2 << " " << pars[0] << " " << pars[1] << endl; - if (chi2 <= fCutChi2) AddVector(patt, chi2, pars); // add vector to the temporary container - } - } // for (mit = fHitPl[lay].begin(); - - //if (flag == 0) { - if (flag >= 0) { - // Missing plane - if (flag0 == 0) return; // 2 consecutive missing planes - // Clear bits - patt &= ~(1 << lay); - if (lay < fgkPlanes - 1) ProcessPlane(lay + 1, patt, flag); - else if (TString::Itoa(patt, 2).CountChar('1') > 2) { - // Straight line fit of the vector with > 2 hits - FindLine(patt, pars); - Double_t chi2 = FindChi2(patt, pars); - cout << " *** Stat: " << chi2 << " " << pars[0] << " " << pars[1] << endl; - if (chi2 <= fCutChi2) AddVector(patt, chi2, pars); // add vector to the temporary container - } - } -} -// ------------------------------------------------------------------------- - -// ----- Private method FindLine --------------------------------------- -void CbmTrdFindVectors::FindLine(Int_t patt, Double_t* pars) -{ - // Fit of hits to the straight line - - // Solve system of linear equations - Bool_t ok = kFALSE, onoff; - TVectorD b(4); - for (Int_t i = 0; i < fgkPlanes; ++i) { - onoff = patt & (1 << i); - if (!onoff) continue; - b[0] += fXy[i][0]; - b[1] += fXy[i][1]; - b[2] += fXy[i][0] * fDz[i]; - b[3] += fXy[i][1] * fDz[i]; - } - - //lu.Print(); - TVectorD solve = fLus[patt]->Solve(b, ok); - //TVectorD solve = lu.TransSolve(b, ok); - //lu.Print(); - for (Int_t i = 0; i < 4; ++i) - pars[i] = solve[i]; - //for (Int_t i = 0; i < 4; ++i) { cout << pars[i] << " "; if (i == 3) cout << endl; } - //Double_t y1 = cosa / sina * (uz[1][0] * cosa - uz[0][0]) + uz[1][0] * sina; - //Double_t y2 = -cosa / sina * (uz[2][0] * cosa - uz[0][0]) - uz[2][0] * sina; - //cout << " OK " << ok << " " << y1 << " " << y2 << endl; -} -// ------------------------------------------------------------------------- - -// ----- Private method FindChi2 --------------------------------------- -Double_t CbmTrdFindVectors::FindChi2(Int_t patt, Double_t* pars) -{ - // Compute chi2 of the fit - - Double_t chi2 = 0, x = 0, y = 0; - Bool_t onoff; - - for (Int_t i = 0; i < fgkPlanes; ++i) { - onoff = patt & (1 << i); - if (!onoff) continue; - x = pars[0] + pars[2] * fDz[i]; - y = pars[1] + pars[3] * fDz[i]; - //Double_t dx = (x - fXy[i][0]) / fErrX; - //Double_t dy = (y - fXy[i][1]) / fErrY; - Double_t dx = (x - fXy[i][0]) / TMath::Max(fXy[i][2], fErrX); - Double_t dy = (y - fXy[i][1]) / TMath::Max(fXy[i][3], fErrY); - chi2 += dx * dx; - chi2 += dy * dy; - } - //cout << " Chi2 = " << chi2 << endl; - return chi2; -} -// ------------------------------------------------------------------------- - -// ----- Private method AddVector -------------------------------------- -void CbmTrdFindVectors::AddVector(Int_t patt, Double_t chi2, Double_t* pars) -{ - // Add vector to the temporary container (as a MuchTrack) - - Bool_t refit = kFALSE; //kTRUE; - TMatrixDSym cov(4); - - if (refit) { - // Refit line with individual hit errors - //cout << " Before: " << chi2 << endl; - //Refit(patt, chi2, pars, cov); - //cout << " After: " << chi2 << endl; - } - else { - cov = *fMatr[patt]; - cov *= (fErrX * fErrX); // the same error in X and Y - } - cov.ResizeTo(5, 5); - cov(4, 4) = 1.0; - - CbmMuchTrack* track = new CbmMuchTrack(); - track->SetChiSq(chi2); - FairTrackParam par(pars[0], pars[1], fZ0, pars[2], pars[3], 0.0, cov); - track->SetParamFirst(&par); - par.SetZ(fZ0 + fDz[fgkPlanes - 1]); - par.SetX(pars[0] + fDz[fgkPlanes - 1] * pars[2]); - par.SetY(pars[1] + fDz[fgkPlanes - 1] * pars[3]); - track->SetParamLast(&par); - //track->SetUniqueID(ista); // just to pass the value - - for (Int_t ipl = 0; ipl < fgkPlanes; ++ipl) { - if (!(patt & (1 << ipl))) continue; - track->AddHit(fXyi[ipl][1], kTRDHIT); - } - Int_t ndf = (track->GetNofHits() > 2) ? track->GetNofHits() * 2 - 4 : 1; - track->SetNDF(ndf); - SetTrackId(track); // set track ID as its flag - fVectors.push_back(track); -} -// ------------------------------------------------------------------------- - -// ----- Private method SetTrackId ------------------------------------- -void CbmTrdFindVectors::SetTrackId(CbmMuchTrack* vec) -{ - // Set vector ID as its flag (maximum track ID of its poins) - - map<Int_t, Int_t> ids; - Int_t nhits = vec->GetNofHits(), id = 0; - - //* - for (Int_t ih = 0; ih < nhits; ++ih) { - CbmTrdHit* hit = (CbmTrdHit*) fHits->UncheckedAt(vec->GetHitIndex(ih)); - CbmTrdCluster* clus = (CbmTrdCluster*) fClusters->UncheckedAt(hit->GetRefId()); - Int_t nDigis = clus->GetNofDigis(); - - for (Int_t j = 0; j < nDigis; ++j) { - CbmMatch* digiM = (CbmMatch*) fDigiMatches->UncheckedAt(clus->GetDigi(j)); - Int_t np = digiM->GetNofLinks(); - - for (Int_t ip = 0; ip < np; ++ip) { - CbmLink link = digiM->GetLink(ip); - //CbmTrdPoint* point = (CbmTrdPoint*) fPoints->UncheckedAt(digiM->GetLink(ip).GetIndex()); - CbmTrdPoint* point = (CbmTrdPoint*) fPoints->Get(link.GetFile(), link.GetEntry(), link.GetIndex()); - id = point->GetTrackID(); - //if (np > 1) cout << ip << " " << id << endl; - if (ids.find(id) == ids.end()) ids.insert(pair<Int_t, Int_t>(id, 1)); - else - ++ids[id]; - } - //if (np > 1) { cout << " digi " << digiM->GetNofLinks() << " " << ista << " " << hit->GetX() << " " << hit->GetY() << endl; exit(0); } - } - } - Int_t maxim = -1, idmax = -9; - for (map<Int_t, Int_t>::iterator it = ids.begin(); it != ids.end(); ++it) { - if (it->second > maxim) { - maxim = it->second; - idmax = it->first; - } - } - // Set vector ID as its flag - vec->SetFlag(idmax); - //*/ -} -// ------------------------------------------------------------------------- - -ClassImp(CbmTrdFindVectors); diff --git a/reco/tracking/vector/CbmTrdFindVectors.h b/reco/tracking/vector/CbmTrdFindVectors.h deleted file mode 100644 index f2cb35b3cbbe5636aa7e390b894b7ba27c2952e5..0000000000000000000000000000000000000000 --- a/reco/tracking/vector/CbmTrdFindVectors.h +++ /dev/null @@ -1,155 +0,0 @@ -/* Copyright (C) 2017-2018 Veksler and Baldin Laboratory of High Energy Physics, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Alexander Zinchenko [committer] */ - -/** CbmTrdFindVectors.h - *@author A.Zinchenko <Alexander.Zinchenko@jinr.ru> - *@since 2017 - ** - ** Task class for vector finding in CBM TRD. - ** Input: - ** Output: - ** - **/ - -#ifndef CBMTRDFINDVECTORS_H_ -#define CBMTRDFINDVECTORS_H_ 1 - -//#include "CbmMuchGeoScheme.h" -#include "FairTask.h" -//#include "FairTrackParam.h" -#include <TDecompLU.h> - -#include <map> -//#include <set> -#include <vector> - -//class CbmMuchPixelHit; -class CbmMuchTrack; -//class TClonesArray; -//class CbmTrdDigiPar; -class CbmMCDataArray; - -class CbmTrdFindVectors : public FairTask { -public: - /** Default constructor **/ - CbmTrdFindVectors(); - - /** Destructor **/ - virtual ~CbmTrdFindVectors(); - - /** Initialisation **/ - virtual InitStatus Init(); - - /** Task execution **/ - virtual void Exec(Option_t* opt); - - /** Finish at the end **/ - virtual void Finish(); - - /** SetParContainers **/ - virtual void SetParContainers(); - - /** Accessors **/ - Int_t GetNofTracks() { return fNofTracks; }; - //Int_t GetNofStat() const { return fgkStat; } - -private: - // Some constants - //static const Int_t fgkStat = 1; // Number of stations - 1 - static const Int_t fgkPlanes = 4; // Number of TRD layers - -private: - /* - CbmMuchGeoScheme* fGeoScheme; // Geometry scheme - TClonesArray* fTrackArray; // Output array of CbmMuchVectors - Int_t fNofTracks; // Number of tracks created - TClonesArray* fHits; // Input array of CbmMuchHit - TClonesArray* fClusters; // Input array of CbmMuchCluster - TClonesArray* fPoints; // Input array of CbmMuchHit - TClonesArray* fDigiMatches; // Input array of CbmMuchHit - Int_t fStatFirst; // First straw station No. - std::multimap<Int_t,Int_t> fHitPl[fgkStat][fgkPlanes]; // hit indices on planes vs tube No - std::multimap<Double_t,Int_t> fHitX[fgkStat][fgkPlanes]; // hit indices on planes vs X-coord. - std::vector<CbmMuchTrack*> fVectors[fgkStat]; // track vectors for stations - //std::vector<CbmMuchTrack*> fVectorsHigh[fgkStat]; // track vectors for stations (high resolution) - Double_t fXy[fgkPlanes][5]; // hit float data - Double_t fXyi[fgkPlanes][3]; // hit int data - Double_t fDz[fgkPlanes]; // geometrical constants (Z-distances from layer 0) - std::map<Int_t,TDecompLU*> fLus; // system matrices (for different hit layer patterns) - Double_t fErrX[9]; // hit measurement error in X - Double_t fErrY[9]; // hit measurement error in Y - Double_t fCutChi2[9]; // Chi2-cuts for each station - Double_t fZ0[fgkStat]; // Z-positions of the first layers - Double_t fRmin[fgkStat]; // inner radii of stations - Double_t fRmax[fgkStat]; // outer radii of stations - Int_t fNsect[fgkStat]; // number of sectors per layer - //Double_t fDtubes[fgkStat][fgkPlanes]; // max. tube difference between views - std::map<Int_t,TMatrixDSym*> fMatr; // system matrices (for different hit layer patterns) - std::multimap<Int_t,CbmMuchTrack*> fSecVec[fgkStat]; // to arrange vectors according to sectors - Double_t fZabs0[9][2]; // Z-positions of absorber faces - Double_t fX0abs[9]; // radiation lengths of the absorbers - - //std::vector<pair<Int_t,Int_t> > fHit2d[fgkStat][fgkPlanes/2]; // Indx1,Indx2 of doublet hits - - void ComputeMatrix(); - void GetHits(); - Bool_t SelectHitId(const CbmMuchPixelHit *hit); - Int_t GetDowns(Int_t ista, std::vector<std::pair<Double_t,Double_t> >& vecDowns); - void MakeVectors(); - //void ProcessDouble(Int_t ista, Int_t lay2, Int_t patt, Int_t flag, Int_t tube0, Int_t segment0); - void ProcessPlane(Int_t ista, Int_t lay2, Int_t patt, Int_t flag); - void AddVector(Int_t ista, Int_t patt, Double_t chi2, Double_t *pars); - void SetTrackId(CbmMuchTrack *vec); - void FindLine(Int_t patt, Double_t *pars); - Double_t FindChi2(Int_t ista, Int_t patt, Double_t *pars); - void CheckParams(); - //void HighRes(); - //void ProcessSingleHigh(Int_t ista, Int_t plane, Int_t patt, Int_t flag, Int_t nok, Double_t uu[fgkPlanes][2]); - void RemoveClones(); - void StoreVectors(); - Int_t CountBits(Int_t x); - void Refit(Int_t patt, Double_t &chi2, Double_t *pars, TMatrixDSym &cov); - void MatchVectors(); - */ - //CbmTrdDigiPar *fDigiPar; // digi params - TClonesArray* fTrackArray; // Output array of CbmMuchVectors - Int_t fNofTracks; // Number of tracks created - TClonesArray* fHits; // Input array of CbmTrdHit - TClonesArray* fClusters; // Input array of CbmTrdCluster - TClonesArray* fDigiMatches; // Input array of - //TClonesArray* fPoints; // Input array of CbmTrdPoint - CbmMCDataArray* fPoints; // Input array of CbmTrdPoint - Double_t fXy[fgkPlanes][5]; // hit float data - Double_t fXyi[fgkPlanes][3]; // hit int data - Double_t fDz[fgkPlanes]; // geometrical constants (Z-distances from layer 0) - std::map<Int_t, TDecompLU*> fLus; // system matrices (for different hit layer patterns) - Double_t fZ0; // Z-positions of the first layers - Double_t fErrX; // hit measurement error in X - Double_t fErrY; // hit measurement error in Y - Double_t fCutChi2; // Chi2-cuts - std::map<Int_t, TMatrixDSym*> fMatr; // system matrices (for different hit layer patterns) - std::multimap<Int_t, Int_t> fHitPl[fgkPlanes]; // hit indices on planes vs tube No - std::multimap<Double_t, Int_t> fHitX[fgkPlanes]; // hit indices on planes vs X-coord. - std::vector<CbmMuchTrack*> fVectors; // track vectors for stations - - void ComputeMatrix(); // compute system matrix - void GetHits(); // get TRD hits - void MakeVectors(); // make vectors - void CheckParams(); // check vector parameters (apriory constraints) - void RemoveClones(); // remove clones - void StoreVectors(); // store vectors - void ProcessPlane(Int_t lay, Int_t patt, Int_t flag); // process next plane - void FindLine(Int_t patt, Double_t* pars); // line fit - Double_t FindChi2(Int_t patt, Double_t* pars); // fit chi2 - void AddVector(Int_t patt, Double_t chi2, - Double_t* pars); // add vector to temp. container - void SetTrackId(CbmMuchTrack* vec); // set track ID - - CbmTrdFindVectors(const CbmTrdFindVectors&); - CbmTrdFindVectors& operator=(const CbmTrdFindVectors&); - - ClassDef(CbmTrdFindVectors, 0) -}; - -#endif diff --git a/reco/tracking/vector/CbmTrdToTofVector.cxx b/reco/tracking/vector/CbmTrdToTofVector.cxx deleted file mode 100644 index 11cc7a605ca93b4c0f0fdaad12a3de944f5fa9ae..0000000000000000000000000000000000000000 --- a/reco/tracking/vector/CbmTrdToTofVector.cxx +++ /dev/null @@ -1,687 +0,0 @@ -/* Copyright (C) 2017-2019 Veksler and Baldin Laboratory of High Energy Physics, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Alexander Zinchenko [committer] */ - -/** CbmTrdToTofVector.cxx - *@author A.Zinchenko <Alexander.Zinchenko@jinr.ru> - *@since 2017 - **/ -#include "CbmTrdToTofVector.h" - -#include "CbmDefs.h" -#include "CbmMCDataArray.h" -#include "CbmMCDataManager.h" -#include "CbmMatch.h" -#include "CbmMuchTrack.h" -#include "CbmSetup.h" -#include "CbmTofAddress.h" -#include "CbmTofDigi.h" -#include "CbmTofHit.h" -#include "CbmTofPoint.h" - -#include "FairRootManager.h" - -#include <TClonesArray.h> -#include <TGeoBBox.h> -#include <TGeoManager.h> -#include <TMath.h> -#include <TMatrixDSym.h> -#include <TVectorD.h> - -#include <iostream> - -using std::cout; -using std::endl; -using std::map; -using std::multimap; -using std::pair; -using std::set; - -// ----- Default constructor ------------------------------------------- -CbmTrdToTofVector::CbmTrdToTofVector() - : FairTask("Trd2TofVec") - , fTrackArray(NULL) - , fNofTracks(0) - , fHits(NULL) - , fHitMatches(NULL) - , fPoints(NULL) - , fDigis(NULL) - , fDigiMatches(NULL) - , fTrdTracks(NULL) - , fErrX(1.0) - , fErrY(1.0) - , fCutChi2(24.0) // chi2/ndf = 6 for 4 hits -{ -} -// ------------------------------------------------------------------------- - -// ----- Destructor ---------------------------------------------------- -CbmTrdToTofVector::~CbmTrdToTofVector() {} -// ------------------------------------------------------------------------- - -// ----- Public method Init (abstract in base class) -------------------- -InitStatus CbmTrdToTofVector::Init() -{ - - // Get and check FairRootManager - FairRootManager* ioman = FairRootManager::Instance(); - if (ioman == NULL) Fatal("Init", "RootManager not instantiated!"); - - // Create and register TrdTrack array (if necessary) - //fTrackArray = static_cast<TClonesArray*> (ioman->GetObject("MuchVector")); - //if (fTrackArray == NULL) { - fTrackArray = new TClonesArray("CbmMuchTrack", 100); - ioman->Register("TofVector", "Tof", fTrackArray, kTRUE); - //} - fHits = static_cast<TClonesArray*>(ioman->GetObject("TofHit")); - fHitMatches = static_cast<TClonesArray*>(ioman->GetObject("TofDigiMatch")); - //fPoints = static_cast<TClonesArray*> (ioman->GetObject("TofPoint")); - CbmMCDataManager* mcManager = (CbmMCDataManager*) ioman->GetObject("MCDataManager"); - if (NULL == mcManager) LOG(fatal) << GetName() << ": No CbmMCDataManager!"; - fPoints = mcManager->InitBranch("TofPoint"); - fDigis = static_cast<TClonesArray*>(ioman->GetObject("TofDigi")); - fDigiMatches = static_cast<TClonesArray*>(ioman->GetObject("TofDigiMatchPoints")); - fTrdTracks = static_cast<TClonesArray*>(ioman->GetObject("TrdVector")); - - TString tag; - CbmSetup::Instance()->GetGeoTag(kTof, tag); - cout << " ******* TOF tag ******** " << tag << endl; - tag.Prepend("tof_"); - - //CbmTofGeoHandler geoHandler; - //geoHandler.Init(); - - // Get TOF location in Z - TGeoVolume* tofV = gGeoManager->GetVolume(tag); - TGeoBBox* shape = (TGeoBBox*) tofV->GetShape(); - shape->GetAxisRange(3, fZ[0], fZ[1]); - cout << " TOF span in Z: " << fZ[0] << " " << fZ[1] << endl; - - return kSUCCESS; -} -// ------------------------------------------------------------------------- - -// ----- SetParContainers ------------------------------------------------- -void CbmTrdToTofVector::SetParContainers() -{ - /* - fDigiPar = (CbmTrdDigiPar*) FairRunAna::Instance()->GetRuntimeDb()->getContainer("CbmTrdDigiPar"); - cout << " ******* digiPar ******** " << fDigiPar << endl; - exit(0); - */ -} -// ------------------------------------------------------------------------- - -// ----- Public method Exec -------------------------------------------- -void CbmTrdToTofVector::Exec(Option_t* opt) -{ - - fTrackArray->Delete(); - - // Do all processing - - // Get hits - GetHits(); - - // Build vectors (extrapolate TRD vectors thru the thickness of TOF) - MakeVectors(); - - // Remove vectors with wrong orientation - // (using empirical cuts for omega muons at 8 GeV) - //CheckParams(); - - // Match TOF hits to TRD vectors - MatchTofToTrd(); - - // Remove clones - //RemoveClones(); - - // Store vectors - StoreVectors(); -} -// ------------------------------------------------------------------------- - -// ----- Public method Finish ------------------------------------------ -void CbmTrdToTofVector::Finish() {} -// ------------------------------------------------------------------------- - -// ----- Private method GetHits ---------------------------------------- -void CbmTrdToTofVector::GetHits() -{ - // Arrange hits according to their Phi-angle - - fHitX.clear(); - fHitY.clear(); - fHitIds.clear(); - fHitTime.clear(); - - Int_t nHits = fHits->GetEntriesFast(), sel = 0; - - for (Int_t i = 0; i < nHits; ++i) { - CbmTofHit* hit = (CbmTofHit*) fHits->UncheckedAt(i); - - //!!! For debug - select hits with certain track IDs - sel = 1; //SelectHitId(hit); - if (!sel) continue; - // - fHitX.insert(pair<Double_t, Int_t>(hit->GetX(), i)); - fHitY.insert(pair<Double_t, Int_t>(hit->GetY(), i)); - CbmMatch* match = (CbmMatch*) fHitMatches->UncheckedAt(i); - Int_t nlinks = match->GetNofLinks(); - set<Int_t> ids; - fHitIds[i] = ids; - - for (Int_t il = 0; il < nlinks; ++il) { - const CbmLink link = match->GetLink(il); - CbmTofDigi* digi = (CbmTofDigi*) fDigis->UncheckedAt(link.GetIndex()); - //AZ CbmMatch *digiM = (CbmMatch*) fDigiMatches->UncheckedAt(link.GetIndex()); - CbmMatch* digiM = digi->GetMatch(); - Int_t npoints = digiM->GetNofLinks(); - - for (Int_t ip = 0; ip < npoints; ++ip) { - const CbmLink link1 = digiM->GetLink(ip); - //CbmTofPoint *point = (CbmTofPoint*) fPoints->UncheckedAt(link1.GetIndex()); - CbmTofPoint* point = (CbmTofPoint*) fPoints->Get(link1.GetFile(), link1.GetEntry(), link1.GetIndex()); - fHitIds[i].insert(point->GetTrackID()); - if (fHitTime.find(i) == fHitTime.end()) fHitTime[i] = point->GetTime(); - else - fHitTime[i] = TMath::Min(point->GetTime(), fHitTime[i]); - //cout << point->GetTrackID() << endl; - } - } - } -} -// ------------------------------------------------------------------------- - -// ----- Private method MakeVectors ------------------------------------ -void CbmTrdToTofVector::MakeVectors() -{ - // Make vectors (extrapolate TRD vectors through the TOF thickness) - - Int_t nvec = fVectors.size(); - for (Int_t j = 0; j < nvec; ++j) - delete fVectors[j]; - fVectors.clear(); - - fLineX.clear(); - - Int_t nTrd = fTrdTracks->GetEntriesFast(); - cout << " TRD tracks: " << nTrd << endl; - - for (Int_t iv = 0; iv < nTrd; ++iv) { - CbmMuchTrack* tr = (CbmMuchTrack*) fTrdTracks->UncheckedAt(iv); - const FairTrackParam& param = *tr->GetParamLast(); - TLine line; - line.SetUniqueID(iv); - - for (Int_t i = 0; i < 2; ++i) { - Double_t dz = fZ[i] - param.GetZ(); - if (i == 0) { - line.SetX1(param.GetX() + param.GetTx() * dz); - line.SetY1(param.GetY() + param.GetTy() * dz); - } - else { - line.SetX2(param.GetX() + param.GetTx() * dz); - line.SetY2(param.GetY() + param.GetTy() * dz); - } - } - fLineX.insert(pair<Double_t, TLine>(TMath::Min(line.GetX1(), line.GetX2()), line)); - } -} -// ------------------------------------------------------------------------- - -// ----- Private method MatchTofToTrd ---------------------------------- -void CbmTrdToTofVector::MatchTofToTrd() -{ - // Match TOF hits to TRD vectors - - //const Double_t window = 30.0; - const Double_t window = 50.0; - multimap<Double_t, Int_t>::iterator mitb, mite, mit1; - multimap<Double_t, pair<Int_t, Int_t>> rads; - map<pair<Int_t, Int_t>, pair<Double_t, Double_t>> dtdl; - set<Int_t> setVec, setHit; - - for (multimap<Double_t, TLine>::iterator mit = fLineX.begin(); mit != fLineX.end(); ++mit) { - Double_t rmin = 999999, dtmin = 0, dlmin = 0; - TVector3 trd(mit->second.GetX2() - mit->second.GetX1(), mit->second.GetY2() - mit->second.GetY1(), 0.0); - Double_t trdLeng = trd.Mag(); - Int_t indVec = mit->second.GetUniqueID(); - CbmMuchTrack* tr = (CbmMuchTrack*) fTrdTracks->UncheckedAt(indVec); - Int_t id = tr->GetFlag(), ihit = -1; - - // Select TOF hits for matching (apply coordinate windows) - mitb = fHitX.lower_bound(mit->first - window); - mite = fHitX.upper_bound(TMath::Max(mit->second.GetX1(), mit->second.GetX2()) + window); - set<Int_t> inds; - for (mit1 = mitb; mit1 != mite; ++mit1) - inds.insert(mit1->second); - mitb = fHitY.lower_bound(TMath::Min(mit->second.GetY1(), mit->second.GetY2()) - window); - mite = fHitY.upper_bound(TMath::Max(mit->second.GetY1(), mit->second.GetY2()) + window); - - for (mit1 = mitb; mit1 != mite; ++mit1) { - if (inds.find(mit1->second) == inds.end()) continue; // outside window - CbmTofHit* hit = (CbmTofHit*) fHits->UncheckedAt(mit1->second); - TVector3 tof(hit->GetX() - mit->second.GetX1(), hit->GetY() - mit->second.GetY1(), 0.0); - Double_t dt = TMath::Abs(trd.Cross(tof).Z()) / trdLeng; - Double_t dl = trd * tof / trdLeng; - if (dl > trdLeng) dl -= trdLeng; - else if (dl > 0) - dl = 0; - Double_t rad = dl * dl + dt * dt; - // Save matches - rads.insert(pair<Double_t, pair<Int_t, Int_t>>(rad, pair<Int_t, Int_t>(indVec, mit1->second))); - dtdl[pair<Int_t, Int_t>(indVec, mit1->second)] = pair<Double_t, Double_t>(dt, dl); - setVec.insert(indVec); - setHit.insert(mit1->second); - /* - if (rad < rmin) { - rmin = rad; - dtmin = dt; - dlmin = dl; - ihit = mit1->second; - } - */ - } - /* - if (ihit >= 0) { - Bool_t match = kFALSE; - if (fHitIds[ihit].find(id) != fHitIds[ihit].end()) match = kTRUE; - //cout << dtmin << " " << dlmin << " " << id << " " << match << endl; - CbmMuchTrack *trTof = new CbmMuchTrack(*tr); - trTof->SetPreviousTrackId(mit->second.GetUniqueID()); // index of TRD vector - FairTrackParam param; - param.SetX(dtmin); // use storage - param.SetY(dlmin); - trTof->SetParamLast(¶m); - trTof->SetFlag(match); - trTof->SetUniqueID(id); - fVectors.push_back(trTof); - } - */ - } // for (multimap<Double_t,TLine>::iterator mit = fLineX.begin(); - - // Create vectors - for (multimap<Double_t, pair<Int_t, Int_t>>::iterator rmit = rads.begin(); rmit != rads.end(); ++rmit) { - Int_t indVec = rmit->second.first, ihit = rmit->second.second; - if (setVec.find(indVec) == setVec.end()) continue; // already matched vector - if (setHit.find(ihit) == setHit.end()) continue; // already matched hit - - Bool_t match = kFALSE; - CbmMuchTrack* tr = (CbmMuchTrack*) fTrdTracks->UncheckedAt(indVec); - Int_t id = tr->GetFlag(); - if (fHitIds[ihit].find(id) != fHitIds[ihit].end()) match = kTRUE; - //cout << dtmin << " " << dlmin << " " << id << " " << match << endl; - CbmMuchTrack* trTof = new CbmMuchTrack(*tr); - trTof->SetPreviousTrackId(indVec); // index of TRD vector - FairTrackParam param; - param.SetX(dtdl[rmit->second].first); // use storage - param.SetY(dtdl[rmit->second].second); - param.SetZ(rmit->first); - trTof->SetParamLast(¶m); - trTof->SetFlag(match); - trTof->SetUniqueID(id); - trTof->SetNDF(ihit); // TOF hit index - use storage - trTof->SetChiSq(fHitTime[ihit]); // min. time - use storage - fVectors.push_back(trTof); - - setVec.erase(indVec); - if (setVec.size() == 0) break; - setHit.erase(ihit); - if (setHit.size() == 0) break; - } -} -// ------------------------------------------------------------------------- - -// ----- Private method CheckParams ------------------------------------ -void CbmTrdToTofVector::CheckParams() -{ - // Remove vectors with wrong orientation - // using empirical cuts for omega muons at 8 Gev - - const Double_t cut[2] = {0.6, 0.6}; // !!! empirical !!! - - Int_t nvec = fVectors.size(); - - for (Int_t iv = 0; iv < nvec; ++iv) { - CbmMuchTrack* vec = fVectors[iv]; - const FairTrackParam* params = vec->GetParamFirst(); - Double_t dTx = params->GetTx() - params->GetX() / params->GetZ(); - if (TMath::Abs(dTx) > cut[0]) vec->SetChiSq(-1.0); - else { - Double_t dTy = params->GetTy() - params->GetY() / params->GetZ(); - if (TMath::Abs(dTy) > cut[1]) vec->SetChiSq(-1.0); - } - } - - for (Int_t iv = nvec - 1; iv >= 0; --iv) { - CbmMuchTrack* vec = fVectors[iv]; - if (vec->GetChiSq() < 0) { - delete fVectors[iv]; - fVectors.erase(fVectors.begin() + iv); - } - } - cout << " Vectors after parameter check: " << nvec << " " << fVectors.size() << endl; -} -// ------------------------------------------------------------------------- - -// ----- Private method RemoveClones ----------------------------------- -void CbmTrdToTofVector::RemoveClones() -{ - // Remove clone vectors (having at least 3 the same hits) - - //Int_t nthr = 3, planes[20]; - Int_t nthr = 2, planes[20]; - - Int_t nvec = fVectors.size(); - - // Do sorting according to "quality" - multimap<Double_t, CbmMuchTrack*> qMap; - multimap<Double_t, CbmMuchTrack*>::iterator it, it1; - - for (Int_t i = 0; i < nvec; ++i) { - CbmMuchTrack* vec = fVectors[i]; - Double_t qual = vec->GetNofHits() + (99 - TMath::Min(vec->GetChiSq(), 99.0)) / 100; - qMap.insert(pair<Double_t, CbmMuchTrack*>(-qual, vec)); - } - - for (it = qMap.begin(); it != qMap.end(); ++it) { - CbmMuchTrack* vec = it->second; - if (vec->GetChiSq() < 0) continue; - for (Int_t j = 0; j < fgkPlanes; ++j) - planes[j] = -1; - - Int_t nhits = vec->GetNofHits(); - for (Int_t ih = 0; ih < nhits; ++ih) { - CbmTofHit* hit = (CbmTofHit*) fHits->UncheckedAt(vec->GetHitIndex(ih)); - Int_t lay = hit->GetPlaneId(); - planes[lay] = vec->GetHitIndex(ih); - } - - it1 = it; - for (++it1; it1 != qMap.end(); ++it1) { - CbmMuchTrack* vec1 = it1->second; - if (vec1->GetChiSq() < 0) continue; - Int_t nsame = 0, same[fgkPlanes] = {0}; - - Int_t nhits1 = vec1->GetNofHits(); - //nthr = TMath::Min(nhits,nhits1) / 2; - //nthr = TMath::Min(nhits,nhits1) * 0.75; - for (Int_t ih = 0; ih < nhits1; ++ih) { - CbmTofHit* hit = (CbmTofHit*) fHits->UncheckedAt(vec1->GetHitIndex(ih)); - Int_t lay = hit->GetPlaneId(); - if (planes[lay] >= 0) { - if (vec1->GetHitIndex(ih) == planes[lay]) same[lay] = 1; - //else same[lay] = 0; - } - } - for (Int_t lay = 0; lay < fgkPlanes; ++lay) - nsame += same[lay]; - - if (nsame >= nthr) { - // Too many the same hits - Int_t clone = 0; - if (nhits > nhits1 + 0) clone = 1; - else if (vec->GetChiSq() * 1 <= vec1->GetChiSq()) - clone = 1; // the same number of hits on 2 tracks - //else if (vec->GetChiSq() * 1.5 <= vec1->GetChiSq()) clone = 1; // the same number of hits on 2 tracks - if (clone) vec1->SetChiSq(-1.0); - } - } - } // for (it = qMap.begin(); - - for (Int_t iv = nvec - 1; iv >= 0; --iv) { - CbmMuchTrack* vec = fVectors[iv]; - if (vec->GetChiSq() < 0) { - delete fVectors[iv]; - fVectors.erase(fVectors.begin() + iv); - } - } - cout << " CbmTrdToTofVector:: Vectors after clones removed: " << nvec << " " << fVectors.size() << endl; -} -// ------------------------------------------------------------------------- - -// ----- Private method StoreVectors ----------------------------------- -void CbmTrdToTofVector::StoreVectors() -{ - // Store vectors (CbmMuchTracks) into TClonesArray - - Int_t ntrs = fTrackArray->GetEntriesFast(); - Int_t nHitsTot = fHits->GetEntriesFast(); - - //set<Int_t> usedHits; - Int_t nvec = fVectors.size(); - - for (Int_t iv = 0; iv < nvec; ++iv) { - CbmMuchTrack* tr = new ((*fTrackArray)[ntrs++]) CbmMuchTrack(*(fVectors[iv])); - //cout << " Track: " << tr->GetNofHits() << endl; - //for (Int_t j = 0; j < tr->GetNofHits(); ++j) cout << j << " " << tr->GetHitIndex(j) << " " << fVectors[ist][iv]->GetHitIndex(j) << endl; - // Set hit flag (to check Lit tracking) - //Int_t nhits = tr->GetNofHits(); - - // Save IDs of contributing points to the hit - CbmMatch* match = new CbmMatch; - Int_t ihit = fVectors[iv]->GetNDF(); - for (set<Int_t>::iterator sit = fHitIds[ihit].begin(); sit != fHitIds[ihit].end(); ++sit) - match->AddLink(1.0, *sit); - tr->SetMatch(match); - } -} -// ------------------------------------------------------------------------- - -// ----- Private method ProcessPlane ----------------------------------- -void CbmTrdToTofVector::ProcessPlane(Int_t lay, Int_t patt, Int_t flag0) -{ - // Main processing engine (recursively adds layer hits to the vector) - - //const Double_t cut[2] = {0.8, 0.8}; // !!! empirical !!! - const Double_t cut[2] = {0.6, 0.6}; // !!! empirical !!! - - Double_t pars[4] = {0.0}; - Int_t flag = 0; - multimap<Int_t, Int_t>::iterator mit; - // Clear bits - patt &= ~(1 << lay); - /* - for (mit = fHitPl[lay].begin(); mit != fHitPl[lay].end(); ++mit) { - Int_t indx = mit->second; - - CbmTofHit *hit = (CbmTofHit*) fHits->UncheckedAt(indx); - fXy[lay][0] = hit->GetX(); - fXy[lay][1] = hit->GetY(); - fXy[lay][2] = hit->GetDx(); - fXy[lay][3] = hit->GetDy(); - //fXy[lay][2] = TMath::Max (hit->GetDx(),fErrX[ista]); - //fXy[lay][3] = TMath::Max (hit->GetDy(),fErrY[ista]); - fXy[lay][4] = hit->GetZ(); - // Clear bits - patt &= ~(1 << lay); - - // Check slopes - Int_t lay0 = 0; - if (!(patt & (1 << lay0))) ++lay0;; - Double_t dx = fXy[lay][0] - fXy[lay0][0]; - Double_t dz = fXy[lay][4] - fXy[lay0][4]; - Double_t dTx = TMath::Abs(dx/dz) - TMath::Abs(fXy[lay][0]/fXy[lay][4]); - if (TMath::Abs(dTx) > cut[0]) continue; - Double_t dy = fXy[lay][1] - fXy[lay0][1]; - Double_t dTy = TMath::Abs(dy/dz) - TMath::Abs(fXy[lay][1]/fXy[lay][4]); - if (TMath::Abs(dTy) > cut[1]) continue; - - fXyi[lay][1] = indx; - flag = 1; - - // Set bit - patt |= (1 << lay); - //cout << lay << " " << patt << " " << hit->GetX() << " " << hit->GetY() << " " << hit->GetZ() << " " << endl; - - if (lay < fgkPlanes - 1) ProcessPlane(lay+1, patt, flag); - else if (TString::Itoa(patt,2).CountChar('1') > 2) { - // Straight line fit of the vector with > 2 hits - FindLine(patt, pars); - Double_t chi2 = FindChi2(patt, pars); - cout << " *** Stat: " << chi2 << " " << pars[0] << " " << pars[1] << endl; - if (chi2 <= fCutChi2) AddVector(patt, chi2, pars); // add vector to the temporary container - } - } // for (mit = fHitPl[lay].begin(); - - //if (flag == 0) { - if (flag >= 0) { - // Missing plane - if (flag0 == 0) return; // 2 consecutive missing planes - // Clear bits - patt &= ~(1 << lay); - if (lay < fgkPlanes - 1) ProcessPlane(lay+1, patt, flag); - else if (TString::Itoa(patt,2).CountChar('1') > 2) { - // Straight line fit of the vector with > 2 hits - FindLine(patt, pars); - Double_t chi2 = FindChi2(patt, pars); - cout << " *** Stat: " << chi2 << " " << pars[0] << " " << pars[1] << endl; - if (chi2 <= fCutChi2) AddVector(patt, chi2, pars); // add vector to the temporary container - } - } - */ -} -// ------------------------------------------------------------------------- - -// ----- Private method FindLine --------------------------------------- -void CbmTrdToTofVector::FindLine(Int_t patt, Double_t* pars) -{ - // Fit of hits to the straight line - - // Solve system of linear equations - Bool_t ok = kFALSE, onoff; - TVectorD b(4); - /* - for (Int_t i = 0; i < fgkPlanes; ++i) { - onoff = patt & (1 << i); - if (!onoff) continue; - b[0] += fXy[i][0]; - b[1] += fXy[i][1]; - b[2] += fXy[i][0] * fDz[i]; - b[3] += fXy[i][1] * fDz[i]; - } - - //lu.Print(); - TVectorD solve = fLus[patt]->Solve(b, ok); - //TVectorD solve = lu.TransSolve(b, ok); - //lu.Print(); - for (Int_t i = 0; i < 4; ++i) pars[i] = solve[i]; - //for (Int_t i = 0; i < 4; ++i) { cout << pars[i] << " "; if (i == 3) cout << endl; } - //Double_t y1 = cosa / sina * (uz[1][0] * cosa - uz[0][0]) + uz[1][0] * sina; - //Double_t y2 = -cosa / sina * (uz[2][0] * cosa - uz[0][0]) - uz[2][0] * sina; - //cout << " OK " << ok << " " << y1 << " " << y2 << endl; - */ -} -// ------------------------------------------------------------------------- - -// ----- Private method FindChi2 --------------------------------------- -Double_t CbmTrdToTofVector::FindChi2(Int_t patt, Double_t* pars) -{ - // Compute chi2 of the fit - - Double_t chi2 = 0, x = 0, y = 0; - Bool_t onoff; - /* - for (Int_t i = 0; i < fgkPlanes; ++i) { - onoff = patt & (1 << i); - if (!onoff) continue; - x = pars[0] + pars[2] * fDz[i]; - y = pars[1] + pars[3] * fDz[i]; - //Double_t dx = (x - fXy[i][0]) / fErrX; - //Double_t dy = (y - fXy[i][1]) / fErrY; - Double_t dx = (x - fXy[i][0]) / TMath::Max(fXy[i][2],fErrX); - Double_t dy = (y - fXy[i][1]) / TMath::Max(fXy[i][3],fErrY); - chi2 += dx * dx; - chi2 += dy * dy; - } - */ - return chi2; -} -// ------------------------------------------------------------------------- - -// ----- Private method AddVector -------------------------------------- -void CbmTrdToTofVector::AddVector(Int_t patt, Double_t chi2, Double_t* pars) -{ - // Add vector to the temporary container (as a MuchTrack) - - Bool_t refit = kFALSE; //kTRUE; - TMatrixDSym cov(4); - /* - if (refit) { - // Refit line with individual hit errors - //cout << " Before: " << chi2 << endl; - //Refit(patt, chi2, pars, cov); - //cout << " After: " << chi2 << endl; - } else { - cov = *fMatr[patt]; - cov *= (fErrX * fErrX); // the same error in X and Y - } - cov.ResizeTo(5,5); - cov(4,4) = 1.0; - - CbmMuchTrack *track = new CbmMuchTrack(); - track->SetChiSq(chi2); - FairTrackParam par(pars[0], pars[1], fZ0, pars[2], pars[3], 0.0, cov); - track->SetParamFirst(&par); - par.SetZ(fZ0 + fDz[fgkPlanes-1]); - par.SetX(pars[0] + fDz[fgkPlanes-1] * pars[2]); - par.SetY(pars[1] + fDz[fgkPlanes-1] * pars[3]); - track->SetParamLast(&par); - //track->SetUniqueID(ista); // just to pass the value - - for (Int_t ipl = 0; ipl < fgkPlanes; ++ipl) { - if (!(patt & (1 << ipl))) continue; - track->AddHit(fXyi[ipl][1], kTRDHIT); - } - Int_t ndf = (track->GetNofHits() > 2) ? track->GetNofHits() * 2 - 4 : 1; - track->SetNDF(ndf); - SetTrackId(track); // set track ID as its flag - fVectors.push_back(track); - */ -} -// ------------------------------------------------------------------------- - -// ----- Private method SetTrackId ------------------------------------- -void CbmTrdToTofVector::SetTrackId(CbmMuchTrack* vec) -{ - // Set vector ID as its flag (maximum track ID of its poins) - - map<Int_t, Int_t> ids; - Int_t nhits = vec->GetNofHits(), id = 0; - - /* - for (Int_t ih = 0; ih < nhits; ++ih) { - CbmTofHit *hit = (CbmTofHit*) fHits->UncheckedAt(vec->GetHitIndex(ih)); - CbmTrdCluster *clus = (CbmTrdCluster*) fClusters->UncheckedAt(hit->GetRefId()); - Int_t nDigis = clus->GetNofDigis(); - - for (Int_t j = 0; j < nDigis; ++j) { - CbmMatch* digiM = (CbmMatch*) fDigiMatches->UncheckedAt(clus->GetDigi(j)); - Int_t np = digiM->GetNofLinks(); - - for (Int_t ip = 0; ip < np; ++ip) { - //CbmMuchPoint* point = (CbmMuchPoint*) fPoints->UncheckedAt(digiM->GetLink(0).GetIndex()); - CbmTrdPoint* point = (CbmTrdPoint*) fPoints->UncheckedAt(digiM->GetLink(ip).GetIndex()); - id = point->GetTrackID(); - //if (np > 1) cout << ip << " " << id << endl; - if (ids.find(id) == ids.end()) ids.insert(pair<Int_t,Int_t>(id,1)); - else ++ids[id]; - } - //if (np > 1) { cout << " digi " << digiM->GetNofLinks() << " " << ista << " " << hit->GetX() << " " << hit->GetY() << endl; exit(0); } - } - } - Int_t maxim = -1, idmax = -9; - for (map<Int_t,Int_t>::iterator it = ids.begin(); it != ids.end(); ++it) { - if (it->second > maxim) { - maxim = it->second; - idmax = it->first; - } - } - // Set vector ID as its flag - vec->SetFlag(idmax); - */ -} -// ------------------------------------------------------------------------- - -ClassImp(CbmTrdToTofVector); diff --git a/reco/tracking/vector/CbmTrdToTofVector.h b/reco/tracking/vector/CbmTrdToTofVector.h deleted file mode 100644 index 942e64c995fc75eaa231b0708a2f9340d2409b72..0000000000000000000000000000000000000000 --- a/reco/tracking/vector/CbmTrdToTofVector.h +++ /dev/null @@ -1,98 +0,0 @@ -/* Copyright (C) 2017-2018 Veksler and Baldin Laboratory of High Energy Physics, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Alexander Zinchenko [committer] */ - -/** CbmTrdToTofVector.h - *@author A.Zinchenko <Alexander.Zinchenko@jinr.ru> - *@since 2017 - ** - ** Task class for vector matchin between CBM TRD and TOF. - ** Input: - ** Output: - ** - **/ - -#ifndef CBMTRDTOTOFVECTOR_H_ -#define CBMTRDTOTOFVECTOR_H_ 1 - -#include "FairTask.h" - -#include <TLine.h> - -#include <map> -#include <set> -#include <vector> - -class CbmMuchTrack; -class CbmMCDataArray; - -class CbmTrdToTofVector : public FairTask { -public: - /** Default constructor **/ - CbmTrdToTofVector(); - - /** Destructor **/ - virtual ~CbmTrdToTofVector(); - - /** Initialisation **/ - virtual InitStatus Init(); - - /** Task execution **/ - virtual void Exec(Option_t* opt); - - /** Finish at the end **/ - virtual void Finish(); - - /** SetParContainers **/ - virtual void SetParContainers(); - - /** Accessors **/ - Int_t GetNofTracks() { return fNofTracks; }; - -private: - // Some constants - static const Int_t fgkPlanes = 4; // Number of TRD layers - -private: - TClonesArray* fTrackArray; // Output array of CbmMuchTracks - Int_t fNofTracks; // Number of tracks created - TClonesArray* fHits; // Input array of CbmTofHit - TClonesArray* fHitMatches; // Input array of CbmMatch - //TClonesArray* fPoints; // Input array of CbmTofPoint - CbmMCDataArray* fPoints; // Input array of CbmTofPoint - TClonesArray* fDigis; // Input array of CbmDigi - TClonesArray* fDigiMatches; // Input array of CbmMatch - TClonesArray* fTrdTracks; // Input array of - Double_t fZ[2]; // TOF location in Z - Double_t fErrX; // hit measurement error in X - Double_t fErrY; // hit measurement error in Y - Double_t fCutChi2; // Chi2-cuts - std::multimap<Double_t, Int_t> fHitX; // hit index vs X - std::multimap<Double_t, Int_t> fHitY; // hit index vs Y - std::map<Int_t, Double_t> fHitTime; // hit time (min. of all contributing points) - std::map<Int_t, std::set<Int_t>> fHitIds; // hit index - to - contributing track IDs - std::vector<CbmMuchTrack*> fVectors; // track vectors for stations - std::multimap<Double_t, TLine> fLineX; // projected TRD vectors vs min X - Double_t fXy[fgkPlanes][5]; // hit float data - Double_t fXyi[fgkPlanes][3]; // hit int data - - void GetHits(); // get TRD hits - void MakeVectors(); // make vectors - void MatchTofToTrd(); // match TOF hits to TRD vectors - void CheckParams(); // check vector parameters (apriory constraints) - void RemoveClones(); // remove clones - void StoreVectors(); // store vectors - void ProcessPlane(Int_t lay, Int_t patt, Int_t flag); // process next plane - void FindLine(Int_t patt, Double_t* pars); // line fit - Double_t FindChi2(Int_t patt, Double_t* pars); // fit chi2 - void AddVector(Int_t patt, Double_t chi2, - Double_t* pars); // add vector to temp. container - void SetTrackId(CbmMuchTrack* vec); // set track ID - - CbmTrdToTofVector(const CbmTrdToTofVector&); - CbmTrdToTofVector& operator=(const CbmTrdToTofVector&); - - ClassDef(CbmTrdToTofVector, 0) -}; - -#endif diff --git a/reco/tracking/vector/CbmVectorFinder.cxx b/reco/tracking/vector/CbmVectorFinder.cxx deleted file mode 100644 index 3b7afe0007ab0235ee8b0915d4c98dda9440131a..0000000000000000000000000000000000000000 --- a/reco/tracking/vector/CbmVectorFinder.cxx +++ /dev/null @@ -1,84 +0,0 @@ -/* Copyright (C) 2017-2018 Veksler and Baldin Laboratory of High Energy Physics, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Alexander Zinchenko [committer] */ - -/** CbmVectorFinder.cxx - *@author A.Zinchenko <Alexander.Zinchenko@jinr.ru> - *@since 2017 - **/ -#include "CbmVectorFinder.h" - -#include "CbmDefs.h" -#include "CbmMuchFindVectors.h" -#include "CbmMuchFindVectorsGem.h" -#include "CbmMuchMergeVectors.h" -#include "CbmMuchToTrdVectors.h" -#include "CbmSetup.h" -#include "CbmTrdFindVectors.h" -#include "CbmTrdToTofVector.h" -//#include "CbmMuchToTofVectors.h" - -#include <iostream> - -using std::cout; -using std::endl; -//using std::map; - -// ----- Default constructor ------------------------------------------- -CbmVectorFinder::CbmVectorFinder() : FairTask("VectorFinder") {} -// ------------------------------------------------------------------------- - -// ----- Destructor ---------------------------------------------------- -CbmVectorFinder::~CbmVectorFinder() {} -// ------------------------------------------------------------------------- - -// ----- Public method Init (abstract in base class) -------------------- -InitStatus CbmVectorFinder::Init() -{ - //cout << " !!!!!!!!! AZ " << CbmSetup::Instance()->IsActive(kTrd) << endl; - //cout << " !!!!!!!!! AZ " << CbmSetup::Instance()->IsActive(kRich) << endl; - if (CbmSetup::Instance()->IsActive(kTrd)) { - FairTask* trdVecf = new CbmTrdFindVectors(); - Add(trdVecf); - if (CbmSetup::Instance()->IsActive(kTof)) { - FairTask* trd2tof = new CbmTrdToTofVector(); - Add(trd2tof); - } - } - - if (CbmSetup::Instance()->IsActive(kMuch)) { - FairTask* muchVecf = new CbmMuchFindVectors(); - Add(muchVecf); - FairTask* muchVecGem = new CbmMuchFindVectorsGem(); - Add(muchVecGem); - FairTask* muchMerge = new CbmMuchMergeVectors(); - Add(muchMerge); - if (CbmSetup::Instance()->IsActive(kTrd)) { - // MUCH-to-TRD merging - FairTask* muchTrd = new CbmMuchToTrdVectors(); - Add(muchTrd); - } - /* - if (CbmSetup::Instance()->IsActive(kTof)) { - // MUCH-to-TOF merging - FairTask *muchTof = new CbmMuchToTofVectors(); - Add(muchTof); - } - */ - } -} -// ------------------------------------------------------------------------- - -// ----- SetParContainers ------------------------------------------------- -void CbmVectorFinder::SetParContainers() {} -// ------------------------------------------------------------------------- - -// ----- Public method Exec -------------------------------------------- -void CbmVectorFinder::Exec(Option_t* opt) {} -// ------------------------------------------------------------------------- - -// ----- Public method Finish ------------------------------------------ -void CbmVectorFinder::Finish() {} -// ------------------------------------------------------------------------- - -ClassImp(CbmVectorFinder); diff --git a/reco/tracking/vector/CbmVectorFinder.h b/reco/tracking/vector/CbmVectorFinder.h deleted file mode 100644 index 52ad3ffa63c63151298e28ec28840ea23794b1fe..0000000000000000000000000000000000000000 --- a/reco/tracking/vector/CbmVectorFinder.h +++ /dev/null @@ -1,119 +0,0 @@ -/* Copyright (C) 2017-2018 Veksler and Baldin Laboratory of High Energy Physics, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Alexander Zinchenko [committer] */ - -/** CbmVectorFinder.h - *@author A.Zinchenko <Alexander.Zinchenko@jinr.ru> - *@since 2017 - ** - ** Steering task class for vector finding in CBM. - ** Input: - ** Output: - ** - **/ - -#ifndef CBMVECTORFINDER_H_ -#define CBMVECTORFINDER_H_ 1 - -//#include "CbmMuchGeoScheme.h" -#include "FairTask.h" -//#include "FairTrackParam.h" -//#include <TDecompLU.h> -//#include <map> -//#include <set> -//#include <vector> - -//class CbmMuchPixelHit; -//class CbmMuchTrack; -//class TClonesArray; - -class CbmVectorFinder : public FairTask { -public: - /** Default constructor **/ - CbmVectorFinder(); - - /** Destructor **/ - virtual ~CbmVectorFinder(); - - /** Initialisation **/ - virtual InitStatus Init(); - - /** Task execution **/ - virtual void Exec(Option_t* opt); - - /** Finish at the end **/ - virtual void Finish(); - - /** SetParContainers **/ - virtual void SetParContainers(); - - /** Accessors **/ - //Int_t GetNofTracks() { return fNofTracks; }; - //Int_t GetNofStat() const { return fgkStat; } - -private: - // Some constants - //static const Int_t fgkStat = 4; // Number of stations - 4 GEMs - //static const Int_t fgkPlanes = 6; // Number of GEM planes per station - -private: - /* - CbmMuchGeoScheme* fGeoScheme; // Geometry scheme - TClonesArray* fTrackArray; // Output array of CbmMuchVectors - Int_t fNofTracks; // Number of tracks created - TClonesArray* fHits; // Input array of CbmMuchHit - TClonesArray* fClusters; // Input array of CbmMuchCluster - TClonesArray* fPoints; // Input array of CbmMuchHit - TClonesArray* fDigiMatches; // Input array of CbmMuchHit - Int_t fStatFirst; // First straw station No. - std::multimap<Int_t,Int_t> fHitPl[fgkStat][fgkPlanes]; // hit indices on planes vs tube No - std::multimap<Double_t,Int_t> fHitX[fgkStat][fgkPlanes]; // hit indices on planes vs X-coord. - std::vector<CbmMuchTrack*> fVectors[fgkStat]; // track vectors for stations - //std::vector<CbmMuchTrack*> fVectorsHigh[fgkStat]; // track vectors for stations (high resolution) - Double_t fXy[fgkPlanes][5]; // hit float data - Double_t fXyi[fgkPlanes][3]; // hit int data - Double_t fDz[fgkPlanes]; // geometrical constants (Z-distances from layer 0) - std::map<Int_t,TDecompLU*> fLus; // system matrices (for different hit layer patterns) - Double_t fErrX[9]; // hit measurement error in X - Double_t fErrY[9]; // hit measurement error in Y - Double_t fCutChi2[9]; // Chi2-cuts for each station - Double_t fZ0[fgkStat]; // Z-positions of the first layers - Double_t fRmin[fgkStat]; // inner radii of stations - Double_t fRmax[fgkStat]; // outer radii of stations - Int_t fNsect[fgkStat]; // number of sectors per layer - //Double_t fDtubes[fgkStat][fgkPlanes]; // max. tube difference between views - std::map<Int_t,TMatrixDSym*> fMatr; // system matrices (for different hit layer patterns) - std::multimap<Int_t,CbmMuchTrack*> fSecVec[fgkStat]; // to arrange vectors according to sectors - Double_t fZabs0[9][2]; // Z-positions of absorber faces - Double_t fX0abs[9]; // radiation lengths of the absorbers - - //std::vector<pair<Int_t,Int_t> > fHit2d[fgkStat][fgkPlanes/2]; // Indx1,Indx2 of doublet hits - - void ComputeMatrix(); - void GetHits(); - Bool_t SelectHitId(const CbmMuchPixelHit *hit); - Int_t GetDowns(Int_t ista, std::vector<std::pair<Double_t,Double_t> >& vecDowns); - void MakeVectors(); - //void ProcessDouble(Int_t ista, Int_t lay2, Int_t patt, Int_t flag, Int_t tube0, Int_t segment0); - void ProcessPlane(Int_t ista, Int_t lay2, Int_t patt, Int_t flag); - void AddVector(Int_t ista, Int_t patt, Double_t chi2, Double_t *pars); - void SetTrackId(CbmMuchTrack *vec); - void FindLine(Int_t patt, Double_t *pars); - Double_t FindChi2(Int_t ista, Int_t patt, Double_t *pars); - void CheckParams(); - //void HighRes(); - //void ProcessSingleHigh(Int_t ista, Int_t plane, Int_t patt, Int_t flag, Int_t nok, Double_t uu[fgkPlanes][2]); - void RemoveClones(); - void StoreVectors(); - Int_t CountBits(Int_t x); - void Refit(Int_t patt, Double_t &chi2, Double_t *pars, TMatrixDSym &cov); - void MatchVectors(); - */ - - CbmVectorFinder(const CbmVectorFinder&); - CbmVectorFinder& operator=(const CbmVectorFinder&); - - ClassDef(CbmVectorFinder, 0) -}; - -#endif diff --git a/reco/tracking/vector/CbmVectorLinkDef.h b/reco/tracking/vector/CbmVectorLinkDef.h deleted file mode 100644 index 537e63f3e3af34e1e9a7d9a04a7ec5bbf4dce73f..0000000000000000000000000000000000000000 --- a/reco/tracking/vector/CbmVectorLinkDef.h +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright (C) 2018 Veksler and Baldin Laboratory of High Energy Physics, Joint Institute for Nuclear Research, Dubna - SPDX-License-Identifier: GPL-3.0-only - Authors: Alexander Zinchenko [committer] */ - -#ifdef __CINT__ - -#pragma link off all globals; -#pragma link off all classes; -#pragma link off all functions; - -#pragma link C++ class CbmVectorFinder + ; -#pragma link C++ class CbmTrdFindVectors + ; -#pragma link C++ class CbmTrdToTofVector + ; -#pragma link C++ class CbmMuchFindVectors + ; -#pragma link C++ class CbmMuchFindVectorsGem + ; -//#pragma link C++ class CbmMuchFindVectorsQa+; -#pragma link C++ class CbmMuchMergeVectors + ; -//#pragma link C++ class CbmMuchMergeVectorsQa+; -#pragma link C++ class CbmMuchToTrdVectors + ; -#pragma link C++ class CbmMuchToTofVectors + ; - -#endif