source: trunk/MagicSoft/Mars/mmain/MMonteCarlo.cc@ 1689

Last change on this file since 1689 was 1668, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 13.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 12/2000 <mailto:tbretz@uni-sw.gwdg.de>
19! Author(s): Harald Kornmayer 1/2001
20!
21! Copyright: MAGIC Software Development, 2000-2001
22!
23!
24\* ======================================================================== */
25
26#include "MMonteCarlo.h"
27
28#include <stdlib.h>
29#include <iostream.h>
30
31#include <TGLabel.h> // TGLabel
32#include <TGButton.h> // TGTextButton
33#include <TGTextEntry.h> // TGTextEntry
34#include <TGProgressBar.h> // TGHProgressBar
35#include <TGButtonGroup.h> // TGVButtonGroup
36
37#include "MGList.h"
38
39ClassImp(MMonteCarlo)
40
41enum {
42 kButCollArea = 0x100,
43 kButTrigRate = 0x101,
44 kButThreshold = 0x102
45};
46
47void MMonteCarlo::AddButtons()
48{
49 TGTextButton *carea = new TGTextButton(fTop2, "Collection Area", kButCollArea);
50 TGTextButton *trate = new TGTextButton(fTop2, "Trigger Rate", kButTrigRate);
51 TGTextButton *thold = new TGTextButton(fTop2, "Threshold", kButThreshold);
52
53 fList->Add(carea);
54 fList->Add(trate);
55 fList->Add(thold);
56
57 carea->Associate(this);
58 trate->Associate(this);
59 thold->Associate(this);
60
61 TGLayoutHints *laybut = new TGLayoutHints(kLHintsNormal, 5, 5, 10, 10);
62 fList->Add(laybut);
63
64 fTop2->AddFrame(carea, laybut);
65 fTop2->AddFrame(trate, laybut);
66 fTop2->AddFrame(thold, laybut);
67}
68
69void MMonteCarlo::AddSetupTab()
70{
71 //
72 // Create Setup Tab
73 //
74 TGCompositeFrame *frame = CreateNewTab("Setup");
75
76 //
77 // Create a button group (it alignes the buttons and make
78 // them automatic radio buttons)
79 // Create three (auto) radio buttons in the button group
80 //
81 TGVButtonGroup *group = new TGVButtonGroup(frame);
82 fList->Add(group);
83
84 fRadioButton1 = new TGRadioButton(group, "Use unnumbered trigger condition olny.");
85 fRadioButton2 = new TGRadioButton(group, "Use only one trigger condition (specify number below).");
86 fRadioButton3 = new TGRadioButton(group, "Use a number of trigger conditions (1..n).");
87
88 fRadioButton1->SetState(kButtonDown);
89
90 /*
91 WARNING:
92 Bacause of some strage and hidden dependencies the
93 GetMaiFrame call in the destructor of TGButton may fail if some
94 of the other gui elemts is deleted first.
95 AddFirst adds the buttons at the beginning of the deletion list,
96 this seems to work.
97 */
98 fList->AddFirst(fRadioButton1);
99 fList->AddFirst(fRadioButton2);
100 fList->AddFirst(fRadioButton3);
101
102 //
103 // Add the button group (all buttons) as first line
104 //
105 frame->AddFrame(group);
106
107 //
108 // Create entry fields and labels for line 3 and 4
109 //
110
111 /*
112 * --> use with root >=3.02 <--
113 *
114
115 TGNumberEntry *fNumEntry1 = new TGNumberEntry(frame, 3.0, 2, M_NENT_LVL1, kNESRealOne, kNEANonNegative);
116 TGNumberEntry *fNumEntry2 = new TGNumberEntry(frame, 2.5, 2, M_NENT_LVL1, kNESRealOne, kNEANonNegative);
117
118 */
119
120 //
121 // Align the lines:
122 // - top, left
123 // - padding: top=20, bottom=0, left=20, right=0
124 //
125 TGLayoutHints *layline = new TGLayoutHints(kLHintsNormal, 20, 0, 20);
126 fList->Add(layline);
127
128
129 //
130 // Create a frame for line 3 and 4 to be able
131 // to align entry field and label in one line
132 //
133 TGHorizontalFrame *f = new TGHorizontalFrame(frame, 0, 0);
134 fNumEntry = new TGTextEntry(f, "****");
135 fNumEntry->SetText("1");
136 fList->Add(fNumEntry);
137
138 // --- doesn't work like expected --- fNumEntry1->SetAlignment(kTextRight);
139 // --- doesn't work like expected --- fNumEntry2->SetAlignment(kTextRight);
140
141 TGLabel *l = new TGLabel(f, "Trigger Condition Setup.");
142 l->SetTextJustify(kTextLeft);
143 fList->Add(l);
144
145 //
146 // Align the text of the label centered, left in the row
147 // with a left padding of 10
148 //
149 TGLayoutHints *laylabel = new TGLayoutHints(kLHintsCenterY|kLHintsLeft, 10); //, 10); //, 5, 5);
150 fList->Add(laylabel);
151
152 //
153 // Add one entry field and the corresponding label to each line
154 //
155 f->AddFrame(fNumEntry);
156 f->AddFrame(l, laylabel);
157
158 //
159 // Add line 3 and 4 to tab
160 //
161 frame->AddFrame(f, layline);
162}
163
164MMonteCarlo::MMonteCarlo(/*const TGWindow *main,*/ const TGWindow *p,
165 const UInt_t w, const UInt_t h)
166: MBrowser(/*main,*/ p, w, h)
167{
168 AddButtons();
169 AddSetupTab();
170
171 MapSubwindows();
172
173 Layout();
174
175 SetWindowName("MonteCarlo Main");
176 SetIconName("MonteCarlo");
177
178 MapWindow();
179}
180
181// ======================================================================
182#include <TObjArray.h>
183
184#include "MParList.h"
185#include "MTaskList.h"
186#include "MEvtLoop.h"
187
188#include "MReadMarsFile.h"
189
190#include "MHMcRate.h"
191#include "MHMcEnergy.h"
192
193#include "MMcTriggerRateCalc.h"
194#include "MMcThresholdCalc.h"
195#include "MMcCollectionAreaCalc.h"
196
197#include "../mmc/MMcTrig.hxx" // FIXME: see FIXME below
198
199Int_t MMonteCarlo::GetDim() const
200{
201 Int_t dim = atoi(fNumEntry->GetText());
202
203 if (dim<0)
204 {
205 dim=0;
206 fNumEntry->SetText("0");
207 }
208
209 if (fRadioButton1->GetState())
210 dim = 0;
211
212 if (fRadioButton2->GetState())
213 dim = -dim;
214
215 return dim;
216}
217
218void MMonteCarlo::CalculateCollectionArea()
219{
220 //
221 // first we have to create our empty lists
222 //
223 MParList plist;
224
225 MTaskList tlist;
226 plist.AddToList(&tlist);
227
228 //
229 // FIXME: This line is needed that root finds the MMc-classes in the
230 // dictionary when calling the constructor of MReadTree
231 // I don't have any idea why...
232 // Rem: This happens only in this GUI!
233 //
234 MMcTrig trig;
235
236 //
237 // Setup out tasks:
238 // - First we have to read the events
239 // - Then we can fill the efficiency histograms
240 //
241 MReadMarsFile read("Events", fInputFile);
242 tlist.AddToList(&read);
243
244 MMcCollectionAreaCalc effi;
245 tlist.AddToList(&effi);
246
247 //
248 // set up the loop for the processing
249 //
250 MEvtLoop magic;
251 magic.SetParList(&plist);
252
253 //
254 // Add ProgressBar to window
255 //
256 TGProgressBar *bar = CreateProgressBar(fTop2);
257 magic.SetProgressBar(bar);
258
259 //
260 // Execute your analysis
261 //
262 Bool_t rc = magic.Eventloop();
263
264 //
265 // Remove progressbar from window
266 //
267 DestroyProgressBar(bar);
268
269 if (!rc)
270 return;
271
272 //
273 // Now the histogram we wanted to get out of the data is
274 // filled and can be displayd
275 //
276 plist.FindObject("MHMcCollectionArea")->DrawClone();
277}
278
279void MMonteCarlo::CalculateTriggerRate()
280{
281 // This macro has two input parameter:
282 // dim : = 0 -> root file with 1 trigger condition.
283 // > 0 -> number of trigger condition to be analised
284 // in multi conditon file.
285 // < 0 -> selects the -dim trigger condition.
286 //
287 // first we have to create our empty lists
288 //
289 const Int_t dim = GetDim();
290
291 MParList plist;
292 MTaskList tlist;
293
294 //
295 // Setup the parameter list.
296 // - we do not need to create any other container. All of them
297 // are created automatically without loss - we don't have to
298 // access them-
299 //
300 // - we need to create MHMcRate only. The other containers
301 // are created automatically without loss - we don't have to
302 // access them-
303 // - MHMcRate must be created by us because we need the pointer
304 // to it and if it would get created automatically it would also be
305 // deleted automatically
306 // - Actually, depending on using a single trigger option MonteCarlo
307 // file or a multyple trigger option, a MHMcRate or an array of
308 // MHMcRate are needed.
309 //
310 plist.AddToList(&tlist);
311
312 //
313 // You don't have to add the MHMcRate container here by hand.
314 // But if you want to print or display these containers later on
315 // it is necessary (Rem: No printing or displaying is done in this
316 // macro yet)
317 //
318 const UInt_t from = dim>0 ? 1 : -dim;
319 const UInt_t to = dim>0 ? dim : -dim;
320 const Int_t num = to-from+1;
321
322 TObjArray hists(MParList::CreateObjList("MHMcRate", from, to));
323 hists.SetOwner();
324
325 //
326 // Check if the list really contains the right number of histograms
327 //
328 if (hists.GetEntriesFast() != num)
329 return;
330
331 //
332 // Add the histograms to the paramater list.
333 //
334 plist.AddToList(&hists);
335
336 //
337 // FIXME: This line is needed that root finds the MMc-classes in the
338 // dictionary when calling the constructor of MReadTree
339 // I don't have any idea why...
340 // Rem: This happens only in this GUI!
341 //
342 MMcTrig trig;
343
344 //
345 // Setup out tasks:
346 // - First we have to read the events
347 // - Then we can calculate rates, for what the number of
348 // triggered showers from a empty reflector file for the
349 // analised trigger conditions should be set (BgR[])
350 //
351 MReadTree read("Events", fInputFile);
352 tlist.AddToList(&read);
353
354 Float_t BgR[10]={660, 4, 0, 0, 0, 0, 0, 0, 0, 0};
355
356 MMcTriggerRateCalc crate(dim, 14, BgR, 100000);
357 tlist.AddToList(&crate);
358
359 //
360 // set up the loop for the processing
361 //
362 MEvtLoop magic;
363 magic.SetParList(&plist);
364
365 //
366 // Add ProgressBar to window
367 //
368 TGProgressBar *bar = CreateProgressBar(fTop2);
369 magic.SetProgressBar(bar);
370
371 //
372 // Execute your analysis
373 //
374 Bool_t rc = magic.Eventloop();
375
376 //
377 // Remove progressbar from window
378 //
379 DestroyProgressBar(bar);
380
381 if (!rc)
382 return;
383
384 hists.Print();
385}
386
387void MMonteCarlo::CalculateThreshold()
388{
389 const Int_t dim = GetDim();
390
391 //
392 // This macro fill the container MHMcEnergies using the task
393 // MMcThresholdCalc and shows the results.
394 //
395 MParList plist;
396
397 MTaskList tlist;
398 plist.AddToList(&tlist);
399
400 //
401 // Setup the parameter list
402 // - You need create the container MHMcEnergies.
403 // + You need to put the number of trigger conditions when
404 // you declarete the MHMcEnergies
405 // + If you don't put any dimension to MHMcEnergies it works
406 // taking only the trigger information from MMcTrig
407 //
408
409 //
410 // Create numtriggerconditions histograms of type MHMcEnergy
411 // and store the histograms in an TObjArray
412 //
413 const UInt_t from = dim>0 ? 1 : -dim;
414 const UInt_t to = dim>0 ? dim : -dim;
415 const Int_t num = to-from+1;
416
417 TObjArray hists(MParList::CreateObjList("MHMcEnergy", from, to));
418 hists.SetOwner();
419
420 //
421 // Check if the list really contains the right number of histograms
422 //
423 if (hists.GetEntriesFast() != num)
424 return;
425
426 //
427 // Add the histograms to the paramater list.
428 //
429 plist.AddToList(&hists);
430
431 //
432 // FIXME: This line is needed that root finds the MMc-classes in the
433 // dictionary when calling the constructor of MReadTree
434 // I don't have any idea why...
435 // Rem: This happens only in this GUI!
436 //
437 MMcTrig trig;
438
439 //
440 // Setup the task list
441 // - You need the read and the MMcThresholdCalc tasks
442 // - You have to fill the histograms for the Energy threshold
443 // + You need to put the number of trigger conditions when
444 // you declarete the MMcThresholdCalc
445 // + If you don't put any dimension to MMcThresholdCalc it works
446 // like one dimension MMcThresholdCalc
447 //
448
449 MReadTree read("Events", fInputFile);
450
451 MMcThresholdCalc calc(dim);
452 tlist.AddToList(&read);
453 tlist.AddToList(&calc);
454
455 MEvtLoop evtloop;
456 evtloop.SetParList(&plist);
457
458 //
459 // Add ProgressBar to window
460 //
461 TGProgressBar *bar = CreateProgressBar(fTop2);
462 evtloop.SetProgressBar(bar);
463
464 //
465 // Execute your analysis
466 //
467 Bool_t rc = evtloop.Eventloop();
468
469 //
470 // Remove progressbar from window
471 //
472 DestroyProgressBar(bar);
473
474 if (!rc)
475 return;
476
477 //
478 // Now you can display the results
479 //
480 TIter Next(&hists);
481 TObject *obj;
482 while ((obj=Next()))
483 obj->DrawClone();
484}
485
486// ======================================================================
487
488Bool_t MMonteCarlo::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
489{
490 if (GET_MSG(msg) == kC_COMMAND && GET_SUBMSG(msg) == kCM_BUTTON)
491 switch (parm1)
492 {
493 case kButCollArea:
494 CalculateCollectionArea();
495 return kTRUE;
496
497 case kButTrigRate:
498 CalculateTriggerRate();
499 return kTRUE;
500
501 case kButThreshold:
502 CalculateThreshold();
503 return kTRUE;
504 }
505
506 return MBrowser::ProcessMessage(msg, parm1, parm2);
507}
Note: See TracBrowser for help on using the repository browser.