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

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