source: trunk/Mars/mhflux/MHThreshold.cc@ 9627

Last change on this file since 9627 was 9362, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 4.4 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 ApplyBinning(*pl, "Threshold", &fHEnergy);
101
102 return kTRUE;
103}
104
105void MHThreshold::Paint(Option_t *option)
106{
107 if (fHEnergy.GetEntries()==0)
108 return;
109
110 TH1D h(fHEnergy);
111 h.SetDirectory(0);
112
113#if ROOT_VERSION_CODE<ROOT_VERSION(5,20,00)
114 Int_t min=1;
115 while (min<h.GetNbinsX() && h.GetBinContent(min)==0)
116 min++;
117 Int_t max=h.GetNbinsX();
118 while (max>min && h.GetBinContent(max)==0)
119 max--;
120
121 if (max-min<5)
122 return;
123
124 h.Smooth(1, min, max);
125#else
126 h.Smooth(1);
127#endif
128
129 const Int_t bin = h.GetMaximumBin();
130 const TAxis &axe = *h.GetXaxis();
131
132 // Assume that the energy binning is logarithmic
133 const Axis_t maxe = TMath::Sqrt(axe.GetBinLowEdge(bin)*axe.GetBinUpEdge(bin));
134
135 TLatex text(0.30, 0.95, MString::Format("E_{max}=%dGeV (%dGeV,%dGeV)", TMath::Nint(maxe),
136 TMath::Nint(axe.GetBinLowEdge(bin)),
137 TMath::Nint(axe.GetBinUpEdge(bin))));
138 text.SetBit(TLatex::kTextNDC);
139 text.SetTextSize(0.04);
140 text.Paint();
141}
142
143void MHThreshold::Draw(Option_t *option)
144{
145 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
146
147 // Do the projection before painting the histograms into
148 // the individual pads
149 pad->SetBorderMode(0);
150
151 gPad->SetLogx();
152 gPad->SetLogy();
153 gPad->SetGridx();
154 gPad->SetGridy();
155
156 fHEnergy.Draw();
157
158 AppendPad();
159}
160
161Int_t MHThreshold::Fill(const MParContainer *par, const Stat_t weight)
162{
163 const Double_t energy = fMcEvt->GetEnergy();
164
165 fHEnergy.Fill(energy, weight/energy);
166
167 return kTRUE;
168}
Note: See TracBrowser for help on using the repository browser.