@@ -1851,6 +1851,7 @@ TProfile *TH2::DoProfile(bool onX, const char *name, Int_t firstbin, Int_t lastb
18511851 }
18521852 opt.ToLower ();
18531853 bool originalRange = opt.Contains (" o" );
1854+ bool useWidth = opt.Contains (" width" );
18541855
18551856 const TAxis& outAxis = ( onX ? fXaxis : fYaxis );
18561857 const TAxis& inAxis = ( onX ? fYaxis : fXaxis );
@@ -1990,13 +1991,13 @@ TProfile *TH2::DoProfile(bool onX, const char *name, Int_t firstbin, Int_t lastb
19901991 }
19911992 Int_t bin = GetBin (binx, biny);
19921993 Double_t cxy = RetrieveBinContent (bin);
1993-
1994+ double step = useWidth ? inAxis. GetBinWidth (inbin) : 1 ;
19941995
19951996 if (cxy) {
19961997 Double_t tmp = 0 ;
19971998 // the following fill update wrongly the fBinSumw2- need to save it before
19981999 if ( useWeights ) tmp = binSumw2.fArray [binOut];
1999- h1->Fill ( xOut, inAxis.GetBinCenter (inbin), cxy );
2000+ h1->Fill ( xOut, inAxis.GetBinCenter (inbin), cxy * step );
20002001 if ( useWeights ) binSumw2.fArray [binOut] = tmp + fSumw2 .fArray [bin];
20012002 }
20022003
@@ -2026,9 +2027,9 @@ TProfile *TH2::DoProfile(bool onX, const char *name, Int_t firstbin, Int_t lastb
20262027
20272028
20282029// //////////////////////////////////////////////////////////////////////////////
2029- // / Project a 2-D histogram into a profile histogram along X.
2030+ // / Project a 2-D histogram into a profile histogram along X (integration along Y) .
20302031// /
2031- // / The projection is made from the channels along the Y axis
2032+ // / The projection is made from summing the channels along the Y axis
20322033// / ranging from firstybin to lastybin included.
20332034// / By default, bins 1 to ny are included
20342035// / When all bins are included, the number of entries in the projection
@@ -2040,6 +2041,9 @@ TProfile *TH2::DoProfile(bool onX, const char *name, Int_t firstbin, Int_t lastb
20402041// / if option "o" original axis range of the target axes will be
20412042// / kept, but only bins inside the selected range will be filled.
20422043// /
2044+ // / if option "width" is specified, each bin content is multiplied
2045+ // / by its Y bin-width during projection
2046+ // /
20432047// / The option can also be used to specify the projected profile error type.
20442048// / Values which can be used are 's', 'i', or 'g'. See TProfile::BuildOptions for details
20452049// /
@@ -2076,9 +2080,9 @@ TProfile *TH2::ProfileX(const char *name, Int_t firstybin, Int_t lastybin, Optio
20762080
20772081
20782082// //////////////////////////////////////////////////////////////////////////////
2079- // / Project a 2-D histogram into a profile histogram along Y.
2083+ // / Project a 2-D histogram into a profile histogram along Y (integration along X) .
20802084// /
2081- // / The projection is made from the channels along the X axis
2085+ // / The projection is made from summing the channels along the X axis
20822086// / ranging from firstxbin to lastxbin included.
20832087// / By default, bins 1 to nx are included
20842088// / When all bins are included, the number of entries in the projection
@@ -2090,6 +2094,9 @@ TProfile *TH2::ProfileX(const char *name, Int_t firstybin, Int_t lastybin, Optio
20902094// / if option "o" , the original axis range of the target axis will be
20912095// / kept, but only bins inside the selected range will be filled.
20922096// /
2097+ // / if option "width" is specified, each bin content is multiplied
2098+ // / by its X bin-width during projection
2099+ // /
20932100// / The option can also be used to specify the projected profile error type.
20942101// / Values which can be used are 's', 'i', or 'g'. See TProfile::BuildOptions for details
20952102// / Using a TCutG object, it is possible to select a sub-range of a 2-D histogram.
@@ -2144,6 +2151,7 @@ TH1D *TH2::DoProjection(bool onX, const char *name, Int_t firstbin, Int_t lastbi
21442151 }
21452152 opt.ToLower (); // must be called after having parsed the cut name
21462153 bool originalRange = opt.Contains (" o" );
2154+ bool useWidth = opt.Contains (" width" );
21472155
21482156 if ( onX )
21492157 {
@@ -2286,9 +2294,10 @@ TH1D *TH2::DoProjection(bool onX, const char *name, Int_t firstbin, Int_t lastbi
22862294 if (!fPainter ->IsInside (binx,biny)) continue ;
22872295 }
22882296 // sum bin content and error if needed
2289- cont += GetBinContent (binx,biny);
2297+ double step = useWidth ? inAxis->GetBinWidth (inbin) : 1 ;
2298+ cont += GetBinContent (binx,biny)*step;
22902299 if (computeErrors) {
2291- Double_t exy = GetBinError (binx,biny);
2300+ Double_t exy = GetBinError (binx,biny)*step ;
22922301 err2 += exy*exy;
22932302 }
22942303 }
@@ -2363,10 +2372,10 @@ TH1D *TH2::DoProjection(bool onX, const char *name, Int_t firstbin, Int_t lastbi
23632372
23642373
23652374// //////////////////////////////////////////////////////////////////////////////
2366- // / Project a 2-D histogram into a 1-D histogram along X.
2375+ // / Project a 2-D histogram into a 1-D histogram along X (integration along Y) .
23672376// /
23682377// / The projection is always of the type TH1D.
2369- // / The projection is made from the channels along the Y axis
2378+ // / The projection is made from summing the channels along the Y axis
23702379// / ranging from firstybin to lastybin included.
23712380// / By default, all bins including under- and overflow are included.
23722381// / The number of entries in the projection is estimated from the
@@ -2380,6 +2389,9 @@ TH1D *TH2::DoProjection(bool onX, const char *name, Int_t firstbin, Int_t lastbi
23802389// / if option "o" original axis range of the target axes will be
23812390// / kept, but only bins inside the selected range will be filled.
23822391// /
2392+ // / if option "width" is specified, each bin content is multiplied
2393+ // / by its Y bin-width during projection
2394+ // /
23832395// / Using a TCutG object, it is possible to select a sub-range of a 2-D histogram.
23842396// / One must create a graphical cut (mouse or C++) and specify the name
23852397// / of the cut between [] in the option.
@@ -2402,10 +2414,10 @@ TH1D *TH2::ProjectionX(const char *name, Int_t firstybin, Int_t lastybin, Option
24022414
24032415
24042416// //////////////////////////////////////////////////////////////////////////////
2405- // / Project a 2-D histogram into a 1-D histogram along Y.
2417+ // / Project a 2-D histogram into a 1-D histogram along Y (integration along X) .
24062418// /
24072419// / The projection is always of the type TH1D.
2408- // / The projection is made from the channels along the X axis
2420+ // / The projection is made from summing the channels along the X axis
24092421// / ranging from firstxbin to lastxbin included.
24102422// / By default, all bins including under- and overflow are included.
24112423// / The number of entries in the projection is estimated from the
@@ -2419,6 +2431,9 @@ TH1D *TH2::ProjectionX(const char *name, Int_t firstybin, Int_t lastybin, Option
24192431// / if option "o" original axis range of the target axes will be
24202432// / kept, but only bins inside the selected range will be filled.
24212433// /
2434+ // / if option "width" is specified, each bin content is multiplied
2435+ // / by its X bin-width during projection
2436+ // /
24222437// / Using a TCutG object, it is possible to select a sub-range of a 2-D histogram.
24232438// / One must create a graphical cut (mouse or C++) and specify the name
24242439// / of the cut between [] in the option.
0 commit comments