REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestDetectorHitsShuffleProcess.cxx
1
10
11#include "TRestDetectorHitsShuffleProcess.h"
12
13using namespace std;
14
16
17TRestDetectorHitsShuffleProcess::TRestDetectorHitsShuffleProcess() { Initialize(); }
18
19TRestDetectorHitsShuffleProcess::TRestDetectorHitsShuffleProcess(const char* configFilename) {
20 Initialize();
21
22 if (LoadConfigFromFile(configFilename) == -1) {
23 LoadDefaultConfig();
24 }
25}
26
27TRestDetectorHitsShuffleProcess::~TRestDetectorHitsShuffleProcess() {
28 // delete fHitsEvent;
29}
30
31void TRestDetectorHitsShuffleProcess::LoadDefaultConfig() {
32 SetName("hitsShuffleProcess");
33 SetTitle("Default config");
34
35 fIterations = 100;
36}
37
39 SetSectionName(this->ClassName());
40 SetLibraryVersion(LIBRARY_VERSION);
41
42 fHitsEvent = nullptr;
43
44 fRandom = nullptr;
45}
46
47void TRestDetectorHitsShuffleProcess::LoadConfig(const string& configFilename, const string& name) {
48 if (LoadConfigFromFile(configFilename, name) == -1) LoadDefaultConfig();
49}
50
52
54 fHitsEvent = (TRestDetectorHitsEvent*)inputEvent;
55
56 TRestHits* hits = fHitsEvent->GetHits();
57
58 Int_t nHits = hits->GetNumberOfHits();
59 if (nHits >= 2) {
60 for (int n = 0; n < fIterations; n++) {
61 Int_t hit1 = (Int_t)(nHits * fRandom->Uniform(0, 1));
62 Int_t hit2 = (Int_t)(nHits * fRandom->Uniform(0, 1));
63
64 hits->SwapHits(hit1, hit2);
65 }
66 }
67 return fHitsEvent;
68}
69
71
73 fIterations = StringToInteger(GetParameter("iterations"));
74 fRandom = new TRandom3(StringToDouble(GetParameter("seed", "0")));
75}
void InitProcess() override
To be executed at the beginning of the run (outside event loop)
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)
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
Process one event.
void Initialize() override
Making default settings.
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 SwapHits(Int_t i, Int_t j)
It exchanges hits n and m affecting to the ordering of the hits inside the list of hits.
Definition: TRestHits.cxx:478
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.
Int_t StringToInteger(std::string in)
Gets an integer from a string.