REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestTrackDetachIsolatedNodesProcess.cxx
1
10
11#include "TRestTrackDetachIsolatedNodesProcess.h"
12
13using namespace std;
14
15const int Nmax = 30;
16
18
19TRestTrackDetachIsolatedNodesProcess::TRestTrackDetachIsolatedNodesProcess() { Initialize(); }
20
21TRestTrackDetachIsolatedNodesProcess::TRestTrackDetachIsolatedNodesProcess(const char* configFilename) {
22 Initialize();
23
24 if (LoadConfigFromFile(configFilename) == -1) LoadDefaultConfig();
26}
27
28TRestTrackDetachIsolatedNodesProcess::~TRestTrackDetachIsolatedNodesProcess() { delete fOutputTrackEvent; }
29
30void TRestTrackDetachIsolatedNodesProcess::LoadDefaultConfig() {
31 SetName("trackDetachIsolatedNodesProcess");
32 SetTitle("Default config");
33}
34
36 SetSectionName(this->ClassName());
37 SetLibraryVersion(LIBRARY_VERSION);
38
39 fInputTrackEvent = nullptr;
40 fOutputTrackEvent = new TRestTrackEvent();
41}
42
43void TRestTrackDetachIsolatedNodesProcess::LoadConfig(const string& configFilename, const string& name) {
44 if (LoadConfigFromFile(configFilename, name) == -1) LoadDefaultConfig();
45
47}
48
50
52 fInputTrackEvent = (TRestTrackEvent*)inputEvent;
53
55 cout << "TRestTrackDetachIsolatedNodesProcess. Number of tracks : "
56 << fInputTrackEvent->GetNumberOfTracks() << endl;
57
59 fInputTrackEvent->PrintEvent();
60
61 // Copying the input tracks to the output track
62 for (int tck = 0; tck < fInputTrackEvent->GetNumberOfTracks(); tck++)
63 fOutputTrackEvent->AddTrack(fInputTrackEvent->GetTrack(tck));
64
65 for (int tck = 0; tck < fInputTrackEvent->GetNumberOfTracks(); tck++) {
66 if (!fInputTrackEvent->isTopLevel(tck)) continue;
67 Int_t tckId = fInputTrackEvent->GetTrack(tck)->GetTrackID();
68
69 TRestVolumeHits* hits = fInputTrackEvent->GetTrack(tck)->GetVolumeHits();
70 TRestVolumeHits* originHits = fInputTrackEvent->GetOriginTrackById(tckId)->GetVolumeHits();
71
72 Int_t nHits = hits->GetNumberOfHits();
73
75 Int_t pId = fInputTrackEvent->GetTrack(tck)->GetParentID();
76 cout << "Track : " << tck << " TrackID : " << tckId << " ParentID : " << pId << endl;
77 cout << "-----------------" << endl;
78 hits->PrintHits();
79 cout << "-----------------" << endl;
80 GetChar();
81 }
82
83 TRestVolumeHits connectedHits;
84 TRestVolumeHits isolatedHit;
85
86 connectedHits.AddHit(hits->GetPosition(0), hits->GetEnergy(0), 0, hits->GetType(0),
87 hits->GetSigma(0));
88
89 for (int n = 1; n < nHits - 1; n++) {
90 TVector3 x0, x1, pos0, pos1;
91
92 Double_t hitConnectivity = 0;
93
94 x0 = hits->GetPosition(n);
95
96 Double_t distance = 0;
97 for (int m = n - 1; m < n + 1; m++) {
98 if (n == m) m++;
99
100 x1 = hits->GetPosition(m);
101
102 pos0 = fTubeLengthReduction * (x1 - x0) + x0;
103 pos1 = (1 - fTubeLengthReduction) * (x1 - x0) + x0;
104
105 distance += (x0 - x1).Mag();
106 hitConnectivity += originHits->GetEnergyInCylinder(pos0, pos1, fTubeRadius);
107 }
108
110 cout << "Hit : " << n << " Connectivity : " << hitConnectivity
111 << " distance : " << distance / 2. << endl;
112
113 if (hitConnectivity <= fConnectivityThreshold && distance / 2 > fThresholdDistance) {
114 isolatedHit.AddHit(hits->GetPosition(n), hits->GetEnergy(n), 0, hits->GetType(n),
115 hits->GetSigma(n));
116
117 TRestTrack isoTrack;
118 isoTrack.SetTrackID(fOutputTrackEvent->GetNumberOfTracks() + 1);
119
120 isoTrack.SetParentID(tckId);
121
122 isoTrack.SetVolumeHits(isolatedHit);
123
124 fOutputTrackEvent->AddTrack(&isoTrack);
125
126 isolatedHit.RemoveHits();
127 } else {
128 connectedHits.AddHit(hits->GetPosition(n), hits->GetEnergy(n), 0, hits->GetType(n),
129 hits->GetSigma(n));
130 }
131 }
132
133 connectedHits.AddHit(hits->GetPosition(nHits - 1), hits->GetEnergy(nHits - 1), 0,
134 hits->GetType(nHits - 1), hits->GetSigma(nHits - 1));
135
136 TRestTrack connectedTrack;
137 connectedTrack.SetTrackID(fOutputTrackEvent->GetNumberOfTracks() + 1);
138
139 connectedTrack.SetParentID(tckId);
140
141 connectedTrack.SetVolumeHits(connectedHits);
142
143 fOutputTrackEvent->AddTrack(&connectedTrack);
144 }
145
147 cout << "xxxx DetachIsolatedNodes trackEvent output xxxxx" << endl;
148 fOutputTrackEvent->PrintEvent();
149 cout << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" << endl;
150 GetChar();
151 }
152
153 return fOutputTrackEvent;
154}
155
157
159 fThresholdDistance = StringToDouble(GetParameter("thDistance", "8"));
160 fConnectivityThreshold = StringToDouble(GetParameter("connectivityThreshold", "0"));
161
162 fTubeLengthReduction = StringToDouble(GetParameter("tubeLength", "0.2"));
163 fTubeRadius = StringToDouble(GetParameter("tubeRadius", "0.2"));
164}
A base class for any REST event.
Definition: TRestEvent.h:38
Double_t GetEnergyInCylinder(const TVector3 &x0, const TVector3 &x1, Double_t radius) const
It determines the total energy contained inside a cylinder with a given radius and delimited between ...
Definition: TRestHits.cxx:262
TVector3 GetPosition(int n) const
It returns the position of hit number n.
Definition: TRestHits.cxx:515
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.
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
std::string GetParameter(std::string parName, TiXmlElement *e, TString defaultValue=PARAMETER_NOT_FOUND_STR)
Returns the value for the parameter named parName in the given section.
@ REST_Debug
+show the defined debug messages
void PrintMetadata() override
Implemented it in the derived metadata class to print out specific metadata information.
void Initialize() override
Making default settings.
void InitProcess() override
To be executed at the beginning of the run (outside event loop)
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 RemoveHits()
It removes all hits inside the class.
Int_t GetChar(std::string hint="Press a KEY to continue ...")
Helps to pause the program, printing a message before pausing.
Double_t StringToDouble(std::string in)
Gets a double from a string.