REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestDetectorHitsRotateAndTranslateProcess.cxx
1
21
22#include "TRestDetectorHitsRotateAndTranslateProcess.h"
23
24using namespace std;
25
26#include <TRandom3.h>
27
29
30TRestDetectorHitsRotateAndTranslateProcess::TRestDetectorHitsRotateAndTranslateProcess() { Initialize(); }
31
32TRestDetectorHitsRotateAndTranslateProcess::TRestDetectorHitsRotateAndTranslateProcess(
33 const char* configFilename) {
34 Initialize();
35
36 if (LoadConfigFromFile(configFilename)) {
37 LoadDefaultConfig();
38 }
39
41}
42
43TRestDetectorHitsRotateAndTranslateProcess::~TRestDetectorHitsRotateAndTranslateProcess() {
44 // TRestDetectorHitsRotateAndTranslateProcess destructor
45}
46
47void TRestDetectorHitsRotateAndTranslateProcess::LoadDefaultConfig() {
48 SetTitle("Default config");
49
50 fDeltaX = 1.0;
51 fDeltaY = 1.0;
52 fDeltaZ = 1.0;
53 fAlpha = 0.;
54 fBeta = 0.;
55 fGamma = 0.;
56}
57
59 SetSectionName(this->ClassName());
60 SetLibraryVersion(LIBRARY_VERSION);
61
62 fDeltaX = 1.0;
63 fDeltaY = 1.0;
64 fDeltaZ = 1.0;
65 fAlpha = 0.;
66 fBeta = 0.;
67 fGamma = 0.;
68
69 fInputHitsEvent = nullptr;
70 fOutputHitsEvent = nullptr;
71}
72
73void TRestDetectorHitsRotateAndTranslateProcess::LoadConfig(string configFilename) {
74 if (LoadConfigFromFile(configFilename)) LoadDefaultConfig();
75
77}
78
80 // Function to be executed once at the beginning of process
81 // (before starting the process of the events)
82
83 // Start by calling the InitProcess function of the abstract class.
84 // Comment this if you don't want it.
85 // TRestEventProcess::InitProcess();
86}
87
89 fInputHitsEvent = (TRestDetectorHitsEvent*)inputEvent;
90
91 fOutputHitsEvent = fInputHitsEvent;
92 // fInputHitsEvent->CloneTo(fOutputHitsEvent);
93
94 TVector3 meanPosition = fOutputHitsEvent->GetMeanPosition();
95 for (unsigned int hit = 0; hit < fOutputHitsEvent->GetNumberOfHits(); hit++) {
96 fOutputHitsEvent->GetHits()->RotateIn3D(hit, fAlpha, fBeta, fGamma, meanPosition);
97 fOutputHitsEvent->GetHits()->Translate(hit, fDeltaX, fDeltaY, fDeltaZ);
98 }
99
100 if (fOutputHitsEvent->GetNumberOfHits() == 0) return nullptr;
101
102 RESTDebug << "Number of hits rotated: " << fInputHitsEvent->GetNumberOfHits() << RESTendl;
103 return fOutputHitsEvent;
104}
105
107 // Function to be executed once at the end of the process
108 // (after all events have been processed)
109
110 // Start by calling the EndProcess function of the abstract class.
111 // Comment this if you don't want it.
112 // TRestEventProcess::EndProcess();
113}
114
116 fDeltaX = GetDblParameterWithUnits("deltaX");
117 fDeltaY = GetDblParameterWithUnits("deltaY");
118 fDeltaZ = GetDblParameterWithUnits("deltaZ");
119
120 fAlpha = StringToDouble(GetParameter("alpha")); // rotation angle around Z
121 fBeta = StringToDouble(GetParameter("beta")); // rotation angle around Y
122 fGamma = StringToDouble(GetParameter("gamma")); // rotation angle around X
123
124 // Conversion to radians
125 fAlpha = fAlpha * TMath::Pi() / 180.;
126 fBeta = fBeta * TMath::Pi() / 180.;
127 fGamma = fGamma * TMath::Pi() / 180.;
128}
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)
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
Process one event.
void PrintMetadata() override
Implemented it in the derived metadata class to print out specific metadata information.
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
void RotateIn3D(Int_t n, Double_t alpha, Double_t beta, Double_t gamma, const TVector3 &center)
It rotates hit n following rotations in Z, Y and X by angles gamma, beta and alpha....
Definition: TRestHits.cxx:393
void Translate(Int_t n, Double_t x, Double_t y, Double_t z)
It moves hit n by a given amount (x,y,z).
Definition: TRestHits.cxx:383
endl_t RESTendl
Termination flag object for TRestStringOutput.
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.
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.
Double_t StringToDouble(std::string in)
Gets a double from a string.