-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoundUpFancyMaps.C
6391 lines (5534 loc) · 261 KB
/
RoundUpFancyMaps.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
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
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "RoundUpFancyMaps.hh"
//HESS
#include <sash/HESSArray.hh>
#include <sash/Folder.hh>
#include <sash/EnvelopeEntry.hh>
#include <sash/DataSet.hh>
#include <sash/NominalPointing.hh>
#include <sash/Time.hh>
#include <sash/TimeDiff.hh>
#include <crash/RotatedSystem.hh>
#include <utilities/Statistics.hh>
#include <utilities/Parameter.hh>
#include <utilities/TextStyle.hh>
#include <utilities/TFftConv.hh>
#include <utilities/TextStyle.hh>
#include <utilities/Flux.hh>
#include <mathutils/Fourier.hh>
#include <display/Histogram.hh>
#include <display/SkyHistogram2D.hh>
#include <parisanalysis/RunList.hh>
#include <parisanalysis/RunStat.hh>
#include <parisanalysis/Analysis2DResults.hh>
#include <parisanalysis/AnalysisConfig.hh>
#include <parisanalysis/FieldOfViewAcceptance.hh>
#include <parisanalysis/AcceptanceMap.hh>
#include <parisanalysis/DataStorageRun.hh>
#include <parisanalysis/RadialAcceptance.hh>
#include <spectrum/SpectrumTableFinderMulti.hh>
#include <spectrum/DataStorageLinearTable.hh>
#include <spectrum/AcceptanceTableEfficiency.hh>
#include <spectrum/ResolutionTableEfficiency.hh>
#include <spectrum/SpectrumBase.hh>
#include <spectrum/SpectrumPowerLaw.hh>
#include <morphology/MorphologyTableFinderMulti.hh>
#include <morphology/AngularResolutionTableEfficiency.hh>
//ROOT
#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 <TNtupleD.h>
#include <TFile.h>
#include <TDirectory.h>
#include <TRolke.h>
//STL
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <vector>
#include <string>
#include <cstdlib>
SurveySuite::MapMaker::MapMaker():
fEventsMap(0),
fAcceptanceMap(0),
fExclusionMap(0),
fExpectedCountsMap(0),
fExtendedExpectedCountsMap(0),
fExcessMap(0),
fUncorrelatedExcessMap(0),
fSignificanceMap(0),
fAlphaMap(0),
fOffMap(0),
fOffAxisMap(0),
fZenithAngleMap(0),
fMuonEfficiencyMap(0),
fMinSafeThresholdMap(0),
fAveragedSafeThresholdMap(0),
fAveragedLiveTimeMap(0)
{
}
/** Destructor */
SurveySuite::MapMaker::~MapMaker()
{
delete fEventsMap;
delete fAcceptanceMap;
delete fExclusionMap;
delete fExpectedCountsMap;
delete fExtendedExpectedCountsMap;
delete fExcessMap;
delete fUncorrelatedExcessMap;
delete fSignificanceMap;
delete fAlphaMap;
delete fOffMap;
delete fOffAxisMap;
delete fZenithAngleMap;
delete fMuonEfficiencyMap;
delete fMinSafeThresholdMap;
delete fAveragedSafeThresholdMap;
delete fAveragedLiveTimeMap;
}
void SurveySuite::MapMaker::Clear()
{
fEventsAndAcceptanceFromFile = 0;
fEventsAndAcceptanceFromRadial = 0;
fEventsAndAcceptanceFromRadialFile = 0;
fExclusionFromFits = 0;
fExclusionFromRegionFile = 0;
fUseConfigTarget = 0;
fUseConfigMapParams = 0;
fUserLambda = 0;
fUserBeta = 0;
fBinSize = 0;
fExtX = 0;
fExtY = 0;
fPsiCut = 0;
fOSRadius = 0;
fAdaptFFT = 0;
fAdaptCut_Alpha = 0;
fConstantArea = 0;
fConstantThickness = 0;
fConstantInnerRadius = 0;
fSmoothRings = 0;
fRingMinimalRadius = 0;
fInnerRingMax = 0;
fOuterRingMax = 0;
fRingStep = 0;
fRingParam_AreaOverPi = 0;
fRingParam_ExcFracMax = 0;
fRingParam_Thickness = 0;
fRingParam_AlphaMax = 0;
fStandardRingRadius = 0;
fStandardRingThickness = 0;
fAverageOff = 0;
fCorrectZenith = 0;
fEMin = 0;
fEMax = 0;
fFitAcceptance = 0;
fSelectAllRunsContributingToTheMap = 0;
fProduceFluxProducts = 0;
fSpectralIndex = 0;
fPointLikeFluxMaps = 0;
fProduceSurfaceBrightnessMap = 0;
fExposureMapsFromFits = 0;
fSaveResults = 0;
fVerbose = 0;
//Configuration flags
fConfigureOutputsFlag = 0;
fConfigureFluxProductsFlag = 0;
fConfigureRingMethodFlag = 0;
fConfigureMapsFlag = 0;
fConfigureAcceptanceFlag = 0;
fConfigureExclusionsFlag = 0;
fStartConfigureFlag = 0;
fEntriesVector.clear();
fScaleFactor.clear();
fRadialIntegrationEbin.clear();
}
/****************************************************************************************************************/
/************************************************* CONFIGURATION ************************************************/
/****************************************************************************************************************/
/**
* Starting configuration : clear everything
*/
void SurveySuite::MapMaker::StartConfigure()
{
Clear();
GetStartConfigureFlag() = true;
}
/**
* Configuration of the exclusion regions. If both parameters are false, the regions from the analysis result file will be taken.
* \param ExclusionFromFits : if true, take the specified FITS mask
* \param ExclusionFromRegionFile : if true, take circular regions from an ascii file with l, b, radius
*
*/
bool SurveySuite::MapMaker::ConfigureExclusions(bool ExclusionFromFits,
bool ExclusionFromRegionFile)
{
GetExclusionFromFits() = ExclusionFromFits;
GetExclusionFromRegionFile() = ExclusionFromRegionFile;
if(!ExclusionFromRegionFile && !ExclusionFromFits)
std::cout << "WARNING: Eclusion regions will be taken from Result File" << std::endl;
GetConfigureExclusionsFlag() = true;
return 1;
}
/**
* Configuration of the Acceptance calculation.
*
* \param EventsAndAcceptanceFromFile : if true, take events and acceptance maps from the analysis result file.
* \param EventsAndAcceptanceFromRadial : if true, (events and) acceptance maps will be computed from radial lookups.
* \param EventsAndAcceptanceFromRadialFile : if true, events and acceptance will be taken from a file previously generated from this program (radial file or ringbg maps)
* If the first three parameters are set to 0, the events and acceptance maps are assumed to be given in FITS format.
* \param PsiCut : PsiCut value to apply in case of radial acceptance computation
* \param FitAcceptance : wether the radial acceptance histogram is fitted or not
* \param CorrectZenith : apply zenith angle correction to the acceptance maps (time consuming!)
* \param SelectAllRunsContributingToTheMap : if custom source position or custom map size is used, do we select all runs contributing to the map or only those contributing to the source position.
* \param ApplySafeThreshold : Applies the safe threshold cut
* \param SafeThresholdFromAcceptance : two methods are available threshold from acceptance or from bias. If true, take threshold from acceptance, if false threshold is taken from bias
* \param SafeThresholdFromPsiCut : the threshold is computed at a given offset. If true, automatically takes compute the threshold at the offset value taken for the PsiCut
* \param SafeThresholdFromPsiValue : the threshold is computed at a given offset. The value here is to chose the offset value for the safe threshold calculation. The parameter SafeThresholdFromPsiCut should be set to false
* \param SafeThresholdRatioParam : this parameter allows to chose the percentage of the maximum acceptance or the bias value that defines the safe threshold energy cut
*
*/
bool SurveySuite::MapMaker::ConfigureAcceptance(bool EventsAndAcceptanceFromFile,
bool EventsAndAcceptanceFromRadial,
bool EventsAndAcceptanceFromRadialFile,
double PsiCut,
bool FitAcceptance,
bool CorrectZenith,
bool SelectAllRunsContributingToTheMap,
bool ApplySafeThreshold,
bool SafeThresholdFromAcceptance,
bool SafeThresholdFromPsiCut,
double SafeThresholdFromPsiValue,
double SafeThresholdRatioParam)
{
//if the next 3 values are == 0 -> Ev and Acc from FITS file!!!
GetEventsAndAcceptanceFromFile() = EventsAndAcceptanceFromFile;
GetEventsAndAcceptanceFromRadial() = EventsAndAcceptanceFromRadial;
GetEventsAndAcceptanceFromRadialFile() = EventsAndAcceptanceFromRadialFile;
GetPsiCut() = PsiCut;
GetFitAcceptance() = FitAcceptance;
GetCorrectZenith() = CorrectZenith;
GetSelectAllRunsContributingToTheMap() = SelectAllRunsContributingToTheMap;
GetApplySafeThreshold() = ApplySafeThreshold;
GetSafeThresholdFromAcceptance() = SafeThresholdFromAcceptance;
GetSafeThresholdFromPsiCut() = SafeThresholdFromPsiCut;
GetSafeThresholdFromPsiValue() = SafeThresholdFromPsiValue;
GetSafeThresholdRatioParam() = SafeThresholdRatioParam;
if(!EventsAndAcceptanceFromRadial && !EventsAndAcceptanceFromFile)
std::cout << "WARNING: Events and Acceptance maps will be taken from FITS Files" << std::endl;
if(EventsAndAcceptanceFromRadial)
if(PsiCut == 0){
std::cout << "ERROR: Events and Acceptance Map from Radial but PsiCut = 0" << std::endl;
GetConfigureAcceptanceFlag() = false;
return 0;
}
GetConfigureAcceptanceFlag() = true;
return 1;
}
/**
* Configuration of the Maps calculation.
*
* \param UseConfigTarget : if true, take target position from the analysis result file. It defines the center of the maps.
* \param UseConfigMapParams : if true, take maps parameters (bin size, extensions) from the analysis result file.
* \param UserLambda : custom Lambda.
* \param UserBeta : custom Beta.
* \param BinSize : custom BinSize.
* \param ExtX : Map extension X.
* \param ExtY : Map extension Y.
* \param OSRadius : Oversampling radius.
* \param EMin : energy min.
* \param EMax : energy max.
*
*/
bool SurveySuite::MapMaker::ConfigureMaps(bool UseConfigTarget,
bool UseConfigMapParams,
double UserLambda,
double UserBeta,
double BinSize,
double ExtX,
double ExtY,
double OSRadius,
double EMin,
double EMax)
{
GetUseConfigTarget() = UseConfigTarget;
GetUseConfigMapParams() = UseConfigMapParams;
GetUserLambda() = UserLambda;
GetUserBeta() = UserBeta;
GetBinSize() = BinSize;
GetExtX() = ExtX;
GetExtY() = ExtY;
GetOSRadius() = OSRadius;
GetEMin() = EMin;
GetEMax() = EMax;
if(!UseConfigTarget)
std::cout << "WARNING: Custom target position -> make sure Lambda and Beta are well filled" << std::endl;
if(!UseConfigMapParams)
if(ExtX == 0 || ExtY == 0){
std::cout << "ERROR: Map parameters not taken from Config but ExtX = 0 or ExtY = 0" << std::endl;
GetConfigureMapsFlag() = false;
return 0;
}
GetConfigureMapsFlag() = true;
return 1;
}
/**
* Configuration of the Ring background method.
*
* \param AdaptFFT : do we use the adaptive ring method
* In case the adaptive ring method is used, the following parameters are used :
* \param AdaptCut_Alpha : if true, cut on alpha value to stop the increase of the ring. Otherwise, cut on the fraction of excluded area.
* \param ConstantArea : rings have constant area
* \param ConstantThickness : rings have constant thickness
* \param ConstantInnerRadius : rings have constant inner radius
* \param SmoothRings : do we smooth the rings number to take in order to avoid sharp edges
* \param RingMinimalRadius : minimal radius to start with
* \param InnerRingMax : inner ring max radius
* \param OuterRingMax : outer ring max radius
* \param RingStep : size if the rings increase
* \param RingParam_AreaOverPi : defines the ring size : area divided by pi.
* \param RingParam_ExcFracMax : maximal allowed excluded fraction
* \param RingParam_Thickness : defines the ring size with the thickness
* \param RingParam_AlphaMax : maximal allowed alpha value
* In case the adaptive ring is not used :
* \param StandardRingRadius : ring radius (center)
* \param StandardRingThickness : ring thickness (ring size is ring radius +/- thickness)
* \param AverageOff
*
*/
bool SurveySuite::MapMaker::ConfigureRingMethod(bool AdaptFFT,
bool AdaptCut_Alpha,
bool ConstantArea,
bool ConstantThickness,
bool ConstantInnerRadius,
bool SmoothRings,
double RingMinimalRadius,
double InnerRingMax,
double OuterRingMax,
double RingStep,
double RingParam_AreaOverPi,
double RingParam_ExcFracMax,
double RingParam_Thickness,
double RingParam_AlphaMax,
double StandardRingRadius,
double StandardRingThickness,
bool AverageOff)
{
GetAdaptFFT() = AdaptFFT;
GetAdaptCut_Alpha() = AdaptCut_Alpha;
GetConstantArea() = ConstantArea;
GetConstantThickness() = ConstantThickness;
GetConstantInnerRadius() = ConstantInnerRadius;
GetSmoothRings() = SmoothRings;
GetRingMinimalRadius() = RingMinimalRadius;
GetInnerRingMax() = InnerRingMax;
GetOuterRingMax() = OuterRingMax;
GetRingStep() = RingStep;
GetRingParam_AreaOverPi() = RingParam_AreaOverPi;
GetRingParam_Thickness() = RingParam_Thickness;
GetRingParam_ExcFracMax() = RingParam_ExcFracMax;
GetRingParam_AlphaMax() = RingParam_AlphaMax;
GetStandardRingRadius() = StandardRingRadius;
GetStandardRingThickness() = StandardRingThickness;
GetAverageOff() = AverageOff;
if(!AdaptFFT){
if(StandardRingRadius < 0.01 || StandardRingThickness < 0.01){
std::cout << "WARNING: standard ring parameters are strange" << std::endl;
}
}
else{
if(!ConstantInnerRadius && !ConstantThickness && !ConstantArea){
std::cout << "ERROR: No method chosen for Adaptive ring calculation" << std::endl;
GetConfigureRingMethodFlag() = false;
return 0;
}
}
GetConfigureRingMethodFlag() = true;
return 1;
}
/**
* Configuration of the flux products.
*
* \param ProduceFluxProducts : do we produce the flux maps
* \param SpectralIndex : spectral index to be taken to compute the expected counts maps.
* \param PointLikeFluxMaps : if true, the point-like spectral tables will be used.
* \param ProduceSurfaceBrightnessMap : deprecated
* \param ExposureMapsFromFits : if true, the exposure maps are expected to be in FITS format
*
*/
bool SurveySuite::MapMaker::ConfigureFluxProducts(bool ProduceFluxProducts,
double SpectralIndex,
bool PointLikeFluxMaps,
bool ProduceSurfaceBrightnessMap,
bool ExposureMapsFromFits,
const char *AnalysisConfig)
{
GetProduceFluxProducts() = ProduceFluxProducts;
GetSpectralIndex() = SpectralIndex;
GetPointLikeFluxMaps() = PointLikeFluxMaps;
GetProduceSurfaceBrightnessMap() = ProduceSurfaceBrightnessMap;
GetExposureMapsFromFits() = ExposureMapsFromFits;
std::cout << ProduceFluxProducts << " " << PointLikeFluxMaps << " " << AnalysisConfig << std::endl;
std::map<std::string, double> fMapOS;
fMapOS["Loose"]=TMath::Sqrt(0.0125);
fMapOS["Std"]=TMath::Sqrt(0.01);
fMapOS["Faint"]=TMath::Sqrt(0.005);
if(!ProduceSurfaceBrightnessMap){
if(ProduceFluxProducts && PointLikeFluxMaps){
fOSRadius = fMapOS[AnalysisConfig];
std::cout << "Flux Maps requested with PointLike Configuration (" << AnalysisConfig << ") -> Updating OSRadius to " << fOSRadius << std::endl;
}
}
else{
fOSRadius = fMapOS[AnalysisConfig];
fPointLikeFluxMaps = 0;
}
GetConfigureFluxProductsFlag() = true;
return 1;
}
/**
* Configuration of the output of the program.
*
* \param SaveResults : if true, the results will be saved in root format
* \param Verbose
*
*/
bool SurveySuite::MapMaker::ConfigureOutputs(bool SaveResults, bool Verbose)
{
GetSaveResults() = SaveResults;
GetVerbose() = Verbose;
GetConfigureOutputsFlag() = true;
return 1;
}
/**
* End of Configuration.
*
*/
bool SurveySuite::MapMaker::EndConfigure(const char *RadialConfig, const char *Resfile, int RunNumberMin, int RunNumberMax, bool UseRunListToMatch, bool UseRunsToForbid, const char *RunListToMatch, const char *RunsToForbid, std::string table_path)
{
if(GetEventsAndAcceptanceFromRadialFile()){
return 1;
}
else if(GetConfigureOutputsFlag() && GetConfigureFluxProductsFlag() && GetConfigureRingMethodFlag() && GetConfigureMapsFlag() && GetConfigureAcceptanceFlag() && GetConfigureExclusionsFlag() && GetStartConfigureFlag()){
if(ConfigureRuns(Resfile, RunNumberMin, RunNumberMax, UseRunListToMatch, UseRunsToForbid, RunListToMatch, RunsToForbid, table_path)){
if(GetApplySafeThreshold()){
ComputeSafeThresholdPerRun(RadialConfig, Resfile, table_path);
}
return 1;
}
else{
return 0;
}
}
else{
return 0;
}
}
/**
*
* Configuration of the runs to used.
*
* One can use a list of runs to match or a list of runs to forbid.
* If the production of flux products is required, an additionnal check will be made to automatically forbid runs which have suspicious spectral tables
*
*/
bool SurveySuite::MapMaker::ConfigureRuns(const char *Resfile, int RunNumberMin, int RunNumberMax, bool UseRunListToMatch, bool UseRunsToForbid, const char *RunListToMatch, const char *RunsToForbid, std::string table_path)
{
if(RunNumberMax != -1){
if(RunNumberMin >= RunNumberMax){
std::cout << "ERROR : Check the run range!!!" << std::endl;
return 0;
}
}
std::vector<int> ForbidList, MatchList;
if(UseRunsToForbid){
std::ifstream ff(RunsToForbid);
int run;
while(!ff.eof())
{
std::string myline;
std::getline(ff,myline);
if (myline.size()==0) continue;
std::istringstream iss_myline(myline);
iss_myline >> run;
ForbidList.push_back(run);
}
}
if(UseRunListToMatch){
std::ifstream fm(RunListToMatch);
int run;
while(!fm.eof())
{
std::string myline;
std::getline(fm,myline);
if (myline.size()==0) continue;
std::istringstream iss_myline(myline);
iss_myline >> run;
MatchList.push_back(run);
}
}
TFile *fileResults = TFile::Open(Resfile);
gROOT->cd();
Sash::DataSet *results = (Sash::DataSet *)fileResults->Get("results");
results->GetEntry(0);
Sash::HESSArray *hess = Sash::Folder::GetFolder(0)->GetHESSArray();
ParisAnalysis::AnalysisConfig *Config = hess->Handle("", (ParisAnalysis::AnalysisConfig *) 0);
Config->LoadAllMembers();
Sash::DataSet *run_results = (Sash::DataSet *)fileResults->Get("run_results");
gROOT->cd();
for(int i = 0; i < run_results->GetEntries(); ++i)
{
run_results->GetEntry(i);
const ParisAnalysis::DataStorageRun* dsrun = hess->Handle("GammaFOVStorage", (ParisAnalysis::DataStorageRun *) 0);
int runnr = dsrun->GetRunNumber();
std::cout << i+1 << "/" << run_results->GetEntries() << "-> Run Nr = " << runnr << " " << RunNumberMin << " " << RunNumberMax << std::endl;
if(RunNumberMin != 0 && runnr <= RunNumberMin)
continue;
if(RunNumberMax != -1 && runnr >= RunNumberMax)
continue;
if(UseRunsToForbid && IsRunInFile(runnr, ForbidList, 0)){
continue;
}
if(UseRunListToMatch && IsRunInFile(runnr, MatchList, 1)){
continue;
}
std::cout << "adding run " << runnr << " to the list of runs to use" << std::endl;
fEntriesVector.push_back(i);
}
if(fProduceFluxProducts){
RemoveBadTablesRuns(Resfile, table_path);
}
std::cout << Utilities::TextStyle::Green() << "NUMBER OF RUNS >> END OF CONFIGURE RUNS" << Utilities::TextStyle::Reset() << std::endl;
std::cout << "Final runlist has " << fEntriesVector.size() << " runs" << std::endl;
return 1;
}
/*
* Function to check if the run is in the given file
*/
bool SurveySuite::MapMaker::IsRunInFile(int RunNumber, std::vector<int> File, bool ReverseAnswer)
{
// std::ifstream f(File);
int run;
bool runinfile = false;
bool runnotinfile = false;
// while(!f.eof())
std::vector<int>::iterator it = File.begin();
for(; it != File.end(); ++it)
{
/* std::string myline;
std::getline(f,myline);
if (myline.size()==0) continue;
std::istringstream iss_myline(myline);
iss_myline >> run;*/
run = *it;
std::cout << run << " " << RunNumber << std::endl;
if(fabs(run - RunNumber) < 1){
std::cout << " -> run in file" << std::endl;
runinfile = true;
if(!ReverseAnswer)
continue;
}
}
if(!ReverseAnswer) return runinfile;
else return !runinfile;
}
/*
* Check the table corresponding to each run and if the masimum acceptance is suspiciously low, forbid the run.
*/
void SurveySuite::MapMaker::RemoveBadTablesRuns(const char *Resfile, std::string table_path)
{
std::cout << Utilities::TextStyle::Green() << "REMOVE BAD TABLES RUNS" << Utilities::TextStyle::Reset() << std::endl;
double fSourceSize = 0.;
if(!GetPointLikeFluxMaps()){
fSourceSize = 1.;
std::cout << "Extended tables will be taken!" << std::endl;
}
TFile *fileResults = TFile::Open(Resfile);
gROOT->cd();
Sash::DataSet *results = (Sash::DataSet *)fileResults->Get("results");
results->GetEntry(0);
Sash::HESSArray *hess = Sash::Folder::GetFolder(0)->GetHESSArray();
ParisAnalysis::AnalysisConfig *Config = hess->Handle("", (ParisAnalysis::AnalysisConfig *) 0);
Config->LoadAllMembers();
Sash::DataSet *run_results = (Sash::DataSet *)fileResults->Get("run_results");
gROOT->cd();
//Retrieve tables
char *s = gSystem->ExpandPathName(table_path.c_str());
setenv("SPECTRUM_PATH",s,1);
delete[] s;
std::string fAcceptanceNameBase = "Combined";
Bool_t fAutoAzimut=false;
Float_t fSourceExtension=0.;
Float_t fTheta2Cut = fSourceSize;
Float_t fMuonEfficiency = 0.;
Bool_t fCheckAnalysisVersion=false;
Bool_t fVerbose=false;
std::map<Int_t,std::string> fMapAzimuth;
fMapAzimuth[0] = "North";
fMapAzimuth[180] = "South";
std::map<Int_t, Spectrum::SpectrumTableFinderMulti*> fMapTableFinder;
std::map<Int_t, std::map<Int_t, const Spectrum::AcceptanceTableEfficiency*> > fMapTableAcceptance;
std::map<Int_t, std::map<Int_t, const Spectrum::ResolutionTableEfficiency*> > fMapTableResolution;
for (std::map<Int_t,std::string>::const_iterator it = fMapAzimuth.begin(); it!=fMapAzimuth.end(); ++it) {
std::string AcceptanceName = fAcceptanceNameBase + it->second;
Float_t Azimuth = Float_t(it->first);
Spectrum::SpectrumTableFinderMulti *table = new Spectrum::SpectrumTableFinderMulti(Spectrum::SpectrumTableFinderMulti::Models,AcceptanceName.c_str(),Azimuth,fAutoAzimut,fSourceExtension,fTheta2Cut,fMuonEfficiency,fCheckAnalysisVersion,fVerbose);
table->Process(Sash::Folder::GetFolder("results"));
// std::cout << Utilities::TextStyle::Blue() << "SpectrumTableFinderMulti[" << Azimuth << "] = " << table << Utilities::TextStyle::Reset() << std::endl;
fMapTableFinder[Azimuth] = table;
std::cout << Utilities::TextStyle::Blue() << "SpectrumTableFinderMulti[" << Azimuth << "] = Done !" << Utilities::TextStyle::Reset() << std::endl;
std::cout << (void*)table << std::endl;
for (int itel=3;itel<=4;++itel) {
std::ostringstream oss_tabname;
oss_tabname << AcceptanceName << "_Tels" << itel;
fMapTableAcceptance[Azimuth][itel] = hess->Get<Spectrum::AcceptanceTableEfficiency>(oss_tabname.str().c_str());
std::cout << Utilities::TextStyle::Blue() << "Retrieve AcceptanceTableEfficiency[" << Azimuth << "][" << itel << "] Named : " << oss_tabname.str().c_str() << " (" << (void*)fMapTableAcceptance[Azimuth][itel] << ")" << Utilities::TextStyle::Reset() << std::endl;
fMapTableResolution[Azimuth][itel] = hess->Get<Spectrum::ResolutionTableEfficiency>(oss_tabname.str().c_str());
std::cout << Utilities::TextStyle::Blue() << "Retrieve ResolutionTableEfficiency[" << Azimuth << "][" << itel << "] Named : " << oss_tabname.str().c_str() << " (" << (void*)fMapTableResolution[Azimuth][itel] << ")" << Utilities::TextStyle::Reset() << std::endl;
oss_tabname.str("");
}
}
std::vector<int>::iterator it = fEntriesVector.begin();
// for(int i = 0; i < run_results->GetEntries(); ++i)
int EntryCounter = 0;
for(; it != fEntriesVector.end(); ++it)
{
int i = *it;
run_results->GetEntry(i);
const ParisAnalysis::DataStorageRun* dsrun = hess->Handle("GammaFOVStorage", (ParisAnalysis::DataStorageRun *) 0);
std::cout << i+1 << "/" << run_results->GetEntries() << std::endl;
double MeanZen = dsrun->GetMeanZenith();
double meanCosZen = cos(MeanZen*TMath::Pi()/180.);
double RelativeEfficiency = dsrun->GetMuonEfficiency();
// Retrieve Azimuth
Double_t MeanAzimuth = dsrun->GetMeanAzimuth();
if (MeanAzimuth > 360. || MeanAzimuth<0.) {
std::cout << Utilities::TextStyle::Red() << "Problem MeanAzimuth = " << MeanAzimuth << " BADLY TAKEN INTO ACCOUNT (I TRY A FIX, BUT CHECK IF THIS IS OK) !!!" << Utilities::TextStyle::Reset() << std::endl;
}
if (MeanAzimuth<0) {MeanAzimuth+=360.;}
if (MeanAzimuth>360) {MeanAzimuth=MeanAzimuth-360.;}
Int_t AzimuthCode = ( (MeanAzimuth<=90. || MeanAzimuth>270) ? 0 : 180 );
// Retrieve LiveTime
Double_t LiveTime = dsrun->GetOnLiveTime();
// Retrieve TelescopeNumber and Pattern !
Int_t NTels = dsrun->GetTelsInRun().size();
// Get the Acceptance/Resolution Tables for the current run
const Spectrum::AcceptanceTableEfficiency *AccTab = fMapTableAcceptance[AzimuthCode][NTels];
if (!AccTab) {
std::cout << Utilities::TextStyle::Yellow() << " Can't find AcceptanceTableEfficiency for AzimuthCode : " << AzimuthCode << " NTels : " << NTels << Utilities::TextStyle::Reset() << std::endl;
continue;
}
const Spectrum::ResolutionTableEfficiency *ResTab = fMapTableResolution[AzimuthCode][NTels];
if (!ResTab) {
std::cout << Utilities::TextStyle::Yellow() << " Can't find ResolutionTableEfficiency for AzimuthCode : " << AzimuthCode << " NTels : " << NTels << Utilities::TextStyle::Reset() << std::endl;
continue;
}
std::cout << meanCosZen << " " << RelativeEfficiency << " " << LiveTime << " " << NTels << std::endl;
double MuonEff = dsrun->GetMuonEfficiency();
double offaxisAngle = fPsiCut;
if(!fSafeThresholdFromPsiCut)
offaxisAngle = fSafeThresholdFromPsiValue;
Double_t lnEmin = log(0.02);
Double_t lnEmax = log(20.);
Double_t lnEstep = 0.01;
Double_t MaxAcceptance = 0;
Double_t CurrentAcceptance = 0;
Double_t CurrentBias = 1;
Double_t CurrentBiasFromGraph = 1;
Double_t lnE = lnEmin;
Double_t lnEThresh = lnEmin;
Double_t lnEThreshBiasFromGraph = lnEmin;
Double_t SafeThreshold = 0;
//----Acceptance method
while(lnE < lnEmax) {
CurrentAcceptance = AccTab->GetAcceptance(lnE,meanCosZen,offaxisAngle,MuonEff);
if(CurrentAcceptance>MaxAcceptance)
MaxAcceptance = CurrentAcceptance;
lnE += lnEstep;
}
std::cout << MaxAcceptance << std::endl;
if(MaxAcceptance < 1){
std::cout << "Strange table .... run will not be used !!!" << std::endl;
fEntriesVector.erase(it);
--it;
}
}
std::cout << fEntriesVector.size() << std::endl;
}
void SurveySuite::MapMaker::ComputeSafeThresholdPerRun(const char *RadialConfig, const char *Resfile, std::string table_path)
{
double fSourceSize = 0.;
if(!GetPointLikeFluxMaps()){
fSourceSize = 1.;
std::cout << "Extended tables will be taken!" << std::endl;
}
std::cout << RadialConfig << std::endl;
std::ostringstream f;
f << "RadialTables/RadialTablesEnergy_" << RadialConfig << ".root";
TFile *RadialFile = TFile::Open(f.str().c_str());
TFile *fileResults = TFile::Open(Resfile);
gROOT->cd();
Sash::DataSet *results = (Sash::DataSet *)fileResults->Get("results");
results->GetEntry(0);
Sash::HESSArray *hess = Sash::Folder::GetFolder(0)->GetHESSArray();
ParisAnalysis::AnalysisConfig *Config = hess->Handle("", (ParisAnalysis::AnalysisConfig *) 0);
Config->LoadAllMembers();
Sash::DataSet *run_results = (Sash::DataSet *)fileResults->Get("run_results");
gROOT->cd();
//Retrieve tables
char *s = gSystem->ExpandPathName(table_path.c_str());
setenv("SPECTRUM_PATH",s,1);
delete[] s;
std::string fAcceptanceNameBase = "Combined";
Bool_t fAutoAzimut=false;
Float_t fSourceExtension=0.;
Float_t fTheta2Cut = fSourceSize;
Float_t fMuonEfficiency = 0.;
Bool_t fCheckAnalysisVersion=false;
Bool_t fVerbose=false;
std::map<Int_t,std::string> fMapAzimuth;
fMapAzimuth[0] = "North";
fMapAzimuth[180] = "South";
std::map<Int_t, Spectrum::SpectrumTableFinderMulti*> fMapTableFinder;
std::map<Int_t, std::map<Int_t, const Spectrum::AcceptanceTableEfficiency*> > fMapTableAcceptance;
std::map<Int_t, std::map<Int_t, const Spectrum::ResolutionTableEfficiency*> > fMapTableResolution;
for (std::map<Int_t,std::string>::const_iterator it = fMapAzimuth.begin(); it!=fMapAzimuth.end(); ++it) {
std::string AcceptanceName = fAcceptanceNameBase + it->second;
Float_t Azimuth = Float_t(it->first);
Spectrum::SpectrumTableFinderMulti *table = new Spectrum::SpectrumTableFinderMulti(Spectrum::SpectrumTableFinderMulti::Models,AcceptanceName.c_str(),Azimuth,fAutoAzimut,fSourceExtension,fTheta2Cut,fMuonEfficiency,fCheckAnalysisVersion,fVerbose);
table->Process(Sash::Folder::GetFolder("results"));
// std::cout << Utilities::TextStyle::Blue() << "SpectrumTableFinderMulti[" << Azimuth << "] = " << table << Utilities::TextStyle::Reset() << std::endl;
fMapTableFinder[Azimuth] = table;
std::cout << Utilities::TextStyle::Blue() << "SpectrumTableFinderMulti[" << Azimuth << "] = Done !" << Utilities::TextStyle::Reset() << std::endl;
std::cout << (void*)table << std::endl;
for (int itel=3;itel<=4;++itel) {
std::ostringstream oss_tabname;
oss_tabname << AcceptanceName << "_Tels" << itel;
fMapTableAcceptance[Azimuth][itel] = hess->Get<Spectrum::AcceptanceTableEfficiency>(oss_tabname.str().c_str());
std::cout << Utilities::TextStyle::Blue() << "Retrieve AcceptanceTableEfficiency[" << Azimuth << "][" << itel << "] Named : " << oss_tabname.str().c_str() << " (" << (void*)fMapTableAcceptance[Azimuth][itel] << ")" << Utilities::TextStyle::Reset() << std::endl;
fMapTableResolution[Azimuth][itel] = hess->Get<Spectrum::ResolutionTableEfficiency>(oss_tabname.str().c_str());
std::cout << Utilities::TextStyle::Blue() << "Retrieve ResolutionTableEfficiency[" << Azimuth << "][" << itel << "] Named : " << oss_tabname.str().c_str() << " (" << (void*)fMapTableResolution[Azimuth][itel] << ")" << Utilities::TextStyle::Reset() << std::endl;
oss_tabname.str("");
}
}
std::vector<int>::iterator it = fEntriesVector.begin();
// for(int i = 0; i < run_results->GetEntries(); ++i)
for(; it != fEntriesVector.end(); ++it)
{
int i = *it;
run_results->GetEntry(i);
const ParisAnalysis::DataStorageRun* dsrun = hess->Handle("GammaFOVStorage", (ParisAnalysis::DataStorageRun *) 0);
std::cout << i+1 << "/" << run_results->GetEntries() << std::endl;
double MeanZen = dsrun->GetMeanZenith();
double meanCosZen = cos(MeanZen*TMath::Pi()/180.);
double RelativeEfficiency = dsrun->GetMuonEfficiency();
// Retrieve Azimuth
Double_t MeanAzimuth = dsrun->GetMeanAzimuth();
if (MeanAzimuth > 360. || MeanAzimuth<0.) {
std::cout << Utilities::TextStyle::Red() << "Problem MeanAzimuth = " << MeanAzimuth << " BADLY TAKEN INTO ACCOUNT (I TRY A FIX, BUT CHECK IF THIS IS OK) !!!" << Utilities::TextStyle::Reset() << std::endl;
}
if (MeanAzimuth<0) {MeanAzimuth+=360.;}
if (MeanAzimuth>360) {MeanAzimuth=MeanAzimuth-360.;}
Int_t AzimuthCode = ( (MeanAzimuth<=90. || MeanAzimuth>270) ? 0 : 180 );
// Retrieve LiveTime
Double_t LiveTime = dsrun->GetOnLiveTime();
// Retrieve TelescopeNumber and Pattern !
Int_t NTels = dsrun->GetTelsInRun().size();
// Get the Acceptance/Resolution Tables for the current run
const Spectrum::AcceptanceTableEfficiency *AccTab = fMapTableAcceptance[AzimuthCode][NTels];
if (!AccTab) {
std::cout << Utilities::TextStyle::Yellow() << " Can't find AcceptanceTableEfficiency for AzimuthCode : " << AzimuthCode << " NTels : " << NTels << Utilities::TextStyle::Reset() << std::endl;
continue;
}
const Spectrum::ResolutionTableEfficiency *ResTab = fMapTableResolution[AzimuthCode][NTels];
if (!ResTab) {
std::cout << Utilities::TextStyle::Yellow() << " Can't find ResolutionTableEfficiency for AzimuthCode : " << AzimuthCode << " NTels : " << NTels << Utilities::TextStyle::Reset() << std::endl;
continue;
}
std::cout << meanCosZen << " " << RelativeEfficiency << " " << LiveTime << " " << NTels << std::endl;
std::cout << RadialConfig << std::endl;
TH2F *hEnergy = (TH2F *)RadialFile->Get("hR2D_4Tels_0");
double int_emin = fEMin;
double int_emax = fEMax;
int binemin = 0;
int binemax = -1;
if(fEMin != 0){
double log10emin = TMath::Log10(fEMin);
binemin = hEnergy->GetXaxis()->FindFixBin(log10emin);
int_emin = pow(10,hEnergy->GetXaxis()->GetBinLowEdge(binemin));
}
else{
int_emin = 0.01;
}
if(fEMax != -1){
double log10emax = TMath::Log10(fEMax);
binemax = hEnergy->GetXaxis()->FindFixBin(log10emax);
int_emax = pow(10,hEnergy->GetXaxis()->GetBinLowEdge(binemax)+hEnergy->GetXaxis()->GetBinWidth(binemax));
}
else{
int_emax = 200;
}
unsigned int nen = 20;
TGraph *gBias = new TGraph(nen);
double en[] = {0.02,0.03,0.05,0.08,0.125,0.2,0.3,0.5,0.8,1.25,
2.,3.,5.,8.,12.5,20.,30.,50.,80.,125.};
std::vector<double> EnergyMC; ///< mc energy
EnergyMC.assign(en,en+nen);
double MuonEff = dsrun->GetMuonEfficiency();
double offaxisAngle = fPsiCut;
if(!fSafeThresholdFromPsiCut)
offaxisAngle = fSafeThresholdFromPsiValue;
//Loop on acceptance values at current zenith angle
Double_t lnEmin = log(0.02);
Double_t lnEmax = log(20.);
Double_t lnEstep = 0.01;
Double_t MaxAcceptance = 0;
Double_t CurrentAcceptance = 0;
Double_t CurrentBias = 1;
Double_t CurrentBiasFromGraph = 1;
Double_t lnE = lnEmin;
Double_t lnEThresh = lnEmin;
Double_t lnEThreshBiasFromGraph = lnEmin;
Double_t SafeThreshold = 0;
if(GetSafeThresholdFromAcceptance()){
//----Acceptance method
while(lnE < lnEmax) {
CurrentAcceptance = AccTab->GetAcceptance(lnE,meanCosZen,offaxisAngle,MuonEff);
if(CurrentAcceptance>MaxAcceptance)
MaxAcceptance = CurrentAcceptance;
lnE += lnEstep;
}
//Find energy where acceptance is a given fraction of its maximum
CurrentAcceptance = AccTab->GetAcceptance(lnEThresh,meanCosZen,offaxisAngle,MuonEff);
while(lnEThresh < lnEmax && CurrentAcceptance < MaxAcceptance * GetSafeThresholdRatioParam()) {
lnEThresh += lnEstep;
CurrentAcceptance = AccTab->GetAcceptance(lnEThresh,meanCosZen,offaxisAngle,MuonEff);
}
SafeThreshold = exp(lnEThresh);
if(MaxAcceptance < 1)
{
std::cout << "Strange Table -> taking threshold value from parametrisation" << std::endl;
SafeThreshold = 0.25+0.0085*MeanZen+exp(-7.94+0.14*MeanZen);
}
}
else{
Int_t mcnpointres(200); // overkill ?
Double_t log_ereco_over_etrue_min = -3.;
Double_t log_ereco_over_etrue_max = 3.;
Double_t log_e_step = (log_ereco_over_etrue_max-log_ereco_over_etrue_min)/Double_t(mcnpointres-1.);
for(unsigned int i = 0; i < nen; ++i)
{
TH1F *hBias = new TH1F("Bias","Bias",200,-3,3);
Double_t etrue = EnergyMC[i];
for (int imcbin=0;imcbin<mcnpointres;++imcbin) {
Double_t log_ereco_over_etrue = log_ereco_over_etrue_min + Double_t(imcbin)*log_e_step;
Double_t mce = etrue*TMath::Exp(log_ereco_over_etrue);
double pdf = 0;
pdf = ResTab->GetPDFvalue( TMath::Log(etrue), TMath::Log(mce), meanCosZen,offaxisAngle,MuonEff);
hBias->SetBinContent(imcbin+1,pdf);
}
gBias->SetPoint(i,log(EnergyMC[i]),hBias->GetMean());
delete hBias;
}
//----Bias Method
lnE = lnEmin;
CurrentBiasFromGraph = gBias->Eval(lnE);
if(gBias->Eval(lnE) < GetSafeThresholdRatioParam()){
while(fabs(gBias->Eval(lnE+lnEstep)-CurrentBiasFromGraph)<0.001){
CurrentBiasFromGraph = gBias->Eval(lnE);
lnE += lnEstep;
}
}
else{
while(CurrentBiasFromGraph > GetSafeThresholdRatioParam()){
CurrentBiasFromGraph = gBias->Eval(lnE);
lnE += lnEstep;
}
}
lnEThreshBiasFromGraph = lnE;
SafeThreshold = exp(lnEThreshBiasFromGraph);
}
std::cout << "SafeThreshold = " << SafeThreshold << std::endl;
fPerRunSafeThreshold[dsrun->GetRunNumber()]=SafeThreshold;
}
}
void SurveySuite::MapMaker::PrintConfigSummary()
{
//Print Config Summary//
std::cout << "**** CONFIG ****" << std::endl;
std::cout << "OverSampling Radius = " << fOSRadius << std::endl;
std::cout << "EMin = " << fEMin << " - EMax = " << fEMax << std::endl;
std::cout << "** Files:" << std::endl;
if(fEventsAndAcceptanceFromRadial){
std::cout << "- Events and Acceptance from RADIAL" << std::endl;
std::cout << "\t- PsiCut = " << fPsiCut << std::endl;
std::cout << "\t- Zenith Correct = " << fCorrectZenith << std::endl;
}
else if(fEventsAndAcceptanceFromFile)
std::cout << "- Events and Acceptance from FILE" << std::endl;
else
std::cout << "- Events and Acceptance from FITS" << std::endl;
if(fExclusionFromRegionFile)
std::cout << "- Exclusion from REGION FILE" << std::endl;
else if(fExclusionFromFits)
std::cout << "- Exclusion from FITS" << std::endl;