/////ビン幅を1 keV にするプログラム///// /////足し合わせるのは他でやるか追加で関数を後で書きましょう///// #include #include #include #include #include #include #include #include #include #include #include #include #include // namespace std // int binchangeall(char *filename){ // /////まずは各runのヒストグラムの入ったrootファイルを読み込む(hist[]として中の各ヒストグラムを取り出す)///// // ifstream ifs(filename); // // int runnumtemp; // int runnum[12]={}; // TFile *file[12]; // TH1D *hist[12][22]; // // string histname[100]; // // int i=0; // ifs>>runnumtemp; // // while(!ifs.eof()){ // runnum[i]=runnumtemp; // file[i] = TFile::Open(Form("./outroot/Spectrum_run%04d.root",runnum[i])); // cout<< i << "\t" << "run" << runnum[i] << " is loaded."<>runnumtemp; // } // // int chnum[22]={1,2,3,4,5,6,7,8, 17,18,19,20,21,22,23, 29,30,31,32,33,34,35}; // // // specout->cd(); // // char *histname; // // sprintf(histname,"GammaEnergy_s%d_Run%d",chnum[0],runnum[0]); // // hist[0][0] = (TH1D*)file[0]->Get(histname); // for (size_t j = 0; j < 12; j++) { // for (size_t c = 0; c < 22; c++) { // sprintf(histname,"GammaEnergy_s%d_Run%d",chnum[c],runnum[j]); // // cout<Get(histname); // // specout->cd(); // // hist[j][i]->Write(); // // cout<<"OK"; // } // } // // hist[0][0]->Draw(); // // specout->cd(); // // for (size_t i = 0; i < 22; i++) { // // for (size_t j = 0; j < 12; j++) { // // hist[j][i]->Write(); // // } // // } // // hist[0][0]->Write(); // /* // TH1::SetDefaultSumw2(); // // TChain *tree = new TChain("dataTree"); // tree -> Add(Form("../runroot/run%04d_*.root",runnum)); // cout << Form("run%04d_000.root",runnum) << endl; // // */ // char *calibpath[12]; // // /////ここはif文に変えると早くなるはず///// // for (size_t i = 0; i < 12; i++) { // sprintf(calibpath[i],"./%04d/calib.txt",runnum[i]); // } // } int binchangeinrun(int runnum){ // cout<<"OK"< > A(100, vector(2)); string str; int ii = 0; int jj = 0; int kk = 0; float temp = 0; if(!ifs){ std::cout<<"Error!"; return 1; } while(getline(ifs,str)){ string token; istringstream stream(str); while(getline(stream,token,'\t')){ // タブ区切り ii = kk/3; jj = kk%3; // cout<Get(histname); // specout->cd(); // hist[j][i]->Write(); // cout<<"OK"; } /////////////////////////////////////////////////////////////// int binnum = 10000; int n; double xx; int x; double yy; int y; int event_x; int event_y; int event_z; int c_event; for(int d = 0; d < binnum; d ++){ // n = d +1 ;//bin number は 1 から始まる for (size_t i = 0; i < 22; i++) { // xx = n / a[i]; //a が 1.6, n = 3 の時には ,ad = 1.25 // x = xx; //新しいヒストグラムのn=3の始まりは前のものの1と2の間にある // // yy = d / a[i]; //次のbinの始まりの位置 // y = yy; //今回だと // // if (a[i]<1 && a[i]>0) {//1 bin < 1 keV の時は3 bin合わせて1 bin がある。 // event_x = hist[i]->GetBinContent(x+1); // event_y = hist[i]->GetBinContent(y+1); // // if (x == y + 1) { // c_event += (x * a[i] - n + 1) * event_y / a[i] + (n - x * a[i]) * event_x / a[i]; // } // else { // event_z = hist[i]->GetBinContent(x); // c_event += (x * a[i] - n + 1) * event_y / a[i] + event_z + (n - x * a[i]) * event_x / a[i]; // } // } // else if (a[i]>=1) {//1 bin >= 1 keV の時は2 bin合わせて1 bin しかない。 // event_x = hist[i]->GetBinContent(x+1); // // if (x == 0 || x == y) { // c_event += event_x / a[i]; // } // else { // event_y = hist[i]->GetBinContent(y+1); // c_event += (x * a[i] - n + 1) * event_y / a[i] + (n - x * a[i]) * event_x / a[i]; // } // } } // newhist->Fill(n, c_event); // if(d%1000==0)cout<cd() // newhist->Write(); // // specout->Close(); return 0; } // int binchangeindetector(char *filename){ // ifstream ifs(filename); // // int runnumtemp; // int runnum[12]={}; // TFile *file[12]; // TH1D *hist[12][22]; // // int i=0; // ifs>>runnumtemp; // // while(!ifs.eof()){ // runnum[i]=runnumtemp; // file[i] = TFile::Open(Form("./outroot/Spectrum_run%04d.root",runnum[i])); // cout<< i << "\t" << "run" << runnum[i] << " is loaded."<>runnumtemp; // } // /////////////////////////////////////////////////////////////// // /////calib.txt から bin 幅を読み取る///// // char *calibpath; // double a[12][22]={}; // float A[22][3] = {}; // // for (size_t i = 0; i < 12; i++) {// i =runnum // sprintf(calibpath, "./%04d/calib.txt",runnum[i]); // ifstream ifs(calibpath); // cout<Get(histname); // // cout<<"OK"<0) {//1 bin < 1 keV の時は3 bin合わせて1 bin がある。 // event_x = hist[i][j]->GetBinContent(x+1); // event_y = hist[i][j]->GetBinContent(y+1); // // if (x == y + 1) { // c_event += (x * a[i][j] - n + 1) * event_y / a[i][j] + (n - x * a[i][j]) * event_x / a[i][j]; // } // else { // event_z = hist[i][j]->GetBinContent(x); // c_event += (x * a[i][j] - n + 1) * event_y / a[i][j] + event_z + (n - x * a[i][j]) * event_x / a[i][j]; // } // } // else if (a[i][j]>=1) {//1 bin >= 1 keV の時は2 bin合わせて1 bin しかない。 // event_x = hist[i][j]->GetBinContent(x+1); // // if (x == 0 || x == y) { // c_event += event_x / a[i][j]; // } // else { // event_y = hist[i][j]->GetBinContent(y+1); // c_event += (x * a[i][j] - n + 1) * event_y / a[i][j] + (n - x * a[i][j]) * event_x / a[i][j]; // } // } // } // newhist[j]->Fill(n, c_event); // if(d%1000==0)cout<cd() // for (size_t i = 0; i < 22; i++) { // newhist[i]->Write(); // // specout->Close(); // return 0; // } // int binchangeall(char *filename){ // ifstream ifs(filename); // // int runnumtemp; // int runnum[12]={}; // TFile *file[12]; // TH1D *hist[12][22]; // // int i=0; // ifs>>runnumtemp; // // while(!ifs.eof()){ // runnum[i]=runnumtemp; // file[i] = TFile::Open(Form("./outroot/Spectrum_run%04d.root",runnum[i])); // cout<< i << "\t" << "run" << runnum[i] << " is loaded."<>runnumtemp; // } // /////////////////////////////////////////////////////////////// // /////calib.txt から bin 幅を読み取る///// // char *calibpath; // double a[12][22]={}; // float A[22][3] = {}; // // for (size_t i = 0; i < 12; i++) {// i =runnum // sprintf(calibpath, "./%04d/calib.txt",runnum[i]); // ifstream ifs(calibpath); // cout<Get(histname); // // cout<<"OK"<0) {//1 bin < 1 keV の時は3 bin合わせて1 bin がある。 // event_x = hist[i][j]->GetBinContent(x+1); // event_y = hist[i][j]->GetBinContent(y+1); // // if (x == y + 1) { // c_event += (x * a[i][j] - n + 1) * event_y / a[i][j] + (n - x * a[i][j]) * event_x / a[i][j]; // } // else { // event_z = hist[i][j]->GetBinContent(x); // c_event += (x * a[i][j] - n + 1) * event_y / a[i][j] + event_z + (n - x * a[i][j]) * event_x / a[i][j]; // } // } // else if (a[i][j]>=1) {//1 bin >= 1 keV の時は2 bin合わせて1 bin しかない。 // event_x = hist[i][j]->GetBinContent(x+1); // // if (x == 0 || x == y) { // c_event += event_x / a[i][j]; // } // else { // event_y = hist[i][j]->GetBinContent(y+1); // c_event += (x * a[i][j] - n + 1) * event_y / a[i][j] + (n - x * a[i][j]) * event_x / a[i][j]; // } // } // } // newhist[j]->Fill(n, c_event); // if(d%1000==0)cout<cd() // for (size_t i = 0; i < 22; i++) { // newhist[i]->Write(); // // specout->Close(); // return 0; // }