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

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