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