FairRoot/PandaRoot
PndHypGeGammaAna.cxx
Go to the documentation of this file.
1 /******************************************************
2 
3 Analysis Task created by M.Steinen steinen@kph.uni-mainz.de
4 Analysis of Gamma Simulation with hypGe detectors
5 *******************************************************/
6 
7 
8 #include "PndHypGeGammaAna.h"
9 #include <iostream>
10 #include <TMath.h>
11 #include "FairRunAna.h"
12 #include "FairRuntimeDb.h"
13 #include <time.h>
14 #include <TCanvas.h>
15 #include <TSpectrum.h>
16 
17 //#include "RhoBase/TFactory.h"
18 
19 
20 using namespace std;
21 
22 
24  : FairTask("Panda HypGeGammaAna Task"), xpeaks(0), ypeaks(0), fHitGe(0), fMCGam(0), fHitSi(0), fHitTargetOther(0)
25 {
28 
29 }
30 PndHypGeGammaAna::PndHypGeGammaAna(TString TxtFileName_Ext,Double_t GammaEnergy_Ext,Int_t nEvents, Int_t nPeaks_Ext,Int_t PeakToLook_Ext)
31  : FairTask("Panda HypGeGammaAna Task"), xpeaks(0), ypeaks(0), fHitGe(0), fMCGam(0), fHitSi(0), fHitTargetOther(0)
32 {
33  TxtFileName=TxtFileName_Ext;
34  GammaEnergy=GammaEnergy_Ext;
36  nPeaks= nPeaks_Ext;
37  PeakToLook = PeakToLook_Ext;
42 }
43 
45 {
46  //delete fStorage;
47  delete hGamEnergy;
48  delete hNumberOfHits;
49  delete hAbsorption;
50  delete Rng;
51  delete xpeaks;
52  delete ypeaks;
53  delete fHitGe;
54  delete fMCGam;
55  delete fHitSi;
56  delete fHitTargetOther;
57 
58  if (fMcTr)
59  {
60  fMcTr->Delete();
61  delete fMcTr;
62  }
63  if (fMc)
64  {
65  fMc->Delete();
66  delete fMc;
67  }
68  if (fGe)
69  {
70  fGe->Delete();
71  delete fGe;
72  }
73  if (fGeAl)
74  {
75  fGeAl->Delete();
76  delete fGeAl;
77  }
78  if (fSilicon)
79  {
80  fSilicon->Delete();
81  delete fSilicon;
82  }
83  if (fTargetOther)
84  {
85  fTargetOther->Delete();
86  delete fTargetOther;
87  }
88 }
89 
90 
92 {
93  cout << "Hyp Ge Gamma Ana:\t" << "Starting Init of HypGe Gamma Ana" << endl;
94 
95  //----------get FairRootManager-------------------------------------
96  ioman = FairRootManager::Instance();
97  if ( ! ioman ) {
98  cout << "-E- PndEmcHitProducer::Init: "
99  << "RootManager not instantiated!" << endl;
100  return kFATAL;
101  }
102 
103  if (fVerbose == 3)
104  cout << "Hyp Ge Gamma Ana:\t" << "Getting FairRootManager finished" << endl;
105 
106  //----------get input arrays---------------------------------------------
107  fMcTr = (TClonesArray*) ioman->GetObject("MCTrack");
108  fGe = (TClonesArray*) ioman->GetObject("HypGePoint");
109  fGeAl = (TClonesArray*) ioman->GetObject("HypGeAlPoint");
110  fSilicon = (TClonesArray*) ioman->GetObject("HypPoint");
111  fTargetOther = (TClonesArray*) ioman->GetObject("HypSTMatBudPoint");
112 
113 
114 
115  if (fVerbose ==3)
116  cout << "Hyp Ge Gamma Ana:\t" << "Getting input arrays finished" << endl;
117 
118  //-----------extracting file name--------------------------------------
119  fName = ioman->GetInFile()->GetName();
120  if (fVerbose == 3)
121  {
122  cout << "Hyp Ge Gamma Ana:\t" << "Full input file name with path: " << fName << endl;
123  cout << "Hyp Ge Gamma Ana:\t" << "Chopping first " << fName.Last('/')+1 << " chars"<< endl;
124  }
125  fName.Remove(0,fName.Last('/')+1);
126  if (fVerbose == 3)
127  cout << "Hyp Ge Gamma Ana:\t" << "File name: " <<fName<< endl;
128 
129  if (fVerbose == 3)
130  cout << "Hyp Ge Gamma Ana:\t" << "File name extraction finished" << endl;
131 
132  //----------create histograms------------------------------------------
134  {
135  iHistoUpperLimit = 0.6;
136  }
137  else
138  {
140  }
141  hGamEnergy = new TH1D("GamEnergy","Total gamma energy deposit, " + fName, 10000*iHistoUpperLimit,0.0,iHistoUpperLimit);
142  hGamEnergyTargetBackground = new TH1D("hGamEnergyTargetBackground","gamma background due to reactions in target, " + fName, 10000*iHistoUpperLimit,0.0,iHistoUpperLimit);
143  hNumberOfHits= new TH1D("NumberOfHits", "Number of Hits, " + fName, 16,0,15);
144  hThetaCheck= new TH1D("hThetaCheck", "Theta Check, " + fName, 90,90,180);
145  hThetaCheckPrimary= new TH1D("hThetaCheckPrimary", "Theta Check only primaries, " + fName, 90,90,180);
146 
147  hAbsorption = new TH1D("hAbsorption", "Part of Gamma interaction in target system," + fName, 10,1,11);
148  hAbsorption ->GetXaxis()->SetBinLabel(1,"Silicon"); // gamma interaction in si detectors
149  hAbsorption ->GetXaxis()->SetBinLabel(2,"Absorber"); // gamma interaction in absorber
150  hAbsorption ->GetXaxis()->SetBinLabel(3,"HoldingFrame"); // gamma interaction in holding frame
151  hAbsorption ->GetXaxis()->SetBinLabel(4,"Window foil"); // gamma interaction in window foil
152  hAbsorption ->GetXaxis()->SetBinLabel(5,"beam pipe"); // gamma interaction in beam pipe
153  hAbsorption ->GetXaxis()->SetBinLabel(6,"Other"); // gamma interaction in other parts
154  h2AbsorptionDistanceAngle = new TH2D("h2AbsorptionDistanceAngle","Correlation of absorption distance and angle," + fName,45,90,180, 100,0,50);
155 
156  if (fVerbose == 3)
157  cout << "Hyp Ge Gamma Ana:\t" << "Histogram creation finished" << endl;
158 
159  //----------set detector resolution---------------------------------------------
160  //TO DO: more realistic resolution (smearing) modell M.Steinen
161  ResConstPar =1.40872e-07;
162  ResGradientPar = 4.16193e-07 ;
164  //----------initialize EvtCount----------------------------------------
165  EvtCount = 0;
166 
167  //----------initialize Compton angles-----------------------
169  {
170  lowComptonAngle = invCompton(0.001332,0.001040);
171  highComptonAngle = invCompton(0.001332,0.001096);
172  }
173 
174  //----------Get number of events from FairRootManager-----------------------
175 
176  if (NumberOfEvents== 0)
177  NumberOfEvents= ioman->GetInChain()->GetEntries();
178  cout << "Hyp Ge Gamma Ana:\tNumber of analyzed events: "<< NumberOfEvents << endl;
179 
180  //----------initialize random generator------------------------------------
181  Rng = new TRandom(time(NULL));
182  cout << "Hyp Ge Gamma Ana:\t" << "Init of HypGe Gamma Ana finished successfully" << endl;
183 
184  //----------create storage in root file------------------------------------
185  //fStorage = new PndHypGeGammaAnaStorage("AnaData","Analysis Data");
186  // fStorage-> SetAllEntries(NumberOfEvents);
187  //fStorage-> SetInFile((ioman->GetInFile()->GetName()).Data()); // this line doen't work!!!!! why?!?!?!?!?!??!?!
188  //----------open txt outputfile--------------------------------------------
189 
190  TxtFile.open(TxtFileName);
191  TxtFile << "Hyp Ge Gamma Ana:\tFile to analyze: \t"<< ioman->GetInFile()->GetName() << endl;
192  TxtFile << "Hyp Ge Gamma Ana:\tNumber of analyzed events: \t"<< NumberOfEvents << endl;
193 
194 
195  std::cout << "-I- gGeoManager = "<<gGeoManager << std::endl;
196  return kSUCCESS;
197 }
198 
200 {
201  // Get Base Container
202  FairRun* ana = FairRun::Instance();
203  FairRuntimeDb* rtdb=ana->GetRuntimeDb();
204  std::cout << "-I- rtdb = "<<rtdb << std::endl;
205 
206 }
207 
208 void PndHypGeGammaAna::Exec(Option_t*)
209 {
210  Double_t EnergyPerCrystal[48] = {0};
211  Double_t CollectedEnergy = 0;
212  SetOfCrystalHit.clear();
213  bool isFirstInteraction = 0;
214  if (fTargetAvailable)
215  {
216  if( fSilicon->GetEntriesFast() || fTargetOther->GetEntriesFast())
217  {
218  bool isEndl = 0;
219  fMCGamPrimary = (PndMCTrack*)fMcTr->At(0);
220  TVector3 PrimaryVertex = fMCGamPrimary->GetStartVertex();
221  TVector3 PrimaryMomentum = fMCGamPrimary->GetMomentum();
222  Double_t PrimaryDistance;
223  Double_t PrimaryTheta;
224 // if (fSilicon->GetEntriesFast())
225 // {
226 // fHitSi = (PndHypPoint*)fSilicon->At(0);
227 // fMCGam = (PndMCTrack*)fMcTr->At(fHitSi->GetTrackID());
228 // if (fHitSi->GetTrackID() == 1 && fMCGam->GetMotherID() <1)
229 // {
230 // isFirstInteraction = 1;
231 // //cout << "TrPIDSi\t\t" << fMCGam->GetPdgCode()<<"\t\t";
232 // isEndl = 1;
233 // fStartVertex = fMCGam->GetStartVertex();
234 // PrimaryDistance = (fStartVertex - PrimaryVertex).Mag();
235 // PrimaryTheta = PrimaryMomentum.Theta()*180/TMath::Pi();
236 // fVertexVolumeName = fHitSi->GetDetName();//=gGeoManager->FindNode(fStartVertex.X(),fStartVertex.Y(),fStartVertex.Z())->GetName();
237 // if(PrimaryTheta >110 && PrimaryTheta <165) // range of germaniums
238 // hAbsorption->Fill(1);
239 // }
240 // }
241  if (fTargetOther->GetEntriesFast())
242  {
244  fMCGam = (PndMCTrack*)fMcTr->At(fHitTargetOther->GetTrackID());
245  if (fHitTargetOther->GetTrackID() == 1 && fMCGam->GetMotherID() < 1 )
246  {
247  //isFirstInteraction = 1;
248  //cout << "TrPIDOt\t\t" << fMCGam->GetPdgCode()<<"\t\t";
249  isEndl = 1;
252  TVector3 InDiffVector =fStartVertex - InVector;
253  TVector3 DiffVector =fStartVertex - PrimaryVertex;
254  PrimaryDistance = DiffVector.Mag();
255  PrimaryTheta = DiffVector.Theta()*180/TMath::Pi();
256  fVertexVolumeName = fHitTargetOther->GetDetName();//=gGeoManager->FindNode(fStartVertex.X(),fStartVertex.Y(),fStartVertex.Z())->GetName();
257  TString StartVolumeName =gGeoManager->FindNode(fStartVertex.X(),fStartVertex.Y(),fStartVertex.Z())->GetName();
258  if(PrimaryTheta >110 && PrimaryTheta <165 && (StartVolumeName.Contains("Sensor") ||StartVolumeName.Contains("Absorber") ||StartVolumeName.Contains("HoldingFrame") ||StartVolumeName.Contains("Window") ||StartVolumeName.Contains("Frame"))) // range of germaniums
259  {
260  isFirstInteraction = 1;
261  if (PrimaryDistance >10)
262  {
263  cout << PrimaryDistance << endl;
264  cout << PrimaryTheta << endl;
265 
266  cout << fVertexVolumeName.Data() << endl;
267  cout << StartVolumeName.Data() << endl;
268  fStartVertex.Print();
269  PrimaryVertex.Print();
270  DiffVector.Print();
271  //InDiffVector.Print();
272  cout << fHitTargetOther->GetLength() << endl;
273  }
274  if (fVertexVolumeName.Contains("Sensor"))
275  {
276  hAbsorption->Fill(1);
277  }
278  else
279  {
280  if (fVertexVolumeName.Contains("Absorber"))
281  {
282  hAbsorption->Fill(2);
283  //cout << fVertexVolumeName.Data()<< endl;
284  }
285  else
286  {
287  if (fVertexVolumeName.Contains("HoldingFrame"))
288  hAbsorption->Fill(3);
289  else
290  {
291  if (fVertexVolumeName.Contains("Window"))
292  hAbsorption->Fill(4);
293  else
294  {
295  if (fVertexVolumeName.Contains("Frame"))
296  hAbsorption->Fill(5);
297  else
298  {
299  hAbsorption->Fill(6);
300  cout << fVertexVolumeName.Data()<< endl;
301  fStartVertex.Print();
302  }
303  }
304  }
305  }
306  }
307  }
308  }
309  } // end of if (fTargetOther->GetEntriesFast())
310  if(isFirstInteraction)
311  {
312  if(PrimaryTheta >110 && PrimaryTheta <165)
313  h2AbsorptionDistanceAngle->Fill(PrimaryTheta,PrimaryDistance);
314  }
315  //if (isEndl)
316  //cout << endl;
317  } // end of if( fSilicon->GetEntriesFast() || fTargetOther->GetEntriesFast())
318  } // end of if (fTargetAvailable)
319  // loop over hits and save energy loss per crystal and crystals hit
320 
321  // theta angle of gammas hiting the germanium
322  fMCGam = (PndMCTrack*)fMcTr->At(0);
323  TVector3 GammaMomentum = fMCGam->GetMomentum();
324  //bool ishThetaCheckPrimaryFilled=0;
325  if (fGe->GetEntriesFast())
326  {
327  hThetaCheck->Fill(GammaMomentum.Theta()*180/TMath::Pi());
328  if (fTargetAvailable)
329  {
330  if (!(fSilicon->GetEntriesFast() || fTargetOther->GetEntriesFast()))
331  hThetaCheckPrimary->Fill(GammaMomentum.Theta()*180/TMath::Pi());
332  }
333  else
334  {
335  hThetaCheckPrimary->Fill(GammaMomentum.Theta()*180/TMath::Pi());
336  //ishThetaCheckPrimaryFilled=1;
337  }
338  }
339  //if (!ishThetaCheckPrimaryFilled && fGe->GetEntriesFast()&& fTargetAvailable && !(fSilicon->GetEntriesFast() || fTargetOther->GetEntriesFast()))
340  //{
341  //hThetaCheck->Fill(GammaMomentum.Theta()*180/TMath::Pi());
342  //if (GammaMomentum.Theta()*180/TMath::Pi() > 170)
343  //{
344  //cout << GammaMomentum.Theta()*180/TMath::Pi() << endl;
345  //cout << fMCGam->GetMotherID() << endl;
346  //}
347  //}
348  // gamma energy part
349  for (Int_t i=0; i < fGe->GetEntriesFast(); i++)
350  {
351  fHitGe=(PndHypGePoint*)fGe->At(i);
353  if (fHitGe->GetEnergyLoss() !=0)
354  {
355  EnergyPerCrystal[fHitGe->GetDetectorID() % 100] += fHitGe->GetEnergyLoss()*1000; // in MeV
356  SetOfCrystalHit.insert(fHitGe->GetDetectorID() % 100);
357  }
358  }
359 
360  // add up the whole collected energy by all crystals, smear every crystal seperatly
361  for (std::set<int>::iterator it=SetOfCrystalHit.begin(); it!=SetOfCrystalHit.end(); ++it)
362  {
363  CollectedEnergy += SmearHit(EnergyPerCrystal[*it]);
364  }
365  // fill histogram if there is any collected Energy
366  if (CollectedEnergy > 0)
367  {
368  hGamEnergy->Fill(CollectedEnergy);
369  if (fTargetAvailable)
370  {
371  if (fSilicon->GetEntriesFast() || fTargetOther->GetEntriesFast())
372  hGamEnergyTargetBackground->Fill(CollectedEnergy);
373  }
374  if (fVerbose >= 2 && CollectedEnergy != 0)
375  cout << "Hyp Ge Gamma Ana:\t" << "Energy " << CollectedEnergy << endl;
376  }
377  // fill number of hits histo when full gamma energy is collected, NoH = size of the set
378  if (TMath::Abs(CollectedEnergy-GammaEnergy) < 10*PeakWidth) //Peak = 10 * PeakWidth of 1 crystal --> takes multiple hits into account (faster than fitting and than doing it again, error is small)
379  {
380  hNumberOfHits->Fill(SetOfCrystalHit.size()); //Fill # of Hits -diagramm
381  if (fVerbose >= 2)
382  cout << "Hyp Ge Gamma Ana:\t" << "NoHFill: " << SetOfCrystalHit.size() << endl;
383  }
384  // show progress every 10 % of events
385  if (!((EvtCount++*10) % NumberOfEvents))
386  {
387  if (EvtCount == 1)
388  cout << "Hyp Ge Gamma Ana:\t"<<"0 % done!" << endl;
389  else
390  cout << "Hyp Ge Gamma Ana:\t" << 100 * Double_t(EvtCount-1)/NumberOfEvents << " % done!" << endl;
391  }
392  if (fVerbose == 3)
393  cout << "Hyp Ge Gamma Ana:\t" << "Event Number"<< EvtCount << endl;
394 }
395 
397 {
398  //-------------Analysis of the spectrum-------------------------------------
399  cout << "Hyp Ge Gamma Ana:\tEvent loop finished" <<endl;
400  //print number of entries in spectrum
401  if (fVerbose >= 2)
402  cout << "Hyp Ge Gamma Ana:\tEntries in spectrum: " << hGamEnergy->GetEntries() <<endl;
403  TxtFile << "Hyp Ge Gamma Ana:\tEntries in spectrum: \t" << hGamEnergy->GetEntries() <<endl;
404 
405 
406  //FindPeaks();
407 
408  //if (DoComptonCalculations)
409  // CalculateCompton();
410 
411 
412  //FitSpectrum();
413  //GetPeakContent();
414  //FittingOutput();
415  //--------------make up for the histograms----------------------------------
416 
418 
419  TxtFile.close();
420  cout << "Hyp Ge Gamma Ana:\tAnalysis finished succesfully" << endl;
421 }
422 
423 
425 {
426 return E-E/(1+E/0.000511*(1-TMath::Cos(Th)));
427 }
429 {
430 return TMath::ACos((E*E-E*Eprime-Eprime*0.000511)/(E*(E-Eprime)));
431 }
432 
434 {
435  Double_t Resolution = CalculatePeakWidth(Energy);
436  Double_t SmearedEnergy = Energy +Rng->Gaus(0,Resolution);
437  return SmearedEnergy;
438 }
439 
441 {
443 }
444 
445 void PndHypGeGammaAna::HistogramCosmetics(TH1D* histo, TString XTitle, Double_t XTitleSize, Double_t XTitleOffset, Double_t XLabelSize, TString YTitle, Double_t YTitleSize, Double_t YTitleOffset, Double_t YLabelSize)
446 {
447  histo->SetXTitle(XTitle.Data());
448  histo->GetXaxis()->SetTitleSize(XTitleSize);
449  histo->GetXaxis()->SetTitleOffset(XTitleOffset);
450  histo->GetXaxis()->SetLabelSize(XLabelSize);
451 
452  histo->SetYTitle(YTitle.Data());
453  histo->GetYaxis()->SetTitleSize(YTitleSize);
454  histo->GetYaxis()->SetTitleOffset(YTitleOffset);
455  histo->GetYaxis()->SetLabelSize(YLabelSize);
456 }
457 void PndHypGeGammaAna::HistogramCosmetics2D(TH2D* histo, TString XTitle, Double_t XTitleSize, Double_t XTitleOffset, Double_t XLabelSize, TString YTitle, Double_t YTitleSize, Double_t YTitleOffset, Double_t YLabelSize)
458 {
459  histo->SetXTitle(XTitle.Data());
460  histo->GetXaxis()->SetTitleSize(XTitleSize);
461  histo->GetXaxis()->SetTitleOffset(XTitleOffset);
462  histo->GetXaxis()->SetLabelSize(XLabelSize);
463 
464  histo->SetYTitle(YTitle.Data());
465  histo->GetYaxis()->SetTitleSize(YTitleSize);
466  histo->GetYaxis()->SetTitleOffset(YTitleOffset);
467  histo->GetYaxis()->SetLabelSize(YLabelSize);
468 }
470 {
471  //fitting the spectrum modell is not good!!!! M.Steinen
472  GausBG = new TF1("GausBG","gausn",(PeakX-1000)/100000,(PeakX+1000)/100000);
473  GausBG->SetParName(0,"Ampl");
474  GausBG->SetParName(1,"x0");
475  GausBG->SetParName(2,"sigma");
476  GausBG->SetParameter(0,PeakY/10000);
477  GausBG->SetParameter(1,PeakX/100000.);
478  GausBG->SetParameter(2,100./100000.);
479  GausBG->SetParLimits(0,0.000001, 1000000);
480  GausBG->SetParLimits(1,(PeakX-100)/100000.,(PeakX+100)/100000.);
481  GausBG->SetParLimits(2,1./100000.,1000./100000.);
482  /*GausBG->SetParameter(0,1);
483  GausBG->SetParameter(1,1);
484  GausBG->SetParameter(2,0);
485  GausBG->FixParameter(2,0);
486  GausBG->FixParameter(1,0);
487  GausBG->FixParameter(0,0);
488  */
489  GausBG->SetNpx(100000);
490  GausBG->SetLineColor(kRed);
491  hGamEnergy->Fit(GausBG,"R");
492 }
493 
495 {
496 cout << "Hyp Ge Gamma Ana:\tCHi²red of the fit \t"<<GausBG->GetChisquare() / GausBG->GetNDF() << endl;
497  cout << "Hyp Ge Gamma Ana:\tCHi²red of the fit \t"<<GausBG->GetChisquare() <<" "<< GausBG->GetNDF() << endl;
498  TxtFile << "Hyp Ge Gamma Ana:\tCHi²red of the fit \t"<<GausBG->GetChisquare() / GausBG->GetNDF() << endl;
499  TxtFile << "Hyp Ge Gamma Ana:\tFitparameter Spectrum (model: gausn):" << endl;
500  for (Int_t i = 0; i < 3; i++)
501  {
502  TxtFile <<"Hyp Ge Gamma Ana:\t" << GausBG->GetParName(i) << ":\t" << GausBG->GetParameter(i) << endl;
503  }
504  if (fVerbose >= 2)
505  {
506  cout << "Hyp Ge Gamma Ana:\tFitparameter Spectrum (model: gausn):" << endl;
507  for (Int_t i = 0; i < 3; i++)
508  {
509  cout <<"Hyp Ge Gamma Ana:\t" << GausBG->GetParName(i) << ":\t" << GausBG->GetParameter(i) << endl;
510  }
511  }
512 
513  Double_t FWHM = GausBG->GetParameter(2)*2.3548200;
514  if (fVerbose >= 2)
515  cout << "Hyp Ge Gamma Ana:\tFWHM[keV]: " << FWHM*1000 << endl;
516  TxtFile << "Hyp Ge Gamma Ana:\tFWHM[keV]:\t" << FWHM*1000 << endl;
517 
518  if (fVerbose >= 2)
519  cout << "Hyp Ge Gamma Ana:\tFull-Energy-Peak-Eff. [%]: " << double(int(GausBG->GetParameter(0)*100000/(NumberOfEvents*2)*100*1000))/1000 << " ± " << double(int(GausBG->GetParError(0)*100000/(NumberOfEvents*2)*100*1000))/1000 << endl; // *2 because only 2Pi of solid angle is simulated
520  TxtFile << "Hyp Ge Gamma Ana:\tFull-Energy-Peak-Eff. [%]: \t" << double(int(GausBG->GetParameter(0)*100000/(NumberOfEvents*2)*100*1000))/1000 << " ± " << double(int(GausBG->GetParError(0)*100000/(NumberOfEvents*2)*100*1000))/1000 << endl; // *2 because only 2Pi of solid angle is simulated
521 }
522 
524 {
525  TSpectrum *s = new TSpectrum(nPeaks);
526  s->Search(hGamEnergy,0.01,"goffnodraw",0.01);
527 
528  if (fVerbose >= 2)
529  cout << "Hyp Ge Gamma Ana:\tSpectrum search finished: " << hGamEnergy->GetEntries() <<endl;
530 
531  xpeaks = s->GetPositionX();
532  ypeaks = s->GetPositionY();
533 
534  if (fVerbose == 3)
535  {
536  for (Int_t i = 0; i < nPeaks; i++)
537  {
538  cout <<"Hyp Ge Gamma Ana:\tPeak @ ("<< xpeaks[i]<<"," << ypeaks[i] << ")" << endl;
539  }
540  }
541  PeakX = xpeaks[PeakToLook-1]*100000;
542  PeakY = ypeaks[PeakToLook-1];
543  DPeakY = sqrt(PeakY);
544 
545  delete s;
546 }
547 
549 {
550  //get content of peak
551  SumPeak = 0;
552  for(Int_t i = PeakX-PeakWidth*10*1000000*100; i <= PeakX+PeakWidth*10*1000000*100; i++) //Peak = 10 * PeakWidth of 1 crystal --> takes multiple hits into account (faster than fitting and than doing it again, error is small)
553  SumPeak += hGamEnergy->GetBinContent(i);
554  DSumPeak = sqrt(SumPeak);
555  if (fVerbose >= 2)
556  {
557  cout <<"Hyp Ge Gamma Ana:\tPeak at bin "<< PeakX << endl;
558  cout <<"Hyp Ge Gamma Ana:\tPeak bin height"<< PeakY << " ± " << DPeakY<< endl;
559  cout <<"Hyp Ge Gamma Ana:\tSumPeak "<<SumPeak << " ± " << DSumPeak << endl;
560  }
561  TxtFile <<"Hyp Ge Gamma Ana:\tPeak at bin \t"<< PeakX << endl;
562  TxtFile <<"Hyp Ge Gamma Ana:\tPeak bin height\t"<< PeakY << " ± " << DPeakY<< endl;
563  TxtFile <<"Hyp Ge Gamma Ana:\tSumPeak \t"<<SumPeak << " ± " << DSumPeak << endl;
564 }
565 
567 {
568  DoComptonCalculations= isActivated;
569 }
570 
572 {
573 // get number of compton events
574 
575  for (Int_t i =Compton(GammaEnergy,lowComptonAngle)*1000*100000; i <= Compton(GammaEnergy,highComptonAngle)*1000*100000; i++)
576  {
577  SumCompton += hGamEnergy->GetBinContent(i);
578  }
580 
581  if (fVerbose >= 2)
582  {
583  cout <<"Hyp Ge Gamma Ana:\tCompton from bins [" << Compton(GammaEnergy,lowComptonAngle)*1000*100000 << " to "<< Compton(GammaEnergy,highComptonAngle)*1000*100000 << "]" << endl;
584  cout <<"Hyp Ge Gamma Ana:\tNumber of compton events: "<< SumCompton<< " +- " << DSumCompton << endl;
585  }
586  TxtFile <<"Hyp Ge Gamma Ana:\tCompton range [bins] \t[" << Compton(GammaEnergy,lowComptonAngle)*1000*100000 << " to "<< Compton(GammaEnergy,highComptonAngle)*1000*100000 << "]" << endl;
587  TxtFile <<"Hyp Ge Gamma Ana:\tNumber of compton events: \t"<< SumCompton<< " +- " << DSumCompton << endl;
588 
589  // calculate Peak/Compton ratio
590 
591  if (SumCompton != 0)
592  {
595  if (fVerbose >= 2)
596  cout << "Hyp Ge Gamma Ana:\tPeak/Compton : "<< PeakToCompton << " ± "<< DPeakToCompton << endl;
597  TxtFile << "Hyp Ge Gamma Ana:\tPeak/Compton : \t"<< PeakToCompton << " ± "<< DPeakToCompton << endl;
598  }
599  else
600  {
601  if (fVerbose >= 2)
602  cout << "Hyp Ge Gamma Ana:\tSumCompton = 0 -> no PeakToCompton possible!"<<endl;
603  TxtFile << "Hyp Ge Gamma Ana:\tSumCompton = 0 -> no PeakToCompton possible!"<<endl;
604  }
605 }
606 
608 {
609 //-------------writing and drawing the histograms-------------------------
610 
611 HistogramCosmetics(hGamEnergy, "#gamma Energy [MeV]", 0.06, 0.7, 0.045, "Counts", 0.06, 0.8, 0.045);
612 HistogramCosmetics(hGamEnergyTargetBackground, "#gamma Energy [MeV]", 0.06, 0.7, 0.045, "Counts", 0.06, 0.8, 0.045);
613 HistogramCosmetics(hNumberOfHits, "Number of Crystals hit", 0.06, 0.7, 0.045, "Counts", 0.06, 0.8, 0.045);
614 HistogramCosmetics(hThetaCheck, "#Theta [#circ]", 0.06, 0.7, 0.045, "Counts", 0.06, 0.8, 0.045);
615 HistogramCosmetics(hThetaCheckPrimary, "#Theta [#circ]", 0.06, 0.7, 0.045, "Counts", 0.06, 0.8, 0.045);
616 HistogramCosmetics(hAbsorption, "part of absorption", 0.06, 0.7, 0.045, "Counts", 0.06, 0.8, 0.045);
617 HistogramCosmetics2D(h2AbsorptionDistanceAngle, "#Theta [#circ]", 0.06, 0.7, 0.045, "Distance [cm]", 0.06, 0.8, 0.045);
618 
619 hGamEnergy->Write();
621 hNumberOfHits->Write();
622 hThetaCheck->Write();
623 hThetaCheckPrimary->Write();
624 hAbsorption->Write();
626 TCanvas* CanGamEnergy = new TCanvas("CanGamEnergy", "Gamma Energy", 1000,600);
627 hGamEnergy->Draw();
628 
629 TCanvas* CanGamEnergyTarget = new TCanvas("CanGamEnergyTarget", "Gamma Energy target", 1000,600);
631 
632 TCanvas* CanNoH = new TCanvas("CanNoH", "Number of Hits", 1000,600);
633 hNumberOfHits->Draw();
634 
635 TCanvas* CanTH = new TCanvas("CanTH", "TH", 1000,600);
636 hThetaCheck->Draw();
637 
638 TCanvas* CanTHPrimary = new TCanvas("CanTHPrimary", "TH prim", 1000,600);
639 hThetaCheckPrimary->Draw();
640 
641 TCanvas* CanAbsorption = new TCanvas("CanAbsorption", "part of absorption", 1000,600);
642 hAbsorption->Draw();
643 
644 TCanvas* CanAbsorption2D = new TCanvas("CanAbsorption2D", "correlation of absorption distance and theta", 1000,600);
645 h2AbsorptionDistanceAngle->Draw("colz");
646 }
647 
649 {
650  //to be implemented
651  // this function checks if a gamma that was absorbed in the target system would have hit the solid angle of the germanium, only than it's important for the material budget
652  // to do this, the start vertex and the momentum vector of the primary gamma have to be projected and checked of this line crosses a germanium detector
653  return 0;
654 }
655 
656 void PndHypGeGammaAna::SetTarget(Bool_t TargetAvailable)
657 {
658  fTargetAvailable=TargetAvailable;
659 }
660 void PndHypGeGammaAna::SetOmegaQuadrupolMode(Bool_t useOmegaQuadrupolMode_ext )
661 {
662  useOmegaQuadrupolMode=useOmegaQuadrupolMode_ext;
663 }
664 
666 {
667  PeakWidtchStrechFactor=PeakWidtchStrechFactor_ext;
668 }
669 
PndMCTrack * fMCGam
TClonesArray * fMc
Double_t GetZin() const
Definition: PndHypPoint.h:94
int fVerbose
Definition: poormantracks.C:24
void ActivateComptonCalculations(Bool_t isActivated=1)
void HistogramCosmetics(TH1D *histo, TString XTitle, Double_t XTitleSize, Double_t XTitleOffset, Double_t XLabelSize, TString YTitle, Double_t YTitleSize, Double_t YTitleOffset, Double_t YLabelSize)
Double_t GetXin() const
Definition: PndHypPoint.h:92
PndHypGePoint * fHitGe
Double_t CalculatePeakWidth(Double_t Energy)
bool InTargetAbsorbedGammaWouldHitGermanium()
void SetTarget(Bool_t TargetAvailable=1)
TClonesArray * fMcTr
Int_t i
Definition: run_full.C:25
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
Double_t PeakWidtchStrechFactor
Double_t invCompton(Double_t E, Double_t Eprime)
TLorentzVector s
Definition: Pnd2DStar.C:50
TClonesArray * fSilicon
void HistogramCosmetics2D(TH2D *histo, TString XTitle, Double_t XTitleSize, Double_t XTitleOffset, Double_t XLabelSize, TString YTitle, Double_t YTitleSize, Double_t YTitleOffset, Double_t YLabelSize)
Int_t GetTrackID() const
Definition: PndHypGePoint.h:51
TVector3 GetMomentum() const
Definition: PndMCTrack.h:78
TGeoManager * gGeoManager
static T Cos(const T &x)
Definition: PndCAMath.h:43
PndMCTrack * fMCGamPrimary
Bool_t useOmegaQuadrupolMode
Double_t Compton(Double_t E, Double_t Th)
static T Abs(const T &x)
Definition: PndCAMath.h:39
Double_t iHistoUpperLimit
void SetPeakWidtchStrechFactor(Double_t PeakWidtchStrechFactor_ext=1)
Double_t
void SetOmegaQuadrupolMode(Bool_t useOmegaQuadrupolMode_ext=1)
Int_t nEvents
Definition: hit_dirc.C:11
TClonesArray * fGeAl
std::set< int > SetOfCrystalHit
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
TClonesArray * fTargetOther
PndHypPoint * fHitSi
PndHypPoint * fHitTargetOther
TH1D * hGamEnergyTargetBackground
Double_t SmearHit(Double_t Energy)
TString GetDetName() const
Definition: PndHypPoint.h:119
ClassImp(PndAnaContFact)
TH2D * h2AbsorptionDistanceAngle
virtual void Exec(Option_t *opt)
virtual InitStatus Init()
TVector3 GetStartVertex() const
Definition: PndMCTrack.h:76
Int_t GetMotherID() const
Definition: PndMCTrack.h:74
Double_t Pi
Int_t GetDetectorID() const
Definition: PndHypGePoint.h:53
TClonesArray * fGe
Double_t GetEnergyLoss() const
Definition: PndHypGePoint.h:62
FairRootManager * ioman