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

Last change on this file since 7749 was 7721, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 11.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, 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), fSignificanceCutLevel(1.7),
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 fThetaSqCut = fSignificanceCutLevel*fFit.GetSignalIntegralMax()/1.7;
178
179 return kTRUE;
180}
181
182// --------------------------------------------------------------------------
183//
184// Return the value from fParemeter which should be filled into the plots
185//
186Double_t MHThetaSqN::GetVal() const
187{
188 return static_cast<const MParameterD*>(fParameter)->GetVal();
189}
190
191// --------------------------------------------------------------------------
192//
193// Abbreviation to set the value used by MHAlpha to fill the histogram
194//
195void MHThetaSqN::SetVal(Double_t val)
196{
197 static_cast<const MParameterD*>(fParameter)->SetVal(val);
198}
199
200// --------------------------------------------------------------------------
201//
202// Abbreviation to set the value used by MHAlpha to fill the histogram
203//
204TVector2 MHThetaSqN::GetVec(const TVector2 &v, Int_t n1) const
205{
206 if (!fMatrix)
207 return v;
208
209 return TVector2( (*fMatrix)[n1], (*fMatrix)[n1+1] );
210}
211
212Bool_t MHThetaSqN::Fill(const MParContainer *par, const Stat_t weight)
213{
214 const TVector2 mean(GetVec(fHillas->GetMean(), 6));
215 const TVector2 norm(GetVec(fHillas->GetNormAxis(), 8));
216
217 const TVector2 org = mean*fMm2Deg + norm*fDisp->GetVal();
218
219 // In the case we are filling off-data src0 contains the anti-source position
220 TVector2 src0(GetVec(fSrcPosCam->GetXY(), 10)*fMm2Deg);
221 if (!fOffData)
222 src0 *= -1;
223
224 const UInt_t n = fNumOffSourcePos+1;
225 const Float_t rad = TMath::TwoPi()/n;
226
227 // Calculate distance (theta-sq) to all (off-)source regions
228 TArrayD dist(n);
229 for (UInt_t i=0; i<n; i++)
230 {
231 const TVector2 src = const_cast<TVector2&>(src0).Rotate(i*rad);
232 dist[i] = (src-org).Mod2();
233 }
234
235 // Processing off-data
236 // Check if event's origin is in the on-regions
237 if (!fOffData && fDoOffCut && dist[0]<fThetaSqCut)
238 return kTRUE;
239
240 for (UInt_t i=0; i<n; i++)
241 {
242 // off: is in src region on: is in off regions
243 /// if (!fOffData && i==0) || (fOffData && i!=0)
244 if ((bool)fOffData ^ (i==0) )
245 continue;
246
247 Stat_t w = weight;
248
249 // Processing on-data
250 if (fOffData && fDoOffCut)
251 {
252 /*
253 static int cnt=0;
254 if (dist[1+(cnt++%fNumOffSourcePos)]<fFit.GetSignalIntegralMax())
255 continue;
256 */
257
258 // Check if event's origin is in one of the off-regions
259 for (UInt_t j=1; j<n; j++)
260 if (dist[j]<fThetaSqCut)
261 {
262 w *= (float)(fNumOffSourcePos-1)/fNumOffSourcePos;
263 break;
264 }
265 }
266
267 SetVal(dist[i]);
268
269 if (!MHAlpha::Fill(NULL, w))
270 return kFALSE;
271 }
272
273 if (!fOffData)
274 {
275 // off 0.4deg 0.3deg
276 // 5: 0.200 ~86% 0.150
277 // 4: 0.235 ~92% 0.176
278 // 3: 0.283 ~96% 0.212
279 // 2: 0.346 ~98% 0.260
280
281 const Double_t dist = src0.Mod()*TMath::Sin(rad/2);
282 if (dist<TMath::Sqrt(fFit.GetSignalIntegralMax()))
283 {
284 *fLog << warn << "WARNING - Source regions overlap: ";
285 *fLog << "distance " << dist << " less than theta-sq cut ";
286 *fLog << TMath::Sqrt(fFit.GetSignalIntegralMax()) << "!" << endl;
287 }
288 }
289
290 return kTRUE;
291}
292
293// --------------------------------------------------------------------------
294//
295// You can use this function if you want to use a MHMatrix instead of
296// MMcEvt. This function adds all necessary columns to the
297// given matrix. Afterward you should fill the matrix with the corresponding
298// data (eg from a file by using MHMatrix::Fill). If you now loop
299// through the matrix (eg using MMatrixLoop) MHHadronness::Fill
300// will take the values from the matrix instead of the containers.
301//
302// It takes fSkipHist* into account!
303//
304void MHThetaSqN::InitMapping(MHMatrix *mat, Int_t type)
305{
306 if (fMatrix)
307 return;
308
309 fMatrix = mat;
310
311 fMap[0] = -1;
312 fMap[1] = -1;
313 fMap[2] = -1;
314 fMap[3] = -1;
315 fMap[4] = -1;
316
317 if (!fSkipHistEnergy)
318 if (type==0)
319 {
320 fMap[1] = fMatrix->AddColumn("MEnergyEst.fVal");
321 fMap[2] = -1;
322 }
323 else
324 {
325 fMap[1] = -1;
326 fMap[2] = fMatrix->AddColumn("MHillas.fSize");
327 }
328
329 if (!fSkipHistTheta)
330 fMap[3] = fMatrix->AddColumn("MPointingPos.fZd");
331
332 fMap[5] = fMatrix->AddColumn("Disp.fVal");
333 fMap[6] = fMatrix->AddColumn("MHillas.fCosDelta");
334 fMap[7] = fMatrix->AddColumn("MHillas.fSinDelta");
335 fMap[8] = fMatrix->AddColumn("MHillas.fMeanX");
336 fMap[9] = fMatrix->AddColumn("MHillas.fMeanY");
337 fMap[10] = fMatrix->AddColumn("MSrcPosCam.fX");
338 fMap[11] = fMatrix->AddColumn("MSrcPosCan.fY");
339
340 // if (!fSkipHistTime)
341 // fMap[4] = fMatrix->AddColumn("MTime.GetAxisTime");
342}
343
344Int_t MHThetaSqN::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
345{
346 Int_t rc = MHAlpha::ReadEnv(env, prefix, print);
347 if (rc==kERROR)
348 return kERROR;
349
350 if (IsEnvDefined(env, prefix, "NumBinsSignal", print))
351 {
352 SetNumBinsSignal(GetEnvValue(env, prefix, "NumBinsSignal", (Int_t)fNumBinsSignal));
353 rc = kTRUE;
354 }
355 if (IsEnvDefined(env, prefix, "NumBinsTotal", print))
356 {
357 SetNumBinsTotal(GetEnvValue(env, prefix, "NumBinsTotal", (Int_t)fNumBinsTotal));
358 rc = kTRUE;
359 }
360 if (IsEnvDefined(env, prefix, "NumOffSourcePos", print))
361 {
362 SetNumOffSourcePos(GetEnvValue(env, prefix, "NumOffSourcePos", (Int_t)fNumOffSourcePos));
363 rc = kTRUE;
364 }
365 if (IsEnvDefined(env, prefix, "DoOffCut", print))
366 {
367 SetDoOffCut(GetEnvValue(env, prefix, "DoOffCut", fDoOffCut));
368 rc = kTRUE;
369 }
370 if (IsEnvDefined(env, prefix, "SignificanceCutLevel", print))
371 {
372 SetSignificanceCutLevel(GetEnvValue(env, prefix, "SignificanceCutLevel", fSignificanceCutLevel));
373 rc = kTRUE;
374 }
375 return rc;
376}
Note: See TracBrowser for help on using the repository browser.