File indexing completed on 2025-08-05 08:13:34
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include <Riostream.h>
0014 #include <stdio.h>
0015 #include <fstream>
0016 #include <sstream>
0017 #include <string>
0018
0019 #include <TMath.h>
0020 #include <TEnv.h>
0021 #include <TH2F.h>
0022 #include <TH1F.h>
0023 #include <TTree.h>
0024 #include <TDatabasePDG.h>
0025 #include <TStyle.h>
0026 #include <TLine.h>
0027 #include <TEllipse.h>
0028 #include <TCanvas.h>
0029 #include <TProfile.h>
0030 #include <TH1D.h>
0031 #include <TH3F.h>
0032 #include <TF1.h>
0033 #include <TText.h>
0034 #include <TLegend.h>
0035 #include <TChain.h>
0036 #include <TString.h>
0037 #include <TLorentzVector.h>
0038 #include <TRandom.h>
0039 #include <TMatrixTBase.h>
0040 #include <TMatrixT.h>
0041 #include "TPaveText.h"
0042 #include <TGraphErrors.h>
0043 #include <TFile.h>
0044 #include <TTree.h>
0045 #include <TSpline.h>
0046 #include <TFrame.h>
0047
0048 using namespace std;
0049
0050 class eic_bnl_rich {
0051
0052 private:
0053
0054 public:
0055
0056 Double_t ind_ray(double Ex, double Ey, double Ez, double Dx, double Dy, double Dz, double cx, double cy, double cz, double vx, double vy, double vz);
0057
0058 void acq(string input_filename, int ind, int pix_lab, int part);
0059 Double_t momentum, ch, ch_v[500];
0060 Double_t c_mean, c_rms, p_ang;
0061 Int_t sec;
0062
0063 double qe(double energy);
0064
0065 void read(string input_filename);
0066
0067 };
0068
0069 Double_t eic_bnl_rich::ind_ray(double Ex, double Ey, double Ez, double Dx, double Dy, double Dz, double cx, double cy, double cz, double vx, double vy, double vz){
0070
0071
0072
0073
0074
0075
0076
0077 LongDouble_t cex,cey,cez;
0078 LongDouble_t cdx,cdy,cdz;
0079
0080 Int_t i,iwhere;
0081
0082 LongDouble_t th,a,d;
0083 LongDouble_t x,dx;
0084
0085 LongDouble_t y,y1;
0086
0087 LongDouble_t eps = 0.00000000001;
0088 LongDouble_t R = 195.;
0089
0090
0091
0092
0093 Double_t sx,sy,sz;
0094 Double_t esx,esy,esz;
0095 Double_t es, theta_c;
0096
0097 cex = -cx+Ex;
0098 cey = -cy+Ey;
0099 cez = -cz+Ez;
0100
0101 cdx = -cx+Dx;
0102 cdy = -cy+Dy;
0103 cdz = -cz+Dz;
0104
0105
0106
0107
0108 a = TMath::Sqrt(cex*cex+cey*cey+cez*cez);
0109 d = TMath::Sqrt(cdx*cdx+cdy*cdy+cdz*cdz);
0110 th = TMath::ACos((cdx*cex+cdy*cey+cdz*cez)/a/d);
0111
0112
0113
0114 i = 0;
0115 x = th/2.;
0116
0117 y = R*(a*sin(x)-d*sin(th-x))+a*d*sin(th-2*x);
0118 y1 = R*(a*cos(x)+d*cos(th-x))-2*a*d*cos(th-2*x);
0119
0120
0121 dx = -y/y1;
0122
0123 while(TMath::Abs(dx)>eps && i<100){
0124
0125 x+=dx;
0126 y = R*(a*sin(x)-d*sin(th-x))+a*d*sin(th-2*x);
0127 y1 = R*(a*cos(x)+d*cos(th-x))-2*a*d*cos(th-2*x);
0128
0129 dx = -y/y1;
0130 i++;
0131
0132 }
0133
0134
0135
0136 if(i<100){
0137 sx = cx + (R*cos(x)/a-R*sin(x)/tan(th)/a)*cex + (R*sin(x)/d/sin(th))*cdx;
0138 sy = cy + (R*cos(x)/a-R*sin(x)/tan(th)/a)*cey + (R*sin(x)/d/sin(th))*cdy;
0139 sz = cz + (R*cos(x)/a-R*sin(x)/tan(th)/a)*cez + (R*sin(x)/d/sin(th))*cdz;
0140
0141 }
0142
0143 esx = sx - Ex;
0144 esy = sy - Ey;
0145 esz = sz - Ez;
0146
0147
0148
0149 es = sqrt(esx*esx+esy*esy+esz*esz);
0150
0151 esx = esx/es;
0152 esy = esy/es;
0153 esz = esz/es;
0154
0155 theta_c = TMath::ACos((esx*vx+esy*vy+esz*vz));
0156
0157 return theta_c;
0158
0159 }
0160
0161 double eic_bnl_rich::qe(double energy){
0162
0163 Double_t qe = 0.;
0164
0165 qe = 12.5*(energy-6.2);
0166 if(energy>10.3) qe = 0.;
0167
0168 return qe;
0169
0170 }
0171
0172 void eic_bnl_rich::acq(string input_filename, int ind, int pix_lab, int part){
0173
0174 c_mean = 0.;
0175 c_rms = 0.;
0176 p_ang = 0.;
0177
0178 Double_t rtd = 180./TMath::Pi();
0179
0180 TFile *file=new TFile(input_filename.c_str());
0181 if (file->IsZombie()) {
0182 cout << "Error opening file" << input_filename << endl;
0183 exit(-1);
0184 }
0185
0186
0187 TTree *eic_rich = (TTree*) file->Get("eval_rich");
0188
0189 Int_t eic_rich_event=0,eic_rich_bankid=0,eic_rich_volumeid=0,eic_rich_hitid=0,*eic_rich_pid=0,eic_rich_mpid=0,eic_rich_trackid=0,eic_rich_mtrackid=0,eic_rich_otrackid=0;
0190 Double_t eic_rich_hit_x=0,eic_rich_hit_y=0,eic_rich_hit_z=0, eic_rich_emi_x=0, eic_rich_emi_y=0, eic_rich_emi_z=0,eic_rich_px=0,eic_rich_py=0,eic_rich_pz=0,eic_rich_mpx=0,eic_rich_mpy=0,eic_rich_mpz=0,eic_rich_e=0,eic_rich_me=0,eic_rich_edep=0;
0191
0192 eic_rich->SetBranchAddress("event",&eic_rich_event);
0193 eic_rich->SetBranchAddress("hit_x",&eic_rich_hit_x);
0194 eic_rich->SetBranchAddress("hit_y",&eic_rich_hit_y);
0195 eic_rich->SetBranchAddress("hit_z",&eic_rich_hit_z);
0196 eic_rich->SetBranchAddress("emi_x",&eic_rich_emi_x);
0197 eic_rich->SetBranchAddress("emi_y",&eic_rich_emi_y);
0198 eic_rich->SetBranchAddress("emi_z",&eic_rich_emi_z);
0199 eic_rich->SetBranchAddress("px",&eic_rich_px);
0200 eic_rich->SetBranchAddress("py",&eic_rich_py);
0201 eic_rich->SetBranchAddress("pz",&eic_rich_pz);
0202 eic_rich->SetBranchAddress("mpx",&eic_rich_mpx);
0203 eic_rich->SetBranchAddress("mpy",&eic_rich_mpy);
0204 eic_rich->SetBranchAddress("mpz",&eic_rich_mpz);
0205 eic_rich->SetBranchAddress("e",&eic_rich_e);
0206 eic_rich->SetBranchAddress("me",&eic_rich_me);
0207 eic_rich->SetBranchAddress("edep",&eic_rich_edep);
0208 eic_rich->SetBranchAddress("bankid",&eic_rich_bankid);
0209 eic_rich->SetBranchAddress("volumeid",&eic_rich_volumeid);
0210 eic_rich->SetBranchAddress("hitid",&eic_rich_hitid);
0211 eic_rich->SetBranchAddress("pid",&eic_rich_pid);
0212 eic_rich->SetBranchAddress("mpid",&eic_rich_mpid);
0213 eic_rich->SetBranchAddress("trackid",&eic_rich_trackid);
0214 eic_rich->SetBranchAddress("mtrackid",&eic_rich_mtrackid);
0215 eic_rich->SetBranchAddress("otrackid",&eic_rich_otrackid);
0216
0217 TRandom rran;
0218 rran.SetSeed(0);
0219 Int_t ev_count[61];
0220 for(Int_t i=0;i<61;i++) ev_count[i]=0;
0221 Int_t ph_count = 0;
0222 Int_t ph_ch_count = 0;
0223
0224 TH2F *ph_det = new TH2F("ph_det","", 1666, -250., 250., 1666, -250., 250.);
0225 TH2F *ph_det1 = new TH2F("ph_det1","", 1666, -250., 250., 1666, -250., 250.);
0226 Double_t momvv_x[10000];
0227 Double_t momvv_y[10000];
0228 Double_t momvv_z[10000];
0229
0230 TH1F *h = new TH1F("","",1000,-70,70);
0231 TH1F *spectrum_ev = new TH1F("","",1000,4.,12.);
0232 TH1F *spectrum_nm = new TH1F("","",1000,100.,300.);
0233 TH1F *ch_ang = new TH1F("","",1000,0.,0.3);
0234 Double_t ang_cut = 0.;
0235 Double_t momv[3] = {0.,0.,0.};
0236
0237 Double_t m_emi[3] = {0.,0.,0.};
0238 Double_t d_hit[3] = {0.,0.,0.};
0239 Double_t xbin = 0.;
0240 Double_t ybin = 0.;
0241 Double_t theta = 0.;
0242 Double_t phi = 0.;
0243 Double_t rr[3] = {0.,0.,0.};
0244 Double_t theta_cc = 0.;
0245 Double_t m[4]={0.000511, 0.13957018, 0.493677, 0.938272};
0246 Double_t em[3][10000];
0247 Double_t vv = 0.;
0248 Int_t imom = 0;
0249 Double_t mom_check = 999.;
0250 Int_t event_check = 1.;
0251 Int_t event_check1 = 1.;
0252 Int_t nph_count = 0;
0253
0254
0255
0256
0257
0258 TH1F **ch_pi_h;
0259 ch_pi_h=new TH1F*[61];
0260 for(Int_t i=0;i<61;i++){
0261 ch_pi_h[i] = new TH1F(Form("ch_pi_h%d",i),"",10000,0,0.3);
0262 }
0263 TH1F *h_mom = new TH1F("","",100,0.,100.);
0264
0265
0266 for(Int_t i=0;(i<eic_rich->GetEntries());i++){
0267
0268 eic_rich->GetEntry(i);
0269
0270 if(eic_rich_event<=ind){
0271
0272 ph_count++;
0273
0274 em[0][ph_count-1] = eic_rich_emi_x;
0275 em[1][ph_count-1] = eic_rich_emi_y;
0276 em[2][ph_count-1] = eic_rich_emi_z;
0277
0278
0279
0280 vv = sqrt((em[0][11]-em[0][0])*(em[0][11]-em[0][0])+(em[1][11]-em[1][0])*(em[1][11]-em[1][0])+(em[2][11]-em[2][0])*(em[2][11]-em[2][0]));
0281
0282 if(ph_count>50){
0283 momvv_x[eic_rich_event-1]=(em[0][11]-em[0][0])/vv;
0284 momvv_y[eic_rich_event-1]=(em[1][11]-em[1][0])/vv;
0285 momvv_z[eic_rich_event-1]=(em[2][11]-em[2][0])/vv;
0286 }
0287 if(eic_rich_event!=event_check){
0288 ph_count=0;
0289 event_check = eic_rich_event;
0290
0291 }
0292 }
0293 }
0294
0295 for(Int_t i=0;(i<eic_rich->GetEntries());i++){
0296
0297 eic_rich->GetEntry(i);
0298
0299
0300
0301
0302 ang_cut = TMath::ACos(eic_rich_mpz/sqrt(eic_rich_mpx*eic_rich_mpx+eic_rich_mpy*eic_rich_mpy+eic_rich_mpz*eic_rich_mpz))*rtd;
0303
0304
0305
0306
0307 if(eic_rich_event<=ind){
0308
0309 momentum = sqrt(eic_rich_mpx*eic_rich_mpx+eic_rich_mpy*eic_rich_mpy+eic_rich_mpz*eic_rich_mpz);
0310 imom = momentum;
0311 if (imom == 0)
0312 continue;
0313 theta_cc = acos(sqrt(imom*imom+m[part]*m[part])/imom/1.00054);
0314
0315 momv[0] = momvv_x[eic_rich_event-1];
0316 momv[1] = momvv_y[eic_rich_event-1];
0317 momv[2] = momvv_z[eic_rich_event-1];
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331 theta = TMath::ACos(momv[2]);
0332 phi = TMath::ATan2(momv[1],momv[0]);
0333
0334 p_ang = theta*rtd;
0335
0336
0337
0338
0339 m_emi[0] = ((220.)/momv[2])*momv[0];
0340 m_emi[1] = ((220.)/momv[2])*momv[1];
0341 m_emi[2] = ((220.)/momv[2])*momv[2];
0342
0343
0344
0345
0346
0347 d_hit[0] = eic_rich_hit_x;
0348 d_hit[1] = eic_rich_hit_y;
0349 d_hit[2] = eic_rich_hit_z;
0350
0351 xbin = ph_det->GetXaxis()->FindBin(eic_rich_hit_x);
0352 ybin = ph_det->GetYaxis()->FindBin(eic_rich_hit_y);
0353
0354 if(pix_lab!=0)d_hit[0] = ph_det->GetXaxis()->GetBinCenter(xbin);
0355 if(pix_lab!=0)d_hit[1] = ph_det->GetYaxis()->GetBinCenter(ybin);
0356
0357 ph_det->Fill(d_hit[0],d_hit[1]);
0358
0359
0360
0361
0362
0363
0364
0365 rr[0] = -18.5*TMath::Sin(eic_rich_volumeid*TMath::Pi()/4.);
0366 rr[1] = 18.5*TMath::Cos(eic_rich_volumeid*TMath::Pi()/4.);
0367 rr[2] = 75.;
0368 sec = eic_rich_volumeid;
0369
0370
0371
0372 ch = ind_ray(m_emi[0], m_emi[1], m_emi[2], d_hit[0], d_hit[1], d_hit[2], rr[0], rr[1], rr[2], momv[0], momv[1], momv[2]);
0373
0374 ph_ch_count++;
0375
0376
0377
0378
0379
0380 if(ch<(theta_cc+0.008) && ch>(theta_cc-0.008) && theta*rtd>15. && theta*rtd<16.){
0381
0382 ch_pi_h[imom]->Fill(ch);
0383 spectrum_nm->Fill(1240./(eic_rich_edep*1000000000.));
0384
0385 ph_det1->Fill(d_hit[0],d_hit[1]);
0386
0387
0388
0389 if(momentum!=mom_check){
0390 h_mom->Fill(imom);
0391 ev_count[imom]++;
0392
0393
0394
0395 mom_check=momentum;
0396 }
0397 }
0398
0399 if(eic_rich_event!=event_check1){
0400
0401
0402 ph_det->Reset();
0403 event_check1 = eic_rich_event;
0404
0405 }
0406 }
0407
0408 }
0409
0410
0411
0412
0413
0414
0415
0416
0417
0418 Int_t summm=0;
0419
0420 ofstream out("pid_test.txt", ios::app);
0421 streambuf *coutbuf = cout.rdbuf();
0422 cout.rdbuf(out.rdbuf());
0423
0424 for(Int_t i=0;i<61;i++){
0425 if(ch_pi_h[i]->GetEntries()!=0)cout<<ch_pi_h[i]->GetMean()<<" "<<ch_pi_h[i]->GetRMS()<<" "<<(int)(ch_pi_h[i]->GetEntries()/ev_count[i])<<" "<<i<<" "<<part<<endl;
0426 else if(i<60)cout<<ch_pi_h[i]->GetMean()<<" "<<ch_pi_h[i]->GetRMS()<<" "<<0<<" "<<i<<" "<<part<<endl;
0427 summm = summm + ev_count[i];
0428 }
0429
0430
0431
0432 ph_det1->Draw("colz");
0433 ch_pi_h[45]->Draw();
0434
0435
0436
0437
0438
0439 }
0440
0441
0442 void eic_bnl_rich::read(string input_filename){
0443
0444 ifstream inputFile;
0445 inputFile.open(input_filename);
0446 if (!inputFile) {
0447 cerr << "Error in opening the file";
0448 exit(1);
0449 }
0450
0451 Double_t theta_ch, sigma_theta, nph, momentum, ptype;
0452 Double_t ch_e_v[60],rms_e_v[60],nph_e_v[60],mom_e_v[60];
0453 Double_t ch_pi_v[60],rms_pi_v[60],nph_pi_v[60],mom_pi_v[60];
0454 Double_t ch_k_v[60],rms_k_v[60],nph_k_v[60],mom_k_v[60];
0455 Double_t ch_p_v[60],rms_p_v[60],nph_p_v[60],mom_p_v[60];
0456 Double_t n_sig_e_pi[60],n_sig_pi_k[60],n_sig_k_p[60],mm_e_pi[60],mm_pi_k[60],mm_k_p[60];
0457 Int_t idx[4] = {0,0,0,0};
0458
0459 while (inputFile>>theta_ch>>sigma_theta>>nph>>momentum>>ptype){
0460
0461 if(ptype==0){
0462 ch_e_v[idx[0]]=theta_ch;
0463 rms_e_v[idx[0]]=sigma_theta;
0464 nph_e_v[idx[0]]=nph*0.6;
0465 if(theta_ch==0) nph_e_v[idx[0]]=0;
0466 mom_e_v[idx[0]]=momentum;
0467 idx[0]++;
0468 }
0469 if(ptype==1){
0470 ch_pi_v[idx[1]]=theta_ch;
0471 rms_pi_v[idx[1]]=sigma_theta;
0472 nph_pi_v[idx[1]]=nph*0.6;
0473 if(theta_ch==0) nph_pi_v[idx[1]]=0;
0474 mom_pi_v[idx[1]]=momentum;
0475 idx[1]++;
0476 }
0477 if(ptype==2){
0478 ch_k_v[idx[2]]=theta_ch;
0479 rms_k_v[idx[2]]=sigma_theta;
0480 nph_k_v[idx[2]]=nph*0.6;
0481 if(theta_ch==0) nph_k_v[idx[2]]=0;
0482 mom_k_v[idx[2]]=momentum;
0483 idx[2]++;
0484 }
0485 if(ptype==3){
0486 ch_p_v[idx[3]]=theta_ch;
0487 rms_p_v[idx[3]]=sigma_theta;
0488 nph_p_v[idx[3]]=nph*0.6;
0489 if(theta_ch==0) nph_p_v[idx[3]]=0;
0490 mom_p_v[idx[3]]=momentum;
0491 idx[3]++;
0492 }
0493
0494
0495 }
0496
0497 Int_t ii=0;
0498 Int_t iii=0;
0499 Int_t iiii=0;
0500
0501 for(Int_t i=0;i<idx[0];i++){
0502
0503 if(ch_e_v[i]!=0 && ch_pi_v[i]!=0 && i>2){
0504 n_sig_e_pi[ii] = (ch_e_v[i]-ch_pi_v[i])*sqrt((nph_e_v[i]+nph_pi_v[i])*0.5)/((rms_e_v[i]+rms_pi_v[i])*0.5);
0505 mm_e_pi[ii] = mom_e_v[i]+0.5;
0506
0507 ii++;
0508 }
0509 if(ch_pi_v[i]!=0 && ch_k_v[i]!=0 && i>16){
0510 n_sig_pi_k[iii] = (ch_pi_v[i]-ch_k_v[i])*sqrt((nph_pi_v[i]+nph_k_v[i])*0.5)/((rms_pi_v[i]+rms_k_v[i])*0.5);
0511 mm_pi_k[iii] = mom_pi_v[i]+0.5;
0512
0513
0514 iii++;
0515 }
0516 if(ch_k_v[i]!=0 && ch_p_v[i]!=0 && i>30){
0517 n_sig_k_p[iiii] = (ch_k_v[i]-ch_p_v[i])*sqrt((nph_k_v[i]+nph_p_v[i])*0.5)/((rms_k_v[i]+rms_p_v[i])*0.5);
0518 mm_k_p[iiii] = mom_k_v[i]+0.5;
0519
0520 iiii++;
0521 }
0522
0523
0524
0525 }
0526
0527 TGraph *sig_pi = new TGraph(idx[1],mom_pi_v,rms_pi_v);
0528 TGraph *nph_pi = new TGraph(idx[1],mom_pi_v,nph_pi_v);
0529
0530 TGraph *gr_e_pi = new TGraph(ii,mm_e_pi,n_sig_e_pi);
0531 TGraph *gr_pi_k = new TGraph(iii,mm_pi_k,n_sig_pi_k);
0532 TGraph *gr_k_p = new TGraph(iiii,mm_k_p,n_sig_k_p);
0533
0534 TCanvas *c1 = new TCanvas("c1","",1000,600);
0535 c1->Divide(1,1);
0536 c1->cd(1);
0537 gr_e_pi->SetLineStyle(2);
0538 gr_e_pi->SetLineWidth(2);
0539 gr_e_pi->SetLineColor(kGreen);
0540 gr_e_pi->SetMarkerColor(kGreen);
0541 gr_e_pi->SetTitle("");
0542 gr_e_pi->GetXaxis()->SetTitle("Momentum [Gev/c]");
0543 gr_e_pi->GetYaxis()->SetTitle("N_{#sigma}^{Ring}");
0544 gr_e_pi->Draw("AC*");
0545 gr_pi_k->SetLineStyle(3);
0546 gr_pi_k->SetLineWidth(2);
0547 gr_pi_k->SetLineColor(kRed);
0548 gr_pi_k->SetMarkerColor(kRed);
0549 gr_pi_k->SetTitle("");
0550 gr_pi_k->Draw("C*");
0551 gr_k_p->SetLineStyle(4);
0552 gr_k_p->SetLineWidth(2);
0553 gr_pi_k->SetLineColor(kBlue);
0554 gr_pi_k->SetMarkerColor(kBlue);
0555 gr_k_p->SetTitle("");
0556 gr_k_p->Draw("C*");
0557 c1->Print("test1.pdf","pdf");
0558
0559 for(Int_t j=0;j<iiii;j++) cout<<n_sig_k_p[j]<<" "<<mm_k_p[j]<<endl;
0560
0561 TCanvas *c2 = new TCanvas("c2","",1000,600);
0562 c2->Divide(1,1);
0563 c2->cd(1);
0564 sig_pi->SetTitle("");
0565 sig_pi->GetXaxis()->SetTitle("Momentum [Gev/c]");
0566 sig_pi->GetYaxis()->SetTitle("#sigma_{#theta_{C}}");
0567 sig_pi->Draw("AP*");
0568 c2->Print("test2.pdf","pdf");
0569
0570 TCanvas *c3 = new TCanvas("c3","",1000,600);
0571 c3->Divide(1,1);
0572 c3->cd(1);
0573 nph_pi->SetTitle("");
0574 nph_pi->GetXaxis()->SetTitle("Momentum [Gev/c]");
0575 nph_pi->GetYaxis()->SetTitle("N_{p.e.}");
0576 nph_pi->Draw("AP*");
0577 c3->Print("test3.pdf","pdf");
0578
0579 }