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

Last change on this file since 8650 was 8644, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 4.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, 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#include "MStatusDisplay.h"
56
57// eventloop
58#include "MParList.h"
59#include "MTaskList.h"
60#include "MEvtLoop.h"
61
62// parameters
63#include "MParameters.h"
64#include "MGeomCamMagic.h"
65
66// histograms
67#include "../mhflux/MHEnergyEst.h"
68
69// tasks
70#include "MReadTree.h"
71#include "MMatrixLoop.h"
72#include "MEnergyEstimate.h"
73#include "MFillH.h"
74
75// filters
76#include "MFDataMember.h"
77
78using namespace std;
79
80ClassImp(MJOptimizeEnergy);
81
82//------------------------------------------------------------------------
83//
84// Read all events from file which do match rules and optimize
85// energy estimator.
86//
87Bool_t MJOptimizeEnergy::RunEnergy(const char *fname, const char *rule, MTask *weights)
88{
89 SetTitle(Form("OptimizeEnergy: %s", fname));
90
91 if (fDisplay)
92 fDisplay->SetTitle(fTitle);
93
94 fLog->Separator("Preparing Energy optimization");
95
96 MParList parlist;
97
98 MParameterI par("DataType");
99 par.SetVal(1);
100 parlist.AddToList(&par);
101
102 MFDataMember filter("DataType.fVal", '>', 0.5);
103 fPreCuts.Add(&filter);
104
105 MGeomCamMagic geom; // For GetConvMm2Deg
106 parlist.AddToList(&geom);
107
108 MHMatrix m("M");
109 AddRulesToMatrix(m);
110 parlist.AddToList(&m);
111
112 MHEnergyEst hist;
113 hist.InitMapping(&m);
114
115 MParameterCalc est(rule, "MParameters");
116 est.SetNameParameter("MEnergyEst");
117 parlist.AddToList(&est);
118
119 MReadTree read("Events");
120 // NECESSARY BECAUSE OF MDataFormula GetRules missing
121 read.DisableAutoScheme();
122 if (fname)
123 read.AddFile(fname);
124 else
125 AddSequences(read, fNamesOn);
126 if (!FillMatrix(read, parlist, kTRUE))
127 return kFALSE;
128
129 fPreCuts.Remove(&filter);
130
131 MTaskList tasklist;
132 parlist.Replace(&tasklist);
133
134 MFillH fill(&hist);
135 if (weights)
136 fill.SetWeight();
137
138 MMatrixLoop loop(&m);
139
140 tasklist.AddToList(&loop);
141 tasklist.AddToList(&est);
142 if (weights)
143 tasklist.AddToList(weights);
144 tasklist.AddToList(&fill);
145
146 // Optimize with the tasklist in this parameterlist
147 if (!Optimize(parlist))
148 return kFALSE;
149
150 // Print the result
151 *fLog << inf << "Finished processing of " << fname << endl;
152 *fLog << inf << "With Rule: " << rule << endl;
153 hist.Print();
154
155 // Store result if requested
156 TObjArray cont;
157 cont.Add(&est);
158 return WriteContainer(cont, fNameOut);
159}
Note: See TracBrowser for help on using the repository browser.