00001
00002
00003
00004
00005
00006
00007
00008 #include "EmcRec/EmcRecParameter.h"
00009 #include "TGraph2DErrors.h"
00010 #include <fstream>
00011 #include <sstream>
00012 #include <assert.h>
00013 #include <stdlib.h>
00014
00015
00016 EmcRecParameter* EmcRecParameter::fpInstance=0;
00017 pthread_mutex_t EmcRecParameter::m_pthread_lock = PTHREAD_MUTEX_INITIALIZER;
00018
00019
00020 EmcRecParameter::EmcRecParameter()
00021 {
00022 string paraPath = getenv("EMCRECROOT");
00023 if(paraPath==""){}
00024 string paraPath1(paraPath);
00025 string paraPath2(paraPath);
00026 string paraPath3(paraPath);
00027 string paraPath4(paraPath);
00028 string paraPath5(paraPath);
00029 string paraPath6(paraPath);
00030 string paraPath7(paraPath);
00031 string paraPath8(paraPath);
00032 string paraPath9(paraPath);
00033 string paraPath10(paraPath);
00034 string paraPath11(paraPath);
00035 string paraPath12(paraPath);
00036 string paraPath13(paraPath);
00037 string paraPath14(paraPath);
00038 string paraPath15(paraPath);
00039 string paraPath16(paraPath);
00040 string paraPath17(paraPath);
00041 string paraPath18(paraPath);
00042 string paraPath19(paraPath);
00043 string paraPath20(paraPath);
00044 string paraPath21(paraPath);
00045 string paraPath22(paraPath);
00046 string paraPath23(paraPath);
00047 string paraPath24(paraPath);
00048 string paraPath25(paraPath);
00049 string paraPath26(paraPath);
00050 string paraPath27(paraPath);
00051 string paraPath28(paraPath);
00052 string paraPath29(paraPath);
00053 paraPath += "/share/EmcRecPara.dat";
00054
00055 ifstream in;
00056 in.open(paraPath.c_str());
00057 assert(in);
00058
00059 const int maxCharOfOneLine=255;
00060 char temp[maxCharOfOneLine];
00061 int inputNo=0;
00062 while(in.peek()!=EOF) {
00063 in.getline(temp,maxCharOfOneLine);
00064 if(temp[0]=='#') continue;
00065 inputNo++;
00066 switch(inputNo) {
00067 case 1:
00068 istringstream(temp)>>fElectronicsNoiseLevel>>fEThresholdSeed>>fEThresholdCluster>>fLogPosOffset;
00069 break;
00070 case 2:
00071 istringstream(temp)>>fMoliereRadius>>fLateralProfile;
00072 break;
00073 case 3:
00074 istringstream(temp)>>eCorr[0]>>eCorr[1]>>eCorr[2]>>eCorr[3];
00075 break;
00076 case 4:
00077 istringstream(temp)>>sigE[0]>>sigE[1]>>sigE[2]
00078 >>sigTheta[0]>>sigTheta[1]>>sigPhi[0]>>sigPhi[1];
00079 break;
00080 case 5:
00081 istringstream(temp)>>hitNb[0]>>hitNb[1]>>hitNb[2];
00082 break;
00083 case 6:
00084 istringstream(temp)>>elecBias[0]>>elecBias[1]>>elecBias[2]
00085 >>elecBias[3]>>elecBias[4];
00086 break;
00087 case 7:
00088 istringstream(temp)>>smCut[0]>>smCut[1]>>smCut[2]>>smCut[3];
00089 break;
00090 default:
00091 break;
00092 }
00093 }
00094 in.close();
00095
00096 paraPath1 += "/share/Peak1.843_10.12calib.dat";
00097 ifstream in1;
00098 in1.open(paraPath1.c_str());
00099 assert(in1);
00100 int ntheta;
00101 double sigma,sigmaerr,peakerr;
00102 for(int i=0;i<56;i++) {
00103 in1>>ntheta>>sigma>>sigmaerr>>peak[i]>>peakerr;
00104 }
00105 in1.close();
00106
00107
00108 paraPath2 += "/share/evset.txt";
00109 ifstream in2;
00110 in2.open(paraPath2.c_str());
00111 assert(in2);
00112 double energy,thetaid,peak1,peakerr1,res,reserr;
00113
00114 dt = new TGraph2DErrors();
00115 dtErr = new TGraph2DErrors();
00116 for(int i=0;i<560;i++){
00117 in2>>energy;
00118 in2>>thetaid;
00119 in2>>peak1;
00120 in2>>peakerr1;
00121 in2>>res;
00122 in2>>reserr;
00123 dt->SetPoint(i,energy,thetaid,peak1);
00124 dt->SetPointError(i,0,0,peakerr1);
00125 dtErr->SetPoint(i,energy,thetaid,res);
00126 dtErr->SetPointError(i,0,0,reserr);
00127
00128 if(i<28) e25min[int(thetaid)]=energy;
00129 if(i>=560-28) e25max[int(thetaid)]=energy;
00130
00131 }
00132 in2.close();
00133
00134
00135 paraPath3 += "/share/BarrLogThetaPara.dat";
00136 ifstream in3;
00137 in3.open(paraPath3.c_str());
00138 assert(in3);
00139 for(int i=0;i<66;i++){
00140 for(int j=0;j<5;j++){
00141 in3>>barrLogThetaPara[i][j];
00142 }
00143 }
00144 in3.close();
00145
00146 paraPath4 += "/share/BarrLogPhiPara.dat";
00147 ifstream in4;
00148 in4.open(paraPath4.c_str());
00149 assert(in4);
00150 for(int i=0;i<66;i++){
00151 for(int j=0;j<5;j++){
00152 in4>>barrLogPhiPara[i][j];
00153 }
00154 }
00155 in4.close();
00156
00157 paraPath5 += "/share/BarrLinThetaPara.dat";
00158 ifstream in5;
00159 in5.open(paraPath5.c_str());
00160 assert(in5);
00161 for(int i=0;i<66;i++){
00162 for(int j=0;j<5;j++){
00163 in5>>barrLinThetaPara[i][j];
00164 }
00165 }
00166 in5.close();
00167
00168 paraPath6 += "/share/BarrLinPhiPara.dat";
00169 ifstream in6;
00170 in6.open(paraPath6.c_str());
00171 assert(in6);
00172 for(int i=0;i<3;i++){
00173 for(int j=0;j<5;j++){
00174 in6>>barrLinPhiPara[i][j];
00175 }
00176 }
00177 in6.close();
00178
00179
00180 paraPath7 += "/share/BarrShLogThetaPara.dat";
00181 ifstream in7;
00182 in7.open(paraPath7.c_str());
00183 assert(in7);
00184 for(int i=0;i<66;i++){
00185 for(int j=0;j<5;j++){
00186 in7>>barrShLogThetaPara[i][j];
00187 }
00188 }
00189 in7.close();
00190
00191 paraPath8 += "/share/BarrShLogPhiPara.dat";
00192 ifstream in8;
00193 in8.open(paraPath8.c_str());
00194 assert(in8);
00195 for(int i=0;i<3;i++){
00196 for(int j=0;j<5;j++){
00197 in8>>barrShLogPhiPara[i][j];
00198 }
00199 }
00200 in8.close();
00201
00202 paraPath9 += "/share/BarrShLinThetaPara.dat";
00203 ifstream in9;
00204 in9.open(paraPath9.c_str());
00205 assert(in9);
00206 for(int i=0;i<66;i++){
00207 for(int j=0;j<5;j++){
00208 in9>>barrShLinThetaPara[i][j];
00209 }
00210 }
00211 in9.close();
00212
00213 paraPath10 += "/share/BarrShLinPhiPara.dat";
00214 ifstream in10;
00215 in10.open(paraPath10.c_str());
00216 assert(in10);
00217 for(int i=0;i<3;i++){
00218 for(int j=0;j<5;j++){
00219 in10>>barrShLinPhiPara[i][j];
00220 }
00221 }
00222 in10.close();
00223
00224
00225 paraPath11 += "/share/EastLogThetaPara.dat";
00226 ifstream in11;
00227 in11.open(paraPath11.c_str());
00228 assert(in11);
00229 for(int i=0;i<18;i++){
00230 for(int j=0;j<5;j++){
00231 in11>>eastLogThetaPara[i][j];
00232 }
00233 }
00234 in11.close();
00235
00236 paraPath12 += "/share/WestLogThetaPara.dat";
00237 ifstream in12;
00238 in12.open(paraPath12.c_str());
00239 assert(in12);
00240 for(int i=0;i<18;i++){
00241 for(int j=0;j<5;j++){
00242 in12>>westLogThetaPara[i][j];
00243 }
00244 }
00245 in12.close();
00246
00247 paraPath13 += "/share/EastLinThetaPara.dat";
00248 ifstream in13;
00249 in13.open(paraPath13.c_str());
00250 assert(in13);
00251 for(int i=0;i<6;i++){
00252 for(int j=0;j<5;j++){
00253 in13>>eastLinThetaPara[i][j];
00254 }
00255 }
00256 in13.close();
00257
00258 paraPath14 += "/share/WestLinThetaPara.dat";
00259 ifstream in14;
00260 in14.open(paraPath14.c_str());
00261 assert(in14);
00262 for(int i=0;i<6;i++){
00263 for(int j=0;j<5;j++){
00264 in14>>westLinThetaPara[i][j];
00265 }
00266 }
00267 in14.close();
00268
00269 paraPath15 += "/share/BarrDataLogThetaPara.dat";
00270 ifstream in15;
00271 in15.open(paraPath15.c_str());
00272 assert(in15);
00273 for(int i=0;i<22;i++){
00274 for(int j=0;j<5;j++){
00275 in15>>barrDataLogThetaPara[i][j];
00276 }
00277 }
00278 in15.close();
00279
00280 paraPath16 += "/share/EastDataLogThetaPara.dat";
00281 ifstream in16;
00282 in16.open(paraPath16.c_str());
00283 assert(in16);
00284 for(int i=0;i<6;i++){
00285 for(int j=0;j<5;j++){
00286 in16>>eastDataLogThetaPara[i][j];
00287 }
00288 }
00289 in16.close();
00290
00291 paraPath17 += "/share/WestDataLogThetaPara.dat";
00292 ifstream in17;
00293 in17.open(paraPath17.c_str());
00294 assert(in17);
00295 for(int i=0;i<6;i++){
00296 for(int j=0;j<5;j++){
00297 in17>>westDataLogThetaPara[i][j];
00298 }
00299 }
00300 in17.close();
00301
00302
00303 paraPath18 += "/share/EastLogPhiPara.dat";
00304 ifstream in18;
00305 in18.open(paraPath18.c_str());
00306 assert(in18);
00307 for(int i=0;i<3;i++){
00308 for(int j=0;j<5;j++){
00309 in18>>eastLogPhiPara[i][j];
00310 }
00311 }
00312 in18.close();
00313
00314 paraPath19 += "/share/WestLogPhiPara.dat";
00315 ifstream in19;
00316 in19.open(paraPath19.c_str());
00317 assert(in19);
00318 for(int i=0;i<3;i++){
00319 for(int j=0;j<5;j++){
00320 in19>>westLogPhiPara[i][j];
00321 }
00322 }
00323 in19.close();
00324
00325 paraPath20 += "/share/EastLinPhiPara.dat";
00326 ifstream in20;
00327 in20.open(paraPath20.c_str());
00328 assert(in20);
00329 for(int i=0;i<1;i++){
00330 for(int j=0;j<5;j++){
00331 in20>>eastLinPhiPara[i][j];
00332 }
00333 }
00334 in20.close();
00335
00336 paraPath21 += "/share/WestLinPhiPara.dat";
00337 ifstream in21;
00338 in21.open(paraPath21.c_str());
00339 assert(in21);
00340 for(int i=0;i<1;i++){
00341 for(int j=0;j<5;j++){
00342 in21>>westLinPhiPara[i][j];
00343 }
00344 }
00345 in21.close();
00346
00347 paraPath22 += "/share/BarrLoglinThetaPara.dat";
00348 ifstream in22;
00349 in22.open(paraPath22.c_str());
00350 assert(in22);
00351 for(int i=0;i<22;i++){
00352 for(int j=0;j<5;j++){
00353 in22>>barrLoglinThetaPara[i][j];
00354 }
00355 }
00356 in22.close();
00357
00358 paraPath23 += "/share/BarrLoglinPhiPara.dat";
00359 ifstream in23;
00360 in23.open(paraPath23.c_str());
00361 assert(in23);
00362 for(int i=0;i<1;i++){
00363 for(int j=0;j<5;j++){
00364 in23>>barrLoglinPhiPara[i][j];
00365 }
00366 }
00367 in23.close();
00368
00369
00370 int ith,iph;
00371 double dth,dtherr,sig,sigerr;
00372
00373 paraPath24 += "/share/PosCorDataBarr.conf";
00374 ifstream in24;
00375 in24.open(paraPath24.c_str());
00376 assert(in24);
00377
00378 for(int i=0;i<5280;i++){
00379
00380 in24>>iph>>ith>>dth>>dtherr>>sig>>sigerr;
00381 barrPosDataCorPara[ith][iph]=dth;
00382
00383 }
00384 in24.close();
00385
00386 paraPath25 += "/share/PosCorDataWest.conf";
00387 ifstream in25;
00388 in25.open(paraPath25.c_str());
00389 assert(in25);
00390 for(int i=0;i<480;i++){
00391
00392 in25>>ith>>iph>>dth>>dtherr>>sig>>sigerr;
00393 westPosDataCorPara[ith][iph]=dth;
00394
00395 }
00396 in25.close();
00397
00398 paraPath26 += "/share/PosCorDataEast.conf";
00399 ifstream in26;
00400 in26.open(paraPath26.c_str());
00401 assert(in26);
00402 for(int i=0;i<480;i++){
00403
00404 in26>>ith>>iph>>dth>>dtherr>>sig>>sigerr;
00405 eastPosDataCorPara[ith][iph]=dth;
00406
00407 }
00408 in26.close();
00409
00411 paraPath27 += "/share/PosCorMCBarr.conf";
00412 ifstream in27;
00413 in27.open(paraPath27.c_str());
00414 assert(in27);
00415
00416 for(int i=0;i<5280;i++){
00417
00418 in27>>iph>>ith>>dth>>dtherr>>sig>>sigerr;
00419 barrPosMCCorPara[ith][iph]=dth;
00420
00421 }
00422 in27.close();
00423
00424 paraPath28 += "/share/PosCorMCWest.conf";
00425 ifstream in28;
00426 in28.open(paraPath28.c_str());
00427 assert(in28);
00428 for(int i=0;i<480;i++){
00429
00430 in28>>ith>>iph>>dth>>dtherr>>sig>>sigerr;
00431 westPosMCCorPara[ith][iph]=dth;
00432
00433 }
00434 in28.close();
00435
00436 paraPath29 += "/share/PosCorMCEast.conf";
00437 ifstream in29;
00438 in29.open(paraPath29.c_str());
00439 assert(in29);
00440 for(int i=0;i<480;i++){
00441
00442 in29>>ith>>iph>>dth>>dtherr>>sig>>sigerr;
00443 eastPosMCCorPara[ith][iph]=dth;
00444
00445 }
00446 in29.close();
00447
00448
00449 }
00450
00451
00452 EmcRecParameter::~EmcRecParameter()
00453 {
00454
00455 delete dt;
00456 delete dtErr;
00457 }
00458
00459
00460
00461 EmcRecParameter& EmcRecParameter::GetInstance()
00462 {
00463 if(!Exist()) {
00464 fpInstance=new EmcRecParameter;
00465 }
00466 return *fpInstance;
00467 }
00468
00469 bool EmcRecParameter::Exist()
00470 {
00471 return fpInstance!=0;
00472 }
00473
00474 void EmcRecParameter::Kill()
00475 {
00476 if(Exist()) {
00477 delete fpInstance;
00478 fpInstance=0;
00479 }
00480 }
00481
00482
00483 double EmcRecParameter::ElectronicsNoiseLevel() const
00484 {
00485 return fElectronicsNoiseLevel;
00486 }
00487
00488 double EmcRecParameter::EThresholdSeed() const
00489 {
00490 return fEThresholdSeed;
00491 }
00492
00493 double EmcRecParameter::EThresholdCluster() const
00494 {
00495 return fEThresholdCluster;
00496 }
00497
00498 double EmcRecParameter::LogPosOffset() const
00499 {
00500 return fLogPosOffset;
00501 }
00502
00503 double EmcRecParameter::TimeMin() const
00504 {
00505 return fTimeMin;
00506 }
00507
00508 double EmcRecParameter::TimeMax() const
00509 {
00510 return fTimeMax;
00511 }
00512
00513
00514 double EmcRecParameter::MethodMode() const
00515 {
00516 return fMethodMode;
00517 }
00518
00519 double EmcRecParameter::PosCorr() const
00520 {
00521 return fPosCorr;
00522 }
00523
00524 double EmcRecParameter::DataMode() const
00525 {
00526 return fDataMode;
00527 }
00528 int EmcRecParameter::ElecSaturation() const
00529 {
00530 return fElecSaturation;
00531 }
00532
00533 double EmcRecParameter::MoliereRadius() const
00534 {
00535 return fMoliereRadius;
00536 }
00537
00538 double EmcRecParameter::LateralProfile() const
00539 {
00540 return fLateralProfile;
00541 }
00542
00543 double EmcRecParameter::ECorr(int n) const
00544 {
00545 return eCorr[n];
00546 }
00547
00548 double EmcRecParameter::SigE(int n) const
00549 {
00550 return sigE[n];
00551 }
00552
00553 double EmcRecParameter::SigTheta(int n) const
00554 {
00555 return sigTheta[n];
00556 }
00557
00558 double EmcRecParameter::SigPhi(int n) const
00559 {
00560 return sigPhi[n];
00561 }
00562
00563 double EmcRecParameter::HitNb(int n) const
00564 {
00565 return hitNb[n];
00566 }
00567
00568 double EmcRecParameter::ElecBias(int n) const
00569 {
00570 return elecBias[n];
00571 }
00572
00573 double EmcRecParameter::SmCut(int n) const
00574 {
00575 return smCut[n];
00576 }
00577
00578 double EmcRecParameter::Peak(int n) const
00579 {
00580 return peak[n];
00581 }
00582
00583 double EmcRecParameter::BarrLogThetaPara(int n , int m) const
00584 {
00585 return barrLogThetaPara[n][m];
00586 }
00587
00588
00589
00590 double EmcRecParameter::BarrLogPhiPara(int n ,int m) const
00591 {
00592 return barrLogPhiPara[n][m];
00593 }
00594
00595
00596 double EmcRecParameter::BarrLoglinThetaPara(int n , int m) const
00597 {
00598 return barrLoglinThetaPara[n][m];
00599 }
00600
00601
00602
00603 double EmcRecParameter::BarrLoglinPhiPara(int n ,int m) const
00604 {
00605 return barrLoglinPhiPara[n][m];
00606 }
00607
00608
00609
00610 double EmcRecParameter::BarrLinThetaPara(int n , int m) const
00611 {
00612 return barrLinThetaPara[n][m];
00613 }
00614
00615 double EmcRecParameter::BarrLinPhiPara(int n ,int m) const
00616 {
00617 return barrLinPhiPara[n][m];
00618 }
00619
00620 double EmcRecParameter::BarrShLogThetaPara(int n , int m) const
00621 {
00622 return barrShLogThetaPara[n][m];
00623 }
00624
00625 double EmcRecParameter::BarrShLogPhiPara(int n ,int m) const
00626 {
00627 return barrShLogPhiPara[n][m];
00628 }
00629
00630 double EmcRecParameter::BarrShLinThetaPara(int n , int m) const
00631 {
00632 return barrShLinThetaPara[n][m];
00633 }
00634
00635 double EmcRecParameter::BarrShLinPhiPara(int n ,int m) const
00636 {
00637 return barrShLinPhiPara[n][m];
00638 }
00639
00640
00641 double EmcRecParameter::EastLogThetaPara(int n ,int m) const
00642 {
00643 return eastLogThetaPara[n][m];
00644 }
00645
00646 double EmcRecParameter::WestLogThetaPara(int n ,int m) const
00647 {
00648 return westLogThetaPara[n][m];
00649 }
00650
00651 double EmcRecParameter::EastLogPhiPara(int n ,int m) const
00652 {
00653 return eastLogPhiPara[n][m];
00654 }
00655
00656 double EmcRecParameter::WestLogPhiPara(int n ,int m) const
00657 {
00658 return westLogPhiPara[n][m];
00659 }
00660
00661 double EmcRecParameter::EastLinPhiPara(int n ,int m) const
00662 {
00663 return eastLinPhiPara[n][m];
00664 }
00665
00666 double EmcRecParameter::WestLinPhiPara(int n ,int m) const
00667 {
00668 return westLinPhiPara[n][m];
00669 }
00670
00671
00672 double EmcRecParameter::EastLinThetaPara(int n ,int m) const
00673 {
00674 return eastLinThetaPara[n][m];
00675 }
00676
00677 double EmcRecParameter::WestLinThetaPara(int n ,int m) const
00678 {
00679 return westLinThetaPara[n][m];
00680 }
00681
00682 double EmcRecParameter::BarrDataLogThetaPara(int n , int m) const
00683 {
00684 return barrDataLogThetaPara[n][m];
00685 }
00686
00687 double EmcRecParameter::BarrPosDataCor(int ntheta, int nphi) const
00688 {
00689 return barrPosDataCorPara[ntheta][nphi];
00690 }
00691
00692 double EmcRecParameter::WestPosDataCor(int ntheta, int nphi) const
00693 {
00694 return westPosDataCorPara[ntheta][nphi];
00695 }
00696
00697 double EmcRecParameter::EastPosDataCor(int ntheta, int nphi) const
00698 {
00699 return eastPosDataCorPara[ntheta][nphi];
00700 }
00701
00702 double EmcRecParameter::BarrPosMCCor(int ntheta, int nphi) const
00703 {
00704 return barrPosMCCorPara[ntheta][nphi];
00705 }
00706
00707 double EmcRecParameter::WestPosMCCor(int ntheta, int nphi) const
00708 {
00709 return westPosMCCorPara[ntheta][nphi];
00710 }
00711
00712 double EmcRecParameter::EastPosMCCor(int ntheta, int nphi) const
00713 {
00714 return eastPosMCCorPara[ntheta][nphi];
00715 }
00716
00717
00718
00719 double EmcRecParameter::EastDataLogThetaPara(int n ,int m) const
00720 {
00721 return eastDataLogThetaPara[n][m];
00722 }
00723
00724 double EmcRecParameter::WestDataLogThetaPara(int n ,int m) const
00725 {
00726 return westDataLogThetaPara[n][m];
00727 }
00728
00729
00730
00731
00732 void EmcRecParameter::SetPositionMode(std::vector<std::string>& mode)
00733 {
00734 if(mode.size()==2) {
00735 positionMode1=mode[0];
00736 positionMode2=mode[1];
00737 }
00738 }
00739
00740
00741 double EmcRecParameter::ECorrMC(double eg, double theid) const
00742 {
00743 double Energy5x5=eg;
00744 if(eg<E25min(int(theid))) eg=E25min(int(theid));
00745 if(eg>E25max(int(theid))) eg=E25max(int(theid))-0.001;
00746 if(theid<=0)theid=0.001;
00747 if(theid>=27)theid=26.999;
00748 Float_t einter = eg + 0.00001;
00749 Float_t tinter = theid+0.0001;
00750 double ecor=dt->Interpolate(einter,tinter);
00751 if(!(ecor))return Energy5x5;
00752 if(ecor<0.5)return Energy5x5;
00753 double EnergyCor=Energy5x5/ecor;
00754 return EnergyCor;
00755 }
00756
00757
00758 double EmcRecParameter::ErrMC(double eg, double theid) const
00759 {
00760
00761 if(eg<E25min(int(theid))) eg=E25min(int(theid));
00762 if(eg>E25max(int(theid))) eg=E25max(int(theid))-0.001;
00763 if(theid<=0)theid=0.001;
00764 if(theid>=27)theid=26.999;
00765 Float_t einter = eg + 0.00001;
00766 Float_t tinter = theid+0.0001;
00767 double err=dtErr->Interpolate(einter,tinter);
00768 return err;
00769 }
00770
00771 double EmcRecParameter::E25min(int n) const
00772 {
00773 return e25min[n];
00774 }
00775 double EmcRecParameter::E25max(int n) const
00776 {
00777 return e25max[n];
00778 }