void checkInputs() { TFile fin("/mnt/sdc/andriusj/DY13TeV/DYanalysis-20160817/ElectronNtupler/test/Analysis_Codes/AccEff/dyee_preFSR_forAccEff_v1steps.root"); TH1D *h1effPass_new= loadHisto(fin,"h1_eff_sumPass","h1effPass_new",1,h1dummy); TH1D *h1effPass_chk= loadHisto(fin,"h1_eff_sumPass_chk","h1effPass_chk",1,h1dummy); TH1D *h1effPass_noTrigNoPU= loadHisto(fin,"h1_eff_sumPass_noTrigNoPU","h1effPass_noTrigNoPU",1,h1dummy); TH1D *h1effTot_new= loadHisto(fin, "h1_eff_sumTot", "h1effTot_new",1,h1dummy); fin.Close(); if (!h1effPass_new || !h1effPass_chk || !h1effPass_noTrigNoPU || !h1effTot_new) return; TFile fin2("/mnt/sdc/andriusj/DY13TeV/DYanalysis-20160817/ElectronNtupler/test/Analysis_Codes/AccEff/dyee_preFSR_forAccEff_v1.root"); TH1D *h1effPass_old= loadHisto(fin2,"h1_eff_sumPass","h1effPass_old",1,h1dummy); TH1D *h1effTot_old= loadHisto(fin2,"h1_eff_sumTot","h1effTot_old",1,h1dummy); fin2.Close(); if (!h1effPass_old || !h1effTot_old) return; histoStyle(h1effPass_chk,kRed,5,1); histoStyle(h1effPass_old,kBlue,7,1); plotHisto(h1effPass_new,"cCheck",1,0,"LPE1","new effPass"); plotHistoSame(h1effPass_chk,"cCheck","LPE1","new effPass (control)"); printRatio(h1effPass_chk,h1effPass_new); //plotHisto(h1effPass_noTrigNoPU,"cCmpOld",1,0,"LPE1","noTrigNoPU"); //plotHistoSame(h1effPass_old,"cCmpOld","LPE1","old effPass"); //printRatio(h1effPass_old,h1effPass_noTrigNoPU); plotHisto(h1effTot_new,"cCmpTot",1,0,"LPE1","new effTot"); plotHistoSame(h1effTot_old,"cCmpTot","LPE1","old effTot"); printRatio(h1effTot_old,h1effTot_new); }
int main (void) { int N = 19; int NA = 10; int m = 11; //double y0[16] = {1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0}; //std::ifstream fin("datafile.txt"); std::ifstream fin("samples.txt"); double **input_data = new double*[N]; for(int i = 0; i < N; i++) input_data[i] = new double[m]; for(int i = 0; i < N; i++){ for(int j = 0; j < m; j++){ fin>>input_data[i][j]; } } fin.close(); std::ifstream fin2("classes.txt"); double *y0 = new double[m]; for(int i = 0; i < m; i++){ fin2>>y0[i]; } fin2.close(); GMDH gmdh1 = GMDH(m, N, NA); // настройка весовых коэффициентов gmdh1.training(input_data, y0); // сохранить GMDH в файл gmdh1.saveGMDH("gmdh.dat"); /* структура файла "gmdh.dat" : | m N NA | rows_size {rows_size} X | | num_of_models CR | {num_of_models} X | id input1 input2 CR weithts[0] weithts[1] weithts[2] weithts[3] */ // загрузить GMDH из файла GMDH gmdh2 = GMDH("gmdh.dat"); gmdh2.saveGMDH("gmdh2.dat"); // проверочка double test1[11] = {0.76500000000000001, 0.52000000000000002, 0.17000000000000001, -0.16500000000000001, -0.36499999999999999, -0.435, -0.42499999999999999, -0.37, -0.33000000000000002, -0.32500000000000001, -0.33500000000000002}; std::cout<<"Normal: "<<gmdh2.testGMDH(test1)<<std::endl; //std::cout<<"High: "<<gmdh2.testGMDH(test2)<<std::endl; //std::cout<<"High: "<<gmdh2.testGMDH(test3)<<std::endl; system ("pause"); /* execute M$-DOS' pause command */ }
void main(){ fstream fin1("fitPara_vs_X.txt",ios::in); fstream fin2("allX_vs_Y.txt",ios::in); float y,x1,x2; // for fitPara_vs_X.txt float x,y1,y2; TGraph* g1 = new TGraph(); g1->SetName("sigma_vs_X"); TGraph* g2 = new TGraph(); g2->SetName("chi2_vs_X"); TGraph* g3 = new TGraph(); g3->SetName("mean_vs_Y"); TGraph* g4 = new TGraph(); g4->SetName("chi2_vs_Y"); int n1=0; int n2=0; while(fin1>>y>>x1>>x2){ if(y>=-37 && y<=-20){ g1->SetPoint(n1,x1,y); g2->SetPoint(n1,x2,y); //cout<<y<<"\t"<<x1<<"\t"<<x2<<endl; n1++; } } fin1.close(); while(fin2>>x>>y1>>y2){ g3->SetPoint(n2,x,y1); g4->SetPoint(n2,x,y2); n2++; } fin2.close(); TCanvas* c = new TCanvas(); g4->GetXaxis()->SetTitle("X offset [mm]"); g4->GetXaxis()->SetTitleSize(0.05); g4->GetXaxis()->SetLabelSize(0.05); g4->GetYaxis()->SetTitle("Y offset [mm]"); g4->GetYaxis()->SetTitleSize(0.05); g4->GetYaxis()->SetLabelSize(0.05); g1->SetMarkerStyle(24); g1->SetMarkerColor(kBlack); g2->SetMarkerStyle(25); g2->SetMarkerColor(kRed); g3->SetMarkerStyle(26); g3->SetMarkerColor(kBlue); g4->SetMarkerStyle(27); g4->SetMarkerColor(kPink); g4->GetYaxis()->SetRangeUser(-38,-20); g4->GetXaxis()->SetRangeUser(-1910,-1810); g4->Draw("AP"); g2->Draw("P"); g3->Draw("P"); g1->Draw("P"); TLegend* leg = new TLegend(0.5,0.5,0.9,0.9); leg->SetHeader("Minimizing from: "); leg->AddEntry(g1,"residual sigma vs X","lp"); leg->AddEntry(g2,"#chi^{2} vs X","lp"); leg->AddEntry(g3,"residual mean vs Y","lp"); leg->AddEntry(g4,"#chi^{2} vs Y","lp"); leg->Draw(); }
// protected void FileInputStreamTestCase::ctors (void) { FileInputStream fin (TEST_FILE_NAME); File file (TEST_FILE_NAME); FileInputStream fin2(TEST_FILE_NAME, READ_SHARE); CPPUNIT_ASSERT_THROW (FileInputStream (TEST_FILE_NAME, WRITE_SHARE), Exception); fin2.close (); fin.close (); FileInputStream fin3(TEST_FILE_NAME, NONE_SHARE); CPPUNIT_ASSERT_THROW (FileInputStream (TEST_FILE_NAME, READ_SHARE), Exception); }
void TaxPolicy::init() { std::fstream fin("./input/taxpolicy/basic_sales_tax.txt", std::ios::in); bool is_tax_rate_readed = false; unsigned int tax_rate = 0; std::unordered_set<std::string> exemptions_list; while (!fin.eof()) { std::string line; std::getline(fin, line); if (!is_tax_rate_readed) { tax_rate = std::stoi(line); is_tax_rate_readed = true; continue; } exemptions_list.insert(line); } tax_items_list_.push_back(TaxItem("basic_sales_tax", tax_rate, exemptions_list)); is_tax_rate_readed = false; std::fstream fin2("./input/taxpolicy/import_duty.txt", std::ios::in); unsigned int tax_rate2 = 0; std::unordered_set<std::string> exemptions_list2; while (!fin2.eof()) { std::string line; std::getline(fin2, line); if (!is_tax_rate_readed) { tax_rate2 = std::stoi(line); is_tax_rate_readed = true; continue; } exemptions_list2.insert(line); } tax_items_list_.push_back(TaxItem("import_duty", tax_rate2, exemptions_list2)); }
int main(int argc, char** argv) { if (argc != 3) { cerr << "incorrect usage\n"; return -1; } string file1(argv[1]); string file2(argv[2]); ifstream fin1(file1); ifstream fin2(file2); Contour c1, c2, actual_c1, actual_c2; // We need to limit contour size to 100 or so. int x,y; while (fin1 >> x >> y) { c1.push_back(make_pair((double)x,(double)y)); } int inc = c1.size()/75; if (inc == 0) inc = 1; for (int i=0;i<c1.size();i+=inc) actual_c1.push_back(c1[i]); while (fin2 >> x >> y) { c2.push_back(make_pair((double)x,(double)y)); } inc = c2.size()/75; if (inc == 0) inc = 1; for (int i=0;i<c2.size();i+=inc) actual_c2.push_back(c2[i]); fin1.close(); fin2.close(); compute_cost(actual_c1, actual_c2); //cout << setprecision(17) << compute_cost(actual_c1,actual_c2) << endl; // cout << "closed: " << // setprecision(17) << compute_cost_closed(actual_c1, actual_c2) << endl; return 0; }
void mergebinbbcshadronv3new(int nrun=98){ const int binnum= 50; const int ncent = 40; char rootfile[500]; char histname1[500]; char histname2[500]; float scon2new[ncent][binnum], ssum2new[ncent][binnum], scon22new[ncent][binnum]; for(int icent=0; icent<ncent; icent++){ for(int ibin=0; ibin<binnum; ibin++){ scon2new[icent][ibin]=0; ssum2new[icent][ibin]=0; scon22new[icent][ibin]=0; } } float scon2new2[ncent][binnum], ssum2new2[ncent][binnum], scon22new2[ncent][binnum]; for(int icent=0; icent<ncent; icent++){ for(int ibin=0; ibin<binnum; ibin++){ scon2new2[icent][ibin]=0; ssum2new2[icent][ibin]=0; scon22new2[icent][ibin]=0; } } float con2new[10][binnum], sum2new[10][binnum], con22new[10][binnum]; for(int icent=0; icent<4; icent++){ for(int ibin=0; ibin<binnum; ibin++){ con2new[icent][ibin]=0; sum2new[icent][ibin]=0; con22new[icent][ibin]=0; } } float reso2[10]={0.034,0.017,0.094,0.065,1,1,1,1,1,1}; float tmp; /* ifstream freso("bbcs_reso.txt"); for(int icent=0; icent<4; icent++){ freso>>tmp>>reso2[icent]; cout<<reso2[icent]<<endl; //reso2[icent]=1.0; } freso.close(); */ int run; //ifstream fin2("Run8dAu200GeVSMD.Lst"); ifstream fin2("Run14He3Au200GeV.Lst"); TFile *f=0; for(int irun=0; irun<nrun; irun++){ fin2>>run; sprintf(rootfile,"%s%d%s","data/hist_",run,".root"); cout<<irun<<" "<<rootfile<<endl; f=new TFile(rootfile); // cal v3 for(int icent=0; icent<4; icent++){ //cout<<icent<<endl; sprintf(histname1,"%s%d","hhadronv3bbcsY_cent_",icent); sprintf(histname2,"%s%d","hhadronv3bbcsY2_cent_",icent); //cout<<histname1<<endl; for(int ibin=0; ibin<binnum; ibin++){//0~60 //cout<<ibin<<endl; float con2=((TProfile *)f->Get(histname1))->GetBinContent(ibin+5); float sum2=((TProfile *)f->Get(histname1))->GetBinEntries(ibin+5); float con22=((TProfile *)f->Get(histname2))->GetBinContent(ibin+5); if(sum2>0){ con2new[icent][ibin] += con2*sum2; sum2new[icent][ibin] += sum2; con22new[icent][ibin] += con22*sum2; } }//end of ibin }//end of icent f->Close(); f->Delete(); }//end of irun fin2.close(); cout<<"finished"<<endl; for(int icent=0; icent<4; icent++){ for(int ibin=0; ibin<binnum; ibin++){ if(sum2new[icent][ibin]>0){ con2new[icent][ibin] = con2new[icent][ibin]/reso2[icent]; con22new[icent][ibin] = con22new[icent][ibin]/reso2[icent]/reso2[icent]; ssum2new[icent][ibin] += sum2new[icent][ibin]; scon2new[icent][ibin] += con2new[icent][ibin]; scon22new[icent][ibin] += con22new[icent][ibin]; } } }//end of run for(int ibin=0; ibin<binnum; ibin++){ ssum2new[10][ibin] = ssum2new[0][ibin];//0~5 scon2new[10][ibin] = scon2new[0][ibin]; scon22new[10][ibin] = scon22new[0][ibin]; ssum2new[11][ibin] = ssum2new[1][ibin];//5~10 scon2new[11][ibin] = scon2new[1][ibin]; scon22new[11][ibin] = scon22new[1][ibin]; ssum2new[12][ibin] = ssum2new[0][ibin]+ssum2new[1][ibin];//0~10 scon2new[12][ibin] = scon2new[0][ibin]+scon2new[1][ibin]; scon22new[12][ibin] = scon22new[0][ibin]+scon22new[1][ibin]; ssum2new[13][ibin] = ssum2new[2][ibin]+ssum2new[3][ibin];//10~20 scon2new[13][ibin] = scon2new[2][ibin]+scon2new[3][ibin]; scon22new[13][ibin] = scon22new[2][ibin]+scon22new[3][ibin]; ssum2new[14][ibin] = ssum2new[12][ibin]+ssum2new[13][ibin];//0~20 scon2new[14][ibin] = scon2new[12][ibin]+scon2new[13][ibin]; scon22new[14][ibin] = scon22new[12][ibin]+scon22new[13][ibin]; } float ptnew[40], eptnew[40]; float v3new[23][40], ev3new[23][40]; int j=-9999; for(int icent=10; icent<15; icent++){ for(int i=0; i<13; i++){ eptnew[i]=0; if(i<8) {//0.4~2.0GeV/c ptnew[i]=i*0.2+0.5; for(int j=0; j<2; j++){ ssum2new2[icent][i] += ssum2new[icent][j+i*2]; scon22new2[icent][i] += scon22new[icent][j+i*2]; scon2new2[icent][i] += scon2new[icent][j+i*2]; //if(icent==10) cout<<i<<" "<<j+i*2<<" "<<ssum2new2[icent][i]<<" "<<ssum2new[icent][j+i*2]<<endl; } } else{ ptnew[i]=(i-8)*0.5+2.25; for(int j=0; j<5; j++){ ssum2new2[icent][i] += ssum2new[icent][j+(i-8)*5+16]; scon22new2[icent][i] += scon22new[icent][j+(i-8)*5+16]; scon2new2[icent][i] += scon2new[icent][j+(i-8)*5+16]; } } } for(int i=0; i<13; i++){ if(ssum2new2[icent][j]>0){ v3new[icent][i]=scon2new2[icent][i]/ssum2new2[icent][i]; ev3new[icent][i]=sqrt(scon22new2[icent][i]/ssum2new2[icent][i]-(scon2new2[icent][i]/ssum2new2[icent][i])**2)/sqrt(ssum2new2[icent][i]); } } } ofstream fv3new0("run12dAu_bbcsnew_hadron_v3_0_5.txt"); //ofstream fv3new1("run12dAu_bbcsnew_hadron_v3_5_10.txt"); //ofstream fv3new2("run12dAu_bbcsnew_hadron_v3_0_10.txt"); //ofstream fv3new3("run12dAu_bbcsnew_hadron_v3_10_20.txt"); //ofstream fv3new4("run12dAu_bbcsnew_hadron_v3_0_20.txt"); for(int i=0; i<18; i++){ fv3new0<<ptnew[i]<<" "<<v3new[10][i]<<" "<<ev3new[10][i]<<endl; //fv3new1<<ptnew[i]<<" "<<v3new[11][i]<<" "<<ev3new[11][i]<<endl; //fv3new2<<ptnew[i]<<" "<<v3new[12][i]<<" "<<ev3new[12][i]<<endl; //fv3new3<<ptnew[i]<<" "<<v3new[13][i]<<" "<<ev3new[13][i]<<endl; //fv3new4<<ptnew[i]<<" "<<v3new[14][i]<<" "<<ev3new[14][i]<<endl; } fv3new0.close(); //fv3new1.close(); //fv3new2.close(); //fv3new3.close(); //fv3new4.close(); }
int main(int argc,char** argv){ quality=atof(argv[1]); BMP fin2 (argv[2]); BMP fin ;fin.init(fin2.w,fin2.h); BMP fout2;fout2.init(fin2.w,fin2.h); BMP fout;fout.init(fin2.w,fin2.h); double in[8][8]; double out[8][8]; double out2[8][8]; int i,j,idx; init_walsh(); init_dwt(); bmp_for(fin) RGB2YUV(fin2(x,y),fin(x,y)); int num_dat[14]; double prob_dat[14]; int sum_dat[14]; double bit_dat[14]; memset(num_dat,0,sizeof(num_dat)); int num_totallen=0; for(int c=0;c<3;c++){ for(int by=0;by<fin.h/8;by++) for(int bx=0;bx<fin.w/8;bx++){ int num_codelen=0; for(int dy=0;dy<8;dy++) for(int dx=0;dx<8;dx++){ int x=bx*8+dx; int y=by*8+dy; in[ dy][ dx]=fin(x,y)[c]; // in[ dy][ dx]=255; } //dct(in,out); //walsh(in,out); // mprint(in); //dwt(in,out); haar(in,out); // mprint(out); // idwt(out,in); // mprint(in); // return 0; // ihaar(out,in); // mprint(in); // return 0; // if(c!=0) mmap(out,(1.0/(qt[c][y][x]*quality))*); mmap(out,round); // mprint(out); vector<RunBit> rvec; vector<Code> cvec; mkRunBit(out,rvec); mkCode(rvec,cvec); for(int dy=0;dy<8;dy++) for(int dx=0;dx<8;dx++){ num_dat[(int)(log(fabs(out[dy][dx])+1.0)/log(2))]++; } // for(int i=0;i<rvec.size();i++) // printf("%d %d\n",rvec[i].zero,rvec[i].code); // printf("\n"); // for(int i=0;i<cvec.size();i++) // printf("%d %x\n",cvec[i].len,cvec[i].code); // return 0; for(int i=0;i<cvec.size();i++) num_codelen+=cvec[i].len; double comprate=(double)(8*8*8)/(double)(num_codelen); // if(comprate<3){ // mprint(out); // for(int i=0;i<rvec.size();i++) // printf("%d %d\n",rvec[i].zero,rvec[i].code); // printf("\n"); // for(int i=0;i<cvec.size();i++) // printf("%d %x\n",cvec[i].len,cvec[i].code); // printf("\n"); // printf("comprate %f",comprate); // return 0; // } num_totallen+=num_codelen; // if(c!=0) mmap(out,(qt[c][y][x]*quality)*); //idct(out,out2); //walsh(out,out2); //idwt(out,out2); ihaar(out,out2); for(int dy=0;dy<8;dy++) for(int dx=0;dx<8;dx++){ int x=bx*8+dx; int y=by*8+dy; fout(x,y)[c]=lmt3[c](out2[ dy][ dx]); } } } bmp_for(fin) YUV2RGB(fout(x,y),fout2(x,y)); for(int y=0;y<14;y++) prob_dat[y]=(double)(num_dat[y])/(double)(fin.w*fin.h*3); for(int y=0;y<14;y++) sum_dat[y]=1<<y; for(int y=0;y<14;y++) if(sum_dat[y]!=0&&prob_dat[y]!=0.0) bit_dat[y]=-log(prob_dat[y]/sum_dat[y])/log(2); double ave_bits=0; for(int y=0;y<14;y++) ave_bits+=prob_dat[y]*bit_dat[y]; for(int y=0;y<14;y++){ printf("%2d,%5d,%9d,%8.3f,%8.3f,%8.3f\n", y, sum_dat[y], num_dat[y], prob_dat[y], bit_dat[y], prob_dat[y]*bit_dat[y] ); } printf("ideal comprate:%f\n",8.0/ave_bits); double tcomprate=(double)(fin.w*fin.h*24)/(double)(num_totallen); printf("tcomprate %f\n",tcomprate); fout2.write(argv[3]); return true; }
void plotCmp(int eff) { TFile fin1("out1_EE_Jan.root","read"); TH1D *hEff1=(TH1D*)fin1.Get("eff_postFSRcorr"); TH1D *hAcc1=(TH1D*)fin1.Get("acc_postFSRcorr"); hEff1->SetDirectory(0); hAcc1->SetDirectory(0); fin1.Close(); TH1D* hAS=(eff) ? hEff1 : hAcc1; TString path="../root_files_reg/constants/DY_j22_19712pb/"; TString fname2= path+ TString((!eff) ? "acceptance_1D.root" : "efficiency_1D.root"); TString fieldName=(eff) ? "hEfficiency" : "hAcceptance"; TString correctionName=(eff) ? "efficiency" : "acceptance"; TFile fin2(fname2,"read"); TH2D *h2Our=(TH2D*)fin2.Get(fieldName); h2Our->SetName("h2Our"); h2Our->SetDirectory(0); fin2.Close(); TH1D *hOurRaw=createProfileX(h2Our,1,fieldName + TString("Raw")); TH1D *hOur=removeLastBin(hOurRaw,fieldName); TString label1="regressed en. (20-500,500-800,800+)"; TH1D *h2=NULL, *h3=NULL; TString label2,label3; if (0) { TString fname3="../root_files_reg/constants/DY_j22_19712pb_20inf/efficiency_1D.root"; if (!eff) fname3.ReplaceAll("efficiency","acceptance"); TFile fin3(fname3,"read"); TH2D* h2tmp=(TH2D*)fin3.Get(fieldName); TH1D* h1tmp=createProfileX(h2tmp,1,"h1tmp"); label2="regressed en. (20-inf)"; h2=removeLastBin(h1tmp,fieldName+TString("regEn20inf")); delete h1tmp; delete h2tmp; fin3.Close(); } if (0) { TString fname4="../root_files/constants/DY_j22_19789pb/efficiency_1D.root"; if (!eff) fname4.ReplaceAll("efficiency","acceptance"); TFile fin4(fname4,"read"); TH2D* h2tmp=(TH2D*)fin4.Get(fieldName); TH1D* h1tmp=createProfileX(h2tmp,1,"h1tmp"); h3=removeLastBin(h1tmp,fieldName+TString("summer2012")); label3="old n-tuples (20-500,500-800,800+)"; delete h1tmp; delete h2tmp; fin4.Close(); } if (0 && !eff) { TString fname3="../root_files_reg/constants/DY_j22_19712pb/acceptance_1D-PU.root"; //if (!eff) fname4.ReplaceAll("efficiency","acceptance"); TFile fin3(fname3,"read"); TH2D* h2tmp=(TH2D*)fin3.Get(fieldName); printHisto(h2tmp); TH1D* h1tmp=createProfileX(h2tmp,1,"h1tmp"); h2=removeLastBin(h1tmp,fieldName+TString("_wPU")); label3="regressed (20-500,500-800,800+); wPU"; delete h1tmp; delete h2tmp; fin3.Close(); } if (0 && !eff) { //TString fname4="../root_files_reg/constants/DY_j22_19712pb/acceptance_1D-PU.root"; TString fname4="../root_files_reg/constants/DY_j22_19712pb_NoReweight/acceptance_1D___NoReweight.root"; //if (!eff) fname4.ReplaceAll("efficiency","acceptance"); TFile fin4(fname4,"read"); TH2D* h2tmp=(TH2D*)fin4.Get(fieldName); printHisto(h2tmp); TH1D* h1tmp=createProfileX(h2tmp,1,"h1tmp"); h3=removeLastBin(h1tmp,fieldName+TString("_noFEWZ")); label3="regressed (20-500,500-800,800+); noFEWZ"; delete h1tmp; delete h2tmp; fin4.Close(); } std::cout << "Alexey: "; printHisto(hAS); //std::cout << "OurRaw: "; printHisto(hOurRaw); std::cout << "Our : "; printHisto(hOur); ComparisonPlot_t cp(ComparisonPlot_t::_ratioPlain,"cp","","#it{M}_{ee}",correctionName,"ratio"); cp.SetLogx(); cp.AddHist1D(hAS,"Alexey","LP",kBlack,1,0); cp.AddHist1D(hOur,label1,"LP",kBlue,1,0); if (h2) cp.AddHist1D(h2,label2,"LP",kGreen+1,1,0); if (h3) cp.AddHist1D(h3,label3,"LP",kRed+1,1,0); TCanvas *cx= new TCanvas("cx","cx",700,850); cp.Prepare2Pads(cx); cp.Draw(cx); cp.TransLegend(0,-0.6); if (1 || h2 || h3) { cp.TransLegend(-0.15,0.); cp.WidenLegend(0.15,0.); } cx->Update(); }
void mergebinfvtxskaonv2(int nrun=87){ const int binnum= 50; const int ncent = 40; char rootfile[500]; char histname1[500]; char histname2[500]; float scon2new[ncent][binnum], ssum2new[ncent][binnum], scon22new[ncent][binnum]; for(int icent=0; icent<ncent; icent++){ for(int ibin=0; ibin<binnum; ibin++){ scon2new[icent][ibin]=0; ssum2new[icent][ibin]=0; scon22new[icent][ibin]=0; } } float con2new[10][binnum], sum2new[10][binnum], con22new[10][binnum]; for(int icent=0; icent<2; icent++){ for(int ibin=0; ibin<binnum; ibin++){ con2new[icent][ibin]=0; sum2new[icent][ibin]=0; con22new[icent][ibin]=0; } } float reso2[10]={0.274,0.208,0.194,0.146034,1,1,1,1,1,1};// tmp; /* ifstream freso("fvtx0s_reso.txt"); for(int icent=0; icent<4; icent++){ freso>>tmp>>reso2[icent]; cout<<reso2[icent]<<endl; //reso2[icent]=1.0; } freso.close(); */ int run; ifstream fin2("Run14He3Au200GeV.Lst"); TFile *f=0; for(int irun=0; irun<nrun; irun++){ fin2>>run; sprintf(rootfile,"%s%d%s","data/hist_",run,".root"); cout<<irun<<" "<<rootfile<<endl; f=new TFile(rootfile); // cal v2 for(int icent=0; icent<1; icent++){ //cout<<icent<<endl; sprintf(histname1,"%s%d","hkaonv2fvtx0sY_cent_",icent); sprintf(histname2,"%s%d","hkaonv2fvtx0sY2_cent_",icent); //cout<<histname1<<endl; for(int ibin=0; ibin<binnum; ibin++){//0~60 //cout<<ibin<<endl; float con2=((TProfile *)f->Get(histname1))->GetBinContent(ibin+5); float sum2=((TProfile *)f->Get(histname1))->GetBinEntries(ibin+5); float con22=((TProfile *)f->Get(histname2))->GetBinContent(ibin+5); if(sum2>0){ con2new[icent][ibin] += con2*sum2; sum2new[icent][ibin] += sum2; con22new[icent][ibin] += con22*sum2; } }//end of ibin }//end of icent f->Close(); f->Delete(); }//end of irun fin2.close(); cout<<"finished"<<endl; for(int icent=0; icent<1; icent++){ for(int ibin=0; ibin<binnum; ibin++){ if(sum2new[icent][ibin]>0){ con2new[icent][ibin] = con2new[icent][ibin]/reso2[icent]; con22new[icent][ibin] = con22new[icent][ibin]/reso2[icent]/reso2[icent]; ssum2new[icent][ibin] += sum2new[icent][ibin]; scon2new[icent][ibin] += con2new[icent][ibin]; scon22new[icent][ibin] += con22new[icent][ibin]; } } }//end of run for(int ibin=0; ibin<binnum; ibin++){ ssum2new[10][ibin] = ssum2new[0][ibin];//0~5 scon2new[10][ibin] = scon2new[0][ibin]; scon22new[10][ibin] = scon22new[0][ibin]; ssum2new[11][ibin] = ssum2new[1][ibin];//5~10 scon2new[11][ibin] = scon2new[1][ibin]; scon22new[11][ibin] = scon22new[1][ibin]; ssum2new[12][ibin] = ssum2new[0][ibin]+ssum2new[1][ibin];//0~10 scon2new[12][ibin] = scon2new[0][ibin]+scon2new[1][ibin]; scon22new[12][ibin] = scon22new[0][ibin]+scon22new[1][ibin]; ssum2new[13][ibin] = ssum2new[2][ibin]+ssum2new[3][ibin];//10~20 scon2new[13][ibin] = scon2new[2][ibin]+scon2new[3][ibin]; scon22new[13][ibin] = scon22new[2][ibin]+scon22new[3][ibin]; ssum2new[14][ibin] = ssum2new[12][ibin]+ssum2new[13][ibin];//0~20 scon2new[14][ibin] = scon2new[12][ibin]+scon2new[13][ibin]; scon22new[14][ibin] = scon22new[12][ibin]+scon22new[13][ibin]; } float ptnew[40], eptnew[40]; float v2new[23][40], ev2new[23][40]; int j=-9999; for(int icent=10; icent<11; icent++){ for(int i=0; i<18; i++){ eptnew[i]=0; ptnew[i]=i*0.2+0.5; j=2*i; ssum2new[icent][j] += ssum2new[icent][j+1]; scon22new[icent][j] += scon22new[icent][j+1]; scon2new[icent][j] += scon2new[icent][j+1]; if(ssum2new[icent][j]>0){ v2new[icent][i]=scon2new[icent][j]/ssum2new[icent][j]; ev2new[icent][i]=sqrt(scon22new[icent][j]/ssum2new[icent][j]-(scon2new[icent][j]/ssum2new[icent][j])**2)/sqrt(ssum2new[icent][j]); } } } ofstream fv2new0("run12dAu_fvtx0s_kaon_v2_0_5.txt"); //ofstream fv2new1("run12dAu_fvtx0s_kaon_v2_5_10.txt"); //ofstream fv2new2("run12dAu_fvtx0s_kaon_v2_0_10.txt"); //ofstream fv2new3("run12dAu_fvtx0s_kaon_v2_10_20.txt"); //ofstream fv2new4("run12dAu_fvtx0s_kaon_v2_0_20.txt"); for(int i=0; i<18; i++){ fv2new0<<ptnew[i]<<" "<<v2new[10][i]<<" "<<ev2new[10][i]<<endl; //fv2new1<<ptnew[i]<<" "<<v2new[11][i]<<" "<<ev2new[11][i]<<endl; //fv2new2<<ptnew[i]<<" "<<v2new[12][i]<<" "<<ev2new[12][i]<<endl; //fv2new3<<ptnew[i]<<" "<<v2new[13][i]<<" "<<ev2new[13][i]<<endl; //fv2new4<<ptnew[i]<<" "<<v2new[14][i]<<" "<<ev2new[14][i]<<endl; } fv2new0.close(); //fv2new1.close(); //fv2new2.close(); //fv2new3.close(); //fv2new4.close(); }
int main(int argc, char **argv) { if (argc != 10) { // 0 1 2 3 4 5 6 7 8 9 cout<<"Usage: "<<argv[0]<<" <normal.db> <trace> <win_size (9)> <delay factor (1)> <tolerize_lim (12)> <anomaly_lim (30)> <suspend_execve (10)> <suspend_execve_time (172800)> <lfc>"<<endl; //if ( (argc == 2) && (string(argv[1]) == "-h") ) documentation(); exit(1); } string db_file = argv[1]; string trace_file = argv[2]; int win_size = atoi(argv[3]); int delay_factor = atoi(argv[4]); int tol_limit = atoi(argv[5]); int anom_limit = atoi(argv[6]); int suspend_execve = atoi(argv[7]); int suspend_execve_time = atoi(argv[8]); int lfc = atoi(argv[9]); Status status(win_size, delay_factor, tol_limit, anom_limit, suspend_execve, suspend_execve_time, lfc); vector<int> sliding_win; // we don't know how many system calls the application makes so start from a large number (like 400) //int normalDB[SYSCALL_COUNT][SYSCALL_COUNT][win_size]; //for (int i=0;i<SYSCALL_COUNT; ++i) // for (int j=0;j<SYSCALL_COUNT; ++j) // for (int k=0;k<win_size; ++k) // normalDB[i][j][k] = 0; // read in the existing normal db (if provided) int ***normalDB; normalDB = new int **[SYSCALL_COUNT]; for (int i=0;i<SYSCALL_COUNT; ++i) { normalDB[i] = new int *[SYSCALL_COUNT]; for (int j=0;j<SYSCALL_COUNT; ++j) { normalDB[i][j] = new int[win_size]; } } /////////////////////////////////////////// /////////////////////////////////////////// // Step 1. read in the normal db /////////////////////////////////////////// vector<int> col1; vector<int> col2; vector<int> col3; // read the normal db into a 2d array observing the max of last column (i.e. window_size) ifstream fin(db_file.c_str()); assert(fin); char ch; string line = ""; string anomaly; while (fin.get(ch)) { if( ch !='\n') line+= ch; else // process the line { int idx1 = line.find(","); int idx2 = line.find(",", idx1 + 1); string part1 = line.substr(0, idx1); string part2 = line.substr(idx1 + 1, idx2-idx1-1); string part3 = line.substr(idx2 + 1); int p1 = atoi(part1.c_str()); int p2 = atoi(part2.c_str()); int p3 = atoi(part3.c_str()); col1.push_back(p1); col2.push_back(p2); col3.push_back(p3); //cout<<p1<<"---"<<p2<<"---"<<p3<<endl; line = ""; } } fin.close(); if( (col1.size() != col2.size()) || (col1.size() != col3.size()) ) { cout<<"Col vectors are not properly initialized..."<<endl; exit(1); } else { for (int i=0; i<col1.size();++i) { int x = col1.at(i); int y = col2.at(i); int z = col3.at(i); normalDB[x][y][z] = 1; } } /////////////////////////////////////////// /////////////////////////////////////////// // Step 2. Start working on the trace /////////////////////////////////////////// ifstream fin2(trace_file.c_str()); assert(fin2); while (fin2.get(ch)) { if( ch !='\n') line+= ch; else // process the line { int idx = line.find(" "); string part1 = line.substr(0, idx); string part2 = line.substr(idx + 1); int process_no = atoi(part1.c_str()); int syscall = atoi(part2.c_str()); //cout<<process_no<<"---"<<syscall<<endl; sliding_win.push_back(syscall); // now we have win_size syscalls in sliding window where the vector end is the most recent if (sliding_win.size() == win_size) { // // This is where you'll take the sliding window and apply detection and update status // such as LFC delay and so on... status.update(sliding_win, normalDB); } if (sliding_win.size() == win_size) sliding_win.erase(sliding_win.begin()); //cout<<sliding_win.size()<<endl; line = ""; } } fin2.close(); /////////////////////////////////////////// /////////////////////////////////////////// // Step 3. Produce output based on results /////////////////////////////////////////// // // Produce an output that GP will read in, nominally, produce // # mismatches, anomaly rate, max LFC, projected delay, execve stopped // attack training happened? ... so on // status.output(); //deallocate array for (int i=0;i<SYSCALL_COUNT; ++i) { for (int j=0;j<SYSCALL_COUNT; ++j) { delete[] normalDB[i][j]; } delete[] normalDB[i]; } delete[] normalDB; cout<<status.mismatch_count<<" / "<<status.total_count<<endl; }
int main(int argc, char* argv[]) { std::ifstream fin1("lTall.txt"); /// all protoss matches std::ifstream fin2("lPall.txt"); /// all protoss matches std::ifstream fin3("lZall.txt"); /// all protoss matches #ifdef GENERATE_X_VALUES std::vector<std::set<int> > terran = get_X_values(fin1); std::vector<std::set<int> > protoss = get_X_values(fin2); std::vector<std::set<int> > zerg = get_X_values(fin3); #else std::vector<std::set<int> > terran = tech_trees(fin1).vector_X; std::vector<std::set<int> > protoss = tech_trees(fin2).vector_X; std::vector<std::set<int> > zerg = tech_trees(fin3).vector_X; #endif #ifdef FILE_OUTPUT std::ofstream terran_fout("terran_possible_tech_trees.txt"); std::ofstream protoss_fout("protoss_possible_tech_trees.txt"); std::ofstream zerg_fout("zerg_possible_tech_trees.txt"); #endif std::set<std::set<int> > terran_verif; for (std::vector<std::set<int> >::const_iterator it = terran.begin(); it != terran.end(); ++it) { #ifdef PRINTALL #ifdef FILE_OUTPUT print_set<Terran_Buildings>(*it, terran_fout); #else print_set<Terran_Buildings>(*it); #endif #endif terran_verif.insert(*it); } if (terran.size() != terran_verif.size()) std::cout << "TEST FAIL" << std::endl; std::cout << "Terran, printed: " << terran.size() << " sets == tech trees" << std::endl; std::set<std::set<int> > protoss_verif; for (std::vector<std::set<int> >::const_iterator it = protoss.begin(); it != protoss.end(); ++it) { #ifdef PRINTALL #ifdef FILE_OUTPUT print_set<Protoss_Buildings>(*it, protoss_fout); #else print_set<Protoss_Buildings>(*it); #endif #endif protoss_verif.insert(*it); } if (protoss.size() != protoss_verif.size()) std::cout << "TEST FAIL" << std::endl; std::cout << "Protoss, printed: " << protoss.size() << " sets == tech trees" << std::endl; std::set<std::set<int> > zerg_verif; for (std::vector<std::set<int> >::const_iterator it = zerg.begin(); it != zerg.end(); ++it) { #ifdef PRINTALL #ifdef FILE_OUTPUT print_set<Zerg_Buildings>(*it, zerg_fout); #else print_set<Zerg_Buildings>(*it); #endif #endif zerg_verif.insert(*it); } if (zerg.size() != zerg_verif.size()) { std::cout << "TEST FAIL" << std::endl; std::cout << zerg.size() << " " << zerg_verif.size() << std::endl; } std::cout << "Zerg, printed: " << zerg.size() << " sets == tech trees" << std::endl; return 0; }
int main(int argc, char** argv) { std::cout << "This program computes the difference between two belief files." << std::endl; if(argc != 3) { std::cout << "Usage example: " << std::endl << " %> " << argv[0] << " bp_beliefs.csv gibbs_beliefs.csv " << std::endl; } std::ifstream fin1(argv[1]); if(!fin1.good()) { std::cout << "Unable to open: " << argv[1] << std::endl; exit(EXIT_FAILURE); } std::ifstream fin2(argv[2]); if(!fin2.good()) { std::cout << "Unable to open: " << argv[2] << std::endl; exit(EXIT_FAILURE); } double L1_L1_error = 0; double L1_L_inf_error = 0; double L_inf_L1_error = 0; size_t disagree = 0; size_t vertices = 0; while(fin1.good() && fin2.good()) { // Read the line for both files std::string line1; std::getline(fin1, line1); std::string line2; std::getline(fin2, line2); line1 = trim(line1); line2 = trim(line2); if(line1.size() == 0 || line2.size() == 0) continue; // Trim the varialble name size_t index1 = line1.find_first_of('/'); assert(index1 != std::string::npos); size_t index2 = line2.find_first_of('/'); assert(index2 != std::string::npos); std::string var1 = trim(line1.substr(0, index1)); std::string var2 = trim(line1.substr(0, index2)); assert(var1 == var2); line1 = line1.substr(index1); line2 = line2.substr(index2); // compute the rest of the string std::stringstream strm1(line1), strm2(line2); size_t index = 0; double sum = 0, max = 0; size_t mapInd1 = 0; double mapVal1 = -1; size_t mapInd2 = 0; double mapVal2 = -1; while(strm1.good() && strm2.good()) { double value1=-1, value2=-1; strm1 >> value1; strm2 >> value2; strm1.ignore(1); strm2.ignore(1); assert(value1 >= 0 && value1 <= 1); assert(value2 >= 0 && value2 <= 1); // Compute the map for each line if(value1 > mapVal1) { mapVal1 = value1; mapInd1 = index; } if(value2 > mapVal2) { mapVal2 = value2; mapInd2 = index; } // Compute the difference in the probabilities double diff = std::abs(value1 - value2); sum += diff; max = std::max(max, diff); // Increment index ++index; } // Assert both lines end at the same state assert(!strm1.good() && !strm2.good()); // update the global counters double l1_error = sum / index; L1_L1_error += l1_error; L1_L_inf_error += max; L_inf_L1_error = std::max(L_inf_L1_error, l1_error); disagree += (mapInd1 != mapInd2? 1 : 0); ++vertices; } // end of while loop assert(!fin1.good() && !fin2.good()); fin1.close(); fin2.close(); std::cout << "Read " << vertices << " beliefs." << std::endl << "L1 L1 error: " << L1_L1_error / vertices << std::endl << "L1 Linf error: " << L1_L_inf_error / vertices << std::endl << "Linf L1 error: " << L_inf_L1_error << std::endl << "%Map Disagree: " << double(disagree) / vertices << std::endl; return EXIT_SUCCESS; }
int main(int argc, char **argv) { if (argc != 6) { // 1 2 3 4 5 6 cout<<"Usage: "<<argv[0]<<" <win_size> <input normal.db (Use N/A to start without file)> <output normal.db> <trace> <schema_file>"<<endl; //if ( (argc == 2) && (string(argv[1]) == "-h") ) documentation(); exit(1); } int win_size = atoi(argv[1]); string in_db_file = argv[2]; string out_db_file = argv[3]; string trace = argv[4]; string schema_file = argv[5]; vector<int> sliding_win; // this is the regular sliding win that we use in pH vector<int> sliding_win2; // this is the resulting pattern vector<int> schema; // read in the schema file ifstream fin2(schema_file.c_str()); assert(fin2); char ch2; string line = ""; int numr; int max_schema_loc = 0; while (fin2.get(ch2)) { if( ch2 !='\n') line+= ch2; else // process the line { int idx1 = -1; int idx2 = line.find(","); while (idx2 != string::npos) { string str = line.substr(idx1 + 1, idx2 - idx1 - 1); numr = atoi(str.c_str()); if (numr > max_schema_loc) max_schema_loc = numr; schema.push_back(numr); idx1 = idx2; idx2 = line.find(",", idx1 + 1); } string str = line.substr(idx1 + 1); numr = atoi(str.c_str()); if (numr > max_schema_loc) max_schema_loc = numr; schema.push_back(numr); break; // once the first line is finished } } fin2.close(); //for (int i=0;i<schema.size();++i) //{ // cout<<schema.at(i)<<endl; //} if(max_schema_loc >= win_size) { cout<<"Error: Maximum schema location ("<<max_schema_loc<<") can't be larger than the window size ("<<win_size<<"). exitting..."<<endl; exit(1); } // we don't know how many system calls the application makes so start from a large number (like 400) //int normalDB[SYSCALL_COUNT][SYSCALL_COUNT][win_size]; //for (int i=0;i<SYSCALL_COUNT; ++i) // for (int j=0;j<SYSCALL_COUNT; ++j) // for (int k=0;k<win_size; ++k) // normalDB[i][j][k] = 0; // read in the existing normal db (if provided) int ***normalDB; normalDB = new int **[SYSCALL_COUNT]; for (int i=0;i<SYSCALL_COUNT; ++i) { normalDB[i] = new int *[SYSCALL_COUNT]; for (int j=0;j<SYSCALL_COUNT; ++j) { normalDB[i][j] = new int[win_size]; // no need to init over winsize (now we have schema len) but leave it like this for now } } if (in_db_file.find("N/A") == string::npos) { vector<int> col1; vector<int> col2; vector<int> col3; // read the normal db into a 2d array observing the max of last column (i.e. window_size) ifstream fin(in_db_file.c_str()); assert(fin); char ch; line = ""; string anomaly; while (fin.get(ch)) { if( ch !='\n') line+= ch; else // process the line { int idx1 = line.find(","); int idx2 = line.find(",", idx1 + 1); string part1 = line.substr(0, idx1); string part2 = line.substr(idx1 + 1, idx2-idx1-1); string part3 = line.substr(idx2 + 1); int p1 = atoi(part1.c_str()); int p2 = atoi(part2.c_str()); int p3 = atoi(part3.c_str()); col1.push_back(p1); col2.push_back(p2); col3.push_back(p3); //cout<<p1<<"---"<<p2<<"---"<<p3<<endl; line = ""; } } fin.close(); if( (col1.size() != col2.size()) || (col1.size() != col3.size()) ) { cout<<"Col vectors are not properly initialized..."<<endl; exit(1); } else { for (int i=0; i<col1.size();++i) { int x = col1.at(i); int y = col2.at(i); int z = col3.at(i); normalDB[x][y][z] = 1; } } } // Start working on the trace ifstream fin(trace.c_str()); assert(fin); char ch; line = ""; string anomaly; while (fin.get(ch)) { if( ch !='\n') line+= ch; else // process the line { int idx = line.find(" "); string part1 = line.substr(0, idx); string part2 = line.substr(idx + 1); int process_no = atoi(part1.c_str()); int syscall = atoi(part2.c_str()); //cout<<process_no<<"---"<<syscall<<endl; sliding_win.push_back(syscall); // now we have win_size syscalls in sliding window where the vector end is the most recent if (sliding_win.size() == win_size) { // create the sliding window2 sliding_win2.clear(); for (int i=0; i<schema.size(); ++i) { sliding_win2.push_back(sliding_win.at(schema.at(i))); } /* for (int i=0; i<sliding_win.size(); ++i) { cout<<sliding_win.at(i)<<" "; } cout<<endl; for (int i=0; i<sliding_win2.size(); ++i) { cout<<sliding_win2.at(i)<<" "; } cout<<endl; */ for (int i=0; i<sliding_win2.size() -1; ++i) { int x = sliding_win2.at(sliding_win2.size() - 1); int y = sliding_win2.at(i); int z = sliding_win2.size() - i - 1; normalDB[x][y][z] = 1; } } if (sliding_win.size() == win_size) sliding_win.erase(sliding_win.begin()); //cout<<sliding_win.size()<<endl; line = ""; } } fin.close(); // we have the normal db, write it to a file ofstream fout(out_db_file.c_str()); for (int i=0;i<SYSCALL_COUNT; ++i) for (int j=0;j<SYSCALL_COUNT; ++j) for (int k=0;k<win_size; ++k) if (normalDB[i][j][k] != 0) { fout<<i<<","<<j<<","<<k<<endl; } fout.close(); //deallocate array for (int i=0;i<SYSCALL_COUNT; ++i) { for (int j=0;j<SYSCALL_COUNT; ++j) { delete[] normalDB[i][j]; } delete[] normalDB[i]; } delete[] normalDB; }
void plotpidket(){ gStyle->SetOptTitle(0); gStyle->SetOptStat(0); gStyle->SetStripDecimals(0); float mpion = 0.13957; float mkaon = 0.49368; float mproton = 0.93827; float pt[13], ept[12], v2[13], ev2[13], sv2[13]; ifstream fin("run12dAu_fvtx0s_hadron_v2_0_5.txt"); for(int i=0; i<13; i++){ ept[i]=0; fin>>pt[i]>>v2[i]>>ev2[i]; } fin.close(); TGraphErrors *grhadron = new TGraphErrors(13, pt, v2, ept, ev2); ifstream fin("run12dAu_fvtx0s_pion_v2_0_5.txt"); for(int i=0; i<13; i++){ ept[i]=0; fin>>pt[i]>>v2[i]>>ev2[i]; pt[i]= sqrt(pt[i]**2+mpion**2)-mpion; pt[i] = pt[i]/2.0; v2[i] = v2[i]/2.0; ev2[i] = ev2[i]/2.0; } fin.close(); TGraphErrors *grpion = new TGraphErrors(13, pt, v2, ept, ev2); ifstream fin("run12dAu_fvtx0s_kaon_v2_0_5.txt"); for(int i=0; i<13; i++){ ept[i]=0; fin>>pt[i]>>v2[i]>>ev2[i]; pt[i]= sqrt(pt[i]**2+mkaon**2)-mkaon; pt[i] = pt[i]/2.0; v2[i] = v2[i]/2.0; ev2[i] = ev2[i]/2.0; } fin.close(); TGraphErrors *grkaon = new TGraphErrors(13, pt, v2, ept, ev2); ifstream fin2("run12dAu_fvtx0s_proton_v2_0_5.txt"); for(int i=0; i<13; i++){ pt[i]=0; fin2>>pt[i]>>v2[i]>>ev2[i]; pt[i]= sqrt(pt[i]**2+mproton**2)-mproton; pt[i] = pt[i]/3.0; v2[i] = v2[i]/3.0; ev2[i] = ev2[i]/3.0; cout<<pt[i]<<endl; } fin2.close(); TGraphErrors *grproton = new TGraphErrors(13, pt, v2, ept, ev2); c1=new TCanvas("c1","c1"); c1->SetFillColor(10); c1->cd(); TH1F *h = new TH1F("h","h",21, 0, 2.1); h->SetMinimum(-0.02); h->SetMaximum(0.18); h->SetMarkerStyle(20); h->SetMarkerSize(1.2); h->Draw(); h->GetYaxis()->SetTitleOffset(0.9); h->GetYaxis()->SetTitleSize(0.05); h->GetYaxis()->SetTitle("v_{2}/n_{q}"); h->GetXaxis()->SetTitle("KE_{T}/n_{q} (GeV)"); h->GetXaxis()->SetTitleSize(0.04); h->GetYaxis()->CenterTitle(kTRUE); h->GetXaxis()->CenterTitle(kTRUE); grkaon->SetMarkerStyle(21); grkaon->SetMarkerSize(1.2); grkaon->SetMarkerColor(6); grkaon->Draw("P"); grpion->SetMarkerStyle(20); grpion->SetMarkerSize(1.2); grpion->SetMarkerColor(2); grpion->Draw("P"); grproton->SetMarkerStyle(24); grproton->SetMarkerSize(1.2); grproton->SetMarkerColor(4); grproton->Draw("P"); TLegend *leg1 = new TLegend(0.60,0.58,0.90,0.88); leg1->SetFillColor(10); leg1->SetLineStyle(4000); leg1->SetLineColor(10); leg1->SetLineWidth(0.); leg1->SetTextSize(0.05); leg1->SetBorderSize(0); leg1->AddEntry(grpion,"0~5%",""); leg1->AddEntry(grpion,"pion","P"); leg1->AddEntry(grkaon,"kaon","P"); leg1->AddEntry(grproton,"proton","P"); leg1->Draw(); }
void plot0v2new(){ gStyle->SetOptStat(0); gStyle->SetOptFit(1); gStyle->SetOptTitle(0); gStyle->SetCanvasBorderMode(0); gStyle->SetStatColor(10); gStyle->SetTitleFillColor(10); const int nrun=339; // ifstream fin1("fvtx0s_v2_cent_0.dat"); ifstream fin1("bbcs_v2_cent_0.dat"); // ifstream fin2("../../final06/rp/fvtx0s_v2_cent_0.dat"); ifstream fin2("../Run15pAu200GeVlowRun1.Lst"); int runlow[92]; ofstream fout1("goodrun_lowlumi.dat"); // ofstream fout1("goodrun_bbcs_v2_cent_0.dat"); // ofstream fout2("goodrun_fvtx1s_v2_cent_0.dat"); float run[nrun]; float par1[nrun], par2[nrun], par3[nrun], par4[nrun]; for(int irun=0;irun<92;irun++) fin2>>runlow[irun]; for(int irun=0; irun<nrun; irun++){ fin1>>run[irun]>>par1[irun]; // fin2>>run[irun]>>par2[irun]; // if(par1[irun]>0.2&&par1[irun]<3.0){ int flag=0; for(int j=0;j<92;j++){ if(run[irun]==runlow[j]) flag=1; } if(flag==1) fout1<<run[irun]<<endl; // } // else cout<<"bbc"<<run[irun]<<endl; // if(par2[irun]>0.2&&par2[irun]<3.0) fout2<<run[irun]<<endl; // else cout<<"mpc"<<run[irun]<<endl; } fin1.close(); // fin2.close(); fout1.close(); // fout2.close(); //cnt //for(int irun=0; irun<nrun; irun++){ //fin4>>run[irun]>>par4[irun]; //if(par4[irun]>0.2&&par4[irun]<5.0) fout4<<run[irun]<<endl; //} //fin4.close(); //fout4.close(); TGraph *gr1 = new TGraph(nrun,run,par1); // TGraph *gr2 = new TGraph(nrun,run,par2); c=new TCanvas("c","c",800,500); c->SetFillColor(10); // TH1F *h=new TH1F("h","RP QA for FVTXs Psi2",436017-432637+20,432637-10,436017+10); TH1F *h=new TH1F("h","RP QA for bbcs Psi2",436017-432637+20,432637-10,436017+10); h->SetMaximum(2.0); h->SetMinimum(-1.0); h->GetXaxis()->SetTitle("#run"); h->GetYaxis()->SetTitle("#chi^{2}/NDF"); h->GetYaxis()->CenterTitle(kTRUE); h->Draw(); gr1->SetMarkerStyle(20); gr1->SetMarkerSize(1.0); gr1->SetMarkerColor(2); gr1->Draw("P"); /* gr2->SetMarkerStyle(22); gr2->SetMarkerSize(1.0); gr2->SetMarkerColor(6); gr2->Draw("P"); */ TLegend *leg2 = new TLegend(0.62,0.87,0.85,0.67); leg2->SetFillColor(10); leg2->SetLineStyle(4000); leg2->SetLineColor(10); leg2->SetLineWidth(0.); leg2->SetTextSize(0.04); leg2->SetBorderSize(0); // leg2->AddEntry(gr1,"Psi2 FVTXs:0~5%",""); leg2->AddEntry(gr1,"Psi2 BBCs:0~5%",""); // leg2->AddEntry(gr2,"eta:-2.5,-1.5","P"); leg2->AddEntry(gr1,"eta:-3.0,-1.0","P"); //leg2->AddEntry(gr3,"SMDs","P"); //leg2->AddEntry(gr4,"CNT","P"); leg2->Draw(); //c->Print("ReactionPlane_cent0_10.eps"); //c->Print("ReactionPlane_cent0_10.gif"); }
void mergebinfvtxshadronv2(int nrun=339,int centbin = 0){ const int binnum= 50; const int ncent = 40; char rootfile[500]; char histname1[500]; char histname2[500]; float scon2new[ncent][binnum], ssum2new[ncent][binnum], scon22new[ncent][binnum]; for(int icent=0; icent<ncent; icent++){ for(int ibin=0; ibin<binnum; ibin++){ scon2new[icent][ibin]=0; ssum2new[icent][ibin]=0; scon22new[icent][ibin]=0; } } float con2new[10][binnum], sum2new[10][binnum], con22new[10][binnum]; for(int icent=0; icent<6; icent++){ for(int ibin=0; ibin<binnum; ibin++){ con2new[icent][ibin]=0; sum2new[icent][ibin]=0; con22new[icent][ibin]=0; } } // float reso2[10]={0.216025,0.208,0.194,0.146034,1,1,1,1,1,1};// tmp; // float reso2[10]={0.216025,0.216025,0.216025,0.216025,0.216025,0.216025};// tmp; float reso2[10] = {0.21129,0.210889,0.215276,1,0.235007,0.27659}; //float reso2[10]={0.213875,0.208,0.194,0.146034,1,1,1,1,1,1};// low // float reso2[10]={0.216908,0.208,0.194,0.146034,1,1,1,1,1,1};// high /* ifstream freso("fvtx0s_reso.txt"); for(int icent=0; icent<4; icent++){ freso>>tmp>>reso2[icent]; cout<<reso2[icent]<<endl; //reso2[icent]=1.0; } freso.close(); */ int run; //ifstream fin2("Run15pAu200GeV.Lst"); ifstream fin2(Form("../rp/goodrun_fvtx0s_v2_cent_%d.dat",centbin+1)); TFile *f=0; for(int irun=0; irun<nrun; irun++){ fin2>>run; sprintf(rootfile,"%s%d%s","data/hist_",run,".root"); f=new TFile(rootfile); cout<<irun<<" "<<rootfile<<endl; // cal v2 for(int icent=0; icent<6; icent++){ //cout<<icent<<endl; sprintf(histname1,"%s%d","hhadronv2fvtx0sY_cent_",icent); sprintf(histname2,"%s%d","hhadronv2fvtx0sY2_cent_",icent); //cout<<histname1<<endl; for(int ibin=0; ibin<binnum; ibin++){//0~60 //cout<<ibin<<endl; float con2=((TProfile *)f->Get(histname1))->GetBinContent(ibin+5); float sum2=((TProfile *)f->Get(histname1))->GetBinEntries(ibin+5); float con22=((TProfile *)f->Get(histname2))->GetBinContent(ibin+5); if(sum2>0){ con2new[icent][ibin] += con2*sum2; sum2new[icent][ibin] += sum2; con22new[icent][ibin] += con22*sum2; } }//end of ibin }//end of icent f->Close(); f->Delete(); }//end of irun fin2.close(); cout<<"finished"<<endl; for(int icent=0; icent<6; icent++){ for(int ibin=0; ibin<binnum; ibin++){ if(sum2new[icent][ibin]>0){ con2new[icent][ibin] = con2new[icent][ibin]/reso2[icent]; con22new[icent][ibin] = con22new[icent][ibin]/reso2[icent]/reso2[icent]; ssum2new[icent][ibin] += sum2new[icent][ibin]; scon2new[icent][ibin] += con2new[icent][ibin]; scon22new[icent][ibin] += con22new[icent][ibin]; } } }//end of run for(int ibin=0; ibin<binnum; ibin++){ ssum2new[10][ibin] = ssum2new[centbin][ibin];//0~5 scon2new[10][ibin] = scon2new[centbin][ibin]; scon22new[10][ibin] = scon22new[centbin][ibin]; ssum2new[11][ibin] = ssum2new[1][ibin];//5~10 scon2new[11][ibin] = scon2new[1][ibin]; scon22new[11][ibin] = scon22new[1][ibin]; ssum2new[12][ibin] = ssum2new[0][ibin]+ssum2new[1][ibin];//sigma scon2new[12][ibin] = scon2new[0][ibin]+scon2new[1][ibin]; scon22new[12][ibin] = scon22new[0][ibin]+scon22new[1][ibin]; ssum2new[12][ibin] += ssum2new[2][ibin];//sigmaa scon2new[12][ibin] += scon2new[2][ibin]; scon22new[12][ibin] += scon22new[2][ibin]; /* ssum2new[13][ibin] = ssum2new[0][ibin]+ssum2new[2][ibin];//width scon2new[13][ibin] = scon2new[0][ibin]+scon2new[2][ibin]; scon22new[13][ibin] = scon22new[0][ibin]+scon22new[2][ibin]; */ ssum2new[13][ibin] = ssum2new[3][ibin];//width scon2new[13][ibin] = scon2new[3][ibin]; scon22new[13][ibin] = scon22new[3][ibin]; /* ssum2new[14][ibin] = ssum2new[12][ibin]+ssum2new[13][ibin];//0~20 scon2new[14][ibin] = scon2new[12][ibin]+scon2new[13][ibin]; scon22new[14][ibin] = scon22new[12][ibin]+scon22new[13][ibin]; */ } float ptnew[40], eptnew[40]; float v2new[23][40], ev2new[23][40]; int j=-9999; for(int icent=10; icent<14; icent++){ for(int i=0; i<18; i++){ eptnew[i]=0; ptnew[i]=i*0.2+0.5; j=2*i; ssum2new[icent][j] += ssum2new[icent][j+1]; scon22new[icent][j] += scon22new[icent][j+1]; scon2new[icent][j] += scon2new[icent][j+1]; if(ssum2new[icent][j]>0){ v2new[icent][i]=scon2new[icent][j]/ssum2new[icent][j]; ev2new[icent][i]=sqrt(scon22new[icent][j]/ssum2new[icent][j]-(scon2new[icent][j]/ssum2new[icent][j])**2)/sqrt(ssum2new[icent][j]); } } } //ofstream fv2new0(Form("run15pAu_fvtx0s_sec%d_hadron_v2_0_5.txt",centbin+1)); ofstream fv2new0(Form("run15pAu_fvtx0s_sec123_hadron_v2_0_5.txt")); //ofstream fv2new1("run15pAu_fvtx0s_hadron_v2_5_10.txt"); //ofstream fv2new2("run15pAu_fvtx0s_hadron_v2_0_10.txt"); //ofstream fv2new3("run15pAu_fvtx0s_hadron_v2_10_20.txt"); //ofstream fv2new4("run15pAu_fvtx0s_hadron_v2_0_20.txt"); double sys[18]; double nonf[18] = {};//{0.119008,0.133265,0.172939,0.199311,0.217043,0.22896,0.328426,0.20634,0.238283}; double asys[18]; TF1 *f1 = new TF1("f1","pol2",0.2,3.5); f1->SetParameters(0.070108,0.0905807,-0.0105988); for(int i=0; i<18; i++){ nonf[i] = f1->Eval(ptnew[i]); asys[i] = sqrt(nonf[i]**2+0.11**2+0.01**2+0.01**2); sys[i] = sqrt(0.11**2+0.01**2+0.01**2); // fv2new0<<ptnew[i]<<" "<<v2new[10][i]<<" "<<ev2new[10][i]<<" "<<v2new[10][i]*sys[i]<<" "<<v2new[10][i]*asys[i]<<endl; // fv2new0<<ptnew[i]<<" "<<v2new[11][i]<<" "<<ev2new[11][i]<<" "<<v2new[11][i]*sys[i]<<" "<<v2new[11][i]*asys[i]<<endl; fv2new0<<ptnew[i]<<" "<<v2new[12][i]<<" "<<ev2new[12][i]<<" "<<v2new[12][i]*sys[i]<<" "<<v2new[12][i]*asys[i]<<endl; // fv2new0<<ptnew[i]<<" "<<v2new[13][i]<<" "<<ev2new[13][i]<<" "<<v2new[13][i]*sys[i]<<" "<<v2new[13][i]*asys[i]<<endl; //fv2new1<<ptnew[i]<<" "<<v2new[11][i]<<" "<<ev2new[11][i]<<endl; //fv2new2<<ptnew[i]<<" "<<v2new[12][i]<<" "<<ev2new[12][i]<<endl; //fv2new3<<ptnew[i]<<" "<<v2new[13][i]<<" "<<ev2new[13][i]<<endl; //fv2new4<<ptnew[i]<<" "<<v2new[14][i]<<" "<<ev2new[14][i]<<endl; } fv2new0.close(); //fv2new1.close(); //fv2new2.close(); //fv2new3.close(); //fv2new4.close(); }
void doit(const char *basename, const int nbins, const double lofit, const double hifit) { // --- read in the data and create a vector with all the values // --- note that this code requires an duplicates to have already been cleaned out // --- this is automatically fixed with the new version of the DAQ/stepper code // --- but the user would do well do double check all output files anyway ifstream fin1(Form("TEMP/%s_Unaveraged_VMin1.txt",basename)); double content; vector<double> voltage1; while(fin1>>content) { voltage1.push_back(content); } fin1.close(); cout << voltage1.size() << endl; // --- do the same for SiPM2 ifstream fin2(Form("TEMP/%s_Unaveraged_VMin2.txt",basename)); vector<double> voltage2; while(fin2>>content) { voltage2.push_back(content); } fin2.close(); cout << voltage2.size() << endl; // --- get the number of entries and the min and max int number = voltage1.size(); double max = *max_element(voltage1.begin(),voltage1.end()); double min = *min_element(voltage1.begin(),voltage1.end()); cout << max << endl; cout << min << endl; // --- use the min and max to calculate a range for the histogram double newmax = min*-0.95; double newmin = max*-1.05 - newmax*0.1; // --- create the new histogram TH1D *h1 = new TH1D("h1","",nbins,newmin,newmax); TH1D *h2 = new TH1D("h2","",nbins,newmin,newmax); TH1D *hsum = new TH1D("hsum","",nbins,2*newmin,2*newmax); TH2D *hh1v2 = new TH2D("hh1v2","",nbins*2,newmin,newmax,nbins*2,newmin,newmax); // SiPM1 vs SiPM2 TH2D *hhSvA = new TH2D("hhSvA","",nbins*2,2*newmin,2*newmax,nbins*2,-1,1); // Sum vs Asymmetry TH2D *hh1v2_cut1 = new TH2D("hh1v2_cut1","",nbins*2,newmin,newmax,nbins*2,newmin,newmax); // SiPM1 vs SiPM2 TH2D *hhSvA_cut1 = new TH2D("hhSvA_cut1","",nbins*2,2*newmin,2*newmax,nbins*2,-1,1); // Sum vs Asymmetry TH2D *hh1v2_cut2 = new TH2D("hh1v2_cut2","",nbins*2,newmin,newmax,nbins*2,newmin,newmax); // SiPM1 vs SiPM2 TH2D *hhSvA_cut2 = new TH2D("hhSvA_cut2","",nbins*2,2*newmin,2*newmax,nbins*2,-1,1); // Sum vs Asymmetry vector<double> sum; vector<double> asym; // --- loop over the vector to fill the histogram for(int i=0; i<number; i++) { // --- SiPM1 h1->Fill(-voltage1[i]); // --- SiPM2 h2->Fill(-voltage2[i]); // --- SiPM1 vs SiPM2 hh1v2->Fill(-voltage1[i],-voltage2[i]); // --- sum vs asymmetry double tempsum = -voltage1[i] + -voltage2[i]; double tempasym = (voltage1[i] - voltage2[i]) / (-voltage1[i] + -voltage2[i]); hsum->Fill(tempsum); hhSvA->Fill(tempsum,tempasym); sum.push_back(tempsum); asym.push_back(tempasym); // --- now do some cuts... if(fabs(tempasym)<0.4) { hh1v2_cut1->Fill(-voltage1[i],-voltage2[i]); hhSvA_cut1->Fill(tempsum,tempasym); } if((voltage1[i]<(voltage2[i]+20*peconvert))&&(voltage2[i]<(voltage1[i]+20*peconvert))) { hh1v2_cut2->Fill(-voltage1[i],-voltage2[i]); hhSvA_cut2->Fill(tempsum,tempasym); } } // --- make a canvas and draw the histogram TCanvas *c1 = new TCanvas("c1","",800,800); // --- rescale the histograms from volts to photoelectrons h1->GetXaxis()->SetLimits(newmin/peconvert,newmax/peconvert); h1->GetXaxis()->SetTitle("Number of photoelectrons"); h1->GetYaxis()->SetTitle("Counts"); // --- define Landau function and draw // --- don't fit yet because the data have tons of ugly low voltage1 background double height = 1049; double mu = 23; double sigma = 3; //TF1 *fun = new TF1("fun","[0]*TMath::Landau(x,[1],[2])",newmin/peconvert,newmax/peconvert); TF1 *fun = new TF1("fun","[0]*TMath::Landau(x,[1],[2])",2*newmin/peconvert,2*newmax/peconvert); fun->SetParameter(0,height); fun->SetParameter(1,mu); fun->SetParameter(2,sigma); double bgscale = 650; // guess... c1->SetLogy(0); c1->Clear(); hh1v2->Draw("colz"); hh1v2->GetXaxis()->SetLimits(newmin/peconvert,newmax/peconvert); hh1v2->GetYaxis()->SetLimits(newmin/peconvert,newmax/peconvert); hh1v2->GetXaxis()->SetTitle("#pe SiPM1"); hh1v2->GetYaxis()->SetTitle("#pe SiPM2"); c1->SetLogz(0); c1->Print(Form("Cosmics/%s_cosmics_1v2.png",basename)); c1->Print(Form("Cosmics/%s_cosmics_1v2.pdf",basename)); c1->SetLogz(1); c1->Print(Form("Cosmics/%s_cosmics_1v2_log.png",basename)); c1->Print(Form("Cosmics/%s_cosmics_1v2_log.pdf",basename)); hhSvA->Draw("colz"); hhSvA->GetXaxis()->SetLimits(2*newmin/peconvert,2*newmax/peconvert); hhSvA->GetXaxis()->SetTitle("Sum"); hhSvA->GetYaxis()->SetTitle("Asymmetry"); c1->SetLogz(0); c1->Print(Form("Cosmics/%s_cosmics_SvA.png",basename)); c1->Print(Form("Cosmics/%s_cosmics_SvA.pdf",basename)); c1->SetLogz(1); c1->Print(Form("Cosmics/%s_cosmics_SvA_log.png",basename)); c1->Print(Form("Cosmics/%s_cosmics_SvA_log.pdf",basename)); // --- now for some cuts... c1->SetLogz(0); hh1v2_cut1->Draw("colz"); hh1v2_cut1->GetXaxis()->SetLimits(newmin/peconvert,newmax/peconvert); hh1v2_cut1->GetYaxis()->SetLimits(newmin/peconvert,newmax/peconvert); hh1v2_cut1->GetXaxis()->SetTitle("#pe SiPM1"); hh1v2_cut1->GetYaxis()->SetTitle("#pe SiPM2"); TLatex *tex1 = new TLatex(0.2,0.8,"|Asymmetry|<0.4"); tex1->SetTextSize(0.05); tex1->SetNDC(kTRUE); tex1->Draw(); c1->SetLogz(0); c1->Print(Form("Cosmics/%s_cosmics_1v2_cut1.png",basename)); c1->Print(Form("Cosmics/%s_cosmics_1v2_cut1.pdf",basename)); c1->SetLogz(1); c1->Print(Form("Cosmics/%s_cosmics_1v2_cut1_log.png",basename)); c1->Print(Form("Cosmics/%s_cosmics_1v2_cut1_log.pdf",basename)); hhSvA_cut1->Draw("colz"); hhSvA_cut1->GetXaxis()->SetLimits(2*newmin/peconvert,2*newmax/peconvert); hhSvA_cut1->GetXaxis()->SetTitle("Sum"); hhSvA_cut1->GetYaxis()->SetTitle("Asymmetry"); tex1->Draw(); c1->SetLogz(0); c1->Print(Form("Cosmics/%s_cosmics_SvA_cut1.png",basename)); c1->Print(Form("Cosmics/%s_cosmics_SvA_cut1.pdf",basename)); c1->SetLogz(1); c1->Print(Form("Cosmics/%s_cosmics_SvA_cut1_log.png",basename)); c1->Print(Form("Cosmics/%s_cosmics_SvA_cut1_log.pdf",basename)); c1->SetLogz(0); hh1v2_cut2->Draw("colz"); hh1v2_cut2->GetXaxis()->SetLimits(newmin/peconvert,newmax/peconvert); hh1v2_cut2->GetYaxis()->SetLimits(newmin/peconvert,newmax/peconvert); hh1v2_cut2->GetXaxis()->SetTitle("#pe SiPM1"); hh1v2_cut2->GetYaxis()->SetTitle("#pe SiPM2"); TLatex *tex2 = new TLatex(0.2,0.8,"SiPMA < SiPMB + 20"); tex2->SetTextSize(0.05); tex2->SetNDC(kTRUE); tex2->Draw(); c1->SetLogz(0); c1->Print(Form("Cosmics/%s_cosmics_1v2_cut2.png",basename)); c1->Print(Form("Cosmics/%s_cosmics_1v2_cut2.pdf",basename)); c1->SetLogz(1); c1->Print(Form("Cosmics/%s_cosmics_1v2_cut2_log.png",basename)); c1->Print(Form("Cosmics/%s_cosmics_1v2_cut2_log.pdf",basename)); hhSvA_cut2->Draw("colz"); hhSvA_cut2->GetXaxis()->SetLimits(2*newmin/peconvert,2*newmax/peconvert); hhSvA_cut2->GetXaxis()->SetTitle("Sum"); hhSvA_cut2->GetYaxis()->SetTitle("Asymmetry"); tex2->Draw(); c1->SetLogz(0); c1->Print(Form("Cosmics/%s_cosmics_SvA_cut2.png",basename)); c1->Print(Form("Cosmics/%s_cosmics_SvA_cut2.pdf",basename)); c1->SetLogz(1); c1->Print(Form("Cosmics/%s_cosmics_SvA_cut2_log.png",basename)); c1->Print(Form("Cosmics/%s_cosmics_SvA_cut2_log.pdf",basename)); hsum->SetLineColor(kBlack); hsum->SetLineWidth(2); hsum->GetXaxis()->SetLimits(2*newmin/peconvert,2*newmax/peconvert); //hsum->GetXaxis()->SetRangeUser(0.0,120.0); hsum->GetXaxis()->SetTitle("Number of photoelectrons SiPM1+SiPM2"); hsum->Draw(); c1->Print(Form("Cosmics/%s_temp.png",basename)); c1->Print(Form("Cosmics/%s_temp.pdf",basename)); hsum->SetMaximum(30); c1->Print(Form("Cosmics/%s_templow.png",basename)); c1->Print(Form("Cosmics/%s_templow.pdf",basename)); c1->SetLogy(); hsum->SetMaximum(1.1*h1->GetBinContent(hsum->GetMaximumBin())); c1->Print(Form("Cosmics/%s_templog.png",basename)); c1->Print(Form("Cosmics/%s_templog.pdf",basename)); // --------------------------------------------------------- bgscale = 100; h1->Fit(fun,"","",lofit,hifit); fun->SetLineColor(kRed); fun->SetLineWidth(2); fun->Draw("same"); cout << fun->GetChisquare() << "/" << fun->GetNDF() << endl; c1->SetLogy(0); c1->Print(Form("Cosmics/%s_tempfit.png",basename)); c1->Print(Form("Cosmics/%s_tempfit.pdf",basename)); h1->SetMaximum(175); c1->Print(Form("Cosmics/%s_templowfit.png",basename)); c1->Print(Form("Cosmics/%s_templowfit.pdf",basename)); h1->SetMaximum(100); c1->Print(Form("Cosmics/%s_tempLOWfit.png",basename)); c1->Print(Form("Cosmics/%s_tempLOWfit.pdf",basename)); c1->SetLogy(1); h1->SetMaximum(1.1*h1->GetBinContent(h1->GetMaximumBin())); c1->Print(Form("Cosmics/%s_templogfit.png",basename)); c1->Print(Form("Cosmics/%s_templogfit.pdf",basename)); c1->Clear(); h1->Draw(); double hax = fun->GetParameter(0); double mux = fun->GetParameter(1); double six = fun->GetParameter(2); fun->SetParameter(0,0.95*hax); fun->SetParameter(1,mux); fun->SetParameter(2,1.1*six); //fun->Draw("same"); //h1->Fit(simplefun,"","",0,60); TF1 *fun2 = new TF1("fun2","([0]/sqrt(6.28))*TMath::Exp(-0.5*((x-[1])/[2] + TMath::Exp(-(x-[1])/[2])))",2*newmin/peconvert,2*newmax/peconvert); // fun2->SetParameter(0,hax); // fun2->SetParameter(1,mux); // fun2->SetParameter(2,six); // fun2->SetParameter(0,93); // fun2->SetParameter(1,35); // fun2->SetParameter(2,5); fun2->SetParameter(0,93); fun2->SetParameter(1,500); fun2->SetParameter(2,100); //fun2->SetLineColor(kBlack); h1->Fit(fun2,"","",lofit,hifit); fun2->Draw("same"); cout << fun2->GetChisquare() << "/" << fun2->GetNDF() << endl; double par1 = fun2->GetParameter(1); TLine line(par1,0,par1,0.24*fun2->GetParameter(0)); line.Draw(); c1->SetLogy(0); c1->Print(Form("Cosmics/%s_tempffit.png",basename)); c1->Print(Form("Cosmics/%s_tempffit.pdf",basename)); h1->SetMaximum(25); c1->Print(Form("Cosmics/%s_templowffit.png",basename)); c1->Print(Form("Cosmics/%s_templowffit.pdf",basename)); h1->SetMaximum(0.3*fun2->GetParameter(0)); TLatex *tex = new TLatex(0.6,0.8,Form("MPV = %.1f #pm %.1f",fun2->GetParameter(1),fun2->GetParError(1))); tex->SetNDC(); tex->SetTextSize(0.05); tex->Draw(); //h1->GetXaxis()->SetRangeUser(0.0,130.0); // new... c1->Print(Form("Cosmics/SmallTileCosmics_%s_tempLOWffit.png",basename)); c1->Print(Form("Cosmics/SmallTileCosmics_%s_tempLOWffit.pdf",basename)); c1->SetLogy(1); h1->SetMaximum(1.1*h1->GetBinContent(h1->GetMaximumBin())); c1->Print(Form("Cosmics/%s_templogffit.png",basename)); c1->Print(Form("Cosmics/%s_templogffit.pdf",basename)); }
void Query::buildIndex() { //string indexType = ""; //cout << "How would you like to build the index? Using an AVL Tree ('A') or a Hash Table('H')?"; //cin >> indexType; /*if(indexType == "A" || indexType == "a") { ifstream fin("output2.txt"); ifstream fin2("output3.txt"); string word = ""; string text = ""; string text1 = ""; string text2 = ""; string text3 = ""; string text4 = ""; string pageTitle = ""; int pageId = 0; int numOfPages = 0; int pageNum = 0; int frequency = 0; while(!fin.eof()) { fin >> word; fin.ignore(4); fin >> numOfPages; fin.ignore(2); Word* w = new Word(word); //cout << word << ": " << "[" << numOfPages << "] "; for(int b = 0; b < numOfPages; b++) { fin >> pageNum; fin.ignore(); fin >> frequency; fin.ignore(3); w->addPages(pageNum); w->addToMap(pageNum, frequency); tree.insert(w); //cout << pageNum << "(" << frequency << "), "; } //cout << endl; } while(!fin2.eof()) { fin2 >> pageTitle; fin2.ignore(3); fin2 >> pageId; /*getline(fin2, text, '$'); getline(fin2, text1, '#'); if(text1 == "$") { getline(fin2, text2, '*'); if(text2 == "#") { getline(fin2, text3, '*'); if(text3 == "*") { getline(fin2, text4, '%'); if(text4 == "*") { break; } else text = text + text1 + text2 + text3 + text4; } else text = text + text1 + text2 + text3; } else text = text + text1 + text2; } else text = text + text1; getline(fin2, text4, '%'); /*cout << "PAGE TITLE: " << pageTitle << endl; cout << "PAGE NUMBER:" << pageId << endl; cout << "TEXT: " << text << endl; Page* p = new Page(pageTitle, pageId, text); pageIndex.insert2(p); } }*/ //else if(indexType == "H" || indexType == "h") //{ ifstream fin("output2.txt"); ifstream fin2("output3.txt"); string word = ""; string text = ""; string text1 = ""; string pageTitle = ""; int pageId = 0; int numOfPages = 0; int pageNum = 0; int frequency = 0; while(!fin.eof()) { fin >> word; fin.ignore(4); fin >> numOfPages; fin.ignore(2); Word* w = new Word(word); //cout << word << ": " << "[" << numOfPages << "] "; for(int b = 0; b < numOfPages; b++) { fin >> pageNum; fin.ignore(); fin >> frequency; fin.ignore(3); w->addPages(pageNum); w->addToMap(pageNum, frequency); table.addWord(w); //cout << pageNum << "(" << frequency << "), "; } //cout << endl; } while(!fin2.eof()) { fin2 >> pageTitle; fin2.ignore(3); fin2 >> pageId; Page* p = new Page(pageTitle, pageId); pageIndex.insert2(p); } fin2.close(); //} }