@@ -1942,6 +1942,44 @@ RooPlot *RooAbsData::plotOn(RooPlot *frame, PlotOpt o) const
1942
1942
return frame;
1943
1943
}
1944
1944
1945
+ namespace {
1946
+
1947
+ RooHist *createAndFillRooHist (RooAbsData const &absData, RooPlot const &frame, RooAbsRealLValue const &var,
1948
+ std::string cuts1, std::string cuts2, RooAbsData::PlotOpt opt, bool efficiency,
1949
+ double scaleFactor)
1950
+ {
1951
+ // create and fill temporary histograms of this variable for each state
1952
+ std::string hist1Name = std::string{absData.GetName ()} + " _plot_1" ;
1953
+ std::string hist2Name = std::string{absData.GetName ()} + " _plot_2" ;
1954
+ std::unique_ptr<TH1> hist1;
1955
+ std::unique_ptr<TH1> hist2;
1956
+
1957
+ if (opt.bins ) {
1958
+ hist1.reset (var.createHistogram (hist1Name.c_str (), " Events" , *opt.bins ));
1959
+ hist2.reset (var.createHistogram (hist2Name.c_str (), " Events" , *opt.bins ));
1960
+ } else {
1961
+ auto &axis = *frame.GetXaxis ();
1962
+ hist1.reset (var.createHistogram (hist1Name.c_str (), " Events" , axis.GetXmin (), axis.GetXmax (), frame.GetNbinsX ()));
1963
+ hist2.reset (var.createHistogram (hist2Name.c_str (), " Events" , axis.GetXmin (), axis.GetXmax (), frame.GetNbinsX ()));
1964
+ }
1965
+
1966
+ if (opt.cuts && strlen (opt.cuts )) {
1967
+ std::string cuts = opt.cuts ;
1968
+ cuts1 += " &&(" + cuts + " )" ;
1969
+ cuts2 += " &&(" + cuts + " )" ;
1970
+ }
1971
+
1972
+ if (!absData.fillHistogram (hist1.get (), RooArgList (var), cuts1.c_str (), opt.cutRange ) ||
1973
+ !absData.fillHistogram (hist2.get (), RooArgList (var), cuts2.c_str (), opt.cutRange )) {
1974
+ return nullptr ;
1975
+ }
1976
+
1977
+ // convert this histogram to a RooHist object on the heap
1978
+ return new RooHist (*hist1, *hist2, 0 , 1 , opt.etype , opt.xErrorSize , efficiency, scaleFactor);
1979
+ }
1980
+
1981
+ } // namespace
1982
+
1945
1983
// //////////////////////////////////////////////////////////////////////////////
1946
1984
// / Create and fill a histogram with the asymmetry N[+] - N[-] / ( N[+] + N[-] ),
1947
1985
// / where N(+/-) is the number of data points with asymCat=+1 and asymCat=-1
@@ -1969,47 +2007,13 @@ RooPlot* RooAbsData::plotAsymOn(RooPlot* frame, const RooAbsCategoryLValue& asym
1969
2007
return nullptr ;
1970
2008
}
1971
2009
1972
- // create and fill temporary histograms of this variable for each state
1973
- std::string hist1Name (GetName ());
1974
- std::string hist2Name (GetName ());
1975
- hist1Name += " _plot1" ;
1976
- std::unique_ptr<TH1> hist1;
1977
- std::unique_ptr<TH1> hist2;
1978
- hist2Name += " _plot2" ;
1979
-
1980
- if (o.bins ) {
1981
- hist1.reset ( var->createHistogram (hist1Name.c_str (), " Events" , *o.bins ) );
1982
- hist2.reset ( var->createHistogram (hist2Name.c_str (), " Events" , *o.bins ) );
1983
- } else {
1984
- hist1.reset ( var->createHistogram (hist1Name.c_str (), " Events" ,
1985
- frame->GetXaxis ()->GetXmin (), frame->GetXaxis ()->GetXmax (),
1986
- frame->GetNbinsX ()) );
1987
- hist2.reset ( var->createHistogram (hist2Name.c_str (), " Events" ,
1988
- frame->GetXaxis ()->GetXmin (), frame->GetXaxis ()->GetXmax (),
1989
- frame->GetNbinsX ()) );
1990
- }
1991
-
1992
- assert (hist1 && hist2);
1993
-
1994
- std::string cuts1;
1995
- std::string cuts2;
1996
- if (o.cuts && strlen (o.cuts )) {
1997
- cuts1 = Form (" (%s)&&(%s>0)" ,o.cuts ,asymCat.GetName ());
1998
- cuts2 = Form (" (%s)&&(%s<0)" ,o.cuts ,asymCat.GetName ());
1999
- } else {
2000
- cuts1 = Form (" (%s>0)" ,asymCat.GetName ());
2001
- cuts2 = Form (" (%s<0)" ,asymCat.GetName ());
2002
- }
2003
-
2004
- if (! fillHistogram (hist1.get (), RooArgList (*var),cuts1.c_str (),o.cutRange ) ||
2005
- ! fillHistogram (hist2.get (), RooArgList (*var),cuts2.c_str (),o.cutRange )) {
2006
- coutE (Plotting) << ClassName () << " ::" << GetName ()
2007
- << " :plotAsymOn: createHistogram() failed" << std::endl;
2008
- return nullptr ;
2010
+ std::string catName = asymCat.GetName ();
2011
+ RooHist *graph =
2012
+ createAndFillRooHist (*this , *frame, *var, " (" + catName + " >0)" , " (" + catName + " <0)" , o, false , o.scaleFactor );
2013
+ if (graph == nullptr ) {
2014
+ coutE (Plotting) << ClassName () << " ::" << GetName () << " :plotAsymOn: createHistogram() failed" << std::endl;
2015
+ return nullptr ;
2009
2016
}
2010
-
2011
- // convert this histogram to a RooHist object on the heap
2012
- RooHist *graph= new RooHist (*hist1,*hist2,0 ,1 ,o.etype ,o.xErrorSize ,false ,o.scaleFactor );
2013
2017
graph->setYAxisLabel ((std::string{" Asymmetry in " } + asymCat.GetName ()).c_str ());
2014
2018
2015
2019
// initialize the frame's normalization setup, if necessary
@@ -2063,48 +2067,16 @@ RooPlot* RooAbsData::plotEffOn(RooPlot* frame, const RooAbsCategoryLValue& effCa
2063
2067
return nullptr ;
2064
2068
}
2065
2069
2066
- // create and fill temporary histograms of this variable for each state
2067
- std::string hist1Name (GetName ());
2068
- std::string hist2Name (GetName ());
2069
- hist1Name += " _plot1" ;
2070
- std::unique_ptr<TH1> hist1;
2071
- std::unique_ptr<TH1> hist2;
2072
- hist2Name += " _plot2" ;
2070
+ std::string catName = effCat.GetName ();
2071
+ RooHist *graph =
2072
+ createAndFillRooHist (*this , *frame, *var, " (" + catName + " ==1)" , " (" + catName + " ==0)" , o, true , 1.0 );
2073
2073
2074
- if (o.bins ) {
2075
- hist1.reset ( var->createHistogram (hist1Name.c_str (), " Events" , *o.bins ) );
2076
- hist2.reset ( var->createHistogram (hist2Name.c_str (), " Events" , *o.bins ) );
2077
- } else {
2078
- hist1.reset ( var->createHistogram (hist1Name.c_str (), " Events" ,
2079
- frame->GetXaxis ()->GetXmin (), frame->GetXaxis ()->GetXmax (),
2080
- frame->GetNbinsX ()) );
2081
- hist2.reset ( var->createHistogram (hist2Name.c_str (), " Events" ,
2082
- frame->GetXaxis ()->GetXmin (), frame->GetXaxis ()->GetXmax (),
2083
- frame->GetNbinsX ()) );
2074
+ if (graph == nullptr ) {
2075
+ coutE (Plotting) << ClassName () << " ::" << GetName () << " :plotEffOn: createHistogram() failed" << std::endl;
2076
+ return nullptr ;
2084
2077
}
2085
2078
2086
- assert (hist1 && hist2);
2087
-
2088
- std::string cuts1;
2089
- std::string cuts2;
2090
- if (o.cuts && strlen (o.cuts )) {
2091
- cuts1 = Form (" (%s)&&(%s==1)" ,o.cuts ,effCat.GetName ());
2092
- cuts2 = Form (" (%s)&&(%s==0)" ,o.cuts ,effCat.GetName ());
2093
- } else {
2094
- cuts1 = Form (" (%s==1)" ,effCat.GetName ());
2095
- cuts2 = Form (" (%s==0)" ,effCat.GetName ());
2096
- }
2097
-
2098
- if (! fillHistogram (hist1.get (), RooArgList (*var),cuts1.c_str (),o.cutRange ) ||
2099
- ! fillHistogram (hist2.get (), RooArgList (*var),cuts2.c_str (),o.cutRange )) {
2100
- coutE (Plotting) << ClassName () << " ::" << GetName ()
2101
- << " :plotEffOn: createHistogram() failed" << std::endl;
2102
- return nullptr ;
2103
- }
2104
-
2105
- // convert this histogram to a RooHist object on the heap
2106
- RooHist *graph= new RooHist (*hist1,*hist2,0 ,1 ,o.etype ,o.xErrorSize ,true );
2107
- graph->setYAxisLabel (Form (" Efficiency of %s=%s" , effCat.GetName (), effCat.lookupName (1 ).c_str ()));
2079
+ graph->setYAxisLabel ((" Efficiency of " + catName + " =" + effCat.lookupName (1 )).c_str ());
2108
2080
2109
2081
// initialize the frame's normalization setup, if necessary
2110
2082
frame->updateNormVars (_vars);
@@ -2113,12 +2085,12 @@ RooPlot* RooAbsData::plotEffOn(RooPlot* frame, const RooAbsCategoryLValue& effCa
2113
2085
if (o.histName ) {
2114
2086
graph->SetName (o.histName ) ;
2115
2087
} else {
2116
- std::string hname ( Form ( " h_%s_Eff[%s] " , GetName (),effCat. GetName ())) ;
2117
- if (o.cutRange && strlen (o.cutRange )> 0 ) {
2118
- hname += Form ( " _CutRange[%s] " , o.cutRange ) ;
2088
+ std::string hname = " h_" + std::string{ GetName ()} + " _Eff[ " + catName + " ] " ;
2089
+ if (o.cutRange && strlen (o.cutRange ) > 0 ) {
2090
+ hname += " _CutRange[" + std::string{ o.cutRange } + " ] " ;
2119
2091
}
2120
2092
if (o.cuts && strlen (o.cuts )>0 ) {
2121
- hname += Form ( " _Cut[%s] " , o.cuts ) ;
2093
+ hname += " _Cut[" + std::string{ o.cuts } + " ] " ;
2122
2094
}
2123
2095
graph->SetName (hname.c_str ()) ;
2124
2096
}
@@ -2614,11 +2586,12 @@ TH2F *RooAbsData::createHistogram(const RooAbsRealLValue &var1, const RooAbsReal
2614
2586
}
2615
2587
}
2616
2588
2617
- const std::string histName = std::string{GetName ()} + " _" + name + " _" + Form (" %08x" , counter++);
2589
+ std::stringstream histName;
2590
+ histName << GetName () << " _" << name << " _" << std::setw (8 ) << std::setfill (' 0' ) << std::hex << counter++;
2618
2591
2619
2592
// create the histogram
2620
2593
auto *histogram =
2621
- new TH2F (histName.c_str (), " Events" , nx, var1.getMin (), var1.getMax (), ny, var2.getMin (), var2.getMax ());
2594
+ new TH2F (histName.str (). c_str (), " Events" , nx, var1.getMin (), var1.getMax (), ny, var2.getMin (), var2.getMax ());
2622
2595
if (!histogram) {
2623
2596
coutE (DataHandling) << GetName () << " ::createHistogram: unable to create a new histogram" << std::endl;
2624
2597
return nullptr ;
0 commit comments