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 | ! Author(s): Abelardo Moralejo 1/2005 <mailto:moralejo@pd.infn.it>!
|
---|
18 | !
|
---|
19 | ! Copyright: MAGIC Software Development, 2000-2003
|
---|
20 | !
|
---|
21 | !
|
---|
22 | \* ======================================================================== */
|
---|
23 |
|
---|
24 | ///////////////////////////////////////////////////////////////////////////////////////
|
---|
25 | //
|
---|
26 | // Macro trainsubsample.C
|
---|
27 | //
|
---|
28 | // Reads a star file from real data, and makes a subsample of it, adding a "fake"
|
---|
29 | // MMcEvt container with MMcEvt.fPartId=14. This intended to produce, from real data,
|
---|
30 | // a "hadron training file" to be used in random forest (or other) g/h separation. The
|
---|
31 | // MMcEvt container is added so that whatever the method will consider these (real)
|
---|
32 | // showers to be all protons (before cuts, most will be, even in the case of strong
|
---|
33 | // source as Crab).
|
---|
34 | //
|
---|
35 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
36 |
|
---|
37 | void trainsubsample()
|
---|
38 | {
|
---|
39 | MParList plist;
|
---|
40 | MTaskList tlist;
|
---|
41 |
|
---|
42 | plist.AddToList(&tlist);
|
---|
43 |
|
---|
44 | MReadMarsFile read("Events", "star_20040918_CrabNebulaW2.root");
|
---|
45 |
|
---|
46 | MFEventSelector evsel;
|
---|
47 |
|
---|
48 | Float_t nevents = 50000; // Number of events to select.
|
---|
49 | Float_t ratio = nevents / (Float_t) read.GetEntries();
|
---|
50 |
|
---|
51 | evsel.SetSelectionRatio(ratio); // Fraction of events in output
|
---|
52 |
|
---|
53 | read.DisableAutoScheme();
|
---|
54 | tlist.AddToList(&read);
|
---|
55 |
|
---|
56 | MMcEvt* mcevt = new MMcEvt;
|
---|
57 | mcevt->SetPartId(14);
|
---|
58 | plist.AddToList(mcevt);
|
---|
59 |
|
---|
60 | MWriteRootFile write("star_train_20040918_CrabNebulaW2.root", "recreate");
|
---|
61 |
|
---|
62 | write.AddContainer("MMcEvt", "Events", kFALSE);
|
---|
63 | write.AddContainer("MHillas", "Events");
|
---|
64 | write.AddContainer("MHillasExt", "Events");
|
---|
65 | write.AddContainer("MImagePar", "Events");
|
---|
66 | write.AddContainer("MNewImagePar", "Events");
|
---|
67 | write.AddContainer("MHillasSrc", "Events");
|
---|
68 | write.AddContainer("MSrcPosCam", "Events");
|
---|
69 | write.AddContainer("MConcentration", "Events", kFALSE);
|
---|
70 | write.AddContainer("MPointingPos", "Events", kFALSE);
|
---|
71 |
|
---|
72 |
|
---|
73 | write.AddContainer("MGeomCam", "RunHeaders", kFALSE);
|
---|
74 | write.AddContainer("MMcConfigRunHeader", "RunHeaders", kFALSE);
|
---|
75 | write.AddContainer("MMcCorsikaRunHeader", "RunHeaders", kFALSE);
|
---|
76 | write.AddContainer("MMcFadcHeader", "RunHeaders", kFALSE);
|
---|
77 | write.AddContainer("MMcTrigHeader", "RunHeaders", kFALSE);
|
---|
78 |
|
---|
79 | write.AddContainer("MRawRunHeader", "RunHeaders");
|
---|
80 | write.AddContainer("MMcRunHeader", "RunHeaders", kFALSE);
|
---|
81 |
|
---|
82 | write.SetFilter(&evsel);
|
---|
83 |
|
---|
84 | tlist.AddToList(&evsel);
|
---|
85 | tlist.AddToList(&write);
|
---|
86 |
|
---|
87 | MEvtLoop evtloop;
|
---|
88 | evtloop.SetParList(&plist);
|
---|
89 |
|
---|
90 | MProgressBar *bar = new MProgressBar;
|
---|
91 | evtloop.SetProgressBar(bar);
|
---|
92 |
|
---|
93 | //
|
---|
94 | // Execute your analysis
|
---|
95 | //
|
---|
96 | if (!evtloop.Eventloop())
|
---|
97 | return;
|
---|
98 |
|
---|
99 | tlist.PrintStatistics();
|
---|
100 |
|
---|
101 | bar->DestroyWindow();
|
---|
102 |
|
---|
103 | return;
|
---|
104 | }
|
---|