REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestTrackReductionProcess.cxx
1
10
11#include "TRestTrackReductionProcess.h"
12
13using namespace std;
14
16
17TRestTrackReductionProcess::TRestTrackReductionProcess() { Initialize(); }
18
19TRestTrackReductionProcess::~TRestTrackReductionProcess() { delete fOutputTrackEvent; }
20
22 SetSectionName(this->ClassName());
23 SetLibraryVersion(LIBRARY_VERSION);
24
25 fInputTrackEvent = nullptr;
26 fOutputTrackEvent = new TRestTrackEvent();
27}
28
30
32 fInputTrackEvent = (TRestTrackEvent*)inputEvent;
33 fOutputTrackEvent->SetEventInfo(fInputTrackEvent);
34
35 // Copying the input tracks to the output track
36 for (int tck = 0; tck < fInputTrackEvent->GetNumberOfTracks(); tck++)
37 fOutputTrackEvent->AddTrack(fInputTrackEvent->GetTrack(tck));
38
40 fInputTrackEvent->PrintOnlyTracks();
41
42 // Reducing the hits inside each track
43 for (int tck = 0; tck < fInputTrackEvent->GetNumberOfTracks(); tck++) {
44 if (!fInputTrackEvent->isTopLevel(tck)) continue;
45
46 TRestTrack* track = fInputTrackEvent->GetTrack(tck);
47 TRestVolumeHits* hits = track->GetVolumeHits();
48
50 cout << "TRestTrackReductionProcess. Reducing hits in track id : " << track->GetTrackID() << endl;
51
52 TRestVolumeHits vHits = (TRestVolumeHits)(*hits);
53 getHitsMerged(vHits);
54 if (fKmeans) {
55 TRestVolumeHits::kMeansClustering(hits, vHits, fMaxIt);
56 int nHitsBefore;
57 int nHitsAfter;
58 do {
59 nHitsBefore = vHits.GetNumberOfHits();
60 getHitsMerged(vHits);
61 TRestVolumeHits::kMeansClustering(hits, vHits, fMaxIt);
62 nHitsAfter = vHits.GetNumberOfHits();
63 } while (nHitsBefore != nHitsAfter);
64 }
65 TRestTrack newTrack;
66 newTrack.SetVolumeHits(vHits);
67 newTrack.SetParentID(track->GetTrackID());
68 newTrack.SetTrackID(fOutputTrackEvent->GetNumberOfTracks() + 1);
69 fOutputTrackEvent->AddTrack(&newTrack);
70 }
71
72 fOutputTrackEvent->SetLevels();
73 return fOutputTrackEvent;
74}
75
76void TRestTrackReductionProcess::getHitsMerged(TRestVolumeHits& hits) {
77 Double_t distance = fStartingDistance;
78 while (distance < fMinimumDistance || hits.GetNumberOfHits() > fMaxNodes) {
80 cout << "TRestTrackReductionProcess. Merging track hits within a "
81 << "distance : " << distance << " mm" << endl;
82 cout << "TRestTrackReductionProcess. Hits now : " << hits.GetNumberOfHits() << endl;
83 }
84
85 Int_t mergedHits = 0;
86
87 Bool_t merged = true;
88 while (merged) {
89 merged = false;
90 for (unsigned int i = 0; i < hits.GetNumberOfHits(); i++) {
91 for (unsigned int j = i + 1; j < hits.GetNumberOfHits(); j++) {
92 if (hits.GetDistance2(i, j) < distance * distance) {
93 mergedHits++;
94 hits.MergeHits(i, j);
95 merged = true;
96 }
97 }
98 }
99 }
100
101 RESTDebug << "TRestTrackReductionProcess. Number of hits merged : " << mergedHits << RESTendl;
102 mergedHits = 0;
103
104 distance *= fDistanceStepFactor;
105 }
106}
107
A base class for any REST event.
Definition: TRestEvent.h:38
void SetEventInfo(TRestEvent *eve)
Definition: TRestEvent.cxx:137
Double_t GetDistance2(int n, int m) const
It returns the euclidian distance between hits n and m.
Definition: TRestHits.cxx:1201
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
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
Process one event.
void EndProcess() override
To be executed at the end of the run (outside event loop)
void Initialize() override
Making default settings.
void InitProcess() override
To be executed at the beginning of the run (outside event loop)