-
Notifications
You must be signed in to change notification settings - Fork 0
/
hotspotposition.C
146 lines (126 loc) · 4.01 KB
/
hotspotposition.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
#include <TCanvas.h>
#include <TRandom.h>
#include <TEllipse.h>
#include <TProfile.h>
#include <TLegend.h>
#include <TLatex.h>
#include <TStyle.h>
#include <TAxis.h>
#include <TPad.h>
#include <TEllipse.h>
#include <TText.h>
#include <TMarker.h>
#include <TROOT.h>
#include <TStyle.h>
#include <TH1F.h>
#include <TH2F.h>
#include <TCanvas.h>
#include <TGraphErrors.h>
#include <TGraphAsymmErrors.h>
#include <TF1.h>
#include <TLegend.h>
#include <TLine.h>
#include <TRandom3.h>
#include <TNtuple.h>
#include <TFile.h>
#include <display/Histogram.hh>
#include <display/SkyHistogram2D.hh>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <map>
#include <vector>
#include <fstream>
int FindSpot(TH2F* SigMap,float SigMin,float RegionSize, float vpx[1000], float vpy[1000], float vxmax[1000]) {
int nbspot=0;
int MapSizeX=SigMap->GetNbinsX();
int MapSizeY=SigMap->GetNbinsY();
double BinSizeX = (SigMap->GetXaxis()->GetXmax() - SigMap->GetXaxis()->GetXmin())/SigMap->GetXaxis()->GetNbins();
double BinSizeY = (SigMap->GetYaxis()->GetXmax() - SigMap->GetYaxis()->GetXmin())/SigMap->GetYaxis()->GetNbins();
int RegionSizeX = ceil(RegionSize/BinSizeX);
int RegionSizeY = ceil(RegionSize/BinSizeY);
int posx,posy,posz;
double Max=0;
while((SigMap->GetMaximum()>SigMin) && (nbspot<1000))
{
SigMap->GetMaximumBin(posx,posy,posz);
float COGx=0;
float COGy=0;
float weight=0;
for (int x=posx-RegionSizeX; x<posx+RegionSizeY+1; x++)
{
if((x<MapSizeX)&&(x>0))
{
for (int y=posy-RegionSizeY; y<posy+RegionSizeY+1; y++)
{
if((y<MapSizeY)&&(y>0))
{
if (((x-posx)*(x-posx)*BinSizeX*BinSizeX + (y-posy)*(y-posy)*BinSizeY*BinSizeY) < RegionSize*RegionSize)
{
COGx+=x*SigMap->GetBinContent(x,y);
COGy+=y*SigMap->GetBinContent(x,y);
weight+=SigMap->GetBinContent(x,y);
if (Max<SigMap->GetBinContent(x,y)){ Max =SigMap->GetBinContent(x,y); }
}
}
}
}
}
posx=floor(COGx/weight);
posy=floor(COGy/weight);
// pos = numero du bin
// vp = coordonnées RA/Dec en degrees
vpx[nbspot]=SigMap->GetXaxis()->GetBinCenter(posx);
vpy[nbspot]=SigMap->GetYaxis()->GetBinCenter(posy);
vxmax[nbspot]=Max;
Max = 0.;
//std::cout << "HOT SPOT " << nbspot+1 << " " << SigMap->GetXaxis()->GetBinCenter(posx) <<" "<<SigMap->GetYaxis()->GetBinCenter(posy) << std::endl;
for (int x=posx-RegionSizeX; x<posx+RegionSizeY+1; x++)
{
if((x<MapSizeX) && (x>0))
{
for (int y=posy-RegionSizeY; y<posy+RegionSizeY+1; y++)
{
if((y<MapSizeY) && (y>0))
if (((x-posx)*(x-posx)*BinSizeX*BinSizeX + (y-posy)*(y-posy)*BinSizeY*BinSizeY) < RegionSize*RegionSize)
{
SigMap->SetBinContent(x,y,0);
}
}
}
}
nbspot++;
if (nbspot==999)
{
cerr << "Warning Maximum sources !!!!!!" << endl;
}
}
return nbspot;
}
void hotspotposition(const char* Prefix ,double MinSig = 4.5,bool SignMap = 1)
{
std::ostringstream MapFile;
Display::SkyHistogram2D *hSig;
if (SignMap) {
MapFile << Prefix<< "_roundup_RingBgMaps.root";
TFile *rootfile_All = TFile::Open(MapFile.str().c_str());
hSig = (Display::SkyHistogram2D *)rootfile_All->Get("SignificanceMap");
}
else {
MapFile << Prefix<< "_roundup_ONOFFTestMaps.root";
TFile *rootfile_All = TFile::Open(MapFile.str().c_str());
hSig = (Display::SkyHistogram2D *)rootfile_All->Get("ONOFFTest");
}
float vpx[1000];
float vpy[1000];
float vmax[1000];
TH2F *SpotMap = new TH2F(*hSig);
int nbspot = FindSpot(SpotMap,MinSig,0.5,vpx,vpy,vmax);
std::cout << MapFile.str().c_str()<< std::endl;
for (int i=0;i<nbspot;i++)
{
std::cout << " " << i+1 << " " << -vpx[i] << " " << vpy[i] <<" Max Sig "<<vmax[i]<< std::endl;
}
if (nbspot==0) std::cout << "No Hot spot found at "<<MinSig<<" sigma, Observe More! "<<std::endl;
}