GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TAnalysisOptions.cxx
Go to the documentation of this file.
1#include "TAnalysisOptions.h"
2
3#include <algorithm>
4#include <cctype>
5#include <iostream>
6
7#include "TEnv.h"
8#include "TKey.h"
9
10#include "Globals.h"
11#include "DynamicLibrary.h"
12#include "TGRSIUtilities.h"
13#include "GRootCommands.h"
14
16{
17 /// Clears all of the variables in the TAnalysisOptions
18 fBuildWindow = 2000;
20 fAddbackWindow = 300;
21 fSuppressionWindow = 300.;
23 fStaticWindow = false;
24 fWaveformFitting = false;
26}
27
28void TAnalysisOptions::Print(Option_t*) const
29{
30 /// Print the current status of TAnalysisOptions, includes all names, lists and flags
31 std::cout << BLUE << "fBuildWindow: " << DCYAN << fBuildWindow << std::endl
32 << BLUE << "fBuildEventsByTimeStamp: " << DCYAN << fBuildEventsByTimeStamp << std::endl
33 << BLUE << "fAddbackWindow: " << DCYAN << fAddbackWindow << std::endl
34 << BLUE << "fSuppressionWindow: " << DCYAN << fSuppressionWindow << std::endl
35 << BLUE << "fSuppressionEnergy: " << DCYAN << fSuppressionEnergy << std::endl
36 << BLUE << "fStaticWindow: " << DCYAN << fStaticWindow << std::endl
37 << BLUE << "fWaveformFitting: " << DCYAN << fWaveformFitting << std::endl
38 << BLUE << "fIsCorrectingCrossTalk: " << DCYAN << fIsCorrectingCrossTalk << std::endl
39 << RESET_COLOR << std::endl;
40}
41
42bool TAnalysisOptions::WriteToFile(const std::string& fileName)
43{
44 TFile file(fileName.c_str(), "update");
45 if(file.IsOpen()) {
46 return WriteToFile(&file);
47 }
48 std::cout << R"(Failed to open file ")" << fileName << R"(" in update mode!)" << std::endl;
49 return false;
50}
51
53{
54 /// Writes options information to the root file
55 // Maintain old gDirectory info
56 bool success = true;
57 TDirectory* oldDir = gDirectory;
58
59 // if no file was provided, try to use the current file
60 if(file == nullptr) {
61 file = gDirectory->GetFile();
62 }
63 // check if we got a file
64 if(file == nullptr) {
65 std::cout << "Error, no file provided and no file open (gDirectory = " << gDirectory->GetName() << ")!" << std::endl;
66 return !success;
67 }
68
69 file->cd();
70 std::string oldoption = std::string(file->GetOption());
71 if(oldoption == "READ") {
72 file->ReOpen("UPDATE");
73 }
74
75 // check again that we have a directory to write to
76 if(!gDirectory) { // we don't compare to nullptr here, as ROOT >= 6.24.00 uses the TDirectoryAtomicAdapter structure with a bool() operator
77 std::cout << "No file opened to write TAnalysisOptions to." << std::endl;
78 return !success;
79 }
80 // write analysis options
81 std::cout << "Writing TAnalysisOptions to " << gDirectory->GetFile()->GetName() << std::endl;
82 Write("AnalysisOptions", TObject::kOverwrite);
83
84 // check if we need to change back to read mode
85 if(oldoption == "READ") {
86 std::cout << " Returning " << gDirectory->GetFile()->GetName() << " to \"" << oldoption.c_str() << "\" mode." << std::endl;
87 file->ReOpen("READ");
88 }
89
90 // go back to original gDirectory
91 oldDir->cd();
92
93 return success;
94}
95
96void TAnalysisOptions::ReadFromFile(const std::string& fileName)
97{
98 TFile file(fileName.c_str(), "read");
99 if(file.IsOpen()) {
100 return ReadFromFile(&file);
101 }
102 std::cout << R"(Failed to open file ")" << fileName << R"(" in read mode!)" << std::endl;
103}
104
106{
107 TDirectory* oldDir = gDirectory;
108 if(file != nullptr && file->IsOpen()) {
109 TList* list = file->GetListOfKeys();
110 TIter iter(list);
111 while(TKey* key = static_cast<TKey*>(iter.Next())) {
112 if((key == nullptr) || (strcmp(key->GetClassName(), "TAnalysisOptions") != 0)) {
113 continue;
114 }
115
116 *this = *static_cast<TAnalysisOptions*>(key->ReadObj());
117 oldDir->cd();
118 return;
119 }
120 std::cout << R"(Failed to find analysis options in file ")" << CYAN << file->GetName() << RESET_COLOR << R"(":)" << std::endl;
121 } else {
122 std::cout << R"(File ")" << file << R"(" is null or not open)" << std::endl;
123 }
124 oldDir->cd();
125}
126
127void TAnalysisOptions::SetCorrectCrossTalk(const bool& flag, Option_t* opt)
128{
130 TString opt1 = opt;
131 opt1.ToUpper();
132 if(opt1.Contains("Q")) {
133 return;
134 }
135
136 std::cout << "Please call TDetector::ResetFlags() on current event to avoid bugs" << std::endl;
137}
#define BLUE
Definition Globals.h:6
#define DCYAN
Definition Globals.h:21
#define CYAN
Definition Globals.h:12
#define RESET_COLOR
Definition Globals.h:5
void Write(const std::shared_ptr< TMidasEvent > &evt, TMidasFile *outfile)
bool fIsCorrectingCrossTalk
True if we are correcting for cross-talk in GRIFFIN at analysis-level.
void SetCorrectCrossTalk(const bool &flag, Option_t *opt="")
bool WriteToFile(const std::string &file)
double fSuppressionEnergy
Minimum energy used to suppress Ge-Events. (default = 0 keV)
int64_t fBuildWindow
if building with a window(GRIFFIN) this is the size of the window. (default = 2us (2000))
void Print(Option_t *opt="") const override
double fSuppressionWindow
Time used to suppress Ge-Events. (default = 300 ns (300))
void Clear(Option_t *opt="") override
bool fBuildEventsByTimeStamp
use time stamps instead of time (including CFD) to build events
double fAddbackWindow
Time used to build Addback-Ge-Events for TIGRESS/GRIFFIN. (default = 300 ns (300))
bool fWaveformFitting
If true, waveform fitting with SFU algorithm will be performed.
void ReadFromFile(const std::string &file)
bool fStaticWindow
Flag to use static window (default moving)