source: trunk/MagicSoft/Mars/macros/starmc2.C@ 5989

Last change on this file since 5989 was 5989, checked in by moralejo, 20 years ago
*** empty log message ***
File size: 5.7 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): Abelardo Moralejo 1/2004 <mailto:moralejo@pd.infn.it>
19 ! Thomas Bretz 5/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
20 !
21 ! Copyright: MAGIC Software Development, 2000-2004
22 !
23 !
24 \* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// STARMC2 - STandard Analysis and Reconstruction (MC example)
29//
30// This macro converts into image parameters an input file of MC data
31// previously calibrated (see mccalibrate.C).
32//
33//
34/////////////////////////////////////////////////////////////////////////////
35
36#include "MImgCleanStd.h"
37
38void starmc2()
39{
40 Char_t* AnalysisFilename = "calibrated_protons.root"; // File to be analyzed
41
42 TString* OutFilename1;
43 TString* OutFilename2;
44
45 // Change output file names as desired. If you want only one output, comment
46 // out the initialization of OutFilename2:
47// OutFilename1 = new TString("star_train.root"); // Output file name 1 (test)
48// OutFilename2 = new TString("star_test.root"); // Output file name 2 (train)
49
50 OutFilename1 = new TString("star.root"); // Output file name 1 (test)
51
52
53 Float_t CleanLev[2] = {3., 2.}; // Tail cuts for image analysis
54
55 // ------------------------------------------------------------------
56
57 //
58 // Create a empty Parameter List and an empty Task List
59 // The tasklist is identified in the eventloop by its name
60 //
61 MParList plist;
62
63 MTaskList tlist;
64
65 plist.AddToList(&tlist);
66
67 MSrcPosCam src;
68 src.SetReadyToSave();
69
70 plist.AddToList(&src);
71
72 //
73 // Now setup the tasks and tasklist:
74 // ---------------------------------
75 //
76 MReadMarsFile read("Events");
77
78 read.AddFile(AnalysisFilename);
79
80 read.DisableAutoScheme();
81
82 MImgCleanStd clean(CleanLev[0], CleanLev[1]); // Applies tail cuts to image.
83
84 MHillasCalc hcalc; // Calculates Hillas parameters not dependent on source position.
85 hcalc.Enable(MHillasCalc::kCalcHillasSrc);
86
87 tlist.AddToList(&read);
88 tlist.AddToList(&clean);
89 tlist.AddToList(&hcalc);
90
91 //
92 // Open output file(s):
93 //
94 MWriteRootFile write1(OutFilename1->Data()); // Writes output
95 //
96 // Add MC containers only if they exist. In this way you can also run on real calibrated data.
97 //
98 write1.AddContainer("MRawRunHeader", "RunHeaders");
99 write1.AddContainer("MMcRunHeader", "RunHeaders", kFALSE);
100 write1.AddContainer("MSrcPosCam", "RunHeaders");
101 write1.AddContainer("MGeomCam", "RunHeaders", kFALSE);
102 write1.AddContainer("MMcConfigRunHeader", "RunHeaders", kFALSE);
103 write1.AddContainer("MMcCorsikaRunHeader", "RunHeaders", kFALSE);
104 write1.AddContainer("MMcFadcHeader", "RunHeaders", kFALSE);
105 write1.AddContainer("MMcTrigHeader", "RunHeaders", kFALSE);
106
107 write1.AddContainer("MMcEvt", "Events", kFALSE);
108 write1.AddContainer("MPointingPos", "Events", kFALSE);
109 write1.AddContainer("MMcTrig", "Events", kFALSE);
110 write1.AddContainer("MRawEvtHeader", "Events");
111 write1.AddContainer("MHillas", "Events");
112 write1.AddContainer("MHillasExt", "Events");
113 write1.AddContainer("MHillasSrc", "Events");
114 write1.AddContainer("MNewImagePar", "Events");
115
116 if (OutFilename2) // Second output file, in case we want a split output
117 {
118 MWriteRootFile write2(OutFilename2->Data()); // Writes output
119 write2.AddContainer("MRawRunHeader", "RunHeaders");
120 write2.AddContainer("MMcRunHeader", "RunHeaders", kFALSE);
121 write2.AddContainer("MSrcPosCam", "RunHeaders");
122 write2.AddContainer("MGeomCam", "RunHeaders", kFALSE);
123 write2.AddContainer("MMcConfigRunHeader", "RunHeaders", kFALSE);
124 write2.AddContainer("MMcCorsikaRunHeader", "RunHeaders", kFALSE);
125 write2.AddContainer("MMcFadcHeader", "RunHeaders", kFALSE);
126 write2.AddContainer("MMcTrigHeader", "RunHeaders", kFALSE);
127
128 write2.AddContainer("MMcEvt", "Events", kFALSE);
129 write2.AddContainer("MPointingPos", "Events", kFALSE);
130 write2.AddContainer("MMcTrig", "Events", kFALSE);
131 write2.AddContainer("MRawEvtHeader", "Events");
132 write2.AddContainer("MHillas", "Events");
133 write2.AddContainer("MHillasExt", "Events");
134 write2.AddContainer("MHillasSrc", "Events");
135 write2.AddContainer("MNewImagePar", "Events");
136
137 //
138 // Divide output in train and test samples, using the event number
139 // (odd/even) to achieve otherwise unbiased event samples:
140 //
141
142 MF filter1("{MMcEvt.fEvtNumber%2}>0.5");
143 MF filter2("{MMcEvt.fEvtNumber%2}<0.5");
144
145 write1.SetFilter(&filter1);
146 write2.SetFilter(&filter2);
147
148 tlist.AddToList(&filter1);
149 tlist.AddToList(&filter2);
150 }
151
152
153 tlist.AddToList(&write1);
154
155 if (OutFilename2)
156 tlist.AddToList(&write2);
157
158
159 //
160 // analysis loop
161 //
162
163 MEvtLoop evtloop;
164 MProgressBar bar;
165 bar.SetWindowName("Analyzing...");
166 evtloop.SetProgressBar(&bar);
167 evtloop.SetParList(&plist);
168
169 if (!evtloop.Eventloop())
170 return;
171
172 tlist.PrintStatistics();
173
174 return;
175}
Note: See TracBrowser for help on using the repository browser.