BmnRoot
Loading...
Searching...
No Matches
BmnManageQA.cxx
Go to the documentation of this file.
1#include "BmnManageQA.h"
2
3#include <TDirectory.h>
4#include <TError.h>
5#include <TFile.h>
6
7std::vector<std::string> pathToList(const char* path);
8
9TH1F* CreateHistogram1(const char* name, const char* xtitle, int nbin, Float_t firstBin, Float_t lastBin)
10{
11 TH1F* h = new TH1F(name, name, nbin, firstBin, lastBin);
12 h->SetXTitle(xtitle);
13 return h;
14}
15
16TH2F* CreateHistogram2(const char* name,
17 const char* xtitle,
18 const char* ytitle,
19 int nbinx,
20 Float_t firstBinX,
21 Float_t lastBinX,
22 int nbiny,
23 Float_t firstBinY,
24 Float_t lastBinY)
25{
26 TH2F* h = new TH2F(name, name, nbinx, firstBinX, lastBinX, nbiny, firstBinY, lastBinY);
27 h->SetXTitle(xtitle);
28 h->SetYTitle(ytitle);
29 return h;
30}
31
32TH3F* CreateHistogram3(const char* name,
33 const char* xtitle,
34 const char* ytitle,
35 const char* ztitle,
36 int nbinx,
37 Float_t firstBinX,
38 Float_t lastBinX,
39 int nbiny,
40 Float_t firstBinY,
41 Float_t lastBinY,
42 int nbinz,
43 Float_t firstBinZ,
44 Float_t lastBinZ)
45{
46 TH3F* h = new TH3F(name, name, nbinx, firstBinX, lastBinX, nbiny, firstBinY, lastBinY, nbinz, firstBinZ, lastBinZ);
47 h->SetXTitle(xtitle);
48 h->SetYTitle(ytitle);
49 h->SetZTitle(ztitle);
50 return h;
51}
52
53// go to given directory if directory dose not exists create it
54
55void toDirectory(const char* dir)
56{
57 std::vector<std::string> splitedPath = pathToList(dir);
58 TDirectory* d = (TDirectory*)gFile;
59 for (size_t i = 0; i < splitedPath.size(); i++) {
60 TDirectory* nextDir = (TDirectory*)d->FindObject(splitedPath[i].c_str());
61 if (!nextDir) {
62 d->mkdir(splitedPath[i].c_str());
63 nextDir = (TDirectory*)d->GetDirectory(splitedPath[i].c_str());
64 }
65 if (!nextDir)
66 Error("QAHelpers::toDir", "Can't create/find directory");
67 d = nextDir;
68 }
69 gFile->cd(dir);
70}
71
72// split path for components using '/' as delimeter
73std::vector<std::string> pathToList(const char* path)
74{
75 std::vector<std::string> result;
76
77 const char* begin = path;
78 const char* index = path;
79
80 while (*index) {
81 for (; *index != 0 && *index != '/'; index++)
82 ;
83 if (begin != index)
84 result.push_back(std::string(begin, index - begin));
85 for (; *index != 0 && *index == '/'; index++)
86 ; // if several delimeters then skip them all
87 begin = index;
88 }
89 return result;
90}
91
92const TGeoShape* getShape(const TGeoManager* g, const char* name)
93{
94 if (!g) {
95 Error("getShape", "Geo Manager not initialized");
96 return 0;
97 }
98 TGeoVolume* vol = gGeoManager->GetVolume(name);
99 if (!vol) {
100 Error("getShape", "Volume %s not found", name);
101 return 0;
102 }
103
104 return vol->GetShape();
105}
106
107// Suffixed versions of CreateHistograms...
108
109TH1F* CreateHistogram1(const char* name,
110 const std::string& suffix,
111 const char* xtitle,
112 int nbin,
113 Float_t firstBin,
114 Float_t lastBin)
115{
116 std::string fullName = std::string(name) + suffix;
117 return CreateHistogram1(fullName.c_str(), xtitle, nbin, firstBin, lastBin);
118}
119TH2F* CreateHistogram2(const char* name,
120 const std::string& suffix,
121 const char* xtitle,
122 const char* ytitle,
123 int nbinx,
124 Float_t firstBinX,
125 Float_t lastBinX,
126 int nbiny,
127 Float_t firstBinY,
128 Float_t lastBinY)
129{
130 std::string fullName = std::string(name) + suffix;
131 return CreateHistogram2(fullName.c_str(), xtitle, ytitle, nbinx, firstBinX, lastBinX, nbiny, firstBinY, lastBinY);
132}
133TH3F* CreateHistogram3(const char* name,
134 const std::string& suffix,
135 const char* xtitle,
136 const char* ytitle,
137 const char* ztitle,
138 int nbinx,
139 Float_t firstBinX,
140 Float_t lastBinX,
141 int nbiny,
142 Float_t firstBinY,
143 Float_t lastBinY,
144 int nbinz,
145 Float_t firstBinZ,
146 Float_t lastBinZ)
147{
148 std::string fullName = std::string(name) + suffix;
149 return CreateHistogram3(fullName.c_str(), xtitle, ytitle, ztitle, nbinx, firstBinX, lastBinX, nbiny, firstBinY,
150 lastBinY, nbinz, firstBinZ, lastBinZ);
151}
void toDirectory(const char *dir)
TH3F * CreateHistogram3(const char *name, const char *xtitle, const char *ytitle, const char *ztitle, int nbinx, Float_t firstBinX, Float_t lastBinX, int nbiny, Float_t firstBinY, Float_t lastBinY, int nbinz, Float_t firstBinZ, Float_t lastBinZ)
std::vector< std::string > pathToList(const char *path)
const TGeoShape * getShape(const TGeoManager *g, const char *name)
TH2F * CreateHistogram2(const char *name, const char *xtitle, const char *ytitle, int nbinx, Float_t firstBinX, Float_t lastBinX, int nbiny, Float_t firstBinY, Float_t lastBinY)
TH1F * CreateHistogram1(const char *name, const char *xtitle, int nbin, Float_t firstBin, Float_t lastBin)
const Float_t d
Z-ccordinate of the first GEM-station.
Definition BmnMwpcHit.cxx:7
int i
Definition P4_F32vec4.h:22