CbmRoot
Loading...
Searching...
No Matches
CbmRichUtil.cxx
Go to the documentation of this file.
1/* Copyright (C) 2021 Justus-Liebig-Universitaet Giessen, Giessen
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Semen Lebedev [committer]*/
4
5#include "CbmRichUtil.h"
6
7#include "CbmDigiManager.h"
8#include "CbmGlobalTrack.h"
9#include "CbmLink.h"
10#include "CbmMCDataArray.h"
11#include "CbmMatchRecoToMC.h"
12#include "CbmRichDetectorData.h"
13#include "CbmRichDigi.h"
15#include "CbmRichGeoManager.h"
16#include "CbmRichHit.h"
17#include "CbmRichRing.h"
18#include "TClonesArray.h"
19
20#include <FairRootManager.h>
21
22using namespace std;
23
24double CbmRichUtil::GetRingTrackDistance(Int_t globalTrackId) { return GetRingTrackDistanceImpl(globalTrackId)[0]; }
25
26double CbmRichUtil::GetRingTrackDistanceX(Int_t globalTrackId) { return GetRingTrackDistanceImpl(globalTrackId)[1]; }
27
28double CbmRichUtil::GetRingTrackDistanceY(Int_t globalTrackId) { return GetRingTrackDistanceImpl(globalTrackId)[2]; }
29
30vector<Double_t> CbmRichUtil::GetRingTrackDistanceImpl(Int_t globalTrackId)
31{
32 vector<Double_t> errorVec = {999., 999., 999.};
33 FairRootManager* ioman = FairRootManager::Instance();
34 if (ioman == NULL) return errorVec;
35 // Do we really need static here, depends on ioman->GetObject() method
36 static TClonesArray* globalTracks = NULL;
37 static TClonesArray* richRings = NULL;
38 static TClonesArray* richProjections = NULL;
39
40 if (globalTracks == NULL || richRings == NULL || richProjections == NULL) {
41 //cout << "globalTracks == NULL || richRings == NULL || richProjections == NULL" << endl;
42 globalTracks = (TClonesArray*) ioman->GetObject("GlobalTrack");
43 richRings = (TClonesArray*) ioman->GetObject("RichRing");
44 richProjections = (TClonesArray*) ioman->GetObject("RichProjection");
45 }
46 else {
47 //cout << "globalTracks, richRings, richProjections NOT NULL" << endl;
48 }
49
50 if (globalTracks == NULL || richRings == NULL || richProjections == NULL) {
51 LOG(error) << "CbmRichUtil::GetRingTrackDistance globalTracks, "
52 "richRings, richProjections NOT INITIALIZED"
53 << endl;
54 return errorVec;
55 }
56
57 const CbmGlobalTrack* globalTrack = static_cast<const CbmGlobalTrack*>(globalTracks->At(globalTrackId));
58 if (globalTrack == NULL) return errorVec;
59
60 Int_t stsId = globalTrack->GetStsTrackIndex();
61 if (stsId < 0) return errorVec;
62
63 const FairTrackParam* pTrack = static_cast<const FairTrackParam*>(richProjections->At(stsId));
64 if (pTrack == NULL) return errorVec;
65
66 if (pTrack->GetX() == 0 && pTrack->GetY() == 0) return errorVec;
67
68 Int_t richId = globalTrack->GetRichRingIndex();
69 if (richId < 0) return errorVec;
70
71 const CbmRichRing* richRing = static_cast<const CbmRichRing*>(richRings->At(richId));
72 if (richRing == NULL) return errorVec;
73
74 // Double_t xRing = richRing->GetCenterX();
75 // Double_t yRing = richRing->GetCenterY();
76 Double_t dx = richRing->GetCenterX() - pTrack->GetX();
77 Double_t dy = richRing->GetCenterY() - pTrack->GetY();
78
79 Double_t dist = TMath::Sqrt(dx * dx + dy * dy);
80
81 vector<Double_t> v = {dist, dx, dy};
82 return v;
83}
84
85vector<double> CbmRichUtil::GetPmtHistXbins() { return GetPmtHistBins(true); }
86
87vector<double> CbmRichUtil::GetPmtHistYbins() { return GetPmtHistBins(false); }
88
89vector<double> CbmRichUtil::GetPmtHistBins(bool isX)
90{
91 vector<double> initVec;
92 vector<int> pmts = CbmRichDigiMapManager::GetInstance().GetPmtIds();
93 for (int pmtId : pmts) {
95 TVector3 inPos(pmtData->fX, pmtData->fY, pmtData->fZ);
96 TVector3 outPos;
98 if (isX) {
99 initVec.push_back(outPos.X() - 0.5 * pmtData->fWidth);
100 initVec.push_back(outPos.X() + 0.5 * pmtData->fWidth);
101 }
102 else {
103 initVec.push_back(outPos.Y() - 0.5 * pmtData->fHeight);
104 initVec.push_back(outPos.Y() + 0.5 * pmtData->fHeight);
105 }
106 }
107 sort(initVec.begin(), initVec.end());
108
109 vector<double> uniVec;
110 for (size_t i = 0; i < initVec.size(); i++) {
111 if (i == 0) uniVec.push_back(initVec[i]);
112 if (initVec[i] - uniVec[uniVec.size() - 1] > 0.000001) uniVec.push_back(initVec[i]);
113 }
114 return uniVec;
115}
FairTask for matching RECO data to MC.
fscal v[fmask::Size]
Definition KfSimdPseudo.h:4
int32_t GetStsTrackIndex() const
int32_t GetRichRingIndex() const
static CbmRichDigiMapManager & GetInstance()
Return Instance of CbmRichGeoManager.
std::vector< Int_t > GetPmtIds()
Return ids for all pmts.
CbmRichPmtData * GetPmtDataById(Int_t id)
Return CbmRichDataPmt by id.
void RotatePoint(TVector3 *inPos, TVector3 *outPos, Bool_t noTilting=false)
static CbmRichGeoManager & GetInstance()
float GetCenterX() const
Definition CbmRichRing.h:77
float GetCenterY() const
Definition CbmRichRing.h:78
static std::vector< double > GetPmtHistBins(bool isX)
static std::vector< double > GetPmtHistYbins()
static std::vector< double > GetRingTrackDistanceImpl(int globalTrackId)
Return a vector with total distance and x, y components. [0] - total distance, [1] - x component,...
static double GetRingTrackDistanceY(int globalTrackId)
static double GetRingTrackDistance(int globalTrackId)
static std::vector< double > GetPmtHistXbins()
static double GetRingTrackDistanceX(int globalTrackId)
Hash for CbmL1LinkKey.