source: branches/AddingGoogleTestEnvironment/macros/tutorials/hft.C@ 18170

Last change on this file since 18170 was 7208, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 6.0 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/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2004-2005
21!
22!
23\* ======================================================================== */
24
25///////////////////////////////////////////////////////////////////////////
26//
27// hft.C
28//
29// example of using MHexagonal*
30//
31///////////////////////////////////////////////////////////////////////////
32
33Bool_t HandleInput()
34{
35 // This must be there to get accesss to the GUI while the macro
36 // is still running!
37
38 TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
39 while (1)
40 {
41 //
42 // While reading the input process gui events asynchronously
43 //
44 timer.TurnOn();
45 TString input = Getline("Type 'q' to exit, <return> to go on: ");
46 timer.TurnOff();
47
48 if (input=="q\n")
49 return kFALSE;
50
51 if (input=="\n")
52 return kTRUE;
53 };
54
55 return kFALSE;
56}
57
58//
59// Setup the data-members of your 'virtual' class
60//
61MHCamera display[5];
62
63TCanvas *c;
64MParList *fParList;
65MTaskList *fTaskList;
66
67MHexagonalFTCalc hft;
68MHexagonFreqSpace *fFreq1;
69MHexagonFreqSpace *fFreq2;
70
71MGeomCam *geomfreq;
72
73TH1F histo("", "", 35, -0.5, 35);
74
75//
76// Called like all PreProcess functions of tasks. Get the access to
77// the containers necessary for you.
78//
79Int_t PreProcess(MParList *plist)
80{
81 fFreq1 = (MHexagonFreqSpace*)plist->FindObject("MHexagonFreqSpace1");
82 if (!fFreq1)
83 return kFALSE;
84 fFreq2 = (MHexagonFreqSpace*)plist->FindObject("MHexagonFreqSpace2");
85 if (!fFreq2)
86 return kFALSE;
87
88 geomfreq=fFreq1->NewGeomCam();
89 geomfreq->SetName("FreqSpace");
90 plist->AddToList(geomfreq);
91
92 // return kTRUE;
93
94 // Get parameter and tasklist, see Process
95 fParList = plist;
96 fTaskList = (MTaskList*)plist->FindObject("MTaskList");
97
98 // Get camera geoemtry
99 MGeomCam *geomcam = (MGeomCam*)plist->FindObject("MGeomCam");
100
101 // setup canvas and camera-histograms
102 c = new TCanvas("Events", "Real Events", 900, 600);
103 c->SetBorderMode(0);
104 c->Divide(3,2);
105 for (int i=0; i<3; i++)
106 {
107 display[i].SetGeometry(*geomfreq);
108 display[i].SetPrettyPalette();
109 c->cd(i+1);
110 display[i].Draw();
111 }
112
113 display[1].SetName("In");
114 display[2].SetName("Out");
115 display[0].SetName("Freq");
116
117 return kTRUE;
118}
119
120//
121// Called like all Process functions of tasks. Process a single
122// event - here display it.
123//
124Int_t Process()
125{
126 // For simplicity we search in the Process function for the
127 // objects. This is deprectaed! Store the pointers to the objects
128 // as data member and get the pointers in PreProcess.
129 MClone *clone1 = (MClone*)fTaskList->FindObject("Clone1");
130 MClone *clone2 = (MClone*)fTaskList->FindObject("Clone2");
131 MGeomCam *geom = (MGeomCam*)fParList->FindObject("MGeomCam");
132
133 // Fill the data into your camera-histograms
134 display[1].SetCamContent(*fFreq1, 1);
135 display[2].SetCamContent(*fFreq1, 2);
136 display[0].SetCamContent(*fFreq2, 0);
137
138 display[1].SetMaximum(-1111);
139 display[2].SetMaximum(-1111);
140 display[1].SetMinimum(0);
141 display[2].SetMinimum(0);
142 display[1].SetMaximum(TMath::Max(display[1].GetMaximum(),
143 display[2].GetMaximum()));
144 display[2].SetMaximum(display[1].GetMaximum());
145
146 MHexagonalFT *ft = &hft.GetHFT();
147
148 histo.Reset();
149 for (int i=0; i<ft->GetNumKnots(); i++)
150 {
151 Double_t val=0;
152 fFreq2->GetPixelContent(val, i, *display[1].GetGeometry());
153 histo.Fill(ft->GetRow(i), val/(i+1));
154 }
155
156 c->cd(4);
157 histo.Draw();
158
159 c->cd(5);
160
161 TH1D *obj1 = (TH1D*)display[1].Projection("Proj1");
162 obj1->SetLineColor(kBlue);
163 obj1->Draw();
164 obj1 = (TH1D*)display[2].Projection("Proj2");
165 obj1->Draw("same");
166
167 c->cd(6);
168 display[0].DrawProjection();
169
170 // Update the display
171 for (int i=1; i<=3; i++)
172 {
173 c->GetPad(i)->GetPad(1)->Modified();
174 c->GetPad(i)->GetPad(1)->Update();
175 }
176
177 return HandleInput();
178}
179
180//
181// Called like all PostProcess functions of tasks. Delete
182// instanciated objects.
183//
184Int_t PostProcess()
185{
186 delete c;
187 delete geomfreq;
188}
189
190void hft(const char *fname="/home/tbretz/Software/mcwobble/lza/cal/19*.root")
191{
192 // Setup parameter- and tasklist
193 MParList plist;
194 MTaskList tlist;
195
196 plist.AddToList(&tlist);
197
198 // setup reading task
199 MReadMarsFile read("Events", fname);
200 read.DisableAutoScheme();
201
202 // Clone MCerPhotEvt befor eimage cleaning
203 MClone clone1("MSignalCam", "Clone1");
204
205 // Setup image cleaning
206 MImgCleanStd clean(8.5, 4);
207 clean.SetMethod(MImgCleanStd::kAbsolute);
208 clean.SetNamePedPhotCam("MPedPhotFromExtractorRndm");
209
210 // Clone MCerPhotEvt befor eimage cleaning
211 MClone clone2("MSignalCam", "Clone2");
212
213 // Setup intercative task calling the functions defined above
214 MTaskInteractive mytask;
215
216 mytask.SetPreProcess(PreProcess);
217 mytask.SetProcess(Process);
218
219 // Setup your tasklist
220 tlist.AddToList(&read);
221 tlist.AddToList(&clone1);
222 tlist.AddToList(&hft);
223 tlist.AddToList(&clone2);
224 tlist.AddToList(&clean);
225 tlist.AddToList(&mytask);
226
227 // Run your analysis
228 MEvtLoop evtloop;
229 evtloop.SetParList(&plist);
230
231 if (!evtloop.Eventloop())
232 return;
233
234 // Print statistics information about your loop
235 tlist.PrintStatistics();
236}
237
Note: See TracBrowser for help on using the repository browser.