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