source: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcPlace.cc@ 4450

Last change on this file since 4450 was 4117, checked in by rico, 21 years ago
*** empty log message ***
File size: 6.9 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! Author(s): Javier Lopez 04/2004 <mailto:jlopez@ifae.es>
18! Author(s): Javier Rico 04/2004 <mailto:jrico@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MSrcPlace
28//
29// Abstract task to set the source position in any place in the camera
30// It keeps a 2D histogram with the assigned positions, so that the same
31// distribution can be applied later to any data set (tipically the OFF data)
32// Classes inheritating MSrcPlace should override the ComputeNewSrcPosition()
33// method and probably include a call to MsrcPlace::PreProcess in their
34// PreProcess method (see, e.g., MSrcPosFromFile or MSrcRotate classes)
35//
36// Input Containers:
37// MSrcPosCam
38//
39// Output Containers:
40// MSrcPosCam
41//
42//////////////////////////////////////////////////////////////////////////////
43
44#include <fstream>
45#include <math.h>
46
47#include "TH2F.h"
48
49#include "MParList.h"
50#include "MSrcPlace.h"
51#include "MSrcPosCam.h"
52
53#include "MLog.h"
54#include "MLogManip.h"
55
56ClassImp(MSrcPlace);
57
58using namespace std;
59
60static const TString gsDefName = "MSrcPlace";
61static const TString gsDefTitle = "Set the position of the source";
62
63// -------------------------------------------------------------------------
64//
65// Default constructor. The first argument is the name of the internal histo,
66// the second (third) argument is the name of the input (output) container
67// containing the source position in the camera plain.
68//
69MSrcPlace::MSrcPlace(const char* srcPosIn, const char* srcPosOut, const char *name, const char *title)
70 : fSrcPosIn(NULL), fSrcPosOut(NULL), fHistoName("SrcPosHist"),
71 fHistoBinPrec(1.), fHistPos(NULL)
72{
73 fName = name ? name : gsDefName.Data();
74 fTitle = title ? title : gsDefTitle.Data();
75
76 fSrcPosInName = srcPosIn;
77 fSrcPosOutName = srcPosOut;
78
79 fMode=kOn;
80 fCreateHisto=kTRUE;
81}
82// -------------------------------------------------------------------------
83//
84// Destructor
85//
86MSrcPlace::~MSrcPlace()
87{
88 if(fHistPos)
89 delete fHistPos;
90}
91
92// -------------------------------------------------------------------------
93//
94// Save the position of the source in the histogram
95//
96void MSrcPlace::SavePosIntoHisto()
97{
98 if(fHistPos)
99 fHistPos->Fill(fSrcPosOut->GetX(),fSrcPosOut->GetY());
100}
101// -------------------------------------------------------------------------
102//
103// Read the position of the source from the histogram
104//
105void MSrcPlace::ReadPosFromHisto()
106{
107 if(fHistPos)
108 {
109 Axis_t x;
110 Axis_t y;
111
112 fHistPos->GetRandom2(x,y);
113 fSrcPosOut->SetXY(x,y);
114 }
115}
116// -------------------------------------------------------------------------
117//
118// Look for needed containers.
119// Check processing mode and if histogram is filled in case kOff mode
120//
121Int_t MSrcPlace::PreProcess(MParList* pList)
122{
123 // create (if needed and requested) internal histogram
124 if(fCreateHisto && !fHistPos)
125 {
126 const Float_t cameraSize = 600; //[mm]
127 const UInt_t nbins = (UInt_t)(cameraSize*2/fHistoBinPrec);
128 fHistPos = new TH2F(fHistoName,"",nbins,-cameraSize,cameraSize,nbins,-cameraSize,cameraSize);
129 fHistPos->SetDirectory(0);
130 *fLog << inf << "MSrcPlace::PreProcess Message: internal histogram " << fHistoName << " created with " << nbins << "x" << nbins << " bins" << endl;
131 }
132
133 // look for/create input MSrcPosCam
134 fSrcPosIn = (MSrcPosCam*)pList->FindObject(AddSerialNumber(fSrcPosInName), "MSrcPosCam");
135 if (!fSrcPosIn)
136 {
137 *fLog << warn << AddSerialNumber(fSrcPosInName) << " [MSrcPosCam] not found... creating default container." << endl;
138 fSrcPosIn = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam", AddSerialNumber(fSrcPosInName));
139 if(!fSrcPosIn)
140 return kFALSE;
141 }
142
143 // look for/create output MSrcPosCam
144 fSrcPosOut = (MSrcPosCam*)pList->FindObject(AddSerialNumber(fSrcPosOutName), "MSrcPosCam");
145 if (!fSrcPosOut)
146 {
147 *fLog << warn << AddSerialNumber(fSrcPosOutName) << " [MSrcPosCam] not found... creating default container." << endl;
148 fSrcPosOut = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam", AddSerialNumber(fSrcPosOutName));
149 if(!fSrcPosOut)
150 return kFALSE;
151 }
152
153 // check mode, look for a filled histogram in case kOff
154 if(fHistPos)
155 {
156 if(fMode==kOn)
157 *fLog << inf << "MSrcPlace PreProcess Message: source postions will be stored in internal histo (" << fHistPos->GetName() << ")" << endl;
158 else
159 {
160 if(fHistPos->GetEntries())
161 *fLog << inf << "MSrcPlace PreProcess Message: source postions will be read from internal histo (" << fHistPos->GetName() << ")" << endl;
162 else
163 {
164 *fLog << err << "MSrcPlace PreProcess Error: source postions attempted to be read from empty histo (" << fHistPos->GetName() << ")" << endl;
165 return kFALSE;
166 }
167 }
168 }
169 return kTRUE;
170}
171
172// -------------------------------------------------------------------------
173//
174// Call to compute a new position and then save it in the histogram (fMode==kOn)
175// of to read the new position from the histogram (fMode==kOff)
176//
177Int_t MSrcPlace::Process()
178{
179 switch(fMode)
180 {
181 case kOn:
182 if(!ComputeNewSrcPosition())
183 return kFALSE;
184 SavePosIntoHisto();
185 break;
186 case kOff:
187 ReadPosFromHisto();
188 break;
189 default:
190 *fLog << err << "MSrcPlace::Process Warning: Wrong mode " << fMode << endl;
191 return kFALSE;
192 }
193 return kTRUE;
194}
195
196// -------------------------------------------------------------------------
197//
198// Dump 2D histo statistics
199//
200Int_t MSrcPlace::PostProcess()
201{
202 if(fMode==kOn && fHistPos)
203 {
204 *fLog << inf << endl;
205 *fLog << inf << "MSrcPlace::PostProcess Message: Created internal histogram with: " << endl;
206 *fLog << inf << "Entries: " << fHistPos->GetEntries() << endl;
207 *fLog << inf << "X projection mean: " << fHistPos->ProjectionX()->GetMean() << endl;
208 *fLog << inf << "X projection rms: " << fHistPos->ProjectionX()->GetRMS() << endl;
209 *fLog << inf << "Y projection mean: " << fHistPos->ProjectionY()->GetMean() << endl;
210 *fLog << inf << "Y projection rms: " << fHistPos->ProjectionY()->GetRMS() << endl;
211 }
212 return kTRUE;
213}
Note: See TracBrowser for help on using the repository browser.