source: branches/MarsMoreSimulationTruth/mtemp/mpisa/macros/AnalCurrents.C@ 20115

Last change on this file since 20115 was 4438, 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 {
133 for(Int_t i=0; i<gsNpix; i++)
134 dcevt.AddPixel(i,val[i]/(Double_t)count,0);
135
136 cout << "Calling test_findstar function" << endl;
137 test_findstar(&dcevt);
138 }
139
140 cout << "Number of averaged events stored into container = " << NumAverEvt << endl;
141 tlist.PrintStatistics();
142
143}
144
145
146// This macro creates a fake MCerPhotEvt container (with some clusters
147// that simulate the starfield seen by the DC currents) and then applies
148// the image cleaning and the Hillas algorithm to recognize and classify
149// the clusters.
150//
151void test_findstar(MCerPhotEvt *wDCEvt)
152{
153 //MGeomCamMagic *geom;
154 MCerPhotEvt *DCEvt = new MCerPhotEvt();
155 Int_t cluster[gsNpix];
156 Float_t startp[gsNpix];
157
158 memset(cluster,-1,gsNpix);
159 memset(startp,-1,gsNpix);
160
161 TVectorD *startpixs = new TVectorD();
162 Double_t tempDC;
163 Int_t pixid;
164 // fill a fake MCerPhotEvt
165 // loop over all pixels
166 for (pixid=0; pixid<gsNpix ; pixid++)
167 {
168 switch (pixid)
169 {
170 case 9:
171 DCEvt->AddPixel(pixid,1.1,0.0);
172 break;
173 case 2:
174 case 8:
175 case 21:
176 case 22:
177 case 23:
178 case 10:
179 DCEvt->AddPixel(pixid,1.1,0.0);
180 break;
181 case 39:
182 DCEvt->AddPixel(pixid,1.2,0.0);
183 break;
184 case 64:
185 DCEvt->AddPixel(pixid,1.71,0.0);
186 break;
187 case 65:
188 DCEvt->AddPixel(pixid,1.70,0.0);
189 break;
190 case 40:
191 DCEvt->AddPixel(pixid,1.72,0.0);
192 break;
193 default:
194 DCEvt->AddPixel(pixid);
195 break;
196 }
197 } // end loop over pixels
198
199 if(!(FindStartPixels(wDCEvt, startpixs)))
200 cout << "ARGH!@!! In function FindStartPixel(): no starting pixel found" << endl;
201
202}
203
204Int_t FindStartPixels(MCerPhotEvt *evt, TVectorD *startpixs)
205{
206 Double_t currDC;
207 Int_t i = 0;
208 Double_t DCthr = 10.0;
209
210 MCerPhotPix *dcpix;
211 MGeomPix *pix;
212
213 // look for all the pixels with a DC higher than the DC of neighbour pixels
214 // loop over all pixels
215 for (Int_t pixid=0; pixid<gsNpix; pixid++)
216 {
217 Double_t tempDC;
218
219 pix = (MGeomPix *)geomcam[pixid]; // MGeomCamMagic pixel
220
221 // Get the DC value of the current pixel
222 evt->GetPixelContent(currDC,pixid,geomcam,0);
223
224 Float_t maxDC = 0.0;
225 // look for the max DC in the neighbors pixels
226 for (Int_t j=0; j < pix->GetNumNeighbors(); j++)
227 {
228 evt->GetPixelContent(tempDC,pix->GetNeighbor(j),geomcam,0);
229 if(tempDC > maxDC)
230 maxDC = tempDC;
231 }
232
233 // a starting pixel was found: it is added to the array
234 if ((currDC>maxDC) && (currDC>DCthr))
235 {
236 startpixs->ResizeTo(++i);
237 startpixs(i-1)=pixid;
238 cout << "Starting pixel PixID=" << startpixs(i-1) << " curr=" << currDC << endl;
239 }
240 }
241
242 if(startpixs->GetNrows()>0)
243 {
244 cout << "Number of starting pixels = " << startpixs->GetNrows() << endl;
245 return 1;
246 }
247 else
248 return 0;
249}
250/*
251Int_t FindCluster(Int_t startpix, Int_t cluster, MGeomCam *geom)
252{
253 return 1;
254
255}
256*/
257
Note: See TracBrowser for help on using the repository browser.