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);}
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");
172
173 return true;
174}