source: branches/Mars_McMismatchStudy/macros/readMagic.C@ 18222

Last change on this file since 18222 was 3957, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 6.4 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 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25///////////////////////////////////////////////////////////////////////////
26//
27// readMagic.C
28// ===========
29//
30// This is a demonstration program showing how to do particular processing
31// on a single event basis. Here we simply display uncleand und cleand
32// images.
33// Therefor MInteractiveTask is used, which gives you the possibility
34// to develop new tasks without the need of compilation.
35// The input is a merpp raw-data file.
36//
37///////////////////////////////////////////////////////////////////////////
38
39Bool_t HandleInput()
40{
41 // This must be there to get accesss to the GUI while the macro
42 // is still running!
43
44 TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
45 while (1)
46 {
47 //
48 // While reading the input process gui events asynchronously
49 //
50 timer.TurnOn();
51 TString input = Getline("Type 'q' to exit, <return> to go on: ");
52 timer.TurnOff();
53
54 if (input=="q\n")
55 return kFALSE;
56
57 if (input=="\n")
58 return kTRUE;
59 };
60
61 return kFALSE;
62}
63
64//
65// Setup the data-members of your 'virtual' class
66//
67MHCamera display[4];
68
69TCanvas *c;
70MParList *fParList;
71MTaskList *fTaskList;
72
73//
74// Called like all PreProcess functions of tasks. Get the access to
75// the containers necessary for you.
76//
77Int_t PreProcess(MParList *plist)
78{
79 // Get parameter and tasklist, see Process
80 fParList = plist;
81 fTaskList = (MTaskList*)plist->FindObject("MTaskList");
82
83 // Get camera geoemtry
84 MGeomCam *geomcam = (MGeomCam*)plist->FindObject("MGeomCam");
85
86 // setup canvas and camera-histograms
87 c = new TCanvas("Events", "Real Events", 600, 600);
88 c->SetBorderMode(0);
89 c->Divide(2,2);
90 for (int i=0; i<4; i++)
91 {
92 display[i].SetGeometry(*geomcam);
93 c->cd(i+1);
94 display[i].Draw();
95 gPad->cd(1);
96 plist->FindObject("MHillas")->Draw();
97 }
98 return kTRUE;
99}
100
101//
102// Called like all Process functions of tasks. Process a single
103// event - here display it.
104//
105Int_t Process()
106{
107 // For simplicity we search in the Process function for the
108 // objects. This is deprectaed! Store the pointers to the objects
109 // as data member and get the pointers in PreProcess.
110 MReadMarsFile *read = (MReadMarsFile*)fTaskList->FindObject("MRead");
111 MClone *clone = (MClone*)fTaskList->FindObject("MClone");
112 MImgCleanStd *clean = (MImgCleanStd*)fTaskList->FindObject("MImgCleanStd");
113 MGeomCam *geom = (MGeomCam*)fParList->FindObject("MGeomCam");
114
115 // Ouput event number
116 cout << "Event #" << read->GetNumEntry() << ":" << endl;
117
118 // Fill the data into your camera-histograms
119 display[0].SetCamContent(*(MCerPhotEvt*)clone->GetClone());
120 display[1].SetCamContent(*(MCerPhotEvt*)fParList->FindObject("MCerPhotEvt"));
121 display[2].SetCamContent(*(MCameraData*)fParList->FindObject("MCameraData"));
122 display[3].SetCamContent(*(MCameraData*)fParList->FindObject("MCameraData"));
123
124 // Setup the cleaning level histogram
125 TArrayF lvl(2);
126 lvl[0] = clean->GetCleanLvl2();
127 lvl[1] = clean->GetCleanLvl1();
128 display[3].SetLevels(lvl);
129
130 // Update the display
131 for (int i=1; i<=4; i++)
132 {
133 c->GetPad(i)->GetPad(1)->Modified();
134 c->GetPad(i)->GetPad(1)->Update();
135 }
136
137 // print the data on the console
138 ((MHillas*)fParList->FindObject("MHillas"))->Print(*geom);
139 ((MHillasExt*)fParList->FindObject("MHillasExt"))->Print(*geom);
140 ((MNewImagePar*)fParList->FindObject("MNewImagePar"))->Print(*geom);
141
142 // wait for 'return'
143 return HandleInput();
144}
145
146//
147// Called like all PostProcess functions of tasks. Delete
148// instanciated objects.
149//
150Int_t PostProcess()
151{
152 delete c;
153}
154
155void readMagic(const char *fname="../Proton*.root")
156{
157 // Setup parameter- and tasklist
158 MParList plist;
159 MTaskList tlist;
160
161 plist.AddToList(&tlist);
162
163 // setup reading task
164 MReadMarsFile read("Events", fname);
165 read.DisableAutoScheme();
166
167 // setup a task making sure that all arrays are resized correctly
168 MGeomApply geomapl;
169
170 // Setup a print task calling TObject::Print
171 MPrint print1("MMcEvt");
172 MPrint print2("MRawEvtHeader");
173 // Skip them if conatainers are not found
174 print1.EnableSkip();
175 print2.EnableSkip();
176
177 // Copy MC pedestals to apropriate conatiners (if MC file)
178 MMcPedestalCopy pcopy;
179 MMcPedestalNSBAdd pnsb;
180
181 // Calculate signal and pedestal from data (use MCerPhotCalc
182 // in case of MC files)
183 MCerPhotAnal2 ncalc;
184
185 // Blind Pixel Treatment (deprecated, will be replaced by
186 // MBadPixel*)
187 MBlindPixelCalc blind;
188 blind.SetUseInterpolation();
189
190 // Clone MCerPhotEvt befor eimage cleaning
191 MClone clone("MCerPhotEvt");
192
193 // Setup image cleaning
194 MImgCleanStd clean;
195
196 // Setup calculation of Image parameters
197 MHillasCalc hcalc;
198
199 // Setup intercative task calling the functions defined above
200 MTaskInteractive mytask;
201
202 mytask.SetPreProcess(PreProcess);
203 mytask.SetProcess(Process);
204
205 // Setup your tasklist
206 tlist.AddToList(&read);
207 tlist.AddToList(&geomapl);
208 tlist.AddToList(&print1);
209 tlist.AddToList(&print2);
210 tlist.AddToList(&pcopy);
211 tlist.AddToList(&pnsb);
212 tlist.AddToList(&ncalc);
213 tlist.AddToList(&blind);
214 tlist.AddToList(&clone);
215 tlist.AddToList(&clean);
216 tlist.AddToList(&hcalc);
217 tlist.AddToList(&mytask);
218
219 // Run your analysis
220 MEvtLoop evtloop;
221 evtloop.SetParList(&plist);
222
223 if (!evtloop.Eventloop())
224 return;
225
226 // Print statistics information about your loop
227 tlist.PrintStatistics();
228}
229
Note: See TracBrowser for help on using the repository browser.