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

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