BOSS 7.0.3
BESIII Offline Software System
Loading...
Searching...
No Matches
convert2simroot.cxx File Reference
#include "TTree.h"
#include "TFile.h"
#include <assert.h>
#include <iostream>
#include <fstream>

Go to the source code of this file.

Functions

bool sim_conv2root ()
 
bool barrel_conv2root ()
 
bool endcap_conv2root ()
 
bool join ()
 
int main ()
 

Function Documentation

◆ barrel_conv2root()

bool barrel_conv2root ( )

Definition at line 59 of file convert2simroot.cxx.

59 {
60 double gain=0.0, ratio=0.0, length=1.0;
61 TTree* t=new TTree("BTofSim","barrel attenuation length and gain");
62 t->Branch("Gain", &gain, "Gain/D");
63 t->Branch("Ratio", &ratio, "Ratio/D");
64 t->Branch("AttenLength", &length, "AttenLength/D");
65
66 double a1overa2 = 1.0, a2 = 1.0;
67 double qmean = 0.0, qsigma = 0.0;
68 ifstream inf1, inf2;
69 bool is_open1=false, is_open2=false;
70 const char* file1="calib_barrel_atten.txt";
71 const char* file2="calib_barrel_q0.txt";
72 inf1.open(file1,ios::in);
73 inf2.open(file2,ios::in);
74 if( inf1.good() ) {
75 is_open1=true;
76 }
77 else {
78 std::cerr<<"file: "<<file1 <<" can't be found!"<<std::endl;
79 }
80 if( inf2.good() ) {
81 is_open2=true;
82 }
83 else {
84 std::cerr<<"file: "<<file2 <<" can't be found!"<<std::endl;
85 }
86
87 try{
88 if( is_open1 && is_open2 ) {
89 for( unsigned int i=0; i<176; i++ ) {
90 inf1 >> length >> ratio;
91 if( fabs(length)<1.0e-6 ) { length = 1.0; }
92 length = 1.0/length;
93
94 inf2 >> gain >> qmean >> qsigma;
95
96 t->Fill();
97 }
98 }
99 } catch(...) {
100 return false;
101 }
102
103 inf1.close();
104 inf2.close();
105
106 TFile f("BarTofSim.root","RECREATE");
107 t->Write();
108 f.Close();
109 delete t;
110 t=NULL;
111
112 return true;
113}
int t()
Definition: t.c:1

Referenced by main().

◆ endcap_conv2root()

bool endcap_conv2root ( )

Definition at line 115 of file convert2simroot.cxx.

115 {
116 double gain=0.0, length=1.0, noisesmear=0.;
117 double scin, mean, errmean, sigma, errsigma;
118 double mc_sigma;
119 TTree* t=new TTree("ETofSim","endcap attenuation length and gain");
120 t->Branch("Gain", &gain, "Gain/D" );
121 t->Branch("AttenLength", &length, "AttenLength/D");
122 t->Branch("NoiseSmear", &noisesmear,"NoiseSmear/D" );
123
124 double length2=1.0;
125 ifstream inf1, inf2, inf3;
126 bool is_open1=false, is_open2=false, is_open3=false;
127 const char* file1="calib_endcap_atten.txt";
128 const char* file2="tEndRes.txt";
129 const char* file3="Endcap_mc_tEndRes.txt";
130 inf1.open(file1,ios::in);
131 inf2.open(file2,ios::in);
132 inf3.open(file3,ios::in);
133 if(inf1.good())
134 is_open1=true;
135 else{
136 std::cerr<<"File: "<<file1<<" can't be opened"<<std::endl;
137 }
138 if(inf2.good())
139 is_open2=true;
140 else{
141 std::cerr<<"File: "<<file2<<" can't be opened"<<std::endl;
142 }
143 if(inf3.good())
144 is_open3=true;
145 else{
146 std::cerr<<"File: "<<file3<<" can't be opened"<<std::endl;
147 }
148 try{
149 if( is_open1 && is_open2 && is_open3) {
150 for(int i=0;i<96;i++) {
151 inf1 >> gain >> length >> length2;
152 inf2 >> scin >> mean >> errmean >> sigma >> errsigma;
153 inf3 >> mc_sigma;
154 if ( mc_sigma > sigma ) {noisesmear = 0.;}
155 else { noisesmear = sqrt(sigma*sigma - mc_sigma*mc_sigma);}
156 t->Fill();
157 }
158 }
159 } catch(...){
160 return false;
161 }
162
163 inf1.close();
164 inf2.close();
165 inf3.close();
166
167 TFile f("EndTofSim.root","RECREATE");
168 t->Write();
169 f.Close();
170 delete t;
171 t=NULL;
172
173 return true;
174}

