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

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