source: trunk/MagicSoft/Mars/macros/CT1EgyEst.C@ 2153

Last change on this file since 2153 was 2116, checked in by wittek, 22 years ago
*** empty log message ***
File size: 9.0 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): Thomas Bretz, 09/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Abelardo Moralejo, 03/2003 <mailto:moralejo@pd.infn.it>
20! Wolfgang Wittek, 04/2003 <mailto:wittek@mppmu.mpg.de>
21!
22! Copyright: MAGIC Software Development, 2000-2003
23!
24!
25\* ======================================================================== */
26
27#include "MParList.h"
28#include "MTaskList.h"
29#include "MGeomCamCT1.h"
30#include "MFEventSelector.h"
31#include "MReadTree.h"
32#include "MFCT1SelFinal.h"
33#include "MHMatrix.h"
34#include "MEnergyEstParam.h"
35#include "MMatrixLoop.h"
36#include "MChisqEval.h"
37#include "MLog.h"
38#include "MLogManip.h"
39
40void CT1EgyEst()
41{
42 // TString inPath = "~magican/ct1test/wittek/marsoutput/optionA/";
43 TString inPath = "./";
44 TString fileNameIn = "MC1.root";
45
46 // TString outPath = "~magican/ct1test/wittek/marsoutput/optionA/";
47 TString outPath = "./";
48 TString energyParName = "energyest.root";
49
50 TString hilName = "MHillas";
51 TString hilSrcName = "MHillasSrc";
52
53 // TString hadronnessName = "MHadronness";
54 TString hadronnessName = "HadNN";
55
56 // Int_t howMany = 10000;
57 Int_t howMany = 2000;
58
59 Float_t maxhadronness = 0.3;
60 Float_t maxalpha = 20.0;
61 Float_t maxdist = 1.;
62
63 CT1EEst(inPath, fileNameIn,
64 outPath, energyParName,
65 hilName, hilSrcName, hadronnessName,
66 howMany, maxhadronness, maxalpha, maxdist);
67}
68
69//------------------------------------------------------------------------
70//
71// Arguments of CT1EEst :
72// ------------------------
73//
74// inPath, fileNameIn path and name of input file (MC gamma events)
75// outPath, energyParName path and name of file containing the parameters
76// of the energy estimator
77// hilName, hilSrcName names of "MHillas" and "MHillasSrc" containers
78// hadronnessName name of container holding the hadronness
79// howMany no.of events to be read from input file
80// maxhadronness maximum value of hadronness to be accepted
81// maxalpha maximum value of |ALPHA| to be accepted
82// maxdist maximum value of DIST (degrees) to be accepted
83//
84
85void CT1EEst(TString inPath, TString fileNameIn,
86 TString outPath, TString energyParName,
87 TString hilName, TString hilSrcName, TString hadronnessName,
88 Int_t howMany,
89 Float_t maxhadronness, Float_t maxalpha, Float_t maxdist)
90{
91 cout << "================================================================"
92 << endl;
93 cout << "Start of energy estimation part" << endl;
94 cout << "" << endl;
95 cout << "CT1EEst input values : " << endl;
96 cout << "---------------------- " << endl;
97 cout << "inPath, fileNameIn = "
98 << inPath << ", " << fileNameIn << endl;
99 cout << "outPath, energyParName = "
100 << outPath << ", " << energyParName << endl;
101 cout << "hilName, hilSrcName, hadronnessName = " << hilName << ", "
102 << hilSrcName << ", " << hadronnessName << endl;
103 cout << "howMany, maxhadronness, maxalpha, maxdist = " << howMany << ", "
104 << maxhadronness << ", " << maxalpha << ", " << maxdist << endl;
105 cout << "" << endl;
106
107
108 //==========================================================================
109 // Start of Part 1 (determination of the parameters of the energy estimator)
110 //
111
112 //-----------------------------------------------------------------------
113 // Fill events into a MHMatrix,
114 // to be used later in the minimization by MINUIT
115 //
116
117 MMcEnergyEst Optimize;
118
119 TString inputfile(outPath);
120 inputfile += fileNameIn;
121 Optimize.SetInFile(inputfile);
122
123 TString paramout(outPath);
124 paramout += energyParName;
125 Optimize.SetOutFile(paramout);
126
127 MFCT1SelFinal filterhadrons;
128 filterhadrons.SetHadronnessName(hadronnessName);
129 filterhadrons.SetCuts(maxhadronness, maxalpha, maxdist);
130 filterhadrons.SetInverted();
131 Optimize.SetEventFilter(&filterhadrons);
132
133 Optimize.SetNevents(howMany);
134
135 //
136 // Find the optimal parameters for the energy estimator:
137 //
138 Optimize.FindParams();
139
140 cout << "--------------------------------------" << endl;
141 cout << "Write parameters of energy estimator onto file '"
142 << paramout << endl;
143 cout << "--------------------------------------" << endl;
144
145 Optimize.Print();
146
147 TFile out(paramout, "recreate");
148 Optimize.SetReadyToSave();
149 Optimize.Write();
150 out.Close();
151
152 //
153 // END of Part 1
154 //==========================================================================
155
156
157
158 //==========================================================================
159 // Start of Part 2 (test quality of energy estimation)
160 //
161 //
162
163 //--------------------------------------------
164 // Read the parameters of the energy estimator
165 //
166
167 TString paramin(outPath);
168 paramin += energyParName;
169
170 TFile enparam(paramin);
171 MMcEnergyEst mcest;
172 mcest.Read("MMcEnergyEst");
173 enparam.Close();
174
175 cout << "--------------------------------------" << endl;
176 cout << "Read parameters of energy estimator from file '"
177 << paramin << endl;
178
179 TArrayD parA(5);
180 TArrayD parB(7);
181
182 for (Int_t i=0; i<parA.GetSize(); i++)
183 parA[i] = mcest.GetCoeff(i);
184 for (Int_t i=0; i<parB.GetSize(); i++)
185 parB[i] = mcest.GetCoeff(i+parA.GetSize());
186
187 //-----------------------------------------------
188 // Create energy estimator task, add necessary containers and
189 // initialize parameters read from file:
190 //
191
192 MEnergyEstParam eest2(hilName);
193 eest2.Add(hilSrcName);
194
195 eest2.SetCoeffA(parA);
196 eest2.SetCoeffB(parB);
197
198
199 //=======================================================================
200 // Setup the event loop
201 //
202 cout << "--------------------------------------" << endl;
203 cout << "Setup event loop for checking quality of energy estimation" << endl;
204
205
206 MTaskList tlist2;
207 MParList parlist2;
208
209 //-----------------------------------------------
210 // Read events
211 //
212
213 TString inputfile(inPath);
214 inputfile += fileNameIn;
215
216 cout << "Read events from file '" << inputfile << "'" << endl;
217 MReadTree read2("Events");
218 read2.AddFile(inputfile);
219 read2.DisableAutoScheme();
220
221
222 //-----------------------------------------------
223 // Select events
224 //
225 cout << "Select events with hadronness < " << maxhadronness
226 << " and |alpha| < " << maxalpha << endl;
227 MFCT1SelFinal hcut2;
228 hcut2.SetHadronnessName(hadronnessName); hcut2;
229 hcut2.SetCuts(maxhadronness, maxalpha, maxdist);
230
231 MContinue cont(&hcut2);
232
233 parlist2.AddToList(&tlist2);
234
235 //********************************
236 // Entries in MTaskList
237
238 tlist2.AddToList(&read2);
239 tlist2.AddToList(&cont);
240 tlist2.AddToList(&eest2);
241
242 //
243 // Create Object MHMcEnergyMigration containing useful histograms,
244 // and task MHMcEnergyMigration to fill them:
245 //
246
247 MHMcEnergyMigration mighist;
248
249 parlist2.AddToList(&mighist);
250
251 MFillH migfill(&mighist, "MMcEvt");
252
253 tlist2.AddToList(&migfill);
254
255 MBinning BinningE("BinningE");
256 MBinning BinningTheta("BinningTheta");
257 BinningE.SetEdgesLog(50, 500, 50000.);
258 BinningTheta.SetEdges(5, 0., 50.);
259
260 parlist2.AddToList(&BinningE);
261 parlist2.AddToList(&BinningTheta);
262
263 MBinning BinningDE("BinningDE");
264 MBinning BinningImpact("BinningImpact");
265
266 BinningDE.SetEdges(60, -1.2, 1.2);
267 BinningImpact.SetEdges(50, 0., 400.);
268 parlist2.AddToList(&BinningDE);
269 parlist2.AddToList(&BinningImpact);
270
271 cout << "Event loop was setup" << endl;
272 MProgressBar bar;
273
274 MEvtLoop evtloop2;
275 evtloop2.SetProgressBar(&bar);
276 evtloop2.SetParList(&parlist2);
277
278 if (!evtloop2.Eventloop())
279 return;
280
281 TString paramout(outPath);
282 paramout += energyParName;
283
284 TFile out2(paramout, "UPDATE");
285 mighist.Write();
286 out2.Close();
287
288 mighist.Draw();
289
290 cout << "Quality histograms were added onto the file '" << paramout << endl;
291 cout << endl;
292 cout << "End of energy estimation part" << endl;
293 cout << "================================================================" << endl;
294 //
295 // End of Part 2 (test quality of energy estimation)
296 //==========================================================================
297 //
298
299 return;
300
301}
Note: See TracBrowser for help on using the repository browser.