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

Last change on this file since 1516 was 1086, checked in by tbretz, 23 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 "MReadTree.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 MReadTree 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 read.SetProgressBar(bar);
258 magic.SetProgressBar(bar);
259
260 //
261 // Execute your analysis
262 //
263 Bool_t rc = magic.Eventloop();
264
265 //
266 // Remove progressbar from window
267 //
268 DestroyProgressBar(bar);
269
270 if (!rc)
271 return;
272
273 //
274 // Now the histogram we wanted to get out of the data is
275 // filled and can be displayd
276 //
277 plist.FindObject("MHMcCollectionArea")->DrawClone();
278}
279
280void MMonteCarlo::CalculateTriggerRate()
281{
282 // This macro has two input parameter:
283 // dim : = 0 -> root file with 1 trigger condition.
284 // > 0 -> number of trigger condition to be analised
285 // in multi conditon file.
286 // < 0 -> selects the -dim trigger condition.
287 //
288 // first we have to create our empty lists
289 //
290 const Int_t dim = GetDim();
291
292 MParList plist;
293 MTaskList tlist;
294
295 //
296 // Setup the parameter list.
297 // - we do not need to create any other container. All of them
298 // are created automatically without loss - we don't have to
299 // access them-
300 //
301 // - we need to create MHMcRate only. The other containers
302 // are created automatically without loss - we don't have to
303 // access them-
304 // - MHMcRate must be created by us because we need the pointer
305 // to it and if it would get created automatically it would also be
306 // deleted automatically
307 // - Actually, depending on using a single trigger option MonteCarlo
308 // file or a multyple trigger option, a MHMcRate or an array of
309 // MHMcRate are needed.
310 //
311 plist.AddToList(&tlist);
312
313 //
314 // You don't have to add the MHMcRate container here by hand.
315 // But if you want to print or display these containers later on
316 // it is necessary (Rem: No printing or displaying is done in this
317 // macro yet)
318 //
319 const UInt_t from = dim>0 ? 1 : -dim;
320 const UInt_t to = dim>0 ? dim : -dim;
321 const Int_t num = to-from+1;
322
323 TObjArray hists(MParList::CreateObjList("MHMcRate", from, to));
324 hists.SetOwner();
325
326 //
327 // Check if the list really contains the right number of histograms
328 //
329 if (hists.GetEntriesFast() != num)
330 return;
331
332 //
333 // Add the histograms to the paramater list.
334 //
335 plist.AddToList(&hists);
336
337 //
338 // FIXME: This line is needed that root finds the MMc-classes in the
339 // dictionary when calling the constructor of MReadTree
340 // I don't have any idea why...
341 // Rem: This happens only in this GUI!
342 //
343 MMcTrig trig;
344
345 //
346 // Setup out tasks:
347 // - First we have to read the events
348 // - Then we can calculate rates, for what the number of
349 // triggered showers from a empty reflector file for the
350 // analised trigger conditions should be set (BgR[])
351 //
352 MReadTree read("Events", fInputFile);
353 tlist.AddToList(&read);
354
355 Float_t BgR[10]={660, 4, 0, 0, 0, 0, 0, 0, 0, 0};
356
357 MMcTriggerRateCalc crate(dim, 14, BgR, 100000);
358 tlist.AddToList(&crate);
359
360 //
361 // set up the loop for the processing
362 //
363 MEvtLoop magic;
364 magic.SetParList(&plist);
365
366 //
367 // Add ProgressBar to window
368 //
369 TGProgressBar *bar = CreateProgressBar(fTop2);
370 read.SetProgressBar(bar);
371 magic.SetProgressBar(bar);
372
373 //
374 // Execute your analysis
375 //
376 Bool_t rc = magic.Eventloop();
377
378 //
379 // Remove progressbar from window
380 //
381 DestroyProgressBar(bar);
382
383 if (!rc)
384 return;
385
386 hists.Print();
387}
388
389void MMonteCarlo::CalculateThreshold()
390{
391 const Int_t dim = GetDim();
392
393 //
394 // This macro fill the container MHMcEnergies using the task
395 // MMcThresholdCalc and shows the results.
396 //
397 MParList plist;
398
399 MTaskList tlist;
400 plist.AddToList(&tlist);
401
402 //
403 // Setup the parameter list
404 // - You need create the container MHMcEnergies.
405 // + You need to put the number of trigger conditions when
406 // you declarete the MHMcEnergies
407 // + If you don't put any dimension to MHMcEnergies it works
408 // taking only the trigger information from MMcTrig
409 //
410
411 //
412 // Create numtriggerconditions histograms of type MHMcEnergy
413 // and store the histograms in an TObjArray
414 //
415 const UInt_t from = dim>0 ? 1 : -dim;
416 const UInt_t to = dim>0 ? dim : -dim;
417 const Int_t num = to-from+1;
418
419 TObjArray hists(MParList::CreateObjList("MHMcEnergy", from, to));
420 hists.SetOwner();
421
422 //
423 // Check if the list really contains the right number of histograms
424 //
425 if (hists.GetEntriesFast() != num)
426 return;
427
428 //
429 // Add the histograms to the paramater list.
430 //
431 plist.AddToList(&hists);
432
433 //
434 // FIXME: This line is needed that root finds the MMc-classes in the
435 // dictionary when calling the constructor of MReadTree
436 // I don't have any idea why...
437 // Rem: This happens only in this GUI!
438 //
439 MMcTrig trig;
440
441 //
442 // Setup the task list
443 // - You need the read and the MMcThresholdCalc tasks
444 // - You have to fill the histograms for the Energy threshold
445 // + You need to put the number of trigger conditions when
446 // you declarete the MMcThresholdCalc
447 // + If you don't put any dimension to MMcThresholdCalc it works
448 // like one dimension MMcThresholdCalc
449 //
450
451 MReadTree read("Events", fInputFile);
452
453 MMcThresholdCalc calc(dim);
454 tlist.AddToList(&read);
455 tlist.AddToList(&calc);
456
457 MEvtLoop evtloop;
458 evtloop.SetParList(&plist);
459
460 //
461 // Add ProgressBar to window
462 //
463 TGProgressBar *bar = CreateProgressBar(fTop2);
464 read.SetProgressBar(bar);
465 evtloop.SetProgressBar(bar);
466
467 //
468 // Execute your analysis
469 //
470 Bool_t rc = evtloop.Eventloop();
471
472 //
473 // Remove progressbar from window
474 //
475 DestroyProgressBar(bar);
476
477 if (!rc)
478 return;
479
480 //
481 // Now you can display the results
482 //
483 TIter Next(&hists);
484 TObject *obj;
485 while ((obj=Next()))
486 obj->DrawClone();
487}
488
489// ======================================================================
490
491Bool_t MMonteCarlo::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
492{
493 if (GET_MSG(msg) == kC_COMMAND && GET_SUBMSG(msg) == kCM_BUTTON)
494 switch (parm1)
495 {
496 case kButCollArea:
497 CalculateCollectionArea();
498 return kTRUE;
499
500 case kButTrigRate:
501 CalculateTriggerRate();
502 return kTRUE;
503
504 case kButThreshold:
505 CalculateThreshold();
506 return kTRUE;
507 }
508
509 return MBrowser::ProcessMessage(msg, parm1, parm2);
510}
Note: See TracBrowser for help on using the repository browser.