source: trunk/MagicSoft/Mars/mtemp/mifae/library/MControlPlots.cc@ 5170

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