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

Last change on this file since 7825 was 7715, checked in by tbretz, 19 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 fHEnergy.Sumw2();
82
83 MBinning binse(50, 20, 50000, "", "log");
84 binse.Apply(fHEnergy);
85}
86
87Bool_t MHThreshold::SetupFill(const MParList *pl)
88{
89 fMcEvt = (MMcEvt*)pl->FindObject("MMcEvt");
90 if (!fMcEvt)
91 {
92 *fLog << err << "MMcEvt not found... abort." << endl;
93 return kFALSE;
94 }
95/*
96 MBinning binse;
97 binse.SetEdges(fHEnergy, 'x');
98
99 MBinning *bins = (MBinning*)pl->FindObject("BinningEnergyEst", "MBinning");
100 if (bins)
101 binse.SetEdges(*bins);
102
103 binse.Apply(fHEnergy);
104 */
105 return kTRUE;
106}
107
108void MHThreshold::Paint(Option_t *option)
109{
110 if (fHEnergy.GetEntries()==0)
111 return;
112
113 TH1D h(fHEnergy);
114
115 Int_t min=1;
116 while (min<h.GetNbinsX() && h.GetBinContent(min)==0)
117 min++;
118 Int_t max=h.GetNbinsX();
119 while (max>min && h.GetBinContent(max)==0)
120 max--;
121
122 if (max-min<5)
123 return;
124
125 h.Smooth(1, min, max);
126
127 const Int_t bin = h.GetMaximumBin();
128 const TAxis &axe = *h.GetXaxis();
129
130 // Assume that the energy binning is logarithmic
131 const Axis_t maxe = TMath::Sqrt(axe.GetBinLowEdge(bin)*axe.GetBinUpEdge(bin));
132
133 TLatex text(0.30, 0.95, Form("E_{max}=%dGeV (%dGeV,%dGeV)", TMath::Nint(maxe),
134 TMath::Nint(axe.GetBinLowEdge(bin)),
135 TMath::Nint(axe.GetBinUpEdge(bin))));
136 text.SetBit(TLatex::kTextNDC);
137 text.SetTextSize(0.04);
138 text.Paint();
139}
140
141void MHThreshold::Draw(Option_t *option)
142{
143 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
144
145 // Do the projection before painting the histograms into
146 // the individual pads
147 pad->SetBorderMode(0);
148
149 gPad->SetLogx();
150 gPad->SetLogy();
151 gPad->SetGridx();
152 gPad->SetGridy();
153
154 fHEnergy.Draw();
155
156 AppendPad();
157}
158
159Bool_t MHThreshold::Fill(const MParContainer *par, const Stat_t weight)
160{
161 const Double_t energy = fMcEvt->GetEnergy();
162
163 fHEnergy.Fill(energy, weight/energy);
164
165 return kTRUE;
166}
Note: See TracBrowser for help on using the repository browser.