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

Last change on this file since 972 was 954, 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 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 // Now setup the tasks and tasklist:
226 //
227 // 1) read in the data from a magic root file MReadTree
228 // 2) calculate number of cerenkov photons MCerPhotCalc
229 // 3) clean the image MImgCleanStd
230 // 4) calculate hillas MHillasCalc
231 // 5) fill the hillas into the histograms MFillH
232 //
233
234 //
235 // The first argument is the tree you want to read.
236 // Events: Cosmic ray events
237 // PedEvents: Pedestal Events
238 // CalEvents: Calibration Events
239 //
240 MReadTree read("Events", fInputFile);
241 MCerPhotCalc ncalc;
242 MImgCleanStd clean(cleanlvl1, cleanlvl2);
243 MHillasCalc hcalc;
244
245 tlist.AddToList(&read);
246 tlist.AddToList(&ncalc);
247 tlist.AddToList(&clean);
248 tlist.AddToList(&hcalc);
249
250 MFillH hfill("MHillas", "MHHillas");
251 MFillH sfill("MHillas", "MHStarMap");
252
253 if (displhillas)
254 tlist.AddToList(&hfill);
255
256 if (displstarmap)
257 tlist.AddToList(&sfill);
258
259 //
260 // Create and setup the eventloop
261 //
262 MEvtLoop evtloop;
263 evtloop.SetParList(&plist);
264
265 //
266 // Execute your analysis
267 //
268 if (!evtloop.Eventloop())
269 return;
270
271 //
272 // After the analysis is finished we can display the histograms
273 //
274 if (displhillas)
275 plist.FindObject("MHHillas")->DrawClone();
276
277 if (displstarmap)
278 plist.FindObject("MHStarMap")->DrawClone();
279
280 cout << endl;
281 cout << "Calculation of Hillas Parameters finished without error!" << endl;
282}
283
284// ======================================================================
285
286Bool_t MAnalysis::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
287{
288 // Process events generated by the buttons in the frame.
289
290 if (GET_MSG(msg)!=kC_COMMAND || GET_SUBMSG(msg)!=kCM_BUTTON)
291 return MBrowser::ProcessMessage(msg, parm1, parm2);
292
293 switch (parm1)
294 {
295 case M_BUTTON_HILLAS:
296 if (!InputFileSelected())
297 {
298 DisplError("No Input (root) File selected!");
299 return kTRUE;
300 }
301
302 switch (parm1)
303 {
304 case M_BUTTON_HILLAS:
305 CalculateHillas();
306 return kTRUE;
307 }
308 return kTRUE;
309 }
310
311 return MBrowser::ProcessMessage(msg, parm1, parm2);
312}
Note: See TracBrowser for help on using the repository browser.