#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 () |
bool barrel_conv2root | ( | ) |
Definition at line 59 of file convert2simroot.cxx.
References genRecEmupikp::i, and t().
00059 { 00060 double gain=0.0, ratio=0.0, length=1.0; 00061 TTree* t=new TTree("BTofSim","barrel attenuation length and gain"); 00062 t->Branch("Gain", &gain, "Gain/D"); 00063 t->Branch("Ratio", &ratio, "Ratio/D"); 00064 t->Branch("AttenLength", &length, "AttenLength/D"); 00065 00066 double a1overa2 = 1.0, a2 = 1.0; 00067 double qmean = 0.0, qsigma = 0.0; 00068 ifstream inf1, inf2; 00069 bool is_open1=false, is_open2=false; 00070 const char* file1="calib_barrel_atten.txt"; 00071 const char* file2="calib_barrel_q0.txt"; 00072 inf1.open(file1,ios::in); 00073 inf2.open(file2,ios::in); 00074 if( inf1.good() ) { 00075 is_open1=true; 00076 } 00077 else { 00078 std::cerr<<"file: "<<file1 <<" can't be found!"<<std::endl; 00079 } 00080 if( inf2.good() ) { 00081 is_open2=true; 00082 } 00083 else { 00084 std::cerr<<"file: "<<file2 <<" can't be found!"<<std::endl; 00085 } 00086 00087 try{ 00088 if( is_open1 && is_open2 ) { 00089 for( unsigned int i=0; i<176; i++ ) { 00090 inf1 >> length >> ratio; 00091 if( fabs(length)<1.0e-6 ) { length = 1.0; } 00092 length = 1.0/length; 00093 00094 inf2 >> gain >> qmean >> qsigma; 00095 00096 t->Fill(); 00097 } 00098 } 00099 } catch(...) { 00100 return false; 00101 } 00102 00103 inf1.close(); 00104 inf2.close(); 00105 00106 TFile f("BarTofSim.root","RECREATE"); 00107 t->Write(); 00108 f.Close(); 00109 delete t; 00110 t=NULL; 00111 00112 return true; 00113 }
bool endcap_conv2root | ( | ) |
Definition at line 115 of file convert2simroot.cxx.
References genRecEmupikp::i, and t().
00115 { 00116 double gain=0.0, length=1.0, noisesmear=0.; 00117 double scin, mean, errmean, sigma, errsigma; 00118 double mc_sigma; 00119 TTree* t=new TTree("ETofSim","endcap attenuation length and gain"); 00120 t->Branch("Gain", &gain, "Gain/D" ); 00121 t->Branch("AttenLength", &length, "AttenLength/D"); 00122 t->Branch("NoiseSmear", &noisesmear,"NoiseSmear/D" ); 00123 00124 double length2=1.0; 00125 ifstream inf1, inf2, inf3; 00126 bool is_open1=false, is_open2=false, is_open3=false; 00127 const char* file1="calib_endcap_atten.txt"; 00128 const char* file2="tEndRes.txt"; 00129 const char* file3="Endcap_mc_tEndRes.txt"; 00130 inf1.open(file1,ios::in); 00131 inf2.open(file2,ios::in); 00132 inf3.open(file3,ios::in); 00133 if(inf1.good()) 00134 is_open1=true; 00135 else{ 00136 std::cerr<<"File: "<<file1<<" can't be opened"<<std::endl; 00137 } 00138 if(inf2.good()) 00139 is_open2=true; 00140 else{ 00141 std::cerr<<"File: "<<file2<<" can't be opened"<<std::endl; 00142 } 00143 if(inf3.good()) 00144 is_open3=true; 00145 else{ 00146 std::cerr<<"File: "<<file3<<" can't be opened"<<std::endl; 00147 } 00148 try{ 00149 if( is_open1 && is_open2 && is_open3) { 00150 for(int i=0;i<96;i++) { 00151 inf1 >> gain >> length >> length2; 00152 inf2 >> scin >> mean >> errmean >> sigma >> errsigma; 00153 inf3 >> mc_sigma; 00154 if ( mc_sigma > sigma ) {noisesmear = 0.;} 00155 else { noisesmear = sqrt(sigma*sigma - mc_sigma*mc_sigma);} 00156 t->Fill(); 00157 } 00158 } 00159 } catch(...){ 00160 return false; 00161 } 00162 00163 inf1.close(); 00164 inf2.close(); 00165 inf3.close(); 00166 00167 TFile f("EndTofSim.root","RECREATE"); 00168 t->Write(); 00169 f.Close(); 00170 delete t; 00171 t=NULL; 00172 00173 return true; 00174 }
bool join | ( | ) |
Definition at line 176 of file convert2simroot.cxx.
00176 { 00177 00178 TFile f1("TofSimConst.root"); 00179 TTree* t1=(TTree*)f1.Get("SimConstants"); 00180 if(0==t1) { std::cerr<<" can't get tree :SimConstants in file TofSimConst.root"<<std::endl; return false;} 00181 TFile f2("BarTofSim.root"); 00182 TTree* t2=(TTree*)f2.Get("BTofSim"); 00183 if(0==t2) { std::cerr<<" can't get tree :BTofSim in file BarTofSim.root"<<std::endl; return false;} 00184 TFile f3("EndTofSim.root"); 00185 TTree* t3=(TTree*)f3.Get("ETofSim"); 00186 if(0==t3) { std::cerr<<" can't get tree :ETofSim in file EndTofSim.root"<<std::endl; return false;} 00187 00188 TFile fnew("TofSimConst.root","RECREATE"); 00189 t1->Write(); 00190 t2->Write(); 00191 t3->Write(); 00192 f1.Close(); 00193 f2.Close(); 00194 f3.Close(); 00195 fnew.Close(); 00196 t1=NULL; 00197 t2=NULL; 00198 t3=NULL; 00199 00200 return true; 00201 }
int main | ( | ) |
Definition at line 203 of file convert2simroot.cxx.
References barrel_conv2root(), endcap_conv2root(), join(), and sim_conv2root().
00203 { 00204 sim_conv2root(); 00205 barrel_conv2root(); 00206 endcap_conv2root(); 00207 join(); 00208 }
bool sim_conv2root | ( | ) |
Definition at line 11 of file convert2simroot.cxx.
Referenced by main().
00011 { 00012 TTree* t=new TTree("SimConstants","threshold and gain constants"); 00013 double blth=50., bhth=50., elth=50., ehth=50.; 00014 double bgain=5.E5, egain=2.5E5; 00015 double bconst=1.0, econst=1.0; 00016 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; 00017 t->Branch("BarLowThres", &blth, "BarLowThres/D" ); 00018 t->Branch("BarHighThres", &bhth, "BarHighThres/D"); 00019 t->Branch("EndLowThres", &elth, "EndLowThres/D" ); 00020 t->Branch("EndHighThres", &ehth, "EndHighThres/D"); 00021 t->Branch("BarPMTGain", &bgain, "BarPMTGain/D" ); 00022 t->Branch("EndPMTGain", &egain, "EndPMTGain/D" ); 00023 t->Branch("BarConstant", &bconst, "BarConst/D" ); 00024 t->Branch("EndConstant", &econst, "EndConst/D" ); 00025 t->Branch("EndNoiseSwitch",&eswitch, "EndNoiseSwitch/D" ); 00026 00027 ifstream inf; 00028 bool is_open=false; 00029 const char* file="SimConstants.txt"; 00030 inf.open(file,ios::in); 00031 if( inf.good() ) { 00032 is_open=true; 00033 } 00034 else { 00035 std::cerr<<"file: "<<file <<" can't be found!"<<std::endl; 00036 } 00037 try{ 00038 if( is_open ){ 00039 inf >> blth >> bhth; 00040 inf >> elth >> ehth; 00041 inf >> bgain; 00042 inf >> egain; 00043 inf >> bconst; 00044 inf >> econst; 00045 inf >> eswitch; 00046 t->Fill(); 00047 } 00048 } 00049 00050 TFile f("TofSimConst.root","RECREATE"); 00051 t->Write(); 00052 f.Close(); 00053 delete t; 00054 t=NULL; 00055 00056 return true; 00057 }