source: trunk/MagicSoft/Mars/mmain/MAnalysis.cc@ 951

Last change on this file since 951 was 951, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 8.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 9/2001 (tbretz@uni-sw.gwdg.de)
19!
20! Copyright: MAGIC Software Development, 2000-2001
21!
22!
23\* ======================================================================== */
24
25#include "MAnalysis.h"
26
27#include <stdlib.h> // atof
28#include <iostream.h>
29
30#include <TGLabel.h> // TGlabel
31#include <TGButton.h> // TGTextButton
32#include <TGTextEntry.h> // TGNumberEntry
33
34ClassImp(MAnalysis)
35
36enum {
37 M_BUTTON_HILLAS
38};
39
40void MAnalysis::AddButtons()
41{
42 TGTextButton *hillas = new TGTextButton(fTop2, "Calculate Standard Hillas", M_BUTTON_HILLAS);
43
44 hillas->Associate(this);
45
46 fList->Add(hillas);
47
48 TGLayoutHints *laybut = new TGLayoutHints(kLHintsTop|kLHintsLeft, 10, 10, 5, 5);
49 fList->Add(laybut);
50
51 fTop2->AddFrame(hillas, laybut);
52}
53
54void MAnalysis::AddSetupTab()
55{
56 //
57 // Create Setup Tab
58 //
59 TGCompositeFrame *frame = CreateNewTab("Setup");
60
61 //
62 // Align the lines:
63 // - top, left
64 // - padding: top=20, bottom=0, left=20, right=0
65 //
66 TGLayoutHints *layline = new TGLayoutHints(kLHintsNormal, 20, 0, 20);
67 fList->Add(layline);
68
69 //
70 // Create check buttons for the first two lines
71 //
72 fCheckButton1 = new TGCheckButton(frame, "Display Hillas Histograms when finished"); //, M_CHECK_DISPLHIL);
73 fCheckButton2 = new TGCheckButton(frame, "Display Star Map Histogram when finished"); //, M_CHECK_DISPLHIL);
74
75 fList->Add(fCheckButton1);
76 fList->Add(fCheckButton2);
77
78 //
79 // Create first two lines with the checkbuttons
80 //
81 frame->AddFrame(fCheckButton1, layline);
82 frame->AddFrame(fCheckButton2, layline);
83
84 //
85 // Create entry fields and labels for line 3 and 4
86 //
87
88 /*
89 * --> use with root >=3.02 <--
90 *
91
92 TGNumberEntry *fNumEntry1 = new TGNumberEntry(frame, 3.0, 2, M_NENT_LVL1, kNESRealOne, kNEANonNegative);
93 TGNumberEntry *fNumEntry2 = new TGNumberEntry(frame, 2.5, 2, M_NENT_LVL1, kNESRealOne, kNEANonNegative);
94
95 */
96
97 //
98 // Create a frame for line 3 and 4 to be able
99 // to align entry field and label in one line
100 //
101 TGHorizontalFrame *f1 = new TGHorizontalFrame(frame, 0, 0);
102 TGHorizontalFrame *f2 = new TGHorizontalFrame(frame, 0, 0);
103
104 fNumEntry1 = new TGTextEntry(f1, "****");
105 fNumEntry2 = new TGTextEntry(f2, "****");
106
107 // --- doesn't work like expected --- fNumEntry1->SetAlignment(kTextRight);
108 // --- doesn't work like expected --- fNumEntry2->SetAlignment(kTextRight);
109
110 fNumEntry1->SetText("3.0");
111 fNumEntry2->SetText("2.5");
112
113 fList->Add(fNumEntry1);
114 fList->Add(fNumEntry2);
115
116 TGLabel *l1 = new TGLabel(f1, "Cleaning Level 1 for standard image cleaning.");
117 TGLabel *l2 = new TGLabel(f2, "Cleaning Level 2 for standard image cleaning.");
118
119 l1->SetTextJustify(kTextLeft);
120 l2->SetTextJustify(kTextLeft);
121
122 fList->Add(l1);
123 fList->Add(l2);
124
125 //
126 // Align the text of the label centered, left in the row
127 // with a left padding of 10
128 //
129 TGLayoutHints *laylabel = new TGLayoutHints(kLHintsCenterY|kLHintsLeft, 10); //, 10); //, 5, 5);
130 fList->Add(laylabel);
131
132 //
133 // Add one entry field and the corresponding label to each line
134 //
135 f1->AddFrame(fNumEntry1);
136 f2->AddFrame(fNumEntry2);
137
138 f1->AddFrame(l1, laylabel);
139 f2->AddFrame(l2, laylabel);
140
141 //
142 // Add line 3 and 4 to tab
143 //
144 frame->AddFrame(f1, layline);
145 frame->AddFrame(f2, layline);
146}
147
148MAnalysis::MAnalysis(const TGWindow *main, const TGWindow *p,
149 const UInt_t w, const UInt_t h)
150: MBrowser(main, p, w, h)
151{
152 AddButtons();
153 AddSetupTab();
154
155 MapSubwindows();
156
157 Layout();
158
159 SetWindowName("Analysis Window");
160 SetIconName("Analysis");
161
162 MapWindow();
163}
164
165// ======================================================================
166
167#include "MParList.h"
168#include "MTaskList.h"
169#include "MGeomCamMagic.h"
170#include "MPedestalCam.h"
171#include "MHHillas.h"
172#include "MHStarMap.h"
173#include "MReadTree.h"
174#include "MCerPhotCalc.h"
175#include "MImgCleanStd.h"
176#include "MHillasCalc.h"
177#include "MFillH.h"
178#include "MEvtLoop.h"
179#include "MHillas.h"
180
181void MAnalysis::CalculateHillas() const
182{
183 //
184 // This is a demonstration program which calculates the Hillas
185 // parameter out of a Magic root file.
186
187 const Bool_t displhillas = fCheckButton1->GetState();
188 const Bool_t displstarmap = fCheckButton2->GetState();
189
190 Float_t cleanlvl1 = atof(fNumEntry1->GetText());
191 Float_t cleanlvl2 = atof(fNumEntry2->GetText());
192
193 if (cleanlvl1<0)
194 {
195 cleanlvl1=0;
196 fNumEntry1->SetText("0");
197 }
198
199 if (cleanlvl2<0)
200 {
201 cleanlvl2=0;
202 fNumEntry2->SetText("0");
203 }
204
205 //
206 // Create a empty Parameter List and an empty Task List
207 // The tasklist is identified in the eventloop by its name
208 //
209 MParList plist;
210
211 MTaskList tlist;
212 plist.AddToList(&tlist);
213
214 //
215 // The geometry container must be created by yourself to make sure
216 // that you don't choos a wrong geometry by chance
217 //
218 MGeomCamMagic geomcam;
219 plist.AddToList(&geomcam);
220
221 MPedestalCam pedest;
222 plist.AddToList(&pedest);
223
224 //
225 // The Hillas histograms (MHHillas) could be created automatically
226 // but to make sure, that they are not deleted when the macro is
227 // finished you must create them yourself and add it to the list
228 //
229 MHillas hillas;
230 plist.AddToList(&hillas);
231
232 MHHillas *hists = new MHHillas;
233 plist.AddToList(hists);
234
235 MHStarMap *smap = new MHStarMap;
236 plist.AddToList(smap);
237
238 // FIXME: Where do we delete this two objects???
239
240 //
241 // Now setup the tasks and tasklist:
242 //
243 // 1) read in the data from a magic root file MReadTree
244 // 2) calculate number of cerenkov photons MCerPhotCalc
245 // 3) clean the image MImgCleanStd
246 // 4) calculate hillas MHillasCalc
247 // 5) fill the hillas into the histograms MFillH
248 //
249
250 //
251 // The first argument is the tree you want to read.
252 // Events: Cosmic ray events
253 // PedEvents: Pedestal Events
254 // CalEvents: Calibration Events
255 //
256 MReadTree read("Events", fInputFile);
257 MCerPhotCalc ncalc;
258 MImgCleanStd clean(cleanlvl1, cleanlvl2);
259 MHillasCalc hcalc;
260 MFillH hfill(&hillas, hists);
261 MFillH sfill(&hillas, smap);
262
263 tlist.AddToList(&read);
264 tlist.AddToList(&ncalc);
265 tlist.AddToList(&clean);
266 tlist.AddToList(&hcalc);
267 tlist.AddToList(&hfill);
268 tlist.AddToList(&sfill);
269
270 //
271 // Create and setup the eventloop
272 //
273 MEvtLoop evtloop;
274 evtloop.SetParList(&plist);
275
276 //
277 // Execute your analysis
278 //
279 if (!evtloop.Eventloop())
280 return;
281
282 //
283 // After the analysis is finished we can display the histograms
284 //
285
286 if (displhillas)
287 hists->Draw();
288
289 if (displstarmap)
290 smap->Draw();
291
292 cout << "Calculation of Hillas Parameters finished without error!" << endl;
293}
294
295// ======================================================================
296
297Bool_t MAnalysis::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
298{
299 // Process events generated by the buttons in the frame.
300
301 if (GET_MSG(msg)!=kC_COMMAND || GET_SUBMSG(msg)!=kCM_BUTTON)
302 return MBrowser::ProcessMessage(msg, parm1, parm2);
303
304 switch (parm1)
305 {
306 case M_BUTTON_HILLAS:
307 if (!InputFileSelected())
308 {
309 DisplError("No Input (root) File selected!");
310 return kTRUE;
311 }
312
313 switch (parm1)
314 {
315 case M_BUTTON_HILLAS:
316 CalculateHillas();
317 return kTRUE;
318 }
319 return kTRUE;
320 }
321
322 return MBrowser::ProcessMessage(msg, parm1, parm2);
323}
Note: See TracBrowser for help on using the repository browser.