forked from mc4ne/CreateXSTree
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.cc
More file actions
298 lines (258 loc) · 10.8 KB
/
Copy pathMain.cc
File metadata and controls
298 lines (258 loc) · 10.8 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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <time.h>
#include <thread>
#include <vector>
#include <chrono>
//#define RATES_DEBUG 1
using namespace std;
#include "HMSXSTree.h"
#include "SHMSXSTree.h"
#include "XSTree.h"
#include "ExtractAcceptance.h"
#include "ACCTools.h"
extern double A1NOptics();
extern double* GetOpticsRate(double pBeamCurrent, double pBeamE, double pDetectorAngle, double pDetectorMomentum, string pDetectorName, int pElasOnly=0);
extern double A1NRates();
//Method 1
extern double GetRate(double pBeamCurrent, double pBeamE, double pDetectorAngle, double pDetectorMomentum, string pDetectorName, int pElasOnly=0);
//Method 2
extern void GetRate(double pBeamCurrent_uA, double pBeamE_GeV, double pDetectorAngle_deg, double pDetectorMomentum_GeV, int Det, int pFullAcc=1);
int getopticsrate_main(int argc, char** argv)
{
if(argc<6) {
cout<<" Error: you need to provide at least 5 arguments!\n"
<<" Calculate rates using method 1.\n"
<<" Usage: "<<argv[0]<<" <BeamCurrent_uA> <Beam_GeV> <DetectorAngle_deg> <DetectorMomentum_GeV> <DetectorName=HMS|SHMS> [ElasOnly=0]\n"
<<" All energies are in GeV unit. All angles are in degree unit.\n"
<<" ElasOnly=-1: pure inelastic for full acceptance.\n"
<<" ElasOnly=0: inelastic + elastic for full acceptance.\n"
<<" ElasOnly=1: pure elastic for full acceptance.\n"
<<" ElasOnly=-30: pure inelastic for 2-SC-Bar acceptance.\n"
<<" ElasOnly=30: inelastic + elastic for 2-SC-Bar acceptance.\n"
<<" ElasOnly=31: pure elastic for 2-SC-Bar acceptance.\n"
<<endl;
exit(-1);
}
const double degree = asin(1.0)/90.0;
double pBeamCurrent, pBeamE, pDetectorAngle, pDetectorMomentum;
string pDetectorName;
pBeamCurrent = atof(argv[1]);
pBeamE = atof(argv[2]);
pDetectorAngle = atof(argv[3])*degree;
pDetectorMomentum = atof(argv[4]);
pDetectorName = argv[5];
int pElasOnly = 0;
if(argc>6) pElasOnly = atol(argv[6]);
cout<<" Beam="<<pBeamE<<" DetAngle="<<pDetectorAngle/degree<<" pDetectorMomentum="<<pDetectorMomentum<<endl;
//extern double* GetOpticsRate(double pBeamCurrent, double pBeamE, double pDetectorAngle, double pDetectorMomentum, string pDetectorName, int pElasOnly=0);
GetOpticsRate(pBeamCurrent, pBeamE, pDetectorAngle, pDetectorMomentum, pDetectorName, pElasOnly);
return 0;
}
int getrate1_main(int argc, char** argv)
{
if(argc<6) {
cout<<" Error: you need to provide at least 5 arguments!\n"
<<" Calculate rates using method 1.\n"
<<" Usage: "<<argv[0]<<" <BeamCurrent_uA> <Beam_GeV> <DetectorAngle_deg> <DetectorMomentum_GeV> <DetectorName=HMS|SHMS> [ElasOnly=0]\n"
<<" All energies are in GeV unit. All angles are in degree unit.\n"
<<" ElasOnly=-1: pure inelastic for full acceptance.\n"
<<" ElasOnly=0: inelastic + elastic for full acceptance.\n"
<<" ElasOnly=1: pure elastic for full acceptance.\n"
<<" ElasOnly=2: inelastic + elastic for full acceptance, with cut of 1.10<W<1.35.\n"
<<" ElasOnly=4: inelastic + elastic for full acceptance. with cut of 2.00<W<100.0\n"
<<" ElasOnly=-30: pure inelastic for 2-SC-Bar acceptance.\n"
<<" ElasOnly=30: inelastic + elastic for 2-SC-Bar acceptance.\n"
<<" ElasOnly=31: pure elastic for 2-SC-Bar acceptance.\n"
<<endl;
exit(-1);
}
const double degree = asin(1.0)/90.0;
double pBeamCurrent, pBeamE, pDetectorAngle, pDetectorMomentum;
string pDetectorName;
pBeamCurrent = atof(argv[1]);
pBeamE = atof(argv[2]);
pDetectorAngle = atof(argv[3])*degree;
pDetectorMomentum = atof(argv[4]);
pDetectorName = argv[5];
int pElasOnly = 0;
if(argc>6) pElasOnly = atol(argv[6]);
cout<<" Beam="<<pBeamE<<" DetAngle="<<pDetectorAngle/degree<<" pDetectorMomentum="<<pDetectorMomentum<<endl;
GetRate(pBeamCurrent, pBeamE, pDetectorAngle, pDetectorMomentum, pDetectorName, pElasOnly);
return 0;
}
int getrate2_main(int argc, char** argv)
{
if(argc<8) {
cout<<" Error: you need to provide 7 arguments!\n"
<<" Calculate rates using method 2.\n"
<<" Usage: "<<argv[0]<<" <BeamCurrent_uA> <Beam_GeV> <DetectorAngle_deg> <DetectorMomentum_GeV> <Detector=1 HMS|2 SHMS> <FullAcceptance=0|1> <xstree_file>\n"
<<" All energies are in GeV unit. All angles are in degree unit.\n"
<<" FullAcceptance==0: will use full acceptance, otherwise only for 2-SC-Bar.\n"
<<endl;
exit(-1);
}
const double degree = asin(1.0)/90.0;
double pBeamCurrent, pBeamE, pDetectorAngle, pDetectorMomentum;
int pDetector, pFullAcceptance;
pBeamCurrent = atof(argv[1]);
pBeamE = atof(argv[2]);
pDetectorAngle = atof(argv[3])*degree;
pDetectorMomentum = atof(argv[4]);
pDetector = atol(argv[5]);
pFullAcceptance = atol(argv[6]);
string xstree_file = argv[7];
TFile *file = TFile::Open(xstree_file.c_str());
cout<<"\n Calculate rates for \""<<xstree_file<<"\" using method 2.\n";
cout<<" Beam="<<pBeamE<<" DetAngle="<<pDetectorAngle/degree<<" pDetectorMomentum="<<pDetectorMomentum<<endl;
GetRate(pBeamCurrent, pBeamE, pDetectorAngle, pDetectorMomentum, pDetector, pFullAcceptance);
file->Close();
return 0;
}
int a1nrate_main(int argc, char** argv)
{
if(argc<2) {
cout<<" Usage: "<<argv[0]<<" [no_argument_needed]\n"
<<endl;
}
A1NRates();
return 0;
}
int a1noptics_main(int argc, char** argv)
{
if(argc<2) {
cout<<" Usage: "<<argv[0]<<" [no_argument_needed]\n"
<<endl;
}
A1NOptics();
return 0;
}
int xstree_main(int argc, char** argv)
{
if(argc<6) {
cout<<" Error: you need to provide 6 arguments!\n"
<<" Usage: "<<argv[0]<<" <pElasOnly> <pBeam_GeV> <pDetectorAngle_deg> <pDetectorMomentum_GeV> <pDetector=1,10 HMS|2,20 SHMS> <rootfile>\n"
<<" if pDetector==10 or 20, will use XStree to do the job \n"
<<" if pElasOnly!=0, will fill the ntuple using elastic XS other than Bosted inelastic XS\n"
<<" All energies are in GeV unit. All angles are in degree unit."
<<endl;
exit(-1);
}
const double degree = asin(1.0)/90.0;
int pElasOnly=0;
double pBeamE, pDetectorAngle, pDetectorMomentum;
int pDetector=1;
TString infile;
pElasOnly = atol(argv[1]);
pBeamE = atof(argv[2]);
pDetectorAngle = atof(argv[3])*degree;
pDetectorMomentum = atof(argv[4]);
pDetector = atol(argv[5]);
infile = argv[6];
cout<<" Beam="<<pBeamE<<" DetAngle="<<pDetectorAngle/degree<<" pDetectorMomentum="<<pDetectorMomentum<<endl;
if(pDetector==1) {
HMSXSTree* pHMS = new HMSXSTree(infile.Data());
pHMS->SetPara(pBeamE, pDetectorAngle, pDetectorMomentum);
pHMS->SetElas(pElasOnly);
pHMS->Run();
delete pHMS;
} else if(pDetector==2) {
SHMSXSTree* pSHMS = new SHMSXSTree(infile.Data());
pSHMS->SetPara(pBeamE, pDetectorAngle, pDetectorMomentum);
pSHMS->SetElas(pElasOnly);
pSHMS->Run();
delete pSHMS;
} else if(pDetector==10 || pDetector==20) {
XSTree* pXSTree = new XSTree(infile.Data(),pDetector/10);
pXSTree->SetPara(pBeamE, pDetectorAngle, pDetectorMomentum);
pXSTree->SetElas(pElasOnly);
pXSTree->Run();
delete pXSTree;
}
return 0;
}
int extractacc_main(int argc, char** argv)
{
if(argc<4) {
cout<<" Error: you need to provide 3 arguments!\n"
<<" Usage: "<<argv[0]<<" <pDetector=1 HMS|2 SHMS> <pType=1|2> <infile> [nthread=1]\n"
<<" pType=2 means only 2 SC bars are turned on\n"
<<" infile is a txt file that list the absolute path of all source root files \n"
<<" nthread is number of threads you want to run with. \n"
<<endl;
exit(-1);
}
int pDet = atol(argv[1]);
int pType = atol(argv[2]);
TString infile = argv[3];
int nthread = 1;
if(argc>4) nthread = atol(argv[4]);
struct timespec start, end;
struct timespec wstart, wend;
double cpu_time=0, wall_time=0;
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start);
clock_gettime(CLOCK_MONOTONIC, &wstart);
std::vector<ExtractAcceptance*> pAcc;
for(int i=0;i<nthread;i++) {
pAcc.push_back(new ExtractAcceptance(infile.Data(),pDet,pType,i,nthread));
}
//construct thread, it will run immediately
std::vector<std::thread> threadObj;
for (int i = 0; i < nthread; i++) {
threadObj.push_back(std::thread(&ExtractAcceptance::Run, pAcc[i]));
std::this_thread::sleep_for(std::chrono::milliseconds(200)); //wait 200ms so the print out message will not be messed up
}
//synchronize threads:
for(int i=0;i<nthread;i++) {
threadObj[i].join();
}
//now merge all results
for(int i=1;i<nthread;i++) {
pAcc[0]->MergeResult(pAcc[i]);
}
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end);
clock_gettime(CLOCK_MONOTONIC, &wend);
cpu_time = (end.tv_sec + 1e-9*end.tv_nsec) - (start.tv_sec + 1e-9*start.tv_nsec);
wall_time = (wend.tv_sec + 1e-9*wend.tv_nsec) - (wstart.tv_sec + 1e-9*wstart.tv_nsec);
cout<<"All threads are done. cpu_time="<<cpu_time<<"s, wall_time="<<wall_time<<"s"<<endl;
//now create output file
cout<<"ExtractAccptance() is merging the result and creating output files ...\n";
pAcc[0]->EndOfRun();
cout<<"done!\n";
return 0;
}
int main(int argc, char** argv)
{
if(argc<2) {
cout<<" Error: you need to provide at least 2 arguments!\n"
<<" Usage: "<<argv[0]<<" <task=a1nrate|extractacc|xstree|getrate> <other_arguments>\n"
<<" task==a1nrate: get all A1N rates for all kinematic points \n"
<<" task==extractacc: extract HMS or SHMS acceptance \n"
<<" task==xstree: add xs branches into mc-signle-arm output ntuple \n"
<<" task==getrate1: get rate for one single kinematics point using method 1\n"
<<" task==getrate2: get rate for given xstree_file using method 2\n"
<<" task==a1noptics: get all A1N optics rates for all kinematic points \n"
<<" task==getopticsrate: get rates for each C12 foil for given kinematic\n"
<<endl
<<" For details of 'other_arguments' in each task, type 'help' after that task \n"
<<" For example: "<<argv[0]<<" extractacc help \n"
<<endl;
exit(-1);
}
string task=argv[1];
if(task == "a1nrate") a1nrate_main(argc-1,&argv[1]);
else if(task == "extractacc") extractacc_main(argc-1,&argv[1]);
else if(task == "xstree") xstree_main(argc-1,&argv[1]);
else if(task == "getrate1") getrate1_main(argc-1,&argv[1]);
else if(task == "getrate2") getrate2_main(argc-1,&argv[1]);
else if(task == "a1noptics") a1noptics_main(argc-1,&argv[1]);
else if(task == "getopticsrate") getopticsrate_main(argc-1,&argv[1]);
else {
cout<<" this given task '"<<task<<"' is not curruetly support ...\n";
}
return 0;
}