source: trunk/MagicSoft/Mars/mhflux/MHThetaSqN.cc@ 7718

Last change on this file since 7718 was 7718, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 9.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): Thomas Bretz, 5/2006 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2006
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MHThetaSqN
28//
29// For more detailes see MHAlpha.
30//
31// How to use this class:
32// - in your ganymed.rc add:
33// MJCut.NameHist: MHThetaSqN
34// - setup the number of off-source regions in your ganymed.rc by:
35// MHThetaSqN.NumOffSourcePos: 2
36// - switch on/off whether an off-theta cut should be done:
37// MHThetaSqN.DoOffCut: Yes,No
38// - and if necessary switch off the Theta cut in your Magic cuts:
39// Cut1.ThetaCut: None
40//
41//////////////////////////////////////////////////////////////////////////////
42#include "MHThetaSqN.h"
43
44#include <TVector2.h>
45
46#include "MParameters.h"
47#include "MSrcPosCam.h"
48#include "MGeomCam.h"
49#include "MHMatrix.h"
50#include "MHillas.h"
51
52#include "MBinning.h"
53#include "MParList.h"
54#include "MTaskList.h"
55#include "MParameters.h"
56
57#include "MLog.h"
58#include "MLogManip.h"
59
60ClassImp(MHThetaSqN);
61
62using namespace std;
63
64// --------------------------------------------------------------------------
65//
66// Default Constructor
67//
68MHThetaSqN::MHThetaSqN(const char *name, const char *title)
69 : MHAlpha(name, title), fDisp(0), fSrcPosCam(0),
70 fNumBinsSignal(3), fNumBinsTotal(75), fNumOffSourcePos(3), fDoOffCut(kTRUE)
71{
72 //
73 // set the name and title of this object
74 //
75 fName = name ? name : "MHThetaSqN";
76 fTitle = title ? title : "Theta Squared plot";
77
78 fNameParameter = "ThetaSquared";
79
80 fHist.SetName("Theta");
81 fHist.SetTitle("Theta");
82 fHist.SetZTitle("\\vartheta^{2} [deg^{2}]");
83 fHist.SetDirectory(NULL);
84
85 // Main histogram
86 fHistTime.SetName("Theta");
87 fHistTime.SetXTitle("\\vartheta^{2} [deg^{2}]");
88 fHistTime.SetDirectory(NULL);
89
90 MBinning binsa, binse, binst;
91 binsa.SetEdges(75, 0, 1.5);
92 //binsa.SetEdges(arr);
93 binse.SetEdgesLog(15, 10, 100000);
94 binst.SetEdgesASin(67, -0.005, 0.665);
95 binsa.Apply(fHistTime);
96
97 MH::SetBinning(&fHist, &binst, &binse, &binsa);
98
99 fParameter = new MParameterD;
100}
101
102MHThetaSqN::~MHThetaSqN()
103{
104 delete fParameter;
105}
106
107// --------------------------------------------------------------------------
108//
109// Overwrites the binning in Alpha (ThetaSq) with a binning for which
110// the upper edge of the 5th bin (bin=5) fit the signal integration window.
111// In total 75 bins are setup.
112//
113// In case of fOffData!=NULL the binnings are taken later from fOffData anyhow.
114//
115Bool_t MHThetaSqN::SetupFill(const MParList *pl)
116{
117 // Default is from default fitter
118 // if a user defined fitter is in the parlist: use this range
119 MAlphaFitter *fit = (MAlphaFitter*)pl->FindObject("MAlphaFitter");
120 if (!fit)
121 fit = &fFit;
122
123 MParameterD *cut = (MParameterD*)pl->FindObject("ThetaSquaredCut", "MParameterD");
124 if (cut)
125 fit->SetSignalIntegralMax(cut->GetVal());
126
127 // Get Histogram binnings
128 MBinning binst, binse;
129 binst.SetEdges(fHist, 'x');
130 binse.SetEdges(fHist, 'y');
131
132 // Calculate bining which fits alpha-cut
133 const Double_t intmax = fit->GetSignalIntegralMax();
134 const UInt_t nbins = fNumBinsTotal;
135 const UInt_t nsig = fNumBinsSignal;
136
137 MBinning binsa(nbins, 0, nbins*intmax/nsig);
138
139 // Apply binning
140 binsa.Apply(fHistTime);
141 MH::SetBinning(&fHist, &binst, &binse, &binsa);
142
143 // Remark: Binnings might be overwritten in MHAlpha::SetupFill
144 if (!MHAlpha::SetupFill(pl))
145 return kFALSE;
146
147 fDisp = (MParameterD*)pl->FindObject("Disp", "MParameterD");
148 if (!fDisp)
149 {
150 *fLog << err << "Disp [MParameterD] not found... abort." << endl;
151 return kFALSE;
152 }
153 fHillas = (MHillas*)pl->FindObject("MHillas");
154 if (!fHillas)
155 {
156 *fLog << err << "MHillas not found... abort." << endl;
157 return kFALSE;
158 }
159 fSrcPosCam = (MSrcPosCam*)pl->FindObject("MSrcPosCam");
160 if (!fSrcPosCam)
161 {
162 *fLog << err << "MSrcPosCam not found... abort." << endl;
163 return kFALSE;
164 }
165
166 MGeomCam *geom = (MGeomCam*)pl->FindObject("MGeomCam");
167 if (!geom)
168 {
169 *fLog << err << "MGeomCam not found... abort." << endl;
170 return kFALSE;
171 }
172 fMm2Deg = geom->GetConvMm2Deg();
173
174 if (fFit.GetScaleMode()==MAlphaFitter::kNone)
175 fFit.SetScaleUser(1./fNumOffSourcePos);
176
177 return kTRUE;
178}
179
180// --------------------------------------------------------------------------
181//
182// Return the value from fParemeter which should be filled into the plots
183//
184Double_t MHThetaSqN::GetVal() const
185{
186 return static_cast<const MParameterD*>(fParameter)->GetVal();
187}
188
189void MHThetaSqN::SetVal(Double_t val)
190{
191 static_cast<const MParameterD*>(fParameter)->SetVal(val);
192}
193
194TVector2 MHThetaSqN::GetVec(const TVector2 &v, Int_t n1) const
195{
196 if (!fMatrix)
197 return v;
198
199 return TVector2( (*fMatrix)[n1], (*fMatrix)[n1+1] );
200}
201
202Bool_t MHThetaSqN::Fill(const MParContainer *par, const Stat_t weight)
203{
204 const TVector2 mean(GetVec(fHillas->GetMean(), 6));
205 const TVector2 norm(GetVec(fHillas->GetNormAxis(), 8));
206
207 const TVector2 org = mean*fMm2Deg + norm*fDisp->GetVal();
208
209 // In the case we are filling off-data src0 contains the anti-source position
210 TVector2 src0(GetVec(fSrcPosCam->GetXY(), 10)*fMm2Deg);
211 if (!fOffData)
212 src0 *= -1;
213
214 const UInt_t n = fNumOffSourcePos+1;
215 const Float_t rad = TMath::TwoPi()/n;
216
217 for (UInt_t i=0; i<n; i++)
218 {
219 const TVector2 src = const_cast<TVector2&>(src0).Rotate(i*rad);
220 const Double_t d = (src-org).Mod2();
221
222 // off: is in src region on: is in off regions
223 /// if (!fOffData && i==0) || (fOffData && i!=0)
224 if ((bool)fOffData ^ (i==0) )
225 {
226 if (d<fFit.GetSignalIntegralMax() && fDoOffCut)
227 return kTRUE;
228
229 // do not fill off data when aiming for on and vice versa
230 continue;
231 }
232
233 SetVal(d);
234
235 if (!MHAlpha::Fill(NULL, weight))
236 return kFALSE;
237 }
238
239 if (!fOffData)
240 {
241 // off 0.4deg 0.3deg
242 // 5: 0.200 ~86% 0.150
243 // 4: 0.235 ~92% 0.176
244 // 3: 0.283 ~96% 0.212
245 // 2: 0.346 ~98% 0.260
246
247 const Double_t dist = src0.Mod()*TMath::Sin(rad/2);
248 if (dist<TMath::Sqrt(fFit.GetSignalIntegralMax()))
249 {
250 *fLog << warn << "WARNING - (Off-)source regions start overlapping: ";
251 *fLog << "distance " << dist << " less than theta-sq cut ";
252 *fLog << TMath::Sqrt(fFit.GetSignalIntegralMax()) << "!" << endl;
253 }
254 }
255
256 return kTRUE;
257}
258
259// --------------------------------------------------------------------------
260//
261// You can use this function if you want to use a MHMatrix instead of
262// MMcEvt. This function adds all necessary columns to the
263// given matrix. Afterward you should fill the matrix with the corresponding
264// data (eg from a file by using MHMatrix::Fill). If you now loop
265// through the matrix (eg using MMatrixLoop) MHHadronness::Fill
266// will take the values from the matrix instead of the containers.
267//
268// It takes fSkipHist* into account!
269//
270void MHThetaSqN::InitMapping(MHMatrix *mat, Int_t type)
271{
272 if (fMatrix)
273 return;
274
275 fMatrix = mat;
276
277 fMap[0] = -1;
278 fMap[1] = -1;
279 fMap[2] = -1;
280 fMap[3] = -1;
281 fMap[4] = -1;
282
283 if (!fSkipHistEnergy)
284 if (type==0)
285 {
286 fMap[1] = fMatrix->AddColumn("MEnergyEst.fVal");
287 fMap[2] = -1;
288 }
289 else
290 {
291 fMap[1] = -1;
292 fMap[2] = fMatrix->AddColumn("MHillas.fSize");
293 }
294
295 if (!fSkipHistTheta)
296 fMap[3] = fMatrix->AddColumn("MPointingPos.fZd");
297
298 fMap[5] = fMatrix->AddColumn("Disp.fVal");
299 fMap[6] = fMatrix->AddColumn("MHillas.fCosDelta");
300 fMap[7] = fMatrix->AddColumn("MHillas.fSinDelta");
301 fMap[8] = fMatrix->AddColumn("MHillas.fMeanX");
302 fMap[9] = fMatrix->AddColumn("MHillas.fMeanY");
303 fMap[10] = fMatrix->AddColumn("MSrcPosCam.fX");
304 fMap[11] = fMatrix->AddColumn("MSrcPosCan.fY");
305
306 // if (!fSkipHistTime)
307 // fMap[4] = fMatrix->AddColumn("MTime.GetAxisTime");
308}
309
310Int_t MHThetaSqN::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
311{
312 Int_t rc = MHAlpha::ReadEnv(env, prefix, print);
313 if (rc==kERROR)
314 return kERROR;
315
316 if (IsEnvDefined(env, prefix, "NumBinsSignal", print))
317 {
318 SetNumBinsSignal(GetEnvValue(env, prefix, "NumBinsSignal", (Int_t)fNumBinsSignal));
319 rc = kTRUE;
320 }
321 if (IsEnvDefined(env, prefix, "NumBinsTotal", print))
322 {
323 SetNumBinsTotal(GetEnvValue(env, prefix, "NumBinsTotal", (Int_t)fNumBinsTotal));
324 rc = kTRUE;
325 }
326 if (IsEnvDefined(env, prefix, "NumOffSourcePos", print))
327 {
328 SetNumOffSourcePos(GetEnvValue(env, prefix, "NumOffSourcePos", (Int_t)fNumOffSourcePos));
329 rc = kTRUE;
330 }
331 if (IsEnvDefined(env, prefix, "DoOffCut", print))
332 {
333 SetDoOffCut(GetEnvValue(env, prefix, "DoOffCut", fDoOffCut));
334 rc = kTRUE;
335 }
336 return rc;
337}
Note: See TracBrowser for help on using the repository browser.