#include <stdio.h>
#include
#include
#include “TCanvas.h”
#include “TF1.h”
#include “TFile.h”
#include “TGraphErrors.h”
#include “TH1.h”
#include “TH2.h”
#include “TSpectrum.h”
using namespace std;
Double_t fitpeak (TH1F *histo)
{
TF1 *fS = new TF1(“fS”,“gaus”,900,1200); //Range change for both
fS->SetParNames(“height”,“mean”,“sigma”);
fS->SetParameter(0,6000);
fS->SetParameter(1,6);
fS->SetParameter(2,0.14);
histo->Fit(fS,“R”);
histo->Draw(“”);
Double_t mean00=fS->GetParameter(1);
return mean00;
}
int cc()
{
FILE *out;
TString outputName = “Sd1r_adc.txt”;
out = fopen(outputName.Data(),“w”);
Double_t mean;
TFile *f = TFile::Open(“tree066330000.root”);
TTree Iris = (TTree)f->Get(“Iris”);
Char_t histo[50],selection[100];
TString histogram = “h1”;
sprintf(histo,“TSd1rADC>>h1(%d,%d,%d)”,60,900,1200); // binning should not be high nor less (60)
// std :: string cut = “.x elasag.C”; //S3cut May not be needed, can comment
// gROOT->ProcessLine(cut.data()); // related
TObjArray Hlist(0);
for(Int_t j=1;j<24; j++)
{
//sprintf(selection,“cut && TICEnergy>450 && TICEnergy<850 && TSd1sChannel==%d”,j); //For data
sprintf(selection,“TSd1rChannel==%d && TICEnergy>183 && TICEnergy<741”,j);
//for simIris // TICEnergy>280 && TICEnergy<700 // i have to put minimum and max values of TICEnergy depends on 3Sigma values after gaussian fitting
Iris->Draw(histo,selection,"");
TH1F *h2 = (TH1F*)gDirectory->Get(histogram.Data());
h2->Draw("");
mean=fitpeak (h2);
Hlist.Add(h2);
cout<<"mean = "<<mean<<" j "<<j<<endl;
//out<<"mean = "<<mean<<" j "<<j<<endl;
fprintf(out,"%d\t%f\n",j,mean);
}
TFile f2("demo.root","recreate");
Hlist.Write();
f2.Close();
fclose(out);
return 0;
}
In demo.root i am getting 24 histograms but all are same, it will be a great help if my demo.root file contains all different histograms after fitting
ROOT Version: 6.24/06
Platform:
Compiler: Not Provided