Ignore:
Timestamp:
08/12/04 06:58:34 (20 years ago)
Author:
wittek
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/manalysis
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/manalysis/MPad.cc

    r2798 r4584  
    6464#include <TCanvas.h>
    6565#include <TFile.h>
     66#include <TVirtualPad.h>
    6667
    6768#include "MBinning.h"
    6869#include "MSigmabar.h"
    69 #include "MMcEvt.hxx"
     70#include "MPointingPos.h"
    7071#include "MLog.h"
    7172#include "MLogManip.h"
     
    7576#include "MCerPhotPix.h"
    7677#include "MCerPhotEvt.h"
     78
     79#include "MH.h"
    7780
    7881#include "MPedPhotCam.h"
     
    190193  //             from sigma_k to sigma_j
    191194
     195  //*fLog << all << "MPad::Merge2Distributions(); Entry" << endl;
     196
    192197  Double_t eps = 1.e-10;
    193198
     
    205210  Double_t v, s, w, t, x, u, a, b, arg;
    206211
     212  //*fLog << "Content of histcp : " << endl;
     213
    207214  for (Int_t j=nbinssig; j >= 1; j--)
    208215  {
     216    //*fLog << "j, hista, histb , histap : " << j << ",  "
     217    //                              <<  hista->GetBinContent(j) << ",  "
     218    //                              <<  histb->GetBinContent(j) << ",  "
     219    //                              <<  histap->GetBinContent(j) << endl;
     220
    209221    v = histcp->GetBinContent(j);
     222    //*fLog << "cp : j, v = " << j << ",  " << v << endl;
     223
    210224    if ( fabs(v) < eps ) continue;
    211225    if (v >= 0.0)
     
    255269      }
    256270
    257       *fLog << all << "k, j, arg = " << k << ",  " << j
    258             << ",  " << arg << endl;
     271      //*fLog << all << "k, j, arg = " << k << ",  " << j
     272      //      << ",  " << arg << endl;
    259273
    260274      //......................................
     
    302316
    303317  // check results
     318
     319  //*fLog << "Content of histap, histbp, histcp : " << endl;
     320
    304321  for (Int_t j=1; j<=nbinssig; j++)
    305322  {
     
    308325    Double_t c = histcp->GetBinContent(j);
    309326
     327    //*fLog << "j, a, b, c = " << j << ":  " << a << ",  " << b << ",  "
     328    //      << c << endl;
     329
    310330    if( fabs(a-b)>3.0*eps  ||  fabs(c)>3.0*eps )
    311331      *fLog << err << "MPad::Merge2Distributions(); inconsistency in results; j, a, b, c = "
     
    314334
    315335  //---------------------------------------------------------------
    316   TCanvas &c = *(MH::MakeDefCanvas("Merging", "", 600, 600));
    317   c.Divide(2, 2);
     336  TCanvas *pad = MH::MakeDefCanvas("Merging", "", 600, 600);
    318337  gROOT->SetSelectedPad(NULL);
    319338
    320   c.cd(1);
     339  pad->Divide(2, 2);
     340
     341  pad->cd(1);
     342  gPad->SetBorderMode(0);
    321343  hista->SetDirectory(NULL);
    322   hista->DrawCopy();
     344  hista->Draw();
    323345  hista->SetBit(kCanDelete);   
    324346
    325   c.cd(2);
     347  pad->cd(2);
     348  gPad->SetBorderMode(0);
    326349  histb->SetDirectory(NULL);
    327   histb->DrawCopy();
     350  histb->Draw();
    328351  histb->SetBit(kCanDelete);   
    329352
    330   c.cd(3);
     353  pad->cd(3);
     354  gPad->SetBorderMode(0);
    331355  histap->SetDirectory(NULL);
    332   histap->DrawCopy();
     356  histap->Draw();
    333357  histap->SetBit(kCanDelete);   
     358
     359  pad->DrawClone();
    334360
    335361  //--------------------------------------------------------------------
     
    339365  delete histcp;
    340366
     367  //*fLog << all << "MPad::Merge2Distributions(); Exit" << endl;
     368
    341369  return kTRUE;
    342370}
     
    357385
    358386Bool_t MPad::MergeONOFFMC(
    359    TH2D *sigthmc,  TH3D *diffpixthmc,  TH3D *sigmapixthmc,
    360    TH2D *blindidthmc,  TH2D *blindnthmc,
    361    TH2D *sigthon,  TH3D *diffpixthon,  TH3D *sigmapixthon,
    362    TH2D *blindidthon,  TH2D *blindnthon,
    363    TH2D *sigthoff, TH3D *diffpixthoff, TH3D *sigmapixthoff,
    364    TH2D *blindidthoff, TH2D *blindnthoff)
     387   TH2D& sigthmc,  TH3D& diffpixthmc,  TH3D& sigmapixthmc,
     388   TH2D& blindidthmc,  TH2D& blindnthmc,
     389   TH2D& sigthon,  TH3D& diffpixthon,  TH3D& sigmapixthon,
     390   TH2D& blindidthon,  TH2D& blindnthon,
     391   TH2D& sigthoff, TH3D& diffpixthoff, TH3D& sigmapixthoff,
     392   TH2D& blindidthoff, TH2D& blindnthoff)
    365393{
     394  //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
     395  // for testing
     396  /*
     397  TAxis *xa = sigthon.GetXaxis();
     398  Int_t nbitheta = xa->GetNbins();
     399
     400  TAxis *ya = sigthon.GetYaxis();
     401  Int_t nbisig = ya->GetNbins();
     402  for (Int_t i=1; i<=nbitheta; i++)
     403  {
     404    for (Int_t j=1; j<=nbisig; j++)
     405    {
     406      if (i>0)
     407      {
     408        sigthmc.SetBinContent( i, j, (Float_t) (625000.0+(nbisig*nbisig*nbisig-j*j*j)) );
     409        sigthon.SetBinContent( i, j, (Float_t)(1.0) );
     410        sigthoff.SetBinContent(  i, j, (Float_t)( (0.5*nbisig-j)*(0.5*nbisig-j)            ) );
     411      }
     412      else
     413      {
     414        sigthmc.SetBinContent( i, j, 0.0);
     415        sigthon.SetBinContent( i, j, 0.0);
     416        sigthoff.SetBinContent(i, j, 0.0);
     417      }
     418    }
     419  }
     420  */
     421  //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
     422
    366423  *fLog << all << "----------------------------------------------------------------------------------" << endl;
    367424  *fLog << all << "MPad::MergeONOFFMC(); Merge the ON, OFF and MC histograms to obtain the target distributions for the padding"
    368425        << endl;
    369426
    370   fHSigmaTheta = new TH2D( (TH2D&)*sigthon );
     427  fHSigmaTheta = new TH2D( (const TH2D&) sigthon );
    371428  fHSigmaTheta->SetNameTitle("2D-ThetaSigmabar", "2D-ThetaSigmabar (target)");
    372429
    373   fHDiffPixTheta = new TH3D( (TH3D&)*diffpixthon );
     430  *fLog << "after booking fHSigmaTheta" << endl;
     431
     432  fHDiffPixTheta = new TH3D( (const TH3D&) diffpixthon );
    374433  fHDiffPixTheta->SetNameTitle("3D-ThetaPixDiff", "3D-ThetaPixDiff (target)");
    375434
    376   fHSigmaPixTheta = new TH3D( (TH3D&)*sigmapixthon );
     435  *fLog << "after booking fHDiffPixTheta" << endl;
     436
     437  fHSigmaPixTheta = new TH3D( (const TH3D&) sigmapixthon );
    377438  fHSigmaPixTheta->SetNameTitle("3D-ThetaPixSigma", "3D-ThetaPixSigma (target)");
    378 
    379   fHBlindPixNTheta = new TH2D( (TH2D&)*blindnthon );
     439  *fLog << "after booking fHSigmaPixTheta" << endl;
     440
     441  fHBlindPixNTheta = new TH2D( (const TH2D&) blindnthon );
    380442  fHBlindPixNTheta->SetNameTitle("2D-ThetaBlindN", "2D-ThetaBlindN (target)");
    381443
    382   fHBlindPixIdTheta = new TH2D( (TH2D&)*blindidthon );
     444  *fLog << "after booking fHBlindPixNTheta" << endl;
     445
     446  fHBlindPixIdTheta = new TH2D( (const TH2D&) blindidthon );
    383447  fHBlindPixIdTheta->SetNameTitle("2D-ThetaBlindId", "2D-ThetaBlindId (target)");
    384448
     449  *fLog << "after booking fHBlindPixIdTheta" << endl;
     450  *fLog << all << "Histograms for the merged padding plots were booked"
     451        << endl;
     452
    385453  //--------------------------
    386   fHSigmaThetaMC = sigthmc;
     454  fHSigmaThetaMC = &sigthmc;
    387455  fHSigmaThetaMC->SetNameTitle("2D-ThetaSigmabarMC", "2D-ThetaSigmabarMC (orig.)");
    388   fHSigmaThetaON = sigthon;
     456  fHSigmaThetaON = &sigthon;
    389457  fHSigmaThetaON->SetNameTitle("2D-ThetaSigmabarON", "2D-ThetaSigmabarON (orig.)");
    390   fHSigmaThetaOFF = sigthoff;
     458  fHSigmaThetaOFF = &sigthoff;
    391459  fHSigmaThetaOFF->SetNameTitle("2D-ThetaSigmabarOFF", "2D-ThetaSigmabarOFF (orig.)");
    392460
     461  //*fLog << all << "addresses of SigmaTheta padding plots were copied"
     462  //      << endl;
     463
    393464  //--------------------------
    394   fHBlindPixNThetaMC = blindnthmc;
     465  fHBlindPixNThetaMC = &blindnthmc;
    395466  fHBlindPixNThetaMC->SetNameTitle("2D-ThetaBlindNMC", "2D-ThetaBlindNMC (orig.)");
    396   fHBlindPixNThetaON = blindnthon;
     467  fHBlindPixNThetaON = &blindnthon;
    397468  fHBlindPixNThetaON->SetNameTitle("2D-ThetaBlindNON", "2D-ThetaBlindNON (orig.)");
    398   fHBlindPixNThetaOFF = blindnthoff;
     469  fHBlindPixNThetaOFF = &blindnthoff;
    399470  fHBlindPixNThetaOFF->SetNameTitle("2D-ThetaBlindNOFF", "2D-ThetaBlindNOFF (orig.)");
    400471
     472  //*fLog << all << "addresses of BlindPixTheta padding plots were copied"
     473  //      << endl;
     474
    401475  //--------------------------
    402   fHBlindPixIdThetaMC = blindidthmc;
     476  fHBlindPixIdThetaMC = &blindidthmc;
    403477  fHBlindPixIdThetaMC->SetNameTitle("2D-ThetaBlindIdMC", "2D-ThetaBlindIdMC (orig.)");
    404   fHBlindPixIdThetaON = blindidthon;
     478  fHBlindPixIdThetaON = &blindidthon;
    405479  fHBlindPixIdThetaON->SetNameTitle("2D-ThetaBlindIdON", "2D-ThetaBlindIdON (orig.)");
    406   fHBlindPixIdThetaOFF = blindidthoff;
     480  fHBlindPixIdThetaOFF = &blindidthoff;
    407481  fHBlindPixIdThetaOFF->SetNameTitle("2D-ThetaBlindIdOFF", "2D-ThetaBlindIdOFF (orig.)");
    408482
     483  //*fLog << all << "addresses of BlindPixIdTheta padding plots were copied"
     484  //      << endl;
     485
    409486  //--------------------------
    410   fHDiffPixThetaMC = diffpixthmc;
     487  fHDiffPixThetaMC = &diffpixthmc;
    411488  fHDiffPixThetaMC->SetNameTitle("3D-ThetaPixDiffMC", "3D-ThetaPixDiffMC (orig.)");
    412   fHDiffPixThetaON = diffpixthon;
     489  fHDiffPixThetaON = &diffpixthon;
    413490  fHDiffPixThetaON->SetNameTitle("3D-ThetaPixDiffON", "3D-ThetaPixDiffON (orig.)");
    414   fHDiffPixThetaOFF = diffpixthoff;
     491  fHDiffPixThetaOFF = &diffpixthoff;
    415492  fHDiffPixThetaOFF->SetNameTitle("3D-ThetaPixDiffOFF", "3D-ThetaPixDiffOFF (orig.)");
    416493
     494  //*fLog << all << "addresses of DiffPixTheta padding plots were copied"
     495  //      << endl;
     496
    417497  //--------------------------
    418   fHSigmaPixThetaMC = sigmapixthmc;
     498  fHSigmaPixThetaMC = &sigmapixthmc;
    419499  fHSigmaPixThetaMC->SetNameTitle("3D-ThetaPixSigmaMC", "3D-ThetaPixSigmaMC (orig.)");
    420   fHSigmaPixThetaON = sigmapixthon;
     500  fHSigmaPixThetaON = &sigmapixthon;
    421501  fHSigmaPixThetaON->SetNameTitle("3D-ThetaPixSigmaON", "3D-ThetaPixSigmaON (orig.)");
    422   fHSigmaPixThetaOFF = sigmapixthoff;
     502  fHSigmaPixThetaOFF = &sigmapixthoff;
    423503  fHSigmaPixThetaOFF->SetNameTitle("3D-ThetaPixSigmaOFF", "3D-ThetaPixSigmaOFF (orig.)");
     504
     505  //*fLog << all << "addresses of SigmaPixTheta padding plots were copied"
     506  //      << endl;
     507
    424508  //--------------------------
    425509
     
    427511  // get binning for fHgON, fHgOFF and fHgMC  from sigthon
    428512  // binning in Theta
    429   TAxis *ax = sigthon->GetXaxis();
     513  TAxis *ax = sigthon.GetXaxis();
     514  Int_t nbinstheta = ax->GetNbins();
     515  TArrayD edgesx;
     516  edgesx.Set(nbinstheta+1);
     517  for (Int_t i=0; i<=nbinstheta; i++)
     518  {
     519    edgesx[i] = ax->GetBinLowEdge(i+1);
     520    //*fLog << all << "i, theta low edge = " << i << ",  " << edgesx[i]
     521    //      << endl;
     522  }
     523  MBinning binth;
     524  binth.SetEdges(edgesx);
     525
     526  // binning in sigmabar
     527  TAxis *ay = sigthon.GetYaxis();
     528  Int_t nbinssig = ay->GetNbins();
     529  TArrayD edgesy;
     530  edgesy.Set(nbinssig+1);
     531  for (Int_t i=0; i<=nbinssig; i++)
     532  {
     533    edgesy[i] = ay->GetBinLowEdge(i+1);
     534    //*fLog << all << "i, sigmabar low edge = " << i << ",  " << edgesy[i]
     535    //      << endl;
     536  }
     537  MBinning binsg;
     538  binsg.SetEdges(edgesy);
     539
     540
     541  fHgMC = new TH3D;
     542  MH::SetBinning(fHgMC, &binth, &binsg, &binsg);
     543  fHgMC->SetNameTitle("3D-PaddingMatrixMC", "3D-PadMatrixThetaMC");
     544
     545  fHgON = new TH3D;
     546  MH::SetBinning(fHgON, &binth, &binsg, &binsg);
     547  fHgON->SetNameTitle("3D-PaddingMatrixON", "3D-PadMatrixThetaON");
     548
     549  fHgOFF = new TH3D;
     550  MH::SetBinning(fHgOFF, &binth, &binsg, &binsg);
     551  fHgOFF->SetNameTitle("3D-PaddingMatrixOFF", "3D-PadMatrixThetaOFF");
     552
     553  //*fLog << all << "fHg histograms were booked" << endl;
     554
     555  //............   loop over Theta bins   ...........................
     556
     557
     558
     559  //*fLog << all << "MPad::MergeONOFFMC(); bins of Theta, Sigmabarold, Sigmabarnew, fraction of events to be padded" << endl;
     560  for (Int_t l=1; l<=nbinstheta; l++)
     561  {
     562    //-------------------------------------------
     563    // merge ON and OFF distributions
     564    // input : hista is the normalized 1D distr. of sigmabar for ON  data
     565    //         histb is the normalized 1D distr. of sigmabar for OFF data
     566    // output : histap    will be the merged distribution (ON-OFF)
     567    //          fHga(k,j) will tell which fraction of ON events should be
     568    //                    padded from bin k to bin j
     569    //          fHgb(k,j) will tell which fraction of OFF events should be
     570    //                    padded from bin k to bin j
     571
     572    TH2D * fHga = new TH2D;
     573    MH::SetBinning(fHga, &binsg, &binsg);
     574    TH2D * fHgb = new TH2D;
     575    MH::SetBinning(fHgb, &binsg, &binsg);
     576
     577    TH1D *hista  = sigthon.ProjectionY("sigon_y", l, l, "");
     578    hista->SetNameTitle("ON-orig", "ON (orig)");
     579    Stat_t suma = hista->Integral();
     580    if (suma != 0.0) hista->Scale(1./suma);
     581
     582    TH1D *histap  = new TH1D( (const TH1D&)*hista );
     583    histap->SetNameTitle("ON-OFF-merged)", "ON-OFF (merged)");
     584
     585    TH1D *histb  = sigthoff.ProjectionY("sigoff_y", l, l, "");
     586    histb->SetNameTitle("OFF-orig", "OFF (orig)");
     587    Stat_t sumb = histb->Integral();
     588    if (sumb != 0.0) histb->Scale(1./sumb);
     589
     590    if (suma == 0.0  ||  sumb == 0.0)
     591    {
     592      delete hista;
     593      delete histb;
     594      delete fHga;
     595      delete fHgb;
     596      delete histap;
     597
     598      *fLog << err
     599            << "cannot call Merge2Distributions(ON, OFF)  for theta bin l = "
     600            << l << ";  NevON, NevOFF = " << suma << ",  " << sumb << endl;
     601
     602      // go to next theta bin (l)
     603      continue;
     604    }
     605
     606    //*fLog << "call Merge2Distributions(ON, OFF)  for theta bin l = "
     607    //      << l << endl;
     608
     609    Merge2Distributions(hista, histb, histap, fHga, fHgb, nbinssig);
     610
     611    // fill fHgON and fHgOFF
     612    for (Int_t k=1; k<=nbinssig; k++)
     613      for (Int_t j=1; j<=nbinssig; j++)
     614      {
     615        Double_t a = fHga->GetBinContent(k,j);
     616        fHgON->SetBinContent(l, k, j, a);
     617
     618        Double_t b = fHgb->GetBinContent(k,j);
     619        fHgOFF->SetBinContent(l, k, j, b);
     620      }
     621
     622    //-------------------------------------------
     623    // now merge ON-OFF and MC distributions
     624    // input : histe is the result of the merging of ON and OFF distributions 
     625    //         histf is the normalized 1D distr. of sigmabar for MC data
     626    // output : histep    will be the merged distribution (target distribution)
     627    //          fHge(k,j) will tell which fraction of ON, OFF events should be
     628    //                    padded from bin k to bin j
     629    //          fHgf(k,j) will tell which fraction of MC events should be
     630    //                    padded from bin k to bin j
     631
     632    TH2D * fHge = new TH2D;
     633    MH::SetBinning(fHge, &binsg, &binsg);
     634    TH2D * fHgf = new TH2D;
     635    MH::SetBinning(fHgf, &binsg, &binsg);
     636
     637    TH1D *histe  = new TH1D( (const TH1D&)*histap);
     638    histe->SetNameTitle("ON-OFF-merged", "ON-OFF (merged)");
     639
     640    TH1D *histep  = new TH1D( (const TH1D&)*histe);
     641    histep->SetNameTitle("ON-OFF-MC-merged)", "ON-OFF-MC (merged)");
     642
     643    TH1D *histf  = sigthmc.ProjectionY("sigmc_y", l, l, "");
     644    histf->SetNameTitle("MC-orig", "MC (orig)");
     645    Double_t sumf = histf->Integral();
     646    if (sumf != 0.0) histf->Scale(1./sumf);
     647
     648    if (sumf == 0.0)
     649    {
     650      delete hista;
     651      delete histb;
     652      delete fHga;
     653      delete fHgb;
     654      delete histap;
     655
     656      delete histe;
     657      delete histf;
     658      delete fHge;
     659      delete fHgf;
     660      delete histep;
     661
     662      *fLog << err
     663            << "cannot call Merge2Distributions(ON-OFF,MC)  for theta bin l = "
     664            << l << ";  NevMC = " << sumf << endl;
     665
     666      // go to next theta bin (l)
     667      continue;
     668    }
     669
     670    //*fLog << "call Merge2Distributions(ON-OFF, MC)  for theta bin l = "
     671    //      << l << endl;
     672
     673    Merge2Distributions(histe, histf, histep, fHge, fHgf, nbinssig);
     674
     675    // update fHgON and fHgOFF
     676    UpdateHg(fHga, histap, fHge, fHgON,  nbinssig, l);
     677    UpdateHg(fHgb, histap, fHge, fHgOFF, nbinssig, l);
     678
     679    // fill fHgMC
     680    for (Int_t k=1; k<=nbinssig; k++)
     681      for (Int_t j=1; j<=nbinssig; j++)
     682      {
     683        Double_t f = fHgf->GetBinContent(k,j);
     684        fHgMC->SetBinContent(l, k, j, f);
     685      }
     686
     687    // fill target distribution fHSigmaTheta
     688    // (only for plotting, it will not  be used in the padding)
     689    for (Int_t j=1; j<=nbinssig; j++)
     690    {
     691      Double_t ep = histep->GetBinContent(j);
     692      fHSigmaTheta->SetBinContent(l, j, ep);
     693    }
     694    //-------------------------------------------
     695
     696    delete hista;
     697    delete histb;
     698    delete fHga;
     699    delete fHgb;
     700    delete histap;
     701
     702    delete histe;
     703    delete histf;
     704    delete fHge;
     705    delete fHgf;
     706    delete histep;
     707  }
     708  //............   end of loop over Theta bins   ....................
     709
     710 
     711  // Define the target distributions
     712  //        fHDiffPixTheta, fHSigmaPixTheta
     713  //               (they are calculated as
     714  //               averages of the ON and OFF distributions)
     715  //        fHBlindPixNTheta, fHBlindPixIdTheta
     716  //               (they are calculated as
     717  //               the sum of the ON and OFF distributions)
     718  // (fHDiffPixTheta will be used in the padding of MC events)
     719
     720  //............   start of new loop over Theta bins   ....................
     721  for (Int_t j=1; j<=nbinstheta; j++)
     722  {
     723    // fraction of ON/OFF/MC events to be padded : fracON, fracOFF, fracMC
     724
     725    Double_t fracON  = fHgON->Integral (j, j, 1, nbinssig, 1, nbinssig, "");
     726    Double_t fracOFF = fHgOFF->Integral(j, j, 1, nbinssig, 1, nbinssig, "");
     727    Double_t fracMC  = fHgMC->Integral(j, j, 1, nbinssig, 1, nbinssig, "");
     728
     729    Double_t normON;
     730    Double_t normOFF;
     731
     732    // set ranges for 2D-projections of 3D-histograms
     733    TAxis *ax = diffpixthon.GetXaxis();
     734    ax->SetRange(j, j);
     735    ax = diffpixthoff.GetXaxis();
     736    ax->SetRange(j, j);
     737
     738    TH2D *hist;
     739    TH2D *histOFF;
     740
     741    TH1D *hist1;
     742    TH1D *hist1OFF;
     743
     744    // weights for ON and OFF distrubtions when
     745    // calculating the weighted average
     746    Double_t facON  = 0.5 * (1. - fracON + fracOFF);
     747    Double_t facOFF = 0.5 * (1. + fracON - fracOFF);
     748 
     749    *fLog << all << "Theta bin j : fracON, fracOFF, fracMC, facON, facOFF = "
     750          << j << ",  " << fracON << ",  " << fracOFF << ",  "
     751          << fracMC << ",  " << facON << ",  " << facOFF << endl;
     752
     753    //------------------------------------------------------------------
     754    // define target distribution  'sigma^2-sigmavar^2 vs. pixel number'
     755    ay = diffpixthon.GetYaxis();
     756    Int_t nbinspixel = ay->GetNbins();
     757
     758    TAxis *az = diffpixthon.GetZaxis();
     759    Int_t nbinsdiff = az->GetNbins();
     760
     761    hist    = (TH2D*)diffpixthon.Project3D("zy");
     762    hist->SetName("dummy");
     763    histOFF = (TH2D*)diffpixthoff.Project3D("zy");
     764
     765    normON  = hist->Integral();
     766    normOFF = histOFF->Integral();
     767    if (normON  != 0.0) hist->Scale(1.0/normON);
     768    if (normOFF != 0.0) histOFF->Scale(1.0/normOFF);
     769
     770    // weighted average of ON and OFF distributions
     771    hist->Scale(facON);
     772    hist->Add(histOFF, facOFF);
     773
     774    for (Int_t k=1; k<=nbinspixel; k++)
     775      for (Int_t l=1; l<=nbinsdiff; l++)
     776      {
     777        Double_t cont = hist->GetBinContent(k,l);
     778        fHDiffPixTheta->SetBinContent(j, k, l, cont); 
     779      }
     780
     781    delete hist;
     782    delete histOFF;
     783
     784    //------------------------------------------------------------------
     785    // define target distribution  'sigma vs. pixel number'
     786    ay = sigmapixthon.GetYaxis();
     787    nbinspixel = ay->GetNbins();
     788
     789    az = sigmapixthon.GetZaxis();
     790    Int_t nbinssigma = az->GetNbins();
     791
     792    hist    = (TH2D*)sigmapixthon.Project3D("zy");
     793    hist->SetName("dummy");
     794    histOFF = (TH2D*)sigmapixthoff.Project3D("zy");
     795
     796    normON  = hist->Integral();
     797    normOFF = histOFF->Integral();
     798    if (normON  != 0.0) hist->Scale(1.0/normON);
     799    if (normOFF != 0.0) histOFF->Scale(1.0/normOFF);
     800
     801    // weighted average of ON and OFF distributions
     802    hist->Scale(facON);
     803    hist->Add(histOFF, facOFF);
     804
     805    for (Int_t k=1; k<=nbinspixel; k++)
     806      for (Int_t l=1; l<=nbinssigma; l++)
     807      {
     808        Double_t cont = hist->GetBinContent(k,l);
     809        fHSigmaPixTheta->SetBinContent(j, k, l, cont); 
     810      }
     811
     812    delete hist;
     813    delete histOFF;
     814
     815
     816    //------------------------------------------------------------------
     817    // define target distribution  'number of blind pixels per event'
     818    ay = blindnthon.GetYaxis();
     819    Int_t nbinsn = ay->GetNbins();
     820
     821    hist1    = fHBlindPixNThetaON->ProjectionY("", j, j, "");
     822    hist1->SetName("dummy");
     823    hist1OFF = fHBlindPixNThetaOFF->ProjectionY("", j, j, "");
     824
     825    normON  = hist1->Integral();
     826    normOFF = hist1OFF->Integral();
     827    if (normON  != 0.0) hist1->Scale(1.0/normON);
     828    if (normOFF != 0.0) hist1OFF->Scale(1.0/normOFF);
     829
     830    // sum of ON and OFF distributions
     831    hist1->Add(hist1OFF, 1.0);
     832    Stat_t sum1 = hist1->Integral();
     833    if (sum1 != 0.0) hist1->Scale( 1.0/sum1 );
     834
     835    for (Int_t k=1; k<=nbinsn; k++)
     836      {
     837        Double_t cont = hist1->GetBinContent(k);
     838        fHBlindPixNTheta->SetBinContent(j, k, cont); 
     839      }
     840
     841    delete hist1;
     842    delete hist1OFF;
     843
     844    //------------------------------------------------------------------
     845    // define target distribution  'id of blind pixel'
     846    ay = blindidthon.GetYaxis();
     847    Int_t nbinsid = ay->GetNbins();
     848
     849    hist1    = fHBlindPixIdThetaON->ProjectionY("", j, j, "");
     850    hist1->SetName("dummy");
     851    hist1OFF = fHBlindPixIdThetaOFF->ProjectionY("", j, j, "");
     852
     853    // divide by the number of events (from fHBlindPixNTheta)
     854    if (normON  != 0.0) hist1->Scale(1.0/normON);
     855    if (normOFF != 0.0) hist1OFF->Scale(1.0/normOFF);
     856
     857    // sum of ON and OFF distributions
     858    hist1->Add(hist1OFF, 1.0);
     859
     860    for (Int_t k=1; k<=nbinsid; k++)
     861      {
     862        Double_t cont = hist1->GetBinContent(k);
     863        fHBlindPixIdTheta->SetBinContent(j, k, cont); 
     864      }
     865
     866    delete hist1;
     867    delete hist1OFF;
     868  }
     869  //............   end of new loop over Theta bins   ....................
     870
     871  *fLog << all
     872        << "MPad::MergeONOFFMC(); The target distributions for the padding have been created"
     873        << endl;
     874  *fLog << all << "----------------------------------------------------------"
     875        << endl;
     876  //--------------------------------------------
     877
     878  fHSigmaThetaMC->SetDirectory(NULL);
     879  fHSigmaThetaON->SetDirectory(NULL);
     880  fHSigmaThetaOFF->SetDirectory(NULL);
     881
     882  fHDiffPixThetaMC->SetDirectory(NULL);
     883  fHDiffPixThetaON->SetDirectory(NULL);
     884  fHDiffPixThetaOFF->SetDirectory(NULL);
     885
     886  fHSigmaPixThetaMC->SetDirectory(NULL);
     887  fHSigmaPixThetaON->SetDirectory(NULL);
     888  fHSigmaPixThetaOFF->SetDirectory(NULL);
     889
     890  fHBlindPixIdThetaMC->SetDirectory(NULL);
     891  fHBlindPixIdThetaON->SetDirectory(NULL);
     892  fHBlindPixIdThetaOFF->SetDirectory(NULL);
     893
     894  fHBlindPixNThetaMC->SetDirectory(NULL);
     895  fHBlindPixNThetaON->SetDirectory(NULL);
     896  fHBlindPixNThetaOFF->SetDirectory(NULL);
     897
     898  fHgMC->SetDirectory(NULL);
     899  fHgON->SetDirectory(NULL);
     900  fHgOFF->SetDirectory(NULL);
     901
     902  return kTRUE;
     903}
     904
     905// --------------------------------------------------------------------------
     906//
     907// Update the matrix fHgA
     908// which contains the final padding prescriptions
     909//
     910
     911Bool_t MPad::UpdateHg(TH2D *fHga, TH1D *histap, TH2D *fHge, TH3D *fHgA,
     912                      Int_t nbinssig, Int_t l)
     913{
     914  // histap  target distribution after ON-OFF merging
     915  // fHga    padding prescription for ON (or OFF) data to get to histap
     916  // fHge    padding prescription to get from histap to the target
     917  //         distribution after the ON-OFF-MC merging
     918  // fHgA    updated padding prescription for ON (or OFF) data to get
     919  //         from the original ON (or OFF) histogram to the target
     920  //         distribution after the ON-OFF-MC merging
     921  // l       Theta bin
     922
     923  Double_t eps = 1.e-10;
     924
     925  for (Int_t k=1; k<=nbinssig; k++)
     926  {
     927    Double_t na  = fHga->Integral(1, nbinssig, k, k, " ");
     928    Double_t ne  = fHge->Integral(k, k, 1, nbinssig, " ");
     929    Double_t nap = histap->GetBinContent(k);
     930
     931    if (ne <= eps)
     932    {
     933      // go to next k
     934      continue;
     935    }
     936
     937    Double_t r = nap - na;
     938
     939    if (r >= ne-eps)
     940    {
     941      for (Int_t j=k+1; j<=nbinssig; j++)
     942      {
     943        Double_t e = fHge->GetBinContent(k,j);
     944        Double_t A = fHgA->GetBinContent(l,k,j);
     945        fHgA->SetBinContent(l, k, j, A + e);
     946      }
     947      // go to next k
     948      continue;
     949    }
     950
     951    for (Int_t j=k+1; j<=nbinssig; j++)
     952    {
     953      Double_t e = fHge->GetBinContent(k,j);
     954      Double_t A = fHgA->GetBinContent(l,k,j);
     955      fHgA->SetBinContent(l, k, j, A + r*e/ne);
     956    }
     957
     958    if (na <= eps)
     959    {
     960      // go to next k
     961      continue;
     962    }
     963
     964    for (Int_t i=1; i<k; i++)
     965    {
     966      Double_t a = fHga->GetBinContent(i,k);
     967      Double_t A = fHgA->GetBinContent(l,i,k);
     968      fHgA->SetBinContent(l, i, k, A - (ne-r)*a/na);
     969    }
     970
     971    for (Int_t i=1; i<=nbinssig; i++)
     972    {
     973      if (i == k) continue;
     974      for (Int_t j=i+1; j<=nbinssig; j++)
     975      {
     976        if (j == k) continue;
     977        Double_t a = fHga->GetBinContent(i,k);
     978        Double_t e = fHge->GetBinContent(k,j);
     979        Double_t A = fHgA->GetBinContent(l,i,j);
     980        fHgA->SetBinContent(l, i, j, A + (ne-r)*a*e/(na*ne)  );
     981      }
     982    }
     983  }
     984
     985  return kTRUE;
     986}
     987
     988// --------------------------------------------------------------------------
     989//
     990// Merge the distributions
     991//   fHSigmaTheta      2D-histogram  (Theta, sigmabar)
     992//
     993// ===>   of ON and MC data   <==============
     994//
     995// and define the matrices fHgMC and fHgON 
     996//
     997// These matrices tell which fraction of events should be padded
     998// from bin k of sigmabar to bin j
     999//
     1000
     1001Bool_t MPad::MergeONMC(
     1002   TH2D& sigthmc,  TH3D& diffpixthmc,  TH3D& sigmapixthmc,
     1003   TH2D& blindidthmc,  TH2D& blindnthmc,
     1004   TH2D& sigthon,  TH3D& diffpixthon,  TH3D& sigmapixthon,
     1005   TH2D& blindidthon,  TH2D& blindnthon)
     1006{
     1007  *fLog << all << "----------------------------------------------------------------------------------" << endl;
     1008  *fLog << all << "MPad::MergeONMC(); Merge the ON  and MC histograms to obtain the target distributions for the padding"
     1009        << endl;
     1010
     1011  fHSigmaTheta = new TH2D( (TH2D&) sigthon );
     1012  fHSigmaTheta->SetNameTitle("2D-ThetaSigmabar", "2D-ThetaSigmabar (target)");
     1013
     1014  fHDiffPixTheta = new TH3D( (TH3D&) diffpixthon );
     1015  fHDiffPixTheta->SetNameTitle("3D-ThetaPixDiff", "3D-ThetaPixDiff (target)");
     1016
     1017  fHSigmaPixTheta = new TH3D( (TH3D&) sigmapixthon );
     1018  fHSigmaPixTheta->SetNameTitle("3D-ThetaPixSigma", "3D-ThetaPixSigma (target)");
     1019
     1020  fHBlindPixNTheta = new TH2D( (TH2D&) blindnthon );
     1021  fHBlindPixNTheta->SetNameTitle("2D-ThetaBlindN", "2D-ThetaBlindN (target)");
     1022
     1023  fHBlindPixIdTheta = new TH2D( (TH2D&) blindidthon );
     1024  fHBlindPixIdTheta->SetNameTitle("2D-ThetaBlindId", "2D-ThetaBlindId (target)");
     1025
     1026  //--------------------------
     1027  fHSigmaThetaMC = &sigthmc;
     1028  fHSigmaThetaMC->SetNameTitle("2D-ThetaSigmabarMC", "2D-ThetaSigmabarMC (orig.)");
     1029  fHSigmaThetaON = &sigthon;
     1030  fHSigmaThetaON->SetNameTitle("2D-ThetaSigmabarON", "2D-ThetaSigmabarON (orig.)");
     1031
     1032  //--------------------------
     1033  fHBlindPixNThetaMC = &blindnthmc;
     1034  fHBlindPixNThetaMC->SetNameTitle("2D-ThetaBlindNMC", "2D-ThetaBlindNMC (orig.)");
     1035  fHBlindPixNThetaON = &blindnthon;
     1036  fHBlindPixNThetaON->SetNameTitle("2D-ThetaBlindNON", "2D-ThetaBlindNON (orig.)");
     1037
     1038  //--------------------------
     1039  fHBlindPixIdThetaMC = &blindidthmc;
     1040  fHBlindPixIdThetaMC->SetNameTitle("2D-ThetaBlindIdMC", "2D-ThetaBlindIdMC (orig.)");
     1041  fHBlindPixIdThetaON = &blindidthon;
     1042  fHBlindPixIdThetaON->SetNameTitle("2D-ThetaBlindIdON", "2D-ThetaBlindIdON (orig.)");
     1043
     1044  //--------------------------
     1045  fHDiffPixThetaMC = &diffpixthmc;
     1046  fHDiffPixThetaMC->SetNameTitle("3D-ThetaPixDiffMC", "3D-ThetaPixDiffMC (orig.)");
     1047  fHDiffPixThetaON = &diffpixthon;
     1048  fHDiffPixThetaON->SetNameTitle("3D-ThetaPixDiffON", "3D-ThetaPixDiffON (orig.)");
     1049
     1050  //--------------------------
     1051  fHSigmaPixThetaMC = &sigmapixthmc;
     1052  fHSigmaPixThetaMC->SetNameTitle("3D-ThetaPixSigmaMC", "3D-ThetaPixSigmaMC (orig.)");
     1053  fHSigmaPixThetaON = &sigmapixthon;
     1054  fHSigmaPixThetaON->SetNameTitle("3D-ThetaPixSigmaON", "3D-ThetaPixSigmaON (orig.)");
     1055
     1056  //--------------------------
     1057
     1058
     1059  // get binning for fHgON and fHgMC  from sigthon
     1060  // binning in Theta
     1061  TAxis *ax = sigthon.GetXaxis();
    4301062  Int_t nbinstheta = ax->GetNbins();
    4311063  TArrayD edgesx;
     
    4411073
    4421074  // binning in sigmabar
    443   TAxis *ay = sigthon->GetYaxis();
     1075  TAxis *ay = sigthon.GetYaxis();
    4441076  Int_t nbinssig = ay->GetNbins();
    4451077  TArrayD edgesy;
     
    4631095  fHgON->SetNameTitle("3D-PaddingMatrixON", "3D-PadMatrixThetaON");
    4641096
    465   fHgOFF = new TH3D;
    466   MH::SetBinning(fHgOFF, &binth, &binsg, &binsg);
    467   fHgOFF->SetNameTitle("3D-PaddingMatrixOFF", "3D-PadMatrixThetaOFF");
    468 
    469   //............   loop over Theta bins   ...........................
    470 
    471 
    472 
    473   *fLog << all << "MPad::MergeONOFFMC(); bins of Theta, Sigmabarold, Sigmabarnew, fraction of events to be padded" << endl;
    474   for (Int_t l=1; l<=nbinstheta; l++)
    475   {
    476     TH2D * fHga = new TH2D;
    477     MH::SetBinning(fHga, &binsg, &binsg);
    478     TH2D * fHgb = new TH2D;
    479     MH::SetBinning(fHgb, &binsg, &binsg);
    480 
    481     //-------------------------------------------
    482     // merge ON and OFF distributions
    483     // input : hista is the normalized 1D distr. of sigmabar for ON  data
    484     //         histb is the normalized 1D distr. of sigmabar for OFF data
    485     // output : histap    will be the merged distribution (ON-OFF)
    486     //          fHga(k,j) will tell which fraction of ON events should be
    487     //                    padded from bin k to bin j
    488     //          fHgb(k,j) will tell which fraction of OFF events should be
    489     //                    padded from bin k to bin j
    490 
    491     TH1D *hista  = sigthon->ProjectionY("sigon_y", l, l, "");
    492     Stat_t suma = hista->Integral();
    493     hista->Scale(1./suma);
    494 
    495     TH1D *histap  = new TH1D( (const TH1D&)*hista );
    496 
    497     TH1D *histb  = sigthoff->ProjectionY("sigoff_y", l, l, "");
    498     Stat_t sumb = histb->Integral();
    499     histb->Scale(1./sumb);
    500 
    501     Merge2Distributions(hista, histb, histap, fHga, fHgb, nbinssig);
    502     delete hista;
    503     delete histb;
    504 
    505     // fill fHgON and fHgOFF
    506     for (Int_t k=1; k<=nbinssig; k++)
    507       for (Int_t j=1; j<=nbinssig; j++)
    508       {
    509         Double_t a = fHga->GetBinContent(k,j);
    510         fHga->SetBinContent (k, j, 0.0);
    511         fHgON->SetBinContent(l, k, j, a);
    512 
    513         Double_t b = fHgb->GetBinContent(k,j);
    514         fHgb->SetBinContent (k, j, 0.0);
    515         fHgOFF->SetBinContent(l, k, j, b);
    516       }
    517 
    518     //-------------------------------------------
    519     // now merge ON-OFF and MC distributions
    520     // input : hista is the result of the merging of ON and OFF distributions 
    521     //         histb is the normalized 1D distr. of sigmabar for MC data
    522     // output : histap    will be the merged distribution (target distribution)
    523     //          fHga(k,j) will tell which fraction of ON, OFF events should be
    524     //                    padded from bin k to bin j
    525     //          fHgb(k,j) will tell which fraction of MC events should be
    526     //                    padded from bin k to bin j
    527 
    528     hista  = new TH1D( (const TH1D&)*histap);
    529 
    530     histb  = sigthmc->ProjectionY("sigmc_y", l, l, "");
    531     sumb = histb->Integral();
    532     histb->Scale(1./sumb);
    533 
    534     Merge2Distributions(hista, histb, histap, fHga, fHgb, nbinssig);
    535     delete hista;
    536     delete histb;
    537 
    538     // update fHgON and fHgOFF and fill fHgMC
    539     for (Int_t k=1; k<=nbinssig; k++)
    540       for (Int_t j=1; j<=nbinssig; j++)
    541       {
    542         Double_t a   =  fHga->GetBinContent  (k,j);
    543 
    544         Double_t aON = fHgON->GetBinContent(l,k,j);
    545         fHgON->SetBinContent(l, k, j, aON+a);
    546 
    547         Double_t aOFF = fHgOFF->GetBinContent(l,k,j);
    548         fHgOFF->SetBinContent(l, k, j, aOFF+a);
    549 
    550         Double_t b = fHgb->GetBinContent(k,j);
    551         fHgMC->SetBinContent(l, k, j, b);
    552       }
    553 
    554     // fill target distribution fHSigmaTheta
    555     // (only for plotting, it will not  be used in the padding)
    556     for (Int_t j=1; j<=nbinssig; j++)
    557     {
    558       Double_t a = histap->GetBinContent(j);
    559       fHSigmaTheta->SetBinContent(l, j, a);
    560     }
    561 
    562     delete fHga;
    563     delete fHgb;
    564 
    565     delete histap;
    566   }
    567   //............   end of loop over Theta bins   ....................
    568 
    569  
    570   // Define the target distributions
    571   //        fHDiffPixTheta, fHSigmaPixTheta
    572   //               (they are calculated as
    573   //               averages of the ON and OFF distributions)
    574   //        fHBlindPixNTheta, fHBlindPixIdTheta
    575   //               (they are calculated as
    576   //               the sum of the ON and OFF distributions)
    577   // (fHDiffPixTheta will be used in the padding of MC events)
    578 
    579   //............   start of new loop over Theta bins   ....................
    580   for (Int_t j=1; j<=nbinstheta; j++)
    581   {
    582     // fraction of ON/OFF/MC events to be padded : fracON, fracOFF, fracMC
    583 
    584     Double_t fracON  = fHgON->Integral (j, j, 1, nbinssig, 1, nbinssig, "");
    585     Double_t fracOFF = fHgOFF->Integral(j, j, 1, nbinssig, 1, nbinssig, "");
    586     Double_t fracMC  = fHgMC->Integral(j, j, 1, nbinssig, 1, nbinssig, "");
    587 
    588     Double_t normON;
    589     Double_t normOFF;
    590 
    591     // set ranges for 2D-projections of 3D-histograms
    592     TAxis *ax = diffpixthon->GetXaxis();
    593     ax->SetRange(j, j);
    594     ax = diffpixthoff->GetXaxis();
    595     ax->SetRange(j, j);
    596 
    597     TH2D *hist;
    598     TH2D *histOFF;
    599 
    600     TH1D *hist1;
    601     TH1D *hist1OFF;
    602 
    603     // weights for ON and OFF distrubtions when
    604     // calculating the weighted average
    605     Double_t facON  = 0.5 * (1. - fracON + fracOFF);
    606     Double_t facOFF = 0.5 * (1. + fracON - fracOFF);
    607  
    608     *fLog << all << "Theta bin j : fracON, fracOFF, facON, facOFF = "
    609           << j << ",  " << fracON << ",  " << fracOFF << ",  "
    610           << fracMC << ",  " << facON << ",  " << facOFF << endl;
    611 
    612     //------------------------------------------------------------------
    613     // define target distribution  'sigma^2-sigmavar^2 vs. pixel number'
    614     ay = diffpixthon->GetYaxis();
    615     Int_t nbinspixel = ay->GetNbins();
    616 
    617     TAxis *az = diffpixthon->GetZaxis();
    618     Int_t nbinsdiff = az->GetNbins();
    619 
    620     hist    = (TH2D*)diffpixthon->Project3D("zy");
    621     hist->SetName("dummy");
    622     histOFF = (TH2D*)diffpixthoff->Project3D("zy");
    623 
    624     normON  = hist->Integral();
    625     normOFF = histOFF->Integral();
    626     if (normON  != 0.0) hist->Scale(1.0/normON);
    627     if (normOFF != 0.0) histOFF->Scale(1.0/normOFF);
    628 
    629     // weighted average of ON and OFF distributions
    630     hist->Scale(facON);
    631     hist->Add(histOFF, facOFF);
    632 
    633     for (Int_t k=1; k<=nbinspixel; k++)
    634       for (Int_t l=1; l<=nbinsdiff; l++)
    635       {
    636         Double_t cont = hist->GetBinContent(k,l);
    637         fHDiffPixTheta->SetBinContent(j, k, l, cont); 
    638       }
    639 
    640     delete hist;
    641     delete histOFF;
    642 
    643     //------------------------------------------------------------------
    644     // define target distribution  'sigma vs. pixel number'
    645     ay = sigmapixthon->GetYaxis();
    646     nbinspixel = ay->GetNbins();
    647 
    648     az = sigmapixthon->GetZaxis();
    649     Int_t nbinssigma = az->GetNbins();
    650 
    651     hist    = (TH2D*)sigmapixthon->Project3D("zy");
    652     hist->SetName("dummy");
    653     histOFF = (TH2D*)sigmapixthoff->Project3D("zy");
    654 
    655     normON  = hist->Integral();
    656     normOFF = histOFF->Integral();
    657     if (normON  != 0.0) hist->Scale(1.0/normON);
    658     if (normOFF != 0.0) histOFF->Scale(1.0/normOFF);
    659 
    660     // weighted average of ON and OFF distributions
    661     hist->Scale(facON);
    662     hist->Add(histOFF, facOFF);
    663 
    664     for (Int_t k=1; k<=nbinspixel; k++)
    665       for (Int_t l=1; l<=nbinssigma; l++)
    666       {
    667         Double_t cont = hist->GetBinContent(k,l);
    668         fHSigmaPixTheta->SetBinContent(j, k, l, cont); 
    669       }
    670 
    671     delete hist;
    672     delete histOFF;
    673 
    674 
    675     //------------------------------------------------------------------
    676     // define target distribution  'number of blind pixels per event'
    677     ay = blindnthon->GetYaxis();
    678     Int_t nbinsn = ay->GetNbins();
    679 
    680     hist1    = fHBlindPixNThetaON->ProjectionY("", j, j, "");
    681     hist1->SetName("dummy");
    682     hist1OFF = fHBlindPixNThetaOFF->ProjectionY("", j, j, "");
    683 
    684     normON  = hist1->Integral();
    685     normOFF = hist1OFF->Integral();
    686     if (normON  != 0.0) hist1->Scale(1.0/normON);
    687     if (normOFF != 0.0) hist1OFF->Scale(1.0/normOFF);
    688 
    689     // sum of ON and OFF distributions
    690     hist1->Add(hist1OFF, 1.0);
    691     hist1->Scale( 1.0/hist1->Integral() );
    692 
    693     for (Int_t k=1; k<=nbinsn; k++)
    694       {
    695         Double_t cont = hist1->GetBinContent(k);
    696         fHBlindPixNTheta->SetBinContent(j, k, cont); 
    697       }
    698 
    699     delete hist1;
    700     delete hist1OFF;
    701 
    702     //------------------------------------------------------------------
    703     // define target distribution  'id of blind pixel'
    704     ay = blindidthon->GetYaxis();
    705     Int_t nbinsid = ay->GetNbins();
    706 
    707     hist1    = fHBlindPixIdThetaON->ProjectionY("", j, j, "");
    708     hist1->SetName("dummy");
    709     hist1OFF = fHBlindPixIdThetaOFF->ProjectionY("", j, j, "");
    710 
    711     // divide by the number of events (from fHBlindPixNTheta)
    712     if (normON  != 0.0) hist1->Scale(1.0/normON);
    713     if (normOFF != 0.0) hist1OFF->Scale(1.0/normOFF);
    714 
    715     // sum of ON and OFF distributions
    716     hist1->Add(hist1OFF, 1.0);
    717 
    718     for (Int_t k=1; k<=nbinsid; k++)
    719       {
    720         Double_t cont = hist1->GetBinContent(k);
    721         fHBlindPixIdTheta->SetBinContent(j, k, cont); 
    722       }
    723 
    724     delete hist1;
    725     delete hist1OFF;
    726   }
    727   //............   end of new loop over Theta bins   ....................
    728 
    729   *fLog << all
    730         << "MPad::MergeONOFFMC(); The target distributions for the padding have been created"
    731         << endl;
    732   *fLog << all << "----------------------------------------------------------"
    733         << endl;
    734   //--------------------------------------------
    735 
    736   fHSigmaThetaMC->SetDirectory(NULL);
    737   fHSigmaThetaON->SetDirectory(NULL);
    738   fHSigmaThetaOFF->SetDirectory(NULL);
    739 
    740   fHDiffPixThetaMC->SetDirectory(NULL);
    741   fHDiffPixThetaON->SetDirectory(NULL);
    742   fHDiffPixThetaOFF->SetDirectory(NULL);
    743 
    744   fHSigmaPixThetaMC->SetDirectory(NULL);
    745   fHSigmaPixThetaON->SetDirectory(NULL);
    746   fHSigmaPixThetaOFF->SetDirectory(NULL);
    747 
    748   fHBlindPixIdThetaMC->SetDirectory(NULL);
    749   fHBlindPixIdThetaON->SetDirectory(NULL);
    750   fHBlindPixIdThetaOFF->SetDirectory(NULL);
    751 
    752   fHBlindPixNThetaMC->SetDirectory(NULL);
    753   fHBlindPixNThetaON->SetDirectory(NULL);
    754   fHBlindPixNThetaOFF->SetDirectory(NULL);
    755 
    756   fHgMC->SetDirectory(NULL);
    757   fHgON->SetDirectory(NULL);
    758   fHgOFF->SetDirectory(NULL);
    759 
    760   return kTRUE;
    761 }
    762 
    763 // --------------------------------------------------------------------------
    764 //
    765 // Merge the distributions
    766 //   fHSigmaTheta      2D-histogram  (Theta, sigmabar)
    767 //
    768 // ===>   of ON and MC data   <==============
    769 //
    770 // and define the matrices fHgMC and fHgON 
    771 //
    772 // These matrices tell which fraction of events should be padded
    773 // from bin k of sigmabar to bin j
    774 //
    775 
    776 Bool_t MPad::MergeONMC(
    777    TH2D *sigthmc,  TH3D *diffpixthmc,  TH3D *sigmapixthmc,
    778    TH2D *blindidthmc,  TH2D *blindnthmc,
    779    TH2D *sigthon,  TH3D *diffpixthon,  TH3D *sigmapixthon,
    780    TH2D *blindidthon,  TH2D *blindnthon)
    781 {
    782   *fLog << all << "----------------------------------------------------------------------------------" << endl;
    783   *fLog << all << "MPad::MergeONMC(); Merge the ON  and MC histograms to obtain the target distributions for the padding"
    784         << endl;
    785 
    786   fHSigmaTheta = new TH2D( (TH2D&)*sigthon );
    787   fHSigmaTheta->SetNameTitle("2D-ThetaSigmabar", "2D-ThetaSigmabar (target)");
    788 
    789   fHDiffPixTheta = new TH3D( (TH3D&)*diffpixthon );
    790   fHDiffPixTheta->SetNameTitle("3D-ThetaPixDiff", "3D-ThetaPixDiff (target)");
    791 
    792   fHSigmaPixTheta = new TH3D( (TH3D&)*sigmapixthon );
    793   fHSigmaPixTheta->SetNameTitle("3D-ThetaPixSigma", "3D-ThetaPixSigma (target)");
    794 
    795   fHBlindPixNTheta = new TH2D( (TH2D&)*blindnthon );
    796   fHBlindPixNTheta->SetNameTitle("2D-ThetaBlindN", "2D-ThetaBlindN (target)");
    797 
    798   fHBlindPixIdTheta = new TH2D( (TH2D&)*blindidthon );
    799   fHBlindPixIdTheta->SetNameTitle("2D-ThetaBlindId", "2D-ThetaBlindId (target)");
    800 
    801   //--------------------------
    802   fHSigmaThetaMC = sigthmc;
    803   fHSigmaThetaMC->SetNameTitle("2D-ThetaSigmabarMC", "2D-ThetaSigmabarMC (orig.)");
    804   fHSigmaThetaON = sigthon;
    805   fHSigmaThetaON->SetNameTitle("2D-ThetaSigmabarON", "2D-ThetaSigmabarON (orig.)");
    806 
    807   //--------------------------
    808   fHBlindPixNThetaMC = blindnthmc;
    809   fHBlindPixNThetaMC->SetNameTitle("2D-ThetaBlindNMC", "2D-ThetaBlindNMC (orig.)");
    810   fHBlindPixNThetaON = blindnthon;
    811   fHBlindPixNThetaON->SetNameTitle("2D-ThetaBlindNON", "2D-ThetaBlindNON (orig.)");
    812 
    813   //--------------------------
    814   fHBlindPixIdThetaMC = blindidthmc;
    815   fHBlindPixIdThetaMC->SetNameTitle("2D-ThetaBlindIdMC", "2D-ThetaBlindIdMC (orig.)");
    816   fHBlindPixIdThetaON = blindidthon;
    817   fHBlindPixIdThetaON->SetNameTitle("2D-ThetaBlindIdON", "2D-ThetaBlindIdON (orig.)");
    818 
    819   //--------------------------
    820   fHDiffPixThetaMC = diffpixthmc;
    821   fHDiffPixThetaMC->SetNameTitle("3D-ThetaPixDiffMC", "3D-ThetaPixDiffMC (orig.)");
    822   fHDiffPixThetaON = diffpixthon;
    823   fHDiffPixThetaON->SetNameTitle("3D-ThetaPixDiffON", "3D-ThetaPixDiffON (orig.)");
    824 
    825   //--------------------------
    826   fHSigmaPixThetaMC = sigmapixthmc;
    827   fHSigmaPixThetaMC->SetNameTitle("3D-ThetaPixSigmaMC", "3D-ThetaPixSigmaMC (orig.)");
    828   fHSigmaPixThetaON = sigmapixthon;
    829   fHSigmaPixThetaON->SetNameTitle("3D-ThetaPixSigmaON", "3D-ThetaPixSigmaON (orig.)");
    830 
    831   //--------------------------
    832 
    833 
    834   // get binning for fHgON and fHgMC  from sigthon
    835   // binning in Theta
    836   TAxis *ax = sigthon->GetXaxis();
    837   Int_t nbinstheta = ax->GetNbins();
    838   TArrayD edgesx;
    839   edgesx.Set(nbinstheta+1);
    840   for (Int_t i=0; i<=nbinstheta; i++)
    841   {
    842     edgesx[i] = ax->GetBinLowEdge(i+1);
    843     *fLog << all << "i, theta low edge = " << i << ",  " << edgesx[i]
    844           << endl;
    845   }
    846   MBinning binth;
    847   binth.SetEdges(edgesx);
    848 
    849   // binning in sigmabar
    850   TAxis *ay = sigthon->GetYaxis();
    851   Int_t nbinssig = ay->GetNbins();
    852   TArrayD edgesy;
    853   edgesy.Set(nbinssig+1);
    854   for (Int_t i=0; i<=nbinssig; i++)
    855   {
    856     edgesy[i] = ay->GetBinLowEdge(i+1);
    857     *fLog << all << "i, sigmabar low edge = " << i << ",  " << edgesy[i]
    858           << endl;
    859   }
    860   MBinning binsg;
    861   binsg.SetEdges(edgesy);
    862 
    863 
    864   fHgMC = new TH3D;
    865   MH::SetBinning(fHgMC, &binth, &binsg, &binsg);
    866   fHgMC->SetNameTitle("3D-PaddingMatrixMC", "3D-PadMatrixThetaMC");
    867 
    868   fHgON = new TH3D;
    869   MH::SetBinning(fHgON, &binth, &binsg, &binsg);
    870   fHgON->SetNameTitle("3D-PaddingMatrixON", "3D-PadMatrixThetaON");
    871 
    8721097
    8731098  //............   loop over Theta bins   ...........................
     
    8931118    //                    padded from bin k to bin j
    8941119
    895     TH1D *hista  = sigthon->ProjectionY("sigon_y", l, l, "");
     1120    TH1D *hista  = sigthon.ProjectionY("sigon_y", l, l, "");
    8961121    Stat_t suma = hista->Integral();
    897     hista->Scale(1./suma);
     1122    if (suma != 0.0) hista->Scale(1./suma);
    8981123
    8991124    TH1D *histap  = new TH1D( (const TH1D&)*hista );
    9001125
    901     TH1D *histb  = sigthmc->ProjectionY("sigmc_y", l, l, "");
     1126    TH1D *histb  = sigthmc.ProjectionY("sigmc_y", l, l, "");
    9021127    Stat_t sumb = histb->Integral();
    903     histb->Scale(1./sumb);
     1128    if (sumb != 0.0) histb->Scale(1./sumb);
    9041129
    9051130    Merge2Distributions(hista, histb, histap, fHga, fHgb, nbinssig);
     
    9581183
    9591184    // set ranges for 2D-projections of 3D-histograms
    960     TAxis *ax = diffpixthon->GetXaxis();
     1185    TAxis *ax = diffpixthon.GetXaxis();
    9611186    ax->SetRange(j, j);
    962     ax = diffpixthmc->GetXaxis();
     1187    ax = diffpixthmc.GetXaxis();
    9631188    ax->SetRange(j, j);
    9641189
     
    9801205    //------------------------------------------------------------------
    9811206    // define target distribution  'sigma^2-sigmavar^2 vs. pixel number'
    982     ay = diffpixthon->GetYaxis();
     1207    ay = diffpixthon.GetYaxis();
    9831208    Int_t nbinspixel = ay->GetNbins();
    9841209
    985     TAxis *az = diffpixthon->GetZaxis();
     1210    TAxis *az = diffpixthon.GetZaxis();
    9861211    Int_t nbinsdiff = az->GetNbins();
    9871212
    988     hist    = (TH2D*)diffpixthon->Project3D("zy");
     1213    hist    = (TH2D*)diffpixthon.Project3D("zy");
    9891214    hist->SetName("dummy");
    990     histMC = (TH2D*)diffpixthmc->Project3D("zy");
     1215    histMC = (TH2D*)diffpixthmc.Project3D("zy");
    9911216
    9921217    normON  = hist->Integral();
     
    10111236    //------------------------------------------------------------------
    10121237    // define target distribution  'sigma vs. pixel number'
    1013     ay = sigmapixthon->GetYaxis();
     1238    ay = sigmapixthon.GetYaxis();
    10141239    nbinspixel = ay->GetNbins();
    10151240
    1016     az = sigmapixthon->GetZaxis();
     1241    az = sigmapixthon.GetZaxis();
    10171242    Int_t nbinssigma = az->GetNbins();
    10181243
    1019     hist    = (TH2D*)sigmapixthon->Project3D("zy");
     1244    hist    = (TH2D*)sigmapixthon.Project3D("zy");
    10201245    hist->SetName("dummy");
    1021     histMC = (TH2D*)sigmapixthmc->Project3D("zy");
     1246    histMC = (TH2D*)sigmapixthmc.Project3D("zy");
    10221247
    10231248    normON  = hist->Integral();
    10241249    normMC = histMC->Integral();
    10251250    if (normON  != 0.0) hist->Scale(1.0/normON);
    1026     if (normMC != 0.0) histMC->Scale(1.0/normMC);
     1251    if (normMC  != 0.0) histMC->Scale(1.0/normMC);
    10271252
    10281253    // weighted average of ON and MC distributions
     
    10431268    //------------------------------------------------------------------
    10441269    // define target distribution  'number of blind pixels per event'
    1045     ay = blindnthon->GetYaxis();
     1270    ay = blindnthon.GetYaxis();
    10461271    Int_t nbinsn = ay->GetNbins();
    10471272
     
    10531278    normMC  = hist1MC->Integral();
    10541279    if (normON  != 0.0) hist1->Scale(1.0/normON);
    1055     if (normMC != 0.0) hist1MC->Scale(1.0/normMC);
     1280    if (normMC  != 0.0) hist1MC->Scale(1.0/normMC);
    10561281
    10571282    // sum of ON and MC distributions
    10581283    hist1->Add(hist1MC, 1.0);
    1059     hist1->Scale( 1.0/hist1->Integral() );
     1284    Stat_t sum1 = hist1->Integral();
     1285    if (sum1 != 0.0) hist1->Scale( 1.0/sum1 );
    10601286
    10611287    for (Int_t k=1; k<=nbinsn; k++)
     
    10701296    //------------------------------------------------------------------
    10711297    // define target distribution  'id of blind pixel'
    1072     ay = blindidthon->GetYaxis();
     1298    ay = blindidthon.GetYaxis();
    10731299    Int_t nbinsid = ay->GetNbins();
    10741300
     
    10791305    // divide by the number of events (from fHBlindPixNTheta)
    10801306    if (normON  != 0.0) hist1->Scale(1.0/normON);
    1081     if (normMC != 0.0) hist1MC->Scale(1.0/normMC);
     1307    if (normMC  != 0.0) hist1MC->Scale(1.0/normMC);
    10821308
    10831309    // sum of ON and MC distributions
     
    11381364
    11391365    //------------------------------------
     1366 
     1367      /*
    11401368      fHSigmaThetaMC =
    11411369      (TH2D*) gROOT->FindObject("2D-ThetaSigmabarMC");
     
    11471375          return kFALSE;
    11481376        }
     1377      */ 
     1378      fHSigmaThetaMC = new TH2D;
     1379      fHSigmaThetaMC->Read("2D-ThetaSigmabarMC");
    11491380      *fLog << all
    11501381            << "MPad : Object '2D-ThetaSigmabarMC' was read in" << endl;
    11511382
     1383      /*
    11521384      fHSigmaThetaON =
    11531385      (TH2D*) gROOT->FindObject("2D-ThetaSigmabarON");
     
    11591391          return kFALSE;
    11601392        }
     1393      */
     1394      fHSigmaThetaON = new TH2D;
     1395      fHSigmaThetaON->Read("2D-ThetaSigmabarON");
    11611396      *fLog << all
    11621397            << "MPad : Object '2D-ThetaSigmabarON' was read in" << endl;
    11631398
     1399      /*
    11641400      fHSigmaThetaOFF =
    11651401      (TH2D*) gROOT->FindObject("2D-ThetaSigmabarOFF");
     
    11711407          return kFALSE;
    11721408        }
     1409      */
     1410      fHSigmaThetaOFF = new TH2D;
     1411      fHSigmaThetaOFF->Read("2D-ThetaSigmabarOFF");
    11731412      *fLog << all
    11741413            << "MPad:Object '2D-ThetaSigmabarOFF' was read in" << endl;
    11751414
    11761415    //------------------------------------
     1416      /*
    11771417      fHDiffPixTheta =
    11781418      (TH3D*) gROOT->FindObject("3D-ThetaPixDiff");
     
    11841424          return kFALSE;
    11851425        }
     1426      */
     1427      fHDiffPixTheta = new TH3D;
     1428      fHDiffPixTheta->Read("3D-ThetaPixDiff");
    11861429      *fLog << all
    11871430            << "MPad : Object '3D-ThetaPixDiff' was read in" << endl;
    11881431
     1432      /*
    11891433      fHDiffPixThetaMC =
    11901434      (TH3D*) gROOT->FindObject("3D-ThetaPixDiffMC");
     
    11961440          return kFALSE;
    11971441        }
     1442      */
     1443      fHDiffPixThetaMC = new TH3D;
     1444      fHDiffPixThetaMC->Read("3D-ThetaPixDiffMC");
    11981445      *fLog << all
    11991446            << "MPad : Object '3D-ThetaPixDiffMC' was read in" << endl;
    12001447
     1448      /*
    12011449      fHDiffPixThetaON =
    12021450      (TH3D*) gROOT->FindObject("3D-ThetaPixDiffON");
     
    12081456          return kFALSE;
    12091457        }
     1458      */
     1459      fHDiffPixThetaON = new TH3D;
     1460      fHDiffPixThetaON->Read("3D-ThetaPixDiffON");
    12101461      *fLog << all
    12111462            << "MPad : Object '3D-ThetaPixDiffON' was read in" << endl;
    12121463
     1464      /*
    12131465      fHDiffPixThetaOFF =
    12141466      (TH3D*) gROOT->FindObject("3D-ThetaPixDiffOFF");
     
    12201472          return kFALSE;
    12211473        }
     1474      */
     1475      fHDiffPixThetaOFF = new TH3D;
     1476      fHDiffPixThetaOFF->Read("3D-ThetaPixDiffOFF");
    12221477      *fLog << all
    12231478            << "MPad : Object '3D-ThetaPixDiffOFF' was read in" << endl;
     
    12251480
    12261481    //------------------------------------
     1482      /*
    12271483       fHSigmaPixTheta =
    12281484      (TH3D*) gROOT->FindObject("3D-ThetaPixSigma");
     
    12341490          return kFALSE;
    12351491        }
     1492      */
     1493      fHSigmaPixTheta = new TH3D;
     1494      fHSigmaPixTheta->Read("3D-ThetaPixSigma");
    12361495      *fLog << all
    12371496            << "MPad : Object '3D-ThetaPixSigma' was read in" << endl;
    12381497
     1498      /*
    12391499       fHSigmaPixThetaMC =
    12401500      (TH3D*) gROOT->FindObject("3D-ThetaPixSigmaMC");
     
    12461506          return kFALSE;
    12471507        }
     1508      */
     1509      fHSigmaPixThetaMC = new TH3D;
     1510      fHSigmaPixThetaMC->Read("3D-ThetaPixSigmaMC");
    12481511      *fLog << all
    12491512            << "MPad : Object '3D-ThetaPixSigmaMC' was read in" << endl;
    12501513
     1514      /*
    12511515      fHSigmaPixThetaON =
    12521516      (TH3D*) gROOT->FindObject("3D-ThetaPixSigmaON");
     
    12581522          return kFALSE;
    12591523        }
     1524      */
     1525      fHSigmaPixThetaON = new TH3D;
     1526      fHSigmaPixThetaON->Read("3D-ThetaPixSigmaON");
    12601527      *fLog << all
    12611528            << "MPad : Object '3D-ThetaPixSigmaON' was read in" << endl;
    12621529
     1530      /*
    12631531      fHSigmaPixThetaOFF =
    12641532      (TH3D*) gROOT->FindObject("3D-ThetaPixSigmaOFF");
     
    12701538          return kFALSE;
    12711539        }
     1540      */
     1541      fHSigmaPixThetaOFF = new TH3D;
     1542      fHSigmaPixThetaOFF->Read("3D-ThetaPixSigmaOFF");
    12721543      *fLog << all
    12731544            << "MPad : Object '3D-ThetaPixSigmaOFF' was read in" << endl;
    12741545
    12751546    //------------------------------------
     1547      /*
    12761548      fHgMC =
    12771549      (TH3D*) gROOT->FindObject("3D-PaddingMatrixMC");
     
    12831555          return kFALSE;
    12841556        }
     1557      */
     1558      fHgMC = new TH3D;
     1559      fHgMC->Read("3D-PaddingMatrixMC");
    12851560      *fLog << all
    12861561            << "MPad : Object '3D-PaddingMatrixMC' was read in" << endl;
    12871562
     1563      /*
    12881564      fHgON =
    12891565      (TH3D*) gROOT->FindObject("3D-PaddingMatrixON");
     
    12951571          return kFALSE;
    12961572        }
     1573      */
     1574      fHgON = new TH3D;
     1575      fHgON->Read("3D-PaddingMatrixON");
    12971576      *fLog << all
    12981577            << "MPad : Object '3D-PaddingMatrixON' was read in" << endl;
    12991578
     1579      /*
    13001580      fHgOFF =
    13011581      (TH3D*) gROOT->FindObject("3D-PaddingMatrixOFF");
     
    13071587          return kFALSE;
    13081588        }
     1589      */
     1590      fHgOFF = new TH3D;
     1591      fHgOFF->Read("3D-PaddingMatrixOFF");
    13091592      *fLog << all
    13101593            << "MPad : Object '3D-PaddingMatrixOFF' was read in" << endl;
    13111594
    13121595    //------------------------------------
     1596      /*
     1597      fHBlindPixIdTheta =
     1598      (TH2D*) gROOT->FindObject("2D-ThetaBlindId");
     1599      if (!fHBlindPixIdTheta)
     1600        {
     1601          *fLog << all
     1602                << "MPad : Object '2D-ThetaBlindId' not found on root file"
     1603                << endl;
     1604          return kFALSE;
     1605        }
     1606      */
     1607      fHBlindPixIdTheta = new TH2D;
     1608      fHBlindPixIdTheta->Read("2D-ThetaBlindId");
     1609      *fLog << all
     1610            << "MPad : Object '2D-ThetaBlindId' was read in" << endl;
     1611
     1612      /*
    13131613      fHBlindPixIdThetaMC =
    13141614      (TH2D*) gROOT->FindObject("2D-ThetaBlindIdMC");
     
    13201620          return kFALSE;
    13211621        }
     1622      */
     1623      fHBlindPixIdThetaMC = new TH2D;
     1624      fHBlindPixIdThetaMC->Read("2D-ThetaBlindIdMC");
    13221625      *fLog << all
    13231626            << "MPad : Object '2D-ThetaBlindIdMC' was read in" << endl;
    13241627
     1628      /*
    13251629      fHBlindPixIdThetaON =
    13261630      (TH2D*) gROOT->FindObject("2D-ThetaBlindIdON");
     
    13321636          return kFALSE;
    13331637        }
     1638      */
     1639      fHBlindPixIdThetaON = new TH2D;
     1640      fHBlindPixIdThetaON->Read("2D-ThetaBlindIdON");
    13341641      *fLog << all
    13351642            << "MPad : Object '2D-ThetaBlindIdON' was read in" << endl;
    13361643
     1644      /*
    13371645      fHBlindPixIdThetaOFF =
    13381646      (TH2D*) gROOT->FindObject("2D-ThetaBlindIdOFF");
     
    13441652          return kFALSE;
    13451653        }
     1654      */
     1655      fHBlindPixIdThetaOFF = new TH2D;
     1656      fHBlindPixIdThetaOFF->Read("2D-ThetaBlindIdOFF");
    13461657      *fLog << all
    1347             << "MPad : Object '2D-ThetaBlindIdMC' was read in" << endl;
     1658            << "MPad : Object '2D-ThetaBlindIdOFF' was read in" << endl;
    13481659
    13491660    //------------------------------------
     1661      /*
     1662      fHBlindPixNTheta =
     1663      (TH2D*) gROOT->FindObject("2D-ThetaBlindN");
     1664      if (!fHBlindPixNTheta)
     1665        {
     1666          *fLog << all
     1667                << "MPad : Object '2D-ThetaBlindN' not found on root file"
     1668                << endl;
     1669          return kFALSE;
     1670        }
     1671      */
     1672      fHBlindPixNTheta = new TH2D;
     1673      fHBlindPixNTheta->Read("2D-ThetaBlindN");
     1674      *fLog << all
     1675            << "MPad : Object '2D-ThetaBlindN' was read in" << endl;
     1676
     1677      /*
    13501678      fHBlindPixNThetaMC =
    13511679      (TH2D*) gROOT->FindObject("2D-ThetaBlindNMC");
     
    13571685          return kFALSE;
    13581686        }
     1687      */
     1688      fHBlindPixNThetaMC = new TH2D;
     1689      fHBlindPixNThetaMC->Read("2D-ThetaBlindNMC");
    13591690      *fLog << all
    13601691            << "MPad : Object '2D-ThetaBlindNMC' was read in" << endl;
    13611692
     1693      /*
    13621694      fHBlindPixNThetaON =
    13631695      (TH2D*) gROOT->FindObject("2D-ThetaBlindNON");
     
    13691701          return kFALSE;
    13701702        }
     1703      */
     1704      fHBlindPixNThetaON = new TH2D;
     1705      fHBlindPixNThetaON->Read("2D-ThetaBlindNON");
    13711706      *fLog << all
    13721707            << "MPad : Object '2D-ThetaBlindNON' was read in" << endl;
    13731708
     1709      /*
    13741710      fHBlindPixNThetaOFF =
    13751711      (TH2D*) gROOT->FindObject("2D-ThetaBlindNOFF");
     
    13811717          return kFALSE;
    13821718        }
     1719      */
     1720      fHBlindPixNThetaOFF = new TH2D;
     1721      fHBlindPixNThetaOFF->Read("2D-ThetaBlindNOFF");
    13831722      *fLog << all
    13841723            << "MPad : Object '2D-ThetaBlindNOFF' was read in" << endl;
     
    14021741  TFile outfile(namefileout, "RECREATE");
    14031742
     1743  fHBlindPixNTheta->Write();
    14041744  fHBlindPixNThetaMC->Write();
    14051745  fHBlindPixNThetaON->Write();
    14061746  fHBlindPixNThetaOFF->Write();
    14071747
     1748  fHBlindPixIdTheta->Write();
    14081749  fHBlindPixIdThetaMC->Write();
    14091750  fHBlindPixIdThetaON->Write();
     
    14701811  }
    14711812
    1472   fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
    1473   if (!fMcEvt)
     1813  fPointPos = (MPointingPos*)pList->FindObject("MPointingPos");
     1814  if (!fPointPos)
    14741815    {
    1475        *fLog << err << dbginf << "MPad : MMcEvt not found... aborting."
     1816       *fLog << err << dbginf << "MPad : MPointingPos not found... aborting."
    14761817             << endl;
    14771818       return kFALSE;
    1478      }
     1819    }
    14791820 
    14801821   fPed = (MPedPhotCam*)pList->FindObject("MPedPhotCam");
     
    15101851     }
    15111852
    1512    fBlinds = (MBlindPixels*)pList->FindCreateObj("MBlindPixels");
    1513    if (!fBlinds)
     1853   fBlindPix = (MBlindPixels*)pList->FindCreateObj("MBlindPixels");
     1854   if (!fBlindPix)
    15141855     {
    15151856       *fLog << err << "MPad : MBlindPixels not found... aborting."
     
    15321873   // plot pedestal sigmas
    15331874   fHSigmaPedestal = new TH2D("SigPed","Sigma: after vs. before padding",
    1534                      100, 0.0, 5.0, 100, 0.0, 5.0);
     1875                     100, 0.0, 75.0, 100, 0.0, 75.0);
    15351876   fHSigmaPedestal->SetXTitle("Pedestal sigma before padding");
    15361877   fHSigmaPedestal->SetYTitle("Pedestal sigma after padding");
     
    15381879   // plot no.of photons (before vs. after padding)
    15391880   fHPhotons = new TH2D("Photons","Photons: after vs.before padding",
    1540                         100, -10.0, 90.0, 100, -10, 90);
     1881                        100, -100.0, 300.0, 100, -100, 300);
    15411882   fHPhotons->SetXTitle("no.of photons before padding");
    15421883   fHPhotons->SetYTitle("no.of photons after padding");
    15431884
    15441885   // plot of added NSB
    1545    fHNSB = new TH1D("NSB","Distribution of added NSB", 100, -10.0, 10.0);
     1886   fHNSB = new TH1D("NSB","Distribution of added NSB", 100, -100.0, 200.0);
    15461887   fHNSB->SetXTitle("no.of added NSB photons");
    15471888   fHNSB->SetYTitle("no.of pixels");
     
    15501891   //--------------------------------------------------------------------
    15511892
    1552    fIter = 20;
     1893   fIter = 10;
    15531894
    15541895   memset(fErrors,   0, sizeof(fErrors));
     
    15701911Int_t MPad::Process()
    15711912{
    1572   *fLog << all << "Entry MPad::Process();" << endl;
     1913  //*fLog << all << "Entry MPad::Process();" << endl;
    15731914
    15741915  // this is the conversion factor from the number of photons
     
    15761917  // later to be taken from MCalibration
    15771918  // fPEperPhoton = PW * LG * QE * 1D
    1578   Double_t fPEperPhoton = 0.95 * 0.90 * 0.13 * 0.9;
     1919  Double_t fPEperPhoton = 0.92 * 0.94 * 0.23 * 0.9;
    15791920
    15801921  //------------------------------------------------
    1581   // add pixels to MCerPhotEvt which are not yet in;
    1582   // set their number of photons equal to zero
    1583 
     1922  // Add pixels to MCerPhotEvt which are not yet in;
     1923  // set their number of photons equal to zero.
     1924  // Purpose : by the padding the number of photons is changed
     1925  // so that cleaning and cuts may be affected.
     1926  // However, no big effect is expectec unless the padding is strong
     1927  // (strong increase of the noise level)
     1928  // At present comment out this code
     1929
     1930  /*
    15841931  UInt_t imaxnumpix = fCam->GetNumPixels();
    15851932
     
    16031950    fEvt->AddPixel(i, 0.0, (*fPed)[i].GetRms());
    16041951  }
    1605 
     1952  */
    16061953
    16071954
     
    16151962  // Calculate average sigma of the event
    16161963  //
    1617   Double_t sigbarold_phot = fSigmabar->Calc(*fCam, *fPed, *fEvt);
    1618   *fLog << all << "MPad::Process(); before padding : " << endl;
    1619   fSigmabar->Print("");
    1620   Double_t sigbarold  = sigbarold_phot * fPEperPhoton;
    1621   Double_t sigbarold2 = sigbarold*sigbarold;
    1622 
    1623   const Double_t theta = kRad2Deg*fMcEvt->GetTelescopeTheta();
    1624   *fLog << all << "theta = " << theta << endl;
     1964
     1965  fSigmabar->Calc(*fCam, *fPed, *fEvt);
     1966  //*fLog << all << "MPad::Process(); before padding : " << endl;
     1967  //fSigmabar->Print("");
     1968
     1969  // inner sigmabar/sqrt(area)
     1970  Double_t sigbarInnerold_phot = fSigmabar->GetSigmabarInner();
     1971  Double_t sigbarInnerold  = sigbarInnerold_phot * fPEperPhoton;
     1972  Double_t sigbarInnerold2 = sigbarInnerold*sigbarInnerold;
     1973
     1974  // outer sigmabar/sqrt(area)
     1975  Double_t sigbarOuterold_phot = fSigmabar->GetSigmabarOuter();
     1976  Double_t sigbarOuterold  = sigbarOuterold_phot * fPEperPhoton;
     1977  Double_t sigbarOuterold2 = sigbarOuterold*sigbarOuterold;
     1978
     1979  const Double_t theta = fPointPos->GetZd();
     1980
     1981  //*fLog << all << "theta = " << theta << endl;
    16251982
    16261983  Int_t binTheta = fHBlindPixNTheta->GetXaxis()->FindBin(theta);
     
    16291986    *fLog << warn
    16301987          << "MPad::Process(); binNumber out of range : theta, binTheta = "
    1631           << theta << ",  " << binTheta << ";  Skip event " << endl;
    1632     // event cannot be padded; skip event
     1988          << theta << ",  " << binTheta << ";  aborting " << endl;
    16331989
    16341990    rc = 2;
     
    16371993  }
    16381994
     1995  //*fLog << all << "binTheta = " << binTheta << endl;
     1996 
     1997
    16391998  //-------------------------------------------
    16401999  // get number of events in this theta bin
    1641   // and number of events in this sigbarold_phot bin
     2000  // and number of events in this sigbarInnerold_phot bin
    16422001
    16432002  Double_t nTheta;
     
    16572016  TH1D *hn;
    16582017  hn = st->ProjectionY("", binTheta, binTheta, "");
     2018
     2019  //*fLog << "Title of histogram : " << st->GetTitle() << endl;
     2020  //for (Int_t i=1; i<=hn->GetNbinsX(); i++)
     2021  //{
     2022  //  *fLog << "bin " << i << " : no.of entries = " << hn->GetBinContent(i)
     2023  //        << endl;
     2024  //}
     2025
    16592026  nTheta = hn->Integral();
    1660   Int_t binSigma = hn->FindBin(sigbarold_phot);
     2027  Int_t binSigma = hn->FindBin(sigbarInnerold_phot);
    16612028  nSigma = hn->GetBinContent(binSigma);
    16622029
    1663    *fLog << all           
    1664          << "Theta, sigbarold_phot, binTheta, binSigma, nTheta, nSigma = "
    1665          << theta << ",  " << sigbarold_phot << ",  " << binTheta << ",  "
    1666          << binSigma << ",  " << nTheta << ",  " << nSigma   << endl;     
     2030  //*fLog << all           
     2031  //       << "Theta, sigbarold_phot, binTheta, binSigma, nTheta, nSigma = "
     2032  //       << theta << ",  " << sigbarInnerold_phot << ",  " << binTheta
     2033  //       << ",  "
     2034  //       << binSigma << ",  " << nTheta << ",  " << nSigma   << endl;     
    16672035
    16682036  delete hn;
    1669  
    1670 
     2037 
    16712038  //-------------------------------------------
    16722039  // for the current theta :
     
    16882055    if ( nblind->Integral() == 0.0 )
    16892056    {
    1690       *fLog << warn << "MPad::Process(); projection for Theta bin "
    1691             << binTheta << " has no entries; Skip event " << endl;
     2057      *fLog << warn << "MPad::Process(); projection of '"
     2058            << fHBlindPixNThetaOFF->GetName() << "' for Theta bin "
     2059            << binTheta << " has no entries; aborting " << endl;
    16922060      // event cannot be padded; skip event
    16932061      delete nblind;
     
    17322100          nlist++;
    17332101
    1734           fBlinds->SetPixelBlind(idBlind);
    1735           *fLog << all << "idBlind = " << idBlind << endl;
     2102          fBlindPix->SetPixelBlind(idBlind);
     2103          //*fLog << all << "idBlind = " << idBlind << endl;
    17362104        }
    1737       fBlinds->SetReadyToSave();
     2105      fBlindPix->SetReadyToSave();
    17382106
    17392107      delete hblind;
     
    17522120    if ( nblind->Integral() == 0.0 )
    17532121    {
    1754       *fLog << warn << "MPad::Process(); projection for Theta bin "
     2122      *fLog << warn << "MPad::Process(); projection of '"
     2123            << fHBlindPixNThetaON->GetName() << "' for Theta bin "
    17552124            << binTheta << " has no entries; Skip event " << endl;
    1756       // event cannot be padded; skip event
    17572125      delete nblind;
    17582126
     
    17962164          nlist++;
    17972165
    1798           fBlinds->SetPixelBlind(idBlind);
    1799           *fLog << all << "idBlind = " << idBlind << endl;
     2166          fBlindPix->SetPixelBlind(idBlind);
     2167          //*fLog << all << "idBlind = " << idBlind << endl;
    18002168        }
    1801       fBlinds->SetReadyToSave();
     2169      fBlindPix->SetReadyToSave();
    18022170
    18032171      delete hblind;
     
    18102178  //
    18112179
    1812   Int_t binSig = fHgON->GetYaxis()->FindBin(sigbarold_phot);
    1813   *fLog << all << "binSig, sigbarold_phot = " << binSig << ",  "
    1814           << sigbarold_phot << endl;
     2180  Int_t binSig = fHgON->GetYaxis()->FindBin(sigbarInnerold_phot);
     2181  //*fLog << all << "binSig, sigbarInnerold_phot = " << binSig << ",  "
     2182  //        << sigbarInnerold_phot << endl;
    18152183
    18162184  Double_t prob;
     
    18432211    prob = 0.0;
    18442212
    1845    *fLog << all << "nTheta, nSigma, prob = " << nTheta << ",  " << nSigma
    1846          << ",  " << prob << endl;
     2213  //*fLog << all << "nTheta, nSigma, prob = " << nTheta << ",  " << nSigma
     2214  //       << ",  " << prob << endl;
    18472215
    18482216  if ( prob <= 0.0  ||  gRandom->Uniform() > prob )
     
    18502218    delete hpad;
    18512219    // event should not be padded
    1852     *fLog << all << "event is not padded" << endl;
     2220    //*fLog << all << "event is not padded" << endl;
    18532221
    18542222    rc = 8;
     
    18572225  }
    18582226  // event should be padded
    1859   *fLog << all << "event will be padded" << endl; 
     2227  //*fLog << all << "event will be padded" << endl; 
    18602228
    18612229
     
    18642232  //     for MC/ON/OFF data according to the matrix fHgMC/ON/OFF
    18652233  //
    1866   Double_t sigmabar_phot = 0;
    1867   Double_t sigmabar      = 0;
     2234  Double_t sigmabarInner_phot = 0;
     2235  Double_t sigmabarInner      = 0;
    18682236
    18692237 
     
    18762244  //}
    18772245
    1878   sigmabar_phot = hpad->GetRandom();
    1879   sigmabar = sigmabar_phot * fPEperPhoton;
    1880 
    1881   *fLog << all << "sigmabar_phot = " << sigmabar_phot << endl;
     2246  sigmabarInner_phot = hpad->GetRandom();
     2247  sigmabarInner = sigmabarInner_phot * fPEperPhoton;
     2248
     2249  //*fLog << all << "sigmabarInner_phot = " << sigmabarInner_phot << endl;
    18822250
    18832251  delete hpad;
    18842252 
    1885   const Double_t sigmabar2 = sigmabar*sigmabar;
     2253  // new inner sigmabar2/area
     2254  const Double_t sigmabarInner2 = sigmabarInner*sigmabarInner;
    18862255
    18872256  //-------------------------------------------
    18882257
    1889   *fLog << all << "MPad::Process(); sigbarold, sigmabar = "
    1890         << sigbarold << ",  "<< sigmabar << endl;
    1891 
    1892   // Skip event if target sigmabar is <= sigbarold
    1893   if (sigmabar <= sigbarold)
     2258  //*fLog << all << "MPad::Process(); sigbarInnerold, sigmabarInner = "
     2259  //      << sigbarInnerold << ",  "<< sigmabarInner << endl;
     2260
     2261  // Stop if target sigmabar is <= sigbarold
     2262  if (sigmabarInner <= sigbarInnerold)
    18942263  {
    1895     *fLog << all << "MPad::Process(); target sigmabar is less than sigbarold : "
    1896           << sigmabar << ",  " << sigbarold << ",   Skip event" << endl;
     2264    *fLog << all << "MPad::Process(); target sigmabarInner is less than sigbarInnerold : "
     2265          << sigmabarInner << ",  " << sigbarInnerold << ",   aborting"
     2266          << endl;
    18972267
    18982268    rc = 4;
     
    19232293  }
    19242294
    1925   // Get RMS of (Sigma^2-sigmabar^2) in this Theta bin.
    1926   // The average electronic noise (to be added) has to be well above this RMS,
    1927   // otherwise the electronic noise of an individual pixel (elNoise2Pix)
    1928   // may become negative
     2295  // In this Theta bin, get RMS of (Sigma^2-sigmabar^2) for inner pixels
     2296  // The average electronic noise (to be added) has to be in the order of
     2297  // this RMS, otherwise the electronic noise of an individual pixel
     2298  // (elNoise2Pix) may become negative
     2299
     2300  // Attention : maximum ID of inner pixels hard coded !!!
     2301  Int_t idmaxpixinner = 396;
     2302  Int_t binmaxpixinner =
     2303        fHDiffPixTheta->GetYaxis()->FindBin( (Double_t)idmaxpixinner );
    19292304
    19302305  TH1D *hnoise;
    19312306  if (fType == "MC")
    1932     hnoise = fHDiffPixTheta->ProjectionZ("", binTheta, binTheta, 0, 9999, "");
     2307    hnoise = fHDiffPixTheta->ProjectionZ("", binTheta, binTheta, 0, binmaxpixinner, "");
    19332308  else if (fType == "ON")
    1934     hnoise = fHDiffPixThetaOFF->ProjectionZ("", binTheta, binTheta, 0, 9999, "");
     2309    hnoise = fHDiffPixThetaOFF->ProjectionZ("", binTheta, binTheta, 0, binmaxpixinner, "");
    19352310  else if (fType == "OFF")
    1936     hnoise = fHDiffPixThetaON->ProjectionZ("", binTheta, binTheta, 0, 9999, "");
     2311    hnoise = fHDiffPixThetaON->ProjectionZ("", binTheta, binTheta, 0, binmaxpixinner, "");
    19372312  else
    19382313  {
     
    19462321  delete hnoise;
    19472322
    1948   elNoise2 = TMath::Min(RMS,  sigmabar2 - sigbarold2);
    1949   *fLog << all << "elNoise2 = " << elNoise2 << endl;
    1950 
    1951   lambdabar = (sigmabar2 - sigbarold2 - elNoise2) / F2excess; 
     2323  elNoise2 = TMath::Min(2.0*RMS,  sigmabarInner2 - sigbarInnerold2);
     2324  //*fLog << all << "elNoise2 = " << elNoise2 << endl;
     2325
     2326  lambdabar = (sigmabarInner2 - sigbarInnerold2 - elNoise2) / F2excess; 
    19522327
    19532328  // This value of lambdabar is the same for all pixels;
     
    19572332  // do the padding for each pixel
    19582333  //
    1959   // pad only pixels   - which are used (before image cleaning)
     2334  // pad only pixels   - which are used and not blind (before image cleaning)
    19602335  //
    19612336
     
    19712346
    19722347
     2348  // throw the Sigma for the pixels from the distribution fHDiffPixTheta
     2349  // MC  : from fHDiffPixTheta
     2350  // ON  : from fHDiffPixThetaOFF
     2351  // OFF : from fHDiffPixThetaON
     2352
     2353  TH3D *sp = NULL;
     2354
     2355  if      (fType == "MC")  sp = fHDiffPixTheta;
     2356  else if (fType == "ON")  sp = fHDiffPixThetaOFF;
     2357  else if (fType == "OFF") sp = fHDiffPixThetaON;
     2358  else
     2359  {
     2360    *fLog << err << "MPad::Process(); illegal data type... aborting"
     2361          << endl;
     2362    return kERROR;
     2363  }
     2364
     2365  Double_t sigbarold2;
     2366  Double_t sigmabar2;
     2367  Double_t sigmabarOuter2;
     2368
     2369
    19732370  for (UInt_t i=0; i<npix; i++)
    19742371  {   
     2372
    19752373    MCerPhotPix &pix = (*fEvt)[i];
    19762374    if ( !pix.IsPixelUsed() )
     
    19902388    Double_t ratioArea = 1.0 / fCam->GetPixRatio(j);
    19912389
     2390    if (ratioArea < 1.5)
     2391    {
     2392      sigbarold2 = sigbarInnerold2;
     2393      sigmabar2  = sigmabarInner2;
     2394    }
     2395    else
     2396    {
     2397      sigbarold2    = sigbarOuterold2;
     2398      //sigbarOuter2  = sigmabarInner2 * sigbarOuterold2 / sigbarInnerold2;
     2399      sigmabarOuter2  = sigmabarInner2 + (sigbarOuterold2 - sigbarInnerold2);
     2400      sigmabar2     = sigmabarOuter2;
     2401    }
     2402
    19922403    MPedPhotPix &ppix = (*fPed)[j];
     2404
     2405    if ( fBlindPix != NULL  &&  fBlindPix->IsBlind(j) )
     2406    {
     2407       // this should never occur, because blind pixels should have
     2408       // been set unused by MBlindPixelsCalc2::UnMap()
     2409       //*fLog << all << "MPad::Process; blind pixel found which is used, j = "
     2410       //       << j << "... go to next pixel." << endl;
     2411       continue;
     2412    }   
     2413
     2414    // count number of pixels treated
     2415    fWarnings[0]++;
     2416
     2417
    19932418    Double_t oldsigma_phot = ppix.GetRms();
    19942419    Double_t oldsigma = oldsigma_phot * fPEperPhoton;
    1995     Double_t oldsigma2 = oldsigma*oldsigma;
     2420    Double_t oldsigma2 = oldsigma*oldsigma / ratioArea;
    19962421
    19972422    //---------------------------------
     
    20052430    TH1D *hdiff;
    20062431
    2007     // throw the Sigma for this pixel from the distribution fHDiffPixTheta
    2008     // MC  : from fHDiffPixTheta
    2009     // ON  : from fHDiffPixThetaOFF
    2010     // OFF : from fHDiffPixThetaON
    2011 
    2012     TH3D *sp = NULL;
    2013 
    2014     if      (fType == "MC")  sp = fHDiffPixTheta;
    2015     else if (fType == "ON")  sp = fHDiffPixThetaOFF;
    2016     else if (fType == "OFF") sp = fHDiffPixThetaON;
    2017     else
    2018     {
    2019       *fLog << err << "MPad::Process(); illegal data type... aborting"
    2020             << endl;
    2021       return kERROR;
    2022     }
    2023 
    2024     hdiff = sp->ProjectionZ("", binTheta, binTheta,
    2025                                 binPixel, binPixel, "");
    2026 
    2027     if ( hdiff->GetEntries() == 0 )
    2028     {
    2029       *fLog << warn << "MPad::Process(); projection for Theta bin "
    2030             << binTheta << "  and pixel bin " << binPixel 
    2031             << " has no entries;  aborting " << endl;
    2032       delete hdiff;
    2033 
    2034       rc = 5;
    2035       fErrors[rc]++;
    2036       return kCONTINUE;     
    2037     }
    2038 
    2039     count = 0;
    2040     ok = kFALSE;
    2041     for (Int_t m=0; m<fIter; m++)
    2042     {
    2043       count += 1;
    2044       diff_phot = hdiff->GetRandom();
    2045       diff = diff_phot * fPEperPhoton * fPEperPhoton;
     2432
     2433     hdiff = sp->ProjectionZ("", binTheta, binTheta,
     2434                                 binPixel, binPixel, "");
     2435     Double_t integral =  hdiff->Integral();
     2436     // if there are no entries in hdiff, diff cannot be thrown
     2437     // in this case diff will be set to zero
     2438     if ( integral == 0 )
     2439     {
     2440       //*fLog << warn << "MPad::Process(); fType = " << fType
     2441       //      << ", projection of '"
     2442       //      << sp->GetName() << "' for Theta bin "
     2443       //      << binTheta << "  and pixel " << j 
     2444       //      << " has no entries; set diff equal to the old difference  "
     2445       //      << endl;
     2446
     2447       diff = TMath::Max(oldsigma2 - sigbarold2,
     2448                         lambdabar*F2excess + oldsigma2 - sigmabar2);
     2449
     2450       rc = 2;
     2451       fWarnings[rc]++;
     2452     }
     2453
     2454     // start of else -------------------
     2455     else
     2456     {
     2457       count = 0;
     2458       ok = kFALSE;
     2459       for (Int_t m=0; m<fIter; m++)
     2460       {
     2461         count += 1;
     2462         diff_phot = hdiff->GetRandom();
     2463
     2464         //*fLog << "after GetRandom : j, m, diff_phot = " << j << " : "
     2465         //      << m << ",  " << diff_phot << endl;
     2466
     2467         diff = diff_phot * fPEperPhoton * fPEperPhoton;
    20462468 
    2047      // the following condition ensures that elNoise2Pix > 0.0
    2048       if ( (diff + sigmabar2 - oldsigma2/ratioArea
    2049                                - lambdabar*F2excess) > 0.0 )
    2050       {
    2051         ok = kTRUE;
    2052         break;
    2053       }
    2054     }
    2055 
    2056     if (!ok)
    2057     {
    2058       *fLog << all << "theta, j, count, sigmabar, diff = " << theta
    2059             << ",  "
    2060             << j << ",  " << count << ",  " << sigmabar << ",  "
    2061             << diff << endl;
    2062       diff = lambdabar*F2excess + oldsigma2/ratioArea - sigmabar2;
    2063 
    2064       rw = 1;
    2065       fWarnings[rw]++;
    2066     }
    2067     else
    2068     {
    2069       rw = 0;
    2070       fWarnings[rw]++;
    2071     }
     2469         // the following condition ensures that elNoise2Pix > 0.0
     2470         if ( (diff + sigmabar2 - oldsigma2
     2471                                - lambdabar*F2excess) > 0.0 )
     2472         {
     2473           ok = kTRUE;
     2474           break;
     2475         }
     2476       }
     2477
     2478       if (!ok)
     2479       {
     2480         //*fLog << all << "theta, j, count, sigmabar2, diff, oldsigma2, ratioArea, lambdabar = "
     2481         //      << theta << ",  "
     2482         //      << j << ",  " << count << ",  " << sigmabar2 << ",  "
     2483         //      << diff << ",  " << oldsigma2 << ",  " << ratioArea << ",  "
     2484         //      << lambdabar << endl;
     2485         diff = lambdabar*F2excess + oldsigma2 - sigmabar2;
     2486
     2487         rw = 1;
     2488         fWarnings[rw]++;
     2489       }
     2490     }
     2491     // end of else --------------------
    20722492
    20732493    delete hdiff;
     
    20782498    // get the additional sigma^2 for this pixel (due to the padding)
    20792499
    2080     addSig2 = sigma2*ratioArea - oldsigma2;
     2500    addSig2 = (sigma2 - oldsigma2) * ratioArea;
    20812501    addSig2_phot = addSig2 / (fPEperPhoton * fPEperPhoton);
    20822502
     
    21392559
    21402560
    2141     Double_t newsigma = sqrt( oldsigma2 + addSig2 );
     2561    Double_t newsigma = sqrt( sigma2 * ratioArea );
    21422562    Double_t newsigma_phot = newsigma / fPEperPhoton;
    21432563    ppix.SetRms( newsigma_phot );
     
    21502570
    21512571  fSigmabar->Calc(*fCam, *fPed, *fEvt);
    2152   *fLog << all << "MPad::Process(); after padding : " << endl;
    2153   fSigmabar->Print("");
    2154 
    2155   *fLog << all << "Exit MPad::Process();" << endl;
     2572  //*fLog << all << "MPad::Process(); after padding : " << endl;
     2573  //fSigmabar->Print("");
     2574
     2575  //*fLog << all << "Exit MPad::Process();" << endl;
    21562576
    21572577  rc = 0;
     
    21732593    *fLog << dec << setfill(' ');
    21742594
    2175     int temp;
    2176     if (fWarnings[0] != 0.0)   
    2177       temp = (int)(fWarnings[1]*100/fWarnings[0]);
    2178     else
    2179       temp = 100;
     2595    if (fWarnings[0] == 0 ) fWarnings[0] = 1;
    21802596
    21812597    *fLog << " " << setw(7) << fWarnings[1] << " (" << setw(3)
    2182           << temp
    2183           << "%) Warning : iteration to find acceptable sigma failed"
     2598          << (int)(fWarnings[1]*100/fWarnings[0])
     2599          << "%) Pixel: iteration to find acceptable sigma failed"
    21842600          << ", fIter = " << fIter << endl;
    21852601
    2186     *fLog << " " << setw(7) << fErrors[1] << " (" << setw(3)
    2187           << (int)(fErrors[1]*100/GetNumExecutions())
    2188           << "%) Evts skipped due to: Sigmabar_old > 0" << endl;
     2602    *fLog << " " << setw(7) << fWarnings[2] << " (" << setw(3)
     2603          << (int)(fWarnings[2]*100/fWarnings[0])
     2604          << "%) Pixel: No data for generating Sigma^2-Sigmabar^2" << endl;
     2605
    21892606
    21902607    *fLog << " " << setw(7) << fErrors[2] << " (" << setw(3)
     
    21922609          << "%) Evts skipped due to: Zenith angle out of range" << endl;
    21932610
    2194     *fLog << " " << setw(7) << fErrors[3] << " (" << setw(3)
    2195           << (int)(fErrors[3]*100/GetNumExecutions())
    2196           << "%) Evts skipped due to: No data for generating Sigmabar" << endl;
    2197 
    21982611    *fLog << " " << setw(7) << fErrors[4] << " (" << setw(3)
    21992612          << (int)(fErrors[4]*100/GetNumExecutions())
    22002613          << "%) Evts skipped due to: Target sigma <= Sigmabar_old" << endl;
    2201 
    2202     *fLog << " " << setw(7) << fErrors[5] << " (" << setw(3)
    2203           << (int)(fErrors[5]*100/GetNumExecutions())
    2204           << "%) Evts skipped due to: No data for generating Sigma^2-Sigmabar^2" << endl;
    2205 
    2206     *fLog << " " << setw(7) << fErrors[6] << " (" << setw(3)
    2207           << (int)(fErrors[6]*100/GetNumExecutions())
    2208           << "%) Evts skipped due to: No data for generating Sigma" << endl;
    22092614
    22102615    *fLog << " " << setw(7) << fErrors[7] << " (" << setw(3)
     
    22242629
    22252630    //---------------------------------------------------------------
    2226     TCanvas &c = *(MH::MakeDefCanvas("Pad", "", 900, 1500));
    2227     c.Divide(3, 5);
     2631    TCanvas &c = *(MH::MakeDefCanvas("Pad", "", 900, 600));
     2632    c.Divide(3, 2);
    22282633    gROOT->SetSelectedPad(NULL);
    22292634
     
    22452650    //--------------------------------------------------------------------
    22462651
    2247 
     2652    /*
    22482653    c.cd(4);
    22492654    fHSigmaTheta->SetDirectory(NULL);
     
    22512656    fHSigmaTheta->DrawCopy();     
    22522657    fHSigmaTheta->SetBit(kCanDelete);     
    2253 
     2658    */
    22542659
    22552660    //--------------------------------------------------------------------
    22562661
    2257 
     2662    /*
    22582663    c.cd(7);
    22592664    fHBlindPixNTheta->SetDirectory(NULL);
     
    22612666    fHBlindPixNTheta->DrawCopy();     
    22622667    fHBlindPixNTheta->SetBit(kCanDelete);     
     2668    */
    22632669
    22642670    //--------------------------------------------------------------------
    22652671
    2266 
     2672    /*
    22672673    c.cd(10);
    22682674    fHBlindPixIdTheta->SetDirectory(NULL);
     
    22702676    fHBlindPixIdTheta->DrawCopy();     
    22712677    fHBlindPixIdTheta->SetBit(kCanDelete);     
    2272 
     2678    */
    22732679
    22742680    //--------------------------------------------------------------------
    22752681    // draw the 3D histogram (target): Theta, pixel, Sigma^2-Sigmabar^2
    22762682
     2683    /*
    22772684    c.cd(5);
    22782685    TH2D *l1 = NULL;
     
    22962703    l2->DrawCopy("box");
    22972704    l2->SetBit(kCanDelete);;
     2705    */
    22982706
    22992707    //--------------------------------------------------------------------
    23002708    // draw the 3D histogram (target): Theta, pixel, Sigma
    23012709
     2710    /*
    23022711    c.cd(6);
    23032712    TH2D *k1 = NULL;
     
    23212730    k2->DrawCopy("box");
    23222731    k2->SetBit(kCanDelete);;
    2323 
     2732    */
    23242733
    23252734    //--------------------------------------------------------------------
    23262735
    2327     c.cd(13);
     2736   
     2737    c.cd(4);
    23282738    TH2D *m1;
    23292739    m1 = (TH2D*) ((TH3*)fHgON)->Project3D("zy");
    23302740    m1->SetDirectory(NULL);
    2331     m1->SetTitle("(Target) Sigmabar-new vs. Sigmabar-old (ON, all  \\Theta)");
     2741    m1->SetTitle("(fHgON) Sigmabar-new vs. Sigmabar-old (ON, all  \\Theta)");
    23322742    m1->SetXTitle("Sigmabar-old");
    23332743    m1->SetYTitle("Sigmabar-new");
     
    23362746    m1->SetBit(kCanDelete);;
    23372747
    2338     c.cd(14);
     2748    c.cd(5);
    23392749    TH2D *m2;
    23402750    m2 = (TH2D*) ((TH3*)fHgOFF)->Project3D("zy");
    23412751    m2->SetDirectory(NULL);
    2342     m2->SetTitle("(Target) Sigmabar-new vs. Sigmabar-old (OFF, all  \\Theta)");
     2752    m2->SetTitle("(fHgOFF) Sigmabar-new vs. Sigmabar-old (OFF, all  \\Theta)");
    23432753    m2->SetXTitle("Sigmabar-old");
    23442754    m2->SetYTitle("Sigmabar-new");
     
    23472757    m2->SetBit(kCanDelete);;
    23482758
    2349     c.cd(15);
     2759    c.cd(6);
    23502760    TH2D *m3;
    23512761    m3 = (TH2D*) ((TH3*)fHgMC)->Project3D("zy");
    23522762    m3->SetDirectory(NULL);
    2353     m3->SetTitle("(Target) Sigmabar-new vs. Sigmabar-old (MC, all  \\Theta)");
     2763    m3->SetTitle("(fHgMC) Sigmabar-new vs. Sigmabar-old (MC, all  \\Theta)");
    23542764    m3->SetXTitle("Sigmabar-old");
    23552765    m3->SetYTitle("Sigmabar-new");
     
    23692779
    23702780
     2781
     2782
     2783
     2784
  • trunk/MagicSoft/Mars/manalysis/MPad.h

    r2798 r4584  
    1717class MCerPhotEvt;
    1818class MPedPhotCam;
    19 class MMcEvt;
     19class MPointingPos;
    2020class MSigmabar;
    2121class MParList;
     
    3131    MCerPhotEvt    *fEvt;
    3232    MSigmabar      *fSigmabar;
    33     MMcEvt         *fMcEvt;
     33    MPointingPos   *fPointPos;
    3434    MPedPhotCam    *fPed;
    35     MBlindPixels   *fBlinds;
     35    MBlindPixels   *fBlindPix;
    3636
    3737    TString        fType;           // type of data to be padded
     
    4141
    4242    Int_t          fErrors[9];
    43     Int_t          fWarnings[2];
     43    Int_t          fWarnings[3];
    4444
    4545    //----------------------------------
     
    8989
    9090
    91     Bool_t Merge2Distributions(TH1D *hista, TH1D * histb, TH1D * histap,
    92                                TH2D *fHga,  TH2D * fHgb, Int_t nbinssig);
     91    Bool_t Merge2Distributions(TH1D *hista, TH1D *histb, TH1D *histap,
     92                               TH2D *fHga,  TH2D *fHgb, Int_t nbinssig);
    9393
     94    Bool_t UpdateHg(TH2D *fHga, TH1D *histap, TH2D *fHge, TH3D *fHgA,
     95                    Int_t nbinssig, Int_t l);
    9496
    9597public:
     
    98100
    99101    Bool_t MergeONOFFMC(
    100       TH2D *sigthmc,  TH3D *diffpixthmc, TH3D *sigmapixthmc,
    101       TH2D *blindidthmc,  TH2D *blindnthmc,
    102       TH2D *sigthon,  TH3D *diffpixthon, TH3D *sigmapixthon,
    103       TH2D *blindidthon,  TH2D *blindnthon,
    104       TH2D *sigthoff=NULL, TH3D *diffpixthoff=NULL,TH3D *sigmapixthoff=NULL,
    105       TH2D *blindidthoff=NULL, TH2D *blindnthoff=NULL);
     102      TH2D& sigthmc,  TH3D& diffpixthmc, TH3D& sigmapixthmc,
     103      TH2D& blindidthmc,  TH2D& blindnthmc,
     104      TH2D& sigthon,  TH3D& diffpixthon, TH3D& sigmapixthon,
     105      TH2D& blindidthon,  TH2D& blindnthon,
     106      TH2D& sigthoff, TH3D& diffpixthoff,TH3D& sigmapixthoff,
     107      TH2D& blindidthoff, TH2D& blindnthoff);
    106108
    107109    Bool_t MergeONMC(
    108       TH2D *sigthmc,  TH3D *diffpixthmc, TH3D *sigmapixthmc,
    109       TH2D *blindidthmc,  TH2D *blindnthmc,
    110       TH2D *sigthon,  TH3D *diffpixthon, TH3D *sigmapixthon,
    111       TH2D *blindidthon,  TH2D *blindnthon);
     110      TH2D& sigthmc,  TH3D& diffpixthmc, TH3D& sigmapixthmc,
     111      TH2D& blindidthmc,  TH2D& blindnthmc,
     112      TH2D& sigthon,  TH3D&diffpixthon, TH3D& sigmapixthon,
     113      TH2D& blindidthon,  TH2D& blindnthon);
    112114
    113115    Bool_t ReadPaddingDist(const char *filein);
  • trunk/MagicSoft/Mars/manalysis/MSigmabar.cc

    r3530 r4584  
    3030//                                                                         //
    3131// This is the storage container to hold information about                 //
    32 // "average" pedestal sigmas                                               //
    33 //                                                                         //
    34 // In calculating averages all sigmas are normalized to the area of pixel 0//
     32// "average" pedestal RMS                                                  //
     33//                                                                         //
     34// The "average" pedestal RMS is calculated as                             //
     35//     <pedRMS> = sqrt( sum_i( (pedRMS_i)^2/area_i ) / no.of pixels )      //
     36//                                                                         //
     37//     which is the sqrt of the average (pedRMS^2 per area)                //
    3538//                                                                         //
    3639/////////////////////////////////////////////////////////////////////////////
     
    109112
    110113    //
    111     // sum up sigma/sqrt(area) for each sector,
     114    // sum up sigma^2/area for each sector,
    112115    // separately for inner and outer region;
    113116    //
     
    147150        const Double_t ratio = geom.GetPixRatio(idx);
    148151
     152        //*fLog << "pixel id, ratio = " << idx << ",  " << ratio << endl;
     153
    149154        const MGeomPix &gpix = geom[idx];
    150155
     
    171176        {
    172177            innerPixels[sector]++;
    173             innerSum[sector]+= sigma * sqrt(ratio);
     178            innerSum[sector]+= sigma*sigma * ratio;
    174179        }
    175180        else
    176181        {
    177182            outerPixels[sector]++;
    178             outerSum[sector]+= sigma * sqrt(ratio);
     183            outerSum[sector]+= sigma*sigma * ratio;
    179184        }
    180185    }
     
    192197    }
    193198
    194     if (fInnerPixels > 0) fSigmabarInner = fSumInner / fInnerPixels;
    195     if (fOuterPixels > 0) fSigmabarOuter = fSumOuter / fOuterPixels;
    196 
    197     //
    198     // this is the average sigma/sqrt(area) (over all pixels)
     199    if (fInnerPixels > 0) fSigmabarInner = sqrt(fSumInner / fInnerPixels);
     200    if (fOuterPixels > 0) fSigmabarOuter = sqrt(fSumOuter / fOuterPixels);
     201
     202    //
     203    // this is the sqrt of the average sigma^2/area
    199204    //
    200205    fSigmabar = (fInnerPixels+fOuterPixels)<=0 ? 0:
    201                 (fSumInner+fSumOuter)/(fInnerPixels+fOuterPixels);
     206                sqrt( (fSumInner+fSumOuter)/(fInnerPixels+fOuterPixels) );
    202207
    203208    for (UInt_t i=0; i<6; i++)
     
    209214
    210215        const Double_t sum = ip + op;
    211         fSigmabarInnerSector[i] = ip <=0 ? 0 :       iss/ip;
    212         fSigmabarOuterSector[i] = op <=0 ? 0 :       oss/op;
    213         fSigmabarSector[i]      = sum<=0 ? 0 : (iss+oss)/sum;
     216        fSigmabarInnerSector[i] = ip <=0 ? 0 :        sqrt(iss/ip);
     217        fSigmabarOuterSector[i] = op <=0 ? 0 :        sqrt(oss/op);
     218        fSigmabarSector[i]      = sum<=0 ? 0 : sqrt((iss+oss)/sum);
    214219    }
    215220
     
    217222    //Print(opt);
    218223
    219   return fSigmabar;
     224  return fSigmabarInner;
    220225}
    221226
  • trunk/MagicSoft/Mars/manalysis/MSigmabar.h

    r2798 r4584  
    1414{
    1515private:
    16     Float_t fSigmabar;          // Sigmabar ("average" RMS) of pedestal
     16    Float_t fSigmabar;          // Sigmabar ( sqrt(average pedestalRMS^2) )
    1717    Float_t fSigmabarInner;     // --only for inner pixels
    1818    Float_t fSigmabarOuter;     // --only for outer pixels 
  • trunk/MagicSoft/Mars/manalysis/MSigmabarCalc.cc

    r2798 r4584  
    3737//   MPedPhotCam
    3838//   MRawRunHeader
    39 //   MMcEvt  (FIXME: Must be replaced by a 'real-data' container)
     39//   MPointingPos
    4040//   MCerPhotEvt
    4141//
     
    5858#include "MSigmabarParam.h"
    5959
    60 #include "MMcEvt.hxx"
     60#include "MPointingPos.h"
    6161
    6262ClassImp(MSigmabarCalc);
     
    105105
    106106    // This is needed for determining min/max Theta
    107     fMcEvt = (MMcEvt*)pList->FindObject(AddSerialNumber("MMcEvt"));
    108     if (!fMcEvt)
     107    fPointPos = (MPointingPos*)pList->FindObject(AddSerialNumber("MPointingPos"));
     108    if (!fPointPos)
    109109    {
    110         *fLog << warn << "MMcEvt not found... aborting." << endl;
     110        *fLog << warn << "MPointingPos not found... aborting." << endl;
    111111        fThetaMin =  0;
    112112        fThetaMax = 90;
     
    148148    if (rc<fSigmabarMin) fSigmabarMin=rc;
    149149
    150     if (!fMcEvt)
     150    if (!fPointPos)
    151151        return kTRUE;
    152152
    153     const Double_t theta = fMcEvt->GetTelescopeTheta()*kRad2Deg;
     153    const Double_t theta = fPointPos->GetZd();
    154154
    155     if (theta>fSigmabarMax) fSigmabarMax=theta;
    156     if (theta<fSigmabarMax) fSigmabarMin=theta;
     155    if (theta>fThetaMax) fThetaMax=theta;
     156    if (theta<fThetaMin) fThetaMin=theta;
    157157
    158158    return kTRUE;
     
    176176void MSigmabarCalc::Reset()
    177177{
    178     if (!fMcEvt)
     178    if (!fPointPos)
    179179        return;
    180180
  • trunk/MagicSoft/Mars/manalysis/MSigmabarCalc.h

    r2798 r4584  
    1010#endif
    1111
    12 #ifndef MARS_MMcEvt
    13 #include "MMcEvt.hxx"
     12#ifndef MARS_MPointingPos
     13#include "MPointingPos.h"
    1414#endif
    1515
     
    3333{
    3434private:
    35     MMcEvt         *fMcEvt;
     35    MPointingPos   *fPointPos;
    3636    MCerPhotEvt    *fEvt;
    3737    MGeomCam       *fCam;
Note: See TracChangeset for help on using the changeset viewer.