- Timestamp:
- 03/28/03 14:24:38 (22 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r1878 r1879 2 2 3 3 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 4 37 2003/03/28: Wolfgang Wittek 5 38 6 39 * mhist/MHMatrix.cc 7 - if nmaxevts>fM.GetNrows() set nmaxevts = fM.GetNrows() 40 - DefRefMatrix: if nmaxevts>fM.GetNrows() set 41 nmaxevts = fM.GetNrows() 8 42 9 43 * manalysis/MSelBasic.[h,cc] -
trunk/MagicSoft/Mars/mbase/MParContainer.h
r1574 r1879 36 36 private: 37 37 enum { 38 kIsSavedAsPrimitive = BIT(15)38 kIsSavedAsPrimitive = BIT(15), 39 39 }; 40 40 … … 44 44 45 45 public: 46 enum { 47 kEnableGraphicalOutput = BIT(16) 48 }; 49 46 50 MParContainer(const char *name="", const char *title="") : fName(name), fTitle(title), fLog(&gLog), fReadyToSave(kFALSE) { } 47 51 MParContainer(const TString &name, const TString &title) : fName(name), fTitle(title), fLog(&gLog), fReadyToSave(kFALSE) { } … … 76 80 virtual void SetReadyToSave(Bool_t flag=kTRUE) { fReadyToSave=flag; } 77 81 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); } 78 84 79 85 TMethodCall *GetterMethod(const char *name) const; -
trunk/MagicSoft/Mars/mbase/MParList.h
r1524 r1879 36 36 37 37 public: 38 enum { kDoNotReset = BIT(1 5) };38 enum { kDoNotReset = BIT(17) }; 39 39 40 40 MParList(const char *name=NULL, const char *title=NULL); -
trunk/MagicSoft/Mars/mhist/MH.cc
r1780 r1879 366 366 // Both histograms must be of the same type: TH1, TH2 or TH3 367 367 // 368 void MH::SetBinning(TH1 *h, TH1 *x)368 void MH::SetBinning(TH1 *h, const TH1 *x) 369 369 { 370 370 if (h->InheritsFrom(TH3::Class()) && x->InheritsFrom(TH3::Class())) 371 371 { 372 SetBinning((TH3*)h, x->GetXaxis(), x->GetYaxis(), x->GetZaxis());372 SetBinning((TH3*)h, ((TH1*)x)->GetXaxis(), ((TH1*)x)->GetYaxis(), ((TH1*)x)->GetZaxis()); 373 373 return; 374 374 } … … 377 377 if (h->InheritsFrom(TH2::Class()) && x->InheritsFrom(TH2::Class())) 378 378 { 379 SetBinning((TH2*)h, x->GetXaxis(), x->GetYaxis());379 SetBinning((TH2*)h, ((TH1*)x)->GetXaxis(), ((TH1*)x)->GetYaxis()); 380 380 return; 381 381 } … … 384 384 if (h->InheritsFrom(TH1::Class()) && x->InheritsFrom(TH1::Class())) 385 385 { 386 SetBinning(h, x->GetXaxis());386 SetBinning(h, ((TH1*)x)->GetXaxis()); 387 387 return; 388 388 } -
trunk/MagicSoft/Mars/mhist/MH.h
r1668 r1879 46 46 static void SetBinning(TH3 *h, const TAxis *binsx, const TAxis *binsy, const TAxis *binsz); 47 47 48 static void SetBinning(TH1 *h, TH1 *x);48 static void SetBinning(TH1 *h, const TH1 *x); 49 49 50 50 static Bool_t ApplyBinning(const MParList &plist, TString name, TH1 *h); -
trunk/MagicSoft/Mars/mhist/MH3.h
r1832 r1879 27 27 28 28 enum { 29 kIsLogx = BIT(1 5),30 kIsLogy = BIT(1 6),31 kIsLogz = BIT(1 7)29 kIsLogx = BIT(17), 30 kIsLogy = BIT(18), 31 kIsLogz = BIT(19) 32 32 }; 33 33 -
trunk/MagicSoft/Mars/mhist/MHMatrix.cc
r1874 r1879 250 250 return kTRUE; 251 251 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 } 259 257 260 258 return kTRUE; … … 687 685 // ------------------------------------------------------------------------ 688 686 // 687 // Used in DefRefMatrix to display the result graphically 688 // 689 void 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 // 723 void 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 // 689 734 // 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, 691 736 // for which a target distribution may be given; 692 // if refcolumn is negative the target distribution will be set693 // equal to the real distribution; the events in the reference694 // matrix will then be simply a random selection of the events695 // in the original matrix.696 737 // thsh histogram containing the target distribution of the variable 697 738 // nmaxevts maximum number of events in the reference matrix … … 709 750 } 710 751 711 if (refcolumn==0)712 {713 *fLog << err << dbginf << "Reference column 0 unknown." << endl;714 return kFALSE;715 }716 717 752 if (thsh.GetMinimum()<0) 718 753 { … … 737 772 738 773 // 739 // if refcolumn < 0 : select reference events randomly740 // i.e. set the normaliztion factotrs equal to 1.0741 774 // refcol is the column number starting at 0; it is >= 0 742 775 // … … 758 791 // set up the real histogram (distribution before) 759 792 // 760 TH1F hth("th", " data at input", nbins, frombin, tobin);793 TH1F hth("th", "Distribution before reduction", nbins, frombin, tobin); 761 794 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); 767 798 hthd.Divide((TH1F*)&thsh, &hth, 1, 1); 768 799 … … 781 812 // get random access 782 813 // 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 789 814 TArrayI ind(nrows); 790 TMath::Sort(nrows, ranx.GetArray(), ind.GetArray(), kTRUE);815 GetRandomArrayI(ind); 791 816 792 817 // … … 805 830 // 806 831 TVector v(fM.GetNrows()); 807 v = TMatrixColumn(fM, refcolumn -1);832 v = TMatrixColumn(fM, refcolumn); 808 833 v += -frombin; 809 834 v *= 1/dbin; … … 842 867 // this is the matrix to be used in the g/h separation 843 868 // 844 fM.ResizeTo(evtcount1, ncols);869 CopyCrop(fM, mnewtmp, evtcount1); 845 870 fNumRow = evtcount1; 846 for (ir=0; ir<evtcount1; ir++)847 TMatrixRow(fM, ir) = vold = TMatrixRow(mnewtmp, ir);848 871 849 872 if (evtcount1 < nmaxevts) 850 873 *fLog << warn << "The reference sample contains less events (" << evtcount1 << ") than required (" << nmaxevts << ")" << endl; 851 874 875 if (TestBit(kEnableGraphicalOutput)) 876 DrawDefRefInfo(hth, hthd, thsh, refcolumn); 877 852 878 if (!rest) 853 879 return kTRUE; 854 880 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); 861 882 862 883 return kTRUE; … … 865 886 // ------------------------------------------------------------------------ 866 887 // 888 // Returns a array containing randomly sorted indices 889 // 890 void 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 // 867 905 // 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 set871 // equal to the real distribution; the events in the reference872 // matrix will then be simply a random selection of the events873 // in the original matrix.874 // thsh histogram containing the target distribution of the variable875 906 // nmaxevts maximum number of events in the reference matrix 876 907 // rest a TMatrix conatining the resulting (not choosen) … … 878 909 // are not interested in this 879 910 // 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 // 880 916 Bool_t MHMatrix::DefRefMatrix(Int_t nmaxevts, TMatrix *rest) 881 917 { … … 907 943 // get random access 908 944 // 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 915 945 TArrayI ind(nrows); 916 TMath::Sort(nrows, ranx.GetArray(), ind.GetArray(), kTRUE);946 GetRandomArrayI(ind); 917 947 918 948 // … … 942 972 // this is the matrix to be used in the g/h separation 943 973 // 944 fM.ResizeTo(evtcount1, ncols);974 CopyCrop(fM, mnewtmp, evtcount1); 945 975 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 }951 976 952 977 if (evtcount1 < nmaxevts) … … 956 981 return kTRUE; 957 982 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); 964 984 965 985 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 contents991 *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 histograms1003 TCanvas *th1 = new TCanvas (fName, fName, 1);1004 th1->Divide(2,2);1005 1006 th1->cd(1);1007 ((TH1F*)fHthsh)->DrawCopy(); // target1008 1009 th1->cd(2);1010 ((TH1F*)fHth)->DrawCopy(); // real histogram before1011 1012 th1->cd(3);1013 ((TH1F*)fHthd)->DrawCopy(); // correction factors1014 1015 th1->cd(4);1016 ((TH1F*)fHthaft)->DrawCopy(); // histogram after1017 1018 //---------------------------------------------------------1019 */1020 //return kTRUE;1021 986 } 1022 987 … … 1028 993 Int_t MHMatrix::Read(const char *name) 1029 994 { 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 41 41 enum { 42 42 kIsOwner = BIT(14), 43 kIsLocked = BIT(1 6)43 kIsLocked = BIT(17) 44 44 }; 45 45 … … 51 51 Bool_t Finalize(); 52 52 53 void DrawDefRefInfo(const TH1 &hth, const TH1 &hthd, const TH1 &thsh, Int_t refcolumn); 54 void GetRandomArrayI(TArrayI &ind) const; 55 53 56 void StreamPrimitive(ofstream &out) const; 54 57 … … 58 61 MHMatrix(const TMatrix &m, const char *name=NULL, const char *title=NULL); 59 62 ~MHMatrix(); 63 64 static void CopyCrop(TMatrix &target, const TMatrix &source, Int_t rows); 60 65 61 66 void Lock() { SetBit(kIsLocked); }
Note:
See TracChangeset
for help on using the changeset viewer.