MIDAS
Loading...
Searching...
No Matches
rmidas.h
Go to the documentation of this file.
1/********************************************************************\
2
3 Name: RMIDAS.H
4 Created by: Stefan Ritt & Konstantin Olchanski
5
6 Contents: ROOT definitions for MIDAS applications
7
8\********************************************************************/
9
10#ifndef _RMIDAS_H_
11#define _RMIDAS_H_
12
13#include <TObjArray.h>
14#include <TFolder.h>
15#include <TCutG.h>
16
17/* root functions really are C++ functions */ extern TFolder *gManaHistosFolder;
19
20// book functions put a root object in a suitable folder
21// for histos, there are a lot of types, so we use templates.
22// for other objects we have one function per object
23template < typename TH1X >
24TH1X EXPRT * h1_book(const char *name, const char *title,
25 int bins, double min, double max)
26{
27 TH1X *hist;
28
29 /* check if histo already exists */
30 if (!gHistoFolderStack->Last())
31 hist = (TH1X *) gManaHistosFolder->FindObjectAny(name);
32 else
34
35 if (hist == NULL) {
36 hist = new TH1X(name, title, bins, min, max);
37 if (!gHistoFolderStack->Last())
39 else
40 ((TFolder *) gHistoFolderStack->Last())->Add(hist);
41 }
42
43 return hist;
44}
45
46template < typename TH1X >
47TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double edges[])
48{
49 TH1X *hist;
50
51 /* check if histo already exists */
52 if (!gHistoFolderStack->Last())
53 hist = (TH1X *) gManaHistosFolder->FindObjectAny(name);
54 else
56
57 if (hist == NULL) {
58 hist = new TH1X(name, title, bins, edges);
59 if (!gHistoFolderStack->Last())
61 else
62 ((TFolder *) gHistoFolderStack->Last())->Add(hist);
63 }
64
65 return hist;
66}
67
68template < typename TH2X >
69TH2X EXPRT * h2_book(const char *name, const char *title,
70 int xbins, double xmin, double xmax,
71 int ybins, double ymin, double ymax)
72{
73 TH2X *hist;
74
75 /* check if histo already exists */
76 if (!gHistoFolderStack->Last())
77 hist = (TH2X *) gManaHistosFolder->FindObjectAny(name);
78 else
80
81 if (hist == NULL) {
82 hist = new TH2X(name, title, xbins, xmin, xmax, ybins, ymin, ymax);
83 if (!gHistoFolderStack->Last())
85 else
86 ((TFolder *) gHistoFolderStack->Last())->Add(hist);
87 }
88
89 return hist;
90}
91
92template < typename TH2X >
93TH2X EXPRT * h2_book(const char *name, const char *title,
94 int xbins, double xmin, double xmax, int ybins, double yedges[])
95{
96 TH2X *hist;
97
98 /* check if histo already exists */
99 if (!gHistoFolderStack->Last())
100 hist = (TH2X *) gManaHistosFolder->FindObjectAny(name);
101 else
102 hist = (TH2X *) ((TFolder *) gHistoFolderStack->Last())->FindObjectAny(name);
103
104 if (hist == NULL) {
105 hist = new TH2X(name, title, xbins, xmin, xmax, ybins, yedges);
106 if (!gHistoFolderStack->Last())
108 else
109 ((TFolder *) gHistoFolderStack->Last())->Add(hist);
110 }
111
112 return hist;
113}
114
115template < typename TH2X >
116TH2X EXPRT * h2_book(const char *name, const char *title,
117 int xbins, double xedges[], int ybins, double ymin, double ymax)
118{
119 TH2X *hist;
120
121 /* check if histo already exists */
122 if (!gHistoFolderStack->Last())
123 hist = (TH2X *) gManaHistosFolder->FindObjectAny(name);
124 else
125 hist = (TH2X *) ((TFolder *) gHistoFolderStack->Last())->FindObjectAny(name);
126
127 if (hist == NULL) {
128 hist = new TH2X(name, title, xbins, xedges, ybins, ymin, ymax);
129 if (!gHistoFolderStack->Last())
131 else
132 ((TFolder *) gHistoFolderStack->Last())->Add(hist);
133 }
134
135 return hist;
136}
137
138template < typename TH2X >
139TH2X EXPRT * h2_book(const char *name, const char *title,
140 int xbins, double xedges[], int ybins, double yedges[])
141{
142 TH2X *hist;
143
144 /* check if histo already exists */
145 if (!gHistoFolderStack->Last())
146 hist = (TH2X *) gManaHistosFolder->FindObjectAny(name);
147 else
148 hist = (TH2X *) ((TFolder *) gHistoFolderStack->Last())->FindObjectAny(name);
149
150 if (hist == NULL) {
151 hist = new TH2X(name, title, xbins, xedges, ybins, yedges);
152 if (!gHistoFolderStack->Last())
154 else
155 ((TFolder *) gHistoFolderStack->Last())->Add(hist);
156 }
157
158 return hist;
159}
160
161/*
162 * the following two macros allow for simple fortran like usage
163 * for the most common histo types
164 */
165#define H1_BOOK(n,t,b,min,max) (h1_book<TH1F>(n,t,b,min,max))
166#define H2_BOOK(n,t,xb,xmin,xmax,yb,ymin,ymax) (h2_book<TH2F>(n,t,xb,xmin,xmax,yb,ymin,ymax))
167
168TCutG *cut_book(const char *name);
169
170#endif
#define EXPRT
Definition esone.h:28
#define name(x)
Definition midas_macro.h:24
TObjArray * gHistoFolderStack
TFolder * gManaHistosFolder
TH2X EXPRT * h2_book(const char *name, const char *title, int xbins, double xmin, double xmax, int ybins, double ymin, double ymax)
Definition rmidas.h:69
TCutG * cut_book(const char *name)
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24