source: branches/Mars_use_drstimefiles/mmain/MMonteCarlo.cc@ 18459

Last change on this file since 18459 was 7804, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 11.9 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#if ROOT_VERSION_CODE < ROOT_VERSION(3,05,05)
200#include "../mmc/MMcTrig.hxx" // FIXME: see FIXME below
201#endif
202
203Int_t MMonteCarlo::GetDim() const
204{
205 Int_t dim = atoi(fNumEntry->GetText());
206
207 if (dim<0)
208 {
209 dim=0;
210 fNumEntry->SetText("0");
211 }
212
213 if (fRadioButton1->GetState())
214 dim = 0;
215
216 if (fRadioButton2->GetState())
217 dim = -dim;
218
219 return dim;
220}
221
222void MMonteCarlo::CalculateCollectionArea()
223{
224 //
225 // first we have to create our empty lists
226 //
227 MParList plist;
228
229 MTaskList tlist;
230 plist.AddToList(&tlist);
231
232#if ROOT_VERSION_CODE < ROOT_VERSION(3,05,05)
233 //
234 // FIXME: This line is needed that root finds the MMc-classes in the
235 // dictionary when calling the constructor of MReadTree
236 // I don't have any idea why...
237 // Rem: This happens only in this GUI!
238 //
239 MMcTrig trig;
240#endif
241
242 //
243 // Setup out tasks:
244 // - First we have to read the events
245 // - Then we can fill the efficiency histograms
246 //
247 MReadMarsFile read("Events", fInputFile);
248 tlist.AddToList(&read);
249
250 MMcCollectionAreaCalc effi;
251 tlist.AddToList(&effi);
252
253 //
254 // set up the loop for the processing
255 //
256 MEvtLoop magic;
257 magic.SetParList(&plist);
258
259 //
260 // Add ProgressBar to window
261 //
262 TGProgressBar *bar = CreateProgressBar(fTop2);
263 magic.SetProgressBar(bar);
264
265 //
266 // Execute your analysis
267 //
268 Bool_t rc = magic.Eventloop();
269
270 //
271 // Remove progressbar from window
272 //
273 DestroyProgressBar(bar);
274
275 if (!rc)
276 return;
277
278 //
279 // Now the histogram we wanted to get out of the data is
280 // filled and can be displayd
281 //
282 plist.FindObject("MHMcCollectionArea")->DrawClone();
283}
284
285void MMonteCarlo::CalculateTriggerRate()
286{
287 //
288 // dim : = 0 -> root file with 1 trigger condition.
289 // > 0 -> number of trigger condition to be analised
290 // in multi conditon file.
291 // < 0 -> selects the -dim trigger condition.
292 //
293 const Int_t dim = GetDim();
294
295 MParList plist;
296 MTaskList tlist;
297
298 //
299 // Setup the parameter list.
300 //
301 plist.AddToList(&tlist);
302
303 const UInt_t from = dim>0 ? 1 : -dim;
304 const UInt_t to = dim>0 ? dim : -dim;
305 const Int_t num = to-from+1;
306
307 TObjArray hists(MParList::CreateObjList("MHMcRate", from, to));
308 hists.SetOwner();
309
310 //
311 // Check if the list really contains the right number of histograms
312 //
313 if (hists.GetEntriesFast() != num)
314 return;
315
316 //
317 // Set for each MHMcRate object the trigger condition number in the
318 // camera file (for the case of camera files with several conditions,
319 // produced with the trigger_loop option.
320 //
321 if (dim < 0)
322 ((MHMcRate*)(hists[0]))->SetTriggerCondNum(to);
323 else
324 for (UInt_t i=from; i<=to; i++)
325 ((MHMcRate*)(hists[i-1]))->SetTriggerCondNum(i);
326
327 //
328 // Add the histograms to the parameter list.
329 //
330 plist.AddToList(&hists);
331
332#if ROOT_VERSION_CODE < ROOT_VERSION(3,05,05)
333 //
334 // FIXME: This line is needed that root finds the MMc-classes in the
335 // dictionary when calling the constructor of MReadTree
336 // I don't have any idea why...
337 // Rem: This happens only in this GUI!
338 //
339 MMcTrig trig;
340#endif
341
342 //
343 // Setup out tasks:
344 // - First we have to read the events
345 // - Then we can calculate rates, for what the number of
346 // triggered showers from a empty reflector file for the
347 // analised trigger conditions should be set (BgR[])
348 //
349 MReadMarsFile read("Events", fInputFile);
350 tlist.AddToList(&read);
351
352 // We calculate only shower rate (not including NSB-only triggers)
353 Float_t* BgR = new Float_t[num];
354 memset(BgR, 0, num*sizeof(Float_t));
355
356 MMcTriggerRateCalc crate(dim, 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 delete BgR;
382
383 if (!rc)
384 return;
385
386 hists.Print();
387}
388
389void MMonteCarlo::CalculateThreshold()
390{
391 const Int_t dim = GetDim();
392
393 MParList plist;
394
395 MTaskList tlist;
396 plist.AddToList(&tlist);
397
398 //
399 // Create numtriggerconditions histograms of type MHMcEnergy
400 // and store the histograms in an TObjArray
401 //
402 const UInt_t from = dim>0 ? 1 : -dim;
403 const UInt_t to = dim>0 ? dim : -dim;
404 const Int_t num = to-from+1;
405
406 TObjArray hists(MParList::CreateObjList("MHMcEnergy", from, to));
407 hists.SetOwner();
408
409 //
410 // Check if the list really contains the right number of histograms
411 //
412 if (hists.GetEntriesFast() != num)
413 return;
414
415 //
416 // Add the histograms to the paramater list.
417 //
418 plist.AddToList(&hists);
419
420#if ROOT_VERSION_CODE < ROOT_VERSION(3,05,05)
421 //
422 // FIXME: This line is needed that root finds the MMc-classes in the
423 // dictionary when calling the constructor of MReadTree
424 // I don't have any idea why...
425 // Rem: This happens only in this GUI!
426 //
427 MMcTrig trig;
428#endif
429
430 //
431 // Setup the task list
432 //
433 MReadTree read("Events", fInputFile);
434
435 MMcThresholdCalc calc(dim);
436 tlist.AddToList(&read);
437 tlist.AddToList(&calc);
438
439 MEvtLoop evtloop;
440 evtloop.SetParList(&plist);
441
442 //
443 // Add ProgressBar to window
444 //
445 TGProgressBar *bar = CreateProgressBar(fTop2);
446 evtloop.SetProgressBar(bar);
447
448 //
449 // Execute your analysis
450 //
451 Bool_t rc = evtloop.Eventloop();
452
453 //
454 // Remove progressbar from window
455 //
456 DestroyProgressBar(bar);
457
458 if (!rc)
459 return;
460
461 //
462 // Now you can display the results
463 //
464 hists.R__FOR_EACH(TObject, DrawClone)();
465}
466
467// ======================================================================
468
469Bool_t MMonteCarlo::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
470{
471 if (GET_MSG(msg) == kC_COMMAND && GET_SUBMSG(msg) == kCM_BUTTON)
472 switch (parm1)
473 {
474 case kButCollArea:
475 CalculateCollectionArea();
476 return kTRUE;
477
478 case kButTrigRate:
479 CalculateTriggerRate();
480 return kTRUE;
481
482 case kButThreshold:
483 CalculateThreshold();
484 return kTRUE;
485 }
486
487 return MBrowser::ProcessMessage(msg, parm1, parm2);
488}
Note: See TracBrowser for help on using the repository browser.