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