00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "BesTofGeoParameter.hh"
00013 #include <fstream>
00014 #include <strstream>
00015 #include <string>
00016 #include <vector>
00017 #include "ReadBoostRoot.hh"
00018
00019 BesTofGeoParameter* BesTofGeoParameter::m_instance = 0;
00020
00021 BesTofGeoParameter* BesTofGeoParameter::GetInstance()
00022 {
00023 if (m_instance == 0){
00024 m_instance = new BesTofGeoParameter;
00025 }
00026 return m_instance;
00027 }
00028
00029
00030 BesTofGeoParameter::BesTofGeoParameter()
00031 {
00032 UNIT["mm"]=1.;
00033 UNIT["cm"]=10.;
00034 UNIT["rag"]=1.;
00035 UNIT["deg"]=(acos(-1))/180.;
00036
00037 m_dataPath = getenv("TOFSIMROOT");
00038 if (!m_dataPath){
00039 G4Exception("BOOST environment not set!");
00040 }
00041 ReadData();
00042 ReadBrData();
00043 ReadMrpcData();
00044 }
00045
00046 BesTofGeoParameter::~BesTofGeoParameter()
00047 {
00048 }
00049
00050 void BesTofGeoParameter::ReadBrData()
00051 {
00052
00053 const G4String pmtDataPath = m_dataPath + "/dat/TofBr.txt";
00054
00055 std::ifstream fin(pmtDataPath);
00056 if (!fin) {
00057 std::cerr << "cannot open " << pmtDataPath << " for initialization.";
00058 exit(-1);
00059 }
00060
00061 using std::string;
00062 using std::vector;
00063 string tempString;
00064 string::size_type pre_position = 0;
00065 string::size_type post_position = 0;
00066 vector<string> stringVector;
00067 while (getline(fin, tempString, '\n')){
00068
00069
00070 pre_position = tempString.find_first_of("#");
00071 if (pre_position != string::npos){
00072 tempString.erase(tempString.begin() + pre_position, tempString.end());
00073 }
00074
00075
00076 pre_position = 0;
00077 post_position = 0;
00078 int size;
00079 while (tempString.find_first_of(" ", pre_position) != string::npos){
00080 pre_position = tempString.find_first_of(" ", pre_position);
00081 post_position = tempString.find_first_not_of(" ", pre_position);
00082 size = post_position - pre_position;
00083 tempString.replace(pre_position, size, " ");
00084 pre_position = post_position - size + 1;
00085 }
00086
00087
00088 if (tempString.size() > 10){
00089 stringVector.push_back(tempString);
00090 }
00091 }
00092
00093
00094 int scinNb;
00095 double tempEPMTgain;
00096 double tempERiseTime;
00097 double tempWPMTgain;
00098 double tempWRiseTime;
00099 double tempAtten;
00100 vector<string>::iterator it = stringVector.begin();
00101 for (it; it != stringVector.end(); it++){
00102
00103 std::istrstream buff((*it).c_str(), strlen((*it).c_str()));
00104 buff >> scinNb >> tempEPMTgain >> tempERiseTime >> tempWPMTgain >> tempWRiseTime >> tempAtten;
00105
00106 m_BrEPMTgain[scinNb] = tempEPMTgain;
00107 m_BrERiseTime[scinNb] = tempERiseTime;
00108 m_BrWPMTgain[scinNb] = tempWPMTgain;
00109 m_BrWRiseTime[scinNb] = tempWRiseTime;
00110 m_atten[scinNb] = tempAtten;
00111
00112 }
00113 fin.close();
00114 }
00115
00116 void BesTofGeoParameter::ReadData()
00117 {
00118
00119 const G4String GeometryPath = m_dataPath + "/dat/BesTof.txt";
00120
00121 std::ifstream fin;
00122 fin.open(GeometryPath);
00123
00124 const int maxCharOfOneLine=255;
00125 char temp[maxCharOfOneLine],*p;
00126 int lineNo=0,inputNo=0;
00127 while (fin.peek()!=EOF)
00128 {
00129 fin.getline(temp,maxCharOfOneLine);
00130 p=temp;
00131 lineNo++;
00132 while (*p!='\0')
00133 {
00134 if (*p=='#')
00135 {
00136 *p='\0';
00137 break;
00138 }
00139 p++;
00140 }
00141 p=temp;
00142 while (*p==' '||*p=='\t')p++;
00143 if (*p=='\0')continue;
00144 inputNo++;
00145 switch (inputNo)
00146 {
00147 case 1:
00148 std::istrstream(p)>>nScinBr>>br1L>>br1TrapW1>>br1TrapW2>>br1TrapH>>br1R1>>AlThickness>>PVFThickness;
00149 break;
00150 case 2:
00151 std::istrstream(p)>>br2L>>br2TrapW1>>br2TrapW2>>br2TrapH>>br2R1;
00152 break;
00153 case 3:
00154 std::istrstream(p)>>bucketDBr>>bucketLBr;
00155 break;
00156 case 4:
00157 std::istrstream(p)>>nScinEc>>ecL>>ecTrapW1>>ecTrapW2>>ecTrapH>>ecTrapH1
00158 >>zPosEastEc>>zPosWestEc>>ecR1>>ecR2;
00159 break;
00160 case 5:
00161 std::istrstream(p)>>bucketDEc>>bucketLEc>>bucketPosR;
00162 break;
00163 case 6:
00164 std::istrstream(p)>>m_tau1>>m_tau2>>m_tau3>>m_tauRatio>>m_refIndex>>m_phNConst>>m_Cpe2pmt>>m_rAngle>>m_QE>>m_CE>>m_peCorFac;
00165 case 7:
00166 std::istrstream(p)>>m_ttsMean>>m_ttsSigma>>m_PMTgain>>m_Ce>>m_riseTime>>m_LLthresh>>m_HLthresh>>m_preGain>>m_noiseSigma;
00167 case 8:
00168 std::istrstream(p)>>m_tau1Ec>>m_tau2Ec>>m_tau3Ec>>m_tauRatioEc>>m_refIndexEc>>m_phNConstEc>>m_Cpe2pmtEc>>m_rAngleEc>>m_QEEc>>m_CEEc>>m_peCorFacEc>>m_attenEc;
00169 case 9:
00170 std::istrstream(p)>>m_ttsMeanEc>>m_ttsSigmaEc>>m_PMTgainEc>>m_CeEc>>m_riseTimeEc>>m_LLthreshEc>>m_HLthreshEc>>m_preGainEc>>m_noiseSigmaEc;
00171 }
00172 }
00173
00174 fin.close();
00175 }
00176
00177
00178
00179 void BesTofGeoParameter::ReadMrpcData()
00180 {
00181
00182 G4String MrpcGeometryPath = m_dataPath + "/dat/BesTofMrpc.txt";
00183 const int maxCharOfOneLine=255;
00184 char temp[maxCharOfOneLine],*p;
00185 container.clear();
00186
00187 std::string key;
00188 double val;
00189 std::string unit;
00190 std::ifstream fin;
00191 fin.open(MrpcGeometryPath);
00192
00193 while (fin.peek()!=EOF)
00194 {
00195 fin.getline(temp,maxCharOfOneLine);
00196 p=temp;
00197 while (*p!='\0')
00198 {
00199 if (*p=='#')
00200 {
00201 *p='\0';
00202 break;
00203 }
00204 p++;
00205 }
00206 p=temp;
00207 while (*p==' '||*p=='\t')p++;
00208 if (*p=='\0')continue;
00209
00210 std::stringstream ss(temp);
00211 ss >> key >> val>>unit;
00212 container[key]=val*UNIT[unit];
00213 }
00214 fin.close();
00215
00216
00217
00218 container2.clear();
00219 double rOffset, angle, angleOffset;
00220 VEC v_rOffset, v_angle, v_angleOffset;
00221 int lineNo = 0;
00222 G4String MrpcGeometryPath1 = m_dataPath + "/dat/Mrpc_adjust.txt";
00223 fin.open(MrpcGeometryPath1);
00224
00225 while (fin.peek()!=EOF)
00226 {
00227 fin.getline(temp,maxCharOfOneLine);
00228 p=temp;
00229 while (*p!='\0')
00230 {
00231 if (*p=='#')
00232 {
00233 *p='\0';
00234 break;
00235 }
00236 p++;
00237 }
00238 p=temp;
00239 while (*p==' '||*p=='\t')p++;
00240 if (*p=='\0')continue;
00241 lineNo++;
00242
00243 std::stringstream ss(temp);
00244 std::stringstream name;
00245 ss >> rOffset >> angle >> angleOffset;
00246 if(lineNo==37)
00247 {
00248 container2["rOffset_east"] = v_rOffset;
00249 container2["angle_east"] = v_angle;
00250 container2["angleOffset_east"] = v_angleOffset;
00251
00252 v_rOffset.clear();
00253 v_angle.clear();
00254 v_angleOffset.clear();
00255 }
00256
00257 v_rOffset.push_back(rOffset);
00258 v_angle.push_back(angle);
00259 v_angleOffset.push_back(angleOffset);
00260 }
00261 container2["rOffset_west"] = v_rOffset;
00262 container2["angle_west"] = v_angle;
00263 container2["angleOffset_west"] = v_angleOffset;
00264
00265 fin.close();
00266
00267
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283 int tofid, strip, end;
00284 for(int i=0; i<72; i++)
00285 {
00286 for(int j=0; j<12; j++)
00287 {
00288 m_deadChannel[i][j] = -999;
00289 }
00290 }
00291
00292 G4String MrpcGeometryPath2 = m_dataPath + "/dat/BesTofMrpc_dead.txt";
00293 fin.open(MrpcGeometryPath2);
00294
00295 while (fin.peek()!=EOF)
00296 {
00297 fin.getline(temp,maxCharOfOneLine);
00298 p=temp;
00299 while (*p!='\0')
00300 {
00301 if (*p=='#')
00302 {
00303 *p='\0';
00304 break;
00305 }
00306 p++;
00307 }
00308 p=temp;
00309 while (*p==' '||*p=='\t')p++;
00310 if (*p=='\0')continue;
00311
00312 std::stringstream ss(temp);
00313 ss >> tofid >> strip >> end;
00314 m_deadChannel[tofid][strip] = end;
00315 std::cout<<"deadC["<<tofid<<"]["<<strip<<"]= "<<m_deadChannel[tofid][strip]<<std::endl;
00316 }
00317
00318 fin.close();
00319
00320
00321 }
00322
00323 double BesTofGeoParameter::Get(std::string key)
00324 {
00325 for(CONTAINER::iterator it=container.begin(); it!=container.end(); ++it)
00326 {
00327 if((it->first)==key)
00328 {
00329 double val = container[key];
00330 return val;
00331 }
00332 }
00333
00334 std::cout<<"!!!! Wrong! Please check the value name !!!!"<<std::endl;
00335 return -999.9;
00336 }
00337
00338 VEC BesTofGeoParameter::GetVec(std::string key)
00339 {
00340 VEC vec;
00341 for(CONTAINER2::iterator it=container2.begin(); it!=container2.end(); ++it)
00342 {
00343 if((it->first)==key)
00344 {
00345 vec = container2[key];
00346 return vec;
00347 }
00348 }
00349
00350 std::cout<<"!!!! Wrong! Please check the value name !!!!"<<std::endl;
00351 return vec;
00352 }
00353
00354 void BesTofGeoParameter::Get_deadChannel(int deadChannel[72][12])
00355 {
00356 for(int i=0; i<72; i++)
00357 {
00358 for(int j=0; j<12; j++)
00359 {
00360 deadChannel[i][j] = m_deadChannel[i][j];
00361 }
00362 }
00363 }
00364