REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestDetectorHitsToTrackFastProcess.cxx
1
13
14#include "TRestDetectorHitsToTrackFastProcess.h"
15
16using namespace std;
17
18#include <TRestMesh.h>
19
21
22TRestDetectorHitsToTrackFastProcess::TRestDetectorHitsToTrackFastProcess() { Initialize(); }
23
24TRestDetectorHitsToTrackFastProcess::TRestDetectorHitsToTrackFastProcess(const char* configFilename) {
25 Initialize();
26
27 if (LoadConfigFromFile(configFilename) == -1) LoadDefaultConfig();
28}
29
30TRestDetectorHitsToTrackFastProcess::~TRestDetectorHitsToTrackFastProcess() {
31 // TRestDetectorHitsToTrackFastProcess destructor
32 delete fTrackEvent;
33}
34
35void TRestDetectorHitsToTrackFastProcess::LoadDefaultConfig() {
36 SetName("fastHitsToTrackProcess");
37 SetTitle("Default config");
38
39 fCellResolution = 10.;
40 fNetSize = 1000.;
41 fNetOrigin = TVector3(-500, -500, -500);
42 fNodes = (Int_t)(fNetSize / fCellResolution);
43}
44
46 SetSectionName(this->ClassName());
47 SetLibraryVersion(LIBRARY_VERSION);
48
49 fCellResolution = 10.;
50 fNetSize = 1000.;
51 fNetOrigin = TVector3(-500, -500, -500);
52 fNodes = (Int_t)(fNetSize / fCellResolution);
53
54 fHitsEvent = nullptr;
55 fTrackEvent = new TRestTrackEvent();
56}
57
58void TRestDetectorHitsToTrackFastProcess::LoadConfig(const string& configFilename, const string& name) {
59 if (LoadConfigFromFile(configFilename, name) == -1) LoadDefaultConfig();
60}
61
63 // Function to be executed once at the beginning of process
64 // (before starting the process of the events)
65
66 // Start by calling the InitProcess function of the abstract class.
67 // Comment this if you don't want it.
68 // TRestEventProcess::InitProcess();
69}
70
72 /* Time measurement
73 high_resolution_clock::time_point t1 = high_resolution_clock::now();
74 */
75 fHitsEvent = (TRestDetectorHitsEvent*)inputEvent;
76
77 fTrackEvent->SetID(fHitsEvent->GetID());
78 fTrackEvent->SetSubID(fHitsEvent->GetSubID());
79 fTrackEvent->SetTimeStamp(fHitsEvent->GetTimeStamp());
80 fTrackEvent->SetSubEventTag(fHitsEvent->GetSubEventTag());
81
82 /* Debug output
83 cout << "----------------------" << endl;
84 cout << "Event ID : " << fHitsEvent->GetID() << endl;
85 cout << "Number of hits : " << fHitsEvent->GetNumberOfHits() << endl;
86 */
87
88 /* Debugging output
89 fHitsEvent->PrintEvent();
90 getchar();
91 */
92
93 TRestHits* xzHits = fHitsEvent->GetXZHits();
94 // cout << "Number of xzHits : " << xzHits->GetNumberOfHits() << endl;
95 Int_t xTracks = FindTracks(xzHits);
96
97 fTrackEvent->SetNumberOfXTracks(xTracks);
98
99 TRestHits* yzHits = fHitsEvent->GetYZHits();
100 // cout << "Number of yzHits : " << yzHits->GetNumberOfHits() << endl;
101 Int_t yTracks = FindTracks(yzHits);
102
103 fTrackEvent->SetNumberOfYTracks(yTracks);
104
105 TRestHits* xyzHits = fHitsEvent->GetXYZHits();
106 // cout << "Number of xyzHits : " << xyzHits->GetNumberOfHits() << endl;
107
108 FindTracks(xyzHits);
109
110 /*
111 cout << "X tracks : " << xTracks << " Y tracks : " << yTracks << endl;
112 cout << "Total number of tracks : " << fTrackEvent->GetNumberOfTracks() <<
113 endl;
114 */
115
116 /* Time measurement
117 high_resolution_clock::time_point t2 = high_resolution_clock::now();
118 auto duration = duration_cast<microseconds>( t2 - t1 ).count();
119 cout << duration << " us" << endl;
120 getchar();
121 */
122
123 if (fTrackEvent->GetNumberOfTracks() == 0) return nullptr;
124
125 fTrackEvent->SetLevels();
126
127 return fTrackEvent;
128}
129
130Int_t TRestDetectorHitsToTrackFastProcess::FindTracks(TRestHits* hits) {
131 TRestMesh* mesh = new TRestMesh(fNetSize, fNodes);
132 mesh->SetOrigin(fNetOrigin);
133
134 mesh->SetNodesFromHits(hits);
135
136 Int_t nTracksFound = mesh->GetNumberOfGroups();
137
138 vector<TRestTrack> track(nTracksFound);
139 vector<TRestVolumeHits> volHit(nTracksFound);
140
141 double nan = numeric_limits<double>::quiet_NaN();
142 for (unsigned int h = 0; h < hits->GetNumberOfHits(); h++) {
143 Double_t x = hits->GetX(h);
144 Double_t y = hits->GetY(h);
145 Double_t z = hits->GetZ(h);
146 Double_t time = hits->GetTime(h);
147 REST_HitType type = hits->GetType(h);
148 Double_t en = hits->GetEnergy(h);
149
150 TVector3 pos(x, y, z);
151 TVector3 sigma(0, 0, 0);
152
153 Int_t gId = mesh->GetGroupId(type == YZ ? nan : hits->GetX(h), type == XZ ? nan : hits->GetY(h),
154 hits->GetZ(h));
155 volHit[gId].AddHit(pos, en, time, type, sigma);
156 }
157
158 for (int tckID = 0; tckID < nTracksFound; tckID++) {
159 track[tckID].SetParentID(0);
160 track[tckID].SetTrackID(fTrackEvent->GetNumberOfTracks() + 1);
161 track[tckID].SetVolumeHits(volHit[tckID]);
162 fTrackEvent->AddTrack(&track[tckID]);
163 }
164
165 delete mesh;
166
167 return nTracksFound;
168}
169
171 // Function to be executed once at the end of the process
172 // (after all events have been processed)
173
174 // Start by calling the EndProcess function of the abstract class.
175 // Comment this if you don't want it.
176 // TRestEventProcess::EndProcess();
177}
178
180 fCellResolution = GetDblParameterWithUnits("cellResolution");
181 fNetSize = GetDblParameterWithUnits("netSize");
182 fNetOrigin = Get3DVectorParameterWithUnits("netOrigin");
183 fNodes = (Int_t)(fNetSize / fCellResolution);
184}
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.
void Initialize() override
Making default settings.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
Process one event.
void InitFromConfigFile() override
To make settings from rml file. This method must be implemented in the derived class.
void EndProcess() override
To be executed at the end of the run (outside event loop)
void InitProcess() override
To be executed at the beginning of the run (outside event loop)
A base class for any REST event.
Definition: TRestEvent.h:38
It saves a 3-coordinate position and an energy for each punctual deposition.
Definition: TRestHits.h:39
A basic class inheriting from TObject to help creating a node grid definition.
Definition: TRestMesh.h:38
void SetOrigin(Double_t oX, Double_t oY, Double_t oZ)
Sets the origin of the bounding-box and initializes the nodes vector to zero.
Definition: TRestMesh.cxx:507
void SetNodesFromHits(TRestHits *hits)
It initializes the nodes using the hit coordinates found inside a TRestHits structure.
Definition: TRestMesh.cxx:318
Int_t GetGroupId(Double_t x, Double_t y, Double_t z)
Returns the group id corresponding to the x,y,z coordinate. If the coordinate falls at a non-initiali...
Definition: TRestMesh.cxx:404
Int_t GetNumberOfGroups() const
Returns the total number of groups identified.
Definition: TRestMesh.h:87
Int_t LoadConfigFromFile(const std::string &configFilename, const std::string &sectionName="")
Give the file name, find out the corresponding section. Then call the main starter.
void SetLibraryVersion(TString version)
Set the library version of this metadata class.
void SetSectionName(std::string sName)
set the section name, clear the section content