Hi Axel,
Thanks for replying and here is what it wrote:
Cannot get histogram chan_0_hist_150
However my code works, it’s here:
void signalFit()
{ TFile* f0 = new TFile("nominal_signalDistributions_20170217.root");
TFile* f1 = new TFile("FitResult_4e.root","recreate");
TH1F * chan_4e_15GeV = (TH1F*)f0->Get("chan_0_hist_150");
TH1F * chan_4e_20GeV = (TH1F*)f0->Get("chan_0_hist_200");
TH1F * chan_4e_25GeV = (TH1F*)f0->Get("chan_0_hist_250");
TH1F * chan_4e_30GeV = (TH1F*)f0->Get("chan_0_hist_300");
TH1F * chan_4e_35GeV = (TH1F*)f0->Get("chan_0_hist_350");
TH1F * chan_4e_40GeV = (TH1F*)f0->Get("chan_0_hist_400");
TH1F * chan_4e_45GeV = (TH1F*)f0->Get("chan_0_hist_450");
TH1F * chan_4e_50GeV = (TH1F*)f0->Get("chan_0_hist_500");
TH1F * chan_4e_55GeV = (TH1F*)f0->Get("chan_0_hist_550");
TH1F * chan_4e_60GeV = (TH1F*)f0->Get("chan_0_hist_600");
//chan_4e_15GeV->Fit("gaus");
TF1 *fit = new TF1("fit","gaus");
FILE *fp = fopen("Chan_4e.dat","w");
chan_4e_15GeV->Fit(fit);
chan_4e_15GeV->Write();
if (fp!=NULL) {
for (int i=0;i<fit->GetNpar();i++) {
Float_t value = fit->GetParameter(i);
fprintf(fp,"%d %f",i+15,value);//will write for instance 15 1.81947416 14.90458417 0.220540 (15 means 15 GeV)
}
}
chan_4e_20GeV->Fit(fit);
chan_4e_20GeV->Write();
if (fp!=NULL) {
fprintf(fp,"\n");
for (int i=0;i<fit->GetNpar();i++) {
Float_t value = fit->GetParameter(i);
fprintf(fp,"%d %f",i+20,value);//will write 20 1.87296621 19.88915322 0.291102 (20 means 20 GeV)
}
}
chan_4e_25GeV->Fit(fit);
chan_4e_25GeV->Write();
if (fp!=NULL) {
fprintf(fp,"\n");
for (int i=0;i<fit->GetNpar();i++) {
Float_t value = fit->GetParameter(i);
fprintf(fp,"%d %f",i+25,value);
}
}
chan_4e_30GeV->Fit(fit);
chan_4e_30GeV->Write();
if (fp!=NULL) {
fprintf(fp,"\n");
for (int i=0;i<fit->GetNpar();i++) {
Float_t value = fit->GetParameter(i);
fprintf(fp,"%d %f",i+30,value);
}
}
chan_4e_35GeV->Fit(fit);
chan_4e_35GeV->Write();
if (fp!=NULL) {
fprintf(fp,"\n");
for (int i=0;i<fit->GetNpar();i++) {
Float_t value = fit->GetParameter(i);
fprintf(fp,"%d %f",i+35,value);
}
}
chan_4e_40GeV->Fit(fit);
chan_4e_40GeV->Write();
if (fp!=NULL) {
fprintf(fp,"\n");
for (int i=0;i<fit->GetNpar();i++) {
Float_t value = fit->GetParameter(i);
fprintf(fp,"%d %f",i+40,value);
}
}
chan_4e_45GeV->Fit(fit);
chan_4e_45GeV->Write();
if (fp!=NULL) {
fprintf(fp,"\n");
for (int i=0;i<fit->GetNpar();i++) {
Float_t value = fit->GetParameter(i);
fprintf(fp,"%d %f",i+45,value);
}
}
chan_4e_50GeV->Fit(fit);
chan_4e_50GeV->Write();
if (fp!=NULL) {
fprintf(fp,"\n");
for (int i=0;i<fit->GetNpar();i++) {
Float_t value = fit->GetParameter(i);
fprintf(fp,"%d %f",i+50,value);
}
}
chan_4e_55GeV->Fit(fit);
chan_4e_55GeV->Write();
if (fp!=NULL) {
fprintf(fp,"\n");
for (int i=0;i<fit->GetNpar();i++) {
Float_t value = fit->GetParameter(i);
fprintf(fp,"%d %f",i+55,value);
}
}
chan_4e_60GeV->Fit(fit);
chan_4e_60GeV->Write();
if (fp!=NULL) {
fprintf(fp,"\n");
for (int i=0;i<fit->GetNpar();i++) {
Float_t value = fit->GetParameter(i);
fprintf(fp,"%d %f",i+60,value);
}
}
fclose(fp);
}
but you can see that’s not an advanced coding.
Cheers