source: trunk/MagicSoft/Mars/mtemp/mpisa/macros/AnalCurrents.C@ 4437

Last change on this file since 4437 was 4437, checked in by galante, 20 years ago
*** empty log message ***
File size: 6.2 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): Javier López, 04/2004 <mailto:jlopez@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24/*
25#include <iostream>
26#include <stdlib.h>
27#include <string.h>
28#include <TString.h>
29#include <TArrayS.h>
30
31#include "MParList.h"
32#include "MTaskList.h"
33#include "MGeomCamMagic.h"
34#include "MCameraDC.h"
35
36#include "MReadReports.h"
37#include "MGeomApply.h"
38#include "MEvtLoop.h"
39*/
40const Int_t gsNpix = 577;
41MGeomCamMagic geomcam;
42
43using namespace std;
44
45void AnalCurrents(const TString filename)
46{
47 //UInt_t numEvents = 1000000;
48 UInt_t numEvents = 1;
49
50 //
51 // Create a empty Parameter List and an empty Task List
52 // The tasklist is identified in the eventloop by its name
53 //
54 MParList plist;
55 MTaskList tlist;
56 plist.AddToList(&tlist);
57
58
59 MCameraDC dccam;
60
61 plist.AddToList(&geomcam);
62 plist.AddToList(&dccam);
63
64 //
65 // Now setup the tasks and tasklist:
66 // ---------------------------------
67 //
68 // Reads the trees of the root file and the analysed branches
69 MReadReports read;
70 read.AddTree("Currents");
71 read.AddFile(filename); // after the reading of the trees!!!
72 read.AddToBranchList("MReportCurrents.*");
73
74 MGeomApply geomapl;
75
76 tlist.AddToList(&geomapl);
77 tlist.AddToList(&read);
78
79 //
80 // Create and setup the eventloop
81 //
82 MEvtLoop evtloop;
83 evtloop.SetParList(&plist);
84
85 MCerPhotEvt dcevt;
86
87 const Int_t NSteps = 5; // Number of steps to average DC over events
88 Int_t count = 0; // counter for averaging NSteps events
89 Int_t NumAverEvt = 1; // counter for averaged events stored into dcevt
90 Double_t val[gsNpix]; // array for managing the averaging of gsNpix
91 // DC values over NSteps events
92
93 // Initialize to 0 array val
94 for(Int_t i=0; i<gsNpix; i++)
95 val[i] = 0.0;
96 //
97 // Execute your analysis
98 //
99 //if (!evtloop.Eventloop(numEvents))
100 // return kFALSE;
101 if (!evtloop.PreProcess())
102 return;
103
104 while (tlist.Process())
105 {
106 ++count;
107 for(Int_t i=0; i<gsNpix; i++)
108 {
109 val[i] += dccam.GetCurrent(i);
110
111 if( (count%NSteps) == 0 )
112 {
113 dcevt.AddPixel(i,val[i]/(Double_t)NSteps,0);
114 dcevt.GetPixelContent(val[i],i,geomcam,0);
115 val[i] = 0.0;
116 }
117 }
118
119 // Reset count and call findstar function on this macroevent
120 if( (count%NSteps) == 0 )
121 {
122 count = 0;
123 ++NumAverEvt;
124 cout << "Calling test_findstar function" << endl;
125 test_findstar(&dcevt);
126 }
127 }
128
129 // Last loop overall pixels to fill with the average
130 // of last count events
131 if(count!=0)
132 for(Int_t i=0; i<gsNpix; i++)
133 dcevt.AddPixel(i,val[i]/(Double_t)count,0);
134
135 cout << "Calling test_findstar function" << endl;
136 test_findstar(&dcevt);
137
138 cout << "Number of averaged events stored into container = " << NumAverEvt << endl;
139 tlist.PrintStatistics();
140
141}
142
143
144// This macro creates a fake MCerPhotEvt container (with some clusters
145// that simulate the starfield seen by the DC currents) and then applies
146// the image cleaning and the Hillas algorithm to recognize and classify
147// the clusters.
148//
149void test_findstar(MCerPhotEvt *wDCEvt)
150{
151 //MGeomCamMagic *geom;
152 MCerPhotEvt *DCEvt = new MCerPhotEvt();
153 Int_t cluster[gsNpix];
154 Float_t startp[gsNpix];
155
156 memset(cluster,-1,gsNpix);
157 memset(startp,-1,gsNpix);
158
159 TVectorD *startpixs = new TVectorD();
160 Double_t tempDC;
161 Int_t pixid;
162 // fill a fake MCerPhotEvt
163 // loop over all pixels
164 for (pixid=0; pixid<gsNpix ; pixid++)
165 {
166 switch (pixid)
167 {
168 case 9:
169 DCEvt->AddPixel(pixid,1.1,0.0);
170 break;
171 case 2:
172 case 8:
173 case 21:
174 case 22:
175 case 23:
176 case 10:
177 DCEvt->AddPixel(pixid,1.1,0.0);
178 break;
179 case 39:
180 DCEvt->AddPixel(pixid,1.2,0.0);
181 break;
182 case 64:
183 DCEvt->AddPixel(pixid,1.71,0.0);
184 break;
185 case 65:
186 DCEvt->AddPixel(pixid,1.70,0.0);
187 break;
188 case 40:
189 DCEvt->AddPixel(pixid,1.72,0.0);
190 break;
191 default:
192 DCEvt->AddPixel(pixid);
193 break;
194 }
195 } // end loop over pixels
196
197 if(!(FindStartPixels(wDCEvt, startpixs)))
198 cout << "ARGH!@!! In function FindStartPixel(): no starting pixel found" << endl;
199
200}
201
202Int_t FindStartPixels(MCerPhotEvt *evt, TVectorD *startpixs)
203{
204 Double_t currDC;
205 Int_t i = 0;
206 Double_t DCthr = 10.0;
207
208 MCerPhotPix *dcpix;
209 MGeomPix *pix;
210
211 // look for all the pixels with a DC higher than the DC of neighbour pixels
212 // loop over all pixels
213 for (Int_t pixid=0; pixid<gsNpix; pixid++)
214 {
215 Double_t tempDC;
216
217 pix = (MGeomPix *)geomcam[pixid]; // MGeomCamMagic pixel
218
219 // Get the DC value of the current pixel
220 evt->GetPixelContent(currDC,pixid,geomcam,0);
221
222 Float_t maxDC = 0.0;
223 // look for the max DC in the neighbors pixels
224 for (Int_t j=0; j < pix->GetNumNeighbors(); j++)
225 {
226 evt->GetPixelContent(tempDC,pix->GetNeighbor(j),geomcam,0);
227 if(tempDC > maxDC)
228 maxDC = tempDC;
229 }
230
231 // a starting pixel was found: it is added to the array
232 if ((currDC>maxDC) && (currDC>DCthr))
233 {
234 startpixs->ResizeTo(++i);
235 startpixs(i-1)=pixid;
236 cout << "Starting pixel PixID=" << startpixs(i-1) << " curr=" << currDC << endl;
237 }
238 }
239
240 if(startpixs->GetNrows()>0)
241 {
242 cout << "Number of starting pixels = " << startpixs->GetNrows() << endl;
243 return 1;
244 }
245 else
246 return 0;
247}
248/*
249Int_t FindCluster(Int_t startpix, Int_t cluster, MGeomCam *geom)
250{
251 return 1;
252
253}
254*/
255
Note: See TracBrowser for help on using the repository browser.