source: branches/Corsika7500Compatibility/mpointing/MSrcPosRndm.cc@ 19779

Last change on this file since 19779 was 9338, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 3.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, 3/2006 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2006
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MSrcPosRndm
28//
29// Input Container:
30// MHSrcPosCam
31//
32// Output Container:
33// MSrcPosCam
34//
35/////////////////////////////////////////////////////////////////////////////
36#include "MSrcPosRndm.h"
37
38#include <TRandom.h>
39
40#include "MLog.h"
41#include "MLogManip.h"
42
43#include "MParList.h"
44
45#include "MGeomCam.h"
46#include "MSrcPosCam.h"
47#include "MHSrcPosCam.h"
48
49ClassImp(MSrcPosRndm);
50
51using namespace std;
52
53// --------------------------------------------------------------------------
54//
55// Search for 'MPointingPos'. Create if not found.
56//
57Int_t MSrcPosRndm::PreProcess(MParList *plist)
58{
59 fGeom = (MGeomCam*)plist->FindObject("MGeomCam");
60 if (!fGeom)
61 {
62 *fLog << err << "ERROR - MGeomCam not found... aborting." << endl;
63 return kFALSE;
64 }
65
66 fSrcPos = (MSrcPosCam*)plist->FindCreateObj("MSrcPosCam");
67 if (!fSrcPos)
68 return kFALSE;
69
70 fSrcPosAnti = (MSrcPosCam*)plist->FindCreateObj("MSrcPosCam", "MSrcPosAnti");
71 if (!fSrcPosAnti)
72 return kFALSE;
73
74 if (fDistOfSource<0)
75 {
76 fHist = (MHSrcPosCam*)plist->FindObject("MHSrcPosCam");
77 if (!fHist)
78 {
79 *fLog << inf << "MHSrcPosCam not found... skipping." << endl;
80 return kSKIP;
81 }
82
83 *fLog << inf << "MHSrcPosCam found... taken to produce a random distribution." << endl;
84 }
85 else
86 *fLog << inf << "Source position will be produced randomly in a distance of " << fDistOfSource << "° from the camera center!" << endl;
87
88 return kTRUE;
89}
90
91// --------------------------------------------------------------------------
92//
93// See class description.
94//
95Int_t MSrcPosRndm::Process()
96{
97 Axis_t x, y;
98 if (fDistOfSource<0)
99 fHist->GetHist().GetRandom2(x, y);
100 else
101 {
102 const Double_t phi = gRandom->Uniform(TMath::TwoPi());
103 x = TMath::Cos(phi)*fDistOfSource;
104 y = TMath::Sin(phi)*fDistOfSource;
105 }
106
107 const Double_t f = fGeom->GetConvMm2Deg();
108
109 fSrcPos->SetXY(x/f, y/f);
110 if (fDistOfSource>=0)
111 fSrcPosAnti->SetXY(-x/f, -y/f);
112 return kTRUE;
113}
Note: See TracBrowser for help on using the repository browser.