void slice_all(){ int run_number = 61917; gStyle->SetOptStat(0); FILE *file1 = fopen("tagh_en.txt","r"); // int min_ch = 150; // int max_ch = 200; int min_ch = 1; int max_ch = 275; // int max_ch = 103; Int_t ind[300]; Float_t emin[300], emax[300]; Double_t tagh_en[300]; Double_t ntagm[300]; Double_t ntagm_er[300]; Double_t ntagh[300]; Double_t accept[300]; Double_t ex[300]; Double_t ey[300]; memset(ntagm,0,sizeof(ntagm)); memset(ntagm_er,0,sizeof(ntagm_er)); memset(accept,0,sizeof(accept)); memset(ex,0,sizeof(ex)); memset(ey,0,sizeof(ey)); Float_t beam_en = 11.6; // TFile *file = new TFile ("61914.root","R"); // TFile *file = new TFile ("61914_new_new.root","R"); // TFile *file = new TFile ("../61915.root","R"); // TFile *file = new TFile ("../61917.root","R"); // TFile *file = new TFile ("../61950.root","R"); TFile *file = new TFile ("../61914.root","R"); // TFile *file = new TFile ("../61340.root","R"); // TFile *file = new TFile ("../61868.root","R"); TFile *file10 = new TFile ("empty_target_all.root","R"); TH2F *comp_tagh = (TH2F*)file->Get("comp_tagh"); TH2F *comp_tagh_bg = (TH2F*)file->Get("comp_tagh_bg"); TH2F *empty_tagh = (TH2F*)file10->Get("comp_tagh"); TH2F *empty_tagh_bg = (TH2F*)file10->Get("comp_tagh_bg"); TH1 *htagh[300]; TH1 *htagh_bg[300]; TH1 *htagh_subt[300]; TH1 *htagh_empty[300]; TH1 *htagh_bg_empty[300]; TH1 *htagh_subt_empty[300]; Int_t ii = 0; while (!feof(file1)){ fscanf(file1,"%d %f %f \n",&ind[ii], &emin[ii], &emax[ii]); tagh_en[ii] = beam_en*(emin[ii] + emax[ii])/2.; cout << ind[ii] << " x = " << emin[ii] << " " << emax[ii] << " TAGH energy = " << tagh_en[ii] << endl; ii++; } fclose(file1); TCanvas *c1 = new TCanvas("c1","c1", 200, 10, 800, 400); comp_tagh->Draw(); TF1 *f0 = new TF1("f0","gaus",-2,2); for(int ii = min_ch; ii < max_ch; ii++){ char title[30]; sprintf(title,"tagh%d",ii); htagh[ii] = comp_tagh->ProjectionY(title,ii,ii); sprintf(title,"tagh_bg%d",ii); htagh_bg[ii] = comp_tagh_bg->ProjectionY(title,ii,ii); htagh_subt[ii] = (TH1F*) htagh[ii]->Clone(); htagh_subt[ii]->Add(htagh_bg[ii],-1); // Empty target background sprintf(title,"tagh_empty%d",ii); htagh_empty[ii] = empty_tagh->ProjectionY(title,ii,ii); sprintf(title,"tagh_bg_empty%d",ii); htagh_bg_empty[ii] = empty_tagh_bg->ProjectionY(title,ii,ii); htagh_subt_empty[ii] = (TH1F*) htagh_empty[ii]->Clone(); htagh_subt_empty[ii]->Add(htagh_bg_empty[ii],-1); // htagh_subt_empty[ii]->Scale(0.0868); // htagh_subt_empty[ii]->Scale(0.097); // htagh_subt_empty[ii]->Scale(0.0422); // Run 61340 htagh_subt_empty[ii]->Scale(0.037); // Run 61868 // htagh_subt_empty[ii]->Scale(0.0693); htagh_subt[ii]->Add(htagh_subt_empty[ii],-1); // htagh[ii]->Draw(); htagh_subt[ii]->SetLineColor(4); htagh_subt[ii]->Draw("histo"); // htagh_bg[ii]->SetFillColor(4); // htagh_subt_empty[ii]->SetFillColor(2); // htagh_bg[ii]->Draw("same"); // htagh_subt_empty[ii]->Draw("hsame"); htagh_subt[ii]->GetXaxis()->SetRangeUser(-1.8,0.6); c1->Update(); // getchar(); Int_t entries = htagh_subt[ii]->GetEntries(); if(entries > 0){ // I. Search for peak Int_t max_bin = 0; Int_t max_amp = 0; for(int jj = 1; jj < 150; jj++){ Int_t cont = htagh_subt[ii]->GetBinContent(jj); if(cont > max_amp){ max_amp = cont; max_bin = jj; } } f0->SetParameters(0,0); f0->SetParameters(1,0); f0->SetParameters(2,0.1); // (alpha, n sigma, mu) auto f2 = new TF1("f2","crystalball",-1,1); f2->SetParameters(max_amp, 0, 0.2, 1, 0.5); cout << " MAX amp = " << max_amp << endl; htagh_subt[ii]->Fit("f0","","",-1.,1.); htagh_subt[ii]->Fit("f2","L","",-1.5,0.5); htagh_subt[ii]->Draw(); cout << " GAUS " << 20*f0->Integral(-1,1) << endl; cout << " CB " << 20*f2->Integral(-1.5,0.5) << endl; ntagm[ii] = 20*f2->Integral(-1.5,0.5); if(f2->GetParameter(0) > 0) ntagm_er[ii] = ntagm[ii]* (f2->GetParError(0)/f2->GetParameter(0)); else ntagm_er[ii] = 1000; int firstbin = htagh_subt[ii]->GetXaxis()->FindBin(-1); int lastbin = htagh_subt[ii]->GetXaxis()->FindBin(1); cout << " ENTRIES = " << htagh_subt[ii]->Integral(firstbin,lastbin); c1->Update(); // getchar(); } } #if 0 cout << endl; cout << endl; // FILE *data_file = fopen("rrr_tagh.txt","w"); // FILE *data_file = fopen("rrr_tagm_new.txt","w"); // FILE *data_file = fopen("comp_61914_tagh.txt","w"); // FILE *data_file = fopen("comp_61914_tagm.txt","w"); // FILE *data_file = fopen("comp_61914_tagm_n.txt","w"); FILE *data_file = fopen("comp_61914_tagh_n.txt","w"); // FILE *data_file = fopen("comp_61915_tagh_new.txt","w"); // FILE *data_file = fopen("comp_61915_tagm.txt","w"); // FILE *data_file = fopen("comp_61917_tagh.txt","w"); // FILE *data_file = fopen("comp_61917_tagm.txt","w"); // FILE *data_file = fopen("comp_61950_tagh.txt","w"); // FILE *data_file = fopen("comp_61950_tagm.txt","w"); // FILE *data_file = fopen("comp_61340_tagh.txt","w"); // FILE *data_file = fopen("comp_61340_tagm.txt","w"); // FILE *data_file = fopen("comp_61868_tagh.txt","w"); // FILE *data_file = fopen("comp_61868_tagm.txt","w"); cout << " FIT RESULTS " << endl; // for(int ii = 1; ii < 275; ii++){ // for(int ii = 1; ii < 103; ii++){ for(int ii = min_ch; ii < max_ch; ii++){ cout << ii << " " << ntagm[ii] << " " << ntagm_er[ii] << endl; fprintf(data_file, "%4d %10.3f %10.3f \n",ii, ntagm[ii], ntagm_er[ii]); } #endif }