Changeset 4966 for trunk/MagicSoft/Mars/mhbase
- Timestamp:
- 09/13/04 08:57:58 (20 years ago)
- Location:
- trunk/MagicSoft/Mars/mhbase
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mhbase/MBinning.cc
r4920 r4966 18 18 ! Author(s): Thomas Bretz, 01/2002 <mailto:tbretz@astro.uni-wuerzburg.de> 19 19 ! 20 ! Copyright: MAGIC Software Development, 2000-200 320 ! Copyright: MAGIC Software Development, 2000-2004 21 21 ! 22 22 ! … … 24 24 25 25 ////////////////////////////////////////////////////////////////////////////// 26 // // 27 // MBinning // 28 // // 26 // 27 // MBinning 28 // 29 // This is a MParCOntainer storing a binning for a histogram. Doing this 30 // you are able to distribute a single binning to several histograms 31 // in your parameter list. 32 // 33 // In some classes the title of the container is used to set the 34 // axis-title of the corresponding axis in your histogram. 35 // 36 // For all the features supported see the function descriptions in 37 // MBinning and MH 38 // 29 39 ////////////////////////////////////////////////////////////////////////////// 30 40 #include "MBinning.h" … … 64 74 } 65 75 76 // -------------------------------------------------------------------------- 77 // 78 // Instantiate MBinning with nbins number of bins between lo (lower edge) 79 // and hi (upper edge), name name and title title. 80 // 66 81 MBinning::MBinning(Int_t nbins, Axis_t lo, Axis_t hi, const char *name, const char *opt, const char *title) 67 82 { … … 70 85 71 86 SetEdges(nbins, lo, hi, opt); 72 73 } 74 87 } 88 89 // -------------------------------------------------------------------------- 90 // 91 // Setup the edges stored in MBinning from the TAxis axe 92 // 75 93 void MBinning::SetEdges(const TAxis &axe) 76 94 { … … 85 103 } 86 104 105 // -------------------------------------------------------------------------- 106 // 107 // Add a new upper edge to the edges stored in MBinning. The new upper 108 // edge must be greater than the current greatest. Using this you can 109 // enhance a histogram bin-by-bin, eg: 110 // TH1F h("", "", 2, 0, 1); 111 // MBinning b; 112 // b.SetEdges(h); 113 // b.AddEdge(2); 114 // b.Apply(h); 115 // b.AddEdge(3); 116 // b.Apply(h); 117 // [...] 118 // 87 119 void MBinning::AddEdge(Axis_t up) 88 120 { … … 101 133 } 102 134 135 void MBinning::RemoveFirstEdge() 136 { 137 const Int_t n = fEdges.GetSize(); 138 for (int i=0; i<n-1; i++) 139 fEdges[i] = fEdges[i+1]; 140 fEdges.Set(n-1); 141 } 142 143 void MBinning::RemoveLastEdge() 144 { 145 fEdges.Set(fEdges.GetSize()-1); 146 } 147 148 // -------------------------------------------------------------------------- 149 // 150 // Set the edges in MBinning from a histogram-axis. Which axis is 151 // specified by axis ('x', 'y', 'z') 152 // 103 153 void MBinning::SetEdges(const TH1 &h, const Char_t axis) 104 154 { 105 TH1 &hist = (TH1&)h; // get rid of const qualifier106 155 switch (tolower(axis)) 107 156 { 108 157 case 'x': 109 SetEdges(*h ist.GetXaxis());158 SetEdges(*h.GetXaxis()); 110 159 return; 111 160 case 'y': 112 SetEdges(*h ist.GetYaxis());161 SetEdges(*h.GetYaxis()); 113 162 return; 114 163 case 'z': 115 SetEdges(*h ist.GetZaxis());164 SetEdges(*h.GetZaxis()); 116 165 return; 117 166 default: 118 167 *fLog << warn << "MBinning::SetEdges: Axis '" << axis << "' unknown... using x." << endl; 119 SetEdges(*h ist.GetXaxis());168 SetEdges(*h.GetXaxis()); 120 169 } 121 170 } -
trunk/MagicSoft/Mars/mhbase/MBinning.h
r4920 r4966 46 46 47 47 void SetEdges(const TAxis &axe); 48 void SetEdges(const MBinning &bins) { SetEdges(fEdges); } 48 49 void SetEdges(const TH1 &h, const Char_t axis='x'); 49 50 void SetEdges(const Int_t nbins, const Axis_t lo, Axis_t up); … … 59 60 for (int i=1; i<fEdges.GetSize(); i++) 60 61 { 61 if ( ((TArrayD)fEdges)[i] >= val)62 if (fEdges[i] >= val) 62 63 return i-1; 63 64 } … … 70 71 } 71 72 72 // FIXME: ROOT workaround: "operator[] const" missing 73 Double_t GetEdgeLo() const { return ((TArrayD)fEdges)[0]; } 74 Double_t GetEdgeHi() const { return ((TArrayD)fEdges)[fEdges.GetSize()-1]; } 73 Double_t GetEdgeLo() const { return fEdges[0]; } 74 Double_t GetEdgeHi() const { return fEdges[fEdges.GetSize()-1]; } 75 75 76 Int_t GetNumEdges() const { return fEdges.GetSize(); }77 Int_t GetNumBins() const { return fEdges.GetSize()-1; }76 Int_t GetNumEdges() const { return fEdges.GetSize(); } 77 Int_t GetNumBins() const { return fEdges.GetSize()-1; } 78 78 79 79 Double_t *GetEdges() const { return (Double_t*)fEdges.GetArray(); } 80 const TArrayD &GetEdgesD() const { return fEdges; } 80 81 81 82 void AddEdge(Axis_t up); 83 void RemoveFirstEdge(); 84 void RemoveLastEdge(); 82 85 83 Bool_t IsLinear() const { return fType==kIsLinear; }86 Bool_t IsLinear() const { return fType==kIsLinear; } 84 87 Bool_t IsLogarithmic() const { return fType==kIsLogarithmic; } 85 Bool_t IsCosinic() const { return fType==kIsCosinic; }86 Bool_t IsDefault() const { return fType==kIsDefault; }87 Bool_t IsUserArray() const { return fType==kIsUserArray; }88 Bool_t IsCosinic() const { return fType==kIsCosinic; } 89 Bool_t IsDefault() const { return fType==kIsDefault; } 90 Bool_t IsUserArray() const { return fType==kIsUserArray; } 88 91 89 Bool_t HasTitle() const { return gsDefTitle!=fTitle; }92 Bool_t HasTitle() const { return gsDefTitle!=fTitle; } 90 93 91 94 void Apply(TH1 &) const; … … 95 98 96 99 #endif 97 -
trunk/MagicSoft/Mars/mhbase/MH.cc
r4956 r4966 478 478 } 479 479 480 void MH::RemoveFirstBin(TH1 &h) 481 { 482 if (h.InheritsFrom(TH2::Class()) || h.InheritsFrom(TH3::Class())) 483 return; 484 485 const Int_t n0 = h.GetNbinsX(); 486 if (n0<2) 487 return; 488 489 TArrayD val(n0-1); 490 TArrayD err(n0-1); 491 for (int i=1; i<n0; i++) 492 { 493 val[i-1] = h.GetBinContent(i+1); 494 err[i-1] = h.GetBinError(i+1); 495 } 496 497 MBinning bins; 498 bins.SetEdges(h, 'x'); 499 bins.RemoveFirstEdge(); 500 bins.Apply(h); 501 502 h.Reset(); 503 504 for (int i=1; i<n0; i++) 505 { 506 h.SetBinContent(i, val[i-1]); 507 h.SetBinError(i, err[i-1]); 508 } 509 } 510 480 511 // -------------------------------------------------------------------------- 481 512 // -
trunk/MagicSoft/Mars/mhbase/MH.h
r4956 r4966 69 69 static void SetBinning(TH1 *h, const TH1 *x); 70 70 71 static void RemoveFirstBin(TH1 &h); 72 71 73 static Bool_t ApplyBinning(const MParList &plist, TString name, TH1 *h); 72 74
Note:
See TracChangeset
for help on using the changeset viewer.