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

Last change on this file since 9114 was 8988, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 4.5 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 "MBinning.h"
49
50#include "MMcEvt.hxx"
51
52#include "MParList.h"
53
54ClassImp(MHThreshold);
55
56using namespace std;
57
58// --------------------------------------------------------------------------
59//
60// Creates the three necessary histograms:
61// - selected showers (input)
62// - all showers (input)
63// - collection area (result)
64//
65MHThreshold::MHThreshold(const char *name, const char *title)
66{
67 // initialize the histogram for the distribution r vs E
68 //
69 // we set the energy range from 2 Gev to 20000 GeV (in log 4 orders
70 // of magnitude) and for each order we take 25 subdivision --> 100 xbins
71 //
72 // we set the radius range from 0 m to 500 m with 10 m bin --> 50 ybins
73 //
74 fName = name ? name : "MHThreshold";
75 fTitle = title ? title : "Histogram to determin the threshold";
76
77 fHEnergy.SetName("Threshold");
78 fHEnergy.SetTitle("Energy Threshold");
79 fHEnergy.SetXTitle("E [GeV]");
80 fHEnergy.SetYTitle("dN/dE [GeV^{-1}]");
81 fHEnergy.SetDirectory(NULL);
82 fHEnergy.UseCurrentStyle();
83
84 MBinning binse(50, 20, 50000, "", "log");
85 binse.Apply(fHEnergy);
86
87 fHEnergy.Sumw2();
88}
89
90Bool_t MHThreshold::SetupFill(const MParList *pl)
91{
92 fMcEvt = (MMcEvt*)pl->FindObject("MMcEvt");
93 if (!fMcEvt)
94 {
95 *fLog << err << "MMcEvt not found... abort." << endl;
96 return kFALSE;
97 }
98/*
99 MBinning binse;
100 binse.SetEdges(fHEnergy, 'x');
101
102 MBinning *bins = (MBinning*)pl->FindObject("BinningEnergyEst", "MBinning");
103 if (bins)
104 binse.SetEdges(*bins);
105
106 binse.Apply(fHEnergy);
107 */
108 return kTRUE;
109}
110
111void MHThreshold::Paint(Option_t *option)
112{
113 if (fHEnergy.GetEntries()==0)
114 return;
115
116 TH1D h(fHEnergy);
117
118#if ROOT_VERSION_CODE<ROOT_VERSION(5,20,00)
119 Int_t min=1;
120 while (min<h.GetNbinsX() && h.GetBinContent(min)==0)
121 min++;
122 Int_t max=h.GetNbinsX();
123 while (max>min && h.GetBinContent(max)==0)
124 max--;
125
126 if (max-min<5)
127 return;
128
129 h.Smooth(1, min, max);
130#else
131 h.Smooth(1);
132#endif
133
134 const Int_t bin = h.GetMaximumBin();
135 const TAxis &axe = *h.GetXaxis();
136
137 // Assume that the energy binning is logarithmic
138 const Axis_t maxe = TMath::Sqrt(axe.GetBinLowEdge(bin)*axe.GetBinUpEdge(bin));
139
140 TLatex text(0.30, 0.95, Form("E_{max}=%dGeV (%dGeV,%dGeV)", TMath::Nint(maxe),
141 TMath::Nint(axe.GetBinLowEdge(bin)),
142 TMath::Nint(axe.GetBinUpEdge(bin))));
143 text.SetBit(TLatex::kTextNDC);
144 text.SetTextSize(0.04);
145 text.Paint();
146}
147
148void MHThreshold::Draw(Option_t *option)
149{
150 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
151
152 // Do the projection before painting the histograms into
153 // the individual pads
154 pad->SetBorderMode(0);
155
156 gPad->SetLogx();
157 gPad->SetLogy();
158 gPad->SetGridx();
159 gPad->SetGridy();
160
161 fHEnergy.Draw();
162
163 AppendPad();
164}
165
166Bool_t MHThreshold::Fill(const MParContainer *par, const Stat_t weight)
167{
168 const Double_t energy = fMcEvt->GetEnergy();
169
170 fHEnergy.Fill(energy, weight/energy);
171
172 return kTRUE;
173}
Note: See TracBrowser for help on using the repository browser.