source: trunk/MagicSoft/Mars/mhflux/MHThreshold.cc@ 9352

Last change on this file since 9352 was 9301, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 4.6 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz 12/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2008
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MHThreshold
28//
29// Class to calculate the threshold of your analysis.
30//
31// It fills a histogram dN/dE vs E with a fine binning. The threshold is
32// determined as the logarithmic center of the bin with the maximum
33// content.
34//
35//////////////////////////////////////////////////////////////////////////////
36#include "MHThreshold.h"
37
38#include <TMath.h>
39
40#include <TF1.h>
41#include <TLatex.h>
42#include <TCanvas.h>
43#include <TPaveStats.h>
44
45#include "MLog.h"
46#include "MLogManip.h"
47
48#include "MString.h"
49#include "MBinning.h"
50
51#include "MMcEvt.hxx"
52
53#include "MParList.h"
54
55ClassImp(MHThreshold);
56
57using namespace std;
58
59// --------------------------------------------------------------------------
60//
61// Creates the three necessary histograms:
62// - selected showers (input)
63// - all showers (input)
64// - collection area (result)
65//
66MHThreshold::MHThreshold(const char *name, const char *title)
67{
68 // initialize the histogram for the distribution r vs E
69 //
70 // we set the energy range from 2 Gev to 20000 GeV (in log 4 orders
71 // of magnitude) and for each order we take 25 subdivision --> 100 xbins
72 //
73 // we set the radius range from 0 m to 500 m with 10 m bin --> 50 ybins
74 //
75 fName = name ? name : "MHThreshold";
76 fTitle = title ? title : "Histogram to determin the threshold";
77
78 fHEnergy.SetName("Threshold");
79 fHEnergy.SetTitle("Energy Threshold");
80 fHEnergy.SetXTitle("E [GeV]");
81 fHEnergy.SetYTitle("dN/dE [GeV^{-1}]");
82 fHEnergy.SetDirectory(NULL);
83 fHEnergy.UseCurrentStyle();
84
85 MBinning binse(50, 20, 50000, "", "log");
86 binse.Apply(fHEnergy);
87
88 fHEnergy.Sumw2();
89}
90
91Bool_t MHThreshold::SetupFill(const MParList *pl)
92{
93 fMcEvt = (MMcEvt*)pl->FindObject("MMcEvt");
94 if (!fMcEvt)
95 {
96 *fLog << err << "MMcEvt not found... abort." << endl;
97 return kFALSE;
98 }
99/*
100 MBinning binse;
101 binse.SetEdges(fHEnergy, 'x');
102
103 MBinning *bins = (MBinning*)pl->FindObject("BinningEnergyEst", "MBinning");
104 if (bins)
105 binse.SetEdges(*bins);
106
107 binse.Apply(fHEnergy);
108 */
109 return kTRUE;
110}
111
112void MHThreshold::Paint(Option_t *option)
113{
114 if (fHEnergy.GetEntries()==0)
115 return;
116
117 TH1D h(fHEnergy);
118 h.SetDirectory(0);
119
120#if ROOT_VERSION_CODE<ROOT_VERSION(5,20,00)
121 Int_t min=1;
122 while (min<h.GetNbinsX() && h.GetBinContent(min)==0)
123 min++;
124 Int_t max=h.GetNbinsX();
125 while (max>min && h.GetBinContent(max)==0)
126 max--;
127
128 if (max-min<5)
129 return;
130
131 h.Smooth(1, min, max);
132#else
133 h.Smooth(1);
134#endif
135
136 const Int_t bin = h.GetMaximumBin();
137 const TAxis &axe = *h.GetXaxis();
138
139 // Assume that the energy binning is logarithmic
140 const Axis_t maxe = TMath::Sqrt(axe.GetBinLowEdge(bin)*axe.GetBinUpEdge(bin));
141
142 TLatex text(0.30, 0.95, MString::Format("E_{max}=%dGeV (%dGeV,%dGeV)", TMath::Nint(maxe),
143 TMath::Nint(axe.GetBinLowEdge(bin)),
144 TMath::Nint(axe.GetBinUpEdge(bin))));
145 text.SetBit(TLatex::kTextNDC);
146 text.SetTextSize(0.04);
147 text.Paint();
148}
149
150void MHThreshold::Draw(Option_t *option)
151{
152 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
153
154 // Do the projection before painting the histograms into
155 // the individual pads
156 pad->SetBorderMode(0);
157
158 gPad->SetLogx();
159 gPad->SetLogy();
160 gPad->SetGridx();
161 gPad->SetGridy();
162
163 fHEnergy.Draw();
164
165 AppendPad();
166}
167
168Int_t MHThreshold::Fill(const MParContainer *par, const Stat_t weight)
169{
170 const Double_t energy = fMcEvt->GetEnergy();
171
172 fHEnergy.Fill(energy, weight/energy);
173
174 return kTRUE;
175}
Note: See TracBrowser for help on using the repository browser.