Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
root2hbook.cc
Go to the documentation of this file.
1 
2 
3 #include <iostream>
4 #include <iomanip>
5 using namespace std;
6 
7 #include <TFile.h>
8 #include <TTree.h>
9 
10 #include "cern_c.h"
11 #define MEMH 8000000
12 #define LREC 1024 /* record length of hbook direct access file in WORDS */
13 #define LUN 3 /* logical unit number of hbook file */
14 extern "C" {
15  float pawc_[MEMH];
16  int quest_[100];
17 };
18 
19 
20 #define MAX_PARTS 50
21 
22 class event_t{
23  public:
24  int n;
25  float E[MAX_PARTS];
26  float px[MAX_PARTS];
27  float py[MAX_PARTS];
28  float pz[MAX_PARTS];
29  float neuETot;
30  int nGen;
31  float genE[MAX_PARTS];
32  float genPx[MAX_PARTS];
33  float genPy[MAX_PARTS];
34  float genPz[MAX_PARTS];
35  int type[MAX_PARTS];
36  float genNeuE;
37 };
38 
39 int main(int narg, char *argv[])
40 {
41  const char *fname ="primex_event.root";
42  if(narg>1)fname = argv[1];
43 
44  // Open ROOT file for input
45  TFile *f = new TFile(fname);
46  if(!f || !f->IsOpen()){
47  cerr<<"Unable to open file \""<<fname<<"\"!"<<endl;
48  return -1;
49  }
50  cout<<"Opened input file \""<<fname<<"\""<<endl;
51 
52  // Find TTree
53  TTree *tree = (TTree*)f->Get("event");
54  if(!tree){
55  cerr<<"Unable to find TTree \"event\" in ROOT file!"<<endl;
56  return -2;
57  }
58 
59  // Set up branches
60  event_t event;
61  tree->SetBranchAddress("n", &event.n);
62  tree->SetBranchAddress("E", &event.E);
63  tree->SetBranchAddress("px", &event.px);
64  tree->SetBranchAddress("py", &event.py);
65  tree->SetBranchAddress("pz", &event.pz);
66  tree->SetBranchAddress("neuETot", &event.neuETot);
67  tree->SetBranchAddress("nGen", &event.nGen);
68  tree->SetBranchAddress("genE", &event.genE);
69  tree->SetBranchAddress("genPx", &event.genPx);
70  tree->SetBranchAddress("genPy", &event.genPy);
71  tree->SetBranchAddress("genPz", &event.genPz);
72  tree->SetBranchAddress("type", &event.type);
73  tree->SetBranchAddress("genNeuE", &event.genNeuE);
74 
75  // Initialize cernlib (monkey shines!)
76  quest_[9] = 65000;
77  int memh = MEMH;
78  hlimit(memh);
79 
80  // Open HBOOK file for writing
81  hropen(LUN, "lun", "primex_event.hbook" , "N", LREC, 0);
82 
83  // Create Ntuple
84  hbnt(10,"event","");
85  char ntp_str[256];
86  sprintf(ntp_str, "n[0,%d]:I,E(n):R,px(n),py(n),pz(n),neuETot,nGen[0,%d]:I,genE(nGen):R,genPx(nGen),genPy(nGen),genPz(nGen),type(nGen):I,genNeuE:R", MAX_PARTS, MAX_PARTS);
87  cout<<ntp_str<<endl;
88  hbname(10,"EVNT", &event.n, ntp_str);
89 
90  // Loop over entries in ROOT file
91  int Nevents = tree->GetEntries();
92  for(int i=1; i<=Nevents; i++){
93  // Read in event
94  tree->GetEntry(i);
95 
96  // Write event to Ntuple
97  hfnt(10);
98 
99  // Update ticker
100  if(i%100 == 0)cout<<" "<<i<<" events processed \r";
101  }
102 
103  cout<<endl;
104  cout<<Nevents<<" events processed total."<<endl;
105 
106  // Close hbook file
107  int icycle=0;
108  hrout(0,icycle,"T");
109  hrend("lun");
110 
111  // Close ROOT file
112  f->Close();
113 
114  return 0;
115 }
116 
117 
118 #if 0
119 ******************************************************************************
120 *Tree :event : Event Reconstruction *
121 *Entries : 10000 : Total = 1882594 bytes File Size = 1363534 *
122 * : : Tree compression factor = 1.37 *
123 ******************************************************************************
124 *Br 0 :n : n/I *
125 *Entries : 10000 : Total Size= 40677 bytes File Size = 4586 *
126 *Baskets : 1 : Basket Size= 32000 bytes Compression= 6.98 *
127 *............................................................................*
128 *Br 1 :E : E[n]/F *
129 *Entries : 10000 : Total Size= 228491 bytes File Size = 183329 *
130 *Baskets : 8 : Basket Size= 32000 bytes Compression= 1.19 *
131 *............................................................................*
132 *Br 2 :px : px[n]/F *
133 *Entries : 10000 : Total Size= 228505 bytes File Size = 187776 *
134 *Baskets : 8 : Basket Size= 32000 bytes Compression= 1.16 *
135 *............................................................................*
136 *Br 3 :py : py[n]/F *
137 *Entries : 10000 : Total Size= 228505 bytes File Size = 187842 *
138 *Baskets : 8 : Basket Size= 32000 bytes Compression= 1.16 *
139 *............................................................................*
140 *Br 4 :pz : pz[n]/F *
141 *Entries : 10000 : Total Size= 228505 bytes File Size = 184061 *
142 *Baskets : 8 : Basket Size= 32000 bytes Compression= 1.18 *
143 *............................................................................*
144 *Br 5 :neuETot : neuETot/F *
145 *Entries : 10000 : Total Size= 40719 bytes File Size = 26283 *
146 *Baskets : 1 : Basket Size= 32000 bytes Compression= 1.22 *
147 *............................................................................*
148 *Br 6 :nGen : nGen/I *
149 *Entries : 10000 : Total Size= 40698 bytes File Size = 263 *
150 *Baskets : 1 : Basket Size= 32000 bytes Compression= 121.66 *
151 *............................................................................*
152 *Br 7 :genE : genE[nGen]/F *
153 *Entries : 10000 : Total Size= 161217 bytes File Size = 118567 *
154 *Baskets : 6 : Basket Size= 32000 bytes Compression= 1.30 *
155 *............................................................................*
156 *Br 8 :genPx : genPx[nGen]/F *
157 *Entries : 10000 : Total Size= 161229 bytes File Size = 122566 *
158 *Baskets : 6 : Basket Size= 32000 bytes Compression= 1.25 *
159 *............................................................................*
160 *Br 9 :genPy : genPy[nGen]/F *
161 *Entries : 10000 : Total Size= 161229 bytes File Size = 122616 *
162 *Baskets : 6 : Basket Size= 32000 bytes Compression= 1.25 *
163 *............................................................................*
164 *Br 10 :genPz : genPz[nGen]/F *
165 *Entries : 10000 : Total Size= 161229 bytes File Size = 118466 *
166 *Baskets : 6 : Basket Size= 32000 bytes Compression= 1.30 *
167 *............................................................................*
168 *Br 11 :type : type[nGen]/I *
169 *Entries : 10000 : Total Size= 161210 bytes File Size = 14124 *
170 *Baskets : 6 : Basket Size= 32000 bytes Compression= 10.88 *
171 *............................................................................*
172 *Br 12 :genNeuE : genNeuE/F *
173 *Entries : 10000 : Total Size= 40719 bytes File Size = 20990 *
174 *Baskets : 1 : Basket Size= 32000 bytes Compression= 1.52 *
175 *............................................................................*
176 root [3]
177 #endif
178 
179 
#define F(x, y, z)
void hbname(int id, const char *CHBLOK, void *VAR, const char *CHFORM)
float neuETot
Definition: root2hbook.cc:29
float py[MAX_PARTS]
Definition: root2hbook.cc:27
void hropen(int lun, char *name, char *filename, char *status, int stor, int istat)
float E[MAX_PARTS]
Definition: root2hbook.cc:25
void hfnt(int id)
void hlimit(int size)
sprintf(text,"Post KinFit Cut")
float genNeuE
Definition: root2hbook.cc:36
#define LUN
Definition: root2hbook.cc:13
void hbnt(int id, char *CHTITL, char *CHOPT)
int quest_[100]
TF1 * f
Definition: FitGains.C:21
#define LREC
Definition: root2hbook.cc:12
float genPx[MAX_PARTS]
Definition: root2hbook.cc:32
#define MEMH
Definition: root2hbook.cc:11
void hrout(int num, int icycle, char *opt)
float pawc_[MEMH]
void hrend(char *filename)
TH1D * py[NCHANNELS]
float genPy[MAX_PARTS]
Definition: root2hbook.cc:33
float genE[MAX_PARTS]
Definition: root2hbook.cc:31
int type[MAX_PARTS]
Definition: root2hbook.cc:35
double Nevents
float pz[MAX_PARTS]
Definition: root2hbook.cc:28
float px[MAX_PARTS]
Definition: root2hbook.cc:26
int nGen
Definition: root2hbook.cc:30
float genPz[MAX_PARTS]
Definition: root2hbook.cc:34
#define MAX_PARTS
Definition: root2hbook.cc:20
#define I(x, y, z)
int main(int argc, char *argv[])
Definition: gendoc.cc:6