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