BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
convert2simroot.cxx
Go to the documentation of this file.
1//=====================================================
2// this script is used for TOF simulation
3//=====================================================
4#include "TFile.h"
5#include "TTree.h"
6#include <assert.h>
7#include <fstream>
8#include <iostream>
9using namespace std;
10
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
17 // east endcap sim; 2-add smear in both east and west endcap sim;
18 t->Branch( "BarLowThres", &blth, "BarLowThres/D" );
19 t->Branch( "BarHighThres", &bhth, "BarHighThres/D" );
20 t->Branch( "EndLowThres", &elth, "EndLowThres/D" );
21 t->Branch( "EndHighThres", &ehth, "EndHighThres/D" );
22 t->Branch( "BarPMTGain", &bgain, "BarPMTGain/D" );
23 t->Branch( "EndPMTGain", &egain, "EndPMTGain/D" );
24 t->Branch( "BarConstant", &bconst, "BarConst/D" );
25 t->Branch( "EndConstant", &econst, "EndConst/D" );
26 t->Branch( "EndNoiseSwitch", &eswitch, "EndNoiseSwitch/D" );
27
28 ifstream inf;
29 bool is_open = false;
30 const char* file = "SimConstants.txt";
31 inf.open( file, ios::in );
32 if ( inf.good() ) { is_open = true; }
33 else { std::cerr << "file: " << file << " can't be found!" << std::endl; }
34 try
35 {
36 if ( is_open )
37 {
38 inf >> blth >> bhth;
39 inf >> elth >> ehth;
40 inf >> bgain;
41 inf >> egain;
42 inf >> bconst;
43 inf >> econst;
44 inf >> eswitch;
45 t->Fill();
46 }
47 }
48
49 TFile f( "TofSimConst.root", "RECREATE" );
50 t->Write();
51 f.Close();
52 delete t;
53 t = NULL;
54
55 return true;
56}
57
59 double gain = 0.0, ratio = 0.0, length = 1.0;
60 TTree* t = new TTree( "BTofSim", "barrel attenuation length and gain" );
61 t->Branch( "Gain", &gain, "Gain/D" );
62 t->Branch( "Ratio", &ratio, "Ratio/D" );
63 t->Branch( "AttenLength", &length, "AttenLength/D" );
64
65 double a1overa2 = 1.0, a2 = 1.0;
66 double qmean = 0.0, qsigma = 0.0;
67 ifstream inf1, inf2;
68 bool is_open1 = false, is_open2 = false;
69 const char* file1 = "calib_barrel_atten.txt";
70 const char* file2 = "calib_barrel_q0.txt";
71 inf1.open( file1, ios::in );
72 inf2.open( file2, ios::in );
73 if ( inf1.good() ) { is_open1 = true; }
74 else { std::cerr << "file: " << file1 << " can't be found!" << std::endl; }
75 if ( inf2.good() ) { is_open2 = true; }
76 else { std::cerr << "file: " << file2 << " can't be found!" << std::endl; }
77
78 try
79 {
80 if ( is_open1 && is_open2 )
81 {
82 for ( unsigned int i = 0; i < 176; i++ )
83 {
84 inf1 >> length >> ratio;
85 if ( fabs( length ) < 1.0e-6 ) { length = 1.0; }
86 length = 1.0 / length;
87
88 inf2 >> gain >> qmean >> qsigma;
89
90 t->Fill();
91 }
92 }
93 } catch ( ... )
94 { return false; }
95
96 inf1.close();
97 inf2.close();
98
99 TFile f( "BarTofSim.root", "RECREATE" );
100 t->Write();
101 f.Close();
102 delete t;
103 t = NULL;
104
105 return true;
106}
107
109 double gain = 0.0, length = 1.0, noisesmear = 0.;
110 double scin, mean, errmean, sigma, errsigma;
111 double mc_sigma;
112 TTree* t = new TTree( "ETofSim", "endcap attenuation length and gain" );
113 t->Branch( "Gain", &gain, "Gain/D" );
114 t->Branch( "AttenLength", &length, "AttenLength/D" );
115 t->Branch( "NoiseSmear", &noisesmear, "NoiseSmear/D" );
116
117 double length2 = 1.0;
118 ifstream inf1, inf2, inf3;
119 bool is_open1 = false, is_open2 = false, is_open3 = false;
120 const char* file1 = "calib_endcap_atten.txt";
121 const char* file2 = "tEndRes.txt";
122 const char* file3 = "Endcap_mc_tEndRes.txt";
123 inf1.open( file1, ios::in );
124 inf2.open( file2, ios::in );
125 inf3.open( file3, ios::in );
126 if ( inf1.good() ) is_open1 = true;
127 else { std::cerr << "File: " << file1 << " can't be opened" << std::endl; }
128 if ( inf2.good() ) is_open2 = true;
129 else { std::cerr << "File: " << file2 << " can't be opened" << std::endl; }
130 if ( inf3.good() ) is_open3 = true;
131 else { std::cerr << "File: " << file3 << " can't be opened" << std::endl; }
132 try
133 {
134 if ( is_open1 && is_open2 && is_open3 )
135 {
136 for ( int i = 0; i < 96; i++ )
137 {
138 inf1 >> gain >> length >> length2;
139 inf2 >> scin >> mean >> errmean >> sigma >> errsigma;
140 inf3 >> mc_sigma;
141 if ( mc_sigma > sigma ) { noisesmear = 0.; }
142 else { noisesmear = sqrt( sigma * sigma - mc_sigma * mc_sigma ); }
143 t->Fill();
144 }
145 }
146 } catch ( ... )
147 { return false; }
148
149 inf1.close();
150 inf2.close();
151 inf3.close();
152
153 TFile f( "EndTofSim.root", "RECREATE" );
154 t->Write();
155 f.Close();
156 delete t;
157 t = NULL;
158
159 return true;
160}
161
162bool join() {
163
164 TFile f1( "TofSimConst.root" );
165 TTree* t1 = (TTree*)f1.Get( "SimConstants" );
166 if ( 0 == t1 )
167 {
168 std::cerr << " can't get tree :SimConstants in file TofSimConst.root" << std::endl;
169 return false;
170 }
171 TFile f2( "BarTofSim.root" );
172 TTree* t2 = (TTree*)f2.Get( "BTofSim" );
173 if ( 0 == t2 )
174 {
175 std::cerr << " can't get tree :BTofSim in file BarTofSim.root" << std::endl;
176 return false;
177 }
178 TFile f3( "EndTofSim.root" );
179 TTree* t3 = (TTree*)f3.Get( "ETofSim" );
180 if ( 0 == t3 )
181 {
182 std::cerr << " can't get tree :ETofSim in file EndTofSim.root" << std::endl;
183 return false;
184 }
185
186 TFile fnew( "TofSimConst.root", "RECREATE" );
187 t1->Write();
188 t2->Write();
189 t3->Write();
190 f1.Close();
191 f2.Close();
192 f3.Close();
193 fnew.Close();
194 t1 = NULL;
195 t2 = NULL;
196 t3 = NULL;
197
198 return true;
199}
200
201int main() {
205 join();
206}
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
char * file
Definition DQA_TO_DB.cxx:16
TFile * f1
bool join()
bool endcap_conv2root()
bool sim_conv2root()
bool barrel_conv2root()
int main()
int t()
Definition t.c:1