18 #include "TRootEmbeddedCanvas.h"
21 #include "TPaveStats.h"
25 #define isfinite(x) _finite(x)
38 using std::stringstream;
45 fAutoSetNumberOfBins(true), fAutoSetXMax(true), fAutoSetXMin(true),
46 fBinWidth(0), fIsBinWidthSet(false), fNumberOfUniqueDataPoints(0),
47 fStyleHistogram(new TH1D())
52 SetBit(kCanDelete, kFALSE);
53 GetYaxis()->SetTitleOffset(1.35);
58 TH1D(histogram),
QGPlot(histogram),
59 fAutoSetNumberOfBins(histogram.fAutoSetNumberOfBins), fAutoSetXMax(histogram.fAutoSetXMax),
60 fAutoSetXMin(histogram.fAutoSetXMin), fBinWidth(histogram.fBinWidth),
61 fDataPoints(histogram.fDataPoints), fIsBinWidthSet(histogram.fIsBinWidthSet),
62 fNumberOfUniqueDataPoints(histogram.fNumberOfUniqueDataPoints), fStyleHistogram(new TH1D())
66 SetBit(kCanDelete, kFALSE);
88 editWindow->GetHistogramParametersFrame()->SetXMin(
GetXMin());
94 editWindow->GetHistogramParametersFrame()->SetXMax(
GetXMax());
104 Double_t xRangeFracPart = xRange - xRangeIntPart;
105 if (xRange < 1000.0 && xRangeFracPart == 0.0) {
112 editWindow->GetHistogramParametersFrame()->SetNumberOfBins(
GetNumberOfBins());
126 editWindow->GetHistogramParametersFrame()->SetXMin(
GetXMin());
127 editWindow->GetHistogramParametersFrame()->SetXMax(
GetXMax());
128 editWindow->GetHistogramParametersFrame()->SetNumberOfBins(
GetNumberOfBins());
140 Color_t line_color = 1;
141 set<Color_t> existingLineColors;
142 list<QGHistogram*>::const_iterator histogramIter;
144 existingLineColors.insert((*histogramIter)->GetLineColor());
147 existingLineColors.insert(10);
148 existingLineColors.insert(5);
149 while (existingLineColors.count(line_color) != 0)
184 vector<Double_t>::const_iterator iter;
192 stringstream yAxisLabelStream;
193 yAxisLabelStream.precision(4);
195 string yAxisLabel = yAxisLabelStream.str();
200 GetXaxis()->SetTitle(xAxisLabel.c_str());
201 GetYaxis()->SetTitle(yAxisLabel.c_str());
203 bool drawSuperimposed =
false;
207 drawSuperimposed =
true;
211 if (drawSuperimposed) {
214 Draw(drawOption.c_str());
225 if(drawSuperimposed) {
226 TPaveStats *s = (TPaveStats*) this->GetListOfFunctions()->FindObject(
"stats");
227 if(s) s->SetTextColor(this->GetLineColor());
251 string drawOption =
"A";
291 cout <<
"Cannot generate the histogram because there is no file open" << endl;
297 cout <<
"Enter an x-axis variable for the histogram" << endl;
299 chain->SetEstimate(chain->GetEntries());
301 Long64_t
N = chain->GetSelectedRows();
303 Double_t *dataPoints = chain->GetV1();
305 Int_t numberNotFinite = 0;
306 for (Int_t i = 0; i <
N; ++i) {
307 if (isfinite(dataPoints[i])) {
313 if (numberNotFinite != 0) {
314 cout <<
"Warning: " << numberNotFinite <<
" Inf/NaN values found and ignored" << endl;
323 return TH1D::GetName();
330 SetXVariable(histogramEditWindow->GetHistogramParametersFrame()->GetXVariable());
331 SetXUnits(histogramEditWindow->GetHistogramParametersFrame()->GetXUnits());
332 if (histogramEditWindow->GetHistogramParametersFrame()->IsXMinSet()) {
333 SetXMin(histogramEditWindow->GetHistogramParametersFrame()->GetXMin());
338 if (histogramEditWindow->GetHistogramParametersFrame()->IsXMaxSet()) {
339 SetXMax(histogramEditWindow->GetHistogramParametersFrame()->GetXMax());
344 if (histogramEditWindow->GetHistogramParametersFrame()->IsNumberOfBinsSet()) {
345 SetNumberOfBins(histogramEditWindow->GetHistogramParametersFrame()->GetNumberOfBins());
350 fIsBinWidthSet = histogramEditWindow->GetHistogramParametersFrame()->IsBinWidthSet();
352 fBinWidth = histogramEditWindow->GetHistogramParametersFrame()->GetBinWidth();
357 SetSuperimpose(histogramEditWindow->GetHistogramParametersFrame()->IsSuperimposeSet());
359 cout <<
"QGHistogram::GetParametersFromEditWindow() Warning: dynamic_cast<QGHistogramEditWindow*> failed" << endl;
366 return GetXaxis()->GetXmin();
371 return GetXaxis()->GetXmax();
376 return GetXaxis()->GetNbins();
398 string oldName = TH1D::GetName();
399 string newName = name;
400 if (newName != oldName) {
410 string styleHistogramName = string(
GetName()) +
"_StyleHistogram";
424 TString valueTString(value);
426 if (valueTString.IsFloat()) {
432 if (valueTString.IsFloat()) {
438 if (valueTString.IsFloat()) {
444 if (valueTString.IsFloat()) {
450 if (valueTString.IsFloat()) {
451 SetFillColor(valueTString.Atoi());
455 if (valueTString.IsFloat()) {
456 SetFillStyle(valueTString.Atoi());
460 if (valueTString.IsFloat()) {
465 if (valueTString.IsFloat()) {
466 SetLineStyle(valueTString.Atoi());
470 if (valueTString.IsFloat()) {
471 SetLineWidth(valueTString.Atoi());
475 if (valueTString.IsFloat()) {
476 SetMarkerColor(valueTString.Atoi());
480 if (valueTString.IsFloat()) {
481 SetMarkerSize(valueTString.Atof());
485 if (valueTString.IsFloat()) {
486 SetMarkerStyle(valueTString.Atoi());
ahisto2 SetLineColor(kRed)
#define NUMBER_OF_BINS_KEY
void RemoveFromDrawnPlots(QGPlot *plot)
Remove pointer to a plot from the list of drawn plots.
void AddToDrawnPlots(QGPlot *plot)
Add pointer to a plot to the list of drawn plots.
QGPlotFrame * GetPlotFrame()
Get pointer to the plot frame.
QGFileHandler * GetFileHandler() const
Get pointer to file handler.
void ClearDrawnPlots()
Clears the collection of drawn plots.
std::list< QGPlot * > & GetDrawnPlots()
Get collection of drawn plots.
bool IsFileOpen()
Check whether a file is open.
QChain * GetQChain()
Get a pointer to the chian.
Class for histogram edit window.
Class for GUI histograms.
void SetNumberOfBins(Int_t numberOfBins)
Set number of bins.
virtual ~QGHistogram()
Destructor.
bool fAutoSetNumberOfBins
Flag to automatically set the number of bins.
void DrawStyleHistogram()
Draw a mini-histogram showing the style of this histogram.
void Erase()
Erase histogram.
Double_t GetXMax() const
Get x-max.
void AutoSetStyle()
Automatically set the histogram style.
Int_t GetNumberOfBins() const
Get number of bins.
Double_t GetXMin() const
Get x-min.
QGHistogram()
Default constructor.
void SetProperty(const std::string &key, const std::string &value)
Set property (used for opening a session)
std::string fDrawOption
Draw option.
bool fAutoSetXMin
Flag to automatically set the x-axis minimum.
void Duplicate()
Duplicate the histogram.
void Display()
Display histogram.
TH1D * fStyleHistogram
Mini-histogram to show style of this histogram.
void SetXMax(Double_t xMax)
Set x-max.
void MakeStylePlot()
Make style plot.
Double_t fBinWidth
Bin width.
const char * GetName() const
Get name of histogram.
bool fAutoSetXMax
Flag to automatically set the x-axis maximum.
std::vector< Double_t > fDataPoints
Collection of points underlying the histogram, useful for instant rebinning.
void DisplayEditWindow()
Display edit window for the histogram.
void SetName(const char *name=0)
Set name of histogram.
void Generate(QChain *chain=0)
Generate histogram.
void SetXMin(Double_t xMin)
Set x-min.
void AutoSetAxisParameters()
Automatically set axis parameters.
void GetParametersFromEditWindow()
Get parameters from edit window.
bool fIsBinWidthSet
Whether or not bin width is set.
void SetBinWidth(Double_t binWidth)
Set bin width.
static std::list< QGHistogram * > fHistograms
Collection of pointers to all QGHistograms.
QGPlotStyleFrame * GetPlotStyleFrame()
Get pointer to the plot style frame.
virtual void SetPlot(QGPlot *plot)=0
Set plot, pure virtual function must be overriden by derived classes.
TRootEmbeddedCanvas * GetEmbeddedCanvas()
Get pointer to canvas.
TRootEmbeddedCanvas * GetEmbeddedCanvas()
Get pointer to embedded canvas.
Base class for GUI plots including histograms, scatter plots, pulses, and graphical cuts.
virtual void SetSuperimpose(bool flag=false)
Set whether the plot should be superimposed.
virtual std::string GeneratePlotName(const std::string &baseName) const
Generate a name for the plot.
virtual bool IsNameInUse(const std::string &name) const
Check whether string is the name of any plot.
std::string fXVariable
X-axis variable.
QGPlotEditWindow * fPlotEditWindow
Pointer to plot edit window.
virtual const std::string & GetXUnits() const
Get x-axis units.
virtual void SetProperty(const std::string &key, const std::string &value)
Set property (used for opening a session)
std::string fCutsString
Cuts in a single string.
virtual void SetXVariable(const std::string &x)
Set X-axis variable.
virtual const std::string & GetXVariable() const
Get x-axis variable.
bool fSuperimpose
Indicates whether plot should be superimposed on existing plot.
QGCanvasWindow * fCanvasWindow
Canvas window to which plot is associated.
virtual void SetXUnits(const std::string &units)
Set X-axis units.