-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscanner.cc
More file actions
404 lines (327 loc) · 11.6 KB
/
Copy pathscanner.cc
File metadata and controls
404 lines (327 loc) · 11.6 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
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
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <algorithm>
#include "agntools.h"
#include "scanner.h"
#include "userfcn.h"
// ROOT
#include "TRint.h"
#include "TROOT.h"
#include "TStopwatch.h"
#include "TMath.h"
using namespace std;
static TProgressBar gProgS;
static TStopwatch gTimerS;
TScanner::TScanner(const vector<TEvent> & events, const vector<TAgn> & sources, const THealpixMap & cMap)
{
fEvents = events;
fNevents = fEvents.size();
fAGNs = sources;
fCovMap = cMap;
Init();
}
void TScanner::Init()
{
// Related to coverage map
fNbPix = fCovMap.size();
vector<long> ip;
for(unsigned int i = 0; i < fNbPix-1; i++) ip.push_back(i);
fCovMap.GiveLB(ip, fLpix, fBpix);
ip.clear();
// Related to the the scan
fMinBigP = 1.;
fEminAtMin = 0.;
fZmaxAtMin = 0.;
fPsiMaxAtMin = 0.;
fLittlePAtMin = 0.;
fLittleKAtMin = 0;
fBigNAtMin = 0;
cout << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl;
cout << " New TScanner Initialized " <<endl;
cout << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl;
}
double TScanner::littleP(double zMaxPar, double psiMaxPar)
{
cout << "Computing the probability that a CR isotropically distributed falls within " << psiMaxPar << " deg of an AGN with z < " << zMaxPar << endl;
gProgS.Zero();
gProgS.fBegin = 0;
gProgS.fEnd = fNbPix;
gProgS.InitPercent();
gTimerS.Start();
int stepNum = 0;
double lp = 0.;
for(unsigned int nPix = 0; nPix < fNbPix; nPix++)
{
if(fCovMap[nPix] > 0.) lp += fCovMap[nPix] * IsSourceNearTest(fLpix[nPix], fBpix[nPix], zMaxPar, psiMaxPar);
stepNum++;
gProgS.PrintPercent(stepNum);
}
gProgS.EndPercent();
gTimerS.Stop();
gTimerS.Print();
return lp;
}
int TScanner::littleK(double zMaxPar, double psiMaxPar, double eMinPar)
{
int lk = 0;
for(unsigned int nEvt = 0; nEvt < fNevents; nEvt++)
if(fEvents[nEvt].fEnergy >= eMinPar) lk += IsSourceNearTest(fEvents[nEvt].fL, fEvents[nEvt].fB, zMaxPar, psiMaxPar);
return lk;
}
int TScanner::bigN(double eMinPar)
{
int lk = 0;
for(unsigned int nEvt = 0 ; nEvt < fNevents; nEvt++)
{
double energy = fEvents[nEvt].fEnergy;
if(energy >= eMinPar) lk++;
}
return lk;
}
// Public TScanner Members
void TScanner::SetRangeEnergy(double eMin, double eMax)
{
bool grt2lst = true;
vector<TEvent> eventsSorted = SortCutEnergy(fEvents, grt2lst, eMin, eMax);
fEvents.resize(eventsSorted.size());
for(unsigned int i = 0; i < eventsSorted.size(); i++) fEvents[i] = eventsSorted[i];
fNevents = fEvents.size();
fEmax = fEvents[0].fEnergy;
fEmin = fEvents[fNevents-1].fEnergy;
eventsSorted.clear();
}
void TScanner::SetRangeRedshift(double zMin, double zMax, double zStep)
{
bool grt2lst = false;
vector<TAgn> AGNsorted = SortCutRedShift(fAGNs, grt2lst, zMin, zMax);
fAGNs.resize(AGNsorted.size());
for(unsigned int i = 0; i < AGNsorted.size(); i++) fAGNs[i] = AGNsorted[i];
fNagn = fAGNs.size();
fZmin = zMin;
fZmax = zMax;
fZstep = zStep;
double zMinTmp = fZmin;
while( zMinTmp <= fZmax )
{
zMinTmp += fZstep;
fZmins.push_back(zMinTmp);
}
fNzStep = fZmins.size();
}
void TScanner::SetRangeAngle(double psiMin, double psiMax, double psiStep)
{
fPsiMin = psiMin;
fPsiMax = psiMax;
fPsiStep = psiStep;
double psiMinTmp = fPsiMin;
while( psiMinTmp <= psiMax )
{
psiMinTmp += fPsiStep;
fPsis.push_back(psiMinTmp);
}
fNpsi = fPsis.size();
}
void TScanner::PrintRanges()
{
printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
printf(" Scan Ranges \n");
printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
printf("%3d events :: %2.3f <= E/EeV <= %2.3f :: %3d steps\n", fNevents, fEmin, fEmax, fNevents);
printf(" %3d AGN :: %1.3f <= Z <= %1.3f :: %3d steps of dZ = %1.3f\n", fNagn, fZmin, fZmax, fNzStep, fZstep);
printf("%3d steps :: %1.3f <= Psi <= %1.3f :: %3d steps of dPsi = %1.3f\n", fNpsi, fPsiMin, fPsiMax, fNpsi, fPsiStep);
printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
}
void TScanner::SetScanResults(double eMinAtMin, double zMaxAtMin, double psiMaxAtMin, double &minBigP, double &littlePAtMin, int &littleKAtMin, int &bigNAtMin)
{
fEminAtMin = eMinAtMin;
fZmaxAtMin = zMaxAtMin;
fPsiMaxAtMin = psiMaxAtMin;
fLittlePAtMin = littleP(fZmaxAtMin, fPsiMaxAtMin); //LittlePAtMin;
fLittleKAtMin = littleK(fZmaxAtMin, fPsiMaxAtMin, fEminAtMin); // LittleKAtMin;
fBigNAtMin = bigN(fEminAtMin); // BigNAtMin;
fMinBigP = bigP(fBigNAtMin, fLittleKAtMin, fLittlePAtMin); // MinBigP;
printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
printf(" Set Scan Results \n");
printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
printf(" big-P | Emin | Zmax | Psimax | little-p | k | N \n");
printf("------------------------------------------------------------\n");
printf(" %1.3e | %2.2f | %1.3f | %2.3f | %2.2f | %2d | %2d \n", fMinBigP, fEminAtMin, fZmaxAtMin, fPsiMaxAtMin, fLittlePAtMin, fLittleKAtMin, fBigNAtMin);
printf("------------------------------------------------------------\n");
littlePAtMin = fLittlePAtMin;
littleKAtMin = fLittleKAtMin;
bigNAtMin = fBigNAtMin;
minBigP = fMinBigP;
}
void TScanner::PerformScan(bool timerOn)
{
fMinBigP = 1.0;
unsigned int TotNumSteps = fNevents*fNzStep*fNpsi;
if(timerOn == true)
{
cout << " Perfroming scan ... " << endl;
gProgS.Zero();
gProgS.fBegin = 0;
gProgS.fEnd = TotNumSteps;
gProgS.InitPercent();
gTimerS.Start();
}
int stepNum = 0;
for(unsigned int SrcN = 0; SrcN < fNzStep; SrcN++)
{
for(unsigned int PsiN = 0; PsiN < fNpsi; PsiN++)
{
double lP = littleP(fZmins[SrcN], fPsis[PsiN]);
for(unsigned int EvN = 0; EvN < fNevents; EvN++)
{
int lK = littleK(fZmins[SrcN], fPsis[PsiN], fEvents[EvN].fEnergy);
double bP = bigP(EvN+1, lK, lP);
if(bP <= fMinBigP)
{
fMinBigP = bP;
fEminAtMin = fEvents[EvN].fEnergy;
fZmaxAtMin = fZmins[SrcN];
fPsiMaxAtMin = fPsis[PsiN];
fLittlePAtMin = lP;
fLittleKAtMin = lK;
fBigNAtMin = EvN+1;
}
stepNum++;
if(timerOn == true) gProgS.PrintPercent(stepNum);
}
}
}
if(timerOn == true)
{
gProgS.EndPercent();
gTimerS.Stop();
gTimerS.Print();
}
}
void TScanner::PrintScanResults(double &eMinAtMin, double &zMaxAtMin, double &psiMaxAtMin, double &minBigP, double &littlePAtMin, int &littleKAtMin, int &bigNAtMin)
{
minBigP = fMinBigP;
eMinAtMin = fEminAtMin;
zMaxAtMin = fZmaxAtMin;
psiMaxAtMin = fPsiMaxAtMin;
littlePAtMin = fLittlePAtMin;
littleKAtMin = fLittleKAtMin;
bigNAtMin = fBigNAtMin;
printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
printf(" Scan Results \n");
printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
printf(" big-P | Emin | Zmax | Psimax | little-p | k | N \n");
printf("------------------------------------------------------------\n");
printf(" %1.3e | %2.2f | %1.3f | %2.3f | %2.2f | %2d | %2d \n", fMinBigP, fEminAtMin, fZmaxAtMin, fPsiMaxAtMin, fLittlePAtMin, fLittleKAtMin, fBigNAtMin);
printf("------------------------------------------------------------\n");
}
vector<TEvent> TScanner::GetEventsThatCorrelate()
{
vector<TEvent> eventsThatCorrelate;
for(unsigned int i = 0; i < fNevents; i++)
{
if(fEvents[i].fEnergy >= fEminAtMin)
{
int isNear = IsSourceNearTest(fEvents[i].fL, fEvents[i].fB, fZmaxAtMin, fPsiMaxAtMin);
if(isNear == 1) eventsThatCorrelate.push_back(fEvents[i]);
}
}
return eventsThatCorrelate;
}
vector<TEvent> TScanner::GetEventsThatDoNotCorrelate()
{
vector<TEvent> eventsThatDoNotCorrelate;
for(unsigned int i=0; i<fNevents; i++)
{
if(fEvents[i].fEnergy >= fEminAtMin)
{
int isNear = IsSourceNearTest(fEvents[i].fL, fEvents[i].fB, fZmaxAtMin, fPsiMaxAtMin);
if(isNear == 0) eventsThatDoNotCorrelate.push_back(fEvents[i]);
}
}
return eventsThatDoNotCorrelate;
}
vector<TAgn> TScanner::SourcesCloserZmax()
{
vector<double> lSources, bSources;
for(unsigned int i = 0; i < fNagn; i++)
{
lSources.push_back(fAGNs[i].fL);
bSources.push_back(fAGNs[i].fB);
}
vector<double> cMapValAtAGNs = fCovMap.Values(lSources, bSources);
vector<TAgn> AGNs;
for(unsigned int i = 0; i < fNagn; i++)
{
bool keep = (fAGNs[i].fZ <= fZmaxAtMin) && (cMapValAtAGNs[i] > 0.);
if( keep ) AGNs.push_back(fAGNs[i]);
}
return AGNs;
}
void TScanner::PrintEventsAndNearAGN()
{
cout << "-----------------------------------------------------------------------" << endl;
cout << " EventsID | E/EeV | galL | galB || Psi | Z | Type" << endl;
cout << "-----------------------------------------------------------------------" << endl;
for(unsigned int nEvt = 0; nEvt < fNevents; nEvt++)
{
if(fEvents[nEvt].fEnergy >= fEminAtMin)
{
double minAngDist = 180.0;
unsigned int index = 0;
for(unsigned int nSources = 0; nSources < fNagn; nSources++)
{
if(fAGNs[nSources].fZ <= fZmaxAtMin)
{
double angDist = AngularDistance(fEvents[nEvt].fRa, fEvents[nEvt].fDec, fAGNs[nSources].fRa, fAGNs[nSources].fDec);
if(angDist <= minAngDist)
{
minAngDist = angDist;
index = nSources;
}
}
}
if(minAngDist <= fPsiMaxAtMin)
{
cout.precision(4);
cout << "DO CORRELATE" << endl;
cout << " " << fEvents[nEvt].fId << " | " << fEvents[nEvt].fEnergy << " | " << fEvents[nEvt].fL << " | " << fEvents[nEvt].fB << " || " << minAngDist << " | " << fAGNs[index].fZ << " | "<< fAGNs[index].fName << endl;
cout << "-----------------------------------------------------------------------" << endl;
}
else
{
cout << "DO NOT CORRELATE" << endl;
cout.precision(4);
cout << " " << fEvents[nEvt].fId << " | " << fEvents[nEvt].fEnergy << " | " << fEvents[nEvt].fL << " | " << fEvents[nEvt].fB << " || " << minAngDist << " | " << fAGNs[index].fZ << " | "<< fAGNs[index].fName << endl;
cout << "-----------------------------------------------------------------------" << endl;
}
}
}
}
int TScanner::IsSourceNearTest(double lTest, double bTest, double zMaxPar, double psiMaxPar)
{
int isNear = 0;
for(unsigned int i = 0; i < fNagn; i++)
{
if(fAGNs[i].fZ <= zMaxPar)
{
double angDist = AngularDistance(lTest, bTest, fAGNs[i].fL, fAGNs[i].fB);
if(angDist <= psiMaxPar) {isNear = 1; break;}
}
}
return isNear;
}
int TScanner::GetBigN(double eMinPar)
{
return bigN(eMinPar);
}
double TScanner::GetLittleP(double zMaxPar, double psiMaxPar)
{
return littleP(zMaxPar, psiMaxPar);
}
int TScanner::GetLittleK(double zMaxPar, double psiMaxPar, double eMinPar)
{
return littleK(zMaxPar, psiMaxPar, eMinPar);
}