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

Last change on this file since 7470 was 7302, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 3.9 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 Thrshold");
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(80, 10, 1000000, "", "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 const TAxis &axe = *fHEnergy.GetXaxis();
111
112 const Int_t bin = fHEnergy.GetMaximumBin();
113
114 // Assume that the energy binning is logarithmic
115 const Axis_t maxe = TMath::Sqrt(axe.GetBinLowEdge(bin)*axe.GetBinUpEdge(bin));
116
117 TLatex text(0.30, 0.95, Form("E_{max}=%dGeV", TMath::Nint(maxe)));
118 text.SetBit(TLatex::kTextNDC);
119 text.SetTextSize(0.04);
120 text.Paint();
121}
122
123void MHThreshold::Draw(Option_t *option)
124{
125 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
126
127 // Do the projection before painting the histograms into
128 // the individual pads
129 pad->SetBorderMode(0);
130
131 gPad->SetLogx();
132 gPad->SetLogy();
133
134 fHEnergy.Draw();
135
136 AppendPad();
137}
138
139Bool_t MHThreshold::Fill(const MParContainer *par, const Stat_t weight)
140{
141 const Double_t energy = fMcEvt->GetEnergy();
142
143 fHEnergy.Fill(energy, weight/energy);
144
145 return kTRUE;
146}
Note: See TracBrowser for help on using the repository browser.