source: trunk/Mars/hawc/plot_cleaned.C@ 20094

Last change on this file since 20094 was 19845, checked in by tbretz, 5 years ago
Allow also .q
File size: 7.5 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-2019
21!
22!
23\* ======================================================================== */
24
25///////////////////////////////////////////////////////////////////////////
26//
27// plot_cleaned.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//
34// Therefor MInteractiveTask is used, which gives you the possibility
35// to develop new tasks without the need of compilation.
36// The input is a merpp raw-data file.
37//
38///////////////////////////////////////////////////////////////////////////
39
40// ==========================================================================
41// ============ see plot_cleaned function at the end of the file ============
42// ==========================================================================
43Bool_t HandleInput()
44{
45 // This is a pure man's command line interface to wait for a key input
46 // and allow exit but at the same time allow interaction with the GUI
47 TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
48 while (1)
49 {
50 // While reading the input process gui events asynchronously
51 timer.TurnOn();
52 const char *gl = Getline("Type 'q' to exit, <return> to go on: ");
53 timer.TurnOff();
54
55 TString input = gl;
56 if (input=="q\n" || input==".q\n")
57 return kFALSE;
58
59 if (input=="\n")
60 return kTRUE;
61 };
62
63 return kFALSE;
64}
65
66// Create four camera histograms
67MHCamera display[4];
68
69// All 'data members' that are required globally
70TCanvas *c;
71MParList *fParList;
72MTaskList *fTaskList;
73
74//
75// Called like all PreProcess functions of tasks. Get the access to
76// the containers necessary for you.
77//
78Int_t PreProcess(MParList *plist)
79{
80 // Get parameter and tasklist, see Process
81 fParList = plist;
82 fTaskList = (MTaskList*)plist->FindObject("MTaskList");
83
84 // Get camera geoemtry
85 MGeomCam *geomcam = (MGeomCam*)plist->FindObject("MGeomCam");
86
87 // setup canvas and camera-histograms
88 c = new TCanvas("Events", "Real Events", 600, 600);
89 c->SetBorderMode(0);
90 c->Divide(2,2);
91 for (int i=0; i<4; i++)
92 {
93 // Tell all histograms which is the geometry to use
94 display[i].SetGeometry(*geomcam);
95
96 // Add the camera object to the pads
97 c->cd(i+1);
98 display[i].Draw();
99
100 // Add the MHillas object (which pains the ellipse)
101 gPad->cd(1);
102 plist->FindObject("MHillas")->Draw();
103 }
104 return kTRUE;
105}
106
107//
108// Called like all Process functions of tasks. Process a single
109// event - here display it.
110//
111Int_t Process()
112{
113 // For simplicity we search in the Process function for the
114 // objects. This is deprectaed! Store the pointers to the objects
115 // as data member and get the pointers in PreProcess.
116 MReadMarsFile *read = (MReadMarsFile*)fTaskList->FindObject("MRead");
117 MSignalCam *cam = (MSignalCam*) fTaskList->FindObject("MSignalCam");
118 MImgCleanStd *clean = (MImgCleanStd*) fTaskList->FindObject("MImgCleanStd");
119 MGeomCam *geom = (MGeomCam*) fParList->FindObject("MGeomCam");
120
121 // Ouput event number
122 cout << "Event #" << read->GetNumEntry() << ":" << endl;
123
124 // Fill the data into your camera-histograms
125 display[0].SetCamContent(*(MSignalCam*)fParList->FindObject("MSignalCam"), 9);
126 display[1].SetCamContent(*(MSignalCam*)fParList->FindObject("MSignalCam"), 3);
127 display[2].SetCamContent(*(MSignalCam*)fParList->FindObject("MSignalCam"), 6);
128 display[3].SetCamContent(*(MSignalCam*)fParList->FindObject("MSignalCam"), 8);
129
130 // Index of island
131 //display[3].SetCamContent(*(MSignalCam*)fParList->FindObject("MSignalCam"), 5);
132
133 // Update the display
134 for (int i=1; i<=4; i++)
135 {
136 c->GetPad(i)->Modified();
137 c->GetPad(i)->Update();
138 }
139
140 // print the data on the console
141 ((MHillas*)fParList->FindObject("MHillas"))->Print(*geom);
142 ((MHillasExt*)fParList->FindObject("MHillasExt"))->Print(*geom);
143 ((MNewImagePar*)fParList->FindObject("MNewImagePar"))->Print(*geom);
144
145 cout << "\n===================================================================" << endl;
146 bool rc = HandleInput();
147 cout << "===================================================================" << endl;
148
149 // wait for 'return'
150 return rc;
151}
152
153//
154// Called like all PostProcess functions of tasks. Delete
155// instanciated objects.
156//
157Int_t PostProcess()
158{
159 delete c;
160}
161
162// ==========================================================================
163//
164// Run the macro with
165//
166// root hawc/plot_cleaned.C\(\"00000001.003_Y_MonteCarlo003_Events.root\"\)
167//
168// The default file name is a Y-file (either as Monte Carlo-truth from ceres
169// or from the callisto)
170//
171// From within root, the escape characters can be omitted, e.g.
172//
173// root
174// [0] .x hawc/plot_cleaned.C("00000001.003_Y_MonteCarlo003_Events.root")
175//
176// ==========================================================================
177
178void plot_cleaned(const char *fname)
179{
180 // Setup parameter- and tasklist
181 MParList plist;
182 MTaskList tlist;
183 plist.AddToList(&tlist);
184
185 // Switch off blind pixels
186 MBadPixelsCam badpixels;
187 badpixels.InitSize(64);
188 badpixels[63].SetUnsuitable(MBadPixelsPix::kUnsuitable);
189 badpixels[62].SetUnsuitable(MBadPixelsPix::kUnsuitable);
190 badpixels[61].SetUnsuitable(MBadPixelsPix::kUnsuitable);
191 plist.AddToList(&badpixels);
192
193 // setup reading task
194 MReadMarsFile read("Events", fname);
195 read.DisableAutoScheme();
196
197 // setup a task making sure that all arrays are resized correctly
198 MGeomApply geomapl;
199
200 // Setup a print task calling TObject::Print
201 MPrint print1("MMcEvt");
202 MPrint print2("MRawEvtHeader");
203 // Skip them if containers are not found
204 print1.EnableSkip();
205 print2.EnableSkip();
206
207 // Switch off blind pixels
208 MBadPixelsTreat treat;
209 treat.SetProcessPedestalRun(kFALSE);
210 treat.SetProcessPedestalEvt(kFALSE);
211
212 // Setup image cleaning
213 MImgCleanTime clean;
214 clean.SetMinCount(0);
215 clean.SetMinSize(25);
216 clean.SetDeltaT(2.5);
217
218 // Setup calculation of Image parameters
219 MHillasCalc hcalc;
220
221 // Setup intercative task calling the functions defined above
222 MTaskInteractive mytask;
223 mytask.SetPreProcess(PreProcess);
224 mytask.SetProcess(Process);
225
226 // Setup your tasklist
227 tlist.AddToList(&read);
228 tlist.AddToList(&geomapl);
229 tlist.AddToList(&print1);
230 tlist.AddToList(&print2);
231 tlist.AddToList(&treat);
232 tlist.AddToList(&clean);
233 tlist.AddToList(&hcalc);
234 tlist.AddToList(&mytask);
235
236 // Run your analysis
237 MEvtLoop evtloop;
238 evtloop.SetParList(&plist);
239
240 if (!evtloop.Eventloop())
241 return;
242
243 // Print statistics information about your loop
244 tlist.PrintStatistics();
245}
246
Note: See TracBrowser for help on using the repository browser.