domenica 18 dicembre 2011

hist.c


// cd C:\Users\Studenti_Simone\Desktop\CorsoSimone\LezioneMilillo\3Novembre\ROOT
//root
//.L Hist.C
void PlotHistogram()
{

FILE *my_file = fopen("C:\\Users\\Studenti_Simone\\Desktop\\CorsoSimone\\Risorse\\isto.txt","r");
if(!my_file)
{
printf("\n file di input non trovato /n ");
return ;
};


//mettilo cosi ti toglie la prima riga!!!!!
   char line[1024];
fgets(line,1025,my_file);

float dato ;
TH1F *hist=new TH1F ( " asse x ", " asse y ",10 , 10 , 20 ) ;
int i=0;
while (fscanf(my_file,"%f %*s",&dato) && i<1000)
{
//printf("%f\n", dato);
hist->Fill(dato);
i++;
}




i=0;
while ( i<=11)
{
printf("BinContent %f \n", hist->GetBinContent(i));
i++;
}


fclose(my_file);
TCanvas*c1=new TCanvas();

hist->Draw();

}

void PlotHistogram2D()
{

FILE *my_file = fopen("C:\\Users\\Studenti_Simone\\Desktop\\CorsoSimone\\Risorse\\isto.txt","r");
if(!my_file)
{
printf("\n file di input non trovato /n ");
return ;
};


//mettilo cosi ti toglie la prima riga!!!!!
   char line[1024];
fgets(line,1025,my_file);

float dato1, dato2 ;
TH2F *hist=new TH2F ( " X ", " Ë Un bellissimo istogramma ",10, 0.05 , 0.5,20 , 16 , 32 ) ;
//su x ho messo slope su y N
while (fscanf(my_file,"%f %f",&dato1, &dato2) && !feof(my_file))
{
//printf("%f\n", dato);
hist->Fill(dato2,dato1);
}
fclose(my_file);

TCanvas*c1=new TCanvas();

hist->SetMarkerColor(2);
hist->SetMarkerStyle(6);
hist->Draw();

}

void motobalistico()
{
double v0x=4, v0y=6, passo=0.001 ;
int t=30, i=0 , step=50;
double x[51] , y[51];
// creare un grafico
TGraph *gr = new TGraph(t,x,y);


while (i<step){
x[i]=v0x*i;
y[i]=(v0y*i)-(0.5*9.28*i*i);
gr->SetPoint(i,x[i],y[i]);
i++;
}


TCanvas*c1=new TCanvas("C1","Cinematica", 200,10, 600, 400);
gr->Draw("AC*");
// Draw A = mostra assi * mostra il segno sul punto
//TMath::Sin()
}




void PlotHistogramSlope()
{

FILE *my_file = fopen("C:\\Users\\Studenti_Simone\\Desktop\\CorsoSimone\\Risorse\\isto.txt","r");
if(!my_file)
{
printf("\n file di input non trovato /n ");
return ;
};


//mettilo cosi ti toglie la prima riga!!!!!
   char line[1024];
fgets(line,1025,my_file);

// ISTOGRAMMA PER SLOPE

float dato ;
TH1F *hist=new TH1F ( " Slope", " asse y ",100  , -0.03 , 0.5 ) ;
int i=0;
while (fscanf(my_file," %*s %f ",&dato) && i<1000)
{
//printf("%f\n", dato);
hist->Fill(dato);
i++;
}




i=0;
while ( i<=11)
{
printf("BinContent %f \n", hist->GetBinContent(i));
i++;
}


//fclose(my_file);
TCanvas*c1=new TCanvas();

hist->SetFillColor(2);
hist->Draw();



// ISTOGRAMMA PER N
//mi riposiziono sennÚ Root legge sempre l'ultimo

rewind(my_file);
char line2[1024];
fgets(line2,1025,my_file);

i=0;
float dato2 ;
TH1F *hist2=new TH1F ( "N ", " asse y ",20 ,11 , 31 ) ;
int i=0;
while (fscanf(my_file,"%f %*s",&dato2) && i<1000)
{
//printf("%f\n", dato2);
hist2->Fill(dato2);
i++;
}




i=0;
while ( i<=11)
{
printf("BinContent %f \n", hist2->GetBinContent(i));
i++;
}


fclose(my_file);
TCanvas*c2=new TCanvas();

hist2->SetFillColor(kOrange -3);
hist2->Draw();

}

