CbmRoot
Loading...
Searching...
No Matches
HalCbmCompressionTask.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023-2023 Warsaw University of Technology, Warsaw
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Daniel Wielanek [committer] */
5
6#include "CbmMCTrack.h"
7#include "CbmTrackMatchNew.h"
8#include "CbmVertex.h"
9#include "FairRootManager.h"
10
11HalCbmCompressionTask::HalCbmCompressionTask() : fStsLinks(nullptr), fTofLinks(nullptr), fAllDep(kFALSE)
12{
13 fStsMatches = new Hal::TrackClones("CbmTrackMatchNew", "StsTrackMatch", "STS");
14 fTofMatches = new Hal::TrackClones("CbmTrackMatchNew", "TofHitMatch", "TOF");
15 fMCTracks = new Hal::TrackClones("CbmMCTrack", "MCTrack", "MC");
16}
17
19{
20 FairRootManager* mngr = FairRootManager::Instance();
21 fTofMatches->GetFromTree();
22 fStsMatches->GetFromTree();
23 fMCTracks->GetFromTree();
24 if (fTofMatches->GetArray() == nullptr) return kFATAL;
25 if (fStsMatches->GetArray() == nullptr) return kFATAL;
26
27 if (fMCTracks->GetArray() == nullptr) return kFATAL;
28
29 mngr->Register("MCTrack", "MC", fMCTracks->GetArray(), kTRUE);
30 fStsLinks = new TClonesArray("CbmTrackMatchNew");
31 fTofLinks = new TClonesArray("CbmTrackMatchNew");
32 mngr->Register("StsTrackMatch", "STS", fStsLinks, kTRUE);
33 mngr->Register("TofHitMatch", "TOF", fTofLinks, kTRUE);
34 mngr->Register("PrimaryVertex.", "PV", (CbmVertex*) mngr->GetObject("PrimaryVertex."), kTRUE);
35 TClonesArray* sts_tracks = (TClonesArray*) mngr->GetObject("StsTrack");
36 TClonesArray* tof_tracks = (TClonesArray*) mngr->GetObject("TofHit");
37 TClonesArray* glob_tracks = (TClonesArray*) mngr->GetObject("GlobalTrack");
38
39 mngr->Register("StsTrack", "STS", sts_tracks, kTRUE);
40 mngr->Register("TofHit", "TOF", tof_tracks, kTRUE);
41 mngr->Register("GlobalTrack", "STS", glob_tracks, kTRUE);
42
43 return kSUCCESS;
44}
45
46void HalCbmCompressionTask::Exec(Option_t* /*opt*/)
47{
48 fMapUse.MakeBigger(fMCTracks->GetEntriesFast());
49 fMapIndex.MakeBigger(fMCTracks->GetEntriesFast());
50 fStsLinks->Clear();
51 fTofLinks->Clear();
52 fStsLinks->ExpandCreateFast(fStsMatches->GetEntriesFast());
53 fTofLinks->ExpandCreateFast(fTofMatches->GetEntriesFast());
54 for (int i = 0; i < fMCTracks->GetEntriesFast(); i++) {
55 fMapUse[i] = 0;
56 fMapIndex[i] = -2;
57 }
58 if (fAllDep) {
59 WithDep();
60 }
61 else {
62 NoDep();
63 }
64}
65
67{
68 for (int i = 0; i < fStsMatches->GetEntriesFast(); i++) {
69 CbmTrackMatchNew* match = (CbmTrackMatchNew*) fStsMatches->UncheckedAt(i);
70 int index = match->GetMatchedLink().GetIndex();
71 if (index >= 0) { // needed?
72 fMapUse[index] = 1;
73 }
74 }
75 for (int i = 0; i < fTofMatches->GetEntriesFast(); i++) {
76 CbmTrackMatchNew* match = (CbmTrackMatchNew*) fTofMatches->UncheckedAt(i);
77 int index = match->GetMatchedLink().GetIndex();
78 if (index >= 0) {
79 fMapUse[index] = 1;
80 }
81 }
82 int count = 0;
83 for (int i = 0; i < fMCTracks->GetEntriesFast(); i++) {
84 if (fMapUse[i] == 1) {
85 fMapIndex[i] = count;
86 ++count;
87 }
88 else {
89 fMCTracks->GetArray()->RemoveAt(i);
90 }
91 }
92 fMCTracks->GetArray()->Compress();
93 for (int i = 0; i < fMCTracks->GetEntriesFast(); i++) {
94 CbmMCTrack* mc = (CbmMCTrack*) fMCTracks->UncheckedAt(i);
95 int mom = mc->GetMotherId();
96 if (mom >= 0) {
97 mc->SetMotherId(fMapIndex[mom]);
98 }
99 }
100
101 //ok let's fix matches
102 for (int iTrack = 0; iTrack < fStsMatches->GetEntriesFast(); iTrack++) {
103 CbmTrackMatchNew* match = (CbmTrackMatchNew*) fStsMatches->UncheckedAt(iTrack);
104 CbmLink link = match->GetMatchedLink();
105 CbmTrackMatchNew* match2 = (CbmTrackMatchNew*) fStsLinks->UncheckedAt(iTrack);
106 match2->ClearLinks();
107 int index = link.GetIndex();
108 if (index >= 0) {
109 link.SetIndex(fMapIndex[index]);
110 link.SetWeight(1);
111 }
112 match2->AddLink(link);
113 }
114 for (int iTrack = 0; iTrack < fTofMatches->GetEntriesFast(); iTrack++) {
115 CbmTrackMatchNew* match = (CbmTrackMatchNew*) fTofMatches->UncheckedAt(iTrack);
116 CbmTrackMatchNew* match2 = (CbmTrackMatchNew*) fTofLinks->UncheckedAt(iTrack);
117 CbmLink link = match->GetMatchedLink();
118 match2->ClearLinks();
119 int index = link.GetIndex();
120 if (index >= 0) {
121 link.SetIndex(fMapIndex[index]);
122 link.SetWeight(1);
123 }
124 match2->AddLink(link);
125 }
126}
127
129{
130 for (int i = 0; i < fStsMatches->GetEntriesFast(); i++) {
131 CbmTrackMatchNew* match = (CbmTrackMatchNew*) fStsMatches->UncheckedAt(i);
132 for (int j = 0; j < match->GetNofLinks(); j++) {
133 int index = match->GetLink(j).GetIndex();
134 if (index >= 0) {
135 fMapUse[index] = 1;
136 }
137 }
138 }
139 for (int i = 0; i < fTofMatches->GetEntriesFast(); i++) {
140 CbmTrackMatchNew* match = (CbmTrackMatchNew*) fTofMatches->UncheckedAt(i);
141 for (int j = 0; j < match->GetNofLinks(); j++) {
142 int index = match->GetLink(j).GetIndex();
143 if (index >= 0) {
144 fMapUse[index] = 1;
145 }
146 }
147 }
148 int count = 0;
149 for (int i = 0; i < fMCTracks->GetEntriesFast(); i++) {
150 if (fMapUse[i] == 1) {
151 fMapIndex[i] = count;
152 ++count;
153 }
154 else {
155 fMCTracks->GetArray()->RemoveAt(i);
156 }
157 }
158 fMCTracks->GetArray()->Compress();
159 for (int i = 0; i < fMCTracks->GetEntriesFast(); i++) {
160 CbmMCTrack* mc = (CbmMCTrack*) fMCTracks->UncheckedAt(i);
161 int mom = mc->GetMotherId();
162 if (mom >= 0) {
163 mc->SetMotherId(fMapIndex[mom]);
164 }
165 }
166
167 //ok let's fix matches
168 for (int iTrack = 0; iTrack < fStsMatches->GetEntriesFast(); iTrack++) {
169 CbmTrackMatchNew* match = (CbmTrackMatchNew*) fStsMatches->UncheckedAt(iTrack);
170 CbmTrackMatchNew* match2 = (CbmTrackMatchNew*) fStsLinks->UncheckedAt(iTrack);
171 match2->ClearLinks();
172 for (int iLink = 0; iLink < match->GetNofLinks(); iLink++) {
173 CbmLink link = match->GetLink(iLink);
174 int index = link.GetIndex();
175 if (index >= 0) {
176 link.SetIndex(fMapIndex[index]);
177 }
178 match2->AddLink(link);
179 }
180 }
181 for (int iTrack = 0; iTrack < fTofMatches->GetEntriesFast(); iTrack++) {
182 CbmTrackMatchNew* match = (CbmTrackMatchNew*) fTofMatches->UncheckedAt(iTrack);
183 CbmTrackMatchNew* match2 = (CbmTrackMatchNew*) fTofLinks->UncheckedAt(iTrack);
184 match2->ClearLinks();
185 for (int iLink = 0; iLink < match->GetNofLinks(); iLink++) {
186 CbmLink link = match->GetLink(iLink);
187 int index = link.GetIndex();
188 if (index >= 0) {
189 link.SetIndex(fMapIndex[index]);
190 }
191 match2->AddLink(link);
192 }
193 }
194}
195
int32_t GetMotherId() const
Definition CbmMCTrack.h:69
void SetMotherId(int32_t id)
Definition CbmMCTrack.h:110
const CbmLink & GetLink(int32_t i) const
Definition CbmMatch.h:39
int32_t GetNofLinks() const
Definition CbmMatch.h:42
void AddLink(const CbmLink &newLink)
Definition CbmMatch.cxx:47
const CbmLink & GetMatchedLink() const
Definition CbmMatch.h:41
void ClearLinks()
Definition CbmMatch.cxx:78
Hal::TrackClones * fTofMatches
Hal::Array_1< Int_t > fMapIndex
Hal::TrackClones * fStsMatches
Hal::TrackClones * fMCTracks
Hal::Array_1< Int_t > fMapUse