| 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 | delete fHSigma;
|
|---|
| 310 | return kCONTINUE;
|
|---|
| 311 | }
|
|---|
| 312 | else
|
|---|
| 313 | {
|
|---|
| 314 | Sigmabar = fHSigma->GetRandom();
|
|---|
| 315 |
|
|---|
| 316 | //*fLog << "Theta, bin number = " << Theta << ", " << binNumber
|
|---|
| 317 | // << ", Sigmabar = " << Sigmabar << endl;
|
|---|
| 318 | }
|
|---|
| 319 | delete fHSigma;
|
|---|
| 320 | }
|
|---|
| 321 |
|
|---|
| 322 |
|
|---|
| 323 | //-------------------------------------------
|
|---|
| 324 |
|
|---|
| 325 | //*fLog << "MPadSchweizer::Process(); SigbarOld, Sigmabar = "
|
|---|
| 326 | // << SigbarOld << ", "<< Sigmabar << endl;
|
|---|
| 327 |
|
|---|
| 328 | // Skip event if target Sigmabar is <= SigbarOld
|
|---|
| 329 | if (Sigmabar <= SigbarOld)
|
|---|
| 330 | {
|
|---|
| 331 | *fLog << "MPadSchweizer::Process(); target Sigmabar is less than SigbarOld : "
|
|---|
| 332 | << Sigmabar << ", " << SigbarOld << ", Skip event" << endl;
|
|---|
| 333 | return kCONTINUE;
|
|---|
| 334 | }
|
|---|
| 335 |
|
|---|
| 336 |
|
|---|
| 337 | //-------------------------------------------
|
|---|
| 338 | //
|
|---|
| 339 | // Calculate average number of NSB photons to be added (lambdabar)
|
|---|
| 340 | // from the value of Sigmabar,
|
|---|
| 341 | // - making assumptions about the average electronic noise (elNoise2) and
|
|---|
| 342 | // - using a fixed value (F2excess) for the excess noise factor
|
|---|
| 343 |
|
|---|
| 344 | Double_t elNoise2; // [photons]
|
|---|
| 345 | Double_t F2excess = 1.3;
|
|---|
| 346 | Double_t lambdabar; // [photons]
|
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 | Int_t binTheta = fHDiffPixTheta->GetXaxis()->FindBin(Theta);
|
|---|
| 350 | if (binTheta != binNumber)
|
|---|
| 351 | {
|
|---|
| 352 | cout << "The binnings of the 2 histograms are not identical; aborting"
|
|---|
| 353 | << endl;
|
|---|
| 354 | return kERROR;
|
|---|
| 355 | }
|
|---|
| 356 |
|
|---|
| 357 | // Get RMS of (Sigma^2-Sigmabar^2) in this Theta bin.
|
|---|
| 358 | // The average electronic noise (to be added) has to be well above this RMS,
|
|---|
| 359 | // otherwise the electronic noise of an individual pixel (elNoise2Pix)
|
|---|
| 360 | // may become negative
|
|---|
| 361 | TH1D* fHNoise = fHDiffPixTheta->ProjectionZ("", binTheta, binTheta,
|
|---|
| 362 | 0, 9999, "");
|
|---|
| 363 | Double_t RMS = fHNoise->GetRMS(1);
|
|---|
| 364 | delete fHNoise;
|
|---|
| 365 | elNoise2 = TMath::Min(RMS, Sigmabar*Sigmabar - SigbarOld*SigbarOld);
|
|---|
| 366 | //*fLog << "elNoise2 = " << elNoise2 << endl;
|
|---|
| 367 |
|
|---|
| 368 | lambdabar = (Sigmabar*Sigmabar - SigbarOld*SigbarOld - elNoise2)
|
|---|
| 369 | / F2excess;
|
|---|
| 370 | // This value of lambdabar is the same for all pixels;
|
|---|
| 371 | // note that lambdabar is normalized to the area of pixel 0
|
|---|
| 372 |
|
|---|
| 373 |
|
|---|
| 374 | //---------- start loop over pixels ---------------------------------
|
|---|
| 375 | // do the padding for each pixel
|
|---|
| 376 | //
|
|---|
| 377 | // pad only pixels - which are used (before image cleaning)
|
|---|
| 378 | // - and for which the no.of photons is != 0.0
|
|---|
| 379 | //
|
|---|
| 380 | Double_t Sig = 0.0;
|
|---|
| 381 | Double_t Sigma2 = 0.0;
|
|---|
| 382 | Double_t Diff = 0.0;
|
|---|
| 383 | Double_t addSig2 = 0.0;
|
|---|
| 384 | Double_t elNoise2Pix = 0.0;
|
|---|
| 385 |
|
|---|
| 386 |
|
|---|
| 387 | for (UInt_t i=0; i<npix; i++)
|
|---|
| 388 | {
|
|---|
| 389 | MCerPhotPix &pix = fEvt->operator[](i);
|
|---|
| 390 | if ( !pix.IsPixelUsed() )
|
|---|
| 391 | continue;
|
|---|
| 392 |
|
|---|
| 393 | if ( pix.GetNumPhotons() == 0.0)
|
|---|
| 394 | {
|
|---|
| 395 | *fLog << "MPadSchweizer::Process(); no.of photons is 0 for used pixel"
|
|---|
| 396 | << endl;
|
|---|
| 397 | continue;
|
|---|
| 398 | }
|
|---|
| 399 |
|
|---|
| 400 | Int_t j = pix.GetPixId();
|
|---|
| 401 | Double_t Area = fCam->GetPixRatio(j);
|
|---|
| 402 |
|
|---|
| 403 | MPedestalPix &ppix = fPed->operator[](j);
|
|---|
| 404 | Double_t oldsigma = ppix.GetMeanRms();
|
|---|
| 405 |
|
|---|
| 406 | //---------------------------------
|
|---|
| 407 | // throw the Sigma for this pixel
|
|---|
| 408 | //
|
|---|
| 409 | Int_t binPixel = fHDiffPixTheta->GetYaxis()->FindBin( (Double_t)j );
|
|---|
| 410 |
|
|---|
| 411 | Int_t count;
|
|---|
| 412 | Int_t OK;
|
|---|
| 413 | TH1D* fHDiff;
|
|---|
| 414 | TH1D* fHSig;
|
|---|
| 415 |
|
|---|
| 416 | switch (fPadFlag)
|
|---|
| 417 | {
|
|---|
| 418 | case 1 :
|
|---|
| 419 | // throw the Sigma for this pixel from the distribution fHDiffPixTheta
|
|---|
| 420 | fHDiff =
|
|---|
| 421 | fHDiffPixTheta->ProjectionZ("", binTheta, binTheta,
|
|---|
| 422 | binPixel, binPixel, "");
|
|---|
| 423 | if ( fHDiff->GetEntries() == 0.0 )
|
|---|
| 424 | {
|
|---|
| 425 | *fLog << "MPadSchweizer::Process(); projection for Theta bin "
|
|---|
| 426 | << binTheta << " and pixel bin " << binPixel
|
|---|
| 427 | << " has no entries; aborting " << endl;
|
|---|
| 428 | return kERROR;
|
|---|
| 429 | }
|
|---|
| 430 |
|
|---|
| 431 | count = 0;
|
|---|
| 432 | OK = 0;
|
|---|
| 433 | for (Int_t m=0; m<20; m++)
|
|---|
| 434 | {
|
|---|
| 435 | count += 1;
|
|---|
| 436 | Diff = fHDiff->GetRandom();
|
|---|
| 437 | // the following condition ensures that elNoise2Pix > 0.0
|
|---|
| 438 | if ( (Diff+Sigmabar*Sigmabar-oldsigma*oldsigma/Area-
|
|---|
| 439 | lambdabar*F2excess) > 0.0 )
|
|---|
| 440 | {
|
|---|
| 441 | OK = 1;
|
|---|
| 442 | break;
|
|---|
| 443 | }
|
|---|
| 444 | }
|
|---|
| 445 | if (OK == 0)
|
|---|
| 446 | {
|
|---|
| 447 | *fLog << "Theta, j, count, Sigmabar, Diff = " << Theta << ", "
|
|---|
| 448 | << j << ", " << count << ", " << Sigmabar << ", "
|
|---|
| 449 | << Diff << endl;
|
|---|
| 450 | Diff = lambdabar*F2excess + oldsigma*oldsigma/Area
|
|---|
| 451 | - Sigmabar*Sigmabar;
|
|---|
| 452 | }
|
|---|
| 453 | delete fHDiff;
|
|---|
| 454 | Sigma2 = Diff + Sigmabar*Sigmabar;
|
|---|
| 455 | break;
|
|---|
| 456 |
|
|---|
| 457 | case 2 :
|
|---|
| 458 | // throw the Sigma for this pixel from the distribution fHSigmaPixTheta
|
|---|
| 459 | fHSig =
|
|---|
| 460 | fHSigmaPixTheta->ProjectionZ("", binTheta, binTheta,
|
|---|
| 461 | binPixel, binPixel, "");
|
|---|
| 462 | if ( fHSig->GetEntries() == 0.0 )
|
|---|
| 463 | {
|
|---|
| 464 | *fLog << "MPadSchweizer::Process(); projection for Theta bin "
|
|---|
| 465 | << binTheta << " and pixel bin " << binPixel
|
|---|
| 466 | << " has no entries; aborting " << endl;
|
|---|
| 467 | return kERROR;
|
|---|
| 468 | }
|
|---|
| 469 |
|
|---|
| 470 | count = 0;
|
|---|
| 471 | OK = 0;
|
|---|
| 472 | for (Int_t m=0; m<20; m++)
|
|---|
| 473 | {
|
|---|
| 474 | count += 1;
|
|---|
| 475 | Sig = fHSig->GetRandom();
|
|---|
| 476 | Sigma2 = Sig*Sig/Area;
|
|---|
| 477 | // the following condition ensures that elNoise2Pix > 0.0
|
|---|
| 478 | if ( (Sigma2-oldsigma*oldsigma/Area-lambdabar*F2excess) > 0.0 )
|
|---|
| 479 | {
|
|---|
| 480 | OK = 1;
|
|---|
| 481 | break;
|
|---|
| 482 | }
|
|---|
| 483 | }
|
|---|
| 484 | if (OK == 0)
|
|---|
| 485 | {
|
|---|
| 486 | *fLog << "Theta, j, count, Sigmabar, Sig = " << Theta << ", "
|
|---|
| 487 | << j << ", " << count << ", " << Sigmabar << ", "
|
|---|
| 488 | << Sig << endl;
|
|---|
| 489 | Sigma2 = lambdabar*F2excess + oldsigma*oldsigma/Area;
|
|---|
| 490 | }
|
|---|
| 491 | delete fHSig;
|
|---|
| 492 | break;
|
|---|
| 493 | }
|
|---|
| 494 |
|
|---|
| 495 | //---------------------------------
|
|---|
| 496 | // get the additional sigma^2 for this pixel (due to the padding)
|
|---|
| 497 | addSig2 = Sigma2*Area - oldsigma*oldsigma;
|
|---|
| 498 |
|
|---|
| 499 |
|
|---|
| 500 | //---------------------------------
|
|---|
| 501 | // get the additional electronic noise for this pixel
|
|---|
| 502 | elNoise2Pix = addSig2 - lambdabar*F2excess*Area;
|
|---|
| 503 |
|
|---|
| 504 |
|
|---|
| 505 | //---------------------------------
|
|---|
| 506 | // throw actual number of additional NSB photons (NSB)
|
|---|
| 507 | // and its RMS (sigmaNSB)
|
|---|
| 508 | Double_t NSB0 = fRnd->Poisson(lambdabar*Area);
|
|---|
| 509 | Double_t arg = NSB0*(F2excess-1.0) + elNoise2Pix;
|
|---|
| 510 | Double_t sigmaNSB0;
|
|---|
| 511 |
|
|---|
| 512 | if (arg >= 0.0)
|
|---|
| 513 | {
|
|---|
| 514 | sigmaNSB0 = sqrt( arg );
|
|---|
| 515 | }
|
|---|
| 516 | else
|
|---|
| 517 | {
|
|---|
| 518 | *fLog << "MPadSchweizer::Process(); argument of sqrt < 0.0 : "
|
|---|
| 519 | << arg << endl;
|
|---|
| 520 | sigmaNSB0 = 0.0000001;
|
|---|
| 521 | }
|
|---|
| 522 |
|
|---|
| 523 |
|
|---|
| 524 | //---------------------------------
|
|---|
| 525 | // smear NSB0 according to sigmaNSB0
|
|---|
| 526 | // and subtract lambdabar because of AC coupling
|
|---|
| 527 | Double_t NSB = fRnd->Gaus(NSB0, sigmaNSB0) - lambdabar*Area;
|
|---|
| 528 |
|
|---|
| 529 | //---------------------------------
|
|---|
| 530 |
|
|---|
| 531 | // add additional NSB to the number of photons
|
|---|
| 532 | Double_t oldphotons = pix.GetNumPhotons();
|
|---|
| 533 | Double_t newphotons = oldphotons + NSB;
|
|---|
| 534 | pix.SetNumPhotons( newphotons );
|
|---|
| 535 |
|
|---|
| 536 | fHNSB->Fill( NSB/sqrt(Area) );
|
|---|
| 537 | fHPhotons->Fill( newphotons/sqrt(Area), oldphotons/sqrt(Area) );
|
|---|
| 538 |
|
|---|
| 539 |
|
|---|
| 540 | // error: add sigma of padded noise quadratically
|
|---|
| 541 | Double_t olderror = pix.GetErrorPhot();
|
|---|
| 542 | Double_t newerror = sqrt( olderror*olderror + addSig2 );
|
|---|
| 543 | pix.SetErrorPhot( newerror );
|
|---|
| 544 |
|
|---|
| 545 |
|
|---|
| 546 | Double_t newsigma = sqrt( oldsigma*oldsigma + addSig2 );
|
|---|
| 547 | ppix.SetMeanRms( newsigma );
|
|---|
| 548 |
|
|---|
| 549 | fHSigmaPedestal->Fill( oldsigma, newsigma );
|
|---|
| 550 | fHSigPixTh-> Fill( Theta, (Double_t) j, newsigma );
|
|---|
| 551 | }
|
|---|
| 552 | //---------- end of loop over pixels ---------------------------------
|
|---|
| 553 |
|
|---|
| 554 | // Calculate Sigmabar again and crosscheck
|
|---|
| 555 | Double_t SigbarNew = fSigmabar->Calc(*fCam, *fPed, *fEvt);
|
|---|
| 556 | //fSigmabar->Print("");
|
|---|
| 557 |
|
|---|
| 558 | fHSigbarTheta->Fill( Theta, SigbarNew );
|
|---|
| 559 |
|
|---|
| 560 | // this loop is only for filling the histogram fHDiffPixTh
|
|---|
| 561 | for (UInt_t i=0; i<npix; i++)
|
|---|
| 562 | {
|
|---|
| 563 | MCerPhotPix &pix = fEvt->operator[](i);
|
|---|
| 564 | if ( !pix.IsPixelUsed() )
|
|---|
| 565 | continue;
|
|---|
| 566 |
|
|---|
| 567 | if ( pix.GetNumPhotons() == 0.0)
|
|---|
| 568 | {
|
|---|
| 569 | *fLog << "MPadSchweizer::Process(); no.of photons is 0 for used pixel"
|
|---|
| 570 | << endl;
|
|---|
| 571 | continue;
|
|---|
| 572 | }
|
|---|
| 573 |
|
|---|
| 574 | Int_t j = pix.GetPixId();
|
|---|
| 575 | Double_t Area = fCam->GetPixRatio(j);
|
|---|
| 576 |
|
|---|
| 577 | MPedestalPix &ppix = fPed->operator[](j);
|
|---|
| 578 | Double_t newsigma = ppix.GetMeanRms();
|
|---|
| 579 |
|
|---|
| 580 | fHDiffPixTh->Fill( Theta, (Double_t) j,
|
|---|
| 581 | newsigma*newsigma/Area-SigbarNew*SigbarNew);
|
|---|
| 582 | }
|
|---|
| 583 |
|
|---|
| 584 |
|
|---|
| 585 | //*fLog << "Exit MPadSchweizer::Process();" << endl;
|
|---|
| 586 |
|
|---|
| 587 | return kTRUE;
|
|---|
| 588 |
|
|---|
| 589 | }
|
|---|
| 590 |
|
|---|
| 591 | // --------------------------------------------------------------------------
|
|---|
| 592 | //
|
|---|
| 593 | //
|
|---|
| 594 | Bool_t MPadSchweizer::PostProcess()
|
|---|
| 595 | {
|
|---|
| 596 | TCanvas &c = *(MH::MakeDefCanvas("PadSchweizer", "", 900, 1200));
|
|---|
| 597 | c.Divide(3, 4);
|
|---|
| 598 | gROOT->SetSelectedPad(NULL);
|
|---|
| 599 |
|
|---|
| 600 |
|
|---|
| 601 | c.cd(1);
|
|---|
| 602 | fHSigmaTheta->SetTitle("2D : Sigmabar, \\Theta (reference sample)");
|
|---|
| 603 | fHSigmaTheta->DrawClone();
|
|---|
| 604 | fHSigmaTheta->SetBit(kCanDelete);
|
|---|
| 605 |
|
|---|
| 606 | //c.cd(1);
|
|---|
| 607 | //fHSigmaPixTheta->DrawClone();
|
|---|
| 608 | //fHSigmaPixTheta->SetBit(kCanDelete);
|
|---|
| 609 |
|
|---|
| 610 | c.cd(4);
|
|---|
| 611 | fHSigbarTheta->DrawClone();
|
|---|
| 612 | fHSigbarTheta->SetBit(kCanDelete);
|
|---|
| 613 |
|
|---|
| 614 |
|
|---|
| 615 | c.cd(7);
|
|---|
| 616 | fHNSB->DrawClone();
|
|---|
| 617 | fHNSB->SetBit(kCanDelete);
|
|---|
| 618 |
|
|---|
| 619 |
|
|---|
| 620 | //--------------------------------------------------------------------
|
|---|
| 621 | // draw the 3D histogram : Theta, pixel, Sigma^2-Sigmabar^2
|
|---|
| 622 |
|
|---|
| 623 | TH2D *l;
|
|---|
| 624 |
|
|---|
| 625 | c.cd(2);
|
|---|
| 626 | l = (TH2D*) ((TH3*)fHDiffPixTh)->Project3D("zx");
|
|---|
| 627 |
|
|---|
| 628 | l->SetTitle("Sigma^2-Sigmabar^2 vs. \\Theta (all pixels)");
|
|---|
| 629 | l->SetXTitle("\\Theta [\\circ]");
|
|---|
| 630 | l->SetYTitle("Sigma^2-Sigmabar^2");
|
|---|
| 631 |
|
|---|
| 632 | *fLog << "before box" << endl;
|
|---|
| 633 |
|
|---|
| 634 | l->Draw("box");
|
|---|
| 635 | l->SetBit(kCanDelete);;
|
|---|
| 636 |
|
|---|
| 637 | c.cd(5);
|
|---|
| 638 | l = (TH2D*) ((TH3*)fHDiffPixTh)->Project3D("zy");
|
|---|
| 639 | l->SetTitle("Sigma^2-Sigmabar^2 vs. pixel number (all \\Theta)");
|
|---|
| 640 | l->SetXTitle("pixel");
|
|---|
| 641 | l->SetYTitle("Sigma^2-Sigmabar^2");
|
|---|
| 642 |
|
|---|
| 643 | l->Draw("box");
|
|---|
| 644 | l->SetBit(kCanDelete);;
|
|---|
| 645 |
|
|---|
| 646 | c.cd(8);
|
|---|
| 647 | ((TH2*)fHDiffPixTh)->DrawCopy();
|
|---|
| 648 |
|
|---|
| 649 |
|
|---|
| 650 | //--------------------------------------------------------------------
|
|---|
| 651 | // draw the 3D histogram : Theta, pixel, Sigma
|
|---|
| 652 |
|
|---|
| 653 | TH2D *k;
|
|---|
| 654 |
|
|---|
| 655 | c.cd(3);
|
|---|
| 656 | k = (TH2D*) ((TH3*)fHSigPixTh)->Project3D("zx");
|
|---|
| 657 | k->SetTitle("Sigma vs. \\Theta (all pixels)");
|
|---|
| 658 | k->SetXTitle("\\Theta [\\circ]");
|
|---|
| 659 | k->SetYTitle("Sigma");
|
|---|
| 660 |
|
|---|
| 661 | k->Draw("box");
|
|---|
| 662 | k->SetBit(kCanDelete);
|
|---|
| 663 |
|
|---|
| 664 | c.cd(6);
|
|---|
| 665 | k = (TH2D*) ((TH3*)fHSigPixTh)->Project3D("zy");
|
|---|
| 666 | k->SetTitle("Sigma vs. pixel number (all \\Theta)");
|
|---|
| 667 | k->SetXTitle("pixel");
|
|---|
| 668 | k->SetYTitle("Sigma");
|
|---|
| 669 |
|
|---|
| 670 | k->Draw("box");
|
|---|
| 671 | k->SetBit(kCanDelete);;
|
|---|
| 672 |
|
|---|
| 673 | c.cd(9);
|
|---|
| 674 | ((TH2*)fHSigPixTh)->DrawCopy();
|
|---|
| 675 |
|
|---|
| 676 | //--------------------------------------------------------------------
|
|---|
| 677 |
|
|---|
| 678 | c.cd(10);
|
|---|
| 679 | fHSigmaPedestal->DrawClone();
|
|---|
| 680 | fHSigmaPedestal->SetBit(kCanDelete);
|
|---|
| 681 |
|
|---|
| 682 | c.cd(11);
|
|---|
| 683 | fHPhotons->DrawClone();
|
|---|
| 684 | fHPhotons->SetBit(kCanDelete);
|
|---|
| 685 |
|
|---|
| 686 | //--------------------------------------------------------------------
|
|---|
| 687 |
|
|---|
| 688 | return kTRUE;
|
|---|
| 689 | }
|
|---|
| 690 |
|
|---|
| 691 | // --------------------------------------------------------------------------
|
|---|
| 692 |
|
|---|