-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainCode.cpp
More file actions
133 lines (96 loc) · 3.78 KB
/
MainCode.cpp
File metadata and controls
133 lines (96 loc) · 3.78 KB
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
{
string Event_Number,Graph,s;
cout<<"Input Event number"<<endl;
cin>>Event_Number;
cout<<"Enter type of graph you want"<<endl;
cin>>Graph;
// Graph Definitions
HitGlobal_xy = new TGraph();
HitGlobal_rz = new TGraph();
// for NHit_vs_theta theta ranges from 0 to 180 degrees so 100 bins taken
NHit_vs_theta_Histogram = new TH1D("NHit_vs_theta_Histogram", "NHit_vs_theta;Polar Angle(Theta)[Degrees];Number of Hits", 100 , 0,180);
// for NHitPair_vs_dist Max distance is approx 5k-6k so 100 bins in range
NHitPair_vs_dist = new TH1D("NHitPair_vs_dist","NHitPair_vs_dist;Distance;Number of Pairs",100,0,6000);
if( Graph == "HitGlobal_xy" ){
HitGlobal_xy->SetTitle("Measured Hit Position Projected to x-y Plane;X(mm);Y(mm)");
ifstream Input_File("event"+Event_Number+"-hits.csv");//input file
int hit,volume,layer,module;
double x,y,z;
char c;
Input_File>>s;//for ignoring first line which consists comma seprated strings
// Main Calculation
while(Input_File.good()){
Input_File>>hit>>c>>x>>c>>y>>c>>z>>c>>volume>>c>>layer>>c>>module;
HitGlobal_xy->SetPoint(hit,x,y);
}
//plot
HitGlobal_xy->Draw("AP");
}
else if( Graph == "HitGlobal_rz" ){
HitGlobal_rz->SetTitle("Measured Hit Position Projected to r-z Plane;Z(mm);R(mm)");
ifstream Input_File("event"+Event_Number+"-hits.csv");// input file
int hit,volume,layer,module;
double x,y,z;
char c;
Input_File>>s;//ignoring first line of file
//Main Calculation
while(Input_File.good()){
Input_File>>hit>>c>>x>>c>>y>>c>>z>>c>>volume>>c>>layer>>c>>module;
double r = sqrt( ( x*x ) + ( y*y ) ); //Calculation of R for plot
HitGlobal_rz->SetPoint(hit,z,r);
}
//plot
HitGlobal_rz->Draw("AP");
}
else if( Graph == "NHit_vs_theta" ){
ifstream Input_File("event"+Event_Number+"-particles.csv");//input file
string particle_id;
int q,j=0;
double vx,vy,vz,px,py,pz,nhits;
char c;
Input_File>>s;
//Main Calculation
while(Input_File.good()){
Input_File>>particle_id>>c>>vx>>c>>vy>>c>>vz>>c>>px>>c>>py>>c>>pz>>c>>q>>c>>nhits;
double theta = acos(vz/(sqrt( ( vx*vx ) + ( vy*vy ) + ( vz*vz ) ))); // Calculationof theta using inverseCos formula
theta = theta*(180 / 3.141592);//conversion to degrees
if(isnan(theta))continue; // for cases where theta tends to nan
NHit_vs_theta_Histogram->Fill(theta);
}
// plot
NHit_vs_theta_Histogram->Draw();
}
else if( Graph == "NHitPair_vs_dist" ){
ifstream Input_File("event"+Event_Number+"-hits.csv");//Input file
int hit,volume,layer,module;
double x,y,z;
char c;
vector<int>volume_id,layer_id,hit_id;
vector <double> cx,cy,cz;
Input_File>>s;
// Storing all the data in vector form
while(Input_File.good()){
Input_File>>hit>>c>>x>>c>>y>>c>>z>>c>>volume>>c>>layer>>c>>module;
auto it1 = volume_id.emplace(volume_id.end() ,volume);
auto it2 = layer_id.emplace(layer_id.end() ,layer);
auto it3 = cx.emplace(cx.end() ,x);
auto it4 = cy.emplace(cy.end() ,y);
auto it5 = cz.emplace(cz.end() ,z);
auto it6 = hit_id.emplace(hit_id.end() ,hit);
}
// Main Calculation for each pair of hits
for(int i=0; i<hit_id.size(); i++){
for(int j=i+1; j<hit_id.size(); j++){
if(volume_id[i]!=volume_id[j] || layer_id[i]!=layer_id[j]){
double x_d = cx[i]-cx[j] ;
double y_d = cy[i]-cy[j] ;
double z_d = cz[i]-cz[j] ;
double distance = sqrt( x_d*x_d + y_d*y_d + z_d*z_d); // distance using distance formula
NHitPair_vs_dist->Fill(distance);
}
}
}
// plot
NHitPair_vs_dist->Draw();
}
}