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

Last change on this file since 8955 was 8911, checked in by tbretz, 17 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 "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 Int_t min=1;
119 while (min<h.GetNbinsX() && h.GetBinContent(min)==0)
120 min++;
121 Int_t max=h.GetNbinsX();
122 while (max>min && h.GetBinContent(max)==0)
123 max--;
124
125 if (max-min<5)
126 return;
127
128 h.Smooth(1, min, max);
129
130 const Int_t bin = h.GetMaximumBin();
131 const TAxis &axe = *h.GetXaxis();
132
133 // Assume that the energy binning is logarithmic
134 const Axis_t maxe = TMath::Sqrt(axe.GetBinLowEdge(bin)*axe.GetBinUpEdge(bin));
135
136 TLatex text(0.30, 0.95, Form("E_{max}=%dGeV (%dGeV,%dGeV)", TMath::Nint(maxe),
137 TMath::Nint(axe.GetBinLowEdge(bin)),
138 TMath::Nint(axe.GetBinUpEdge(bin))));
139 text.SetBit(TLatex::kTextNDC);
140 text.SetTextSize(0.04);
141 text.Paint();
142}
143
144void MHThreshold::Draw(Option_t *option)
145{
146 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
147
148 // Do the projection before painting the histograms into
149 // the individual pads
150 pad->SetBorderMode(0);
151
152 gPad->SetLogx();
153 gPad->SetLogy();
154 gPad->SetGridx();
155 gPad->SetGridy();
156
157 fHEnergy.Draw();
158
159 AppendPad();
160}
161
162Bool_t MHThreshold::Fill(const MParContainer *par, const Stat_t weight)
163{
164 const Double_t energy = fMcEvt->GetEnergy();
165
166 fHEnergy.Fill(energy, weight/energy);
167
168 return kTRUE;
169}
Note: See TracBrowser for help on using the repository browser.