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

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