-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConstructGG.C
388 lines (319 loc) · 12.7 KB
/
ConstructGG.C
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
#include<vector>
#include <string>
#include "TH2D.h"
#include "TTreeReader.h"
#include "TTreeReaderValue.h"
#include "TTreeReaderArray.h"
#include "TFileCollection.h"
#include "TCollection.h"
#include "TChain.h"
#include "TROOT.h"
#include "THashList.h"
#include "TThread.h"
#include "TFile.h"
#include "THnSparse.h"
#include "./TXPConfig.h"
// Global Variables for this file
static long long int TotalEntries;
static long long int PartialEntries;
static bool GO = true;
// TODO: Move progress related functions/operations to progressThread
// and rename progressThread to TProgressViewer
static void* UpdateProgress(void *ptr)
{
while( GO == true )
{
// Thread safe printing with global mutex
TThread::Lock();
printf("\rProgress %.2f%%, %.1f of %.1f",
100*PartialEntries/(double)TotalEntries,
(double) PartialEntries,
(double) TotalEntries);
TThread::UnLock();
gSystem->Sleep(20);
}
return NULL;
}
// Timing functions
static int16_t ggBTLow = 500; // *10ns
static int16_t ggBTHigh = 2500;
static int16_t ggTLow = 0; // *10ns
static int16_t ggTHigh = 150;
static bool isTimeRandom( int16_t &Time1, int16_t &Time2 )
{
return abs(Time1 - Time2) > ggBTLow && abs(Time1 - Time2) < ggBTHigh ;
}
static bool isTimePrompt( int16_t &Time1, int16_t &Time2 )
{
return abs(Time1 - Time2) > ggTLow && abs(Time1 - Time2) < ggTHigh ;
}
static TList* TimingCoincidence( TFileCollection* fc )
{
// Load Experimental Config
TXPConfig* XPConfig = new TXPConfig("./XPConfig.txt", "./XPConfigs/XPGeometry.txt" );
// Start progress bar
printf("\rProgress %.2f%%, %.1f of %.1f",
100*PartialEntries/(double)TotalEntries,
(double) PartialEntries,
(double) TotalEntries);
TThread *t1 = new TThread("t1", UpdateProgress, NULL);
t1->Run();
printf("Loading TTree's into TChain...\n");
// Load Lst2RootTree's into a TChain
TChain* pChain = new TChain("Lst2RootTree");
pChain->AddFileInfoList( fc->GetList() );
// Load events TTree into TTreeReader:
// The data types used are taken from the code used to produce
// the original trees.
TTreeReader TreeR(pChain);
TotalEntries = TreeR.GetEntries(true);
TTreeReaderArray<int32_t> energy(TreeR, "energy");
TTreeReaderArray<int16_t> adc(TreeR, "adc");
TTreeReaderArray<int16_t> timeStamp(TreeR, "timeStamp");
TTreeReaderValue<int> multiplicity(TreeR, "multiplicity");
// Setup histograms for export
TList* outList = new TList();
// Make Matricies here (1 keV/bin)
TH2D* ggMatPrompt = new TH2D("ggMatPrompt", "Prompt #gamma-#gamma Coincidence",
10000, 0, 10000,
10000, 0, 10000);
TH2D* ggMatRand = new TH2D("ggMatRand", "Random #gamma-#gamma Coincidence",
10000, 0, 10000,
10000, 0, 10000);
TH2D* ggBS = new TH2D("ggBS", "#gamma-#gamma Coincidence Background Subtracted",
10000, 0, 10000,
10000, 0, 10000);
outList->Add(ggMatPrompt);
outList->Add(ggMatRand);
outList->Add(ggBS);
// Time histograms
TH1D* ggTimeDiff = new TH1D("ggTimeDiff", "#gamma-#gamma time difference",
511, 0, 4095);
TH1D* ggTimeDiffBGO = new TH1D("ggTimeDiffBGO", "#gamma-#gamma time difference involving BGO",
511, 0, 4095);
TH1D* ggTimeDiffHPGe = new TH1D("ggTimeDiffHPGe", "#gamma-#gamma time difference of other detectors",
511, 0, 4095);
outList->Add(ggTimeDiff);
outList->Add(ggTimeDiffBGO);
outList->Add(ggTimeDiffHPGe);
// Plot the histogram that shows the size of the event packets
TH1D* hEvntPacketSize = new TH1D("hEvntPacketSize",
"#gamma-#gamma multiplicity of events",
200, 0, 200);
TH1D* hAddbackEvntPacketSize = new TH1D("hAddbackEvntPacketSize",
"Addback #gamma-#gamma multiplicity of events",
15, 0, 15);
outList->Add(hEvntPacketSize);
outList->Add(hAddbackEvntPacketSize);
// Addback matricies
TH2D* ggMatPromptAddback = new TH2D("ggMatPromptAddback", "Addback Prompt #gamma-#gamma Coincidence",
10000, 0, 10000,
10000, 0, 10000);
TH2D* ggMatRandAddback = new TH2D("ggMatRandAddback", "Addback Random #gamma-#gamma Coincidence",
10000, 0, 10000,
10000, 0, 10000);
TH2D* aaBS = new TH2D("aaBS", "Addback #gamma-#gamma Coincidence Background Subtracted",
10000, 0, 10000,
10000, 0, 10000);
outList->Add(ggMatPromptAddback);
outList->Add(ggMatRandAddback);
outList->Add(aaBS);
// Opposite Addback matricies
TH2D* ggMatPromptAddOpp = new TH2D("ggMatPromptAddOpp", "Addback Prompt #gamma-#gamma Coincidence Opposite Detectors",
10000, 0, 10000,
10000, 0, 10000);
TH2D* ggMatRandAddOpp = new TH2D("ggMatRandAddOpp", "Addback Random #gamma-#gamma Coincidence Opposite Detectors",
10000, 0, 10000,
10000, 0, 10000);
TH2D* ggBSAddOpp = new TH2D("ggBSAddOpp", "Addback #gamma-#gamma Coincidence Opposite Detectors Background Subtracted",
10000, 0, 10000,
10000, 0, 10000);
outList->Add(ggMatPromptAddOpp);
outList->Add(ggMatRandAddOpp);
outList->Add(ggBSAddOpp);
TH1D* ggTimeDiffAddback = new TH1D("ggTimeDiffAddback", "Addback #gamma-#gamma time difference",
511, 0, 4095);
outList->Add(ggTimeDiffAddback);
int eventMulti;
EvntPacket::Addback* AddbackPkt;
printf("Starting Analysis...\n");
// Parse through TTree
while ( TreeR.Next() )
{
eventMulti = *multiplicity;
hEvntPacketSize->Fill(eventMulti);
// Avoid race conditions with mutexs (necessary? TODO)
//while(TThread::TryLock()) {}
PartialEntries++;
//TThread::UnLock();
// No single events
if( eventMulti == 1 ) // if == 1 skip
continue;
// fill group of events if not vito
// ie, no BGO hits in event packet
for( int i = 0; i < eventMulti; i++ )
for( int j = i+1; j < eventMulti; j++ )
{
// No coincidence with underflow or overflow
if( energy[i] < 2 || energy[j] < 2 )
continue;
if( energy[i] > 32760 || energy[j] > 32760 )
continue;
if( XPConfig->isBGO( adc[i] ) || XPConfig->isBGO( adc[j] ) )
ggTimeDiffBGO->Fill( abs(timeStamp[i] - timeStamp[j] ) );
else
ggTimeDiffHPGe->Fill( abs(timeStamp[i] - timeStamp[j] ) );
// Vito detectors
if( XPConfig->isVito( adc[i] ) || XPConfig->isVito( adc[j] ) )
continue;
ggTimeDiff->Fill( abs(timeStamp[i] - timeStamp[j]) );
if ( isTimeRandom( timeStamp[i], timeStamp[j] ) )
ggMatRand->Fill( XPConfig->GetEnergy( energy[i], adc[i] ),
XPConfig->GetEnergy( energy[j], adc[j] ));
if ( isTimePrompt( timeStamp[i], timeStamp[j] ) )
{
ggMatPrompt->Fill( XPConfig->GetEnergy( energy[i], adc[i] ),
XPConfig->GetEnergy( energy[j], adc[j] ));
}
}
AddbackPkt = XPConfig->Leaf2Addback( energy, adc, timeStamp, eventMulti );
hAddbackEvntPacketSize->Fill( AddbackPkt->multiplicity );
for( int i = 0; i < AddbackPkt->multiplicity; i++ )
{
for( int j = i+1; j < AddbackPkt->multiplicity; j++)
{
if( AddbackPkt->isCompton[i] || AddbackPkt->isCompton[j] )
continue; // skip over events marked as compton
// fill time diff
ggTimeDiffAddback->Fill( abs(
AddbackPkt->timeStamp[i] - AddbackPkt->timeStamp[j]) );
// construct time random
if( isTimeRandom( AddbackPkt->timeStamp[i], AddbackPkt->timeStamp[j] ) )
{
ggMatRandAddback->Fill( AddbackPkt->Energy[i], AddbackPkt->Energy[j] );
if( XPConfig->GetAngleDetec( AddbackPkt->detectorNum[i],
AddbackPkt->detectorNum[j] ) )
ggMatRandAddOpp->Fill( AddbackPkt->Energy[i], AddbackPkt->Energy[j] );
}
// construct prompt
if( isTimePrompt( AddbackPkt->timeStamp[i], AddbackPkt->timeStamp[j] ) )
{
ggMatPromptAddback->Fill( AddbackPkt->Energy[i], AddbackPkt->Energy[j] );
if( XPConfig->GetAngleDetec( AddbackPkt->detectorNum[i],
AddbackPkt->detectorNum[j] ) )
ggMatPromptAddOpp->Fill( AddbackPkt->Energy[i], AddbackPkt->Energy[j] );
}
}
}
delete AddbackPkt;
}
// Stop thread that displays progress and print final progress
GO = false;
printf("\rProgress %.2f%%, %.1f of %.1f\n",
100*PartialEntries/(double)TotalEntries,
(double) PartialEntries,
(double) TotalEntries);
// Construct background subtracted gg matrix
ggBS->Add(ggMatPrompt);
ggBS->Add(ggMatRand, -abs(ggTHigh-ggTLow)/abs(ggBTHigh-ggBTLow));
aaBS->Add(ggMatPromptAddback);
aaBS->Add(ggMatRandAddback, -abs(ggTHigh-ggTLow)/abs(ggBTHigh-ggBTLow));
ggBSAddOpp->Add(ggMatPromptAddOpp);
ggBSAddOpp->Add(ggMatRandAddOpp, -abs(ggTHigh-ggTLow)/abs(ggBTHigh-ggBTLow));
// Cleanup
delete XPConfig;
delete pChain;
return outList;
}
TH2D* ConstructGG( TFileCollection* fc )
{
TXPConfig* XPConfig = new TXPConfig("./XPConfig.txt");
printf("Progress %.2f%%, %lld of %lld",
100*PartialEntries/(double)TotalEntries,
PartialEntries,
TotalEntries);
TThread *t1 = new TThread("t1", UpdateProgress, NULL);
t1->Run();
// Load Lst2RootTree's into chain and reader
TChain* pChain = new TChain("Lst2RootTree");
pChain->AddFileInfoList( fc->GetList() );
// Event Parameters
TTreeReader TreeR(pChain);
TotalEntries = TreeR.GetEntries(true);
TTreeReaderArray<int32_t> energy(TreeR, "energy");
TTreeReaderArray<int16_t> adc(TreeR, "adc");
TTreeReaderArray<int16_t> timeStamp(TreeR, "timeStamp");
TTreeReaderValue<int> multiplicity(TreeR, "multiplicity");
TH2D* ggMat = new TH2D("ggMat", "Gamma Gamma Coincidence",
8191, 0, 12000,
8191, 0, 12000);
bool vito = false;
int eventMulti;
// Begin gg construction
while ( TreeR.Next() ) {
// Reset for next group
vito = false;
eventMulti = *multiplicity;
//while(TThread::TryLock()) {}
PartialEntries++;
//TThread::UnLock();
//** Descriminators **//
if( eventMulti == 1 ) // if == 1 skip
continue;
for( int i = 0; i < eventMulti; i++ )
{
if( XPConfig->isVito( adc[i] ) )
vito = true;
}
for( int i = 0; i < eventMulti; i++ )
{
if( energy[i] < 2 )
vito = true;
}
// fill results if valid
if( !vito )
for( int i = 0; i < eventMulti; i++ )
for( int j = i+1; j < eventMulti; j++ )
// if result is weird, vito it
// otherwise populate ggMat
ggMat->Fill( XPConfig->GetEnergy( energy[i], adc[i] ),
XPConfig->GetEnergy( energy[j], adc[j] ));
}
GO = false;
printf("\rProgress %.2f%%, %lld of %lld\n",
100*PartialEntries/(double)TotalEntries,
PartialEntries,
TotalEntries);
delete XPConfig;
delete pChain;
return ggMat;
}
TH2D* ConstructGG( std::string TFileList )
{
TFileCollection* fc = new TFileCollection( "RootFileList", "", TFileList.c_str() );
return ConstructGG( fc );
}
TList* TimingCoincidence( std::string TFileList )
{
TFileCollection* fc = new TFileCollection( "RootFileList", "", TFileList.c_str() );
return TimingCoincidence( fc );
}
int TimingCoincidence2File( std::string TFileList, std::string OutputFile )
{
TFile* outfile = new TFile( OutputFile.c_str() , "recreate");
TList* outlist = TimingCoincidence( TFileList );
printf("Writing to file %s\n", OutputFile.c_str());
outlist->Write();
printf("Closing file...\n");
outfile->Close();
return 0;
}
/*
TH2D* ConstructGGParallel( std::string TFileList )
{
TFileCollection* fc = new TFileCollection( "RootFileList", "", TFileList.c_str() );
ROOT::EnableThreadSafety();
ROOT::MakeThreaded<TH2F> ParHisto("ParHisto", "#gamma-#gamma",
8191, 0, 12000, 8191, 0, 12000);
ROOT::TTreeProcessor
*/