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

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