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 |
|
---|
39 | ClassImp(MMonteCarlo)
|
---|
40 |
|
---|
41 | enum {
|
---|
42 | kButCollArea = 0x100,
|
---|
43 | kButTrigRate = 0x101,
|
---|
44 | kButThreshold = 0x102
|
---|
45 | };
|
---|
46 |
|
---|
47 | void 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 |
|
---|
69 | void 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 | GetMainFrame 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 |
|
---|
164 | MMonteCarlo::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 |
|
---|
199 | Int_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 |
|
---|
218 | void 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 |
|
---|
279 | void MMonteCarlo::CalculateTriggerRate()
|
---|
280 | {
|
---|
281 | //
|
---|
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 | const Int_t dim = GetDim();
|
---|
288 |
|
---|
289 | MParList plist;
|
---|
290 | MTaskList tlist;
|
---|
291 |
|
---|
292 | //
|
---|
293 | // Setup the parameter list.
|
---|
294 | //
|
---|
295 | plist.AddToList(&tlist);
|
---|
296 |
|
---|
297 | const UInt_t from = dim>0 ? 1 : -dim;
|
---|
298 | const UInt_t to = dim>0 ? dim : -dim;
|
---|
299 | const Int_t num = to-from+1;
|
---|
300 |
|
---|
301 | TObjArray hists(MParList::CreateObjList("MHMcRate", from, to));
|
---|
302 | hists.SetOwner();
|
---|
303 |
|
---|
304 | //
|
---|
305 | // Check if the list really contains the right number of histograms
|
---|
306 | //
|
---|
307 | if (hists.GetEntriesFast() != num)
|
---|
308 | return;
|
---|
309 |
|
---|
310 | //
|
---|
311 | // Set for each MHMcRate object the trigger condition number in the
|
---|
312 | // camera file (for the case of camera files with several conditions,
|
---|
313 | // produced with the trigger_loop option.
|
---|
314 | //
|
---|
315 | if (dim < 0)
|
---|
316 | ((MHMcRate*)(hists[0]))->SetTriggerCondNum(to);
|
---|
317 | else
|
---|
318 | for (UInt_t i=from; i<=to; i++)
|
---|
319 | ((MHMcRate*)(hists[i-1]))->SetTriggerCondNum(i);
|
---|
320 |
|
---|
321 | //
|
---|
322 | // Add the histograms to the parameter list.
|
---|
323 | //
|
---|
324 | plist.AddToList(&hists);
|
---|
325 |
|
---|
326 | //
|
---|
327 | // FIXME: This line is needed that root finds the MMc-classes in the
|
---|
328 | // dictionary when calling the constructor of MReadTree
|
---|
329 | // I don't have any idea why...
|
---|
330 | // Rem: This happens only in this GUI!
|
---|
331 | //
|
---|
332 | MMcTrig trig;
|
---|
333 |
|
---|
334 | //
|
---|
335 | // Setup out tasks:
|
---|
336 | // - First we have to read the events
|
---|
337 | // - Then we can calculate rates, for what the number of
|
---|
338 | // triggered showers from a empty reflector file for the
|
---|
339 | // analised trigger conditions should be set (BgR[])
|
---|
340 | //
|
---|
341 | MReadMarsFile read("Events", fInputFile);
|
---|
342 | tlist.AddToList(&read);
|
---|
343 |
|
---|
344 | // We calculate only shower rate (not including NSB-only triggers)
|
---|
345 | Float_t* BgR = new Float_t[num];
|
---|
346 | memset(BgR, 0, num*sizeof(Float_t));
|
---|
347 |
|
---|
348 | MMcTriggerRateCalc crate(dim, BgR, 100000);
|
---|
349 | tlist.AddToList(&crate);
|
---|
350 |
|
---|
351 | //
|
---|
352 | // set up the loop for the processing
|
---|
353 | //
|
---|
354 | MEvtLoop magic;
|
---|
355 | magic.SetParList(&plist);
|
---|
356 |
|
---|
357 | //
|
---|
358 | // Add ProgressBar to window
|
---|
359 | //
|
---|
360 | TGProgressBar *bar = CreateProgressBar(fTop2);
|
---|
361 | magic.SetProgressBar(bar);
|
---|
362 |
|
---|
363 | //
|
---|
364 | // Execute your analysis
|
---|
365 | //
|
---|
366 | Bool_t rc = magic.Eventloop();
|
---|
367 |
|
---|
368 | //
|
---|
369 | // Remove progressbar from window
|
---|
370 | //
|
---|
371 | DestroyProgressBar(bar);
|
---|
372 |
|
---|
373 | delete BgR;
|
---|
374 |
|
---|
375 | if (!rc)
|
---|
376 | return;
|
---|
377 |
|
---|
378 | hists.Print();
|
---|
379 | }
|
---|
380 |
|
---|
381 | void MMonteCarlo::CalculateThreshold()
|
---|
382 | {
|
---|
383 | const Int_t dim = GetDim();
|
---|
384 |
|
---|
385 | MParList plist;
|
---|
386 |
|
---|
387 | MTaskList tlist;
|
---|
388 | plist.AddToList(&tlist);
|
---|
389 |
|
---|
390 | //
|
---|
391 | // Create numtriggerconditions histograms of type MHMcEnergy
|
---|
392 | // and store the histograms in an TObjArray
|
---|
393 | //
|
---|
394 | const UInt_t from = dim>0 ? 1 : -dim;
|
---|
395 | const UInt_t to = dim>0 ? dim : -dim;
|
---|
396 | const Int_t num = to-from+1;
|
---|
397 |
|
---|
398 | TObjArray hists(MParList::CreateObjList("MHMcEnergy", from, to));
|
---|
399 | hists.SetOwner();
|
---|
400 |
|
---|
401 | //
|
---|
402 | // Check if the list really contains the right number of histograms
|
---|
403 | //
|
---|
404 | if (hists.GetEntriesFast() != num)
|
---|
405 | return;
|
---|
406 |
|
---|
407 | //
|
---|
408 | // Add the histograms to the paramater list.
|
---|
409 | //
|
---|
410 | plist.AddToList(&hists);
|
---|
411 |
|
---|
412 | //
|
---|
413 | // FIXME: This line is needed that root finds the MMc-classes in the
|
---|
414 | // dictionary when calling the constructor of MReadTree
|
---|
415 | // I don't have any idea why...
|
---|
416 | // Rem: This happens only in this GUI!
|
---|
417 | //
|
---|
418 | MMcTrig trig;
|
---|
419 |
|
---|
420 | //
|
---|
421 | // Setup the task list
|
---|
422 | //
|
---|
423 | MReadTree read("Events", fInputFile);
|
---|
424 |
|
---|
425 | MMcThresholdCalc calc(dim);
|
---|
426 | tlist.AddToList(&read);
|
---|
427 | tlist.AddToList(&calc);
|
---|
428 |
|
---|
429 | MEvtLoop evtloop;
|
---|
430 | evtloop.SetParList(&plist);
|
---|
431 |
|
---|
432 | //
|
---|
433 | // Add ProgressBar to window
|
---|
434 | //
|
---|
435 | TGProgressBar *bar = CreateProgressBar(fTop2);
|
---|
436 | evtloop.SetProgressBar(bar);
|
---|
437 |
|
---|
438 | //
|
---|
439 | // Execute your analysis
|
---|
440 | //
|
---|
441 | Bool_t rc = evtloop.Eventloop();
|
---|
442 |
|
---|
443 | //
|
---|
444 | // Remove progressbar from window
|
---|
445 | //
|
---|
446 | DestroyProgressBar(bar);
|
---|
447 |
|
---|
448 | if (!rc)
|
---|
449 | return;
|
---|
450 |
|
---|
451 | //
|
---|
452 | // Now you can display the results
|
---|
453 | //
|
---|
454 | hists.ForEach(TObject, DrawClone)();
|
---|
455 | }
|
---|
456 |
|
---|
457 | // ======================================================================
|
---|
458 |
|
---|
459 | Bool_t MMonteCarlo::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
|
---|
460 | {
|
---|
461 | if (GET_MSG(msg) == kC_COMMAND && GET_SUBMSG(msg) == kCM_BUTTON)
|
---|
462 | switch (parm1)
|
---|
463 | {
|
---|
464 | case kButCollArea:
|
---|
465 | CalculateCollectionArea();
|
---|
466 | return kTRUE;
|
---|
467 |
|
---|
468 | case kButTrigRate:
|
---|
469 | CalculateTriggerRate();
|
---|
470 | return kTRUE;
|
---|
471 |
|
---|
472 | case kButThreshold:
|
---|
473 | CalculateThreshold();
|
---|
474 | return kTRUE;
|
---|
475 | }
|
---|
476 |
|
---|
477 | return MBrowser::ProcessMessage(msg, parm1, parm2);
|
---|
478 | }
|
---|