void ch2ns(TH2* hist, int IDsta=1, TString opt=""){ /* ROOT Macro for TDC calibration from 2d histogram (ID vs Traw) input: 2d-hist option="nstop" -> wait is skipped output: ch2ns.txt -> calibration values */ // modify this line if you need const double period=10;// period of TDC calibrator (ns) Int_t nbin=hist->GetXaxis()->GetNbins(); Int_t num=0; vector prm; hist->Draw(); gPad->GetCanvas()->Clear(); gPad->GetCanvas()->Divide(1,2); for (Int_t i=IDsta-1;i num++; Int_t ID = i+1; TH1 *h=MakeBanY(hist,ID); gPad->GetCanvas()->cd(1); h->Draw(); gPad->GetCanvas()->cd(2); double val=GetPrmFromHist(h,period); prm.push_back(val); // Draw gPad->GetCanvas()->Update(); cout<<"ID="<::iterator it=prm.begin(); while(it!=prm.end()){ ofs1<<*it<GetMaximum()*0.2;// threshold for peak search int nbin = h->GetXaxis()->GetNbins(); Double_t xmin,xmax; double p[3]; vector peaks; vector tvals; int OverThre=0; for(int ibin=1;ibinGetBinContent(ibin)>thre ){ OverThre=1; xmin=h->GetXaxis()->GetBinCenter(ibin); }else if ( OverThre==1 && h->GetBinContent(ibin)GetXaxis()->GetBinCenter(ibin); } if (OverThre==2){ OverThre=0; TF1 *func = new TF1("myfunc","gaus"); double mean = 0.5*(xmin+xmax); double rms = 0.5*0.3*(xmax-xmin); func->SetParameters( h->GetMaximum(), h->GetMean(), h->GetRMS() ); h->Fit(func,"Q","",xmin,xmax); func->GetParameters(p); // cout<<"peak value is "<Fit("pol1","Q"); TString title=h->GetName(); tg->SetTitle(title); tg->Draw("AP*"); tg->GetXaxis()->SetRangeUser(h->GetXaxis()->GetXmin(), h->GetXaxis()->GetXmax()); calval=tg->GetFunction("pol1")->GetParameter(1); return calval; } //___________________________________________________________________________ TH1* MakeBanY(TH2* hist, Int_t id){ TString str=hist->GetName(); ostringstream oss; oss<ProjectionY(str.Data(),id,id); } //___________________________________________________________________________ bool Wait(){ //check and quit if q is typed printf("[enter]:continue, [q]:quit >"); char s[1]; gets(s); if(s[0]=='q') { cout<<"Break fit loop"<