Changeset 1879


Ignore:
Timestamp:
03/28/03 14:24:38 (22 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r1878 r1879  
    22
    33
     4 2003/03/28: Thomas Bretz
     5
     6   * mbase/MParContainer.h:
     7     - added kEnableGraphicalOutput
     8     - added EnableGraphicalOutput
     9     - added IsGraphicalOutputEnabled
     10   
     11   * mbase/MParList.h:
     12     - changed BIT(15) to BIT(17)
     13   
     14   * mhist/MH.[h,cc]:
     15     - SetBinning(TH1*, TH1*) --> SetBinning(TH1*, const TH1*)
     16   
     17   * mhist/MH3.h:
     18     - changed BIT(15) to BIT(17)
     19     - changed BIT(16) to BIT(18)
     20     - changed BIT(17) to BIT(19)
     21
     22   * mhist/MHMatrix.[h,cc]:
     23     - added DrawDefRefInfo
     24     - added CopyCrop
     25     - added GetRandomArrayI
     26     - changed DefRefMatrix to support the above
     27     - fixed a bug in DefRefMatrix (evtcount2 in the last loop
     28       instead of evtcount1)
     29     - Don't do anything in the finalization if the matrix has the correct
     30       dimensions
     31     - fixed comment of DefRefMatrix
     32     - changed number of first column from 1 to 0
     33     - changed BIT(16) to BIT(17)
     34
     35
     36
    437 2003/03/28: Wolfgang Wittek
    538
    639    * mhist/MHMatrix.cc
    7       - if nmaxevts>fM.GetNrows() set nmaxevts = fM.GetNrows()
     40      - DefRefMatrix: if nmaxevts>fM.GetNrows() set
     41        nmaxevts = fM.GetNrows()
    842
    943    * manalysis/MSelBasic.[h,cc]
  • trunk/MagicSoft/Mars/mbase/MParContainer.h

    r1574 r1879  
    3636private:
    3737    enum {
    38         kIsSavedAsPrimitive = BIT(15)
     38        kIsSavedAsPrimitive    = BIT(15),
    3939    };
    4040
     
    4444
    4545public:
     46    enum {
     47        kEnableGraphicalOutput = BIT(16)
     48    };
     49
    4650    MParContainer(const char *name="", const char *title="") : fName(name), fTitle(title), fLog(&gLog), fReadyToSave(kFALSE) {  }
    4751    MParContainer(const TString &name, const TString &title) : fName(name), fTitle(title), fLog(&gLog), fReadyToSave(kFALSE) {  }
     
    7680    virtual void   SetReadyToSave(Bool_t flag=kTRUE) { fReadyToSave=flag; }
    7781    virtual Bool_t IsSavedAsPrimitive() const        { return TestBit(kIsSavedAsPrimitive); }
     82    virtual void   EnableGraphicalOutput(Bool_t flag=kTRUE) { flag ? SetBit(kEnableGraphicalOutput) : ResetBit(kEnableGraphicalOutput);}
     83    virtual Bool_t IsGraphicalOutputEnabled() const  { return TestBit(kEnableGraphicalOutput); }
    7884
    7985    TMethodCall *GetterMethod(const char *name) const;
  • trunk/MagicSoft/Mars/mbase/MParList.h

    r1524 r1879  
    3636
    3737public:
    38     enum { kDoNotReset = BIT(15) };
     38    enum { kDoNotReset = BIT(17) };
    3939
    4040    MParList(const char *name=NULL, const char *title=NULL);
  • trunk/MagicSoft/Mars/mhist/MH.cc

    r1780 r1879  
    366366// Both histograms must be of the same type: TH1, TH2 or TH3
    367367//
    368 void MH::SetBinning(TH1 *h, TH1 *x)
     368void MH::SetBinning(TH1 *h, const TH1 *x)
    369369{
    370370    if (h->InheritsFrom(TH3::Class()) && x->InheritsFrom(TH3::Class()))
    371371    {
    372         SetBinning((TH3*)h, x->GetXaxis(), x->GetYaxis(), x->GetZaxis());
     372        SetBinning((TH3*)h, ((TH1*)x)->GetXaxis(), ((TH1*)x)->GetYaxis(), ((TH1*)x)->GetZaxis());
    373373        return;
    374374    }
     
    377377    if (h->InheritsFrom(TH2::Class()) && x->InheritsFrom(TH2::Class()))
    378378    {
    379         SetBinning((TH2*)h, x->GetXaxis(), x->GetYaxis());
     379        SetBinning((TH2*)h, ((TH1*)x)->GetXaxis(), ((TH1*)x)->GetYaxis());
    380380        return;
    381381    }
     
    384384    if (h->InheritsFrom(TH1::Class()) && x->InheritsFrom(TH1::Class()))
    385385    {
    386         SetBinning(h, x->GetXaxis());
     386        SetBinning(h, ((TH1*)x)->GetXaxis());
    387387        return;
    388388    }
  • trunk/MagicSoft/Mars/mhist/MH.h

    r1668 r1879  
    4646    static void SetBinning(TH3 *h, const TAxis *binsx, const TAxis *binsy, const TAxis *binsz);
    4747
    48     static void SetBinning(TH1 *h, TH1 *x);
     48    static void SetBinning(TH1 *h, const TH1 *x);
    4949
    5050    static Bool_t ApplyBinning(const MParList &plist, TString name, TH1 *h);
  • trunk/MagicSoft/Mars/mhist/MH3.h

    r1832 r1879  
    2727
    2828    enum {
    29         kIsLogx = BIT(15),
    30         kIsLogy = BIT(16),
    31         kIsLogz = BIT(17)
     29        kIsLogx = BIT(17),
     30        kIsLogy = BIT(18),
     31        kIsLogz = BIT(19)
    3232    };
    3333
  • trunk/MagicSoft/Mars/mhist/MHMatrix.cc

    r1874 r1879  
    250250        return kTRUE;
    251251
    252     TMatrix m(fM);
    253 
    254     fM.ResizeTo(fNumRow, fData->GetNumEntries());
    255 
    256     TVector vold(fM.GetNcols());
    257     for (int x=0; x<fM.GetNrows(); x++)
    258         TMatrixRow(fM, x) = vold = TMatrixRow(m, x);
     252    if (fNumRow != fM.GetNrows())
     253    {
     254        TMatrix m(fM);
     255        CopyCrop(fM, m, fNumRow);
     256    }
    259257
    260258    return kTRUE;
     
    687685// ------------------------------------------------------------------------
    688686//
     687//  Used in DefRefMatrix to display the result graphically
     688//
     689void MHMatrix::DrawDefRefInfo(const TH1 &hth, const TH1 &hthd, const TH1 &thsh, Int_t refcolumn)
     690{
     691    //
     692    // Fill a histogram with the distribution after raduction
     693    //
     694    TH1F hta;
     695    hta.SetName("hta");
     696    hta.SetTitle("Distribution after reduction");
     697    SetBinning(&hta, &hth);
     698
     699    for (Int_t i=0; i<fM.GetNrows(); i++)
     700        hta.Fill(fM(i, refcolumn));
     701
     702    TCanvas *th1 = MakeDefCanvas(this);
     703    th1->Divide(2,2);
     704
     705    th1->cd(1);
     706    ((TH1&)hth).DrawCopy();   // real histogram before
     707
     708    th1->cd(2);
     709    ((TH1&)hta).DrawCopy();   // histogram after
     710
     711    th1->cd(3);
     712    ((TH1&)hthd).DrawCopy();  // correction factors
     713
     714    th1->cd(4);
     715    ((TH1&)thsh).DrawCopy();  // target
     716}
     717
     718// ------------------------------------------------------------------------
     719//
     720//  Resizes th etarget matrix to rows*source.GetNcol() and copies
     721//  the data from the first (n)rows or the source into the target matrix.
     722//
     723void MHMatrix::CopyCrop(TMatrix &target, const TMatrix &source, Int_t rows)
     724{
     725    TVector v(source.GetNcols());
     726
     727    target.ResizeTo(rows, source.GetNcols());
     728    for (Int_t ir=0; ir<rows; ir++)
     729        TMatrixRow(target, ir) = v = TMatrixRow(source, ir);
     730}
     731
     732// ------------------------------------------------------------------------
     733//
    689734// Define the reference matrix
    690 //   refcolumn  number of the column (starting at 1)containing the variable,
     735//   refcolumn  number of the column (starting at 0) containing the variable,
    691736//              for which a target distribution may be given;
    692 //              if refcolumn is negative the target distribution will be set
    693 //              equal to the real distribution; the events in the reference
    694 //              matrix will then be simply a random selection of the events
    695 //              in the original matrix.
    696737//   thsh       histogram containing the target distribution of the variable
    697738//   nmaxevts   maximum number of events in the reference matrix
     
    709750    }
    710751
    711     if (refcolumn==0)
    712     {
    713         *fLog << err << dbginf << "Reference column 0 unknown." << endl;
    714         return kFALSE;
    715     }
    716 
    717752    if (thsh.GetMinimum()<0)
    718753    {
     
    737772
    738773    //
    739     // if refcolumn < 0 : select reference events randomly
    740     //                    i.e. set the normaliztion factotrs equal to 1.0
    741774    // refcol is the column number starting at 0; it is >= 0
    742775    //
     
    758791    // set up the real histogram (distribution before)
    759792    //
    760     TH1F hth("th", "data at input", nbins, frombin, tobin);
     793    TH1F hth("th", "Distribution before reduction", nbins, frombin, tobin);
    761794    for (Int_t j=0; j<nrows; j++)
    762         hth.Fill(fM(j, refcolumn-1));
    763 
    764     hth.DrawCopy();
    765 
    766     TH1F hthd("thd", "correction factors", nbins, frombin, tobin);
     795        hth.Fill(fM(j, refcolumn));
     796
     797    TH1F hthd("thd", "Correction factors", nbins, frombin, tobin);
    767798    hthd.Divide((TH1F*)&thsh, &hth, 1, 1);
    768799
     
    781812    // get random access
    782813    //
    783     TArrayF ranx(nrows);
    784 
    785     TRandom3 rnd(0);
    786     for (Int_t i=0; i<nrows; i++)
    787         ranx[i] = rnd.Rndm(i);
    788 
    789814    TArrayI ind(nrows);
    790     TMath::Sort(nrows, ranx.GetArray(), ind.GetArray(), kTRUE);
     815    GetRandomArrayI(ind);
    791816
    792817    //
     
    805830    //
    806831    TVector v(fM.GetNrows());
    807     v = TMatrixColumn(fM, refcolumn-1);
     832    v = TMatrixColumn(fM, refcolumn);
    808833    v += -frombin;
    809834    v *= 1/dbin;
     
    842867    // this is the matrix to be used in the g/h separation
    843868    //
    844     fM.ResizeTo(evtcount1, ncols);
     869    CopyCrop(fM, mnewtmp, evtcount1);
    845870    fNumRow = evtcount1;
    846     for (ir=0; ir<evtcount1; ir++)
    847         TMatrixRow(fM, ir) = vold = TMatrixRow(mnewtmp, ir);
    848871
    849872    if (evtcount1 < nmaxevts)
    850873        *fLog << warn << "The reference sample contains less events (" << evtcount1 << ") than required (" << nmaxevts << ")" << endl;
    851874
     875    if (TestBit(kEnableGraphicalOutput))
     876        DrawDefRefInfo(hth, hthd, thsh, refcolumn);
     877
    852878    if (!rest)
    853879        return kTRUE;
    854880
    855     rest->ResizeTo(evtcount2, ncols);
    856     for (ir=0; ir<evtcount1; ir++)
    857     {
    858         TVector vold(fM.GetNcols());
    859         TMatrixRow(*rest, ir) = vold = TMatrixRow(mrest, ir);
    860     }
     881    CopyCrop(*rest, mrest, evtcount2);
    861882
    862883    return kTRUE;
     
    865886// ------------------------------------------------------------------------
    866887//
     888// Returns a array containing randomly sorted indices
     889//
     890void MHMatrix::GetRandomArrayI(TArrayI &ind) const
     891{
     892    const Int_t rows = ind.GetSize();
     893
     894    TArrayF ranx(rows);
     895
     896    TRandom3 rnd(0);
     897    for (Int_t i=0; i<rows; i++)
     898        ranx[i] = rnd.Rndm(i);
     899
     900    TMath::Sort(rows, ranx.GetArray(), ind.GetArray(), kTRUE);
     901}
     902
     903// ------------------------------------------------------------------------
     904//
    867905// Define the reference matrix
    868 //   refcolumn  number of the column (starting at 1)containing the variable,
    869 //              for which a target distribution may be given;
    870 //              if refcolumn is negative the target distribution will be set
    871 //              equal to the real distribution; the events in the reference
    872 //              matrix will then be simply a random selection of the events
    873 //              in the original matrix.
    874 //   thsh       histogram containing the target distribution of the variable
    875906//   nmaxevts   maximum number of events in the reference matrix
    876907//   rest       a TMatrix conatining the resulting (not choosen)
     
    878909//              are not interested in this
    879910//
     911//              the target distribution will be set
     912//              equal to the real distribution; the events in the reference
     913//              matrix will then be simply a random selection of the events
     914//              in the original matrix.
     915//
    880916Bool_t MHMatrix::DefRefMatrix(Int_t nmaxevts, TMatrix *rest)
    881917{
     
    907943    // get random access
    908944    //
    909     TArrayF ranx(nrows);
    910 
    911     TRandom3 rnd(0);
    912     for (Int_t i=0; i<nrows; i++)
    913         ranx[i] = rnd.Rndm(i);
    914 
    915945    TArrayI ind(nrows);
    916     TMath::Sort(nrows, ranx.GetArray(), ind.GetArray(), kTRUE);
     946    GetRandomArrayI(ind);
    917947
    918948    //
     
    942972    // this is the matrix to be used in the g/h separation
    943973    //
    944     fM.ResizeTo(evtcount1, ncols);
     974    CopyCrop(fM, mnewtmp, evtcount1);
    945975    fNumRow = evtcount1;
    946     for (Int_t ir=0; ir<evtcount1; ir++)
    947     {
    948         TVector vold(fM.GetNcols());
    949         TMatrixRow(fM, ir) = vold = TMatrixRow(mnewtmp, ir);
    950     }
    951976
    952977    if (evtcount1 < nmaxevts)
     
    956981        return kTRUE;
    957982
    958     rest->ResizeTo(evtcount2, ncols);
    959     for (Int_t ir=0; ir<evtcount1; ir++)
    960     {
    961         TVector vold(fM.GetNcols());
    962         TMatrixRow(*rest, ir) = vold = TMatrixRow(mrest, ir);
    963     }
     983    CopyCrop(*rest, mrest, evtcount2);
    964984
    965985    return kTRUE;
    966 
    967     /*
    968      TMatrix mnew(evtcount, nconl);
    969      for (Int_t ir=0; ir<evtcount; ir++)
    970      for (Int_t ic=0; ic<fNcols; ic++)
    971      fM(ir,ic)   = mnewtmp(ir,ic);
    972 
    973      //
    974      //  test: print new matrix (part)
    975      //
    976      *fLog << "DefRefMatrix:  Event matrix (output) :" << endl;
    977      *fLog << "DefRefMatrix:  Nrows, Ncols = " << mnew.GetNrows();
    978      *fLog << " " << mnew.GetNcols() << endl;
    979 
    980      for (Int_t ir=0;ir<10; ir++)
    981      {
    982      *fLog <<ir <<" ";
    983      for (Int_t ic=0; ic<mnew.GetNcols(); ic++)
    984      cout<<Mnew(ir,ic)<<" ";
    985      *fLog <<endl;
    986      }
    987      */
    988 
    989     /*
    990      //  test print new bin contents
    991      *fLog << "MHMatrix::DefRefMatrix;  new histogram: " << endl;
    992      for (Int_t j=1; j<=fnbins; j++)
    993      {
    994      float a = fHthaft->GetBinContent(j);
    995      *fLog << j << "  "<< a << "   ";
    996      }
    997      *fLog <<endl;
    998      */
    999 
    1000     /*
    1001      //---------------------------------------------------------
    1002      // ==== plot four histograms
    1003      TCanvas *th1 = new TCanvas (fName, fName, 1);
    1004      th1->Divide(2,2);
    1005 
    1006      th1->cd(1);
    1007      ((TH1F*)fHthsh)->DrawCopy();      // target
    1008 
    1009      th1->cd(2);
    1010      ((TH1F*)fHth)->DrawCopy();        // real histogram before
    1011 
    1012      th1->cd(3);
    1013      ((TH1F*)fHthd)->DrawCopy();       // correction factors
    1014 
    1015      th1->cd(4);
    1016      ((TH1F*)fHthaft)->DrawCopy();     // histogram after
    1017 
    1018      //---------------------------------------------------------
    1019      */
    1020     //return kTRUE;
    1021986}
    1022987
     
    1028993Int_t MHMatrix::Read(const char *name)
    1029994{
    1030   Int_t ret = TObject::Read(name);
    1031   SetName(name);
    1032 
    1033   return ret;
    1034 }
    1035 
    1036 // --------------------------------------------------------------------------
     995    Int_t ret = TObject::Read(name);
     996    SetName(name);
     997
     998    return ret;
     999}
     1000
     1001// --------------------------------------------------------------------------
  • trunk/MagicSoft/Mars/mhist/MHMatrix.h

    r1853 r1879  
    4141    enum {
    4242        kIsOwner  = BIT(14),
    43         kIsLocked = BIT(16)
     43        kIsLocked = BIT(17)
    4444    };
    4545
     
    5151    Bool_t Finalize();
    5252
     53    void DrawDefRefInfo(const TH1 &hth, const TH1 &hthd, const TH1 &thsh, Int_t refcolumn);
     54    void GetRandomArrayI(TArrayI &ind) const;
     55
    5356    void StreamPrimitive(ofstream &out) const;
    5457
     
    5861    MHMatrix(const TMatrix &m, const char *name=NULL, const char *title=NULL);
    5962    ~MHMatrix();
     63
     64    static void CopyCrop(TMatrix &target, const TMatrix &source, Int_t rows);
    6065
    6166    void Lock()   { SetBit(kIsLocked); }
Note: See TracChangeset for help on using the changeset viewer.