REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestTrackDetachIsolatedNodesProcess.cxx
1 
11 #include "TRestTrackDetachIsolatedNodesProcess.h"
12 
13 using namespace std;
14 
15 const int Nmax = 30;
16 
18 
19 TRestTrackDetachIsolatedNodesProcess::TRestTrackDetachIsolatedNodesProcess() { Initialize(); }
20 
21 TRestTrackDetachIsolatedNodesProcess::TRestTrackDetachIsolatedNodesProcess(const char* configFilename) {
22  Initialize();
23 
24  if (LoadConfigFromFile(configFilename) == -1) LoadDefaultConfig();
25  PrintMetadata();
26 }
27 
28 TRestTrackDetachIsolatedNodesProcess::~TRestTrackDetachIsolatedNodesProcess() { delete fOutputTrackEvent; }
29 
30 void 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 
43 void TRestTrackDetachIsolatedNodesProcess::LoadConfig(const string& configFilename, const string& name) {
44  if (LoadConfigFromFile(configFilename, name) == -1) LoadDefaultConfig();
45 
46  PrintMetadata();
47 }
48 
50 
52  fInputTrackEvent = (TRestTrackEvent*)inputEvent;
53 
54  if (this->GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Debug)
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 
74  /* {{{ Debug output */
75 
76  if (this->GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Debug) {
77  Int_t pId = fInputTrackEvent->GetTrack(tck)->GetParentID();
78  cout << "Track : " << tck << " TrackID : " << tckId << " ParentID : " << pId << endl;
79  cout << "-----------------" << endl;
80  hits->PrintHits();
81  cout << "-----------------" << endl;
82  GetChar();
83  }
84  /* }}} */
85 
86  TRestVolumeHits connectedHits;
87  TRestVolumeHits isolatedHit;
88 
89  connectedHits.AddHit(hits->GetPosition(0), hits->GetEnergy(0), 0, hits->GetType(0),
90  hits->GetSigma(0));
91 
92  for (int n = 1; n < nHits - 1; n++) {
93  TVector3 x0, x1, pos0, pos1;
94 
95  Double_t hitConnectivity = 0;
96 
97  x0 = hits->GetPosition(n);
98 
99  Double_t distance = 0;
100  for (int m = n - 1; m < n + 1; m++) {
101  if (n == m) m++;
102 
103  x1 = hits->GetPosition(m);
104 
105  pos0 = fTubeLengthReduction * (x1 - x0) + x0;
106  pos1 = (1 - fTubeLengthReduction) * (x1 - x0) + x0;
107 
108  distance += (x0 - x1).Mag();
109  hitConnectivity += originHits->GetEnergyInCylinder(pos0, pos1, fTubeRadius);
110  }
111 
112  if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Debug)
113  cout << "Hit : " << n << " Connectivity : " << hitConnectivity
114  << " distance : " << distance / 2. << endl;
115 
116  if (hitConnectivity <= fConnectivityThreshold && distance / 2 > fThresholdDistance) {
117  isolatedHit.AddHit(hits->GetPosition(n), hits->GetEnergy(n), 0, hits->GetType(n),
118  hits->GetSigma(n));
119 
120  TRestTrack isoTrack;
121  isoTrack.SetTrackID(fOutputTrackEvent->GetNumberOfTracks() + 1);
122 
123  isoTrack.SetParentID(tckId);
124 
125  isoTrack.SetVolumeHits(isolatedHit);
126 
127  fOutputTrackEvent->AddTrack(&isoTrack);
128 
129  isolatedHit.RemoveHits();
130  } else {
131  connectedHits.AddHit(hits->GetPosition(n), hits->GetEnergy(n), 0, hits->GetType(n),
132  hits->GetSigma(n));
133  }
134  }
135 
136  connectedHits.AddHit(hits->GetPosition(nHits - 1), hits->GetEnergy(nHits - 1), 0,
137  hits->GetType(nHits - 1), hits->GetSigma(nHits - 1));
138 
139  TRestTrack connectedTrack;
140  connectedTrack.SetTrackID(fOutputTrackEvent->GetNumberOfTracks() + 1);
141 
142  connectedTrack.SetParentID(tckId);
143 
144  connectedTrack.SetVolumeHits(connectedHits);
145 
146  fOutputTrackEvent->AddTrack(&connectedTrack);
147  }
148 
149  if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Debug) {
150  cout << "xxxx DetachIsolatedNodes trackEvent output xxxxx" << endl;
151  fOutputTrackEvent->PrintEvent();
152  cout << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" << endl;
153  GetChar();
154  }
155 
156  return fOutputTrackEvent;
157 }
158 
160 
162  fThresholdDistance = StringToDouble(GetParameter("thDistance", "8"));
163  fConnectivityThreshold = StringToDouble(GetParameter("connectivityThreshold", "0"));
164 
165  fTubeLengthReduction = StringToDouble(GetParameter("tubeLength", "0.2"));
166  fTubeRadius = StringToDouble(GetParameter("tubeRadius", "0.2"));
167 }
A base class for any REST event.
Definition: TRestEvent.h:38
virtual void PrintEvent() const
Definition: TRestEvent.cxx:187
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
@ REST_Debug
+show the defined debug messages
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.