BOSS 6.6.4.p03
BESIII Offline Software System
Loading...
Searching...
No Matches
convElec2root.cxx
Go to the documentation of this file.
1//=====================================================
2// this script is used to convert result in text file//
3// to root files. it is based on files named that start
4// by "calib_barrel" .it means thest result from barrel. //
5//=====================================================
6#include "TTree.h"
7#include "TFile.h"
8#include <assert.h>
9#include <iostream>
10#include <fstream>
11using namespace std;
13 TTree* t1=new TTree("QElecBarParEast","barrel parameters of east end");
14 TTree* t2=new TTree("QElecBarParWest","barrel parameters of west end");
15 TTree* t3=new TTree("BarBoardNum","barrel electronics number");
16 double p1[11]={0.};
17 double p2[11]={0.};
18 char brname[50]; //branch name
19 char ptname[50]; //pattern name
20 for(int i=0;i<11;i++){
21 sprintf(brname,"P%d",i);
22 sprintf(ptname,"p%d/D",i);
23 t1->Branch(brname,&p1[i],ptname);
24 t2->Branch(brname,&p2[i],ptname);
25 }
26
27 double num[4]={0.};
28 sprintf(brname,"Board");
29 sprintf(ptname,"board/D");
30 t3->Branch(brname,&num[0],ptname);
31 sprintf(brname,"Crate");
32 sprintf(ptname,"crate/D");
33 t3->Branch(brname,&num[1],ptname);
34 sprintf(brname,"Fee");
35 sprintf(ptname,"fee/D");
36 t3->Branch(brname,&num[2],ptname);
37 sprintf(brname,"Channel");
38 sprintf(ptname,"channel/D");
39 t3->Branch(brname,&num[3],ptname);
40
41 const unsigned int N = 2;
42 bool is_open[N]={false};
43 ifstream infile[N];
44 char inTxtFile[N][500]={"ElecBarEast.txt","ElecBarWest.txt"};
45 for(int m=0;m<N;m++){
46 infile[m].open(inTxtFile[m],ios::in);
47 if(infile[m].good())
48 is_open[m]=true;
49 else
50 std::cerr<<"file: "<<inTxtFile[N]<<" can't be found!"<<std::endl;
51 }
52 try{
53 for(int k=0;k<176;k++){
54 //------------set p-------------------------
55 if(is_open[0]){
56 for( unsigned int j=0; j<4; j++ ) {
57 infile[0] >> num[j];
58 }
59 for( unsigned int j=0; j<9; j++ ) {
60 infile[0] >> p1[j];
61 }
62 }
63 t1->Fill();
64 t3->Fill();
65 if(is_open[1]){
66 for( unsigned int j=0; j<4; j++ ) {
67 infile[1] >> num[j];
68 }
69 for( unsigned int j=0; j<9; j++ ) {
70 infile[1] >> p2[j];
71 }
72 }
73 t2->Fill();
74 t3->Fill();
75 }
76 }
77 catch(...) {
78 return false;
79 }
80
81 TFile f("BarTofQElecPar.root","RECREATE");
82 t1->Write();
83 t2->Write();
84 t3->Write();
85 f.Close();
86 delete t1;
87 delete t2;
88 delete t3;
89 t1=NULL;
90 t2=NULL;
91 t3=NULL;
92 return true;
93}
94
96 TTree* t1=new TTree("QElecEndPar","endcap parameters of east end");
97 TTree* t2=new TTree("EndBoardNum","endcap electronics number");
98 double p[11]={0.};
99 char brname[50]; //branch name
100 char ptname[50]; //pattern name
101 for(int i=0;i<11;i++){
102 sprintf(brname,"P%d",i);
103 sprintf(ptname,"p%d/D",i);
104 t1->Branch(brname,&p[i],ptname);
105 }
106
107 double num[4]={0.};
108 sprintf(brname,"Board");
109 sprintf(ptname,"board/D");
110 t2->Branch(brname,&num[0],ptname);
111 sprintf(brname,"Crate");
112 sprintf(ptname,"crate/D");
113 t2->Branch(brname,&num[1],ptname);
114 sprintf(brname,"Fee");
115 sprintf(ptname,"fee/D");
116 t2->Branch(brname,&num[2],ptname);
117 sprintf(brname,"Channel");
118 sprintf(ptname,"channel/D");
119 t2->Branch(brname,&num[3],ptname);
120
121 bool is_open=false;
122 ifstream infile;
123 char inTxtFile[500]="ElecEndcap.txt";
124 infile.open(inTxtFile,ios::in);
125 if(infile.good())
126 is_open=true;
127 else
128 std::cerr<<"file: "<<inTxtFile<<" can't be found!"<<std::endl;
129 try{
130 for(int k=0;k<96;k++){
131 //------------set p-------------------------
132 if(is_open){
133 for( unsigned int j=0; j<4; j++ ) {
134 infile >> num[j];
135 }
136 for( unsigned int j=0; j<9; j++ ) {
137 infile >> p[j];
138 }
139 }
140 t1->Fill();
141 t2->Fill();
142 }
143 }
144 catch(...) {
145 return false;
146 }
147
148 TFile f("EndTofQElecPar.root","RECREATE");
149 t1->Write();
150 t2->Write();
151 f.Close();
152 delete t1;
153 delete t2;
154 t1=NULL;
155 t2=NULL;
156 return true;
157}
158
159
161 TTree* t1=new TTree("SimQElecBarParEast","barrel parameters of east end");
162 TTree* t2=new TTree("SimQElecBarParWest","barrel parameters of west end");
163 double p1[11]={0.};
164 double p2[11]={0.};
165 char brname[50]; //branch name
166 char ptname[50]; //pattern name
167 for(int i=0;i<11;i++){
168 sprintf(brname,"P%d",i);
169 sprintf(ptname,"p%d/D",i);
170 t1->Branch(brname,&p1[i],ptname);
171 t2->Branch(brname,&p2[i],ptname);
172 }
173
174 const unsigned int N = 2;
175 bool is_open[N]={false};
176 ifstream infile[N];
177 char inTxtFile[N][500]={"ElecBarEast-Curve.txt","ElecBarWest-Curve.txt"};
178 for(int m=0;m<N;m++){
179 infile[m].open(inTxtFile[m],ios::in);
180 if(infile[m].good())
181 is_open[m]=true;
182 else
183 std::cerr<<"file: "<<inTxtFile[N]<<" can't be found!"<<std::endl;
184 }
185 try{
186 for(int k=0;k<176;k++){
187 //------------set p-------------------------
188 if(is_open[0]){
189 for( unsigned int j=0; j<11; j++ ) {
190 infile[0] >> p1[j];
191 }
192 }
193 if(is_open[1]){
194 for( unsigned int j=0; j<11; j++ ) {
195 infile[1] >> p2[j];
196 }
197 }
198 t1->Fill();
199 t2->Fill();
200 }
201 }
202 catch(...) {
203 return false;
204 }
205
206 TFile f("SimBarTofQElecPar.root","RECREATE");
207 t1->Write();
208 t2->Write();
209 f.Close();
210 delete t1;
211 delete t2;
212 t1=NULL;
213 t2=NULL;
214 return true;
215}
216
218 TTree* t=new TTree("SimQElecEndPar","endcap parameters of east end");
219 double p[11]={0.};
220 char brname[50]; //branch name
221 char ptname[50]; //pattern name
222 for(int i=0;i<11;i++){
223 sprintf(brname,"P%d",i);
224 sprintf(ptname,"p%d/D",i);
225 t->Branch(brname,&p[i],ptname);
226 }
227
228 bool is_open=false;
229 ifstream infile;
230 char inTxtFile[500]="ElecEndcap-Curve.txt";
231 infile.open(inTxtFile,ios::in);
232 if(infile.good())
233 is_open=true;
234 else
235 std::cerr<<"file: "<<inTxtFile<<" can't be found!"<<std::endl;
236 try{
237 for(int k=0;k<96;k++){
238 //------------set p-------------------------
239 if(is_open){
240 for( unsigned int j=0; j<11; j++ ) {
241 infile >> p[j];
242 }
243 }
244 t->Fill();
245 }
246 }
247 catch(...) {
248 return false;
249 }
250
251 TFile f("SimEndTofQElecPar.root","RECREATE");
252 t->Write();
253 f.Close();
254 delete t;
255 t=NULL;
256 return true;
257}
258
259
260bool join() {
261 TFile f1("EndTofQElecPar.root");
262 TTree* t11=(TTree*)f1.Get("QElecEndPar");
263 if(0==t11) { std::cerr<<" can't get tree :QElecEndPar in file EndTofQElecPar.root"<<std::endl; return false;}
264 TTree* t12=(TTree*)f1.Get("EndBoardNum");
265 if(0==t12) { std::cerr<<" can't get tree :EndBoardNum in file EndTofQElecPar.root"<<std::endl; return false;}
266
267 TFile f2("BarTofQElecPar.root");
268 TTree* t21=(TTree*)f2.Get("QElecBarParEast");
269 if(0==t21) { std::cerr<<" can't get tree :QElecBarParEast in file BarTofQElecPar.root"<<std::endl; return false;}
270 TTree* t22=(TTree*)f2.Get("QElecBarParWest");
271 if(0==t22) { std::cerr<<" can't get tree :QElecBarParWest in file BarTofQElecPar.root"<<std::endl; return false;}
272 TTree* t23=(TTree*)f2.Get("BarBoardNum");
273 if(0==t23) { std::cerr<<" can't get tree :BarBoardNum in file BarTofQElecPar.root"<<std::endl; return false;}
274
275 TFile f3("SimEndTofQElecPar.root");
276 TTree* t31=(TTree*)f3.Get("SimQElecEndPar");
277 if(0==t31) { std::cerr<<" can't get tree :SimQElecEndPar in file SimEndTofQElecPar.root"<<std::endl; return false;}
278
279 TFile f4("SimBarTofQElecPar.root");
280 TTree* t41=(TTree*)f4.Get("SimQElecBarParEast");
281 if(0==t41) { std::cerr<<" can't get tree :SimQElecBarParEast in file SimBarTofQElecPar.root"<<std::endl; return false;}
282 TTree* t42=(TTree*)f4.Get("SimQElecBarParWest");
283 if(0==t42) { std::cerr<<" can't get tree :SimQElecBarParWest in file SimBarTofQElecPar.root"<<std::endl; return false;}
284
285 TFile fnew("TofQElecConst.root","RECREATE");
286 t11->Write();
287 t12->Write();
288 t21->Write();
289 t22->Write();
290 t23->Write();
291 t31->Write();
292 t41->Write();
293 t42->Write();
294 f1.Close();
295 f2.Close();
296 f3.Close();
297 f4.Close();
298 fnew.Close();
299 t11=NULL;
300 t12=NULL;
301 t21=NULL;
302 t22=NULL;
303 t23=NULL;
304 t31=NULL;
305 t41=NULL;
306 t42=NULL;
307 return true;
308}
309
310bool main() {
315 join();
316}
TFile * f1
bool join()
bool sim_endcap_conv2root()
bool sim_barrel_conv2root()
bool endcap_conv2root()
bool main()
bool barrel_conv2root()
int num[96]
Definition: ranlxd.c:373
int t()
Definition: t.c:1