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