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

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