Commit b89c3481edd9904152d22c20c413c1c29f8bbd75
1 parent
013a064e
Make effective area histogram rebinning optional.
Showing
1 changed file
with
26 additions
and
17 deletions
scripts/cta_root2caldb.py
| ... | ... | @@ -683,18 +683,20 @@ class caldb(): |
| 683 | 683 | # Return boundary information |
| 684 | 684 | return bounds |
| 685 | 685 | |
| 686 | - def root2caldb(self, filename): | |
| 686 | + def root2caldb(self, filename, rebin=False): | |
| 687 | 687 | """ |
| 688 | 688 | Translate ROOT to CALDB information. |
| 689 | 689 | |
| 690 | 690 | Parameters: |
| 691 | 691 | filename - ROOT 2D performance filename. |
| 692 | + Keywords: | |
| 693 | + rebin - Rebin Etrue histogram (useful for Prod1 IFAE runs) | |
| 692 | 694 | """ |
| 693 | 695 | # Open ROOT performance file |
| 694 | 696 | file = TFile(filename) |
| 695 | 697 | |
| 696 | 698 | # Create effective area |
| 697 | - self.root2ea(file) | |
| 699 | + self.root2ea(file, rebin=rebin) | |
| 698 | 700 | |
| 699 | 701 | # Create point spread function |
| 700 | 702 | self.root2psf(file) |
| ... | ... | @@ -708,7 +710,7 @@ class caldb(): |
| 708 | 710 | # Return |
| 709 | 711 | return |
| 710 | 712 | |
| 711 | - def root2ea(self, file): | |
| 713 | + def root2ea(self, file, rebin=False): | |
| 712 | 714 | """ |
| 713 | 715 | Translate ROOT to CALDB effective area extension. The following ROOT |
| 714 | 716 | histograms are used: |
| ... | ... | @@ -719,7 +721,7 @@ class caldb(): |
| 719 | 721 | Parameters: |
| 720 | 722 | file - ROOT file. |
| 721 | 723 | Keywords: |
| 722 | - None | |
| 724 | + rebin - Rebin Etrue histogram (useful for Prod1 IFAE runs) | |
| 723 | 725 | """ |
| 724 | 726 | # Continue only if effective area HDU has been opened |
| 725 | 727 | if self.hdu_ea != None: |
| ... | ... | @@ -729,17 +731,18 @@ class caldb(): |
| 729 | 731 | ereco = TH2F() |
| 730 | 732 | file.GetObject("EffectiveAreaEtrue_offaxis", etrue) |
| 731 | 733 | file.GetObject("EffectiveArea_offaxis", ereco) |
| 732 | - #print etrue.GetXaxis().GetBinLowEdge(1), etrue.GetXaxis().GetBinUpEdge(etrue.GetXaxis().GetNbins()) | |
| 733 | - #print ereco.GetXaxis().GetBinLowEdge(1), ereco.GetXaxis().GetBinUpEdge(ereco.GetXaxis().GetNbins()) | |
| 734 | + #print(etrue.GetXaxis().GetBinLowEdge(1), etrue.GetXaxis().GetBinUpEdge(etrue.GetXaxis().GetNbins())) | |
| 735 | + #print(ereco.GetXaxis().GetBinLowEdge(1), ereco.GetXaxis().GetBinUpEdge(ereco.GetXaxis().GetNbins())) | |
| 734 | 736 | |
| 735 | 737 | # Rebin etrue histogram |
| 736 | - etrue.RebinX(10) | |
| 737 | - neng = etrue.GetXaxis().GetNbins() | |
| 738 | - noffset = etrue.GetYaxis().GetNbins() | |
| 739 | - for ioff in range(noffset): | |
| 740 | - for ieng in range(neng): | |
| 741 | - value = etrue.GetBinContent(ieng+1,ioff+1) / 10.0 | |
| 742 | - etrue.SetBinContent(ieng+1,ioff+1,value) | |
| 738 | + if rebin: | |
| 739 | + etrue.RebinX(10) | |
| 740 | + neng = etrue.GetXaxis().GetNbins() | |
| 741 | + noffset = etrue.GetYaxis().GetNbins() | |
| 742 | + for ioff in range(noffset): | |
| 743 | + for ieng in range(neng): | |
| 744 | + value = etrue.GetBinContent(ieng+1,ioff+1) / 10.0 | |
| 745 | + etrue.SetBinContent(ieng+1,ioff+1,value) | |
| 743 | 746 | |
| 744 | 747 | # Write boundaries (use Ereco boundaries) |
| 745 | 748 | bounds = self.make_2D(ereco, self.hdu_ea, None, "m2") |
| ... | ... | @@ -955,9 +958,15 @@ if __name__ == '__main__': |
| 955 | 958 | - ERes_offaxis (2D) - Energy Resolution |
| 956 | 959 | - Ebias_offaxis (2D) - Energy bias |
| 957 | 960 | """ |
| 958 | - # Set ROOT filename | |
| 959 | - path = "/Users/jurgen/Documents/Travail/Projects/CTA/WP-MC/root/IFAEOffaxisPerformanceBEI_May2012" | |
| 960 | - irf = "SubarrayE_IFAE_50hours_20120510_offaxis.root" | |
| 961 | + # Set path and root file | |
| 962 | + #path = "/project-data/cta/performance/prod1/IFAEOffaxisPerformanceBEI_May2012" | |
| 963 | + #irf = "SubarrayE_IFAE_50hours_20120510_offaxis.root" | |
| 964 | + #rebin = True | |
| 965 | + path = "/project-data/cta/performance/prod2/Performance_DESY_20140128" | |
| 966 | + irf = "DESY.d20140105.Erec1.V2.ID0_180degNIM2.prod2-Aar-NS.S.2a.180000s.root" | |
| 967 | + rebin = False | |
| 968 | + | |
| 969 | + # Set filename | |
| 961 | 970 | filename = path+"/"+irf |
| 962 | 971 | |
| 963 | 972 | # Set observation identifiers |
| ... | ... | @@ -974,5 +983,5 @@ if __name__ == '__main__': |
| 974 | 983 | db.open("test") |
| 975 | 984 | |
| 976 | 985 | # Translate ROOT to CALDB information |
| 977 | - db.root2caldb(filename) | |
| 986 | + db.root2caldb(filename, rebin=rebin) | |
| 978 | 987 | |
| 979 | 988 | \ No newline at end of file | ... | ... |