-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDDMAnalysis.cpp
178 lines (133 loc) · 5.92 KB
/
DDMAnalysis.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include "TFile.h"
#include "TTree.h"
#include "TBranch.h"
#include "TH1I.h"
#include "TGraph2D.h"
#include "TGraphErrors.h"
using namespace std;
int main (int argc, char** argv)
{
//string steeringFileName = argv[1];
string directory = argv[1];
stringstream steeringFileName;
steeringFileName << directory << "steering.txt";
ifstream steeringFile;
steeringFile.open(steeringFileName.str().c_str());
string word;
string filename;
Double_t pressure;
Double_t timeRes;
TGraph2D* deviationPlot = new TGraph2D(1);
deviationPlot->SetNameTitle("deviation", "Median directional deviation vs pressure and time resolution");
TGraph2D* deviationPlotMean = new TGraph2D(1);
deviationPlotMean->SetNameTitle("deviationMean", "Mean directional deviation vs pressure and time resolution");
TGraph2D* thetaErrorPlot = new TGraph2D(1);
thetaErrorPlot->SetNameTitle("thetaError", "Median theta deviation vs pressure and time resolution");
TGraph2D* thetaErrorPlotMean = new TGraph2D(1);
thetaErrorPlotMean->SetNameTitle("thetaErrorMean", "Mean theta deviation vs pressure and time resolution");
TGraph2D* phiErrorPlot = new TGraph2D(1);
phiErrorPlot->SetNameTitle("phiError", "Median phi deviation vs pressure and time resolution");
TGraph2D* phiErrorPlotMean = new TGraph2D(1);
phiErrorPlotMean->SetNameTitle("phiErrorMean", "Mean phi deviation vs pressure and time resolution");
TGraphErrors* deviationMeanPressureErrors = new TGraphErrors(1);
deviationMeanPressureErrors->SetNameTitle("deviationMeanPressureErrors", "Mean directional deviation versus pressure (best time resolution)");
TGraphErrors* deviationMeanTimeResErrors = new TGraphErrors(1);
deviationMeanTimeResErrors->SetNameTitle("deviationMeanTimeResErrors", "Mean directional deviation versus time resolution (best pressure)");
Int_t pointCounter = 0;
Int_t pointCounterPressure = 0;
Int_t pointCounterTimeRes = 0;
while (steeringFile >> word)
{
pointCounter++;
deviationPlot->Set(pointCounter);
TH1I* deviationHist = new TH1I("deviation", "deviation", 100, 0, M_PI);
TH1I* thetaErrorHist = new TH1I("thetaError", "thetaError", 100, 0, M_PI);
TH1I* phiErrorHist = new TH1I("phiError", "phiError", 100, 0, 2*M_PI);
// Get parameters from steering file
steeringFile >> word;
pressure = atof(word.c_str());
steeringFile >> word;
timeRes = atof(word.c_str());
stringstream filename;
filename << directory << "ddm_p" << pressure << "atm_tres" << timeRes << "ns.root";
cout << "Reading file: " << filename.str() << " (pressure " << pressure << " atm, time resolution " << timeRes << " ns)" << endl;
// Open data file and read in results tree
TFile* dataFile = new TFile(filename.str().c_str(), "READ");
TTree* dataTree = (TTree*)dataFile->Get("recoResultsCamera");
TBranch* dataBranch = dataTree->GetBranch("recoResultsCamera_branch");
Int_t nEvents = dataTree->GetEntries();
// Get branch contents
Double_t branchData[9];
dataTree->SetBranchAddress("recoResultsCamera_branch", &branchData);
// Loop over data
for (Int_t i=0; i<nEvents; i++)
{
dataTree->GetEntry(i);
deviationHist->Fill(branchData[6]);
thetaErrorHist->Fill(branchData[8]);
phiErrorHist->Fill(branchData[7]);
}
// Calculate mean and median of deviation distribution
Double_t deviationMean = deviationHist->GetMean();
Double_t deviationMeanError = deviationHist->GetMeanError();
Double_t deviationMedian;
Double_t thetaErrorMean = thetaErrorHist->GetMean();
Double_t thetaErrorMedian;
Double_t phiErrorMean = phiErrorHist->GetMean();
Double_t phiErrorMedian;
Double_t medianQuantile = 0.5;
deviationHist->GetQuantiles(1,&deviationMedian,&medianQuantile);
thetaErrorHist->GetQuantiles(1,&thetaErrorMedian,&medianQuantile);
phiErrorHist->GetQuantiles(1,&phiErrorMedian,&medianQuantile);
//cout << "Median deviation: " << deviationMedian << endl << endl;
delete deviationHist;
delete thetaErrorHist;
delete phiErrorHist;
// Close data file
dataFile->Close();
// Save data points
deviationPlot->SetPoint(pointCounter - 1, pressure, timeRes, deviationMedian);
deviationPlotMean->SetPoint(pointCounter - 1, pressure, timeRes, deviationMean);
thetaErrorPlot->SetPoint(pointCounter - 1, pressure, timeRes, thetaErrorMedian);
thetaErrorPlotMean->SetPoint(pointCounter - 1, pressure, timeRes, thetaErrorMean);
phiErrorPlot->SetPoint(pointCounter - 1, pressure, timeRes, phiErrorMedian);
phiErrorPlotMean->SetPoint(pointCounter - 1, pressure, timeRes, phiErrorMean);
if (timeRes == 1.0)
{
pointCounterPressure++;
deviationMeanPressureErrors->SetPoint(pointCounterPressure - 1, pressure, deviationMean);
deviationMeanPressureErrors->SetPointError(pointCounterPressure - 1, 0, deviationMeanError);
}
if (pressure == 0.005)
{
pointCounterTimeRes++;
deviationMeanTimeResErrors->SetPoint(pointCounterTimeRes - 1, timeRes, deviationMean);
deviationMeanTimeResErrors->SetPointError(pointCounterTimeRes - 1, 0, deviationMeanError);
}
}
TFile* analysisFile = new TFile("/storage/gp_ws_ddm/Analysis.root", "UPDATE");
deviationPlot->Write();
delete deviationPlot;
deviationPlotMean->Write();
delete deviationPlotMean;
thetaErrorPlot->Write();
delete thetaErrorPlot;
thetaErrorPlotMean->Write();
delete thetaErrorPlotMean;
phiErrorPlot->Write();
delete phiErrorPlot;
phiErrorPlotMean->Write();
delete phiErrorPlotMean;
deviationMeanPressureErrors->Write();
delete deviationMeanPressureErrors;
deviationMeanTimeResErrors->Write();
delete deviationMeanTimeResErrors;
steeringFile.close();
analysisFile->Close();
return 0;
}