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): Robert Wagner <mailto:magicsoft@rwagner.de> 10/2002
|
---|
19 | ! Wolfgang Wittek <mailto:wittek@mppmu.mpg.de> 02/2003
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2003
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | /////////////////////////////////////////////////////////////////////////////
|
---|
27 | // //
|
---|
28 | // MPadSchweizer //
|
---|
29 | // //
|
---|
30 | // This task applies padding such that for a given pixel and for a given //
|
---|
31 | // Theta bin the resulting distribution of the pedestal sigma is identical//
|
---|
32 | // to the distributions given by fHSigmaPixTheta and fHDiffPixTheta. //
|
---|
33 | // //
|
---|
34 | // The number of photons, its error and the pedestal sigmas are altered. //
|
---|
35 | // On average, the number of photons added is zero. //
|
---|
36 | // //
|
---|
37 | // The formulas used can be found in Thomas Schweizer's Thesis, //
|
---|
38 | // Section 2.2.1 //
|
---|
39 | // //
|
---|
40 | // There are 2 options for the padding : //
|
---|
41 | // //
|
---|
42 | // 1) fPadFlag = 1 : //
|
---|
43 | // Generate first a Sigmabar using the 2D-histogram Sigmabar vs. Theta //
|
---|
44 | // (fHSigmaTheta). Then generate a pedestal sigma for each pixel using //
|
---|
45 | // the 3D-histogram Theta, pixel no., Sigma^2-Sigmabar^2 //
|
---|
46 | // (fHDiffPixTheta). //
|
---|
47 | // //
|
---|
48 | // This is the preferred option as it takes into account the //
|
---|
49 | // correlations between the Sigma of a pixel and Sigmabar. //
|
---|
50 | // //
|
---|
51 | // 2) fPadFlag = 2 : //
|
---|
52 | // Generate a pedestal sigma for each pixel using the 3D-histogram //
|
---|
53 | // Theta, pixel no., Sigma (fHSigmaPixTheta). //
|
---|
54 | // //
|
---|
55 | // //
|
---|
56 | // The padding has to be done before the image cleaning because the //
|
---|
57 | // image cleaning depends on the pedestal sigmas. //
|
---|
58 | // //
|
---|
59 | // //
|
---|
60 | // This implementation has been tested for CT1 data. For MAGIC some //
|
---|
61 | // modifications are necessary. //
|
---|
62 | // //
|
---|
63 | /////////////////////////////////////////////////////////////////////////////
|
---|
64 | #include "MPadSchweizer.h"
|
---|
65 |
|
---|
66 | #include <stdio.h>
|
---|
67 |
|
---|
68 | #include "TH1.h"
|
---|
69 | #include "TH2.h"
|
---|
70 | #include "TH3.h"
|
---|
71 | #include "TProfile.h"
|
---|
72 | #include "TRandom.h"
|
---|
73 | #include "TCanvas.h"
|
---|
74 |
|
---|
75 | #include "MBinning.h"
|
---|
76 | #include "MSigmabar.h"
|
---|
77 | #include "MMcEvt.hxx"
|
---|
78 | #include "MLog.h"
|
---|
79 | #include "MLogManip.h"
|
---|
80 | #include "MParList.h"
|
---|
81 | #include "MGeomCam.h"
|
---|
82 |
|
---|
83 | #include "MCerPhotPix.h"
|
---|
84 | #include "MCerPhotEvt.h"
|
---|
85 |
|
---|
86 | #include "MPedestalCam.h"
|
---|
87 | #include "MPedestalPix.h"
|
---|
88 |
|
---|
89 | ClassImp(MPadSchweizer);
|
---|
90 |
|
---|
91 | // --------------------------------------------------------------------------
|
---|
92 | //
|
---|
93 | // Default constructor.
|
---|
94 | //
|
---|
95 | MPadSchweizer::MPadSchweizer(const char *name, const char *title,
|
---|
96 | TH2D *fHist2, TH3D *fHist3, TH3D *fHist3Diff) :
|
---|
97 | fRunType(0), fGroup(0)
|
---|
98 | {
|
---|
99 | fName = name ? name : "MPadSchweizer";
|
---|
100 | fTitle = title ? title : "Task for the padding (Schweizer)";
|
---|
101 |
|
---|
102 | fHSigmaTheta = fHist2;
|
---|
103 | fHSigmaPixTheta = fHist3;
|
---|
104 | fHDiffPixTheta = fHist3Diff;
|
---|
105 |
|
---|
106 | fHSigmaTheta->SetDirectory(NULL);
|
---|
107 | fHSigmaPixTheta->SetDirectory(NULL);
|
---|
108 | fHDiffPixTheta->SetDirectory(NULL);
|
---|
109 |
|
---|
110 | Print();
|
---|
111 | }
|
---|
112 |
|
---|
113 | // --------------------------------------------------------------------------
|
---|
114 | //
|
---|
115 | // Destructor.
|
---|
116 | //
|
---|
117 | MPadSchweizer::~MPadSchweizer()
|
---|
118 | {
|
---|
119 | //nothing yet
|
---|
120 | }
|
---|
121 |
|
---|
122 | // --------------------------------------------------------------------------
|
---|
123 | //
|
---|
124 | // Set the option for the padding
|
---|
125 | //
|
---|
126 | void MPadSchweizer::SetPadFlag(Int_t padflag)
|
---|
127 | {
|
---|
128 | fPadFlag = padflag;
|
---|
129 | *fLog << "MPadSchweizer::SetPadFlag(); choose option " << fPadFlag << endl;
|
---|
130 | }
|
---|
131 |
|
---|
132 | // --------------------------------------------------------------------------
|
---|
133 | //
|
---|
134 | // Set the pointers and prepare the histograms
|
---|
135 | //
|
---|
136 | Bool_t MPadSchweizer::PreProcess(MParList *pList)
|
---|
137 | {
|
---|
138 | fRnd = new TRandom3(0);
|
---|
139 |
|
---|
140 | fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
|
---|
141 | if (!fMcEvt)
|
---|
142 | {
|
---|
143 | *fLog << err << dbginf << "MMcEvt not found... aborting." << endl;
|
---|
144 | return kFALSE;
|
---|
145 | }
|
---|
146 |
|
---|
147 | fPed = (MPedestalCam*)pList->FindObject("MPedestalCam");
|
---|
148 | if (!fPed)
|
---|
149 | {
|
---|
150 | *fLog << err << "MPedestalCam not found... aborting." << endl;
|
---|
151 | return kFALSE;
|
---|
152 | }
|
---|
153 |
|
---|
154 | fCam = (MGeomCam*)pList->FindObject("MGeomCam");
|
---|
155 | if (!fCam)
|
---|
156 | {
|
---|
157 | *fLog << err << "MGeomCam not found (no geometry information available)... aborting." << endl;
|
---|
158 | return kFALSE;
|
---|
159 | }
|
---|
160 |
|
---|
161 | fEvt = (MCerPhotEvt*)pList->FindObject("MCerPhotEvt");
|
---|
162 | if (!fEvt)
|
---|
163 | {
|
---|
164 | *fLog << err << "MCerPhotEvt not found... aborting." << endl;
|
---|
165 | return kFALSE;
|
---|
166 | }
|
---|
167 |
|
---|
168 | fSigmabar = (MSigmabar*)pList->FindCreateObj("MSigmabar");
|
---|
169 | if (!fSigmabar)
|
---|
170 | {
|
---|
171 | *fLog << err << "MSigmabar not found... aborting." << endl;
|
---|
172 | return kFALSE;
|
---|
173 | }
|
---|
174 |
|
---|
175 | // Get Theta Binning
|
---|
176 | MBinning* binstheta = (MBinning*)pList->FindObject("BinningTheta");
|
---|
177 | if (!binstheta)
|
---|
178 | {
|
---|
179 | *fLog << err << "BinningTheta not found... aborting." << endl;
|
---|
180 | return kFALSE;
|
---|
181 | }
|
---|
182 |
|
---|
183 | // Get Sigma Binning
|
---|
184 | MBinning* binssigma = (MBinning*)pList->FindObject("BinningSigmabar");
|
---|
185 | if (!binssigma)
|
---|
186 | {
|
---|
187 | *fLog << err << "BinningSigmabar not found... aborting." << endl;
|
---|
188 | return kFALSE;
|
---|
189 | }
|
---|
190 |
|
---|
191 | // Get binning for (sigma^2-sigmabar^2)
|
---|
192 | MBinning* binsdiff = (MBinning*)pList->FindObject("BinningDiffsigma2");
|
---|
193 | if (!binsdiff)
|
---|
194 | {
|
---|
195 | *fLog << err << "BinningDiffsigma2 not found... aborting." << endl;
|
---|
196 | return kFALSE;
|
---|
197 | }
|
---|
198 |
|
---|
199 | // Get binning for pixel number
|
---|
200 | UInt_t npix = fPed->GetSize();
|
---|
201 | MBinning binspix("BinningPixel");
|
---|
202 | MBinning* binspixel = &binspix;
|
---|
203 | binspixel->SetEdges(npix, -0.5, ((float)npix)-0.5 );
|
---|
204 |
|
---|
205 |
|
---|
206 | //--------------------------------------------------------------------
|
---|
207 | // histograms for checking the padding
|
---|
208 | //
|
---|
209 | // plot pedestal sigmas
|
---|
210 | fHSigmaPedestal = new TH2D("SigPed","Sigma: after vs. before padding",
|
---|
211 | 100, 0.0, 5.0, 100, 0.0, 5.0);
|
---|
212 | fHSigmaPedestal->SetXTitle("orig. Pedestal sigma");
|
---|
213 | fHSigmaPedestal->SetYTitle("padded Pedestal sigma");
|
---|
214 |
|
---|
215 | // plot no.of photons (before vs. after padding)
|
---|
216 | fHPhotons = new TH2D("Photons","Photons: after vs.before padding",
|
---|
217 | 100, -10.0, 90.0, 100, -10, 90);
|
---|
218 | fHPhotons->SetXTitle("no.of photons before padding");
|
---|
219 | fHPhotons->SetYTitle("no.of photons after padding");
|
---|
220 |
|
---|
221 | // plot of added NSB
|
---|
222 | fHNSB = new TH1D("NSB","Distribution of added NSB", 100, -10.0, 10.0);
|
---|
223 | fHNSB->SetXTitle("no.of added NSB photons");
|
---|
224 | fHNSB->SetYTitle("no.of pixels");
|
---|
225 |
|
---|
226 | fHSigbarTheta = new TH2D();
|
---|
227 | fHSigbarTheta->SetNameTitle("fHSigmabar",
|
---|
228 | "2D : Sigmabar, \\Theta (after padding)");
|
---|
229 | MH::SetBinning(fHSigbarTheta, binstheta, binssigma);
|
---|
230 | fHSigbarTheta->SetXTitle("Theta");
|
---|
231 | fHSigbarTheta->SetYTitle("Sigmabar");
|
---|
232 |
|
---|
233 | fHSigPixTh = new TH3D();
|
---|
234 | fHSigPixTh->SetNameTitle("fHSigPixTh","3D: \\Theta, pixel no., Sigma (after padding)");
|
---|
235 | MH::SetBinning(fHSigPixTh, binstheta, binspixel, binssigma);
|
---|
236 | fHSigPixTh->SetXTitle("\\Theta [\\circ]");
|
---|
237 | fHSigPixTh->SetYTitle("pixel number");
|
---|
238 | fHSigPixTh->SetZTitle("Sigma");
|
---|
239 |
|
---|
240 | fHDiffPixTh = new TH3D();
|
---|
241 | fHDiffPixTh->SetNameTitle("fHDiffPixTh","3D: \\Theta, pixel no., Sigma^2-Sigmabar^2 (after padding)");
|
---|
242 | MH::SetBinning(fHDiffPixTh, binstheta, binspixel, binsdiff);
|
---|
243 | fHDiffPixTh->SetXTitle("\\Theta [\\circ]");
|
---|
244 | fHDiffPixTh->SetYTitle("pixel number");
|
---|
245 | fHDiffPixTh->SetZTitle("Sigma^2-Sigmabar^2");
|
---|
246 |
|
---|
247 | //--------------------------------------------------------------------
|
---|
248 |
|
---|
249 | memset(fErrors, 0, sizeof(fErrors));
|
---|
250 |
|
---|
251 | return kTRUE;
|
---|
252 | }
|
---|
253 |
|
---|
254 | // --------------------------------------------------------------------------
|
---|
255 | //
|
---|
256 | // Do the Padding
|
---|
257 | // idealy the events to be padded should have been generated without NSB
|
---|
258 | //
|
---|
259 | Bool_t MPadSchweizer::Process()
|
---|
260 | {
|
---|
261 | //*fLog << "Entry MPadSchweizer::Process();" << endl;
|
---|
262 |
|
---|
263 | Int_t rc;
|
---|
264 |
|
---|
265 | const UInt_t npix = fEvt->GetNumPixels();
|
---|
266 |
|
---|
267 | Double_t SigbarOld;
|
---|
268 |
|
---|
269 |
|
---|
270 | SigbarOld = fSigmabar->Calc(*fCam, *fPed, *fEvt);
|
---|
271 | //*fLog << "before padding : " << endl;
|
---|
272 | //fSigmabar->Print("");
|
---|
273 |
|
---|
274 |
|
---|
275 | //$$$$$$$$$$$$$$$$$$$$$$$$$$
|
---|
276 | // to simulate the situation that before the padding the NSB and
|
---|
277 | // electronic noise are zero : set Sigma = 0 for all pixels
|
---|
278 | //for (UInt_t i=0; i<npix; i++)
|
---|
279 | //{
|
---|
280 | // MCerPhotPix &pix = fEvt->operator[](i);
|
---|
281 | // Int_t j = pix.GetPixId();
|
---|
282 |
|
---|
283 | // MPedestalPix &ppix = fPed->operator[](j);
|
---|
284 | // ppix.SetMeanRms(0.0);
|
---|
285 | //}
|
---|
286 | //$$$$$$$$$$$$$$$$$$$$$$$$$$
|
---|
287 |
|
---|
288 | //-------------------------------------------
|
---|
289 | // Calculate average sigma of the event
|
---|
290 | //
|
---|
291 | SigbarOld = fSigmabar->Calc(*fCam, *fPed, *fEvt);
|
---|
292 | //fSigmabar->Print("");
|
---|
293 |
|
---|
294 | if (SigbarOld > 0.0)
|
---|
295 | {
|
---|
296 | //*fLog << "MPadSchweizer::Process(); Sigmabar of event to be padded is > 0 : "
|
---|
297 | // << SigbarOld << ". Stop event loop " << endl;
|
---|
298 | // input data should have Sigmabar = 0; stop event loop
|
---|
299 |
|
---|
300 | rc = 1;
|
---|
301 | fErrors[rc]++;
|
---|
302 | return kCONTINUE;
|
---|
303 | }
|
---|
304 |
|
---|
305 | Double_t Theta = kRad2Deg*fMcEvt->GetTelescopeTheta();
|
---|
306 | // *fLog << "Theta = " << Theta << endl;
|
---|
307 |
|
---|
308 |
|
---|
309 | //-------------------------------------------
|
---|
310 | // for the current Theta,
|
---|
311 | // generate a Sigmabar according to the histogram fHSigmaTheta
|
---|
312 | //
|
---|
313 | Double_t Sigmabar;
|
---|
314 | Int_t binNumber = fHSigmaTheta->GetXaxis()->FindBin(Theta);
|
---|
315 |
|
---|
316 | if ( binNumber < 1 || binNumber > fHSigmaTheta->GetNbinsX() )
|
---|
317 | {
|
---|
318 | *fLog << "MPadSchweizer::Process(); binNumber out of range : Theta, binNumber = "
|
---|
319 | << Theta << ", " << binNumber << "; Skip event " << endl;
|
---|
320 | // event cannot be padded; skip event
|
---|
321 |
|
---|
322 | rc = 2;
|
---|
323 | fErrors[rc]++;
|
---|
324 | return kCONTINUE;
|
---|
325 | }
|
---|
326 | else
|
---|
327 | {
|
---|
328 | TH1D* fHSigma =
|
---|
329 | fHSigmaTheta->ProjectionY("", binNumber, binNumber, "");
|
---|
330 | if ( fHSigma->GetEntries() == 0.0 )
|
---|
331 | {
|
---|
332 | *fLog << "MPadSchweizer::Process(); projection for Theta bin "
|
---|
333 | << binNumber << " has no entries; Skip event " << endl;
|
---|
334 | // event cannot be padded; skip event
|
---|
335 | delete fHSigma;
|
---|
336 |
|
---|
337 | rc = 3;
|
---|
338 | fErrors[rc]++;
|
---|
339 | return kCONTINUE;
|
---|
340 | }
|
---|
341 | else
|
---|
342 | {
|
---|
343 | Sigmabar = fHSigma->GetRandom();
|
---|
344 |
|
---|
345 | //*fLog << "Theta, bin number = " << Theta << ", " << binNumber
|
---|
346 | // << ", Sigmabar = " << Sigmabar << endl;
|
---|
347 | }
|
---|
348 | delete fHSigma;
|
---|
349 | }
|
---|
350 |
|
---|
351 |
|
---|
352 | //-------------------------------------------
|
---|
353 |
|
---|
354 | //*fLog << "MPadSchweizer::Process(); SigbarOld, Sigmabar = "
|
---|
355 | // << SigbarOld << ", "<< Sigmabar << endl;
|
---|
356 |
|
---|
357 | // Skip event if target Sigmabar is <= SigbarOld
|
---|
358 | if (Sigmabar <= SigbarOld)
|
---|
359 | {
|
---|
360 | *fLog << "MPadSchweizer::Process(); target Sigmabar is less than SigbarOld : "
|
---|
361 | << Sigmabar << ", " << SigbarOld << ", Skip event" << endl;
|
---|
362 |
|
---|
363 | rc = 4;
|
---|
364 | fErrors[rc]++;
|
---|
365 | return kCONTINUE;
|
---|
366 | }
|
---|
367 |
|
---|
368 |
|
---|
369 | //-------------------------------------------
|
---|
370 | //
|
---|
371 | // Calculate average number of NSB photons to be added (lambdabar)
|
---|
372 | // from the value of Sigmabar,
|
---|
373 | // - making assumptions about the average electronic noise (elNoise2) and
|
---|
374 | // - using a fixed value (F2excess) for the excess noise factor
|
---|
375 |
|
---|
376 | Double_t elNoise2; // [photons]
|
---|
377 | Double_t F2excess = 1.3;
|
---|
378 | Double_t lambdabar; // [photons]
|
---|
379 |
|
---|
380 |
|
---|
381 | Int_t binTheta = fHDiffPixTheta->GetXaxis()->FindBin(Theta);
|
---|
382 | if (binTheta != binNumber)
|
---|
383 | {
|
---|
384 | cout << "The binnings of the 2 histograms are not identical; aborting"
|
---|
385 | << endl;
|
---|
386 | return kERROR;
|
---|
387 | }
|
---|
388 |
|
---|
389 | // Get RMS of (Sigma^2-Sigmabar^2) in this Theta bin.
|
---|
390 | // The average electronic noise (to be added) has to be well above this RMS,
|
---|
391 | // otherwise the electronic noise of an individual pixel (elNoise2Pix)
|
---|
392 | // may become negative
|
---|
393 | TH1D* fHNoise = fHDiffPixTheta->ProjectionZ("", binTheta, binTheta,
|
---|
394 | 0, 9999, "");
|
---|
395 | Double_t RMS = fHNoise->GetRMS(1);
|
---|
396 | delete fHNoise;
|
---|
397 | elNoise2 = TMath::Min(RMS, Sigmabar*Sigmabar - SigbarOld*SigbarOld);
|
---|
398 | //*fLog << "elNoise2 = " << elNoise2 << endl;
|
---|
399 |
|
---|
400 | lambdabar = (Sigmabar*Sigmabar - SigbarOld*SigbarOld - elNoise2)
|
---|
401 | / F2excess;
|
---|
402 | // This value of lambdabar is the same for all pixels;
|
---|
403 | // note that lambdabar is normalized to the area of pixel 0
|
---|
404 |
|
---|
405 |
|
---|
406 | //---------- start loop over pixels ---------------------------------
|
---|
407 | // do the padding for each pixel
|
---|
408 | //
|
---|
409 | // pad only pixels - which are used (before image cleaning)
|
---|
410 | //
|
---|
411 | Double_t Sig = 0.0;
|
---|
412 | Double_t Sigma2 = 0.0;
|
---|
413 | Double_t Diff = 0.0;
|
---|
414 | Double_t addSig2 = 0.0;
|
---|
415 | Double_t elNoise2Pix = 0.0;
|
---|
416 |
|
---|
417 |
|
---|
418 | for (UInt_t i=0; i<npix; i++)
|
---|
419 | {
|
---|
420 | MCerPhotPix &pix = fEvt->operator[](i);
|
---|
421 | if ( !pix.IsPixelUsed() )
|
---|
422 | continue;
|
---|
423 |
|
---|
424 | //if ( pix.GetNumPhotons() == 0.0)
|
---|
425 | //{
|
---|
426 | // *fLog << "MPadSchweizer::Process(); no.of photons is 0 for used pixel"
|
---|
427 | // << endl;
|
---|
428 | // continue;
|
---|
429 | //}
|
---|
430 |
|
---|
431 | Int_t j = pix.GetPixId();
|
---|
432 | Double_t Area = fCam->GetPixRatio(j);
|
---|
433 |
|
---|
434 | MPedestalPix &ppix = fPed->operator[](j);
|
---|
435 | Double_t oldsigma = ppix.GetMeanRms();
|
---|
436 |
|
---|
437 | //---------------------------------
|
---|
438 | // throw the Sigma for this pixel
|
---|
439 | //
|
---|
440 | Int_t binPixel = fHDiffPixTheta->GetYaxis()->FindBin( (Double_t)j );
|
---|
441 |
|
---|
442 | Int_t count;
|
---|
443 | Int_t OK;
|
---|
444 | TH1D* fHDiff;
|
---|
445 | TH1D* fHSig;
|
---|
446 |
|
---|
447 | switch (fPadFlag)
|
---|
448 | {
|
---|
449 | case 1 :
|
---|
450 | // throw the Sigma for this pixel from the distribution fHDiffPixTheta
|
---|
451 | fHDiff =
|
---|
452 | fHDiffPixTheta->ProjectionZ("", binTheta, binTheta,
|
---|
453 | binPixel, binPixel, "");
|
---|
454 | if ( fHDiff->GetEntries() == 0.0 )
|
---|
455 | {
|
---|
456 | *fLog << "MPadSchweizer::Process(); projection for Theta bin "
|
---|
457 | << binTheta << " and pixel bin " << binPixel
|
---|
458 | << " has no entries; aborting " << endl;
|
---|
459 |
|
---|
460 | rc = 5;
|
---|
461 | fErrors[rc]++;
|
---|
462 | return kCONTINUE;
|
---|
463 | }
|
---|
464 |
|
---|
465 | count = 0;
|
---|
466 | OK = 0;
|
---|
467 | for (Int_t m=0; m<20; m++)
|
---|
468 | {
|
---|
469 | count += 1;
|
---|
470 | Diff = fHDiff->GetRandom();
|
---|
471 | // the following condition ensures that elNoise2Pix > 0.0
|
---|
472 | if ( (Diff+Sigmabar*Sigmabar-oldsigma*oldsigma/Area-
|
---|
473 | lambdabar*F2excess) > 0.0 )
|
---|
474 | {
|
---|
475 | OK = 1;
|
---|
476 | break;
|
---|
477 | }
|
---|
478 | }
|
---|
479 | if (OK == 0)
|
---|
480 | {
|
---|
481 | *fLog << "Theta, j, count, Sigmabar, Diff = " << Theta << ", "
|
---|
482 | << j << ", " << count << ", " << Sigmabar << ", "
|
---|
483 | << Diff << endl;
|
---|
484 | Diff = lambdabar*F2excess + oldsigma*oldsigma/Area
|
---|
485 | - Sigmabar*Sigmabar;
|
---|
486 | }
|
---|
487 | delete fHDiff;
|
---|
488 | Sigma2 = Diff + Sigmabar*Sigmabar;
|
---|
489 | break;
|
---|
490 |
|
---|
491 | case 2 :
|
---|
492 | // throw the Sigma for this pixel from the distribution fHSigmaPixTheta
|
---|
493 | fHSig =
|
---|
494 | fHSigmaPixTheta->ProjectionZ("", binTheta, binTheta,
|
---|
495 | binPixel, binPixel, "");
|
---|
496 | if ( fHSig->GetEntries() == 0.0 )
|
---|
497 | {
|
---|
498 | *fLog << "MPadSchweizer::Process(); projection for Theta bin "
|
---|
499 | << binTheta << " and pixel bin " << binPixel
|
---|
500 | << " has no entries; aborting " << endl;
|
---|
501 |
|
---|
502 | rc = 6;
|
---|
503 | fErrors[rc]++;
|
---|
504 | return kCONTINUE;
|
---|
505 | }
|
---|
506 |
|
---|
507 | count = 0;
|
---|
508 | OK = 0;
|
---|
509 | for (Int_t m=0; m<20; m++)
|
---|
510 | {
|
---|
511 | count += 1;
|
---|
512 | Sig = fHSig->GetRandom();
|
---|
513 | Sigma2 = Sig*Sig/Area;
|
---|
514 | // the following condition ensures that elNoise2Pix > 0.0
|
---|
515 | if ( (Sigma2-oldsigma*oldsigma/Area-lambdabar*F2excess) > 0.0 )
|
---|
516 | {
|
---|
517 | OK = 1;
|
---|
518 | break;
|
---|
519 | }
|
---|
520 | }
|
---|
521 | if (OK == 0)
|
---|
522 | {
|
---|
523 | *fLog << "Theta, j, count, Sigmabar, Sig = " << Theta << ", "
|
---|
524 | << j << ", " << count << ", " << Sigmabar << ", "
|
---|
525 | << Sig << endl;
|
---|
526 | Sigma2 = lambdabar*F2excess + oldsigma*oldsigma/Area;
|
---|
527 | }
|
---|
528 | delete fHSig;
|
---|
529 | break;
|
---|
530 | }
|
---|
531 |
|
---|
532 | //---------------------------------
|
---|
533 | // get the additional sigma^2 for this pixel (due to the padding)
|
---|
534 | addSig2 = Sigma2*Area - oldsigma*oldsigma;
|
---|
535 |
|
---|
536 |
|
---|
537 | //---------------------------------
|
---|
538 | // get the additional electronic noise for this pixel
|
---|
539 | elNoise2Pix = addSig2 - lambdabar*F2excess*Area;
|
---|
540 |
|
---|
541 |
|
---|
542 | //---------------------------------
|
---|
543 | // throw actual number of additional NSB photons (NSB)
|
---|
544 | // and its RMS (sigmaNSB)
|
---|
545 | Double_t NSB0 = fRnd->Poisson(lambdabar*Area);
|
---|
546 | Double_t arg = NSB0*(F2excess-1.0) + elNoise2Pix;
|
---|
547 | Double_t sigmaNSB0;
|
---|
548 |
|
---|
549 | if (arg >= 0.0)
|
---|
550 | {
|
---|
551 | sigmaNSB0 = sqrt( arg );
|
---|
552 | }
|
---|
553 | else
|
---|
554 | {
|
---|
555 | *fLog << "MPadSchweizer::Process(); argument of sqrt < 0.0 : "
|
---|
556 | << arg << endl;
|
---|
557 | sigmaNSB0 = 0.0000001;
|
---|
558 | }
|
---|
559 |
|
---|
560 |
|
---|
561 | //---------------------------------
|
---|
562 | // smear NSB0 according to sigmaNSB0
|
---|
563 | // and subtract lambdabar because of AC coupling
|
---|
564 | Double_t NSB = fRnd->Gaus(NSB0, sigmaNSB0) - lambdabar*Area;
|
---|
565 |
|
---|
566 | //---------------------------------
|
---|
567 |
|
---|
568 | // add additional NSB to the number of photons
|
---|
569 | Double_t oldphotons = pix.GetNumPhotons();
|
---|
570 | Double_t newphotons = oldphotons + NSB;
|
---|
571 | pix.SetNumPhotons( newphotons );
|
---|
572 |
|
---|
573 | fHNSB->Fill( NSB/sqrt(Area) );
|
---|
574 | fHPhotons->Fill( oldphotons/sqrt(Area), newphotons/sqrt(Area) );
|
---|
575 |
|
---|
576 |
|
---|
577 | // error: add sigma of padded noise quadratically
|
---|
578 | Double_t olderror = pix.GetErrorPhot();
|
---|
579 | Double_t newerror = sqrt( olderror*olderror + addSig2 );
|
---|
580 | pix.SetErrorPhot( newerror );
|
---|
581 |
|
---|
582 |
|
---|
583 | Double_t newsigma = sqrt( oldsigma*oldsigma + addSig2 );
|
---|
584 | ppix.SetMeanRms( newsigma );
|
---|
585 |
|
---|
586 | fHSigmaPedestal->Fill( oldsigma, newsigma );
|
---|
587 | fHSigPixTh-> Fill( Theta, (Double_t) j, newsigma );
|
---|
588 | }
|
---|
589 | //---------- end of loop over pixels ---------------------------------
|
---|
590 |
|
---|
591 | // Calculate Sigmabar again and crosscheck
|
---|
592 |
|
---|
593 | Double_t SigbarNew = fSigmabar->Calc(*fCam, *fPed, *fEvt);
|
---|
594 | //*fLog << "after padding : " << endl;
|
---|
595 | //fSigmabar->Print("");
|
---|
596 |
|
---|
597 | fHSigbarTheta->Fill( Theta, SigbarNew );
|
---|
598 |
|
---|
599 | // this loop is only for filling the histogram fHDiffPixTh
|
---|
600 | for (UInt_t i=0; i<npix; i++)
|
---|
601 | {
|
---|
602 | MCerPhotPix &pix = fEvt->operator[](i);
|
---|
603 | if ( !pix.IsPixelUsed() )
|
---|
604 | continue;
|
---|
605 |
|
---|
606 | //if ( pix.GetNumPhotons() == 0.0)
|
---|
607 | //{
|
---|
608 | // *fLog << "MPadSchweizer::Process(); no.of photons is 0 for used pixel"
|
---|
609 | // << endl;
|
---|
610 | // continue;
|
---|
611 | //}
|
---|
612 |
|
---|
613 | Int_t j = pix.GetPixId();
|
---|
614 | Double_t Area = fCam->GetPixRatio(j);
|
---|
615 |
|
---|
616 | MPedestalPix &ppix = fPed->operator[](j);
|
---|
617 | Double_t newsigma = ppix.GetMeanRms();
|
---|
618 |
|
---|
619 | fHDiffPixTh->Fill( Theta, (Double_t) j,
|
---|
620 | newsigma*newsigma/Area-SigbarNew*SigbarNew);
|
---|
621 | }
|
---|
622 |
|
---|
623 |
|
---|
624 | //*fLog << "Exit MPadSchweizer::Process();" << endl;
|
---|
625 |
|
---|
626 | rc = 0;
|
---|
627 | fErrors[rc]++;
|
---|
628 |
|
---|
629 | return kTRUE;
|
---|
630 |
|
---|
631 | }
|
---|
632 |
|
---|
633 | // --------------------------------------------------------------------------
|
---|
634 | //
|
---|
635 | //
|
---|
636 | Bool_t MPadSchweizer::PostProcess()
|
---|
637 | {
|
---|
638 | if (GetNumExecutions() != 0)
|
---|
639 | {
|
---|
640 |
|
---|
641 | *fLog << inf << endl;
|
---|
642 | *fLog << GetDescriptor() << " execution statistics:" << endl;
|
---|
643 | *fLog << dec << setfill(' ');
|
---|
644 | *fLog << " " << setw(7) << fErrors[1] << " (" << setw(3)
|
---|
645 | << (int)(fErrors[1]*100/GetNumExecutions())
|
---|
646 | << "%) Evts skipped due to: Sigmabar_old > 0" << endl;
|
---|
647 |
|
---|
648 | *fLog << " " << setw(7) << fErrors[2] << " (" << setw(3)
|
---|
649 | << (int)(fErrors[2]*100/GetNumExecutions())
|
---|
650 | << "%) Evts skipped due to: Zenith angle out of range" << endl;
|
---|
651 |
|
---|
652 | *fLog << " " << setw(7) << fErrors[3] << " (" << setw(3)
|
---|
653 | << (int)(fErrors[3]*100/GetNumExecutions())
|
---|
654 | << "%) Evts skipped due to: No data for generating Sigmabar" << endl;
|
---|
655 |
|
---|
656 | *fLog << " " << setw(7) << fErrors[4] << " (" << setw(3)
|
---|
657 | << (int)(fErrors[4]*100/GetNumExecutions())
|
---|
658 | << "%) Evts skipped due to: Target sigma <= Sigmabar_old" << endl;
|
---|
659 |
|
---|
660 | *fLog << " " << setw(7) << fErrors[5] << " (" << setw(3)
|
---|
661 | << (int)(fErrors[5]*100/GetNumExecutions())
|
---|
662 | << "%) Evts skipped due to: No data for generating Sigma^2-Sigmabar^2" << endl;
|
---|
663 |
|
---|
664 | *fLog << " " << setw(7) << fErrors[6] << " (" << setw(3)
|
---|
665 | << (int)(fErrors[6]*100/GetNumExecutions())
|
---|
666 | << "%) Evts skipped due to: No data for generating Sigma" << endl;
|
---|
667 |
|
---|
668 | *fLog << " " << fErrors[0] << " ("
|
---|
669 | << (int)(fErrors[0]*100/GetNumExecutions())
|
---|
670 | << "%) Evts survived the padding!" << endl;
|
---|
671 | *fLog << endl;
|
---|
672 |
|
---|
673 | }
|
---|
674 |
|
---|
675 | //---------------------------------------------------------------
|
---|
676 | TCanvas &c = *(MH::MakeDefCanvas("PadSchweizer", "", 900, 1200));
|
---|
677 | c.Divide(3, 4);
|
---|
678 | gROOT->SetSelectedPad(NULL);
|
---|
679 |
|
---|
680 |
|
---|
681 | c.cd(1);
|
---|
682 | fHSigmaTheta->SetDirectory(NULL);
|
---|
683 | fHSigmaTheta->SetTitle("2D : Sigmabar, \\Theta (reference sample)");
|
---|
684 | fHSigmaTheta->DrawCopy();
|
---|
685 | fHSigmaTheta->SetBit(kCanDelete);
|
---|
686 |
|
---|
687 | //c.cd(1);
|
---|
688 | //fHSigmaPixTheta->DrawCopy();
|
---|
689 | //fHSigmaPixTheta->SetBit(kCanDelete);
|
---|
690 |
|
---|
691 | c.cd(4);
|
---|
692 | fHSigbarTheta->SetDirectory(NULL);
|
---|
693 | fHSigbarTheta->DrawCopy();
|
---|
694 | fHSigbarTheta->SetBit(kCanDelete);
|
---|
695 |
|
---|
696 |
|
---|
697 | c.cd(7);
|
---|
698 | fHNSB->SetDirectory(NULL);
|
---|
699 | fHNSB->DrawCopy();
|
---|
700 | fHNSB->SetBit(kCanDelete);
|
---|
701 |
|
---|
702 |
|
---|
703 | //--------------------------------------------------------------------
|
---|
704 | // draw the 3D histogram : Theta, pixel, Sigma^2-Sigmabar^2
|
---|
705 |
|
---|
706 | TH2D *l;
|
---|
707 |
|
---|
708 | c.cd(2);
|
---|
709 | l = (TH2D*) ((TH3*)fHDiffPixTh)->Project3D("zx");
|
---|
710 | l->SetDirectory(NULL);
|
---|
711 | l->SetTitle("Sigma^2-Sigmabar^2 vs. \\Theta (all pixels)");
|
---|
712 | l->SetXTitle("\\Theta [\\circ]");
|
---|
713 | l->SetYTitle("Sigma^2-Sigmabar^2");
|
---|
714 |
|
---|
715 | l->DrawCopy("box");
|
---|
716 | l->SetBit(kCanDelete);;
|
---|
717 |
|
---|
718 | c.cd(5);
|
---|
719 | l = (TH2D*) ((TH3*)fHDiffPixTh)->Project3D("zy");
|
---|
720 | l->SetDirectory(NULL);
|
---|
721 | l->SetTitle("Sigma^2-Sigmabar^2 vs. pixel number (all \\Theta)");
|
---|
722 | l->SetXTitle("pixel");
|
---|
723 | l->SetYTitle("Sigma^2-Sigmabar^2");
|
---|
724 |
|
---|
725 | l->DrawCopy("box");
|
---|
726 | l->SetBit(kCanDelete);;
|
---|
727 |
|
---|
728 | c.cd(8);
|
---|
729 | ((TH2*)fHDiffPixTh)->DrawCopy();
|
---|
730 |
|
---|
731 |
|
---|
732 | //--------------------------------------------------------------------
|
---|
733 | // draw the 3D histogram : Theta, pixel, Sigma
|
---|
734 |
|
---|
735 | TH2D *k;
|
---|
736 |
|
---|
737 | c.cd(3);
|
---|
738 | k = (TH2D*) ((TH3*)fHSigPixTh)->Project3D("zx");
|
---|
739 | k->SetDirectory(NULL);
|
---|
740 | k->SetTitle("Sigma vs. \\Theta (all pixels)");
|
---|
741 | k->SetXTitle("\\Theta [\\circ]");
|
---|
742 | k->SetYTitle("Sigma");
|
---|
743 |
|
---|
744 | k->DrawCopy("box");
|
---|
745 | k->SetBit(kCanDelete);
|
---|
746 |
|
---|
747 | c.cd(6);
|
---|
748 | k = (TH2D*) ((TH3*)fHSigPixTh)->Project3D("zy");
|
---|
749 | k->SetDirectory(NULL);
|
---|
750 | k->SetTitle("Sigma vs. pixel number (all \\Theta)");
|
---|
751 | k->SetXTitle("pixel");
|
---|
752 | k->SetYTitle("Sigma");
|
---|
753 |
|
---|
754 | k->DrawCopy("box");
|
---|
755 | k->SetBit(kCanDelete);;
|
---|
756 |
|
---|
757 | c.cd(9);
|
---|
758 | ((TH2*)fHSigPixTh)->DrawCopy();
|
---|
759 |
|
---|
760 | //--------------------------------------------------------------------
|
---|
761 |
|
---|
762 | c.cd(10);
|
---|
763 | fHSigmaPedestal->SetDirectory(NULL);
|
---|
764 | fHSigmaPedestal->DrawCopy();
|
---|
765 | fHSigmaPedestal->SetBit(kCanDelete);
|
---|
766 |
|
---|
767 | c.cd(11);
|
---|
768 | fHPhotons->SetDirectory(NULL);
|
---|
769 | fHPhotons->DrawCopy();
|
---|
770 | fHPhotons->SetBit(kCanDelete);
|
---|
771 |
|
---|
772 | //--------------------------------------------------------------------
|
---|
773 |
|
---|
774 | return kTRUE;
|
---|
775 | }
|
---|
776 |
|
---|
777 | // --------------------------------------------------------------------------
|
---|
778 |
|
---|