mcr/calib/tofino/DetermineKaonThreshold.C

00001 /*
00002 ======================================================================
00003   DetermineKaonThreshold(TString const &filename)
00004     Read a root file (produced by TofinoStability) and find the threshold
00005     for kaons in the sqrt(ADCe*ADCp) spectrum of high threshold.
00006 ======================================================================
00007 */
00008 #include <iostream>
00009 #include "TH1.h"
00010 #include "TF1.h"
00011 #include "TFile.h"
00012 #include "TStyle.h"
00013 #include "TCanvas.h"
00014 #include "TPad.h"
00015 #include "TArrow.h"
00016 
00017 void DetermineKaonThreshold(TString const &filename){
00018   gStyle->SetOptFit(1);
00019   TFile *f=new TFile(filename);
00020   if (!f){
00021     cout << "File does not exist." << endl;
00022     return;
00023   }
00024   TH1F *AdcSqr[12];
00025   TArrow *th_arrow[12];
00026   TString hname;
00027   TF1 *fit_func, *landau_fit;
00028   Int_t threshold[12];
00029   TCanvas *c1=new TCanvas("c1","c1",0,0,800,640);
00030   c1->Divide(3,2);
00031   TCanvas *c2=new TCanvas("c2","c2",0,0,800,640);
00032   c2->Divide(3,2);
00033   //  TPad *pad1=new TPad("pad1","pad1",0,0,1,1);
00034 //    pad1->SetFillStyle(4000);
00035 //    pad1->Draw();
00036 //    pad1->cd();
00037   for (Int_t sl=0; sl<12; sl++){
00038     if (sl<6) c1->cd(sl+1);
00039     else c2->cd(sl-5);
00040     hname="TofinoAdcKaonSqrAll_";
00041     hname+=(sl+1);
00042     AdcSqr[sl]=(TH1F*) f->Get(hname);
00043     if (!AdcSqr[sl]){
00044       cout << "Input root file is too old... Make a updated one!" << endl;
00045       return;
00046     }
00047     fit_func=new TF1("fit_func", "landau(0)+landau(3)",0,1200);
00048     fit_func->SetParameter(0,1000);
00049     fit_func->SetParameter(1,200);
00050     fit_func->SetParLimits(1,200,400);
00051     fit_func->SetParameter(2,100);
00052     fit_func->SetParLimits(2,0,400);
00053     fit_func->SetParameter(3,10000);
00054     fit_func->SetParameter(4,800);
00055     fit_func->SetParLimits(4,500,1000);
00056     fit_func->SetParameter(5,100);
00057     fit_func->SetParLimits(5,30,100);
00058     AdcSqr[sl]->Fit("fit_func","Q","",0,1200);
00059     //   AdcSqr[sl]->Fit("landau","","",0,1200);
00060     AdcSqr[sl]->Draw();
00061 
00062     landau_fit=new TF1("landau_fit","landau(0)",0,1200);
00063     landau_fit->SetParameter(0,fit_func->GetParameter(3));
00064     landau_fit->SetParameter(1,fit_func->GetParameter(4));
00065     landau_fit->SetParameter(2,fit_func->GetParameter(5));
00066     landau_fit->SetLineColor(kRed);
00067     landau_fit->Draw("same");
00068     Double_t landau_x=fit_func->GetParameter(4), landau_y;
00069     Double_t maxy=landau_fit->Eval(landau_x);
00070     do{
00071       landau_x-=0.1;
00072       landau_y=landau_fit->Eval(landau_x);
00073     } while (landau_y>maxy*0.01);
00074     threshold[sl]=(Int_t) landau_x;
00075      th_arrow[sl] = new TArrow(threshold[sl], 0.05*AdcSqr[sl]->GetMaximum(),
00076                               threshold[sl], 0.5*AdcSqr[sl]->GetMaximum(),
00077                               0.02,"<|");
00078     th_arrow[sl]->SetLineWidth(2);
00079     th_arrow[sl]->SetLineColor(kBlue);
00080     th_arrow[sl]->SetFillColor(kBlue);
00081     th_arrow[sl]->Draw();
00082     //    pad1->Modified();
00083     //    c1->Update();    
00084     cout << "Slab " << sl+1 << " : threshold=" << threshold[sl] << endl;
00085   }}

Generated on Tue Oct 16 15:40:47 2007 by  doxygen 1.5.2