source: trunk/MagicSoft/Mars/mmain/MMonteCarlo.cc@ 958

Last change on this file since 958 was 954, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 11.1 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): 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
36ClassImp(MMonteCarlo)
37
38enum {
39 M_BUTTON_COLAREA,
40 M_BUTTON_RATE,
41 M_BUTTON_THRESHOLD
42};
43
44void 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
66void 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 //
77 TGVButtonGroup *group = new TGVButtonGroup(frame);
78 fList->Add(group);
79
80 //
81 // Create three (auto) radio buttons in the button group
82 //
83 fRadioButton1 = new TGRadioButton(group, "Use unnumbered trigger condition olny.");
84 fRadioButton2 = new TGRadioButton(group, "Use only one trigger condition (specify number below).");
85 fRadioButton3 = new TGRadioButton(group, "Use a number of trigger conditions (1..n).");
86
87 fList->Add(fRadioButton1);
88 fList->Add(fRadioButton2);
89 fList->Add(fRadioButton3);
90
91 //
92 // Add the button group (all buttons) as first line
93 //
94 frame->AddFrame(group);
95
96 //
97 // Create entry fields and labels for line 3 and 4
98 //
99
100 /*
101 * --> use with root >=3.02 <--
102 *
103
104 TGNumberEntry *fNumEntry1 = new TGNumberEntry(frame, 3.0, 2, M_NENT_LVL1, kNESRealOne, kNEANonNegative);
105 TGNumberEntry *fNumEntry2 = new TGNumberEntry(frame, 2.5, 2, M_NENT_LVL1, kNESRealOne, kNEANonNegative);
106
107 */
108
109 //
110 // Align the lines:
111 // - top, left
112 // - padding: top=20, bottom=0, left=20, right=0
113 //
114 TGLayoutHints *layline = new TGLayoutHints(kLHintsNormal, 20, 0, 20);
115 fList->Add(layline);
116
117
118 //
119 // Create a frame for line 3 and 4 to be able
120 // to align entry field and label in one line
121 //
122 TGHorizontalFrame *f = new TGHorizontalFrame(frame, 0, 0);
123 fNumEntry = new TGTextEntry(f, "****");
124 fNumEntry->SetText("1");
125 fList->Add(fNumEntry);
126
127 // --- doesn't work like expected --- fNumEntry1->SetAlignment(kTextRight);
128 // --- doesn't work like expected --- fNumEntry2->SetAlignment(kTextRight);
129
130 TGLabel *l = new TGLabel(f, "Trigger Condition Setup.");
131 l->SetTextJustify(kTextLeft);
132 fList->Add(l);
133
134 //
135 // Align the text of the label centered, left in the row
136 // with a left padding of 10
137 //
138 TGLayoutHints *laylabel = new TGLayoutHints(kLHintsCenterY|kLHintsLeft, 10); //, 10); //, 5, 5);
139 fList->Add(laylabel);
140
141 //
142 // Add one entry field and the corresponding label to each line
143 //
144 f->AddFrame(fNumEntry);
145 f->AddFrame(l, laylabel);
146
147 //
148 // Add line 3 and 4 to tab
149 //
150 frame->AddFrame(f, layline);
151}
152
153MMonteCarlo::MMonteCarlo(const TGWindow *main, const TGWindow *p,
154 const UInt_t w, const UInt_t h)
155: MBrowser(main, p, w, h)
156{
157 AddButtons();
158 AddSetupTab();
159
160 MapSubwindows();
161
162 Layout();
163
164 SetWindowName("MonteCarlo Main");
165 SetIconName("MonteCarlo");
166
167 MapWindow();
168}
169
170// ======================================================================
171#include <TObjArray.h>
172
173#include "MParList.h"
174#include "MTaskList.h"
175#include "MEvtLoop.h"
176
177#include "MReadTree.h"
178
179#include "MHMcRate.h"
180#include "MHMcEnergy.h"
181
182#include "MMcTriggerRateCalc.h"
183#include "MMcThresholdCalc.h"
184#include "MMcCollectionAreaCalc.h"
185
186Int_t MMonteCarlo::GetDim() const
187{
188 Int_t dim = atoi(fNumEntry->GetText());
189
190 if (dim<0)
191 {
192 dim=0;
193 fNumEntry->SetText("0");
194 }
195
196 if (fRadioButton1->GetState())
197 dim = 0;
198
199 if (fRadioButton2->GetState())
200 dim = -dim;
201
202 return dim;
203}
204
205void MMonteCarlo::CalculateCollectionArea() const
206{
207 //
208 // first we have to create our empty lists
209 //
210 MParList plist;
211
212 MTaskList tlist;
213 plist.AddToList(&tlist);
214
215 //
216 // Setup out tasks:
217 // - First we have to read the events
218 // - Then we can fill the efficiency histograms
219 //
220 MReadTree reader("Events", fInputFile);
221 tlist.AddToList(&reader);
222
223 MMcCollectionAreaCalc effi;
224 tlist.AddToList(&effi);
225
226 //
227 // set up the loop for the processing
228 //
229 MEvtLoop magic;
230 magic.SetParList(&plist);
231
232 //
233 // Start to loop over all events
234 //
235 if (!magic.Eventloop())
236 return;
237
238 //
239 // Now the histogram we wanted to get out of the data is
240 // filled and can be displayd
241 //
242 plist.FindObject("MHMcCollectionArea")->DrawClone();
243}
244
245void MMonteCarlo::CalculateTriggerRate() const
246{
247 // This macro has two input parameter:
248 // dim : = 0 -> root file with 1 trigger condition.
249 // > 0 -> number of trigger condition to be analised
250 // in multi conditon file.
251 // < 0 -> selects the -dim trigger condition.
252 //
253 // first we have to create our empty lists
254 //
255 const Int_t dim = GetDim();
256
257 MParList plist;
258 MTaskList tlist;
259
260 //
261 // Setup the parameter list.
262 // - we do not need to create any other container. All of them
263 // are created automatically without loss - we don't have to
264 // access them-
265 //
266 // - we need to create MHMcRate only. The other containers
267 // are created automatically without loss - we don't have to
268 // access them-
269 // - MHMcRate must be created by us because we need the pointer
270 // to it and if it would get created automatically it would also be
271 // deleted automatically
272 // - Actually, depending on using a single trigger option MonteCarlo
273 // file or a multyple trigger option, a MHMcRate or an array of
274 // MHMcRate are needed.
275 //
276 plist.AddToList(&tlist);
277
278 //
279 // You don't have to add the MHMcRate container here by hand.
280 // But if you want to print or display these containers later on
281 // it is necessary (Rem: No printing or displaying is done in this
282 // macro yet)
283 //
284 TObjArray hists(MParList::CreateObjList("MHMcRate", dim));
285 hists.SetOwner();
286
287 //
288 // Check if the list really contains the right number of histograms
289 //
290 if (hists.GetEntriesFast() != dim)
291 return;
292
293 //
294 // Add the histograms to the paramater list.
295 //
296 plist.AddToList(&hists);
297
298 //
299 // Setup out tasks:
300 // - First we have to read the events
301 // - Then we can calculate rates, for what the number of
302 // triggered showers from a empty reflector file for the
303 // analised trigger conditions should be set (BgR[])
304 //
305 MReadTree reader("Events", fInputFile);
306 tlist.AddToList(&reader);
307
308 Float_t BgR[10]={660,4,0,0,0,0,0,0,0,0};
309
310 MMcTriggerRateCalc crate(dim, 14, BgR, 100000, 2.75, 10.91e-2);
311 tlist.AddToList(&crate);
312
313 //
314 // set up the loop for the processing
315 //
316 MEvtLoop magic;
317 magic.SetParList(&plist);
318
319 //
320 // Start to loop over all events
321 //
322 if (!magic.Eventloop())
323 return;
324
325 TIter Next(&hists);
326 MHMcRate *rate=NULL;
327 while ((rate=(MHMcRate*)Next()))
328 rate->Print();
329}
330
331void MMonteCarlo::CalculateThreshold() const
332{
333 const Int_t dim = GetDim();
334
335 //
336 // This macro fill the container MHMcEnergies using the task
337 // MMcThresholdCalc and shows the results.
338 //
339 MParList plist;
340
341 MTaskList tlist;
342 plist.AddToList(&tlist);
343
344 //
345 // Setup the parameter list
346 // - You need create the container MHMcEnergies.
347 // + You need to put the number of trigger conditions when
348 // you declarete the MHMcEnergies
349 // + If you don't put any dimension to MHMcEnergies it works
350 // taking only the trigger information from MMcTrig
351 //
352
353 //
354 // Create numtriggerconditions histograms of type MHMcEnergy
355 // and store the histograms in an TObjArray
356 //
357 TObjArray hists(MParList::CreateObjList("MHMcEnergy", dim));
358 hists.SetOwner();
359
360 //
361 // Check if the list really contains the right number of histograms
362 //
363 if (hists.GetEntriesFast() != dim)
364 return;
365
366 //
367 // Add the histograms to the paramater list.
368 //
369 plist.AddToList(&hists);
370
371 //
372 // Setup the task list
373 // - You need the read and the MMcThresholdCalc tasks
374 // - You have to fill the histograms for the Energy threshold
375 // + You need to put the number of trigger conditions when
376 // you declarete the MMcThresholdCalc
377 // + If you don't put any dimension to MMcThresholdCalc it works
378 // like one dimension MMcThresholdCalc
379 //
380 MReadTree read("Events", fInputFile);
381 MMcThresholdCalc calc(dim);
382
383 tlist.AddToList(&read);
384 tlist.AddToList(&calc);
385
386 MEvtLoop evtloop;
387 evtloop.SetParList(&plist);
388
389 //
390 // Begin the loop (if the loop wasn't succesfull
391 // don't try to draw the results
392 //
393 if (!evtloop.Eventloop())
394 return;
395
396 //
397 // Now you can display the results
398 //
399 TIter Next(&hists);
400 MHMcRate *hist=NULL;
401 while ((hist=(MHMcRate*)Next()))
402 hist->DrawClone();
403}
404
405// ======================================================================
406
407Bool_t MMonteCarlo::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
408{
409 if (GET_MSG(msg) == kC_COMMAND && GET_SUBMSG(msg) == kCM_BUTTON)
410 switch (parm1)
411 {
412 case M_BUTTON_COLAREA:
413 CalculateCollectionArea();
414 return kTRUE;
415
416 case M_BUTTON_RATE:
417 CalculateTriggerRate();
418 return kTRUE;
419
420 case M_BUTTON_THRESHOLD:
421 CalculateThreshold();
422 return kTRUE;
423 }
424
425 return MBrowser::ProcessMessage(msg, parm1, parm2);
426}
Note: See TracBrowser for help on using the repository browser.