ATLAS Offline Software
Loading...
Searching...
No Matches
IPlotBase.cxx
Go to the documentation of this file.
1
12
13#include "IPlotBase.h"
14#include "MsgMacros.h"
15
16#include "Resplot/Resplot.h"
17
18
19
20void IDTPM2::IPlotBase::copyHist( TH1* hsrc, TH1* hdest, bool copyoverflow ) const {
21
22 if ( hsrc->GetNbinsX()!=hdest->GetNbinsX() ) return; // do we want to give an error message ?? throw and exception ??
23
24 int imin = 0;
25 int imax = hsrc->GetNbinsX()+1;
26
27 if ( !copyoverflow ) {
28 imin = 1;
29 imax = hsrc->GetNbinsX();
30 }
31
32 for ( int i=imin ; i<=imax ; i++ ) {
33 hdest->SetBinContent( i, hsrc->GetBinContent(i) );
34 hdest->SetBinError( i, hsrc->GetBinError(i) );
35 }
36
37 hdest->SetEntries( hsrc->GetEntries() );
38}
39
40
41
42void IDTPM2::IPlotBase::getHist( ServiceHandle<ITHistSvc>& histsvc, const std::string& hname, TH1* hsrc ) const {
43 TH1* h = 0;
44 if ( histsvc->getHist( hname, h ).isFailure() ) MY_MSG_WARNING << "Could not retieve histogram: " << hname << endmsg;
45 else copyHist( hsrc, h );
46}
47
48
49void IDTPM2::IPlotBase::processResolution( ServiceHandle<ITHistSvc>& histsvc, const std::string& path, bool writeflag ) const {
50
51 TH2* hist2d = 0;
52
53 if ( histsvc->getHist( path+"2D", hist2d ).isFailure() ) MY_MSG_WARNING << "Could not retieve 2D: " << (path+"2D") << endmsg;
54 else {
55
60
61 Resplot::Resplot rp( path, hist2d );
62
63 rp.Finalise( Resplot::FitNull95 );
64
65 if ( !writeflag ) {
68 // if ( histsvc->regHist( path+"1D", rp.H1D() ).isFailure() ) MY_MSG_WARNING << "Unable to register histogram: 1D: " << name() << endmsg;
69 // if ( histsvc->regHist( path+"mean", rp.Mean() ).isFailure() ) MY_MSG_WARNING << "Unable to register histogram: mean: " << name() << endmsg;
70 // if ( histsvc->regHist( path+"sigma", rp.Sigma() ).isFailure() ) MY_MSG_WARNING << "Unable to register histogram: sigma: " << name() << endmsg;
71 // }
72 // else {
74 getHist( histsvc, path+"1D", rp.H1D() );
75 getHist( histsvc, path+"mean", rp.Mean() );
76 getHist( histsvc, path+"sigma", rp.Sigma() );
77 }
78 }
79
80}
81
82
86std::string IDTPM2::IPlotBase::realPath( const std::string& tag ) {
87
88 std::string dir = (*monTool())->getPath();
89
91 std::string stub = dir.substr( dir.find('/', 1) + 1 ) + tag;
92
93 const std::vector<std::string>& allhists = histSvc()->getHists();
94
95 std::string basestr = "";
96
97 for ( size_t i=0 ; i<allhists.size() ; i++ ) {
98 if ( allhists[i].find(stub)!=std::string::npos ) {
99 std::string s = allhists[i];
100 basestr = s.substr(0,s.find("/"+stub)+1);
101 break;
102 }
103 }
104
105 return basestr + stub;
106
107}
108
109
110
111
112
113#if 0
114
115void IDTPM2::IPlotBase::binWidthNormalise( ServiceHandle<ITHistSvc>& histsvc, const std::string& hname ) const {
116 TH1* h = 0;
117 if ( histsvc->getHist( hname, h ).isFailure() ) MY_MSG_WARNING << "Could not retieve histogram: " << hname << endmsg;
118 else binWidthNormalise( h );
119}
120
121
122void IDTPM2::IPlotBase::binWidthNormalize( TH1* h ) const {
123
124 if ( !h ) return;
125
126 int nbins = h->GetNbinsX();
127 double width = h->GetBinWidth(1);
128
129 double eps = 1e-12;
130
131 bool variable = false;
132
133 for ( int i=2 ; i<=nbins ; i++ ) {
134 if ( std::fabs( h->GetBinWidth(i)-width )>eps ) {
135 variable = true;
136 break;
137 }
138 }
139
140 if ( !variable ) return;
141
142 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) {
143 double w = h->GetBinWidth(i);
144 h->SetBinContent( i, h->GetBinContent(i)/w );
145 h->SetBinError( i, h->GetBinError(i)/w );
146 }
147
148}
149
150#endif
#define endmsg
ReadCards * rp
emacs: this is -*- c++ -*-
#define MY_MSG_WARNING
Definition MsgMacros.h:23
const double width
int imax(int i, int j)
Header file for AthHistogramAlgorithm.
void copyHist(TH1 *hsrc, TH1 *hdest, bool copyoverflow=true) const
resolution porocessing stuff these don't really even need to be class functions, they could be simply...
Definition IPlotBase.cxx:20
void getHist(const std::string &hname, TH1 *hsrc)
Definition IPlotBase.h:88
void processResolution(const std::string &path, bool writeflag=false)
Definition IPlotBase.h:89
ToolHandle< GenericMonitoringTool > * monTool()
mon tool
Definition IPlotBase.h:71
std::string realPath(const std::string &tag="")
This is a horrific function, has to get ALL the histograms, just to be able to work out how to get th...
Definition IPlotBase.cxx:86
virtual ServiceHandle< ITHistSvc > & histSvc()
we may well need these at some point ...
Definition IPlotBase.h:105
bool allhists
Definition hcg.cxx:81
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:140
TF1 * FitNull95(TH1D *s, double a=0, double b=0)
Definition Resplot.cxx:1472