#include "TCanvas.h" #include "TGraph.h" #include "TH2.h" #include "TMath.h" #include "TNtuple.h" #include "TStyle.h" #include #include #include #include #include #include void ReFitResol( char * path = "/data/ncant06/a/palencia/tof_5.3.3/calibrations/", char *store = "feb_06", int west = 0) { char histoname[50]; char tempname[50]; char tempname1[50]; char rootfile[200]; char txtfile[200]; char s[500]; int changed; sprintf(rootfile,"%s/root/%s_pmtres-calib.root", path, store); TFile *newfile = new TFile(rootfile); ifstream txt_file; if (!west)sprintf(txtfile,"%s/files/%s_PmtRes-calib_e.txt", path, store); if (west) sprintf(txtfile,"%s/files/%s_PmtRes-calib_w.txt", path, store); txt_file.open(txtfile); ofstream txt_file_out; sprintf(s,"%s/files/temp_resol.txt", path); cout << s << endl; txt_file_out.open(s); while (txt_file){ int bar; double resol, slope, c3, c4; txt_file >> bar >> resol >> c3 >> slope >> c4; if (txt_file.eof()) { cout << "txt_file.eof() is true!" << endl; break; } changed = 0; if (resol <0.05 || resol > 0.2) { changed = 1; cout << " Before, pmt: " << bar << ", resol = " << resol << " +- " << c3 << ", slope = " << slope << " +- " << c4 << endl; if (!west) sprintf(histoname,"resid_east_%d",bar); if (west) sprintf(histoname,"resid_west_%d",bar); cout << histoname << endl; TH2F* histotemp = (TH2F*) newfile->Get(histoname); sprintf(tempname,"temp%d",bar); histotemp->SetName(tempname); histotemp->FitSlicesY(); sprintf(tempname1,"temp%d_2",bar); TH1F* histotemp_2 = (TH1F*) gDirectory->Get(tempname1); TF1 *f1 = new TF1("f1","pol1",0.,300.); histotemp_2->Fit("f1","Q"); histotemp_2->Draw(); double new_slope = f1->GetParameter(1); double new_slope_err = f1->GetParError(1); double new_offset = f1->GetParameter(0); double new_offset_err = f1->GetParError(0); double new_resol = 300*new_slope + new_offset; double new_resol_err = TMath::Sqrt(300*300*new_slope_err*new_slope_err + new_offset_err*new_offset_err); cout << " Resol (z=0) = " << new_offset << ", -slope = " << new_slope << endl; cout << " Resol (z=300) = " << new_resol << endl; if ((new_offset*new_offset - 0.04037*0.04037)<0){ cout << "******ERROR in bar " << bar<< " west"<Close(); }