source: trunk/MagicSoft/Mars/macros/plot.C@ 4591

Last change on this file since 4591 was 3957, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 4.3 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, 5/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Author(s): Rudy Bock, 5/2002 <mailto:rkb@mppmu.mpg.de>
20!
21! Copyright: MAGIC Software Development, 2000-2004
22!
23!
24\* ======================================================================== */
25
26///////////////////////////////////////////////////////////////////////////
27//
28// plot.C
29// ======
30//
31// This macro shows how to fill and display a histogram using Mars
32//
33// The advantage of using Mars histograms instead of root-trees is that
34// you can fill values in your histogram which is calculated in the
35// eventloop.
36//
37// In this particular sample we fill a histogram with the size parameter
38// of gammas and one with hadron's size. At the end we display both in a
39// single plot.
40//
41// The input is a star-macro already conatining image parameters.
42//
43///////////////////////////////////////////////////////////////////////////
44
45void plot()
46{
47 // Create a status display for graphical output
48 MStatusDisplay *d = new MStatusDisplay;
49 d->SetLogStream(&gLog);
50
51 //
52 // Create a empty Parameter List and an empty Task List
53 // The tasklist is identified in the eventloop by its name
54 //
55 MParList plist;
56
57 MTaskList tlist;
58 plist.AddToList(&tlist);
59
60 //
61 // Now setup the tasks and tasklist:
62 // ---------------------------------
63 //
64
65 // First Task: Read file with image parameters
66 // (created with the star.C macro)
67 MReadMarsFile read("Events", "MC_OFF1.root");
68 read.AddFile("MC_ON1.root");
69 read.DisableAutoScheme();
70 tlist.AddToList(&read);
71
72 // Create a filter for Gammas
73 MFParticleId fgamma("MMcEvt", '=', MMcEvt::kGAMMA);
74 tlist.AddToList(&fgamma);
75
76 // Create a filter for Non-Gammas
77 MFParticleId fhadrons("MMcEvt", '!', MMcEvt::kGAMMA);
78 tlist.AddToList(&fhadrons);
79
80 // -------------------------------------------------------
81 //
82 // set the name of the variable to plot and the binning
83 //
84 TString var("Hillas.fSize");
85
86 MBinning bins("BinningMH3X");
87 bins.SetEdgesLog(50, 100, 20000);
88 plist.AddToList(&bins);
89 //
90 // -------------------------------------------------------
91
92 // Create a histogram for the data from gammas and from non-gammas
93 MH3 h3g(var);
94 MH3 h3h(var);
95
96 // Add the histograms to the parameter container list
97 plist.AddToList(&h3g);
98 plist.AddToList(&h3h);
99
100 // Create a task which fills one histogram with the gamma-data
101 MFillH fillg(&h3g);
102 fillg.SetFilter(&fgamma);
103 tlist.AddToList(&fillg);
104
105 // Create a task which fills the other histogram with the non-gamma-data
106 MFillH fillh(&h3h);
107 fillh.SetFilter(&fhadrons);
108 tlist.AddToList(&fillh);
109
110 //
111 // Create and setup the eventloop
112 //
113 MEvtLoop evtloop;
114 evtloop.SetParList(&plist);
115
116 //
117 // Execute your analysis
118 //
119 evtloop.SetDisplay(d);
120 if (!evtloop.Eventloop())
121 return;
122
123 tlist.PrintStatistics();
124
125 // Create a pad, check if MStatusDisplay was not closed meanwhile
126 if (evtloop.GetDisplay())
127 d->AddTab("Size");
128 else
129 MH::MakeDefCanvas("Plot");
130
131 // x-axis to logarithmic scale
132 gPad->SetLogx();
133
134 // Setup some style options of the two histograms
135 // and draw a copy of both
136 h3h.GetHist().SetLineColor(kRed);
137 MH::DrawCopy(h3h.GetHist(), h3g.GetHist(), "Size");
138
139 // Now create a new histogram, fill it with the division of the
140 // two histograms and draw also a copy of it
141 TH1D h;
142 MH::SetBinning(&h, &bins);
143 h.Divide(&h3g.GetHist(), &h3h.GetHist());
144 h.SetLineColor(kGreen);
145 h.DrawCopy("same");
146}
Note: See TracBrowser for help on using the repository browser.