20 return Energy-Energy/(1+Energy/0.000511*(1-
TMath::Cos(Th)));
24 return TMath::ACos((Energy*Energy-Energy*Eprime-Eprime*0.000511)/(Energy*(Energy-Eprime)));
28 return par[0]+x[0] * par[1]+x[0] * x[0] * par[2]+ par[3] * 1/(
TMath::Sqrt(2 *
TMath::Pi()) * par[5]) * TMath::Exp(- pow((x[0] -par[4]),2)/2/par[5]/par[5]);
32 return par[1]*TMath::Poisson(x[0],par[0]);
39 Anapath.Remove(Anapath.Last(
'/'),Anapath.Length()-Anapath.Last(
'/'));
40 cout << Anapath << endl;
41 TString InputName =Filepath.Remove(0,Filepath.Last(
'/')+1);
43 if (InputName.Contains(
"TripleBall40Offset10STT"))
45 if (InputName.Contains(
"TripleBall40Offset20STT"))
47 if (InputName.Contains(
"SecTar"))
52 TFile *File =
new TFile(FileName.Data());
57 File->GetObject(
"gamTde;1",hGammaSpectrum);
58 File->GetObject(
"Number of Hits;1",hNoOfHits);
59 File->GetObject(
"ParameterBuffer;1",hParBuffer);
60 Double_t Energy = hParBuffer->GetBinContent(1)/NoOfJobs;
61 Int_t
nEvents = hParBuffer->GetBinContent(2)/NoOfJobs;
62 Int_t ChannelResolution = hParBuffer->GetBinContent(3)/NoOfJobs;
63 Double_t Resolution = hParBuffer->GetBinContent(4)/NoOfJobs;
64 cout << Energy <<
" " << nEvents <<
" " << ChannelResolution <<
" " << Resolution << endl;
67 txtfile.open(
"OutputCombinedAna.txt");
68 txtfile <<
"File analysed:\t" << InputName << endl;
69 txtfile<<
"Number of Simulated Events:\t"<<nEvents<<endl;
73 TCanvas*
can3 =
new TCanvas(
"can3",
"germanium detector",0,0,1000,1000);
74 hGammaSpectrum->Draw();
84 TSpectrum *
s =
new TSpectrum(npeaks);
85 s->Search(hGammaSpectrum,npeaks,
"new",0.01);
87 Float_t *xpeaks = s->GetPositionX();
88 Float_t *ypeaks = s->GetPositionY();
91 for (Int_t
i = 0;
i < npeaks; ++
i)
93 cout <<
"("<< xpeaks[
i]<<
"," << ypeaks[
i] <<
") ";
97 Double_t PeakX = xpeaks[PeakToLook-1]*ChannelResolution;
98 Double_t PeakY = ypeaks[PeakToLook-1];
102 for(Int_t
i = PeakX-Resolution*10*10/2.3548;
i <= PeakX+Resolution*10*10/2.3548;
i++)
103 SumPeak += hGammaSpectrum->GetBinContent(
i);
105 cout <<
"MaxX: "<< PeakX <<
"; MaxY: " << PeakY <<
" +- " << DPeakY<< endl;
106 cout <<
"SumPeak: " << SumPeak <<
" +- " << DSumPeak << endl;
107 txtfile <<
"MaxX: "<< PeakX <<
"; MaxY: " << PeakY <<
" +- " << DPeakY<< endl;
108 txtfile <<
"SumPeak: " << SumPeak <<
" +- " << DSumPeak << endl;
110 Double_t ComptonEdge = Int_t(PeakX*(1-1/(1+2*PeakX/5110)))+1;
111 cout <<
"ComptonEdge @ Bin: " << ComptonEdge << endl;
112 Double_t SumCompton=0, DSumCompton = 0;
115 for (Int_t
i =
Compton(Energy,lowAngle)*ChannelResolution;
i <=
Compton(Energy,highAngle)*ChannelResolution;
i++)
117 SumCompton += hGammaSpectrum->GetBinContent(
i);
119 DSumCompton =
sqrt(SumCompton);
121 cout <<
"lowEnChan: " <<
Compton(Energy,lowAngle)*ChannelResolution << endl <<
"highEnChan: "<<
Compton(Energy,highAngle)*ChannelResolution << endl;
122 txtfile <<
"lowEnChan: " <<
Compton(Energy,lowAngle)*ChannelResolution << endl <<
"highEnChan: "<<
Compton(Energy,highAngle)*ChannelResolution << endl;
123 cout <<
"N. of Compton Events: "<< SumCompton<<
" +- " << DSumCompton << endl;
124 txtfile <<
"N. of Compton Events: "<< SumCompton<<
" +- " << DSumCompton << endl;
129 PeakToCompton = PeakY/SumCompton*(
Compton(Energy,highAngle)-
Compton(Energy,lowAngle))*ChannelResolution;
130 DPeakToCompton =
sqrt(pow(DPeakY/SumCompton,2)+ pow(PeakY*DSumCompton/SumCompton/SumCompton,2))*(
Compton(Energy,highAngle)-
Compton(Energy,lowAngle))*ChannelResolution;
131 cout <<
"Peak/Compton (res): "<< PeakToCompton <<
" +- "<< DPeakToCompton << endl;
132 txtfile <<
"Peak/Compton (res):\t"<< PeakToCompton <<
" +- "<< DPeakToCompton << endl;
137 cout <<
"SumCompton = 0 -> no PeakToCompton possible!"<<endl;
138 txtfile <<
"SumCompton = 0 -> no PeakToCompton possible!"<<endl;
140 Double_t AllEntries = hGammaSpectrum->GetEntries();
141 cout <<
"Entries: " << AllEntries << endl;
142 txtfile <<
"Entries: " << AllEntries << endl;
147 TF1 *GausBG =
new TF1(
"GausBG",
"gausn",(PeakX-100)/ChannelResolution,(PeakX+100)/ChannelResolution);
148 GausBG->SetParName(0,
"Ampl");
149 GausBG->SetParName(1,
"x0");
150 GausBG->SetParName(2,
"sigma");
151 GausBG->SetParameter(0,PeakY/10000);
152 GausBG->SetParameter(1,PeakX/
Double_t(ChannelResolution));
153 GausBG->SetParameter(2,100./
Double_t(ChannelResolution));
154 GausBG->SetParLimits(0,0.0000001, 1000000);
155 GausBG->SetParLimits(1,(PeakX-10)/
Double_t(ChannelResolution),(PeakX+10)/
Double_t(ChannelResolution));
156 GausBG->SetParLimits(2,1./
Double_t(ChannelResolution),100./
Double_t(ChannelResolution));
164 GausBG->SetNpx(100000);
165 GausBG->SetLineColor(kRed);
166 hGammaSpectrum->Fit(GausBG,
"R");
168 txtfile <<
"Fitparameter Spectrum (model: gausn):" << endl;
169 for (Int_t
i = 0;
i < 3;
i++)
171 txtfile << GausBG->GetParName(
i) <<
":\t" << GausBG->GetParameter(
i) << endl;
173 Double_t FWHM = GausBG->GetParameter(2)*2.3548200;
174 txtfile <<
"FWHM[keV]:\t" << FWHM*1000000 << endl;
175 cout <<
"FWHM[keV]:\t" << FWHM*1000000 << endl;
196 Double_t FullEnergyPeakEff = double(
int(GausBG->GetParameter(0)*ChannelResolution/(nEvents*2)*100*1000))/1000;
197 Double_t FullEnergyPeakEffError = double(
int(GausBG->GetParError(0)*ChannelResolution/(nEvents*2)*100*1000))/1000;
199 cout <<
"Full-Energy-Peak-Eff. [%]: " << FullEnergyPeakEff << endl;;
200 txtfile <<
"Full-Energy-Peak-Eff. [%]:\t" << FullEnergyPeakEff << endl;
202 cout <<
"Error ofFull-Energy-Peak-Eff. [%]: " << FullEnergyPeakEffError<< endl;
203 txtfile <<
"Error of Full-Energy-Peak-Eff. [%]:\t" << FullEnergyPeakEffError << endl;
205 TFile *Output =
new TFile(
"OutputCombinedAna.root",
"RECREATE");
206 hGammaSpectrum->Write();
213 TString CollectFileName = Anapath +
"/CollectFEPF.txt";
214 ofstream CollectFile(CollectFileName,
ios::out|ios::app);
215 CollectFile << Geometry <<
"\t" << Sektar <<
"\t"<< Energy <<
"\t"<< nEvents <<
"\t" << FullEnergyPeakEff <<
"\t" << FullEnergyPeakEffError <<
"\t" <<FWHM*1000000 <<
"\t"<< PeakToCompton<<
"\t"<<InputName << endl;
219 cout <<
"macro finished successfully" << endl;
int AnalyseCombinedGammaFiles(TString Filepath, TString FileName, Int_t NoOfJobs=10)
friend F32vec4 sqrt(const F32vec4 &a)
static T Sqrt(const T &x)
Double_t invCompton(Double_t Energy, Double_t Eprime)
Double_t PeakFunc(Double_t *x, Double_t *par)
Double_t PoissonFunc(Double_t *x, Double_t *par)
Double_t Compton(Double_t Energy, Double_t Th)