GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TRuntimeObjects.cxx
Go to the documentation of this file.
1#include "TRuntimeObjects.h"
2
3#include <utility>
4
5#include "TCutG.h"
6#include "TFile.h"
7#include "TH1.h"
8#include "TH2.h"
9#include "TDirectoryFile.h"
10#include "TProfile.h"
11
12#include "GValue.h"
13
14std::map<std::string, TRuntimeObjects*> TRuntimeObjects::fRuntimeMap;
15
16TRuntimeObjects::TRuntimeObjects(std::shared_ptr<const TFragment> frag, TList* objects, TList* gates,
17 std::vector<TFile*>& cut_files, TDirectory* directory, const char* name)
18 : fFrag(std::move(frag)), fObjects(objects), fGates(gates), fCut_files(cut_files), fDirectory(directory)
19{
20 SetName(name);
21 fRuntimeMap.insert(std::make_pair(name, this));
22}
23
24TRuntimeObjects::TRuntimeObjects(TList* objects, TList* gates, std::vector<TFile*>& cut_files, TDirectory* directory,
25 const char* name)
26 : fFrag(nullptr), fObjects(objects), fGates(gates), fCut_files(cut_files), fDirectory(directory)
27{
28 SetName(name);
29 fRuntimeMap.insert(std::make_pair(name, this));
30}
31
32TH1* TRuntimeObjects::FillHistogram(const char* name, int bins, double low, double high, double value, double weight)
33{
34 FillHistogram("General", name, bins, low, high, value, weight);
35 return nullptr;
36}
37
38TH2* TRuntimeObjects::FillHistogram(const char* name, int Xbins, double Xlow, double Xhigh, double Xvalue, int Ybins, double Ylow, double Yhigh, double Yvalue, double weight)
39{
40 FillHistogram("General", name, Xbins, Xlow, Xhigh, Xvalue, Ybins, Ylow, Yhigh, Yvalue, weight);
41 return nullptr;
42}
43
44TProfile* TRuntimeObjects::FillProfileHist(const char* name, int Xbins, double Xlow, double Xhigh, double Xvalue, double Yvalue)
45{
46 FillProfileHist("General", name, Xbins, Xlow, Xhigh, Xvalue, Yvalue);
47 return nullptr;
48}
49
50TH2* TRuntimeObjects::FillHistogramSym(const char* name, int Xbins, double Xlow, double Xhigh, double Xvalue, int Ybins, double Ylow, double Yhigh, double Yvalue)
51{
52 FillHistogramSym("General", name, Xbins, Xlow, Xhigh, Xvalue, Ybins, Ylow, Yhigh, Yvalue);
53 return nullptr;
54}
55
56//-------------------------------------------------------------------------
57TDirectory* TRuntimeObjects::FillHistogram(const char* dirname, const char* name, int bins, double low, double high, double value, double weight)
58{
59 TDirectory* dir = FindDirectory(dirname);
60
61 auto* hist = static_cast<TH1*>(dir->FindObject(name));
62 if(hist == nullptr) {
63 hist = new TH1D(name, name, bins, low, high);
64 hist->SetDirectory(dir);
65 dir->Add(hist);
66 }
67
68 if(!std::isnan(value)) {
69 hist->Fill(value, weight);
70 }
71 return dir;
72}
73
74TDirectory* TRuntimeObjects::FillHistogram(const char* dirname, const char* name, int Xbins, double Xlow, double Xhigh,
75 double Xvalue, int Ybins, double Ylow, double Yhigh, double Yvalue,
76 double weight)
77{
78 TDirectory* dir = FindDirectory(dirname);
79 auto* hist = static_cast<TH2*>(dir->FindObject(name));
80 if(hist == nullptr) {
81 hist = new TH2D(name, name, Xbins, Xlow, Xhigh, Ybins, Ylow, Yhigh);
82 hist->SetDirectory(dir);
83 dir->Add(hist);
84 }
85
86 if(!std::isnan(Xvalue) && !std::isnan(Yvalue)) {
87 hist->Fill(Xvalue, Yvalue, weight);
88 }
89 return dir;
90}
91
92TDirectory* TRuntimeObjects::FillProfileHist(const char* dirname, const char* name, int Xbins, double Xlow,
93 double Xhigh, double Xvalue, double Yvalue)
94{
95
96 TDirectory* dir = FindDirectory(dirname);
97 auto* prof = static_cast<TProfile*>(dir->FindObject(name));
98 if(prof == nullptr) {
99 prof = new TProfile(name, name, Xbins, Xlow, Xhigh);
100 prof->SetDirectory(dir);
101 dir->Add(prof);
102 }
103
104 if(!(std::isnan(Xvalue))) {
105 if(!(std::isnan(Yvalue))) {
106 prof->Fill(Xvalue, Yvalue);
107 }
108 }
109 return dir;
110}
111
112TDirectory* TRuntimeObjects::FillHistogramSym(const char* dirname, const char* name, int Xbins, double Xlow,
113 double Xhigh, double Xvalue, int Ybins, double Ylow, double Yhigh,
114 double Yvalue)
115{
116 TDirectory* dir = FindDirectory(dirname);
117 auto* hist = static_cast<TH2*>(dir->FindObject(name));
118 if(hist == nullptr) {
119 hist = new TH2D(name, name, Xbins, Xlow, Xhigh, Ybins, Ylow, Yhigh);
120 hist->SetDirectory(dir);
121 dir->Add(hist);
122 }
123 if(!(std::isnan(Xvalue))) {
124 if(!(std::isnan(Yvalue))) {
125 hist->Fill(Xvalue, Yvalue);
126 hist->Fill(Yvalue, Xvalue);
127 }
128 }
129 return dir;
130}
131//-------------------------------------------------------------------------
132
134{
135 return *fObjects;
136}
137
139{
140 return *fGates;
141}
142
143TCutG* TRuntimeObjects::GetCut(const std::string& name)
144{
145 for(auto& tfile : fCut_files) {
146 TObject* obj = tfile->Get(name.c_str());
147 if(obj != nullptr) {
148 auto* cut = static_cast<TCutG*>(obj);
149 if(cut != nullptr) {
150 return cut;
151 }
152 }
153 }
154 return nullptr;
155}
156
157double TRuntimeObjects::GetVariable(const char* name) const
158{
159 return GValue::Value(name);
160}
161
162TDirectory* TRuntimeObjects::FindDirectory(const char* dirname)
163{
164 auto* dir = static_cast<TDirectory*>(GetObjects().FindObject(dirname));
165 if(dir == nullptr) {
166 dir = new TDirectory(dirname, dirname);
167 GetObjects().Add(dir);
168 }
169 return dir;
170}
TH1D * hist
Definition UserFillObj.h:3
static double Value(const std::string &)
Definition GValue.cxx:39
std::vector< TFile * > & fCut_files
TCutG * GetCut(const std::string &name)
TDirectory * FindDirectory(const char *)
TRuntimeObjects(std::shared_ptr< const TFragment > frag, TList *objects, TList *gates, std::vector< TFile * > &cut_files, TDirectory *directory=nullptr, const char *name="default")
Constructor.
double GetVariable(const char *name) const
static std::map< std::string, TRuntimeObjects * > fRuntimeMap
TH1 * FillHistogram(const char *name, int bins, double low, double high, double value, double weight=1)
TProfile * FillProfileHist(const char *name, int Xbins, double Xlow, double Xhigh, double Xvalue, double Yvalue)
TH2 * FillHistogramSym(const char *name, int Xbins, double Xlow, double Xhigh, double Xvalue, int Ybins, double Ylow, double Yhigh, double Yvalue)