REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestDetectorHitsReductionProcess.cxx
1 //
13 
14 #include "TRestDetectorHitsReductionProcess.h"
15 
16 using namespace std;
17 
19 
20 TRestDetectorHitsReductionProcess::TRestDetectorHitsReductionProcess() { Initialize(); }
21 
22 TRestDetectorHitsReductionProcess::TRestDetectorHitsReductionProcess(const char* configFilename) {
23  Initialize();
24  if (LoadConfigFromFile(configFilename) == -1) {
25  LoadDefaultConfig();
26  }
27 }
28 
29 TRestDetectorHitsReductionProcess::~TRestDetectorHitsReductionProcess() {}
30 
31 void TRestDetectorHitsReductionProcess::LoadDefaultConfig() {
32  SetName("hitsReductionProcess");
33  SetTitle("Default config");
34 
35  fStartingDistance = 0.5;
36  fMinimumDistance = 3;
37  fDistanceFactor = 1.5;
38  fMaxNodes = 30;
39 }
40 
42  SetSectionName(this->ClassName());
43  SetLibraryVersion(LIBRARY_VERSION);
44 
45  fInputHitsEvent = nullptr;
46  fOutputHitsEvent = nullptr;
47 }
48 
49 void TRestDetectorHitsReductionProcess::LoadConfig(const string& configFilename, const string& name) {
50  if (LoadConfigFromFile(configFilename, name) == -1) LoadDefaultConfig();
51 }
52 
54 
56  fInputHitsEvent = (TRestDetectorHitsEvent*)inputEvent;
57  fOutputHitsEvent = fInputHitsEvent;
58 
59  Int_t initialHits = fOutputHitsEvent->GetNumberOfHits();
60 
61  // Reducing the hits
62  TRestHits* hits = fOutputHitsEvent->GetHits();
63 
64  Double_t distance = fStartingDistance;
65  while (distance < fMinimumDistance || hits->GetNumberOfHits() > fMaxNodes) {
66  Bool_t merged = true;
67  while (merged) {
68  merged = false;
69  for (unsigned int i = 0; i < hits->GetNumberOfHits(); i++) {
70  for (unsigned int j = i + 1; j < hits->GetNumberOfHits(); j++) {
71  if (hits->GetDistance2(i, j) < distance * distance) {
72  hits->MergeHits(i, j);
73  merged = true;
74  }
75  }
76  }
77  }
78  distance *= fDistanceFactor;
79  }
80 
81  Int_t finalHits = fOutputHitsEvent->GetNumberOfHits();
82 
83  if (this->GetVerboseLevel() == TRestStringOutput::REST_Verbose_Level::REST_Debug) {
84  cout << "TRestDetectorHitsReductionProcess : Initial number of hits : " << initialHits << endl;
85  cout << "TRestDetectorHitsReductionProcess : Final number of hits : " << finalHits << endl;
86  }
87 
88  /*
89  cout << "output event" << endl;
90  cout << "+++++++++++++++++" << endl;
91  fOutputHitsEvent->PrintEvent();
92  cout << "+++++++++++++++++" << endl;
93  getchar();
94  */
95 
96  // cout << "Number output of tracks : " <<
97  // fOutputTrackEvent->GetNumberOfTracks() << endl;
98 
99  return fOutputHitsEvent;
100 }
101 
103 
105  fStartingDistance = GetDblParameterWithUnits("startingDistance");
106  fMinimumDistance = GetDblParameterWithUnits("minimumDistance");
107  fDistanceFactor = StringToDouble(GetParameter("distanceStepFactor"));
108  fMaxNodes = StringToDouble(GetParameter("maxNodes"));
109 }
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
Process one event.
void Initialize() override
Making default settings.
void InitProcess() override
To be executed at the beginning of the run (outside event loop)
void EndProcess() override
To be executed at the end of the run (outside event loop)
void InitFromConfigFile() override
To make settings from rml file. This method must be implemented in the derived class.
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
virtual void MergeHits(int n, int m)
It merges hits n and m being the resulting hit placed at the weighted center and being its final ener...
Definition: TRestHits.cxx:458
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
Double_t StringToDouble(std::string in)
Gets a double from a string.