Geant4_10
fragmentAngularDistributionHistogram.C
Go to the documentation of this file.
1 #include "Riostream.h"
2 #include "TSystem.h"
3 #include "TInterpreter.h"
4 #include "TROOT.h"
5 #include "TApplication.h"
6 #include "TFile.h"
7 #include "TNtuple.h"
8 #include "TCanvas.h"
9 #include "TH1F.h"
10 #include "THStack.h"
11 #include "TCut.h"
12 #include "TString.h"
13 #include "TMath.h"
14 
15 /***************************
16  * Root script that produces a histogram of the angular distribution of
17  * a certain type of charged fragment (default Z=1).
18  *
19  * Notice that this produces a histogram with equally spaced bins for angles.
20  *
21  * Comparison to E.Haettner will not yield good results, but shows
22  * alternative approach for analyzing the same data.
23  *
24  * @author Gillis Danielsen
25  * **************************/
26 
28 gStyle->SetOptStat(0000000000); //remove the redundant statbox
29  gROOT->SetStyle("clearRetro");
30  //this will be used as base for pulling the experimental data
31  TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
32  dir.ReplaceAll("basic.C","");
33  dir.ReplaceAll("/./","/");
34  ifstream in;
35 
36  TString pDepth, fragment, Znum;
37  cout << "Enter phantom depth (eg. 27.9, see experimentalData directory for choices): ";
38  cin >> pDepth;
39  cout << "Enter fragment Z-number (eg. 1): ";
40  cin >> Znum;
41  cout << "Enter fragment name (Znum 1 -> H,Znum 2->He...): ";
42  cin >> fragment;
43 
44  TString experimentalDataPath = "experimentalData/iaeaBenchmark/angularDistributions/" + pDepth + "/" + fragment + "" + pDepth +".dat";
45  TString simulationDataPath = "IAEA_" + pDepth + ".root";
46 
47  in.open(experimentalDataPath);
48  Float_t f1,f2;
49  Int_t nlines = 0;
50  TFile *f = new TFile("fragmentAngularDistribution.root","RECREATE");
51  TNtuple *ntuple = new TNtuple("ntuple","Data from ascii file","x:y");
52 
53  Char_t DATAFLAG[4];
54  Int_t NDATA;
55  Char_t n1[15], n2[15];
56  in >> DATAFLAG >> NDATA ; // Read EXFOR line: 'DATA 6'
57  in >> n1 >> n2; // Read column titles: 'Energy He B [...]'
58 
59  cout <<n1<<" "<<n2<<"\n";
60  while (1) {
61  in >> f1 >> f2;
62  if (!in.good()) break;
63  if (nlines < 500 ) printf("%f %f\n",f1,f2);
64  ntuple->Fill(f1,f2);
65  nlines++;
66  }
67  printf(" found %d points\n",nlines);
68  //Let's pull in the simulation-data
69  //TCanvas *mc = new TCanvas("mc", "Simulation");
70  TFile *simulation = TFile::Open(simulationDataPath);
71  TNtuple *fragments = (TNtuple*) simulation->Get("fragmentNtuple");
72 
73  //Block bellow pulls out the simulation's metadata from the metadata ntuple.
74  TNtuple *metadata = (TNtuple*) simulation->Get("metaData");
75  Float_t events, detectorDistance,waterThickness,beamEnergy,energyError,phantomCenterDistance;
76  metadata->SetBranchAddress("events",&events);
77  metadata->SetBranchAddress("waterThickness",&waterThickness);
78  metadata->SetBranchAddress("detectorDistance",&detectorDistance);
79  metadata->SetBranchAddress("beamEnergy",&beamEnergy);
80  metadata->SetBranchAddress("energyError",&energyError);
81  metadata->SetBranchAddress("phantomCenterDistance",&phantomCenterDistance);
82  metadata->GetEntry(0); //there is just one row to consider.
83 
84  //good to keep for ref. G4 might give weird units due to change.
85  metadata->Scan();
86 
87 
88  TString Znum = Form("%i", 1); //hydrogen seems to be the only interesting fragment due to largest amounts
89  /*
90  * A logical bin amount could be calculated as follows, E.Haettner used a detector with 4cm side length,
91  * the scattering distance is 295.85, thus arctan(4 / 295.85) = 0.774612657 degrees. As 14 degrees is shown
92  * in Haettners graphs and is chosen here as well that would mean approx 14/.77 ~ 18.
93  * This should mean moving the detector one detectorlength. so that the bins "do not overlap". This is ab it of an approx though
94  * because the change in degrees is not linear.
95  * So far these results are though very much inconsistent with Haettners.
96  *
97  * Although here one should note that the degrees are not linear.
98  *
99  * The negativeHist is a cludge-fix to get the negative degrees (will be exactly the same)
100  */
101  Double_t maxDegrees = 14; //highest plotted degree amount
102  int binAmount = 25; //amount of bins in plotted histogram
103  TH1F *hist1 = new TH1F("hist1", "Fragment angular distribution", binAmount, 0, maxDegrees); //The histogram for the angular distribution at a set length
104  //This histogram needs to be hist1 with a symmetric negative side
105  TH1F *symmetricHist = new TH1F("symmetricHist", "Fragment angular distr.", 2*binAmount, -1*maxDegrees, maxDegrees); //bin amount must be even
106 
107  //Things needed for the analysis (based on the metadata pulled earlier)
108  //ALL UNITS ARE FOR NOW cm
109  Double_t detectorSideLength = 4; //40mm
110  Double_t scatteringDistance = detectorDistance - phantomCenterDistance;
111  TString sdstring = Form("%.4f", scatteringDistance);
112 
113  TCanvas *c1 = new TCanvas("histograms", "Angular distribution at certain phantom thickness, sd" + sdstring); //This is where we will plot
114 
118 TString middleY;
119 //Projection from ntuple to histogram, so that the angle is trigonometrically pulled as the binned variable
120  fragments->Project("hist1","57.29577*atan((posZ^2+posY^2)/" + sdstring + ")", "(Z == " + Znum + ")");
121 
122 //Secondly all bins need to be scaled according to the solid angle of that phi+-deltaPhi circlepart. Before this the curve is "bragg-curvish", what I want is "concaveish".
123 //this could be done inside the reading of the tuple into the histo, however doing it afterwards improves
124  Double_t value, width, deltaPhi, degrees;
125  Double_t binNormalization = 1;
126  std::cout << "bin-number" << "\t" << "value" << "\t" << "solid angle segment" << endl;
127 for(int bin = 0; bin <= hist1->GetNbinsX(); bin++){
128  value = hist1->GetBinContent(bin); //the incident-particle normalized amount of hits
129  width = hist1->GetBinWidth(bin); //so this is degrees/radians
130  degrees = hist1->GetBinCenter(bin);
131  deltaPhi = width/2;
132  binNormalization = 2*TMath::Pi()*(TMath::Cos(TMath::DegToRad()*(degrees-deltaPhi)) - TMath::Cos(TMath::DegToRad()*(degrees+deltaPhi))); //Gunzer-marx uses this , which is a tad of an approximation
133  symmetricHist->SetBinContent(bin+hist1->GetNbinsX(), value/(binNormalization*events)); //Solid angle and amount of events
134  symmetricHist->SetBinContent(hist1->GetNbinsX()-bin+1, value/(binNormalization*events)); //Solid angle and amount of events
135  }
136  symmetricHist->SetAxisRange(-2,14);
137  symmetricHist->SetXTitle("Angle (degrees)");
138  symmetricHist->SetYTitle("(N/N0) / [sr]");
139 
141  TF1* fitgaus = new TF1("fitgaus","gaus");
142  TF2* fitexpo = new TF1("fitexpo","expo");
143  fitgaus->SetLineColor(2);
144  fitexpo->SetLineColor(4);
145  symmetricHist->Fit(fitgaus,""); // data should be reshaped a bit for the gaussian (as root seems to have some problems here)
146  symmetricHist->Fit(fitexpo, "+"); //aparently two fits on the same histo seem to much for root
147  symmetricHist->Draw();
148  //symmetricHist->SetMaximum(35); //needed to get E.Haettners data visible
149  /*
150  //Plots of experimental data are kind of meaningless with a constant-angle-binned histogram.
151  ntuple->SetMarkerStyle(22);
152  ntuple->SetMarkerColor(kRed);
153  ntuple->Draw("y:x","","p,same");
154  */
155 
156  c1->SaveAs("angularDistributionHistogramWithFits.png");
157 
158 }
ifstream in
Definition: comparison.C:7
float bin[41]
Definition: plottest35.C:14
#define width
TCanvas * c1
Definition: plotHisto.C:7
TTree * ntuple
Definition: macro.C:6
TFile f
Definition: plotHisto.C:6
void fragmentAngularDistributionHistogram()
Float_t f1
Float_t f2
G4int Int_t
TH1D * hist1
Definition: plotHisto.C:9
G4float Float_t
const XML_Char int const XML_Char * value
Definition: expat.h:331
printf("%d Experimental points found\n", nlines)
G4double Double_t
nlines
TDirectory * dir
Definition: macro.C:5