REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestDetectorHitsToTrackProcess.cxx
1/*************************************************************************
2 * This file is part of the REST software framework. *
3 * *
4 * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
5 * For more information see http://gifna.unizar.es/trex *
6 * *
7 * REST is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * REST is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have a copy of the GNU General Public License along with *
18 * REST in $REST_PATH/LICENSE. *
19 * If not, see http://www.gnu.org/licenses/. *
20 * For the list of contributors see $REST_PATH/CREDITS. *
21 *************************************************************************/
22
84
85#include "TRestDetectorHitsToTrackProcess.h"
86using namespace std;
87
89
94
99 delete fTrackEvent;
100 // TRestDetectorHitsToTrackProcess destructor
101}
102
108 SetSectionName(this->ClassName());
109 SetLibraryVersion(LIBRARY_VERSION);
110
111 fClusterDistance = 1.;
112
113 fHitsEvent = nullptr;
114 fTrackEvent = new TRestTrackEvent();
115}
116
121 /* Time measurement
122 high_resolution_clock::time_point t1 = high_resolution_clock::now();
123 */
124
125 fHitsEvent = (TRestDetectorHitsEvent*)inputEvent;
126 fTrackEvent->SetEventInfo(fHitsEvent);
127
129 cout << "TResDetectorHitsToTrackProcess : nHits " << fHitsEvent->GetNumberOfHits() << endl;
130
131 TRestHits* xzHits = fHitsEvent->GetXZHits();
132
134 cout << "TRestDetectorHitsToTrackProcess : Number of xzHits : " << xzHits->GetNumberOfHits() << endl;
135 Int_t xTracks = FindTracks(xzHits);
136
137 fTrackEvent->SetNumberOfXTracks(xTracks);
138
139 TRestHits* yzHits = fHitsEvent->GetYZHits();
141 cout << "TRestDetectorHitsToTrackProcess : Number of yzHits : " << yzHits->GetNumberOfHits() << endl;
142 Int_t yTracks = FindTracks(yzHits);
143
144 fTrackEvent->SetNumberOfYTracks(yTracks);
145
146 TRestHits* xyzHits = fHitsEvent->GetXYZHits();
148 cout << "TRestDetectorHitsToTrackProcess : Number of xyzHits : " << xyzHits->GetNumberOfHits()
149 << endl;
150
151 FindTracks(xyzHits);
152
154 cout << "TRestDetectorHitsToTrackProcess. X tracks : " << xTracks << " Y tracks : " << yTracks
155 << endl;
156 cout << "TRestDetectorHitsToTrackProcess. Total number of tracks : "
157 << fTrackEvent->GetNumberOfTracks() << endl;
158 }
159
160 if (fTrackEvent->GetNumberOfTracks() == 0) return nullptr;
161
163 fTrackEvent->PrintOnlyTracks();
164
165 fTrackEvent->SetLevels();
166
167 return fTrackEvent;
168}
169
178 Int_t nTracksFound = 0;
179 vector<Int_t> Q; // list of points (hits) that need to be checked
180 vector<Int_t> P; // list of neighbours within a radious fClusterDistance
181
182 bool isProcessed = false;
183 Int_t qsize = 0;
184 TRestTrack* track = new TRestTrack();
185
186 TRestVolumeHits volHit;
187
188 Float_t fClusterDistance2 = (Float_t)(fClusterDistance * fClusterDistance);
189
190 // for every event in the point cloud
191 while (hits->GetNumberOfHits() > 0) {
192 Q.push_back(0);
193
194 // for every point in Q
195 for (unsigned int q = 0; q < Q.size(); q++) {
196 // we look for the neighbours
197 for (unsigned int j = 0; j < hits->GetNumberOfHits(); j++) {
198 if ((int)j != Q[q]) {
199 if (hits->GetDistance2(Q[q], j) < fClusterDistance2) P.push_back(j);
200 }
201 }
202 qsize = Q.size();
203
204 // For all the neighbours found P.size()
205 // Check if the points have already been processed
206 for (unsigned int i = 0; i < P.size(); i++) {
207 isProcessed = false;
208
209 for (int j = 0; j < qsize; j++) {
210 // if yes, we do not consider it again
211 if (P[i] == Q[j]) {
212 isProcessed = true;
213 break;
214 }
215 }
216
217 // If not, we add the point P[i] to the list of Q
218 if (isProcessed == false) {
219 Q.push_back(P[i]);
220 }
221 }
222
223 P.clear();
224 }
225
226 // We order the Q vector
227 std::sort(Q.begin(), Q.end());
228 // Then we swap to decresing order
229 std::reverse(Q.begin(), Q.end());
230
231 // When the list of all points in Q has been processed, we add the clusters
232 // to the TrackEvent and reset Q
233 for (unsigned int nhit = 0; nhit < Q.size(); nhit++) {
234 const Double_t x = hits->GetX(Q[nhit]);
235 const Double_t y = hits->GetY(Q[nhit]);
236 const Double_t z = hits->GetZ(Q[nhit]);
237 const Double_t en = hits->GetEnergy(Q[nhit]);
238
239 TVector3 pos(x, y, z);
240 TVector3 sigma(0., 0., 0.);
241
242 volHit.AddHit(pos, en, 0, hits->GetType(Q[nhit]), sigma);
243
244 hits->RemoveHit(Q[nhit]);
245 }
246
247 track->SetParentID(0);
248 track->SetTrackID(fTrackEvent->GetNumberOfTracks() + 1);
249 track->SetVolumeHits(volHit);
250 volHit.RemoveHits();
251
252 RESTDebug << "Adding track : id=" << track->GetTrackID() << " parent : " << track->GetParentID()
253 << RESTendl;
254 fTrackEvent->AddTrack(track);
255 nTracksFound++;
256
257 Q.clear();
258 }
259
260 delete track;
261
262 return nTracksFound;
263}
TRestHits * GetXYZHits()
This method collects all hits which are compatible with a XYZ hit.
TRestHits * GetXZHits()
This method collects all hits which are compatible with a XZ-projected hit.
TRestHits * GetYZHits()
This method collects all hits which are compatible with a YZ-projected hit.
A process to convert a TRestDetectorHitsEvent into a TRestTrackEvent.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
The main processing event function.
Double_t fClusterDistance
The hits distance used to define a cluster of hits.
void Initialize() override
Function to initialize input/output event members and define the section name.
Int_t FindTracks(TRestHits *hits)
The main algorithm. It idetifies the hits that belong to each track and adds them already to the outp...
A base class for any REST event.
Definition: TRestEvent.h:38
void SetEventInfo(TRestEvent *eve)
Definition: TRestEvent.cxx:137
It saves a 3-coordinate position and an energy for each punctual deposition.
Definition: TRestHits.h:39
virtual void RemoveHit(int n)
It removes the hit at position n from the list.
Definition: TRestHits.cxx:503
Double_t GetDistance2(int n, int m) const
It returns the euclidian distance between hits n and m.
Definition: TRestHits.cxx:1201
virtual void PrintHits(Int_t nHits=-1) const
It prints on screen the first nHits from the list.
Definition: TRestHits.cxx:1380
endl_t RESTendl
Termination flag object for TRestStringOutput.
void SetLibraryVersion(TString version)
Set the library version of this metadata class.
TRestStringOutput::REST_Verbose_Level GetVerboseLevel()
returns the verboselevel in type of REST_Verbose_Level enumerator
void SetSectionName(std::string sName)
set the section name, clear the section content
@ REST_Debug
+show the defined debug messages
void RemoveHits()
It removes all hits inside the class.