void Dipendenza()
{

FILE *my_file = fopen("C:\\Users\\Studenti_Simone\\Desktop\\CorsoSimone\\Risorse\\isto.txt","r");
if(!my_file)
{
printf("\n file di input non trovato /n ");
return ;
};


//mettilo cosi ti toglie la prima riga!!!!!
   char line[1024];
fgets(line,1025,my_file);

float dato, dato2 ;


//Bin1

TH1F *hist0=new TH1F ( " Bin1 ", " asse y ",25 , 10 , 35 ) ;
TH1F *slope0=new TH1F ( " Slope1 ", " asse y ",10 , 0 , 0.06 ) ;
int i=0;
while (fscanf(my_file,"%f %f",&dato , &dato2) && i<3100)
{
if(dato2<0.05 && dato>15){
//printf("%f\n", dato);
slope0->Fill(dato2);
hist0->Fill(dato);
}
i++;
}

rewind(my_file);
fgets(line,1025,my_file);



//Bin2

TH1F *hist=new TH1F ( " Bin2 ", " asse y ",25 , 10 , 35 ) ;
int i=0;
while (fscanf(my_file,"%f %f",&dato , &dato2) && i<3100)
{
if(dato2<0.15 && dato2>0.05 && dato>15){
//printf("%f\n", dato);
hist->Fill(dato);
}
i++;
}

rewind(my_file);
fgets(line,1025,my_file);

//Bin 3

TH1F *hist2=new TH1F ( " Bin3 ", " asse y ",25 , 10 , 35 ) ;
int i=0;
while (fscanf(my_file,"%f %f",&dato , &dato2) && i<3100)
{
if(dato2>0.15 && dato2<0.25 && dato>15){
//printf("%f\n", dato);
hist2->Fill(dato);
}
i++;
}



rewind(my_file);
fgets(line,1025,my_file);

//Bin 4

TH1F *hist4=new TH1F ( " Bin4 ", " asse y ",25 , 10 , 35 ) ;
int i=0;
while (fscanf(my_file,"%f %f",&dato , &dato2) && i<3100)
{
if(dato2>0.15 && dato2<0.25 && dato>15){
//printf("%f\n", dato);
hist4->Fill(dato);
}
i++;
}

i=0;
while ( i<=11)
{
printf("BinContent %f \n", hist->GetBinContent(i));
i++;
}


fclose(my_file);
TCanvas*c1=new TCanvas();
c1->Divide(2,3);
c1->cd(2);
hist->Draw();
c1->cd(3);
hist2->Draw();
c1->cd(1);
hist0->Draw();
c1->cd(4);
hist4->Draw();
c1->cd(5);
slope0->Draw();

}


void graficoTemp()
{

int  i=0;
double x[1500] , y[1500], m[1500];


FILE *my_file = fopen("C:\\Users\\Studenti_Simone\\Desktop\\CorsoSimone\\Risorse\\RisultatoTempDay.txt","r");
if(!my_file)
{
printf("\n file di input non trovato /n ");
return ;
};





TGraph *gr = new TGraph(i,x,y);
//su x ho messo slope su y N
while (fscanf(my_file,"%*s %lf %lf",&x[i], &y[i]) && !feof(my_file))
{
printf("%f\n", x[i]);
m[i]=(((y[i]-y[0])/60)/60);

gr->SetPoint(i,m[i],x[i]);
i++;
}
fclose(my_file);








TCanvas*c1=new TCanvas("C1","Temperatura", 200,10, 400, 500);
gr->Draw("A*");
// Draw A = mostra assi * mostra il segno sul punto
//TMath::Sin()
}

Nessun commento:

Posta un commento