REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestDetectorHitmapAnalysisProcess.cxx
1/*************************************************************************
2 * This file is part of the REST software framework. *
3 * *
4 * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
5 * For more information see http://gifna.unizar.es/trex *
6 * *
7 * REST is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * REST is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have a copy of the GNU General Public License along with *
18 * REST in $REST_PATH/LICENSE. *
19 * If not, see http://www.gnu.org/licenses/. *
20 * For the list of contributors see $REST_PATH/CREDITS. *
21 *************************************************************************/
22
89
90#include "TRestDetectorHitmapAnalysisProcess.h"
91
92using namespace std;
93
95
100
105
119 Initialize();
120 LoadConfigFromFile(configFilename);
121}
122
127 SetSectionName(this->ClassName());
128 SetLibraryVersion(LIBRARY_VERSION);
129
130 fHitsEvent = nullptr;
131}
132
137 fHitsEvent = (TRestDetectorHitsEvent*)inputEvent;
138
139 TVector3 hitMean = fHitsEvent->GetMeanPosition();
140
141 TVector3 transformedMean = hitMean;
142
143 for (const auto& t : fTransformations) {
145 tr = GetTransformation(t);
146
147 if (tr.type == "specular") transformedMean = Specular(transformedMean, tr);
148 if (tr.type == "rotation") transformedMean = Rotation(transformedMean, tr);
149 if (tr.type == "translation") transformedMean = Translation(transformedMean, tr);
150 }
151
152 SetObservableValue("xMean", transformedMean.X());
153 SetObservableValue("yMean", transformedMean.Y());
154 SetObservableValue("zMean", transformedMean.Z());
155
156 return fHitsEvent;
157}
158
163TVector3 TRestDetectorHitmapAnalysisProcess::Specular(const TVector3& pos, const HitTransformation& tr) {
164 if (tr.type != "specular") return {0, 0, 0};
165
166 TVector3 V = pos - tr.position;
167 Double_t vByN = V.Dot(tr.vector);
168 TVector3 reflectionVector = V - 2 * vByN * tr.vector;
169 return tr.position + reflectionVector;
170}
171
176TVector3 TRestDetectorHitmapAnalysisProcess::Rotation(const TVector3& pos, const HitTransformation& tr) {
177 if (tr.type != "rotation") return {0, 0, 0};
178
179 TVector3 position = pos - tr.position;
180 position.Rotate(tr.angle, tr.vector);
181 position += tr.position;
182
183 return position;
184}
185
191 if (tr.type != "translation") return {0, 0, 0};
192
193 TVector3 position = pos + tr.vector;
194 return position;
195}
196
201 for (const auto& t : fTransDefinitions) {
202 if (t.name == name) return t;
203 }
204
206 return Tr;
207}
208
214
215 auto specularDef = GetElement("specular");
216 while (specularDef) {
217 HitTransformation trans;
218 trans.type = "specular";
219
220 string name = GetFieldValue("name", specularDef);
221 if (name == "Not defined") {
222 RESTError << "The `name` field was not found in specular definition!" << RESTendl;
223 exit(1);
224 }
225 trans.name = name;
226
227 TVector3 position = Get3DVectorParameterWithUnits("position", specularDef);
228 if (position == TVector3(-1, -1, -1)) {
229 RESTError << "The `position` field was not found in specular definition!" << RESTendl;
230 exit(1);
231 }
232 trans.position = position;
233
234 TVector3 vect = Get3DVectorParameterWithUnits("vector", specularDef);
235 if (vect == TVector3(-1, -1, -1)) {
236 RESTError << "The `vector` field was not found in specular definition!" << RESTendl;
237 exit(1);
238 }
239 trans.vector = vect;
240
241 fTransDefinitions.push_back(trans);
242 specularDef = GetNextElement(specularDef);
243 }
244
245 auto rotationDef = GetElement("rotation");
246 while (rotationDef) {
247 HitTransformation trans;
248 trans.type = "rotation";
249
250 string name = GetFieldValue("name", rotationDef);
251 if (name == "Not defined") {
252 RESTError << "The `name` field was not found in rotation definition!" << RESTendl;
253 exit(1);
254 }
255 trans.name = name;
256
257 TVector3 position = Get3DVectorParameterWithUnits("position", rotationDef);
258 if (position == TVector3(-1, -1, -1)) {
259 RESTError << "The `position` field was not found in rotation definition!" << RESTendl;
260 exit(1);
261 }
262 trans.position = position;
263
264 TVector3 vect = Get3DVectorParameterWithUnits("vector", rotationDef);
265 if (vect == TVector3(-1, -1, -1)) {
266 RESTError << "The `vector` field was not found in rotation definition!" << RESTendl;
267 exit(1);
268 }
269 trans.vector = vect;
270
271 Double_t angle = GetDblParameterWithUnits("angle", rotationDef);
272 if (angle == PARAMETER_NOT_FOUND_DBL) {
273 RESTError << "The `angle` field was not found in rotation definition!" << RESTendl;
274 exit(1);
275 }
276 trans.angle = angle;
277
278 fTransDefinitions.push_back(trans);
279 rotationDef = GetNextElement(rotationDef);
280 }
281
282 auto translationDef = GetElement("translation");
283 while (translationDef) {
284 HitTransformation trans;
285 trans.type = "translation";
286
287 string name = GetFieldValue("name", translationDef);
288 if (name == "Not defined") {
289 RESTError << "The `name` field was not found in translation definition!" << RESTendl;
290 exit(1);
291 }
292 trans.name = name;
293
294 TVector3 vect = Get3DVectorParameterWithUnits("vector", translationDef);
295 if (vect == TVector3(-1, -1, -1)) {
296 RESTError << "The `vector` field was not found in translation definition!" << RESTendl;
297 exit(1);
298 }
299 trans.vector = vect;
300
301 fTransDefinitions.push_back(trans);
302 translationDef = GetNextElement(translationDef);
303 }
304}
305
311
312 if (!fTransDefinitions.empty()) {
313 RESTMetadata << " List of transformation definitions: " << RESTendl;
314 RESTMetadata << " ----------------------------------- " << RESTendl;
315 RESTMetadata << " " << RESTendl;
316 } else
317 RESTMetadata << " No transformations found! " << RESTendl;
318
319 for (const auto& t : fTransDefinitions) {
320 if (t.type == "specular") {
321 RESTMetadata << " - Specular transformation: " << RESTendl;
322 RESTMetadata << " + Plane position : (" << t.position.X() << ", " << t.position.Y() << ", "
323 << t.position.Z() << ") mm" << RESTendl;
324 RESTMetadata << " + Plane normal : (" << t.vector.X() << ", " << t.vector.Y() << ", "
325 << t.vector.Z() << ")" << RESTendl;
326 RESTMetadata << " " << RESTendl;
327 }
328
329 if (t.type == "rotation") {
330 RESTMetadata << " - Rotation transformation: " << RESTendl;
331 RESTMetadata << " + Rotation center : (" << t.position.X() << ", " << t.position.Y() << ", "
332 << t.position.Z() << ") mm" << RESTendl;
333 RESTMetadata << " + Rotation axis : (" << t.vector.X() << ", " << t.vector.Y() << ", "
334 << t.vector.Z() << ")" << RESTendl;
335 RESTMetadata << " + Rotation angle : " << t.angle * units("degrees") << " degrees" << RESTendl;
336 RESTMetadata << " " << RESTendl;
337 }
338
339 if (t.type == "translation") {
340 RESTMetadata << " - Translation transformation: " << RESTendl;
341 RESTMetadata << " + Translation vector : (" << t.vector.X() << ", " << t.vector.Y() << ", "
342 << t.vector.Z() << ") mm" << RESTendl;
343 RESTMetadata << " " << RESTendl;
344 }
345 }
346
347 RESTMetadata << " Order of transformations: " << RESTendl;
348 RESTMetadata << " ------------------------- " << RESTendl;
349 RESTMetadata << " " << RESTendl;
350
351 int n = 0;
352 for (const auto& t : fTransformations) {
353 n++;
354 RESTMetadata << n << ". " << t << RESTendl;
355 }
356
357 EndPrintProcess();
358}
An analysis process to apply rotation/translation/specular to mean hit positions.
std::vector< HitTransformation > fTransDefinitions
A list of transformations that can be applied to the mean positions.
TVector3 Specular(const TVector3 &pos, const HitTransformation &tr)
It performs a specular transformation of the given pos in the argument and the transformation propert...
HitTransformation GetTransformation(const std::string &name)
It returns the transformation with a given name.
void Initialize() override
Function to initialize input/output event members and define the section name.
TRestDetectorHitsEvent * fHitsEvent
A pointer to the specific TRestDetectorHitsEvent input.
TVector3 Translation(const TVector3 &pos, const HitTransformation &tr)
It performs a translation of the given pos in the argument and the transformation properties stored i...
std::vector< std::string > fTransformations
An ordered list with the names of transformations that will be applied.
TVector3 Rotation(const TVector3 &pos, const HitTransformation &tr)
It performs a rotation of the given pos in the argument and the transformation properties stored in t...
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
The main processing event function.
void PrintMetadata() override
Prints out the metadata member values.
void InitFromConfigFile() override
A custom initalization from a config file.
virtual void InitFromConfigFile() override
To make settings from rml file. This method must be implemented in the derived class.
void BeginPrintProcess()
[name, cut range]
void SetObservableValue(const std::string &name, const T &value)
Set observable value for AnalysisTree.
A base class for any REST event.
Definition: TRestEvent.h:38
endl_t RESTendl
Termination flag object for TRestStringOutput.
TiXmlElement * GetElement(std::string eleDeclare, TiXmlElement *e=nullptr)
Get an xml element from a given parent element, according to its declaration.
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.
std::string GetFieldValue(std::string parName, TiXmlElement *e)
Returns the field value of an xml element which has the specified name.
void SetSectionName(std::string sName)
set the section name, clear the section content
TiXmlElement * GetNextElement(TiXmlElement *e)
Get the next sibling xml element of this element, with same eleDeclare.
A structure to define a given hit transformation.
TVector3 vector
The translation vector, the axis of rotation or the specular plane normal.
std::string name
A given name that allows to place an order to the transformations.
TVector3 position
The center of rotation or a point contained in the specular plane.
std::string type
The type of transformation (specular/rotation/translation)
Double_t angle
The angle of rotation.