source: trunk/MagicSoft/Mars/macros/plot2.C@ 5757

Last change on this file since 5757 was 3957, checked in by tbretz, 21 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, 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// plot2.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 width vs length
38// of gammas and hadrons. At the end we display both in a single plot.
39//
40// The input is a star-macro already conatining image parameters.
41//
42///////////////////////////////////////////////////////////////////////////
43
44void plot2()
45{
46 //
47 // Create a empty Parameter List and an empty Task List
48 // The tasklist is identified in the eventloop by its name
49 //
50 MParList plist;
51
52 MTaskList tlist;
53 plist.AddToList(&tlist);
54
55 //
56 // Now setup the tasks and tasklist:
57 // ---------------------------------
58 //
59
60 // First Task: read in a file created with star.C
61 MReadMarsFile read("Events", "star.root");
62 read.DisableAutoScheme();
63 tlist.AddToList(&read);
64
65 // Create a filter for the gamma events
66 MFParticleId fgamma("MMcEvt", '=', MMcEvt::kGAMMA);
67 tlist.AddToList(&fgamma);
68
69 // Create a filter for the non-gamma events
70 MFParticleId fhadrons("MMcEvt", '!', MMcEvt::kGAMMA);
71 tlist.AddToList(&fhadrons);
72
73 // -------------------------------------------------------
74 //
75 // set the name of the variable to plot and the binning
76 //
77 MGeomCamMagic cam;
78 plist.AddToList(&cam);
79
80 // Set the variables (converted to deg)
81 TString vary("MHillas.fWidth*MGeomCam.fConvMm2Deg");
82 TString varx("MHillas.fLength*MGeomCam.fConvMm2Deg");
83
84 // Set the binning
85 MBinning binsy("BinningMH3Y");
86 MBinning binsx("BinningMH3X");
87 binsy.SetEdges(11, 0, 0.3);
88 binsx.SetEdges(11, 0, 0.6);
89 plist.AddToList(&binsx);
90 plist.AddToList(&binsy);
91 //
92 // -------------------------------------------------
93
94 // Create two 2D histograms and add them to the list
95 MH3 h3g(varx, vary);
96 MH3 h3h(varx, vary);
97
98 plist.AddToList(&h3g);
99 plist.AddToList(&h3h);
100
101 // Create a task to fill one histogram with the gamma data
102 MFillH fillg(&h3g);
103 fillg.SetFilter(&fgamma);
104 tlist.AddToList(&fillg);
105
106 // Create a task to fill the other one with the non gamma data
107 MFillH fillh(&h3h);
108 fillh.SetFilter(&fhadrons);
109 tlist.AddToList(&fillh);
110
111 //
112 // Create and setup the eventloop
113 //
114 MEvtLoop evtloop;
115 evtloop.SetParList(&plist);
116
117 //
118 // Execute your analysis
119 //
120 MProgressBar bar;
121 evtloop.SetProgressBar(&bar);
122 if (!evtloop.Eventloop())
123 return;
124
125 tlist.PrintStatistics();
126
127 // Create a default canvas
128 MH::MakeDefCanvas("Plot");
129
130 // setup some style options
131 h3h.GetHist().SetMarkerColor(kRed);
132 h3h.GetHist().SetLineColor(kRed);
133 h3h.GetHist().SetFillStyle(4000);
134
135 // show a contour plot of both histograms
136 h3h.GetHist().DrawCopy("cont3");
137 h3g.GetHist().DrawCopy("cont3same");
138
139 return;
140
141 //
142 // Use this (or something similar) if you want to plot the profile
143 // histograms
144 //
145 TProfile *p = ((TH2&)h3g.GetHist()).ProfileX();
146 p->Draw("same");
147 p->SetBit(kCanDelete);
148
149 TProfile *p = ((TH2&)h3h.GetHist()).ProfileX();
150 p->SetLineColor(kRed);
151 p->SetFillStyle(4000);
152 p->Draw("same");
153 p->SetBit(kCanDelete);
154}
Note: See TracBrowser for help on using the repository browser.