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 <TGButtonGroup.h> // TGVButtonGroup
|
---|
35 |
|
---|
36 | ClassImp(MMonteCarlo)
|
---|
37 |
|
---|
38 | enum {
|
---|
39 | M_BUTTON_COLAREA,
|
---|
40 | M_BUTTON_RATE,
|
---|
41 | M_BUTTON_THRESHOLD
|
---|
42 | };
|
---|
43 |
|
---|
44 | void MMonteCarlo::AddButtons()
|
---|
45 | {
|
---|
46 | TGTextButton *carea = new TGTextButton(fTop1, "Collection Area", M_BUTTON_COLAREA);
|
---|
47 | TGTextButton *trate = new TGTextButton(fTop1, "Trigger Rate", M_BUTTON_RATE);
|
---|
48 | TGTextButton *thold = new TGTextButton(fTop1, "Threshold", M_BUTTON_THRESHOLD);
|
---|
49 |
|
---|
50 | fList->Add(carea);
|
---|
51 | fList->Add(trate);
|
---|
52 | fList->Add(thold);
|
---|
53 |
|
---|
54 | carea->Associate(this);
|
---|
55 | trate->Associate(this);
|
---|
56 | thold->Associate(this);
|
---|
57 |
|
---|
58 | TGLayoutHints *laybut = new TGLayoutHints(kLHintsNormal, 5, 5, 10, 10);
|
---|
59 | fList->Add(laybut);
|
---|
60 |
|
---|
61 | fTop1->AddFrame(carea, laybut);
|
---|
62 | fTop1->AddFrame(trate, laybut);
|
---|
63 | fTop1->AddFrame(thold, laybut);
|
---|
64 | }
|
---|
65 |
|
---|
66 | void MMonteCarlo::AddSetupTab()
|
---|
67 | {
|
---|
68 | //
|
---|
69 | // Create Setup Tab
|
---|
70 | //
|
---|
71 | TGCompositeFrame *frame = CreateNewTab("Setup");
|
---|
72 |
|
---|
73 | //
|
---|
74 | // Create a button group (it alignes the buttons and make
|
---|
75 | // them automatic radio buttons)
|
---|
76 | // Create three (auto) radio buttons in the button group
|
---|
77 | //
|
---|
78 | TGVButtonGroup *group = new TGVButtonGroup(frame);
|
---|
79 | fList->Add(group);
|
---|
80 |
|
---|
81 | fRadioButton1 = new TGRadioButton(group, "Use unnumbered trigger condition olny.");
|
---|
82 | fRadioButton2 = new TGRadioButton(group, "Use only one trigger condition (specify number below).");
|
---|
83 | fRadioButton3 = new TGRadioButton(group, "Use a number of trigger conditions (1..n).");
|
---|
84 |
|
---|
85 | fRadioButton1->SetState(kButtonDown);
|
---|
86 |
|
---|
87 | /* FIXME:
|
---|
88 | fList->Add(fRadioButton1);
|
---|
89 | fList->Add(fRadioButton2);
|
---|
90 | fList->Add(fRadioButton3);
|
---|
91 | */
|
---|
92 |
|
---|
93 | //
|
---|
94 | // Add the button group (all buttons) as first line
|
---|
95 | //
|
---|
96 | frame->AddFrame(group);
|
---|
97 |
|
---|
98 | //
|
---|
99 | // Create entry fields and labels for line 3 and 4
|
---|
100 | //
|
---|
101 |
|
---|
102 | /*
|
---|
103 | * --> use with root >=3.02 <--
|
---|
104 | *
|
---|
105 |
|
---|
106 | TGNumberEntry *fNumEntry1 = new TGNumberEntry(frame, 3.0, 2, M_NENT_LVL1, kNESRealOne, kNEANonNegative);
|
---|
107 | TGNumberEntry *fNumEntry2 = new TGNumberEntry(frame, 2.5, 2, M_NENT_LVL1, kNESRealOne, kNEANonNegative);
|
---|
108 |
|
---|
109 | */
|
---|
110 |
|
---|
111 | //
|
---|
112 | // Align the lines:
|
---|
113 | // - top, left
|
---|
114 | // - padding: top=20, bottom=0, left=20, right=0
|
---|
115 | //
|
---|
116 | TGLayoutHints *layline = new TGLayoutHints(kLHintsNormal, 20, 0, 20);
|
---|
117 | fList->Add(layline);
|
---|
118 |
|
---|
119 |
|
---|
120 | //
|
---|
121 | // Create a frame for line 3 and 4 to be able
|
---|
122 | // to align entry field and label in one line
|
---|
123 | //
|
---|
124 | TGHorizontalFrame *f = new TGHorizontalFrame(frame, 0, 0);
|
---|
125 | fNumEntry = new TGTextEntry(f, "****");
|
---|
126 | fNumEntry->SetText("1");
|
---|
127 | fList->Add(fNumEntry);
|
---|
128 |
|
---|
129 | // --- doesn't work like expected --- fNumEntry1->SetAlignment(kTextRight);
|
---|
130 | // --- doesn't work like expected --- fNumEntry2->SetAlignment(kTextRight);
|
---|
131 |
|
---|
132 | TGLabel *l = new TGLabel(f, "Trigger Condition Setup.");
|
---|
133 | l->SetTextJustify(kTextLeft);
|
---|
134 | fList->Add(l);
|
---|
135 |
|
---|
136 | //
|
---|
137 | // Align the text of the label centered, left in the row
|
---|
138 | // with a left padding of 10
|
---|
139 | //
|
---|
140 | TGLayoutHints *laylabel = new TGLayoutHints(kLHintsCenterY|kLHintsLeft, 10); //, 10); //, 5, 5);
|
---|
141 | fList->Add(laylabel);
|
---|
142 |
|
---|
143 | //
|
---|
144 | // Add one entry field and the corresponding label to each line
|
---|
145 | //
|
---|
146 | f->AddFrame(fNumEntry);
|
---|
147 | f->AddFrame(l, laylabel);
|
---|
148 |
|
---|
149 | //
|
---|
150 | // Add line 3 and 4 to tab
|
---|
151 | //
|
---|
152 | frame->AddFrame(f, layline);
|
---|
153 | }
|
---|
154 |
|
---|
155 | MMonteCarlo::MMonteCarlo(const TGWindow *main, const TGWindow *p,
|
---|
156 | const UInt_t w, const UInt_t h)
|
---|
157 | : MBrowser(main, p, w, h)
|
---|
158 | {
|
---|
159 | AddButtons();
|
---|
160 | AddSetupTab();
|
---|
161 |
|
---|
162 | MapSubwindows();
|
---|
163 |
|
---|
164 | Layout();
|
---|
165 |
|
---|
166 | SetWindowName("MonteCarlo Main");
|
---|
167 | SetIconName("MonteCarlo");
|
---|
168 |
|
---|
169 | MapWindow();
|
---|
170 | }
|
---|
171 |
|
---|
172 | // ======================================================================
|
---|
173 | #include <TObjArray.h>
|
---|
174 |
|
---|
175 | #include "MParList.h"
|
---|
176 | #include "MTaskList.h"
|
---|
177 | #include "MEvtLoop.h"
|
---|
178 |
|
---|
179 | #include "MReadTree.h"
|
---|
180 |
|
---|
181 | #include "MHMcRate.h"
|
---|
182 | #include "MHMcEnergy.h"
|
---|
183 |
|
---|
184 | #include "MMcTriggerRateCalc.h"
|
---|
185 | #include "MMcThresholdCalc.h"
|
---|
186 | #include "MMcCollectionAreaCalc.h"
|
---|
187 |
|
---|
188 | #include "../mmc/MMcTrig.hxx" // FIXME: see FIXME below
|
---|
189 |
|
---|
190 | Int_t MMonteCarlo::GetDim() const
|
---|
191 | {
|
---|
192 | return 0;
|
---|
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() const
|
---|
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 reader("Events", fInputFile);
|
---|
234 | // reader.UseLeaf("fImpact");
|
---|
235 | // reader.UseLeaf("fEnergy");
|
---|
236 | // reader.UseLeaf("fNumFirstLevel");
|
---|
237 |
|
---|
238 | tlist.AddToList(&reader);
|
---|
239 |
|
---|
240 | MMcCollectionAreaCalc effi;
|
---|
241 | tlist.AddToList(&effi);
|
---|
242 |
|
---|
243 | //
|
---|
244 | // set up the loop for the processing
|
---|
245 | //
|
---|
246 | MEvtLoop magic;
|
---|
247 | magic.SetParList(&plist);
|
---|
248 |
|
---|
249 | //
|
---|
250 | // Start to loop over all events
|
---|
251 | //
|
---|
252 | if (!magic.Eventloop())
|
---|
253 | return;
|
---|
254 |
|
---|
255 | //
|
---|
256 | // Now the histogram we wanted to get out of the data is
|
---|
257 | // filled and can be displayd
|
---|
258 | //
|
---|
259 | plist.FindObject("MHMcCollectionArea")->DrawClone();
|
---|
260 | }
|
---|
261 |
|
---|
262 | void MMonteCarlo::CalculateTriggerRate() const
|
---|
263 | {
|
---|
264 | // This macro has two input parameter:
|
---|
265 | // dim : = 0 -> root file with 1 trigger condition.
|
---|
266 | // > 0 -> number of trigger condition to be analised
|
---|
267 | // in multi conditon file.
|
---|
268 | // < 0 -> selects the -dim trigger condition.
|
---|
269 | //
|
---|
270 | // first we have to create our empty lists
|
---|
271 | //
|
---|
272 | const Int_t dim = GetDim();
|
---|
273 |
|
---|
274 | MParList plist;
|
---|
275 | MTaskList tlist;
|
---|
276 |
|
---|
277 | //
|
---|
278 | // Setup the parameter list.
|
---|
279 | // - we do not need to create any other container. All of them
|
---|
280 | // are created automatically without loss - we don't have to
|
---|
281 | // access them-
|
---|
282 | //
|
---|
283 | // - we need to create MHMcRate only. The other containers
|
---|
284 | // are created automatically without loss - we don't have to
|
---|
285 | // access them-
|
---|
286 | // - MHMcRate must be created by us because we need the pointer
|
---|
287 | // to it and if it would get created automatically it would also be
|
---|
288 | // deleted automatically
|
---|
289 | // - Actually, depending on using a single trigger option MonteCarlo
|
---|
290 | // file or a multyple trigger option, a MHMcRate or an array of
|
---|
291 | // MHMcRate are needed.
|
---|
292 | //
|
---|
293 | plist.AddToList(&tlist);
|
---|
294 |
|
---|
295 | //
|
---|
296 | // You don't have to add the MHMcRate container here by hand.
|
---|
297 | // But if you want to print or display these containers later on
|
---|
298 | // it is necessary (Rem: No printing or displaying is done in this
|
---|
299 | // macro yet)
|
---|
300 | //
|
---|
301 | const UInt_t from = dim>0 ? 1 : -dim;
|
---|
302 | const UInt_t to = dim>0 ? dim : -dim;
|
---|
303 | const Int_t num = to-from+1;
|
---|
304 |
|
---|
305 | TObjArray hists(MParList::CreateObjList("MHMcRate", from, to));
|
---|
306 | hists.SetOwner();
|
---|
307 |
|
---|
308 | //
|
---|
309 | // Check if the list really contains the right number of histograms
|
---|
310 | //
|
---|
311 | if (hists.GetEntriesFast() != num)
|
---|
312 | return;
|
---|
313 |
|
---|
314 | //
|
---|
315 | // Add the histograms to the paramater list.
|
---|
316 | //
|
---|
317 | plist.AddToList(&hists);
|
---|
318 |
|
---|
319 | //
|
---|
320 | // FIXME: This line is needed that root finds the MMc-classes in the
|
---|
321 | // dictionary when calling the constructor of MReadTree
|
---|
322 | // I don't have any idea why...
|
---|
323 | // Rem: This happens only in this GUI!
|
---|
324 | //
|
---|
325 | MMcTrig trig;
|
---|
326 |
|
---|
327 | //
|
---|
328 | // Setup out tasks:
|
---|
329 | // - First we have to read the events
|
---|
330 | // - Then we can calculate rates, for what the number of
|
---|
331 | // triggered showers from a empty reflector file for the
|
---|
332 | // analised trigger conditions should be set (BgR[])
|
---|
333 | //
|
---|
334 | MReadTree reader("Events", fInputFile);
|
---|
335 | /* reader.UseLeaf("fImpact");
|
---|
336 | reader.UseLeaf("fEnergy");
|
---|
337 | reader.UseLeaf("fPhi");
|
---|
338 | reader.UseLeaf("fTheta");
|
---|
339 | reader.UseLeaf("fNumFirstLevel");
|
---|
340 | reader.UseLeaf("fPhotElfromShower");
|
---|
341 | */
|
---|
342 | tlist.AddToList(&reader);
|
---|
343 |
|
---|
344 | Float_t BgR[10]={660, 4, 0, 0, 0, 0, 0, 0, 0, 0};
|
---|
345 |
|
---|
346 | MMcTriggerRateCalc crate(dim, 14, BgR, 100000);
|
---|
347 | tlist.AddToList(&crate);
|
---|
348 |
|
---|
349 | //
|
---|
350 | // set up the loop for the processing
|
---|
351 | //
|
---|
352 | MEvtLoop magic;
|
---|
353 | magic.SetParList(&plist);
|
---|
354 |
|
---|
355 | //
|
---|
356 | // Start to loop over all events
|
---|
357 | //
|
---|
358 | if (!magic.Eventloop())
|
---|
359 | return;
|
---|
360 |
|
---|
361 | hists.Print();
|
---|
362 | }
|
---|
363 |
|
---|
364 | void MMonteCarlo::CalculateThreshold() const
|
---|
365 | {
|
---|
366 | const Int_t dim = GetDim();
|
---|
367 |
|
---|
368 | //
|
---|
369 | // This macro fill the container MHMcEnergies using the task
|
---|
370 | // MMcThresholdCalc and shows the results.
|
---|
371 | //
|
---|
372 | MParList plist;
|
---|
373 |
|
---|
374 | MTaskList tlist;
|
---|
375 | plist.AddToList(&tlist);
|
---|
376 |
|
---|
377 | //
|
---|
378 | // Setup the parameter list
|
---|
379 | // - You need create the container MHMcEnergies.
|
---|
380 | // + You need to put the number of trigger conditions when
|
---|
381 | // you declarete the MHMcEnergies
|
---|
382 | // + If you don't put any dimension to MHMcEnergies it works
|
---|
383 | // taking only the trigger information from MMcTrig
|
---|
384 | //
|
---|
385 |
|
---|
386 | //
|
---|
387 | // Create numtriggerconditions histograms of type MHMcEnergy
|
---|
388 | // and store the histograms in an TObjArray
|
---|
389 | //
|
---|
390 | const UInt_t from = dim>0 ? 1 : -dim;
|
---|
391 | const UInt_t to = dim>0 ? dim : -dim;
|
---|
392 | const Int_t num = to-from+1;
|
---|
393 |
|
---|
394 | TObjArray hists(MParList::CreateObjList("MHMcEnergy", from, to));
|
---|
395 | hists.SetOwner();
|
---|
396 |
|
---|
397 | //
|
---|
398 | // Check if the list really contains the right number of histograms
|
---|
399 | //
|
---|
400 | if (hists.GetEntriesFast() != num)
|
---|
401 | return;
|
---|
402 |
|
---|
403 | //
|
---|
404 | // Add the histograms to the paramater list.
|
---|
405 | //
|
---|
406 | plist.AddToList(&hists);
|
---|
407 |
|
---|
408 | //
|
---|
409 | // FIXME: This line is needed that root finds the MMc-classes in the
|
---|
410 | // dictionary when calling the constructor of MReadTree
|
---|
411 | // I don't have any idea why...
|
---|
412 | // Rem: This happens only in this GUI!
|
---|
413 | //
|
---|
414 | MMcTrig trig;
|
---|
415 |
|
---|
416 | //
|
---|
417 | // Setup the task list
|
---|
418 | // - You need the read and the MMcThresholdCalc tasks
|
---|
419 | // - You have to fill the histograms for the Energy threshold
|
---|
420 | // + You need to put the number of trigger conditions when
|
---|
421 | // you declarete the MMcThresholdCalc
|
---|
422 | // + If you don't put any dimension to MMcThresholdCalc it works
|
---|
423 | // like one dimension MMcThresholdCalc
|
---|
424 | //
|
---|
425 | MReadTree read("Events", fInputFile);
|
---|
426 | /* read.UseLeaf("fEnergy");
|
---|
427 | read.UseLeaf("fNumFirstLevel");
|
---|
428 | */
|
---|
429 | MMcThresholdCalc calc(dim);
|
---|
430 | tlist.AddToList(&read);
|
---|
431 | tlist.AddToList(&calc);
|
---|
432 |
|
---|
433 | MEvtLoop evtloop;
|
---|
434 | evtloop.SetParList(&plist);
|
---|
435 |
|
---|
436 | //
|
---|
437 | // Begin the loop (if the loop wasn't successfull
|
---|
438 | // don't try to draw the results
|
---|
439 | //
|
---|
440 | if (!evtloop.Eventloop())
|
---|
441 | return;
|
---|
442 |
|
---|
443 | //
|
---|
444 | // Now you can display the results
|
---|
445 | //
|
---|
446 | TIter Next(&hists);
|
---|
447 | TObject *obj;
|
---|
448 | while ((obj=Next()))
|
---|
449 | obj->DrawClone();
|
---|
450 | }
|
---|
451 |
|
---|
452 | // ======================================================================
|
---|
453 |
|
---|
454 | Bool_t MMonteCarlo::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
|
---|
455 | {
|
---|
456 | if (GET_MSG(msg) == kC_COMMAND && GET_SUBMSG(msg) == kCM_BUTTON)
|
---|
457 | switch (parm1)
|
---|
458 | {
|
---|
459 | case M_BUTTON_COLAREA:
|
---|
460 | CalculateCollectionArea();
|
---|
461 | return kTRUE;
|
---|
462 |
|
---|
463 | case M_BUTTON_RATE:
|
---|
464 | CalculateTriggerRate();
|
---|
465 | return kTRUE;
|
---|
466 |
|
---|
467 | case M_BUTTON_THRESHOLD:
|
---|
468 | CalculateThreshold();
|
---|
469 | return kTRUE;
|
---|
470 | }
|
---|
471 |
|
---|
472 | return MBrowser::ProcessMessage(msg, parm1, parm2);
|
---|
473 | }
|
---|