source: trunk/MagicSoft/Mars/mjoptim/MJOptimizeEnergy.cc@ 7572

Last change on this file since 7572 was 7169, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 3.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, 9/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MJOptimize
28//
29// Class for otimizing a rule to estimate the energy. For more details see
30// MJOptimize.
31//
32// Example:
33// --------
34//
35// MJOptimizeEnergy opt;
36// opt.SetDebug(2);
37// opt.SetOptimizer(MJOptimize::kMigrad);
38// opt.SetNumEvents(20000);
39// opt.EnableTestTrain();
40// opt.AddParameter("MHillas.fSize");
41// opt.SetParameter(0, 1, 0, 2);
42// char *r = "[0]*M[0]"; //Rule to calculate estimated energy
43// MStatusDisplay *d = new MStatusDisplay;
44// opt.SetDisplay(d);
45// opt.RunDisp("ganymed-summary.root", r);
46//
47/////////////////////////////////////////////////////////////////////////////
48#include "MJOptimizeEnergy.h"
49
50#include "MHMatrix.h"
51
52// environment
53#include "MLog.h"
54#include "MLogManip.h"
55
56// eventloop
57#include "MParList.h"
58#include "MTaskList.h"
59#include "MEvtLoop.h"
60
61// parameters
62#include "MParameters.h"
63#include "MGeomCamMagic.h"
64
65// histograms
66#include "../mhflux/MHEnergyEst.h"
67
68// tasks
69#include "MReadTree.h"
70#include "MMatrixLoop.h"
71#include "MEnergyEstimate.h"
72#include "MFillH.h"
73
74// filters
75#include "MFDataMember.h"
76
77using namespace std;
78
79ClassImp(MJOptimizeEnergy);
80
81//------------------------------------------------------------------------
82//
83// Read all events from file which do match rules and optimize
84// energy estimator.
85//
86Bool_t MJOptimizeEnergy::RunEnergy(const char *fname, const char *rule, MTask *weights)
87{
88 fLog->Separator("Preparing Energy optimization");
89
90 MParList parlist;
91
92 MParameterI par("DataType");
93 par.SetVal(1);
94 parlist.AddToList(&par);
95
96 MFDataMember filter("DataType.fVal", '>', 0.5);
97 fPreCuts.Add(&filter);
98
99 MGeomCamMagic geom; // For GetConvMm2Deg
100 parlist.AddToList(&geom);
101
102 MHMatrix m("M");
103 AddRulesToMatrix(m);
104 parlist.AddToList(&m);
105
106 MHEnergyEst hist;
107 hist.InitMapping(&m);
108
109 MParameterCalc est(rule, "MParameters");
110 est.SetNameParameter("MEnergyEst");
111 parlist.AddToList(&est);
112
113 MReadTree read("Events");
114 // NECESSARY BECAUSE OF MDataFormula GetRules missing
115 read.DisableAutoScheme();
116 if (fname)
117 read.AddFile(fname);
118 else
119 AddSequences(read, fNamesOn);
120 if (!FillMatrix(read, parlist, kTRUE))
121 return kFALSE;
122
123 fPreCuts.Remove(&filter);
124
125 MTaskList tasklist;
126 parlist.Replace(&tasklist);
127
128 MFillH fill(&hist);
129 if (weights)
130 fill.SetWeight();
131
132 MMatrixLoop loop(&m);
133
134 tasklist.AddToList(&loop);
135 tasklist.AddToList(&est);
136 if (weights)
137 tasklist.AddToList(weights);
138 tasklist.AddToList(&fill);
139
140 // Optimize with the tasklist in this parameterlist
141 if (!Optimize(parlist))
142 return kFALSE;
143
144 // Print the result
145 *fLog << inf << "Rule: " << rule << endl;
146 hist.Print();
147
148 // Store result if requested
149 TObjArray cont;
150 cont.Add(&est);
151 return WriteContainer(cont, fNameOut);
152}
Note: See TracBrowser for help on using the repository browser.