7 return Energy-Energy/(1+Energy/0.000511*(1-
TMath::Cos(Th)));
11 return TMath::ACos((Energy*Energy-Energy*Eprime-Eprime*0.000511)/(Energy*(Energy-Eprime)));
16 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]);
21 return par[1]*TMath::Poisson(x[0],par[0]);
32 gSystem->Load(
"libHypGe");
41 Int_t IndexPreEnergy = Filename.Index(
"E",1,4,0);
42 Int_t IndexPostEnergy = Filename.Index(
"MeV",3,4,0);
43 TString EnergyFromFileName = Filename(IndexPreEnergy+1,IndexPostEnergy-IndexPreEnergy-1);
45 Double_t Energy = EnergyFromFileName.Atof();
52 if(Filename.EndsWith(
".root",1))
54 Filename.ReplaceAll(
".root",
"");
55 cout <<
"Filename ending chopped!" << endl;
58 TFile*
g =
new TFile(CompleteFilename);
61 Filename.ReplaceAll(
"Sim",
"Ana");
62 SubFolder.ReplaceAll(
"Sim",
"Ana");
63 TString Path = getenv(
"SIMDATADIR");
65 char CommandBuffer[400];
66 sprintf(CommandBuffer,
".!mkdir -p %s",outfile.Data());
67 cout <<
"Processing " << CommandBuffer<< endl;
68 gROOT->ProcessLine(CommandBuffer);
73 txtfileName +=
".txt";
74 TFile*
fi =
new TFile(outfile,
"RECREATE");
80 txtfile.open(txtfileName);
81 txtfile <<
"File read:" << CompleteFilename << endl;
85 TTree *
b=(TTree *) g->Get(
"pndsim") ;
86 TClonesArray*
hit_bar=
new TClonesArray(
"PndHypGePoint");
87 b->SetBranchAddress(
"HypGePoint",&hit_bar);
88 TClonesArray*
mc_bar=
new TClonesArray(
"PndMCTrack");
89 b->SetBranchAddress(
"MCTrack",&mc_bar);
95 Double_t HistoUpperThreshold = Energy*1.2;
96 string Name =
"total gam energy deposit, " + Filename;
97 Int_t ChannelResolution = 10000000;
98 TH1D*
gamTde =
new TH1D(
"gamTde",Name.c_str(),ChannelResolution*HistoUpperThreshold,0.0000,HistoUpperThreshold);
104 TH1D *hNoHits =
new TH1D(
"Number of Hits",
"Number of Hits", 10,0,10);
112 std::set<int> SetOfCrystalHit;
113 std::set<int>::iterator it;
115 Int_t
nEvents = b->GetEntriesFast();
116 cout<<
"Number of Simulated Events: "<<nEvents<<endl;
117 txtfile<<
"Number of Simulated Events: "<<nEvents<<endl;
122 for (Int_t k=0; k<
nEvents; k++)
128 if (!((k*10)% nEvents))
133 for (Int_t
i=0;
i<hit_bar->GetEntriesFast();
i++)
140 Eng += gRandom->Gaus(0,0.000001*Resolution/2.3548);
151 if (
TMath::Abs(Eng-Energy) < 10*0.000001*Resolution/2.3548)
159 hNoHits->Fill(SetOfCrystalHit.size());
168 SetOfCrystalHit.clear();
174 TCanvas*
can3 =
new TCanvas(
"can3",
"germanium detector",0,0,1000,1000);
183 Int_t PeakToLook = 1;
185 TSpectrum *
s =
new TSpectrum(npeaks);
186 s->Search(gamTde,npeaks,
"new",0.01);
188 Float_t *xpeaks = s->GetPositionX();
189 Float_t *ypeaks = s->GetPositionY();
192 for (Int_t
i = 0;
i < npeaks; ++
i)
194 cout <<
"("<< xpeaks[
i]<<
"," << ypeaks[
i] <<
") ";
198 Double_t PeakX = xpeaks[PeakToLook-1]*ChannelResolution;
199 Double_t PeakY = ypeaks[PeakToLook-1];
203 for(Int_t
i = PeakX-Resolution*10*10/2.3548;
i <= PeakX+Resolution*10*10/2.3548;
i++)
204 SumPeak += gamTde->GetBinContent(
i);
206 cout <<
"MaxX: "<< PeakX <<
"; MaxY: " << PeakY <<
" +- " << DPeakY<< endl;
207 cout <<
"SumPeak: " << SumPeak <<
" +- " << DSumPeak << endl;
208 txtfile <<
"MaxX: "<< PeakX <<
"; MaxY: " << PeakY <<
" +- " << DPeakY<< endl;
209 txtfile <<
"SumPeak: " << SumPeak <<
" +- " << DSumPeak << endl;
211 Double_t ComptonEdge = Int_t(PeakX*(1-1/(1+2*PeakX/5110)))+1;
212 cout <<
"ComptonEdge @ Bin: " << ComptonEdge << endl;
213 Double_t SumCompton=0, DSumCompton = 0;
216 for (Int_t
i =
Compton(Energy,lowAngle)*ChannelResolution;
i <=
Compton(Energy,highAngle)*ChannelResolution;
i++)
218 SumCompton += gamTde->GetBinContent(
i);
220 DSumCompton =
sqrt(SumCompton);
222 cout <<
"lowEnChan: " <<
Compton(Energy,lowAngle)*ChannelResolution << endl <<
"highEnChan: "<<
Compton(Energy,highAngle)*ChannelResolution << endl;
223 txtfile <<
"lowEnChan: " <<
Compton(Energy,lowAngle)*ChannelResolution << endl <<
"highEnChan: "<<
Compton(Energy,highAngle)*ChannelResolution << endl;
224 cout <<
"N. of Compton Events: "<< SumCompton<<
" +- " << DSumCompton << endl;
225 txtfile <<
"N. of Compton Events: "<< SumCompton<<
" +- " << DSumCompton << endl;
230 PeakToCompton = PeakY/SumCompton*(
Compton(Energy,highAngle)-
Compton(Energy,lowAngle))*ChannelResolution;
231 DPeakToCompton =
sqrt(pow(DPeakY/SumCompton,2)+ pow(PeakY*DSumCompton/SumCompton/SumCompton,2))*(
Compton(Energy,highAngle)-
Compton(Energy,lowAngle))*ChannelResolution;
232 cout <<
"Peak/Compton (res): "<< PeakToCompton <<
" +- "<< DPeakToCompton << endl;
233 txtfile <<
"Peak/Compton (res): "<< PeakToCompton <<
" +- "<< DPeakToCompton << endl;
238 cout <<
"SumCompton = 0 -> no PeakToCompton possible!"<<endl;
239 txtfile <<
"SumCompton = 0 -> no PeakToCompton possible!"<<endl;
241 Double_t AllEntries = gamTde->GetEntries();
242 cout <<
"Entries: " << AllEntries << endl;
243 txtfile <<
"Entries: " << AllEntries << endl;
248 TF1 *GausBG =
new TF1(
"GausBG",
"gausn",(PeakX-100)/ChannelResolution,(PeakX+100)/ChannelResolution);
249 GausBG->SetParName(0,
"Ampl");
250 GausBG->SetParName(1,
"x0");
251 GausBG->SetParName(2,
"sigma");
252 GausBG->SetParameter(0,PeakY/10000);
253 GausBG->SetParameter(1,PeakX/
Double_t(ChannelResolution));
254 GausBG->SetParameter(2,100./
Double_t(ChannelResolution));
255 GausBG->SetParLimits(0,0.0000001, 1000000);
256 GausBG->SetParLimits(1,(PeakX-10)/
Double_t(ChannelResolution),(PeakX+10)/
Double_t(ChannelResolution));
257 GausBG->SetParLimits(2,1./
Double_t(ChannelResolution),100./
Double_t(ChannelResolution));
265 GausBG->SetNpx(100000);
266 GausBG->SetLineColor(kRed);
267 gamTde->Fit(GausBG,
"R");
269 txtfile <<
"Fitparameter Spectrum (model: gausn):" << endl;
270 for (Int_t
i = 0;
i < 3;
i++)
272 txtfile << GausBG->GetParName(
i) <<
":\t" << GausBG->GetParameter(
i) << endl;
274 Double_t FWHM = GausBG->GetParameter(2)*2.3548200;
275 txtfile <<
"FWHM[keV]:\t" << FWHM*1000000 << endl;
276 cout <<
"FWHM[keV]:\t" << FWHM*1000000 << endl;
278 TF1 *Poisson =
new TF1(
"Poisson",
"gausn",0,15);
282 Poisson->SetParName(0,
"Ampl");
283 Poisson->SetParName(1,
"x0");
284 Poisson->SetParName(2,
"sigma");
286 Poisson->SetNpx(100000);
287 Poisson->SetLineColor(kRed);
297 gamTde->SetXTitle(
"Energy [GeV]");
298 gamTde->SetYTitle(
"Counts");
299 gamTde->GetYaxis()->SetTitleOffset(1.35);
300 hNoHits->SetXTitle(
"Number of Hits");
301 hNoHits->SetYTitle(
"Counts");
302 hNoHits->GetYaxis()->SetTitleOffset(1.1);
304 cout <<
"Full-Energy-Peak-Eff. [%]: " << double(
int(GausBG->GetParameter(0)*ChannelResolution/(nEvents*2)*100*1000))/1000 << endl;
305 txtfile <<
"Full-Energy-Peak-Eff. [%]: " << double(
int(GausBG->GetParameter(0)*ChannelResolution/(nEvents*2)*100*1000))/1000 << endl;
307 cout <<
"Error ofFull-Energy-Peak-Eff. [%]: " << double(
int(GausBG->GetParError(0)*ChannelResolution/(nEvents*2)*100*1000))/1000 << endl;
308 txtfile <<
"Error of Full-Energy-Peak-Eff. [%]: " << double(
int(GausBG->GetParError(0)*ChannelResolution/(nEvents*2)*100*1000))/1000 << endl;
345 cout << endl << endl;
346 cout <<
"Macro finished succesfully." << endl;
347 cout <<
"Output file is " << outfile << endl;
348 cout <<
"Parameter file is " << txtfileName << endl;
349 cout <<
"Real time " << rtime <<
" s, CPU time " << ctime <<
" s" << endl;
friend F32vec4 sqrt(const F32vec4 &a)
static T Sqrt(const T &x)
int GammaSpectraAnalysis_NoH(TString Filename="Sim_Geo36_E0.500MeV_Evts10000000_FileEvts20000_Gen1_ST0__1.root", TString SubFolder="Sim_Geo36_E0.500MeV_Evts10000000_FileEvts20000_Gen1_ST0")
Double_t Compton(Double_t Energy, Double_t Th)
TString CompleteFilename(TString mu, TString Q, TString Psf)
Double_t invCompton(Double_t Energy, Double_t Eprime)
Int_t GetDetectorID() const
Double_t GetEnergyLoss() const
Double_t PeakFunc(Double_t *x, Double_t *par)
Double_t PoissonFunc(Double_t *x, Double_t *par)