ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitCommon/DataFormats/src/Hist1DRat.cc
Revision: 1.1
Committed: Wed Apr 29 15:14:05 2009 UTC (16 years ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_032, Mit_031, Mit_025c_branch2, Mit_025c_branch1, Mit_030, Mit_029c, Mit_030_pre1, Mit_029a, Mit_029, Mit_029_pre1, Mit_028a, Mit_025c_branch0, Mit_028, Mit_027a, Mit_027, Mit_026, Mit_025e, Mit_025d, Mit_025c, Mit_025b, Mit_025a, Mit_025, Mit_025pre2, Mit_024b, Mit_025pre1, Mit_024a, Mit_024, Mit_023, Mit_022a, Mit_022, Mit_020d, TMit_020d, Mit_020c, Mit_021, Mit_021pre2, Mit_021pre1, Mit_020b, Mit_020a, Mit_020, Mit_020pre1, Mit_018, Mit_017, Mit_017pre3, Mit_017pre2, Mit_017pre1, V07-05-00, Mit_016, Mit_015b, Mit_015a, Mit_015, Mit_014e, Mit_014d, Mit_014c, Mit_014b, ConvRejection-10-06-09, Mit_014a, Mit_014, Mit_014pre3, Mit_014pre2, Mit_014pre1, Mit_013d, Mit_013c, Mit_013b, Mit_013a, Mit_013, Mit_013pre1, Mit_012i, Mit_012g, Mit_012f, Mit_012e, Mit_012d, Mit_012c, Mit_012b, Mit_012a, Mit_012, Mit_011a, Mit_008, Mit_011, Mit_010a, Mit_010, Mit_009c, Mit_009b, Mit_009a, HEAD
Branch point for: Mit_025c_branch
Log Message:
Added histogram ratio class.

File Contents

# Content
1 // $Id: Vect3.cc,v 1.1 2009/03/08 12:00:54 loizides Exp $
2
3 #include "MitCommon/DataFormats/interface/Hist1DRat.h"
4 #include <TList.h>
5
6 ClassImp(mithep::Hist1DRat)
7
8 using namespace mithep;
9
10 //--------------------------------------------------------------------------------------------------
11 Hist1DRat::Hist1DRat(const char *name, const char *title, Int_t nbinsx, Double_t xlow, Double_t xup)
12 : fNum(Form("%s_num",name),title,nbinsx,xlow,xup),
13 fDen(Form("%s_den",name),title,nbinsx,xlow,xup),
14 fRat(0)
15 {
16 // Constructor.
17 }
18
19 //--------------------------------------------------------------------------------------------------
20 void Hist1DRat::Browse(TBrowser *b)
21 {
22 // Browse ratio histogram.
23
24 Create();
25 fRat->Browse(b);
26 }
27
28 //--------------------------------------------------------------------------------------------------
29 void Hist1DRat::Create()
30 {
31 // Create ratio histogram if needed
32
33 if (fRat)
34 return;
35
36 fRat = dynamic_cast<TH1D*>(fNum.Clone(GetName()));
37 fRat->Divide(&fDen);
38 }
39
40 //--------------------------------------------------------------------------------------------------
41 void Hist1DRat::Draw(Option_t *option)
42 {
43 // Create ratio histogram if needed and draw it afterwards.
44
45 Create();
46 fRat->Draw(option);
47 }
48
49 //--------------------------------------------------------------------------------------------------
50 void Hist1DRat::Fill(Double_t x, Double_t weight)
51 {
52 // Fill histograms.
53
54 fNum.Fill(x,weight);
55 fDen.Fill(x,weight);
56 Reset();
57 }
58
59 //--------------------------------------------------------------------------------------------------
60 void Hist1DRat::FillDen(Double_t x, Double_t weight)
61 {
62 // Fill denominator.
63
64 fDen.Fill(x,weight);
65 Reset();
66 }
67
68
69 //--------------------------------------------------------------------------------------------------
70 void Hist1DRat::FillNum(Double_t x, Double_t weight)
71 {
72 // Fill numerator.
73
74 fNum.Fill(x,weight);
75 Reset();
76 }
77
78 Long64_t Hist1DRat::Merge(TCollection *list)
79 {
80 // Merge numerator and denominator histograms.
81
82 TList nhs;
83 TList dhs;
84
85 TIter next(list);
86 while (TObject *o = next()) {
87 Hist1DRat *rat = dynamic_cast<Hist1DRat*>(o);
88 if (rat) {
89 nhs.Add(const_cast<TH1D*>(rat->GetNum()));
90 dhs.Add(const_cast<TH1D*>(rat->GetDen()));
91 }
92 }
93
94 Long64_t nres = fNum.Merge(&nhs);
95 Long64_t dres = fDen.Merge(&dhs);
96
97 Reset();
98 return nres+dres;
99 }