The complete code is:
[code]{
gROOT->Reset();
#include “TSystem.h”
#include
#include
using namespace std;
const char* inDir = “/data/PhD/Data\ Analysis/w01s04-hist/”;
const char* ext = “.csv”;
char* dir = gSystem->ExpandPathName(inDir);
void* dirp = gSystem->OpenDirectory(dir);
//gSystem->FreeDirectory(dirp);
if(!dirp) {
printf(“Failed to open directory: %d\n”,inDir);
return;
}
const char* entry;
const char* filename[100];
FILE *inp;
TString str;
Int_t j;
ofstream output;
while(entry = gSystem->GetDirEntry(dirp)) {
str = entry;
if( str.EndsWith(ext) ) {
filename[j++] = gSystem->ConcatFileName(dir,entry);
}
for(Int_t i=0;i<j;i++){
FILE *inp = fopen(filename[i],"r");
float x,y1,y2,y3,y4,y5,y6,y7,y8;
Double_t nbins = 4100;
Double_t xmin = 0;
Double_t xmax = (Double_t)nbins;
TCanvas *c1 = new TCanvas();
TH1F *adc = new TH1F("adc",entry,nbins,xmin,xmax);
/* Histogramm wird mit Daten gefüllt */
for(int k=1;k<nbins;k++){
fscanf(inp,"%f; %f; %f; %f; %f; %f; %f; %f; %f;",&x,&y1,&y2,&y3,&y4,&y5,&y6,&y7,&y8);
adc->Fill(x,y5);
}
fclose(inp);
adc->SetMaximum(800);
//c1->SetLogy(1);
Double_t par[12];
TF1 *g1 = new TF1("g1","gaus",1450,1650);
TF1 *g2 = new TF1("g2","gaus",1660,1800);
TF1 *g3 = new TF1("g3","gaus",2000,2180);
TF1 *g4 = new TF1("g4","gaus",2200,2450);
TF1 *total = new TF1("total","gaus(0)+gaus(3)+gaus(6)+gaus(9)",1450,2450);
adc->Fit("g1","R");
adc->Fit("g2","R+");
adc->Fit("g3","R+");
adc->Fit("g4","R+");
g1->GetParameters(&par[0]);
g2->GetParameters(&par[3]);
g3->GetParameters(&par[6]);
g4->GetParameters(&par[9]);
total->SetParameters(par);
adc->Fit("total","R+");
/* /\* Zeichne Histogramm *\/ */
c1->Update();
adc->Draw("L");
total->SetLineColor(kRed);
total->Draw("SAME");
/* Schreibe Plot in png-File */
gSystem->ProcessEvents();
char imgname[150];
sprintf(imgname,"/data/PhD/Data\ Analysis/w01s04-hist/spec_plots/gauss_%s.png",entry);
c1->SaveAs(imgname);
Float_t chpos1 = total->GetParameter(1);
Float_t sig1 = total->GetParameter(2);
Float_t chpos2 = total->GetParameter(4);
Float_t sig2 = total->GetParameter(5);
Float_t chpos3 = total->GetParameter(7);
Float_t sig3 = total->GetParameter(8);
Float_t chpos4 = total->GetParameter(10);
Float_t sig4 = total->GetParameter(11);
/* Schreibe Daten-Output-File für Gauss-Fit-Peaks */
char outname[150];
sprintf(outname,"/data/PhD/Data\ Analysis/w01s04-hist/dat/gauss_peaks_%s_1.dat",entry);
output.open(outname);
output << "Peak " << "Position[keV] " << "Sigma " << endl;
output << "Ti-KAlpha " << chpos1 << " " << sig1 << endl;
output << "Ti-KBeta " << chpos2 << " " << sig2 << endl;
output << "Mn-KAlpha " << chpos3 << " " << sig3 << endl;
output << "Mn-KBeta " << chpos4 << " " << sig4 << endl;
output.close();
return 0;
delete total, g1, g2, g3, g4;
delete adc;
c1->Close();
}
}
return;
}
[/code]