Blame |
Last modification |
View Log
| RSS feed
#include <stdio.h>
#include <stdlib.h>
#include <TROOT.h>
#include <TF1.h>
#include <TH1F.h>
#include <TH1D.h>
#include <TH2D.h>
#include <TCanvas.h>
#include <TStyle.h>
#include <TSystem.h>
#include <TFile.h>
#include <TDirectory.h>
#include <TPaveText.h>
#include <TStatistic.h>
#include <TNamed.h>
#include <TAxis.h>
#include <TPDF.h>
#include <TFitResult.h>
int febana(int run){
const int hid=1;
char name[128];
const char * hname = "h2d_0";
int brd[4];
sprintf(name,"%s;%d",hname,hid); //you define histogram h2d_0;1 test pulse, h2d_0;2 offset
TH2D *h = (TH2D *) gDirectory->Get(name); //this tell you directory to your histogram
//serialNumber = h->GetTitle();
/********radeliti hočem serijsko številko********************/
char b0[255], b1[255], b2[255], b3[255], b00[255], b01[255], b10[255], b11[255], b20[255], b21[255], b30[255], b31[255];
//sscanf(serialNumber,"%s%s%s%s",b0,b1,b2,b3);
sscanf(h->GetTitle(),"%s%s%s%s",b0,b1,b2,b3);
sscanf(b0, "%[^=]=%s", b00, b01); //b01 je serijska številka od borda0
sscanf(b1, "%[^=]=%s", b10, b11); //b11 je serijska številka od borda1
sscanf(b2, "%[^=]=%s", b20, b21); //b21 je serijska številka od borda2
sscanf(b3, "%[^=]=%s", b30, b31); //b31 je serijska številka od borda3
/*****************************************************************************/
/********radeliti hočem serijsko številko boarda********************/
for (int k=0;k<4;k++){
sprintf(name,"vth1_%d_0",k); //you define histogram vth1_0_0;1
TH2D * h0 = (TH2D *) gDirectory->Get(name); //this tell you directory to your histogram
if (!h0) continue;
sscanf(h0->GetTitle(),"%*s%*s%*s%*s sn=%d",&brd[k]);
printf("sn = %d\n",brd[k]);
}
/*********************Ofset scanning******************************************/
int nx=0;
int imax=36;
for (int i=2;i<=imax;i++){
sprintf(name,"h2d_0;%d",i);
TH2D *h2dp=(TH2D *) gDirectory->Get(name); // directory do grafoz z offset scanningom
if (h2dp) nx++;
}
TCanvas *c55= new TCanvas("c55","Offset scanning",1000,800); //definiramo canvase
c55->Divide(8,4); //razdelimo canvase
TCanvas *ccoarse[4];
TCanvas *cfine[4];
for (int i=0;i<4;i++){
sprintf(name,"ccoarse%d",i);
ccoarse[i]= new TCanvas(name,name,1000,800);
ccoarse[i]->Divide(4,4);
sprintf(name,"cfine%d",i);
cfine[i]= new TCanvas(name,name,1000,800);
cfine[i]->Divide(4,4);
}
TH2D *hfeb[4];
TH2D *hcoarsemean[4];
TH2D *hfinemean[4];
TH2D *hmean[4];
sprintf(name,"h2d_0;2");
TH2D *h2dz=(TH2D *) gDirectory->Get(name);
if (!h2dz) {
printf("Histogram %s not found.\n");
return 0;
}
for (int n=0;n<4;n++){
sprintf(name,"board%d", n);
hfeb[n]= new TH2D(name, name,h2dz->GetNbinsX()/4, -0.5,143.5, h2dz->GetNbinsY() , h2dz->GetYaxis()->GetXmin(), h2dz->GetYaxis()->GetXmax() );
sprintf(name,"hcoarsemean_%d", n);
hcoarsemean[n]= new TH2D(name,"Mean rough;HAPD ch;decoded offset",144,-0.5,143.5,16,-0.5,15.5);
sprintf(name,"hmean_%d", n);
hmean[n]= new TH2D(name,"Mean;HAPD ch;offset",144,-0.5,144,nx,-0.5,nx-0.5);
hmean[n]->SetMinimum(300);
hmean[n]->SetMaximum(700);
sprintf(name,"hfinemean_%d", n);
hfinemean[n]= new TH2D(name,"Mean fine;HAPD ch;decoded offset",144,-0.5,143.5,16,-0.5,15.5);
}
int i0;
int i01;
for (int i=2;i<nx+2;i++){
sprintf(name,"h2d_0;%d",i);
printf("%s\n",name);
TH2D *h2d=(TH2D *) gDirectory->Get(name);
for (int x=0;x<h2d->GetNbinsX();x++){
for (int y=0;y<h2d->GetNbinsY();y++){
float val = h2d->GetBinContent(x+1,y+1);
hfeb[x/144]->SetBinContent(x%144+1, y+1,val);
}
}
if(i<18){ //popravimo našo skalo za coarse scanning
int j= (i-2)%8;
int k= (i-2)/8;
int j0= -(1-j/1)*1;
int k0= (1-k/1)*8;
i0=j0+k0+1;
} else i0=50; //ker imamo še fine scannig, bo pri njih vrednost x-koordinate enaka 50 (za lažjo obdelovo podatkov)
if(i>17){ //popravimo našo skalo za fine scanning
int j= (i-18)%8;
int k= (i-18)/8;
int j0= -(1-j/1)*1;
int k0= (1-k/1)*8;
i01=j0+k0+1;
} else i01=50; //ker imamo še coarse scannig, bo pri njih vrednost x-koordinate enaka 50 (za lažjo obdelovo podatkov)
if (h2d){
sprintf(name,"%s %s %s %s graf %d",b01, b11, b21, b31, i-1);
h2d->SetTitle(name);
if (i>1) {
c55->cd(i-1);
h2d->DrawCopy("colz"); //narišemo vse grafe on 4 boardov za Offset scanning
}
}
for (int board=0;board<4;board++){
if (hfeb[board]){
if (i>1&&i<18) {
sprintf(name,"Coarse scanning board %d scan %d",brd[board], i-1);
hfeb[board]->SetTitle(name);
ccoarse[board]->cd(i-1);
hfeb[board]->DrawCopy("colz"); //coarse offset scanning board0
}else{
sprintf(name,"Fine scanning board %d scan %d",brd[board], i-17);
hfeb[board]->SetTitle(name);
cfine[board]->cd(i-17);
hfeb[board]->DrawCopy("colz"); //fine offset scanning board0
}
TF1 *f = new TF1("fit","gaus", 0 , 1000); //definiraš gaussovski fit
for (int ch=0;ch<hfeb[board]->GetNbinsX();ch++){
TH1D *hy0 = hfeb[board]->ProjectionY("_py",ch+1,ch+1); //narediš projekcije za vsak kanal
hy0->Fit(f,"QWWN"); //narediš fit čez projekcije
double mean = hy0->GetMean(); //prebereš mean
hcoarsemean[board]->Fill(ch,i0,mean); //napolniš grafe
hmean[board]->Fill(ch,i-2,mean);
hfinemean[board]->Fill(ch,i01,mean);
}
}
}
}
for (int board=0;board<4;board++){
sprintf(name,"board %d.pdf", brd[board]);
printf("board pri pdf %s\n",name);
ccoarse[board]->Print(name,"pdf");
cfine[board]->Print(name,"pdf");
}
/****************mean and slope together****************************/
TF1 *f0 = new TF1("mlin","pol1", 0 , 127); //linearni fit definiran za vse grafe
TCanvas * cfit[4];
TH1F *hpoolfine[4];
TH1F *hfitcoarse[4];
TH1F *hfitfine [4];
TH1F *hpoolcoarse[4];
for (int board=0;board<4;board++){
hcoarsemean[board]->FitSlicesY(f0);
sprintf(name,"%s_1",hcoarsemean[board]->GetName());
printf("%s\n",name);
hfitcoarse[board] = ((TH1F * ) gDirectory->Get(name));
hfinemean[board]->FitSlicesY(f0);
sprintf(name,"%s_1",hfinemean[board]->GetName());
printf("%s\n",name);
hfitfine[board] = ((TH1F * ) gDirectory->Get(name));
sprintf(name,"cfit%d",board);
printf("%s\n",name);
cfit[board]= new TCanvas(name,name,1000,800);
cfit[board]->Divide(1,3);
cfit[board]->cd(1);
hmean[board]->ProjectionY("hprojection1_1",1,1)->Draw();
hmean[board]->ProjectionY("hprojection1_3",3,3)->Draw("same");
hmean[board]->ProjectionY("hprojection1_10",10,10)->Draw("same");
hmean[board]->ProjectionY("hprojection1_15",15,15)->Draw("same");
cfit[board]->cd(3);
gStyle->SetOptStat(1);
sprintf(name,"hpoolfine_%d",board);
printf("%s\n",name);
hpoolfine[board] = new TH1F(name,"Fine slope together",10,-1.5,-0.7);
for (int ch=0;ch<hfitfine[board]->GetNbinsX();ch++){
hpoolfine[board]->Fill(hfitfine[board]->GetBinContent(ch+1));
}
hpoolfine[board]->Draw();
cfit[board]->cd(2);
gStyle->SetOptStat(1);
sprintf(name,"hpoolcoarse_%d",board);
printf("%s\n",name);
hpoolcoarse[board] = new TH1F(name,"Coarse slope together",10,-17,-10);
for (int ch=0;ch<hfitcoarse[board]->GetNbinsX();ch++){
hpoolcoarse[board]->Fill(hfitcoarse[board]->GetBinContent(ch+1));
}
hpoolcoarse[board]->Draw();
sprintf(name,"board %d.pdf", brd[board]);
printf("%s\n",name);
//c20->Print(name,"pdf");
}
//return;
/****************************OffsetVariation board0**********************************************/
TCanvas *c0coarse[4];
TCanvas *c0fine[4];
for (int board=0;board<4;board++){
sprintf(name,"hcoarsemean_%d",board);
TH2D *h0coarse=(TH2D *) gDirectory->Get(name);
sprintf(name,"hfinemean_%d",board);
TH2D *h0fine=(TH2D *) gDirectory->Get(name);
char nv[20];
char opt[20];
int first =0;
sprintf(name,"c0coarse%d",board);
c0coarse[board]= new TCanvas(name,name,1000,800);
c0coarse[board]->Divide(4,2);
sprintf(name,"c0fine%d",board);
c0fine[board]= new TCanvas(name,name,1000,800);
c0fine[board]->Divide(4,2);
//return;
for (int chip=0;chip<4; chip++){
c0coarse[board]->cd(chip+1);
first=0;
for (int ch=0+chip*36;ch<(36+chip*36);ch++) {
sprintf(nv,"hxc_%d",ch);
TH1D* h0coarsep= h0coarse->ProjectionY(nv,ch+1,ch+1);
//TFitResultPtr r0 = h0coarsep>Fit(f0,"SQN");
//double chi0= r0->Chi2();
if (first) sprintf(opt,"same"); else {
h0coarsep->GetXaxis()->SetRangeUser(300,1000);
sprintf(opt,"");
}
sprintf(name,"Coarse mean chip %d",chip);
h0coarsep->SetTitle(name);
h0coarsep->SetMinimum(350);
h0coarsep->SetMaximum(750);
h0coarsep->Draw(opt);
first=1;
}
}
gStyle->SetOptStat(1);
for (int chip=0;chip<4;chip++){
c0coarse[board]->cd(chip+5);
sprintf(name,"hslopecoarse%dchip%d",board,chip);
TH1F *hpool = new TH1F(name,name,10,-17,-10);
for (int ch=0+chip*36;ch<(36+chip*36);ch++){
hpool->Fill(hfitcoarse[board]->GetBinContent(ch+1));
}
hpool->Draw();
}
for (int chip=0;chip<4; chip++){
c0fine[board]->cd(chip+1);
first=0;
for (int ch=0+chip*36;ch<(36+chip*36);ch++) {
sprintf(nv,"hxf_%d",ch);
TH1D* h0finep= h0fine->ProjectionY(nv,ch+1,ch+1);
TFitResultPtr r0 = h0finep->Fit(f0,"SQN");
double chi0= r0->Chi2();
if (first) sprintf(opt,"same"); else {
h0finep->GetXaxis()->SetRangeUser(300,1000);
sprintf(opt,"");
}
sprintf(name,"Fine mean chip %d",chip);
h0finep->SetTitle(name);
h0finep->SetMinimum(400);
h0finep->SetMaximum(600);
h0finep->Draw(opt);
first=1;
}
}
for (int chip=0;chip<4;chip++){
c0fine[board]->cd(chip+5);
sprintf(name,"hslopefine%dchip%d",board,chip);
TH1F *hpool = new TH1F(name,name,10,-1.5,-0.7);
for (int ch=0+chip*36;ch<(36+chip*36);ch++){
hpool->Fill(hfitfine[board]->GetBinContent(ch+1));
}
hpool->Draw();
}
c0coarse[board]->Update();
c0fine[board]->Update();
/* sprintf(pngname,"C:\\home\\anze\\print\\scan\\Offset Variation\\%s %s.png",Offset0,b01);
c0v->SaveAs(pngname, "png");*/
sprintf(name,"board %d.pdf", brd[board]);
c0coarse[board]->Print(name,"pdf");
sprintf(name,"board %d.pdf)", brd[board]);
c0fine[board]->Print(name,"pdf");
}
/************************Slope**************************************************/
/*FILE *fp1 = fopen("Slope vsi.txt","at");
if (fp1!=NULL) {
fprintf(fp1,"%s , %f , %f , %f , %f , %f , %f , %f , %f , %f , %f\n",b01,hpool0->GetMean(),hpool01->GetMean(), hpool0100->GetMean(), hpool0101->GetMean(), hpool0102->GetMean(), hpool0103->GetMean(), hpool0104->GetMean(), hpool0105->GetMean(), hpool0106->GetMean(), hpool0107->GetMean());
fprintf(fp1,"%s , %f , %f , %f , %f , %f , %f , %f , %f , %f , %f\n",b11,hpool1->GetMean(),hpool11->GetMean(), hpool1110->GetMean(), hpool1111->GetMean(), hpool1112->GetMean(), hpool1113->GetMean(), hpool1114->GetMean(), hpool1115->GetMean(), hpool1116->GetMean(), hpool1117->GetMean());
fprintf(fp1,"%s , %f , %f , %f , %f , %f , %f , %f , %f , %f , %f\n",b21,hpool2->GetMean(),hpool21->GetMean(), hpool2120->GetMean(), hpool2121->GetMean(), hpool2122->GetMean(), hpool2123->GetMean(), hpool2124->GetMean(), hpool2125->GetMean(), hpool2126->GetMean(), hpool2127->GetMean());
fprintf(fp1,"%s , %f , %f , %f , %f , %f , %f , %f , %f , %f , %f\n",b31,hpool3->GetMean(),hpool31->GetMean(), hpool3130->GetMean(), hpool3131->GetMean(), hpool3132->GetMean(), hpool3133->GetMean(), hpool3134->GetMean(), hpool3135->GetMean(), hpool3136->GetMean(), hpool3137->GetMean());
}
fclose(fp1);
/***********************************vsi nakloni iz vseh kanalov*************************************************/
/*for(int ch=0;ch<144;ch++){
FILE *fp2 = fopen("proba tocke.txt","at");
if (fp2!=NULL) {
//fprintf(fp2,"%s , %f , %f\n",b01,hfito10->GetBinContent(ch+1),hfito101->GetBinContent(ch+1));
//fprintf(fp2,"%s , %f , %f\n",b11,hfito11->GetBinContent(ch+1),hfito111->GetBinContent(ch+1));
//fprintf(fp2,"%s , %f , %f\n",b21,hfito12->GetBinContent(ch+1),hfito121->GetBinContent(ch+1));
fprintf(fp2,"%s , %f , %f\n",b31,hfito13->GetBinContent(ch+1),hfito131->GetBinContent(ch+1)));
}
}
/****************************************************************************************************/
return 0;
}