Referenced by main().

◆ join()

bool join ( )

Definition at line 176 of file convert2simroot.cxx.

176 {
177
178 TFile f1("TofSimConst.root");
179 TTree* t1=(TTree*)f1.Get("SimConstants");
180 if(0==t1) { std::cerr<<" can't get tree :SimConstants in file TofSimConst.root"<<std::endl; return false;}
181 TFile f2("BarTofSim.root");
182 TTree* t2=(TTree*)f2.Get("BTofSim");
183 if(0==t2) { std::cerr<<" can't get tree :BTofSim in file BarTofSim.root"<<std::endl; return false;}
184 TFile f3("EndTofSim.root");
185 TTree* t3=(TTree*)f3.Get("ETofSim");
186 if(0==t3) { std::cerr<<" can't get tree :ETofSim in file EndTofSim.root"<<std::endl; return false;}
187
188 TFile fnew("TofSimConst.root","RECREATE");
189 t1->Write();
190 t2->Write();
191 t3->Write();
192 f1.Close();
193 f2.Close();
194 f3.Close();
195 fnew.Close();
196 t1=NULL;
197 t2=NULL;
198 t3=NULL;
199
200 return true;
201}
TFile * f1

Referenced by main().

◆ main()

int main ( )

Definition at line 203 of file convert2simroot.cxx.

203 {
207 join();
208}
bool join()
bool endcap_conv2root()
bool sim_conv2root()
bool barrel_conv2root()

◆ sim_conv2root()

bool sim_conv2root ( )

Definition at line 11 of file convert2simroot.cxx.

11 {
12 TTree* t=new TTree("SimConstants","threshold and gain constants");
13 double blth=50., bhth=50., elth=50., ehth=50.;
14 double bgain=5.E5, egain=2.5E5;
15 double bconst=1.0, econst=1.0;
16 double eswitch=0;//swtich for endcap noise sim: 0-no sigma smear ; 1-only add smear in east endcap sim; 2-add smear in both east and west endcap sim;
17 t->Branch("BarLowThres", &blth, "BarLowThres/D" );
18 t->Branch("BarHighThres", &bhth, "BarHighThres/D");
19 t->Branch("EndLowThres", &elth, "EndLowThres/D" );
20 t->Branch("EndHighThres", &ehth, "EndHighThres/D");
21 t->Branch("BarPMTGain", &bgain, "BarPMTGain/D" );
22 t->Branch("EndPMTGain", &egain, "EndPMTGain/D" );
23 t->Branch("BarConstant", &bconst, "BarConst/D" );
24 t->Branch("EndConstant", &econst, "EndConst/D" );
25 t->Branch("EndNoiseSwitch",&eswitch, "EndNoiseSwitch/D" );
26
27 ifstream inf;
28 bool is_open=false;
29 const char* file="SimConstants.txt";
30 inf.open(file,ios::in);
31 if( inf.good() ) {
32 is_open=true;
33 }
34 else {
35 std::cerr<<"file: "<<file <<" can't be found!"<<std::endl;
36 }
37 try{
38 if( is_open ){
39 inf >> blth >> bhth;
40 inf >> elth >> ehth;
41 inf >> bgain;
42 inf >> egain;
43 inf >> bconst;
44 inf >> econst;
45 inf >> eswitch;
46 t->Fill();
47 }
48 }
49
50 TFile f("TofSimConst.root","RECREATE");
51 t->Write();
52 f.Close();
53 delete t;
54 t=NULL;
55
56 return true;
57}
char * file
Definition: DQA_TO_DB.cxx:15

Referenced by main().