REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestTrackReductionProcess.cxx
1 
11 #include "TRestTrackReductionProcess.h"
12 
13 using namespace std;
14 
16 
17 TRestTrackReductionProcess::TRestTrackReductionProcess() { Initialize(); }
18 
19 TRestTrackReductionProcess::~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 
39  if (this->GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Debug)
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 
49  if (this->GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Debug)
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 
76 void TRestTrackReductionProcess::getHitsMerged(TRestVolumeHits& hits) {
77  Double_t distance = fStartingDistance;
78  while (distance < fMinimumDistance || hits.GetNumberOfHits() > fMaxNodes) {
79  if (this->GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Debug) {
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
@ 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)