Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:20:34

0001 #include "/phenix/u/shlim/Style.h"
0002 
0003 void Draw(const int runnumber=28, const int segnumber=200){
0004 
0005     int bPOST_ALIGN = false;
0006     int bPRE_ALIGN = false;
0007 
0008     float z_min = 200;
0009     float z_max = 800;
0010     float x_min = 200;
0011     float x_max = 500;
0012 
0013     gStyle->SetOptStat(0);
0014 
0015     const int nColor[4] = {1, 2, 4, 8};
0016 
0017     TFile *infile = new TFile(Form("MvtxQAHisto-%08d-%04d.root",runnumber,segnumber),"read");
0018 
0019     TH2F *h2d_hit[4];
0020     TH2F *h2d_hit_trk[4];
0021     TH1F *h1d_hit_per_evt[4];
0022     TH1F *h1d_hit_x[4];
0023     TH1F *h1d_hit_y[4];
0024     TH1F *h1d_hit_trk_x[4];
0025     TH1F *h1d_hit_trk_y[4];
0026 
0027     TH1F *h1d_clus_size_x[4];
0028     TH1F *h1d_clus_size_z[4];
0029     TH2F *h2d_clus[4];
0030     TH1F *h1d_clus_per_evt[4];
0031 
0032     TH1F *h1d_clus_res_x[4];
0033     TH1F *h1d_clus_res_z[4];
0034     TProfile *h1p_clus_res_x[4];
0035     TProfile *h1p_clus_res_z[4];
0036 
0037     TF1 *f1p_clus_res_x[4];
0038     TF1 *f1p_clus_res_z[4];
0039 
0040 
0041     for (int ichip=0; ichip<4; ichip++){
0042         h2d_hit[ichip] = (TH2F*)infile->Get(Form("h2d_hit_chip%d",ichip));
0043         h2d_hit_trk[ichip] = (TH2F*)infile->Get(Form("h2d_hit_trk_chip%d",ichip));
0044         h1d_hit_per_evt[ichip] = (TH1F*)infile->Get(Form("h1d_hit_per_evt_chip%d",ichip));
0045 
0046         h1d_hit_x[ichip] = (TH1F*)h2d_hit[ichip]->ProjectionX(Form("h1d_hit_x_chip%d",ichip));
0047         h1d_hit_y[ichip] = (TH1F*)h2d_hit[ichip]->ProjectionY(Form("h1d_hit_y_chip%d",ichip));
0048         h1d_hit_x[ichip]->SetLineColor(1);
0049         h1d_hit_y[ichip]->SetLineColor(1);
0050 
0051         h1d_hit_trk_x[ichip] = (TH1F*)h2d_hit_trk[ichip]->ProjectionX(Form("h1d_hit_trk_x_chip%d",ichip));
0052         h1d_hit_trk_y[ichip] = (TH1F*)h2d_hit_trk[ichip]->ProjectionY(Form("h1d_hit_trk_y_chip%d",ichip));
0053         h1d_hit_trk_x[ichip]->SetLineColor(1);
0054         h1d_hit_trk_y[ichip]->SetLineColor(1);
0055 
0056         h2d_clus[ichip] = (TH2F*)infile->Get(Form("h2d_clus_chip%d",ichip));
0057 
0058         h1d_clus_size_x[ichip] = (TH1F*)infile->Get(Form("h1d_clus_size_x_chip%d",ichip));
0059         h1d_clus_size_z[ichip] = (TH1F*)infile->Get(Form("h1d_clus_size_z_chip%d",ichip));
0060 
0061         h1d_clus_per_evt[ichip] = (TH1F*)infile->Get(Form("h1d_clus_per_evt_chip%d",ichip));
0062 
0063         h1d_clus_size_x[ichip]->SetLineColor(1);
0064         h1d_clus_size_z[ichip]->SetLineColor(2);
0065 
0066         h1d_clus_res_x[ichip] = (TH1F*)infile->Get(Form("h1d_clus_res_x_chip%d",ichip));
0067         h1d_clus_res_z[ichip] = (TH1F*)infile->Get(Form("h1d_clus_res_z_chip%d",ichip));
0068 
0069         h1d_clus_res_x[ichip]->SetLineColor(nColor[ichip]);
0070         h1d_clus_res_z[ichip]->SetLineColor(nColor[ichip]);
0071 
0072         h1p_clus_res_x[ichip] = (TProfile*)infile->Get(Form("h1p_clus_res_x_chip%d",ichip));
0073         h1p_clus_res_z[ichip] = (TProfile*)infile->Get(Form("h1p_clus_res_z_chip%d",ichip));
0074 
0075         h1p_clus_res_x[ichip]->SetLineColor(nColor[ichip]);
0076         h1p_clus_res_z[ichip]->SetLineColor(nColor[ichip]);
0077     }
0078 
0079     TH1F *h1d_clus_eff = (TH1F*)infile->Get("h1d_clus_eff");
0080     TH1F *h1d_clus_associated = (TH1F*)infile->Get("h1d_clus_associated");
0081 
0082     TCanvas *c0 = new TCanvas("c0","c0",1.1*2*400,400);
0083     c0->Divide(2,1);
0084 
0085     c0->cd(1);
0086     SetPadStyle();
0087     gPad->SetLogy();
0088 
0089     htmp = (TH1F*)gPad->DrawFrame(0,1,50,1.5*h1d_hit_per_evt[0]->GetMaximum());
0090     SetHistoStyle();
0091 
0092     for (int ichip=0; ichip<4; ichip++){
0093         h1d_hit_per_evt[ichip]->SetLineColor(nColor[ichip]);
0094         h1d_hit_per_evt[ichip]->SetLineWidth(2);
0095         h1d_hit_per_evt[ichip]->Draw("same");
0096     }
0097 
0098     c0->cd(2);
0099     SetPadStyle();
0100     gPad->SetLogy();
0101 
0102     htmp = (TH1F*)gPad->DrawFrame(0,1,10,1.5*h1d_clus_per_evt[0]->GetMaximum());
0103     SetHistoStyle();
0104 
0105     for (int ichip=0; ichip<4; ichip++){
0106         h1d_clus_per_evt[ichip]->SetLineColor(nColor[ichip]);
0107         h1d_clus_per_evt[ichip]->SetLineWidth(2);
0108         h1d_clus_per_evt[ichip]->Draw("same");
0109     }
0110 
0111     //return;
0112     //
0113     //
0114     ofstream fpre;
0115     if ( bPRE_ALIGN ){
0116         char fname[300];
0117         sprintf(fname,"beamcenter/beamcenter_%08d.txt",runnumber);
0118         fpre.open(fname);
0119     }
0120 
0121     TCanvas *c1 = new TCanvas("c1","c1",150*1.1*3,150*4);
0122     c1->Divide(3,4);
0123 
0124     for (int ichip=0; ichip<4; ichip++){
0125 
0126         c1->cd(3*ichip+1);
0127         SetPadStyle();
0128         gPad->SetLogz();
0129 
0130         htmp = (TH1F*)h2d_hit[ichip];
0131         SetHistoStyle();
0132 
0133         htmp->Draw("col2");
0134 
0135         c1->cd(3*ichip+2);
0136         SetPadStyle();
0137 
0138         htmp = (TH1F*)h1d_hit_x[ichip];
0139         SetHistoStyle();
0140         htmp->Draw();
0141 
0142         TF1 *fx = new TF1("fx","gaus",z_min,z_max);
0143         htmp->Fit(fx,"R0Q");
0144         //fx->Draw("same");
0145 
0146         fx->SetRange(fx->GetParameter(1)-fx->GetParameter(2), fx->GetParameter(1)+fx->GetParameter(2));
0147         htmp->Fit(fx,"R0Q");
0148         fx->Draw("same");
0149 
0150         /*
0151         TF1 *fxx = new TF1("fxx","gaus(0)+gaus(3)",0,1024);
0152         fxx->SetParameter(0,fx->GetParameter(0));
0153         fxx->SetParameter(1,fx->GetParameter(1));
0154         fxx->SetParameter(2,fx->GetParameter(2));
0155         fxx->SetParameter(3,0.1*fx->GetParameter(0));
0156         fxx->FixParameter(4,fx->GetParameter(1));
0157         fxx->SetParameter(5,10.0*fx->GetParameter(2));
0158         htmp->Fit(fxx,"R0");
0159         fxx->Draw("same");
0160         */
0161 
0162         c1->cd(3*ichip+3);
0163         SetPadStyle();
0164 
0165         htmp = (TH1F*)h1d_hit_y[ichip];
0166         SetHistoStyle();
0167         htmp->Draw();
0168 
0169         TF1 *fy = new TF1("fy","gaus",x_min,x_max);
0170         htmp->Fit(fy,"R0Q");
0171         //fy->Draw("same");
0172         //
0173         fy->SetRange(fy->GetParameter(1)-fy->GetParameter(2), fy->GetParameter(1)+fy->GetParameter(2));
0174         htmp->Fit(fy,"R0Q");
0175         fy->Draw("same");
0176 
0177         /*
0178         TF1 *fyy = new TF1("fyy","gaus(0)+gaus(3)",0,1024);
0179         fyy->SetParameter(0,fy->GetParameter(0));
0180         fyy->SetParameter(1,fy->GetParameter(1));
0181         fyy->SetParameter(2,fy->GetParameter(2));
0182         fyy->SetParameter(3,0.1*fy->GetParameter(0));
0183         fyy->SetParameter(4,fy->GetParameter(1));
0184         fyy->SetParameter(5,10.0*fy->GetParameter(2));
0185         htmp->Fit(fyy,"R0Q");
0186         fyy->Draw("same");
0187         */
0188 
0189         double offset_xx = fx->GetParameter(1);
0190         double offset_yy = fy->GetParameter(1);
0191         /*
0192         if ( fabs(fxx->GetParameter(0))<fabs(fxx->GetParameter(3)) ){
0193             offset_xx = fxx->GetParameter(4);
0194         }
0195 
0196         if ( fabs(fyy->GetParameter(0))<fabs(fyy->GetParameter(3)) ){
0197             offset_yy = fyy->GetParameter(4);
0198         }
0199         */
0200 
0201         if ( bPRE_ALIGN ){
0202             fpre << ichip << " 0 " << ichip << " " << offset_yy << " " << -2.2*ichip/(28e-4) << " " << offset_xx << endl;
0203             cout << ichip << " 0 " << ichip << " " << offset_yy << " " << -2.2*ichip/(28e-4) << " " << offset_xx << endl;
0204         }
0205 
0206 
0207         /*
0208         cout 
0209             << "CHIP: " << ichip 
0210             << ", x: " << fx->GetParameter(1) 
0211             << ", sx: " << fx->GetParameter(2) 
0212             << ", y: " << fy->GetParameter(1) 
0213             << ", sy: " << fy->GetParameter(2) 
0214             << endl;
0215         */
0216 
0217     }//
0218 
0219     if ( bPRE_ALIGN ){
0220         fpre.close();
0221     }
0222 
0223     TCanvas *c3 = new TCanvas("c3","c3",200*1.1*2,200*2);
0224     c3->Divide(2,2);
0225 
0226     for (int ichip=0; ichip<4; ichip++){
0227         c3->cd(ichip+1);
0228         SetPadStyle();
0229         gPad->SetLogy();
0230 
0231         htmp = (TH1F*)gPad->DrawFrame(0,5,10,1.5*h1d_clus_size_x[ichip]->GetMaximum());
0232         SetHistoStyle();
0233 
0234         h1d_clus_size_x[ichip]->Draw("same");
0235         h1d_clus_size_z[ichip]->Draw("same");
0236 
0237 
0238     }
0239 
0240     TCanvas *c4 = new TCanvas("c4","c4",300*1.1*2,300*2);
0241     c4->Divide(2,2);
0242 
0243     c4->cd(1);
0244     SetPadStyle();
0245     gPad->SetLogy();
0246 
0247     htmp = (TH1F*)gPad->DrawFrame(-6,1,6,1.5*h1d_clus_res_z[0]->GetMaximum());
0248     SetHistoStyle("dz (pixel, 28 #mum)");
0249 
0250     for (int ichip=0; ichip<4; ichip++){
0251         h1d_clus_res_z[ichip]->SetLineWidth(2);
0252         h1d_clus_res_z[ichip]->Draw("same");
0253     }
0254 
0255     c4->cd(2);
0256     SetPadStyle();
0257     //gPad->SetLogy();
0258 
0259     htmp = (TH1F*)gPad->DrawFrame(0,-2.5,1024,+2.5);
0260     SetHistoStyle();
0261     SetHistoStyle("Column index","dz (pixel, 28 #mum)");
0262 
0263     for (int ichip=0; ichip<4; ichip++){
0264         h1p_clus_res_z[ichip]->Draw("same");
0265 
0266         f1p_clus_res_z[ichip] = new TF1(Form("f1p_clus_res_z_%d",ichip),"pol1",z_min,z_max);
0267         h1p_clus_res_z[ichip]->Fit(f1p_clus_res_z[ichip],"R0Q");
0268         f1p_clus_res_z[ichip]->SetLineColor(nColor[ichip]);
0269         if ( bPOST_ALIGN )
0270             f1p_clus_res_z[ichip]->Draw("same");
0271     }
0272 
0273     c4->cd(3);
0274     SetPadStyle();
0275     gPad->SetLogy();
0276 
0277     htmp = (TH1F*)gPad->DrawFrame(-6,1,6,1.5*h1d_clus_res_x[0]->GetMaximum());
0278     SetHistoStyle("dx (pixel, 28 #mum)");
0279 
0280     for (int ichip=0; ichip<4; ichip++){
0281         h1d_clus_res_x[ichip]->SetLineWidth(2);
0282         h1d_clus_res_x[ichip]->Draw("same");
0283     }
0284 
0285     c4->cd(4);
0286     SetPadStyle();
0287     //gPad->SetLogy();
0288 
0289     htmp = (TH1F*)gPad->DrawFrame(0,-2.5,512,+2.5);
0290     SetHistoStyle("Row index","dx (pixel, 28 #mum)");
0291 
0292     for (int ichip=0; ichip<4; ichip++){
0293         h1p_clus_res_x[ichip]->Draw("same");
0294 
0295         f1p_clus_res_x[ichip] = new TF1(Form("f1p_clus_res_x_%d",ichip),"pol1",x_min,x_max);
0296         h1p_clus_res_x[ichip]->Fit(f1p_clus_res_x[ichip],"R0Q");
0297         f1p_clus_res_x[ichip]->SetLineColor(nColor[ichip]);
0298         if ( bPOST_ALIGN )
0299             f1p_clus_res_x[ichip]->Draw("same");
0300     }
0301 
0302     if ( bPOST_ALIGN ){
0303         char fname[300];
0304         sprintf(fname,"beamcenter/beamcenter_%08d.txt",runnumber);
0305         ifstream fpar;
0306         fpar.open(fname);
0307         int tmp_layer, tmp_stave, tmp_chip;
0308         double tmp_xx, tmp_yy, tmp_zz;
0309 
0310         double par_xx[4], par_yy[4], par_zz[4];
0311 
0312         while ( fpar >> tmp_layer >> tmp_stave >> tmp_chip >> tmp_xx >> tmp_yy >> tmp_zz ){
0313             par_xx[tmp_chip] = tmp_xx;
0314             par_yy[tmp_chip] = tmp_yy;
0315             par_zz[tmp_chip] = tmp_zz;
0316         }
0317         fpar.close();
0318 
0319         ofstream fpar_out;
0320         sprintf(fname,"beamcenter/beamcenter_%08d.txt",runnumber);
0321         fpar_out.open(fname);
0322 
0323         for (int ichip=0; ichip<4; ichip++){
0324             cout 
0325                 << ichip << " " 
0326                 << "0 " 
0327                 << ichip << " " 
0328                 << par_xx[ichip] + (f1p_clus_res_x[ichip]->Eval(par_xx[0]) - f1p_clus_res_x[0]->Eval(par_xx[0])) << " "
0329                 << par_yy[ichip] << " "
0330                 << par_zz[ichip] + (f1p_clus_res_z[ichip]->Eval(par_zz[0]) - f1p_clus_res_z[0]->Eval(par_zz[0]))
0331                 << endl;
0332 
0333             fpar_out
0334                 << ichip << " " 
0335                 << "0 " 
0336                 << ichip << " " 
0337                 << par_xx[ichip] + (f1p_clus_res_x[ichip]->Eval(par_xx[0]) - f1p_clus_res_x[0]->Eval(par_xx[0])) << " "
0338                 << par_yy[ichip] << " "
0339                 << par_zz[ichip] + (f1p_clus_res_z[ichip]->Eval(par_zz[0]) - f1p_clus_res_z[0]->Eval(par_zz[0]))
0340                 << endl;
0341         }
0342         fpar_out.close();
0343     }
0344 
0345 
0346     /*
0347     TCanvas *c3 = new TCanvas("c3","c3",150*1.1*4,150*2);
0348     c3->Divide(4,2);
0349 
0350     for (int ichip=0; ichip<4; ichip++){
0351 
0352         c3->cd(ichip+1);
0353         SetPadStyle();
0354         gPad->SetLogy();
0355 
0356         htmp = (TH1F*)h1d_hit_trk_x[ichip];
0357         SetHistoStyle();
0358 
0359         TF1 *fx = new TF1("fx","gaus",-5,5);
0360         htmp->Fit(fx,"R0Q");
0361 
0362         double sum = 0;
0363         for (int ii=0; ii<21; ii++){
0364             sum += fx->Eval(-10+ii);
0365         }
0366 
0367         cout << "Noise R x: " << (htmp->Integral()-sum)/htmp->Integral() << endl;
0368 
0369         htmp->SetAxisRange(-50,50);
0370         htmp->Draw("");
0371         fx->Draw("same");
0372 
0373         c3->cd(ichip+5);
0374         SetPadStyle();
0375         gPad->SetLogy();
0376 
0377         htmp = (TH1F*)h1d_hit_trk_y[ichip];
0378         SetHistoStyle();
0379 
0380         TF1 *fy = new TF1("fy","gaus",-5,5);
0381         htmp->Fit(fy,"R0Q");
0382 
0383         sum = 0;
0384         for (int ii=0; ii<21; ii++){
0385             sum += fy->Eval(-10+ii);
0386         }
0387 
0388         cout << "Noise R y: " << (htmp->Integral()-sum)/htmp->Integral() << endl;
0389 
0390         htmp->SetAxisRange(-50,50);
0391         htmp->Draw("");
0392         fy->Draw("same");
0393 
0394         //cout << "Noise R y: " << (htmp->GetEntries()-fy->Integral(-10,10))/htmp->GetEntries() << endl;
0395     }//
0396 
0397     int nevents = h1d_clus_associated->Integral(h1d_clus_associated->FindBin(3),h1d_clus_associated->GetNbinsX());
0398 
0399     h1d_clus_eff->Sumw2();
0400     h1d_clus_eff->Scale(1./nevents);
0401 
0402     TCanvas *c5 = new TCanvas("c5","c5",1.1*400,400);
0403     SetPadStyle();
0404 
0405     htmp = (TH1F*)gPad->DrawFrame(-0.5,0.95,3.5,1.02);
0406     SetHistoStyle();
0407 
0408     h1d_clus_eff->SetLineWidth(2);
0409     h1d_clus_eff->SetLineColor(1);
0410     h1d_clus_eff->Draw("same");
0411 
0412     */
0413 
0414 
0415 }