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 |
|
---|
37 | ClassImp(MMonteCarlo)
|
---|
38 |
|
---|
39 | enum {
|
---|
40 | M_BUTTON_COLAREA,
|
---|
41 | M_BUTTON_RATE,
|
---|
42 | M_BUTTON_THRESHOLD
|
---|
43 | };
|
---|
44 |
|
---|
45 | void 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 |
|
---|
67 | void 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 |
|
---|
156 | MMonteCarlo::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 |
|
---|
191 | Int_t MMonteCarlo::GetDim() const
|
---|
192 | {
|
---|
193 | Int_t dim = atoi(fNumEntry->GetText());
|
---|
194 |
|
---|
195 | if (dim<0)
|
---|
196 | {
|
---|
197 | dim=0;
|
---|
198 | fNumEntry->SetText("0");
|
---|
199 | }
|
---|
200 |
|
---|
201 | if (fRadioButton1->GetState())
|
---|
202 | dim = 0;
|
---|
203 |
|
---|
204 | if (fRadioButton2->GetState())
|
---|
205 | dim = -dim;
|
---|
206 |
|
---|
207 | return dim;
|
---|
208 | }
|
---|
209 |
|
---|
210 | void MMonteCarlo::CalculateCollectionArea()
|
---|
211 | {
|
---|
212 | //
|
---|
213 | // first we have to create our empty lists
|
---|
214 | //
|
---|
215 | MParList plist;
|
---|
216 |
|
---|
217 | MTaskList tlist;
|
---|
218 | plist.AddToList(&tlist);
|
---|
219 |
|
---|
220 | //
|
---|
221 | // FIXME: This line is needed that root finds the MMc-classes in the
|
---|
222 | // dictionary when calling the constructor of MReadTree
|
---|
223 | // I don't have any idea why...
|
---|
224 | // Rem: This happens only in this GUI!
|
---|
225 | //
|
---|
226 | MMcTrig trig;
|
---|
227 |
|
---|
228 | //
|
---|
229 | // Setup out tasks:
|
---|
230 | // - First we have to read the events
|
---|
231 | // - Then we can fill the efficiency histograms
|
---|
232 | //
|
---|
233 | MReadTree read("Events", fInputFile);
|
---|
234 | tlist.AddToList(&read);
|
---|
235 |
|
---|
236 | MMcCollectionAreaCalc effi;
|
---|
237 | tlist.AddToList(&effi);
|
---|
238 |
|
---|
239 | //
|
---|
240 | // set up the loop for the processing
|
---|
241 | //
|
---|
242 | MEvtLoop magic;
|
---|
243 | magic.SetParList(&plist);
|
---|
244 |
|
---|
245 | //
|
---|
246 | // Add ProgressBar to window
|
---|
247 | //
|
---|
248 | TGProgressBar *bar = CreateProgressBar(fTop2);
|
---|
249 | read.SetProgressBar(bar);
|
---|
250 | magic.SetProgressBar(bar);
|
---|
251 |
|
---|
252 | //
|
---|
253 | // Execute your analysis
|
---|
254 | //
|
---|
255 | Bool_t rc = magic.Eventloop();
|
---|
256 |
|
---|
257 | //
|
---|
258 | // Remove progressbar from window
|
---|
259 | //
|
---|
260 | DestroyProgressBar(bar);
|
---|
261 |
|
---|
262 | if (!rc)
|
---|
263 | return;
|
---|
264 |
|
---|
265 | //
|
---|
266 | // Now the histogram we wanted to get out of the data is
|
---|
267 | // filled and can be displayd
|
---|
268 | //
|
---|
269 | plist.FindObject("MHMcCollectionArea")->DrawClone();
|
---|
270 | }
|
---|
271 |
|
---|
272 | void MMonteCarlo::CalculateTriggerRate()
|
---|
273 | {
|
---|
274 | // This macro has two input parameter:
|
---|
275 | // dim : = 0 -> root file with 1 trigger condition.
|
---|
276 | // > 0 -> number of trigger condition to be analised
|
---|
277 | // in multi conditon file.
|
---|
278 | // < 0 -> selects the -dim trigger condition.
|
---|
279 | //
|
---|
280 | // first we have to create our empty lists
|
---|
281 | //
|
---|
282 | const Int_t dim = GetDim();
|
---|
283 |
|
---|
284 | MParList plist;
|
---|
285 | MTaskList tlist;
|
---|
286 |
|
---|
287 | //
|
---|
288 | // Setup the parameter list.
|
---|
289 | // - we do not need to create any other container. All of them
|
---|
290 | // are created automatically without loss - we don't have to
|
---|
291 | // access them-
|
---|
292 | //
|
---|
293 | // - we need to create MHMcRate only. The other containers
|
---|
294 | // are created automatically without loss - we don't have to
|
---|
295 | // access them-
|
---|
296 | // - MHMcRate must be created by us because we need the pointer
|
---|
297 | // to it and if it would get created automatically it would also be
|
---|
298 | // deleted automatically
|
---|
299 | // - Actually, depending on using a single trigger option MonteCarlo
|
---|
300 | // file or a multyple trigger option, a MHMcRate or an array of
|
---|
301 | // MHMcRate are needed.
|
---|
302 | //
|
---|
303 | plist.AddToList(&tlist);
|
---|
304 |
|
---|
305 | //
|
---|
306 | // You don't have to add the MHMcRate container here by hand.
|
---|
307 | // But if you want to print or display these containers later on
|
---|
308 | // it is necessary (Rem: No printing or displaying is done in this
|
---|
309 | // macro yet)
|
---|
310 | //
|
---|
311 | const UInt_t from = dim>0 ? 1 : -dim;
|
---|
312 | const UInt_t to = dim>0 ? dim : -dim;
|
---|
313 | const Int_t num = to-from+1;
|
---|
314 |
|
---|
315 | TObjArray hists(MParList::CreateObjList("MHMcRate", from, to));
|
---|
316 | hists.SetOwner();
|
---|
317 |
|
---|
318 | //
|
---|
319 | // Check if the list really contains the right number of histograms
|
---|
320 | //
|
---|
321 | if (hists.GetEntriesFast() != num)
|
---|
322 | return;
|
---|
323 |
|
---|
324 | //
|
---|
325 | // Add the histograms to the paramater list.
|
---|
326 | //
|
---|
327 | plist.AddToList(&hists);
|
---|
328 |
|
---|
329 | //
|
---|
330 | // FIXME: This line is needed that root finds the MMc-classes in the
|
---|
331 | // dictionary when calling the constructor of MReadTree
|
---|
332 | // I don't have any idea why...
|
---|
333 | // Rem: This happens only in this GUI!
|
---|
334 | //
|
---|
335 | MMcTrig trig;
|
---|
336 |
|
---|
337 | //
|
---|
338 | // Setup out tasks:
|
---|
339 | // - First we have to read the events
|
---|
340 | // - Then we can calculate rates, for what the number of
|
---|
341 | // triggered showers from a empty reflector file for the
|
---|
342 | // analised trigger conditions should be set (BgR[])
|
---|
343 | //
|
---|
344 | MReadTree read("Events", fInputFile);
|
---|
345 | tlist.AddToList(&read);
|
---|
346 |
|
---|
347 | Float_t BgR[10]={660, 4, 0, 0, 0, 0, 0, 0, 0, 0};
|
---|
348 |
|
---|
349 | MMcTriggerRateCalc crate(dim, 14, BgR, 100000);
|
---|
350 | tlist.AddToList(&crate);
|
---|
351 |
|
---|
352 | //
|
---|
353 | // set up the loop for the processing
|
---|
354 | //
|
---|
355 | MEvtLoop magic;
|
---|
356 | magic.SetParList(&plist);
|
---|
357 |
|
---|
358 | //
|
---|
359 | // Add ProgressBar to window
|
---|
360 | //
|
---|
361 | TGProgressBar *bar = CreateProgressBar(fTop2);
|
---|
362 | read.SetProgressBar(bar);
|
---|
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 | if (!rc)
|
---|
376 | return;
|
---|
377 |
|
---|
378 | hists.Print();
|
---|
379 | }
|
---|
380 |
|
---|
381 | void MMonteCarlo::CalculateThreshold()
|
---|
382 | {
|
---|
383 | const Int_t dim = GetDim();
|
---|
384 |
|
---|
385 | //
|
---|
386 | // This macro fill the container MHMcEnergies using the task
|
---|
387 | // MMcThresholdCalc and shows the results.
|
---|
388 | //
|
---|
389 | MParList plist;
|
---|
390 |
|
---|
391 | MTaskList tlist;
|
---|
392 | plist.AddToList(&tlist);
|
---|
393 |
|
---|
394 | //
|
---|
395 | // Setup the parameter list
|
---|
396 | // - You need create the container MHMcEnergies.
|
---|
397 | // + You need to put the number of trigger conditions when
|
---|
398 | // you declarete the MHMcEnergies
|
---|
399 | // + If you don't put any dimension to MHMcEnergies it works
|
---|
400 | // taking only the trigger information from MMcTrig
|
---|
401 | //
|
---|
402 |
|
---|
403 | //
|
---|
404 | // Create numtriggerconditions histograms of type MHMcEnergy
|
---|
405 | // and store the histograms in an TObjArray
|
---|
406 | //
|
---|
407 | const UInt_t from = dim>0 ? 1 : -dim;
|
---|
408 | const UInt_t to = dim>0 ? dim : -dim;
|
---|
409 | const Int_t num = to-from+1;
|
---|
410 |
|
---|
411 | TObjArray hists(MParList::CreateObjList("MHMcEnergy", from, to));
|
---|
412 | hists.SetOwner();
|
---|
413 |
|
---|
414 | //
|
---|
415 | // Check if the list really contains the right number of histograms
|
---|
416 | //
|
---|
417 | if (hists.GetEntriesFast() != num)
|
---|
418 | return;
|
---|
419 |
|
---|
420 | //
|
---|
421 | // Add the histograms to the paramater list.
|
---|
422 | //
|
---|
423 | plist.AddToList(&hists);
|
---|
424 |
|
---|
425 | //
|
---|
426 | // FIXME: This line is needed that root finds the MMc-classes in the
|
---|
427 | // dictionary when calling the constructor of MReadTree
|
---|
428 | // I don't have any idea why...
|
---|
429 | // Rem: This happens only in this GUI!
|
---|
430 | //
|
---|
431 | MMcTrig trig;
|
---|
432 |
|
---|
433 | //
|
---|
434 | // Setup the task list
|
---|
435 | // - You need the read and the MMcThresholdCalc tasks
|
---|
436 | // - You have to fill the histograms for the Energy threshold
|
---|
437 | // + You need to put the number of trigger conditions when
|
---|
438 | // you declarete the MMcThresholdCalc
|
---|
439 | // + If you don't put any dimension to MMcThresholdCalc it works
|
---|
440 | // like one dimension MMcThresholdCalc
|
---|
441 | //
|
---|
442 |
|
---|
443 | MReadTree read("Events", fInputFile);
|
---|
444 |
|
---|
445 | MMcThresholdCalc calc(dim);
|
---|
446 | tlist.AddToList(&read);
|
---|
447 | tlist.AddToList(&calc);
|
---|
448 |
|
---|
449 | MEvtLoop evtloop;
|
---|
450 | evtloop.SetParList(&plist);
|
---|
451 |
|
---|
452 | //
|
---|
453 | // Add ProgressBar to window
|
---|
454 | //
|
---|
455 | TGProgressBar *bar = CreateProgressBar(fTop2);
|
---|
456 | read.SetProgressBar(bar);
|
---|
457 | evtloop.SetProgressBar(bar);
|
---|
458 |
|
---|
459 | //
|
---|
460 | // Execute your analysis
|
---|
461 | //
|
---|
462 | Bool_t rc = evtloop.Eventloop();
|
---|
463 |
|
---|
464 | //
|
---|
465 | // Remove progressbar from window
|
---|
466 | //
|
---|
467 | DestroyProgressBar(bar);
|
---|
468 |
|
---|
469 | if (!rc)
|
---|
470 | return;
|
---|
471 |
|
---|
472 | //
|
---|
473 | // Now you can display the results
|
---|
474 | //
|
---|
475 | TIter Next(&hists);
|
---|
476 | TObject *obj;
|
---|
477 | while ((obj=Next()))
|
---|
478 | obj->DrawClone();
|
---|
479 | }
|
---|
480 |
|
---|
481 | // ======================================================================
|
---|
482 |
|
---|
483 | Bool_t MMonteCarlo::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
|
---|
484 | {
|
---|
485 | if (GET_MSG(msg) == kC_COMMAND && GET_SUBMSG(msg) == kCM_BUTTON)
|
---|
486 | switch (parm1)
|
---|
487 | {
|
---|
488 | case M_BUTTON_COLAREA:
|
---|
489 | CalculateCollectionArea();
|
---|
490 | return kTRUE;
|
---|
491 |
|
---|
492 | case M_BUTTON_RATE:
|
---|
493 | CalculateTriggerRate();
|
---|
494 | return kTRUE;
|
---|
495 |
|
---|
496 | case M_BUTTON_THRESHOLD:
|
---|
497 | CalculateThreshold();
|
---|
498 | return kTRUE;
|
---|
499 | }
|
---|
500 |
|
---|
501 | return MBrowser::ProcessMessage(msg, parm1, parm2);
|
---|
502 | }
|
---|