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

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