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