-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNWReader.cpp
454 lines (407 loc) · 14.9 KB
/
NWReader.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
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
#include "include/NWReader.h"
//____________________________________________________
NWReader::NWReader(TChain *Chain, const char * DataType, bool IsDataCalibrated) :
fChain(Chain),
fDegToRad(TMath::Pi()/180.),
fRadToDeg(180./TMath::Pi()),
fSpeedOfLight(29.9792),
fNWBarLength(200),
fNWBarHigh(7.62),
fNWBarThickness(6.35),
fIsNWA(false),
fIsNWB(false),
fIsFA(false),
fIsVW(false),
fIsDataCalibrated(IsDataCalibrated),
fNWAPositionCalibrated(false),
fNWBPositionCalibrated(false),
fNWTimeCalibrated(false),
fNWPulseHeightCalibrated(false),
fNWACosmicRayPositionLoaded(false),
fNWBCosmicRayPositionLoaded(false),
fNWATimeCalibrated(false),
fNWBTimeCalibrated(false),
fNWAGeometryCalibrated(false),
fNWBGeometryCalibrated(false),
fNWAPulseHeightMatched(false),
fNWBPulseHeightMatched(false),
fNWAPulseHeightCalibrated(false),
fNWBPulseHeightCalibrated(false),
fFATimeCalibrated(false),
fNWAPositionCalibration(new NWPositionCalibration(NUM_BARS_NWA)),
fNWBPositionCalibration(new NWPositionCalibration(NUM_BARS_NWB)),
fNWACosmicRayInfo(new NWCosmicRayManager(NUM_BARS_NWA)),
fNWBCosmicRayInfo(new NWCosmicRayManager(NUM_BARS_NWB)),
fNWATimeCalibration(new NWTimeCalibration(NUM_BARS_NWA)),
fNWBTimeCalibration(new NWTimeCalibration(NUM_BARS_NWB)),
fNWAGeometry(new NWGeometry(NUM_BARS_NWA)),
fNWBGeometry(new NWGeometry(NUM_BARS_NWB)),
fNWAPulseHeightCalibrationTools(new NWPulseHeightCalibration(NUM_BARS_NWA)),
fNWBPulseHeightCalibrationTools(new NWPulseHeightCalibration(NUM_BARS_NWB)),
fFATimeCalibration(new FATimeCalibration(NUM_DETECTORS_FA))
{
//Parsing DataType string to allocate specific detectors
std::string DetectorsIncluded(DataType);
std::istringstream StreamDetectorsIncluded(DetectorsIncluded);
std::string DetectorToAdd;
while (StreamDetectorsIncluded>>DetectorToAdd) {
if(DetectorToAdd.compare("NWA")==0) fIsNWA=true;
if(DetectorToAdd.compare("NWB")==0) fIsNWB=true;
if(DetectorToAdd.compare("FA")==0) fIsFA=true;
if(DetectorToAdd.compare("VW")==0) fIsVW=true;
}
if(fChain!=0) {
fNWReader = new TTreeReader(fChain);
if(!fIsDataCalibrated) {
if(fIsNWA) fNWA = new TTreeReaderValue<HTNeutronWallData>(*fNWReader, "NWA.");
if(fIsNWB) fNWB = new TTreeReaderValue<HTNeutronWallData>(*fNWReader, "NWB.");
if(fIsFA) fForwardArray = new TTreeReaderValue<HTForwardArrayData>(*fNWReader, "ForwardArray.");
if(fIsVW) fVetoWall = new TTreeReaderValue<HTVetoWallData>(*fNWReader, "VetoWall.");
} else {
if(fIsNWA) fNWACal = new TTreeReaderValue<NeutronWallCalibratedData>(*fNWReader, "NWA.");
if(fIsNWB) fNWBCal = new TTreeReaderValue<NeutronWallCalibratedData>(*fNWReader, "NWB.");
if(fIsFA) fForwardArrayCal = new TTreeReaderValue<ForwardArrayCalibratedData>(*fNWReader, "ForwardArray.");
if(fIsVW) fVetoWallCal = new TTreeReaderValue<VetoWallCalibratedData>(*fNWReader, "VetoWall.");
}
}
}
//____________________________________________________
NWReader::~NWReader()
{
if(fChain!=0) {
delete fNWReader;
if(!fIsDataCalibrated) {
if (fIsNWA) delete fNWA;
if (fIsNWB) delete fNWB;
if (fIsFA) delete fForwardArray;
if (fIsVW) delete fVetoWall;
} else {
if (fIsNWA) delete fNWACal;
if (fIsNWB) delete fNWBCal;
if (fIsFA) delete fForwardArrayCal;
if (fIsVW) delete fVetoWallCal;
}
}
if(fNWAPositionCalibration) delete fNWAPositionCalibration;
if(fNWBPositionCalibration) delete fNWBPositionCalibration;
if(fNWACosmicRayInfo) delete fNWACosmicRayInfo;
if(fNWBCosmicRayInfo) delete fNWBCosmicRayInfo;
if(fNWATimeCalibration) delete fNWATimeCalibration;
if(fNWBTimeCalibration) delete fNWBTimeCalibration;
if(fFATimeCalibration) delete fFATimeCalibration;
if(fNWAGeometry) delete fNWAGeometry;
if(fNWBGeometry) delete fNWBGeometry;
}
//____________________________________________________
int NWReader::LoadNWPositionCalibration(const char * file_name, const char * WallToCalibrate)
{
if(strcmp(WallToCalibrate,"NWA")==0) {
int NLines=fNWAPositionCalibration->LoadCalibration(file_name);
if(NLines>0) {
fNWAPositionCalibrated=true;
printf("Loaded position calibration for NWA %s\n", file_name);
return NLines;
}
fNWAPositionCalibrated=false;
}
if(strcmp(WallToCalibrate,"NWB")==0) {
int NLines=fNWBPositionCalibration->LoadCalibration(file_name);
if(NLines>0) {
fNWBPositionCalibrated=true;
printf("Loaded position calibration for NWB %s\n", file_name);
return NLines;
}
fNWBPositionCalibrated=false;
}
printf("Error: Error while loading NW Position calibration file %s\n", file_name);
return -1;
}
//____________________________________________________
int NWReader::LoadNWCosmicRayPosition(const char * file_name, const char * WallToCalibrate)
{
if(strcmp(WallToCalibrate,"NWA")==0) {
int NLines=fNWACosmicRayInfo->LoadPeakPositions(file_name);
if(NLines>0) {
fNWACosmicRayPositionLoaded=true;
printf("Loaded cosmics calibration for NWA %s\n", file_name);
return NLines;
}
fNWACosmicRayPositionLoaded=false;
}
if(strcmp(WallToCalibrate,"NWB")==0) {
int NLines=fNWBCosmicRayInfo->LoadPeakPositions(file_name);
if(NLines>0) {
fNWBCosmicRayPositionLoaded=true;
printf("Loaded cosmics calibration for NWB %s\n", file_name);
return NLines;
}
fNWBCosmicRayPositionLoaded=false;
}
printf("Error: Error while loading NW cosmic ray positions %s\n", file_name);
return -1;
}
//____________________________________________________
int NWReader::LoadNWTimeCalibration(const char * file_name, const char * WallToCalibrate)
{
if(strcmp(WallToCalibrate,"NWA")==0) {
int NLines=fNWATimeCalibration->LoadCalibration(file_name);
if(NLines>0) {
fNWATimeCalibrated=true;
printf("Loaded time calibration for NWA %s\n", file_name);
return NLines;
}
fNWATimeCalibrated=false;
}
if(strcmp(WallToCalibrate,"NWB")==0) {
int NLines=fNWBTimeCalibration->LoadCalibration(file_name);
if(NLines>0) {
fNWBTimeCalibrated=true;
printf("Loaded time calibration for NWB %s\n", file_name);
return NLines;
}
fNWBTimeCalibrated=false;
}
printf("Error: Error while loading NW time calibration %s\n", file_name);
return -1;
}
//____________________________________________________
int NWReader::LoadNWGeometryFiducialPoints(const char * file_name, const char * WallToCalibrate)
{
if(strcmp(WallToCalibrate,"NWA")==0) {
int NLines=fNWAGeometry->LoadFiducialPoints(file_name);
if(NLines>0) {
fNWAGeometryCalibrated=true;
printf("Loaded geometry fiducial points for NWA %s\n", file_name);
return NLines;
}
fNWAGeometryCalibrated=false;
}
if(strcmp(WallToCalibrate,"NWB")==0) {
int NLines=fNWBGeometry->LoadFiducialPoints(file_name);
if(NLines>0) {
fNWBGeometryCalibrated=true;
printf("Loaded geometry fiducial points for NWB %s\n", file_name);
return NLines;
}
fNWBGeometryCalibrated=false;
}
printf("Error: Error while loading NW geometry fiducial points %s\n", file_name);
return -1;
}
//____________________________________________________
int NWReader::LoadFATimeCalibration(const char * file_name)
{
int NLines=fFATimeCalibration->LoadCalibration(file_name);
if(NLines>0) {
fFATimeCalibrated=true;
printf("Loaded time calibration for FA %s\n", file_name);
return NLines;
} else {
fFATimeCalibrated=false;
printf("Error: Error while loading FA time calibration %s\n", file_name);
return -1;
}
}
//____________________________________________________
int NWReader::LoadFATimePulseHeightCorrection(const char * file_name)
{
int NLines=fFATimeCalibration->LoadPulseHeightCorrection(file_name);
if(NLines>0) {
fFATimeCalibrated=true;
printf("Loaded time pulse height correction for FA %s\n", file_name);
return NLines;
} else {
fFATimeCalibrated=false;
printf("Error: Error while loading FA time calibration %s\n", file_name);
return -1;
}
}
//____________________________________________________
double NWReader::GetNWAXcm(int num_bar, double tleft, double tright) const
{
return fNWAPositionCalibrated ? fNWAPositionCalibration->GetPosition(num_bar, tleft, tright) : -9999;
}
//____________________________________________________
double NWReader::GetNWBXcm(int num_bar, double tleft, double tright) const
{
return fNWBPositionCalibrated ? fNWBPositionCalibration->GetPosition(num_bar, tleft, tright) : -9999;
}
//____________________________________________________
double NWReader::GetNWACosmicCenter(int num_bar) const
{
return fNWACosmicRayPositionLoaded ? fNWBCosmicRayInfo->GetCosmicRayCenter(num_bar) : -9999;
}
//____________________________________________________
double NWReader::GetNWACosmicStartingPoint(int num_bar) const
{
return fNWACosmicRayPositionLoaded ? fNWBCosmicRayInfo->GetCosmicRayStartingPoint(num_bar) : -9999;
}
//____________________________________________________
double NWReader::GetNWBCosmicCenter(int num_bar) const
{
return fNWBCosmicRayPositionLoaded ? fNWBCosmicRayInfo->GetCosmicRayCenter(num_bar) : -9999;
}
//____________________________________________________
double NWReader::GetNWBCosmicStartingPoint(int num_bar) const
{
return fNWBCosmicRayPositionLoaded ? fNWBCosmicRayInfo->GetCosmicRayStartingPoint(num_bar) : -9999;
}
//____________________________________________________
double NWReader::GetNWATimeMean(int num_bar, double tleft, double tright) const
{
return fNWATimeCalibrated ? 0.5*(tleft+tright)-fNWATimeCalibration->GetTimeOffset(num_bar) : -9999;
}
//____________________________________________________
double NWReader::GetNWBTimeMean(int num_bar, double tleft, double tright) const
{
return fNWBTimeCalibrated ? 0.5*(tleft+tright)-fNWBTimeCalibration->GetTimeOffset(num_bar) : -9999;
}
//____________________________________________________
double NWReader::GetFATimeOffset(int num_det) const
{
return fFATimeCalibrated ? fFATimeCalibration->GetTimeOffset(num_det) : 0;
}
//____________________________________________________
double NWReader::GetNWATheta(int num_bar, double Xcm) const
{
return fNWAGeometryCalibrated ? fNWAGeometry->GetTheta(num_bar, Xcm) : -9999;
}
//____________________________________________________
double NWReader::GetNWAPhi(int num_bar, double Xcm) const
{
return fNWAGeometryCalibrated ? fNWAGeometry->GetPhi(num_bar, Xcm) : -9999;
}
//____________________________________________________
double NWReader::GetNWAThetaRan(int num_bar, double Xcm) const
{
return fNWAGeometryCalibrated ? fNWAGeometry->GetThetaRan(num_bar, Xcm) : -9999;
}
//____________________________________________________
double NWReader::GetNWAPhiRan(int num_bar, double Xcm) const
{
return fNWAGeometryCalibrated ? fNWAGeometry->GetPhiRan(num_bar, Xcm) : -9999;
}
//____________________________________________________
double NWReader::GetNWADistance(int num_bar, double Xcm) const
{
return fNWAGeometryCalibrated ? fNWAGeometry->GetR(num_bar, Xcm) : -9999;
}
//____________________________________________________
double NWReader::GetNWADistanceRan(int num_bar, double Xcm) const
{
return fNWAGeometryCalibrated ? fNWAGeometry->GetRRan(num_bar, Xcm) : -9999;
}
//____________________________________________________
double NWReader::GetNWBTheta(int num_bar, double Xcm) const
{
return fNWBGeometryCalibrated ? fNWBGeometry->GetTheta(num_bar, Xcm) : -9999;
}
//____________________________________________________
double NWReader::GetNWBPhi(int num_bar, double Xcm) const
{
return fNWBGeometryCalibrated ? fNWBGeometry->GetPhi(num_bar, Xcm) : -9999;
}
//____________________________________________________
double NWReader::GetNWBThetaRan(int num_bar, double Xcm) const
{
return fNWBGeometryCalibrated ? fNWBGeometry->GetThetaRan(num_bar, Xcm) : -9999;
}
//____________________________________________________
double NWReader::GetNWBPhiRan(int num_bar, double Xcm) const
{
return fNWBGeometryCalibrated ? fNWBGeometry->GetPhiRan(num_bar, Xcm) : -9999;
}
//____________________________________________________
double NWReader::GetNWBDistance(int num_bar, double Xcm) const
{
return fNWBGeometryCalibrated ? fNWBGeometry->GetR(num_bar, Xcm) : -9999;
}
//____________________________________________________
double NWReader::GetNWBDistanceRan(int num_bar, double Xcm) const
{
return fNWBGeometryCalibrated ? fNWBGeometry->GetRRan(num_bar, Xcm) : -9999;
}
//____________________________________________________
double NWReader::GetFATimePulseHeightCorrection(int num_det, double pulse_height) const
{
return fFATimeCalibrated ? fFATimeCalibration->GetTimePulseHeightCorrection(num_det, pulse_height) : 0;
}
//____________________________________________________
void NWReader::Loop(const char * file_name, Long64_t evt_amount)
{
// this method loops on the first "evt_amount" data entries
// and creates a ROOT otput file named "file_name"
// where the user can write some ROOT output
TFile * FileOut = new TFile(file_name, "RECREATE");
Long64_t nentries=fChain->GetEntries();
if(evt_amount!=0) {
nentries=evt_amount;
}
Long64_t jentry=0;
std::cout << "found " << nentries << " entries\n";
for(;fNWReader->Next() && jentry<nentries; jentry++)
{
if(jentry%100000==0) {
printf("Percentage = %.2f %%\n", 100*double(jentry)/nentries);
}
if (fIsNWA) {
NeutronWallCalibratedData * NWA = fNWACal->Get();
//Insert NWA code here
}
if (fIsNWB) {
NeutronWallCalibratedData * NWB = fNWBCal->Get();
//Insert NWB code here
}
if (fIsFA) {
HTForwardArrayData * ForwardArray = fForwardArray->Get();
//Insert ForwardArray code here
}
if (fIsVW) {
HTVetoWallData * VetoWall = fVetoWall->Get();
//Insert VetoWall code here
}
jentry++;
}
// closing output file
FileOut->Close();
}
//____________________________________________________
void NWReader::LoopOnCalibratedData(const char * file_name, Long64_t evt_amount)
{
// this method loops on the first "evt_amount" data entries
// and creates a ROOT otput file named "file_name"
// where the user can write some ROOT output
TFile * FileOut = new TFile(file_name, "RECREATE");
Long64_t nentries=fChain->GetEntries();
if(evt_amount!=0) {
nentries=evt_amount;
}
Long64_t jentry=0;
std::cout << "found " << nentries << " entries\n";
for(;fNWReader->Next() && jentry<nentries; jentry++)
{
if(jentry%100000==0) {
printf("Percentage = %.2f %%\n", 100*double(jentry)/nentries);
}
if (fIsNWA) {
NeutronWallCalibratedData * NWA = fNWACal->Get();
//Insert NWA code here
}
if (fIsNWB) {
NeutronWallCalibratedData * NWB = fNWBCal->Get();
//Insert NWB code here
}
if (fIsFA) {
ForwardArrayCalibratedData * ForwardArray = fForwardArrayCal->Get();
//Insert ForwardArray code here
}
if (fIsVW) {
VetoWallCalibratedData * VetoWall = fVetoWallCal->Get();
//Insert VetoWall code here
}
// Insert here code
jentry++;
}
// closing output file
FileOut->Close();
}