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

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