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): Robert Wagner, 2/2004 <mailto:rwagner@mppmu.mpg.de>
|
---|
18 | ! Author(s): Javier López , 4/2004 <mailto:jlopez@ifae.es>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MFindStars
|
---|
28 | //
|
---|
29 | /////////////////////////////////////////////////////////////////////////////
|
---|
30 | #include "MFindStars.h"
|
---|
31 |
|
---|
32 | #include <TFile.h>
|
---|
33 | #include <TTree.h>
|
---|
34 |
|
---|
35 | #include "MObservatory.h"
|
---|
36 | #include "MAstroCamera.h"
|
---|
37 | #include "MMcConfigRunHeader.h"
|
---|
38 |
|
---|
39 | #include "MLog.h"
|
---|
40 | #include "MLogManip.h"
|
---|
41 |
|
---|
42 | #include "MHCamera.h"
|
---|
43 |
|
---|
44 | #include "MGeomCam.h"
|
---|
45 | #include "MGeomPix.h"
|
---|
46 | #include "MCameraDC.h"
|
---|
47 | #include "MTime.h"
|
---|
48 | #include "MReportDrive.h"
|
---|
49 | #include "MStarLocalCam.h"
|
---|
50 | #include "MStarLocalPos.h"
|
---|
51 |
|
---|
52 | #include "MParList.h"
|
---|
53 |
|
---|
54 | ClassImp(MFindStars);
|
---|
55 | using namespace std;
|
---|
56 |
|
---|
57 | MFindStars::MFindStars(const char *name, const char *title)
|
---|
58 | {
|
---|
59 | fName = name ? name : "MFindStars";
|
---|
60 | fTitle = title ? title : "Tool to find stars from Base Currents";
|
---|
61 |
|
---|
62 | fMaxNumIntegratedEvents = 10;
|
---|
63 | fRingInterest = 100; //[mm] ~ 0.3 deg
|
---|
64 |
|
---|
65 | fPixelsUsed.Set(577);
|
---|
66 | fPixelsUsed.Reset((Char_t)kTRUE);
|
---|
67 | }
|
---|
68 |
|
---|
69 | Int_t MFindStars::PreProcess(MParList *pList)
|
---|
70 | {
|
---|
71 |
|
---|
72 | fGeomCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
|
---|
73 |
|
---|
74 | if (!fGeomCam)
|
---|
75 | {
|
---|
76 | *fLog << err << AddSerialNumber("MGeomCam") << " not found ... aborting" << endl;
|
---|
77 | return kFALSE;
|
---|
78 | }
|
---|
79 |
|
---|
80 | fCurr = (MCameraDC*)pList->FindObject(AddSerialNumber("MCameraDC"));
|
---|
81 |
|
---|
82 | if (!fCurr)
|
---|
83 | {
|
---|
84 | *fLog << err << AddSerialNumber("MCameraDC") << " not found ... aborting" << endl;
|
---|
85 | return kFALSE;
|
---|
86 | }
|
---|
87 |
|
---|
88 | fTimeCurr = (MTime*)pList->FindObject(AddSerialNumber("MTimeCurrents"));
|
---|
89 |
|
---|
90 | if (!fTimeCurr)
|
---|
91 | {
|
---|
92 | *fLog << err << AddSerialNumber("MTimeCurrents") << " not found ... aborting" << endl;
|
---|
93 | return kFALSE;
|
---|
94 | }
|
---|
95 |
|
---|
96 | fDrive = (MReportDrive*)pList->FindObject(AddSerialNumber("MReportDrive"));
|
---|
97 |
|
---|
98 | if (!fDrive)
|
---|
99 | {
|
---|
100 | *fLog << err << AddSerialNumber("MReportDrive") << " not found ... aborting" << endl;
|
---|
101 | return kFALSE;
|
---|
102 | }
|
---|
103 |
|
---|
104 | fStars = (MStarLocalCam*)pList->FindCreateObj(AddSerialNumber("MStarLocalCam"));
|
---|
105 | if (!fStars)
|
---|
106 | {
|
---|
107 | *fLog << err << AddSerialNumber("MStarLocalCam") << " cannot be created ... aborting" << endl;
|
---|
108 | return kFALSE;
|
---|
109 | }
|
---|
110 |
|
---|
111 | //Initialitation MAstroCamera
|
---|
112 | // Name of a MC file having MGeomCam and MMcConfigRunHeader
|
---|
113 | TString fname = "../data/Gamma_zbin9_90_7_1480to1489_w0.root";
|
---|
114 |
|
---|
115 | // Time for which to get the picture
|
---|
116 | // MTime time;
|
---|
117 | // time.Set(2004, 2, 28, 01, 32, 15);
|
---|
118 |
|
---|
119 | // Current observatory
|
---|
120 | MObservatory magic1;
|
---|
121 |
|
---|
122 | // Right Ascension [h] and declination [deg] of source
|
---|
123 | // Currently 'perfect' pointing is assumed
|
---|
124 | // const Double_t ra = MAstro::Hms2Rad(5, 34, 31.9);
|
---|
125 | // const Double_t dec = MAstro::Dms2Rad(22, 0, 52.0);
|
---|
126 |
|
---|
127 | // --------------------------------------------------------------------------
|
---|
128 | // Create camera display from geometry
|
---|
129 | MMcConfigRunHeader *config=0;
|
---|
130 | MGeomCam *geom=0;
|
---|
131 |
|
---|
132 | TFile file(fname);
|
---|
133 | TTree *tree = (TTree*)file.Get("RunHeaders");
|
---|
134 | tree->SetBranchAddress("MMcConfigRunHeader", &config);
|
---|
135 | if (tree->GetBranch("MGeomCam"))
|
---|
136 | tree->SetBranchAddress("MGeomCam", &geom);
|
---|
137 | tree->GetEntry(0);
|
---|
138 |
|
---|
139 | fAstro.SetMirrors(*config->GetMirrors());
|
---|
140 | fAstro.SetGeom(*geom);
|
---|
141 |
|
---|
142 |
|
---|
143 | fAstro.SetLimMag(6);
|
---|
144 | fAstro.SetRadiusFOV(3);
|
---|
145 | fAstro.ReadBSC("../data/bsc5.dat");
|
---|
146 |
|
---|
147 | fAstro.SetObservatory(magic1);
|
---|
148 | // Time for which to get the picture
|
---|
149 | // MTime time;
|
---|
150 | // time.Set(2004, 2, 28, 01, 32, 15);
|
---|
151 | // fAstro.SetTime(time);
|
---|
152 | fAstro.SetTime(*fTimeCurr);
|
---|
153 | fAstro.SetGuiActive();
|
---|
154 |
|
---|
155 | fAstro.SetStarList(fStars->GetList());
|
---|
156 |
|
---|
157 | return kTRUE;
|
---|
158 | }
|
---|
159 |
|
---|
160 | Int_t MFindStars::Process()
|
---|
161 | {
|
---|
162 |
|
---|
163 | Float_t ra = fDrive->GetRa();
|
---|
164 | Float_t dec = fDrive->GetDec();
|
---|
165 |
|
---|
166 | fAstro.SetRaDec(ra, dec);
|
---|
167 | fAstro.SetGuiActive();
|
---|
168 |
|
---|
169 | fAstro.FillStarList();
|
---|
170 |
|
---|
171 | if (fNumIntegratedEvents < fMaxNumIntegratedEvents)
|
---|
172 | {
|
---|
173 | fDisplay.AddCamContent(*fCurr);
|
---|
174 | fNumIntegratedEvents++;
|
---|
175 | }
|
---|
176 | else
|
---|
177 | {
|
---|
178 | //loop to extract position of stars on the camera
|
---|
179 | TIter Next(fStars->GetList());
|
---|
180 | MStarLocalPos* star;
|
---|
181 | while ((star=(MStarLocalPos*)Next()))
|
---|
182 | FindStar(star);
|
---|
183 |
|
---|
184 | //After finding stars reset all vairables
|
---|
185 | fDisplay.Reset();
|
---|
186 | fNumIntegratedEvents=0;
|
---|
187 | }
|
---|
188 |
|
---|
189 | return kTRUE;
|
---|
190 | }
|
---|
191 |
|
---|
192 | Int_t MFindStars::PostProcess()
|
---|
193 | {
|
---|
194 | fStars->Print();
|
---|
195 | return kTRUE;
|
---|
196 | }
|
---|
197 |
|
---|
198 | void MFindStars::SetBlindPixels(TArrayS blindpixels)
|
---|
199 | {
|
---|
200 | Int_t npix = blindpixels.GetSize();
|
---|
201 |
|
---|
202 | for (Int_t idx=0; idx<npix; idx++)
|
---|
203 | fPixelsUsed[blindpixels[idx]]=(Char_t)kFALSE;
|
---|
204 |
|
---|
205 | fDisplay.SetUsed(fPixelsUsed);
|
---|
206 | }
|
---|
207 |
|
---|
208 | Bool_t MFindStars::FindStar(MStarLocalPos* star)
|
---|
209 | {
|
---|
210 |
|
---|
211 | Float_t expX = star->GetXExp();
|
---|
212 | Float_t expY = star->GetYExp();
|
---|
213 |
|
---|
214 | UInt_t numPixels = fGeomCam->GetNumPixels();
|
---|
215 |
|
---|
216 | // First define a area of interest around the expected position of the star
|
---|
217 | for (UInt_t pix=1; pix<numPixels; pix++)
|
---|
218 | {
|
---|
219 |
|
---|
220 | Float_t pixXpos=(*fGeomCam)[pix].GetX();
|
---|
221 | Float_t pixYpos=(*fGeomCam)[pix].GetY();
|
---|
222 | Float_t dist = sqrt((pixXpos-expX)*(pixXpos-expX)+
|
---|
223 | (pixYpos-expY)*(pixYpos-expY));
|
---|
224 |
|
---|
225 | if (dist < fRingInterest)
|
---|
226 | fPixelsUsed[pix]=(Char_t)kTRUE;
|
---|
227 | }
|
---|
228 |
|
---|
229 | fDisplay.SetUsed(fPixelsUsed);
|
---|
230 |
|
---|
231 | // Find the two close pixels with the maximun dc
|
---|
232 | for (UInt_t pix=1; pix<numPixels; pix++)
|
---|
233 | {
|
---|
234 | Float_t maxDC = 0;
|
---|
235 |
|
---|
236 | if(fDisplay.IsUsed(pix))
|
---|
237 | {
|
---|
238 | Float_t dc[2];
|
---|
239 | Float_t maxPix[2];
|
---|
240 | dc[0] = fDisplay.GetBinContent(pix+1);
|
---|
241 |
|
---|
242 | MGeomPix g = (*fGeomCam)[pix];
|
---|
243 | Int_t numNextNeighbors = g.GetNumNeighbors();
|
---|
244 |
|
---|
245 | Float_t dcsum;
|
---|
246 | for(Int_t nextNeighbor=0; nextNeighbor<numNextNeighbors; nextNeighbor++)
|
---|
247 | {
|
---|
248 | if(fDisplay.IsUsed(pix))
|
---|
249 | {
|
---|
250 | UInt_t swneighbor = g.GetNeighbor(nextNeighbor);
|
---|
251 | dc[1] = fDisplay.GetBinContent(swneighbor+1);
|
---|
252 |
|
---|
253 |
|
---|
254 | dcsum = dc[0] + dc[1];
|
---|
255 |
|
---|
256 | if(dcsum > maxDC*2)
|
---|
257 | {
|
---|
258 | maxPix[0] = pix;
|
---|
259 | maxPix[1] = swneighbor;
|
---|
260 | maxDC = dcsum/2;
|
---|
261 | }
|
---|
262 | }
|
---|
263 | }
|
---|
264 | }
|
---|
265 | }
|
---|
266 |
|
---|
267 | // determine mean x and mean y of the selected px
|
---|
268 | Float_t meanX=0;
|
---|
269 | Float_t meanY=0;
|
---|
270 | Float_t meanSqX=0;
|
---|
271 | Float_t meanSqY=0;
|
---|
272 | Float_t sumCharge=0;
|
---|
273 | UInt_t usedPx=0;
|
---|
274 | for(UInt_t pix=0; pix<numPixels; pix++)
|
---|
275 | {
|
---|
276 | if(fDisplay.IsUsed(pix))
|
---|
277 | {
|
---|
278 | usedPx++;
|
---|
279 |
|
---|
280 | Float_t charge=fDisplay.GetBinContent(pix+1);
|
---|
281 | Float_t pixXpos=(*fGeomCam)[pix].GetX();
|
---|
282 | Float_t pixYpos=(*fGeomCam)[pix].GetY();
|
---|
283 |
|
---|
284 | meanX+=charge*pixXpos;
|
---|
285 | meanY+=charge*pixYpos;
|
---|
286 | meanSqX+=charge*pixXpos*pixXpos;
|
---|
287 | meanSqY+=charge*pixYpos*pixYpos;
|
---|
288 | sumCharge+=charge;
|
---|
289 | // fDisplay.ResetUsed(i); // this px must not be used again!
|
---|
290 | } //for... use
|
---|
291 | }
|
---|
292 |
|
---|
293 | star->SetCalcValues(sumCharge,meanX,meanY,meanSqX,meanSqY);
|
---|
294 | fStars->GetList()->Add(star);
|
---|
295 |
|
---|
296 | return kTRUE;
|
---|
297 | }
|
---|
298 |
|
---|
299 |
|
---|
300 |
|
---|
301 |
|
---|