41 gROOT->Macro(
"$VMCWORKDIR/gconfig/rootlogon.C");
43 gSystem->Load(
"libHyp");
44 gSystem->Load(
"libHypGe");
53 Int_t IndexPreEnergy = Filename.Index(
"_",1,0,TString::kExact);
54 Int_t IndexPostEnergy = Filename.Index(
"MeV",3,0,TString::kExact);
55 TString EnergyFromFileName = Filename(IndexPreEnergy+1,IndexPostEnergy-IndexPreEnergy-1);
57 Double_t Energy = EnergyFromFileName.Atof()/1000;
58 cout <<
"Gamma energy: " << Energy << endl;
62 if(Filename.EndsWith(
".root"))
64 Filename.ReplaceAll(
".root",
"");
65 cout <<
"Filename ending chopped!" << endl;
68 TFile*
g =
new TFile(CompleteFilename);
71 TString Path = getenv(
"SIMDATADIR");
76 txtfileName +=
".txt";
77 TFile*
fi =
new TFile(outfile,
"RECREATE");
83 txtfile.open(txtfileName);
84 txtfile <<
"File read:" << CompleteFilename << endl;
86 TTree *
b=(TTree *) g->Get(
"pndsim") ;
87 TClonesArray*
hit_bar=
new TClonesArray(
"PndHypGePoint");
88 b->SetBranchAddress(
"HypGePoint",&hit_bar);
89 TClonesArray*
mc_bar=
new TClonesArray(
"PndMCTrack");
90 b->SetBranchAddress(
"MCTrack",&mc_bar);
96 Double_t HistoUpperThreshold = Energy*1.2;
97 TString Name =
"total gam energy deposit, " + Filename;
98 TH1D*
gamTde =
new TH1D(
"gamTde",Name.Data(),10000000*HistoUpperThreshold,0.0000,HistoUpperThreshold);
104 TH1D *hNoHits =
new TH1D(
"Number of Hits",
"Number of Hits", 10,0,10);
112 set<int> SetOfCrystalHit;
113 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;
120 for (Int_t k=0; k<
nEvents; k++)
125 if (!((k*10)% nEvents))
130 for (Int_t
i=0;
i<hit_bar->GetEntriesFast();
i++)
136 Eng +=gRandom->Gaus(0,0.000001*Resolution/2.3548);
144 if (
TMath::Abs(Eng-Energy) < 10*0.000001*Resolution/2.3548)
152 hNoHits->Fill(SetOfCrystalHit.size());
161 SetOfCrystalHit.clear();
163 cout <<
"event loop finished"<< endl;
166 TCanvas*
can3 =
new TCanvas(
"can3",
"germanium detector",0,0,1000,1000);
175 Int_t PeakToLook = 1;
178 TSpectrum *
s =
new TSpectrum(npeaks);
179 s->Search(gamTde,npeaks,
"new",0.01);
181 Float_t *xpeaks = s->GetPositionX();
182 Float_t *ypeaks = s->GetPositionY();
185 for (Int_t
i = 0;
i < npeaks; ++
i)
187 cout <<
"("<< xpeaks[
i]<<
"," << ypeaks[
i] <<
") ";
191 Double_t PeakX = xpeaks[PeakToLook-1]*10000000;
192 Double_t PeakY = ypeaks[PeakToLook-1];
196 for(Int_t
i = PeakX-Resolution*10*10/2.3548;
i <= PeakX+Resolution*10*10/2.3548;
i++)
197 SumPeak += gamTde->GetBinContent(
i);
199 cout <<
"MaxX: "<< PeakX <<
"; MaxY: " << PeakY <<
" +- " << DPeakY<< endl;
200 cout <<
"SumPeak: " << SumPeak <<
" +- " << DSumPeak << endl;
201 txtfile <<
"MaxX: "<< PeakX <<
"; MaxY: " << PeakY <<
" +- " << DPeakY<< endl;
202 txtfile <<
"SumPeak: " << SumPeak <<
" +- " << DSumPeak << endl;
204 Double_t ComptonEdge = Int_t(PeakX*(1-1/(1+2*PeakX/5110)))+1;
205 cout <<
"ComptonEdge @ Bin: " << ComptonEdge << endl;
206 Double_t SumCompton=0, DSumCompton = 0;
209 for (Int_t
i =
Compton(E,lowAngle)*10000000;
i <=
Compton(E,highAngle)*10000000;
i++)
211 SumCompton += gamTde->GetBinContent(
i);
213 DSumCompton =
sqrt(SumCompton);
215 cout <<
"lowEnChan: " <<
Compton(E,lowAngle)*10000000 << endl <<
"highEnChan: "<<
Compton(E,highAngle)*10000000 << endl;
216 txtfile <<
"lowEnChan: " <<
Compton(E,lowAngle)*100000000 << endl <<
"highEnChan: "<<
Compton(E,highAngle)*10000000 << endl;
217 cout <<
"N. of Compton Events: "<< SumCompton<<
" +- " << DSumCompton << endl;
218 txtfile <<
"N. of Compton Events: "<< SumCompton<<
" +- " << DSumCompton << endl;
223 PeakToCompton = PeakY/SumCompton*(
Compton(E,highAngle)-
Compton(E,lowAngle))*10000000;
224 DPeakToCompton =
sqrt(pow(DPeakY/SumCompton,2)+ pow(PeakY*DSumCompton/SumCompton/SumCompton,2))*(
Compton(E,highAngle)-
Compton(E,lowAngle))*10000000;
225 cout <<
"Peak/Compton (res): "<< PeakToCompton <<
" +- "<< DPeakToCompton << endl;
226 txtfile <<
"Peak/Compton (res): "<< PeakToCompton <<
" +- "<< DPeakToCompton << endl;
231 cout <<
"SumCompton = 0 -> no PeakToCompton possible!"<<endl;
232 txtfile <<
"SumCompton = 0 -> no PeakToCompton possible!"<<endl;
234 Double_t AllEntries = gamTde->GetEntries();
235 cout <<
"Entries: " << AllEntries << endl;
236 txtfile <<
"Entries: " << AllEntries << endl;
241 TF1 *GausBG =
new TF1(
"GausBG",
"gausn",(PeakX-100)/10000000,(PeakX+100)/10000000);
242 GausBG->SetParName(0,
"Ampl");
243 GausBG->SetParName(1,
"x0");
244 GausBG->SetParName(2,
"sigma");
245 GausBG->SetParameter(0,PeakY/10000);
246 GausBG->SetParameter(1,PeakX/10000000.);
247 GausBG->SetParameter(2,100./10000000.);
248 GausBG->SetParLimits(0,0.0000001, 1000000);
249 GausBG->SetParLimits(1,(PeakX-10)/10000000.,(PeakX+10)/10000000.);
250 GausBG->SetParLimits(2,1./10000000.,100./10000000.);
258 GausBG->SetNpx(100000);
259 GausBG->SetLineColor(kRed);
260 gamTde->Fit(GausBG,
"R");
262 txtfile <<
"Fitparameter Spectrum (model: gausn):" << endl;
263 for (Int_t
i = 0;
i < 3;
i++)
265 txtfile << GausBG->GetParName(
i) <<
":\t" << GausBG->GetParameter(
i) << endl;
267 Double_t FWHM = GausBG->GetParameter(2)*2.3548200;
268 txtfile <<
"FWHM[keV]:\t" << FWHM*1000000 << endl;
269 cout <<
"FWHM[keV]:\t" << FWHM*1000000 << endl;
271 TF1 *Poisson =
new TF1(
"Poisson",
"gausn",0,15);
275 Poisson->SetParName(0,
"Ampl");
276 Poisson->SetParName(1,
"x0");
277 Poisson->SetParName(2,
"sigma");
279 Poisson->SetNpx(100000);
280 Poisson->SetLineColor(kRed);
290 gamTde->SetXTitle(
"Energy [GeV]");
291 gamTde->SetYTitle(
"Counts");
292 gamTde->GetYaxis()->SetTitleOffset(1.35);
293 hNoHits->SetXTitle(
"Number of Hits");
294 hNoHits->SetYTitle(
"Counts");
295 hNoHits->GetYaxis()->SetTitleOffset(1.1);
297 cout <<
"Full-Energy-Peak-Eff. [%]: " << double(
int(GausBG->GetParameter(0)*10000000/(nEvents*2)*100*1000))/1000 << endl;
298 txtfile <<
"Full-Energy-Peak-Eff. [%]: " << double(
int(GausBG->GetParameter(0)*10000000/(nEvents*2)*100*1000))/1000 << endl;
300 cout <<
"Error ofFull-Energy-Peak-Eff. [%]: " << double(
int(GausBG->GetParError(0)*10000000/(nEvents*2)*100*1000))/1000 << endl;
301 txtfile <<
"Error of Full-Energy-Peak-Eff. [%]: " << double(
int(GausBG->GetParError(0)*10000000/(nEvents*2)*100*1000))/1000 << endl;
316 cout << endl << endl;
317 cout <<
"Macro finished succesfully." << endl;
318 cout <<
"Output file is " << outfile << endl;
319 cout <<
"Parameter file is " << txtfileName << endl;
320 cout <<
"Real time " << rtime <<
" s, CPU time " << ctime <<
" s" << endl;
friend F32vec4 sqrt(const F32vec4 &a)
TString CompleteFilename(TString mu, TString Q, TString Psf)
Double_t Compton(Double_t E, Double_t Th)
Double_t invCompton(Double_t E, Double_t Eprime)
Int_t GetDetectorID() const
Double_t GetEnergyLoss() const