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 | 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 |
|
---|
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 | // This macro has two input parameter:
|
---|
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 | // first we have to create our empty lists
|
---|
288 | //
|
---|
289 | const Int_t dim = GetDim();
|
---|
290 |
|
---|
291 | MParList plist;
|
---|
292 | MTaskList tlist;
|
---|
293 |
|
---|
294 | //
|
---|
295 | // Setup the parameter list.
|
---|
296 | // - we do not need to create any other container. All of them
|
---|
297 | // are created automatically without loss - we don't have to
|
---|
298 | // access them-
|
---|
299 | //
|
---|
300 | // - we need to create MHMcRate only. The other containers
|
---|
301 | // are created automatically without loss - we don't have to
|
---|
302 | // access them-
|
---|
303 | // - MHMcRate must be created by us because we need the pointer
|
---|
304 | // to it and if it would get created automatically it would also be
|
---|
305 | // deleted automatically
|
---|
306 | // - Actually, depending on using a single trigger option MonteCarlo
|
---|
307 | // file or a multyple trigger option, a MHMcRate or an array of
|
---|
308 | // MHMcRate are needed.
|
---|
309 | //
|
---|
310 | plist.AddToList(&tlist);
|
---|
311 |
|
---|
312 | //
|
---|
313 | // You don't have to add the MHMcRate container here by hand.
|
---|
314 | // But if you want to print or display these containers later on
|
---|
315 | // it is necessary (Rem: No printing or displaying is done in this
|
---|
316 | // macro yet)
|
---|
317 | //
|
---|
318 | const UInt_t from = dim>0 ? 1 : -dim;
|
---|
319 | const UInt_t to = dim>0 ? dim : -dim;
|
---|
320 | const Int_t num = to-from+1;
|
---|
321 |
|
---|
322 | TObjArray hists(MParList::CreateObjList("MHMcRate", from, to));
|
---|
323 | hists.SetOwner();
|
---|
324 |
|
---|
325 | //
|
---|
326 | // Check if the list really contains the right number of histograms
|
---|
327 | //
|
---|
328 | if (hists.GetEntriesFast() != num)
|
---|
329 | return;
|
---|
330 |
|
---|
331 | //
|
---|
332 | // Add the histograms to the paramater list.
|
---|
333 | //
|
---|
334 | plist.AddToList(&hists);
|
---|
335 |
|
---|
336 | //
|
---|
337 | // FIXME: This line is needed that root finds the MMc-classes in the
|
---|
338 | // dictionary when calling the constructor of MReadTree
|
---|
339 | // I don't have any idea why...
|
---|
340 | // Rem: This happens only in this GUI!
|
---|
341 | //
|
---|
342 | MMcTrig trig;
|
---|
343 |
|
---|
344 | //
|
---|
345 | // Setup out tasks:
|
---|
346 | // - First we have to read the events
|
---|
347 | // - Then we can calculate rates, for what the number of
|
---|
348 | // triggered showers from a empty reflector file for the
|
---|
349 | // analised trigger conditions should be set (BgR[])
|
---|
350 | //
|
---|
351 | MReadMarsFile read("Events", fInputFile);
|
---|
352 | tlist.AddToList(&read);
|
---|
353 |
|
---|
354 | // We calculate only shower rate (not including NSB-only triggers)
|
---|
355 | Float_t* BgR = new Float_t[dim];
|
---|
356 | memset(BgR, 0, num*sizeof(Float_t));
|
---|
357 |
|
---|
358 | MMcTriggerRateCalc crate(dim, BgR, 100000);
|
---|
359 | tlist.AddToList(&crate);
|
---|
360 |
|
---|
361 | //
|
---|
362 | // set up the loop for the processing
|
---|
363 | //
|
---|
364 | MEvtLoop magic;
|
---|
365 | magic.SetParList(&plist);
|
---|
366 |
|
---|
367 | //
|
---|
368 | // Add ProgressBar to window
|
---|
369 | //
|
---|
370 | TGProgressBar *bar = CreateProgressBar(fTop2);
|
---|
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 |
|
---|
389 | void 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 | evtloop.SetProgressBar(bar);
|
---|
465 |
|
---|
466 | //
|
---|
467 | // Execute your analysis
|
---|
468 | //
|
---|
469 | Bool_t rc = evtloop.Eventloop();
|
---|
470 |
|
---|
471 | //
|
---|
472 | // Remove progressbar from window
|
---|
473 | //
|
---|
474 | DestroyProgressBar(bar);
|
---|
475 |
|
---|
476 | if (!rc)
|
---|
477 | return;
|
---|
478 |
|
---|
479 | //
|
---|
480 | // Now you can display the results
|
---|
481 | //
|
---|
482 | TIter Next(&hists);
|
---|
483 | TObject *obj;
|
---|
484 | while ((obj=Next()))
|
---|
485 | obj->DrawClone();
|
---|
486 | }
|
---|
487 |
|
---|
488 | // ======================================================================
|
---|
489 |
|
---|
490 | Bool_t MMonteCarlo::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
|
---|
491 | {
|
---|
492 | if (GET_MSG(msg) == kC_COMMAND && GET_SUBMSG(msg) == kCM_BUTTON)
|
---|
493 | switch (parm1)
|
---|
494 | {
|
---|
495 | case kButCollArea:
|
---|
496 | CalculateCollectionArea();
|
---|
497 | return kTRUE;
|
---|
498 |
|
---|
499 | case kButTrigRate:
|
---|
500 | CalculateTriggerRate();
|
---|
501 | return kTRUE;
|
---|
502 |
|
---|
503 | case kButThreshold:
|
---|
504 | CalculateThreshold();
|
---|
505 | return kTRUE;
|
---|
506 | }
|
---|
507 |
|
---|
508 | return MBrowser::ProcessMessage(msg, parm1, parm2);
|
---|
509 | }
|
---|