Changeset 2128 for trunk/MagicSoft/Mars


Ignore:
Timestamp:
05/21/03 12:21:58 (22 years ago)
Author:
wittek
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r2127 r2128  
    11                                                 -*-*- END OF LINE -*-*-
     2
     3 2003/05/21: Wolfgang Wittek
     4
     5   * mhist/MHBlindPixels.[h,cc]
     6     - change 1D histogram into 2D histogram (pixel Id vs. Theta)
     7     - add 2D histogram : no.of blind pixels vs. Theta
     8
     9   * mhist/MHSigmaTheta.cc
     10     - correct "BinningPix"
     11
     12   * manalysis/MPadSchweizer.[h,cc]
     13     - add simulation of blind pixels
     14
     15   * mhist/MHMatrix.cc
     16     - in DefRefMatrix : allow variable bin size for 'hth' and 'hthd'
     17
     18
     19
    220 2003/05/20: Oscar Blanch Bigas
    321
     
    5068   * manalysis/MFiltercutsCalc.[h,cc]:
    5169     - added
    52 
    5370
    5471
  • trunk/MagicSoft/Mars/manalysis/MPadSchweizer.cc

    r2070 r2128  
    8686#include "MPedestalCam.h"
    8787#include "MPedestalPix.h"
     88#include "MBlindPixels.h"
    8889
    8990ClassImp(MPadSchweizer);
     
    101102  fHSigmaPixTheta = NULL;
    102103  fHDiffPixTheta  = NULL;
     104  fHBlindPixIdTheta = NULL;
     105  fHBlindPixNTheta  = NULL;
    103106
    104107  fHSigmaPedestal = NULL;
     
    125128// fHSigmaPixTheta 3D-hiostogram (Theta, pixel, sigma)
    126129// fHDiffPixTheta  3D-histogram  (Theta, pixel, sigma^2-sigmabar^2)
    127 //
    128 //
    129 void MPadSchweizer::SetHistograms(TH2D *hist2, TH3D *hist3, TH3D *hist3Diff)
     130// fHBlindPixIdTheta 2D-histogram  (Theta, blind pixel Id)
     131// fHBlindPixNTheta  2D-histogram  (Theta, no.of blind pixels )
     132//
     133//
     134void MPadSchweizer::SetHistograms(TH2D *hist2, TH3D *hist3, TH3D *hist3Diff,
     135                                  TH2D *hist2Pix, TH2D *hist2PixN)
    130136{
    131137    fHSigmaTheta    = hist2;
    132138    fHSigmaPixTheta = hist3;
    133139    fHDiffPixTheta  = hist3Diff;
     140    fHBlindPixIdTheta = hist2Pix;
     141    fHBlindPixNTheta  = hist2PixN;
    134142
    135143    fHSigmaTheta->SetDirectory(NULL);
    136144    fHSigmaPixTheta->SetDirectory(NULL);
    137145    fHDiffPixTheta->SetDirectory(NULL);
     146    fHBlindPixIdTheta->SetDirectory(NULL);
     147    fHBlindPixNTheta->SetDirectory(NULL);
    138148
    139149    Print();
     
    171181Bool_t MPadSchweizer::PreProcess(MParList *pList)
    172182{
    173   if ( !fHSigmaTheta  || !fHSigmaPixTheta  || !fHDiffPixTheta)
     183  if ( !fHSigmaTheta  || !fHSigmaPixTheta  || !fHDiffPixTheta  ||
     184       !fHBlindPixIdTheta  ||  !fHBlindPixNTheta)
    174185  {
    175186       *fLog << err << "At least one of the histograms needed for the padding is not defined ... aborting." << endl;
     
    190201       return kFALSE;
    191202     }
    192  
     203
    193204   fCam = (MGeomCam*)pList->FindObject("MGeomCam");
    194205   if (!fCam)
     
    211222       return kFALSE;
    212223     }
     224
     225   fBlinds = (MBlindPixels*)pList->FindCreateObj("MBlindPixels");
     226   if (!fBlinds)
     227     {
     228       *fLog << err << "MBlindPixels not found... aborting." << endl;
     229       return kFALSE;
     230     }
    213231   
    214232
     
    296314  //-------------------------------------------
    297315  // for the current theta,
     316  // generate blind pixels according to the histograms
     317  //          fHBlindPixNTheta and fHBlindPixIDTheta
     318  //
     319
     320
     321  Int_t binPix = fHBlindPixNTheta->GetXaxis()->FindBin(theta);
     322
     323  if ( binPix < 1  ||  binPix > fHBlindPixNTheta->GetNbinsX() )
     324  {
     325    //*fLog << "MPadSchweizer::Process(); binNumber out of range : theta, binPix = "
     326    //      << theta << ",  " << binPix << ";  Skip event " << endl;
     327    // event cannot be padded; skip event
     328
     329    rc = 2;
     330    fErrors[rc]++;
     331    return kCONTINUE;
     332  }
     333
     334  // numBlind is the number of blind pixels in this event
     335  TH1D *nblind;
     336  UInt_t numBlind;
     337
     338  nblind = fHBlindPixNTheta->ProjectionY("", binPix, binPix, "");
     339  if ( nblind->GetEntries() == 0.0 )
     340  {
     341    *fLog << "MPadSchweizer::Process(); projection for Theta bin "
     342          << binPix << " has no entries; Skip event " << endl;
     343    // event cannot be padded; skip event
     344    delete nblind;
     345
     346    rc = 7;
     347    fErrors[rc]++;
     348    return kCONTINUE;
     349  }
     350  else
     351  {
     352    numBlind = (Int_t) (nblind->GetRandom()+0.5);
     353
     354    //*fLog << "numBlind = " << numBlind << endl;
     355  }
     356  delete nblind;
     357
     358
     359  // throw the Id of numBlind different pixels in this event
     360  TH1D *hblind;
     361  UInt_t idBlind;
     362  UInt_t listId[npix];
     363  UInt_t nlist = 0;
     364  Bool_t equal;
     365
     366  hblind = fHBlindPixIdTheta->ProjectionY("", binPix, binPix, "");
     367  if ( hblind->GetEntries() > 0.0 )
     368    for (UInt_t i=0; i<numBlind; i++)
     369    {
     370      while(1)
     371      {
     372        idBlind = (Int_t) (hblind->GetRandom()+0.5);
     373        equal = kFALSE;
     374        for (UInt_t j=0; j<nlist; j++)
     375          if (idBlind == listId[j])
     376          {
     377            equal = kTRUE;
     378            break;
     379          }
     380        if (!equal) break;
     381      }
     382      listId[nlist] = idBlind;
     383      nlist++;
     384
     385      fBlinds->SetPixelBlind(idBlind);
     386      //*fLog << "idBlind = " << idBlind << endl;
     387    }
     388  delete hblind;
     389
     390
     391  //-------------------------------------------
     392  // for the current theta,
    298393  // generate a sigmabar according to the histogram fHSigmaTheta
    299394  //
     
    301396  Int_t binNumber = fHSigmaTheta->GetXaxis()->FindBin(theta);
    302397
     398  if (binPix != binNumber)
     399  {
     400    cout << "The binnings of the 2 histograms are not identical; aborting"
     401         << endl;
     402    return kERROR;
     403  }
     404
    303405  TH1D *hsigma;
    304406
    305   if ( binNumber < 1  ||  binNumber > fHSigmaTheta->GetNbinsX() )
     407  hsigma = fHSigmaTheta->ProjectionY("", binNumber, binNumber, "");
     408  if ( hsigma->GetEntries() == 0.0 )
    306409  {
    307     //*fLog << "MPadSchweizer::Process(); binNumber out of range : theta, binNumber = "
    308     //      << theta << ",  " << binNumber << "; Skip event " << endl;
     410    *fLog << "MPadSchweizer::Process(); projection for Theta bin "
     411          << binNumber << " has no entries; Skip event " << endl;
    309412    // event cannot be padded; skip event
    310 
    311     rc = 2;
     413    delete hsigma;
     414
     415    rc = 3;
    312416    fErrors[rc]++;
    313417    return kCONTINUE;
     
    315419  else
    316420  {
    317     hsigma = fHSigmaTheta->ProjectionY("", binNumber, binNumber, "");
    318     if ( hsigma->GetEntries() == 0.0 )
    319     {
    320       *fLog << "MPadSchweizer::Process(); projection for Theta bin "
    321             << binNumber << " has no entries; Skip event " << endl;
    322       // event cannot be padded; skip event
    323       delete hsigma;
    324 
    325       rc = 3;
    326       fErrors[rc]++;
    327       return kCONTINUE;
    328     }
    329     else
    330     {
    331       sigmabar = hsigma->GetRandom();
    332 
    333       //*fLog << "Theta, bin number = " << theta << ",  " << binNumber
    334       //      << ",  sigmabar = " << sigmabar << endl;
    335     }
    336     delete hsigma;
    337   }
     421    sigmabar = hsigma->GetRandom();
     422     //*fLog << "Theta, bin number = " << theta << ",  " << binNumber      //      << ",  sigmabar = " << sigmabar << endl
     423  }
     424  delete hsigma;
     425
    338426  const Double_t sigmabar2 = sigmabar*sigmabar;
    339427
     
    644732          << "%) Evts skipped due to: No data for generating Sigma" << endl;
    645733
     734    *fLog << " " << setw(7) << fErrors[7] << " (" << setw(3)
     735          << (int)(fErrors[7]*100/GetNumExecutions())
     736          << "%) Evts skipped due to: No data for generating Blind pixels" << endl;
     737
    646738    *fLog << " " << fErrors[0] << " ("
    647739          << (int)(fErrors[0]*100/GetNumExecutions())
  • trunk/MagicSoft/Mars/manalysis/MPadSchweizer.h

    r2021 r2128  
    2020class MSigmabar;
    2121class MParList;
     22class MBlindPixels;
    2223
    2324class MPadSchweizer : public MTask
     
    2930    MMcEvt         *fMcEvt;
    3031    MPedestalCam   *fPed;
     32    MBlindPixels   *fBlinds;
    3133
    3234    Int_t          fPadFlag;
     
    3436    Int_t          fGroup;
    3537
    36     Int_t          fErrors[7];
     38    Int_t          fErrors[8];
    3739
    3840    // plots used for the padding
     41    TH2D           *fHBlindPixIdTheta; // 2D-histogram (blind pixel Id vs. Theta)
     42    TH2D           *fHBlindPixNTheta; // 2D-histogram (no.of blind pixels vs. Theta)
    3943    TH2D           *fHSigmaTheta;    // 2D-histogram (sigmabar vs. Theta)
    4044    TH3D           *fHSigmaPixTheta; // 3D-histogram (Theta, pixel, sigma)
     
    5357    ~MPadSchweizer();
    5458
    55     void SetHistograms(TH2D *hist2, TH3D *hist3, TH3D *hist3Diff);
     59    void SetHistograms(TH2D *hist2, TH3D *hist3, TH3D *hist3Diff,
     60                       TH2D *hist2Pix, TH2D *hist2PixN);
    5661
    5762    Bool_t PreProcess(MParList *pList);
  • trunk/MagicSoft/Mars/mhist/MHBlindPixels.cc

    r2112 r2128  
     1
    12/* ======================================================================== *\
    23!
     
    3233#include <TCanvas.h>
    3334
     35#include "MMcEvt.hxx"
    3436#include "MBlindPixels.h"
     37#include "MPedestalCam.h"
     38#include "MParList.h"
     39#include "MBinning.h"
     40
     41#include "MLog.h"
     42#include "MLogManip.h"
    3543
    3644ClassImp(MHBlindPixels);
     
    4149//
    4250MHBlindPixels::MHBlindPixels(const char *name, const char *title)
    43     : fHist(fName, fTitle, 577, -.5, 577-.5)
    4451{
    4552    fName  = name  ? name  : "MHBlindPixels";
    46     fTitle = title ? title : "Histogram for Blind Pixels";
     53    fTitle = title ? title : "Histogram for Blind Pixels vs. Theta";
    4754
    4855    //  - we initialize the histogram
    49     //  - we have to give diferent names for the diferent histograms because
     56    //  - we have to give different names for the different histograms because
    5057    //    root don't allow us to have diferent histograms with the same name
    5158
    52     fHist.SetName("1D-BlindPixels");
    53     fHist.SetTitle(fTitle);
     59    fBlindId.SetName("2D-IdBlindPixels");
     60    fBlindId.SetTitle("2D-IdBlindPixels");
     61    fBlindId.SetDirectory(NULL);
     62    fBlindId.SetXTitle("\\Theta [\\circ]");
     63    fBlindId.SetYTitle("pixel Id");
    5464
    55     fHist.SetDirectory(NULL);
     65    fBlindN.SetName("2D-NBlindPixels");
     66    fBlindN.SetTitle("2D-NBlindPixels");
     67    fBlindN.SetDirectory(NULL);
     68    fBlindN.SetXTitle("\\Theta [\\circ]");
     69    fBlindN.SetYTitle("number of blind pixels");
     70}
    5671
    57     fHist.SetXTitle("Id");
    58     fHist.SetYTitle("Counts");
     72// --------------------------------------------------------------------------
     73//
     74// Set the binnings and prepare the filling of the histogram
     75//
     76Bool_t MHBlindPixels::SetupFill(const MParList *plist)
     77{
     78    fMcEvt = (MMcEvt*)plist->FindObject("MMcEvt");
     79    if (!fMcEvt)
     80    {
     81        *fLog << err << "MMcEvt not found... aborting." << endl;
     82        return kFALSE;
     83    }
     84
     85    fPed = (MPedestalCam*)plist->FindObject("MPedestalCam");
     86    if (!fPed)
     87    {
     88        *fLog << err << "MPedestalCam not found... aborting." << endl;
     89        return kFALSE;
     90    }
     91
     92
     93    // Get Theta Binning
     94    MBinning* binstheta  = (MBinning*)plist->FindObject("BinningTheta", "MBinning");
     95    if (!binstheta)
     96    {
     97        *fLog << err << "Object 'BinningTheta' [MBinning] not found... aborting" << endl;
     98        return kFALSE;
     99    }
     100
     101    // Get binning for pixel number
     102    const UInt_t npix1 = fPed->GetSize()+1;
     103
     104    MBinning binspix("BinningPixel");
     105    binspix.SetEdges(npix1, -0.5, npix1-0.5);
     106
     107    // Set binnings in histograms
     108    SetBinning(&fBlindId, binstheta, &binspix);
     109    SetBinning(&fBlindN,  binstheta, &binspix);
     110
     111    return kTRUE;
    59112}
    60113
     
    68121    pad->SetBorderMode(0);
    69122
    70     fHist.Draw(option);
     123    pad->Divide(2,2);
     124
     125    TH1D *h;
     126
     127    pad->cd(1);
     128    fBlindId.Draw(option);
     129
     130    pad->cd(2);
     131    fBlindN.Draw(option);
     132
     133    pad->cd(3);
     134    gPad->SetBorderMode(0);
     135    h = ((TH2*)&fBlindId)->ProjectionY("ProjY-pixId", -1, 9999, "");
     136    h->SetDirectory(NULL);
     137    h->SetTitle("Distribution of blind pixel Id");
     138    h->SetXTitle("Id of blind pixel");
     139    h->SetYTitle("No. of events");
     140    h->Draw(option);
     141    h->SetBit(kCanDelete);
     142
     143    pad->cd(4);
     144    gPad->SetBorderMode(0);
     145    h = ((TH2*)&fBlindN)->ProjectionY("ProjY-pixN", -1, 9999, "");
     146    h->SetDirectory(NULL);
     147    h->SetTitle("Distribution of no.of blind pixels");
     148    h->SetXTitle("No. of blind pixels");
     149    h->SetYTitle("No. of events");
     150    h->Draw(option);
     151    h->SetBit(kCanDelete);
    71152
    72153    pad->Modified();
     
    79160        return kFALSE;
    80161
     162    Double_t theta = fMcEvt->GetTelescopeTheta()*kRad2Deg;
    81163    const MBlindPixels &bp = *(MBlindPixels*)par;
    82164
    83165    // FIXME: Slow.
    84     for (int i=0; i<577; i++)
     166    const UInt_t npix = fPed->GetSize();
     167
     168    UInt_t nb = 0;
     169    for (UInt_t i=0; i<npix; i++)
     170    {
    85171        if (bp.IsBlind(i))
    86             fHist.Fill(i, w);
     172        {
     173          fBlindId.Fill(theta, i, w);
     174          nb++;
     175        }   
     176    }
     177    fBlindN.Fill(theta, nb, w);
    87178
    88179    return kTRUE;
    89180}
     181
     182
     183
     184
     185
     186
     187
     188
     189
     190
     191
     192
  • trunk/MagicSoft/Mars/mhist/MHBlindPixels.h

    r2043 r2128  
    55#include "MH.h"
    66#endif
    7 #ifndef ROOT_TH1
    8 #include <TH1.h>
     7#ifndef ROOT_TH2
     8#include <TH2.h>
    99#endif
     10
     11class MPedestalCam;
     12class MMcEvt;
     13class MParList;
     14
    1015
    1116class MHBlindPixels : public MH
    1217{
    1318private:
    14     TH1D fHist; //
     19    MPedestalCam  *fPed;      //!
     20    MMcEvt        *fMcEvt;    //!
     21
     22    TH2D          fBlindId; // 2D-histogram : pixel Id vs. Theta
     23    TH2D          fBlindN;  // 2D-histogram : no.of blind pixels vs. Theta
    1524
    1625public:
    1726    MHBlindPixels(const char *name=NULL, const char *title=NULL);
    1827
    19     const TH1D *GetHist()       { return &fHist; }
    20     const TH1D *GetHist() const { return &fHist; }
     28    const TH2D *GetBlindId()       { return &fBlindId; }
     29    const TH2D *GetBlindId() const { return &fBlindId; }
    2130
    22     TH1 *GetHistByName(const TString name) { return &fHist; }
     31    const TH2D *GetBlindN()       { return &fBlindN; }
     32    const TH2D *GetBlindN() const { return &fBlindN; }
     33
     34    TH2 *GetBlinIdByName(const TString name) { return &fBlindId; }
     35    TH2 *GetBlinNByName(const TString name) { return &fBlindN; }
    2336
    2437    void Draw(Option_t* option = "");
     38    Bool_t SetupFill(const MParList *plist);
    2539    Bool_t Fill(const MParContainer *par, const Stat_t w=1);
    2640
    27     ClassDef(MHBlindPixels, 1)  // Histogram of blind pixels
     41    ClassDef(MHBlindPixels, 1)  // Histogram of blind pixel Id vs. Theta
    2842};
    2943
    3044#endif
     45
     46
  • trunk/MagicSoft/Mars/mhist/MHMatrix.cc

    r2104 r2128  
    788788    // Calculate normalization factors
    789789    //
    790     const int    nbins   = thsh.GetNbinsX();
    791     const double frombin = thsh.GetBinLowEdge(1);
    792     const double tobin   = thsh.GetBinLowEdge(nbins+1);
    793     const double dbin    = thsh.GetBinWidth(1);
     790    //const int    nbins   = thsh.GetNbinsX();
     791    //const double frombin = thsh.GetBinLowEdge(1);
     792    //const double tobin   = thsh.GetBinLowEdge(nbins+1);
     793    //const double dbin    = thsh.GetBinWidth(1);
     794
    794795    const Int_t  nrows   = fM.GetNrows();
    795796    const Int_t  ncols   = fM.GetNcols();
     
    798799    // set up the real histogram (distribution before)
    799800    //
    800     TH1F hth("th", "Distribution before reduction", nbins, frombin, tobin);
     801    //TH1F hth("th", "Distribution before reduction", nbins, frombin, tobin);
     802    TH1F hth;
     803    hth.SetNameTitle("th", "Distribution before reduction");
     804    SetBinning(&hth, &thsh);
    801805    hth.SetDirectory(NULL);
    802806    for (Int_t j=0; j<nrows; j++)
    803807        hth.Fill(fM(j, refcolumn));
    804808
    805     TH1F hthd("thd", "Correction factors", nbins, frombin, tobin);
     809    //TH1F hthd("thd", "Correction factors", nbins, frombin, tobin);
     810    TH1F hthd;
     811    hthd.SetNameTitle("thd", "Correction factors");
     812    SetBinning(&hthd, &thsh);
    806813    hthd.SetDirectory(NULL);
    807814    hthd.Divide((TH1F*)&thsh, &hth, 1, 1);
     
    840847    TVector v(fM.GetNrows());
    841848    v = TMatrixColumn(fM, refcolumn);
    842     v += -frombin;
    843     v *= 1/dbin;
     849    //v += -frombin;
     850    //v *= 1/dbin;
    844851
    845852    //
     
    850857    for (ir=0; ir<nrows; ir++)
    851858    {
    852         const Int_t indref = (Int_t)v(ind[ir]);
    853 
     859        // const Int_t indref = (Int_t)v(ind[ir]);
     860        const Int_t indref = hthd.FindBin(v(ind[ir])) - 1;
    854861        cumulweight[indref] += hthd.GetBinContent(indref+1);
    855862        if (cumulweight[indref]<=0.5)
  • trunk/MagicSoft/Mars/mhist/MHSigmaTheta.cc

    r2109 r2128  
    100100
    101101    MBinning binspix("BinningPixel");
    102     binspix.SetEdges(577, -0.5, 577.5);
     102    binspix.SetEdges(578, -0.5, 577.5);
    103103
    104104    SetBinning(&fSigmaTheta,    &binst, &binsb);
     
    169169
    170170    // Get binning for pixel number
    171     const UInt_t npix = fPed->GetSize();
     171    const UInt_t npix1 = fPed->GetSize()+1;
    172172
    173173    MBinning binspix("BinningPixel");
    174     binspix.SetEdges(npix, -0.5, 0.5+npix);
     174    binspix.SetEdges(npix1, -0.5, npix1-0.5);
    175175
    176176    // Set binnings in histograms
Note: See TracChangeset for help on using the changeset viewer.