source: branches/Corsika7500Compatibility/mtemp/mifae/library/MControlPlots.cc@ 19811

Last change on this file since 19811 was 5879, checked in by rico, 20 years ago
*** empty log message ***
File size: 6.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! Author(s): Javier Rico 04/2004 <mailto:jrico@ifae.es>
18! Ester Aliu 10/2004 <mailto:aliu@ifae.es> (update according
19! the new classes of the islands)
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MControlPlots
28//
29//
30//////////////////////////////////////////////////////////////////////////////
31
32#include <fstream>
33
34#include "TStyle.h"
35
36#include "MParList.h"
37#include "MControlPlots.h"
38#include "MIslands.h"
39#include "MImgIsland.h"
40#include "MHCamera.h"
41#include "MGeomCamMagic.h"
42
43#include "MLog.h"
44#include "MLogManip.h"
45
46ClassImp(MControlPlots);
47
48using namespace std;
49
50static const TString gsDefName = "MControlPlots";
51static const TString gsDefTitle = "Produce some control plots";
52
53// -------------------------------------------------------------------------
54//
55// Constructor
56//
57MControlPlots::MControlPlots(TString filename,const char* name, const char* title)
58 : fMode(kOn), fFileName(filename), fGeomCam(NULL), fIslands(NULL), fProduceFile(kTRUE)
59{
60 fName = name ? name : gsDefName.Data();
61 fTitle = title ? title : gsDefTitle.Data();
62
63 fCameraHisto[kOn] = NULL;
64 fCameraHisto[kOff] = NULL;
65
66}
67// -------------------------------------------------------------------------
68//
69// Destructor
70//
71MControlPlots::~MControlPlots()
72{
73 Clear();
74
75 if(fCameraHisto[kOn])
76 delete fCameraHisto[kOn];
77 if(fCameraHisto[kOff])
78 delete fCameraHisto[kOff];
79}
80
81void MControlPlots::Clear(const Option_t *o)
82{
83
84 if(fGeomCam)
85 delete fGeomCam;
86
87 fGeomCam = NULL;
88}
89
90
91// -------------------------------------------------------------------------
92//
93// Look for needed containers.
94//
95Int_t MControlPlots::PreProcess(MParList* pList)
96{
97
98 Reset();
99
100 // FIXME! only valid for Magic geometry for the time being!
101 fGeomCam = new MGeomCamMagic;
102
103 // look for MIslands object
104 fIslands = (MIslands*)pList->FindObject("MIslands");
105 if (!fIslands)
106 *fLog << warn << AddSerialNumber("MIslands") << " [MIslands] not found... Some control plots will not be produced" << endl;
107 else
108 {
109 if (fCameraHisto[fMode])
110 {
111 *fLog << err << GetDescriptor()
112 << "Camera with mode " << fMode << " already existing " << endl;
113 return kFALSE;
114 }
115 TString name = "";
116 switch (fMode)
117 {
118 case kOn:
119 name += "On";
120 break;
121 case kOff:
122 name += "Off";
123 break;
124 }
125 fCameraHisto[fMode] = new MHCamera(*fGeomCam,
126 name.Data(),
127 "Pixels surviving Image Cleaning");
128 }
129 return kTRUE;
130}
131
132// -------------------------------------------------------------------------
133//
134//
135Int_t MControlPlots::Process()
136{
137 if(!fIslands) return kTRUE;
138
139 MImgIsland *imgIsl = NULL;
140 TIter Next(fIslands->GetList());
141
142 Int_t pixNum = 0;
143 Int_t idPix = -1;
144
145 while ((imgIsl=(MImgIsland*)Next()))
146 {
147 pixNum = imgIsl->GetPixNum();
148
149 for(Int_t k = 0; k<pixNum; k++)
150 {
151 idPix = imgIsl->GetPixList(k);
152 fCameraHisto[fMode]->Fill(idPix,1.);
153 fCameraHisto[fMode]->SetUsed(idPix);
154 }
155 }
156
157 /* for (UInt_t i=0;i<fGeomCam->GetNumPixels();i++)
158 {
159 // cout << fIslands->GetIslId(i) << " ";
160 if (fIslands->GetIslId(i)>=0)
161 {
162 fCameraHisto[fMode]->Fill(i,1);
163 fCameraHisto[fMode]->SetUsed(i);
164 }
165 }*/
166
167 // cout << endl;
168 return kTRUE;
169}
170
171// -------------------------------------------------------------------------
172//
173//
174Int_t MControlPlots::PostProcess()
175{
176 if(!fProduceFile) return kTRUE;
177 if(fProduceFile && !fFileName.Length())
178 {
179 *fLog << warn << "MControlPlots::PostProcess Warning: output file requested but no name for it" << endl;
180 return kTRUE;
181 }
182
183 // Canvas style
184 gStyle->SetCanvasColor(0);
185 gStyle->SetCanvasBorderMode(0);
186 gStyle->SetPadBorderMode(0);
187 gStyle->SetFrameBorderMode(0);
188 gStyle->SetStatColor(0);
189 gStyle->SetTitleFillColor(0);
190
191 TCanvas* c = new TCanvas("survivals","Pixels surviving Image Cleaning",800,800);
192 MHCamera* diff=NULL;
193
194 // in case both on and off histos are present, print both and the difference between them
195 if(fCameraHisto[kOn] && fCameraHisto[kOff])
196 {
197 diff = new MHCamera(*fGeomCam,"Diff","Difference of pixels surviving Image Cleaning");
198
199 // Normalize Off to On
200 Float_t NormOn=0;
201 Float_t NormOff=0;
202 for(Int_t i=1;i<diff->GetSize()-2;i++)
203 {
204 NormOff+=fCameraHisto[kOff]->GetBinContent(i);
205 NormOn+=fCameraHisto[kOn]->GetBinContent(i);
206 }
207
208 fCameraHisto[kOff]->Scale(NormOn/NormOff);
209
210 for(Int_t i=1;i<diff->GetSize()-2;i++)
211 {
212 diff->SetBinContent(i,(Double_t)fCameraHisto[kOn]->GetBinContent(i)-fCameraHisto[kOff]->GetBinContent(i));
213 diff->SetUsed(i);
214 }
215 fCameraHisto[kOn]->SetPrettyPalette();
216 fCameraHisto[kOff]->SetPrettyPalette();
217 diff->SetPrettyPalette();
218
219 c->Divide(2,2);
220
221 Float_t max = TMath::Max(fCameraHisto[kOn]->GetMaximum(),fCameraHisto[kOff]->GetMaximum());
222 Float_t min = TMath::Min(fCameraHisto[kOn]->GetMinimum(),fCameraHisto[kOff]->GetMinimum());
223 fCameraHisto[kOn]->SetMaximum(max);
224 fCameraHisto[kOn]->SetMinimum(min);
225 fCameraHisto[kOff]->SetMaximum(max);
226 fCameraHisto[kOff]->SetMinimum(min);
227
228 c->cd(1);
229 fCameraHisto[kOn]->Draw();
230 gPad->Modified();
231 gPad->Update();
232
233 c->cd(2);
234 fCameraHisto[kOff]->Draw();
235 gPad->Modified();
236 gPad->Update();
237
238 c->cd(3);
239 diff->Draw();
240 gPad->Modified();
241 gPad->Update();
242
243 c->cd(4);
244 diff->DrawProjection();
245 gPad->Modified();
246 gPad->Update();
247 }
248 // plot the existing histo
249 else
250 {
251 c->cd(1);
252 fCameraHisto[fMode]->Draw();
253 gPad->Modified();
254 gPad->Update();
255 }
256
257 c->SaveAs(fFileName);
258 delete c;
259 if(diff)
260 delete diff;
261 return kTRUE;
262}
Note: See TracBrowser for help on using the repository browser.